프로젝트

일반

사용자정보

개정판 f90c018b

IDf90c018b439f05f5e3e0d5178a661c4de0d0a695
상위 d1576bff
하위 ce9281d7

humkyung 이(가) 약 7년 전에 추가함

Find secondary lines

차이점 보기:

DTI_PID/DTI_PID/LineNoTracer.py
17 17
    '''
18 18
    def __init__(self, symbols, lines, lineNos):
19 19
        try:
20
            self.symbols = symbols
21
            self.lines = lines
22
            self.lineNos = lineNos
20
            self._symbols = symbols
21
            for symbol in self._symbols: symbol.owner = None
22
            self._lines = lines
23
            for line in self._lines: line.owner = None
24
            self._lineNos = lineNos
23 25
        except Exception as ex:
24 26
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
25 27

  
......
42 44
                configs = docData.getConfigs('Line No', 'Configuration')
43 45

  
44 46
                docData.lineNos.clear()
45
                for lineNo in self.lineNos: lineNo.conns.clear()
46
                docData.lineNos = self.lineNos
47
                for lineNo in self._lineNos: lineNo.conns.clear()
48
                docData.lineNos = self._lineNos
47 49
                for lineno in docData.lineNos:
48 50
                    minDist = None
49 51
                    startLine = None
50
                    for line in self.lines:
52
                    for line in self._lines:
51 53
                        dist = line.distanceTo((lineno.center().x(), lineno.center().y()))
52 54
                        if (minDist is None) or (dist < minDist):
53 55
                            minDist = dist
......
55 57
                    if (startLine is not None) and (minDist < toler):
56 58
                        lineno.conns.append(startLine)
57 59
                
60
                # find primary lines
58 61
                for lineno in docData.lineNos:
59 62
                    if 1 == len(lineno.conns):
60 63
                        self.findConnectedObjects(lineno.conns[0], toler=10)
61 64
                        connectedItems = lineno.getConnectedItems()
65
                        for item in connectedItems: item.owner = lineno # set item's owner
66
                        
67
                        connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
68
                        
69
                        maxLength = None
70
                        maxLengthItem = None
71
                        for line in connectedLines:
72
                            length = line.length()
73
                            if maxLength is None or maxLength < length:
74
                                maxLength = length
75
                                maxLengthItem = line
76

  
77
                        if maxLengthItem is not None: maxLengthItem.addFlowArrow()  # TODO: check error scene() returns None
78

  
79
                # find secondary lines
80
                for line in self._lines:
81
                    if line.owner is not None: continue
82

  
83
                    matches = [x for x in self._lines if x.owner is not None and x.isConnectable(line)]
84
                    if matches:
85
                        connectedItems = self.findConnectedObjects(line, toler=10)
86
                        for item in connectedItems: item.owner = matches[0]
87

  
62 88
                        connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
63 89
                        
64 90
                        maxLength = None
......
86 112
        pool = []
87 113
        pool.append(startLine)
88 114
        
89
        visited = []
115
        visited = [startLine]
90 116
        while len(pool) > 0:
91 117
            obj = pool.pop()
92 118
            if type(obj) is QEngineeringLineItem:
93
                matches = [x for x in self.symbols if (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
119
                matches = [x for x in self._symbols if (x.owner is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
94 120
                if not matches:
95
                    matches = [x for x in self.lines if (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
121
                    matches = [x for x in self._lines if (x.owner is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
96 122
            elif issubclass(type(obj), SymbolSvgItem):
97
                matches = [x for x in self.lines if (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
123
                matches = [x for x in self._lines if (x.owner is None) and (x not in visited) and len(obj.connectIfPossible(x, toler)) > 0]
98 124
                if not matches:
99
                    matches = [x for x in self.symbols if (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
125
                    matches = [x for x in self._symbols if (x.owner is None) and (x is not obj) and (x not in visited) and (len(obj.connectIfPossible(x, toler)) > 0)]
100 126

  
101 127
            for match in matches:
102 128
                pool.append(match)
103 129
                visited.append(match)
130

  
131
        return visited
DTI_PID/DTI_PID/Shapes/QEngineeringAbstractItem.py
1 1
from PyQt5.QtCore import pyqtSignal, QObject
2 2

  
3 3
class QEngineeringAbstractItem(QObject):
4
    def __init__():
4
    def __init__(self):
5 5
        super(QEngineeringAbstractItem, self).__init__()
6 6

  
7
        self._owner = None
8

  
7 9
    '''
8 10
        @brief      Abstract method. Variable [color] is RGB hex code
9 11
        @author     Jeongwoo
......
13 15
        raise NotImplementedError
14 16

  
15 17
    def getColor(self):
16
        raise NotImplementedError
18
        raise NotImplementedError
19

  
20
    '''
21
        @brief  getter of owner
22
        @author humkyung
23
        @date   2018.05.12
24
    '''
25
    @property
26
    def owner(self):
27
        return self._owner 
28

  
29
    '''
30
        @brief  setter of owner
31
        @author humkyung
32
        @date   2018.05.12
33
    '''
34
    @owner.setter
35
    def owner(self, value):
36
        self._owner = value
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py
187 187
        return lhs.intersection(rhs)
188 188

  
189 189
    '''
190
        @brief  check if two lines are connectable
191
        @author humkyung
192
        @date   2018.05.12
193
    '''
194
    def isConnectable(self, line):
195
        import math
196

  
197
        startPt = line.startPoint()
198
        endPt = line.endPoint()
199

  
200
        dx = endPt[0] - startPt[0]
201
        dy = endPt[1] - startPt[1]
202
        length = math.sqrt(dx*dx + dy*dy)
203
        dx /= length
204
        dy /= length
205
        extendedLine = [(startPt[0]+dx*20, startPt[1]+dy*20), (endPt[0]-dx*20, endPt[1]-dy*20)]
206
        pt = self.intersection(extendedLine)
207

  
208
        return (pt is not None)
209

  
210
    '''
190 211
        @brief      connect line and symbol is able to be connected and return symbol
191 212
        @author     humkyung
192 213
        @date       2018.04.16

내보내기 Unified diff