Skip to content

Commit

Permalink
Merge pull request #22 from arup-group/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nic-burgers-arup committed Oct 20, 2020
2 parents edae8e2 + f026d47 commit cec5e88
Show file tree
Hide file tree
Showing 19 changed files with 672 additions and 259 deletions.
81 changes: 64 additions & 17 deletions SpeckleGSA/BaseReceiverSender.cs
Expand Up @@ -7,10 +7,10 @@

namespace SpeckleGSA
{
public abstract class BaseReceiverSender
{
public bool IsInit = false;
public bool IsBusy = false;
public abstract class BaseReceiverSender
{
public bool IsInit = false;
public bool IsBusy = false;

#region lock-related

Expand All @@ -31,6 +31,31 @@ protected void ExecuteWithLock(ref object lockObject, Action a)
}
#endregion

protected List<string> GetFilteredKeywords(IEnumerable<KeyValuePair<Type, List<Type>>> prereqs)
{
var keywords = new List<string>();
foreach (var kvp in prereqs)
{
try
{
var keyword = (string)kvp.Key.GetAttribute("GSAKeyword");
if (keyword.Length > 0)
{
keywords.AddIfNotContains(keyword);
var subKeywords = (string[])kvp.Key.GetAttribute("SubGSAKeywords");
if (subKeywords.Length > 0)
{
foreach (var skw in subKeywords)
{
keywords.AddIfNotContains(skw);
}
}
}
}
catch { }
}
return keywords;
}
protected List<string> GetFilteredKeywords(Dictionary<Type, List<Type>> prereqs)
{
var keywords = new List<string>();
Expand All @@ -57,21 +82,21 @@ protected List<string> GetFilteredKeywords(Dictionary<Type, List<Type>> prereqs)
return keywords;
}

protected bool ObjectTypeMatchesLayer(Type t, GSATargetLayer layer)
{
var analysisLayerAttribute = t.GetAttribute("AnalysisLayer");
var designLayerAttribute = t.GetAttribute("DesignLayer");
protected bool ObjectTypeMatchesLayer(Type t, GSATargetLayer layer)
{
var analysisLayerAttribute = t.GetAttribute("AnalysisLayer");
var designLayerAttribute = t.GetAttribute("DesignLayer");

//If an object type has a layer attribute exists and its boolean value doesn't match the settings target layer, then it doesn't match. This could be reviewed and simplified.
if ((analysisLayerAttribute != null && layer == GSATargetLayer.Analysis && !(bool)analysisLayerAttribute)
|| (designLayerAttribute != null && layer == GSATargetLayer.Design && !(bool)designLayerAttribute))
{
return false;
}
return true;
}
//If an object type has a layer attribute exists and its boolean value doesn't match the settings target layer, then it doesn't match. This could be reviewed and simplified.
if ((analysisLayerAttribute != null && layer == GSATargetLayer.Analysis && !(bool)analysisLayerAttribute)
|| (designLayerAttribute != null && layer == GSATargetLayer.Design && !(bool)designLayerAttribute))
{
return false;
}
return true;
}

protected List<IGSASenderDictionary> GetAssembliesStaticTypes()
public static List<IGSASenderDictionary> GetAssembliesSenderDictionaries()
{
var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer))));
var staticObjects = new List<IGSASenderDictionary>();
Expand All @@ -97,5 +122,27 @@ protected List<IGSASenderDictionary> GetAssembliesStaticTypes()
}
return staticObjects;
}

public static Dictionary<Type, List<object>> GetAllConvertedGsaObjectsByType()
{
var gsaStaticObjects = GetAssembliesSenderDictionaries();
var currentObjects = new Dictionary<Type, List<object>>();
foreach (var dict in gsaStaticObjects)
{
var allObjects = dict.GetAll();
//Ensure alphabetical order here as this has a bearing on the order of the layers when it's sent, and therefore the order of
//the layers as displayed in GH. Note the type names here are the GSA ones (e.g. GSAGravityLoading) not the StructuralClasses ones
var sortedKeys = allObjects.Keys.OrderBy(k => k.Name);
foreach (var t in sortedKeys)
{
if (!currentObjects.ContainsKey(t))
{
currentObjects[t] = new List<object>();
}
currentObjects[t].AddRange(allObjects[t]);
}
}
return currentObjects;
}
}
}
4 changes: 2 additions & 2 deletions SpeckleGSA/Properties/AssemblyInfo.cs
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.11.1.1")]
[assembly: AssemblyFileVersion("0.11.1.1")]
[assembly: AssemblyVersion("0.11.1.2")]
[assembly: AssemblyFileVersion("0.11.1.2")]
8 changes: 3 additions & 5 deletions SpeckleGSA/Receiver.cs
Expand Up @@ -54,8 +54,6 @@ public async Task<List<string>> Initialize(string restApi, string apiToken)
ExecuteWithLock(ref traversedSerialisedLock, () => traversedSerialisedTypes.Clear());
ExecuteWithLock(ref traversedDeserialisedLock, () => traversedDeserialisedTypes.Clear());

senderDictionaries.Clear();

Status.AddMessage("Initialising receivers");

var attributeType = typeof(GSAObject);
Expand Down Expand Up @@ -205,7 +203,7 @@ public async void Trigger(object sender, EventArgs e)
GSA.gsaCache.Snapshot(streamIds[i]);
}

var gsaStaticObjects = GetAssembliesStaticTypes();
var gsaStaticObjects = GetAssembliesSenderDictionaries();

foreach (var dict in gsaStaticObjects)
{
Expand All @@ -225,7 +223,7 @@ public async void Trigger(object sender, EventArgs e)
var otherLayer = GSA.Settings.TargetLayer == GSATargetLayer.Design ? GSATargetLayer.Analysis : GSATargetLayer.Design;
await ProcessObjectsForLayer(otherLayer);

var toBeAddedGwa = GSA.gsaCache.GetNewlyAddedGwa();
var toBeAddedGwa = GSA.gsaCache.GetNewlyGwaSetCommands();
for (int i = 0; i < toBeAddedGwa.Count(); i++)
{
GSA.gsaProxy.SetGwa(toBeAddedGwa[i]);
Expand Down Expand Up @@ -490,7 +488,7 @@ private void SerialiseUpdateCacheForGSAType(GSATargetLayer layer, string keyword

if (!traversedSerialisedTypes.Contains(readPrereqs[j]))
{
var prereqResult = Converter.Serialise(prereqDummyObject);
_ = Converter.Serialise(prereqDummyObject);
var prereqSerialisedObjects = CollateSerialisedObjects(readPrereqs[j]);

for (int k = 0; k < prereqSerialisedObjects.Count; k++)
Expand Down

0 comments on commit cec5e88

Please sign in to comment.