Skip to content

Support ACDB_MLEADEROBJECTCONTEXTDATA_CLASS #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ACadSharp/Classes/DxfClassCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ public static void UpdateDxfClasses(CadDocument doc)
ProxyFlags = ProxyFlags.EraseAllowed | ProxyFlags.DisablesProxyWarningDialog,
WasZombie = false,
});

//AcDbMLeaderObjectContextData
doc.Classes.AddOrUpdate(new DxfClass {
CppClassName = DxfSubclassMarker.MultiLeaderObjectContextData,
ClassNumber = (short)(500 + doc.Classes.Count),
DwgVersion = ACadVersion.MC0_0,
DxfName = DxfFileToken.ObjectMLeaderContextData,
ItemClassId = 499,
MaintenanceVersion = 0,
ProxyFlags = ProxyFlags.EraseAllowed | ProxyFlags.DisablesProxyWarningDialog,
WasZombie = false,
});
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static class DxfFileToken
public const string ObjectScale = "SCALE";
public const string ObjectSortEntsTable = "SORTENTSTABLE";
public const string ObjectXRecord = "XRECORD";
public const string ObjectMLeaderContextData = "CONTEXT_DATA";
public const string ObjectMLeaderContextData = "ACDB_MLEADEROBJECTCONTEXTDATA_CLASS";
public const string ObjectEvalGraph = "ACAD_EVALUATION_GRAPH";
public const string ObjectBlockLinearParameter = "BLOCKLINEARPARAMETER";
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";
Expand Down
4 changes: 3 additions & 1 deletion src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class DxfSubclassMarker
public const string Material = "AcDbMaterial";
public const string MultiLeader = "AcDbMLeader";
public const string MLeaderStyle = "AcDbMLeaderStyle";
public const string MultiLeaderAnnotContext = "AcDbMultiLeaderAnnotContext";
public const string MultiLeaderObjectContextData = "AcDbMLeaderObjectContextData";
public const string LwPolyline = "AcDbPolyline";
public const string PolylineVertex = "AcDb2dVertex";
public const string Polyline3d = "AcDb3dPolyline";
Expand Down Expand Up @@ -85,6 +85,8 @@ public static class DxfSubclassMarker
public const string DictionaryVariables = "DictionaryVariables";
public const string Scale = "AcDbScale";
public const string GeoData = "AcDbGeoData";
public const string ObjectContextData = "AcDbObjectContextData";
public const string AnnotScaleObjectContextData = "AcDbAnnotScaleObjectContextData";

//Dynamic block constants
public const string EvalGraph = "AcDbEvalGraph";
Expand Down
131 changes: 83 additions & 48 deletions src/ACadSharp/Entities/MultiLeader.cs

Large diffs are not rendered by default.

69 changes: 61 additions & 8 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Linq;
using System.IO;
using System;
using static ACadSharp.Objects.MultiLeaderAnnotContext;
using static ACadSharp.Objects.MultiLeaderObjectContextData;
using CSUtilities.Converters;
using CSUtilities.Extensions;
using System.Globalization;
Expand Down Expand Up @@ -1053,6 +1053,9 @@ private CadTemplate readUnlistedType(short classNumber)
case "MULTILEADER":
template = this.readMultiLeader();
break;
case "ACDB_MLEADEROBJECTCONTEXTDATA_CLASS":
template = this.readMultiLeaderAnnotContext();
break;
case "MLEADERSTYLE":
template = this.readMultiLeaderStyle();
break;
Expand Down Expand Up @@ -3111,6 +3114,7 @@ private CadTemplate readMultiLeader()
{
MultiLeader mLeader = new MultiLeader();
CadMLeaderTemplate template = new CadMLeaderTemplate(mLeader);
template.CadMLeaderAnnotContextTemplate = new CadMLeaderAnnotContextTemplate(mLeader.ContextData);

this.readCommonEntityData(template);

Expand All @@ -3120,7 +3124,7 @@ private CadTemplate readMultiLeader()
var f270 = this._objectReader.ReadBitShort();
}

this.readMultiLeaderAnnotContext(mLeader.ContextData, template);
this.readMultiLeaderAnnotContext(mLeader.ContextData, template.CadMLeaderAnnotContextTemplate);

// Multileader Common data
// 340 Leader StyleId (handle)
Expand Down Expand Up @@ -3246,10 +3250,59 @@ private CadTemplate readMultiLeader()
return template;
}

private MultiLeaderAnnotContext readMultiLeaderAnnotContext(MultiLeaderAnnotContext annotContext, CadMLeaderTemplate template)
private CadTemplate readObjectContextData(CadTemplate template)
{
this.readCommonNonEntityData(template);
ObjectContextData contextData = (ObjectContextData)template.CadObject;

//BS 70 Version (default value is 3).
contextData.Version = _objectReader.ReadBitShort();
//B - Has file to extension dictionary (default value is true).
contextData.HasFileToExtensionDictionary = _objectReader.ReadBit();
//B 290 Default flag (default value is false).
contextData.Default = _objectReader.ReadBit();

return template;
}


private CadTemplate readAnnotScaleObjectContextData(CadAnnotScaleObjectContextDataTemplate template)
{
this.readObjectContextData(template);
template.ScaleHandle = this.handleReference();

return template;
}

private CadTemplate readMultiLeaderAnnotContext()
{
MultiLeaderObjectContextData annotContext = new MultiLeaderObjectContextData();
CadMLeaderAnnotContextTemplate template = new CadMLeaderAnnotContextTemplate(annotContext);

this.readAnnotScaleObjectContextData(template);
this.readMultiLeaderAnnotContext(annotContext, template);

return template;
}


private MultiLeaderObjectContextData readMultiLeaderAnnotContext(MultiLeaderObjectContextData annotContext, CadMLeaderAnnotContextTemplate template)
{
// BL - Number of leader roots
int leaderRootCount = this._objectReader.ReadBitLong();
if (leaderRootCount == 0)
{
bool b0 = _objectReader.ReadBit();
bool b1 = _objectReader.ReadBit();
bool b2 = _objectReader.ReadBit();
bool b3 = _objectReader.ReadBit();
bool b4 = _objectReader.ReadBit();
bool b5 = _objectReader.ReadBit();
bool b6 = _objectReader.ReadBit();

leaderRootCount = b5 ? 2 : 1;
}

for (int i = 0; i < leaderRootCount; i++)
{
annotContext.LeaderRoots.Add(this.readLeaderRoot(template));
Expand Down Expand Up @@ -3283,7 +3336,7 @@ private MultiLeaderAnnotContext readMultiLeaderAnnotContext(MultiLeaderAnnotCont
// 3BD 11 Normal vector
annotContext.TextNormal = this._objectReader.Read3BitDouble();
// H 340 Text style handle (hard pointer)
template.AnnotContextTextStyleHandle = this.handleReference();
template.TextStyleHandle = this.handleReference();
// 3BD 12 Location
annotContext.TextLocation = this._objectReader.Read3BitDouble();
// 3BD 13 Direction
Expand Down Expand Up @@ -3344,7 +3397,7 @@ private MultiLeaderAnnotContext readMultiLeaderAnnotContext(MultiLeaderAnnotCont
//B 296 Has contents block
//IF Has contents block
// H 341 AcDbBlockTableRecord handle (soft pointer)
template.AnnotContextBlockRecordHandle = this.handleReference();
template.BlockRecordHandle = this.handleReference();
// 3BD 14 Normal vector
annotContext.BlockContentNormal = this._objectReader.Read3BitDouble();
// 3BD 15 Location
Expand Down Expand Up @@ -3410,7 +3463,7 @@ private MultiLeaderAnnotContext readMultiLeaderAnnotContext(MultiLeaderAnnotCont
return annotContext;
}

private LeaderRoot readLeaderRoot(CadMLeaderTemplate template)
private LeaderRoot readLeaderRoot(CadMLeaderAnnotContextTemplate template)
{
LeaderRoot leaderRoot = new LeaderRoot();

Expand Down Expand Up @@ -3457,10 +3510,10 @@ private LeaderRoot readLeaderRoot(CadMLeaderTemplate template)
return leaderRoot;
}

private LeaderLine readLeaderLine(CadMLeaderTemplate template)
private LeaderLine readLeaderLine(CadMLeaderAnnotContextTemplate template)
{
LeaderLine leaderLine = new LeaderLine();
CadMLeaderTemplate.LeaderLineSubTemplate leaderLineSubTemplate = new CadMLeaderTemplate.LeaderLineSubTemplate(leaderLine);
CadMLeaderAnnotContextTemplate.LeaderLineSubTemplate leaderLineSubTemplate = new CadMLeaderAnnotContextTemplate.LeaderLineSubTemplate(leaderLine);
template.LeaderLineSubTemplates.Add(leaderLineSubTemplate);

// Points
Expand Down
37 changes: 25 additions & 12 deletions src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ private void writeMultiLeader(MultiLeader multiLeader)
this._writer.WriteBitShort(2);
}

writeMultiLeaderAnnotContext(multiLeader.ContextData);
writeMultiLeaderAnnotContextSubObject(true, multiLeader.ContextData);

// Multileader Common data
// 340 Leader StyleId (handle)
Expand All @@ -1143,7 +1143,7 @@ private void writeMultiLeader(MultiLeader multiLeader)
this._writer.WriteBitLong((int)multiLeader.PropertyOverrideFlags);
// 170 LeaderLineType (short)
this._writer.WriteBitShort((short)multiLeader.PathType);
// 91 Leader LineColor (Color)
// 91 Leade LineColor (Color)
this._writer.WriteCmColor(multiLeader.LineColor);
// 341 LeaderLineTypeID (handle/LineType)
this._writer.HandleReference(DwgReferenceType.HardPointer, multiLeader.LeaderLineType);
Expand Down Expand Up @@ -1235,12 +1235,25 @@ private void writeMultiLeader(MultiLeader multiLeader)
}
}

private void writeMultiLeaderAnnotContext(MultiLeaderAnnotContext annotContext)
{

// BL - Number of leader roots
private void writeMultiLeaderAnnotContextSubObject(bool writeLeaderRootsCount, MultiLeaderObjectContextData annotContext)
{
int leaderRootCount = annotContext.LeaderRoots.Count;
this._writer.WriteBitLong(leaderRootCount);
if (writeLeaderRootsCount) {
// BL - Number of leader roots
this._writer.WriteBitLong(leaderRootCount);
}
else {
this._writer.WriteBitLong(0);
this._writer.WriteBit(false); // b0
this._writer.WriteBit(false); // b1
this._writer.WriteBit(false); // b2
this._writer.WriteBit(false); // b3
this._writer.WriteBit(false); // b4
this._writer.WriteBit(leaderRootCount == 2); // b5
this._writer.WriteBit(leaderRootCount == 1); // b6
}

for (int i = 0; i < leaderRootCount; i++)
{
writeLeaderRoot(annotContext.LeaderRoots[i]);
Expand Down Expand Up @@ -1397,7 +1410,7 @@ private void writeMultiLeaderAnnotContext(MultiLeaderAnnotContext annotContext)
}
}

private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
private void writeLeaderRoot(MultiLeaderObjectContextData.LeaderRoot leaderRoot)
{
// B 290 Is content valid(ODA writes true)/DXF: Has Set Last Leader Line Point
this._writer.WriteBit(leaderRoot.ContentValid);
Expand All @@ -1413,7 +1426,7 @@ private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
// 3BD 12 Break start point
// 3BD 13 Break end point
this._writer.WriteBitLong(leaderRoot.BreakStartEndPointsPairs.Count);
foreach (MultiLeaderAnnotContext.StartEndPointPair startEndPointPair in leaderRoot.BreakStartEndPointsPairs)
foreach (MultiLeaderObjectContextData.StartEndPointPair startEndPointPair in leaderRoot.BreakStartEndPointsPairs)
{
this._writer.Write3BitDouble(startEndPointPair.StartPoint);
this._writer.Write3BitDouble(startEndPointPair.EndPoint);
Expand All @@ -1427,7 +1440,7 @@ private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
// Leader lines
// BL Number of leader lines
this._writer.WriteBitLong(leaderRoot.Lines.Count);
foreach (MultiLeaderAnnotContext.LeaderLine leaderLine in leaderRoot.Lines)
foreach (MultiLeaderObjectContextData.LeaderLine leaderLine in leaderRoot.Lines)
{
writeLeaderLine(leaderLine);
}
Expand All @@ -1439,7 +1452,7 @@ private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
}
}

private void writeLeaderLine(MultiLeaderAnnotContext.LeaderLine leaderLine)
private void writeLeaderLine(MultiLeaderObjectContextData.LeaderLine leaderLine)
{
// Points
// BL - Number of points
Expand All @@ -1462,7 +1475,7 @@ private void writeLeaderLine(MultiLeaderAnnotContext.LeaderLine leaderLine)
// Start/end point pairs
// 3BD 12 End point
this._writer.WriteBitLong(leaderLine.StartEndPoints.Count);
foreach (MultiLeaderAnnotContext.StartEndPointPair sep in leaderLine.StartEndPoints)
foreach (MultiLeaderObjectContextData.StartEndPointPair sep in leaderLine.StartEndPoints)
{
// 3BD 11 Start Point
this._writer.Write3BitDouble(sep.StartPoint);
Expand Down Expand Up @@ -2449,4 +2462,4 @@ private void writeChildEntities(IEnumerable<Entity> entities, Seqend seqend)
}
}
}
}
}
24 changes: 23 additions & 1 deletion src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ private void writeObject(CadObject obj)
case MultiLeaderStyle multiLeaderStyle:
this.writeMultiLeaderStyle(multiLeaderStyle);
break;
case MultiLeaderObjectContextData multiLeaderObjectContextData:
this.writeObjectContextData(multiLeaderObjectContextData);
this.writeAnnotScaleObjectContextData(multiLeaderObjectContextData);
this.writeMultiLeaderAnnotContext(multiLeaderObjectContextData);
break;
case PlotSettings plotsettings:
this.writePlotSettings(plotsettings);
break;
Expand Down Expand Up @@ -644,6 +649,23 @@ private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
}
}

private void writeObjectContextData(ObjectContextData objectContextData) {
//BS 70 Version.
this._writer.WriteBitShort(objectContextData.Version);
//B - Has file to extension dictionary.
this._writer.WriteBit(objectContextData.HasFileToExtensionDictionary);
//B 290 Default flag.
this._writer.WriteBit(objectContextData.Default);
}

private void writeAnnotScaleObjectContextData(AnnotScaleObjectContextData annotScaleObjectContextData) {
this._writer.HandleReference(DwgReferenceType.HardPointer, annotScaleObjectContextData.Scale);
}

private void writeMultiLeaderAnnotContext(MultiLeaderObjectContextData multiLeaderAnnotContext) {
writeMultiLeaderAnnotContextSubObject(false, multiLeaderAnnotContext);
}

private void writePlotSettings(PlotSettings plot)
{
//Common:
Expand Down Expand Up @@ -774,7 +796,7 @@ private void writeXRecord(XRecord xrecord)
ms.EndianConverter = new LittleEndianConverter();

foreach (XRecord.Entry entry in xrecord.Entries)
{
{
if (entry.Value == null)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void writeObject<T>(T co)
case AcdbPlaceHolder:
case EvaluationGraph:
case Material:
case MultiLeaderAnnotContext:
case MultiLeaderObjectContextData:
case VisualStyle:
case ImageDefinitionReactor:
case UnknownNonGraphicalObject:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ private void writeMText(MText mtext, bool writeSubclass = true)

private void writeMultiLeader(MultiLeader multiLeader)
{
MultiLeaderAnnotContext contextData = multiLeader.ContextData;
MultiLeaderObjectContextData contextData = multiLeader.ContextData;

this._writer.Write(100, "AcDbMLeader");

Expand Down Expand Up @@ -754,7 +754,7 @@ private void writeMultiLeader(MultiLeader multiLeader)
this._writer.Write(295, 0);
}

private void writeMultiLeaderAnnotContext(MultiLeaderAnnotContext contextData)
private void writeMultiLeaderAnnotContext(MultiLeaderObjectContextData contextData)
{
this._writer.Write(300, "CONTEXT_DATA{");
this._writer.Write(40, contextData.ScaleFactor);
Expand Down Expand Up @@ -811,7 +811,7 @@ private void writeMultiLeaderAnnotContext(MultiLeaderAnnotContext contextData)

this._writer.Write(297, contextData.NormalReversed);

foreach (MultiLeaderAnnotContext.LeaderRoot leaderRoot in contextData.LeaderRoots)
foreach (MultiLeaderObjectContextData.LeaderRoot leaderRoot in contextData.LeaderRoots)
{
writeLeaderRoot(leaderRoot);
}
Expand All @@ -821,7 +821,7 @@ private void writeMultiLeaderAnnotContext(MultiLeaderAnnotContext contextData)
this._writer.Write(301, "}"); // CONTEXT_DATA
}

private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
private void writeLeaderRoot(MultiLeaderObjectContextData.LeaderRoot leaderRoot)
{
this._writer.Write(302, "LEADER{");

Expand All @@ -836,7 +836,7 @@ private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
this._writer.Write(90, leaderRoot.LeaderIndex);
this._writer.Write(40, leaderRoot.LandingDistance);

foreach (MultiLeaderAnnotContext.LeaderLine leaderLine in leaderRoot.Lines)
foreach (MultiLeaderObjectContextData.LeaderLine leaderLine in leaderRoot.Lines)
{
writeLeaderLine(leaderLine);
}
Expand All @@ -845,7 +845,7 @@ private void writeLeaderRoot(MultiLeaderAnnotContext.LeaderRoot leaderRoot)
this._writer.Write(303, "}"); // LEADER
}

private void writeLeaderLine(MultiLeaderAnnotContext.LeaderLine leaderLine)
private void writeLeaderLine(MultiLeaderObjectContextData.LeaderLine leaderLine)
{
this._writer.Write(304, "LEADER_LINE{");

Expand Down
Loading