Exemplo n.º 1
0
        private double GetAngleUnitTypeMaxValue(AngleUnitType?angleUnitTypeNullable = null)
        {
            AngleUnitType angleUnitType = angleUnitTypeNullable ?? _angleUnitType;

            switch (angleUnitType)
            {
            case AngleUnitType.InGameUnits:
                return(65536);

            case AngleUnitType.HAU:
                return(4096);

            case AngleUnitType.Degrees:
                return(360);

            case AngleUnitType.Radians:
                return(2 * Math.PI);

            case AngleUnitType.Revolutions:
                return(1);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        public WatchVariableAngleWrapper(
            WatchVariable watchVar,
            WatchVariableControl watchVarControl,
            Type displayType,
            bool?isYaw)
            : base(watchVar, watchVarControl, displayType, 0)
        {
            _baseType             = WatchVar.MemoryType ?? displayType;
            _defaultEffectiveType = displayType ?? WatchVar.MemoryType;
            if (_baseType == null || _defaultEffectiveType == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            _defaultSigned = TypeUtilities.TypeSign[_defaultEffectiveType];
            _signed        = _defaultSigned;

            _defaultAngleUnitType = AngleUnitType.InGameUnits;
            _angleUnitType        = _defaultAngleUnitType;

            _defaultTruncateToMultipleOf16 = false;
            _truncateToMultipleOf16        = _defaultTruncateToMultipleOf16;

            _defaultConstrainToOneRevolution =
                displayType != null && TypeUtilities.TypeSize[displayType] == 2 &&
                watchVar.MemoryType != null && TypeUtilities.TypeSize[watchVar.MemoryType] == 4;
            _constrainToOneRevolution = _defaultConstrainToOneRevolution;

            _defaultReverse = false;
            _reverse        = _defaultReverse;

            _isYaw = isYaw ?? DEFAULT_IS_YAW;

            AddAngleContextMenuStripItems();
        }
Exemplo n.º 3
0
        private double GetAngleUnitTypeAndMaybeSignedMinValue(AngleUnitType?angleUnitTypeNullable = null, bool?signedNullable = null)
        {
            AngleUnitType angleUnitType = angleUnitTypeNullable ?? _angleUnitType;
            bool          signed        = signedNullable ?? _signed;
            double        maxValue      = GetAngleUnitTypeMaxValue(angleUnitType);

            return(signed ? -1 * maxValue / 2 : 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an Angle with the given value and unit type
        /// </summary>
        /// <param name="value"></param>
        public Angle(float value, AngleUnitType unitType = AngleUnitType.Degrees) : this()
        {
            if (unitType == AngleUnitType.Radians)
            {
                value = (float)RadianToDegree(value);
            }

            this.Value = value;
        }
        private void AddAngleContextMenuStripItems()
        {
            ToolStripMenuItem itemSigned = new ToolStripMenuItem("Signed");

            _setSigned = (bool signed) =>
            {
                _signed            = signed;
                itemSigned.Checked = signed;
            };
            itemSigned.Click  += (sender, e) => _setSigned(!_signed);
            itemSigned.Checked = _signed;

            ToolStripMenuItem itemUnits = new ToolStripMenuItem("Units...");

            _setAngleUnitType = ControlUtilities.AddCheckableDropDownItems(
                itemUnits,
                new List <string> {
                "In-Game Units", "HAU", "Degrees", "Radians", "Revolutions"
            },
                new List <AngleUnitType>
            {
                AngleUnitType.InGameUnits,
                AngleUnitType.HAU,
                AngleUnitType.Degrees,
                AngleUnitType.Radians,
                AngleUnitType.Revolutions,
            },
                (AngleUnitType angleUnitType) => { _angleUnitType = angleUnitType; },
                _angleUnitType);

            ToolStripMenuItem itemTruncateToMultipleOf16 = new ToolStripMenuItem("Truncate to Multiple of 16");

            _setTruncateToMultipleOf16 = (bool truncateToMultipleOf16) =>
            {
                _truncateToMultipleOf16            = truncateToMultipleOf16;
                itemTruncateToMultipleOf16.Checked = truncateToMultipleOf16;
            };
            itemTruncateToMultipleOf16.Click  += (sender, e) => _setTruncateToMultipleOf16(!_truncateToMultipleOf16);
            itemTruncateToMultipleOf16.Checked = _truncateToMultipleOf16;

            ToolStripMenuItem itemConstrainToOneRevolution = new ToolStripMenuItem("Constrain to One Revolution");

            _setConstrainToOneRevolution = (bool constrainToOneRevolution) =>
            {
                _constrainToOneRevolution            = constrainToOneRevolution;
                itemConstrainToOneRevolution.Checked = constrainToOneRevolution;
            };
            itemConstrainToOneRevolution.Click  += (sender, e) => _setConstrainToOneRevolution(!_constrainToOneRevolution);
            itemConstrainToOneRevolution.Checked = _constrainToOneRevolution;

            _contextMenuStrip.AddToBeginningList(new ToolStripSeparator());
            _contextMenuStrip.AddToBeginningList(itemSigned);
            _contextMenuStrip.AddToBeginningList(itemUnits);
            _contextMenuStrip.AddToBeginningList(itemTruncateToMultipleOf16);
            _contextMenuStrip.AddToBeginningList(itemConstrainToOneRevolution);
        }
Exemplo n.º 6
0
        public WatchVariableAngleWrapper(
            WatchVariable watchVar,
            WatchVariableControl watchVarControl)
            : base(watchVar, watchVarControl, 0)
        {
            _signed                   = _watchVar.SignedType.Value;
            _angleUnitType            = AngleUnitType.InGameUnits;
            _truncateToMultipleOf16   = false;
            _constrainToOneRevolution = false;

            AddAngleContextMenuStripItems();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the value of the angle in the desired unit type
 /// </summary>
 /// <param name="type">The type of unit value to return</param>
 /// <returns></returns>
 public float GetValueInUnitType(AngleUnitType type)
 {
     if (type == AngleUnitType.Degrees)
     {
         return(this.Value);
     }
     else             /* if (type == AngleUnitType.Radians) */
     {
         float result = (float)DegreeToRadian(Value);
         return(result);
     }
 }
Exemplo n.º 8
0
        public double Calculate(Queue <string> queue, AngleUnitType angleUnitType)
        {
            Stack stack = new Stack();

            while (queue.Any())
            {
                string item = queue.Dequeue();

                if (string.IsNullOrWhiteSpace(item))
                {
                    throw new NotAllowedElementInQueueException($"The following element does not allowed in the queue! Element value: {item}");
                }

                if (item.IsDecimalNumber())
                {
                    stack.Push(item);
                }
                else if (Functions.IsTrigonometricFunction(item))
                {
                    TrigonometricFunctionType trigonometricFunctionType = Functions.GetTrigonometricFunctionTypeByText(item);

                    CalculateWithTrigonometricFunction(stack, trigonometricFunctionType, angleUnitType);
                }
                else if (Functions.IsFunction(item))
                {
                    FunctionType functionType = Functions.GetFunctionTypeByText(item);

                    CalculateWithFunction(stack, functionType);
                }
                else if (Operators.IsOperator(item))
                {
                    OperatorType operatorType = Operators.GetOperatorTypeByText(item);

                    CalculateWithOperator(stack, operatorType);
                }
                else
                {
                    throw new UnknownElementInQueueException($"The following element does not allowed in the queue! Element value: {item}");
                }
            }

            if (stack.Count != 1)
            {
                throw new SyntaxErrorException("The stack contains more items than it should!");
            }

            return(double.Parse(Convert.ToString(stack.Pop())));
        }
Exemplo n.º 9
0
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name", "The dimension style name should be at least one character long.");
            }

            this.IsReserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension and extension lines
            this.dimclrd  = AciColor.ByBlock;
            this.dimltype = Linetype.ByBlock;
            this.dimlwd   = Lineweight.ByBlock;
            this.dimdle   = 0.0;
            this.dimdli   = 0.38;
            this.dimsd1   = false;
            this.dimsd2   = false;

            this.dimclre  = AciColor.ByBlock;
            this.dimltex1 = Linetype.ByBlock;
            this.dimltex2 = Linetype.ByBlock;
            this.dimlwe   = Lineweight.ByBlock;
            this.dimse1   = false;
            this.dimse2   = false;
            this.dimexo   = 0.0625;
            this.dimexe   = 0.18;
            this.dimfxlon = false;
            this.dimfxl   = 1.0;

            // symbols and arrows
            this.dimldrblk = null;
            this.dimblk1   = null;
            this.dimblk2   = null;
            this.dimasz    = 0.18;
            this.dimcen    = 0.09;

            // text
            this.dimtxsty        = TextStyle.Default;
            this.dimclrt         = AciColor.ByBlock;
            this.dimtfillclr     = null;
            this.dimtxt          = 0.18;
            this.dimtad          = DimensionStyleTextVerticalPlacement.Centered;
            this.dimjust         = DimensionStyleTextHorizontalPlacement.Centered;
            this.dimgap          = 0.09;
            this.dimtih          = false;
            this.dimtoh          = false;
            this.dimtxtdirection = DimensionStyleTextDirection.LeftToRight;
            this.dimtfac         = 1.0;

            // fit
            this.dimtofl  = false;
            this.dimsoxd  = true;
            this.dimscale = 1.0;
            this.dimatfit = DimensionStyleFitOptions.BestFit;
            this.dimtix   = false;
            this.dimtmove = DimensionStyleFitTextMove.BesideDimLine;

            // primary units
            this.dimdec    = 4;
            this.dimadec   = 0;
            this.dimPrefix = string.Empty;
            this.dimSuffix = string.Empty;
            this.dimdsep   = '.';
            this.dimlfac   = 1.0;
            this.dimaunit  = AngleUnitType.DecimalDegrees;
            this.dimlunit  = LinearUnitType.Decimal;
            this.dimfrac   = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros   = false;
            this.suppressLinearTrailingZeros  = false;
            this.suppressZeroFeet             = true;
            this.suppressZeroInches           = true;
            this.suppressAngularLeadingZeros  = false;
            this.suppressAngularTrailingZeros = false;
            this.dimrnd = 0.0;

            // alternate units
            this.alternateUnits = new DimensionStyleAlternateUnits();

            // tolerances
            this.tolerances = new DimensionStyleTolerances();
        }
Exemplo n.º 10
0
        public static List<ToolStripItem> CreateSelectionToolStripItems(
            Func<List<WatchVariableControl>> getVars,
            WatchVariableFlowLayoutPanel panel)
        {
            Action<WatchVariableControlSettings> apply = (WatchVariableControlSettings settings) =>
            {
                if (KeyboardUtilities.IsCtrlHeld())
                    WatchVariableControlSettingsManager.AddSettings(settings);
                else
                    getVars().ForEach(control => control.ApplySettings(settings));
            };

            ToolStripMenuItem itemHighlight = new ToolStripMenuItem("Highlight...");
            ControlUtilities.AddDropDownItems(
                itemHighlight,
                new List<string>() { "Highlight", "Don't Highlight" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeHighlighted: true, newHighlighted: true)),
                    () => apply(new WatchVariableControlSettings(changeHighlighted: true, newHighlighted: false)),
                });

            ToolStripMenuItem itemLock = new ToolStripMenuItem("Lock...");
            ControlUtilities.AddDropDownItems(
                itemLock,
                new List<string>() { "Lock", "Don't Lock" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeLocked: true, newLocked: true)),
                    () => apply(new WatchVariableControlSettings(changeLocked: true, newLocked: false)),
                });

            ToolStripMenuItem itemCopy = new ToolStripMenuItem("Copy...");
            Action<List<WatchVariableControl>, string> copyValues =
                (List<WatchVariableControl> controls, string separator) =>
            {
                Clipboard.SetText(
                    String.Join(separator, controls.ConvertAll(
                        control => control.GetValue(false))));
            };
            ControlUtilities.AddDropDownItems(
                itemCopy,
                new List<string>() {
                    "Copy with Commas",
                    "Copy with Tabs",
                    "Copy with Line Breaks",
                    "Copy for Code",
                },
                new List<Action>()
                {
                    () => copyValues(getVars(), ","),
                    () => copyValues(getVars(), "\t"),
                    () => copyValues(getVars(), "\r\n"),
                    () =>
                    {
                        List<WatchVariableControl> watchVars = getVars();
                        string prefix = KeyboardUtilities.IsCtrlHeld() ? DialogUtilities.GetStringFromDialog() : "";
                        List<string> lines = new List<string>();
                        foreach (WatchVariableControl watchVar in watchVars)
                        {
                            Type type = watchVar.GetMemoryType();
                            string line = String.Format(
                                "{0} {1}{2} = {3}{4};",
                                type != null ? TypeUtilities.TypeToString[watchVar.GetMemoryType()] : "double",
                                prefix,
                                watchVar.VarName.Replace(" ", ""),
                                watchVar.GetValue(false),
                                type == typeof(float) ? "f" : "");
                            lines.Add(line);
                        }
                        if (lines.Count > 0)
                        {
                            Clipboard.SetText(String.Join("\r\n", lines));
                        }
                    },
                });

            ToolStripMenuItem itemPaste = new ToolStripMenuItem("Paste");
            itemPaste.Click += (sender, e) =>
            {
                List<string> stringList = ParsingUtilities.ParseStringList(Clipboard.GetText());
                List<WatchVariableControl> varList = getVars();
                if (stringList.Count != varList.Count) return;

                Config.Stream.Suspend();
                for (int i = 0; i < stringList.Count; i++)
                {
                    varList[i].SetValue(stringList[i]);
                }
                Config.Stream.Resume();
            };

            ToolStripMenuItem itemRoundTo = new ToolStripMenuItem("Round to...");
            ToolStripMenuItem itemRoundToDefault = new ToolStripMenuItem("Default");
            itemRoundToDefault.Click += (sender, e) =>
                apply(new WatchVariableControlSettings(
                    changeRoundingLimit: true, changeRoundingLimitToDefault: true));
            ToolStripMenuItem itemRoundToNoRounding = new ToolStripMenuItem("No Rounding");
            itemRoundToNoRounding.Click += (sender, e) =>
                apply(new WatchVariableControlSettings(
                    changeRoundingLimit: true, newRoundingLimit: -1));
            List<ToolStripMenuItem> itemsRoundToNumDecimalPlaces = new List<ToolStripMenuItem>();
            for (int i = 0; i <= 10; i++)
            {
                int index = i;
                itemsRoundToNumDecimalPlaces.Add(new ToolStripMenuItem(index + " decimal place(s)"));
                itemsRoundToNumDecimalPlaces[index].Click += (sender, e) =>
                    apply(new WatchVariableControlSettings(
                        changeRoundingLimit: true, newRoundingLimit: index));
            }
            itemRoundTo.DropDownItems.Add(itemRoundToDefault);
            itemRoundTo.DropDownItems.Add(itemRoundToNoRounding);
            itemsRoundToNumDecimalPlaces.ForEach(setAllRoundingLimitsNumberItem =>
            {
                itemRoundTo.DropDownItems.Add(setAllRoundingLimitsNumberItem);
            });

            ToolStripMenuItem itemDisplayAsHex = new ToolStripMenuItem("Display as Hex...");
            ControlUtilities.AddDropDownItems(
                itemDisplayAsHex,
                new List<string>() { "Default", "Hex", "Decimal" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, changeDisplayAsHexToDefault: true)),
                    () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, newDisplayAsHex: true)),
                    () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, newDisplayAsHex: false)),
                });

            ToolStripMenuItem itemAngleSigned = new ToolStripMenuItem("Angle: Signed...");
            ControlUtilities.AddDropDownItems(
                itemAngleSigned,
                new List<string>() { "Default", "Unsigned", "Signed" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeAngleSigned: true, changeAngleSignedToDefault: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleSigned: true, newAngleSigned: false)),
                    () => apply(new WatchVariableControlSettings(changeAngleSigned: true, newAngleSigned: true)),
                });

            ToolStripMenuItem itemAngleUnits = new ToolStripMenuItem("Angle: Units...");
            ToolStripMenuItem itemAngleUnitsDefault = new ToolStripMenuItem("Default");
            itemAngleUnitsDefault.Click += (sender, e) =>
                apply(new WatchVariableControlSettings(
                    changeAngleUnits: true, changeAngleUnitsToDefault: true));
            List<ToolStripMenuItem> itemsAngleUnitsValue = new List<ToolStripMenuItem>();
            foreach (AngleUnitType angleUnitType in Enum.GetValues(typeof(AngleUnitType)))
            {
                AngleUnitType angleUnitTypeFixed = angleUnitType;
                ToolStripMenuItem itemAngleUnitsValue = new ToolStripMenuItem(angleUnitTypeFixed.ToString());
                itemAngleUnitsValue.Click += (sender, e) =>
                    apply(new WatchVariableControlSettings(
                        changeAngleUnits: true, newAngleUnits: angleUnitTypeFixed));
                itemsAngleUnitsValue.Add(itemAngleUnitsValue);
            }
            itemAngleUnits.DropDownItems.Add(itemAngleUnitsDefault);
            itemsAngleUnitsValue.ForEach(setAllAngleUnitsValuesItem =>
            {
                itemAngleUnits.DropDownItems.Add(setAllAngleUnitsValuesItem);
            });

            ToolStripMenuItem itemAngleTruncateToMultipleOf16 = new ToolStripMenuItem("Angle: Truncate to Multiple of 16...");
            ControlUtilities.AddDropDownItems(
                itemAngleTruncateToMultipleOf16,
                new List<string>() { "Default", "Truncate to Multiple of 16", "Don't Truncate to Multiple of 16" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, changeAngleTruncateToMultipleOf16ToDefault: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, newAngleTruncateToMultipleOf16: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, newAngleTruncateToMultipleOf16: false)),
                });

            ToolStripMenuItem itemAngleConstrainToOneRevolution = new ToolStripMenuItem("Angle: Constrain to One Revolution...");
            ControlUtilities.AddDropDownItems(
                itemAngleConstrainToOneRevolution,
                new List<string>() { "Default", "Constrain to One Revolution", "Don't Constrain to One Revolution" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, changeAngleConstrainToOneRevolutionToDefault: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, newAngleConstrainToOneRevolution: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, newAngleConstrainToOneRevolution: false)),
                });

            ToolStripMenuItem itemAngleDisplayAsHex = new ToolStripMenuItem("Angle: Display as Hex...");
            ControlUtilities.AddDropDownItems(
                itemAngleDisplayAsHex,
                new List<string>() { "Default", "Hex", "Decimal" },
                new List<Action>()
                {
                    () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, changeAngleDisplayAsHexToDefault: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, newAngleDisplayAsHex: true)),
                    () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, newAngleDisplayAsHex: false)),
                });

            ToolStripMenuItem itemShowVariableXml = new ToolStripMenuItem("Show Variable XML");
            itemShowVariableXml.Click += (sender, e) =>
            {
                InfoForm infoForm = new InfoForm();
                infoForm.SetText(
                    "Variable Info",
                    "Variable XML",
                    String.Join("\r\n", getVars().ConvertAll(control => control.ToXml(true))));
                infoForm.Show();
            };

            ToolStripMenuItem itemShowVariableInfo = new ToolStripMenuItem("Show Variable Info");
            itemShowVariableInfo.Click += (sender, e) =>
            {
                InfoForm infoForm = new InfoForm();
                infoForm.SetText(
                    "Variable Info",
                    "Variable Info",
                    String.Join("\t",
                        WatchVariableWrapper.GetVarInfoLabels()) +
                        "\r\n" +
                        String.Join(
                            "\r\n",
                            getVars().ConvertAll(control => control.GetVarInfo())
                                .ConvertAll(infoList => String.Join("\t", infoList))));
                infoForm.Show();
            };

            ToolStripMenuItem itemMove = new ToolStripMenuItem("Move...");
            ControlUtilities.AddDropDownItems(
                itemMove,
                new List<string>() { "Start Move", "End Move", "Clear Move" },
                new List<Action>()
                {
                    () => panel.NotifyOfReorderingStart(getVars()),
                    () => panel.NotifyOfReorderingEnd(getVars()),
                    () => panel.NotifyOfReorderingClear(),
                });

            ToolStripMenuItem itemRemove = new ToolStripMenuItem("Remove");
            itemRemove.Click += (sender, e) => panel.RemoveVariables(getVars());

            ToolStripMenuItem itemEnableCustomization = new ToolStripMenuItem("Enable Customization");
            itemEnableCustomization.Click += (sender, e) => apply(new WatchVariableControlSettings(enableCustomization: true));

            ToolStripMenuItem itemOpenController = new ToolStripMenuItem("Open Controller");
            itemOpenController.Click += (sender, e) =>
            {
                List<WatchVariableControl> vars = getVars();
                VariableControllerForm varController =
                    new VariableControllerForm(
                        vars.ConvertAll(control => control.VarName),
                        vars.ConvertAll(control => control.WatchVarWrapper),
                        vars.ConvertAll(control => control.FixedAddressList));
                varController.Show();
            };

            ToolStripMenuItem itemOpenPopOut = new ToolStripMenuItem("Open Pop Out");
            itemOpenPopOut.Click += (sender, e) =>
            {
                VariablePopOutForm form = new VariablePopOutForm();
                form.Initialize(getVars().ConvertAll(control => control.CreateCopy()));
                form.ShowForm();
            };

            ToolStripMenuItem itemAddToTab = new ToolStripMenuItem("Add to Tab...");
            itemAddToTab.Click += (sender, e) => SelectionForm.ShowDataManagerSelectionForm(getVars());

            ToolStripMenuItem itemAddToCustomTab = new ToolStripMenuItem("Add to Custom Tab");
            itemAddToCustomTab.Click += (sender, e) => WatchVariableControl.AddVarsToTab(getVars(), Config.CustomManager);

            return new List<ToolStripItem>
            {
                itemHighlight,
                itemLock,
                itemCopy,
                itemPaste,
                new ToolStripSeparator(),
                itemRoundTo,
                itemDisplayAsHex,
                new ToolStripSeparator(),
                itemAngleSigned,
                itemAngleUnits,
                itemAngleTruncateToMultipleOf16,
                itemAngleConstrainToOneRevolution,
                itemAngleDisplayAsHex,
                new ToolStripSeparator(),
                itemShowVariableXml,
                itemShowVariableInfo,
                new ToolStripSeparator(),
                itemMove,
                itemRemove,
                itemEnableCustomization,
                itemOpenController,
                itemOpenPopOut,
                itemAddToTab,
                itemAddToCustomTab,
            };
        }
Exemplo n.º 11
0
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "The dimension style name should be at least one character long.");
            }

            this.IsReserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension lines
            this.dimclrd  = AciColor.ByBlock;
            this.dimltype = Linetype.ByBlock;
            this.dimlwd   = Lineweight.ByBlock;
            this.dimsd    = false;
            this.dimdli   = 0.38;
            this.dimdle   = 0.0;

            // extension lines
            this.dimclre  = AciColor.ByBlock;
            this.dimltex1 = Linetype.ByBlock;
            this.dimltex2 = Linetype.ByBlock;
            this.dimlwe   = Lineweight.ByBlock;
            this.dimse1   = false;
            this.dimse2   = false;
            this.dimexo   = 0.0625;
            this.dimexe   = 0.18;

            // symbols and arrows
            this.dimasz    = 0.18;
            this.dimcen    = 0.09;
            this.dimldrblk = null;
            this.dimblk1   = null;
            this.dimblk2   = null;

            // text
            this.dimtxsty = TextStyle.Default;
            this.dimclrt  = AciColor.ByBlock;
            this.dimtxt   = 0.18;
            this.dimtad   = 1;
            this.dimjust  = 0;
            this.dimgap   = 0.09;

            // fit
            this.dimscale = 1.0;

            // primary units
            this.dimdec    = 2;
            this.dimadec   = 0;
            this.dimPrefix = string.Empty;
            this.dimSuffix = string.Empty;
            this.dimtih    = 0;
            this.dimtoh    = 0;
            this.dimdsep   = '.';
            this.dimlfac   = 1.0;
            this.dimaunit  = AngleUnitType.DecimalDegrees;
            this.dimlunit  = LinearUnitType.Decimal;
            this.dimfrac   = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros   = false;
            this.suppressLinearTrailingZeros  = false;
            this.suppressAngularLeadingZeros  = false;
            this.suppressAngularTrailingZeros = false;
            this.suppressZeroFeet             = true;
            this.suppressZeroInches           = true;
            this.dimrnd = 0.0;
        }
Exemplo n.º 12
0
        private static void CalculateWithTrigonometricFunction(Stack stack, TrigonometricFunctionType trigonometricFunctionType, AngleUnitType angleUnitType)
        {
            double operand;

            switch (trigonometricFunctionType)
            {
            case TrigonometricFunctionType.Sin:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Sin(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Sin(operand * (Math.PI / 180)));
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            case TrigonometricFunctionType.ArcSin:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Asin(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Asin(operand) * 180 / Math.PI);
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            case TrigonometricFunctionType.Cos:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Cos(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Cos(operand * (Math.PI / 180)));
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            case TrigonometricFunctionType.ArcCos:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Acos(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Acos(operand) * 180 / Math.PI);
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            case TrigonometricFunctionType.Tan:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Tan(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Tan(operand * (Math.PI / 180)));
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            case TrigonometricFunctionType.ArcTan:
                operand = double.Parse(Convert.ToString(stack.Pop()));

                switch (angleUnitType)
                {
                case AngleUnitType.Radian:
                    stack.Push(Math.Atan(operand) * 1);
                    break;

                case AngleUnitType.Degree:
                    stack.Push(Math.Atan(operand) * 180 / Math.PI);
                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(angleUnitType), (int)angleUnitType, typeof(AngleUnitType));
                }

                break;

            default:
                throw new InvalidEnumArgumentException(nameof(trigonometricFunctionType), (int)trigonometricFunctionType, typeof(TrigonometricFunctionType));
            }
        }
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException(nameof(name), "The dimension style name should be at least one character long.");

            this.reserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension lines
            this.dimclrd = AciColor.ByBlock;
            this.dimltype = LineType.ByBlock;
            this.dimlwd = Lineweight.ByBlock;
            this.dimdli = 0.38;
            this.dimdle = 0.0;

            // extension lines
            this.dimclre = AciColor.ByBlock;
            this.dimltex1 = LineType.ByBlock;
            this.dimltex2 = LineType.ByBlock;
            this.dimlwe = Lineweight.ByBlock;
            this.dimse1 = false;
            this.dimse2 = false;
            this.dimexo = 0.0625;
            this.dimexe = 0.18;

            // symbols and arrows
            this.dimasz = 0.18;
            this.dimcen = 0.09;
            this.dimsah = false;
            this.dimldrblk = null;
            this.dimblk = null;
            this.dimblk1 = null;
            this.dimblk2 = null;

            // text
            this.dimtxsty = TextStyle.Default;
            this.dimclrt = AciColor.ByBlock;
            this.dimtxt = 0.18;
            this.dimtad = 1;
            this.dimjust = 0;
            this.dimgap = 0.09;

            // fit
            this.dimscale = 1.0;

            // primary units
            this.dimdec = 2;
            this.dimadec = 0;
            this.dimpost = "<>";
            this.dimtih = 0;
            this.dimtoh = 0;
            this.dimdsep = '.';
            this.dimlfac = 1.0;
            this.dimaunit = AngleUnitType.DecimalDegrees;
            this.dimlunit = LinearUnitType.Decimal;
            this.dimfrac = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros = false;
            this.suppressLinearTrailingZeros = false;
            this.suppressAngularLeadingZeros = false;
            this.suppressAngularTrailingZeros = false;
            this.suppressZeroFeet = true;
            this.suppressZeroInches = true;
            this.dimrnd = 0.0;
        }
        public static List <ToolStripItem> CreateSelectionToolStripItems(
            Func <List <WatchVariableControl> > getVars,
            WatchVariableFlowLayoutPanel panel)
        {
            Action <WatchVariableControlSettings, List <WatchVariableControl> > apply2 =
                (WatchVariableControlSettings settings, List <WatchVariableControl> vars) =>
            {
                if (KeyboardUtilities.IsCtrlHeld())
                {
                    WatchVariableControlSettingsManager.AddSettings(settings);
                }
                else
                {
                    vars.ForEach(control => control.ApplySettings(settings));
                }
            };

            Action <WatchVariableControlSettings> apply = (WatchVariableControlSettings settings) => apply2(settings, getVars());

            ToolStripMenuItem itemHighlight = new ToolStripMenuItem("Highlight...");

            ControlUtilities.AddDropDownItems(
                itemHighlight,
                new List <string>()
            {
                "Highlight", "Don't Highlight"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeHighlighted: true, newHighlighted: true)),
                () => apply(new WatchVariableControlSettings(changeHighlighted: true, newHighlighted: false)),
            });
            ToolStripMenuItem itemHighlightColor = new ToolStripMenuItem("Color...");

            ControlUtilities.AddDropDownItems(
                itemHighlightColor,
                new List <string>()
            {
                "Red",
                "Orange",
                "Yellow",
                "Green",
                "Blue",
                "Purple",
                "Pink",
                "Brown",
                "Black",
                "White",
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Red)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Orange)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Yellow)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Green)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Blue)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Purple)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Pink)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Brown)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.Black)),
                () => apply(new WatchVariableControlSettings(changeHighlightColor: true, newHighlightColor: Color.White)),
            });
            itemHighlight.DropDownItems.Add(itemHighlightColor);

            ToolStripMenuItem itemLock = new ToolStripMenuItem("Lock...");

            ControlUtilities.AddDropDownItems(
                itemLock,
                new List <string>()
            {
                "Lock", "Don't Lock"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeLocked: true, newLocked: true)),
                () => apply(new WatchVariableControlSettings(changeLocked: true, newLocked: false)),
            });

            ToolStripMenuItem itemFixAddress = new ToolStripMenuItem("Fix Address...");

            ControlUtilities.AddDropDownItems(
                itemFixAddress,
                new List <string>()
            {
                "Default", "Fix Address", "Don't Fix Address"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeFixedAddress: true, changeFixedAddressToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeFixedAddress: true, newFixedAddress: true)),
                () => apply(new WatchVariableControlSettings(changeFixedAddress: true, newFixedAddress: false)),
            });

            ToolStripMenuItem itemCopy = new ToolStripMenuItem("Copy...");

            CopyUtilities.AddDropDownItems(itemCopy, getVars);

            ToolStripMenuItem itemPaste = new ToolStripMenuItem("Paste");

            itemPaste.Click += (sender, e) =>
            {
                List <WatchVariableControl> varList = getVars();
                List <string> stringList            = ParsingUtilities.ParseStringList(Clipboard.GetText());
                if (stringList.Count == 0)
                {
                    return;
                }

                Config.Stream.Suspend();
                for (int i = 0; i < varList.Count; i++)
                {
                    varList[i].SetValue(stringList[i % stringList.Count]);
                }
                Config.Stream.Resume();
            };

            ToolStripMenuItem itemRoundTo        = new ToolStripMenuItem("Round to...");
            ToolStripMenuItem itemRoundToDefault = new ToolStripMenuItem("Default");

            itemRoundToDefault.Click += (sender, e) =>
                                        apply(new WatchVariableControlSettings(
                                                  changeRoundingLimit: true, changeRoundingLimitToDefault: true));
            ToolStripMenuItem itemRoundToNoRounding = new ToolStripMenuItem("No Rounding");

            itemRoundToNoRounding.Click += (sender, e) =>
                                           apply(new WatchVariableControlSettings(
                                                     changeRoundingLimit: true, newRoundingLimit: -1));
            List <ToolStripMenuItem> itemsRoundToNumDecimalPlaces = new List <ToolStripMenuItem>();

            for (int i = 0; i <= 10; i++)
            {
                int index = i;
                itemsRoundToNumDecimalPlaces.Add(new ToolStripMenuItem(index + " decimal place(s)"));
                itemsRoundToNumDecimalPlaces[index].Click += (sender, e) =>
                                                             apply(new WatchVariableControlSettings(
                                                                       changeRoundingLimit: true, newRoundingLimit: index));
            }
            itemRoundTo.DropDownItems.Add(itemRoundToDefault);
            itemRoundTo.DropDownItems.Add(itemRoundToNoRounding);
            itemsRoundToNumDecimalPlaces.ForEach(setAllRoundingLimitsNumberItem =>
            {
                itemRoundTo.DropDownItems.Add(setAllRoundingLimitsNumberItem);
            });

            ToolStripMenuItem itemDisplayAsHex = new ToolStripMenuItem("Display as Hex...");

            ControlUtilities.AddDropDownItems(
                itemDisplayAsHex,
                new List <string>()
            {
                "Default", "Hex", "Decimal"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, changeDisplayAsHexToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, newDisplayAsHex: true)),
                () => apply(new WatchVariableControlSettings(changeDisplayAsHex: true, newDisplayAsHex: false)),
            });

            ToolStripMenuItem itemAngleSigned = new ToolStripMenuItem("Angle: Signed...");

            ControlUtilities.AddDropDownItems(
                itemAngleSigned,
                new List <string>()
            {
                "Default", "Unsigned", "Signed"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeAngleSigned: true, changeAngleSignedToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeAngleSigned: true, newAngleSigned: false)),
                () => apply(new WatchVariableControlSettings(changeAngleSigned: true, newAngleSigned: true)),
            });

            ToolStripMenuItem itemAngleUnits        = new ToolStripMenuItem("Angle: Units...");
            ToolStripMenuItem itemAngleUnitsDefault = new ToolStripMenuItem("Default");

            itemAngleUnitsDefault.Click += (sender, e) =>
                                           apply(new WatchVariableControlSettings(
                                                     changeAngleUnits: true, changeAngleUnitsToDefault: true));
            List <ToolStripMenuItem> itemsAngleUnitsValue = new List <ToolStripMenuItem>();

            foreach (AngleUnitType angleUnitType in Enum.GetValues(typeof(AngleUnitType)))
            {
                AngleUnitType angleUnitTypeFixed = angleUnitType;
                string        stringValue        = angleUnitTypeFixed.ToString();
                if (stringValue == AngleUnitType.InGameUnits.ToString())
                {
                    stringValue = "In-Game Units";
                }
                ToolStripMenuItem itemAngleUnitsValue = new ToolStripMenuItem(stringValue);
                itemAngleUnitsValue.Click += (sender, e) =>
                                             apply(new WatchVariableControlSettings(
                                                       changeAngleUnits: true, newAngleUnits: angleUnitTypeFixed));
                itemsAngleUnitsValue.Add(itemAngleUnitsValue);
            }
            itemAngleUnits.DropDownItems.Add(itemAngleUnitsDefault);
            itemsAngleUnitsValue.ForEach(setAllAngleUnitsValuesItem =>
            {
                itemAngleUnits.DropDownItems.Add(setAllAngleUnitsValuesItem);
            });

            ToolStripMenuItem itemAngleTruncateToMultipleOf16 = new ToolStripMenuItem("Angle: Truncate to Multiple of 16...");

            ControlUtilities.AddDropDownItems(
                itemAngleTruncateToMultipleOf16,
                new List <string>()
            {
                "Default", "Truncate to Multiple of 16", "Don't Truncate to Multiple of 16"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, changeAngleTruncateToMultipleOf16ToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, newAngleTruncateToMultipleOf16: true)),
                () => apply(new WatchVariableControlSettings(changeAngleTruncateToMultipleOf16: true, newAngleTruncateToMultipleOf16: false)),
            });

            ToolStripMenuItem itemAngleConstrainToOneRevolution = new ToolStripMenuItem("Angle: Constrain to One Revolution...");

            ControlUtilities.AddDropDownItems(
                itemAngleConstrainToOneRevolution,
                new List <string>()
            {
                "Default", "Constrain to One Revolution", "Don't Constrain to One Revolution"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, changeAngleConstrainToOneRevolutionToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, newAngleConstrainToOneRevolution: true)),
                () => apply(new WatchVariableControlSettings(changeAngleConstrainToOneRevolution: true, newAngleConstrainToOneRevolution: false)),
            });

            ToolStripMenuItem itemAngleReverse = new ToolStripMenuItem("Angle: Reverse...");

            ControlUtilities.AddDropDownItems(
                itemAngleReverse,
                new List <string>()
            {
                "Default", "Reverse", "Don't Reverse"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeAngleReverse: true, changeAngleReverseToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeAngleReverse: true, newAngleReverse: true)),
                () => apply(new WatchVariableControlSettings(changeAngleReverse: true, newAngleReverse: false)),
            });

            ToolStripMenuItem itemAngleDisplayAsHex = new ToolStripMenuItem("Angle: Display as Hex...");

            ControlUtilities.AddDropDownItems(
                itemAngleDisplayAsHex,
                new List <string>()
            {
                "Default", "Hex", "Decimal"
            },
                new List <Action>()
            {
                () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, changeAngleDisplayAsHexToDefault: true)),
                () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, newAngleDisplayAsHex: true)),
                () => apply(new WatchVariableControlSettings(changeAngleDisplayAsHex: true, newAngleDisplayAsHex: false)),
            });

            ToolStripMenuItem itemShowVariableXml = new ToolStripMenuItem("Show Variable XML");

            itemShowVariableXml.Click += (sender, e) =>
            {
                InfoForm infoForm = new InfoForm();
                infoForm.SetText(
                    "Variable Info",
                    "Variable XML",
                    String.Join("\r\n", getVars().ConvertAll(control => control.ToXml(true))));
                infoForm.Show();
            };

            ToolStripMenuItem itemShowVariableInfo = new ToolStripMenuItem("Show Variable Info");

            itemShowVariableInfo.Click += (sender, e) =>
            {
                InfoForm infoForm = new InfoForm();
                infoForm.SetText(
                    "Variable Info",
                    "Variable Info",
                    String.Join("\t",
                                WatchVariableWrapper.GetVarInfoLabels()) +
                    "\r\n" +
                    String.Join(
                        "\r\n",
                        getVars().ConvertAll(control => control.GetVarInfo())
                        .ConvertAll(infoList => String.Join("\t", infoList))));
                infoForm.Show();
            };

            void createBinaryMathOperationVariable(BinaryMathOperation operation)
            {
                List <WatchVariableControl> controls = getVars();

                if (controls.Count % 2 == 1)
                {
                    controls.RemoveAt(controls.Count - 1);
                }

                for (int i = 0; i < controls.Count / 2; i++)
                {
                    WatchVariableControl control1 = controls[i];
                    WatchVariableControl control2 = controls[i + controls.Count / 2];
                    string specialType            = WatchVariableSpecialUtilities.AddBinaryMathOperationEntry(control1, control2, operation);

                    WatchVariable watchVariable =
                        new WatchVariable(
                            memoryTypeName: null,
                            specialType: specialType,
                            baseAddressType: BaseAddressTypeEnum.None,
                            offsetUS: null,
                            offsetJP: null,
                            offsetSH: null,
                            offsetEU: null,
                            offsetDefault: null,
                            mask: null,
                            shift: null,
                            handleMapping: true);
                    WatchVariableControlPrecursor precursor =
                        new WatchVariableControlPrecursor(
                            name: string.Format("{0} {1} {2}", control1.VarName, MathOperationUtilities.GetSymbol(operation), control2.VarName),
                            watchVar: watchVariable,
                            subclass: WatchVariableSubclass.Number,
                            backgroundColor: null,
                            displayType: null,
                            roundingLimit: null,
                            useHex: null,
                            invertBool: null,
                            isYaw: null,
                            coordinate: null,
                            groupList: new List <VariableGroup>()
                    {
                        VariableGroup.Custom
                    });
                    WatchVariableControl control = precursor.CreateWatchVariableControl();
                    panel.AddVariable(control);
                }
            }

            void createAggregateMathOperationVariable(AggregateMathOperation operation)
            {
                List <WatchVariableControl> controls = getVars();

                if (controls.Count == 0)
                {
                    return;
                }
                string        specialType   = WatchVariableSpecialUtilities.AddAggregateMathOperationEntry(controls, operation);
                WatchVariable watchVariable =
                    new WatchVariable(
                        memoryTypeName: null,
                        specialType: specialType,
                        baseAddressType: BaseAddressTypeEnum.None,
                        offsetUS: null,
                        offsetJP: null,
                        offsetSH: null,
                        offsetEU: null,
                        offsetDefault: null,
                        mask: null,
                        shift: null,
                        handleMapping: true);
                WatchVariableControlPrecursor precursor =
                    new WatchVariableControlPrecursor(
                        name: operation.ToString(),
                        watchVar: watchVariable,
                        subclass: WatchVariableSubclass.Number,
                        backgroundColor: null,
                        displayType: null,
                        roundingLimit: null,
                        useHex: null,
                        invertBool: null,
                        isYaw: null,
                        coordinate: null,
                        groupList: new List <VariableGroup>()
                {
                    VariableGroup.Custom
                });
                WatchVariableControl control = precursor.CreateWatchVariableControl();

                panel.AddVariable(control);
            }

            void createDistanceMathOperationVariable(bool use3D)
            {
                List <WatchVariableControl> controls = getVars();
                bool satisfies2D = !use3D && controls.Count >= 4;
                bool satisfies3D = use3D && controls.Count >= 6;

                if (!satisfies2D && !satisfies3D)
                {
                    return;
                }
                string specialType = WatchVariableSpecialUtilities.AddDistanceMathOperationEntry(controls, use3D);
                string name        = use3D ?
                                     string.Format(
                    "({0},{1},{2}) to ({3},{4},{5})",
                    controls[0].VarName,
                    controls[1].VarName,
                    controls[2].VarName,
                    controls[3].VarName,
                    controls[4].VarName,
                    controls[5].VarName) :
                                     string.Format(
                    "({0},{1}) to ({2},{3})",
                    controls[0].VarName,
                    controls[1].VarName,
                    controls[2].VarName,
                    controls[3].VarName);
                WatchVariable watchVariable =
                    new WatchVariable(
                        memoryTypeName: null,
                        specialType: specialType,
                        baseAddressType: BaseAddressTypeEnum.None,
                        offsetUS: null,
                        offsetJP: null,
                        offsetSH: null,
                        offsetEU: null,
                        offsetDefault: null,
                        mask: null,
                        shift: null,
                        handleMapping: true);
                WatchVariableControlPrecursor precursor =
                    new WatchVariableControlPrecursor(
                        name: name,
                        watchVar: watchVariable,
                        subclass: WatchVariableSubclass.Number,
                        backgroundColor: null,
                        displayType: null,
                        roundingLimit: null,
                        useHex: null,
                        invertBool: null,
                        isYaw: null,
                        coordinate: null,
                        groupList: new List <VariableGroup>()
                {
                    VariableGroup.Custom
                });
                WatchVariableControl control = precursor.CreateWatchVariableControl();

                panel.AddVariable(control);
            }

            void createRealTimeVariable()
            {
                List <WatchVariableControl> controls = getVars();

                for (int i = 0; i < controls.Count; i++)
                {
                    WatchVariableControl control = controls[i];
                    string specialType           = WatchVariableSpecialUtilities.AddRealTimeEntry(control);

                    WatchVariable watchVariable =
                        new WatchVariable(
                            memoryTypeName: null,
                            specialType: specialType,
                            baseAddressType: BaseAddressTypeEnum.None,
                            offsetUS: null,
                            offsetJP: null,
                            offsetSH: null,
                            offsetEU: null,
                            offsetDefault: null,
                            mask: null,
                            shift: null,
                            handleMapping: true);
                    WatchVariableControlPrecursor precursor =
                        new WatchVariableControlPrecursor(
                            name: string.Format("{0} Real Time", control.VarName),
                            watchVar: watchVariable,
                            subclass: WatchVariableSubclass.String,
                            backgroundColor: null,
                            displayType: null,
                            roundingLimit: null,
                            useHex: null,
                            invertBool: null,
                            isYaw: null,
                            coordinate: null,
                            groupList: new List <VariableGroup>()
                    {
                        VariableGroup.Custom
                    });
                    WatchVariableControl control2 = precursor.CreateWatchVariableControl();
                    panel.AddVariable(control2);
                }
            }

            ToolStripMenuItem itemAddVariables = new ToolStripMenuItem("Add Variable(s)...");

            ControlUtilities.AddDropDownItems(
                itemAddVariables,
                new List <string>()
            {
                "Addition",
                "Subtraction",
                "Multiplication",
                "Division",
                "Modulo",
                "Non-Negative Modulo",
                "Exponent",
                null,
                "Mean",
                "Median",
                "Min",
                "Max",
                null,
                "2D Distance",
                "3D Distance",
                null,
                "Real Time",
            },
                new List <Action>()
            {
                () => createBinaryMathOperationVariable(BinaryMathOperation.Add),
                () => createBinaryMathOperationVariable(BinaryMathOperation.Subtract),
                () => createBinaryMathOperationVariable(BinaryMathOperation.Multiply),
                () => createBinaryMathOperationVariable(BinaryMathOperation.Divide),
                () => createBinaryMathOperationVariable(BinaryMathOperation.Modulo),
                () => createBinaryMathOperationVariable(BinaryMathOperation.NonNegativeModulo),
                () => createBinaryMathOperationVariable(BinaryMathOperation.Exponent),
                () => { },
                () => createAggregateMathOperationVariable(AggregateMathOperation.Mean),
                () => createAggregateMathOperationVariable(AggregateMathOperation.Median),
                () => createAggregateMathOperationVariable(AggregateMathOperation.Min),
                () => createAggregateMathOperationVariable(AggregateMathOperation.Max),
                () => { },
                () => createDistanceMathOperationVariable(use3D: false),
                () => createDistanceMathOperationVariable(use3D: true),
                () => { },
                () => createRealTimeVariable(),
            });

            ToolStripMenuItem itemSetCascadingValues = new ToolStripMenuItem("Set Cascading Values");

            itemSetCascadingValues.Click += (sender, e) =>
            {
                List <WatchVariableControl> controls = getVars();
                object value1 = DialogUtilities.GetStringFromDialog(labelText: "Base Value:");
                object value2 = DialogUtilities.GetStringFromDialog(labelText: "Offset Value:");
                if (value1 == null || value2 == null)
                {
                    return;
                }
                double?number1 = ParsingUtilities.ParseDoubleNullable(value1);
                double?number2 = ParsingUtilities.ParseDoubleNullable(value2);
                if (!number1.HasValue || !number2.HasValue)
                {
                    return;
                }
                List <Func <object, bool> > setters = controls.SelectMany(control => control.GetSetters()).ToList();
                for (int i = 0; i < setters.Count; i++)
                {
                    setters[i](number1.Value + i * number2.Value);
                }
            };

            List <string> backgroundColorStringList = new List <string>();
            List <Action> backgroundColorActionList = new List <Action>();

            backgroundColorStringList.Add("Default");
            backgroundColorActionList.Add(
                () => apply(new WatchVariableControlSettings(changeBackgroundColor: true, changeBackgroundColorToDefault: true)));
            foreach (KeyValuePair <string, string> pair in ColorUtilities.ColorToParamsDictionary)
            {
                Color  color       = ColorTranslator.FromHtml(pair.Value);
                string colorString = pair.Key;
                if (colorString == "LightBlue")
                {
                    colorString = "Light Blue";
                }
                backgroundColorStringList.Add(colorString);
                backgroundColorActionList.Add(
                    () => apply(new WatchVariableControlSettings(changeBackgroundColor: true, newBackgroundColor: color)));
            }
            backgroundColorStringList.Add("Control (No Color)");
            backgroundColorActionList.Add(
                () => apply(new WatchVariableControlSettings(changeBackgroundColor: true, newBackgroundColor: SystemColors.Control)));
            backgroundColorStringList.Add("Custom Color");
            backgroundColorActionList.Add(
                () =>
            {
                List <WatchVariableControl> vars = getVars();
                Color?newColor = ColorUtilities.GetColorFromDialog(SystemColors.Control);
                if (newColor.HasValue)
                {
                    apply2(new WatchVariableControlSettings(changeBackgroundColor: true, newBackgroundColor: newColor.Value), vars);
                    ColorUtilities.LastCustomColor = newColor.Value;
                }
            });
            backgroundColorStringList.Add("Last Custom Color");
            backgroundColorActionList.Add(
                () => apply(new WatchVariableControlSettings(changeBackgroundColor: true, newBackgroundColor: ColorUtilities.LastCustomColor)));
            ToolStripMenuItem itemBackgroundColor = new ToolStripMenuItem("Background Color...");

            ControlUtilities.AddDropDownItems(
                itemBackgroundColor,
                backgroundColorStringList,
                backgroundColorActionList);

            ToolStripMenuItem itemMove = new ToolStripMenuItem("Move...");

            ControlUtilities.AddDropDownItems(
                itemMove,
                new List <string>()
            {
                "Start Move", "End Move", "Clear Move"
            },
                new List <Action>()
            {
                () => panel.NotifyOfReorderingStart(getVars()),
                () => panel.NotifyOfReorderingEnd(getVars()),
                () => panel.NotifyOfReorderingClear(),
            });

            ToolStripMenuItem itemRemove = new ToolStripMenuItem("Remove");

            itemRemove.Click += (sender, e) => panel.RemoveVariables(getVars());

            ToolStripMenuItem itemRename = new ToolStripMenuItem("Rename...");

            itemRename.Click += (sender, e) =>
            {
                List <WatchVariableControl> watchVars = getVars();
                string template = DialogUtilities.GetStringFromDialog("$");
                if (template == null)
                {
                    return;
                }
                foreach (WatchVariableControl control in watchVars)
                {
                    control.VarName = template.Replace("$", control.VarName);
                }
            };

            ToolStripMenuItem itemOpenController = new ToolStripMenuItem("Open Controller");

            itemOpenController.Click += (sender, e) =>
            {
                List <WatchVariableControl> vars          = getVars();
                VariableControllerForm      varController =
                    new VariableControllerForm(
                        vars.ConvertAll(control => control.VarName),
                        vars.ConvertAll(control => control.WatchVarWrapper),
                        vars.ConvertAll(control => control.FixedAddressList));
                varController.Show();
            };

            ToolStripMenuItem itemOpenTripletController = new ToolStripMenuItem("Open Triplet Controller");

            itemOpenTripletController.Click += (sender, e) =>
            {
                VariableTripletControllerForm form = new VariableTripletControllerForm();
                form.Initialize(getVars().ConvertAll(control => control.CreateCopy()));
                form.ShowForm();
            };

            ToolStripMenuItem itemOpenPopOut = new ToolStripMenuItem("Open Pop Out");

            itemOpenPopOut.Click += (sender, e) =>
            {
                VariablePopOutForm form = new VariablePopOutForm();
                form.Initialize(getVars().ConvertAll(control => control.CreateCopy()));
                form.ShowForm();
            };

            ToolStripMenuItem itemAddToTab = new ToolStripMenuItem("Add to Tab...");

            ControlUtilities.AddDropDownItems(
                itemAddToTab,
                new List <string>()
            {
                "Regular", "Fixed", "Grouped by Base Address", "Grouped by Variable"
            },
                new List <Action>()
            {
                () => SelectionForm.ShowDataManagerSelectionForm(getVars(), AddToTabTypeEnum.Regular),
                () => SelectionForm.ShowDataManagerSelectionForm(getVars(), AddToTabTypeEnum.Fixed),
                () => SelectionForm.ShowDataManagerSelectionForm(getVars(), AddToTabTypeEnum.GroupedByBaseAddress),
                () => SelectionForm.ShowDataManagerSelectionForm(getVars(), AddToTabTypeEnum.GroupedByVariable),
            });

            ToolStripMenuItem itemAddToCustomTab = new ToolStripMenuItem("Add to Custom Tab...");

            ControlUtilities.AddDropDownItems(
                itemAddToCustomTab,
                new List <string>()
            {
                "Regular", "Fixed", "Grouped by Base Address", "Grouped by Variable"
            },
                new List <Action>()
            {
                () => WatchVariableControl.AddVarsToTab(getVars(), Config.CustomManager, AddToTabTypeEnum.Regular),
                () => WatchVariableControl.AddVarsToTab(getVars(), Config.CustomManager, AddToTabTypeEnum.Fixed),
                () => WatchVariableControl.AddVarsToTab(getVars(), Config.CustomManager, AddToTabTypeEnum.GroupedByBaseAddress),
                () => WatchVariableControl.AddVarsToTab(getVars(), Config.CustomManager, AddToTabTypeEnum.GroupedByVariable),
            });

            return(new List <ToolStripItem>()
            {
                itemHighlight,
                itemLock,
                itemFixAddress,
                itemCopy,
                itemPaste,
                new ToolStripSeparator(),
                itemRoundTo,
                itemDisplayAsHex,
                new ToolStripSeparator(),
                itemAngleSigned,
                itemAngleUnits,
                itemAngleTruncateToMultipleOf16,
                itemAngleConstrainToOneRevolution,
                itemAngleReverse,
                itemAngleDisplayAsHex,
                new ToolStripSeparator(),
                itemShowVariableXml,
                itemShowVariableInfo,
                new ToolStripSeparator(),
                itemAddVariables,
                itemSetCascadingValues,
                new ToolStripSeparator(),
                itemBackgroundColor,
                itemMove,
                itemRemove,
                itemRename,
                itemOpenController,
                itemOpenTripletController,
                itemOpenPopOut,
                itemAddToTab,
                itemAddToCustomTab,
            });
        }
        public WatchVariableControlSettings(
            bool changeRoundingLimit          = false,
            bool changeRoundingLimitToDefault = false,
            int newRoundingLimit = 0,

            bool changeDisplayAsHex          = false,
            bool changeDisplayAsHexToDefault = false,
            bool newDisplayAsHex             = false,

            bool changeAngleSigned          = false,
            bool changeAngleSignedToDefault = false,
            bool newAngleSigned             = false,

            bool changeYawSigned          = false,
            bool changeYawSignedToDefault = false,
            bool newYawSigned             = false,

            bool changeAngleUnits          = false,
            bool changeAngleUnitsToDefault = false,
            AngleUnitType newAngleUnits    = AngleUnitType.InGameUnits,

            bool changeAngleTruncateToMultipleOf16          = false,
            bool changeAngleTruncateToMultipleOf16ToDefault = false,
            bool newAngleTruncateToMultipleOf16             = false,

            bool changeAngleConstrainToOneRevolution          = false,
            bool changeAngleConstrainToOneRevolutionToDefault = false,
            bool newAngleConstrainToOneRevolution             = false,

            bool changeAngleReverse          = false,
            bool changeAngleReverseToDefault = false,
            bool newAngleReverse             = false,

            bool changeAngleDisplayAsHex          = false,
            bool changeAngleDisplayAsHexToDefault = false,
            bool newAngleDisplayAsHex             = false,

            bool changeHighlighted = false,
            bool newHighlighted    = false,

            bool changeHighlightColor = false,
            Color?newHighlightColor   = null,

            bool changeBackgroundColor          = false,
            bool changeBackgroundColorToDefault = false,
            Color?newBackgroundColor            = null,

            bool changeLocked = false,
            bool newLocked    = false,

            bool changeFixedAddress          = false,
            bool changeFixedAddressToDefault = false,
            bool newFixedAddress             = false)
        {
            ChangeRoundingLimit          = changeRoundingLimit;
            ChangeRoundingLimitToDefault = changeRoundingLimitToDefault;
            NewRoundingLimit             = newRoundingLimit;

            ChangeDisplayAsHex          = changeDisplayAsHex;
            ChangeDisplayAsHexToDefault = changeDisplayAsHexToDefault;
            NewDisplayAsHex             = newDisplayAsHex;

            ChangeAngleSigned          = changeAngleSigned;
            ChangeAngleSignedToDefault = changeAngleSignedToDefault;
            NewAngleSigned             = newAngleSigned;

            ChangeYawSigned          = changeYawSigned;
            ChangeYawSignedToDefault = changeYawSignedToDefault;
            NewYawSigned             = newYawSigned;

            ChangeAngleUnits          = changeAngleUnits;
            ChangeAngleUnitsToDefault = changeAngleUnitsToDefault;
            NewAngleUnits             = newAngleUnits;

            ChangeAngleTruncateToMultipleOf16          = changeAngleTruncateToMultipleOf16;
            ChangeAngleTruncateToMultipleOf16ToDefault = changeAngleTruncateToMultipleOf16ToDefault;
            NewAngleTruncateToMultipleOf16             = newAngleTruncateToMultipleOf16;

            ChangeAngleConstrainToOneRevolution          = changeAngleConstrainToOneRevolution;
            ChangeAngleConstrainToOneRevolutionToDefault = changeAngleConstrainToOneRevolutionToDefault;
            NewAngleConstrainToOneRevolution             = newAngleConstrainToOneRevolution;

            ChangeAngleReverse          = changeAngleReverse;
            ChangeAngleReverseToDefault = changeAngleReverseToDefault;
            NewAngleReverse             = newAngleReverse;

            ChangeAngleDisplayAsHex          = changeAngleDisplayAsHex;
            ChangeAngleDisplayAsHexToDefault = changeAngleDisplayAsHexToDefault;
            NewAngleDisplayAsHex             = newAngleDisplayAsHex;

            ChangeHighlighted = changeHighlighted;
            NewHighlighted    = newHighlighted;

            ChangeHighlightColor = changeHighlightColor;
            NewHighlightColor    = newHighlightColor;

            ChangeBackgroundColor          = changeBackgroundColor;
            ChangeBackgroundColorToDefault = changeBackgroundColorToDefault;
            NewBackgroundColor             = newBackgroundColor;

            ChangeLocked = changeLocked;
            NewLocked    = newLocked;

            ChangeFixedAddress          = changeFixedAddress;
            ChangeFixedAddressToDefault = changeFixedAddressToDefault;
            NewFixedAddress             = newFixedAddress;
        }
        public WatchVariableControlSettings(
            bool changeRoundingLimit          = false,
            bool changeRoundingLimitToDefault = false,
            int newRoundingLimit = 0,

            bool changeDisplayAsHex          = false,
            bool changeDisplayAsHexToDefault = false,
            bool newDisplayAsHex             = false,

            bool changeAngleSigned          = false,
            bool changeAngleSignedToDefault = false,
            bool newAngleSigned             = false,

            bool changeYawSigned          = false,
            bool changeYawSignedToDefault = false,
            bool newYawSigned             = false,

            bool changeAngleUnits          = false,
            bool changeAngleUnitsToDefault = false,
            AngleUnitType newAngleUnits    = AngleUnitType.InGameUnits,

            bool changeAngleTruncateToMultipleOf16          = false,
            bool changeAngleTruncateToMultipleOf16ToDefault = false,
            bool newAngleTruncateToMultipleOf16             = false,

            bool changeAngleConstrainToOneRevolution          = false,
            bool changeAngleConstrainToOneRevolutionToDefault = false,
            bool newAngleConstrainToOneRevolution             = false,

            bool changeAngleDisplayAsHex          = false,
            bool changeAngleDisplayAsHexToDefault = false,
            bool newAngleDisplayAsHex             = false,

            bool changeHighlighted = false,
            bool newHighlighted    = false,

            bool changeLocked = false,
            bool newLocked    = false,

            bool enableCustomization = false)
        {
            ChangeRoundingLimit          = changeRoundingLimit;
            ChangeRoundingLimitToDefault = changeRoundingLimitToDefault;
            NewRoundingLimit             = newRoundingLimit;

            ChangeDisplayAsHex          = changeDisplayAsHex;
            ChangeDisplayAsHexToDefault = changeDisplayAsHexToDefault;
            NewDisplayAsHex             = newDisplayAsHex;

            ChangeAngleSigned          = changeAngleSigned;
            ChangeAngleSignedToDefault = changeAngleSignedToDefault;
            NewAngleSigned             = newAngleSigned;

            ChangeYawSigned          = changeYawSigned;
            ChangeYawSignedToDefault = changeYawSignedToDefault;
            NewYawSigned             = newYawSigned;

            ChangeAngleUnits          = changeAngleUnits;
            ChangeAngleUnitsToDefault = changeAngleUnitsToDefault;
            NewAngleUnits             = newAngleUnits;

            ChangeAngleTruncateToMultipleOf16          = changeAngleTruncateToMultipleOf16;
            ChangeAngleTruncateToMultipleOf16ToDefault = changeAngleTruncateToMultipleOf16ToDefault;
            NewAngleTruncateToMultipleOf16             = newAngleTruncateToMultipleOf16;

            ChangeAngleConstrainToOneRevolution          = changeAngleConstrainToOneRevolution;
            ChangeAngleConstrainToOneRevolutionToDefault = changeAngleConstrainToOneRevolutionToDefault;
            NewAngleConstrainToOneRevolution             = newAngleConstrainToOneRevolution;

            ChangeAngleDisplayAsHex          = changeAngleDisplayAsHex;
            ChangeAngleDisplayAsHexToDefault = changeAngleDisplayAsHexToDefault;
            NewAngleDisplayAsHex             = newAngleDisplayAsHex;

            ChangeHighlighted = changeHighlighted;
            NewHighlighted    = newHighlighted;

            ChangeLocked = changeLocked;
            NewLocked    = newLocked;

            EnableCustomization = enableCustomization;
        }