Пример #1
0
        private List <Segment2D> CutOutDoor(Segment2D currentDoor, List <Segment2D> allWalls)
        {
            var listArray     = new List <List <Segment2D> >();
            var newWallList   = new List <Segment2D>();
            var wallsToRemove = new List <Segment2D>();

            Vector2D[] doorVertices    = currentDoor.GetVertices();
            Vector2D   doorVectorStart = doorVertices[0];
            Vector2D   doorVectorEnd   = doorVertices[1];
            Vector2D   doorVector      = doorVectorEnd.Difference(doorVectorStart).GetAsNormalized();

            foreach (Segment2D currentWall in allWalls)
            {
                Vector2D[] wallVertices    = currentWall.GetVertices();
                Vector2D   wallVectorStart = wallVertices[0];
                Vector2D   wallVectorEnd   = wallVertices[1];
                Vector2D   wallVector      = wallVectorEnd.Difference(wallVectorStart).GetAsNormalized();

                if (wallVectorStart.IsEqualTo(wallVectorEnd))
                {
                    wallsToRemove.Add(currentWall);
                    continue;
                }
                else if (GeoAdditionals.SegmentsLieOnTopOfEachOther(currentDoor, currentWall))
                {
                    double cos = wallVector.Dot(doorVector) / (wallVector.normalize() * doorVector.normalize());

                    if (cos < 0)
                    {
                        doorVectorStart = doorVertices[1];
                        doorVectorEnd   = doorVertices[0];
                    }

                    if (!wallVectorStart.IsEqualTo(doorVectorStart))
                    {
                        Segment2D wallToDoor = GeometryFactory.CreateSegment2D(new Vector2D[] { wallVectorStart, doorVectorStart }, currentWall.Name);
                        newWallList.Add(wallToDoor);
                    }
                    if (!doorVectorEnd.IsEqualTo(wallVectorEnd))
                    {
                        Segment2D wallFromDoor = GeometryFactory.CreateSegment2D(new Vector2D[] { doorVectorEnd, wallVectorEnd }, currentWall.Name);
                        newWallList.Add(wallFromDoor);
                    }

                    wallsToRemove.Add(currentWall);
                    continue;
                }
                else
                {
                    continue;
                }
            }
            foreach (Segment2D wallToRemove in wallsToRemove)
            {
                allWalls.Remove(wallToRemove);
            }

            allWalls.AddRange(newWallList);
            return(allWalls);
        }
Пример #2
0
        public List <Segment2D> GetOuterBoundaryWall(List <Geometry2D> allWallsOfRoom)
        {
            foreach (Geometry2D currentWall in allWallsOfRoom)
            {
                if (currentWall.GetType() == typeof(Polygon2D))
                {
                    Polygon2D currentWallAsPolygon2D = currentWall as Polygon2D;

                    if (allWallsOfRoom.Count == 1)
                    {
                        OuterBoundaryPolygon = currentWallAsPolygon2D;
                    }
                    else
                    {
                        if (GeoAdditionals.Polygon2DContainsAllOtherObjects(currentWallAsPolygon2D, allWallsOfRoom))
                        {
                            OuterBoundaryPolygon = currentWallAsPolygon2D;
                        }
                    }
                }
            }

            return(GeometryFactory.DividePolygon2DintoSegment2D(OuterBoundaryPolygon));
        }
Пример #3
0
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(LANGUAGE_TAG_US);
        Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo(LANGUAGE_TAG_US);

        UIApplication uiApp = commandData.Application;
        UIDocument    uiDoc = commandData.Application.ActiveUIDocument;
        Document      doc   = commandData.Application.ActiveUIDocument.Document;

        var rom = new RevitObjectManager();
        var ogc = new ObjectToGeometryConverter();

        List <Level> allLevels = UserInteractionService.LetUserPickLevels(doc, rom);

        if (allLevels.Count == 0)
        {
            TaskDialog.Show("Plugin abort", "User did not select any levels, Plugin aborts.");
            return(Result.Cancelled);
        }

        List <Scenario> allScenarios = new List <Scenario>();
        List <Stairs>   allStairs    = rom.GetAllStairs(doc);

        foreach (Level level in allLevels)
        {
            GeometryFactory.Reset();
            ogc.Reset();

            List <Room> rooms = rom.GetAllRoomsFromLevel(level);

            if (!rom.RoomsOnCurrentLevelPlaced(rooms))
            {
                continue;
            }

            List <FamilyInstance> doors = rom.GetAllDoorsFromLevel(level);
            List <KeyValuePair <string, List <Stairs> > > stairs = rom.GetAllStairsFromLevel(uiDoc, allStairs, level);

            var originList           = new List <Polygon2D>();
            var intermediateList     = new List <Polygon2D>(); // unused... probably for stairs that pass through a level
            var destinationList      = new List <Polygon2D>();
            var gatheringLineList    = new List <Segment2D>();
            var wallList             = new List <Segment2D>();
            var solidList            = new List <Polygon2D>();
            var roomBoundaryPolygons = new List <Polygon2D>();

            // assemble list of all walls and the most outer boundary wall
            foreach (Room currentRoom in rooms)
            {
                if (currentRoom.Location != null)
                {
                    List <Geometry2D> allWallsOfRoom = ogc.GetWallsOfRoomAsGeometry2D(uiDoc, currentRoom);
                    wallList.AddRange(ogc.GetOuterBoundaryWall(allWallsOfRoom));
                    roomBoundaryPolygons.Add(ogc.OuterBoundaryPolygon);// also adds nulls... and duplicates?!
                    wallList.AddRange(ogc.GetObstacleWalls(allWallsOfRoom));
                    solidList.AddRange(ogc.GetObstacleSolids(allWallsOfRoom));
                }
            }

            foreach (var currentPair in stairs)
            {
                List <Polygon2D> allStairAreas = new List <Polygon2D>();

                if (currentPair.Key.Equals(RevitObjectManager.BASE_LEVEL_KEY))
                {
                    foreach (Stairs currentStairs in currentPair.Value)
                    {
                        Polygon2D stairArea = ogc.GetStairAreaPolygon(uiDoc, currentStairs, RevitObjectManager.BASE_LEVEL_KEY);

                        if (GeoAdditionals.ConvertedRoomsContainStairArea(roomBoundaryPolygons, stairArea))
                        {
                            allStairAreas.Add(stairArea);
                        }
                    }
                }
                else if (currentPair.Key.Equals(RevitObjectManager.TOP_LEVEL_KEY))
                {
                    foreach (Stairs currentStairs in currentPair.Value)
                    {
                        Polygon2D stairArea = ogc.GetStairAreaPolygon(uiDoc, currentStairs, RevitObjectManager.TOP_LEVEL_KEY);

                        if (GeoAdditionals.ConvertedRoomsContainStairArea(roomBoundaryPolygons, stairArea))
                        {
                            allStairAreas.Add(stairArea);
                        }
                    }
                }

                originList.AddRange(allStairAreas);
                destinationList.AddRange(allStairAreas);
            }

            List <Geometry2D> convertedDoors = ogc.CreateDoorSegments(uiDoc, doors);
            List <Segment2D>  doorSegments   = new List <Segment2D>();

            foreach (Geometry2D currentDoor in convertedDoors)
            {
                if (currentDoor.GetType() == typeof(Segment2D))
                {
                    doorSegments.Add((Segment2D)currentDoor);
                }
                else if (currentDoor.GetType() == typeof(Polygon2D))
                {
                    originList.Add((Polygon2D)currentDoor);
                    destinationList.Add((Polygon2D)currentDoor);
                }
            }

            wallList = ogc.RemoveDotWalls(wallList);
            wallList = ogc.CreateDoorOpenings(doorSegments, wallList);

            wallList        = ogc.SetCorrectWallNames(wallList);
            solidList       = ogc.SetCorrectPolygonNames(solidList, ObjectToGeometryConverter.SOLID_OBJECT_NAME);
            originList      = ogc.SetCorrectPolygonNames(originList, ObjectToGeometryConverter.ORIGIN_OBJECT_NAME);
            destinationList = ogc.SetCorrectPolygonNames(destinationList, ObjectToGeometryConverter.DESTINATION_OBJECT_NAME);

            double[] minCoords       = GeometryFactory.GetMinimumCoordinates();
            double[] maxCoords       = GeometryFactory.GetMaximumCoordinates();
            Scenario currentScenario = new Scenario(level.Name, minCoords, maxCoords, originList, intermediateList, gatheringLineList, destinationList, wallList, solidList);
            allScenarios.Add(currentScenario);
        }

        var converter       = new OutputModelConverter();
        var simulatorOutput = converter.ToSimulator(allScenarios);

        var saveFileService = new UserInteractionService();

        saveFileService.SaveSimulatorToXml(simulatorOutput);

        return(Result.Succeeded);
    }