Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        void _AddBSplineCurve(Geom2d_BSplineCurve bspline, double first, double last)
        {
            // Cut spline
            bspline = Geom2dConvert.SplitBSplineCurve(bspline, first, last, 0.00001);

            if (_Document.Flags.HasFlag(DxfFlags.ExportSplineAsPolygon))
            {
                _AddPolygonCurve(bspline);
                return;
            }

            if (bspline.Degree() > 3)
            {
                // Try to reduce the order of the curve
                var continuity = bspline.Continuity();
                if (continuity != GeomAbs_Shape.GeomAbs_C0)
                {
                    continuity = GeomAbs_Shape.GeomAbs_C1;
                }

                var converter = new Geom2dConvert_ApproxCurve(bspline, _Precision * 10.0, continuity, 100, 3);
                if (!(converter.IsDone() && converter.HasResult()))
                {
                    Messages.Warning("DxfExporter: BSpline curve has an undecreasable degree of " + bspline.Degree() + ".");
                    return;
                }

                bspline = converter.Curve();
            }

            var knotSource  = bspline.KnotSequence();
            var knots       = new double[knotSource.Length()];
            int sourceStart = knotSource.Lower();

            for (int i = 0; i < knots.Length; i++)
            {
                knots[i] = knotSource.Value(sourceStart + i);
            }

            var points  = new Pnt2d[bspline.NbPoles()];
            var weights = new double[points.Length];

            for (int i = 0; i < bspline.NbPoles(); i++)
            {
                points[i]  = bspline.Pole(i + 1);
                weights[i] = bspline.Weight(i + 1);
            }

            var flags = DxfDomSpline.SplineFlags.None;

            if (bspline.IsRational())
            {
                flags = flags.Added(DxfDomSpline.SplineFlags.IsRational);
            }

            var entity = new DxfDomSpline(_CurrentLayer, bspline.Degree(), knots, points, weights, flags);

            _Document.Entities.Add(entity);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        public static bool RenderBSplineCurve(IDrawingRenderer renderer, Geom2d_BSplineCurve bspline, double first, double last, bool reverse)
        {
            if (renderer.Capabilities.BSplineCurveMaxDegree > 0)
            {
                bspline = Geom2dConvert.SplitBSplineCurve(bspline, first, last, 0.00001);

                if (bspline.Degree() > renderer.Capabilities.BSplineCurveMaxDegree)
                {
                    // Try to reduce the order of the curve
                    var continuity = bspline.Continuity();
                    if (continuity != GeomAbs_Shape.GeomAbs_C0)
                    {
                        continuity = GeomAbs_Shape.GeomAbs_C1;
                    }

                    var converter = new Geom2dConvert_ApproxCurve(bspline, 0.0001, continuity, 100, 3);
                    if (!(converter.IsDone() && converter.HasResult()))
                    {
                        Messages.Warning("BrepRenderHelper: BSpline curve has an undecreasable degree of " + bspline.Degree() + ".");
                        return(false);
                    }

                    bspline = converter.Curve();
                }

                var knotSource  = bspline.KnotSequence();
                var knots       = new double[knotSource.Length()];
                int sourceStart = knotSource.Lower();
                for (int i = 0; i < knots.Length; i++)
                {
                    knots[i] = knotSource.Value(sourceStart + i);
                }

                var points  = new Pnt2d[bspline.NbPoles()];
                var weights = new double[points.Length];
                for (int i = 0; i < bspline.NbPoles(); i++)
                {
                    points[i]  = bspline.Pole(i + 1);
                    weights[i] = bspline.Weight(i + 1);
                }

                renderer.BSplineCurve(bspline.Degree(), knots, points, weights, bspline.IsRational());
                return(true);
            }
            else
            {
                // Cannot render BSpline, Try bezier
                var  converter = new Geom2dConvert_BSplineCurveToBezierCurve(bspline, first, last, 0.001 /*Precision.PConfusion() * 10*/);
                bool result    = true;

                if (reverse)
                {
                    for (int i = converter.NbArcs(); i >= 1; i -= 1)
                    {
                        var arc = converter.Arc(i);
                        result &= RenderBezierCurve(renderer, arc, arc.FirstParameter(), arc.LastParameter(), true);
                    }
                }
                else
                {
                    for (int i = 1; i <= converter.NbArcs(); i += 1)
                    {
                        var arc = converter.Arc(i);
                        result &= RenderBezierCurve(renderer, arc, arc.FirstParameter(), arc.LastParameter(), false);
                    }
                }

                return(result);
            }
        }