개정판 6a187649
dev issue #637: add spec break at scene
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
33 | 33 |
|
34 | 34 |
self.symbol = None |
35 | 35 |
self.isCopy = False |
36 |
self.isSpecBreak = False |
|
37 |
self.specBreak_startPoint = [] |
|
36 | 38 |
|
37 | 39 |
''' |
38 | 40 |
@brief Scroll / Pan / Zoom with Wheel Button |
... | ... | |
113 | 115 |
self.copySymbol(QApplication.clipboard().text()) |
114 | 116 |
|
115 | 117 |
self.isTreated = False |
118 |
elif self.isCopy and self.isSpecBreak: |
|
119 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
|
120 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
121 |
|
|
122 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform()) |
|
123 |
if item is not None and type(item) is QEngineeringConnectorItem: |
|
124 |
scenePos = QPointF(item.center()[0], item.center()[1]) |
|
125 |
|
|
126 |
offsetX = 0 |
|
127 |
offsetY = 0 |
|
128 |
transform = QTransform() |
|
129 |
currentPt = self.symbol.getCurrentPoint() |
|
130 |
if 0 == self.symbol.angle or 3.14 == self.symbol.angle: |
|
131 |
transform.translate(self.specBreak_startPoint[0], scenePos.y()) |
|
132 |
offsetY = self.specBreak_startPoint[1] - scenePos.y() |
|
133 |
|
|
134 |
else: |
|
135 |
transform.translate(scenePos.x(), self.specBreak_startPoint[1]) |
|
136 |
offsetX = self.specBreak_startPoint[0] - scenePos.x() |
|
137 |
|
|
138 |
transform.rotateRadians(-self.symbol.angle) |
|
139 |
transform.translate(-currentPt[0], -currentPt[1]) |
|
140 |
self.symbol.setTransform(transform) |
|
141 |
|
|
142 |
self.symbol.specBreak_offsetX = offsetX |
|
143 |
self.symbol.specBreak_offsetY = offsetY |
|
144 |
|
|
145 |
connLoc = self.symbol.connectors[0]._loc |
|
146 |
self.symbol.connectors[0].setPos((float(connLoc[0] + offsetX), float(connLoc[1] + offsetY))) |
|
147 |
self.symbol.loc = (self.symbol.loc[0] - offsetX, self.symbol.loc[1] - offsetY) |
|
148 |
#self.symbol.connectors[0].connectPoint = (self.symbol.connectors[0].connectPoint[0] - offsetX, self.symbol.connectors[0].connectPoint[1] - offsetY) |
|
149 |
|
|
150 |
self.symbol = None |
|
151 |
self.isCopy = False |
|
152 |
self.isSpecBreak = False |
|
153 |
|
|
154 |
QApplication.instance().setOverrideCursor(QCursor(Qt.ArrowCursor)) |
|
155 |
elif 'mouseMoveEvent' == param[0]: |
|
156 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
157 |
|
|
158 |
item = self.imageViewer.scene.itemAt(scenePos, QTransform()) |
|
159 |
if item is not None and type(item) is QEngineeringConnectorItem: |
|
160 |
scenePos = QPointF(item.center()[0], item.center()[1]) |
|
161 |
|
|
162 |
transform = QTransform() |
|
163 |
currentPt = self.symbol.getCurrentPoint() |
|
164 |
if 0 == self.symbol.angle or 3.14 == self.symbol.angle: |
|
165 |
transform.translate(self.specBreak_startPoint[0], scenePos.y()) |
|
166 |
else: |
|
167 |
transform.translate(scenePos.x(), self.specBreak_startPoint[1]) |
|
168 |
transform.rotateRadians(-self.symbol.angle) |
|
169 |
transform.translate(-currentPt[0], -currentPt[1]) |
|
170 |
self.symbol.setTransform(transform) |
|
171 |
elif 'keyPressEvent' == param[0] and event.key() == Qt.Key_Escape: |
|
172 |
self.imageViewer.scene.removeItem(self.symbol) |
|
173 |
self.symbol = None |
|
174 |
self.isCopy = False |
|
175 |
self.isSpecBreak = False |
|
176 |
|
|
116 | 177 |
else: |
117 | 178 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
118 | 179 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
DTI_PID/DTI_PID/ItemPropertyTableWidget.py | ||
---|---|---|
317 | 317 |
if self.symData.type == 'Segment Breaks' and (key == 'Up Stream' or key == 'Down Stream'): |
318 | 318 |
comboBox = QComboBox() |
319 | 319 |
comboBox.addItem('') |
320 |
|
|
321 | 320 |
|
321 |
itemList = self.mainWindow.findOverlapConnector(self.symData.connectors[0]) |
|
322 |
for item in itemList: |
|
323 |
comboBox.addItem(str(item.uid)) |
|
322 | 324 |
|
323 |
#dd |
|
324 |
#self.mainWindow |
|
325 |
if key == 'Up Stream': |
|
326 |
comboBox.currentTextChanged.connect(self.upStreamChanged) |
|
327 |
else: |
|
328 |
comboBox.currentTextChanged.connect(self.downStreamChanged) |
|
325 | 329 |
|
326 | 330 |
tempIndex = comboBox.findText(value) if comboBox.findText(value) != -1 else 0 |
327 | 331 |
comboBox.setCurrentIndex(tempIndex) |
332 |
|
|
328 | 333 |
self.setCellWidget(row, 1, comboBox) |
329 | 334 |
else: |
330 | 335 |
self.setItem(row, 1, valueItem) |
... | ... | |
349 | 354 |
else: |
350 | 355 |
self.setRowCount(0) |
351 | 356 |
|
357 |
''' |
|
358 |
@brief combobox change event |
|
359 |
@author kyouho |
|
360 |
@date 2018.08.28 |
|
361 |
''' |
|
362 |
def upStreamChanged(self, text): |
|
363 |
if self.symData is not None: |
|
364 |
find = False |
|
365 |
for index in range(len(self.symData.attrs)): |
|
366 |
if type(self.symData.attrs[index]) is tuple and self.symData.attrs[index][0] == 'Up Stream': |
|
367 |
self.symData.attrs[index] = (self.symData.attrs[index][0], text) |
|
368 |
find = True |
|
369 |
break |
|
370 |
|
|
371 |
if not find: |
|
372 |
self.symData.attrs.append(('Up Stream', text)) |
|
373 |
|
|
374 |
''' |
|
375 |
@brief combobox change event |
|
376 |
@author kyouho |
|
377 |
@date 2018.08.28 |
|
378 |
''' |
|
379 |
def downStreamChanged(self, text): |
|
380 |
if self.symData is not None: |
|
381 |
find = False |
|
382 |
for index in range(len(self.symData.attrs)): |
|
383 |
if type(self.symData.attrs[index]) is tuple and self.symData.attrs[index][0] == 'Down Stream': |
|
384 |
self.symData.attrs[index] = (self.symData.attrs[index][0], text) |
|
385 |
find = True |
|
386 |
break |
|
387 |
|
|
388 |
if not find: |
|
389 |
self.symData.attrs.append(('Down Stream', text)) |
|
352 | 390 |
|
353 | 391 |
''' |
354 | 392 |
@brief find text item using uid |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1382 | 1382 |
for symbol in symbols: |
1383 | 1383 |
# 처음에는 attrs의 uid가 connectedItem에 String으로 들어가있기 때문에 |
1384 | 1384 |
for index in range(len(symbol.attrs)): |
1385 |
if type(symbol.attrs[index]) is not UserInputAttribute: |
|
1385 |
if type(symbol.attrs[index]) is not UserInputAttribute and type(symbol.attrs[index]) is not tuple:
|
|
1386 | 1386 |
symbol.attrs[index] = self.graphicsView.findItemByUid(symbol.attrs[index]) |
1387 | 1387 |
|
1388 | 1388 |
# Update Scene |
... | ... | |
1496 | 1496 |
@date 2018.08.21 |
1497 | 1497 |
''' |
1498 | 1498 |
def checkAttribute(self): |
1499 |
docData = AppDocData.instance() |
|
1500 |
if not self.graphicsView.hasImage(): |
|
1501 |
return |
|
1499 |
try: |
|
1502 | 1500 |
|
1503 |
# symbol 경우 |
|
1504 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem)] |
|
1505 |
for item in items: |
|
1506 |
attrs = item.attrs |
|
1507 |
|
|
1508 |
removeAttrList = [] |
|
1509 |
for attr in attrs: |
|
1510 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute) |
|
1511 |
if attrInfo is None: |
|
1512 |
removeAttrList.append(attr) |
|
1513 |
# 해당 attribute가 맞는지 확인 |
|
1514 |
else: |
|
1515 |
attrType = attrInfo[2] |
|
1516 |
_type = type(attr) |
|
1517 |
if attrType == 'Symbol Item': |
|
1518 |
if not issubclass(_type, SymbolSvgItem): |
|
1519 |
removeAttrList.append(attr) |
|
1520 |
elif attrType == 'Text Item': |
|
1521 |
if _type is not QEngineeringTextItem: |
|
1522 |
removeAttrList.append(attr) |
|
1523 |
elif attrType == 'Int': |
|
1524 |
if _type is not UserInputAttribute and self.isNumber(attr.text): |
|
1525 |
removeAttrList.append(attr) |
|
1526 |
elif attrType == 'String': |
|
1527 |
if _type is not UserInputAttribute: |
|
1528 |
removeAttrList.append(attr) |
|
1501 |
docData = AppDocData.instance() |
|
1502 |
if not self.graphicsView.hasImage(): |
|
1503 |
return |
|
1504 |
|
|
1505 |
# symbol 경우 |
|
1506 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), SymbolSvgItem)] |
|
1507 |
for item in items: |
|
1508 |
attrs = item.attrs |
|
1509 |
|
|
1510 |
removeAttrList = [] |
|
1511 |
for attr in attrs: |
|
1512 |
if type(attr) is tuple: |
|
1513 |
continue |
|
1529 | 1514 |
|
1530 |
for attr in removeAttrList: |
|
1531 |
attrs.remove(attr) |
|
1515 |
if attr is None: |
|
1516 |
removeAttrList.append(attr) |
|
1517 |
continue |
|
1532 | 1518 |
|
1533 |
# Line No Text Item의 경우 |
|
1534 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringLineNoTextItem)] |
|
1535 |
for item in items: |
|
1536 |
attrs = item._attrs |
|
1537 |
|
|
1538 |
removeAttrList = [] |
|
1539 |
for attr in attrs: |
|
1540 |
if type(attr) is UserInputAttribute: |
|
1541 |
attrInfo = docData.getLinePropertiesByUID(attr.attribute) |
|
1519 |
attrInfo = docData.getSymbolAttributeByUID(attr.attribute) |
|
1542 | 1520 |
if attrInfo is None: |
1543 | 1521 |
removeAttrList.append(attr) |
1522 |
# 해당 attribute가 맞는지 확인 |
|
1523 |
else: |
|
1524 |
attrType = attrInfo[2] |
|
1525 |
_type = type(attr) |
|
1526 |
if attrType == 'Symbol Item': |
|
1527 |
if not issubclass(_type, SymbolSvgItem): |
|
1528 |
removeAttrList.append(attr) |
|
1529 |
elif attrType == 'Text Item': |
|
1530 |
if _type is not QEngineeringTextItem: |
|
1531 |
removeAttrList.append(attr) |
|
1532 |
elif attrType == 'Int': |
|
1533 |
if _type is not UserInputAttribute and self.isNumber(attr.text): |
|
1534 |
removeAttrList.append(attr) |
|
1535 |
elif attrType == 'String': |
|
1536 |
if _type is not UserInputAttribute: |
|
1537 |
removeAttrList.append(attr) |
|
1538 |
|
|
1539 |
for attr in removeAttrList: |
|
1540 |
attrs.remove(attr) |
|
1541 |
|
|
1542 |
# Line No Text Item의 경우 |
|
1543 |
items = [item for item in self.graphicsView.scene.items() if issubclass(type(item), QEngineeringLineNoTextItem)] |
|
1544 |
for item in items: |
|
1545 |
attrs = item._attrs |
|
1546 |
|
|
1547 |
removeAttrList = [] |
|
1548 |
for attr in attrs: |
|
1549 |
if type(attr) is UserInputAttribute: |
|
1550 |
attrInfo = docData.getLinePropertiesByUID(attr.attribute) |
|
1551 |
if attrInfo is None: |
|
1552 |
removeAttrList.append(attr) |
|
1544 | 1553 |
|
1545 |
for attr in removeAttrList: |
|
1546 |
attrs.remove(attr) |
|
1554 |
for attr in removeAttrList:
|
|
1555 |
attrs.remove(attr)
|
|
1547 | 1556 |
|
1557 |
except Exception as ex: |
|
1558 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
1559 |
self.addMessage.emit(MessageType.Error, message) |
|
1548 | 1560 |
''' |
1549 | 1561 |
@brief Check Number |
1550 | 1562 |
@author kyouho |
... | ... | |
1560 | 1572 |
return False |
1561 | 1573 |
|
1562 | 1574 |
''' |
1575 |
@brief find overlap Connector |
|
1576 |
@author kyouho |
|
1577 |
@date 2018.08.28 |
|
1563 | 1578 |
''' |
1564 |
#def findConnect |
|
1579 |
def findOverlapConnector(self, connectorItem): |
|
1580 |
from shapely.geometry import Point |
|
1581 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
|
1582 |
itemList = [] |
|
1583 |
|
|
1584 |
x = connectorItem.center()[0] |
|
1585 |
y = connectorItem.center()[1] |
|
1586 |
|
|
1587 |
connectors = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringConnectorItem and item != connectorItem] |
|
1588 |
for connector in connectors: |
|
1589 |
if Point(x, y).distance(Point(connector.center()[0], connector.center()[1])) < 5: |
|
1590 |
itemList.append(connector.parent) |
|
1591 |
|
|
1592 |
return itemList |
|
1565 | 1593 |
|
1566 | 1594 |
|
1567 | 1595 |
if __name__ == '__main__': |
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
507 | 507 |
svg = self.createSymbolObject(svgFileName) |
508 | 508 |
self.matchSymbolToLine(svg, scenePos) |
509 | 509 |
|
510 |
if svg.type == 'Segment Breaks': |
|
511 |
svg.angle = 0 |
|
512 |
self.command.specBreak_startPoint = [scenePos.x(), scenePos.y()] |
|
513 |
self.command.isCopy = True |
|
514 |
self.command.isSpecBreak = True |
|
515 |
self.command.symbol = svg |
|
516 |
|
|
517 |
|
|
510 | 518 |
event.acceptProposedAction() |
511 | 519 |
|
512 | 520 |
''' |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
59 | 59 |
self.currentCursor = 0 |
60 | 60 |
self.transfer = Transfer() |
61 | 61 |
|
62 |
self.specBreak_offsetX = 0 |
|
63 |
self.specBreak_offsetY = 0 |
|
64 |
|
|
62 | 65 |
|
63 | 66 |
try: |
64 | 67 |
f = QFile(path) |
... | ... | |
127 | 130 |
for index in range(len(connectionPoints)): |
128 | 131 |
split = connectionPoints[index].split(',') |
129 | 132 |
self.setConnector() |
130 |
self.connectors[index].setPos((float(split[0]), float(split[1])))
|
|
133 |
self.connectors[index].setPos((float(split[0]) - self.specBreak_offsetX, float(split[1]) - self.specBreak_offsetY))
|
|
131 | 134 |
self.connectors[index].connectPoint = (float(split[0]), float(split[1])) |
132 | 135 |
self.connectors[index].sceneConnectPoint = connPts[index] if len(connPts) > index else None |
133 | 136 |
|
... | ... | |
522 | 525 |
attrs['Label'] = '{}'.format(attr) |
523 | 526 |
elif type(attr) is UserInputAttribute: |
524 | 527 |
attrs[attr.attribute] = attr.text |
528 |
elif type(attr) is tuple: |
|
529 |
attrs[attr[0]] = attr[1] |
|
525 | 530 |
|
526 | 531 |
return attrs |
527 | 532 |
|
... | ... | |
624 | 629 |
|
625 | 630 |
attributesNode = Element('SYMBOLATTRIBUTES') |
626 | 631 |
for attr in self.attrs: |
627 |
if type(attr) is not UserInputAttribute: |
|
632 |
if type(attr) is UserInputAttribute: |
|
633 |
attributesNode.append(attr.toXml()) |
|
634 |
elif type(attr) is not tuple: |
|
628 | 635 |
attributeNode = Element('SYMBOLATTRIBUTE') |
629 | 636 |
attributeNode.text = str(attr.uid) |
630 | 637 |
attributesNode.append(attributeNode) |
631 |
else: |
|
632 |
attributesNode.append(attr.toXml()) |
|
638 |
elif type(attr) is tuple and self.type == 'Segment Breaks': |
|
639 |
attributeNode = Element(attr[0].upper().replace(' ','')) |
|
640 |
attributeNode.text = str(attr[1] if attr[1] is not None else '') |
|
641 |
attributesNode.append(attributeNode) |
|
633 | 642 |
|
634 | 643 |
node.append(attributesNode) |
635 | 644 |
|
... | ... | |
637 | 646 |
currentPointModeIndexNode.text = str(self.currentPointModeIndex) |
638 | 647 |
node.append(currentPointModeIndexNode) |
639 | 648 |
|
649 |
if self.type == 'Segment Breaks': |
|
650 |
specBreakOffsetXNode = Element('SPECBREAKOFFSETX') |
|
651 |
specBreakOffsetXNode.text = str(self.specBreak_offsetX) |
|
652 |
node.append(specBreakOffsetXNode) |
|
653 |
|
|
654 |
specBreakOffsetYNode = Element('SPECBREAKOFFSETY') |
|
655 |
specBreakOffsetYNode.text = str(self.specBreak_offsetY) |
|
656 |
node.append(specBreakOffsetYNode) |
|
657 |
|
|
658 |
|
|
659 |
|
|
640 | 660 |
except Exception as ex: |
641 | 661 |
return str(self.uid) |
642 | 662 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
... | ... | |
723 | 743 |
typeValue = attr.find('TYPEVALUE').text |
724 | 744 |
item[0].attrs.append(UserInputAttribute(typeUID, typeValue)) |
725 | 745 |
|
746 |
if item[0].type == 'Segment Breaks': |
|
747 |
upStreamNode = attributes.find('UPSTREAM') |
|
748 |
downStreamNode = attributes.find('DOWNSTREAM') |
|
749 |
if upStreamNode is not None : |
|
750 |
item[0].attrs.append(('Up Stream', upStreamNode.text)) |
|
751 |
if downStreamNode is not None: |
|
752 |
item[0].attrs.append(('Down Stream', downStreamNode.text)) |
|
753 |
|
|
726 | 754 |
currentPointModeIndex = node.find('CURRENTPOINTMODEINDEX') |
727 | 755 |
if currentPointModeIndex is not None: |
728 | 756 |
item[0].currentPointModeIndex = int(currentPointModeIndex.text) |
757 |
|
|
758 |
if item[0].type == 'Segment Breaks': |
|
759 |
specBreakOffsetXNode = node.find('SPECBREAKOFFSETX') |
|
760 |
specBreakOffsetYNode = node.find('SPECBREAKOFFSETY') |
|
761 |
if specBreakOffsetXNode is not None and specBreakOffsetYNode is not None: |
|
762 |
item[0].specBreak_offsetX = float(specBreakOffsetXNode.text) |
|
763 |
item[0].specBreak_offsetY = float(specBreakOffsetYNode.text) |
|
764 |
connLoc = item[0].connectors[0]._loc |
|
765 |
item[0].connectors[0].setPos((float(connLoc[0] + item[0].specBreak_offsetX), float(connLoc[1] + item[0].specBreak_offsetY))) |
|
766 |
item[0].reSettingSymbol(item[0].getCurrentPoint(), item[0].angle) |
|
767 |
|
|
729 | 768 |
item[1] = owner |
730 | 769 |
except Exception as ex: |
731 | 770 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
... | ... | |
857 | 896 |
''' |
858 | 897 |
def addSvgItemToScene(self, scene): |
859 | 898 |
transform = QTransform() |
860 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
|
899 |
transform.translate(self.loc[0] + self.symbolOrigin[0] + self.specBreak_offsetX, self.loc[1] + self.symbolOrigin[1] + self.specBreak_offsetY)
|
|
861 | 900 |
transform.rotateRadians(-self.angle) |
862 | 901 |
currentPoint = self.getCurrentPoint() |
863 |
transform.translate(-currentPoint[0], -currentPoint[1])
|
|
902 |
transform.translate(-currentPoint[0] - self.specBreak_offsetX, -currentPoint[1] - self.specBreak_offsetY)
|
|
864 | 903 |
|
865 | 904 |
self.setTransform(transform) |
866 | 905 |
scene.addItem(self) |
... | ... | |
943 | 982 |
def reSettingSymbol(self, standardPoint, angle): |
944 | 983 |
transform = QTransform() |
945 | 984 |
|
946 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
|
985 |
transform.translate(self.loc[0] + self.symbolOrigin[0] + self.specBreak_offsetX, self.loc[1] + self.symbolOrigin[1] + self.specBreak_offsetY)
|
|
947 | 986 |
transform.rotateRadians(-angle) |
948 |
transform.translate(-standardPoint[0], -standardPoint[1])
|
|
987 |
transform.translate(-standardPoint[0] - self.specBreak_offsetX, -standardPoint[1] - self.specBreak_offsetY)
|
|
949 | 988 |
|
950 | 989 |
self.setTransform(transform) |
951 | 990 |
|
내보내기 Unified diff