private void btnRemove_Click(object sender, EventArgs e)
        {
            if (listGearBox.SelectedItems.Count > 0)
            {
                GearBox gearBoxToDelete = new GearBox();
                gearBoxToDelete = (GearBox)listGearBox.SelectedItems[0];
                foreach (GearBox gb in Program.gearBoxList)
                {
                    if (gb.Equals(gearBoxToDelete))
                    {
                        gearBoxToDelete = gb;
                    }
                }

                Program.gearBoxList.Remove(gearBoxToDelete);
                Database1DataSet1TableAdapters.GearBoxTableAdapter gbta = new Database1DataSet1TableAdapters.GearBoxTableAdapter();
                gbta.Delete(gearBoxToDelete.ID, gearBoxToDelete.Name, gearBoxToDelete.Alpha, gearBoxToDelete.AxesDistance, gearBoxToDelete.GearModule, gearBoxToDelete.InputTorque, gearBoxToDelete.OutputTorque, gearBoxToDelete.TorqueRatio, gearBoxToDelete.InputGear.ID, gearBoxToDelete.OutputGear.ID);

            }
            refreshList();
            treeViewGearBox.Nodes.Clear();
            propertyGridGearBox.SelectedObject = null;
            this.btnRemove.Enabled = false;
            this.btnEdit.Enabled = false;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            // TODO: Save
            GearBox gb = new GearBox();
            gb.Name = txtName.Text;
            gb.Alpha = Convert.ToDouble(numAlpha.Value);
            gb.AxesDistance = Convert.ToDouble(numAxisDistance.Value);
            gb.GearModule = Convert.ToDouble(numGearModule.Value);
            gb.InputGear = inputGear;
            gb.OutputGear = outputGear;
            gb.OutputTorque = Convert.ToDouble(numOutputTorque.Value);
            gb.InputTorque = Convert.ToDouble(numInputTorque.Value);
            gb.TorqueRatio = Convert.ToDouble(numTorqueRatio.Value);

            if (gb.Name != "" && gb.InputGear != null && gb.OutputGear != null)
            {
                Database1DataSet1TableAdapters.GearBoxTableAdapter gbta = new Database1DataSet1TableAdapters.GearBoxTableAdapter();
                gbta.Insert(gb.Name, gb.Alpha,gb.AxesDistance,gb.GearModule,gb.InputTorque, gb.OutputTorque, gb.TorqueRatio, gb.InputGear.ID, gb.OutputGear.ID);
                gb.ID = (int)gbta.getID(gb.Name, gb.Alpha, gb.AxesDistance, gb.GearModule, gb.InputTorque, gb.OutputTorque, gb.TorqueRatio, gb.InputGear.ID, gb.OutputGear.ID);
                Program.gearBoxList.Add(gb);
                DialogResult = DialogResult.OK;
            }
            else
            {
                if (gb.Name == "")
                    MessageBox.Show("You have to add a Name to your gear box", "Impossible to save the gear box", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                else if (gb.InputGear == null)
                    MessageBox.Show("You have to add a Input Gear to your gear box", "Impossible to save the gear box", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                else
                    MessageBox.Show("You have to add a Output Gear to your gear box", "Impossible to save the gear box", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 private void updateTreeView(GearBox gb)
 {
     treeView1.Nodes.Clear();
     treeView1.Nodes.Add(Util.fillTreeView(gb));
     propertyGrid1.SelectedObject = gb;
 }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            btnValidate.Visible = false;

            if (txtName.Text == "")
               MessageBox.Show("You have to add a Name to your Gear Box", "Impossible to generate a GearBox ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else if (txtInputMaterial.Tag == null)
                MessageBox.Show("You have to add a Material to your InputGear", "Impossible to generate a GearBox", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else if (txtOutputMaterial.Tag == null)
                MessageBox.Show("You have to add a Material to your OutputGear", "Impossible to generate a GearBox", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else
            {
                tsStatusLabel.Text = "Starting the generation...";

                numTorqueRatio.Value = numOutputTorque.Value / numInputTorque.Value;
                double axesDistance = Convert.ToDouble(numAxesDistance.Value);
                double torqueRatio = Convert.ToDouble(numTorqueRatio.Value);
                gearBox = new GearBox();
                inputGear = new Gear();
                outputGear = new Gear();
                double alpha = Convert.ToDouble(numAlpha.Value)*Math.PI/180;

                /*
                 * Data extraction
                 */

                // Gear Box Creation
                gearBox.Name = txtName.Text;
                gearBox.Alpha = alpha;
                gearBox.GearModule = Convert.ToDouble(numGearModule.Value);
                gearBox.AxesDistance = axesDistance;
                gearBox.TorqueRatio = torqueRatio;
                gearBox.InputTorque = Convert.ToDouble(numInputTorque.Value);
                gearBox.OutputTorque = Convert.ToDouble(numOutputTorque.Value);
                gearBox.InputGear = inputGear;
                gearBox.OutputGear = outputGear;

                // Input Gear Creation
                inputGear.Name = txtName.Text + " Input Gear";
                inputGear.Alpha = alpha;
                inputGear.GearModule = Convert.ToDouble(numGearModule.Value);
                inputGear.WantedRadius = axesDistance * (1 / (1 + torqueRatio));
                inputGear.Torque = Convert.ToDouble(numInputTorque.Value);
                inputGear.Material = (Material)txtInputMaterial.Tag;

                // Output Gear Creation
                outputGear.Name = txtName.Text + " Output Gear";
                outputGear.Alpha = alpha;
                outputGear.GearModule = Convert.ToDouble(numGearModule.Value);
                outputGear.WantedRadius = axesDistance * (1 - 1 / (1 + torqueRatio));
                outputGear.Torque = Convert.ToDouble(numOutputTorque.Value);
                outputGear.Material = (Material)txtOutputMaterial.Tag;

                /*
                 * Data Calculation
                 */

                //Input Gear Calculation
                gearCalculation(inputGear, true);
                updateGearOnCatia(inputGear, true);

                gearCalculation(outputGear, false);
                updateGearOnCatia(outputGear, false);
                showGearboxOnCatia(gearBox);

                updateTreeView(gearBox);
                this.btnValidate.Visible = true;
            }
        }
        private void showGearboxOnCatia(GearBox gb)
        {
            tsStatusLabel.Text = "Generating the Gear Box on Catia...";
            INFITF.Application catiaApp = null;
            try
            {
                catiaApp = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application") as INFITF.Application;
            }
            catch (Exception ex)
            {
                catiaApp = System.Activator.CreateInstance(Type.GetTypeFromProgID("CATIA.Application")) as INFITF.Application;
            }
            finally
            {
                catiaApp.Visible = true;
                catiaApp.Documents.Open(path + "\\GearBox.CATProduct");
            }
            ProductStructureTypeLib.ProductDocument productDoc = (ProductStructureTypeLib.ProductDocument)catiaApp.ActiveDocument;
            ProductStructureTypeLib.Product product = productDoc.Product;

            KnowledgewareTypeLib.Parameter type = (KnowledgewareTypeLib.Parameter)product.Parameters.GetItem("AxesDistance");
            type.ValuateFromString(gb.AxesDistance + "mm");

            product.Update();
            productDoc.Save();
            tsStatusLabel.Text = "Generation Complete";
        }
예제 #6
0
        public static void refreshGearBoxList()
        {
            Program.gearBoxList.Clear();

            Database1DataSet1TableAdapters.GearBoxTableAdapter gbta = new Database1DataSet1TableAdapters.GearBoxTableAdapter();
            Database1DataSet1.GearBoxDataTable GearBoxFromDB = new Database1DataSet1.GearBoxDataTable();
            gbta.Fill(GearBoxFromDB);

            foreach (Database1DataSet1.GearBoxRow row in GearBoxFromDB)
            {
                GearBox gb = new GearBox();
                gb.ID = row.ID;
                gb.Name = row.GearBoxName;
                gb.Alpha = row.Alpha;
                gb.AxesDistance = row.AxesDistance;
                gb.GearModule = row.GearModule;
                gb.InputTorque = row.InputTorque;
                gb.OutputTorque = row.OutputTorque;
                gb.TorqueRatio = row.TorqueRatio;
                gb.InputGear = Util.getGearById(row.InputGear);
                gb.OutputGear = Util.getGearById(row.OutputGear);

                Program.gearBoxList.Add(gb);
            }
        }