Cafu Engine
ChildFrame.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_CHILDFRAME_HPP_INCLUDED
8 #define CAFU_CHILDFRAME_HPP_INCLUDED
9 
10 #include "../CommandHistory.hpp"
11 
12 #include "Math3D/Angles.hpp"
13 #include "Math3D/Vector3.hpp"
14 #include "Templates/Array.hpp"
15 
16 #include "wx/mdi.h"
17 #include "wx/timer.h"
18 #include "wx/aui/framemanager.h"
19 
20 
21 namespace cf { namespace TypeSys { class TypeInfoT; } }
22 namespace MapEditor { class EntityHierarchyPanelT; }
23 
24 class ConsoleDialogT;
26 class InspectorDialogT;
28 class GroupsToolbarT;
29 class MapDocumentT;
30 class MaterialsToolbarT;
31 class ParentFrameT;
32 class ToolManagerT;
33 class ViewWindowT;
34 class wxProcessEvent;
35 
36 
37 class AutoSaveTimerT : public wxTimer
38 {
39  public:
40 
41  AutoSaveTimerT(MapDocumentT* Doc, unsigned long ChildFrameNr);
42  ~AutoSaveTimerT();
43 
44  void Notify();
45 
46 
47  private:
48 
49  MapDocumentT* m_Doc;
50  wxString m_AutoSaveName;
51 };
52 
53 
54 /// This class represents a child frame.
55 class ChildFrameT : public wxMDIChildFrame
56 {
57  public:
58 
59  /// IDs for the controls whose events we are interested in.
60  /// Some of the IDs below are commented out. This is usually because there already exists a wx-defined
61  /// ID for the same purpose, which works well with the wx model-view-controler framework.
62  /// See the ParentFrameT class header and documentation for additional information.
63  enum
64  {
65  ID_MENU_FILE_CLOSE=wxID_HIGHEST+1+2000,
66  ID_MENU_FILE_SAVE,
67  ID_MENU_FILE_SAVEAS,
68 
69  // ID_MENU_EDIT_UNDO,
70  // ID_MENU_EDIT_REDO,
71  // ID_MENU_EDIT_CUT,
72  // ID_MENU_EDIT_COPY,
73  // ID_MENU_EDIT_PASTE,
74  ID_MENU_EDIT_PASTE_SPECIAL,
75  ID_MENU_EDIT_DELETE,
76  ID_MENU_EDIT_SELECT_NONE,
77  // ID_MENU_EDIT_SELECT_ALL,
78  ID_MENU_SELECTION_ASSIGN_TO_ENTITY,
79  ID_MENU_SELECTION_GROUP,
80  ID_MENU_SELECTION_HIDE,
81  ID_MENU_SELECTION_HIDE_OTHER,
82 
83  ID_MENU_MAP_SNAP_TO_GRID,
84  ID_MENU_MAP_SHOW_GRID_2D,
85  ID_MENU_MAP_GRID_SETTINGS,
86  ID_MENU_MAP_FINER_GRID,
87  ID_MENU_MAP_COARSER_GRID,
88  ID_MENU_MAP_AUTO_GROUP_ENTITIES,
89  ID_MENU_MAP_GOTO_PRIMITIVE,
90  ID_MENU_MAP_SHOW_INFO,
91  ID_MENU_MAP_CHECK_FOR_PROBLEMS,
92  ID_MENU_MAP_LOAD_POINTFILE,
93  ID_MENU_MAP_UNLOAD_POINTFILE,
94 
95  ID_MENU_VIEW_TOOLBARS,
96  ID_MENU_VIEW_TOOLBARS_FILE,
97  ID_MENU_VIEW_TOOLBARS_TOOLS,
98  ID_MENU_VIEW_TOOLBARS_TOOLOPTIONS,
99  ID_MENU_VIEW_PANELS_ENTITY_HIERARCHY,
100  ID_MENU_VIEW_PANELS_ENTITY_INSPECTOR,
101  ID_MENU_VIEW_PANELS_MATERIALS,
102  ID_MENU_VIEW_PANELS_GROUPS,
103  ID_MENU_VIEW_PANELS_CONSOLE,
104  ID_MENU_VIEW_NEW_2D_VIEW,
105  ID_MENU_VIEW_NEW_3D_VIEW,
106  ID_MENU_VIEW_LOAD_DEFAULT_PERSPECTIVE,
107  ID_MENU_VIEW_LOAD_USER_PERSPECTIVE,
108  ID_MENU_VIEW_SAVE_USER_PERSPECTIVE,
109  ID_MENU_VIEW_CENTER_2D_VIEWS,
110  ID_MENU_VIEW_CENTER_3D_VIEWS,
111  ID_MENU_VIEW_SHOW_ENTITY_INFO,
112  ID_MENU_VIEW_SHOW_ENTITY_TARGETS,
113 
114  ID_MENU_TOOLS_TOOL_SELECTION,
115  ID_MENU_TOOLS_TOOL_CAMERA,
116  ID_MENU_TOOLS_TOOL_NEWBRUSH,
117  ID_MENU_TOOLS_TOOL_NEWENTITY,
118  ID_MENU_TOOLS_TOOL_NEWBEZIERPATCH,
119  ID_MENU_TOOLS_TOOL_NEWTERRAIN,
120  ID_MENU_TOOLS_TOOL_NEWDECAL,
121  ID_MENU_TOOLS_TOOL_EDITSURFACEPROPERTIES,
122  ID_MENU_TOOLS_TOOL_TERRAINEDITOR,
123  ID_MENU_TOOLS_TOOL_CLIP,
124  ID_MENU_TOOLS_TOOL_EDITVERTICES,
125  ID_MENU_TOOLS_CARVE,
126  ID_MENU_TOOLS_MAKE_HOLLOW,
127  ID_MENU_TOOLS_APPLY_MATERIAL,
128  ID_MENU_TOOLS_REPLACE_MATERIALS,
129  ID_MENU_TOOLS_MATERIAL_LOCK,
130  ID_MENU_TOOLS_TRANSFORM,
131  ID_MENU_TOOLS_ALIGN,
132  ID_MENU_TOOLS_ALIGN_LEFT,
133  ID_MENU_TOOLS_ALIGN_RIGHT,
134  ID_MENU_TOOLS_ALIGN_HOR_CENTER,
135  ID_MENU_TOOLS_ALIGN_TOP,
136  ID_MENU_TOOLS_ALIGN_BOTTOM,
137  ID_MENU_TOOLS_ALIGN_VERT_CENTER,
138  ID_MENU_TOOLS_MIRROR,
139  ID_MENU_TOOLS_MIRROR_HOR,
140  ID_MENU_TOOLS_MIRROR_VERT,
141 
142  ID_MENU_COMPONENTS_FIRST,
143  ID_MENU_COMPONENTS_MAX = ID_MENU_COMPONENTS_FIRST + 100,
144 
145  ID_MENU_PREFABS_LOAD,
146  ID_MENU_PREFABS_SAVE,
147  ID_MENU_PREFABS_PATH_FIRST,
148  ID_MENU_PREFABS_PATH_LAST = ID_MENU_PREFABS_PATH_FIRST + 31,
149 
150  ID_MENU_COMPILE_FLAG_SAVE_MAP,
151  ID_MENU_COMPILE_FLAG_RUN_BSP,
152  ID_MENU_COMPILE_FLAG_RUN_PVS,
153  ID_MENU_COMPILE_FLAG_RUN_LIGHT,
154  ID_MENU_COMPILE_FLAG_RUN_ENGINE,
155  ID_MENU_COMPILE_QUICK,
156  ID_MENU_COMPILE_NORMAL,
157  ID_MENU_COMPILE_QUALITY,
158  ID_MENU_COMPILE_CUSTOM,
159  ID_MENU_COMPILE_ABORT
160  };
161 
162  /// Constants for use with SetStatusText, to give the individual panes a name.
164  {
165  SBP_MENU_HELP=0,
166  SBP_SELECTION,
167  SBP_MOUSE_POS,
168  SBP_SELECTION_DIMS,
169  SBP_GRID_ZOOM,
170  SBP_GRID_SNAP
171  };
172 
173 
174  /// The constructor.
175  /// @param Parent The parent frame.
176  /// @param MapDoc This frame's document. The frame becomes the owner of the document,
177  /// i.e. it is responsible for destructing it. `MapDoc` is created externally so
178  /// that this constructor doesn't have to deal with problems constructing it.
179  ChildFrameT(ParentFrameT* Parent, MapDocumentT* MapDoc);
180 
181  /// The destructor.
182  /// Notifies the dependent ViewWindowTs that we're being destroyed before them.
183  /// See documentation of ViewWindowT::NotifyChildFrameDies() for full details.
184  ~ChildFrameT();
185 
186  /// Returns this child frames document.
187  MapDocumentT* GetDoc() const { return m_Doc; }
188 
189  /// [...]
190  /// All(!) commands for modifying the document must be submitted via this method.
191  bool SubmitCommand(CommandT* Command);
192 
193  /// Returns the list of all (2D and 3D) view windows that are currently open in this frame.
194  /// The returned list is always sorted in MRU (most-recently-used) order.
195  const ArrayT<ViewWindowT*>& GetViewWindows() const { return m_ViewWindows; }
196 
197  /// Based on the most recently used views (2D or 3D), this method figures out a point in space that the user can see well.
199 
200  void All2DViews_Zoom(float ZoomFactor);
201  void All2DViews_Center(const Vector3fT& CenterPoint);
202 
203  // These two methods are needed because we cannot show or hide wxAUI panes from "outside" otherwise.
204  bool IsPaneShown(wxWindow* Pane); ///< Tells if the given pane (one of our toolbars or dialogs that is managed by wxAUI) is currently shown.
205  void ShowPane(wxWindow* Pane, bool DoShow=true); ///< Shows or hides the given pane (one of our toolbars or dialogs that is managed by wxAUI).
206  void SetCaption(wxWindow* Pane, const wxString& Caption); ///< Sets the caption of the AUI pane for the given window.
207 
208  ToolManagerT& GetToolManager() { return *m_ToolManager; } ///< Returns our tool manager.
209  MaterialsToolbarT* GetMaterialsToolbar() { return m_MaterialsToolbar; } ///< Returns the Materials toolbar.
210  GroupsToolbarT* GetGroupsToolbar() { return m_GroupsToolbar; } ///< Returns the Groups toolbar.
211  EditSurfacePropsDialogT* GetSurfacePropsDialog() { return m_SurfacePropsDialog; } ///< Returns the Surface Properties dialog.
212  TerrainEditorDialogT* GetTerrainEditorDialog() { return m_TerrainEditorDialog; } ///< Returns the Terrain Editor dialog.
213  InspectorDialogT* GetInspectorDialog() { return m_InspectorDialog; } ///< Returns the Entity Inspector dialog.
214 
215 
216  private:
217 
218  class UpdaterT; ///< An observer of the map document and the tools that updates this child frame (its status bar, tool options bar, etc.).
219  friend class ViewWindowT; ///< Friend class so that our ViewWindowT children can manage/maintain the m_ViewWindows list themselves.
220 
221  ParentFrameT* m_Parent;
222  wxAuiManager m_AUIManager;
223  wxString m_AUIDefaultPerspective;
224  MapDocumentT* m_Doc;
225  CommandHistoryT* m_History; ///< The command history.
226  unsigned long m_LastSavedAtCommandNr; ///< The ID of the command after which the document was last saved. If the current command ID from the history differs from this, the document contains unsaved changes.
227  AutoSaveTimerT m_AutoSaveTimer;
228  ToolManagerT* m_ToolManager;
229  MapEditor::EntityHierarchyPanelT* m_EntityHierarchyDialog;
230  MaterialsToolbarT* m_MaterialsToolbar;
231  GroupsToolbarT* m_GroupsToolbar;
232  ConsoleDialogT* m_ConsoleDialog;
233  EditSurfacePropsDialogT* m_SurfacePropsDialog;
234  TerrainEditorDialogT* m_TerrainEditorDialog;
235  InspectorDialogT* m_InspectorDialog;
236  UpdaterT* m_Updater;
237  wxMenu* FileMenu;
238  wxMenu* m_ComponentsMenu;
239  wxMenu* m_PrefabsMenu;
240  ArrayT<wxString> m_PrefabsMenuPaths; ///< The paths for the quick-load items in the "Prefabs" menu.
241  wxMenu* CompileMenu;
242 
243  wxProcess* CurrentProcess; ///< The currently running process started from the Compile menu. NULL when there is no process running.
244  int CurrentProcessID; ///< The PID of the currently running process, or 0 if no process is running.
245  ArrayT<wxString> PendingCompileCommands; ///< Pending console commands for map compilation.
246  ArrayT<ViewWindowT*> m_ViewWindows; ///< The list of all (2D and 3D) view windows that are currently open in this frame. Managed/maintained by the ViewWindowTs themselves.
247 
248 
249  /// Recursively builds the "Components" menu, traversing the given TypeInfoT hierarchy.
250  static void BuildComponentsMenu(wxMenu* MenuParent, const cf::TypeSys::TypeInfoT* TypeParent);
251 
252  /// Updates the quick-load items in the "Prefabs" menu.
253  void UpdatePrefabsMenu();
254 
255  /// Loads the prefab with the given filename and adds it to the map.
256  void LoadPrefab(const wxString& FileName);
257 
258  /// Helper method that resets compile process and pending commands and prints a message into the console.
259  /// Used to prevent code duplication.
260  void EndCompiling(const wxString& ConsoleMessage, const wxColour* Colour=wxGREEN);
261 
262  /// Shows or hides the given AUI pane.
263  void PaneToggleShow(wxAuiPaneInfo& PaneInfo);
264 
265  // Event handlers.
266  void OnClose (wxCloseEvent& CE); ///< Event handler for close events, e.g. after a system close button or command or a call to Close() (also see ParentFrameT::OnClose()). See wx Window Deletion Overview for more details.
267  void OnIdle (wxIdleEvent& IE); ///< Idle event handler, for updating the console when an external compile process runs, update all 3D views and caching textures.
268  void OnProcessEnd (wxProcessEvent& PE);
269  void OnMenuFile (wxCommandEvent& CE); ///< Event handler for File menu events.
270  void OnMenuFileUpdate (wxUpdateUIEvent& UE); ///< Event handler for File menu update events.
271 
272  void OnMenuEditUndoRedo (wxCommandEvent& CE);
273  void OnMenuEditCut (wxCommandEvent& CE);
274  void OnMenuEditCopy (wxCommandEvent& CE);
275  void OnMenuEditPaste (wxCommandEvent& CE);
276  void OnMenuEditDelete (wxCommandEvent& CE);
277  void OnMenuEditSelectNone (wxCommandEvent& CE);
278  void OnMenuEditSelectAll (wxCommandEvent& CE);
279  void OnMenuEditUpdate (wxUpdateUIEvent& UE);
280 
281  void OnMenuView (wxCommandEvent& CE); ///< Event handler for View menu events.
282  void OnMenuViewUpdate (wxUpdateUIEvent& UE); ///< Event handler for View menu update events.
283  void OnMenuTools (wxCommandEvent& CE); ///< Event handler for Tools menu events.
284  void OnMenuToolsUpdate(wxUpdateUIEvent& UE); ///< Event handler for Tools menu update events.
285  void OnMenuComponents (wxCommandEvent& CE); ///< Event handler for Components menu events.
286  void OnMenuPrefabs (wxCommandEvent& CE); ///< Event handler for Prefabs menu events.
287  void OnMenuCompile (wxCommandEvent& CE); ///< Event handler for Compile menu events.
288  void OnWindowActivate (wxActivateEvent& AE);
289  void OnAuiPaneClose (wxAuiManagerEvent& AE);
290 
291  DECLARE_EVENT_TABLE()
292 };
293 
294 #endif
Vector3fT GuessUserVisiblePoint() const
Based on the most recently used views (2D or 3D), this method figures out a point in space that the u...
Definition: ChildFrame.cpp:765
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
The Materials toolbar (actually, a dialog).
Definition: ToolbarMaterials.hpp:21
void ShowPane(wxWindow *Pane, bool DoShow=true)
Shows or hides the given pane (one of our toolbars or dialogs that is managed by wxAUI).
Definition: ChildFrame.cpp:837
This class represents the CaWE parent (main) frame.
Definition: ParentFrame.hpp:33
Definition: DialogInspector.hpp:22
Definition: DialogEntityHierarchy.hpp:153
A class that acts as an observer of the map document and the tools for the child frame.
Definition: ChildFrame.cpp:103
ToolManagerT & GetToolManager()
Returns our tool manager.
Definition: ChildFrame.hpp:208
Definition: DialogTerrainEdit.hpp:19
Definition: CommandHistory.hpp:13
This class represents a child frame.
Definition: ChildFrame.hpp:55
bool IsPaneShown(wxWindow *Pane)
Tells if the given pane (one of our toolbars or dialogs that is managed by wxAUI) is currently shown...
Definition: ChildFrame.cpp:827
~ChildFrameT()
The destructor.
Definition: ChildFrame.cpp:710
MaterialsToolbarT * GetMaterialsToolbar()
Returns the Materials toolbar.
Definition: ChildFrame.hpp:209
ChildFrameT(ParentFrameT *Parent, MapDocumentT *MapDoc)
The constructor.
Definition: ChildFrame.cpp:323
Definition: ChildFrame.hpp:37
MapDocumentT * GetDoc() const
Returns this child frames document.
Definition: ChildFrame.hpp:187
This class represents a (superclass of a) 2D or 3D map view window.
Definition: ChildFrameViewWin.hpp:21
GroupsToolbarT * GetGroupsToolbar()
Returns the Groups toolbar.
Definition: ChildFrame.hpp:210
InspectorDialogT * GetInspectorDialog()
Returns the Entity Inspector dialog.
Definition: ChildFrame.hpp:213
EditSurfacePropsDialogT * GetSurfacePropsDialog()
Returns the Surface Properties dialog.
Definition: ChildFrame.hpp:211
Definition: DialogConsole.hpp:11
This class represents a general command for implementing modifications to the applications document...
Definition: CommandPattern.hpp:30
The "Edit Surface Properties" dialog is the counterpart of the ToolEditSurfaceT tool.
Definition: DialogEditSurfaceProps.hpp:33
Definition: ToolManager.hpp:20
const ArrayT< ViewWindowT * > & GetViewWindows() const
Returns the list of all (2D and 3D) view windows that are currently open in this frame.
Definition: ChildFrame.hpp:195
The groups toolbar (actually, a dialog).
Definition: ToolbarGroups.hpp:23
StatusBarPaneIDs
Constants for use with SetStatusText, to give the individual panes a name.
Definition: ChildFrame.hpp:163
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
bool SubmitCommand(CommandT *Command)
[...] All(!) commands for modifying the document must be submitted via this method.
Definition: ChildFrame.cpp:753
TerrainEditorDialogT * GetTerrainEditorDialog()
Returns the Terrain Editor dialog.
Definition: ChildFrame.hpp:212
void SetCaption(wxWindow *Pane, const wxString &Caption)
Sets the caption of the AUI pane for the given window.
Definition: ChildFrame.cpp:852