IEditorImpl.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. // Description : IEditor interface implementation.
  9. #pragma once
  10. #include "IEditor.h"
  11. #include "MainWindow.h"
  12. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  13. #include <memory> // for shared_ptr
  14. #include <QMap>
  15. #include <QApplication>
  16. #include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
  17. #include <AzCore/std/string/string.h>
  18. #include "Commands/CommandManager.h"
  19. #include "Include/IErrorReport.h"
  20. #include "ErrorReport.h"
  21. class QMenu;
  22. #define GET_PLUGIN_ID_FROM_MENU_ID(ID) (((ID) & 0x000000FF))
  23. #define GET_UI_ELEMENT_ID_FROM_MENU_ID(ID) ((((ID) & 0x0000FF00) >> 8))
  24. class CObjectManager;
  25. class CUndoManager;
  26. class CGameEngine;
  27. class CErrorsDlg;
  28. class CTrackViewSequenceManager;
  29. class CEditorFileMonitor;
  30. class AzAssetWindow;
  31. class AzAssetBrowserRequestHandler;
  32. class AssetEditorRequestsHandler;
  33. struct IEditorFileMonitor;
  34. class CVegetationMap;
  35. namespace Editor
  36. {
  37. class EditorQtApplication;
  38. }
  39. namespace AssetDatabase
  40. {
  41. class AssetDatabaseLocationListener;
  42. }
  43. class CEditorImpl
  44. : public IEditor
  45. {
  46. Q_DECLARE_TR_FUNCTIONS(CEditorImpl)
  47. public:
  48. CEditorImpl();
  49. virtual ~CEditorImpl();
  50. void Initialize();
  51. void OnBeginShutdownSequence();
  52. void OnEarlyExitShutdownSequence();
  53. void Uninitialize();
  54. void SetGameEngine(CGameEngine* ge);
  55. void DeleteThis() override { delete this; };
  56. IEditorClassFactory* GetClassFactory() override;
  57. CEditorCommandManager* GetCommandManager() override { return m_pCommandManager; };
  58. ICommandManager* GetICommandManager() override { return m_pCommandManager; }
  59. void ExecuteCommand(const char* sCommand, ...) override;
  60. void ExecuteCommand(const QString& command) override;
  61. void SetDocument(CCryEditDoc* pDoc) override;
  62. CCryEditDoc* GetDocument() const override;
  63. bool IsLevelLoaded() const override;
  64. void SetModifiedFlag(bool modified = true) override;
  65. void SetModifiedModule(EModifiedModule eModifiedModule, bool boSet = true) override;
  66. bool IsLevelExported() const override;
  67. bool SetLevelExported(bool boExported = true) override;
  68. void InitFinished();
  69. bool IsModified() override;
  70. bool IsInitialized() const override{ return m_bInitialized; }
  71. bool SaveDocument() override;
  72. ISystem* GetSystem() override;
  73. void WriteToConsole(const char* string) override { CLogFile::WriteLine(string); };
  74. void WriteToConsole(const QString& string) override { CLogFile::WriteLine(string); };
  75. // Change the message in the status bar
  76. void SetStatusText(const QString& pszString) override;
  77. IMainStatusBar* GetMainStatusBar() override;
  78. bool ShowConsole([[maybe_unused]] bool show) override
  79. {
  80. //if (AfxGetMainWnd())return ((CMainFrame *) (AfxGetMainWnd()))->ShowConsole(show);
  81. return false;
  82. }
  83. void SetConsoleVar(const char* var, float value) override;
  84. float GetConsoleVar(const char* var) override;
  85. //! Query main window of the editor
  86. QMainWindow* GetEditorMainWindow() const override
  87. {
  88. return MainWindow::instance();
  89. };
  90. QString GetPrimaryCDFolder() override;
  91. QString GetLevelName() override;
  92. QString GetLevelFolder() override;
  93. QString GetLevelDataFolder() override;
  94. QString GetSearchPath(EEditorPathName path) override;
  95. QString GetResolvedUserFolder() override;
  96. bool ExecuteConsoleApp(const QString& CommandLine, QString& OutputText, bool bNoTimeOut = false, bool bShowWindow = false) override;
  97. bool IsInGameMode() override;
  98. void SetInGameMode(bool inGame) override;
  99. bool IsInSimulationMode() override;
  100. bool IsInTestMode() override;
  101. bool IsInPreviewMode() override;
  102. bool IsInConsolewMode() override;
  103. bool IsInLevelLoadTestMode() override;
  104. bool IsInMatEditMode() override { return m_bMatEditMode; }
  105. //! Enables/Disable updates of editor.
  106. void EnableUpdate(bool enable) override { m_bUpdates = enable; };
  107. CGameEngine* GetGameEngine() override { return m_pGameEngine; };
  108. CDisplaySettings* GetDisplaySettings() override { return m_pDisplaySettings; };
  109. CBaseObject* NewObject(const char* typeName, const char* fileName = "", const char* name = "", float x = 0.0f, float y = 0.0f, float z = 0.0f, bool modifyDoc = true) override;
  110. void DeleteObject(CBaseObject* obj) override;
  111. IObjectManager* GetObjectManager() override;
  112. // This will return a null pointer if CrySystem is not loaded before
  113. // Global Sandbox Settings are loaded from the registry before CrySystem
  114. // At that stage GetSettingsManager will return null and xml node in
  115. // memory will not be populated with Sandbox Settings.
  116. // After m_IEditor is created and CrySystem loaded, it is possible
  117. // to feed memory node with all necessary data needed for export
  118. // (gSettings.Load() and CXTPDockingPaneManager/CXTPDockingPaneLayout Sandbox layout management)
  119. CSettingsManager* GetSettingsManager() override;
  120. CSelectionGroup* GetSelection() override;
  121. int ClearSelection() override;
  122. CBaseObject* GetSelectedObject() override;
  123. void SelectObject(CBaseObject* obj) override;
  124. void LockSelection(bool bLock) override;
  125. bool IsSelectionLocked() override;
  126. CMusicManager* GetMusicManager() override { return m_pMusicManager; };
  127. IEditorFileMonitor* GetFileMonitor() override;
  128. float GetTerrainElevation(float x, float y) override;
  129. Editor::EditorQtApplication* GetEditorQtApplication() override { return m_QtApplication; }
  130. const QColor& GetColorByName(const QString& name) override;
  131. //////////////////////////////////////////////////////////////////////////
  132. IMovieSystem* GetMovieSystem() override
  133. {
  134. if (m_pSystem)
  135. {
  136. return m_pSystem->GetIMovieSystem();
  137. }
  138. return nullptr;
  139. };
  140. CPluginManager* GetPluginManager() override { return m_pPluginManager; }
  141. CViewManager* GetViewManager() override;
  142. CViewport* GetActiveView() override;
  143. void SetActiveView(CViewport* viewport) override;
  144. CLevelIndependentFileMan* GetLevelIndependentFileMan() override { return m_pLevelIndependentFileMan; }
  145. void UpdateViews(int flags, const AABB* updateRegion) override;
  146. void ResetViews() override;
  147. void ReloadTrackView() override;
  148. Vec3 GetMarkerPosition() override { return m_marker; };
  149. void SetMarkerPosition(const Vec3& pos) override { m_marker = pos; };
  150. void SetSelectedRegion(const AABB& box) override;
  151. void GetSelectedRegion(AABB& box) override;
  152. bool AddToolbarItem(uint8 iId, IUIEvent* pIHandler);
  153. void SetDataModified() override;
  154. void SetOperationMode(EOperationMode mode) override;
  155. EOperationMode GetOperationMode() override;
  156. void SetAxisConstraints(AxisConstrains axis) override;
  157. AxisConstrains GetAxisConstrains() override;
  158. void SetAxisVectorLock(bool bAxisVectorLock) override { m_bAxisVectorLock = bAxisVectorLock; }
  159. bool IsAxisVectorLocked() override { return m_bAxisVectorLock; }
  160. void SetTerrainAxisIgnoreObjects(bool bIgnore) override;
  161. bool IsTerrainAxisIgnoreObjects() override;
  162. void SetReferenceCoordSys(RefCoordSys refCoords) override;
  163. RefCoordSys GetReferenceCoordSys() override;
  164. XmlNodeRef FindTemplate(const QString& templateName) override;
  165. void AddTemplate(const QString& templateName, XmlNodeRef& tmpl) override;
  166. const QtViewPane* OpenView(QString sViewClassName, bool reuseOpened = true) override;
  167. /**
  168. * Returns the top level widget which is showing the view pane with the specified name.
  169. * To access the child widget which actually implements the view pane use this instead:
  170. * QtViewPaneManager::FindViewPane<MyDialog>(name);
  171. */
  172. QWidget* FindView(QString viewClassName) override;
  173. bool CloseView(const char* sViewClassName) override;
  174. bool SetViewFocus(const char* sViewClassName) override;
  175. // close ALL panels related to classId, used when unloading plugins.
  176. void CloseView(const GUID& classId) override;
  177. bool SelectColor(QColor &color, QWidget *parent = 0) override;
  178. void Update();
  179. SFileVersion GetFileVersion() override { return m_fileVersion; };
  180. SFileVersion GetProductVersion() override { return m_productVersion; };
  181. //! Get shader enumerator.
  182. CUndoManager* GetUndoManager() override { return m_pUndoManager; };
  183. void BeginUndo() override;
  184. void RestoreUndo(bool undo) override;
  185. void AcceptUndo(const QString& name) override;
  186. void CancelUndo() override;
  187. void SuperBeginUndo() override;
  188. void SuperAcceptUndo(const QString& name) override;
  189. void SuperCancelUndo() override;
  190. void SuspendUndo() override;
  191. void ResumeUndo() override;
  192. void Undo() override;
  193. void Redo() override;
  194. bool IsUndoRecording() override;
  195. bool IsUndoSuspended() override;
  196. void RecordUndo(IUndoObject* obj) override;
  197. bool FlushUndo(bool isShowMessage = false) override;
  198. bool ClearLastUndoSteps(int steps) override;
  199. bool ClearRedoStack() override;
  200. //! Retrieve current animation context.
  201. CAnimationContext* GetAnimation() override;
  202. CTrackViewSequenceManager* GetSequenceManager() override;
  203. ITrackViewSequenceManager* GetSequenceManagerInterface() override;
  204. CToolBoxManager* GetToolBoxManager() override { return m_pToolBoxManager; };
  205. IErrorReport* GetErrorReport() override { return m_pErrorReport; }
  206. IErrorReport* GetLastLoadedLevelErrorReport() override { return m_pLasLoadedLevelErrorReport; }
  207. void StartLevelErrorReportRecording() override;
  208. void CommitLevelErrorReport() override {SAFE_DELETE(m_pLasLoadedLevelErrorReport); m_pLasLoadedLevelErrorReport = new CErrorReport(*m_pErrorReport); }
  209. IFileUtil* GetFileUtil() override { return m_pFileUtil; }
  210. void Notify(EEditorNotifyEvent event) override;
  211. void NotifyExcept(EEditorNotifyEvent event, IEditorNotifyListener* listener) override;
  212. void RegisterNotifyListener(IEditorNotifyListener* listener) override;
  213. void UnregisterNotifyListener(IEditorNotifyListener* listener) override;
  214. //! Register document notifications listener.
  215. void RegisterDocListener(IDocListener* listener) override;
  216. //! Unregister document notifications listener.
  217. void UnregisterDocListener(IDocListener* listener) override;
  218. //! Retrieve interface to the source control.
  219. ISourceControl* GetSourceControl() override;
  220. //! Retrieve true if source control is provided and enabled in settings
  221. bool IsSourceControlAvailable() override;
  222. //! Only returns true if source control is both available AND currently connected and functioning
  223. bool IsSourceControlConnected() override;
  224. //! Setup Material Editor mode
  225. void SetMatEditMode(bool bIsMatEditMode);
  226. void ReduceMemory() override;
  227. ESystemConfigPlatform GetEditorConfigPlatform() const override;
  228. void ReloadTemplates() override;
  229. void AddErrorMessage(const QString& text, const QString& caption);
  230. void ShowStatusText(bool bEnable) override;
  231. void OnObjectContextMenuOpened(QMenu* pMenu, const CBaseObject* pObject);
  232. void RegisterObjectContextMenuExtension(TContextMenuExtensionFunc func) override;
  233. SSystemGlobalEnvironment* GetEnv() override;
  234. IImageUtil* GetImageUtil() override; // Vladimir@conffx
  235. SEditorSettings* GetEditorSettings() override;
  236. ILogFile* GetLogFile() override { return m_pLogFile; }
  237. void UnloadPlugins() override;
  238. void LoadPlugins() override;
  239. QMimeData* CreateQMimeData() const override;
  240. void DestroyQMimeData(QMimeData* data) const override;
  241. protected:
  242. AZStd::string LoadProjectIdFromProjectData();
  243. void DetectVersion();
  244. void RegisterTools();
  245. void SetPrimaryCDFolder();
  246. //! List of all notify listeners.
  247. std::list<IEditorNotifyListener*> m_listeners;
  248. EOperationMode m_operationMode;
  249. ISystem* m_pSystem;
  250. IFileUtil* m_pFileUtil;
  251. CClassFactory* m_pClassFactory;
  252. CEditorCommandManager* m_pCommandManager;
  253. CObjectManager* m_pObjectManager;
  254. CPluginManager* m_pPluginManager;
  255. CViewManager* m_pViewManager;
  256. CUndoManager* m_pUndoManager;
  257. Vec3 m_marker;
  258. AABB m_selectedRegion;
  259. AxisConstrains m_selectedAxis;
  260. RefCoordSys m_refCoordsSys;
  261. bool m_bAxisVectorLock;
  262. bool m_bUpdates;
  263. bool m_bTerrainAxisIgnoreObjects;
  264. SFileVersion m_fileVersion;
  265. SFileVersion m_productVersion;
  266. CXmlTemplateRegistry m_templateRegistry;
  267. CDisplaySettings* m_pDisplaySettings;
  268. QString m_primaryCDFolder;
  269. QString m_userFolder;
  270. bool m_bSelectionLocked;
  271. CGameEngine* m_pGameEngine;
  272. CAnimationContext* m_pAnimationContext;
  273. CTrackViewSequenceManager* m_pSequenceManager;
  274. CToolBoxManager* m_pToolBoxManager;
  275. CMusicManager* m_pMusicManager;
  276. CErrorReport* m_pErrorReport;
  277. //! Contains the error reports for the last loaded level.
  278. CErrorReport* m_pLasLoadedLevelErrorReport;
  279. //! Global instance of error report class.
  280. CErrorsDlg* m_pErrorsDlg;
  281. //! Source control interface.
  282. ISourceControl* m_pSourceControl;
  283. CSelectionTreeManager* m_pSelectionTreeManager;
  284. //! CConsole Synchronization
  285. CConsoleSynchronization* m_pConsoleSync;
  286. //! Editor Settings Manager
  287. CSettingsManager* m_pSettingsManager;
  288. CLevelIndependentFileMan* m_pLevelIndependentFileMan;
  289. std::unique_ptr<CEditorFileMonitor> m_pEditorFileMonitor;
  290. QString m_selectFileBuffer;
  291. QString m_levelNameBuffer;
  292. //! True if the editor is in material edit mode. Fast preview of materials.
  293. //! In this mode only very limited functionality is available.
  294. bool m_bMatEditMode;
  295. bool m_bShowStatusText;
  296. bool m_bInitialized;
  297. bool m_bExiting;
  298. static void CmdPy(IConsoleCmdArgs* pArgs);
  299. std::vector<TContextMenuExtensionFunc> m_objectContextMenuExtensions;
  300. Editor::EditorQtApplication* const m_QtApplication = nullptr;
  301. // This has to be absolute for the namespace since there is also a class called AssetDatabase that causes issues in unity builds
  302. ::AssetDatabase::AssetDatabaseLocationListener* m_pAssetDatabaseLocationListener;
  303. AzAssetBrowserRequestHandler* m_pAssetBrowserRequestHandler;
  304. AssetEditorRequestsHandler* m_assetEditorRequestsHandler;
  305. IImageUtil* m_pImageUtil; // Vladimir@conffx
  306. ILogFile* m_pLogFile; // Vladimir@conffx
  307. AZStd::mutex m_pluginMutex; // protect any pointers that come from plugins, such as the source control cached pointer.
  308. static const char* m_crashLogFileName;
  309. };