프로젝트

일반

사용자정보

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

hytos / DTI_PID / DTI_PID / Shapes / EngineeringValveOperCodeTextItem.py @ 86fc75ab

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

1
# coding: utf-8
2
"""
3
    This is engineering valve operation code module
4
"""
5
import os.path
6
import sys
7
import copy
8
try:
9
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect
10
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont
11
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem
12
except ImportError:
13
    try:
14
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect
15
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont
16
    except ImportError:
17
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
18

    
19
from EngineeringPolylineItem import QEngineeringPolylineItem
20
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
21
import OcrResultDialog
22
from AppDocData import AppDocData, MessageType
23
from EngineeringTextItem import QEngineeringTextItem
24
from SymbolSvgItem import SymbolSvgItem
25

    
26
class QEngineeringValveOperCodeTextItem(QEngineeringTextItem):
27
    """
28
    This is engineering valve operation code text item class
29
    """
30
    def __init__(self, parent=None):
31
        import uuid
32

    
33
        QEngineeringTextItem.__init__(self, parent)
34
        self.type = 'VALVE OPER CODE'
35

    
36
    def findOwner(self, symbols):
37
        import math
38

    
39
        try:
40
            minDist = None
41
            selected = None
42

    
43
            configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio')
44
            ratio = float(configs[0].value) if 1 == len(configs) else 1.5
45

    
46
            dist = (self.sceneBoundingRect().height() + self.sceneBoundingRect().width()) * ratio / 2
47
            center = self.sceneBoundingRect().center()
48

    
49
            for symbol in symbols:
50
                if type(symbol) is SymbolSvgItem:                    
51
                    dx = symbol.center().x() - center.x()
52
                    dy = symbol.center().y() - center.y()
53
                    length = math.sqrt(dx*dx + dy*dy)
54
                    if (length < dist) and (minDist is None or length < minDist):
55
                        minDist = length
56
                        selected = symbol
57

    
58
            if selected is not None:
59
                selected.add_assoc_item(self)
60
                self.owner = selected
61

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