/// <summary> /// Check if the node has a parameter that references a GNBase /// </summary> /// <param name="gb">The GNBase to compare against.</param> /// <returns>True if the node contains a parameter referencing the node, else false.</returns> public bool HierarchyContains(LLDNBase gb, bool checkSelf = true) { if (checkSelf == true && this == gb) { return(true); } foreach (ParamBase pb in this.genParams) { if (pb.type != ParamBase.Type.PCMInput) { continue; } ParamConnection pc = pb as ParamConnection; if (pc.IsConnected() == false) { continue; } if (pc.Reference == gb) { return(true); } if (pc.Reference.HierarchyContains(gb) == true) { return(true); } } return(false); }
public bool ClearKnowledgeOfConnection(LLDNBase gnb) { bool any = false; foreach (ParamBase pb in this.genParams) { if (pb.type != ParamBase.Type.PCMInput) { continue; } ParamConnection pc = pb as ParamConnection; if (pc.IsConnected() == false) { continue; } if (pc.Reference == gnb) { pc.SetReference(null); any = true; } } return(any); }
public bool TreeAppearsValid(WiringCollection wc, WiringDocument owner) { if (this.conInput.IsConnected() == false) { return(false); } Queue <LLDNBase> toScan = new Queue <LLDNBase>(); toScan.Enqueue(this.conInput.Reference); while (toScan.Count > 0) { LLDNBase f = toScan.Dequeue(); if (f.CanMakeNoise() == true) { return(true); } if (f.nodeType == NodeType.Reference && wc != null) { LLDNReference refr = f as LLDNReference; if (refr != null && string.IsNullOrEmpty(refr.reference.referenceGUID) == false && owner != null) { WiringDocument refWD = wc.GetDocument(refr.reference.referenceGUID); if (refWD != null) { if (refWD == owner) { return(false); } if (refWD.Output != null) { toScan.Enqueue(refWD.Output); } } } } foreach (ParamConnection pc in f.GetParamConnections()) { if (pc.IsConnected() == false) { continue; } if (f.VerifyConnectionUsed(pc) == false) { continue; } toScan.Enqueue(pc.Reference); } } return(false); }
public bool SetConnection(ParamConnection ownedConParam, LLDNBase newConnection) { if (ownedConParam.IsConnected() == true) { if (ownedConParam.Reference == newConnection) { return(true); } if (newConnection.HierarchyContains(this) == true) { return(false); } } ownedConParam.SetReference(newConnection); return(true); }
public System.Xml.XmlElement SaveXML(System.Xml.XmlDocument xmlDoc) { System.Xml.XmlElement wdDoc = xmlDoc.CreateElement(xmlName); wdDoc.SetAttribute("name", this.name); wdDoc.SetAttribute("id", this.guid); wdDoc.SetAttribute("cat", this.GetCategoryName()); if (this.output != null) { wdDoc.SetAttribute("output", this.output.GUID); } foreach (LLDNBase gnb in this.generators) { LLDNBase.CreateSaveElement(wdDoc, gnb); } return(wdDoc); }
public virtual LLDNBase Clone(Dictionary <string, LLDNBase> directory = null) { LLDNBase clone = this.CloneType(); for (int i = 0; i < clone.genParams.Count; ++i) { ParamBase pbClone = clone.genParams[i]; ParamBase pbThis = null; if ( string.Equals(this.genParams[i].name, pbClone.name, System.StringComparison.OrdinalIgnoreCase) && this.genParams[i].type == pbClone.type) { pbThis = this.genParams[i]; } else { pbThis = this.GetParam( clone.genParams[i].name, clone.genParams[i].type); } if (pbThis == null) { continue; } string str = this.genParams[i].GetStringValue(); clone.genParams[i].SetValueFromString(str); if (directory != null) { clone.genParams[i].SetValueFromString(str, directory); } } return(clone); }
public void AddGenerator(LLDNBase generator) { switch (generator.nodeType) { case LLDNBase.NodeType.GateList: { LLDNGateList convGateList = generator as LLDNGateList; if (gateList != null) { // Nope! There can only be one! if (this.gateList != null) { return; } this.gateList = convGateList; } } break; } this.generators.Add(generator); }
public bool RemoveNode(LLDNBase node, bool removeConnections = true) { if (this.generators.Remove(node) == false) { return(false); } if (this.gateList == node) { this.gateList = null; } if (removeConnections == true) { node.ClearAllConnections(); foreach (LLDNBase g in this.generators) { g.ClearKnowledgeOfConnection(node); } } return(true); }
public void SetReference(LLDNBase newRef) { this.reference = newRef; }
public void ClearReference() { this.reference = null; }
public ParamConnection(string name, LLDNBase reference, string widgetType = "") : base(name, Type.PCMInput, widgetType) { this.reference = reference; }
public bool IsConnected(LLDNBase test) { return(this.reference == test); }
public bool LoadXML(System.Xml.XmlElement ele) { if (ele.Name != "wiring") { return(false); } System.Xml.XmlAttribute attrName = ele.Attributes["name"]; if (attrName != null) { this.name = attrName.Value; if (this.name.Length > MaxNameLen) { this.name = this.name.Substring(0, MaxNameLen); } } System.Xml.XmlAttribute attrCat = ele.Attributes["cat"]; if (attrCat != null) { this.category = WiringCollectionBase.GetCategoryFromName(attrCat.Value); } Dictionary <string, LLDNBase> directory = new Dictionary <string, LLDNBase>(); Dictionary <LLDNBase, System.Xml.XmlElement> xmlToGNMap = new Dictionary <LLDNBase, System.Xml.XmlElement>(); foreach (System.Xml.XmlElement eleNode in ele) { if (eleNode.Name != "node") { continue; } System.Xml.XmlAttribute attrType = eleNode.Attributes["type"]; if (attrType == null) { continue; } LLDNBase.NodeType nt; if (System.Enum.TryParse <LLDNBase.NodeType>(attrType.Value, true, out nt) == false) { continue; } string guid = null; System.Xml.XmlAttribute attrID = eleNode.Attributes["id"]; if (attrID != null) { guid = attrID.Value; } LLDNBase newGN = LLDNBase.CreateGenerator(nt, guid); if (newGN.LoadXML(eleNode) == false) { continue; } System.Xml.XmlAttribute attrX = eleNode.Attributes["x"]; if (attrX != null) { float.TryParse(attrX.Value, out newGN.cachedUILocation.x); } System.Xml.XmlAttribute attrY = eleNode.Attributes["y"]; if (attrY != null) { float.TryParse(attrY.Value, out newGN.cachedUILocation.y); } this.generators.Add(newGN); xmlToGNMap.Add(newGN, eleNode); directory.Add(newGN.GUID, newGN); } foreach (LLDNBase gnb in this.generators) { gnb.LoadXML(xmlToGNMap[gnb], directory); } string outputID = null; System.Xml.XmlAttribute attrOutput = ele.Attributes["output"]; if (attrOutput != null) { outputID = attrOutput.Value; } if (string.IsNullOrEmpty(outputID) == false) { LLDNBase gnbOut; if (directory.TryGetValue(outputID, out gnbOut) == true) { this.output = gnbOut as LLDNOutput; } } return(true); }
public bool SetConnection_Input(LLDNBase input) { return(this.SetConnection(this.conInput, input)); }
public bool GuessMakesNoise(WiringCollection collection, HashSet <WiringDocument> encountered = null) { if (this.output == null) { return(false); } if (encountered == null) { encountered = new HashSet <WiringDocument>(); } encountered.Add(this); Queue <LLDNBase> toScan = new Queue <LLDNBase>(); toScan.Enqueue(this.output); List <LLDNReference> refs = new List <LLDNReference>(); while (toScan.Count > 0) { LLDNBase check = toScan.Dequeue(); foreach (ParamConnection pc in check.GetParamConnections()) { if (pc.IsConnected() == false) { continue; } LLDNBase gb = pc.Reference; LLDNReference gnr = gb as LLDNReference; if (gnr != null && collection != null) { // Check these after everything else in the current doc. refs.Add(gnr); } else { if (gb.CanMakeNoise() == true) { return(true); } toScan.Enqueue(gb); } } } foreach (LLDNReference gnr in refs) { if (gnr.reference == null) { continue; } WiringDocument wd = collection.GetDocument(gnr.reference.referenceGUID); if (encountered.Contains(wd) == true) { continue; } if (wd.GuessMakesNoise(collection, encountered) == true) { return(true); } } return(false); }
public static System.Xml.XmlElement CreateSaveElement(System.Xml.XmlElement parent, LLDNBase gnb) { System.Xml.XmlElement ret = parent.OwnerDocument.CreateElement("node"); ret.SetAttribute("type", gnb.nodeType.ToString()); ret.SetAttribute("id", gnb.GUID); ret.SetAttribute("x", gnb.cachedUILocation.x.ToString()); ret.SetAttribute("y", gnb.cachedUILocation.y.ToString()); parent.AppendChild(ret); gnb.SaveXML(ret); return(ret); }
public WiringDocument Clone(string newName) { // Fill up the directory. Used so we can use existing // cloning utilities for cloning connection params. Dictionary <string, LLDNBase> thisLookup = new Dictionary <string, LLDNBase>(); foreach (LLDNBase gnb in this.generators) { thisLookup.Add(gnb.GUID, gnb); } // Copy all the generators. Dictionary <LLDNBase, LLDNBase> thisToThatMap = new Dictionary <LLDNBase, LLDNBase>(); WiringDocument wd = new WiringDocument(false, null); foreach (LLDNBase gnb in this.generators) { LLDNBase clone = gnb.Clone(thisLookup); clone.cachedUILocation = gnb.cachedUILocation; wd.generators.Add(clone); thisToThatMap.Add(gnb, clone); } // Convert the connections to point to their own equivalents. foreach (LLDNBase gnb in wd.generators) { foreach (ParamBase pb in gnb.nodeParams) { if (pb.type == ParamBase.Type.PCMInput) { ParamConnection pcon = pb as ParamConnection; if (pcon.IsConnected() == false) { continue; } LLDNBase conv; if (thisToThatMap.TryGetValue(pcon.Reference, out conv) == true) { pcon.SetReference(conv); } else { pcon.ClearReference(); } } } } // Fix up the output if (this.output != null) { LLDNBase gbOutput = thisToThatMap[this.output]; if (gbOutput != null && gbOutput.nodeType == LLDNBase.NodeType.Output) { wd.output = (LLDNOutput)gbOutput; } } // Finish if (string.IsNullOrEmpty(newName) == false) { wd.SetName(newName); } else { wd.SetName(this.name); } return(wd); }