프로젝트

일반

사용자정보

개정판 07441dd5

ID07441dd57e93e2f271913722fe5ec99832f2fb74
상위 43acb030
하위 b7354ec1

백흠경이(가) 약 5년 전에 추가함

issue #640: check 'Attr At' value when create a attribute for symbol

Change-Id: I28b8fbe65751d1487f9a3dd872742e9e96b40e11

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
2194 2194
    def saveSymbolAttributes(self, type, attrs, type_str):
2195 2195
        from CodeTables import CodeTable
2196 2196

  
2197
        conn = self.project.database.connect()
2198
        with conn:
2197
        with self.project.database.connect() as conn:
2199 2198
            try:
2200 2199
                # Get a cursor object
2201 2200
                cursor = conn.cursor()
DTI_PID/DTI_PID/Commands/DefaultCommand.py
55 55

  
56 56
        try:
57 57
            if not self.isCopy:
58
                if 'mousePressEvent' == param[0] and event.button() == Qt.MiddleButton:
58
                if 'mousePressEvent' == param[0] and (event.button() == Qt.MiddleButton or
59
                                                      event.button() == Qt.RightButton):
59 60
                    self.imageViewer.setDragMode(QGraphicsView.ScrollHandDrag)
60 61
                    QGraphicsView.mousePressEvent(self.imageViewer, QMouseEvent(QEvent.MouseButtonPress, event.pos(), Qt.LeftButton, event.buttons(), Qt.NoModifier))
61
                elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.MiddleButton:
62
                elif 'mouseReleaseEvent' == param[0] and (event.button() == Qt.MiddleButton or
63
                                                          event.button() == Qt.RightButton):
62 64
                    try:
63 65
                        self.imageViewer.setDragMode(QGraphicsView.NoDrag)
64 66
                    finally:
DTI_PID/DTI_PID/ConnectAttrDialog.py
19 19

  
20 20
'''
21 21
'''
22

  
23

  
22 24
class Worker(QObject):
23 25
    """ This is Worker class """
24 26
    from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QGridLayout, QListWidget
......
45 47
        @author humkyung
46 48
        @date   2018.06.17
47 49
    '''
48
    def run(self): # A slot takes no params
50

  
51
    def run(self):  # A slot takes no params
49 52
        from LineNoTracer import connectAttrImpl
50 53

  
51 54
        try:
52 55
            connectAttrImpl(self, self._update_line_type, self._update_flow_mark, self._update_spec)
53 56
        except Exception as ex:
54
            from App import App 
55
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
57
            from App import App
58
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
59
                                                           sys.exc_info()[-1].tb_lineno)
56 60
            App.mainWnd().addMessage.emit(MessageType.Error, message)
57 61

  
62

  
58 63
class QConnectAttrDialog(QDialog):
59 64
    """ This is connect attr dialog class """
60 65

  
61
    def __init__(self, parent, graphicsView): #Parent is MainWindow
66
    def __init__(self, parent, graphicsView):  # Parent is MainWindow
62 67
        import ConnectAttr_UI
63 68

  
64 69
        QDialog.__init__(self, parent)
......
69 74
        self.ui.setupUi(self)
70 75
        self.ui.pushButtonStart.setFocus()
71 76
        self.ui.buttonBox.setEnabled(True)
72
        self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) ## connect to func rowInserted(self, item)
77
        self.ui.listWidget.model().rowsInserted.connect(self.rowInserted)  ## connect to func rowInserted(self, item)
73 78
        self.isRunned = False
74
        
79

  
75 80
        self.ui.pushButtonStart.clicked.connect(self.connStart)
76 81

  
77 82
    def connStart(self):
78
        '''
79
            @brief  connection start
80
            @author euisung
81
            @date   2019.02.25
82
        ''' 
83
        """start to connect attributes"""
84

  
83 85
        self.ui.buttonBox.setEnabled(False)
84 86
        self.ui.pushButtonStart.setEnabled(False)
85 87
        self.ui.progressBar.setValue(0)
......
92 94
        @author     Jeongwoo
93 95
        @date       18.04.12
94 96
    '''
97

  
95 98
    def rowInserted(self, item):
96 99
        self.ui.listWidget.scrollToBottom()
97 100

  
......
100 103
        @author humkyung
101 104
        @date   2018.06.17
102 105
    '''
106

  
103 107
    def addListItem(self, msg):
104 108
        self.ui.listWidget.addItem(msg)
105 109

  
......
109 113
        @date       2018.06.17
110 114
        @history    humkyung 2018.06.27 reset value if maxValue is -1
111 115
    '''
116

  
112 117
    def updateProgress(self, maxValue):
113 118
        if maxValue != -1:
114 119
            self.ui.progressBar.setMaximum(maxValue)
......
121 126
        @author humkyung
122 127
        @date   2018.06.17
123 128
    '''
129

  
124 130
    def startThread(self):
125 131
        import timeit
126 132

  
......
128 134
            self.ui.buttonBox.setDisabled(True)
129 135

  
130 136
            # 1 - create Worker and Thread inside the Form
131
            self.obj = Worker(self.graphicsView, self.ui.checkBoxUpdateLineType.isChecked(), self.ui.checkBoxUpdateFlowMark.isChecked(), self.ui.checkBoxUpdateSpec.isChecked())
137
            self.obj = Worker(self.graphicsView, self.ui.checkBoxUpdateLineType.isChecked(),
138
                              self.ui.checkBoxUpdateFlowMark.isChecked(), self.ui.checkBoxUpdateSpec.isChecked())
132 139
            self.thread = QThread()
133 140

  
134 141
            # 2 - Move the Worker object to the Thread object
......
150 157

  
151 158
            self.tmStart = timeit.default_timer()
152 159
        except Exception as ex:
153
            from App import App 
154
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
160
            from App import App
161
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
162
                                                           sys.exc_info()[-1].tb_lineno)
155 163
            App.mainWnd().addMessage.emit(MessageType.Error, message)
156 164
        finally:
157 165
            pass
......
163 171
        @history    humkyung 2018.06.17 add flow mark for pipe run
164 172
                    humkyung 2018.08.16 don't update line type according to connected items
165 173
    '''
174

  
166 175
    def dlgExit(self):
167 176
        import timeit
168 177

  
169 178
        try:
170 179
            self.ui.progressBar.setValue(self.ui.progressBar.maximum())
180
            self.ui.buttonBox.setEnabled(True)
171 181
        except Exception as ex:
172 182
            from App import App
173 183

  
174
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
184
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
185
                                                           sys.exc_info()[-1].tb_lineno)
175 186
            App.mainWnd().addMessage.emit(MessageType.Error, message)
176 187
        finally:
177
            self.tmStop = timeit.default_timer()    
188
            self.tmStop = timeit.default_timer()
178 189
            seconds = self.tmStop - self.tmStart
179
            self.ui.listWidget.addItem("\nRunning Time : {} min".format(str(round(seconds/60, 1))) + "\n")
190
            self.ui.listWidget.addItem("\nRunning Time : {} min".format(str(round(seconds / 60, 1))) + "\n")
DTI_PID/DTI_PID/ItemPropertyTableWidget.py
129 129
            elif item is None:
130 130
                self.setRowCount(0)
131 131
        except Exception as ex:
132
            from App import App 
132
            from App import App
133 133

  
134 134
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
135 135
            App.mainWnd().addMessage.emit(MessageType.Error, message)
......
151 151
        self.setRowCount(13)
152 152
        self.verticalHeader().hide()
153 153
        self.horizontalHeader().setStretchLastSection(True)
154
        
154

  
155 155
    '''
156 156
        @brief      Slot to accept item click event
157 157
        @author     Jeongwoo
......
264 264
            self.lineNoChanged(item)
265 265
        finally:
266 266
            self.blockSignals(False)
267
        
267

  
268 268
    '''
269 269
        @brief      Reset table with new SymbolSvgItem
270 270
        @author     Jeongwoo
......
387 387
                self._areaComboBox.tag = widgetItem
388 388
                self._areaComboBox.addItem('None')
389 389
                title_list = []
390
                for title_area in title_area_list:
391
                    area = Area(title_area[1], title_area[0])
392
                    title_list.append(area)
390
                if title_area_list:
391
                    for title_area in title_area_list:
392
                        area = Area(title_area[1], title_area[0])
393
                        title_list.append(area)
393 394
                for area in area_list + title_list:
394 395
                    self._areaComboBox.addItem(area.name)
395 396
                self.setCellWidget(4, 3, self._areaComboBox)
......
403 404
                    item.setFlags(Qt.ItemIsEnabled)
404 405
                    #item.setBackground(Qt.lightGray)
405 406
        except Exception as ex:
406
            from App import App 
407
            from App import App
407 408

  
408 409
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
409 410
            App.mainWnd().addMessage.emit(MessageType.Error, message)
......
512 513
                            self.setItem(row, 3, value_item)
513 514

  
514 515
                    checkbox.state_changed(checkbox.isChecked())
515
                    
516

  
516 517
                    row = row + 1
517 518
                except Exception as ex:
518
                    from App import App 
519
                    from App import App
519 520

  
520 521
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
521 522
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
......
564 565

  
565 566
                    row = row + 1
566 567
                except Exception as ex:
567
                        from App import App 
568
                        from App import App
568 569

  
569 570
                        message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
570 571
                        App.mainWnd().addMessage.emit(MessageType.Error, message)
......
595 596
            connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem)))
596 597
            connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
597 598
            self.setItem(row, 3, connector_item)
598
            
599

  
599 600
            row = row + 1
600 601
            count = count + 1
601 602

  
......
661 662

  
662 663
                if type(self._item) is QEngineeringSpecBreakItem:
663 664
                    self.show_item_properties(self._item)
664
                
665

  
665 666
                for index in range(self.rowCount()):
666 667
                    item = self.item(index, 3)
667 668
                    if item is not None: item.setToolTip(item.text())
......
696 697
                self.show_item_connectors(self._item)
697 698
            else:
698 699
                self.setRowCount(0)
699
            
700

  
700 701
        except Exception as ex:
701
            from App import App 
702
            from App import App
702 703

  
703 704
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
704 705
            App.mainWnd().addMessage.emit(MessageType.Error, message)
......
716 717
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
717 718
                    find = True
718 719
                    break
719
            
720

  
720 721
            if not find:
721 722
                self._item.attrs.append(('Up Stream', text))
722 723

  
......
733 734
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
734 735
                    find = True
735 736
                    break
736
            
737

  
737 738
            if not find:
738 739
                self._item.attrs.append(('Down Stream', text))
739 740

  
......
777 778
        self.setItem(0, 3, item)
778 779

  
779 780
        self.show_item_properties(lineNoItem)
780
        
781

  
781 782
        row = self.rowCount()
782 783
        attrs = lineNoItem.getAttributes()
783 784
        self.setRowCount(row + len(attrs))
......
814 815
                    if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled)
815 816
                else:
816 817
                    valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
817
                 
818

  
818 819
                if key.Attribute.upper() == 'STREAM_NO':
819 820
                    self.streamNoComboBox = QComboBox()
820 821
                    self.streamNoComboBox.tag = key
821 822
                    self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged)
822
                    
823

  
823 824
                    streamNos = sorted(list(appDocData.hmbTable.streamNos()))
824 825
                    for streamNo in streamNos:
825 826
                        self.streamNoComboBox.addItem(streamNo)
......
973 974
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
974 975
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
975 976
                    self.mainWindow.graphicsView.command = cmd
976
                elif self.item(row, column).flags() != Qt.ItemIsEnabled: 
977
                elif self.item(row, column).flags() != Qt.ItemIsEnabled:
977 978
                    self.editItem(self.item(row, column))
978 979
            elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem:
979 980
                # unused code
DTI_PID/DTI_PID/LineDetector.py
252 252
                    direction = connector.dir()
253 253
                    if direction is None:
254 254
                        # calculate direction of connector
255
                        dx = connector.sceneConnectPoint[0] - symbol.origin[0]
256
                        dy = connector.sceneConnectPoint[1] - symbol.origin[1]
255
                        dx = connector.center()[0] - symbol.origin[0]
256
                        dy = connector.center()[1] - symbol.origin[1]
257 257
                    else:
258 258
                        dx, dy = direction[0], direction[1]
259 259
                    # up to here
......
265 265

  
266 266
                        if abs(dx) < 0.1:  # vertical line
267 267
                            dir = [0, 1 if dy > 0 else -1]
268
                            pt = [round(connector.sceneConnectPoint[0] - offsetX),
269
                                  round(connector.sceneConnectPoint[1] - offsetY)]
268
                            pt = [round(connector.center()[0] - offsetX),
269
                                  round(connector.center()[1] - offsetY)]
270 270
                            pt, thickness = self.adjust_start_point(pt, dir)
271 271
                            if thickness != -1:
272 272
                                pool.append([dir, pt, thickness, True if not pool else False])
273 273
                        elif abs(dy) < 0.1:  # horizontal line
274 274
                            dir = [1 if dx > 0 else -1, 0]
275
                            pt = [round(connector.sceneConnectPoint[0] - offsetX),
276
                                  round(connector.sceneConnectPoint[1] - offsetY)]
275
                            pt = [round(connector.center()[0] - offsetX),
276
                                  round(connector.center()[1] - offsetY)]
277 277
                            pt, thickness = self.adjust_start_point(pt, dir)
278 278
                            if thickness != -1:
279 279
                                pool.append([dir, pt, thickness, True if not pool else False])
......
340 340

  
341 341
    def connectLineToSymbol(self, line, symbol, toler):
342 342
        startPt = list(line.startPoint())
343
        distStart = [(self.distanceTo(startPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])),
344
                      (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in
343
        distStart = [(self.distanceTo(startPt, (connector.center()[0], connector.center()[1])),
344
                      (connector.center()[0], connector.center()[1])) for connector in
345 345
                     symbol.connectors]
346 346
        distStart.sort()
347 347

  
348 348
        endPt = list(line.endPoint())
349
        distEnd = [(self.distanceTo(endPt, (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])),
350
                    (connector.sceneConnectPoint[0], connector.sceneConnectPoint[1])) for connector in
349
        distEnd = [(self.distanceTo(endPt, (connector.center()[0], connector.center()[1])),
350
                    (connector.center()[0], connector.center()[1])) for connector in
351 351
                   symbol.connectors]
352 352
        distEnd.sort()
353 353

  
DTI_PID/DTI_PID/LineNoTracer.py
1275 1275
        (type1, value, traceback) = sys.exc_info()
1276 1276
        sys.excepthook(type1, value, traceback)
1277 1277
    finally:
1278
        from App import App
1279 1278
        worker.finished.emit()
1280
        App.mainWnd().dlgConnectAttr.ui.buttonBox.setEnabled(True)
1281 1279

  
1282 1280

  
DTI_PID/DTI_PID/QtImageViewer.py
88 88
        #   Qt.ScrollBarAsNeeded: Shows a scroll bar only when zoomed.
89 89
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
90 90
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
91
        #self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
92
        #self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
91
        # self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
92
        # self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
93 93

  
94 94
        # Stack of QRectF zoom boxes in scene coordinates.
95 95
        self.zoomStack = []
......
213 213
                if QT_VERSION_STR[0] == '4':
214 214
                    file_path = QFileDialog.getOpenFileName(self, "Open image file",
215 215
                                                            app_doc_data.project.getDrawingFilePath(),
216
                                                           "Image files(*.png *.jpg)", options=options)
216
                                                            "Image files(*.png *.jpg)", options=options)
217 217
                elif QT_VERSION_STR[0] == '5':
218 218
                    file_path, _ = QFileDialog.getOpenFileName(self, "Open image file",
219 219
                                                               app_doc_data.project.getDrawingFilePath(),
220
                                                                  "Image files(*.png *.jpg)", options=options)
220
                                                               "Image files(*.png *.jpg)", options=options)
221 221

  
222 222
                _bytes = None
223 223
                with open(file_path.encode('utf-8'), 'rb') as stream:
......
271 271
                    self.fitInView(self.zoomStack[-1], Qt.KeepAspectRatio)  # Show zoomed rect (ignore aspect ratio).
272 272
            else:
273 273
                self.zoomStack = []  # Clear the zoom stack (in case we got here because of an invalid zoom).
274
                self.fitInView(self.sceneRect(), self.aspectRatioMode)  # Show entire image (use current aspect ratio mode).
274
                self.fitInView(self.sceneRect(),
275
                               self.aspectRatioMode)  # Show entire image (use current aspect ratio mode).
275 276

  
276 277
    def zoomImageInit(self):
277 278
        if self.hasImage():
......
318 319
                self.command.execute(['mouseMoveEvent', event, scenePos])
319 320
                if self.command.name == "SelectAttribute":
320 321
                    QGraphicsView.mouseMoveEvent(self, event)
321
                if self.command.isTreated == True: return
322
                if self.command.isTreated:
323
                    event.accept()
324
                    return
322 325
        except Exception as ex:
323 326
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
324 327
                                                       sys.exc_info()[-1].tb_lineno))
......
341 344
            if self.command is not None:
342 345
                scenePos = self.mapToScene(event.pos())
343 346
                self.command.execute(['mousePressEvent', event, scenePos])
344
                if self.command.isTreated == True: return
347
                if self.command.isTreated:
348
                    event.accpet()
349
                    return
345 350
        except Exception as ex:
346 351
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
347 352
                                                       sys.exc_info()[-1].tb_lineno))
......
596 601
        strConnPts = symbol.getConnectionPoint()
597 602
        if strConnPts is not None and strConnPts != '':
598 603
            connPts = [(float(x.split(',')[0]), float(x.split(',')[1])) if len(x.split(',')) == 2 else (
599
            x.split(',')[0], float(x.split(',')[1]), float(x.split(',')[2])) \
604
                x.split(',')[0], float(x.split(',')[1]), float(x.split(',')[2])) \
600 605
                       for x in strConnPts.split('/')]
601 606

  
602 607
        svg.buildItem(svg_file_name, symbol.getType(), 0, None, None, None, connPts, symbol.getBaseSymbol(),
......
782 787
            arr = np.array(ptr).reshape(height, width, 4)  # Copies the data
783 788
            return arr
784 789
        except Exception as ex:
785
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
790
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
791
                                                       sys.exc_info()[-1].tb_lineno))
786 792

  
787 793

  
788 794
if __name__ == '__main__':
DTI_PID/DTI_PID/RecognitionDialog.py
204 204
    @staticmethod
205 205
    def executeRecognition(createDetectedItems, path, listWidget, isLineChecked, worker, batch, createUnknownItems):
206 206
        """
207
        @brief      Main function
207
        @brief      recognize symbol, text, line from image p&id
208 208
        @author     Jeongwoo
209 209
        @date
210 210
        @history    humkyung 2018.04.06 change error display from message box to print
......
299 299
                                   round(noteArea.x):round(noteArea.x + noteArea.width)].copy()
300 300
                    cv2.rectangle(app_doc_data.imgSrc, (round(noteArea.x), round(noteArea.y)),
301 301
                                  (round(noteArea.x + noteArea.width), round(noteArea.y + noteArea.height)), 255, -1)
302
                    #cv2.imwrite('c:\\temp\\note.png', noteArea.img)
303
                    #cv2.imwrite('c:\\temp\\removed_note.png', app_doc_data.imgSrc)
302 304
                # up to here
303 305

  
304 306
                area = app_doc_data.getArea('Drawing')
......
361 363
                        worker.updateBatchProgress.emit(len(srcList), 4)
362 364
                        continue
363 365

  
364
                    pool = futures.ThreadPoolExecutor(max_workers=THREAD_MAX_WORKER)
366
                    #cv2.imwrite('c:\\temp\\before-imgSrc.png', area.img)
367
                    #pool = futures.ThreadPoolExecutor(max_workers=THREAD_MAX_WORKER)
365 368
                    searchedTextSymList = []
366 369
                    for sym in searchedSymbolList:
367
                        pool.submit(Worker.remove_detected_symbol_image, sym, app_doc_data.imgSrc)
368
                    pool.shutdown(wait=True)
370
                        Worker.remove_detected_symbol_image(sym, app_doc_data.imgSrc)
371
                        #pool.submit(Worker.remove_detected_symbol_image, sym, app_doc_data.imgSrc)
372
                    #pool.shutdown(wait=True)
373
                    #cv2.imwrite('c:\\temp\\imgSrc.png', area.img)
369 374
                else:
370 375
                    '''
371 376
                    import math
......
859 864

  
860 865
                # draw contour with white color
861 866
                roiItem = cv2.drawContours(roiItem, selected_contours, -1, (255, 255, 255), -1)
867
                # cv2.imwrite("c:\\temp\\roiItem.png", roiItem)
862 868

  
863 869
            # try to recognize symbol twice(first one is normal, second on is flipped)
864 870
            steps = [False, True] if detectFlip else [False]
......
1701 1707
        sh = sym.getHeight()
1702 1708
        angle = sym.getRotatedAngle()
1703 1709
        # get symbol image
1704
        symImg = cv2.imread(path)
1705
        symImg = cv2.threshold(Worker.cvtGrayImage(symImg), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
1710
        sym_img = cv2.imread(path)
1711
        sym_img = cv2.cvtColor(sym_img, cv2.COLOR_BGR2GRAY)
1712
        # symImg = cv2.threshold(Worker.cvtGrayImage(symImg), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
1706 1713
        if sym.getDetectFlip() is 1:
1707
            symImg = cv2.flip(symImg, 1)
1714
            sym_img = cv2.flip(sym_img, 1)
1708 1715

  
1709 1716
        for i in range(angle // 90):
1710
            symImg = cv2.rotate(symImg, cv2.ROTATE_90_COUNTERCLOCKWISE)
1717
            sym_img = cv2.rotate(sym_img, cv2.ROTATE_90_COUNTERCLOCKWISE)
1711 1718
        # up to here
1712 1719

  
1713 1720
        threadLock.acquire()
1714 1721
        temp = imgSrc[sp[1]:sp[1] + sh, sp[0]:sp[0] + sw]
1715
        symImg = cv2.erode(symImg, np.ones((3, 3), np.uint8))
1716
        mask = cv2.bitwise_or(temp, symImg)
1722
        sym_img = cv2.erode(sym_img, np.ones((5, 5), np.uint8))
1723
        mask = cv2.bitwise_or(temp, sym_img)
1717 1724
        imgXOR = cv2.bitwise_xor(temp, mask)
1718 1725
        imgSrc[sp[1]:sp[1] + sh, sp[0]:sp[0] + sw] = cv2.bitwise_not(imgXOR)
1719 1726
        threadLock.release()
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py
53 53
        self._spec_break = None
54 54
        self._connectedItem = None
55 55
        self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT  # default value is connected at pt
56
        self.sceneConnectPoint = None
56
        self._sceneConnectPoint = None
57 57
        self.connectPoint = None
58 58
        self._hoverItem = None
59 59

  
......
78 78
        self._label.setPlainText(value)
79 79

  
80 80
    @property
81
    def sceneConnectPoint(self):
82
        """return the position of connector in scene"""
83

  
84
        if self.scene():
85
            return self.sceneBoundingRect().center().x(), self.sceneBoundingRect().center().y()
86
        else:
87
            return self.recognized_pt
88

  
89
    def center(self):
90
        """return the position of connector in scene"""
91

  
92
        if self.scene():
93
            return self.sceneBoundingRect().center().x(), self.sceneBoundingRect().center().y()
94
        else:
95
            return self.recognized_pt
96

  
97
    @property
81 98
    def connectedItem(self):
82 99
        """ getter of connectedItem """
83 100
        import uuid
......
155 172
        return None
156 173

  
157 174
    def __repr__(self):
158
        return '{},{},{},{}'.format(self._direction, self.sceneConnectPoint[0], self.sceneConnectPoint[1],
159
                                    self._symbol_idx)
175
        return '{},{},{},{}'.format(self._direction, self.center()[0], self.center()[1], self._symbol_idx)
160 176

  
161 177
    '''
162 178
        @brief  build connector item
......
171 187
            self.setZValue(self.parent.zValue() + 1)
172 188

  
173 189
    '''
174
        @brief      return center of connector
175
        @author     humkyung
176
        @date       2018.07.23
177
    '''
178

  
179
    def center(self):
180
        pt = self.sceneBoundingRect().center()
181
        return (pt.x(), pt.y())
182

  
183
    '''
184 190
        @brief  set position of connector
185 191
        @author humkyung
186 192
        @date   2018.05.02
......
190 196
        self._loc = [pos[0], pos[1]]
191 197
        self.setRect(self._loc[0] - round(self.SMALL_SIZE * 0.5), self._loc[1] - round(self.SMALL_SIZE * 0.5),
192 198
                     self.SMALL_SIZE, self.SMALL_SIZE)
193
        self.sceneConnectPoint = (self.sceneBoundingRect().center().x(), self.sceneBoundingRect().center().y())
194 199
        self.update()
195 200

  
196
        """ set label positon at center of connector """
201
        """ set label position at center of connector """
197 202
        self._label.setPos(QPointF(self._loc[0], self._loc[1]))
198 203

  
199 204
    def connect(self, item, at=QEngineeringAbstractItem.CONNECTED_AT_PT):
......
492 497
        import uuid
493 498

  
494 499
        try:
495
            self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT if record[
496
                                                                                 'Connected_At'] == '0' else QEngineeringAbstractItem.CONNECTED_AT_BODY
500
            self._connected_at = QEngineeringAbstractItem.CONNECTED_AT_PT if record['Connected_At'] == '0' else \
501
                QEngineeringAbstractItem.CONNECTED_AT_BODY
497 502

  
498 503
            connectedItemStr = record['Connected']
499 504
            connectPointStr = [record['X'], record['Y']]
500 505
            sceneConnectPointStr = [record['X'], record['Y']]
501 506

  
502
            self._connectedItem = uuid.UUID(
503
                connectedItemStr) if connectedItemStr and connectedItemStr != 'None' else None
507
            self._connectedItem = uuid.UUID(connectedItemStr) if connectedItemStr and connectedItemStr != 'None' else \
508
                None
504 509
            self.connectPoint = (float(connectPointStr[0]), float(connectPointStr[1]))
505
            self.sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1]))
510
            # self.sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1]))
506 511

  
507 512
            self.setBrush(Qt.yellow) if self._connectedItem else self.setBrush(Qt.blue)
508 513
        except Exception as ex:
......
532 537

  
533 538
            self._connectedItem = uuid.UUID(connectedItemStr) if connectedItemStr != 'None' else None
534 539
            self.connectPoint = (float(connectPointStr[0]), float(connectPointStr[1]))
535
            self.sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1]))
540
            # self.sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1])) 2020.2.8
536 541

  
537 542
            self.setBrush(Qt.yellow) if self._connectedItem else self.setBrush(Qt.blue)
538 543
        except Exception as ex:
......
593 598
            center = self.boundingRect().center()
594 599
            connectPointNode.text = str(center.x()) + ',' + str(center.y())
595 600
            sceneConnectPointNode = Element('SCENECONNECTPOINT')
596
            center = [self.sceneBoundingRect().center().x(),
597
                      self.sceneBoundingRect().center().y()] if self.scene() else self.sceneConnectPoint
601
            center = self.center()
598 602
            sceneConnectPointNode.text = str(center[0]) + ',' + str(center[1])
599 603

  
600 604
            node.append(connectedItemNode)
......
619 623
        cols = ['Components_UID', '[Index]', 'X', 'Y', 'Connected', 'Connected_At']
620 624
        values = ['?', '?', '?', '?', '?', '?']
621 625
        param = [  # str(self.uid),
622
            str(self.parentItem()), self._label.toPlainText(), self.sceneConnectPoint[0], self.sceneConnectPoint[1], \
626
            str(self.parentItem()), self._label.toPlainText(), self.center()[0], self.center()[1], \
623 627
            str(self.connectedItem.uid) if self.connectedItem else None, \
624 628
            str(self._connected_at)]
625 629
        sql = 'insert into Points({}) values({})'.format(','.join(cols), ','.join(values))
626 630

  
627
        # print(self.sceneConnectPoint)
628

  
629 631
        return (sql, tuple(param))
630 632

  
631 633

  
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py
78 78
                    connector = QEngineeringConnectorItem(parent=self, index=index + 1)
79 79
                    connector.setPos(vertex)
80 80
                    connector.setParentItem(self)
81
                    # connector의 connectPoint, sceneConnectPoint를 vertex로 함 추후 좀 알아봐서 수정 필요
82 81
                    connector.connectPoint = vertex
83
                    connector.sceneConnectPoint = vertex
82
                    connector.recognized_pt = vertex    # 좌표 위치 저장
84 83

  
85 84
                    # add connector move able
86 85
                    connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
......
549 548
                        break
550 549
        else:
551 550
            if len(item.connectors) == 2:
552
                connector1Point = item.connectors[0].sceneConnectPoint
553
                connector2Point = item.connectors[1].sceneConnectPoint
551
                connector1Point = item.connectors[0].center()
552
                connector2Point = item.connectors[1].center()
554 553

  
555 554
                # startPoint와 같은 connPts 찾음
556 555
                if startPoint[0] == connector1Point[0] and startPoint[1] == connector1Point[1]:
......
678 677
        try:
679 678
            if issubclass(type(obj), SymbolSvgItem):
680 679
                for i in range(len(obj.connectors)):
681
                    pt = obj.connectors[i].sceneConnectPoint
682
                    if (Point(startPt[0], startPt[1]).distance(Point(pt[0], pt[1])) < toler):
680
                    pt = obj.connectors[i].center()
681
                    if Point(startPt[0], startPt[1]).distance(Point(pt[0], pt[1])) < toler:
683 682
                        if self.connectors[0].connectedItem is None and obj.connectors[i].connectedItem is None:
684 683
                            self.connectors[0].connect(obj)
685 684
                            obj.connectors[i].connect(self)
686 685
                            # line, start, end
687 686
                            res.append(obj)
688
                            res.append(obj.connectors[i].sceneConnectPoint)
687
                            res.append(obj.connectors[i].center())
689 688
                            res.append(endPt)
690
                    elif (Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler):
689
                    elif Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler:
691 690
                        if self.connectors[1].connectedItem is None and obj.connectors[i].connectedItem is None:
692 691
                            self.connectors[1].connect(obj)
693 692
                            obj.connectors[i].connect(self)
694 693
                            # line, start, end
695 694
                            res.append(obj)
696 695
                            res.append(startPt)
697
                            res.append(obj.connectors[i].sceneConnectPoint)
696
                            res.append(obj.connectors[i].center())
698 697
            elif type(obj) is QEngineeringLineItem:
699 698
                _startPt = obj.startPoint()
700 699
                _endPt = obj.endPoint()
......
929 928
                rotatedPt = affinity.rotate(Point(symbol.connectors[i].connectPoint[0] - symbol.symbolOrigin[0],
930 929
                                                  symbol.connectors[i].connectPoint[1] - symbol.symbolOrigin[1]),
931 930
                                            -angle, Point(0, 0), use_radians=True)
932
                symbol.connectors[i].sceneConnectPoint = (origin.x + rotatedPt.x, origin.y + rotatedPt.y)
931
                #symbol.connectors[i].sceneConnectPoint = (origin.x + rotatedPt.x, origin.y + rotatedPt.y)
933 932

  
934
            dx1 = symbol.connectors[0].sceneConnectPoint[0] - self.startPoint()[0]
935
            dy1 = symbol.connectors[0].sceneConnectPoint[1] - self.startPoint()[1]
933
            dx1 = symbol.connectors[0].center()[0] - self.startPoint()[0]
934
            dy1 = symbol.connectors[0].center()[1] - self.startPoint()[1]
936 935
            length1 = math.sqrt(dx1 * dx1 + dy1 * dy1)
937
            dx2 = symbol.connectors[1].sceneConnectPoint[0] - self.startPoint()[0]
938
            dy2 = symbol.connectors[1].sceneConnectPoint[1] - self.startPoint()[1]
936
            dx2 = symbol.connectors[1].center()[0] - self.startPoint()[0]
937
            dy2 = symbol.connectors[1].center()[1] - self.startPoint()[1]
939 938
            length2 = math.sqrt(dx2 * dx2 + dy2 * dy2)
940 939

  
941 940
            if length1 < length2:
942
                processLine = QEngineeringLineItem([symbol.connectors[1].sceneConnectPoint, self.endPoint()])
941
                processLine = QEngineeringLineItem([symbol.connectors[1].center(), self.endPoint()])
943 942
                processLine.connectors[0].connectedItem = symbol
944 943
                processLine.connectors[1].connectedItem = self.connectors[1].connectedItem
945 944
                self.scene().addItem(processLine)
946 945

  
947
                line = QLineF(self.line().p1(), QPointF(symbol.connectors[0].sceneConnectPoint[0],
948
                                                        symbol.connectors[0].sceneConnectPoint[1]))
946
                line = QLineF(self.line().p1(), QPointF(symbol.connectors[0].center()[0],
947
                                                        symbol.connectors[0].center()[1]))
949 948
                self.setLine(line)
950 949
                self.connectors[1].connectedItem = symbol
951 950

  
952 951
                symbol.connectors[0].connectedItem = self
953 952
                symbol.connectors[1].connectedItem = processLine
954 953
            else:
955
                processLine = QEngineeringLineItem([symbol.connectors[0].sceneConnectPoint, self.endPoint()])
954
                processLine = QEngineeringLineItem([symbol.connectors[0].center(), self.endPoint()])
956 955
                processLine.connectors[0].connectedItem = symbol
957 956
                processLine.connectors[1].connectedItem = self.connectors[1].connectedItem
958 957
                self.scene().addItem(processLine)
959 958

  
960
                line = QLineF(self.line().p1(), QPointF(symbol.connectors[1].sceneConnectPoint[0],
961
                                                        symbol.connectors[1].sceneConnectPoint[1]))
959
                line = QLineF(self.line().p1(), QPointF(symbol.connectors[1].center()[0],
960
                                                        symbol.connectors[1].center()[1]))
962 961
                self.setLine(line)
963 962
                self.connectors[1].connectedItem = symbol
964 963

  
......
1355 1354
                    item.connectors[iterIndex].parse_record(connector)
1356 1355
                    iterIndex += 1
1357 1356

  
1358
            # get associations 
1357
            # get associations
1359 1358
            associations = app_doc_data.get_component_associations(uid)
1360 1359
            if associations:
1361 1360
                for assoc in associations:
......
1424 1423
                    item.connectors[iterIndex].parse_xml(connector)
1425 1424
                    iterIndex += 1
1426 1425

  
1427
            # get associations 
1426
            # get associations
1428 1427
            attributeValue = node.find('ASSOCIATIONS')
1429 1428
            if attributeValue is not None:
1430 1429
                for assoc in attributeValue.iter('ASSOCIATION'):
......
1565 1564
        index = 1
1566 1565
        for connector in self.connectors:
1567 1566
            params.append((  # str(connector.uid),
1568
                str(self.uid), index, connector.sceneConnectPoint[0], connector.sceneConnectPoint[1], \
1567
                str(self.uid), index, connector.center()[0], connector.center()[1], \
1569 1568
                str(connector.connectedItem.uid) if connector.connectedItem else None, \
1570 1569
                str(connector._connected_at)))
1571 1570
            index += 1
DTI_PID/DTI_PID/Shapes/EngineeringReservedWordTextItem.py
90 90
                if line.connectors[1].connectedItem is not None: continue
91 91

  
92 92
                dl = min(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) / 10
93
                dx = dl if (line.connectors[0].sceneConnectPoint[0] - line.connectors[1].sceneConnectPoint[0]) > 0 else -dl
94
                dy = -dl if (line.connectors[0].sceneConnectPoint[1] - line.connectors[1].sceneConnectPoint[1]) > 0 else dl
93
                dx = dl if (line.connectors[0].center()[0] - line.connectors[1].center()[0]) > 0 else -dl
94
                dy = -dl if (line.connectors[0].center()[1] - line.connectors[1].center()[1]) > 0 else dl
95 95
                
96 96
                startPoint = line.endPoint()
97 97
                for index in range(30):
DTI_PID/DTI_PID/Shapes/EngineeringVendorItem.py
56 56
            connector.setPos((point.x(), point.y()))
57 57
            connector.setParentItem(self)
58 58
            connector.connectPoint = (point.x(), point.y())
59
            connector.sceneConnectPoint = (point.x(), point.y())
60 59
            connector.setZValue(QEngineeringVendorItem.ZVALUE)
61 60
            connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
62 61
            connector.setAcceptTouchEvents(True)
......
140 139
                connector.setPos((x, y))
141 140
                connector.setParentItem(self)
142 141
                connector.connectPoint = (x, y)
143
                connector.sceneConnectPoint = (x, y)
144 142
                connector.setZValue(QEngineeringVendorItem.ZVALUE)
145 143
                connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
146 144
                connector.setAcceptTouchEvents(True)
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
475 475
        if not self.scene(): return super().itemChange(change, value)
476 476

  
477 477
        if change == QGraphicsItem.ItemPositionHasChanged or change == QGraphicsItem.ItemRotationChange:
478
            for conn in self.connectors:
479
                conn.sceneConnectPoint = (conn.sceneBoundingRect().center().x(), conn.sceneBoundingRect().center().y())
480

  
481 478
            from EngineeringLineItem import QEngineeringLineItem
482 479
            for connector in self.connectors:
483 480
                if connector.connectedItem is not None and type(connector.connectedItem) == QEngineeringLineItem:
......
563 560
            for connector in self.connectors:
564 561
                params.append( \
565 562
                    (  # str(connector.uid),
566
                        str(self.uid), index, connector.sceneConnectPoint[0], connector.sceneConnectPoint[1], \
563
                        str(self.uid), index, connector.center()[0], connector.center()[1], \
567 564
                        str(connector.connectedItem.uid) if connector.connectedItem else None, \
568 565
                        str(connector._connected_at)) \
569 566
                    )
......
587 584
        from SpecialItemTypesDialog import SpecialItemTypes
588 585

  
589 586
        try:
590
            docData = AppDocData.instance()
587
            app_doc_data = AppDocData.instance()
591 588
            self.name = name
592 589
            self.type = _type
593 590
            self.angle = angle
......
595 592
            self.size = size if size else [0, 0]
596 593
            self.origin = origin
597 594
            if dbUid is None:
598
                symbolInfo = docData.getSymbolByQuery('name', name)
595
                symbolInfo = app_doc_data.getSymbolByQuery('name', name)
599 596
            else:
600
                symbolInfo = docData.getSymbolByQuery('UID', dbUid)
597
                symbolInfo = app_doc_data.getSymbolByQuery('UID', dbUid)
601 598
            self.dbUid = symbolInfo.uid
602 599
            self.iType = symbolInfo.iType
603 600
            originalPoint = symbolInfo.getOriginalPoint().split(',')
......
616 613
                    x = float(tokens[0])
617 614
                    y = float(tokens[1])
618 615
                elif len(tokens) >= 3:
619
                    direction = connPts[index][0]
616
                    direction = connPts[index][0] if index < len(connPts) else tokens[0]
620 617
                    x = float(tokens[1])
621 618
                    y = float(tokens[2])
622 619
                if len(tokens) >= 4:
......
636 633
                self.connectors[index].symbol_idx = symbol_idx
637 634
                self.connectors[index].setPos((x, y))
638 635
                self.connectors[index].connectPoint = (x, y)
639
                self.connectors[index].sceneConnectPoint = (connPts[index][0], connPts[index][1]) if \
636
                # recognized_pt is only valid right after symbol is recognized
637
                self.connectors[index].recognized_pt = (connPts[index][0], connPts[index][1]) if \
640 638
                    len(connPts[index]) == 2 else (connPts[index][1], connPts[index][2]) if \
641 639
                    len(connPts[index]) == 3 else (connPts[index][1], connPts[index][2]) if \
642 640
                    len(connPts[index]) == 4 else None
641
                # up to here
643 642
            self.parentSymbol = parentSymbol
644 643
            self.childSymbol = childSymbol
645 644
            self.hasInstrumentLabel = hasInstrumentLabel
......
695 694
        '''
696 695
        for connector in self.connectors:
697 696
            for iConnector in item.connectors:
698
                dx = connector.sceneConnectPoint[0] - iConnector.sceneConnectPoint[0]
699
                dy = connector.sceneConnectPoint[1] - iConnector.sceneConnectPoint[1]
697
                dx = connector.center()[0] - iConnector.center()[0]
698
                dy = connector.center()[1] - iConnector.center()[1]
700 699
                if (math.sqrt(dx * dx + dy * dy) < toler): return True
701 700

  
702 701
        return False
......
758 757
                startPt = obj.startPoint()
759 758
                endPt = obj.endPoint()
760 759
                for i in range(len(self.connectors)):
761
                    if (Point(startPt[0], startPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0],
762
                                                                     self.connectors[i].sceneConnectPoint[1])) < toler):
760
                    if (Point(startPt[0], startPt[1]).distance(Point(self.connectors[i].center()[0],
761
                                                                     self.connectors[i].center()[1])) < toler):
763 762
                        if self.connectors[i].connectedItem is None and obj.connectors[0].connectedItem is None:
764 763
                            self.connectors[i].connect(obj)
765 764
                            obj.connectors[0].connect(self)
766 765
                            # line, start, end
767 766
                            res.append(obj)
768
                            res.append(self.connectors[i].sceneConnectPoint)
767
                            res.append(self.connectors[i].center())
769 768
                            res.append(endPt)
770
                    if (Point(endPt[0], endPt[1]).distance(Point(self.connectors[i].sceneConnectPoint[0],
771
                                                                 self.connectors[i].sceneConnectPoint[1])) < toler):
769
                    if (Point(endPt[0], endPt[1]).distance(Point(self.connectors[i].center()[0],
770
                                                                 self.connectors[i].center()[1])) < toler):
772 771
                        if self.connectors[i].connectedItem is None and obj.connectors[1].connectedItem is None:
773 772
                            self.connectors[i].connect(obj)
774 773
                            obj.connectors[1].connect(self)
775 774
                            # line, start, end
776 775
                            res.append(obj)
777 776
                            res.append(startPt)
778
                            res.append(self.connectors[i].sceneConnectPoint)
777
                            res.append(self.connectors[i].center())
779 778
            elif issubclass(type(obj), SymbolSvgItem):
780 779
                for i in range(len(self.connectors)):
781 780
                    if i > 3: break
782 781
                    for j in range(len(obj.connectors)):
783 782
                        if j > 3: break
784
                        _pt = Point(obj.connectors[j].sceneConnectPoint[0], obj.connectors[j].sceneConnectPoint[1])
785
                        if (_pt.distance(Point(self.connectors[i].sceneConnectPoint[0],
786
                                               self.connectors[i].sceneConnectPoint[1])) < toler):
783
                        _pt = Point(obj.connectors[j].center()[0], obj.connectors[j].center()[1])
784
                        if (_pt.distance(Point(self.connectors[i].center()[0],
785
                                               self.connectors[i].center()[1])) < toler):
787 786
                            if self.connectors[i].connectedItem is None:
788 787
                                self.connectors[i].connect(obj)
789 788
                            if obj.connectors[j].connectedItem is None:
......
819 818
        import math
820 819

  
821 820
        for connector in self.connectors:
822
            dx = connector.sceneConnectPoint[0] - pt[0]
823
            dy = connector.sceneConnectPoint[1] - pt[1]
824
            if math.sqrt(dx * dx + dy * dy) < toler: return connPt
821
            dx = connector.center()[0] - pt[0]
822
            dy = connector.center()[1] - pt[1]
823

  
824
            if math.sqrt(dx * dx + dy * dy) < toler:
825
                return connPt
825 826

  
826 827
        return None
827 828

  
......
1101 1102
            configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio')
1102 1103
            ratio = float(configs[0].value) if 1 == len(configs) else 1.5
1103 1104

  
1105
            rect = self.sceneBoundingRect()
1104 1106
            dist = max(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) * ratio
1105 1107
            center = self.sceneBoundingRect().center()
1106 1108

  
1107 1109
            minDist = None
1108 1110
            selected = None
1109 1111
            for attr in attributes:
1110
                # size text and operation code text will find onwer themselves in findowner method
1112
                # size text and operation code text will find owner themselves in findowner method
1111 1113
                if False:  # type(attr) is QEngineeringSizeTextItem or type(attr) is QEngineeringValveOperCodeTextItem:
1112 1114
                    dx = attr.center().x() - center.x()
1113 1115
                    dy = attr.center().y() - center.y()
......
1122 1124
                        if math.sqrt(dx * dx + dy * dy) < dist:
1123 1125
                            if self.add_assoc_item(attr):
1124 1126
                                attr.owner = self
1127
                elif issubclass(type(attr), QEngineeringTextItem):
1128
                    if rect.contains(attr.center()):
1129
                        if self.add_assoc_item(attr):
1130
                            attr.owner = self  # set owner of text
1125 1131

  
1126 1132
            if selected is not None:
1127 1133
                if self.add_assoc_item(selected):
......
1876 1882
        self.rotate(self.getCurrentPoint(), self.angle)
1877 1883
        scene.addItem(self)
1878 1884
        self.size[0], self.size[1] = round(self.sceneBoundingRect().width()), round(self.sceneBoundingRect().height())
1879
        for conn in self.connectors:
1880
            conn.sceneConnectPoint = (conn.sceneBoundingRect().center().x(), conn.sceneBoundingRect().center().y())
1885
        trans = self.transform()
1881 1886

  
1882 1887
    '''
1883 1888
        @brief      
......
2019 2024
            self.connectors[1].connectedItem = conn1Item
2020 2025

  
2021 2026
            currentPoint = self.getCurrentPoint()
2022
            self.reSettingSymbol(currentPoint, self.angle)
2027
            #self.reSettingSymbol(currentPoint, self.angle)
2023 2028

  
2024 2029
    '''
2025 2030
        @brief      change standard point
......
2036 2041
            self.currentPointModeIndex = 0
2037 2042

  
2038 2043
        currentPoint = self.getCurrentPoint()
2039
        self.reSettingSymbol(currentPoint, self.angle)
2044
        #self.reSettingSymbol(currentPoint, self.angle)
2040 2045

  
2041 2046
    '''
2042 2047
        @brief      get standard point
DTI_PID/DTI_PID/SymbolAttrEditorDialog.py
16 16

  
17 17
import SymbolAttrEditor_UI
18 18

  
19

  
19 20
class QSymbolAttrEditorDialog(QDialog):
20 21
    """ This is symbol attribute editor dialog class """
21
    
22
    SYMBOL_ATTR_DATA_TYPES = {'Symbol Item':-1, 'Size Text Item':-1, 'Text Item':-1, 'Tag No':-1, 'Valve Oper Code':-1, 'Line Item':-1, 'Comp Item':-1, 'EQ Item':-1, 'Int':1, 'String':1}
22

  
23
    SYMBOL_ATTR_DATA_TYPES = {'Symbol Item': -1, 'Size Text Item': -1, 'Text Item': -1, 'Tag No': -1,
24
                              'Valve Oper Code': -1, 'Line Item': -1, 'Comp Item': -1, 'EQ Item': -1, 'Int': 1,
25
                              'String': 1}
23 26
    LINE_NO_ATTR_TYPES = ['Code Table', 'Int', 'String', 'Symbol']
24 27

  
25
    def __init__(self, parent, symbolType = None):
28
    def __init__(self, parent, symbolType=None):
26 29
        QDialog.__init__(self, parent)
27 30

  
28 31
        self.ui = SymbolAttrEditor_UI.Ui_SymbolAttrEditorDialog()
......
76 79

  
77 80
    def cell_double_clicked(self, row, column):
78 81
        if self._symbolType is None or not (column is 6 or column is 7): return
79
        if hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row, 0).tag.IsProp == 2: return
80
    
82
        if hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row,
83
                                                                                                 0).tag.IsProp == 2: return
84

  
81 85
        from SymbolAttrTargetDialog import SymbolAttrTargetDialog
82 86
        from SymbolAttrCodeTableDialog import SymbolAttrCodeTableDialog
83 87
        from App import App
......
85 89
        try:
86 90
            # code table setting
87 91
            if column == 7:
88
                dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).tag.UID), tableDatas=self.ui.tableWidgetAttr.item(row, 7).tag)
92
                dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).tag.UID),
93
                                                   tableDatas=self.ui.tableWidgetAttr.item(row, 7).tag)
89 94
                (isAccept, code_data) = dialog.showDialog()
90
  
95

  
91 96
                if isAccept:
92 97
                    self.ui.tableWidgetAttr.item(row, 7).tag = code_data
93 98

  
......
105 110

  
106 111
                dialog = SymbolAttrTargetDialog(self, symbolType, self.ui.tableWidgetAttr.item(row, 6).tag)
107 112
                (isAccept, target) = dialog.showDialog()
108
  
113

  
109 114
                if isAccept:
110 115
                    self.ui.tableWidgetAttr.item(row, 6).tag = target
111 116
                    if target == 'ALL':
......
117 122
            from App import App
118 123
            from AppDocData import MessageType
119 124

  
120
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
125
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
126
                                                           sys.exc_info()[-1].tb_lineno)
121 127
            App.mainWnd().addMessage.emit(MessageType.Error, message)
122 128

  
123 129
    '''
......
125 131
        @author     kyouho
126 132
        @date       2018.08.16
127 133
    '''
134

  
128 135
    def settingComboBoxSymbolType(self, selectedType):
129 136
        docData = AppDocData.instance()
130 137
        comboBox = self.ui.comboBoxSymbolType
......
144 151
        @author     kyouho
145 152
        @date       2018.08.16
146 153
    '''
154

  
147 155
    def changeSymbolType(self):
148 156
        self._symbolType = self.ui.comboBoxSymbolType.currentText()
149 157
        self.ui.tableWidgetAttr.setRowCount(0)
......
158 166
        """
159 167

  
160 168
        appDocData = AppDocData.instance()
161
        
169

  
162 170
        self.currentTypeId = appDocData.getSymbolTypeId(symbolType)
163 171

  
164 172
        attrs = appDocData.getSymbolAttribute(symbolType)
......
166 174

  
167 175
        row = 0
168 176
        for attr in attrs:
169
            item = QTableWidgetItem(str(attr.UID))              # UID
177
            item = QTableWidgetItem(str(attr.UID))  # UID
170 178
            item.tag = attr
171 179
            self.ui.tableWidgetAttr.setItem(row, 0, item)
172
            item = QTableWidgetItem(attr.Attribute)             # Name
180
            item = QTableWidgetItem(attr.Attribute)  # Name
173 181
            if attr.IsProp >= 2:
174 182
                item.setFlags(Qt.ItemIsEnabled)
175 183
                item.setBackground(Qt.lightGray)
176 184
            self.ui.tableWidgetAttr.setItem(row, 1, item)
177
            item = QTableWidgetItem(attr.DisplayAttribute)      # Display Name
185
            item = QTableWidgetItem(attr.DisplayAttribute)  # Display Name
178 186
            self.ui.tableWidgetAttr.setItem(row, 2, item)
179 187

  
180 188
            attrTypeComboBox = QComboBox()
181
            for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items():
189
            for key, value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items():
182 190
                attrTypeComboBox.addItem(key)
183 191

  
184
            if attr.IsProp  >= 3:
192
            if attr.IsProp >= 3:
185 193
                attrTypeComboBox.setEnabled(False)
186
            if attr.AttributeType in [type for type , _ in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items()]:
194
            if attr.AttributeType in [type for type, _ in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items()]:
187 195
                self.ui.tableWidgetAttr.setCellWidget(row, 3, attrTypeComboBox)
188
                result = attrTypeComboBox.findText(attr.AttributeType) # Type
196
                result = attrTypeComboBox.findText(attr.AttributeType)  # Type
189 197
                attrTypeComboBox.setCurrentIndex(result)
190 198
            else:
191
                if attr.IsProp  >= 3:
199
                if attr.IsProp >= 3:
192 200
                    item = QTableWidgetItem(attr.AttributeType)
193 201
                    item.setFlags(Qt.ItemIsEnabled)
194 202
                self.ui.tableWidgetAttr.setItem(row, 3, item)
195 203

  
196
            item = QTableWidgetItem(str(attr.AttrAt))    # Attribute At
204
            item = QTableWidgetItem(str(attr.AttrAt))  # Attribute At
197 205
            if attr.IsProp >= 2:
198 206
                item.setFlags(Qt.ItemIsEnabled)
199 207
            self.ui.tableWidgetAttr.setItem(row, 4, item)
200 208

  
201
            item = QTableWidgetItem(attr.Expression)    # Expression
209
            item = QTableWidgetItem(attr.Expression)  # Expression
202 210
            if attr.IsProp >= 2:
203 211
                item.setFlags(Qt.ItemIsEnabled)
204 212
            self.ui.tableWidgetAttr.setItem(row, 5, item)
......
220 228
    def saveData(self):
221 229
        """save symbol attributes"""
222 230

  
223
        appDocData = AppDocData.instance()
231
        app_doc_data = AppDocData.instance()
224 232

  
225 233
        attrs = []
226 234
        table = self.ui.tableWidgetAttr
227
        
235

  
228 236
        for index in range(table.rowCount()):
229 237
            attr = []
230 238
            attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '')
231 239
            attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '')
232 240
            attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '')
233
            attr.append(table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3) else table.item(index, 3).text())#attr.append(table.item(index, 1).text())
234
            attr.append(table.item(index, 4).text() if table.item(index, 4) is not None else '')     # Attribute At
235
            attr.append(table.item(index, 5).text() if table.item(index, 5) is not None else '')     # Expression
236
            attr.append(table.item(index, 6).tag if table.item(index, 6).tag is not None else 'ALL') # Target
241

  
242
            attr_data_type = table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3) else \
243
                table.item(index, 3).text()
244
            attr.append(attr_data_type)
245

  
246
            attr_at = table.item(index, 4).text() if table.item(index, 4) is not None else ''
247
            if attr_data_type in ['Text Item', 'Symbol Item'] and not attr_at:
248
                QMessageBox.information(self, 'Information', f"'Attr At' must be set for {attr_data_type}")
249
                return False
250

  
251
            attr.append(attr_at)  # Attribute At
252

  
253
            attr.append(table.item(index, 5).text() if table.item(index, 5) is not None else '')  # Expression
254
            attr.append(table.item(index, 6).tag if table.item(index, 6).tag is not None else 'ALL')  # Target
237 255
            attr.append(index)
238 256
            attr.append(table.item(index, 0).tag.IsProp) if hasattr(table.item(index, 0), 'tag') else attr.append(0)
239
            attr.append(table.item(index, 7).tag)
257
            attr.append(table.item(index, 7).tag)   # code table
240 258
            attrs.append(attr)
241 259

  
242
        appDocData.saveSymbolAttributes(self.currentTypeId, attrs, self._symbolType)
260
        app_doc_data.saveSymbolAttributes(self.currentTypeId, attrs, self._symbolType)
261
        return True
243 262

  
244 263
    '''
245 264
        @brief  add a attribute
246 265
        @author humkyung
247 266
        @date   2018.08.13
248 267
    '''
268

  
249 269
    def onAddAttr(self):
250 270
        import uuid
251 271
        from SymbolAttr import SymbolAttr
......
254 274
        self.ui.tableWidgetAttr.setRowCount(rows + 1)
255 275

  
256 276
        attrTypeComboBox = QComboBox()
257
        for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items():
277
        for key, value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items():
258 278
            attrTypeComboBox.addItem(key)
259 279

  
260 280
        self.ui.tableWidgetAttr.setCellWidget(rows, 3, attrTypeComboBox)
......
281 301
        @author humkyung
282 302
        @date   2018.08.13
283 303
    '''
304

  
284 305
    def onDelAttr(self):
285 306
        model = self.ui.tableWidgetAttr.model()
286 307
        row = self.ui.tableWidgetAttr.currentRow()
287
        
288
        if row != -1 and not (hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row, 0).tag.IsProp == 2):
308

  
309
        if row != -1 and not (hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row,
310
                                                                                                                    0).tag.IsProp == 2):
289 311
            model.removeRow(row)
290 312

  
291 313
    '''
......
293 315
        @author     humkyung
294 316
        @date       2018.08.13
295 317
    '''
318

  
296 319
    def accept(self):
297 320
        if self._symbolType is not None:
298
            self.saveData()
321
            if not self.saveData():
322
                return
299 323
        else:
300 324
            self.saveLineAttrData()
301
        
325

  
302 326
        QDialog.accept(self)
303 327

  
304 328
    '''
......
306 330
        @author kyoyho
307 331
        @date   2018.08.21
308 332
    '''
333

  
309 334
    def settingLineNoAttributeTable(self):
310 335
        table = self.ui.tableWidgetAttr
311 336
        docData = AppDocData.instance()
......
318 343
            item = QTableWidgetItem(attr.UID if attr.UID is not None else '')
319 344
            self.ui.tableWidgetAttr.setItem(row, 0, item)
320 345
            item = QTableWidgetItem(attr.Attribute if attr.Attribute is not None else '')
321
            #item.setFlags(Qt.ItemIsEnabled)
346
            # item.setFlags(Qt.ItemIsEnabled)
322 347
            self.ui.tableWidgetAttr.setItem(row, 1, item)
323 348
            item = QTableWidgetItem(attr.DisplayAttribute if attr.DisplayAttribute is not None else '')
324 349
            self.ui.tableWidgetAttr.setItem(row, 2, item)
......
343 368
        @author kyoyho
344 369
        @date   2018.08.21
345 370
    '''
371

  
346 372
    def onAddLineNoAttr(self):
347 373
        rows = self.ui.tableWidgetAttr.rowCount()
348 374
        self.ui.tableWidgetAttr.setRowCount(rows + 1)
349
        
375

  
350 376
        attrTypeComboBox = QComboBox()
351 377
        for _type in QSymbolAttrEditorDialog.LINE_NO_ATTR_TYPES:
352 378
            attrTypeComboBox.addItem(_type)
353 379
        self.ui.tableWidgetAttr.setCellWidget(rows, 3, attrTypeComboBox)
354
       
380

  
355 381
        import uuid
356 382
        self.ui.tableWidgetAttr.setItem(rows, 0, QTableWidgetItem(str(uuid.uuid4())))
357
    
383

  
358 384
    '''
359 385
        @brief  delete selected attribute 
360 386
        @author kyoyho
361 387
        @date   2018.08.21
362 388
    '''
389

  
363 390
    def onDelLineNoAttr(self):
364 391
        model = self.ui.tableWidgetAttr.model()
365 392
        row = self.ui.tableWidgetAttr.currentRow()
366
        
393

  
367 394
        if row != -1:
368 395
            model.removeRow(row)
369 396

  
......
372 399
        @author     kyouho
373 400
        @date       2018.08.20
374 401
    '''
402

  
375 403
    def isNumber(self, num):
376 404
        p = re.compile('(^[0-9]+$)')
377 405
        result = p.match(num)
......
386 414
        @author     kyouho
387 415
        @date       2018.08.21
388 416
    '''
417

  
389 418
    def saveLineAttrData(self):
390 419
        appDocData = AppDocData.instance()
391 420

  
392 421
        attrs = []
393 422
        table = self.ui.tableWidgetAttr
394
        
423

  
395 424
        for index in range(table.rowCount()):
396 425
            attr = []
397 426
            attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '')
398 427
            attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '')
399 428
            attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '')
400
            attr.append(table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3).currentIndex() >= 0 else '')
401
            attr.append(int(table.item(index, 4).text()) if table.item(index, 4) is not None and self.isNumber(table.item(index, 4).text()) else None)
429
            attr.append(
430
                table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3).currentIndex() >= 0 else '')
431
            attr.append(int(table.item(index, 4).text()) if table.item(index, 4) is not None and self.isNumber(
432
                table.item(index, 4).text()) else None)
402 433
            attr.append(index)
403 434
            attrs.append(attr)
404 435

  
405
        appDocData.saveLineAttributes(attrs)
436
        appDocData.saveLineAttributes(attrs)

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)