public void AddPositionDependency(IEdgeModel model) { IDependency dependency = CreateDependencyFromEdge(model, out INodeModel parent); Add(parent, dependency); LogDependencies(); }
static LinkedNodesDependency CreateDependencyFromEdge(IEdgeModel model, out INodeModel parent) { LinkedNodesDependency dependency; if (model.InputPortModel.NodeModel is IStackModel && model.InputPortModel.PortType != PortType.Instance) { dependency = new LinkedNodesDependency { DependentPort = model.InputPortModel, ParentPort = model.OutputPortModel, count = 1, }; parent = model.OutputPortModel.NodeModel; } else { dependency = new LinkedNodesDependency { DependentPort = model.OutputPortModel, ParentPort = model.InputPortModel, }; parent = model.InputPortModel.NodeModel; } return(dependency); }
public override bool CreateDependencyFromEdge(IEdgeModel model, out LinkedNodesDependency linkedNodesDependency, out INodeModel parent) { var outputNode = model.OutputPortModel.NodeModel; var inputNode = model.InputPortModel.NodeModel; bool outputIsData = outputNode.IsDataNode(); bool inputIsData = inputNode.IsDataNode(); if (outputIsData) { parent = inputNode; linkedNodesDependency = new LinkedNodesDependency { count = 1, DependentPort = model.OutputPortModel, ParentPort = model.InputPortModel, }; return(true); } if (!inputIsData) { parent = outputNode; linkedNodesDependency = new LinkedNodesDependency { count = 1, DependentPort = model.InputPortModel, ParentPort = model.OutputPortModel, }; return(true); } linkedNodesDependency = default; parent = default; return(false); }
public static List <IEdgeModel> GetDropEdgeModelsToDelete(IEdgeModel edge) { List <IEdgeModel> edgeModelsToDelete = new List <IEdgeModel>(); if (edge.ToPort != null && edge.ToPort.Capacity == PortCapacity.Single) { foreach (var edgeToDelete in edge.ToPort.GetConnectedEdges()) { if (!ReferenceEquals(edgeToDelete, edge) && !(edgeToDelete is GhostEdgeModel)) { edgeModelsToDelete.Add(edgeToDelete); } } } if (edge.FromPort != null && edge.FromPort.Capacity == PortCapacity.Single) { foreach (var edgeToDelete in edge.FromPort.GetConnectedEdges()) { if (!ReferenceEquals(edgeToDelete, edge) && !(edgeToDelete is GhostEdgeModel)) { edgeModelsToDelete.Add(edgeToDelete); } } } return(edgeModelsToDelete); }
public CreateNodeOnEdgeAction(IEdgeModel edgeModel, Vector2 position, GraphNodeModelSearcherItem selectedItem) { EdgeModel = edgeModel; Position = position; SelectedItem = selectedItem; }
public MoveEdgeControlPointAction(IEdgeModel edgeModel, int edgeIndex, Vector2 newPosition, float newTightness) { EdgeModel = edgeModel; EdgeIndex = edgeIndex; NewPosition = newPosition; NewTightness = newTightness; }
public CreateNodeOnEdgeAction(IEdgeModel edgeModel, Vector2 position, GraphNodeModelSearcherItem selectedItem, GUID?guid = null) { EdgeModel = edgeModel; Position = position; SelectedItem = selectedItem; Guid = guid; }
void Connect(IEdgeModel edgeModel, IGTFPortModel output, IGTFPortModel input) { var edge = GraphElementFactory.CreateUI <Edge>(m_GraphView, m_Store, edgeModel as IGTFEdgeModel); AddToGraphView(edge); m_GraphView.AddPositionDependency(edge.VSEdgeModel); }
/// <summary> /// Initializes a new CreateNodeFromSearcherCommand. /// </summary> /// <param name="edgeModel">The edge model on which to insert the newly created node.</param> /// <param name="position">The position where to create the node.</param> /// <param name="selectedItem">The searcher item representing the node to create.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item. If none is provided, a new /// SerializableGUID will be generated for it.</param> public CreateNodeOnEdgeCommand(IEdgeModel edgeModel, Vector2 position, GraphNodeModelSearcherItem selectedItem, SerializableGUID guid = default) : this() { EdgeModel = edgeModel; Position = position; SelectedItem = selectedItem; Guid = guid.Valid ? guid : SerializableGUID.Generate(); }
public void AddPositionDependency(IEdgeModel model) { if (!model.GraphModel.Stencil.CreateDependencyFromEdge(model, out var dependency, out INodeModel parent)) { return; } Add(parent, dependency); LogDependencies(); }
/// <summary> /// Makes the edge last in the port's list of edges. /// </summary> /// <param name="self">The port.</param> /// <param name="edge">The edge to reorder.</param> public static void MoveEdgeLast(IReorderableEdgesPortModel self, IEdgeModel edge) { if (!self.HasReorderableEdges) { return; } self.GraphModel.MoveBefore(new[] { edge }, null); }
public static void ShowEdgeNodes(State state, IEdgeModel edgeModel, Vector2 position, Action <GraphNodeModelSearcherItem> callback) { var stencil = state.CurrentGraphModel.Stencil; var filter = stencil.GetSearcherFilterProvider()?.GetEdgeSearcherFilter(edgeModel); var adapter = stencil.GetSearcherAdapter(state.CurrentGraphModel, "Insert Node"); var dbProvider = stencil.GetSearcherDatabaseProvider(); var dbs = dbProvider.GetGraphElementsSearcherDatabases().ToList(); PromptSearcher(dbs, filter, adapter, position, callback); }
/// <inheritdoc /> public virtual bool CreateDependencyFromEdge(IEdgeModel edgeModel, out LinkedNodesDependency linkedNodesDependency, out INodeModel parentNodeModel) { linkedNodesDependency = new LinkedNodesDependency { DependentPort = edgeModel.FromPort, ParentPort = edgeModel.ToPort, }; parentNodeModel = edgeModel.ToPort.NodeModel; return(true); }
public virtual SearcherFilter GetEdgeSearcherFilter(IEdgeModel edgeModel) { Type it = edgeModel.InputPortModel.DataTypeHandle.Resolve(m_Stencil); IPortModel opm = edgeModel.OutputPortModel; TypeHandle oth = opm.DataTypeHandle == TypeHandle.ThisType ? m_Stencil.GetThisType() : opm.DataTypeHandle; Type ot = oth.Resolve(m_Stencil); return(new SearcherFilter(SearcherContext.Graph) .WithVisualScriptingNodesExcept(new[] { typeof(ThisNodeModel) }) // TODO : We should be able to determine if a VSNode type has input port instead of doing this .WithUnaryOperators(ot, opm.NodeModel is IConstantNodeModel) .WithBinaryOperators(ot)); }
public Edge(IEdgeModel edgeModel) : this() { m_EdgeModel = edgeModel; capabilities = VseUtility.ConvertCapabilities(m_EdgeModel); PortType portType = m_EdgeModel?.OutputPortModel?.PortType ?? PortType.Data; EnableInClassList("execution", portType == PortType.Execution || portType == PortType.Loop); EnableInClassList("event", portType == PortType.Event); viewDataKey = m_EdgeModel?.GetId(); }
bool RestoreEdge(IEdgeModel edge) { var inputPortModel = (PortModel)edge.InputPortModel; var outputPortModel = (PortModel)edge.OutputPortModel; if (inputPortModel != null && outputPortModel != null) { Connect(edge, outputPortModel, inputPortModel); return(true); } return(false); }
private void HandleAttributes(XmlTextReader reader, String curTypeName, INode curNode) { for (int attrIndex = 0; attrIndex < reader.AttributeCount; ++attrIndex) { reader.MoveToAttribute(attrIndex); // skip attributes not giving references=edges String name = reader.Name; if (name.StartsWith("xmi:") || name == "xsi:type" || name == "xsi:schemaLocation" || name.StartsWith("xmlns:")) { continue; } String attrRefType = FindRefTypeName(curTypeName, name); if (attrRefType != null) { // List of references as in attribute separated by spaces String refEdgeTypeName = FindContainingTypeName(curTypeName, name); String grgenRefEdgeTypeName = GrGenTypeNameFromXmi(refEdgeTypeName) + "_" + name; IEdgeModel edgeModel = graph.Model.EdgeModel; String[] destNodeNames = reader.Value.Split(' '); if (IsRefOrdered(curTypeName, name)) { int i = 0; foreach (String destNodeName in destNodeNames) { IEdge parentEdge = graph.AddEdge(edgeModel.GetType(grgenRefEdgeTypeName), curNode, GetNode(destNodeName)); parentEdge.SetAttribute("ordering", i); ++i; } } else { foreach (String destNodeName in destNodeNames) { graph.AddEdge(edgeModel.GetType(grgenRefEdgeTypeName), curNode, GetNode(destNodeName)); } } } else { if (name == "href") // skip href attributes { continue; } AssignAttribute(curNode, name, reader.Value); } } }
void BuildEdgeContextualMenu(IReadOnlyCollection<IGraphElementModel> selectedModels) { IEdgeModel firstMatchingModel = selectedModels .OfType<IEdgeModel>() .FirstOrDefault(x => x.InputPortModel?.NodeModel is IStackModel && x.OutputPortModel?.NodeModel is IStackModel); if (firstMatchingModel != null) { m_Evt.menu.AppendAction("Edge/Merge", menuAction => m_Store.Dispatch(new MergeStackAction( (StackBaseModel)firstMatchingModel.OutputPortModel.NodeModel, (StackBaseModel)firstMatchingModel.InputPortModel.NodeModel)), eventBase => DropdownMenuAction.Status.Normal); } }
void Connect(IEdgeModel edgeModel, Experimental.GraphView.Port output, Experimental.GraphView.Port input) { var edge = new Edge(edgeModel); AddToGraphView(edge); edge.input = input; edge.output = output; edge.input.Connect(edge); edge.output.Connect(edge); m_GraphView.AddPositionDependency(edge.model); }
bool RestoreEdge(IEdgeModel edge, Dictionary <PortModel, Experimental.GraphView.Port> portsByModel) { var inputPortModel = (PortModel)edge.InputPortModel; var outputPortModel = (PortModel)edge.OutputPortModel; if (inputPortModel != null && outputPortModel != null && portsByModel.TryGetValue(inputPortModel, out var i) && portsByModel.TryGetValue(outputPortModel, out var o)) { Connect(edge, o, i); return(true); } return(false); }
/// <summary> /// Makes the edge up in the port's list of edges. /// </summary> /// <param name="self">The port.</param> /// <param name="edge">The edge to reorder.</param> public static void MoveEdgeUp(IReorderableEdgesPortModel self, IEdgeModel edge) { if (!self.HasReorderableEdges) { return; } var edges = self.GetConnectedEdges().ToList(); var idx = edges.IndexOf(edge); if (idx >= 1) { self.GraphModel.MoveBefore(new[] { edge }, edges[idx - 1]); } }
/// <summary> /// Makes the edge down in the port's list of edges. /// </summary> /// <param name="self">The port.</param> /// <param name="edge">The edge to reorder.</param> public static void MoveEdgeDown(IReorderableEdgesPortModel self, IEdgeModel edge) { if (!self.HasReorderableEdges) { return; } var edges = self.GetConnectedEdges().ToList(); var idx = edges.IndexOf(edge); if (idx < edges.Count - 1) { self.GraphModel.MoveAfter(new[] { edge }, edges[idx + 1]); } }
static State SplitStack(State previousState, SplitStackAction action) { VSGraphModel graphModel = (VSGraphModel)previousState.CurrentGraphModel; Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Move stacked nodes"); if (action.SplitIndex > 0 && action.SplitIndex < action.StackModel.NodeModels.Count()) { // Get the list of nodes to move to another stack. var nodeModels = action.StackModel.NodeModels.Skip(action.SplitIndex).ToList(); if (nodeModels.Any()) { // Get old stack (stack A) var stackA = action.StackModel; // Create new stack (stack B). var stackB = graphModel.CreateStack(((NodeModel)stackA).Title + "_split", stackA.Position + Vector2.up * 300); // Move the list of nodes to this new stack. stackB.MoveStackedNodes(nodeModels, 0); // if the stack had a condition node or anything providing the actual port models, we need to move // the nodes BEFORE fetching the port models, as stack.portModels will actually return the condition // port models var stackAOutputPortModel = stackA.OutputPorts.First(); var stackBInputPortModel = stackB.InputPorts.First(); var stackBOutputPortModel = stackB.OutputPorts.First(); // Connect the edges that were connected to the old stack to the new one. var previousEdgeConnections = graphModel.GetEdgesConnections(stackAOutputPortModel).ToList(); foreach (var edge in previousEdgeConnections) { graphModel.CreateEdge(edge.InputPortModel, stackBOutputPortModel); graphModel.DeleteEdge(edge); } // Connect the new stack with the old one. IEdgeModel newEdge = graphModel.CreateEdge(stackBInputPortModel, stackAOutputPortModel); graphModel.LastChanges.ChangedElements.Add(stackA); graphModel.LastChanges.ModelsToAutoAlign.Add(newEdge); } } return(previousState); }
static State CreateNodeOnEdge(State previousState, CreateNodeOnEdgeAction action) { IEdgeModel edgeModel = action.EdgeModel; // Instantiate node var graphModel = (VSGraphModel)previousState.CurrentGraphModel; var position = action.Position - Vector2.up * k_NodeOffset; List <GUID> guids = action.Guid.HasValue ? new List <GUID> { action.Guid.Value } : null; var elementModels = action.SelectedItem.CreateElements.Invoke( new GraphNodeCreationData(graphModel, position, guids: guids)); if (elementModels.Length == 0 || !(elementModels[0] is INodeModel selectedNodeModel)) { return(previousState); } // Connect input port var inputPortModel = selectedNodeModel is FunctionCallNodeModel ? selectedNodeModel.InputsByDisplayOrder.FirstOrDefault(p => p.DataType.Equals(edgeModel.OutputPortModel.DataType)) : selectedNodeModel.InputsByDisplayOrder.FirstOrDefault(); if (inputPortModel != null) { graphModel.CreateEdge(inputPortModel, edgeModel.OutputPortModel); } // Find first matching output type and connect it var outputPortModel = GetFirstPortModelOfType(edgeModel.InputPortModel.DataType, selectedNodeModel.OutputsByDisplayOrder); if (outputPortModel != null) { graphModel.CreateEdge(edgeModel.InputPortModel, outputPortModel); } // Delete old edge graphModel.DeleteEdge(edgeModel); return(previousState); }
public void Test_DisconnectSetPropertyKeepsPortType([Values] TestingMode mode) { VariableDeclarationModel trDecl = GraphModel.CreateGraphVariableDeclaration("tr", typeof(Transform).GenerateTypeHandle(Stencil), true); IVariableModel trVar = GraphModel.CreateVariableNode(trDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); GraphModel.CreateEdge(setters.InstancePort, trVar.OutputPort); setters.AddMember( new TypeMember { Path = new List <string> { "position" }, Type = Stencil.GenerateTypeHandle(typeof(Vector3)) } ); IConstantNodeModel constToken = GraphModel.CreateConstantNode("v3", typeof(Vector3).GenerateTypeHandle(Stencil), Vector2.left * 200); IEdgeModel edge = GraphModel.CreateEdge(setters.GetPortsForMembers().First(), constToken.OutputPort); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.GetPortsForMembers().First().DataType.Resolve(Stencil), Is.EqualTo(typeof(Vector3))); }); }
public void Test_DisconnectSetPropertyInstanceSetsRightPortType(TestingMode mode, int inputIndex, Type expectedPortType) { VariableDeclarationModel goDecl = GraphModel.CreateGraphVariableDeclaration("go", typeof(GameObject).GenerateTypeHandle(Stencil), true); IVariableModel goVar = GraphModel.CreateVariableNode(goDecl, Vector2.left); FunctionModel method = GraphModel.CreateFunction("TestFunction", Vector2.zero); SetPropertyGroupNodeModel setters = method.CreateSetPropertyGroupNode(0); IEdgeModel edge = GraphModel.CreateEdge(setters.InstancePort, goVar.OutputPort); PropertyInfo propertyInfo = typeof(Transform).GetProperty("position"); var newMember = new TypeMember { Path = new List <string> { propertyInfo?.Name }, Type = typeof(Transform).GenerateTypeHandle(Stencil) }; setters.AddMember(newMember); TestPrereqActionPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); return(new DeleteElementsAction(edge)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); Assert.That(method.NodeModels.Count(), Is.EqualTo(1)); Assert.That(GetStackedNode(0, 0), Is.TypeOf <SetPropertyGroupNodeModel>()); Assert.That(setters.InstancePort.DataType, Is.EqualTo(TypeHandle.Unknown)); Assert.That(setters.GetPortsForMembers().First().DataType, Is.EqualTo(typeof(Transform).GenerateTypeHandle(Stencil))); }); }
/// <summary> /// Initializes a new instance of the <see cref="ReorderEdgeCommand"/> class. /// </summary> /// <param name="edgeModel">The edge to reorder.</param> /// <param name="type">The reorder operation to apply.</param> public ReorderEdgeCommand(IEdgeModel edgeModel, ReorderType type) : this() { EdgeModel = edgeModel; Type = type; switch (Type) { case ReorderType.MoveFirst: UndoString = "Move Edge First"; break; case ReorderType.MoveUp: UndoString = "Move Edge Up"; break; case ReorderType.MoveDown: UndoString = "Move Edge Down"; break; case ReorderType.MoveLast: UndoString = "Move Edge Last"; break; } }
public virtual bool CreateDependencyFromEdge(IEdgeModel model, out LinkedNodesDependency linkedNodesDependency, out INodeModel parent) { if (model.InputPortModel.NodeModel is IStackModel && model.InputPortModel.PortType != PortType.Instance) { linkedNodesDependency = new LinkedNodesDependency { DependentPort = model.InputPortModel, ParentPort = model.OutputPortModel, count = 1, }; parent = model.OutputPortModel.NodeModel; } else { linkedNodesDependency = new LinkedNodesDependency { DependentPort = model.OutputPortModel, ParentPort = model.InputPortModel, }; parent = model.InputPortModel.NodeModel; } return(true); }
protected virtual void VisitEdge(IEdgeModel edgeModel) { }
private void ParseNodeFirstPass(XmlTextReader reader, XMLTree parentNode, String parentTypeName) { INodeModel nodeModel = graph.Model.NodeModel; IEdgeModel edgeModel = graph.Model.EdgeModel; Dictionary <String, int> tagNameToNextIndex = new Dictionary <String, int>(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement) { break; // reached end of current nesting level } if (reader.NodeType != XmlNodeType.Element) { continue; } bool emptyElem = reader.IsEmptyElement; // retard API designer String tagName = reader.Name; String id = null; if (reader.MoveToAttribute("xmi:id")) { id = reader.Value; } String elementName = null; if (reader.MoveToAttribute("name")) { elementName = reader.Value; } String typeName = null; if (reader.MoveToAttribute("xsi:type")) { typeName = reader.Value; } else if (reader.MoveToAttribute("xmi:type")) { typeName = reader.Value; } else { typeName = FindRefTypeName(parentTypeName, tagName); if (typeName == null) { // Treat it as an attribute AssignAttribute(parentNode.elementNode, tagName, reader.ReadInnerXml()); XMLTree attributeChild = new XMLTree(); attributeChild.elementNode = null; attributeChild.elementName = elementName; attributeChild.element = tagName; attributeChild.children = null; parentNode.children.Add(attributeChild); continue; } } INode gnode = graph.AddNode(nodeModel.GetType(GrGenTypeNameFromXmi(typeName))); XMLTree child = new XMLTree(); child.elementNode = gnode; child.elementName = elementName; child.element = tagName; child.children = new List <XMLTree>(); parentNode.children.Add(child); if (id != null) { nodeMap[id] = gnode; } String edgeTypeName = FindContainingTypeName(parentTypeName, tagName); String grgenEdgeTypeName = GrGenTypeNameFromXmi(edgeTypeName) + "_" + tagName; IEdge parentEdge = graph.AddEdge(edgeModel.GetType(grgenEdgeTypeName), parentNode.elementNode, gnode); if (IsRefOrdered(parentTypeName, tagName)) { int nextIndex = 0; tagNameToNextIndex.TryGetValue(tagName, out nextIndex); parentEdge.SetAttribute("ordering", nextIndex); tagNameToNextIndex[tagName] = nextIndex + 1; } if (!emptyElem) { ParseNodeFirstPass(reader, child, typeName); } } }