Пример #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <BuildingElement> SetBuildingElementTypeByAdjacencies(this List <BuildingElement> elements)
        {
            foreach (BuildingElement be in elements)
            {
                ElementProperties elementProps = be.ElementProperties() as ElementProperties;
                if (elementProps == null)
                {
                    elementProps = new ElementProperties();
                    be.ExtendedProperties.Add(elementProps);
                }

                BuildingElementContextProperties contextProps = be.ContextProperties() as BuildingElementContextProperties;
                if (contextProps == null)
                {
                    contextProps = new BuildingElementContextProperties();
                    be.ExtendedProperties.Add(contextProps);
                }

                if (contextProps.ConnectedSpaces.Where(x => x != "-1").ToList().Count == 0)
                {
                    elementProps.BuildingElementType = BuildingElementType.Shade;
                }
                else if (contextProps.ConnectedSpaces.Where(x => x != "-1").ToList().Count == 1)
                {
                    elementProps.BuildingElementType = BuildingElementType.WallExternal;
                }
                else if (contextProps.ConnectedSpaces.Where(x => x != "-1").ToList().Count == 2)
                {
                    elementProps.BuildingElementType = BuildingElementType.WallInternal;
                }
            }

            return(elements);
        }
Пример #2
0
        /***************************************************/
        /****          public Methods - Lines           ****/
        /***************************************************/

        public static List <BuildingElement> BuildSpace(this List <BuildingElement> elements, string spaceName)
        {
            List <BuildingElement> rtnElements = new List <BuildingElement>();

            foreach (BuildingElement be in elements)
            {
                BuildingElementContextProperties contextProps = be.ContextProperties() as BuildingElementContextProperties;
                if (contextProps != null)
                {
                    if (contextProps.ConnectedSpaces.Count == 1 && contextProps.ConnectedSpaces[0] == spaceName)
                    {
                        rtnElements.Add(be);
                    }
                    else if (contextProps.ConnectedSpaces.Count == 2)
                    {
                        if (contextProps.ConnectedSpaces[0] == spaceName || contextProps.ConnectedSpaces[1] == spaceName)
                        {
                            rtnElements.Add(be);
                        }
                    }
                }
            }

            return(rtnElements);
        }
Пример #3
0
        public static List <List <BuildingElement> > MatchSpaces(this List <List <BuildingElement> > elementsAsSpaces, List <Space> spaces)
        {
            spaces = new List <oM.Environment.Elements.Space>(spaces);

            foreach (List <BuildingElement> bes in elementsAsSpaces)
            {
                foreach (BuildingElement be in bes)
                {
                    BuildingElementContextProperties props = be.ContextProperties() as BuildingElementContextProperties;
                    if (props != null && props.ConnectedSpaces.Count > 0)
                    {
                        Space foundSpace = spaces.Where(x => x.Name == props.ConnectedSpaces[0]).FirstOrDefault();

                        if (foundSpace != null)
                        {
                            if (be.CustomData.ContainsKey("Space_Custom_Data"))
                            {
                                be.CustomData["Space_Custom_Data"] = foundSpace.CustomData;
                            }
                            else
                            {
                                be.CustomData.Add("Space_Custom_Data", foundSpace.CustomData);
                            }
                        }
                    }
                }
            }

            return(elementsAsSpaces);
        }
Пример #4
0
        public static BuildingElement MergeBuildingElement(this BuildingElement element1, BuildingElement element2)
        {
            BuildingElement rtnElement = null;

            if (element1.Area() > element2.Area())
            {
                rtnElement = element2.Copy();
            }
            else
            {
                rtnElement = element1.Copy();
            }

            rtnElement.ExtendedProperties.Remove(rtnElement.ContextProperties());

            //Move any properties over which need to be merged between the two elements... Currently only adjacent spaces
            BuildingElementContextProperties masterProperties = new BuildingElementContextProperties();

            BuildingElementContextProperties mergeToProps = (element1.ContextProperties() as BuildingElementContextProperties);

            if (mergeToProps != null)
            {
                masterProperties.Colour          = mergeToProps.Colour;
                masterProperties.ConnectedSpaces = new List <string>(mergeToProps.ConnectedSpaces);
                masterProperties.IsAir           = mergeToProps.IsAir;
                masterProperties.IsGround        = mergeToProps.IsGround;
                masterProperties.Reversed        = mergeToProps.Reversed;
            }

            BuildingElementContextProperties mergeProps = (element2.ContextProperties() as BuildingElementContextProperties);

            if (mergeProps == null)
            {
                mergeProps = new BuildingElementContextProperties(); //Hopefully this will never be needed...
            }
            if (mergeProps.ConnectedSpaces.Count > 0)
            {
                if (masterProperties.ConnectedSpaces.Count == 1)
                {
                    masterProperties.ConnectedSpaces.Add(mergeProps.ConnectedSpaces.Where(x => x != "-1").FirstOrDefault());
                }
                else
                {
                    masterProperties.ConnectedSpaces[masterProperties.ConnectedSpaces.IndexOf("-1")] = mergeProps.ConnectedSpaces.Where(x => x != "-1").FirstOrDefault();
                }
            }

            rtnElement.ExtendedProperties.Add(masterProperties);
            return(rtnElement);
        }
Пример #5
0
        public static List <string> UniqueSpaceNames(this List <BuildingElement> elements)
        {
            List <string> spaceNames = new List <string>();

            foreach (BuildingElement be in elements)
            {
                if (be.ContextProperties() != null && (be.ContextProperties() as BuildingElementContextProperties) != null)
                {
                    BuildingElementContextProperties props = be.ContextProperties() as BuildingElementContextProperties;
                    spaceNames.AddRange(props.ConnectedSpaces);
                }
            }

            return(spaceNames.Where(x => !x.Equals("-1")).Distinct().ToList());
        }
Пример #6
0
        public static List <BuildingElement> Space(List <BuildingElement> elements, string name)
        {
            foreach (BuildingElement be in elements)
            {
                BuildingElementContextProperties props = be.ContextProperties() as BuildingElementContextProperties;
                if (props == null)
                {
                    props = new BuildingElementContextProperties();
                    be.ExtendedProperties.Add(props);
                }

                props.ConnectedSpaces = new List <string> {
                    name, "-1"
                };                                                       //Default everyone to have an adjacent space of -1
            }

            return(elements);
        }
Пример #7
0
        public static string CommonSpaceName(this List <BuildingElement> elements)
        {
            //Gets the single space name which most commonly unites these elements
            List <string> uniqueNames = elements.UniqueSpaceNames();

            Dictionary <string, int> nameCount = new Dictionary <string, int>();

            foreach (string s in uniqueNames)
            {
                nameCount.Add(s, 0);
            }

            foreach (BuildingElement be in elements)
            {
                if (be.ContextProperties() != null && (be.ContextProperties() as BuildingElementContextProperties) != null)
                {
                    BuildingElementContextProperties props = be.ContextProperties() as BuildingElementContextProperties;
                    foreach (string name in props.ConnectedSpaces)
                    {
                        if (name != "-1")
                        {
                            nameCount[name]++;
                        }
                    }
                }
            }

            KeyValuePair <string, int> mostCommon = nameCount.First();

            foreach (KeyValuePair <string, int> kvp in nameCount)
            {
                if (kvp.Value > mostCommon.Value)
                {
                    mostCommon = kvp;
                }
            }

            return(mostCommon.Key);
        }
Пример #8
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <BuildingElement> AddAdjacentSpace(this List <BuildingElement> elements, string spaceName)
        {
            foreach (BuildingElement be in elements)
            {
                BuildingElementContextProperties props = be.ContextProperties() as BuildingElementContextProperties;
                if (props == null)
                {
                    BH.Engine.Reflection.Compute.RecordError("Element " + be.BHoM_Guid.ToString() + " could not have adjacent space set");
                }
                else
                {
                    if (props.ConnectedSpaces.Count == 1)
                    {
                        props.ConnectedSpaces.Add(spaceName);
                    }
                    else
                    {
                        props.ConnectedSpaces[1] = spaceName;
                    }
                }
            }

            return(elements);
        }