Skip to content

Commit 9d9af86

Browse files
authored
Merge branch 'main' into task/COMPSGH-200-Dev-Tools
2 parents 66180a5 + 011158c commit 9d9af86

File tree

144 files changed

+409
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+409
-519
lines changed

Compos/0_File/ComposFile.cs

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.IO.Pipes;
45
using System.Linq;
6+
using System.Runtime.Remoting.Contexts;
7+
using System.Runtime.Remoting.Messaging;
58
using System.Text;
69
using Compos_8_6;
710
using ComposAPI.Helpers;
@@ -54,15 +57,35 @@ public static ComposFile Open(string fileName) {
5457
status = ComposFile.ComposCOM.SaveAs(tempCoa);
5558
if (status == 1) {
5659
return null;
57-
}
58-
59-
// open temp coa file as ASCII string
60-
string coaString = File.ReadAllText(tempCoa, Encoding.Default);
60+
}
61+
string coaString = File.ReadAllText(tempCoa, GetFileEncoding(tempCoa));
6162
var file = ComposFile.FromCoaString(coaString);
62-
6363
return file;
6464
}
6565

66+
public static Encoding GetFileEncoding(string filePath) {
67+
Stream fileStream = File.OpenRead(filePath);
68+
var Utf8EncodingVerifier = Encoding.GetEncoding("utf-8", new EncoderExceptionFallback(), new DecoderExceptionFallback());
69+
using (var reader = new StreamReader(fileStream, Utf8EncodingVerifier,
70+
detectEncodingFromByteOrderMarks: true, leaveOpen: true, bufferSize: 1024)) {
71+
string detectedEncoding;
72+
try {
73+
while (!reader.EndOfStream) {
74+
reader.ReadLine();
75+
}
76+
detectedEncoding = reader.CurrentEncoding.BodyName;
77+
}
78+
catch (Exception) {
79+
// Failed to decode the file using the BOM/UT8.
80+
// Assume it's local ANSI
81+
detectedEncoding = "ISO-8859-1";
82+
}
83+
// Rewind the stream
84+
fileStream.Seek(0, SeekOrigin.Begin);
85+
return Encoding.GetEncoding(detectedEncoding);
86+
}
87+
}
88+
6689
public void AddMember(IMember member) {
6790
((Member)member).Register(this);
6891
Members.Add(member);

Compos/1_Beam/BeamSection/BeamSection.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ public override string ToString() {
154154
string start = "";
155155
if (StartPosition.QuantityInfo.UnitType == typeof(LengthUnit)) {
156156
var l = (Length)StartPosition;
157-
if (l != Length.Zero) {
157+
if (!ComposUnitsHelper.IsEqual(l, Length.Zero)) {
158158
start = ", Px:" + l.ToString("g2").Replace(" ", string.Empty);
159159
}
160160
} else {
161161
var p = (Ratio)StartPosition;
162-
if (p != Ratio.Zero) {
162+
if (!ComposUnitsHelper.IsEqual(p, Ratio.Zero)) {
163163
start = ", Px:" + p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
164164
}
165165
}
@@ -220,7 +220,7 @@ private void SetFromProfileString(string profile) {
220220

221221
string[] type = parts[1].Split('(', ')');
222222
if (type.Length > 1) {
223-
UnitParser parser = UnitParser.Default;
223+
UnitParser parser = OasysUnitsSetup.Default.UnitParser;
224224
unit = parser.Parse<LengthUnit>(type[1]);
225225
}
226226
try {
@@ -245,7 +245,7 @@ private void SetFromProfileString(string profile) {
245245

246246
string[] type = parts[1].Split('(', ')');
247247
if (type.Length > 1) {
248-
UnitParser parser = UnitParser.Default;
248+
UnitParser parser = OasysUnitsSetup.Default.UnitParser;
249249
unit = parser.Parse<LengthUnit>(type[1]);
250250
}
251251
try {

Compos/1_Beam/WebOpening/WebOpening.cs

+30-16
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public IQuantity CentroidPosFromStart {
3030
}
3131
if (value.QuantityInfo.UnitType != typeof(LengthUnit) & value.QuantityInfo.UnitType != typeof(RatioUnit)) {
3232
throw new ArgumentException("Centroid Position From Start must be either Length or Ratio");
33-
} else {
33+
}
34+
else {
3435
m_CentroidPosFromStart = value;
3536
}
3637
}
@@ -43,7 +44,8 @@ public IQuantity CentroidPosFromTop {
4344
}
4445
if (value.QuantityInfo.UnitType != typeof(LengthUnit) & value.QuantityInfo.UnitType != typeof(RatioUnit)) {
4546
throw new ArgumentException("Centroid Position From Top must be either Length or Ratio");
46-
} else {
47+
}
48+
else {
4749
m_CentroidPosFromTop = value;
4850
}
4951
}
@@ -142,7 +144,8 @@ public WebOpening(Length width, Length height, NotchPosition position, IWebOpeni
142144
// static type for this constructor
143145
if (position == NotchPosition.Start) {
144146
WebOpeningType = OpeningType.Start_notch;
145-
} else {
147+
}
148+
else {
146149
WebOpeningType = OpeningType.End_notch;
147150
}
148151
// inputs
@@ -204,12 +207,14 @@ public string ToCoaString(string name, ComposUnits units) {
204207
}
205208
if (OpeningStiffeners == null) {
206209
parameters.Add("STIFFENER_NO");
207-
} else {
210+
}
211+
else {
208212
parameters.Add("STIFFENER_YES");
209213

210214
if (!OpeningStiffeners.IsBothSides | OpeningStiffeners.IsNotch) {
211215
parameters.Add("ONE_SIDE_STIFFENER");
212-
} else {
216+
}
217+
else {
213218
parameters.Add("BOTH_SIDE_STIFFENER");
214219
}
215220

@@ -219,7 +224,8 @@ public string ToCoaString(string name, ComposUnits units) {
219224
if (OpeningStiffeners.IsNotch) {
220225
parameters.Add(CoaHelper.FormatSignificantFigures(OpeningStiffeners.TopStiffenerWidth.ToUnit(units.Section).Value, 6));
221226
parameters.Add(CoaHelper.FormatSignificantFigures(OpeningStiffeners.TopStiffenerThickness.ToUnit(units.Section).Value, 6));
222-
} else {
227+
}
228+
else {
223229
parameters.Add(CoaHelper.FormatSignificantFigures(OpeningStiffeners.BottomStiffenerWidth.ToUnit(units.Section).Value, 6));
224230
parameters.Add(CoaHelper.FormatSignificantFigures(OpeningStiffeners.BottomStiffenerThickness.ToUnit(units.Section).Value, 6));
225231
}
@@ -235,14 +241,14 @@ public override string ToString() {
235241
case OpeningType.Start_notch:
236242
case OpeningType.End_notch:
237243
case OpeningType.Rectangular:
238-
if (Width == null || Height == null) {
244+
if (ComposUnitsHelper.IsEqual(Width, Length.Zero) || ComposUnitsHelper.IsEqual(Height, Length.Zero)) {
239245
return "Invalid Webopening";
240246
}
241247
size = Width.As(Height.Unit).ToString("g2") + "x" + Height.ToString("g2").Replace(" ", string.Empty);
242248
break;
243249

244250
case OpeningType.Circular:
245-
if (Diameter == null) {
251+
if (ComposUnitsHelper.IsEqual(Diameter, Length.Zero)) {
246252
return "Invalid Webopening";
247253
}
248254
size = "Ø" + Diameter.ToString("g2").Replace(" ", string.Empty);
@@ -264,11 +270,13 @@ public override string ToString() {
264270
string x = "";
265271
if (CentroidPosFromStart == null) {
266272
return "Invalid Webopening";
267-
} else {
273+
}
274+
else {
268275
if (CentroidPosFromStart.QuantityInfo.UnitType == typeof(LengthUnit)) {
269276
var l = (Length)CentroidPosFromStart;
270277
x = l.ToString("f2").Replace(" ", string.Empty);
271-
} else {
278+
}
279+
else {
272280
var p = (Ratio)CentroidPosFromStart;
273281
x = p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
274282
}
@@ -277,11 +285,13 @@ public override string ToString() {
277285
string z = "";
278286
if (CentroidPosFromStart == null) {
279287
return "Invalid Webopening";
280-
} else {
288+
}
289+
else {
281290
if (CentroidPosFromTop.QuantityInfo.UnitType == typeof(LengthUnit)) {
282291
var l = (Length)CentroidPosFromTop;
283292
z = l.ToString("g2").Replace(" ", string.Empty);
284-
} else {
293+
}
294+
else {
285295
var p = (Ratio)CentroidPosFromTop;
286296
z = p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
287297
}
@@ -331,12 +341,14 @@ internal static IWebOpening FromCoaString(List<string> parameters, ComposUnits u
331341
opening.Diameter = new Length(Convert.ToDouble(parameters[3], noComma), units.Section);
332342
if (parameters[5].EndsWith("%")) {
333343
opening.CentroidPosFromStart = new Ratio(Convert.ToDouble(parameters[5].Replace("%", string.Empty), noComma), RatioUnit.Percent);
334-
} else {
344+
}
345+
else {
335346
opening.CentroidPosFromStart = new Length(Convert.ToDouble(parameters[5], noComma), units.Length);
336347
}
337348
if (parameters[6].EndsWith("%")) {
338349
opening.CentroidPosFromTop = new Ratio(Convert.ToDouble(parameters[6].Replace("%", string.Empty), noComma), RatioUnit.Percent);
339-
} else {
350+
}
351+
else {
340352
opening.CentroidPosFromTop = new Length(Convert.ToDouble(parameters[6], noComma), units.Section);
341353
}
342354
break;
@@ -346,7 +358,8 @@ internal static IWebOpening FromCoaString(List<string> parameters, ComposUnits u
346358

347359
if (parameters[8] == "ONE_SIDE_STIFFENER") {
348360
webOpeningStiffeners.IsBothSides = false;
349-
} else {
361+
}
362+
else {
350363
webOpeningStiffeners.IsBothSides = true;
351364
}
352365

@@ -356,7 +369,8 @@ internal static IWebOpening FromCoaString(List<string> parameters, ComposUnits u
356369

357370
if (parameters[2] == "LEFT_NOTCH" | parameters[2] == "RIGHT_NOTCH") {
358371
webOpeningStiffeners.IsNotch = true;
359-
} else {
372+
}
373+
else {
360374
webOpeningStiffeners.IsNotch = false;
361375
webOpeningStiffeners.BottomStiffenerWidth = new Length(Convert.ToDouble(parameters[12], noComma), units.Section);
362376
webOpeningStiffeners.BottomStiffenerThickness = new Length(Convert.ToDouble(parameters[13], noComma), units.Section);

Compos/2_Studs/StudGroupSpacing.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public override string ToString() {
4949
string start = "";
5050
if (DistanceFromStart.QuantityInfo.UnitType == typeof(LengthUnit)) {
5151
var l = (Length)DistanceFromStart;
52-
if (l != Length.Zero) {
52+
if (!ComposUnitsHelper.IsEqual(l, Length.Zero)) {
5353
start = "From:" + l.ToString("g2").Replace(" ", string.Empty);
5454
}
55-
} else {
55+
}
56+
else {
5657
var p = (Ratio)DistanceFromStart;
57-
if (p != Ratio.Zero) {
58+
if (!ComposUnitsHelper.IsEqual(p, Ratio.Zero)) {
5859
start = "From:" + p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
5960
}
6061
}

Compos/2_Studs/StudSpecification.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using ComposAPI.Helpers;
34
using OasysUnits;
45
using OasysUnits.Units;
56

@@ -96,24 +97,24 @@ public override string ToString() {
9697
string noStudStart = "";
9798
if (NoStudZoneStart.QuantityInfo.UnitType == typeof(LengthUnit)) {
9899
var l = (Length)NoStudZoneStart;
99-
if (l != Length.Zero) {
100+
if (!ComposUnitsHelper.IsEqual(l, Length.Zero)) {
100101
noStudStart = "NoStudStart:" + l.ToString("g2").Replace(" ", string.Empty);
101102
}
102103
} else {
103104
var p = (Ratio)NoStudZoneStart;
104-
if (p != Ratio.Zero) {
105+
if (!ComposUnitsHelper.IsEqual(p, Ratio.Zero)) {
105106
noStudStart = "NoStudStart:" + p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
106107
}
107108
}
108109
string noStudEnd = "";
109110
if (NoStudZoneEnd.QuantityInfo.UnitType == typeof(LengthUnit)) {
110111
var l = (Length)NoStudZoneEnd;
111-
if (l != Length.Zero) {
112+
if (!ComposUnitsHelper.IsEqual(l, Length.Zero)) {
112113
noStudEnd = "NoStudEnd:" + l.ToString("g2").Replace(" ", string.Empty);
113114
}
114115
} else {
115116
var p = (Ratio)NoStudZoneEnd;
116-
if (p != Ratio.Zero) {
117+
if (!ComposUnitsHelper.IsEqual(p, Ratio.Zero)) {
117118
noStudEnd = "NoStudEnd:" + p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
118119
}
119120
}

Compos/3_Slab/SlabDimension/SlabDimension.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ public override string ToString() {
9595
string start = "";
9696
if (StartPosition.QuantityInfo.UnitType == typeof(LengthUnit)) {
9797
var l = (Length)StartPosition;
98-
if (l != Length.Zero) {
98+
if (!ComposUnitsHelper.IsEqual(l, Length.Zero)) {
9999
start = ", s:" + l.ToUnit(ComposUnitsHelper.LengthUnitGeometry).ToString("g2").Replace(" ", string.Empty);
100100
}
101101
} else {
102102
var p = (Ratio)StartPosition;
103-
if (p != Ratio.Zero) {
103+
if (!ComposUnitsHelper.IsEqual(p, Ratio.Zero)) {
104104
start = ", s:" + p.ToUnit(RatioUnit.Percent).ToString("g2").Replace(" ", string.Empty);
105105
}
106106
}

Compos/5_Member/DesignCriteria/DeflectionLimit.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public DeflectionLimit(double spanDeflectionRatio) {
2121
public string ToCoaString(string name, DeflectionLimitLoadType type, ComposUnits units) {
2222
string coaString = "";
2323

24-
if (AbsoluteDeflection != Length.Zero) {
24+
if (!ComposUnitsHelper.IsEqual(AbsoluteDeflection,Length.Zero)) {
2525
var parameters = new List<string> {
2626
CoaIdentifier.DesignCriteria.DeflectionLimit,
2727
name,
@@ -33,7 +33,7 @@ public string ToCoaString(string name, DeflectionLimitLoadType type, ComposUnits
3333
coaString += CoaHelper.CreateString(parameters);
3434
}
3535

36-
if (SpanOverDeflectionRatio != Ratio.Zero) {
36+
if (!ComposUnitsHelper.IsEqual(SpanOverDeflectionRatio, Ratio.Zero)) {
3737
var parameters = new List<string> {
3838
CoaIdentifier.DesignCriteria.DeflectionLimit,
3939
name,
@@ -50,11 +50,11 @@ public string ToCoaString(string name, DeflectionLimitLoadType type, ComposUnits
5050

5151
public override string ToString() {
5252
string str = "";
53-
if (AbsoluteDeflection != Length.Zero) {
53+
if (!ComposUnitsHelper.IsEqual(AbsoluteDeflection, Length.Zero)) {
5454
str += "δ:" + AbsoluteDeflection.ToUnit(ComposUnitsHelper.LengthUnitResult).ToString("f0").Replace(" ", string.Empty) + ", ";
5555
}
5656

57-
if (SpanOverDeflectionRatio != Ratio.Zero) {
57+
if (!ComposUnitsHelper.IsEqual(SpanOverDeflectionRatio, Ratio.Zero)) {
5858
str += "δ:1/" + SpanOverDeflectionRatio.DecimalFractions.ToString("f0").Replace(" ", string.Empty);
5959
}
6060
return str.TrimEnd(' ').TrimEnd(',');

Compos/7_Results/5_1_CompositeProperties/CompositeSectionProperties.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using ComposAPI.Helpers;
45
using OasysUnits;
56
using OasysUnits.Units;
67

@@ -181,7 +182,7 @@ public List<AreaMomentOfInertia> MomentOfInertiaVibration {
181182
/// </summary>
182183
public Frequency NaturalFrequency {
183184
get {
184-
if (m_frequency == Frequency.Zero) {
185+
if (ComposUnitsHelper.IsEqual(m_frequency,Frequency.Zero)) {
185186
m_frequency = new Frequency(Member.UtilisationFactor(UtilisationFactorOption.NaturalFrequency), FrequencyUnit.Hertz);
186187
}
187188
return m_frequency;

Compos/ComposAPI.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<ItemGroup>
6565
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.3" />
6666
<PackageReference Include="OasysUnits">
67-
<Version>1.0.0</Version>
67+
<Version>1.2.1</Version>
6868
</PackageReference>
6969
</ItemGroup>
7070
</Project>

Compos/ComposUnits.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,27 @@ public string ToCoaString() {
6565
internal void FromCoaString(List<string> parameters) {
6666
switch (parameters[1]) {
6767
case CoaIdentifier.Units.Force:
68-
Force = (ForceUnit)UnitParser.Default.Parse(parameters[2], typeof(ForceUnit));
68+
Force = (ForceUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(ForceUnit));
6969
break;
7070

7171
case CoaIdentifier.Units.Length:
72-
Length = (LengthUnit)UnitParser.Default.Parse(parameters[2], typeof(LengthUnit));
72+
Length = (LengthUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(LengthUnit));
7373
break;
7474

7575
case CoaIdentifier.Units.Displacement:
76-
Displacement = (LengthUnit)UnitParser.Default.Parse(parameters[2], typeof(LengthUnit));
76+
Displacement = (LengthUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(LengthUnit));
7777
break;
7878

7979
case CoaIdentifier.Units.Section:
80-
Section = (LengthUnit)UnitParser.Default.Parse(parameters[2], typeof(LengthUnit));
80+
Section = (LengthUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(LengthUnit));
8181
break;
8282

8383
case CoaIdentifier.Units.Stress:
84-
Stress = (PressureUnit)UnitParser.Default.Parse(parameters[2], typeof(PressureUnit));
84+
Stress = (PressureUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(PressureUnit));
8585
break;
8686

8787
case CoaIdentifier.Units.Mass:
88-
Mass = (MassUnit)UnitParser.Default.Parse(parameters[2], typeof(MassUnit));
88+
Mass = (MassUnit)OasysUnitsSetup.Default.UnitParser.Parse(parameters[2], typeof(MassUnit));
8989
break;
9090
}
9191
}

0 commit comments

Comments
 (0)