main.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import json
  2. import time
  3. from tqdm import tqdm
  4. import ezdxf
  5. import core
  6. import drawer
  7. from drawer import FanMainDrawer, ShaftDrawer, WindowDrawer, WindFlowDrawer, FanSystemDrawer
  8. from drawer.GateDrawer import GateDrawer
  9. from drawer.TunDrawer import TunDrawer
  10. from drawer.WindBridgeDrawer import WindBridgeDrawer
  11. def calculate_route_gap(graph_unit):
  12. tun_id = graph_unit['ntunid']
  13. tun = dict_tuns[tun_id]
  14. tun_from = tun['nfrom']['x'], tun['nfrom']['z']
  15. tun_to = tun['ntoid']['x'], tun['ntoid']['z']
  16. route = core.calculate_angle_with_x_axis(tun_from, tun_to)
  17. return route, tun['gap']
  18. def calculate_route_middle(wind_flow_unit):
  19. path_start = wind_flow_unit[0]['x'], wind_flow_unit[0]['z']
  20. path_end = wind_flow_unit[-1]['x'], wind_flow_unit[-1]['z']
  21. path_middle = core.find_point_on_line(path_start, path_end, 1 / 2)
  22. route = core.calculate_angle_with_x_axis(path_start, path_end)
  23. return path_middle, route
  24. def add_line_auxiliary(msp, from_, to_, color):
  25. msp.add_line(from_, to_, dxfattribs={'color': color})
  26. if __name__ == '__main__':
  27. tmp_json = 'data/tunData.json'
  28. tmp_json2 = 'data/tunPath.json'
  29. with open(tmp_json, 'r', encoding='utf-8') as r:
  30. node_list = json.loads(r.read())
  31. tuns = node_list['tunsMap']
  32. with open(tmp_json2, 'r', encoding='utf-8') as r:
  33. node_list2 = json.loads(r.read())
  34. doc = ezdxf.new('R2000')
  35. doc.styles.add("LiberationSerif", font="LiberationSerif.ttf")
  36. msp = doc.modelspace()
  37. for tun in tqdm(tuns,desc='【巷道绘制中】'):
  38. tun_id = tun[0]
  39. tun_e = tun[1]
  40. if tun_e['tunType'] == '1':
  41. shaft_center = tun_e['nfrom']['x'], tun_e['nfrom']['z']
  42. sd = ShaftDrawer(msp, tun_e['fwidth'], shaft_center, 0, 42)
  43. sd.draw_shaft_drawer()
  44. else:
  45. vec1 = tun_e['vec12'][0]['x'], tun_e['vec12'][0]['z']
  46. vec2 = tun_e['vec12'][1]['x'], tun_e['vec12'][1]['z']
  47. vec3 = tun_e['vec34'][0]['x'], tun_e['vec34'][0]['z']
  48. vec4 = tun_e['vec34'][1]['x'], tun_e['vec34'][1]['z']
  49. color = core.get_color_by_layer(tun_e['nlayerid'])
  50. n_from = tun_e['nfrom']['x'], tun_e['nfrom']['z']
  51. n_to = tun_e['ntoid']['x'], tun_e['ntoid']['z']
  52. td = TunDrawer(msp, tun_e['nlayerid'], color, (vec1, vec2), (vec3, vec4), n_from, n_to)
  53. td.draw_tun()
  54. tun[1]['gap'] = core.min_distance_between_segments((vec1, vec2), (vec3, vec4))
  55. dict_tuns = {k: v for k, v in tuns}
  56. layers = node_list['layerMap']
  57. for layer in layers:
  58. windows = layer[1]['windows']
  59. for window in tqdm(windows,desc=f' 图层{layer[0]} 【风窗绘制中】'):
  60. point_c = window['x'], window['z']
  61. route, gap = calculate_route_gap(window)
  62. wd = WindowDrawer(msp, gap, point_c, route)
  63. wd.draw_window()
  64. gates = layer[1]['gates']
  65. for gate in tqdm(gates,desc=f'图层{layer[0]} 【风门绘制中】'):
  66. point_c = gate['x'], gate['z']
  67. route, gap = calculate_route_gap(gate)
  68. gd = GateDrawer(msp, gap, point_c, route)
  69. gd.draw_gate()
  70. fans = layer[1]['fans']
  71. for fan in tqdm(fans,desc=f'图层{layer[0]} 【风扇绘制中】'):
  72. if 'fanmain' in str(fan['strtype']):
  73. point_c = fan['x'], fan['z']
  74. route, gap = calculate_route_gap(fan)
  75. fmd = FanMainDrawer(msp, gap, point_c, route)
  76. fmd.draw_fan_main()
  77. if 'fansystem' in str(fan['strtype']):
  78. point_c = fan['x'], fan['z']
  79. route, gap = calculate_route_gap(fan)
  80. fsd = FanSystemDrawer(msp, gap, point_c, route)
  81. fsd.draw_fan_system()
  82. # path_lines = node_list2['pathLins']
  83. for line in node_list2:
  84. in_paths = line[1]['inPaths']
  85. for in_path in tqdm(in_paths,desc=f'图层{line[0]} 【进风方向绘制中】'):
  86. if len(in_path) != 0:
  87. path_middle, route = calculate_route_middle(in_path)
  88. wfd = WindFlowDrawer(msp, 5, path_middle, route, 3)
  89. wfd.draw_wind_flow()
  90. no_paths = line[1]['noPaths']
  91. for no_path in tqdm(no_paths,desc=f'图层{line[0]} 【未指定方向绘制中】'):
  92. if len(no_path) != 0:
  93. path_middle, route = calculate_route_middle(no_path)
  94. wfd = WindFlowDrawer(msp, 5, path_middle, route, 3)
  95. wfd.draw_wind_flow()
  96. out_paths = line[1]['outPaths']
  97. for out_path in tqdm(out_paths,desc=f'图层{line[0]} 【回风方向绘制中】'):
  98. if len(out_path) != 0:
  99. path_middle, route = calculate_route_middle(out_path)
  100. wfd = WindFlowDrawer(msp, 5, path_middle, route, 1)
  101. wfd.draw_wind_flow()
  102. use_paths = line[1]['usePaths']
  103. for use_path in tqdm(use_paths,desc=f'图层{line[0]} 【用风方向绘制中】'):
  104. if len(use_path) != 0:
  105. path_middle, route = calculate_route_middle(use_path)
  106. wfd = WindFlowDrawer(msp, 5, path_middle, route, 1)
  107. wfd.draw_wind_flow()
  108. with open('data/tunCross.json','r', encoding='utf-8') as r:
  109. node_list3 = json.loads(r.read())
  110. for layer in node_list3:
  111. cross_nodes = layer[1]['crossNodes']
  112. for cross_node in tqdm(cross_nodes,desc=f'图层{layer[0]} 【风桥绘制中】'):
  113. center = cross_node['crossPoint']['x'],-cross_node['crossPoint']['y']
  114. tun_node ={'ntunid':cross_node['tun1Id']}
  115. gap,route=calculate_route_gap(tun_node)
  116. tun1 = dict_tuns[cross_node['tun1Id']]
  117. wbd = WindBridgeDrawer(msp,center,cross_node['tun1Id'],cross_node['tun2Id'],layer[0],gap,route)
  118. wbd.draw_wind_bridge_drawer()
  119. a = time.time()
  120. doc.saveas(f'save/tuns{str(a)}.dxf')