/// <summary> /// Creates a new Underlay that is a copy of the current instance. /// </summary> /// <returns>A new Underlay that is a copy of this instance.</returns> public override object Clone() { Underlay entity = new Underlay { //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, //Underlay properties Definition = (UnderlayDefinition)this.definition.Clone(), Position = this.position, Scale = this.scale, Rotation = this.rotation, Contrast = this.contrast, Fade = this.fade, DisplayOptions = this.displayOptions, ClippingBoundary = this.clippingBoundary != null ? (ClippingBoundary)this.clippingBoundary.Clone() : null }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new Underlay that is a copy of the current instance. /// </summary> /// <returns>A new Underlay that is a copy of this instance.</returns> public override object Clone() { Underlay entity = new Underlay { //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, //Underlay properties Definition = (UnderlayDefinition) this.definition.Clone(), Position = this.position, Scale = this.scale, Rotation = this.rotation, Contrast = this.contrast, Fade = this.fade, DisplayOptions = this.displayOptions, ClippingBoundary = this.clippingBoundary != null ? (ClippingBoundary) this.clippingBoundary.Clone() : null }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
private Underlay ReadUnderlay() { string underlayDefHandle = null; Vector3 position = Vector3.Zero; Vector3 scale = new Vector3(1.0); double rotation = 0.0; Vector3 normal = Vector3.UnitZ; UnderlayDisplayFlags displayOptions = UnderlayDisplayFlags.ShowUnderlay; short contrast = 100; short fade = 0; Vector2 clippingVertex = Vector2.Zero; List<Vector2> clippingVertexes = new List<Vector2>(); ClippingBoundary clippingBoundary; List<XData> xData = new List<XData>(); this.chunk.Next(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 10: position.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 20: position.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 30: position.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 41: scale.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 42: scale.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 43: scale.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 50: rotation = 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 340: underlayDefHandle = this.chunk.ReadHex(); this.chunk.Next(); break; case 280: displayOptions = (UnderlayDisplayFlags) this.chunk.ReadShort(); this.chunk.Next(); break; case 281: contrast = this.chunk.ReadShort(); this.chunk.Next(); break; case 282: fade = this.chunk.ReadShort(); this.chunk.Next(); break; case 11: clippingVertex = new Vector2(); clippingVertex.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 21: clippingVertex.Y = this.chunk.ReadDouble(); clippingVertexes.Add(clippingVertex); 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 wcsPosition = MathHelper.Transform(position, normal, CoordinateSystem.Object, CoordinateSystem.World); if (clippingVertexes.Count < 2) clippingBoundary = null; else if (clippingVertexes.Count == 2) clippingBoundary = new ClippingBoundary(clippingVertexes[0], clippingVertexes[1]); else clippingBoundary = new ClippingBoundary(clippingVertexes); Underlay underlay = new Underlay { Position = wcsPosition, Scale = scale, Normal = normal, Rotation = rotation, DisplayOptions = displayOptions, Contrast = contrast, Fade = fade, ClippingBoundary = clippingBoundary }; underlay.XData.AddRange(xData); if (string.IsNullOrEmpty(underlayDefHandle) || underlayDefHandle == "0") return null; this.underlayToDefinitionHandles.Add(underlay, underlayDefHandle); return underlay; }
private void WriteUnderlay(Underlay underlay) { this.chunk.Write(100, SubclassMarker.Underlay); this.chunk.Write(340, underlay.Definition.Handle); Vector3 ocsPosition = MathHelper.Transform(underlay.Position, underlay.Normal, CoordinateSystem.World, CoordinateSystem.Object); this.chunk.Write(10, ocsPosition.X); this.chunk.Write(20, ocsPosition.Y); this.chunk.Write(30, ocsPosition.Z); this.chunk.Write(41, underlay.Scale.X); this.chunk.Write(42, underlay.Scale.Y); this.chunk.Write(43, underlay.Scale.Z); this.chunk.Write(50, underlay.Rotation); this.chunk.Write(210, underlay.Normal.X); this.chunk.Write(220, underlay.Normal.Y); this.chunk.Write(230, underlay.Normal.Z); this.chunk.Write(280, (short) underlay.DisplayOptions); this.chunk.Write(281, underlay.Contrast); this.chunk.Write(282, underlay.Fade); if (underlay.ClippingBoundary != null) { foreach (Vector2 vertex in underlay.ClippingBoundary.Vertexes) { this.chunk.Write(11, vertex.X); this.chunk.Write(21, vertex.Y); } } }
private static void UnderlayEntity() { UnderlayDgnDefinition underlayDef1 = new UnderlayDgnDefinition("DgnUnderlay.dgn"); Underlay underlay1 = new Underlay(underlayDef1); underlay1.Normal = new Vector3(1, 0, 0); underlay1.Position = new Vector3(0, 1, 0); underlay1.Scale = new Vector3(0.001); UnderlayDwfDefinition underlayDef2 = new UnderlayDwfDefinition("DwfUnderlay.dwf"); Underlay underlay2 = new Underlay(underlayDef2); underlay2.Rotation = 45; underlay2.Scale = new Vector3(0.01); UnderlayPdfDefinition underlayDef3 = new UnderlayPdfDefinition("PdfUnderlay.pdf"); underlayDef3.Page = "3"; Underlay underlay3 = new Underlay(underlayDef3); DxfDocument doc = new DxfDocument(DxfVersion.AutoCad2013); doc.AddEntity(underlay1); doc.AddEntity(underlay2); doc.AddEntity(underlay3); doc.Save("UnderlayEntity.dxf"); DxfDocument load = DxfDocument.Load("UnderlayEntity.dxf"); load.Save("UnderlayEntity2.dxf"); }