private void WriteTrace(Trace trace) { this.chunk.Write(100, SubclassMarker.Trace); // the vertexes are stored in OCS this.chunk.Write(10, trace.FirstVertex.X); this.chunk.Write(20, trace.FirstVertex.Y); this.chunk.Write(30, trace.Elevation); this.chunk.Write(11, trace.SecondVertex.X); this.chunk.Write(21, trace.SecondVertex.Y); this.chunk.Write(31, trace.Elevation); this.chunk.Write(12, trace.ThirdVertex.X); this.chunk.Write(22, trace.ThirdVertex.Y); this.chunk.Write(32, trace.Elevation); this.chunk.Write(13, trace.FourthVertex.X); this.chunk.Write(23, trace.FourthVertex.Y); this.chunk.Write(33, trace.Elevation); this.chunk.Write(39, trace.Thickness); this.chunk.Write(210, trace.Normal.X); this.chunk.Write(220, trace.Normal.Y); this.chunk.Write(230, trace.Normal.Z); this.WriteXData(trace.XData); }
/// <summary> /// Creates a new Trace that is a copy of the current instance. /// </summary> /// <returns>A new Trace that is a copy of this instance.</returns> public override object Clone() { Trace entity = new Trace { //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, //Solid properties FirstVertex = this.firstVertex, SecondVertex = this.secondVertex, ThirdVertex = this.thirdVertex, FourthVertex = this.fourthVertex, Thickness = this.thickness }; foreach (XData data in this.XData.Values) entity.XData.Add((XData)data.Clone()); return entity; }
private Trace ReadTrace() { Vector3 v0 = Vector3.Zero; Vector3 v1 = Vector3.Zero; Vector3 v2 = Vector3.Zero; Vector3 v3 = Vector3.Zero; double thickness = 0.0; Vector3 normal = Vector3.UnitZ; List<XData> xData = new List<XData>(); this.chunk.Next(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 10: v0.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 20: v0.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 30: v0.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 11: v1.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 21: v1.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 31: v1.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 12: v2.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 22: v2.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 32: v2.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 13: v3.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 23: v3.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 33: v3.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 70: thickness = 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; } } Trace entity = new Trace { FirstVertex = new Vector2(v0.X, v0.Y), SecondVertex = new Vector2(v1.X, v1.Y), ThirdVertex = new Vector2(v2.X, v2.Y), FourthVertex = new Vector2(v3.X, v3.Y), Elevation = v0.Z, Thickness = thickness, Normal = normal }; entity.XData.AddRange(xData); return entity; }
private static void TraceEntity() { // The Trace entity behaves exactly as the Solid, they have the same properties and have the same graphical representation. // They are a different entity since in AutoCad they show as two distinct types of objects. // In any case, it is recommended to always use the Solid in its place. Vector2 a = new Vector2(-1, -1); Vector2 b = new Vector2(1, -1); Vector2 c = new Vector2(-1, 1); Vector2 d = new Vector2(1, 1); Trace trace = new Trace(a, b, c, d); trace.Normal = new Vector3(1, 1, 0); trace.Elevation = 2; DxfDocument doc = new DxfDocument(); doc.AddEntity(trace); doc.Save("TraceEntity.dxf"); }