// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved. #include "NiagaraConvertPinViewModel.h" #include "NiagaraNodeConvert.h" #include "NiagaraConvertNodeViewModel.h" #include "NiagaraConvertPinSocketViewModel.h" #include "EdGraphSchema_Niagara.h" FNiagaraConvertPinViewModel::FNiagaraConvertPinViewModel(TSharedRef InOwnerConvertNodeViewModel, UEdGraphPin& InGraphPin) : OwnerConvertNodeViewModel(InOwnerConvertNodeViewModel) , GraphPin(InGraphPin) , bSocketViewModelsNeedRefresh(true) { } FGuid FNiagaraConvertPinViewModel::GetPinId() const { return GraphPin.PinId; } UEdGraphPin& FNiagaraConvertPinViewModel::GetGraphPin() { return GraphPin; } const TArray>& FNiagaraConvertPinViewModel::GetSocketViewModels() { if (bSocketViewModelsNeedRefresh) { RefreshSocketViewModels(); } return SocketViewModels; } TSharedPtr FNiagaraConvertPinViewModel::GetOwnerConvertNodeViewModel() { return OwnerConvertNodeViewModel.Pin(); } void GenerateSocketViewModelsRecursive(TSharedRef OwnerPinViewModel, TSharedPtr OwnerPinSocketViewModel, EEdGraphPinDirection Direction, const UStruct* Struct, TArray>& SocketViewModels) { for (TFieldIterator PropertyIterator(Struct); PropertyIterator; ++PropertyIterator) { UProperty* Property = *PropertyIterator; if (Property != nullptr) { TSharedRef SocketViewModel = MakeShareable(new FNiagaraConvertPinSocketViewModel(OwnerPinViewModel, OwnerPinSocketViewModel, Property->GetFName(), Direction)); UStructProperty* StructProperty = Cast(Property); if (StructProperty != nullptr) { TArray> ChildSocketViewModels; GenerateSocketViewModelsRecursive(OwnerPinViewModel, SocketViewModel, Direction, StructProperty->Struct, ChildSocketViewModels); SocketViewModel->SetChildSockets(ChildSocketViewModels); } SocketViewModels.Add(SocketViewModel); } } } void FNiagaraConvertPinViewModel::RefreshSocketViewModels() { SocketViewModels.Empty(); const UEdGraphSchema_Niagara* Schema = Cast(GraphPin.GetSchema()); GenerateSocketViewModelsRecursive(this->AsShared(), TSharedPtr(), GraphPin.Direction, Schema->PinToTypeDefinition(&GraphPin).GetStruct(), SocketViewModels); bSocketViewModelsNeedRefresh = false; }