private void SetAttributes(EntityObject entity, IGeoObject go) { if (go is IColorDef cd && cd.ColorDef != null) { AciColor clr; if (cd.ColorDef.Color.ToArgb().Equals(Color.White.ToArgb()) || cd.ColorDef.Color.ToArgb().Equals(Color.Black.ToArgb())) { clr = AciColor.Default; } else { clr = AciColor.FromTrueColor(cd.ColorDef.Color.ToArgb()); if (clr.Index > 0 && clr.Index < 256) { var indexColor = AciColor.FromCadIndex(clr.Index); if (indexColor.ToColor().ToArgb().Equals(cd.ColorDef.Color.ToArgb())) { // if the color matches the index color exactly // we don't need to use TruColor clr.UseTrueColor = false; } } } entity.Color = clr; } if (go.Layer != null) { if (!createdLayers.TryGetValue(go.Layer, out netDxf.Tables.Layer layer)) { layer = new netDxf.Tables.Layer(go.Layer.Name); doc.Layers.Add(layer); createdLayers[go.Layer] = layer; } entity.Layer = layer; } if (go is ILinePattern lp) { if (!createdLinePatterns.TryGetValue(lp.LinePattern, out Linetype linetype)) { List <LinetypeSegment> segments = new List <LinetypeSegment>(); if (lp.LinePattern.Pattern != null) { for (int i = 0; i < lp.LinePattern.Pattern.Length; i++) { LinetypeSegment ls; if ((i & 0x01) == 0) { ls = new LinetypeSimpleSegment(lp.LinePattern.Pattern[i]); } else { ls = new LinetypeSimpleSegment(-lp.LinePattern.Pattern[i]); } segments.Add(ls); } } linetype = new Linetype(lp.LinePattern.Name); linetype.Segments.AddRange(segments); doc.Linetypes.Add(linetype); createdLinePatterns[lp.LinePattern] = linetype; } entity.Linetype = linetype; } if (go is ILineWidth lw) { double minError = double.MaxValue; Lineweight found = Lineweight.Default; foreach (Lineweight lwe in Enum.GetValues(typeof(Lineweight))) { double err = Math.Abs(((int)lwe) / 100.0 - lw.LineWidth.Width); if (err < minError) { minError = err; found = lwe; } } entity.Lineweight = found; } }
private static LayerStateProperties ReadLayerProperties(TextCodeValueReader chunk) { LayerPropertiesFlags flags = LayerPropertiesFlags.Plot; string lineType = String.Empty; //string plotStyle = string.Empty; AciColor color = AciColor.Default; Lineweight lineweight = Lineweight.Default; Transparency transparency = new Transparency(0); string name = chunk.ReadString(); chunk.Next(); while (chunk.Code != 8 && chunk.Code != 0) { switch (chunk.Code) { case 90: flags = (LayerPropertiesFlags)chunk.ReadInt(); chunk.Next(); break; case 62: color = AciColor.FromCadIndex(chunk.ReadShort()); chunk.Next(); break; case 370: lineweight = (Lineweight)chunk.ReadShort(); chunk.Next(); break; case 6: lineType = chunk.ReadString(); chunk.Next(); break; case 2: //plotStyle = chunk.ReadString(); chunk.Next(); break; case 440: int alpha = chunk.ReadInt(); transparency = alpha == 0 ? new Transparency(0) : Transparency.FromAlphaValue(alpha); chunk.Next(); break; case 92: color = AciColor.FromTrueColor(chunk.ReadInt()); chunk.Next(); break; default: chunk.Next(); break; } } if (string.IsNullOrEmpty(name)) { return(null); } LayerStateProperties properties = new LayerStateProperties(name) { Flags = flags, Color = color, Lineweight = lineweight, LinetypeName = lineType, //PlotStyleName = plotStyle, Transparency = transparency }; return(properties); }
private void SetAttributes(EntityObject entity, IGeoObject go) { if (go is IColorDef cd && cd.ColorDef != null) { AciColor clr = AciColor.FromTrueColor(cd.ColorDef.Color.ToArgb()); entity.Color = clr; } if (go.Layer != null) { if (!createdLayers.TryGetValue(go.Layer, out netDxf.Tables.Layer layer)) { layer = new netDxf.Tables.Layer(go.Layer.Name); doc.Layers.Add(layer); createdLayers[go.Layer] = layer; } entity.Layer = layer; } if (go is ILinePattern lp) { if (!createdLinePatterns.TryGetValue(lp.LinePattern, out Linetype linetype)) { List <LinetypeSegment> segments = new List <LinetypeSegment>(); if (lp.LinePattern.Pattern != null) { for (int i = 0; i < lp.LinePattern.Pattern.Length; i++) { LinetypeSegment ls; if ((i & 0x01) == 0) { ls = new LinetypeSimpleSegment(lp.LinePattern.Pattern[i]); } else { ls = new LinetypeSimpleSegment(-lp.LinePattern.Pattern[i]); } segments.Add(ls); } } linetype = new Linetype(lp.LinePattern.Name); linetype.Segments.AddRange(segments); doc.Linetypes.Add(linetype); createdLinePatterns[lp.LinePattern] = linetype; } entity.Linetype = linetype; } if (go is ILineWidth lw) { double minError = double.MaxValue; Lineweight found = Lineweight.Default; foreach (Lineweight lwe in Enum.GetValues(typeof(Lineweight))) { double err = Math.Abs(((int)lwe) / 100.0 - lw.LineWidth.Width); if (err < minError) { minError = err; found = lwe; } } entity.Lineweight = found; } }