Eclipse SUMO - Simulation of Urban MObility
GUIMessageWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-2020 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 /****************************************************************************/
20 // A logging window for the gui
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <cassert>
30 #include <fxkeys.h>
31 #include "GUIMessageWindow.h"
32 
33 
34 // ===========================================================================
35 // static members
36 // ===========================================================================
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 GUIMessageWindow::GUIMessageWindow(FXComposite* parent) :
44  FXText(parent, nullptr, 0, 0, 0, 0, 0, 50),
45  myStyles(new FXHiliteStyle[8]),
46  myErrorRetriever(nullptr),
47  myMessageRetriever(nullptr),
48  myWarningRetriever(nullptr) {
49  setStyled(true);
50  setEditable(false);
51  const FXColor white = FXRGB(0xff, 0xff, 0xff);
52  const FXColor blue = FXRGB(0x00, 0x00, 0x88);
53  const FXColor green = FXRGB(0x00, 0x88, 0x00);
54  const FXColor red = FXRGB(0x88, 0x00, 0x00);
55  const FXColor yellow = FXRGB(0xe6, 0x98, 0x00);
56  const FXColor fuchsia = FXRGB(0x88, 0x00, 0x88);
57  // set separator style
58  myStyles[0].normalForeColor = blue;
59  myStyles[0].normalBackColor = white;
60  myStyles[0].selectForeColor = white;
61  myStyles[0].selectBackColor = blue;
62  myStyles[0].hiliteForeColor = blue;
63  myStyles[0].hiliteBackColor = white;
64  myStyles[0].activeBackColor = white;
65  myStyles[0].style = 0;
66  // set message text style
67  myStyles[1] = myStyles[0];
68  myStyles[1].normalForeColor = green;
69  myStyles[1].selectBackColor = green;
70  myStyles[1].hiliteForeColor = green;
71  myStyles[4] = myStyles[1];
72  myStyles[4].style = STYLE_UNDERLINE;
73  // set error text style
74  myStyles[2] = myStyles[0];
75  myStyles[2].normalForeColor = red;
76  myStyles[2].selectBackColor = red;
77  myStyles[2].hiliteForeColor = red;
78  myStyles[5] = myStyles[2];
79  myStyles[5].style = STYLE_UNDERLINE;
80  // set warning text style
81  myStyles[3] = myStyles[0];
82  myStyles[3].normalForeColor = yellow;
83  myStyles[3].selectBackColor = yellow;
84  myStyles[3].hiliteForeColor = yellow;
85  myStyles[6] = myStyles[3];
86  myStyles[6].style = STYLE_UNDERLINE;
87  // set GLDebug text style
88  myStyles[7] = myStyles[0];
89  myStyles[7].normalForeColor = fuchsia;
90  myStyles[7].selectBackColor = fuchsia;
91  myStyles[7].hiliteForeColor = fuchsia;
92  //
93  setHiliteStyles(myStyles);
94 }
95 
96 
98  delete[] myStyles;
99  delete myMessageRetriever;
100  delete myErrorRetriever;
101  delete myWarningRetriever;
102 }
103 
104 
105 const GUIGlObject*
106 GUIMessageWindow::getActiveStringObject(const FXString& text, const FXint pos, const FXint lineS, const FXint lineE) const {
107  const FXint idS = MAX2(text.rfind(" '", pos), text.rfind("='", pos));
108  const FXint idE = text.find("'", pos);
109  if (idS >= 0 && idE >= 0 && idS >= lineS && idE <= lineE) {
110  FXint typeS = text.rfind(" ", idS - 1);
111  if (typeS >= 0) {
112  if (text.at(typeS + 1) == '(') {
113  typeS++;
114  }
115  std::string type(text.mid(typeS + 1, idS - typeS - 1).lower().text());
116  if (type == "tllogic") {
117  type = "tlLogic"; // see GUIGlObject.cpp
118  } else if (type == "busstop" || type == "trainstop") {
119  type = "busStop";
120  } else if (type == "containerstop") {
121  type = "containerStop";
122  } else if (type == "chargingstation") {
123  type = "chargingStation";
124  } else if (type == "overheadwiresegment") {
125  type = "overheadWireSegment";
126  } else if (type == "parkingarea") {
127  type = "parkingArea";
128  }
129  const std::string id(text.mid(idS + 2, idE - idS - 2).text());
130  return GUIGlObjectStorage::gIDStorage.getObjectBlocking(type + ":" + id);
131  }
132  }
133  return nullptr;
134 }
135 
136 
137 void
138 GUIMessageWindow::setCursorPos(FXint pos, FXbool notify) {
139  FXText::setCursorPos(pos, notify);
140  if (myLocateLinks) {
142  std::vector<std::string> viewIDs = main->getViewIDs();
143  if (viewIDs.empty()) {
144  return;
145  }
146  GUIGlChildWindow* const child = main->getViewByID(viewIDs[0]);
147  const FXString text = getText();
148  const GUIGlObject* const glObj = getActiveStringObject(text, pos, lineStart(pos), lineEnd(pos));
149  if (glObj != nullptr) {
150  child->setView(glObj->getGlID());
152  if (getApp()->getKeyState(KEY_Control_L)) {
154  }
155  }
156  }
157 }
158 
159 
160 void
161 GUIMessageWindow::appendMsg(GUIEventType eType, const std::string& msg) {
162  if (!isEnabled()) {
163  show();
164  }
165  // build the styled message
166  FXint style = 1;
167  switch (eType) {
169  // color: blue
170  style = 0;
171  break;
173  // color: fuchsia
174  style = 7;
175  break;
177  // color: red
178  style = 2;
179  break;
181  // color: yellow
182  style = 3;
183  break;
185  // color: green
186  style = 1;
187  break;
188  default:
189  assert(false);
190  }
191  FXString text(msg.c_str());
192  if (myLocateLinks) {
193  FXint pos = text.find("'");
194  while (pos >= 0) {
195  const GUIGlObject* const glObj = getActiveStringObject(text, pos + 1, 0, text.length());
196  if (glObj != nullptr) {
198  FXString insText = text.left(pos + 1);
199  FXText::appendStyledText(insText, style + 1);
200  text.erase(0, pos + 1);
201  pos = text.find("'");
202  insText = text.left(pos);
203  FXText::appendStyledText(insText, style + 4);
204  text.erase(0, pos);
205  }
206  pos = text.find("'", pos + 1);
207  }
208  }
209  // insert rest of the message
210  FXText::appendStyledText(text, style + 1, true);
211  FXText::setCursorPos(getLength() - 1);
212  FXText::setBottomLine(getLength() - 1);
213  if (isEnabled()) {
214  layout();
215  update();
216  }
217 }
218 
219 
220 void
222  std::string msg = "----------------------------------------------------------------------------------------\n";
223  FXText::appendStyledText(msg.c_str(), (FXint) msg.length(), 1, true);
224  FXText::setCursorPos(getLength() - 1);
225  FXText::setBottomLine(getLength() - 1);
226  if (isEnabled()) {
227  layout();
228  update();
229  }
230 }
231 
232 
233 void
235  if (getLength() == 0) {
236  return;
237  }
238  FXText::removeText(0, getLength() - 1, true);
239  if (isEnabled()) {
240  layout();
241  update();
242  }
243 }
244 
245 
246 void
248  if (myMessageRetriever == nullptr) {
249  // initialize only if registration is requested
255  }
261 }
262 
263 
264 void
271 }
272 
273 
274 /****************************************************************************/
GUIEventType
Definition: GUIEvent.h:32
@ EVENT_GLDEBUG_OCCURRED
send when a gldebug occured
Definition: GUIEvent.h:52
@ EVENT_ERROR_OCCURRED
send when a error occured
Definition: GUIEvent.h:46
@ EVENT_DEBUG_OCCURRED
send when a debug occured
Definition: GUIEvent.h:49
@ EVENT_MESSAGE_OCCURRED
send when a message occured
Definition: GUIEvent.h:40
@ EVENT_WARNING_OCCURRED
send when a warning occured
Definition: GUIEvent.h:43
GUISelectedStorage gSelected
A global holder of selected objects.
T MAX2(T a, T b)
Definition: StdDefs.h:79
int main(int argc, char *argv[])
void setView(GUIGlID id)
Centers the view onto the given artifact.
GUIGlID getGlID() const
Returns the numerical id of the object.
void unblockObject(GUIGlID id)
Marks an object as unblocked.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
static GUIMainWindow * getInstance()
get instance
OutputDevice * myGLDebugRetriever
void addSeparator()
Adds a a separator to this log window.
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations.
void unregisterMsgHandlers()
unregister message handlers
void clear()
Clears the window.
GUIMessageWindow(FXComposite *parent)
Constructor.
static bool myLocateLinks
whether messages are linked to the GUI elements
FXHiliteStyle * myStyles
The text colors used.
void appendMsg(GUIEventType eType, const std::string &msg)
Adds new text to the window.
virtual void setCursorPos(FXint pos, FXbool notify=FALSE)
set cursor position over a certain line
OutputDevice * myWarningRetriever
OutputDevice * myMessageRetriever
OutputDevice * myDebugRetriever
~GUIMessageWindow()
Destructor.
const GUIGlObject * getActiveStringObject(const FXString &text, const FXint pos, const FXint lineS, const FXint lineE) const
get active string object
void registerMsgHandlers()
register message handlers
void toggleSelection(GUIGlID id)
Toggles selection of an object.
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:175
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
Definition: MsgHandler.cpp:98
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
Definition: MsgHandler.cpp:89
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:183
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:54