Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEInspectorFrame.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/****************************************************************************/
19// The Widget for modifying network-element attributes (i.e. lane speed)
20/****************************************************************************/
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
30
31#include "GNEInspectorFrame.h"
32
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
41
47
48// Object implementation
49FXIMPLEMENT(GNEInspectorFrame, FXVerticalFrame, GNEInspectorFrameMap, ARRAYNUMBER(GNEInspectorFrameMap))
50FXIMPLEMENT(GNEInspectorFrame::TemplateEditor, MFXGroupBoxModule, TemplateEditorMap, ARRAYNUMBER(TemplateEditorMap))
51
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56
57// ---------------------------------------------------------------------------
58// GNEInspectorFrame::TemplateEditor - methods
59// ---------------------------------------------------------------------------
60
62 MFXGroupBoxModule(inspectorFrameParent, TL("Templates")),
63 myInspectorFrameParent(inspectorFrameParent),
64 myEdgeTemplate(nullptr) {
65 // Create set template button
66 mySetTemplateButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Set as Template"), "", "", nullptr, this, MID_HOTKEY_SHIFT_F1_TEMPLATE_SET, GUIDesignButton);
67 // Create copy template button
68 myCopyTemplateButton = GUIDesigns::buildFXButton(getCollapsableFrame(), "", "", "", nullptr, this, MID_HOTKEY_SHIFT_F2_TEMPLATE_COPY, GUIDesignButton);
69 // Create copy template button
70 myClearTemplateButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("clear Edge Template"), "", "", nullptr, this, MID_HOTKEY_SHIFT_F3_TEMPLATE_CLEAR, GUIDesignButton);
71}
72
73
76
77
78bool
80 // show template editor only if we're editing an edge in Network mode AND we have at least one inspected edge
81 if (myInspectorFrameParent->myViewNet->getEditModes().isCurrentSupermodeNetwork()) {
82 for (const auto& AC : myInspectorFrameParent->getViewNet()->getInspectedElements().getACs()) {
83 if (AC->getTagProperty().getTag() == SUMO_TAG_EDGE) {
84 // update buttons and show module
85 updateButtons();
86 show();
87 return true;
88 }
89 }
90 }
91 return false;
92}
93
94
95void
97 // hide template editor
98 hide();
99}
100
101
104 return myEdgeTemplate;
105}
106
107
108void
110 // delete previous template edge
111 if (myEdgeTemplate) {
112 delete myEdgeTemplate;
113 myEdgeTemplate = nullptr;
114 }
115 // update edge template
116 if (edge) {
117 myEdgeTemplate = new GNEEdgeTemplate(edge);
118 // use template by default
119 myInspectorFrameParent->myViewNet->getViewParent()->getCreateEdgeFrame()->setUseEdgeTemplate();
120 }
121}
122
123
124void
126 if (myEdgeTemplate) {
127 myEdgeTemplate->updateLaneTemplates();
128 // use template by default
129 myInspectorFrameParent->myViewNet->getViewParent()->getCreateEdgeFrame()->setUseEdgeTemplate();
130 }
131}
132
133void
135 // check if template editor AND mySetTemplateButton is enabled
136 if (shown() && mySetTemplateButton->isEnabled()) {
137 onCmdSetTemplate(nullptr, 0, nullptr);
138 }
139}
140
141
142void
144 // check if template editor AND myCopyTemplateButton is enabled
145 if (shown() && myCopyTemplateButton->isEnabled()) {
146 onCmdCopyTemplate(nullptr, 0, nullptr);
147 }
148}
149
150
151void
153 // check if template editor AND myClearTemplateButton is enabled
154 if (shown() && myClearTemplateButton->isEnabled()) {
155 onCmdClearTemplate(nullptr, 0, nullptr);
156 }
157}
158
159
160long
162 // apply to all selected edges
163 for (const auto& AC : myInspectorFrameParent->myViewNet->getInspectedElements().getACs()) {
164 if (AC->getTagProperty().getTag() == SUMO_TAG_EDGE) {
165 // set template
166 setEdgeTemplate(myInspectorFrameParent->myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(AC->getID()));
167 // update buttons
168 updateButtons();
169 }
170 }
171 return 1;
172}
173
174
175long
177 // first check
178 if (myEdgeTemplate) {
179 // begin copy template
180 myInspectorFrameParent->myViewNet->getUndoList()->begin(myEdgeTemplate, "copy edge template");
181 // iterate over inspected ACs
182 for (const auto& AC : myInspectorFrameParent->myViewNet->getInspectedElements().getACs()) {
183 // avoid copy template in the same edge
184 if (AC->getID() != myEdgeTemplate->getID()) {
185 // retrieve edge ID (and throw exception if edge doesn't exist)
186 myInspectorFrameParent->myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(AC->getID())->copyTemplate(myEdgeTemplate, myInspectorFrameParent->myViewNet->getUndoList());
187 }
188 }
189 // end copy template
190 myInspectorFrameParent->myViewNet->getUndoList()->end();
191 // refresh inspector parent
192 myInspectorFrameParent->myAttributesEditor->refreshAttributesEditor();
193 }
194 return 1;
195}
196
197
198long
200 // set null edge
201 setEdgeTemplate(nullptr);
202 // update buttons
203 updateButtons();
204 return 1;
205}
206
207
208void
210 const auto& inspectedElements = myInspectorFrameParent->getViewNet()->getInspectedElements();
211 // only show set template button if we have exactly one inspected edge
212 if (inspectedElements.isInspectingSingleElement() && (inspectedElements.getFirstAC()->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
213 mySetTemplateButton->setText((TLF("Set edge '%' as Template", inspectedElements.getFirstAC()->getID())).c_str());
214 mySetTemplateButton->show();
215 } else {
216 mySetTemplateButton->hide();
217 }
218 // enable or disable clear buttons depending of myEdgeTemplate
219 if (myEdgeTemplate) {
220 // update caption of copy button
221 if (inspectedElements.isInspectingSingleElement()) {
222 myCopyTemplateButton->setText(("Copy '" + myEdgeTemplate->getID() + "' into edge '" + inspectedElements.getFirstAC()->getID() + "'").c_str());
223 } else {
224 myCopyTemplateButton->setText(("Copy '" + myEdgeTemplate->getID() + "' into " + toString(inspectedElements.getACs().size()) + " selected edges").c_str());
225 }
226 // enable set and clear buttons
227 myCopyTemplateButton->enable();
228 myClearTemplateButton->enable();
229 } else {
230 // update caption of copy button
231 myCopyTemplateButton->setText(TL("No edge Template Set"));
232 // disable set and clear buttons
233 myCopyTemplateButton->disable();
234 myClearTemplateButton->disable();
235 }
236}
237
238// ---------------------------------------------------------------------------
239// GNEInspectorFrame - methods
240// ---------------------------------------------------------------------------
241
243 GNEFrame(viewParent, viewNet, "Inspector") {
244
245 // Create back button
248 myHeaderLeftFrame->hide();
249 myBackButton->hide();
250
251 // Create Overlapped Inspection module
253
254 // Create Attributes Editor module
256
257 // Create Flow Attributes Editor module
259
260 // Create GEO Parameters Editor module
262
263 // create parameters Editor module
265
266 // Create Netedit Attributes Editor module
268
269 // Create Template editor module
271
272 // Create GNEElementTree module
274}
275
276
278
279
280void
283 // stop select new element
285 // show
287}
288
289
290void
295
296
297bool
299 const Position &clickedPosition, const bool shiftKeyPressed) {
300 // get unlocked attribute carrier front
301 auto AC = viewObjects.getAttributeCarrierFront();
302 // first check if we have clicked over an Attribute Carrier
303 if (AC) {
304 // if Control key is Pressed, select instead inspect element
306 // toggle networkElement selection
307 if (AC->isAttributeCarrierSelected()) {
309 } else {
310 AC->selectAttributeCarrier();
311 }
312 } else {
313 // show Overlapped Inspection module
314 myOverlappedInspection->showOverlappedInspection(viewObjects, clickedPosition, shiftKeyPressed);
315 // focus upper element of inspector frame
317 }
318 return true;
319 } else {
320 return false;
321 }
322}
323
324
325void
327 std::vector<GNEAttributeCarrier*> itemsToInspect;
328 // Use the implementation of inspect for multiple AttributeCarriers to avoid repetition of code
329 if (AC) {
331 // obtain selected ACs depending of current supermode
332 const auto selectedACs = myViewNet->getNet()->getAttributeCarriers()->getSelectedAttributeCarriers(false);
333 // reserve space
334 itemsToInspect.reserve(selectedACs.size());
335 // iterate over selected ACs
336 for (const auto& selectedAC : selectedACs) {
337 // filter ACs to inspect using Tag as criterion
338 if (selectedAC->getTagProperty().getTag() == AC->getTagProperty().getTag()) {
339 itemsToInspect.push_back(selectedAC);
340 }
341 }
342 } else {
343 itemsToInspect.push_back(AC);
344 }
345 }
346 inspectElements(itemsToInspect, previousInspectedAC);
347}
348
349void
350GNEInspectorFrame::inspectElements(const std::vector<GNEAttributeCarrier*>& ACs, GNEAttributeCarrier* previousInspectedAC) {
352 myPreviousInspectedAC = previousInspectedAC;
354}
355
356
357void
359 // simply clear overlapped inspection (it refresh inspector frame)
361}
362
363
364void
366 const auto& inspectedElements = myViewNet->getInspectedElements();
367 // check if show back button
369 myHeaderLeftFrame->show();
370 myBackButton->show();
371 } else {
372 myHeaderLeftFrame->hide();
373 myBackButton->hide();
374 }
375 // Show all attribute editors (will be automatically hidden if there are no elements to inspect)
376 myAttributesEditor->showAttributesEditor(inspectedElements.getACs());
377 myFlowAttributesEditor->showAttributesEditor(inspectedElements.getACs());
378 myNeteditAttributesEditor->showAttributesEditor(inspectedElements.getACs());
379 myGEOAttributesEditor->showAttributesEditor(inspectedElements.getACs());
380 // Hide other moduls
384 // If vector of attribute Carriers contain data
385 if (inspectedElements.isInspectingElements()) {
386 // Set header
387 std::string headerString;
388 if (inspectedElements.getFirstAC()->getTagProperty().isNetworkElement()) {
389 headerString = "Net: ";
390 } else if (inspectedElements.getFirstAC()->getTagProperty().isAdditionalElement()) {
391 headerString = "Additional: ";
392 } else if (inspectedElements.getFirstAC()->getTagProperty().isShapeElement()) {
393 headerString = "Shape: ";
394 } else if (inspectedElements.getFirstAC()->getTagProperty().isTAZElement()) {
395 headerString = "TAZ: ";
396 } else if (inspectedElements.getFirstAC()->getTagProperty().isWireElement()) {
397 headerString = "WIRE: ";
398 } else if (inspectedElements.getFirstAC()->getTagProperty().isVehicle()) {
399 headerString = "Vehicle: ";
400 } else if (inspectedElements.getFirstAC()->getTagProperty().isRoute()) {
401 headerString = "Route: ";
402 } else if (inspectedElements.getFirstAC()->getTagProperty().isPerson()) {
403 headerString = "Person: ";
404 } else if (inspectedElements.getFirstAC()->getTagProperty().isPlanPerson()) {
405 headerString = "PersonPlan: ";
406 } else if (inspectedElements.getFirstAC()->getTagProperty().isContainer()) {
407 headerString = "Container: ";
408 } else if (inspectedElements.getFirstAC()->getTagProperty().isPlanContainer()) {
409 headerString = "ContainerPlan: ";
410 } else if (inspectedElements.getFirstAC()->getTagProperty().isVehicleStop()) {
411 headerString = "Stop: ";
412 } else if (inspectedElements.getFirstAC()->getTagProperty().isDataElement()) {
413 headerString = "Data: ";
414 }
416 headerString += toString(inspectedElements.getACs().size()) + " ";
417 }
418 headerString += inspectedElements.getFirstAC()->getTagStr();
420 headerString += "s";
421 }
422 // Set headerString into header label
423 getFrameHeaderLabel()->setText(headerString.c_str());
424
425 // show parameters editor
427
428 // If attributes correspond to an Edge and we aren't in demand mode, show template editor
430
431 // if we inspect a single Attribute carrier vector, show their children
432 if (inspectedElements.isInspectingSingleElement()) {
433 myHierarchicalElementTree->showHierarchicalElementTree(inspectedElements.getFirstAC());
434 }
435 } else {
436 getFrameHeaderLabel()->setText(TL("Inspect"));
438 }
439 // update frame width
441 // update viewNet
442 myViewNet->update();
443}
444
445
450
451
456
457
462
463
468
469
474
475
476long
479 return 1;
480}
481
482
483void
487
488
489void
491 inspectElement(AC);
492 // update view (due dotted contour)
494}
495
496/****************************************************************************/
FXDEFMAP(GNEInspectorFrame) GNEInspectorFrameMap[]
@ MID_GNE_INSPECTORFRAME_INSPECTPREVIOUSELEMENT
go back to the previous element
@ MID_HOTKEY_SHIFT_F2_TEMPLATE_COPY
copy template
Definition GUIAppEnum.h:264
@ MID_HOTKEY_SHIFT_F1_TEMPLATE_SET
set template
Definition GUIAppEnum.h:262
@ MID_HOTKEY_SHIFT_F3_TEMPLATE_CLEAR
clear template
Definition GUIAppEnum.h:266
#define GUIDesignButton
Definition GUIDesigns.h:82
#define GUIDesignButtonRectangular
little rectangular button used in frames (For example, in "help" buttons)
Definition GUIDesigns.h:94
@ BIGARROWLEFT
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
@ SUMO_TAG_EDGE
begin/end of the description of an edge
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void showAttributesEditor(GNEAttributeCarrier *AC)
edit attributes of the given AC (usually the edited template AC)
void abortReparenting()
abort selecting parent
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
void hideHierarchicalElementTree()
hide GNEElementTree
void showHierarchicalElementTree(GNEAttributeCarrier *AC)
show GNEElementTree
void hideParametersEditor()
hide netedit attributes EditorInspector
void showParametersEditor()
show netedit attributes EditorInspector
void setFrameWidth(const int newWidth)
set width of GNEFrame
Definition GNEFrame.cpp:133
void focusUpperElement()
focus upper element of frame
Definition GNEFrame.cpp:109
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition GNEFrame.cpp:162
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:115
virtual void show()
show Frame
Definition GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition GNEFrame.cpp:124
FXHorizontalFrame * myHeaderLeftFrame
fame for left header elements
Definition GNEFrame.h:124
void hideTemplateEditor()
hide template editor
void clearTemplate()
clear template (used by shortcut)
void setEdgeTemplate(const GNEEdge *edge)
set edge template
long onCmdCopyTemplate(FXObject *, FXSelector, void *)
copy edge attributes from edge template
void setTemplate()
set template (used by shortcut)
long onCmdSetTemplate(FXObject *, FXSelector, void *)
GNEEdgeTemplate * getEdgeTemplate() const
get edge template (to copy attributes from)
void copyTemplate()
copy template (used by shortcut)
void updateEdgeTemplate()
update edge template
bool showTemplateEditor()
show template editor
long onCmdClearTemplate(FXObject *, FXSelector, void *)
clear current edge template
GNEAttributesEditor * myNeteditAttributesEditor
Netedit Attributes editor.
long onCmdInspectPreviousElement(FXObject *, FXSelector, void *)
called when user press inspet previous elemnt button
GNEAttributeCarrier * myPreviousInspectedAC
Pointer to previous element inspected.
void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog (can be reimplemented in frame children)
TemplateEditor * getTemplateEditor() const
get template editor
GNEInspectorFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void inspectElements(const std::vector< GNEAttributeCarrier * > &ACs, GNEAttributeCarrier *previousInspectedAC=nullptr)
Inspect the given elements.
GNEElementTree * getHierarchicalElementTree() const
get GNEElementTree modul
bool inspectClickedElements(GNEViewNetHelper::ViewObjectsSelector &viewObjects, const Position &clickedPosition, const bool shiftKeyPressed)
process click over Viewnet
void show()
show inspector frame
GNEFrameAttributeModules::ParametersEditor * myParametersEditor
Parameters editor inspector.
GNEAttributesEditor * myFlowAttributesEditor
Flow attributes editor.
GNEAttributesEditor * myAttributesEditor
Attributes editor.
GNEAttributesEditor * myGEOAttributesEditor
GEO Attributes editor.
GNEOverlappedInspection * myOverlappedInspection
FOX need this.
GNEOverlappedInspection * getOverlappedInspection() const
get GNEOverlappedInspection modul
void clearInspection()
clear inspection
GNEAttributesEditor * getAttributesEditor() const
get AttributesEditor
void hide()
hide inspector frame
FXButton * myBackButton
Back Button.
void inspectElement(GNEAttributeCarrier *AC, GNEAttributeCarrier *previousInspectedAC=nullptr)
Inspect a single element.
GNEElementTree * myHierarchicalElementTree
Attribute Carrier Hierarchy.
void refreshInspection()
refresh current inspection
~GNEInspectorFrame()
Destructor.
TemplateEditor * myTemplateEditor
Template editor.
GNEAttributesEditor * getNeteditAttributesEditor() const
get Netedit Attributes editor
void updateFrameAfterUndoRedo()
function called after undo/redo in the current frame (can be reimplemented in frame children)
std::vector< GNEAttributeCarrier * > getSelectedAttributeCarriers(const bool ignoreCurrentSupermode)
get all selected attribute carriers (or only relative to current supermode
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
void clearOverlappedInspection()
clear overlapped inspection
void hiderOverlappedInspection()
hide overlapped inspection
void showOverlappedInspection(GNEViewNetHelper::ViewObjectsSelector &viewObjects, const Position &clickedPosition, const bool shiftKeyPressed)
show overlapped inspection
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void inspectACs(const std::vector< GNEAttributeCarrier * > &ACs)
inspect multiple ACs
bool isInspectingMultipleElements() const
check if we're inspecting more than one elements
class used to group all variables related with objects under cursor after a click over view
GNEAttributeCarrier * getAttributeCarrierFront() const
get front attribute carrier or a pointer to nullptr
GNENet * getNet() const
get the net object
const GNEViewNetHelper::MouseButtonKeyPressed & getMouseButtonKeyPressed() const
get Key Pressed module
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
GNEViewParent * getViewParent() const
get the net object
void updateViewNet(const bool ignoreViewUpdater=true) const
Mark the entire GNEViewNet to be repainted later.
A single child window which contains a view of the simulation area.
int getFrameAreaWidth() const
get frame area width
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
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXGroupBoxModule (based on FXGroupBox)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
bool altKeyPressed() const
check if ALT is pressed during current event
bool controlKeyPressed() const
check if CONTROL is pressed during current event