프로젝트

일반

사용자정보

개정판 15e26d1c

ID15e26d1c0572cf75f10b2c188e93eda78e51f675
상위 517c793e
하위 0fcc5855, a247f7e8, ccb42e9b

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

Implementing issue #489: Trim Line 처리

차이점 보기:

DTI_PID/DTI_PID/LineNoTracer.py
8 8
import shapely
9 9
from AppDocData import AppDocData
10 10

  
11
#sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Shapes'))
12
#import QEngineeringLineItem
13

  
14 11
class LineNoTracer:
15 12
    '''
16 13
        @history    2018.04.26 Jeongwoo Variable name changed (texts → lineNos)
......
26 23
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
27 24

  
28 25
    '''
26
        @brief  find primary lines connected to given line no
27
        @author humkyung
28
    '''
29
    def findPrimaryLines(self, lineno):
30
        from QEngineeringLineItem import QEngineeringLineItem
31
        from QEngineeringRunItem import QEngineeringRunItem
32

  
33
        connectedItems = []
34
        if 1 == len(lineno.conns):
35
            connectedItems = self.findConnectedObjects(lineno.conns[0], toler=10)
36
            for item in connectedItems: item.owner = lineno # set item's owner
37
            
38
            pipeRun = QEngineeringRunItem()
39
            pipeRun.items = connectedItems
40
            lineno.runs.append(pipeRun)
41

  
42
            connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
43
            
44
            maxLength = None
45
            maxLengthItem = None
46
            for line in connectedLines:
47
                length = line.length()
48
                if maxLength is None or maxLength < length:
49
                    maxLength = length
50
                    maxLengthItem = line
51

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

  
54
        return connectedItems
55

  
56
    '''
57
        @brief  find secondary lines
58
        @author humkyung
59
    '''
60
    def findSecondaryLines(self, lines):
61
        from QEngineeringLineItem import QEngineeringLineItem
62
        from QEngineeringRunItem import QEngineeringRunItem
63

  
64
        foundCount = 1
65
        while foundCount:
66
            foundCount = 0
67
            notMatches = []
68
            for line in lines:
69
                if line.owner is not None: continue
70

  
71
                matches = [x for x in self._lines if x.owner is not None and x.isConnectable(line)]
72
                if matches:
73
                    foundCount += 1
74
                    connectedItems = self.findConnectedObjects(line, toler=10)
75
                    for item in connectedItems: item.owner = matches[0].owner   # set item's owner
76

  
77
                    pipeRun = QEngineeringRunItem()
78
                    pipeRun.items = connectedItems
79
                    if pipeRun.items is not None and len(pipeRun.items) > 0:
80
                        matches[0].owner.runs.append(pipeRun)
81

  
82
                    connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
83
                
84
                    maxLength = None
85
                    maxLengthItem = None
86
                    for line in connectedLines:
87
                        length = line.length()
88
                        if maxLength is None or maxLength < length:
89
                            maxLength = length
90
                            maxLengthItem = line
91

  
92
                    if maxLengthItem is not None: maxLengthItem.addFlowArrow()  # TODO: check error scene() returns None
93
                else:
94
                    notMatches.append(line)
95
            lines = notMatches
96

  
97
    '''
29 98
        @brief      trace line no
30 99
        @author     humkyung
31 100
        @date       2018.04.16
......
41 110
        from QEngineeringLineItem import QEngineeringLineItem
42 111
        from SymbolSvgItem import SymbolSvgItem
43 112
        from QEngineeringRunItem import QEngineeringRunItem
113
        from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem
44 114

  
45 115
        try:
46 116
            docData = AppDocData.instance()
......
70 140
    
71 141
                # find primary lines
72 142
                for lineno in docData.lineNos:
73
                    if 1 == len(lineno.conns):
74
                        connectedItems = self.findConnectedObjects(lineno.conns[0], toler=10)
75
                        for item in connectedItems: item.owner = lineno # set item's owner
76
                        
77
                        pipeRun = QEngineeringRunItem()
78
                        pipeRun.items = connectedItems
79
                        lineno.runs.append(pipeRun)
80

  
81
                        connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
82
                        
83
                        maxLength = None
84
                        maxLengthItem = None
85
                        for line in connectedLines:
86
                            length = line.length()
87
                            if maxLength is None or maxLength < length:
88
                                maxLength = length
89
                                maxLengthItem = line
90

  
91
                        if maxLengthItem is not None: maxLengthItem.addFlowArrow()  # TODO: check error scene() returns None
143
                    self.findPrimaryLines(lineno)
92 144

  
93 145
                # find secondary lines
94 146
                lines = self._lines
95
                foundCount = 1
96
                while foundCount:
97
                    foundCount = 0
98
                    notMatches = []
99
                    for line in lines:
100
                        if line.owner is not None: continue
101

  
102
                        matches = [x for x in self._lines if x.owner is not None and x.isConnectable(line)]
103
                        if matches:
104
                            foundCount += 1
105
                            connectedItems = self.findConnectedObjects(line, toler=10)
106
                            for item in connectedItems: item.owner = matches[0].owner   # set item's owner
107

  
108
                            pipeRun = QEngineeringRunItem()
109
                            pipeRun.items = connectedItems
110
                            if pipeRun.items is not None and len(pipeRun.items) > 0:
111
                                matches[0].owner.runs.append(pipeRun)
112

  
113
                            connectedLines = [item for item in connectedItems if type(item) is QEngineeringLineItem]
114
                        
115
                            maxLength = None
116
                            maxLengthItem = None
117
                            for line in connectedLines:
118
                                length = line.length()
119
                                if maxLength is None or maxLength < length:
120
                                    maxLength = length
121
                                    maxLengthItem = line
122

  
123
                            if maxLengthItem is not None: maxLengthItem.addFlowArrow()  # TODO: check error scene() returns None
124
                        else:
125
                            notMatches.append(line)
126
                    lines = notMatches
147
                self.findSecondaryLines(lines)
148

  
149
            ### make trim lines
150
            orphanLines = [line for line in self._lines if line.owner is None] 
151
            if orphanLines:
152
                orphanLines = sorted(orphanLines, key=lambda param:param.length(), reverse=True)
153
                while len(orphanLines) > 0:
154
                    trimLineNo = QEngineeringTrimLineNoTextItem()
155
                    trimLineNo.conns.append(orphanLines[0])
156
                    orphanLines[0].owner = trimLineNo
157
                    connectedItems = self.findPrimaryLines(trimLineNo)
158
                    for item in connectedItems:
159
                        if item in orphanLines: orphanLines.remove(item)
160

  
161
                    self.findSecondaryLines(orphanLines)
162
                    for item in orphanLines[:]:
163
                        if item.owner is not None: orphanLines.remove(item)
164

  
165
                    docData.lineNos.append(trimLineNo)
166

  
127 167
        except Exception as ex:
128 168
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
129 169

  

내보내기 Unified diff