public DaggerSubNode() { _subNodeGraph = new DaggerGraph(); _subNodeGraph._parentSubNode = this; AssociatedUINode = "IDaggerUISubNode"; }
/// <summary> /// Connect this pin to Input Pin /// </summary> /// <param name="input">pin to connect to</param> /// <returns>true if succeded</returns> public bool ConnectToInput(DaggerInputPin input) { DaggerGraph outputpincontainer = (_parentNode != null) ? _parentNode.ParentGraph : _parentGraph; DaggerGraph inputpincontainer = (input._parentNode != null) ? input._parentNode.ParentGraph : input._parentGraph; if (outputpincontainer == null) { throw new InvalidOperationException("Output pin is not associated with a DaggerGraph"); } if (inputpincontainer == null) { throw new InvalidOperationException("Input pin is not associated with a DaggerGraph"); } if (inputpincontainer != outputpincontainer) { throw new InvalidOperationException("Input pin and Output pin are not associated with the same DaggerGraph"); } if (input.IsConnected) { // disconnect the input pin from it's previous connection if (!input.Disconnect(false)) { return(false); } } //call the before connect event to see if we can connect them if (outputpincontainer.OnBeforePinsConnected(this, input)) { //connect the two pins _connectedTo.Add(input); input._connectedTo = this; //if we have data, give it to the input if (_data != null) { input.Data = _data; } // let the graph know they are connected outputpincontainer.OnPinsConnected(this, input); // if the input pin is marked as autoclone, create a duplicate pin if (input.AutoClone) { // Don't AutoClone during the deserialization process if (!input._parentNode.ParentGraph._isDeserializing) { DaggerInputPin newpin = new DaggerInputPin(); newpin.Name = input.Name; newpin.DataType = input.DataType; newpin.AutoClone = true; newpin._wasCloned = true; input.ParentNode.InputPins.Add(newpin); } } // refresh the UINodes if they are attached if (_parentNode != null && _parentNode.UINode != null) { _parentNode.UINode.CalculateLayout(); } if (input._parentNode != null && input._parentNode.UINode != null) { input._parentNode.UINode.CalculateLayout(); } // if we autocloned, refresh the UIGraph to re-align the noodles if (input._autoClone && input._parentNode.UINode != null) { input._parentNode.UINode.ParentUIGraph.UpdateNoodles(input._parentNode); } // call the AfterPinConnected event if (PinConnected != null) { PinConnected(this, new EventArgs()); } input.InvokeAfterConnect(); return(true); } else { return(false); } }
/// <summary> /// Disconnect link going to input /// </summary> /// <param name="input">Input pin to disconnect from</param> /// <param name="forceDisconnect">if true, ignore pre-disconnect testing</param> /// <returns>true if disconnect succeded</returns> public bool Disconnect(DaggerInputPin input, bool forceDisconnect) { //get the parent graph of this pin DaggerGraph parentGraph = (_parentGraph == null) ? _parentNode.ParentGraph : _parentGraph; if (parentGraph == null) { throw new InvalidOperationException("Output pin is not associated with a DaggerGraph"); } //do we have this input pin? if (_connectedTo.Contains(input)) { // call the before connect event to see if we can disconnect them if (parentGraph.OnBeforePinsDisconnected(this, input) || forceDisconnect) { _connectedTo.Remove(input); input._connectedTo = null; //let the container know they are disonnected parentGraph.OnPinsDisonnected(this, input); //if the input was autocloned or is marked AutoClone, remove it from the node DaggerNode inputParentNode = input._parentNode; if (input._wasCloned || input._autoClone) { inputParentNode.InputPins.Remove(input); //refresh the ui if (inputParentNode.UINode != null) { inputParentNode.UINode.CalculateLayout(); inputParentNode.UINode.ParentUIGraph.UpdateNoodles(inputParentNode); } } //if the input was marked AutoClone, pass the torch to the next compatible pin if (input._autoClone) { foreach (DaggerInputPin pin in inputParentNode.InputPins) { if (pin.DataType == input.DataType) { pin._autoClone = true; break; } } } // raise the AfterPinDisconnected event if (PinDisconnected != null) { PinDisconnected(this, new EventArgs()); } input.InvokeAfterDisconnect(); return(true); } else { //we failed to disconnect them return(false); } } else { // raise the AfterPinDisconnected event if (PinDisconnected != null) { PinDisconnected(this, new EventArgs()); } input.InvokeAfterDisconnect(); //since we were never connected to this pin, they are technically disconnected return(true); } }