GeometryGym.Ifc.IfcIndexedPolyCurve.Convert C# (CSharp) Méthode

Convert() static private méthode

static private Convert ( DatabaseIfc db, PolyCurve polycurve, bool twoD ) : IfcIndexedPolyCurve
db DatabaseIfc
polycurve PolyCurve
twoD bool
Résultat IfcIndexedPolyCurve
        internal static IfcIndexedPolyCurve Convert(DatabaseIfc db, PolyCurve polycurve, bool twoD)
        {
            double tol = db.Tolerance;
            Curve[] segments = polycurve.Explode();
            PolyCurve pc = new PolyCurve();
            foreach (Curve s in segments)
            {
                if (s.IsLinear(tol))
                    pc.Append(new Line(s.PointAtStart, s.PointAtEnd));
                else
                {
                    Arc a = Arc.Unset;
                    if (s.TryGetArc(out a, tol))
                        pc.Append(a);
                    else
                        return null;
                }
            }
            List<IfcSegmentIndexSelect> segs = new List<IfcSegmentIndexSelect>();
            IfcCartesianPointList cpl = null;
            bool closed = pc.PointAtStart.DistanceTo(pc.PointAtEnd) < tol;
            if (twoD)
            {
                Point2d pt = new Point2d(pc.PointAtStart.X, pc.PointAtStart.Y);
                int pcounter = 1;
                List<Point2d> pts = new List<Point2d>();
                pts.Add(pt);
                IfcLineIndex li = null;
                for (int icounter = 0; icounter < pc.SegmentCount; icounter++)
                {
                    Curve c = pc.SegmentCurve(icounter);
                    if (c.IsLinear(tol) && c.PointAtStart.DistanceTo(c.PointAtEnd) < tol)
                        continue;
                    if (c.IsLinear(tol))
                    {
                        if (closed && icounter + 1 == segments.Length)
                        {
                            if (li != null)
                                li.mIndices.Add(1);
                            else
                                li = new IfcLineIndex(pcounter, 1);
                        }
                        else
                        {
                            pts.Add(new Point2d(c.PointAtEnd.X, c.PointAtEnd.Y));
                            if (li != null)
                                li.mIndices.Add(++pcounter);
                            else
                                li = new IfcLineIndex(pcounter++, pcounter);
                        }
                    }
                    else
                    {
                        if (li != null)
                        {
                            segs.Add(li);
                            li = null;
                        }
                        Point3d tp = c.PointAt(c.Domain.Mid);
                        pts.Add(new Point2d(tp.X, tp.Y));
                        if (closed && icounter + 1 == segments.Length)
                            segs.Add(new IfcArcIndex(pcounter++, pcounter++, 1));
                        else
                        {
                            pts.Add(new Point2d(c.PointAtEnd.X, c.PointAtEnd.Y));
                            segs.Add(new IfcArcIndex(pcounter++, pcounter++, pcounter));
                        }
                    }
                }
                if (li != null)
                    segs.Add(li);
                cpl = new IfcCartesianPointList2D(db, pts.ToArray());
            }
            else
            {
                Point3d pt = pc.PointAtStart;
                int pcounter = 1;
                List<Point3d> pts = new List<Point3d>();
                pts.Add(pt);
                List<IfcSegmentIndexSelect> sis = new List<IfcSegmentIndexSelect>(segments.Length);
                IfcLineIndex li = null;
                for (int icounter = 0; icounter < pc.SegmentCount; icounter++)
                {
                    Curve c = pc.SegmentCurve(icounter);
                    if (c.IsLinear(tol) && c.PointAtStart.DistanceTo(c.PointAtEnd) < tol)
                        continue;
                    if (c.IsLinear(tol))
                    {
                        if (closed && icounter + 1 == segments.Length)
                        {
                            if (li != null)
                                li.mIndices.Add(0);
                            else
                                li = new IfcLineIndex(pcounter, 0);
                        }
                        else
                        {
                            pts.Add(c.PointAtEnd);
                            if (li != null)
                                li.mIndices.Add(++pcounter);
                            else
                                li = new IfcLineIndex(pcounter++, pcounter);
                        }
                    }
                    else
                    {
                        if (li != null)
                        {
                            segs.Add(li);
                            li = null;
                        }
                        pts.Add(c.PointAt(c.Domain.Mid));
                        if (closed && icounter + 1 == segments.Length)
                            segs.Add(new IfcArcIndex(pcounter++, pcounter, 0));
                        else
                        {
                            pts.Add(c.PointAtEnd);
                            segs.Add(new IfcArcIndex(pcounter++, pcounter++, pcounter));
                        }
                    }
                }
                if (li != null)
                    segs.Add(li);
                cpl = new IfcCartesianPointList3D(db, pts.ToArray());
            }
            return new IfcIndexedPolyCurve(cpl, segs) { };
        }

Usage Example

Exemple #1
0
        internal static IfcBoundedCurve convCurve(DatabaseIfc db, Curve crv, IfcCartesianPoint optStrt, bool twoD, out IfcCartesianPoint end)
        {
            double tol = db.Tolerance;

            end = null;
            Curve c = crv.DuplicateCurve();

            if (c.IsLinear(tol))
            {
                if (twoD)
                {
                    end = new IfcCartesianPoint(db, new Point2d(c.PointAtEnd.X, c.PointAtEnd.Y));
                }
                else
                {
                    end = new IfcCartesianPoint(db, c.PointAtEnd);
                }
                if (optStrt == null)
                {
                    if (twoD)
                    {
                        optStrt = new IfcCartesianPoint(db, new Point2d(c.PointAtStart.X, c.PointAtStart.Y));
                    }
                    else
                    {
                        optStrt = new IfcCartesianPoint(db, c.PointAtStart);
                    }
                }
                return(new IfcPolyline(optStrt, end));
            }
            ArcCurve ac = c as ArcCurve;

            if (ac != null)
            {
                return(new IfcTrimmedCurve(db, ac.Arc, twoD, optStrt, out end));
            }
            Arc arc = Arc.Unset;

            if (c.TryGetArc(out arc, tol))
            {
                return(new IfcTrimmedCurve(db, arc, twoD, optStrt, out end));
            }

            Polyline pl = new Polyline();

            if (c.TryGetPolyline(out pl))
            {
                if (db.mRelease != ReleaseVersion.IFC2x3 && db.mRelease != ReleaseVersion.IFC4)
                {
                    if (twoD)
                    {
                        return(new IfcIndexedPolyCurve(new IfcCartesianPointList2D(db, pl.ConvertAll(x => new Point2d(x.X, x.Y)))));
                    }
                    else
                    {
                        return(new IfcIndexedPolyCurve(new IfcCartesianPointList3D(db, pl)));
                    }
                }
                List <IfcCartesianPoint> cps = new List <IfcCartesianPoint>();
                if (twoD)
                {
                    Point2d p = new Point2d(pl[0].X, pl[0].Y), n;
                    cps.Add(new IfcCartesianPoint(db, p));
                    for (int icounter = 1; icounter < pl.Count - 1; icounter++)
                    {
                        n = new Point2d(pl[icounter].X, pl[icounter].Y);
                        if (n.DistanceTo(p) > tol)
                        {
                            cps.Add(new IfcCartesianPoint(db, n));
                            p = n;
                        }
                    }
                    n = new Point2d(pl[pl.Count - 1].X, pl[pl.Count - 1].Y);
                    if (n.DistanceTo(p) > tol)
                    {
                        if (pl.IsClosed)
                        {
                            cps.Add(cps[0]);
                        }
                        else
                        {
                            cps.Add(new IfcCartesianPoint(db, n));
                        }
                    }
                }
                else
                {
                    Point3d p = pl[0], n;
                    cps.Add(new IfcCartesianPoint(db, p));
                    for (int icounter = 1; icounter < pl.Count; icounter++)
                    {
                        n = pl[icounter];
                        if (n.DistanceTo(p) > tol)
                        {
                            cps.Add(new IfcCartesianPoint(db, n));
                            p = n;
                        }
                    }
                }
                return(new IfcPolyline(cps));
            }
            PolyCurve plc = c as PolyCurve;

            if (plc != null)
            {
                if (db.mRelease != ReleaseVersion.IFC2x3 && db.mRelease != ReleaseVersion.IFC4)
                {
                    IfcIndexedPolyCurve ipc = IfcIndexedPolyCurve.Convert(db, plc, twoD);
                    if (ipc != null)
                    {
                        return(ipc);
                    }
                }
                return(new IfcCompositeCurve(db, plc, twoD));
            }
            if (db.mRelease != ReleaseVersion.IFC2x3)
            {
                NurbsCurve nc = c as NurbsCurve;
                if (nc != null)
                {
                    if (nc.IsRational)
                    {
                        return(new IfcRationalBSplineCurveWithKnots(db, nc, twoD));
                    }
                    return(new IfcBSplineCurveWithKnots(db, nc, twoD));
                }
            }

            return(null);
        }