ToolsApplicationAPI.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. #pragma once
  9. #include <AzCore/base.h>
  10. #include <AzCore/Debug/Budget.h>
  11. #include <AzCore/EBus/EBus.h>
  12. #include <AzCore/Math/Aabb.h>
  13. #include <AzCore/Math/Uuid.h>
  14. #include <AzCore/Component/Entity.h>
  15. #include <AzCore/Component/EntityId.h>
  16. #include <AzCore/Component/ComponentBus.h>
  17. #include <AzCore/std/containers/vector.h>
  18. #include <AzCore/Slice/SliceComponent.h>
  19. #include <AzCore/Outcome/Outcome.h>
  20. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  21. #include <AzToolsFramework/SourceControl/SourceControlAPI.h>
  22. #include <AzFramework/Entity/EntityContextBus.h>
  23. namespace AZ
  24. {
  25. class Entity;
  26. class Vector2;
  27. class Entity;
  28. }
  29. class QMenu;
  30. class QWidget;
  31. class QApplication;
  32. class QDockWidget;
  33. class QMainWindow;
  34. struct IEditor;
  35. namespace AzToolsFramework
  36. {
  37. struct ViewPaneOptions;
  38. class PreemptiveUndoCache;
  39. class EntityPropertyEditor;
  40. namespace UndoSystem
  41. {
  42. class UndoStack;
  43. class URSequencePoint;
  44. }
  45. namespace AssetBrowser
  46. {
  47. class AssetSelectionModel;
  48. }
  49. using EntityIdList = AZStd::vector<AZ::EntityId>;
  50. using EntityList = AZStd::vector<AZ::Entity*>;
  51. using ClassDataList = AZStd::vector<const AZ::SerializeContext::ClassData*>;
  52. using EntityIdSet = AZStd::unordered_set<AZ::EntityId>;
  53. //! Return true to accept this type of component.
  54. using ComponentFilter = AZStd::function<bool(const AZ::SerializeContext::ClassData&)>;
  55. /**
  56. * Bus owned by the ToolsApplication. Listen for general ToolsApplication events.
  57. */
  58. class ToolsApplicationEvents
  59. : public AZ::EBusTraits
  60. {
  61. public:
  62. using Bus = AZ::EBus<ToolsApplicationEvents>;
  63. /*!
  64. * Fired prior to committing a change in entity selection set.
  65. */
  66. virtual void BeforeEntitySelectionChanged() {}
  67. /*!
  68. * Fired after committing a change in entity selection set.
  69. * \param EntityIdList the list of newly selected entity Ids
  70. * \param EntityIdList the list of newly deselected entity Ids
  71. */
  72. virtual void AfterEntitySelectionChanged(const EntityIdList& /*newlySelectedEntities*/, const EntityIdList& /*newlyDeselectedEntities*/) {}
  73. /*!
  74. * Fired before committing a change in entity highlighting set.
  75. */
  76. virtual void BeforeEntityHighlightingChanged() {}
  77. /*!
  78. * Fired after committing a change in entity highlighting set.
  79. */
  80. virtual void AfterEntityHighlightingChanged() {}
  81. /*!
  82. * Fired when an entity's transform parent has changed.
  83. */
  84. virtual void EntityParentChanged(AZ::EntityId /*entityId*/, AZ::EntityId /*newParentId*/, AZ::EntityId /*oldParentId*/) {}
  85. /*!
  86. * Fired when a given entity has been unregistered from the application.
  87. * \param entityId - The Id of the subject entity.
  88. */
  89. virtual void EntityDeregistered(AZ::EntityId /*entity*/) {}
  90. /*!
  91. * Fired when a given entity has been registered with the application.
  92. * \param entityId - The Id of the subject entity.
  93. */
  94. virtual void EntityRegistered(AZ::EntityId /*entity*/) {}
  95. /*!
  96. * Broadcast when the user has created an entity as a child of another entity.
  97. * This event is broadcast after the entity has been created and activated and
  98. * all relevant transform component information has been set.
  99. * \param entityId - The Id of the new entity
  100. * \param parentId - The Id of the new entity's parent
  101. */
  102. virtual void EntityCreatedAsChild(AZ::EntityId /*entityId*/, AZ::EntityId /*parentId*/) {}
  103. /*!
  104. * Fired just prior to applying a requested undo or redo operation.
  105. */
  106. virtual void BeforeUndoRedo() {}
  107. /*!
  108. * Fired just after applying a requested undo or redo operation.
  109. */
  110. virtual void AfterUndoRedo() {}
  111. /*!
  112. * Fired when a new undo batch has been started.
  113. * \param label - description of the batch.
  114. */
  115. virtual void OnBeginUndo(const char* /*label*/) {}
  116. /*!
  117. * Fired when an undo batch has been ended..
  118. * \param label - description of the batch.
  119. * \param changed - did anything change during the batch
  120. */
  121. virtual void OnEndUndo(const char* /*label*/, bool /*changed*/) {}
  122. /*!
  123. * Notify property UI to refresh the property tree.
  124. */
  125. virtual void InvalidatePropertyDisplay(PropertyModificationRefreshLevel /*level*/) {}
  126. /*!
  127. * Process source control status for the specified file.
  128. */
  129. virtual void GotSceneSourceControlStatus(SourceControlFileInfo& /*fileInfo*/) {}
  130. /*!
  131. * Process scene status.
  132. */
  133. virtual void PerformActionsBasedOnSceneStatus(bool /*sceneIsNew*/, bool /*readOnly*/) {}
  134. /*!
  135. * Highlight the specified asset in the asset browser.
  136. */
  137. virtual void ShowAssetInBrowser(AZStd::string /*assetName*/) {}
  138. /*!
  139. * Event sent when the editor is set to Isolation Mode where only selected entities are visible
  140. */
  141. virtual void OnEnterEditorIsolationMode() {}
  142. /*!
  143. * Event sent when the editor quits Isolation Mode
  144. */
  145. virtual void OnExitEditorIsolationMode() {}
  146. /*!
  147. * Sets the position of the next entity to be instantiated, used by the EditorEntityModel when dragging from asset browser
  148. */
  149. virtual void SetEntityInstantiationPosition(const AZ::EntityId& /*parent*/, const AZ::EntityId& /*beforeEntity*/) {}
  150. /*!
  151. * Clears the position of the next entity to be instantiated, used by the EditorEntityModel if entity instantiation fails
  152. * after SetEntityInstantiationPosition is called. This makes sure entities created after the initial event don't end up with a parent out of
  153. * sync in the outliner and transform component.
  154. */
  155. virtual void ClearEntityInstantiationPosition() {}
  156. /*!
  157. * Called when the level is saved.
  158. */
  159. virtual void OnSaveLevel() {}
  160. };
  161. using ToolsApplicationNotificationBus = AZ::EBus<ToolsApplicationEvents>;
  162. /**
  163. * Bus used to make general requests to the ToolsApplication.
  164. */
  165. class ToolsApplicationRequests
  166. : public AZ::EBusTraits
  167. {
  168. public:
  169. using Bus = AZ::EBus<ToolsApplicationRequests>;
  170. //////////////////////////////////////////////////////////////////////////
  171. // EBusTraits overrides
  172. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  173. //////////////////////////////////////////////////////////////////////////
  174. /*!
  175. * Handles pre-export tasks for an entity, such as generating runtime components on the target.
  176. */
  177. virtual void PreExportEntity(AZ::Entity& /*source*/, AZ::Entity& /*target*/) = 0;
  178. /*!
  179. * Handles post-export tasks for an entity.
  180. */
  181. virtual void PostExportEntity(AZ::Entity& /*source*/, AZ::Entity& /*target*/) = 0;
  182. /*!
  183. * Marks an entity as dirty.
  184. * \param target - The Id of the entity to mark as dirty.
  185. */
  186. virtual void AddDirtyEntity(AZ::EntityId target) = 0;
  187. /*!
  188. * Removes an entity from the dirty entity set.
  189. * \param target - The Id of the entity to remove
  190. * \return 1 if target EntityId was removed successfully, otherwise 0
  191. */
  192. virtual int RemoveDirtyEntity(AZ::EntityId target) = 0;
  193. /*!
  194. * Clears the dirty entity set.
  195. */
  196. virtual void ClearDirtyEntities() = 0;
  197. /*!
  198. * \return true if an undo/redo operation is in progress.
  199. */
  200. virtual bool IsDuringUndoRedo() = 0;
  201. /*!
  202. * Notifies the application the user intends to undo the last undo-able operation.
  203. */
  204. virtual void UndoPressed() = 0;
  205. /*!
  206. * Notifies the application the user intends to reapply the last redo-able operation.
  207. */
  208. virtual void RedoPressed() = 0;
  209. /*!
  210. * Notifies the application that the undo stack needs to be flushed
  211. */
  212. virtual void FlushUndo() = 0;
  213. /*!
  214. * Notifies the application that the redo stack needs to be sliced (removed)
  215. */
  216. virtual void FlushRedo() = 0;
  217. /*!
  218. * Notifies the application that the user intends to select an entity.
  219. * \param entityId - the Id of the newly selected entity.
  220. */
  221. virtual void MarkEntitySelected(AZ::EntityId entityId) = 0;
  222. /*!
  223. * Notifies the application that the user intends to select a list of entities.
  224. * This should be used any time multiple entities are selected, as this is
  225. * a large performance improvement over calling MarkEntitySelected more than once.
  226. * \param entitiesToSelect - the vector of newly selected entities
  227. */
  228. virtual void MarkEntitiesSelected(const EntityIdList& entitiesToSelect) = 0;
  229. /*!
  230. * Notifies the application that the user intends to deselect an entity.
  231. * \param entityId - the Id of the now deselected entity.
  232. */
  233. virtual void MarkEntityDeselected(AZ::EntityId entityId) = 0;
  234. /*!
  235. * Notifies the application that the user intends to deselect a list of entities.
  236. * This should be used any time multiple entities are deselected, as this is
  237. * a large performance improvement over calling MarkEntityDeselected more than once.
  238. * \param entitiesToDeselect - the vector of newly deselected entities
  239. */
  240. virtual void MarkEntitiesDeselected(const EntityIdList& entitiesToDeselect) = 0;
  241. /*!
  242. * Notifies the application that editor has highlighted an entity, or removed
  243. * a highlight. This is used for mouse-hover behavior in Sandbox.
  244. */
  245. virtual void SetEntityHighlighted(AZ::EntityId entityId, bool highlighted) = 0;
  246. /*!
  247. * Starts a new undo batch.
  248. * \param label - description of the operation.
  249. * \return a handle for the new batch, which can be used with ResumeUndoBatch().
  250. */
  251. virtual UndoSystem::URSequencePoint* BeginUndoBatch(const char* label) = 0;
  252. /*!
  253. * Attempts to continue adding to an existing undo batch command.
  254. * If the specified batchId is on the top of the stack, it is used, otherwise a new
  255. * handle is returned.
  256. * \param batchId - the Id of the undo batch (returned from BeginUndoBatch).
  257. * \param label - description of the operation.
  258. * \return a handle for the batch.
  259. */
  260. virtual UndoSystem::URSequencePoint* ResumeUndoBatch(UndoSystem::URSequencePoint* batchId, const char* label) = 0;
  261. /*!
  262. * Completes the current undo batch.
  263. * It's still possible to resume the batch as long as it's still the most recent one.
  264. */
  265. virtual void EndUndoBatch() = 0;
  266. /*!
  267. * Retrieves the preemptive undo cache for the application.
  268. */
  269. virtual PreemptiveUndoCache* GetUndoCache() = 0;
  270. /*!
  271. * \return true if the entity (or entities) can be edited/modified.
  272. */
  273. virtual bool IsEntityEditable(AZ::EntityId entityId) = 0;
  274. virtual bool AreEntitiesEditable(const EntityIdList& entityIds) = 0;
  275. /*!
  276. * Notifies the tools application that the user wishes to checkout selected entities.
  277. */
  278. virtual void CheckoutPressed() = 0;
  279. /*!
  280. * Returns source control info for the current world/scene.
  281. * Not yet implemented in ToolsApplication.
  282. */
  283. virtual SourceControlFileInfo GetSceneSourceControlInfo() = 0;
  284. /*!
  285. * Returns true if any entities are selected, false if no entities are selected.
  286. */
  287. virtual bool AreAnyEntitiesSelected() = 0;
  288. /*!
  289. * Returns the number of selected entities.
  290. */
  291. virtual int GetSelectedEntitiesCount() = 0;
  292. /*!
  293. * Retrieves the set of selected entities.
  294. * \return a list of entity Ids.
  295. */
  296. virtual const EntityIdList& GetSelectedEntities() = 0;
  297. /*!
  298. * Retrieves the set of highlighted (but not selected) entities.
  299. * \return a list of entity Ids.
  300. */
  301. virtual const EntityIdList& GetHighlightedEntities() = 0;
  302. /*!
  303. * Explicitly specifies the set of selected entities.
  304. * \param a list of entity Ids.
  305. */
  306. virtual void SetSelectedEntities(const EntityIdList& selectedEntities) = 0;
  307. /*!
  308. * Functionality removed, function call left in to prevent compile issues if anybody's using it.
  309. * \param entityId
  310. */
  311. virtual bool IsSelectable(const AZ::EntityId& entityId) = 0;
  312. /*!
  313. * Returns true if the specified entity is currently selected.
  314. * \param entityId
  315. */
  316. virtual bool IsSelected(const AZ::EntityId& entityId) = 0;
  317. /*!
  318. * Returns true if the specified entity is a slice root.
  319. * \param entityId
  320. */
  321. virtual bool IsSliceRootEntity(const AZ::EntityId& entityId) = 0;
  322. /*!
  323. * Retrieves the undo stack.
  324. * \return a pointer to the undo stack.
  325. */
  326. virtual UndoSystem::UndoStack* GetUndoStack() = 0;
  327. /*!
  328. * Retrieves the current undo batch.
  329. * \returns a pointer to the top of the undo stack.
  330. */
  331. virtual UndoSystem::URSequencePoint* GetCurrentUndoBatch() = 0;
  332. /*!
  333. * Given a list of input entity Ids, gather their children and all descendants as well.
  334. * \param inputEntities list of entities whose children should be gathered.
  335. * \return set of entity Ids including input entities and their descendants.
  336. */
  337. virtual EntityIdSet GatherEntitiesAndAllDescendents(const EntityIdList& inputEntities) = 0;
  338. //! Create a new entity at a default position
  339. virtual AZ::EntityId CreateNewEntity(AZ::EntityId parentId = AZ::EntityId()) = 0;
  340. //! Create a new entity at a specified position
  341. virtual AZ::EntityId CreateNewEntityAtPosition(const AZ::Vector3& pos, AZ::EntityId parentId = AZ::EntityId()) = 0;
  342. //! Gets an existing entity id from a known id.
  343. virtual AZ::EntityId GetExistingEntity(AZ::u64 id) = 0;
  344. //! Returns if an entity with the given id exists
  345. virtual bool EntityExists(AZ::EntityId id) = 0;
  346. /*!
  347. * Delete all currently-selected entities.
  348. */
  349. virtual void DeleteSelected() = 0;
  350. /*!
  351. * Deletes the specified entity.
  352. */
  353. virtual void DeleteEntityById(AZ::EntityId entityId) = 0;
  354. /*!
  355. * Deletes all specified entities.
  356. */
  357. virtual void DeleteEntities(const EntityIdList& entities) = 0;
  358. /*!
  359. * Deletes the specified entity, as well as any transform descendants.
  360. */
  361. virtual void DeleteEntityAndAllDescendants(AZ::EntityId entityId) = 0;
  362. /*!
  363. * Deletes all entities in the provided list, as well as their transform descendants.
  364. */
  365. virtual void DeleteEntitiesAndAllDescendants(const EntityIdList& entities) = 0;
  366. virtual bool DetachEntities(const AZStd::vector<AZ::EntityId>& entitiesToDetach, AZStd::vector<AZStd::pair<AZ::EntityId, AZ::SliceComponent::EntityRestoreInfo>>& restoreInfos) = 0;
  367. /*!
  368. * \brief Detaches the supplied subslices from their owning slice instance
  369. * \param subsliceRootList A list of SliceInstanceAddresses paired with a mapping from the sub slices asset entityId's to the owing slice instance's live entityIds
  370. See SliceComponent::GetMappingBetweenSubsliceAndSourceInstanceEntityIds for a helper to acquire this mapping
  371. * \param restoreInfos A list of EntityRestoreInfo's to be filled with information on how to restore the entities in the subslices back to their original state before this operation
  372. * \return Returns true on operation success, false otherwise
  373. */
  374. virtual bool DetachSubsliceInstances(const AZ::SliceComponent::SliceInstanceEntityIdRemapList& subsliceRootList,
  375. AZStd::vector<AZStd::pair<AZ::EntityId, AZ::SliceComponent::EntityRestoreInfo>>& restoreInfos) = 0;
  376. /*!
  377. * \brief Finds the Common root of an entity list; Also finds the top level entities in a given list of active entities (who share the common root)
  378. * Example : A(B[D,E{F}],C),G (Letter is entity name, braces hold children)
  379. * Sample run | entitiesToBeChecked:(B,D,E,F,C)
  380. * commonRootEntityId: <A> , topLevelEntities: <B,C>, return : <true>
  381. * Sample run | entitiesToBeChecked:(E,C)
  382. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <E,C>, return : <false>
  383. * Sample run | entitiesToBeChecked:(A,G,B,E,C)
  384. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <A,G>, return : <true> (True because both of the top level entities have no parent , which for us is the common parent)
  385. * Sample run | entitiesToBeChecked:(A,D)
  386. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <A,D>, return : <false>
  387. * \param entitiesToBeChecked List of entities whose parentage is to be found
  388. * \param commonRootEntityId [Out] Entity id of the common root for the entitiesToBeChecked
  389. * \param topLevelEntities [Out] List of entities at the top of the hierarchy in entitiesToBeChecked
  390. * \return boolean value indicating whether entities have a common root or not
  391. * IF True commonRootEntityId is the common root of all rootLevelEntities
  392. * IF False commonRootEntityId is an invalid entity id
  393. * NOTE: Requires that the entities to be checked are live, they must be active and available via TransformBus.
  394. * \ref entitiesToBeChecked cannot contain nested entities with gaps, see Sample run 4
  395. */
  396. virtual bool FindCommonRoot(const AzToolsFramework::EntityIdSet& entitiesToBeChecked, AZ::EntityId& commonRootEntityId
  397. , AzToolsFramework::EntityIdList* topLevelEntities = nullptr) = 0;
  398. /**
  399. * \brief Finds the Common root of an entity list; Also finds the top level entities in a given list of inactive entities (who share the common root)
  400. * Example : A(B[D,E{F}],C),G (Letter is entity name, braces hold children)
  401. * Sample run | entitiesToBeChecked:(B,D,E,F,C)
  402. * commonRootEntityId: <A> , topLevelEntities: <B,C>, return : <true>
  403. * Sample run | entitiesToBeChecked:(E,C)
  404. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <E,C>, return : <false>
  405. * Sample run | entitiesToBeChecked:(A,G,B,E,C)
  406. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <A,G>, return : <true> (True because both of the top level entities have no parent , which for us is the common parent)
  407. * Sample run | entitiesToBeChecked:(A,D)
  408. * commonRootEntityId:<InvalidEntityId> , topLevelEntities: <A,D>, return : <false>
  409. * \param entitiesToBeChecked List of entities whose parentage is to be found
  410. * \param commonRootEntityId [Out] Entity id of the common root for the entitiesToBeChecked
  411. * \param topLevelEntities [Out] List of entities at the top of the hierarchy in entitiesToBeChecked
  412. * \return boolean value indicating whether entities have a common root or not
  413. * IF True commonRootEntityId is the common root of all rootLevelEntities
  414. * IF False commonRootEntityId is an invalid entity id
  415. * NOTE: Does not require that the entities to be checked are live, they could be temp or asset entities.
  416. * \ref entitiesToBeChecked cannot contain nested entities with gaps, see Sample run 4
  417. */
  418. virtual bool FindCommonRootInactive(const AzToolsFramework::EntityList& entitiesToBeChecked, AZ::EntityId& commonRootEntityId, AzToolsFramework::EntityList* topLevelEntities = nullptr) = 0;
  419. /**
  420. * Find all top level entities in the transform hierarchy of a list of entities, whether they are active or not.
  421. * Different from the function FindCommonRootInactive, this function returns all top level entities even if \ref entityIdsToCheck contains gaps in its transform hierarchy, at the cost of performance.
  422. * @param entityIdsToCheck A list of entity ids.
  423. * @param[out] A list of entity ids of top level entities.
  424. */
  425. virtual void FindTopLevelEntityIdsInactive(const EntityIdList& entityIdsToCheck, EntityIdList& topLevelEntityIds) = 0;
  426. /**
  427. * Check every entity to see if they all belong to the same slice instance, if so return that slice instance address, otherwise return null.
  428. * @param entityIds An group of EntityIds.
  429. * @return The slice instance address if all of \ref entityIds belongs to the same slice instance, otherwise null.
  430. */
  431. virtual AZ::SliceComponent::SliceInstanceAddress FindCommonSliceInstanceAddress(const EntityIdList& entityIds) = 0;
  432. /**
  433. * Get the id of the root entity of a slice instance.
  434. * This function ignores any unpushed change made to the transform hierarchy of the entities in the slice instance in question.
  435. * @param sliceAddress The address of a slice instance.
  436. * @return The root entity id.
  437. */
  438. virtual AZ::EntityId GetRootEntityIdOfSliceInstance(AZ::SliceComponent::SliceInstanceAddress sliceAddress) = 0;
  439. /**
  440. * Get the id of the level that is loaded currently in the editor.
  441. * This is a "singleton" type of EntityId that represents the current level.
  442. * It can be used to add level components to it.
  443. */
  444. virtual AZ::EntityId GetCurrentLevelEntityId() = 0;
  445. /**
  446. * Prepares a file for editability. Interacts with source-control if the asset is not already writable, in a blocking fashion.
  447. * \param path full path of the asset to be made editable.
  448. * \param progressMessage progress message to display during checkout operation.
  449. * \param progressCallback user callback for retrieving progress information, provide RequestEditProgressCallback() if no progress reporting is required.
  450. * \return boolean value indicating if the file is writable after the operation.
  451. */
  452. using RequestEditProgressCallback = AZStd::function<void(int& current, int& max)>;
  453. virtual bool RequestEditForFileBlocking(const char* assetPath, const char* progressMessage, const RequestEditProgressCallback& progressCallback) = 0;
  454. /**
  455. * Same as RequestEditForBlocking, but intentionally fails operation when source control is offline
  456. * We add this function as convenience to side step the behavior of removing write protection when LocalFileSCComponent is used
  457. * \param path full path of the asset to be made editable.
  458. * \param progressMessage progress message to display during checkout operation.
  459. * \param progressCallback user callback for retrieving progress information, provide RequestEditProgressCallback() if no progress reporting is required.
  460. * \return boolean value indicating if the file is writable after the operation.
  461. */
  462. virtual bool CheckSourceControlConnectionAndRequestEditForFileBlocking(const char* assetPath, const char* progressMessage, const RequestEditProgressCallback& progressCallback) = 0;
  463. /**
  464. * Prepares a file for editability. Interacts with source-control if the asset is not already writable.
  465. * \param path full path of the asset to be made editable.
  466. * \param resultCallback user callback to be notified when source control operation is complete. Callback will be invoked with a true success value if the file was made writable.
  467. * If the file is already writable at the time the function is called, resultCallback(true) will be invoked immediately.
  468. */
  469. using RequestEditResultCallback = AZStd::function<void(bool success)>;
  470. virtual void RequestEditForFile(const char* assetPath, RequestEditResultCallback resultCallback) = 0;
  471. /**
  472. * Same as RequestEditForFile, but intentionally fails operation when source control is offline
  473. * We add this function as convenience to side step the behavior of removing write protection when LocalFileSCComponent is used
  474. * \param path full path of the asset to be made editable.
  475. * \param resultCallback user callback to be notified when source control operation is complete. Callback will be invoked with a true success value if the file was made writable.
  476. * If the file is already writable at the time the function is called, resultCallback(true) will be invoked immediately.
  477. */
  478. virtual void CheckSourceControlConnectionAndRequestEditForFile(const char* assetPath, RequestEditResultCallback resultCallback) = 0;
  479. /*!
  480. * Enter the Isolation Mode and hide entities that are not selected.
  481. */
  482. virtual void EnterEditorIsolationMode() = 0;
  483. /*!
  484. * Exit the Isolation Mode and stop hiding entities.
  485. */
  486. virtual void ExitEditorIsolationMode() = 0;
  487. /*!
  488. * Request if the editor is currently in Isolation Mode
  489. * /return boolean indicating if the editor is currently in Isolation Mode
  490. */
  491. virtual bool IsEditorInIsolationMode() = 0;
  492. /**
  493. * Creates and adds a new entity to the tools application from components which match at least one of the requiredTags
  494. * The tag matching occurs on AZ::Edit::SystemComponentTags attribute from the reflected class data in the serialization context
  495. */
  496. virtual void CreateAndAddEntityFromComponentTags(const AZStd::vector<AZ::Crc32>& requiredTags, const char* entityName) = 0;
  497. /**
  498. * Attempts to resolve a path to an executable using the current executable's folder
  499. */
  500. using ResolveToolPathOutcome = AZ::Outcome<AZStd::string, AZStd::string>;
  501. virtual ResolveToolPathOutcome ResolveConfigToolsPath(const char* toolApplicationName) const = 0;
  502. /**
  503. * Open 3D Engine Internal use only.
  504. *
  505. * Run a specific redo command separate from the undo/redo system.
  506. * In many cases before a modification on an entity takes place, it is first packaged into
  507. * undo/redo commands. Running the modification's redo command separate from the undo/redo
  508. * system simulates its execution, and avoids some code duplication.
  509. */
  510. virtual void RunRedoSeparately(UndoSystem::URSequencePoint* redoCommand) = 0;
  511. };
  512. using ToolsApplicationRequestBus = AZ::EBus<ToolsApplicationRequests>;
  513. /**
  514. * Bus keyed on entity Id for selection events.
  515. * Note that upon connection OnSelected() may be immediately invoked.
  516. */
  517. class EntitySelectionEvents
  518. : public AZ::ComponentBus
  519. {
  520. public:
  521. ////////////////////////////////////////////////////////////////////////
  522. // EBusTraits overrides
  523. /**
  524. * Custom connection policy notifies handler if entity is already selected.
  525. */
  526. template<class Bus>
  527. struct SelectionConnectionPolicy
  528. : public AZ::EBusConnectionPolicy<Bus>
  529. {
  530. static void Connect(typename Bus::BusPtr& busPtr, typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::Context::ConnectLockGuard& connectLock, const typename Bus::BusIdType& id = 0)
  531. {
  532. AZ::EBusConnectionPolicy<Bus>::Connect(busPtr, context, handler, connectLock, id);
  533. EntityIdList selectedEntities;
  534. EBUS_EVENT_RESULT(selectedEntities, ToolsApplicationRequests::Bus, GetSelectedEntities);
  535. if (AZStd::find(selectedEntities.begin(), selectedEntities.end(), id) != selectedEntities.end())
  536. {
  537. handler->OnSelected();
  538. }
  539. }
  540. };
  541. template<typename Bus>
  542. using ConnectionPolicy = SelectionConnectionPolicy<Bus>;
  543. using Bus = AZ::EBus<EntitySelectionEvents>;
  544. ////////////////////////////////////////////////////////////////////////
  545. virtual void OnSelected() {}
  546. virtual void OnDeselected() {}
  547. };
  548. /**
  549. * Bus for editor requests related to Pick Mode.
  550. */
  551. class EditorPickModeRequests
  552. : public AZ::EBusTraits
  553. {
  554. public:
  555. using Bus = AZ::EBus<EditorPickModeRequests>;
  556. // EBusTraits overrides
  557. using BusIdType = AzFramework::EntityContextId;
  558. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  559. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  560. /**
  561. * Move the Editor out of Pick Mode.
  562. * Note: The Editor is moved into Pick Mode by a button in the Entity Inspector UI.
  563. */
  564. virtual void StopEntityPickMode() = 0;
  565. /**
  566. * When in Pick Mode, set the picked entity to the assigned slot(s).
  567. * @note It is only valid to make this request when the editor is in Pick Mode.
  568. */
  569. virtual void PickModeSelectEntity(AZ::EntityId entityId) = 0;
  570. protected:
  571. ~EditorPickModeRequests() = default;
  572. };
  573. /// Type to inherit to implement EditorPickModeRequests
  574. using EditorPickModeRequestBus = AZ::EBus<EditorPickModeRequests>;
  575. /**
  576. * Bus for editor notifications related to Pick Mode.
  577. */
  578. class EditorPickModeNotifications
  579. : public AZ::EBusTraits
  580. {
  581. public:
  582. // EBusTraits overrides
  583. using BusIdType = AzFramework::EntityContextId;
  584. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  585. /**
  586. * Notify other systems that the editor has entered Pick Mode select.
  587. */
  588. virtual void OnEntityPickModeStarted() {}
  589. /**
  590. * Notify other systems that the editor has left Pick Mode select.
  591. */
  592. virtual void OnEntityPickModeStopped() {}
  593. protected:
  594. ~EditorPickModeNotifications() = default;
  595. };
  596. /// Type to inherit to implement EditorPickModeNotifications
  597. using EditorPickModeNotificationBus = AZ::EBus<EditorPickModeNotifications>;
  598. /**
  599. * Bus for general editor requests to be intercepted by the application (e.g. Sandbox).
  600. */
  601. class EditorRequests
  602. : public AZ::EBusTraits
  603. {
  604. public:
  605. using Bus = AZ::EBus<EditorRequests>;
  606. //////////////////////////////////////////////////////////////////////////
  607. // EBusTraits overrides
  608. // PLEASE PLEASE PLEASE don't change this to multiple unless you change all of the
  609. // calls to this E-BUS that expect a returned value to handle multiple
  610. // buses listening.
  611. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  612. //////////////////////////////////////////////////////////////////////////
  613. /// Registers a view pane (generally a QMainWindow-derived class) with the main editor.
  614. /// It's easier to use AzToolsFramework::RegisterViewPane, as it does not require a widget creation function to be supplied.
  615. /// \param name - display name for the pane. Will appear in the window header bar, as well as the context menu.
  616. /// \param category - category under the Tools menu that will contain the option to open the pane.
  617. /// \param viewOptions - structure defining various UI options for the pane.
  618. /// \param widgetCreationFunc - function callback for constructing the pane.
  619. typedef AZStd::function<QWidget*(QWidget*)> WidgetCreationFunc;
  620. virtual void RegisterViewPane(const char* /*name*/, const char* /*category*/, const ViewPaneOptions& /*viewOptions*/, const WidgetCreationFunc& /*widgetCreationFunc*/) {};
  621. //! Similar to EditorRequests::RegisterViewPane, although instead of specifying a widget creation function, the user
  622. //! must connect to the ViewPaneCallbacks bus and respond to the CreateViewPaneWidget event that is called when
  623. //! the view pane needs to be constructed.
  624. virtual void RegisterCustomViewPane(const char* /*name*/, const char* /*category*/, const ViewPaneOptions& /*viewOptions*/) {};
  625. /// Unregisters a view pane by name from the main editor.
  626. /// \param name - the name of the pane to be unregistered. This must match the name used for registration.
  627. virtual void UnregisterViewPane(const char* /*name*/) {};
  628. /// Returns the widget contained/wrapped in a view pane.
  629. /// \param viewPaneName - the name of the pane which contains the widget to be retrieved. This must match the name used for registration.
  630. virtual QWidget* GetViewPaneWidget(const char* /*viewPaneName*/) { return nullptr; }
  631. /// Show an Editor window by name.
  632. void ShowViewPane(const char* paneName) { OpenViewPane(paneName); }
  633. /// Opens an Editor window by name. Shows it if it was previously hidden, and activates it even if it's already visible.
  634. virtual void OpenViewPane(const char* /*paneName*/) {}
  635. /// Opens a new instance of an Editor window by name and returns the dock widget container
  636. virtual QDockWidget* InstanceViewPane(const char* /*paneName*/) { return nullptr; }
  637. /// Closes an Editor window by name.
  638. /// If the view pane was registered with the ViewPaneOptions.isDeletable set to true (the default), this will delete the view pane, if it was open.
  639. /// If the view pane was not registered with the ViewPaneOptions.isDeletable set to true, the view pane will be hidden instead.
  640. virtual void CloseViewPane(const char* /*paneName*/) {}
  641. //! Spawn asset browser for the appropriate asset types.
  642. virtual void BrowseForAssets(AssetBrowser::AssetSelectionModel& /*selection*/) = 0;
  643. /// Creates editor-side representation of an underlying entity.
  644. virtual void CreateEditorRepresentation(AZ::Entity* /*entity*/) { }
  645. /// Destroys editor-side representation of a given entity.
  646. virtual bool DestroyEditorRepresentation(AZ::EntityId /*entityId*/, bool /*deleteAZEntity*/) { return false; }
  647. /// Clone selected entities/slices.
  648. virtual void CloneSelection(bool& /*handled*/) {}
  649. /// Delete selected entities/slices
  650. virtual void DeleteSelectedEntities(bool /*includeDescendants*/) {}
  651. /// Create a new entity at a default position
  652. virtual AZ::EntityId CreateNewEntity(AZ::EntityId parentId = AZ::EntityId()) { (void)parentId; return AZ::EntityId(); }
  653. /// Create a new entity as a child of an existing entity - Intended only to handle explicit requests from the user
  654. virtual AZ::EntityId CreateNewEntityAsChild(AZ::EntityId /*parentId*/) { return AZ::EntityId(); }
  655. /// Create a new entity at a specified position
  656. virtual AZ::EntityId CreateNewEntityAtPosition(const AZ::Vector3& /*pos*/, AZ::EntityId parentId = AZ::EntityId()) { (void)parentId; return AZ::EntityId(); }
  657. /// Gets and existing EntityId from a known id passed ad a u64
  658. virtual AZ::EntityId GetExistingEntity(AZ::u64 id) {return AZ::EntityId{id}; }
  659. virtual AzFramework::EntityContextId GetEntityContextId() { return AzFramework::EntityContextId::CreateNull(); }
  660. /// Retrieve the main application window.
  661. virtual QWidget* GetMainWindow() { return nullptr; }
  662. /// Retrieve main editor interface.
  663. virtual IEditor* GetEditor() { return nullptr; }
  664. virtual bool GetUndoSliceOverrideSaveValue() { return false; }
  665. /// Retrieve the setting for messaging
  666. virtual bool GetShowCircularDependencyError() { return true; }
  667. /// Hide or show the circular dependency error when saving slices
  668. virtual void SetShowCircularDependencyError(const bool& /*showCircularDependencyError*/) {}
  669. /// Launches the Lua editor and opens the specified (space separated) files.
  670. virtual void LaunchLuaEditor(const char* /*files*/) {}
  671. /// Returns whether a level document is open.
  672. virtual bool IsLevelDocumentOpen() { return false; }
  673. /// Return the name of a level document.
  674. virtual AZStd::string GetLevelName() { return AZStd::string(); }
  675. /// Return default icon to show in the viewport for components that haven't specified an icon.
  676. virtual AZStd::string GetDefaultComponentViewportIcon() { return AZStd::string(); }
  677. /// Return default icon to show in the palette, etc for components that haven't specified an icon.
  678. virtual AZStd::string GetDefaultComponentEditorIcon() { return AZStd::string(); }
  679. /// Return default entity icon to show both in viewport and entity-inspector.
  680. virtual AZStd::string GetDefaultEntityIcon() { return AZStd::string(); }
  681. /// Return path to icon for component.
  682. /// Path will be empty if component should have no icon.
  683. virtual AZStd::string GetComponentEditorIcon(const AZ::Uuid& /*componentType*/, AZ::Component* /*component*/) { return AZStd::string(); }
  684. //! Return path to icon for component type.
  685. //! Path will be empty if component type should have no icon.
  686. virtual AZStd::string GetComponentTypeEditorIcon(const AZ::Uuid& /*componentType*/) { return AZStd::string(); }
  687. /**
  688. * Return the icon image path based on the component type and where it is used.
  689. * \param componentType component type
  690. * \param componentIconAttrib edit attribute describing where the icon is used, it could be one of Icon, Viewport and HidenIcon
  691. * \return the path of the icon image
  692. */
  693. virtual AZStd::string GetComponentIconPath(const AZ::Uuid& /*componentType*/, AZ::Crc32 /*componentIconAttrib*/, AZ::Component* /*component*/) { return AZStd::string(); }
  694. /**
  695. * Calculate the navigation 2D radius in units of an agent given its Navigation Type Name
  696. * @param angentTypeName the name that identifies the agent navigation type
  697. * @return the 2D horizontal radius of the agent, -1 if not found
  698. */
  699. virtual float CalculateAgentNavigationRadius(const char* /*angentTypeName*/) { return -1; }
  700. /**
  701. * Retrieve the default agent Navigation Type Name
  702. * @return the string identifying an agent navigation type
  703. */
  704. virtual const char* GetDefaultAgentNavigationTypeName() { return ""; }
  705. virtual void OpenPinnedInspector(const AzToolsFramework::EntityIdSet& /*entities*/) { }
  706. virtual void ClosePinnedInspector(AzToolsFramework::EntityPropertyEditor* /*editor*/) {}
  707. /// Return all available agent types defined in the Navigation xml file.
  708. virtual AZStd::vector<AZStd::string> GetAgentTypes() { return AZStd::vector<AZStd::string>(); }
  709. /// Focus all viewports on the selected and highlighted entities
  710. virtual void GoToSelectedOrHighlightedEntitiesInViewports() { }
  711. /// Focus all viewports on the selected entities
  712. virtual void GoToSelectedEntitiesInViewports() { }
  713. /// Returns true if the selected entities can be moved to, and false if not.
  714. virtual bool CanGoToSelectedEntitiesInViewports() { return true; }
  715. /// Returns the world-space position under the center of the render viewport.
  716. virtual AZ::Vector3 GetWorldPositionAtViewportCenter() { return AZ::Vector3::CreateZero(); }
  717. virtual void InstantiateSliceFromAssetId(const AZ::Data::AssetId& /*assetId*/) {}
  718. /// Clears current redo stack
  719. virtual void ClearRedoStack() {}
  720. /// Return the icon texture id (from internal IconManager) for a given entity icon path.
  721. /// This can be passed to DrawTextureLabel to draw an entity icon.
  722. virtual int GetIconTextureIdFromEntityIconPath(const AZStd::string& entityIconPath) = 0;
  723. /// Returns if the Display Helpers option is toggled on in the Editor.
  724. virtual bool DisplayHelpersVisible() = 0;
  725. };
  726. using EditorRequestBus = AZ::EBus<EditorRequests>;
  727. /**
  728. * Bus for general editor events.
  729. */
  730. class EditorEvents
  731. : public AZ::EBusTraits
  732. {
  733. public:
  734. using Bus = AZ::EBus<EditorEvents>;
  735. virtual void OnEscape() {}
  736. /// The editor has changed performance specs.
  737. virtual void OnEditorSpecChange() {}
  738. enum EditorContextMenuFlags
  739. {
  740. eECMF_NONE = 0,
  741. eECMF_HIDE_ENTITY_CREATION = 0x1,
  742. eECMF_USE_VIEWPORT_CENTER = 0x2,
  743. };
  744. /// Populate slice portion of edit-time context menu
  745. virtual void PopulateEditorGlobalContextMenu_SliceSection(QMenu * /*menu*/, const AZ::Vector2& /*point*/, int /*flags*/) {}
  746. /// Anything can override this and return true to skip over the WelcomeScreenDialog
  747. virtual bool SkipEditorStartupUI() { return false; }
  748. /// Notify that it's ok to register views
  749. virtual void NotifyRegisterViews() {}
  750. /// Notify that central widget has been initialized
  751. virtual void NotifyCentralWidgetInitialized() {}
  752. /// Notify that the Qt Application object is now ready to be used
  753. virtual void NotifyQtApplicationAvailable(QApplication* /* application */) {}
  754. /// Notify that the IEditor is ready
  755. virtual void NotifyIEditorAvailable(IEditor* /*editor*/) {}
  756. /// Notify that the MainWindow has been fully initialized
  757. virtual void NotifyMainWindowInitialized(QMainWindow* /*mainWindow*/) {}
  758. /// Notify that the Editor has been fully initialized
  759. virtual void NotifyEditorInitialized() {}
  760. /// Signal that an asset should be highlighted / selected
  761. virtual void SelectAsset(const QString& /* assetPath */) {}
  762. };
  763. using EditorEventsBus = AZ::EBus<EditorEvents>;
  764. class ViewPaneCallbacks
  765. : public AZ::EBusTraits
  766. {
  767. public:
  768. //////////////////////////////////////////////////////////////////////////
  769. // EBusTraits overrides
  770. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  771. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  772. using BusIdType = AZStd::string;
  773. //////////////////////////////////////////////////////////////////////////
  774. //! Return the window ID of the created view pane widget
  775. virtual AZ::u64 CreateViewPaneWidget() { return AZ::u64(); }
  776. };
  777. using ViewPaneCallbackBus = AZ::EBus<ViewPaneCallbacks>;
  778. /**
  779. * RAII Helper class for undo batches.
  780. *
  781. * AzToolsFramework::ScopedUndoBatch undoBatch("Batch Name");
  782. * entity->ChangeData(...);
  783. * undoBatch.MarkEntityDirty(entity->GetId());
  784. */
  785. class ScopedUndoBatch
  786. {
  787. public:
  788. AZ_CLASS_ALLOCATOR(ScopedUndoBatch, AZ::SystemAllocator, 0);
  789. explicit ScopedUndoBatch(const char* batchName)
  790. {
  791. ToolsApplicationRequests::Bus::BroadcastResult(
  792. m_undoBatch, &ToolsApplicationRequests::Bus::Events::BeginUndoBatch, batchName);
  793. }
  794. ~ScopedUndoBatch()
  795. {
  796. ToolsApplicationRequests::Bus::Broadcast(&ToolsApplicationRequests::Bus::Events::EndUndoBatch);
  797. }
  798. // utility/convenience function for adding dirty entity
  799. static void MarkEntityDirty(const AZ::EntityId& id)
  800. {
  801. ToolsApplicationRequests::Bus::Broadcast(&ToolsApplicationRequests::Bus::Events::AddDirtyEntity, id);
  802. }
  803. UndoSystem::URSequencePoint* GetUndoBatch() const
  804. {
  805. return m_undoBatch;
  806. }
  807. private:
  808. AZ_DISABLE_COPY_MOVE(ScopedUndoBatch);
  809. UndoSystem::URSequencePoint* m_undoBatch = nullptr;
  810. };
  811. /// Registers a view pane with the main editor. It will be listed under the "Tools" menu on the main window's menubar.
  812. /// Note that if a view pane is registered with it's ViewPaneOptions.isDeletable set to true, the widget will be deallocated and destructed on close.
  813. /// Otherwise, it will be hidden instead.
  814. /// If you'd like to be able to veto the close (for instance, if the user has unsaved data), override the closeEvent() on your custom
  815. /// viewPane widget and call ignore() on the QCloseEvent* parameter.
  816. ///
  817. /// \param viewPaneName - name for the pane. This is what will appear in the dock window's title bar, as well as in the main editor window's menubar, if the optionalMenuText is not set in the viewOptions parameter.
  818. /// \param category - category under the "Tools" menu that will contain the option to open the newly registered pane.
  819. /// \param viewOptions - structure defining various options for the pane.
  820. template <typename TWidget>
  821. inline void RegisterViewPane(const char* name, const char* category, const ViewPaneOptions& viewOptions)
  822. {
  823. AZStd::function<QWidget*(QWidget*)> windowCreationFunc = [](QWidget* parent = nullptr)
  824. {
  825. return new TWidget(parent);
  826. };
  827. EditorRequests::Bus::Broadcast(&EditorRequests::RegisterViewPane, name, category, viewOptions, windowCreationFunc);
  828. }
  829. /// Registers a view pane with the main editor. It will be listed under the "Tools" menu on the main window's menubar.
  830. /// This variant is most useful when dealing with singleton view widgets.
  831. /// Note that if the new view is a singleton, and shouldn't be destroyed by the view pane manager, viewOptions.isDeletable must be set to false.
  832. /// Note that if a view pane is registered with it's ViewPaneOptions.isDeletable set to true, the widget will be deallocated and destructed on close.
  833. /// Otherwise, it will be hidden instead.
  834. /// If you'd like to be able to veto the close (for instance, if the user has unsaved data), override the closeEvent() on your custom
  835. /// viewPane widget and call ignore() on the QCloseEvent* parameter.
  836. ///
  837. /// \param viewPaneName - name for the pane. This is what will appear in the dock window's title bar, as well as in the main editor window's menubar, if the optionalMenuText is not set in the viewOptions parameter.
  838. /// \param category - category under the "Tools" menu that will contain the option to open the newly registered pane.
  839. /// \param viewOptions - structure defining various options for the pane.
  840. template <typename TWidget>
  841. inline void RegisterViewPane(const char* viewPaneName, const char* category, const ViewPaneOptions& viewOptions, AZStd::function<QWidget*(QWidget*)> windowCreationFunc)
  842. {
  843. EditorRequests::Bus::Broadcast(&EditorRequests::RegisterViewPane, viewPaneName, category, viewOptions, windowCreationFunc);
  844. }
  845. /// Unregisters a view pane with the main editor. It will no longer be listed under the "Tools" menu on the main window's menubar.
  846. /// Any currently open view panes of this type will be closed before the view pane handlers are unregistered.
  847. ///
  848. /// \param viewPaneName - name of the pane to unregister. Must be the same as the name previously registered with RegisterViewPane.
  849. inline void UnregisterViewPane(const char* viewPaneName)
  850. {
  851. EditorRequests::Bus::Broadcast(&EditorRequests::UnregisterViewPane, viewPaneName);
  852. }
  853. /// Returns the widget contained/wrapped in a view pane.
  854. /// \param name - the name of the pane which contains the widget to be retrieved. This must match the name used for registration.
  855. template <typename TWidget>
  856. inline TWidget* GetViewPaneWidget(const char* viewPaneName)
  857. {
  858. QWidget* ret = nullptr;
  859. EditorRequests::Bus::BroadcastResult(ret, &EditorRequests::GetViewPaneWidget, viewPaneName);
  860. return qobject_cast<TWidget*>(ret);
  861. }
  862. /// Opens a view pane if not already open, and activating the view pane if it was already opened.
  863. ///
  864. /// \param viewPaneName - name of the pane to open/activate. Must be the same as the name previously registered with RegisterViewPane.
  865. inline void OpenViewPane(const char* viewPaneName)
  866. {
  867. EditorRequests::Bus::Broadcast(&EditorRequests::OpenViewPane, viewPaneName);
  868. }
  869. /// Opens a view pane if not already open, and activating the view pane if it was already opened.
  870. ///
  871. /// \param viewPaneName - name of the pane to open/activate. Must be the same as the name previously registered with RegisterViewPane.
  872. inline QDockWidget* InstanceViewPane(const char* viewPaneName)
  873. {
  874. QDockWidget* ret = nullptr;
  875. EditorRequests::Bus::BroadcastResult(ret, &EditorRequests::InstanceViewPane, viewPaneName);
  876. return ret;
  877. }
  878. /// Closes a view pane if it is currently open.
  879. ///
  880. /// \param viewPaneName - name of the pane to open/activate. Must be the same as the name previously registered with RegisterViewPane.
  881. inline void CloseViewPane(const char* viewPaneName)
  882. {
  883. EditorRequests::Bus::Broadcast(&EditorRequests::CloseViewPane, viewPaneName);
  884. }
  885. /**
  886. * Helper to wrap checking if an undo/redo operation is in progress.
  887. */
  888. inline bool UndoRedoOperationInProgress()
  889. {
  890. bool isDuringUndoRedo = false;
  891. ToolsApplicationRequestBus::BroadcastResult(
  892. isDuringUndoRedo, &ToolsApplicationRequests::IsDuringUndoRedo);
  893. return isDuringUndoRedo;
  894. }
  895. } // namespace AzToolsFramework
  896. AZ_DECLARE_BUDGET(AzToolsFramework);