개정판 17cbda7d
issue #503: vendorPackage 설정 기능 개선(추가, 삭제 기능 추가)
Change-Id: I08b01ae0d81bb448e5d53328aef3b1abfb9f216f
DTI_PID/DTI_PID/Commands/PlaceLineCommand.py | ||
---|---|---|
4 | 4 |
""" |
5 | 5 |
|
6 | 6 |
import os.path |
7 |
import sys |
|
7 | 8 |
import AbstractCommand |
9 |
|
|
8 | 10 |
try: |
9 | 11 |
from PyQt5.QtCore import * |
10 | 12 |
from PyQt5.QtGui import * |
... | ... | |
16 | 18 |
except ImportError: |
17 | 19 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
18 | 20 |
|
21 |
|
|
19 | 22 |
class PlaceLineCommand(AbstractCommand.AbstractCommand): |
20 |
""" |
|
21 |
This is place line class |
|
22 |
""" |
|
23 |
"""This is place line class""" |
|
23 | 24 |
|
24 | 25 |
onSuccess = pyqtSignal() |
25 | 26 |
onRejected = pyqtSignal(AbstractCommand.AbstractCommand) |
26 | 27 |
|
27 | 28 |
def __init__(self, imageViewer): |
28 | 29 |
super(PlaceLineCommand, self).__init__(imageViewer) |
29 |
self.name = 'PlaceLine'
|
|
30 |
self.name = 'PlaceLine' |
|
30 | 31 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
31 | 32 |
|
32 | 33 |
self._polyline = None |
33 |
|
|
34 |
|
|
34 | 35 |
''' |
35 | 36 |
@brief reset command status |
36 | 37 |
@author humkyung |
37 | 38 |
@date 2018.07.23 |
38 | 39 |
''' |
40 |
|
|
39 | 41 |
def reset(self): |
40 | 42 |
self._polyline = None |
41 | 43 |
|
... | ... | |
44 | 46 |
@author humkyung |
45 | 47 |
@date 2018.07.23 |
46 | 48 |
''' |
49 |
|
|
47 | 50 |
def execute(self, param): |
48 | 51 |
import shapely |
49 | 52 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
... | ... | |
54 | 57 |
self.isTreated = False |
55 | 58 |
|
56 | 59 |
event = param[1] |
57 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
58 |
if self._polyline is None: |
|
59 |
selected = [conn for conn in self.imageViewer.scene.items(param[2]) if type(conn) is not QGraphicsTextItem][0] |
|
60 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
|
61 |
self._polyline = QEngineeringPolylineItem() |
|
62 |
self._polyline._vertices.append(selected.center()) |
|
63 |
self.imageViewer.scene.addItem(self._polyline) |
|
64 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
65 |
elif selected is not None and type(selected) is QEngineeringLineItem: |
|
66 |
length = selected.length()*0.5 |
|
67 |
dir = selected.perpendicular() |
|
68 |
start = [param[2].x() - dir[0]*length, param[2].y() - dir[1]*length] |
|
69 |
end = [param[2].x() + dir[0]*length, param[2].y() + dir[1]*length] |
|
70 |
pt = selected.intersection([start, end]) |
|
71 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
60 |
try: |
|
61 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
62 |
if self._polyline is None: |
|
63 |
selected = \ |
|
64 |
[conn for conn in self.imageViewer.scene.items(param[2]) if type(conn) is not QGraphicsTextItem][0] |
|
65 |
if selected is not None and type(selected) is QEngineeringConnectorItem: |
|
72 | 66 |
self._polyline = QEngineeringPolylineItem() |
73 |
self._polyline._vertices.append([pt.x, pt.y])
|
|
67 |
self._polyline._vertices.append(selected.center())
|
|
74 | 68 |
self.imageViewer.scene.addItem(self._polyline) |
75 | 69 |
self.imageViewer.scene.setFocusItem(self._polyline) |
76 |
else: |
|
77 |
try: |
|
78 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
79 |
self._polyline._vertices.append(self._polyline._pt) |
|
80 |
self._polyline.update() |
|
81 |
finally: |
|
82 |
pass |
|
83 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
84 |
self.onSuccess.emit() |
|
85 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
86 |
self.onRejected.emit(self) |
|
87 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
88 |
self._polyline.onMouseMoved(event, param[2]) |
|
89 |
elif 'keyPressEvent' == param[0]: |
|
90 |
if event.key() == Qt.Key_Escape: |
|
70 |
elif selected is not None and type(selected) is QEngineeringLineItem: |
|
71 |
length = selected.length() * 0.5 |
|
72 |
dir = selected.perpendicular() |
|
73 |
start = [param[2].x() - dir[0] * length, param[2].y() - dir[1] * length] |
|
74 |
end = [param[2].x() + dir[0] * length, param[2].y() + dir[1] * length] |
|
75 |
pt = selected.intersection([start, end]) |
|
76 |
if (pt is not None) and (type(pt) == shapely.geometry.point.Point): |
|
77 |
self._polyline = QEngineeringPolylineItem() |
|
78 |
self._polyline._vertices.append([pt.x, pt.y]) |
|
79 |
self.imageViewer.scene.addItem(self._polyline) |
|
80 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
81 |
else: |
|
82 |
try: |
|
83 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
84 |
self._polyline._vertices.append(self._polyline._pt) |
|
85 |
self._polyline.update() |
|
86 |
finally: |
|
87 |
pass |
|
88 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
89 |
self.onSuccess.emit() |
|
90 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
91 | 91 |
self.onRejected.emit(self) |
92 |
self.isTreated = False |
|
93 |
elif event.key() == Qt.Key_A: # axis lock mode |
|
94 |
self._polyline.drawing_mode = QEngineeringPolylineItem.AXIS_MODE |
|
95 |
elif event.key() == Qt.Key_F: # free drawing mode |
|
96 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
92 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
93 |
self._polyline.onMouseMoved(event, param[2]) |
|
94 |
elif 'keyPressEvent' == param[0]: |
|
95 |
if event.key() == Qt.Key_Escape: |
|
96 |
self.onRejected.emit(self) |
|
97 |
self.isTreated = False |
|
98 |
elif event.key() == Qt.Key_A: # axis lock mode |
|
99 |
self._polyline.drawing_mode = QEngineeringPolylineItem.AXIS_MODE |
|
100 |
elif event.key() == Qt.Key_F: # free drawing mode |
|
101 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
102 |
except Exception as ex: |
|
103 |
from App import App |
|
104 |
from AppDocData import MessageType |
|
105 |
|
|
106 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
107 |
sys.exc_info()[-1].tb_lineno) |
|
108 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
97 | 109 |
|
98 | 110 |
def undo(self): |
99 | 111 |
pass |
100 | 112 |
|
101 | 113 |
def redo(self): |
102 |
pass |
|
114 |
pass |
DTI_PID/DTI_PID/Commands/PlacePolygonCommand.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 | 2 |
import os.path |
3 |
import sys |
|
3 | 4 |
import AbstractCommand |
5 |
|
|
4 | 6 |
try: |
5 | 7 |
from PyQt5.QtCore import * |
6 | 8 |
from PyQt5.QtGui import * |
... | ... | |
12 | 14 |
except ImportError: |
13 | 15 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
14 | 16 |
|
17 |
|
|
15 | 18 |
class PlacePolygonCommand(AbstractCommand.AbstractCommand): |
16 |
""" |
|
17 |
This is place polygon class |
|
18 |
""" |
|
19 |
"""This is place polygon class""" |
|
19 | 20 |
|
20 | 21 |
onSuccess = pyqtSignal() |
21 | 22 |
onRejected = pyqtSignal(AbstractCommand.AbstractCommand) |
22 | 23 |
|
23 | 24 |
def __init__(self, imageViewer): |
24 | 25 |
super(PlacePolygonCommand, self).__init__(imageViewer) |
25 |
self.name = 'PlaceLine'
|
|
26 |
self.name = 'PlaceLine' |
|
26 | 27 |
self.imageViewer.setCursor(QCursor(Qt.CrossCursor)) |
27 | 28 |
|
28 | 29 |
self._polyline = None |
29 |
|
|
30 |
|
|
30 | 31 |
''' |
31 | 32 |
@brief reset command status |
32 | 33 |
@author humkyung |
33 | 34 |
@date 2018.07.23 |
34 | 35 |
''' |
36 |
|
|
35 | 37 |
def reset(self): |
36 | 38 |
self._polyline = None |
37 | 39 |
|
... | ... | |
40 | 42 |
@author humkyung |
41 | 43 |
@date 2018.07.23 |
42 | 44 |
''' |
45 |
|
|
43 | 46 |
def execute(self, param): |
44 | 47 |
import shapely |
45 | 48 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
... | ... | |
49 | 52 |
self.isTreated = False |
50 | 53 |
|
51 | 54 |
event = param[1] |
52 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
53 |
try: |
|
54 |
if self._polyline is None: |
|
55 |
self._polyline = QEngineeringPolylineItem() |
|
56 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
57 |
self._polyline._vertices.append((param[2].x(), param[2].y())) |
|
58 |
self.imageViewer.scene.addItem(self._polyline) |
|
59 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
60 |
else: |
|
61 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
62 |
self._polyline._vertices.append(self._polyline._pt) |
|
63 |
self._polyline.update() |
|
64 |
finally: |
|
65 |
pass |
|
66 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
67 |
self.onSuccess.emit() |
|
68 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
69 |
self.onRejected.emit(self) |
|
70 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
71 |
self._polyline.onMouseMoved(event, param[2]) |
|
72 |
elif 'keyPressEvent' == param[0]: |
|
73 |
if event.key() == Qt.Key_Escape: |
|
55 |
try: |
|
56 |
if 'mousePressEvent' == param[0] and event.button() == Qt.LeftButton: |
|
57 |
try: |
|
58 |
if self._polyline is None: |
|
59 |
self._polyline = QEngineeringPolylineItem() |
|
60 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
61 |
self._polyline._vertices.append((param[2].x(), param[2].y())) |
|
62 |
self.imageViewer.scene.addItem(self._polyline) |
|
63 |
self.imageViewer.scene.setFocusItem(self._polyline) |
|
64 |
else: |
|
65 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
66 |
|
|
67 |
dx = param[2].x() - self._polyline._vertices[-1][0] |
|
68 |
dy = param[2].y() - self._polyline._vertices[-1][1] |
|
69 |
modifiers = QApplication.keyboardModifiers() |
|
70 |
if modifiers == Qt.ShiftModifier: |
|
71 |
if abs(dx) > abs(dy): |
|
72 |
dy = 0 |
|
73 |
else: |
|
74 |
dx = 0 |
|
75 |
|
|
76 |
self._polyline._vertices.append((self._polyline._vertices[-1][0] + dx, |
|
77 |
self._polyline._vertices[-1][1] + dy)) |
|
78 |
self._polyline.update() |
|
79 |
finally: |
|
80 |
pass |
|
81 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is not None: |
|
82 |
self.onSuccess.emit() |
|
83 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.RightButton and self._polyline is None: |
|
74 | 84 |
self.onRejected.emit(self) |
75 |
self.isTreated = False |
|
85 |
elif 'mouseMoveEvent' == param[0] and self._polyline is not None: |
|
86 |
modifiers = QApplication.keyboardModifiers() |
|
87 |
if modifiers == Qt.ShiftModifier: |
|
88 |
self._polyline.drawing_mode = QEngineeringPolylineItem.AXIS_MODE |
|
89 |
else: |
|
90 |
self._polyline.drawing_mode = QEngineeringPolylineItem.FREE_MODE |
|
91 |
|
|
92 |
self._polyline.onMouseMoved(event, param[2]) |
|
93 |
elif 'keyPressEvent' == param[0]: |
|
94 |
if event.key() == Qt.Key_Escape: |
|
95 |
self.onRejected.emit(self) |
|
96 |
self.isTreated = False |
|
97 |
except Exception as ex: |
|
98 |
from App import App |
|
99 |
from AppDocData import MessageType |
|
100 |
|
|
101 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
102 |
sys.exc_info()[-1].tb_lineno) |
|
103 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
76 | 104 |
|
77 | 105 |
def undo(self): |
78 | 106 |
pass |
79 | 107 |
|
80 | 108 |
def redo(self): |
81 |
pass |
|
109 |
pass |
DTI_PID/DTI_PID/ConfigurationDialog.py | ||
---|---|---|
14 | 14 |
import Configuration_UI |
15 | 15 |
import tesseract_ocr_module as TOCR |
16 | 16 |
|
17 |
|
|
17 | 18 |
class ListView(QListView): |
18 | 19 |
def __init__(self, *args, **kwargs): |
19 | 20 |
super(ListView, self).__init__(*args, **kwargs) |
20 | 21 |
|
22 |
|
|
21 | 23 |
class QConfigurationDialog(QDialog): |
22 | 24 |
""" |
23 | 25 |
@history humkyung 2018.05.05 read configuration for instrument and opc tag no rule |
... | ... | |
29 | 31 |
humkyung 2018.06.29 add line type table |
30 | 32 |
kyouho 2018.07.04 add self.delimiter = '"' |
31 | 33 |
""" |
34 |
|
|
32 | 35 |
def __init__(self, parent): |
33 | 36 |
from LineTypeConditions import LineTypeConditions |
34 | 37 |
|
... | ... | |
59 | 62 |
self.ui.comboBoxOCRData.selectedIndex = 0 |
60 | 63 |
|
61 | 64 |
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) |
|
65 |
self.ui.spinBoxExpandSize.setValue(int(configs[0].value)) if 1 == len( |
|
66 |
configs) else self.ui.spinBoxExpandSize.setValue(10) |
|
63 | 67 |
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) |
|
68 |
self.ui.spinBoxShrinkSize.setValue(int(configs[0].value)) if 1 == len( |
|
69 |
configs) else self.ui.spinBoxShrinkSize.setValue(0) |
|
65 | 70 |
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) |
|
71 |
self.ui.spinBoxMergeSize.setValue(int(configs[0].value)) if 1 == len( |
|
72 |
configs) else self.ui.spinBoxMergeSize.setValue(10) |
|
67 | 73 |
configs = docData.getConfigs('Text Recognition', 'White Character List') |
68 | 74 |
self.ui.lineEditWhiteCharList.setText(configs[0].value) if 1 == len(configs) else self.ui.lineEditWhiteCharList.setText(TOCR.DEFAULT_CONF[40:]) |
69 | 75 |
configs = docData.getConfigs('Text Recognition', 'White Single Text') |
70 | 76 |
self.ui.lineEditSingleText.setText(configs[0].value) if 1 == len(configs) else self.ui.lineEditSingleText.setText('H,L') |
71 | 77 |
|
72 |
|
|
73 | 78 |
configs = docData.getConfigs('Text Size', 'Min Text Size') |
74 |
self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
79 |
self.ui.minTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len( |
|
80 |
configs) else self.ui.minTextSizeSpinBox.setValue(30) |
|
75 | 81 |
configs = docData.getConfigs('Text Size', 'Max Text Size') |
76 |
self.ui.maxTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
82 |
self.ui.maxTextSizeSpinBox.setValue(int(configs[0].value)) if 1 == len( |
|
83 |
configs) else self.ui.maxTextSizeSpinBox.setValue(60) |
|
77 | 84 |
|
78 | 85 |
configs = docData.getConfigs('Size', 'Delimiter') |
79 | 86 |
self.ui.lineEditSizeDelimiter.setText(configs[0].value if 1 == len(configs) else 'X') |
80 | 87 |
configs = docData.getConfigs('Range', 'Detection Ratio') |
81 |
self.ui.doubleSpinBoxDetectionRange.setValue(float(configs[0].value)) if 1 == len(configs) else self.ui.doubleSpinBoxDetectionRange.setValue(2.5) |
|
88 |
self.ui.doubleSpinBoxDetectionRange.setValue(float(configs[0].value)) if 1 == len( |
|
89 |
configs) else self.ui.doubleSpinBoxDetectionRange.setValue(2.5) |
|
82 | 90 |
configs = docData.getConfigs('Flow Mark', 'Position') |
83 |
self.ui.spinBoxFlowMarkPosition.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlowMarkPosition.setValue(100) |
|
91 |
self.ui.spinBoxFlowMarkPosition.setValue(int(configs[0].value)) if 1 == len( |
|
92 |
configs) else self.ui.spinBoxFlowMarkPosition.setValue(100) |
|
84 | 93 |
configs = docData.getConfigs('Flow Mark', 'Length') |
85 |
self.ui.spinBoxFlowMarkLength.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlowMarkLength.setValue(200) |
|
94 |
self.ui.spinBoxFlowMarkLength.setValue(int(configs[0].value)) if 1 == len( |
|
95 |
configs) else self.ui.spinBoxFlowMarkLength.setValue(200) |
|
86 | 96 |
|
87 | 97 |
configs = docData.getConfigs('Filter', 'MinimumSize') |
88 |
self.ui.spinBoxMinimumSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMinimumSize.setValue(30) |
|
98 |
self.ui.spinBoxMinimumSize.setValue(int(configs[0].value)) if 1 == len( |
|
99 |
configs) else self.ui.spinBoxMinimumSize.setValue(30) |
|
89 | 100 |
configs = docData.getConfigs('Filter', 'ErodeSize') |
90 |
self.ui.spinBoxUnrecognitionIgnoreStep.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxUnrecognitionIgnoreStep.setValue(3) |
|
101 |
self.ui.spinBoxUnrecognitionIgnoreStep.setValue(int(configs[0].value)) if 1 == len( |
|
102 |
configs) else self.ui.spinBoxUnrecognitionIgnoreStep.setValue(3) |
|
91 | 103 |
configs = docData.getConfigs('Filter', 'DilateSize') |
92 |
self.ui.spinBoxDilateSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxDilateSize.setValue(0) |
|
104 |
self.ui.spinBoxDilateSize.setValue(int(configs[0].value)) if 1 == len( |
|
105 |
configs) else self.ui.spinBoxDilateSize.setValue(0) |
|
93 | 106 |
configs = docData.getConfigs('Filter', 'FlatSize') |
94 |
self.ui.spinBoxFlatSize.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxFlatSize.setValue(0) |
|
107 |
self.ui.spinBoxFlatSize.setValue(int(configs[0].value)) if 1 == len( |
|
108 |
configs) else self.ui.spinBoxFlatSize.setValue(0) |
|
95 | 109 |
|
96 | 110 |
# set min,max area for small object |
97 | 111 |
configs = docData.getConfigs('Small Object Size', 'Min Area') |
98 |
self.ui.spinBoxMinArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMinArea.setValue(20) |
|
112 |
self.ui.spinBoxMinArea.setValue(int(configs[0].value)) if 1 == len( |
|
113 |
configs) else self.ui.spinBoxMinArea.setValue(20) |
|
99 | 114 |
configs = docData.getConfigs('Small Object Size', 'Max Area') |
100 |
self.ui.spinBoxMaxArea.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxMaxArea.setValue(50) |
|
115 |
self.ui.spinBoxMaxArea.setValue(int(configs[0].value)) if 1 == len( |
|
116 |
configs) else self.ui.spinBoxMaxArea.setValue(50) |
|
101 | 117 |
# up to here |
102 | 118 |
|
103 | 119 |
windowSize = docData.getSlidingWindowSize() |
... | ... | |
105 | 121 |
self.ui.spinBoxHeight.setValue(windowSize[1]) |
106 | 122 |
|
107 | 123 |
configs = docData.getConfigs('Small Line Minimum Length', 'Min Length') |
108 |
self.ui.smallLineMinLengthSpinBox.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.smallLineMinLengthSpinBox.setValue(25) |
|
124 |
self.ui.smallLineMinLengthSpinBox.setValue(int(configs[0].value)) if 1 == len( |
|
125 |
configs) else self.ui.smallLineMinLengthSpinBox.setValue(25) |
|
109 | 126 |
configs = docData.getConfigs('Line Detector', 'Length to connect line') |
110 |
if configs: self.ui.spinBoxLengthToConnectLine.setValue(int(configs[0].value)) if 1 == len(configs) else self.ui.spinBoxLengthToConnectLine.setValue(20) |
|
111 |
|
|
127 |
if configs: self.ui.spinBoxLengthToConnectLine.setValue(int(configs[0].value)) if 1 == len( |
|
128 |
configs) else self.ui.spinBoxLengthToConnectLine.setValue(20) |
|
129 |
|
|
112 | 130 |
configs = docData.getConfigs('Line', 'Default Type') |
113 | 131 |
for lineType in LineTypeConditions.items(): |
114 | 132 |
self.ui.comboBoxLineType.addItem(lineType.name) |
... | ... | |
144 | 162 |
if prop.AttributeType == "Code Table": |
145 | 163 |
self.tempLineColorUID.append(prop.Attribute) |
146 | 164 |
self.ui.comboBoxColorOption.addItem(prop.DisplayAttribute) |
147 |
|
|
165 |
|
|
148 | 166 |
self.load_line_properties() |
149 | 167 |
|
150 | 168 |
# line no setting (line no, size unit, delimiter) |
... | ... | |
162 | 180 |
for value in lineNo.split(self.delimiter): |
163 | 181 |
lineProp = docData.getLinePropertiesByUID(value) |
164 | 182 |
if lineProp: |
165 |
displayLineNo = displayLineNo + lineProp[0].DisplayAttribute
|
|
183 |
displayLineNo = displayLineNo + lineProp[0].DisplayAttribute |
|
166 | 184 |
else: |
167 |
displayLineNo = displayLineNo + value
|
|
185 |
displayLineNo = displayLineNo + value |
|
168 | 186 |
|
169 | 187 |
item = QListWidgetItem(displayLineNo) |
170 | 188 |
item.tag = [sizeUnit[index], lineNo, lineInsideDelimiter[index]] |
... | ... | |
185 | 203 |
self.ui.lineEditOPCToPrefix.setText(configs[0].value if configs else '') |
186 | 204 |
configs = docData.getConfigs('Supplied by Tag Rule', 'by Vendor') |
187 | 205 |
self.ui.lineEditByVendor.setText(configs[0].value if configs else 'by Vendor') |
188 |
self.ui.lineEditDrainSize.setText(docData.drain_size) # 2019.05.20 added by humkyung
|
|
206 |
self.ui.lineEditDrainSize.setText(docData.drain_size) # 2019.05.20 added by humkyung |
|
189 | 207 |
|
190 | 208 |
configs = docData.getConfigs('LineTypes') |
191 | 209 |
|
192 | 210 |
line_type_conditions = LineTypeConditions.items() |
193 | 211 |
self.ui.tableWidgetLineTypes.setColumnCount(6) |
194 |
self.ui.tableWidgetLineTypes.setHorizontalHeaderLabels([self.tr('Name'), self.tr('Color'), self.tr('Width'), self.tr('Style'), self.tr('Opacity'), self.tr('Conditions')]) |
|
212 |
self.ui.tableWidgetLineTypes.setHorizontalHeaderLabels( |
|
213 |
[self.tr('Name'), self.tr('Color'), self.tr('Width'), self.tr('Style'), self.tr('Opacity'), |
|
214 |
self.tr('Conditions')]) |
|
195 | 215 |
self.ui.tableWidgetLineTypes.setRowCount(len(line_type_conditions)) |
196 | 216 |
row = 0 |
197 | 217 |
for _condition in line_type_conditions: |
... | ... | |
225 | 245 |
|
226 | 246 |
""" line style """ |
227 | 247 |
lineStyleComboBox = QComboBox() |
228 |
lineStyleComboBox.addItems(['SolidLine', 'DashLine', 'DotLine', 'DashDotLine', 'DashDotDotLine', 'CustomDashLine']) |
|
248 |
lineStyleComboBox.addItems( |
|
249 |
['SolidLine', 'DashLine', 'DotLine', 'DashDotLine', 'DashDotDotLine', 'CustomDashLine']) |
|
229 | 250 |
if matches: |
230 | 251 |
tokens = matches[0].value.split(',') |
231 | 252 |
lineStyleComboBox.setCurrentText(tokens[2] if len(tokens) == 4 else tokens[1]) |
232 | 253 |
else: |
233 | 254 |
lineStyleComboBox.setCurrentText('SolidLine') |
234 |
lineStyleComboBox.setCurrentText(matches[0].value.split(',')[1]) if matches else lineStyleComboBox.setCurrentText('SolidLine') |
|
255 |
lineStyleComboBox.setCurrentText( |
|
256 |
matches[0].value.split(',')[1]) if matches else lineStyleComboBox.setCurrentText('SolidLine') |
|
235 | 257 |
self.ui.tableWidgetLineTypes.setCellWidget(row, 3, lineStyleComboBox) |
236 | 258 |
|
237 | 259 |
""" line transparent """ |
... | ... | |
259 | 281 |
self.ui.tableWidgetLineTypes.horizontalHeader().setStretchLastSection(True) |
260 | 282 |
|
261 | 283 |
configs = docData.getConfigs('Instrument', 'Color') |
262 |
self.ui.pushButtonInstrumentColor.setStyleSheet('background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
|
284 |
self.ui.pushButtonInstrumentColor.setStyleSheet( |
|
285 |
'background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
|
263 | 286 |
configs = docData.getConfigs('Equipment', 'Color') |
264 |
self.ui.pushButtonEquipColor.setStyleSheet('background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
|
287 |
self.ui.pushButtonEquipColor.setStyleSheet( |
|
288 |
'background-color:{}'.format(configs[0].value if configs else QEngineeringAbstractItem.DEFAULT_COLOR)) |
|
265 | 289 |
configs = docData.getConfigs('Symbol Style', 'Opacity') |
266 | 290 |
self.ui.spinBoxSymbolOpacity.setValue(int(configs[0].value) if configs else 50) |
267 | 291 |
|
... | ... | |
281 | 305 |
self.ui.radioButtonFixedSize.setChecked(False) |
282 | 306 |
self.ui.spinBoxFontSize.setValue(10) |
283 | 307 |
self.ui.spinBoxFontSize.setEnabled(self.ui.radioButtonFixedSize.isChecked()) |
284 |
|
|
308 |
|
|
285 | 309 |
# Line Color Visible Option 가져옴 |
286 | 310 |
configs = docData.getConfigs('Line Color', 'Visible Option') |
287 | 311 |
if configs: |
... | ... | |
291 | 315 |
else: |
292 | 316 |
self.ui.radioButtonRandom.setChecked(True) |
293 | 317 |
self.ui.radioButtonProperty.setChecked(False) |
294 |
|
|
318 |
|
|
295 | 319 |
# Color Property 선택값 가져옴 |
296 | 320 |
self.ui.tableWidgetColorProperty.setHorizontalHeaderLabels(['Value', 'Color', 'ref', 'colorStr']) |
297 | 321 |
table = self.ui.tableWidgetColorProperty |
... | ... | |
300 | 324 |
if configs: |
301 | 325 |
uid = configs[0].value |
302 | 326 |
lineProp = docData.getLinePropertiesByUID(uid) |
303 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText(lineProp[0].DisplayAttribute) >= 0 else '' |
|
304 |
|
|
327 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText( |
|
328 |
lineProp[0].DisplayAttribute) >= 0 else '' |
|
329 |
|
|
305 | 330 |
index = self.ui.comboBoxColorOption.findText(selectedOption) |
306 | 331 |
self.ui.comboBoxColorOption.setCurrentIndex(index) |
307 | 332 |
self.currentIndex = index |
308 | 333 |
|
309 | 334 |
table.hideColumn(2) |
310 | 335 |
table.hideColumn(3) |
311 |
#Column Header Size |
|
336 |
# Column Header Size
|
|
312 | 337 |
self.ui.tableWidgetColorProperty.horizontalHeaderItem(0).setSizeHint(QSize(30, 30)) |
313 | 338 |
self.setPropertyToggle(self.ui.radioButtonProperty.isChecked()) |
314 | 339 |
|
... | ... | |
345 | 370 |
self.ui.pushButtonClearAccessInfo.clicked.connect(self.clear_drawing_access_info_clicked) |
346 | 371 |
|
347 | 372 |
def clear_drawing_access_info_clicked(self): |
348 |
reply = QMessageBox.question(self, self.tr('Continue?'), self.tr('Are you sure you want to clear drawing access information?'), QMessageBox.Yes, QMessageBox.Cancel) |
|
373 |
reply = QMessageBox.question(self, self.tr('Continue?'), |
|
374 |
self.tr('Are you sure you want to clear drawing access information?'), |
|
375 |
QMessageBox.Yes, QMessageBox.Cancel) |
|
349 | 376 |
if reply == QMessageBox.Yes: |
350 | 377 |
AppDocData.instance().clear_occupying_drawing(None) |
351 | 378 |
QMessageBox.information(self, self.tr('Information'), self.tr('Succeeded')) |
... | ... | |
380 | 407 |
if prop.AttributeType == 'Code Table': |
381 | 408 |
self.tempLineColorUID.append(prop.Attribute) |
382 | 409 |
self.ui.comboBoxColorOption.addItem(prop.DisplayAttribute) |
383 |
|
|
384 | 410 |
|
385 | 411 |
configs = app_doc_data.getConfigs('Color Property', 'State') |
386 | 412 |
if configs: |
387 | 413 |
uid = configs[0].value |
388 | 414 |
lineProp = app_doc_data.getLinePropertiesByUID(uid) |
389 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText(lineProp[0].DisplayAttribute) >= 0 else '' |
|
390 |
|
|
415 |
selectedOption = lineProp[0].DisplayAttribute if lineProp and self.ui.comboBoxColorOption.findText( |
|
416 |
lineProp[0].DisplayAttribute) >= 0 else '' |
|
417 |
|
|
391 | 418 |
index = self.ui.comboBoxColorOption.findText(selectedOption) |
392 | 419 |
self.ui.comboBoxColorOption.setCurrentIndex(index) |
393 | 420 |
self.currentIndex = index |
... | ... | |
404 | 431 |
from App import App |
405 | 432 |
from AppDocData import MessageType |
406 | 433 |
|
407 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
434 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
435 |
sys.exc_info()[-1].tb_lineno) |
|
408 | 436 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
409 | 437 |
|
410 | 438 |
''' |
... | ... | |
412 | 440 |
@author kyouho |
413 | 441 |
@date 2018.07.10 |
414 | 442 |
''' |
443 |
|
|
415 | 444 |
def clearColorPropertyTable(self): |
416 | 445 |
table = self.ui.tableWidgetColorProperty |
417 | 446 |
model = table.model() |
... | ... | |
424 | 453 |
@author kyouho |
425 | 454 |
@date 2018.07.09 |
426 | 455 |
''' |
456 |
|
|
427 | 457 |
def settingDefaultColorTable(self, property): |
428 | 458 |
docData = AppDocData.instance() |
429 | 459 |
table = self.ui.tableWidgetColorProperty |
... | ... | |
437 | 467 |
else: |
438 | 468 |
return |
439 | 469 |
|
440 |
if tableName.replace(' ','') == "NominalDiameter": |
|
441 |
#중복 체크 배열 |
|
470 |
if tableName.replace(' ', '') == "NominalDiameter":
|
|
471 |
# 중복 체크 배열
|
|
442 | 472 |
checkRepeat = [] |
443 | 473 |
# Size 표기 가져옴 |
444 | 474 |
configs = docData.getConfigs('Line No', 'Size Unit') |
445 | 475 |
# Size 관련 Table 가져옴 |
446 | 476 |
result = docData.getNomialPipeSizeData(False, "Metric") |
447 |
|
|
477 |
|
|
448 | 478 |
for pipeSize in result: |
449 | 479 |
if not pipeSize.inchStr or not pipeSize.metricStr: |
450 | 480 |
continue |
... | ... | |
481 | 511 |
@author kyouho |
482 | 512 |
@date 2018.07.09 |
483 | 513 |
''' |
514 |
|
|
484 | 515 |
def settingColorStringCell(self, property): |
485 | 516 |
docData = AppDocData.instance() |
486 | 517 |
table = self.ui.tableWidgetColorProperty |
487 | 518 |
rowCount = table.rowCount() |
488 | 519 |
for j in range(rowCount): |
489 | 520 |
ref = table.item(j, 2) |
490 |
|
|
521 |
|
|
491 | 522 |
configs = docData.getConfigs(property, ref.text()) |
492 | 523 |
if configs: |
493 | 524 |
colorStr = table.item(j, 3) |
... | ... | |
498 | 529 |
@author kyouho |
499 | 530 |
@date 2018.07.09 |
500 | 531 |
''' |
532 |
|
|
501 | 533 |
def settingColorCell(self): |
502 | 534 |
table = self.ui.tableWidgetColorProperty |
503 | 535 |
rowCount = table.rowCount() |
504 |
|
|
536 |
|
|
505 | 537 |
for i in range(rowCount): |
506 | 538 |
colorCell = table.item(i, 1) |
507 | 539 |
colorDataCell = table.item(i, 3) |
... | ... | |
516 | 548 |
colorCell.setBackground(QColor(int(r), int(g), int(b))) |
517 | 549 |
else: |
518 | 550 |
colorCell.setBackground(QColor(self.defaultColor.red, self.defaultColor.green, self.defaultColor.blue)) |
519 |
|
|
551 |
|
|
520 | 552 |
''' |
521 | 553 |
@brief Cell Double Click Event |
522 | 554 |
@author kyouho |
523 | 555 |
@date 2018.07.09 |
524 | 556 |
''' |
557 |
|
|
525 | 558 |
def currentIndexChanged(self, index): |
526 | 559 |
if self.currentIndex != index and index is not -1: |
527 | 560 |
self.currentIndex = index |
528 | 561 |
|
529 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
|
562 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex() |
|
530 | 563 |
name = self.tempLineColorUID[selectedIndex] |
531 | 564 |
|
532 | 565 |
docData = AppDocData.instance() |
533 | 566 |
lineProp = [prop for prop in docData.getLineProperties() if prop.Attribute == name] |
534 |
|
|
567 |
|
|
535 | 568 |
if lineProp: |
536 | 569 |
# 기본 테이블 셋팅 |
537 | 570 |
self.settingDefaultColorTable(lineProp[0].UID) |
538 | 571 |
# 설정된 색상 가져옴 |
539 | 572 |
self.settingColorStringCell(lineProp[0].UID) |
540 | 573 |
|
541 |
#Table Color Setting |
|
574 |
# Table Color Setting
|
|
542 | 575 |
self.settingColorCell() |
543 | 576 |
|
544 | 577 |
def change_instrument_color(self): |
... | ... | |
573 | 606 |
from App import App |
574 | 607 |
from AppDocData import MessageType |
575 | 608 |
|
576 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
609 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
610 |
sys.exc_info()[-1].tb_lineno) |
|
577 | 611 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
578 | 612 |
|
579 | 613 |
''' |
... | ... | |
581 | 615 |
@author kyouho |
582 | 616 |
@date 2018.07.09 |
583 | 617 |
''' |
618 |
|
|
584 | 619 |
def cellDoubleClick(self, row, column): |
585 | 620 |
if column == 1: |
586 | 621 |
color = QColorDialog.getColor(self.ui.tableWidgetColorProperty.item(row, column).background().color()) |
587 | 622 |
if color.isValid(): |
588 |
self.ui.tableWidgetColorProperty.setItem(row, 3, QTableWidgetItem(str(color.red()) + ',' + str(color.green()) + ',' + str(color.blue()))) |
|
589 |
#Table Color Setting |
|
623 |
self.ui.tableWidgetColorProperty.setItem(row, 3, QTableWidgetItem( |
|
624 |
str(color.red()) + ',' + str(color.green()) + ',' + str(color.blue()))) |
|
625 |
# Table Color Setting |
|
590 | 626 |
self.settingColorCell() |
591 | 627 |
|
592 | 628 |
''' |
... | ... | |
594 | 630 |
@author humkyung |
595 | 631 |
@date 2018.04.09 |
596 | 632 |
''' |
633 |
|
|
597 | 634 |
def addLineProperty(self): |
598 | 635 |
from ConfigurationLineNoDialog import QConfigurationLineNoDialog |
599 | 636 |
|
... | ... | |
608 | 645 |
@author humkyung |
609 | 646 |
@date 2018.06.30 |
610 | 647 |
''' |
648 |
|
|
611 | 649 |
def onFixedSizeToggled(self, radioButton): |
612 | 650 |
self.ui.spinBoxFontSize.setEnabled(self.ui.radioButtonFixedSize.isChecked()) |
613 | 651 |
|
... | ... | |
616 | 654 |
@author kyouho |
617 | 655 |
@date 2018.07.10 |
618 | 656 |
''' |
657 |
|
|
619 | 658 |
def onPropertyToggled(self, radioButton): |
620 | 659 |
self.setPropertyToggle(self.ui.radioButtonProperty.isChecked()) |
660 |
|
|
621 | 661 |
''' |
622 | 662 |
@brief enable/disable font size spinbox |
623 | 663 |
@author kyouho |
624 | 664 |
@date 2018.07.10 |
625 | 665 |
''' |
666 |
|
|
626 | 667 |
def setPropertyToggle(self, enable): |
627 | 668 |
try: |
628 | 669 |
if enable: |
629 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
|
670 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex() |
|
630 | 671 |
name = self.tempLineColorUID[selectedIndex] |
631 | 672 |
|
632 | 673 |
docData = AppDocData.instance() |
... | ... | |
636 | 677 |
self.settingDefaultColorTable(lineProp[0].UID) |
637 | 678 |
# 설정된 색상 가져옴 |
638 | 679 |
self.settingColorStringCell(lineProp[0].UID) |
639 |
#Table Color Setting |
|
680 |
# Table Color Setting
|
|
640 | 681 |
self.settingColorCell() |
641 | 682 |
else: |
642 | 683 |
self.clearColorPropertyTable() |
... | ... | |
646 | 687 |
from App import App |
647 | 688 |
from AppDocData import MessageType |
648 | 689 |
|
649 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
690 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
691 |
sys.exc_info()[-1].tb_lineno) |
|
650 | 692 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
651 | 693 |
finally: |
652 | 694 |
self.ui.tableWidgetColorProperty.resizeColumnsToContents() |
... | ... | |
667 | 709 |
humkyung 2018.06.20 save Expand and Shrink size for recognizing text |
668 | 710 |
kyouho 2018.07.04 edit cofiguration new delimiter (self.delimiter) |
669 | 711 |
''' |
712 |
|
|
670 | 713 |
def accept(self): |
671 | 714 |
from NominalPipeSize import NominalPipeSizeTable |
672 | 715 |
from LineTypeConditions import LineTypeConditions |
... | ... | |
684 | 727 |
configs.append(Config('Text Recognition', 'Expand Size', self.ui.spinBoxExpandSize.value())) |
685 | 728 |
configs.append(Config('Text Recognition', 'Shrink Size', self.ui.spinBoxShrinkSize.value())) |
686 | 729 |
configs.append(Config('Text Recognition', 'Merge Size', self.ui.spinBoxMergeSize.value())) |
687 |
|
|
730 |
|
|
688 | 731 |
configs.append(Config('Text Size', 'Min Text Size', self.ui.minTextSizeSpinBox.value())) |
689 | 732 |
configs.append(Config('Text Size', 'Max Text Size', self.ui.maxTextSizeSpinBox.value())) |
690 |
|
|
733 |
|
|
691 | 734 |
configs.append(Config('Size', 'Delimiter', self.ui.lineEditSizeDelimiter.text())) |
692 | 735 |
configs.append(Config('Range', 'Detection Ratio', self.ui.doubleSpinBoxDetectionRange.value())) |
693 | 736 |
configs.append(Config('Flow Mark', 'Position', self.ui.spinBoxFlowMarkPosition.value())) |
... | ... | |
701 | 744 |
configs.append(Config('Sliding Window', 'Width', self.ui.spinBoxWidth.value())) |
702 | 745 |
configs.append(Config('Sliding Window', 'Height', self.ui.spinBoxHeight.value())) |
703 | 746 |
configs.append(Config('Small Line Minimum Length', 'Min Length', self.ui.smallLineMinLengthSpinBox.value())) |
704 |
configs.append(Config('Line Detector', 'Length to connect line', self.ui.spinBoxLengthToConnectLine.value())) |
|
747 |
configs.append( |
|
748 |
Config('Line Detector', 'Length to connect line', self.ui.spinBoxLengthToConnectLine.value())) |
|
705 | 749 |
configs.append(Config('Line', 'Default Type', self.ui.comboBoxLineType.currentText())) |
706 | 750 |
configs.append(Config('Line', 'Diagonal', '1' if self.ui.radioButtonDiagonalYes.isChecked() else '-1')) |
707 | 751 |
configs.append(Config('Text', 'Background', '1' if self.ui.radioButtonBackTextYes.isChecked() else '-1')) |
... | ... | |
714 | 758 |
configs.append(Config('Drain Size Rule', 'Size', docData.drain_size)) |
715 | 759 |
configs.append(Config('Text Recognition', 'White Character List', self.ui.lineEditWhiteCharList.text())) |
716 | 760 |
configs.append(Config('Text Recognition', 'White Single Text', self.ui.lineEditSingleText.text())) |
717 |
|
|
718 | 761 |
# Add Line Color Option - 2018.07.06 by kyouho |
719 | 762 |
rbRandomValue = self.ui.radioButtonRandom.isChecked() |
720 | 763 |
|
... | ... | |
723 | 766 |
color = self.ui.tableWidgetLineTypes.item(row, 1).background().color().name() |
724 | 767 |
width = self.ui.tableWidgetLineTypes.cellWidget(row, 2).text() |
725 | 768 |
style = self.ui.tableWidgetLineTypes.cellWidget(row, 3).currentText() |
726 |
transparent = self.ui.tableWidgetLineTypes.cellWidget(row, 4).text()
|
|
727 |
configs.append(Config('LineTypes', lineType, '{},{},{},{}'.format(color, width, style,transparent))) |
|
769 |
transparent = self.ui.tableWidgetLineTypes.cellWidget(row, 4).text() |
|
770 |
configs.append(Config('LineTypes', lineType, '{},{},{},{}'.format(color, width, style, transparent)))
|
|
728 | 771 |
""" add line type condition to configs """ |
729 | 772 |
data = self.ui.tableWidgetLineTypes.item(row, 0).data(Qt.UserRole) |
730 | 773 |
configs.append(data) |
731 |
|
|
774 |
|
|
732 | 775 |
docData = AppDocData.instance() |
733 |
|
|
734 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex()
|
|
776 |
|
|
777 |
selectedIndex = self.ui.comboBoxColorOption.currentIndex() |
|
735 | 778 |
name = self.tempLineColorUID[selectedIndex] |
736 | 779 |
lineProp = [prop for prop in docData.getLineProperties() if prop.Attribute == name] |
737 | 780 |
|
... | ... | |
748 | 791 |
if colorStr: |
749 | 792 |
configs.append(Config(lineProp[0].UID, refStr, colorStr)) |
750 | 793 |
|
751 |
#Configuration |
|
794 |
# Configuration
|
|
752 | 795 |
sizeUnit = None |
753 | 796 |
configuration = None |
754 | 797 |
lineInsideDelimiter = None |
... | ... | |
768 | 811 |
configs.append(Config('Line No', 'Delimiter', lineInsideDelimiter)) |
769 | 812 |
|
770 | 813 |
# save symbol opacity - 2019.04.18 added by humkyung |
771 |
configs.append(Config('Instrument', 'Color', self.ui.pushButtonInstrumentColor.palette().color(QPalette.Background).name())) |
|
814 |
configs.append(Config('Instrument', 'Color', |
|
815 |
self.ui.pushButtonInstrumentColor.palette().color(QPalette.Background).name())) |
|
772 | 816 |
QEngineeringInstrumentItem.INST_COLOR = None |
773 |
configs.append(Config('Equipment', 'Color', self.ui.pushButtonEquipColor.palette().color(QPalette.Background).name())) |
|
817 |
configs.append( |
|
818 |
Config('Equipment', 'Color', self.ui.pushButtonEquipColor.palette().color(QPalette.Background).name())) |
|
774 | 819 |
QEngineeringEquipmentItem.EQUIP_COLOR = None |
775 | 820 |
configs.append(Config('Symbol Style', 'Opacity', str(self.ui.spinBoxSymbolOpacity.value()))) |
776 | 821 |
|
777 | 822 |
font = self.ui.fontComboBox.currentFont() |
778 | 823 |
configs.append(Config('Text Style', 'Font Name', font.family())) |
779 |
configs.append(Config('Text Style', 'Font Size', str(self.ui.spinBoxFontSize.value()) if self.ui.radioButtonFixedSize.isChecked() else '-1')) |
|
824 |
configs.append(Config('Text Style', 'Font Size', str( |
|
825 |
self.ui.spinBoxFontSize.value()) if self.ui.radioButtonFixedSize.isChecked() else '-1')) |
|
780 | 826 |
|
781 | 827 |
configs.append(Config('Data Load', 'Xml First', '1' if self.ui.radioButtonLoadXmlYes.isChecked() else '-1')) |
782 |
configs.append(Config('Data Save', 'Unknown Xml Only', '1' if self.ui.radioButtonSaveUnknownYes.isChecked() else '-1')) |
|
783 |
|
|
828 |
configs.append( |
|
829 |
Config('Data Save', 'Unknown Xml Only', '1' if self.ui.radioButtonSaveUnknownYes.isChecked() else '-1')) |
|
830 |
|
|
784 | 831 |
docData.saveConfigs(configs) |
785 | 832 |
docData.lineTypeConfigs = None # clear line type configurations |
786 |
NominalPipeSizeTable.instance().pipe_sizes = None # clear nominal pipe size table
|
|
833 |
NominalPipeSizeTable.instance().pipe_sizes = None # clear nominal pipe size table |
|
787 | 834 |
|
788 | 835 |
except Exception as ex: |
789 | 836 |
from App import App |
790 | 837 |
from AppDocData import MessageType |
791 | 838 |
|
792 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
839 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
840 |
sys.exc_info()[-1].tb_lineno) |
|
793 | 841 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
794 | 842 |
|
795 | 843 |
QDialog.accept(self) |
... | ... | |
799 | 847 |
@author humkyung |
800 | 848 |
@date 2018.04.09 |
801 | 849 |
''' |
850 |
|
|
802 | 851 |
def removeSelectedItem(self): |
803 | 852 |
selectedIndex = self.ui.listWidgetLineNo.currentRow() |
804 | 853 |
if selectedIndex is not -1: |
... | ... | |
809 | 858 |
@author humkyung |
810 | 859 |
@date 2018.04.09 |
811 | 860 |
''' |
861 |
|
|
812 | 862 |
def keyPressEvent(self, event): |
813 | 863 |
if event.key() == Qt.Key_Delete: |
814 | 864 |
self.removeSelectedItem() |
DTI_PID/DTI_PID/LineDetector.py | ||
---|---|---|
4 | 4 |
import math |
5 | 5 |
import shapely |
6 | 6 |
|
7 |
|
|
7 | 8 |
class LineDetector(): |
8 | 9 |
def __init__(self, image): |
9 | 10 |
try: |
... | ... | |
13 | 14 |
self.height = self._image.shape[::-1][1] if self._image is not None else None |
14 | 15 |
self.Result = np.zeros((self.width, self.height, 3), np.uint8) if self._image is not None else None |
15 | 16 |
except Exception as ex: |
16 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
17 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
18 |
sys.exc_info()[-1].tb_lineno)) |
|
17 | 19 |
|
18 | 20 |
''' |
19 | 21 |
@brief dot product of given two vectors |
20 | 22 |
@author humkyung |
21 | 23 |
@date 2018.04.14 |
22 | 24 |
''' |
25 |
|
|
23 | 26 |
def dotProduct(self, lhs, rhs): |
24 |
return sum([lhs[i]*rhs[i] for i in range(len(lhs))])
|
|
27 |
return sum([lhs[i] * rhs[i] for i in range(len(lhs))])
|
|
25 | 28 |
|
26 | 29 |
''' |
27 | 30 |
@brief get length of given vector |
28 | 31 |
@author humkyung |
29 | 32 |
@date 2018.04.14 |
30 | 33 |
''' |
34 |
|
|
31 | 35 |
def getLength(self, lhs): |
32 | 36 |
return math.sqrt(self.dotProduct(lhs, lhs)) |
33 | 37 |
|
... | ... | |
38 | 42 |
@history 2018.05.29 Jeongwoo Add try-exception |
39 | 43 |
@TODO : Need to modify case - Exception |
40 | 44 |
''' |
45 |
|
|
41 | 46 |
def getAngle(self, lhs, rhs): |
42 | 47 |
try: |
43 | 48 |
return math.acos(self.dotProduct(lhs, rhs) / (self.getLength(lhs) * self.getLength(rhs))) |
44 | 49 |
except Exception as ex: |
45 | 50 |
return sys.float_info.max |
46 |
|
|
51 |
|
|
47 | 52 |
""" |
48 | 53 |
@brief get distance between given two points |
49 | 54 |
@author humkyung |
50 | 55 |
@date 2018.04.13 |
51 | 56 |
""" |
57 |
|
|
52 | 58 |
def distanceTo(self, lhs, rhs): |
53 | 59 |
dx = rhs[0] - lhs[0] |
54 | 60 |
dy = rhs[1] - lhs[1] |
55 |
return math.sqrt(dx*dx + dy*dy)
|
|
61 |
return math.sqrt(dx * dx + dy * dy)
|
|
56 | 62 |
|
57 | 63 |
''' |
58 | 64 |
@brief rotate given point about origin by angle |
59 | 65 |
@author humkyung |
60 | 66 |
@date 2018.04.12 |
61 | 67 |
''' |
68 |
|
|
62 | 69 |
def rotatePoint(self, point, origin, angle): |
63 | 70 |
dx = point[0] - origin[0] |
64 | 71 |
dy = point[1] - origin[1] |
... | ... | |
72 | 79 |
@author humkyung |
73 | 80 |
@date 2018.04.11 |
74 | 81 |
''' |
82 |
|
|
75 | 83 |
def isConnected(self, lhs, rhs, toler=0): |
76 | 84 |
length = [] |
77 | 85 |
|
... | ... | |
79 | 87 |
# check if share one point |
80 | 88 |
dx = (lhs[0][0] - rhs[0][0]) |
81 | 89 |
dy = (lhs[0][1] - rhs[0][1]) |
82 |
length.append(math.sqrt(dx*dx + dy*dy))
|
|
90 |
length.append(math.sqrt(dx * dx + dy * dy))
|
|
83 | 91 |
dx = (lhs[1][0] - rhs[0][0]) |
84 | 92 |
dy = (lhs[1][1] - rhs[0][1]) |
85 |
length.append(math.sqrt(dx*dx + dy*dy))
|
|
93 |
length.append(math.sqrt(dx * dx + dy * dy))
|
|
86 | 94 |
dx = (lhs[0][0] - rhs[1][0]) |
87 | 95 |
dy = (lhs[0][1] - rhs[1][1]) |
88 |
length.append(math.sqrt(dx*dx + dy*dy))
|
|
96 |
length.append(math.sqrt(dx * dx + dy * dy))
|
|
89 | 97 |
dx = (lhs[1][0] - rhs[1][0]) |
90 | 98 |
dy = (lhs[1][1] - rhs[1][1]) |
91 |
length.append(math.sqrt(dx*dx + dy*dy))
|
|
99 |
length.append(math.sqrt(dx * dx + dy * dy))
|
|
92 | 100 |
matches = [len for len in length if len < toler] |
93 | 101 |
# up to here |
94 | 102 |
|
95 | 103 |
return (len(matches) == 1) |
96 | 104 |
except Exception as ex: |
97 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
98 |
|
|
105 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
106 |
sys.exc_info()[-1].tb_lineno)) |
|
107 |
|
|
99 | 108 |
return False |
100 | 109 |
|
101 | 110 |
""" |
... | ... | |
103 | 112 |
@author humkyung |
104 | 113 |
@date 2018.04.11 |
105 | 114 |
""" |
115 |
|
|
106 | 116 |
def isCollinear(self, lhs, rhs, toler): |
107 | 117 |
try: |
108 |
#print(lhs) |
|
109 |
#print(rhs) |
|
118 |
# print(lhs)
|
|
119 |
# print(rhs)
|
|
110 | 120 |
if self.isConnected(lhs, rhs, toler): |
111 | 121 |
dx1 = lhs[1][0] - lhs[0][0] |
112 | 122 |
dy1 = lhs[1][1] - lhs[0][1] |
113 |
length = math.sqrt(dx1*dx1 + dy1*dy1)
|
|
123 |
length = math.sqrt(dx1 * dx1 + dy1 * dy1)
|
|
114 | 124 |
dx1 /= length |
115 | 125 |
dy1 /= length |
116 | 126 |
dx2 = rhs[1][0] - rhs[0][0] |
117 | 127 |
dy2 = rhs[1][1] - rhs[0][1] |
118 |
length = math.sqrt(dx2*dx2 + dy2*dy2)
|
|
128 |
length = math.sqrt(dx2 * dx2 + dy2 * dy2)
|
|
119 | 129 |
dx2 /= length |
120 | 130 |
dy2 /= length |
121 | 131 |
|
122 | 132 |
dx = math.fabs(dx1) - math.fabs(dx2) |
123 | 133 |
dy = math.fabs(dy1) - math.fabs(dy2) |
124 | 134 |
|
125 |
return (math.sqrt(dx*dx + dy*dy) < 0.00001)
|
|
135 |
return (math.sqrt(dx * dx + dy * dy) < 0.00001)
|
|
126 | 136 |
except Exception as ex: |
127 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
137 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
138 |
sys.exc_info()[-1].tb_lineno)) |
|
128 | 139 |
|
129 | 140 |
return False |
130 | 141 |
|
... | ... | |
134 | 145 |
@date 2018.04.11 |
135 | 146 |
@history 2018.05.16 Jeongwoo Connect Lines with long distance points |
136 | 147 |
''' |
148 |
|
|
137 | 149 |
def connectLines(self, lines, toler): |
138 | 150 |
res = [] |
139 | 151 |
|
140 | 152 |
pts = [] |
141 |
#print(lines) |
|
153 |
# print(lines)
|
|
142 | 154 |
maxthickness = 0 |
143 | 155 |
for line in lines: |
144 | 156 |
pts.append(line[0]) |
... | ... | |
158 | 170 |
res.append(lpt) |
159 | 171 |
res.append(rpt) |
160 | 172 |
res.append(maxthickness) |
161 |
#print(res) |
|
173 |
# print(res)
|
|
162 | 174 |
return res |
163 | 175 |
|
164 | 176 |
''' |
... | ... | |
167 | 179 |
@date 2018.06.21 |
168 | 180 |
@history humkyung 2018.07.31 return -1 thickness tuple if near point is not black |
169 | 181 |
''' |
182 |
|
|
170 | 183 |
def adjustStartPoint(self, pt, dir): |
171 | 184 |
from AppDocData import AppDocData |
172 | 185 |
docData = AppDocData.instance() |
... | ... | |
177 | 190 |
black = 0 |
178 | 191 |
|
179 | 192 |
norm = [-dir[1], dir[0]] |
180 |
if black == self._image[pt[1] + round(dir[1]*windowSize[1]), pt[0] + round(dir[0]*windowSize[1])]:
|
|
181 |
_pt = [pt[0] + round(dir[0]*windowSize[1]), pt[1] + round(dir[1]*windowSize[1])]
|
|
193 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1]), pt[0] + round(dir[0] * windowSize[1])]:
|
|
194 |
_pt = [pt[0] + round(dir[0] * windowSize[1]), pt[1] + round(dir[1] * windowSize[1])]
|
|
182 | 195 |
else: |
183 | 196 |
found = False |
184 |
for step in [1,2,-1,-2]: |
|
185 |
if black == self._image[pt[1] + round(dir[1]*windowSize[1] + norm[1]*step), pt[0] + round(dir[0]*windowSize[1] + norm[0]*step)]: |
|
186 |
_pt = [pt[0] + round(dir[0]*windowSize[1] + norm[0]*step), pt[1] + round(dir[1]*windowSize[1] + norm[1]*step)] |
|
197 |
for step in [1, 2, -1, -2]: |
|
198 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1] + norm[1] * step), pt[0] + round( |
|
199 |
dir[0] * windowSize[1] + norm[0] * step)]: |
|
200 |
_pt = [pt[0] + round(dir[0] * windowSize[1] + norm[0] * step), |
|
201 |
pt[1] + round(dir[1] * windowSize[1] + norm[1] * step)] |
|
187 | 202 |
found = True |
188 | 203 |
break |
189 | 204 |
|
190 | 205 |
if not found: return (pt, -1) |
191 | 206 |
|
192 |
color = black
|
|
207 |
color = black |
|
193 | 208 |
lhs = [_pt[0], _pt[1]] |
194 | 209 |
lhscount = 1 |
195 | 210 |
while color != white: |
196 |
lhs[0] = _pt[0] + round(norm[0]*lhscount)
|
|
197 |
lhs[1] = _pt[1] + round(norm[1]*lhscount)
|
|
211 |
lhs[0] = _pt[0] + round(norm[0] * lhscount)
|
|
212 |
lhs[1] = _pt[1] + round(norm[1] * lhscount)
|
|
198 | 213 |
color = self._image[lhs[1], lhs[0]] |
199 | 214 |
lhscount += 1 |
200 | 215 |
|
201 |
color = black
|
|
216 |
color = black |
|
202 | 217 |
rhs = [_pt[0], _pt[1]] |
203 | 218 |
rhscount = 1 |
204 | 219 |
while color != white: |
205 |
rhs[0] = _pt[0] - round(norm[0]*rhscount)
|
|
206 |
rhs[1] = _pt[1] - round(norm[1]*rhscount)
|
|
220 |
rhs[0] = _pt[0] - round(norm[0] * rhscount)
|
|
221 |
rhs[1] = _pt[1] - round(norm[1] * rhscount)
|
|
207 | 222 |
color = self._image[rhs[1], rhs[0]] |
208 | 223 |
rhscount += 1 |
209 | 224 |
|
210 | 225 |
size = lhscount + rhscount |
211 |
offset = round((lhscount - rhscount)*0.5) if size < windowSize[1] else 0 |
|
212 |
#print(size) |
|
213 |
return ([pt[0] + norm[0]*offset, pt[1] + norm[1]*offset], size)# if size > windowSize[1] else windowSize[1]) |
|
226 |
offset = round((lhscount - rhscount) * 0.5) if size < windowSize[1] else 0 |
|
227 |
# print(size) |
|
228 |
return ( |
|
229 |
[pt[0] + norm[0] * offset, pt[1] + norm[1] * offset], |
|
230 |
size) # if size > windowSize[1] else windowSize[1]) |
|
214 | 231 |
except Exception as ex: |
215 |
from App import App
|
|
232 |
from App import App |
|
216 | 233 |
from AppDocData import MessageType |
217 | 234 |
|
218 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
235 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
236 |
sys.exc_info()[-1].tb_lineno) |
|
219 | 237 |
App.mainWnd().addMessage.emit(MessageType.Error, message) if not 'is out of bounds' in message else '' |
220 | 238 |
return (pt, -1) |
221 | 239 |
|
... | ... | |
230 | 248 |
humkyung 2018.04.12 use connection points without rotating(already rotated) |
231 | 249 |
humkyung 2018.09.01 use connector's direction for detecting line |
232 | 250 |
''' |
251 |
|
|
233 | 252 |
def detectConnectedLine(self, symbol, offsetX, offsetY): |
234 | 253 |
res = [] |
235 | 254 |
|
... | ... | |
244 | 263 |
dy = connector.sceneConnectPoint[1] - symbol.origin[1] |
245 | 264 |
else: |
246 | 265 |
dx, dy = direction[0], direction[1] |
247 |
#print('dx : ' + str(dx) + ', dy : ' + str(dy)) |
|
266 |
# print('dx : ' + str(dx) + ', dy : ' + str(dy))
|
|
248 | 267 |
## up to here |
249 | 268 |
|
250 |
length = math.sqrt(dx*dx + dy*dy)
|
|
269 |
length = math.sqrt(dx * dx + dy * dy)
|
|
251 | 270 |
if length > 0: |
252 | 271 |
dx /= length |
253 | 272 |
dy /= length |
254 | 273 |
|
255 |
if abs(dx) < 0.1: # vertical line |
|
256 |
dir = [0,1 if dy > 0 else -1] |
|
257 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), round(connector.sceneConnectPoint[1] - offsetY)] |
|
274 |
if abs(dx) < 0.1: # vertical line |
|
275 |
dir = [0, 1 if dy > 0 else -1] |
|
276 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), |
|
277 |
round(connector.sceneConnectPoint[1] - offsetY)] |
|
258 | 278 |
pt, thickness = self.adjustStartPoint(pt, dir) |
259 | 279 |
if thickness != -1: pool.append([dir, pt, thickness, True if not pool else False]) |
260 |
#print("v") |
|
261 |
elif abs(dy) < 0.1: # horizontal line |
|
262 |
dir = [1 if dx > 0 else -1,0] |
|
263 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), round(connector.sceneConnectPoint[1] - offsetY)] |
|
280 |
# print("v") |
|
281 |
elif abs(dy) < 0.1: # horizontal line |
|
282 |
dir = [1 if dx > 0 else -1, 0] |
|
283 |
pt = [round(connector.sceneConnectPoint[0] - offsetX), |
|
284 |
round(connector.sceneConnectPoint[1] - offsetY)] |
|
264 | 285 |
pt, thickness = self.adjustStartPoint(pt, dir) |
265 | 286 |
if thickness != -1: pool.append([dir, pt, thickness, True if not pool else False]) |
266 |
#print("h") |
|
267 |
#print(thickness) |
|
268 |
#print(pool) |
|
287 |
# print("h")
|
|
288 |
# print(thickness)
|
|
289 |
# print(pool)
|
|
269 | 290 |
|
270 |
#print(len(pool)) |
|
291 |
# print(len(pool))
|
|
271 | 292 |
while len(pool) > 0: |
272 | 293 |
dir, pt, thickness, forward = pool.pop() |
273 | 294 |
line = self.detectLine(pt, dir, thickness, forward) |
274 | 295 |
if line is not None: |
275 | 296 |
line.append(thickness) |
276 |
#print(line) |
|
297 |
# print(line)
|
|
277 | 298 |
res.append(line if forward else [line[1], line[0], thickness]) |
278 |
if ([1,0] == dir) or ([-1,0] == dir): # turn up/down
|
|
299 |
if ([1, 0] == dir) or ([-1, 0] == dir): # turn up/down
|
|
279 | 300 |
connectedPt = [line[1][0], pt[1]] |
280 |
pt, thickness = self.adjustStartPoint(connectedPt, [0,1]) |
|
281 |
if thickness != -1: pool.append([[0,1], pt, thickness, forward]) |
|
282 |
pt, thickness = self.adjustStartPoint(connectedPt, [0,-1]) |
|
283 |
if thickness != -1: pool.append([[0,-1], pt, thickness, not forward]) |
|
284 |
elif ([0,1] == dir) or ([0,-1] == dir): # turn left/right
|
|
301 |
pt, thickness = self.adjustStartPoint(connectedPt, [0, 1])
|
|
302 |
if thickness != -1: pool.append([[0, 1], pt, thickness, forward])
|
|
303 |
pt, thickness = self.adjustStartPoint(connectedPt, [0, -1])
|
|
304 |
if thickness != -1: pool.append([[0, -1], pt, thickness, not forward])
|
|
305 |
elif ([0, 1] == dir) or ([0, -1] == dir): # turn left/right
|
|
285 | 306 |
connectedPt = [pt[0], line[1][1]] |
286 |
pt, thickness = self.adjustStartPoint(connectedPt, [1,0]) |
|
287 |
if thickness != -1: pool.append([[1,0], pt, thickness, forward]) |
|
288 |
pt, thickness = self.adjustStartPoint(connectedPt, [-1,0]) |
|
289 |
if thickness != -1: pool.append([[-1,0], pt, thickness, not forward]) |
|
290 |
#print(res) |
|
307 |
pt, thickness = self.adjustStartPoint(connectedPt, [1, 0])
|
|
308 |
if thickness != -1: pool.append([[1, 0], pt, thickness, forward])
|
|
309 |
pt, thickness = self.adjustStartPoint(connectedPt, [-1, 0])
|
|
310 |
if thickness != -1: pool.append([[-1, 0], pt, thickness, not forward])
|
|
311 |
# print(res)
|
|
291 | 312 |
return res |
292 | 313 |
except Exception as ex: |
293 |
from App import App
|
|
314 |
from App import App |
|
294 | 315 |
from AppDocData import MessageType |
295 | 316 |
|
296 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
317 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
318 |
sys.exc_info()[-1].tb_lineno) |
|
297 | 319 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
298 | 320 |
|
299 | 321 |
''' |
... | ... | |
303 | 325 |
@history humkyung 2018.04.12 continue loop if line is not in connectedLines |
304 | 326 |
Jeongwoo 2018.05.16 Make comments if-statement |
305 | 327 |
''' |
328 |
|
|
306 | 329 |
def mergeLines(self, connectedLines, toler): |
307 | 330 |
try: |
308 | 331 |
for line in connectedLines[:]: |
309 | 332 |
if line not in connectedLines: continue |
310 |
matches = [param for param in connectedLines if (line != param) and self.isCollinear(line, param, toler)] |
|
333 |
matches = [param for param in connectedLines if |
|
334 |
(line != param) and self.isCollinear(line, param, toler)] |
|
311 | 335 |
if len(matches) > 0: |
312 |
#print(len(matches)) |
|
336 |
# print(len(matches))
|
|
313 | 337 |
matches.append(line) |
314 |
#if len(matches) > 2: matches = matches[0:2] # pick last two objects |
|
338 |
# if len(matches) > 2: matches = matches[0:2] # pick last two objects
|
|
315 | 339 |
mergedLine = self.connectLines(matches, toler) |
316 | 340 |
if mergedLine is not None and len(mergedLine) > 0: |
317 | 341 |
connectedLines.append(mergedLine) |
318 | 342 |
for match in matches: connectedLines.remove(match) |
319 | 343 |
except Exception as ex: |
320 |
from App import App
|
|
344 |
from App import App |
|
321 | 345 |
from AppDocData import MessageType |
322 | 346 |
|
323 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
347 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
348 |
sys.exc_info()[-1].tb_lineno) |
|
324 | 349 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
325 | 350 |
|
326 | 351 |
''' |
... | ... | |
328 | 353 |
@author humkyung |
329 | 354 |
@date 2018.04.13 |
330 | 355 |
''' |
356 |
|
|
331 | 357 |
def connectLineToSymbol(self, line, symbol, toler): |
332 | 358 |
startPt = list(line.startPoint()) |
333 |
distStart = [(self.distanceTo(startPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in symbol.connectors] |
|
359 |
distStart = [(self.distanceTo(startPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), |
|
360 |
(connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in |
|
361 |
symbol.connectors] |
|
334 | 362 |
distStart.sort() |
335 | 363 |
|
336 | 364 |
endPt = list(line.endPoint()) |
337 |
distEnd = [(self.distanceTo(endPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in symbol.connectors] |
|
365 |
distEnd = [(self.distanceTo(endPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])), |
|
366 |
(connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in |
|
367 |
symbol.connectors] |
|
338 | 368 |
distEnd.sort() |
339 | 369 |
|
340 | 370 |
if distStart[0][0] < distEnd[0][0]: |
... | ... | |
361 | 391 |
res = line.connect_if_possible(symbol, toler) |
362 | 392 |
if res: |
363 | 393 |
line.set_line([res[1], res[2]]) |
394 |
|
|
364 | 395 |
''' |
365 | 396 |
@brief extend line to intersection point |
366 | 397 |
@author humkyung |
367 | 398 |
@date 2018.04.14 |
368 | 399 |
''' |
400 |
|
|
369 | 401 |
def connectLineToLine(self, lhs, rhs, toler=20): |
370 | 402 |
try: |
371 | 403 |
res = lhs.connect_if_possible(rhs, toler) |
372 | 404 |
if not res: |
373 | 405 |
return |
374 |
|
|
406 |
|
|
375 | 407 |
lhs_start = list(lhs.startPoint()) |
376 | 408 |
lhs_end = list(lhs.endPoint()) |
377 | 409 |
rhs_start = list(rhs.startPoint()) |
... | ... | |
379 | 411 |
|
380 | 412 |
dx = rhs_end[0] - rhs_start[0] |
381 | 413 |
dy = rhs_end[1] - rhs_start[1] |
382 |
length = math.sqrt(dx*dx + dy*dy)
|
|
414 |
length = math.sqrt(dx * dx + dy * dy)
|
|
383 | 415 |
if length == 0: return |
384 | 416 |
dx /= length |
385 | 417 |
dy /= length |
386 |
rightLine = [(rhs_start[0]-dx*toler, rhs_start[1]-dy*toler), (rhs_end[0]+dx*toler, rhs_end[1]+dy*toler)] |
|
418 |
rightLine = [(rhs_start[0] - dx * toler, rhs_start[1] - dy * toler), |
|
419 |
(rhs_end[0] + dx * toler, rhs_end[1] + dy * toler)] |
|
387 | 420 |
shapelyRightLine = shapely.geometry.LineString(rightLine) |
388 | 421 |
|
389 | 422 |
dx = lhs_end[0] - lhs_start[0] |
390 | 423 |
dy = lhs_end[1] - lhs_start[1] |
391 |
length = math.sqrt(dx*dx + dy*dy)
|
|
424 |
length = math.sqrt(dx * dx + dy * dy)
|
|
392 | 425 |
if length == 0: return |
393 | 426 |
dx /= length |
394 | 427 |
dy /= length |
395 |
line = [(lhs_start[0]-dx*toler, lhs_start[1]-dy*toler), (lhs_end[0]+dx*toler, lhs_end[1]+dy*toler)] |
|
428 |
line = [(lhs_start[0] - dx * toler, lhs_start[1] - dy * toler), |
|
429 |
(lhs_end[0] + dx * toler, lhs_end[1] + dy * toler)] |
|
396 | 430 |
shapelyLine = shapely.geometry.LineString(line) |
397 | 431 |
|
398 | 432 |
pt = shapelyRightLine.intersection(shapelyLine) |
... | ... | |
436 | 470 |
|
437 | 471 |
rhs.set_line([rhs_start, rhs_end]) |
438 | 472 |
except Exception as ex: |
439 |
from App import App
|
|
473 |
from App import App |
|
440 | 474 |
from AppDocData import MessageType |
441 | 475 |
|
442 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
476 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
477 |
sys.exc_info()[-1].tb_lineno) |
|
443 | 478 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
444 | 479 |
|
445 | 480 |
''' |
... | ... | |
447 | 482 |
@author humkyung |
448 | 483 |
@date 2018.05.18 |
449 | 484 |
''' |
485 |
|
|
450 | 486 |
def detectLineThickness(self, pt, dir): |
451 | 487 |
import math |
452 | 488 |
from AppDocData import AppDocData |
... | ... | |
458 | 494 |
color = white |
459 | 495 |
|
460 | 496 |
norm = [-dir[1], dir[0]] |
461 |
if black == self._image[pt[1] + round(dir[1]*windowSize[1]), pt[0] + round(dir[0]*windowSize[1])]:
|
|
462 |
_pt = [pt[0] + round(dir[0]*windowSize[1]), pt[1] + round(dir[1]*windowSize[1])]
|
|
497 |
if black == self._image[pt[1] + round(dir[1] * windowSize[1]), pt[0] + round(dir[0] * windowSize[1])]:
|
|
498 |
_pt = [pt[0] + round(dir[0] * windowSize[1]), pt[1] + round(dir[1] * windowSize[1])]
|
|
463 | 499 |
else: |
464 | 500 |
return windowSize[1] |
465 | 501 |
|
466 |
color = black
|
|
502 |
color = black |
|
467 | 503 |
lhs = [pt[0], pt[1]] |
468 | 504 |
count = 1 |
469 | 505 |
while color != white: |
470 |
lhs[0] = pt[0] + round(norm[0]*count)
|
|
471 |
lhs[1] = pt[1] + round(norm[1]*count)
|
|
506 |
lhs[0] = pt[0] + round(norm[0] * count)
|
|
507 |
lhs[1] = pt[1] + round(norm[1] * count)
|
|
472 | 508 |
color = self._image[lhs[1], lhs[0]] |
473 | 509 |
count += 1 |
474 | 510 |
|
475 |
color = black
|
|
511 |
color = black |
|
476 | 512 |
rhs = [pt[0], pt[1]] |
477 | 513 |
count = 1 |
478 | 514 |
while color != white: |
479 |
rhs[0] = pt[0] - round(norm[0]*count)
|
|
480 |
rhs[1] = pt[1] - round(norm[1]*count)
|
|
515 |
rhs[0] = pt[0] - round(norm[0] * count)
|
|
516 |
rhs[1] = pt[1] - round(norm[1] * count)
|
|
481 | 517 |
color = self._image[rhs[1], rhs[0]] |
482 | 518 |
count += 1 |
483 | 519 |
|
484 | 520 |
dx = rhs[0] - lhs[0] |
485 | 521 |
dy = rhs[1] - lhs[1] |
486 |
return math.sqrt(dx*dx + dy*dy)
|
|
522 |
return math.sqrt(dx * dx + dy * dy)
|
|
487 | 523 |
|
488 |
''' |
|
489 |
@brief detect a line along given direction |
|
490 |
@author humkyung |
|
491 |
@date 2018.04 |
|
492 |
@history humkyung 2018.05.18 add parameter for thickness |
|
493 |
Jeongwoo 2018.05.18 Read LineLengthConfig and Comapare on if-statement |
|
494 |
''' |
|
495 | 524 |
def detectLine(self, pt, dir, thickness, forward): |
525 |
"""detect a line along given direction""" |
|
496 | 526 |
from AppDocData import AppDocData |
497 | 527 |
|
498 | 528 |
lineLengthConfigs = AppDocData.instance().getConfigs('Small Line Minimum Length', 'Min Length') |
... | ... | |
500 | 530 |
try: |
501 | 531 |
white = [255] |
502 | 532 |
windowSize = AppDocData.instance().getSlidingWindowSize() |
503 |
xHalf = round(windowSize[0]*0.5)
|
|
504 |
yHalf = round(windowSize[1]*0.5)
|
|
533 |
xHalf = round(windowSize[0] * 0.5)
|
|
534 |
yHalf = round(windowSize[1] * 0.5)
|
|
505 | 535 |
|
506 |
if ([1,0] == dir): |
|
507 |
image = self._image[(pt[1]-yHalf):(pt[1]+yHalf), pt[0]:self.width]
|
|
536 |
if ([1, 0] == dir):
|
|
537 |
image = self._image[(pt[1] - yHalf):(pt[1] + yHalf), pt[0]:self.width]
|
|
508 | 538 |
imgWidth, imgHeight = image.shape[::-1] |
509 | 539 |
index = 0 |
510 |
for i in range(imgWidth-windowSize[0]):
|
|
511 |
window = image[0:windowSize[1], i:i+windowSize[0]]
|
|
512 |
if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break |
|
540 |
for i in range(imgWidth - windowSize[0]):
|
|
541 |
window = image[0:windowSize[1], i:i + windowSize[0]]
|
|
542 |
if (white == window[0:windowSize[1], 0:windowSize[0]]).all(): break
|
|
513 | 543 |
index += 1 |
514 | 544 |
if index > lineMinLength: |
515 |
#self._image[(pt[1]-yHalf):(pt[1]+yHalf), pt[0]:(pt[0]+i)] = white |
|
516 |
cv2.line(self._image, (pt[0],pt[1]), (pt[0]+i,pt[1]), 255, thickness)
|
|
517 |
return [[pt[0], pt[1]], [pt[0] + i - round(thickness*0.5), pt[1]]]
|
|
518 |
elif ([-1,0] == dir): |
|
519 |
image = self._image[(pt[1]-yHalf):(pt[1]+yHalf), 0:pt[0]]
|
|
545 |
# self._image[(pt[1]-yHalf):(pt[1]+yHalf), pt[0]:(pt[0]+i)] = white
|
|
546 |
cv2.line(self._image, (pt[0], pt[1]), (pt[0] + i, pt[1]), 255, thickness)
|
|
547 |
return [[pt[0], pt[1]], [pt[0] + i - round(thickness * 0.5), pt[1]]]
|
|
548 |
elif ([-1, 0] == dir):
|
|
549 |
image = self._image[(pt[1] - yHalf):(pt[1] + yHalf), 0:pt[0]]
|
|
520 | 550 |
imgWidth, imgHeight = image.shape[::-1] |
521 | 551 |
index = 0 |
522 |
for i in range(imgWidth-windowSize[0], -1, -1):
|
|
523 |
window = image[0:windowSize[1], i:i+windowSize[0]]
|
|
524 |
if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break |
|
552 |
for i in range(imgWidth - windowSize[0], -1, -1):
|
|
553 |
window = image[0:windowSize[1], i:i + windowSize[0]]
|
|
554 |
if (white == window[0:windowSize[1], 0:windowSize[0]]).all(): break
|
|
525 | 555 |
index += 1 |
526 |
if index > lineMinLength:
|
|
527 |
#self._image[int(pt[1]-yHalf):int(pt[1]+yHalf), (i+windowSize[0]+yHalf):pt[0]] = white |
|
528 |
cv2.line(self._image, (i+windowSize[0],pt[1]), (pt[0],pt[1]), 255, thickness)
|
|
529 |
return [[pt[0], pt[1]], [i+windowSize[0]+round(thickness*0.5), pt[1]]]
|
|
530 |
elif ([0,1] == dir): |
|
556 |
if index > lineMinLength: |
|
557 |
# self._image[int(pt[1]-yHalf):int(pt[1]+yHalf), (i+windowSize[0]+yHalf):pt[0]] = white
|
|
558 |
cv2.line(self._image, (i + windowSize[0], pt[1]), (pt[0], pt[1]), 255, thickness)
|
|
559 |
return [[pt[0], pt[1]], [i + windowSize[0] + round(thickness * 0.5), pt[1]]]
|
|
560 |
elif ([0, 1] == dir):
|
|
531 | 561 |
windowSize.reverse() |
532 |
xHalf = round(windowSize[0]*0.5)
|
|
533 |
yHalf = round(windowSize[1]*0.5)
|
|
562 |
xHalf = round(windowSize[0] * 0.5)
|
|
563 |
yHalf = round(windowSize[1] * 0.5)
|
|
534 | 564 |
|
535 |
image = self._image[pt[1]:self.height, int(pt[0]-xHalf):int(pt[0]+xHalf)]
|
|
565 |
image = self._image[pt[1]:self.height, int(pt[0] - xHalf):int(pt[0] + xHalf)]
|
|
536 | 566 |
imgWidth, imgHeight = image.shape[::-1] |
537 | 567 |
index = 0 |
538 |
for i in range(imgHeight-windowSize[1]):
|
|
539 |
window = image[i:i+windowSize[1], 0:windowSize[0]]
|
|
540 |
if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break |
|
568 |
for i in range(imgHeight - windowSize[1]):
|
|
569 |
window = image[i:i + windowSize[1], 0:windowSize[0]]
|
|
570 |
if (white == window[0:windowSize[1], 0:windowSize[0]]).all(): break
|
|
541 | 571 |
index += 1 |
542 | 572 |
if index > lineMinLength: |
543 |
#self._image[(pt[1]):(pt[1]+i), (pt[0]-xHalf):(pt[0]+xHalf)] = white |
|
544 |
cv2.line(self._image, (pt[0],pt[1]), (pt[0],pt[1]+i), 255, thickness)
|
|
545 |
return [[pt[0], pt[1]], [pt[0], pt[1] + i - round(thickness*0.5)]]
|
|
546 |
elif ([0,-1] == dir): |
|
573 |
# self._image[(pt[1]):(pt[1]+i), (pt[0]-xHalf):(pt[0]+xHalf)] = white
|
|
574 |
cv2.line(self._image, (pt[0], pt[1]), (pt[0], pt[1] + i), 255, thickness)
|
|
575 |
return [[pt[0], pt[1]], [pt[0], pt[1] + i - round(thickness * 0.5)]]
|
|
576 |
elif ([0, -1] == dir):
|
|
547 | 577 |
windowSize.reverse() |
548 |
xHalf = round(windowSize[0]*0.5)
|
|
549 |
yHalf = round(windowSize[1]*0.5)
|
|
578 |
xHalf = round(windowSize[0] * 0.5)
|
|
579 |
yHalf = round(windowSize[1] * 0.5)
|
|
550 | 580 |
|
551 |
image = self._image[0:pt[1], (pt[0]-xHalf):(pt[0]+xHalf)]
|
|
581 |
image = self._image[0:pt[1], (pt[0] - xHalf):(pt[0] + xHalf)]
|
|
552 | 582 |
imgWidth, imgHeight = image.shape[::-1] |
553 | 583 |
index = 0 |
554 |
for i in range(imgHeight-windowSize[1], -1, -1):
|
|
555 |
window = image[i:i+windowSize[1], 0:windowSize[0]]
|
|
556 |
if (white == window[0:windowSize[1],0:windowSize[0]]).all(): break |
|
584 |
for i in range(imgHeight - windowSize[1], -1, -1):
|
|
585 |
window = image[i:i + windowSize[1], 0:windowSize[0]]
|
|
586 |
if (white == window[0:windowSize[1], 0:windowSize[0]]).all(): break
|
|
557 | 587 |
index += 1 |
558 | 588 |
if index > lineMinLength: |
559 |
#self._image[(i+windowSize[1]):pt[1], (pt[0]-xHalf):(pt[0]+xHalf)] = white |
|
560 |
cv2.line(self._image, (pt[0],i+windowSize[1]), (pt[0],pt[1]), 255, thickness)
|
|
561 |
return [[pt[0], pt[1]], [pt[0], i+windowSize[1]+round(thickness*0.5)]]
|
|
589 |
# self._image[(i+windowSize[1]):pt[1], (pt[0]-xHalf):(pt[0]+xHalf)] = white
|
|
590 |
cv2.line(self._image, (pt[0], i + windowSize[1]), (pt[0], pt[1]), 255, thickness)
|
|
591 |
return [[pt[0], pt[1]], [pt[0], i + windowSize[1] + round(thickness * 0.5)]]
|
|
562 | 592 |
except Exception as ex: |
563 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
593 |
from App import App |
|
594 |
from AppDocData import MessageType |
|
595 |
|
|
596 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
597 |
sys.exc_info()[-1].tb_lineno) |
|
598 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
564 | 599 |
|
565 | 600 |
return None |
566 | 601 |
|
567 |
def detectLineWithoutSymbol(self, area):# path, offsetX, offsetY): |
|
602 |
def detectLineWithoutSymbol(self, area): # path, offsetX, offsetY):
|
|
568 | 603 |
''' |
569 | 604 |
@brief detect remain line after detection using symbol info |
내보내기 Unified diff