Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligning with changes in BHoMAdapter Refactoring Level 04 #293

Merged
merged 32 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5df6e52
Adding CRUD folder and migration
IsakNaslundBh Jan 13, 2020
0685432
AdapterIDName
IsakNaslundBh Jan 13, 2020
b42c9dc
Missed AdapterId
IsakNaslundBh Jan 13, 2020
ab49e2c
Update NextId.cs
IsakNaslundBh Jan 13, 2020
2ff8c79
Adapter Actions
IsakNaslundBh Jan 13, 2020
01d53ff
Comparers and DependencyTypes
IsakNaslundBh Jan 13, 2020
185c67b
Renaming fix
IsakNaslundBh Jan 13, 2020
2450a72
Configs and methodnamings for CRUD methods
IsakNaslundBh Jan 13, 2020
6dfc82d
Update tags fix
IsakNaslundBh Jan 13, 2020
4e5ad5a
Rename filke to UpdateTags
IsakNaslundBh Jan 13, 2020
c278737
Load modules
IsakNaslundBh Jan 13, 2020
e5ba5ee
Folder tidy up.
alelom Jan 14, 2020
8c29d02
Execute now returns `Output<object,bool>`
alelom Jan 14, 2020
6f981a8
Execute returns `Output<List<object>, bool>`
alelom Jan 16, 2020
6f8d71e
Adding missing commands and fallback
IsakNaslundBh Jan 17, 2020
1c519c2
Fixing some comment lines and method to private
IsakNaslundBh Jan 17, 2020
cba993a
More comment headers
IsakNaslundBh Jan 17, 2020
5f0c8a7
Update close to handle save boolean
IsakNaslundBh Jan 17, 2020
07e5791
Update to Close to close model, not application
IsakNaslundBh Jan 17, 2020
3d22963
adding comparer for Bar
IsakNaslundBh Jan 20, 2020
4cf86f9
Adding loads to dependency types
IsakNaslundBh Jan 20, 2020
96d3fa2
Tweaking delete to else if and calling base for not yet supperted types
IsakNaslundBh Jan 20, 2020
72dbd63
Adding empty line
IsakNaslundBh Jan 20, 2020
e1b8c09
Update Analyse as previous method had flaws
IsakNaslundBh Jan 21, 2020
0b9cc34
Update extract case numbers after adapter changes
IsakNaslundBh Jan 21, 2020
b7079de
remove empty line
IsakNaslundBh Jan 21, 2020
d86c7e5
Adding ActionConfig to all ReadResults methods
IsakNaslundBh Jan 22, 2020
ca2ffc3
Missing action config
IsakNaslundBh Jan 22, 2020
8676e2c
Rollback of Load dependencies
IsakNaslundBh Jan 23, 2020
dd59cb1
moving private methods in main adapter file
IsakNaslundBh Jan 24, 2020
729afc4
whitespace
IsakNaslundBh Jan 24, 2020
95acc13
fix for range of cases for execute
IsakNaslundBh Jan 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,131 +26,104 @@
using System;
using BH.oM.Structure.Loads;
using RobotOM;
using BH.oM.Adapter;
using BH.oM.Reflection;
using BH.oM.Adapter.Commands;

namespace BH.Adapter.Robot
{
public partial class RobotAdapter
{
/***************************************************/
/**** Adapter Methods ****/
/**** IAdapter Interface ****/
/***************************************************/

public override bool Execute(string command, Dictionary<string, object> parameters = null, Dictionary<string, object> config = null)
public override Output<List<object>, bool> Execute(IExecuteCommand command, ActionConfig actionConfig = null)
{
string commandUpper = command.ToUpper();
var output = new Output<List<object>, bool>() { Item1 = null, Item2 = false };

if (commandUpper == "CLOSE")
return Close();
output.Item2 = RunCommand(command as dynamic);

else if (commandUpper == "SAVE")
{
string fileName = default(string);
string[] fileNameStringAlt = {
"Filename",
"File name",
"File_name",
"filename",
"file name",
"file_name",
"FileName",
"File Name",
"File_Name",
"FILENAME",
"FILE NAME",
"FILE_NAME"
};
foreach (string str in fileNameStringAlt)
{
if (parameters.ContainsKey(str))
{
fileName = (string)parameters[str];
break;
}
}
return Save(fileName);
}
return output;
}

//else if (commandUpper == "CLEARRESULTS" || commandUpper == "DELETERESULTS")
//{
// return ClearResults();
//}
/***************************************************/
/**** Commands ****/
/***************************************************/

else if (commandUpper == "ANALYSE" || commandUpper == "RUN")
{
IList cases = null;
string[] caseStringAlt =
{
"Cases",
"CASES",
"cases",
"LoadCases",
"LOADCASES",
"loadcases",
"Loadcases",
"Load Cases",
"LOAD CASES",
"load cases",
"Load cases",
"Load_Cases",
"LOAD_CASES",
"load_cases",
"Load_cases"
};
foreach (string str in caseStringAlt)
{
object obj;
if (parameters.TryGetValue(str, out obj))
{
cases = obj as IList;
break;
}
}
return Analyse(cases);
}
public bool RunCommand(NewModel command)
{
m_RobotApplication.Interactive = 1;
m_RobotApplication.Project.New(IRobotProjectType.I_PT_SHELL);
return true;
}

else
return false;
/***************************************************/

public bool RunCommand(Close command)
{
if (command.SaveBeforeClose)
m_RobotApplication.Project.Save();

m_RobotApplication.Project.Close();
return true;
}

/***************************************************/

public bool Close()
public bool RunCommand(Save command)
{
m_RobotApplication.Quit(IRobotQuitOption.I_QO_PROMPT_TO_SAVE_CHANGES);
m_RobotApplication.Project.Save();
return true;
}

/***************************************************/

public bool Save(string fileName = null)
public bool RunCommand(SaveAs command)
{
if (fileName == null)
{
m_RobotApplication.Project.Save();
return true;
}
else
{
m_RobotApplication.Project.SaveAs(fileName);
return true;
}
m_RobotApplication.Project.SaveAs(command.FileName);
return true;
}

/***************************************************/

public bool Analyse(IList cases = null)
public bool RunCommand(AnalyseLoadCases command)
{
return Analyse(command.LoadCases);
}

/***************************************************/

public bool RunCommand(Analyse command)
{
return Analyse();
}

/***************************************************/

public bool RunCommand(IExecuteCommand command)
{
Engine.Reflection.Compute.RecordWarning($"The command {command.GetType().Name} is not supported by this Adapter.");
return false;
}

/***************************************************/
/**** Private Support Methods ****/
/***************************************************/

private bool Analyse(IEnumerable<object> cases = null)
{
RobotSelection rSelection = m_RobotApplication.Project.Structure.Selections.Create(IRobotObjectType.I_OT_CASE);
int index = m_RobotApplication.Project.Structure.Cases.FreeNumber;
if(index > 2)
if (index > 2)
rSelection.FromText("1to" + (index - 1).ToString());
else
rSelection.FromText("1");
SetAux(rSelection, false);

rSelection = m_RobotApplication.Project.Structure.Selections.Create(IRobotObjectType.I_OT_CASE);
if (cases != null && cases.Count > 0)

if (cases != null && cases.Count() > 0)
{
List<int> caseNums = GetCaseNumbers(cases);
string str = "";
Expand All @@ -176,57 +149,46 @@ public bool Analyse(IList cases = null)

/***************************************************/

private List<int> GetCaseNumbers(IList cases)
private List<int> GetCaseNumbers(IEnumerable<object> cases)
{
List<int> caseNums = new List<int>();

if (cases is List<string>)
return (cases as List<string>).Select(x => int.Parse(x)).ToList();
else if (cases is List<int>)
return cases as List<int>;
else if (cases is List<double>)
return (cases as List<double>).Select(x => (int)Math.Round(x)).ToList();

else if (cases is List<Loadcase>)
foreach (object o in cases)
{
for (int i = 0; i < cases.Count; i++)
int id;
if (o is Loadcase)
{
caseNums.Add(System.Convert.ToInt32((cases[i] as Loadcase).Number));
caseNums.Add((o as Loadcase).Number);
}
}
else if (cases is List<LoadCombination>)
{
foreach (object lComb in cases)
else if (o is LoadCombination)
{
LoadCombination lComb = (o as LoadCombination);
foreach (Tuple<double, ICase> lCase in (lComb as LoadCombination).LoadCases)
{
caseNums.Add(System.Convert.ToInt32(lCase.Item2.Number));
}
caseNums.Add(System.Convert.ToInt32((lComb as LoadCombination).CustomData[AdapterId]));
caseNums.Add(System.Convert.ToInt32((lComb as LoadCombination).CustomData[AdapterIdName]));
}
}

else
{
List<int> idsOut = new List<int>();
foreach (object o in cases)
else if (o is int)
{
int id;
if (int.TryParse(o.ToString(), out id))
{
idsOut.Add(id);
}
caseNums.Add((int)o);
}
else if (int.TryParse(o.ToString(), out id))
{
caseNums.Add(id);
}
else
{
Engine.Reflection.Compute.RecordWarning("Could not extract case information from object " + o.ToString() + ". Case information need to be provided as Loadcases, Loadcombinations or as case numbers (string or int)");
}
return idsOut;
}


return caseNums;

}

/***************************************************/

public void SetAux(RobotSelection CSelection, bool yn)
private void SetAux(RobotSelection CSelection, bool yn)
{
RobotCaseCollection Caux = m_RobotApplication.Project.Structure.Cases.GetMany(CSelection);
RobotCaseServer CServer = m_RobotApplication.Project.Structure.Cases;
Expand Down
60 changes: 60 additions & 0 deletions Robot_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.IO;
using System.Collections.Generic;
using RobotOM;
using System.Diagnostics;
using BH.oM.Adapters.Robot;
using BH.Engine.Adapters.Robot;
using BH.oM.Data.Requests;
using BH.oM.Adapter;

namespace BH.Adapter.Robot
{
public partial class RobotAdapter
{

/***************************************************/
/**** Public Methods ****/
/***************************************************/

/* Temporary override of the pull method until updates have been made to the MeshResults and IResultCOllection : IResult
*/
public override IEnumerable<object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
FilterRequest filter = request as FilterRequest;
if (filter != null)
{
if (filter.Type == typeof(BH.oM.Structure.Results.MeshResult))
{
return ReadMeshResults(filter);
}
}

return base.Pull(request, pullType, actionConfig);
}

/***************************************************/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)
List<Bar> nonCacheBars = new List<Bar>();
foreach (Bar bhomBar in bars)
{
barNum = System.Convert.ToInt32(bhomBar.CustomData[AdapterId]);
barNum = System.Convert.ToInt32(bhomBar.CustomData[AdapterIdName]);

//if (bhomBar.SectionProperty != null)
//{
Expand All @@ -73,8 +73,8 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)
materialName = bhomBar.SectionProperty.Material.Name;
}
rcache.AddBar(barNum,
System.Convert.ToInt32(bhomBar.StartNode.CustomData[AdapterId]),
System.Convert.ToInt32(bhomBar.EndNode.CustomData[AdapterId]),
System.Convert.ToInt32(bhomBar.StartNode.CustomData[AdapterIdName]),
System.Convert.ToInt32(bhomBar.EndNode.CustomData[AdapterIdName]),
sectionName,
materialName,
bhomBar.OrientationAngle * 180 / Math.PI);
Expand Down Expand Up @@ -128,7 +128,7 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)
{
try
{
barNum = System.Convert.ToInt32(bhomBar.CustomData[AdapterId]);
barNum = System.Convert.ToInt32(bhomBar.CustomData[AdapterIdName]);
RobotBar rBar = barServer.Get(barNum) as RobotBar;
barTags[barNum] = bhomBar.Tags;
BH.Engine.Robot.Convert.SetFEAType(rBar, bhomBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ private bool CreateCollection(IEnumerable<FEMesh> fEMeshes)
if (fMeshFace.NodeListIndices.Count == 3)
{
ptarray.SetSize(3);
ptarray.Set(1, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[0]].CustomData[AdapterId]));
ptarray.Set(2, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[1]].CustomData[AdapterId]));
ptarray.Set(3, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[2]].CustomData[AdapterId]));
ptarray.Set(1, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[0]].CustomData[AdapterIdName]));
ptarray.Set(2, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[1]].CustomData[AdapterIdName]));
ptarray.Set(3, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[2]].CustomData[AdapterIdName]));
}
else if (fMeshFace.NodeListIndices.Count == 4)
{
ptarray.SetSize(4);
ptarray.Set(1, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[0]].CustomData[AdapterId]));
ptarray.Set(2, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[1]].CustomData[AdapterId]));
ptarray.Set(3, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[2]].CustomData[AdapterId]));
ptarray.Set(4, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[3]].CustomData[AdapterId]));
ptarray.Set(1, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[0]].CustomData[AdapterIdName]));
ptarray.Set(2, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[1]].CustomData[AdapterIdName]));
ptarray.Set(3, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[2]].CustomData[AdapterIdName]));
ptarray.Set(4, System.Convert.ToInt32(fEMesh.Nodes[fMeshFace.NodeListIndices[3]].CustomData[AdapterIdName]));
}

FEMeshFace clone = fMeshFace.GetShallowClone() as FEMeshFace;
clone.CustomData[AdapterId] = fMeshFaceIdx;
clone.CustomData[AdapterIdName] = fMeshFaceIdx;
fEMesh.Faces[i] = clone;

faceList = faceList + fMeshFaceIdx.ToString() + ",";
Expand All @@ -82,7 +82,7 @@ private bool CreateCollection(IEnumerable<FEMesh> fEMeshes)
faceList.TrimEnd(',');

int elemNumber = objServer.Objects.FreeNumber;
fEMesh.CustomData[AdapterId] = elemNumber;
fEMesh.CustomData[AdapterIdName] = elemNumber;
objServer.Objects.CreateOnFiniteElems(faceList, elemNumber);
mesh = objServer.Objects.Get(elemNumber) as RobotObjObject;
if (fEMesh.Property is LoadingPanelProperty)
Expand Down
Loading