#include <netedit/GNEApplicationWindow.h>
#include <netedit/GNENet.h>
#include <netedit/GNEViewNet.h>
#include <netedit/GNEViewParent.h>
#include <netedit/elements/additional/GNETAZ.h>
#include <netedit/elements/demand/GNEDemandElementPlan.h>
#include <netedit/elements/demand/GNEPlanParents.h>
#include <netedit/frames/common/GNEInspectorFrame.h>
#include <utils/gui/div/GLHelper.h>
#include <utils/gui/div/GUIDesigns.h>
#include <utils/gui/windows/GUIAppEnum.h>
#include "GNEPlanCreator.h"
FXDEFMAP(GNEPlanCreator) PathCreatorMap[] = {
FXMAPFUNC(SEL_COMMAND, MID_GNE_PATHCREATOR_ABORT, GNEPlanCreator::onCmdAbortPathCreation),
FXMAPFUNC(SEL_COMMAND, MID_GNE_PATHCREATOR_FINISH, GNEPlanCreator::onCmdCreatePath),
FXMAPFUNC(SEL_COMMAND, MID_GNE_PATHCREATOR_USELASTROUTE, GNEPlanCreator::onCmdUseLastRoute),
FXMAPFUNC(SEL_UPDATE, MID_GNE_PATHCREATOR_USELASTROUTE, GNEPlanCreator::onUpdUseLastRoute),
FXMAPFUNC(SEL_COMMAND, MID_GNE_PATHCREATOR_REMOVELAST, GNEPlanCreator::onCmdRemoveLastElement)
};
FXIMPLEMENT(GNEPlanCreator, MFXGroupBoxModule, PathCreatorMap, ARRAYNUMBER(PathCreatorMap))
GNEPlanCreator::PlanPath::PlanPath(GNEPathManager* pathManager, const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEEdge* toEdge) :
myConflictVClass(false),
myConflictDisconnected(false) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(vClass, fromEdge, toEdge);
if (mySubPath.empty()) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(SVC_PEDESTRIAN, fromEdge, toEdge);
if (mySubPath.empty()) {
mySubPath = {fromEdge, toEdge};
myConflictDisconnected = true;
} else {
myConflictVClass = true;
}
}
}
GNEPlanCreator::PlanPath::PlanPath(GNEPathManager* pathManager, const SUMOVehicleClass vClass, GNEEdge* fromEdge, GNEJunction* toJunction) :
myConflictVClass(false),
myConflictDisconnected(false) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(vClass, fromEdge, toJunction);
if (mySubPath.empty()) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(SVC_PEDESTRIAN, fromEdge, toJunction);
if (mySubPath.empty()) {
mySubPath = {fromEdge};
myConflictDisconnected = true;
} else {
myConflictVClass = true;
}
}
}
GNEPlanCreator::PlanPath::PlanPath(GNEPathManager* pathManager, const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEEdge* toEdge) :
myConflictVClass(false),
myConflictDisconnected(false) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(vClass, fromJunction, toEdge);
if (mySubPath.empty()) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(SVC_PEDESTRIAN, fromJunction, toEdge);
if (mySubPath.empty()) {
mySubPath = {toEdge};
myConflictDisconnected = true;
} else {
myConflictVClass = true;
}
}
}
GNEPlanCreator::PlanPath::PlanPath(GNEPathManager* pathManager, const SUMOVehicleClass vClass, GNEJunction* fromJunction, GNEJunction* toJunction) :
myConflictVClass(false),
myConflictDisconnected(false) {
mySubPath = pathManager->getPathCalculator()->calculateDijkstraPath(vClass, fromJunction, toJunction);
if (mySubPath.empty()) {
if (mySubPath.empty()) {
myConflictDisconnected = true;
} else {
myConflictVClass = true;
}
}
}
const std::vector<GNEEdge*>&
GNEPlanCreator::PlanPath::getSubPath() const {
return mySubPath;
}
bool
GNEPlanCreator::PlanPath::isConflictVClass() const {
return myConflictVClass;
}
bool
GNEPlanCreator::PlanPath::isConflictDisconnected() const {
return myConflictDisconnected;
}
GNEPlanCreator::PlanPath::PlanPath() :
myConflictVClass(false),
myConflictDisconnected(false) {
}
GNEPlanCreator::GNEPlanCreator(GNEFrame* frameParent, GNEPathManager* pathManager) :
MFXGroupBoxModule(frameParent, TL("Route creator")),
myFrameParent(frameParent),
myPathManager(pathManager),
myVClass(SVC_PASSENGER),
myPlanParents(0) {
myUseLastRoute = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Use last route"), "", "", GUIIconSubSys::getIcon(GUIIcon::ROUTE), this, MID_GNE_PATHCREATOR_USELASTROUTE, GUIDesignButton);
myUseLastRoute->disable();
myFinishCreationButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Finish route creation"), "", "", nullptr, this, MID_GNE_PATHCREATOR_FINISH, GUIDesignButton);
myFinishCreationButton->disable();
myAbortCreationButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Abort route creation"), "", "", nullptr, this, MID_GNE_PATHCREATOR_ABORT, GUIDesignButton);
myAbortCreationButton->disable();
myRemoveLastInsertedElement = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Remove last element"), "", "", nullptr, this, MID_GNE_PATHCREATOR_REMOVELAST, GUIDesignButton);
myRemoveLastInsertedElement->disable();
myInfoLabel = new FXLabel(this, "", 0, GUIDesignLabelFrameInformation);
}
GNEPlanCreator::~GNEPlanCreator() {}
bool
GNEPlanCreator::planCanBeCreated(const GNEDemandElement* planTemplate) const {
if (planTemplate == nullptr) {
return false;
} else if (planTemplate->getTagProperty()->isPlanPersonTrip()) {
return myPlanParameteres.getPersonTripTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanWalk()) {
return myPlanParameteres.getWalkTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanRide()) {
return myPlanParameteres.getRideTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanTransport()) {
return myPlanParameteres.getTransportTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanTranship()) {
return myPlanParameteres.getTranshipTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanStopPerson()) {
return myPlanParameteres.getPersonStopTag() != SUMO_TAG_NOTHING;
} else if (planTemplate->getTagProperty()->isPlanStopContainer()) {
return myPlanParameteres.getContainerStopTag() != SUMO_TAG_NOTHING;
} else {
return false;
}
}
void
GNEPlanCreator::showPlanCreatorModule(const GNEPlanSelector* planSelector, const GNEDemandElement* previousPlan) {
abortPathCreation();
hideCreationButtons();
myPlanParents = 0;
myPreviousPlanElement = previousPlan;
const auto& planTagProperty = planSelector->getCurrentPlanTagProperties();
if (planTagProperty->planRoute()) {
myPlanParents |= ROUTE;
myUseLastRoute->show();
} else {
myUseLastRoute->hide();
}
if (planTagProperty->planEdge()) {
myPlanParents |= EDGE;
}
if (planTagProperty->planStoppingPlace()) {
myPlanParents |= STOPPINGPLACE;
}
if (planTagProperty->planConsecutiveEdges()) {
myPlanParents |= CONSECUTIVE_EDGES;
showCreationButtons();
}
if (planTagProperty->planFromEdge() || planTagProperty->planToEdge()) {
myPlanParents |= START_EDGE;
myPlanParents |= END_EDGE;
showCreationButtons();
}
if (planTagProperty->planFromJunction() || planTagProperty->planToJunction()) {
myPlanParents |= START_JUNCTION;
myPlanParents |= END_JUNCTION;
showCreationButtons();
}
if (planTagProperty->planFromTAZ() || planTagProperty->planToTAZ()) {
myPlanParents |= START_TAZ;
myPlanParents |= END_TAZ;
showCreationButtons();
}
if (planTagProperty->planFromStoppingPlace() || planTagProperty->planToStoppingPlace()) {
myPlanParents |= START_STOPPINGPLACE;
myPlanParents |= END_STOPPINGPLACE;
showCreationButtons();
}
updateInfoLabel();
if (myPreviousPlanElement && planTagProperty->planFromTo()) {
const auto previousTagProperty = myPreviousPlanElement->getTagProperty();
if (previousTagProperty->planToEdge() || previousTagProperty->planEdge()) {
addFromToEdge(myPreviousPlanElement->getParentEdges().back());
} else if (previousTagProperty->planToJunction()) {
addFromToJunction(myPreviousPlanElement->getParentJunctions().back());
} else if (previousTagProperty->planToTAZ()) {
addFromToTAZ(myPreviousPlanElement->getParentTAZs().back());
} else if (previousTagProperty->planToStoppingPlace() || previousTagProperty->planStoppingPlace()) {
addFromToStoppingPlace(myPreviousPlanElement->getParentStoppingPlaces().back());
}
}
if (planTagProperty->isPlanRide() || planTagProperty->isPlanContainer()) {
myVClass = SVC_PASSENGER;
} else {
myVClass = SVC_PEDESTRIAN;
}
recalc();
show();
}
void
GNEPlanCreator::hidePathCreatorModule() {
clearPath();
hide();
}
bool
GNEPlanCreator::addRoute(GNEDemandElement* route) {
if ((myPlanParents & ROUTE) == 0) {
return false;
}
myPlanParameteres.toRoute = route->getID();
return myFrameParent->createPath(false);
}
bool
GNEPlanCreator::addEdge(GNELane* lane) {
if (myPlanParents & CONSECUTIVE_EDGES) {
return addConsecutiveEdge(lane->getParentEdge());
} else if (myPlanParents & EDGE) {
return addSingleEdge(lane);
} else if ((myPlanParents & START_EDGE) || (myPlanParents & END_EDGE)) {
return addFromToEdge(lane->getParentEdge());
} else {
return false;
}
}
bool
GNEPlanCreator::addJunction(GNEJunction* junction) {
if ((myPlanParents & START_JUNCTION) || (myPlanParents & END_JUNCTION)) {
return addFromToJunction(junction);
} else {
return false;
}
}
bool
GNEPlanCreator::addTAZ(GNEAdditional* taz) {
if ((myPlanParents & START_TAZ) || (myPlanParents & END_TAZ)) {
return addFromToTAZ(taz);
} else {
return false;
}
}
bool
GNEPlanCreator::addStoppingPlace(GNEAdditional* stoppingPlace) {
if (myPlanParents & STOPPINGPLACE) {
return addSingleStoppingPlace(stoppingPlace);
} else if ((myPlanParents & START_STOPPINGPLACE) || (myPlanParents & END_STOPPINGPLACE)) {
return addFromToStoppingPlace(stoppingPlace);
} else {
return false;
}
}
const CommonXMLStructure::PlanParameters&
GNEPlanCreator::getPlanParameteres() const {
return myPlanParameteres;
}
double
GNEPlanCreator::getClickedPositionOverLane() const {
return myClickedPositionOverLane;
}
const std::vector<GNEPlanCreator::PlanPath>&
GNEPlanCreator::getPath() const {
return myPath;
}
void
GNEPlanCreator::drawTemporalRoute(const GUIVisualizationSettings& s) const {
const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
const double lineWidth = 0.35;
const double lineWidthin = 0.25;
GLHelper::pushMatrix();
glTranslated(0, 0, GLO_MAX - 0.1);
if (myPath.size() > 0) {
GLHelper::setColor(RGBColor::GREY);
for (int i = 0; i < (int)myPath.size(); i++) {
const GNEPlanCreator::PlanPath& path = myPath.at(i);
for (int j = 0; j < (int)path.getSubPath().size(); j++) {
const GNELane* lane = path.getSubPath().at(j)->getChildLanes().back();
if (((i == 0) && (j == 0)) || (j > 0)) {
GLHelper::drawBoxLines(lane->getLaneShape(), lineWidth);
}
if ((j + 1) < (int)path.getSubPath().size()) {
const GNELane* nextLane = path.getSubPath().at(j + 1)->getChildLanes().back();
if (lane->getLane2laneConnections().exist(nextLane)) {
GLHelper::drawBoxLines(lane->getLane2laneConnections().getLane2laneGeometry(nextLane).getShape(), lineWidth);
} else {
GLHelper::drawBoxLines({lane->getLaneShape().back(), nextLane->getLaneShape().front()}, lineWidth);
}
}
}
}
glTranslated(0, 0, 0.1);
for (int i = 0; i < (int)myPath.size(); i++) {
const GNEPlanCreator::PlanPath& path = myPath.at(i);
if (path.isConflictDisconnected()) {
GLHelper::setColor(s.candidateColorSettings.conflict);
} else if (path.isConflictVClass()) {
GLHelper::setColor(s.candidateColorSettings.special);
} else {
GLHelper::setColor(RGBColor::ORANGE);
}
for (int j = 0; j < (int)path.getSubPath().size(); j++) {
const GNELane* lane = path.getSubPath().at(j)->getChildLanes().back();
if (((i == 0) && (j == 0)) || (j > 0)) {
GLHelper::drawBoxLines(lane->getLaneShape(), lineWidthin);
}
if ((j + 1) < (int)path.getSubPath().size()) {
const GNELane* nextLane = path.getSubPath().at(j + 1)->getChildLanes().back();
if (lane->getLane2laneConnections().exist(nextLane)) {
GLHelper::drawBoxLines(lane->getLane2laneConnections().getLane2laneGeometry(nextLane).getShape(), lineWidthin);
} else {
GLHelper::drawBoxLines({ lane->getLaneShape().back(), nextLane->getLaneShape().front() }, lineWidthin);
}
}
}
}
} else if (!myPlanParameteres.fromJunction.empty() && !myPlanParameteres.toJunction.empty()) {
GLHelper::setColor(RGBColor::ORANGE);
const Position posA = ACs->getJunctions().at(myPlanParameteres.fromJunction)->getPositionInView();
const Position posB = ACs->getJunctions().at(myPlanParameteres.toJunction)->getPositionInView();
const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
const double len = posA.distanceTo2D(posB);
GLHelper::drawBoxLine(posA, rot, len, 0.25);
} else if (!myPlanParameteres.fromTAZ.empty() && !myPlanParameteres.toTAZ.empty()) {
GLHelper::setColor(RGBColor::ORANGE);
const Position posA = ACs->retrieveAdditional(SUMO_TAG_TAZ, myPlanParameteres.fromTAZ)->getPositionInView();
const Position posB = ACs->retrieveAdditional(SUMO_TAG_TAZ, myPlanParameteres.toTAZ)->getPositionInView();
const double rot = ((double)atan2((posB.x() - posA.x()), (posA.y() - posB.y())) * (double) 180.0 / (double)M_PI);
const double len = posA.distanceTo2D(posB);
GLHelper::drawBoxLine(posA, rot, len, 0.25);
}
GLHelper::popMatrix();
}
void
GNEPlanCreator::abortPathCreation() {
if (getNumberOfSelectedElements() > 0) {
myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->enableUndoRedoTemporally();
clearPath();
myFinishCreationButton->disable();
myAbortCreationButton->disable();
myRemoveLastInsertedElement->disable();
myFrameParent->getViewNet()->updateViewNet();
}
}
void
GNEPlanCreator::removeLastElement() {
if (myRemoveLastInsertedElement->isEnabled()) {
if (myPlanParameteres.consecutiveEdges.size() > 0) {
myPlanParameteres.consecutiveEdges.pop_back();
} else if (!myPlanParameteres.toEdge.empty()) {
myPlanParameteres.toEdge.clear();
} else if (!myPlanParameteres.toJunction.empty()) {
myPlanParameteres.toJunction.clear();
} else if (!myPlanParameteres.toTAZ.empty()) {
myPlanParameteres.toTAZ.clear();
} else if (!myPlanParameteres.toBusStop.empty()) {
myPlanParameteres.toBusStop.clear();
} else if (!myPlanParameteres.toTrainStop.empty()) {
myPlanParameteres.toBusStop.clear();
} else if (!myPlanParameteres.toContainerStop.empty()) {
myPlanParameteres.toBusStop.clear();
} else if (!myPlanParameteres.toChargingStation.empty()) {
myPlanParameteres.toBusStop.clear();
} else if (!myPlanParameteres.toParkingArea.empty()) {
myPlanParameteres.toBusStop.clear();
} else if (!myPlanParameteres.fromEdge.empty()) {
myPlanParameteres.fromEdge.clear();
} else if (!myPlanParameteres.fromJunction.empty()) {
myPlanParameteres.fromJunction.clear();
} else if (!myPlanParameteres.fromTAZ.empty()) {
myPlanParameteres.fromTAZ.clear();
} else if (!myPlanParameteres.fromBusStop.empty()) {
myPlanParameteres.fromBusStop.clear();
} else if (!myPlanParameteres.fromTrainStop.empty()) {
myPlanParameteres.fromBusStop.clear();
} else if (!myPlanParameteres.fromContainerStop.empty()) {
myPlanParameteres.fromBusStop.clear();
} else if (!myPlanParameteres.fromChargingStation.empty()) {
myPlanParameteres.fromBusStop.clear();
} else if (!myPlanParameteres.fromParkingArea.empty()) {
myPlanParameteres.fromBusStop.clear();
}
updateRemoveLastItemButton();
recalculatePath();
}
}
long
GNEPlanCreator::onCmdCreatePath(FXObject*, FXSelector, void*) {
return myFrameParent->createPath(false);
}
long
GNEPlanCreator::onCmdUseLastRoute(FXObject*, FXSelector, void*) {
return myFrameParent->createPath(true);
}
long
GNEPlanCreator::onUpdUseLastRoute(FXObject* sender, FXSelector, void*) {
if ((myPlanParents & ROUTE) && myFrameParent->getViewNet()->getLastCreatedRoute()) {
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
} else {
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
}
}
long
GNEPlanCreator::onCmdAbortPathCreation(FXObject*, FXSelector, void*) {
abortPathCreation();
return 1;
}
long
GNEPlanCreator::onCmdRemoveLastElement(FXObject*, FXSelector, void*) {
removeLastElement();
return 1;
}
void
GNEPlanCreator::clearPath() {
myPlanParameteres.clear();
myClickedPositionOverLane = 0;
myPath.clear();
}
void
GNEPlanCreator::recalculatePath() {
const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
myPath.clear();
if (myPlanParameteres.consecutiveEdges.size() > 0) {
for (int i = 1; i < (int)myPlanParameteres.consecutiveEdges.size(); i++) {
myPath.push_back(PlanPath(myPathManager, myVClass,
ACs->retrieveEdge(myPlanParameteres.consecutiveEdges.at(i - 1)),
ACs->retrieveEdge(myPlanParameteres.consecutiveEdges.at(i))));
}
} else {
GNEEdge* fromEdge = nullptr;
if (!myPlanParameteres.fromEdge.empty()) {
fromEdge = ACs->retrieveEdge(myPlanParameteres.fromEdge);
} else if (!myPlanParameteres.fromBusStop.empty()) {
fromEdge = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, myPlanParameteres.fromBusStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.fromTrainStop.empty()) {
fromEdge = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, myPlanParameteres.fromTrainStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.fromContainerStop.empty()) {
fromEdge = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, myPlanParameteres.fromContainerStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.fromChargingStation.empty()) {
fromEdge = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, myPlanParameteres.fromChargingStation)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.fromParkingArea.empty()) {
fromEdge = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, myPlanParameteres.fromParkingArea)->getParentLanes().front()->getParentEdge();
}
GNEEdge* toEdge = nullptr;
if (!myPlanParameteres.toEdge.empty()) {
toEdge = ACs->retrieveEdge(myPlanParameteres.toEdge);
} else if (!myPlanParameteres.toBusStop.empty()) {
toEdge = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, myPlanParameteres.toBusStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.toTrainStop.empty()) {
toEdge = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, myPlanParameteres.toTrainStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.toContainerStop.empty()) {
toEdge = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, myPlanParameteres.toContainerStop)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.toChargingStation.empty()) {
toEdge = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, myPlanParameteres.toChargingStation)->getParentLanes().front()->getParentEdge();
} else if (!myPlanParameteres.toParkingArea.empty()) {
toEdge = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, myPlanParameteres.toParkingArea)->getParentLanes().front()->getParentEdge();
}
if (fromEdge && toEdge) {
myPath.push_back(PlanPath(myPathManager, myVClass, fromEdge, toEdge));
} else if (fromEdge && !myPlanParameteres.toJunction.empty()) {
myPath.push_back(PlanPath(myPathManager, myVClass, fromEdge, ACs->getJunctions().at(myPlanParameteres.toJunction)));
} else if (!myPlanParameteres.fromJunction.empty() && toEdge) {
myPath.push_back(PlanPath(myPathManager, myVClass, ACs->getJunctions().at(myPlanParameteres.fromJunction), toEdge));
} else if (!myPlanParameteres.fromJunction.empty() && !myPlanParameteres.toJunction.empty()) {
myPath.push_back(PlanPath(myPathManager, myVClass,
ACs->getJunctions().at(myPlanParameteres.fromJunction),
ACs->getJunctions().at(myPlanParameteres.toJunction)));
}
}
}
int
GNEPlanCreator::getNumberOfSelectedElements() const {
return myPlanParameteres.getNumberOfDefinedParameters();
}
void
GNEPlanCreator::updateRemoveLastItemButton() const {
if (myPreviousPlanElement) {
if (getNumberOfSelectedElements() == 2) {
myRemoveLastInsertedElement->enable();
} else {
myRemoveLastInsertedElement->disable();
}
} else {
if (getNumberOfSelectedElements() > 0) {
myRemoveLastInsertedElement->enable();
} else {
myRemoveLastInsertedElement->disable();
}
}
}
void
GNEPlanCreator::showCreationButtons() {
myFinishCreationButton->show();
myAbortCreationButton->show();
myRemoveLastInsertedElement->show();
}
void
GNEPlanCreator::hideCreationButtons() {
myFinishCreationButton->hide();
myAbortCreationButton->hide();
myRemoveLastInsertedElement->hide();
}
void
GNEPlanCreator::updateInfoLabel() {
const bool consecutiveEdges = (myPlanParents & CONSECUTIVE_EDGES);
const bool route = (myPlanParents & ROUTE);
const bool edges = (myPlanParents & EDGE) ||
(myPlanParents & START_EDGE) ||
(myPlanParents & END_EDGE);
const bool TAZs = (myPlanParents & START_TAZ) ||
(myPlanParents & END_TAZ);
const bool junctions = (myPlanParents & START_JUNCTION) ||
(myPlanParents & END_JUNCTION);
const bool stoppingPlace = (myPlanParents & STOPPINGPLACE) ||
(myPlanParents & START_STOPPINGPLACE) ||
(myPlanParents & END_STOPPINGPLACE);
std::ostringstream information;
information
<< TL("Click over:") << "\n"
<< (consecutiveEdges ? "- Consecutive edges\n" : "")
<< (route ? "- Routes\n" : "")
<< (edges ? "- Edges\n" : "")
<< (TAZs ? "- TAZs\n" : "")
<< (junctions ? "- Junctions\n" : "")
<< (stoppingPlace ? "- StoppingPlaces\n" : "");
std::string informationStr = information.str();
informationStr.pop_back();
myInfoLabel->setText(informationStr.c_str());
}
bool
GNEPlanCreator::addSingleEdge(GNELane* lane) {
myPlanParameteres.toEdge = lane->getParentEdge()->getID();
const auto clickedPos = myFrameParent->getViewNet()->getPositionInformation();
myClickedPositionOverLane = lane->getLaneShape().nearest_offset_to_point2D(clickedPos);
return myFrameParent->createPath(false);
}
bool
GNEPlanCreator::addSingleStoppingPlace(GNEAdditional* stoppingPlace) {
switch (stoppingPlace->getTagProperty()->getTag()) {
case SUMO_TAG_BUS_STOP:
myPlanParameteres.toBusStop = stoppingPlace->getID();
break;
case SUMO_TAG_TRAIN_STOP:
myPlanParameteres.toTrainStop = stoppingPlace->getID();
break;
case SUMO_TAG_CONTAINER_STOP:
myPlanParameteres.toContainerStop = stoppingPlace->getID();
break;
case SUMO_TAG_CHARGING_STATION:
myPlanParameteres.toChargingStation = stoppingPlace->getID();
break;
case SUMO_TAG_PARKING_AREA:
myPlanParameteres.toParkingArea = stoppingPlace->getID();
break;
default:
return false;
}
return myFrameParent->createPath(false);
}
bool
GNEPlanCreator::addConsecutiveEdge(GNEEdge* edge) {
if ((myPlanParameteres.consecutiveEdges.size() > 0) && (myPlanParameteres.consecutiveEdges.back() == edge->getID())) {
WRITE_WARNING(TL("Double edges aren't allowed"));
return false;
}
myPlanParameteres.consecutiveEdges.push_back(edge->getID());
myAbortCreationButton->enable();
myFinishCreationButton->enable();
updateRemoveLastItemButton();
recalculatePath();
return true;
}
bool
GNEPlanCreator::addFromToJunction(GNEJunction* junction) {
if (myPlanParameteres.fromJunction == junction->getID()) {
WRITE_WARNING(TL("Double junctions aren't allowed"));
return false;
}
if (getNumberOfSelectedElements() == 2) {
WRITE_WARNING(TL("Only two from-to elements are allowed"));
return false;
}
if (getNumberOfSelectedElements() == 0) {
myPlanParameteres.fromJunction = junction->getID();
} else {
myPlanParameteres.toJunction = junction->getID();
}
myAbortCreationButton->enable();
myFinishCreationButton->enable();
updateRemoveLastItemButton();
recalculatePath();
return true;
}
bool
GNEPlanCreator::addFromToTAZ(GNEAdditional* TAZ) {
if (myPlanParameteres.fromTAZ == TAZ->getID()) {
WRITE_WARNING(TL("Double TAZs aren't allowed"));
return false;
}
if (getNumberOfSelectedElements() == 2) {
WRITE_WARNING(TL("Only two from-to elements are allowed"));
return false;
}
if (getNumberOfSelectedElements() == 0) {
myPlanParameteres.fromTAZ = TAZ->getID();
} else {
myPlanParameteres.toTAZ = TAZ->getID();
}
myAbortCreationButton->enable();
myFinishCreationButton->enable();
updateRemoveLastItemButton();
recalculatePath();
return true;
}
bool
GNEPlanCreator::addFromToEdge(GNEEdge* edge) {
if (myPlanParameteres.fromEdge == edge->getID()) {
WRITE_WARNING(TL("Double edges aren't allowed"));
return false;
}
if (getNumberOfSelectedElements() == 2) {
WRITE_WARNING(TL("Only two from-to elements are allowed"));
return false;
}
if (getNumberOfSelectedElements() == 0) {
myPlanParameteres.fromEdge = edge->getID();
} else {
myPlanParameteres.toEdge = edge->getID();
}
myAbortCreationButton->enable();
myFinishCreationButton->enable();
updateRemoveLastItemButton();
recalculatePath();
return true;
}
bool
GNEPlanCreator::addFromToStoppingPlace(GNEAdditional* stoppingPlace) {
const auto stoppingPlaceID = stoppingPlace->getID();
if ((myPlanParameteres.toBusStop == stoppingPlaceID) ||
(myPlanParameteres.toTrainStop == stoppingPlaceID) ||
(myPlanParameteres.toContainerStop == stoppingPlaceID) ||
(myPlanParameteres.toChargingStation == stoppingPlaceID) ||
(myPlanParameteres.toParkingArea == stoppingPlaceID)) {
WRITE_WARNING(TL("Double stoppingPlaces aren't allowed"));
return false;
}
if (getNumberOfSelectedElements() == 2) {
WRITE_WARNING(TL("Only two from-to elements are allowed"));
return false;
}
if (getNumberOfSelectedElements() == 0) {
switch (stoppingPlace->getTagProperty()->getTag()) {
case SUMO_TAG_BUS_STOP:
myPlanParameteres.fromBusStop = stoppingPlaceID;
break;
case SUMO_TAG_TRAIN_STOP:
myPlanParameteres.fromTrainStop = stoppingPlaceID;
break;
case SUMO_TAG_CONTAINER_STOP:
myPlanParameteres.fromContainerStop = stoppingPlaceID;
break;
case SUMO_TAG_CHARGING_STATION:
myPlanParameteres.fromChargingStation = stoppingPlaceID;
break;
case SUMO_TAG_PARKING_AREA:
myPlanParameteres.fromParkingArea = stoppingPlaceID;
break;
default:
return false;
}
} else {
switch (stoppingPlace->getTagProperty()->getTag()) {
case SUMO_TAG_BUS_STOP:
myPlanParameteres.toBusStop = stoppingPlaceID;
break;
case SUMO_TAG_TRAIN_STOP:
myPlanParameteres.toTrainStop = stoppingPlaceID;
break;
case SUMO_TAG_CONTAINER_STOP:
myPlanParameteres.toContainerStop = stoppingPlaceID;
break;
case SUMO_TAG_CHARGING_STATION:
myPlanParameteres.toChargingStation = stoppingPlaceID;
break;
case SUMO_TAG_PARKING_AREA:
myPlanParameteres.toParkingArea = stoppingPlaceID;
break;
default:
return false;
}
}
myAbortCreationButton->enable();
myFinishCreationButton->enable();
myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->disableUndoRedoTemporally("creation of stoppingPlace path");
updateRemoveLastItemButton();
recalculatePath();
return true;
}