Ejemplo n.º 1
0
        /// <summary>
        /// Calculates the path of egress from each desk instance to the escapeLocation and returns a list of EgressResult objects.
        /// </summary>
        /// <param name="deskInstances"> A list of Revit desk family instances.</param>
        /// <param name="escapeLocation"> The point where the exit is, typically from a door location.</param>
        /// <param name="view"> The view to perform the egress calculation.</param>
        /// <param name="maxEgressDistance"> The maximum distance which is permitted for escape.</param>
        public static List <EgressResult> GetResults(List <DynamoElement> deskInstances, ProtoPoint escapeLocation, DynamoView view, double maxEgressDistance)
        {
            double maxEgressDistanceInFt =
                UnitUtils.ConvertToInternalUnits(maxEgressDistance, DisplayUnitType.DUT_MILLIMETERS);

            Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            XYZ escapeLocationXyz = escapeLocation.ToXyz();

            List <EgressResult> egressResults = new List <EgressResult>();

            foreach (var deskInstance in deskInstances)
            {
                LocationPoint deskLocation = (LocationPoint)deskInstance.InternalElement.Location;

                PathOfTravel pathOfTravel = PathOfTravel.Create((View)view.InternalElement, deskLocation.Point, escapeLocationXyz);

                EgressResult egressResult = new EgressResult(deskInstance, pathOfTravel, maxEgressDistanceInFt);

                egressResults.Add(egressResult);
            }

            TransactionManager.Instance.TransactionTaskDone();

            return(egressResults);
        }
Ejemplo n.º 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            //Select first room
            Reference     selection     = uidoc.Selection.PickObject(ObjectType.Element); //Select Element 1
            ElementId     eleId         = selection.ElementId;
            LocationPoint eleLocPt      = doc.GetElement(eleId).Location as LocationPoint;
            XYZ           roomXyzPoint1 = eleLocPt.Point;

            //Select second room
            Reference     selection2    = uidoc.Selection.PickObject(ObjectType.Element); //Select Element 2
            ElementId     eleId2        = selection2.ElementId;
            LocationPoint eleLocPt2     = doc.GetElement(eleId2).Location as LocationPoint;
            XYZ           roomXyzPoint2 = eleLocPt2.Point;

            //Find shortest Path
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Find shortest Path !");

                PathOfTravel route = PathOfTravel.Create(doc.ActiveView, roomXyzPoint1, roomXyzPoint2);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = commandData.Application.ActiveUIDocument.Document;

            IList <Reference> selection1 = uidoc.Selection.PickObjects(ObjectType.Element);     //Select 1st list
            IList <XYZ>       roomsXyz1  = selection1                                           //Room 1,2 & 3
                                           .Select(r => doc.GetElement(r.ElementId).Location)
                                           .Cast <LocationPoint>()
                                           .Select(locPoint => locPoint.Point)
                                           .ToList();

            IList <Reference> selection2 = uidoc.Selection.PickObjects(ObjectType.Element);     //Select 2nd list
            IList <XYZ>       roomsXyz2  = selection2                                           //Room 4,6 & 8
                                           .Select(r => doc.GetElement(r.ElementId).Location)
                                           .Cast <LocationPoint>()
                                           .Select(locPoint => locPoint.Point)
                                           .ToList();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Find shortest Path !");

                //IList<PathOfTravel> routeMap = PathOfTravel.CreateMapped(doc.ActiveView, roomsXyz1, roomsXyz2);
                IList <PathOfTravel> routeMultiple = PathOfTravel.CreateMultiple(doc.ActiveView, roomsXyz1, roomsXyz2);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  Generates paths of travel from points in one room to many target locations using the slower (one-at-a-time) method.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="room"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        private static void GeneratePathsOfTravelForOneRoomManyDoors(Document doc, ViewPlan viewPlan, Room room, List <XYZ> endPoints, ResultsSummary resultsSummary)
        {
            List <XYZ> sourcePoints = GetRoomNearCornerPoints(room);

            resultsSummary.numSourcePoints += sourcePoints.Count;

            // generate paths

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();
                IList <PathOfTravelCalculationStatus> statuses;
                IList <PathOfTravel> pathsOfTravel = PathOfTravel.CreateMapped(viewPlan, sourcePoints, endPoints, out statuses);

                foreach (PathOfTravel pOT in pathsOfTravel)
                {
                    if (pOT == null)
                    {
                        resultsSummary.numFailures++;
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                }
                t.Commit();
            }
        }
Ejemplo n.º 5
0
        public void WayPointRemoveGet_ValidArgs()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                false);

            // Assert created PathOfTravel element is valid.
            Assert.NotNull(pathOfTravelOneToOne);
            Assert.AreEqual(1, pathOfTravelOneToOne.GetLength(0));
            Assert.NotNull(pathOfTravelOneToOne[0]);

            // Current PathOfTravel element.
            var pathOfTravel = pathOfTravelOneToOne[0];

            // Assert we can insert a way point at valid index
            pathOfTravel.InsertWayPoint(Point.ByCoordinates(50, 50, 0), 0);
            var listWayPointsOneElem = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsOneElem);
            Assert.AreEqual(1, listWayPointsOneElem.Count);
            Assert.NotNull(listWayPointsOneElem[0]);
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsOneElem[0].ToString());

            // Assert way point is removed
            pathOfTravel.RemoveWayPoint(0);
            var listWayPointsEmpty = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsEmpty);
            Assert.AreEqual(0, listWayPointsEmpty.Count);
        }
Ejemplo n.º 6
0
        public void WayPointInsertGet_ValidArgs()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                false);

            // Assert created PathOfTravel element is valid.
            Assert.NotNull(pathOfTravelOneToOne);
            Assert.AreEqual(1, pathOfTravelOneToOne.GetLength(0));
            Assert.NotNull(pathOfTravelOneToOne[0]);

            // Current PathOfTravel element.
            var pathOfTravel = pathOfTravelOneToOne[0];

            // Assert there is no way points on current PathOfTravel element.
            var listWayPointsEmpty = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsEmpty);
            Assert.AreEqual(0, listWayPointsEmpty.Count);

            // Assert only 0 index can be used to insert a way point.
            Assert.Throws(
                typeof(Autodesk.Revit.Exceptions.InvalidOperationException),
                () => pathOfTravel.InsertWayPoint(Point.ByCoordinates(50, 50, 0), -1));
            Assert.Throws(
                typeof(Autodesk.Revit.Exceptions.InvalidOperationException),
                () => pathOfTravel.InsertWayPoint(Point.ByCoordinates(50, 50, 0), 1));

            // Assert we can insert a way point at valid index
            pathOfTravel.InsertWayPoint(Point.ByCoordinates(50, 50, 0), 0);
            var listWayPointsOneElem = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsOneElem);
            Assert.AreEqual(1, listWayPointsOneElem.Count);
            Assert.NotNull(listWayPointsOneElem[0]);
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsOneElem[0].ToString());

            // Assert valid indices to insert way points are 0 and 1.
            Assert.Throws(
                typeof(Autodesk.Revit.Exceptions.InvalidOperationException),
                () => pathOfTravel.InsertWayPoint(Point.ByCoordinates(25, 25, 0), -1));
            Assert.Throws(
                typeof(Autodesk.Revit.Exceptions.InvalidOperationException),
                () => pathOfTravel.InsertWayPoint(Point.ByCoordinates(25, 25, 0), 2));

            // Assert way point is inserted at index 0.
            // inserting at index 1 is tested in WayPointSetGet_ValidArgs.
            pathOfTravel.InsertWayPoint(Point.ByCoordinates(25, 25, 0), 0);
            var listWayPointsTwoElems = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsTwoElems);
            Assert.AreEqual(2, listWayPointsTwoElems.Count);
            Assert.NotNull(listWayPointsTwoElems[0]);
            Assert.NotNull(listWayPointsTwoElems[1]);
            Assert.AreEqual("(25.000000000, 25.000000000, 0.000000000)", listWayPointsTwoElems[0].ToString());
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsTwoElems[1].ToString());
        }
Ejemplo n.º 7
0
 public void LongestOfShortestExitPaths_NullView()
 {
     Assert.Throws(
         typeof(System.ArgumentNullException),
         () => PathOfTravel.LongestOfShortestExitPaths(
             null,
             new Point[] { Point.ByCoordinates(0, 0, 0) }));
 }
Ejemplo n.º 8
0
 public void LongestOfShortestExitPaths_EmptyExitPointsArray()
 {
     Assert.Throws(
         typeof(System.ArgumentException),
         () => PathOfTravel.LongestOfShortestExitPaths(
             GetFloorPlan(),
             new Point[] { }));
 }
Ejemplo n.º 9
0
 public void LongestOfShortestExitPaths_NoRoomsInFloor()
 {
     Assert.Throws(
         typeof(System.ArgumentException),
         () => PathOfTravel.LongestOfShortestExitPaths(
             GetFloorPlan(),
             new Point[] { Point.ByCoordinates(0, 0, 0) }));
 }
Ejemplo n.º 10
0
 public void Create_DifferentPointCounts()
 {
     Assert.Throws(
         typeof(System.ArgumentException),
         () => PathOfTravel.ByFloorPlanPoints(
             GetFloorPlan(),
             new Point[] { },
             new Point[] { Point.ByCoordinates(100, 100, 0) },
             false));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Constructs a new EgressResult.
        /// </summary>
        internal EgressResult(DynamoElement instance, PathOfTravel pathOfTravel, double maxEgressDistance)
        {
            this.Instance = instance;

            double totalPathLength = 0.0;

            this.Path = new List <DynamoCurve>();
            foreach (Curve curve in pathOfTravel.GetCurves())
            {
                totalPathLength += curve.Length;
                this.Path.Add(curve.ToProtoType());
            }

            this.IsValid = totalPathLength < maxEgressDistance;
        }
Ejemplo n.º 12
0
        public void WayPointSetGet_ValidArgs()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                false);

            // Assert created PathOfTravel element is valid.
            Assert.NotNull(pathOfTravelOneToOne);
            Assert.AreEqual(1, pathOfTravelOneToOne.GetLength(0));
            Assert.NotNull(pathOfTravelOneToOne[0]);

            // Current PathOfTravel element.
            var pathOfTravel = pathOfTravelOneToOne[0];

            // Assert we can insert a way point at valid index
            pathOfTravel.InsertWayPoint(Point.ByCoordinates(50, 50, 0), 0);
            var listWayPointsOneElem = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsOneElem);
            Assert.AreEqual(1, listWayPointsOneElem.Count);
            Assert.NotNull(listWayPointsOneElem[0]);
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsOneElem[0].ToString());

            // Assert way point is inserted at index 1
            // inserting at index 0 is tested in WayPointInsertGet_ValidArgs.
            pathOfTravel.InsertWayPoint(Point.ByCoordinates(75, 75, 0), 1);
            var listWayPointsTwoElems = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsTwoElems);
            Assert.AreEqual(2, listWayPointsTwoElems.Count);
            Assert.NotNull(listWayPointsTwoElems[0]);
            Assert.NotNull(listWayPointsTwoElems[1]);
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsTwoElems[0].ToString());
            Assert.AreEqual("(75.000000000, 75.000000000, 0.000000000)", listWayPointsTwoElems[1].ToString());

            //Assert we can modify a way point
            pathOfTravel.SetWayPoint(Point.ByCoordinates(90, 90, 0), 1);
            var listWayPointsTwoElemsAfterSet = pathOfTravel.GetWayPoints();

            Assert.NotNull(listWayPointsTwoElemsAfterSet);
            Assert.AreEqual(2, listWayPointsTwoElemsAfterSet.Count);
            Assert.NotNull(listWayPointsTwoElemsAfterSet[0]);
            Assert.NotNull(listWayPointsTwoElemsAfterSet[1]);
            Assert.AreEqual("(50.000000000, 50.000000000, 0.000000000)", listWayPointsTwoElemsAfterSet[0].ToString());
            Assert.AreEqual("(90.000000000, 90.000000000, 0.000000000)", listWayPointsTwoElemsAfterSet[1].ToString());
        }
Ejemplo n.º 13
0
        public void Create_InvalidEndPoint()
        {
            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    GetFloorPlan(),
                    new Point[] { Point.ByCoordinates(0, 0, 0) },
                    null,                                            // null end point array
                    false));

            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    GetFloorPlan(),
                    new Point[] { Point.ByCoordinates(0, 0, 0) },
                    null,                                            // null end point array
                    true));
        }
Ejemplo n.º 14
0
        public void Create_NullStartPointArray()
        {
            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    GetFloorPlan(),                                  // null start point array
                    null,
                    new Point[] { Point.ByCoordinates(100, 100, 0) },
                    false));

            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    GetFloorPlan(),                                  // null start point array
                    null,
                    new Point[] { Point.ByCoordinates(100, 100, 0) },
                    true));
        }
Ejemplo n.º 15
0
        public void LongestOfShortestExitPaths_ValidArgOneReturn()
        {
            Autodesk.Revit.DB.ViewPlan defaultView = (Autodesk.Revit.DB.ViewPlan)GetDefaultViewPlan();

            var longestOfShortestPaths = PathOfTravel.LongestOfShortestExitPaths(
                defaultView.ToDSType(true) as FloorPlanView,
                new Point[] { Point.ByCoordinates(23.349, 2.508, 3.625),
                              Point.ByCoordinates(12.892, 7.285, 3.625) });

            Assert.NotNull(longestOfShortestPaths);
            Assert.AreEqual(1, longestOfShortestPaths.Length);
            Assert.NotNull(longestOfShortestPaths[0]);

            int boudingBoxTest = longestOfShortestPaths[0].BoundingBox.ToString().CompareTo(
                "BoundingBox(MinPoint = Point(X = 23.349, Y = -46.619, Z = 0.000), MaxPoint = Point(X = 62.349, Y = 2.508, Z = 0.000))");

            Assert.AreEqual(0, boudingBoxTest);
        }
Ejemplo n.º 16
0
        public void Create_NullView()
        {
            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    null,                                            // null view
                    new Point[] { Point.ByCoordinates(0, 0, 0) },
                    new Point[] { Point.ByCoordinates(100, 100, 0) },
                    false));

            Assert.Throws(
                typeof(System.ArgumentNullException),
                () => PathOfTravel.ByFloorPlanPoints(
                    null,                                            // null view
                    new Point[] { Point.ByCoordinates(0, 0, 0) },
                    new Point[] { Point.ByCoordinates(100, 100, 0) },
                    true));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Generates paths of travel from the center points of the room to a single door using the many to many approach.   Does not collect and display results.
        /// </summary>
        private void CreatePathsOfTravelRoomCenterpointsToSingleDoor(UIDocument uiDoc)
        {
            Document  doc      = uiDoc.Document;
            ViewPlan  viewPlan = uiDoc.ActiveView as ViewPlan;
            ElementId levelId  = viewPlan.GenLevel.Id;

            // select exit door
            Reference reference   = uiDoc.Selection.PickObject(ObjectType.Element, new DoorSelectionFilter(), "Select a target door");
            Instance  doorElement = doc.GetElement(reference) as Instance;
            Transform trf         = doorElement.GetTransform();
            XYZ       endPoint    = trf.Origin;

            // find all rooms
            FilteredElementCollector fec = new FilteredElementCollector(doc);

            fec.WherePasses(new Autodesk.Revit.DB.Architecture.RoomFilter());

            List <XYZ> startPoints = new List <XYZ>();

            foreach (Room room in fec.Cast <Room>().Where <Room>(rm => rm.Level.Id == levelId))
            {
                LocationPoint location = room.Location as LocationPoint;
                if (location == null)
                {
                    continue;
                }
                XYZ roomPoint = location.Point;
                startPoints.Add(roomPoint);
            }

            // generate paths
            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();
                IList <PathOfTravelCalculationStatus> statuses;
                PathOfTravel.CreateMapped(viewPlan, startPoints, new List <XYZ> {
                    endPoint
                }, out statuses);
                t.Commit();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Wraps all calls to PathOfTravel.Create() with multiple start/ends.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="viewPlan"></param>
        /// <param name="startPoints"></param>
        /// <param name="endPoints"></param>
        /// <param name="resultsSummary"></param>
        /// <param name="mapAllStartsToAllEnds"></param>
        private static void GeneratePathsOfTravel(Document doc, ViewPlan viewPlan, List <XYZ> startPoints, List <XYZ> endPoints, ResultsSummary resultsSummary, bool mapAllStartsToAllEnds)
        {
            // Performance monitoring
            Stopwatch stopwatch = Stopwatch.StartNew();

            using (Transaction t = new Transaction(doc, "Generate paths of travel"))
            {
                t.Start();

                IList <PathOfTravelCalculationStatus> statuses;
                IList <PathOfTravel> pathsOfTravel;
                if (mapAllStartsToAllEnds)
                {
                    pathsOfTravel = PathOfTravel.CreateMapped(viewPlan, startPoints, endPoints, out statuses);
                }
                else
                {
                    pathsOfTravel = PathOfTravel.CreateMultiple(viewPlan, startPoints, endPoints, out statuses);
                }

                int i = 0;

                foreach (PathOfTravel pathOfTravel in pathsOfTravel)
                {
                    if (pathOfTravel == null)
                    {
                        resultsSummary.numFailures++;
                        resultsSummary.failuresFound.Add(statuses[i]);
                    }
                    else
                    {
                        resultsSummary.numSuccesses++;
                    }
                    i++;
                }

                t.Commit();
            }
            stopwatch.Stop();
            resultsSummary.elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
        }
Ejemplo n.º 19
0
        public void Create_ValidArgs()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                false);

            Assert.NotNull(pathOfTravelOneToOne);
            Assert.Equals(pathOfTravelOneToOne.GetLength(0), 1);
            Assert.NotNull(pathOfTravelOneToOne[0]);

            var pathOfTravelManyToMany = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                true);

            Assert.NotNull(pathOfTravelManyToMany);
            Assert.Equals(pathOfTravelManyToMany.GetLength(0), 1);
            Assert.NotNull(pathOfTravelManyToMany[0]);
        }
Ejemplo n.º 20
0
        public void Create_PointsTooClose()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(double.Epsilon / 2, 0, 0) },
                false);

            Assert.NotNull(pathOfTravelOneToOne);
            Assert.Equals(pathOfTravelOneToOne.GetLength(0), 1);
            Assert.Null(pathOfTravelOneToOne[0]);

            var pathOfTravelManyToMany = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(double.Epsilon / 2, 0, 0) },
                true);

            Assert.NotNull(pathOfTravelManyToMany);
            Assert.Equals(pathOfTravelManyToMany.GetLength(0), 1);
            Assert.Null(pathOfTravelManyToMany[0]);
        }
Ejemplo n.º 21
0
        public void Create_PointsIdentical()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                false);

            Assert.NotNull(pathOfTravelOneToOne);
            Assert.AreEqual(1, pathOfTravelOneToOne.GetLength(0));
            Assert.Null(pathOfTravelOneToOne[0]);

            var pathOfTravelManyToMany = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                true);

            Assert.NotNull(pathOfTravelManyToMany);
            Assert.AreEqual(1, pathOfTravelManyToMany.GetLength(0));
            Assert.Null(pathOfTravelManyToMany[0]);
        }
Ejemplo n.º 22
0
        public void Create_ValidArgs()
        {
            var pathOfTravelOneToOne = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                false);

            Assert.NotNull(pathOfTravelOneToOne);
            // First argument in AreEqual assert is used as expected value in the assertion failure message.
            Assert.AreEqual(1, pathOfTravelOneToOne.GetLength(0));
            Assert.NotNull(pathOfTravelOneToOne[0]);

            var pathOfTravelManyToMany = PathOfTravel.ByFloorPlanPoints(
                GetFloorPlan(),
                new Point[] { Point.ByCoordinates(0, 0, 0) },
                new Point[] { Point.ByCoordinates(100, 100, 0) },
                true);

            Assert.NotNull(pathOfTravelManyToMany);
            Assert.AreEqual(1, pathOfTravelManyToMany.GetLength(0));
            Assert.NotNull(pathOfTravelManyToMany[0]);
        }
Ejemplo n.º 23
0
        public void LongestOfShortestExitPaths_ValidArgTwoReturns()
        {
            Autodesk.Revit.DB.ViewPlan defaultView = (Autodesk.Revit.DB.ViewPlan)GetDefaultViewPlan();

            var longestOfShortestPaths = PathOfTravel.LongestOfShortestExitPaths(
                defaultView.ToDSType(true) as FloorPlanView,
                new Point[] { Point.ByCoordinates(12.892, -7.285, 3.625),
                              Point.ByCoordinates(33.806, -7.285, 3.625) });

            Assert.NotNull(longestOfShortestPaths);
            Assert.AreEqual(2, longestOfShortestPaths.Length);
            Assert.NotNull(longestOfShortestPaths[0]);
            Assert.NotNull(longestOfShortestPaths[1]);

            int boudingBoxTest1 = longestOfShortestPaths[0].BoundingBox.ToString().CompareTo(
                "BoundingBox(MinPoint = Point(X = 33.806, Y = -7.285, Z = 0.000), MaxPoint = Point(X = 62.349, Y = 31.965, Z = 0.000))");

            int boudingBoxTest2 = longestOfShortestPaths[1].BoundingBox.ToString().CompareTo(
                "BoundingBox(MinPoint = Point(X = -16.235, Y = -7.285, Z = 0.000), MaxPoint = Point(X = 12.892, Y = 31.965, Z = 0.000))");

            Assert.AreEqual(0, boudingBoxTest1);
            Assert.AreEqual(0, boudingBoxTest2);
        }
Ejemplo n.º 24
0
        public KeyValuePair <List <ElementId>, List <double> > Graph(Document doc, IList <ElementId> RoomForbid)
        {
            var levelid = ViewLevel(doc);
            var rooms   = GetRoomsOnLevel(doc, levelid);
            var doors   = GetAllDoors(doc, levelid);
            var exits   = GetExits(doc);
            var RoomIDs = new List <ElementId>();
            var DoorIDs = new List <ElementId>();
            var AllIDs  = new List <ElementId>();

            foreach (ElementId d in doors)
            {
                DoorIDs.Add(d);
                AllIDs.Add(d);
            }
            foreach (Room r in rooms)
            {
                RoomIDs.Add(r.Id);
                AllIDs.Add(r.Id);
            }


            var mat_dim = RoomIDs.Count + DoorIDs.Count;

            int[,] mat = new int[100, 100];
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    mat[i, j] = 0;
                }
            }

            foreach (ElementId id in DoorIDs)
            {
                int            count   = 0;
                Element        door    = doc.GetElement(id);
                FamilyInstance doorfam = door as FamilyInstance;
                Room           temp1   = doorfam.FromRoom;
                Room           temp2   = doorfam.ToRoom;
                int            offset  = DoorIDs.Count;
                int            dindex  = DoorIDs.FindIndex(a => a.IntegerValue == id.IntegerValue);
                foreach (ElementId rid in RoomIDs)
                {
                    int rindex = RoomIDs.FindIndex(a => a.IntegerValue == rid.IntegerValue);
                    if (temp1 != null && temp1.Id == rid)
                    {
                        mat[dindex, offset + rindex] = 1; count++;
                        continue;
                    }
                    if (temp2 != null && temp2.Id == rid)
                    {
                        mat[dindex, offset + rindex] = 1; count++;
                        continue;
                    }
                }
            }


            var RoomLocs   = new List <XYZ>();
            var DoorLocs   = new List <XYZ>();
            var AllLocs    = new List <XYZ>();
            var LocsForbid = new List <XYZ>();

            foreach (ElementId id in DoorIDs)
            {
                Element       r   = doc.GetElement(id);
                LocationPoint loc = r.Location as LocationPoint;
                XYZ           xyz = loc.Point;
                DoorLocs.Add(xyz);
                AllLocs.Add(xyz);
            }
            foreach (ElementId id in RoomIDs)
            {
                Element       r   = doc.GetElement(id);
                LocationPoint loc = r.Location as LocationPoint;
                XYZ           xyz = loc.Point;
                RoomLocs.Add(xyz);
                AllLocs.Add(xyz);
                if (RoomForbid.Contains(id))
                {
                    LocsForbid.Add(xyz);
                }
            }

            double[,] ajm = new double[100, 100];
            for (int i = 0; i < mat_dim; i++)
            {
                for (int j = 0; j < mat_dim; j++)
                {
                    ajm[i, j] = -1;
                }
            }
            IList <Curve>[,] pathMap = new IList <Curve> [mat_dim, mat_dim];
            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("CAL");
                int  offset = DoorIDs.Count;
                View view   = doc.ActiveView;
                for (int i = 0; i < mat_dim; i++)
                {
                    for (int j = 0; j < mat_dim; j++)
                    {
                        if (mat[i, j] == 0)
                        {
                            continue;
                        }
                        if (LocsForbid.Contains(RoomLocs[j - offset]))
                        {
                            continue;
                        }
                        PathOfTravel p = PathOfTravel.Create(view, DoorLocs[i], RoomLocs[j - offset]);
                        if (p == null)
                        {
                            continue;
                        }
                        var crs = p.GetCurves();
                        pathMap[i, j] = crs;
                        ajm[i, j]     = calDis(crs);
                        ajm[j, i]     = ajm[i, j];
                    }
                }
                trans.Commit();
            }

            //for (int i = DoorIDs.Count; i < mat_dim; i++) {
            //    int tmp = 0;
            //    for (int j = 0; j < mat_dim; j++)
            //        if (ajm[i, j] > 0) tmp++;
            //    if(tmp==0) TaskDialog.Show("Revit", RoomIDs[i-DoorIDs.Count].ToString());
            //}

            foreach (ElementId fid in RoomForbid)
            {
                Element tmp = doc.GetElement(fid);
                if (!tmp.Category.Name.ToLower().Contains("room"))
                {
                    continue;
                }
                int index = AllIDs.FindIndex(a => a.IntegerValue == fid.IntegerValue);
                for (int i = 0; i < AllIDs.Count; i++)
                {
                    ajm[index, i] = -1;
                    ajm[i, index] = -1;
                }
                TaskDialog.Show("revit", "delete a room");
            }
            for (int i = 0; i < AllIDs.Count; i++)
            {
                for (int j = 0; j < AllIDs.Count; j++)
                {
                    if (i == j)
                    {
                        ajm[i, j] = 0;
                        continue;
                    }
                    if (ajm[i, j] < 0)
                    {
                        ajm[i, j] = MAX_NUM;
                    }
                }
            }
            //string ttt = "";
            //for (int i = 0; i < AllIDs.Count; i++) {
            //    for (int j = 0; j < AllIDs.Count; j++)
            //        ttt += ajm[i, j].ToString() + "  ";

            //    ttt += "\n";
            //}
            //TaskDialog.Show("revit", ttt);
            var dis       = GetFloyd(ajm, mat_dim);
            var final_rel = new List <double>();
            var final_des = new List <int>();

            foreach (ElementId rid in RoomIDs)
            {
                double len      = MAX_NUM;
                int    des_node = -1;
                int    x        = AllIDs.FindIndex(a => a.IntegerValue == rid.IntegerValue);
                foreach (ElementId did in exits)
                {
                    int    y       = AllIDs.FindIndex(a => a.IntegerValue == did.IntegerValue);
                    double tmp_len = dis[x, y].length;
                    if (len >= tmp_len)
                    {
                        len      = tmp_len;
                        des_node = y;
                    }
                }
                final_rel.Add(len);
                final_des.Add(des_node);
            }

            var Final_path = new List <List <int> >();

            for (int i = 0; i < RoomIDs.Count; i++)
            {
                var rid = RoomIDs[i];
                if (final_rel[i] > MAX_NUM - 1)
                {
                    Final_path.Add(null);
                    continue;
                }
                var nodes = new List <int>();
                var dst   = final_des[i];
                int x     = AllIDs.FindIndex(a => a.IntegerValue == rid.IntegerValue);
                nodes.Add(dst);
                int pre = dis[x, dst].pre;
                while (true)
                {
                    nodes.Add(pre);
                    if (pre == x)
                    {
                        break;
                    }
                    pre = dis[x, pre].pre;
                }
                nodes.Reverse();
                Final_path.Add(nodes);
            }

            return(new KeyValuePair <List <ElementId>, List <double> >(RoomIDs, final_rel));
        }
Ejemplo n.º 25
0
        public KeyValuePair <List <ElementId>, List <double> > TravelDis(Document doc, ICollection <ElementId> selectedIds, List <ElementId> RoomsForbid) //distances of all rooms on current level to nearest exit
        {
            View currentView = doc.ActiveView;

            //door location
            var doors = new List <ElementId>();

            doors = GetExits(doc);
            var doors_loc = new List <XYZ>();

            foreach (ElementId id in doors)
            {
                Element       door = doc.GetElement(id);
                LocationPoint loc  = door.Location as LocationPoint;
                XYZ           xyz  = loc.Point;
                doors_loc.Add(xyz);
            }
            //room location
            var levelid   = ViewLevel(doc);
            var rooms     = GetRoomsOnLevel(doc, levelid);
            var final_rel = new List <double>();
            var rooms_loc = CenterOfRoom(doc, rooms);

            //TaskDialog.Show("Revit", doors_loc.Count.ToString());
            //TaskDialog.Show("Revit", rooms_loc.Count.ToString());
            var Exit2Door = new List <XYZ>();

            using (TransactionGroup transGroup = new TransactionGroup(doc))
            {
                transGroup.Start("group start");
                using (Transaction trans_del = new Transaction(doc))
                {
                    trans_del.Start("Del");
                    foreach (ElementId id in RoomsForbid)
                    {
                        Element temp = doc.GetElement(id);
                        DeleteDoorsOfRoom(doc, id);
                    }
                    trans_del.Commit();
                }
                using (Transaction trans = new Transaction(doc))
                {
                    if (trans.Start("Path") == TransactionStatus.Started)
                    {
                        //PathOfTravel.CreateMapped(currentView, rooms_loc, doors_loc);

                        //try to find the shortest path to the exits(one of)
                        //var ig = new List<ElementId>();
                        var settings = RouteAnalysisSettings.GetRouteAnalysisSettings(doc);
                        //foreach (ElementId id in selectedIds)
                        //{
                        //    Element temp = doc.GetElement(id);
                        //    ig.Add(temp.Category.Id);
                        //}
                        settings.SetIgnoredCategoryIds(selectedIds);
                        foreach (XYZ r in rooms_loc)
                        {
                            double temp_len = 10000000;
                            XYZ    temp_loc = null;
                            int    cnt      = 0;
                            foreach (XYZ d in doors_loc)
                            {
                                PathOfTravel path = PathOfTravel.Create(currentView, r, d);
                                if (path == null)
                                {
                                    continue;
                                }
                                IList <Curve> p = path.GetCurves();
                                if (temp_len >= calDis(p))
                                {
                                    temp_loc = d;
                                    temp_len = calDis(p);
                                }
                            }
                            Exit2Door.Add(temp_loc);
                        }
                        trans.RollBack();

                        //TaskDialog taskdialog = new TaskDialog("Revit");
                        //taskdialog.MainContent = "Click [OK] to commot and click [cancel] to roll back";
                        //TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel;
                        //taskdialog.CommonButtons = buttons;
                        //if (TaskDialogResult.Ok == taskdialog.Show())
                        //{
                        //    if (TransactionStatus.Committed != trans.Commit()) {
                        //        TaskDialog.Show("Fail", "Trans can not be committed");
                        //    }
                        //}
                        //else {
                        //    trans.RollBack();
                        //}
                    }
                }

                var RoomsPoint = rooms_loc;

                using (Transaction trans2 = new Transaction(doc))
                {
                    if (trans2.Start("Path_final") == TransactionStatus.Started)
                    {
                        var settings = RouteAnalysisSettings.GetRouteAnalysisSettings(doc);

                        settings.SetIgnoredCategoryIds(selectedIds);
                        for (int i = 0; i < RoomsPoint.Count; i++)
                        {
                            XYZ    d         = Exit2Door[i];
                            XYZ    r         = RoomsPoint[i];
                            Room   temp_room = doc.GetRoomAtPoint(r);
                            double halfDia   = calHalfDia(temp_room);
                            if (r == null || d == null)
                            {
                                final_rel.Add(MAX_NUM);
                                continue;
                            }
                            ;
                            IList <Curve> path = PathOfTravel.Create(currentView, r, d).GetCurves();
                            final_rel.Add(calDis(path));
                        }
                        trans2.Commit();
                    }
                }
                transGroup.Assimilate();
            }
            var allRoomName = new List <ElementId>();

            foreach (Room r in rooms)
            {
                allRoomName.Add(r.Id);
            }
            return(new KeyValuePair <List <ElementId>, List <double> >(allRoomName, final_rel));
        }
Ejemplo n.º 26
0
        public IList <XYZ> CalPointOfRooms(Document doc, IEnumerable <Room> rooms, List <XYZ> Exit2Door, ICollection <ElementId> eleIg)
        {
            var rel = new List <XYZ>();

            using (Transaction trans = new Transaction(doc))
            {
                if (trans.Start("Path") == TransactionStatus.Started)
                {
                    int count    = 0;
                    var settings = RouteAnalysisSettings.GetRouteAnalysisSettings(doc);
                    settings.SetIgnoredCategoryIds(eleIg);
                    foreach (Room room in rooms)
                    {
                        var            exit      = Exit2Door[count];
                        BoundingBoxXYZ box       = room.get_BoundingBox(null);
                        Transform      trf       = box.Transform;
                        XYZ            min_xyz   = box.Min;
                        XYZ            max_xyz   = box.Max;
                        XYZ            minInCoor = trf.OfPoint(min_xyz);
                        XYZ            maxInCoor = trf.OfPoint(max_xyz);
                        List <XYZ>     temp      = new List <XYZ>();
                        temp.Add(new XYZ(minInCoor.X, maxInCoor.Y, minInCoor.Z));
                        temp.Add(new XYZ(minInCoor.Y, maxInCoor.X, minInCoor.Z));
                        temp.Add(new XYZ(maxInCoor.X, minInCoor.Y, minInCoor.Z));
                        temp.Add(new XYZ(maxInCoor.Y, minInCoor.X, minInCoor.Z));

                        XYZ    final     = null;
                        double final_dis = MAX_NUM;
                        foreach (XYZ r in temp)
                        {
                            if (!room.IsPointInRoom(r))
                            {
                                continue;
                            }
                            PathOfTravel path = PathOfTravel.Create(doc.ActiveView, r, exit);
                            if (path == null)
                            {
                                continue;
                            }
                            double dis = calDis(path.GetCurves());
                            if (dis < final_dis)
                            {
                                final_dis = dis;
                                final     = r;
                            }
                        }
                        if (final == null)
                        {
                            LocationPoint loc = room.Location as LocationPoint;
                            XYZ           xyz = loc.Point;
                            rel.Add(xyz);
                        }
                        else
                        {
                            rel.Add(final);
                        }
                    }
                    trans.RollBack();
                }
            }

            //foreach (Room r in rooms)
            //{
            //    LocationPoint loc = r.Location as LocationPoint;
            //    XYZ xyz = loc.Point;
            //    rel.Add(xyz);
            //}
            return(rel);
        }