基本完成了画连续档的代码。
This commit is contained in:
commit
4255995b66
|
|
@ -0,0 +1,87 @@
|
|||
from collections import OrderedDict
|
||||
import re
|
||||
from attrs import define
|
||||
|
||||
|
||||
@define
|
||||
class SEntry:
|
||||
tower_name: str = ""
|
||||
tower_height: float = 0
|
||||
tower_type: str = ""
|
||||
mileage_in_s: int = 0
|
||||
back_k: float = 0
|
||||
forth_k: float = 0
|
||||
altitude_off: float = 0
|
||||
foundation_low: float = 0 # 基降
|
||||
fitting: str = "" # 金具
|
||||
is_tension_tower: bool = False
|
||||
|
||||
|
||||
class SFile:
|
||||
def __init__(self) -> None:
|
||||
self.tower_dic = None
|
||||
|
||||
def open(self, s_file_path):
|
||||
self.tower_dic = OrderedDict()
|
||||
tower_dic = self.tower_dic
|
||||
with open(s_file_path, encoding="gbk") as s_file_obj:
|
||||
new_k = 0
|
||||
last_k = -1
|
||||
# next_is_tension_tower=False
|
||||
last_tower_name = ""
|
||||
for line in s_file_obj:
|
||||
norm_line = line.strip()
|
||||
if norm_line == "":
|
||||
continue
|
||||
if "首端转角号" in norm_line:
|
||||
new_k = float(norm_line.split(":")[-1].replace("E", "e")) # 模板系数
|
||||
continue
|
||||
if "塔号" in norm_line:
|
||||
# next_is_tension_tower=True
|
||||
if last_tower_name != "":
|
||||
tower_dic[last_tower_name].is_tension_tower = True
|
||||
continue
|
||||
norm_entry = re.sub("\s+", ",", norm_line)
|
||||
sep_entry = norm_entry.split(",")
|
||||
tower_name = sep_entry[0]
|
||||
if tower_name in tower_dic:
|
||||
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.forth_k = new_k
|
||||
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
|
||||
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
|
||||
tower_dic[list(tower_dic.keys())[-1]].is_tension_tower = True
|
||||
|
||||
|
||||
@define
|
||||
class Fitting:
|
||||
fitting_length_dic = {}
|
||||
|
||||
def __init__(self, fitting_file_path):
|
||||
content = []
|
||||
with open(fitting_file_path) as fitting_file:
|
||||
for line in fitting_file:
|
||||
norm_line = line.strip()
|
||||
if norm_line == "":
|
||||
continue
|
||||
norm_entry = re.sub("\s+", ",", norm_line)
|
||||
content.append(norm_entry.split(","))
|
||||
ite = iter(content[7:])
|
||||
for fit in ite: # 跳过前面7行
|
||||
fit_name = fit[0]
|
||||
fit_parameter = next(ite)
|
||||
self.fitting_length_dic[fit_name] = float(fit_parameter[2]) / 1000
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
from tkinter.messagebox import NO
|
||||
import xlwings as xw
|
||||
from PWFile import SFile, Fitting
|
||||
from Apyautocad import Apyautocad, APoint
|
||||
import os
|
||||
import re
|
||||
import numpy as np
|
||||
from time import sleep
|
||||
|
||||
# 读取Z文件,找到Z断面第一个点的坐标
|
||||
def plane_z_origin(z_file_path):
|
||||
with open(z_file_path) as zfile:
|
||||
content = zfile.read()
|
||||
norm_content = re.sub("\s+", ",", content)
|
||||
sep = norm_content.split(",")
|
||||
return np.array([float(sep[0]), float(sep[1])])
|
||||
|
||||
|
||||
def deduce_zfile_from_cad_path(cad_file_path):
|
||||
dwg_file_name = os.path.split(cad_file_path)
|
||||
dwg_prefix = dwg_file_name[1].split(".")[0]
|
||||
return os.path.join(dwg_file_name[0], f"Z{dwg_prefix}")
|
||||
|
||||
|
||||
def deduce_fit_db_from_cad_path(cad_file_path):
|
||||
dwg_file_name = os.path.split(cad_file_path)
|
||||
dwg_prefix = dwg_file_name[1].split(".")[0]
|
||||
return os.path.join(dwg_file_name[0], "Fit.db")
|
||||
|
||||
|
||||
def curve_fun(x, span, k, gaocha):
|
||||
return x * gaocha / span - x * (span - x) * k
|
||||
|
||||
|
||||
class StringImpactExcel:
|
||||
def __init__(self) -> None:
|
||||
# self._wb=None
|
||||
pass
|
||||
|
||||
def read(self, wb):
|
||||
# with xw.App(visible=True) as app:
|
||||
pos代表档距 = "F13"
|
||||
pos档距 = "L13"
|
||||
pos高差 = "R13"
|
||||
pos张力 = "AB18"
|
||||
pos档距21 = "E25"
|
||||
sheet = wb.sheets["3225-3226"]
|
||||
print(sheet.range("V25:V46").value)
|
||||
|
||||
def set_true_color(object,r,g,b):
|
||||
true_color=object.TrueColor
|
||||
true_color.SetRGB(r,g,b)
|
||||
|
||||
def main():
|
||||
# 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:
|
||||
# wb_string_impact = app.books.open("特高压耐张串影响弧垂计算(送电室2018人员版)1122-1218.xls")
|
||||
# stringImpactExcel = StringImpactExcel()
|
||||
# stringImpactExcel.read(wb_string_impact)
|
||||
with Apyautocad(create_if_not_exists=True, visible=False) as cad:
|
||||
doc = cad.app.Documents.Open(r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg")
|
||||
sleep(1)
|
||||
z_file_path = deduce_zfile_from_cad_path(
|
||||
r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg"
|
||||
)
|
||||
z_point = plane_z_origin(z_file_path)
|
||||
fitting_file_path = deduce_fit_db_from_cad_path(
|
||||
r"d:\工程\金上线\排位\定位完排位\PW.0706\J33-J49\033A.dwg"
|
||||
)
|
||||
fitting = Fitting(fitting_file_path)
|
||||
fitting_length_dict = fitting.fitting_length_dic
|
||||
first_tower_point = z_point
|
||||
last_tower_info = None # 上一个塔位信息
|
||||
accu_mileage = 0 # 累计档距
|
||||
accu_altitude_off = 0 # 累计高差
|
||||
is_first_tower = True
|
||||
for tower in s_file.tower_dic:
|
||||
tower_info = s_file.tower_dic[tower]
|
||||
if not last_tower_info:
|
||||
last_tower_info = tower_info
|
||||
foundation_low = tower_info.foundation_low
|
||||
accu_mileage = (
|
||||
accu_mileage + tower_info.mileage_in_s - last_tower_info.mileage_in_s
|
||||
)
|
||||
accu_altitude_off = accu_altitude_off + tower_info.altitude_off # 中心桩高程
|
||||
tower_start = APoint(
|
||||
*(
|
||||
(
|
||||
first_tower_point
|
||||
+ np.array(
|
||||
[accu_mileage / 5, (accu_altitude_off - foundation_low) * 2]
|
||||
)
|
||||
).tolist()
|
||||
)
|
||||
)
|
||||
tower_height = tower_info.tower_height
|
||||
tower_end = APoint(
|
||||
*(
|
||||
first_tower_point
|
||||
+ np.array(
|
||||
[
|
||||
accu_mileage / 5,
|
||||
(accu_altitude_off + tower_height - foundation_low) * 2,
|
||||
]
|
||||
)
|
||||
).tolist()
|
||||
)
|
||||
# 画杆高
|
||||
cad.model.AddLine(tower_start, tower_end)
|
||||
# 画弧垂
|
||||
if not is_first_tower: # 从第二基塔开始画
|
||||
draw_k = tower_info.back_k
|
||||
span = tower_info.mileage_in_s - last_tower_info.mileage_in_s
|
||||
last_tower_fiting = last_tower_info.fitting
|
||||
last_tower_fitting_length = fitting_length_dict[last_tower_fiting]
|
||||
if last_tower_info.is_tension_tower:
|
||||
last_tower_fitting_length = 0
|
||||
tower_fitting = tower_info.fitting
|
||||
tower_fitting_length = fitting_length_dict[tower_fitting]
|
||||
if tower_info.is_tension_tower:
|
||||
tower_fitting_length = 0
|
||||
last_tower_height = last_tower_info.tower_height
|
||||
last_foundation_low = last_tower_info.foundation_low
|
||||
# 挂点高差
|
||||
fiting_altitude_off = (
|
||||
tower_info.altitude_off
|
||||
+ (tower_height - foundation_low - tower_fitting_length)
|
||||
- (
|
||||
last_tower_height
|
||||
- last_foundation_low
|
||||
- last_tower_fitting_length
|
||||
)
|
||||
) # 前侧高为正
|
||||
# 画导线弧垂
|
||||
x = np.linspace(0, span, int(span), endpoint=True)
|
||||
curve = curve_fun(x, span, draw_k, fiting_altitude_off)
|
||||
draw_curve_x = (first_tower_point[0]) + (x + accu_mileage - span) / 5
|
||||
draw_curve_y = (
|
||||
first_tower_point[1]
|
||||
+ (
|
||||
+curve
|
||||
+ accu_altitude_off
|
||||
- tower_info.altitude_off
|
||||
- last_tower_info.foundation_low
|
||||
+ last_tower_info.tower_height
|
||||
- last_tower_fitting_length
|
||||
)
|
||||
* 2
|
||||
)
|
||||
draw_curve_x = draw_curve_x.reshape(len(draw_curve_x), 1)
|
||||
draw_curve_y = draw_curve_y.reshape(len(draw_curve_y), 1)
|
||||
draw_ground_curve_y = draw_curve_y - 18 * 2 # 切地线
|
||||
draw_tree_curve_y = draw_curve_y - 13.5 * 2 # 切树线
|
||||
draw_point = np.hstack(
|
||||
(draw_curve_x, draw_curve_y, np.zeros((len(draw_curve_x), 1)))
|
||||
)
|
||||
draw_ground_curve_point = np.hstack(
|
||||
(
|
||||
draw_curve_x,
|
||||
draw_ground_curve_y,
|
||||
np.zeros((len(draw_curve_x), 1)),
|
||||
)
|
||||
)
|
||||
draw_tree_curve_point = np.hstack(
|
||||
(draw_curve_x, draw_tree_curve_y, np.zeros((len(draw_curve_x), 1)))
|
||||
)
|
||||
added_curve=cad.model.AddPolyLine(
|
||||
draw_point.reshape(1, draw_curve_x.shape[0] * 3)[0]
|
||||
)
|
||||
set_true_color(added_curve,122,219,245)
|
||||
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)
|
||||
added_true_curve=cad.model.AddPolyLine(
|
||||
draw_tree_curve_point.reshape(1, draw_tree_curve_y.shape[0] * 3)[0]
|
||||
)
|
||||
set_true_color(added_true_curve, 116, 230, 165)
|
||||
is_first_tower = False
|
||||
last_tower_info = tower_info
|
||||
doc.SaveAs(r"d:\工程\金上线\code\考虑耐张串重弧垂\T033A.dwg")
|
||||
|
||||
|
||||
main()
|
||||
Loading…
Reference in New Issue