프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / LineNoTracer.py @ 1d2a9f33

이력 | 보기 | 이력해설 | 다운로드 (28.9 KB)

1
# coding: utf-8
2
""" This is line no tracer module """
3

    
4
import sys
5
import math
6
import shapely
7
from AppDocData import AppDocData, MessageType
8
from EngineeringLineItem import QEngineeringLineItem
9
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
10
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem
11
from SymbolSvgItem import SymbolSvgItem
12
from EngineeringTextItem import QEngineeringTextItem
13
from EngineeringUnknownItem import QEngineeringUnknownItem
14
try:
15
    from PyQt5.QtCore import *
16
    from PyQt5.QtGui import *
17
    from PyQt5.QtWidgets import *
18
except ImportError:
19
    try:
20
        from PyQt4.QtCore import *
21
        from PyQt4.QtGui import *
22
    except ImportError:
23
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
24

    
25
class LineNoTracer:
26
    '''
27
        @history    2018.04.26 Jeongwoo Variable name changed (texts → lineNos)
28
    '''
29
    def __init__(self, symbols, lines, lineNos, specBreak, lineIndicator, vendor):
30
        try:
31
            self._symbols = symbols
32
            self._lines = lines
33
            self._lineNos = lineNos
34
            self._spec_breaks = specBreak
35
            self._lineIndicator = lineIndicator
36
            
37
            """
38
            for spec in self._specBreak:
39
                for attr in spec.attrs:
40
                    if type(attr) is tuple and attr[1] != '':
41
                        self._specBreakUID.append(attr[1])
42
            """
43
        except Exception as ex:
44
            from App import App 
45

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

    
49
    '''
50
        @brief  find primary lines connected to given line no
51
        @author humkyung
52
    '''
53
    def find_primary_lines(self, lineno):
54
        from EngineeringLineItem import QEngineeringLineItem
55
        from EngineeringRunItem import QEngineeringRunItem
56

    
57
        connected_items = []
58
        
59
        _from = lineno.prop('From')
60
        _to = lineno.prop('To')
61
        if _from and _to and lineno.empty():
62
            connected_items = self.find_connected_objects(_from, to=_to)
63
            if _from in connected_items and _to in connected_items:
64
                start = connected_items.index(_from)
65
                end = connected_items.index(_to)
66
                if start < end:
67
                    connected_items = connected_items[start:end+1]
68
                else:
69
                    connected_items = connected_items[end:start+1]
70
                    connected_items.reverse()
71
        elif (not _from or not _to) and (1 == len(lineno.conns)):
72
            connected_items = self.find_connected_objects(lineno.conns[0])
73

    
74
        if connected_items:
75
            for item in connected_items: 
76
                item.owner = lineno # set item's owner
77
            
78
            line_run = QEngineeringRunItem()
79
            line_run.items = connected_items
80
            line_run.arrange_flow_direction()
81
            line_run.owner = lineno
82
            lineno.runs.append(line_run)
83

    
84
            lineno.set_property('From', connected_items[0])
85
            lineno.set_property('To', connected_items[-1])
86

    
87
        if _to is not None and (not connected_items or connected_items[-1] is not _to):
88
            _to.owner = None
89

    
90
        return connected_items
91

    
92
    '''
93
        @brief  find secondary lines
94
        @author humkyung
95
    '''
96
    def find_secondary_lines(self, lines):
97
        from EngineeringAbstractItem import QEngineeringAbstractItem
98
        from EngineeringLineItem import QEngineeringLineItem
99
        from EngineeringRunItem import QEngineeringRunItem
100

    
101
        try:
102
            foundCount = 1
103
            while foundCount:
104
                foundCount = 0
105
                notMatches = []
106
                for line in lines:
107
                    if line.owner is not None: continue
108

    
109
                    line_matches = [x for x in self._lines if x.owner and line.is_connected(x, QEngineeringAbstractItem.CONNECTED_AT_BODY)]
110
                    symbol_matches = [x for x in self._symbols if x.owner and line.is_connected(x)]
111
                    if line_matches or symbol_matches:
112
                        foundCount += 1
113
                        connected_items = self.find_connected_objects(line)
114
                        
115
                        owner = line_matches[0].owner if line_matches else symbol_matches[0].owner
116
                        for item in connected_items:
117
                            item.owner = owner # set item's owner
118

    
119
                        line_run = QEngineeringRunItem()
120
                        line_run.items = connected_items
121
                        line_run.arrange_flow_direction()
122
                        if line_run.items is not None and len(line_run.items) > 0:
123
                            line_run.owner = owner
124
                            owner.runs.append(line_run)
125
                    else:
126
                        notMatches.append(line)
127
                lines = notMatches
128
        except Exception as ex:
129
            from App import App 
130

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

    
134
    '''
135
        @brief      trace line no
136
        @author     humkyung
137
        @date       2018.04.16
138
        @history    2018.04.26 Jeongwoo docDatalineNos = self.lineNos, Not For loop
139
                    humkyung 2018.05.08 add flow arrow
140
                    Jeongwoo 2018.05.14 Add [runs] on Primary/Secondary Line - Need to modify Secondary Line
141
                    Jeongwoo 2018.05.15 Make Comments [lineno.conns[0].owner = lineno]
142
                    Jeongwoo 2018.05.17 Modify find secondary lines with 'while'
143
                                        Modify find secondary lines with 'while' used sublist for unconnected line
144
                    humkyung 2018.05.18 set start line's owner before tracing
145
    '''
146
    def execute(self, displayMessage, updateProgress, toler=50):
147
        from EngineeringLineItem import QEngineeringLineItem
148
        from SymbolSvgItem import SymbolSvgItem
149
        from EngineeringRunItem import QEngineeringRunItem
150
        from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem
151

    
152
        try:
153
            docData = AppDocData.instance()
154

    
155
            configs = docData.getConfigs('Line No', 'Delimiter')
156
            if 1 == len(configs):
157
                configs = docData.getConfigs('Line No', 'Configuration')
158

    
159
                for lineno in self._lineNos:
160
                    _from = lineno.prop('From')
161
                    _to = lineno.prop('To')
162
                    if _from and _to and (type(_from) is QEngineeringLineItem or issubclass(type(_from), SymbolSvgItem)) and (type(_to) is QEngineeringLineItem or issubclass(type(_to), SymbolSvgItem)) :
163
                        _from.owner = lineno
164
                        _to.owner = lineno
165
                        continue
166
                    else:
167
                        lineno.set_property('From', None)
168
                        lineno.set_property('To', None)
169

    
170
                    lineno.conns.clear()
171
                    minDist = None
172
                    startLine = None
173
                    for line in self._lines:
174
                        dist = line.distanceTo((lineno.center().x(), lineno.center().y()))
175
                        if (minDist is None) or (dist < minDist):
176
                            minDist = dist
177
                            startLine = line
178
                    if (startLine is not None) and (minDist < toler):
179
                        lineno.conns.append(startLine)
180
                        startLine.owner = lineno
181
                
182
                """
183
                ## lineIndicator
184
                extendPixel = 30
185
                for lineIndicator in self._lineIndicator:
186
                    maxOverLap = 0
187
                    matchLineNo = None
188
                    liInRect = [round(lineIndicator.boundingRect().x()), round(lineIndicator.boundingRect().y()), round(lineIndicator.boundingRect().x() + lineIndicator.boundingRect().width()), round(lineIndicator.boundingRect().y() + lineIndicator.boundingRect().height())]
189
                    for remainLineNo in remainLineNos:
190
                        xOverlap = False
191
                        yOverlap = False
192
                        extendDx = remainLineNo.size[0] if lineIndicator.isVH == 'V' else remainLineNo.size[1]
193
                        reNoRect = [round(remainLineNo.loc[0] - extendDx), round(remainLineNo.loc[1] - extendDx), round(remainLineNo.loc[0] + remainLineNo.size[0] + extendDx), round(remainLineNo.loc[1] + remainLineNo.size[1] + extendDx)]
194
                        w, h = 0, 0                        
195
                        for x1 in range(reNoRect[0], reNoRect[2] + 1):
196
                            for x2 in range(liInRect[0], liInRect[2] + 1):
197
                                if x1 - x2 is 0:
198
                                    xOverlap = True
199
                                    w += 1
200
                        if not xOverlap:
201
                            continue
202
                        for y1 in range(reNoRect[1], reNoRect[3] + 1):
203
                            for y2 in range(liInRect[1], liInRect[3] + 1):
204
                                if y1 - y2 is 0:
205
                                    yOverlap = True
206
                                    h += 1
207

208
                        if not xOverlap or not yOverlap:
209
                            continue
210
                        overLapRate = (w / lineIndicator.boundingRect().width() * 100) if lineIndicator.boundingRect().width() > lineIndicator.boundingRect().height() else (h / lineIndicator.boundingRect().height() * 100)
211
                        #print(overLapRate)
212
                        if maxOverLap < overLapRate:
213
                            maxOverLap = overLapRate
214
                            matchLineNo = remainLineNo
215
                            #lineIndicator.setBrush(QBrush(QColor(255, 0, 0, 127)))
216

217
                    if matchLineNo is not None:
218
                        #print(matchLineNo.text() + ' indicator : ' + str(lineIndicator.boundingRect().x()) + ', ' + str(lineIndicator.boundingRect().y()))
219
                        matchLine = None
220
                        x1, y1, x2, y2 = int(lineIndicator.boundingRect().x() + lineIndicator.otherLine[0]), int(lineIndicator.boundingRect().y() + lineIndicator.otherLine[1]), int(lineIndicator.boundingRect().x() + lineIndicator.otherLine[2]), int(lineIndicator.boundingRect().y() + lineIndicator.otherLine[3])
221
                        #print([type(x1), type(y1), type(x2), type(y2)])
222
                        startXorY = (min(liInRect[0], liInRect[2]) - extendPixel) if lineIndicator.isVH == 'V' else (min(liInRect[1], liInRect[3]) - extendPixel)
223
                        endXorY = (max(liInRect[0], liInRect[2]) + extendPixel) if lineIndicator.isVH == 'V' else (max(liInRect[1], liInRect[3]) + extendPixel)
224
                        fXorY = []
225
                        for dXOrdY in range(startXorY, endXorY + 1): # if horizontal -> Y, if vertical -> X
226
                            if lineIndicator.isVH == 'V':
227
                                fXorY.append(round(((y2-y1)/(x2-x1))*dXOrdY + y1 - ((y2-y1)/(x2-x1))*x1)) # f(x)
228
                            else:
229
                                fXorY.append(round(((x2-x1)/(y2-y1))*dXOrdY + x1 - ((x2-x1)/(y2-y1))*y1)) # f(y)
230

231
                        #print(self._lines)
232
                        for line in self._lines:
233
                            axis1Overlap = False
234
                            axis2Overlap = False
235
                            lX1, lY1, lX2, lY2 = int(line.startPoint()[0]), int(line.startPoint()[1]), int(line.endPoint()[0]), int(line.endPoint()[1])
236
                            #print([lX1, lY1, lX2, lY2])
237

238
                            if lineIndicator.isVH == 'V':
239
                                range11 = range(startXorY, endXorY + 1)
240
                                range12 = range(min(lX1, lX2), max(lX1, lX2)+ 1)
241
                                range21 = fXorY
242
                                range22 = range(min(lY1, lY2), max(lY1, lY2) + 1)
243
                            else:
244
                                range11 = range(startXorY, endXorY + 1)
245
                                range12 = range(min(lY1, lY2), max(lY1, lY2) + 1)
246
                                range21 = fXorY
247
                                range22 = range(min(lX1, lX2), max(lX1, lX2) + 1)
248
                            #print(fXorY)
249
                            #print(type(fXorY[0]))
250
                            #print([range11[0],range11[-1], range12[0],range12[-1], range21[0],range21[-1], range22[0],range22[-1]])
251

252
                            for axis11 in range11:
253
                                for axis12 in range12:
254
                                    if axis11 - axis12 is 0:
255
                                        axis1Overlap = True
256
                                        break
257
                                if axis1Overlap: break
258
                            if not axis1Overlap:
259
                                continue
260
                            for axis21 in range21:
261
                                for axis22 in range22:
262
                                    if axis21 - axis22 is 0:
263
                                        axis2Overlap = True
264
                                        break
265
                                if axis2Overlap: break
266
                            
267
                            if axis1Overlap and axis2Overlap:
268
                                matchLine = line
269
                                break
270
                        if matchLine is not None:
271
                            matchLineNo.conns.append(matchLine)
272
                            lineIndicator.lineIndicator = 'Match'
273
                            lineIndicator.setBrush(QBrush(QColor(0, 0, 255, 127)))
274
                            #print('connected ' + matchLineNo.text() + ' and ' + matchLine.uid)                     
275
                ## up to here
276
                """
277
                            
278
                maxValue = len(self._lineNos) + 1   ## line no's count + secondary line
279

    
280
                # find primary lines
281
                # sort line no with from,to value
282
                self._lineNos.sort(key=lambda line_no:(1 if line_no.prop('From') else 0)+(1 if line_no.prop('To') else 0),reverse=True)
283
                for lineno in self._lineNos:
284
                    if displayMessage: displayMessage.emit('{} {}'.format(lineno.text(), 'Topology Construction'))
285
                    self.find_primary_lines(lineno)
286
                    if updateProgress: updateProgress.emit(maxValue)
287

    
288
                # find secondary lines
289
                lines = self._lines
290
                self.find_secondary_lines(lines)
291
                if updateProgress: updateProgress.emit(maxValue)
292

    
293
            ### make trim lines
294
            """
295
            updateProgress.emit(-1) # reset progressbar
296
            displayMessage.emit('Unknown line Topology Construction')
297
            orphanLines = [line for line in self._lines if line.owner is None] 
298
            if orphanLines:
299
                maxValue = len(orphanLines)
300
                orphanLines = sorted(orphanLines, key=lambda param:param.length(), reverse=True)
301
                while len(orphanLines) > 0:
302
                    trimLineNo = QEngineeringTrimLineNoTextItem()
303
                    trimLineNo.conns.append(orphanLines[0])
304
                    orphanLines[0].owner = trimLineNo
305
                    orphanLines[0].linkedItem = trimLineNo
306

307
                    connectedItems = self.findPrimaryLines(trimLineNo)
308
                    for item in connectedItems:
309
                        if item in orphanLines:
310
                            orphanLines.remove(item)
311
                            updateProgress.emit(maxValue)
312

313
                    self.findSecondaryLines(orphanLines)
314
                    for item in orphanLines[:]:
315
                        if item.owner is not None:
316
                            orphanLines.remove(item)
317
                            updateProgress.emit(maxValue)
318

319
                    docData.tracerLineNos.append(trimLineNo)
320
            """
321
            if updateProgress: updateProgress.emit(maxValue)
322
        except Exception as ex:
323
            from App import App 
324

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

    
328
    '''
329
        @brief      find objects connected to given line while loop
330
        @author     humkyung
331
        @date       2018.04.16
332
        @history    humkyung 2018.05.08 find symbol or line connected to given object
333
                    humkyung 2018.05.10 set found object's owner
334
                    humkyung 2018.05.17 try to connect both symbol and line
335
                    humkyung 2018.06.22 order connected objects
336
    '''
337
    def find_connected_objects(self, start, to=None):
338
        from EngineeringLineItem import QEngineeringLineItem
339
        from EngineeringEquipmentItem import QEngineeringEquipmentItem
340
        from SymbolSvgItem import SymbolSvgItem
341

    
342
        visited = [start]
343

    
344
        try:
345
            pool = []
346
            pool.append((0, start))
347
            
348
            while len(pool) > 0:
349
                sign, obj = pool.pop()
350

    
351
                """ check obj is upstream or downstream of spec break """
352
                matches = [spec_break for spec_break in self._spec_breaks if spec_break.is_connected(obj)]
353
                if matches or issubclass(type(obj), QEngineeringEquipmentItem): continue
354
                """ end loop if obj is to """
355
                if to is not None and str(obj.uid) == str(to.uid): break
356

    
357
                if type(obj) is QEngineeringLineItem:
358
                    symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and (x not in visited) and obj.is_connected(x)]
359
                    lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (x is not obj) and (x not in visited) and obj.is_connected(x)]
360

    
361
                elif issubclass(type(obj), SymbolSvgItem):
362
                    lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (x not in visited) and obj.is_connected(x)]
363

    
364
                    if len(lineMatches) > 1: # choose one if connected lines are more than 2
365
                        matches = [x for x in [visited[0], visited[-1]] if obj.is_connected(x)]
366
                        if matches:
367
                            next_connected = [x for x in lineMatches if obj.next_connected(x, matches[0])]
368
                            if next_connected: lineMatches = next_connected
369

    
370
                    symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and (x is not obj) and (x not in visited) and obj.is_connected(x, None)]
371
                    #print(symbolMatches)
372

    
373
                # order connected objects
374
                matches = []
375
                matches.extend(symbolMatches)
376
                matches.extend(lineMatches)
377

    
378
                if sign == 0 and len(matches) > 1:
379
                    mid = int(len(matches)*0.5)
380
                    lhs = matches[0:mid]
381
                    rhs = matches[mid:]
382
                elif sign == -1:
383
                    lhs = matches
384
                    rhs = []
385
                else:
386
                    lhs = []
387
                    rhs = matches
388

    
389
                for match in lhs:
390
                    pool.append((-1, match))
391
                    visited.insert(0, match)
392

    
393
                for match in rhs:
394
                    pool.append((1, match))
395
                    visited.append(match)
396
                # up to here
397

    
398
        except Exception as ex:
399
            from App import App 
400

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

    
404
        return visited
405

    
406
'''
407
    @brief      connect attributes
408
    @author     humkyung
409
    @date       2018.06.17
410
    @history    humkyung 2018.06.21 paste connect attributes codes from recognizeLine function
411
                kyouho  2018.09.14  clear Item's owner 
412
'''
413
def connectAttrImpl(worker, update_line_type):
414
    import os
415
    from App import App
416
    from LineNoTracer import LineNoTracer
417
    from AppDocData import AppDocData
418
    from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
419
    from EngineeringInstrumentItem import QEngineeringInstrumentItem
420
    from EngineeringReducerItem import QEngineeringReducerItem
421
    from EngineeringEquipmentItem import QEngineeringEquipmentItem
422
    from QEngineeringOPCItem import QEngineeringOPCItem
423
    from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
424
    from EngineeringVendorItem import QEngineeringVendorItem
425
    from EngineeringEndBreakItem import QEngineeringEndBreakItem
426

    
427
    try:
428
        symbols = []
429
        lines = []
430
        lineNos = []
431
        specBreak = []
432
        lineIndicator = []
433
        vendor_packages = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringVendorItem]
434
        end_breaks = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringEndBreakItem]
435
        for end_break in end_breaks:
436
            worker.graphicsView.scene.removeItem(end_break)
437

    
438
        configs = AppDocData.instance().getConfigs('Supplied by Tag Rule', 'by Vendor')
439
        vendorTag = configs[0].value if configs else 'By Vendor'
440
        for item in worker.graphicsView.scene.items():
441
            if type(item) is QEngineeringSpecBreakItem:
442
                specBreak.append(item)
443
            elif issubclass(type(item), SymbolSvgItem) and not type(item) is QEngineeringUnknownItem:
444
                matches = [vendor_package for vendor_package in vendor_packages if vendor_package.includes(item)]
445
                if matches:
446
                    item.set_property('Supplied By', vendorTag)
447
                else:
448
                    item.set_property('Supplied By', '')
449
                symbols.append(item)
450
            elif type(item) is QEngineeringLineNoTextItem:
451
                lineNos.append(item)
452
            elif type(item) is QEngineeringLineItem:
453
                #matches = [vendor_package for vendor_package in vendor_packages if vendor_package.includes(item)]
454
                #if not matches: lines.append(item)
455
                lines.append(item)
456
            elif type(item) is QEngineeringUnknownItem and item.lineIndicator != 'False':
457
                lineIndicator.append(item)
458

    
459
        # trace line no
460
        tracer = LineNoTracer(symbols, lines, lineNos, specBreak, lineIndicator, vendor_packages)
461
        tracer.execute(worker.displayMessage, worker.updateProgress)
462
        # up to here
463

    
464
        # connect attribute
465
        texts = [item for item in worker.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)]
466
        for symbol in symbols:
467
            try:
468
                symbol.connectAttribute(texts)
469
            except Exception as ex:
470
                from App import App 
471
                message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
472
                App.mainWnd().addMessage.emit(MessageType.Error, message)
473

    
474
        """ try to connect label to valve """
475
        labels = [symbol for symbol in symbols if type(symbol) is QEngineeringInstrumentItem and not symbol.is_connected]
476
        valves = [symbol for symbol in symbols if type(symbol) is not QEngineeringInstrumentItem and type(symbol) is not QEngineeringReducerItem and type(symbol) is not QEngineeringEquipmentItem \
477
            and type(symbol) is not QEngineeringOPCItem and type(symbol) is not QEngineeringSpecBreakItem]
478
        for valve in valves:
479
            valve.connectAttribute(labels, clear=False)
480

    
481
        """ update line type """
482
        if update_line_type == True:
483
            lines = [line for line in worker.graphicsView.scene.items() if type(line) is QEngineeringLineItem]
484
            #for line in lines: line.lineType = 'Primary'
485
            for line in lines: line.update_line_type()
486

    
487
        """make end break"""
488
        docdata = AppDocData.instance()
489

    
490
        end_break_names = docdata.getSymbolListByType('type', 'End Break')
491
        if len(end_break_names) is not 0:
492
                
493
            svgFileName = end_break_names[0].sName
494
            symbol = AppDocData.instance().getSymbolByQuery('name', svgFileName)
495
            svgFilePath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), symbol.getType(), svgFileName+'.svg')
496

    
497
            end_breaks = []
498
            lineNo_froms = []
499
            lineNo_tos = []
500

    
501
            for lineNo in lineNos:
502
                lineNo_froms.append(lineNo.prop('From')) if lineNo.prop('From') is not None else None
503
                lineNo_tos.append(lineNo.prop('To')) if lineNo.prop('To') is not None else None
504
                #end_breaks.extend(lineNo.end_break())
505

    
506
            for line_end in lineNo_froms + lineNo_tos:
507
                #print(type(line_end))
508
                for connector in line_end.connectors:
509
                    if connector.connectedItem is not None and connector.connectedItem.owner is not line_end.owner:
510
                        end_break = SymbolSvgItem.createItem(symbol.getType(), svgFilePath)
511
                        pt = [connector.center()[0] - float(symbol.getOriginalPoint().split(',')[0]), connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])]
512
                        origin = [0,0]
513
                        if 2 == len(symbol.getOriginalPoint().split(',')):
514
                            tokens = symbol.getOriginalPoint().split(',')
515
                            origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])]
516
                        end_break.buildItem(svgFileName, symbol.getType(), 5.7, pt, [end_break.boundingRect().width(), end_break.boundingRect().height()], origin, [], symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
517
        
518
                        end_break.set_property('Connected Item', connector.connectedItem)
519
                        end_break.setToolTip('owner : ' + str(line_end))
520
                        end_break.area = 'Drawing'
521
                        end_break.owner = line_end
522
                        end_breaks.append(end_break)
523
            
524
            '''
525
            for lineNo_from in lineNo_froms + lineNo_tos:
526
                for connector in lineNo_from.connectors:
527
                    for lineNo_to in lineNo_tos + lineNo_froms:
528
                        if lineNo_from is lineNo_to or lineNo_from.owner is lineNo_to.owner : continue
529
                        if connector.connectedItem is lineNo_to:
530
                            end_break = SymbolSvgItem.createItem(symbol.getType(), svgFilePath)
531
                            pt = [connector.center()[0] - float(symbol.getOriginalPoint().split(',')[0]), connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])]
532
                            origin = [0,0]
533
                            if 2 == len(symbol.getOriginalPoint().split(',')):
534
                                tokens = symbol.getOriginalPoint().split(',')
535
                                origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])]
536
                            end_break.buildItem(svgFileName, symbol.getType(), 5.7, pt, [end_break.boundingRect().width(), end_break.boundingRect().height()], origin, [], symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), symbol.getHasInstrumentLabel())
537
            
538
                            end_break.set_property('Connected Item', lineNo_to)
539
                            end_break.setToolTip('owner : ' + str(lineNo_from))
540
                            end_break.area = 'Drawing'
541
                            end_break.owner = lineNo_from
542
                            end_breaks.append(end_break)
543
            '''
544
            
545
            if end_breaks:
546
            # check dulplication
547
                dupl = set()
548
                for i in range(len(end_breaks)):
549
                    for j in range(len(end_breaks)):
550
                        if i == j: continue
551
                        else:
552
                            setI = set([end_breaks[i].owner, end_breaks[i].prop('Connected Item')])
553
                            setJ = set([end_breaks[j].owner, end_breaks[j].prop('Connected Item')])
554
                            if not (setI - setJ):
555
                                index = [i, j]
556
                                index.sort()
557
                                index = tuple(index)
558
                                dupl.add(index)
559
                #print(dupl)
560
                dupl = list(set([indexSet[1] for indexSet in list(dupl)]))
561
                dupl.sort(reverse=True)
562
                #print(dupl)
563
                for index in dupl:
564
                    end_breaks.pop(index)
565

    
566
                for end_break in end_breaks:
567
                    end_break.transfer.onRemoved.connect(App.mainWnd().itemRemoved)
568
                    end_break.addSvgItemToScene(worker.graphicsView.scene)
569

    
570
    except Exception as ex:
571
        from App import App 
572
        message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
573
        App.mainWnd().addMessage.emit(MessageType.Error, message)
574
    finally:
575
        worker.finished.emit()
576

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