// Node creation when validate a choice public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context) { // window to graph position var windowRoot = window.rootVisualElement; var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, context.screenMousePosition - window.position.position); var graphMousePosition = graphView.contentViewContainer.WorldToLocal(windowMousePosition); var nodeType = searchTreeEntry.userData is Type ? (Type)searchTreeEntry.userData : ((NodeProvider.PortDescription)searchTreeEntry.userData).nodeType; graphView.RegisterCompleteObjectUndo("Added " + nodeType); var view = graphView.AddNode(BaseNode.CreateFromType(nodeType, graphMousePosition)); if (searchTreeEntry.userData is NodeProvider.PortDescription desc) { var targetPort = view.GetPortViewFromFieldName(desc.portFieldName, desc.portIdentifier); if (inputPortView == null) { graphView.Connect(targetPort, outputPortView); } else { graphView.Connect(inputPortView, targetPort); } } return(true); }
public virtual void OnDropOutsidePort(Edge edge, Vector2 position) { this.graphView.RegisterCompleteObjectUndo("Disconnect edge"); //If the edge was already existing, remove it if (!edge.isGhostEdge) { graphView.Disconnect(edge as EdgeView); } // when on of the port is null, then the edge was created and dropped outside of a port if (edge.input == null || edge.output == null) { Vector2 mousePos = graphView.ChangeCoordinatesTo(graphView.contentViewContainer, position); // Empirical offset: mousePos += new Vector2(-10f, -18); // TODO: function this.graphView.RegisterCompleteObjectUndo("Added relay node "); var relayNode = BaseNode.CreateFromType <RelayNode>(mousePos); var relayView = graphView.AddNode(relayNode); // Connect to the new relay node: var port = edge.output ?? edge.input; var pv = port as PortView; bool isInput = edge.input == null; var p = pv.owner.nodeTarget.GetPort(pv.fieldName, pv.portData.identifier); // Wait for node to be created ... graphView.schedule.Execute(() => { // We can't use edge here because it have been destroyed if (isInput) { var newEdge = graphView.graph.Connect(relayNode.inputPorts[0], p); graphView.ConnectView(new EdgeView() { userData = newEdge, input = relayView.GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier), output = pv.owner.GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier) }); } else { var newEdge = graphView.graph.Connect(p, relayNode.outputPorts[0]); graphView.ConnectView(new EdgeView() { userData = newEdge, input = pv.owner.GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier), output = relayView.GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier) }); } }).ExecuteLater(1); } //TODO: open new nodes selector and connect the created node if there is one }
// Node creation when validate a choice public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context) { // window to graph position var windowRoot = window.rootVisualElement; var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, context.screenMousePosition - window.position.position); var graphMousePosition = graphView.contentViewContainer.WorldToLocal(windowMousePosition); graphView.RegisterCompleteObjectUndo("Added " + searchTreeEntry.userData); graphView.AddNode(BaseNode.CreateFromType((Type)searchTreeEntry.userData, graphMousePosition)); return(true); }
public RelayNodeView AddRelayNode(PortView inputPort, PortView outputPort, Vector2 position) { var relayNode = BaseNode.CreateFromType <RelayNode>(position); var view = AddNode(relayNode) as RelayNodeView; if (outputPort != null) { Connect(view.inputPortViews[0], outputPort); } if (inputPort != null) { Connect(inputPort, view.outputPortViews[0]); } return(view); }
void DragPerformedCallback(DragPerformEvent e) { var mousePos = (e.currentTarget as VisualElement).ChangeCoordinatesTo(contentViewContainer, e.localMousePosition); var dragData = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>; if (dragData == null) { return; } var exposedParameterFieldViews = dragData.OfType <ExposedParameterFieldView>(); if (exposedParameterFieldViews.Any()) { foreach (var paramFieldView in exposedParameterFieldViews) { var paramNode = BaseNode.CreateFromType <ParameterNode>(mousePos); paramNode.parameterGUID = paramFieldView.parameter.guid; AddNode(paramNode); } } }