Eclipse SUMO - Simulation of Urban MObility
GNETAZRelDataFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // The Widget for add TAZRelationData elements
19 /****************************************************************************/
20 #include <config.h>
21 
25 #include <netedit/GNEViewNet.h>
28 
29 #include "GNETAZRelDataFrame.h"
30 
31 
32 // ===========================================================================
33 // FOX callback mapping
34 // ===========================================================================
35 
40 };
41 
42 // Object implementation
43 FXIMPLEMENT(GNETAZRelDataFrame::ConfirmTAZRelation, MFXGroupBoxModule, ConfirmTAZRelationMap, ARRAYNUMBER(ConfirmTAZRelationMap))
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 
49 // ---------------------------------------------------------------------------
50 // GNETAZRelDataFrame::ConfirmTAZRelation - methods
51 // ---------------------------------------------------------------------------
52 
54  MFXGroupBoxModule(TAZRelDataFrame, TL("Confirm TAZRelation")),
55  myTAZRelDataFrame(TAZRelDataFrame) {
56  myConfirmTAZButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Create TAZRelation"), "", TL("Click fromTaz and toTaz (confirm hotkey <ENTER>)"), GUIIconSubSys::getIcon(GUIIcon::TAZRELDATA), this, MID_GNE_CREATE, GUIDesignButton);
57  myConfirmTAZButton->disable();
58  myClearTAZButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Clear selection"), "", TL("Clear selected TAZs (hotkey <ESC>)"), GUIIconSubSys::getIcon(GUIIcon::CLEARMESSAGEWINDOW), this, MID_GNE_ABORT, GUIDesignButton);
59  myClearTAZButton->disable();
60 }
61 
62 
64 
65 
66 long
68  myTAZRelDataFrame->buildTAZRelationData();
69  return 1;
70 }
71 
72 
73 long
75  if (myTAZRelDataFrame->myFirstTAZ && myTAZRelDataFrame->mySecondTAZ) {
76  myConfirmTAZButton->enable();
77  } else {
78  myConfirmTAZButton->disable();
79  }
80  if (myTAZRelDataFrame->myFirstTAZ || myTAZRelDataFrame->mySecondTAZ) {
81  myClearTAZButton->enable();
82  } else {
83  myClearTAZButton->disable();
84  }
85  return 1;
86 }
87 
88 
89 long
91  myTAZRelDataFrame->clearTAZSelection();
92  myTAZRelDataFrame->getViewNet()->update();
93  return 1;
94 }
95 
96 // ---------------------------------------------------------------------------
97 // GNETAZRelDataFrame::TAZRelLegend - methods
98 // ---------------------------------------------------------------------------
99 
101  MFXGroupBoxModule(TAZRelDataFrame, TL("Information")),
102  myFromTAZLabel(nullptr),
103  myToTAZLabel(nullptr) {
104  // create from TAZ label
105  myFromTAZLabel = new FXLabel(getCollapsableFrame(), "From TAZ", 0, GUIDesignLabel(JUSTIFY_LEFT));
107  // create to TAZ Label
108  myToTAZLabel = new FXLabel(getCollapsableFrame(), "To TAZ", 0, GUIDesignLabel(JUSTIFY_LEFT));
110 }
111 
112 
114 
115 
116 void
117 GNETAZRelDataFrame::Legend::setLabels(const GNETAZ* fromTAZ, const GNETAZ* toTAZ) {
118  // from TAZ
119  if (fromTAZ) {
120  myFromTAZLabel->setText(("From TAZ: " + fromTAZ->getID()).c_str());
121  } else {
122  myFromTAZLabel->setText(TL("From TAZ"));
123  }
124  // to TAZ
125  if (toTAZ) {
126  myToTAZLabel->setText(("To TAZ: " + toTAZ->getID()).c_str());
127  } else {
128  myToTAZLabel->setText(TL("To TAZ"));
129  }
130 }
131 
132 // ---------------------------------------------------------------------------
133 // GNETAZRelDataFrame - methods
134 // ------------------------------------------------------------------------
135 
137  GNEGenericDataFrame(viewParent, viewNet, SUMO_TAG_TAZREL, false) {
138  // create confirm TAZ Relation
140  // create legend
141  myLegend = new Legend(this);
142 }
143 
144 
146 
147 
148 bool
150  // check if myFirstTAZElement is empty
151  if (myFirstTAZ) {
152  if (mySecondTAZ) {
153  // both already defined
154  return false;
155  } else if (viewObjects.getTAZFront()) {
156  mySecondTAZ = viewObjects.getTAZFront();
158  return true;
159  } else {
160  return false;
161  }
162  } else if (viewObjects.getTAZFront()) {
163  myFirstTAZ = viewObjects.getTAZFront();
165  return true;
166  } else {
167  return false;
168  }
169 }
170 
171 
172 void
174  // check conditions
175  if (myFirstTAZ && mySecondTAZ) {
177  WRITE_WARNINGF(TL("A % must be defined within an interval."), toString(SUMO_TAG_TAZREL));
179  WRITE_WARNINGF(TL("There is already a % defined in TAZ'%'."), toString(SUMO_TAG_TAZREL), myFirstTAZ->getID());
181  WRITE_WARNINGF(TL("There is already a % defined between TAZ'%' and '%'."), toString(SUMO_TAG_TAZREL), myFirstTAZ->getID(), mySecondTAZ->getID());
183  // declare data handler
184  GNEDataHandler dataHandler(myViewNet->getNet(), "", true, false);
185  // build data interval object and fill it
190  // create TAZRelData
191  CommonXMLStructure::SumoBaseObject* TAZRelData = new CommonXMLStructure::SumoBaseObject(dataIntervalObject);
192  // finally create TAZRelationData
194  delete dataIntervalObject;
195  // reset both TAZs
196  myFirstTAZ = nullptr;
197  mySecondTAZ = nullptr;
199  }
200  }
201 }
202 
203 
206  return myFirstTAZ;
207 }
208 
209 
212  return mySecondTAZ;
213 }
214 
215 
216 void
218  myFirstTAZ = nullptr;
219  mySecondTAZ = nullptr;
221 }
222 
223 /****************************************************************************/
FXDEFMAP(GNETAZRelDataFrame::ConfirmTAZRelation) ConfirmTAZRelationMap[]
@ MID_GNE_CREATE
create element
Definition: GUIAppEnum.h:932
@ MID_GNE_ABORT
abort lane path creation
Definition: GUIAppEnum.h:988
#define GUIDesignButton
Definition: GUIDesigns.h:88
#define GUIDesignLabel(justify)
Definition: GUIDesigns.h:249
@ CLEARMESSAGEWINDOW
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
@ SUMO_TAG_TAZREL
a relation between two TAZs
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
const std::string getID() const
get ID (all Attribute Carriers have one)
void buildTAZRelationData(const CommonXMLStructure::SumoBaseObject *sumoBaseObject, const std::string &fromTAZID, const std::string &toTAZID, const Parameterised::Map &parameters)
Builds TAZRelationData.
double getAttributeDouble(SumoXMLAttr key) const
bool TAZRelExists(const GNEAdditional *TAZ) const
check if there is already a TAZRel defined in one TAZ
bool areAttributesValid() const
check if current attributes are valid
const Parameterised::Map & getParametersMap() const
get parameters as map
GNEViewNet * myViewNet
FOX need this.
Definition: GNEFrame.h:117
GNEDataInterval * getDataInterval() const
get current select data set ID
GNEFrameAttributeModules::GenericDataAttributes * myGenericDataAttributes
parameters editor creator
IntervalSelector * myIntervalSelector
interval selector modul
Definition: GNETAZ.h:34
long onCmdConfirmTAZRelation(FXObject *, FXSelector, void *)
called when user press confirm TAZ Relation button
long onUpdConfirmTAZRelation(FXObject *, FXSelector, void *)
called when TAZ Relation button is updated
long onCmdClearSelection(FXObject *, FXSelector, void *)
called when user press clear TAZ Relation button
void setLabels(const GNETAZ *fromTAZ, const GNETAZ *toTAZ)
set labels
FXLabel * myToTAZLabel
to TAZ Label
FXLabel * myFromTAZLabel
from TAZ label
Legend(GNETAZRelDataFrame *TAZRelDataFrame)
constructor
GNETAZ * mySecondTAZ
first selected TAZ Element
bool setTAZ(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
set clicked TAZ
void buildTAZRelationData()
build TAZRelation data
~GNETAZRelDataFrame()
Destructor.
GNETAZRelDataFrame::Legend * myLegend
TAZRel legend.
GNEAdditional * getSecondTAZ() const
get first selected TAZ Element
GNETAZRelDataFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void clearTAZSelection()
clear TAZ selection
GNETAZRelDataFrame::ConfirmTAZRelation * myConfirmTAZRelation
confirm TAZ Relation
GNETAZ * myFirstTAZ
first selected TAZ Element
GNEAdditional * getFirstTAZ() const
get first selected TAZ Element
class used to group all variables related with objects under cursor after a click over view
GNETAZ * getTAZFront() const
get front TAZ or a pointer to nullptr
GNENet * getNet() const
get the net object
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
Definition: GUIDesigns.cpp:128
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:112
static const RGBColor GREEN
Definition: RGBColor.h:186
static const RGBColor MAGENTA
Definition: RGBColor.h:190