public static SpeckleObject ToSpeckle(this GSA2DElement dummyObject)
    {
      var typeName = dummyObject.GetType().Name;
      var newElementLines = ToSpeckleBase<GSA2DElement>();
      var newMeshLines = ToSpeckleBase<GSA2DElementMesh>();
      var newLinesTuples = new List<Tuple<int, string>>();
      foreach (var k in newElementLines.Keys)
      {
        newLinesTuples.Add(new Tuple<int, string>(k, newElementLines[k]));
      }
      foreach (var k in newMeshLines.Keys)
      {
        newLinesTuples.Add(new Tuple<int, string>(k, newMeshLines[k]));
      }

      var elementsLock = new object();
      var elements = new List<GSA2DElement>();
      var nodes = Initialiser.GsaKit.GSASenderObjects.Get<GSANode>();
      var props = Initialiser.GsaKit.GSASenderObjects.Get<GSA2DProperty>();

      var newLines = newLinesTuples.Select(nl => nl.Item2);
      Parallel.ForEach(newLines, p =>
      {
        var pPieces = p.ListSplit(Initialiser.AppResources.Proxy.GwaDelimiter);
        // Check if void or not an element
        if (!(pPieces[4] == "2D_VOID_CUTTER" || pPieces[4].Is1DMember() || pPieces[4].Is2DMember())
          && (pPieces[4].ParseElementNumNodes() == 3 | pPieces[4].ParseElementNumNodes() == 4))
        {
          var gsaId = pPieces[1];
          try
          {
            var element = new GSA2DElement() { GWACommand = p };
            element.ParseGWACommand(nodes, props);
            lock (elementsLock)
            {
              elements.Add(element);
            }
          }
          catch (Exception ex)
          {
            Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, typeName, gsaId);
            Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, typeName, gsaId);
          }
        }
      });

      Initialiser.GsaKit.GSASenderObjects.AddRange(elements);

      return (elements.Count() == 0) ? new SpeckleNull() :  new SpeckleObject();
    }
Пример #2
0
        public static SpeckleObject ToSpeckle(this GSA2DElement dummyObject)
        {
            var newElementLines = ToSpeckleBase <GSA2DElement>();
            var newMeshLines    = ToSpeckleBase <GSA2DElementMesh>();
            var newLinesTuples  = new List <Tuple <int, string> >();

            foreach (var k in newElementLines.Keys)
            {
                newLinesTuples.Add(new Tuple <int, string>(k, newElementLines[k]));
            }
            foreach (var k in newMeshLines.Keys)
            {
                newLinesTuples.Add(new Tuple <int, string>(k, newMeshLines[k]));
            }

            var elementsLock = new object();
            var elements     = new List <GSA2DElement>();
            var nodes        = Initialiser.GSASenderObjects.Get <GSANode>();
            var props        = Initialiser.GSASenderObjects.Get <GSA2DProperty>();

            var newLines = newLinesTuples.Select(nl => nl.Item2);

            Parallel.ForEach(newLines, p =>
            {
                var pPieces = p.ListSplit("\t");
                // Check if void or not an element
                if (!(pPieces[4] == "2D_VOID_CUTTER" || pPieces[4].Is1DMember() || pPieces[4].Is2DMember()) &&
                    (pPieces[4].ParseElementNumNodes() == 3 | pPieces[4].ParseElementNumNodes() == 4))
                {
                    try
                    {
                        var element = new GSA2DElement()
                        {
                            GWACommand = p
                        };
                        element.ParseGWACommand(nodes, props);
                        lock (elementsLock)
                        {
                            elements.Add(element);
                        }
                    }
                    catch { }
                }
            });

            Initialiser.GSASenderObjects.AddRange(elements);

            return((elements.Count() == 0) ? new SpeckleNull() :  new SpeckleObject());
        }
Пример #3
0
    public static SpeckleObject ToSpeckle(this GSA2DElement dummyObject)
    {
      var settings = Initialiser.AppResources.Settings;
      var anyElement2dResults = settings.ResultTypes != null && settings.ResultTypes.Any(rt => rt.ToString().ToLower().Contains("2d"));
      if (settings.TargetLayer == GSATargetLayer.Analysis && settings.StreamSendConfig == StreamContentConfig.TabularResultsOnly && !anyElement2dResults)
      {
        return new SpeckleNull();
      }

      var typeName = dummyObject.GetType().Name;
      var newElementLines = ToSpeckleBase<GSA2DElement>();
      var newLinesTuples = new List<Tuple<int, string>>();
      var keyword = dummyObject.GetGSAKeyword();

      foreach (var k in newElementLines.Keys)
      {
        newLinesTuples.Add(new Tuple<int, string>(k, newElementLines[k]));
      }

      var elementsLock = new object();
      var elements = new List<GSA2DElement>();
      var nodes = Initialiser.GsaKit.GSASenderObjects.Get<GSANode>();
      var props = Initialiser.GsaKit.GSASenderObjects.Get<GSA2DProperty>();
      var gsaProps = GetGsaPropDict();
      var newLines = newLinesTuples.Select(nl => nl.Item2);
#if DEBUG
      foreach (var p in newLines)
#else
      Parallel.ForEach(newLines, p =>
#endif
      {
        var pPieces = p.ListSplit(Initialiser.AppResources.Proxy.GwaDelimiter);
        var gsaId = pPieces[1];
        var typeStr = pPieces[4];

        if (Enum.TryParse(typeStr, true, out ElementNumNodes elementType) && Is2DElement(elementType))
        {
          var numNodes = (int)elementType;
          // There is no such thing as a void element
          if ((numNodes == 3 || numNodes == 4))
          {
            try
            {
              var element = new GSA2DElement() { GWACommand = p };
              element.ParseGWACommand(nodes, props, gsaProps);
              lock (elementsLock)
              {
                elements.Add(element);
              }
            }
            catch (Exception ex)
            {
              Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, ex,
                "Keyword=" + keyword, "Index=" + gsaId);
            }
          }
          else
          {
            Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Information, "Unsupported 2D element type: " + typeStr, gsaId);
            Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Information, "No support for type of 2D element",
                "Keyword=" + keyword, "Index=" + gsaId, "NumNodes=" + numNodes, "Type=" + typeStr);
          }
        }
      }
#if !DEBUG
      );
#endif

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

      return (elements.Count() == 0) ? new SpeckleNull() :  new SpeckleObject();
    }