|
@@ -1,19 +1,51 @@
|
|
|
"""Graph Model.
|
|
|
-
|
|
|
"""
|
|
|
from enum import Enum
|
|
|
from systemrelation import graph_model
|
|
|
from systemrelation import systemdatautils
|
|
|
from systemrelation import systemutils
|
|
|
+from systemrelation import revit_const
|
|
|
+
|
|
|
+class SystemVertex:
|
|
|
+ """Graph Vertex.
|
|
|
+ """
|
|
|
+ vertex_type = 0
|
|
|
+
|
|
|
+ def __init__(self,parent, connector,system_data):
|
|
|
+ self.connector=connector
|
|
|
+ self.system_data = system_data
|
|
|
+ self.parent= parent
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ return str(systemutils.get_specify_type_parent(self,FloorGraph).model.floor_name)+':'+str(self.system_data.source_id)
|
|
|
+
|
|
|
+ def __eq__(self, other):
|
|
|
+ return self.system_data.source_id==other.system_data.source_id
|
|
|
|
|
|
+ def __hash__(self):
|
|
|
+ return hash(self.system_data.source_id)
|
|
|
+
|
|
|
+ def is_open_vertical_pipe(self):
|
|
|
+ '''
|
|
|
+ Connector to other floor
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ if (len(self.connector.connect_id_json)==0):
|
|
|
+ if( self.connector.belong_type in revit_const.MEPCURVE):
|
|
|
+ return True
|
|
|
+ return False
|
|
|
|
|
|
class SystemEdge:
|
|
|
"""Graph Edge."""
|
|
|
# edge data.contain all edge element
|
|
|
flow_direction = 0
|
|
|
|
|
|
- def __init__(self, system_data):
|
|
|
+ def __init__(self,parent, system_data):
|
|
|
self.system_data = system_data
|
|
|
+ self.parent = parent
|
|
|
+
|
|
|
+ def get_vertexs(self):
|
|
|
+ return [self.start_vertex,self.end_vertex]
|
|
|
# @property
|
|
|
# def start_vertex(self):
|
|
|
# return self.start_vertex
|
|
@@ -23,18 +55,6 @@ class SystemEdge:
|
|
|
# return self.end_vertex
|
|
|
|
|
|
|
|
|
-class SystemVertex:
|
|
|
- """Graph Vertex.
|
|
|
- """
|
|
|
- vertex_type = 0
|
|
|
-
|
|
|
- def __init__(self, system_data):
|
|
|
- self.system_data = system_data
|
|
|
-
|
|
|
- def __str__(self):
|
|
|
- return str(self.system_data.source_id)
|
|
|
-
|
|
|
-
|
|
|
class SystemGraph:
|
|
|
"""System Graph
|
|
|
"""
|
|
@@ -43,32 +63,51 @@ class SystemGraph:
|
|
|
# system type Name
|
|
|
system_name = ""
|
|
|
|
|
|
- def __init__(self):
|
|
|
+ def __init__(self,parent):
|
|
|
self.system_edges = []
|
|
|
+ self.parent=parent
|
|
|
|
|
|
def add_edge(self, c1, c2, elements):
|
|
|
- edge = SystemEdge(elements)
|
|
|
- edge.start_vertex = SystemVertex(elements[0])
|
|
|
- edge.end_vertex = SystemVertex(elements[-1])
|
|
|
+ """
|
|
|
+ Create edge and add to system_edges list
|
|
|
+ :param c1:
|
|
|
+ :param c2:
|
|
|
+ :param elements:
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ edge = SystemEdge(self,elements)
|
|
|
+ edge.start_vertex = SystemVertex(edge,c1,elements[0])
|
|
|
+ edge.end_vertex = SystemVertex(edge,c2,elements[-1])
|
|
|
self.system_edges.append(edge)
|
|
|
return edge
|
|
|
|
|
|
+ def get_open_vertical_pipes(self):
|
|
|
+ """
|
|
|
+ Get all open vertical pipe Vertex
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ open_pipes=[]
|
|
|
+ for edge in self.system_edges:
|
|
|
+ for vertex in edge.get_vertexs():
|
|
|
+ if vertex.is_open_vertical_pipe():
|
|
|
+ open_pipes.append(vertex)
|
|
|
+ return open_pipes
|
|
|
+
|
|
|
|
|
|
class FloorGraph:
|
|
|
"""FLoor Graph.
|
|
|
May contain one or more SystemGraph.
|
|
|
"""
|
|
|
|
|
|
- def __init__(self, project_id,model_id, system_name, domain):
|
|
|
- self.project_id=project_id
|
|
|
- self.model_id = model_id
|
|
|
+ def __init__(self,model, system_name, domain):
|
|
|
+ self.model=model;
|
|
|
self.system_name = system_name
|
|
|
self.domain = domain
|
|
|
- floor_connectors = systemdatautils.get_connectors_data(model_id, system_name, domain)
|
|
|
+ floor_connectors = systemdatautils.get_connectors_data(self.model.file_id, system_name, domain)
|
|
|
floor_connectors = systemutils.sort_connectors(floor_connectors)
|
|
|
floor_connectors = list(map(systemutils.add_attr_is_used, floor_connectors))
|
|
|
self.connector_data = (floor_connectors)
|
|
|
- self.element_data = systemutils.list_to_dict(systemdatautils.get_element_data(model_id))
|
|
|
+ self.element_data = systemutils.list_to_dict(systemdatautils.get_element_data(self.model.file_id))
|
|
|
self.system_graphs = []
|
|
|
|
|
|
def get_floor_graphs(self):
|
|
@@ -76,7 +115,7 @@ class FloorGraph:
|
|
|
system_name,domain
|
|
|
"""
|
|
|
for connector in self.connector_data:
|
|
|
- system_graph = graph_model.SystemGraph()
|
|
|
+ system_graph = graph_model.SystemGraph(self)
|
|
|
graph_next_connectors = [connector]
|
|
|
# dept-first
|
|
|
for connector in graph_next_connectors:
|
|
@@ -96,7 +135,7 @@ class FloorGraph:
|
|
|
if (connector.is_used):
|
|
|
return system_edge
|
|
|
try:
|
|
|
- #Add other side to be Spreaded
|
|
|
+ #Add other side to be spreaded
|
|
|
graph_next_connectors.extend(self.get_other_connectors(connector))
|
|
|
edge_elements = [self.get_element(connector.belong)]
|
|
|
current_connector = connector
|
|
@@ -171,6 +210,57 @@ class FloorGraph:
|
|
|
"""
|
|
|
return self.element_data[element_id]
|
|
|
|
|
|
+class GroupedSystemGraph:
|
|
|
+ '''
|
|
|
+ Systemgraph be connected via vertical pipe
|
|
|
+ May contain more system.Different floor;
|
|
|
+ '''
|
|
|
+ def __init__(self, systemgraph):
|
|
|
+ self.systemgraphs=[systemgraph]
|
|
|
+ self.connectedges=[]
|
|
|
+ def add_system(self,systemgraph):
|
|
|
+ '''
|
|
|
+ Add system into groupsystem
|
|
|
+ :param systemgraph:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ self.systemgraphs.append(systemgraph)
|
|
|
+
|
|
|
+ def add_edge(self,vertex1,vertex2):
|
|
|
+ '''
|
|
|
+ Create virtual edge that connect two floor.
|
|
|
+ Add edge to edge list.
|
|
|
+ :param vertex1:
|
|
|
+ :param vertex2:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ edge=SystemEdge(None,None)
|
|
|
+ edge.start_vertex=vertex1
|
|
|
+ edge.end_vertex=vertex2
|
|
|
+ self.connectedges.append(edge)
|
|
|
+
|
|
|
+class ProjectGraph:
|
|
|
+ '''
|
|
|
+ ProjectGraph contain more than one GroupedSystemGraph.
|
|
|
+ '''
|
|
|
+ def __init__(self):
|
|
|
+ self.groupedsystemgraphs=[]
|
|
|
+
|
|
|
+ def remove_groupedsystemgraphs(self, systemgraph):
|
|
|
+ '''
|
|
|
+ Check system has existed in grouped system list.
|
|
|
+ if exist remove it .
|
|
|
+ :param systemgraph:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ try:
|
|
|
+ tt = next(groupedsystemgraph for groupedsystemgraph in self.groupedsystemgraphs if
|
|
|
+ systemgraph in groupedsystemgraph.systemgraphs)
|
|
|
+ if tt:
|
|
|
+ self.groupedsystemgraphs.remove(tt)
|
|
|
+ except StopIteration:
|
|
|
+ pass
|
|
|
+
|
|
|
|
|
|
class SystemFlowDirection(Enum):
|
|
|
"""Edge Flow Direction.
|