Esempio n. 1
0
 public AGPropertyExpr(starPadSDK.MathExpr.Expr expr, EqGoal goal)
     : base(expr)
 {
     _goal = goal;
 }
Esempio n. 2
0
        private XElement CheckExprHead(ref XElement gates, starPadSDK.MathExpr.Expr expr, DPoint point, out bool isNotGate)
        {
            XElement gt = null;

            if (expr == starPadSDK.MathExpr.WellKnownSym.plus)
            {
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Or");
                gt.SetAttributeValue("Name", "Or");
                gt.SetAttributeValue("ID", cid);
                gt.SetAttributeValue("NumInputs", 2);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", point.X);
                gt.Element("Point").SetAttributeValue("Y", point.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                //iniX -= 80;
                //iniY += 80;
                isNotGate = false;
            }
            else if (expr == starPadSDK.MathExpr.WellKnownSym.times)
            {
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "And");
                gt.SetAttributeValue("Name", "And");
                gt.SetAttributeValue("ID", cid);
                gt.SetAttributeValue("NumInputs", 2);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", point.X);
                gt.Element("Point").SetAttributeValue("Y", point.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                //iniX -= 80;
                //iniY += 80;
                isNotGate = false;
            }
            else if( expr == starPadSDK.MathExpr.WellKnownSym.lognot){ 
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Not");
                gt.SetAttributeValue("Name", "Not");
                gt.SetAttributeValue("ID", cid);
                gt.SetAttributeValue("NumInputs", 2);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", point.X);
                gt.Element("Point").SetAttributeValue("Y", point.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                isNotGate = true;
            }
            else if (expr == starPadSDK.MathExpr.WellKnownSym.xorGate)
            {
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Xor");
                gt.SetAttributeValue("Name", "Xor");
                gt.SetAttributeValue("ID", cid);
                gt.SetAttributeValue("NumInputs", 2);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", point.X);
                gt.Element("Point").SetAttributeValue("Y", point.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                isNotGate = false;
            }
            else if (expr == starPadSDK.MathExpr.WellKnownSym.power)
            {
                //Not Gate
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Not");
                gt.SetAttributeValue("Name", "Not");
                gt.SetAttributeValue("ID", cid);
                gt.SetAttributeValue("NumInputs", 1);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", point.X);
                gt.Element("Point").SetAttributeValue("Y", point.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                isNotGate = true;
            }
            else {
                isNotGate = false;    
            }

            return gt;
        }
Esempio n. 3
0
 public AGShapeExpr(starPadSDK.MathExpr.Expr expr, ShapeSymbol ss)
     : base(expr)
 {
     _shapeSymbol = ss;
 }
Esempio n. 4
0
        private XElement ConvertStarPadExprToXElement(ref XElement gates, ref XElement wires, starPadSDK.MathExpr.Expr expr, DPoint parentPos)
        {
            if (expr is starPadSDK.MathExpr.LetterSym)
            {
                #region
                //So it is the input, add inputGate and relative Comment
                string letter = (expr as starPadSDK.MathExpr.LetterSym).Letter.ToString();
                if (!addedInputGate.Keys.Contains(letter)) {
                   
                    //Create one UserInput with Comment
                    XElement gt = new XElement("Gate");
                    gt.SetAttributeValue("Type", "UserInput");
                    gt.SetAttributeValue("Name", letter);
                    gt.SetAttributeValue("ID", cid);
                    gt.Add(new XElement("Point"));
                    gt.Element("Point").SetAttributeValue("X", parentPos.X - Rand());
                    gt.Element("Point").SetAttributeValue("Y", parentPos.Y);
                    gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                    gates.Add(gt);
                    addedInputGate.Add(letter, gt);
                    cid++;
                    //iniX -= 80;

                    gt = new XElement("Gate");
                    gt.SetAttributeValue("Type", "Comment");
                    gt.SetAttributeValue("Name", letter);
                    gt.SetAttributeValue("ID", cid);
                    gt.Add(new XElement("Point"));
                    gt.Element("Point").SetAttributeValue("X", parentPos.X - 2 * Rand());
                    gt.Element("Point").SetAttributeValue("Y", parentPos.Y);
                    gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                    gt.Add(new XElement("Comment", letter));

                    gates.Add(gt);
                    cid++;
                    //iniY += 80;
                }
                return addedInputGate[letter];
                #endregion
            }
            else if (expr is starPadSDK.MathExpr.CompositeExpr)
            {
                starPadSDK.MathExpr.CompositeExpr compositeExpr = expr as starPadSDK.MathExpr.CompositeExpr;

                bool isNotGate = false;

                XElement gate = CheckExprHead(ref gates, compositeExpr.Head, new DPoint(parentPos.X - Rand(), parentPos.Y), out isNotGate);

                int toGateID = int.Parse(gate.Attribute("ID").Value);
              
                if (compositeExpr.Args.Length == 2)
                {
                    if (isNotGate)
                    {
                        //Not gate 
                        XElement fromGate = ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[0], new DPoint(parentPos.X - Rand(), parentPos.Y));
                        int fromGateID = int.Parse(fromGate.Attribute("ID").Value);

                        XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", fromGateID);
                        wire.Element("From").SetAttributeValue("Port", 0);
                        wire.Element("To").SetAttributeValue("ID", toGateID);
                        wire.Element("To").SetAttributeValue("Port", 0);
                        wires.Add(wire);
                    }
                    else
                    {
                        //Left Child
                        XElement fromGate = ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[0], new DPoint(parentPos.X - Rand(), parentPos.Y - Rand()));
                        int fromGateID = int.Parse(fromGate.Attribute("ID").Value);

                        XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", fromGateID);
                        wire.Element("From").SetAttributeValue("Port", 0);
                        wire.Element("To").SetAttributeValue("ID", toGateID);
                        wire.Element("To").SetAttributeValue("Port", 1);
                        wires.Add(wire);

                        //Right Child
                        fromGate = ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[1], new DPoint(parentPos.X - Rand(), parentPos.Y + Rand()));
                        fromGateID = int.Parse(fromGate.Attribute("ID").Value);

                        wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", fromGateID);
                        wire.Element("From").SetAttributeValue("Port", 0);
                        wire.Element("To").SetAttributeValue("ID", toGateID);
                        wire.Element("To").SetAttributeValue("Port", 0);
                        wires.Add(wire);
                    }
                }
                else if (compositeExpr.Args.Length > 2)
                {
                    //There are above 2 argumennts inside of list, so construct one new binary tree to parse. 

                    List<XElement> duplicatedGates = new List<XElement>();
                    DPoint tempPoint = new DPoint(parentPos.X -deltaX, parentPos.Y - deltaY);;
                    for(int i = 0; i < compositeExpr.Args.Length - 2; i++)
                    {
                        XElement gt = DuplicateGate(ref gates, gate, ref tempPoint);
                        duplicatedGates.Add(gt);
                    }

                    List<starPadSDK.MathExpr.Expr> compositeExpressions = new List<starPadSDK.MathExpr.Expr>();

                    foreach (starPadSDK.MathExpr.Expr ce in compositeExpr.Args)
                    {
                        compositeExpressions.Add(ce);
                    }

                    XElementTree argTree = new XElementTree(gate);

                    duplicateWires(ref gates, ref wires, ref duplicatedGates, ref compositeExpressions, ref argTree);

                }
                else if (compositeExpr.Args.Length == 1)
                { 
                    //Not gate 
                    XElement fromGate = ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[0], new DPoint(parentPos.X - Rand(), parentPos.Y));
                    int fromGateID = int.Parse(fromGate.Attribute("ID").Value);

                    XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                    wire.Element("From").SetAttributeValue("ID", fromGateID);
                    wire.Element("From").SetAttributeValue("Port", 0);
                    wire.Element("To").SetAttributeValue("ID", toGateID);
                    wire.Element("To").SetAttributeValue("Port", 0);
                    wires.Add(wire);
                }
                return gate;
            }
            else {
                return null;
            }
        }
Esempio n. 5
0
        //Expression
        public XElement ParseStarPadExpr(starPadSDK.MathExpr.Expr expr)
        {
            Reset();

            XElement root = new XElement("CircuitGroup");
            root.SetAttributeValue("Version", "1.2");
            XElement circuit = new XElement("Circuit");

            XElement gates = new XElement("Gates");
            XElement wires = new XElement("Wires");

            if (expr is starPadSDK.MathExpr.CompositeExpr)
            {
                #region composite handling
                starPadSDK.MathExpr.CompositeExpr compositeExpr = expr as starPadSDK.MathExpr.CompositeExpr;
                if (compositeExpr.Head != starPadSDK.MathExpr.WellKnownSym.equals)
                {
                    #region

                    //Create UserOutput and relative comment    

                    XElement gt = new XElement("Gate");
                    gt.SetAttributeValue("Type", "Comment");
                    gt.SetAttributeValue("Name", "Y");
                    gt.SetAttributeValue("ID", cid);
                    gt.Add(new XElement("Point"));
                    gt.Element("Point").SetAttributeValue("X", dPoint.X);
                    gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                    gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                    gt.Add(new XElement("Comment", "Y"));

                    gates.Add(gt);
                    cid++;
                    //iniY += 80;

                    gt = new XElement("Gate");
                    gt.SetAttributeValue("Type", "UserOutput");
                    gt.SetAttributeValue("Name", "Y");
                    gt.SetAttributeValue("ID", cid);
                    gt.Add(new XElement("Point"));
                    gt.Element("Point").SetAttributeValue("X", dPoint.X - deltaX);
                    gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                    gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                    gates.Add(gt);
                    cid++;
                    //iniX -= 80;

                    XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                    wire.Element("From").SetAttributeValue("ID", 3);
                    wire.Element("From").SetAttributeValue("Port", 0);
                    wire.Element("To").SetAttributeValue("ID", 2);
                    wire.Element("To").SetAttributeValue("Port", 0);

                    wires.Add(wire);

                    ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr, new DPoint(dPoint.X- deltaX, dPoint.Y));

                    #endregion
                }
                else {
                    if (compositeExpr.Args[0] is starPadSDK.MathExpr.LetterSym)
                    {
                        #region
                        string outputLabel = (compositeExpr.Args[0] as starPadSDK.MathExpr.LetterSym).Letter.ToString();

                        //Create UserOutput and relative comment    

                        XElement gt = new XElement("Gate");
                        gt.SetAttributeValue("Type", "Comment");
                        gt.SetAttributeValue("Name", outputLabel);
                        gt.SetAttributeValue("ID", cid);
                        gt.Add(new XElement("Point"));
                        gt.Element("Point").SetAttributeValue("X", dPoint.X);
                        gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                        gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                        gt.Add(new XElement("Comment", outputLabel));

                        gates.Add(gt);
                        cid++;
                        //iniX -= 80;

                        gt = new XElement("Gate");
                        gt.SetAttributeValue("Type", "UserOutput");
                        gt.SetAttributeValue("Name", outputLabel);
                        gt.SetAttributeValue("ID", cid);
                        gt.Add(new XElement("Point"));
                        gt.Element("Point").SetAttributeValue("X", dPoint.X - deltaX);
                        gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                        gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                        gates.Add(gt);
                        cid++;
                        //iniX -= 80;

                        XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", 3);
                        wire.Element("From").SetAttributeValue("Port", 0);
                        wire.Element("To").SetAttributeValue("ID", 2);
                        wire.Element("To").SetAttributeValue("Port", 0);

                        wires.Add(wire);

                        ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[1], new DPoint(dPoint.X - deltaX, dPoint.Y));
                        #endregion
                    }
                    else
                    {
                        #region
                        string outputLabel = (compositeExpr.Args[1] as starPadSDK.MathExpr.LetterSym).Letter.ToString();

                        //Create UserOutput and relative comment    

                        XElement gt = new XElement("Gate");
                        gt.SetAttributeValue("Type", "Comment");
                        gt.SetAttributeValue("Name", outputLabel);
                        gt.SetAttributeValue("ID", cid);
                        gt.Add(new XElement("Point"));
                        gt.Element("Point").SetAttributeValue("X", dPoint.X);
                        gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                        gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                        gt.Add(new XElement("Comment", outputLabel));

                        gates.Add(gt);
                        cid++;
                        //iniX -= 80;

                        gt = new XElement("Gate");
                        gt.SetAttributeValue("Type", "UserOutput");
                        gt.SetAttributeValue("Name", outputLabel);
                        gt.SetAttributeValue("ID", cid);
                        gt.Add(new XElement("Point"));
                        gt.Element("Point").SetAttributeValue("X", dPoint.X - deltaX);
                        gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                        gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                        gates.Add(gt);
                        cid++;
                        //iniX -= 80;

                        XElement wire = new XElement("Wire", new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", 3);
                        wire.Element("From").SetAttributeValue("Port", 0);
                        wire.Element("To").SetAttributeValue("ID", 2);
                        wire.Element("To").SetAttributeValue("Port", 0);

                        wires.Add(wire);

                        ConvertStarPadExprToXElement(ref gates, ref wires, compositeExpr.Args[0], new DPoint(dPoint.X - deltaX, dPoint.Y));
                        #endregion
                    }
                }
                #endregion
            }
            else if (expr is starPadSDK.MathExpr.LetterSym)
            {
                #region simple Symbol input
                //Create one UserOutput with Comment
                XElement gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Comment");
                gt.SetAttributeValue("Name", "Y");
                gt.SetAttributeValue("ID", cid);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", dPoint.X );
                gt.Element("Point").SetAttributeValue("Y", dPoint.Y );
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                gt.Add(new XElement("Comment", "Y"));
                

                gates.Add(gt);
                cid++;
                //dPoint.Y += 80;

                 gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "UserOutput");
                gt.SetAttributeValue("Name", "Y");
                gt.SetAttributeValue("ID", cid);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", dPoint.X - deltaX);
                gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                //dPoint.X -= 80;

                //Create one UserInput with Comment
                gt = new XElement("Gate");
                gt.SetAttributeValue("Type","UserInput");
                gt.SetAttributeValue("Name", ((starPadSDK.MathExpr.LetterSym)expr).Letter.ToString());
                gt.SetAttributeValue("ID", cid);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", dPoint.X - 2 * deltaX);
                gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);

                gates.Add(gt);
                cid++;
                //dPoint.X -= 80;

                gt = new XElement("Gate");
                gt.SetAttributeValue("Type", "Comment");
                gt.SetAttributeValue("Name", ((starPadSDK.MathExpr.LetterSym)expr).Letter.ToString());
                gt.SetAttributeValue("ID", cid);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", dPoint.X - 3 * deltaX);
                gt.Element("Point").SetAttributeValue("Y", dPoint.Y);
                gt.Element("Point").SetAttributeValue("Angle", 0.0f);
                gt.Add(new XElement("Comment", ((starPadSDK.MathExpr.LetterSym)expr).Letter.ToString()));

                gates.Add(gt);
                cid++;
                //dPoint.Y += 80;

                //Add one wire
                XElement wire = new XElement("Wire",new XElement("From"), new XElement("To"));
                wire.Element("From").SetAttributeValue("ID", 3);
                wire.Element("From").SetAttributeValue("Port", 0);
                wire.Element("To").SetAttributeValue("ID", 2);
                wire.Element("To").SetAttributeValue("Port", 0);
                
                wires.Add(wire);

                #endregion
            }
            else
            {
                return null;
            }

            circuit.Add(gates);
            circuit.Add(wires);

            root.Add(circuit);
            return root;
 
        }
Esempio n. 6
0
 protected AGEquationExpr(starPadSDK.MathExpr.Expr expr)
     : base(expr)
 {
 }
Esempio n. 7
0
 public AGEquationExpr(starPadSDK.MathExpr.Expr expr, Equation eq)
     : base(expr)
 {
     _equation = eq;
 }
Esempio n. 8
0
 public IKnowledge(starPadSDK.MathExpr.Expr exp)
 {
     _inputExpr = exp;
 }