IEditorImpl.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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 : CEditorImpl class implementation.
  9. #include "EditorDefs.h"
  10. #include "IEditorImpl.h"
  11. #include <EditorCommonAPI.h>
  12. // Qt
  13. #include <QByteArray>
  14. // AzCore
  15. #include <AzCore/IO/Path/Path.h>
  16. #include <AzCore/JSON/document.h>
  17. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  18. #include <AzCore/Utils/Utils.h>
  19. // AzFramework
  20. #include <AzFramework/Terrain/TerrainDataRequestBus.h>
  21. // AzToolsFramework
  22. #include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
  23. #include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
  24. // AzQtComponents
  25. #include <AzQtComponents/Components/Widgets/ColorPicker.h>
  26. #include <AzQtComponents/Utilities/Conversions.h>
  27. // Editor
  28. #include "CryEdit.h"
  29. #include "Dialogs/ErrorsDlg.h"
  30. #include "PluginManager.h"
  31. #include "ViewManager.h"
  32. #include "DisplaySettings.h"
  33. #include "LevelIndependentFileMan.h"
  34. #include "TrackView/TrackViewSequenceManager.h"
  35. #include "AnimationContext.h"
  36. #include "GameEngine.h"
  37. #include "ToolBox.h"
  38. #include "MainWindow.h"
  39. #include "Settings.h"
  40. #include "Include/IObjectManager.h"
  41. #include "Include/ISourceControl.h"
  42. #include "Objects/SelectionGroup.h"
  43. #include "Objects/ObjectManager.h"
  44. #include "EditorFileMonitor.h"
  45. #include "MainStatusBar.h"
  46. #include "Util/FileUtil_impl.h"
  47. #include "Util/ImageUtil_impl.h"
  48. #include "LogFileImpl.h"
  49. #include "Editor/AssetDatabase/AssetDatabaseLocationListener.h"
  50. #include "Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h"
  51. #include "Editor/AssetEditor/AssetEditorRequestsHandler.h"
  52. #include "Core/QtEditorApplication.h" // for Editor::EditorQtApplication
  53. static CCryEditDoc * theDocument;
  54. #include <QMimeData>
  55. #include <QMessageBox>
  56. #include <QProcess>
  57. #if defined(EXTERNAL_CRASH_REPORTING)
  58. #include <ToolsCrashHandler.h>
  59. #endif
  60. #ifndef VERIFY
  61. #define VERIFY(EXPRESSION) { auto e = EXPRESSION; assert(e); }
  62. #endif
  63. const char* CEditorImpl::m_crashLogFileName = "SessionStatus/editor_statuses.json";
  64. CEditorImpl::CEditorImpl()
  65. : m_operationMode(eOperationModeNone)
  66. , m_pSystem(nullptr)
  67. , m_pFileUtil(nullptr)
  68. , m_pClassFactory(nullptr)
  69. , m_pCommandManager(nullptr)
  70. , m_pObjectManager(nullptr)
  71. , m_pPluginManager(nullptr)
  72. , m_pViewManager(nullptr)
  73. , m_pUndoManager(nullptr)
  74. , m_marker(0, 0, 0)
  75. , m_selectedAxis(AXIS_TERRAIN)
  76. , m_refCoordsSys(COORDS_LOCAL)
  77. , m_bAxisVectorLock(false)
  78. , m_bUpdates(true)
  79. , m_bTerrainAxisIgnoreObjects(false)
  80. , m_pDisplaySettings(nullptr)
  81. , m_bSelectionLocked(true)
  82. , m_pGameEngine(nullptr)
  83. , m_pAnimationContext(nullptr)
  84. , m_pSequenceManager(nullptr)
  85. , m_pToolBoxManager(nullptr)
  86. , m_pMusicManager(nullptr)
  87. , m_pErrorReport(nullptr)
  88. , m_pLasLoadedLevelErrorReport(nullptr)
  89. , m_pErrorsDlg(nullptr)
  90. , m_pSourceControl(nullptr)
  91. , m_pSelectionTreeManager(nullptr)
  92. , m_pConsoleSync(nullptr)
  93. , m_pSettingsManager(nullptr)
  94. , m_pLevelIndependentFileMan(nullptr)
  95. , m_bMatEditMode(false)
  96. , m_bShowStatusText(true)
  97. , m_bInitialized(false)
  98. , m_bExiting(false)
  99. , m_QtApplication(static_cast<Editor::EditorQtApplication*>(qApp))
  100. , m_pImageUtil(nullptr)
  101. , m_pLogFile(nullptr)
  102. {
  103. // note that this is a call into EditorCore.dll, which stores the g_pEditorPointer for all shared modules that share EditorCore.dll
  104. // this means that they don't need to do SetIEditor(...) themselves and its available immediately
  105. SetIEditor(this);
  106. m_pFileUtil = new CFileUtil_impl();
  107. m_pLogFile = new CLogFileImpl();
  108. m_pLevelIndependentFileMan = new CLevelIndependentFileMan;
  109. SetPrimaryCDFolder();
  110. gSettings.Load();
  111. m_pErrorReport = new CErrorReport;
  112. m_pClassFactory = CClassFactory::Instance();
  113. m_pCommandManager = new CEditorCommandManager;
  114. m_pEditorFileMonitor.reset(new CEditorFileMonitor());
  115. m_pDisplaySettings = new CDisplaySettings;
  116. m_pDisplaySettings->LoadRegistry();
  117. m_pPluginManager = new CPluginManager;
  118. m_pObjectManager = new CObjectManager;
  119. m_pViewManager = new CViewManager;
  120. m_pUndoManager = new CUndoManager;
  121. m_pToolBoxManager = new CToolBoxManager;
  122. m_pSequenceManager = new CTrackViewSequenceManager;
  123. m_pAnimationContext = new CAnimationContext;
  124. m_pImageUtil = new CImageUtil_impl();
  125. m_selectedRegion.min = Vec3(0, 0, 0);
  126. m_selectedRegion.max = Vec3(0, 0, 0);
  127. DetectVersion();
  128. RegisterTools();
  129. m_pAssetDatabaseLocationListener = nullptr;
  130. m_pAssetBrowserRequestHandler = nullptr;
  131. m_assetEditorRequestsHandler = nullptr;
  132. if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  133. {
  134. if (AZ::IO::FixedMaxPath crashLogPath; settingsRegistry->Get(crashLogPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_ProjectUserPath))
  135. {
  136. crashLogPath /= m_crashLogFileName;
  137. AZ::IO::SystemFile::CreateDir(crashLogPath.ParentPath().FixedMaxPathString().c_str());
  138. QFile::setPermissions(crashLogPath.c_str(), QFileDevice::ReadOther | QFileDevice::WriteOther);
  139. }
  140. }
  141. }
  142. void CEditorImpl::Initialize()
  143. {
  144. #if defined(EXTERNAL_CRASH_REPORTING)
  145. CrashHandler::ToolsCrashHandler::InitCrashHandler("Editor", {});
  146. #endif
  147. // Must be set before QApplication is initialized, so that we support HighDpi monitors, like the Retina displays
  148. // on Windows 10
  149. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  150. QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
  151. // Prevents (native) sibling widgets from causing problems with docked QOpenGLWidgets on Windows
  152. // The problem is due to native widgets ending up with pixel formats that are incompatible with the GL pixel format
  153. // (generally due to a lack of an alpha channel). This blocks the creation of a shared GL context.
  154. // And on macOS it prevents all kinds of bugs related to native widgets, specially regarding toolbars (duplicate toolbars, artifacts, crashes).
  155. QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  156. // Activate QT immediately so that its available as soon as CEditorImpl is (and thus GetIEditor())
  157. InitializeEditorCommon(GetIEditor());
  158. }
  159. //The only purpose of that function is to be called at the very begining of the shutdown sequence so that we can instrument and track
  160. //how many crashes occur while shutting down
  161. void CEditorImpl::OnBeginShutdownSequence()
  162. {
  163. }
  164. void CEditorImpl::OnEarlyExitShutdownSequence()
  165. {
  166. }
  167. void CEditorImpl::Uninitialize()
  168. {
  169. if (m_pSystem)
  170. {
  171. UninitializeEditorCommonISystem(m_pSystem);
  172. }
  173. UninitializeEditorCommon();
  174. }
  175. void CEditorImpl::UnloadPlugins()
  176. {
  177. AZStd::scoped_lock lock(m_pluginMutex);
  178. // Flush core buses. We're about to unload DLLs and need to ensure we don't have module-owned functions left behind.
  179. AZ::Data::AssetBus::ExecuteQueuedEvents();
  180. AZ::TickBus::ExecuteQueuedEvents();
  181. // first, stop anyone from accessing plugins that provide things like source control.
  182. // note that m_psSourceControl is re-queried
  183. m_pSourceControl = nullptr;
  184. // Send this message to ensure that any widgets queued for deletion will get deleted before their
  185. // plugin containing their vtable is unloaded. If not, access violations can occur
  186. QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete);
  187. GetPluginManager()->ReleaseAllPlugins();
  188. GetPluginManager()->UnloadAllPlugins();
  189. }
  190. void CEditorImpl::LoadPlugins()
  191. {
  192. AZStd::scoped_lock lock(m_pluginMutex);
  193. static const QString editor_plugins_folder("EditorPlugins");
  194. // Build, verify, and set the engine root's editor plugin folder
  195. QString editorPluginPathStr;
  196. AZStd::string_view exeFolder;
  197. AZ::ComponentApplicationBus::BroadcastResult(exeFolder, &AZ::ComponentApplicationRequests::GetExecutableFolder);
  198. QDir testDir;
  199. testDir.setPath(AZStd::string(exeFolder).c_str());
  200. if (testDir.exists() && testDir.cd(editor_plugins_folder))
  201. {
  202. editorPluginPathStr = testDir.absolutePath();
  203. }
  204. // If no editor plugin path was found based on the root engine path, then fallback to the current editor.exe path
  205. if (editorPluginPathStr.isEmpty())
  206. {
  207. editorPluginPathStr = QString("%1/%2").arg(qApp->applicationDirPath(), editor_plugins_folder);
  208. }
  209. QString pluginSearchPath = QDir::toNativeSeparators(QString("%1/*" AZ_DYNAMIC_LIBRARY_EXTENSION).arg(editorPluginPathStr));
  210. GetPluginManager()->LoadPlugins(pluginSearchPath.toUtf8().data());
  211. }
  212. CEditorImpl::~CEditorImpl()
  213. {
  214. gSettings.Save();
  215. m_bExiting = true; // Can't save level after this point (while Crash)
  216. SAFE_RELEASE(m_pSourceControl);
  217. SAFE_DELETE(m_pViewManager)
  218. SAFE_DELETE(m_pObjectManager) // relies on prefab manager
  219. SAFE_DELETE(m_pPluginManager)
  220. SAFE_DELETE(m_pAnimationContext) // relies on undo manager
  221. SAFE_DELETE(m_pUndoManager)
  222. if (m_pDisplaySettings)
  223. {
  224. m_pDisplaySettings->SaveRegistry();
  225. }
  226. SAFE_DELETE(m_pDisplaySettings)
  227. SAFE_DELETE(m_pToolBoxManager)
  228. SAFE_DELETE(m_pCommandManager)
  229. SAFE_DELETE(m_pClassFactory)
  230. SAFE_DELETE(m_pLasLoadedLevelErrorReport)
  231. SAFE_DELETE(m_pSettingsManager);
  232. SAFE_DELETE(m_pAssetDatabaseLocationListener);
  233. SAFE_DELETE(m_pAssetBrowserRequestHandler);
  234. SAFE_DELETE(m_assetEditorRequestsHandler);
  235. // Game engine should be among the last things to be destroyed, as it
  236. // destroys the engine.
  237. SAFE_DELETE(m_pErrorsDlg);
  238. SAFE_DELETE(m_pLevelIndependentFileMan);
  239. SAFE_DELETE(m_pGameEngine);
  240. // The error report must be destroyed after the game, as the engine
  241. // refers to the error report and the game destroys the engine.
  242. SAFE_DELETE(m_pErrorReport);
  243. SAFE_DELETE(m_pFileUtil); // Vladimir@Conffx
  244. SAFE_DELETE(m_pImageUtil); // Vladimir@Conffx
  245. SAFE_DELETE(m_pLogFile); // Vladimir@Conffx
  246. }
  247. void CEditorImpl::SetPrimaryCDFolder()
  248. {
  249. QString szFolder = qApp->applicationDirPath();
  250. QDir::setCurrent(szFolder);
  251. }
  252. void CEditorImpl::SetGameEngine(CGameEngine* ge)
  253. {
  254. m_pAssetDatabaseLocationListener = new AssetDatabase::AssetDatabaseLocationListener();
  255. m_pAssetBrowserRequestHandler = new AzAssetBrowserRequestHandler();
  256. m_assetEditorRequestsHandler = aznew AssetEditorRequestsHandler();
  257. m_pSystem = ge->GetSystem();
  258. m_pGameEngine = ge;
  259. InitializeEditorCommonISystem(m_pSystem);
  260. m_templateRegistry.LoadTemplates("Editor");
  261. m_pObjectManager->LoadClassTemplates("Editor");
  262. m_pObjectManager->RegisterCVars();
  263. m_pAnimationContext->Init();
  264. }
  265. void CEditorImpl::RegisterTools()
  266. {
  267. }
  268. void CEditorImpl::ExecuteCommand(const char* sCommand, ...)
  269. {
  270. va_list args;
  271. va_start(args, sCommand);
  272. ExecuteCommand(QString::asprintf(sCommand, args));
  273. va_end(args);
  274. }
  275. void CEditorImpl::ExecuteCommand(const QString& command)
  276. {
  277. m_pCommandManager->Execute(command.toUtf8().data());
  278. }
  279. void CEditorImpl::Update()
  280. {
  281. if (!m_bUpdates)
  282. {
  283. return;
  284. }
  285. // Make sure this is not called recursively
  286. m_bUpdates = false;
  287. if (IsInPreviewMode())
  288. {
  289. SetModifiedFlag(false);
  290. SetModifiedModule(eModifiedNothing);
  291. }
  292. m_bUpdates = true;
  293. }
  294. ISystem* CEditorImpl::GetSystem()
  295. {
  296. return m_pSystem;
  297. }
  298. IEditorClassFactory* CEditorImpl::GetClassFactory()
  299. {
  300. return m_pClassFactory;
  301. }
  302. CCryEditDoc* CEditorImpl::GetDocument() const
  303. {
  304. return theDocument;
  305. }
  306. bool CEditorImpl::IsLevelLoaded() const
  307. {
  308. return GetDocument() && GetDocument()->IsDocumentReady();
  309. }
  310. void CEditorImpl::SetDocument(CCryEditDoc* pDoc)
  311. {
  312. theDocument = pDoc;
  313. }
  314. void CEditorImpl::SetModifiedFlag(bool modified)
  315. {
  316. if (GetDocument() && GetDocument()->IsDocumentReady())
  317. {
  318. GetDocument()->SetModifiedFlag(modified);
  319. if (modified)
  320. {
  321. GetDocument()->SetLevelExported(false);
  322. }
  323. }
  324. }
  325. void CEditorImpl::SetModifiedModule(EModifiedModule eModifiedModule, bool boSet)
  326. {
  327. if (GetDocument())
  328. {
  329. GetDocument()->SetModifiedModules(eModifiedModule, boSet);
  330. }
  331. }
  332. bool CEditorImpl::IsLevelExported() const
  333. {
  334. CCryEditDoc* pDoc = GetDocument();
  335. if (pDoc)
  336. {
  337. return pDoc->IsLevelExported();
  338. }
  339. return false;
  340. }
  341. bool CEditorImpl::SetLevelExported(bool boExported)
  342. {
  343. if (GetDocument())
  344. {
  345. GetDocument()->SetLevelExported(boExported);
  346. return true;
  347. }
  348. return false;
  349. }
  350. bool CEditorImpl::IsModified()
  351. {
  352. if (GetDocument())
  353. {
  354. return GetDocument()->IsModified();
  355. }
  356. return false;
  357. }
  358. bool CEditorImpl::SaveDocument()
  359. {
  360. if (m_bExiting)
  361. {
  362. return false;
  363. }
  364. if (GetDocument())
  365. {
  366. return GetDocument()->Save();
  367. }
  368. else
  369. {
  370. return false;
  371. }
  372. }
  373. QString CEditorImpl::GetPrimaryCDFolder()
  374. {
  375. return m_primaryCDFolder;
  376. }
  377. QString CEditorImpl::GetLevelFolder()
  378. {
  379. return GetGameEngine()->GetLevelPath();
  380. }
  381. QString CEditorImpl::GetLevelName()
  382. {
  383. m_levelNameBuffer = GetGameEngine()->GetLevelName();
  384. return m_levelNameBuffer;
  385. }
  386. QString CEditorImpl::GetLevelDataFolder()
  387. {
  388. return Path::AddPathSlash(Path::AddPathSlash(GetGameEngine()->GetLevelPath()) + "LevelData");
  389. }
  390. QString CEditorImpl::GetSearchPath(EEditorPathName path)
  391. {
  392. return gSettings.searchPaths[path][0];
  393. }
  394. QString CEditorImpl::GetResolvedUserFolder()
  395. {
  396. m_userFolder = Path::GetResolvedUserSandboxFolder();
  397. return m_userFolder;
  398. }
  399. void CEditorImpl::SetDataModified()
  400. {
  401. GetDocument()->SetModifiedFlag(true);
  402. }
  403. void CEditorImpl::SetStatusText(const QString& pszString)
  404. {
  405. if (m_bShowStatusText && !m_bMatEditMode && GetMainStatusBar())
  406. {
  407. GetMainStatusBar()->SetStatusText(pszString);
  408. }
  409. }
  410. IMainStatusBar* CEditorImpl::GetMainStatusBar()
  411. {
  412. return MainWindow::instance()->StatusBar();
  413. }
  414. void CEditorImpl::SetOperationMode(EOperationMode mode)
  415. {
  416. m_operationMode = mode;
  417. gSettings.operationMode = mode;
  418. }
  419. EOperationMode CEditorImpl::GetOperationMode()
  420. {
  421. return m_operationMode;
  422. }
  423. void CEditorImpl::SetAxisConstraints(AxisConstrains axisFlags)
  424. {
  425. m_selectedAxis = axisFlags;
  426. m_pViewManager->SetAxisConstrain(axisFlags);
  427. SetTerrainAxisIgnoreObjects(false);
  428. // Update all views.
  429. UpdateViews(eUpdateObjects, nullptr);
  430. }
  431. AxisConstrains CEditorImpl::GetAxisConstrains()
  432. {
  433. return m_selectedAxis;
  434. }
  435. void CEditorImpl::SetTerrainAxisIgnoreObjects(bool bIgnore)
  436. {
  437. m_bTerrainAxisIgnoreObjects = bIgnore;
  438. }
  439. bool CEditorImpl::IsTerrainAxisIgnoreObjects()
  440. {
  441. return m_bTerrainAxisIgnoreObjects;
  442. }
  443. void CEditorImpl::SetReferenceCoordSys(RefCoordSys refCoords)
  444. {
  445. m_refCoordsSys = refCoords;
  446. // Update all views.
  447. UpdateViews(eUpdateObjects, nullptr);
  448. // Update the construction plane infos.
  449. CViewport* pViewport = GetActiveView();
  450. if (pViewport)
  451. {
  452. pViewport->MakeConstructionPlane(GetIEditor()->GetAxisConstrains());
  453. }
  454. Notify(eNotify_OnRefCoordSysChange);
  455. }
  456. RefCoordSys CEditorImpl::GetReferenceCoordSys()
  457. {
  458. return m_refCoordsSys;
  459. }
  460. CBaseObject* CEditorImpl::NewObject(const char* typeName, const char* fileName, const char* name, float x, float y, float z, bool modifyDoc)
  461. {
  462. CUndo undo("Create new object");
  463. IEditor* editor = GetIEditor();
  464. if (modifyDoc)
  465. {
  466. editor->SetModifiedFlag();
  467. editor->SetModifiedModule(eModifiedBrushes);
  468. }
  469. CBaseObject* object = editor->GetObjectManager()->NewObject(typeName, nullptr, fileName, name);
  470. if (!object)
  471. {
  472. return nullptr;
  473. }
  474. object->SetPos(Vec3(x, y, z));
  475. return object;
  476. }
  477. //////////////////////////////////////////////////////////////////////////
  478. void CEditorImpl::DeleteObject(CBaseObject* obj)
  479. {
  480. SetModifiedFlag();
  481. GetIEditor()->SetModifiedModule(eModifiedBrushes);
  482. GetObjectManager()->DeleteObject(obj);
  483. }
  484. CBaseObject* CEditorImpl::GetSelectedObject()
  485. {
  486. if (m_pObjectManager->GetSelection()->GetCount() != 1)
  487. {
  488. return nullptr;
  489. }
  490. return m_pObjectManager->GetSelection()->GetObject(0);
  491. }
  492. void CEditorImpl::SelectObject(CBaseObject* obj)
  493. {
  494. GetObjectManager()->SelectObject(obj);
  495. }
  496. IObjectManager* CEditorImpl::GetObjectManager()
  497. {
  498. return m_pObjectManager;
  499. };
  500. CSettingsManager* CEditorImpl::GetSettingsManager()
  501. {
  502. // Do not go any further before XML class is ready to use
  503. if (!gEnv)
  504. {
  505. return nullptr;
  506. }
  507. if (!GetISystem())
  508. {
  509. return nullptr;
  510. }
  511. if (!m_pSettingsManager)
  512. {
  513. m_pSettingsManager = new CSettingsManager(eSettingsManagerMemoryStorage);
  514. }
  515. return m_pSettingsManager;
  516. }
  517. CSelectionGroup* CEditorImpl::GetSelection()
  518. {
  519. return m_pObjectManager->GetSelection();
  520. }
  521. int CEditorImpl::ClearSelection()
  522. {
  523. if (GetSelection()->IsEmpty())
  524. {
  525. return 0;
  526. }
  527. CUndo undo("Clear Selection");
  528. return GetObjectManager()->ClearSelection();
  529. }
  530. void CEditorImpl::LockSelection(bool bLock)
  531. {
  532. // Selection must be not empty to enable selection lock.
  533. if (!GetSelection()->IsEmpty())
  534. {
  535. m_bSelectionLocked = bLock;
  536. }
  537. else
  538. {
  539. m_bSelectionLocked = false;
  540. }
  541. }
  542. bool CEditorImpl::IsSelectionLocked()
  543. {
  544. return m_bSelectionLocked;
  545. }
  546. CViewManager* CEditorImpl::GetViewManager()
  547. {
  548. return m_pViewManager;
  549. }
  550. CViewport* CEditorImpl::GetActiveView()
  551. {
  552. MainWindow* mainWindow = MainWindow::instance();
  553. if (mainWindow)
  554. {
  555. CLayoutViewPane* viewPane = mainWindow->GetActiveView();
  556. if (viewPane)
  557. {
  558. return qobject_cast<QtViewport*>(viewPane->GetViewport());
  559. }
  560. }
  561. return nullptr;
  562. }
  563. void CEditorImpl::SetActiveView(CViewport* viewport)
  564. {
  565. m_pViewManager->SelectViewport(viewport);
  566. }
  567. void CEditorImpl::UpdateViews(int flags, const AABB* updateRegion)
  568. {
  569. AABB prevRegion = m_pViewManager->GetUpdateRegion();
  570. if (updateRegion)
  571. {
  572. m_pViewManager->SetUpdateRegion(*updateRegion);
  573. }
  574. m_pViewManager->UpdateViews(flags);
  575. if (updateRegion)
  576. {
  577. m_pViewManager->SetUpdateRegion(prevRegion);
  578. }
  579. }
  580. void CEditorImpl::ReloadTrackView()
  581. {
  582. Notify(eNotify_OnReloadTrackView);
  583. }
  584. void CEditorImpl::ResetViews()
  585. {
  586. m_pViewManager->ResetViews();
  587. m_pDisplaySettings->SetRenderFlags(m_pDisplaySettings->GetRenderFlags());
  588. }
  589. IEditorFileMonitor* CEditorImpl::GetFileMonitor()
  590. {
  591. return m_pEditorFileMonitor.get();
  592. }
  593. float CEditorImpl::GetTerrainElevation(float x, float y)
  594. {
  595. float terrainElevation = AzFramework::Terrain::TerrainDataRequests::GetDefaultTerrainHeight();
  596. AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(terrainElevation
  597. , &AzFramework::Terrain::TerrainDataRequests::GetHeightFromFloats, x, y,
  598. AzFramework::Terrain::TerrainDataRequests::Sampler::BILINEAR, nullptr);
  599. return terrainElevation;
  600. }
  601. const QColor& CEditorImpl::GetColorByName(const QString& name)
  602. {
  603. return m_QtApplication->GetColorByName(name);
  604. }
  605. void CEditorImpl::SetSelectedRegion(const AABB& box)
  606. {
  607. m_selectedRegion = box;
  608. }
  609. void CEditorImpl::GetSelectedRegion(AABB& box)
  610. {
  611. box = m_selectedRegion;
  612. }
  613. const QtViewPane* CEditorImpl::OpenView(QString sViewClassName, bool reuseOpened)
  614. {
  615. auto openMode = reuseOpened ? QtViewPane::OpenMode::None : QtViewPane::OpenMode::MultiplePanes;
  616. return QtViewPaneManager::instance()->OpenPane(sViewClassName, openMode);
  617. }
  618. QWidget* CEditorImpl::FindView(QString viewClassName)
  619. {
  620. return QtViewPaneManager::instance()->GetView(viewClassName);
  621. }
  622. // Intended to give a window focus only if it is currently open
  623. bool CEditorImpl::SetViewFocus(const char* sViewClassName)
  624. {
  625. QWidget* findWindow = FindView(sViewClassName);
  626. if (findWindow)
  627. {
  628. findWindow->setFocus(Qt::OtherFocusReason);
  629. return true;
  630. }
  631. return false;
  632. }
  633. bool CEditorImpl::CloseView(const char* sViewClassName)
  634. {
  635. return QtViewPaneManager::instance()->ClosePane(sViewClassName);
  636. }
  637. void CEditorImpl::CloseView(const GUID& classId)
  638. {
  639. IClassDesc* found = GetClassFactory()->FindClass(classId);
  640. if (found)
  641. {
  642. CloseView(found->ClassName().toUtf8().data());
  643. }
  644. }
  645. bool CEditorImpl::SelectColor(QColor& color, QWidget* parent)
  646. {
  647. const AZ::Color c = AzQtComponents::fromQColor(color);
  648. AzQtComponents::ColorPicker dlg(AzQtComponents::ColorPicker::Configuration::RGB, tr("Select Color"), parent);
  649. dlg.setCurrentColor(c);
  650. dlg.setSelectedColor(c);
  651. if (dlg.exec() == QDialog::Accepted)
  652. {
  653. color = AzQtComponents::toQColor(dlg.currentColor());
  654. return true;
  655. }
  656. return false;
  657. }
  658. void CEditorImpl::SetInGameMode(bool inGame)
  659. {
  660. if (IsInSimulationMode())
  661. {
  662. return;
  663. }
  664. if (m_pGameEngine)
  665. {
  666. m_pGameEngine->RequestSetGameMode(inGame);
  667. }
  668. }
  669. bool CEditorImpl::IsInGameMode()
  670. {
  671. if (m_pGameEngine)
  672. {
  673. return m_pGameEngine->IsInGameMode();
  674. }
  675. return false;
  676. }
  677. bool CEditorImpl::IsInSimulationMode()
  678. {
  679. if (m_pGameEngine)
  680. {
  681. return m_pGameEngine->GetSimulationMode();
  682. }
  683. return false;
  684. }
  685. bool CEditorImpl::IsInTestMode()
  686. {
  687. return CCryEditApp::instance()->IsInTestMode();
  688. }
  689. bool CEditorImpl::IsInConsolewMode()
  690. {
  691. return CCryEditApp::instance()->IsInConsoleMode();
  692. }
  693. bool CEditorImpl::IsInLevelLoadTestMode()
  694. {
  695. return CCryEditApp::instance()->IsInLevelLoadTestMode();
  696. }
  697. bool CEditorImpl::IsInPreviewMode()
  698. {
  699. return CCryEditApp::instance()->IsInPreviewMode();
  700. }
  701. static AZStd::string SafeGetStringFromDocument(rapidjson::Document& projectCfg, const char* memberName)
  702. {
  703. if (projectCfg.HasMember(memberName) && projectCfg[memberName].IsString())
  704. {
  705. return projectCfg[memberName].GetString();
  706. }
  707. return "";
  708. }
  709. AZStd::string CEditorImpl::LoadProjectIdFromProjectData()
  710. {
  711. const char* MissingProjectId = "";
  712. // get the full path of the project.json
  713. AZStd::string fullPath;
  714. AZStd::string relPath("project.json");
  715. bool fullPathFound = false;
  716. using namespace AzToolsFramework;
  717. AssetSystemRequestBus::BroadcastResult(fullPathFound, &AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relPath, fullPath);
  718. if (!fullPathFound)
  719. {
  720. return MissingProjectId;
  721. }
  722. QFile file(fullPath.c_str());
  723. if (!file.open(QIODevice::ReadOnly))
  724. {
  725. return MissingProjectId;
  726. }
  727. // Read the project.json file using its full path
  728. QByteArray fileContents = file.readAll();
  729. file.close();
  730. rapidjson::Document projectCfg;
  731. projectCfg.Parse(fileContents);
  732. if (!projectCfg.IsObject())
  733. {
  734. return MissingProjectId;
  735. }
  736. AZStd::string projectId = SafeGetStringFromDocument(projectCfg, "project_id");
  737. // if we don't have a valid projectId by now, it's not happening
  738. if (projectId.empty() || projectId[0] == '\0')
  739. {
  740. return MissingProjectId;
  741. }
  742. // get the project Id and project name from the project.json file
  743. QString projectName(SafeGetStringFromDocument(projectCfg, "project_name").data());
  744. QFileInfo fileInfo(fullPath.c_str());
  745. QDir folderDirectory = fileInfo.dir();
  746. // get the project name from the folder directory
  747. QString editorProjectName = folderDirectory.dirName();
  748. // if the project name in the file doesn't match the directory name, it probably means that this is
  749. // a copied project, and not safe to put any plain text into the projectId string
  750. if (editorProjectName.compare(projectName, Qt::CaseInsensitive) != 0)
  751. {
  752. return projectId;
  753. }
  754. // get the project Id generated by using the project name from the folder directory
  755. QByteArray editorProjectNameUtf8 = editorProjectName.toUtf8();
  756. AZ::Uuid id = AZ::Uuid::CreateName(editorProjectNameUtf8.constData());
  757. // The projects that Open 3D Engine ships with had their project IDs hand-generated based on the name of the level.
  758. // Therefore, if the UUID from the project name is the same as the UUID in the file, it's one of our projects
  759. // and we can therefore send the name back, making it easier for Metrics to determine which level it was.
  760. // We are checking to see if this is a project we ship with Open 3D Engine, and therefore we can unobfuscate non-customer information.
  761. if (id != AZ::Uuid(projectId.data()))
  762. {
  763. return projectId;
  764. }
  765. QByteArray projectNameUtf8 = projectName.toUtf8();
  766. projectId += " [";
  767. projectId += projectNameUtf8.constData();
  768. projectId += "]";
  769. return projectId;
  770. }
  771. void CEditorImpl::DetectVersion()
  772. {
  773. #if defined(AZ_PLATFORM_WINDOWS)
  774. char exe[_MAX_PATH];
  775. DWORD dwHandle;
  776. UINT len;
  777. wchar_t ver[1024 * 8];
  778. AZ::Utils::GetExecutablePath(exe, _MAX_PATH);
  779. AZStd::wstring exeW;
  780. AZStd::to_wstring(exeW, exe);
  781. int verSize = GetFileVersionInfoSizeW(exeW.c_str(), &dwHandle);
  782. if (verSize > 0)
  783. {
  784. GetFileVersionInfoW(exeW.c_str(), dwHandle, 1024 * 8, ver);
  785. VS_FIXEDFILEINFO* vinfo;
  786. VerQueryValueW(ver, L"\\", (void**)&vinfo, &len);
  787. m_fileVersion.v[0] = vinfo->dwFileVersionLS & 0xFFFF;
  788. m_fileVersion.v[1] = vinfo->dwFileVersionLS >> 16;
  789. m_fileVersion.v[2] = vinfo->dwFileVersionMS & 0xFFFF;
  790. m_fileVersion.v[3] = vinfo->dwFileVersionMS >> 16;
  791. m_productVersion.v[0] = vinfo->dwProductVersionLS & 0xFFFF;
  792. m_productVersion.v[1] = vinfo->dwProductVersionLS >> 16;
  793. m_productVersion.v[2] = vinfo->dwProductVersionMS & 0xFFFF;
  794. m_productVersion.v[3] = vinfo->dwProductVersionMS >> 16;
  795. }
  796. #else
  797. // This requires the application version to be set using QCoreApplication::setApplicationVersion, which isn't done yet.
  798. const QString version = qApp->applicationVersion();
  799. if (!version.isEmpty())
  800. {
  801. QByteArray versionBytes = version.toUtf8();
  802. m_fileVersion.Set(versionBytes.data());
  803. m_productVersion.Set(versionBytes.data());
  804. }
  805. #endif
  806. }
  807. XmlNodeRef CEditorImpl::FindTemplate(const QString& templateName)
  808. {
  809. return m_templateRegistry.FindTemplate(templateName);
  810. }
  811. void CEditorImpl::AddTemplate(const QString& templateName, XmlNodeRef& tmpl)
  812. {
  813. m_templateRegistry.AddTemplate(templateName, tmpl);
  814. }
  815. bool CEditorImpl::ExecuteConsoleApp(const QString& CommandLine, QString& OutputText, [[maybe_unused]] bool bNoTimeOut, bool bShowWindow)
  816. {
  817. CLogFile::FormatLine("Executing console application '%s'", CommandLine.toUtf8().data());
  818. QProcess process;
  819. if (bShowWindow)
  820. {
  821. #if defined(AZ_PLATFORM_WINDOWS)
  822. process.start("cmd.exe", { QString("/C %1").arg(CommandLine) });
  823. #elif defined(AZ_PLATFORM_LINUX)
  824. //KDAB_TODO
  825. #elif defined(AZ_PLATFORM_MAC)
  826. process.start("/usr/bin/osascript", { QString("-e 'tell application \"Terminal\" to do script \"%1\"'").arg(QString(CommandLine).replace("\"", "\\\"")) });
  827. #else
  828. process.start("/usr/bin/csh", { QString("-c \"%1\"'").arg(QString(CommandLine).replace("\"", "\\\"")) } );
  829. #endif
  830. }
  831. else
  832. {
  833. process.start(CommandLine, QStringList());
  834. }
  835. if (!process.waitForStarted())
  836. {
  837. return false;
  838. }
  839. // Wait for the process to finish
  840. process.waitForFinished();
  841. OutputText += process.readAllStandardOutput();
  842. OutputText += process.readAllStandardError();
  843. return true;
  844. }
  845. void CEditorImpl::BeginUndo()
  846. {
  847. if (m_pUndoManager)
  848. {
  849. m_pUndoManager->Begin();
  850. }
  851. }
  852. void CEditorImpl::RestoreUndo(bool undo)
  853. {
  854. if (m_pUndoManager)
  855. {
  856. m_pUndoManager->Restore(undo);
  857. }
  858. }
  859. void CEditorImpl::AcceptUndo(const QString& name)
  860. {
  861. if (m_pUndoManager)
  862. {
  863. m_pUndoManager->Accept(name);
  864. }
  865. }
  866. void CEditorImpl::CancelUndo()
  867. {
  868. if (m_pUndoManager)
  869. {
  870. m_pUndoManager->Cancel();
  871. }
  872. }
  873. void CEditorImpl::SuperBeginUndo()
  874. {
  875. if (m_pUndoManager)
  876. {
  877. m_pUndoManager->SuperBegin();
  878. }
  879. }
  880. void CEditorImpl::SuperAcceptUndo(const QString& name)
  881. {
  882. if (m_pUndoManager)
  883. {
  884. m_pUndoManager->SuperAccept(name);
  885. }
  886. }
  887. void CEditorImpl::SuperCancelUndo()
  888. {
  889. if (m_pUndoManager)
  890. {
  891. m_pUndoManager->SuperCancel();
  892. }
  893. }
  894. void CEditorImpl::SuspendUndo()
  895. {
  896. if (m_pUndoManager)
  897. {
  898. m_pUndoManager->Suspend();
  899. }
  900. }
  901. void CEditorImpl::ResumeUndo()
  902. {
  903. if (m_pUndoManager)
  904. {
  905. m_pUndoManager->Resume();
  906. }
  907. }
  908. void CEditorImpl::Undo()
  909. {
  910. if (m_pUndoManager)
  911. {
  912. m_pUndoManager->Undo();
  913. }
  914. }
  915. void CEditorImpl::Redo()
  916. {
  917. if (m_pUndoManager)
  918. {
  919. m_pUndoManager->Redo();
  920. }
  921. }
  922. bool CEditorImpl::IsUndoRecording()
  923. {
  924. if (m_pUndoManager)
  925. {
  926. return m_pUndoManager->IsUndoRecording();
  927. }
  928. return false;
  929. }
  930. bool CEditorImpl::IsUndoSuspended()
  931. {
  932. if (m_pUndoManager)
  933. {
  934. return m_pUndoManager->IsUndoSuspended();
  935. }
  936. return false;
  937. }
  938. void CEditorImpl::RecordUndo(IUndoObject* obj)
  939. {
  940. if (m_pUndoManager)
  941. {
  942. m_pUndoManager->RecordUndo(obj);
  943. }
  944. }
  945. bool CEditorImpl::FlushUndo(bool isShowMessage)
  946. {
  947. if (isShowMessage && m_pUndoManager && m_pUndoManager->IsHaveUndo() && QMessageBox::question(AzToolsFramework::GetActiveWindow(), QObject::tr("Flush Undo"), QObject::tr("After this operation undo will not be available! Are you sure you want to continue?")) != QMessageBox::Yes)
  948. {
  949. return false;
  950. }
  951. if (m_pUndoManager)
  952. {
  953. m_pUndoManager->Flush();
  954. }
  955. return true;
  956. }
  957. bool CEditorImpl::ClearLastUndoSteps(int steps)
  958. {
  959. if (!m_pUndoManager || !m_pUndoManager->IsHaveUndo())
  960. {
  961. return false;
  962. }
  963. m_pUndoManager->ClearUndoStack(steps);
  964. return true;
  965. }
  966. bool CEditorImpl::ClearRedoStack()
  967. {
  968. if (!m_pUndoManager || !m_pUndoManager->IsHaveRedo())
  969. {
  970. return false;
  971. }
  972. m_pUndoManager->ClearRedoStack();
  973. return true;
  974. }
  975. void CEditorImpl::SetConsoleVar(const char* var, float value)
  976. {
  977. ICVar* ivar = GetSystem()->GetIConsole()->GetCVar(var);
  978. if (ivar)
  979. {
  980. ivar->Set(value);
  981. }
  982. }
  983. float CEditorImpl::GetConsoleVar(const char* var)
  984. {
  985. ICVar* ivar = GetSystem()->GetIConsole()->GetCVar(var);
  986. if (ivar)
  987. {
  988. return ivar->GetFVal();
  989. }
  990. return 0;
  991. }
  992. CAnimationContext* CEditorImpl::GetAnimation()
  993. {
  994. return m_pAnimationContext;
  995. }
  996. CTrackViewSequenceManager* CEditorImpl::GetSequenceManager()
  997. {
  998. return m_pSequenceManager;
  999. }
  1000. ITrackViewSequenceManager* CEditorImpl::GetSequenceManagerInterface()
  1001. {
  1002. return GetSequenceManager();
  1003. }
  1004. void CEditorImpl::RegisterDocListener(IDocListener* listener)
  1005. {
  1006. CCryEditDoc* doc = GetDocument();
  1007. if (doc)
  1008. {
  1009. doc->RegisterListener(listener);
  1010. }
  1011. }
  1012. void CEditorImpl::UnregisterDocListener(IDocListener* listener)
  1013. {
  1014. CCryEditDoc* doc = GetDocument();
  1015. if (doc)
  1016. {
  1017. doc->UnregisterListener(listener);
  1018. }
  1019. }
  1020. void CEditorImpl::StartLevelErrorReportRecording()
  1021. {
  1022. IErrorReport* errorReport = GetErrorReport();
  1023. if (errorReport)
  1024. {
  1025. errorReport->Clear();
  1026. errorReport->SetImmediateMode(false);
  1027. errorReport->SetShowErrors(true);
  1028. }
  1029. }
  1030. // Confetti Start: Leroy Sikkes
  1031. void CEditorImpl::Notify(EEditorNotifyEvent event)
  1032. {
  1033. NotifyExcept(event, nullptr);
  1034. }
  1035. void CEditorImpl::NotifyExcept(EEditorNotifyEvent event, IEditorNotifyListener* listener)
  1036. {
  1037. if (m_bExiting)
  1038. {
  1039. return;
  1040. }
  1041. std::list<IEditorNotifyListener*>::iterator it = m_listeners.begin();
  1042. while (it != m_listeners.end())
  1043. {
  1044. if (*it == listener)
  1045. {
  1046. it++;
  1047. continue; // skip "except" listener
  1048. }
  1049. (*it++)->OnEditorNotifyEvent(event);
  1050. }
  1051. if (event == eNotify_OnInit)
  1052. {
  1053. REGISTER_COMMAND("py", CmdPy, 0, "Execute a Python code snippet.");
  1054. }
  1055. GetPluginManager()->NotifyPlugins(event);
  1056. }
  1057. // Confetti end: Leroy Sikkes
  1058. void CEditorImpl::RegisterNotifyListener(IEditorNotifyListener* listener)
  1059. {
  1060. listener->m_bIsRegistered = true;
  1061. stl::push_back_unique(m_listeners, listener);
  1062. }
  1063. void CEditorImpl::UnregisterNotifyListener(IEditorNotifyListener* listener)
  1064. {
  1065. m_listeners.remove(listener);
  1066. listener->m_bIsRegistered = false;
  1067. }
  1068. ISourceControl* CEditorImpl::GetSourceControl()
  1069. {
  1070. AZStd::scoped_lock lock(m_pluginMutex);
  1071. if (m_pSourceControl)
  1072. {
  1073. return m_pSourceControl;
  1074. }
  1075. IEditorClassFactory* classFactory = GetIEditor() ? GetIEditor()->GetClassFactory() : nullptr;
  1076. if (classFactory)
  1077. {
  1078. std::vector<IClassDesc*> classes;
  1079. classFactory->GetClassesBySystemID(ESYSTEM_CLASS_SCM_PROVIDER, classes);
  1080. for (int i = 0; i < classes.size(); i++)
  1081. {
  1082. IClassDesc* pClass = classes[i];
  1083. ISourceControl* pSCM = nullptr;
  1084. HRESULT hRes = pClass->QueryInterface(__az_uuidof(ISourceControl), (void**)&pSCM);
  1085. if (!FAILED(hRes) && pSCM)
  1086. {
  1087. m_pSourceControl = pSCM;
  1088. return m_pSourceControl;
  1089. }
  1090. }
  1091. }
  1092. return nullptr;
  1093. }
  1094. bool CEditorImpl::IsSourceControlAvailable()
  1095. {
  1096. if ((gSettings.enableSourceControl) && (GetSourceControl()))
  1097. {
  1098. return true;
  1099. }
  1100. return false;
  1101. }
  1102. bool CEditorImpl::IsSourceControlConnected()
  1103. {
  1104. if ((gSettings.enableSourceControl) && (GetSourceControl()) && (GetSourceControl()->GetConnectivityState() == ISourceControl::Connected))
  1105. {
  1106. return true;
  1107. }
  1108. return false;
  1109. }
  1110. void CEditorImpl::SetMatEditMode(bool bIsMatEditMode)
  1111. {
  1112. m_bMatEditMode = bIsMatEditMode;
  1113. }
  1114. void CEditorImpl::ShowStatusText(bool bEnable)
  1115. {
  1116. m_bShowStatusText = bEnable;
  1117. }
  1118. void CEditorImpl::ReduceMemory()
  1119. {
  1120. GetIEditor()->GetUndoManager()->ClearRedoStack();
  1121. GetIEditor()->GetUndoManager()->ClearUndoStack();
  1122. GetIEditor()->GetObjectManager()->SendEvent(EVENT_FREE_GAME_DATA);
  1123. #if defined(AZ_PLATFORM_WINDOWS)
  1124. HANDLE hHeap = GetProcessHeap();
  1125. if (hHeap)
  1126. {
  1127. uint64 maxsize = (uint64)HeapCompact(hHeap, 0);
  1128. CryLogAlways("Max Free Memory Block = %I64d Kb", maxsize / 1024);
  1129. }
  1130. #endif
  1131. }
  1132. ESystemConfigPlatform CEditorImpl::GetEditorConfigPlatform() const
  1133. {
  1134. return m_pSystem->GetConfigPlatform();
  1135. }
  1136. void CEditorImpl::InitFinished()
  1137. {
  1138. if (!m_bInitialized)
  1139. {
  1140. m_bInitialized = true;
  1141. Notify(eNotify_OnInit);
  1142. // Let system wide listeners know about this as well.
  1143. GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_EDITOR_ON_INIT, 0, 0);
  1144. }
  1145. }
  1146. void CEditorImpl::ReloadTemplates()
  1147. {
  1148. m_templateRegistry.LoadTemplates("Editor");
  1149. }
  1150. void CEditorImpl::AddErrorMessage(const QString& text, const QString& caption)
  1151. {
  1152. if (!m_pErrorsDlg)
  1153. {
  1154. m_pErrorsDlg = new CErrorsDlg(GetEditorMainWindow());
  1155. m_pErrorsDlg->show();
  1156. }
  1157. m_pErrorsDlg->AddMessage(text, caption);
  1158. }
  1159. void CEditorImpl::CmdPy(IConsoleCmdArgs* pArgs)
  1160. {
  1161. if (AzToolsFramework::EditorPythonRunnerRequestBus::HasHandlers())
  1162. {
  1163. // Execute the given script command.
  1164. QString scriptCmd = pArgs->GetCommandLine();
  1165. scriptCmd = scriptCmd.right(scriptCmd.length() - 2); // The part of the text after the 'py'
  1166. scriptCmd = scriptCmd.trimmed();
  1167. AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByString, scriptCmd.toUtf8().data(), false);
  1168. }
  1169. else
  1170. {
  1171. AZ_Warning("python", false, "EditorPythonRunnerRequestBus has no handlers");
  1172. }
  1173. }
  1174. void CEditorImpl::OnObjectContextMenuOpened(QMenu* pMenu, const CBaseObject* pObject)
  1175. {
  1176. for (auto it : m_objectContextMenuExtensions)
  1177. {
  1178. it(pMenu, pObject);
  1179. }
  1180. }
  1181. void CEditorImpl::RegisterObjectContextMenuExtension(TContextMenuExtensionFunc func)
  1182. {
  1183. m_objectContextMenuExtensions.push_back(func);
  1184. }
  1185. // Vladimir@Conffx
  1186. SSystemGlobalEnvironment* CEditorImpl::GetEnv()
  1187. {
  1188. assert(gEnv);
  1189. return gEnv;
  1190. }
  1191. // Leroy@Conffx
  1192. SEditorSettings* CEditorImpl::GetEditorSettings()
  1193. {
  1194. return &gSettings;
  1195. }
  1196. IImageUtil* CEditorImpl::GetImageUtil()
  1197. {
  1198. return m_pImageUtil;
  1199. }
  1200. QMimeData* CEditorImpl::CreateQMimeData() const
  1201. {
  1202. return new QMimeData();
  1203. }
  1204. void CEditorImpl::DestroyQMimeData(QMimeData* data) const
  1205. {
  1206. delete data;
  1207. }