/***************************************************/

        internal static void LogNullProperties(this BHoMObject obj, IEnumerable <string> propertyNames = null)
        {
            //TODO: Move this one to the BHoM_Engine?
            List <string> nullPropertyNames = new List <string>();

            Type type = obj.GetType();

            if (propertyNames == null)
            {
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo pi in properties)
                {
                    if (pi.GetValue(obj) == null)
                    {
                        nullPropertyNames.Add(pi.Name);
                    }
                }
            }
            else
            {
                foreach (string propertyName in propertyNames)
                {
                    if (type.GetProperty(propertyName).GetValue(obj) == null)
                    {
                        nullPropertyNames.Add(propertyName);
                    }
                }
            }

            if (nullPropertyNames.Count > 0)
            {
                string warning = string.Format("The BHoM object if missing following properties: {0}. BHoM_Guid: {1}.", string.Join(", ", nullPropertyNames), obj.BHoM_Guid);

                ElementId revitID = obj.ElementId();
                if (revitID != null)
                {
                    warning += string.Format(" Revit ElementId: {0}.", revitID.IntegerValue);
                }
                BH.Engine.Reflection.Compute.RecordWarning(warning);
            }
        }
示例#2
0
        private static Dictionary <BHoMObject, BoundingBox> FilterObjects(List <BHoMObject> objects, SpatialSpecification spatialSpec)
        {
            Dictionary <BHoMObject, BoundingBox> passedObj_zoneBox = new Dictionary <BHoMObject, BoundingBox>();

            Dictionary <BHoMObject, IGeometry> objsGeometry = new Dictionary <BHoMObject, IGeometry>();

            // Compute the geometry for each object.
            foreach (var obj in objects)
            {
                BHoMObject bhomObj = obj as BHoMObject;
                IGeometry  geom    = BH.Engine.Base.Query.IGeometry(bhomObj);

                if (geom == null)
                {
                    BH.Engine.Reflection.Compute.RecordWarning($"Could not Query the Geometry out of a given {bhomObj.GetType().Name}.");
                    continue;
                }

                objsGeometry[bhomObj] = geom;
            }

            // Filter objects based on the spatialSpecifications.
            ZoneSpecification zoneSpec = spatialSpec.ZoneSpecification;

            // A bounding box is calculated per each object as defined by the individual ZoneSpecification
            Dictionary <BHoMObject, BoundingBox> bbPerObj = new Dictionary <BHoMObject, BoundingBox>();
            List <BoundingBox> allZoneBoxes = spatialSpec.SpatialBoundingBoxes();

            foreach (BHoMObject bhomObj in objsGeometry.Keys)
            {
                // Check if any of the Specification's boundingBoxes contains the object
                foreach (var zoneBB in allZoneBoxes)
                {
                    if (zoneBB.IsContaining(objsGeometry[bhomObj]))
                    {
                        // If the zone bounding box contains the bhomObject's Geometry, let's apply the other filters.
                        var res = VerifyCondition(new List <object>()
                        {
                            bhomObj
                        }, new LogicalCondition()
                        {
                            Conditions = zoneSpec.FilterConditions
                        });
                        if (res.PassedObjects.Count == 1) // if the object passed all the provided Conditions, then it's passed.
                        {
                            passedObj_zoneBox[res.PassedObjects.First() as BHoMObject] = zoneBB;
                        }
                    }
                }
            }

            return(passedObj_zoneBox);
        }