개정판 d9cbc4d3
SymbolBase 내 getSvgFileFullPath, getImageFileFullPath 메소드 추가 및 관련 부분 적용
DTI_PID/DTI_PID/Commands/CreateSymbolCommand.py | ||
---|---|---|
29 | 29 |
@brief crop image by rectangle selected by user |
30 | 30 |
@history 2018.05.02 Jeongwoo Init self.offsetX and self.offsetY |
31 | 31 |
Add QtImageViewer.startPointChanged.emit |
32 |
2018.05.03 Jeongwoo Make Svg/Image File Path by SymbolBase.getSvgFileFullePath() and SymbolBase.getImageFileFullPath() |
|
32 | 33 |
''' |
33 | 34 |
def execute(self, param): |
34 | 35 |
event = param[1] |
... | ... | |
48 | 49 |
(isAccepted, isImmediateInsert, offsetX, offsetY, newSym) = symbolEditorDialog.showDialog() |
49 | 50 |
if isAccepted: |
50 | 51 |
if isImmediateInsert: |
51 |
svgPath = AppDocData.instance().getCurrentProject().getSvgFilePath() + "/" + newSym.getType() + "/" + newSym.getName() + ".svg"
|
|
52 |
img = cv2.imread(AppDocData.instance().getCurrentProject().getImageFilePath() + "/" + newSym.getType() + "/" + newSym.getName() + ".png", 1)
|
|
52 |
svgPath = newSym.getSvgFileFullPath()
|
|
53 |
img = cv2.imread(newSym.getImageFileFullPath(), 1)
|
|
53 | 54 |
w, h = (0, 0) |
54 | 55 |
if len(img.shape[::-1]) == 2: |
55 | 56 |
w, h = img.shape[::-1] |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
323 | 323 |
@history 2018.05.02 Jeongwoo Change return value of QSymbolEditorDialog (Single variable → Tuple) |
324 | 324 |
Add SymbolSvgItem |
325 | 325 |
2018.05.03 Jeongwoo Change method to draw Svg Item on Scene (svg.addSvgItemToScene) |
326 |
Change method to make svg and image path |
|
326 | 327 |
''' |
327 | 328 |
def createSymbol(self): |
328 | 329 |
image = self.graphicsView.image() |
... | ... | |
332 | 333 |
self.dirTreeWidget.initDirTreeWidget() |
333 | 334 |
if isAccepted: |
334 | 335 |
if isImmediateInsert: |
335 |
svgPath = AppDocData.instance().getCurrentProject().getSvgFilePath() + "/" + newSym.getType() + "/" + newSym.getName() + ".svg"
|
|
336 |
img = cv2.imread(AppDocData.instance().getCurrentProject().getImageFilePath() + "/" + newSym.getType() + "/" + newSym.getName() + ".png", 1)
|
|
336 |
svgPath = newSym.getSvgFileFullPath()
|
|
337 |
img = cv2.imread(newSym.getImageFileFullPath(), 1)
|
|
337 | 338 |
w, h = (0, 0) |
338 | 339 |
if len(img.shape[::-1]) == 2: |
339 | 340 |
w, h = img.shape[::-1] |
DTI_PID/DTI_PID/QDirTreeWidget.py | ||
---|---|---|
81 | 81 |
result = msg.exec_() |
82 | 82 |
self.handleDeleteSymbolAction(result, itemType, itemName) |
83 | 83 |
|
84 |
''' |
|
85 |
@history 2018.05.03 Jeongwoo Modify file path with ".png" and ".svg" |
|
86 |
Use project object when making svgPath |
|
87 |
''' |
|
84 | 88 |
def handleDeleteSymbolAction(self, result, itemType, itemName): |
85 | 89 |
print("handle") |
86 | 90 |
if result == QMessageBox.Ok: |
87 | 91 |
project = AppDocData.instance().getCurrentProject() |
88 |
imagePath = project.getImageFilePath() + "/" + itemType + "/" + itemName # itemName includes ".png"
|
|
92 |
imagePath = project.getImageFilePath() + "/" + itemType + "/" + itemName + ".png" # itemName DOESN'T includes ".png"
|
|
89 | 93 |
if os.path.exists(imagePath): |
90 | 94 |
os.remove(imagePath) |
91 | 95 |
|
92 |
svgPath = AppDocData.instance().getSvgFilePath() + "/" + itemType + "/" + itemName.replace(".png", ".svg")
|
|
96 |
svgPath = project.getSvgFilePath() + "/" + itemType + "/" + itemName + ".svg"
|
|
93 | 97 |
if os.path.exists(svgPath): |
94 | 98 |
os.remove(svgPath) |
95 | 99 |
|
96 |
AppDocData.instance().deleteSymbol(itemName.replace(".png", ""))
|
|
100 |
AppDocData.instance().deleteSymbol(itemName) |
|
97 | 101 |
self.initDirTreeWidget() |
98 | 102 |
else: |
99 | 103 |
pass |
... | ... | |
116 | 120 |
@brief Load Symbol Info and add TreeItem with DB |
117 | 121 |
@author Jeongwoo |
118 | 122 |
@date 18.04.20 |
123 |
@history 2018.05.03 Jeongwoo Get Svg File Path by SymbolBase.getSvgFileFullPath() |
|
119 | 124 |
''' |
120 | 125 |
def loadSymbolInfo(self): |
121 |
'''ss''' |
|
122 |
SVG_PATH_ROOT = AppDocData.instance().getCurrentProject().getSvgFilePath() |
|
123 | 126 |
symbolTypeList = AppDocData.instance().getSymbolTypeList() |
124 | 127 |
for symbolType in symbolTypeList: |
125 | 128 |
parent = QTreeWidgetItem(self, [symbolType]) |
... | ... | |
128 | 131 |
for symbol in symbolList: |
129 | 132 |
symbolItem = QTreeWidgetItem(parent, [symbol.getName()]) |
130 | 133 |
symbolItem.setData(0, self.TREE_DATA_ROLE, symbol) ## ADD DATA |
131 |
svgPath = os.path.join(SVG_PATH_ROOT, symbolType, symbol.getName() + '.svg')
|
|
134 |
svgPath = symbol.getSvgFileFullPath()
|
|
132 | 135 |
icon = QIcon(svgPath) |
133 | 136 |
symbolItem.setIcon(0, icon) |
134 | 137 |
symbolItem.svgFilePath = svgPath # save svg file path |
DTI_PID/DTI_PID/QSymbolEditorDialog.py | ||
---|---|---|
24 | 24 |
|
25 | 25 |
''' |
26 | 26 |
@history 2018.05.02 Jeongwoo Add variables (self.offsetX, self.offsetY, self.newSym) |
27 |
2018.05.03 Jeongwoo Remove parameter in SG_DbHelper() |
|
27 | 28 |
''' |
28 | 29 |
def __init__(self, parent, image, project, selectedSymbol = None): |
29 | 30 |
QDialog.__init__(self, parent) |
... | ... | |
40 | 41 |
self.offsetX = 0 |
41 | 42 |
self.offsetY = 0 |
42 | 43 |
self.newSym = None |
43 |
self.dbHelper = SG_DbHelper.SG_DbHelper(self.project.getPath())
|
|
44 |
self.dbHelper = SG_DbHelper.SG_DbHelper() |
|
44 | 45 |
|
45 | 46 |
''' |
46 | 47 |
@brief Set up QtImageViewer and QImage |
... | ... | |
311 | 312 |
''' |
312 | 313 |
@brief Called when Save Button Clicked |
313 | 314 |
Validation Check → Make Symbol Data → Insert Symbol Data into DB → Save png and svg files |
315 |
@history 2018.05.03 Jeongwoo Change parameters on method 'deleteImageAndSvg' |
|
314 | 316 |
''' |
315 | 317 |
def accept(self): |
316 | 318 |
print("save") |
... | ... | |
329 | 331 |
image = self.ui.imageView.image() |
330 | 332 |
if image is not None: |
331 | 333 |
if self.selectedSymbol is not None: |
332 |
self.deleteImageAndSvg(self.selectedSymbol.getPath(), self.selectedSymbol.getType(), self.selectedSymbol.getName())
|
|
334 |
self.deleteImageAndSvg(self.selectedSymbol.getImageFileFullPath(), self.selectedSymbol.getSvgFileFullPath())
|
|
333 | 335 |
imageLocation = self.project.getImageFilePath() + "/" + fileType |
334 | 336 |
if not os.path.exists(imageLocation): |
335 | 337 |
os.makedirs(imageLocation) |
... | ... | |
361 | 363 |
self.isAccepted = False |
362 | 364 |
QDialog.reject(self) |
363 | 365 |
|
364 |
def deleteImageAndSvg(self, imagePath, fileType, fileName): |
|
366 |
''' |
|
367 |
@history 2018.05.03 Jeongwoo Change Parameters (imagePath, type, name → imagePath, svgPath) |
|
368 |
''' |
|
369 |
def deleteImageAndSvg(self, imagePath, svgPath): |
|
365 | 370 |
if os.path.exists(imagePath): |
366 | 371 |
os.remove(imagePath) |
367 | 372 |
|
368 |
svgPath = self.project.getSvgFilePath() + "/" + fileType + "/" + fileName + ".svg" |
|
369 | 373 |
if os.path.exists(svgPath): |
370 | 374 |
os.remove(svgPath) |
371 | 375 |
|
372 | 376 |
''' |
373 | 377 |
@brief Called When error occured while saving png and svg files |
374 | 378 |
Delete png, svg files and record from DB |
379 |
@history 2018.05.03 Jeongwoo Change Parameters and fileName variable |
|
375 | 380 |
''' |
376 |
def resetInsertSymbol(self, imagePath, fileName):
|
|
377 |
self.deleteImageAndSvg(imagePath, fileName)
|
|
381 |
def resetInsertSymbol(self, imagePath, svgPath):
|
|
382 |
self.deleteImageAndSvg(imagePath, svgPath)
|
|
378 | 383 |
|
384 |
fileName = os.path.basename(imagePath.replace('.png', '')) |
|
379 | 385 |
AppDocData.instance().deleteSymbol(fileName) |
380 | 386 |
|
381 |
def resetUpdateSymbol(self, imagePath, fileName): |
|
382 |
self.deleteImageAndSvg(imagePath, fileName) |
|
387 |
''' |
|
388 |
@history 2018.05.03 Jeongwoo Change Parameters |
|
389 |
''' |
|
390 |
def resetUpdateSymbol(self, imagePath, svgPath): |
|
391 |
self.deleteImageAndSvg(imagePath, svgPath) |
|
383 | 392 |
|
384 | 393 |
SG_DbHelper.SG_DbHelper().updateSymbol(self.selectedSymbol) |
385 | 394 |
|
DTI_PID/DTI_PID/SG_DbHelper.py | ||
---|---|---|
88 | 88 |
|
89 | 89 |
''' |
90 | 90 |
@history 18.04.20 Jeongwoo Change dbFullPath (Root dir DB→ Each project DB) |
91 |
18.05.03 Jeongwoo Remove RootDir parameter |
|
91 | 92 |
''' |
92 |
def __init__(self, rootDir):
|
|
93 |
def __init__(self): |
|
93 | 94 |
print("DB Helper __init__") |
94 |
self.ROOT_DIR = rootDir |
|
95 | 95 |
|
96 | 96 |
self.dbFullPath = AppDocData.instance().getCurrentProject().getDbFilePath() + "/" + self.DB_NAME |
97 | 97 |
#if not os.path.isfile(dbFullPath): |
DTI_PID/DTI_PID/SymbolBase.py | ||
---|---|---|
1 | 1 |
OCR_OPTION_NOT_EXEC = 0 |
2 | 2 |
OCR_OPTION_ALL_FIND = 1 |
3 | 3 |
OCR_OPTION_HALF_AND_HALF = 2 |
4 |
|
|
4 | 5 |
class SymbolBase(): |
5 | 6 |
def __init__(self, id, sName, sType, threshold = None, minMatchCount = 0 |
6 | 7 |
, isDetectOnOrigin = False, rotationCount = 4, ocrOption = OCR_OPTION_NOT_EXEC, isContainChild = 0 |
... | ... | |
125 | 126 |
def getIsExceptDetect(self): |
126 | 127 |
return self.isExceptDetect |
127 | 128 |
|
129 |
''' |
|
130 |
@brief Get Image File Full Path |
|
131 |
@author Jeongwoo |
|
132 |
@date 2018.05.03 |
|
133 |
''' |
|
134 |
def getImageFileFullPath(self): |
|
135 |
from AppDocData import AppDocData |
|
136 |
project = AppDocData.instance().getCurrentProject() |
|
137 |
if project is not None: |
|
138 |
return project.getImageFilePath() + "/" + self.getType() + "/" + self.getName() + ".png" |
|
139 |
return None |
|
140 |
|
|
141 |
''' |
|
142 |
@brief Get Svg File Full Path |
|
143 |
@author Jeongwoo |
|
144 |
@date 2018.05.03 |
|
145 |
''' |
|
146 |
def getSvgFileFullPath(self): |
|
147 |
from AppDocData import AppDocData |
|
148 |
project = AppDocData.instance().getCurrentProject() |
|
149 |
if project is not None: |
|
150 |
return project.getSvgFilePath() + "/" + self.getType() + "/" + self.getName() + ".svg" |
|
151 |
return None |
|
152 |
|
|
128 | 153 |
class imgLine(): |
129 | 154 |
def __init__(self, start, end): |
130 | 155 |
self.start = start |
내보내기 Unified diff