1.塔呼高可以有小数。

This commit is contained in:
n3040 2022-08-06 23:08:32 +08:00
parent 0dc1f3e153
commit 2c0c013b73
2 changed files with 138 additions and 115 deletions

249
PWFile.py
View File

@ -1,3 +1,4 @@
import math
import os.path import os.path
from collections import OrderedDict from collections import OrderedDict
import re import re
@ -20,14 +21,14 @@ class SEntry:
tower_height: float = 0 tower_height: float = 0
tower_type: str = "" tower_type: str = ""
mileage_in_s: int = 0 mileage_in_s: int = 0
back_k: float = 0 back_k: float = 0 # 杆塔后侧的k值
forth_k: float = 0 forth_k: float = 0 # 杆塔前侧的k值
altitude_off: float = 0 # 中心桩高差 altitude_off: float = 0 # 中心桩高差
foundation_low: float = 0 # 基降 foundation_low: float = 0 # 基降
fitting: str = "" # 金具 fitting: str = "" # 金具
is_tension_tower: bool = False is_tension_tower: bool = False # 是否为耐张塔
back_representive_span: float = 0 # 代表档距 back_representive_span: float = 0 # 后侧代表档距
forth_representive_span: float = 0 # 代表档距 forth_representive_span: float = 0 # 前侧代表档距
class SFile: class SFile:
@ -65,7 +66,7 @@ class SFile:
tower_dic[tower_name].forth_k = new_k # 更新耐张塔前侧k值。 tower_dic[tower_name].forth_k = new_k # 更新耐张塔前侧k值。
tower_dic[ tower_dic[
tower_name tower_name
].forth_representive_span = new_reprtv_span # 更新耐张塔前侧k值 ].forth_representive_span = new_reprtv_span # 更新耐张塔前侧代表档距
last_k = tower_dic[tower_name].forth_k last_k = tower_dic[tower_name].forth_k
last_reprtv_span = tower_dic[tower_name].forth_representive_span last_reprtv_span = tower_dic[tower_name].forth_representive_span
continue continue
@ -91,7 +92,7 @@ class SFile:
@define @define
class Fitting: class Fitting: # 金具
fitting_length_dic = {} fitting_length_dic = {}
def __init__(self, fitting_file_path): def __init__(self, fitting_file_path):
@ -140,7 +141,7 @@ def deduce_fit_db_from_cad_path(cad_file_path):
return os.path.join(dwg_file_name[0], "Fit.db") return os.path.join(dwg_file_name[0], "Fit.db")
def curve_fun(x, span, k, gaocha): def curve_fun(x, span, k, gaocha): # 弧垂公式
return x * gaocha / span - x * (span - x) * k return x * gaocha / span - x * (span - x) * k
@ -250,102 +251,104 @@ class StringImpactPlate:
stringImpactExcel = StringImpactExcel() stringImpactExcel = StringImpactExcel()
sleep(1) sleep(1)
draw_first_tower_key = tower_key_list[draw_tower_index[0]] draw_first_tower_key = tower_key_list[draw_tower_index[0]]
first_tower_info = tower_dict[draw_first_tower_key] first_tower_info: SEntry = tower_dict[draw_first_tower_key]
forth_reprtv_span = first_tower_info.forth_representive_span forth_reprtv_span = first_tower_info.forth_representive_span
continouse_sheet.range("B69").value = forth_reprtv_span continouse_sheet.range("B69").value = forth_reprtv_span
high_temperature_tension = continouse_sheet.range("L69").value high_temperature_tension = continouse_sheet.range("L69").value
forth_tower_info: SEntry = tower_dict[tower_key_list[draw_tower_index[0] + 1]] if first_tower_info.is_tension_tower:
if forth_tower_info.is_tension_tower: forth_tower_info: SEntry = tower_dict[tower_key_list[draw_tower_index[0] + 1]]
forth_tower_fitting_length = 0 if forth_tower_info.is_tension_tower:
else: forth_tower_fitting_length = 0
forth_tower_fitting_length = fitting.fitting_length_dic[ else:
forth_tower_info.fitting forth_tower_fitting_length = fitting.fitting_length_dic[
] forth_tower_info.fitting
gaocha_of_first_tower = ( ]
( gaocha_of_first_tower = (
forth_tower_info.tower_height (
- forth_tower_info.foundation_low forth_tower_info.tower_height
- forth_tower_fitting_length - forth_tower_info.foundation_low
- forth_tower_fitting_length
)
- (first_tower_info.tower_height - first_tower_info.foundation_low)
+ forth_tower_info.altitude_off
) )
- (first_tower_info.tower_height - first_tower_info.foundation_low) span_of_first_tower = (
+ forth_tower_info.altitude_off forth_tower_info.mileage_in_s - first_tower_info.mileage_in_s
) )
span_of_first_tower = ( (x, y) = stringImpactExcel.read(
forth_tower_info.mileage_in_s - first_tower_info.mileage_in_s wb_string_impact,
) gaocha_of_first_tower,
(x, y) = stringImpactExcel.read( span_of_first_tower,
wb_string_impact, high_temperature_tension,
gaocha_of_first_tower, )
span_of_first_tower, # TODO: 没有考虑断面中间有耐张塔的情况
high_temperature_tension, plot_x = (plate_origin[0] + x / 5).reshape(len(x), 1)
) plot_y = (
# TODO: 没有考虑断面中间有耐张塔的情况 plate_origin[1]
plot_x = (plate_origin[0] + x / 5).reshape(len(x), 1) + (first_tower_info.tower_height - first_tower_info.foundation_low + y) * 2
plot_y = ( ).reshape(len(x), 1)
plate_origin[1] self._plot(cad, plot_x, plot_y)
+ (first_tower_info.tower_height - first_tower_info.foundation_low + y) * 2 # 记录
).reshape(len(x), 1) record = StringImpactExcelRecord()
self._plot(cad, plot_x, plot_y) record.from_tower_name = first_tower_info.tower_name
# 记录 record.fo_tower_name = forth_tower_info.tower_name
record = StringImpactExcelRecord() record.span = span_of_first_tower
record.from_tower_name = first_tower_info.tower_name record.representive_span = first_tower_info.forth_representive_span
record.fo_tower_name = forth_tower_info.tower_name record.gaocha = gaocha_of_first_tower
record.span = span_of_first_tower record.tension = high_temperature_tension
record.representive_span = first_tower_info.forth_representive_span self.excel_record_list.append(record)
record.gaocha = gaocha_of_first_tower
record.tension = high_temperature_tension
self.excel_record_list.append(record)
# 画右侧耐张塔的弧垂 # 画右侧耐张塔的弧垂
draw_last_tower_key = tower_key_list[draw_tower_index[-1]] draw_last_tower_key = tower_key_list[draw_tower_index[-1]]
last_tower_info = tower_dict[draw_last_tower_key] # 最后一个塔位 last_tower_info:SEntry = tower_dict[draw_last_tower_key] # 最后一个塔位
back_reprtv_span = last_tower_info.back_representive_span if last_tower_info.is_tension_tower:
back_tower_info: SEntry = tower_dict[tower_key_list[draw_tower_index[-1] - 1]] back_reprtv_span = last_tower_info.back_representive_span
if back_tower_info.is_tension_tower: back_tower_info: SEntry = tower_dict[tower_key_list[draw_tower_index[-1] - 1]]
back_tower_fitting_length = 0 if back_tower_info.is_tension_tower:
else: back_tower_fitting_length = 0
back_tower_fitting_length = fitting.fitting_length_dic[ else:
back_tower_info.fitting back_tower_fitting_length = fitting.fitting_length_dic[
] back_tower_info.fitting
gaocha_of_last_tower = ( ]
( gaocha_of_last_tower = (
back_tower_info.tower_height (
- back_tower_info.foundation_low back_tower_info.tower_height
- back_tower_fitting_length - back_tower_info.foundation_low
- back_tower_fitting_length
)
- (last_tower_info.tower_height - last_tower_info.foundation_low)
- last_tower_info.altitude_off
) )
- (last_tower_info.tower_height - last_tower_info.foundation_low) span_of_last_tower = last_tower_info.mileage_in_s - back_tower_info.mileage_in_s
- last_tower_info.altitude_off (x, y) = stringImpactExcel.read(
) wb_string_impact,
span_of_last_tower = last_tower_info.mileage_in_s - back_tower_info.mileage_in_s gaocha_of_last_tower,
(x, y) = stringImpactExcel.read( span_of_last_tower,
wb_string_impact, high_temperature_tension,
gaocha_of_last_tower,
span_of_last_tower,
high_temperature_tension,
)
plot_last_tower_x = (
plate_origin[0]
+ (
tower_dict[tower_key_list[draw_tower_index[-1]]].mileage_in_s
- tower_dict[tower_key_list[draw_tower_index[0]]].mileage_in_s
) )
/ 5 plot_last_tower_x = (
- x / 5 # 从右往左画 plate_origin[0]
).reshape(len(x), 1) + (
accumulate_altitude_off = np.sum( tower_dict[tower_key_list[draw_tower_index[-1]]].mileage_in_s
[ - tower_dict[tower_key_list[draw_tower_index[0]]].mileage_in_s
tower_dict[tower_key_list[bar]].altitude_off )
for bar in range(draw_tower_index[0] + 1, draw_tower_index[-1] + 1) / 5
] - x / 5 # 从右往左画
) ).reshape(len(x), 1)
plot_last_tower_y = ( accumulate_altitude_off = np.sum(
plate_origin[1] [
+ accumulate_altitude_off * 2 tower_dict[tower_key_list[bar]].altitude_off
+ (last_tower_info.tower_height - last_tower_info.foundation_low + y) * 2 for bar in range(draw_tower_index[0] + 1, draw_tower_index[-1] + 1)
).reshape(len(x), 1) ]
plot_last_tower_vector = np2d_to_array( )
np.hstack((plot_last_tower_x, plot_last_tower_y)) plot_last_tower_y = (
) plate_origin[1]
self._plot(cad, plot_last_tower_x, plot_last_tower_y) + accumulate_altitude_off * 2
+ (last_tower_info.tower_height - last_tower_info.foundation_low + y) * 2
).reshape(len(x), 1)
plot_last_tower_vector = np2d_to_array(
np.hstack((plot_last_tower_x, plot_last_tower_y))
)
self._plot(cad, plot_last_tower_x, plot_last_tower_y)
def draw(self): def draw(self):
if self._cad: if self._cad:
@ -376,7 +379,7 @@ class ContinuousPlate:
s_file.open(s_file_path) s_file.open(s_file_path)
dwg_file_path = self._dwg_file_path dwg_file_path = self._dwg_file_path
with Apyautocad( with Apyautocad(
create_if_not_exists=True, visible=False, auto_close=False create_if_not_exists=True, visible=True, auto_close=False
) as cad: ) as cad:
self.cad = cad self.cad = cad
doc = cad.app.Documents.Open(dwg_file_path) doc = cad.app.Documents.Open(dwg_file_path)
@ -409,6 +412,14 @@ class ContinuousPlate:
continue continue
if not last_tower_info: if not last_tower_info:
last_tower_info = tower_info last_tower_info = tower_info
if draw_count > draw_count_limit - 1:
break
foundation_low = tower_info.foundation_low
accu_mileage = (
accu_mileage
+ tower_info.mileage_in_s
- last_tower_info.mileage_in_s
)
if draw_count == draw_count_limit - 1: if draw_count == draw_count_limit - 1:
# 画代表档距 # 画代表档距
representive_span_text = f"{tower_info.back_representive_span:.0f}" representive_span_text = f"{tower_info.back_representive_span:.0f}"
@ -424,15 +435,7 @@ class ContinuousPlate:
added_representive_span_text, added_representive_span_text,
ColorEnume.representive_span_text_color_rgb, ColorEnume.representive_span_text_color_rgb,
) )
if draw_count > draw_count_limit - 1: if is_first_tower: # 是否是开始画的第一个塔。
break
foundation_low = tower_info.foundation_low
accu_mileage = (
accu_mileage
+ tower_info.mileage_in_s
- last_tower_info.mileage_in_s
)
if is_first_tower:
accu_altitude_off = 0 accu_altitude_off = 0
else: else:
accu_altitude_off = ( accu_altitude_off = (
@ -452,12 +455,21 @@ class ContinuousPlate:
) )
) )
tower_height = tower_info.tower_height tower_height = tower_info.tower_height
np_tower_end = first_tower_point + np.array( if tower_info.is_tension_tower:
[ np_tower_end = first_tower_point + np.array(
accu_mileage / 5, [
(accu_altitude_off + tower_height - foundation_low) * 2, accu_mileage / 5,
] (accu_altitude_off + tower_height - foundation_low) * 2,
) ]
)
else:
np_tower_end = first_tower_point + np.array(
[
accu_mileage / 5,
(accu_altitude_off + tower_height - foundation_low-fitting_length_dict[tower_info.fitting]+3) * 2,
]
)#直线塔杆高只比悬垂挂点高3米
tower_end = APoint(*np_tower_end.tolist()) tower_end = APoint(*np_tower_end.tolist())
# 画杆高 # 画杆高
cad.model.AddLine(tower_start, tower_end) cad.model.AddLine(tower_start, tower_end)
@ -467,8 +479,12 @@ class ContinuousPlate:
APoint(*(np_tower_end + np.array([-5, 13])).tolist()), APoint(*(np_tower_end + np.array([-5, 13])).tolist()),
5, 5,
) )
if abs(math.floor(tower_info.tower_height)-tower_info.tower_height)<0.1:#考虑了半米呼高的情况
draw_tower_height_str=f'{tower_info.tower_height:.0f}'
else:
draw_tower_height_str = f'{tower_info.tower_height:.1f}'
cad.model.AddText( cad.model.AddText(
f"{tower_info.tower_type}-{tower_info.tower_height}", f"{tower_info.tower_type}-{draw_tower_height_str}",
APoint(*(np_tower_end + np.array([-5, 5])).tolist()), APoint(*(np_tower_end + np.array([-5, 5])).tolist()),
5, 5,
) )
@ -623,5 +639,12 @@ class ControlFile:
string_impact_plate.draw() string_impact_plate.draw()
cad = continousePlate.cad cad = continousePlate.cad
cad.doc.SaveAs(self.get_zt_dwg_file_path()) cad.doc.SaveAs(self.get_zt_dwg_file_path())
# # 画完后再打开
# cad = None
# continousePlate = None
# with Apyautocad(
# create_if_not_exists=True, visible=True, auto_close=False
# ) as cad:
# cad.app.Documents.Open(self.get_zt_dwg_file_path())
if self._close_cad_document: if self._close_cad_document:
cad.doc.Close(False) cad.doc.Close(False)

4
gui.py
View File

@ -42,12 +42,12 @@ class MainWindow(QMainWindow, Ui_mainWindow):
self.statusBar().showMessage( self.statusBar().showMessage(
f"{datetime.datetime.now()} Finished.", 8000 f"{datetime.datetime.now()} Finished.", 8000
) )
QMessageBox.information(self, "提示", "断面图已生成。")
file_info = QFileInfo(z_control_file_path) file_info = QFileInfo(z_control_file_path)
self._setting.setValue( self._setting.setValue(
"last_working_directory", file_info.absoluteDir().absolutePath() "last_working_directory", file_info.absoluteDir().absolutePath()
) )
zfile_name = file_info.baseName()
QMessageBox.information(self, "提示", zfile_name + "断面图已生成。")
def _cBCloseCadDocClicked(self): def _cBCloseCadDocClicked(self):
self._setting.setValue("close_cad", self.cBCloseCadDoc.isChecked()) self._setting.setValue("close_cad", self.cBCloseCadDoc.isChecked())