private static void AssociativeHatches() { DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); // optionally you can the normal of the polyline, by default it is the UnitZ vector //poly.Normal = new Vector3(1.0); poly.IsClosed = true; HatchBoundaryPath boundary = new HatchBoundaryPath(new List<EntityObject> { poly }); HatchPattern pattern = HatchPattern.Line; pattern.Scale = 10; pattern.Angle = 45; // the hatch boundary can be set in the hatch constructor or it can be added later //Hatch hatch = new Hatch(pattern, new[]{boundary}, true); Hatch hatch = new Hatch(pattern, true); // you will need to manually set the hatch normal to the boundary normal if it is not the UnitZ, // to work properly all boundary entities must belong to the same plane //hatch.Normal = poly.Normal; // the hatch boundary can be set in the hatch constructor or it can be added later, remember hatches with no boundaries will not be saved hatch.BoundaryPaths.Add(boundary); Circle circle = new Circle(Vector2.Zero, 5); // all boundary entities should have the same normal, by default it is the UnitZ // the hatch will not handle the normals of the different boundary path, you will have to make sure they all lay on the same plane //circle.Normal = poly.Normal; hatch.BoundaryPaths.Add(new HatchBoundaryPath(new List<EntityObject> { circle })); // when an associative hatch is added to a document the referenced boundary entities will be added too dxf.AddEntity(hatch); dxf.Save("Hatch.dxf"); DxfDocument dxf2 = DxfDocument.Load("Hatch.dxf"); // you can remove boundaries from a hatch dxf2.Hatches[0].BoundaryPaths.Remove(dxf2.Hatches[0].BoundaryPaths[1]); // and add new ones LwPolyline p = new LwPolyline(); p.Vertexes.Add(new LwPolylineVertex(-20, -20)); p.Vertexes.Add(new LwPolylineVertex(20, -20)); p.Vertexes.Add(new LwPolylineVertex(20, 20)); p.Vertexes.Add(new LwPolylineVertex(-20, 20)); p.IsClosed = true; dxf2.Hatches[0].BoundaryPaths.Add(new HatchBoundaryPath(new List<EntityObject> { p })); dxf2.Save("Hatch add and remove boundaries.dxf"); DxfDocument dxf3 = DxfDocument.Load("Hatch.dxf"); // unlinking the boundary entities from a hatch will not automatically remove them from the document, you can use the returned list to delete them // unlinking the boundary will make the hatch non-associative List<EntityObject> oldBoundary = dxf3.Hatches[0].UnLinkBoundary(); dxf3.RemoveEntity(oldBoundary); // we can recreate the hatch boundary and optionally linking it, thus making it associative, // if the hatch is associative and belongs to a document the new entities will also be automatically added to the same document List<EntityObject> newBoundary = dxf3.Hatches[0].CreateBoundary(true); dxf3.Save("Hatch new contour.dxf"); DxfDocument dxf4 = DxfDocument.Load("Hatch.dxf"); // if the hatch is associative, it is possible to modify the entities that make the boundary // for non-associative the list of entities will contain zero items if (dxf4.Hatches[0].Associative) { // this will only work for associative hatches HatchBoundaryPath path = dxf4.Hatches[0].BoundaryPaths[0]; LwPolyline entity = (LwPolyline) path.Entities[0]; entity.Vertexes[2].Position = new Vector2(15, 15); // after modifying the boundary entities, it is necessary to rebuild the edges path.Update(); dxf4.Save("Hatch change boundary.dxf"); } }
/// <summary> /// Creates a new Hatch that is a copy of the current instance. /// </summary> /// <returns>A new Hatch that is a copy of this instance.</returns> /// <remarks>If the hatch is associative the referenced boundary entities will not be automatically cloned. Use CreateBoundary if required.</remarks> public override object Clone() { Hatch entity = new Hatch((HatchPattern)this.pattern.Clone(), this.associative) { //EntityObject properties Layer = (Layer)this.Layer.Clone(), Linetype = (Linetype)this.Linetype.Clone(), Color = (AciColor)this.Color.Clone(), Lineweight = this.Lineweight, Transparency = (Transparency)this.Transparency.Clone(), LinetypeScale = this.LinetypeScale, Normal = this.Normal, IsVisible = this.IsVisible, //Hatch properties Elevation = this.elevation }; foreach (HatchBoundaryPath path in this.boundaryPaths) { entity.boundaryPaths.Add((HatchBoundaryPath)path.Clone()); } foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new Hatch that is a copy of the current instance. /// </summary> /// <returns>A new Hatch that is a copy of this instance.</returns> /// <remarks>If the hatch is associative the referenced boundary entities will not be automatically cloned. Use CreateBoundary if required.</remarks> public override object Clone() { Hatch entity = new Hatch((HatchPattern)this.pattern.Clone(), false) { //EntityObject properties Layer = (Layer)this.layer.Clone(), LineType = (LineType)this.lineType.Clone(), Color = (AciColor)this.color.Clone(), Lineweight = (Lineweight)this.lineweight.Clone(), Transparency = (Transparency)this.transparency.Clone(), LineTypeScale = this.lineTypeScale, Normal = this.normal, //Hatch properties Elevation = this.elevation }; foreach (HatchBoundaryPath path in this.boundaryPaths) { entity.boundaryPaths.Add((HatchBoundaryPath)path.Clone()); } foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Convert a netDXF hatch to a set of Nucleus planar regions /// </summary> /// <param name="hatch"></param> /// <returns></returns> public static PlanarRegion[] Convert(nDE.Hatch hatch) { PlanarRegion[] result = new PlanarRegion[hatch.BoundaryPaths.Count]; for (int i = 0; i < hatch.BoundaryPaths.Count; i++) { result[i] = new PlanarRegion(Convert(hatch.BoundaryPaths[i]), ExtractAttributes(hatch)); } return(result); }
/// <summary> /// Convert a Nucleus planar region to a netDXF hatch /// </summary> /// <param name="region"></param> /// <returns></returns> public static nDE.Hatch Convert(PlanarRegion region) { var result = new nDE.Hatch(nDE.HatchPattern.Solid, false); result.BoundaryPaths.Add(ConvertToBoundary(region.Perimeter)); foreach (Curve voidCrv in region.Voids) { result.BoundaryPaths.Add(ConvertToBoundary(voidCrv)); } SetAttributes(result, region.Attributes); return(result); }
private void WriteHatch(Hatch hatch) { this.chunk.Write(100, SubclassMarker.Hatch); this.chunk.Write(10, 0.0); this.chunk.Write(20, 0.0); this.chunk.Write(30, hatch.Elevation); this.chunk.Write(210, hatch.Normal.X); this.chunk.Write(220, hatch.Normal.Y); this.chunk.Write(230, hatch.Normal.Z); this.chunk.Write(2, this.EncodeNonAsciiCharacters(hatch.Pattern.Name)); this.chunk.Write(70, (short) hatch.Pattern.Fill); this.chunk.Write(71, (short) 0); // boundary paths info this.WriteHatchBoundaryPaths(hatch.BoundaryPaths); // pattern info this.WriteHatchPattern(hatch.Pattern); this.WriteXData(hatch.XData); }
private void FillEllipse(DxfDocument dxf, Layer layer, Ellipse dxfEllipse, Core2D.Style.ArgbColor color) { var fill = ToColor(color); var fillTransparency = ToTransparency(color); // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360. var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Ellipse)dxfEllipse.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; dxf.AddEntity(hatch); }
private void Hatch_BoundaryPathRemoved(Hatch sender, ObservableCollectionEventArgs<HatchBoundaryPath> e) { this.Entities.Remove(e.Item.Entities); }
private void DrawEllipseInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect) { var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360. var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Ellipse)dxfEllipse.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfEllipse.Layer = layer; dxfEllipse.Color = stroke; dxfEllipse.Transparency.Value = strokeTansparency; dxfEllipse.Lineweight.Value = lineweight; doc.AddEntity(dxfEllipse); } }
private static void ComplexHatch() { HatchPattern pattern = HatchPattern.FromFile("hatch\\acad.pat", "ESCHER"); pattern.Scale = 1.5; pattern.Angle = 30; LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.IsClosed = true; List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath> { new HatchBoundaryPath(new List<EntityObject> {poly}) }; Hatch hatch = new Hatch(pattern, boundary, true); DxfDocument dxf = new DxfDocument(); dxf.AddEntity(poly); dxf.AddEntity(hatch); dxf.Save("complexhatch.dxf"); DxfDocument dxf2 = DxfDocument.Load("complexhatch.dxf"); dxf2.Save("complexhatch2.dxf"); }
private static void HatchTestLinesBoundary() { DxfDocument dxf = new DxfDocument(); Line line1 = new Line(new Vector3(-10,-10,0),new Vector3(10,-10,0)); Line line2 = new Line(new Vector3(10, -10, 0), new Vector3(10, 10, 0)); Line line3 = new Line(new Vector3(10, 10, 0), new Vector3(-10, 10, 0)); Line line4 = new Line(new Vector3(-10, 10, 0), new Vector3(-10, -10, 0)); List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{ new HatchBoundaryPath(new List<EntityObject>{line1, line2, line3, line4}) }; Hatch hatch = new Hatch(HatchPattern.Line, boundary, true); hatch.Layer = new Layer("hatch") { Color = AciColor.Red, LineType = LineType.Dashed }; hatch.Elevation = 52; hatch.Pattern.Angle = 45; hatch.Pattern.Scale = 10; hatch.Normal = new Vector3(1, 1, 1); XData xdata = new XData(new ApplicationRegistry("netDxf")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf")); xdata.XDataRecord.Add(XDataRecord.OpenControlString); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "netDxf hatch")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.Distance, hatch.Pattern.Scale)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, hatch.Pattern.Angle)); xdata.XDataRecord.Add(XDataRecord.CloseControlString); hatch.XData.Add(xdata); //dxf.AddEntity(line1); //dxf.AddEntity(line2); //dxf.AddEntity(line3); //dxf.AddEntity(line4); dxf.AddEntity(hatch); dxf.AddEntity(hatch.CreateBoundary(true)); dxf.Save("hatchTest.dxf"); }
private void WriteHatch(Hatch hatch) { this.chunk.Write(100, SubclassMarker.Hatch); this.chunk.Write(10, 0.0); this.chunk.Write(20, 0.0); this.chunk.Write(30, hatch.Elevation); this.chunk.Write(210, hatch.Normal.X); this.chunk.Write(220, hatch.Normal.Y); this.chunk.Write(230, hatch.Normal.Z); this.chunk.Write(2, this.EncodeNonAsciiCharacters(hatch.Pattern.Name)); this.chunk.Write(70, (short) hatch.Pattern.Fill); if(hatch.Associative) this.chunk.Write(71, (short)1); else this.chunk.Write(71, (short)0); // boundary paths info this.WriteHatchBoundaryPaths(hatch.BoundaryPaths); // pattern info this.WriteHatchPattern(hatch.Pattern); // add the required extended data entries to the hatch XData this.AddHatchPatternXData(hatch); this.WriteXData(hatch.XData); }
private static void HatchCircleBoundary() { DxfDocument dxf = new DxfDocument(); // create a circle that will be our hatch boundary in this case it is a circle with center (5.5, -5.5, 0.0) and a radius 10.0 Circle circle = new Circle(new Vector3(5.5, -5.5, 0), 10); // create the hatch boundary path with only the circle (a circle is already a closed loop it is all we need to define a valid boundary path) // a hatch can have many boundaries (closed loops) and every boundary path can be made of several entities (lines, polylines, arcs, circles and ellipses) List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath> { new HatchBoundaryPath(new List<EntityObject>{circle}) }; // create the hatch in this case we will use the predefined Solid hatch pattern and our circle as the boundary path //Hatch hatch = new Hatch(HatchPattern.Solid, boundary); Hatch hatch = new Hatch(HatchPattern.Line, boundary, true); // to give a color to the hatch, we have to options: // create a new layer with a color for the hatch (in this case by default the hatch will have a ByLayer color) //Layer hatchLayer = new Layer("HathLayer") {Color = AciColor.Green}; //hatch.Layer = hatchLayer; // or give the hatch a color just for it // old AutoCAD versions only had 255 colors (indexed color), now in AutoCAD you can use true colors (8 bits per channel) but at the moment this is not supported. // if you try to give r, g, b values to define a color it will be converted to an indexed color // (I haven't tested this code a lot, so errors might appear and the result might not be what you expected). hatch.Color = AciColor.Red; // the hatch by itself will not show the boundary, but we can use the same entity to show the limits of the hatch, adding it to the document dxf.AddEntity(circle); // add the hatch to the document dxf.AddEntity(hatch); dxf.Save("circle solid fill.dxf"); }
private static void CustomHatchPattern() { DxfDocument dxf = new DxfDocument(); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; LwPolyline poly2 = new LwPolyline(); poly2.Vertexes.Add(new LwPolylineVertex(-5, -5)); poly2.Vertexes.Add(new LwPolylineVertex(5, -5)); poly2.Vertexes.Add(new LwPolylineVertex(5, 5)); poly2.Vertexes.Add(new LwPolylineVertex(-5, 5)); poly2.Vertexes[1].Bulge = -0.25; poly2.IsClosed = true; LwPolyline poly3 = new LwPolyline(); poly3.Vertexes.Add(new LwPolylineVertex(-8, -8)); poly3.Vertexes.Add(new LwPolylineVertex(-6, -8)); poly3.Vertexes.Add(new LwPolylineVertex(-6, -6)); poly3.Vertexes.Add(new LwPolylineVertex(-8, -6)); poly3.IsClosed = true; List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{ new HatchBoundaryPath(new List<EntityObject>{poly}), new HatchBoundaryPath(new List<EntityObject>{poly2}), new HatchBoundaryPath(new List<EntityObject>{poly3}), }; HatchPattern pattern = new HatchPattern("MyPattern", "A custom hatch pattern"); HatchPatternLineDefinition line1 = new HatchPatternLineDefinition(); line1.Angle = 45; line1.Origin = Vector2.Zero; line1.Delta=new Vector2(4,4); line1.DashPattern.Add(12); line1.DashPattern.Add(-4); pattern.LineDefinitions.Add(line1); HatchPatternLineDefinition line2 = new HatchPatternLineDefinition(); line2.Angle = 135; line2.Origin = new Vector2(2.828427125, 2.828427125); line2.Delta = new Vector2(4,-4); line2.DashPattern.Add(12); line2.DashPattern.Add(-4); pattern.LineDefinitions.Add(line2); Hatch hatch = new Hatch(pattern, boundary, true); hatch.Layer = new Layer("hatch") { Color = AciColor.Red, LineType = LineType.Continuous }; hatch.Pattern.Angle = 0; hatch.Pattern.Scale = 1; dxf.AddEntity(poly); dxf.AddEntity(poly2); dxf.AddEntity(poly3); dxf.AddEntity(hatch); dxf.Save("hatchTest.dxf"); }
/// <inheritdoc/> public override void Draw(object dc, Core2D.Shapes.XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<Core2D.Data.XProperty> db, Core2D.Data.Database.XRecord r) { if (!quadraticBezier.IsStroked && !quadraticBezier.IsFilled) return; var dxf = dc as DxfDocument; var style = quadraticBezier.Style; var dxfSpline = CreateQuadraticSpline( quadraticBezier.Point1.X + dx, quadraticBezier.Point1.Y + dy, quadraticBezier.Point2.X + dx, quadraticBezier.Point2.Y + dy, quadraticBezier.Point3.X + dx, quadraticBezier.Point3.Y + dy); if (quadraticBezier.IsFilled) { var fill = ToColor(style.Fill); var fillTransparency = ToTransparency(style.Fill); var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Spline)dxfSpline.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = _currentLayer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; dxf.AddEntity(hatch); } if (quadraticBezier.IsStroked) { var stroke = ToColor(style.Stroke); var strokeTansparency = ToTransparency(style.Stroke); var lineweight = ToLineweight(style.Thickness); dxfSpline.Layer = _currentLayer; dxfSpline.Color = stroke; dxfSpline.Transparency.Value = strokeTansparency; dxfSpline.Lineweight = lineweight; dxf.AddEntity(dxfSpline); } }
private static void WriteSplineBoundaryHatch() { List<SplineVertex> ctrlPoints = new List<SplineVertex> { new SplineVertex(new Vector3(0, 0, 0)), new SplineVertex(new Vector3(25, 50, 0)), new SplineVertex(new Vector3(50, 0, 0)), new SplineVertex(new Vector3(75, 50, 0)), new SplineVertex(new Vector3(100, 0, 0)) }; // hatch with single closed spline boundary path Spline spline = new Spline(ctrlPoints, 3, true); // closed periodic List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>(); HatchBoundaryPath path = new HatchBoundaryPath(new List<EntityObject> {spline}); boundary.Add(path); Hatch hatch = new Hatch(HatchPattern.Line, boundary, true); hatch.Pattern.Angle = 45; hatch.Pattern.Scale = 10; DxfDocument dxf = new DxfDocument(); dxf.AddEntity(hatch); dxf.AddEntity(spline); dxf.Save("hatch closed spline.dxf"); dxf = DxfDocument.Load("hatch closed spline.dxf"); dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010; dxf.Save("hatch closed spline 2010.dxf"); // hatch boundary path with spline and line Spline openSpline = new Spline(ctrlPoints, 3); Line line = new Line(ctrlPoints[0].Position, ctrlPoints[ctrlPoints.Count - 1].Position); List<HatchBoundaryPath> boundary2 = new List<HatchBoundaryPath>(); HatchBoundaryPath path2 = new HatchBoundaryPath(new List<EntityObject> { openSpline, line }); boundary2.Add(path2); Hatch hatch2 = new Hatch(HatchPattern.Line, boundary2, true); hatch2.Pattern.Angle = 45; hatch2.Pattern.Scale = 10; DxfDocument dxf2 = new DxfDocument(); dxf2.AddEntity(hatch2); dxf2.AddEntity(openSpline); dxf2.AddEntity(line); dxf2.Save("hatch open spline.dxf"); dxf2 = DxfDocument.Load("hatch open spline.dxf"); dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010; dxf2.Save("hatch open spline 2010.dxf"); }
private static void WriteGradientPattern() { List<LwPolylineVertex> vertexes = new List<LwPolylineVertex> { new LwPolylineVertex(new Vector2(0, 0)), new LwPolylineVertex(new Vector2(0, 150)), new LwPolylineVertex(new Vector2(150, 150)), new LwPolylineVertex(new Vector2(150, 0)) }; LwPolyline pol = new LwPolyline(vertexes, true); Line line1 = new Line(new Vector2(0, 0), new Vector2(0, 150)); Line line2 = new Line(new Vector2(0, 150), new Vector2(150, 150)); Line line3 = new Line(new Vector2(150, 150), new Vector2(150, 0)); Line line4 = new Line(new Vector2(150, 0), new Vector2(0, 0)); AciColor color = new AciColor(63, 79, 127); HatchGradientPattern gradient = new HatchGradientPattern(color, AciColor.Blue, HatchGradientPatternType.Linear); //HatchGradientPattern gradient = new HatchGradientPattern(AciColor.Red, 0.75, HatchGradientPatternType.Linear); gradient.Angle = 30; List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath> { new HatchBoundaryPath(new List<EntityObject> {pol}) }; Hatch hatch = new Hatch(gradient, boundary, true); // gradients are only supported for AutoCad2004 and later DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2004); dxf.AddEntity(hatch); dxf.Save("gradient test.dxf"); //DxfDocument dxf2 = DxfDocument.Load("gradient test.dxf"); //dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000; //dxf.Save("gradient test 2000.dxf"); }
private void Hatch_BoundaryPathAdded(Hatch sender, ObservableCollectionEventArgs<HatchBoundaryPath> e) { Layout layout = sender.Owner.Record.Layout; foreach (EntityObject entity in e.Item.Entities) { // the hatch belongs to a layout if (entity.Owner != null) { // the hatch and its entities must belong to the same document or block if (!ReferenceEquals(entity.Owner.Record.Layout, layout)) throw new ArgumentException("The HatchBoundaryPath entity and the hatch must belong to the same layout and document. Clone it instead."); // there is no need to do anything else we will not add the same entity twice } else { // we will add the new entity to the same document and layout of the hatch string active = this.ActiveLayout; this.ActiveLayout = layout.Name; // the entity does not belong to anyone this.AddEntity(entity, false, true); this.ActiveLayout = active; } } }
private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect) { double x = rect.X; double y = rect.Y; double w = rect.Width; double h = rect.Height; var dxfLine1 = CreateLine(x, y, x + w, y); var dxfLine2 = CreateLine(x + w, y, x + w, y + h); var dxfLine3 = CreateLine(x + w, y + h, x, y + h); var dxfLine4 = CreateLine(x, y + h, x, y); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Line)dxfLine1.Clone(), (Line)dxfLine2.Clone(), (Line)dxfLine3.Clone(), (Line)dxfLine4.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfLine1.Layer = layer; dxfLine1.Color = stroke; dxfLine1.Transparency.Value = strokeTansparency; dxfLine1.Lineweight.Value = lineweight; dxfLine2.Layer = layer; dxfLine2.Color = stroke; dxfLine2.Transparency.Value = strokeTansparency; dxfLine2.Lineweight.Value = lineweight; dxfLine3.Layer = layer; dxfLine3.Color = stroke; dxfLine3.Transparency.Value = strokeTansparency; dxfLine3.Lineweight.Value = lineweight; dxfLine4.Layer = layer; dxfLine4.Color = stroke; dxfLine4.Transparency.Value = strokeTansparency; dxfLine4.Lineweight.Value = lineweight; doc.AddEntity(dxfLine1); doc.AddEntity(dxfLine2); doc.AddEntity(dxfLine3); doc.AddEntity(dxfLine4); } }
private void Hatch_BoundaryPathRemoved(Hatch sender, ObservableCollectionEventArgs<HatchBoundaryPath> e) { foreach (EntityObject entity in e.Item.Entities) { this.RemoveEntity(entity); } }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="qbezier"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object doc, Test2d.XQBezier qbezier, double dx, double dy, ImmutableArray<Test2d.ShapeProperty> db, Test2d.Record r) { if (!qbezier.IsStroked && !qbezier.IsFilled) return; var _doc = doc as DxfDocument; var style = qbezier.Style; var dxfSpline = CreateQuadraticSpline( qbezier.Point1.X + dx, qbezier.Point1.Y + dy, qbezier.Point2.X + dx, qbezier.Point2.Y + dy, qbezier.Point3.X + dx, qbezier.Point3.Y + dy); if (qbezier.IsFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Spline)dxfSpline.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = _currentLayer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; _doc.AddEntity(hatch); } if (qbezier.IsStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfSpline.Layer = _currentLayer; dxfSpline.Color = stroke; dxfSpline.Transparency.Value = strokeTansparency; dxfSpline.Lineweight.Value = lineweight; _doc.AddEntity(dxfSpline); } }
private static void HatchTest1() { DxfDocument dxf = new DxfDocument(); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; LwPolyline poly2 = new LwPolyline(); poly2.Vertexes.Add(new LwPolylineVertex(-5, -5)); poly2.Vertexes.Add(new LwPolylineVertex(5, -5)); poly2.Vertexes.Add(new LwPolylineVertex(5, 5)); poly2.Vertexes.Add(new LwPolylineVertex(-5, 5)); poly2.Vertexes[1].Bulge = -0.25; poly2.IsClosed = true; LwPolyline poly3 = new LwPolyline(); poly3.Vertexes.Add(new LwPolylineVertex(-8, -8)); poly3.Vertexes.Add(new LwPolylineVertex(-6, -8)); poly3.Vertexes.Add(new LwPolylineVertex(-6, -6)); poly3.Vertexes.Add(new LwPolylineVertex(-8, -6)); poly3.IsClosed = true; Line line = new Line(new Vector2(-5, -5), new Vector2(5, -5)); List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{ new HatchBoundaryPath(new List<EntityObject>{line, poly}), new HatchBoundaryPath(new List<EntityObject>{poly2}), new HatchBoundaryPath(new List<EntityObject>{poly3}), }; Hatch hatch = new Hatch(HatchPattern.Net, boundary, true); hatch.Layer = new Layer("hatch") { Color = AciColor.Red, LineType = LineType.Continuous }; hatch.Pattern.Angle = 30; hatch.Elevation = 52; hatch.Normal = new Vector3(1,1,0); hatch.Pattern.Scale = 1 / hatch.Pattern.LineDefinitions[0].Delta.Y; //dxf.AddEntity(poly); //dxf.AddEntity(poly2); //dxf.AddEntity(poly3); dxf.AddEntity(hatch); dxf.AddEntity(hatch.CreateBoundary(true)); dxf.Save("hatchTest1.dxf"); dxf = DxfDocument.Load("hatchTest1.dxf"); }
/// <inheritdoc/> public override void Draw(object dc, Core2D.Shapes.XPath path, double dx, double dy, ImmutableArray<Core2D.Data.XProperty> db, Core2D.Data.Database.XRecord r) { if (!path.IsStroked && !path.IsFilled) return; var dxf = dc as DxfDocument; var style = path.Style; IList<HatchBoundaryPath> bounds; ICollection<EntityObject> entities; CreateHatchBoundsAndEntitiess(path.Geometry, dx, dy, out bounds, out entities); if (entities == null || bounds == null) return; if (path.IsFilled) { var fill = ToColor(style.Fill); var fillTransparency = ToTransparency(style.Fill); var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = _currentLayer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; dxf.AddEntity(hatch); } if (path.IsStroked) { // TODO: Add support for Closed paths. var stroke = ToColor(style.Stroke); var strokeTansparency = ToTransparency(style.Stroke); var lineweight = ToLineweight(style.Thickness); foreach (var entity in entities) { entity.Layer = _currentLayer; entity.Color = stroke; entity.Transparency.Value = strokeTansparency; entity.Lineweight = lineweight; dxf.AddEntity(entity); } } }
private void AddHatchPatternXData(Hatch hatch) { XData xdataEntry; if (hatch.XData.ContainsAppId(ApplicationRegistry.DefaultName)) { xdataEntry = hatch.XData[ApplicationRegistry.DefaultName]; xdataEntry.XDataRecord.Clear(); } else { xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName)); hatch.XData.Add(xdataEntry); } xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, hatch.Pattern.Origin.X)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, hatch.Pattern.Origin.Y)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0)); HatchGradientPattern grad = hatch.Pattern as HatchGradientPattern; if (grad == null) return; if (hatch.XData.ContainsAppId("GradientColor1ACI")) { xdataEntry = hatch.XData["GradientColor1ACI"]; xdataEntry.XDataRecord.Clear(); } else { xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI")); hatch.XData.Add(xdataEntry); } xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color1.Index)); if (hatch.XData.ContainsAppId("GradientColor2ACI")) { xdataEntry = hatch.XData["GradientColor2ACI"]; xdataEntry.XDataRecord.Clear(); } else { xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI")); hatch.XData.Add(xdataEntry); } xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color2.Index)); }
private static void HatchTest2() { DxfDocument dxf = new DxfDocument(); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; Circle circle = new Circle(Vector3.Zero, 5); Ellipse ellipse = new Ellipse(Vector3.Zero,16,10); ellipse.Rotation = 30; List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{ new HatchBoundaryPath(new List<EntityObject>{poly}), new HatchBoundaryPath(new List<EntityObject>{circle}), new HatchBoundaryPath(new List<EntityObject>{ellipse}) }; Hatch hatch = new Hatch(HatchPattern.Line, boundary, false); hatch.Pattern.Angle = 150; hatch.Pattern.Scale = 5; //hatch.Normal = new Vector3(1,1,1); //hatch.Elevation = 23; //dxf.AddEntity(poly); //dxf.AddEntity(circle); //dxf.AddEntity(ellipse); dxf.AddEntity(hatch); hatch.CreateBoundary(true); dxf.Save("hatchTest2.dxf"); dxf = DxfDocument.Load("hatchTest2.dxf"); dxf.Save("hatchTest2 copy.dxf"); }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="arc"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object doc, Test2d.XArc arc, double dx, double dy, ImmutableArray<Test2d.ShapeProperty> db, Test2d.Record r) { var _doc = doc as DxfDocument; var style = arc.Style; var dxfEllipse = CreateEllipticalArc(arc, dx, dy); if (arc.IsFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360. var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Ellipse)dxfEllipse.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = _currentLayer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; _doc.AddEntity(hatch); } if (arc.IsStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfEllipse.Layer = _currentLayer; dxfEllipse.Color = stroke; dxfEllipse.Transparency.Value = strokeTansparency; dxfEllipse.Lineweight.Value = lineweight; _doc.AddEntity(dxfEllipse); } }
private static void HatchTest3() { DxfDocument dxf = new DxfDocument(); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.Vertexes[2].Bulge = 1; poly.IsClosed = true; Ellipse ellipse = new Ellipse(Vector3.Zero, 16, 10); ellipse.Rotation = 0; ellipse.StartAngle = 0; ellipse.EndAngle = 180; LwPolyline poly2 = new LwPolyline(); poly2.Vertexes.Add(new LwPolylineVertex(-8, 0)); poly2.Vertexes.Add(new LwPolylineVertex(0, -4)); poly2.Vertexes.Add(new LwPolylineVertex(8, 0)); //Arc arc = new Arc(Vector3.Zero,8,180,0); //Line line =new Line(new Vector3(8,0,0), new Vector3(-8,0,0)); List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>{ new HatchBoundaryPath(new List<EntityObject>{poly}), new HatchBoundaryPath(new List<EntityObject>{poly2, ellipse}) }; Hatch hatch = new Hatch(HatchPattern.Line, boundary, true); hatch.Pattern.Angle = 45; //dxf.AddEntity(poly); //dxf.AddEntity(ellipse); ////dxf.AddEntity(arc); ////dxf.AddEntity(line); //dxf.AddEntity(poly2); dxf.AddEntity(hatch); dxf.Save("hatchTest3.dxf"); }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="path"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object doc, Test2d.XPath path, double dx, double dy, ImmutableArray<Test2d.ShapeProperty> db, Test2d.Record r) { if (!path.IsStroked && !path.IsFilled) return; var _doc = doc as DxfDocument; var style = path.Style; ICollection<HatchBoundaryPath> bounds; ICollection<EntityObject> entities; CreateHatchBoundsAndEntitiess(path.Geometry, dx, dy, out bounds, out entities); if (entities == null || bounds == null) return; if (path.IsFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = _currentLayer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; _doc.AddEntity(hatch); } if (path.IsStroked) { // TODO: Add support for Closed paths. var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); foreach (var entity in entities) { entity.Layer = _currentLayer; entity.Color = stroke; entity.Transparency.Value = strokeTansparency; entity.Lineweight.Value = lineweight; _doc.AddEntity(entity); } } }
private static void HatchTest4() { DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010); LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(-10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, -10)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(-10, 10)); poly.IsClosed = true; List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>() { new HatchBoundaryPath(new List<EntityObject>()) }; ; //List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath> {new HatchBoundaryPath(new List<Entity> {poly})}; HatchGradientPattern pattern = new HatchGradientPattern(AciColor.Yellow, AciColor.Blue, HatchGradientPatternType.Linear); pattern.Origin = new Vector2(120, -365); Hatch hatch = new Hatch(pattern, boundary, true); dxf.AddEntity(hatch); dxf.AddEntity(hatch.CreateBoundary(true)); dxf.Save("HatchTest4.dxf"); dxf = DxfDocument.Load("HatchTest4.dxf"); dxf.Save("HatchTest4 copy.dxf"); }
private void Hatch_BoundaryPathAdded(Hatch sender, ObservableCollectionEventArgs<HatchBoundaryPath> e) { foreach (EntityObject entity in e.Item.Entities) { if (entity.Owner != null) { if (!ReferenceEquals(entity.Owner, this)) throw new ArgumentException("The HatchBoundaryPath entity and the hatch must belong to the same block. Clone it instead."); } else { this.Entities.Add(entity); } } }
private Hatch ReadHatch() { string name = string.Empty; HatchFillType fill = HatchFillType.SolidFill; double elevation = 0.0; Vector3 normal = Vector3.UnitZ; HatchPattern pattern = HatchPattern.Line; bool associative = false; List<HatchBoundaryPath> paths = new List<HatchBoundaryPath>(); List<XData> xData = new List<XData>(); this.chunk.Next(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 2: name = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString()); this.chunk.Next(); break; case 30: elevation = this.chunk.ReadDouble(); this.chunk.Next(); break; case 210: normal.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 220: normal.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 230: normal.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 91: // the next lines hold the information about the hatch boundary paths int numPaths = this.chunk.ReadInt(); paths = this.ReadHatchBoundaryPaths(numPaths); break; case 70: // Solid fill flag fill = (HatchFillType) this.chunk.ReadShort(); //if (fill == HatchFillType.SolidFill) name = PredefinedHatchPatternName.Solid; this.chunk.Next(); break; case 71: // Associativity flag (associative = 1; non-associative = 0); for MPolygon, solid-fill flag (has solid fill = 1; lacks solid fill = 0) if (this.chunk.ReadShort() != 0) associative = true; this.chunk.Next(); break; case 75: // the next lines hold the information about the hatch pattern pattern = this.ReadHatchPattern(name); pattern.Fill = fill; break; case 1001: string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString()); XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId)); xData.Add(data); break; default: if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071) throw new Exception("The extended data of an entity must start with the application registry code."); this.chunk.Next(); break; } } if (paths.Count == 0) return null; Hatch entity = new Hatch(pattern, new List<HatchBoundaryPath>(), associative) { Elevation = elevation, Normal = normal }; this.hatchToPaths.Add(entity, paths); entity.XData.AddRange(xData); // here is where dxf stores the pattern origin XData patternOrigin; Vector2 origin = Vector2.Zero; if (entity.XData.TryGetValue(ApplicationRegistry.DefaultName, out patternOrigin)) { foreach (XDataRecord record in patternOrigin.XDataRecord) { if (record.Code == XDataCode.RealX) origin.X = (double) record.Value; else if (record.Code == XDataCode.RealY) origin.Y = (double) record.Value; // record.Code == XDataCode.RealZ is always 0 } } pattern.Origin = origin; return entity; }
/// <summary> /// Creates a new Hatch that is a copy of the current instance. /// </summary> /// <returns>A new Hatch that is a copy of this instance.</returns> /// <remarks>If the hatch is associative the referenced boundary entities will not be automatically cloned. Use CreateBoundary if required.</remarks> public override object Clone() { Hatch entity = new Hatch((HatchPattern) this.pattern.Clone(), false) { //EntityObject properties Layer = (Layer)this.layer.Clone(), LineType = (LineType)this.lineType.Clone(), Color = (AciColor)this.color.Clone(), Lineweight = (Lineweight)this.lineweight.Clone(), Transparency = (Transparency)this.transparency.Clone(), LineTypeScale = this.lineTypeScale, Normal = this.normal, //Hatch properties Elevation = this.elevation }; foreach (HatchBoundaryPath path in this.boundaryPaths) entity.boundaryPaths.Add((HatchBoundaryPath) path.Clone()); foreach (XData data in this.XData.Values) entity.XData.Add((XData)data.Clone()); return entity; }
private void FillRectangle(DxfDocument dxf, Layer layer, double x, double y, double width, double height, Core2D.Style.ArgbColor color) { var fill = ToColor(color); var fillTransparency = ToTransparency(color); var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { CreateLine(x, y, x + width, y), CreateLine(x + width, y, x + width, y + height), CreateLine(x + width, y + height, x, y + height), CreateLine(x, y + height, x, y) }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; dxf.AddEntity(hatch); }