diff --git a/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml b/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml index d88919e229dc79870eae34729c4dfa1ca1666f08..714a8edc0cca48ed70f37dd100950b76be92c4f7 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml +++ b/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml @@ -3,12 +3,14 @@ ARON DTO of armarx::objpose::ObjectPose. --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <AronIncludes> - <Include include="<RobotAPI/libraries/aron/common/aron/OrientedBox.xml>" autoinclude="true" /> - <Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectID.xml>" autoinclude="true" /> - <Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectType.xml>" autoinclude="true" /> - <Include include="<RobotAPI/libraries/ArmarXObjects/aron/PoseManifoldGaussian.xml>" autoinclude="true" /> - </AronIncludes> + + <Includes> + <Include package="RobotAPI" path="libraries/aron/common/aron/OrientedBox.xml" /> + <Include package="RobotAPI" path="libraries/ArmarXObjects/aron/ObjectID.xml" /> + <Include package="RobotAPI" path="libraries/ArmarXObjects/aron/ObjectType.xml" /> + <Include package="RobotAPI" path="libraries/ArmarXObjects/aron/PoseManifoldGaussian.xml" /> + </Includes> + <GenerateTypes> <Object name="armarx::objpose::arondto::ObjectAttachmentInfo"> diff --git a/source/RobotAPI/libraries/armem/aron/MemoryLink.xml b/source/RobotAPI/libraries/armem/aron/MemoryLink.xml index 3f04e393abf0c07747cdebd8288ca655f169e7c5..d38cd43a32aef5e1db68e1ae8a35860c9349a97f 100644 --- a/source/RobotAPI/libraries/armem/aron/MemoryLink.xml +++ b/source/RobotAPI/libraries/armem/aron/MemoryLink.xml @@ -1,11 +1,9 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/armem/aron/MemoryID.xml" /> + </Includes> + <GenerateTypes> <Object name="armarx::armem::arondto::MemoryLink" template="T"> <ObjectChild key="memoryID"> diff --git a/source/RobotAPI/libraries/armem_gui/instance/DataView.cpp b/source/RobotAPI/libraries/armem_gui/instance/DataView.cpp index 38033d8badc055615c131567ca9fdb8f9abe0741..f4d5f79cabb89ecbf0a0e5c50c8975af6e14010d 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/DataView.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/DataView.cpp @@ -364,7 +364,7 @@ namespace armarx::armem::gui::instance item->data(int(Columns::TYPE), Qt::UserRole).toInt()); switch (type) { - case aron::type::Descriptor::eImage: + case aron::type::Descriptor::IMAGE: { if (const std::optional<aron::Path> path = getElementPath(item)) { @@ -632,7 +632,7 @@ namespace armarx::armem::gui::instance // pixelType = aron::type::Image::pixelTypeFromName(imageData->getType()); // For now we assume it comes from c++ where '5' means CV_32FC1 (=5) - pixelType = (imageData->getType() == "5" ? PixelType::depth32 : PixelType::rgb24); + pixelType = (imageData->getType() == "5" ? PixelType::DEPTH32 : PixelType::RGB24); } catch (const aron::error::AronException&) { @@ -644,13 +644,13 @@ namespace armarx::armem::gui::instance { switch (pixelType.value()) { - case PixelType::rgb24: + case PixelType::RGB24: ARMARX_CHECK_EQUAL(shape.at(2), 3) << "Expected Rgb24 image to have 3 bytes per pixel."; image = QImage(imageData->getData(), cols, rows, QImage::Format::Format_RGB888); break; - case PixelType::depth32: + case PixelType::DEPTH32: image = imageView->convertDepth32ToRGB32(*imageData); clearLimitsHistory = false; break; diff --git a/source/RobotAPI/libraries/armem_objects/aron/Attachment.xml b/source/RobotAPI/libraries/armem_objects/aron/Attachment.xml index 76cb21c07a16e8f37c0fa00f6a4ab2b90cfd2983..43c864165e99a8b0a400a45cf790ec4310a5483c 100644 --- a/source/RobotAPI/libraries/armem_objects/aron/Attachment.xml +++ b/source/RobotAPI/libraries/armem_objects/aron/Attachment.xml @@ -1,12 +1,9 @@ <!--This class contains the data structure for ObjectPose --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/armem/aron/MemoryID.xml" /> + </Includes> <GenerateTypes> <Object name="armarx::armem::arondto::attachment::AgentDescription"> diff --git a/source/RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml b/source/RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml index 774c6e0d5d32734a16d7fdc918f491d19cfbfa39..27acad2fa236d09663b1f1f605ae915b0b34d7d8 100644 --- a/source/RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml +++ b/source/RobotAPI/libraries/armem_objects/aron/ObjectInstance.xml @@ -3,14 +3,11 @@ Core segment type of Object/Instance. --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.aron.generated.h>" /> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml>" /> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/ArmarXObjects/aron/ObjectPose.xml" /> + <Include package="RobotAPI" path="libraries/armem/aron/MemoryID.xml" /> + </Includes> + <GenerateTypes> <Object name="armarx::armem::arondto::ObjectInstance"> diff --git a/source/RobotAPI/libraries/armem_reasoning/aron/Anticipation.xml b/source/RobotAPI/libraries/armem_reasoning/aron/Anticipation.xml index a3f481c630d573970ace675032a13becc9ca57fe..1767413e76d00aaeaf076da7cdae8236d4f7ee5e 100644 --- a/source/RobotAPI/libraries/armem_reasoning/aron/Anticipation.xml +++ b/source/RobotAPI/libraries/armem_reasoning/aron/Anticipation.xml @@ -1,12 +1,9 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/armem/aron/MemoryID.xml" /> + </Includes> <GenerateTypes> <Object name='armarx::reasoning::arondto::Anticipation'> diff --git a/source/RobotAPI/libraries/armem_robot/aron/Robot.xml b/source/RobotAPI/libraries/armem_robot/aron/Robot.xml index 63e87ab3c4ba7193a8b7800ed4c24881c09e1b45..95227b98ba9a66db9552c5de413651de6a5ee8a9 100644 --- a/source/RobotAPI/libraries/armem_robot/aron/Robot.xml +++ b/source/RobotAPI/libraries/armem_robot/aron/Robot.xml @@ -1,16 +1,12 @@ <!--This class contains the data structure for ObjectPose --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/armem_robot/aron/RobotDescription.aron.generated.h>" /> - <Include include="<RobotAPI/libraries/armem_robot/aron/RobotState.aron.generated.h>" /> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <!-- <Include include="<RobotAPI/libraries/armem_objects/aron/RobotDescription.xml>" /> --> - <Include include="<RobotAPI/libraries/armem_robot/aron/RobotState.xml>" /> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/armem_robot/aron/RobotDescription.xml" /> + <Include package="RobotAPI" path="libraries/armem_robot/aron/RobotState.xml" /> + <Include package="RobotAPI" path="libraries/armem/aron/MemoryID.xml" /> + </Includes> + <GenerateTypes> <Object name="armarx::armem::arondto::Robot"> diff --git a/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml b/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml index edce8c802a4e77cb571492700422b7c04eb7e1a1..727a9b831a998c7b16dc25a27df94f48549fa51b 100644 --- a/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml +++ b/source/RobotAPI/libraries/armem_robot/aron/RobotDescription.xml @@ -1,12 +1,9 @@ <!--This class cotains information on how to create a VirtualRobot::Robot --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<RobotAPI/libraries/aron/common/aron/PackagePath.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/aron/common/aron/PackagePath.xml>" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/aron/common/aron/PackagePath.xml" /> + </Includes> <GenerateTypes> <Object name='armarx::armem::arondto::RobotDescription'> diff --git a/source/RobotAPI/libraries/armem_robot_state/aron/Transform.xml b/source/RobotAPI/libraries/armem_robot_state/aron/Transform.xml index 02ebe91b35094809953de6cfd0252c8a2048cf98..6408b9a11e353bc6c50e2893f285f99b9b613989 100644 --- a/source/RobotAPI/libraries/armem_robot_state/aron/Transform.xml +++ b/source/RobotAPI/libraries/armem_robot_state/aron/Transform.xml @@ -1,13 +1,11 @@ <!--This class contains the data structure for ObjectPose --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - <Include include="<RobotAPI/libraries/armem_robot_state/aron/TransformHeader.aron.generated.h>" /> - </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/armem_robot_state/aron/TransformHeader.xml>" /> - </AronIncludes> + <Includes> + <SystemInclude include="Eigen/Core" /> + <Include package="RobotAPI" path="libraries/armem_robot_state/aron/TransformHeader.xml" /> + </Includes> + <GenerateTypes> <Object name="armarx::armem::arondto::Transform"> <ObjectChild key='header'> diff --git a/source/RobotAPI/libraries/armem_robot_state/aron/TransformHeader.xml b/source/RobotAPI/libraries/armem_robot_state/aron/TransformHeader.xml index c6bd5b94f93fa10e0638c75d17e8dbed0ad5bc60..f56e52c915284cd7c0a2a8deaa0c0cf179e3a154 100644 --- a/source/RobotAPI/libraries/armem_robot_state/aron/TransformHeader.xml +++ b/source/RobotAPI/libraries/armem_robot_state/aron/TransformHeader.xml @@ -1,9 +1,10 @@ <!--This class contains the data structure for ObjectPose --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - </CodeIncludes> + <Includes> + <SystemInclude include="Eigen/Core" /> + </Includes> + <GenerateTypes> <Object name="armarx::armem::arondto::TransformHeader"> <ObjectChild key='parentFrame'> diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp index 777dbb0b3e5a54196283983367cdd2066ff216ef..2ebbab1cccdad55bec5e15e1ac085d718bb07369 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp @@ -85,18 +85,6 @@ namespace armarx::aron::codegenerator::cpp ToAronTypeDTO.enforceMemberAccess = "->toAronObjectDTO()"; initialTypeWriters.push_back(ToAronTypeDTO); } - - // toJSON Method - /* - { - codegenerator::WriterInfo toJSON; - toJSON.methodName = "toJSON"; - toJSON.returnType = "nlohmann::json"; - toJSON.writerClassType = "armarx::aron::data::writer::NlohmannJSONWriter"; - toJSON.include = "<RobotAPI/libraries/aron/core/data/rw/writer/nlohmannJSON/NlohmannJSONWriter.h>"; - dataWriters.push_back(toJSON); - } - */ } void Writer::addSpecificReaderMethods() @@ -138,18 +126,6 @@ namespace armarx::aron::codegenerator::cpp fromAronDTO.enforceConversion = "std::make_shared<armarx::aron::data::Dict>"; dataReaders.push_back(fromAronDTO); } - - // fromJSON Method - /* - { - codegenerator::ReaderInfo fromJSON; - fromJSON.methodName = "fromJSON"; - fromJSON.argumentType = "nlohmann::json"; - fromJSON.readerClassType = "armarx::aron::data::reader::NlohmannJSONReader"; - fromJSON.include = "<RobotAPI/libraries/aron/core/data/rw/reader/nlohmannJSON/NlohmannJSONReader.h>"; - dataReaders.push_back(fromJSON); - } - */ } @@ -162,15 +138,13 @@ namespace armarx::aron::codegenerator::cpp //std::cout << "Generating: " << nav->getName() << std::endl; // Convert to Object type and create class object - if (type == nullptr) - { - throw error::AronException(__PRETTY_FUNCTION__, "An received public type is null. Abort due to error!"); - } + ARMARX_CHECK_NOT_NULL(type); generator::ObjectClass generator(*type); - CppClassPtr c = setupBasicCppClass(publicGenerateObjectType, generator); + setupMemberFields(c, publicGenerateObjectType.doc_members, generator); + // check for templates if (!type->getTemplates().empty()) { std::vector<std::string> tmpl; @@ -184,8 +158,8 @@ namespace armarx::aron::codegenerator::cpp std::string requiresDef = "requires " + simox::alg::join(tmpl_requires, " && "); c->setTemplates(templateDef + "\n" + requiresDef); } - setupMemberFields(c, publicGenerateObjectType.doc_members, generator); + // check for inheritance if (type->getExtends() != nullptr) { generator::ObjectClass extendsSerializer(*type->getExtends()); @@ -194,20 +168,16 @@ namespace armarx::aron::codegenerator::cpp else { c->addInherit("public armarx::aron::codegenerator::cpp::AronGeneratedClass"); - c->addInclude("<RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/AronGeneratedClass.h>"); } - for (const std::string& s : additionalIncludes) + // Writermethods + for (codegenerator::WriterInfo info : dataWriters) { - if (!s.empty()) + if (info.returnType == OWN_TYPE_NAME) { - c->addInclude(s); + info.returnType = generator.getFullClassCppTypename(); } - } - // Writermethods - for (const codegenerator::WriterInfo& info : dataWriters) - { if (!info.include.empty()) { c->addInclude(info.include); @@ -217,15 +187,30 @@ namespace armarx::aron::codegenerator::cpp } // Add methods to set the member variables - for (const codegenerator::StaticReaderInfo& info : staticDataReaders) + // also resolve the original class name if the return type is set to special + for (codegenerator::StaticReaderInfo info : staticDataReaders) { + if (info.returnType == OWN_TYPE_NAME) + { + info.returnType = generator.getFullClassCppTypename(); + } + if (info.argumentType == OWN_TYPE_NAME) + { + info.argumentType = generator.getFullClassCppTypename(); + } + CppMethodPtr convert = generator.toSpecializedStaticDataReaderMethod(info); c->addMethod(convert); } // Add methods to set the member variables - for (const codegenerator::ReaderInfo& info : dataReaders) + for (codegenerator::ReaderInfo info : dataReaders) { + if (info.argumentType == OWN_TYPE_NAME) + { + info.argumentType = generator.getFullClassCppTypename(); + } + if (!info.include.empty()) { c->addInclude(info.include); @@ -235,8 +220,13 @@ namespace armarx::aron::codegenerator::cpp } // Typewritermethods - for (const codegenerator::WriterInfo& info : initialTypeWriters) + for (codegenerator::WriterInfo info : initialTypeWriters) { + if (info.returnType == OWN_TYPE_NAME) + { + info.returnType = generator.getFullClassCppTypename(); + } + if (!info.include.empty()) { c->addInclude(info.include); @@ -254,18 +244,13 @@ namespace armarx::aron::codegenerator::cpp for (const auto& publicGenerateIntEnumType : generateIntEnums) { const auto& nav = publicGenerateIntEnumType.correspondingType; - if (nav == nullptr) - { - throw error::AronException(__PRETTY_FUNCTION__, "An received public type is null. Abort due to error!"); - } + ARMARX_CHECK_NOT_NULL(nav); generator::IntEnumClass generator(*nav); - CppClassPtr c = setupBasicCppClass(publicGenerateIntEnumType, generator); setupMemberFields(c, publicGenerateIntEnumType.doc_values, generator); c->addInherit("public armarx::aron::codegenerator::cpp::AronGeneratedClass"); - c->addInclude("<RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/AronGeneratedClass.h>"); // ctor c->addCtor(generator.toCopyCtor(c->getName())); @@ -322,6 +307,7 @@ namespace armarx::aron::codegenerator::cpp classDoc += (info.doc_brief.empty() ? "" : " * @brief " + info.doc_brief + "\n"); classDoc += (info.doc_author.empty() ? "" : " * @author " + info.doc_author + "\n"); } + c->addClassDoc(classDoc); c->setPragmaOnceIncludeGuard(true); @@ -330,17 +316,27 @@ namespace armarx::aron::codegenerator::cpp c->addInclude("<string>"); c->addInclude("<vector>"); c->addInclude("<map>"); + + // add predefined includes from generator app (e.g. coming from reader) + for (const std::string& s : additionalIncludes) + { + if (!s.empty()) + { + c->addInclude(s); + } + } + + // add aron includes c->addInclude("<RobotAPI/interface/aron.h>"); + c->addInclude("<RobotAPI/libraries/aron/core/aron_conversions.h>"); + c->addInclude("<RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/AronGeneratedClass.h>"); - // add generator includes + // add generator includes (e.g. coming from dto types) for (const auto& i : gen.getRequiredIncludes()) { c->addInclude(i); } - // set This typename - c->addPublicField(std::string("using ") + OWN_TYPE_NAME + " = " + classCppTypename + ";"); - // ctor c->addCtor(gen.toCtor(c->getName())); diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.h index 1ce3857fe648a572a21ee4b224c9b09d0d074bdc..9405f63952de447de96a97e68fb3614bfec47807 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.h @@ -63,7 +63,7 @@ namespace armarx::aron::codegenerator::cpp void setupMemberFields(CppClassPtr&, const std::map<std::string, std::string>& doc_members, const generator::IntEnumClass&) const; private: - static const constexpr char* OWN_TYPE_NAME = "This"; + static const constexpr char* OWN_TYPE_NAME = "OWN_TYPE_NAME"; }; } diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp index fa4ead59d8499a5efd314330e835b5b72b04ff80..8cdd98da4fd8d151225f671bc0ed4c5e3c2ef0cf 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp @@ -287,7 +287,7 @@ namespace armarx::aron::codegenerator::cpp doc << "@return - nothing"; CppMethodPtr m = CppMethodPtr(new CppMethod("static " + info.returnType + " " + info.methodName + "(const " + info.argumentType + "& input)", doc.str())); - m->addLine("This t;"); + m->addLine(info.returnType + " t;"); m->addLine("t.fromAron(input);"); m->addLine("return t;"); return m; diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/container/Object.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/container/Object.cpp index c7a8773cbe3a617e802b0f7c509e85d0e64097a0..63405700dbc3da7c2ac31287c692ed8352971116 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/container/Object.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/container/Object.cpp @@ -27,7 +27,6 @@ #include <SimoxUtility/meta/type_name.h> #include <SimoxUtility/algorithm/vector.hpp> - namespace armarx::aron::codegenerator::cpp::generator { @@ -38,7 +37,10 @@ namespace armarx::aron::codegenerator::cpp::generator static const std::map<std::string, std::string> DTO_REPLACEMENTS = { {"armarx::arondto::Duration", "armarx::core::time::Duration"}, - {"armarx::arondto::DateTime", "armarx::core::time::DateTime"} + {"armarx::arondto::DateTime", "armarx::core::time::DateTime"}, + {"armarx::arondto::FramedPosition", "armarx::FramedPosition"}, + {"armarx::arondto::FramedOrientation", "armarx::FramedOrientation"}, + {"armarx::arondto::FramedPose", "armarx::FramedPose"} }; if (DTO_REPLACEMENTS.count(c) > 0) @@ -56,7 +58,10 @@ namespace armarx::aron::codegenerator::cpp::generator static const std::map<std::string, std::vector<std::string>> DTO_REPLACEMENTS = { {"armarx::arondto::Duration", {"<ArmarXCore/core/time/Duration.h>", "<RobotAPI/libraries/aron/common/aron_conversions/time.h>", "<RobotAPI/libraries/aron/common/aron/time.aron.generated.h>"}}, - {"armarx::arondto::DateTime", {"<ArmarXCore/core/time/DateTime.h>", "<RobotAPI/libraries/aron/common/aron_conversions/time.h>", "<RobotAPI/libraries/aron/common/aron/time.aron.generated.h>"}} + {"armarx::arondto::DateTime", {"<ArmarXCore/core/time/DateTime.h>", "<RobotAPI/libraries/aron/common/aron_conversions/time.h>", "<RobotAPI/libraries/aron/common/aron/time.aron.generated.h>"}}, + {"armarx::arondto::FramedPosition", {"<RobotAPI/libraries/core/FramedPose.h>", "<RobotAPI/libraries/aron/common/aron_conversions/framed.h>", "<RobotAPI/libraries/aron/common/aron/framed.aron.generated.h>"}}, + {"armarx::arondto::FramedOrientation", {"<RobotAPI/libraries/core/FramedPose.h>", "<RobotAPI/libraries/aron/common/aron_conversions/framed.h>", "<RobotAPI/libraries/aron/common/aron/framed.aron.generated.h>"}}, + {"armarx::arondto::FramedPose", {"<RobotAPI/libraries/core/FramedPose.h>", "<RobotAPI/libraries/aron/common/aron_conversions/framed.h>", "<RobotAPI/libraries/aron/common/aron/framed.aron.generated.h>"}} }; if (DTO_REPLACEMENTS.count(c) > 0) diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp index 768fa0dd6a721493433b5f810c1b40200f132d55..6c3717520d48ee01a83a31d76769e8b6dd273f69 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp @@ -73,10 +73,10 @@ namespace armarx::aron::codegenerator::cpp::generator enum_to_value << "\t}"; value_to_enum << "\t}"; - fields.push_back(std::make_shared<CppField>("const std::map<" + std::string(IMPL_ENUM) + ", std::string>", "EnumToStringMap", enum_to_name.str(), "Mapping enum values to readable strings")); - fields.push_back(std::make_shared<CppField>("const std::map<std::string, " + std::string(IMPL_ENUM) + ">", "StringToEnumMap", name_to_enum.str(), "Mapping readable strings to enum values")); - fields.push_back(std::make_shared<CppField>("const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value")); - fields.push_back(std::make_shared<CppField>("const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", std::string>", "EnumToStringMap", enum_to_name.str(), "Mapping enum values to readable strings")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<std::string, " + std::string(IMPL_ENUM) + ">", "StringToEnumMap", name_to_enum.str(), "Mapping readable strings to enum values")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum")); fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", "", "The current value of the enum object")); diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp index f8e044b8d11522df32648b59dff0fd3b114d4cdc..0d54dc8bf173b1262ecbc938a6c1678fb1dff8b2 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp @@ -33,7 +33,7 @@ namespace armarx::aron::codegenerator::cpp::generator // constructors ObjectClass::ObjectClass(const type::Object& e) : detail::SpecializedGeneratorBase<type::Object, ObjectClass>( - e.getObjectName(), + e.getObjectNameWithTemplateInstantiations(), // should be similar to the object name e.getObjectNameWithTemplates(), simox::meta::get_type_name<data::dto::Dict>(), simox::meta::get_type_name<type::dto::AronObject>(), e) diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/aron/DerivedClassTest.xml b/source/RobotAPI/libraries/aron/codegeneration/test/aron/DerivedClassTest.xml index 53e8107bc93618f0fdd9e405ef469ede2175e042..edda7cf5f457545a57496e62283ed58cb321b68f 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/test/aron/DerivedClassTest.xml +++ b/source/RobotAPI/libraries/aron/codegeneration/test/aron/DerivedClassTest.xml @@ -1,9 +1,10 @@ <!--This class contains the data structure for NaturalIKResults --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <AronIncludes> - <Include include="<RobotAPI/libraries/aron/codegeneration/test/aron/BaseClassTest.xml>" autoinclude="true" /> - </AronIncludes> + <Includes> + <Include package="RobotAPI" path="libraries/aron/codegeneration/test/aron/BaseClassTest.xml" /> + </Includes> + <GenerateTypes> <Object name='armarx::DerivedClassTest' extends="armarx::BaseClassTest" doc-brief="This is a brief doc" doc-author="Itse me, Mario!"> diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/aron/DtoTest.xml b/source/RobotAPI/libraries/aron/codegeneration/test/aron/DtoTest.xml index b08df68f4c54f23ced8e8e5540d499997191e682..d25bdefdd140dac7b1168bff4dcdbc68fd3cb878 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/test/aron/DtoTest.xml +++ b/source/RobotAPI/libraries/aron/codegeneration/test/aron/DtoTest.xml @@ -6,9 +6,21 @@ <objectchild key='the_time'> <datetime /> </ObjectChild> + <objectchild key='the_time2'> + <time /> + </ObjectChild> <objectchild key='the_duration'> <duration /> </ObjectChild> + <objectchild key='the_pos'> + <framedposition /> + </ObjectChild> + <objectchild key='the_ori'> + <framedorientation /> + </ObjectChild> + <objectchild key='the_pose'> + <framedpose /> + </ObjectChild> </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/aron/OptionalTest.xml b/source/RobotAPI/libraries/aron/codegeneration/test/aron/OptionalTest.xml index 2b0d2d39810d2d1c05d4c40bba55ee36fc29615a..29b58d4594a99b5845c25fcbfe003d97bb89b763 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/test/aron/OptionalTest.xml +++ b/source/RobotAPI/libraries/aron/codegeneration/test/aron/OptionalTest.xml @@ -1,8 +1,9 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - </CodeIncludes> + <Include> + <SystemInclude package="" path="Eigen/Core" /> + </Include> + <GenerateTypes> <Object name="armarx::OptionalTestElement"> <ObjectChild key="val"> diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/Reader.h b/source/RobotAPI/libraries/aron/codegeneration/typereader/Reader.h index 31ab1c61873c847901528695670ea14272f3ad17..0c8695fa42045cf49c18295e3bd8fc59fcbfe3b8 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/Reader.h +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/Reader.h @@ -54,7 +54,7 @@ namespace armarx::aron::typereader std::vector<std::string> getCodeIncludes() const { - return codeIncludes; + return systemIncludes; } std::vector<std::string> getAronIncludes() const { @@ -80,7 +80,7 @@ namespace armarx::aron::typereader protected: std::vector<std::string> alreadyParsedXMLFiles; - std::vector<std::string> codeIncludes; + std::vector<std::string> systemIncludes; std::vector<std::string> aronIncludes; std::vector<codegenerator::ReaderInfo> readers; diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp index 3a7ba2a06711d3f02f19fc17e73b31adc7bf6da3..dae418cdb4fd4de31b2daf86c839b60b988233ca 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp @@ -75,7 +75,7 @@ namespace armarx::aron::typereader::xml if (HasAttribute(node, att)) { std::string v = simox::alg::to_lower(node.attribute_value(att.c_str())); - if (v == "1" or v == "true" or v == "wahr" or v == "yes" or v == "ja" or v == "") + if (v == "1" or v == "true" or v == "yes" or v == "ja" or v == "") { return true; } @@ -92,10 +92,22 @@ namespace armarx::aron::typereader::xml { if (!(HasTagName(node, name))) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong tag", name); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node has the wrong tag. Expected: " + name, node.name()); } } + void util::EnforceTagNames(const RapidXmlReaderNode& node, const std::vector<std::string>& names) + { + for (const auto& name : names) + { + if (HasTagName(node, name)) + { + return; + } + } + throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node has the wrong tag. Expected one of: " + simox::alg::to_string(names, ", "), node.name()); + } + std::string util::GetTagName(const armarx::RapidXmlReaderNode& node) { return simox::alg::to_lower(node.name()); diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h index bc1a437058bfd75b111d257e8c7200889ae88ee8..a780a801173760a7adeae69fda0b4cff4a66e0f9 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h @@ -42,12 +42,12 @@ namespace armarx::aron::typereader::xml // Definition tags const std::string TYPE_DEFINITION_TAG = "arontypedefinition"; - const std::string CODE_INCLUDES_TAG = "codeincludes"; - const std::string INCLUDES_TAG = "aronincludes"; - const std::string GENERATE_TYPES_TAG = "generatetypes"; - const std::string AUTO_CODE_INCLUDE = "autoinclude"; - + const std::string CODE_INCLUDES_TAG = "codeincludes"; // Legacy + const std::string ARON_INCLUDES_TAG = "aronincludes"; // Legacy + const std::string INCLUDES_TAG = "includes"; + const std::string SYSTEM_INCLUDE_TAG = "systeminclude"; const std::string INCLUDE_TAG = "include"; + const std::string GENERATE_TYPES_TAG = "generatetypes"; // Attribute names const std::string METHOD_ATTRIBUTE_NAME = "method"; @@ -68,14 +68,15 @@ namespace armarx::aron::typereader::xml const std::string COLS_ATTRIBUTE_NAME = "cols"; const std::string DIMENSIONS_ATTRIBUTE_NAME = "dimensions"; const std::string SHAPE_ATTRIBUTE_NAME = "shape"; - const std::string OPTIONAL_NAME = "optional"; - const std::string RAW_PTR_NAME = "raw_ptr"; - const std::string SHARED_PTR_NAME = "shared_ptr"; - const std::string UNIQUE_PTR_NAME = "unique_ptr"; - const std::string PACKAGE_NAME = "package"; - const std::string DOC_BRIEF_NAME = "doc-brief"; - const std::string DOC_AUTHOR_NAME = "doc-author"; - const std::string DOC_PARAM_NAME = "doc-param"; + const std::string OPTIONAL_ATTRIBUTE_NAME = "optional"; + const std::string RAW_PTR_ATTRIBUTE_NAME = "raw_ptr"; + const std::string SHARED_PTR_ATTRIBUTE_NAME = "shared_ptr"; + const std::string UNIQUE_PTR_ATTRIBUTE_NAME = "unique_ptr"; + const std::string PACKAGE_ATTRIBUTE_NAME = "package"; + const std::string DOC_BRIEF_ATTRIBUTE_NAME = "doc-brief"; + const std::string DOC_AUTHOR_ATTRIBUTE_NAME = "doc-author"; + const std::string DOC_PARAM_ATTRIBUTE_NAME = "doc-param"; + const std::string PATH_ATTRIBUTE_NAME = "path"; // Second level tags. Only important if in specific top level tag const std::string OBJECT_CHILD_TAG = "objectchild"; @@ -112,9 +113,13 @@ namespace armarx::aron::typereader::xml {"orientation", {"<quaternion type='float32' />", ""}}, // You can also add replacements for arondtos here! + // structure: {xml-identifier, {replacement, auto-include}} {"datetime", {"<armarx::arondto::DateTime />", "<RobotAPI/libraries/aron/common/aron/time.xml>"}}, {"time", {"<armarx::arondto::DateTime />", "<RobotAPI/libraries/aron/common/aron/time.xml>"}}, - {"duration", {"<armarx::arondto::Duration />", "<RobotAPI/libraries/aron/common/aron/time.xml>"}} + {"duration", {"<armarx::arondto::Duration />", "<RobotAPI/libraries/aron/common/aron/time.xml>"}}, + {"framedposition", {"<armarx::arondto::FramedPosition />", "<RobotAPI/libraries/aron/common/aron/framed.xml>"}}, + {"framedorientation", {"<armarx::arondto::FramedOrientation />", "<RobotAPI/libraries/aron/common/aron/framed.xml>"}}, + {"framedpose", {"<armarx::arondto::FramedPose />", "<RobotAPI/libraries/aron/common/aron/framed.xml>"}} }; } @@ -131,6 +136,7 @@ namespace armarx::aron::typereader::xml bool HasTagName(const RapidXmlReaderNode& node, const std::string& name); void EnforceTagName(const RapidXmlReaderNode& node, const std::string& name); + void EnforceTagNames(const RapidXmlReaderNode& node, const std::vector<std::string>& names); std::string GetTagName(const RapidXmlReaderNode& node); void EnforceChildSizeSmaller(const RapidXmlReaderNode& node, const size_t size); diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp index 5eebd6d760ea6ac14a034817f172e9a6c2f887be..9aa67cac2e52f89cc4149d9e4d9cc2bd44908568 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp @@ -142,19 +142,19 @@ namespace armarx::aron::typereader::xml type::Maybe ReaderFactory::getMaybe(const RapidXmlReaderNode& n) const { - if (util::AttributeIsTrue(n, constantes::OPTIONAL_NAME)) + if (util::AttributeIsTrue(n, constantes::OPTIONAL_ATTRIBUTE_NAME)) { return type::Maybe::OPTIONAL; } - if (util::AttributeIsTrue(n, constantes::RAW_PTR_NAME)) + if (util::AttributeIsTrue(n, constantes::RAW_PTR_ATTRIBUTE_NAME)) { return type::Maybe::RAW_PTR; } - if (util::AttributeIsTrue(n, constantes::SHARED_PTR_NAME)) + if (util::AttributeIsTrue(n, constantes::SHARED_PTR_ATTRIBUTE_NAME)) { return type::Maybe::SHARED_PTR; } - if (util::AttributeIsTrue(n, constantes::UNIQUE_PTR_NAME)) + if (util::AttributeIsTrue(n, constantes::UNIQUE_PTR_ATTRIBUTE_NAME)) { return type::Maybe::UNIQUE_PTR; } @@ -190,8 +190,8 @@ namespace armarx::aron::typereader::xml auto newObjectInfo = typereader::GenerateObjectInfo(); newObjectInfo.typeName = name; - newObjectInfo.doc_brief = util::GetAttributeWithDefault(node, constantes::DOC_BRIEF_NAME, ""); - newObjectInfo.doc_author = util::GetAttributeWithDefault(node, constantes::DOC_AUTHOR_NAME, ""); + newObjectInfo.doc_brief = util::GetAttributeWithDefault(node, constantes::DOC_BRIEF_ATTRIBUTE_NAME, ""); + newObjectInfo.doc_author = util::GetAttributeWithDefault(node, constantes::DOC_AUTHOR_ATTRIBUTE_NAME, ""); // reset private known types allPreviouslyKnownPrivateTypes = templates; @@ -207,9 +207,9 @@ namespace armarx::aron::typereader::xml checkObjectMemberName(key); - if (util::HasAttribute(objectChild, constantes::DOC_BRIEF_NAME)) + if (util::HasAttribute(objectChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)) { - newObjectInfo.doc_members.insert({key, util::GetAttribute(objectChild, constantes::DOC_BRIEF_NAME)}); + newObjectInfo.doc_members.insert({key, util::GetAttribute(objectChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); } std::vector<RapidXmlReaderNode> children = objectChild.nodes(); @@ -480,9 +480,9 @@ namespace armarx::aron::typereader::xml const std::string key = util::GetAttribute(valueChild, constantes::KEY_ATTRIBUTE_NAME); - if (util::HasAttribute(valueChild, constantes::DOC_BRIEF_NAME)) + if (util::HasAttribute(valueChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)) { - newEnumInfo.doc_values.insert({key, util::GetAttribute(valueChild, constantes::DOC_BRIEF_NAME)}); + newEnumInfo.doc_values.insert({key, util::GetAttribute(valueChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); } const std::string value = util::GetAttribute(valueChild, constantes::VALUE_ATTRIBUTE_NAME); diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp index 3f7d947e03f21a23088ee88505fabc7d3610b763..b5de00b0a790888e6638a9a1207a7f3795efe5be 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.cpp @@ -27,6 +27,9 @@ // Header #include "Reader.h" +// Simox +#include <SimoxUtility/algorithm/vector.hpp> + // ArmarX #include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> #include <ArmarXCore/core/system/cmake/CMakePackageFinder.h> @@ -41,6 +44,13 @@ namespace armarx::aron::typereader::xml namespace { + + [[deprecated("Using the tags <CodeInclude> and <AronInclude> is deprecated. Only use a single top-level-tag <Includes> instead.")]] + void deprecated_include() + { + + } + /// Resolve a relative Package path. This may be removed in a newer version of aron std::optional<fs::path> resolveRelativePackagePath(const fs::path& path) { @@ -95,35 +105,71 @@ namespace armarx::aron::typereader::xml util::EnforceChildSizeSmallerEqual(root, 4); - auto code_includes = util::GetFirstNodeWithTag(root, constantes::CODE_INCLUDES_TAG); - auto aron_includes = util::GetFirstNodeWithTag(root, constantes::INCLUDES_TAG); + auto includes = util::GetFirstNodeWithTag(root, constantes::INCLUDES_TAG); auto generate_types = util::GetFirstNodeWithTag(root, constantes::GENERATE_TYPES_TAG); - // 1. Check includes - if (code_includes.has_value()) + // 0. Check legacy includes + auto codeincludes = util::GetFirstNodeWithTag(root, constantes::CODE_INCLUDES_TAG); + auto aronincludes = util::GetFirstNodeWithTag(root, constantes::ARON_INCLUDES_TAG); + if (codeincludes.has_value()) { - for (const auto& include : (*code_includes).nodes()) + deprecated_include(); + + for (const auto& include : (*codeincludes).nodes()) + { + auto i = readCodeInclude(include, filePath); + if (i) this->systemIncludes.push_back(*i); + } + } + if (aronincludes.has_value()) + { + deprecated_include(); + + for (const auto& include : (*aronincludes).nodes()) { - this->codeIncludes.push_back(readCodeInclude(include, filePath)); + auto i = readAronInclude(include, filePath); + if (i) this->aronIncludes.push_back(*i); } } - // 2. Check AronIncludes - // 2.1 Read replacement files - for (const auto& p : constantes::REPLACEMENTS) + // 1. Check includes + if (includes.has_value()) { - if (!p.second.second.empty()) + for (const auto& include : (*includes).nodes()) { - this->aronIncludes.push_back(readAronInclude(p.second.second, filePath)); + if (util::HasTagName(include, constantes::SYSTEM_INCLUDE_TAG)) + { + auto i = readCodeInclude(include, filePath); + if (i) this->systemIncludes.push_back(*i); + } + + // ToDo: add special tag for aron includes + + // ToDo: system includes also allow to use the <include> tag. Try to estimate aron or system include from attributes + if (util::HasTagName(include, constantes::INCLUDE_TAG)) + { + auto i = readAronInclude(include, filePath); + if (i) this->aronIncludes.push_back(*i); + } } } - // 2.2 Read user defined aron includes - if (aron_includes.has_value()) + // 2. Check used tags of GenerateTypes for special defaulted includes + if (generate_types.has_value()) { - for (const auto& aronInclude : (*aron_includes).nodes()) + for (const auto& generateType : (*generate_types).nodes()) { - this->aronIncludes.push_back(readAronInclude(aronInclude, filePath)); + if (util::HasTagName(generateType, constantes::OBJECT_TAG)) + { + for (const auto& x : checkForInclude(generateType, filePath)) + { + auto i = this->readAronInclude(x, filePath); + if (i && std::find(this->aronIncludes.begin(), this->aronIncludes.end(), *i) == this->aronIncludes.end()) + { + this->aronIncludes.push_back(*i); + } + } + } } } @@ -154,38 +200,56 @@ namespace armarx::aron::typereader::xml } } - std::string Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath) + std::optional<std::string> Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath) { - util::EnforceTagName(node, constantes::INCLUDE_TAG); - util::EnforceAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME); - const std::string include = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME); - return readCodeInclude(include, filePath); + util::EnforceTagNames(node, {constantes::SYSTEM_INCLUDE_TAG, constantes::INCLUDE_TAG}); + std::string specifiedPath = util::GetAttributeWithDefault(node, constantes::INCLUDE_ATTRIBUTE_NAME, ""); + specifiedPath = simox::alg::replace_all(specifiedPath, "<", ""); + specifiedPath = simox::alg::replace_all(specifiedPath, ">", ""); + if (specifiedPath.empty()) + { + // else we require a package path + util::EnforceAttribute(node, constantes::PACKAGE_ATTRIBUTE_NAME); + util::EnforceAttribute(node, constantes::PATH_ATTRIBUTE_NAME); + const std::string package = util::GetAttribute(node, constantes::PACKAGE_ATTRIBUTE_NAME); + const std::string path = util::GetAttribute(node, constantes::PATH_ATTRIBUTE_NAME); + specifiedPath = package + "/" + path; + } + return readCodeInclude("<" + specifiedPath + ">", filePath); // <> for legacy reasons. ToDo: } - std::string Reader::readCodeInclude(const std::string& s, const std::filesystem::path&) + std::optional<std::string> Reader::readCodeInclude(std::string s, const std::filesystem::path&) { return s; } - std::string Reader::readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath) + std::optional<std::string> Reader::readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath) { util::EnforceTagName(node, constantes::INCLUDE_TAG); - std::string specifiedPath = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME); - std::string resolved_absolute_path = readAronInclude(specifiedPath, filePath); + std::string specifiedPath = util::GetAttributeWithDefault(node, constantes::INCLUDE_ATTRIBUTE_NAME, ""); + specifiedPath = simox::alg::replace_all(specifiedPath, "<", ""); + specifiedPath = simox::alg::replace_all(specifiedPath, ">", ""); + if (specifiedPath.empty()) + { + const std::string package = util::GetAttribute(node, constantes::PACKAGE_ATTRIBUTE_NAME); + const std::string path = util::GetAttribute(node, constantes::PATH_ATTRIBUTE_NAME); + specifiedPath = package + "/" + path; + } - if (util::HasAttribute(node, constantes::AUTO_CODE_INCLUDE)) + std::optional<std::string> resolved_absolute_path = readAronInclude("<" + specifiedPath + ">", filePath); + if (resolved_absolute_path) // we found something { std::string codeinclude = simox::alg::replace_last(specifiedPath, ".xml", ".aron.generated.h"); - this->codeIncludes.push_back(codeinclude); + auto i = this->readCodeInclude("<" + codeinclude + ">", filePath); + if (i) this->systemIncludes.push_back(*i); } return resolved_absolute_path; } - std::string Reader::readAronInclude(const std::string& s, const std::filesystem::path& filePath) + std::optional<std::string> Reader::readAronInclude(std::string specifiedPath, const std::filesystem::path& filePath) { - std::string specifiedPath = s; specifiedPath = simox::alg::replace_all(specifiedPath, "<", ""); specifiedPath = simox::alg::replace_all(specifiedPath, ">", ""); const std::filesystem::path xmlincludepath(specifiedPath); @@ -220,7 +284,7 @@ namespace armarx::aron::typereader::xml // check if referred file is same as current file. If so, abort. if (resolved_absolute_path == filePath) { - return ""; + return std::nullopt; } // parse parent xml file and add objects to alreday known @@ -242,6 +306,32 @@ namespace armarx::aron::typereader::xml return resolved_absolute_path.string(); } + std::vector<std::string> Reader::checkForInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath) + { + std::vector<std::string> ret; + for (const auto& repl : constantes::REPLACEMENTS) + { + if (!repl.second.second.empty() && util::HasTagName(node, repl.first)) + { + // we found a string that will be replaced so we might need to add a default include + ret.push_back(repl.second.second); + break; + } + } + + if (not ret.empty()) // children are not allowed for dto replaced nodes! + { + util::EnforceChildSize(node, 0); + } + + for (const auto& n : node.nodes()) // only valid if ret is empty + { + auto v = checkForInclude(n, filePath); + ret = simox::alg::appended(ret, v); + } + + return ret; + } type::ObjectPtr Reader::readGenerateObject(const RapidXmlReaderNode& node) { diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h index e686154899b9dc96d246584391e9814e0701bd85..d661a62bf07c674a0085fd5b387601a539796966 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Reader.h @@ -56,11 +56,13 @@ namespace armarx::aron::typereader::xml private: void parse(const RapidXmlReaderPtr& node, const std::filesystem::path& filePath); - std::string readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); - std::string readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); + std::optional<std::string> readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); + std::optional<std::string> readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); - std::string readCodeInclude(const std::string&, const std::filesystem::path& filePath); - std::string readAronInclude(const std::string&, const std::filesystem::path& filePath); + std::vector<std::string> checkForInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filePath); + + std::optional<std::string> readCodeInclude(std::string, const std::filesystem::path& filePath); + std::optional<std::string> readAronInclude(std::string, const std::filesystem::path& filePath); type::ObjectPtr readGenerateObject(const RapidXmlReaderNode& node); diff --git a/source/RobotAPI/libraries/aron/common/CMakeLists.txt b/source/RobotAPI/libraries/aron/common/CMakeLists.txt index 14e5a0305d96f267dae3a20c70f05bb37fdee2f3..8dc8e85556003093661f8adc0e4352ed5f660726 100644 --- a/source/RobotAPI/libraries/aron/common/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/common/CMakeLists.txt @@ -9,6 +9,7 @@ armarx_add_library( # ArmarXCore ArmarXCore # RobotAPI + RobotAPICore aron HEADERS @@ -27,6 +28,9 @@ armarx_add_library( json_conversions/armarx.h + rw/time.h + rw/framed.h + util/object_finders.h SOURCES @@ -42,6 +46,9 @@ armarx_add_library( json_conversions/armarx.cpp + rw/time.cpp + rw/framed.cpp + util/object_finders.cpp ) diff --git a/source/RobotAPI/libraries/aron/common/aron/OrientedBox.xml b/source/RobotAPI/libraries/aron/common/aron/OrientedBox.xml index c7527c2cfc3e862f45bf5f69a039b27c96eb5d50..3a264f6fe394d7959f88e7348942870fbd62eef4 100644 --- a/source/RobotAPI/libraries/aron/common/aron/OrientedBox.xml +++ b/source/RobotAPI/libraries/aron/common/aron/OrientedBox.xml @@ -3,10 +3,12 @@ The ARON DTO of simox::OrientedBoxf. --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> + <CodeIncludes> <Include include="<Eigen/Core>" /> <Include include="<Eigen/Geometry>" /> </CodeIncludes> + <GenerateTypes> <Object name="simox::arondto::OrientedBox"> diff --git a/source/RobotAPI/libraries/aron/common/aron/framed.xml b/source/RobotAPI/libraries/aron/common/aron/framed.xml index 2e2e6d45f95defa21e39670d5957dba539d63972..1fb5025dfd26637f542f05606bbe41777fc0a903 100644 --- a/source/RobotAPI/libraries/aron/common/aron/framed.xml +++ b/source/RobotAPI/libraries/aron/common/aron/framed.xml @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Geometry>" /> - </CodeIncludes> + <Includes> + <SystemInclude include="Eigen/Geometry" /> + </Includes> <GenerateTypes> diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/framed.cpp b/source/RobotAPI/libraries/aron/common/aron_conversions/framed.cpp index 516620a1391ac99431431b4a0c3125971d3567cb..e7139063b3e439d80e94942b48223ce128ce7bdc 100644 --- a/source/RobotAPI/libraries/aron/common/aron_conversions/framed.cpp +++ b/source/RobotAPI/libraries/aron/common/aron_conversions/framed.cpp @@ -1 +1,36 @@ #include "framed.h" + +#include <RobotAPI/libraries/aron/common/aron/framed.aron.generated.h> + +namespace armarx +{ + void fromAron(const arondto::FramedPosition& dto, armarx::FramedPosition& bo) + { + + } + + void toAron(arondto::FramedPosition& dto, const armarx::FramedPosition& bo) + { + + } + + void fromAron(const arondto::FramedOrientation& dto, armarx::FramedOrientation& bo) + { + + } + + void toAron(arondto::FramedOrientation& dto, const armarx::FramedOrientation& bo) + { + + } + + void fromAron(const arondto::FramedPose& dto, armarx::FramedPose& bo) + { + + } + + void toAron(arondto::FramedPose& dto, const armarx::FramedPose& bo) + { + + } +} diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/framed.h b/source/RobotAPI/libraries/aron/common/aron_conversions/framed.h index f7c53ac77567e564a372a918a2bd671311239c98..49246f99c37c149d342c58b31f639fc68c6a07ed 100644 --- a/source/RobotAPI/libraries/aron/common/aron_conversions/framed.h +++ b/source/RobotAPI/libraries/aron/common/aron_conversions/framed.h @@ -1,11 +1,26 @@ #pragma once #include <RobotAPI/libraries/aron/core/aron_conversions.h> +#include <RobotAPI/libraries/core/FramedPose.h> + +// arondto forward declarations +namespace armarx::arondto +{ + class FramedPosition; + class FramedOrientation; + class FramedPose; + class FramedID; +} -#include <RobotAPI/libraries/aron/common/aron/framed.aron.generated.h> namespace armarx { + void fromAron(const arondto::FramedPosition& dto, armarx::FramedPosition& bo); + void toAron(arondto::FramedPosition& dto, const armarx::FramedPosition& bo); + void fromAron(const arondto::FramedOrientation& dto, armarx::FramedOrientation& bo); + void toAron(arondto::FramedOrientation& dto, const armarx::FramedOrientation& bo); -} // namespace armarx + void fromAron(const arondto::FramedPose& dto, armarx::FramedPose& bo); + void toAron(arondto::FramedPose& dto, const armarx::FramedPose& bo); +} diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/time.cpp b/source/RobotAPI/libraries/aron/common/aron_conversions/time.cpp index 2ee681ca3695cd0751ab7d89f498362a6ab87319..154079cb9d64be74ec6bf7e2ad030485548ff800 100644 --- a/source/RobotAPI/libraries/aron/common/aron_conversions/time.cpp +++ b/source/RobotAPI/libraries/aron/common/aron_conversions/time.cpp @@ -2,9 +2,8 @@ #include <IceUtil/Time.h> -#include <ArmarXCore/core/time/ice_conversions.h> - #include <RobotAPI/libraries/aron/common/aron/time.aron.generated.h> +#include <ArmarXCore/core/time/ice_conversions.h> void IceUtil::fromAron(const long& dto, IceUtil::Time& bo) diff --git a/source/RobotAPI/libraries/aron/common/aron_conversions/time.h b/source/RobotAPI/libraries/aron/common/aron_conversions/time.h index 0ea9cb87a972c2fe2e7d2713f608242095cacffa..2dc940f196215903f090c57a398f74e7fc90a25d 100644 --- a/source/RobotAPI/libraries/aron/common/aron_conversions/time.h +++ b/source/RobotAPI/libraries/aron/common/aron_conversions/time.h @@ -3,6 +3,15 @@ #include <RobotAPI/libraries/aron/core/aron_conversions.h> #include <ArmarXCore/core/time_minimal.h> +// arondto forward declarations +namespace armarx::arondto +{ + class ClockType; + class Duration; + class DateTime; + class Frequency; +} + namespace IceUtil { @@ -23,14 +32,6 @@ namespace IceUtil } namespace armarx { - namespace arondto - { - class ClockType; - class Duration; - class Frequency; - class DateTime; - } - void fromAron(const arondto::ClockType& dto, ClockType& bo); void toAron(arondto::ClockType& dto, const ClockType& bo); diff --git a/source/RobotAPI/libraries/aron/common/rw/framed.cpp b/source/RobotAPI/libraries/aron/common/rw/framed.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f88461dbf51e7634cb25a9f96fbbc6f05a08b95 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/rw/framed.cpp @@ -0,0 +1,2 @@ +#include "framed.h" + diff --git a/source/RobotAPI/libraries/aron/common/rw/framed.h b/source/RobotAPI/libraries/aron/common/rw/framed.h new file mode 100644 index 0000000000000000000000000000000000000000..bedc47f6f40cb52aa6f894ad06935e940d86cba2 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/rw/framed.h @@ -0,0 +1,32 @@ +#pragma once + +#include "../aron_conversions/framed.h" + +#include <RobotAPI/libraries/aron/common/aron/framed.aron.generated.h> + +namespace armarx +{ + // Helper methods for code generation to convert json/aron to bo and vice versa + namespace aron + { + template<class ReaderT> + armarx::FramedPosition readFramedPosition(ReaderT& aron_r, typename ReaderT::InputType& input) + { + arondto::FramedPosition aron; + aron.read(aron_r, input); + + armarx::FramedPosition ret; + armarx::fromAron(aron, ret); + return ret; + } + + template<class WriterT> + typename WriterT::ReturnType writeFramedPosition(WriterT& aron_w, const armarx::FramedPosition& input, const armarx::aron::Path& aron_p = armarx::aron::Path()) + { + arondto::FramedPosition aron; + armarx::toAron(aron, input); + return aron.write(aron_w, aron_p); + } + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/aron/common/rw/time.cpp b/source/RobotAPI/libraries/aron/common/rw/time.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbe876c66b979df75c4cd328edb1fea33611d987 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/rw/time.cpp @@ -0,0 +1 @@ +#include "time.h" diff --git a/source/RobotAPI/libraries/aron/common/rw/time.h b/source/RobotAPI/libraries/aron/common/rw/time.h new file mode 100644 index 0000000000000000000000000000000000000000..02ebe2b4a9815e55cd8907fb6c2829bd07943000 --- /dev/null +++ b/source/RobotAPI/libraries/aron/common/rw/time.h @@ -0,0 +1,53 @@ +#pragma once + +#include "../aron_conversions/time.h" + +#include <RobotAPI/libraries/aron/common/aron/time.aron.generated.h> + +namespace armarx +{ + // Helper methods for code generation to convert json/aron to bo and vice versa + namespace aron + { + template<class ReaderT> + armarx::core::time::DateTime readDateTime(ReaderT& aron_r, typename ReaderT::InputType& input) + { + arondto::DateTime aron; + aron.read(aron_r, input); + + armarx::core::time::DateTime ret; + armarx::fromAron(aron, ret); + return ret; + } + + template<class WriterT> + typename WriterT::ReturnType writeDateTime(WriterT& aron_w, const armarx::core::time::DateTime& input, const armarx::aron::Path& aron_p = armarx::aron::Path()) + { + arondto::DateTime aron; + armarx::toAron(aron, input); + return aron.write(aron_w, aron_p); + } + + + + template<class ReaderT> + armarx::core::time::Duration readDuration(ReaderT& aron_r, typename ReaderT::InputType& input) + { + arondto::Duration aron; + aron.read(aron_r, input); + + armarx::core::time::Duration ret; + armarx::fromAron(aron, ret); + return ret; + } + + template<class WriterT> + typename WriterT::ReturnType writeDuration(WriterT& aron_w, const armarx::core::time::Duration& input, const armarx::aron::Path& aron_p = armarx::aron::Path()) + { + arondto::Duration aron; + armarx::toAron(aron, input); + return aron.write(aron_w, aron_p); + } + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/aron/core/aron_conversions.h b/source/RobotAPI/libraries/aron/core/aron_conversions.h index 3e454465ef1720d550113cf570435bae53bb64a1..1cef1c931ff03787b3759da77cd3f64dbcd08d56 100644 --- a/source/RobotAPI/libraries/aron/core/aron_conversions.h +++ b/source/RobotAPI/libraries/aron/core/aron_conversions.h @@ -5,9 +5,10 @@ #include <optional> #include <vector> +#include "Path.h" + namespace armarx::aron { - /** * Framework for converting ARON DTOs (Data Transfer Objects) to C++ BOs * (Business Objects) and back. @@ -271,6 +272,12 @@ namespace armarx::aron } } + + + + +// And do the same for the armarx namespace to ensure consistency with all the other aron_conversions declaraions +// (which are usually in the armarx namespace) namespace armarx { // Same type