Example #1
0
 public VCCSElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f, st)
 {
     mInputCount = st.nextTokenInt();
     mExprString = CustomLogicModel.unescape(st.nextToken());
     parseExpr();
     SetupPins();
 }
Example #2
0
        public DiodeElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f)
        {
            const double defaultdrop = 0.805904783;

            mDiode = new Diode(mCir);
            double fwdrop   = defaultdrop;
            double zvoltage = 0;

            try {
                ReferenceName = st.nextToken();
            } catch { }
            if (0 != (f & FLAG_MODEL))
            {
                try {
                    mModelName = CustomLogicModel.unescape(st.nextToken());
                } catch { }
            }
            else
            {
                if (0 != (f & FLAG_FWDROP))
                {
                    try {
                        fwdrop = st.nextTokenDouble();
                    } catch { }
                }
                mModel     = DiodeModel.GetModelWithParameters(fwdrop, zvoltage);
                mModelName = mModel.Name;
            }
            setup();
        }
Example #3
0
 public override void SetupPins()
 {
     if (modelName == null)
     {
         postCount = bits;
         allocNodes();
         return;
     }
     model       = CustomLogicModel.getModelWithName(modelName);
     inputCount  = model.inputs.Length;
     outputCount = model.outputs.Length;
     sizeY       = inputCount > outputCount ? inputCount : outputCount;
     if (sizeY == 0)
     {
         sizeY = 1;
     }
     sizeX     = 2;
     postCount = inputCount + outputCount;
     pins      = new Pin[postCount];
     for (int i = 0; i != inputCount; i++)
     {
         pins[i] = new Pin(this, i, SIDE_W, model.inputs[i]);
         pins[i].fixName();
     }
     for (int i = 0; i != outputCount; i++)
     {
         pins[i + inputCount]        = new Pin(this, i, SIDE_E, model.outputs[i]);
         pins[i + inputCount].output = true;
         pins[i + inputCount].fixName();
     }
     lastValues    = new bool[postCount];
     patternValues = new bool[26];
     highImpedance = new bool[postCount];
 }
Example #4
0
 public override void UpdateModels()
 {
     model = CustomLogicModel.getModelWithNameOrCopy(modelName, model);
     SetupPins();
     allocNodes();
     SetPoints();
 }
Example #5
0
        protected override string dump()
        {
            /* insert model name before the elements */
            string s = dumpWithMask(0);

            s += " " + CustomLogicModel.escape(modelName);
            s += dumpElements();
            return(s);
        }
Example #6
0
        protected string dumpElements()
        {
            string dumpStr = "";

            for (int i = 0; i < compElmList.Count; i++)
            {
                string tstring = compElmList[i].Dump;
                var    rg      = new Regex("[A-Za-z0-9]+ 0 0 0 0 0 ");
                tstring = rg.Replace(tstring, "", 1); /* remove unused tint x1 y1 x2 y2 coords for internal components */
                dumpStr = string.Join(" ", dumpStr, CustomLogicModel.escape(tstring));
            }
            return(dumpStr);
        }
Example #7
0
        public CustomLogicElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f, st)
        {
            modelName = CustomLogicModel.unescape(st.nextToken());
            UpdateModels();
            int i;

            for (i = 0; i != PostCount; i++)
            {
                if (pins[i].output)
                {
                    Volts[i]      = st.nextTokenDouble();
                    pins[i].value = Volts[i] > 2.5;
                }
            }
        }
Example #8
0
        public static void UndumpModel(StringTokenizer st)
        {
            string name = CustomLogicModel.unescape(st.nextToken());

            CustomCompositeElm.lastModelName = name;
            var model = GetModelWithName(name);

            if (model == null)
            {
                model      = new CustomCompositeModel();
                model.Name = name;
                mModelMap.Add(name, model);
            }
            model.undump(st);
        }
Example #9
0
 public LabeledNodeElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f)
 {
     Text = st.nextToken();
     if ((mFlags & FLAG_ESCAPE) == 0)
     {
         // old-style dump before escape/unescape
         while (st.hasMoreTokens())
         {
             Text += ' ' + st.nextToken();
         }
     }
     else
     {
         // new-style dump
         Text = CustomLogicModel.unescape(Text);
     }
 }
Example #10
0
        protected string dumpElements(int mask)
        {
            string dumpStr = "";

            for (int i = 0; i < compElmList.Count; i++)
            {
                if ((mask & (1 << i)) == 0)
                {
                    continue;
                }
                string tstring = compElmList[i].Dump;
                var    rg      = new Regex("[A-Za-z0-9]+ 0 0 0 0 ");
                tstring  = rg.Replace(tstring, "", 1); /* remove unused tint x1 y1 x2 y2 coords for internal components */
                dumpStr += " " + CustomLogicModel.escape(tstring);
            }
            return(dumpStr);
        }
Example #11
0
        protected override string dump()
        {
            var s = base.dump();

            s += " " + CustomLogicModel.escape(modelName);

            /* the code to do this in ChipElm doesn't work here because we don't know
             * how many pins to read until we read the model name!  So we have to
             * duplicate it here. */
            for (int i = 0; i != PostCount; i++)
            {
                if (pins[i].output)
                {
                    s += " " + Volts[i];
                }
            }
            return(s);
        }
Example #12
0
        public string Dump()
        {
            Dumped = true;
            string str = ". " + CustomLogicModel.escape(Name) + " 0 " + SizeX + " " + SizeY + " " + ExtList.Count + " ";
            int    i;

            for (i = 0; i != ExtList.Count; i++)
            {
                var ent = ExtList[i];
                if (i > 0)
                {
                    str += " ";
                }
                str += CustomLogicModel.escape(ent.name) + " " + ent.node + " " + ent.pos + " " + ent.side;
            }
            str += " " + CustomLogicModel.escape(NodeList) + " " + CustomLogicModel.escape(ElmDump);
            return(str);
        }
Example #13
0
        void undump(StringTokenizer st)
        {
            st.nextTokenInt();
            SizeX = st.nextTokenInt();
            SizeY = st.nextTokenInt();
            int extCount = st.nextTokenInt();
            int i;

            ExtList = new List <ExtListEntry>();
            for (i = 0; i != extCount; i++)
            {
                string s  = CustomLogicModel.unescape(st.nextToken());
                int    n  = st.nextTokenInt();
                int    p  = st.nextTokenInt();
                int    sd = st.nextTokenInt();
                ExtList.Add(new ExtListEntry(s, n, p, sd));
            }
            NodeList = CustomLogicModel.unescape(st.nextToken());
            ElmDump  = CustomLogicModel.unescape(st.nextToken());
        }
Example #14
0
 public override void SetElementValue(int n, ElementInfo ei)
 {
     if (n == 2)
     {
         modelName = lastModelName = ei.Textf.Text;
         model     = CustomLogicModel.getModelWithNameOrCopy(modelName, model);
         SetupPins();
         allocNodes();
         SetPoints();
         return;
     }
     if (n == 3)
     {
         var editDialog = new ElementInfoDialog(model);
         CirSim.CustomLogicEditDialog = editDialog;
         var pos = CirSim.Sim.DisplayLocation;
         editDialog.Show(pos.X + P1.X, pos.Y + P1.Y);
         return;
     }
     base.SetElementValue(n, ei);
 }
Example #15
0
 protected override string dump()
 {
     return(base.dump() + " " + mInputCount + " " + CustomLogicModel.escape(mExprString));
 }
Example #16
0
 protected override string dump()
 {
     mFlags |= FLAG_MODEL;
     return(ReferenceName + " " + CustomLogicModel.escape(mModelName));
 }
Example #17
0
 protected override string dump()
 {
     mFlags |= FLAG_ESCAPE;
     return(mSize + " " + CustomLogicModel.escape(mText));
 }
Example #18
0
 public TextElm(Point a, Point b, int f, StringTokenizer st) : base(a, b, f)
 {
     mSize = int.Parse(st.nextToken());
     mText = st.nextToken();
     mText = CustomLogicModel.unescape(mText);
 }
Example #19
0
 public CustomCompositeElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f)
 {
     modelName = CustomLogicModel.unescape(st.nextToken());
     updateModels(st);
 }
Example #20
0
        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;
        }