from tqdm import tqdm import core from dict.dict_manager import DictManager from entity.Line import Plg, Line from entity.Node import Node from entity.primitives import Tun3d, TunText, TunGap, AirFlow, Fan, Window, Gate standard_width = 0.5 class DictManger3D(DictManager): def __init__(self, original_data): super().__init__(original_data) self.gaps_list = [] self.get_tun_gap() self.get_tun3d_dict() self.get_tun_text() self.get_air_flow() self.get_windows_3d() self.get_gates_3d() self.get_fans_3d() def get_tun3d_dict(self): node_list = self.original_data["tunsMap"] for node in tqdm(node_list, desc=' 【巷道读取中】'): obj = node[1] vec_l_series = [ (obj['vecL1']['x'], obj['vecL1']['z']), (obj['vecL2']['x'], obj['vecL2']['z']), (obj['vecL3']['x'], obj['vecL3']['z']), (obj['vecL4']['x'], obj['vecL4']['z']) ] vec_r_series = [ (obj['vecR1']['x'], obj['vecR1']['z']), (obj['vecR2']['x'], obj['vecR2']['z']), (obj['vecR3']['x'], obj['vecR3']['z']), (obj['vecR4']['x'], obj['vecR4']['z']) ] vec_b_series = [ (obj['vec1']['x'], obj['vec1']['z']), (obj['vec2']['x'], obj['vec2']['z']), (obj['vec3']['x'], obj['vec3']['z']), (obj['vec4']['x'], obj['vec4']['z']) ] from_ = (obj["nfrom"]["x"], obj["nfrom"]["z"]) to_ = (obj["nto"]["x"], obj["nto"]["z"]) vec_middle = from_, to_ center = core.find_point_on_line(from_, to_, 1 / 2) center = Node(center, '3d', 0) middle_line = Line(vec_middle, '3d', 0) color = self.layer_map[obj['nlayerid']]['ncolor'] color = core.hex_to_rgb(color) width = core.min_distance_between_segments(vec_b_series[:2], vec_b_series[2:]) t3d = Tun3d(obj['ntunid'], obj["nlayerid"], obj["strname"], center, middle_line, Plg(vec_l_series), Plg(vec_r_series), Plg(vec_b_series), obj['fq'], color, width, obj['arrowShow'], obj['nairtype']) self.tun_dict[obj['ntunid']] = t3d def get_tun_text(self): node_list = self.original_data["tunsMap"] tun_text_dict = {} for node in tqdm(node_list, desc=' 【巷道文字读取中】'): node = node[1] if node["tunType"] == '1': continue tun = self.tun_dict.get(node["ntunid"]) tun_key = node["strname"] + f'{ core.calculate_angle_with_x_axis(tun.middle_line.original_line[0], tun.middle_line.original_line[1]):.7f}' if tun_key not in tun_text_dict: # 如果不在,则初始化一个新的空列表作为值 tun_text_dict[tun_key] = { "id": tun.id, "text": node["strname"], "name": tun.name, "layer_id": tun.layer_id, "width": standard_width, "color": tun.color, "tun_middle_lines": [] } from_ = (node["nfrom"]["x"], node["nfrom"]["z"]) to_ = (node["nto"]["x"], node["nto"]["z"]) # 将 from_ 和 to_ 坐标添加到 tun_text 对应的列表中 tun_text_dict[tun_key]['tun_middle_lines'].extend([from_, to_]) for tun_text in tqdm(tun_text_dict.values(), desc=' 【巷道文字读取中】'): tun_middle_lines = tun_text['tun_middle_lines'] farthest = core.farthest_points(tun_middle_lines) divIndex = self.layer_map[tun_text['layer_id']]['divIndex'] middle_line = Line(farthest, '3d', divIndex) center = core.find_point_on_line(farthest[0], farthest[1], 1 / 2) # center_node = Node(center, '3d', divIndex) tt = TunText(tun_text['id'], tun_text['layer_id'], tun_text['text'], center_node, middle_line, tun_text['width'], tun_text['color'], 0) tun_length = core.distance(middle_line.agg_line[0], middle_line.agg_line[1]) text_len = len(tun_text['text']) * 0.7 if tun_length * 0.5 > text_len: self.tun_text_list.append(tt) def get_tun_gap(self): for node in self.original_data['nodeFaceMap']: plg = [] for n in node: if 'screenX' in n: plg.append((n['screenX'], n['screenY'])) plg_obj = Plg(plg) self.gaps_list.append(TunGap(plg_obj)) def get_air_flow(self): for tun in tqdm(self.tun_dict.values(), '【风流读取中】'): if tun.arrow_show == 0: continue; if tun.fq < 0.3: continue tun_len = core.distance(tun.middle_line.original_line[0],tun.middle_line.original_line[1]) if tun_len < 7 * tun.width: continue divIndex = self.layer_map[tun.layer_id]['divIndex'] if tun_len < 50 * tun.width: center = tun.center air_flow = AirFlow(core.get_random_id(),tun.layer_id,'',center,tun.middle_line,tun.width,tun.color,tun.air_type) self.air_flow_list.append(air_flow) else: space = int(tun_len // (50 * tun.width)) points = core.divide_segment(tun.middle_line.original_line[0], tun.middle_line.original_line[1], space)[1:-1] for i in range(len(points)): center = Node(points[i],'3d',divIndex) air_flow = AirFlow(core.get_random_id(), tun.layer_id, '', center, tun.middle_line, standard_width, tun.color, tun.air_type) self.air_flow_list.append(air_flow) def get_fans_3d(self): layer_map = self.original_data["layerMap"] for layer in tqdm(layer_map, desc='【风扇读取中】'): items = layer[1]['fans'] for item in items: tun = self.tun_dict.get(item["ntunid"]) if tun is None: continue divIndex = self.layer_map[item['nlayerid']]['divIndex'] center = Node((item['screenX'], item['screenY']), '3d', divIndex) color = core.hex_to_rgb(self.layer_map[item['nlayerid']]['ncolor']) fan = Fan(item['id'],item['nlayerid'],item['strname'],center,tun.middle_line,standard_width,color,item['strtype']) self.fan_list.append(fan) def get_windows_3d(self): layer_map = self.original_data["layerMap"] for layer in tqdm(layer_map, desc='【风窗读取中】'): items = layer[1]['windows'] for item in items: tun = self.tun_dict.get(item["ntunid"]) if tun is None: continue divIndex = self.layer_map[item['nlayerid']]['divIndex'] center = Node((item['screenX'], item['screenY']), '3d', divIndex) color = core.hex_to_rgb(self.layer_map[item['nlayerid']]['ncolor']) window = Window(item['id'],item['nlayerid'],item['strname'],center,tun.middle_line,standard_width,color) self.window_list.append(window) def get_gates_3d(self): layer_map = self.original_data["layerMap"] for layer in tqdm(layer_map, desc='【风门读取中】'): items = layer[1]['gates'] for item in items: tun = self.tun_dict.get(item["ntunid"]) if tun is None: continue divIndex = self.layer_map[item['nlayerid']]['divIndex'] center = Node((item['screenX'], item['screenY']), '3d', divIndex) color = core.hex_to_rgb(self.layer_map[item['nlayerid']]['ncolor']) gate = Gate(item['id'],item['nlayerid'],item['strname'],center,tun.middle_line,standard_width,color) self.gate_list.append(gate)