WorldEditorDoc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // WorldEditorDoc.h : interface of the CWorldEditorDoc class
  13. //
  14. /////////////////////////////////////////////////////////////////////////////
  15. #ifndef WORLDEDITORDOC_H
  16. #define WORLDEDITORDOC_H 1
  17. #define SNAP_DOUBLE_CM 0.015625
  18. #define SNAP_FLOAT_CM 0.015625f
  19. #define SNAP_FLOAT_12 0.125f
  20. #define SNAP_FLOAT_25 0.25f
  21. #define SNAP_ANGLE_GRID (AngleDeg(2.5f))
  22. #define POLYGON_MODE 1
  23. #define SECTOR_MODE 2
  24. #define ENTITY_MODE 3
  25. #define VERTEX_MODE 4
  26. #define TERRAIN_MODE 5
  27. #define CSG_MODE 6
  28. enum ESelectionType
  29. {
  30. ST_NONE = 0,
  31. ST_VERTEX,
  32. ST_ENTITY,
  33. ST_VOLUME,
  34. ST_SECTOR,
  35. ST_POLYGON,
  36. };
  37. enum CSGType
  38. {
  39. CSG_ILLEGAL = 0,
  40. CSG_ADD,
  41. CSG_ADD_REVERSE,
  42. CSG_REMOVE,
  43. CSG_REMOVE_REVERSE,
  44. CSG_SPLIT_SECTORS,
  45. CSG_JOIN_SECTORS,
  46. CSG_SPLIT_POLYGONS,
  47. CSG_JOIN_POLYGONS,
  48. CSG_JOIN_POLYGONS_KEEP_TEXTURES,
  49. CSG_JOIN_ALL_POLYGONS,
  50. CSG_JOIN_ALL_POLYGONS_KEEP_TEXTURES,
  51. CSG_JOIN_LAYERS,
  52. CSG_ADD_ENTITIES,
  53. };
  54. class CUndo
  55. {
  56. public:
  57. CListNode m_lnListNode;
  58. CTFileName m_fnmUndoFile; // name of temporary file used for undo/redo
  59. /* Constructor. */
  60. CUndo(void); // throw char *
  61. /* Destructor. */
  62. ~CUndo(void);
  63. };
  64. class CWorldEditorDoc : public CDocument
  65. {
  66. protected: // create from serialization only
  67. CWorldEditorDoc();
  68. DECLARE_DYNCREATE(CWorldEditorDoc)
  69. // Attributes
  70. public:
  71. CDynamicContainer<CTerrainUndo> m_dcTerrainUndo;
  72. INDEX m_iCurrentTerrainUndo;
  73. BOOL m_bAskedToCheckOut;
  74. SLONG m_slDisplaceTexTime;
  75. INDEX m_iMirror;
  76. INDEX m_iTexture;
  77. CTerrain *m_ptrSelectedTerrain;
  78. CTextureObject m_toBackdropUp;
  79. CTextureObject m_toBackdropFt;
  80. CTextureObject m_toBackdropRt;
  81. CObject3D m_o3dBackdropObject;
  82. FLOAT3D m_vCreateBoxVertice0; // vertices that were last used in box creation
  83. FLOAT3D m_vCreateBoxVertice1;
  84. FLOAT3D m_avVolumeBoxVertice[ 8]; // volume box vertices
  85. // number of vertices used for creating last primitive base polygon (-1 for recreate base)
  86. BOOL m_bPrimitiveCreatedFirstTime;
  87. INDEX m_ctLastPrimitiveVertices;
  88. DOUBLE m_fLastPrimitiveWidth;
  89. DOUBLE m_fLastPrimitiveLenght;
  90. BOOL m_bLastIfOuter;
  91. TriangularisationType m_ttLastTriangularisationType;
  92. // index of vertice on volume box that user is currently dragging
  93. INDEX m_iVolumeBoxDragVertice;
  94. // starting position of volume box vertice before drag started
  95. FLOAT3D m_vVolumeBoxStartDragVertice;
  96. BOOL m_bPreLastUsedPrimitiveMode;
  97. BOOL m_bLastUsedPrimitiveMode;
  98. CTFileName m_fnLastDroppedTemplate;
  99. enum CSGType m_csgtPreLastUsedCSGOperation;
  100. enum CSGType m_csgtLastUsedCSGOperation;
  101. // list head for undo
  102. CListHead m_lhUndo;
  103. // list head for redo
  104. CListHead m_lhRedo;
  105. BOOL m_bAutoSnap;
  106. BOOL m_bOrientationIcons;
  107. BOOL m_bPrimitiveMode;
  108. BOOL m_bBrowseEntitiesMode;
  109. CPlacement3D m_plGrid;
  110. CPlacement3D m_plSecondLayer;
  111. CPlacement3D m_plDeltaPlacement;
  112. CPlacement3D m_plLastPlacement;
  113. CWorld m_woWorld;
  114. CWorld *m_pwoSecondLayer; // world for holding second layer
  115. CEntity *m_penPrimitive;
  116. // index for holding pre CSG mode
  117. INDEX m_iPreCSGMode;
  118. INDEX m_iMode;
  119. // volume selection
  120. CDynamicContainer<CEntity> m_cenEntitiesSelectedByVolume;
  121. INDEX m_iSelectedEntityInVolume;
  122. // selections
  123. CEntitySelection m_selEntitySelection;
  124. CBrushSectorSelection m_selSectorSelection;
  125. CBrushVertexSelection m_selVertexSelection;
  126. CStaticArray<DOUBLE3D> m_avStartDragVertices;
  127. CBrushPolygonSelection m_selPolygonSelection;
  128. CStaticArray<CPlacement3D> m_aSelectedEntityPlacements;
  129. CBrushPolygon *m_pbpoLastCentered;
  130. CChangeableRT m_chSelections;
  131. CChangeableRT m_chDocument;
  132. BOOL m_bWasEverSaved; // set if saved at least once (if not - play from testgame.wld)
  133. BOOL m_bReadOnly; // opened file was read-only
  134. CWorldEditorView *m_pCutLineView;
  135. FLOAT3D m_vCutLineStart;
  136. FLOAT3D m_vCutLineEnd;
  137. FLOAT3D m_vControlLineDragStart;
  138. // Operations
  139. public:
  140. // Function corects coordinates of vertices that represent box because given vertice is
  141. // moved and box has invalid geometry
  142. void CorrectBox(INDEX iMovedVtx, FLOAT3D vNewPosition);
  143. // Selects entity with given index inside volume
  144. void SelectGivenEntity( INDEX iEntityToSelect);
  145. // adds all world's entities that fall inside volume into volume selection
  146. void SelectEntitiesByVolumeBox(void);
  147. void ConvertObject3DToBrush(CObject3D &ob, BOOL bApplyProjectedMapping=FALSE,
  148. INDEX iMipBrush=0, FLOAT fMipFactor=1E6f, BOOL bApplyDefaultPolygonProperties=TRUE);
  149. // calculate base of primitive (discard vertex draging)
  150. void CreateConusPrimitive(void);
  151. void CreateTorusPrimitive(void);
  152. void CreateStaircasesPrimitive(void);
  153. void CreateSpherePrimitive(void);
  154. void CreateTerrainPrimitive(void);
  155. void CreateTerrainObject3D( CImageInfo *piiDisplace, INDEX iSlicesX, INDEX iSlicesZ, INDEX iMip);
  156. void CreatePrimitive(void);
  157. // apply auto colorize function
  158. void ApplyAutoColorize(void);
  159. // refresh primitive page
  160. void RefreshPrimitivePage(void);
  161. // refresh primitive page
  162. void RefreshCurrentInfoPage(void);
  163. // apply now current primitive settings (used in load primitive settings and history)
  164. void ApplyCurrentPrimitiveSettings(void);
  165. BOOL IsEntityCSGEnabled(void);
  166. // start creating primitive
  167. void StartPrimitiveCSG( CPlacement3D plPrimitive, BOOL bResetAngles = TRUE);
  168. // start CSG with world template
  169. void StartTemplateCSG( CPlacement3D plPrimitive, const CTFileName &fnWorld,
  170. BOOL bResetAngles = TRUE);
  171. // inform all views that CSG is started
  172. void AtStartCSG(void);
  173. // inform all views that CSG is finished
  174. void AtStopCSG(void);
  175. // apply current CSG operation
  176. void PreApplyCSG(enum CSGType CSGType);
  177. void ApplyCSG(enum CSGType CSGType);
  178. // cancel current CSG operation
  179. void CancelCSG(void);
  180. // clean up after doing a CSG
  181. void StopCSG(void);
  182. // does "snap to grid" for given float
  183. void SnapFloat( FLOAT &fDest, FLOAT fStep = SNAP_FLOAT_GRID);
  184. // does "snap to grid" for given angle
  185. void SnapAngle( ANGLE &angDest, ANGLE fStep = SNAP_ANGLE_GRID);
  186. // does "snap to grid" for given placement
  187. void SnapToGrid( CPlacement3D &plPlacement, FLOAT fSnapValue);
  188. // does "snap to grid" for primitive values
  189. void SnapPrimitiveValuesToGrid(void);
  190. // saves curent state of the world as tail of give undo/redo list
  191. void SaveWorldIntoUndoRedoList( CListHead &lhList);
  192. // restores last operation from given undo/redo object
  193. void LoadWorldFromUndoRedoList( CUndo *pUndoRedo);
  194. // remembers last operation into undo buffer
  195. void RememberUndo(void);
  196. // undoes last operation
  197. void Undo(void);
  198. // redoes last undoed operation
  199. void Redo(void);
  200. // retrieves editing mode
  201. inline INDEX GetEditingMode() { return m_iMode;};
  202. // selects all entities in volume
  203. void OnSelectAllInVolume(void);
  204. // sets editing mode
  205. void SetEditingMode( INDEX iNewMode);
  206. // paste given texture over polygon selection
  207. void PasteTextureOverSelection_t( CTFileName fnFileName);
  208. // deselect all selected members in current selection mode
  209. void DeselectAll(void);
  210. // Sets message about current mode and selected members
  211. void SetStatusLineModeInfoMessage( void);
  212. // creates texture from picture and initializes texture object
  213. void SetupBackdropTextureObject( CTFileName fnPicture, CTextureObject &to);
  214. // saves thumbnail
  215. void SaveThumbnail(void);
  216. // reset primitive settings
  217. void ResetPrimitive(void);
  218. void InsertPrimitiveVertex(INDEX iEdge, FLOAT3D vVertexToInsert);
  219. void DeletePrimitiveVertex(INDEX iVtxToDelete);
  220. void ApplyMirrorAndStretch(INDEX iMirror, FLOAT fStretch);
  221. void SetActiveTextureLayer(INDEX iLayer);
  222. void ClearSelections(ESelectionType stExcept=ST_NONE);
  223. BOOL IsCloneUpdatingAllowed(void);
  224. void SetCutMode( CWorldEditorView *pwedView);
  225. void ApplyCut( void);
  226. // show/hide functoins
  227. void OnHideSelectedEntities(void);
  228. void OnHideUnselectedEntities(void);
  229. void OnShowAllEntities(void);
  230. void OnHideSelectedSectors(void);
  231. void OnHideUnselectedSectors(void);
  232. void OnShowAllSectors(void);
  233. void SetModifiedFlag( BOOL bModified = TRUE);
  234. void ReloadWorld(void);
  235. BOOL IsReadOnly(void);
  236. BOOL IsBrushUpdatingAllowed(void);
  237. void OnIdle(void);
  238. // Overrides
  239. // ClassWizard generated virtual function overrides
  240. //{{AFX_VIRTUAL(CWorldEditorDoc)
  241. public:
  242. virtual BOOL OnNewDocument();
  243. virtual void Serialize(CArchive& ar);
  244. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  245. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  246. //}}AFX_VIRTUAL
  247. // Implementation
  248. public:
  249. virtual ~CWorldEditorDoc();
  250. #ifdef _DEBUG
  251. virtual void AssertValid() const;
  252. virtual void Dump(CDumpContext& dc) const;
  253. #endif
  254. protected:
  255. // Generated message map functions
  256. public:
  257. //{{AFX_MSG(CWorldEditorDoc)
  258. afx_msg void OnCsgSplitSectors();
  259. afx_msg void OnUpdateCsgSplitSectors(CCmdUI* pCmdUI);
  260. afx_msg void OnCsgCancel();
  261. afx_msg void OnShowOrientation();
  262. afx_msg void OnUpdateShowOrientation(CCmdUI* pCmdUI);
  263. afx_msg void OnEditUndo();
  264. afx_msg void OnEditRedo();
  265. afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
  266. afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
  267. afx_msg void OnWorldSettings();
  268. afx_msg void OnCsgJoinSectors();
  269. afx_msg void OnUpdateCsgJoinSectors(CCmdUI* pCmdUI);
  270. afx_msg void OnAutoSnap();
  271. afx_msg void OnCsgAdd();
  272. afx_msg void OnUpdateCsgAdd(CCmdUI* pCmdUI);
  273. afx_msg void OnCsgRemove();
  274. afx_msg void OnUpdateCsgRemove(CCmdUI* pCmdUI);
  275. afx_msg void OnCsgSplitPolygons();
  276. afx_msg void OnUpdateCsgSplitPolygons(CCmdUI* pCmdUI);
  277. afx_msg void OnCsgJoinPolygons();
  278. afx_msg void OnUpdateCsgJoinPolygons(CCmdUI* pCmdUI);
  279. afx_msg void OnCalculateShadows();
  280. afx_msg void OnBrowseEntitiesMode();
  281. afx_msg void OnUpdateBrowseEntitiesMode(CCmdUI* pCmdUI);
  282. afx_msg void OnPreviousSelectedEntity();
  283. afx_msg void OnUpdatePreviousSelectedEntity(CCmdUI* pCmdUI);
  284. afx_msg void OnNextSelectedEntity();
  285. afx_msg void OnUpdateNextSelectedEntity(CCmdUI* pCmdUI);
  286. afx_msg void OnJoinLayers();
  287. afx_msg void OnUpdateAutoSnap(CCmdUI* pCmdUI);
  288. afx_msg void OnSelectByClass();
  289. afx_msg void OnUpdateSelectByClass(CCmdUI* pCmdUI);
  290. afx_msg void OnCsgJoinAllPolygons();
  291. afx_msg void OnUpdateCsgJoinAllPolygons(CCmdUI* pCmdUI);
  292. afx_msg void OnTexture1();
  293. afx_msg void OnUpdateTexture1(CCmdUI* pCmdUI);
  294. afx_msg void OnTexture2();
  295. afx_msg void OnUpdateTexture2(CCmdUI* pCmdUI);
  296. afx_msg void OnTexture3();
  297. afx_msg void OnUpdateTexture3(CCmdUI* pCmdUI);
  298. afx_msg void OnTextureMode1();
  299. afx_msg void OnTextureMode2();
  300. afx_msg void OnTextureMode3();
  301. afx_msg void OnSaveThumbnail();
  302. afx_msg void OnUpdateLinks();
  303. afx_msg void OnSnapshot();
  304. afx_msg void OnMirrorAndStretch();
  305. afx_msg void OnFlipLayer();
  306. afx_msg void OnUpdateFlipLayer(CCmdUI* pCmdUI);
  307. afx_msg void OnFilterSelection();
  308. afx_msg void OnUpdateClones();
  309. afx_msg void OnUpdateUpdateClones(CCmdUI* pCmdUI);
  310. afx_msg void OnSelectByClassAll();
  311. afx_msg void OnHideSelected();
  312. afx_msg void OnUpdateHideSelected(CCmdUI* pCmdUI);
  313. afx_msg void OnHideUnselected();
  314. afx_msg void OnShowAll();
  315. afx_msg void OnCheckEdit();
  316. afx_msg void OnCheckAdd();
  317. afx_msg void OnCheckDelete();
  318. afx_msg void OnUpdateCheckEdit(CCmdUI* pCmdUI);
  319. afx_msg void OnUpdateCheckAdd(CCmdUI* pCmdUI);
  320. afx_msg void OnUpdateCheckDelete(CCmdUI* pCmdUI);
  321. afx_msg void OnUpdateBrushes();
  322. afx_msg void OnSelectByClassImportant();
  323. afx_msg void OnInsert3dObject();
  324. afx_msg void OnExport3dObject();
  325. afx_msg void OnUpdateExport3dObject(CCmdUI* pCmdUI);
  326. afx_msg void OnCrossroadForN();
  327. afx_msg void OnPopupVtxAllign();
  328. afx_msg void OnPopupVtxFilter();
  329. afx_msg void OnPopupVtxNumeric();
  330. afx_msg void OnTextureMode4();
  331. afx_msg void OnTextureMode5();
  332. afx_msg void OnTextureMode6();
  333. afx_msg void OnTextureMode7();
  334. afx_msg void OnTextureMode8();
  335. afx_msg void OnTextureMode9();
  336. afx_msg void OnTextureMode10();
  337. //}}AFX_MSG
  338. DECLARE_MESSAGE_MAP()
  339. afx_msg void OnExportPlacements();
  340. afx_msg void OnExportEntities();
  341. };
  342. /////////////////////////////////////////////////////////////////////////////
  343. #endif // WORLDEDITORDOC_H