프로젝트

일반

사용자정보

개정판 a53a67b6

IDa53a67b62be912a6ef7467c412fc6b557fcd3463
상위 1b8b3003
하위 1ba66f8d, 8a489471

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

issue #1166: Special Item 인식

Change-Id: I1d2b165277ec60d1025dbb9d05db3362a841584a

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
2875 2875
                cursor.execute(sql)
2876 2876

  
2877 2877
                # delete Points
2878
                sql = "delete from Points where Components_UID = (select UID from Components where Drawings_UID=(select UID from Drawings where Name= '{}'))".format(pidNo)
2878
                sql = "delete from Points where Components_UID in (select UID from Components where Drawings_UID=(select UID from Drawings where Name='{}'))".format(pidNo)
2879 2879
                cursor.execute(sql)
2880 2880

  
2881 2881
                # delete Components 
2882
                sql = "delete from Components where Drawings_UID = (select UID from Drawings where Name= '{}')".format(pidNo)
2882
                sql = "delete from Components where Drawings_UID = (select UID from Drawings where Name='{}')".format(pidNo)
2883 2883
                cursor.execute(sql)
2884 2884

  
2885 2885
                # delete Vendor Package
DTI_PID/DTI_PID/LineNoTracer.py
378 378
    from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem
379 379
    from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem
380 380
    from EngineeringErrorItem import QEngineeringErrorItem
381
    from EngineeringTextItem import QEngineeringTextItem
382
    from SpecialItemTypesDialog import SpecialItemTracer
381 383

  
382 384
    try:
383 385
        worker.displayMessage.emit('Initiating...')
......
464 466

  
465 467
        """ try to connect label to valve """
466 468
        labels = [symbol for symbol in symbols if type(symbol) is QEngineeringInstrumentItem and not symbol.has_connection]
467
        #print(labels[0])
468 469
        valves = [symbol for symbol in symbols if symbol.type == 'Specialty Components' or symbol.type == 'In-Line' or symbol.type == 'Relief Devices']
469
        #print(valves[0])
470 470
        for label in labels:
471 471
            label.connectAttribute(valves, clear=False)
472 472

  
......
503 503
        """ update line type """
504 504
        if update_line_type == True:
505 505
            worker.displayMessage.emit('Updating Line Type...')
506
            #lines = [line for line in worker.graphicsView.scene.items() if type(line) is QEngineeringLineItem]
507
            #for line in lines: line.lineType = 'Primary'
508 506
            for line in lines: line.update_line_type()
509 507

  
510 508
        """make end break"""
......
579 577
        for lineNo in lineNos + docdata.tracerLineNos:
580 578
            lineNo.update_flow_mark(position, length)
581 579

  
582
        '''
583
        line_names = docdata.getSymbolListByType('type', 'Flow Mark')
584
        if len(line_names) is not 0:
585
                
586
            svgFileName = line_names[0].sName
587
            symbol = docdata.getSymbolByQuery('name', svgFileName)
588
            svgFilePath = os.path.join(docdata.getCurrentProject().getSvgFilePath(), symbol.getType(), svgFileName+'.svg')
589

  
590
            allowed_error = 0.000001
591

  
592
            for lineNo in lineNos + docdata.tracerLineNos:
593
                for run in lineNo.runs:
594
                    pre = None
595
                    preRadian = None
596
                    for item in run.items:
597
                        if pre is None and type(item) is QEngineeringLineItem and (item._lineType == 'Primary' or item._lineType == 'Secondary'):
598
                            pre = item
599
                            start = item.line().p1()
600
                            end = item.line().p2()
601
                            _dir = [(end.x() - start.x())/item.length(), (end.y() - start.y())/item.length()]
602
                            radian = math.atan2(_dir[0], _dir[1]) - math.pi / 2
603
                            preRadian = radian if radian >= 0 else radian + 2 * math.pi
604
                            preDir = _dir
605
                            #print(_dir)
606
                            continue
607
                        elif type(item) is QEngineeringLineItem and (item._lineType == 'Primary' or item._lineType == 'Secondary'):
608
                            pre._flowMark = []
609
                            start = item.line().p1()
610
                            end = item.line().p2()
611
                            _dir = [(end.x() - start.x())/item.length(), (end.y() - start.y())/item.length()]
612
                            radian = math.atan2(_dir[0], _dir[1]) - math.pi / 2
613
                            currRadian = radian if radian >= 0 else radian + 2 * math.pi
614
                            if abs(currRadian - preRadian) > allowed_error:
615
                                # insert flow mark at pre line
616
                                #print(currRadian)
617
                                flow_mark = SymbolSvgItem.createItem(symbol.getType(), svgFilePath)
618
                                pt = [pre.connectors[1].center()[0] - float(symbol.getOriginalPoint().split(',')[0]) - preDir[0] * 20, pre.connectors[1].center()[1] - float(symbol.getOriginalPoint().split(',')[1]) - preDir[1] * 20]
619
                                origin = [0,0]
620
                                if 2 == len(symbol.getOriginalPoint().split(',')):
621
                                    tokens = symbol.getOriginalPoint().split(',')
622
                                    origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])]
623
                                flow_mark.buildItem(svgFileName, symbol.getType(), preRadian, pt, [flow_mark.boundingRect().width(), flow_mark.boundingRect().height()], origin, [], symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
624
                                flow_mark.setToolTip('owner : ' + str(pre))
625
                                flow_mark.area = 'Drawing'
626
                                flow_mark.owner = pre
627
                                flow_mark.setParentItem(pre)
628
                                pre._flowMark.append(flow_mark)
629
                                flow_marks.append(flow_mark)
630

  
631
                                pre = item
632
                                preDir = _dir
633
                                preRadian = currRadian
634
            
635
            for flow_mark in flow_marks:
636
                if not flow_mark.prop('Freeze'):
637
                    flow_mark.transfer.onRemoved.connect(App.mainWnd().itemRemoved)
638
                    flow_mark.addSvgItemToScene(worker.graphicsView.scene)
639
            '''
640

  
580
        # trace special item
581
        worker.displayMessage.emit('Find line for special item...')
582
        tracer = SpecialItemTracer([item for item in worker.graphicsView.scene.items() if (type(item) is SymbolSvgItem or type(item) is QEngineeringTextItem) and item.special_item_type], lines)
583
        tracer.execute(worker.displayMessage, worker.updateProgress)
584
        # up to here
641 585
    except Exception as ex:
642 586
        from App import App 
643 587
        message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py
22 22
    def __init__(self, parent=None):
23 23
        self._color = self.DEFAULT_COLOR # default color
24 24
        self._owner = None
25
        self.conns = []
25 26
        self.special_item_type = None   # UID for special item type
26 27
        self._hover = False
27 28
        self._area = None
DTI_PID/DTI_PID/Shapes/EngineeringConnectorItem.py
508 508

  
509 509
        cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y', 'Connected']
510 510
        values = ['?', '?', '?', '?', '?', '?']
511
        param = [str(self.uid), str(self.parent.uid), self.symbol_idx, self.connectPoint[0], self.connectPoint[1], str(self.connectedItem.uid) if self.connectedItem else None]
511
        param = [str(self.uid), str(self.parentItem()), self._label.toPlainText(), self.connectPoint[0], self.connectPoint[1], str(self.connectedItem.uid) if self.connectedItem else None]
512 512
        sql = 'insert or replace into Points({}) values({})'.format(','.join(cols), ','.join(values))
513 513

  
514 514
        return (sql, tuple(param))
DTI_PID/DTI_PID/Shapes/EngineeringLineNoTextItem.py
333 333
                item.loc = [x, y]
334 334
                item.size = (width, height)
335 335
                item.angle = angle
336
                #item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text))
336
                item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text))
337 337

  
338 338
                """ apply freeze value """
339 339
                #item.freeze_item.update_freeze(item.prop('Freeze'))
DTI_PID/DTI_PID/Shapes/EngineeringReducerItem.py
17 17
    ZVALUE = 20
18 18
    clicked = pyqtSignal(QGraphicsSvgItem)
19 19

  
20
    '''
21
    '''
20
    ''' '''
22 21
    def __init__(self, path, uid=None, flip=0):
23 22
        from SymbolAttr import SymbolProp
24 23

  
25 24
        SymbolSvgItem.__init__(self, path, uid, flip)
26 25
        
27
        '''
28
        self._properties = \
29
            {\
30
                SymbolProp(None, 'Main Size', 'Size Text Item', Expression='self.EvaluatedMainSize'):None, 
31
                SymbolProp(None, 'Sub Size', 'Size Text Item', Expression='self.EvaluatedSubSize'):None, 
32
                SymbolProp(None, 'Supplied By', 'String'):None
33
            }
34
        '''
35

  
36 26
        self.setZValue(QEngineeringReducerItem.ZVALUE)
37 27

  
38 28
    @property
......
173 163
        sql = 'insert or replace into VALVE_DATA_LIST({}) values({})'.format(','.join(cols), ','.join(values))
174 164
        res.append((sql, tuple(param)))
175 165

  
166
        cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Area', 'Owner', 'Connected', 'SuppliedBy', \
167
                'SpecialItemTypes_UID']
168
        values = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
169
        param = [str(self.uid), str(appDocData.activeDrawing.UID), str(self.dbUid), self.loc[0], self.loc[1], self.size[0], self.size[1], str(self.angle), 
170
        self.area, str(self.owner) if self.owner else None, \
171
        str(self.conns[0]) if self.conns else None, \
172
        self.prop('Supplied By'), \
173
        str(self.special_item_type) if self.special_item_type else None]
174
        sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
175
        res.append((sql, tuple(param)))
176

  
176 177
        _attrs = self.getAttributes()
177 178
        for key in _attrs.keys():
178 179
            cols = ['UID', 'Components_UID', 'SymbolAttribute_UID', 'Value']
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py
37 37
        self.loc = None
38 38
        self.size = None
39 39
        self.angle = 0  # angle in radian
40
        self.conns = []
41 40
        self._owner = None
42 41
        self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable)
43 42
        self.setAcceptHoverEvents(True)
......
642 641
        res = []
643 642

  
644 643
        appDocData = AppDocData.instance()
645
        cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Area', 'Value', 'Owner', 'SpecialItemTypes_UID']
646
        values = ['?', '?', "(select UID from Symbol where Name='Text' and SymbolType_UID='-1')", '?', '?', '?', '?', '?', '?', '?', '?', '?']
644
        cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Area', 'Value', 'Owner', 'Connected', \
645
                'SpecialItemTypes_UID']
646
        values = ['?', '?', "(select UID from Symbol where Name='Text' and SymbolType_UID='-1')", '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
647 647

  
648 648
        rect = self.sceneBoundingRect()
649 649
        param = [str(self.uid), str(appDocData.activeDrawing.UID), rect.x(), rect.y(), rect.width(), rect.height(), str(self.angle), 
650
        self.area, self.text(), str(self.owner) if self.owner else None, str(self.special_item_type) if self.special_item_type else None]
650
        self.area, self.text(), \
651
        str(self.owner) if self.owner else None, \
652
        str(self.conns[0]) if self.conns else None, \
653
        str(self.special_item_type) if self.special_item_type else None]
651 654
        sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
652 655
        res.append((sql, tuple(param)))
653 656

  
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
54 54
        self.flip = flip
55 55
        # attributeType uid
56 56
        self.attribute = ''
57
        #self._properties = {SymbolProp(None, 'Size', 'Size Text Item', Expression='self.EvaluatedSize'):None, SymbolProp(None, 'Supplied By', 'String'):None}
58 57
        self._properties = {SymbolProp(None, 'Supplied By', 'String'):None}
59 58

  
60 59
        self.setAcceptDrops(True)
......
406 405
        sql = 'insert or replace into VALVE_DATA_LIST({}) values({})'.format(','.join(cols), ','.join(values))
407 406
        res.append((sql, tuple(param)))
408 407

  
409
        cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Area', 'Owner', 'SpecialItemTypes_UID']
410
        values = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
408
        cols = ['UID', 'Drawings_UID', 'Symbol_UID', 'X', 'Y', 'Width', 'Height', 'Rotation', 'Area', 'Owner', 'Connected', 'SuppliedBy', \
409
                'SpecialItemTypes_UID']
410
        values = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?']
411 411
        param = [str(self.uid), str(appDocData.activeDrawing.UID), str(self.dbUid), self.loc[0], self.loc[1], self.size[0], self.size[1], str(self.angle), 
412
        self.area, str(self.owner) if self.owner else None, str(self.special_item_type) if self.special_item_type else None]
412
        self.area, str(self.owner) if self.owner else None, \
413
        str(self.conns[0]) if self.conns else None, \
414
        self.prop('Supplied By'), \
415
        str(self.special_item_type) if self.special_item_type else None]
413 416
        sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
414 417
        res.append((sql, tuple(param)))
415 418

  
......
437 440
                    2018.05.30  Jeongwoo    Add parameters (parentSymbol, childSymbol)
438 441
    '''
439 442
    def buildItem(self, name, _type, angle, loc, size, origin, connPts, parentSymbol, childSymbol, hasInstrumentLabel, dbUid=None):
443
        from SpecialItemTypesDialog import SpecialItemTypes
444

  
440 445
        try:
441 446
            docData = AppDocData.instance()
442 447
            self.name = name
......
452 457
            self.dbUid = symbolInfo.uid
453 458
            originalPoint = symbolInfo.getOriginalPoint().split(',')
454 459
            self.symbolOrigin = [float(originalPoint[0]), float(originalPoint[1])]
455
            #if self.flip is 1:
456
            #    self.symbolOrigin[0] = self.size[0] - self.symbolOrigin[0]
457 460

  
458 461
            # setting connectors
459 462
            connectionPoints = symbolInfo.getConnectionPoint().split('/')
......
485 488
                self.connectors[index].sceneConnectPoint = (connPts[index][0], connPts[index][1]) if len(connPts[index]) == 2 else \
486 489
                                                           (connPts[index][1], connPts[index][2]) if len(connPts[index]) == 3 else \
487 490
                                                           (connPts[index][1], connPts[index][2]) if len(connPts[index]) == 4 else None
488
                #print((x, y))
489
                #print(self.connectors[index].sceneConnectPoint)
490
                
491 491
            self.parentSymbol = parentSymbol
492 492
            self.childSymbol = childSymbol
493 493
            self.hasInstrumentLabel = hasInstrumentLabel
494 494
            self.currentPointModeIndex = 0
495
            self.special_item_type = SpecialItemTypes.instance().find_match_exactly(self)
495 496

  
496 497
            tooltip = '<b>{}</b><br>{}={}'.format(str(self.uid), self.type, self.name)
497 498
            self.setToolTip(tooltip)
DTI_PID/DTI_PID/SpecialItemTypesDialog.py
46 46

  
47 47
    @staticmethod
48 48
    def clearTables():
49
        SpecialItemType.SPECIAL_ITEM_TYPES = {}
49
        SpecialItemTypes.SPECIAL_ITEM_TYPES = {}
50

  
51
class SpecialItemTracer:
52
    """ This is special item tracer class """
53
    def __init__(self, special_items, lines):
54
        try:
55
            self._special_items = special_items 
56
            self._lines = lines
57
        except Exception as ex:
58
            from App import App 
59

  
60
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
61
            App.mainWnd().addMessage.emit(MessageType.Error, message)
62

  
63
    def execute(self, displayMessage, updateProgress, toler=600):
64
        """ find line item related to special item  """
65

  
66
        for special_item in self._special_items:
67
            special_item.conns.clear()
68

  
69
            min_dist = None
70
            connected = None
71
            for line in self._lines:
72
                dist = line.distanceTo((special_item.center().x(), special_item.center().y()))
73
                if (min_dist is None) or (dist < min_dist):
74
                    min_dist = dist
75
                    connected = line
76
            if (connected is not None) and (min_dist < toler): special_item.conns.append(connected)
50 77

  
51 78
class QSpecialItemTypesDialog(QDialog):
52 79
    """ This Special Item Types dialog class """
DTI_PID/DTI_PID/TextItemFactory.py
71 71
            if result[0]:
72 72
                item = QEngineeringLineNoTextItem()
73 73
                text = ''.join(result[1])
74
                item.setToolTip('<b>{}</b><br>LINE NO={}'.format(str(item.uid), text))
75 74
                item.setPlainText(text)
76 75

  
77 76
                # get color option

내보내기 Unified diff

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