1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
10 /// @file    GNEShape.cpp
11 /// @author  Pablo Alvarez Lopez
12 /// @date    Jun 2017
13 /// @version $Id$
14 ///
15 // Abstract class for Shapes uses in netedit
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <utils/gui/images/GUITextureSubSys.h>
25 #include <utils/gui/div/GUIGlobalSelection.h>
26 #include <netedit/frames/GNESelectorFrame.h>
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEViewParent.h>
30 #include <utils/gui/globjects/GLIncludes.h>
31 
32 #include "GNEShape.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 
GNEShape(GNENet * net,SumoXMLTag tag,bool movementBlocked,const std::vector<GNEEdge * > & edgeParents,const std::vector<GNELane * > & laneParents,const std::vector<GNEShape * > & shapeParents,const std::vector<GNEAdditional * > & additionalParents,const std::vector<GNEDemandElement * > & demandElementParents,const std::vector<GNEEdge * > & edgeChilds,const std::vector<GNELane * > & laneChilds,const std::vector<GNEShape * > & shapeChilds,const std::vector<GNEAdditional * > & additionalChilds,const std::vector<GNEDemandElement * > & demandElementChilds)39 GNEShape::GNEShape(GNENet* net, SumoXMLTag tag, bool movementBlocked,
40                    const std::vector<GNEEdge*>& edgeParents,
41                    const std::vector<GNELane*>& laneParents,
42                    const std::vector<GNEShape*>& shapeParents,
43                    const std::vector<GNEAdditional*>& additionalParents,
44                    const std::vector<GNEDemandElement*>& demandElementParents,
45                    const std::vector<GNEEdge*>& edgeChilds,
46                    const std::vector<GNELane*>& laneChilds,
47                    const std::vector<GNEShape*>& shapeChilds,
48                    const std::vector<GNEAdditional*>& additionalChilds,
49                    const std::vector<GNEDemandElement*>& demandElementChilds) :
50     GNEAttributeCarrier(tag),
51     GNEHierarchicalElementParents(this, edgeParents, laneParents, shapeParents, additionalParents, demandElementParents),
52     GNEHierarchicalElementChilds(this, edgeChilds, laneChilds, shapeChilds, additionalChilds, demandElementChilds),
53     myNet(net),
54     myBlockMovement(movementBlocked) {
55 }
56 
57 
~GNEShape()58 GNEShape::~GNEShape() {}
59 
60 
61 GNENet*
getNet() const62 GNEShape::getNet() const {
63     return myNet;
64 }
65 
66 
67 bool
isMovementBlocked() const68 GNEShape::isMovementBlocked() const {
69     return myBlockMovement;
70 }
71 
72 
73 void
draw(const Position & pos,double layer,double size) const74 GNEShape::draw(const Position& pos, double layer, double size) const {
75     if (myNet->getViewNet()->showLockIcon()) {
76         // Start pushing matrix
77         glPushMatrix();
78         // Traslate to middle of shape
79         glTranslated(pos.x(), pos.y(), layer + 0.1);
80         // Rotate 180 degrees
81         glRotated(180, 0, 0, 1);
82         // Set draw color
83         glColor3d(1, 1, 1);
84         // Draw icon depending of the selection status
85         if (mySelected) {
86             if (myBlockMovement) {
87                 // Draw lock texture if shape is movable, is blocked and is selected
88                 GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getTexture(GNETEXTURE_LOCKSELECTED), size);
89             } else {
90                 // Draw empty texture if shape is movable, isn't blocked and is selected
91                 GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getTexture(GNETEXTURE_EMPTYSELECTED), size);
92             }
93         } else {
94             if (myBlockMovement) {
95                 // Draw lock texture if shape is movable and is blocked
96                 GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getTexture(GNETEXTURE_LOCK), size);
97             } else {
98                 // Draw empty texture if shape is movable and isn't blocked
99                 GUITexturesHelper::drawTexturedBox(GUITextureSubSys::getTexture(GNETEXTURE_EMPTY), size);
100             }
101         }
102         // Pop matrix
103         glPopMatrix();
104     }
105 }
106 
107 
108 void
selectAttributeCarrier(bool changeFlag)109 GNEShape::selectAttributeCarrier(bool changeFlag) {
110     if (!myNet) {
111         throw ProcessError("Net cannot be nullptr");
112     } else {
113         GUIGlObject* object = dynamic_cast<GUIGlObject*>(this);
114         gSelected.select(object->getGlID());
115         // add object into list of selected objects
116         myNet->getViewNet()->getViewParent()->getSelectorFrame()->getLockGLObjectTypes()->addedLockedObject(object->getType());
117         if (changeFlag) {
118             mySelected = true;
119         }
120     }
121 }
122 
123 
124 void
unselectAttributeCarrier(bool changeFlag)125 GNEShape::unselectAttributeCarrier(bool changeFlag) {
126     if (!myNet) {
127         throw ProcessError("Net cannot be nullptr");
128     } else {
129         GUIGlObject* object = dynamic_cast<GUIGlObject*>(this);
130         gSelected.deselect(object->getGlID());
131         // remove object of list of selected objects
132         myNet->getViewNet()->getViewParent()->getSelectorFrame()->getLockGLObjectTypes()->removeLockedObject(object->getType());
133         if (changeFlag) {
134             mySelected = false;
135         }
136     }
137 }
138 
139 
140 bool
isAttributeCarrierSelected() const141 GNEShape::isAttributeCarrierSelected() const {
142     return mySelected;
143 }
144 
145 
146 bool
drawUsingSelectColor() const147 GNEShape::drawUsingSelectColor() const {
148     if (mySelected && (myNet->getViewNet()->getEditModes().currentSupermode == GNE_SUPERMODE_NETWORK)) {
149         return true;
150     } else {
151         return false;
152     }
153 }
154 
155 
156 std::string
getPopUpID() const157 GNEShape::getPopUpID() const {
158     return getTagStr() + ": " + getID();
159 }
160 
161 
162 std::string
getHierarchyName() const163 GNEShape::getHierarchyName() const {
164     return getTagStr();
165 }
166 
167 /****************************************************************************/
168