hytos / DTI_PID / DTI_PID / ConfigurationDialog.py @ 60363ba3
이력 | 보기 | 이력해설 | 다운로드 (39.4 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is Configuratio dialog module """
|
3 |
|
4 |
import os |
5 |
import sys |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
import sqlite3 |
10 |
from AppDocData import AppDocData |
11 |
from AppDocData import Config |
12 |
from AppDocData import Color |
13 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
14 |
import Configuration_UI |
15 |
import tesseract_ocr_module as TOCR |
16 |
|
17 |
class ListView(QListView): |
18 |
def __init__(self, *args, **kwargs): |
19 |
super(ListView, self).__init__(*args, **kwargs) |
20 |
|
21 |
class QConfigurationDialog(QDialog): |
22 |
"""
|
23 |
@history humkyung 2018.05.05 read configuration for instrument and opc tag no rule
|
24 |
humkyung 2018.05.09 read line no tag rule configuration
|
25 |
Jeongwoo 2018.05.18 read Small Line Minimum Length
|
26 |
Jeongwoo 2018.06.04 read Min/Max Text Size
|
27 |
Jeongwoo 2018.06.05 read Text Area Detection Method
|
28 |
humkyung 2018.06.20 add expand,shrink and merge size for recognizing text
|
29 |
humkyung 2018.06.29 add line type table
|
30 |
kyouho 2018.07.04 add self.delimiter = '"'
|
31 |
"""
|
32 |
def __init__(self, parent): |
33 |
from LineTypeConditions import LineTypeConditions |
34 |
|
35 |
QDialog.__init__(self, parent)
|
36 |
|
37 |
self.ui = Configuration_UI.Ui_ConfigurationDialog()
|
38 |
self.ui.setupUi(self) |
39 |
self.isAccepted = False |
40 |
self.delimiter = '"' |
41 |
self.lineNoDelimiter = '!-!' |
42 |
self.defaultColor = Color(0, 0, 0, 255) |
43 |
self.currentIndex = 0 |
44 |
self.lineNoAttributeUID = []
|
45 |
self.tempLineColorUID = []
|
46 |
|
47 |
docData = AppDocData.instance() |
48 |
self.ui.comboBoxOCRData.addItem('eng') |
49 |
tessdata_path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID', 'Tesseract-OCR', 'tessdata') |
50 |
if os.path.isfile(os.path.join(tessdata_path, docData.getCurrentProject().getName() + '.traineddata')): |
51 |
self.ui.comboBoxOCRData.addItem(docData.getCurrentProject().getName())
|
52 |
|
53 |
configs = docData.getConfigs('Text Recognition', 'OCR Data') |
54 |
value = configs[0].value if 1 == len(configs) else '' |
55 |
if value:
|
56 |
at = self.ui.comboBoxOCRData.findText(value)
|
57 |
self.ui.comboBoxOCRData.setCurrentIndex(at)
|
58 |
else:
|
59 |
self.ui.comboBoxOCRData.selectedIndex = 0 |
60 |
|
61 |
configs = docData.getConfigs('Text Recognition', 'Expand Size') |
62 |
self.ui.spinBoxExpandSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxExpandSize.setValue(10) |
63 |
configs = docData.getConfigs('Text Recognition', 'Shrink Size') |
64 |
self.ui.spinBoxShrinkSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxShrinkSize.setValue(0) |
65 |
configs = docData.getConfigs('Text Recognition', 'Merge Size') |
66 |
self.ui.spinBoxMergeSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMergeSize.setValue(10) |
67 |
configs = docData.getConfigs('Text Recognition', 'White Character List') |
68 |
self.ui.lineEditWhiteCharList.setText(configs[0].value) if 1 == len(configs) else self.ui.lineEditWhiteCharList.setText(TOCR.DEFAULT_CONF[40:]) |
69 |
|
70 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
71 |
self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
72 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
73 |
self.ui.maxTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
74 |
|
75 |
configs = docData.getConfigs('Size', 'Delimiter') |
76 |
self.ui.lineEditSizeDelimiter.setText(configs[0].value if 1 == len(configs) else 'X') |
77 |
configs = docData.getConfigs('Range', 'Detection Ratio') |
78 |
self.ui.doubleSpinBoxDetectionRange.setValue(float(configs[0].value)) if 1 == len(configs) else self.ui.doubleSpinBoxDetectionRange.setValue(2.5) |
79 |
configs = docData.getConfigs('Flow Mark', 'Position') |
80 |
self.ui.spinBoxFlowMarkPosition.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlowMarkPosition.setValue(100) |
81 |
configs = docData.getConfigs('Flow Mark', 'Length') |
82 |
self.ui.spinBoxFlowMarkLength.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlowMarkLength.setValue(200) |
83 |
|
84 |
configs = docData.getConfigs('Filter', 'MinimumSize') |
85 |
self.ui.spinBoxMinimumSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMinimumSize.setValue(30) |
86 |
configs = docData.getConfigs('Filter', 'ErodeSize') |
87 |
self.ui.spinBoxUnrecognitionIgnoreStep.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxUnrecognitionIgnoreStep.setValue(3) |
88 |
configs = docData.getConfigs('Filter', 'DilateSize') |
89 |
self.ui.spinBoxDilateSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxDilateSize.setValue(0) |
90 |
configs = docData.getConfigs('Filter', 'FlatSize') |
91 |
self.ui.spinBoxFlatSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlatSize.setValue(0) |
92 |
|
93 |
# set min,max area for small object
|
94 |
configs = docData.getConfigs('Small Object Size', 'Min Area') |
95 |
self.ui.spinBoxMinArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMinArea.setValue(20) |
96 |
configs = docData.getConfigs('Small Object Size', 'Max Area') |
97 |
self.ui.spinBoxMaxArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMaxArea.setValue(50) |
98 |
# up to here
|
99 |
|
100 |
windowSize = docData.getSlidingWindowSize() |
101 |
self.ui.spinBoxWidth.setValue(windowSize[0]) |
102 |
self.ui.spinBoxHeight.setValue(windowSize[1]) |
103 |
|
104 |
configs = docData.getConfigs('Small Line Minimum Length', 'Min Length') |
105 |
self.ui.smallLineMinLengthSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.smallLineMinLengthSpinBox.setValue(25) |
106 |
configs = docData.getConfigs('Line Detector', 'Length to connect line') |
107 |
if configs: self.ui.spinBoxLengthToConnectLine.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxLengthToConnectLine.setValue(20) |
108 |
|
109 |
configs = docData.getConfigs('Line', 'Default Type') |
110 |
for lineType in LineTypeConditions.items(): |
111 |
self.ui.comboBoxLineType.addItem(lineType.name)
|
112 |
value = configs[0].value if 1 == len(configs) else '' |
113 |
if value:
|
114 |
at = self.ui.comboBoxLineType.findText(value)
|
115 |
self.ui.comboBoxLineType.setCurrentIndex(at)
|
116 |
else:
|
117 |
at = self.ui.comboBoxLineType.findText('Secondary') |
118 |
self.ui.comboBoxLineType.setCurrentIndex(at)
|
119 |
configs = docData.getConfigs('Line', 'Diagonal') |
120 |
if configs:
|
121 |
size = int(configs[0].value) |
122 |
self.ui.radioButtonDiagonalYes.setChecked(True if size == 1 else False) |
123 |
self.ui.radioButtonDiagonalNo.setChecked(True if size == -1 else False) |
124 |
else:
|
125 |
self.ui.radioButtonDiagonalYes.setChecked(True) |
126 |
self.ui.radioButtonDiagonalNo.setChecked(False) |
127 |
|
128 |
properties = docData.getLineProperties() |
129 |
if properties:
|
130 |
for prop in properties: |
131 |
self.lineNoAttributeUID.append(prop.UID)
|
132 |
if prop.AttributeType == "Code Table": |
133 |
self.tempLineColorUID.append(prop.Attribute)
|
134 |
self.ui.comboBoxColorOption.addItem(prop.DisplayAttribute)
|
135 |
|
136 |
self.load_line_properties()
|
137 |
|
138 |
# line no setting (line no, size unit, delimiter)
|
139 |
configs = docData.getConfigs('Line No', 'Size Unit') |
140 |
if 1 == len(configs): |
141 |
sizeUnit = configs[0].value.split(self.lineNoDelimiter) |
142 |
configs = docData.getConfigs('Line No', 'Delimiter') |
143 |
if 1 == len(configs): |
144 |
lineInsideDelimiter = configs[0].value.split(self.lineNoDelimiter) |
145 |
configs = docData.getConfigs('Line No', 'Configuration') |
146 |
if len(configs) == 1 and configs[0].value is not None: |
147 |
index = 0
|
148 |
for lineNo in configs[0].value.split(self.lineNoDelimiter): |
149 |
displayLineNo = ''
|
150 |
for value in lineNo.split(self.delimiter): |
151 |
lineProp = docData.getLinePropertiesByUID(value) |
152 |
if lineProp:
|
153 |
displayLineNo = displayLineNo + lineProp[0].DisplayAttribute
|
154 |
else:
|
155 |
displayLineNo = displayLineNo + value |
156 |
|
157 |
item = QListWidgetItem(displayLineNo) |
158 |
item.tag = [sizeUnit[index], lineNo, lineInsideDelimiter[index]] |
159 |
self.ui.listWidgetLineNo.addItem(item)
|
160 |
index = index + 1
|
161 |
|
162 |
configs = docData.getConfigs('Note No Tag Rule', 'Note No Expression') |
163 |
self.ui.lineEditNoteNoExpression.setText(configs[0].value if configs else '') |
164 |
configs = docData.getConfigs('Note No Tag Rule', 'Note No Symbol Name') |
165 |
self.ui.lineEditNoteNoSymbolName.setText(configs[0].value if configs else '') |
166 |
if self.ui.lineEditNoteNoSymbolName.text() == '': |
167 |
self.ui.lineEditNoteNoSymbolName.setEnabled(False) |
168 |
else:
|
169 |
self.ui.checkBoxNoteNoSymbolName.setCheckState(Qt.Checked)
|
170 |
configs = docData.getConfigs('OPC Tag Rule', 'From Prefix') |
171 |
self.ui.lineEditOPCFromPrefix.setText(configs[0].value if configs else '') |
172 |
configs = docData.getConfigs('OPC Tag Rule', 'To Prefix') |
173 |
self.ui.lineEditOPCToPrefix.setText(configs[0].value if configs else '') |
174 |
configs = docData.getConfigs('Supplied by Tag Rule', 'by Vendor') |
175 |
self.ui.lineEditByVendor.setText(configs[0].value if configs else 'by Vendor') |
176 |
self.ui.lineEditDrainSize.setText(docData.drain_size) # 2019.05.20 added by humkyung |
177 |
|
178 |
configs = docData.getConfigs('LineTypes')
|
179 |
|
180 |
line_type_conditions = LineTypeConditions.items() |
181 |
self.ui.tableWidgetLineTypes.setColumnCount(6) |
182 |
self.ui.tableWidgetLineTypes.setHorizontalHeaderLabels([self.tr('Name'), self.tr('Color'), self.tr('Width'), self.tr('Style'), self.tr('Opacity'), self.tr('Conditions')]) |
183 |
self.ui.tableWidgetLineTypes.setRowCount(len(line_type_conditions)) |
184 |
row = 0
|
185 |
for _condition in line_type_conditions: |
186 |
item = QTableWidgetItem(_condition.name) |
187 |
item.setFlags(Qt.ItemIsEnabled) |
188 |
item.setData(Qt.UserRole, _condition) |
189 |
self.ui.tableWidgetLineTypes.setItem(row, 0, item) |
190 |
|
191 |
matches = [config for config in configs if config.key == _condition.name] |
192 |
|
193 |
"""" Color """
|
194 |
color_cell = QTableWidgetItem('')
|
195 |
color_cell.setFlags(Qt.ItemIsEnabled) |
196 |
if matches:
|
197 |
tokens = matches[0].value.split(',') |
198 |
color_cell.setBackground(QColor(tokens[0]) if len(tokens) == 4 else Qt.blue) |
199 |
else:
|
200 |
color_cell.setBackground(Qt.blue) |
201 |
self.ui.tableWidgetLineTypes.setItem(row, 1, color_cell) |
202 |
|
203 |
""" line width """
|
204 |
lineWidthSpinBox = QSpinBox() |
205 |
lineWidthSpinBox.setRange(1, 25) |
206 |
lineWidthSpinBox.setSingleStep(1)
|
207 |
if matches:
|
208 |
tokens = matches[0].value.split(',') |
209 |
lineWidthSpinBox.setValue(int(tokens[1]) if len(tokens) == 4 else int(tokens[0])) |
210 |
else:
|
211 |
lineWidthSpinBox.setValue(5)
|
212 |
self.ui.tableWidgetLineTypes.setCellWidget(row, 2, lineWidthSpinBox) |
213 |
|
214 |
""" line style """
|
215 |
lineStyleComboBox = QComboBox() |
216 |
lineStyleComboBox.addItems(['SolidLine', 'DashLine', 'DotLine', 'DashDotLine', 'DashDotDotLine', 'CustomDashLine']) |
217 |
if matches:
|
218 |
tokens = matches[0].value.split(',') |
219 |
lineStyleComboBox.setCurrentText(tokens[2] if len(tokens) == 4 else tokens[1]) |
220 |
else:
|
221 |
lineStyleComboBox.setCurrentText('SolidLine')
|
222 |
lineStyleComboBox.setCurrentText(matches[0].value.split(',')[1]) if matches else lineStyleComboBox.setCurrentText('SolidLine') |
223 |
self.ui.tableWidgetLineTypes.setCellWidget(row, 3, lineStyleComboBox) |
224 |
|
225 |
""" line transparent """
|
226 |
lineTransparentSpinBox = QSpinBox() |
227 |
lineTransparentSpinBox.setRange(10, 100) |
228 |
lineTransparentSpinBox.setSingleStep(10)
|
229 |
if matches:
|
230 |
tokens = matches[0].value.split(',') |
231 |
lineTransparentSpinBox.setValue(int(tokens[3]) if len(tokens) == 4 else 100) |
232 |
else:
|
233 |
lineTransparentSpinBox.setValue(100)
|
234 |
self.ui.tableWidgetLineTypes.setCellWidget(row, 4, lineTransparentSpinBox) |
235 |
|
236 |
""" line type conditions """
|
237 |
condition_cell = QTableWidgetItem('...')
|
238 |
condition_cell.setTextAlignment(Qt.AlignHCenter) |
239 |
condition_cell.setFlags(Qt.ItemIsEnabled) |
240 |
self.ui.tableWidgetLineTypes.setItem(row, 5, condition_cell) |
241 |
|
242 |
row += 1
|
243 |
|
244 |
self.ui.tableWidgetLineTypes.horizontalHeaderItem(0).setSizeHint(QSize(30, 30)) |
245 |
self.ui.tableWidgetLineTypes.setColumnWidth(2, 135) |
246 |
self.ui.tableWidgetLineTypes.resizeColumnsToContents()
|
247 |
self.ui.tableWidgetLineTypes.horizontalHeader().setStretchLastSection(True) |
248 |
|
249 |
configs = docData.getConfigs('Instrument', 'Color') |
250 |
self.ui.pushButtonInstrumentColor.setStyleSheet('background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
251 |
configs = docData.getConfigs('Equipment', 'Color') |
252 |
self.ui.pushButtonEquipColor.setStyleSheet('background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
253 |
configs = docData.getConfigs('Symbol Style', 'Opacity') |
254 |
self.ui.spinBoxSymbolOpacity.setValue(int(configs[0].value) if configs else 50) |
255 |
|
256 |
self.ui.labelFontName.setBuddy(self.ui.fontComboBox) |
257 |
configs = docData.getConfigs('Text Style', 'Font Name') |
258 |
if configs:
|
259 |
self.ui.fontComboBox.setCurrentFont(QFont(configs[0].value, 10)) |
260 |
configs = docData.getConfigs('Text Style', 'Font Size') |
261 |
if configs:
|
262 |
size = int(configs[0].value) |
263 |
self.ui.radioButtonAutoSize.setChecked(True if size == -1 else False) |
264 |
self.ui.radioButtonFixedSize.setChecked(True if size != -1 else False) |
265 |
self.ui.spinBoxFontSize.setValue(size if size != -1 else 10) |
266 |
self.ui.spinBoxFontSize.setEnabled(self.ui.radioButtonFixedSize.isChecked()) |
267 |
else:
|
268 |
self.ui.radioButtonAutoSize.setChecked(True) |
269 |
self.ui.radioButtonFixedSize.setChecked(False) |
270 |
self.ui.spinBoxFontSize.setValue(10) |
271 |
self.ui.spinBoxFontSize.setEnabled(self.ui.radioButtonFixedSize.isChecked()) |
272 |
|
273 |
# Line Color Visible Option 가져옴
|
274 |
configs = docData.getConfigs('Line Color', 'Visible Option') |
275 |
if configs:
|
276 |
data = configs[0].value
|
277 |
self.ui.radioButtonRandom.setChecked(True if data == 'Random' else False) |
278 |
self.ui.radioButtonProperty.setChecked(True if data == 'Property' else False) |
279 |
else:
|
280 |
self.ui.radioButtonRandom.setChecked(True) |
281 |
self.ui.radioButtonProperty.setChecked(False) |
282 |
|
283 |
# Color Property 선택값 가져옴
|
284 |
self.ui.tableWidgetColorProperty.setHorizontalHeaderLabels(['Value', 'Color', 'ref', 'colorStr']) |
285 |
table = self.ui.tableWidgetColorProperty
|
286 |
index = 0
|
287 |
configs = docData.getConfigs('Color Property', 'State') |
288 |
if configs:
|
289 |
uid = configs[0].value
|
290 |
lineProp = docData.getLinePropertiesByUID(uid) |
291 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText(lineProp[0].DisplayAttribute) >= 0 else '' |
292 |
|
293 |
index = self.ui.comboBoxColorOption.findText(selectedOption)
|
294 |
self.ui.comboBoxColorOption.setCurrentIndex(index)
|
295 |
self.currentIndex = index
|
296 |
|
297 |
table.hideColumn(2)
|
298 |
table.hideColumn(3)
|
299 |
#Column Header Size
|
300 |
self.ui.tableWidgetColorProperty.horizontalHeaderItem(0).setSizeHint(QSize(30, 30)) |
301 |
self.setPropertyToggle(self.ui.radioButtonProperty.isChecked()) |
302 |
|
303 |
configs = docData.getConfigs('Data Load', 'Xml First') |
304 |
if configs:
|
305 |
size = int(configs[0].value) |
306 |
self.ui.radioButtonLoadXmlYes.setChecked(True if size == 1 else False) |
307 |
self.ui.radioButtonLoadXmlNo.setChecked(True if size == -1 else False) |
308 |
else:
|
309 |
self.ui.radioButtonLoadXmlYes.setChecked(True) |
310 |
self.ui.radioButtonLoadXmlNo.setChecked(False) |
311 |
configs = docData.getConfigs('Data Save', 'Unknown Xml Only') |
312 |
if configs:
|
313 |
size = int(configs[0].value) |
314 |
self.ui.radioButtonSaveUnknownYes.setChecked(True if size == 1 else False) |
315 |
self.ui.radioButtonSaveUnknownNo.setChecked(True if size == -1 else False) |
316 |
else:
|
317 |
self.ui.radioButtonSaveUnknownYes.setChecked(True) |
318 |
self.ui.radioButtonSaveUnknownNo.setChecked(False) |
319 |
|
320 |
# connect signals and slots
|
321 |
self.ui.pushButtonAddProperty.clicked.connect(self.addLineProperty) |
322 |
self.ui.pushButtonDeleteProperty.clicked.connect(self.removeSelectedItem) |
323 |
self.ui.radioButtonFixedSize.toggled.connect(self.onFixedSizeToggled) |
324 |
self.ui.pushButtonInstrumentColor.clicked.connect(self.change_instrument_color) |
325 |
self.ui.pushButtonEquipColor.clicked.connect(self.change_equipment_color) |
326 |
self.ui.tableWidgetLineTypes.cellDoubleClicked.connect(self.cell_double_clicked) |
327 |
self.ui.tableWidgetColorProperty.cellDoubleClicked.connect(self.cellDoubleClick) |
328 |
self.ui.comboBoxColorOption.currentIndexChanged.connect(self.currentIndexChanged) |
329 |
self.ui.radioButtonRandom.toggled.connect(self.onPropertyToggled) |
330 |
self.ui.pushButtonLineNoAttribute.clicked.connect(self.editLineNoAttributeClicked) |
331 |
self.ui.checkBoxNoteNoSymbolName.stateChanged.connect(self.checkBoxNoteNoSymbolNameChanged) |
332 |
self.ui.listWidgetLineNo.itemDoubleClicked.connect(self.lineNoItemDoubleCliced) |
333 |
self.ui.pushButtonClearAccessInfo.clicked.connect(self.clear_drawing_access_info_clicked) |
334 |
|
335 |
def clear_drawing_access_info_clicked(self): |
336 |
reply = QMessageBox.question(self, self.tr('Continue?'), self.tr('Are you sure you want to clear drawing access information?'), QMessageBox.Yes, QMessageBox.Cancel) |
337 |
if reply == QMessageBox.Yes:
|
338 |
AppDocData.instance().clear_occupying_drawing(None)
|
339 |
QMessageBox.information(self, self.tr('Information'), self.tr('Succeeded')) |
340 |
|
341 |
def lineNoItemDoubleCliced(self, item): |
342 |
from ConfigurationLineNoDialog import QConfigurationLineNoDialog |
343 |
|
344 |
configuration_line_no_dialog = QConfigurationLineNoDialog(self, False, self.delimiter, item) |
345 |
isAccepted, newItem = configuration_line_no_dialog.showDialog() |
346 |
if isAccepted:
|
347 |
index = self.ui.listWidgetLineNo.currentRow()
|
348 |
self.ui.listWidgetLineNo.insertItem(index, newItem)
|
349 |
self.ui.listWidgetLineNo.takeItem(index + 1) |
350 |
|
351 |
def checkBoxNoteNoSymbolNameChanged(self): |
352 |
if self.ui.checkBoxNoteNoSymbolName.isChecked() is True: |
353 |
self.ui.lineEditNoteNoSymbolName.setEnabled(True) |
354 |
else:
|
355 |
self.ui.lineEditNoteNoSymbolName.setText('') |
356 |
self.ui.lineEditNoteNoSymbolName.setEnabled(False) |
357 |
|
358 |
def load_line_properties(self): |
359 |
app_doc_data = AppDocData.instance() |
360 |
app_doc_data.clearLineNoProperties() |
361 |
properties = app_doc_data.getLineProperties() |
362 |
if properties:
|
363 |
self.lineNoAttributeUID.clear()
|
364 |
self.tempLineColorUID.clear()
|
365 |
self.ui.comboBoxColorOption.clear()
|
366 |
for prop in properties: |
367 |
self.lineNoAttributeUID.append(prop.UID)
|
368 |
if prop.AttributeType == 'Code Table': |
369 |
self.tempLineColorUID.append(prop.Attribute)
|
370 |
self.ui.comboBoxColorOption.addItem(prop.DisplayAttribute)
|
371 |
|
372 |
|
373 |
configs = app_doc_data.getConfigs('Color Property', 'State') |
374 |
if configs:
|
375 |
uid = configs[0].value
|
376 |
lineProp = app_doc_data.getLinePropertiesByUID(uid) |
377 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText(lineProp[0].DisplayAttribute) >= 0 else '' |
378 |
|
379 |
index = self.ui.comboBoxColorOption.findText(selectedOption)
|
380 |
self.ui.comboBoxColorOption.setCurrentIndex(index)
|
381 |
self.currentIndex = index
|
382 |
|
383 |
def editLineNoAttributeClicked(self): |
384 |
""" edit line no attributes and then update line no attribute combobox if close attribute editor dialog by accept button """
|
385 |
from SymbolAttrEditorDialog import QSymbolAttrEditorDialog |
386 |
try:
|
387 |
dlg = QSymbolAttrEditorDialog(self)
|
388 |
if QDialog.Accepted == dlg.exec_():
|
389 |
# update line no attribute combobox
|
390 |
self.load_line_properties()
|
391 |
except Exception as ex: |
392 |
from App import App |
393 |
from AppDocData import MessageType |
394 |
|
395 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
396 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
397 |
|
398 |
'''
|
399 |
@brief Clear Table
|
400 |
@author kyouho
|
401 |
@date 2018.07.10
|
402 |
'''
|
403 |
def clearColorPropertyTable(self): |
404 |
table = self.ui.tableWidgetColorProperty
|
405 |
model = table.model() |
406 |
|
407 |
while table.rowCount():
|
408 |
model.removeRow(table.rowCount() - 1)
|
409 |
|
410 |
'''
|
411 |
@brief setting default table
|
412 |
@author kyouho
|
413 |
@date 2018.07.09
|
414 |
'''
|
415 |
def settingDefaultColorTable(self, property): |
416 |
docData = AppDocData.instance() |
417 |
table = self.ui.tableWidgetColorProperty
|
418 |
self.clearColorPropertyTable()
|
419 |
|
420 |
dic = {} |
421 |
|
422 |
lineProp = docData.getLinePropertiesByUID(property)
|
423 |
if lineProp:
|
424 |
tableName = lineProp[0].Attribute
|
425 |
else:
|
426 |
return
|
427 |
|
428 |
if tableName.replace(' ','') == "NominalDiameter": |
429 |
#중복 체크 배열
|
430 |
checkRepeat = [] |
431 |
# Size 표기 가져옴
|
432 |
configs = docData.getConfigs('Line No', 'Size Unit') |
433 |
# Size 관련 Table 가져옴
|
434 |
result = docData.getNomialPipeSizeData(False, "Metric") |
435 |
|
436 |
for pipeSize in result: |
437 |
if not pipeSize.inchStr or not pipeSize.metricStr: |
438 |
continue
|
439 |
else:
|
440 |
replaceInchStr = pipeSize.inchStr.replace("'", '"') |
441 |
if checkRepeat.count(replaceInchStr):
|
442 |
continue
|
443 |
else:
|
444 |
checkRepeat.append(replaceInchStr) |
445 |
|
446 |
if configs[0].value == 'Inch': |
447 |
dic[replaceInchStr] = pipeSize.metricStr |
448 |
else:
|
449 |
dic[pipeSize.metricStr] = pipeSize.metricStr |
450 |
|
451 |
elif tableName != "Tag Seq No": |
452 |
result = docData.getCodeTable(tableName, True)
|
453 |
for fluidCode in result: |
454 |
dic[fluidCode] = fluidCode |
455 |
|
456 |
if dic:
|
457 |
table.setRowCount(len(dic))
|
458 |
|
459 |
row = 0
|
460 |
for i in dic.keys(): |
461 |
table.setItem(row, 0, QTableWidgetItem(i))
|
462 |
table.setItem(row, 1, QTableWidgetItem('')) |
463 |
table.setItem(row, 2, QTableWidgetItem(dic[i]))
|
464 |
table.setItem(row, 3, QTableWidgetItem('')) |
465 |
row += 1
|
466 |
|
467 |
'''
|
468 |
@brief setting Color String Cell
|
469 |
@author kyouho
|
470 |
@date 2018.07.09
|
471 |
'''
|
472 |
def settingColorStringCell(self, property): |
473 |
docData = AppDocData.instance() |
474 |
table = self.ui.tableWidgetColorProperty
|
475 |
rowCount = table.rowCount() |
476 |
for j in range(rowCount): |
477 |
ref = table.item(j, 2)
|
478 |
|
479 |
configs = docData.getConfigs(property, ref.text())
|
480 |
if configs:
|
481 |
colorStr = table.item(j, 3)
|
482 |
colorStr.setText(configs[0].value)
|
483 |
|
484 |
'''
|
485 |
@brief setting color cell
|
486 |
@author kyouho
|
487 |
@date 2018.07.09
|
488 |
'''
|
489 |
def settingColorCell(self): |
490 |
table = self.ui.tableWidgetColorProperty
|
491 |
rowCount = table.rowCount() |
492 |
|
493 |
for i in range(rowCount): |
494 |
colorCell = table.item(i, 1)
|
495 |
colorDataCell = table.item(i, 3)
|
496 |
colorStr = colorDataCell.text() |
497 |
|
498 |
if colorStr:
|
499 |
split = colorStr.split(',')
|
500 |
r = split[0]
|
501 |
g = split[1]
|
502 |
b = split[2]
|
503 |
|
504 |
colorCell.setBackground(QColor(int(r), int(g), int(b))) |
505 |
else:
|
506 |
colorCell.setBackground(QColor(self.defaultColor.red, self.defaultColor.green, self.defaultColor.blue)) |
507 |
|
508 |
'''
|
509 |
@brief Cell Double Click Event
|
510 |
@author kyouho
|
511 |
@date 2018.07.09
|
512 |
'''
|
513 |
def currentIndexChanged(self, index): |
514 |
if self.currentIndex != index and index is not -1: |
515 |
self.currentIndex = index
|
516 |
|
517 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
518 |
name = self.tempLineColorUID[selectedIndex]
|
519 |
|
520 |
docData = AppDocData.instance() |
521 |
lineProp = [prop for prop in docData.getLineProperties() if prop.Attribute == name] |
522 |
|
523 |
if lineProp:
|
524 |
# 기본 테이블 셋팅
|
525 |
self.settingDefaultColorTable(lineProp[0].UID) |
526 |
# 설정된 색상 가져옴
|
527 |
self.settingColorStringCell(lineProp[0].UID) |
528 |
|
529 |
#Table Color Setting
|
530 |
self.settingColorCell()
|
531 |
|
532 |
def change_instrument_color(self): |
533 |
""" change instrument's color """
|
534 |
color = QColorDialog.getColor(self.ui.pushButtonInstrumentColor.palette().button().color())
|
535 |
if color.isValid():
|
536 |
item = self.ui.pushButtonInstrumentColor.setStyleSheet('background-color:{}'.format(color.name())) |
537 |
|
538 |
def change_equipment_color(self): |
539 |
""" change instrument's color """
|
540 |
color = QColorDialog.getColor(self.ui.pushButtonEquipColor.palette().button().color())
|
541 |
if color.isValid():
|
542 |
item = self.ui.pushButtonEquipColor.setStyleSheet('background-color:{}'.format(color.name())) |
543 |
|
544 |
def cell_double_clicked(self, row, column): |
545 |
""" change line type's color or change line type's conditions """
|
546 |
if column == 1: |
547 |
color = QColorDialog.getColor(self.ui.tableWidgetLineTypes.item(row, column).background().color())
|
548 |
if color.isValid():
|
549 |
item = self.ui.tableWidgetLineTypes.item(row, column)
|
550 |
item.setBackground(color) |
551 |
elif column == 5: |
552 |
""" pop up line type conditions dialog """
|
553 |
from LineTypeConditionsDialog import QLineTypeConditionsDialog |
554 |
|
555 |
try:
|
556 |
data = self.ui.tableWidgetLineTypes.item(row, 0).data(Qt.UserRole) |
557 |
dlg = QLineTypeConditionsDialog(self, data)
|
558 |
if QDialog.Accepted == dlg.exec_():
|
559 |
pass
|
560 |
except Exception as ex: |
561 |
from App import App |
562 |
from AppDocData import MessageType |
563 |
|
564 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
565 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
566 |
|
567 |
'''
|
568 |
@brief Cell Double Click Event
|
569 |
@author kyouho
|
570 |
@date 2018.07.09
|
571 |
'''
|
572 |
def cellDoubleClick(self, row, column): |
573 |
if column == 1: |
574 |
color = QColorDialog.getColor(self.ui.tableWidgetColorProperty.item(row, column).background().color())
|
575 |
if color.isValid():
|
576 |
self.ui.tableWidgetColorProperty.setItem(row, 3, QTableWidgetItem(str(color.red()) + ',' + str(color.green()) + ',' + str(color.blue()))) |
577 |
#Table Color Setting
|
578 |
self.settingColorCell()
|
579 |
|
580 |
'''
|
581 |
@brief add line property
|
582 |
@author humkyung
|
583 |
@date 2018.04.09
|
584 |
'''
|
585 |
def addLineProperty(self): |
586 |
from ConfigurationLineNoDialog import QConfigurationLineNoDialog |
587 |
|
588 |
configuration_line_no_dialog = QConfigurationLineNoDialog(self, True, self.delimiter) |
589 |
isAccepted, newItem = configuration_line_no_dialog.showDialog() |
590 |
if isAccepted:
|
591 |
index = self.ui.listWidgetLineNo.currentRow()
|
592 |
self.ui.listWidgetLineNo.addItem(newItem)
|
593 |
|
594 |
'''
|
595 |
@brief enable/disable font size spinbox
|
596 |
@author humkyung
|
597 |
@date 2018.06.30
|
598 |
'''
|
599 |
def onFixedSizeToggled(self, radioButton): |
600 |
self.ui.spinBoxFontSize.setEnabled(self.ui.radioButtonFixedSize.isChecked()) |
601 |
|
602 |
'''
|
603 |
@brief property radio button toggle event
|
604 |
@author kyouho
|
605 |
@date 2018.07.10
|
606 |
'''
|
607 |
def onPropertyToggled(self, radioButton): |
608 |
self.setPropertyToggle(self.ui.radioButtonProperty.isChecked()) |
609 |
'''
|
610 |
@brief enable/disable font size spinbox
|
611 |
@author kyouho
|
612 |
@date 2018.07.10
|
613 |
'''
|
614 |
def setPropertyToggle(self, enable): |
615 |
try:
|
616 |
if enable:
|
617 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
618 |
name = self.tempLineColorUID[selectedIndex]
|
619 |
|
620 |
docData = AppDocData.instance() |
621 |
lineProp = [prop for prop in docData.getLineProperties() if prop.Attribute == name] |
622 |
if lineProp:
|
623 |
# 기본 테이블 셋팅
|
624 |
self.settingDefaultColorTable(lineProp[0].UID) |
625 |
# 설정된 색상 가져옴
|
626 |
self.settingColorStringCell(lineProp[0].UID) |
627 |
#Table Color Setting
|
628 |
self.settingColorCell()
|
629 |
else:
|
630 |
self.clearColorPropertyTable()
|
631 |
|
632 |
self.ui.comboBoxColorOption.setEnabled(enable)
|
633 |
except Exception as ex: |
634 |
from App import App |
635 |
from AppDocData import MessageType |
636 |
|
637 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
638 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
639 |
finally:
|
640 |
self.ui.tableWidgetColorProperty.resizeColumnsToContents()
|
641 |
self.ui.tableWidgetColorProperty.horizontalHeader().setStretchLastSection(True) |
642 |
|
643 |
'''
|
644 |
@brief insert or update configurations modified by user
|
645 |
@author humkyung
|
646 |
@date 2018.??.??
|
647 |
@history humkyung 2018.04.24 save size unit of line no
|
648 |
humkyung 2018.04.26 save min,max area for small object
|
649 |
humkyung 2018.05.02 save size delimiter
|
650 |
humkyung 2018.05.05 save instrument and opc tag no rule
|
651 |
humkyung 2018.05.09 save line no tag rule
|
652 |
Jeongwoo 2018.05.18 save Small Line Minimum Length
|
653 |
Jeongwoo 2018.06.04 save Min/Max Text Size
|
654 |
Jeongwoo 2018.06.05 save Text Area Detection Method
|
655 |
humkyung 2018.06.20 save Expand and Shrink size for recognizing text
|
656 |
kyouho 2018.07.04 edit cofiguration new delimiter (self.delimiter)
|
657 |
'''
|
658 |
def accept(self): |
659 |
from NominalPipeSize import NominalPipeSizeTable |
660 |
from LineTypeConditions import LineTypeConditions |
661 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
662 |
from EngineeringEquipmentItem import QEngineeringEquipmentItem |
663 |
|
664 |
try:
|
665 |
docData = AppDocData.instance() |
666 |
|
667 |
self.isAccepted = True |
668 |
|
669 |
configs = [] |
670 |
docData.OCRData = self.ui.comboBoxOCRData.currentText() if self.ui.comboBoxOCRData.currentText() else 'eng' |
671 |
configs.append(Config('Text Recognition', 'OCR Data', docData.OCRData)) |
672 |
configs.append(Config('Text Recognition', 'Expand Size', self.ui.spinBoxExpandSize.value())) |
673 |
configs.append(Config('Text Recognition', 'Shrink Size', self.ui.spinBoxShrinkSize.value())) |
674 |
configs.append(Config('Text Recognition', 'Merge Size', self.ui.spinBoxMergeSize.value())) |
675 |
|
676 |
configs.append(Config('Text Size', 'Min Text Size', self.ui.minTextSizeSpinBox.value())) |
677 |
configs.append(Config('Text Size', 'Max Text Size', self.ui.maxTextSizeSpinBox.value())) |
678 |
|
679 |
configs.append(Config('Size', 'Delimiter', self.ui.lineEditSizeDelimiter.text())) |
680 |
configs.append(Config('Range', 'Detection Ratio', self.ui.doubleSpinBoxDetectionRange.value())) |
681 |
configs.append(Config('Flow Mark', 'Position', self.ui.spinBoxFlowMarkPosition.value())) |
682 |
configs.append(Config('Flow Mark', 'Length', self.ui.spinBoxFlowMarkLength.value())) |
683 |
configs.append(Config('Filter', 'MinimumSize', self.ui.spinBoxMinimumSize.value())) |
684 |
configs.append(Config('Filter', 'ErodeSize', self.ui.spinBoxUnrecognitionIgnoreStep.value())) |
685 |
configs.append(Config('Filter', 'DilateSize', self.ui.spinBoxDilateSize.value())) |
686 |
configs.append(Config('Filter', 'FlatSize', self.ui.spinBoxFlatSize.value())) |
687 |
configs.append(Config('Small Object Size', 'Min Area', self.ui.spinBoxMinArea.value())) |
688 |
configs.append(Config('Small Object Size', 'Max Area', self.ui.spinBoxMaxArea.value())) |
689 |
configs.append(Config('Sliding Window', 'Width', self.ui.spinBoxWidth.value())) |
690 |
configs.append(Config('Sliding Window', 'Height', self.ui.spinBoxHeight.value())) |
691 |
configs.append(Config('Small Line Minimum Length', 'Min Length', self.ui.smallLineMinLengthSpinBox.value())) |
692 |
configs.append(Config('Line Detector', 'Length to connect line', self.ui.spinBoxLengthToConnectLine.value())) |
693 |
configs.append(Config('Line', 'Default Type', self.ui.comboBoxLineType.currentText())) |
694 |
configs.append(Config('Line', 'Diagonal', '1' if self.ui.radioButtonDiagonalYes.isChecked() else '-1')) |
695 |
configs.append(Config('Note No Tag Rule', 'Note No Expression', self.ui.lineEditNoteNoExpression.text())) |
696 |
configs.append(Config('Note No Tag Rule', 'Note No Symbol Name', self.ui.lineEditNoteNoSymbolName.text())) |
697 |
configs.append(Config('OPC Tag Rule', 'From Prefix', self.ui.lineEditOPCFromPrefix.text())) |
698 |
configs.append(Config('OPC Tag Rule', 'To Prefix', self.ui.lineEditOPCToPrefix.text())) |
699 |
configs.append(Config('Supplied by Tag Rule', 'by Vendor', self.ui.lineEditByVendor.text())) |
700 |
docData.drain_size = self.ui.lineEditDrainSize.text()
|
701 |
configs.append(Config('Drain Size Rule', 'Size', docData.drain_size)) |
702 |
configs.append(Config('Text Recognition', 'White Character List', self.ui.lineEditWhiteCharList.text())) |
703 |
|
704 |
# Add Line Color Option - 2018.07.06 by kyouho
|
705 |
rbRandomValue = self.ui.radioButtonRandom.isChecked()
|
706 |
|
707 |
for row in range(self.ui.tableWidgetLineTypes.rowCount()): |
708 |
lineType = self.ui.tableWidgetLineTypes.item(row, 0).text() |
709 |
color = self.ui.tableWidgetLineTypes.item(row, 1).background().color().name() |
710 |
width = self.ui.tableWidgetLineTypes.cellWidget(row, 2).text() |
711 |
style = self.ui.tableWidgetLineTypes.cellWidget(row, 3).currentText() |
712 |
transparent = self.ui.tableWidgetLineTypes.cellWidget(row, 4).text() |
713 |
configs.append(Config('LineTypes', lineType, '{},{},{},{}'.format(color, width, style,transparent))) |
714 |
""" add line type condition to configs """
|
715 |
data = self.ui.tableWidgetLineTypes.item(row, 0).data(Qt.UserRole) |
716 |
configs.append(data) |
717 |
|
718 |
docData = AppDocData.instance() |
719 |
|
720 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
721 |
name = self.tempLineColorUID[selectedIndex]
|
722 |
lineProp = [prop for prop in docData.getLineProperties() if prop.Attribute == name] |
723 |
|
724 |
configs.append(Config('Line Color', 'Visible Option', 'Random' if rbRandomValue else 'Property')) |
725 |
if lineProp:
|
726 |
configs.append(Config('Color Property', 'State', lineProp[0].UID)) |
727 |
|
728 |
if not rbRandomValue: |
729 |
table = self.ui.tableWidgetColorProperty
|
730 |
rowCount = self.ui.tableWidgetColorProperty.rowCount()
|
731 |
for i in range(rowCount): |
732 |
refStr = table.item(i, 2).text()
|
733 |
colorStr = table.item(i, 3).text()
|
734 |
if colorStr:
|
735 |
configs.append(Config(lineProp[0].UID, refStr, colorStr))
|
736 |
|
737 |
#Configuration
|
738 |
sizeUnit = None
|
739 |
configuration = None
|
740 |
lineInsideDelimiter = None
|
741 |
for i in range(self.ui.listWidgetLineNo.count()): |
742 |
item = self.ui.listWidgetLineNo.item(i)
|
743 |
if configuration is None: |
744 |
sizeUnit = item.tag[0]
|
745 |
configuration = item.tag[1]
|
746 |
lineInsideDelimiter = item.tag[2]
|
747 |
else:
|
748 |
sizeUnit += self.lineNoDelimiter + item.tag[0] |
749 |
configuration += self.lineNoDelimiter + item.tag[1] |
750 |
lineInsideDelimiter += self.lineNoDelimiter + item.tag[2] |
751 |
if self.ui.listWidgetLineNo.count() is not 0: |
752 |
configs.append(Config('Line No', 'Size Unit', sizeUnit)) |
753 |
configs.append(Config('Line No', 'Configuration', configuration)) |
754 |
configs.append(Config('Line No', 'Delimiter', lineInsideDelimiter)) |
755 |
|
756 |
# save symbol opacity - 2019.04.18 added by humkyung
|
757 |
configs.append(Config('Instrument', 'Color', self.ui.pushButtonInstrumentColor.palette().color(QPalette.Background).name())) |
758 |
QEngineeringInstrumentItem.INST_COLOR = None
|
759 |
configs.append(Config('Equipment', 'Color', self.ui.pushButtonEquipColor.palette().color(QPalette.Background).name())) |
760 |
QEngineeringEquipmentItem.EQUIP_COLOR = None
|
761 |
configs.append(Config('Symbol Style', 'Opacity', str(self.ui.spinBoxSymbolOpacity.value()))) |
762 |
|
763 |
font = self.ui.fontComboBox.currentFont()
|
764 |
configs.append(Config('Text Style', 'Font Name', font.family())) |
765 |
configs.append(Config('Text Style', 'Font Size', str(self.ui.spinBoxFontSize.value()) if self.ui.radioButtonFixedSize.isChecked() else '-1')) |
766 |
|
767 |
configs.append(Config('Data Load', 'Xml First', '1' if self.ui.radioButtonLoadXmlYes.isChecked() else '-1')) |
768 |
configs.append(Config('Data Save', 'Unknown Xml Only', '1' if self.ui.radioButtonSaveUnknownYes.isChecked() else '-1')) |
769 |
|
770 |
docData.saveConfigs(configs) |
771 |
docData.lineTypeConfigs = None # clear line type configurations |
772 |
NominalPipeSizeTable.instance().pipe_sizes = None # clear nominal pipe size table |
773 |
|
774 |
except Exception as ex: |
775 |
from App import App |
776 |
from AppDocData import MessageType |
777 |
|
778 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
779 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
780 |
|
781 |
QDialog.accept(self)
|
782 |
|
783 |
'''
|
784 |
@brief deleted selected item
|
785 |
@author humkyung
|
786 |
@date 2018.04.09
|
787 |
'''
|
788 |
def removeSelectedItem(self): |
789 |
selectedIndex = self.ui.listWidgetLineNo.currentRow()
|
790 |
if selectedIndex is not -1: |
791 |
self.ui.listWidgetLineNo.takeItem(selectedIndex)
|
792 |
|
793 |
'''
|
794 |
@brief key press event
|
795 |
@author humkyung
|
796 |
@date 2018.04.09
|
797 |
'''
|
798 |
def keyPressEvent(self, event): |
799 |
if event.key() == Qt.Key_Delete:
|
800 |
self.removeSelectedItem()
|
801 |
return
|