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

Make use of caching system in base adapter #418

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Etabs_Adapter/CRUD/Read/Bar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public partial class ETABSAdapter : BHoMAdapter
private List<Bar> ReadBar(List<string> ids = null)
{
List<Bar> barList = new List<Bar>();
Dictionary<string, Node> bhomNodes = ReadNode().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, ISectionProperty> bhomSections = ReadSectionProperty().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Node> bhomNodes = GetCachedOrReadAsDictionary<string, Node>();
Dictionary<string, ISectionProperty> bhomSections = GetCachedOrReadAsDictionary<string, ISectionProperty>();

int nameCount = 0;
string[] names = { };
Expand Down
68 changes: 41 additions & 27 deletions Etabs_Adapter/CRUD/Read/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,62 +84,80 @@ private List<RigidLink> ReadRigidLink(List<string> ids = null)
}
}

Dictionary<string, LinkConstraint> constraints = new Dictionary<string, LinkConstraint>();


foreach (KeyValuePair<string, List<string>> kvp in idDict)
{
RigidLink bhLink = new RigidLink();
SetAdapterId(bhLink, kvp.Key);

if (kvp.Value == null)
{
SetAdapterId(bhLink, kvp.Key);
string startId = "";
string endId = "";
m_model.LinkObj.GetPoints(kvp.Key, ref startId, ref endId);

List<Node> endNodes = ReadNode(new List<string> { startId, endId });
bhLink.PrimaryNode = endNodes[0];
bhLink.SecondaryNodes = new List<Node>() { endNodes[1] };
//Dummy nodes with correct Id
bhLink.PrimaryNode = new Node { Name = startId };
bhLink.SecondaryNodes = new List<Node>() { new Node { Name = endId } };
}
else
{

SetAdapterId(bhLink, kvp.Key);
string startId = "";
string endId = "";
string multiLinkId = kvp.Key + ":::0";
List<string> nodeIdsToRead = new List<string>();


m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
nodeIdsToRead.Add(startId);
bhLink.PrimaryNode = new Node { Name = startId }; //Dummy startnode with correct Id

List<string> endIds = new List<string>();
for (int i = 1; i < kvp.Value.Count(); i++)
{
multiLinkId = kvp.Key + ":::" + i;
m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
nodeIdsToRead.Add(endId);
endIds.Add(endId);
}

List<Node> endNodes = ReadNode(nodeIdsToRead);
bhLink.PrimaryNode = endNodes[0];
endNodes.RemoveAt(0);
bhLink.SecondaryNodes = endNodes;
bhLink.SecondaryNodes = endIds.Select(x => new Node { Name = x }).ToList(); //Dummy endnodes with correct Id
}
string propName = "";
m_model.LinkObj.GetProperty(kvp.Key, ref propName);

LinkConstraint constr;
if (!constraints.TryGetValue(propName, out constr))
{
constr = ReadLinkConstraints(new List<string> { propName }).FirstOrDefault();
constraints[propName] = constr;
}
bhLink.Constraint = constr;
bhLink.Constraint = new LinkConstraint { Name = propName }; //Dummy constraint to be populated in later loop

linkList.Add(bhLink);
}

if (linkList.Count == 0)
return linkList;

//Get ids of primary and secondary nodes
List<string> nodeIds = linkList.SelectMany(x => x.SecondaryNodes.Select(s => s.Name).Concat(new List<string> { x.PrimaryNode.Name })).Distinct().ToList();
Dictionary<string, Node> nodes = GetCachedOrReadAsDictionary<string, Node>(nodeIds);

List<string> contstrainIds = linkList.Select(x => x.Constraint.Name).Distinct().ToList();
//Get cached or read out all constraints used by Links
Dictionary<string, LinkConstraint> constraints = contstrainIds.Any() ? new Dictionary<string, LinkConstraint>() : GetCachedOrReadAsDictionary<string, LinkConstraint>(contstrainIds);

foreach (RigidLink link in linkList)
{
LinkConstraint constraint; //Reasign cached/read contraint
if (constraints.TryGetValue(link.Constraint.Name, out constraint))
link.Constraint = constraint;

Node stNode;
if (nodes.TryGetValue(link.PrimaryNode.Name, out stNode))
link.PrimaryNode = stNode;

for (int i = 0; i < link.SecondaryNodes.Count; i++)
{
Node secNode;
if (nodes.TryGetValue(link.SecondaryNodes[i].Name, out secNode))
link.SecondaryNodes[i] = secNode;
}
}


return linkList;
}

Expand Down Expand Up @@ -234,8 +252,4 @@ private LinkConstraint GetLinearLinkConstraint(string name)

/***************************************************/
}
}




}
16 changes: 8 additions & 8 deletions Etabs_Adapter/CRUD/Read/Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private List<ILoad> ReadLoad(Type type, List<string> ids = null)
{
List<ILoad> loadList = new List<ILoad>();

List<Loadcase> loadcaseList = ReadLoadcase();
List<Loadcase> loadcaseList = GetCachedOrRead<Loadcase>();

if (ids != null)
{
Expand Down Expand Up @@ -132,7 +132,7 @@ private List<ILoad> ReadPointLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Node> bhomNodes = ReadNode().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Node> bhomNodes = GetCachedOrReadAsDictionary<string, Node>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -180,7 +180,7 @@ private List<ILoad> ReadBarLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Bar> bhomBars = ReadBar().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Bar> bhomBars = GetCachedOrReadAsDictionary<string, Bar>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -244,7 +244,7 @@ private List<ILoad> ReadBarVaryingLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Bar> bhomBars = ReadBar().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Bar> bhomBars = GetCachedOrReadAsDictionary<string, Bar>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -316,7 +316,7 @@ private List<ILoad> ReadAreaLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Panel> bhomPanels = ReadPanel().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Panel> bhomPanels = GetCachedOrReadAsDictionary<string, Panel>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -366,7 +366,7 @@ private List<ILoad> ReadAreaTempratureLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Panel> bhomPanels = ReadPanel().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Panel> bhomPanels = GetCachedOrReadAsDictionary<string, Panel>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -402,7 +402,7 @@ private List<ILoad> ReadBarTempratureLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Bar> bhomBars = ReadBar().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Bar> bhomBars = GetCachedOrReadAsDictionary<string, Bar>();

string[] names = null;
string[] loadcase = null;
Expand Down Expand Up @@ -438,7 +438,7 @@ private List<ILoad> ReadBarPointLoad(List<Loadcase> loadcases)
{
List<ILoad> bhLoads = new List<ILoad>();

Dictionary<string, Bar> bhomBars = ReadBar().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Bar> bhomBars = GetCachedOrReadAsDictionary<string, Bar>();

string[] names = null;
string[] loadcase = null;
Expand Down
2 changes: 1 addition & 1 deletion Etabs_Adapter/CRUD/Read/Loadcase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private List<LoadCombination> ReadLoadCombination(List<string> ids = null)
List<LoadCombination> combinations = new List<LoadCombination>();

//get all load cases before combinations
Dictionary<string, Loadcase> bhomCases = ReadLoadcase().ToDictionary(x => x.Name.ToString());
Dictionary<string, Loadcase> bhomCases = GetCachedOrReadAsDictionary<string, Loadcase>();

int nameCount = 0;
string[] nameArr = { };
Expand Down
4 changes: 2 additions & 2 deletions Etabs_Adapter/CRUD/Read/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private List<FEMesh> ReadMesh(List<string> ids = null)
ids = FilterIds(ids, nameArr);

List<FEMesh> meshes = new List<FEMesh>();
Dictionary<string, Node> nodes = new Dictionary<string, Node>();
Dictionary<string, ISurfaceProperty> surfaceProps = ReadSurfaceProperty().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, Node> nodes = GetCachedOrReadAsDictionary<string, Node>();
Dictionary<string, ISurfaceProperty> surfaceProps = GetCachedOrReadAsDictionary<string, ISurfaceProperty>();

foreach (string id in ids)
{
Expand Down
2 changes: 1 addition & 1 deletion Etabs_Adapter/CRUD/Read/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private List<Panel> ReadPanel(List<string> ids = null)
{
List<Panel> panelList = new List<Panel>();

Dictionary<string, ISurfaceProperty> bhomProperties = ReadSurfaceProperty().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, ISurfaceProperty> bhomProperties = GetCachedOrReadAsDictionary<string, ISurfaceProperty>();
int nameCount = 0;
string[] nameArr = { };
m_model.AreaObj.GetNameList(ref nameCount, ref nameArr);
Expand Down
2 changes: 1 addition & 1 deletion Etabs_Adapter/CRUD/Read/SectionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public partial class ETABSAdapter : BHoMAdapter
private List<ISectionProperty> ReadSectionProperty(List<string> ids = null)
{
List<ISectionProperty> propList = new List<ISectionProperty>();
Dictionary<String, IMaterialFragment> bhomMaterials = ReadMaterial().ToDictionary(x => x.DescriptionOrName());
Dictionary<string, IMaterialFragment> bhomMaterials = GetCachedOrReadAsDictionary<string, IMaterialFragment>();

int nameCount = 0;
string[] names = { };
Expand Down
2 changes: 1 addition & 1 deletion Etabs_Adapter/CRUD/Read/SurfaceProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private List<ISurfaceProperty> ReadSurfaceProperty(List<string> ids = null)
{
List<ISurfaceProperty> propertyList = new List<ISurfaceProperty>();

Dictionary<string, IMaterialFragment> bhomMaterials = ReadMaterial().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, IMaterialFragment> bhomMaterials = GetCachedOrReadAsDictionary<string, IMaterialFragment>();

int nameCount = 0;
string[] nameArr = { };
Expand Down
2 changes: 0 additions & 2 deletions Etabs_Adapter/CRUD/Read/_Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ protected override IEnumerable<IBHoMObject> IRead(Type type, IList ids, ActionCo
return ReadGrid(listIds);
else if (type == typeof(FEMesh))
return ReadMesh(listIds);
else if (type == typeof(FEMesh))
return ReadMesh(listIds);
else if (typeof(IResult).IsAssignableFrom(type))
{
ReadResultsError(type);
Expand Down