Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2021/05/23]
Browse files Browse the repository at this point in the history
* Added two methods to the MathHelper class to transform object 2d coordinates to world coordinates given the entity normal and elevation.
* Added two methods to the MathHelper class to transform world coordinates to object 2d coordinates given the entity normal, they also return as an out parameter the average Z axis value of the transformed points.
* Deleted netDxf.nuspec file.
* Improved the Leader.Update method, its results should be more consistent in transformed Leader entities.
* Added the property Direction to the Leader class. It represents the direction of the annotation.
* (fixed) When loading a Leader with a text annotation, it was assumed that it always had a hook line. It might not be always the case.
	Now when assigning a text annotation to a Leader it will not automatically add one, it needs to be done manually if desired.
	Also a call to the Update method is not done automatically. It is needed to reflect the actual properties and style of the Leader, but there might be special cases when it is needed to have control over it.
	See "AssignAnnotationToLeader()" sample.
  • Loading branch information
haplokuon committed May 23, 2021
1 parent 21bcbf5 commit 4a16a14
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 478 deletions.
66 changes: 60 additions & 6 deletions TestDxfDocument/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using netDxf;
Expand Down Expand Up @@ -33,6 +32,7 @@ public static void Main()

#region Samples for new and modified features 3.0.0

//AssignAnnotationToLeader();
//CreateImageDefinition();

#endregion
Expand Down Expand Up @@ -262,6 +262,58 @@ public static void Main()

#region Samples for new and modified features 3.0.0

private static void AssignAnnotationToLeader()
{
// We will create a Leader entity creating the annotation manually and assigning to it.
// This will be the same as:
Leader original = new Leader("Sample annotation", new[] {new Vector2(0, 0), new Vector2(2.5, 2.5)});

// Create a leader with no annotation
Leader leader = new Leader(new[] {new Vector2(0, 0), new Vector2(2.5, 2.5)});
//leader.Offset = new Vector2(0.1, 0.1);

// Create the text that will become the leader annotation
MText text = new MText("Sample annotation", new Vector2(5.0,5.0), .5) {Rotation = 0};
text.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
// Assign the text annotation to the leader
leader.Annotation = text;
// The next two code lines are the important ones, that use to be automatically applied but now it has to be done manually.
// When assigning a text annotation to a leader it will not automatically add a hook line to it.
// Usually Text and MText annotations have hook lines, but Insert and Tolerance annotations do not.
leader.HasHookline = true;
// Also a call to the Update method is not done automatically.
// It is needed to reflect the actual properties and style of the Leader,
// but it might be special cases when it is needed to have control over it.
leader.Update(true);

// Assign the leader to a new layer, keep in mind that the annotation will maintain its original layer
leader.Layer = new Layer("Layer1") {Color = AciColor.Blue};

// test cloning and transformation
Leader copy1 = (Leader)leader.Clone();
copy1.TransformBy(Matrix3.RotationZ(90 * MathHelper.DegToRad), Vector3.Zero);
// after transforming a Leader entity is not necessary to call the Update method
// this is just a check to ensure that the shape of the leader is kept, regardless
copy1.Update(true);

Leader copy2 = (Leader)leader.Clone();
copy2.TransformBy(Matrix3.Scale(1, -1, 1), Vector3.Zero);
copy2.Update(true);

Leader copy3 = (Leader) leader.Clone();
copy3.TransformBy(Matrix3.RotationZ(200 * MathHelper.DegToRad), Vector3.Zero);
copy3.Update(true);

// And the typical create document, add entity, and save file.
DxfDocument doc = new DxfDocument();
doc.Entities.Add(original);
doc.Entities.Add(leader);
doc.Entities.Add(copy1);
doc.Entities.Add(copy2);
doc.Entities.Add(copy3);
doc.Save("test.dxf");
}

private static void CreateImageDefinition()
{
// The Image entity constructors "public ImageDefinition(string file)" and "public ImageDefinition(string name, string file)"
Expand Down Expand Up @@ -730,6 +782,8 @@ public static void LeaderMirror()

Leader leader1 = new Leader(vertexes1, style);
leader1.Annotation = new MText("Sample annotation");
leader1.HasHookline = true;
leader1.Update(true);
//leader1.Annotation = new Text("Sample annotation", style.TextHeight);

//// a tolerance annotation
Expand Down Expand Up @@ -1516,7 +1570,7 @@ private static void TestLeader()
vertexes4.Add(new Vector2(-7.5, -5));
Leader leader4 = new Leader(block, vertexes4);
// change the leader offset to move the leader hook (the last vertex of the leader vertexes list) in relation to the annotation position.
leader4.Offset = new Vector2(-0.5, 0);
//leader4.Offset = new Vector2(-0.5, 0);
leader4.Update(true);

DxfDocument doc = new DxfDocument();
Expand Down Expand Up @@ -2479,8 +2533,8 @@ private static void LeaderEntity()
//leader1.Update(true);


DxfDocument compare = DxfDocument.Load("Leader compare.dxf");
Leader l = compare.Entities.Leaders.ElementAt(0);
//DxfDocument compare = DxfDocument.Load("Leader compare.dxf");
//Leader l = compare.Entities.Leaders.ElementAt(0);

// leader not in the XY plane
Leader cloned = (Leader) leader1.Clone();
Expand Down Expand Up @@ -2530,8 +2584,8 @@ private static void LeaderEntity()
vertexes4.Add(new Vector2(-5, -5));
vertexes4.Add(new Vector2(-7.5, -5));
Leader leader4 = new Leader(block, vertexes4);
// change the leader offset to move the leader hook (the last vertex of the leader vertexes list) in relation to the annotation position.
leader4.Offset = new Vector2(1, 1);
// change the leader offset to move the leader hook (the last vertex of the leader vertexes list) in relation to the annotation position.
//leader4.Offset = new Vector2(1, 1);
leader4.Update(true);

// add entities to the document
Expand Down
12 changes: 12 additions & 0 deletions doc/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## Change history


### [2021/05/23]
* Added two methods to the MathHelper class to transform object 2d coordinates to world coordinates given the entity normal and elevation.
* Added two methods to the MathHelper class to transform world coordinates to object 2d coordinates given the entity normal, they also return as an out parameter the average Z axis value of the transformed points.
* Deleted netDxf.nuspec file.
* Improved the Leader.Update method, its results should be more consistent in transformed Leader entities.
* Added the property Direction to the Leader class. It represents the direction of the annotation.
* (fixed) When loading a Leader with a text annotation, it was assumed that it always had a hook line. It might not be always the case.
Now when assigning a text annotation to a Leader it will not automatically add one, it needs to be done manually if desired.
Also a call to the Update method is not done automatically. It is needed to reflect the actual properties and style of the Leader, but there might be special cases when it is needed to have control over it.
See "AssignAnnotationToLeader()" sample.

### [2021/05/02]
* Added netDxf.nuspec file.
* Ellipses with its major axis smaller than its minor axis are not allowed.
Expand Down
2 changes: 1 addition & 1 deletion netDxf/DxfDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal DxfDocument(HeaderVariables drawingVariables, bool createDefaultObjects
{
this.supportFolders = new SupportFolders(supportFolders);
this.buildDimensionBlocks = false;
this.comments = new List<string> { "DXF file generated by netDxf https://github.com/haplokuon/netDxf, Copyright(C) 2009-2020 Daniel Carvajal, Licensed under LGPL" };
this.comments = new List<string> { "DXF file generated by netDxf https://github.com/haplokuon/netDxf, Copyright(C) 2009-2021 Daniel Carvajal, Licensed under LGPL" };
this.Owner = null;
this.drawingVariables = drawingVariables;
this.NumHandles = this.AssignHandle(0);
Expand Down
6 changes: 3 additions & 3 deletions netDxf/Entities/Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ public override void TransformBy(Matrix3 transformation, Vector3 translation)
Vector3 v = transOW * Vector3.UnitX;
v = transformation * v;
v = transWO * v;
double newRotation = Vector2.Angle(new Vector2(v.X, v.Y))* MathHelper.RadToDeg;
double newRotation = Vector2.Angle(new Vector2(v.X, v.Y));

transWO = Matrix3.RotationZ(newRotation * MathHelper.DegToRad).Transpose() * transWO;
transWO = Matrix3.RotationZ(newRotation).Transpose() * transWO;

Vector3 s = transOW * this.Scale;
s = transformation * s;
Expand All @@ -654,7 +654,7 @@ public override void TransformBy(Matrix3 transformation, Vector3 translation)
this.Normal = newNormal;
this.Position = newPosition;
this.Scale = newScale;
this.Rotation = newRotation;
this.Rotation = newRotation * MathHelper.RadToDeg;

foreach (Attribute att in this.attributes)
{
Expand Down
Loading

0 comments on commit 4a16a14

Please sign in to comment.