main_3.py 3.5 KB

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