#include <netedit/GNENet.h>
#include "GNESegment.h"
GNESegment::GNESegment(GNEPathManager* pathManager, GNEPathElement* element, const GNELane* lane, std::vector<GNESegment*>& segments) :
myPathManager(pathManager),
myPathElement(element),
myLane(lane),
myJunction(nullptr),
myNextSegment(nullptr),
myPreviousSegment(nullptr),
myLabelSegment(false),
myContour(new GNEContour),
myFromContour(nullptr),
myToContour(nullptr) {
if (segments.size() > 0) {
myPreviousSegment = segments.back();
myPreviousSegment->myNextSegment = this;
myToContour = myPreviousSegment->myToContour;
myPreviousSegment->myToContour = nullptr;
if (myPreviousSegment->myPreviousSegment && myPreviousSegment->myPreviousSegment->myLane) {
myLaneIndex = myPreviousSegment->myPreviousSegment->myLaneIndex + 1;
} else if (myPreviousSegment->myLane) {
myLaneIndex = myPreviousSegment->myLaneIndex + 1;
}
} else {
myFromContour = new GNEContour();
myToContour = new GNEContour();
}
segments.push_back(this);
myPathManager->addSegmentInLaneSegments(this, lane);
}
GNESegment::GNESegment(GNEPathManager* pathManager, GNEPathElement* element, const GNEJunction* junction, std::vector<GNESegment*>& segments) :
myPathManager(pathManager),
myPathElement(element),
myLane(nullptr),
myJunction(junction),
myNextSegment(nullptr),
myPreviousSegment(nullptr),
myLabelSegment(false),
myContour(new GNEContour),
myFromContour(nullptr),
myToContour(nullptr) {
if (segments.size() > 0) {
myPreviousSegment = segments.back();
myPreviousSegment->myNextSegment = this;
myToContour = myPreviousSegment->myToContour;
myPreviousSegment->myToContour = nullptr;
if (myPreviousSegment->myPreviousSegment && myPreviousSegment->myPreviousSegment->myJunction) {
myJunctionIndex = myPreviousSegment->myPreviousSegment->myJunctionIndex + 1;
} else if (myPreviousSegment->myJunction) {
myJunctionIndex = myPreviousSegment->myJunctionIndex + 1;
}
} else {
myFromContour = new GNEContour();
myToContour = new GNEContour();
}
segments.push_back(this);
myPathManager->addSegmentInJunctionSegments(this, junction);
}
GNESegment::~GNESegment() {
if (!myPathManager->myCleaningSegments) {
myPathManager->clearSegmentFromJunctionAndLaneSegments(this);
if (myPreviousSegment) {
myPreviousSegment->myNextSegment = nullptr;
}
if (myNextSegment) {
myNextSegment->myPreviousSegment = nullptr;
}
}
delete myContour;
if (myFromContour) {
delete myFromContour;
}
if (myToContour) {
delete myToContour;
}
}
GNEContour*
GNESegment::getContour() const {
return myContour;
}
GNEContour*
GNESegment::getFromContour() const {
return myFromContour;
}
GNEContour*
GNESegment::getToContour() const {
return myToContour;
}
GNESegment*
GNESegment::getNextSegment() const {
return myNextSegment;
}
GNESegment*
GNESegment::getPreviousSegment() const {
return myPreviousSegment;
}
bool
GNESegment::isFirstSegment() const {
return (myPreviousSegment == nullptr);
}
bool
GNESegment::isLastSegment() const {
return (myNextSegment == nullptr);
}
GNEPathElement*
GNESegment::getPathElement() const {
return myPathElement;
}
const GNELane*
GNESegment::getLane() const {
return myLane;
}
const GNELane*
GNESegment::getPreviousLane() const {
if (myPreviousSegment) {
return myPreviousSegment->getLane();
} else {
return nullptr;
}
}
const GNELane*
GNESegment::getNextLane() const {
if (myNextSegment) {
return myNextSegment->getLane();
} else {
return nullptr;
}
}
int
GNESegment::getLaneIndex() const {
return myLaneIndex;
}
const GNEJunction*
GNESegment::getJunction() const {
return myJunction;
}
int
GNESegment::getJunctionIndex() const {
return myJunctionIndex;
}
bool
GNESegment::isLabelSegment() const {
return myLabelSegment;
}
void
GNESegment::markSegmentLabel() {
myLabelSegment = true;
}
GNESegment::GNESegment() :
myPathManager(nullptr),
myPathElement(nullptr),
myLane(nullptr),
myJunction(nullptr),
myNextSegment(nullptr),
myPreviousSegment(nullptr),
myLabelSegment(false) {
}