main_2.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import json
  2. import math
  3. import sys
  4. import time
  5. import ezdxf
  6. from tqdm import tqdm
  7. import core
  8. from drawer import ShaftDrawer, TunDrawer, WindowDrawer, GateDrawer, FanMainDrawer, FanSystemDrawer, WindFlowDrawer
  9. from drawer.CADJson import CADJson
  10. from drawer.MeshTemplateDrawer import MeshTemplateDrawer
  11. from drawer.WindBridgeDrawer import WindBridgeDrawer
  12. import requests
  13. url = 'http://192.168.183.216:8008/python/tunCAD'
  14. global_route = - math.pi / 6
  15. global_scale = 0.6
  16. global_shift = -1000,3000
  17. def calculate_route_middle(wind_flow_unit):
  18. path_start = wind_flow_unit[0]['x'], wind_flow_unit[0]['z']
  19. path_end = wind_flow_unit[-1]['x'], wind_flow_unit[-1]['z']
  20. path_middle = core.find_point_on_line(path_start, path_end, 1 / 2)
  21. route = core.calculate_angle_with_x_axis(path_start, path_end)
  22. return path_middle, route
  23. if __name__ == '__main__':
  24. # doc = ezdxf.new('R2000')
  25. cad_json = CADJson("data/Cad.json")
  26. tun_list = cad_json.tun_list
  27. fan_list = cad_json.fan_list
  28. window_list = cad_json.window_list
  29. doc = ezdxf.readfile("data/moban.dxf")
  30. doc.styles.add("msyh", font="data/msyh.ttc")
  31. msp = doc.modelspace()
  32. with open("data/Cad.json", 'r', encoding='utf-8') as r:
  33. cad_json = json.loads(r.read())
  34. layer_map = cad_json["layerMap"]
  35. for (k, v) in layer_map:
  36. doc.layers.new(name=f'图层{k}')
  37. node_list = cad_json["tunsMapCAD"]
  38. # tun_list = []
  39. window_list = []
  40. gate_list = []
  41. fan_list = []
  42. for node in node_list:
  43. node = node[1]
  44. fan_list.extend(node["fans"])
  45. for tun in tqdm(tun_list, desc=' 【巷道绘制中】'):
  46. if tun['type'] == '1':
  47. shaft_center = tun['from'][0], tun['from'][1]
  48. # shaft_center = core.rotate_point_around_another(shaft_center, (0, 0), global_route)
  49. sd = ShaftDrawer(msp,tun['layer_id'], tun['width'], shaft_center, tun["route"] + global_route, 42)
  50. sd.draw_shaft_drawer()
  51. else:
  52. td = TunDrawer(msp, tun['layer_id'], tun["vec12"], tun["vec34"], tun["from"], tun["to"], tun["name"], global_route,tun["width"])
  53. td.draw_tun()
  54. for window in tqdm(window_list, desc=f' 【风窗绘制中】'):
  55. point_c = window['x'], window['z']
  56. point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
  57. wd = WindowDrawer(msp, window["gap"], window["nlayerid"],point_c, window["route"] + global_route)
  58. wd.draw_window()
  59. for gate in tqdm(gate_list, desc=f' 【风门绘制中】'):
  60. point_c = gate['x'], gate['z']
  61. point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
  62. gd = GateDrawer(msp,gate["nlayerid"], gate["gap"], point_c, gate["route"] + global_route)
  63. gd.draw_gate()
  64. for fan in tqdm(fan_list, desc=f' 【风扇绘制中】'):
  65. if 'fanmain' in str(fan['strtype']):
  66. point_c = fan['x'], fan['z']
  67. point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
  68. # fmd = FanMainDrawer(msp, fan["nlayerid"],fan["gap"], point_c, fan["route"] + global_route)
  69. # fmd.draw_fan_main()
  70. if 'fansystem' in str(fan['strtype']):
  71. point_c = fan['x'], fan['z']
  72. point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
  73. # fsd = FanSystemDrawer(msp, fan["gap"], point_c, fan["route"] + global_route)
  74. # fsd.draw_fan_system()
  75. path_point_layers = cad_json["pathPointMap"]
  76. for path_point in path_point_layers:
  77. in_paths = path_point[1]['inPaths']
  78. for in_path in tqdm(in_paths, desc=f'图层{path_point[0]} 【进风方向绘制中】'):
  79. if len(in_path) != 0:
  80. path_middle, route = calculate_route_middle(in_path)
  81. path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
  82. wfd = WindFlowDrawer(msp,path_point[0],5, path_middle, route + global_route, 3)
  83. wfd.draw_wind_flow()
  84. no_paths = path_point[1]['noPaths']
  85. for no_path in tqdm(no_paths, desc=f'图层{path_point[0]} 【未指定方向绘制中】'):
  86. if len(no_path) != 0:
  87. path_middle, route = calculate_route_middle(no_path)
  88. path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
  89. wfd = WindFlowDrawer(msp,path_point[0], 5, path_middle, route + global_route, 3)
  90. wfd.draw_wind_flow()
  91. out_paths = path_point[1]['outPaths']
  92. for out_path in tqdm(out_paths, desc=f'图层{path_point[0]} 【回风方向绘制中】'):
  93. if len(out_path) != 0:
  94. path_middle, route = calculate_route_middle(out_path)
  95. path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
  96. wfd = WindFlowDrawer(msp, path_point[0],5, path_middle, route + global_route, 1)
  97. wfd.draw_wind_flow()
  98. use_paths = path_point[1]['usePaths']
  99. for use_path in tqdm(use_paths, desc=f'图层{path_point[0]} 【用风方向绘制中】'):
  100. if len(use_path) != 0:
  101. path_middle, route = calculate_route_middle(use_path)
  102. path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
  103. wfd = WindFlowDrawer(msp,path_point[0], 5, path_middle, route + global_route, 1)
  104. layer_map = cad_json["layerMap"]
  105. for layer in layer_map:
  106. cross_nodes = layer[1]['crossNodes']
  107. for cross_node in tqdm(cross_nodes, desc=f'图层{layer[0]} 【风桥绘制中】'):
  108. center = cross_node['crossPoint']['x'], -cross_node['crossPoint']['y']
  109. tun = [tun_ for tun_ in tun_list if tun_.get("tun_id") == cross_node['tun1Id']][0]
  110. route = core.calculate_angle_with_x_axis(tun["from"], tun["to"])
  111. # line_1 = (tun["vec12"][0]["x"], tun["vec12"][0]["z"]), (tun["vec12"][-1]["x"], tun["vec12"][-1]["z"])
  112. # line_2 = (tun["vec34"][0]["x"], tun["vec34"][0]["z"]), (tun["vec34"][-1]["x"], tun["vec34"][-1]["z"])
  113. # gap = core.min_distance_between_segments(line_1,
  114. # line_2)
  115. # center = core.rotate_point_around_another(center, (0, 0), global_route)
  116. # wbd = WindBridgeDrawer(msp, center, cross_node['tun1Id'], cross_node['tun2Id'], layer[0],
  117. # tun["angle"] + global_route, gap)
  118. # wbd.draw_wind_bridge_drawer()
  119. a = time.time()
  120. doc.saveas(f'save/tuns{str(a)}.dxf')