コード例 #1
0
        public static string ToNative(this StructuralLoadCase loadCase)
        {
            if (string.IsNullOrEmpty(loadCase.ApplicationId))
            {
                return("");
            }
            return(Helper.ToNativeTryCatch(loadCase, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaLoadCase>();
                var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, loadCase.ApplicationId);
                var streamId = Initialiser.AppResources.Cache.LookupStream(loadCase.ApplicationId);
                var gsaLoad = new GsaLoadCase()
                {
                    ApplicationId = loadCase.ApplicationId,
                    Index = index,
                    StreamId = streamId,
                    Title = loadCase.Name,
                    CaseType = loadCase.CaseType
                };

                if (gsaLoad.Gwa(out var gwaLines, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, index, gwaLines.First(), streamId, loadCase.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaLoadCase>());
                }
                //TO DO: add to error messages shown on UI
                return "";
            }
コード例 #2
0
    public static SpeckleObject ToSpeckle(this GSA2DElementResult dummyObject)
    {
      var kw = GsaRecord.GetKeyword<GsaEl>();
      var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>();
      var comboKw = GsaRecord.GetKeyword<GsaCombination>();

      //var resultTypes = Initialiser.AppResources.Settings.Element2DResults.Keys.ToList();
      var cases = Initialiser.AppResources.Settings.ResultCases;

      //if (Initialiser.AppResources.Settings.Element2DResults.Count() == 0
      if (!Initialiser.AppResources.Settings.ResultTypes.Any(rt => rt.ToString().ToLower().Contains("2d"))
        || (Initialiser.AppResources.Settings.StreamSendConfig == StreamContentConfig.ModelWithEmbeddedResults
          && Initialiser.GsaKit.GSASenderObjects.Count<GSA2DElement>() == 0))
      {
        return new SpeckleNull();
      }

      var axisStr = Initialiser.AppResources.Settings.ResultInLocalAxis ? "local" : "global";
      var typeName = dummyObject.GetType().Name;


      if (Initialiser.AppResources.Settings.StreamSendConfig == StreamContentConfig.ModelWithEmbeddedResults)
      {
        Embed2DResults(typeName, axisStr, kw, loadTaskKw, comboKw, cases);
      }
      else
      {
        if (!Create2DElementResultObjects(typeName, axisStr, kw, loadTaskKw, comboKw, cases))
        {
          return new SpeckleNull();
        }
      }

      return new SpeckleObject();
    }
コード例 #3
0
        public GsaKit()
        {
            var assembly      = GetType().Assembly; //This assembly
            var assemblyTypes = assembly.GetTypes();

            var gsaBaseType      = typeof(GsaRecord);
            var gsaAttributeType = typeof(GsaType);

            schemaTypes.AddRange(assemblyTypes.Where(t => t.IsSubclassOf(gsaBaseType) && t.CustomAttributes.Any(ca => ca.AttributeType == gsaAttributeType)));

            var oldGsaInterface = typeof(IGSASpeckleContainer);

            oldSchemaTypes.AddRange(assemblyTypes.Where(t => oldGsaInterface.IsAssignableFrom(t) && !t.IsAbstract));

            //First get all keywords associated with implemented classes of the layer - this is needed because the referenced keywords
            //in the GsaType attribute of GsaRecord classes sometimes span both layers
            layerKeywordTypes = new Dictionary <GSATargetLayer, Dictionary <Type, GwaKeyword> >
            {
                { GSATargetLayer.Design, new Dictionary <Type, GwaKeyword>() },
                { GSATargetLayer.Analysis, new Dictionary <Type, GwaKeyword>() }
            };

            //These aren't limited to whether these keywords are implemented in any classes as yet
            layerKeywords = new Dictionary <GSATargetLayer, List <GwaKeyword> >
            {
                { GSATargetLayer.Design, new List <GwaKeyword>() },
                { GSATargetLayer.Analysis, new List <GwaKeyword>() }
            };

            var relevantSchemaTypes = schemaTypes.Where(t => GsaRecord.IsSelfContained(t));

            GenerateLayerKeywords(relevantSchemaTypes);
            GenerateLayerKeywordTypes(relevantSchemaTypes);
        }
コード例 #4
0
        public static string ToNative(this Structural1DPropertyExplicit prop)
        {
            if (string.IsNullOrEmpty(prop.ApplicationId))
            {
                return("");
            }

            var gsaSectionDict = new Dictionary <MaterialType, Func <Structural1DPropertyExplicit, int, GsaSection> >
            {
                { MaterialType.Concrete, ToGsaSectionConcrete },
                { MaterialType.Steel, ToGsaSectionSteel },
                { MaterialType.Generic, ToGsaSectionGeneric }
            };

            var keyword  = GsaRecord.GetKeyword <GsaSection>();
            var streamId = Initialiser.AppResources.Cache.LookupStream(prop.ApplicationId);
            var index    = Initialiser.AppResources.Cache.ResolveIndex(keyword, prop.ApplicationId);

            var materialIndex = 0;
            var materialType  = MaterialType.Generic;

            var materialSteelKeyword = typeof(GSAMaterialSteel).GetGSAKeyword();
            var materialConcKeyword  = typeof(GSAMaterialConcrete).GetGSAKeyword();

            var res = Initialiser.AppResources.Cache.LookupIndex(materialSteelKeyword, prop.MaterialRef);

            if (res.HasValue)
            {
                materialIndex = res.Value;
                materialType  = MaterialType.Steel;
            }
            else
            {
                res = Initialiser.AppResources.Cache.LookupIndex(materialConcKeyword, prop.MaterialRef);
                if (res.HasValue)
                {
                    materialIndex = res.Value;
                    materialType  = MaterialType.Concrete;
                }
                else
                {
                    //For generic, set index to 1 as a default
                    materialIndex = 1;
                }
            }

            var gsaSection = gsaSectionDict[materialType](prop, materialIndex);

            gsaSection.Index         = index;
            gsaSection.ApplicationId = prop.ApplicationId;
            gsaSection.Name          = prop.Name;

            if (gsaSection.Gwa(out var gwaLines, false))
            {
                Initialiser.AppResources.Cache.Upsert(keyword, index, gwaLines.First(), streamId, prop.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaSection>());
            }

            return("");
        }
コード例 #5
0
        /*
         * private Dictionary<Type, List<Type>> ResultTypeDependencies()
         * {
         * //Build up dictionary of new GSA schema types and keywords - to be used to construct dependencies based on these new types
         * var layerSchemaDict = layerKeywordTypes[Initialiser.AppResources.Settings.TargetLayer];
         * var layerSchemaTypes = layerSchemaDict.Keys;
         * var layerKw = layerSchemaDict.Values.Select(v => v.GetStringValue()).ToList();
         *
         * var resultTypeDependencies = new Dictionary<Type, List<Type>>();
         * var oldSchemaResultTypes = oldSchemaTypes.Where(t => ((string)t.GetAttribute<GSAObject>("Stream")).Contains("result")).ToList();
         * foreach (var t in oldSchemaResultTypes)
         * {
         *  if (!resultTypeDependencies.ContainsKey(t))
         *  {
         *    resultTypeDependencies.Add(t, new List<Type>());
         *  }
         *
         *  var attVal = t.GetAttribute<GSAObject>("ReadPrerequisite");
         *  var prereqs = (attVal != null) ? ((Type[])attVal).ToList() : new List<Type>();
         *
         *  //the prereqs list is a list of the old schema types
         *  foreach (var tPrereq in prereqs)
         *  {
         *    //Remove version for comparison with keyword enum
         *    var kwPrereq = ((string)tPrereq.GetAttribute<GSAObject>("GSAKeyword")).Split('.').First();
         *
         *    if (layerKw.Any(lkw => lkw.Equals(kwPrereq, StringComparison.InvariantCultureIgnoreCase)))
         *    {
         *      resultTypeDependencies[t].Add(tPrereq);
         *    }
         *  }
         * }
         * return resultTypeDependencies;
         * }
         */

        private Dictionary <GSATargetLayer, bool> TypeLayers(Type t)
        {
            return(new Dictionary <GSATargetLayer, bool>
            {
                { GSATargetLayer.Design, GsaRecord.IsDesignLayer(t) },
                { GSATargetLayer.Analysis, GsaRecord.IsAnalysisLayer(t) }
            });
        }
コード例 #6
0
        public static string ToNative(this Structural0DSpring spring)
        {
            if (string.IsNullOrEmpty(spring.ApplicationId) || spring.Value == null || string.IsNullOrEmpty(spring.PropertyRef))
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(spring, () =>
            {
                var propIndex = Initialiser.AppResources.Cache.LookupIndex(GsaRecord.GetKeyword <GsaPropSpr>(), spring.PropertyRef);
                if (propIndex == null)
                {
                    //TO DO : add error message
                    return "";
                }

                var keyword = GsaRecord.GetKeyword <GsaNode>();
                var streamId = Initialiser.AppResources.Cache.LookupStream(spring.ApplicationId);
                var index = Initialiser.AppResources.Proxy.NodeAt(spring.Value[0], spring.Value[1], spring.Value[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance);

                var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index);
                GsaNode gsaNode;
                if (existingGwa == null || existingGwa.Count() == 0 || string.IsNullOrEmpty(existingGwa.First()))
                {
                    gsaNode = new GsaNode()
                    {
                        Index = index,
                        ApplicationId = spring.ApplicationId,
                        Name = spring.Name,
                        StreamId = streamId,
                        X = spring.Value[0],
                        Y = spring.Value[1],
                        Z = spring.Value[2],
                        SpringPropertyIndex = propIndex
                    };
                }
                else
                {
                    gsaNode = new GsaNode();
                    if (!gsaNode.FromGwa(existingGwa.First()))
                    {
                        //TO DO: add error mesage
                        return "";
                    }
                    gsaNode.SpringPropertyIndex = propIndex;
                }

                //Yes, the Axis member of the Speckle StructuralSpringProperty object is not used

                if (gsaNode.Gwa(out var gwaLines, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, gsaNode.Index.Value, gwaLines.First(), streamId, gsaNode.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaNode>());
                }

                return "";
            }
コード例 #7
0
        public static string ToNative(this StructuralStorey storey)
        {
            if (string.IsNullOrEmpty(storey.ApplicationId) && Helper.IsZeroAxis(storey.Axis))
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(storey, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaGridPlane>();
                var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, storey.ApplicationId);
                var streamId = Initialiser.AppResources.Cache.LookupStream(storey.ApplicationId);

                var gsaPlane = new GsaGridPlane()
                {
                    Index = index,
                    ApplicationId = storey.ApplicationId,
                    StreamId = streamId,
                    Name = storey.Name,
                    Elevation = storey.Elevation,
                    Type = GridPlaneType.Storey,
                };

                gsaPlane.StoreyToleranceAboveAuto = (!storey.ToleranceAbove.HasValue || storey.ToleranceAbove.Value == 0);
                if (storey.ToleranceBelow.HasValue && storey.ToleranceBelow.Value != 0)
                {
                    gsaPlane.StoreyToleranceBelow = storey.ToleranceBelow;
                }
                gsaPlane.StoreyToleranceBelowAuto = (!storey.ToleranceBelow.HasValue || storey.ToleranceBelow.Value == 0);
                if (!gsaPlane.StoreyToleranceAboveAuto)
                {
                    gsaPlane.StoreyToleranceAbove = storey.ToleranceAbove;
                }

                if (storey.ValidNonZero())
                {
                    gsaPlane.AxisRefType = GridPlaneAxisRefType.Reference;
                    //Create new axis on the fly here
                    var gsaAxis = StructuralAxisToNative.ToNativeSchema(storey.Axis);
                    StructuralAxisToNative.ToNative(gsaAxis);

                    gsaPlane.AxisIndex = gsaAxis.Index;
                }
                else
                {
                    gsaPlane.AxisRefType = GridPlaneAxisRefType.Global;
                }

                if (gsaPlane.Gwa(out var gsaPlaneGwaLines, true))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, index, gsaPlaneGwaLines.First(), streamId, storey.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaLoadCase>());
                }

                return "";
            }));
コード例 #8
0
        //These methods are structured slightly differently as currently an axis is a special case - it's not directly part of the structural schema
        //and only called as part of ToNative calls for other higher-level types which create axes as necessary

        public static string ToNative(this GsaAxis gsaAxis)
        {
            var keyword = GsaRecord.GetKeyword <GsaAxis>();

            if (gsaAxis.Gwa(out var gwaLines, false))
            {
                //axes currently never have an application ID
                Initialiser.AppResources.Cache.Upsert(keyword, gsaAxis.Index.Value, gwaLines.First(), gsaAxis.StreamId, "", GsaRecord.GetGwaSetCommandType <GsaAxis>());
            }
            return("");
        }
コード例 #9
0
 private void GenerateLayerKeywordTypes(IEnumerable <Type> relevantSchemaTypes)
 {
     foreach (var t in relevantSchemaTypes)
     {
         foreach (var layer in new[] { GSATargetLayer.Design, GSATargetLayer.Analysis })
         {
             if (MatchesLayer(t, layer))
             {
                 layerKeywordTypes[layer].Add(t, GsaRecord.GetGwaKeyword(t));
             }
         }
     }
 }
コード例 #10
0
        public static SpeckleObject ToSpeckle(this GsaLoadNode dummyObject)
        {
            var typeName = dummyObject.GetType().Name;
            var gsaLoads = Helper.GetNewFromCache <GSA0DLoad, GsaLoadNode>();

            if (gsaLoads.Count() == 0)
            {
                return(new SpeckleObject());
            }
            gsaLoads = gsaLoads.Where(l => l.Index.ValidNonZero()).ToList();

            var keyword         = GsaRecord.GetKeyword <GsaLoadNode>();
            var nodeKeyword     = GsaRecord.GetKeyword <GsaNode>();
            var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>();

            //The 0D loads are split into two groups:
            //1. Those which are grouped by Application ID - n:1 ratio (where n <= 6) between GSA objects and Speckle objects
            //2. Those which are sent out individually - 1:1 ratio between GSA objects and Speckle objects
            //To avoid complication regarding merging with existing objects: if a 0D load was previously received from Speckle (i.e. it has an application ID)
            //and it was manually changed from GLOBAL to referencing an axis, then ignore the application ID when sending out (i.e. lump it with group #2)
            var group1 = gsaLoads.Where(l => !string.IsNullOrEmpty(l.ApplicationId) && l.GlobalAxis);
            var group2 = gsaLoads.Except(group1);
            var nodeIndicesReferenced = new List <int>();

            var structural0DLoads = new List <Structural0DLoad>();
            var gsaNodes          = Initialiser.GsaKit.GSASenderObjects.Get <GSANode>();

            Add0dLoadsWithAppId(nodeKeyword, loadCaseKeyword, group1, gsaNodes, ref structural0DLoads, ref nodeIndicesReferenced);
            Add0dLoadsWithoutAppId(keyword, nodeKeyword, loadCaseKeyword, group2, gsaNodes, ref structural0DLoads, ref nodeIndicesReferenced);

            var forceSendNodes = gsaNodes.Where(n => nodeIndicesReferenced.Any(nir => nir == n.GSAId)).ToList();

            foreach (var fsn in forceSendNodes)
            {
                fsn.ForceSend = true;
            }

            var loads = structural0DLoads.Select(sl => new GSA0DLoad()
            {
                Value = sl
            }).ToList();

            if (loads.Count() > 0)
            {
                Initialiser.GsaKit.GSASenderObjects.AddRange(loads);
            }
            return((loads.Count() > 0) ? new SpeckleObject() : new SpeckleNull());
        }
コード例 #11
0
        public static string ToNative(this Structural1DLoad load)
        {
            if (string.IsNullOrEmpty(load.ApplicationId) && !Helper.IsValidLoading(load.Loading))
            {
                return("");
            }

            //Note: only LOAD_BEAM_UDL is supported at this stage
            var keyword           = GsaRecord.GetKeyword <GsaLoadBeam>();
            var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadBeam>();
            var streamId          = Initialiser.AppResources.Cache.LookupStream(load.ApplicationId);

            var loadCaseIndex = Initialiser.AppResources.Cache.ResolveIndex(GsaRecord.GetKeyword <GsaLoadCase>(), load.LoadCaseRef);

            var entityKeyword = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Design) ? GsaRecord.GetKeyword <GsaMemb>() : GsaRecord.GetKeyword <GsaEl>();
            var entityIndices = Initialiser.AppResources.Cache.LookupIndices(entityKeyword, load.ElementRefs).Where(i => i.HasValue).Select(i => i.Value).ToList();

            var loadingDict = Helper.ExplodeLoading(load.Loading);

            foreach (var k in loadingDict.Keys)
            {
                var applicationId = string.Join("_", load.ApplicationId, k.ToString());
                var index         = Initialiser.AppResources.Cache.ResolveIndex(keyword, applicationId);
                var gsaLoad       = new GsaLoadBeamUdl()
                {
                    Index         = index,
                    ApplicationId = applicationId,
                    StreamId      = streamId,
                    Name          = load.Name,
                    LoadDirection = k,
                    Load          = loadingDict[k],
                    Projected     = false,
                    AxisRefType   = LoadBeamAxisRefType.Global,
                    LoadCaseIndex = loadCaseIndex,
                    Entities      = entityIndices
                };

                if (gsaLoad.Gwa(out var gwa, false))
                {
                    foreach (var gwaLine in gwa)
                    {
                        Initialiser.AppResources.Cache.Upsert(keyword, index, gwaLine, streamId, applicationId, gwaSetCommandType);
                    }
                }
            }

            return("");
        }
コード例 #12
0
 private static Dictionary<int, GsaProp2d> GetGsaPropDict()
 {
   var propsKeyword = GsaRecord.GetKeyword<GsaProp2d>();
   var gsaPropGwas = Initialiser.AppResources.Cache.GetGwa(propsKeyword);
   var gsaProps = new Dictionary<int, GsaProp2d>();
   foreach (var gwa in gsaPropGwas)
   {
     var gsaProp = new GsaProp2d();
     gsaProp.FromGwa(gwa);
     if (gsaProp.Index.HasValue)
     {
       gsaProps.Add(gsaProp.Index.Value, gsaProp);
     }
   }
   return gsaProps;
 }
コード例 #13
0
    public static SpeckleObject ToSpeckle(this GsaPropSpr dummy)
    {
      var kw = GsaRecord.GetKeyword<GsaPropSpr>();
      var newLines = Initialiser.AppResources.Cache.GetGwaToSerialise(kw);

      int numAdded = 0;

      var structuralSpringProperties = new List<StructuralSpringProperty>();

#if DEBUG
      foreach (var i in newLines.Keys)
#else
      Parallel.ForEach(newLines.Keys, i =>
#endif
      {
        var obj = Helper.ToSpeckleTryCatch(kw, i, () =>
        {
          var gsaPropSpr = new GsaPropSpr();
          if (gsaPropSpr.FromGwa(newLines[i]))
          {
            var structuralProp = new StructuralSpringProperty()
            {
              Name = gsaPropSpr.Name,
              ApplicationId = SpeckleStructuralGSA.Helper.GetApplicationId(kw, i),
              DampingRatio = gsaPropSpr.DampingRatio,
              SpringType = gsaPropSpr.PropertyType,
              Stiffness = Helper.AxisDirDictToStructuralVectorSix(gsaPropSpr.Stiffnesses)
            };
            ((Dictionary<string, object>)structuralProp.Properties["structural"]).Add("NativeId", i.ToString());
            return structuralProp;
          }
          return new SpeckleNull();
        });

        if (!(obj is SpeckleNull))
        {
          Initialiser.GsaKit.GSASenderObjects.Add(new GSASpringProperty() { Value = (StructuralSpringProperty)obj, GSAId = i } );
          numAdded++;
        }
      }
#if !DEBUG
      );
#endif

      return (numAdded > 0) ? new SpeckleObject() : new SpeckleNull();
    }
コード例 #14
0
        public static string ToNative(this StructuralSpringProperty prop)
        {
            if (string.IsNullOrEmpty(prop.ApplicationId) || prop.SpringType == StructuralSpringPropertyType.NotSet)
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(prop, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaPropSpr>();
                var streamId = Initialiser.AppResources.Cache.LookupStream(prop.ApplicationId);
                var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, prop.ApplicationId);

                var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index);
                var gsaPropSpr = new GsaPropSpr()
                {
                    Index = index,
                    ApplicationId = prop.ApplicationId,
                    StreamId = streamId,
                    Name = prop.Name,
                    PropertyType = prop.SpringType,
                    DampingRatio = prop.DampingRatio
                };

                if (prop.Stiffness != null && prop.Stiffness.Value != null && prop.Stiffness.Value.Count() > 0)
                {
                    gsaPropSpr.Stiffnesses = new Dictionary <AxisDirection6, double>();
                    for (int i = 0; i < prop.Stiffness.Value.Count(); i++)
                    {
                        if (prop.Stiffness.Value[i] > 0)
                        {
                            gsaPropSpr.Stiffnesses.Add(Helper.AxisDirs[i], prop.Stiffness.Value[i]);
                        }
                    }
                }

                //Yes, the Axis member of the Speckle StructuralSpringProperty object is not used

                if (gsaPropSpr.Gwa(out var gwaLines, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, gsaPropSpr.Index.Value, gwaLines.First(), streamId, gsaPropSpr.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaNode>());
                }

                return "";
            }
コード例 #15
0
        public static string ToNative(this Structural0DLoad load)
        {
            if (string.IsNullOrEmpty(load.ApplicationId) && !Helper.IsValidLoading(load.Loading))
            {
                return("");
            }

            var keyword         = GsaRecord.GetKeyword <GsaLoadNode>();
            var nodeKeyword     = GsaRecord.GetKeyword <GsaNode>();
            var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>();

            var nodeIndices       = Initialiser.AppResources.Cache.LookupIndices(nodeKeyword, load.NodeRefs).Where(x => x.HasValue).Select(x => x.Value).OrderBy(i => i).ToList();
            var loadCaseIndex     = Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, load.LoadCaseRef);
            var streamId          = Initialiser.AppResources.Cache.LookupStream(load.ApplicationId);
            var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadNode>();

            var gwaList     = new List <string>();
            var loadingDict = Helper.ExplodeLoading(load.Loading);

            foreach (var k in loadingDict.Keys)
            {
                var applicationId = string.Join("_", load.ApplicationId, k.ToString());
                var index         = Initialiser.AppResources.Cache.ResolveIndex(keyword, applicationId);
                var gsaLoad       = new GsaLoadNode()
                {
                    Index         = index,
                    ApplicationId = applicationId,
                    StreamId      = streamId,
                    Name          = load.Name,
                    LoadDirection = k,
                    Value         = loadingDict[k],
                    GlobalAxis    = true,
                    NodeIndices   = nodeIndices,
                    LoadCaseIndex = loadCaseIndex
                };
                if (gsaLoad.Gwa(out var gwa, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, index, gwa.First(), streamId, applicationId, gwaSetCommandType);
                }
            }

            return("");
        }
コード例 #16
0
        private Dictionary <Type, List <Type> > TypeDependencies(StreamDirection direction)
        {
            var typeDependencies = new Dictionary <Type, List <Type> >();

            //Build up dictionary of new GSA schema types and keywords - to be used to construct dependencies based on these new types
            var layerSchemaDict     = layerKeywordTypes[Initialiser.AppResources.Settings.TargetLayer];
            var layerSchemaTypes    = layerSchemaDict.Keys;
            var layerSchemaKeywords = layerSchemaDict.Values;
            var layerKwDependencies = layerSchemaTypes.ToDictionary(t => layerSchemaDict[t],
                                                                    t => GsaRecord.GetReferencedKeywords(t).Where(kw => layerSchemaKeywords.Contains(kw)).ToList());

            foreach (var oldT in oldSchemaTypes)
            {
                var oldTKeyword = ((string)oldT.GetAttribute <GSAObject>("GSAKeyword")).Split('.').First();
                if (!string.IsNullOrEmpty(oldTKeyword) && !layerKwDependencies.Keys.Any(k => k.GetStringValue().Equals(oldTKeyword, StringComparison.InvariantCultureIgnoreCase)))
                {
                    continue;
                }

                if (!typeDependencies.ContainsKey(oldT))
                {
                    typeDependencies.Add(oldT, new List <Type>());
                }

                var attVal           = oldT.GetAttribute <GSAObject>(((direction == StreamDirection.Receive) ? "Write" : "Read") + "Prerequisite");
                var prereqs          = (attVal != null) ? ((Type[])attVal).ToList() : new List <Type>();
                var isAnalylsisLayer = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Analysis);

                foreach (var tPrereq in prereqs)
                {
                    //Remove version for comparison with keyword enum
                    var kwPrereq = ((string)tPrereq.GetAttribute <GSAObject>("GSAKeyword")).Split('.').First();

                    if (layerKwDependencies.Keys.Any(k => k.GetStringValue().Equals(kwPrereq, StringComparison.InvariantCultureIgnoreCase)) ||
                        (tPrereq.Name.Contains("Result") && isAnalylsisLayer))
                    {
                        typeDependencies[oldT].Add(tPrereq);
                    }
                }
            }

            return(typeDependencies);
        }
コード例 #17
0
        public static SpeckleObject ToSpeckle(this GsaLoadBeam dummyObject)
        {
            var newLines = Initialiser.AppResources.Cache.GetGwaToSerialise(dummyObject.Keyword);
            //This will return ALL load beams, which (in the future) may not be UDLs
            //Also in the future, the cache will return Gsa schema objects, not just GWA that needs to be converted into Gsa schema objects
            var allGsaLoadBeams = GwaToGsaLoadBeams(newLines);

            allGsaLoadBeams = allGsaLoadBeams.Where(l => l.Index.ValidNonZero()).ToList();
            var gsaLoadsByType = allGsaLoadBeams.GroupBy(l => l.GetType()).ToDictionary(g => g.Key, g => g.ToList());

            var keyword         = GsaRecord.GetKeyword <GsaLoadBeamUdl>();
            var axisKeyword     = GsaRecord.GetKeyword <GsaAxis>();
            var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>();
            var entityKeyword   = (Initialiser.AppResources.Settings.TargetLayer == SpeckleGSAInterfaces.GSATargetLayer.Design) ? GsaRecord.GetKeyword <GsaMemb>() : GsaRecord.GetKeyword <GsaEl>();

            //Just to UDL for now
            var gsaLoads = gsaLoadsByType[typeof(GsaLoadBeamUdl)].Cast <GsaLoadBeamUdl>().ToList();

            var structural1DLoads = new List <Structural1DLoad>();


            //The 1D loads are split into two groups:
            //1. Those which are grouped by Application ID - n:1 ratio (where n <= 6) between GSA objects and Speckle objects
            //2. Those which are sent out individually - 1:1 ratio between GSA objects and Speckle objects
            //To avoid complication regarding merging with existing objects: if a 1D load was previously received from Speckle (i.e. it has an application ID)
            //and it was manually changed from GLOBAL to referencing an axis, then ignore the application ID when sending out (i.e. lump it with group #2)
            var group1 = gsaLoads.Where(l => !string.IsNullOrEmpty(l.ApplicationId) && l.AxisRefType == LoadBeamAxisRefType.Global);
            var group2 = gsaLoads.Except(group1);

            Add1dLoadsWithAppId(entityKeyword, loadCaseKeyword, group1, ref structural1DLoads);
            Add1dLoadsWithoutAppId(keyword, axisKeyword, entityKeyword, loadCaseKeyword, group2, ref structural1DLoads);

            var loads = structural1DLoads.Select(sl => new GSA1DLoad()
            {
                Value = sl
            }).Cast <GSA1DLoad>().ToList();

            if (loads.Count() > 0)
            {
                Initialiser.GsaKit.GSASenderObjects.AddRange(loads);
            }
            return((loads.Count() > 0) ? new SpeckleObject() : new SpeckleNull());
        }
コード例 #18
0
        public static GsaAxis ToNativeSchema(this StructuralAxis axis)
        {
            var keyword = GsaRecord.GetKeyword <GsaAxis>();
            var index   = Initialiser.AppResources.Cache.ResolveIndex(keyword);
            var origin  = (Valid(axis.Origin)) ? axis.Origin : new SpecklePoint(0, 0, 0);
            var gsaAxis = new GsaAxis()
            {
                Index   = index,
                Name    = axis.Name,
                OriginX = origin.Value[0],
                OriginY = origin.Value[1],
                OriginZ = origin.Value[2],
                XDirX   = axis.Xdir.Value[0],
                XDirY   = axis.Xdir.Value[1],
                XDirZ   = axis.Xdir.Value[2],
                XYDirX  = axis.Ydir.Value[0],
                XYDirY  = axis.Ydir.Value[1],
                XYDirZ  = axis.Ydir.Value[2]
            };

            return(gsaAxis);
        }
コード例 #19
0
    public static SpeckleObject ToSpeckle(this GSA1DElementResult dummyObject)
    {
      var result1dTypes = new[] { ResultType.Element1dDisplacement, ResultType.Element1dForce };
      var resultTypes = Initialiser.AppResources.Settings.ResultTypes.Intersect(result1dTypes).ToList();

      if (resultTypes.Count == 0
        || (Initialiser.AppResources.Settings.StreamSendConfig == StreamContentConfig.ModelWithEmbeddedResults 
          && Initialiser.GsaKit.GSASenderObjects.Count<GSA1DElement>() == 0))
      {
        return new SpeckleNull();
      }

      var kw = GsaRecord.GetKeyword<GsaEl>();
      var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>();
      var comboKw = GsaRecord.GetKeyword<GsaCombination>();

      var axisStr = Initialiser.AppResources.Settings.ResultInLocalAxis ? "local" : "global";
      var num1dPos = Initialiser.AppResources.Settings.Result1DNumPosition;
      var typeName = dummyObject.GetType().Name;

      var numAdditionalPoints = Initialiser.AppResources.Settings.Result1DNumPosition;

      var cases = Initialiser.AppResources.Settings.ResultCases;

      if (Initialiser.AppResources.Settings.StreamSendConfig == StreamContentConfig.ModelWithEmbeddedResults)
      {
        Embed1DResults(typeName, axisStr, num1dPos, kw, loadTaskKw, comboKw, resultTypes, cases, numAdditionalPoints);
      }
      else
      {
        if (!Create1DElementResultObjects(typeName, axisStr, num1dPos, loadTaskKw, comboKw, resultTypes, cases, numAdditionalPoints))
        {
          return new SpeckleNull();
        }
      }

      return new SpeckleObject();
    }
コード例 #20
0
        private void GenerateLayerKeywords(IEnumerable <Type> relevantSchemaTypes)
        {
            //This dictionary should be independent of layer
            var keywordDependencies = relevantSchemaTypes.ToDictionary(t => GsaRecord.GetGwaKeyword(t), t => GsaRecord.GetReferencedKeywords(t));

            var implementedKwsByLayer = relevantSchemaTypes.ToDictionary(t => GsaRecord.GetGwaKeyword(t), t => TypeLayers(t));

            foreach (var kw in keywordDependencies.Keys)
            {
                foreach (var layer in new[] { GSATargetLayer.Design, GSATargetLayer.Analysis })
                {
                    if (implementedKwsByLayer[kw][layer])
                    {
                        if (!layerKeywords[layer].Contains(kw))
                        {
                            layerKeywords[layer].Add(kw);
                        }
                    }
                    if (keywordDependencies[kw] != null && keywordDependencies[kw].Length > 0)
                    {
                        foreach (var kwPrereq in keywordDependencies[kw])
                        {
                            //The attributes on the types are the container for knowing which layer a keyword is for.  For each referenced
                            //(i.e. prerequiste) keyword of a keyword, a corresponding type will need to be found in order to determine which
                            //layer that referenced keyword is on.
                            //However, at any point in time, there might not be a type created yet for that referenced keyword.  For these cases,
                            //assume that the referenced keyword is for both layers.

                            if (((implementedKwsByLayer.ContainsKey(kwPrereq) && implementedKwsByLayer[kwPrereq][layer]) || !implementedKwsByLayer.ContainsKey(kwPrereq)) &&
                                (!layerKeywords[layer].Contains(kwPrereq)))
                            {
                                layerKeywords[layer].Add(kwPrereq);
                            }
                        }
                    }
                }
            }
        }
コード例 #21
0
        public static string ToNative(this StructuralLoadPlane loadPlane)
        {
            if (string.IsNullOrEmpty(loadPlane.ApplicationId))
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(loadPlane, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaGridSurface>();
                var storeyKeyword = GsaRecord.GetKeyword <GsaGridPlane>();
                var streamId = Initialiser.AppResources.Cache.LookupStream(loadPlane.ApplicationId);

                var index = Initialiser.AppResources.Cache.ResolveIndex(keyword, loadPlane.ApplicationId);
                var gsaGridSurface = new GsaGridSurface()
                {
                    ApplicationId = loadPlane.ApplicationId,
                    StreamId = streamId,
                    Index = index,
                    Name = loadPlane.Name,
                    Tolerance = loadPlane.Tolerance,
                    Angle = loadPlane.SpanAngle,

                    Type = (loadPlane.ElementDimension.HasValue && loadPlane.ElementDimension.Value == 1)
            ? GridSurfaceElementsType.OneD
            : (loadPlane.ElementDimension.HasValue && loadPlane.ElementDimension.Value == 2)
              ? GridSurfaceElementsType.TwoD
              : GridSurfaceElementsType.NotSet,

                    Span = (loadPlane.Span.HasValue && loadPlane.Span.Value == 1)
            ? GridSurfaceSpan.One
            : (loadPlane.Span.HasValue && loadPlane.Span.Value == 2)
              ? GridSurfaceSpan.Two
              : GridSurfaceSpan.NotSet,

                    //There is no support for entity references in the structural schema, so leave entities blank, which is equal to "all"

                    //There is no support for this argument in the Structural schema, and was even omitted from the GWA
                    //in the previous version of the ToNative code
                    Expansion = GridExpansion.PlaneCorner
                };

                if (!string.IsNullOrEmpty(loadPlane.StoreyRef))
                {
                    var gridPlaneIndex = Initialiser.AppResources.Cache.LookupIndex(storeyKeyword, loadPlane.StoreyRef);

                    if (gridPlaneIndex.ValidNonZero())
                    {
                        gsaGridSurface.PlaneRefType = GridPlaneAxisRefType.Reference;
                        gsaGridSurface.PlaneIndex = gridPlaneIndex;
                    }
                }
                else if (loadPlane.Axis.ValidNonZero())
                {
                    gsaGridSurface.PlaneRefType = GridPlaneAxisRefType.Reference;

                    //Create axis
                    //Create new axis on the fly here
                    var gsaAxis = StructuralAxisToNative.ToNativeSchema(loadPlane.Axis);
                    StructuralAxisToNative.ToNative(gsaAxis);

                    //Create plane - the key here is that it's not a storey, but a general, type of grid plane,
                    //which is why the ToNative() method for SpeckleStorey shouldn't be used as it only creates storey-type GSA grid plane
                    var gsaPlaneKeyword = GsaRecord.GetKeyword <GsaGridPlane>();
                    var planeIndex = Initialiser.AppResources.Cache.ResolveIndex(gsaPlaneKeyword);

                    var gsaPlane = new GsaGridPlane()
                    {
                        Index = planeIndex,
                        Name = loadPlane.Name,
                        Type = GridPlaneType.General,
                        AxisRefType = GridPlaneAxisRefType.Reference,
                        AxisIndex = gsaAxis.Index
                    };
                    if (gsaPlane.Gwa(out var gsaPlaneGwas, true))
                    {
                        Initialiser.AppResources.Cache.Upsert(gsaPlaneKeyword, planeIndex, gsaPlaneGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridPlane>());
                    }
                    gsaGridSurface.PlaneIndex = planeIndex;
                }
コード例 #22
0
        public static string ToNative(this StructuralAssembly assembly)
        {
            if (string.IsNullOrEmpty(assembly.ApplicationId) || assembly.Value == null || assembly.Value.Count < 6)
            {
                return("");
            }

            //Need to convert rounding expressed as an epsilon (e.g. 0.001) to a number of decimal places for use in Math.Round calls
            var epsilon      = SpeckleStructuralClasses.Helper.PointComparisonEpsilon.ToString();
            var numDecPlaces = epsilon.IndexOf('1') - epsilon.IndexOf('.');

            var keyword  = GsaRecord.GetKeyword <GsaAssembly>();
            var index    = Initialiser.AppResources.Cache.ResolveIndex(keyword, assembly.ApplicationId);
            var streamId = Initialiser.AppResources.Cache.LookupStream(assembly.ApplicationId);

            var topo1Pt  = CoordsToPoint(assembly.Value.Take(3));
            var topo2Pt  = CoordsToPoint(assembly.Value.Skip(3).Take(3));
            var orientPt = (assembly.OrientationPoint.Value == null) ? new Point3D(0, 0, 0) : CoordsToPoint(assembly.OrientationPoint.Value);

            var topo1Index    = Initialiser.AppResources.Proxy.NodeAt(topo1Pt.X, topo1Pt.Y, topo1Pt.Z, Initialiser.AppResources.Settings.CoincidentNodeAllowance);
            var topo2Index    = Initialiser.AppResources.Proxy.NodeAt(topo2Pt.X, topo2Pt.Y, topo2Pt.Z, Initialiser.AppResources.Settings.CoincidentNodeAllowance);
            var orientPtIndex = Initialiser.AppResources.Proxy.NodeAt(orientPt.X, orientPt.Y, orientPt.Z, Initialiser.AppResources.Settings.CoincidentNodeAllowance);

            var entityKeyword = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Design) ? GsaRecord.GetKeyword <GsaMemb>() : GsaRecord.GetKeyword <GsaEl>();
            var entityIndices = Initialiser.AppResources.Cache.LookupIndices(entityKeyword, assembly.ElementRefs).Where(i => i.HasValue).Select(i => i.Value).ToList();

            var gsaAssembly = new GsaAssembly()
            {
                Index         = index,
                ApplicationId = assembly.ApplicationId,
                StreamId      = streamId,
                Name          = assembly.Name,
                Topo1         = topo1Index,
                Topo2         = topo2Index,
                OrientNode    = orientPtIndex,
                CurveType     = CurveType.Lagrange,
                SizeY         = assembly.Width ?? 0,
                SizeZ         = 0,
                Type          = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Design) ? GSAEntity.MEMBER : GSAEntity.ELEMENT,
                Entities      = entityIndices
            };

            if (assembly.NumPoints.HasValue && assembly.NumPoints.Value > 0)
            {
                gsaAssembly.PointDefn      = PointDefinition.Points;
                gsaAssembly.NumberOfPoints = assembly.NumPoints.Value;
            }
            else if (assembly.PointDistances != null && assembly.PointDistances.Count() > 0)
            {
                gsaAssembly.PointDefn = PointDefinition.Explicit;
                var distances = assembly.PointDistances.Select(pd => Math.Round(pd, numDecPlaces)).Distinct().OrderBy(n => n).ToList();
                gsaAssembly.ExplicitPositions.AddRange(distances);
            }
            else if (assembly.StoreyRefs != null && assembly.StoreyRefs.Count() > 0)
            {
                gsaAssembly.PointDefn     = PointDefinition.Storey;
                gsaAssembly.StoreyIndices = Initialiser.AppResources.Cache.LookupIndices(GsaRecord.GetKeyword <GsaGridPlane>(), assembly.StoreyRefs).Where(i => i.HasValue).Select(i => i.Value).ToList();
                //Not verifying at the moment that the grid planes are indeed storeys
            }
            else
            {
                gsaAssembly.PointDefn      = PointDefinition.Points;
                gsaAssembly.NumberOfPoints = 10;
            }

            if (gsaAssembly.Gwa(out var gwaLines, false))
            {
                //axes currently never have a stream nor an application ID
                Initialiser.AppResources.Cache.Upsert(keyword, gsaAssembly.Index.Value, gwaLines.First(), streamId, assembly.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaAssembly>());
            }

            return("");
        }
コード例 #23
0
        public static SpeckleObject ToSpeckle(this GsaSection dummyObject)
        {
            var settings         = Initialiser.AppResources.Settings;
            var element1dResults = settings.ResultTypes != null && settings.ResultTypes.Any(rt => rt.ToString().ToLower().Contains("1d"));

            if (settings.TargetLayer == GSATargetLayer.Analysis && settings.StreamSendConfig == StreamContentConfig.TabularResultsOnly && !element1dResults)
            {
                return(new SpeckleNull());
            }

            var kw       = GsaRecord.GetKeyword <GsaSection>();
            var newLines = Initialiser.AppResources.Cache.GetGwaToSerialise(kw);

            int numAdded = 0;

            var structural1DPropertyExplicits = new List <Structural1DPropertyExplicit>();

            var concreteMaterials = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialConcrete>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialConcrete)o.SpeckleObject).ApplicationId);
            var steelMaterials    = Initialiser.GsaKit.GSASenderObjects.Get <GSAMaterialSteel>().ToDictionary(o => o.GSAId, o => ((StructuralMaterialSteel)o.SpeckleObject).ApplicationId);

            //Currently only handles explicit 1D properties
            //Filtering out all but explicit properties:
            //1.  First exclude any GWA lines with the exact string "EXP" - make first pass at filtering them out
            //2.  Call FromGwa for all and perform logic check of values of GsaSection (and subclass) instances
            var indicesContainingEXP = newLines.Keys.Where(k => newLines[k].Contains("EXP")).ToList();
            var gsaSectionsExp       = new List <GsaSection>();

            foreach (var i in indicesContainingEXP)
            {
                var obj = Helper.ToSpeckleTryCatch(dummyObject.Keyword, i, () =>
                {
                    var gsaSection = new GsaSection();
                    if (gsaSection.FromGwa(newLines[i]) && FindExpDetails(gsaSection, out var comp, out var pde))
                    {
                        if (string.IsNullOrEmpty(gsaSection.ApplicationId))
                        {
                            gsaSection.ApplicationId = SpeckleStructuralGSA.Helper.FormatApplicationId(kw, i);
                        }
                        var structuralProp = new Structural1DPropertyExplicit()
                        {
                            Name          = gsaSection.Name,
                            ApplicationId = gsaSection.ApplicationId,
                            Area          = pde.Area,
                            Iyy           = pde.Iyy,
                            Izz           = pde.Izz,
                            J             = pde.J,
                            Ky            = pde.Ky,
                            Kz            = pde.Kz
                        };

                        //No support for any other material type at this stage
                        if (comp.MaterialType == Section1dMaterialType.CONCRETE || comp.MaterialType == Section1dMaterialType.STEEL)
                        {
                            var materialIndex          = comp.MaterialIndex ?? 0;
                            var materialDict           = (comp.MaterialType == Section1dMaterialType.CONCRETE) ? concreteMaterials : steelMaterials;
                            structuralProp.MaterialRef = (materialIndex > 0 && materialDict.ContainsKey(materialIndex)) ? materialDict[materialIndex] : null;
                        }
                        return(structuralProp);
                    }
                    return(new SpeckleNull());
                });
コード例 #24
0
        public static string ToNative(this StructuralNode node)
        {
            if (string.IsNullOrEmpty(node.ApplicationId) || node.Value == null || node.Value.Count < 3)
            {
                return("");
            }

            return(Helper.ToNativeTryCatch(node, () =>
            {
                var keyword = GsaRecord.GetKeyword <GsaNode>();
                var massKeyword = GsaRecord.GetKeyword <GsaPropMass>();

                var index = Initialiser.AppResources.Proxy.NodeAt(node.Value[0], node.Value[1], node.Value[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance);
                var streamId = Initialiser.AppResources.Cache.LookupStream(node.ApplicationId);

                var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index);
                GsaNode gsaNode;
                if (existingGwa == null || existingGwa.Count() == 0 || string.IsNullOrEmpty(existingGwa.First()))
                {
                    gsaNode = new GsaNode()
                    {
                        Index = index,
                        ApplicationId = node.ApplicationId,
                        Name = node.Name,
                        StreamId = streamId,
                        X = node.Value[0],
                        Y = node.Value[1],
                        Z = node.Value[2],
                    };
                }
                else
                {
                    gsaNode = new GsaNode();
                    if (!gsaNode.FromGwa(existingGwa.First()))
                    {
                        //TO DO: add error mesage
                        return "";
                    }
                }

                if (node.Mass.HasValue && node.Mass.Value > 0)
                {
                    int?massIndex = null;
                    GsaPropMass gsaPropMass = null;

                    //Assume the PROP_MASS has the same Application ID as this node
                    //Check if the existing mass with the App ID still has the mass required by this StructuralNode
                    massIndex = Initialiser.AppResources.Cache.LookupIndex(massKeyword, node.ApplicationId);
                    if (massIndex.HasValue)
                    {
                        var massGwa = Initialiser.AppResources.Cache.GetGwa(massKeyword, massIndex.Value);
                        if (massGwa != null && massGwa.Count() > 0 && !string.IsNullOrEmpty(massGwa.First()))
                        {
                            gsaPropMass = new GsaPropMass();
                            gsaPropMass.FromGwa(massGwa.First());

                            if (Math.Abs(gsaPropMass.Mass - node.Mass.Value) > massEpsilon)
                            {
                                gsaPropMass.Mass = node.Mass.Value;
                            }
                        }
                    }

                    if (gsaPropMass == null)
                    {
                        gsaPropMass = new GsaPropMass()
                        {
                            ApplicationId = gsaNode.ApplicationId,
                            StreamId = streamId,
                            Index = Initialiser.AppResources.Cache.ResolveIndex(massKeyword, gsaNode.ApplicationId),
                            Mass = node.Mass.Value
                        };
                        if (!string.IsNullOrEmpty(node.Name))
                        {
                            gsaPropMass.Name = "Mass for " + node.Name;
                        }
                    }
                    if (gsaPropMass.Gwa(out var massGwaLines, false))
                    {
                        Initialiser.AppResources.Cache.Upsert(massKeyword, gsaPropMass.Index.Value, massGwaLines.First(), streamId, gsaPropMass.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaPropMass>());
                    }
                }
コード例 #25
0
 private bool MatchesLayer(Type t, GSATargetLayer layer)
 {
     return((layer == GSATargetLayer.Design && GsaRecord.IsDesignLayer(t)) ||
            (layer == GSATargetLayer.Analysis && GsaRecord.IsAnalysisLayer(t)));
 }
コード例 #26
0
        public void ParseGWACommand(List <GSA2DElement> elements)
        {
            if (elements.Count() < 1)
            {
                return;
            }

            var obj = new Structural2DElementMesh
            {
                ApplicationId = Helper.GetApplicationId(GsaRecord.GetKeyword <GsaMemb>(), GSAId),

                Vertices             = new List <double>(),
                Faces                = new List <int>(),
                ElementApplicationId = new List <string>(),

                ElementType = elements.First().Value.ElementType,
                PropertyRef = elements.First().Value.PropertyRef,
                Axis        = new List <StructuralAxis>(),
                Offset      = new List <double>()
            };

            var axes          = obj.Axis ?? new List <StructuralAxis>();
            var offsets       = obj.Offset ?? new List <double>();
            var elementAppIds = obj.ElementApplicationId ?? new List <string>();

            foreach (var e in elements)
            {
                var verticesOffset = obj.Vertices.Count() / 3;
                obj.Vertices.AddRange(e.Value.Vertices);
                obj.Faces.Add(e.Value.Faces.First());
                obj.Faces.AddRange(e.Value.Faces.Skip(1).Select(x => x + verticesOffset));

                axes.Add(e.Value.Axis);
                offsets.Add(e.Value.Offset ?? 0);
                elementAppIds.Add(e.Value.ApplicationId);

                // Result merging
                if (e.Value.Result != null)
                {
                    try
                    {
                        foreach (var loadCase in e.Value.Result.Keys)
                        {
                            if (obj.Result == null)
                            {
                                //Can't assign an empty dictionary to obj.Result (due to schema's implementation)
                                obj.Result = new Dictionary <string, object>
                                {
                                    { loadCase, new Structural2DElementResult()
                                      {
                                          Value    = new Dictionary <string, object>(),
                                          IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis,
                                      } }
                                };
                            }
                            else if (!obj.Result.ContainsKey(loadCase))
                            {
                                obj.Result[loadCase] = new Structural2DElementResult()
                                {
                                    Value    = new Dictionary <string, object>(),
                                    IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis,
                                };
                            }

                            if (e.Value.Result[loadCase] is Structural2DElementResult resultExport)
                            {
                                foreach (var key in resultExport.Value.Keys)
                                {
                                    if (!(obj.Result[loadCase] as Structural2DElementResult).Value.ContainsKey(key))
                                    {
                                        (obj.Result[loadCase] as Structural2DElementResult).Value[key] = new Dictionary <string, object>(resultExport.Value[key] as Dictionary <string, object>);
                                    }
                                    else
                                    {
                                        foreach (var resultKey in ((obj.Result[loadCase] as Structural2DElementResult).Value[key] as Dictionary <string, object>).Keys)
                                        {
                                            (((obj.Result[loadCase] as Structural2DElementResult).Value[key] as Dictionary <string, object>)[resultKey] as List <object>)
                                            .AddRange((resultExport.Value[key] as Dictionary <string, object>)[resultKey] as List <object>);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // UNABLE TO MERGE RESULTS
                                obj.Result = null;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // UNABLE TO MERGE RESULTS
                        obj.Result = null;
                    }
                }
            }

            obj.Axis   = axes;
            obj.Offset = offsets;
            obj.ElementApplicationId = elementAppIds;

            this.Value = obj;
        }
コード例 #27
0
    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();
    }
コード例 #28
0
        public static string ToNative(this Structural2DLoadPanel loadPanel)
        {
            if (string.IsNullOrEmpty(loadPanel.ApplicationId))
            {
                return("");
            }
            if (loadPanel.Loading == null || loadPanel.Loading.Value == null || loadPanel.Loading.Value.All(v => v == 0))
            {
                Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Structural2DLoadPanel with no loading", loadPanel.ApplicationId);
                return("");
            }

            var keyword           = GsaRecord.GetKeyword <GsaLoadGridArea>();
            var gwaSetCommandType = GsaRecord.GetGwaSetCommandType <GsaLoadGridArea>();
            var streamId          = Initialiser.AppResources.Cache.LookupStream(loadPanel.ApplicationId);

            var loadCaseKeyword = GsaRecord.GetKeyword <GsaLoadCase>();
            var loadCaseIndex   = Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, loadPanel.LoadCaseRef);

            var loadingDict      = ExplodeLoading(loadPanel.Loading);
            var originalPolyline = loadPanel.Value.ToArray();

            //There are two possible axes at play here:
            //1.  one associated with the grid surface (referred by LoadPlaneRef) applied to the coordinates of the polyline
            //2.  one associated with the loading - i.e. applied to the load
            //Note: only the first is supported here

            //When retrieving the axis (to use in transforming the polyline etc), there are two routes here:
            //1.  referencing a load plane (grid surface)
            //2.  not referencing a load plane, in which case a grid surface and axis needs to be created

            var gridSurfaceKeyword = GsaRecord.GetKeyword <GsaGridSurface>();
            var gridPlaneKeyword   = GsaRecord.GetKeyword <GsaGridPlane>();
            var axisKeyword        = GsaRecord.GetKeyword <GsaAxis>();

            StructuralAxis axis             = null;
            int            gridSurfaceIndex = 0;

            if (string.IsNullOrEmpty(loadPanel.LoadPlaneRef))
            {
                //If there is no load plane (corresponding to GRID_SURFACE in GSA terms) specified, then at minimum a GRID_SURFACE still needs
                //to be created but it doesn't need to refer to a GRID_PLANE because that load plane can just have "GLOBAL" set for its plane.

                //HOWEVER, the approach taken here - which could be reviewed - is to create one anyway, whose X and y axes are based on the polyline
                //so that an elevation value can be set in the GRID_PLANE

                //Create axis based on the polyline
                try
                {
                    axis      = SpeckleStructuralGSA.Helper.Parse2DAxis(originalPolyline);
                    axis.Name = loadPanel.Name;
                    var gsaAxis = StructuralAxisToNative.ToNativeSchema(axis);
                    gsaAxis.StreamId = streamId;
                    StructuralAxisToNative.ToNative(gsaAxis);

                    var gridPlaneIndex = Initialiser.AppResources.Cache.ResolveIndex(gridPlaneKeyword);
                    var gsaGridPlane   = new GsaGridPlane()
                    {
                        Index       = gridPlaneIndex,
                        Name        = loadPanel.Name,
                        StreamId    = streamId,
                        AxisRefType = GridPlaneAxisRefType.Reference,
                        AxisIndex   = gsaAxis.Index,
                        Elevation   = AxisElevation(axis, originalPolyline),
                        Type        = GridPlaneType.General,
                        StoreyToleranceAboveAuto = true,
                        StoreyToleranceBelowAuto = true
                    };
                    if (gsaGridPlane.Gwa(out var gsaGridPlaneGwas, false))
                    {
                        Initialiser.AppResources.Cache.Upsert(gridPlaneKeyword, gridPlaneIndex, gsaGridPlaneGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridPlane>());
                    }

                    gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword);
                    var gsaGridSurface = new GsaGridSurface()
                    {
                        Index        = gridSurfaceIndex,
                        PlaneRefType = GridPlaneAxisRefType.Reference,
                        StreamId     = streamId,
                        PlaneIndex   = gridPlaneIndex,
                        Name         = loadPanel.Name,
                        AllIndices   = true,
                        Type         = GridSurfaceElementsType.TwoD,
                        Span         = GridSurfaceSpan.One,
                        Angle        = 0,
                        Tolerance    = 0.01,
                        Expansion    = GridExpansion.PlaneCorner
                    };
                    if (gsaGridSurface.Gwa(out var gsaGridSurfaceGwas, false))
                    {
                        Initialiser.AppResources.Cache.Upsert(gridSurfaceKeyword, gridSurfaceIndex, gsaGridSurfaceGwas.First(), streamId, "", GsaRecord.GetGwaSetCommandType <GsaGridSurface>());
                    }
                }
                catch
                {
                    Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Generating axis from coordinates for 2D load panel", loadPanel.ApplicationId);
                }
            }
            else
            {
                //Get axis from load plane using LoadPlaneRef
                //Within this option, there are two routes to retrieve the axis:
                //1.  the StructuralLoadPlane has its own axis (because AxisRefs aren't offered yet in the Structural classes)
                //2.  the StructuralLoadPlane references a StructuralStorey, which has an axis

                gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword, loadPanel.LoadPlaneRef);
                var gsaGridSurfaceGwa = Initialiser.AppResources.Cache.GetGwa(gridSurfaceKeyword, gridSurfaceIndex).First();

                var gsaGridSurface = new GsaGridSurface();
                if (gsaGridSurface.FromGwa(gsaGridSurfaceGwa))
                {
                    if (gsaGridSurface.PlaneRefType == GridPlaneAxisRefType.Reference && gsaGridSurface.PlaneIndex.ValidNonZero())
                    {
                        var gsaGridPlaneGwa = Initialiser.AppResources.Cache.GetGwa(gridPlaneKeyword, gsaGridSurface.PlaneIndex.Value).First();

                        var gsaGridPlane = new GsaGridPlane();
                        if (gsaGridPlane.FromGwa(gsaGridPlaneGwa))
                        {
                            if (gsaGridPlane.AxisRefType == GridPlaneAxisRefType.Reference && gsaGridPlane.AxisIndex.ValidNonZero())
                            {
                                var axisIndex = gsaGridPlane.AxisIndex.Value;

                                var gsaAxisGwa = Initialiser.AppResources.Cache.GetGwa(axisKeyword, axisIndex).First();
                                var gsaAxis    = new GsaAxis();
                                if (gsaAxis.FromGwa(gsaAxisGwa))
                                {
                                    axis = (StructuralAxis)gsaAxis.ToSpeckle();
                                }
                                else
                                {
                                    Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse AXIS GWA", loadPanel.ApplicationId);
                                }
                            }
                            else
                            {
                                Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Invalid AXIS reference", loadPanel.ApplicationId);
                            }
                        }
                        else
                        {
                            Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse GRID_PLANE GWA", loadPanel.ApplicationId);
                        }
                    }
                    else
                    {
                        Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Invalid GRID_PLANE reference", loadPanel.ApplicationId);
                    }
                }
                else
                {
                    Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Unable to parse GRID_SURFACE GWA", loadPanel.ApplicationId);
                }
            }

            // Transform polygon coordinates to the relevant axis
            // keep in mind that the 2D load panel inherits from SpecklePolyline
            var polyline = SpeckleStructuralGSA.Helper.MapPointsGlobal2Local(originalPolyline, axis);

            foreach (var k in loadingDict.Keys)
            {
                var applicationId = string.Join("_", loadPanel.ApplicationId, k.ToString());
                var index         = Initialiser.AppResources.Cache.ResolveIndex(keyword, applicationId);

                var gsaLoadPanel = new GsaLoadGridArea()
                {
                    Index            = index,
                    ApplicationId    = applicationId,
                    StreamId         = streamId,
                    Name             = loadPanel.Name,
                    Value            = loadingDict[k],
                    GridSurfaceIndex = gridSurfaceIndex,
                    LoadDirection    = k,
                    LoadCaseIndex    = loadCaseIndex,
                    //No support yet for an axis separate to the grid surface's, on which the loading is applied
                    AxisRefType = AxisRefType.Global,
                    //No support yet for whole-plane 2D load panels - all assumed to be based on polyline/polygon
                    Area      = LoadAreaOption.Polygon,
                    Polygon   = PolylineCoordsToGwaPolygon(polyline),
                    Projected = false
                };
                if (gsaLoadPanel.Gwa(out var gsaLoadPanelGwas, false))
                {
                    Initialiser.AppResources.Cache.Upsert(keyword, index, gsaLoadPanelGwas.First(), streamId, applicationId, GsaRecord.GetGwaSetCommandType <GsaLoadGridArea>());
                }
            }

            return("");
        }
コード例 #29
0
        public string SetGWACommand()
        {
            if (this.Value == null)
            {
                return("");
            }
            var load = this.Value as Structural1DLoadLine;

            if (load.ApplicationId == null)
            {
                return("");
            }

            var keyword = typeof(GSAGridLineLoad).GetGSAKeyword();

            //There are no GSA types for these yet, so use empty strings for the type names

            var loadCaseKeyword = typeof(GSALoadCase).GetGSAKeyword();

            var indexResult = Initialiser.AppResources.Cache.LookupIndex(loadCaseKeyword, load.LoadCaseRef);
            var loadCaseRef = indexResult ?? Initialiser.AppResources.Cache.ResolveIndex(loadCaseKeyword, load.LoadCaseRef);

            if (indexResult == null && load.ApplicationId != null)
            {
                if (load.LoadCaseRef == null)
                {
                    Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Blank load case references found for these Application IDs:",
                                                               load.ApplicationId);
                }
                else
                {
                    Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Load case references not found:",
                                                               load.ApplicationId + " referencing " + load.LoadCaseRef);
                }
            }

            StructuralAxis axis        = null;
            var            ls          = new List <string>();
            var            gwaCommands = new List <string>();
            int            gridSurfaceIndex;

            double elevation = 0;

            if (string.IsNullOrEmpty(load.LoadPlaneRef))
            {
                axis = (load.Value == null)
          ? new StructuralAxis(new StructuralVectorThree(1, 0, 0), new StructuralVectorThree(0, 1, 0))
          : Helper.Parse1DAxis(load.Value.ToArray());

                Helper.SetAxis(axis, out int planeAxisIndex, out string planeAxisGwa, load.Name);
                if (planeAxisGwa.Length > 0)
                {
                    gwaCommands.Add(planeAxisGwa);
                }

                if (load.Value != null)
                {
                    // Calculate elevation
                    elevation = (load.Value[0] * axis.Normal.Value[0] +
                                 load.Value[1] * axis.Normal.Value[1] +
                                 load.Value[2] * axis.Normal.Value[2]) /
                                Math.Sqrt(axis.Normal.Value[0] * axis.Normal.Value[0] +
                                          axis.Normal.Value[1] * axis.Normal.Value[1] +
                                          axis.Normal.Value[2] * axis.Normal.Value[2]);
                }

                gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex("GRID_SURFACE.1");
                var gridPlaneIndex = Initialiser.AppResources.Cache.ResolveIndex("GRID_PLANE.4");

                ls.Clear();
                ls.AddRange(new[] {
                    "SET",
                    "GRID_PLANE.4",
                    gridPlaneIndex.ToString(),
                    load.Name == null || load.Name == "" ? " " : load.Name,
                    "GENERAL", // Type
                    planeAxisIndex.ToString(),
                    elevation.ToString(),
                    "0", // Elevation above
                    "0"
                });      // Elevation below
                gwaCommands.Add(string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls));

                ls.Clear();
                ls.AddRange(new[] { "SET",
                                    "GRID_SURFACE.1",
                                    gridSurfaceIndex.ToString(),
                                    load.Name == null || load.Name == "" ? " " : load.Name,
                                    gridPlaneIndex.ToString(),
                                    "1",          // Dimension of elements to target
                                    "all",        // List of elements to target
                                    "0.01",       // Tolerance
                                    "TWO_SIMPLE", // Span option
                                    "0" });       // Span angle
                gwaCommands.Add(string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls));
            }
            else //LoadPlaneRef is not empty/null
            {
                var gridSurfaceKeyword = GsaRecord.GetKeyword <GsaGridSurface>();
                var lookupIndex        = Initialiser.AppResources.Cache.LookupIndex(gridSurfaceKeyword, load.LoadPlaneRef);
                if (lookupIndex == null)
                {
                    gridSurfaceIndex = Initialiser.AppResources.Cache.ResolveIndex(gridSurfaceKeyword, load.LoadPlaneRef);
                }
                else
                {
                    gridSurfaceIndex = lookupIndex.Value;
                }

                var loadPlanesDict = Initialiser.AppResources.Cache.GetIndicesSpeckleObjects(typeof(StructuralLoadPlane).Name);
                if (loadPlanesDict.ContainsKey(gridSurfaceIndex) && loadPlanesDict[gridSurfaceIndex] != null)
                {
                    var loadPlane = ((StructuralLoadPlane)loadPlanesDict[gridSurfaceIndex]);
                    if (loadPlane.Axis != null)
                    {
                        axis = loadPlane.Axis;
                    }
                    else
                    {
                        try
                        {
                            var storeyIndex = Initialiser.AppResources.Cache.LookupIndex("GRID_PLANE.4", loadPlane.StoreyRef).Value;
                            var storeysDict = Initialiser.AppResources.Cache.GetIndicesSpeckleObjects(typeof(StructuralStorey).Name);
                            if (storeysDict.ContainsKey(storeyIndex) && storeysDict[storeyIndex] != null)
                            {
                                var storey = ((StructuralStorey)storeysDict[storeyIndex]);
                                if (storey.Axis != null)
                                {
                                    axis = storey.Axis;
                                }
                            }
                        }
                        catch { }

                        if (axis == null)
                        {
                            axis = new StructuralAxis(new StructuralVectorThree(1, 0, 0), new StructuralVectorThree(0, 1, 0));
                        }
                    }
                }
            }

            // Transform coordinate to new axis
            var transformed = Helper.MapPointsGlobal2Local(load.Value.ToArray(), axis);

            var direction = new string[3] {
                "X", "Y", "Z"
            };

            for (var i = 0; i < Math.Min(direction.Count(), load.Loading.Value.Count()); i++)
            {
                if (load.Loading.Value[i] == 0)
                {
                    continue;
                }

                var subLs = new List <string>();
                for (var j = 0; j < transformed.Count(); j += 3)
                {
                    subLs.Add("(" + transformed[j].ToString() + "," + transformed[j + 1].ToString() + ")");
                }

                ls.Clear();

                var index = Initialiser.AppResources.Cache.ResolveIndex(typeof(GSAGridLineLoad).GetGSAKeyword());

                var sid = Helper.GenerateSID(load);
                ls.AddRange(new[] {
                    "SET_AT",
                    index.ToString(),
                    keyword + (string.IsNullOrEmpty(sid) ? "" : ":" + sid),
                    load.Name == null || load.Name == "" ? " " : load.Name + (load.Name.All(char.IsDigit) ? " " : ""),
                    gridSurfaceIndex.ToString(),
                    "POLYGON",
                    string.Join(" ", subLs),
                    loadCaseRef.ToString(),
                    "GLOBAL",
                    "NO",
                    direction[i],
                    load.Loading.Value[i].ToString(),
                    load.LoadingEnd == null ? load.Loading.Value[i].ToString() : load.LoadingEnd.Value[i].ToString()
                });

                gwaCommands.Add(string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls));
            }

            return(string.Join("\n", gwaCommands));
        }
コード例 #30
0
    public static SpeckleObject ToSpeckle(this GSAMiscResult dummyObject)
    {
      var keyword = typeof(GSAAssembly).GetGSAKeyword();
      var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>();
      var comboKw = GsaRecord.GetKeyword<GsaCombination>();
      var typeName = dummyObject.GetType().Name;
      var axisStr = Initialiser.AppResources.Settings.ResultInLocalAxis ? "local" : "global";

      //var resultTypes = Initialiser.AppResources.Settings.MiscResults.Keys.Where(r => r.ToLower().Contains("assembly")).ToList();
      var cases = Initialiser.AppResources.Settings.ResultCases;

      //if (resultTypes.Count() == 0 
      if (Initialiser.AppResources.Settings.ResultTypes == null || !Initialiser.AppResources.Settings.ResultTypes.Contains(ResultType.AssemblyForcesAndMoments)
        || !Initialiser.AppResources.Cache.GetKeywordRecordsSummary(keyword, out var gwa, out var indices, out var applicationIds))
      {
        return new SpeckleNull();
      }

      var gsaMiscResults = new List<GSAMiscResult>();
      var gsaMiscResultsLock = new object();

      Initialiser.AppResources.Proxy.LoadResults(ResultGroup.Assembly, out int numErrorRows, cases, indices);
      if (numErrorRows > 0)
      {
        Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of assembly results");
        Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of assembly results");
      }

#if DEBUG
      for (int i = 0; i < indices.Count(); i++)
#else
      Parallel.For(0, indices.Count, i =>
#endif
      {
        var entity = indices[i];
        var applicationId = applicationIds[i];

        try
        {
          if (Initialiser.AppResources.Proxy.GetResultHierarchy(ResultGroup.Assembly, entity, out var results) && results != null)
          {
            var orderedLoadCases = results.Keys.OrderBy(k => k).ToList();
            foreach (var loadCase in orderedLoadCases)
            {
              if (!SchemaConversion.Helper.FilterResults(results[loadCase], out var sendableResults))
              {
                continue;
              }
              var miscResult = new StructuralMiscResult()
              {
                IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis,
                Value = sendableResults,
                TargetRef = applicationId
              };
              var loadCaseRef = SchemaConversion.Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw);
              if (!string.IsNullOrEmpty(loadCaseRef))
              {
                miscResult.LoadCaseRef = loadCase;
              }

              lock (gsaMiscResultsLock)
              {
                gsaMiscResults.Add(new GSAMiscResult { Value = miscResult, GSAId = entity });
              }
            }
          }

        }
        catch (Exception ex)
        {
          var contextDesc = string.Join(" ", typeName, entity);
          Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, ex, contextDesc, i.ToString());
        }
      }
#if !DEBUG
      );
#endif
      Initialiser.AppResources.Proxy.ClearResults(ResultGroup.Assembly);

      if (gsaMiscResults.Count > 0)
      {
        Initialiser.GsaKit.GSASenderObjects.AddRange(gsaMiscResults);
      }

      return new SpeckleObject();
    }