예제 #1
0
 public LightMathCalculateDataFieldInfo(DataEntityMapping mapping, MathOperator opera, object left, object right)
     : base(mapping)
 {
     _opera = opera;
     _left  = left;
     _right = right;
 }
예제 #2
0
        static void Main(string[] args)
        {
            //MathOperator MethodPointer = new MathOperator(Add);
            //Console.WriteLine(MethodPointer(5, 7));

            //MathOperator MethodPointer2 = new MathOperator((num1, num2) => { return num1 + num2; });
            //Console.WriteLine(MethodPointer2(5, 7));

            //MathOperator MethodPointer3 = (num1, num2) => { return num1 + num2; };
            //Console.WriteLine(MethodPointer3(5, 7));

            MathOperator op = Add;

            op += Sub;
            Console.WriteLine(op(12, 5));

            //var array = new string[]
            //{
            //    "omer", "meital", "matan"
            //};

            //for (int i = 0; i < array.Length; i++)
            //{
            //    Console.WriteLine(array[i]);
            //}

            //var list = array.ToList();
            //list.ForEach(x => x.Replace('e', 'f'));
        }
예제 #3
0
    public static double Test5(double num1, double num2, MathOperator op)
    {
        double num3;

        switch (op)
        {
        case MathOperator.Add:
            num3 = num1 + num2;
            return(num3);

        case MathOperator.Subtract:
            num3 = num1 - num2;
            return(num3);

        case MathOperator.Multiply:
            num3 = num1 * num2;
            return(num3);

        case MathOperator.Divide:
            num3 = num1 / num2;
            return(num3);
        }
        ;
        return(0);
    }
    public static double Test5(double num1, double num2, MathOperator op)
    {
        double num3;

        switch (op)
        {
        case MathOperator.Add:
            num3 = num1 + num2;
            return(num3);

        case MathOperator.Subtract:
            num3 = num1 - num2;
            return(num3);

        case MathOperator.Multiply:
            num3 = num1 * num2;
            return(num3);

        case MathOperator.Divide:
            num3 = num1 / num2;
            return(num3);

        //add default switch case for error: not all code paths return a value  bla bla..
        default:
            return(0);
        }
        ;
    }
예제 #5
0
        public static List <string> InfixToPostfix(List <string> infixExpression)
        {
            List <string>       postfixExpression = new List <string>();
            Heap <MathOperator> signHeap          = new Heap <MathOperator>();
            int openBrackets = 0;

            for (int i = 0; i < infixExpression.Count; i++)
            {
                if (IsMathOperator(infixExpression[i]))
                {
                    MathOperator inputOperator = new MathOperator(infixExpression[i], openBrackets);
                    if (signHeap.Amount == 0)
                    {
                        signHeap.Push(inputOperator);
                    }
                    else
                    {
                        while (signHeap.Amount != 0)
                        {
                            MathOperator tempOperator = signHeap.Pop();
                            if (tempOperator.Priority <= inputOperator.Priority)
                            {
                                signHeap.Push(tempOperator);
                                signHeap.Push(inputOperator);
                                break;
                            }
                            else
                            {
                                postfixExpression.Add(tempOperator.Type);
                                if (signHeap.Amount == 0)
                                {
                                    signHeap.Push(inputOperator);
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (IsBracket(infixExpression[i]))
                {
                    if (infixExpression[i].Equals("("))
                    {
                        openBrackets++;
                    }
                    else
                    {
                        openBrackets--;
                    }
                }
                else
                {
                    postfixExpression.Add(infixExpression[i]);
                }
            }
            while (signHeap.Amount != 0)
            {
                postfixExpression.Add(signHeap.Pop().Type);
            }
            return(postfixExpression);
        }
예제 #6
0
        public ExpressionResult RunExpression(MathOperator op, string expression)
        {
            long result = 0;
            var  values = tokenizer.Parse(expression);

            switch (op)
            {
            case MathOperator.Add:
                result = math.Add(values.ToArray());
                break;

            case MathOperator.Subtract:
                result = math.Subtract(values.ToArray());
                break;

            case MathOperator.Divide:
                result = math.Divide(values.ToArray());
                break;

            case MathOperator.Multiply:
                result = math.Multiply(values.ToArray());
                break;
            }
            return(new ExpressionResult(result, values.ToArray()));
        }
예제 #7
0
            private MathOpcode CreateMathOpcode(MathOperator op)
            {
                MathOpcode opcode = null;

                switch (op)
                {
                case MathOperator.None:
                    return(opcode);

                case MathOperator.Plus:
                    return(new PlusOpcode());

                case MathOperator.Minus:
                    return(new MinusOpcode());

                case MathOperator.Div:
                    return(new DivideOpcode());

                case MathOperator.Multiply:
                    return(new MultiplyOpcode());

                case MathOperator.Mod:
                    return(new ModulusOpcode());

                case MathOperator.Negate:
                    return(new NegateOpcode());
                }
                return(opcode);
            }
예제 #8
0
        public void GetMaxPrecedence()
        {
            List <MathToken> tokens = _lexer.GetTokens("3 + 3 * 2");
            MathToken        token  = _precedence.GetMaxPrecedence(tokens);
            MathOperator     op     = OperatorFactory.Create(token.Token);

            Assert.AreEqual(op.Token, "*");
        }
예제 #9
0
 public static void VisitDic(MathOperator key, string cfg)
 {
     //Discarded unreachable code: IL_0002
     //IL_0003: Incompatible stack heights: 0 vs 1
     if (key != 0)
     {
         throw new FacadePropertyStruct(key, cfg);
     }
 }
예제 #10
0
 public FacadePropertyStruct(MathOperator ident, string ord)
 {
     //Discarded unreachable code: IL_0002, IL_0006
     //IL_0003: Incompatible stack heights: 0 vs 1
     //IL_0007: Incompatible stack heights: 0 vs 1
     SingletonReader.PushGlobal();
     base._002Ector(LogoutDic(ident, ord));
     m_WatcherList  = ident;
     collectionList = ord;
 }
예제 #11
0
        public void SetExpression(Expression leftExpression, Expression rightExpression, MathOperator newMathOperator)
        {
            leftOperand  = new Expression(leftExpression);
            rightOperand = new Expression(rightExpression);
            mathOperator = newMathOperator;
            mathOperand  = MathOperand.Expression;

            constant = 0;
            symbol   = '\0';
        }
예제 #12
0
        public void RetornaExeptionNaDivisaoPorZero()
        {
            //Given
            decimal first  = 10;
            decimal second = 0;

            var mathOperator = new MathOperator();

            //When
            //Then
            Assert.Throws <DivideByZeroException>(() => mathOperator.Divide(first, second));
        }
예제 #13
0
        public void DeveDarErroAoTentarDividirPorDoisNumeros()
        {
            //Given
            var     first        = 100;
            var     second       = 2;
            var     mathOperator = new MathOperator();
            decimal expected     = 50;
            decimal result;

            //When
            result = mathOperator.Divide(first, second);
            //Then
            Assert.Equal(expected, result);
        }
예제 #14
0
        public void RetunrSumOfTwoNumbers()
        {
            //Given
            decimal first    = 10;
            decimal second   = 20;
            decimal expected = 30;

            decimal result;

            var mathOperator = new MathOperator();

            //When
            result = mathOperator.Add(first, second);
            //Then
            Assert.Equal(expected, result);
        }
예제 #15
0
    public void GenerateQuiz()
    {
        operandA = Random.Range(10, 50);
        operandB = Random.Range(10, 50);

        mathOperator = (MathOperator)Random.Range(0, 3);

        string sign = "";

        switch (mathOperator)
        {
        case MathOperator.PLUS:
            correctResult = operandA + operandB;
            sign          = "+";
            break;

        case MathOperator.MINUS:
            correctResult = operandA - operandB;
            sign          = "-";
            break;

        case MathOperator.MULTIPLY:
            correctResult = operandA * operandB;
            sign          = "*";
            break;

        case MathOperator.DEVIDE:
            correctResult = operandA / operandB;
            sign          = "/";
            break;
        }

        question = operandA + " " + sign + " " + operandB + " = ?";

        Debug.Log("Question : " + question);
        Debug.Log("Correct result : " + correctResult);

        results    = new int[4];
        results[0] = correctResult;

        GenerateFakeResults();

        Debug.Log("Answer 1: " + results[0]);
        Debug.Log("Answer 2: " + results[1]);
        Debug.Log("Answer 3: " + results[2]);
        Debug.Log("Answer 4: " + results[3]);
    }
 private string MathOperatorToString(MathOperator @operator)
 {
     switch (@operator)
     {
         case MathOperator.Add:
             return _schema.Operators.Add;
         case MathOperator.Subtract:
             return _schema.Operators.Subtract;
         case MathOperator.Multiply:
             return _schema.Operators.Multiply;
         case MathOperator.Divide:
             return _schema.Operators.Divide;
         case MathOperator.Modulo:
             return _schema.Operators.Modulo;
         default:
             throw new InvalidOperationException("Invalid MathOperator specified.");
     }
 }
 private static string MathOperatorToString(MathOperator @operator)
 {
     switch (@operator)
     {
         case MathOperator.Add:
             return "+";
         case MathOperator.Subtract:
             return "-";
         case MathOperator.Multiply:
             return "*";
         case MathOperator.Divide:
             return "/";
         case MathOperator.Modulo:
             return "%";
         default:
             throw new InvalidOperationException("Invalid MathOperator specified.");
     }
 }
 private int CalculateNextAssignment(int current, int numeric, MathOperator mathOperator)
 {
     if (mathOperator == MathOperator.Multiply)
     {
         return(current * numeric);
     }
     else if (mathOperator == MathOperator.Add)
     {
         return(current + numeric);
     }
     else if (mathOperator == MathOperator.Subtract)
     {
         return(current - numeric);
     }
     else
     {
         throw new Exception("Unknown operator: " + mathOperator);
     }
 }
예제 #19
0
        private string MathOperatorToString(MathOperator @operator)
        {
            switch (@operator)
            {
            case MathOperator.Add:
                return(_schema.Operators.Add);

            case MathOperator.Subtract:
                return(_schema.Operators.Subtract);

            case MathOperator.Multiply:
                return(_schema.Operators.Multiply);

            case MathOperator.Divide:
                return(_schema.Operators.Divide);

            case MathOperator.Modulo:
                return(_schema.Operators.Modulo);

            default:
                throw new InvalidEnumArgumentException("Invalid MathOperator specified.");
            }
        }
예제 #20
0
        private static string MathOperatorToString(MathOperator @operator)
        {
            switch (@operator)
            {
            case MathOperator.Add:
                return("+");

            case MathOperator.Subtract:
                return("-");

            case MathOperator.Multiply:
                return("*");

            case MathOperator.Divide:
                return("/");

            case MathOperator.Modulo:
                return("%");

            default:
                throw new InvalidOperationException("Invalid MathOperator specified.");
            }
        }
예제 #21
0
            MathOpcode CreateMathOpcode(MathOperator op)
            {
                MathOpcode opcode = null;

                switch (op)
                {
                case MathOperator.None:
                    Fx.Assert("");
                    break;

                case MathOperator.Plus:
                    opcode = new PlusOpcode();
                    break;

                case MathOperator.Minus:
                    opcode = new MinusOpcode();
                    break;

                case MathOperator.Div:
                    opcode = new DivideOpcode();
                    break;

                case MathOperator.Multiply:
                    opcode = new MultiplyOpcode();
                    break;

                case MathOperator.Mod:
                    opcode = new ModulusOpcode();
                    break;

                case MathOperator.Negate:
                    opcode = new NegateOpcode();
                    break;
                }

                return(opcode);
            }
예제 #22
0
 public OperatorSymbol(MathOperator o)
 {
     this.ContainedOperator = o;
     if (o == MathOperator.CloseBracket)
     {
         this.precedence = -2;
     }
     else if (o == MathOperator.Divide)
     {
         this.precedence = 8;
     }
     else if (o == MathOperator.Minus)
     {
         this.precedence = 6;
     }
     else if (o == MathOperator.Multiply)
     {
         this.precedence = 8;
     }
     else if (o == MathOperator.OpenBracket)
     {
         this.precedence = -1;
     }
     else if (o == MathOperator.Plus)
     {
         this.precedence = 6;
     }
     else if (o == MathOperator.Power)
     {
         this.precedence = 9;
     }
     else
     {
         this.precedence = -62345;
     }
 }
예제 #23
0
 private void onMathOperatorEnter(MathOperator op)
 {
     solve();
     currentOperator = op;
     prevNumber      = result.Text;
 }
예제 #24
0
        private static OperatorToken OperatorToken(string token, int index)
        {
            OperatorToken t = null;

            if (token.StartsWith(CONST_AND))
            {
                t = new OperatorToken();
            }
            else if (token.StartsWith(CONST_OR))
            {
                t = new OperatorToken();
            }
            else if (token.StartsWith(CONST_BIT_LEFT))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_RIGHT))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_NOT_EQUALS))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_GREATER_EQUALS))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_LESS_EQUALS))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_EQUALS))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_GREATER))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_LESS))
            {
                t = new ConditionToken();
            }
            else if (token.StartsWith(CONST_PLUS))
            {
                t = new MathOperator();
            }
            else if (token.StartsWith(CONST_MINUS))
            {
                t = new MathOperator();
            }
            else if (token.StartsWith(CONST_MULT))
            {
                t = new MathOperator();
            }
            else if (token.StartsWith(CONST_DIVD))
            {
                t = new MathOperator();
            }
            else if (token.StartsWith(CONST_MOD))
            {
                t = new MathOperator();
            }
            else if (token.StartsWith(CONST_BIT_AND))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_LEFT))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_NOT))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_OR))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_RIGHT))
            {
                t = new BitOperator();
            }
            else if (token.StartsWith(CONST_BIT_XOR))
            {
                t = new BitOperator();
            }
            t.Value  = token;
            t.Index  = index;
            t.Length = token.Length;

            return(t);
        }
예제 #25
0
 protected ExpressionString(MathOperator op)
 {
     Operator = op;
     List     = new List <TElem>();
 }
예제 #26
0
 internal MathOpcode(OpcodeID id, MathOperator op) : base(id)
 {
     this.mathOp = op;
 }
            private MathOpcode CreateMathOpcode(MathOperator op)
            {
                MathOpcode opcode = null;
                switch (op)
                {
                    case MathOperator.None:
                        return opcode;

                    case MathOperator.Plus:
                        return new PlusOpcode();

                    case MathOperator.Minus:
                        return new MinusOpcode();

                    case MathOperator.Div:
                        return new DivideOpcode();

                    case MathOperator.Multiply:
                        return new MultiplyOpcode();

                    case MathOperator.Mod:
                        return new ModulusOpcode();

                    case MathOperator.Negate:
                        return new NegateOpcode();
                }
                return opcode;
            }
예제 #28
0
            MathOpcode CreateMathOpcode(MathOperator op)
            {
                MathOpcode opcode = null;
                switch (op)
                {
                    case MathOperator.None:
                        Fx.Assert("");
                        break;

                    case MathOperator.Plus:
                        opcode = new PlusOpcode();
                        break;
                    case MathOperator.Minus:
                        opcode = new MinusOpcode();
                        break;
                    case MathOperator.Div:
                        opcode = new DivideOpcode();
                        break;
                    case MathOperator.Multiply:
                        opcode = new MultiplyOpcode();
                        break;
                    case MathOperator.Mod:
                        opcode = new ModulusOpcode();
                        break;
                    case MathOperator.Negate:
                        opcode = new NegateOpcode();
                        break;
                }

                return opcode;
            }
예제 #29
0
 internal XPathMathExpr(MathOperator op, XPathExpr left, XPathExpr right)
     : base(XPathExprType.Math, ValueDataType.Double, left, right)
 {
     this.op = op;
 }
 internal MathCalculateDataFieldInfo(DataFieldInfo info, MathOperator opera, object value)
     : base(info)
 {
     _opera = opera;
     _value = value;
 }
예제 #31
0
파일: Price.cs 프로젝트: kiquenet/B4F
 private static Price MathOperation(Price lhs, Price rhs, MathOperator op)
 {
     if (((Object)rhs == null) && ((Object)lhs == null))
     {
         //throw new ApplicationException("Both Prices may not be Null!");
         return null;
     }
     else if (((Object)rhs == null) || ((Object)lhs == null))
     {
         if ((Object)rhs == null)
         {
             return (Price)lhs.MemberwiseClone();
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return (Price)rhs.MemberwiseClone();
                 case MathOperator.Subtract:
                     return (rhs * -1);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
     else
     {
         // Use Eq because it is not possible to do operator overloading on an interface
         if (!(lhs.Underlying.Equals(rhs.Underlying)))
         {
             throw new ApplicationException("Cannot add Two different currencies!");
         }
         else if (!(lhs.Instrument.Equals(rhs.Instrument)))
         {
             throw new ApplicationException("Cannot add Two different instruments!");
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return lhs.Clone(lhs.Quantity + rhs.Quantity);
                 case MathOperator.Subtract:
                     return lhs.Clone(lhs.Quantity - rhs.Quantity);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
 }
예제 #32
0
 public TestCalcService()
 {
     op = MathOperator.Add;
 }
예제 #33
0
 internal MathOpcode(OpcodeID id, MathOperator op)
     : base(id)
 {
     this.mathOp = op;
 }
        public GraphElement CreateNode(MathNode mathNode)
        {
            if (mathNode is MathOperator)
            {
                MathOperator add = mathNode as MathOperator;

                return(CreateMathNode(mathNode, mathNode.name, add.m_Position, 2, 1));
            }
            else if (mathNode is MathStackNode)
            {
                MathStackNode mathStackNode = mathNode as MathStackNode;

                return(CreateStackNode(mathStackNode, mathStackNode.m_Position));
            }
            else if (mathNode is MathFunction)
            {
                MathFunction fn = mathNode as MathFunction;

                Debug.Assert(fn.parameterCount == fn.parameterNames.Length);

                Node nodeUI = CreateMathNode(mathNode, mathNode.name, mathNode.m_Position, fn.parameterNames.Length, 1);

                for (int i = 0; i < fn.parameterNames.Length; ++i)
                {
                    (nodeUI.inputContainer.ElementAt(i) as Port).portName = fn.parameterNames[i];
                }

                return(nodeUI);
            }
            else if (mathNode is IMathBookFieldNode)
            {
                IMathBookFieldNode mathBookFieldNode = mathNode as IMathBookFieldNode;
                SimpleTokenNode    tokenNode         = new SimpleTokenNode(mathBookFieldNode);

                tokenNode.SetPosition(new Rect(mathNode.m_Position, Vector2.zero));
                tokenNode.RefreshPorts();
                tokenNode.visible = true;

                return(tokenNode);
            }
            else if (mathNode is MathConstant)
            {
                MathConstant mathConstant = mathNode as MathConstant;

                Node nodeUI = CreateMathNode(
                    mathNode,
                    mathConstant.name,
                    mathConstant.m_Position, 0, 1);

                var field = new DoubleField()
                {
                    value = mathConstant.m_Value
                };
                field.SetEnabled(!(mathConstant is PIConstant));
                field.RegisterValueChangedCallback(evt => mathConstant.m_Value = (float)evt.newValue);
                nodeUI.inputContainer.Add(field);
                nodeUI.RefreshExpandedState();
                return(nodeUI);
            }
            else if (mathNode is MathResult)
            {
                MathResult mathResult = mathNode as MathResult;

                Node nodeUI = CreateMathNode(
                    mathNode,
                    "Result",
                    mathResult.m_Position, 1, 0);

                nodeUI.inputContainer.Add(new Button(() => Debug.Log(mathResult.Evaluate()))
                {
                    text = "Print result"
                });

                return(nodeUI);
            }
            else if (mathNode is MathGroupNode)
            {
                MathGroupNode mathGroupNode = mathNode as MathGroupNode;

                if (mathGroupNode.m_IsScope)
                {
                    return(CreateScope(mathGroupNode,
                                       mathGroupNode.m_Position));
                }
                else
                {
                    return(CreateGroupNode(mathGroupNode,
                                           mathGroupNode.m_Title,
                                           mathGroupNode.m_Position));
                }
            }

            return(null);
        }
예제 #35
0
 public MathReference(object leftOperand, object rightOperand, MathOperator @operator)
 {
     _leftOperand  = leftOperand;
     _rightOperand = rightOperand;
     _operator     = @operator;
 }
예제 #36
0
 private static InstrumentSize MathOperation(InstrumentSize lhs, InstrumentSize rhs, MathOperator op, bool noRounding)
 {
     if (((Object)rhs == null) && ((Object)lhs == null))
     {
         //throw new ApplicationException("Both Instruments may not be Null!");
         return null;
     }
     else if (((Object)rhs == null) || ((Object)lhs == null))
     {
         if ((Object)rhs == null)
         {
             return (InstrumentSize)lhs.MemberwiseClone();
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return (InstrumentSize)rhs.MemberwiseClone();
                 case MathOperator.Subtract:
                     return InstrumentSize.Multiply(rhs, -1M, noRounding);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
     else
     {
         // Use Eq because it is not possible to do operator overloading on an interface
         if (!(lhs.Underlying.Equals(rhs.Underlying)))
         {
             string errorMessage;
             if (lhs.IsMoney)
             {
                 errorMessage = "Cannot add Two different currencies!";
             }
             else
             {
                 errorMessage = "Cannot add two different Intruments";
             }
             throw new ApplicationException(errorMessage);
         }
         else
         {
             switch (op)
             {
                 case MathOperator.Add:
                     return new InstrumentSize(lhs.Quantity + rhs.Quantity, lhs.Underlying, noRounding);
                 case MathOperator.Subtract:
                     return new InstrumentSize(lhs.Quantity - rhs.Quantity, lhs.Underlying, noRounding);
                 default:
                     throw new ApplicationException("You did not select a valid math operation");
             }
         }
     }
 }
예제 #37
0
 private MathReference(object leftOperand, object rightOperand, MathOperator @operator, string alias) : base(alias)
 {
     _leftOperand  = leftOperand;
     _rightOperand = rightOperand;
     _operator     = @operator;
 }
예제 #38
0
 public MathExpressionResult(MathOperator op, char opChar, string expression)
 {
     this.op         = op;
     this.opChar     = opChar;
     this.expression = expression;
 }
        public void Reload(IEnumerable <MathNode> nodesToReload, IEnumerable <MathPlacemat> placemats, IEnumerable <MathStickyNote> stickies, Dictionary <string, string> oldToNewIdMapping = null)
        {
            string oldId;
            var    nodes          = new Dictionary <MathNode, GraphElement>();
            var    oldIdToNewNode = new Dictionary <string, ISelectable>();

            var newToOldIdMapping = new Dictionary <string, string>();

            if (oldToNewIdMapping != null)
            {
                foreach (var oldIdKV in oldToNewIdMapping)
                {
                    newToOldIdMapping[oldIdKV.Value] = oldIdKV.Key;
                }
            }

            // Create the nodes.
            foreach (MathNode mathNode in nodesToReload)
            {
                GraphElement node = m_SimpleGraphViewWindow.CreateNode(mathNode);

                if (node is Group)
                {
                    node.name = "SimpleGroup";
                }
                else if (node is Scope)
                {
                    node.name = "SimpleScope";
                }
                else
                {
                    node.name = "SimpleNode";
                }

                if (node == null)
                {
                    Debug.LogError("Could not create node " + mathNode);
                    continue;
                }

                nodes[mathNode] = node;

                if (mathNode.groupNode == null)
                {
                    if (newToOldIdMapping.TryGetValue(mathNode.nodeID.ToString(), out oldId))
                    {
                        oldIdToNewNode.Add(oldId, node);
                    }
                }

                AddElement(node);
            }

            // Assign scopes
            foreach (MathNode mathNode in nodesToReload)
            {
                if (mathNode.groupNode == null)
                {
                    continue;
                }

                Scope graphScope = nodes[mathNode.groupNode] as Scope;

                graphScope.AddElement(nodes[mathNode]);
            }

            // Add to stacks
            foreach (MathNode mathNode in nodesToReload)
            {
                MathStackNode stack = mathNode as MathStackNode;

                if (stack == null)
                {
                    continue;
                }

                StackNode graphStackNode = nodes[stack] as StackNode;

                for (int i = 0; i < stack.nodeCount; ++i)
                {
                    MathNode stackMember = stack.GetNode(i);
                    if (stackMember == null)
                    {
                        Debug.LogWarning("null stack member! Item " + i + " of stack " + stack.name + " is null. Possibly a leftover from bad previous manips.");
                    }

                    graphStackNode.AddElement(nodes[stackMember]);
                }
            }

            // Connect the presenters.
            foreach (var mathNode in nodesToReload)
            {
                if (mathNode is MathOperator)
                {
                    MathOperator mathOperator = mathNode as MathOperator;

                    if (!nodes.ContainsKey(mathNode))
                    {
                        Debug.LogError("No element found for " + mathNode);
                        continue;
                    }

                    var graphNode = nodes[mathNode] as Node;

                    if (mathOperator.left != null && nodes.ContainsKey(mathOperator.left))
                    {
                        var outputPort = (nodes[mathOperator.left] as Node).outputContainer[0] as Port;
                        var inputPort  = graphNode.inputContainer[0] as Port;

                        Edge edge = inputPort.ConnectTo(outputPort);
                        edge.viewDataKey = mathOperator.left.nodeID + "_edge";
                        AddElement(edge);
                    }
                    else if (mathOperator.left != null)
                    {
                        //add.m_Left = null;
                        Debug.LogWarning("Invalid left operand for operator " + mathOperator + " , " + mathOperator.left);
                    }

                    if (mathOperator.right != null && nodes.ContainsKey(mathOperator.right))
                    {
                        var outputPort = (nodes[mathOperator.right] as Node).outputContainer[0] as Port;
                        var inputPort  = graphNode.inputContainer[1] as Port;

                        Edge edge = inputPort.ConnectTo(outputPort);
                        edge.viewDataKey = mathOperator.right.nodeID + "_edge";
                        AddElement(edge);
                    }
                    else if (mathOperator.right != null)
                    {
                        Debug.LogWarning("Invalid right operand for operator " + mathOperator + " , " + mathOperator.right);
                    }
                }
                else if (mathNode is MathFunction)
                {
                    MathFunction mathFunction = mathNode as MathFunction;

                    if (!nodes.ContainsKey(mathNode))
                    {
                        Debug.LogError("No element found for " + mathNode);
                        continue;
                    }

                    var graphNode = nodes[mathNode] as Node;

                    for (int i = 0; i < mathFunction.parameterCount; ++i)
                    {
                        MathNode param = mathFunction.GetParameter(i);

                        if (param != null && nodes.ContainsKey(param))
                        {
                            var outputPort = (nodes[param] as Node).outputContainer[0] as Port;
                            var inputPort  = graphNode.inputContainer[i] as Port;

                            Edge edge = inputPort.ConnectTo(outputPort);
                            edge.viewDataKey = param.nodeID + "_edge";
                            AddElement(edge);
                        }
                        else if (param != null)
                        {
                            Debug.LogWarning("Invalid parameter for function" + mathFunction + " , " +
                                             param);
                        }
                    }
                }
                else if (mathNode is MathResult)
                {
                    MathResult mathResult = mathNode as MathResult;
                    var        graphNode  = nodes[mathNode] as Node;

                    if (mathResult.root != null)
                    {
                        var outputPort = (nodes[mathResult.root] as Node).outputContainer[0] as Port;
                        var inputPort  = graphNode.inputContainer[0] as Port;

                        Edge edge = inputPort.ConnectTo(outputPort);
                        edge.viewDataKey = mathResult.root.nodeID + "_edge";
                        AddElement(edge);
                    }
                }
            }

            foreach (var matModel in placemats.OrderBy(p => p.zOrder))
            {
                var newPlacemat = placematContainer.CreatePlacemat <SimplePlacemat>(matModel.position, matModel.zOrder, matModel.title);
                newPlacemat.userData    = matModel;
                newPlacemat.viewDataKey = matModel.identification;
                newPlacemat.Model       = matModel;

                if (newToOldIdMapping.TryGetValue(matModel.identification, out oldId))
                {
                    oldIdToNewNode.Add(oldId, newPlacemat);
                }
            }

            if (stickies != null)
            {
                var existingStickies = this.Query <SimpleStickyNote>().ToList();

                foreach (var sticky in existingStickies.Where(t => !stickies.Contains(t.model)))
                {
                    RemoveElement(sticky);
                }

                foreach (var stickyModel in stickies.Except(existingStickies.Select(t => t.model)))
                {
                    var newSticky = new SimpleStickyNote();
                    newSticky.model    = stickyModel;
                    newSticky.userData = stickyModel;
                    AddElement(newSticky);

                    if (newToOldIdMapping.TryGetValue(stickyModel.id, out oldId))
                    {
                        oldIdToNewNode.Add(oldId, newSticky);
                    }
                }
            }

            // Now that all graph elements have been created, init the collapsed elements of each placemat.
            foreach (var p in this.Query <SimplePlacemat>().ToList())
            {
                p.InitCollapsedElementsFromModel();
            }

            // Make sure collapsed edges are hidden.
            placematContainer.HideCollapsedEdges();

            UpdateSelection(oldIdToNewNode);

            RebuildBlackboard();
        }