import json import math import sys import time import ezdxf from tqdm import tqdm import core from drawer import ShaftDrawer, TunDrawer, WindowDrawer, GateDrawer, FanMainDrawer, FanSystemDrawer, WindFlowDrawer from drawer.CADJson import CADJson from drawer.MeshTemplateDrawer import MeshTemplateDrawer from drawer.WindBridgeDrawer import WindBridgeDrawer import requests url = 'http://192.168.183.216:8008/python/tunCAD' if __name__ == '__main__': # doc = ezdxf.new('R2000') cad_json = CADJson("data/wlml.json") # cad_json = CADJson("data/Cad.json") # tun_list = cad_json.tun_list # fan_list = cad_json.fan_list # window_list = cad_json.window_list doc = ezdxf.readfile("data/huojitu-moban4.dxf") doc.styles.add("msyh", font="data/msyh.ttc") for layer in cad_json.json['layerMap']: doc.layers.new(name=f'图层{layer[0]}') msp = doc.modelspace() for tun in tqdm(cad_json.tun_list, desc=' 【巷道绘制中】'): if tun['type'] == '1': shaft_center = tun['from'][0], tun['from'][1] sd = ShaftDrawer(msp, tun['layer_id'], tun['width'], shaft_center, 0) sd.draw_shaft_drawer() else: td = TunDrawer(msp, tun['layer_id'], tun["vec12"], tun["vec34"], tun["from"], tun["to"], tun["name"], tun["width"]) td.draw_tun() for window in tqdm(cad_json.window_list, desc=f' 【风窗绘制中】'): wd = WindowDrawer(msp, window["width"], window["layer"], window["center"], window["route"]) wd.draw_window() for gate in tqdm(cad_json.gate_list, desc=f' 【风门绘制中】'): gd = GateDrawer(msp, gate["layer"], gate["width"], gate['center'], gate["route"]) gd.draw_gate() for fan in tqdm(cad_json.fan_list, desc=f' 【风扇绘制中】'): if 'fanmain' in str(fan['type']): fmd = FanMainDrawer(msp, fan["layer"], fan["width"], fan['center'], fan["route"]) fmd.draw_fan_main() if 'fansystem' in str(fan['type']): fsd = FanSystemDrawer(msp, fan["width"], fan['center'], fan["route"]) fsd.draw_fan_system() wind_flow_list = cad_json.wind_flow_list for in_path in tqdm(wind_flow_list['in'], desc=f' 【进风方向绘制中】'): if len(in_path) != 0: wfd = WindFlowDrawer(msp, in_path['layer'], 3, in_path['center'], in_path['route'], in_path['type']) wfd.draw_wind_flow() for no_path in tqdm(wind_flow_list['no'], desc=f'【未指定方向绘制中】'): if len(no_path) != 0: wfd = WindFlowDrawer(msp, no_path['layer'], 3, no_path['center'], no_path['route'], no_path['type']) wfd.draw_wind_flow() for out_path in tqdm(wind_flow_list['out'], desc=f'【回风方向绘制中】'): if len(out_path) != 0: wfd = WindFlowDrawer(msp, out_path['layer'], 3, out_path['center'], out_path['route'], out_path['type']) wfd.draw_wind_flow() for use_path in tqdm(wind_flow_list['use'], desc=f' 【用风方向绘制中】'): if len(use_path) != 0: wfd = WindFlowDrawer(msp, use_path['layer'], 3, use_path['center'], use_path['route'], use_path['type']) wfd.draw_wind_flow() for wind_bridge in tqdm(cad_json.wind_bridge_list, desc=f' 【风桥绘制中】'): wbd = WindBridgeDrawer(msp, wind_bridge['center'], wind_bridge['layer'], wind_bridge['route'], wind_bridge['width']) wbd.draw_wind_bridge_drawer() a = time.time() doc.saveas(f'save/tuns{str(a)}.dxf')