public void DrawPolygon(SvgDocument SvgDocument, PointF[] vertices, Color c) { SvgPointCollection points = new SvgPointCollection(); foreach (PointF p in vertices) { points.Add(new SvgUnit(p.X)); points.Add(new SvgUnit(p.Y)); } SvgPolygon SvgPolygon = new SvgPolygon() { Points = points, Fill = new SvgColourServer(c), StrokeWidth = 0 }; SvgDocument.Children.Add(SvgPolygon); }
/// <summary> /// Addts a point to points /// </summary> /// <param name="points"></param> /// <param name="point"></param> private static void AddPointToCollection(SvgPointCollection points, Point point) { points.Add(Helpers.dtos(point.X)); points.Add(Helpers.dtos(point.Y)); }
public static void DrawOrDiscardEntity(BlockTableRecord btr, Transaction tx, Matrix3d transform, Svg.SvgGroup group)//, int upscale) { foreach (oid oid in btr) { switch (oid.ObjectClass.Name) { case "AcDbLine": //prdDbg(oid.ObjectClass.Name); Line line = oid.Go <Line>(tx); using (Line newLine = new Line(line.StartPoint, line.EndPoint)) { newLine.TransformBy(transform); SvgLine sline = new Svg.SvgLine { StartX = ts(newLine.StartPoint.X), StartY = ts(-newLine.StartPoint.Y), EndX = ts(newLine.EndPoint.X), EndY = ts(-newLine.EndPoint.Y), StrokeWidth = ts(0.1), Stroke = new Svg.SvgColourServer(System.Drawing.Color.Black) }; //if (flip != Flip.PP) //{ // sline.Transforms = AddTransforms(flip, // sline.StartX + sline.EndX, // sline.StartY + sline.EndY); //} group.Children.Add(sline); //mSpc.AppendEntity(newLine); //tx.AddNewlyCreatedDBObject(newLine, true); } break; case "AcDbPolyline": //prdDbg(oid.ObjectClass.Name); Polyline pline = oid.Go <Polyline>(tx); using (Polyline newPline = new Polyline(pline.NumberOfVertices)) { for (int i = 0; i < pline.NumberOfVertices; i++) { newPline.AddVertexAt(i, pline.GetPoint2dAt(i), 0, 0, 0); } newPline.TransformBy(transform); Extents3d bbox = newPline.GeometricExtents; //Prepare for Svg.Transforms SvgPointCollection pcol = new SvgPointCollection(); for (int i = 0; i < newPline.NumberOfVertices; i++) { Point2d p2d = newPline.GetPoint2dAt(i); pcol.Add(ts(p2d.X)); pcol.Add(ts(-p2d.Y)); } SvgPolyline sPline = new SvgPolyline(); sPline.Points = pcol; if (pline.NumberOfVertices == 2) { sPline.StrokeWidth = ts(0.1); sPline.Stroke = new SvgColourServer(System.Drawing.Color.Black); } else { sPline.Fill = new SvgColourServer(System.Drawing.Color.Black); } //if (flip != Flip.PP) //{ // sPline.Transforms = AddTransforms(flip, // ts(bbox.MinPoint.X + bbox.MaxPoint.X), // ts(bbox.MinPoint.Y + bbox.MaxPoint.Y)); //} group.Children.Add(sPline); } break; case "AcDbCircle": //prdDbg(oid.ObjectClass.Name); Circle circle = oid.Go <Circle>(tx); using (Circle newCircle = new Circle()) { newCircle.SetDatabaseDefaults(); newCircle.Center = circle.Center; newCircle.Radius = circle.Radius; newCircle.TransformBy(transform); SvgCircle sCircle = new Svg.SvgCircle { CenterX = ts(newCircle.Center.X), CenterY = ts(-newCircle.Center.Y), Radius = ts(newCircle.Radius), Fill = new Svg.SvgColourServer(System.Drawing.Color.Black), }; //if (flip != Flip.PP) //{ // sCircle.Transforms = AddTransforms(flip, // 2 * sCircle.CenterX, // 2 * sCircle.CenterY); //} group.Children.Add(sCircle); //mSpc.AppendEntity(newCircle); //tx.AddNewlyCreatedDBObject(newCircle, true); } break; case "AcDbMText": prdDbg(oid.ObjectClass.Name); MText mText = oid.Go <MText>(tx); string text = mText.Contents; using (DBText newText = new DBText()) { newText.SetDatabaseDefaults(); newText.TextString = text; newText.Position = mText.Location; newText.Rotation = mText.Rotation; //newText.TransformBy(transform); SvgText sText = new SvgText(newText.TextString); prdDbg(ts(newText.Position.X).ToString()); prdDbg(ts(newText.Position.Y).ToString()); sText.X.Add(ts(newText.Position.X)); sText.Y.Add(ts(newText.Position.Y + 0.1)); sText.FontFamily = "Arial"; sText.FontSize = ts(0.50); prdDbg(ts(newText.Rotation * (180 / Math.PI)).ToString()); sText.Rotate = ts(newText.Rotation * (180 / Math.PI)).ToString(); sText.Fill = new SvgColourServer(System.Drawing.Color.Black); group.Children.Add(sText); } break; case "AcDbBlockReference": DrawOrDiscardEntity(tx.GetObject(oid, OpenMode.ForRead) as BlockReference, tx, group); //, upscale); break; default: //prdDbg("Not implemented: " + oid.ObjectClass.Name); break; } } }