프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / Shapes / EngineeringReservedWordTextItem.py @ ce5ca212

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

1 74fc4c98 esham21
# coding: utf-8
2
""" This is engineering reserved word text item module """
3
4
import os.path
5
import sys
6
import copy
7
try:
8
    from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect
9
    from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont
10
    from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, QGraphicsTextItem
11
except ImportError:
12
    try:
13
        from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect
14
        from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont
15
    except ImportError:
16
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
17
18 4493ceff esham21
from AppDocData import AppDocData, MessageType
19 74fc4c98 esham21
from EngineeringTextItem import QEngineeringTextItem
20
21
class QEngineeringReservedWordTextItem(QEngineeringTextItem):
22 ff77e799 humkyung
    """ This is engineering reserved words text item class """
23 74fc4c98 esham21
24
    def __init__(self, uid=None, parent=None):
25
        QEngineeringTextItem.__init__(self, uid, parent)
26 4493ceff esham21
        self.type = 'Reserved Word'
27
28
    def findOwner(self, lines):
29
        import sys
30
31
        try:
32 edc78461 esham21
            # find line onwer parallel
33 4493ceff esham21
            self.onwer = None
34
            dist = min(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) * 2
35
            center = self.sceneBoundingRect().center()
36
37
            maxOverlap = 0
38
            minDist = sys.maxsize
39
            selected = None
40
            hLines = []
41
            vLines = []
42
            for line in lines:
43
                if line.sceneBoundingRect().height() > line.sceneBoundingRect().width():
44
                    vLines.append(line)
45
                else:
46
                    hLines.append(line)
47
48
            if self.sceneBoundingRect().height() > self.sceneBoundingRect().width():
49
                lines = vLines
50
            else:
51
                lines = hLines
52
            
53
            axisText = range(round(self.sceneBoundingRect().x()), round(self.sceneBoundingRect().x() + self.sceneBoundingRect().width())) if lines is hLines else range(round(self.sceneBoundingRect().y()), round(self.sceneBoundingRect().y() + self.sceneBoundingRect().height()))
54
            #print(axisText)
55
            for line in lines:
56
                intercept = line.sceneBoundingRect().center().y() if lines is hLines else line.sceneBoundingRect().center().x()
57
                length = abs(intercept - center.y()) if lines is hLines else abs(intercept - center.x())
58
                if (length < dist):
59
                    overlap = 0
60
                    axisLine = range(round(line.sceneBoundingRect().x()), round(line.sceneBoundingRect().x() + line.sceneBoundingRect().width())) if lines is hLines else range(round(line.sceneBoundingRect().y()), round(line.sceneBoundingRect().y() + line.sceneBoundingRect().height()))
61
                    #print(axisLine)
62
                    for onLine in axisLine:
63
                        for onText in axisText:
64
                            if onLine - onText is 0:
65
                                overlap += 1
66
                    #print(overlap)
67
                    if overlap == maxOverlap and length < minDist:
68
                        selected = line
69
                        maxOverlap = overlap
70
                        minDist = length
71
                    elif overlap > maxOverlap:
72
                        selected = line
73
                        maxOverlap = overlap
74
                        minDist = length
75
76
            if selected is not None:
77
                self.owner = selected
78 edc78461 esham21
                return
79 4493ceff esham21
                #print(self.owner)
80 edc78461 esham21
            ## up to here
81
82
            # fine line owner orthogonal
83
            if self.sceneBoundingRect().height() < self.sceneBoundingRect().width():
84
                lines = vLines
85
            else:
86
                lines = hLines
87
88
            minDist = 30
89
            for line in lines:
90 f1632ad7 esham21
                if line.connectors[1].connectedItem is not None: continue
91
92 edc78461 esham21
                dl = min(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) / 10
93
                dx = dl if (line.connectors[0].sceneConnectPoint[0] - line.connectors[1].sceneConnectPoint[0]) > 0 else -dl
94
                dy = -dl if (line.connectors[0].sceneConnectPoint[1] - line.connectors[1].sceneConnectPoint[1]) > 0 else dl
95
                
96
                startPoint = line.endPoint()
97
                for index in range(30):
98
                    point = (startPoint[0] + index * dx, startPoint[1] + index * dy)
99
                    if self.sceneBoundingRect().contains(point[0], point[1]):
100
                        if index < minDist:
101
                            minDist = index
102
                            selected = line
103
                            break
104
105
            if selected is not None:
106
                self.owner = selected
107 4493ceff esham21
108
        except Exception as ex:
109
            from App import App 
110 ce5ca212 kim yeonjin
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
111 4493ceff esham21
            App.mainWnd().addMessage.emit(MessageType.Error, message)
클립보드 이미지 추가 (최대 크기: 500 MB)