Skip to content

Commit

Permalink
Merge pull request #169 from arup-group/feature/GSAGH-121-gwa-command…
Browse files Browse the repository at this point in the history
…-component

gsagh-121 gwa command component
  • Loading branch information
kpne authored Sep 29, 2022
2 parents 05eddd1 + 05ddc4f commit 2306649
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,4 @@ dist/*
/IntegrationTests/obj

/GhSA/bin/x64/Release
/UnitTestGsaGH/bin/x64/Debug
58 changes: 58 additions & 0 deletions GsaGH/Components/0_Model/GwaModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using Grasshopper.Kernel;
using GsaAPI;
using GsaGH.Parameters;


namespace GsaGH.Components
{
/// <summary>
/// Component to create a GSA model from GWA string
/// </summary>
public class GwaModel : GH_OasysComponent
{
#region Name and Ribbon Layout
public override Guid ComponentGuid => new Guid("6f701c53-1531-45ef-9842-9356da59b590");
public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure;
protected override System.Drawing.Bitmap Icon => GsaGH.Properties.Resources.GwaModel;
public GwaModel()
: base("Create GWA Model", "GWA", "Create a model from a GWA string.",
Ribbon.CategoryName.Name(),
Ribbon.SubCategoryName.Cat0())
{ this.Hidden = true; } // sets the initial state of the component to hidden
#endregion

#region Input and output
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("GWA string", "GWA", "GWA string from GSA. Right-click on any data, and select copy all. Paste into notepad to check the data. \r\nThis input takes a a list of text strings that will automatically be joined. Construct a tree structure if you want to create multiple GSA files. \r\nThe syntax of the command is based on GWA syntax and the units follow the GWA unit syntax; –\r\nrefer to the “GSA Keywords” document for details", GH_ParamAccess.list);
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddParameter(new GsaModelParameter());
}
#endregion

protected override void SolveInstance(IGH_DataAccess DA)
{
Interop.Gsa_10_1.ComAuto m = new Interop.Gsa_10_1.ComAuto();
m.NewFile();
string gwa = "";
List<string> strings = new List<string>();
if (DA.GetDataList(0, strings))
foreach (string s in strings)
gwa += s + "\n";

m.GwaCommand(gwa);
string temp = Path.GetTempPath() + Guid.NewGuid().ToString() + ".gwb";
m.SaveAs(temp);
GsaModel gsaGH = new GsaModel();
gsaGH.Model.Open(temp);
DA.SetData(0, gsaGH);
}
}
}
8 changes: 8 additions & 0 deletions GsaGH/GsaGH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<HintPath>..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\GsaAPI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Interop.Gsa_10_1">
<HintPath>..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\Interop.Gsa_10_1.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -99,6 +103,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Components\0_Model\GetAnalysis.cs" />
<Compile Include="Components\0_Model\GwaModel.cs" />
<Compile Include="Components\1_Properties\CreateSectionModifier.cs" />
<Compile Include="Components\1_Properties\CreateProp3d.cs" />
<Compile Include="Components\1_Properties\EditSectionModifier.cs" />
Expand Down Expand Up @@ -641,6 +646,9 @@
<ItemGroup>
<None Include="Properties\Icons\TotalLoadAndReaction.png" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\Icons\GwaModel.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
48 changes: 30 additions & 18 deletions GsaGH/Parameters/GsaMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,44 @@ public GsaMaterial(int material_id)

internal GsaMaterial(GsaSection section, AnalysisMaterial analysisMaterial = null)
{
if (section == null) { return; }
if (section.API_Section == null) { return; }
if (analysisMaterial == null && section.Material.AnalysisMaterial != null)
analysisMaterial = section.Material.AnalysisMaterial;
else if (section.API_Section.MaterialAnalysisProperty > 0 && section.Material != null && analysisMaterial == null)
analysisMaterial = section.Material.AnalysisMaterial;
if (section == null || section.API_Section == null)
return;
if (section.Material != null)
{
if (analysisMaterial == null && section.Material.AnalysisMaterial != null)
analysisMaterial = section.Material.AnalysisMaterial;
else if (section.API_Section.MaterialAnalysisProperty > 0 && section.Material != null && analysisMaterial == null)
analysisMaterial = section.Material.AnalysisMaterial;
}

CreateFromAPI(section.API_Section.MaterialType, section.API_Section.MaterialAnalysisProperty, section.API_Section.MaterialGradeProperty, analysisMaterial);
}
internal GsaMaterial(GsaProp2d prop, AnalysisMaterial analysisMaterial = null)
{
if (prop == null) { return; }
if (prop.API_Prop2d == null) { return; }
if (analysisMaterial == null && prop.Material.AnalysisMaterial != null)
analysisMaterial = prop.Material.AnalysisMaterial;
else if (prop.API_Prop2d.MaterialAnalysisProperty > 0 && prop.Material != null && analysisMaterial == null)
analysisMaterial = prop.Material.AnalysisMaterial;
if (prop == null || prop.API_Prop2d == null)
return;
if (prop.Material != null)
{
if (analysisMaterial == null && prop.Material.AnalysisMaterial != null)
analysisMaterial = prop.Material.AnalysisMaterial;
else if (prop.API_Prop2d.MaterialAnalysisProperty > 0 && analysisMaterial == null)
analysisMaterial = prop.Material.AnalysisMaterial;
}

CreateFromAPI(prop.API_Prop2d.MaterialType, prop.API_Prop2d.MaterialAnalysisProperty, prop.API_Prop2d.MaterialGradeProperty, analysisMaterial);
}
internal GsaMaterial(GsaProp3d prop, AnalysisMaterial analysisMaterial = null)
{
if (prop == null) { return; }
if (prop.API_Prop3d == null) { return; }
if (analysisMaterial == null && prop.Material.AnalysisMaterial != null)
analysisMaterial = prop.Material.AnalysisMaterial;
else if (prop.API_Prop3d.MaterialAnalysisProperty > 0 && prop.Material != null && analysisMaterial == null)
analysisMaterial = prop.Material.AnalysisMaterial;
if (prop == null || prop.API_Prop3d == null)
return;

if (prop.Material != null)
{
if (analysisMaterial == null && prop.Material.AnalysisMaterial != null)
analysisMaterial = prop.Material.AnalysisMaterial;
else if (prop.API_Prop3d.MaterialAnalysisProperty > 0 && analysisMaterial == null)
analysisMaterial = prop.Material.AnalysisMaterial;
}
CreateFromAPI(prop.API_Prop3d.MaterialType, prop.API_Prop3d.MaterialAnalysisProperty, prop.API_Prop3d.MaterialGradeProperty, analysisMaterial);
}
private void CreateFromAPI(MaterialType materialType, int analysisProp, int gradeProp, AnalysisMaterial analysisMaterial)
Expand Down
Binary file added GsaGH/Properties/Icons/GwaModel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions GsaGH/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GsaGH/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,7 @@
<data name="TotalLoadAndReaction" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\TotalLoadAndReaction.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GwaModel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\GwaModel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

0 comments on commit 2306649

Please sign in to comment.