systemutils.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 systemrelation import revit_const
  6. from functools import cmp_to_key
  7. def path2edge(elements):
  8. """
  9. Convert path to GraphtEdge
  10. :param elements:
  11. :return:
  12. """
  13. pass
  14. def graph_arrange(graph):
  15. """
  16. Combine Vertex that connect to virtul Vertex
  17. :param graph:
  18. :return:
  19. """
  20. pass
  21. def connector_sort(connector1, connector2):
  22. """Use Define Sort rule"""
  23. dic = {revit_const.EQUIPMENT: 0, revit_const.COMPONENT: 1, revit_const.OTHER: 2, revit_const.PIPE: 3,
  24. revit_const.DUCT: 4}
  25. x = dic[connector1.belong_type]
  26. y = dic[connector2.belong_type]
  27. return 1 if x > y else -1
  28. def sort_connectors(connectors):
  29. """Sort Connector order by Equipment>EquipPart>Other>Pipe>Duct"""
  30. return sorted(connectors, key=cmp_to_key(lambda x,y:connector_sort(x,y)))
  31. def is_break_condition(element):
  32. """Path end Condition."""
  33. res = element.type in revit_const.FACILITY
  34. return res
  35. def dic2obj(d):
  36. """Convert Dict to Object.
  37. """
  38. top = type('new', (object,), d)
  39. seqs = tuple, list, set, frozenset
  40. for i, j in d.items():
  41. if isinstance(j, dict):
  42. setattr(top, i, dic2obj(j))
  43. elif isinstance(j, seqs):
  44. setattr(top, i,
  45. type(j)(dic2obj(sj) if isinstance(sj, dict) else sj for sj in j))
  46. else:
  47. setattr(top, i, j)
  48. return top
  49. def list_to_dict(lis):
  50. ids = [idx.id for idx in lis]
  51. dic = dict(zip(ids, lis))
  52. return dic
  53. def add_attr_is_used(x):
  54. """"""
  55. x.is_used=False
  56. return x