From c23d5451f9214b6dadebf123f07e1fd32394fc3d Mon Sep 17 00:00:00 2001 From: Alder Date: Fri, 31 May 2024 08:56:46 +0200 Subject: [PATCH 1/3] add new XSD headerTpe and generate classes (#1009) --- cpacs_gen_input/cpacs_schema.xsd | 146 ++++++++++++--- .../{CPACSUpdates.cpp => CPACSChangeLog.cpp} | 54 +++--- src/generated/CPACSChangeLog.h | 82 ++++++++ src/generated/CPACSHeader.cpp | 97 ++-------- src/generated/CPACSHeader.h | 41 ++-- src/generated/CPACSLogEntry.cpp | 148 +++++++++++++++ .../{CPACSUpdate.h => CPACSLogEntry.h} | 63 +++---- .../{CPACSUpdate.cpp => CPACSVersionInfo.cpp} | 175 +++++++++++------- src/generated/CPACSVersionInfo.h | 112 +++++++++++ src/generated/CPACSVersionInfos.cpp | 111 +++++++++++ .../{CPACSUpdates.h => CPACSVersionInfos.h} | 34 ++-- 11 files changed, 779 insertions(+), 284 deletions(-) rename src/generated/{CPACSUpdates.cpp => CPACSChangeLog.cpp} (50%) create mode 100644 src/generated/CPACSChangeLog.h create mode 100644 src/generated/CPACSLogEntry.cpp rename src/generated/{CPACSUpdate.h => CPACSLogEntry.h} (54%) rename src/generated/{CPACSUpdate.cpp => CPACSVersionInfo.cpp} (50%) create mode 100644 src/generated/CPACSVersionInfo.h create mode 100644 src/generated/CPACSVersionInfos.cpp rename src/generated/{CPACSUpdates.h => CPACSVersionInfos.h} (65%) diff --git a/cpacs_gen_input/cpacs_schema.xsd b/cpacs_gen_input/cpacs_schema.xsd index c60f06237..0c8f3bebb 100644 --- a/cpacs_gen_input/cpacs_schema.xsd +++ b/cpacs_gen_input/cpacs_schema.xsd @@ -823,40 +823,26 @@ marko.alder@dlr.de Name of CPACS dataset - + Description of CPACS dataset - - - Creator of initial CPACS dataset - - - - - - Timestamp of initial CPACS dataset creation - - - - + - Version of initial CPACS dataset + Version of initial CPACS dataset according to the Semantic Versioning 2.0.0 standard. - + - CPACS version that the dataset is valid to. The element is optional, since data sets - can be valid for several CPACS versions. However, we strongly recommend to assign data sets to a - specific CPACS version as far as possible, especially since some tools and libraries (e.g. TiGL) - require this specification. + DEPRECATED: Should only be set to allow TiGL to open the file until TiGL is adopted accordingly. + Will be replaced by the cpacsVersion element in versionInfos. - + @@ -34132,4 +34118,122 @@ The fuel tank volume type should also be used for the wing fuel tank + + + + + + Version Informations + + + + + + + + + + + + + + + + + + + Version Information + + + + + + + + + + CPACS version of the dataset + + + + + + Description of CPACS dataset + + + + + + Timestamp of initial CPACS dataset creation + + + + + + Creator of initial CPACS dataset + + + + + + + + + + + + + + + + Change log + + + + + + + + + + + + + + + + + + + Log entry + + + + + + + + + + Description of CPACS dataset + + + + + + Timestamp + + + + + + Creator (tool, person, etc.) + + + + + + + + diff --git a/src/generated/CPACSUpdates.cpp b/src/generated/CPACSChangeLog.cpp similarity index 50% rename from src/generated/CPACSUpdates.cpp rename to src/generated/CPACSChangeLog.cpp index 20db5a505..7a9cff29a 100644 --- a/src/generated/CPACSUpdates.cpp +++ b/src/generated/CPACSChangeLog.cpp @@ -16,9 +16,9 @@ // limitations under the License. #include -#include "CPACSHeader.h" -#include "CPACSUpdate.h" -#include "CPACSUpdates.h" +#include "CPACSChangeLog.h" +#include "CPACSLogEntry.h" +#include "CPACSVersionInfo.h" #include "CTiglError.h" #include "CTiglLogging.h" #include "CTiglUIDObject.h" @@ -28,27 +28,27 @@ namespace tigl { namespace generated { - CPACSUpdates::CPACSUpdates(CPACSHeader* parent) + CPACSChangeLog::CPACSChangeLog(CPACSVersionInfo* parent) { //assert(parent != NULL); m_parent = parent; } - CPACSUpdates::~CPACSUpdates() + CPACSChangeLog::~CPACSChangeLog() { } - const CPACSHeader* CPACSUpdates::GetParent() const + const CPACSVersionInfo* CPACSChangeLog::GetParent() const { return m_parent; } - CPACSHeader* CPACSUpdates::GetParent() + CPACSVersionInfo* CPACSChangeLog::GetParent() { return m_parent; } - const CTiglUIDObject* CPACSUpdates::GetNextUIDParent() const + const CTiglUIDObject* CPACSChangeLog::GetNextUIDParent() const { if (m_parent) { return m_parent->GetNextUIDParent(); @@ -56,7 +56,7 @@ namespace generated return nullptr; } - CTiglUIDObject* CPACSUpdates::GetNextUIDParent() + CTiglUIDObject* CPACSChangeLog::GetNextUIDParent() { if (m_parent) { return m_parent->GetNextUIDParent(); @@ -64,43 +64,43 @@ namespace generated return nullptr; } - void CPACSUpdates::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) + void CPACSChangeLog::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) { - // read element update - if (tixi::TixiCheckElement(tixiHandle, xpath + "/update")) { - tixi::TixiReadElements(tixiHandle, xpath + "/update", m_updates, 1, tixi::xsdUnbounded, this); + // read element logEntry + if (tixi::TixiCheckElement(tixiHandle, xpath + "/logEntry")) { + tixi::TixiReadElements(tixiHandle, xpath + "/logEntry", m_logEntrys, 1, tixi::xsdUnbounded, this); } } - void CPACSUpdates::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const + void CPACSChangeLog::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const { - // write element update - tixi::TixiSaveElements(tixiHandle, xpath + "/update", m_updates); + // write element logEntry + tixi::TixiSaveElements(tixiHandle, xpath + "/logEntry", m_logEntrys); } - const std::vector>& CPACSUpdates::GetUpdates() const + const std::vector>& CPACSChangeLog::GetLogEntrys() const { - return m_updates; + return m_logEntrys; } - std::vector>& CPACSUpdates::GetUpdates() + std::vector>& CPACSChangeLog::GetLogEntrys() { - return m_updates; + return m_logEntrys; } - CPACSUpdate& CPACSUpdates::AddUpdate() + CPACSLogEntry& CPACSChangeLog::AddLogEntry() { - m_updates.push_back(make_unique(this)); - return *m_updates.back(); + m_logEntrys.push_back(make_unique(this)); + return *m_logEntrys.back(); } - void CPACSUpdates::RemoveUpdate(CPACSUpdate& ref) + void CPACSChangeLog::RemoveLogEntry(CPACSLogEntry& ref) { - for (std::size_t i = 0; i < m_updates.size(); i++) { - if (m_updates[i].get() == &ref) { - m_updates.erase(m_updates.begin() + i); + for (std::size_t i = 0; i < m_logEntrys.size(); i++) { + if (m_logEntrys[i].get() == &ref) { + m_logEntrys.erase(m_logEntrys.begin() + i); return; } } diff --git a/src/generated/CPACSChangeLog.h b/src/generated/CPACSChangeLog.h new file mode 100644 index 000000000..229cd2d5e --- /dev/null +++ b/src/generated/CPACSChangeLog.h @@ -0,0 +1,82 @@ +// Copyright (c) 2020 RISC Software GmbH +// +// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). +// Do not edit, all changes are lost when files are re-generated. +// +// Licensed under the Apache License, Version 2.0 (the "License") +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include +#include +#include "tigl_internal.h" +#include "UniquePtr.h" + +namespace tigl +{ +class CTiglUIDObject; + +namespace generated +{ + class CPACSLogEntry; + class CPACSVersionInfo; + + // This class is used in: + // CPACSVersionInfo + + /// @brief Change log + /// + /// + class CPACSChangeLog + { + public: + TIGL_EXPORT CPACSChangeLog(CPACSVersionInfo* parent); + + TIGL_EXPORT virtual ~CPACSChangeLog(); + + TIGL_EXPORT CPACSVersionInfo* GetParent(); + + TIGL_EXPORT const CPACSVersionInfo* GetParent() const; + + TIGL_EXPORT virtual CTiglUIDObject* GetNextUIDParent(); + TIGL_EXPORT virtual const CTiglUIDObject* GetNextUIDParent() const; + + TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); + TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; + + TIGL_EXPORT virtual const std::vector>& GetLogEntrys() const; + TIGL_EXPORT virtual std::vector>& GetLogEntrys(); + + TIGL_EXPORT virtual CPACSLogEntry& AddLogEntry(); + TIGL_EXPORT virtual void RemoveLogEntry(CPACSLogEntry& ref); + + protected: + CPACSVersionInfo* m_parent; + + std::vector> m_logEntrys; + + private: + CPACSChangeLog(const CPACSChangeLog&) = delete; + CPACSChangeLog& operator=(const CPACSChangeLog&) = delete; + + CPACSChangeLog(CPACSChangeLog&&) = delete; + CPACSChangeLog& operator=(CPACSChangeLog&&) = delete; + }; +} // namespace generated + +// Aliases in tigl namespace +using CCPACSChangeLog = generated::CPACSChangeLog; +using CCPACSLogEntry = generated::CPACSLogEntry; +using CCPACSVersionInfo = generated::CPACSVersionInfo; +} // namespace tigl diff --git a/src/generated/CPACSHeader.cpp b/src/generated/CPACSHeader.cpp index d25e38d1e..4d042b69e 100644 --- a/src/generated/CPACSHeader.cpp +++ b/src/generated/CPACSHeader.cpp @@ -28,7 +28,7 @@ namespace tigl namespace generated { CPACSHeader::CPACSHeader(CPACSCpacs* parent) - : m_timestamp(0) + : m_versionInfos(this) { //assert(parent != NULL); m_parent = parent; @@ -85,25 +85,6 @@ namespace generated } } - // read element creator - if (tixi::TixiCheckElement(tixiHandle, xpath + "/creator")) { - m_creator = tixi::TixiGetElement(tixiHandle, xpath + "/creator"); - if (m_creator.empty()) { - LOG(WARNING) << "Required element creator is empty at xpath " << xpath; - } - } - else { - LOG(ERROR) << "Required element creator is missing at xpath " << xpath; - } - - // read element timestamp - if (tixi::TixiCheckElement(tixiHandle, xpath + "/timestamp")) { - m_timestamp = tixi::TixiGetElement(tixiHandle, xpath + "/timestamp"); - } - else { - LOG(ERROR) << "Required element timestamp is missing at xpath " << xpath; - } - // read element version if (tixi::TixiCheckElement(tixiHandle, xpath + "/version")) { m_version = tixi::TixiGetElement(tixiHandle, xpath + "/version"); @@ -123,15 +104,12 @@ namespace generated } } - // read element updates - if (tixi::TixiCheckElement(tixiHandle, xpath + "/updates")) { - m_updates = boost::in_place(this); - try { - m_updates->ReadCPACS(tixiHandle, xpath + "/updates"); - } catch(const std::exception& e) { - LOG(ERROR) << "Failed to read updates at xpath " << xpath << ": " << e.what(); - m_updates = boost::none; - } + // read element versionInfos + if (tixi::TixiCheckElement(tixiHandle, xpath + "/versionInfos")) { + m_versionInfos.ReadCPACS(tixiHandle, xpath + "/versionInfos"); + } + else { + LOG(ERROR) << "Required element versionInfos is missing at xpath " << xpath; } } @@ -153,14 +131,6 @@ namespace generated } } - // write element creator - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); - tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); - - // write element timestamp - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/timestamp"); - tixi::TixiSaveElement(tixiHandle, xpath + "/timestamp", m_timestamp); - // write element version tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/version"); tixi::TixiSaveElement(tixiHandle, xpath + "/version", m_version); @@ -176,16 +146,9 @@ namespace generated } } - // write element updates - if (m_updates) { - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/updates"); - m_updates->WriteCPACS(tixiHandle, xpath + "/updates"); - } - else { - if (tixi::TixiCheckElement(tixiHandle, xpath + "/updates")) { - tixi::TixiRemoveElement(tixiHandle, xpath + "/updates"); - } - } + // write element versionInfos + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/versionInfos"); + m_versionInfos.WriteCPACS(tixiHandle, xpath + "/versionInfos"); } @@ -209,26 +172,6 @@ namespace generated m_description = value; } - const std::string& CPACSHeader::GetCreator() const - { - return m_creator; - } - - void CPACSHeader::SetCreator(const std::string& value) - { - m_creator = value; - } - - const std::time_t& CPACSHeader::GetTimestamp() const - { - return m_timestamp; - } - - void CPACSHeader::SetTimestamp(const std::time_t& value) - { - m_timestamp = value; - } - const std::string& CPACSHeader::GetVersion() const { return m_version; @@ -249,26 +192,14 @@ namespace generated m_cpacsVersion = value; } - const boost::optional& CPACSHeader::GetUpdates() const - { - return m_updates; - } - - boost::optional& CPACSHeader::GetUpdates() - { - return m_updates; - } - - CPACSUpdates& CPACSHeader::GetUpdates(CreateIfNotExistsTag) + const CPACSVersionInfos& CPACSHeader::GetVersionInfos() const { - if (!m_updates) - m_updates = boost::in_place(this); - return *m_updates; + return m_versionInfos; } - void CPACSHeader::RemoveUpdates() + CPACSVersionInfos& CPACSHeader::GetVersionInfos() { - m_updates = boost::none; + return m_versionInfos; } } // namespace generated diff --git a/src/generated/CPACSHeader.h b/src/generated/CPACSHeader.h index b936eb464..528ac4b09 100644 --- a/src/generated/CPACSHeader.h +++ b/src/generated/CPACSHeader.h @@ -19,11 +19,9 @@ #include #include -#include #include #include -#include "CPACSUpdates.h" -#include "CreateIfNotExists.h" +#include "CPACSVersionInfos.h" #include "tigl_internal.h" namespace tigl @@ -64,49 +62,32 @@ namespace generated TIGL_EXPORT virtual const boost::optional& GetDescription() const; TIGL_EXPORT virtual void SetDescription(const boost::optional& value); - TIGL_EXPORT virtual const std::string& GetCreator() const; - TIGL_EXPORT virtual void SetCreator(const std::string& value); - - TIGL_EXPORT virtual const std::time_t& GetTimestamp() const; - TIGL_EXPORT virtual void SetTimestamp(const std::time_t& value); - TIGL_EXPORT virtual const std::string& GetVersion() const; TIGL_EXPORT virtual void SetVersion(const std::string& value); TIGL_EXPORT virtual const boost::optional& GetCpacsVersion() const; TIGL_EXPORT virtual void SetCpacsVersion(const boost::optional& value); - TIGL_EXPORT virtual const boost::optional& GetUpdates() const; - TIGL_EXPORT virtual boost::optional& GetUpdates(); - - TIGL_EXPORT virtual CPACSUpdates& GetUpdates(CreateIfNotExistsTag); - TIGL_EXPORT virtual void RemoveUpdates(); + TIGL_EXPORT virtual const CPACSVersionInfos& GetVersionInfos() const; + TIGL_EXPORT virtual CPACSVersionInfos& GetVersionInfos(); protected: CPACSCpacs* m_parent; /// Name of CPACS dataset - std::string m_name; + std::string m_name; /// Description of CPACS dataset - boost::optional m_description; - - /// Creator of initial CPACS dataset - std::string m_creator; - - /// Timestamp of initial CPACS dataset creation - std::time_t m_timestamp; + boost::optional m_description; - /// Version of initial CPACS dataset - std::string m_version; + /// Version of initial CPACS dataset according to the Semantic Versioning 2.0.0 standard. + std::string m_version; - /// CPACS version that the dataset is valid to. The element is optional, since data sets - /// can be valid for several CPACS versions. However, we strongly recommend to assign data sets to a - /// specific CPACS version as far as possible, especially since some tools and libraries (e.g. TiGL) - /// require this specification. - boost::optional m_cpacsVersion; + /// DEPRECATED: Should only be set to allow TiGL to open the file until TiGL is adopted accordingly. + /// Will be replaced by the cpacsVersion element in versionInfos. + boost::optional m_cpacsVersion; - boost::optional m_updates; + CPACSVersionInfos m_versionInfos; private: CPACSHeader(const CPACSHeader&) = delete; diff --git a/src/generated/CPACSLogEntry.cpp b/src/generated/CPACSLogEntry.cpp new file mode 100644 index 000000000..41c0cea7b --- /dev/null +++ b/src/generated/CPACSLogEntry.cpp @@ -0,0 +1,148 @@ +// Copyright (c) 2020 RISC Software GmbH +// +// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). +// Do not edit, all changes are lost when files are re-generated. +// +// Licensed under the Apache License, Version 2.0 (the "License") +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "CPACSChangeLog.h" +#include "CPACSLogEntry.h" +#include "CTiglError.h" +#include "CTiglLogging.h" +#include "CTiglUIDObject.h" +#include "TixiHelper.h" + +namespace tigl +{ +namespace generated +{ + CPACSLogEntry::CPACSLogEntry(CPACSChangeLog* parent) + : m_timestamp(0) + { + //assert(parent != NULL); + m_parent = parent; + } + + CPACSLogEntry::~CPACSLogEntry() + { + } + + const CPACSChangeLog* CPACSLogEntry::GetParent() const + { + return m_parent; + } + + CPACSChangeLog* CPACSLogEntry::GetParent() + { + return m_parent; + } + + const CTiglUIDObject* CPACSLogEntry::GetNextUIDParent() const + { + if (m_parent) { + return m_parent->GetNextUIDParent(); + } + return nullptr; + } + + CTiglUIDObject* CPACSLogEntry::GetNextUIDParent() + { + if (m_parent) { + return m_parent->GetNextUIDParent(); + } + return nullptr; + } + + void CPACSLogEntry::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) + { + // read element description + if (tixi::TixiCheckElement(tixiHandle, xpath + "/description")) { + m_description = tixi::TixiGetElement(tixiHandle, xpath + "/description"); + if (m_description.empty()) { + LOG(WARNING) << "Required element description is empty at xpath " << xpath; + } + } + else { + LOG(ERROR) << "Required element description is missing at xpath " << xpath; + } + + // read element timestamp + if (tixi::TixiCheckElement(tixiHandle, xpath + "/timestamp")) { + m_timestamp = tixi::TixiGetElement(tixiHandle, xpath + "/timestamp"); + } + else { + LOG(ERROR) << "Required element timestamp is missing at xpath " << xpath; + } + + // read element creator + if (tixi::TixiCheckElement(tixiHandle, xpath + "/creator")) { + m_creator = tixi::TixiGetElement(tixiHandle, xpath + "/creator"); + if (m_creator.empty()) { + LOG(WARNING) << "Required element creator is empty at xpath " << xpath; + } + } + else { + LOG(ERROR) << "Required element creator is missing at xpath " << xpath; + } + + } + + void CPACSLogEntry::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const + { + // write element description + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/description"); + tixi::TixiSaveElement(tixiHandle, xpath + "/description", m_description); + + // write element timestamp + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/timestamp"); + tixi::TixiSaveElement(tixiHandle, xpath + "/timestamp", m_timestamp); + + // write element creator + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); + tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); + + } + + const std::string& CPACSLogEntry::GetDescription() const + { + return m_description; + } + + void CPACSLogEntry::SetDescription(const std::string& value) + { + m_description = value; + } + + const std::time_t& CPACSLogEntry::GetTimestamp() const + { + return m_timestamp; + } + + void CPACSLogEntry::SetTimestamp(const std::time_t& value) + { + m_timestamp = value; + } + + const std::string& CPACSLogEntry::GetCreator() const + { + return m_creator; + } + + void CPACSLogEntry::SetCreator(const std::string& value) + { + m_creator = value; + } + +} // namespace generated +} // namespace tigl diff --git a/src/generated/CPACSUpdate.h b/src/generated/CPACSLogEntry.h similarity index 54% rename from src/generated/CPACSUpdate.h rename to src/generated/CPACSLogEntry.h index 85b452313..3572467ce 100644 --- a/src/generated/CPACSUpdate.h +++ b/src/generated/CPACSLogEntry.h @@ -28,26 +28,24 @@ class CTiglUIDObject; namespace generated { - class CPACSUpdates; + class CPACSChangeLog; // This class is used in: - // CPACSUpdates + // CPACSChangeLog - /// @brief updateType + /// @brief Log entry /// - /// Update type, containing a datablock for each update of - /// the CPACS dataset /// - class CPACSUpdate + class CPACSLogEntry { public: - TIGL_EXPORT CPACSUpdate(CPACSUpdates* parent); + TIGL_EXPORT CPACSLogEntry(CPACSChangeLog* parent); - TIGL_EXPORT virtual ~CPACSUpdate(); + TIGL_EXPORT virtual ~CPACSLogEntry(); - TIGL_EXPORT CPACSUpdates* GetParent(); + TIGL_EXPORT CPACSChangeLog* GetParent(); - TIGL_EXPORT const CPACSUpdates* GetParent() const; + TIGL_EXPORT const CPACSChangeLog* GetParent() const; TIGL_EXPORT virtual CTiglUIDObject* GetNextUIDParent(); TIGL_EXPORT virtual const CTiglUIDObject* GetNextUIDParent() const; @@ -55,50 +53,37 @@ namespace generated TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; - TIGL_EXPORT virtual const std::string& GetModification() const; - TIGL_EXPORT virtual void SetModification(const std::string& value); - - TIGL_EXPORT virtual const std::string& GetCreator() const; - TIGL_EXPORT virtual void SetCreator(const std::string& value); + TIGL_EXPORT virtual const std::string& GetDescription() const; + TIGL_EXPORT virtual void SetDescription(const std::string& value); TIGL_EXPORT virtual const std::time_t& GetTimestamp() const; TIGL_EXPORT virtual void SetTimestamp(const std::time_t& value); - TIGL_EXPORT virtual const std::string& GetVersion() const; - TIGL_EXPORT virtual void SetVersion(const std::string& value); - - TIGL_EXPORT virtual const std::string& GetCpacsVersion() const; - TIGL_EXPORT virtual void SetCpacsVersion(const std::string& value); + TIGL_EXPORT virtual const std::string& GetCreator() const; + TIGL_EXPORT virtual void SetCreator(const std::string& value); protected: - CPACSUpdates* m_parent; - - /// Description of Modification of CPACS data - std::string m_modification; + CPACSChangeLog* m_parent; - /// Creator of CPACS modification - std::string m_creator; + /// Description of CPACS dataset + std::string m_description; - /// Timestamp of CPACS modification + /// Timestamp std::time_t m_timestamp; - /// New version number of CPACS dataset after - /// modification - std::string m_version; - - /// CPACS version that the dataset is valid to - std::string m_cpacsVersion; + /// Creator (tool, person, etc.) + std::string m_creator; private: - CPACSUpdate(const CPACSUpdate&) = delete; - CPACSUpdate& operator=(const CPACSUpdate&) = delete; + CPACSLogEntry(const CPACSLogEntry&) = delete; + CPACSLogEntry& operator=(const CPACSLogEntry&) = delete; - CPACSUpdate(CPACSUpdate&&) = delete; - CPACSUpdate& operator=(CPACSUpdate&&) = delete; + CPACSLogEntry(CPACSLogEntry&&) = delete; + CPACSLogEntry& operator=(CPACSLogEntry&&) = delete; }; } // namespace generated // Aliases in tigl namespace -using CCPACSUpdate = generated::CPACSUpdate; -using CCPACSUpdates = generated::CPACSUpdates; +using CCPACSLogEntry = generated::CPACSLogEntry; +using CCPACSChangeLog = generated::CPACSChangeLog; } // namespace tigl diff --git a/src/generated/CPACSUpdate.cpp b/src/generated/CPACSVersionInfo.cpp similarity index 50% rename from src/generated/CPACSUpdate.cpp rename to src/generated/CPACSVersionInfo.cpp index cecbed1ec..dee52870f 100644 --- a/src/generated/CPACSUpdate.cpp +++ b/src/generated/CPACSVersionInfo.cpp @@ -16,8 +16,8 @@ // limitations under the License. #include -#include "CPACSUpdate.h" -#include "CPACSUpdates.h" +#include "CPACSVersionInfo.h" +#include "CPACSVersionInfos.h" #include "CTiglError.h" #include "CTiglLogging.h" #include "CTiglUIDObject.h" @@ -27,28 +27,28 @@ namespace tigl { namespace generated { - CPACSUpdate::CPACSUpdate(CPACSUpdates* parent) + CPACSVersionInfo::CPACSVersionInfo(CPACSVersionInfos* parent) : m_timestamp(0) { //assert(parent != NULL); m_parent = parent; } - CPACSUpdate::~CPACSUpdate() + CPACSVersionInfo::~CPACSVersionInfo() { } - const CPACSUpdates* CPACSUpdate::GetParent() const + const CPACSVersionInfos* CPACSVersionInfo::GetParent() const { return m_parent; } - CPACSUpdates* CPACSUpdate::GetParent() + CPACSVersionInfos* CPACSVersionInfo::GetParent() { return m_parent; } - const CTiglUIDObject* CPACSUpdate::GetNextUIDParent() const + const CTiglUIDObject* CPACSVersionInfo::GetNextUIDParent() const { if (m_parent) { return m_parent->GetNextUIDParent(); @@ -56,7 +56,7 @@ namespace generated return nullptr; } - CTiglUIDObject* CPACSUpdate::GetNextUIDParent() + CTiglUIDObject* CPACSVersionInfo::GetNextUIDParent() { if (m_parent) { return m_parent->GetNextUIDParent(); @@ -64,28 +64,39 @@ namespace generated return nullptr; } - void CPACSUpdate::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) + void CPACSVersionInfo::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) { - // read element modification - if (tixi::TixiCheckElement(tixiHandle, xpath + "/modification")) { - m_modification = tixi::TixiGetElement(tixiHandle, xpath + "/modification"); - if (m_modification.empty()) { - LOG(WARNING) << "Required element modification is empty at xpath " << xpath; + // read attribute version + if (tixi::TixiCheckAttribute(tixiHandle, xpath, "version")) { + m_version = tixi::TixiGetAttribute(tixiHandle, xpath, "version"); + if (m_version.empty()) { + LOG(WARNING) << "Required attribute version is empty at xpath " << xpath; } } else { - LOG(ERROR) << "Required element modification is missing at xpath " << xpath; + LOG(ERROR) << "Required attribute version is missing at xpath " << xpath; } - // read element creator - if (tixi::TixiCheckElement(tixiHandle, xpath + "/creator")) { - m_creator = tixi::TixiGetElement(tixiHandle, xpath + "/creator"); - if (m_creator.empty()) { - LOG(WARNING) << "Required element creator is empty at xpath " << xpath; + // read element cpacsVersion + if (tixi::TixiCheckElement(tixiHandle, xpath + "/cpacsVersion")) { + m_cpacsVersion = tixi::TixiGetElement(tixiHandle, xpath + "/cpacsVersion"); + if (m_cpacsVersion.empty()) { + LOG(WARNING) << "Required element cpacsVersion is empty at xpath " << xpath; } } else { - LOG(ERROR) << "Required element creator is missing at xpath " << xpath; + LOG(ERROR) << "Required element cpacsVersion is missing at xpath " << xpath; + } + + // read element description + if (tixi::TixiCheckElement(tixiHandle, xpath + "/description")) { + m_description = tixi::TixiGetElement(tixiHandle, xpath + "/description"); + if (m_description.empty()) { + LOG(WARNING) << "Required element description is empty at xpath " << xpath; + } + } + else { + LOG(ERROR) << "Required element description is missing at xpath " << xpath; } // read element timestamp @@ -96,102 +107,134 @@ namespace generated LOG(ERROR) << "Required element timestamp is missing at xpath " << xpath; } - // read element version - if (tixi::TixiCheckElement(tixiHandle, xpath + "/version")) { - m_version = tixi::TixiGetElement(tixiHandle, xpath + "/version"); - if (m_version.empty()) { - LOG(WARNING) << "Required element version is empty at xpath " << xpath; + // read element creator + if (tixi::TixiCheckElement(tixiHandle, xpath + "/creator")) { + m_creator = tixi::TixiGetElement(tixiHandle, xpath + "/creator"); + if (m_creator.empty()) { + LOG(WARNING) << "Required element creator is empty at xpath " << xpath; } } else { - LOG(ERROR) << "Required element version is missing at xpath " << xpath; + LOG(ERROR) << "Required element creator is missing at xpath " << xpath; } - // read element cpacsVersion - if (tixi::TixiCheckElement(tixiHandle, xpath + "/cpacsVersion")) { - m_cpacsVersion = tixi::TixiGetElement(tixiHandle, xpath + "/cpacsVersion"); - if (m_cpacsVersion.empty()) { - LOG(WARNING) << "Required element cpacsVersion is empty at xpath " << xpath; + // read element changeLog + if (tixi::TixiCheckElement(tixiHandle, xpath + "/changeLog")) { + m_changeLog = boost::in_place(this); + try { + m_changeLog->ReadCPACS(tixiHandle, xpath + "/changeLog"); + } catch(const std::exception& e) { + LOG(ERROR) << "Failed to read changeLog at xpath " << xpath << ": " << e.what(); + m_changeLog = boost::none; } } - else { - LOG(ERROR) << "Required element cpacsVersion is missing at xpath " << xpath; - } } - void CPACSUpdate::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const + void CPACSVersionInfo::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const { - // write element modification - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/modification"); - tixi::TixiSaveElement(tixiHandle, xpath + "/modification", m_modification); + // write attribute version + tixi::TixiSaveAttribute(tixiHandle, xpath, "version", m_version); - // write element creator - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); - tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); + // write element cpacsVersion + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/cpacsVersion"); + tixi::TixiSaveElement(tixiHandle, xpath + "/cpacsVersion", m_cpacsVersion); + + // write element description + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/description"); + tixi::TixiSaveElement(tixiHandle, xpath + "/description", m_description); // write element timestamp tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/timestamp"); tixi::TixiSaveElement(tixiHandle, xpath + "/timestamp", m_timestamp); - // write element version - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/version"); - tixi::TixiSaveElement(tixiHandle, xpath + "/version", m_version); + // write element creator + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); + tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); - // write element cpacsVersion - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/cpacsVersion"); - tixi::TixiSaveElement(tixiHandle, xpath + "/cpacsVersion", m_cpacsVersion); + // write element changeLog + if (m_changeLog) { + tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/changeLog"); + m_changeLog->WriteCPACS(tixiHandle, xpath + "/changeLog"); + } + else { + if (tixi::TixiCheckElement(tixiHandle, xpath + "/changeLog")) { + tixi::TixiRemoveElement(tixiHandle, xpath + "/changeLog"); + } + } } - const std::string& CPACSUpdate::GetModification() const + const std::string& CPACSVersionInfo::GetVersion() const { - return m_modification; + return m_version; } - void CPACSUpdate::SetModification(const std::string& value) + void CPACSVersionInfo::SetVersion(const std::string& value) { - m_modification = value; + m_version = value; } - const std::string& CPACSUpdate::GetCreator() const + const std::string& CPACSVersionInfo::GetCpacsVersion() const { - return m_creator; + return m_cpacsVersion; } - void CPACSUpdate::SetCreator(const std::string& value) + void CPACSVersionInfo::SetCpacsVersion(const std::string& value) { - m_creator = value; + m_cpacsVersion = value; } - const std::time_t& CPACSUpdate::GetTimestamp() const + const std::string& CPACSVersionInfo::GetDescription() const + { + return m_description; + } + + void CPACSVersionInfo::SetDescription(const std::string& value) + { + m_description = value; + } + + const std::time_t& CPACSVersionInfo::GetTimestamp() const { return m_timestamp; } - void CPACSUpdate::SetTimestamp(const std::time_t& value) + void CPACSVersionInfo::SetTimestamp(const std::time_t& value) { m_timestamp = value; } - const std::string& CPACSUpdate::GetVersion() const + const std::string& CPACSVersionInfo::GetCreator() const { - return m_version; + return m_creator; } - void CPACSUpdate::SetVersion(const std::string& value) + void CPACSVersionInfo::SetCreator(const std::string& value) { - m_version = value; + m_creator = value; } - const std::string& CPACSUpdate::GetCpacsVersion() const + const boost::optional& CPACSVersionInfo::GetChangeLog() const { - return m_cpacsVersion; + return m_changeLog; } - void CPACSUpdate::SetCpacsVersion(const std::string& value) + boost::optional& CPACSVersionInfo::GetChangeLog() { - m_cpacsVersion = value; + return m_changeLog; + } + + CPACSChangeLog& CPACSVersionInfo::GetChangeLog(CreateIfNotExistsTag) + { + if (!m_changeLog) + m_changeLog = boost::in_place(this); + return *m_changeLog; + } + + void CPACSVersionInfo::RemoveChangeLog() + { + m_changeLog = boost::none; } } // namespace generated diff --git a/src/generated/CPACSVersionInfo.h b/src/generated/CPACSVersionInfo.h new file mode 100644 index 000000000..7e513a6cd --- /dev/null +++ b/src/generated/CPACSVersionInfo.h @@ -0,0 +1,112 @@ +// Copyright (c) 2020 RISC Software GmbH +// +// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). +// Do not edit, all changes are lost when files are re-generated. +// +// Licensed under the Apache License, Version 2.0 (the "License") +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include +#include +#include +#include +#include "CPACSChangeLog.h" +#include "CreateIfNotExists.h" +#include "tigl_internal.h" + +namespace tigl +{ +class CTiglUIDObject; + +namespace generated +{ + class CPACSVersionInfos; + + // This class is used in: + // CPACSVersionInfos + + /// @brief Version Information + /// + /// + class CPACSVersionInfo + { + public: + TIGL_EXPORT CPACSVersionInfo(CPACSVersionInfos* parent); + + TIGL_EXPORT virtual ~CPACSVersionInfo(); + + TIGL_EXPORT CPACSVersionInfos* GetParent(); + + TIGL_EXPORT const CPACSVersionInfos* GetParent() const; + + TIGL_EXPORT virtual CTiglUIDObject* GetNextUIDParent(); + TIGL_EXPORT virtual const CTiglUIDObject* GetNextUIDParent() const; + + TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); + TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; + + TIGL_EXPORT virtual const std::string& GetVersion() const; + TIGL_EXPORT virtual void SetVersion(const std::string& value); + + TIGL_EXPORT virtual const std::string& GetCpacsVersion() const; + TIGL_EXPORT virtual void SetCpacsVersion(const std::string& value); + + TIGL_EXPORT virtual const std::string& GetDescription() const; + TIGL_EXPORT virtual void SetDescription(const std::string& value); + + TIGL_EXPORT virtual const std::time_t& GetTimestamp() const; + TIGL_EXPORT virtual void SetTimestamp(const std::time_t& value); + + TIGL_EXPORT virtual const std::string& GetCreator() const; + TIGL_EXPORT virtual void SetCreator(const std::string& value); + + TIGL_EXPORT virtual const boost::optional& GetChangeLog() const; + TIGL_EXPORT virtual boost::optional& GetChangeLog(); + + TIGL_EXPORT virtual CPACSChangeLog& GetChangeLog(CreateIfNotExistsTag); + TIGL_EXPORT virtual void RemoveChangeLog(); + + protected: + CPACSVersionInfos* m_parent; + + std::string m_version; + + /// CPACS version of the dataset + std::string m_cpacsVersion; + + /// Description of CPACS dataset + std::string m_description; + + /// Timestamp of initial CPACS dataset creation + std::time_t m_timestamp; + + /// Creator of initial CPACS dataset + std::string m_creator; + + boost::optional m_changeLog; + + private: + CPACSVersionInfo(const CPACSVersionInfo&) = delete; + CPACSVersionInfo& operator=(const CPACSVersionInfo&) = delete; + + CPACSVersionInfo(CPACSVersionInfo&&) = delete; + CPACSVersionInfo& operator=(CPACSVersionInfo&&) = delete; + }; +} // namespace generated + +// Aliases in tigl namespace +using CCPACSVersionInfo = generated::CPACSVersionInfo; +using CCPACSVersionInfos = generated::CPACSVersionInfos; +} // namespace tigl diff --git a/src/generated/CPACSVersionInfos.cpp b/src/generated/CPACSVersionInfos.cpp new file mode 100644 index 000000000..5158462fa --- /dev/null +++ b/src/generated/CPACSVersionInfos.cpp @@ -0,0 +1,111 @@ +// Copyright (c) 2020 RISC Software GmbH +// +// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). +// Do not edit, all changes are lost when files are re-generated. +// +// Licensed under the Apache License, Version 2.0 (the "License") +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "CPACSHeader.h" +#include "CPACSVersionInfo.h" +#include "CPACSVersionInfos.h" +#include "CTiglError.h" +#include "CTiglLogging.h" +#include "CTiglUIDObject.h" +#include "TixiHelper.h" + +namespace tigl +{ +namespace generated +{ + CPACSVersionInfos::CPACSVersionInfos(CPACSHeader* parent) + { + //assert(parent != NULL); + m_parent = parent; + } + + CPACSVersionInfos::~CPACSVersionInfos() + { + } + + const CPACSHeader* CPACSVersionInfos::GetParent() const + { + return m_parent; + } + + CPACSHeader* CPACSVersionInfos::GetParent() + { + return m_parent; + } + + const CTiglUIDObject* CPACSVersionInfos::GetNextUIDParent() const + { + if (m_parent) { + return m_parent->GetNextUIDParent(); + } + return nullptr; + } + + CTiglUIDObject* CPACSVersionInfos::GetNextUIDParent() + { + if (m_parent) { + return m_parent->GetNextUIDParent(); + } + return nullptr; + } + + void CPACSVersionInfos::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) + { + // read element versionInfo + if (tixi::TixiCheckElement(tixiHandle, xpath + "/versionInfo")) { + tixi::TixiReadElements(tixiHandle, xpath + "/versionInfo", m_versionInfos, 1, tixi::xsdUnbounded, this); + } + + } + + void CPACSVersionInfos::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const + { + // write element versionInfo + tixi::TixiSaveElements(tixiHandle, xpath + "/versionInfo", m_versionInfos); + + } + + const std::vector>& CPACSVersionInfos::GetVersionInfos() const + { + return m_versionInfos; + } + + std::vector>& CPACSVersionInfos::GetVersionInfos() + { + return m_versionInfos; + } + + CPACSVersionInfo& CPACSVersionInfos::AddVersionInfo() + { + m_versionInfos.push_back(make_unique(this)); + return *m_versionInfos.back(); + } + + void CPACSVersionInfos::RemoveVersionInfo(CPACSVersionInfo& ref) + { + for (std::size_t i = 0; i < m_versionInfos.size(); i++) { + if (m_versionInfos[i].get() == &ref) { + m_versionInfos.erase(m_versionInfos.begin() + i); + return; + } + } + throw CTiglError("Element not found"); + } + +} // namespace generated +} // namespace tigl diff --git a/src/generated/CPACSUpdates.h b/src/generated/CPACSVersionInfos.h similarity index 65% rename from src/generated/CPACSUpdates.h rename to src/generated/CPACSVersionInfos.h index 451c443cf..cfc5915da 100644 --- a/src/generated/CPACSUpdates.h +++ b/src/generated/CPACSVersionInfos.h @@ -29,23 +29,21 @@ class CTiglUIDObject; namespace generated { - class CPACSUpdate; + class CPACSVersionInfo; class CPACSHeader; // This class is used in: // CPACSHeader - /// @brief updatesType + /// @brief Version Informations /// - /// Updates type, containing update data for the CPACS - /// dataset /// - class CPACSUpdates + class CPACSVersionInfos { public: - TIGL_EXPORT CPACSUpdates(CPACSHeader* parent); + TIGL_EXPORT CPACSVersionInfos(CPACSHeader* parent); - TIGL_EXPORT virtual ~CPACSUpdates(); + TIGL_EXPORT virtual ~CPACSVersionInfos(); TIGL_EXPORT CPACSHeader* GetParent(); @@ -57,28 +55,28 @@ namespace generated TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; - TIGL_EXPORT virtual const std::vector>& GetUpdates() const; - TIGL_EXPORT virtual std::vector>& GetUpdates(); + TIGL_EXPORT virtual const std::vector>& GetVersionInfos() const; + TIGL_EXPORT virtual std::vector>& GetVersionInfos(); - TIGL_EXPORT virtual CPACSUpdate& AddUpdate(); - TIGL_EXPORT virtual void RemoveUpdate(CPACSUpdate& ref); + TIGL_EXPORT virtual CPACSVersionInfo& AddVersionInfo(); + TIGL_EXPORT virtual void RemoveVersionInfo(CPACSVersionInfo& ref); protected: CPACSHeader* m_parent; - std::vector> m_updates; + std::vector> m_versionInfos; private: - CPACSUpdates(const CPACSUpdates&) = delete; - CPACSUpdates& operator=(const CPACSUpdates&) = delete; + CPACSVersionInfos(const CPACSVersionInfos&) = delete; + CPACSVersionInfos& operator=(const CPACSVersionInfos&) = delete; - CPACSUpdates(CPACSUpdates&&) = delete; - CPACSUpdates& operator=(CPACSUpdates&&) = delete; + CPACSVersionInfos(CPACSVersionInfos&&) = delete; + CPACSVersionInfos& operator=(CPACSVersionInfos&&) = delete; }; } // namespace generated // Aliases in tigl namespace -using CCPACSUpdates = generated::CPACSUpdates; -using CCPACSUpdate = generated::CPACSUpdate; +using CCPACSVersionInfos = generated::CPACSVersionInfos; +using CCPACSVersionInfo = generated::CPACSVersionInfo; using CCPACSHeader = generated::CPACSHeader; } // namespace tigl From fecb70059c3e2f2e47ab67b5405c74ab5fcaf879 Mon Sep 17 00:00:00 2001 From: Alder Date: Fri, 31 May 2024 12:39:10 +0200 Subject: [PATCH 2/3] fix error if CPACS version is under versionInfos --- bindings/python_internal/core.i | 6 +- cpacs_gen_input/PruneList.txt | 3 + src/api/tigl.cpp | 6 +- src/generated/CPACSChangeLog.cpp | 111 ------------- src/generated/CPACSChangeLog.h | 82 ---------- src/generated/CPACSLogEntry.cpp | 148 ------------------ src/generated/CPACSLogEntry.h | 89 ----------- src/generated/CPACSVersionInfo.cpp | 44 ------ src/generated/CPACSVersionInfo.h | 22 +-- .../TestData/testversion_new_header.xml | 28 ++++ tests/unittests/testCpacsVersion.cpp | 10 ++ 11 files changed, 55 insertions(+), 494 deletions(-) delete mode 100644 src/generated/CPACSChangeLog.cpp delete mode 100644 src/generated/CPACSChangeLog.h delete mode 100644 src/generated/CPACSLogEntry.cpp delete mode 100644 src/generated/CPACSLogEntry.h create mode 100644 tests/unittests/TestData/testversion_new_header.xml diff --git a/bindings/python_internal/core.i b/bindings/python_internal/core.i index 5bc574624..ed27e0195 100644 --- a/bindings/python_internal/core.i +++ b/bindings/python_internal/core.i @@ -27,7 +27,8 @@ #include "CTiglMemoryPool.h" #include "CTiglError.h" #include "CCPACSStringVector.h" -#include "generated/CPACSUpdates.h" +#include "generated/CPACSVersionInfo.h" +#include "generated/CPACSVersionInfos.h" #include "generated/CPACSHeader.h" #include "CTiglUIDObject.h" #include "ITiglUIDRefObject.h" @@ -49,6 +50,7 @@ %include "CTiglMemoryPool.h" %include "generated/CPACSStringVectorBase.h" %include "CCPACSStringVector.h" -%include "generated/CPACSUpdates.h" +%include "generated/CPACSVersionInfo.h" +%include "generated/CPACSVersionInfos.h" %include "generated/CPACSHeader.h" diff --git a/cpacs_gen_input/PruneList.txt b/cpacs_gen_input/PruneList.txt index 05cf95c59..5661c9373 100644 --- a/cpacs_gen_input/PruneList.txt +++ b/cpacs_gen_input/PruneList.txt @@ -7,6 +7,9 @@ CPACSMissionDefinitions CPACSStudies CPACSMaterial +// in header +CPACSChangeLog + // in toolspecific CPACSToolspecific diff --git a/src/api/tigl.cpp b/src/api/tigl.cpp index b5ff085cf..eab4db502 100644 --- a/src/api/tigl.cpp +++ b/src/api/tigl.cpp @@ -171,7 +171,11 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglOpenCPACSConfiguration(TixiDocumentHandle /* check CPACS Version */ { char* cpacsVersionStr = NULL; - ReturnCode tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/cpacsVersion", &cpacsVersionStr); + ReturnCode tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/versionInfos/versionInfo[@version=../../version]/cpacsVersion", &cpacsVersionStr); + + if (tixiRet != SUCCESS) { + tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/cpacsVersion", &cpacsVersionStr); + } if (tixiRet != SUCCESS) { // NO CPACS Version Information in Header diff --git a/src/generated/CPACSChangeLog.cpp b/src/generated/CPACSChangeLog.cpp deleted file mode 100644 index 7a9cff29a..000000000 --- a/src/generated/CPACSChangeLog.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2020 RISC Software GmbH -// -// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). -// Do not edit, all changes are lost when files are re-generated. -// -// Licensed under the Apache License, Version 2.0 (the "License") -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "CPACSChangeLog.h" -#include "CPACSLogEntry.h" -#include "CPACSVersionInfo.h" -#include "CTiglError.h" -#include "CTiglLogging.h" -#include "CTiglUIDObject.h" -#include "TixiHelper.h" - -namespace tigl -{ -namespace generated -{ - CPACSChangeLog::CPACSChangeLog(CPACSVersionInfo* parent) - { - //assert(parent != NULL); - m_parent = parent; - } - - CPACSChangeLog::~CPACSChangeLog() - { - } - - const CPACSVersionInfo* CPACSChangeLog::GetParent() const - { - return m_parent; - } - - CPACSVersionInfo* CPACSChangeLog::GetParent() - { - return m_parent; - } - - const CTiglUIDObject* CPACSChangeLog::GetNextUIDParent() const - { - if (m_parent) { - return m_parent->GetNextUIDParent(); - } - return nullptr; - } - - CTiglUIDObject* CPACSChangeLog::GetNextUIDParent() - { - if (m_parent) { - return m_parent->GetNextUIDParent(); - } - return nullptr; - } - - void CPACSChangeLog::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) - { - // read element logEntry - if (tixi::TixiCheckElement(tixiHandle, xpath + "/logEntry")) { - tixi::TixiReadElements(tixiHandle, xpath + "/logEntry", m_logEntrys, 1, tixi::xsdUnbounded, this); - } - - } - - void CPACSChangeLog::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const - { - // write element logEntry - tixi::TixiSaveElements(tixiHandle, xpath + "/logEntry", m_logEntrys); - - } - - const std::vector>& CPACSChangeLog::GetLogEntrys() const - { - return m_logEntrys; - } - - std::vector>& CPACSChangeLog::GetLogEntrys() - { - return m_logEntrys; - } - - CPACSLogEntry& CPACSChangeLog::AddLogEntry() - { - m_logEntrys.push_back(make_unique(this)); - return *m_logEntrys.back(); - } - - void CPACSChangeLog::RemoveLogEntry(CPACSLogEntry& ref) - { - for (std::size_t i = 0; i < m_logEntrys.size(); i++) { - if (m_logEntrys[i].get() == &ref) { - m_logEntrys.erase(m_logEntrys.begin() + i); - return; - } - } - throw CTiglError("Element not found"); - } - -} // namespace generated -} // namespace tigl diff --git a/src/generated/CPACSChangeLog.h b/src/generated/CPACSChangeLog.h deleted file mode 100644 index 229cd2d5e..000000000 --- a/src/generated/CPACSChangeLog.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2020 RISC Software GmbH -// -// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). -// Do not edit, all changes are lost when files are re-generated. -// -// Licensed under the Apache License, Version 2.0 (the "License") -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include -#include "tigl_internal.h" -#include "UniquePtr.h" - -namespace tigl -{ -class CTiglUIDObject; - -namespace generated -{ - class CPACSLogEntry; - class CPACSVersionInfo; - - // This class is used in: - // CPACSVersionInfo - - /// @brief Change log - /// - /// - class CPACSChangeLog - { - public: - TIGL_EXPORT CPACSChangeLog(CPACSVersionInfo* parent); - - TIGL_EXPORT virtual ~CPACSChangeLog(); - - TIGL_EXPORT CPACSVersionInfo* GetParent(); - - TIGL_EXPORT const CPACSVersionInfo* GetParent() const; - - TIGL_EXPORT virtual CTiglUIDObject* GetNextUIDParent(); - TIGL_EXPORT virtual const CTiglUIDObject* GetNextUIDParent() const; - - TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); - TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; - - TIGL_EXPORT virtual const std::vector>& GetLogEntrys() const; - TIGL_EXPORT virtual std::vector>& GetLogEntrys(); - - TIGL_EXPORT virtual CPACSLogEntry& AddLogEntry(); - TIGL_EXPORT virtual void RemoveLogEntry(CPACSLogEntry& ref); - - protected: - CPACSVersionInfo* m_parent; - - std::vector> m_logEntrys; - - private: - CPACSChangeLog(const CPACSChangeLog&) = delete; - CPACSChangeLog& operator=(const CPACSChangeLog&) = delete; - - CPACSChangeLog(CPACSChangeLog&&) = delete; - CPACSChangeLog& operator=(CPACSChangeLog&&) = delete; - }; -} // namespace generated - -// Aliases in tigl namespace -using CCPACSChangeLog = generated::CPACSChangeLog; -using CCPACSLogEntry = generated::CPACSLogEntry; -using CCPACSVersionInfo = generated::CPACSVersionInfo; -} // namespace tigl diff --git a/src/generated/CPACSLogEntry.cpp b/src/generated/CPACSLogEntry.cpp deleted file mode 100644 index 41c0cea7b..000000000 --- a/src/generated/CPACSLogEntry.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) 2020 RISC Software GmbH -// -// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). -// Do not edit, all changes are lost when files are re-generated. -// -// Licensed under the Apache License, Version 2.0 (the "License") -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "CPACSChangeLog.h" -#include "CPACSLogEntry.h" -#include "CTiglError.h" -#include "CTiglLogging.h" -#include "CTiglUIDObject.h" -#include "TixiHelper.h" - -namespace tigl -{ -namespace generated -{ - CPACSLogEntry::CPACSLogEntry(CPACSChangeLog* parent) - : m_timestamp(0) - { - //assert(parent != NULL); - m_parent = parent; - } - - CPACSLogEntry::~CPACSLogEntry() - { - } - - const CPACSChangeLog* CPACSLogEntry::GetParent() const - { - return m_parent; - } - - CPACSChangeLog* CPACSLogEntry::GetParent() - { - return m_parent; - } - - const CTiglUIDObject* CPACSLogEntry::GetNextUIDParent() const - { - if (m_parent) { - return m_parent->GetNextUIDParent(); - } - return nullptr; - } - - CTiglUIDObject* CPACSLogEntry::GetNextUIDParent() - { - if (m_parent) { - return m_parent->GetNextUIDParent(); - } - return nullptr; - } - - void CPACSLogEntry::ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) - { - // read element description - if (tixi::TixiCheckElement(tixiHandle, xpath + "/description")) { - m_description = tixi::TixiGetElement(tixiHandle, xpath + "/description"); - if (m_description.empty()) { - LOG(WARNING) << "Required element description is empty at xpath " << xpath; - } - } - else { - LOG(ERROR) << "Required element description is missing at xpath " << xpath; - } - - // read element timestamp - if (tixi::TixiCheckElement(tixiHandle, xpath + "/timestamp")) { - m_timestamp = tixi::TixiGetElement(tixiHandle, xpath + "/timestamp"); - } - else { - LOG(ERROR) << "Required element timestamp is missing at xpath " << xpath; - } - - // read element creator - if (tixi::TixiCheckElement(tixiHandle, xpath + "/creator")) { - m_creator = tixi::TixiGetElement(tixiHandle, xpath + "/creator"); - if (m_creator.empty()) { - LOG(WARNING) << "Required element creator is empty at xpath " << xpath; - } - } - else { - LOG(ERROR) << "Required element creator is missing at xpath " << xpath; - } - - } - - void CPACSLogEntry::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const - { - // write element description - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/description"); - tixi::TixiSaveElement(tixiHandle, xpath + "/description", m_description); - - // write element timestamp - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/timestamp"); - tixi::TixiSaveElement(tixiHandle, xpath + "/timestamp", m_timestamp); - - // write element creator - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); - tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); - - } - - const std::string& CPACSLogEntry::GetDescription() const - { - return m_description; - } - - void CPACSLogEntry::SetDescription(const std::string& value) - { - m_description = value; - } - - const std::time_t& CPACSLogEntry::GetTimestamp() const - { - return m_timestamp; - } - - void CPACSLogEntry::SetTimestamp(const std::time_t& value) - { - m_timestamp = value; - } - - const std::string& CPACSLogEntry::GetCreator() const - { - return m_creator; - } - - void CPACSLogEntry::SetCreator(const std::string& value) - { - m_creator = value; - } - -} // namespace generated -} // namespace tigl diff --git a/src/generated/CPACSLogEntry.h b/src/generated/CPACSLogEntry.h deleted file mode 100644 index 3572467ce..000000000 --- a/src/generated/CPACSLogEntry.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2020 RISC Software GmbH -// -// This file was generated by CPACSGen from CPACS XML Schema (c) German Aerospace Center (DLR/SC). -// Do not edit, all changes are lost when files are re-generated. -// -// Licensed under the Apache License, Version 2.0 (the "License") -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include -#include -#include -#include "tigl_internal.h" - -namespace tigl -{ -class CTiglUIDObject; - -namespace generated -{ - class CPACSChangeLog; - - // This class is used in: - // CPACSChangeLog - - /// @brief Log entry - /// - /// - class CPACSLogEntry - { - public: - TIGL_EXPORT CPACSLogEntry(CPACSChangeLog* parent); - - TIGL_EXPORT virtual ~CPACSLogEntry(); - - TIGL_EXPORT CPACSChangeLog* GetParent(); - - TIGL_EXPORT const CPACSChangeLog* GetParent() const; - - TIGL_EXPORT virtual CTiglUIDObject* GetNextUIDParent(); - TIGL_EXPORT virtual const CTiglUIDObject* GetNextUIDParent() const; - - TIGL_EXPORT virtual void ReadCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath); - TIGL_EXPORT virtual void WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const; - - TIGL_EXPORT virtual const std::string& GetDescription() const; - TIGL_EXPORT virtual void SetDescription(const std::string& value); - - TIGL_EXPORT virtual const std::time_t& GetTimestamp() const; - TIGL_EXPORT virtual void SetTimestamp(const std::time_t& value); - - TIGL_EXPORT virtual const std::string& GetCreator() const; - TIGL_EXPORT virtual void SetCreator(const std::string& value); - - protected: - CPACSChangeLog* m_parent; - - /// Description of CPACS dataset - std::string m_description; - - /// Timestamp - std::time_t m_timestamp; - - /// Creator (tool, person, etc.) - std::string m_creator; - - private: - CPACSLogEntry(const CPACSLogEntry&) = delete; - CPACSLogEntry& operator=(const CPACSLogEntry&) = delete; - - CPACSLogEntry(CPACSLogEntry&&) = delete; - CPACSLogEntry& operator=(CPACSLogEntry&&) = delete; - }; -} // namespace generated - -// Aliases in tigl namespace -using CCPACSLogEntry = generated::CPACSLogEntry; -using CCPACSChangeLog = generated::CPACSChangeLog; -} // namespace tigl diff --git a/src/generated/CPACSVersionInfo.cpp b/src/generated/CPACSVersionInfo.cpp index dee52870f..595de8975 100644 --- a/src/generated/CPACSVersionInfo.cpp +++ b/src/generated/CPACSVersionInfo.cpp @@ -118,17 +118,6 @@ namespace generated LOG(ERROR) << "Required element creator is missing at xpath " << xpath; } - // read element changeLog - if (tixi::TixiCheckElement(tixiHandle, xpath + "/changeLog")) { - m_changeLog = boost::in_place(this); - try { - m_changeLog->ReadCPACS(tixiHandle, xpath + "/changeLog"); - } catch(const std::exception& e) { - LOG(ERROR) << "Failed to read changeLog at xpath " << xpath << ": " << e.what(); - m_changeLog = boost::none; - } - } - } void CPACSVersionInfo::WriteCPACS(const TixiDocumentHandle& tixiHandle, const std::string& xpath) const @@ -152,17 +141,6 @@ namespace generated tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/creator"); tixi::TixiSaveElement(tixiHandle, xpath + "/creator", m_creator); - // write element changeLog - if (m_changeLog) { - tixi::TixiCreateElementIfNotExists(tixiHandle, xpath + "/changeLog"); - m_changeLog->WriteCPACS(tixiHandle, xpath + "/changeLog"); - } - else { - if (tixi::TixiCheckElement(tixiHandle, xpath + "/changeLog")) { - tixi::TixiRemoveElement(tixiHandle, xpath + "/changeLog"); - } - } - } const std::string& CPACSVersionInfo::GetVersion() const @@ -215,27 +193,5 @@ namespace generated m_creator = value; } - const boost::optional& CPACSVersionInfo::GetChangeLog() const - { - return m_changeLog; - } - - boost::optional& CPACSVersionInfo::GetChangeLog() - { - return m_changeLog; - } - - CPACSChangeLog& CPACSVersionInfo::GetChangeLog(CreateIfNotExistsTag) - { - if (!m_changeLog) - m_changeLog = boost::in_place(this); - return *m_changeLog; - } - - void CPACSVersionInfo::RemoveChangeLog() - { - m_changeLog = boost::none; - } - } // namespace generated } // namespace tigl diff --git a/src/generated/CPACSVersionInfo.h b/src/generated/CPACSVersionInfo.h index 7e513a6cd..4705c5f01 100644 --- a/src/generated/CPACSVersionInfo.h +++ b/src/generated/CPACSVersionInfo.h @@ -17,13 +17,9 @@ #pragma once -#include -#include #include #include #include -#include "CPACSChangeLog.h" -#include "CreateIfNotExists.h" #include "tigl_internal.h" namespace tigl @@ -72,30 +68,22 @@ namespace generated TIGL_EXPORT virtual const std::string& GetCreator() const; TIGL_EXPORT virtual void SetCreator(const std::string& value); - TIGL_EXPORT virtual const boost::optional& GetChangeLog() const; - TIGL_EXPORT virtual boost::optional& GetChangeLog(); - - TIGL_EXPORT virtual CPACSChangeLog& GetChangeLog(CreateIfNotExistsTag); - TIGL_EXPORT virtual void RemoveChangeLog(); - protected: CPACSVersionInfos* m_parent; - std::string m_version; + std::string m_version; /// CPACS version of the dataset - std::string m_cpacsVersion; + std::string m_cpacsVersion; /// Description of CPACS dataset - std::string m_description; + std::string m_description; /// Timestamp of initial CPACS dataset creation - std::time_t m_timestamp; + std::time_t m_timestamp; /// Creator of initial CPACS dataset - std::string m_creator; - - boost::optional m_changeLog; + std::string m_creator; private: CPACSVersionInfo(const CPACSVersionInfo&) = delete; diff --git a/tests/unittests/TestData/testversion_new_header.xml b/tests/unittests/TestData/testversion_new_header.xml new file mode 100644 index 000000000..da1d9613b --- /dev/null +++ b/tests/unittests/TestData/testversion_new_header.xml @@ -0,0 +1,28 @@ + + +
+ Cpacs2Test + Test file to check versioning according to new CPACS header + 2.0.0 + + + Test for version 2.0.0 + 3.5 + Marko Alder + 2024-05-31T10:00:00 + + + Test for version 1.0.0 + 3.3 + Marko Alder + 2024-05-30T10:00:00 + + +
+ + + + + + +
diff --git a/tests/unittests/testCpacsVersion.cpp b/tests/unittests/testCpacsVersion.cpp index 7ecf89e0a..8c9a0e64f 100644 --- a/tests/unittests/testCpacsVersion.cpp +++ b/tests/unittests/testCpacsVersion.cpp @@ -60,3 +60,13 @@ TEST(CPACSVersion, noCPACSVersion) tiglCloseCPACSConfiguration(tiglHandle); } + +TEST(CPACSVersion, newCPACSHeader) +{ + TixiHandleWrapper tixihandle("TestData/testversion_new_header.xml"); + + TiglCPACSConfigurationHandle tiglHandle = -1; + EXPECT_EQ(TIGL_SUCCESS, tiglOpenCPACSConfiguration(tixihandle, "", &tiglHandle)); + + tiglCloseCPACSConfiguration(tiglHandle); +} From fbbdcdf112df5ae596d9ad5073180d0cd22efd21 Mon Sep 17 00:00:00 2001 From: Alder Date: Fri, 31 May 2024 13:12:34 +0200 Subject: [PATCH 3/3] add documentation strings --- src/api/tigl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/tigl.cpp b/src/api/tigl.cpp index eab4db502..51972b3e3 100644 --- a/src/api/tigl.cpp +++ b/src/api/tigl.cpp @@ -171,8 +171,12 @@ TIGL_COMMON_EXPORT TiglReturnCode tiglOpenCPACSConfiguration(TixiDocumentHandle /* check CPACS Version */ { char* cpacsVersionStr = NULL; + + // Default behavior: CPACS versioning since v3.5 ReturnCode tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/versionInfos/versionInfo[@version=../../version]/cpacsVersion", &cpacsVersionStr); + // CPACS versioning until v3.4 + // Note: should return a deprication warning when TiGL is at v3.5 if (tixiRet != SUCCESS) { tixiRet = tixiGetTextElement(tixiHandle, "/cpacs/header/cpacsVersion", &cpacsVersionStr); }