hytos / HYTOS / HYTOS / AppDocData.py @ 5ddf3ffe
이력 | 보기 | 이력해설 | 다운로드 (33.6 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is document data(SDI) class """
|
3 |
|
4 |
import sys |
5 |
import os |
6 |
import sqlite3 |
7 |
import datetime |
8 |
from enum import Enum |
9 |
|
10 |
try:
|
11 |
from PyQt5.QtCore import * |
12 |
from PyQt5.QtGui import * |
13 |
from PyQt5 import QtWidgets |
14 |
except ImportError: |
15 |
from PyQt4.QtCore import * |
16 |
from PyQt4.QtGui import * |
17 |
import numpy as np |
18 |
|
19 |
from App import App |
20 |
from SingletonInstance import SingletonInstane |
21 |
import symbol |
22 |
from NominalPipeSize import NominalPipeSize |
23 |
|
24 |
class Source: |
25 |
def __init__(self, source): |
26 |
if type(source) is np.ndarray: |
27 |
self.source = Image.fromarray(source)
|
28 |
elif type(source) is PngImagePlugin.PngImageFile or type(source) is JpegImagePlugin.JpegImageFile: |
29 |
self.source = source
|
30 |
elif type(source) is QImage: |
31 |
self.source = Image.fromqimage(source)
|
32 |
elif type(source) is QPixmap: |
33 |
self.source = Image.fromqpixmap(source)
|
34 |
|
35 |
'''
|
36 |
@history 2018.05.18 Jeongwoo When Parameter [rect] is None, return whole image
|
37 |
'''
|
38 |
def getPyImageOnRect(self, rect = None): |
39 |
if rect is not None: |
40 |
return self.source.copy().crop((rect.left(), rect.top(), rect.right(), rect.bottom())) |
41 |
else:
|
42 |
return self.source.copy() |
43 |
|
44 |
def getQImageOnRect(self, rect = None): |
45 |
image = ImageQt(self.getPyImageOnRect(rect))
|
46 |
return image.convertToFormat(QImage.Format_RGBA8888)
|
47 |
|
48 |
class Config: |
49 |
def __init__(self, section, key, value): |
50 |
self.section = section
|
51 |
self.key = key
|
52 |
self.value = value
|
53 |
|
54 |
|
55 |
'''
|
56 |
@brief MessageType
|
57 |
@author humkyung
|
58 |
@date 2018.07.31
|
59 |
'''
|
60 |
class MessageType(Enum): |
61 |
Normal = 1
|
62 |
Error = 2
|
63 |
|
64 |
class AppDocData(SingletonInstane): |
65 |
|
66 |
def __init__(self): |
67 |
from DisplayColors import DisplayColors |
68 |
|
69 |
self._imgFilePath = None |
70 |
self.imgName = None |
71 |
self.imgWidth = 0 |
72 |
self.imgHeight = 0 |
73 |
self._OCRData = None |
74 |
|
75 |
self._areas = []
|
76 |
self.equipments = []
|
77 |
self.lineNos = []
|
78 |
self.lines = []
|
79 |
self.texts = []
|
80 |
self.symbols = []
|
81 |
self.unknowns = []
|
82 |
self.tracerLineNos = []
|
83 |
self.lineIndicators = []
|
84 |
self._colors = None |
85 |
self._lineNoProperties = None |
86 |
self._lineTypes = None |
87 |
self._lineTypeConfigs = None |
88 |
self._activeDrawing = None |
89 |
self._titleBlockProperties = None |
90 |
self.needReOpening = None |
91 |
|
92 |
self.configTable = None |
93 |
|
94 |
def clearItemList(self, trim): |
95 |
'''
|
96 |
@brief clear item list
|
97 |
@author euisung
|
98 |
@date 2018.11.28
|
99 |
'''
|
100 |
self.equipments.clear()
|
101 |
self.symbols.clear()
|
102 |
self.lineNos.clear()
|
103 |
self.texts.clear()
|
104 |
self.lines.clear()
|
105 |
self.unknowns.clear()
|
106 |
self.lineIndicators.clear()
|
107 |
if trim:
|
108 |
self.tracerLineNos.clear()
|
109 |
|
110 |
'''
|
111 |
@brief clear
|
112 |
@author humkyung
|
113 |
@date 2018.09.06
|
114 |
'''
|
115 |
def clear(self): |
116 |
self._imgFilePath = None |
117 |
self.imgName = None |
118 |
self.imgWidth = 0 |
119 |
self.imgHeight = 0 |
120 |
|
121 |
self._areas.clear()
|
122 |
self.equipments.clear()
|
123 |
self.lineNos.clear()
|
124 |
self.lines.clear()
|
125 |
self.texts.clear()
|
126 |
self.symbols.clear()
|
127 |
self.unknowns.clear()
|
128 |
self.tracerLineNos.clear()
|
129 |
self.lineIndicators.clear()
|
130 |
self._colors = None |
131 |
self._lineNoProperties = None |
132 |
self._lineTypeConfigs = None |
133 |
self._activeDrawing = None |
134 |
self._titleBlockProperties = None |
135 |
|
136 |
'''
|
137 |
@brief Get DB file path in ProgramData
|
138 |
@author Jeongwoo
|
139 |
@date 2018.06.27
|
140 |
@history 2018.06.29 Jeongwoo Change method to get template db path
|
141 |
'''
|
142 |
def getTemplateDbPath(self): |
143 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
144 |
templateDbPath = os.path.join(path, 'Template.db')
|
145 |
return templateDbPath
|
146 |
|
147 |
def getAppDbPath(self): |
148 |
"""
|
149 |
@brief Get application DB file path in ProgramData
|
150 |
@author humkyung
|
151 |
@date 2018.10.01
|
152 |
"""
|
153 |
|
154 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
155 |
app_database = os.path.join(path, 'App.db')
|
156 |
return app_database
|
157 |
|
158 |
'''
|
159 |
@brief build application database
|
160 |
@author humkyung
|
161 |
@date 2018.04.20
|
162 |
'''
|
163 |
def buildAppDatabase(self): |
164 |
try:
|
165 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
166 |
appDatabaseFilePath = os.path.join(path, 'App.db')
|
167 |
|
168 |
# Creates or opens a file called mydb with a SQLite3 DB
|
169 |
conn = sqlite3.connect(appDatabaseFilePath) |
170 |
with conn:
|
171 |
# Get a cursor object
|
172 |
cursor = conn.cursor() |
173 |
|
174 |
sqlFiles = ['App.sql']
|
175 |
for sqlFile in sqlFiles: |
176 |
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', sqlFile)
|
177 |
try:
|
178 |
file = QFile(filePath) |
179 |
file.open(QFile.ReadOnly)
|
180 |
sql = file.readAll()
|
181 |
sql = str(sql, encoding='utf8') |
182 |
cursor.executescript(sql) |
183 |
finally:
|
184 |
file.close()
|
185 |
conn.commit() |
186 |
# Catch the exception
|
187 |
except Exception as ex: |
188 |
# Roll back any change if something goes wrong
|
189 |
conn.rollback() |
190 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
191 |
|
192 |
'''
|
193 |
@brief load app style
|
194 |
@author humkyung
|
195 |
@date 2018.04.20
|
196 |
'''
|
197 |
def loadAppStyle(self): |
198 |
style = 'Fusion'
|
199 |
|
200 |
return style
|
201 |
|
202 |
@property
|
203 |
def border_file_path(self): |
204 |
""" return border file path """
|
205 |
|
206 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
207 |
return os.path.join(path, 'Border.png') |
208 |
|
209 |
@property
|
210 |
def symbol_file_path(self): |
211 |
""" return svg symbol file path """
|
212 |
|
213 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
214 |
return os.path.join(path, 'svg') |
215 |
|
216 |
def getRoughness(self): |
217 |
res = [] |
218 |
|
219 |
conn = sqlite3.connect(self.activeDrawing.path)
|
220 |
with conn:
|
221 |
try:
|
222 |
conn.row_factory = sqlite3.Row |
223 |
# Get a cursor object
|
224 |
cursor = conn.cursor() |
225 |
|
226 |
sql = "select UID, Material, Meter, Inch, Feet, Milimeter from Roughness"
|
227 |
cursor.execute(sql) |
228 |
rows = cursor.fetchall() |
229 |
for row in rows: |
230 |
res.append((row[0], row[1], row[2], row[3], row[4], row[5])) |
231 |
# Catch the exception
|
232 |
except Exception as ex: |
233 |
# Roll back any change if something goes wrong
|
234 |
conn.rollback() |
235 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
236 |
|
237 |
return res
|
238 |
|
239 |
def getInsideDiameter(self, nominaldiameter_uid, schedule_uid): |
240 |
res = [] |
241 |
try:
|
242 |
db = sqlite3.connect(self.activeDrawing.path)
|
243 |
# Get a cursor object
|
244 |
cursor = db.cursor() |
245 |
|
246 |
sql = """select UID
|
247 |
, Milimeter
|
248 |
, Inch
|
249 |
from InsideDiameter
|
250 |
where NominalDiameter_UID = ?
|
251 |
and Schedule_UID = ?"""
|
252 |
|
253 |
param = (nominaldiameter_uid, schedule_uid) |
254 |
cursor.execute(sql, param) |
255 |
rows = cursor.fetchall() |
256 |
for row in rows: |
257 |
res.append((row[0], row[1], row[2])) |
258 |
# Catch the exception
|
259 |
except Exception as ex: |
260 |
# Roll back any change if something goes wrong
|
261 |
db.rollback() |
262 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
263 |
finally:
|
264 |
# Close the db connection
|
265 |
db.close() |
266 |
|
267 |
return res
|
268 |
|
269 |
def getSchedule(self): |
270 |
res = [] |
271 |
|
272 |
conn = sqlite3.connect(self.activeDrawing.path)
|
273 |
with conn:
|
274 |
try:
|
275 |
# Get a cursor object
|
276 |
cursor = conn.cursor() |
277 |
|
278 |
sql = "select UID, No from Schedule"
|
279 |
cursor.execute(sql) |
280 |
rows = cursor.fetchall() |
281 |
for row in rows: |
282 |
res.append((row[0], row[1])) |
283 |
# Catch the exception
|
284 |
except Exception as ex: |
285 |
# Roll back any change if something goes wrong
|
286 |
conn.rollback() |
287 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
288 |
|
289 |
return res
|
290 |
|
291 |
def getNominalDiameter(self): |
292 |
res = [] |
293 |
|
294 |
# Creates or opens a file called mydb with a SQLite3 DB
|
295 |
conn = sqlite3.connect(self.activeDrawing.path)
|
296 |
with conn:
|
297 |
try:
|
298 |
# Get a cursor object
|
299 |
cursor = conn.cursor() |
300 |
|
301 |
sql = "select UID, Milimeter, Inch from NominalDiameter"
|
302 |
cursor.execute(sql) |
303 |
rows = cursor.fetchall() |
304 |
for row in rows: |
305 |
res.append((row[0], row[1], row[2])) |
306 |
# Catch the exception
|
307 |
except Exception as ex: |
308 |
# Roll back any change if something goes wrong
|
309 |
conn.rollback() |
310 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
311 |
|
312 |
return res
|
313 |
|
314 |
|
315 |
def getAppConfigs(self, section, key=None): |
316 |
"""
|
317 |
@brief get application configurations
|
318 |
@author humkyung
|
319 |
@date 2018.11.01
|
320 |
"""
|
321 |
|
322 |
res = [] |
323 |
|
324 |
try:
|
325 |
# Creates or opens a file called mydb with a SQLite3 DB
|
326 |
dbPath = self.getAppDbPath()
|
327 |
conn = sqlite3.connect(dbPath) |
328 |
# Get a cursor object
|
329 |
cursor = conn.cursor() |
330 |
|
331 |
if key is not None: |
332 |
sql = "select * from configuration where section=? and key=?"
|
333 |
param = (section, key) |
334 |
else:
|
335 |
sql = "select * from configuration where section=?"
|
336 |
param = (section,) |
337 |
|
338 |
cursor.execute(sql, param) |
339 |
rows = cursor.fetchall() |
340 |
for row in rows: |
341 |
res.append(Config(row[0], row[1], row[2])) |
342 |
# Catch the exception
|
343 |
except Exception as ex: |
344 |
# Roll back any change if something goes wrong
|
345 |
conn.rollback() |
346 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
347 |
finally:
|
348 |
# Close the db connection
|
349 |
conn.close() |
350 |
|
351 |
return res
|
352 |
|
353 |
|
354 |
def saveAppConfigs(self, configs): |
355 |
"""
|
356 |
@brief save application configurations
|
357 |
@author humkyung
|
358 |
@date 2018.10.01
|
359 |
"""
|
360 |
|
361 |
try:
|
362 |
# Creates or opens a file called mydb with a SQLite3 DB
|
363 |
dbPath = self.getAppDbPath()
|
364 |
conn = sqlite3.connect(dbPath) |
365 |
# Get a cursor object
|
366 |
cursor = conn.cursor() |
367 |
|
368 |
for config in configs: |
369 |
value = config.value |
370 |
if type(value) is str and "'" in value: |
371 |
value = value.replace("'", "''") |
372 |
|
373 |
sql = "insert or replace into configuration values(?,?,?)"
|
374 |
param = (config.section, config.key, value) |
375 |
|
376 |
cursor.execute(sql, param) |
377 |
conn.commit() |
378 |
# Catch the exception
|
379 |
except Exception as ex: |
380 |
# Roll back any change if something goes wrong
|
381 |
conn.rollback() |
382 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
383 |
finally:
|
384 |
# Close the db connection
|
385 |
conn.close() |
386 |
|
387 |
|
388 |
def initializeDataByDrawingUID(self, uid): |
389 |
try:
|
390 |
# Creates or opens a file called mydb with a SQLite3 DB
|
391 |
conn = sqlite3.connect(self.activeDrawing.path)
|
392 |
# Get a cursor object
|
393 |
cursor = conn.cursor() |
394 |
|
395 |
# 0. Delete Points
|
396 |
sql = "delete from Points where Components_UID in (select UID from Components where Drawings_UID = '{}')".format(uid)
|
397 |
cursor.execute(sql) |
398 |
|
399 |
# 1. Delete HMB
|
400 |
sql = "delete from HMB where Components_UID in (select UID from Components where Drawings_UID = '{}')".format(uid)
|
401 |
cursor.execute(sql) |
402 |
|
403 |
# 2. Delete Components
|
404 |
sql = "delete from Components where Drawings_UID='{}'".format(uid)
|
405 |
cursor.execute(sql) |
406 |
|
407 |
conn.commit() |
408 |
# Catch the exception
|
409 |
except Exception as ex: |
410 |
# Roll back any change if something goes wrong
|
411 |
conn.rollback() |
412 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
413 |
finally:
|
414 |
# Close the db connection
|
415 |
conn.close() |
416 |
|
417 |
def deleteDrawingByName(self, drawingName): |
418 |
""" delete given drawing """
|
419 |
conn = sqlite3.connect(self.getAppDbPath())
|
420 |
with conn:
|
421 |
try:
|
422 |
# Get a cursor object
|
423 |
cursor = conn.cursor() |
424 |
|
425 |
sql = 'delete from Drawings where Name=?'
|
426 |
param = (drawingName,) |
427 |
cursor.execute(sql, param) |
428 |
|
429 |
conn.commit() |
430 |
# Catch the exception
|
431 |
except Exception as ex: |
432 |
# Roll back any change if something goes wrong
|
433 |
conn.rollback() |
434 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
435 |
|
436 |
|
437 |
def deleteAppConfigs(self, section, key=None): |
438 |
"""
|
439 |
@brief delete application configurations
|
440 |
@author humkyung
|
441 |
@date 2018.11.01
|
442 |
"""
|
443 |
|
444 |
try:
|
445 |
# Creates or opens a file called mydb with a SQLite3 DB
|
446 |
dbPath = self.getAppDbPath()
|
447 |
conn = sqlite3.connect(dbPath) |
448 |
# Get a cursor object
|
449 |
cursor = conn.cursor() |
450 |
|
451 |
if key is not None: |
452 |
sql = "delete from configuration where section='{}' and key='{}'".format(section, key)
|
453 |
else:
|
454 |
sql = "delete from configuration where section='{}'".format(section)
|
455 |
cursor.execute(sql) |
456 |
|
457 |
conn.commit() |
458 |
# Catch the exception
|
459 |
except Exception as ex: |
460 |
# Roll back any change if something goes wrong
|
461 |
conn.rollback() |
462 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
463 |
finally:
|
464 |
# Close the db connection
|
465 |
conn.close() |
466 |
|
467 |
'''
|
468 |
@brief get symbol name
|
469 |
@history 18.04.24 Jeongwoo Add isExceptDetect Field
|
470 |
'''
|
471 |
def getSymbolByQuery(self, fieldName, param): |
472 |
ret = None
|
473 |
|
474 |
conn = sqlite3.connect(self.activeDrawing.path)
|
475 |
with conn:
|
476 |
cursor = conn.cursor() |
477 |
|
478 |
sql = """select s.UID
|
479 |
, s.Name
|
480 |
, t.Category
|
481 |
, t.Type
|
482 |
, s.OriginalPoint
|
483 |
, s.ConnectionPoint
|
484 |
from Symbols s
|
485 |
inner join SymbolType t
|
486 |
on s.SymbolType_UID = t.UID
|
487 |
where """ + "s." + fieldName + '=?' |
488 |
|
489 |
try:
|
490 |
cursor.execute(sql, (param,)) |
491 |
rows = cursor.fetchall() |
492 |
if rows is not None and len(rows) > 0: |
493 |
symbolTuple = rows[0]
|
494 |
ret = symbol.SymbolBase(symbolTuple[0], symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4], symbolTuple[5]) |
495 |
except Exception as ex: |
496 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
497 |
|
498 |
return ret
|
499 |
|
500 |
def getSymbolListByUID(self, uid): |
501 |
""" get symbol list by given uid """
|
502 |
ret = [] |
503 |
|
504 |
conn = sqlite3.connect(self.activeDrawing.path)
|
505 |
with conn:
|
506 |
cursor = conn.cursor() |
507 |
|
508 |
sql = """select s.UID
|
509 |
, s.Name
|
510 |
, t.Category
|
511 |
, t.Type
|
512 |
, s.OriginalPoint
|
513 |
, s.ConnectionPoint
|
514 |
from Symbols s
|
515 |
inner join SymbolType t
|
516 |
on s.SymbolType_UID = t.uid
|
517 |
where s.SymbolType_UID = ?"""
|
518 |
|
519 |
try:
|
520 |
cursor.execute(sql, (uid,)) |
521 |
rows = cursor.fetchall() |
522 |
if rows is not None and len(rows) > 0: |
523 |
for row in rows: |
524 |
sym = symbol.SymbolBase(row[0], row[1], row[2], row[3], row[4], row[5]) |
525 |
|
526 |
ret.append(sym) |
527 |
except Exception as ex: |
528 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
529 |
|
530 |
return ret
|
531 |
|
532 |
|
533 |
def getResistanceCoefficientByMethod(self, method): |
534 |
res = [] |
535 |
try:
|
536 |
# Creates or opens a file called mydb with a SQLite3 DB
|
537 |
dbPath = os.path.join(self.activeDrawing.path)
|
538 |
db = sqlite3.connect(dbPath) |
539 |
db.row_factory = sqlite3.Row |
540 |
# Get a cursor object
|
541 |
cursor = db.cursor() |
542 |
|
543 |
sql = """select UID
|
544 |
, Method
|
545 |
, Category
|
546 |
, Type
|
547 |
, Name
|
548 |
, K
|
549 |
from ResistanceCoefficient
|
550 |
where Method = ?
|
551 |
order by rowid"""
|
552 |
|
553 |
param = (method,) |
554 |
cursor.execute(sql, param) |
555 |
rows = cursor.fetchall() |
556 |
for row in rows: |
557 |
res.append((row[0], row[1], row[2], row[3], row[4], row[5])) |
558 |
# Catch the exception
|
559 |
except Exception as ex: |
560 |
# Roll back any change if something goes wrong
|
561 |
db.rollback() |
562 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
563 |
finally:
|
564 |
# Close the db connection
|
565 |
db.close() |
566 |
|
567 |
return res
|
568 |
|
569 |
'''
|
570 |
@brief save to database
|
571 |
@author yjkim
|
572 |
@date 2019.08.28
|
573 |
'''
|
574 |
def saveToDatabase(self, item, index): |
575 |
""" save given items to database """
|
576 |
conn = sqlite3.connect(self.activeDrawing.path, isolation_level=None) |
577 |
with conn:
|
578 |
try:
|
579 |
# Get a cursor object
|
580 |
cursor = conn.cursor() |
581 |
|
582 |
if index == 0: |
583 |
# delete Points
|
584 |
sql = 'delete from Points'
|
585 |
cursor.execute(sql) |
586 |
|
587 |
# delete HMB
|
588 |
sql = 'delete from HMB'
|
589 |
cursor.execute(sql) |
590 |
|
591 |
# delete Components
|
592 |
sql = 'delete from Components'
|
593 |
cursor.execute(sql) |
594 |
|
595 |
sql = item.toSql() |
596 |
if type(sql) is list: |
597 |
for item in sql: |
598 |
if item is not None and 2 == len(item): |
599 |
cursor.execute(item[0], item[1]) |
600 |
else:
|
601 |
if sql is not None and 2 == len(sql): |
602 |
cursor.execute(sql[0], sql[1]) |
603 |
|
604 |
conn.commit() |
605 |
# Catch the exception
|
606 |
except Exception as ex: |
607 |
from App import App |
608 |
# Roll back any change if something goes wrong
|
609 |
conn.rollback() |
610 |
|
611 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
612 |
print(message) |
613 |
print(sql) |
614 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
615 |
|
616 |
|
617 |
def getDrawings(self): |
618 |
"""
|
619 |
@brief get drawings
|
620 |
@author humkyung
|
621 |
@date 2018.11.03
|
622 |
"""
|
623 |
from Drawing import Drawing |
624 |
|
625 |
res = [] |
626 |
# Creates or opens a file called mydb with a SQLite3 DB
|
627 |
dbPath = self.getAppDbPath()
|
628 |
conn = sqlite3.connect(dbPath) |
629 |
with conn:
|
630 |
try:
|
631 |
conn.row_factory = sqlite3.Row |
632 |
# Get a cursor object
|
633 |
cursor = conn.cursor() |
634 |
|
635 |
sql = 'select UID,[NAME],[DATETIME] from Drawings'
|
636 |
cursor.execute(sql) |
637 |
rows = cursor.fetchall() |
638 |
for row in rows: |
639 |
res.append(Drawing(row[0], row[1], row[2])) |
640 |
# Catch the exception
|
641 |
except Exception as ex: |
642 |
# Roll back any change if something goes wrong
|
643 |
conn.rollback() |
644 |
from App import App |
645 |
|
646 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
647 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
648 |
|
649 |
return res
|
650 |
|
651 |
'''
|
652 |
@brief update drawings
|
653 |
@author yeonjin
|
654 |
@date 2019.08.07
|
655 |
'''
|
656 |
def updateDrawing(self, drawing): |
657 |
import uuid |
658 |
|
659 |
# Creates or opens a file called mydb with a SQLite3 DB
|
660 |
dbPath = self.getAppDbPath()
|
661 |
conn = sqlite3.connect(dbPath) |
662 |
with conn:
|
663 |
try:
|
664 |
# Get a cursor object
|
665 |
cursor = conn.cursor() |
666 |
|
667 |
sql = """update Drawings
|
668 |
set Name = ?
|
669 |
, DateTime = ?
|
670 |
where uid = ?"""
|
671 |
param = (drawing[0][1], drawing[0][2], drawing[0][0]) |
672 |
cursor.execute(sql, param) |
673 |
|
674 |
conn.commit() |
675 |
|
676 |
# Catch the exception
|
677 |
except Exception as ex: |
678 |
# Roll back any change if something goes wrong
|
679 |
conn.rollback() |
680 |
from App import App |
681 |
|
682 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
683 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
684 |
|
685 |
'''
|
686 |
@brief save drawings
|
687 |
@author humkyung
|
688 |
@date 2018.11.03
|
689 |
'''
|
690 |
def saveDrawing(self, drawing): |
691 |
import uuid |
692 |
from shutil import copyfile |
693 |
|
694 |
conn = sqlite3.connect(self.getAppDbPath())
|
695 |
with conn:
|
696 |
try:
|
697 |
# Get a cursor object
|
698 |
cursor = conn.cursor() |
699 |
|
700 |
sql = 'insert or replace into Drawings(UID, [NAME], [DATETIME]) values(?, ?, ?)'
|
701 |
param = (drawing.UID, drawing.path, drawing.date_time) |
702 |
cursor.execute(sql, param) |
703 |
|
704 |
conn.commit() |
705 |
|
706 |
if not os.path.exists(drawing.path): copyfile(self.getTemplateDbPath(), drawing.path) |
707 |
# Catch the exception
|
708 |
except Exception as ex: |
709 |
# Roll back any change if something goes wrong
|
710 |
conn.rollback() |
711 |
from App import App |
712 |
|
713 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
714 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
715 |
|
716 |
'''
|
717 |
@brief Return Symbol Category Items
|
718 |
@author yeonjin
|
719 |
@date 19.07.11
|
720 |
'''
|
721 |
def getSymbolCategoryList(self): |
722 |
SymbolCategoryList = [] |
723 |
|
724 |
conn = sqlite3.connect(self.activeDrawing.path)
|
725 |
with conn:
|
726 |
cursor = conn.cursor() |
727 |
sql = 'SELECT DISTINCT CATEGORY FROM SymbolType ORDER BY type ASC'
|
728 |
try:
|
729 |
cursor.execute(sql) |
730 |
rows = cursor.fetchall() |
731 |
for row in rows: |
732 |
SymbolCategoryList.append((row[0])) # category |
733 |
except Exception as ex: |
734 |
from App import App |
735 |
|
736 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
737 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
738 |
|
739 |
return SymbolCategoryList
|
740 |
|
741 |
|
742 |
def getComponentByComponentUID(self, uid): |
743 |
ComponentList = [] |
744 |
|
745 |
conn = sqlite3.connect(self.activeDrawing.path)
|
746 |
with conn:
|
747 |
try:
|
748 |
conn.row_factory = sqlite3.Row |
749 |
cursor = conn.cursor() |
750 |
|
751 |
sql = """select c.uid
|
752 |
, c.Name
|
753 |
, c.Symbols_UID
|
754 |
, t.Category
|
755 |
, t.type
|
756 |
, s.Name
|
757 |
, s.OriginalPoint
|
758 |
, c.X
|
759 |
, c.Y
|
760 |
, c.Rotation
|
761 |
, c.Scale
|
762 |
, p.uid
|
763 |
, p.[Index]
|
764 |
, p.x
|
765 |
, p.y
|
766 |
, p.ConnectedItem_UID
|
767 |
from points p
|
768 |
left join components c
|
769 |
on p.components_uid = c.uid
|
770 |
left join symbols s
|
771 |
on c.Symbols_UID = s.UID
|
772 |
left join SymbolType t
|
773 |
on s.symboltype_uid = t.uid
|
774 |
where c.uid = ?
|
775 |
order by p.[Index]"""
|
776 |
param = (uid,) |
777 |
cursor.execute(sql, param) |
778 |
rows = cursor.fetchall() |
779 |
for row in rows: |
780 |
data = [] |
781 |
for index in range(len(cursor.description)): |
782 |
data.append(row[index]) |
783 |
ComponentList.append(data) # Components_UID
|
784 |
except Exception as ex: |
785 |
from App import App |
786 |
|
787 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
788 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
789 |
|
790 |
return ComponentList
|
791 |
|
792 |
def get_nozzle_data(self, uid): |
793 |
""" get nozzle data of given uid """
|
794 |
from EngineeringConnectorItem import NozzleData |
795 |
|
796 |
res = None
|
797 |
conn = sqlite3.connect(self.activeDrawing.path)
|
798 |
with conn:
|
799 |
conn.row_factory = sqlite3.Row |
800 |
cursor = conn.cursor() |
801 |
sql = 'select Pressure, Pressure_Drop, Elevation, Over_Design_CV from Nozzles where Points_UID=?'
|
802 |
param = (uid, ) |
803 |
cursor.execute(sql, param) |
804 |
rows = cursor.fetchall() |
805 |
if rows:
|
806 |
res = NozzleData() |
807 |
if rows[0]['Pressure']: |
808 |
res.pressure = float(rows[0]['Pressure']) |
809 |
if rows[0]['Pressure_Drop']: |
810 |
res.pressure_drop = float(rows[0]['Pressure_Drop']) |
811 |
if rows[0]['Elevation']: |
812 |
res.elevation = float(rows[0]['Elevation']) |
813 |
if rows[0]['Over_Design_CV']: |
814 |
res.over_design_cv = float(rows[0]['Over_Design_CV']) |
815 |
return res
|
816 |
|
817 |
def getDrawingsUnitsByDrawingUID(self, drawing): |
818 |
""" get units of drawing """
|
819 |
unitsList = [] |
820 |
|
821 |
conn = sqlite3.connect(drawing.path) |
822 |
with conn:
|
823 |
cursor = conn.cursor() |
824 |
|
825 |
sql = 'select du.Units, u.Value from DrawingsUnits du \
|
826 |
left join units u on du.Units_UID = u.uid'
|
827 |
try:
|
828 |
cursor.execute(sql) |
829 |
rows = cursor.fetchall() |
830 |
for row in rows: |
831 |
unitsList.append((row[0], row[1])) |
832 |
except Exception as ex: |
833 |
from App import App |
834 |
|
835 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
836 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
837 |
|
838 |
return unitsList
|
839 |
|
840 |
|
841 |
'''
|
842 |
@brief Return Components By DrawingUID
|
843 |
@author yeonjin
|
844 |
@date 19.07.29
|
845 |
'''
|
846 |
def getComponentListByDrawingUID(self, drawing): |
847 |
ComponentList = [] |
848 |
|
849 |
conn = sqlite3.connect(drawing.path) |
850 |
with conn:
|
851 |
try:
|
852 |
conn.row_factory = sqlite3.Row |
853 |
cursor = conn.cursor() |
854 |
sql = 'select UID from Components order by x desc'
|
855 |
cursor.execute(sql) |
856 |
rows = cursor.fetchall() |
857 |
for row in rows: |
858 |
ComponentList.append((row[0])) # Components_UID |
859 |
except Exception as ex: |
860 |
from App import App |
861 |
|
862 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
863 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
864 |
|
865 |
return ComponentList
|
866 |
|
867 |
'''
|
868 |
@brief Return Symbol Type Items By Category
|
869 |
@author yeonjin
|
870 |
@date 19.07.11
|
871 |
'''
|
872 |
def getSymbolTypeListByCategory(self, category): |
873 |
symbolTypeList = [] |
874 |
|
875 |
conn = sqlite3.connect(self.activeDrawing.path)
|
876 |
with conn:
|
877 |
cursor = conn.cursor() |
878 |
sql = 'SELECT UID, Category, Type FROM SymbolType WHERE Category = "' + category + '"' |
879 |
try:
|
880 |
cursor.execute(sql) |
881 |
rows = cursor.fetchall() |
882 |
for row in rows: |
883 |
symbolTypeList.append((row[0], row[1], row[2])) # UID, Category, Type |
884 |
except Exception as ex: |
885 |
from App import App |
886 |
|
887 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
888 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
889 |
|
890 |
return symbolTypeList
|
891 |
|
892 |
def getUnits(self): |
893 |
unitsList = [] |
894 |
|
895 |
try:
|
896 |
conn = sqlite3.connect(self.activeDrawing.path)
|
897 |
cursor = conn.cursor() |
898 |
sql = 'Select UID, Key, Value From Units'
|
899 |
try:
|
900 |
cursor.execute(sql) |
901 |
rows = cursor.fetchall() |
902 |
for row in rows: |
903 |
unitsList.append((row[0], row[1], row[2])) # UID, Key, Value |
904 |
except Exception as ex: |
905 |
from App import App |
906 |
|
907 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
908 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
909 |
finally:
|
910 |
conn.close() |
911 |
|
912 |
return unitsList
|
913 |
|
914 |
|
915 |
def getHMBDisplayNameAndUnitsExpression(self): |
916 |
res = [] |
917 |
|
918 |
if self.activeDrawing: |
919 |
conn = sqlite3.connect(self.activeDrawing.path)
|
920 |
with conn:
|
921 |
cursor = conn.cursor() |
922 |
sql = """SELECT dn.DISPLAY_NAME
|
923 |
, hu.Units_Expression
|
924 |
FROM DisplayNames dn
|
925 |
left join HMBUnits hu
|
926 |
on dn.COLUMN_NAME = Hu.Column_Name
|
927 |
where dn.Table_Name = 'HMB'
|
928 |
order by dn.[Order]"""
|
929 |
try:
|
930 |
cursor.execute(sql) |
931 |
rows = cursor.fetchall() |
932 |
for row in rows: |
933 |
res.append((row[0], row[1])) |
934 |
except Exception as ex: |
935 |
from App import App |
936 |
|
937 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
938 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
939 |
|
940 |
return res
|
941 |
|
942 |
'''
|
943 |
@brief Get Symbol Category by Symbol Type
|
944 |
@author Jeongwoo
|
945 |
@date 2018.05.09
|
946 |
'''
|
947 |
def getSymbolCategoryByType(self, type): |
948 |
category = None
|
949 |
|
950 |
conn = sqlite3.connect(self.activeDrawing.path)
|
951 |
with conn:
|
952 |
try:
|
953 |
cursor = conn.cursor() |
954 |
sql = 'SELECT Category FROM SymbolType WHERE type = "' + type + '"' |
955 |
cursor.execute(sql) |
956 |
rows = cursor.fetchall() |
957 |
if rows is not None and len(rows) > 0: |
958 |
category = rows[0][0] |
959 |
except Exception as ex: |
960 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
961 |
|
962 |
return category
|
963 |
|
964 |
|
965 |
|
966 |
'''
|
967 |
@brief getter of activeDrawing
|
968 |
@author humkyung
|
969 |
@date 2018.07.07
|
970 |
'''
|
971 |
@property
|
972 |
def activeDrawing(self): |
973 |
return self._activeDrawing |
974 |
|
975 |
'''
|
976 |
@brief setter of activeDrawing
|
977 |
@author humkyung
|
978 |
@date 2018.07.07
|
979 |
'''
|
980 |
@activeDrawing.setter
|
981 |
def activeDrawing(self, value): |
982 |
self._activeDrawing = value
|