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 
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewParent.h>
30 
31 #include "GNEShape.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 
38 GNEShape::GNEShape(GNENet* net, SumoXMLTag tag, bool movementBlocked) :
40  myNet(net),
41  myBlockMovement(movementBlocked) {
42 }
43 
44 
46 
47 
48 GNENet*
50  return myNet;
51 }
52 
53 
54 bool
56  return myBlockMovement;
57 }
58 
59 
60 void
61 GNEShape::draw(const Position& pos, double layer, double size) const {
62  if (myNet->getViewNet()->showLockIcon()) {
63  // Start pushing matrix
64  glPushMatrix();
65  // Traslate to middle of shape
66  glTranslated(pos.x(), pos.y(), layer + 0.1);
67  // Rotate 180 degrees
68  glRotated(180, 0, 0, 1);
69  // Set draw color
70  glColor3d(1, 1, 1);
71  // Draw icon depending of the selection status
72  if (mySelected) {
73  if (myBlockMovement) {
74  // Draw lock texture if shape is movable, is blocked and is selected
76  } else {
77  // Draw empty texture if shape is movable, isn't blocked and is selected
79  }
80  } else {
81  if (myBlockMovement) {
82  // Draw lock texture if shape is movable and is blocked
84  } else {
85  // Draw empty texture if shape is movable and isn't blocked
87  }
88  }
89  // Pop matrix
90  glPopMatrix();
91  }
92 }
93 
94 
95 void
97  if (!myNet) {
98  throw ProcessError("Net cannot be nullptr");
99  } else {
100  GUIGlObject* object = dynamic_cast<GUIGlObject*>(this);
101  gSelected.select(object->getGlID());
102  // add object into list of selected objects
104  if (changeFlag) {
105  mySelected = true;
106  }
107  }
108 }
109 
110 
111 void
113  if (!myNet) {
114  throw ProcessError("Net cannot be nullptr");
115  } else {
116  GUIGlObject* object = dynamic_cast<GUIGlObject*>(this);
117  gSelected.deselect(object->getGlID());
118  // remove object of list of selected objects
120  if (changeFlag) {
121  mySelected = false;
122  }
123  }
124 }
125 
126 
127 bool
129  return mySelected;
130 }
131 
132 
133 std::string
135  return getTagStr() + ": " + getID();
136 }
137 
138 
139 std::string
141  return getTagStr();
142 }
143 
144 
145 void
147 }
148 
149 
150 /****************************************************************************/
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.
void draw(const Position &pos, double layer, double size=0.5) const
draw lock icon
Definition: GNEShape.cpp:61
SumoXMLTag
Numbers representing SUMO-XML - element names.
void addedLockedObject(const GUIGlObjectType type)
set object selected
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:128
GNEViewParent * getViewParent() const
get the net object
double y() const
Returns the y-position.
Definition: Position.h:62
double x() const
Returns the x-position.
Definition: Position.h:57
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
GNEShape(GNENet *net, SumoXMLTag tag, bool movementBlocked)
Constructor.
Definition: GNEShape.cpp:38
GNENet * myNet
the net to inform about updates
Definition: GNEShape.h:165
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEShape.cpp:96
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEShape.cpp:140
bool showLockIcon() const
check if lock icon should be visible
LockGLObjectTypes * getLockGLObjectTypes() const
get selected items
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
bool myBlockMovement
flag to block movement
Definition: GNEShape.h:171
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:146
void removeLockedObject(const GUIGlObjectType type)
set object unselected
bool isMovementBlocked() const
return true if movement is blocked
Definition: GNEShape.cpp:55
GNESelectorFrame * getSelectorFrame() const
get frame for GNE_MODE_SELECT
const std::string getID() const
function to support debugging
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEShape.cpp:134
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:49
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEShape.cpp:112
GUIGlID getGlID() const
Returns the numerical id of the object.
GUISelectedStorage gSelected
A global holder of selected objects.
~GNEShape()
Destructor.
Definition: GNEShape.cpp:45
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1730