Cafu Engine
DialogEditSurfaceProps.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_DIALOG_EDIT_SURFACE_PROPS_HPP_INCLUDED
8 #define CAFU_DIALOG_EDIT_SURFACE_PROPS_HPP_INCLUDED
9 
10 #include "SurfaceInfo.hpp"
11 #include "ObserverPattern.hpp"
12 #include "wx/wx.h"
13 #include "wx/spinctrl.h"
14 
15 
16 class EditorMaterialI;
17 class MapBezierPatchT;
18 class MapBrushT;
19 class MapDocumentT;
20 class MapElementT;
21 class MapFaceT;
22 class ViewWindow3DT;
23 
24 
25 /**
26  * The "Edit Surface Properties" dialog is the counterpart of the ToolEditSurfaceT tool.
27  *
28  * Its state is comprised of two largely independent sub-states:
29  * - the set of selected faces and Bezier patches,
30  * - the surface information of the last picked face or Bezier patch, some of
31  * which is kept in explicit members, some as values of the dialog controls.
32  */
33 class EditSurfacePropsDialogT : public wxPanel, public ObserverT
34 {
35  public:
36 
37  static const unsigned long ALL_FACES; // Needed to select all faces of a brush.
38 
39  /// The constructor.
40  EditSurfacePropsDialogT(wxWindow* Parent, MapDocumentT* MapDoc);
41 
42  /// The destructor.
44 
45  // Implementation of the ObserverT interface.
46  void NotifySubjectDies(SubjectT* Subject);
47 
48  /// Overridden wxDialog::Show() function, because we also want to update the dialog on Show(true).
49  /// Note that this method is called *indirectly* by the wxAUI framework, when the related pane is shown or hidden!
50  bool Show(bool show=true);
51 
52  /// Clears the list of faces and patches that were selected for surface-editing.
53  void ClearSelection();
54 
55  /// This method toggles the selection status of the given object.
56  /// It is called when the user left-clicked a face, Bezier patch or terrain in the 3D view.
57  ///
58  /// @param Object The basic map object that is to be toggled.
59  /// @param FaceIndex If `Object` is a brush, `FaceIndex` indicates which face of the
60  /// brush is to be toggled, or `ALL_FACES` for all faces.
61  /// @param IsRecursive Used for implementation purposes only, user code should always
62  /// pass the default value (`false`).
63  void ToggleClick(MapElementT* Object, unsigned long FaceIndex, bool IsRecursive = false);
64 
65  /// Called when the user right clicked on a face/patch in the 3D view to apply a material.
66  /// FaceIndex==ALL_FACES will perform the apply click on all faces of a brush (if Object is a brush).
67  void ApplyClick(ViewWindow3DT& ViewWin3D, MapElementT* Object, unsigned long FaceIndex);
68 
69  /// Called when a material is picked by the eye dropper (left mouse button click in eyedropper mode).
70  void EyeDropperClick(MapElementT* Object, unsigned long FaceIndex);
71 
72  /// Returns true if the hide selection overlay checkbox is unchecked and false if it is checked.
73  bool WantSelectionOverlay() const { return !CheckBoxHideSelMask->IsChecked(); }
74 
75  /// Returns the number of currently selected faces.
76  unsigned long GetNrOfSelectedFaces() const { return m_SelectedFaces.Size(); }
77 
78  /// Returns the number of currently selected Bezier patches.
79  unsigned long GetNrOfSelectedPatches() const { return m_SelectedPatches.Size(); }
80 
81  /// Returns the current list of MRU materials (the first element is the selected material).
83 
84 
85  private:
86 
87  /// This enum describes how previously picked surface details
88  /// are to be applied to another surface.
89  enum ApplyModeT
90  {
91  ApplyNormal,
92  ApplyViewAligned,
93  ApplyEdgeAligned,
94  ApplyProjective
95  };
96 
97  /// This enum describes what surface detail (or combination of details)
98  /// is to be applied to a face or patch.
99  enum ApplyDetailT
100  {
101  ApplyNone =0x00,
102  ApplyScaleX =0x01,
103  ApplyScaleY =0x02,
104  ApplyShiftX =0x04,
105  ApplyShiftY =0x08,
106  ApplyRotation=0x10,
107  ApplyAll =0xFF
108  };
109 
110  /// A struct that describes a selected face.
111  struct SelectedFaceT
112  {
113  MapFaceT* Face;
114  MapBrushT* Brush;
115  unsigned long FaceIndex;
116  };
117 
118  /// This struct helps to provide a better user experience when a material is applied to
119  /// several faces or patches: If the application is not possible for some reason, we want
120  /// to inform the user only once, not once per face or patch.
121  struct MsgCountsT
122  {
123  MsgCountsT()
124  : NoRefPlane(0), NoCenterFace(0), NoEdgeAlign(0) {}
125 
126  unsigned int NoRefPlane;
127  unsigned int NoCenterFace;
128  unsigned int NoEdgeAlign;
129  };
130 
131  MapDocumentT* m_MapDoc; ///< Pointer to the currently active document, or NULL when no document active.
132  TexCoordGenModeT m_CurrentTexGenMode; ///< The tex-coords generation mode for the currently (i.e. last) picked face/patch (`PlaneProj` or `MatFit`, never `Custom`).
133  Vector3fT m_CurrentUAxis; ///< The u-axis of the currently (i.e. last) picked face/patch.
134  Vector3fT m_CurrentVAxis; ///< The v-axis of the currently (i.e. last) picked face/patch.
135  ArrayT<SelectedFaceT> m_SelectedFaces; ///< The list of selected faces.
136  ArrayT<MapBezierPatchT*> m_SelectedPatches; ///< The list of selected patches.
137 
138  /// Returns the material that is currently set in the ChoiceCurrentMat (or NULL for none).
139  EditorMaterialI* GetCurrentMaterial() const;
140 
141  /// Computes a SurfaceInfoT instance for a MapFaceT according to the current dialog
142  /// settings and the given parameters.
143  ///
144  /// @param Face
145  /// The face to compute a new SurfaceInfoT for. The defaults for all values that don't
146  /// change are copied from the existing SurfaceInfoT instance of this face.
147  ///
148  /// @param Mat
149  /// The "reference" material that provides the material's width and height values that
150  /// are needed for some of the computations. This can be `NULL` or `Face->GetMaterial()`
151  /// whenever the material is not intended to be replaced by the caller. If however the
152  /// caller intends to replace the face's material anyway, it must be the new material!
153  ///
154  /// @param ApplyMode
155  /// The algorithm that is used for computing the details of the new SurfaceInfoT
156  /// instance.
157  ///
158  /// @param Detail
159  /// If `ApplyMode` is `ApplyNormal`, `Detail` determines the subset of values to
160  /// account for. Must be `ApplyAll` in in all other `ApplyModes`.
161  ///
162  /// @param MsgCounts
163  /// If problems occur, this helps to inform the user about each problem only once.
164  ///
165  /// @param ViewWin3D
166  /// The 3D view that is needed for the computations when `ApplyMode` is
167  /// `ApplyViewAligned`.
168  SurfaceInfoT ObtainSurfaceInfo(const MapFaceT* Face, EditorMaterialI* Mat, const ApplyModeT ApplyMode, const ApplyDetailT Detail, MsgCountsT& MsgCounts, ViewWindow3DT* ViewWin3D = NULL) const;
169 
170  /// Computes a SurfaceInfoT instance for a MapBezierPatchT according to the current dialog
171  /// settings and the given parameters. For details, see ObtainSurfaceInfo() above.
172  SurfaceInfoT ObtainSurfaceInfo(const MapBezierPatchT* Patch, EditorMaterialI* Mat, const ApplyModeT ApplyMode, const ApplyDetailT Detail, MsgCountsT& MsgCounts, ViewWindow3DT* ViewWin3D = NULL) const;
173 
174  // Updates the face normal and material vector info in the dialog.
175  void UpdateVectorInfo();
176 
177  /// Updates the dialog controls depending on the current selection.
178  void UpdateAfterSelChange();
179 
180  // "Orientation" section controls.
181  wxSpinCtrlDouble* m_SpinCtrlScaleX;
182  wxSpinCtrlDouble* m_SpinCtrlScaleY;
183  wxSpinCtrlDouble* m_SpinCtrlShiftX;
184  wxSpinCtrlDouble* m_SpinCtrlShiftY;
185  wxSpinCtrlDouble* m_SpinCtrlRotation;
186  wxStaticText* m_TexGenModeInfo;
187 
188  // Face and Material Vector info text.
189  wxStaticText* MaterialXInfo;
190  wxStaticText* MaterialYInfo;
191 
192  // "Alignment" section controls.
193  wxStaticText* m_wrtWorldAxesText;
194  wxStaticText* m_wrtWorldAxesInfo;
195  wxButton* m_wrtWorldAxesButton;
196  wxStaticText* m_wrtFacePlaneText;
197  wxStaticText* m_wrtFacePlaneInfo;
198  wxButton* m_wrtFacePlaneButton;
199  wxCheckBox* m_CheckBoxTreatMultipleAsOne;
200 
201  // "Material" section controls.
202  wxChoice* ChoiceCurrentMat;
203  wxStaticBitmap* m_BitmapCurrentMat;
204  wxStaticText* StaticTextCurrentMatSize;
205 
206  // "Tool Mode" section controls.
207  wxCheckBox* CheckBoxHideSelMask;
208  wxChoice* ChoiceRightMBMode;
209 
210  // "Material Orientation" section event handlers (one for all spin controls).
211  void OnSpinCtrlValueChanged(wxSpinDoubleEvent& Event);
212 
213  // "Alignment" section event handlers.
214  void OnButtonAlign (wxCommandEvent& Event);
215  void OnButtonAlignWrtAxes (wxCommandEvent& Event);
216  void OnCheckBoxTreatMultipleAsOne(wxCommandEvent& Event);
217 
218  // "Material" section event handlers.
219  void OnSelChangeCurrentMat(wxCommandEvent& Event);
220  void OnButtonBrowseMats (wxCommandEvent& Event);
221  void OnButtonReplaceMats (wxCommandEvent& Event);
222 
223  // "Tool Mode" section event handlers.
224  void OnCheckBoxHideSelMask(wxCommandEvent& Event);
225  void OnSelChangeRightMB (wxCommandEvent& Event);
226 
227 
228  // IDs for the controls whose events we are interested in.
229  enum
230  {
231  ID_SPINCTRL_SCALE_X=wxID_HIGHEST+1,
232  ID_SPINCTRL_SCALE_Y,
233  ID_SPINCTRL_SHIFT_X,
234  ID_SPINCTRL_SHIFT_Y,
235  ID_SPINCTRL_ROTATION,
236  ID_BUTTON_ALIGN2FITFACE,
237  ID_BUTTON_ALIGN2TOP,
238  ID_BUTTON_ALIGN2LEFT,
239  ID_BUTTON_ALIGN2CENTER,
240  ID_BUTTON_ALIGN2RIGHT,
241  ID_BUTTON_ALIGN2BOTTOM,
242  ID_BUTTON_ALIGN_WRT_WORLD,
243  ID_BUTTON_ALIGN_WRT_FACE,
244  ID_CHECKBOX_TREAT_MULTIPLE_AS_ONE,
245  ID_CHOICE_CURRENT_MAT,
246  ID_BUTTON_BROWSE_MATS,
247  ID_BUTTON_REPLACE_MATS,
248  ID_CHECKBOX_HIDE_SEL_MASK,
249  ID_CHOICE_RIGHT_MB_MODE
250  };
251 
252  DECLARE_EVENT_TABLE()
253 };
254 
255 #endif
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
void NotifySubjectDies(SubjectT *Subject)
This method is called whenever a subject is about the be destroyed (and become unavailable).
Definition: DialogEditSurfaceProps.cpp:336
unsigned long GetNrOfSelectedPatches() const
Returns the number of currently selected Bezier patches.
Definition: DialogEditSurfaceProps.hpp:79
This class holds all information that is needed in order to compute the UV texture-space coordinates ...
Definition: SurfaceInfo.hpp:51
bool WantSelectionOverlay() const
Returns true if the hide selection overlay checkbox is unchecked and false if it is checked...
Definition: DialogEditSurfaceProps.hpp:73
unsigned long Size() const
Get size of array.
Definition: Array.hpp:138
bool Show(bool show=true)
Overridden wxDialog::Show() function, because we also want to update the dialog on Show(true)...
Definition: DialogEditSurfaceProps.cpp:344
void ApplyClick(ViewWindow3DT &ViewWin3D, MapElementT *Object, unsigned long FaceIndex)
Called when the user right clicked on a face/patch in the 3D view to apply a material.
Definition: DialogEditSurfaceProps.cpp:466
Definition: ObserverPattern.hpp:64
void EyeDropperClick(MapElementT *Object, unsigned long FaceIndex)
Called when a material is picked by the eye dropper (left mouse button click in eyedropper mode)...
Definition: DialogEditSurfaceProps.cpp:524
Definition: MapBrush.hpp:15
unsigned long GetNrOfSelectedFaces() const
Returns the number of currently selected faces.
Definition: DialogEditSurfaceProps.hpp:76
This class represents a bezier patch.
Definition: MapBezierPatch.hpp:44
Definition: EditorMaterial.hpp:21
Definition: ObserverPattern.hpp:158
EditSurfacePropsDialogT(wxWindow *Parent, MapDocumentT *MapDoc)
The constructor.
Definition: DialogEditSurfaceProps.cpp:62
Definition: ChildFrameViewWin3D.hpp:21
void ClearSelection()
Clears the list of faces and patches that were selected for surface-editing.
Definition: DialogEditSurfaceProps.cpp:374
The "Edit Surface Properties" dialog is the counterpart of the ToolEditSurfaceT tool.
Definition: DialogEditSurfaceProps.hpp:33
ArrayT< EditorMaterialI * > GetMRUMaterials() const
Returns the current list of MRU materials (the first element is the selected material).
Definition: DialogEditSurfaceProps.cpp:1413
This file provides the classes for the Observer pattern as described in the book by the GoF...
This is the base class for all elements ("objects") that can exist in a map.
Definition: MapElement.hpp:57
void ToggleClick(MapElementT *Object, unsigned long FaceIndex, bool IsRecursive=false)
This method toggles the selection status of the given object.
Definition: DialogEditSurfaceProps.cpp:390
~EditSurfacePropsDialogT()
The destructor.
Definition: DialogEditSurfaceProps.cpp:329
Definition: MapFace.hpp:26