프로젝트

일반

사용자정보

개정판 ac917e1b

IDac917e1b31ad0e3b050cf2d77ff66853df6aabcc
상위 d20c56f1
하위 59bbfb9b

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

issue #1052: 스트림 라인 생성 시 스트림 넘버 태그 배치 오류 수정

Change-Id: Ia7591b6377da4f884099dca346f973dc394e3fd9

차이점 보기:

HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py
18 18
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
19 19
from EngineeringAbstractItem import QEngineeringAbstractItem
20 20

  
21

  
21 22
class QEngineeringStreamlineItem(QGraphicsPathItem, QEngineeringAbstractItem):
22 23
    """ This is EngineeringStreamlineItem Class """
23 24

  
......
30 31
                    2018.05.15  Jeongwoo    Change method to call parent's __init__
31 32
                    2018.05.25  Jeongwoo    Change self.pen's default color (red → blue)
32 33
    '''
34

  
33 35
    def __init__(self, uid=None, parent=None):
34 36
        import uuid
35 37
        from EngineeringStreamNoTextItem import QEngineeringStreamNoTextItem
......
37 39
        try:
38 40
            QGraphicsPathItem.__init__(self, parent)
39 41
            QEngineeringAbstractItem.__init__(self)
40
            self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable)
42
            self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
41 43
            self.setAcceptHoverEvents(True)
42 44
            self.setAcceptTouchEvents(True)
43 45

  
......
46 48
            self._vertices = []
47 49
            self.isCreated = False
48 50
            self._pt = None
49
            self.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # set default pen
50
            
51
            self.setPen(QPen(Qt.blue, 1, Qt.SolidLine))  # set default pen
52

  
51 53
            self._stream_no = 0
52 54
            self._stream_no_text = None
53 55

  
......
56 58
        except Exception as ex:
57 59
            from App import App
58 60
            from AppDocData import MessageType
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

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

  
63 66
    def __repr__(self):
......
76 79

  
77 80
        self._stream_no = value
78 81
        self._stream_no_text = QEngineeringStreamNoTextItem('<{}>'.format(self._stream_no), self)
79
        
82
        self.build_path()
83

  
80 84
    @property
81 85
    def data(self):
82 86
        """ return hmb data"""
......
113 117
        """
114 118

  
115 119
        from SymbolSvgItem import SymbolSvgItem
116
        from EngineeringConnectorItem import QEngineeringConnectorItem 
120
        from EngineeringConnectorItem import QEngineeringConnectorItem
117 121

  
118 122
        targets = []
119 123
        index = 0
120
        for vertex in [self._vertices[0],self._vertices[-1]]:          
124
        for vertex in [self._vertices[0], self._vertices[-1]]:
121 125
            if pointsUids:
122
                connector = QEngineeringConnectorItem(pointsUids[index], parent=self, index=index+1)
123
            else: 
124
                connector = QEngineeringConnectorItem(uid=None, parent=self, index=index+1)
126
                connector = QEngineeringConnectorItem(pointsUids[index], parent=self, index=index + 1)
127
            else:
128
                connector = QEngineeringConnectorItem(uid=None, parent=self, index=index + 1)
125 129

  
126 130
            connector.setPos(vertex)
127 131
            connector.setParentItem(self)
......
129 133
            connector.sceneConnectPoint = vertex
130 134

  
131 135
            # add connector move ables
132
            connector.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable)
136
            connector.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
133 137
            connector.setAcceptTouchEvents(True)
134 138
            connector.transfer.onPosChanged.connect(self.on_connector_pos_changed)
135 139

  
......
164 168

  
165 169
        dx = end[0] - start[0]
166 170
        dy = end[1] - start[1]
167
        length = math.sqrt(dx*dx + dy*dy)
171
        length = math.sqrt(dx * dx + dy * dy)
168 172
        if length == 0: return
169 173

  
170
        _dir = [(end[0] - start[0])/length, (end[1] - start[1])/length]
174
        _dir = [(end[0] - start[0]) / length, (end[1] - start[1]) / length]
171 175
        perpendicular = (-_dir[1], _dir[0])
172 176
        polygon = QPolygonF()
173
        polygon.append(QPointF(end[0] - _dir[0]*QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[0]*QEngineeringStreamlineItem.ARROW_SIZE*0.25, 
174
                            end[1] - _dir[1]*QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[1]*QEngineeringStreamlineItem.ARROW_SIZE*0.25))
175
        polygon.append(QPointF(end[0] - _dir[0]*QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[0]*QEngineeringStreamlineItem.ARROW_SIZE*0.25, 
176
                            end[1] - _dir[1]*QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[1]*QEngineeringStreamlineItem.ARROW_SIZE*0.25))
177
        polygon.append(QPointF(end[0] - _dir[0] * QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[
178
            0] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25,
179
                               end[1] - _dir[1] * QEngineeringStreamlineItem.ARROW_SIZE + perpendicular[
180
                                   1] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25))
181
        polygon.append(QPointF(end[0] - _dir[0] * QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[
182
            0] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25,
183
                               end[1] - _dir[1] * QEngineeringStreamlineItem.ARROW_SIZE - perpendicular[
184
                                   1] * QEngineeringStreamlineItem.ARROW_SIZE * 0.25))
177 185
        polygon.append(QPointF(end[0], end[1]))
178 186
        polygon.append(polygon[0])  # close polygon
179 187

  
......
188 196
    '''
189 197
        @brief  construct a polyline
190 198
    '''
199

  
191 200
    def process(self, param):
192 201
        if ('mousePressEvent' == param[0]) and (param[1].button() == Qt.LeftButton):
193 202
            self._vertices.append(param[2])
......
199 208
    '''
200 209
        @brief  clone an object
201 210
    '''
211

  
202 212
    def clone(self):
203 213
        clone = QEngineeringStreamlineItem()
204 214
        clone._vertices = copy.deepcopy(self._vertices)
205 215
        clone.isCreated = self.isCreated
206 216

  
207 217
        return clone
208
        
218

  
209 219
    def init(self):
210 220
        self._vertices = []
211 221
        self._pt = None
212 222
        self.isCreated = False
213 223

  
214
    def buildItem(self):
215
        self.__buildItem()        
216

  
217 224
    '''
218 225
        @build  build path
219 226
        @author humkyung
220 227
        @date   2018.04.23
221 228
    '''
222
    def __buildItem(self):
223
        import math
224 229

  
225
        path = QPainterPath()
226
        path.moveTo(self._vertices[0][0], self._vertices[0][1])
227

  
228
        max_length = 0
229
        max_length_line = [None, None]
230
        for i in range(1, len(self._vertices)):
231
            path.lineTo(self._vertices[i][0], self._vertices[i][1])
232
            dx = self._vertices[i][0] - self._vertices[i-1][0]
233
            dy = self._vertices[i][1] - self._vertices[i-1][1]
234
            if dx*dx + dy*dy > max_length:
235
                max_length = dx*dx + dy*dy
236
                max_length_line[0] = self._vertices[i-1]
237
                max_length_line[1] = self._vertices[i]
238

  
239
        self.setPath(path)
240
        self.isCreated = True
241

  
242
        if self._stream_no_text:
243
            if max_length_line[0] is not None and max_length_line[1] is not None:
244
                x = (max_length_line[0][0] + max_length_line[1][0] - self._stream_no_text.textWidth())*0.5
245
                y = (max_length_line[0][1] + max_length_line[1][1])*0.5
246
                self._stream_no_text.setPos(QPointF(x, y))
247
                dx = max_length_line[0][0] - max_length_line[1][0]
248
                dy = max_length_line[0][1] - max_length_line[1][1]
249
                self._stream_no_text.setRotation(90) if abs(dy) > abs(dx) else self._stream_no_text.setRotation(0)
230
    def build_path(self):
231
        if not self._vertices or len(self._vertices) < 2:
232
            return
233

  
234
        try:
235
            path = QPainterPath()
236
            path.moveTo(self._vertices[0][0], self._vertices[0][1])
237

  
238
            max_length = 0
239
            max_length_line = [None, None]
240
            for i in range(1, len(self._vertices)):
241
                path.lineTo(self._vertices[i][0], self._vertices[i][1])
242
                dx = self._vertices[i][0] - self._vertices[i - 1][0]
243
                dy = self._vertices[i][1] - self._vertices[i - 1][1]
244
                if dx * dx + dy * dy > max_length:
245
                    max_length = dx * dx + dy * dy
246
                    max_length_line[0] = self._vertices[i - 1]
247
                    max_length_line[1] = self._vertices[i]
248

  
249
            self.setPath(path)
250
            self.isCreated = True
251

  
252
            if self._stream_no_text:
253
                if max_length_line[0] is not None and max_length_line[1] is not None:
254
                    x = (max_length_line[0][0] + max_length_line[1][0] - self._stream_no_text.textWidth()) * 0.5
255
                    y = (max_length_line[0][1] + max_length_line[1][1]) * 0.5
256
                    self._stream_no_text.setPos(QPointF(x, y))
257
                    dx = max_length_line[0][0] - max_length_line[1][0]
258
                    dy = max_length_line[0][1] - max_length_line[1][1]
259
                    self._stream_no_text.setRotation(90) if abs(dy) > abs(dx) else self._stream_no_text.setRotation(0)
260
        except Exception as ex:
261
            from App import App
262
            from AppDocData import MessageType
263

  
264
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
265
                                                           sys.exc_info()[-1].tb_lineno)
266
            App.mainWnd().addMessage.emit(MessageType.Error, message)
250 267

  
251 268
    '''
252
        @brief      return bouding rectangle of polyline
269
        @brief      return bounding rectangle of polyline
253 270
        @author     humkyung
254 271
        @date       2018.07.23
255 272
    '''
273

  
256 274
    def boundingRect(self):
257 275
        rect = QRectF()
258
        
276

  
259 277
        if self.isCreated:
260 278
            rect = self.path().boundingRect()
261 279
            rect = QRectF(rect.left() - 5, rect.top() - 5, rect.width() + 10, rect.height() + 10)
......
269 287
                    minX = pt[0]
270 288
                if minY is None or pt[1] < minY:
271 289
                    minY = pt[1]
272
                
290

  
273 291
                if maxX is None or pt[0] > maxX:
274 292
                    maxX = pt[0]
275 293
                if maxY is None or pt[1] > maxY:
276 294
                    maxY = pt[1]
277
            
295

  
278 296
            if self._pt is not None:
279 297
                if minX is None or self._pt[0] < minX:
280 298
                    minX = self._pt[0]
281 299
                if minY is None or self._pt[1] < minY:
282 300
                    minY = self._pt[1]
283
                
301

  
284 302
                if maxX is None or self._pt[0] > maxX:
285 303
                    maxX = self._pt[0]
286 304
                if maxY is None or self._pt[1] > maxY:
......
288 306

  
289 307
            if minX is not None and minY is not None and maxX is not None and maxY is not None:
290 308
                rect = QRectF(minX - 5, minY - 5, maxX - minX + 10, maxY - minY + 10)
291
        
309

  
292 310
        return rect
293 311

  
294 312
    '''
......
296 314
        @author     humkyung
297 315
        @date       2018.07.26
298 316
    '''
317

  
299 318
    def onMouseMoved(self, event, scenePos):
300 319
        from SymbolSvgItem import SymbolSvgItem
301 320
        from EngineeringConnectorItem import QEngineeringConnectorItem
......
309 328
        elif (item is not None) and (type(item) is QEngineeringConnectorItem):
310 329
            pt = item.center()
311 330
        # up to here
312
            
331

  
313 332
        del self._vertices[1:]
314 333
        dx = pt[0] - self._vertices[0][0]
315 334
        dy = pt[1] - self._vertices[0][1]
316
        self._vertices.append((self._vertices[0][0] + dx*0.5, self._vertices[0][1]))
335
        self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1]))
317 336
        self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
318 337
        self._vertices.append(pt)
319 338

  
320
        self.__buildItem()
339
        self.build_path()
321 340
        self.update()
322
        
341

  
323 342
    def hoverEnterEvent(self, event):
324 343
        """ hilight item and it's children """
325 344
        self.highlight(True)
......
329 348
        self.highlight(False)
330 349

  
331 350
    def highlight(self, flag):
332
        self.hover = flag 
333
        self.setZValue(QEngineeringAbstractItem.HOVER_ZVALUE) if flag else self.setZValue(QEngineeringStreamlineItem.ZVALUE)
351
        self.hover = flag
352
        self.setZValue(QEngineeringAbstractItem.HOVER_ZVALUE) if flag else self.setZValue(
353
            QEngineeringStreamlineItem.ZVALUE)
334 354
        self.update()
335 355

  
336 356
    def paint(self, painter, option, widget):
......
346 366
            color = self.getColor()
347 367
            self.setColor(color)
348 368
            QGraphicsPathItem.paint(self, painter, option, widget)
349
        
369

  
350 370
    '''
351 371
        @brief      Return real item position
352 372
        @authro     Jeongwoo
353 373
        @date       2018.05.29
354 374
    '''
375

  
355 376
    def boundingRectOnScene(self):
356 377
        rect = self.boundingRect()
357 378
        sp = self.startPoint()
......
365 386
        @history    2018.05.11  Jeongwoo    Add self.setPen() Method
366 387
        @history    humkyung 2018.05.13 call setPen method to apply changed color
367 388
    '''
389

  
368 390
    def setColor(self, color):
369 391
        c = QColor()
370 392
        c.setNamedColor(color)
......
375 397

  
376 398
    def on_symbol_pos_changed(self, symbol):
377 399
        """ rebuild stream line because symbol position is changed """
378
        if self.connectors[0].connectedItem is not None : self.connectors[0].setPos(self.connectors[0].connectedItem.center())
379
        if self.connectors[-1].connectedItem is not None : self.connectors[-1].setPos(self.connectors[-1].connectedItem.center())
400
        if self.connectors[0].connectedItem is not None: self.connectors[0].setPos(
401
            self.connectors[0].connectedItem.center())
402
        if self.connectors[-1].connectedItem is not None: self.connectors[-1].setPos(
403
            self.connectors[-1].connectedItem.center())
380 404
        self.on_connector_pos_changed(None)
381 405

  
382 406
    def on_connector_pos_changed(self, connector):
......
387 411
        self._vertices.append(self.connectors[0].center())
388 412
        dx = self.connectors[-1].center()[0] - self._vertices[0][0]
389 413
        dy = self.connectors[-1].center()[1] - self._vertices[0][1]
390
        self._vertices.append((self._vertices[0][0] + dx*0.5, self._vertices[0][1]))
414
        self._vertices.append((self._vertices[0][0] + dx * 0.5, self._vertices[0][1]))
391 415
        self._vertices.append((self._vertices[-1][0], self._vertices[-1][1] + dy))
392 416
        self._vertices.append(self.connectors[-1].center())
393
        self.__buildItem()
417
        self.build_path()
394 418
        self.update_arrow()
395 419
        self.update()
396 420

  
397 421
    def mouseDoubleClickEvent(self, event):
398 422
        from StreamDataDialog import QStreamDataDialog
399
        
423

  
400 424
        dialog = QStreamDataDialog()
401 425
        res = dialog.showDialog(self)
402 426
        if res == True:
403 427
            self.load_HMB()
404 428

  
405
    def load_HMB(self):        
406
        from App import App 
429
    def load_HMB(self):
430
        from App import App
407 431

  
408 432
        App.mainWnd().load_HMB()
409
        
433

  
410 434
    def keyPressEvent(self, event):
411 435
        from App import App
412 436
        from AppDocData import AppDocData
413 437
        if not self.isSelected(): return
414 438

  
415
        if event.key() == Qt.Key_Delete: 
439
        if event.key() == Qt.Key_Delete:
416 440
            self.transfer.onRemoved.emit(self)
417 441
        elif event.key() == Qt.Key_QuoteLeft:
418
            self.mouseDoubleClickEvent(event)    
419
           
442
            self.mouseDoubleClickEvent(event)
443

  
420 444
    def toSql(self):
421 445
        """ convert valve data to sql query """
422 446
        import uuid
......
430 454
        uid = self.uid
431 455

  
432 456
        cols = ['UID', 'Symbols_UID', 'Name']
433
        values = ['?','?', '?']
457
        values = ['?', '?', '?']
434 458
        param = [str(uid), str(dbUid), str(self.stream_no)]
435 459
        sql = 'insert or replace into Components({}) values({})'.format(','.join(cols), ','.join(values))
436 460
        res.append((sql, tuple(param)))
437 461

  
438 462
        # save vertices to database
439 463
        index = 1
440
        for vertex in self._vertices:                                    
464
        for vertex in self._vertices:
441 465
            if index == 1 and self.connectors[0].connectedItem is not None:
442 466
                cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y', 'ConnectedItem_UID']
443 467
                values = ['?', '?', '?', '?', '?', '?']
444
                param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1], str(self.connectors[0].connectedItem.uid)]
468
                param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1],
469
                         str(self.connectors[0].connectedItem.uid)]
445 470
            elif index == 4 and self.connectors[1].connectedItem is not None:
446 471
                cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y', 'ConnectedItem_UID']
447 472
                values = ['?', '?', '?', '?', '?', '?']
448
                param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1], str(self.connectors[1].connectedItem.uid)]
473
                param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1],
474
                         str(self.connectors[1].connectedItem.uid)]
449 475
            else:
450 476
                cols = ['UID', 'Components_UID', '[Index]', 'X', 'Y']
451 477
                values = ['?', '?', '?', '?', '?']
452 478
                param = [str(uuid.uuid4()), str(uid), index, vertex[0], vertex[1]]
453
        
479

  
454 480
            sql = 'insert or replace into Points({}) values({})'.format(','.join(cols), ','.join(values))
455 481

  
456 482
            res.append((sql, tuple(param)))
457 483
            index += 1
458 484
        # up to here
459 485

  
460

  
461

  
462 486
        return res
463 487

  
464
    @staticmethod 
488
    @staticmethod
465 489
    def fromDatabase(componentInfos):
466 490
        from EngineeringConnectorItem import QEngineeringConnectorItem
467 491
        from AppDocData import AppDocData
......
470 494
        try:
471 495
            app_doc_data = AppDocData.instance()
472 496

  
473
            uid = componentInfos[0][0]              #uid@Components
497
            uid = componentInfos[0][0]  # uid@Components
474 498

  
475 499
            item = QEngineeringStreamlineItem(uid)
476 500
            hmb_data = app_doc_data.activeDrawing.hmbTable.get_hmb_data(uid)
477
            item.stream_no = int(hmb_data.stream_no) if hmb_data else 1 # stream no
501
            item.stream_no = int(hmb_data.stream_no) if hmb_data else 1  # stream no
478 502

  
479 503
            pointsUids = []
480
            for componentInfo in componentInfos:     
481
                pointsUid = componentInfo[11]           # uid@Points           
482
                x = componentInfo[13]                   # X@Points
483
                y = componentInfo[14]                   # Y@Points
504
            for componentInfo in componentInfos:
505
                pointsUid = componentInfo[11]  # uid@Points
506
                x = componentInfo[13]  # X@Points
507
                y = componentInfo[14]  # Y@Points
484 508

  
485 509
                pointsUids.append(pointsUid)
486 510
                item._vertices.append((x, y))
......
488 512
            connectorItems = [componentInfos[0][15], componentInfos[-1][15]]
489 513

  
490 514
            item.setVisible(False)
491
            item.__buildItem()
515
            item.build_path()
492 516
            item.build_connectors(connectorItems, pointsUids)
493
  
517

  
494 518
            item.update()
495 519

  
496 520
        except Exception as ex:
497
            from App import App 
521
            from App import App
498 522
            from AppDocData import MessageType
499 523

  
500
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
524
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
525
                                                          sys.exc_info()[-1].tb_lineno)
501 526
            App.mainWnd().addMessage.emit(MessageType.Error, message)
502 527

  
503 528
        return item
......
508 533
    @author     Jeongwoo
509 534
    @date       2018.06.18
510 535
'''
536

  
537

  
511 538
class Transfer(QObject):
512 539
    onRemoved = pyqtSignal(QGraphicsItem)
513 540

  
514
    def __init__(self, parent = None):
515
        QObject.__init__(self, parent)
541
    def __init__(self, parent=None):
542
        QObject.__init__(self, parent)

내보내기 Unified diff

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