main_3.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if __name__ == '__main__':
  15. # doc = ezdxf.new('R2000')
  16. cad_json = CADJson("data/wlml.json")
  17. # cad_json = CADJson("data/Cad.json")
  18. # tun_list = cad_json.tun_list
  19. # fan_list = cad_json.fan_list
  20. # window_list = cad_json.window_list
  21. doc = ezdxf.readfile("data/huojitu-moban4.dxf")
  22. doc.styles.add("msyh", font="data/msyh.ttc")
  23. for layer in cad_json.json['layerMap']:
  24. doc.layers.new(name=f'图层{layer[0]}')
  25. msp = doc.modelspace()
  26. for tun in tqdm(cad_json.tun_list, desc=' 【巷道绘制中】'):
  27. if tun['type'] == '1':
  28. shaft_center = tun['from'][0], tun['from'][1]
  29. sd = ShaftDrawer(msp, tun['layer_id'], tun['width'], shaft_center, 0)
  30. sd.draw_shaft_drawer()
  31. else:
  32. td = TunDrawer(msp, tun['layer_id'], tun["vec12"], tun["vec34"], tun["from"], tun["to"], tun["name"],
  33. tun["width"])
  34. td.draw_tun()
  35. for window in tqdm(cad_json.window_list, desc=f' 【风窗绘制中】'):
  36. wd = WindowDrawer(msp, window["width"], window["layer"], window["center"], window["route"])
  37. wd.draw_window()
  38. for gate in tqdm(cad_json.gate_list, desc=f' 【风门绘制中】'):
  39. gd = GateDrawer(msp, gate["layer"], gate["width"], gate['center'], gate["route"])
  40. gd.draw_gate()
  41. for fan in tqdm(cad_json.fan_list, desc=f' 【风扇绘制中】'):
  42. if 'fanmain' in str(fan['type']):
  43. fmd = FanMainDrawer(msp, fan["layer"], fan["width"], fan['center'], fan["route"])
  44. fmd.draw_fan_main()
  45. if 'fansystem' in str(fan['type']):
  46. fsd = FanSystemDrawer(msp, fan["width"], fan['center'], fan["route"])
  47. fsd.draw_fan_system()
  48. wind_flow_list = cad_json.wind_flow_list
  49. for in_path in tqdm(wind_flow_list['in'], desc=f' 【进风方向绘制中】'):
  50. if len(in_path) != 0:
  51. wfd = WindFlowDrawer(msp, in_path['layer'], 3, in_path['center'], in_path['route'], in_path['type'])
  52. wfd.draw_wind_flow()
  53. for no_path in tqdm(wind_flow_list['no'], desc=f'【未指定方向绘制中】'):
  54. if len(no_path) != 0:
  55. wfd = WindFlowDrawer(msp, no_path['layer'], 3, no_path['center'], no_path['route'], no_path['type'])
  56. wfd.draw_wind_flow()
  57. for out_path in tqdm(wind_flow_list['out'], desc=f'【回风方向绘制中】'):
  58. if len(out_path) != 0:
  59. wfd = WindFlowDrawer(msp, out_path['layer'], 3, out_path['center'], out_path['route'], out_path['type'])
  60. wfd.draw_wind_flow()
  61. for use_path in tqdm(wind_flow_list['use'], desc=f' 【用风方向绘制中】'):
  62. if len(use_path) != 0:
  63. wfd = WindFlowDrawer(msp, use_path['layer'], 3, use_path['center'], use_path['route'], use_path['type'])
  64. wfd.draw_wind_flow()
  65. for wind_bridge in tqdm(cad_json.wind_bridge_list, desc=f' 【风桥绘制中】'):
  66. wbd = WindBridgeDrawer(msp, wind_bridge['center'], wind_bridge['layer'],
  67. wind_bridge['route'], wind_bridge['width'])
  68. wbd.draw_wind_bridge_drawer()
  69. a = time.time()
  70. doc.saveas(f'save/tuns{str(a)}.dxf')