Skip to content

Commit

Permalink
MLStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Oct 21, 2023
1 parent 5ebba3e commit 3a487a8
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4103,12 +4103,16 @@ 1024 512

//R2018+:
if (this.R2018Plus)
{
//Line type handle H Line type handle (hard pointer)
elementTemplate.LinetypeHandle = this.handleReference();
}
//Before R2018:
else
{
//Ltindex BS Linetype index (yes, index)
elementTemplate.LinetypeIndex = this._objectReader.ReadBitShort();
}

template.ElementTemplates.Add(elementTemplate);
mlineStyle.Elements.Add(element);
Expand Down
80 changes: 79 additions & 1 deletion ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private void writeObject(CadObject obj)
switch (obj)
{
case DictionaryVariable:
case MLStyle:
case Scale:
case SortEntitiesTable:
case XRecord:
Expand All @@ -45,6 +44,9 @@ private void writeObject(CadObject obj)
case Layout layout:
this.writeLayout(layout);
break;
case MLStyle style:
this.writeMLStyle(style);
break;
case PlotSettings plotsettings:
this.writePlotSettings(plotsettings);
break;
Expand Down Expand Up @@ -190,6 +192,82 @@ private void writeLayout(Layout layout)
}
}

private void writeMLStyle(MLStyle mlineStyle)
{
//Common:
//Name TV Name of this style
this._writer.WriteVariableText(mlineStyle.Name);
//Desc TV Description of this style
this._writer.WriteVariableText(mlineStyle.Description);

short flags = 0;
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.DisplayJoints))
{
flags = (short)(flags | 1U);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.FillOn))
{
flags = (short)(flags | 2U);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartSquareCap))
{
flags = (short)(flags | 16U);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartRoundCap))
{
flags = (short)(flags | 0x20);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartInnerArcsCap))
{
flags = (short)(flags | 0x40);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndSquareCap))
{
flags = (short)(flags | 0x100);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndRoundCap))
{
flags = (short)(flags | 0x200);
}
if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndInnerArcsCap))
{
flags = (short)(flags | 0x400);
}

//Flags BS A short which reconstitutes the mlinestyle flags as defined in DXF.
this._writer.WriteBitShort(flags);

//fillcolor CMC Fill color for this style
this._writer.WriteCmColor(mlineStyle.FillColor);
//startang BD Start angle
this._writer.WriteBitDouble(mlineStyle.StartAngle);
//endang BD End angle
this._writer.WriteBitDouble(mlineStyle.EndAngle);

//linesinstyle RC Number of lines in this style
this._writer.WriteByte((byte)mlineStyle.Elements.Count);
foreach (MLStyle.Element element in mlineStyle.Elements)
{
//Offset BD Offset of this segment
this._writer.WriteBitDouble(element.Offset);
//Color CMC Color of this segment
this._writer.WriteCmColor(element.Color);
//R2018+:
if (this.R2018Plus)
{
//Line type handle H Line type handle (hard pointer)
this._writer.HandleReference(DwgReferenceType.HardPointer, element.LineType);
}
//Before R2018:
else
{
//TODO: Fix the Linetype index for dwgReader and DwgWriter
//Ltindex BS Linetype index (yes, index)
this._writer.WriteBitShort(0);
}
}
}

private void writePlotSettings(PlotSettings plot)
{
//Common:
Expand Down
1 change: 1 addition & 0 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Write()
this.writeTable(this._document.DimensionStyles);

this.writeBlockEntities();
this.writeObjects();
}

private void writeBlockControl()
Expand Down

0 comments on commit 3a487a8

Please sign in to comment.