Exemple #1
0
        public static RectangularGeometry TogbXML_RectangularGeometry(this IClosedPlanar3D closedPlanar3D, double tolerance = Core.Tolerance.MicroDistance)
        {
            if (closedPlanar3D == null)
            {
                return(null);
            }

            Plane plane = closedPlanar3D.GetPlane();

            Planar.BoundingBox2D boundingBox2D = plane.Convert(closedPlanar3D).GetBoundingBox();
            double area_closedPlanar3D         = closedPlanar3D.GetArea();
            double area_boundingBox2D          = boundingBox2D.GetArea();

            double width  = boundingBox2D.Width;
            double height = boundingBox2D.Height;

            if (System.Math.Abs(area_closedPlanar3D - area_boundingBox2D) > Core.Tolerance.MacroDistance)
            {
                //TODO: find better way to keep side ratio
                width  = System.Math.Sqrt(area_closedPlanar3D);
                height = area_closedPlanar3D / width;
            }

            RectangularGeometry rectangularGeometry = new RectangularGeometry();

            rectangularGeometry.Azimuth        = Spatial.Query.Azimuth(closedPlanar3D, Vector3D.WorldY).ToString();
            rectangularGeometry.Width          = width.ToString();
            rectangularGeometry.Height         = height.ToString();
            rectangularGeometry.CartesianPoint = plane.Convert(boundingBox2D.Min).TogbXML(tolerance);
            rectangularGeometry.Tilt           = Spatial.Query.Tilt(closedPlanar3D).ToString();
            return(rectangularGeometry);
        }
        static public Surface SetUpSurfaceFromIDF(EPObj.MemorySafe_Surface epsurface, PlanarGeometry pg)
        {
            Surface retsurface = new Surface();

            retsurface.PlanarGeometry = pg;
            if (epsurface._sunExposureVar == "SunExposed")
            {
                retsurface.AdjacentSpaceId = new AdjacentSpaceId[1];
                if (epsurface.tilt > 45 && epsurface.tilt < 135)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an exterior wall
                    retsurface.surfaceType       = surfaceTypeEnum.ExteriorWall;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj = new AdjacentSpaceId();
                    adj.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = true;
                }
                //it can be a roof
                else if (epsurface.tilt >= 0 && epsurface.tilt <= 45)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an exterior wall
                    retsurface.surfaceType       = surfaceTypeEnum.Roof;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj = new AdjacentSpaceId();
                    adj.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = true;
                }
                //it can be an exposed floor
                else
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an exterior wall
                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundSlab;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj = new AdjacentSpaceId();
                    adj.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = true;
                }
            }
            else if (epsurface._sunExposureVar == "NoSun" && epsurface._outsideBoundaryCondition == "Ground")
            {
                if (epsurface.tilt > 45 && epsurface.tilt < 135)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground wall
                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundWall;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
                else if (epsurface.tilt >= 0 && epsurface.tilt <= 45)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground ceiling
                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundCeiling;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
                else
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground slab or slab on grade

                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundSlab;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
            }
            else
            {
                retsurface.AdjacentSpaceId = new AdjacentSpaceId[2];
                //some new code associated with finding the order of the two spaces
                if (epsurface.tilt > 45 && epsurface.tilt < 135)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground wall
                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundWall;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    //this is wrong
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
                else if (epsurface.tilt >= 0 && epsurface.tilt <= 45)
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground ceiling
                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundCeiling;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    //this is wrong
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
                else
                {
                    Dictionary <string, double> WH = new Dictionary <string, double>();
                    //it can be considered an underground slab or slab on grade

                    retsurface.surfaceType       = surfaceTypeEnum.UndergroundSlab;
                    retsurface.constructionIdRef = "something";
                    retsurface.Name = epsurface.name;
                    //this is wrong
                    AdjacentSpaceId adj1 = new AdjacentSpaceId();
                    adj1.spaceIdRef = epsurface.zoneName;
                    AdjacentSpaceId adj2 = new AdjacentSpaceId();
                    adj2.spaceIdRef = epsurface.zoneName;
                    retsurface.AdjacentSpaceId[0] = adj1;
                    retsurface.AdjacentSpaceId[1] = adj2;

                    RectangularGeometry rg = new RectangularGeometry();
                    rg.Azimuth = gb.FormatDoubleToString(epsurface.azimuth);
                    //find lower left hand corner of exterior wall
                    //for now, we will just arbitrarily choose a point
                    rg.CartesianPoint = pg.PolyLoop.Points[0];
                    rg.Tilt           = gb.FormatDoubleToString(epsurface.tilt);
                    //get width and height
                    WH        = GetWidthandHeight(epsurface, retsurface.surfaceType);
                    rg.Width  = gb.FormatDoubleToString(WH["width"]);
                    rg.Height = gb.FormatDoubleToString(WH["height"]);
                    retsurface.RectangularGeometry = rg;

                    retsurface.PlanarGeometry    = pg;
                    retsurface.exposedToSunField = false;
                }
            }
            return(retsurface);
        }
        public static bool CreateSerial(string filepath)
        {
            //place an in memory object here that represents your class representation of the building
            List <EPObj.MemorySafe_Spaces> myspace = new List <EPObj.MemorySafe_Spaces>();

            myspace = EnergyPlusClass.EPlusSpacestoObjectList(@"C:\Users\Chiensi\Documents\C\Buro Happold\Oregon Sustainability Center\Run 1 + Daylighting Only\Run 1 new.idf");

            gb.gbci = new CultureInfo(String.Empty);

            bool ret = false;

            //the basics
            //constructor to define the basics
            gbXML gbx = new gbXML();

            gbx.lengthUnit      = lengthUnitEnum.Feet;
            gbx.temperatureUnit = temperatureUnitEnum.F;
            string id  = "cmps-1";
            Campus cmp = CreateCampus(id);

            cmp.Buildings = new Building[10000];
            gbx.Campus    = cmp;

            //where does this location information from?  it could be smartly inferred somehow, but otherwise specified by the user/programmer
            Location zeloc = new Location();

            zeloc.Name      = "San Francisco, CA";
            zeloc.Latitude  = "37.795";
            zeloc.Longitude = "-122.394";
            //end the basics
            //tie location and campus back to the gbXML file
            cmp.Location = zeloc;

            //Define the building(s) on the site
            //CHarriman Septempber 19 2013
            cmp.Buildings[0] = MakeBuilding(2000, "bldg-1", buildingTypeEnum.DiningBarLoungeOrLeisure);

            //CHarriman September 19 2013
            //define the stories for each building
            //several ways to do this
            List <List <double> > points = prod.MakeFakeList(5);
            BuildingStorey        bs     = MakeStorey(1, points);

            //CHarriman Jan 15 2014
            //define the spaces for each building (these come from a space object elsewhere
            List <Space> gbSpaces = new List <Space>();

            gbSpaces = MakeSpacesFromEPObj(myspace);


            for (int spacecount = 0; spacecount < gbSpaces.Count(); spacecount++)
            {
                cmp.Buildings[0].Spaces[spacecount] = gbSpaces[spacecount];
            }


            //after making all the spaces, I make the surfaces
            cmp.Surface = new Surface[uniquesurfaces.Count()];
            int surfcount = 0;

            foreach (KeyValuePair <string, Surface> pair in uniquesurfaces)
            {
                Surface surf = new Surface();
                surf.id = pair.Key;
                //this is a hard one, how to deal with this?  For now, everything is external, and idf can sort of tell me
                surf.surfaceType       = pair.Value.surfaceType;
                surf.constructionIdRef = pair.Value.constructionIdRef;
                surf.Name = pair.Value.Name;
                AdjacentSpaceId[] adjspaces = new AdjacentSpaceId[pair.Value.AdjacentSpaceId.Count()];
                int counter = 0;
                foreach (AdjacentSpaceId adj in pair.Value.AdjacentSpaceId)
                {
                    adjspaces[counter] = adj;
                    counter++;
                }
                surf.AdjacentSpaceId = adjspaces;
                RectangularGeometry rg = new RectangularGeometry();
                rg = pair.Value.RectangularGeometry;
                surf.RectangularGeometry = rg;
                surf.PlanarGeometry      = pair.Value.PlanarGeometry;
                cmp.Surface[surfcount]   = surf;
                surfcount++;
            }


            cmp.Buildings[0].bldgStories[0] = bs;

            //write xml to the file
            XmlSerializer szer = new XmlSerializer(typeof(gbXML));
            TextWriter    tw   = new StreamWriter(filepath);

            szer.Serialize(tw, gbx);
            tw.Close();

            return(ret);
        }