public static bool SolidToSolidIntersect(Part part1, Part part2)
        {
            double originalVolume = 0.0;

            part1.GetReportProperty("VOLUME_NET", ref originalVolume);

            var cuttingPart = new BooleanPart
            {
                Father = part1
            };

            part2.Class = BooleanPart.BooleanOperativeClassName;
            cuttingPart.SetOperativePart(part2);
            cuttingPart.Insert();

            double volumeAfterCut = 0.0;

            part1.GetReportProperty("VOLUME_NET", ref volumeAfterCut);

            cuttingPart.Delete();

            if (originalVolume > volumeAfterCut)
            {
                Tracer._trace("volume change");
                return(true);
            }

            return(false);
        }
        public Beam CutBeamByPart(Beam beam, Part part, bool startSideCut = true)
        {
            // вырезаем ThasBeam по MainBeam
            var         partClass = part.Class;
            BooleanPart Beam      = new BooleanPart();

            Beam.Father = beam;
            part.Class  = BooleanPart.BooleanOperativeClassName;
            Beam.SetOperativePart(part);
            Beam.Insert();
            part.Class = partClass;
            part.Modify();

            // создаем режущую плоскость, чтобы отбросить
            //..(левую) часть ThisBeam по плоскости MainBeam
            CutPlane BeamLineCut = new CutPlane();

            BeamLineCut.Father = beam;
            Plane BeamCutPlane = new Plane();
            var   cs           = part.GetCoordinateSystem();

            if (startSideCut)
            {
                cs.AxisX *= -1;
            }
            BeamCutPlane.AxisX  = cs.AxisX;
            BeamCutPlane.AxisY  = cs.AxisY;
            BeamCutPlane.Origin = cs.Origin;
            BeamLineCut.Plane   = BeamCutPlane;
            BeamLineCut.Insert();

            Model.CommitChanges();

            return(beam);
        }
        /*
         * public static ContourPlate CreateCuttingPart(string profileString, string mate)
         * {
         *  var plate = new ContourPlate();
         *
         *  //var myProfileString = "PL" + (thickness).ToString("F2");
         *
         *  string sysProfileString = null;
         *
         *  ProfileConversion.ConvertFromCurrentUnits(profileString, ref sysProfileString);
         *  plate.Profile.ProfileString = sysProfileString;
         *  plate.Material.MaterialString = "ANTIMATERIAL";
         *  plate.Class = BooleanPart.BooleanOperativeClassName;
         *  plate.Name = "CUTPART";
         *  plate.PartNumber.Prefix = "0";
         *  plate.PartNumber.StartNumber = 0;
         *  plate.AssemblyNumber.Prefix = " ";
         *  plate.AssemblyNumber.StartNumber = 0;
         *
         *  plate.Position.Depth = Position.DepthEnum.BEHIND;
         *  plate.Position.Plane = Position.PlaneEnum.MIDDLE;
         *  plate.Position.PlaneOffset = 0;
         *  plate.Position.Rotation = Position.RotationEnum.FRONT;
         *  plate.Position.RotationOffset = 0.0;
         *
         *  return plate;
         * }
         */

        private void TryApplyCuts(Part part, List <Tuple <AABB, Part> > cutSolids)
        {
            if (null == cutSolids)
            {
                return;
            }

            var partBox = part.GetAABB();

            // check collision
            foreach (var cutObjects in cutSolids)
            {
                var aabb          = cutObjects.Item1;
                var operativePart = cutObjects.Item2;
                if (!GeometryUtils.testAABBAABB(aabb, partBox))
                {
                    continue;
                }

                BooleanPart Beam = new BooleanPart();
                Beam.Father = part;
                Beam.SetOperativePart(operativePart);
                if (!Beam.Insert())
                {
                    Tracer._trace("Insert failed!");
                }
                //Tracer._trace($"Cut solid: {part.Name}.");
            }
        }
        private void TryApplyCuts(Part part, List <Part> cutContours)
        {
            foreach (var cutObject in cutContours)
            {
                cutObject.Insert();
                if (SolidToSolidIntersect(part, cutObject))
                {
                    var plate = new BooleanPart {
                        Father = part
                    };
                    plate.SetOperativePart(cutObject);
                    if (!plate.Insert())
                    {
                        Tracer._trace("Insert failed!");
                    }

                    Tracer._trace($"Cut contour: {part.Profile.ProfileString}.");
                }
                cutObject.Delete();
            }
        }
        internal static ModelObject GetBooleanPart()
        {
            var beam        = GetBeam();
            var cuttingPart = new Beam()
            {
                StartPoint = new Point(5500, 6000, 0),
                EndPoint   = new Point(5500, 8000, 0),
                Class      = BooleanPart.BooleanOperativeClassName,
            };

            cuttingPart.Profile.ProfileString = "100*100";
            cuttingPart.Insert();

            var cut = new BooleanPart();

            cut.Father = beam;
            cut.SetOperativePart(cuttingPart);
            cut.Insert();
            cuttingPart.Delete();
            return(cut);
        }
Exemple #6
0
        /// <summary>
        /// Adds the cut for the wallshoe components
        /// </summary>
        /// <param name="variables">List of doubles with dimensions of the component</param>
        /// <param name="p1">The point which gives the x position of the component on fatherpart</param>
        /// <param name="minY">Fatherparts solids miminum Y position</param>
        /// <param name="maxY">Fatherparts solids miminum Y position</param>
        /// <param name="changeDirection">Boolean to give the direction</param>
        /// <param name="fatherpart">Part to insert the cut to</param>
        private bool AddWallShoeCut(double[] variables, Point p1, double minY, double maxY, bool changeDirection, Part fatherpart)
        {
            try {
                ContourPlate cutpart = new ContourPlate();
                BooleanPart  bPart   = new BooleanPart();
                cutpart.Name                    = "Leikkaus";
                cutpart.Position.Depth          = Position.DepthEnum.MIDDLE;
                cutpart.Position.Plane          = Position.PlaneEnum.MIDDLE;
                cutpart.Class                   = BooleanPart.BooleanOperativeClassName;
                cutpart.Material.MaterialString = "Reikä";
                cutpart.Profile.ProfileString   = "PL135";
                cutpart.Profile.ProfileString   = "PL" + variables[4];
                if (!changeDirection)
                {
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - variables[0], p1.Z + variables[1]), null));
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - variables[0], p1.Z + variables[1] + variables[2]), null));
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1] + variables[2] + (Math.Tan(variables[3] * Math.PI / 180) * ((maxY - minY) / 2 + variables[0]))), null));
                }
                else
                {
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y + variables[0], p1.Z + variables[1]), null));
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y + variables[0], p1.Z + variables[1] + variables[2]), null));
                    cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1] + variables[2] + (Math.Tan(variables[3] * Math.PI / 180) * ((minY - maxY) / 2 + variables[0]))), null));
                }
                cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1]), null));
                cutpart.Insert();
                bPart.Father = fatherpart;
                bPart.SetOperativePart(cutpart);
                if (!bPart.Insert())
                {
                    WriteLog("Leikkauksen (1) tekeminen epäonnistui!");
                }
                cutpart.Delete();
            } catch (Exception ex) {
                WriteLog(ex.Message + "\n" + ex.StackTrace);
                return(false);
            }

            return(true);
        }
        public static ContourPlate InsertCutPlate(ContourPlate cuttedPlate, ArrayList points,
                                                  string profileString, string materialString, Chamfer chamfer = null)
        {
            var cp = new ContourPlate();

            foreach (Point point in points)
            {
                cp.AddContourPoint(point, chamfer);
            }
            cp.Profile.ProfileString   = profileString;
            cp.Material.MaterialString = materialString;
            cp.Class = BooleanPart.BooleanOperativeClassName;
            cp.Insert();
            var bp = new BooleanPart {
                Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = cuttedPlate
            };

            bp.SetOperativePart(cp);
            bp.Insert();
            cp.Delete();
            return(cp);
        }
Exemple #8
0
        private void InsertComponents(ModelObject mObj, List <TSM.Component> components)
        {
            TransformationPlane originalTransformationplane = null;

            try {
                lock (wHandler) {
                    originalTransformationplane = wHandler.GetCurrentTransformationPlane();
                }
                ComponentInput compInput  = new ComponentInput();
                Part           fatherpart = mObj as Part;
                Assembly       assembly   = fatherpart.GetAssembly();

                // Get the transformationplane from objects coordinate systems vectors and because objects coordinate system is not the same XY plane as of models,
                // so cross product needs to be made for the Y-axis
                TransformationPlane fatherpartsTransformationPlane = new TransformationPlane(fatherpart.GetCoordinateSystem().Origin, fatherpart.GetCoordinateSystem().AxisX, Vector.Cross(fatherpart.GetCoordinateSystem().AxisY, fatherpart.GetCoordinateSystem().AxisX));
                lock (wHandler) {
                    wHandler.SetCurrentTransformationPlane(fatherpartsTransformationPlane);
                }
                double         minX  = fatherpart.GetSolid().MinimumPoint.X;
                double         minY  = fatherpart.GetSolid().MinimumPoint.Y;
                double         minZ  = fatherpart.GetSolid().MinimumPoint.Z;
                double         maxX  = fatherpart.GetSolid().MaximumPoint.X;
                double         maxY  = fatherpart.GetSolid().MaximumPoint.Y;
                double         maxZ  = fatherpart.GetSolid().MaximumPoint.Z;
                Solid          s     = fatherpart.GetSolid();
                FaceEnumerator fEnum = s.GetFaceEnumerator();
                StringBuilder  sb    = new StringBuilder();
                while (fEnum.MoveNext())
                {
                    sb.AppendLine(fEnum.Current.Normal.ToString());
                }
                Point        p1            = null;
                Point        p2            = null;
                List <Point> cutPartPoints = new List <Point>()
                {
                    new Point(),
                    new Point(),
                    new Point(),
                    new Point()
                };
                ContourPlate cutpart = null;

                for (int i = 0; i < components.Count; i++)
                {
                    cutpart                         = new ContourPlate();
                    cutpart.Name                    = "Leikkaus";
                    cutpart.Position.Depth          = Position.DepthEnum.MIDDLE;
                    cutpart.Position.Plane          = Position.PlaneEnum.MIDDLE;
                    cutpart.Class                   = BooleanPart.BooleanOperativeClassName;
                    cutpart.Material.MaterialString = "Reikä";
                    cutpart.Profile.ProfileString   = "PL135";
                    BooleanPart bPart = new BooleanPart();
                    compInput = new ComponentInput();
                    switch (i)
                    {
                    case 0:
                        p1 = new Point(minX + 300, 0, minZ);
                        p2 = new Point(minX + 300, maxY, minZ);
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 40), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 161.68), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 161.68 + (Math.Tan(9.88 * Math.PI / 180) * ((maxY - minY) / 2 + 52))), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 40), null));
                        cutpart.Insert();
                        bPart.Father = fatherpart;
                        bPart.SetOperativePart(cutpart);
                        if (!bPart.Insert())
                        {
                            SetInfoText("Leikkauksen (1) tekeminen epäonnistui!");
                        }
                        cutpart.Delete();
                        break;

                    case 1:
                        p1 = new Point(maxX - 300, 0, minZ);
                        p2 = new Point(maxX - 300, maxY, minZ);
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 40), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 161.68), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 161.68 + (Math.Tan(9.88 * Math.PI / 180) * ((maxY - minY) / 2 + 52))), null));
                        cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 40), null));
                        cutpart.Insert();
                        bPart.Father = fatherpart;
                        bPart.SetOperativePart(cutpart);
                        if (!bPart.Insert())
                        {
                            SetInfoText("Leikkauksen (2) tekeminen epäonnistui!");
                        }
                        cutpart.Delete();
                        break;

                    case 2:
                        p1 = new Point(minX + 300, 0, maxZ + 135);
                        p2 = new Point(minX + 300, maxY, maxZ + 135);
                        break;

                    case 3:
                        p1 = new Point(maxX - 300, 0, maxZ + 135);
                        p2 = new Point(maxX - 300, maxY, maxZ + 135);
                        break;
                    }
                    compInput.AddOneInputPosition(p1);
                    compInput.AddOneInputPosition(p2);
                    components[i].SetComponentInput(compInput);
                    if (!components[i].Insert())
                    {
                        SetInfoText("Komponentin laittaminen epäonnistui!");
                    }
                }
                foreach (TSM.Component c in components)
                {
                    assembly.Add(c);
                    assembly.Modify();
                }
            } catch (Exception ex) {
                ExceptionOccured(ex.Message, ex.StackTrace);
                SetInfoText("Komponentin asettamisessa tapahtui virhe!");
            } finally {
                lock (wHandler) {
                    wHandler.SetCurrentTransformationPlane(originalTransformationplane);
                }
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var model = new Model();

            if (model.GetConnectionStatus())
            {
                Console.WriteLine("You can start writting your Tekla project");

                //insert fence handles
                var beamHandle1 = new Beam()
                {
                    StartPoint = new Point(0.0, 0.0, 3000.0),
                    EndPoint   = new Point(36000.0, 0.0, 3000.0),
                    Profile    = new Profile {
                        ProfileString = "RHS200*5"
                    }
                };
                beamHandle1.Insert();
                var beamHandle2 = new Beam()
                {
                    StartPoint = new Point(0.0, 0.0, 3000.0),
                    EndPoint   = new Point(0.0, 30000.0, 3000.0),
                    Profile    = new Profile {
                        ProfileString = "RHS200*5"
                    }
                };
                beamHandle2.Insert();
                var beamHandle3 = new Beam()
                {
                    StartPoint = new Point(36000.0, 0.0, 3000.0),
                    EndPoint   = new Point(36000.0, 30000.0, 3000.0),
                    Profile    = new Profile {
                        ProfileString = "RHS200*5"
                    }
                };
                beamHandle3.Insert();
                var beamHandle4 = new Beam()
                {
                    StartPoint = new Point(0.0, 30000.0, 3000.0),
                    EndPoint   = new Point(36000.0, 30000.0, 3000.0),
                    Profile    = new Profile {
                        ProfileString = "RHS200*5"
                    }
                };
                beamHandle4.Insert();

                //insert fence columns
                for (int index = 0; index <= 36000; index += 3000)
                {
                    var point  = new Point(index * 1.0, 0.0);
                    var column = AddColumn(point, 3000);
                }
                for (int index = 3000; index <= 30000; index += 3000)
                {
                    var point  = new Point(0.0, index * 1.0);
                    var column = AddColumn(point, 3000);
                }
                for (int index = 3000; index <= 36000; index += 3000)
                {
                    var point  = new Point(index * 1.0, 30000.0);
                    var column = AddColumn(point, 3000);
                }
                for (int index = 3000; index <= 27000; index += 3000)
                {
                    var point  = new Point(36000.0, index * 1.0);
                    var column = AddColumn(point, 3000);
                }

                Console.WriteLine("Give the weight of the house, number between 10 and 34:");
                string val         = Console.ReadLine();
                int    houseWeight = Convert.ToInt32(val);
                Console.WriteLine("Give the height of the house, number between 3 and 10");
                string val1        = Console.ReadLine();
                int    houseHeight = Convert.ToInt32(val1);
                Console.WriteLine("Give the side weight of the house, number between 10 and 28");
                string val2            = Console.ReadLine();
                int    houseSideWeight = Convert.ToInt32(val2);

                //int houseSideWeight = 20;
                //int houseWeight = 25;
                //int houseHeight = 6;
                var frontWall = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, 0),
                    new Point(houseWeight * 1000, 1000, 0),
                    new Point(houseWeight * 1000, 1000, houseHeight * 1000),
                    new Point(1000, 1000, houseHeight * 1000)
                });
                var leftWall = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, 0),
                    new Point(1000, houseSideWeight * 1000, 0),
                    new Point(1000, houseSideWeight * 1000, houseHeight * 1000),
                    new Point(1000, 1000, houseHeight * 1000)
                });
                var rightWall = AddPlate(new List <Point>
                {
                    new Point(houseWeight * 1000, 1000, 0),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, 0),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, houseHeight * 1000),
                    new Point(houseWeight * 1000, 1000, houseHeight * 1000)
                });
                var backWall = AddPlate(new List <Point>
                {
                    new Point(1000, houseSideWeight * 1000, 0),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, 0),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, houseHeight * 1000),
                    new Point(1000, houseSideWeight * 1000, houseHeight * 1000)
                });
                var Floor = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, 0),
                    new Point(houseWeight * 1000, 1000, 0),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, 0),
                    new Point(1000, houseSideWeight * 1000, 0)
                });
                var Roof = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, houseHeight * 1000),
                    new Point(houseWeight * 1000, 1000, houseHeight * 1000),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, houseHeight * 1000),
                    new Point(1000, houseSideWeight * 1000, houseHeight * 1000)
                });
                var leftSideRoof = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, houseHeight * 1000),
                    new Point((houseWeight / 2) * 1000, 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point((houseWeight / 2) * 1000, houseSideWeight * 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point(1000, houseSideWeight * 1000, houseHeight * 1000)
                });
                var RightSideRoof = AddPlate(new List <Point>
                {
                    new Point(houseWeight * 1000, 1000, houseHeight * 1000),
                    new Point((houseWeight / 2) * 1000, 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point((houseWeight / 2) * 1000, houseSideWeight * 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, houseHeight * 1000)
                });
                var frontRoofWall = AddPlate(new List <Point>
                {
                    new Point(1000, 1000, houseHeight * 1000),
                    new Point((houseWeight / 2) * 1000, 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point(houseWeight * 1000, 1000, houseHeight * 1000)
                });
                var backRoofWall = AddPlate(new List <Point>
                {
                    new Point(1000, houseSideWeight * 1000, houseHeight * 1000),
                    new Point((houseWeight / 2) * 1000, houseSideWeight * 1000, (houseHeight + (houseHeight / 2)) * 1000),
                    new Point(houseWeight * 1000, houseSideWeight * 1000, houseHeight * 1000)
                });

                var cutDoor = AddCutPlate(new List <Point>
                {
                    new Point((houseWeight / 2) * 1000 - 1000, 1000, 50),
                    new Point((houseWeight / 2) * 1000 + 1000, 1000, 50),
                    new Point((houseWeight / 2) * 1000 + 1000, 1000, (houseHeight / 2) * 1000),
                    new Point((houseWeight / 2) * 1000 - 1000, 1000, (houseHeight / 2) * 1000)
                });
                var boolPart1 = new BooleanPart {
                    Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = frontWall
                };
                boolPart1.SetOperativePart(cutDoor);
                boolPart1.Insert();
                //cutDoor.Delete();

                var cutBackDoor = AddCutPlate(new List <Point>
                {
                    new Point((houseWeight / 2) * 1000 - 1000, houseSideWeight * 1000, 50),
                    new Point((houseWeight / 2) * 1000 + 1000, houseSideWeight * 1000, 50),
                    new Point((houseWeight / 2) * 1000 + 1000, houseSideWeight * 1000, (houseHeight / 2) * 1000),
                    new Point((houseWeight / 2) * 1000 - 1000, houseSideWeight * 1000, (houseHeight / 2) * 1000)
                });
                var boolPart3 = new BooleanPart {
                    Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = backWall
                };
                boolPart3.SetOperativePart(cutBackDoor);
                boolPart3.Insert();

                var cutLeftWindow = AddCutPlate(new List <Point>
                {
                    new Point(3000, 1000, 2000),
                    new Point(5000, 1000, 2000),
                    new Point(5000, 1000, houseHeight * 1000 - 1000),
                    new Point(3000, 1000, houseHeight * 1000 - 1000)
                });
                var boolPart2 = new BooleanPart {
                    Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = frontWall
                };
                boolPart2.SetOperativePart(cutLeftWindow);
                boolPart2.Insert();
                cutLeftWindow.Delete();

                var cutRightWindow = AddCutPlate(new List <Point>
                {
                    new Point(houseWeight * 1000 - 4000, 1000, 2000),
                    new Point(houseWeight * 1000 - 2000, 1000, 2000),
                    new Point(houseWeight * 1000 - 2000, 1000, houseHeight * 1000 - 1000),
                    new Point(houseWeight * 1000 - 4000, 1000, houseHeight * 1000 - 1000)
                });
                var boolPart4 = new BooleanPart {
                    Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = frontWall
                };
                boolPart4.SetOperativePart(cutRightWindow);
                boolPart4.Insert();
                cutRightWindow.Delete();

                model.CommitChanges();
            }
            else
            {
                Console.WriteLine("Please open Tekla first!");
            }
            Console.ReadLine();
        }