civil-tools-v 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CivilTools/DXFGenerator/BasicDXF.py +3 -0
- CivilTools/DXFGenerator/__init__.py +0 -0
- CivilTools/FigureGenerator/BasicPNGPlotter.py +43 -0
- CivilTools/FigureGenerator/BasicPltPlotter.py +3 -0
- CivilTools/FigureGenerator/StairCalculationSheetPNGPlotter.py +16 -0
- CivilTools/FigureGenerator/__init__.py +0 -0
- CivilTools/ReportGenerator/BasicGenerator.py +267 -0
- CivilTools/ReportGenerator/DocParagraph.py +17 -0
- CivilTools/ReportGenerator/DocPicture.py +9 -0
- CivilTools/ReportGenerator/DocTable.py +41 -0
- CivilTools/ReportGenerator/SeismicReport.py +220 -0
- CivilTools/ReportGenerator/SeismicReportTemplate.py +240 -0
- CivilTools/ReportGenerator/StairCalculationReport.py +465 -0
- CivilTools/ReportGenerator/UtilFunctions.py +225 -0
- CivilTools/ReportGenerator/__init__.py +7 -0
- CivilTools/YDBLoader/BuildingDefine/Beam/Beam.py +26 -0
- CivilTools/YDBLoader/BuildingDefine/Beam/__init__.py +1 -0
- CivilTools/YDBLoader/BuildingDefine/Column/Column.py +16 -0
- CivilTools/YDBLoader/BuildingDefine/Column/__init__.py +1 -0
- CivilTools/YDBLoader/BuildingDefine/ComponentType.py +10 -0
- CivilTools/YDBLoader/BuildingDefine/Geometry/Grid.py +21 -0
- CivilTools/YDBLoader/BuildingDefine/Geometry/Joint.py +25 -0
- CivilTools/YDBLoader/BuildingDefine/Geometry/StandFloor.py +2 -0
- CivilTools/YDBLoader/BuildingDefine/Geometry/__init__.py +3 -0
- CivilTools/YDBLoader/BuildingDefine/GlobalResult/BasicResult.py +45 -0
- CivilTools/YDBLoader/BuildingDefine/GlobalResult/SeismicResult.py +128 -0
- CivilTools/YDBLoader/BuildingDefine/GlobalResult/__init__.py +2 -0
- CivilTools/YDBLoader/BuildingDefine/Section/Section.py +49 -0
- CivilTools/YDBLoader/BuildingDefine/Section/ShapeEnum.py +42 -0
- CivilTools/YDBLoader/BuildingDefine/Section/__init__.py +2 -0
- CivilTools/YDBLoader/BuildingDefine/Slab/Slab.py +2 -0
- CivilTools/YDBLoader/BuildingDefine/Slab/__init__.py +1 -0
- CivilTools/YDBLoader/BuildingDefine/StairPart/LoadDefine.py +38 -0
- CivilTools/YDBLoader/BuildingDefine/StairPart/StairComponent.py +95 -0
- CivilTools/YDBLoader/BuildingDefine/StairPart/StairPart.py +206 -0
- CivilTools/YDBLoader/BuildingDefine/StairPart/__init__.py +3 -0
- CivilTools/YDBLoader/BuildingDefine/__init__.py +9 -0
- CivilTools/YDBLoader/SQLiteConnector/Connector.py +80 -0
- CivilTools/YDBLoader/SQLiteConnector/RowDataFactory.py +45 -0
- CivilTools/YDBLoader/SQLiteConnector/YDBTableName.py +96 -0
- CivilTools/YDBLoader/SQLiteConnector/__init__.py +3 -0
- CivilTools/YDBLoader/YDBLoader.py +224 -0
- CivilTools/YDBLoader/YDBType.py +5 -0
- CivilTools/YDBLoader/__init__.py +4 -0
- CivilTools/__init__.py +1 -0
- civil_tools_v-0.0.1.dist-info/LICENSE +21 -0
- civil_tools_v-0.0.1.dist-info/METADATA +98 -0
- civil_tools_v-0.0.1.dist-info/RECORD +50 -0
- civil_tools_v-0.0.1.dist-info/WHEEL +5 -0
- civil_tools_v-0.0.1.dist-info/top_level.txt +1 -0
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from PIL import Image, ImageDraw
|
2
|
+
import warnings
|
3
|
+
|
4
|
+
class BasicPNGPlotter:
|
5
|
+
def __init__(self, width, height, bg = (0,0,0,0)):
|
6
|
+
self.width = width
|
7
|
+
self.height = height
|
8
|
+
self.image = Image.new('RGBA', (width, height), bg)
|
9
|
+
self.draw = ImageDraw.Draw(self.image)
|
10
|
+
|
11
|
+
def draw_horizental_line(self,s_x,s_y,length,color = "black",line_width = 2):
|
12
|
+
"""画一段水平线,length为长度,正代表向右"""
|
13
|
+
self.draw_line(s_x,s_y,s_x + length, s_y,color,line_width)
|
14
|
+
|
15
|
+
def draw_vertical_line(self,s_x,s_y,length,color = "black",line_width = 2):
|
16
|
+
"""画一段竖直线,length为长度,正代表向下"""
|
17
|
+
self.draw_line(s_x,s_y,s_x + length, s_y,color,line_width)
|
18
|
+
|
19
|
+
def draw_rectangle(self,s_x, s_y, rec_width, rec_height,color = "black",line_width = 2):
|
20
|
+
"""画一个矩形,左上角点为s_x,s_y,width正代表向右,height正代表向下"""
|
21
|
+
self.draw_horizental_line(s_x,s_y,rec_width,color,line_width)
|
22
|
+
self.draw_horizental_line(s_x,s_y + rec_height,rec_width,color,line_width)
|
23
|
+
self.draw_vertical_line(s_x,s_y,rec_height,color,line_width)
|
24
|
+
self.draw_vertical_line(s_x + rec_width,s_y,rec_height,color,line_width)
|
25
|
+
|
26
|
+
def draw_line(self,s_x,s_y,e_x,e_y,color = "black",width = 2):
|
27
|
+
if s_x<0 or s_x > self.width or s_y <0 or s_y> self.height:
|
28
|
+
warnings.warn("Start point is out of figure.")
|
29
|
+
if e_x<0 or e_x > self.width or e_y <0 or e_y> self.height:
|
30
|
+
warnings.warn("End point is out of figure.")
|
31
|
+
self.draw.line((s_x,s_y,e_x,e_y), fill=color, width=width)
|
32
|
+
|
33
|
+
def draw_png(self):
|
34
|
+
self.draw.line((0, 0, 500, 500), fill='black', width=2)
|
35
|
+
|
36
|
+
def save(self,path):
|
37
|
+
self.image.save(path, 'PNG')
|
38
|
+
|
39
|
+
|
40
|
+
if __name__ == "__main__":
|
41
|
+
p = BasicPNGPlotter(1500,800)
|
42
|
+
p.draw_png()
|
43
|
+
p.save("testfiles/output.png")
|
File without changes
|
@@ -0,0 +1,267 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from docx import Document
|
3
|
+
from docx.shared import Inches, RGBColor, Pt, Cm
|
4
|
+
from docx.oxml.ns import qn, nsdecls
|
5
|
+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_BREAK
|
6
|
+
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_ALIGNMENT
|
7
|
+
from docx.oxml.parser import parse_xml
|
8
|
+
from docx.oxml.xmlchemy import BaseOxmlElement
|
9
|
+
from docx.enum.section import WD_ORIENTATION
|
10
|
+
from .DocParagraph import DocParagraph
|
11
|
+
from .DocPicture import DocPicture
|
12
|
+
from .DocTable import DocTable
|
13
|
+
from .UtilFunctions import set_cell_border , analysis_sub_and_super_script
|
14
|
+
FONT_STR = "w:eastAsia"
|
15
|
+
|
16
|
+
class Page:
|
17
|
+
def __init__(self,width:float,height:float,is_landscape=False):
|
18
|
+
self._width = width
|
19
|
+
self._height = height
|
20
|
+
self.is_landscape = is_landscape
|
21
|
+
|
22
|
+
@property
|
23
|
+
def width(self):
|
24
|
+
return self._height if self.is_landscape else self._width
|
25
|
+
|
26
|
+
@property
|
27
|
+
def height(self):
|
28
|
+
return self._width if self.is_landscape else self._height
|
29
|
+
|
30
|
+
|
31
|
+
class PageSize(Enum):
|
32
|
+
A4 = Page(210,297)
|
33
|
+
A4_LANDSCAPE = Page(210,297,True)
|
34
|
+
A3 = Page(297,420)
|
35
|
+
A3_LANDSCAPE = Page(297,420,True)
|
36
|
+
|
37
|
+
|
38
|
+
class BasicGenerator:
|
39
|
+
|
40
|
+
def __init__(self):
|
41
|
+
self.mm_factor = 36000
|
42
|
+
self.doc = Document()
|
43
|
+
self.init_styles()
|
44
|
+
self.highlighted_color = 7
|
45
|
+
|
46
|
+
def init_styles(self):
|
47
|
+
styles = self.doc.styles
|
48
|
+
self.body_style = self.init_body_style(styles)
|
49
|
+
self.table_style = self.init_table_style(styles)
|
50
|
+
self.small_title_style = self.init_small_title_style(styles)
|
51
|
+
|
52
|
+
def init_body_style(self,styles):
|
53
|
+
"""生成一个用于普通段落文字的body_style
|
54
|
+
|
55
|
+
Args:
|
56
|
+
styles (_type_): _description_
|
57
|
+
|
58
|
+
Returns:
|
59
|
+
_type_: _description_
|
60
|
+
"""
|
61
|
+
body_style = styles['Body Text']
|
62
|
+
body_style.paragraph_format.first_line_indent = Inches(0.32)
|
63
|
+
body_style.paragraph_format.space_before = Pt(0)
|
64
|
+
body_style.paragraph_format.space_after = Pt(0)
|
65
|
+
body_style.font.name = 'Times New Roman'
|
66
|
+
body_style._element.rPr.rFonts.set(qn(FONT_STR), '宋体')
|
67
|
+
return body_style
|
68
|
+
|
69
|
+
def init_table_style(self,styles):
|
70
|
+
"""生成一个用于表格内部段落文字的table_style
|
71
|
+
|
72
|
+
Args:
|
73
|
+
styles (_type_): _description_
|
74
|
+
|
75
|
+
Returns:
|
76
|
+
_type_: _description_
|
77
|
+
"""
|
78
|
+
table_style = styles['Normal']
|
79
|
+
table_style.font.name = 'Time New Roman'
|
80
|
+
table_style.font.size = Pt(10)
|
81
|
+
table_style._element.rPr.rFonts.set(qn(FONT_STR), '宋体')
|
82
|
+
table_style.paragraph_format.space_before = Pt(0)
|
83
|
+
table_style.paragraph_format.space_after = Pt(0)
|
84
|
+
return table_style
|
85
|
+
|
86
|
+
def init_small_title_style(self, styles):
|
87
|
+
"""生成用于表格名称和图片名称的small_title_style
|
88
|
+
|
89
|
+
Args:
|
90
|
+
styles (_type_): _description_
|
91
|
+
|
92
|
+
Returns:
|
93
|
+
_type_: _description_
|
94
|
+
"""
|
95
|
+
small_title_style = styles['Body Text 2']
|
96
|
+
small_title_style.font.name = 'Times New Roman'
|
97
|
+
small_title_style._element.rPr.rFonts.set(qn(FONT_STR), '黑体')
|
98
|
+
small_title_style.paragraph_format.space_before = Pt(6)
|
99
|
+
small_title_style.paragraph_format.space_after = Pt(3)
|
100
|
+
small_title_style.paragraph_format.line_spacing = Pt(15)
|
101
|
+
return small_title_style
|
102
|
+
|
103
|
+
def change_paper_size(self, page_size:PageSize, column_num:int = 1):
|
104
|
+
section = self.doc.sections[0]
|
105
|
+
section.page_width = int(page_size.value.width * self.mm_factor)
|
106
|
+
section.page_heigth = int(page_size.value.height * self.mm_factor)
|
107
|
+
if page_size.value.is_landscape:
|
108
|
+
section.orientation = WD_ORIENTATION.LANDSCAPE
|
109
|
+
sect_pr = section._sectPr
|
110
|
+
cols = sect_pr.xpath('./w:cols')[0]
|
111
|
+
cols.set(qn('w:num'), str(column_num))
|
112
|
+
|
113
|
+
def change_paper_margin(self, left:int, top:int, right:int, bottom:int):
|
114
|
+
"""改变页边距,单位为mm,按照左、上、右、下的顺序
|
115
|
+
"""
|
116
|
+
section = self.doc.sections[0]
|
117
|
+
section.top_margin = int(self.mm_factor * top)
|
118
|
+
section.bottom_margin = int(self.mm_factor * bottom)
|
119
|
+
section.left_margin = int(self.mm_factor * left)
|
120
|
+
section.right_margin = int(self.mm_factor * right)
|
121
|
+
|
122
|
+
def add_big_title(self, context):
|
123
|
+
p = self.doc.add_paragraph(context)
|
124
|
+
run = p.runs[0]
|
125
|
+
run.font.size = Pt(14)
|
126
|
+
run.font.bold = True
|
127
|
+
p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
128
|
+
|
129
|
+
def add_title(self,title:DocParagraph,space_before:float = 0 ,space_after:float = 0):
|
130
|
+
"""为了添加大纲等级而添加的函数,不需要大纲等级时不要使用
|
131
|
+
|
132
|
+
Args:
|
133
|
+
title (DocParagraph): _description_
|
134
|
+
"""
|
135
|
+
p = self.doc.add_heading("", level=title.par_level)
|
136
|
+
run = p.add_run(title.context)
|
137
|
+
run.font.name = u'Times New Roman'
|
138
|
+
run._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
|
139
|
+
run.font.color.rgb = RGBColor(0, 0, 0)
|
140
|
+
par_format = p.paragraph_format
|
141
|
+
par_format.space_before = Pt(space_before)
|
142
|
+
par_format.space_after = Pt(space_after)
|
143
|
+
|
144
|
+
self.paragraph_format_double_check(p,title)
|
145
|
+
|
146
|
+
def add_paragraph(self, par:DocParagraph):
|
147
|
+
if '{' in par.context:
|
148
|
+
a,b = analysis_sub_and_super_script(par.context)
|
149
|
+
if par.style != None:
|
150
|
+
p = self.doc.add_paragraph("",par.style)
|
151
|
+
else:
|
152
|
+
p = self.doc.add_paragraph()
|
153
|
+
self.add_context_with_sub_or_super(p,a,b)
|
154
|
+
elif par.style !=None:
|
155
|
+
p = self.doc.add_paragraph(par.context,par.style)
|
156
|
+
else:
|
157
|
+
p = self.doc.add_paragraph(par.context)
|
158
|
+
self.paragraph_format_double_check(p,par)
|
159
|
+
|
160
|
+
def add_context_with_sub_or_super(self, p,str_list,sub_or_super):
|
161
|
+
for i in range(len(str_list)):
|
162
|
+
run = p.add_run(str_list[i])
|
163
|
+
run.font.name = u'Times New Roman'
|
164
|
+
if sub_or_super[i] == 1:
|
165
|
+
run.font.subscript = True
|
166
|
+
elif sub_or_super[i] == 2:
|
167
|
+
run.font.superscript = True
|
168
|
+
elif sub_or_super[i] ==3:
|
169
|
+
run.font.highlight_color = self.highlighted_color
|
170
|
+
run.font.size = Pt(11)
|
171
|
+
|
172
|
+
def paragraph_format_double_check(self,p,doc_par:DocParagraph):
|
173
|
+
run = p.runs[0]
|
174
|
+
if doc_par.font_size != None:
|
175
|
+
run.font.size = Pt(doc_par.font_size)
|
176
|
+
if doc_par.is_bold != None:
|
177
|
+
run.font.bold = doc_par.is_bold
|
178
|
+
par_format = p.paragraph_format
|
179
|
+
if doc_par.first_line_indent != None:
|
180
|
+
par_format.first_line_indent = Inches(doc_par.first_line_indent)
|
181
|
+
if doc_par.alignment != None:
|
182
|
+
par_format.alignment = doc_par.alignment
|
183
|
+
if doc_par.font_size != None:
|
184
|
+
run.font.size = Pt(doc_par.font_size)
|
185
|
+
|
186
|
+
def add_table(self, my_table:DocTable):
|
187
|
+
if my_table.title != None:
|
188
|
+
p = self.doc.add_paragraph(my_table.title,self.small_title_style)
|
189
|
+
p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
190
|
+
table = self.doc.add_table(rows=my_table.row_num, cols=my_table.column_num, style='Table Grid')
|
191
|
+
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
192
|
+
for (i,j,k,p) in my_table.merged_cells:
|
193
|
+
table.cell(i,j).merge(table.cell(k,p))
|
194
|
+
for i in range(my_table.row_num):
|
195
|
+
for j in range(my_table.column_num):
|
196
|
+
self.add_table_cell(table,my_table,i,j)
|
197
|
+
self.tab_bg_color(table,my_table.row_num,my_table.column_num)
|
198
|
+
|
199
|
+
def tab_bg_color(self, table, rows, cols, color_str='CCCCCC'):
|
200
|
+
"""表格样式调整"""
|
201
|
+
shading_list = locals()
|
202
|
+
for i in range(cols):
|
203
|
+
shading_list['shading_elm_' + str(i)] = parse_xml(
|
204
|
+
r'<w:shd {} w:fill="{bgColor}"/>'.format(nsdecls('w'), bgColor=color_str))
|
205
|
+
table.rows[0].cells[i]._tc.get_or_add_tcPr().append(shading_list['shading_elm_' + str(i)])
|
206
|
+
for i in range(rows):
|
207
|
+
shading_list['shading_elm_' + str(cols+i)] = parse_xml(
|
208
|
+
r'<w:shd {} w:fill="{bgColor}"/>'.format(nsdecls('w'), bgColor=color_str))
|
209
|
+
table.rows[i].cells[0]._tc.get_or_add_tcPr().append(shading_list['shading_elm_' + str(cols+i)])
|
210
|
+
table_cells = table._cells
|
211
|
+
for i in range(rows):
|
212
|
+
table_row = table_cells[i * cols:i * cols + cols]
|
213
|
+
for k in range(cols):
|
214
|
+
table_row[k].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
|
215
|
+
table_row[k].paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER
|
216
|
+
if i == 0:
|
217
|
+
runs = table_row[k].paragraphs[0].runs
|
218
|
+
for m in range(len(runs)):
|
219
|
+
runs[m].bold = True
|
220
|
+
table.rows[i].height = Cm(0.7)
|
221
|
+
|
222
|
+
def add_table_cell(self, table, my_table:DocTable, i,j):
|
223
|
+
try:
|
224
|
+
cell = table.cell(i, j)
|
225
|
+
_ = my_table.context[i][j]
|
226
|
+
except IndexError:
|
227
|
+
return
|
228
|
+
if '{' in my_table.context[i][j]:
|
229
|
+
a,b = analysis_sub_and_super_script(my_table.context[i][j])
|
230
|
+
p = cell.paragraphs[0]
|
231
|
+
self.add_context_with_sub_or_super(p,a,b)
|
232
|
+
else:
|
233
|
+
cell.text = my_table.context[i][j]
|
234
|
+
cell.paragraphs[0].style = self.table_style
|
235
|
+
p = cell.paragraphs[0]
|
236
|
+
p.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
237
|
+
if my_table.no_grid:
|
238
|
+
set_cell_border(cell,top={"color": "#FFFFFF"},
|
239
|
+
bottom={"color": "#FFFFFF"},
|
240
|
+
start={"color": "#FFFFFF"},
|
241
|
+
end={"color": "#FFFFFF"},)
|
242
|
+
if my_table.all_bold:
|
243
|
+
p.runs[0].font.bold = True
|
244
|
+
|
245
|
+
def add_picture(self,doc_picture:DocPicture):
|
246
|
+
self.doc.add_picture(doc_picture.path, width=Inches(doc_picture.width))
|
247
|
+
last_paragraph = self.doc.paragraphs[-1]
|
248
|
+
last_paragraph.alignment = 1
|
249
|
+
|
250
|
+
def add_blank_paragraph(self):
|
251
|
+
self.doc.add_paragraph()
|
252
|
+
|
253
|
+
def add_page_break(self):
|
254
|
+
if len(self.doc.paragraphs[-1].runs)>0:
|
255
|
+
self.doc.paragraphs[-1].runs[0].add_break(WD_BREAK.PAGE)
|
256
|
+
else:
|
257
|
+
run = self.doc.paragraphs[-1].add_run("")
|
258
|
+
run.add_break(WD_BREAK.PAGE)
|
259
|
+
|
260
|
+
def save(self,path:str):
|
261
|
+
for _ in range(10):
|
262
|
+
try:
|
263
|
+
self.doc.save(path)
|
264
|
+
except Exception:
|
265
|
+
path = path.replace(".docx","1.docx")
|
266
|
+
|
267
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class DocParagraph:
|
4
|
+
def init_attr(self):
|
5
|
+
self.style = None
|
6
|
+
self.font_size = 11
|
7
|
+
self.first_line_indent = None
|
8
|
+
self.space_before = None
|
9
|
+
self.space_after = None
|
10
|
+
self.line_spacing = None
|
11
|
+
self.is_bold = None
|
12
|
+
self.alignment = None
|
13
|
+
self.par_level = None
|
14
|
+
|
15
|
+
def __init__(self,context):
|
16
|
+
self.context = context
|
17
|
+
self.init_attr()
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import List
|
2
|
+
|
3
|
+
class DocTable:
|
4
|
+
def init_content(self):
|
5
|
+
self.context = [["None"] * self.column_num for _ in range(self.row_num)]
|
6
|
+
self.merged_cells = set()
|
7
|
+
|
8
|
+
def __init__(self,row_num, column_num):
|
9
|
+
self.row_num = row_num
|
10
|
+
self.column_num = column_num
|
11
|
+
self.title = None
|
12
|
+
self.no_grid = False
|
13
|
+
self.all_bold = False
|
14
|
+
self.init_content()
|
15
|
+
|
16
|
+
def set_table_title(self, title):
|
17
|
+
self.title = title
|
18
|
+
|
19
|
+
|
20
|
+
def set_table_context(self, context):
|
21
|
+
if len(context) == self.row_num and len(context[0]) == self.column_num:
|
22
|
+
self.context = context
|
23
|
+
else:
|
24
|
+
raise ValueError("输入的内容行列数量不对")
|
25
|
+
|
26
|
+
|
27
|
+
def merge_cells(self,i,j,k,p):
|
28
|
+
# 检查合并范围是否合法
|
29
|
+
if i < 0 or i >= self.row_num or j < 0 or j >= self.column_num:
|
30
|
+
raise ValueError("起始单元格超出表格范围")
|
31
|
+
if k < 0 or k >= self.row_num or p < 0 or p >= self.column_num:
|
32
|
+
raise ValueError("结束单元格超出表格范围")
|
33
|
+
if i > k or (i == k and j > p):
|
34
|
+
raise ValueError("起始单元格必须在结束单元格之前")
|
35
|
+
|
36
|
+
# 检查是否与已合并的单元格冲突
|
37
|
+
for start_row, start_col, end_row, end_col in self.merged_cells:
|
38
|
+
if (i <= end_row and k > start_row) and (j <= end_col and p > start_col):
|
39
|
+
raise ValueError("合并范围与已合并的单元格冲突")
|
40
|
+
|
41
|
+
self.merged_cells.add((i, j, k, p))
|
@@ -0,0 +1,220 @@
|
|
1
|
+
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_ALIGNMENT
|
2
|
+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_BREAK
|
3
|
+
from docx.shared import Inches, RGBColor, Pt, Cm
|
4
|
+
|
5
|
+
from .BasicGenerator import BasicGenerator, PageSize
|
6
|
+
from .DocParagraph import DocParagraph
|
7
|
+
from .DocTable import DocTable
|
8
|
+
from .DocPicture import DocPicture
|
9
|
+
from .SeismicReportTemplate import SRTemplate
|
10
|
+
from .UtilFunctions import add_comma_in_num_str
|
11
|
+
|
12
|
+
class SeismicReport(BasicGenerator):
|
13
|
+
def __init__(self):
|
14
|
+
super().__init__()
|
15
|
+
# 修改为A3图纸,横向,两栏
|
16
|
+
self.change_paper_size(PageSize.A3_LANDSCAPE,2)
|
17
|
+
# 修改纸张Margin,单位mm
|
18
|
+
self.change_paper_margin(32,25,32,25)
|
19
|
+
# 格式统一修改
|
20
|
+
self.body_style.paragraph_format.line_spacing = Pt(22)
|
21
|
+
|
22
|
+
def creat_doc(self):
|
23
|
+
self.__add_info()
|
24
|
+
self.__add_seismic_chapter()
|
25
|
+
|
26
|
+
|
27
|
+
def __add_info(self):
|
28
|
+
model_name = "TestModel"
|
29
|
+
par_context = SRTemplate.FIRST_INFO(model_name)
|
30
|
+
paragraph = DocParagraph(par_context)
|
31
|
+
paragraph.style = self.body_style
|
32
|
+
self.add_paragraph(paragraph)
|
33
|
+
|
34
|
+
def __add_seismic_chapter(self):
|
35
|
+
chapter_index = 8
|
36
|
+
sub_index = 1
|
37
|
+
self.__add_seismic_chapter_title(chapter_index)
|
38
|
+
sub_index = self.__add_seismic_embedding(chapter_index,sub_index)
|
39
|
+
sub_index = self.__add_project_mass(chapter_index, sub_index)
|
40
|
+
sub_index = self.__add_period( chapter_index,sub_index)
|
41
|
+
sub_index = self.__add_shear_mass_ratio( chapter_index,sub_index)
|
42
|
+
sub_index = self.__add_shear_and_moment( chapter_index,sub_index)
|
43
|
+
sub_index = self.__add_horizental_moment_ratio_for_column( chapter_index,sub_index)
|
44
|
+
sub_index = self.__add_disp_and_drift( chapter_index,sub_index)
|
45
|
+
sub_index = self.__add_horizental_stiffness_ratio( chapter_index,sub_index)
|
46
|
+
sub_index = self.__add_rotation_ratio( chapter_index,sub_index)
|
47
|
+
sub_index = self.__add_stiffness_mass_ratio( chapter_index,sub_index)
|
48
|
+
sub_index = self.__add_shear_capacity_ratio( chapter_index,sub_index)
|
49
|
+
sub_index = self.__add_wind_acc( chapter_index,sub_index)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def __add_seismic_chapter_title(self,chapter_index :int):
|
54
|
+
|
55
|
+
yjk_version = "6.0.0"
|
56
|
+
|
57
|
+
current_context = SRTemplate.SEISMIC_CHAPTER_TITLE
|
58
|
+
par_context = DocParagraph(current_context.title(chapter_index))
|
59
|
+
par_context.par_level = 1
|
60
|
+
self.add_title(par_context,12,6)
|
61
|
+
paragraph_texts = current_context.paragraph(chapter_index,yjk_version)
|
62
|
+
for context in paragraph_texts[:-1]:
|
63
|
+
paragraph = DocParagraph(context)
|
64
|
+
paragraph.style = self.body_style
|
65
|
+
self.add_paragraph(paragraph)
|
66
|
+
|
67
|
+
text = paragraph_texts[-1]
|
68
|
+
paragraph = DocParagraph(text)
|
69
|
+
paragraph.style = self.body_style
|
70
|
+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
71
|
+
paragraph.first_line_indent = 0
|
72
|
+
self.add_paragraph(paragraph)
|
73
|
+
|
74
|
+
figure_title = current_context.picture(chapter_index)
|
75
|
+
paragraph = DocParagraph(figure_title)
|
76
|
+
paragraph.style = self.small_title_style
|
77
|
+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
78
|
+
self.add_paragraph(paragraph)
|
79
|
+
|
80
|
+
def __add_seismic_embedding(self, chapter_index:int, sub_index:int):
|
81
|
+
|
82
|
+
current_context = SRTemplate.SEISMIC_EMBEDDING
|
83
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
84
|
+
|
85
|
+
context = current_context.paragraph(chapter_index,sub_index)[0]
|
86
|
+
paragraph = DocParagraph(context)
|
87
|
+
paragraph.style = self.body_style
|
88
|
+
self.add_paragraph(paragraph)
|
89
|
+
|
90
|
+
table_title = current_context.table(chapter_index,sub_index)
|
91
|
+
paragraph = DocParagraph(table_title)
|
92
|
+
paragraph.style = self.small_title_style
|
93
|
+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
94
|
+
self.add_paragraph(paragraph)
|
95
|
+
|
96
|
+
table = DocTable(3,7)
|
97
|
+
table.merge_cells(1,4,2,4)
|
98
|
+
table.merge_cells(1,5,2,5)
|
99
|
+
table.set_table_context(current_context.table_context)
|
100
|
+
self.add_table(table)
|
101
|
+
|
102
|
+
|
103
|
+
return sub_index + 1
|
104
|
+
|
105
|
+
def __add_project_mass(self, chapter_index:int, sub_index:int):
|
106
|
+
|
107
|
+
total_mass = 125452
|
108
|
+
total_area = 4345
|
109
|
+
average_load = total_mass / total_area * 10
|
110
|
+
|
111
|
+
current_context = SRTemplate.PROJECT_MASS
|
112
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
113
|
+
|
114
|
+
contexts = current_context.paragraph(
|
115
|
+
chapter_index,
|
116
|
+
sub_index,
|
117
|
+
total_mass = add_comma_in_num_str(total_mass),
|
118
|
+
total_area = add_comma_in_num_str(total_area),
|
119
|
+
average_load = average_load
|
120
|
+
)
|
121
|
+
paragraph = DocParagraph(contexts[0])
|
122
|
+
paragraph.style = self.body_style
|
123
|
+
self.add_paragraph(paragraph)
|
124
|
+
|
125
|
+
table_title = current_context.table(chapter_index,sub_index)
|
126
|
+
paragraph = DocParagraph(table_title)
|
127
|
+
paragraph.style = self.small_title_style
|
128
|
+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
|
129
|
+
self.add_paragraph(paragraph)
|
130
|
+
|
131
|
+
table = DocTable(4,4)
|
132
|
+
table.set_table_context(current_context.table_context(
|
133
|
+
A = 1
|
134
|
+
))
|
135
|
+
self.add_table(table)
|
136
|
+
|
137
|
+
|
138
|
+
return sub_index + 1
|
139
|
+
|
140
|
+
def __add_period(self, chapter_index:int, sub_index:int):
|
141
|
+
current_context = SRTemplate.PERIOD
|
142
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
143
|
+
|
144
|
+
|
145
|
+
return sub_index + 1
|
146
|
+
|
147
|
+
def __add_shear_mass_ratio(self, chapter_index:int, sub_index:int):
|
148
|
+
current_context = SRTemplate.SHEAR_MASS_RATIO
|
149
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
150
|
+
|
151
|
+
|
152
|
+
return sub_index + 1
|
153
|
+
|
154
|
+
def __add_shear_and_moment(self, chapter_index:int, sub_index:int):
|
155
|
+
current_context = SRTemplate.SHEAR_AND_MOMENT
|
156
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
157
|
+
|
158
|
+
|
159
|
+
return sub_index + 1
|
160
|
+
|
161
|
+
def __add_horizental_moment_ratio_for_column(self, chapter_index:int, sub_index:int):
|
162
|
+
current_context = SRTemplate.HORIZENTAL_MOMENT_RATIO_FOR_COLUMN
|
163
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
164
|
+
|
165
|
+
|
166
|
+
return sub_index + 1
|
167
|
+
|
168
|
+
def __add_disp_and_drift(self, chapter_index:int, sub_index:int):
|
169
|
+
current_context = SRTemplate.DISP_AND_DRIFT
|
170
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
171
|
+
|
172
|
+
|
173
|
+
return sub_index + 1
|
174
|
+
|
175
|
+
def __add_horizental_stiffness_ratio(self, chapter_index:int, sub_index:int):
|
176
|
+
current_context = SRTemplate.HORIZENTAL_STIFFNESS_RATIO
|
177
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
178
|
+
|
179
|
+
|
180
|
+
return sub_index + 1
|
181
|
+
|
182
|
+
def __add_rotation_ratio(self, chapter_index:int, sub_index:int):
|
183
|
+
current_context = SRTemplate.ROTATION_RATIO
|
184
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
185
|
+
|
186
|
+
|
187
|
+
return sub_index + 1
|
188
|
+
|
189
|
+
def __add_stiffness_mass_ratio(self, chapter_index:int, sub_index:int):
|
190
|
+
current_context = SRTemplate.STIFFNESS_MASS_RATIO
|
191
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
192
|
+
|
193
|
+
|
194
|
+
return sub_index + 1
|
195
|
+
|
196
|
+
def __add_shear_capacity_ratio(self, chapter_index:int, sub_index:int):
|
197
|
+
current_context = SRTemplate.SHEAR_CAPACITY_RATIO
|
198
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
199
|
+
|
200
|
+
|
201
|
+
return sub_index + 1
|
202
|
+
|
203
|
+
def __add_wind_acc(self, chapter_index:int, sub_index:int):
|
204
|
+
current_context = SRTemplate.WIND_ACC
|
205
|
+
self.__insert_title_par_2(current_context,chapter_index,sub_index)
|
206
|
+
|
207
|
+
|
208
|
+
return sub_index + 1
|
209
|
+
|
210
|
+
|
211
|
+
def __insert_title_par_2(self, current_context, chapter_index, sub_index):
|
212
|
+
par_context = DocParagraph(current_context.title(chapter_index,sub_index))
|
213
|
+
par_context.par_level = 2
|
214
|
+
self.add_title(par_context,6 ,6 )
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|