Skip to content

Commit

Permalink
pre-commit| apply csharpier| ANA-1928
Browse files Browse the repository at this point in the history
  • Loading branch information
renefritze committed Apr 30, 2024
1 parent 006f3b6 commit dffad0c
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 116 deletions.
9 changes: 4 additions & 5 deletions AdSec/.NET/AdsToApi/AdsToApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static class AdsToApi
public static void Main()
{
// Read the required .ads file as string
System.String path = "..\\..\\..\\..\\..\\..\\..\\DocumentationOnly\\.NET\\DotNetCodeSnippets\\api2section.ads";
System.String path =
"..\\..\\..\\..\\..\\..\\..\\DocumentationOnly\\.NET\\DotNetCodeSnippets\\api2section.ads";
System.String json = System.IO.File.ReadAllText(path);

// Use JsonParser's Deserialize method to convert from JSON to API objects
Expand All @@ -26,14 +27,12 @@ public static void Main()
System.Collections.Generic.IList<ISection> api_sections = api.Sections;
ISection section_one = api_sections[0];

// Access and print warnings to check for warning messages while converting JSON to API
// Access and print warnings to check for warning messages while converting JSON to API
System.Collections.Generic.IList<IWarning> api_warnings = api.Warnings;
for (int i = 0; i< api_warnings.Count; i++)
for (int i = 0; i < api_warnings.Count; i++)
{
Console.WriteLine(api_warnings[i].Description);
}

}
}
}

37 changes: 26 additions & 11 deletions AdSec/.NET/ApiToAds/ApiToAds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using OasysUnits;
using Oasys.AdSec.DesignCode;


namespace ApiToAds
{
/// <summary>
Expand All @@ -21,28 +20,44 @@ public static class ApiToAds
{
public static void Main()
{
// Create API section
IConcrete C30 = Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.GB.PD6687.Edition_2010.C30_37;
// Create API section
IConcrete C30 = Concrete
.EN1992
.Part1_1
.Edition_2004
.NationalAnnex
.GB
.PD6687
.Edition_2010
.C30_37;
ICircleProfile circle_profile = ICircleProfile.Create(Length.FromMillimeters(1000));
ISection section = ISection.Create(circle_profile, C30);

// Use JsonConverter's SectionToJson method to obtain the JSON string
JsonConverter converter = new JsonConverter(EN1992.Part1_1.Edition_2004.NationalAnnex.GB.PD6687.Edition_2010);
// Use JsonConverter's SectionToJson method to obtain the JSON string
JsonConverter converter = new JsonConverter(
EN1992.Part1_1.Edition_2004.NationalAnnex.GB.PD6687.Edition_2010
);
String json = converter.SectionToJson(section);

// Save this JSON string into .ads file
// Save this JSON string into .ads file
System.IO.File.WriteAllText("adsec_section.ads", json);

// To save a section with loads (or deformation)
Oasys.AdSec.ILoad load_one = ILoad.Create(Force.FromKilonewtons(-10), Moment.Zero, Moment.Zero);
Oasys.AdSec.ILoad load_two = ILoad.Create(Force.FromKilonewtons(-15), Moment.Zero, Moment.Zero);
// To save a section with loads (or deformation)
Oasys.AdSec.ILoad load_one = ILoad.Create(
Force.FromKilonewtons(-10),
Moment.Zero,
Moment.Zero
);
Oasys.AdSec.ILoad load_two = ILoad.Create(
Force.FromKilonewtons(-15),
Moment.Zero,
Moment.Zero
);
Oasys.Collections.IList<ILoad> load_list = Oasys.Collections.IList<ILoad>.Create();
load_list.Add(load_one);
load_list.Add(load_two);
String json_with_loads = converter.SectionToJson(section, load_list);
System.IO.File.WriteAllText("adsec_section_with_loads.ads", json_with_loads);

}
}
}

2 changes: 1 addition & 1 deletion AdSec/.NET/ApiVersion/ApiVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public static void Main()
System.Console.WriteLine("The AdSec API version is " + IVersion.Api());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,45 @@ public static class ReinforcedConcreteAnalysis
public static void Main()
{
// Create a rectangular section
var profile = IRectangleProfile.Create(Length.FromMillimeters(800), Length.FromMillimeters(400));
IConcrete sectionMaterial = Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014.C40_50;
var profile = IRectangleProfile.Create(
Length.FromMillimeters(800),
Length.FromMillimeters(400)
);
IConcrete sectionMaterial = Concrete
.EN1992
.Part1_1
.Edition_2004
.NationalAnnex
.GB
.Edition_2014
.C40_50;
var section = ISection.Create(profile, sectionMaterial);

// Set the cover
section.Cover = ICover.Create(Length.FromMillimeters(40));

// Set some reinforcement
IReinforcement reinforcementMaterial = Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014.S500B;
IBarBundle bar20mm = IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(20));
IBarBundle bar16mm = IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(16));
IBarBundle bar12mm = IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(12));
IReinforcement reinforcementMaterial = Reinforcement
.Steel
.EN1992
.Part1_1
.Edition_2004
.NationalAnnex
.GB
.Edition_2014
.S500B;
IBarBundle bar20mm = IBarBundle.Create(
reinforcementMaterial,
Length.FromMillimeters(20)
);
IBarBundle bar16mm = IBarBundle.Create(
reinforcementMaterial,
Length.FromMillimeters(16)
);
IBarBundle bar12mm = IBarBundle.Create(
reinforcementMaterial,
Length.FromMillimeters(12)
);

// Define top reinforcement
ILayer topLayer = ILayerByBarCount.Create(4, bar16mm);
Expand Down Expand Up @@ -76,7 +103,10 @@ public static void Main()
IServiceabilityResult serviceabilityResult = solution.Serviceability.Check(load);

// Display the crack width in mm
double crackWidth = Math.Round(serviceabilityResult.MaximumWidthCrack.Width.Millimeters, 2);
double crackWidth = Math.Round(
serviceabilityResult.MaximumWidthCrack.Width.Millimeters,
2
);
Console.WriteLine($"The maximum crack width is: {crackWidth}mm");
}
}
Expand Down
27 changes: 23 additions & 4 deletions AdSec/.NET/SampleProgram/SampleProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,35 @@ private static void Main()
{
// Create a circular section
var profile = ICircleProfile.Create(Length.FromMillimeters(500));
IConcrete sectionMaterial = Concrete.EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014.C40_50;
IConcrete sectionMaterial = Concrete
.EN1992
.Part1_1
.Edition_2004
.NationalAnnex
.GB
.Edition_2014
.C40_50;
var section = ISection.Create(profile, sectionMaterial);

IReinforcement reinforcementMaterial = Reinforcement.Steel.EN1992.Part1_1.Edition_2004.NationalAnnex.GB.Edition_2014.S500B;
ILayer layer = ILayerByBarCount.Create(4, IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(32)));
IReinforcement reinforcementMaterial = Reinforcement
.Steel
.EN1992
.Part1_1
.Edition_2004
.NationalAnnex
.GB
.Edition_2014
.S500B;
ILayer layer = ILayerByBarCount.Create(
4,
IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(32))
);
// Set some reinforcement
IGroup group = ILineGroup.Create(
IPoint.Create(Length.Zero, Length.Zero),
IPoint.Create(Length.FromMillimeters(150), Length.FromMillimeters(150)),
layer);
layer
);

section.ReinforcementGroups.Add(group);

Expand Down
5 changes: 3 additions & 2 deletions AdSec/.NET/SampleProgramTestsUsingMocking/ApiMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public void MockSample()
// GIVEN a serviceability result
Length length = Length.FromMillimeters(0.5);
Mock<ICrack> mockCrack = new Mock<ICrack>();
Mock<IServiceabilityResult> mockServiceabilityResult = new Mock<IServiceabilityResult>();
Mock<IServiceabilityResult> mockServiceabilityResult =
new Mock<IServiceabilityResult>();
mockServiceabilityResult.Setup(_ => _.MaximumWidthCrack).Returns(mockCrack.Object);
mockCrack.Setup(_ => _.Width).Returns(length);

Expand All @@ -30,4 +31,4 @@ public void MockSample()
Assert.Equal(someExpectedValue, crackWidth);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,27 @@ public void IsCrackWidthSatisfactory_True_ForSmallCrack()
Length length = Length.FromMillimeters(1);
Mock<ICrack> crackMock = new Mock<ICrack>();
Mock<ILoad> loadMock = new Mock<ILoad>();
Mock<IServiceabilityResult> serviceabilityResultMock = new Mock<IServiceabilityResult>();
Mock<IServiceabilityResult> serviceabilityResultMock =
new Mock<IServiceabilityResult>();
Mock<IServiceability> serviceability = new Mock<IServiceability>();
Mock<ISolution> solutionMock = new Mock<ISolution>();

serviceabilityResultMock.SetupGet(_ => _.MaximumWidthCrack).Returns(crackMock.Object);
serviceabilityResultMock.SetupGet(_ => _.MaximumWidthCrack.Width).Returns(length);
serviceability.Setup(_ => _.Check(loadMock.Object)).Returns(serviceabilityResultMock.Object);
serviceability
.Setup(_ => _.Check(loadMock.Object))
.Returns(serviceabilityResultMock.Object);
solutionMock.SetupGet(_ => _.Serviceability).Returns(serviceability.Object);

// WHEN we check that the crack width is within our expectations
bool actualResult = SampleProgram.SampleProgram.IsCrackWidthSatisfactory(solutionMock.Object, loadMock.Object);
bool actualResult = SampleProgram.SampleProgram.IsCrackWidthSatisfactory(
solutionMock.Object,
loadMock.Object
);

// THEN IsCrackWidthSatisfactory() uses the mock objects
bool expectedResult = true;
Assert.Equal(expectedResult, actualResult);
}
}
}
}
54 changes: 39 additions & 15 deletions AdSec/.NET/SaveSectionImage/SaveSectionImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,82 @@ namespace SaveSectionImage
/// <summary>
/// This example shows how to save the XML to a file to create an SVG file.
/// It also shows how you can use a third party library to convert the SVG into a PNG file.
///
///
/// You might like to run the 'ApiVersion' example first, just to check
/// that the API is installed correctly.
/// </summary>
public static class SaveSectionImage
{
static void Main()
{
// We're going to create a rectangular section with a sub-component.
// We're going to create a rectangular section with a sub-component.

// Create the rectangular section
IProfile profile = IRectangleProfile.Create(Length.FromMillimeters(500), Length.FromMillimeters(300));
IProfile profile = IRectangleProfile.Create(
Length.FromMillimeters(500),
Length.FromMillimeters(300)
);
IConcrete sectionMaterial = Concrete.IS456.Edition_2000.M30;
ISection section = ISection.Create(profile, sectionMaterial);

// Set the cover
section.Cover = ICover.Create(Length.FromMillimeters(30));

// Assign reinforcements to the main section
// Assign reinforcements to the main section
IReinforcement reinforcementMaterial = Reinforcement.Steel.IS456.Edition_2000.S415;
IBarBundle bar16mm = IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(16));
ILayer layerWithPitch125mm = ILayerByBarPitch.Create(bar16mm, Length.FromMillimeters(125));
IBarBundle bar16mm = IBarBundle.Create(
reinforcementMaterial,
Length.FromMillimeters(16)
);
ILayer layerWithPitch125mm = ILayerByBarPitch.Create(
bar16mm,
Length.FromMillimeters(125)
);
IPerimeterGroup mainSectionReinforcement = IPerimeterGroup.Create();
mainSectionReinforcement.Layers.Add(layerWithPitch125mm);
IBarBundle link10mm = IBarBundle.Create(reinforcementMaterial, Length.FromMillimeters(10));
IBarBundle link10mm = IBarBundle.Create(
reinforcementMaterial,
Length.FromMillimeters(10)
);
ILinkGroup mainSectionLink = ILinkGroup.Create(link10mm);
section.ReinforcementGroups.Add(mainSectionReinforcement);
section.ReinforcementGroups.Add(mainSectionLink);

// Create another rectangular section which we'll use as a sub-component.
IProfile subcomponentProfile = IRectangleProfile.Create(Length.FromMillimeters(250), Length.FromMillimeters(700));
IProfile subcomponentProfile = IRectangleProfile.Create(
Length.FromMillimeters(250),
Length.FromMillimeters(700)
);
ISection subcomponentSection = ISection.Create(subcomponentProfile, sectionMaterial);
subcomponentSection.Cover = ICover.Create(Length.FromMillimeters(30));

// Assign reinforcements to the sub-component section
ILayer layerWithPitch120mm = ILayerByBarPitch.Create(bar16mm, Length.FromMillimeters(120));
// Assign reinforcements to the sub-component section
ILayer layerWithPitch120mm = ILayerByBarPitch.Create(
bar16mm,
Length.FromMillimeters(120)
);
IPerimeterGroup subcomponentReinforcement = IPerimeterGroup.Create();
subcomponentReinforcement.Layers.Add(layerWithPitch120mm);
ILinkGroup subcomponentLink = ILinkGroup.Create(link10mm);
subcomponentSection.ReinforcementGroups.Add(subcomponentReinforcement);
subcomponentSection.ReinforcementGroups.Add(subcomponentLink);

// Add this sub-component section to the main section
IPoint subcomponentOffset = IPoint.Create(Length.FromMillimeters(-200), Length.FromMillimeters(125));
ISubComponent subcomponent = ISubComponent.Create(subcomponentSection, subcomponentOffset);
// Add this sub-component section to the main section
IPoint subcomponentOffset = IPoint.Create(
Length.FromMillimeters(-200),
Length.FromMillimeters(125)
);
ISubComponent subcomponent = ISubComponent.Create(
subcomponentSection,
subcomponentOffset
);
section.SubComponents.Add(subcomponent);

// Flatten the section
// Flatten the section
IAdSec adsecApp = IAdSec.Create(IS456.Edition_2000);
ISection flattenedSection = adsecApp.Flatten(section);

// Get SVG XML body as a string
// Get SVG XML body as a string
string svgStr = new SectionImageBuilder(flattenedSection).Svg();

// This string can be written into SVG format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ internal static void Export(Model model, string outputDirectory)

// We can use the default data exporter to export all fields in simple data types
DefaultDataExporter.Export(model.Nodes(), Path.Combine(outputDirectory, "Nodes.csv"));
DefaultDataExporter.Export(model.Elements(), Path.Combine(outputDirectory, "Elements.csv"));
DefaultDataExporter.Export(model.Members(), Path.Combine(outputDirectory, "Members.csv"));
DefaultDataExporter.Export(
model.Elements(),
Path.Combine(outputDirectory, "Elements.csv")
);
DefaultDataExporter.Export(
model.Members(),
Path.Combine(outputDirectory, "Members.csv")
);

// Analyse Task 1 in advance of exporting some results
model.Analyse(1);

// we can create a custom exporter for more complex data, or to customise the fields
// here we export the force at both ends of each beam using our Element1DResultExporter
BeamScheduleExporter.Export(model.Results(), Path.Combine(outputDirectory, "BeamSchedule.csv"));
BeamScheduleExporter.Export(
model.Results(),
Path.Combine(outputDirectory, "BeamSchedule.csv")
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public static void Main(string[] args)
{
// this is the entry point for the application
// parse the command line options and call the relevant export function(s)
Parser.Default.ParseArguments<CommandLineOptions>(args).WithParsed(options =>
{
ModelExporter.Export(new Model(options.InputFile), options.OutputDirectory);
});
Parser.Default
.ParseArguments<CommandLineOptions>(args)
.WithParsed(options =>
{
ModelExporter.Export(new Model(options.InputFile), options.OutputDirectory);
});
}
}
}
Loading

0 comments on commit dffad0c

Please sign in to comment.