コード例 #1
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());
        }
コード例 #2
0
        private static List <GsaLoadBeam> GwaToGsaLoadBeams(Dictionary <int, string> newLines)
        {
            var instanceInfo = new Dictionary <GwaKeyword, Type>()
            {
                { GwaKeyword.LOAD_BEAM_UDL, typeof(GsaLoadBeamUdl) },
                { GwaKeyword.LOAD_BEAM_LINE, typeof(GsaLoadBeamLine) },
                { GwaKeyword.LOAD_BEAM_POINT, typeof(GsaLoadBeamPoint) },
                { GwaKeyword.LOAD_BEAM_PATCH, typeof(GsaLoadBeamPatch) },
                { GwaKeyword.LOAD_BEAM_TRILIN, typeof(GsaLoadBeamPatchTrilin) }
            };

            var schemaObjs = new List <GsaLoadBeam>();

            foreach (var index in newLines.Keys)
            {
                GsaLoadBeam obj = null;
                foreach (var kw in instanceInfo.Keys)
                {
                    if (newLines[index].Contains(kw.ToString()))
                    {
                        obj = (GsaLoadBeam)Activator.CreateInstance(instanceInfo[kw]);
                        break;
                    }
                }
                if (obj != null)
                {
                    obj.Index = index;

                    if (obj.FromGwa(newLines[index]))
                    {
                        schemaObjs.Add(obj);
                    }
                }
            }
            return(schemaObjs);
        }