Esempio n. 1
0
        public void run()
        {
            try
            {
                //parameters
                t3d.Point center;
                double    radius;
                double    height  = 0;
                double    width   = 0;
                int       rotaion = -1;

                if (cm_rotation.SelectedIndex == 1)
                {
                    rotaion = 1;
                }
                double curve_angle = 0;
                double holeSize    = int.Parse(tx_size.Text);

                //picking one part and one point
                //part
                PolyBeam main_beam = new Picker().PickObject(Picker.PickObjectEnum.PICK_ONE_PART) as PolyBeam;
                //set coordiates
                model.GetWorkPlaneHandler().SetCurrentTransformationPlane(new TransformationPlane());
                CoordinateSystem mainPart_coordinat = main_beam.GetCoordinateSystem();
                if (main_beam.Position.Rotation == Position.RotationEnum.BACK || main_beam.Position.Rotation == Position.RotationEnum.FRONT)
                {
                    mainPart_coordinat.AxisY = mainPart_coordinat.AxisX.Cross(mainPart_coordinat.AxisY);
                    main_beam.GetReportProperty("WIDTH", ref height);
                    main_beam.GetReportProperty("HEIGHT", ref width);
                }
                else
                {
                    main_beam.GetReportProperty("HEIGHT", ref height);
                    main_beam.GetReportProperty("WIDTH", ref width);
                }

                TransformationPlane transformationPlane = new TransformationPlane(mainPart_coordinat);
                model.GetWorkPlaneHandler().SetCurrentTransformationPlane(transformationPlane);
                //pick point
                ArrayList point       = new Picker().PickPoints(Picker.PickPointEnum.PICK_ONE_POINT);
                t3d.Point first_point = point[0] as t3d.Point;
                first_point = new t3d.Point(first_point.X, first_point.Y, 0);


                // get proprties of curved beam
                get_circle_center(main_beam, out center, out radius);

                double inner_radius = radius - height / 2;
                double outer_radius = radius + height / 2;


                // get angle of inner curve
                curve_angle = angleOfCurve(double.Parse(tx_dis.Text) * -1, radius);

                // convert center and picking point to new local coorditaes
                conver_coordinates_center_point(center, first_point, out center, out first_point);

                //calculate required inner point
                t3d.Point point1_dis;
                t3d.Point point2_dis;
                calculate2HolesCoordiates(center, radius, outer_radius, curve_angle, out point1_dis, out point2_dis);

                //// insert hole  curve
                BoltArray hole1 = insert_hole(main_beam, new t3d.Point(point1_dis.X, point1_dis.Y, point1_dis.Z + width / 2 * rotaion),
                                              new t3d.Point(point1_dis.X + 10, point1_dis.Y, point1_dis.Z + width / 2 * rotaion)
                                              , holeSize, 0);


                //calculate required out point
                // insert hole  curve

                /*  BoltArray hole2 = insert_hole(main_beam, point2_dis,
                 *    new t3d.Point(point2_dis.X, point2_dis.Y, point2_dis.Z + 10)
                 *    , holeSize, 0);*/
                // get bol vector

                LineSegment secHole = new LineSegment(new t3d.Point(hole1.FirstPosition.X, hole1.FirstPosition.Y, hole1.FirstPosition.Z + 1000),
                                                      new t3d.Point(hole1.FirstPosition.X, hole1.FirstPosition.Y, hole1.FirstPosition.Z - 1000));



                Solid     checkIntesection  = main_beam.GetSolid();
                ArrayList intersectedPoints = checkIntesection.Intersect(secHole);
                // loop
                while (intersectedPoints.Count > 0)
                {
                    conver_coordinates_center_point(center, point1_dis, out center, out point1_dis);
                    calculate2HolesCoordiates(center, radius, outer_radius, curve_angle, out point1_dis, out point2_dis);
                    //// insert hole  curve
                    hole1 = insert_hole(main_beam, new t3d.Point(point1_dis.X, point1_dis.Y, point1_dis.Z + width / 2 * rotaion),
                                        new t3d.Point(point1_dis.X + 10, point1_dis.Y, point1_dis.Z + width / 2 * rotaion)
                                        , holeSize, 0);


                    //calculate required out point
                    // insert hole  curve

                    /*  hole2 = insert_hole(main_beam, point2_dis,
                     *    new t3d.Point(point2_dis.X, point2_dis.Y, point2_dis.Z + 10)
                     *    , holeSize, curve_angle);*/

                    // firstHole = new LineSegment(hole1.FirstPosition, hole1.SecondPosition);
                    secHole = new LineSegment(new t3d.Point(hole1.FirstPosition.X, hole1.FirstPosition.Y, hole1.FirstPosition.Z + 1000),
                                              new t3d.Point(hole1.FirstPosition.X, hole1.FirstPosition.Y, hole1.FirstPosition.Z - 1000));

                    intersectedPoints = checkIntesection.Intersect(secHole);
                }
                if (intersectedPoints.Count == 0)
                {
                    hole1.Delete();
                    //hole2.Delete();
                }

                model.GetWorkPlaneHandler().SetCurrentTransformationPlane(new TransformationPlane());


                model.CommitChanges();
            }
            catch (Exception)
            {
            }
        }