개정판 7aa3c8e5
dev issue #622: 저장, 불러오기 할때 심볼들간의 connection 유지 및 connection xml저장 방식 수정
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
4 | 4 |
try: |
5 | 5 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent |
6 | 6 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent, QTransform |
7 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication |
|
7 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication, QMessageBox
|
|
8 | 8 |
except ImportError: |
9 | 9 |
try: |
10 | 10 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent |
... | ... | |
95 | 95 |
xmlStr = QApplication.clipboard().text() |
96 | 96 |
if xmlStr.find('<SYMBOL>') > -1 and xmlStr.find('</SYMBOL>') > -1: |
97 | 97 |
self.copySymbol(QApplication.clipboard().text()) |
98 |
elif 'keyPressEvent' == param[0] and (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_S): |
|
99 |
import XmlGenerator as xg |
|
100 |
from AppDocData import AppDocData |
|
101 |
docData = AppDocData.instance() |
|
102 |
xg.writeXmlOnScene(docData.imgName, docData.imgWidth, docData.imgHeight, self.imageViewer.scene) |
|
103 |
QMessageBox.about(self.imageViewer, "알림", "정상적으로 저장되었습니다.") |
|
98 | 104 |
|
99 | 105 |
self.isTreated = False |
100 | 106 |
else: |
... | ... | |
139 | 145 |
et = fromstring(xmlStr) |
140 | 146 |
item = SymbolSvgItem.fromXml(et) |
141 | 147 |
self.symbol = item[0] |
148 |
for connector in self.symbol.connectors: |
|
149 |
connector.connectedItem = None |
|
142 | 150 |
# uid 새로 할당 |
143 | 151 |
self.symbol.uid = uuid.uuid4() |
144 | 152 |
self.imageViewer.scene.addItem(self.symbol) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
936 | 936 |
if len(matches) == 1: |
937 | 937 |
item[0].owner = matches[0][0] |
938 | 938 |
# up to here |
939 |
|
|
940 |
# set symbol's connectItem |
|
941 |
symbols = [symbol for symbol in self.graphicsView.scene.items() if issubclass(type(symbol), SymbolSvgItem)] |
|
942 |
for symbol in symbols: |
|
943 |
connectors = symbol.connectors |
|
944 |
for connector in connectors: |
|
945 |
if connector.connectedItem is not None: |
|
946 |
pass |
|
947 |
|
|
948 |
# up to here |
|
949 |
|
|
939 |
|
|
950 | 940 |
for item in symbols: |
951 | 941 |
self.addSvgItemToScene(item[0]) |
952 | 942 |
|
... | ... | |
1028 | 1018 |
self.addUnknownItemToScene(item) |
1029 | 1019 |
# up to here |
1030 | 1020 |
|
1021 |
|
|
1022 |
# set symbol's connectItem |
|
1023 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
1024 |
connectors = [item for item in self.graphicsView.scene.items() if type(item) == QEngineeringConnectorItem and item.connectedItem is not None] |
|
1025 |
for connector in connectors: |
|
1026 |
# 처음에는 UID가 connectedItem에 String으로 들어가있기 때문에 |
|
1027 |
connector.connectedItem = self.graphicsView.findItemByUid(connector.connectedItem) |
|
1028 |
|
|
1031 | 1029 |
# Update Scene |
1032 | 1030 |
self.graphicsView.scene.update(self.graphicsView.sceneRect()) |
1033 | 1031 |
except Exception as ex: |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
4 | 4 |
try: |
5 | 5 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QPointF |
6 | 6 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QPainter, QCursor, QPen, QBrush, QColor, QTransform |
7 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication, QMessageBox
|
|
7 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QApplication |
|
8 | 8 |
except ImportError: |
9 | 9 |
try: |
10 | 10 |
from PyQt4.QtCore import * |
... | ... | |
363 | 363 |
else: |
364 | 364 |
if self.command is not None: |
365 | 365 |
self.command.execute(['keyPressEvent', event, []]) |
366 |
''' |
|
367 |
elif event.key() == Qt.Key_C and self.isPressCtrl: |
|
368 |
selectedItems = self.scene.selectedItems() |
|
369 |
if len(selectedItems) == 1 and issubclass(type(selectedItems[0]), SymbolSvgItem): |
|
370 |
from xml.etree.ElementTree import tostring |
|
371 |
xmlStr = str(tostring(selectedItems[0].toXml())) |
|
372 |
xmlStr = xmlStr[xmlStr.find('<SYMBOL>'):xmlStr.find('</SYMBOL>') + 9] |
|
373 |
QApplication.clipboard().setText(xmlStr) |
|
374 |
elif event.key() == Qt.Key_V and self.isPressCtrl: |
|
375 |
if self.command is not None and self.command.name == 'Default' and not self.command.isCopy: |
|
376 |
xmlStr = QApplication.clipboard().text() |
|
377 |
if xmlStr.find('<SYMBOL>') > -1 and xmlStr.find('</SYMBOL>') > -1: |
|
378 |
self.command.copySymbol(QApplication.clipboard().text()) |
|
379 |
elif event.key() == Qt.Key_S and self.isPressCtrl: |
|
380 |
import XmlGenerator as xg |
|
381 |
from AppDocData import AppDocData |
|
382 |
docData = AppDocData.instance() |
|
383 |
xg.writeXmlOnScene(docData.imgName, docData.imgWidth, docData.imgHeight, self.scene) |
|
384 |
QMessageBox.about(self, "알림", "정상적으로 저장되었습니다.") |
|
366 |
|
|
385 | 367 |
|
386 | 368 |
QGraphicsView.keyPressEvent(self, event) |
387 | 369 |
except Exception as ex: |
... | ... | |
565 | 547 |
svg.setSelected(True) |
566 | 548 |
self.scene.setFocusItem(svg) |
567 | 549 |
|
550 |
''' |
|
551 |
@brief find item by uid (SymbolSvgItem 기반, QEngineeringConnectorItem 제외, QEngineeringLineItem 포함) |
|
552 |
@author kyouho |
|
553 |
@date 2018.07.31 |
|
554 |
''' |
|
555 |
def findItemByUid(self, uid): |
|
556 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
557 |
items = [item for item in self.scene.items() if (issubclass(type(item), SymbolSvgItem) and type(item) != QEngineeringConnectorItem) or issubclass(type(item), QEngineeringLineItem)] |
|
558 |
for item in items: |
|
559 |
if item.uid == uid: |
|
560 |
return item |
|
561 |
|
|
562 |
return None |
|
563 |
|
|
564 |
|
|
565 |
|
|
568 | 566 |
if __name__ == '__main__': |
569 | 567 |
import sys |
570 | 568 |
try: |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
52 | 52 |
connector = QEngineeringConnectorItem(self) |
53 | 53 |
connector.setPos(vertex) |
54 | 54 |
connector.setParentItem(self) |
55 |
# connector의 connectPoint, sceneConnectPoint를 vertex로 함 추후 좀 알아봐서 수정 필요 |
|
56 |
connector.connectPoint = vertex |
|
57 |
connector.sceneConnectPoint = vertex |
|
58 |
|
|
55 | 59 |
connector.setZValue(self.zValue() + 1) |
56 | 60 |
self.connectors.append(connector) |
57 | 61 |
|
... | ... | |
864 | 868 |
|
865 | 869 |
item = None |
866 | 870 |
try: |
871 |
uidNode = node.find('UID') |
|
872 |
uid = uidNode.text if uidNode is not None else uuid.uuid4() # generate UUID |
|
873 |
|
|
867 | 874 |
startPoint = [float(x) for x in node.find('STARTPOINT').text.split(',')] |
868 | 875 |
endPoint = [float(x) for x in node.find('ENDPOINT').text.split(',')] |
869 | 876 |
lineType = node.find('TYPE').text if node.find('TYPE') else 'Primary' |
870 |
connsNode = node.find('CONNS') |
|
871 |
conns = [uuid.UUID(conn) if conn != 'None' else None for conn in connsNode.text.split(',')] if connsNode is not None else [None, None] |
|
872 | 877 |
|
873 | 878 |
item = QEngineeringLineItem(vertices=[startPoint, endPoint]) |
874 | 879 |
item.lineType = lineType |
875 |
for connIndex in range(len(conns)): |
|
876 |
item.connectors[connIndex].connectedItem = conns[connIndex] |
|
880 |
item.uid = uid |
|
881 |
|
|
882 |
connectors = node.find('CONNECTORS') |
|
883 |
if connectors is not None: |
|
884 |
iterIndex = 0 |
|
885 |
for connector in connectors.iter('CONNECTOR'): |
|
886 |
connectedItemStr = connector.find('CONNECTEDITEM').text |
|
887 |
connectPointStr = connector.find('CONNECTPOINT').text.split(',') |
|
888 |
sceneConnectPointStr = connector.find('SCENECONNECTPOINT').text.split(',') |
|
889 |
|
|
890 |
item.connectors[iterIndex].connectedItem = connectedItemStr if connectedItemStr != 'None' else None |
|
891 |
item.connectors[iterIndex].connectPoint = (float(connectPointStr[0]), float(connectPointStr[1])) |
|
892 |
item.connectors[iterIndex].sceneConnectPoint = (float(sceneConnectPointStr[0]), float(sceneConnectPointStr[1])) |
|
893 |
|
|
894 |
iterIndex += 1 |
|
877 | 895 |
except Exception as ex: |
878 | 896 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
879 | 897 |
|
... | ... | |
910 | 928 |
typeNode.text = self.lineType |
911 | 929 |
node.append(typeNode) |
912 | 930 |
|
913 |
# write conected items' uid to xml |
|
914 |
connsNode = Element('CONNS') |
|
915 |
connsNode.text = ','.join([str(connector.connectedItem.uid) if connector.connectedItem is not None else 'None' for connector in self.connectors]) |
|
916 |
node.append(connsNode) |
|
931 |
connectorsNode = Element('CONNECTORS') |
|
932 |
for connector in self.connectors: |
|
933 |
connectorNode = Element('CONNECTOR') |
|
934 |
connectedItemNode = Element('CONNECTEDITEM') |
|
935 |
connectedItemNode.text = str(connector.connectedItem.uid) if connector.connectedItem is not None else 'None' |
|
936 |
connectPointNode = Element('CONNECTPOINT') |
|
937 |
connectPointNode.text = str(connector.connectPoint[0]) + ',' + str(connector.connectPoint[1]) |
|
938 |
sceneConnectPointNode = Element('SCENECONNECTPOINT') |
|
939 |
sceneConnectPointNode.text = str(connector.sceneConnectPoint[0]) + ',' + str(connector.sceneConnectPoint[1]) |
|
940 |
|
|
941 |
connectorNode.append(connectedItemNode) |
|
942 |
connectorNode.append(connectPointNode) |
|
943 |
connectorNode.append(sceneConnectPointNode) |
|
944 |
connectorsNode.append(connectorNode) |
|
945 |
node.append(connectorsNode) |
|
946 |
|
|
917 | 947 |
# up to here |
918 | 948 |
except Exception as ex: |
919 | 949 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
646 | 646 |
|
647 | 647 |
try: |
648 | 648 |
uidNode = node.find('UID') |
649 |
uid = uuid.UUID(uidNode.text) if uidNode is not None else uuid.uuid4() # generate UUID
|
|
649 |
uid = uidNode.text if uidNode is not None else uuid.uuid4() # generate UUID
|
|
650 | 650 |
|
651 | 651 |
pt = [float(x) for x in node.find('LOCATION').text.split(',')] |
652 | 652 |
size = [float(x) for x in node.find('SIZE').text.split(',')] |
내보내기 Unified diff