root/simulator/trunk/src/utilities/console/consoleframe.cpp

Revision 1472, 13.9 kB (checked in by sehenley, 6 months ago)

Save work on TestPathGenerator? 1.2.3.1, Console Graphics tab.

  • Property svn:keywords set to
    Url
    Rev
    Author
    Date
    Id
Line 
1 //    OSRail -- a network enabled railroad operations simulator and utilities
2 //    Copyright (C) 2007,2008,2009 Samuel E. Henley sehenley@comcast.net
3 //
4 //    This program is free software; you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation; either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    This program is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License along
15 //    with this program; if not, write to the Free Software Foundation, Inc.,
16 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 //
18 //
19 #include "preconsole.h"
20 #include "console.h"
21
22 #include "consoleframe.h"
23 #include "assertslistctrl.h"
24 #include "assertspanel.h"
25 #include "profilepanel.h"
26 #include "unittestlistctrl.h"
27 #include "unittestpanel.h"
28 #include "dumpsscrolledwindow.h"
29 #include "dumpspanel.h"
30 #include "tweakerlistctrl.h"
31 #include "tweakerpanel.h"
32
33 #include <typeinfo>
34
35 /// \addtogroup utilities "Utilities"
36 /// @{
37     /// \addtogroup consoleserver "Console Server"
38     /// @{
39
40 IMPLEMENT_DYNAMIC_CLASS( ConsoleFrame, wxFrame )
41
42 BEGIN_EVENT_TABLE(ConsoleFrame, wxFrame)
43     EVT_MENU( XRCID("about_menu_item"), ConsoleFrame::OnAbout )
44     EVT_MENU( XRCID("fullscreen_menu_item"), ConsoleFrame::OnFullScreen )
45     EVT_MENU( XRCID("exit_menu_item"), ConsoleFrame::OnQuit )
46     EVT_MENU( XRCID("close_all_menu_item"), ConsoleFrame::OnCloseAll )
47     EVT_IDLE(ConsoleFrame::idleTime)
48     EVT_TIMER(wxID_ANY, ConsoleFrame::OnTimer)
49 END_EVENT_TABLE()
50
51 //static ipc::Provider<ipc::ConsoleIPCCommand> toConsoleClient( "Console Output", ipc::ConsoleIPCBufferSize );
52 //static ipc::Consumer<ipc::ConsoleIPCCommand> fromConsoleClient( "Console Input", ipc::ConsoleIPCBufferSize );
53
54 ConsoleFrame::ConsoleFrame()
55     : wxFrame( NULL, wxID_ANY,  _("Console")  ), notebook(0), timer( this, wxID_ANY )
56 {
57     //File menu
58     wxMenuBar* bar = wxXmlResource::Get()->LoadMenuBar( wxT("main_menu_bar"));
59     SetMenuBar( bar );
60
61     //Status bar
62     CreateStatusBar(2);
63     int widths[] = { -1, 100 };
64     SetStatusWidths( 2, widths );
65
66     //Notebooks
67     notebook = new wxNotebook( this,
68                                wxID_ANY,
69                                wxDefaultPosition,
70                                wxDefaultSize );
71
72     SetClientSize( 800, 600 );
73
74     timer.Start( ConsoleTimerConstant );
75
76 }
77
78 void ConsoleFrame::initializeFrame()
79 {
80     //File menu
81     wxMenuBar* bar = wxXmlResource::Get()->LoadMenuBar( wxT("main_menu_bar"));
82     SetMenuBar( bar );
83
84     //Status bar
85     CreateStatusBar(2);
86     int widths[] = { -1, 100 };
87     SetStatusWidths( 2, widths );
88
89     //Notebooks
90     notebook = new wxNotebook( this,
91                                wxID_ANY,
92                                wxDefaultPosition,
93                                wxDefaultSize );
94
95     SetClientSize( 800, 600 );
96
97     timer.Start( ConsoleTimerConstant );
98 }
99
100 void ConsoleFrame::OnAbout( wxCommandEvent& event )
101 {
102     wxDialog dlg;
103     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("about_dialog"));
104     dlg.ShowModal();
105 }
106
107 void ConsoleFrame::OnQuit( wxCommandEvent& event )
108 {
109     Close( true );
110 }
111
112 void ConsoleFrame::OnFullScreen( wxCommandEvent& event )
113 {
114     ShowFullScreen( !IsFullScreen(), wxFULLSCREEN_NOBORDER|wxFULLSCREEN_NOCAPTION );
115 }
116
117 void ConsoleFrame::OnCloseAll( wxCommandEvent& event )
118 {
119     wxGetApp().closeFrames();
120 }
121
122
123 void ConsoleFrame::OnClose( wxCommandEvent& event )
124 {
125     Close( true );
126 }
127
128 //virtual
129 bool ConsoleFrame::Destroy()
130 {
131     /// \note Call the application and remove myself
132     /// from the frame list (frames)
133     wxGetApp().destroyFrame( this );
134     return wxWindow::Destroy();
135 }
136
137 //private
138 bool ConsoleFrame::checkMessages()
139 {
140     return readNextFromClient();
141 }
142
143 // private
144 void ConsoleFrame::OnTimer( wxTimerEvent& event )
145 {
146     //checkMessages();
147 }
148
149 // public
150 void ConsoleFrame::idleTime( wxIdleEvent& event )
151 {
152     if( checkMessages() )event.RequestMore();
153 }
154
155 bool ConsoleFrame::readNextFromClient()
156 {
157     try
158     {
159         std::vector<ipc::AssertRecordImpl> new_asserts;
160         ipc::getNewAsserts( new_asserts, true );
161         if( !new_asserts.empty() )
162         {
163             for( size_t j=0; j<new_asserts.size(); ++j )
164             {
165                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( new_asserts[j].program ));  //side effect build new program frame.
166
167                 AssertsPanel* p = dynamic_cast<AssertsPanel*>( pframe->message_pages[new_asserts[j].page] );
168                 if( !p )
169                 {
170                      p = dynamic_cast<AssertsPanel*>( wxCreateDynamicObject( wxT("AssertsPanel") ));
171                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("asserts_page") );
172                      p->initialize();
173                      pframe->notebook->AddPage( p, new_asserts[j].page, false );
174                      pframe->message_pages[new_asserts[j].page] = p;
175                 }
176
177                 p->addAsserts( new_asserts[j] );
178                 pframe->Refresh();
179             }
180
181         }
182
183         //Profiles
184         std::vector<ipc::ProfileRecordImpl> profiles;
185         ipc::getProfiles( profiles, true );
186         if( !profiles.empty() )
187         {
188             for( size_t j=0; j<profiles.size(); ++j )
189             {
190                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( profiles[j].program ));  //side effect build new program frame.
191
192                 ProfilePanel* p = dynamic_cast<ProfilePanel*>( pframe->profile_pages[profiles[j].page] );
193                 if( !p )
194                 {
195                      p = dynamic_cast<ProfilePanel*>( wxCreateDynamicObject( wxT("ProfilePanel") ));
196                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("profile_page") );
197                      p->initialize();
198                      pframe->notebook->AddPage( p, profiles[j].page, false );
199                      pframe->profile_pages[profiles[j].page] = p;
200                 }
201
202                 p->addProfile( profiles[j] );
203                 pframe->Refresh();
204             }
205
206         }
207
208         //Messages
209         std::vector<ipc::MessageRecordImpl> messages;
210         ipc::getMessages( messages, true );
211         if( !messages.empty() )
212         {
213             for( size_t j=0; j<messages.size(); ++j )
214             {
215                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( messages[j].program ));  //side effect build new program frame.
216
217                 AssertsPanel* p = dynamic_cast<AssertsPanel*>( pframe->message_pages[messages[j].page] );
218                 if( !p )
219                 {
220                      p = dynamic_cast<AssertsPanel*>( wxCreateDynamicObject( wxT("AssertsPanel") ));
221                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("asserts_page") );
222                      p->initialize();
223                      pframe->notebook->AddPage( p, messages[j].page, false );
224                      pframe->message_pages[messages[j].page] = p;
225                 }
226
227                 p->addMessage( messages[j] );
228                 pframe->Refresh();
229             }
230
231         }
232
233         //Exceptions
234         ipc::getExceptions( messages, true );
235         if( !messages.empty() )
236         {
237             for( size_t j=0; j<messages.size(); ++j )
238             {
239                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( messages[j].program ));  //side effect build new program frame.
240
241                 AssertsPanel* p = dynamic_cast<AssertsPanel*>( pframe->message_pages[messages[j].page] );
242                 if( !p )
243                 {
244                      p = dynamic_cast<AssertsPanel*>( wxCreateDynamicObject( wxT("AssertsPanel") ));
245                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("asserts_page") );
246                      p->initialize();
247                      pframe->notebook->AddPage( p, messages[j].page, false );
248                      pframe->message_pages[messages[j].page] = p;
249                 }
250
251                 p->addException( messages[j] );
252                 pframe->Refresh();
253             }
254
255         }
256
257         //Dumps
258         ipc::getDumps( messages, true );
259         if( !messages.empty() )
260         {
261             for( size_t j=0; j<messages.size(); ++j )
262             {
263                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( messages[j].program ));  //side effect build new program frame.
264
265                 DumpsPanel* p = dynamic_cast<DumpsPanel*>( pframe->dump_pages[messages[j].page] );
266                 if( !p )
267                 {
268                      p = dynamic_cast<DumpsPanel*>( wxCreateDynamicObject( wxT("DumpsPanel") ));
269                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("dumps_page") );
270                      p->initialize();
271                      pframe->notebook->AddPage( p, messages[j].page, false );
272                      pframe->dump_pages[messages[j].page] = p;
273                 }
274
275                 p->addDump( messages[j] );
276                 pframe->Refresh();
277             }
278
279         }
280
281         //UnitTest
282         std::vector<ipc::UnitTestRecordImpl> unittests;
283         ipc::getUnitTests( unittests, true );
284         if( !unittests.empty() )
285         {
286             for( size_t j=0; j<unittests.size(); ++j )
287             {
288                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( unittests[j].program ));  //side effect build new program frame.
289
290                 UnitTestPanel* p = dynamic_cast<UnitTestPanel*>( pframe->unittest_pages[unittests[j].suite] );
291                 if( !p )
292                 {
293                      p = dynamic_cast<UnitTestPanel*>( wxCreateDynamicObject( wxT("UnitTestPanel") ));
294                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("unittest_page") );
295                      p->initialize();
296                      pframe->notebook->AddPage( p, unittests[j].suite, false );
297                      pframe->unittest_pages[unittests[j].suite] = p;
298                 }
299
300                 p->addUnitTest( unittests[j] );
301                 pframe->Refresh();
302             }
303
304         }
305
306         std::vector<ipc::TweakerRecordImpl> new_tweakers;
307         ipc::getNewTweakers( new_tweakers, true );
308         if( !new_tweakers.empty() )
309         {
310             for( size_t j=0; j<new_tweakers.size(); ++j )
311             {
312                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( new_tweakers[j].program ));  //side effect build new program frame.
313
314                 TweakerPanel* p = dynamic_cast<TweakerPanel*>( pframe->message_pages[new_tweakers[j].page] );
315                 if( !p )
316                 {
317                      p = dynamic_cast<TweakerPanel*>( wxCreateDynamicObject( wxT("TweakerPanel") ));
318                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("tweaker_page") );
319                      p->initialize();
320                      pframe->notebook->AddPage( p, new_tweakers[j].page, false );
321                      pframe->message_pages[new_tweakers[j].page] = p;
322                 }
323
324                 p->addTweaker( new_tweakers[j] );
325                 pframe->Refresh();
326             }
327
328         }
329
330         //Graphics
331         std::vector<ipc::GraphicsRecordImpl> graphics;
332         ipc::getGraphics( graphics, true );
333         if( !graphics.empty() )
334         {
335             for( size_t j=0; j<graphics.size(); ++j )
336             {
337                 ConsoleFrame* pframe = static_cast<ConsoleFrame*>( wxGetApp().getProgramFrame( graphics[j].program ));  //side effect build new program frame.
338
339                 AssertsPanel* p = dynamic_cast<AssertsPanel*>( pframe->message_pages[graphics[j].page] );
340                 if( !p )
341                 {
342                      p = dynamic_cast<AssertsPanel*>( wxCreateDynamicObject( wxT("AssertsPanel") ));
343                      wxXmlResource::Get()->LoadPanel( dynamic_cast<wxPanel*>(p), pframe->notebook, wxT("asserts_page") );
344                      p->initialize();
345                      pframe->notebook->AddPage( p, graphics[j].page, false );
346                      pframe->message_pages[graphics[j].page] = p;
347                 }
348
349                 p->addGraphics( graphics[j] );
350                 pframe->Refresh();
351             }
352
353         }
354
355         return false;
356
357     }
358     catch( ipc::IpcExceptionBase& e )
359     {
360         char buf[20];
361         std::string data = "IPC Exception: ";
362         data += e.file;
363         data += ' ';
364         data += ipc::itoa(e.line, buf, 10 );
365         data += ' ';
366         data += e.what();
367         data += ", Class: ";
368         std::string class_name = typeid( e ).name();
369         data += class_name;
370         std::cerr << data.c_str() << std::endl;
371         int error_number = 19L; //unknown_ipoc_exception
372         int index = class_name.find( "IpcException" );
373         if( index != std::string::npos )
374         {
375             error_number = 0;
376             index++;
377             while( index < class_name.length() )
378             {
379                 if( class_name[index] >= '0' && class_name[index] <= '9' )
380                 {
381                     error_number *= 10;
382                     error_number += class_name[index] - '0';
383                 }
384                 index++;
385             }
386         }
387     }
388     catch( std::exception &e )
389     {
390         std::string data = "STL Exception: ";
391         data += e.what();
392         data += ", Class: ";
393         data += typeid( e ).name();
394         EXCEPTION( "Console", "Console", data.c_str() );
395     }
396     catch( ... )
397     {
398         std::string data = "Unknown Exception";
399         EXCEPTION( "Console", "Console", data.c_str() );
400     }
401
402     //purge the record some sort of problem
403
404     return false; //leave it in the buffer
405 }
406
407
408
409     /// @}   group consoleserver
410 /// @}   group utilities
Note: See TracBrowser for help on using the browser.