SUMO - Simulation of Urban MObility
GNEShape.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Abstract class for Shapes uses in netedit
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
28 #include <netedit/GNENet.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNEViewParent.h>
31 
32 #include "GNEShape.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
39 GNEShape::GNEShape(GNENet* net, SumoXMLTag tag, bool movementBlocked, bool shapeBlocked) :
41  myNet(net),
42  myBlockMovement(movementBlocked),
43  myBlockShape(shapeBlocked) {
44 }
45 
46 
48 
49 
50 GNENet*
52  return myNet;
53 }
54 
55 
56 bool
58  return myBlockMovement;
59 }
60 
61 
62 bool
64  return myBlockShape;
65 }
66 
67 
68 void
69 GNEShape::drawLockIcon(const Position& pos, double layer, double size) const {
70  if (myNet->getViewNet()->showLockIcon()) {
71  // Start pushing matrix
72  glPushMatrix();
73  // Traslate to middle of shape
74  glTranslated(pos.x(), pos.y(), layer + 0.1);
75  // Rotate 180 degrees
76  glRotated(180, 0, 0, 1);
77  // Set draw color
78  glColor3d(1, 1, 1);
79  // Draw icon depending of the selection status
80  if (mySelected) {
81  if (myBlockMovement) {
82  // Draw lock texture if shape is movable, is blocked and is selected
84  } else {
85  // Draw empty texture if shape is movable, isn't blocked and is selected
87  }
88  } else {
89  if (myBlockMovement) {
90  // Draw lock texture if shape is movable and is blocked
92  } else {
93  // Draw empty texture if shape is movable and isn't blocked
95  }
96  }
97  // Pop matrix
98  glPopMatrix();
99  }
100 }
101 
102 
103 void
105  if (!myNet) {
106  throw ProcessError("Net cannot be nullptr");
107  } else {
108  gSelected.select(dynamic_cast<GUIGlObject*>(this)->getGlID());
109  if (changeFlag) {
110  mySelected = true;
111  }
112  }
113 }
114 
115 
116 void
118  if (!myNet) {
119  throw ProcessError("Net cannot be nullptr");
120  } else {
121  gSelected.deselect(dynamic_cast<GUIGlObject*>(this)->getGlID());
122  if (changeFlag) {
123  mySelected = false;
124  }
125  }
126 }
127 
128 
129 bool
131  return mySelected;
132 }
133 
134 
135 std::string
137  return toString(getTag()) + ": " + getID();
138 }
139 
140 
141 std::string
143  return toString(getTag());
144 }
145 
146 
147 void
149 }
150 
151 
152 /****************************************************************************/
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
SumoXMLTag
Numbers representing SUMO-XML - element names.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEShape.cpp:130
double y() const
Returns the y-position.
Definition: Position.h:61
GNEShape(GNENet *net, SumoXMLTag tag, bool movementBlocked, bool shapeBlocked)
Constructor.
Definition: GNEShape.cpp:39
double x() const
Returns the x-position.
Definition: Position.h:56
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:80
GNENet * myNet
the net to inform about updates
Definition: GNEShape.h:196
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEShape.cpp:104
void drawLockIcon(const Position &pos, double layer, double size=0.5) const
draw lock icon
Definition: GNEShape.cpp:69
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEShape.cpp:142
bool showLockIcon() const
check if lock icon should be visible
bool myBlockShape
flag for block shape
Definition: GNEShape.h:205
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:202
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
virtual void mouseOverObject(const GUIVisualizationSettings &s) const =0
method for check if mouse is over objects
Definition: GNEShape.cpp:148
bool isMovementBlocked() const
return true if movement is blocked
Definition: GNEShape.cpp:57
const std::string getID() const
function to support debugging
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEShape.cpp:136
void deselect(GUIGlID id)
Deselects the object with the given id.
GNENet * getNet() const
get Net in which this element is placed
Definition: GNEShape.cpp:51
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEShape.cpp:117
virtual GUIGlID getGlID() const =0
Returns the numerical id of the object.
bool isShapeBlocked() const
return true if shape is blocked
Definition: GNEShape.cpp:63
GUISelectedStorage gSelected
A global holder of selected objects.
~GNEShape()
Destructor.
Definition: GNEShape.cpp:47
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1745
SumoXMLTag getTag() const
get XML Tag assigned to this object