From a712cf1e6497793d2434d3f0c1e862cf0a30df85 Mon Sep 17 00:00:00 2001 From: milek7 Date: Wed, 22 Jun 2022 00:46:28 +0200 Subject: [PATCH] allow for multiple isolated segments in track --- Track.cpp | 26 ++++++++++++-------------- Track.h | 8 ++++---- editoruipanels.cpp | 10 +++++++++- messaging.cpp | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Track.cpp b/Track.cpp index 211a2be7..9cf67496 100644 --- a/Track.cpp +++ b/Track.cpp @@ -853,7 +853,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) { // obwód izolowany, do którego tor należy parser->getTokens(); *parser >> token; - pIsolated = TIsolated::Find(token); + Isolated.push_back(TIsolated::Find(token)); } else if (str == "angle1") { // kąt ścięcia końca od strony 1 @@ -922,13 +922,11 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) str = token; } // alternatywny zapis nazwy odcinka izolowanego - po znaku "@" w nazwie toru - if (!pIsolated) - if ((i = m_name.find("@")) != std::string::npos) - if (i < m_name.length()) // nie może być puste - { - pIsolated = TIsolated::Find(m_name.substr(i + 1, m_name.length())); - m_name = m_name.substr(0, i - 1); // usunięcie z nazwy - } + if ((i = m_name.find("@")) != std::string::npos && i < m_name.length()) + { + Isolated.push_back(TIsolated::Find(m_name.substr(i + 1, m_name.length()))); + m_name = m_name.substr(0, i - 1); // usunięcie z nazwy + } // calculate path location location( ( @@ -1010,11 +1008,11 @@ void TTrack::QueueEvents( event_sequence const &Events, TDynamicObject const *Ow } } -std::string TTrack::IsolatedName() +std::string TTrack::RemoteIsolatedName() { // podaje nazwę odcinka izolowanego, jesli nie ma on jeszcze przypisanych zdarzeń - if (pIsolated) - if (!pIsolated->evBusy && !pIsolated->evFree) - return pIsolated->asName; + for (const TIsolated *iso : Isolated) + if (!iso->evBusy && !iso->evFree) + return iso->asName; return ""; }; @@ -2333,8 +2331,8 @@ TTrack::export_as_text_( std::ostream &Output ) const { Output << "velocity " << fVelocity << ' '; } } - if( pIsolated ) { - Output << "isolated " << pIsolated->asName << ' '; + for( const TIsolated *iso : Isolated ) { + Output << "isolated " << iso->asName << ' '; } if( fOverhead != -1.0 ) { Output << "overhead " << fOverhead << ' '; diff --git a/Track.h b/Track.h index 93e26865..caa0c2ab 100644 --- a/Track.h +++ b/Track.h @@ -153,7 +153,7 @@ class TTrack : public scene::basic_node friend itemproperties_panel; private: - TIsolated * pIsolated = nullptr; // obwód izolowany obsługujący zajęcia/zwolnienia grupy torów + std::vector Isolated; // obwód izolowany obsługujący zajęcia/zwolnienia grupy torów std::shared_ptr SwitchExtension; // dodatkowe dane do toru, który jest zwrotnicą std::shared_ptr Segment; TTrack * trNext = nullptr; // odcinek od strony punktu 2 - to powinno być w segmencie @@ -300,9 +300,9 @@ public: void RadioStop(); void AxleCounter(int i, TDynamicObject *o) { - if (pIsolated) - pIsolated->Modify(i, o); }; // dodanie lub odjęcie osi - std::string IsolatedName(); + for (TIsolated *iso : Isolated) + iso->Modify(i, o); }; // dodanie lub odjęcie osi + std::string RemoteIsolatedName(); double WidthTotal(); bool IsGroupable(); int TestPoint( Math3D::vector3 *Point); diff --git a/editoruipanels.cpp b/editoruipanels.cpp index 0af9fdf3..7b6afde1 100644 --- a/editoruipanels.cpp +++ b/editoruipanels.cpp @@ -109,9 +109,17 @@ itemproperties_panel::update( scene::basic_node const *Node ) { else if( typeid( *node ) == typeid( TTrack ) ) { auto const *subnode = static_cast( node ); + + std::string isolatedlist; + for (const TIsolated *iso : subnode->Isolated) { + if (!isolatedlist.empty()) + isolatedlist += ", "; + isolatedlist += iso->asName; + } + // basic attributes textline = - "isolated: " + ( ( subnode->pIsolated != nullptr ) ? Bezogonkow( subnode->pIsolated->asName ) : "(none)" ) + "isolated: " + ( !isolatedlist.empty() ? isolatedlist : "(none)" ) + "\nvelocity: " + to_string( subnode->SwitchExtension ? subnode->SwitchExtension->fVelocity : subnode->fVelocity ) + "\nwidth: " + to_string( subnode->fTrackWidth ) + " m" + "\nfriction: " + to_string( subnode->fFriction, 2 ) diff --git a/messaging.cpp b/messaging.cpp index 628252af..918dd779 100644 --- a/messaging.cpp +++ b/messaging.cpp @@ -371,7 +371,7 @@ WyslijObsadzone() r.fPar[ 16 * i + 5 ] = vehicle->GetPosition().y; r.fPar[ 16 * i + 6 ] = vehicle->GetPosition().z; r.iPar[ 16 * i + 7 ] = static_cast( vehicle->Mechanik->action() ); - strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->IsolatedName().c_str() ); + strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->RemoteIsolatedName().c_str() ); strcpy( r.cString + 64 * i + 48, vehicle->Mechanik->TrainName().c_str() ); i++; if( i > 30 ) break;