public ListEquation(ReadFromXml r)
        {
            readxml = r;
            cList = readxml.getConnectionList();
            dList = readxml.getDeviceList();
            nList = readxml.GetNodeList();
            eList = new ArrayList();
            currentList = new ArrayList();

            cEnum = cList.GetEnumerator();
            dEnum = dList.GetEnumerator();
            nEnum = nList.GetEnumerator();

            start = new Node();
            end = new Node();
        }
        public ReadFromXml(string instr)
        {
            string sOID = ""; //start object id
            string sPID = ""; //start point id
            string eOID = ""; //end object id
            string ePID = ""; //end point id

            cdList = new ArrayList();
            cnList = new ArrayList();
            ccList = new ArrayList();

            Node a = new Node("123","789"); //dummy
            cnList.Add(a);

            //Create XML DOM instance
            XmlDocument document = new XmlDocument();
            document.LoadXml(instr);
            //Select all graphic object elements and connections
            XmlNodeList objList1 = document.SelectNodes("//graphicObject");
            XmlNodeList objList2 = document.SelectNodes("//connection");

            int countDevice=0;

            int countResistor=1;
            int countCapacitor=1;
            int countInductor=1;
            int countTransitor=1;
            int countVDC=1;
            int countVAC=1;
            int countCsource=1;
            int countGround =1;
            int countJFET =1;
            int countOpamp=1;
            int countDiode=1;

            foreach(XmlNode objNode in objList1)
            {
                XmlNodeReader objNodeReader = new XmlNodeReader(objNode);

                while(objNodeReader.Read())	//read thru all child nodes of this node
                {
                    if(objNodeReader.NodeType == XmlNodeType.Element)	//	***READING NODES AND DEVICE***
                    {
                        if(objNodeReader.Name == "graphicObject")
                        {
                            objID = objNodeReader.GetAttribute("id");	// to read the id attribute of the element
                            template = objNodeReader.GetAttribute("template");	// to read the template attribute of the element, test if it is Capacitor, Resistor or others
                            type = objNodeReader.GetAttribute("type");	// to read the type attribute of the element, test if it is a link node.

                            switch ( template )	// typecast to specific type of device.
                            {
                                case "Resistor" :
                                    device = (Resistor)new Resistor(objID, "" + countDevice);    //chester
                                    countDevice++;
                                    countResistor++;
                                    break;

                                case "VsourceDC" :
                                    device = (VsourceDC)new VsourceDC(objID, ""+countDevice);       //chester
                                    countDevice++;
                                    countVDC++;
                                    break;

                                case "Inductor" :
                                    //device = (Inductor) new Inductor(objID,""+countDevice);
                                    device = (Inductor) new Inductor(objID,""+countInductor);
                                    countInductor++;
                                    //countDevice++;
                                    break;
                                case "Capacitor" :
                                    //device = (Capacitor) new Capacitor(objID,""+countDevice);
                                    device = (Capacitor)new Capacitor(objID, "" + countCapacitor);
                                    countCapacitor++;
                                    //countDevice++;
                                    break;
                                case "VsourceAC" :
                                    //device = (VsourceAC) new VsourceAC(objID,""+countDevice);
                                    device = (VsourceAC) new VsourceAC(objID,""+countVAC);
                                    countVAC++;
                                    //countDevice++;
                                    break;
                                case "Csource" :
                                    //device = (Csource) new Csource(objID,""+countDevice);
                                    device = (Csource) new Csource(objID,""+countCsource);
                                    countCsource++;
                                    break;
                                case "Diode" :
                                    device = (Diode) new Diode(objID,""+countDiode);
                                    countDiode++;
                                    break;
                                case "Transitor" :
                                    //device = (Transitor) new Transitor(objID,""+countDevice);
                                    device = (Transitor)new Transitor(objID, "" + countTransitor);
                                    countTransitor++;
                                    //countDevice++;
                                    break;
                                case "Ground" :
                                    device = (Ground) new Ground(objID,""+countGround);
                                    countGround++;
                                    break;
                                case "JFET" :
                                    device = (JFET) new JFET(objID,""+countJFET);
                                    countJFET++;
                                    break;

                                case "Opamp" :
                                    device = (Opamp) new Opamp(objID,""+countOpamp);
                                    countOpamp++;
                                    break;
                                default:
                                    device = new Device();
                                    device.SetID(objID);
                                    break;
                            }

                            #region "Chester for new device implementation"
                                 device.convert(objNodeReader);
                            #endregion

                            if (!cdList.Contains(device))
                            {
                                cdList.Add(device);
                            }

                        }
                    }
                }
            }

            //reading connection
            int countNode=0;
            IEnumerator cnEnum;

            foreach(XmlNode objNode in objList2)
            {
                XmlNodeReader objNodeReader = new XmlNodeReader(objNode);
                Node startNode = new Node();
                Node endNode = new Node();

                int cnt=0;

                while(objNodeReader.Read())	//read thru all child nodes of this node
                {
                    if(objNodeReader.NodeType == XmlNodeType.Element)
                    {

                        //Console.WriteLine(cnList.Count);
                        if(objNodeReader.Name == "point" && cnt%2==0 )
                        {
                            sOID = objNodeReader.GetAttribute("objectID");
                            sPID = objNodeReader.GetAttribute("pointID");

                            startNode.SetObjID(sOID);
                            startNode.SetPtID(sPID);
                            startNode.setstart(true);
                            cnEnum = cnList.GetEnumerator();

                            int countAll1=1;
                            while(cnEnum.MoveNext())
                            {
                                string currentObjID = ((Node)cnEnum.Current).GetObjID();
                                string currentPtID = ((Node)cnEnum.Current).GetPtID();
                                if(sOID!=null && sPID!=null)
                                {
                                    if(currentObjID.Equals(sOID) && currentPtID.Equals(sPID))
                                    {
                                        startNode.SetName(((Node)cnEnum.Current).GetName());
                                        break;
                                    }
                                    else
                                    {
                                        if(cnList.Count==countAll1)
                                        {
                                            //string name = "N"+countNode;
                                            string name = countNode+"";
                                            startNode.SetName(name);
                                            countNode++;
                                            cnList.Add(startNode);
                                            countAll1++;
                                            break;
                                        }

                                    }
                                }
                                countAll1++;
                                //Console.WriteLine("cnList count "+cnList.Count+" count 1 " + countAll1 );

                            }

                            cnt++;
                        }
                        else if(objNodeReader.Name == "point")
                        {
                            eOID = objNodeReader.GetAttribute("objectID");
                            ePID = objNodeReader.GetAttribute("pointID");
                            endNode.SetObjID(eOID);
                            endNode.SetPtID(ePID);
                            cnEnum = cnList.GetEnumerator();

                            int countAll2=1;
                            while(cnEnum.MoveNext())
                            {
                                string currentObjID = ((Node)cnEnum.Current).GetObjID();
                                string currentPtID = ((Node)cnEnum.Current).GetPtID();
                                if(eOID!=null && ePID!=null)
                                {
                                    if(currentObjID.Equals(eOID) && currentPtID.Equals(ePID))
                                    {
                                        endNode.SetName(((Node)cnEnum.Current).GetName());
                                        break;
                                    }
                                    else
                                    {
                                        if(cnList.Count==countAll2)
                                        {
                                            //string name = "N"+countNode;
                                            string name = ""+countNode;
                                            endNode.SetName(name);
                                            countNode++;
                                            cnList.Add(endNode);

                                            countAll2++;
                                            break;

                                        }
                                    }

                                }
                                countAll2++;
                                //Console.WriteLine(cnList.Count+" count 2 " + countAll2 );
                            }
                            if(eOID!=null && ePID!=null)
                            {
                                Connection connection = new Connection(startNode,endNode);
                                ccList.Add(connection);
                                startNode = new Node();
                                endNode = new Node();
                            }
                            cnt=0;

                        }

                    }
                }
            }
            cnList.RemoveAt(0);
            cnList.TrimToSize();

            IEnumerator cEnum = ccList.GetEnumerator();
            IEnumerator dEnum = cdList.GetEnumerator();
            IEnumerator nEnum = cnList.GetEnumerator();

            //to set the device name of the node
            while(nEnum.MoveNext())
            {
                dEnum = cdList.GetEnumerator();
                while(dEnum.MoveNext())
                {
                    if(((Node)nEnum.Current).GetObjID().Equals(((Device)dEnum.Current).GetID()))
                    {
                        ((Node)nEnum.Current).SetDeviceName(((Device)dEnum.Current).GetName());

                        if(((Device)dEnum.Current).GetNodeCount() == 0)
                        {
                            ((Device)dEnum.Current).SetNode1((Node)nEnum.Current);
                        }
                        else if(((Device)dEnum.Current).GetNodeCount() == 1)
                        {
                            ((Device)dEnum.Current).SetNode2((Node)nEnum.Current);
                        }
                        else if(((Device)dEnum.Current).GetNodeCount() == 2)
                        {
                            ((Device)dEnum.Current).SetNode3((Node)nEnum.Current);
                        }

                    }

                }
            }
            cEnum = ccList.GetEnumerator();
            dEnum = cdList.GetEnumerator();
            nEnum = cnList.GetEnumerator();
            //to set nodes in to the device
        }
 public void addNode(Node n)
 {
     elementList.Add(n);
 }
 public void SetNode(Node s,Node e)
 {
     start = s;
     end = e;
 }
        public string OutConnEquation()
        {
            startNode = conn.GetStart();
            endNode = conn.GetEnd();

            string equation = "V" + startNode.GetName() + " = " + "V" + endNode.GetName();
            return (equation);
        }
 public Connection(Node s,Node e)
 {
     SetNode(s,e);
 }
 public Equation(Device d, Node start, Node end)
 {
     startNode = start;
     endNode = end;
     device =d;
 }
Esempio n. 8
0
 public void SetNode3(Node n3)
 {
     node3 = n3;
     nodeCount = 3;
 }
Esempio n. 9
0
 public void SetNode2(Node n2)
 {
     node2 = n2;
     nodeCount = 2;
 }
Esempio n. 10
0
 public void SetNode1(Node n1)
 {
     node1 = n1;
     nodeCount = 1;
 }
Esempio n. 11
0
        public void SetDeviceMergeNode()
        {
            ArrayList MergeNodeList = GetMergeNodeList();
            Device currentDevice = new Device();
            Node deviceNode1 = new Node();
            Node deviceNode2 = new Node();
            Node deviceNode3 = new Node();
            Node currentNode = new Node();
            MergeNode mNode;

            dEnum = dList.GetEnumerator();
            IEnumerator mnlEnum = MergeNodeList.GetEnumerator();
            IEnumerator mnEnum = MergeNodeList.GetEnumerator();

            //for each device in the device list
            while(dEnum.MoveNext())
            {
                currentDevice = (Device)dEnum.Current;
                deviceNode1 = currentDevice.GetNode1();
                deviceNode2 = currentDevice.GetNode2();

                //for each mergeNode in the mergeNodeList
                mnlEnum = MergeNodeList.GetEnumerator();
                while(mnlEnum.MoveNext())
                {
                    mNode = (MergeNode)mnlEnum.Current;

                    mnEnum = mNode.getList().GetEnumerator();
                    //for each node in the mergeNode
                    while(mnEnum.MoveNext())
                    {
                        currentNode = (Node)mnEnum.Current;
                        if(currentNode.GetName().Equals(deviceNode1.GetName()))
                        {
                            currentDevice.SetMergeNode1(mNode);
                        }
                        if(currentDevice.GetNode2()!=null)
                        {
                            if(currentNode.GetName().Equals(deviceNode2.GetName()))
                            {
                                currentDevice.SetMergeNode2(mNode);
                            }
                        }
                        if(currentDevice.GetNode3()!=null)
                        {
                            deviceNode3 = currentDevice.GetNode3();

                            if(currentNode.GetName().Equals(deviceNode3.GetName()))
                            {
                                currentDevice.SetMergeNode3(mNode);
                            }
                        }

                    }
                }
            }
        }