public static SpeckleObject ToSpeckle(this GSANodeResult dummyObject) { if (Initialiser.Settings.NodalResults.Count() == 0) { return(new SpeckleNull()); } if (Initialiser.Settings.EmbedResults && !Initialiser.GSASenderObjects.ContainsKey(typeof(GSANode))) { return(new SpeckleNull()); } if (Initialiser.Settings.EmbedResults) { var nodes = Initialiser.GSASenderObjects[typeof(GSANode)].Cast <GSANode>().ToList(); foreach (var kvp in Initialiser.Settings.NodalResults) { foreach (var loadCase in Initialiser.Settings.ResultCases) { if (!Initialiser.Interface.CaseExist(loadCase)) { continue; } foreach (var node in nodes) { var id = node.GSAId; if (node.Value.Result == null) { node.Value.Result = new Dictionary <string, object>(); } var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global"); if (resultExport == null || resultExport.Count() == 0) { continue; } if (!node.Value.Result.ContainsKey(loadCase)) { node.Value.Result[loadCase] = new StructuralNodeResult() { Value = new Dictionary <string, object>() }; } (node.Value.Result[loadCase] as StructuralNodeResult).Value[kvp.Key] = resultExport.ToDictionary(x => x.Key, x => (x.Value as List <double>)[0] as object); node.ForceSend = true; } } } } else { Initialiser.GSASenderObjects[typeof(GSANodeResult)] = new List <object>(); var results = new List <GSANodeResult>(); var keyword = HelperClass.GetGSAKeyword(typeof(GSANode)); var indices = Initialiser.Cache.LookupIndices(keyword).Where(i => i.HasValue).Select(i => i.Value).ToList(); foreach (var kvp in Initialiser.Settings.NodalResults) { foreach (var loadCase in Initialiser.Settings.ResultCases) { if (!Initialiser.Interface.CaseExist(loadCase)) { continue; } for (var i = 0; i < indices.Count(); i++) { var id = indices[i]; //var id = 1; //var highestIndex = (int)Initialiser.Interface.RunGWACommand("HIGHEST\t" + keyword); //while (id <= highestIndex) //{ //if ((int)Initialiser.Interface.RunGWACommand("EXIST\t" + keyword + "\t" + id.ToString()) == 1) //{ var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global"); if (resultExport == null || resultExport.Count() == 0) { id++; continue; } var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == id.ToString()); if (existingRes == null) { var newRes = new StructuralNodeResult() { Value = new Dictionary <string, object>(), TargetRef = HelperClass.GetApplicationId(typeof(GSANode).GetGSAKeyword(), id), IsGlobal = !Initialiser.Settings.ResultInLocalAxis, }; newRes.Value[kvp.Key] = resultExport; newRes.GenerateHash(); results.Add(new GSANodeResult() { Value = newRes }); } else { existingRes.Value.Value[kvp.Key] = resultExport; } //} //id++; } } } Initialiser.GSASenderObjects[typeof(GSANodeResult)].AddRange(results); } return(new SpeckleObject()); }
private static void EmbedNodeResults(string typeName, string axisStr) { var nodes = Initialiser.GsaKit.GSASenderObjects.Get <GSANode>(); foreach (var kvp in Initialiser.AppResources.Settings.NodalResults) { foreach (var loadCase in Initialiser.AppResources.Settings.ResultCases.Where(rc => Initialiser.AppResources.Proxy.CaseExist(rc))) { foreach (var node in nodes) { var id = node.GSAId; var obj = node.Value; try { if (obj.Result == null) { obj.Result = new Dictionary <string, object>(); } var resultExport = Initialiser.AppResources.Proxy.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, axisStr); if (resultExport == null || resultExport.Count() == 0) { continue; } var newResult = new StructuralNodeResult() { LoadCaseRef = loadCase, TargetRef = obj.ApplicationId, Value = new Dictionary <string, object>() }; //The setter of obj.Result won't accept a value if there are no keys (to avoid issues during merging), so //setting a value here needs to be done with at least one key in it if (obj.Result == null) { obj.Result = new Dictionary <string, object>() { { loadCase, newResult } }; } else if (!obj.Result.ContainsKey(loadCase)) { obj.Result[loadCase] = newResult; } (obj.Result[loadCase] as StructuralNodeResult).Value[kvp.Key] = resultExport.ToDictionary(x => x.Key, x => (x.Value as List <double>)[0] as object); node.ForceSend = true; } catch (Exception ex) { var contextDesc = string.Join(" ", typeName, kvp.Key, loadCase); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, contextDesc, id.ToString()); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, contextDesc, id.ToString()); } } } } }
private static bool CreateNodeResultObjects(string typeName, string axisStr) { var results = new List <GSANodeResult>(); var keyword = typeof(GSANode).GetGSAKeyword(); //Unlike embedding, separate results doesn't necessarily mean that there is a Speckle object created for each node. There is always though //some GWA loaded into the cache if (!Initialiser.AppResources.Cache.GetKeywordRecordsSummary(keyword, out var gwa, out var indices, out var applicationIds)) { return(false); } foreach (var kvp in Initialiser.AppResources.Settings.NodalResults) { foreach (var loadCase in Initialiser.AppResources.Settings.ResultCases.Where(rc => Initialiser.AppResources.Proxy.CaseExist(rc))) { for (var i = 0; i < indices.Count(); i++) { try { var resultExport = Initialiser.AppResources.Proxy.GetGSAResult(indices[i], kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, axisStr); if (resultExport == null || resultExport.Count() == 0) { continue; } var targetRef = string.IsNullOrEmpty(applicationIds[i]) ? Helper.GetApplicationId(keyword, indices[i]) : applicationIds[i]; var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == targetRef && x.Value.LoadCaseRef == loadCase); if (existingRes == null) { var newRes = new StructuralNodeResult() { Value = new Dictionary <string, object>(), TargetRef = targetRef, IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, LoadCaseRef = loadCase }; newRes.Value[kvp.Key] = resultExport; newRes.GenerateHash(); results.Add(new GSANodeResult() { Value = newRes, GSAId = indices[i] }); } else { existingRes.Value.Value[kvp.Key] = resultExport; } } catch (Exception ex) { var contextDesc = string.Join(" ", typeName, kvp.Key, loadCase); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, contextDesc, i.ToString()); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, contextDesc, i.ToString()); } } } } Initialiser.GsaKit.GSASenderObjects.AddRange(results); return(true); }
public static SpeckleObject ToSpeckle(this GsaNode dummyObject) { var nodeKw = GsaRecord.GetKeyword<GsaNode>(); var springKw = GsaRecord.GetKeyword<GsaPropSpr>(); var massKw = GsaRecord.GetKeyword<GsaPropMass>(); var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>(); var comboKw = GsaRecord.GetKeyword<GsaCombination>(); var newNodeLines = Initialiser.AppResources.Cache.GetGwaToSerialise(nodeKw); var sendResults = GetNodeResultSettings(out var embedResults, out var resultTypes, out var resultCases); if (sendResults) { Initialiser.AppResources.Proxy.LoadResults(ResultGroup.Node, out int numErrorRows, resultCases, newNodeLines.Keys.ToList()); if (numErrorRows > 0) { Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results"); Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results"); } } //This method produces two types of SpeckleStructural objects var structuralNodes = new List<StructuralNode>(); var structural0dSprings = new List<Structural0DSpring>(); int numToBeSent = 0; #if DEBUG foreach (var i in newNodeLines.Keys) #else Parallel.ForEach(newNodeLines.Keys, i => #endif { GsaNode gsaNode = null; var objNode = Helper.ToSpeckleTryCatch(nodeKw, i, () => { gsaNode = new GsaNode(); if (gsaNode.FromGwa(newNodeLines[i])) { var structuralNode = new StructuralNode() { Name = gsaNode.Name, ApplicationId = SpeckleStructuralGSA.Helper.GetApplicationId(nodeKw, i), Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z }, Restraint = GetRestraint(gsaNode) }; if (gsaNode.MeshSize.HasValue && gsaNode.MeshSize.Value > 0) { structuralNode.GSALocalMeshSize = gsaNode.MeshSize.Value; } if (gsaNode.MassPropertyIndex.HasValue && gsaNode.MassPropertyIndex.Value > 0) { var massGwas = Initialiser.AppResources.Cache.GetGwa(massKw, gsaNode.MassPropertyIndex.Value); if (massGwas != null && massGwas.Count() > 0 && !string.IsNullOrEmpty(massGwas.First())) { var gsaPropMass = new GsaPropMass(); if (gsaPropMass.FromGwa(massGwas.First()) && gsaPropMass.Mass > 0) { structuralNode.Mass = gsaPropMass.Mass; } } } return structuralNode; } return new SpeckleNull(); }); if (objNode !=null && !(objNode is SpeckleNull)) { var structuralNode = (StructuralNode)objNode; GSANodeResult gsaNodeResult = null; //Embed results if appropriate as the last thing to do to the new Speckle object before being added to the collection of objects to be sent if (sendResults) { if (Initialiser.AppResources.Proxy.GetResultHierarchy(ResultGroup.Node, i, out var results) && results != null) { var orderedLoadCases = results.Keys.OrderBy(k => k).ToList(); if (embedResults) { foreach (var loadCase in orderedLoadCases) { if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults)) { continue; } var nodeResult = new StructuralNodeResult() { IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, TargetRef = structuralNode.ApplicationId, Value = sendableResults }; var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw); if (!string.IsNullOrEmpty(loadCaseRef)) { //nodeResult.LoadCaseRef = loadCaseRef; nodeResult.LoadCaseRef = loadCase; } if (structuralNode.Result == null) { //Can't just allocate an empty dictionary as the Result set property won't allow it structuralNode.Result = new Dictionary<string, object>() { { loadCase, nodeResult } }; } else { structuralNode.Result.Add(loadCase, nodeResult); } } } else { foreach (var loadCase in orderedLoadCases) { if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults)) { continue; } var nodeResult = new StructuralNodeResult() { IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, TargetRef = structuralNode.ApplicationId, Value = sendableResults }; var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw); if (!string.IsNullOrEmpty(loadCaseRef)) { //nodeResult.LoadCaseRef = loadCaseRef; nodeResult.LoadCaseRef = loadCase; } gsaNodeResult = new GSANodeResult { Value = nodeResult, GSAId = i }; Initialiser.GsaKit.GSASenderObjects.Add(gsaNodeResult); } } } } var senderObjectGsaNode = new GSANode() { Value = structuralNode, GSAId = i }; if (gsaNodeResult != null) { senderObjectGsaNode.ForceSend = true; } Initialiser.GsaKit.GSASenderObjects.Add(senderObjectGsaNode); numToBeSent++; //Add spring object if appropriate if (gsaNode.SpringPropertyIndex.HasValue && gsaNode.SpringPropertyIndex.Value > 0) { var objSpring = Helper.ToSpeckleTryCatch(nodeKw, i, () => { var springPropRef = SpeckleStructuralGSA.Helper.GetApplicationId(springKw, gsaNode.SpringPropertyIndex.Value); if (!string.IsNullOrEmpty(springPropRef)) { var structural0dSpring = new Structural0DSpring() { //The application ID might need a better mechanism to allow a StructuralNode and Structural0DSpring previously received //that originally created the one node to be separated out again to produce the Application ID to use here for this spring //TO DO - review, for now just append a string to ensure the same Application ID value isn't used twice ApplicationId = gsaNode.ApplicationId + "_spring", Name = gsaNode.Name, Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z }, PropertyRef = springPropRef, Dummy = false }; return structural0dSpring; } return new SpeckleNull(); }); if (!(objSpring is SpeckleNull)) { Initialiser.GsaKit.GSASenderObjects.Add(new GSA0DSpring() { Value = (Structural0DSpring)objSpring, GSAId = i }); numToBeSent++; } } //if spring object needs to be added } //if node object was successfully created } #if !DEBUG ); #endif if (sendResults) { Initialiser.AppResources.Proxy.ClearResults(ResultGroup.Node); } return (numToBeSent > 0) ? new SpeckleObject() : new SpeckleNull(); }