예제 #1
0
        public void TestProbeResult()
        {
            var outputs = ProbeResult.ReadProbeResults(Path.Combine(folder, "internalCloud"));

            Assert.IsTrue(outputs.ContainsKey("p"));
            Assert.IsTrue(outputs.ContainsKey("U"));
        }
예제 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string folder     = null;
            string meshPath   = null;
            var    refresh    = false;
            var    _overrides = "";

            DA.GetData(0, ref folder);
            DA.GetData(1, ref meshPath);
            DA.GetData(2, ref _overrides);
            DA.GetData(3, ref refresh);

            var overrides = new ProbeResultOverrides().FromJson(_overrides) ?? new ProbeResultOverrides {
                Exclude = null, Include = null, Distance = 0.1, Outputs = null
            };

            AddOverrideOutputs(overrides);

            if (string.IsNullOrEmpty(folder))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide a valid string to the Folder input.");
            }

            // Get Cache to see if we already did this
            var cacheKey     = folder + meshPath + _overrides;
            var cachedValues = StringCache.getCache(cacheKey);

            DA.DisableGapLogic();

            if (!string.IsNullOrEmpty(folder) && (cachedValues == null || refresh))
            {
                const string queueName = "probeResults";
                StringCache.setCache(InstanceGuid.ToString(), "");

                // Get queue lock
                var queueLock = StringCache.getCache(queueName);
                if (queueLock != "true")
                {
                    StringCache.setCache(queueName, "true");
                    StringCache.setCache(cacheKey + "progress", "Loading...");

                    QueueManager.addToQueue(queueName, () =>
                    {
                        try
                        {
                            var results = ProbeResult.ReadProbeResults(
                                folder,
                                overrides.Exclude,
                                overrides.Include
                                );
                            cachedValues = JsonConvert.SerializeObject(results);
                            StringCache.setCache(cacheKey, cachedValues);

                            var points = ProbeResult.ReadPointsFromResults(
                                folder,
                                overrides.Exclude,
                                overrides.Include
                                );
                            probePoints = ConvertPointsToDataTree(points);

                            if (!string.IsNullOrEmpty(meshPath))
                            {
                                loadedMeshes = Import.LoadMeshFromPath(meshPath, overrides.Exclude, overrides.Include);
                            }


                            if (loadedMeshes != null && loadedMeshes.Any())
                            {
                                if (points != null && points.Any())
                                {
                                    try
                                    {
                                        correctedMesh = CorrectMesh(loadedMeshes, points, overrides.Distance ?? 0.1);
                                    }
                                    catch (InvalidOperationException error)
                                    {
                                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning,
                                                          $"Could not construct new mesh. Got error: {error.Message}");
                                    }
                                }
                                else
                                {
                                    correctedMesh = CorrectMesh(loadedMeshes);
                                }
                            }

                            probeResults = new Dictionary <string, DataTree <object> >();
                            foreach (var key in results.Keys)
                            {
                                probeResults.Add(key, ConvertToDataTree(results[key]));
                            }

                            info       = UpdateInfo(results);
                            resultKeys = results.Keys.ToList();
                            StringCache.setCache(cacheKey + "progress", "Done");
                        }
                        catch (Exception e)
                        {
                            StringCache.setCache(InstanceGuid.ToString(), e.Message);
                            StringCache.setCache(cacheKey, "error");
                            StringCache.setCache(cacheKey + "progress", "");
                        }

                        ExpireSolutionThreadSafe(true);
                        Thread.Sleep(2000);
                        StringCache.setCache(queueName, "");
                    });
                    ExpireSolutionThreadSafe(true);
                }
            }


            HandleErrors();

            if (probePoints != null)
            {
                DA.SetDataTree(1, probePoints);
            }

            if (correctedMesh != null)
            {
                DA.SetDataTree(2, correctedMesh);
            }

            if (info != null)
            {
                DA.SetDataTree(0, info);
            }

            if (probeResults != null)
            {
                foreach (var key in probeResults.Keys)
                {
                    AddToOutput(DA, key, probeResults[key], overrides.Outputs);
                }
            }

            if (resultKeys != null && overrides.Outputs == null)
            {
                resultKeys.Add("Info");
                resultKeys.Add("Points");
                resultKeys.Add("Mesh");
                RemoveUnusedOutputs(resultKeys);
            }

            Message = StringCache.getCache(cacheKey + "progress");
        }