3
0

AtomToolsFrameworkSystemComponent.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #include <AtomToolsFramework/Document/AtomToolsAnyDocument.h>
  9. #include <AtomToolsFramework/Document/AtomToolsDocument.h>
  10. #include <AtomToolsFramework/Document/AtomToolsDocumentSystem.h>
  11. #include <AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h>
  12. #include <AtomToolsFramework/EntityPreviewViewport/EntityPreviewViewportSettingsSystem.h>
  13. #include <AtomToolsFramework/Graph/DynamicNode/DynamicNode.h>
  14. #include <AtomToolsFramework/Graph/DynamicNode/DynamicNodeManager.h>
  15. #include <AtomToolsFramework/Graph/DynamicNode/DynamicNodePaletteItem.h>
  16. #include <AtomToolsFramework/Graph/GraphCompiler.h>
  17. #include <AtomToolsFramework/Graph/GraphDocument.h>
  18. #include <AtomToolsFramework/Graph/GraphViewConstructPresets.h>
  19. #include <AtomToolsFramework/Graph/GraphViewSettings.h>
  20. #include <AtomToolsFramework/Inspector/InspectorWidget.h>
  21. #include <AtomToolsFramework/Util/Util.h>
  22. #include <AtomToolsFrameworkSystemComponent.h>
  23. #include <AzCore/RTTI/BehaviorContext.h>
  24. #include <AzCore/Serialization/EditContext.h>
  25. #include <AzCore/Serialization/SerializeContext.h>
  26. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  27. #include <AzCore/Utils/Utils.h>
  28. #include <AzCore/std/string/regex.h>
  29. #include <Inspector/PropertyWidgets/PropertyStringBrowseEditCtrl.h>
  30. namespace AtomToolsFramework
  31. {
  32. void AtomToolsFrameworkSystemComponent::Reflect(AZ::ReflectContext* context)
  33. {
  34. AtomToolsDocument::Reflect(context);
  35. AtomToolsAnyDocument::Reflect(context);
  36. AtomToolsDocumentSystem::Reflect(context);
  37. CreateDynamicNodeMimeEvent::Reflect(context);
  38. DynamicNode::Reflect(context);
  39. DynamicProperty::Reflect(context);
  40. DynamicPropertyGroup::Reflect(context);
  41. EntityPreviewViewportSettingsSystem::Reflect(context);
  42. GraphCompiler::Reflect(context);
  43. GraphDocument::Reflect(context);
  44. GraphViewSettings::Reflect(context);
  45. GraphViewConstructPresets::Reflect(context);
  46. InspectorWidget::Reflect(context);
  47. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  48. {
  49. serialize->RegisterGenericType<AZStd::unordered_map<AZStd::string, bool>>();
  50. serialize->RegisterGenericType<AZStd::map<AZStd::string, AZStd::vector<AZStd::string>>>();
  51. serialize->Class<AtomToolsFrameworkSystemComponent, AZ::Component>()
  52. ->Version(0)
  53. ;
  54. if (auto editContext = serialize->GetEditContext())
  55. {
  56. editContext->Class<AtomToolsFrameworkSystemComponent>("AtomToolsFrameworkSystemComponent", "")
  57. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  58. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  59. ;
  60. }
  61. }
  62. }
  63. void AtomToolsFrameworkSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  64. {
  65. provided.push_back(AZ_CRC_CE("AtomToolsFrameworkSystemService"));
  66. }
  67. void AtomToolsFrameworkSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  68. {
  69. incompatible.push_back(AZ_CRC_CE("AtomToolsFrameworkSystemService"));
  70. }
  71. void AtomToolsFrameworkSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  72. {
  73. AZ_UNUSED(required);
  74. }
  75. void AtomToolsFrameworkSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  76. {
  77. AZ_UNUSED(dependent);
  78. }
  79. void AtomToolsFrameworkSystemComponent::Init()
  80. {
  81. }
  82. void AtomToolsFrameworkSystemComponent::Activate()
  83. {
  84. ReadSettings();
  85. RegisterStringBrowseEditHandler();
  86. AtomToolsFrameworkSystemRequestBus::Handler::BusConnect();
  87. // Monitor and update registry settings related to file utility functions
  88. if (auto registry = AZ::SettingsRegistry::Get())
  89. {
  90. m_settingsNotifyEventHandler = registry->RegisterNotifier(
  91. [this](const AZ::SettingsRegistryInterface::NotifyEventArgs& notifyEventArgs)
  92. {
  93. if (AZ::SettingsRegistryMergeUtils::IsPathAncestorDescendantOrEqual(
  94. "/O3DE/Atom/Tools", notifyEventArgs.m_jsonKeyPath) ||
  95. AZ::SettingsRegistryMergeUtils::IsPathAncestorDescendantOrEqual(
  96. "/O3DE/AtomToolsFramework", notifyEventArgs.m_jsonKeyPath))
  97. {
  98. ReadSettings();
  99. }
  100. });
  101. }
  102. }
  103. void AtomToolsFrameworkSystemComponent::Deactivate()
  104. {
  105. AtomToolsFrameworkSystemRequestBus::Handler::BusDisconnect();
  106. }
  107. void AtomToolsFrameworkSystemComponent::ReadSettings()
  108. {
  109. AZ::IO::FixedMaxPath cachePath = AZ::Utils::GetProjectPath();
  110. cachePath /= "Cache";
  111. m_cacheFolder = cachePath.LexicallyNormal().StringAsPosix();
  112. m_ignoreCacheFolder = GetSettingsValue("/O3DE/AtomToolsFramework/Application/IgnoreCacheFolder", true);
  113. m_ignoredPathRegexPatterns = GetSettingsObject<AZStd::vector<AZStd::string>>("/O3DE/AtomToolsFramework/Application/IgnoredPathRegexPatterns");
  114. m_editablePathSettings = GetSettingsObject<AZStd::unordered_map<AZStd::string, bool>>("/O3DE/Atom/Tools/EditablePathSettings");
  115. m_previewablePathSettings = GetSettingsObject<AZStd::unordered_map<AZStd::string, bool>>("/O3DE/Atom/Tools/PreviewablePathSettings");
  116. }
  117. bool AtomToolsFrameworkSystemComponent::IsPathIgnored(const AZStd::string& path) const
  118. {
  119. if (path.empty())
  120. {
  121. return true;
  122. }
  123. // Ignoring the cache folder is currently the most common case for tools that want to ignore intermediate assets
  124. const AZStd::string pathWithoutAlias = GetPathWithoutAlias(path);
  125. if (m_ignoreCacheFolder && pathWithoutAlias.starts_with(m_cacheFolder))
  126. {
  127. return true;
  128. }
  129. // For more extensive customization, pattern matching is also supported via IgnoredPathRegexPatterns. This is empty by default.
  130. for (const auto& patternStr : m_ignoredPathRegexPatterns)
  131. {
  132. if (!patternStr.empty())
  133. {
  134. AZStd::regex patternRegex(patternStr, AZStd::regex::flag_type::icase);
  135. if (AZStd::regex_match(pathWithoutAlias, patternRegex))
  136. {
  137. return true;
  138. }
  139. }
  140. }
  141. return false;
  142. }
  143. bool AtomToolsFrameworkSystemComponent::IsPathEditable(const AZStd::string& path) const
  144. {
  145. if (!path.empty())
  146. {
  147. const AZStd::string pathWithoutAlias = GetPathWithoutAlias(path);
  148. for (const auto& [storedPath, flag] : m_editablePathSettings)
  149. {
  150. if (pathWithoutAlias == GetPathWithoutAlias(storedPath))
  151. {
  152. return flag;
  153. }
  154. }
  155. }
  156. return true;
  157. }
  158. bool AtomToolsFrameworkSystemComponent::IsPathPreviewable(const AZStd::string& path) const
  159. {
  160. if (!path.empty())
  161. {
  162. const AZStd::string pathWithoutAlias = GetPathWithoutAlias(path);
  163. for (const auto& [storedPath, flag] : m_previewablePathSettings)
  164. {
  165. if (pathWithoutAlias == GetPathWithoutAlias(storedPath))
  166. {
  167. return flag;
  168. }
  169. }
  170. }
  171. return true;
  172. }
  173. } // namespace AtomToolsFramework