123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <AzCore/Component/EntityId.h>
- #include <AzCore/Memory/SystemAllocator.h>
- #include <AzToolsFramework/Undo/UndoSystem.h>
- #include <ScriptCanvas/Bus/UndoBus.h>
- #include <ScriptCanvas/Core/Core.h>
- namespace ScriptCanvasEditor
- {
- class GraphItemCommandNotifications
- : public AZ::EBusTraits
- {
- public:
- static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
- using BusIdType = ScriptCanvas::ScriptCanvasId;
- virtual void PreRestore(const UndoData& /*oldData*/) {};
- virtual void PostRestore(const UndoData& /* restoredData*/) {};
- };
- using GraphItemCommandNotificationBus = AZ::EBus<GraphItemCommandNotifications>;
- // This command is the base URSequencePoint command from which all Script Canvas undo/redo commands derive
- class GraphItemCommand
- : public AzToolsFramework::UndoSystem::URSequencePoint
- {
- public:
- AZ_RTTI(GraphItemCommand, "{94B50FAC-ACAF-4B9B-BA3C-9F3EE36854BA}", AzToolsFramework::UndoSystem::URSequencePoint);
- AZ_CLASS_ALLOCATOR(GraphItemCommand, AZ::SystemAllocator);
- explicit GraphItemCommand(AZStd::string_view friendlyName);
- ~GraphItemCommand() override = default;
- void Undo() override;
- void Redo() override;
- virtual void Capture(EditorGraph* graph, bool captureUndo);
- bool Changed() const override;
- protected:
- GraphItemCommand(const GraphItemCommand&) = delete;
- const GraphItemCommand& operator=(const GraphItemCommand&) = delete;
- virtual void RestoreItem(const AZStd::vector<AZ::u8>& restoreBuffer);
- AZ::EntityId m_graphCanvasGraphId;
- AZ::EntityId m_scriptCanvasEntityId; ///< The id of the ScriptCanvas Entity with the Script Canvas Graph and Graph Canvas Scene
- ScriptCanvas::ScriptCanvasId m_scriptCanvasId;
- AZStd::vector<AZ::u8> m_undoState;
- AZStd::vector<AZ::u8> m_redoState;
- };
- // This commands captures a modification to a Script Canvas graph involving either a ScriptCanvas Node/Connection or a GraphCanvas Node/Connection
- class GraphItemChangeCommand
- : public GraphItemCommand
- {
- public:
- AZ_RTTI(GraphItemChangeCommand, "{9F8805F7-61CD-40FC-B426-020925F4E3DB}", GraphItemCommand);
- AZ_CLASS_ALLOCATOR(GraphItemChangeCommand, AZ::SystemAllocator);
- GraphItemChangeCommand(AZStd::string_view friendlyName);
- ~GraphItemChangeCommand() = default;
- void Undo() override;
- void Redo() override;
- void Capture(EditorGraph* graph, bool captureUndo) override;
- void RestoreItem(const AZStd::vector<AZ::u8>& restoreBuffer) override;
- protected:
- GraphItemChangeCommand(const GraphItemChangeCommand&) = delete;
- const GraphItemChangeCommand& operator=(const GraphItemChangeCommand&) = delete;
- void DeleteOldGraphData(const UndoData& oldData);
- void ActivateRestoredGraphData(const UndoData& restoredData);
- };
- // This command captures when a node or connection is added to the Script Canvas graph.
- class GraphItemAddCommand
- : public GraphItemChangeCommand
- {
- public:
- AZ_RTTI(GraphItemAddCommand, "{01E6BC39-0A2C-4C05-9384-804A63321D62}", GraphItemChangeCommand);
- AZ_CLASS_ALLOCATOR(GraphItemAddCommand, AZ::SystemAllocator);
- explicit GraphItemAddCommand(AZStd::string_view friendlyName);
- ~GraphItemAddCommand() override = default;
- void Undo() override;
- void Redo() override;
- void Capture(EditorGraph* graph, bool captureUndo) override;
- protected:
- GraphItemAddCommand(const GraphItemAddCommand&) = delete;
- const GraphItemAddCommand& operator=(const GraphItemAddCommand&) = delete;
- };
- // This command captures when a node or connection is removed from the Script Canvas graph
- class GraphItemRemovalCommand
- : public GraphItemChangeCommand
- {
- public:
- AZ_RTTI(GraphItemRemovalCommand, "{6257B3EC-E9E8-4419-AA25-2A768C21B635}", GraphItemChangeCommand);
- AZ_CLASS_ALLOCATOR(GraphItemRemovalCommand, AZ::SystemAllocator);
- explicit GraphItemRemovalCommand(AZStd::string_view friendlyName);
- ~GraphItemRemovalCommand() override = default;
- void Undo() override;
- void Redo() override;
- void Capture(EditorGraph* graph, bool captureUndo) override;
- protected:
- GraphItemRemovalCommand(const GraphItemRemovalCommand&) = delete;
- const GraphItemRemovalCommand& operator=(const GraphItemRemovalCommand&) = delete;
- };
- }
|