Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
140ea41
added test
DomCR Apr 12, 2023
bf16f31
placeholder
DomCR Apr 12, 2023
66a1137
Merge remote-tracking branch 'origin/master' into DwgWriter-Insert
DomCR Apr 15, 2023
afd0848
Merge remote-tracking branch 'origin/master' into DwgWriter-Insert
DomCR Apr 21, 2023
7ec5f56
test
DomCR Apr 21, 2023
8f3ddca
method
DomCR Apr 28, 2023
8e897ff
Merge remote-tracking branch 'origin/master' into DwgWriter-Insert
DomCR May 10, 2023
e354a10
added exception
DomCR Oct 9, 2023
d676e0a
added tests
DomCR Oct 9, 2023
40aad88
LwPolyline
DomCR Oct 9, 2023
1352d12
Face3D
DomCR Oct 9, 2023
d85dc75
ignore Hatch
DomCR Oct 9, 2023
05063ef
Xline
DomCR Oct 9, 2023
bf07b71
Ray
DomCR Oct 9, 2023
2b88d49
Mline
DomCR Oct 9, 2023
614ea4d
PolyfaceMesh
DomCR Oct 9, 2023
6beecf2
PolyfaceMesh
DomCR Oct 10, 2023
73b0dc1
Polyline3D
DomCR Oct 10, 2023
6fbc7fe
Solid
DomCR Oct 10, 2023
cf8a0b9
Spline
DomCR Oct 10, 2023
1a137c1
ignore unlisted
DomCR Oct 10, 2023
051b04b
Leader
DomCR Oct 10, 2023
d16424a
ignore Insert
DomCR Oct 10, 2023
ad6015f
unignore hatch
DomCR Oct 10, 2023
35b5f9f
store dictionaries
DomCR Oct 11, 2023
9233509
Merge remote-tracking branch 'origin/DwgWriter-entities' into DwgWrit…
DomCR Oct 11, 2023
c3271e5
writeDictionaries
DomCR Oct 12, 2023
8ecb847
hatch writer
DomCR Oct 13, 2023
ce2f898
test
DomCR Oct 13, 2023
de31d01
viewport
DomCR Oct 14, 2023
cef930e
Merge pull request #177 from DomCR/DwgWriter-hatch
DomCR Oct 14, 2023
20b5fd8
Merge remote-tracking branch 'origin/master' into DwgWriter-entities
DomCR Oct 14, 2023
b592fac
Merge remote-tracking branch 'origin/DwgWriter-entities' into DwgWrit…
DomCR Oct 14, 2023
de7f905
objects
DomCR Oct 14, 2023
2e766da
xrecord
DomCR Oct 14, 2023
be3c94f
register entities
DomCR Oct 14, 2023
ac7716b
xrecord placeholder
DomCR Oct 14, 2023
5451061
Vertex2D
DomCR Oct 15, 2023
b8a4b06
test placeholder
DomCR Oct 15, 2023
670f52a
group
DomCR Oct 15, 2023
e82bd67
AcdbPlaceHolder
DomCR Oct 15, 2023
472f034
PlotSettings
DomCR Oct 15, 2023
7778beb
Layout
DomCR Oct 16, 2023
d68c63e
merge with base
DomCR Oct 16, 2023
f79d7ce
insert
DomCR Oct 16, 2023
466a97d
child
DomCR Oct 16, 2023
4396caf
write atts
DomCR Oct 16, 2023
43f282e
unignore
DomCR Oct 16, 2023
802dc20
AttributeBase ignore
DomCR Oct 16, 2023
978170e
cleanup
DomCR Oct 16, 2023
ddffbf1
Merge pull request #123 from DomCR/DwgWriter-Insert
DomCR Oct 16, 2023
4393b9d
Polyline2D
DomCR Oct 16, 2023
240bb9e
AttributeEntity
DomCR Oct 17, 2023
304d6ba
AttributeDefinition
DomCR Oct 17, 2023
b311b5e
layer owner repeated
DomCR Oct 17, 2023
b027999
Merge branch 'DwgWriter-entities' into DwgWriter-dictionaries
DomCR Oct 17, 2023
79cddbf
test
DomCR Oct 17, 2023
5ebba3e
order in writer matters
DomCR Oct 18, 2023
3a487a8
MLStyle
DomCR Oct 21, 2023
baacc62
ignore CadDictionaryWithDefault
DomCR Oct 21, 2023
7e6d493
Scale
DomCR Oct 21, 2023
2c519df
unignore scale
DomCR Oct 21, 2023
85e7314
DictionaryVariable
DomCR Oct 21, 2023
70e1983
CadDictionaryWithDefault
DomCR Oct 21, 2023
05acba2
unignore CadDictionaryWithDefault
DomCR Oct 23, 2023
9cd2b30
xrecord placeholder
DomCR Oct 23, 2023
6410328
Merge pull request #180 from DomCR/DwgWriter-dictionaries
DomCR Oct 26, 2023
8be03c1
Merge remote-tracking branch 'origin/master' into DwgWriter-entities
DomCR Oct 26, 2023
99a3864
LineTypeTabe write
DomCR Oct 27, 2023
6b21242
comments
DomCR Oct 27, 2023
6a33da8
ignore shape
DomCR Oct 27, 2023
e9e1d1d
ignore Shape and Solid3D
DomCR Oct 27, 2023
5666ef4
comment
DomCR Oct 27, 2023
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
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Common/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static CadObject createObject(Type type, Type original, bool randomize)
return null;
}

if (type == typeof(XRecrod)
if (type == typeof(XRecord)
|| type == typeof(PlotSettings)
|| type == typeof(Material)
|| type == typeof(MLStyle)
Expand Down
24 changes: 21 additions & 3 deletions ACadSharp.Tests/IO/DWG/DwgWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ namespace ACadSharp.Tests.IO.DWG
{
public class DwgWriterTests : IOTestsBase
{
public static TheoryData<Entity> Entities { get; }

public DwgWriterTests(ITestOutputHelper output) : base(output) { }

static DwgWriterTests()
{
Entities = new TheoryData<Entity>
{
EntityFactory.Create<Point>(),
EntityFactory.Create<Line>(),
};
}

[Theory]
[MemberData(nameof(Versions))]
public void WriteEmptyTest(ACadVersion version)
{
string path = Path.Combine(_samplesOutFolder, $"out_empty_sample_{version}.dwg");
CadDocument doc = new CadDocument();
doc.Header.Version = version;

string path = Path.Combine(_samplesOutFolder, $"out_empty_sample_{version}.dwg");

using (var wr = new DwgWriter(path, doc))
{
if (isSupportedVersion(version))
Expand All @@ -43,19 +53,27 @@ public void WriteEmptyTest(ACadVersion version)
//this.checkDwgDocumentInAutocad(Path.GetFullPath(path));
}

[Theory]
[MemberData(nameof(Entities))]
public void WriteSingleEntityFile(Entity entity)
{

}

[Theory]
[MemberData(nameof(Versions))]
public void WriteTest(ACadVersion version)
{
CadDocument doc = new CadDocument();
doc.Header.Version = version;

addEntities(doc);
this.addEntities(doc);

string path = Path.Combine(_samplesOutFolder, $"out_sample_{version}.dwg");

using (var wr = new DwgWriter(path, doc))
{
wr.OnNotification += this.onNotification;
if (isSupportedVersion(version))
{
wr.Write();
Expand Down
75 changes: 74 additions & 1 deletion ACadSharp.Tests/IO/IOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ public void EmptyDwgToDxf()
this.writeDxfFile(pathOut, doc, true);
}

[Theory]
[MemberData(nameof(DwgFilePaths))]
public void DwgToDwg(string test)
{
CadDocument doc = DwgReader.Read(test);

string file = Path.GetFileNameWithoutExtension(test);
string pathOut = Path.Combine(_samplesOutFolder, $"{file}_out.dwg");

//accoreconsole always fails because cannot recover the file
this.writeDwgFile(pathOut, doc, false);
}

[Theory]
[MemberData(nameof(DwgFilePaths))]
public void DwgToDxf(string test)
Expand All @@ -48,7 +61,28 @@ public void DxfToDxf(string test)

[Theory]
[MemberData(nameof(DwgFilePaths))]
public void DwgEntitiesToNewFile(string test)
public void DwgEntitiesToDwgFile(string test)
{
CadDocument doc = DwgReader.Read(test);

CadDocument transfer = new CadDocument();
transfer.Header.Version = doc.Header.Version;

List<Entity> entities = new List<Entity>(doc.Entities);
foreach (var item in entities)
{
Entity e = doc.Entities.Remove(item);
transfer.Entities.Add(e);
}

string file = Path.GetFileNameWithoutExtension(test);
string pathOut = Path.Combine(_samplesOutFolder, $"{file}_moved_out.dwg");
this.writeDwgFile(pathOut, transfer, false);
}

[Theory]
[MemberData(nameof(DwgFilePaths))]
public void DwgEntitiesToDxfFile(string test)
{
CadDocument doc = DwgReader.Read(test);

Expand All @@ -67,6 +101,33 @@ public void DwgEntitiesToNewFile(string test)
this.writeDxfFile(pathOut, transfer, true);
}

private void writeCadFile(string file, CadWriterBase writer, bool check)
{
using (writer)
{
writer.OnNotification += this.onNotification;
writer.Write();
}

if (check)
this.checkDxfDocumentInAutocad(Path.GetFullPath(file));
}

private void writeDwgFile(string file, CadDocument doc, bool check)
{
if (doc.Header.Version < ACadVersion.AC1014 || doc.Header.Version > ACadVersion.AC1018)
return;

using (DwgWriter writer = new DwgWriter(file, doc))
{
writer.OnNotification += this.onNotification;
writer.Write();
}

if (check)
this.checkDwgDocumentInAutocad(Path.GetFullPath(file));
}

private void writeDxfFile(string file, CadDocument doc, bool check)
{
using (DxfWriter writer = new DxfWriter(file, doc, false))
Expand All @@ -78,5 +139,17 @@ private void writeDxfFile(string file, CadDocument doc, bool check)
if (check)
this.checkDxfDocumentInAutocad(Path.GetFullPath(file));
}

private void writeDwgFile(string file, CadDocument doc)
{
if (doc.Header.Version > ACadVersion.AC1018)
return;

using (DwgWriter writer = new DwgWriter(file, doc))
{
writer.OnNotification += this.onNotification;
writer.Write();
}
}
}
}
2 changes: 1 addition & 1 deletion ACadSharp.Tests/IO/LocalSampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void ReadUserDwg(string test)

CadDocument doc = DwgReader.Read(test, this._dwgConfiguration, this.onNotification);

//return;
return;

string outPath = Path.Combine(Path.GetDirectoryName(test), $"{Path.GetFileNameWithoutExtension(test)}.out.dxf");
using (DxfWriter writer = new DxfWriter(outPath, doc, false))
Expand Down
8 changes: 8 additions & 0 deletions ACadSharp/CadObjectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class CadObjectCollection<T> : IObservableCollection<T>
/// </summary>
public int Count { get { return this._entries.Count; } }

public T this[int index]
{
get
{
return this._entries.ElementAtOrDefault(index);
}
}

protected readonly HashSet<T> _entries = new HashSet<T>();

public CadObjectCollection(CadObject owner)
Expand Down
4 changes: 2 additions & 2 deletions ACadSharp/Entities/Dimension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ public DimensionStyle Style

private readonly DimensionType _flags;

private DimensionStyle _style = DimensionStyle.Default;

protected Dimension(DimensionType type)
{
this._flags = type;
}

private DimensionStyle _style = DimensionStyle.Default;

public override CadObject Clone()
{
Dimension clone = (Dimension)base.Clone();
Expand Down
15 changes: 14 additions & 1 deletion ACadSharp/Entities/Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ namespace ACadSharp.Entities
public class Insert : Entity
{
/// <inheritdoc/>
public override ObjectType ObjectType => ObjectType.INSERT;
public override ObjectType ObjectType
{
get
{
if (this.RowCount > 1 || this.ColumnCount > 1)
{
return ObjectType.MINSERT;
}
else
{
return ObjectType.INSERT;
}
}
}

/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityInsert;
Expand Down
52 changes: 51 additions & 1 deletion ACadSharp/Entities/Leader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using ACadSharp.Tables;
using CSMath;
using System;
using System.Collections.Generic;

namespace ACadSharp.Entities
Expand Down Expand Up @@ -29,7 +30,26 @@ public class Leader : Entity
/// Dimension Style
/// </summary>
[DxfCodeValue(3)]
public DimensionStyle Style { get; set; } = DimensionStyle.Default;
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>
/// Arrowhead flag
Expand Down Expand Up @@ -112,6 +132,36 @@ public class Leader : Entity
[DxfCodeValue(213, 223, 233)]
public XYZ AnnotationOffset { get; set; } = XYZ.Zero;

private DimensionStyle _style = DimensionStyle.Default;

internal override void AssignDocument(CadDocument doc)
{
base.AssignDocument(doc);

this._style = this.updateTable(this.Style, doc.DimensionStyles);

doc.DimensionStyles.OnRemove += this.tableOnRemove;
}

internal override void UnassignDocument()
{
this.Document.DimensionStyles.OnRemove -= this.tableOnRemove;

base.UnassignDocument();

this.Style = (DimensionStyle)this.Style.Clone();
}

protected override void tableOnRemove(object sender, CollectionChangedEventArgs e)
{
base.tableOnRemove(sender, e);

if (e.Item.Equals(this.Style))
{
this.Style = this.Document.DimensionStyles[DimensionStyle.DefaultName];
}
}

public override CadObject Clone()
{
Leader clone = (Leader)base.Clone();
Expand Down
16 changes: 14 additions & 2 deletions ACadSharp/Entities/PolyFaceMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class PolyfaceMesh : Polyline
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.PolyfaceMesh;

public SeqendCollection<VertexFaceRecord> Faces { get; }
public CadObjectCollection<VertexFaceRecord> Faces { get; }

public PolyfaceMesh()
{
this.Vertices.OnAdd += this.verticesOnAdd;
this.Faces = new SeqendCollection<VertexFaceRecord>(this);
this.Faces = new CadObjectCollection<VertexFaceRecord>(this);
}

public override IEnumerable<Entity> Explode()
Expand All @@ -45,5 +45,17 @@ private void verticesOnAdd(object sender, CollectionChangedEventArgs e)
throw new ArgumentException($"Wrong vertex type {e.Item.SubclassMarker} for {this.SubclassMarker}");
}
}

internal override void AssignDocument(CadDocument doc)
{
base.AssignDocument(doc);
doc.RegisterCollection(this.Faces);
}

internal override void UnassignDocument()
{
this.Document.UnregisterCollection(this.Faces);
base.UnassignDocument();
}
}
}
16 changes: 14 additions & 2 deletions ACadSharp/Entities/PolyfaceMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class PolyfaceMesh : Polyline
/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.PolyfaceMesh;

public SeqendCollection<VertexFaceRecord> Faces { get; }
public CadObjectCollection<VertexFaceRecord> Faces { get; }

public PolyfaceMesh()
{
this.Vertices.OnAdd += this.verticesOnAdd;
this.Faces = new SeqendCollection<VertexFaceRecord>(this);
this.Faces = new CadObjectCollection<VertexFaceRecord>(this);
}

public override IEnumerable<Entity> Explode()
Expand All @@ -45,5 +45,17 @@ private void verticesOnAdd(object sender, CollectionChangedEventArgs e)
throw new ArgumentException($"Wrong vertex type {e.Item.SubclassMarker} for {this.SubclassMarker}");
}
}

internal override void AssignDocument(CadDocument doc)
{
base.AssignDocument(doc);
doc.RegisterCollection(this.Faces);
}

internal override void UnassignDocument()
{
this.Document.UnregisterCollection(this.Faces);
base.UnassignDocument();
}
}
}
2 changes: 1 addition & 1 deletion ACadSharp/Entities/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Shape : Entity
/// Size
/// </summary>
[DxfCodeValue(40)]
public double Size { get; set; } = 0.0;
public double Size { get; set; } = 1.0;

/// <summary>
/// Shape name
Expand Down
3 changes: 1 addition & 2 deletions ACadSharp/Entities/Spline.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ACadSharp.Attributes;
using CSMath;
using System;
using System.Collections.Generic;

namespace ACadSharp.Entities
Expand Down Expand Up @@ -44,7 +43,7 @@ public class Spline : Entity
/// Degree of the spline curve
/// </summary>
[DxfCodeValue(71)]
public double Degree { get; set; }
public int Degree { get; set; }

/// <summary>
/// Number of knots
Expand Down
Loading