Skip to content

Commit

Permalink
pts n faces
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Feb 2, 2025
1 parent 6334567 commit b6bd56b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 18 deletions.
33 changes: 33 additions & 0 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4896,6 +4896,9 @@ private CadTemplate readGeoData()
//H Soft pointer to host block
template.HostBlockHandle = this.handleReference();

//BS Design coordinate type
geoData.CoordinatesType = (DesignCoordinatesType)this._mergedReaders.ReadBitShort();

switch (geoData.Version)
{
case GeoDataVersion.R2009:
Expand Down Expand Up @@ -4975,6 +4978,36 @@ private CadTemplate readGeoData()

//VT Observation from tag
geoData.ObservationFromTag = this._mergedReaders.ReadVariableText();
//VT Observation to tag
geoData.ObservationToTag = this._mergedReaders.ReadVariableText();
//VT Observation coverage tag
geoData.ObservationCoverageTag = this._mergedReaders.ReadVariableText();

//BL Number of geo mesh points
int npts = this._mergedReaders.ReadBitLong();
for (int i = 0; i < npts; i++)
{
var pt = new GeoData.GeoMeshPoint();
//2RD Source point
pt.Source = this._mergedReaders.Read2RawDouble();
//2RD Destination point
pt.Destination = this._mergedReaders.Read2RawDouble();
geoData.Points.Add(pt);
}

//BL Number of geo mesh faces
int nfaces = this._mergedReaders.ReadBitLong();
for (int i = 0; i < nfaces; i++)
{
var face = new GeoData.GeoMeshFace();
//BL Face index 1
face.Index1 = this._mergedReaders.ReadBitLong();
//BL Face index 2
face.Index2 = this._mergedReaders.ReadBitLong();
//BL Face index 3
face.Index3 = this._mergedReaders.ReadBitLong();
geoData.Faces.Add(face);
}

return template;
}
Expand Down
81 changes: 67 additions & 14 deletions src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using ACadSharp.Objects;
using ACadSharp.Objects.Evaluations;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using static ACadSharp.IO.Templates.CadEvaluationGraphTemplate;

namespace ACadSharp.IO.DXF
Expand Down Expand Up @@ -71,7 +71,7 @@ private CadTemplate readObject()
case DxfFileToken.ObjectSortEntsTable:
return this.readSortentsTable();
case DxfFileToken.ObjectGeoData:
return this.readObjectCodes<GeoData>(new CadNonGraphicalObjectTemplate(new GeoData()), this.readObjectSubclassMap);
return this.readObjectCodes<GeoData>(new CadGeoDataTemplate(), this.readGeoData);
case DxfFileToken.ObjectScale:
return this.readObjectCodes<Scale>(new CadTemplate<Scale>(new Scale()), this.readScale);
case DxfFileToken.ObjectTableContent:
Expand Down Expand Up @@ -191,12 +191,7 @@ private bool readEvaluationGraph(CadTemplate template, DxfMap map)
tmp.NodeTemplates.Add(nodeTemplate);
}

if (this._reader.DxfCode == DxfCode.Start)
{
return true;
}

return this.readEvaluationGraph(template, map);
return this.checkObjectEnd(template, map, this.readEvaluationGraph);
case 92:
//Edges
while (this._reader.Code == 92)
Expand All @@ -214,12 +209,7 @@ private bool readEvaluationGraph(CadTemplate template, DxfMap map)
this._reader.ReadNext();
}

if(this._reader.DxfCode == DxfCode.Start)
{
return true;
}

return this.readEvaluationGraph(template, map);
return this.checkObjectEnd(template, map, this.readEvaluationGraph);
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.EvalGraph]);
}
Expand All @@ -246,6 +236,69 @@ private bool readLayout(CadTemplate template, DxfMap map)
}
}

private bool readGeoData(CadTemplate template, DxfMap map)
{
CadGeoDataTemplate tmp = template as CadGeoDataTemplate;

switch (this._reader.Code)
{
// Number of Geo-Mesh points
case 93:
var npts = this._reader.ValueAsInt;
for (int i = 0; i < npts; i++)
{
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 13);
double sourceX = this._reader.ValueAsDouble;
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 23);
double sourceY = this._reader.ValueAsDouble;

this._reader.ReadNext();
Debug.Assert(this._reader.Code == 14);
double destX = this._reader.ValueAsDouble;
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 24);
double destY = this._reader.ValueAsDouble;

tmp.CadObject.Points.Add(new GeoData.GeoMeshPoint
{
Source = new CSMath.XY(sourceX, sourceY),
Destination = new CSMath.XY(destX, destY)
});
}
return true;
// Number of Geo-Mesh points
case 96:
var nfaces = this._reader.ValueAsInt;
for (int i = 0; i < nfaces; i++)
{
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 97);
int index1 = this._reader.ValueAsInt;
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 98);
int index2 = this._reader.ValueAsInt;
this._reader.ReadNext();
Debug.Assert(this._reader.Code == 99);
int index3 = this._reader.ValueAsInt;

tmp.CadObject.Faces.Add(new GeoData.GeoMeshFace
{
Index1 = index1,
Index2 = index2,
Index3 = index3
});
}
return true;
case 303:
tmp.CadObject.CoordinateSystemDefinition += this._reader.ValueAsString;
return true;
default:
return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
}
}

private bool readScale(CadTemplate template, DxfMap map)
{
switch (this._reader.Code)
Expand Down
17 changes: 13 additions & 4 deletions src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExte
}
}

protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
{
if (this._reader.DxfCode == DxfCode.Start)
{
return true;
}
else
{
return func.Invoke(template, map);
}
}

private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
{
switch (this._reader.Code)
Expand Down Expand Up @@ -607,9 +619,6 @@ protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass
case 53:
hatch.PatternAngle = this._reader.ValueAsAngle;
return true;
//Number of dash length items
case 79:
return true;
//TODO: Check hatch undocumented codes
case 90:
return true;
Expand Down Expand Up @@ -1724,7 +1733,7 @@ protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)

if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
{
value = (double)value * MathUtils.DegToRadFactor;
value = (double)value * MathHelper.DegToRadFactor;
}

dxfProperty.SetValue(this._reader.Code, cadObject, value);
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/IO/Templates/CadGeoDataTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ internal class CadGeoDataTemplate : CadTemplate<GeoData>
{
public ulong? HostBlockHandle { get; set; }

public CadGeoDataTemplate() : base(new GeoData()) { }

public CadGeoDataTemplate(GeoData geodata) : base(geodata) { }

public override void Build(CadDocumentBuilder builder)
Expand Down
26 changes: 26 additions & 0 deletions src/ACadSharp/Objects/GeoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACadSharp.Types.Units;
using CSMath;
using System;
using System.Collections.Generic;

namespace ACadSharp.Objects
{
Expand Down Expand Up @@ -183,6 +184,31 @@ public BlockRecord HostBlock
[DxfCodeValue(307)]
public string ObservationCoverageTag { get; set; } = string.Empty;

[DxfCodeValue(DxfReferenceType.Count, 93)]
public List<GeoMeshPoint> Points { get; } = new();

[DxfCodeValue(DxfReferenceType.Count, 96)]
public List<GeoMeshFace> Faces { get; } = new();

private BlockRecord _hostBlock;

public class GeoMeshPoint
{
[DxfCodeValue(13, 23)]
public XY Source { get; set; }

[DxfCodeValue(14, 24)]
public XY Destination { get; set; }
}

public class GeoMeshFace
{
[DxfCodeValue(97)]
public int Index1 { get; set; }
[DxfCodeValue(98)]
public int Index2 { get; set; }
[DxfCodeValue(99)]
public int Index3 { get; set; }
}
}
}

0 comments on commit b6bd56b

Please sign in to comment.