public bool HandleKey(FormulaEditorKey key, LocalVariable localVariable = null, GlobalVariable globalVariable = null)
        {
            if (key == FormulaEditorKey.Delete)
            {
                PushUndo();
                return(Delete());
            }

            PushUndo();
            var token = CreateToken(key, localVariable, globalVariable);

            return(Insert((token is IFormulaFunction)
                ? new[] { token, FormulaTokenFactory.CreateParenthesisToken(true) }
                : new[] { token }));
        }
Ejemplo n.º 2
0
 public FormulaKey(FormulaEditorKey key, LocalVariable localVariable = null, GlobalVariable globalVariable = null)
 {
     Key = key;
     LocalVariable = localVariable;
     GlobalVariable = globalVariable;
 }
        private static IFormulaToken CreateToken(FormulaEditorKey key, LocalVariable localVariable, GlobalVariable globalVariable)
        {
            switch (key)
            {
            // Constants
            case FormulaEditorKey.D0: return(FormulaTokenFactory.CreateDigitToken(0));

            case FormulaEditorKey.D1: return(FormulaTokenFactory.CreateDigitToken(1));

            case FormulaEditorKey.D2: return(FormulaTokenFactory.CreateDigitToken(2));

            case FormulaEditorKey.D3: return(FormulaTokenFactory.CreateDigitToken(3));

            case FormulaEditorKey.D4: return(FormulaTokenFactory.CreateDigitToken(4));

            case FormulaEditorKey.D5: return(FormulaTokenFactory.CreateDigitToken(5));

            case FormulaEditorKey.D6: return(FormulaTokenFactory.CreateDigitToken(6));

            case FormulaEditorKey.D7: return(FormulaTokenFactory.CreateDigitToken(7));

            case FormulaEditorKey.D8: return(FormulaTokenFactory.CreateDigitToken(8));

            case FormulaEditorKey.D9: return(FormulaTokenFactory.CreateDigitToken(9));

            case FormulaEditorKey.DecimalSeparator: return(FormulaTokenFactory.CreateDecimalSeparatorToken());

            case FormulaEditorKey.ParameterSeparator: return(FormulaTokenFactory.CreateParameterSeparatorToken());

            case FormulaEditorKey.Pi: return(FormulaTokenFactory.CreatePiToken());

            case FormulaEditorKey.True: return(FormulaTokenFactory.CreateTrueToken());

            case FormulaEditorKey.False: return(FormulaTokenFactory.CreateFalseToken());

            // Operators
            case FormulaEditorKey.Plus: return(FormulaTokenFactory.CreatePlusToken());

            case FormulaEditorKey.Minus: return(FormulaTokenFactory.CreateMinusToken());

            case FormulaEditorKey.Multiply: return(FormulaTokenFactory.CreateMultiplyToken());

            case FormulaEditorKey.Divide: return(FormulaTokenFactory.CreateDivideToken());

            case FormulaEditorKey.Caret: return(FormulaTokenFactory.CreateCaretToken());

            case FormulaEditorKey.Equals: return(FormulaTokenFactory.CreateEqualsToken());

            case FormulaEditorKey.NotEquals: return(FormulaTokenFactory.CreateNotEqualsToken());

            case FormulaEditorKey.Greater: return(FormulaTokenFactory.CreateGreaterToken());

            case FormulaEditorKey.GreaterEqual: return(FormulaTokenFactory.CreateGreaterEqualToken());

            case FormulaEditorKey.Less: return(FormulaTokenFactory.CreateLessToken());

            case FormulaEditorKey.LessEqual: return(FormulaTokenFactory.CreateLessEqualToken());

            case FormulaEditorKey.And: return(FormulaTokenFactory.CreateAndToken());

            case FormulaEditorKey.Or: return(FormulaTokenFactory.CreateOrToken());

            case FormulaEditorKey.Not: return(FormulaTokenFactory.CreateNotToken());

            case FormulaEditorKey.Mod: return(FormulaTokenFactory.CreateModToken());

            // Functions
            case FormulaEditorKey.Exp: return(FormulaTokenFactory.CreateExpToken());

            case FormulaEditorKey.Log: return(FormulaTokenFactory.CreateLogToken());

            case FormulaEditorKey.Ln: return(FormulaTokenFactory.CreateLnToken());

            case FormulaEditorKey.Min: return(FormulaTokenFactory.CreateMinToken());

            case FormulaEditorKey.Max: return(FormulaTokenFactory.CreateMaxToken());

            case FormulaEditorKey.Sin: return(FormulaTokenFactory.CreateSinToken());

            case FormulaEditorKey.Cos: return(FormulaTokenFactory.CreateCosToken());

            case FormulaEditorKey.Tan: return(FormulaTokenFactory.CreateTanToken());

            case FormulaEditorKey.Arcsin: return(FormulaTokenFactory.CreateArcsinToken());

            case FormulaEditorKey.Arccos: return(FormulaTokenFactory.CreateArccosToken());

            case FormulaEditorKey.Arctan: return(FormulaTokenFactory.CreateArctanToken());

            case FormulaEditorKey.Sqrt: return(FormulaTokenFactory.CreateSqrtToken());

            case FormulaEditorKey.Abs: return(FormulaTokenFactory.CreateAbsToken());

            case FormulaEditorKey.Round: return(FormulaTokenFactory.CreateRoundToken());

            case FormulaEditorKey.Random: return(FormulaTokenFactory.CreateRandomToken());

            // Sensors
            case FormulaEditorKey.AccelerationX: return(FormulaTokenFactory.CreateAccelerationXToken());

            case FormulaEditorKey.AccelerationY: return(FormulaTokenFactory.CreateAccelerationYToken());

            case FormulaEditorKey.AccelerationZ: return(FormulaTokenFactory.CreateAccelerationZToken());

            case FormulaEditorKey.Compass: return(FormulaTokenFactory.CreateCompassToken());

            case FormulaEditorKey.InclinationX: return(FormulaTokenFactory.CreateInclinationXToken());

            case FormulaEditorKey.InclinationY: return(FormulaTokenFactory.CreateInclinationYToken());

            case FormulaEditorKey.Loudness: return(FormulaTokenFactory.CreateLoudnessToken());

            // Properties
            case FormulaEditorKey.Brightness: return(FormulaTokenFactory.CreateBrightnessToken());

            case FormulaEditorKey.Layer: return(FormulaTokenFactory.CreateLayerToken());

            case FormulaEditorKey.Transparency: return(FormulaTokenFactory.CreateTransparencyToken());

            case FormulaEditorKey.PositionX: return(FormulaTokenFactory.CreatePositionXToken());

            case FormulaEditorKey.PositionY: return(FormulaTokenFactory.CreatePositionYToken());

            case FormulaEditorKey.Rotation: return(FormulaTokenFactory.CreateRotationToken());

            case FormulaEditorKey.Size: return(FormulaTokenFactory.CreateSizeToken());

            // Variables
            case FormulaEditorKey.LocalVariable: return(FormulaTokenFactory.CreateLocalVariableToken(localVariable));

            case FormulaEditorKey.GlobalVariable: return(FormulaTokenFactory.CreateGlobalVariableToken(globalVariable));

            // brackets
            case FormulaEditorKey.OpeningParenthesis: return(FormulaTokenFactory.CreateParenthesisToken(true));

            case FormulaEditorKey.ClosingParenthesis: return(FormulaTokenFactory.CreateParenthesisToken(false));

            default: throw new ArgumentOutOfRangeException("key");
            }
        }
 public FormulaKey(FormulaEditorKey key, LocalVariable localVariable = null, GlobalVariable globalVariable = null)
 {
     Key            = key;
     LocalVariable  = localVariable;
     GlobalVariable = globalVariable;
 }
Ejemplo n.º 5
0
        private static IFormulaToken CreateToken(FormulaEditorKey key, LocalVariable localVariable, GlobalVariable globalVariable)
        {
            switch (key)
            {
                // Constants
                case FormulaEditorKey.D0: return FormulaTokenFactory.CreateDigitToken(0);
                case FormulaEditorKey.D1: return FormulaTokenFactory.CreateDigitToken(1);
                case FormulaEditorKey.D2: return FormulaTokenFactory.CreateDigitToken(2);
                case FormulaEditorKey.D3: return FormulaTokenFactory.CreateDigitToken(3);
                case FormulaEditorKey.D4: return FormulaTokenFactory.CreateDigitToken(4);
                case FormulaEditorKey.D5: return FormulaTokenFactory.CreateDigitToken(5);
                case FormulaEditorKey.D6: return FormulaTokenFactory.CreateDigitToken(6);
                case FormulaEditorKey.D7: return FormulaTokenFactory.CreateDigitToken(7);
                case FormulaEditorKey.D8: return FormulaTokenFactory.CreateDigitToken(8);
                case FormulaEditorKey.D9: return FormulaTokenFactory.CreateDigitToken(9);
                case FormulaEditorKey.DecimalSeparator: return FormulaTokenFactory.CreateDecimalSeparatorToken();
                case FormulaEditorKey.ParameterSeparator: return FormulaTokenFactory.CreateParameterSeparatorToken();
                case FormulaEditorKey.Pi: return FormulaTokenFactory.CreatePiToken();
                case FormulaEditorKey.True: return FormulaTokenFactory.CreateTrueToken();
                case FormulaEditorKey.False: return FormulaTokenFactory.CreateFalseToken();

                // Operators
                case FormulaEditorKey.Plus: return FormulaTokenFactory.CreatePlusToken();
                case FormulaEditorKey.Minus: return FormulaTokenFactory.CreateMinusToken();
                case FormulaEditorKey.Multiply: return FormulaTokenFactory.CreateMultiplyToken();
                case FormulaEditorKey.Divide: return FormulaTokenFactory.CreateDivideToken();
                case FormulaEditorKey.Caret: return FormulaTokenFactory.CreateCaretToken();
                case FormulaEditorKey.Equals: return FormulaTokenFactory.CreateEqualsToken();
                case FormulaEditorKey.NotEquals: return FormulaTokenFactory.CreateNotEqualsToken();
                case FormulaEditorKey.Greater: return FormulaTokenFactory.CreateGreaterToken();
                case FormulaEditorKey.GreaterEqual: return FormulaTokenFactory.CreateGreaterEqualToken();
                case FormulaEditorKey.Less: return FormulaTokenFactory.CreateLessToken();
                case FormulaEditorKey.LessEqual: return FormulaTokenFactory.CreateLessEqualToken();
                case FormulaEditorKey.And: return FormulaTokenFactory.CreateAndToken();
                case FormulaEditorKey.Or: return FormulaTokenFactory.CreateOrToken();
                case FormulaEditorKey.Not: return FormulaTokenFactory.CreateNotToken();
                case FormulaEditorKey.Mod: return FormulaTokenFactory.CreateModToken();

                // Functions
                case FormulaEditorKey.Exp: return FormulaTokenFactory.CreateExpToken();
                case FormulaEditorKey.Log: return FormulaTokenFactory.CreateLogToken();
                case FormulaEditorKey.Ln: return FormulaTokenFactory.CreateLnToken();
                case FormulaEditorKey.Min: return FormulaTokenFactory.CreateMinToken();
                case FormulaEditorKey.Max: return FormulaTokenFactory.CreateMaxToken();
                case FormulaEditorKey.Sin: return FormulaTokenFactory.CreateSinToken();
                case FormulaEditorKey.Cos: return FormulaTokenFactory.CreateCosToken();
                case FormulaEditorKey.Tan: return FormulaTokenFactory.CreateTanToken();
                case FormulaEditorKey.Arcsin: return FormulaTokenFactory.CreateArcsinToken();
                case FormulaEditorKey.Arccos: return FormulaTokenFactory.CreateArccosToken();
                case FormulaEditorKey.Arctan: return FormulaTokenFactory.CreateArctanToken();
                case FormulaEditorKey.Sqrt: return FormulaTokenFactory.CreateSqrtToken();
                case FormulaEditorKey.Abs: return FormulaTokenFactory.CreateAbsToken();
                case FormulaEditorKey.Round: return FormulaTokenFactory.CreateRoundToken();
                case FormulaEditorKey.Random: return FormulaTokenFactory.CreateRandomToken();

                // Sensors
                case FormulaEditorKey.AccelerationX: return FormulaTokenFactory.CreateAccelerationXToken();
                case FormulaEditorKey.AccelerationY: return FormulaTokenFactory.CreateAccelerationYToken();
                case FormulaEditorKey.AccelerationZ: return FormulaTokenFactory.CreateAccelerationZToken();
                case FormulaEditorKey.Compass: return FormulaTokenFactory.CreateCompassToken();
                case FormulaEditorKey.InclinationX: return FormulaTokenFactory.CreateInclinationXToken();
                case FormulaEditorKey.InclinationY: return FormulaTokenFactory.CreateInclinationYToken();
                case FormulaEditorKey.Loudness: return FormulaTokenFactory.CreateLoudnessToken();

                // Properties
                case FormulaEditorKey.Brightness: return FormulaTokenFactory.CreateBrightnessToken();
                case FormulaEditorKey.Layer: return FormulaTokenFactory.CreateLayerToken();
                case FormulaEditorKey.Transparency: return FormulaTokenFactory.CreateTransparencyToken();
                case FormulaEditorKey.PositionX: return FormulaTokenFactory.CreatePositionXToken();
                case FormulaEditorKey.PositionY: return FormulaTokenFactory.CreatePositionYToken();
                case FormulaEditorKey.Rotation: return FormulaTokenFactory.CreateRotationToken();
                case FormulaEditorKey.Size: return FormulaTokenFactory.CreateSizeToken();

                // Variables
                case FormulaEditorKey.LocalVariable: return FormulaTokenFactory.CreateLocalVariableToken(localVariable);
                case FormulaEditorKey.GlobalVariable: return FormulaTokenFactory.CreateGlobalVariableToken(globalVariable);

                // brackets
                case FormulaEditorKey.OpeningParenthesis: return FormulaTokenFactory.CreateParenthesisToken(true);
                case FormulaEditorKey.ClosingParenthesis: return FormulaTokenFactory.CreateParenthesisToken(false);

                default: throw new ArgumentOutOfRangeException("key");
            }
        }
Ejemplo n.º 6
0
        public bool HandleKey(FormulaEditorKey key, LocalVariable localVariable = null, GlobalVariable globalVariable = null)
        {
            if (key == FormulaEditorKey.Delete)
            {
                PushUndo();
                return Delete();
            }

            PushUndo();
            var token = CreateToken(key, localVariable, globalVariable);
            return Insert((token is IFormulaFunction)
                ? new[] { token, FormulaTokenFactory.CreateParenthesisToken(true) }
                : new[] { token });
        }