Ejemplo n.º 1
0
    public static string ToNative(this Structural2DElement el)
    {
      var layer = Initialiser.AppResources.Settings.TargetLayer;

      if (el == null || el.Vertices == null || el.ApplicationId == null)
      {
        return "";
      }

      if (layer == GSATargetLayer.Design)
      {
        return new GSA2DMember() { Value = el }.SetGWACommand();
      }
      if (layer == GSATargetLayer.Analysis && (el.NumFaces() == 1))
      {
        return new GSA2DElement() { Value = el }.SetGWACommand();
      }

      //Reaching this point means it should be treated as a full analytical mesh - where each face creates a new 2D element
      el.Consolidate();

      var elMesh = new Structural2DElementMesh(el.Vertices, el.Faces, el.Colors, el.ElementType, el.PropertyRef,
        new[] { el.Axis }, new[] { el.Offset ?? 0 }, el.ApplicationId, el.GSAMeshSize ?? 0, el.Properties);

      return (new GSA2DElementMesh() { Value = elMesh }).SetGWACommand();
    }
Ejemplo n.º 2
0
 public static string ToNative(this Structural2DElementMesh mesh)
 {
     return((Initialiser.Settings.TargetLayer == GSATargetLayer.Analysis)
 ? new GSA2DElementMesh()
     {
         Value = mesh
     }.SetGWACommand()
 : new GSA2DMember()
     {
         Value = mesh
     }.SetGWACommand());
 }
Ejemplo n.º 3
0
 public static string ToNative(this Structural2DElementMesh mesh)
 {
     return(SchemaConversion.Helper.ToNativeTryCatch(mesh, () => (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Analysis)
 ? new GSA2DElementMesh()
     {
         Value = mesh
     }.SetGWACommand()
 : new GSA2DMember()
     {
         Value = mesh
     }.SetGWACommand()));
 }
Ejemplo n.º 4
0
        public static string ToNative(this SpeckleMesh inputObject)
        {
            var convertedObject = new Structural2DElementMesh();

            foreach (var p in convertedObject.GetType().GetProperties().Where(p => p.CanWrite))
            {
                var inputProperty = inputObject.GetType().GetProperty(p.Name);
                if (inputProperty != null)
                {
                    p.SetValue(convertedObject, inputProperty.GetValue(inputObject));
                }
            }

            return(convertedObject.ToNative());
        }
Ejemplo n.º 5
0
        public void TestKristjanSpeckleConstructor()
        {
            var coor = new double[] {
                41079.0479, 88847.4378, 2850,
                45177.0349, 89591.5655, 2850,
                45177.0349, 89591.5655, 5200,
                46485.6358, 89829.1862, 5200,
                46485.6358, 89829.1862, 2850,
                46756.1572, 89878.3084, 2850,
                46756.1572, 89878.3084, 7450,
                41079.0479, 88847.4378, 7450,
            };
            var dummyMesh = new Structural2DElementMesh(coor, null, Structural2DElementType.Wall, null, null, null);

            Assert.IsNotNull(dummyMesh.Faces);
            var faces = dummyMesh.Faces;

            Assert.True(faces.ContainsSublist(new[] { 0, 0, 1, 2 }));
            Assert.True(faces.ContainsSublist(new[] { 0, 2, 3, 6 }));
            Assert.True(faces.ContainsSublist(new[] { 0, 3, 4, 5 }));
            Assert.True(faces.ContainsSublist(new[] { 0, 3, 5, 6 }));
            Assert.True(faces.ContainsSublist(new[] { 0, 0, 6, 7 }));
            Assert.True(faces.ContainsSublist(new[] { 0, 0, 2, 6 }));
        }
Ejemplo n.º 6
0
        public void ParseGWACommand(List <GSA2DElement> elements)
        {
            if (elements.Count() < 1)
            {
                return;
            }

            var obj = new Structural2DElementMesh
            {
                ApplicationId = Helper.GetApplicationId(typeof(GSA2DElementMesh).GetGSAKeyword(), 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>()
            };

            if (Initialiser.Settings.Element2DResults.Count > 0 && Initialiser.Settings.EmbedResults)
            {
                obj.Result = new Dictionary <string, object>();
            }

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

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


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

                // Result merging
                if (obj.Result != null && ((Structural2DElement)e.Value).Result != null)
                {
                    try
                    {
                        foreach (string loadCase in e.Value.Result.Keys)
                        {
                            if (!obj.Result.ContainsKey(loadCase))
                            {
                                obj.Result[loadCase] = new Structural2DElementResult()
                                {
                                    Value    = new Dictionary <string, object>(),
                                    IsGlobal = !Initialiser.Settings.ResultInLocalAxis,
                                }
                            }
                            ;

                            var resultExport = e.Value.Result[loadCase] as Structural2DElementResult;

                            if (resultExport != null)
                            {
                                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 <double>)
                                            .AddRange((resultExport.Value[key] as Dictionary <string, object>)[resultKey] as List <double>);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // UNABLE TO MERGE RESULTS
                                obj.Result = null;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        // UNABLE TO MERGE RESULTS
                        obj.Result = null;
                    }
                }

                this.SubGWACommand.Add(e.GWACommand);
                this.SubGWACommand.AddRange(e.SubGWACommand);
            }

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

            this.Value = obj;
        }
Ejemplo n.º 7
0
        public static List <SpeckleObject> ToSpeckle(this AnalyticalModelSurface mySurface)
        {
            var returnObjects = new List <SpeckleObject>();

            if (!mySurface.IsEnabled())
            {
                return(new List <SpeckleObject>());
            }

            // Get the family
            var myRevitElement = Doc.GetElement(mySurface.GetElementId());

            var type = Structural2DElementType.Generic;

            if (myRevitElement is Floor)
            {
                type = Structural2DElementType.Slab;
            }
            else if (myRevitElement is Wall)
            {
                type = Structural2DElementType.Wall;
            }

            // Voids first

            var voidLoops = mySurface.GetLoops(AnalyticalLoopType.Void);

            foreach (var loop in voidLoops)
            {
                var coor = new List <double>();
                foreach (var curve in loop)
                {
                    var points = curve.Tessellate();

                    foreach (var p in points.Skip(1))
                    {
                        coor.Add(p.X / Scale);
                        coor.Add(p.Y / Scale);
                        coor.Add(p.Z / Scale);
                    }
                }

                returnObjects.Add(new Structural2DVoid(coor.ToArray(), null));
            }

            var polylines = new List <double[]>();

            var loops = mySurface.GetLoops(AnalyticalLoopType.External);

            foreach (var loop in loops)
            {
                var coor = new List <double>();
                foreach (var curve in loop)
                {
                    var points = curve.Tessellate();

                    foreach (var p in points.Skip(1))
                    {
                        coor.Add(p.X / Scale);
                        coor.Add(p.Y / Scale);
                        coor.Add(p.Z / Scale);
                    }
                }

                polylines.Add(coor.ToArray());
            }

            var coordinateSystem = mySurface.GetLocalCoordinateSystem();
            var axis             = coordinateSystem == null ? null : new StructuralAxis(
                new StructuralVectorThree(new double[] { coordinateSystem.BasisX.X, coordinateSystem.BasisX.Y, coordinateSystem.BasisX.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisY.X, coordinateSystem.BasisY.Y, coordinateSystem.BasisY.Z }),
                new StructuralVectorThree(new double[] { coordinateSystem.BasisZ.X, coordinateSystem.BasisZ.Y, coordinateSystem.BasisZ.Z })
                );

            // Property
            string sectionID = null;

            try
            {
                var mySection = new Structural2DProperty();

                mySection.Name          = Doc.GetElement(myRevitElement.GetTypeId()).Name;
                mySection.ApplicationId = Doc.GetElement(myRevitElement.GetTypeId()).UniqueId;

                if (myRevitElement is Floor)
                {
                    var myFloor = myRevitElement as Floor;
                    mySection.Thickness = myFloor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).AsDouble() / Scale;
                }
                else if (myRevitElement is Wall)
                {
                    var myWall = myRevitElement as Wall;
                    mySection.Thickness = myWall.WallType.Width / Scale;
                }

                try
                {
                    // Material
                    Material        myMat    = null;
                    StructuralAsset matAsset = null;

                    if (myRevitElement is Floor)
                    {
                        var myFloor = myRevitElement as Floor;
                        myMat = Doc.GetElement(myFloor.FloorType.StructuralMaterialId) as Material;
                    }
                    else if (myRevitElement is Wall)
                    {
                        var myWall = myRevitElement as Wall;
                        myMat = Doc.GetElement(myWall.WallType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId()) as Material;
                    }

                    SpeckleObject myMaterial = null;

                    matAsset = ((PropertySetElement)Doc.GetElement(myMat.StructuralAssetId)).GetStructuralAsset();

                    var matType = myMat.MaterialClass;

                    switch (matType)
                    {
                    case "Concrete":
                        var concMat = new StructuralMaterialConcrete();
                        concMat.ApplicationId         = myMat.UniqueId;
                        concMat.Name                  = Doc.GetElement(myMat.StructuralAssetId).Name;
                        concMat.YoungsModulus         = matAsset.YoungModulus.X;
                        concMat.ShearModulus          = matAsset.ShearModulus.X;
                        concMat.PoissonsRatio         = matAsset.PoissonRatio.X;
                        concMat.Density               = matAsset.Density;
                        concMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X;
                        concMat.CompressiveStrength   = matAsset.ConcreteCompression;
                        concMat.MaxStrain             = 0;
                        concMat.AggragateSize         = 0;
                        myMaterial = concMat;
                        break;

                    case "Steel":
                        var steelMat = new StructuralMaterialSteel();
                        steelMat.ApplicationId         = myMat.UniqueId;
                        steelMat.Name                  = Doc.GetElement(myMat.StructuralAssetId).Name;
                        steelMat.YoungsModulus         = matAsset.YoungModulus.X;
                        steelMat.ShearModulus          = matAsset.ShearModulus.X;
                        steelMat.PoissonsRatio         = matAsset.PoissonRatio.X;
                        steelMat.Density               = matAsset.Density;
                        steelMat.CoeffThermalExpansion = matAsset.ThermalExpansionCoefficient.X;
                        steelMat.YieldStrength         = matAsset.MinimumYieldStress;
                        steelMat.UltimateStrength      = matAsset.MinimumTensileStrength;
                        steelMat.MaxStrain             = 0;
                        myMaterial = steelMat;
                        break;

                    default:
                        var defMat = new StructuralMaterialSteel();
                        defMat.ApplicationId = myMat.UniqueId;
                        defMat.Name          = Doc.GetElement(myMat.StructuralAssetId).Name;
                        myMaterial           = defMat;
                        break;
                    }

                    myMaterial.GenerateHash();
                    mySection.MaterialRef = (myMaterial as SpeckleObject).ApplicationId;

                    returnObjects.Add(myMaterial);
                }
                catch { }

                mySection.GenerateHash();

                sectionID = mySection.ApplicationId;

                returnObjects.Add(mySection);
            }
            catch { }

            var counter = 0;

            foreach (var coor in polylines)
            {
                var dummyMesh = new Structural2DElementMesh(coor, null, type, null, null, null);

                var numFaces = 0;
                for (var i = 0; i < dummyMesh.Faces.Count(); i++)
                {
                    numFaces++;
                    i += dummyMesh.Faces[i] + 3;
                }

                var mesh = new Structural2DElementMesh();
                mesh.Vertices    = dummyMesh.Vertices;
                mesh.Faces       = dummyMesh.Faces;
                mesh.Colors      = dummyMesh.Colors;
                mesh.ElementType = type;
                if (sectionID != null)
                {
                    mesh.PropertyRef = sectionID;
                }
                if (axis != null)
                {
                    mesh.Axis = Enumerable.Repeat(axis, numFaces).ToList();
                }
                mesh.Offset = Enumerable.Repeat(0.0, numFaces).Cast <double>().ToList(); //TODO

                mesh.GenerateHash();
                mesh.ApplicationId = mySurface.UniqueId + "_" + (counter++).ToString();

                returnObjects.Add(mesh);
            }

            return(returnObjects);
        }
Ejemplo n.º 8
0
 //TODO
 public static Element ToNative(this Structural2DElementMesh myMesh)
 {
     return(null);
 }
    public string SetGWACommand(int group = 0)
    {
      if (this.Value == null)
        return "";

      var obj = (SpeckleObject)this.Value;
      var baseMesh = (SpeckleMesh)this.Value;

      if (baseMesh.Vertices == null || baseMesh.Vertices.Count() == 0)
        return "";

      var colour = (baseMesh.Colors == null || baseMesh.Colors.Count < 1) ? "NO_RGB" : baseMesh.Colors[0].ArgbToHexColor().ToString();

      StructuralAxis axis;
      Structural2DElementMesh mesh;
      bool? gsaDummy;
      string propRef;
      double? offset;
      string sid;
      Structural2DElementType structural2dElementType;
      double? gsaMeshSize;

      //This is to avoid relying on the fact that this.Value is dynamic - casting to one of the expected types first
      if (this.Value is Structural2DElement)
      {
        var el = (Structural2DElement)this.Value;
        structural2dElementType = el.ElementType;
        sid = Helper.GenerateSID(el);
        propRef = el.PropertyRef;
        mesh = new Structural2DElementMesh() { baseMesh = ((Structural2DElement) this.Value).baseMesh };
        gsaMeshSize = el.GSAMeshSize;
        gsaDummy = el.GSADummy;
        axis = el.Axis;
        offset = el.Offset;
      }
      else if (this.Value is Structural2DElementMesh)
      {
        var el = (Structural2DElementMesh)this.Value;
        structural2dElementType = el.ElementType;
        propRef = el.PropertyRef;
        sid = Helper.GenerateSID(el);
        mesh = ((Structural2DElementMesh) this.Value);
        gsaMeshSize = el.GSAMeshSize;
        gsaDummy = el.GSADummy;
        axis = (el.Axis == null || el.Axis.Count == 0) ? null : el.Axis.First();
        offset = (el.Offset == null || el.Offset.Count == 0) ? null : (double ?) el.Offset.First();
      }
      else
      {
        return "";
      }

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

      var index = Initialiser.AppResources.Cache.ResolveIndex(typeof(GSA2DMember).GetGSAKeyword(), obj.ApplicationId);

      var propKeyword = typeof(GSA2DProperty).GetGSAKeyword();
      var indexResult = Initialiser.AppResources.Cache.LookupIndex(propKeyword, propRef);
      //If the reference can't be found, then reserve a new index so that it at least doesn't point to any other existing record
      var propIndex = indexResult ?? Initialiser.AppResources.Cache.ResolveIndex(propKeyword, propRef);
      if (indexResult == null && obj.ApplicationId != null)
      {
        if (propRef == null)
        {
          Helper.SafeDisplay("Blank property references found for these Application IDs:", obj.ApplicationId);
        }
        else
        {
          Helper.SafeDisplay("2D property references not found:", obj.ApplicationId + " referencing " + propRef);
        }
      }

      var gwaCommands = new List<string>();

      var ls = new List<string>
      {
        "SET",
        keyword + ":" + sid,
        index.ToString(),
        string.IsNullOrEmpty(obj.Name) ? " " : obj.Name,
        colour
      };
      ls.Add(ElementTypeToString(structural2dElementType));
      ls.Add("ALL");
      ls.Add(propIndex.ToString());
      ls.Add(group != 0 ? group.ToString() : index.ToString()); // TODO: This allows for targeting of elements from members group
      
      mesh.Consolidate();
      var connectivities = mesh.Edges();

      if (connectivities == null || connectivities.Count() == 0)
      {
        //This is likely if the vertices are duplicated or other strange states
        return "";
      }

      var coor = new List<double>();
      foreach (var c in connectivities[0])
      {
        coor.AddRange(baseMesh.Vertices.Skip(c * 3).Take(3));
      }
      coor = coor.Essential().ToList();
      var coorPts = Enumerable.Range(0, coor.Count() / 3).Select(i => new double[] { coor[i * 3], coor[i * 3 + 1], coor[i * 3 + 2] }).ToList();

      //Use these reduced coordinates to call NodeAt and create a topo string
      // topo
      var topo = "";
      var prevNodeIndex = -1;
      foreach (var coorPt in coorPts)
      {
        var currIndex = Initialiser.AppResources.Proxy.NodeAt(coorPt[0], coorPt[1], coorPt[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance);
        if (prevNodeIndex != currIndex)
        {
          topo += currIndex.ToString() + " ";
        }
        prevNodeIndex = currIndex;
      }

      ls.Add(topo.Trim());
      
      ls.Add("0"); // Orientation node
      
      // angle
      if (axis == null)
      {
        ls.Add("0");
      }
      else
      {
        try
        {
          ls.Add(Helper.Get2DAngle(coor.ToArray(), axis).ToString());
        }
        catch { ls.Add("0"); }
      }
      ls.Add(gsaMeshSize == 0 ? "1" : gsaMeshSize.ToString()); // Target mesh size
      ls.Add("YES"); // intersector
      ls.Add("LINEAR"); // Element type
      ls.Add("0"); // Fire resistance (mins)
      ls.Add("0"); // Fire limiting temp
      ls.Add("0"); // Time 1
      ls.Add("0"); // Time 2
      ls.Add("0"); // Time 3
      ls.Add("0"); // Time 4
      ls.Add((gsaDummy.HasValue && gsaDummy.Value) ? "DUMMY" : "ACTIVE");
      ls.Add(offset.HasValue ? offset.ToString() : "0"); // Offset z
      ls.Add("NO"); // Internal auto offset
      //These are default values - filled in here to avoid instances of GWA comparisons (when upserting into the cache) showing change where there isn't
      ls.Add("REBAR_2D.1");
      ls.Add("0.03");
      ls.Add("0.03");
      ls.Add("0");
      gwaCommands.Add(string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls));

      return string.Join("\n", gwaCommands);
    }
    public int Group; // Keep for load targetting

    public void ParseGWACommand(List<GSANode> nodes, List<GSA2DProperty> props)
    {
      // MEMB.8 | num | name | colour | type (2D) | exposure | prop | group | topology | node | angle | mesh_size | is_intersector | analysis_type | fire | time[4] | dummy | off_auto_internal | off_z | reinforcement2d |

      if (this.GWACommand == null)
        return;

      var obj = new Structural2DElementMesh();

      var pieces = this.GWACommand.ListSplit(Initialiser.AppResources.Proxy.GwaDelimiter);

      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[] { '"' }); // name
      var color = pieces[counter++].ParseGSAColor(); // colour

      var type = pieces[counter++];
      obj.ElementType = (type == "SLAB") ? Structural2DElementType.Slab : (type == "WALL") ? Structural2DElementType.Wall : Structural2DElementType.Generic;

      counter++; // exposure - fire property

      var propertyGSAId = Convert.ToInt32(pieces[counter++]);

      obj.PropertyRef = Helper.GetApplicationId(typeof(GSA2DProperty).GetGSAKeyword(), propertyGSAId);
      this.Group = Convert.ToInt32(pieces[counter++]); // Keep group for load targetting

      // topology
      var coordinates = new List<double>();
      var nodeRefsFull = pieces[counter++];

      //Remove the specification of internal nodes
      var nodeRefsWithoutInternalNodes = Regex.Replace(nodeRefsFull, @"P\([0-9]*(.*?)\)", "");
      nodeRefsWithoutInternalNodes = Regex.Replace(nodeRefsWithoutInternalNodes, @"L\([0-9]*(.*?)\)", "");
      nodeRefsWithoutInternalNodes = Regex.Replace(nodeRefsWithoutInternalNodes, @"V\([0-9]*(.*?)\)", "");

      var nodeRefs = nodeRefsWithoutInternalNodes.Trim().ListSplit(" ");
      for (var i = 0; i < nodeRefs.Length; i++)
      {
        var node = nodes.Where(n => n.GSAId.ToString() == nodeRefs[i]).FirstOrDefault();
        if (node == null)
        {
          //TO DO: review how this is possible and prevent it
          continue;
        }

        coordinates.AddRange(node.Value.Value);
        this.SubGWACommand.Add(node.GWACommand);
      }

      var temp = new Structural2DElementMesh(
          coordinates.Essential(),
          color.HexToArgbColor(),
          obj.ElementType, obj.PropertyRef,
          null,
          null);


      obj.Vertices = temp.Vertices;
      obj.Faces = temp.Faces;
      obj.Colors = temp.Colors;

      var numFaces = 0;
      for (var i = 0; i < obj.Faces.Count(); i++)
      {
        numFaces++;
        i += obj.Faces[i] + 3;
      }

      counter++; // Orientation node

      var prop = props.Where(p => p.Value.ApplicationId == obj.PropertyRef).FirstOrDefault();
      StructuralAxis axis = null;
      try
      {
        axis = Helper.Parse2DAxis(coordinates.ToArray(),
            Convert.ToDouble(pieces[counter++]),
            prop == null ? false : (prop as GSA2DProperty).IsAxisLocal);
      }
      catch
      {
        Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, "Generating axis from coordinates for 2D member", obj.ApplicationId);
      }

      if (axis != null)
      {
        obj.Axis = Enumerable.Repeat(axis, numFaces).ToList();
        if (prop != null)
        {
          this.SubGWACommand.Add(prop.GWACommand);
        }
      }

      //Since this is a GSA-specific property, only set if not default
      var meshSize = Convert.ToDouble(pieces[counter++]);
      if (meshSize > 0)
      {
        obj.GSAMeshSize = meshSize; // mesh_size
      }

      counter++; // intersector
      counter++; // analysis type

      counter = counter+=6; // skip fire bits to get to dummy status
      //Since this is a GSA-specific property, only set if true;
      var dummy = (pieces[counter++] == "DUMMY");
      if (dummy)
      {
        obj.GSADummy = dummy;
      }

      Initialiser.AppResources.Proxy.GetGSATotal2DElementOffset(propertyGSAId, Convert.ToDouble(pieces[counter++]), out var offset, out var offsetRec);
      this.SubGWACommand.Add(offsetRec);

      obj.Offset = Enumerable.Repeat(offset, numFaces).ToList();

      // skip remaining commands

      if (!obj.Properties.ContainsKey("structural"))
      {
        obj.Properties.Add("structural", new Dictionary<string, object>());
      }
      ((Dictionary<string, object>)obj.Properties["structural"]).Add("NativeId", this.GSAId.ToString());

      this.Value = obj;
    }
Ejemplo n.º 11
0
        public string SetGWACommand(int group = 0)
        {
            if (this.Value == null)
            {
                return("");
            }

            var obj      = (SpeckleObject)this.Value;
            var baseMesh = (SpeckleMesh)this.Value;

            if (baseMesh.Vertices == null || baseMesh.Vertices.Count() == 0)
            {
                return("");
            }

            var colour = (baseMesh.Colors == null || baseMesh.Colors.Count < 1) ? "NO_RGB" : baseMesh.Colors[0].ArgbToHexColor().ToString();

            StructuralAxis          axis;
            Structural2DElementMesh mesh;
            bool?  gsaDummy;
            string propRef;
            double?offset;
            string sid;
            Structural2DElementType structural2dElementType;
            double?gsaMeshSize;

            //This is to avoid relying on the fact that this.Value is dynamic - casting to one of the expected types first
            if (this.Value is Structural2DElement)
            {
                var el = (Structural2DElement)this.Value;
                structural2dElementType = el.ElementType;
                sid     = Helper.GenerateSID(el);
                propRef = el.PropertyRef;
                mesh    = new Structural2DElementMesh()
                {
                    baseMesh = this.Value.baseMesh
                };
                gsaMeshSize = el.GSAMeshSize;
                gsaDummy    = el.GSADummy;
                axis        = el.Axis;
                offset      = el.Offset;
            }
            else if (this.Value is Structural2DElementMesh)
            {
                var el = (Structural2DElementMesh)this.Value;
                structural2dElementType = el.ElementType;
                propRef     = el.PropertyRef;
                sid         = Helper.GenerateSID(el);
                mesh        = this.Value;
                gsaMeshSize = el.GSAMeshSize;
                gsaDummy    = el.GSADummy;
                axis        = (el.Axis == null || el.Axis.Count == 0) ? null : el.Axis.First();
                offset      = (el.Offset == null || el.Offset.Count == 0) ? null : (double?)el.Offset.First();
            }
            else
            {
                return("");
            }

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

            var index = Initialiser.Cache.ResolveIndex(typeof(GSA2DMember).GetGSAKeyword(), obj.ApplicationId);

            var propKeyword = typeof(GSA2DProperty).GetGSAKeyword();
            var indexResult = Initialiser.Cache.LookupIndex(propKeyword, propRef);
            //If the reference can't be found, then reserve a new index so that it at least doesn't point to any other existing record
            var propIndex = indexResult ?? Initialiser.Cache.ResolveIndex(propKeyword, propRef);

            if (indexResult == null && obj.ApplicationId != null)
            {
                if (propRef == null)
                {
                    Helper.SafeDisplay("Blank property references found for these Application IDs:", obj.ApplicationId);
                }
                else
                {
                    Helper.SafeDisplay("Property references not found:", obj.ApplicationId + " referencing " + propRef);
                }
            }

            var gwaCommands = new List <string>();

            var ls = new List <string>
            {
                "SET",
                keyword + ":" + sid,
                index.ToString(),
                string.IsNullOrEmpty(obj.Name) ? " " : obj.Name,
                colour
            };

            ls.Add(ElementTypeToString(structural2dElementType));
            ls.Add(propIndex.ToString());
            ls.Add(group != 0 ? group.ToString() : index.ToString()); // TODO: This allows for targeting of elements from members group
            var topo           = "";
            var prevNodeIndex  = -1;
            var connectivities = mesh.Edges();

            if (connectivities == null || connectivities.Count() == 0)
            {
                //This is likely if the vertices are duplicated or other strange states
                return("");
            }

            var coor = new List <double>();

            foreach (var c in connectivities[0])
            {
                coor.AddRange(baseMesh.Vertices.Skip(c * 3).Take(3));
                var currIndex = Helper.NodeAt(baseMesh.Vertices[c * 3], baseMesh.Vertices[c * 3 + 1], baseMesh.Vertices[c * 3 + 2], Initialiser.Settings.CoincidentNodeAllowance);
                if (prevNodeIndex != currIndex)
                {
                    topo += currIndex.ToString() + " ";
                }
                prevNodeIndex = currIndex;
            }
            ls.Add(topo.Trim());
            ls.Add("0"); // Orientation node
            if (axis == null)
            {
                ls.Add("0");
            }
            else
            {
                try
                {
                    ls.Add(Helper.Get2DAngle(coor.ToArray(), axis).ToString());
                }
                catch { ls.Add("0"); }
            }
            ls.Add(gsaMeshSize == 0 ? "1" : gsaMeshSize.ToString()); // Target mesh size
            ls.Add("MESH");                                          // TODO: What is this?
            ls.Add("LINEAR");                                        // Element type
            ls.Add("0");                                             // Fire
            ls.Add("0");                                             // Time 1
            ls.Add("0");                                             // Time 2
            ls.Add("0");                                             // Time 3
            ls.Add("0");                                             // TODO: What is this?
            ls.Add((gsaDummy.HasValue && gsaDummy.Value) ? "DUMMY" : "ACTIVE");
            ls.Add("NO");                                            // Internal auto offset
            ls.Add(offset.HasValue ? offset.ToString() : "0");       // Offset z
            ls.Add("ALL");                                           // Exposure

            gwaCommands.Add(string.Join("\t", ls));

            return(string.Join("\n", gwaCommands));
        }
Ejemplo n.º 12
0
        public void ParseGWACommand(List <GSANode> nodes, List <GSA2DProperty> props)
        {
            if (this.GWACommand == null)
            {
                return;
            }

            var obj = new Structural2DElementMesh();

            var pieces = this.GWACommand.ListSplit("\t");

            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[] { '"' });
            var color = pieces[counter++].ParseGSAColor();

            var type = pieces[counter++];

            if (type == "SLAB")
            {
                obj.ElementType = Structural2DElementType.Slab;
            }
            else if (type == "WALL")
            {
                obj.ElementType = Structural2DElementType.Wall;
            }
            else
            {
                obj.ElementType = Structural2DElementType.Generic;
            }

            var propertyGSAId = Convert.ToInt32(pieces[counter++]);

            obj.PropertyRef = Helper.GetApplicationId(typeof(GSA2DProperty).GetGSAKeyword(), propertyGSAId);
            this.Group      = Convert.ToInt32(pieces[counter++]); // Keep group for load targetting

            var coordinates  = new List <double>();
            var nodeRefsFull = pieces[counter++];

            //Remove the specification of internal nodes
            var nodeRefsWithoutInternalNodes = Regex.Replace(nodeRefsFull, @"P\([0-9]*(.*?)\)", "");

            var nodeRefs = nodeRefsWithoutInternalNodes.Trim().ListSplit(" ");

            for (var i = 0; i < nodeRefs.Length; i++)
            {
                var node = nodes.Where(n => n.GSAId.ToString() == nodeRefs[i]).FirstOrDefault();
                if (node == null)
                {
                    //TO DO: review how this is possible and prevent it
                    continue;
                }

                coordinates.AddRange(node.Value.Value);
                this.SubGWACommand.Add(node.GWACommand);
            }

            var temp = new Structural2DElementMesh(
                coordinates.Essential(),
                color.HexToArgbColor(),
                obj.ElementType, obj.PropertyRef,
                null,
                null);

            obj.Vertices = temp.Vertices;
            obj.Faces    = temp.Faces;
            obj.Colors   = temp.Colors;

            var numFaces = 0;

            for (var i = 0; i < obj.Faces.Count(); i++)
            {
                numFaces++;
                i += obj.Faces[i] + 3;
            }

            counter++; // Orientation node

            var prop = props.Where(p => p.Value.ApplicationId == obj.PropertyRef).FirstOrDefault();
            var axis = Helper.Parse2DAxis(coordinates.ToArray(),
                                          Convert.ToDouble(pieces[counter++]),
                                          prop == null ? false : (prop as GSA2DProperty).IsAxisLocal);

            obj.Axis = Enumerable.Repeat(axis, numFaces).ToList();
            if (prop != null)
            {
                this.SubGWACommand.Add(prop.GWACommand);
            }

            // Skip to offsets at second to last
            counter = pieces.Length - 2;

            Initialiser.Interface.GetGSATotal2DElementOffset(propertyGSAId, Convert.ToDouble(pieces[counter++]), out var offset, out var offsetRec);
            this.SubGWACommand.Add(offsetRec);

            obj.Offset = Enumerable.Repeat(offset, numFaces).ToList();

            this.Value = obj;
        }