hytos / DTI_PID / DTI_PID / AppDocData.py @ 9d0a18b6
이력 | 보기 | 이력해설 | 다운로드 (49.4 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
import sys |
4 |
import os |
5 |
from PyQt5.QtCore import * |
6 |
import sqlite3 |
7 |
import datetime |
8 |
from PIL import PngImagePlugin, JpegImagePlugin |
9 |
from PIL import Image |
10 |
from PIL.ImageQt import ImageQt |
11 |
|
12 |
try:
|
13 |
from PyQt5.QtCore import QBuffer |
14 |
from PyQt5.QtGui import QImage, QPixmap |
15 |
except ImportError: |
16 |
from PyQt4.QtCore import QBuffer |
17 |
from PyQt4.QtGui import QImage, QPixmap |
18 |
import numpy as np |
19 |
|
20 |
from SingletonInstance import SingletonInstane |
21 |
import Project |
22 |
import SymbolBase |
23 |
import symbol |
24 |
from EquipmentData import EquipmentData |
25 |
|
26 |
class Source: |
27 |
def __init__(self, source): |
28 |
if type(source) is np.ndarray: |
29 |
self.source = Image.fromarray(source)
|
30 |
elif type(source) is PngImagePlugin.PngImageFile or type(source) is JpegImagePlugin.JpegImageFile: |
31 |
self.source = source
|
32 |
elif type(source) is QImage: |
33 |
self.source = Image.fromqimage(source)
|
34 |
elif type(source) is QPixmap: |
35 |
self.source = Image.fromqpixmap(source)
|
36 |
|
37 |
'''
|
38 |
@history 2018.05.18 Jeongwoo When Parameter [rect] is None, return whole image
|
39 |
'''
|
40 |
def getPyImageOnRect(self, rect = None): |
41 |
if rect is not None: |
42 |
return self.source.copy().crop((rect.left(), rect.top(), rect.right(), rect.bottom())) |
43 |
else:
|
44 |
return self.source.copy() |
45 |
|
46 |
def getQImageOnRect(self, rect = None): |
47 |
image = ImageQt(self.getPyImageOnRect(rect))
|
48 |
return image.convertToFormat(QImage.Format_RGBA8888)
|
49 |
|
50 |
class Area: |
51 |
def __init__(self): |
52 |
self.name = None |
53 |
self.x = None |
54 |
self.y = None |
55 |
self.width = None |
56 |
self.height = None |
57 |
|
58 |
'''
|
59 |
@brief parse area
|
60 |
@author humkyung
|
61 |
@date 2018.06.29
|
62 |
'''
|
63 |
def parse(self, strArea): |
64 |
import re |
65 |
|
66 |
found = re.findall('\d+', strArea)
|
67 |
if len(found) == 4: |
68 |
self.x = int(found[0]) |
69 |
self.y = int(found[1]) |
70 |
self.width = int(found[2]) |
71 |
self.height = int(found[3]) |
72 |
|
73 |
'''
|
74 |
@brief to string
|
75 |
@author humkyung
|
76 |
@date 2018.06.30
|
77 |
'''
|
78 |
def toString(self): |
79 |
return '({},{}),({},{})'.format(self.x, self.y, self.width, self.height) |
80 |
|
81 |
'''
|
82 |
@brief clone an object
|
83 |
'''
|
84 |
def clone(self): |
85 |
clone = Area() |
86 |
clone.x = self.x
|
87 |
clone.y = self.y
|
88 |
clone.width = self.width
|
89 |
clone.height = self.height
|
90 |
|
91 |
class Config: |
92 |
def __init__(self, section, key, value): |
93 |
self.section = section
|
94 |
self.key = key
|
95 |
self.value = value
|
96 |
|
97 |
class NominalPipeSize: |
98 |
def __init__(self, code, metric, inch, inchStr, metricStr): |
99 |
self.code = code
|
100 |
self.metric = metric
|
101 |
self.inch = inch
|
102 |
self.inchStr = inchStr
|
103 |
self.metricStr = metricStr
|
104 |
self.sizeUnit = 'Metric' |
105 |
|
106 |
'''
|
107 |
@brief return size value string
|
108 |
@author humkyung
|
109 |
@date 2018.04.24
|
110 |
'''
|
111 |
def sizeValue(self): |
112 |
return self.inchStr if 'Inch' == self.sizeUnit else self.metricStr |
113 |
|
114 |
'''
|
115 |
@brief Pipe color class
|
116 |
'''
|
117 |
class Color: |
118 |
def __init__(self, index, red, green, blue): |
119 |
self.index = index
|
120 |
self.red = red
|
121 |
self.green = green
|
122 |
self.blue = blue
|
123 |
|
124 |
class AppDocData(SingletonInstane): |
125 |
def __init__(self): |
126 |
self.imgName = None |
127 |
self.imgWidth = 0 |
128 |
self.imgHeight = 0 |
129 |
|
130 |
self._areas = []
|
131 |
self.equipments = []
|
132 |
self.equipmentDataList = []
|
133 |
self.lineNos = []
|
134 |
self.lines = []
|
135 |
self.symbols = []
|
136 |
self._colors = None |
137 |
self._lineTypes = None |
138 |
self._lineTypeConfigs = None |
139 |
|
140 |
'''
|
141 |
@brief Get DB file path in ProgramData
|
142 |
@author Jeongwoo
|
143 |
@date 2018.06.27
|
144 |
@history 2018.06.29 Jeongwoo Change method to get template db path
|
145 |
'''
|
146 |
def getTemplateDbPath(self): |
147 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
148 |
templateDbPath = os.path.join(path, 'Template.db')
|
149 |
return templateDbPath
|
150 |
|
151 |
'''
|
152 |
@brief getter of colors
|
153 |
@author humkyung
|
154 |
@date 2018.06.18
|
155 |
'''
|
156 |
@property
|
157 |
def colors(self): |
158 |
if self._colors is None: |
159 |
self._colors = []
|
160 |
try:
|
161 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath() , 'ITI_PID.db') |
162 |
|
163 |
conn = sqlite3.connect(dbPath) |
164 |
cursor = conn.cursor() |
165 |
sql = 'SELECT UID,RED,GREEN,BLUE FROM Colors'
|
166 |
cursor.execute(sql) |
167 |
rows = cursor.fetchall() |
168 |
for row in rows: |
169 |
self._colors.append(Color(int(row[0]), int(row[1]), int(row[2]), int(row[3]))) |
170 |
# Catch the exception
|
171 |
except Exception as ex: |
172 |
# Roll back any change if something goes wrong
|
173 |
conn.rollback() |
174 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
175 |
finally:
|
176 |
conn.close() |
177 |
|
178 |
return self._colors |
179 |
|
180 |
'''
|
181 |
@brief setter of colors
|
182 |
@author humkyung
|
183 |
@date 2018.06.18
|
184 |
'''
|
185 |
@colors.setter
|
186 |
def colors(self, value): |
187 |
self._colors = value
|
188 |
|
189 |
'''
|
190 |
@brief getter of line type configs
|
191 |
@author humkyung
|
192 |
@date 2018.06.28
|
193 |
'''
|
194 |
@property
|
195 |
def lineTypeConfigs(self): |
196 |
from PyQt5.QtCore import Qt |
197 |
|
198 |
if self._lineTypeConfigs is None: |
199 |
self._lineTypeConfigs = []
|
200 |
|
201 |
styleMap = [('SolidLine', Qt.SolidLine), ('DashLine', Qt.DashLine), ('DotLine', Qt.DotLine), ('DashDotLine', Qt.DashDotLine), |
202 |
('DashDotDotLine', Qt.DashDotDotLine), ('CustomDashLine', Qt.CustomDashLine)] |
203 |
|
204 |
configs = self.getConfigs('LineTypes') |
205 |
for config in configs: |
206 |
width, _style = config.value.split(',')
|
207 |
matches = [param for param in styleMap if param[0] == _style] |
208 |
style = matches[0][1] if matches else Qt.SolidLine |
209 |
self._lineTypeConfigs.append((config.key, int(width), style)) |
210 |
|
211 |
return self._lineTypeConfigs |
212 |
|
213 |
'''
|
214 |
@brief setter of line type configs
|
215 |
@author humkyung
|
216 |
@date 2018.06.28
|
217 |
'''
|
218 |
@lineTypeConfigs.setter
|
219 |
def lineTypeConfigs(self, value): |
220 |
self._lineTypeConfigs = value
|
221 |
|
222 |
'''
|
223 |
@brief get line type config of given line type
|
224 |
@author humkyung
|
225 |
@date 2018.06.28
|
226 |
'''
|
227 |
def getLineTypeConfig(self, lineType): |
228 |
from PyQt5.QtCore import Qt |
229 |
|
230 |
matches = [config for config in self.lineTypeConfigs if config[0] == lineType] |
231 |
return matches[0] if matches else (lineType, 5, Qt.SolidLine) |
232 |
|
233 |
def setCurrentPidSource(self, image): |
234 |
self.imgWidth, self.imgHeight = image.size |
235 |
|
236 |
self.currentPidSource = Source(image)
|
237 |
|
238 |
def getCurrentPidSource(self): |
239 |
return self.currentPidSource |
240 |
|
241 |
'''
|
242 |
@brief Check if Exist data or not, Moved from SG_DbHelper
|
243 |
@author Jeongwoo
|
244 |
@date 2018.05.03
|
245 |
'''
|
246 |
def isExistData(self, fieldName, data): |
247 |
rows = None
|
248 |
try:
|
249 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
250 |
|
251 |
conn = sqlite3.connect(dbPath) |
252 |
cursor = conn.cursor() |
253 |
sql = ""
|
254 |
if isinstance(data, str): |
255 |
sql = "SELECT * FROM Symbol WHERE " + fieldName + " = '"+ data +"'" |
256 |
else:
|
257 |
sql = "SELECT * FROM Symbol WHERE " + fieldName + " = "+ str(data) +"" |
258 |
cursor.execute(sql) |
259 |
rows = cursor.fetchall() |
260 |
# Catch the exception
|
261 |
except Exception as ex: |
262 |
# Roll back any change if something goes wrong
|
263 |
conn.rollback() |
264 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
265 |
finally:
|
266 |
conn.close() |
267 |
if rows is not None and len(rows) > 0: |
268 |
return True |
269 |
else:
|
270 |
return False |
271 |
|
272 |
'''
|
273 |
@brief Check if exist file name or not, Moved from SG_DbHelper
|
274 |
@author Jeongwoo
|
275 |
@date 2018.05.03
|
276 |
'''
|
277 |
def isExistFileName(self, name): |
278 |
rows = None
|
279 |
try:
|
280 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
281 |
conn = sqlite3.connect(dbPath) |
282 |
cursor = conn.cursor() |
283 |
sql = "SELECT * FROM Symbol WHERE name = '"+ name +"'" |
284 |
cursor.execute(sql) |
285 |
rows = cursor.fetchall() |
286 |
# Catch the exception
|
287 |
except Exception as ex: |
288 |
# Roll back any change if something goes wrong
|
289 |
conn.rollback() |
290 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
291 |
finally:
|
292 |
conn.close() |
293 |
if rows is not None and len(rows) > 0: |
294 |
return True |
295 |
else:
|
296 |
return False |
297 |
|
298 |
'''
|
299 |
@brief Insert new symbol into Symbol Table, Moved from SG_DbHelper
|
300 |
@author Jeongwoo
|
301 |
@date 2018.05.03
|
302 |
'''
|
303 |
def insertSymbol(self, symbol): |
304 |
isAdded = False
|
305 |
try:
|
306 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
307 |
conn = sqlite3.connect(dbPath) |
308 |
|
309 |
INSERT_SYMBOL_SQL = '''
|
310 |
INSERT INTO Symbol(symId, name, type, threshold, minMatchPoint, isDetectOrigin, rotationCount, ocrOption, isContainChild, originalPoint, connectionPoint, baseSymbol, additionalSymbol, isExceptDetect)
|
311 |
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
312 |
'''
|
313 |
|
314 |
cursor = conn.cursor() |
315 |
query = (symbol.getId(), symbol.getName(), symbol.getType(), symbol.getThreshold() |
316 |
, symbol.getMinMatchCount(), symbol.getIsDetectOnOrigin(), symbol.getRotationCount() |
317 |
, symbol.getOcrOption(), symbol.getIsContainChild() |
318 |
, symbol.getOriginalPoint(), symbol.getConnectionPoint() |
319 |
, symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getIsExceptDetect()) |
320 |
cursor.execute(INSERT_SYMBOL_SQL, query) |
321 |
conn.commit() |
322 |
isAdded = True
|
323 |
# Catch the exception
|
324 |
except Exception as ex: |
325 |
# Roll back any change if something goes wrong
|
326 |
conn.rollback() |
327 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
328 |
finally:
|
329 |
conn.close() |
330 |
return (isAdded, symbol.getType(), symbol.getName(), symbol.getPath())
|
331 |
|
332 |
'''
|
333 |
@brief Update symbol in Symbol Table, Moved from SG_DbHelper
|
334 |
@author Jeongwoo
|
335 |
@date 2018.05.03
|
336 |
'''
|
337 |
def updateSymbol(self, symbol): |
338 |
isUpdated = False
|
339 |
try:
|
340 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
341 |
conn = sqlite3.connect(dbPath) |
342 |
|
343 |
UPDATE_SYMBOL_SQL = '''
|
344 |
UPDATE Symbol
|
345 |
SET
|
346 |
symId = ?, name = ?, type = ?, threshold = ?, minMatchPoint = ?, isDetectOrigin = ?,
|
347 |
rotationCount = ?, ocrOption = ?, isContainChild = ?, originalPoint = ?, connectionPoint = ?,
|
348 |
baseSymbol = ?, additionalSymbol = ?, isExceptDetect = ?
|
349 |
WHERE uid = ?
|
350 |
'''
|
351 |
|
352 |
cursor = conn.cursor() |
353 |
query = (symbol.getId(), symbol.getName(), symbol.getType(), symbol.getThreshold() |
354 |
, symbol.getMinMatchCount(), symbol.getIsDetectOnOrigin(), symbol.getRotationCount() |
355 |
, symbol.getOcrOption(), symbol.getIsContainChild() |
356 |
, symbol.getOriginalPoint(), symbol.getConnectionPoint() |
357 |
, symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getIsExceptDetect(), symbol.getUid()) |
358 |
cursor.execute(UPDATE_SYMBOL_SQL, query) |
359 |
conn.commit() |
360 |
isUpdated = True
|
361 |
# Catch the exception
|
362 |
except Exception as ex: |
363 |
# Roll back any change if something goes wrong
|
364 |
conn.rollback() |
365 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
366 |
finally:
|
367 |
conn.close() |
368 |
return (isUpdated, symbol.getType(), symbol.getName(), symbol.getPath())
|
369 |
|
370 |
'''
|
371 |
@brief Get Detecting Target Symbol List (Field 'isExceptDetect' == False(0))
|
372 |
@author Jeongwoo
|
373 |
@date 18.04.24
|
374 |
@history humkyung 2018.06.28 select symbol order by threshold descending
|
375 |
'''
|
376 |
def getTargetSymbolList(self): |
377 |
targetSymbolList = [] |
378 |
|
379 |
try:
|
380 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
381 |
|
382 |
conn = sqlite3.connect(dbPath) |
383 |
cursor = conn.cursor() |
384 |
sql = 'SELECT * FROM Symbol WHERE isExceptDetect = 0 order by threshold desc'
|
385 |
try:
|
386 |
cursor.execute(sql) |
387 |
rows = cursor.fetchall() |
388 |
for row in rows: |
389 |
sym = symbol.SymbolBase(row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[0]) ## uid is last item |
390 |
targetSymbolList.append(sym) |
391 |
except Exception as ex: |
392 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
393 |
finally:
|
394 |
conn.close() |
395 |
|
396 |
return targetSymbolList
|
397 |
|
398 |
'''
|
399 |
@brief build application database
|
400 |
@author humkyung
|
401 |
@date 2018.04.20
|
402 |
'''
|
403 |
def buildAppDatabase(self): |
404 |
try:
|
405 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
406 |
appDatabaseFilePath = os.path.join(path, 'App.db')
|
407 |
|
408 |
# Creates or opens a file called mydb with a SQLite3 DB
|
409 |
conn = sqlite3.connect(appDatabaseFilePath) |
410 |
# Get a cursor object
|
411 |
cursor = conn.cursor() |
412 |
|
413 |
sqlFiles = ['App.Configuration.sql', 'App.Styles.sql'] |
414 |
for sqlFile in sqlFiles: |
415 |
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', sqlFile)
|
416 |
try:
|
417 |
file = QFile(filePath) |
418 |
file.open(QFile.ReadOnly)
|
419 |
sql = file.readAll()
|
420 |
sql = str(sql, encoding='utf8') |
421 |
cursor.executescript(sql) |
422 |
finally:
|
423 |
file.close()
|
424 |
conn.commit() |
425 |
# Catch the exception
|
426 |
except Exception as ex: |
427 |
# Roll back any change if something goes wrong
|
428 |
conn.rollback() |
429 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
430 |
finally:
|
431 |
# Close the db connection
|
432 |
conn.close() |
433 |
|
434 |
'''
|
435 |
@brief load app style
|
436 |
@author humkyung
|
437 |
@date 2018.04.20
|
438 |
'''
|
439 |
def loadAppStyle(self): |
440 |
style = 'Fusion'
|
441 |
|
442 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
443 |
if not os.path.exists(path): os.makedirs(path) |
444 |
|
445 |
self.buildAppDatabase()
|
446 |
try:
|
447 |
appDatabaseFilePath = os.path.join(path, 'App.db')
|
448 |
# Creates or opens a file called mydb with a SQLite3 DB
|
449 |
conn = sqlite3.connect(appDatabaseFilePath) |
450 |
# Get a cursor object
|
451 |
cursor = conn.cursor() |
452 |
|
453 |
sql = "select Value from Configuration where Section='App' and Key='Style'"
|
454 |
cursor.execute(sql) |
455 |
rows = cursor.fetchall() |
456 |
style = rows[0][0] if 1 == len(rows) else 'Fusion' |
457 |
# Catch the exception
|
458 |
except Exception as ex: |
459 |
# Roll back any change if something goes wrong
|
460 |
conn.rollback() |
461 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
462 |
finally:
|
463 |
# Close the db connection
|
464 |
conn.close() |
465 |
|
466 |
return style
|
467 |
|
468 |
'''
|
469 |
@brief load app styles and then return a list
|
470 |
@author humkyung
|
471 |
@date 2018.04.20
|
472 |
'''
|
473 |
def loadAppStyles(self): |
474 |
styles = [] |
475 |
|
476 |
try:
|
477 |
self.buildAppDatabase()
|
478 |
|
479 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
480 |
appDatabaseFilePath = os.path.join(path, 'App.db')
|
481 |
|
482 |
# Creates or opens a file called mydb with a SQLite3 DB
|
483 |
conn = sqlite3.connect(appDatabaseFilePath) |
484 |
# Get a cursor object
|
485 |
cursor = conn.cursor() |
486 |
|
487 |
sql = 'select UID,Value from Styles'
|
488 |
cursor.execute(sql) |
489 |
rows = cursor.fetchall() |
490 |
for row in rows: styles.append(row[1]) |
491 |
if 0 == len(rows): rows.append('fusion') |
492 |
# Catch the exception
|
493 |
except Exception as ex: |
494 |
# Roll back any change if something goes wrong
|
495 |
conn.rollback() |
496 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
497 |
finally:
|
498 |
# Close the db connection
|
499 |
conn.close() |
500 |
|
501 |
return styles
|
502 |
|
503 |
'''
|
504 |
@brief Set current Project
|
505 |
@history 2018.06.27 Jeongwoo If DB file is not, copy DB file from ProgramData
|
506 |
'''
|
507 |
def setCurrentProject(self, project): |
508 |
self.project = project
|
509 |
self.makeChildDir()
|
510 |
try:
|
511 |
# Creates or opens a file called mydb with a SQLite3 DB
|
512 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath() , "ITI_PID.db") |
513 |
|
514 |
if not os.path.isfile(dbPath): |
515 |
templatePath = self.getTemplateDbPath()
|
516 |
templateFile = QFile(templatePath) |
517 |
templateFile.copy(dbPath) |
518 |
# Catch the exception
|
519 |
except Exception as ex: |
520 |
# Roll back any change if something goes wrong
|
521 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
522 |
finally:
|
523 |
pass
|
524 |
|
525 |
'''
|
526 |
@brief Make Directory
|
527 |
@author Jeongwoo
|
528 |
@date 18.05.08
|
529 |
@history humkyung 2018.06.19 make 'Tile' directory
|
530 |
'''
|
531 |
def makeChildDir(self): |
532 |
project = AppDocData.instance().getCurrentProject() |
533 |
dbDir = project.getDbFilePath() |
534 |
if not os.path.exists(dbDir): |
535 |
os.makedirs(dbDir) |
536 |
imgDir = project.getImageFilePath() |
537 |
if not os.path.exists(imgDir): |
538 |
os.makedirs(imgDir) |
539 |
svgDir = project.getSvgFilePath() |
540 |
if not os.path.exists(svgDir): |
541 |
os.makedirs(svgDir) |
542 |
outputDir = project.getOutputPath() |
543 |
if not os.path.exists(outputDir): |
544 |
os.makedirs(outputDir) |
545 |
tempDir = project.getTempPath() |
546 |
if not os.path.exists(tempDir): |
547 |
os.makedirs(tempDir) |
548 |
|
549 |
path = os.path.join(tempDir, 'Tile')
|
550 |
if not os.path.exists(path): |
551 |
os.makedirs(path) |
552 |
|
553 |
'''
|
554 |
@brief Get current Project
|
555 |
'''
|
556 |
def getCurrentProject(self): |
557 |
return self.project |
558 |
|
559 |
'''
|
560 |
@brief return project database path
|
561 |
@history humkyung 2018.04.19 return Project.db in Program Data folder instead of PROJECT_DB_PATH variable
|
562 |
'''
|
563 |
def getPrjDatabasePath(self): |
564 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
565 |
if not os.path.exists(path): os.makedirs(path) |
566 |
|
567 |
prjDatabaseFilePath = os.path.join(path, 'Project.db')
|
568 |
try:
|
569 |
# Creates or opens a file called mydb with a SQLite3 DB
|
570 |
conn = sqlite3.connect(prjDatabaseFilePath) |
571 |
# Get a cursor object
|
572 |
cursor = conn.cursor() |
573 |
|
574 |
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Scripts', 'Project.Projects.sql') |
575 |
try:
|
576 |
file = QFile(filePath) |
577 |
file.open(QFile.ReadOnly)
|
578 |
sql = file.readAll()
|
579 |
sql = str(sql, encoding='utf8') |
580 |
cursor.executescript(sql) |
581 |
finally:
|
582 |
file.close()
|
583 |
conn.commit() |
584 |
# Catch the exception
|
585 |
except Exception as ex: |
586 |
# Roll back any change if something goes wrong
|
587 |
conn.rollback() |
588 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
589 |
finally:
|
590 |
# Close the db connection
|
591 |
conn.close() |
592 |
|
593 |
return prjDatabaseFilePath
|
594 |
|
595 |
'''
|
596 |
@brief return line properties
|
597 |
@author humkyung
|
598 |
@date 2018.04.09
|
599 |
'''
|
600 |
def getLineProperties(self): |
601 |
res = [] |
602 |
try:
|
603 |
# Creates or opens a file called mydb with a SQLite3 DB
|
604 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
605 |
db = sqlite3.connect(dbPath) |
606 |
# Get a cursor object
|
607 |
cursor = db.cursor() |
608 |
|
609 |
sql = "select Name from LineProperties order by Name"
|
610 |
cursor.execute(sql) |
611 |
rows = cursor.fetchall() |
612 |
for row in rows: |
613 |
res.append(row[0])
|
614 |
# Catch the exception
|
615 |
except Exception as ex: |
616 |
# Roll back any change if something goes wrong
|
617 |
db.rollback() |
618 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
619 |
finally:
|
620 |
# Close the db connection
|
621 |
db.close() |
622 |
|
623 |
return res
|
624 |
|
625 |
'''
|
626 |
@brief return line types
|
627 |
@author humkyung
|
628 |
@date 2018.06.27
|
629 |
'''
|
630 |
def getLineTypes(self): |
631 |
res = [] |
632 |
try:
|
633 |
# Creates or opens a file called mydb with a SQLite3 DB
|
634 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
635 |
db = sqlite3.connect(dbPath) |
636 |
# Get a cursor object
|
637 |
cursor = db.cursor() |
638 |
|
639 |
sql = "select Name from LineTypes order by Name"
|
640 |
cursor.execute(sql) |
641 |
rows = cursor.fetchall() |
642 |
for row in rows: |
643 |
res.append(row[0])
|
644 |
# Catch the exception
|
645 |
except Exception as ex: |
646 |
# Roll back any change if something goes wrong
|
647 |
db.rollback() |
648 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
649 |
finally:
|
650 |
# Close the db connection
|
651 |
db.close() |
652 |
|
653 |
return res
|
654 |
|
655 |
'''
|
656 |
@brief Insert New Project Info
|
657 |
@author Jeongwoo
|
658 |
@date 2018.04.06
|
659 |
@history humkyung 2018.04.19 use getPrjDatabasePath function instead of PROJECT_DB_PATH variable
|
660 |
'''
|
661 |
def insertProjectInfo(self, dir): |
662 |
try:
|
663 |
prjDatabaseFilePath = self.getPrjDatabasePath()
|
664 |
conn = sqlite3.connect(prjDatabaseFilePath) |
665 |
folderName = dir.split('/')[-1] |
666 |
if folderName:
|
667 |
nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
|
668 |
sql = "INSERT INTO Projects(Name, Path, CreatedDate, UpdatedDate) VALUES('" + folderName + "', '" + dir + "', '" + nowDate + "', '" + nowDate + "')" |
669 |
cur = conn.cursor() |
670 |
cur.execute(sql) |
671 |
conn.commit() |
672 |
else:
|
673 |
print("Empty folder name")
|
674 |
except Exception as ex: |
675 |
# Roll back any change if something goes wrong
|
676 |
conn.rollback() |
677 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
678 |
finally:
|
679 |
conn.close() |
680 |
|
681 |
'''
|
682 |
@brief Update Project UpdatedDate Field
|
683 |
@author Jeongwoo
|
684 |
@date 2018.04.06
|
685 |
@history humkyung 2018.04.19 use getPrjDatabasePath function instead of PROJECT_DB_PATH variable
|
686 |
'''
|
687 |
def updateProjectUpdatedDate(self, id): |
688 |
try:
|
689 |
prjDatabaseFilePath = self.getPrjDatabasePath()
|
690 |
conn = sqlite3.connect(prjDatabaseFilePath) |
691 |
nowDate = datetime.datetime.now().strftime('%Y.%m.%d %H:%M')
|
692 |
sql = '''
|
693 |
UPDATE Projects
|
694 |
SET UpdatedDate = ?
|
695 |
WHERE Id = ?
|
696 |
'''
|
697 |
cur = conn.cursor() |
698 |
cur.execute(sql, (nowDate, id))
|
699 |
conn.commit() |
700 |
except Exception as ex: |
701 |
# Roll back any change if something goes wrong
|
702 |
conn.rollback() |
703 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
704 |
finally:
|
705 |
conn.close() |
706 |
|
707 |
'''
|
708 |
@brief get project list from database
|
709 |
@history humkyung 2018.04.18 add only project which's project exists
|
710 |
'''
|
711 |
def getProjectList(self): |
712 |
from Project import Project |
713 |
|
714 |
projectList = [] |
715 |
|
716 |
try:
|
717 |
conn = sqlite3.connect(self.getPrjDatabasePath())
|
718 |
cursor = conn.cursor() |
719 |
sql = 'SELECT id,name,path,createddate,updateddate FROM Projects ORDER BY UpdatedDate DESC'
|
720 |
try:
|
721 |
cursor.execute(sql) |
722 |
rows = cursor.fetchall() |
723 |
for row in rows: |
724 |
if os.path.isdir(row[2]): # check if folder exists |
725 |
projectList.append(Project(row[0], row[1], row[2], row[3], row[4])) |
726 |
except Exception as ex: |
727 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
728 |
finally:
|
729 |
conn.close() |
730 |
|
731 |
return projectList
|
732 |
|
733 |
'''
|
734 |
@brief get sliding window size
|
735 |
@author humkyung
|
736 |
'''
|
737 |
def getSlidingWindowSize(self): |
738 |
res = [10,10] |
739 |
try:
|
740 |
configs = self.getConfigs('Sliding Window') |
741 |
for config in configs: |
742 |
if config.key == 'Width': |
743 |
res[0] = int(config.value) |
744 |
elif config.key == 'Height': |
745 |
res[1] = int(config.value) |
746 |
# Catch the exception
|
747 |
except Exception as ex: |
748 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
749 |
|
750 |
return res
|
751 |
|
752 |
'''
|
753 |
@brief get line no configuration
|
754 |
@author humkyung
|
755 |
@date 2018.04.16
|
756 |
'''
|
757 |
def getLineNoConfiguration(self): |
758 |
res = None
|
759 |
try:
|
760 |
# Creates or opens a file called mydb with a SQLite3 DB
|
761 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
762 |
conn = sqlite3.connect(dbPath) |
763 |
# Get a cursor object
|
764 |
cursor = conn.cursor() |
765 |
|
766 |
delimiter = None
|
767 |
sql = "select * from configuration where section='Line No' and key='Delimiter"
|
768 |
cursor.execute(sql) |
769 |
rows = cursor.fetchall() |
770 |
if len(rows) == 1: |
771 |
delimiter = rows[0][2] |
772 |
|
773 |
if delimiter is not None: |
774 |
sql = "select * from configuration where section='Line No' and key='Configuration'"
|
775 |
cursor.execute(sql) |
776 |
rows = cursor.fetchall() |
777 |
if len(rows) == 1: |
778 |
res = rows[0][2].split(delimiter) |
779 |
# Catch the exception
|
780 |
except Exception as ex: |
781 |
# Roll back any change if something goes wrong
|
782 |
conn.rollback() |
783 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
784 |
finally:
|
785 |
# Close the db connection
|
786 |
conn.close() |
787 |
|
788 |
return res
|
789 |
|
790 |
'''
|
791 |
@brief get area list
|
792 |
@author humkyung
|
793 |
'''
|
794 |
def getAreaList(self): |
795 |
if len(self._areas) == 0: |
796 |
try:
|
797 |
# Creates or opens a file called mydb with a SQLite3 DB
|
798 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
799 |
conn = sqlite3.connect(dbPath) |
800 |
# Get a cursor object
|
801 |
cursor = conn.cursor() |
802 |
|
803 |
sql = "select * from configuration where section='Area'"
|
804 |
cursor.execute(sql) |
805 |
rows = cursor.fetchall() |
806 |
for row in rows: |
807 |
area = Area() |
808 |
area.name = row[1]
|
809 |
area.parse(row[2])
|
810 |
self._areas.append(area)
|
811 |
# Catch the exception
|
812 |
except Exception as ex: |
813 |
# Roll back any change if something goes wrong
|
814 |
conn.rollback() |
815 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
816 |
finally:
|
817 |
# Close the db connection
|
818 |
conn.close() |
819 |
|
820 |
return self._areas |
821 |
|
822 |
'''
|
823 |
@brief get area of given name
|
824 |
@author humkyung
|
825 |
@date 2018.04.07
|
826 |
'''
|
827 |
def getArea(self, name): |
828 |
areas = self.getAreaList()
|
829 |
matches = [area for area in areas if area.name==name] |
830 |
if 1 == len(matches): return matches[0] |
831 |
|
832 |
return None |
833 |
|
834 |
'''
|
835 |
@brief get configurations
|
836 |
@author humkyung
|
837 |
@date 2018.04.16
|
838 |
'''
|
839 |
def getConfigs(self, section, key=None): |
840 |
res = [] |
841 |
|
842 |
try:
|
843 |
# Creates or opens a file called mydb with a SQLite3 DB
|
844 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
845 |
conn = sqlite3.connect(dbPath) |
846 |
# Get a cursor object
|
847 |
cursor = conn.cursor() |
848 |
|
849 |
if key is not None: |
850 |
sql = "select * from configuration where section='{}' and key='{}'".format(section, key)
|
851 |
else:
|
852 |
sql = "select * from configuration where section='{}'".format(section)
|
853 |
|
854 |
cursor.execute(sql) |
855 |
rows = cursor.fetchall() |
856 |
for row in rows: |
857 |
res.append(Config(row[0], row[1], row[2])) |
858 |
# Catch the exception
|
859 |
except Exception as ex: |
860 |
# Roll back any change if something goes wrong
|
861 |
conn.rollback() |
862 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
863 |
finally:
|
864 |
# Close the db connection
|
865 |
conn.close() |
866 |
|
867 |
return res
|
868 |
|
869 |
'''
|
870 |
@brief save configurations
|
871 |
@author humkyung
|
872 |
@date 2018.04.16
|
873 |
'''
|
874 |
def saveConfigs(self, configs): |
875 |
try:
|
876 |
# Creates or opens a file called mydb with a SQLite3 DB
|
877 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
878 |
conn = sqlite3.connect(dbPath) |
879 |
# Get a cursor object
|
880 |
cursor = conn.cursor() |
881 |
|
882 |
for config in configs: |
883 |
sql = "insert or replace into configuration values('{}','{}','{}')".format(config.section, config.key, config.value)
|
884 |
cursor.execute(sql) |
885 |
conn.commit() |
886 |
# Catch the exception
|
887 |
except Exception as ex: |
888 |
# Roll back any change if something goes wrong
|
889 |
conn.rollback() |
890 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
891 |
finally:
|
892 |
# Close the db connection
|
893 |
conn.close() |
894 |
|
895 |
'''
|
896 |
@brief delete configurations
|
897 |
@author humkyung
|
898 |
@date 2018.06.29
|
899 |
'''
|
900 |
def deleteConfigs(self, section, key=None): |
901 |
try:
|
902 |
# Creates or opens a file called mydb with a SQLite3 DB
|
903 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
904 |
conn = sqlite3.connect(dbPath) |
905 |
# Get a cursor object
|
906 |
cursor = conn.cursor() |
907 |
|
908 |
if key is not None: |
909 |
sql = "delete from configuration where section='{}' and key='{}'".format(section, key)
|
910 |
else:
|
911 |
sql = "delete from configuration where section='{}'".format(section)
|
912 |
cursor.execute(sql) |
913 |
|
914 |
conn.commit() |
915 |
# Catch the exception
|
916 |
except Exception as ex: |
917 |
# Roll back any change if something goes wrong
|
918 |
conn.rollback() |
919 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
920 |
finally:
|
921 |
# Close the db connection
|
922 |
conn.close() |
923 |
|
924 |
'''
|
925 |
@brief set area list
|
926 |
@history humkyung 2018.05.18 round area coordinate and dimension before saving
|
927 |
'''
|
928 |
def setAreaList(self, areas): |
929 |
for area in areas: |
930 |
matches = [x for x in self._areas if x.name==area.name] |
931 |
if 1 == len(matches): |
932 |
matches[0].x = area.x
|
933 |
matches[0].y = area.y
|
934 |
matches[0].width = area.width
|
935 |
matches[0].height = area.height
|
936 |
elif 0 == len(matches): |
937 |
self._areas.append(area)
|
938 |
|
939 |
try:
|
940 |
# Creates or opens a file called mydb with a SQLite3 DB
|
941 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), "ITI_PID.db") |
942 |
conn = sqlite3.connect(dbPath) |
943 |
# Get a cursor object
|
944 |
cursor = conn.cursor() |
945 |
|
946 |
for area in self._areas: |
947 |
sql = "insert or replace into configuration values('Area','{}','({},{}),({},{})')".format(area.name, round(area.x), round(area.y), round(area.width), round(area.height)) |
948 |
cursor.execute(sql) |
949 |
|
950 |
conn.commit() |
951 |
# Catch the exception
|
952 |
except Exception as ex: |
953 |
# Roll back any change if something goes wrong
|
954 |
conn.rollback() |
955 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
956 |
finally:
|
957 |
# Close the db connection
|
958 |
conn.close() |
959 |
|
960 |
'''
|
961 |
@brief get symbol name list
|
962 |
'''
|
963 |
def getSymbolNameList(self): |
964 |
symbolNametList = [] |
965 |
|
966 |
try:
|
967 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
968 |
|
969 |
conn = sqlite3.connect(dbPath) |
970 |
cursor = conn.cursor() |
971 |
sql = 'SELECT * FROM SymbolName'
|
972 |
try:
|
973 |
cursor.execute(sql) |
974 |
rows = cursor.fetchall() |
975 |
for row in rows: |
976 |
symbolNametList.append(row[2]) # Name String |
977 |
except Exception as ex: |
978 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
979 |
finally:
|
980 |
conn.close() |
981 |
|
982 |
return symbolNametList
|
983 |
|
984 |
'''
|
985 |
@brief get symbol name list by symbol Type
|
986 |
@author Jeongwoo
|
987 |
@date 18.04.06
|
988 |
@history .
|
989 |
'''
|
990 |
def getSymbolNameListByType(self, type): |
991 |
symbolNametList = [] |
992 |
|
993 |
try:
|
994 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
995 |
|
996 |
conn = sqlite3.connect(dbPath) |
997 |
cursor = conn.cursor() |
998 |
sql = ''
|
999 |
if type is not None: |
1000 |
sql = 'SELECT * FROM SymbolName WHERE type = "' + type + '"' |
1001 |
try:
|
1002 |
cursor.execute(sql) |
1003 |
rows = cursor.fetchall() |
1004 |
for row in rows: |
1005 |
symbolNametList.append(row[2]) # Name String |
1006 |
except Exception as ex: |
1007 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1008 |
finally:
|
1009 |
conn.close() |
1010 |
|
1011 |
return symbolNametList
|
1012 |
|
1013 |
'''
|
1014 |
@brief delete added symbol data
|
1015 |
'''
|
1016 |
def deleteSymbol(self, fileName): |
1017 |
ret = False
|
1018 |
try:
|
1019 |
dbPath = self.getCurrentProject().getPath() + "/db/ITI_PID.db" |
1020 |
conn = sqlite3.connect(dbPath) |
1021 |
cursor = conn.cursor() |
1022 |
sql = "DELETE FROM Symbol WHERE name = ?"
|
1023 |
try:
|
1024 |
cursor.execute(sql, (fileName,)) |
1025 |
conn.commit() |
1026 |
ret = True
|
1027 |
except Exception as ex: |
1028 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1029 |
ret = False
|
1030 |
finally:
|
1031 |
conn.close() |
1032 |
return (ret, fileName)
|
1033 |
|
1034 |
'''
|
1035 |
@brief get symbol name
|
1036 |
@history 18.04.24 Jeongwoo Add isExceptDetect Field
|
1037 |
'''
|
1038 |
def getSymbolByQuery(self, fieldName, param): |
1039 |
ret = None
|
1040 |
|
1041 |
try:
|
1042 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
1043 |
conn = sqlite3.connect(dbPath) |
1044 |
cursor = conn.cursor() |
1045 |
sql = 'SELECT * FROM Symbol WHERE ' + fieldName + ' = "' + param + '"' |
1046 |
try:
|
1047 |
cursor.execute(sql) |
1048 |
rows = cursor.fetchall() |
1049 |
if rows is not None and len(rows) > 0: |
1050 |
symbolTuple = rows[0]
|
1051 |
ret = symbol.SymbolBase(symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4] |
1052 |
, symbolTuple[5], symbolTuple[6], symbolTuple[7], symbolTuple[8], symbolTuple[9] |
1053 |
, symbolTuple[10], symbolTuple[11], symbolTuple[12], symbolTuple[13], symbolTuple[14], symbolTuple[0]) ## uid is last item |
1054 |
#ret = symbol.SymbolBase(symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4]
|
1055 |
# , symbolTuple[5], symbolTuple[6], symbolTuple[7], symbolTuple[8], symbolTuple[9]
|
1056 |
# , symbolTuple[10], symbolTuple[11], symbolTuple[12], symbolTuple[13], symbolTuple[14], symbolTuple[0]) ## uid is last item
|
1057 |
except Exception as ex: |
1058 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1059 |
finally:
|
1060 |
conn.close() |
1061 |
|
1062 |
return ret
|
1063 |
|
1064 |
'''
|
1065 |
@brief get symbol name list
|
1066 |
@history 18.04.24 Jeongwoo Add isExceptDetect Field
|
1067 |
'''
|
1068 |
def getSymbolListByQuery(self, fieldName=None, param=None): |
1069 |
ret = [] |
1070 |
|
1071 |
try:
|
1072 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
1073 |
conn = sqlite3.connect(dbPath) |
1074 |
cursor = conn.cursor() |
1075 |
if fieldName is not None and param is not None: |
1076 |
sql = 'SELECT * FROM Symbol WHERE ' + fieldName + ' = "' + param + '"' |
1077 |
else:
|
1078 |
sql = 'SELECT * FROM Symbol'
|
1079 |
try:
|
1080 |
cursor.execute(sql) |
1081 |
rows = cursor.fetchall() |
1082 |
if rows is not None and len(rows) > 0: |
1083 |
for symbolTuple in rows: |
1084 |
sym = symbol.SymbolBase(symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4] |
1085 |
, symbolTuple[5], symbolTuple[6], symbolTuple[7], symbolTuple[8], symbolTuple[9] |
1086 |
, symbolTuple[10], symbolTuple[11], symbolTuple[12], symbolTuple[13], symbolTuple[14], symbolTuple[0]) ## uid is last item |
1087 |
ret.append(sym) |
1088 |
except Exception as ex: |
1089 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1090 |
finally:
|
1091 |
conn.close() |
1092 |
|
1093 |
return ret
|
1094 |
|
1095 |
'''
|
1096 |
@brief get nominal pipe size
|
1097 |
@author humkyung
|
1098 |
@date 2018.04.20
|
1099 |
@history humkyung 2018.04.24 read MetricStr column and set size unit
|
1100 |
'''
|
1101 |
def getNomialPipeSizeData(self): |
1102 |
res = [] |
1103 |
try:
|
1104 |
configs = self.getConfigs('Line No', 'Size Unit') |
1105 |
sizeUnit = configs[0].value if 1 == len(configs) else 'Metric' |
1106 |
|
1107 |
# Creates or opens a file called mydb with a SQLite3 DB
|
1108 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
1109 |
conn = sqlite3.connect(dbPath) |
1110 |
# Get a cursor object
|
1111 |
cursor = conn.cursor() |
1112 |
|
1113 |
sql = "select Code,Metric,Inch,InchStr,MetricStr from 'NOMINAL PIPE SIZE'"
|
1114 |
cursor.execute(sql) |
1115 |
rows = cursor.fetchall() |
1116 |
for row in rows: |
1117 |
pipeSize = NominalPipeSize(row[0], float(row[1]) if row[1] is not None else -1, float(row[2]) if row[2] is not None else -1, row[3], row[4]) |
1118 |
pipeSize.sizeUnit = sizeUnit |
1119 |
res.append(pipeSize) |
1120 |
# Catch the exception
|
1121 |
except Exception as ex: |
1122 |
# Roll back any change if something goes wrong
|
1123 |
conn.rollback() |
1124 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1125 |
finally:
|
1126 |
# Close the db connection
|
1127 |
conn.close() |
1128 |
|
1129 |
return res
|
1130 |
|
1131 |
'''
|
1132 |
@brief get Fluid Code
|
1133 |
@author kyouho
|
1134 |
@date 2018.07.03
|
1135 |
'''
|
1136 |
def getFluidCodeData(self): |
1137 |
from FluidCodeData import FluidCodeData |
1138 |
result = [] |
1139 |
|
1140 |
try:
|
1141 |
# Creates or opens a file called mydb with a SQLite3 DB
|
1142 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
1143 |
conn = sqlite3.connect(dbPath) |
1144 |
# Get a cursor object
|
1145 |
cursor = conn.cursor() |
1146 |
|
1147 |
sql = 'select uid, code, description from FluidCode'
|
1148 |
cursor.execute(sql) |
1149 |
rows = cursor.fetchall() |
1150 |
for row in rows: |
1151 |
data = FluidCodeData(row[0], row[1], row[2]) |
1152 |
result.append(data) |
1153 |
# Catch the exception
|
1154 |
except Exception as ex: |
1155 |
# Roll back any change if something goes wrong
|
1156 |
conn.rollback() |
1157 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1158 |
finally:
|
1159 |
# Close the db connection
|
1160 |
conn.close() |
1161 |
|
1162 |
return result
|
1163 |
|
1164 |
'''
|
1165 |
@brief set Fluid Code
|
1166 |
@author kyouho
|
1167 |
@date 2018.07.03
|
1168 |
'''
|
1169 |
def setFluidCodeData(self, addDataList, removeDataList): |
1170 |
try:
|
1171 |
# Creates or opens a file called mydb with a SQLite3 DB
|
1172 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
1173 |
conn = sqlite3.connect(dbPath) |
1174 |
# Get a cursor object
|
1175 |
cursor = conn.cursor() |
1176 |
|
1177 |
for data in addDataList: |
1178 |
uid = data.uid |
1179 |
if not uid: |
1180 |
sql = "insert or replace into FluidCode(UID, CODE, DESCRIPTION) values(lower(hex(randomblob(16))), '{}', '{}')".format(data.code, data.description)
|
1181 |
else:
|
1182 |
sql = "update FluidCode SET CODE='{}', DESCRIPTION='{}' WHERE UID = '{}'".format(data.code, data.description, data.uid)
|
1183 |
cursor.execute(sql) |
1184 |
|
1185 |
for data in removeDataList: |
1186 |
uid = data.uid |
1187 |
if uid:
|
1188 |
sql = "delete from FluidCode where UID = '{}'".format(uid)
|
1189 |
cursor.execute(sql) |
1190 |
|
1191 |
conn.commit() |
1192 |
|
1193 |
# Catch the exception
|
1194 |
except Exception as ex: |
1195 |
# Roll back any change if something goes wrong
|
1196 |
conn.rollback() |
1197 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1198 |
finally:
|
1199 |
# Close the db connection
|
1200 |
conn.close() |
1201 |
|
1202 |
'''
|
1203 |
@brief get equipment data list
|
1204 |
@author humkyung
|
1205 |
@date 2018.05.03
|
1206 |
'''
|
1207 |
def getEquipmentDataList(self): |
1208 |
from EquipmentData import EquipmentData |
1209 |
|
1210 |
if not self.equipmentDataList: |
1211 |
try:
|
1212 |
# Creates or opens a file called mydb with a SQLite3 DB
|
1213 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
1214 |
conn = sqlite3.connect(dbPath) |
1215 |
# Get a cursor object
|
1216 |
cursor = conn.cursor() |
1217 |
|
1218 |
sql = 'select TAG_NO from EQUIPMENT_DATA_LIST'
|
1219 |
cursor.execute(sql) |
1220 |
rows = cursor.fetchall() |
1221 |
for row in rows: |
1222 |
data = EquipmentData(row[0])
|
1223 |
self.equipmentDataList.append(data)
|
1224 |
# Catch the exception
|
1225 |
except Exception as ex: |
1226 |
# Roll back any change if something goes wrong
|
1227 |
conn.rollback() |
1228 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1229 |
finally:
|
1230 |
# Close the db connection
|
1231 |
conn.close() |
1232 |
|
1233 |
return self.equipmentDataList |
1234 |
|
1235 |
'''
|
1236 |
@brief set equipment data list
|
1237 |
@author humkyung
|
1238 |
@date 2018.05.03
|
1239 |
'''
|
1240 |
def setEquipmentDataList(self, dataList): |
1241 |
try:
|
1242 |
# Creates or opens a file called mydb with a SQLite3 DB
|
1243 |
dbPath = os.path.join(self.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
1244 |
conn = sqlite3.connect(dbPath) |
1245 |
# Get a cursor object
|
1246 |
cursor = conn.cursor() |
1247 |
|
1248 |
for data in dataList: |
1249 |
sql = "insert or replace into EQUIPMENT_DATA_LIST(UID,TAG_NO) values(lower(hex(randomblob(16))),'{}')".format(data.tagNo)
|
1250 |
cursor.execute(sql) |
1251 |
conn.commit() |
1252 |
|
1253 |
self.equipmentDataList = dataList
|
1254 |
# Catch the exception
|
1255 |
except Exception as ex: |
1256 |
# Roll back any change if something goes wrong
|
1257 |
conn.rollback() |
1258 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1259 |
finally:
|
1260 |
# Close the db connection
|
1261 |
conn.close() |
1262 |
|
1263 |
'''
|
1264 |
@brief get IsOriginDetect ComboBox Items
|
1265 |
'''
|
1266 |
def getIsOriginDetectComboBoxItems(self): |
1267 |
return [("원본 도면", 0), ("텍스트 제거 도면", 1)] |
1268 |
|
1269 |
'''
|
1270 |
@brief get IsOriginDetect ComboBox Items
|
1271 |
'''
|
1272 |
def getOcrOptionComboBoxItems(self): |
1273 |
return [("OCR 미적용", 0), ("일반 심볼", 1), ("Instrument 계통", 2)] |
1274 |
|
1275 |
'''
|
1276 |
@brief Return Symbol Type Items
|
1277 |
@author Jeongwoo
|
1278 |
@date 18.04.20
|
1279 |
@history 18.05.08 Jeongwoo type index changed
|
1280 |
'''
|
1281 |
def getSymbolTypeList(self): |
1282 |
symbolTypeList = [] |
1283 |
|
1284 |
try:
|
1285 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
1286 |
|
1287 |
conn = sqlite3.connect(dbPath) |
1288 |
cursor = conn.cursor() |
1289 |
sql = 'SELECT * FROM SymbolType ORDER BY type ASC'
|
1290 |
try:
|
1291 |
cursor.execute(sql) |
1292 |
rows = cursor.fetchall() |
1293 |
for row in rows: |
1294 |
symbolTypeList.append(row[2]) # Type String |
1295 |
except Exception as ex: |
1296 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1297 |
finally:
|
1298 |
conn.close() |
1299 |
|
1300 |
return symbolTypeList
|
1301 |
|
1302 |
'''
|
1303 |
@brief Get Symbol Category by Symbol Type
|
1304 |
@author Jeongwoo
|
1305 |
@date 2018.05.09
|
1306 |
'''
|
1307 |
def getSymbolCategoryByType(self, type): |
1308 |
category = None
|
1309 |
try:
|
1310 |
dbPath = self.getCurrentProject().getDbFilePath() + "/ITI_PID.db" |
1311 |
conn = sqlite3.connect(dbPath) |
1312 |
cursor = conn.cursor() |
1313 |
sql = 'SELECT category FROM SymbolType WHERE type = "' + type + '"' |
1314 |
cursor.execute(sql) |
1315 |
rows = cursor.fetchall() |
1316 |
if rows is not None and len(rows) > 0: |
1317 |
category = rows[0][0] |
1318 |
except Exception as ex: |
1319 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
1320 |
finally:
|
1321 |
conn.close() |
1322 |
|
1323 |
return category
|
1324 |
|
1325 |
'''
|
1326 |
@brief Check Symbol Type is included in 'Equipment' Category
|
1327 |
@author Jeongwoo
|
1328 |
@date 2018.05.09
|
1329 |
'''
|
1330 |
def isEquipmentType(self, type): |
1331 |
category = self.getSymbolCategoryByType(type) |
1332 |
return (category is not None and category == 'Equipment') |
1333 |
|
1334 |
'''
|
1335 |
@brief Return Symbol Type Items with "None"
|
1336 |
@author Jeongwoo
|
1337 |
@date 18.04.06
|
1338 |
@history Seperate SymbolTypeList and "None"
|
1339 |
'''
|
1340 |
def getSymbolTypeComboBoxItems(self): |
1341 |
symbolTypeList = self.getSymbolTypeList()
|
1342 |
symbolTypeList.insert(0, "None") |
1343 |
|
1344 |
return symbolTypeList
|
1345 |
|
1346 |
'''
|
1347 |
@brief get Base Symbol ComboBox Items
|
1348 |
'''
|
1349 |
def getBaseSymbolComboBoxItems(self, type = None): |
1350 |
bsymbolNameList = self.getSymbolNameListByType(type) |
1351 |
bsymbolNameList.sort() |
1352 |
bsymbolNameList.insert(0, "None") |
1353 |
return bsymbolNameList
|
1354 |
|
1355 |
'''
|
1356 |
@brief get Additional Symbol ComboBox Items
|
1357 |
'''
|
1358 |
def getAdditionalSymbolComboBoxItems(self): |
1359 |
asymbolNameList = self.getSymbolNameList()
|
1360 |
asymbolNameList.sort() |
1361 |
asymbolNameList.insert(0, "None") |
1362 |
return asymbolNameList
|
1363 |
|
1364 |
'''
|
1365 |
@brief get Additional Symbol's default direction ComboBox Items
|
1366 |
'''
|
1367 |
def getDefaultSymbolDirectionComboBoxItems(self): |
1368 |
return [("UP", 0), ("DOWN", 2), ("LEFT", 3), ("RIGHT", 1)] |
1369 |
|
1370 |
pass
|