void TryAddStackIndex(IStackModel stack, int index) { if (!m_StackIndexes.ContainsKey(stack)) { m_StackIndexes.Add(stack, index); } }
public ChangeStackedNodeAction(INodeModel oldNodeModel, IStackModel stackModel, StackNodeModelSearcherItem selectedItem) { OldNodeModel = oldNodeModel; StackModel = stackModel; SelectedItem = selectedItem; }
public StackNodeCreationData(IStackModel stackModel, int index, SpawnFlags spawnFlags = SpawnFlags.Default) { StackModel = stackModel; Index = index; SpawnFlags = spawnFlags; }
public virtual SearcherFilter GetStackSearcherFilter(IStackModel stackModel) { return(new SearcherFilter(SearcherContext.Stack) .WithVisualScriptingNodes(stackModel) .WithUnaryOperators() .WithMacros()); }
public StackNode(Store store, IStackModel stackModel, INodeBuilder builder) { m_Store = store; this.stackModel = stackModel; m_GraphView = builder.GraphView; styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "StackNode.uss")); style.overflow = Overflow.Visible; var borderItem = this.MandatoryQ("borderItem"); borderItem.style.overflow = Overflow.Visible; this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent)); RegisterCallback <AttachToPanelEvent>(OnEnterPanel); RegisterCallback <DetachFromPanelEvent>(OnLeavePanel); RegisterCallback <CustomStyleResolvedEvent>(OnCustomStyleResolved); userData = stackModel; UpdateFromModel(); inputContainer.pickingMode = PickingMode.Ignore; outputContainer.pickingMode = PickingMode.Ignore; PopulateStack(m_GraphView, store, stackModel, this); }
public SearcherFilter WithControlFlow(Type type, IStackModel stackModel) { this.RegisterControlFlow(data => data.Type != null && type.IsAssignableFrom(data.Type) && stackModel.AcceptNode(type)); return(this); }
public StackNode(Store store, IStackModel stackModel, INodeBuilder builder) { m_Store = store; this.stackModel = stackModel; m_GraphView = builder.GraphView; styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "StackNode.uss")); // @TODO: This might need to be reviewed in favor of a better / more scalable approach (non preprocessor based) // that would ideally bring the same level of backward/forward compatibility and/or removed when a 2013 beta version lands. #if UNITY_2019_3_OR_NEWER styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "StackNode.2019.3.uss")); #endif style.overflow = Overflow.Visible; var borderItem = this.MandatoryQ("borderItem"); borderItem.style.overflow = Overflow.Visible; this.AddManipulator(new ContextualMenuManipulator(OnContextualMenuEvent)); RegisterCallback <AttachToPanelEvent>(OnEnterPanel); RegisterCallback <DetachFromPanelEvent>(OnLeavePanel); RegisterCallback <CustomStyleResolvedEvent>(OnCustomStyleResolved); userData = stackModel; UpdateFromModel(); inputContainer.pickingMode = PickingMode.Ignore; outputContainer.pickingMode = PickingMode.Ignore; PopulateStack(m_GraphView, store, stackModel, this); }
public CreateStackedNodeFromSearcherAction(IStackModel stackModel, int index, StackNodeModelSearcherItem selectedItem) { StackModel = stackModel; Index = index; SelectedItem = selectedItem; }
public void RegisterBuiltStack(IStackModel stackModel) { if (!m_BuiltStacks.Add(stackModel)) { throw new LoopDetectedException($"stack already built: {stackModel.GetId()} number of inputs: {stackModel.InputPorts[0].ConnectionPortModels.Count()}"); } }
public static SearcherFilter WithControlFlowExcept(this SearcherFilter self, IStackModel stackModel, IEnumerable <Type> exceptions) { self.RegisterControlFlow(data => !exceptions.Any(e => e.IsAssignableFrom(data.Type)) && stackModel.AcceptNode(data.Type)); return(self); }
public CreateStackedNodeFromSearcherAction(IStackModel stackModel, int index, StackNodeModelSearcherItem selectedItem, IReadOnlyList <GUID> guids = null) { StackModel = stackModel; Index = index; SelectedItem = selectedItem; Guids = guids; }
public StackNodeCreationData(IStackModel stackModel, int index, SpawnFlags spawnFlags = SpawnFlags.Default, IReadOnlyList <GUID> guids = null) { StackModel = stackModel; Index = index; SpawnFlags = spawnFlags; Guids = guids; }
protected override void VisitStack(IStackModel stack, HashSet <IStackModel> visitedStacks, HashSet <INodeModel> visitedNodes) { base.VisitStack(stack, visitedStacks, visitedNodes); foreach (var callback in Callbacks) { callback(stack); } }
public CreateStackedNodeFromOutputPortAction(IPortModel portModel, IStackModel stackModel, int index, StackNodeModelSearcherItem selectedItem, IEnumerable <IGTFEdgeModel> edgesToDelete = null) { PortModel = portModel; StackModel = stackModel; Index = index; SelectedItem = selectedItem; EdgesToDelete = edgesToDelete ?? Enumerable.Empty <IGTFEdgeModel>(); }
public CreateInsertLoopNodeAction(IPortModel portModel, IStackModel stackModel, int index, LoopStackModel loopStackModel, IEnumerable <IEdgeModel> edgesToDelete = null) { PortModel = portModel; StackModel = stackModel; Index = index; LoopStackModel = loopStackModel; EdgesToDelete = edgesToDelete ?? Enumerable.Empty <IEdgeModel>(); }
public SearcherFilter WithIfConditions(TypeHandle inputType, IStackModel stackModel) { this.RegisterControlFlow(data => data.Type == typeof(IfConditionNodeModel) && stackModel.AcceptNode(data.Type) && inputType == TypeHandle.Bool ); return(this); }
static void CreateNodes(Store store, IPortModel portModel, Vector2 position, IEnumerable <IEdgeModel> edgesToDelete, IStackModel stackModel, int index, IGroupNodeModel groupModel) { switch (portModel.PortType) { case PortType.Data: case PortType.Instance: switch (portModel.Direction) { case Direction.Output when stackModel != null: if (portModel.DataType != TypeHandle.Unknown) { SearcherService.ShowOutputToStackNodes( store.GetState(), stackModel, portModel, position, item => { store.Dispatch(new CreateStackedNodeFromOutputPortAction( portModel, stackModel, index, item, edgesToDelete, groupModel)); }); } break; case Direction.Output: SearcherService.ShowOutputToGraphNodes(store.GetState(), portModel, position, item => { store.Dispatch(new CreateNodeFromOutputPortAction( portModel, position, item, edgesToDelete, groupModel)); }); break; case Direction.Input: SearcherService.ShowInputToGraphNodes(store.GetState(), portModel, position, item => { store.Dispatch(new CreateNodeFromInputPortAction( portModel, position, item, edgesToDelete, groupModel)); }); break; default: throw new ArgumentOutOfRangeException(); } break; case PortType.Execution: if (portModel.NodeModel is LoopStackModel loopStack && portModel.Direction == Direction.Input) { if (stackModel != null) { store.Dispatch(new CreateInsertLoopNodeAction( portModel, stackModel, index, loopStack, edgesToDelete, groupModel)); } } else { store.Dispatch(new CreateNodeFromExecutionPortAction( portModel, position, edgesToDelete, groupModel)); } break;
static void OnDropOutsideCallback(Store store, Vector2 pos, Edge edge) { VseGraphView graphView = edge.GetFirstAncestorOfType <VseGraphView>(); Vector2 worldPos = pos; pos = graphView.contentViewContainer.WorldToLocal(pos); List <IEdgeModel> edgesToDelete = GetDropEdgeModelsToDelete(edge); // when grabbing an existing edge's end, the edgeModel should be deleted if ((edge).GraphElementModel != null) { edgesToDelete.Add((IEdgeModel)edge.GraphElementModel); } IStackModel targetStackModel = null; int targetIndex = -1; IGroupNodeModel groupModel = null; StackNode stackNode = graphView.lastHoveredVisualElement as StackNode ?? graphView.lastHoveredVisualElement.GetFirstOfType <StackNode>(); if (stackNode != null) { targetStackModel = stackNode.stackModel; targetIndex = stackNode.GetInsertionIndex(worldPos); } else if (graphView.lastHoveredVisualElement is Group group) { groupModel = group.model; } IPortModel existingPortModel; // warning: when dragging the end of an existing edge, both ports are non null. if (edge.input != null && edge.output != null) { float distanceToOutput = Vector2.Distance(edge.edgeControl.from, pos); float distanceToInput = Vector2.Distance(edge.edgeControl.to, pos); // note: if the user was able to stack perfectly both ports, we'd be in trouble if (distanceToOutput < distanceToInput) { existingPortModel = (IPortModel)edge.input.userData; } else { existingPortModel = (IPortModel)edge.output.userData; } } else { Port existingPort = (Port)(edge.input ?? edge.output); existingPortModel = existingPort.userData as IPortModel; } CreateNodes(store, existingPortModel, pos, edgesToDelete, targetStackModel, targetIndex, groupModel); }
// This will find a common descendant stack for both inputs // ie. FindCommonDescendant(A, B) => E // Note: if c wasn't connected to E, A and B would not have a common descendant, // as no descendant of B would be reachable from C // Root // / \ // A B // / \ | // C D | // \__\ / // E // we need to keep two sets/queues, one per initial branch // another solution would be to keep an Ancestor hashset associated to each stack model // and find a non empty union public static StackBaseModel FindCommonDescendant(IStackModel root, StackBaseModel a, StackBaseModel b) { var stackModels = new HashSet <IStackModel>(); if (root != a && root != b) { stackModels.Add(root); } return(FindCommonDescendant(stackModels, a, b)); }
public static void ShowOutputToStackNodes(State state, IStackModel stackModel, IPortModel portModel, Vector2 position, Action <StackNodeModelSearcherItem> callback) { var stencil = state.CurrentGraphModel.Stencil; var filter = stencil.GetSearcherFilterProvider()?.GetOutputToStackSearcherFilter(portModel, stackModel); var adapter = stencil.GetSearcherAdapter(stackModel, "Add a stack Node"); var dbProvider = stencil.GetSearcherDatabaseProvider(); var dbs = dbProvider.GetGraphElementsSearcherDatabases().ToList(); PromptSearcher(dbs, filter, adapter, position, callback); }
public virtual SearcherFilter GetStackSearcherFilter(IStackModel stackModel) { return(new SearcherFilter(SearcherContext.Stack) .WithVisualScriptingNodes(stackModel) .WithUnaryOperators() .WithControlFlows(stackModel) .WithProperties() .WithMethods() .WithFunctionReferences() .WithMacros()); }
void BuildStackContextualMenu(IReadOnlyCollection <IGraphElementModel> selectedModels) { IStackModel firstModel = selectedModels.Where(x => x is IStackModel).Cast <IStackModel>().FirstOrDefault(); if (firstModel != null) { m_Evt.menu.AppendAction("Create Node", menuAction => { m_GraphView.window.DisplaySmartSearch(menuAction); }, DropdownMenuAction.AlwaysEnabled); } }
protected virtual void VisitStack(IStackModel stack, HashSet <IStackModel> visitedStacks, HashSet <INodeModel> visitedNodes) { visitedStacks.Add(stack); // instance/data ports on stacks foreach (var inputPortModel in stack.InputPorts) { if (inputPortModel.PortType != PortType.Execution && inputPortModel.Connected) { bool any = false; foreach (var connectionPortModel in inputPortModel.ConnectionPortModels) { if (!visitedNodes.Contains(connectionPortModel.NodeModel)) { VisitNode(connectionPortModel.NodeModel, visitedNodes); } any = true; stack.OnConnection(inputPortModel, connectionPortModel); } if (!any) { stack.OnConnection(inputPortModel, null); } } } // Still not visiting variable parameters... if (stack is IHasVariableDeclaration hasVariableDeclaration) { foreach (var variableDeclaration in hasVariableDeclaration.VariableDeclarations) { VisitVariableDeclaration(variableDeclaration); } } foreach (INodeModel nodeModel in stack.NodeModels) { VisitNode(nodeModel, visitedNodes); } foreach (StackBaseModel connectedStack in RoslynTranslator.GetConnectedStacks(stack)) { if (connectedStack == null || visitedStacks.Contains(connectedStack)) { continue; } VisitStack(connectedStack, visitedStacks, visitedNodes); } }
EventPropagation OnCreateLogNode(LogNodeModel.LogTypes logType) { var stack = m_GraphView.lastHoveredSmartSearchCompatibleElement as StackNode; IStackModel stackModel = stack?.stackModel; if (stackModel != null) { m_Store.Dispatch(new CreateLogNodeAction(stackModel, logType)); return(EventPropagation.Stop); } return(EventPropagation.Continue); }
public static bool ContainsCoroutine(this IStackModel stack) { if (s_Visited == null) { s_Visited = new HashSet <IStackModel>(); } else { s_Visited.Clear(); } s_Visited.Add(stack); return(ContainsCoroutine(stack, s_Visited)); }
internal static void ShowStackNodes(State state, IStackModel stackModel, Vector2 position, Action <StackNodeModelSearcherItem> callback, ISearcherAdapter searcherAdapter = null) { var stencil = state.CurrentGraphModel.Stencil; var filter = stencil.GetSearcherFilterProvider()?.GetStackSearcherFilter(stackModel); var adapter = searcherAdapter ?? new StackNodeSearcherAdapter(stackModel, "Add a stack node"); var dbProvider = stencil.GetSearcherDatabaseProvider(); var dbs = dbProvider.GetGraphElementsSearcherDatabases() .Concat(dbProvider.GetReferenceItemsSearcherDatabases()) .ToList(); PromptSearcher(dbs, filter, adapter, position, callback); }
static IStackModel GetNextStack(IStackModel stack) { foreach (var outputPort in stack.OutputPorts) { foreach (var connectionPortModel in outputPort.ConnectionPortModels) { if (connectionPortModel.NodeModel is IStackModel nextStack) { return(nextStack); } } } return(null); }
static void PopulateStack(GraphView graphView, Store store, IStackModel stackModel, StackNode stack) { foreach (var nodeModel in stackModel.NodeModels) { var node = GraphElementFactory.CreateUI(graphView, store, nodeModel); if (node != null) { stack.AddElement(node); ((VseGraphView)graphView).AddPositionDependency( stack.stackModel, (INodeModel)((IHasGraphElementModel)node).GraphElementModel); node.style.position = Position.Relative; } } }
static void PopulateStack(GraphView graphView, Store store, IStackModel stackModel, StackNode stack) { foreach (var nodeModel in stackModel.NodeModels) { if (GraphElementFactory.CreateUI <GraphElement>(graphView, store, nodeModel as IGTFNodeModel) is GraphElement node) { stack.AddElement(node); if (graphView is VseGraphView vseGraphView) { vseGraphView.AddPositionDependency(stack.StackModel, nodeModel); } node.style.position = Position.Relative; } } }
public override SearcherFilter GetStackSearcherFilter(IStackModel stackModel) { if (stackModel is IPrivateIteratorStackModel ism && ism.Mode == UpdateMode.OnEnd) { return(new SearcherFilter(SearcherContext.Stack) .WithVisualScriptingNodes(stackModel) .WithUnaryOperators() .WithControlFlowExcept(stackModel, new[] { typeof(ICoroutine) }) .WithProperties() .WithMethods() .WithFunctionReferences() .WithMacros()); } return(base.GetStackSearcherFilter(stackModel)); }