Esempio n. 1
0
        protected override void OnElementsAdded(IEnumerable <GraphElement> elements)
        {
            List <GraphElement> elementsList = elements.ToList();

            base.OnElementsAdded(elementsList);
            if (!m_Populating)
            {
                INodeModel[] nodeModels = elementsList.OfType <IHasGraphElementModel>().Select(e => e.GraphElementModel).OfType <INodeModel>().ToArray();

                List <Tuple <IVariableDeclarationModel, Vector2> > variablesToCreate =
                    DragAndDropHelper.ExtractVariablesFromDroppedElements(elementsList,
                                                                          (VseGraphView)m_GraphView,
                                                                          Event.current.mousePosition);
                if (variablesToCreate.Any())
                {
                    if (nodeModels.Any(e => !(e is IVariableModel)))
                    {
                        // fail because in the current setup this would mean dispatching several actions
                        throw new ArgumentException("Unhandled case, dropping blackboard/variables fields and nodes at the same time");
                    }
                    m_Store.Dispatch(new CreateVariableNodesAction(variablesToCreate, model));
                }
                else
                {
                    Node firstStackedNode = elementsList.OfType <Node>().FirstOrDefault(n => n.IsInStack && n.Stack == null && n.model != null);
                    m_Store.Dispatch(new AddToGroupNodeAction(model, firstStackedNode?.layout.position ?? Vector2.negativeInfinity, nodeModels));

                    // We now need to remove all newly added nodes that were actually added to a stack (and thus not directly to a group).
                    RemoveElementsWithoutNotification(elementsList.OfType <Node>().Where(n => n.IsInStack));
                }
            }
        }
Esempio n. 2
0
        public bool DragPerform(DragPerformEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget, ISelection dragSource)
        {
            if (GraphView == null)
            {
                return(false);
            }

            List <ISelectable>  selectionList = selection.ToList();
            List <GraphElement> dropElements  = selectionList.OfType <GraphElement>().ToList();

            Assert.IsTrue(dropElements.Count == 1);
            GraphElement elementToDrop = dropElements.First();

            var edgesToDelete = capacity == Capacity.Multi ? new List <IEdgeModel>() : connections.Select(c => ((Edge)c).model).ToList();

            if (IsTokenToDrop(selectionList[0]))
            {
                Token token = ((Token)selectionList[0]);
                token.NeedStoreDispatch = true;
                m_Store.Dispatch(new CreateEdgeAction(Model, ((IVariableModel)token.GraphElementModel).OutputPort, edgesToDelete, CreateEdgeAction.PortAlignmentType.Input));
                return(true);
            }

            List <Tuple <IVariableDeclarationModel, Vector2> > variablesToCreate = DragAndDropHelper.ExtractVariablesFromDroppedElements(dropElements, GraphView, evt.mousePosition);

            PortType type = ((IPortModel)userData).PortType;

            if (type != PortType.Data && type != PortType.Instance) // do not connect loop/exec ports to variables
            {
                return(GraphView.DragPerform(evt, selectionList, dropTarget, dragSource));
            }

            IVariableDeclarationModel varModelToCreate = variablesToCreate.Single().Item1;

            m_Store.Dispatch(new CreateVariableNodesAction(varModelToCreate, evt.mousePosition, edgesToDelete, (IPortModel)userData, autoAlign: true));

            GraphView.ClearPlaceholdersAfterDrag();

            return(true);
        }