Esempio n. 1
0
        private void btn_multiBeams_Click(object sender, EventArgs e)
        {
            try
            {
                Picker    picker = new Picker();
                ArrayList points = picker.PickPoints(Picker.PickPointEnum.PICK_POLYGON);

                if (points.Count >= 3)
                {
                    TSG.Point  start     = new TSG.Point(0, 0, 0);
                    TSG.Point  middle    = new TSG.Point(0, 0, 0);
                    TSG.Point  end       = new TSG.Point(0, 0, 0);
                    TSG.Vector vectorFit = new TSG.Vector();
                    TSG.Vector vectorZ   = new TSG.Vector();
                    TSG.Vector vectorOne = new TSG.Vector();
                    TSG.Vector vectorTwo = new TSG.Vector();

                    ArrayList listBeams  = new ArrayList();
                    ArrayList listPlates = new ArrayList();

                    double angelDegree = 0.0;

                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        TSM.Beam beam = BeamFirst(points[i] as TSG.Point, points[i + 1] as TSG.Point);
                        beam.Insert();
                        listBeams.Add(beam);
                        this.model.CommitChanges();
                    }

                    double primaryWidth  = 0.0;
                    double primaryHeight = 0.0;

                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        try
                        {
                            start  = points[i] as TSG.Point;
                            middle = points[i + 1] as TSG.Point;
                            end    = points[i + 2] as TSG.Point;
                        }
                        catch
                        {
                        }

                        vectorOne = new TSG.Vector(middle.X - start.X, middle.Y - start.Y, middle.Z - start.Z);
                        vectorOne.Normalize();
                        vectorTwo = new TSG.Vector(middle.X - end.X, middle.Y - end.Y, middle.Z - end.Z);
                        vectorTwo.Normalize();
                        double angle = vectorOne.GetAngleBetween(vectorTwo);
                        angelDegree = angle * 180 / Math.PI;

                        //TSG.Vector vectorFit = new TSG.Vector(1 * Math.Cos(angle / 2), 1 * Math.Cos(angle / 2), 0);
                        vectorFit = new TSG.Vector(vectorOne.X + vectorTwo.X, vectorOne.Y + vectorTwo.Y, vectorOne.Z + vectorTwo.Z);
                        vectorZ   = vectorOne.Cross(vectorTwo);

                        TSG.CoordinateSystem coordinateSystem = new TSG.CoordinateSystem();

                        double thick;
                        if (tb_thcikPlates.Text != string.Empty)
                        {
                            double.TryParse(tb_thcikPlates.Text, out thick);
                        }
                        else
                        {
                            thick = 20.0;
                        }

                        double offset  = thick;
                        double angleFD = 90 - (angelDegree / 2);
                        double angleFR = Math.PI * angleFD / 180;

                        double width  = 0.0;
                        double heigth = 0.0;

                        double x = Math.Round(vectorFit.X, 2, MidpointRounding.ToEven);
                        double y = Math.Round(vectorFit.Y, 2, MidpointRounding.ToEven);
                        double z = Math.Round(vectorFit.Z, 2, MidpointRounding.ToEven);


                        TSM.Beam beam1 = listBeams[i] as TSM.Beam;
                        TSM.Beam beam2 = listBeams[i + 1] as TSM.Beam;
                        beam1.GetReportProperty("WIDTH", ref primaryWidth);
                        beam1.GetReportProperty("HEIGHT", ref primaryHeight);

                        if (x == 0.0 && y == 0.0 && z == 0.0)
                        {
                            TSG.Vector bAxisX = beam1.GetCoordinateSystem().AxisX;
                            TSG.Vector bAxisY = beam1.GetCoordinateSystem().AxisY;
                            TSG.Vector bAxisZ = bAxisY.Cross(bAxisX);

                            coordinateSystem = new TSG.CoordinateSystem(middle, bAxisZ, bAxisY);
                        }
                        else
                        {
                            coordinateSystem = new TSG.CoordinateSystem(
                                middle, vectorFit, vectorZ);
                        }

                        TSM.WorkPlaneHandler planeHandler = model.GetWorkPlaneHandler();

                        TSM.TransformationPlane original  = planeHandler.GetCurrentTransformationPlane();
                        TSM.TransformationPlane beamPlane = new TSM.TransformationPlane(coordinateSystem);
                        planeHandler.SetCurrentTransformationPlane(beamPlane);

                        FitBeam(beam1, -offset);
                        FitBeam(beam2, offset);

                        if (z != 0)
                        {
                            vectorZ = vectorTwo.Cross(vectorOne);

                            planeHandler.SetCurrentTransformationPlane(original);
                            TSG.CoordinateSystem coordinatePlate = new TSG.CoordinateSystem(
                                middle, vectorZ, vectorFit);

                            TSM.TransformationPlane beamPlate = new TSM.TransformationPlane(coordinatePlate);
                            planeHandler.SetCurrentTransformationPlane(beamPlate);

                            width  = primaryWidth;
                            heigth = 50 + primaryHeight / (Math.Cos(angleFR));
                        }
                        else
                        {
                            width  = 50 + primaryWidth / (Math.Cos(angleFR));
                            heigth = primaryHeight;
                        }


                        bool positionPlate = true;

                        for (int k = 0; k < 2; k++)
                        {
                            TSM.ContourPlate plate = PlateFirst(width, heigth, offset);
                            if (positionPlate)
                            {
                                plate.Position.Depth = TSM.Position.DepthEnum.BEHIND;
                                positionPlate        = false;
                            }
                            else
                            {
                                plate.Position.Depth = TSM.Position.DepthEnum.FRONT;
                            }
                            plate.Insert();
                            listPlates.Add(plate);
                        }

                        TSM.ContourPlate plate1 = listPlates[0] as TSM.ContourPlate;
                        TSM.ContourPlate plate2 = listPlates[1] as TSM.ContourPlate;

                        BoltPlatetoPlate(plate1, plate2, heigth, width);

                        WeldBeamToPlate(beam1, plate1);
                        WeldBeamToPlate(beam2, plate2);

                        planeHandler.SetCurrentTransformationPlane(original);

                        this.model.CommitChanges();
                        listPlates.Clear();
                    }

                    this.model.CommitChanges();

                    listBeams.Clear();
                }
                else
                {
                    MessageBox.Show(Tekla.Structures.Dialog.UIControls.LocalizeForm.Localization.GetText("albl_Invalid_input_parts"));//translation of text in message box
                }
            }
            catch
            {
            }
        }
Esempio n. 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            ModelObjectSelector mos = new ModelObjectSelector();

            TSM.ModelObjectEnumerator moe = mos.GetSelectedObjects();

            moe.SelectInstances = false;

            while (moe.MoveNext())
            {
                if (moe.Current is TSM.Part)
                {
                    TSM.Part part = moe.Current as TSM.Part;

                    // this method needs to be called to properly fill all the properties of the part
                    part.Select();

                    double partLength = 0.0;
                    double partHeight = 0.0;
                    double partWidth  = 0.0;
                    part.GetReportProperty("LENGTH", ref partLength);
                    part.GetReportProperty("HEIGHT", ref partHeight);
                    part.GetReportProperty("WIDTH", ref partWidth);

                    TSM.ModelObjectEnumerator MyAllBooleans = part.GetBooleans();
                    TSM.ModelObjectEnumerator MyAllBolts    = part.GetBolts();
                    TSM.ModelObject           MyFather      = part.GetFatherComponent();


                    TSG.CoordinateSystem coordinateSystem = part.GetCoordinateSystem();
                    TSM.WorkPlaneHandler planeHandler     = model.GetWorkPlaneHandler();

                    // before we create a new plane we need to store the old one
                    TSM.TransformationPlane original  = planeHandler.GetCurrentTransformationPlane();
                    TSM.TransformationPlane partPlane = new TSM.TransformationPlane(coordinateSystem);
                    planeHandler.SetCurrentTransformationPlane(partPlane);

                    //this.DrawCoordinateSystem();

                    TSG.Point p1 = new TSG.Point(0, partHeight / 2, 0);
                    TSG.Point p2 = new TSG.Point(partLength, partHeight / 2, 0);
                    TSG.Point p3 = new TSG.Point(partLength, -partHeight / 2, 0);
                    TSG.Point p4 = new TSG.Point(0, -partHeight / 2, 0);

                    TSM.ContourPlate CP            = new TSM.ContourPlate();
                    TSM.ContourPoint conturePoint1 = new TSM.ContourPoint(p1, null);
                    TSM.ContourPoint conturePoint2 = new TSM.ContourPoint(p2, null);
                    TSM.ContourPoint conturePoint3 = new TSM.ContourPoint(p3, null);
                    TSM.ContourPoint conturePoint4 = new TSM.ContourPoint(p4, null);

                    CP.AddContourPoint(conturePoint1);
                    CP.AddContourPoint(conturePoint2);
                    CP.AddContourPoint(conturePoint3);
                    CP.AddContourPoint(conturePoint4);
                    CP.Name   = "NEM";
                    CP.Finish = "xxx";
                    CP.Profile.ProfileString   = "PL" + partWidth;
                    CP.Material.MaterialString = "S235";
                    CP.Class = "1";

                    CP.Insert();

                    while (MyAllBooleans.MoveNext())
                    {
                        try
                        {
                            TSM.BooleanPart partBooleans = MyAllBooleans.Current as TSM.BooleanPart;

                            TSM.Part partBool = partBooleans.OperativePart as TSM.Part;
                            partBool.Class = TSM.BooleanPart.BooleanOperativeClassName;
                            partBool.Insert();

                            TSM.BooleanPart myboolpart = new TSM.BooleanPart();
                            myboolpart.Father = CP;
                            myboolpart.SetOperativePart(partBool);
                            myboolpart.Insert();
                            partBool.Delete();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }


                    while (MyAllBolts.MoveNext())
                    {
                        try
                        {
                            if (MyAllBolts.Current is TSM.BoltGroup)
                            {
                                TSM.BoltGroup b = MyAllBolts.Current as TSM.BoltGroup;

                                TSM.Part toBolted = b.PartToBeBolted as TSM.Part;
                                TSM.Part toBolt   = b.PartToBoltTo as TSM.Part;
                                if (toBolted.Identifier.ID == toBolt.Identifier.ID)
                                {
                                    b.PartToBeBolted = CP;
                                    b.PartToBoltTo   = CP;
                                }
                                else if (toBolted.Identifier.ID == part.Identifier.ID)
                                {
                                    b.PartToBoltTo.GetBolts();
                                    b.PartToBeBolted = CP;
                                }
                                else
                                {
                                    b.PartToBoltTo = CP;
                                    b.PartToBeBolted.GetBolts();
                                }
                                b.Insert();
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }

                    if (MyFather != null)
                    {
                        TSM.ModelObjectEnumerator elementOfComponenet = MyFather.GetChildren();
                        while (elementOfComponenet.MoveNext())
                        {
                            TSM.Part element = elementOfComponenet.Current as TSM.Part;
                            try
                            {
                                if (element is TSM.Part)
                                {
                                    if (element.Identifier.ID == part.Identifier.ID)
                                    {
                                        element = CP;

                                        element.Modify();
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }



                    part.Delete();
                    planeHandler.SetCurrentTransformationPlane(original);
                }
            }

            this.model.CommitChanges();
        }