Skip to content
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

Tolerance entity #235

Merged
merged 5 commits into from
Jan 4, 2024
Merged
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
54 changes: 54 additions & 0 deletions ACadSharp.Tests/Data/document_tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,60 @@
"OwnerHandle": 31,
"DictionaryHandle": 0,
"Children": []
},
{
"Color": null,
"LayerName": "0",
"IsInvisible": false,
"Transparency": {
"IsByLayer": false,
"IsByBlock": false,
"Value": 0
},
"LinetypeName": "ByLayer",
"LinetypeScale": 1.0,
"LineWeight": -1,
"ACadName": "Autodesk.AutoCAD.DatabaseServices.FeatureControlFrame",
"Handle": 2082,
"OwnerHandle": 31,
"DictionaryHandle": 0,
"Children": []
},
{
"Color": null,
"LayerName": "0",
"IsInvisible": false,
"Transparency": {
"IsByLayer": false,
"IsByBlock": false,
"Value": 0
},
"LinetypeName": "ByLayer",
"LinetypeScale": 1.0,
"LineWeight": -1,
"ACadName": "Autodesk.AutoCAD.DatabaseServices.FeatureControlFrame",
"Handle": 2083,
"OwnerHandle": 31,
"DictionaryHandle": 0,
"Children": []
},
{
"Color": null,
"LayerName": "0",
"IsInvisible": false,
"Transparency": {
"IsByLayer": false,
"IsByBlock": false,
"Value": 0
},
"LinetypeName": "ByLayer",
"LinetypeScale": 1.0,
"LineWeight": -1,
"ACadName": "Autodesk.AutoCAD.DatabaseServices.FeatureControlFrame",
"Handle": 2084,
"OwnerHandle": 31,
"DictionaryHandle": 0,
"Children": []
}
],
"Name": "*Model_Space",
Expand Down
33 changes: 0 additions & 33 deletions ACadSharp.Tests/IO/DWG/DwgWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,5 @@ private void addEntities(CadDocument doc)
doc.Entities.Add(EntityFactory.Create<Point>());
doc.Entities.Add(EntityFactory.Create<Line>());
}

private bool isSupportedVersion(ACadVersion version)
{
switch (version)
{
case ACadVersion.MC0_0:
case ACadVersion.AC1_2:
case ACadVersion.AC1_4:
case ACadVersion.AC1_50:
case ACadVersion.AC2_10:
case ACadVersion.AC1002:
case ACadVersion.AC1003:
case ACadVersion.AC1004:
case ACadVersion.AC1006:
case ACadVersion.AC1009:
case ACadVersion.AC1012:
return false;
case ACadVersion.AC1014:
case ACadVersion.AC1015:
case ACadVersion.AC1018:
return true;
case ACadVersion.AC1021:
return false;
case ACadVersion.AC1024:
return true;
case ACadVersion.AC1027:
case ACadVersion.AC1032:
return true;
case ACadVersion.Unknown:
default:
return false;
}
}
}
}
33 changes: 33 additions & 0 deletions ACadSharp.Tests/IO/IOTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,38 @@ protected static void loadSamples(string folder, string ext, TheoryData<string>
files.Add(string.Empty);
}
}

protected bool isSupportedVersion(ACadVersion version)
{
switch (version)
{
case ACadVersion.MC0_0:
case ACadVersion.AC1_2:
case ACadVersion.AC1_4:
case ACadVersion.AC1_50:
case ACadVersion.AC2_10:
case ACadVersion.AC1002:
case ACadVersion.AC1003:
case ACadVersion.AC1004:
case ACadVersion.AC1006:
case ACadVersion.AC1009:
case ACadVersion.AC1012:
return false;
case ACadVersion.AC1014:
case ACadVersion.AC1015:
case ACadVersion.AC1018:
return true;
case ACadVersion.AC1021:
return false;
case ACadVersion.AC1024:
return true;
case ACadVersion.AC1027:
case ACadVersion.AC1032:
return true;
case ACadVersion.Unknown:
default:
return false;
}
}
}
}
3 changes: 0 additions & 3 deletions ACadSharp/Entities/Dimension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public DimensionType Flags
[DxfCodeValue(42)]
public double Measurement { get; internal set; }


/// <summary>
/// Gets or sets a value indicating whether the first arrow
/// is to be flipped.
Expand All @@ -120,7 +119,6 @@ public DimensionType Flags
[DxfCodeValue(74)]
public bool FlipArrow1 { get; set; }


/// <summary>
/// Gets or sets a value indicating whether the second arrow
/// to be flipped.
Expand All @@ -135,7 +133,6 @@ public DimensionType Flags
[DxfCodeValue(75)]
public bool FlipArrow2 { get; set; }


/// <summary>
/// Dimension text explicitly entered by the user
/// </summary>
Expand Down
79 changes: 79 additions & 0 deletions ACadSharp/Entities/Tolerance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using ACadSharp.Attributes;
using ACadSharp.Tables;
using CSMath;
using System;

namespace ACadSharp.Entities
{
/// <summary>
/// Represents a <see cref="Tolerance"/> entity.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.EntityTolerance"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.Tolerance"/>
/// </remarks>
[DxfName(DxfFileToken.EntityTolerance)]
[DxfSubClass(DxfSubclassMarker.Tolerance)]
public class Tolerance : Entity
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.TOLERANCE;

/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityTolerance;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.Tolerance;

/// <summary>
/// Dimension style
/// </summary>
[DxfCodeValue(DxfReferenceType.Name, 3)]
public DimensionStyle Style
{
get { return this._style; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

if (this.Document != null)
{
this._style = this.updateTable(value, this.Document.DimensionStyles);
}
else
{
this._style = value;
}
}
}

/// <summary>
/// Insertion point (in WCS)
/// </summary>
[DxfCodeValue(10, 20, 30)]
public XYZ InsertionPoint { get; set; }

/// <summary>
/// X-axis direction vector (in WCS)
/// </summary>
[DxfCodeValue(11, 21, 31)]
public XYZ Direction { get; set; }

/// <summary>
/// Specifies the three-dimensional normal unit vector for the object.
/// </summary>
[DxfCodeValue(210, 220, 230)]
public XYZ Normal { get; set; } = XYZ.AxisZ;

/// <summary>
/// Visual representation of the tolerance
/// </summary>
[DxfCodeValue(1)]
public string Text { get; set; }

private DimensionStyle _style = DimensionStyle.Default;
}
}
38 changes: 38 additions & 0 deletions ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System;
using ACadSharp.Types;
using static ACadSharp.Objects.MultiLeaderAnnotContext;
using System.Net;

namespace ACadSharp.IO.DWG
{
Expand Down Expand Up @@ -828,6 +829,7 @@ private CadTemplate readObject(ObjectType type)
template = this.readLeader();
break;
case ObjectType.TOLERANCE:
template = this.readTolerance();
break;
case ObjectType.MLINE:
template = this.readMLine();
Expand Down Expand Up @@ -3314,6 +3316,42 @@ private CadTemplate readMultiLeaderStyle()
return template;
}

private CadTemplate readTolerance()
{
Tolerance tolerance = new Tolerance();
CadToleranceTemplate template = new CadToleranceTemplate(tolerance);

//Common Entity Data
this.readCommonEntityData(template);

//R13 - R14 Only:
if (this.R13_14Only)
{
//Unknown short S
short s = this._objectReader.ReadBitShort();
//Height BD --
double height = this._objectReader.ReadBitDouble();
//Dimgap(?) BD dimgap at time of creation, *dimscale
double dimscale = this._objectReader.ReadBitDouble();
}

//Common:
//Ins pt 3BD 10
tolerance.InsertionPoint = this._objectReader.Read3BitDouble();
//X direction 3BD 11
tolerance.Direction = this._objectReader.Read3BitDouble();
//Extrusion 3BD 210 etc.
tolerance.Normal = this._objectReader.Read3BitDouble();
//Text string BS 1
tolerance.Text = this._textReader.ReadVariableText();

//Common Entity Handle Data
//H DIMSTYLE(hard pointer)
template.DimensionStyleHandle = this.handleReference();

return template;
}

private CadTemplate readMLine()
{
MLine mline = new MLine();
Expand Down
36 changes: 34 additions & 2 deletions ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ACadSharp.Entities;
using CSMath;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -147,9 +146,12 @@ private void writeEntity(Entity entity)
this.writeTextEntity(textEntity);
break;
default:
throw new NotImplementedException($"Entity not implemented : {entity.GetType().FullName}");
throw new NotImplementedException($"TextEntity not implemented : {entity.GetType().FullName}");
}
break;
case Tolerance tolerance:
this.writeTolerance(tolerance);
break;
case Vertex vertex:
switch (vertex)
{
Expand Down Expand Up @@ -1800,6 +1802,36 @@ private void writeVertex(Vertex vertex)
this._writer.Write3BitDouble(vertex.Location);
}

private void writeTolerance(Tolerance tolerance)
{
this.writeCommonEntityData(tolerance);

//R13 - R14 Only:
if (this.R13_14Only)
{
//Unknown short S
this._writer.WriteBitShort(0);
//Height BD --
this._writer.WriteBitDouble(0.0);
//Dimgap(?) BD dimgap at time of creation, *dimscale
this._writer.WriteBitDouble(0.0);
}

//Common:
//Ins pt 3BD 10
this._writer.Write3BitDouble(tolerance.InsertionPoint);
//X direction 3BD 11
this._writer.Write3BitDouble(tolerance.Direction);
//Extrusion 3BD 210 etc.
this._writer.Write3BitDouble(tolerance.Normal);
//Text string BS 1
this._writer.WriteVariableText(tolerance.Text);

//Common Entity Handle Data
//H DIMSTYLE(hard pointer)
this._writer.HandleReference(DwgReferenceType.HardPointer, tolerance.Style);
}

private void writeViewport(Viewport viewport)
{
//Center 3BD 10
Expand Down
Loading
Loading