Eclipse SUMO - Simulation of Urban MObility
GNEFrame.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-2022 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 additional elements
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNEViewNet.h>
23 #include <netedit/GNEViewParent.h>
26 
27 #include "GNEFrame.h"
28 
29 
30 // ===========================================================================
31 // static members
32 // ===========================================================================
33 
34 FXFont* GNEFrame::myFrameHeaderFont = nullptr;
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 
40 GNEFrame::GNEFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet, const std::string& frameLabel) :
41  FXVerticalFrame(horizontalFrameParent, GUIDesignAuxiliarFrame),
42  myViewNet(viewNet) {
43 
44  // fill myPredefinedTagsMML (to avoid repeating this fill during every element creation)
45  int i = 0;
47  int key = SUMOXMLDefinitions::attrs[i].key;
48  assert(key >= 0);
49  while (key >= (int)myPredefinedTagsMML.size()) {
50  myPredefinedTagsMML.push_back("");
51  }
53  i++;
54  }
55 
56  // Create font only one time
57  if (myFrameHeaderFont == nullptr) {
58  myFrameHeaderFont = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
59  }
60 
61  // Create frame for header
62  myHeaderFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
63 
64  // Create frame for left elements of header (By default unused)
66  myHeaderLeftFrame->hide();
67 
68  // Create titel frame
69  myFrameHeaderLabel = new FXLabel(myHeaderFrame, frameLabel.c_str(), nullptr, GUIDesignLabelFrameInformation);
70 
71  // Create frame for right elements of header (By default unused)
73  myHeaderRightFrame->hide();
74 
75  // Add separator
76  new FXHorizontalSeparator(this, GUIDesignHorizontalSeparator);
77 
78  // Create frame for contents
79  myScrollWindowsContents = new FXScrollWindow(this, GUIDesignContentsScrollWindow);
80 
81  // Create frame for contents
83 
84  // Set font of header
86 
87  // Hide Frame
88  FXVerticalFrame::hide();
89 }
90 
91 
93  // delete frame header only one time
94  if (myFrameHeaderFont) {
95  delete myFrameHeaderFont;
96  myFrameHeaderFont = nullptr;
97  }
98 }
99 
100 
101 void
103  myFrameHeaderLabel->setFocus();
104 }
105 
106 
107 void
109  // show scroll window
110  FXVerticalFrame::show();
111  // Show and update Frame Area in which this GNEFrame is placed
113 }
114 
115 
116 void
118  // hide scroll window
119  FXVerticalFrame::hide();
120  // Hide Frame Area in which this GNEFrame is placed
122 }
123 
124 
125 void
126 GNEFrame::setFrameWidth(int newWidth) {
127  setWidth(newWidth);
128  myScrollWindowsContents->setWidth(newWidth);
129 }
130 
131 
132 GNEViewNet*
134  return myViewNet;
135 }
136 
137 
138 FXLabel*
140  return myFrameHeaderLabel;
141 }
142 
143 
144 FXFont*
146  return myFrameHeaderFont;
147 }
148 
149 
150 void
152  // this function has to be reimplemente in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
153 }
154 
155 // ---------------------------------------------------------------------------
156 // GNEFrame - protected methods
157 // ---------------------------------------------------------------------------
158 
159 void
161  // this function has to be reimplemente in all child frames that uses a TagSelector modul
162 }
163 
164 
165 void
167  // this function has to be reimplemente in all child frames that uses a DemandElementSelector
168 }
169 
170 
171 bool
173  // this function has to be reimplemente in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
174  return false;
175 }
176 
177 
178 void
180  // this function has to be reimplemente in all child frames that uses a TagSelector modul
181 }
182 
183 
184 void
186  // this function has to be reimplemente in all child frames that uses a AttributesCreator editor with extended attributes
187 }
188 
189 
190 void
192  // this function has to be reimplemente in all child frames that uses a OverlappedInspection
193 }
194 
195 
196 void
198  // this function has to be reimplemente in all child frames that uses a path
199 }
200 
201 void
203  FXDialogBox* attributesHelpDialog = new FXDialogBox(myScrollWindowsContents, ("Parameters of " + AC->getTagStr()).c_str(), GUIDesignDialogBoxResizable, 0, 0, 0, 0, 10, 10, 10, 38, 4, 4);
204  // Create FXTable
205  FXTable* myTable = new FXTable(attributesHelpDialog, attributesHelpDialog, MID_TABLE, GUIDesignTableNotEditable);
206  attributesHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::MODEINSPECT));
207  int sizeColumnDescription = 0;
208  int sizeColumnDefinitions = 0;
209  myTable->setVisibleRows((FXint)(AC->getTagProperty().getNumberOfAttributes()));
210  myTable->setVisibleColumns(3);
211  myTable->setTableSize((FXint)(AC->getTagProperty().getNumberOfAttributes()), 3);
212  myTable->setBackColor(FXRGB(255, 255, 255));
213  myTable->setColumnText(0, "Attribute");
214  myTable->setColumnText(1, "Description");
215  myTable->setColumnText(2, "Definition");
216  myTable->getRowHeader()->setWidth(0);
217  // Iterate over vector of additional parameters
218  int itemIndex = 0;
219  for (const auto& tagProperty : AC->getTagProperty()) {
220  // Set attribute
221  FXTableItem* attribute = new FXTableItem(tagProperty.getAttrStr().c_str());
222  attribute->setJustify(FXTableItem::CENTER_X);
223  myTable->setItem(itemIndex, 0, attribute);
224  // Set description of element
225  FXTableItem* type = new FXTableItem("");
226  type->setText(tagProperty.getDescription().c_str());
227  sizeColumnDescription = MAX2(sizeColumnDescription, (int)tagProperty.getDescription().size());
228  type->setJustify(FXTableItem::CENTER_X);
229  myTable->setItem(itemIndex, 1, type);
230  // Set definition
231  FXTableItem* definition = new FXTableItem(tagProperty.getDefinition().c_str());
232  definition->setJustify(FXTableItem::LEFT);
233  myTable->setItem(itemIndex, 2, definition);
234  sizeColumnDefinitions = MAX2(sizeColumnDefinitions, (int)tagProperty.getDefinition().size());
235  itemIndex++;
236  }
237  // set header
238  FXHeader* header = myTable->getColumnHeader();
239  header->setItemJustify(0, JUSTIFY_CENTER_X);
240  header->setItemSize(0, 120);
241  header->setItemJustify(1, JUSTIFY_CENTER_X);
242  header->setItemSize(1, sizeColumnDescription * 7);
243  header->setItemJustify(2, JUSTIFY_CENTER_X);
244  header->setItemSize(2, sizeColumnDefinitions * 6);
245  // Create horizontal separator
246  new FXHorizontalSeparator(attributesHelpDialog, GUIDesignHorizontalSeparator);
247  // Create frame for OK Button
248  FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(attributesHelpDialog, GUIDesignAuxiliarHorizontalFrame);
249  // Create Button Close (And two more horizontal frames to center it)
250  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
251  new FXButton(myHorizontalFrameOKButton, "OK\t\tclose", GUIIconSubSys::getIcon(GUIIcon::ACCEPT), attributesHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
252  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
253  // Write Warning in console if we're in testing mode
254  WRITE_DEBUG("Opening HelpAttributes dialog for tag '" + AC->getTagProperty().getTagStr() + "' showing " + toString(AC->getTagProperty().getNumberOfAttributes()) + " attributes");
255  // create Dialog
256  attributesHelpDialog->create();
257  // show in the given position
258  attributesHelpDialog->show(PLACEMENT_CURSOR);
259  // refresh APP
260  getApp()->refresh();
261  // open as modal dialog (will block all windows until stop() or stopModal() is called)
262  getApp()->runModalFor(attributesHelpDialog);
263  // Write Warning in console if we're in testing mode
264  WRITE_DEBUG("Closing HelpAttributes dialog for tag '" + AC->getTagProperty().getTagStr() + "'");
265 }
266 
267 
268 const std::vector<std::string>&
270  return myPredefinedTagsMML;
271 }
272 
273 /****************************************************************************/
@ MID_TABLE
The Table.
Definition: GUIAppEnum.h:493
#define GUIDesignTableNotEditable
design for table extended over frame that cannot be edited
Definition: GUIDesigns.h:553
#define GUIDesignDialogBoxResizable
design for standard dialog box (for example, about dialog)
Definition: GUIDesigns.h:536
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:352
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:343
#define GUIDesignButtonOK
Definition: GUIDesigns.h:124
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:395
#define GUIDesignContentsScrollWindow
design for the content frame of every frame
Definition: GUIDesigns.h:337
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:340
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:244
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
@ SUMO_ATTR_NOTHING
invalid attribute
T MAX2(T a, T b)
Definition: StdDefs.h:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
FXHorizontalFrame * myHeaderRightFrame
fame for right header elements
Definition: GNEFrame.h:126
virtual void attributeUpdated()
function called after set a valid attribute in AttributeCreator/AttributeEditor/ParametersEditor/....
Definition: GNEFrame.cpp:179
void focusUpperElement()
focus upper element of frame
Definition: GNEFrame.cpp:102
virtual void updateFrameAfterUndoRedo()
function called after undo/redo in the current frame (can be reimplemented in frame children)
Definition: GNEFrame.cpp:151
virtual void attributesEditorExtendedDialogOpened()
open AttributesCreator extended dialog (can be reimplemented in frame children)
Definition: GNEFrame.cpp:185
virtual void tagSelected()
Tag selected in TagSelector.
Definition: GNEFrame.cpp:160
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition: GNEFrame.cpp:139
FXScrollWindow * myScrollWindowsContents
scroll windows that holds the content frame
Definition: GNEFrame.h:130
virtual void demandElementSelected()
selected demand element in DemandElementSelector
Definition: GNEFrame.cpp:166
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:114
FXFont * getFrameHeaderFont() const
get font of the header's frame
Definition: GNEFrame.cpp:145
virtual void createPath()
create path (can be reimplemented in frame children)
Definition: GNEFrame.cpp:197
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:117
FXHorizontalFrame * myHeaderFrame
fame for header elements
Definition: GNEFrame.h:120
~GNEFrame()
destructor
Definition: GNEFrame.cpp:92
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
virtual void selectedOverlappedElement(GNEAttributeCarrier *AC)
open AttributesCreator extended dialog (can be reimplemented in frame children)
Definition: GNEFrame.cpp:191
virtual bool shapeDrawed()
build a shaped element using the drawed shape (can be reimplemented in frame children)
Definition: GNEFrame.cpp:172
void openHelpAttributesDialog(const GNEAttributeCarrier *AC) const
Open help attributes dialog.
Definition: GNEFrame.cpp:202
std::vector< std::string > myPredefinedTagsMML
Map of attribute ids to their (readable) string-representation (needed for SUMOSAXAttributesImpl_Cach...
Definition: GNEFrame.h:139
FXLabel * myFrameHeaderLabel
the label for the frame's header
Definition: GNEFrame.h:136
void setFrameWidth(int newWidth)
set width of GNEFrame
Definition: GNEFrame.cpp:126
static FXFont * myFrameHeaderFont
static Font for the Header (it's common for all headers, then create only one time)
Definition: GNEFrame.h:133
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:269
FXHorizontalFrame * myHeaderLeftFrame
fame for left header elements
Definition: GNEFrame.h:123
GNEFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet, const std::string &frameLabel)
Constructor.
Definition: GNEFrame.cpp:40
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
int getNumberOfAttributes() const
get number of attributes
GNEViewParent * getViewParent() const
get the net object
void hideFramesArea()
hide frames area if all GNEFrames are hidden
void showFramesArea()
show frames area if at least a GNEFrame is showed
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static StringBijection< int >::Entry attrs[]
The names of SUMO-XML attributes (for passing to GenericSAXHandler)