IEditorImpl.cpp 34 KB

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