You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/GraphModel/Code/Source/Model/Connection.cpp

101 lines
3.0 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// AZ
#include <AzCore/PlatformDef.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
// Graph Model
#include <GraphModel/Model/Connection.h>
#include <GraphModel/Model/Node.h>
#include <GraphModel/Model/Graph.h>
namespace GraphModel
{
Connection::Connection(GraphPtr graph, SlotPtr sourceSlot, SlotPtr targetSlot)
: GraphElement(graph)
, m_sourceSlot(sourceSlot)
, m_targetSlot(targetSlot)
{
AZ_Assert(sourceSlot->SupportsConnections(), "sourceSlot type does not support connections to other slots");
AZ_Assert(targetSlot->SupportsConnections(), "targetSlot type does not support connections to other slots");
const NodeId sourceNodeId = sourceSlot->GetParentNode()->GetId();
const NodeId targetNodeId = targetSlot->GetParentNode()->GetId();
m_sourceEndpoint = AZStd::make_pair(sourceNodeId, sourceSlot->GetSlotId());
m_targetEndpoint = AZStd::make_pair(targetNodeId, targetSlot->GetSlotId());
}
void Connection::PostLoadSetup(GraphPtr graph)
{
m_graph = graph;
m_sourceSlot = azrtti_cast<Slot*>(graph->FindSlot(m_sourceEndpoint));
m_targetSlot = azrtti_cast<Slot*>(graph->FindSlot(m_targetEndpoint));
}
void Connection::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<Connection>()
->Version(0)
->Field("m_sourceEndpoint", &Connection::m_sourceEndpoint)
->Field("m_targetEndpoint", &Connection::m_targetEndpoint)
;
}
}
NodePtr Connection::GetSourceNode() const
{
if (GetSourceSlot())
{
return GetSourceSlot()->GetParentNode();
}
return nullptr;
}
NodePtr Connection::GetTargetNode() const
{
if (GetTargetSlot())
{
return GetTargetSlot()->GetParentNode();
}
return nullptr;
}
SlotPtr Connection::GetSourceSlot() const
{
return m_sourceSlot.lock();
}
SlotPtr Connection::GetTargetSlot() const
{
return m_targetSlot.lock();
}
const Endpoint& Connection::GetSourceEndpoint() const
{
return m_sourceEndpoint;
}
const Endpoint& Connection::GetTargetEndpoint() const
{
return m_targetEndpoint;
}
} // namespace GraphModel