VRUT::MainWindow Class Reference

Main window class. More...

#include <mainwindow.h>

List of all members.

Public Member Functions

 MainWindow (const wxString &title, const wxPoint &pos, const wxSize &size)
 Class constructor.
virtual ~MainWindow ()
 Class destructor.
void FixLoglevelMenu (int logLevel)
wxAuiManager * GetAUIManager ()
 Get window's AUI manager.
wxAuiNotebook * GetRenderNotebook ()
 Get notebook with render windows.

Protected Member Functions

 MainWindow ()
 Class constructor.
void onFileMenu (wxCommandEvent &evt)
 On file menu event.
void onViewMenu (wxCommandEvent &evt)
 On view menu event.
void onLogMenu (wxCommandEvent &evt)
 On log level change event.
void onCommandEvent (wxCommandEvent &evt)
 Process other wxCommandEvent event.
void onClose (wxCloseEvent &evt)
 On window close event method.
void onPaneClose (wxAuiManagerEvent &evt)
 On pane close event method.

Protected Attributes

wxAuiManager auiMgr
 AUI manager.
wxAuiNotebook * renderNotebook
 Notebook for render windows.


Detailed Description

Main window class.

Definition at line 23 of file mainwindow.h.


Constructor & Destructor Documentation

MainWindow::MainWindow (  )  [protected]

Class constructor.

Definition at line 29 of file mainwindow.cpp.

00029                        : wxFrame(), renderNotebook((wxAuiNotebook *)NULL)
00030 {
00031 }

MainWindow::MainWindow ( const wxString &  title,
const wxPoint &  pos,
const wxSize &  size 
)

Class constructor.

File menu

Log menu

View menu

Menu bar

Status bar

Log window

Console

Notebook for render windows

Connect event handler

Definition at line 34 of file mainwindow.cpp.

00035               : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
00036 {
00037        if (wxFileName::FileExists(ICON_MAIN_WINDOW))
00038               SetIcon(wxIcon(ICON_MAIN_WINDOW, wxBITMAP_TYPE_PNG));
00039        auiMgr.SetManagedWindow(this);
00040 
00042        wxMenu * menuFile = new wxMenu;
00043        menuFile->Append( ID_MainWin_About, wxT("&About"), wxT("About this application") );
00044        menuFile->AppendSeparator();
00045        menuFile->Append( ID_MainWin_Quit, wxT("E&xit"), wxT("Exit application") );
00047        wxMenu * logmenu = new wxMenu;
00048        wxMenu * loglvlMenu = new wxMenu;
00049        logmenu->AppendSubMenu( loglvlMenu, wxT("&Set level"), wxT("&Messages with lower priority than selected will not be logged") );
00050        loglvlMenu->AppendRadioItem( ID_MainWin_LogDisable, wxT("&Disable"), wxT("Stop logging") );
00051        loglvlMenu->AppendRadioItem( ID_MainWin_LogError, wxT("&Errors"), wxT("Log error messages only") );
00052        loglvlMenu->AppendRadioItem( ID_MainWin_LogWarning, wxT("&Warnings"), wxT("Log warnings and errors") );
00053        loglvlMenu->AppendRadioItem( ID_MainWin_LogMessage, wxT("&Messages"), wxT("Log standard messages and higher priority messages") );
00054        loglvlMenu->AppendRadioItem( ID_MainWin_LogAll, wxT("&All"), wxT("Log all messages") )->Check();
00056        wxMenu * viewMenu = new wxMenu;
00057        viewMenu->AppendCheckItem( ID_MainWin_View_Console, wxT("Console"), wxT("Show/hide console") )->Check();
00058        viewMenu->AppendCheckItem( ID_MainWin_View_Log, wxT("Log"), wxT("Show/hide log window") )->Check();
00059        viewMenu->AppendCheckItem( ID_MainWin_View_Status, wxT("Status"), wxT("Show/hide status bar") )->Check();
00060        viewMenu->AppendCheckItem( ID_MainWin_View_RenderNotebook, wxT("Render"), wxT("Show/hide notebook with render windows") )->Check();
00061        viewMenu->AppendCheckItem( ID_MainWin_View_Parameters, wxT("Parameters"), wxT("Show/hide notebook with registered parameters") )->Check();
00063        wxMenuBar * menuBar = new wxMenuBar;
00064        menuBar->Append( menuFile, wxT("&File") );
00065        menuBar->Append( logmenu, wxT("&Logging") );
00066        menuBar->Append( viewMenu, wxT("&View") );
00067        SetMenuBar( menuBar );
00069        CreateStatusBar();
00071        long style = wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_AUTO_URL | wxTE_LEFT | wxTE_BESTWRAP | wxTE_NOHIDESEL;
00072        wxTextCtrl * txtCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, style);
00073        wxLog::SetActiveTarget(new FlexiLog(txtCtrl));
00074        auiMgr.AddPane(txtCtrl, wxAuiPaneInfo().
00075                       DefaultPane().Name(wxT("Log")).
00076                       Caption(wxT("Log")).Top().
00077                       PinButton().BestSize(GetSize().x, 260));
00079        Console* console = new Console(this);
00080        console->SetDropTarget(new DropTarget(false));
00081        auiMgr.AddPane(console, wxAuiPaneInfo().
00082                       DefaultPane().Name(wxT("Console")).
00083                       Caption(wxT("Console")).Bottom().
00084                       PinButton().BestSize(GetSize().x, 20));
00086        wxString nbName = wxT("Render");
00087        renderNotebook = new wxAuiNotebook(this,
00088                                     wxID_ANY,
00089                                     wxDefaultPosition,
00090                                     wxDefaultSize,
00091                                     wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_MOVE
00092                                     | wxAUI_NB_TAB_EXTERNAL_MOVE | wxAUI_NB_SCROLL_BUTTONS
00093                                     | wxAUI_NB_TOP | wxAUI_NB_CLOSE_ON_ALL_TABS);
00094        renderNotebook->SetName(nbName);
00095        auiMgr.AddPane(renderNotebook, wxAuiPaneInfo().
00096                       DefaultPane().Name(nbName).
00097                       Caption(nbName).Center().
00098                       PinButton().BestSize(640, 480));
00099        auiMgr.Update();
00100 
00101 
00103        Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MainWindow::onClose), (wxObject *)NULL, this);
00104 
00105        Connect(ID_MainWin_Quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onFileMenu), (wxObject *)NULL, this);
00106        Connect(ID_MainWin_About, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onFileMenu), (wxObject *)NULL, this);
00107        Connect(ID_MainWin_LogDisable, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onLogMenu), (wxObject *)NULL, this);
00108        Connect(ID_MainWin_LogError, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onLogMenu), (wxObject *)NULL, this);
00109        Connect(ID_MainWin_LogWarning, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onLogMenu), (wxObject *)NULL, this);
00110        Connect(ID_MainWin_LogMessage, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onLogMenu), (wxObject *)NULL, this);
00111        Connect(ID_MainWin_LogAll, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onLogMenu), (wxObject *)NULL, this);
00112        Connect(ID_MainWin_View_Console, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onViewMenu), (wxObject *)NULL, this);
00113        Connect(ID_MainWin_View_Log, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onViewMenu), (wxObject *)NULL, this);
00114        Connect(ID_MainWin_View_Status, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onViewMenu), (wxObject *)NULL, this);
00115        Connect(ID_MainWin_View_RenderNotebook, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onViewMenu), (wxObject *)NULL, this);
00116        Connect(ID_MainWin_View_Parameters, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::onViewMenu), (wxObject *)NULL, this);
00117        Connect(wxID_ANY, wxEVT_AUI_PANE_CLOSE, wxAuiManagerEventHandler(MainWindow::onPaneClose), (wxObject *)NULL, this);
00118 
00119        Connect(wxID_ANY, Event::EVT_LOG_LEVEL_SET, wxCommandEventHandler(MainWindow::onCommandEvent), (wxObject *)NULL, this);
00120        Connect(wxID_ANY, Event::EVT_RENDER_FRAMERATE, wxCommandEventHandler(MainWindow::onCommandEvent), (wxObject *)NULL, this);
00121        Connect(wxID_ANY, Event::EVT_GUI_PANE_SHOW, wxCommandEventHandler(MainWindow::onCommandEvent), (wxObject *)NULL, this);
00122 
00123        this->SetDropTarget(new DropTarget);
00124 }

MainWindow::~MainWindow (  )  [virtual]

Class destructor.

Definition at line 127 of file mainwindow.cpp.

00128 {
00129        FlexiLog::SetTextCtrlLogging(false);
00130        auiMgr.UnInit();
00131 }


Member Function Documentation

void MainWindow::onFileMenu ( wxCommandEvent &  evt  )  [protected]

On file menu event.

This prevents calling process idle in EventHandler

Definition at line 134 of file mainwindow.cpp.

00135 {
00136        switch (evt.GetId())
00137        {
00138        case ID_MainWin_Quit:
00139               {
00140                      wxMessageDialog * dial = new wxMessageDialog( this,
00141                              wxT("Really quit?"), wxT("Really quit?"),
00142                              wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
00143 
00144                      int ret = dial->ShowModal();
00145                      dial->Destroy();
00146 
00147                      if (ret == wxID_YES)
00148                      {
00150                             Disconnect(wxID_ANY, wxEVT_IDLE);
00151                             wxCommandEvent ev = Event::GET_EVT_EXIT();
00152                             KERNEL->GetMessageSink()->PostEvent(ev, true);
00153                      }
00154               }
00155               break;
00156        case ID_MainWin_About:
00157               wxMessageBox(wxT("VRUT v0.5"), wxT("About VRUT"), wxOK | wxICON_INFORMATION, this);
00158               break;
00159        default:
00160               break;
00161        }
00162 }

void MainWindow::onViewMenu ( wxCommandEvent &  evt  )  [protected]

On view menu event.

Definition at line 165 of file mainwindow.cpp.

00166 {
00167        switch (evt.GetId())
00168        {
00169        case ID_MainWin_View_Console:
00170        case ID_MainWin_View_Log:
00171        case ID_MainWin_View_Parameters:
00172               {
00173                      wxMenu * viewMenu = GetMenuBar()->GetMenu(2);
00174                      wxASSERT_MSG(viewMenu, wxT("Bad MainWindow menu structure"));
00175                      wxMenuItem * mitem = viewMenu->FindItem(evt.GetId());
00176                      if (mitem)
00177                      {
00178                             auiMgr.GetPane(mitem->GetText()).Show(evt.IsChecked());
00179                             mitem->Check(evt.IsChecked());
00180                      }
00181               }
00182               break;
00183        case ID_MainWin_View_RenderNotebook:
00184               {
00185                      wxMenu * viewMenu = GetMenuBar()->GetMenu(2);
00186                      wxASSERT_MSG(viewMenu, wxT("Bad MainWindow menu structure"));
00187                      wxMenuItem * mitem = viewMenu->FindItem(ID_MainWin_View_RenderNotebook);
00188                      if (mitem)
00189                      {
00190                             auiMgr.GetPane(mitem->GetText()).Show(evt.IsChecked());
00191                             mitem->Check(evt.IsChecked());
00192                      }
00193                      if (!evt.IsChecked())
00194                      {
00195                             while (renderNotebook && renderNotebook->GetPageCount())
00196                                    renderNotebook->DeletePage(0);
00197                      }
00198               }
00199               break;
00200        case ID_MainWin_View_Status:
00201               if (evt.IsChecked())
00202                      SetStatusBar(CreateStatusBar());
00203               else
00204                      SetStatusBar((wxStatusBar *)NULL);
00205               break;
00206        }
00207 
00208        auiMgr.Update();
00209 }

void MainWindow::onLogMenu ( wxCommandEvent &  evt  )  [protected]

On log level change event.

Definition at line 212 of file mainwindow.cpp.

00213 {
00214        wxLogLevel loglevel = wxLOG_Max;
00215        switch (evt.GetId())
00216        {
00217        case ID_MainWin_LogDisable:
00218               loglevel = wxLOG_FatalError;
00219               break;
00220        case ID_MainWin_LogError:
00221               loglevel = wxLOG_Error;
00222               break;
00223        case ID_MainWin_LogWarning:
00224               loglevel = wxLOG_Warning;
00225               break;
00226        case ID_MainWin_LogMessage:
00227               loglevel = wxLOG_Message;
00228               break;
00229        case ID_MainWin_LogAll:
00230               loglevel = wxLOG_Max;
00231               break;
00232        default:
00233               LOGWARNING(wxT("Unknown log level. Ignored."));
00234               break;
00235        }
00236        wxCommandEvent ev = Event::GET_EVT_LOG_LEVEL_SET(loglevel);
00237        KERNEL->GetMessageSink()->PostEvent(ev);
00238 }

void MainWindow::onCommandEvent ( wxCommandEvent &  evt  )  [protected]

Process other wxCommandEvent event.

Definition at line 241 of file mainwindow.cpp.

00242 {
00243        switch (evt.GetEventType())
00244        {
00245        case Event::EVT_LOG_LEVEL_SET:
00246               FixLoglevelMenu(evt.GetInt());
00247               break;
00248        case Event::EVT_RENDER_FRAMERATE:
00249               if (GetStatusBar())
00250                      SetStatusText(wxString::Format(wxT("Window %i rendered %.1f FPS"), evt.GetId(), 0.001f*evt.GetInt()));
00251               break;
00252        case Event::EVT_GUI_PANE_SHOW:
00253               {
00254                      wxCommandEvent menuEvt(wxEVT_COMMAND_MENU_SELECTED);
00255                      menuEvt.SetId(evt.GetId());
00256                      menuEvt.SetInt(evt.GetInt());
00257                      ProcessEvent(menuEvt);
00258               }
00259               break;
00260        }
00261 }

void MainWindow::onClose ( wxCloseEvent &  evt  )  [protected]

On window close event method.

Definition at line 264 of file mainwindow.cpp.

00265 {
00266        if (KERNEL && KERNEL->GetMessageSink())
00267               KERNEL->GetMessageSink()->UnregisterListener(this);
00268        SAFE_RELEASE(KERNEL);
00269        evt.Skip();
00270 }

void MainWindow::onPaneClose ( wxAuiManagerEvent &  evt  )  [protected]

On pane close event method.

Definition at line 273 of file mainwindow.cpp.

00274 {
00275        if (!evt.pane)
00276        {
00277               evt.Skip();
00278               return;
00279        }
00280 
00281        wxMenu * viewMenu = GetMenuBar()->GetMenu(2);
00282        wxASSERT_MSG(viewMenu, wxT("Bad MainWindow menu structure"));
00283        int menuID = viewMenu->FindItem(evt.pane->name);
00284        wxMenuItem * mitem = viewMenu->FindItem(menuID);
00285        if (mitem)
00286               mitem->Check(false);
00287        evt.Skip();
00288 
00289        if (evt.pane->name.IsSameAs(renderNotebook->GetName()))
00290        {
00291               bool close = true;
00292               if (renderNotebook->GetPageCount() > 1)
00293               {
00294                      wxMessageDialog * dial = new wxMessageDialog( this,
00295                              wxT("Really close all render windows?"),
00296                              wxT("Close render windows?"),
00297                              wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION );
00298                      close = ( dial->ShowModal() == wxID_YES );
00299                      dial->Destroy();
00300               }
00301               if (close)
00302               {
00303                      while (renderNotebook->GetPageCount())
00304                             renderNotebook->DeletePage(0);
00305               }
00306               else
00307                      evt.Veto();
00308        }
00309 }

void MainWindow::FixLoglevelMenu ( int  logLevel  ) 

Fix loglevel menu item Checks menu item according to current loglevel when changed in other way than menu selection

Update menu check if processed event was sent explicitly

Definition at line 312 of file mainwindow.cpp.

00313 {
00315        wxMenu * logMenu = GetMenuBar()->GetMenu(1);
00316        wxASSERT_MSG(logMenu, wxT("Bad MainWindow menu structure"));
00317        wxMenuItem * setLevelMenuItem = logMenu->FindItemByPosition(0);
00318        wxASSERT_MSG(setLevelMenuItem, wxT("Bad MainWindow menu structure"));
00319        wxMenu * setLevelMenu = setLevelMenuItem->GetSubMenu();
00320        wxASSERT_MSG(setLevelMenu, wxT("Bad MainWindow menu structure"));
00321        wxMenuItem * levelItem = (wxMenuItem *)NULL;
00322 
00323        int itemID = 0;
00324        switch (logLevel)
00325        {
00326        case wxLOG_FatalError:
00327               itemID = ID_MainWin_LogDisable;
00328               break;
00329        case wxLOG_Error:
00330               itemID = ID_MainWin_LogError;
00331               break;
00332        case wxLOG_Warning:
00333               itemID = ID_MainWin_LogWarning;
00334               break;
00335        case wxLOG_Info:
00336        case wxLOG_Debug:
00337               itemID = ID_MainWin_LogAll;
00338               break;
00339        case wxLOG_Trace:
00340        case wxLOG_Progress:
00341        case wxLOG_Message:
00342        case wxLOG_Status:
00343               itemID = ID_MainWin_LogMessage;
00344               break;
00345        }
00346        levelItem = setLevelMenu->FindItem(itemID);
00347        if (levelItem)
00348               levelItem->Check();
00349 }

wxAuiManager* VRUT::MainWindow::GetAUIManager (  )  [inline]

Get window's AUI manager.

Definition at line 59 of file mainwindow.h.

00060         {
00061             return &auiMgr;
00062         }

wxAuiNotebook* VRUT::MainWindow::GetRenderNotebook (  )  [inline]

Get notebook with render windows.

Definition at line 64 of file mainwindow.h.

00065         {
00066             return renderNotebook;
00067         }


Member Data Documentation

wxAuiManager VRUT::MainWindow::auiMgr [protected]

AUI manager.

Definition at line 29 of file mainwindow.h.

wxAuiNotebook* VRUT::MainWindow::renderNotebook [protected]

Notebook for render windows.

Definition at line 31 of file mainwindow.h.


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:43 2009 for VRUT by  doxygen 1.5.5