Esempio n. 1
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static Floor ToRevitFloor(this oM.Physical.Elements.Floor floor, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (floor == null || floor.Construction == null || document == null)
            {
                return(null);
            }

            Floor revitFloor = refObjects.GetValue <Floor>(document, floor.BHoM_Guid);

            if (revitFloor != null)
            {
                return(revitFloor);
            }

            PlanarSurface planarSurface = floor.Location as PlanarSurface;

            if (planarSurface == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            FloorType floorType = floor.Construction?.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_Floors
            }, settings, refObjects) as FloorType;

            if (floorType == null)
            {
                floorType = floor.ElementType(document, settings);
            }

            if (floorType == null)
            {
                Compute.ElementTypeNotFoundWarning(floor);
                return(null);
            }

            double bottomElevation = floor.Location.IBounds().Min.Z;
            Level  level           = document.LevelBelow(bottomElevation.FromSI(UnitType.UT_Length), settings);

            oM.Geometry.Plane sketchPlane = new oM.Geometry.Plane {
                Origin = new BH.oM.Geometry.Point {
                    Z = bottomElevation
                }, Normal = Vector.ZAxis
            };
            ICurve     curve      = planarSurface.ExternalBoundary.IProject(sketchPlane);
            CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves());

            BH.oM.Geometry.Plane slabPlane = planarSurface.FitPlane();
            if (1 - Math.Abs(Vector.ZAxis.DotProduct(slabPlane.Normal)) <= settings.AngleTolerance)
            {
                revitFloor = document.Create.NewFloor(curveArray, floorType, level, true);
            }
            else
            {
                Vector normal = slabPlane.Normal;
                if (normal.Z < 0)
                {
                    normal = -slabPlane.Normal;
                }

                double angle = normal.Angle(Vector.ZAxis);
                double tan   = Math.Tan(angle);

                XYZ dir = normal.Project(oM.Geometry.Plane.XY).ToRevit().Normalize();
                BH.oM.Geometry.Line ln = slabPlane.PlaneIntersection(sketchPlane);
                XYZ start = ln.ClosestPoint(curveArray.get_Item(0).GetEndPoint(0).PointFromRevit(), true).ToRevit();
                Autodesk.Revit.DB.Line line = Autodesk.Revit.DB.Line.CreateBound(start, start + dir);

                revitFloor = document.Create.NewSlab(curveArray, level, line, -tan, true);
                revitFloor.SetParameter(BuiltInParameter.ELEM_TYPE_PARAM, floorType.Id);
            }

            revitFloor.CheckIfNullPush(floor);
            if (revitFloor == null)
            {
                return(null);
            }

            document.Regenerate();

            if (planarSurface.InternalBoundaries != null)
            {
                foreach (ICurve hole in planarSurface.InternalBoundaries)
                {
                    document.Create.NewOpening(revitFloor, Create.CurveArray(hole.IProject(slabPlane).IToRevitCurves()), true);
                }
            }

            foreach (BH.oM.Physical.Elements.IOpening opening in floor.Openings)
            {
                PlanarSurface openingLocation = opening.Location as PlanarSurface;
                if (openingLocation == null)
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Conversion of a floor opening to Revit failed because its location is not a planar surface. Floor BHoM_Guid: {0}, Opening BHoM_Guid: {1}", floor.BHoM_Guid, opening.BHoM_Guid));
                    continue;
                }

                document.Create.NewOpening(revitFloor, Create.CurveArray(openingLocation.ExternalBoundary.IToRevitCurves()), true);

                if (!(opening is BH.oM.Physical.Elements.Void))
                {
                    BH.Engine.Reflection.Compute.RecordWarning(String.Format("Revit allows only void openings in floors, therefore the BHoM opening of type {0} has been converted to a void opening. Floor BHoM_Guid: {1}, Opening BHoM_Guid: {2}", opening.GetType().Name, floor.BHoM_Guid, opening.BHoM_Guid));
                }
            }

            double offset = revitFloor.LookupParameterDouble(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);

            // Copy parameters from BHoM object to Revit element
            revitFloor.CopyParameters(floor, settings);

            // Update the offset in case the level had been overwritten.
            if (revitFloor.LevelId.IntegerValue != level.Id.IntegerValue)
            {
                Level newLevel = document.GetElement(revitFloor.LevelId) as Level;
                offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length);
            }

            revitFloor.SetParameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM, offset);

            refObjects.AddOrReplace(floor, revitFloor);
            return(revitFloor);
        }
Esempio n. 2
0
        public void StartNewGame()
        {
            DestroyOldGame();

            Vector3[] vertexPositionsArray;

            if (squaresToggle.isOn)
            {
                IntVector2 boardSize;
                if (smallToggle.isOn)
                {
                    boardSize = new IntVector2(9, 9);
                }
                else if (mediumToggle.isOn)
                {
                    boardSize = new IntVector2(13, 13);
                }
                else
                {
                    boardSize = new IntVector2(19, 19);
                }
                _surface         = RectangularQuadGrid.Create(Vector2.right, Vector2.up, Vector3.zero, Quaternion.identity, false, false, boardSize);
                _topology        = ((RectangularQuadGrid)_surface).CreateManifold(out vertexPositionsArray);
                _vertexPositions = PositionalVertexAttribute.Create(_surface, vertexPositionsArray);
            }
            else if (hexesToggle.isOn)
            {
                IntVector2 boardSize;
                if (smallToggle.isOn)
                {
                    boardSize = new IntVector2(9, 9);
                }
                else if (mediumToggle.isOn)
                {
                    boardSize = new IntVector2(13, 13);
                }
                else
                {
                    boardSize = new IntVector2(19, 19);
                }
                _surface = RectangularHexGrid.Create(
                    HexGridDescriptor.CreateCornerUp(true, HexGridAxisStyles.StaggeredSymmetric),
                    Vector3.zero, Quaternion.identity,
                    false, false,
                    boardSize);
                _topology        = ((RectangularHexGrid)_surface).CreateManifold(out vertexPositionsArray);
                _vertexPositions = PositionalVertexAttribute.Create(_surface, vertexPositionsArray);
            }
            else
            {
                IntVector2 boardSize;
                if (smallToggle.isOn)
                {
                    boardSize = new IntVector2(9, 9);
                }
                else if (mediumToggle.isOn)
                {
                    boardSize = new IntVector2(13, 13);
                }
                else
                {
                    boardSize = new IntVector2(19, 19);
                }
                _surface = RectangularHexGrid.Create(
                    HexGridDescriptor.CreateCornerUp(true, HexGridAxisStyles.StaggeredSymmetric),
                    Vector3.zero, Quaternion.identity,
                    false, false,
                    boardSize);
                _topology        = ((RectangularHexGrid)_surface).CreateManifold(out vertexPositionsArray);
                _vertexPositions = PositionalVertexAttribute.Create(_surface, vertexPositionsArray);

                var regularityWeight = 0.5f;
                var equalAreaWeight  = 1f - regularityWeight;

                var regularityRelaxedVertexPositions = new Vector3[_topology.vertices.Count].AsVertexAttribute();
                var equalAreaRelaxedVertexPositions  = new Vector3[_topology.vertices.Count].AsVertexAttribute();
                var relaxedVertexPositions           = regularityRelaxedVertexPositions;
                var faceCentroids = PositionalFaceAttribute.Create(_surface, _topology.internalFaces.Count);
                var vertexAreas   = new float[_topology.vertices.Count].AsVertexAttribute();

                FaceAttributeUtility.CalculateFaceCentroidsFromVertexPositions(_topology.internalFaces, _vertexPositions, faceCentroids);
                VertexAttributeUtility.CalculateVertexAreasFromVertexPositionsAndFaceCentroids(_topology.vertices, _vertexPositions, faceCentroids, vertexAreas);

                var totalArea = 0f;
                foreach (var vertexArea in vertexAreas)
                {
                    totalArea += vertexArea;
                }

                Func <float> relaxIterationFunction = () =>
                {
                    PlanarManifoldUtility.RelaxVertexPositionsForRegularity(_topology, _vertexPositions, true, regularityRelaxedVertexPositions);
                    PlanarManifoldUtility.RelaxVertexPositionsForEqualArea(_topology, _vertexPositions, totalArea, true, equalAreaRelaxedVertexPositions, faceCentroids, vertexAreas);
                    for (int i = 0; i < relaxedVertexPositions.Count; ++i)
                    {
                        relaxedVertexPositions[i] = regularityRelaxedVertexPositions[i] * regularityWeight + equalAreaRelaxedVertexPositions[i] * equalAreaWeight;
                    }
                    var relaxationAmount = PlanarManifoldUtility.CalculateRelaxationAmount(_vertexPositions, relaxedVertexPositions);
                    for (int i = 0; i < _vertexPositions.Count; ++i)
                    {
                        _vertexPositions[i] = relaxedVertexPositions[i];
                    }
                    return(relaxationAmount);
                };

                Func <bool> repairFunction = () =>
                {
                    return(PlanarManifoldUtility.ValidateAndRepair(_topology, _surface.normal, _vertexPositions, 0.5f, true));
                };

                Action relaxationLoopFunction = TopologyRandomizer.CreateRelaxationLoopFunction(20, 20, 0.95f, relaxIterationFunction, repairFunction);

                TopologyRandomizer.Randomize(
                    _topology, 1, 0.1f,
                    3, 3, 5, 7, true,
                    _random,
                    relaxationLoopFunction);
            }

            _facePositions = PositionalFaceAttribute.Create(_surface, _topology.internalFaces.Count);
            FaceAttributeUtility.CalculateFaceCentroidsFromVertexPositions(_topology.internalFaces, _vertexPositions, _facePositions);

            _innerAngleBisectors = EdgeAttributeUtility.CalculateFaceEdgeBisectorsFromVertexPositions(_topology.internalFaces, PlanarSurface.Create(Vector3.zero, Quaternion.identity), _vertexPositions);

            _faceBoardStates = new BoardState[_topology.internalFaces.Count].AsFaceAttribute();

            foreach (var face in _topology.internalFaces)
            {
                _faceBoardStates[face] = BoardState.Empty;
            }

            _facePieces = new Transform[_topology.internalFaces.Count].AsFaceAttribute();

            _partitioning        = UniversalFaceSpatialPartitioning.Create(_surface, _topology, _vertexPositions);
            _picker.partitioning = _partitioning;
            _picker.enabled      = true;

            var centerVertexNormal = _surface.normal.normalized;

            var triangulation = new SeparatedFacesUmbrellaTriangulation(2,
                                                                        (Topology.FaceEdge edge, DynamicMesh.IIndexedVertexAttributes vertexAttributes) =>
            {
                vertexAttributes.position = _vertexPositions[edge];
                vertexAttributes.normal   = (_vertexPositions[edge] + _surface.normal * 5f - _facePositions[edge.nearFace]).normalized;
                vertexAttributes.uv       = new Vector2(0.25f, 0f);
                vertexAttributes.Advance();

                vertexAttributes.position = _vertexPositions[edge] + _innerAngleBisectors[edge] * 0.05f;
                vertexAttributes.normal   = (vertexAttributes.position + _surface.normal * 5f - _facePositions[edge.nearFace]).normalized;
                vertexAttributes.uv       = new Vector2(0.25f, 0.5f);
                vertexAttributes.Advance();
            },
                                                                        (Topology.Face face, DynamicMesh.IIndexedVertexAttributes vertexAttributes) =>
            {
                vertexAttributes.position = _facePositions[face];
                vertexAttributes.normal   = centerVertexNormal;
                vertexAttributes.uv       = new Vector2(0.25f, 1f);
                vertexAttributes.Advance();
            });

            _dynamicMesh = DynamicMesh.Create(
                _topology.enumerableInternalFaces,
                DynamicMesh.VertexAttributes.Position |
                DynamicMesh.VertexAttributes.Normal |
                DynamicMesh.VertexAttributes.UV,
                triangulation);

            foreach (var mesh in _dynamicMesh.submeshes)
            {
                var meshObject = Instantiate(meshFilterRendererPrefab);
                meshObject.mesh = mesh;
                meshObject.transform.SetParent(gameBoardMeshes);
            }

            _gameBoardBounds = new Bounds(Vector3.zero, Vector3.zero);
            foreach (var vertex in _topology.vertices)
            {
                _gameBoardBounds.Encapsulate(_vertexPositions[vertex]);
            }

            AdjustCamera();

            var pickerCollider = GetComponent <BoxCollider>();

            pickerCollider.center = _gameBoardBounds.center;
            pickerCollider.size   = _gameBoardBounds.size;

            _whiteCount = 0;
            _blackCount = 0;
            _moveCount  = 0;

            whiteCountText.text = _whiteCount.ToString();
            blackCountText.text = _blackCount.ToString();

            _gameActive = true;
            _turn       = BoardState.Black;
        }
Esempio n. 3
0
 public static Point Centroid(this PlanarSurface surface, double tolerance = Tolerance.Distance)
 {
     return(Centroid(new List <ICurve> {
         surface.ExternalBoundary
     }, surface.InternalBoundaries, tolerance));
 }
Esempio n. 4
0
        /***************************************************/

        public static List <ICurve> ExternalEdges(this PlanarSurface surface)
        {
            return(new List <ICurve> {
                surface.ExternalBoundary
            });
        }
Esempio n. 5
0
        /***************************************************/

        public static PlanarSurface ProjectAlong(this PlanarSurface surface, Plane plane, Vector vector)
        {
            return(new PlanarSurface(
                       surface.ExternalBoundary.IProjectAlong(plane, vector),
                       surface.InternalBoundaries.Select(x => x.IProjectAlong(plane, vector)).ToList()));
        }
Esempio n. 6
0
        /***************************************************/

        public static PlanarSurface Transform(this PlanarSurface surface, TransformMatrix transform)
        {
            return(new PlanarSurface(surface.ExternalBoundary.ITransform(transform), surface.InternalBoundaries.Select(x => x.ITransform(transform)).ToList()));
        }
Esempio n. 7
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static oM.Environment.Elements.Panel EnvironmentPanelFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            //Create a BuildingElement from the familyInstance geometry
            settings = settings.DefaultIfNull();

            oM.Environment.Elements.Panel panel = refObjects.GetValue <oM.Environment.Elements.Panel>(familyInstance.Id);
            if (panel != null)
            {
                return(panel);
            }

            PlanarSurface openingSurface = familyInstance.OpeningSurface(null, settings) as PlanarSurface;
            ICurve        outline        = openingSurface?.ExternalBoundary;

            if (outline == null)
            {
                return(null);
            }

            panel = new oM.Environment.Elements.Panel()
            {
                ExternalEdges = outline.ToEdges(),
                Name          = familyInstance.FamilyTypeFullName(),
            };

            //Set ExtendedProperties
            OriginContextFragment originContext = new OriginContextFragment()
            {
                ElementID = familyInstance.Id.IntegerValue.ToString(), TypeName = familyInstance.FamilyTypeFullName()
            };

            originContext.SetProperties(familyInstance.Symbol, settings.ParameterSettings);
            originContext.SetProperties(familyInstance, settings.ParameterSettings);
            panel.Fragments.Add(originContext);

            PanelAnalyticalFragment panelAnalytical = new PanelAnalyticalFragment();

            panelAnalytical.SetProperties(familyInstance.Symbol, settings.ParameterSettings);
            panelAnalytical.SetProperties(familyInstance, settings.ParameterSettings);
            panel.Fragments.Add(panelAnalytical);

            PanelContextFragment panelContext = new PanelContextFragment();

            panelContext.SetProperties(familyInstance.Symbol, settings.ParameterSettings);
            panelContext.SetProperties(familyInstance, settings.ParameterSettings);
            panel.Fragments.Add(panelContext);

            BuildingResultFragment buildingResults = new BuildingResultFragment();

            buildingResults.SetProperties(familyInstance.Symbol, settings.ParameterSettings);
            buildingResults.SetProperties(familyInstance, settings.ParameterSettings);
            panel.Fragments.Add(buildingResults);

            oM.Environment.Elements.PanelType?panelType = familyInstance.Category.PanelType();
            if (panelType.HasValue)
            {
                panel.Type = panelType.Value;
            }
            else
            {
                panel.Type = oM.Environment.Elements.PanelType.Undefined;
            }

            //Set identifiers, parameters & custom data
            panel.SetIdentifiers(familyInstance);
            panel.CopyParameters(familyInstance, settings.ParameterSettings);
            panel.SetProperties(familyInstance, settings.ParameterSettings);

            refObjects.AddOrReplace(familyInstance.Id, panel);
            return(panel);
        }
Esempio n. 8
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static List <BH.oM.Geometry.Line> CeilingPattern(this Ceiling ceiling, RevitSettings settings, PlanarSurface surface = null)
        {
            CeilingType       ceilingType = ceiling.Document.GetElement(ceiling.GetTypeId()) as CeilingType;
            CompoundStructure comStruct   = ceilingType.GetCompoundStructure();

            Material material = null;

            if (comStruct != null && comStruct.GetLayers().Count > 0)
            {
                material = ceiling.Document.GetElement(comStruct.GetLayers().Last().MaterialId) as Material;
            }
            else
            {
                ElementId materialId = ceiling.GetMaterialIds(false)?.FirstOrDefault();

                if (materialId != null)
                {
                    material = ceiling.Document.GetElement(materialId) as Material;
                }
            }

            if (material == null)
            {
                BH.Engine.Reflection.Compute.RecordWarning(String.Format("Ceiling patterns could not be pulled because there is no material assigned to the ceiling. Revit ElementId: {0}", ceiling.Id));
                return(new List <oM.Geometry.Line>());
            }

            double rotation;
            XYZ    alignment = ceiling.CeilingPatternAlignment(material, settings, out rotation);

            List <oM.Geometry.Line> result = new List <oM.Geometry.Line>();

            if (surface == null)
            {
                //This would need to be extended to take openings from Values into account
                foreach (PlanarSurface srf in ceiling.PanelSurfaces(ceiling.FindInserts(true, true, true, true), settings).Keys)
                {
                    result.AddRange(material.CeilingPattern(srf, settings, alignment, rotation));
                }
            }
            else
            {
                result.AddRange(material.CeilingPattern(surface, settings, alignment, rotation));
            }

            return(result);
        }
Esempio n. 9
0
        /***************************************************/

        public static List <BH.oM.Geometry.Line> CeilingPattern(this Material revitMaterial, PlanarSurface surface, RevitSettings settings, XYZ origin = null, double angle = 0)
        {
            surface = surface.Rotate(BH.oM.Geometry.Point.Origin, Vector.ZAxis, -angle);
            BoundingBox box = surface.IBounds();

            origin = Transform.CreateRotation(XYZ.BasisZ, -angle).OfPoint(origin);

            double z            = surface.ExternalBoundary.IControlPoints().Max(x => x.Z);
            double yLength      = (box.Max.Y - box.Min.Y) / 2;
            double xLength      = (box.Max.X - box.Min.X) / 2;
            double maxBoxLength = box.Min.Distance(box.Max);

            BH.oM.Geometry.Line leftLine = new oM.Geometry.Line
            {
                Start = new oM.Geometry.Point {
                    X = box.Min.X, Y = box.Min.Y, Z = z
                },
                End = new oM.Geometry.Point {
                    X = box.Min.X, Y = box.Max.Y, Z = z
                },
            };

            BH.oM.Geometry.Line rightLine = new oM.Geometry.Line
            {
                Start = new oM.Geometry.Point {
                    X = box.Max.X, Y = box.Min.Y, Z = z
                },
                End = new oM.Geometry.Point {
                    X = box.Max.X, Y = box.Max.Y, Z = z
                },
            };

            List <BH.oM.Geometry.Line> boundarySegments = surface.ExternalBoundary.ICollapseToPolyline(settings.AngleTolerance).SubParts().ToList();

            List <BH.oM.Geometry.Line> patterns           = new List <BH.oM.Geometry.Line>();
            FillPatternElement         fillPatternElement = null;

#if (REVIT2020 || REVIT2021)
            fillPatternElement = revitMaterial.Document.GetElement(revitMaterial.SurfaceForegroundPatternId) as FillPatternElement;
#else
            fillPatternElement = revitMaterial.Document.GetElement(revitMaterial.SurfacePatternId) as FillPatternElement;
#endif

            if (fillPatternElement != null)
            {
                FillPattern fillPattern = fillPatternElement.GetFillPattern();
                if (fillPattern == null || fillPattern.IsSolidFill)
                {
                    return(new List <oM.Geometry.Line>()); //Skip solid filled patterns
                }
                IList <FillGrid> fillGridList = fillPattern.GetFillGrids();
                foreach (FillGrid grid in fillGridList)
                {
                    double offset = grid.Offset.ToSI(UnitType.UT_Length);

                    double currentY = ((int)((box.Min.Y - yLength) / offset)) * offset;
                    double currentX = ((int)((box.Min.X - xLength) / offset)) * offset;

                    double minNum = currentX;
                    double maxNum = (box.Max.X + xLength);

                    if (grid.Angle.ToSI(UnitType.UT_Angle) > settings.AngleTolerance)
                    {
                        minNum = currentY;
                        maxNum = (box.Max.Y + yLength);
                    }

                    if (origin != null)
                    {
                        if (grid.Angle.ToSI(UnitType.UT_Angle) > settings.AngleTolerance)
                        {
                            minNum += (origin.Y % grid.Offset).ToSI(UnitType.UT_Length);
                        }
                        else
                        {
                            minNum += (origin.X % grid.Offset).ToSI(UnitType.UT_Length);
                        }
                    }

                    while ((minNum + offset) < maxNum)
                    {
                        BH.oM.Geometry.Point pt = new oM.Geometry.Point {
                            X = minNum + offset, Y = box.Min.Y, Z = z
                        };
                        BH.oM.Geometry.Point pt2 = new oM.Geometry.Point {
                            X = minNum + offset, Y = box.Max.Y, Z = z
                        };

                        BH.oM.Geometry.Line pline = new oM.Geometry.Line {
                            Start = pt, End = pt2
                        };

                        if (grid.Angle.ToSI(UnitType.UT_Angle) > settings.AngleTolerance)
                        {
                            BH.oM.Geometry.Point rotatePt = pline.Centroid();
                            pline = pline.Rotate(rotatePt, Vector.ZAxis, grid.Angle.ToSI(UnitType.UT_Angle));

                            pline.Start.Y = minNum + offset;
                            pline.End.Y   = minNum + offset;

                            BH.oM.Geometry.Point intersect = pline.LineIntersection(leftLine, true);
                            if (intersect != null)
                            {
                                pline.Start = intersect;
                            }

                            intersect = pline.LineIntersection(rightLine, true);
                            if (intersect != null)
                            {
                                pline.End = intersect;
                            }

                            Vector v1 = pline.End - pline.Start; //From start TO end
                            v1 *= maxBoxLength;
                            Vector v2 = pline.Start - pline.End; //From end TO start
                            v2 *= maxBoxLength;

                            pline.Start = pline.Start.Translate(v2);
                            pline.End   = pline.End.Translate(v1);
                        }

                        List <BH.oM.Geometry.Point> intersections = new List <oM.Geometry.Point>();
                        foreach (BH.oM.Geometry.Line l in boundarySegments)
                        {
                            BH.oM.Geometry.Point p = pline.LineIntersection(l);
                            if (p != null)
                            {
                                intersections.Add(p);
                            }
                        }

                        List <BH.oM.Geometry.Line> lines = new List <oM.Geometry.Line>();

                        if (intersections.Count > 0)
                        {
                            lines = pline.SplitAtPoints(intersections);
                        }
                        else
                        {
                            lines.Add(pline);
                        }

                        foreach (BH.oM.Geometry.Line l in lines)
                        {
                            List <BH.oM.Geometry.Point> pts = l.ControlPoints();
                            pts.Add(l.Centroid());

                            if (surface.ExternalBoundary.IIsContaining(pts, true))
                            {
                                patterns.Add(l.Rotate(BH.oM.Geometry.Point.Origin, Vector.ZAxis, angle));
                            }
                        }

                        minNum += offset;
                    }
                }
            }

            patterns.AddRange(boundarySegments.Select(x => x.Rotate(BH.oM.Geometry.Point.Origin, Vector.ZAxis, angle))); //Close off the ceiling pattern for its own use

            return(patterns);
        }
Esempio n. 10
0
        /***************************************************/

        public static PlanarSurface Clone(this PlanarSurface surface)
        {
            return(new PlanarSurface(surface.ExternalBoundary.IClone(), surface.InternalBoundaries.Select(x => x.IClone()).ToList()));
        }
Esempio n. 11
0
        /***************************************************/

        public static PlanarSurface Rotate(this PlanarSurface surface, Point origin, Vector axis, double rad)
        {
            TransformMatrix rotationMatrix = Create.RotationMatrix(origin, axis, rad);

            return(Transform(surface, rotationMatrix));
        }
Esempio n. 12
0
 public static List <Point> Points(PlanarSurface g)
 {
     return(g.ExternalBoundary.IControlPoints().Concat(g.InternalBoundaries.SelectMany(ib => ib.IControlPoints())).ToList());
 }
Esempio n. 13
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static ISurface OpeningSurface(this FamilyInstance familyInstance, HostObject host = null, RevitSettings settings = null)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            BoundingBoxXYZ bbox = familyInstance.get_BoundingBox(null);

            if (bbox == null)
            {
                return(null);
            }

            // Get parent element if this family instance is a nested instance
            Element parentElem = familyInstance.SuperComponent;
            int     parentId   = -1;

            if (parentElem != null)
            {
                parentId = familyInstance.SuperComponent.Id.IntegerValue;
            }

            settings = settings.DefaultIfNull();
            List <HostObject> hosts;

            if (host != null)
            {
                hosts = new List <HostObject> {
                    host
                }
            }
            ;
            else
            {
                BoundingBoxIntersectsFilter bbif = new BoundingBoxIntersectsFilter(new Outline(bbox.Min, bbox.Max));
                hosts = new FilteredElementCollector(familyInstance.Document).OfClass(typeof(HostObject)).WherePasses(bbif).Cast <HostObject>().ToList();
                hosts = hosts.Where(x => x.FindInserts(true, true, true, true).Any(y => (y.IntegerValue == familyInstance.Id.IntegerValue) || (y.IntegerValue == parentId))).ToList();
            }

            List <ISurface> surfaces = new List <ISurface>();

            if (parentElem != null) // Indicates element is a nested instance and needs different approach to extract location
            {
                Document    doc = familyInstance.Document;
                Transaction t   = new Transaction(doc);

                t.Start("Temp Delete Inserts");
                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != -1).ToList();

                // Create dummy instance of nested element with matching parameters
                LocationPoint locPt         = familyInstance.Location as LocationPoint;
                Element       dummyInstance = doc.Create.NewFamilyInstance(locPt.Point, familyInstance.Symbol, hosts.First() as Element, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                IEnumerable <BuiltInParameter> paramsToSkip = new List <BuiltInParameter> {
                    BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM, BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM
                };
                familyInstance.CopyParameters(dummyInstance, paramsToSkip);

                doc.Delete(inserts);
                doc.Regenerate();

                surfaces = GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings);
            }

            else if (hosts.Count == 0)
            {
                HostObject curtainHost = familyInstance.Host as HostObject;
                if (curtainHost == null)
                {
                    return(null);
                }

                List <CurtainGrid> curtainGrids = curtainHost.ICurtainGrids();
                if (curtainGrids.Count != 0)
                {
                    foreach (CurtainGrid cg in curtainGrids)
                    {
                        List <ElementId>   ids   = cg.GetPanelIds().ToList();
                        List <CurtainCell> cells = cg.GetCurtainCells().ToList();
                        if (ids.Count != cells.Count)
                        {
                            return(null);
                        }

                        for (int i = 0; i < ids.Count; i++)
                        {
                            if (ids[i].IntegerValue == familyInstance.Id.IntegerValue)
                            {
                                foreach (PolyCurve curve in cells[i].CurveLoops.FromRevit())
                                {
                                    PlanarSurface surface = new PlanarSurface(curve, null);
                                    if (surface == null)
                                    {
                                        return(null);
                                    }

                                    surfaces.Add(surface);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Document    doc = familyInstance.Document;
                Transaction t   = new Transaction(doc);

                t.Start("Temp Delete Inserts");

                List <ElementId> inserts = hosts.SelectMany(x => x.FindInserts(true, true, true, true)).Distinct().Where(x => x.IntegerValue != familyInstance.Id.IntegerValue).ToList();
                doc.Delete(inserts);
                doc.Regenerate();

                try
                {
                    inserts.Add(familyInstance.Id);
                }
                catch
                {
                }

                surfaces = GetOpeningGeometry(t, doc, hosts, inserts, familyInstance, settings);
            }

            if (surfaces.Count == 0)
            {
                return(null);
            }
            else if (surfaces.Count == 1)
            {
                return(surfaces[0]);
            }
            else
            {
                return new PolySurface {
                           Surfaces = surfaces
                }
            };
        }
Esempio n. 14
0
        /***************************************************/

        public static List <ICurve> InternalEdges(this PlanarSurface surface)
        {
            return(surface.InternalBoundaries);
        }
Esempio n. 15
0
 public static Vector Normal(this PlanarSurface surface)
 {
     return(surface.ExternalBoundary.INormal());
 }
Esempio n. 16
0
        /***************************************************/

        public static PlanarSurface Mirror(this PlanarSurface surface, Plane p)
        {
            return(new PlanarSurface(surface.ExternalBoundary.IMirror(p), surface.InternalBoundaries.Select(x => x.IMirror(p)).ToList()));
        }
Esempio n. 17
0
        /***************************************************/
        /**** Public Methods - Surfaces                 ****/
        /***************************************************/

        public static Plane FitPlane(this PlanarSurface surface, double tolerance = Tolerance.Distance)
        {
            return(IFitPlane(surface.ExternalBoundary, tolerance));
        }
Esempio n. 18
0
        /***************************************************/

        public static bool IsInPlane(this PlanarSurface surface, Plane plane, double tolerance = Tolerance.Distance)
        {
            return(surface.ExternalBoundary.IIsInPlane(plane, tolerance));
        }
Esempio n. 19
0
 public static Panel Panel(PlanarSurface surface, ISurfaceProperty property = null, Vector localX = null, string name = "")
 {
     return(surface.IsNull() ? null : Panel(surface.ExternalBoundary, surface.InternalBoundaries.ToList(), property, localX, name));
 }
Esempio n. 20
0
        /***************************************************/

        public static PlanarSurface Scale(this PlanarSurface surface, Point origin, Vector scaleVector)
        {
            TransformMatrix scaleMatrix = Create.ScaleMatrix(origin, scaleVector);

            return(surface.Transform(scaleMatrix));
        }