Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------

        void _ImportEllipse(DxfDomEllipse dxfEllipse)
        {
            var centerPoint   = dxfEllipse.CenterPoint;
            var majorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec());
            var minorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec().Rotated(90.0.ToRad()).Scaled(dxfEllipse.Ratio));

            var centerIndex   = _AddPoint(centerPoint, false);
            var majorRimIndex = _AddPoint(majorRimPoint, false);
            var minorRimIndex = _AddPoint(minorRimPoint, false);

            if (majorRimIndex != minorRimIndex)
            {
                _Segments.Add(new SketchSegmentEllipse(centerIndex, majorRimIndex, minorRimIndex));
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------

        void _ImportEllipticalArc(DxfDomEllipse dxfEllipse)
        {
            var centerPoint   = dxfEllipse.CenterPoint;
            var majorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec());
            var minorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec().Rotated(90.0.ToRad()).Scaled(dxfEllipse.Ratio));

            var ellipse = Geom2dUtils.MakeEllipse(centerPoint, majorRimPoint, minorRimPoint);

            var bezierPointArray = Geom2dUtils.EllipticalArcToBezier(ellipse, dxfEllipse.StartParameter, dxfEllipse.EndParameter);

            foreach (var bezierPoints in bezierPointArray)
            {
                var startPoint = _AddPoint(bezierPoints.p1);
                var endPoint   = _AddPoint(bezierPoints.p2);
                _Segments.Add(new SketchSegmentBezier(startPoint, _AddPoint(bezierPoints.c1, false), _AddPoint(bezierPoints.c2, false), endPoint));
            }
        }
Esempio n. 3
0
        //--------------------------------------------------------------------------------------------------

        void _AddEllipseSegment(SketchSegmentEllipse ellipseSegment)
        {
            var ellipse = ellipseSegment.GetEllipse(_Sketch.Points);

            if (_Document.Flags.HasFlag(DxfFlags.ExportEllipseAsPolygon))
            {
                _AddPolygonCurve(new Geom2d_Ellipse(ellipse));
                return;
            }

            var center = ellipse.Location();
            var majorAxisPointOffset = ellipse.XAxis().Direction.ToVec().Multiplied(ellipse.MajorRadius()).ToPnt();
            var ratio = ellipse.MinorRadius() / ellipse.MajorRadius();

            var entity = new DxfDomEllipse("0", center, majorAxisPointOffset, ratio);

            _Document.Entities.Add(entity);
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------------------------------

        void _AddEllipticalArcSegment(SketchSegmentEllipticalArc arcSegment)
        {
            var parameter = new double[2];
            var ellipse   = arcSegment.GetEllipse(_Sketch.Points, parameter);

            if (_Document.Flags.HasFlag(DxfFlags.ExportEllipseAsPolygon))
            {
                var trimmedCurve = new Geom2d_TrimmedCurve(new Geom2d_Ellipse(ellipse), parameter[0], parameter[1]);
                _AddPolygonCurve(trimmedCurve);
                return;
            }

            var center = ellipse.Location();
            var majorAxisPointOffset = ellipse.XAxis().Direction.ToVec().Multiplied(ellipse.MajorRadius()).ToPnt();
            var ratio = ellipse.MinorRadius() / ellipse.MajorRadius();

            var entity = new DxfDomEllipse("0", center, majorAxisPointOffset, ratio, parameter[0], parameter[1]);

            _Document.Entities.Add(entity);
        }
Esempio n. 5
0
        //--------------------------------------------------------------------------------------------------

        void IDrawingRenderer.Ellipse(Pnt2d center, double majorRadius, double minorRadius, double rotation, double startAngle, double endAngle)
        {
            if (startAngle > endAngle)
            {
                startAngle.Swap(ref endAngle);
            }

            if (_Document.Flags.HasFlag(DxfFlags.ExportEllipseAsPolygon))
            {
                Geom2d_Ellipse geom2DEllipse = new(new Ax2d(center, Dir2d.DX.Rotated(-rotation)), majorRadius, minorRadius);
                if (startAngle.Distance(endAngle).IsEqual(Maths.DoublePI, 0.00001))
                {
                    // Full ellipse
                    _AddPolygonCurve(geom2DEllipse);
                }
                else
                {
                    // Elliptical arc
                    _AddPolygonCurve(new Geom2d_TrimmedCurve(geom2DEllipse, startAngle, endAngle));
                }
                return;
            }

            var majorAxisPointOffset = Dir2d.DX.ToVec().Rotated(-rotation).Multiplied(majorRadius);
            var ratio = minorRadius / majorRadius;

            if (startAngle.Distance(endAngle).IsEqual(Maths.DoublePI, 0.00001))
            {
                // Full ellipse
                var entity = new DxfDomEllipse(_CurrentLayerName, center, majorAxisPointOffset.ToPnt(), ratio);
                _AddEntity(entity);
            }
            else
            {
                // Elliptical arc
                var entity = new DxfDomEllipse(_CurrentLayerName, center, majorAxisPointOffset.ToPnt(), ratio, startAngle, endAngle);
                _AddEntity(entity);
            }
        }