Skip to content

Commit b66b1c8

Browse files
authored
Add support for ssd::SystemGeometry (#1456)
1 parent e52118b commit b66b1c8

6 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/OMSimulatorLib/System.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ oms::System::System(const oms::ComRef& cref, oms_system_enu_t type, oms::Model*
7373

7474
oms::System::~System()
7575
{
76+
if (system_geometry)
77+
delete system_geometry;
78+
7679
for (const auto& connector : connectors)
7780
if (connector)
7881
delete connector;
@@ -671,6 +674,9 @@ oms_status_enu_t oms::System::exportToSSD(pugi::xml_node& node, Snapshot& snapsh
671674
if (oms_status_ok != element.getGeometry()->exportToSSD(node))
672675
return logError("export of system ElementGeometry failed");
673676

677+
if (system_geometry)
678+
system_geometry->exportToSSD(node);
679+
674680
// export top level system connectors
675681
if (connectors.size() > 1)
676682
{
@@ -804,6 +810,12 @@ oms_status_enu_t oms::System::importFromSnapshot(const pugi::xml_node& node, con
804810
geometry.importFromSSD(*it);
805811
setGeometry(geometry);
806812
}
813+
else if (name == oms::ssp::Draft20180219::ssd::system_geometry)
814+
{
815+
if (!system_geometry)
816+
system_geometry = new oms::ssd::SystemGeometry();
817+
system_geometry->importFromSSD(*it);
818+
}
807819
else if (name == oms::ssp::Version1_0::ssd::parameter_bindings) // parameter bindings provided either as inline or .ssv files
808820
{
809821
Values resources; // create a list of <ssd:ParameterBindings>

src/OMSimulatorLib/System.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "ResultWriter.h"
4444
#include "Snapshot.h"
4545
#include "ssd/ConnectorGeometry.h"
46+
#include "ssd/SystemGeometry.h"
4647
#if !defined(NO_TLM)
4748
#include "TLMBusConnector.h"
4849
#endif
@@ -248,6 +249,8 @@ namespace oms
248249
Values values; ///< system level connectors, parameters and their start values defined before instantiating the FMU and external inputs defined after initialization
249250

250251
Element element;
252+
ssd::SystemGeometry* system_geometry = NULL;
253+
251254
std::vector<Connector*> connectors; ///< last element is always NULL
252255
std::vector<oms_element_t*> subelements; ///< last element is always NULL; don't free it
253256
std::vector<BusConnector*> busconnectors;

src/OMSimulatorLib/ssd/SystemGeometry.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "SystemGeometry.h"
3333
#include "../Logging.h"
34+
#include "Tags.h"
3435

3536
#include <string.h>
3637

@@ -74,3 +75,28 @@ oms::ssd::SystemGeometry& oms::ssd::SystemGeometry::operator=(oms::ssd::SystemGe
7475

7576
return *this;
7677
}
78+
79+
oms_status_enu_t oms::ssd::SystemGeometry::exportToSSD(pugi::xml_node& root) const
80+
{
81+
// export ssd:ElementGeometry
82+
if (x1 != 0.0 && y1 != 0.0 && x2 != 0.0 && y2 != 0.0)
83+
{
84+
pugi::xml_node node = root.append_child(oms::ssp::Draft20180219::ssd::system_geometry);
85+
node.append_attribute("x1") = std::to_string(x1).c_str();
86+
node.append_attribute("y1") = std::to_string(y1).c_str();
87+
node.append_attribute("x2") = std::to_string(x2).c_str();
88+
node.append_attribute("y2") = std::to_string(y2).c_str();
89+
}
90+
91+
return oms_status_ok;
92+
}
93+
94+
oms_status_enu_t oms::ssd::SystemGeometry::importFromSSD(const pugi::xml_node& node)
95+
{
96+
x1 = node.attribute("x1").as_double();
97+
y1 = node.attribute("y1").as_double();
98+
x2 = node.attribute("x2").as_double();
99+
y2 = node.attribute("y2").as_double();
100+
101+
return oms_status_ok;
102+
}

src/OMSimulatorLib/ssd/SystemGeometry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#include "OMSimulator/Types.h"
3636

37+
#include <pugixml.hpp>
38+
3739
#include <string>
3840

3941
namespace oms
@@ -55,6 +57,9 @@ namespace oms
5557
double getY1() const {return y1;}
5658
double getX2() const {return x2;}
5759
double getY2() const {return y2;}
60+
61+
oms_status_enu_t exportToSSD(pugi::xml_node& root) const;
62+
oms_status_enu_t importFromSSD(const pugi::xml_node& node);
5863
};
5964
}
6065
}

src/OMSimulatorLib/ssd/Tags.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const char* oms::ssp::Draft20180219::ssd::elements = "ssd:El
5555
const char* oms::ssp::Draft20180219::ssd::enumerations = "ssd:Enumerations";
5656
const char* oms::ssp::Draft20180219::ssd::simulation_information = "ssd:SimulationInformation";
5757
const char* oms::ssp::Draft20180219::ssd::system = "ssd:System";
58+
const char* oms::ssp::Draft20180219::ssd::system_geometry = "ssd:SystemGeometry";
5859
const char* oms::ssp::Draft20180219::ssd::system_structure_description = "ssd:SystemStructureDescription";
5960
const char* oms::ssp::Draft20180219::ssd::units = "ssd:Units";
6061

src/OMSimulatorLib/ssd/Tags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ namespace oms
121121
extern const char* elements;
122122
extern const char* enumerations;
123123
extern const char* simulation_information;
124+
extern const char* system_geometry;
124125
extern const char* system_structure_description;
125126
extern const char* system;
126127
extern const char* units;

0 commit comments

Comments
 (0)