37 |
37 |
QGraphicsSvgItem.__init__(self)
|
38 |
38 |
QEngineeringAbstractItem.__init__(self)
|
39 |
39 |
|
40 |
|
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable)#|QGraphicsItem.ItemIsMovable)
|
|
40 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable|QGraphicsItem.ItemSendsGeometryChanges)
|
41 |
41 |
|
42 |
42 |
self.dbUid = None
|
43 |
43 |
self.uid = uuid.uuid4() if uid is None else uuid.UUID(uid, version=4)
|
... | ... | |
370 |
370 |
return res
|
371 |
371 |
'''
|
372 |
372 |
|
|
373 |
def itemChange(self, change, value):
|
|
374 |
""" call signals when item's position is changed """
|
|
375 |
if change == QGraphicsItem.ItemPositionChange:
|
|
376 |
return value
|
|
377 |
|
|
378 |
return super().itemChange(change, value)
|
|
379 |
|
373 |
380 |
def toSql(self):
|
374 |
381 |
""" convert valve data to sql query """
|
375 |
382 |
import uuid
|
... | ... | |
435 |
442 |
|
436 |
443 |
# setting connectors
|
437 |
444 |
connectionPoints = symbolInfo.getConnectionPoint().split('/')
|
438 |
|
#print(connectionPoints)
|
439 |
445 |
for index in range(len(connectionPoints)):
|
440 |
446 |
if connectionPoints[index] == '':
|
441 |
447 |
break
|
... | ... | |
477 |
483 |
except Exception as ex:
|
478 |
484 |
from App import App
|
479 |
485 |
|
480 |
|
print(self.uid)
|
481 |
486 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
482 |
487 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
483 |
488 |
|
... | ... | |
711 |
716 |
@date 18.07.17
|
712 |
717 |
'''
|
713 |
718 |
def mouseReleaseEvent(self, event):
|
|
719 |
if hasattr(self, '_rotating') and event.button() == Qt.RightButton:
|
|
720 |
self.angle = -self.__angle
|
|
721 |
self.ungrabMouse()
|
|
722 |
del self._rotating
|
|
723 |
|
714 |
724 |
super().mouseReleaseEvent(event)
|
715 |
725 |
|
|
726 |
def mouseMoveEvent(self, event):
|
|
727 |
""" rotate symbol accroding to current mouse point """
|
|
728 |
if hasattr(self, '_rotating'):
|
|
729 |
# get origin point of symbol
|
|
730 |
origin = self.sceneBoundingRect().center()
|
|
731 |
# up to here
|
|
732 |
|
|
733 |
dx = (event.scenePos().x() - origin.x())
|
|
734 |
dy = (event.scenePos().y() - origin.y())
|
|
735 |
length = math.sqrt(dx*dx + dy*dy)
|
|
736 |
|
|
737 |
self.__angle = 0
|
|
738 |
if length > 0:
|
|
739 |
self.__angle = math.acos(dx / length)
|
|
740 |
cross = np.cross([1, 0], [dx, dy])
|
|
741 |
self.__angle = -self.__angle if cross < 0 else self.__angle
|
|
742 |
|
|
743 |
self.rotate(self.symbolOrigin, -self.__angle)
|
|
744 |
self.reSettingConnetors()
|
|
745 |
|
716 |
746 |
def removeSelfAttr(self, attributeName):
|
717 |
747 |
target = None
|
718 |
748 |
for attr in self.attrs:
|
... | ... | |
765 |
795 |
'''
|
766 |
796 |
def keyPressEvent(self, event):
|
767 |
797 |
from EngineeringErrorItem import QEngineeringErrorItem
|
|
798 |
from RotateSymbolDialog import QRotateSymbolDialog
|
|
799 |
|
768 |
800 |
if not self.isSelected():
|
769 |
801 |
return
|
770 |
802 |
if event.key() == Qt.Key_Delete:
|
... | ... | |
777 |
809 |
self.changeConnPoint()
|
778 |
810 |
elif event.key() == Qt.Key_F and type(self) is not QEngineeringErrorItem:
|
779 |
811 |
self.flipSymbol()
|
|
812 |
elif event.key() == Qt.Key_X:
|
|
813 |
dialog = QRotateSymbolDialog(None, self.angle, self.origin, self.zValue())
|
|
814 |
(isAccept, angle, x, y, z) = dialog.showDialog()
|
|
815 |
|
|
816 |
if isAccept:
|
|
817 |
self.angle = angle
|
|
818 |
self.loc = [x - self.symbolOrigin[0], y - self.symbolOrigin[1]]
|
|
819 |
self.origin = [x, y]
|
|
820 |
scene = self.scene()
|
|
821 |
scene.removeItem(self)
|
|
822 |
self.addSvgItemToScene(scene)
|
|
823 |
self.setZValue(z)
|
|
824 |
|
|
825 |
self.reSettingConnetors()
|
|
826 |
elif event.key() == Qt.Key_Escape:
|
|
827 |
if hasattr(self, '_rotating'):
|
|
828 |
self.ungrabMouse()
|
|
829 |
|
|
830 |
transform = QTransform()
|
|
831 |
transform.translate((self.loc[0] + self.symbolOrigin[0]), (self.loc[1] + self.symbolOrigin[1]))
|
|
832 |
transform.rotateRadians(self.angle)
|
|
833 |
transform.translate(-self.symbolOrigin[0], -self.symbolOrigin[1])
|
|
834 |
self.setTransform(transform)
|
|
835 |
self.reSettingConnetors()
|
|
836 |
|
|
837 |
del self._rotating
|
|
838 |
elif event.key() == Qt.Key_Up: ### translate up/down/left/right symbol
|
|
839 |
self.moveBy(0, -1)
|
|
840 |
#self.loc[1] = self.loc[1] - 1
|
|
841 |
self.reSettingConnetors()
|
|
842 |
elif event.key() == Qt.Key_Down:
|
|
843 |
self.moveBy(0, 1)
|
|
844 |
#self.loc[1] = self.loc[1] + 1
|
|
845 |
self.reSettingConnetors()
|
|
846 |
elif event.key() == Qt.Key_Left:
|
|
847 |
self.moveBy(-1, 0)
|
|
848 |
#self.loc[0] = self.loc[0] - 1
|
|
849 |
self.reSettingConnetors()
|
|
850 |
elif event.key() == Qt.Key_Right:
|
|
851 |
self.moveBy(1, 0)
|
|
852 |
#self.loc[0] = self.loc[0] + 1
|
|
853 |
self.reSettingConnetors()
|
780 |
854 |
|
781 |
855 |
'''
|
782 |
856 |
@brief connect attribute
|
... | ... | |
830 |
904 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
831 |
905 |
|
832 |
906 |
'''
|
833 |
|
@brief Double click event, Show rotate symbol dialog
|
|
907 |
@brief start rotating
|
834 |
908 |
@author euisung
|
835 |
909 |
@date 2019.04.16
|
836 |
910 |
'''
|
837 |
911 |
def mouseDoubleClickEvent(self, event):
|
838 |
|
from RotateSymbolDialog import QRotateSymbolDialog
|
839 |
|
from EngineeringErrorItem import QEngineeringErrorItem
|
840 |
|
|
841 |
|
if type(self) is QEngineeringErrorItem: return
|
842 |
|
|
843 |
|
dialog = QRotateSymbolDialog(None, self.angle, self.origin, self.zValue())
|
844 |
|
(isAccept, angle, x, y, z) = dialog.showDialog()
|
845 |
|
|
846 |
|
if isAccept:
|
847 |
|
self.angle = angle
|
848 |
|
self.loc = [x - self.symbolOrigin[0], y - self.symbolOrigin[1]]
|
849 |
|
self.origin = [x, y]
|
850 |
|
scene = self.scene()
|
851 |
|
scene.removeItem(self)
|
852 |
|
self.addSvgItemToScene(scene)
|
853 |
|
self.setZValue(z)
|
854 |
|
|
855 |
|
self.reSettingConnetors()
|
|
912 |
if not hasattr(self, '_rotating'):
|
|
913 |
self._rotating = True
|
|
914 |
self._rotation = self.rotation()
|
|
915 |
self.grabMouse()
|
856 |
916 |
|
857 |
917 |
'''
|
858 |
918 |
@brief get attribute
|
... | ... | |
994 |
1054 |
connectionNode.text = '/'.join(connection_point)
|
995 |
1055 |
node.append(connectionNode)
|
996 |
1056 |
|
997 |
|
#rect = self.sceneBoundingRect()
|
998 |
1057 |
locNode = Element('LOCATION')
|
999 |
|
locNode.text = '{},{}'.format(self.loc[0], self.loc[1])
|
|
1058 |
# calculate symbol's left-top corner
|
|
1059 |
transform = QTransform()
|
|
1060 |
transform.translate(self.scenePos().x(), self.scenePos().y())
|
|
1061 |
transform.rotateRadians(-self.angle)
|
|
1062 |
loc = transform.map(QPointF(self.symbolOrigin[0], self.symbolOrigin[1]))
|
|
1063 |
# up to here
|
|
1064 |
locNode.text = '{},{}'.format(loc.x() - self.symbolOrigin[0], loc.y() - self.symbolOrigin[1])
|
1000 |
1065 |
node.append(locNode)
|
1001 |
1066 |
|
1002 |
1067 |
sizeNode = Element('SIZE')
|
1003 |
|
#sizeNode.text = '{},{}'.format(rect.width(), rect.height())
|
1004 |
1068 |
sizeNode.text = '{},{}'.format(self.size[0], self.size[1])
|
1005 |
1069 |
node.append(sizeNode)
|
1006 |
1070 |
|
... | ... | |
1350 |
1414 |
painter.setPen(self.focuspen)
|
1351 |
1415 |
painter.drawRect(self.boundingRect())
|
1352 |
1416 |
|
|
1417 |
painter.drawEllipse(QPointF(0, 0), 10, 10)
|
|
1418 |
|
1353 |
1419 |
'''
|
1354 |
1420 |
@brief override paint(draw connection points)
|
1355 |
1421 |
@author humkyung
|
... | ... | |
1382 |
1448 |
kyouho 2018.07.30 remove connectors logic
|
1383 |
1449 |
'''
|
1384 |
1450 |
def addSvgItemToScene(self, scene):
|
1385 |
|
transform = QTransform()
|
1386 |
|
#print(self.symbolOrigin)
|
1387 |
|
|
1388 |
|
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
1389 |
|
transform.rotateRadians(-self.angle)
|
1390 |
|
currentPoint = self.getCurrentPoint()
|
1391 |
|
transform.translate(-currentPoint[0], -currentPoint[1])
|
1392 |
|
|
1393 |
|
if self.flip is 1:
|
1394 |
|
transform.scale(-1.0, 1.0)
|
1395 |
|
transform.translate(-self.size[0], 0)
|
1396 |
|
#allowed_error = 0.01
|
1397 |
|
#if abs(self.angle - 0) <= allowed_error or abs(self.angle - 3.14) <= allowed_error:
|
1398 |
|
# transform.translate(-self.size[0], 0)
|
1399 |
|
#elif abs(self.angle - 1.57) <= allowed_error:
|
1400 |
|
# transform.translate(0, 0)
|
1401 |
|
#else:
|
1402 |
|
# transform.translate(0, 0)
|
1403 |
|
|
1404 |
|
self.setTransform(transform)
|
|
1451 |
self.rotate(self.getCurrentPoint(), self.angle)
|
1405 |
1452 |
scene.addItem(self)
|
1406 |
1453 |
|
1407 |
1454 |
'''
|
... | ... | |
1470 |
1517 |
self.flip = 0
|
1471 |
1518 |
|
1472 |
1519 |
currentPoint = self.getCurrentPoint()
|
1473 |
|
self.reSettingSymbol(currentPoint, self.angle)
|
|
1520 |
self.rotate(currentPoint, self.angle)
|
|
1521 |
self.reSettingConnetors()
|
1474 |
1522 |
|
1475 |
1523 |
'''
|
1476 |
1524 |
@brief rotate Symbol
|
... | ... | |
1496 |
1544 |
else:
|
1497 |
1545 |
self.angle = angle
|
1498 |
1546 |
|
1499 |
|
#scene = self.scene()
|
1500 |
|
#self.scene().removeItem(self)
|
1501 |
|
#self.addSvgItemToScene(scene)
|
1502 |
1547 |
currentPoint = self.getCurrentPoint()
|
1503 |
|
self.reSettingSymbol(currentPoint, self.angle)
|
|
1548 |
self.rotate(currentPoint, self.angle)
|
|
1549 |
self.reSettingConnetors()
|
1504 |
1550 |
|
1505 |
1551 |
'''
|
1506 |
1552 |
@brief resetting rotate Symbol
|
1507 |
1553 |
@author kyouho
|
1508 |
1554 |
@date 2018.07.24
|
1509 |
1555 |
'''
|
1510 |
|
def reSettingSymbol(self, standardPoint, angle):
|
|
1556 |
def rotate(self, standardPoint, angle):
|
1511 |
1557 |
transform = QTransform()
|
1512 |
|
|
1513 |
1558 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
1514 |
1559 |
transform.rotateRadians(-angle)
|
1515 |
1560 |
transform.translate(-standardPoint[0], -standardPoint[1])
|
1516 |
1561 |
|
1517 |
1562 |
if self.flip is 1:
|
1518 |
1563 |
transform.scale(-1.0, 1.0)
|
1519 |
|
transform.translate(- 2 * self.symbolOrigin[0], 0)
|
|
1564 |
transform.translate(-2 * self.symbolOrigin[0], 0)
|
1520 |
1565 |
|
1521 |
1566 |
self.setTransform(transform)
|
1522 |
|
self.reSettingConnetors()
|
1523 |
1567 |
|
1524 |
1568 |
def reSettingConnetors(self):
|
1525 |
1569 |
for conn in self.connectors:
|
... | ... | |
1590 |
1634 |
@date 18.08.06
|
1591 |
1635 |
'''
|
1592 |
1636 |
def reCalculationRotatedItem(self):
|
1593 |
|
|
1594 |
1637 |
transform = QTransform()
|
1595 |
1638 |
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
1596 |
1639 |
transform.rotateRadians(-self.angle)
|