Пример #1
0
        private bool ShouldSave()
        {
            if (joint.cDriver == null)
            {
                return(true);
            }

            double inputGear = 1, outputGear = 1;

            inputGear  = (double)InputGeartxt.Value;
            outputGear = (double)OutputGeartxt.Value;

            PneumaticDriverMeta pneumatic = joint.cDriver.GetInfo <PneumaticDriverMeta>();
            WheelDriverMeta     wheel     = joint.cDriver.GetInfo <WheelDriverMeta>();
            ElevatorDriverMeta  elevator  = joint.cDriver.GetInfo <ElevatorDriverMeta>();

            Enum.TryParse(MotorTypeDropDown.SelectedItem.ToString(), out MotorType motor);
            if (cmbJointDriver.SelectedIndex != typeOptions.ToList().IndexOf(joint.cDriver.GetDriveType()) + 1 ||
                txtPort1.Value != joint.cDriver.port1 ||
                txtPort2.Value != joint.cDriver.port2 ||
                txtLowLimit.Value != (decimal)joint.cDriver.lowerLimit ||
                txtHighLimit.Value != (decimal)joint.cDriver.upperLimit ||
                inputGear != joint.cDriver.InputGear || outputGear != joint.cDriver.OutputGear ||
                rbCAN.Checked != joint.cDriver.isCan || chkBoxHasBrake.Checked != joint.cDriver.hasBrake ||
                motor != joint.cDriver.motor)
            {
                return(true);
            }

            if (pneumatic != null &&
                (numericUpDownPnuDia.Value != (decimal)pneumatic.width ||
                 cmbPneumaticPressure.SelectedIndex != (int)pneumatic.pressureEnum))
            {
                return(true);
            }

            if (wheel != null &&
                (cmbWheelType.SelectedIndex != (int)wheel.type ||
                 cmbFrictionLevel.SelectedIndex != (int)wheel.GetFrictionLevel() ||
                 chkBoxDriveWheel.Checked != wheel.isDriveWheel))
            {
                return(true);
            }

            if (elevator != null)
            {
                return(true);
            }

            //If going from "NOT A WHEEL" to a wheel
            if (cmbWheelType.SelectedIndex != 0 && wheel == null && joint.cDriver.GetDriveType() == JointDriverType.MOTOR)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        public static string WheelFrictionString(WheelDriverMeta wheel)
        {
            switch (wheel.GetFrictionLevel())
            {
            case FrictionLevel.LOW:
                return("Low");

            case FrictionLevel.MEDIUM:
                return("Medium");

            case FrictionLevel.HIGH:
                return("High");

            default:
                return("None");
            }
        }
Пример #3
0
        public void ShowDialog(SkeletalJoint_Base baseJoint, List <RigidNode_Base> nodes, Form owner)
        {
            Saved = false;

            if (nodes.Count > 1)
            {
                bool same = true;

                foreach (RigidNode_Base node in nodes)
                {
                    JointDriver driver = node.GetSkeletalJoint().cDriver;
                    if (driver == null || driver.CompareTo(baseJoint.cDriver) != 0)
                    {
                        same = false;
                    }
                }

                if (same)
                {
                    joint = baseJoint;
                }
                else
                {
                    joint = SkeletalJoint_Base.JOINT_FACTORY(baseJoint.GetJointType());
                }
            }
            else
            {
                joint = baseJoint;
            }
            this.nodes  = nodes;
            typeOptions = JointDriver.GetAllowedDrivers(joint);

            // Used for capitalization
            TextInfo textInfo = new CultureInfo("en-US", true).TextInfo;

            cmbJointDriver.Items.Clear();
            cmbJointDriver.Items.Add("No Driver");
            foreach (JointDriverType type in typeOptions)
            {
                cmbJointDriver.Items.Add(textInfo.ToTitleCase(Enum.GetName(typeof(JointDriverType), type).Replace('_', ' ').ToLowerInvariant()));
            }
            if (joint.cDriver != null)
            {
                cmbJointDriver.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()) + 1;

                if (joint.cDriver.port1 < txtPort1.Minimum)
                {
                    txtPort1.Value = txtPort1.Minimum;
                }
                else if (joint.cDriver.port1 > txtPort1.Maximum)
                {
                    txtPort1.Value = txtPort1.Maximum;
                }
                else
                {
                    txtPort1.Value = joint.cDriver.port1;
                }

                if (joint.cDriver.port2 < txtPort2.Minimum)
                {
                    txtPort2.Value = txtPort2.Minimum;
                }
                else if (joint.cDriver.port2 > txtPort2.Maximum)
                {
                    txtPort2.Value = txtPort2.Maximum;
                }
                else
                {
                    txtPort2.Value = joint.cDriver.port2;
                }

                txtLowLimit.Value  = (decimal)joint.cDriver.lowerLimit;
                txtHighLimit.Value = (decimal)joint.cDriver.upperLimit;

                rbPWM.Checked          = !joint.cDriver.isCan;
                rbCAN.Checked          = joint.cDriver.isCan;
                chkBoxHasBrake.Checked = joint.cDriver.hasBrake;
                if (joint.cDriver.OutputGear == 0)// prevents output gear from being 0
                {
                    joint.cDriver.OutputGear = 1;
                }
                if (joint.cDriver.InputGear == 0)// prevents input gear from being 0
                {
                    joint.cDriver.InputGear = 1;
                }
                OutputGeartxt.Value = (decimal)joint.cDriver.OutputGear; // reads the existing gearing and writes it to the input field so the user sees their existing value
                InputGeartxt.Value  = (decimal)joint.cDriver.InputGear;  // reads the existing gearing and writes it to the input field so the user sees their existing value

                {
                    PneumaticDriverMeta pneumaticMeta = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                    if (pneumaticMeta != null)
                    {
                        numericUpDownPnuDia.Value          = (decimal)pneumaticMeta.width;
                        cmbPneumaticPressure.SelectedIndex = (int)pneumaticMeta.pressureEnum;
                    }
                    else
                    {
                        numericUpDownPnuDia.Value          = (decimal)1.0;
                        cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.HIGH;
                    }
                }
                {
                    WheelDriverMeta wheelMeta = joint.cDriver.GetInfo <WheelDriverMeta>();
                    if (wheelMeta != null)
                    {
                        try
                        {
                            cmbWheelType.SelectedIndex     = (int)wheelMeta.type;
                            cmbFrictionLevel.SelectedIndex = (int)wheelMeta.GetFrictionLevel();
                        }
                        catch
                        {
                            // If an exception was thrown (System.ArguementOutOfRangeException) it means
                            // the user did not choose a wheel type when they were configuring the
                            // wheel joint
                            cmbWheelType.SelectedIndex     = (int)WheelType.NORMAL;
                            cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                        }

                        chkBoxDriveWheel.Checked = wheelMeta.isDriveWheel;
                        cmbWheelType_SelectedIndexChanged(null, null);
                    }
                    else
                    {
                        cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                        cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                    }
                }
                {
                    ElevatorDriverMeta elevatorMeta = joint.cDriver.GetInfo <ElevatorDriverMeta>();
                }
                {
                    switch (joint.cDriver.motor)
                    {
                    case MotorType.GENERIC:
                        RobotCompetitionDropDown.SelectedItem = RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultRobotCompetition.ToString();
                        MotorTypeDropDown.SelectedItem        = "GENERIC";
                        break;

                    case MotorType.CIM:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "CIM";
                        break;

                    case MotorType.MINI_CIM:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "MIN_CIM";
                        break;

                    case MotorType.BAG_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BAG_MOTOR";
                        break;

                    case MotorType.REDLINE_775_PRO:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "REDLINE_775_PRO";
                        break;

                    case MotorType.ANDYMARK_9015:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "ANDYMARK_9015";
                        break;

                    case MotorType.BANEBOTS_775_18v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_775_18v";
                        break;

                    case MotorType.BANEBOTS_775_12v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_775_12v";
                        break;

                    case MotorType.BANEBOTS_550_12v:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "BANEBOTS_550_12v";
                        break;

                    case MotorType.ANDYMARK_775_125:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "ANDYMARK_775_125";
                        break;

                    case MotorType.SNOW_BLOWER:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "SNOW_BLOWER";
                        break;

                    case MotorType.NIDEC_BLDC:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "NIDEC_BLDC";
                        break;

                    case MotorType.THROTTLE_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "THROTTLE_MOTOR";
                        break;

                    case MotorType.WINDOW_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FRC";
                        MotorTypeDropDown.SelectedItem        = "WINDOW_MOTOR";
                        break;

                    case MotorType.NEVEREST:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "NEVEREST";
                        break;

                    case MotorType.TETRIX_MOTOR:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "TETRIX_MOTOR";
                        break;

                    case MotorType.MODERN_ROBOTICS_MATRIX:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "MODERN_ROBOTICS_MATRIX";
                        break;

                    case MotorType.REV_ROBOTICS_HD_HEX_20_TO_1:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_HD_HEX_20_TO_1";
                        break;

                    case MotorType.REV_ROBOTICS_HD_HEX_40_TO_1:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_HD_HEX_40_TO_1";
                        break;

                    case MotorType.REV_ROBOTICS_CORE_HEX:
                        RobotCompetitionDropDown.SelectedItem = "FTC";
                        MotorTypeDropDown.SelectedItem        = "REV_ROBOTICS_CORE_HEX";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_600_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_600_RPM";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_200_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_200_RPM";
                        break;

                    case MotorType.VEX_V5_Smart_Motor_100_RPM:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_V5_Smart_Motor_100_RPM";
                        break;

                    case MotorType.VEX_393_NORMAL_SPEED:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_NORMAL_SPEED";
                        break;

                    case MotorType.VEX_393_HIGH_SPEED:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_HIGH_SPEED";
                        break;

                    case MotorType.VEX_393_TURBO_GEAR_SET:
                        RobotCompetitionDropDown.SelectedItem = "VEX";
                        MotorTypeDropDown.SelectedItem        = "VEX_393_TURBO_GEAR_SET";
                        break;
                    }
                }
            }
            else //Default values
            {
                cmbJointDriver.SelectedIndex = 0;
                txtPort1.Value      = txtPort1.Minimum;
                txtPort2.Value      = txtPort2.Minimum;
                txtLowLimit.Value   = txtLowLimit.Minimum;
                txtHighLimit.Value  = txtHighLimit.Minimum;
                InputGeartxt.Value  = (decimal)1.0;
                OutputGeartxt.Value = (decimal)1.0;

                rbPWM.Checked = true;

                chkBoxHasBrake.Checked = false;

                numericUpDownPnuDia.Value          = (decimal)0.5;
                cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.MEDIUM;

                cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                chkBoxDriveWheel.Checked       = false;

                RobotCompetitionDropDown.SelectedItem = RobotExporterAddInServer.Instance.AddInSettingsManager.DefaultRobotCompetition;
                MotorTypeDropDown.SelectedItem        = "GENERIC";
            }

            PrepLayout();
            base.Location = new System.Drawing.Point(Cursor.Position.X - 10, Cursor.Position.Y - base.Height - 10);
            this.ShowDialog(owner);
        }
Пример #4
0
    public void ShowDialog(SkeletalJoint_Base baseJoint, List <RigidNode_Base> nodes, Form owner)
    {
        Saved = false;

        if (nodes.Count > 1)
        {
            bool same = true;

            foreach (RigidNode_Base node in nodes)
            {
                JointDriver driver = node.GetSkeletalJoint().cDriver;
                if (driver == null || driver.CompareTo(baseJoint.cDriver) != 0)
                {
                    same = false;
                }
            }

            if (same)
            {
                joint = baseJoint;
            }
            else
            {
                joint = SkeletalJoint_Base.JOINT_FACTORY(baseJoint.GetJointType());
            }
        }
        else
        {
            joint = baseJoint;
        }
        this.nodes  = nodes;
        typeOptions = JointDriver.GetAllowedDrivers(joint);

        // Used for capitalization
        TextInfo textInfo = new CultureInfo("en-US", true).TextInfo;

        cmbJointDriver.Items.Clear();
        cmbJointDriver.Items.Add("No Driver");
        foreach (JointDriverType type in typeOptions)
        {
            cmbJointDriver.Items.Add(textInfo.ToTitleCase(Enum.GetName(typeof(JointDriverType), type).Replace('_', ' ').ToLowerInvariant()));
        }
        if (joint.cDriver != null)
        {
            cmbJointDriver.SelectedIndex = Array.IndexOf(typeOptions, joint.cDriver.GetDriveType()) + 1;

            if (joint.cDriver.port1 < txtPort1.Minimum)
            {
                txtPort1.Value = txtPort1.Minimum;
            }
            else if (joint.cDriver.port1 > txtPort1.Maximum)
            {
                txtPort1.Value = txtPort1.Maximum;
            }
            else
            {
                txtPort1.Value = joint.cDriver.port1;
            }

            if (joint.cDriver.port2 < txtPort2.Minimum)
            {
                txtPort2.Value = txtPort2.Minimum;
            }
            else if (joint.cDriver.port2 > txtPort2.Maximum)
            {
                txtPort2.Value = txtPort2.Maximum;
            }
            else
            {
                txtPort2.Value = joint.cDriver.port2;
            }

            txtLowLimit.Value  = (decimal)joint.cDriver.lowerLimit;
            txtHighLimit.Value = (decimal)joint.cDriver.upperLimit;

            rbPWM.Checked          = !joint.cDriver.isCan;
            rbCAN.Checked          = joint.cDriver.isCan;
            chkBoxHasBrake.Checked = joint.cDriver.hasBrake;
            if (joint.cDriver.OutputGear == 0)    // prevents output gear from being 0
            {
                joint.cDriver.OutputGear = 1;
            }
            if (joint.cDriver.InputGear == 0)// prevents input gear from being 0
            {
                joint.cDriver.InputGear = 1;
            }
            OutputGeartxt.Value = (decimal)joint.cDriver.OutputGear; // reads the existing gearing and writes it to the input field so the user sees their existing value
            InputGeartxt.Value  = (decimal)joint.cDriver.InputGear;  // reads the existing gearing and writes it to the input field so the user sees their existing value

            #region Meta info recovery
            {
                PneumaticDriverMeta pneumaticMeta = joint.cDriver.GetInfo <PneumaticDriverMeta>();
                if (pneumaticMeta != null)
                {
                    cmbPneumaticDiameter.SelectedIndex = (int)pneumaticMeta.widthEnum;
                    cmbPneumaticPressure.SelectedIndex = (int)pneumaticMeta.pressureEnum;
                }
                else
                {
                    cmbPneumaticDiameter.SelectedIndex = (int)PneumaticDiameter.MEDIUM;
                    cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.HIGH;
                }
            }
            {
                WheelDriverMeta wheelMeta = joint.cDriver.GetInfo <WheelDriverMeta>();
                if (wheelMeta != null)
                {
                    try
                    {
                        cmbWheelType.SelectedIndex     = (int)wheelMeta.type;
                        cmbFrictionLevel.SelectedIndex = (int)wheelMeta.GetFrictionLevel();
                    }
                    catch
                    {
                        // If an exception was thrown (System.ArguementOutOfRangeException) it means
                        // the user did not choose a wheel type when they were configuring the
                        // wheel joint
                        cmbWheelType.SelectedIndex     = (int)WheelType.NORMAL;
                        cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                    }

                    chkBoxDriveWheel.Checked = wheelMeta.isDriveWheel;
                    cmbWheelType_SelectedIndexChanged(null, null);
                }
                else
                {
                    cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
                    cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
                }
            }
            {
                ElevatorDriverMeta elevatorMeta = joint.cDriver.GetInfo <ElevatorDriverMeta>();
            }
            #endregion
        }
        else //Default values
        {
            cmbJointDriver.SelectedIndex = 0;
            txtPort1.Value      = txtPort1.Minimum;
            txtPort2.Value      = txtPort2.Minimum;
            txtLowLimit.Value   = txtLowLimit.Minimum;
            txtHighLimit.Value  = txtHighLimit.Minimum;
            InputGeartxt.Value  = (decimal)1.0;
            OutputGeartxt.Value = (decimal)1.0;

            rbPWM.Checked = true;

            chkBoxHasBrake.Checked = false;

            cmbPneumaticDiameter.SelectedIndex = (int)PneumaticDiameter.MEDIUM;
            cmbPneumaticPressure.SelectedIndex = (int)PneumaticPressure.MEDIUM;

            cmbWheelType.SelectedIndex     = (int)WheelType.NOT_A_WHEEL;
            cmbFrictionLevel.SelectedIndex = (int)FrictionLevel.MEDIUM;
            chkBoxDriveWheel.Checked       = false;
        }

        PrepLayout();
        base.Location = new System.Drawing.Point(Cursor.Position.X - 10, Cursor.Position.Y - base.Height - 10);
        this.ShowDialog(owner);
    }