示例#1
0
        public static Section CreateSection(Brep brp, Plane pln)
        {
            var    sec = new Section();
            string id  = "P101";

            var tx = Transform.ChangeBasis(Plane.WorldYZ, Util.SofiSectionBasePlane) * Transform.ChangeBasis(Plane.WorldXY, pln);

            int pointIndex = 0;

            foreach (var lp in brp.Loops)
            {
                var crv = lp.To3dCurve();

                crv.Transform(tx);

                var polyLine = Util.CreatePolyLine(crv);
                if (polyLine != null)
                {
                    var secLp = new SectionLoop();
                    secLp.Type = lp.LoopType == BrepLoopType.Outer ? SectionLoopType.Outer : SectionLoopType.Inner;
                    int firstIndex = -1;
                    int i          = 0;
                    foreach (var pt in polyLine)
                    {
                        if (i < polyLine.Count - 1)
                        {
                            var secPt = new SectionPoint()
                            {
                                Id    = id,
                                EType = EdgeTransitionType.Fillet,
                                EdgeTransitionValue1 = 0.0,
                                EdgeTransitionValue2 = 0.0,
                                Y = pt.Y,
                                Z = pt.Z,
                            };
                            id = Util.CountStringUp(id);

                            if (i++ == 0)
                            {
                                firstIndex = pointIndex;
                            }
                            secLp.Add(pointIndex++);
                            sec.Points.Add(secPt);
                        }
                    }
                    if (firstIndex > -1)
                    {
                        secLp.Add(firstIndex);
                    }
                    sec.Loops.Add(secLp);
                }
            }

            return(sec);
        }
示例#2
0
        public SectionLoop Duplicate()
        {
            var res = new SectionLoop()
            {
                Type              = Type,
                MaterialId        = MaterialId,
                ConstructionStage = ConstructionStage,
            };

            foreach (var i in this)
            {
                res.Add(i);
            }
            return(res);
        }
示例#3
0
        private PolyCurve GetPolyCurve(SectionLoop loop)
        {
            var curve = new PolyCurve();

            if (loop.Count < 2)
            {
                return(curve);
            }

            var lines    = new List <Line>();
            var fillets  = new Dictionary <int, NurbsCurve>();
            var chamfers = new Dictionary <int, Line>();

            // create lines
            Point3d p1 = new Point3d(0.0, Points[loop[0]].Y, Points[loop[0]].Z);

            for (int i = 1; i < loop.Count; ++i)
            {
                Point3d p2 = new Point3d(0.0, Points[loop[i]].Y, Points[loop[i]].Z);

                lines.Add(new Line(p1, p2));
                p1 = p2;
            }

            // create Edge Transitions
            for (int i = 0; i < lines.Count; ++i)
            {
                var pt = Points[loop[i]];

                // create EdgeTransition
                if ((pt.EType == EdgeTransitionType.Fillet && pt.EdgeTransitionValue1 > 1.0E-6) || (pt.EType == EdgeTransitionType.Chamfer && pt.EdgeTransitionValue1 > 1.0E-6 && pt.EdgeTransitionValue2 > 1.0E-6))
                {
                    var l1 = i == 0 ? lines.Last() : lines[i - 1];
                    var l2 = lines[i];
                    if (l1.Length > 1.0E-6 && l2.Length > 1.0E-6)
                    {
                        bool writeBackLines = false;
                        if (pt.EType == EdgeTransitionType.Fillet)
                        {
                            var arc = CreateTrimFillet(pt.EdgeTransitionValue1, ref l1, ref l2);
                            if (arc.Radius > 1.0E-3)
                            {
                                fillets.Add(i, arc.ToNurbsCurve());
                                writeBackLines = true;
                            }
                        }
                        if (pt.EType == EdgeTransitionType.Chamfer)
                        {
                            var chamfer = CreateTrimChamfer(pt.EdgeTransitionValue1, pt.EdgeTransitionValue2, ref l1, ref l2);
                            if (chamfer.Length > 1.0E-6)
                            {
                                chamfers.Add(i, chamfer);
                                writeBackLines = true;
                            }
                        }
                        if (writeBackLines)
                        {
                            lines[i] = l2;
                            if (i == 0)
                            {
                                lines[lines.Count - 1] = l1;
                            }
                            else
                            {
                                lines[i - 1] = l1;
                            }
                        }
                    }
                }
            }

            // create polycurve
            for (int i = 0; i < lines.Count; ++i)
            {
                if (fillets.TryGetValue(i, out var fillet))
                {
                    curve.Append(fillet);
                }
                if (chamfers.TryGetValue(i, out var chamfer))
                {
                    curve.Append(chamfer);
                }
                if (i < lines.Count - 1 && lines[i].Length > 1.0E-6)
                {
                    curve.Append(lines[i]);
                }
            }
            if (curve.PointAtStart.DistanceTo(curve.PointAtEnd) > 1.0E-6)
            {
                curve.Append(new Line(curve.PointAtEnd, curve.PointAtStart));
            }

            return(curve);
        }