瀏覽代碼

update to remove references to inbound/outbound slots and make it open to any slot declared in the test, creates a Slot() class for use with the Node() class, remove non-generic functions relating to inbound/outbound

Signed-off-by: NULL <[email protected]>
NULL 2 年之前
父節點
當前提交
dd54832433

+ 34 - 28
AutomatedTesting/Gem/PythonTests/Atom/atom_utils/material_canvas_utils.py

@@ -8,6 +8,7 @@ SPDX-License-Identifier: Apache-2.0 OR MIT
 import azlmbr.atomtools as atomtools
 import azlmbr.editor.graph as graph
 import azlmbr.math as math
+import azlmbr.object
 import azlmbr.bus as bus
 
 import Atom.atom_utils.atom_tools_utils as atom_tools_utils
@@ -52,9 +53,23 @@ class Graph(object):
         node_object = self._create_node_by_name(node_name)
         node_id = graph.GraphControllerRequestBus(
             bus.Event, GraphControllerRequestBusEvents.ADD_NODE, self.graph_id, node_object, position)
+        if not node_id:
+            return  # If the node isn't valid, don't add it.
         self.nodes.append(Node(node_object, node_id, node_name, self.graph_id, position))
 
 
+class Slot(object):
+    """
+    Represents a slot that is part of a Node (required).
+    """
+
+    def __init__(self, slot_name):
+        self.slot_name = slot_name
+        self.id = graph.GraphModelSlotId(slot_name)
+        if not self.id:
+            self.id = None
+
+
 class Node(object):
     """
     Represents a node inside of a Graph (required).
@@ -66,45 +81,36 @@ class Node(object):
         self.node_name = node_name
         self.graph_id = graph_id
         self.position = position
-        self.outbound_slot = graph.GraphModelSlotId('outPosition')
-        self.inbound_slot = graph.GraphModelSlotId('inPositionOffset')
+        self.slots = []
 
-    def connect_to_node_outbound_slot(self, target_node: Node) -> object:
+    def add_slot(self, slot_name: str) -> None:
         """
-        Adds a new connection between this node's inbound slot to target_node's outbound slot.
-        :param target_node: A Node() object for the target node to connect to.
-        :return: azlmbr.object.PythonProxyObject representing a C++ AZStd::shared_ptr<Connection> object.
+        Adds a new Slot object to this Node to identify one of its existing slots.
+        :param slot_name: Name of the slot to lookup using graph.GraphModelSlotId().
+        :return: None, but adds the new slot to the self.slots list.
         """
-        return graph.GraphControllerRequestBus(
-            bus.Event, GraphControllerRequestBusEvents.ADD_CONNECTION_BY_SLOT_ID, self.graph_id,
-            self.node_object, self.inbound_slot, target_node, target_node.outbound_slot)
+        self.slots.append(Slot(slot_name))
 
-    def connect_to_node_inbound_slot(self, target_node: Node) -> object:
+    def connect_slots(self, source_slot: Slot, target_node: (), target_slot: Slot) -> azlmbr.object.PythonProxyObject:
         """
-        Adds a new connection between this node's outbound slot to target_node's inbound slot.
-        :param target_node: A Node() object for the target node to connect to.
+        Connects a starting source_slot to a destination target_slot.
+        :param source_slot: A Slot() object for the source_node in a given Node() object.
+        :param target_node: A Node() object for the target node that holds the target_slot we are connecting to.
+        :param target_slot: A Slot() object for the slot we are connecting to from the source_node.
         :return: azlmbr.object.PythonProxyObject representing a C++ AZStd::shared_ptr<Connection> object.
         """
         return graph.GraphControllerRequestBus(
             bus.Event, GraphControllerRequestBusEvents.ADD_CONNECTION_BY_SLOT_ID, self.graph_id,
-            self.node_object, self.outbound_slot, target_node, target_node.inbound_slot)
-
-    def is_connected_to_node_outbound_slot(self, target_node: Node) -> bool:
-        """
-        Determines if self.node_object's inbound slot is connected to the target_node's outbound slot.
-        :param target_node: A Node() object for the target node to connect to.
-        :return: bool representing success (True) or failure (False)
-        """
-        return graph.GraphControllerRequestBus(
-            bus.Event, GraphControllerRequestBusEvents.ARE_SLOTS_CONNECTED, self.graph_id,
-            self.node_object, self.inbound_slot, target_node, target_node.outbound_slot)
+            self.node_object, source_slot.id, target_node.node_object, target_slot.id)
 
-    def is_connected_to_node_inbound_slot(self, target_node: Node) -> bool:
+    def are_slots_connected(self, source_slot: Slot, target_node: (), target_slot: Slot) -> bool:
         """
-        Determines if self.node_object's outbound slot is connected to the target_node's inbound slot.
-        :param target_node: A Node() object for the target node to connect to.
-        :return: bool representing success (True) or failure (False)
+        Determines if the source_slot is connected to the target_slot on the target_node.
+        :param source_slot: A Slot() object for the source_node in a given Node() object.
+        :param target_node: A Node() object for the target node that should be connected to the source node.
+        :param target_slot: A Slot() object for the slot we should be connected to from the source_node.
+        :return: True if the source_slot and target_slot are connected, False otherwise.
         """
         return graph.GraphControllerRequestBus(
             bus.Event, GraphControllerRequestBusEvents.ARE_SLOTS_CONNECTED, self.graph_id,
-            self.node_object, self.outbound_slot, target_node, target_node.inbound_slot)
+            self.node_object, source_slot.id, target_node.node_object, target_slot.id)

+ 12 - 9
AutomatedTesting/Gem/PythonTests/Atom/tests/MaterialCanvas_Atom_BasicTests.py

@@ -68,7 +68,7 @@ def MaterialCanvas_BasicFunctionalityChecks_AllChecksPass():
     import azlmbr.math as math
 
     import Atom.atom_utils.atom_tools_utils as atom_tools_utils
-    from Atom.atom_utils.material_canvas_utils import Graph, Node
+    from Atom.atom_utils.material_canvas_utils import Graph
     from editor_python_test_tools.utils import Report, Tracer, TestHelper
 
     with Tracer() as error_tracer:
@@ -113,18 +113,18 @@ def MaterialCanvas_BasicFunctionalityChecks_AllChecksPass():
             test_material_graph = Graph(material_graph_document_file)
             Report.result(Tests.verify_all_material_graphs_are_opened,
                           atom_tools_utils.is_document_open(test_material_graph.document_id) is True)
-            test_material_graphs.append(test_material_graph.document_id)
+            test_material_graphs.append(test_material_graph)
 
         # 5. Use the CloseAllDocumentsExcept bus call to close all but test_1_material_graph.
         test_1_material_graph = test_material_graphs[0]
         atom_tools_utils.close_all_except_selected(test_1_material_graph.document_id)
         Report.result(
             Tests.close_all_opened_material_graphs_except_one,
-            atom_tools_utils.is_document_open(test_1_material_graph) is True and
-            atom_tools_utils.is_document_open(test_material_graphs[1]) is False and
-            atom_tools_utils.is_document_open(test_material_graphs[2]) is False and
-            atom_tools_utils.is_document_open(test_material_graphs[3]) is False and
-            atom_tools_utils.is_document_open(test_material_graphs[4]) is False)
+            atom_tools_utils.is_document_open(test_1_material_graph.document_id) is True and
+            atom_tools_utils.is_document_open(test_material_graphs[1].document_id) is False and
+            atom_tools_utils.is_document_open(test_material_graphs[2].document_id) is False and
+            atom_tools_utils.is_document_open(test_material_graphs[3].document_id) is False and
+            atom_tools_utils.is_document_open(test_material_graphs[4].document_id) is False)
 
         # 6. Verify Node Palette pane visibility.
         atom_tools_utils.set_pane_visibility("Node Palette", True)
@@ -152,8 +152,11 @@ def MaterialCanvas_BasicFunctionalityChecks_AllChecksPass():
             standard_pbr_node.node_object.typename == "AZStd::shared_ptr<Node>")
 
         # 10. Create a node connection between world_position_node outbound slot and standard_pbr_node inbound slot.
-        world_position_node.connect_to_node_inbound_slot(standard_pbr_node)
-        are_slots_connected = world_position_node.is_connected_to_node_inbound_slot(standard_pbr_node)
+        world_position_node.add_slot('outPosition')
+        standard_pbr_node.add_slot('inPositionOffset')
+        world_position_node.connect_slots(world_position_node.slots[0], standard_pbr_node, standard_pbr_node.slots[0])
+        are_slots_connected = world_position_node.are_slots_connected(
+            world_position_node.slots[0], standard_pbr_node, standard_pbr_node.slots[0])
         Report.result(Tests.nodes_connected, are_slots_connected is True)
 
         # 11. Look for errors and asserts.