프로젝트

일반

사용자정보

개정판 4d03a31c

ID4d03a31c67e09cee87616afecce993d4638616b4
상위 8783588b
하위 86c5a909, fc832cc3

함의성이(가) 5년 이상 전에 추가함

issue #663: add line type for connector and fix auto connection

Change-Id: I502298e49c361ea48ec01cbc2cce75529843a449

차이점 보기:

DTI_PID/DTI_PID/Configs.py
50 50
                            else:
51 51
                                return (False,)
52 52
                        elif lineProp[0].Length:
53
                            _text = _text[:lineProp[0].Length].replace('o', '0').replace('O', '0') + _text[lineProp[0].Length:]
53 54
                            match = re.search(re.compile('^[0-9]{{{}}}'.format(lineProp[0].Length)), _text)
54 55
                            if match:
55 56
                                _text = _text[len(match.group(match.start())):len(_text)]
DTI_PID/DTI_PID/LineDetector.py
345 345
            else:
346 346
                endPt[0] += dx
347 347

  
348
            line.set_line([[distStart[0][1][0],distStart[0][1][1]], endPt])
349
            line.connect_if_possible(symbol, toler)
348
            if line.connect_if_possible(symbol, toler):
349
                line.set_line([[distStart[0][1][0],distStart[0][1][1]], endPt])
350 350
        else:
351 351
            dx = distEnd[0][1][0] - endPt[0]
352 352
            dy = distEnd[0][1][1] - endPt[1]
......
356 356
            else:
357 357
                startPt[0] += dx
358 358

  
359
            line.set_line([startPt, [distEnd[0][1][0],distEnd[0][1][1]]])
360
            line.connect_if_possible(symbol, toler)
361

  
359
            if line.connect_if_possible(symbol, toler):
360
                line.set_line([startPt, [distEnd[0][1][0],distEnd[0][1][1]]])
361
                
362 362
    '''
363 363
        @brief  extend line to intersection point
364 364
        @author humkyung
DTI_PID/DTI_PID/RecognitionDialog.py
512 512
                            conn.connectedItem = None
513 513
                        worker.graphicsView.scene.removeItem(lineItem)
514 514

  
515
                    listWidget.addItem('Connecting lines')
516
                    area = app_doc_data.getArea('Drawing')
517
                    detector = LineDetector(area.img)
518
                    symbols = app_doc_data.symbols
519
                    configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line')
520
                    toler = int(configs[0].value) if configs else 20
521
                    if app_doc_data.lines:
522
                        # connect line to line
523
                        try:
524
                            for line in app_doc_data.lines:
525
                                matches = [it for it in app_doc_data.lines if
526
                                           (it is not line) and (not line.isParallel(it))]
527

  
528
                                # get closest line
529
                                selected = []
530
                                for match in matches:
531
                                    dist = [line.distanceTo(match.startPoint()), line.distanceTo(match.endPoint())]
532
                                    if dist[0] < toler or dist[1] < toler:
533
                                        selected.append(match)
534
                                # up to here
535

  
536
                                for match in matches:
537
                                    detector.connectLineToLine(match, line, toler)
538
                        except Exception as ex:
539
                            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[
540
                                -1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
541
                            worker.displayLog.emit(MessageType.Error, message)
542
                        # up to here
543

  
544
                        # connect line to symbol
545
                        try:
546
                            for line in app_doc_data.lines:
547
                                matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)]
548
                                for symbol in matches:
549
                                    detector.connectLineToSymbol(line, symbol, toler=round(toler / 2))
550
                        except Exception as ex:
551
                            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[
552
                                -1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
553
                            worker.displayLog.emit(MessageType.Error, message)
554
                        # up to here
555

  
556 515
                # connect symbol to symbol
557 516
                try:
558 517
                    configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line')
......
569 528
                    worker.displayLog.emit(MessageType.Error, message)
570 529
                # up to here
571 530

  
531
                listWidget.addItem('Connecting lines')
532
                area = app_doc_data.getArea('Drawing')
533
                detector = LineDetector(area.img)
534
                symbols = app_doc_data.symbols
535
                configs = app_doc_data.getConfigs('Line Detector', 'Length to connect line')
536
                toler = int(configs[0].value) if configs else 20
537
                if app_doc_data.lines:
538
                    # connect line to line
539
                    try:
540
                        for line in app_doc_data.lines:
541
                            matches = [it for it in app_doc_data.lines if
542
                                       (it is not line) and (not line.isParallel(it))]
543

  
544
                            for match in matches:
545
                                detector.connectLineToLine(match, line, toler)
546
                    except Exception as ex:
547
                        message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[
548
                            -1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
549
                        worker.displayLog.emit(MessageType.Error, message)
550
                    # up to here
551

  
552
                    # connect line to symbol
553
                    try:
554
                        for line in app_doc_data.lines:
555
                            matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)]
556
                            for symbol in matches:
557
                                detector.connectLineToSymbol(line, symbol, toler=toler)
558

  
559
                        # change line type using symbol connection type(info)
560
                        for sym in symbols:
561
                            if sym.conn_type:
562
                                for index in range(len(sym.conn_type)):
563
                                    item = sym.connectors[index].connectedItem
564
                                    if item and type(item) is QEngineeringLineItem:
565
                                        Worker.changeConnectedLineType(item, sym.conn_type[index])
566
                    except Exception as ex:
567
                        message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[
568
                            -1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
569
                        worker.displayLog.emit(MessageType.Error, message)
570
                    # up to here
571

  
572 572
                createUnknownItems(mainRes)
573 573

  
574 574
                worker.updateBatchProgress.emit(len(srcList), 1)
......
579 579
        finally:
580 580
            pass
581 581

  
582
    @staticmethod
583
    def changeConnectedLineType(line, lineType):
584
        line.lineType = lineType
585
        if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \
586
                (line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \
587
                line.connectors[0].connectedItem.lineType is not lineType:
588
            Worker.changeConnectedLineType(line.connectors[0].connectedItem, lineType)
589
        if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \
590
                (line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \
591
                line.connectors[1].connectedItem.lineType is not lineType:
592
            Worker.changeConnectedLineType(line.connectors[1].connectedItem, lineType)
593

  
582 594
    '''
583 595
        @history    2018.05.25  Jeongwoo    Moved from MainWindow
584 596
                    2018.05.28  Jeongwoo    Add xmlPath Parameter and append LineInfo into xml
......
609 621
                for item in items:
610 622
                    item.transfer.onRemoved.emit(item)
611 623
                    # worker.graphicsView.scene.removeItem(item)
612

  
613 624
            # up to here
614 625

  
615 626
            # detect line
......
647 658
                appDocData.lines.append(processLine)
648 659
                appDocData.allItems.append(processLine)
649 660

  
650
                # if processLine.length() > 100: # TODO: check critical length
651
                #    processLine.addFlowArrow()
652

  
653
            listWidget.addItem('Connecting lines')
654
            if appDocData.lines:
655
                # connect line to symbol
656
                try:
657
                    for line in appDocData.lines:
658
                        matches = [symbol for symbol in symbols if symbol.is_connectable(line, toler=toler)]
659
                        for symbol in matches:
660
                            detector.connectLineToSymbol(line, symbol, toler=round(toler / 2))
661
                except Exception as ex:
662
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
663
                                                                  sys.exc_info()[-1].tb_lineno)
664
                    worker.displayLog.emit(MessageType.Error, message)
665
                # up to here
666

  
667
                # connect line to line
668
                configs = appDocData.getConfigs('Line Detector', 'Length to connect line')
669
                toler = int(configs[0].value) if configs else 20
670
                try:
671
                    for line in appDocData.lines:
672
                        matches = [it for it in appDocData.lines if (it is not line) and (not line.isParallel(it))]
673

  
674
                        # get closest line
675
                        selected = []
676
                        for match in matches:
677
                            dist = [line.distanceTo(match.startPoint()), line.distanceTo(match.endPoint())]
678
                            if dist[0] < toler or dist[1] < toler:
679
                                selected.append(match)
680
                        # up to here
681

  
682
                        for match in matches:
683
                            detector.connectLineToLine(match, line, toler)
684
                except Exception as ex:
685
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
686
                                                                  sys.exc_info()[-1].tb_lineno)
687
                    worker.displayLog.emit(MessageType.Error, message)
688
                # up to here
689

  
690
            listWidget.addItem(worker.tr('Creating lines...'))
691

  
692 661
            """
693 662
            for pts in connectedLines:
694 663
                processLine = QEngineeringLineItem(vertices=[(area.x + param[0], area.y + param[1]) for param in pts[:-1]], thickness=pts[2])
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py
608 608
        @history    humkyung 2018.05.08 check if line is possible to be connected
609 609
                    Jeongwoo 2018.05.15 Split if-statement and Connect each symbol and line
610 610
    '''
611
    def connect_if_possible(self, obj, toler):
611
    def connect_if_possible(self, obj, toler=20):
612 612
        """ connect line or symbol is able to be connected and return symbol or line connected to connectors """
613 613

  
614 614
        from shapely.geometry import Point
......
624 624
            if issubclass(type(obj), SymbolSvgItem):
625 625
                for i in range(len(obj.connectors)):
626 626
                    pt = obj.connectors[i].sceneConnectPoint
627

  
628 627
                    if (Point(startPt[0], startPt[1]).distance(Point(pt[0], pt[1])) < toler):
629
                        if self.connectors[0].connectedItem is None:
628
                        if self.connectors[0].connectedItem is None and obj.connectors[i].connectedItem is None:
630 629
                            self.connectors[0].connect(obj) 
631
                        if obj.connectors[i].connectedItem is None:
632 630
                            obj.connectors[i].connect(self)
633

  
634
                        res.append(obj)
635
                    if (Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler):
636
                        if self.connectors[1].connectedItem is None:
631
                            res.append(obj)
632
                    elif (Point(endPt[0], endPt[1]).distance(Point(pt[0], pt[1])) < toler):
633
                        if self.connectors[1].connectedItem is None and obj.connectors[i].connectedItem is None:
637 634
                            self.connectors[1].connect(obj)
638
                        if obj.connectors[i].connectedItem is None:
639 635
                            obj.connectors[i].connect(self)
640

  
641
                        res.append(obj)
636
                            res.append(obj)
642 637
            elif type(obj) is QEngineeringLineItem:
643 638
                _startPt = obj.startPoint()
644 639
                _endPt = obj.endPoint()
......
654 649
                    else:
655 650
                        obj.connectors[0].connect(self, at=QEngineeringAbstractItem.CONNECTED_AT_BODY)
656 651

  
657
                if self.distanceTo(_endPt) < toler:
652
                elif self.distanceTo(_endPt) < toler:
658 653
                    if ((Point(startPt[0], startPt[1]).distance(Point(_endPt[0], _endPt[1])) < toler)):
659 654
                        self.connectors[0].connect(obj)
660 655
                        obj.connectors[1].connect(self)
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
72 72

  
73 73
        self.in_out_connector = [[], []] # 0 : in, 1 : out
74 74
        self.break_connector = []
75
        self.conn_type = []
75 76

  
76 77
        try:
77 78
            f = QFile(path)
......
599 600
                if len(tokens) == 2:
600 601
                    x = float(tokens[0])
601 602
                    y = float(tokens[1])
602
                elif len(tokens) == 3:
603
                    direction = tokens[0]
604
                    x = float(tokens[1])
605
                    y = float(tokens[2])
606
                elif len(tokens) == 4:
607
                    direction = tokens[0]
608
                    x = float(tokens[1])
609
                    y = float(tokens[2])
610
                    symbol_idx = tokens[3]
611
                elif len(tokens) > 4:
603
                elif len(tokens) >= 3:
612 604
                    direction = tokens[0]
613 605
                    x = float(tokens[1])
614 606
                    y = float(tokens[2])
607
                if len(tokens) >= 4:
615 608
                    symbol_idx = tokens[3]
609
                if len(tokens) >= 6:
616 610
                    if tokens[4] == 'In':
617 611
                        self.in_out_connector[0].append(index)
618 612
                    elif tokens[4] == 'Out':
619 613
                        self.in_out_connector[1].append(index)
620 614
                    if tokens[5] == 'O':
621 615
                        self.break_connector.append(index)
616
                if len(tokens) >= 7:
617
                    self.conn_type.append(tokens[6])
622 618

  
623 619
                self.setConnector(index + 1)
624 620
                self.connectors[index].direction = direction
DTI_PID/DTI_PID/SymbolEditorDialog.py
15 15

  
16 16
import SymbolEditor_UI
17 17
from AppDocData import * 
18
from LineTypeConditions import LineTypeConditions
18 19

  
19 20
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
20 21
import CropCommand, HandCommand, ZoomCommand, PenCommand, EraserCommand, AreaEraserCommand, OriginalPointCommand, ConnectionPointCommand, AreaZoomCommand, FitImageCommand, RemoveTextCommand, RotateImageCommand, FlipImageCommand
......
43 44
            self.project = project
44 45
            self.ui = SymbolEditor_UI.Ui_Dialog()
45 46
            self.ui.setupUi(self)
46
            self.ui.tableWidgetConnList.setColumnCount(5)
47
            self.ui.tableWidgetConnList.setHorizontalHeaderLabels([self.tr('Position'), self.tr('Direction'), self.tr('Symbol'), self.tr('In_out'), self.tr('Break')])
47
            self.ui.tableWidgetConnList.setColumnCount(6)
48
            self.ui.tableWidgetConnList.setHorizontalHeaderLabels([self.tr('Position'), self.tr('Direction'), self.tr('Symbol'), self.tr('In_out'), self.tr('Break'), self.tr('Type')])
48 49
            self.ui.tableWidgetConnList.horizontalHeaderItem(0).setSizeHint(QSize(25, 25))
49 50
            self.ui.tableWidgetConnList.itemPressed.connect(self.onConnPtPressed)
50 51

  
......
303 304
                        symbol_idx = '0'
304 305
                        in_out = 'None'
305 306
                        break_or_not = 'X'
307
                        configs = AppDocData.instance().getConfigs('Line', 'Default Type')
308
                        conn_type = configs[0].value if 1 == len(configs) else 'Secondary'
306 309
                        tokens = conString.split(',')
307
                        if len(tokens) == 4:
308
                            direction = tokens[0]
309
                            x = tokens[1]
310
                            y = tokens[2]
311
                            symbol_idx = tokens[3]
312
                        elif len(tokens) == 3:
313
                            direction = tokens[0]
314
                            x = tokens[1]
315
                            y = tokens[2]
316
                        elif len(tokens) == 2:
317
                            x = tokens[0]
318
                            y = tokens[1]
319
                        elif len(tokens) > 4:
310
                        if len(tokens) == 2:
311
                            x = float(tokens[0])
312
                            y = float(tokens[1])
313
                        elif len(tokens) >= 3:
320 314
                            direction = tokens[0]
321 315
                            x = float(tokens[1])
322 316
                            y = float(tokens[2])
317
                        if len(tokens) >= 4:
323 318
                            symbol_idx = tokens[3]
319
                        if len(tokens) >= 6:
324 320
                            in_out = tokens[4]
325 321
                            break_or_not = tokens[5]
322
                        if len(tokens) >= 7:
323
                            conn_type = tokens[6]
326 324

  
327 325
                        conn = ConnectionPointCommand.ConnectionPointCommand.drawCircle(self.ui.imageView, x, y, self.conn_index)
328 326
                        self.conn_index += 1
......
347 345
                        self.ui.tableWidgetConnList.setCellWidget(row, 2, symbol_idx_combobox)
348 346
                        # up to here
349 347

  
350
                        in_out_ComboBox = QComboBox(self.ui.tableWidgetConnList)
351
                        in_out_ComboBox.addItems(['None', 'In', 'Out'])
352
                        in_out_ComboBox.setCurrentText(in_out)
353
                        self.ui.tableWidgetConnList.setCellWidget(row, 3, in_out_ComboBox)
348
                        in_out_combobox = QComboBox(self.ui.tableWidgetConnList)
349
                        in_out_combobox.addItems(['None', 'In', 'Out'])
350
                        in_out_combobox.setCurrentText(in_out)
351
                        self.ui.tableWidgetConnList.setCellWidget(row, 3, in_out_combobox)
354 352

  
355 353
                        break_ComboBox = QComboBox(self.ui.tableWidgetConnList)
356 354
                        break_ComboBox.addItems(['O', 'X'])
357 355
                        break_ComboBox.setCurrentText(break_or_not)
358 356
                        self.ui.tableWidgetConnList.setCellWidget(row, 4, break_ComboBox)
359 357

  
358
                        conn_type_combobox = QComboBox(self.ui.tableWidgetConnList)
359
                        conn_type_combobox.addItems([lineType.name for lineType in LineTypeConditions.items()])
360
                        conn_type_combobox.setCurrentText(conn_type)
361
                        self.ui.tableWidgetConnList.setCellWidget(row, 5, conn_type_combobox)
362

  
360 363
                        row = row + 1
361 364

  
362 365
                    self.ui.tableWidgetConnList.resizeColumnsToContents()
......
516 519
            symbol_idx = self.ui.tableWidgetConnList.cellWidget(row, 2).currentText()
517 520
            in_out = self.ui.tableWidgetConnList.cellWidget(row, 3).currentText()
518 521
            break_or_not = self.ui.tableWidgetConnList.cellWidget(row, 4).currentText()
522
            conn_type = self.ui.tableWidgetConnList.cellWidget(row, 5).currentText()
519 523

  
520
            connPtString = '{},{},{},{},{}'.format(direction, self.ui.tableWidgetConnList.item(row, 0).text(), symbol_idx, in_out, break_or_not)
524
            connPtString = '{},{},{},{},{},{}'.format(direction, self.ui.tableWidgetConnList.item(row, 0).text(), symbol_idx, in_out, break_or_not, conn_type)
521 525
            connPtStringList.append(connPtString)
522 526

  
523 527
        res = '/'.join(connPtStringList)
......
830 834
            self.ui.tableWidgetConnList.setCellWidget(rows, 2, symbol_idx_combobox)
831 835
            # up to here
832 836

  
833
            in_out_ComboBox = QComboBox(self.ui.tableWidgetConnList)
834
            in_out_ComboBox.addItems(['None', 'In', 'Out'])
835
            in_out_ComboBox.setCurrentText('None')
836
            self.ui.tableWidgetConnList.setCellWidget(rows, 3, in_out_ComboBox)
837
            in_out_combobox = QComboBox(self.ui.tableWidgetConnList)
838
            in_out_combobox.addItems(['None', 'In', 'Out'])
839
            in_out_combobox.setCurrentText('None')
840
            self.ui.tableWidgetConnList.setCellWidget(rows, 3, in_out_combobox)
837 841

  
838 842
            break_ComboBox = QComboBox(self.ui.tableWidgetConnList)
839 843
            break_ComboBox.addItems(['O', 'X'])
840 844
            break_ComboBox.setCurrentText('X')
841 845
            self.ui.tableWidgetConnList.setCellWidget(rows, 4, break_ComboBox)
842 846

  
847
            conn_type_combobox = QComboBox(self.ui.tableWidgetConnList)
848
            conn_type_combobox.addItems([lineType.name for lineType in LineTypeConditions.items()])
849
            conn_type_combobox.setCurrentText(conn_type)
850
            self.ui.tableWidgetConnList.setCellWidget(row, 5, conn_type_combobox)
851

  
843 852
            self.conn_index += 1
844 853
            
845 854
            self.ui.tableWidgetConnList.resizeColumnsToContents()
DTI_PID/DTI_PID/SymbolEditor_UI.py
11 11
class Ui_Dialog(object):
12 12
    def setupUi(self, Dialog):
13 13
        Dialog.setObjectName("Dialog")
14
        Dialog.resize(1280, 823)
14
        Dialog.resize(1477, 823)
15 15
        Dialog.setMinimumSize(QtCore.QSize(1280, 720))
16 16
        Dialog.setMaximumSize(QtCore.QSize(16777215, 16777215))
17 17
        font = QtGui.QFont()
......
317 317
        self.verticalLayout_2.addWidget(self.imageViewContainer)
318 318
        self.gridLayout.addLayout(self.verticalLayout_2, 0, 1, 1, 1)
319 319
        self.widget = QtWidgets.QWidget(self.splitter)
320
        self.widget.setMinimumSize(QtCore.QSize(500, 0))
320
        self.widget.setMinimumSize(QtCore.QSize(650, 0))
321 321
        self.widget.setMaximumSize(QtCore.QSize(500, 16777215))
322 322
        self.widget.setObjectName("widget")
323 323
        self.gridLayout_2 = QtWidgets.QGridLayout(self.widget)
......
332 332
        self.scrollArea.setWidgetResizable(True)
333 333
        self.scrollArea.setObjectName("scrollArea")
334 334
        self.scrollAreaWidgetContents = QtWidgets.QWidget()
335
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 478, 754))
335
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 628, 754))
336 336
        self.scrollAreaWidgetContents.setMinimumSize(QtCore.QSize(378, 0))
337 337
        self.scrollAreaWidgetContents.setMaximumSize(QtCore.QSize(16777215, 16777215))
338 338
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
DTI_PID/DTI_PID/UI/SymbolEditor.ui
6 6
   <rect>
7 7
    <x>0</x>
8 8
    <y>0</y>
9
    <width>1280</width>
9
    <width>1477</width>
10 10
    <height>823</height>
11 11
   </rect>
12 12
  </property>
......
688 688
     <widget class="QWidget" name="widget" native="true">
689 689
      <property name="minimumSize">
690 690
       <size>
691
        <width>500</width>
691
        <width>650</width>
692 692
        <height>0</height>
693 693
       </size>
694 694
      </property>
......
726 726
             <rect>
727 727
              <x>0</x>
728 728
              <y>0</y>
729
              <width>478</width>
729
              <width>628</width>
730 730
              <height>754</height>
731 731
             </rect>
732 732
            </property>

내보내기 Unified diff

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