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

Commit f7382d6

Browse files
committed
[2019/06/23]
* (fixed) When a new element is added to a MLineStyle that already belongs to a document, it was not registering the style as a user of the linetype. * Cleanup some unneeded code.
1 parent 075314e commit f7382d6

File tree

8 files changed

+35
-168
lines changed

8 files changed

+35
-168
lines changed

doc/Changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change history
22

3+
[2019/06/23]
4+
* (fixed) When a new element is added to a MLineStyle that already belongs to a document, it was not registering the style as a user of the linetype.
5+
* Cleanup some unneeded code.
6+
37
[2019/06/21]
48
* Improved the speed of the method IsValidName of the TableObject class. This will improve the overall speed of adding table objects blocks, layers, styles,... to the document; what, also, will improve the DXF loading performance.
59
* The InvalidCharcters property of the TableObject class will return a char[] instead of a IReadOnlyList<string>.

netDxf/Collections/Linetypes.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ public void AddFromFile(string file, bool reload)
105105
/// </remarks>
106106
public bool AddFromFile(string file, string linetypeName, bool reload)
107107
{
108-
Linetype linetype;
109108
string f = this.Owner.SupportFolders.FindFile(file);
110109
if (string.IsNullOrEmpty(f))
111110
throw new FileNotFoundException("The LIN file has not been found.", file);
112111

113-
linetype = Linetype.Load(f, linetypeName);
112+
Linetype linetype = Linetype.Load(f, linetypeName);
114113

115114
if (linetype == null) return false;
116115

netDxf/Collections/MLineStyles.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void MLineStyle_ElementLinetypeChanged(MLineStyle sender, TableObjectCha
172172
private void MLineStyle_ElementAdded(MLineStyle sender, MLineStyleElementChangeEventArgs e)
173173
{
174174
e.Item.Linetype = this.Owner.Linetypes.Add(e.Item.Linetype);
175-
//this.Owner.Linetypes.References[e.Item.Linetype.Name].Add(sender);
175+
this.Owner.Linetypes.References[e.Item.Linetype.Name].Add(sender);
176176
}
177177

178178
private void MLineStyle_ElementRemoved(MLineStyle sender, MLineStyleElementChangeEventArgs e)

netDxf/Entities/Ellipse.cs

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,77 +35,6 @@ public class Ellipse :
3535
{
3636
#region private classes
3737

38-
public class CalculatePoints
39-
{
40-
public static void main()
41-
{
42-
// TODO Auto-generated method stub
43-
44-
/*
45-
*
46-
dp(t) = sqrt( (r1*sin(t))^2 + (r2*cos(t))^2)
47-
circ = sum(dp(t), t=0..2*Pi step 0.0001)
48-
49-
n = 20
50-
51-
nextPoint = 0
52-
run = 0.0
53-
for t=0..2*Pi step 0.0001
54-
if n*run/circ >= nextPoint then
55-
set point (r1*cos(t), r2*sin(t))
56-
nextPoint = nextPoint + 1
57-
next
58-
run = run + dp(t)
59-
next
60-
*/
61-
62-
63-
double r1 = 20.0;
64-
double r2 = 10.0;
65-
66-
double theta = 0.0;
67-
double twoPi = Math.PI*2.0;
68-
double deltaTheta = 0.0001;
69-
double numIntegrals = Math.Round(twoPi/deltaTheta);
70-
double circ=0.0;
71-
double dpt=0.0;
72-
73-
/* integrate over the elipse to get the circumference */
74-
for( int i=0; i < numIntegrals; i++ ) {
75-
theta += i*deltaTheta;
76-
dpt = computeDpt( r1, r2, theta);
77-
circ += dpt;
78-
}
79-
80-
int n=20;
81-
int nextPoint = 0;
82-
double run = 0.0;
83-
theta = 0.0;
84-
85-
for( int i=0; i < numIntegrals; i++ ) {
86-
theta += deltaTheta;
87-
double subIntegral = n*run/circ;
88-
if( (int) subIntegral >= nextPoint ) {
89-
double x = r1 * Math.Cos(theta);
90-
double y = r2 * Math.Sin(theta);
91-
nextPoint++;
92-
}
93-
run += computeDpt(r1, r2, theta);
94-
}
95-
}
96-
97-
static double computeDpt( double r1, double r2, double theta )
98-
{
99-
double dp=0.0;
100-
101-
double dpt_sin = Math.Pow(r1*Math.Sin(theta), 2.0);
102-
double dpt_cos = Math.Pow( r2*Math.Cos(theta), 2.0);
103-
dp = Math.Sqrt(dpt_sin + dpt_cos);
104-
105-
return dp;
106-
}
107-
}
108-
10938
private static class ConicThroughFivePoints
11039
{
11140
private static double[] CoefficientsLine(Vector2 p1, Vector2 p2)
@@ -618,8 +547,8 @@ public override void TransformBy(Matrix3 transformation, Vector3 translation)
618547

619548
wcsAnglePoints[i] = transformation * wcsAnglePoints[i];
620549
wcsPoints[i] += translation;
621-
622550
}
551+
623552
List<Vector3> ocsAnglePoints = MathHelper.Transform(wcsAnglePoints, newNormal, CoordinateSystem.World, CoordinateSystem.Object);
624553

625554
Vector2 newStart = new Vector2(ocsAnglePoints[0].X, ocsAnglePoints[0].Y);

netDxf/Entities/Shape.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Shape :
3434
{
3535
#region private fields
3636

37-
private string name;
37+
private readonly string name;
3838
private ShapeStyle style;
3939
private Vector3 position;
4040
private double size;

netDxf/Entities/Text.cs

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -460,90 +460,6 @@ public override void TransformBy(Matrix3 transformation, Vector3 translation)
460460
this.ObliqueAngle = newObliqueAngle;
461461
}
462462

463-
public void TransformBy2(Matrix3 transformation, Vector3 translation)
464-
{
465-
Vector3 newPosition;
466-
Vector3 newNormal;
467-
Vector2 newUvector;
468-
Vector2 newVvector;
469-
double newWidthFactor;
470-
double newHeight;
471-
double newRotation;
472-
double newObliqueAngle;
473-
bool reverseText;
474-
475-
newPosition = transformation * this.Position + translation;
476-
newNormal = transformation * this.Normal;
477-
478-
Matrix3 transOW = MathHelper.ArbitraryAxis(this.Normal);
479-
480-
Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal);
481-
transWO = transWO.Transpose();
482-
483-
List<Vector2> uv = MathHelper.Transform(new List<Vector2>
484-
{
485-
this.WidthFactor * this.Height * Vector2.UnitX,
486-
new Vector2(this.Height * Math.Tan(this.ObliqueAngle * MathHelper.DegToRad), this.Height)
487-
},
488-
this.Rotation * MathHelper.DegToRad,
489-
CoordinateSystem.Object, CoordinateSystem.World);
490-
491-
Vector3 v;
492-
v = transOW * new Vector3(uv[0].X, uv[0].Y, 0.0);
493-
v = transformation * v;
494-
v = transWO * v;
495-
newUvector = new Vector2(v.X, v.Y);
496-
497-
v = transOW * new Vector3(uv[1].X, uv[1].Y, 0.0);
498-
v = transformation * v;
499-
v = transWO * v;
500-
newVvector = new Vector2(v.X, v.Y);
501-
502-
newRotation = Vector2.Angle(newUvector) * MathHelper.RadToDeg;
503-
newObliqueAngle = Vector2.Angle(newVvector) * MathHelper.RadToDeg;
504-
505-
if (Vector2.CrossProduct(newUvector, newVvector) < 0)
506-
{
507-
newObliqueAngle = 90 - (newRotation - newObliqueAngle);
508-
newRotation += 180;
509-
reverseText = true;
510-
}
511-
else
512-
{
513-
newObliqueAngle = 90 + (newRotation - newObliqueAngle);
514-
reverseText = false;
515-
}
516-
517-
if (newObliqueAngle >= 360) newObliqueAngle -= 360;
518-
519-
// the oblique angle is defined between -85 nad 85 degrees
520-
if (newObliqueAngle > 180)
521-
newObliqueAngle = 180 - newObliqueAngle;
522-
if (newObliqueAngle < -85)
523-
newObliqueAngle = -85;
524-
else if (newObliqueAngle > 85)
525-
newObliqueAngle = 85;
526-
527-
// the height must be greater than zero, the cos is always positive between -85 and 85
528-
newHeight = newVvector.Modulus() * Math.Cos(newObliqueAngle * MathHelper.DegToRad);
529-
newHeight = MathHelper.IsZero(newHeight) ? MathHelper.Epsilon : newHeight;
530-
531-
// the width factor is defined between 0.01 nad 100
532-
newWidthFactor = newUvector.Modulus() / newHeight;
533-
if(newWidthFactor<0.01)
534-
newWidthFactor = 0.01;
535-
else if (newWidthFactor > 100)
536-
newWidthFactor = 100;
537-
538-
this.Position = newPosition;
539-
this.Normal = newNormal;
540-
this.Rotation = newRotation;
541-
this.Height = newHeight;
542-
this.WidthFactor = newWidthFactor;
543-
this.ObliqueAngle = newObliqueAngle;
544-
if (reverseText) this.IsBackward = !this.IsBackward;
545-
}
546-
547463
/// <summary>
548464
/// Creates a new Text that is a copy of the current instance.
549465
/// </summary>

netDxf/IO/DxfReader.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,49 +3984,71 @@ private double ReadToleranceTextHeightXData(XData xData)
39843984
while (records.MoveNext())
39853985
{
39863986
XDataRecord data = records.Current;
3987+
if(data == null) return textHeight;
39873988

39883989
// the tolerance text height are stored under the string "DSTYLE"
39893990
if (data.Code == XDataCode.String && string.Equals((string) data.Value, "DSTYLE", StringComparison.OrdinalIgnoreCase))
39903991
{
39913992
if (records.MoveNext())
3993+
{
39923994
data = records.Current;
3995+
if(data == null) return textHeight;
3996+
}
39933997
else
3998+
{
39943999
return textHeight; // premature end
4000+
}
39954001

39964002
// all style overrides are enclosed between XDataCode.ControlString "{" and "}"
39974003
if (data.Code != XDataCode.ControlString && (string) data.Value != "{")
4004+
{
39984005
return textHeight; // premature end
4006+
}
39994007

40004008
if (records.MoveNext())
4009+
{
40014010
data = records.Current;
4011+
if(data == null) return textHeight;
4012+
}
40024013
else
4014+
{
40034015
return textHeight; // premature end
4016+
}
40044017

40054018
while (!(data.Code == XDataCode.ControlString && (string) data.Value == "}"))
40064019
{
4007-
if (data.Code != XDataCode.Int16)
4008-
return textHeight;
4020+
if (data.Code != XDataCode.Int16) return textHeight;
4021+
40094022
short textHeightCode = (short) data.Value;
40104023
if (records.MoveNext())
4024+
{
40114025
data = records.Current;
4026+
if(data == null) return textHeight;
4027+
}
40124028
else
4029+
{
40134030
return textHeight; // premature end
4031+
}
40144032

40154033
//the xData overrides must be read in pairs.
40164034
//the first is the dimension style property to override, the second is the new value
40174035
switch (textHeightCode)
40184036
{
40194037
case 140:
4020-
if (data.Code != XDataCode.Real)
4021-
return textHeight; // premature end
4038+
if (data.Code != XDataCode.Real) return textHeight; // premature end
40224039
textHeight = (double) data.Value;
40234040
break;
40244041
}
40254042

40264043
if (records.MoveNext())
4044+
{
40274045
data = records.Current;
4046+
if(data == null) return textHeight;
4047+
}
40284048
else
4049+
{
40294050
return textHeight; // premature end
4051+
}
40304052
}
40314053
}
40324054
}

netDxf/Tables/Linetype.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,7 @@ public override object Clone()
651651
private void Segments_BeforeAddItem(ObservableCollection<LinetypeSegment> sender, ObservableCollectionEventArgs<LinetypeSegment> e)
652652
{
653653
// null items are not allowed
654-
if (e.Item == null)
655-
e.Cancel = true;
656-
else
657-
e.Cancel = false;
654+
e.Cancel = e.Item == null;
658655
}
659656

660657
private void Segments_AddItem(ObservableCollection<LinetypeSegment> sender, ObservableCollectionEventArgs<LinetypeSegment> e)

0 commit comments

Comments
 (0)