00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __RT_WXVIS__
00019 #define __RT_WXVIS__
00020
00021 #include "robbase.h"
00022 #include "robmanage.h"
00023 #include <rtcollect.h>
00024
00025
00026
00027
00028 #include <wx/wx.h>
00029 #include <wx/listctrl.h>
00030 #include <wx/splitter.h>
00031 #include <wx/artprov.h>
00032 #include "robwxext.h"
00033 #include "robwxstruct.h"
00034
00035
00036 class RoboTourEvent;
00037 class DebugEvent;
00038
00039 class RobVisFrame;
00040 class FieldPanel;
00041 class PlayerListCtrl;
00042 class PlayerInfoDialog;
00043 class BotErrFilterDialog;
00044 class DebugDialog;
00045 class HistoryCtrl;
00046 class BotPainter;
00047
00048
00049
00050
00051
00052 typedef void (wxEvtHandler::*RoboTourEventFunction)(RoboTourEvent&);
00053 typedef void (wxEvtHandler::*DebugEventFunction)(DebugEvent&);
00054
00055
00056 BEGIN_DECLARE_EVENT_TYPES()
00057 DECLARE_EVENT_TYPE(EVT_RT_SHOW_TYPE, wxEVT_USER_FIRST + 200)
00058 DECLARE_EVENT_TYPE(EVT_RT_INITSIM_TYPE, wxEVT_USER_FIRST + 201)
00059 DECLARE_EVENT_TYPE(EVT_RT_STEPSIM_TYPE, wxEVT_USER_FIRST + 202)
00060 DECLARE_EVENT_TYPE(EVT_RT_EXITSIM_TYPE, wxEVT_USER_FIRST + 203)
00061 DECLARE_EVENT_TYPE(EVT_RT_STEPTOUR_TYPE, wxEVT_USER_FIRST + 204)
00062 DECLARE_EVENT_TYPE(EVT_RT_PLAYER_TYPE, wxEVT_USER_FIRST + 205)
00063 DECLARE_EVENT_TYPE(EVT_RT_SETUPDLG_TYPE, wxEVT_USER_FIRST + 206)
00064 DECLARE_EVENT_TYPE(EVT_RT_MSGINFO_TYPE, wxEVT_USER_FIRST + 207)
00065 DECLARE_EVENT_TYPE(EVT_RT_MSGWARN_TYPE, wxEVT_USER_FIRST + 208)
00066 DECLARE_EVENT_TYPE(EVT_RT_MSGERROR_TYPE, wxEVT_USER_FIRST + 209)
00067 DECLARE_EVENT_TYPE(EVT_RT_MSGROBERR_TYPE, wxEVT_USER_FIRST + 210)
00068
00069 DECLARE_EVENT_TYPE(EVT_DEBUG_UPDATE_TYPE, wxEVT_USER_FIRST + 250)
00070 DECLARE_EVENT_TYPE(EVT_DEBUG_CLOSE_TYPE, wxEVT_USER_FIRST + 251)
00071 END_DECLARE_EVENT_TYPES()
00072
00073
00074 #define EVT_RT_SHOW(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_SHOW_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00075 #define EVT_RT_INITSIM(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_INITSIM_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00076 #define EVT_RT_STEPSIM(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_STEPSIM_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00077 #define EVT_RT_EXITSIM(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_EXITSIM_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00078 #define EVT_RT_STEPTOUR(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_STEPTOUR_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00079 #define EVT_RT_PLAYER(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_PLAYER_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00080 #define EVT_RT_SETUPDLG(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_SETUPDLG_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00081 #define EVT_RT_MSGINFO(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_MSGINFO_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00082 #define EVT_RT_MSGWARN(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_MSGWARN_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00083 #define EVT_RT_MSGERROR(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_MSGERROR_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00084 #define EVT_RT_MSGROBERR(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_RT_MSGROBERR_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00085 #define EVT_DEBUG_UPDATE(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_DEBUG_UPDATE_TYPE, -1, -1, (wxObjectEventFunction) & fn, NULL ),
00086 #define EVT_DEBUG_CLOSE(fn) DECLARE_EVENT_TABLE_ENTRY( EVT_DEBUG_CLOSE_TYPE,-1, -1, (wxObjectEventFunction) & fn, NULL ),
00087
00088
00089 class RoboTourEvent : public wxEvent
00090 {
00091 DECLARE_DYNAMIC_CLASS(RoboTourEvent)
00092 public:
00093 RoboTourEvent(int eventType = EVT_RT_SHOW_TYPE);
00094 RoboTourEvent(const RoboTourEvent& evt);
00095 wxEvent* Clone() const;
00096
00097 void LoadSimData(rt::Simulation* sim, int simNum);
00098 void LoadBotData(rt::Simulation* sim);
00099 void LoadTourData(rt::Simulation* sim, const lrt::Array<rt::TourResult>& tr, const rt::TourInitInfo& ti);
00100 void LoadPlayerData(int playerNum, rt::Simulation* sim, const lrt::Array<rt::TourResult>& tr);
00101
00102 lrt::Vector<BotInfo> botData;
00103 SimInfo simData;
00104 lrt::Vector<TourInfo> tourData;
00105 rt::TourInitInfo tourInitData;
00106 PlayerInfo playerData;
00107 MsgInfo msgData;
00108 void* retData;
00109 };
00110
00111
00112 class DebugEvent : public wxEvent
00113 {
00114 DECLARE_DYNAMIC_CLASS(DebugEvent)
00115 public:
00116 DebugEvent(int eventType = EVT_DEBUG_UPDATE_TYPE);
00117
00118 wxEvent* Clone() const;
00119
00120 DebugInfo data;
00121 };
00122
00123
00127 class BotPainter {
00128 public:
00129 BotPainter();
00130 BotPainter(const BotPainter&);
00131 ~BotPainter();
00132
00133 void LoadSettings();
00134 void StoreSettings();
00135
00136 void SetProgramColour(int progNum, const wxColour& col);
00137 wxColour& GetProgramColour(int progNum);
00138 int GetProgramColourCount();
00139
00140 void DrawBot(BotInfo& bot, wxDC& dc, const wxPoint& position, int size, bool bg = true);
00141 wxImageList* CreateImageList(int imgSize);
00142
00143 private:
00144 int GetFrameStyle(int botType);
00145 void CalcPoints(int dir, int fieldSize, wxPoint* points);
00146 lrt::Vector<wxColour> programColours;
00147 wxBrush* backBrush,* botBrush;
00148 wxPen* backPen,* botPen,* activePen;
00149
00150 };
00151
00153 class FieldDisplay
00154 {
00155 public:
00156 virtual ~FieldDisplay() {}
00157 virtual void EnterSim(const SimInfo& info) = 0;
00158 virtual void StepSim(const lrt::Vector<BotInfo>& status) = 0;
00159 virtual void ExitSim() = 0;
00160 virtual void Update(bool force = false) = 0;
00161 virtual bool Show(bool doShow = true) = 0;
00162 virtual void HandleProgramColourChange() = 0;
00163 virtual wxWindow* GetAsWindow() = 0;
00164 protected:
00165 FieldDisplay(RobVisFrame* vframe) : vframe(vframe) {}
00166 RobVisFrame* vframe;
00167 };
00168
00169 class NoFieldPanel : public wxControl, public FieldDisplay
00170 {
00171 public:
00172 NoFieldPanel(wxWindow* parent, RobVisFrame* vframe, wxWindowID id);
00173 ~NoFieldPanel();
00174 void EnterSim(const SimInfo& info);
00175
00176 void StepSim(const lrt::Vector<BotInfo>& status);
00177 void ExitSim();
00178
00179 void Update(bool force = false);
00180 bool Show(bool doShow);
00181 void HandleProgramColourChange();
00182 wxWindow* GetAsWindow();
00183
00184 DECLARE_EVENT_TABLE()
00185 private:
00186 void OnPaint(wxPaintEvent& event);
00187 };
00188
00189 class FieldPanel : public wxControl, public FieldDisplay
00190 {
00191 public:
00192 FieldPanel(wxWindow* parent, RobVisFrame* vframe, wxWindowID id);
00193 ~FieldPanel();
00194
00195 void EnterSim(const SimInfo& info);
00196
00197 void StepSim(const lrt::Vector<BotInfo>& status);
00198 void ExitSim();
00199
00200 virtual wxSize DoGetBestSize() const;
00201
00202
00203 void Update(bool force = false);
00204
00205 bool Show(bool doShow);
00206 void HandleProgramColourChange();
00207 wxWindow* GetAsWindow();
00208
00209 DECLARE_EVENT_TABLE()
00210 private:
00211 void Paint(wxDC& device, bool forceDraw);
00212 void OnPaint(wxPaintEvent& event);
00213 void OnClick(wxMouseEvent& event);
00214
00215
00216
00217 int fieldSize, xOffset, yOffset;
00218
00219
00220 bool inSim;
00221 SimInfo simInfo;
00222 lrt::Vector<BotInfo> status, prevStatus;
00223 };
00224
00225 class PlayerListCtrl : public ImprovedListCtrl
00226 {
00227 public:
00228 PlayerListCtrl(wxWindow* parent, RobVisFrame* vframe, wxWindowID id);
00229 ~PlayerListCtrl();
00230
00231 void Update(const lrt::Vector<TourInfo>& tourData);
00232
00233 void SetImageIfNeeded(long row, int image);
00234 void SetItemIfNeeded(long row, int col, const wxString& text);
00235 void SetItemIfNeeded(long row, int col, int num) { SetItemIfNeeded(row, col, wxString::Format("%d", num)); }
00236
00237 void HandleProgramColourChange();
00238
00239 DECLARE_EVENT_TABLE()
00240 private:
00241 RobVisFrame* vframe;
00242 int numFieldSize;
00243
00244 lrt::Vector< lrt::Vector<wxString> > strings;
00245 lrt::Vector<int> images; bool haveImgList; int imgListSize;
00246
00247
00248 void OnClick(wxListEvent&);
00249 };
00250
00251 class RobVisFrame : public wxFrame
00252 {
00253 public:
00254 static RobVisFrame* theVisFrame;
00255 static GuiInfo guiInfo;
00256
00257 RobVisFrame();
00258 ~RobVisFrame();
00259
00260 virtual bool Destroy();
00261
00262 BotPainter& GetBotPainter() { return painter; }
00263
00264 void HandleProgramColourChange();
00265 void HandleFieldClick(int fieldX, int fieldY);
00266 bool HandleDebugDialogClose(int debugID);
00267
00268 DECLARE_EVENT_TABLE()
00269 private:
00270
00271 void LoadSettings();
00272 void StoreSettings();
00273
00274 bool AddStdIcon(wxImageList* iList, wxArtID id, const wxSize& sz);
00275 void AddMessage(const wxString& msg, int icon);
00276 bool Filter(int errid);
00277 void SetActiveFieldDisplay(int num, bool toogleTools = false);
00278
00279 void OnProgramColourMenu(wxCommandEvent&);
00280 void OnBotErrFilterMenu(wxCommandEvent&);
00281 void OnUseHQMenu(wxCommandEvent&);
00282 void OnShowMessageList(wxCommandEvent&);
00283 void OnNewTourMenu(wxCommandEvent&);
00284 void OnAbortTourMenu(wxCommandEvent&);
00285 void OnHideMenu(wxCommandEvent&);
00286 void OnExitMenu(wxCommandEvent&);
00287 void OnHelp(wxCommandEvent&);
00288 void OnAbout(wxCommandEvent&);
00289 void OnClose(wxCloseEvent&);
00290
00291 void OnShow(RoboTourEvent&);
00292 void OnInitSim(RoboTourEvent&);
00293 void OnStepSim(RoboTourEvent&);
00294 void OnExitSim(RoboTourEvent&);
00295 void OnStepTour(RoboTourEvent&);
00296 void OnPlayerInfo(RoboTourEvent&);
00297 void OnSetupDlg(RoboTourEvent&);
00298
00299 void OnMsgInfo(RoboTourEvent&);
00300 void OnMsgWarn(RoboTourEvent&);
00301 void OnMsgError(RoboTourEvent&);
00302 void OnMsgRobErr(RoboTourEvent&);
00303
00304 void OnDebugUpdate(DebugEvent&);
00305 void OnDebugClose(DebugEvent&);
00306
00307 void OnStart(wxCommandEvent&);
00308 void OnStartLock(wxCommandEvent&);
00309 void OnSlowMode(wxCommandEvent&);
00310 void OnPause(wxCommandEvent&);
00311 void OnAbort(wxCommandEvent&);
00312 void OnSpeed(wxCommandEvent&);
00313 void OnNoField(wxCommandEvent&);
00314 void On2DField(wxCommandEvent&);
00315 void On3DField(wxCommandEvent&);
00316
00317
00318 SimInfo simInfo;
00319 wxPanel* infoPanel;
00320 lrt::Vector<FieldDisplay*> field;
00321 lrt::Map<int, DebugDialog*> debugDialogs;
00322 lrt::Vector<int> ignoreDebugIDs;
00323 FieldDisplay* activeField; int activeFieldNum;
00324 PlayerListCtrl* players;
00325 HistoryCtrl* history;
00326 ImprovedListCtrl* messages;
00327 wxStaticText* tSimCount,* tCycleCount;
00328 wxSplitterWindow* hSplitter,* vSplitter;
00329 BotPainter painter;
00330
00331 BotErrFilterDialog* errFilter;
00332
00333 bool haveSim;
00334 int curCycle, numBotColours;
00335 lrt::Time framesStart;
00336 int numFramesSince;
00337 };
00338
00339 enum {
00340 RVF_Start = 100,
00341 RVF_StartLock,
00342 RVF_Speed,
00343 RVF_Slow,
00344 RVF_Pause,
00345 RVF_Abort,
00346 RVF_NoField,
00347 RVF_2DField,
00348 RVF_3DField,
00349 RVF_Colours,
00350 RVF_Filter,
00351 RVF_UseHQ,
00352 RVF_ShowMsg,
00353 RVF_NewTour,
00354 RVF_AbortTour,
00355 RVF_HideWin,
00356 RVF_HelpIndex,
00357 RVF_About,
00358 };
00359
00360 class PlayerInfoDialog : public wxDialog
00361 {
00362 public:
00363 PlayerInfoDialog(wxFrame* parent, const lrt::Vector<lrt::Pair<lrt::String, lrt::String> >& info);
00364 };
00365
00366
00367 #endif //__RT_WXVIS__
00368