Ejemplo n.º 1
0
        private void makeEdge(Node n1, Node n2)
        {
            string tmp1 = n1.Id + "-" + n2.Id;
            string tmp2 = n2.Id + "-" + n1.Id;

            if (_edgeDictionary.ContainsKey(tmp1))
            {
                return;                                    // already exists
            }
            if (_edgeDictionary.ContainsKey(tmp2))
            {
                return;
            }

            LifeSaver.Models.Edge edge =
                new Models.Edge()
            {
                End1 = n1, End2 = n2
            };
            edge.Distance = n1.Location.DistanceTo(n2.Location);

            _edgeDictionary.Add(tmp1, edge);
            _edgeDictionary.Add(tmp2, edge);
            n1.Neighbors.Add(edge);
            n2.Neighbors.Add(edge);

            _allEdges.Add(edge);
        }
Ejemplo n.º 2
0
        private Dictionary <ElementId, RoomWithTransitLines> getRoomsWithTransitLines()
        {
            Dictionary <ElementId, RoomWithTransitLines> rooms = new Dictionary <ElementId, RoomWithTransitLines>();
            FilteredElementCollector coll = null;

            if (_view != null)
            {
                coll = new FilteredElementCollector(_doc);
            }
            else
            {
                coll = new FilteredElementCollector(_doc, _view.Id);
            }

            coll.OfCategory(BuiltInCategory.OST_Lines).OfClass(typeof(CurveElement)).WhereElementIsNotElementType();

            List <CurveElement> curves = coll.Cast <CurveElement>().Where(c => c.CurveElementType == CurveElementType.ModelCurve).ToList();

            curves = curves.Where(c => (c.LineStyle != null) && (c.LineStyle.Name.ToUpper() == "TRANSITLINE")).ToList();

            if (curves.Count == 0)
            {
                return(rooms);
            }


            foreach (ModelCurve mc in curves)
            {
                XYZ end1 = mc.GeometryCurve.GetEndPoint(0);
                XYZ end2 = mc.GeometryCurve.GetEndPoint(1);

                Room r1 = _doc.GetRoomAtPoint(end1, _phase);
                Room r2 = _doc.GetRoomAtPoint(end2, _phase);

                if ((r1 == null) || (r2 == null))
                {
                    throw new AnalysisException("The Transit Line Id: " + mc.Id.IntegerValue + " is not entirely in a room in phase " + _phase.Name)
                          {
                              Element = mc.Id
                          }
                }
                ;

                if ((r1.Id != r2.Id))
                {
                    throw new AnalysisException("The Transit Line Id:  " + mc.Id.IntegerValue + " is not entirely in the same room in phase " + _phase.Name)
                          {
                              Element = mc.Id
                          }
                }
                ;

                // see if it already exists or not...
                if (rooms.ContainsKey(r1.Id) == false)
                {
                    rooms.Add(r1.Id, new RoomWithTransitLines(r1));
                }

                Node node1 = new Node()
                {
                    LevelId  = r1.Id,
                    Location = end1,
                    NodeType = Node.NodeTypeEnum.TransitPoint,
                    RevitId  = mc.Id,
                    RoomId   = r1.Id
                };
                Node node2 = new Node()
                {
                    LevelId  = r2.Id,
                    Location = end2,
                    NodeType = Node.NodeTypeEnum.TransitPoint,
                    RevitId  = mc.Id,
                    RoomId   = r2.Id
                };
                addNode(node1);
                addNode(node2);

                rooms[r1.Id].Lines.Add(new TransitLine()
                {
                    Curve   = mc.GeometryCurve,
                    RevitId = mc.Id,
                    RoomId  = r1.Id,
                    End1    = node1,
                    End2    = node2
                });

                // make an edge as well...

                Models.Edge edge = new Models.Edge()
                {
                    End1 = node1, End2 = node2
                };

                _edgeDictionary.Add(node1.Id + "-" + node2.Id, edge);
                _edgeDictionary.Add(node2.Id + "-" + node1.Id, edge);
                _allEdges.Add(edge);
            }

            return(rooms);
        }