CADJson.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. import json
  2. import math
  3. import requests
  4. from tqdm import tqdm
  5. import core
  6. # # 旋转
  7. # # global_route = -math.pi / 4
  8. # global_route = 0
  9. # # 缩放
  10. # global_scale = 1
  11. # # 偏移
  12. # global_shift = 0, 0
  13. class CADJson:
  14. def __init__(self, path, config):
  15. self.json = request_graph_point(path)
  16. self.config = config
  17. # with open("tun3D.json", 'r', encoding='utf-8') as f:
  18. # self.json = json.load(f)
  19. self.model = self.get_model()
  20. self.layer_map = self.get_layerMap()
  21. self.tun_plg_dict = self.get_tun_plg_dict()
  22. self.tun_dict = self.get_tun_dict()
  23. self.fan_list = self.get_fans()
  24. self.window_list = self.get_windows()
  25. self.gate_list = self.get_gates()
  26. # self.wind_flow_list = self.get_wind_flow()
  27. self.wind_bridge_list = self.get_wind_bridge()
  28. # self.tun_dict = self.get_tun_dict()
  29. self.sealed_list = self.get_sealed_list()
  30. self.air_flow_list = self.get_air_flow()
  31. self.air_flow_list_3d = self.get_air_flow_3d()
  32. self.window_list_3d = self.get_windows_3d()
  33. self.gates_list_3d = self.get_gates_3d()
  34. self.fans_list_3d = self.get_fans_3d()
  35. self.gaps_list = self.get_gap_node()
  36. self.tun_text_dict = self.get_tun_text()
  37. self.ari_duct_dict = self.get_ari_duct_dict()
  38. def global_process(self, point):
  39. point = core.rotate_point_around_another(point, (0, 0), self.config['global']['route'])
  40. point = core.scale_point(point[0], point[1], self.config['global']['scale'])
  41. point = point[0] + self.config['global']['shift']['x'], - (point[1] + self.config['global']['shift']['y'])
  42. return point
  43. def get_model(self):
  44. model = self.json["model"]
  45. model['cadOffsetX'] = self.config['agg']['shift']['x']
  46. model['cadOffsetY'] = self.config['agg']['shift']['y']
  47. model['cadAngle'] = self.config['agg']['route']
  48. model['scale'] = self.config['agg']['scale']
  49. return model
  50. def get_layerMap(self):
  51. layer_list = self.json["layerMap"]
  52. layer_map = {}
  53. for layer in layer_list:
  54. layer_map[layer[0]] = layer[1]
  55. i = 0
  56. for key, value in layer_map.items():
  57. layer_map[key]['cadOffsetX'] = self.config['div']['shift']['x'][i]
  58. layer_map[key]['cadOffsetY'] = self.config['div']['shift']['y'][i]
  59. layer_map[key]['cadAngle'] = self.config['div']['route'][i]
  60. layer_map[key]['scale'] = self.config['div']['scale'][i]
  61. i = i + 1
  62. return layer_map
  63. def get_tun_on_line(self):
  64. node_list = self.json["tunsMap"]
  65. tun_text_dict = {}
  66. for node in tqdm(node_list, desc=' 【巷道文字读取中】'):
  67. node = node[1]
  68. if check_node(node) is False: continue
  69. if node['nusingtype'] == "1":
  70. fq = node['freportq']* 60
  71. else:
  72. fq = node['fq'] * 60
  73. formatted_fq = round(fq, 1)
  74. fq_text = str(formatted_fq) + "m³/min"
  75. fq_v = node['fq']
  76. tun_text = node["strname"] + " " + fq_text
  77. if tun_text in tun_text_dict.keys():
  78. tun_text_dict[tun_text]["tun_line"]["agg"].append(
  79. layer_aggregation(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])), self.model))
  80. tun_text_dict[tun_text]["tun_line"]["agg"].append(
  81. layer_aggregation(self.global_process((node["nto"]["x"], node["nto"]["z"])), self.model))
  82. tun_text_dict[tun_text]["tun_line"]["div"].append(
  83. layer_divide(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])), self.layer_map[node["nlayerid"]]))
  84. tun_text_dict[tun_text]["tun_line"]["div"].append(
  85. layer_divide(self.global_process((node["nto"]["x"], node["nto"]["z"])), self.layer_map[node["nlayerid"]]))
  86. else:
  87. tun_text_dict[tun_text] = {
  88. "fq_v": fq_v,
  89. "fq": fq_text,
  90. "text": tun_text,
  91. "layer": node["nlayerid"],
  92. "tun_line": {"agg": [], "div": []}
  93. }
  94. tun_text_dict[tun_text]["tun_line"]["agg"].append(
  95. layer_aggregation(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])), self.model))
  96. tun_text_dict[tun_text]["tun_line"]["agg"].append(
  97. layer_aggregation(self.global_process((node["nto"]["x"], node["nto"]["z"])), self.model))
  98. tun_text_dict[tun_text]["tun_line"]["div"].append(
  99. layer_divide(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])), self.layer_map[node["nlayerid"]]))
  100. tun_text_dict[tun_text]["tun_line"]["div"].append(
  101. layer_divide(self.global_process((node["nto"]["x"], node["nto"]["z"])), self.layer_map[node["nlayerid"]]))
  102. return tun_text_dict
  103. def get_tun_text(self):
  104. tun_text_dict = self.get_tun_on_line()
  105. for node in tqdm(tun_text_dict.values(), desc=' 【巷道文字读取中】'):
  106. node_list_agg = node['tun_line']["agg"]
  107. node_list_div = node['tun_line']["div"]
  108. farthest_agg = core.farthest_points(node_list_agg)
  109. farthest_div = core.farthest_points(node_list_div)
  110. tun_text_dict[node['text']]['farthest'] = {'agg': farthest_agg, 'div': farthest_div}
  111. return tun_text_dict
  112. def get_tun_plg_dict(self):
  113. if "tunsMap" not in self.json: return {}
  114. node_list = self.json["tunsMap"]
  115. tun_plg_dict = {}
  116. for node in tqdm(node_list, desc=' 【巷道读取中】'):
  117. obj = node[1]
  118. if "vecL1" not in obj: return {}
  119. vec_l_series = [
  120. (obj['vecL1']['x'], obj['vecL1']['z']),
  121. (obj['vecL2']['x'], obj['vecL2']['z']),
  122. (obj['vecL3']['x'], obj['vecL3']['z']),
  123. (obj['vecL4']['x'], obj['vecL4']['z'])
  124. ]
  125. vec_r_series = [
  126. (obj['vecR1']['x'], obj['vecR1']['z']),
  127. (obj['vecR2']['x'], obj['vecR2']['z']),
  128. (obj['vecR3']['x'], obj['vecR3']['z']),
  129. (obj['vecR4']['x'], obj['vecR4']['z'])
  130. ]
  131. vec_b_series = [
  132. (obj['vec1']['x'], obj['vec1']['z']),
  133. (obj['vec2']['x'], obj['vec2']['z']),
  134. (obj['vec3']['x'], obj['vec3']['z']),
  135. (obj['vec4']['x'], obj['vec4']['z'])
  136. ]
  137. plg = {
  138. "color": core.hex_to_rgb(self.layer_map[obj['nlayerid']]['ncolor']),
  139. "layer_id": obj["nlayerid"],
  140. "width": core.min_distance_between_segments(vec_b_series[:2], vec_b_series[2:]),
  141. "type": obj["tunType"],
  142. "angle": obj["angleRad"],
  143. "air_type": obj["nairtype"],
  144. "from": {
  145. "agg": layer_aggregation(self.global_process((obj["nfrom"]["x"], obj["nfrom"]["z"])), self.model),
  146. "div": layer_divide(self.global_process((obj["nfrom"]["x"], obj["nfrom"]["z"])),
  147. self.layer_map[obj["nlayerid"]])
  148. },
  149. "to": {"agg": layer_aggregation(self.global_process((obj["nto"]["x"], obj["nto"]["z"])), self.model),
  150. "div": layer_divide(self.global_process((obj["nto"]["x"], obj["nto"]["z"])),
  151. self.layer_map[obj["nlayerid"]])},
  152. "name": obj["strname"],
  153. "vec_r": {"agg": [], "div": []},
  154. "vec_l": {"agg": [], "div": []},
  155. "vec_b": {"agg": [], "div": []
  156. }
  157. }
  158. fq = obj['fq'] * 60
  159. formatted_fq = round(fq, 1)
  160. plg['fq'] = str(formatted_fq) + "m³/min"
  161. plg['fq_v'] = obj['fq']
  162. for n in vec_b_series:
  163. agg_point = layer_aggregation(self.global_process((n[0], n[1])), self.model)
  164. plg["vec_b"]["agg"].append(agg_point)
  165. div_point = layer_divide(self.global_process((n[0], n[1])), self.layer_map[obj["nlayerid"]])
  166. plg["vec_b"]["div"].append(div_point)
  167. for n in vec_l_series:
  168. agg_point = layer_aggregation(self.global_process((n[0], n[1])), self.model)
  169. plg["vec_l"]["agg"].append(agg_point)
  170. div_point = layer_divide(self.global_process((n[0], n[1])), self.layer_map[obj["nlayerid"]])
  171. plg["vec_l"]["div"].append(div_point)
  172. for n in vec_r_series:
  173. agg_point = layer_aggregation(self.global_process((n[0], n[1])), self.model)
  174. plg["vec_r"]["agg"].append(agg_point)
  175. div_point = layer_divide(self.global_process((n[0], n[1])), self.layer_map[obj["nlayerid"]])
  176. plg["vec_r"]["div"].append(div_point)
  177. plg["route"] = {
  178. "agg": core.calculate_angle_with_x_axis(plg['from']['agg'],
  179. plg['to']['agg']),
  180. "div": core.calculate_angle_with_x_axis(plg['from']['div'],
  181. plg['to']['div'])}
  182. tun_plg_dict[obj['ntunid']] = plg
  183. return tun_plg_dict
  184. def get_tun_dict(self):
  185. if not 'tunsMap' in self.json: return {}
  186. node_list = self.json["tunsMap"]
  187. tun_dict = {}
  188. for node in tqdm(node_list, desc=' 【巷道读取中】'):
  189. node = node[1]
  190. if check_node(node) is False: continue
  191. tun = {
  192. "tun_id": node["ntunid"],
  193. "layer_id": node["nlayerid"],
  194. "width": node["fwidth"],
  195. "type": node["tunType"],
  196. "angle": node["angleRad"],
  197. "air_type": node["nairtype"],
  198. "from": {
  199. "agg": layer_aggregation(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])), self.model),
  200. "div": layer_divide(self.global_process((node["nfrom"]["x"], node["nfrom"]["z"])),
  201. self.layer_map[node["nlayerid"]])
  202. },
  203. "to": {"agg": layer_aggregation(self.global_process((node["nto"]["x"], node["nto"]["z"])), self.model),
  204. "div": layer_divide(self.global_process((node["nto"]["x"], node["nto"]["z"])),
  205. self.layer_map[node["nlayerid"]])},
  206. "name": node["strname"],
  207. "vec12": {"agg": [], "div": []},
  208. "vec34": {"agg": [], "div": []}
  209. }
  210. fq = node['fq'] * 60
  211. formatted_fq = round(fq, 1)
  212. tun['fq'] = str(formatted_fq) + "m³/min"
  213. tun['fq_v'] = node['fq']
  214. if 'headVecList' in node and node['headVecList'] is not None and len(node['headVecList']) > 1:
  215. head_vec_from = node['headVecList'][0]
  216. head_vec_to = node['headVecList'][1]
  217. tun['head_vec_from'] = {
  218. "agg": layer_aggregation(self.global_process((head_vec_from["x"], head_vec_from["z"])),
  219. self.model),
  220. "div": layer_divide(self.global_process((head_vec_from["x"], head_vec_from["z"])),
  221. self.layer_map[node["nlayerid"]])
  222. }
  223. tun['head_vec_to'] = {
  224. "agg": layer_aggregation(self.global_process((head_vec_to["x"], head_vec_to["z"])),
  225. self.model),
  226. "div": layer_divide(self.global_process((head_vec_to["x"], head_vec_to["z"])),
  227. self.layer_map[node["nlayerid"]])
  228. }
  229. else:
  230. tun['head_vec_from'] = {
  231. "agg": None,
  232. "div": None
  233. }
  234. tun['head_vec_to'] = {
  235. "agg": None,
  236. "div": None
  237. }
  238. if "arrowShow" in node and node["arrowShow"] is not None and node["arrowShow"] != 0:
  239. tun['arrow_show'] = True
  240. else:
  241. tun['arrow_show'] = False
  242. for n in node["vec12"]:
  243. agg_point = layer_aggregation(self.global_process((n["x"], n["z"])), self.model)
  244. tun["vec12"]["agg"].append(agg_point)
  245. for n in node["layerVec12"]:
  246. div_point = layer_divide(self.global_process((n["x"], n["z"])), self.layer_map[node["nlayerid"]])
  247. tun["vec12"]["div"].append(div_point)
  248. for n in node["vec34"]:
  249. agg_point = layer_aggregation(self.global_process((n["x"], n["z"])), self.model)
  250. tun["vec34"]["agg"].append(agg_point)
  251. for n in node["layerVec34"]:
  252. div_point = layer_divide(self.global_process((n["x"], n["z"])), self.layer_map[node["nlayerid"]])
  253. tun["vec34"]["div"].append(div_point)
  254. if tun["type"] != "1" and len(tun["vec12"]) > 1 and len(tun["vec34"]) > 1:
  255. seg1 = tun["vec12"]['div'][0], tun["vec12"]['div'][-1]
  256. seg2 = tun["vec34"]['div'][0], tun["vec34"]['div'][-1]
  257. tun["width"] = core.min_distance_between_segments(seg1, seg2)
  258. tun["route"] = {
  259. "agg": core.calculate_angle_with_x_axis(tun['from']['agg'],
  260. tun['to']['agg']),
  261. "div": core.calculate_angle_with_x_axis(tun['from']['div'],
  262. tun['to']['div'])
  263. }
  264. else:
  265. tun["route"] = {
  266. "agg": 0,
  267. "div": 0
  268. }
  269. tun["width"] = 3.1415936
  270. tun_dict[tun["tun_id"]] = tun
  271. return tun_dict
  272. def get_gap_node(self):
  273. gaps_list = []
  274. for node in self.json['nodeFaceMap']:
  275. gaps = []
  276. for n in node:
  277. if 'screenX' in n:
  278. agg_point = layer_aggregation(self.global_process((n['screenX'], n['screenY'])), self.model)
  279. gaps.append(agg_point)
  280. gaps_list.append(gaps)
  281. return gaps_list
  282. def get_windows(self):
  283. layer_map = self.json["layerMap"]
  284. window_list = []
  285. for layer in tqdm(layer_map, desc=' 【风窗读取中】'):
  286. windows = layer[1]["windows"]
  287. for w in windows:
  288. tun = self.tun_dict.get(w["ntunid"])
  289. if tun is None: continue
  290. # tun = [tun_ for tun_ in self.tun_list if tun_.get("tun_id") == w["ntunid"]][0]
  291. window = {"layer": w["nlayerid"], "color": core.get_color_by_layer(w["nlayerid"]),
  292. "name": w["strname"],
  293. "id": w["id"],
  294. "center": {
  295. "agg": layer_aggregation(self.global_process((w['x'], w['z'])), self.model),
  296. "div": layer_divide(self.global_process((w['x'], w['z'])),
  297. self.layer_map[w["nlayerid"]])
  298. },
  299. 'route': {"agg": tun["route"]['agg'],
  300. "div": tun["route"]['div']
  301. },
  302. 'width': tun['width']
  303. }
  304. window_list.append(window)
  305. return window_list
  306. def get_windows_3d(self):
  307. layer_map = self.json["layerMap"]
  308. window_list = []
  309. for layer in tqdm(layer_map, desc=' 【风窗读取中】'):
  310. windows = layer[1]["windows"]
  311. for w in windows:
  312. tun = self.tun_plg_dict.get(w["ntunid"])
  313. if tun is None: continue
  314. # tun = [tun_ for tun_ in self.tun_list if tun_.get("tun_id") == w["ntunid"]][0]
  315. window = {"layer": w["nlayerid"], "color": core.get_color_by_layer(w["nlayerid"]),
  316. "name": w["strname"],
  317. "id": w["id"],
  318. "center": {
  319. "agg": layer_aggregation(self.global_process((w['screenX'], w['screenY'])), self.model),
  320. "div": layer_divide(self.global_process((w['screenX'], w['screenY'])),
  321. self.layer_map[w["nlayerid"]])
  322. },
  323. 'route': {"agg": tun["route"]['agg'],
  324. "div": tun["route"]['div']
  325. },
  326. 'width': tun['width']
  327. }
  328. window_list.append(window)
  329. return window_list
  330. def get_fans_3d(self):
  331. layer_map = self.json["layerMap"]
  332. fans_list = []
  333. for layer in tqdm(layer_map, desc=' 【风扇读取中】'):
  334. fans = layer[1]["fans"]
  335. for f in fans:
  336. tun = self.tun_plg_dict.get(f["ntunid"])
  337. if tun is None: continue
  338. fan = {"layer": f["nlayerid"], "color": core.get_color_by_layer(f["nlayerid"]),
  339. "name": f["strname"],
  340. "id": f["id"],
  341. "type": f["strtype"],
  342. "center": {
  343. "agg": layer_aggregation(self.global_process((f['screenX'], f['screenY'])), self.model),
  344. "div": layer_divide(self.global_process((f['screenX'], f['screenY'])),
  345. self.layer_map[f["nlayerid"]])
  346. },
  347. 'route': {"agg": tun["route"]['agg'],
  348. "div": tun["route"]['div']
  349. },
  350. 'width': tun['width']
  351. }
  352. fans_list.append(fan)
  353. return fans_list
  354. def get_ari_duct_dict(self):
  355. layer_map = self.json["layerMap"]
  356. ari_duct_dict = {}
  357. for layer in tqdm(layer_map, desc=' 【风筒读取中】'):
  358. fans = layer[1]["fans"]
  359. for f in fans:
  360. tun = self.tun_dict.get(f["ntunid"])
  361. if tun is None: continue
  362. ad_list = []
  363. for path in f['localFanCylinderPath']:
  364. ad = {
  365. "layer": f["nlayerid"],
  366. "from": {
  367. "agg": layer_aggregation(self.global_process((path[0]['x'], path[0]['z'])), self.model),
  368. "div": layer_divide(self.global_process((path[0]['x'], path[0]['z'])),
  369. self.layer_map[f["nlayerid"]]),
  370. },
  371. "to": {
  372. "agg": layer_aggregation(self.global_process((path[1]['x'], path[1]['z'])), self.model),
  373. "div": layer_divide(self.global_process((path[1]['x'], path[1]['z'])),
  374. self.layer_map[f["nlayerid"]]),
  375. },
  376. 'route': {"agg": tun["route"]['agg'],
  377. "div": tun["route"]['div']
  378. },
  379. 'width': tun['width']
  380. }
  381. ad_list.append(ad)
  382. ari_duct_dict[f['id']] = ad_list
  383. return ari_duct_dict
  384. def get_fans(self):
  385. layer_map = self.json["layerMap"]
  386. fans_list = []
  387. for layer in tqdm(layer_map, desc=' 【风扇读取中】'):
  388. fans = layer[1]["fans"]
  389. for f in fans:
  390. tun = self.tun_dict.get(f["ntunid"])
  391. if tun is None: continue
  392. fan = {"layer": f["nlayerid"], "color": core.get_color_by_layer(f["nlayerid"]),
  393. "type": f["strtype"],
  394. "name": f["strname"],
  395. "id": f["id"],
  396. "center": {
  397. "agg": layer_aggregation(self.global_process((f['x'], f['z'])), self.model),
  398. "div": layer_divide(self.global_process((f['x'], f['z'])), self.layer_map[f["nlayerid"]])
  399. },
  400. 'route': {"agg": tun["route"]['agg'],
  401. "div": tun["route"]['div']
  402. },
  403. 'width': tun['width']
  404. }
  405. fans_list.append(fan)
  406. return fans_list
  407. #
  408. # def get_fans_3d(self):
  409. # layer_map = self.json["layerMap"]
  410. # fans_list = []
  411. # for layer in tqdm(layer_map, desc=' 【风扇读取中】'):
  412. # fans = layer[1]["fans"]
  413. # for f in fans:
  414. # tun = self.tun_plg_dict.get(f["ntunid"])
  415. # if tun is None: continue
  416. # fan = {"layer": f["nlayerid"], "color": core.get_color_by_layer(f["nlayerid"]),
  417. # "type": f["strtype"],
  418. # "name": f["strname"],
  419. # "id": f["id"],
  420. # "center": {
  421. # "agg": layer_aggregation(self.global_process((f['screenX'], f['screenY'])), self.model),
  422. # "div": layer_divide(self.global_process((f['screenX'], f['screenY'])),
  423. # self.layer_map[f["nlayerid"]])
  424. # },
  425. # 'route': {"agg": tun["route"]['agg'],
  426. # "div": tun["route"]['div']
  427. # },
  428. # 'width': tun['width']
  429. # }
  430. # fans_list.append(fan)
  431. # return fans_list
  432. def get_gates_3d(self):
  433. layer_map = self.json["layerMap"]
  434. gate_list = []
  435. for layer in tqdm(layer_map, desc=' 【风门读取中】'):
  436. gates = layer[1]["gates"]
  437. for g in gates:
  438. tun = self.tun_plg_dict.get(g["ntunid"])
  439. if tun is None: continue
  440. gate = {"layer": g["nlayerid"], "color": core.get_color_by_layer(g["nlayerid"]),
  441. "type": g["strtype"],
  442. "name": g["strname"],
  443. "id": g["id"],
  444. "center": {
  445. "agg": layer_aggregation(self.global_process((g['screenX'], g['screenY'])), self.model),
  446. "div": layer_divide(self.global_process((g['screenX'], g['screenY'])),
  447. self.layer_map[g["nlayerid"]])
  448. },
  449. 'route': {"agg": tun["route"]['agg'],
  450. "div": tun["route"]['div']
  451. },
  452. 'width': tun['width']
  453. }
  454. gate_list.append(gate)
  455. return gate_list
  456. def get_sealed_list(self):
  457. layer_map = self.json["layerMap"]
  458. sealed_list = []
  459. for layer in tqdm(layer_map, desc=' 【密闭读取中】'):
  460. sealeds = layer[1]["obfurages"]
  461. for s in sealeds:
  462. tun = self.tun_dict.get(s["ntunid"])
  463. sealed = {"layer": s["nlayerid"], "color": core.get_color_by_layer(s["nlayerid"]),
  464. "id": s["id"],
  465. "center": {
  466. "agg": layer_aggregation(self.global_process((s['x'], s['z'])), self.model),
  467. "div": layer_divide(self.global_process((s['x'], s['z'])), self.layer_map[s["nlayerid"]])
  468. },
  469. 'route': {"agg": tun["route"]['agg'],
  470. "div": tun["route"]['div']
  471. },
  472. 'tun_id': s["ntunid"],
  473. 'width': tun['width']
  474. }
  475. sealed_list.append(sealed)
  476. return sealed_list
  477. def get_gates(self):
  478. layer_map = self.json["layerMap"]
  479. gate_list = []
  480. for layer in tqdm(layer_map, desc=' 【风门读取中】'):
  481. gates = layer[1]["gates"]
  482. for g in gates:
  483. tun = self.tun_dict.get(g["ntunid"])
  484. if tun is None: continue
  485. gate = {"layer": g["nlayerid"], "color": core.get_color_by_layer(g["nlayerid"]),
  486. "type": g["strtype"],
  487. "name": g["strname"],
  488. "id": g["id"],
  489. "center": {
  490. "agg": layer_aggregation(self.global_process((g['x'], g['z'])), self.model),
  491. "div": layer_divide(self.global_process((g['x'], g['z'])), self.layer_map[g["nlayerid"]])
  492. },
  493. 'route': {"agg": tun["route"]['agg'],
  494. "div": tun["route"]['div']
  495. },
  496. 'width': tun['width']
  497. }
  498. gate_list.append(gate)
  499. return gate_list
  500. def calculate_route_middle(self, path, layer_id):
  501. path_start = self.global_process((path[0]['x'], path[0]['z']))
  502. path_end = self.global_process((path[-1]['x'], path[-1]['z']))
  503. path_start_agg = layer_aggregation(path_start, self.model)
  504. path_end_agg = layer_aggregation(path_end, self.model)
  505. path_start_div = layer_divide(path_start, self.layer_map[layer_id])
  506. path_end_div = layer_divide(path_end, self.layer_map[layer_id])
  507. path_middle_agg = core.find_point_on_line(path_start_agg, path_end_agg, 1 / 2)
  508. path_middle_div = core.find_point_on_line(path_start_div, path_end_div, 1 / 2)
  509. route_agg = core.calculate_angle_with_x_axis(path_start_agg, path_end_agg)
  510. route_div = core.calculate_angle_with_x_axis(path_start_div, path_end_div)
  511. return {"middle": {"agg": path_middle_agg, "div": path_middle_div},
  512. "route": {"agg": route_agg, "div": route_div}}
  513. def calculate_segment_route_middle(self, vector, layer_id):
  514. path_start = self.global_process(vector[0])
  515. path_end = self.global_process(vector[1])
  516. path_start_agg = layer_aggregation(path_start, self.model)
  517. path_end_agg = layer_aggregation(path_end, self.model)
  518. path_start_div = layer_divide(path_start, self.layer_map[layer_id])
  519. path_end_div = layer_divide(path_end, self.layer_map[layer_id])
  520. path_middle_agg = core.find_point_on_line(path_start_agg, path_end_agg, 1 / 2)
  521. path_middle_div = core.find_point_on_line(path_start_div, path_end_div, 1 / 2)
  522. route_agg = core.calculate_angle_with_x_axis(path_start_agg, path_end_agg)
  523. route_div = core.calculate_angle_with_x_axis(path_start_div, path_end_div)
  524. return {"middle": {"agg": path_middle_agg, "div": path_middle_div},
  525. "route": {"agg": route_agg, "div": route_div}}
  526. def get_air_flow_3d(self):
  527. air_flow_3d_list = []
  528. for tun in tqdm(self.tun_plg_dict.values(), desc='【风流方向读取中】'):
  529. vec_agg = tun['from']['agg'], tun['to']['agg']
  530. vec_div = tun["from"]["div"], tun["to"]["div"]
  531. distance = core.distance(vec_agg[0], vec_agg[1])
  532. flow_len = tun['width'] * 5
  533. if distance < 6 * tun['width']:
  534. continue
  535. if tun['fq_v'] < 0.3:
  536. continue
  537. elif 6 * tun['width'] < distance < 12 * tun['width']:
  538. middle_agg = core.find_point_on_line(vec_agg[0], vec_agg[1], 1 / 2)
  539. middle_div = core.find_point_on_line(vec_div[0], vec_div[1], 1 / 2)
  540. air_flow = {
  541. "layer": tun['layer_id'],
  542. "center": {
  543. "agg": middle_agg,
  544. "div": middle_div
  545. },
  546. "route": {"agg": tun["route"]['agg'],
  547. "div": tun['route']['div']},
  548. "type": tun['air_type'],
  549. "len": flow_len
  550. }
  551. air_flow_3d_list.append(air_flow)
  552. else:
  553. space = int(distance // (100 * tun['width']))
  554. agg_points = core.divide_segment(vec_agg[0], vec_agg[1], space)[1:-1]
  555. div_points = core.divide_segment(vec_div[0], vec_div[1], space)[1:-1]
  556. for i in range(len(agg_points)):
  557. air_flow = {
  558. "layer": tun['layer_id'],
  559. "center": {
  560. "agg": agg_points[i],
  561. "div": div_points[i]
  562. },
  563. "route": {"agg": tun["route"]['agg'],
  564. "div": tun['route']['div']},
  565. "type": tun['air_type'],
  566. "len": flow_len
  567. }
  568. air_flow_3d_list.append(air_flow)
  569. return air_flow_3d_list
  570. def get_air_flow(self):
  571. air_flow_list = []
  572. tun_ids = [obj["tun_id"] for obj in self.sealed_list]
  573. for tun in tqdm(self.tun_dict.values(), desc='【风流方向读取中】'):
  574. vec_agg = tun['from']['agg'], tun['to']['agg']
  575. vec_div = tun["from"]["div"], tun["to"]["div"]
  576. distance = core.distance(vec_agg[0], vec_agg[1])
  577. flow_len = tun['width'] * 5
  578. if not tun['arrow_show']:
  579. if tun['tun_id'] in tun_ids: continue # 密闭空间不画风流
  580. if tun['fq_v'] < 0.3: continue
  581. if distance < 6 * tun['width']: continue
  582. if 50 < distance < 100:
  583. middle_agg = core.find_point_on_line(vec_agg[0], vec_agg[1], 1 / 2)
  584. middle_div = core.find_point_on_line(vec_div[0], vec_div[1], 1 / 2)
  585. air_flow = {
  586. "layer": tun['layer_id'],
  587. "center": {
  588. "agg": middle_agg,
  589. "div": middle_div
  590. },
  591. "route": {"agg": tun["route"]['agg'],
  592. "div": tun['route']['div']},
  593. "type": tun['air_type'],
  594. "len": flow_len
  595. }
  596. air_flow_list.append(air_flow)
  597. else:
  598. space = int(distance // (100 * tun['width']))
  599. agg_points = core.divide_segment(vec_agg[0], vec_agg[1], space)[1:-1]
  600. div_points = core.divide_segment(vec_div[0], vec_div[1], space)[1:-1]
  601. for i in range(len(agg_points)):
  602. air_flow = {
  603. "layer": tun['layer_id'],
  604. "center": {
  605. "agg": agg_points[i],
  606. "div": div_points[i]
  607. },
  608. "route": {"agg": tun["route"]['agg'],
  609. "div": tun['route']['div']},
  610. "type": tun['air_type'],
  611. "len": flow_len
  612. }
  613. air_flow_list.append(air_flow)
  614. return air_flow_list
  615. # def get_wind_flow(self):
  616. # path_point_map = self.json["pathLineMap"]
  617. # wind_flow_list = {
  618. # "in": [],
  619. # "no": [],
  620. # "out": [],
  621. # "use": []
  622. # }
  623. # for path_point in tqdm(path_point_map, desc=' 【风流方向读取中】'):
  624. # in_paths = path_point[1]['inPaths']
  625. # for path in in_paths:
  626. # middle_route = self.calculate_route_middle(path, path_point[0])
  627. # in_path = {
  628. # "layer": path_point[0],
  629. # "center": {
  630. # "agg": middle_route["middle"]["agg"],
  631. # "div": middle_route["middle"]["div"]
  632. # },
  633. # "route": {"agg": middle_route["route"]["agg"],
  634. # "div": middle_route["route"]["div"]},
  635. # "color": "3",
  636. # "type": "3"
  637. # }
  638. # wind_flow_list["in"].append(in_path)
  639. #
  640. # no_paths = path_point[1]['noPaths']
  641. # for path in no_paths:
  642. # middle_route = self.calculate_route_middle(path, path_point[0])
  643. # no_path = {
  644. # "layer": path_point[0],
  645. # "center": {
  646. # "agg": middle_route["middle"]["agg"],
  647. # "div": middle_route["middle"]["div"]
  648. # },
  649. # "route": {"agg": middle_route["route"]["agg"],
  650. # "div": middle_route["route"]["div"]},
  651. # "color": "3",
  652. # "type": "3"
  653. # }
  654. # wind_flow_list["no"].append(no_path)
  655. #
  656. # out_paths = path_point[1]['outPaths']
  657. # for path in out_paths:
  658. # middle_route = self.calculate_route_middle(path, path_point[0])
  659. # out_path = {
  660. # "layer": path_point[0],
  661. # "center": {
  662. # "agg": middle_route["middle"]["agg"],
  663. # "div": middle_route["middle"]["div"]
  664. # },
  665. # "route": {"agg": middle_route["route"]["agg"],
  666. # "div": middle_route["route"]["div"]},
  667. # "color": "1",
  668. # "type": "1"
  669. # }
  670. # wind_flow_list["out"].append(out_path)
  671. # use_paths = path_point[1]['usePaths']
  672. # for path in use_paths:
  673. # middle_route = self.calculate_route_middle(path, path_point[0])
  674. # use_path = {
  675. # "layer": path_point[0],
  676. # "center": {
  677. # "agg": middle_route["middle"]["agg"],
  678. # "div": middle_route["middle"]["div"]
  679. # },
  680. # "route": {"agg": middle_route["route"]["agg"],
  681. # "div": middle_route["route"]["div"]},
  682. # "color": "1",
  683. # "type": "1"
  684. # }
  685. # wind_flow_list["use"].append(use_path)
  686. #
  687. # return wind_flow_list
  688. def get_wind_bridge(self):
  689. layer_map = self.json["layerMap"]
  690. wind_bridge_list = []
  691. for layer in tqdm(layer_map, desc=' 【风桥读取中】'):
  692. cross_nodes = layer[1]['crossNodes']
  693. for cross_node in cross_nodes:
  694. center = cross_node['crossPoint']['x'], -cross_node['crossPoint']['y']
  695. # tun = [tun_ for tun_ in self.tun_list if tun_.get("tun_id") == cross_node['tun1Id']][0]
  696. tun = self.tun_dict.get(cross_node["tun1Id"])
  697. if tun is None: continue
  698. wind_bridge = {
  699. 'layer': layer[0],
  700. 'color': core.get_color_by_layer(layer[0]),
  701. "center": {
  702. "agg": layer_aggregation(self.global_process(center), self.model),
  703. "div": layer_divide(self.global_process(center), self.layer_map[layer[0]])
  704. },
  705. 'route': {"agg": tun["route"]['agg'],
  706. "div": tun['route']['div']},
  707. 'width': tun['width'] * 1.5114514
  708. }
  709. wind_bridge_list.append(wind_bridge)
  710. return wind_bridge_list
  711. def get_wind_bridge_3d(self):
  712. layer_map = self.json["layerMap"]
  713. wind_bridge_list = []
  714. for layer in tqdm(layer_map, desc=' 【风桥读取中】'):
  715. cross_nodes = layer[1]['crossNodes']
  716. for cross_node in cross_nodes:
  717. center = cross_node['crossPoint']['x'], -cross_node['crossPoint']['y']
  718. # tun = [tun_ for tun_ in self.tun_list if tun_.get("tun_id") == cross_node['tun1Id']][0]
  719. tun = self.tun_plg_dict.get(cross_node["tun1Id"])
  720. if tun is None: continue
  721. wind_bridge = {
  722. 'layer': layer[0],
  723. 'color': core.get_color_by_layer(layer[0]),
  724. "center": {
  725. "agg": layer_aggregation(self.global_process(center), self.model),
  726. "div": layer_divide(self.global_process(center), self.layer_map[layer[0]])
  727. },
  728. 'route': {"agg": tun["route"]['agg'],
  729. "div": tun['route']['div']},
  730. 'width': tun['width'] * 1.5114514
  731. }
  732. wind_bridge_list.append(wind_bridge)
  733. return wind_bridge_list
  734. def layer_aggregation(point, model):
  735. coefficient_x = model['cadOffsetX'] if 'cadOffsetX' in model.keys() else 0
  736. coefficient_y = model['cadOffsetY'] if 'cadOffsetY' in model.keys() else 0
  737. coefficient_route = model['cadAngle'] if 'cadAngle' in model.keys() else 0
  738. point_ = core.rotate_point_around_another(point, (0, 0), coefficient_route)
  739. point_ = point_[0] + coefficient_x, point_[1] + coefficient_y
  740. return point_
  741. def layer_divide(point, layer):
  742. coefficient_x = layer['cadOffsetX'] if 'cadOffsetX' in layer.keys() or layer['cadOffsetX'] is None else 0
  743. coefficient_y = layer['cadOffsetY'] if 'cadOffsetY' in layer.keys() or layer['cadOffsetY'] is None else 0
  744. coefficient_route = layer['cadAngle'] if 'cadAngle' in layer.keys() or layer['cadAngle'] is None else 0
  745. point_ = core.rotate_point_around_another(point, (0, 0), coefficient_route)
  746. point_ = point_[0] + coefficient_x, point_[1] + coefficient_y
  747. return point_
  748. def request_graph_point(url):
  749. response = requests.get(url, timeout=10)
  750. print(f"请求耗时{url} {response.elapsed.total_seconds()} 秒")
  751. cad_json = {}
  752. if response.status_code == 200:
  753. cad_json = response.json() # 将响应内容解析为JSON格式
  754. else:
  755. print(f"请求失败,状态码:{response.status_code}")
  756. return cad_json
  757. def check_node(node):
  758. flag = True
  759. if node["vec12"] is None or node["vec34"] is None:
  760. flag = False
  761. return flag
  762. if "layerVec12" not in node or "layerVec34" not in node or node["layerVec12"] is None or node["layerVec34"] is None:
  763. flag = False
  764. return flag
  765. if len(node["vec12"]) < 1 or len(node["vec34"]) < 1:
  766. flag = False
  767. return flag
  768. if len(node["layerVec12"]) < 1 or len(node["layerVec34"]) < 1:
  769. flag = False
  770. return flag
  771. else:
  772. if node["vec12"][0]['x'] is None or node["vec12"][0]['z'] is None:
  773. flag = False
  774. if node["vec12"][1]['x'] is None or node["vec12"][1]['z'] is None:
  775. flag = False
  776. if node["vec34"][0]['x'] is None or node["vec34"][0]['z'] is None:
  777. flag = False
  778. if node["vec34"][1]['x'] is None or node["vec34"][1]['z'] is None:
  779. flag = False
  780. if node["layerVec12"][0]['x'] is None or node["layerVec12"][0]['z'] is None:
  781. flag = False
  782. if node["layerVec12"][1]['x'] is None or node["layerVec12"][1]['z'] is None:
  783. flag = False
  784. if node["layerVec34"][0]['x'] is None or node["layerVec34"][0]['z'] is None:
  785. flag = False
  786. if node["layerVec34"][1]['x'] is None or node["layerVec34"][1]['z'] is None:
  787. flag = False
  788. return flag