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-2016 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 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // static members
47 // ===========================================================================
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 GUIMessageWindow::GUIMessageWindow(FXComposite* parent) :
55  FXText(parent, 0, 0, 0, 0, 0, 0, 50),
56  myStyles(new FXHiliteStyle[7]),
57  myErrorRetriever(0),
58  myMessageRetriever(0),
59  myWarningRetriever(0) {
60  setStyled(true);
61  setEditable(false);
62  const FXColor white = FXRGB(0xff, 0xff, 0xff);
63  const FXColor blue = FXRGB(0x00, 0x00, 0x88);
64  const FXColor green = FXRGB(0x00, 0x88, 0x00);
65  const FXColor red = FXRGB(0x88, 0x00, 0x00);
66  const FXColor yellow = FXRGB(0xe6, 0x98, 0x00);
67  // set separator style
68  myStyles[0].normalForeColor = blue;
69  myStyles[0].normalBackColor = white;
70  myStyles[0].selectForeColor = white;
71  myStyles[0].selectBackColor = blue;
72  myStyles[0].hiliteForeColor = blue;
73  myStyles[0].hiliteBackColor = white;
74  myStyles[0].activeBackColor = white;
75  myStyles[0].style = 0;
76  // set message text style
77  myStyles[1] = myStyles[0];
78  myStyles[1].normalForeColor = green;
79  myStyles[1].selectBackColor = green;
80  myStyles[1].hiliteForeColor = green;
81  myStyles[4] = myStyles[1];
82  myStyles[4].style = STYLE_UNDERLINE;
83  // set error text style
84  myStyles[2] = myStyles[0];
85  myStyles[2].normalForeColor = red;
86  myStyles[2].selectBackColor = red;
87  myStyles[2].hiliteForeColor = red;
88  myStyles[5] = myStyles[2];
89  myStyles[5].style = STYLE_UNDERLINE;
90  // set warning text style
91  myStyles[3] = myStyles[0];
92  myStyles[3].normalForeColor = yellow;
93  myStyles[3].selectBackColor = yellow;
94  myStyles[3].hiliteForeColor = yellow;
95  myStyles[6] = myStyles[3];
96  myStyles[6].style = STYLE_UNDERLINE;
97  //
98  setHiliteStyles(myStyles);
99 }
100 
101 
103  delete[] myStyles;
104  delete myMessageRetriever;
105  delete myErrorRetriever;
106  delete myWarningRetriever;
107 }
108 
109 
110 const GUIGlObject*
111 GUIMessageWindow::getActiveStringObject(const FXString& text, const FXint pos, const FXint lineS, const FXint lineE) const {
112  const FXint idS = MAX2(text.rfind(" '", pos), text.rfind("='", pos));
113  const FXint idE = text.find("'", pos);
114  if (idS >= 0 && idE >= 0 && idS >= lineS && idE <= lineE) {
115  const FXint typeS = text.rfind(" ", idS - 1);
116  if (typeS >= 0) {
117  std::string type(text.mid(typeS + 1, idS - typeS - 1).lower().text());
118  if (type == "tllogic") {
119  type = "tlLogic"; // see GUIGlObject.cpp
120  }
121  const std::string id(text.mid(idS + 2, idE - idS - 2).text());
122  return GUIGlObjectStorage::gIDStorage.getObjectBlocking(type + ":" + id);
123  }
124  }
125  return 0;
126 }
127 
128 
129 void
130 GUIMessageWindow::setCursorPos(FXint pos, FXbool notify) {
131  FXText::setCursorPos(pos, notify);
132  if (myLocateLinks) {
134  std::vector<std::string> viewIDs = main->getViewIDs();
135  if (viewIDs.empty()) {
136  return;
137  }
138  GUIGlChildWindow* const child = dynamic_cast<GUIGlChildWindow*>(main->getViewByID(viewIDs[0]));
139  const FXString text = getText();
140  const GUIGlObject* const glObj = getActiveStringObject(text, pos, lineStart(pos), lineEnd(pos));
141  if (glObj != 0) {
142  child->setView(glObj->getGlID());
144  }
145  }
146 }
147 
148 
149 void
150 GUIMessageWindow::appendMsg(GUIEventType eType, const std::string& msg) {
151  if (!isEnabled()) {
152  show();
153  }
154  // build the styled message
155  FXint style = 1;
156  switch (eType) {
157  case EVENT_ERROR_OCCURED:
158  // color: red
159  style = 2;
160  break;
162  // color: yellow
163  style = 3;
164  break;
166  // color: green
167  style = 1;
168  break;
169  default:
170  assert(false);
171  }
172  FXString text(msg.c_str());
173  if (myLocateLinks) {
174  FXint pos = text.find("'");
175  while (pos >= 0) {
176  const GUIGlObject* const glObj = getActiveStringObject(text, pos + 1, 0, text.length());
177  if (glObj != 0) {
179  FXString insText = text.left(pos + 1);
180  FXText::appendStyledText(insText, style + 1);
181  text.erase(0, pos + 1);
182  pos = text.find("'");
183  insText = text.left(pos);
184  FXText::appendStyledText(insText, style + 4);
185  text.erase(0, pos);
186  }
187  pos = text.find("'", pos + 1);
188  }
189  }
190  // insert rest of the message
191  FXText::appendStyledText(text, style + 1, true);
192  FXText::setCursorPos(getLength() - 1);
193  FXText::setBottomLine(getLength() - 1);
194  if (isEnabled()) {
195  layout();
196  update();
197  }
198 }
199 
200 
201 void
203  std::string msg = "----------------------------------------------------------------------------------------\n";
204  FXText::appendStyledText(msg.c_str(), (FXint) msg.length(), 1, true);
205  FXText::setCursorPos(getLength() - 1);
206  FXText::setBottomLine(getLength() - 1);
207  if (isEnabled()) {
208  layout();
209  update();
210  }
211 }
212 
213 
214 void
216  if (getLength() == 0) {
217  return;
218  }
219  FXText::removeText(0, getLength() - 1, true);
220  if (isEnabled()) {
221  layout();
222  update();
223  }
224 }
225 
226 
227 void
229  if (myMessageRetriever == 0) {
230  // initialize only if registration is requested
234  }
238 }
239 
240 
241 void
246 }
247 
248 
249 /****************************************************************************/
250 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:71
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
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:75
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:161
~GUIMessageWindow()
Destructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
void addSeparator()
Adds a a separator to this log window.
FXMDIChild * getViewByID(const std::string &id) const
#define new
Definition: debug_new.h:121
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:175
GUIMessageWindow(FXComposite *parent)
Constructor.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:62
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.
static bool myLocateLinks
whether messages are linked to the GUI elements
const GUIGlObject * getActiveStringObject(const FXString &text, const FXint pos, const FXint lineS, const FXint lineE) const
send when a warning occured
Definition: GUIEvent.h:53
void unblockObject(GUIGlID id)
Marks an object as unblocked.
void clear()
Clears the window.
std::vector< std::string > getViewIDs() const
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[])