프로젝트

일반

사용자정보

개정판 42d83048

ID42d8304806a11e3a5f13380ba0e772f73dc6eece
상위 971ba947
하위 05ffcb65

gaqhf 이(가) 6년 이상 전에 추가함

dev issue #482: 라인 하나로 묶어서 xml 저장 node(MERGEDLINE)

차이점 보기:

DTI_PID/DTI_PID/Shapes/EngineeringRunItem.py
92 92
        @history    Jeongwoo 2018.05.24 Add math.fabs() on sublist's if-statement
93 93
                                        Change toler(1 → 5) and Modify Longest Line's coords // Make comments Test Code
94 94
                    humkyung 2018.06.22 sort lines before writing to xml
95
                    kyouho  2018.08.09 Line 묶기
95 96
    '''
96 97
    def toXml(self):
97 98
        from xml.etree.ElementTree import Element, SubElement, dump, ElementTree
......
99 100
        from SymbolSvgItem import SymbolSvgItem
100 101

  
101 102
        try:
103
            # Line 가로, 세로 기준으로 아이템을 묶음 (라인별로)
104
            isVertical = None
105
            itemLists = []
106
            itemList = []
107
            for index in range(len(self.items)):
108
                last = False
109

  
110
                if type(self.items[index]) is QEngineeringLineItem:
111
                    lineVertical = self.items[index].isVertical()
112
                    # Line의 처음 상태 확인 후 저장
113
                    if isVertical == None:
114
                        itemList.append(self.items[index])
115
                        isVertical = lineVertical
116
                    # Line이 같은 방향이면 저장
117
                    elif isVertical == lineVertical:
118
                        itemList.append(self.items[index])
119
                    # Line이 다른 방향이면 초기화
120
                    else:
121
                        itemLists.append((itemList, isVertical))
122
                        itemList = []
123
                        isVertical = lineVertical
124
                        itemList.append(self.items[index])
125
                else:
126
                    itemList.append(self.items[index])
127

  
128
                if index == len(self.items) - 1:
129
                    itemLists.append((itemList, isVertical))
130

  
131
            # Line 별로 라인을 합친 라인을 저장
132
            mergedLines = []
133
            for list in itemLists:
134
                startPoint = []
135
                endPoint = []
136
                # direction의 0 = 낮은 값 -> 높은 값 (좌표 값 기준)
137
                direction = 0
138
                for line in list[0]:
139
                    # 통합 Line의 시작점과 끝점을 구함
140
                    if type(line) is QEngineeringLineItem:
141
                        pt1 = line.startPoint()
142
                        pt2 = line.endPoint()
143
                        if len(startPoint) == 0:
144
                            # vertical 경우
145
                            if list[1]:
146
                                # startPoint가 더 큼
147
                                if pt1[1] > pt2[1]:
148
                                    direction = 1
149
                                # endPoint가 더 큼
150
                                else:
151
                                    direction = 0
152
                            # horizontal 경우
153
                            else:
154
                                if pt1[0] > pt2[0]:
155
                                    direction = 1
156
                                else:
157
                                    direction = 0
158
                        
159
                        # start가 end로 낮은 값에서 높은 값으로
160
                        if direction == 0:
161
                            if list[1]:
162
                                if len(startPoint) == 0:
163
                                    startPoint = pt1 if pt1[1] < pt2[1] else pt2
164
                                    endPoint = pt1 if pt1[1] > pt2[1] else pt2
165
                                else:
166
                                    startPoint = startPoint if startPoint[1] < pt1[1] else pt1
167
                                    startPoint = startPoint if startPoint[1] < pt2[1] else pt2
168
                                    endPoint = endPoint if endPoint[1] > pt1[1] else pt1
169
                                    endPoint = endPoint if endPoint[1] > pt2[1] else pt2
170
                            else:
171
                                if len(startPoint) == 0:
172
                                    startPoint = pt1 if pt1[0] < pt2[0] else pt2
173
                                    endPoint = pt1 if pt1[0] > pt2[0] else pt2
174
                                else:
175
                                    startPoint = startPoint if startPoint[0] < pt1[0] else pt1
176
                                    startPoint = startPoint if startPoint[0] < pt2[0] else pt2
177
                                    endPoint = endPoint if endPoint[0] > pt1[0] else pt1
178
                                    endPoint = endPoint if endPoint[0] > pt2[0] else pt2
179
                        # start가 end로 높은 값에서 낮은 값으로
180
                        else:
181
                            if list[1]:
182
                                if len(startPoint) == 0:
183
                                    startPoint = pt1 if pt1[1] > pt2[1] else pt2
184
                                    endPoint = pt1 if pt1[1] < pt2[1] else pt2
185
                                else:
186
                                    startPoint = startPoint if startPoint[1] > pt1[1] else pt1
187
                                    startPoint = startPoint if startPoint[1] > pt2[1] else pt2
188
                                    endPoint = endPoint if endPoint[1] < pt1[1] else pt1
189
                                    endPoint = endPoint if endPoint[1] < pt2[1] else pt2
190
                            else:
191
                                if len(startPoint) == 0:
192
                                    startPoint = pt1 if pt1[0] > pt2[0] else pt2
193
                                    endPoint = pt1 if pt1[0] < pt2[0] else pt2
194
                                else:
195
                                    startPoint = startPoint if startPoint[0] > pt1[0] else pt1
196
                                    startPoint = startPoint if startPoint[0] > pt2[0] else pt2
197
                                    endPoint = endPoint if endPoint[0] < pt1[0] else pt1
198
                                    endPoint = endPoint if endPoint[0] < pt2[0] else pt2
199

  
200
                # 통합 Line을 추가
201
                if len(startPoint) == 2 and len(endPoint) == 2:
202
                    allLine = QEngineeringLineItem([startPoint, endPoint])
203
                    mergedLines.append(allLine)
204

  
102 205
            node = Element('RUN')
206
            # append merged Line 
207
            mergeNode = Element('MERGEDLINE')
208
            for line in mergedLines:
209
                mergeNode.append(line.toXml())
210
            node.append(mergeNode)
103 211

  
104 212
            for item in self.items:
105 213
                # skip line item which's connected items are same
106
                if (type(item) is QEngineeringLineItem) and (item.conns[0] is item.conns[1]):
214
                if (type(item) is QEngineeringLineItem) and (item.connectors[0].connectedItem is item.connectors[1].connectedItem):
107 215
                    continue
108 216
                # up to here
109 217

  
......
112 220
            connectedSymbols = [item for item in self.items if issubclass(type(item), SymbolSvgItem)]
113 221
            for item in connectedSymbols:
114 222
                item.toXmlAsAttribute(node)
115
        except Exception as ex:
223

  
224

  
225

  
226

  
227
        except Exception as ex: 
116 228
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
117 229

  
118
        return node 
230
        return node

내보내기 Unified diff

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