SUMO - Simulation of Urban MObility
GUIMessageWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A logging window for the gui
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2003-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <cassert>
38 #include "GUIMessageWindow.h"
39 
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 GUIMessageWindow::GUIMessageWindow(FXComposite* parent) :
51  FXText(parent, 0, 0, 0, 0, 0, 0, 50),
52  myStyles(new FXHiliteStyle[7]),
53  myErrorRetriever(0),
54  myMessageRetriever(0),
55  myWarningRetriever(0) {
56  setStyled(true);
57  setEditable(false);
58  const FXColor white = FXRGB(0xff, 0xff, 0xff);
59  const FXColor blue = FXRGB(0x00, 0x00, 0x88);
60  const FXColor green = FXRGB(0x00, 0x88, 0x00);
61  const FXColor red = FXRGB(0x88, 0x00, 0x00);
62  const FXColor yellow = FXRGB(0xe6, 0x98, 0x00);
63  // set separator style
64  myStyles[0].normalForeColor = blue;
65  myStyles[0].normalBackColor = white;
66  myStyles[0].selectForeColor = white;
67  myStyles[0].selectBackColor = blue;
68  myStyles[0].hiliteForeColor = blue;
69  myStyles[0].hiliteBackColor = white;
70  myStyles[0].activeBackColor = white;
71  myStyles[0].style = 0;
72  // set message text style
73  myStyles[1] = myStyles[0];
74  myStyles[1].normalForeColor = green;
75  myStyles[1].selectBackColor = green;
76  myStyles[1].hiliteForeColor = green;
77  myStyles[4] = myStyles[1];
78  myStyles[4].style = STYLE_UNDERLINE;
79  // set error text style
80  myStyles[2] = myStyles[0];
81  myStyles[2].normalForeColor = red;
82  myStyles[2].selectBackColor = red;
83  myStyles[2].hiliteForeColor = red;
84  myStyles[5] = myStyles[2];
85  myStyles[5].style = STYLE_UNDERLINE;
86  // set warning text style
87  myStyles[3] = myStyles[0];
88  myStyles[3].normalForeColor = yellow;
89  myStyles[3].selectBackColor = yellow;
90  myStyles[3].hiliteForeColor = yellow;
91  myStyles[6] = myStyles[3];
92  myStyles[6].style = STYLE_UNDERLINE;
93  //
94  setHiliteStyles(myStyles);
95 }
96 
97 
99  delete[] myStyles;
100  delete myMessageRetriever;
101  delete myErrorRetriever;
102  delete myWarningRetriever;
103 }
104 
105 
106 const GUIGlObject*
107 GUIMessageWindow::getActiveStringObject(const FXString& text, const FXint pos, const FXint lineS, const FXint lineE) const {
108  const FXint idS = MAX2(text.rfind(" '", pos), text.rfind("='", pos));
109  const FXint idE = text.find("'", pos);
110  if (idS >= 0 && idE >= 0 && idS >= lineS && idE <= lineE) {
111  const FXint typeS = text.rfind(" ", idS - 1);
112  if (typeS >= 0) {
113  std::string type(text.mid(typeS + 1, idS - typeS - 1).lower().text());
114  if (type == "tllogic") {
115  type = "tlLogic"; // see GUIGlObject.cpp
116  }
117  const std::string id(text.mid(idS + 2, idE - idS - 2).text());
118  return GUIGlObjectStorage::gIDStorage.getObjectBlocking(type + ":" + id);
119  }
120  }
121  return 0;
122 }
123 
124 
125 void
126 GUIMessageWindow::setCursorPos(FXint pos, FXbool notify) {
127  FXText::setCursorPos(pos, notify);
128  if (myLocateLinks) {
130  std::vector<std::string> viewIDs = main->getViewIDs();
131  if (viewIDs.empty()) {
132  return;
133  }
134  GUIGlChildWindow* const child = dynamic_cast<GUIGlChildWindow*>(main->getViewByID(viewIDs[0]));
135  const FXString text = getText();
136  const GUIGlObject* const glObj = getActiveStringObject(text, pos, lineStart(pos), lineEnd(pos));
137  if (glObj != 0) {
138  child->setView(glObj->getGlID());
140  }
141  }
142 }
143 
144 
145 void
146 GUIMessageWindow::appendMsg(GUIEventType eType, const std::string& msg) {
147  if (!isEnabled()) {
148  show();
149  }
150  // build the styled message
151  FXint style = 1;
152  switch (eType) {
153  case EVENT_ERROR_OCCURED:
154  // color: red
155  style = 2;
156  break;
158  // color: yellow
159  style = 3;
160  break;
162  // color: green
163  style = 1;
164  break;
165  default:
166  assert(false);
167  }
168  FXString text(msg.c_str());
169  if (myLocateLinks) {
170  FXint pos = text.find("'");
171  while (pos >= 0) {
172  const GUIGlObject* const glObj = getActiveStringObject(text, pos + 1, 0, text.length());
173  if (glObj != 0) {
175  FXString insText = text.left(pos + 1);
176  FXText::appendStyledText(insText, style + 1);
177  text.erase(0, pos + 1);
178  pos = text.find("'");
179  insText = text.left(pos);
180  FXText::appendStyledText(insText, style + 4);
181  text.erase(0, pos);
182  }
183  pos = text.find("'", pos + 1);
184  }
185  }
186  // insert rest of the message
187  FXText::appendStyledText(text, style + 1, true);
188  FXText::setCursorPos(getLength() - 1);
189  FXText::setBottomLine(getLength() - 1);
190  if (isEnabled()) {
191  layout();
192  update();
193  }
194 }
195 
196 
197 void
199  std::string msg = "----------------------------------------------------------------------------------------\n";
200  FXText::appendStyledText(msg.c_str(), (FXint) msg.length(), 1, true);
201  FXText::setCursorPos(getLength() - 1);
202  FXText::setBottomLine(getLength() - 1);
203  if (isEnabled()) {
204  layout();
205  update();
206  }
207 }
208 
209 
210 void
212  if (getLength() == 0) {
213  return;
214  }
215  FXText::removeText(0, getLength() - 1, true);
216  if (isEnabled()) {
217  layout();
218  update();
219  }
220 }
221 
222 
223 void
225  if (myMessageRetriever == 0) {
226  // initialize only if registration is requested
230  }
234 }
235 
236 
237 void
242 }
243 
244 
245 /****************************************************************************/
246 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
void appendMsg(GUIEventType eType, const std::string &msg)
Adds new text to the window.
send when a message occured
Definition: GUIEvent.h:50
void registerMsgHandlers()
register and unregister message handlers
T MAX2(T a, T b)
Definition: StdDefs.h:70
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:157
~GUIMessageWindow()
Destructor.
std::vector< std::string > getViewIDs() const
void addSeparator()
Adds a a separator to this log window.
FXHiliteStyle * myStyles
The text colors used.
virtual void setCursorPos(FXint pos, FXbool notify=FALSE)
static GUIMainWindow * getInstance()
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:171
GUIMessageWindow(FXComposite *parent)
Constructor.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:58
send when a error occured
Definition: GUIEvent.h:56
GUIEventType
Definition: GUIEvent.h:42
OutputDevice * myMessageRetriever
void setView(GUIGlID id)
Centers the view onto the given artifact.
FXMDIChild * getViewByID(const std::string &id) const
static bool myLocateLinks
whether messages are linked to the GUI elements
send when a warning occured
Definition: GUIEvent.h:53
GUIGlID getGlID() const
Returns the numerical id of the object.
const GUIGlObject * getActiveStringObject(const FXString &text, const FXint pos, const FXint lineS, const FXint lineE) const
void unblockObject(GUIGlID id)
Marks an object as unblocked.
void clear()
Clears the window.
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations.
OutputDevice * myWarningRetriever
int main(int argc, char *argv[])