示例#1
0
        //--------------------------------------------------------------------------------------------------

        protected void AddBezierCurve(Geom2d_BezierCurve geom2DBezier, double first, double last, bool reverse)
        {
            if (geom2DBezier.Degree() > 3)
            {
                // Try to reduce the order of the curve
                var continuity = geom2DBezier.Continuity();
                if (continuity != GeomAbs_Shape.GeomAbs_C0)
                {
                    continuity = GeomAbs_Shape.GeomAbs_C1;
                }

                var converter = new Geom2dConvert_ApproxCurve(geom2DBezier, 0.001 /*Precision.Confusion() * 10*/, continuity, 1000, 3);
                if (!(converter.IsDone() && converter.HasResult()))
                {
                    Messages.Warning("SvgExporter: Bezier curve has an undecreasable order of " + geom2DBezier.Degree() + ".");
                    return;
                }
                AddBSplineCurve(converter.Curve(), first, last, reverse);
                return;
            }

            // Create segment, SVG path does not support UV
            geom2DBezier.Segment(first, last);
            Pnt2d c1, c2;
            var   start = reverse ? geom2DBezier.EndPoint() : geom2DBezier.StartPoint();
            var   end   = reverse ? geom2DBezier.StartPoint() : geom2DBezier.EndPoint();

            BoundingBox?.Add(start);
            BoundingBox?.Add(end);

            switch (geom2DBezier.Degree())
            {
            case 1:
                AddToPath(new SvgPathSegLineto(start, end));
                break;

            case 2:
                c1 = geom2DBezier.Pole(2);
                BoundingBox?.Add(c1);
                AddToPath(new SvgPathSegCurvetoQuadratic(start, c1, end));
                break;

            case 3:
                c1 = geom2DBezier.Pole(reverse ? 3 : 2);
                c2 = geom2DBezier.Pole(reverse ? 2 : 3);
                BoundingBox?.Add(c1);
                BoundingBox?.Add(c2);
                AddToPath(new SvgPathSegCurvetoCubic(start, c1, c2, end));
                break;

            default:
                Messages.Warning("SvgExporter: Bezier curve has an unsupported order of " + geom2DBezier.Degree() + ".");
                break;
            }
        }
示例#2
0
        //--------------------------------------------------------------------------------------------------

        void _AddBezierCurve(Geom2d_BezierCurve geom2DBezier, double firstParameter, double lastParameter)
        {
            int p1, p2, p3, p4;

            switch (geom2DBezier.Degree())
            {
            case 1:
                p1 = _AddPoint(geom2DBezier.StartPoint());
                p2 = _AddPoint(geom2DBezier.EndPoint());
                _Segments.Add(new SketchSegmentLine(p1, p2));
                break;

            case 2:
                p1 = _AddPoint(geom2DBezier.StartPoint());
                p2 = _AddPoint(geom2DBezier.Pole(2), false);
                p3 = _AddPoint(geom2DBezier.EndPoint());
                _Segments.Add(new SketchSegmentBezier(p1, p2, p3));
                break;

            case 3:
                p1 = _AddPoint(geom2DBezier.StartPoint());
                p2 = _AddPoint(geom2DBezier.Pole(2), false);
                p3 = _AddPoint(geom2DBezier.Pole(3), false);
                p4 = _AddPoint(geom2DBezier.EndPoint());
                _Segments.Add(new SketchSegmentBezier(p1, p2, p3, p4));
                break;

            default:
                // Try to reduce the order of the curve
                var continuity = geom2DBezier.Continuity();
                if (continuity != GeomAbs_Shape.GeomAbs_C0)
                {
                    continuity = GeomAbs_Shape.GeomAbs_C1;
                }

                var trimmedCurve = new Geom2d_TrimmedCurve(geom2DBezier, firstParameter, lastParameter);

                var converter = new Geom2dConvert_ApproxCurve(trimmedCurve, 0.001 /*Precision.Confusion() * 10*/, continuity, 1000, 3);
                if (!(converter.IsDone() && converter.HasResult()))
                {
                    Messages.Warning("DxfImporter: Bezier curve has an undecreasable order of " + geom2DBezier.Degree() + ".");
                    return;
                }
                _AddBSplineCurve(converter.Curve());
                break;
            }
        }
示例#3
0
        //--------------------------------------------------------------------------------------------------

        public static bool RenderBezierCurve(IDrawingRenderer renderer, Geom2d_BezierCurve bezier, double first, double last, bool reverse)
        {
            if (renderer.Capabilities.BezierCurveMaxDegree > 0)
            {
                var maxDegree = Math.Min(3, renderer.Capabilities.BezierCurveMaxDegree);
                if (bezier.Degree() > maxDegree)
                {
                    // Try to reduce the order of the curve
                    var continuity = bezier.Continuity();
                    if (continuity != GeomAbs_Shape.GeomAbs_C0)
                    {
                        continuity = GeomAbs_Shape.GeomAbs_C1;
                    }

                    var converter = new Geom2dConvert_ApproxCurve(bezier, 0.0001, continuity, 1000, maxDegree);
                    if (!(converter.IsDone() && converter.HasResult()))
                    {
                        Messages.Warning("BrepRenderHelper: Bezier curve has an undecreasable order of " + bezier.Degree() + ".");
                        return(false);
                    }

                    return(RenderBSplineCurve(renderer, converter.Curve(), first, last, reverse));
                }

                bezier.Segment(first, last);
                Pnt2d c1, c2;
                var   start = reverse ? bezier.EndPoint() : bezier.StartPoint();
                var   end   = reverse ? bezier.StartPoint() : bezier.EndPoint();

                switch (bezier.Degree())
                {
                case 1:
                    renderer.Line(start, end);
                    return(true);

                case 2:
                    c1 = bezier.Pole(2);
                    renderer.BezierCurve(new[] { start, c1, end });
                    return(true);

                case 3:
                    c1 = bezier.Pole(reverse ? 3 : 2);
                    c2 = bezier.Pole(reverse ? 2 : 3);
                    renderer.BezierCurve(new[] { start, c1, c2, end });
                    return(true);

                default:
                    Messages.Warning("BrepRenderHelper: Bezier curve has an unsupported order of " + bezier.Degree() + ".");
                    break;
                }

                return(false);
            }
            else
            {
                // Try to create B-Spline curve
                var bsplineCurve = ShapeConstruct.ConvertCurveToBSpline(bezier, first, last, 0.0001, bezier.Continuity(), 10000, 3);
                if (bsplineCurve != null)
                {
                    return(RenderBSplineCurve(renderer, bsplineCurve, first, last, reverse));
                }
                Messages.Warning("BrepRenderHelper: Bezier curve is not supported by exporter and conversion to BSpline failed.");
                return(false);
            }
        }