public XPreviewElement(IfcProduct ifcEntity)
            : base(ifcEntity)
        {
            Color       = ifcEntity.Description;
            ProfilePath = LoadProfilePath();

            XPolygon LoadProfilePath()
            {
                XPolygon profile = new XPolygon();

                foreach (var rep in ifcEntity.Representation.Representations)
                {
                    if (rep.RepresentationIdentifier == "Plan" && rep.RepresentationType == "Curve2D")
                    {
                        foreach (var item in rep.Items)
                        {
                            if (item is IfcPolyline polyline)
                            {
                                foreach (var point in polyline.Points)
                                {
                                    profile.Add(new XbimPoint3D(point.X, point.Y, point.Z));
                                }
                            }
                        }
                    }
                }

                return(profile);
            }
        }
Exemple #2
0
        private static Paths ToPaths(XPolygon polygon, double scaleBy = 1)
        {
            Paths paths = new Paths();

            paths.Add(ToPath(polygon, scaleBy));
            return(paths);
        }
Exemple #3
0
        private static List <XPolygon> FromPolyTree(PolyNode results, PathOrientation subjectOrientation, double scaleBy = 1000)
        {
            List <XPolygon> polygons = new List <XPolygon>();

            foreach (PolyNode child in results.Childs)
            {
                PathOrientation orientation = Clipper.Orientation(child.Contour) == true ? PathOrientation.Anticlockwise : PathOrientation.Clockwise;
                XPolygon        polygon     = FromPath(child.Contour, scaleBy);
                polygons.Add(polygon);

                foreach (PolyNode childNode in child.Childs)
                {
                    //polygon.InnerPaths.Add(FromPath(childNode.Contour, scaleBy));
                    //List<SimplePolygon> childPolygons = FromPolyTree(childNode, subjectOrientation, scaleBy);
                    //polygons.AddRange(childPolygons);
                }
                if (orientation != subjectOrientation)
                {
                    polygon.Reverse();
                }
                //polygon.MakeLines();
            }

            return(polygons);
        }
Exemple #4
0
        /// <summary>
        /// Creates a transformed copy of the polygon
        /// </summary>
        /// <param name="transform"></param>
        /// <returns></returns>
        public XPolygon Transformed(XbimMatrix3D transform)
        {
            XPolygon transformed = new XPolygon();

            ForEach(p => transformed.Add(transform.Transform(p)));
            return(transformed);
        }
Exemple #5
0
        private XPreviewBuilding CreateGarageStructure(XParameters parameters)
        {
            XbimPoint3D location  = parameters.Perimeter.First();
            XPolygon    perimeter = parameters.Perimeter.Normalized(location);
            // Create the building
            XPreviewBuilding garage = new XPreviewBuilding()
            {
                Name               = parameters.BuildingName,
                Location           = location,
                ReferenceDirection = new XbimVector3D(1, 0, 0),
                Axis               = new XbimVector3D(0, 0, 1)
            };

            // Building stories
            for (int i = 0; i < parameters.NumberOfFloors; i++)
            {
                XPreviewBuildingStory story = new XPreviewBuildingStory
                {
                    Name               = "Floor " + (i + 1).ToString(),
                    Location           = new XbimPoint3D(0, 0, i * parameters.FloorToFloor),
                    ReferenceDirection = new XbimVector3D(1, 0, 0),
                    Axis               = new XbimVector3D(0, 0, 1),
                    Container          = garage,
                    StoryNumber        = (i + 1),
                };
            }

            return(garage);
        }
Exemple #6
0
        /// <summary>
        /// Creates an identical copy of the polygon
        /// </summary>
        /// <returns></returns>
        public XPolygon Clone()
        {
            XPolygon copy = new XPolygon();

            ForEach(pt => copy.Add(new XbimPoint3D(pt.X, pt.Y, pt.Z)));
            return(copy);
        }
Exemple #7
0
        private void CreateCorridorWalls(XPreviewBuildingStory story)
        {
            XbimPoint3D p1 = new XbimPoint3D(0, parameters.CorridorWidth, 0);
            XbimPoint3D p2 = new XbimPoint3D(parameters.ReferenceLine.Length, parameters.CorridorWidth, 0);

            XPolygon wallProfile = CreateWallProfile(p1.Distance(p2));

            XPreviewWall wall = new XPreviewWall
            {
                Name        = "Wall ",
                Location    = new XbimPoint3D(0, -parameters.CorridorWidth / 2, 0),
                ProfilePath = wallProfile.Clone(),
                Thickness   = parameters.InteriorWallThickness,
                Height      = parameters.CeilingElevation,
                Container   = story
            };

            wall = new XPreviewWall
            {
                Name        = "Wall ",
                Location    = new XbimPoint3D(0, parameters.CorridorWidth / 2, 0),
                ProfilePath = wallProfile.Clone(),
                Thickness   = parameters.InteriorWallThickness,
                Height      = parameters.CeilingElevation,
                Container   = story
            };
        }
Exemple #8
0
        public XPolygon Normalized(XbimPoint3D origin)
        {
            XPolygon temp = new XPolygon();

            ForEach(pt => temp.Add(new XbimPoint3D(pt.X, pt.Y, pt.Z)));
            temp.Normalize(origin);
            return(temp);
        }
Exemple #9
0
 public List <XPolygon> Clip(ClipType clipType, XPolygon clip, double scaleBy = 1000)
 {
     return(XPolygon.Clip(clipType, new List <XPolygon>()
     {
         this
     }, new List <XPolygon>()
     {
         clip
     }, scaleBy));
 }
Exemple #10
0
        private XPolygon CreateProfileP(double wallThickness)
        {
            double   unitWidth = UnitWidth - wallThickness;
            double   unitDepth = UnitDepth - wallThickness;
            XPolygon profile   = new XPolygon();

            profile.Add(new XbimPoint3D(-unitWidth / 2, UnitDepth / 2, 0));
            profile.Add(new XbimPoint3D(unitWidth / 2, UnitDepth / 2, 0));
            profile.Add(new XbimPoint3D(unitWidth / 2, -unitDepth / 2, 0));
            profile.Add(new XbimPoint3D(-unitWidth / 2, -unitDepth / 2, 0));
            return(profile);
        }
Exemple #11
0
        private static XPolygon FromPath(Path clipPath, double scaleBy = 1)
        {
            XPolygon path = new XPolygon();

            foreach (IntPoint pt in clipPath)
            {
                XbimPoint3D p = new XbimPoint3D(pt.X / scaleBy, pt.Y / scaleBy, 0);
                //p.UserData = pt.userData;
                path.Add(p);
            }
            return(path);
        }
Exemple #12
0
        /// <summary>
        /// Creates the internal wall profile from two points on the cenbter line and a thickness
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        private XPolygon CreateWallProfile(double length)
        {
            XPolygon wallProfile = new XPolygon
            {
                new XbimPoint3D(0, -parameters.InteriorWallThickness / 2, 0),
                new XbimPoint3D(length, -parameters.InteriorWallThickness / 2, 0),
                new XbimPoint3D(length, parameters.InteriorWallThickness / 2, 0),
                new XbimPoint3D(0, parameters.InteriorWallThickness / 2, 0)
            };

            return(wallProfile);
        }
Exemple #13
0
        private XPolygon CreateCorridorSpaceProfile(double wallThickness)
        {
            double width = parameters.CorridorWidth - wallThickness;

            // Transform the line to be in building coordinates;
            XLine refLine = parameters.ReferenceLine.Transformed(building.InverseGlobalTransform);
            // Create the profile. To be consistent the profile is centered at the mid point
            // starts upper left and is oriented clockwise
            XPolygon profile = new XPolygon
            {
                new XbimPoint3D(-refLine.Length / 2, width / 2, 0),
                new XbimPoint3D(refLine.Length / 2, width / 2, 0),
                new XbimPoint3D(refLine.Length / 2, -width / 2, 0),
                new XbimPoint3D(-refLine.Length / 2, -width / 2, 0)
            };

            return(profile);
        }
Exemple #14
0
        /// <summary>
        /// Creates the corridor space
        /// </summary>
        /// <param name="story"></param>
        private void CreateCorridorSpace(XPreviewBuildingStory story)
        {
            // Transform the line to be in building coordinates;
            XLine refLine = parameters.ReferenceLine.Transformed(building.InverseGlobalTransform);

            // Craete the profile
            XPolygon profile = CreateCorridorSpaceProfile(parameters.InteriorWallThickness);
            // Location will be at the center of the reference line
            XbimPoint3D   location = refLine.MidPoint;
            XPreviewSpace space    = new XPreviewSpace
            {
                Name        = "Corridor " + story.StoryNumber.ToString(),
                ProfilePath = profile,
                Height      = parameters.CeilingElevation,
                Location    = location,
                Container   = story,
                Color       = "#afafaf"
            };
        }
Exemple #15
0
        private void CreateSlabs(XPreviewBuildingStory story)
        {
            // For which we need the total footprint as defined by the units. But we can't boolean them together
            // because there are gaps between the spaces now - arrrghhhh!

            // Make the corridor polygon and then make each unit and boolean add them.
            XPolygon        corridor = CreateCorridorSpaceProfile(0).Transformed(story.Elements.First().LocalTransform);
            List <XPolygon> results  = new List <XPolygon>()
            {
                corridor
            };

            foreach (XPreviewSpace space in story.Elements.Where(elem => elem is XPreviewSpace space && space.LongName != null))
            {
                // Find the relating unit definition so we can create a polygon the extents of width and depth
                UnitParameters unitdef = unitsToCreate.Find(u => u.UnitType == space.LongName);
                if (unitdef != null)
                {
                    XPolygon fullProfile = unitdef.CreateFullSizeProfile().Transformed(space.LocalTransform);
                    results = XPolygon.Clip(ClipType.ctUnion, results, new List <XPolygon>()
                    {
                        fullProfile
                    });
                }
            }

            // We will place the slab at 0,0,0 on the story
            XPreviewSlab slab = new XPreviewSlab
            {
                Name        = "Slab " + story.StoryNumber,
                ProfilePath = results.First(),
                Thickness   = parameters.InterzoneSlabThickness,
                Container   = story,
                Height      = -parameters.InterzoneSlabThickness
            };
        }