public string SetGWACommand(int group = 0)
    {
      if (this.Value == null)
      { 
        return "";
      }

      var mesh = this.Value as Structural2DElement;
      if (mesh.ApplicationId == null)
      {
        return "";
      }

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

      var index = Initialiser.AppResources.Cache.ResolveIndex(typeof(GSA2DElement).GetGSAKeyword(), mesh.ApplicationId);

      var propKeyword = typeof(GSA2DProperty).GetGSAKeyword();
      var indexResult = Initialiser.AppResources.Cache.LookupIndex(propKeyword, mesh.PropertyRef);
      //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 propRef = indexResult ?? Initialiser.AppResources.Cache.ResolveIndex(propKeyword, mesh.PropertyRef);
      if (indexResult == null && mesh.ApplicationId != null)
      {
        if (mesh.PropertyRef == null)
        {
          Helper.SafeDisplay("Blank property references found for these Application IDs:", mesh.ApplicationId);
        }
        else
        {
          Helper.SafeDisplay("2D property references not found:", mesh.ApplicationId + " referencing " + mesh.PropertyRef);
        }
      }

      var sid = Helper.GenerateSID(mesh);
      var ls = new List<string>
      {
        "SET",
        keyword + (string.IsNullOrEmpty(sid) ? "" : ":" + sid),
        index.ToString(),
        mesh.Name == null || mesh.Name == "" ? " " : mesh.Name,
        mesh.Colors == null || mesh.Colors.Count() < 1 ? "NO_RGB" : mesh.Colors[0].ArgbToHexColor().ToString(),
        mesh.Vertices.Count() / 3 == 3 ? "TRI3" : "QUAD4",
        propRef.ToString(),
        group.ToString() // Group
      };
      var numVertices = mesh.Faces[0] + 3;
      var coor = new List<double>();
      for (var i = 1; i < mesh.Faces.Count(); i++)
      {
        coor.AddRange(mesh.Vertices.Skip(mesh.Faces[i] * 3).Take(3));
        ls.Add(Initialiser.AppResources.Proxy.NodeAt(mesh.Vertices[mesh.Faces[i] * 3], mesh.Vertices[mesh.Faces[i] * 3 + 1], mesh.Vertices[mesh.Faces[i] * 3 + 2], Initialiser.AppResources.Settings.CoincidentNodeAllowance).ToString());
      }
      ls.Add("0"); //Orientation node
      if (mesh.Axis == null)
      {
        ls.Add("0");
      }
      else
      {
        try
        {
          ls.Add(Helper.Get2DAngle(coor.ToArray(), mesh.Axis).ToString());
        }
        catch { ls.Add("0"); }
      }
      ls.Add("NO_RLS");

      ls.Add("0"); // Offset x-start
      ls.Add("0"); // Offset x-end
      ls.Add("0"); // Offset y
      ls.Add(mesh.Offset.ToString());

      ls.Add(""); // parent_member

      ls.Add((mesh.GSADummy.HasValue && mesh.GSADummy.Value) ? "DUMMY" : "");

      return (string.Join(Initialiser.AppResources.Proxy.GwaDelimiter.ToString(), ls));
    }
    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);
    }
示例#3
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));
        }