/* are n1 and n2 connected internally somehow? */ public override bool GetConnection(int n1, int n2) { var cnLinks1 = compNodeList[n1].Links; var cnLinks2 = compNodeList[n2].Links; /* see if any elements are connected to both n1 and n2, then call getConnection() on those */ for (int i = 0; i < cnLinks1.Count; i++) { CircuitNodeLink link1 = cnLinks1[i]; for (int j = 0; j < cnLinks2.Count; j++) { CircuitNodeLink link2 = cnLinks2[j]; if (link1.Elm == link2.Elm && link1.Elm.GetConnection(link1.Num, link2.Num)) { return(true); } } } return(false); }
public void loadComposite(StringTokenizer stIn, string model, int[] externalNodes) { var compNodeHash = new Dictionary <int, CircuitNode>(); var modelLinet = new StringTokenizer(model, "\r"); CircuitNode cn; CircuitNodeLink cnLink; VoltageSourceRecord vsRecord; compElmList = new List <CircuitElm>(); compNodeList = new List <CircuitNode>(); voltageSources = new List <VoltageSourceRecord>(); /* Build compElmList and compNodeHash from input string */ while (modelLinet.hasMoreTokens()) { string line = modelLinet.nextToken(); var stModel = new StringTokenizer(line, " +\t\n\r\f"); var ceType = MenuItems.GetItemFromString(stModel.nextToken()); var newce = MenuItems.ConstructElement(ceType); if (stIn != null) { var tint = newce.DumpType; string dumpedCe = stIn.nextToken(); if (useEscape()) { dumpedCe = CustomLogicModel.unescape(dumpedCe); } var stCe = new StringTokenizer(dumpedCe, useEscape() ? " " : "_"); // TODO: loadComposite int flags = 0; //stCe.nextTokenInt(); newce = MenuItems.CreateCe(tint, new Point(), new Point(), flags, stCe); } compElmList.Add(newce); int thisPost = 0; while (stModel.hasMoreTokens()) { int nodeOfThisPost = stModel.nextTokenInt(); cnLink = new CircuitNodeLink(); cnLink.Num = thisPost; cnLink.Elm = newce; if (!compNodeHash.ContainsKey(nodeOfThisPost)) { cn = new CircuitNode(); cn.Links.Add(cnLink); compNodeHash.Add(nodeOfThisPost, cn); } else { cn = compNodeHash[nodeOfThisPost]; cn.Links.Add(cnLink); } thisPost++; } } /* Flatten compNodeHash in to compNodeList */ numPosts = externalNodes.Length; for (int i = 0; i < externalNodes.Length; i++) { /* External Nodes First */ if (compNodeHash.ContainsKey(externalNodes[i])) { compNodeList.Add(compNodeHash[externalNodes[i]]); compNodeHash.Remove(externalNodes[i]); } else { throw new Exception(); } } foreach (var entry in compNodeHash) { int key = entry.Key; compNodeList.Add(compNodeHash[key]); } /* allocate more nodes for sub-elements' internal nodes */ for (int i = 0; i != compElmList.Count; i++) { var ce = compElmList[i]; int inodes = ce.InternalNodeCount; for (int j = 0; j != inodes; j++) { cnLink = new CircuitNodeLink(); cnLink.Num = j + ce.PostCount; cnLink.Elm = ce; cn = new CircuitNode(); cn.Links.Add(cnLink); compNodeList.Add(cn); } } numNodes = compNodeList.Count; /*Console.WriteLine("Dumping compNodeList"); * for (int i = 0; i < numNodes; i++) { * Console.WriteLine("New node" + i + " Size of links:" + compNodeList.get(i).links.size()); * }*/ posts = new Point[numPosts]; /* Enumerate voltage sources */ for (int i = 0; i < compElmList.Count; i++) { int cnt = compElmList[i].VoltageSourceCount; for (int j = 0; j < cnt; j++) { vsRecord = new VoltageSourceRecord(); vsRecord.elm = compElmList[i]; vsRecord.vsNumForElement = j; voltageSources.Add(vsRecord); } } /* dump new circuits with escape() */ mFlags |= FLAG_ESCAPE; }