/// <summary> /// Modifies or creates the xData hatch information entries that hold the values for the gradient color indexes. /// </summary> /// <param name="xdata">Hatch <see cref="XData">XData</see></param> public void GradientColorAciXData(Dictionary <string, XData> xdata) { if (xdata.ContainsKey("GradientColor1ACI")) { XData xdataEntry = xdata["GradientColor1ACI"]; XDataRecord record = new XDataRecord(XDataCode.Integer, this.color1.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, this.Color1.Index)); xdata.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry); } if (xdata.ContainsKey("GradientColor2ACI")) { XData xdataEntry = xdata["GradientColor2ACI"]; XDataRecord record = new XDataRecord(XDataCode.Integer, this.color2.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, this.color2.Index)); xdata.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry); } }
//needs to go to cadgen exporter with a list of polylines and attributes public static MemoryStream Get(string fileName, IExporter cadGenExporter, Action <string> action) { bool isBinary; var ver = DxfDocument.CheckDxfFileVersion(fileName, out isBinary); DxfDocument doc = DxfDocument.Load(fileName); var docSector = doc.Texts.FirstOrDefault(x => string.Equals(x.Layer.Name, "Sector", StringComparison.InvariantCultureIgnoreCase)); var polys = GetPolys(doc); var i = 0; var c = polys.Count(); //Parallel.ForEach(polys, p => foreach (var p in polys) { var cI = Interlocked.Increment(ref i); action($"Export DXF: {cI} / {c}; index:{p.index.Value}"); //CF - INDEX int index; if (int.TryParse(p.index.Value.Trim(), out index)) { var points = p.poly.ToPoints(); var area = VectorExtensions.Area(points); p.poly.XData.Clear(); var cg = cadGenExporter.Export(index, points, area, p.nrCadGeneral?.Value, docSector?.Value, p.nrCadastral?.Value).Result; if (cg.Length > 0) { var xD = new XData(new ApplicationRegistry("TOPO")); xD.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "{")); foreach (var line in cg) { var xDR = new XDataRecord(XDataCode.String, line); xD.XDataRecord.Add(xDR); } xD.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "}")); p.poly.XData.Add(xD); } } }//); var stream = new MemoryStream(); doc.Save(stream, isBinary); stream.Seek(0, SeekOrigin.Begin); return(stream); }
internal void AddPatternXData() { if (this.XData.ContainsKey(ApplicationRegistry.Default.Name)) { XData xdataEntry = this.XData[ApplicationRegistry.Default.Name]; xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0)); } else { XData xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.Default.Name)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0)); this.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry); } if (!(this.Pattern is HatchGradientPattern)) { return; } HatchGradientPattern grad = (HatchGradientPattern)this.Pattern; if (this.XData.ContainsKey("GradientColor1ACI")) { XData xdataEntry = this.XData["GradientColor1ACI"]; XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color1.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color1.Index)); this.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry); } if (this.XData.ContainsKey("GradientColor2ACI")) { XData xdataEntry = this.XData["GradientColor2ACI"]; XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color2.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color2.Index)); this.XData.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry); } }
private void SetUserData(netDxf.Entities.EntityObject entity, IGeoObject go) { if (entity is null || go is null || go.UserData is null || go.UserData.Count == 0) { return; } foreach (KeyValuePair <string, object> de in go.UserData) { if (de.Value is ExtendedEntityData xData) { ApplicationRegistry registry = new ApplicationRegistry(xData.ApplicationName); XData data = new XData(registry); foreach (var item in xData.Data) { XDataCode code = item.Key; XDataRecord record = new XDataRecord(code, item.Value); data.XDataRecord.Add(record); } entity.XData.Add(data); } else { ApplicationRegistry registry = new ApplicationRegistry(ApplicationRegistry.DefaultName); XData data = new XData(registry); XDataRecord record = null; //TODO: Add more types if (de.Value is string strValue) { record = new XDataRecord(XDataCode.String, strValue); } else if (de.Value is short shrValue) { record = new XDataRecord(XDataCode.Int16, shrValue); } else if (de.Value is int intValue) { record = new XDataRecord(XDataCode.Int32, intValue); } if (record != null) { data.XDataRecord.Add(record); } } } }
public Class1() { DxfDocument doc = new DxfDocument(); var poly = new Polyline(); poly.Vertexes.Add(new PolylineVertex(0, 0, 0)); poly.Vertexes.Add(new PolylineVertex(10, 10, 0)); poly.Vertexes.Add(new PolylineVertex(10, 20, 0)); poly.Vertexes.Add(new PolylineVertex(20, 0, 0)); poly.IsClosed = true; var xd = new XDataRecord(XDataCode.String, "kroko"); var x = new XData(new ApplicationRegistry("mimi")); x.XDataRecord.Add(xd); poly.XData.Add(x); doc.AddEntity(poly); doc.Save("abc.dxf"); }
private XData ReadXDataRecord(ApplicationRegistry appReg) { XData xData = new XData(appReg); this.chunk.Next(); while (this.chunk.Code >= 1000 && this.chunk.Code <= 1071) { if (this.chunk.Code == (short) XDataCode.AppReg) break; XDataCode code = (XDataCode) this.chunk.Code; object value = null; switch (code) { case XDataCode.String: value = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString()); break; case XDataCode.AppReg: // Application name cannot appear inside the extended data, AutoCAD assumes it is the beginning of a new application extended data group break; case XDataCode.ControlString: value = this.chunk.ReadString(); break; case XDataCode.LayerName: value = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString()); break; case XDataCode.BinaryData: value = this.chunk.ReadBytes(); break; case XDataCode.DatabaseHandle: value = this.chunk.ReadString(); break; case XDataCode.RealX: case XDataCode.RealY: case XDataCode.RealZ: case XDataCode.WorldSpacePositionX: case XDataCode.WorldSpacePositionY: case XDataCode.WorldSpacePositionZ: case XDataCode.WorldSpaceDisplacementX: case XDataCode.WorldSpaceDisplacementY: case XDataCode.WorldSpaceDisplacementZ: case XDataCode.WorldDirectionX: case XDataCode.WorldDirectionY: case XDataCode.WorldDirectionZ: case XDataCode.Real: case XDataCode.Distance: case XDataCode.ScaleFactor: value = this.chunk.ReadDouble(); break; case XDataCode.Int16: value = this.chunk.ReadShort(); break; case XDataCode.Int32: value = this.chunk.ReadInt(); break; } XDataRecord xDataRecord = new XDataRecord(code, value); xData.XDataRecord.Add(xDataRecord); this.chunk.Next(); } return xData; }
internal void AddPatternXData() { if (this.XData.ContainsAppId(ApplicationRegistry.DefaultName)) { XData xdataEntry = this.XData[ApplicationRegistry.DefaultName]; xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0)); } else { XData xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y)); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0)); this.XData.Add(xdataEntry); } if (!(this.Pattern is HatchGradientPattern)) return; HatchGradientPattern grad = (HatchGradientPattern)this.Pattern; if (this.XData.ContainsAppId("GradientColor1ACI")) { XData xdataEntry = this.XData["GradientColor1ACI"]; XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color1.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color1.Index)); this.XData.Add(xdataEntry); } if (this.XData.ContainsAppId("GradientColor2ACI")) { XData xdataEntry = this.XData["GradientColor2ACI"]; XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color2.Index); xdataEntry.XDataRecord.Clear(); xdataEntry.XDataRecord.Add(record); } else { XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI")); xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color2.Index)); this.XData.Add(xdataEntry); } }