示例#1
0
        private static bool SetClosedVolume(List <ICondition> conditions, Dictionary <string, List <Zone> > zonesByName)
        {
            bool success = true;

            for (int i = 0; i < conditions.Count(); i++)
            {
                IsInZone isInZoneCondition = conditions[i] as IsInZone;
                if (isInZoneCondition == null)
                {
                    continue;
                }

                // Select only zones with the same name of the current Condition ("pertainingZones")
                List <Zone> pertainingZones = new List <Zone>();
                if (!zonesByName.TryGetValue(isInZoneCondition.ZoneName, out pertainingZones))
                {
                    BH.Engine.Reflection.Compute.RecordWarning($"A {nameof(IsInZone)} condition specified a {nameof(IsInZone.ZoneName)} `{isInZoneCondition.ZoneName}` that could not be found among any of the Reference Elements' target zones.");
                    success = false;
                    continue;
                }

                // Add the closed volumes of the pertainingZones to the current Condition.
                if (isInZoneCondition.ClosedVolumes == null)
                {
                    isInZoneCondition.ClosedVolumes = new List <oM.Geometry.IGeometry>();
                }

                isInZoneCondition.ClosedVolumes.AddRange(pertainingZones.Select(z => z.ClosedVolume));

                // Update the input list.
                conditions[i] = isInZoneCondition;
            }

            return(success);
        }
示例#2
0
 public static void SetClosedVolume(IsInZone isInZoneCondition, List <Zone> zones)
 {
     isInZoneCondition.ClosedVolumes.AddRange(
         zones
         .Where(z => z.ZoneName == isInZoneCondition.ZoneName)     // Make sure only Zones with the same ZoneName as the condition are used.
         .Select(z => z.ClosedVolume)
         );
 }
示例#3
0
        private static ConditionResult VerifyCondition(List <object> objects, IsInZone isInZone)
        {
            ConditionResult result = new ConditionResult()
            {
                Condition = isInZone
            };
            List <string> failInfo = new List <string>();

            foreach (var obj in objects)
            {
                bool passed = false;

                IObject iObj = obj as IObject;
                if (iObj != null)
                {
                    foreach (var cv in isInZone.ClosedVolumes)
                    {
                        if (BH.Engine.CIH.Query.IsContaining(cv, iObj, isInZone.ContainmentRule))
                        {
                            passed = true;
                            break;
                        }
                    }

                    if (passed)
                    {
                        result.PassedObjects.Add(obj);
                    }
                    else
                    {
                        result.FailedObjects.Add(obj);
                        failInfo.Add($"{(string.IsNullOrWhiteSpace(isInZone.Clause) ? "" : isInZone.Clause + " failed: ")}" +
                                     $"{isInZone.ToString()}");
                    }
                }
                else
                {
                    result.FailedObjects.Add(obj);
                    failInfo.Add($"Could not evaluate containment for an object of type `{obj.GetType().Name}`.");
                }

                result.Pattern.Add(passed);
            }

            result.FailInfo = failInfo;
            return(result);
        }