private static void SetEllipseParameters(netDxf.Entities.Ellipse ellipse, double startparam, double endparam) { //CADability: also set the start and end parameter //ellipse.StartParameter = startparam; //ellipse.EndParameter = endparam; if (MathHelper.IsZero(startparam) && MathHelper.IsEqual(endparam, MathHelper.TwoPI)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 0.0; } else { double a = ellipse.MajorAxis * 0.5; double b = ellipse.MinorAxis * 0.5; Vector2 startPoint = new Vector2(a * Math.Cos(startparam), b * Math.Sin(startparam)); Vector2 endPoint = new Vector2(a * Math.Cos(endparam), b * Math.Sin(endparam)); if (Vector2.Equals(startPoint, endPoint)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 0.0; } else { ellipse.StartAngle = Vector2.Angle(startPoint) * MathHelper.RadToDeg; ellipse.EndAngle = Vector2.Angle(endPoint) * MathHelper.RadToDeg; } } }
private EntityObject ExportEllipse(GeoObject.Ellipse elli) { netDxf.Entities.EntityObject entity = null; if (elli.IsArc) { Plane dxfPlane; if (elli.CounterClockWise) { dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(elli.Plane.Normal)); } else { dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(-elli.Plane.Normal)); } if (elli.IsCircle) { GeoObject.Ellipse aligned = GeoObject.Ellipse.Construct(); aligned.SetArcPlaneCenterStartEndPoint(dxfPlane, dxfPlane.Project(elli.Center), dxfPlane.Project(elli.StartPoint), dxfPlane.Project(elli.EndPoint), dxfPlane, true); entity = new netDxf.Entities.Arc(Vector3(aligned.Center), aligned.Radius, aligned.StartParameter / Math.PI * 180, (aligned.StartParameter + aligned.SweepParameter) / Math.PI * 180); entity.Normal = Vector3(dxfPlane.Normal); } else { netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius); entity = expelli; entity.Normal = Vector3(elli.Plane.Normal); Plane cdbplane = elli.Plane; GeoVector2D dir = dxfPlane.Project(cdbplane.DirectionX); SweepAngle rot = new SweepAngle(GeoVector2D.XAxis, dir); expelli.Rotation = rot.Degree; SetEllipseParameters(expelli, elli.StartParameter, elli.StartParameter + elli.SweepParameter); } } else { if (elli.IsCircle) { entity = new netDxf.Entities.Circle(Vector3(elli.Center), elli.Radius); entity.Normal = Vector3(elli.Plane.Normal); } else { netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius); entity = expelli; entity.Normal = Vector3(elli.Plane.Normal); Plane dxfplane = Import.Plane(expelli.Center, expelli.Normal); // this plane is not correct, it has to be rotated Plane cdbplane = elli.Plane; GeoVector2D dir = dxfplane.Project(cdbplane.DirectionX); SweepAngle rot = new SweepAngle(GeoVector2D.XAxis, dir); expelli.Rotation = rot.Degree; } } return(entity); }
public System.Windows.Shapes.Ellipse GetCanvasEllipse(netDxf.Entities.Ellipse ellipse, Vector3 startVector, double canvasHeight) { var tempEllipse = new System.Windows.Shapes.Ellipse(); tempEllipse.Height = ellipse.MinorAxis; tempEllipse.Width = ellipse.MajorAxis; tempEllipse.StrokeThickness = 1; tempEllipse.Stroke = Brushes.Black; tempEllipse.SetValue(Canvas.LeftProperty, -ellipse.MajorAxis / 2 + ellipse.Center.X - startVector.X); tempEllipse.SetValue(Canvas.TopProperty, -ellipse.MinorAxis / 2 - ellipse.Center.Y + canvasHeight + startVector.Y); return(tempEllipse); }
public Ellipse(netDxf.Entities.Ellipse inputEllipse) { MaxXMaxY = new Vector3(); MinXMinY = new Vector3(); InputEllipse = inputEllipse; var a = inputEllipse.MajorAxis / 2; var b = inputEllipse.MinorAxis / 2; MinXMinY.X = inputEllipse.Center.X - a; MinXMinY.Y = inputEllipse.Center.Y - b; MaxXMaxY.X = inputEllipse.Center.X + a; MaxXMaxY.Y = inputEllipse.Center.Y + b; var h = (a - b) / (a + b); Length = Math.PI * (a + b) * (1 + 3 * h * h / (10 + Math.Sqrt(4 - 3 * h * h))); }
private Ellipse ReadEllipse(ref CodeValuePair code) { var ellipse = new Ellipse(); Vector3d center = Vector3d.Zero; Vector3d axisPoint = Vector3d.Zero; Vector3d normal = Vector3d.UnitZ; float ratio = 0; Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>(); code = this.ReadCodePair(); while (code.Code != 0) { switch (code.Code) { case 5: ellipse.Handle = code.Value; code = this.ReadCodePair(); break; case 8: //layer code ellipse.Layer = this.GetLayer(code.Value); code = this.ReadCodePair(); break; case 62: //aci color code ellipse.Color = new AciColor(short.Parse(code.Value)); code = this.ReadCodePair(); break; case 6: //type line code ellipse.LineType = this.GetLineType(code.Value); code = this.ReadCodePair(); break; case 10: center.X = double.Parse(code.Value); code = this.ReadCodePair(); break; case 20: center.Y = double.Parse(code.Value); code = this.ReadCodePair(); break; case 30: center.Z = double.Parse(code.Value); code = this.ReadCodePair(); break; case 11: axisPoint.X = double.Parse(code.Value); code = this.ReadCodePair(); break; case 21: axisPoint.Y = double.Parse(code.Value); code = this.ReadCodePair(); break; case 31: axisPoint.Z = double.Parse(code.Value); code = this.ReadCodePair(); break; case 40: ratio = float.Parse(code.Value); code = this.ReadCodePair(); break; case 41: ellipse.StartAngle = double.Parse(code.Value)*MathHelper.RadToDeg; code = this.ReadCodePair(); break; case 42: ellipse.EndAngle = double.Parse(code.Value)*MathHelper.RadToDeg; code = this.ReadCodePair(); break; case 210: normal.X = double.Parse(code.Value); code = this.ReadCodePair(); break; case 220: normal.Y = double.Parse(code.Value); code = this.ReadCodePair(); break; case 230: normal.Z = double.Parse(code.Value); code = this.ReadCodePair(); break; case 1001: XData xDataItem = this.ReadXDataRecord(code.Value, ref code); xData.Add(xDataItem.ApplicationRegistry, xDataItem); break; default: if (code.Code >= 1000 && code.Code <= 1071) throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file, "The extended data of an entity must start with the application registry code " + this.fileLine); code = this.ReadCodePair(); break; } } Vector3d ocsAxisPoint = MathHelper.Transform((Vector3d) axisPoint, (Vector3d) normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); double rotation = Vector2d.AngleBetween(Vector2d.UnitX, new Vector2d(ocsAxisPoint.X, ocsAxisPoint.Y)); ellipse.MajorAxis = 2*axisPoint.Modulus(); ellipse.MinorAxis = ellipse.MajorAxis*ratio; ellipse.Rotation = rotation*MathHelper.RadToDeg; ellipse.Center = center; ellipse.Normal = normal; ellipse.XData = xData; return ellipse; }
private void WriteEllipse(Ellipse ellipse) { this.chunk.Write(100, SubclassMarker.Ellipse); this.chunk.Write(10, ellipse.Center.X); this.chunk.Write(20, ellipse.Center.Y); this.chunk.Write(30, ellipse.Center.Z); double sine = 0.5*ellipse.MajorAxis*Math.Sin(ellipse.Rotation*MathHelper.DegToRad); double cosine = 0.5*ellipse.MajorAxis*Math.Cos(ellipse.Rotation*MathHelper.DegToRad); Vector3 axisPoint = MathHelper.Transform(new Vector3(cosine, sine, 0), ellipse.Normal, CoordinateSystem.Object, CoordinateSystem.World); this.chunk.Write(11, axisPoint.X); this.chunk.Write(21, axisPoint.Y); this.chunk.Write(31, axisPoint.Z); this.chunk.Write(210, ellipse.Normal.X); this.chunk.Write(220, ellipse.Normal.Y); this.chunk.Write(230, ellipse.Normal.Z); this.chunk.Write(40, ellipse.MinorAxis/ellipse.MajorAxis); double[] paramaters = this.GetEllipseParameters(ellipse); this.chunk.Write(41, paramaters[0]); this.chunk.Write(42, paramaters[1]); this.WriteXData(ellipse.XData); }
private void WriteEllipse(Ellipse ellipse) { if (this.activeSection != StringCode.EntitiesSection && !this.isBlockEntities) { throw new InvalidDxfSectionException(this.activeSection, this.file); } if (this.version == DxfVersion.AutoCad12) { this.WriteEllipseAsPolyline(ellipse); return; } this.WriteCodePair(0, ellipse.CodeName); this.WriteCodePair(5, ellipse.Handle); this.WriteCodePair(100, SubclassMarker.Entity); this.WriteEntityCommonCodes(ellipse); this.WriteCodePair(100, SubclassMarker.Ellipse); this.WriteCodePair(10, ellipse.Center.X); this.WriteCodePair(20, ellipse.Center.Y); this.WriteCodePair(30, ellipse.Center.Z); double sine = (0.5 * ellipse.MajorAxis * Math.Sin(ellipse.Rotation * MathHelper.DegToRad)); double cosine = (0.5 * ellipse.MajorAxis * Math.Cos(ellipse.Rotation * MathHelper.DegToRad)); Vector3d axisPoint = MathHelper.Transform(new Vector3d(cosine, sine, 0), ellipse.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World); this.WriteCodePair(11, axisPoint.X); this.WriteCodePair(21, axisPoint.Y); this.WriteCodePair(31, axisPoint.Z); this.WriteCodePair(210, ellipse.Normal.X); this.WriteCodePair(220, ellipse.Normal.Y); this.WriteCodePair(230, ellipse.Normal.Z); this.WriteCodePair(40, ellipse.MinorAxis/ellipse.MajorAxis); this.WriteCodePair(41, ellipse.StartAngle*MathHelper.DegToRad); this.WriteCodePair(42, ellipse.EndAngle*MathHelper.DegToRad); this.WriteXData(ellipse.XData); }
public override object Clone() { Ellipse copy = new Ellipse { Center = this.Center, EndMajorAxis = this.EndMajorAxis, MinorRatio = this.MinorRatio, StartAngle = this.StartAngle, EndAngle = this.EndAngle, IsCounterclockwise = this.IsCounterclockwise }; return copy; }
private static void SetEllipseParameters(Ellipse ellipse, double[] param) { if (MathHelper.IsZero(param[0]) && MathHelper.IsEqual(param[1], MathHelper.TwoPI)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 0.0; } else { double a = ellipse.MajorAxis*0.5; double b = ellipse.MinorAxis*0.5; Vector2 startPoint = new Vector2(a*Math.Cos(param[0]), b*Math.Sin(param[0])); Vector2 endPoint = new Vector2(a*Math.Cos(param[1]), b*Math.Sin(param[1])); if (Equals(startPoint, endPoint)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 0.0; } else { ellipse.StartAngle = Vector2.Angle(startPoint)*MathHelper.RadToDeg; ellipse.EndAngle = Vector2.Angle(endPoint)*MathHelper.RadToDeg; } } }
private static Ellipse ProcessEllipse(Ellipse ellipse, Matrix3 trans, Vector3 pos) { ellipse.Center = trans * ellipse.Center + pos; ellipse.Normal = trans * ellipse.Normal; return(ellipse); }
private void SetEllipseParameters(Ellipse ellipse, double[] param) { double a = ellipse.MajorAxis*0.5; double b = ellipse.MinorAxis*0.5; Vector2 startPoint = new Vector2(a * Math.Cos(param[0]), b * Math.Sin(param[0])); Vector2 endPoint = new Vector2(a * Math.Cos(param[1]), b * Math.Sin(param[1])); // trigonometry functions are very prone to round off errors if (startPoint.Equals(endPoint)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 360.0; } else { ellipse.StartAngle = Vector2.Angle(startPoint) * MathHelper.RadToDeg; ellipse.EndAngle = Vector2.Angle(endPoint) * MathHelper.RadToDeg; } }
private void SetInternalInfo(IEnumerable <EntityObject> entities) { bool containsPolyline = false; edges.Clear(); foreach (EntityObject entity in entities) { if (containsPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense, // like, for example, an internal loop that is made of a single arc. // so if AutoCAD is OK with that I am too, the program that make use of this information will take care of this inconsistencies switch (entity.Type) { case EntityType.Arc: edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Circle: edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Ellipse: edges.Add(Ellipse.ConvertFrom(entity)); break; case EntityType.Line: edges.Add(Line.ConvertFrom(entity)); break; case EntityType.LwPolyline: LwPolyline lwpoly = (LwPolyline)entity; if (lwpoly.IsClosed) { if (edges.Count != 0) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } edges.Add(Polyline.ConvertFrom(entity)); pathType |= HatchBoundaryPathTypeFlags.Polyline; containsPolyline = true; } else { SetInternalInfo(lwpoly.Explode()); // open polylines will always be exploded, only one polyline can be present in a path } break; case EntityType.Polyline: Entities.Polyline poly = (Entities.Polyline)entity; if (poly.IsClosed) { if (edges.Count != 0) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } edges.Add(Polyline.ConvertFrom(entity)); pathType |= HatchBoundaryPathTypeFlags.Polyline; containsPolyline = true; } else { SetInternalInfo(poly.Explode()); // open polylines will always be exploded, only one polyline can be present in a path } break; case EntityType.Spline: edges.Add(Spline.ConvertFrom(entity)); break; default: throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary. Only Arc, Circle, Ellipse, Line, LwPolyline, and Spline entities are allowed.", entity.Type)); } } }
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 StrokeEllipse(DxfDocument dxf, Layer layer, Ellipse dxfEllipse, Core2D.Style.ArgbColor color, double thickness) { var stroke = ToColor(color); var strokeTansparency = ToTransparency(color); var lineweight = ToLineweight(thickness); dxfEllipse.Layer = layer; dxfEllipse.Color = stroke; dxfEllipse.Transparency.Value = strokeTansparency; dxfEllipse.Lineweight = lineweight; dxf.AddEntity(dxfEllipse); }
private void SetInternalInfo(IList <EntityObject> entities) { bool containsClosedPolyline = false; this.edges.Clear(); foreach (EntityObject entity in entities) { if ((this.pathTypeFlag & HatchBoundaryPathTypeFlags.Polyline) == HatchBoundaryPathTypeFlags.Polyline) { if (this.edges.Count >= 1) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } } // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense, like, for example an internal loop that is made of a single arc. // so if AutoCAD is ok with that I am too, the program that make use of this information will take care of this inconsistencies switch (entity.Type) { case EntityType.Arc: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Circle: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Arc.ConvertFrom(entity)); break; case EntityType.Ellipse: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Ellipse.ConvertFrom(entity)); break; case EntityType.Line: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Line.ConvertFrom(entity)); break; case EntityType.LightWeightPolyline: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } LwPolyline poly = (LwPolyline)entity; if (poly.IsClosed) { this.edges.Add(Polyline.ConvertFrom(entity)); // A polyline HatchBoundaryPath must be closed this.pathTypeFlag |= HatchBoundaryPathTypeFlags.Polyline; containsClosedPolyline = true; } else { this.SetInternalInfo(poly.Explode()); // open polylines will always be exploded, only one polyline can be present in a path } break; case EntityType.Spline: if (containsClosedPolyline) { throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path."); } this.edges.Add(Spline.ConvertFrom(entity)); break; default: throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary.", entity.Type)); } } }
/// <summary> /// Explodes the current insert. /// </summary> /// <returns>A list of entities.</returns> public List <EntityObject> Explode() { List <EntityObject> entities = new List <EntityObject>(); Matrix3 transformation = this.GetTransformation(); Vector3 translation = this.Position - transformation * this.block.Origin; foreach (EntityObject entity in this.block.Entities) { Vector3 localScale = MathHelper.Transform(this.Scale, entity.Normal, CoordinateSystem.World, CoordinateSystem.Object); bool isUniformScale = MathHelper.IsEqual(localScale.X, localScale.Y); // entities with reactors are associated with other entities they will handle the transformation if (entity.Reactors.Count > 0) { continue; } if (!isUniformScale) { switch (entity.Type) { case EntityType.Circle: { Circle circle = (Circle)entity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = circle.Center, MajorAxis = 2 * circle.Radius, MinorAxis = 2 * circle.Radius, Thickness = circle.Thickness }; ellipse.TransformBy(transformation, translation); entities.Add(ellipse); break; } case EntityType.Arc: { Arc arc = (Arc)entity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = arc.Center, MajorAxis = 2 * arc.Radius, MinorAxis = 2 * arc.Radius, StartAngle = arc.StartAngle, EndAngle = arc.EndAngle, Thickness = arc.Thickness }; ellipse.TransformBy(transformation, translation); entities.Add(ellipse); break; } case EntityType.LwPolyline: { List <EntityObject> newEntities = ((LwPolyline)entity).Explode(); foreach (EntityObject newEntity in newEntities) { if (newEntity.Type == EntityType.Arc) { Arc arc = (Arc)newEntity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = arc.Center, MajorAxis = 2 * arc.Radius, MinorAxis = 2 * arc.Radius, StartAngle = arc.StartAngle, EndAngle = arc.EndAngle, Thickness = arc.Thickness }; ellipse.TransformBy(transformation, translation); entities.Add(ellipse); } else { newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } } break; } case EntityType.MLine: { List <EntityObject> newEntities = ((MLine)entity).Explode(); foreach (EntityObject newEntity in newEntities) { if (newEntity.Type == EntityType.Arc) { Arc arc = (Arc)newEntity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = arc.Center, MajorAxis = 2 * arc.Radius, MinorAxis = 2 * arc.Radius, StartAngle = arc.StartAngle, EndAngle = arc.EndAngle, Thickness = arc.Thickness }; ellipse.TransformBy(transformation, translation); entities.Add(ellipse); } else { newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } } break; } default: { EntityObject newEntity = (EntityObject)entity.Clone(); newEntity.TransformBy(transformation, translation); entities.Add(newEntity); break; } } } else { EntityObject newEntity = (EntityObject)entity.Clone(); newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } } foreach (Attribute attribute in this.attributes) { // the attributes will be exploded as a Text entity Text text = new Text { //Attribute properties Layer = (Layer)attribute.Layer.Clone(), Linetype = (Linetype)attribute.Linetype.Clone(), Color = (AciColor)attribute.Color.Clone(), Lineweight = attribute.Lineweight, Transparency = (Transparency)attribute.Transparency.Clone(), LinetypeScale = attribute.LinetypeScale, Normal = attribute.Normal, IsVisible = attribute.IsVisible, Height = attribute.Height, WidthFactor = attribute.WidthFactor, ObliqueAngle = attribute.ObliqueAngle, Value = attribute.Value, Style = (TextStyle)attribute.Style.Clone(), Position = attribute.Position, Rotation = attribute.Rotation, Alignment = attribute.Alignment, IsBackward = attribute.IsBackward, IsUpsideDown = attribute.IsUpsideDown }; entities.Add(text); } return(entities); }
/// <summary> /// Explodes the current insert. /// </summary> /// <returns>A list of entities.</returns> /// <remarks> /// Non-uniform scaling is not supported by all entities. Read the documentation of the entities TranformBy method. /// </remarks> public List <EntityObject> Explode() { bool isUniformScale = MathHelper.IsEqual(this.scale.X, this.scale.Y) && MathHelper.IsEqual(this.scale.Y, this.scale.Z); List <EntityObject> entities = new List <EntityObject>(); Matrix3 transformation = this.GetTransformation(this.Owner == null ? DrawingUnits.Unitless : this.Block.Record.Owner.Owner.DrawingVariables.InsUnits); Vector3 translation = this.Position - transformation * this.block.Origin; foreach (EntityObject entity in this.block.Entities) { // TODO: entities with no implemented TransformBy method if (entity.Type == EntityType.Viewport) { continue; } // entities with reactors are associated with other entities they will handle the transformation if (entity.Reactors.Count > 0) { continue; } if (!isUniformScale) { switch (entity.Type) { case EntityType.Circle: { Circle circle = (Circle)entity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = circle.Center, MajorAxis = 2 * circle.Radius, MinorAxis = 2 * circle.Radius, Thickness = circle.Thickness }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } ellipse.TransformBy(transformation, translation); entities.Add(ellipse); break; } case EntityType.Arc: { Arc arc = (Arc)entity; Ellipse ellipse = new Ellipse { //EntityObject properties Layer = (Layer)entity.Layer.Clone(), Linetype = (Linetype)entity.Linetype.Clone(), Color = (AciColor)entity.Color.Clone(), Lineweight = entity.Lineweight, Transparency = (Transparency)entity.Transparency.Clone(), LinetypeScale = entity.LinetypeScale, Normal = entity.Normal, IsVisible = entity.IsVisible, //Ellipse properties Center = arc.Center, MajorAxis = 2 * arc.Radius, MinorAxis = 2 * arc.Radius, StartAngle = arc.StartAngle, EndAngle = arc.EndAngle, Thickness = arc.Thickness }; ellipse.TransformBy(transformation, translation); entities.Add(ellipse); break; } case EntityType.LwPolyline: { List <EntityObject> newEntities = ((LwPolyline)entity).Explode(); foreach (EntityObject newEntity in newEntities) { newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } break; } case EntityType.MLine: { List <EntityObject> newEntities = ((MLine)entity).Explode(); foreach (EntityObject newEntity in newEntities) { newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } break; } default: { EntityObject newEntity = (EntityObject)entity.Clone(); newEntity.TransformBy(transformation, translation); entities.Add(newEntity); break; } } } else { EntityObject newEntity = (EntityObject)entity.Clone(); newEntity.TransformBy(transformation, translation); entities.Add(newEntity); } } return(entities); }
private Ellipse ReadEllipse() { Vector3 center = Vector3.Zero; Vector3 axisPoint = Vector3.Zero; Vector3 normal = Vector3.UnitZ; double[] param = new double[2]; double ratio = 0.0; List<XData> xData = new List<XData>(); this.chunk.Next(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 10: center.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 20: center.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 30: center.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 11: axisPoint.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 21: axisPoint.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 31: axisPoint.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 40: ratio = this.chunk.ReadDouble(); this.chunk.Next(); break; case 41: param[0] = this.chunk.ReadDouble(); this.chunk.Next(); break; case 42: param[1] = 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 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; } } Vector3 ocsAxisPoint = MathHelper.Transform(axisPoint, normal, CoordinateSystem.World, CoordinateSystem.Object); double rotation = Vector2.Angle(new Vector2(ocsAxisPoint.X, ocsAxisPoint.Y)); double majorAxis = 2*axisPoint.Modulus(); double minorAxis = majorAxis*ratio; Ellipse ellipse = new Ellipse { MajorAxis = majorAxis, MinorAxis = minorAxis, Rotation = rotation*MathHelper.RadToDeg, Center = center, Normal = normal }; ellipse.XData.AddRange(xData); SetEllipseParameters(ellipse, param); return ellipse; }
private static void PaperSpace() { // Sample on how to work with Layouts DxfDocument dxf = new DxfDocument(); // A new DxfDocument will create the default "Model" layout that is associated with the ModelSpace block. This layout cannot be erased or renamed. Line line = new Line(new Vector2(0), new Vector2(100)); // The line will be added to the "Model" layout since this is the active one by default. dxf.AddEntity(line); // Create a new Layout, all new layouts will be associated with different PaperSpace blocks, // while there can be only one ModelSpace multiple PaperSpace blocks might exist in the document Layout layout1 = new Layout("Layout1"); // When the layout is added to the list, a new PaperSpace block will be created automatically dxf.Layouts.Add(layout1); // Set this new Layout as the active one. All entities will now be added to this layout. dxf.ActiveLayout = layout1.Name; // Create a viewport, this is the window to the ModelSpace Viewport viewport1 = new Viewport { Width = 100, Height = 100, Center = new Vector3(50, 50, 0), }; // Add it to the "Layout1" since this is the active one dxf.AddEntity(viewport1); // Also add a circle Circle circle = new Circle(new Vector2(150), 25); dxf.AddEntity(circle); // Create a second Layout, add it to the list, and set it as the active one. Layout layout2 = new Layout("Layout2"); dxf.Layouts.Add(layout2); dxf.ActiveLayout = layout2.Name; // viewports might have a non rectangular boundary, in this case we will use an ellipse. Ellipse ellipse = new Ellipse(new Vector2(100), 200, 150); Viewport viewport2 = new Viewport { ClippingBoundary = ellipse, }; // Add the viewport to the document. This will also add the ellipse to the document. dxf.AddEntity(viewport2); Layout layout3 = new Layout("AnyName"); dxf.Layouts.Add(layout3); //layout can also be renamed layout3.Name = "Layout3"; //dxf.Layouts.Remove(layout2.Name); ShowDxfDocumentInformation(dxf); // Save the document as always. dxf.Save("PaperSpace.dxf"); #region CAUTION - This is subject to change in the future, use it with care // You cannot directly remove the ellipse from the document since it has been attached to a viewport bool ok = dxf.RemoveEntity(ellipse); // OK = false // If an entity has been attached to another, its reactor will point to its owner // This information is subject to change in the future to become a list, an entity can be attached to multiple objects; // but at the moment only the viewport clipping boundary make use of this. // This is the way AutoCad also handles hatch and dimension associativity, that I might implement in the future DxfObject reactor = ellipse.Reactors[0]; // in this case reactor points to viewport2 // You need to delete the viewport instead. This deletes the viewport and the ellipse //dxf.RemoveEntity(viewport2); // another way of deleting the ellipse, is first to assign another clipping boundary to the viewport or just set it to null viewport2.ClippingBoundary = null; // now it will be possible to delete the ellipse. This will not delete the viewport. ok = dxf.RemoveEntity(ellipse); // OK = true // Save the document if you want to test the changes dxf.Save("PaperSpace.dxf"); #endregion DxfDocument dxfLoad = DxfDocument.Load("PaperSpace.dxf"); // For every entity you can check its layout // The entity Owner will return the block to which it belongs, it can be a *Model_Space, *Paper_Space, ... or a common block if the entity is part of its geometry. // The block record stores information about the block and one of them is the layout, this mimics the way the dxf stores this information. // Remember only the internal blocks *Model_Space, *Paper_Space, *Paper_Space0, *Paper_Space1, ... have an associated layout, // all other blocks will return null is asked for block.Record.Layout Layout associatedLayout = dxfLoad.Lines[0].Owner.Record.Layout; // or you can get the complete list of entities of a layout foreach (Layout layout in dxfLoad.Layouts) { List<DxfObject> entities = dxfLoad.Layouts.GetReferences(layout.Name); } // You can also remove any layout from the list, except the "Model". // Remember all entities that has been added to this layout will also be removed. // This mimics the behavior in AutoCad, when a layout is deleted all entities in it will also be deleted. dxfLoad.Layouts.Remove(layout1.Name); Layout layout4 = (Layout) layout2.Clone("Layout4"); dxfLoad.Layouts.Add(layout4); ShowDxfDocumentInformation(dxfLoad); dxfLoad.Save("PaperSpace removed.dxf"); }
private static Ellipse ProcessEllipse(Ellipse ellipse, Matrix3 trans, Vector3 pos) { ellipse.Center = trans*ellipse.Center + pos; ellipse.Normal = trans*ellipse.Normal; return ellipse; }
private static void CheckReferences() { DxfDocument dxf = new DxfDocument(); Layer layer1 = new Layer("Layer1"); layer1.Color = AciColor.Blue; layer1.LineType = LineType.Center; Layer layer2 = new Layer("Layer2"); layer2.Color = AciColor.Red; LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(0, 0)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(20, 0)); poly.Vertexes.Add(new LwPolylineVertex(30, 10)); poly.Layer = layer1; dxf.AddEntity(poly); Ellipse ellipse = new Ellipse(new Vector3(2, 2, 0), 5, 3); ellipse.Rotation = 30; ellipse.Layer = layer1; dxf.AddEntity(ellipse); Line line = new Line(new Vector2(10, 5), new Vector2(-10, -5)); line.Layer = layer2; line.LineType = LineType.DashDot; dxf.AddEntity(line); dxf.Save("test.dxf"); dxf = DxfDocument.Load("sample.dxf"); foreach (ApplicationRegistry registry in dxf.ApplicationRegistries) { foreach (DxfObject o in dxf.ApplicationRegistries.GetReferences(registry)) { if (o is EntityObject) { foreach (KeyValuePair<string, XData> data in ((EntityObject)o).XData) { if (data.Key == registry.Name) if (!ReferenceEquals(registry, data.Value.ApplicationRegistry)) Console.WriteLine("Application registry {0} not equal entity to {1}", registry.Name, o.CodeName); } } } } foreach (Block block in dxf.Blocks) { foreach (DxfObject o in dxf.Blocks.GetReferences(block)) { if (o is Insert) if (!ReferenceEquals(block, ((Insert)o).Block)) Console.WriteLine("Block {0} not equal entity to {1}", block.Name, o.CodeName); } } foreach (ImageDefinition def in dxf.ImageDefinitions) { foreach (DxfObject o in dxf.ImageDefinitions.GetReferences(def)) { if (o is Image) if (!ReferenceEquals(def, ((Image)o).Definition)) Console.WriteLine("Image definition {0} not equal entity to {1}", def.Name, o.CodeName); } } foreach (DimensionStyle dimStyle in dxf.DimensionStyles) { foreach (DxfObject o in dxf.DimensionStyles.GetReferences(dimStyle)) { if (o is Dimension) if (!ReferenceEquals(dimStyle, ((Dimension)o).Style)) Console.WriteLine("Dimension style {0} not equal entity to {1}", dimStyle.Name, o.CodeName); } } foreach (Group g in dxf.Groups) { foreach (DxfObject o in dxf.Groups.GetReferences(g)) { // no references } } foreach (UCS u in dxf.UCSs) { foreach (DxfObject o in dxf.UCSs.GetReferences(u)) { } } foreach (TextStyle style in dxf.TextStyles) { foreach (DxfObject o in dxf.TextStyles.GetReferences(style)) { if (o is Text) if (!ReferenceEquals(style, ((Text)o).Style)) Console.WriteLine("Text style {0} not equal entity to {1}", style.Name, o.CodeName); if (o is MText) if (!ReferenceEquals(style, ((MText)o).Style)) Console.WriteLine("Text style {0} not equal entity to {1}", style.Name, o.CodeName); if (o is DimensionStyle) if (!ReferenceEquals(style, ((DimensionStyle)o).DIMTXSTY)) Console.WriteLine("Text style {0} not equal entity to {1}", style.Name, o.CodeName); } } foreach (Layer layer in dxf.Layers) { foreach (DxfObject o in dxf.Layers.GetReferences(layer)) { if (o is Block) if (!ReferenceEquals(layer, ((Block)o).Layer)) Console.WriteLine("Layer {0} not equal entity to {1}", layer.Name, o.CodeName); if (o is EntityObject) if (!ReferenceEquals(layer, ((EntityObject)o).Layer)) Console.WriteLine("Layer {0} not equal entity to {1}", layer.Name, o.CodeName); } } foreach (LineType lType in dxf.LineTypes) { foreach (DxfObject o in dxf.LineTypes.GetReferences(lType)) { if (o is Layer) if (!ReferenceEquals(lType, ((Layer)o).LineType)) Console.WriteLine("Line type {0} not equal to {1}", lType.Name, o.CodeName); if (o is MLineStyle) { foreach (MLineStyleElement e in ((MLineStyle)o).Elements) { if (!ReferenceEquals(lType, e.LineType)) Console.WriteLine("Line type {0} not equal to {1}", lType.Name, o.CodeName); } } if (o is EntityObject) if (!ReferenceEquals(lType, ((EntityObject)o).LineType)) Console.WriteLine("Line type {0} not equal entity to {1}", lType.Name, o.CodeName); } } Console.WriteLine("Press a key to continue..."); Console.ReadKey(); }
public void WriteProject(WaveguideDesignerProjectData project) { if( project == null ) return; Type type; EntityObject obj = null; DxfDocument doc = new DxfDocument(); doc.Name = project.Name; Layer dxfLayer; LayerData layerData; foreach( VirtualLayer vLayer in project.VirtualGraphics.Layers ) { layerData = null; foreach( LayerData tmp in project.Layers ) if( tmp.VirtualLayer == vLayer ) { layerData = tmp; break; } if( layerData == null ) continue; dxfLayer = new Layer( layerData.Name ); dxfLayer.Color.Index = (short)layerData.LayerNumber; doc.Layers.Add( dxfLayer ); foreach( VirtualShapeBase vShape in vLayer.Shapes ) { type = vShape.GetType(); if( type == typeof( VirtualRectangle ) ) { VirtualRectangle rect = (VirtualRectangle)vShape; Polyline dxfrect = new Polyline(); obj = new Polyline(); dxfrect.IsClosed = true; dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y + rect.Size.H, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y + rect.Size.H, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) ); obj = dxfrect; } else if( type == typeof( VirtualPolygon ) ) { VirtualPolygon poly = (VirtualPolygon)vShape; Polyline dxfpoly = new Polyline(); dxfpoly.IsClosed = true; foreach( PointD p in poly.Vertices ) dxfpoly.Vertexes.Add( conv( p ) ); dxfpoly.Vertexes.Add( conv( poly.Vertices[0] ) ); obj = dxfpoly; } else if( type == typeof( VirtualEllipse ) ) { VirtualEllipse elli = (VirtualEllipse)vShape; Ellipse dxfelli = new Ellipse(); dxfelli.Center = new netDxf.Vector3( elli.Center.X, elli.Center.Y, 0 ); dxfelli.StartAngle = 0; dxfelli.EndAngle = 360; dxfelli.MajorAxis = Math.Max( elli.Radius.W, elli.Radius.H ); dxfelli.MinorAxis = Math.Min( elli.Radius.W, elli.Radius.H ); dxfelli.Rotation = elli.Radius.W >= elli.Radius.H ? 0 : 90; obj = dxfelli; } else if( type == typeof( VirtualPie ) ) { VirtualPie pie = (VirtualPie)vShape; Ellipse dxfelli = new Ellipse(); dxfelli.Center = new netDxf.Vector3( pie.Center.X, pie.Center.Y, 0 ); dxfelli.StartAngle = pie.StartAngle; dxfelli.EndAngle = pie.EndAngle; dxfelli.MajorAxis = Math.Max( pie.Radius.W, pie.Radius.H ); dxfelli.MinorAxis = Math.Min( pie.Radius.W, pie.Radius.H ); dxfelli.Rotation = pie.Radius.W >= pie.Radius.H ? 0 : 90; obj = dxfelli; } else obj = null; if( obj == null ) continue; obj.Layer = dxfLayer; doc.AddEntity( obj ); } } doc.Save( FileName ); }
private static void LayerAndLineTypesUsesAndRemove() { DxfDocument dxf = new DxfDocument(); Layer layer1 = new Layer("Layer1"); layer1.Color = AciColor.Blue; layer1.LineType = LineType.Center; Layer layer2 = new Layer("Layer2"); layer2.Color = AciColor.Red; LwPolyline poly = new LwPolyline(); poly.Vertexes.Add(new LwPolylineVertex(0, 0)); poly.Vertexes.Add(new LwPolylineVertex(10, 10)); poly.Vertexes.Add(new LwPolylineVertex(20, 0)); poly.Vertexes.Add(new LwPolylineVertex(30, 10)); poly.Layer = layer1; dxf.AddEntity(poly); Ellipse ellipse = new Ellipse(new Vector3(2, 2, 0), 5, 3); ellipse.Rotation = 30; ellipse.Layer = layer1; dxf.AddEntity(ellipse); Line line = new Line(new Vector2(10, 5), new Vector2(-10, -5)); line.Layer = layer2; line.LineType = LineType.DashDot; dxf.AddEntity(line); bool ok; // this will return false since layer1 is not empty ok = dxf.Layers.Remove(layer1.Name); List<DxfObject> entities = dxf.Layers.GetReferences(layer1.Name); foreach (DxfObject o in entities) { dxf.RemoveEntity(o as EntityObject); } // now this should return true since layer1 is empty ok = dxf.Layers.Remove(layer1.Name); // blocks needs an special attention Layer layer3 = new Layer("Layer3"); layer3.Color = AciColor.Yellow; Circle circle = new Circle(Vector3.Zero, 15); // it is always recommended that all block entities will be located in layer 0, but this is up to the user. circle.Layer = new Layer("circle"); circle.Layer.Color = AciColor.Green; Block block = new Block("MyBlock"); block.Entities.Add(circle); block.Layer = new Layer("blockLayer"); AttributeDefinition attdef = new AttributeDefinition("NewAttribute"); attdef.Layer = new Layer("attDefLayer"); attdef.LineType = LineType.Center; block.AttributeDefinitions.Add(attdef); Insert insert = new Insert(block, new Vector2(5, 5)); insert.Layer = layer3; insert.Attributes[0].Layer = new Layer("attLayer"); insert.Attributes[0].LineType = LineType.Dashed; dxf.AddEntity(insert); dxf.Save("test.dxf"); DxfDocument dxf2 = DxfDocument.Load("test.dxf"); // this list will contain the circle entity List<DxfObject> dxfObjects; dxfObjects = dxf.Layers.GetReferences("circle"); // but we cannot removed since it is part of a block ok = dxf.RemoveEntity(circle); // we need to remove first the block, but to do this we need to make sure there are no references of that block in the document dxfObjects = dxf.Blocks.GetReferences(block.Name); foreach (DxfObject o in dxfObjects) { dxf.RemoveEntity(o as EntityObject); } // now it is safe to remove the block since we do not have more references in the document ok = dxf.Blocks.Remove(block.Name); // now it is safe to remove the layer "circle", the circle entity was removed with the block since it was part of it ok = dxf.Layers.Remove("circle"); // purge all document layers, only empty layers will be removed dxf.Layers.Clear(); // purge all document line types, only line types without references will be removed dxf.LineTypes.Clear(); dxf.Save("test2.dxf"); }
private void WriteEllipseAsPolyline(Ellipse ellipse) { //we will draw the ellipse as a polyline, it is not supported in AutoCad12 dxf files this.WriteCodePair(0, DxfObjectCode.Polyline); this.WriteEntityCommonCodes(ellipse); //closed polyline this.WriteCodePair(70, 1); //dummy point this.WriteCodePair(10, 0.0); this.WriteCodePair(20, 0.0); this.WriteCodePair(30, ellipse.Center.Z); this.WriteCodePair(39, ellipse.Thickness); this.WriteCodePair(210, ellipse.Normal.X); this.WriteCodePair(220, ellipse.Normal.Y); this.WriteCodePair(230, ellipse.Normal.Z); //Obsolete; formerly an “entities follow flag” (optional; ignore if present) //but its needed to load the dxf file in AutoCAD this.WriteCodePair(66, "1"); this.WriteXData(ellipse.XData); List<Vector2d> points = ellipse.PolygonalVertexes(ellipse.CurvePoints); foreach (Vector2d v in points) { this.WriteCodePair(0, DxfObjectCode.Vertex); this.WriteCodePair(8, ellipse.Layer); this.WriteCodePair(70, 0); this.WriteCodePair(10, v.X); this.WriteCodePair(20, v.Y); } this.WriteCodePair(0, StringCode.EndSequence); }
private static void ToPolyline() { DxfDocument dxf = new DxfDocument(); Vector3 center = new Vector3(1, 8, -7); Vector3 normal = new Vector3(1, 1, 1); Circle circle = new Circle(center, 7.5); circle.Normal = normal; Arc arc = new Arc(center, 5, -45, 45); arc.Normal = normal; Ellipse ellipse = new Ellipse(center, 15, 7.5); ellipse.Rotation = 35; ellipse.Normal = normal; Ellipse ellipseArc = new Ellipse(center, 10, 5); ellipseArc.StartAngle = 315; ellipseArc.EndAngle = 45; ellipseArc.Rotation = 35; ellipseArc.Normal = normal; dxf.AddEntity(circle); dxf.AddEntity(circle.ToPolyline(10)); dxf.AddEntity(arc); dxf.AddEntity(arc.ToPolyline(10)); dxf.AddEntity(ellipse); dxf.AddEntity(ellipse.ToPolyline(10)); dxf.AddEntity(ellipseArc); dxf.AddEntity(ellipseArc.ToPolyline(10)); dxf.Save("to polyline.dxf"); dxf = DxfDocument.Load("to polyline.dxf"); dxf.Save("to polyline2.dxf"); }
private double[] GetEllipseParameters(Ellipse ellipse) { double atan1; double atan2; if (ellipse.IsFullEllipse) { atan1 = 0.0; atan2 = MathHelper.TwoPI; } else { Vector2 startPoint = new Vector2(ellipse.Center.X, ellipse.Center.Y) + ellipse.PolarCoordinateRelativeToCenter(ellipse.StartAngle); Vector2 endPoint = new Vector2(ellipse.Center.X, ellipse.Center.Y) + ellipse.PolarCoordinateRelativeToCenter(ellipse.EndAngle); double a = ellipse.MajorAxis*0.5; double b = ellipse.MinorAxis*0.5; double px1 = (startPoint.X - ellipse.Center.X)/a; double py1 = (startPoint.Y - ellipse.Center.Y)/b; double px2 = (endPoint.X - ellipse.Center.X)/a; double py2 = (endPoint.Y - ellipse.Center.Y)/b; atan1 = Math.Atan2(py1, px1); atan2 = Math.Atan2(py2, px2); } return new[] {atan1, atan2}; }
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"); }
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"); }
private static void Ellipse() { DxfDocument dxf = new DxfDocument(); //Line line = new Line(new Vector3(0, 0, 0), new Vector3(2 * Math.Cos(Math.PI / 4),2 * Math.Cos(Math.PI / 4), 0)); //dxf.AddEntity(line); //Line line2 = new Line(new Vector3(0, 0, 0), new Vector3(0, -2, 0)); //dxf.AddEntity(line2); //Arc arc=new Arc(Vector3.Zero,2,45,270); //dxf.AddEntity(arc); Ellipse ellipse = new Ellipse(new Vector3(2,2,0), 5,3); ellipse.Rotation = 30; ellipse.Normal=new Vector3(1,1,1); ellipse.Thickness = 2; dxf.AddEntity(ellipse); Ellipse ellipseArc = new Ellipse(new Vector3(2, 10, 0), 5, 3); ellipseArc.StartAngle = -45; ellipseArc.EndAngle = 45; dxf.AddEntity(ellipseArc); dxf.Save("ellipse.dxf"); dxf = new DxfDocument(); dxf = DxfDocument.Load("ellipse.dxf"); DxfDocument load = DxfDocument.Load("test ellipse.dxf"); load.Save("saved test ellipse.dxf"); }
/// <summary> /// Creates a new Ellipse that is a copy of the current instance. /// </summary> /// <returns>A new Ellipse that is a copy of this instance.</returns> public override object Clone() { Ellipse entity = new Ellipse { //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, //Ellipse properties Center = this.center, MajorAxis = this.majorAxis, MinorAxis = this.minorAxis, Rotation = this.rotation, StartAngle = this.startAngle, EndAngle = this.endAngle, Thickness = this.thickness }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
private static void Ellipse() { DxfDocument dxf = new DxfDocument(); Line line = new Line(new Vector3d(0, 0, 0), new Vector3d((2 * Math.Cos(Math.PI / 4)), (2 * Math.Cos(Math.PI / 4)), 0)); dxf.AddEntity(line); Line line2 = new Line(new Vector3d(0, 0, 0), new Vector3d(0, -2, 0)); dxf.AddEntity(line2); Arc arc=new Arc(Vector3d.Zero,2,45,270); dxf.AddEntity(arc); // ellipses are saved as polylines Ellipse ellipse = new Ellipse(new Vector3d(2,2,0), 5,3); ellipse.Rotation = 30; ellipse.Normal=new Vector3d(1,1,1); ellipse.Thickness = 2; dxf.AddEntity(ellipse); dxf.Save("ellipse.dxf", DxfVersion.AutoCad2000); dxf = new DxfDocument(); dxf.Load("ellipse.dxf"); }