123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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'
- global_route = - math.pi / 6
- global_scale = 0.6
- global_shift = -1000,3000
- def calculate_route_middle(wind_flow_unit):
- path_start = wind_flow_unit[0]['x'], wind_flow_unit[0]['z']
- path_end = wind_flow_unit[-1]['x'], wind_flow_unit[-1]['z']
- path_middle = core.find_point_on_line(path_start, path_end, 1 / 2)
- route = core.calculate_angle_with_x_axis(path_start, path_end)
- return path_middle, route
- if __name__ == '__main__':
- # doc = ezdxf.new('R2000')
- 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/moban.dxf")
- doc.styles.add("msyh", font="data/msyh.ttc")
- msp = doc.modelspace()
- with open("data/Cad.json", 'r', encoding='utf-8') as r:
- cad_json = json.loads(r.read())
- layer_map = cad_json["layerMap"]
- for (k, v) in layer_map:
- doc.layers.new(name=f'图层{k}')
- node_list = cad_json["tunsMapCAD"]
- # tun_list = []
- window_list = []
- gate_list = []
- fan_list = []
- for node in node_list:
- node = node[1]
- fan_list.extend(node["fans"])
- for tun in tqdm(tun_list, desc=' 【巷道绘制中】'):
- if tun['type'] == '1':
- shaft_center = tun['from'][0], tun['from'][1]
- # shaft_center = core.rotate_point_around_another(shaft_center, (0, 0), global_route)
- sd = ShaftDrawer(msp,tun['layer_id'], tun['width'], shaft_center, tun["route"] + global_route, 42)
- sd.draw_shaft_drawer()
- else:
- td = TunDrawer(msp, tun['layer_id'], tun["vec12"], tun["vec34"], tun["from"], tun["to"], tun["name"], global_route,tun["width"])
- td.draw_tun()
- for window in tqdm(window_list, desc=f' 【风窗绘制中】'):
- point_c = window['x'], window['z']
- point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
- wd = WindowDrawer(msp, window["gap"], window["nlayerid"],point_c, window["route"] + global_route)
- wd.draw_window()
- for gate in tqdm(gate_list, desc=f' 【风门绘制中】'):
- point_c = gate['x'], gate['z']
- point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
- gd = GateDrawer(msp,gate["nlayerid"], gate["gap"], point_c, gate["route"] + global_route)
- gd.draw_gate()
- for fan in tqdm(fan_list, desc=f' 【风扇绘制中】'):
- if 'fanmain' in str(fan['strtype']):
- point_c = fan['x'], fan['z']
- point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
- # fmd = FanMainDrawer(msp, fan["nlayerid"],fan["gap"], point_c, fan["route"] + global_route)
- # fmd.draw_fan_main()
- if 'fansystem' in str(fan['strtype']):
- point_c = fan['x'], fan['z']
- point_c = core.rotate_point_around_another(point_c, (0, 0), global_route)
- # fsd = FanSystemDrawer(msp, fan["gap"], point_c, fan["route"] + global_route)
- # fsd.draw_fan_system()
- path_point_layers = cad_json["pathPointMap"]
- for path_point in path_point_layers:
- in_paths = path_point[1]['inPaths']
- for in_path in tqdm(in_paths, desc=f'图层{path_point[0]} 【进风方向绘制中】'):
- if len(in_path) != 0:
- path_middle, route = calculate_route_middle(in_path)
- path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
- wfd = WindFlowDrawer(msp,path_point[0],5, path_middle, route + global_route, 3)
- wfd.draw_wind_flow()
- no_paths = path_point[1]['noPaths']
- for no_path in tqdm(no_paths, desc=f'图层{path_point[0]} 【未指定方向绘制中】'):
- if len(no_path) != 0:
- path_middle, route = calculate_route_middle(no_path)
- path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
- wfd = WindFlowDrawer(msp,path_point[0], 5, path_middle, route + global_route, 3)
- wfd.draw_wind_flow()
- out_paths = path_point[1]['outPaths']
- for out_path in tqdm(out_paths, desc=f'图层{path_point[0]} 【回风方向绘制中】'):
- if len(out_path) != 0:
- path_middle, route = calculate_route_middle(out_path)
- path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
- wfd = WindFlowDrawer(msp, path_point[0],5, path_middle, route + global_route, 1)
- wfd.draw_wind_flow()
- use_paths = path_point[1]['usePaths']
- for use_path in tqdm(use_paths, desc=f'图层{path_point[0]} 【用风方向绘制中】'):
- if len(use_path) != 0:
- path_middle, route = calculate_route_middle(use_path)
- path_middle = core.rotate_point_around_another(path_middle, (0, 0), global_route)
- wfd = WindFlowDrawer(msp,path_point[0], 5, path_middle, route + global_route, 1)
- layer_map = cad_json["layerMap"]
- for layer in layer_map:
- cross_nodes = layer[1]['crossNodes']
- for cross_node in tqdm(cross_nodes, desc=f'图层{layer[0]} 【风桥绘制中】'):
- center = cross_node['crossPoint']['x'], -cross_node['crossPoint']['y']
- tun = [tun_ for tun_ in tun_list if tun_.get("tun_id") == cross_node['tun1Id']][0]
- route = core.calculate_angle_with_x_axis(tun["from"], tun["to"])
- # line_1 = (tun["vec12"][0]["x"], tun["vec12"][0]["z"]), (tun["vec12"][-1]["x"], tun["vec12"][-1]["z"])
- # line_2 = (tun["vec34"][0]["x"], tun["vec34"][0]["z"]), (tun["vec34"][-1]["x"], tun["vec34"][-1]["z"])
- # gap = core.min_distance_between_segments(line_1,
- # line_2)
- # center = core.rotate_point_around_another(center, (0, 0), global_route)
- # wbd = WindBridgeDrawer(msp, center, cross_node['tun1Id'], cross_node['tun2Id'], layer[0],
- # tun["angle"] + global_route, gap)
- # wbd.draw_wind_bridge_drawer()
- a = time.time()
- doc.saveas(f'save/tuns{str(a)}.dxf')
|