프로젝트

일반

사용자정보

개정판 6fad8ffd

ID6fad8ffde2d2510706c892c5ff47b99b1ae98a0e
상위 ef2691cb
하위 77b3fca3

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

fixed some bugs

차이점 보기:

DTI_PID/DTI_PID/MainWindow.py
408 408
                lines.append(processLine)
409 409
                for pt in pts:
410 410
                    processLine._pol.append(QPointF(pt[0] + round(area.x), pt[1] + round(area.y)))
411
                processLine.buildPath()
411
                processLine.buildItem()
412 412
                processLine.setPen(QPen(Qt.blue, 5, Qt.SolidLine))
413 413
                self.graphicsView.scene.addItem(processLine)
414 414

  
......
507 507
                angle = float(text.find('ANGLE').text) if text.find('ANGLE') is not None else 0
508 508
                text = text.find('TEXT').text
509 509
                item = TextItemFactory.instance().createTextItem(text, delimiter, lineNoconfigs)
510
                item.loc = (x, y)
511
                item.size = (width, height)
512
                item.angle = angle
513
                item.setPlainText(text)
514
                item.setDefaultTextColor(Qt.blue)
515
                item.removed.connect(self.resultTreeWidget.itemRemoved)
516
                item.addTextItemToScene(self.graphicsView.scene)
510
                if item is not None:
511
                    item.loc = (x, y)
512
                    item.size = (width, height)
513
                    item.angle = angle
514
                    item.setPlainText(text)
515
                    item.setDefaultTextColor(Qt.blue)
516
                    item.removed.connect(self.resultTreeWidget.itemRemoved)
517
                    item.addTextItemToScene(self.graphicsView.scene)
517 518

  
518 519
            # parse notes
519 520
            for note in root.iter('NOTE'):
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py
31 31

  
32 32
    '''
33 33
        @brief  construct a ProcessLineItem
34
        @author humkyung
34 35
    '''
35 36
    def process(self, param):
37
        from SymbolSvgItem import SymbolSvgItem
38

  
36 39
        if ('mousePressEvent' == param[0]) and (param[1].button() == Qt.LeftButton):
37 40
            self._vertices.append(self._pt)
38 41
        elif ('mouseMoveEvent' == param[0]):
39
            # get connection or origin point near by mouse point
40
            pt = param[2]
41
            item = self.scene().itemAt(param[2].x(), param[2].y(), QTransform())
42
            if (item is not None) and (type(item) is QGraphicsBoundingBoxItem):
43
                if item.center is not None: pt = item.center
42
            # get connection point near by mouse point
43
            pt = (param[2].x(), param[2].y())
44
            item = self.scene().itemAt(pt[0], pt[1], QTransform())
45
            if (item is not None) and (type(item) is SymbolSvgItem):
46
                connPt = item.getConnectionPointCloseTo(pt, 5)
47
                if connPt is not None: pt = connPt
44 48
            # up to here
45 49
                
46 50
            if len(self._vertices) > 0:
47
                dx = abs(self._vertices[-1].x() - pt.x())
48
                dy = abs(self._vertices[-1].y() - pt.y())
51
                dx = abs(self._vertices[-1][0] - pt[0])
52
                dy = abs(self._vertices[-1][1] - pt[1])
49 53
                if dx < dy:
50
                    self._pt = QPointF(self._vertices[-1].x(), pt.y())
54
                    self._pt = (self._vertices[-1][0], pt[1])
51 55
                else:
52
                    self._pt = QPointF(pt.x(), self._vertices[-1].y())
56
                    self._pt = (pt[0], self._vertices[-1][1])
53 57
            else:
54 58
                self._pt = pt
55 59
        elif ('mouseReleaseEvent' == param[0]) and (param[1].button() == Qt.RightButton):
......
62 66
        clone = QEngineeringLineItem()
63 67
        clone._vertices = copy.deepcopy(self._vertices)
64 68
        for vertex in clone._vertices:
65
            clone._pol.append(vertex)
66
        clone.buildPath()
69
            clone._pol.append(QPointF(vertex[0], vertex[1]))
70
        clone.buildItem()
67 71
        clone.isCreated = self.isCreated
68 72

  
69 73
        return clone
......
225 229
                processLine = QEngineeringLineItem()
226 230
                processLine._pol.append(QPointF(symbol.connPts[1][0], symbol.connPts[1][1]))
227 231
                processLine._pol.append(QPointF(self.endPoint()[0], self.endPoint()[1]))
228
                processLine.buildPath()
232
                processLine.buildItem()
229 233
                processLine.setPen(QPen(Qt.blue, 5, Qt.SolidLine))
230 234
                processLine.conns.append(symbol)
231 235
                processLine.conns.append(self.conns[1])
......
241 245
                processLine = QEngineeringLineItem()
242 246
                processLine._pol.append(QPointF(symbol.connPts[0][0], symbol.connPts[0][1]))
243 247
                processLine._pol.append(QPointF(self.endPoint()[0], self.endPoint()[1]))
244
                processLine.buildPath()
248
                processLine.buildItem()
245 249
                processLine.setPen(QPen(Qt.blue, 5, Qt.SolidLine))
246 250
                processLine.conns.append(symbol)
247 251
                processLine.conns.append(self.conns[1])
......
254 258
                symbol.conns.append(processLine)
255 259
                symbol.conns.append(self)
256 260

  
257
            self.buildPath()
261
            self.buildItem()
258 262
            self.update()
259 263

  
260 264
        symbol.loc = [origin.x - symbol.origin[0], origin.y - symbol.origin[1]]
......
302 306
            self._pol.clear()
303 307
            self._pol.append(QPointF(start[0], start[1]))
304 308
            self._pol.append(QPointF(end[0], end[1]))
305
            self.buildPath()
309
            self.buildItem()
306 310
            self.update()
307 311

  
308 312
    def hoverEnterEvent(self, event):
DTI_PID/DTI_PID/Shapes/QEngineeringLineNoTextItem.py
20 20
from QEngineeringTextItem import QEngineeringTextItem
21 21

  
22 22
class QEngineeringLineNoTextItem(QEngineeringTextItem):
23
    removed = pyqtSignal(QGraphicsItem)
23
    #removed = pyqtSignal(QGraphicsItem)
24 24

  
25 25
    def __init__(self, parent=None):
26 26
        import uuid
DTI_PID/DTI_PID/Shapes/QEngineeringNoteItem.py
20 20
import re
21 21

  
22 22
class QEngineeringNoteItem(QEngineeringTextItem):
23
    removed = pyqtSignal(QGraphicsTextItem)
23
    #removed = pyqtSignal(QGraphicsTextItem)
24 24

  
25 25
    def __init__(self, parent=None):
26 26
        QEngineeringTextItem.__init__(self, parent)
DTI_PID/DTI_PID/Shapes/QGraphicsPolylineItem.py
48 48
        
49 49
    def init(self):
50 50
        self._vertices = []
51
        self._pol.clear()
52
        self._pt = None
51 53
        self.isCreated = False
52 54

  
53 55
    '''
......
55 57
        @author humkyung
56 58
        @date   2018.04.23
57 59
    '''
58
    def buildPath(self):
60
    def buildItem(self):
59 61
        self._path = QPainterPath()
60 62
        self._path.addPolygon(self._pol)
61 63
        self.setPath(self._path)
......
86 88
        if self.isCreated:
87 89
            QGraphicsPathItem.paint(self, painter, options, widget)
88 90
        elif len(self._vertices) > 0:
89
            pen = QPen(Qt.blue, 20, Qt.SolidLine)
91
            pen = QPen(Qt.blue, 5, Qt.SolidLine)
90 92
            painter.setPen(pen)
91 93
            for i in range(len(self._vertices)-1):
92
                painter.drawLine(self._vertices[i].x(), self._vertices[i].y(), self._vertices[i+1].x(), self._vertices[i+1].y())
94
                painter.drawLine(self._vertices[i][0], self._vertices[i][1], self._vertices[i+1][0], self._vertices[i+1][1])
93 95
            if self._pt is not None:
94
                painter.drawLine(self._vertices[len(self._vertices)-1].x(), self._vertices[len(self._vertices)-1].y(), self._pt.x(), self._pt.y())
96
                painter.drawLine(self._vertices[-1][0], self._vertices[-1][1], self._pt[0], self._pt[1])
95 97
        
96 98
        '''
97 99
        if self.isSelected:
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
85 85
        return res
86 86

  
87 87
    '''
88
        @brief  get connection point close to given point in tolerance
89
        @author humkyung
90
        @dat
91
    '''
92
    def getConnectionPointCloseTo(self, pt, toler=10):
93
        import math
94

  
95
        for connPt in self.connPts:
96
            dx = connPt[0] - pt[0]
97
            dy = connPt[1] - pt[1]
98
            if math.sqrt(dx*dx + dy*dy) < toler: return connPt
99
            
100
        return None
101

  
102
    '''
88 103
        @brief  return center of symbol
89 104
        @author humkyung
90 105
        @date   2018.04.08
......
93 108
        return self.sceneBoundingRect().center()
94 109
        
95 110
    def hoverEnterEvent(self, event):
96
        cursor = QCursor( Qt.OpenHandCursor )
97
        QApplication.instance().setOverrideCursor( cursor )
111
        cursor = QCursor(Qt.OpenHandCursor)
112
        QApplication.instance().setOverrideCursor(cursor)
98 113
        self.update()
99 114

  
100 115
    def hoverLeaveEvent(self, event):
101 116
        QApplication.instance().restoreOverrideCursor()
102 117
        self.update()
103 118

  
119
    '''
120
        @brief  change cursor to CrossCursor if mouse point is close to connection point
121
        @author humkyung
122
        @date   2018.04.28
123
    '''
104 124
    def hoverMoveEvent(self, event):
105
        pass
125
        scenePos = self.mapToScene(event.pos())
126
        connPt = self.getConnectionPointCloseTo((scenePos.x(), scenePos.y()), 5)
127
        if connPt is not None:
128
            cursor = QCursor(Qt.CrossCursor)
129
            QApplication.instance().changeOverrideCursor(cursor)
130
        else:
131
            cursor = QCursor(Qt.OpenHandCursor)
132
            QApplication.instance().changeOverrideCursor(cursor)
133

  
134
        self.update()
106 135

  
107 136
    '''
108 137
        @brief      Mouse Press Event
DTI_PID/DTI_PID/TextItemFactory.py
26 26
    '''
27 27
    def createTextItem(self, text, delimiter = '', lineNoConfig = ''):
28 28
        item = None
29
        if self.isNoteNoText(text):
30
            item = QEngineeringNoteItem()
31
        elif (delimiter != '' and lineNoConfig != '') and self.isLineNo(text, delimiter, lineNoConfig):
32
            item = QEngineeringLineNoTextItem()
33
        else:
34
            item = QEngineeringTextItem()
29

  
30
        try:
31
            if self.isNoteNoText(text):
32
                item = QEngineeringNoteItem()
33
            elif (delimiter != '' and lineNoConfig != '') and self.isLineNo(text, delimiter, lineNoConfig):
34
                item = QEngineeringLineNoTextItem()
35
            else:
36
                item = QEngineeringTextItem()
37
        except Exception as ex:
38
            print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
39

  
35 40
        return item
36 41

  
37 42
    '''
DTI_PID/DTI_PID/XmlGenerator.py
111 111
    return xml
112 112

  
113 113
def generateXml(pidName, pidWidth, pidHeight, searchedSymbolList, textInfoList, imgLineList, noteTextInfoList):
114
    xml = Element(ROOT_NODE_NAME) # Root Node
115
    SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = pidName
116
    SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight)
114
    try:
115
        xml = Element(ROOT_NODE_NAME) # Root Node
116
        SubElement(xml, ROOT_DWGNAME_NODE_NAME).text = pidName
117
        SubElement(xml, ROOT_SIZE_NODE_NAME).text = str(pidWidth) + "," + str(pidHeight)
117 118

  
118
    symbolListNode = Element(SYMBOL_LIST_NODE_NAME) # Symbol List Node
119
    sortedList = sorted(searchedSymbolList, key=lambda sym:sym.getName())
120
    for symbol in sortedList:
121
        node = getSymbolInfoNode(symbol)
122
        symbolListNode.append(node)
119
        symbolListNode = Element(SYMBOL_LIST_NODE_NAME) # Symbol List Node
120
        sortedList = sorted(searchedSymbolList, key=lambda sym:sym.getName())
121
        for symbol in sortedList:
122
            node = getSymbolInfoNode(symbol)
123
            symbolListNode.append(node)
123 124

  
124
    xml.append(symbolListNode)
125
        xml.append(symbolListNode)
125 126

  
126
    textInfoListNode = Element(TEXT_INFO_LIST_NODE_NAME) # Text Info List Node
127
    for textInfo in textInfoList:
128
        node = getTextInfoNode(textInfo)
129
        textInfoListNode.append(node)
127
        textInfoListNode = Element(TEXT_INFO_LIST_NODE_NAME) # Text Info List Node
128
        for textInfo in textInfoList:
129
            node = getTextInfoNode(textInfo)
130
            textInfoListNode.append(node)
130 131

  
131
    xml.append(textInfoListNode)
132
        xml.append(textInfoListNode)
132 133

  
133
    imgLineListNode = Element(IMG_LINE_LIST_NODE_NAME) # Image Line List Node
134
    for imgLine in imgLineList:
135
        node = getImgLineNode(imgLine)
136
        imgLineListNode.append(node)
134
        imgLineListNode = Element(IMG_LINE_LIST_NODE_NAME) # Image Line List Node
135
        for imgLine in imgLineList:
136
            node = getImgLineNode(imgLine)
137
            imgLineListNode.append(node)
137 138

  
138
    xml.append(imgLineListNode)
139
        xml.append(imgLineListNode)
139 140

  
140
    noteTextInfoListNode = Element(NOTE_TEXT_INFO_LIST_NOTE_NAME)
141
    for noteTextInfo in noteTextInfoList:
142
        node = getNoteTextInfoNode(noteTextInfo)
143
        noteTextInfoListNode.append(node)
141
        noteTextInfoListNode = Element(NOTE_TEXT_INFO_LIST_NOTE_NAME)
142
        if noteTextInfoList is not None:
143
            for noteTextInfo in noteTextInfoList:
144
                node = getNoteTextInfoNode(noteTextInfo)
145
                noteTextInfoListNode.append(node)
144 146

  
145
    xml.append(noteTextInfoListNode)
147
        xml.append(noteTextInfoListNode)
148
    except Exception as ex:
149
        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
146 150

  
147 151
    return xml
148 152

  

내보내기 Unified diff

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