From 0555479ab40c06dc123fc6af44d5f7c6418952a0 Mon Sep 17 00:00:00 2001 From: n3040 Date: Mon, 25 Jul 2022 02:05:08 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=AE=8C=E6=88=90=E4=BA=86=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=E8=80=83=E8=99=91=E8=80=90=E5=BC=A0=E4=B8=B2=E9=87=8D?= =?UTF-8?q?=E5=BC=A7=E5=9E=82=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PWFile.py | 20 +++++-- main.py | 161 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 152 insertions(+), 29 deletions(-) diff --git a/PWFile.py b/PWFile.py index e6fdaac..0c62053 100644 --- a/PWFile.py +++ b/PWFile.py @@ -11,10 +11,12 @@ class SEntry: mileage_in_s: int = 0 back_k: float = 0 forth_k: float = 0 - altitude_off: float = 0 + altitude_off: float = 0#中心桩高差 foundation_low: float = 0 # 基降 fitting: str = "" # 金具 is_tension_tower: bool = False + back_representive_span: float = 0 # 代表档距 + forth_representive_span: float = 0 # 代表档距 class SFile: @@ -26,8 +28,9 @@ class SFile: tower_dic = self.tower_dic with open(s_file_path, encoding="gbk") as s_file_obj: new_k = 0 + new_reprtv_span = 0 last_k = -1 - # next_is_tension_tower=False + last_reprtv_span = -1 last_tower_name = "" for line in s_file_obj: norm_line = line.strip() @@ -35,6 +38,9 @@ class SFile: continue if "首端转角号" in norm_line: new_k = float(norm_line.split(":")[-1].replace("E", "e")) # 模板系数 + new_reprtv_span = float( + re.findall("代表档距 : (\d+) 模板系数", norm_line)[0] + ) # 代表档距 continue if "塔号" in norm_line: # next_is_tension_tower=True @@ -48,19 +54,20 @@ class SFile: tower_dic[tower_name].forth_k = new_k # 更新耐张塔前侧k值。 continue s_entry = SEntry() - # s_entry.is_tension_tower=next_is_tension_tower - # next_is_tension_tower=False s_entry.tower_name = tower_name last_tower_name = tower_name s_entry.tower_type = sep_entry[6] s_entry.tower_height = float(sep_entry[7]) s_entry.mileage_in_s = float(sep_entry[1]) s_entry.back_k = last_k + s_entry.back_representive_span = last_reprtv_span s_entry.forth_k = new_k + s_entry.forth_representive_span = new_reprtv_span s_entry.altitude_off = float(sep_entry[3]) s_entry.foundation_low = float(sep_entry[4]) s_entry.fitting = sep_entry[8] last_k = s_entry.forth_k + last_reprtv_span = s_entry.forth_representive_span tower_dic[tower_name] = s_entry tower_dic[list(tower_dic.keys())[-1]].forth_k = -1 tower_dic[list(tower_dic.keys())[0]].is_tension_tower = True @@ -85,3 +92,8 @@ class Fitting: fit_name = fit[0] fit_parameter = next(ite) self.fitting_length_dic[fit_name] = float(fit_parameter[2]) / 1000 +@define +class ColorEnume: + wire_color_rgb=[122, 219, 245] + tree_color_rgb=[122, 219, 245] + ground_color_rgb=[116, 230, 165] \ No newline at end of file diff --git a/main.py b/main.py index 8203ef7..11ee4c9 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,13 @@ from tkinter.messagebox import NO import xlwings as xw -from PWFile import SFile, Fitting +from PWFile import SFile, Fitting,ColorEnume from Apyautocad import Apyautocad, APoint import os import re import numpy as np from time import sleep from attrs import define +from typing import List # 读取Z文件,找到Z断面第一个点的坐标 def plane_z_origin(z_file_path): @@ -33,20 +34,34 @@ def curve_fun(x, span, k, gaocha): return x * gaocha / span - x * (span - x) * k +def np2d_to_array(np2d): # 把2维numpy数组转换成cad可以用的数组 + t = np.hstack((np2d, np.zeros((np2d.shape[0], 1)))).reshape(1, np2d.shape[0] * 3) + return t[0] + + class StringImpactExcel: def __init__(self) -> None: # self._wb=None pass - def read(self, wb): - # with xw.App(visible=True) as app: + def read(self, wb, gaocha, span, tension): pos代表档距 = "F13" pos档距 = "L13" pos高差 = "R13" pos张力 = "AB18" - pos档距21 = "E25" + pos总串长 = "C8" sheet = wb.sheets["3225-3226"] - print(sheet.range("V25:V46").value) + sheet.range(pos高差).value = gaocha + sheet.range(pos档距).value = span + sheet.range(pos张力).value = tension + string_length = sheet.range(pos总串长).value + # print(sheet.range("V25:V46").value) + x = np.linspace(string_length, span, int(span / 5), endpoint=True) + x[0] = sheet.range("E23").value + x[1]=sheet.range("E24").value + sheet.range(f"E25:E{25+len(x)-3}").value = x[2:].reshape(len(x[2:]), 1) + y = np.array(sheet.range(f"V23:V{23+len(x)-1}").value)/2#表格是乘以了2的,为了和x保持一致,没有乘比例。 + return (x, y) def set_true_color(object, r, g, b): @@ -55,6 +70,94 @@ def set_true_color(object, r, g, b): object.TrueColor = true_color +@define +class StringImpactPlate: + _dwg_file_path: str + _s_file_path: str + _draw_tower_name: List[str] + # _tension_section:int#耐张段数量 + _continouse_tension_excel: str + _string_impact_curve_excel: str + + def _find_target_towe_index(self, tower_name_list: List[str]): + index = [] + for foo in self._draw_tower_name: + index.append(tower_name_list.index(foo)) + return index + + def draw(self): + # 计算代表档距 + s_file = SFile() + s_file.open(self._s_file_path) + tower_dict = s_file.tower_dic + tower_key_list = list(tower_dict.keys()) + draw_tower_index = self._find_target_towe_index(tower_key_list) + fitting_file_path = deduce_fit_db_from_cad_path(self._dwg_file_path) + fitting = Fitting(fitting_file_path) + z_file_path = deduce_zfile_from_cad_path(self._dwg_file_path) + plate_origin = plane_z_origin(z_file_path) + with xw.App(visible=True) as excel_app, Apyautocad( + create_if_not_exists=True, visible=True, auto_close=False + ) as cad: + continouse_wb = excel_app.books.open("张力计算(临界档距公式法V20090602)-送电室版).xls") + continouse_sheet = continouse_wb.sheets["2710导线-单回1250-70"] + wb_string_impact = excel_app.books.open( + "特高压耐张串影响弧垂计算(送电室2018人员版)1122-1218.xls" + ) + stringImpactExcel = StringImpactExcel() + cad.app.Documents.Open(self._dwg_file_path) + sleep(1) + for draw_tower_foo in draw_tower_index: + draw_tower_key = tower_key_list[draw_tower_foo] + tower_info = tower_dict[draw_tower_key] + forth_reprtv_span = tower_info.forth_representive_span + continouse_sheet.range("B69").value = forth_reprtv_span + high_temperature_tension = continouse_sheet.range("L69").value + forth_tower_info = tower_dict[tower_key_list[draw_tower_foo + 1]] + gaocha = ( + ( + forth_tower_info.tower_height + - forth_tower_info.foundation_low + - fitting.fitting_length_dic[forth_tower_info.fitting] + ) + - ( + tower_info.tower_height + - tower_info.foundation_low + - fitting.fitting_length_dic[tower_info.fitting] + ) + + forth_tower_info.altitude_off + ) + span = forth_tower_info.mileage_in_s - tower_info.mileage_in_s + (x, y) = stringImpactExcel.read( + wb_string_impact, gaocha, span, high_temperature_tension + ) + # TODO: 计算累计里程和高差 + plot_x = (plate_origin[0] + x / 5).reshape(len(x), 1) + plot_y = (plate_origin[1] + (tower_info.tower_height-tower_info.foundation_low+ y)*2 ).reshape(len(x), 1) + plot_vector = np2d_to_array(np.hstack((plot_x, plot_y))) + added_curve=cad.model.AddPolyLine(plot_vector) + set_true_color(added_curve,*ColorEnume.wire_color_rgb) + plot_ground_y=plot_y-18*2 + plot_ground_vector=np2d_to_array(np.hstack((plot_x, plot_ground_y))) + added_ground_curve = cad.model.AddPolyLine(plot_ground_vector) + set_true_color(added_ground_curve, *ColorEnume.ground_color_rgb) + plot_tree_y = plot_y - 13.5 * 2 + plot_tree_vector = np2d_to_array(np.hstack((plot_x, plot_tree_y))) + added_tree_curve = cad.model.AddPolyLine(plot_tree_vector) + set_true_color(added_tree_curve, *ColorEnume.tree_color_rgb) + pass + + # can_start=False + # tower_dict_iterator=iter(list(tower_dict.keys())) + # for tower_info_key in tower_dict_iterator: + # tower_info=tower_dict[tower_info_key] + # if tower_info.tower_name==self._draw_tower_name: + # if tower_info.is_tension_tower==False: + # raise Exception('耐张段影响弧垂第1基塔不是耐张塔!') + # can_start=True + # if can_start: + + @define class ContinuousPlate: _dwg_file_path: str @@ -71,6 +174,11 @@ class ContinuousPlate: # stringImpactExcel = StringImpactExcel() # stringImpactExcel.read(wb_string_impact) dwg_file_path = self._dwg_file_path + # with xw.App(visible=False) as app: + # wb = app.books.open('张力计算(临界档距公式法V20090602)-送电室版).xls') + # sheet = wb.sheets['2710导线-单回1250-70'] + # sheet.range('B69').value=120 + # print(sheet.range('L69').value) with Apyautocad( create_if_not_exists=True, visible=False, auto_close=False ) as cad: @@ -86,14 +194,14 @@ class ContinuousPlate: accu_mileage = 0 # 累计档距 accu_altitude_off = 0 # 累计高差 is_first_tower = True - can_start_draw=-1 - start_tower_name=self._from_tower_name - draw_count=0 + can_start_draw = -1 + start_tower_name = self._from_tower_name + draw_count = 0 for tower in s_file.tower_dic: tower_info = s_file.tower_dic[tower] - if tower_info.tower_name==start_tower_name: - can_start_draw=0 - if can_start_draw<0 or draw_count>self._draw_tower_count-1: + if tower_info.tower_name == start_tower_name: + can_start_draw = 0 + if can_start_draw < 0 or draw_count > self._draw_tower_count - 1: break if not last_tower_info: last_tower_info = tower_info @@ -131,7 +239,7 @@ class ContinuousPlate: ) # 画杆高 cad.model.AddLine(tower_start, tower_end) - draw_count+=1 + draw_count += 1 # 画弧垂 if not is_first_tower: # 从第二基塔开始画 draw_k = tower_info.back_k @@ -198,7 +306,7 @@ class ContinuousPlate: added_curve = cad.model.AddPolyLine( draw_point.reshape(1, draw_curve_x.shape[0] * 3)[0] ) - set_true_color(added_curve, 122, 219, 245) + set_true_color(added_curve, Color) added_ground_curve = cad.model.AddPolyLine( draw_ground_curve_point.reshape( 1, draw_ground_curve_y.shape[0] * 3 @@ -217,11 +325,6 @@ class ContinuousPlate: def main1(): - # with xw.App(visible=False) as app: - # wb = app.books.open('张力计算(临界档距公式法V20090602)-送电室版).xls') - # sheet = wb.sheets['2710导线-单回1250-70'] - # sheet.range('B69').value=120 - # print(sheet.range('L69').value) s_file = SFile() s_file.open(r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\S033.DAT") # with xw.App(visible=False) as app: @@ -338,30 +441,38 @@ def main1(): added_curve = cad.model.AddPolyLine( draw_point.reshape(1, draw_curve_x.shape[0] * 3)[0] ) - set_true_color(added_curve, 122, 219, 245) + set_true_color(added_curve, *ColorEnume.wire_color_rgb) added_ground_curve = cad.model.AddPolyLine( draw_ground_curve_point.reshape( 1, draw_ground_curve_y.shape[0] * 3 )[0] ) - set_true_color(added_ground_curve, 122, 219, 245) + set_true_color(added_ground_curve, *ColorEnume.ground_color_rgb) added_tree_curve = cad.model.AddPolyLine( draw_tree_curve_point.reshape(1, draw_tree_curve_y.shape[0] * 3)[0] ) - set_true_color(added_tree_curve, 116, 230, 165) + set_true_color(added_tree_curve, *ColorEnume.tree_color_rgb) is_first_tower = False last_tower_info = tower_info doc.SaveAs(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg") def main(): - continousePlate = ContinuousPlate( + # continousePlate = ContinuousPlate( + # r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg", + # r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\S033.DAT", + # "N3339", + # 7, + # ) + # continousePlate.draw(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg") + string_impact_plate = StringImpactPlate( r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg", r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\S033.DAT", - "N3339", - 7, + ["N3339"], + "", + "", ) - continousePlate.draw(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg") + string_impact_plate.draw() if __name__ == "__main__":