//-------------------------------------------------------------------------------------------------- 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; } }
//-------------------------------------------------------------------------------------------------- void _AddEllipse(Geom2d_Ellipse ellipse, double first, double last) { if (_Document.Flags.HasFlag(DxfFlags.ExportEllipseAsPolygon)) { if (Math.Abs(last - first) < ellipse.Period()) { // Elliptical arc var trimmedCurve = new Geom2d_TrimmedCurve(ellipse, first, last); _AddPolygonCurve(trimmedCurve); } else { // Full ellipse _AddPolygonCurve(ellipse); } return; } var center = ellipse.Location(); var majorAxisPointOffset = ellipse.XAxis().Direction.ToVec().Multiplied(ellipse.MajorRadius()); var ratio = ellipse.MinorRadius() / ellipse.MajorRadius(); if (Math.Abs(last - first) < ellipse.Period()) { // Elliptical arc if (ellipse.Position().Sense() > 0) { var temp = first; first = ellipse.Period() - last; last = ellipse.Period() - temp; } var entity = new DxfDomEllipse(_CurrentLayer, center, majorAxisPointOffset.ToPnt(), ratio, first, last); _Document.Entities.Add(entity); } else { // Full ellipse var entity = new DxfDomEllipse(_CurrentLayer, center, majorAxisPointOffset.ToPnt(), ratio); _Document.Entities.Add(entity); } }
//-------------------------------------------------------------------------------------------------- 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); }
public void Init(Geom2d_TrimmedCurve b_isector) { throw new NotImplementedException(); }