systemutils.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. """system calc utils.
  2. 1. get connectors where model_id='@model_id' and belong_type='Equipment' and mep_system_type='@system_name'
  3. 2. get path start with connector,end with triple ,cross,equipment,end
  4. """
  5. from functools import cmp_to_key
  6. import vg
  7. import json
  8. from relations.src.system_relation import revit_const
  9. def path2edge(elements):
  10. """
  11. Convert path to GraphtEdge
  12. :param elements:
  13. :return:
  14. """
  15. pass
  16. def graph_arrange(graph):
  17. """
  18. Combine Vertex that connect to virtul Vertex
  19. :param graph:
  20. :return:
  21. """
  22. pass
  23. def connector_sort(connector1, connector2):
  24. """Use Define Sort rule"""
  25. dic = {revit_const.EQUIPMENT: 0, revit_const.COMPONENT: 1,revit_const.JoinObject:2, revit_const.OTHER: 2, revit_const.PIPE: 3,
  26. revit_const.DUCT: 4}
  27. x = dic[connector1.belong_type]
  28. y = dic[connector2.belong_type]
  29. return 1 if x > y else -1
  30. def sort_connectors(connectors):
  31. """Sort Connector order by Equipment>EquipPart>Other>Pipe>Duct"""
  32. return sorted(connectors, key=cmp_to_key(lambda x, y: connector_sort(x, y)))
  33. def is_break_condition(element):
  34. """Path end Condition."""
  35. res = element.type in revit_const.FACILITY
  36. return res
  37. def dic2obj(d):
  38. """Convert Dict to Object.
  39. """
  40. top = type('new', (object,), d)
  41. seqs = tuple, list, set, frozenset
  42. for i, j in d.items():
  43. j0 = j
  44. try:
  45. j0 = json.loads(j0)
  46. except Exception as e:
  47. pass
  48. if isinstance(j0, dict):
  49. setattr(top, i, dic2obj(j0))
  50. elif isinstance(j0, seqs):
  51. setattr(top, i,
  52. type(j0)(dic2obj(sj) if isinstance(sj, dict) else sj for sj in j0))
  53. else:
  54. setattr(top, i, j0)
  55. return top
  56. def sqldata2objlist(data):
  57. '''Convert Sqldata to Object list.
  58. '''
  59. return list(map(dic2obj,data))
  60. def list_to_dict(lis):
  61. '''Convert list to id Dict.
  62. :param lis:
  63. :return:
  64. '''
  65. ids = [idx.id for idx in lis if idx.id]
  66. dic = dict(zip(ids, lis))
  67. return dic
  68. def add_attr_is_used(x):
  69. """
  70. Add is_used attribute.
  71. :param x:
  72. :return:
  73. """
  74. x.is_used = False
  75. return x
  76. def is_xyz_equal(origin1, origin2):
  77. """
  78. Judge the two origin are almost equal.
  79. :param origin1:
  80. :param origin2:
  81. :return:
  82. """
  83. v1 = [origin1.X, origin1.Y, origin1.Z]
  84. v2 = [origin2.X, origin2.Y, origin2.Z]
  85. return vg.almost_equal(v1, v2, atol=1e-08)
  86. def get_specify_type_parent(vertex, type):
  87. parent = vertex
  88. try:
  89. while not isinstance(parent, type):
  90. parent = parent.parent
  91. except :
  92. parent=None
  93. return parent