948 |
948 |
|
949 |
949 |
def mouseReleaseEvent(self, event):
|
950 |
950 |
if hasattr(self, '_rotating') and event.button() == Qt.RightButton:
|
|
951 |
from RotateCommand import RotateCommand
|
|
952 |
|
951 |
953 |
self.angle = -self._angle if self._angle > -math.pi and self._angle < 0 else 2 * math.pi - self._angle
|
|
954 |
|
|
955 |
self.scene().undo_stack.push(RotateCommand(self.scene(), [self,], self._rotating))
|
|
956 |
|
952 |
957 |
self.ungrabMouse()
|
953 |
958 |
del self._rotating
|
954 |
959 |
|
... | ... | |
971 |
976 |
cross = int(np.cross([1, 0], [dx, dy]))
|
972 |
977 |
self._angle = -self._angle if cross < 0 else self._angle
|
973 |
978 |
|
974 |
|
self.rotate(self.getCurrentPoint(), -self._angle)
|
|
979 |
self.rotate(-self._angle)
|
975 |
980 |
|
976 |
981 |
def removeSelfAttr(self, attributeName):
|
977 |
982 |
target = None
|
... | ... | |
1033 |
1038 |
return
|
1034 |
1039 |
if event.key() == Qt.Key_B:
|
1035 |
1040 |
self.bind_close_items()
|
|
1041 |
"""
|
1036 |
1042 |
elif event.key() == Qt.Key_R and QApplication.keyboardModifiers() != Qt.ControlModifier and \
|
1037 |
1043 |
type(self) is not QEngineeringErrorItem:
|
1038 |
1044 |
self.rotateSymbol()
|
1039 |
|
elif event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem:
|
|
1045 |
"""
|
|
1046 |
if event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem:
|
1040 |
1047 |
pass
|
1041 |
1048 |
elif event.key() == Qt.Key_C and type(self) is not QEngineeringErrorItem:
|
1042 |
1049 |
self.changeConnPoint()
|
1043 |
1050 |
elif event.key() == Qt.Key_F and type(self) is not QEngineeringErrorItem:
|
1044 |
|
self.flipSymbol()
|
|
1051 |
self.flip = 1 if self.flip is 0 else 0
|
|
1052 |
self.flip_symbol()
|
1045 |
1053 |
elif event.key() == Qt.Key_Return:
|
1046 |
1054 |
return
|
1047 |
1055 |
# disable
|
... | ... | |
1052 |
1060 |
self.angle = angle
|
1053 |
1061 |
self.loc = [x - self.symbolOrigin[0], y - self.symbolOrigin[1]]
|
1054 |
1062 |
self.origin = [x, y]
|
1055 |
|
self.rotate(self.getCurrentPoint(), self.angle)
|
|
1063 |
self.rotate(self.angle)
|
1056 |
1064 |
self.setZValue(z)
|
1057 |
1065 |
elif event.key() == Qt.Key_Escape:
|
1058 |
1066 |
if hasattr(self, '_rotating'):
|
1059 |
1067 |
self.ungrabMouse()
|
1060 |
1068 |
|
1061 |
|
transform = QTransform()
|
1062 |
|
transform.translate((self.loc[0] + self.symbolOrigin[0]), (self.loc[1] + self.symbolOrigin[1]))
|
1063 |
|
transform.rotateRadians(self.angle)
|
1064 |
|
transform.translate(-self.symbolOrigin[0], -self.symbolOrigin[1])
|
1065 |
|
self.setTransform(transform)
|
1066 |
|
|
|
1069 |
self.rotate(math.radians(self._rotating))
|
1067 |
1070 |
del self._rotating
|
1068 |
1071 |
elif event.key() == Qt.Key_Up: # translate up/down/left/right symbol
|
1069 |
1072 |
modifiers = QApplication.keyboardModifiers()
|
... | ... | |
1177 |
1180 |
|
1178 |
1181 |
def mouseDoubleClickEvent(self, event):
|
1179 |
1182 |
if not hasattr(self, '_rotating'):
|
1180 |
|
self._rotating = True
|
|
1183 |
self._rotating = self.rotation()
|
1181 |
1184 |
self.grabMouse()
|
1182 |
1185 |
|
1183 |
1186 |
'''
|
... | ... | |
1908 |
1911 |
'''
|
1909 |
1912 |
|
1910 |
1913 |
def addSvgItemToScene(self, scene):
|
1911 |
|
self.rotate(self.getCurrentPoint(), self.angle)
|
|
1914 |
self.setTransformOriginPoint(QPointF(self.symbolOrigin[0], self.symbolOrigin[1]))
|
|
1915 |
|
|
1916 |
if self.flip:
|
|
1917 |
self.flip_symbol()
|
|
1918 |
|
|
1919 |
self.moveBy(-self.symbolOrigin[0], -self.symbolOrigin[1])
|
|
1920 |
self.setRotation(math.degrees(-self.angle))
|
|
1921 |
self.moveBy(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
|
1922 |
|
|
1923 |
# self.rotate_symbol(self.angle, self.getCurrentPoint())
|
1912 |
1924 |
scene.addItem(self)
|
1913 |
1925 |
self.size[0], self.size[1] = round(self.sceneBoundingRect().width()), round(self.sceneBoundingRect().height())
|
1914 |
1926 |
trans = self.transform()
|
... | ... | |
1969 |
1981 |
@date 2018.05.25
|
1970 |
1982 |
'''
|
1971 |
1983 |
|
1972 |
|
def boundingRectOnScene(self):
|
|
1984 |
def roundingRectOnScene(self):
|
1973 |
1985 |
rect = self.boundingRect()
|
1974 |
1986 |
rect.moveTo(self.loc[0], self.loc[1])
|
1975 |
1987 |
return rect
|
1976 |
1988 |
|
1977 |
|
def flipSymbol(self):
|
1978 |
|
'''
|
1979 |
|
@brief remove item when user press delete key
|
1980 |
|
@author humkyung
|
1981 |
|
@date 2018.04.23
|
1982 |
|
'''
|
1983 |
|
if self.flip is 0:
|
1984 |
|
self.flip = 1
|
1985 |
|
else:
|
1986 |
|
self.flip = 0
|
1987 |
|
|
1988 |
|
currentPoint = self.getCurrentPoint()
|
1989 |
|
self.rotate(currentPoint, self.angle)
|
|
1989 |
def flip_symbol(self) -> None:
|
|
1990 |
"""flip symbol"""
|
1990 |
1991 |
|
1991 |
|
'''
|
1992 |
|
@brief rotate Symbol
|
1993 |
|
@author kyouho
|
1994 |
|
@date 2018.07.24
|
1995 |
|
'''
|
1996 |
|
|
1997 |
|
def rotateSymbol(self, angle=None):
|
1998 |
|
if angle is None:
|
1999 |
|
# degree 0
|
2000 |
|
if 0 == self.angle:
|
2001 |
|
self.angle = 1.57
|
2002 |
|
# degree 90
|
2003 |
|
elif (1.57 == self.angle):
|
2004 |
|
self.angle = 3.14
|
2005 |
|
# degree 180
|
2006 |
|
elif 3.14 == self.angle:
|
2007 |
|
self.angle = 4.71
|
2008 |
|
# degree 270
|
2009 |
|
elif 4.71 == self.angle:
|
2010 |
|
self.angle = 0
|
2011 |
|
else:
|
2012 |
|
self.angle = 0
|
2013 |
|
else:
|
2014 |
|
self.angle = angle
|
2015 |
|
|
2016 |
|
currentPoint = self.getCurrentPoint()
|
2017 |
|
self.rotate(currentPoint, self.angle)
|
2018 |
|
|
2019 |
|
def get_transform(self, pt, angle):
|
2020 |
|
""" return a transform """
|
2021 |
1992 |
transform = QTransform()
|
2022 |
|
transform.translate(self.loc[0] + self.symbolOrigin[0], self.loc[1] + self.symbolOrigin[1])
|
2023 |
|
transform.rotateRadians(-angle)
|
2024 |
|
transform.translate(-pt[0], -pt[1])
|
2025 |
|
|
2026 |
1993 |
if self.flip is 1:
|
|
1994 |
rect = self.boundingRect()
|
2027 |
1995 |
transform.scale(-1.0, 1.0)
|
2028 |
|
transform.translate(-2 * self.symbolOrigin[0], 0)
|
|
1996 |
transform.translate(-rect.width(), 0)
|
2029 |
1997 |
|
2030 |
|
return transform
|
|
1998 |
self.setTransform(transform)
|
2031 |
1999 |
|
2032 |
|
'''
|
2033 |
|
@brief resetting rotate Symbol
|
2034 |
|
@author kyouho
|
2035 |
|
@date 2018.07.24
|
2036 |
|
'''
|
2037 |
|
|
2038 |
|
def rotate(self, standardPoint, angle):
|
2039 |
|
self.setTransform(self.get_transform(standardPoint, angle))
|
2040 |
|
self.setRotation(0) # force to emit itemChange signal
|
|
2000 |
def rotate(self, angle: float) -> None:
|
|
2001 |
"""rotate symbol by given angle in radian"""
|
|
2002 |
import math
|
|
2003 |
self.setRotation(math.degrees(angle))
|
2041 |
2004 |
|
2042 |
2005 |
'''
|
2043 |
2006 |
@brief change Conn point
|
... | ... | |
2072 |
2035 |
currentPoint = self.getCurrentPoint()
|
2073 |
2036 |
#self.reSettingSymbol(currentPoint, self.angle)
|
2074 |
2037 |
|
2075 |
|
'''
|
2076 |
|
@brief get standard point
|
2077 |
|
@author kyouho
|
2078 |
|
@date 2018.07.25
|
2079 |
|
'''
|
2080 |
|
|
2081 |
2038 |
def getCurrentPoint(self):
|
|
2039 |
"""return transform origin point"""
|
2082 |
2040 |
pointList = []
|
2083 |
2041 |
pointList.append(self.symbolOrigin)
|
2084 |
2042 |
for connector in self.connectors:
|
... | ... | |
2092 |
2050 |
@date 18.08.06
|
2093 |
2051 |
'''
|
2094 |
2052 |
|
|
2053 |
"""
|
2095 |
2054 |
def reCalculationRotatedItem(self):
|
2096 |
2055 |
goPoint = self.get_transform(self.getCurrentPoint(), self.angle).map(
|
2097 |
2056 |
QPoint(self.symbolOrigin[0], self.symbolOrigin[1]))
|
2098 |
2057 |
self.loc = [self.loc[0] + self.origin[0] - goPoint.x(), self.loc[1] + self.origin[1] - goPoint.y()]
|
|
2058 |
"""
|
2099 |
2059 |
|
2100 |
2060 |
|
2101 |
2061 |
def recursiveChangeAttributes(node, attName, attValue):
|