-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.py
executable file
·401 lines (353 loc) · 13.1 KB
/
report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#! /Users/tsuno/.pyenv/shims/python3
# -*- coding:utf-8 -*-
import os, sys
#import Image
#import urllib2
#from cStringIO import StringIO
#zipアーカイブからファイルを読み込むため。通常は必要ないはず。
#sys.path.insert(0, 'reportlab.zip')
import reportlab
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.units import cm
#
import linecache
#
class Report():
def __init__(self):
#self.FONT_NAME = "Helvetica"
self.FONT_NAME = "GenShinGothic"
GEN_SHIN_GOTHIC_MEDIUM_TTF = "./fonts/GenShinGothic-Monospace-Medium.ttf"
# フォント登録
pdfmetrics.registerFont(TTFont('GenShinGothic', GEN_SHIN_GOTHIC_MEDIUM_TTF))
#font_size = 20
#c.setFont('GenShinGothic', font_size)
########################################################################
# 文字と画像を配置
def create_row(self,c, index, data):
#y_shift = -240 * index
y_shift = -180 * index
c.setFont(self.FONT_NAME, 9)
"""
for i in range(0,len(data)):
# txt
c.drawString(300, 720-(i-1)*10 + y_shift, data[i])
"""
c.drawString(55, self.ypos(0,y_shift), data[0].encode('utf-8'))
c.drawString(55, self.ypos(1,y_shift), data[1].encode('utf-8'))
# Slab Condition
lx = "{:.2f}".format(float(data[2]))
ly = "{:.2f}".format(float(data[3]))
t = data[4]
dt = data[5]
w = data[6]
creep = data[7]
fc = data[8]
gamma = data[9]
# Rebar Arrangement
lx1Pitch = data[10]
lx2Pitch = data[11]
ly1Pitch = data[12]
ly2Pitch = data[13]
#
ind_bound = int( data[14] )
# Combo
lx1bar = data[19]
lx2bar = data[20]
ly1bar = data[21]
ly2bar = data[22]
# 出力
mx1 = data[23]
mx2 = data[24]
my1 = data[25]
my2 = data[26]
#
atx1 = data[27]
atx2 = data[28]
aty1 = data[29]
aty2 = data[30]
#
reqt = data[31]
tbyl = data[32]
#
sfx1 = data[33]
sfx2 = data[34]
sfy1 = data[35]
sfy2 = data[36]
defl = data[37]
dBySan = data[38]
# add
ft = data[39]
# Design Condition
c.drawString(260, self.ypos(0,y_shift),
"Lx = "
)
c.drawString(290, self.ypos(0,y_shift),
lx + "m, ")
c.drawString(350, self.ypos(0,y_shift),
"Ly = "
)
c.drawString(380, self.ypos(0,y_shift),
ly + " m"\
)
#
c.drawString(260, self.ypos(1,y_shift),
"t = "
)
c.drawString(290, self.ypos(1,y_shift),
t + " mm, "\
)
c.drawString(350, self.ypos(1,y_shift),
"dt = "
)
c.drawString(380, self.ypos(1,y_shift),
dt + " mm"\
)
#
c.drawString(260, self.ypos(2,y_shift),
"fc = "
)
c.drawString(290, self.ypos(2,y_shift),
fc + " N/mm2, "\
)
c.drawString(350, self.ypos(2,y_shift),
"( γ = " + gamma + " kN/m3)"\
)
c.drawString(430, self.ypos(2,y_shift),
"ft = " + ft + " N/mm2"\
)
#
c.drawString(260, self.ypos(3,y_shift),
"w = "
)
c.drawString(290, self.ypos(3,y_shift),
w + " kN/m2, "\
)
c.drawString(350, self.ypos(3,y_shift),
"K = "
)
c.drawString(380, self.ypos(3,y_shift),
creep \
)
# Result for the stress
"""
c.drawString(330, self.ypos(5,y_shift), "S,Ext. " )
c.drawString(380, self.ypos(5,y_shift), "S,Cen. " )
c.drawString(430, self.ypos(5,y_shift), "L,Ext. " )
c.drawString(480, self.ypos(5,y_shift), "L,Cen. " )
"""
c.drawString(330, self.ypos(5,y_shift), "短辺端部 " )
c.drawString(380, self.ypos(5,y_shift), "短辺中央 " )
c.drawString(430, self.ypos(5,y_shift), "長辺端部" )
c.drawString(480, self.ypos(5,y_shift), "長辺中央" )
c.drawString(260, self.ypos(6,y_shift), "M " )
c.drawString(260, self.ypos(7,y_shift), "at " )
c.drawString(260, self.ypos(8,y_shift), "上端" )
c.drawString(260, self.ypos(9,y_shift), "下端" )
c.drawString(260, self.ypos(10,y_shift), "検定比" )
c.drawString(290, self.ypos(6,y_shift), "kN.m/m " )
c.drawString(290, self.ypos(7,y_shift), "mm2 " )
c.drawString(330, self.ypos(6,y_shift), mx1)
c.drawString(380, self.ypos(6,y_shift), mx2 )
c.drawString(430, self.ypos(6,y_shift), my1 )
c.drawString(480, self.ypos(6,y_shift), my2 )
c.drawString(330, self.ypos(7,y_shift), atx1 )
c.drawString(380, self.ypos(7,y_shift), atx2 )
c.drawString(430, self.ypos(7,y_shift), aty1 )
c.drawString(480, self.ypos(7,y_shift), aty2 )
c.drawString(330, self.ypos(8,y_shift), lx1bar + "@" + lx1Pitch )
c.drawString(380, self.ypos(9,y_shift), lx2bar + "@" + lx2Pitch )
c.drawString(430, self.ypos(8,y_shift), ly1bar + "@" + ly1Pitch )
c.drawString(480, self.ypos(9,y_shift), ly2bar + "@" + ly2Pitch )
c.drawString(330, self.ypos(10,y_shift), sfx1 )
c.drawString(380, self.ypos(10,y_shift), sfx2 )
c.drawString(430, self.ypos(10,y_shift), sfy1 )
c.drawString(480, self.ypos(10,y_shift), sfy2 )
# Deflection
c.drawString(260, self.ypos(12,y_shift), "変形")
c.drawString(260, self.ypos(13,y_shift), "Req.t = ")
c.drawString(300, self.ypos(13,y_shift), reqt + " mm,")
c.drawString(350, self.ypos(13,y_shift), "( t/Lx = " )
c.drawString(430, self.ypos(13,y_shift), tbyl + ")")
c.drawString(260, self.ypos(14,y_shift), "δ = " )
c.drawString(300, self.ypos(14,y_shift), defl + " mm, ")
c.drawString(350, self.ypos(14,y_shift), "δ/Lx = " )
c.drawString(430, self.ypos(14,y_shift), dBySan)
"""
for i in range(2,len(data)):
# txt
#c.drawString(300, 720-(i-1)*10 + y_shift, data[i])
c.drawString(500, 720-(i-1)*10 + y_shift, data[i])
"""
# png
imagefile=self.boundimage(ind_bound)
c.drawImage(imagefile, 70, y_shift + 540, width=5*cm , preserveAspectRatio=True)
def boundimage(self,index):
if index == 0 or index == 1: # 4辺固定
image_data = "./images/4sideFix.jpg"
elif index == 2: # 3辺固定
image_data = "./images/m3_1.jpg"
elif index == 3:# 3辺固定
image_data = "./images/m3_2.jpg"
elif index == 4:# 2辺固定
image_data = "./images/m2.jpg"
elif index ==5: # 4辺支持
image_data = "./images/m4pin.jpg"
elif index ==6: # 3辺支持長辺支持
image_data = "./images/m3_1pin.jpg"
elif index ==7: # 3辺固定短辺支持
image_data = "./images/m3-1pin2.jpg"
elif index ==8: # 2辺固定2辺支持
image_data = "./images/m2_2pin.jpg"
elif index ==9: # 2辺固定2辺支持
image_data = "./images/m2_2pin2.jpg"
elif index ==10: # 2辺固定2辺支持
image_data = "./images/m2_2pin3.jpg"
elif IdBound ==11: # 短辺1辺固定3辺支持
image_data = "./images/m1-3pin1.jpg"
elif IdBound ==12: # 長辺1辺固定3辺支持
image_data = "./images/m1-3pin2.jpg"
else:
print("Error report/def")
return image_data
def ypos(self,ipos,y_shift):
return 730-(ipos-1)*10 + y_shift
########################################################################
# pdfの作成
def print_page(self, c, index, nCase):
#タイトル描画
c.setFont(self.FONT_NAME, 20)
#c.drawString(50, 795, u"Design of the twoway slab")
c.drawString(50, 795, u"スラブの設計")
#グリッドヘッダー設定
xlist = [40, 240, 560]
ylist = [760, 780]
c.grid(xlist, ylist)
#sub title
c.setFont(self.FONT_NAME, 12)
c.drawString(55, 765, u"符号")
c.drawString(260, 765, u"設計")
#データを描画
########################################################################
#for i, data in range(0,int(nCase)):
for i in range(0,nCase):
# f = open(inputf[index+i],'r')
"""
tmpData = []
while True:
line = f.readline()
if line:
if line != '\n':
tmpData.append(line.replace('\n',''))
else:
tmpData.append('')
else:
break
"""
line = linecache.getline('./db/rcslab.txt', index+i+1 )
data = line.split(', ')
linecache.clearcache()
#f.close()
#data = tmpData
self.create_row( c, i, data )
#最後にグリッドを更新
#ylist = [40, 280, 520, 760]
#ylist = [40, 160, 280, 400, 520, 640, 760]
ylist = [40, 220, 400, 580, 760]
c.grid(xlist, ylist[4 - nCase:])
#ページを確定
c.showPage()
########################################################################
# pdfの作成
def print_head(self, c , title):
#title = 'Sample Project'
#タイトル描画
c.setFont(self.FONT_NAME, 20)
c.drawString(50, 795, title)
#sub title
c.setFont(self.FONT_NAME, 12)
#データを描画
########################################################################
inputf = './db/input.txt'
f = open(inputf,'r', encoding='utf-8')
tmpData = []
while True:
line = f.readline()
if line:
if line != '\n':
tmpData.append(line.replace('\n',''))
else:
tmpData.append('')
else:
break
f.close()
data = tmpData
#c.setFont(self.FONT_NAME, 9)
for i in range(0,len(data)):
# txt
c.drawString(55, 720-(i-1)*14, data[i])
"""
# Model Diagram
imagefile = './db/model.png'
c.drawImage(imagefile, 60, -300, width=18*cm , preserveAspectRatio=True)
"""
#ページを確定
c.showPage()
########################################################################
# whole control
def create_pdf(self, dataNum, pdfFile, title):
# Parameter -------
# inputf : path to text file
# imagefile: path to png file
# pdfFile : name of making pdf file
#フォントファイルを指定して、フォントを登録
#folder = os.path.dirname(reportlab.__file__) + os.sep + 'fonts'
#pdfmetrics.registerFont(TTFont(FONT_NAME, os.path.join(folder, 'ipag.ttf')))
#出力するPDFファイル
c = canvas.Canvas(pdfFile)
# ページ数
########################################################################
#dataNum = len(inputf)
numPage = dataNum // 4
numMod = dataNum % 4
#print(numPage,numMod)
if numMod >= 1:
numPage = numPage + 1
# pdfの作成
########################################################################
#self.print_head( c , title)
for i in range(0,numPage):
index = 4*i # index: 参照データのインデックス
if numPage == 1:
self.print_page( c, index, dataNum)
elif i != numPage-1 and numPage != 1:
self.print_page( c, index, 4)
else:
if numMod != 0:
self.print_page( c, index, numMod)
else:
self.print_page( c, index, 4 )
#pdfファイル生成
########################################################################
c.save()
print ("repot.py is Okay!!.")
########################################################################
# END CLASS
"""
########################################################################
# test script
pathname = "./test.pdf"
obj = Report()
# テキストの読み込み
########################################################################
inputf = []
inputf.append("./db/rcslab.txt")
inputf.append("./db/rcslab.txt")
inputf.append("./db/rcslab.txt")
inputf.append("./db/rcslab.txt")
inputf.append("./db/rcslab.txt")
inputf.append("./db/rcslab.txt")
title = "sample"
obj.create_pdf(3,pathname,title)
"""