public static NFTask GetGeometry() { Msg("[Nesting Factory] Starting collect geometry..."); ICollection <Area> EO = Doc.GetAreas(); IEnumerator <Area> GeomEnum = EO.GetEnumerator(); GeomEnum.MoveNext(); NFTask task = new NFTask(); for (int area_num = 0; area_num < EO.Count; area_num++) { Area area = GeomEnum.Current; GeomEnum.MoveNext(); Rectangle BoundBox = area.BoundRect; double bound_x = BoundBox.Left; double bound_y = BoundBox.Top; NFItem item = new NFItem(area.ObjectId.ToString()); for (int num_contour = 0; num_contour < area.ContourCount; num_contour++) { Contour contour = area.GetContour(num_contour); NFContour cont = new NFContour(); for (int num_segment = 0; num_segment < contour.SegmentCount; num_segment++) { ContourSegment csegment = contour.GetSegment(num_segment); switch (csegment.GeometryType) { case ObjectGeometryType.Line: LineGeometry linegeom = csegment.Geometry as LineGeometry; cont.AddPoint(new NFPoint(linegeom.X1 - bound_x, bound_y - linegeom.Y1, 0)); cont.AddPoint(new NFPoint(linegeom.X2 - bound_x, bound_y - linegeom.Y2, 0)); break; /*case ObjectGeometryType.Polyline: * * PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry; * CircleArcGeometry[] cArcs = polygeom.GetCircleArcApproximation(2); * * for (int i = 0; i < cArcs.GetLength(0); i++) * { * cArcToDoubles(cArcs[i], ref cont, BoundBox); * } * break;*/ case ObjectGeometryType.CircleArc: CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry; cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise); break; case ObjectGeometryType.Circle: CircleGeometry cirgeom = csegment.Geometry as CircleGeometry; cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1)); cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - bound_x, bound_y - cirgeom.CenterY, 1)); break; default: PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry; int v_count = polygeom.Count; for (int i = 0; i < v_count; i++) { if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count) { cont.AddPoint(new NFPoint(polygeom.GetX(i) - bound_x, bound_y - polygeom.GetY(i), 0)); } } break; } } item.AddContour(cont); } task.AddItem(item); } Msg("[Nesting Factory] Geometry collected"); return(task); }
public static NFTask GetGeometry() { Msg("[Nesting Factory] Starting collect geometry..."); ICollection <Area> Areas = Doc.GetAreas(); NFTask task = new NFTask(); foreach (var area in Areas) { Rectangle BoundBox = area.BoundRect; double boundX = BoundBox.Left; double boundY = BoundBox.Top; NFItem item = new NFItem(area.ObjectId.ToString()); for (int num_contour = 0; num_contour < area.ContourCount; num_contour++) { Contour contour = area.GetContour(num_contour); NFContour cont = new NFContour(); foreach (var csegment in contour) { switch (csegment.GeometryType) { case ObjectGeometryType.Line: LineGeometry linegeom = csegment.Geometry as LineGeometry; cont.AddPoint(new NFPoint(linegeom.X1 - boundX, boundY - linegeom.Y1, 0)); cont.AddPoint(new NFPoint(linegeom.X2 - boundX, boundY - linegeom.Y2, 0)); break; case ObjectGeometryType.CircleArc: CircleArcGeometry cgeom = csegment.Geometry as CircleArcGeometry; cArcToDoubles(cgeom, ref cont, BoundBox, csegment.IsCounterclockwise); break; case ObjectGeometryType.Circle: CircleGeometry cirgeom = csegment.Geometry as CircleGeometry; cont.AddPoint(new NFPoint(cirgeom.CenterX + cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1)); cont.AddPoint(new NFPoint(cirgeom.CenterX - cirgeom.Radius - boundX, boundY - cirgeom.CenterY, 1)); break; default: PolylineGeometry polygeom = csegment.Geometry as PolylineGeometry; int v_count = polygeom.Count; for (int i = 0; i < v_count; i++) { if (v_count < 50 || i % (csegment.GeometryType == ObjectGeometryType.Ellipse ? 5 : 1) == 0 || i == v_count) { cont.AddPoint(new NFPoint(polygeom.GetX(i) - boundX, boundY - polygeom.GetY(i), 0)); } } break; } } item.AddContour(cont); } task.AddItem(item); } Msg("[Nesting Factory] Geometry collected"); return(task); }