public static string ToNative(this StructuralSpringProperty prop) { return(new GSASpringProperty() { Value = prop }.SetGWACommand()); }
public void MergeTestGSA_WithMerger() { var ls1 = new object[] { "PROP_SPR.4:{speckle_app_id:gh/a}", 1, "LSPxGeneral", "NO_RGB", "GENERAL", 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0.21 }; var gwa1 = string.Join(GSAProxy.GwaDelimiter.ToString(), ls1.Select(l => l.ToString())); PrepareInterfacerForGwaToSpeckle <GSASpringProperty>(gwa1, "PROP_SPR", "gh/a"); //Call the ToSpeckle method, which just adds to the GSASenderObjects collection- GsaPropSprToSpeckle.ToSpeckle(new GsaPropSpr()); var existing = (StructuralSpringProperty)Initialiser.GsaKit.GSASenderObjects.Get <GSASpringProperty>().First().Value; var newToMerge = new StructuralSpringProperty() { DampingRatio = 1.5 }; var speckleTypes = SpeckleUtil.Helper.GetLoadedSpeckleTypes(); var mappingTypes = new List <Type>(); var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetTypes().Any(t => typeof(ISpeckleInitializer).IsAssignableFrom(t))).ToList(); var relevantAssemblies = assemblies.Where(a => a.FullName.Contains("GSA")); foreach (var assembly in relevantAssemblies) { foreach (var t in speckleTypes) { var methods = SpeckleUtil.Helper.GetExtensionMethods(assembly, t, "ToNative"); if (methods != null && methods.Count() > 0) { mappingTypes.Add(t); } if (t.BaseType != null) { if (!mappingTypes.Contains(t.BaseType)) { mappingTypes.Add(t.BaseType); } } } } var merger = new SpeckleObjectMerger(); merger.Initialise(mappingTypes); var resultingObject = merger.Merge(newToMerge, existing); }
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(); }
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 ""; }
public void MergeTestGSA() { var ls1 = new object[] { "PROP_SPR.4:{speckle_app_id:gh/a}", 1, "LSPxGeneral", "NO_RGB", "GENERAL", 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0.21 }; var gwa1 = string.Join(GSAProxy.GwaDelimiter.ToString(), ls1.Select(l => l.ToString())); PrepareInterfacerForGwaToSpeckle <GSASpringProperty>(gwa1, "PROP_SPR", "gh/a"); //Call the ToSpeckle method, which just adds to the GSASenderObjects collection GsaPropSprToSpeckle.ToSpeckle(new GsaPropSpr()); var existing = (StructuralSpringProperty)Initialiser.GsaKit.GSASenderObjects.Get <GSASpringProperty>().First().Value; var newToMerge = new StructuralSpringProperty() { DampingRatio = 1.5 }; var m = SetupGSAMerger(); var resultingObject = m.Map(newToMerge, existing); }
public void MergeTestGSA() { var ls1 = new object[] { "PROP_SPR.3:{speckle_app_id:gh/a}", 1, "LSPxGeneral", "NO_RGB", "GLOBAL", "GENERAL", 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0.21 }; var gwa1 = string.Join("\t", ls1.Select(l => l.ToString())); PrepareInterfacerForGwaToSpeckle <GSASpringProperty>(gwa1, "PROP_SPR.3", "gh/a"); //Call the ToSpeckle method, which just adds to the GSASenderObjects collection Conversions.ToSpeckle(new GSASpringProperty()); var existing = (StructuralSpringProperty)((IGSASpeckleContainer)Initialiser.GSASenderObjects[typeof(GSASpringProperty)].First()).Value; var newToMerge = new StructuralSpringProperty() { DampingRatio = 1.5 }; var m = SetupGSAMerger(); var resultingObject = m.Map(newToMerge, existing); }
public void ParseGWACommand() { if (this.GWACommand == null) { return; } var pieces = this.GWACommand.ListSplit("\t"); var obj = new StructuralSpringProperty(); var counter = 1; // Skip identifier this.GSAId = Convert.ToInt32(pieces[counter++]); obj.ApplicationId = Helper.GetApplicationId(this.GetGSAKeyword(), this.GSAId); obj.Name = pieces[counter++].Trim(new char[] { '"' }); counter++; //Skip colour var gsaAxis = pieces[counter++]; if (gsaAxis == "GLOBAL") { obj.Axis = Helper.Parse0DAxis(0, Initialiser.Interface, out var gwaRec); } else if (gsaAxis == "VERTICAL") { obj.Axis = Helper.Parse0DAxis(-14, Initialiser.Interface, out var gwaRec); } else { obj.Axis = Helper.Parse0DAxis(Convert.ToInt32(gsaAxis), Initialiser.Interface, out var gwaRec); this.SubGWACommand.Add(gwaRec); } var springPropertyType = pieces[counter++]; var stiffnesses = new double[6]; var dampingRatio = 0d; switch (springPropertyType.ToLower()) { case "axial": obj.SpringType = StructuralSpringPropertyType.Axial; double.TryParse(pieces[counter++], out stiffnesses[0]); break; case "compression": obj.SpringType = StructuralSpringPropertyType.Compression; double.TryParse(pieces[counter++], out stiffnesses[0]); break; case "tension": obj.SpringType = StructuralSpringPropertyType.Tension; double.TryParse(pieces[counter++], out stiffnesses[0]); break; case "gap": obj.SpringType = StructuralSpringPropertyType.Gap; double.TryParse(pieces[counter++], out stiffnesses[0]); break; case "friction": obj.SpringType = StructuralSpringPropertyType.Friction; double.TryParse(pieces[counter++], out stiffnesses[0]); double.TryParse(pieces[counter++], out stiffnesses[1]); double.TryParse(pieces[counter++], out stiffnesses[2]); counter++; //Coefficient of friction, not supported yet break; case "torsional": // TODO: As of build 48 of GSA, the torsional stiffness is not extracted in GWA records //return; obj.SpringType = StructuralSpringPropertyType.Torsional; double.TryParse(pieces[counter++], out stiffnesses[3]); break; case "lockup": obj.SpringType = StructuralSpringPropertyType.Lockup; double.TryParse(pieces[counter++], out stiffnesses[0]); break; case "general": obj.SpringType = StructuralSpringPropertyType.General; counter--; for (var i = 0; i < 6; i++) { double.TryParse(pieces[counter += 2], out stiffnesses[i]); } counter++; double.TryParse(pieces[counter], out dampingRatio); break; default: return; } ; obj.Stiffness = new StructuralVectorSix(stiffnesses); double.TryParse(pieces[counter++], out dampingRatio); //Found some extremely small floating point issues so rounding to (arbitrarily-chosen) 4 digits obj.DampingRatio = Math.Round(dampingRatio, 4); this.Value = obj; }