public static SpeckleObject ToSpeckle(this GSA1DElementResult dummyObject)
        {
            if (Initialiser.Settings.Element1DResults.Count() == 0)
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults && !Initialiser.GSASenderObjects.ContainsKey(typeof(GSA1DElement)))
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults)
            {
                var elements = Initialiser.GSASenderObjects[typeof(GSA1DElement)].Cast <GSA1DElement>().ToList();

                var entities = elements.Cast <IGSASpeckleContainer>().ToList();

                foreach (var kvp in Initialiser.Settings.Element1DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        foreach (var entity in entities)
                        {
                            var id = entity.GSAId;

                            if (entity.Value.Result == null)
                            {
                                entity.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", Initialiser.Settings.Result1DNumPosition);

                            if (resultExport == null)
                            {
                                continue;
                            }

                            if (!entity.Value.Result.ContainsKey(loadCase))
                            {
                                entity.Value.Result[loadCase] = new Structural1DElementResult()
                                {
                                    Value = new Dictionary <string, object>()
                                }
                            }
                            ;

                            (entity.Value.Result[loadCase] as Structural1DElementResult).Value[kvp.Key] = resultExport;
                        }
                    }
                }

                // Linear interpolate the line values
                foreach (var entity in entities)
                {
                    var dX = (entity.Value.Value[3] - entity.Value.Value[0]) / (Initialiser.Settings.Result1DNumPosition + 1);
                    var dY = (entity.Value.Value[4] - entity.Value.Value[1]) / (Initialiser.Settings.Result1DNumPosition + 1);
                    var dZ = (entity.Value.Value[5] - entity.Value.Value[2]) / (Initialiser.Settings.Result1DNumPosition + 1);

                    var interpolatedVertices = new List <double>();
                    interpolatedVertices.AddRange((entity.Value.Value as List <double>).Take(3));

                    for (var i = 1; i <= Initialiser.Settings.Result1DNumPosition; i++)
                    {
                        interpolatedVertices.Add(interpolatedVertices[0] + dX * i);
                        interpolatedVertices.Add(interpolatedVertices[1] + dY * i);
                        interpolatedVertices.Add(interpolatedVertices[2] + dZ * i);
                    }

                    interpolatedVertices.AddRange((entity.Value.Value as List <double>).Skip(3).Take(3));

                    entity.Value.ResultVertices = interpolatedVertices;
                }
            }
            else
            {
                Initialiser.GSASenderObjects[typeof(GSA1DElementResult)] = new List <object>();

                var results = new List <GSA1DElementResult>();

                var keyword = HelperClass.GetGSAKeyword(typeof(GSA1DElement));
                var gwa     = Initialiser.Cache.GetGwa(keyword);

                foreach (var kvp in Initialiser.Settings.Element1DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        for (var i = 0; i < gwa.Count(); i++)
                        {
                            var record = gwa[i];

                            var pPieces = record.ListSplit("\t");
                            if (pPieces[4].ParseElementNumNodes() != 2)
                            {
                                continue;
                            }

                            if (!int.TryParse(pPieces[1], out var id))
                            {
                                //Could not extract index
                                continue;
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global", Initialiser.Settings.Result1DNumPosition);

                            if (resultExport == null || resultExport.Count() == 0)
                            {
                                continue;
                            }

                            var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == id.ToString());
                            if (existingRes == null)
                            {
                                var newRes = new Structural1DElementResult()
                                {
                                    Value     = new Dictionary <string, object>(),
                                    TargetRef = HelperClass.GetApplicationId(typeof(GSA1DElement).GetGSAKeyword(), id),
                                    IsGlobal  = !Initialiser.Settings.ResultInLocalAxis,
                                };
                                newRes.Value[kvp.Key] = resultExport;

                                newRes.GenerateHash();

                                results.Add(new GSA1DElementResult()
                                {
                                    Value = newRes
                                });
                            }
                            else
                            {
                                existingRes.Value.Value[kvp.Key] = resultExport;
                            }
                        }
                    }
                }

                Initialiser.GSASenderObjects[typeof(GSA1DElementResult)].AddRange(results);
            }

            return(new SpeckleObject());
        }
        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());
        }
        public static SpeckleObject ToSpeckle(this GSA2DElementResult dummyObject)
        {
            if (Initialiser.Settings.Element2DResults.Count() == 0)
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults && !Initialiser.GSASenderObjects.ContainsKey(typeof(GSA2DElement)))
            {
                return(new SpeckleNull());
            }

            if (Initialiser.Settings.EmbedResults)
            {
                var elements = Initialiser.GSASenderObjects[typeof(GSA2DElement)].Cast <GSA2DElement>().ToList();

                foreach (var kvp in Initialiser.Settings.Element2DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        foreach (var element in elements)
                        {
                            var id = element.GSAId;

                            if (element.Value.Result == null)
                            {
                                element.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 (!element.Value.Result.ContainsKey(loadCase))
                            {
                                element.Value.Result[loadCase] = new Structural2DElementResult()
                                {
                                    Value = new Dictionary <string, object>()
                                }
                            }
                            ;

                            // Let's split the dictionary into xxx_face and xxx_vertex
                            var faceDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => new List <double>()
                            {
                                (x.Value as List <double>).Last()
                            } as object);
                            var vertexDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => (x.Value as List <double>).Take((x.Value as List <double>).Count - 1).ToList() as object);

                            (element.Value.Result[loadCase] as Structural2DElementResult).Value[kvp.Key + "_face"]   = faceDictionary;
                            (element.Value.Result[loadCase] as Structural2DElementResult).Value[kvp.Key + "_vertex"] = vertexDictionary;
                        }
                    }
                }
            }
            else
            {
                Initialiser.GSASenderObjects[typeof(GSA2DElementResult)] = new List <object>();

                var results = new List <GSA2DElementResult>();

                var keyword = HelperClass.GetGSAKeyword(typeof(GSA2DElement));
                var gwa     = Initialiser.Cache.GetGwa(keyword);

                foreach (var kvp in Initialiser.Settings.Element2DResults)
                {
                    foreach (var loadCase in Initialiser.Settings.ResultCases)
                    {
                        if (!Initialiser.Interface.CaseExist(loadCase))
                        {
                            continue;
                        }

                        for (var i = 0; i < gwa.Count(); i++)
                        {
                            var record = gwa[i];

                            var pPieces = record.ListSplit("\t");
                            if (pPieces[4].ParseElementNumNodes() != 3 && pPieces[4].ParseElementNumNodes() != 4)
                            {
                                continue;
                            }

                            if (!int.TryParse(pPieces[1], out var id))
                            {
                                //Could not extract index
                                continue;
                            }

                            var resultExport = Initialiser.Interface.GetGSAResult(id, kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3, loadCase, Initialiser.Settings.ResultInLocalAxis ? "local" : "global");

                            if (resultExport == null)
                            {
                                continue;
                            }

                            // Let's split the dictionary into xxx_face and xxx_vertex
                            var faceDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => new List <double>()
                            {
                                (x.Value as List <double>).Last()
                            } as object);
                            var vertexDictionary = resultExport.ToDictionary(
                                x => x.Key,
                                x => (x.Value as List <double>).Take((x.Value as List <double>).Count - 1).ToList() as object);

                            var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == id.ToString());
                            if (existingRes == null)
                            {
                                var newRes = new Structural2DElementResult()
                                {
                                    Value     = new Dictionary <string, object>(),
                                    TargetRef = HelperClass.GetApplicationId(typeof(GSA2DElement).GetGSAKeyword(), id),
                                    IsGlobal  = !Initialiser.Settings.ResultInLocalAxis,
                                };
                                newRes.Value[kvp.Key + "_face"]   = faceDictionary;
                                newRes.Value[kvp.Key + "_vertex"] = vertexDictionary;

                                newRes.GenerateHash();

                                results.Add(new GSA2DElementResult()
                                {
                                    Value = newRes
                                });
                            }
                            else
                            {
                                existingRes.Value.Value[kvp.Key + "_face"]   = faceDictionary;
                                existingRes.Value.Value[kvp.Key + "_vertex"] = vertexDictionary;
                            }
                        }
                    }
                }

                Initialiser.GSASenderObjects[typeof(GSA2DElementResult)].AddRange(results);
            }

            return(new SpeckleObject());
        }