Skip to content

Commit 39e072f

Browse files
authored
Fix connection geometry for connections from end to start (#930)
1 parent 8877a18 commit 39e072f

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

src/OMSimulatorLib/Connection.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ oms_status_enu_t oms::Connection::exportToSSD(pugi::xml_node &root) const
139139
return oms_status_ok;
140140
}
141141

142-
void oms::Connection::setGeometry(const oms::ssd::ConnectionGeometry* newGeometry)
142+
void oms::Connection::setGeometry(const oms::ssd::ConnectionGeometry* newGeometry, bool inverse)
143143
{
144144
oms::ssd::ConnectionGeometry* geometry_ = reinterpret_cast<oms::ssd::ConnectionGeometry*>(this->geometry);
145145
if (geometry_)
146146
delete geometry_;
147-
geometry_ = new oms::ssd::ConnectionGeometry(*newGeometry);
147+
geometry_ = new oms::ssd::ConnectionGeometry(*newGeometry, inverse);
148148
this->geometry = reinterpret_cast<ssd_connection_geometry_t*>(geometry_);
149149
}
150150

@@ -171,6 +171,11 @@ void oms::Connection::setTLMParameters(double delay, double alpha, double linear
171171
tlmparameters->angularimpedance = angualrimpedance;
172172
}
173173

174+
bool oms::Connection::isStrictEqual(const oms::ComRef& signalA, const oms::ComRef& signalB) const
175+
{
176+
return signalA == oms::ComRef(this->conA) && signalB == oms::ComRef(this->conB);
177+
}
178+
174179
bool oms::Connection::isEqual(const oms::ComRef& signalA, const oms::ComRef& signalB) const
175180
{
176181
return (signalA == oms::ComRef(this->conA) && signalB == oms::ComRef(this->conB)) || (signalA == oms::ComRef(this->conB) && signalB == oms::ComRef(this->conA));

src/OMSimulatorLib/Connection.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ namespace oms
6060
const oms::ComRef getSignalB() const {return oms::ComRef(conB);}
6161

6262
const oms::ssd::ConnectionGeometry* getGeometry() const {return reinterpret_cast<oms::ssd::ConnectionGeometry*>(geometry);}
63-
void setGeometry(const oms::ssd::ConnectionGeometry* newGeometry);
63+
void setGeometry(const oms::ssd::ConnectionGeometry* newGeometry, bool inverse=false);
6464
void setTLMParameters(const oms_tlm_connection_parameters_t* parameters);
6565
void setTLMParameters(double delay, double alpha, double linearimpedance, double angualrimpedance);
6666
oms_tlm_connection_parameters_t* getTLMParameters() const {return tlmparameters;}
6767

6868
oms_connection_type_enu_t getType() const {return type;}
6969

7070
bool isEqual(const oms::Connection& connection) const;
71-
bool isEqual(const oms::ComRef& signalA, const oms::ComRef& signalB) const;
71+
bool isEqual(const oms::ComRef& signalA, const oms::ComRef& signalB) const; ///< "A->B" and "B->A" are treated the same
72+
bool isStrictEqual(const oms::ComRef& signalA, const oms::ComRef& signalB) const; ///< "A->B" is not strict equal "B->A"
7273
bool containsSignal(const oms::ComRef& signal) const;
7374
bool containsSignalB(const oms::ComRef& signal) const;
7475

src/OMSimulatorLib/System.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,8 @@ oms_status_enu_t oms::System::setConnectionGeometry(const oms::ComRef& crefA, co
14521452
for (auto& connection : connections)
14531453
if (connection && connection->isEqual(crefA, crefB))
14541454
{
1455-
connection->setGeometry(geometry);
1455+
bool inverse = connection->isStrictEqual(crefB, crefA);
1456+
connection->setGeometry(geometry, inverse);
14561457
return oms_status_ok;
14571458
}
14581459

src/OMSimulatorLib/Util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,16 @@ static inline bool almostEqualRelativeAndAbs(double a, double b, double reltol=D
7777
return false;
7878
}
7979

80+
template <class T>
81+
void reverseArray(T* array, unsigned int length)
82+
{
83+
T tmp;
84+
for (unsigned int start = 0, end = length-1; start < end; start++, end--)
85+
{
86+
tmp = array[start];
87+
array[start] = array[end];
88+
array[end] = tmp;
89+
}
90+
}
91+
8092
#endif

src/OMSimulatorLib/ssd/ConnectionGeometry.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "../Logging.h"
3535
#include "Tags.h"
36+
#include "Util.h"
3637

3738
#include <string.h>
3839
#include <sstream>
@@ -47,7 +48,7 @@ oms::ssd::ConnectionGeometry::ConnectionGeometry()
4748
this->n = 0;
4849
}
4950

50-
oms::ssd::ConnectionGeometry::ConnectionGeometry(const oms::ssd::ConnectionGeometry& rhs)
51+
oms::ssd::ConnectionGeometry::ConnectionGeometry(const oms::ssd::ConnectionGeometry& rhs, bool inverse)
5152
{
5253
logTrace();
5354

@@ -59,6 +60,11 @@ oms::ssd::ConnectionGeometry::ConnectionGeometry(const oms::ssd::ConnectionGeome
5960
this->pointsY = new double[rhs.n];
6061
memcpy(this->pointsX, rhs.pointsX, n*sizeof(double));
6162
memcpy(this->pointsY, rhs.pointsY, n*sizeof(double));
63+
if (inverse)
64+
{
65+
reverseArray(this->pointsX, this->n);
66+
reverseArray(this->pointsY, this->n);
67+
}
6268
}
6369
else
6470
{

src/OMSimulatorLib/ssd/ConnectionGeometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace oms
4646
{
4747
public:
4848
ConnectionGeometry();
49-
ConnectionGeometry(const ConnectionGeometry& rhs);
49+
ConnectionGeometry(const ConnectionGeometry& rhs, bool inverse=false);
5050
~ConnectionGeometry();
5151

5252
ConnectionGeometry& operator=(ConnectionGeometry const& rhs);

0 commit comments

Comments
 (0)