2737 |
2737 |
def keyPressEvent(self, event):
|
2738 |
2738 |
"""restore to default command when user press Escape key"""
|
2739 |
2739 |
try:
|
|
2740 |
#print('main : ' + str(event.key()))
|
2740 |
2741 |
if event.key() == Qt.Key_Escape:
|
2741 |
2742 |
checked = self.checked_action()
|
2742 |
2743 |
if checked:
|
2743 |
2744 |
checked.setChecked(False)
|
2744 |
2745 |
self.graphicsView.useDefaultCommand()
|
2745 |
|
elif event.key() == Qt.Key_M: # merge text as vertical
|
|
2746 |
elif event.key() == Qt.Key_M: # merge text, line
|
2746 |
2747 |
from TextInfo import TextInfo
|
|
2748 |
from EngineeringConnectorItem import QEngineeringConnectorItem
|
|
2749 |
from LineDetector import LineDetector
|
|
2750 |
|
|
2751 |
# line merge
|
|
2752 |
lineItems = [line for line in self.graphicsView.scene().selectedItems() if
|
|
2753 |
issubclass(type(line), QEngineeringLineItem)]
|
|
2754 |
lineValidation = True
|
|
2755 |
if len(lineItems) > 1:
|
|
2756 |
x = []
|
|
2757 |
y = []
|
|
2758 |
connectedItems = []
|
|
2759 |
isVertical = None
|
|
2760 |
for line in lineItems:
|
|
2761 |
if isVertical == None:
|
|
2762 |
isVertical = line.isVertical()
|
|
2763 |
elif isVertical != line.isVertical():
|
|
2764 |
lineValidation = False
|
|
2765 |
|
|
2766 |
x.append(line.start_point()[0])
|
|
2767 |
y.append(line.start_point()[1])
|
|
2768 |
x.append(line.end_point()[0])
|
|
2769 |
y.append(line.end_point()[1])
|
|
2770 |
|
|
2771 |
if line.connectors[0].connectedItem:
|
|
2772 |
connectedItems.append(line.connectors[0].connectedItem)
|
|
2773 |
if line.connectors[1].connectedItem:
|
|
2774 |
connectedItems.append(line.connectors[1].connectedItem)
|
|
2775 |
|
|
2776 |
if lineValidation:
|
|
2777 |
startPoint = [min(x), min(y)]
|
|
2778 |
endPoint = [max(x), max(y)]
|
|
2779 |
lineItem = QEngineeringLineItem(vertices=[startPoint, endPoint])
|
|
2780 |
lineItem.transfer.onRemoved.connect(self.itemRemoved)
|
|
2781 |
lineItem.lineType = lineItems[0].lineType
|
|
2782 |
|
|
2783 |
for line in lineItems:
|
|
2784 |
line.transfer.onRemoved.emit(line)
|
|
2785 |
|
|
2786 |
detector = LineDetector(None)
|
|
2787 |
|
|
2788 |
for pt in [startPoint, endPoint]:
|
|
2789 |
selected = [item for item in self.graphicsView.scene().items(QPointF(pt[0], pt[1])) if
|
|
2790 |
type(item) is QEngineeringConnectorItem or type(item) is QEngineeringLineItem]
|
|
2791 |
if selected:
|
|
2792 |
if type(selected[0]) is QEngineeringConnectorItem and selected[0].parent in connectedItems:
|
|
2793 |
lineItem.connect_if_possible(selected[0].parent, 5)
|
|
2794 |
else:
|
|
2795 |
detector.connectLineToLine(selected[0], lineItem, 5)
|
|
2796 |
|
|
2797 |
self.graphicsView.scene().addItem(lineItem)
|
|
2798 |
# up to here
|
2747 |
2799 |
|
|
2800 |
# text merge
|
2748 |
2801 |
textItems = [text for text in self.graphicsView.scene().selectedItems() if
|
2749 |
2802 |
issubclass(type(text), QEngineeringTextItem)]
|
2750 |
|
if not textItems or len(textItems) is 1:
|
2751 |
|
return
|
2752 |
|
|
2753 |
|
angle = None
|
2754 |
|
for item in textItems:
|
2755 |
|
if angle is None:
|
2756 |
|
angle = item.angle
|
2757 |
|
else:
|
2758 |
|
if angle != item.angle:
|
2759 |
|
return
|
2760 |
|
|
2761 |
|
modifiers = QApplication.keyboardModifiers()
|
2762 |
|
enter_or_space = ' ' if modifiers == Qt.ControlModifier else '\n'
|
2763 |
|
x_or_y = 0 if (modifiers == Qt.ControlModifier and angle == 0) or (modifiers != Qt.ControlModifier and angle == 1.57) else 1
|
2764 |
|
|
2765 |
|
textItems = sorted(textItems, key=lambda text: text.loc[x_or_y]) if textItems[0].angle == 0 else ( \
|
2766 |
|
sorted(textItems, key=lambda text: text.loc[x_or_y]) if textItems[0].angle == 1.57 else ( \
|
2767 |
|
sorted(textItems, key=lambda text: text.loc[x_or_y], reverse=True) if textItems[0].angle == 4.71 else \
|
2768 |
|
sorted(textItems, key=lambda text: text.loc[x_or_y], reverse=True)))
|
2769 |
|
|
2770 |
|
if textItems[0].angle == 1.57 and modifiers == Qt.ControlModifier:
|
2771 |
|
textItems.reverse()
|
2772 |
|
|
2773 |
|
minX = sys.maxsize
|
2774 |
|
minY = sys.maxsize
|
2775 |
|
maxX = 0
|
2776 |
|
maxY = 0
|
2777 |
|
newText = ''
|
2778 |
|
|
2779 |
|
for text in textItems:
|
2780 |
|
if text.loc[0] < minX: minX = text.loc[0]
|
2781 |
|
if text.loc[1] < minY: minY = text.loc[1]
|
2782 |
|
if text.loc[0] + text.size[0] > maxX: maxX = text.loc[0] + text.size[0]
|
2783 |
|
if text.loc[1] + text.size[1] > maxY: maxY = text.loc[1] + text.size[1]
|
2784 |
|
newText = newText + text.text() + enter_or_space
|
2785 |
|
text.transfer.onRemoved.emit(text)
|
2786 |
|
newText = newText[:-1]
|
2787 |
|
|
2788 |
|
textInfo = TextInfo(newText, minX, minY, maxX - minX, maxY - minY, textItems[0].angle)
|
2789 |
|
x = textInfo.getX()
|
2790 |
|
y = textInfo.getY()
|
2791 |
|
angle = textInfo.getAngle()
|
2792 |
|
text = textInfo.getText()
|
2793 |
|
width = textInfo.getW()
|
2794 |
|
height = textInfo.getH()
|
2795 |
|
item = TextItemFactory.instance().createTextItem(textInfo)
|
2796 |
|
if item is not None:
|
2797 |
|
item.loc = [x, y]
|
2798 |
|
item.size = (width, height)
|
2799 |
|
item.angle = angle
|
2800 |
|
item.area = textItems[0].area
|
2801 |
|
item.setDefaultTextColor(Qt.blue)
|
2802 |
|
item.addTextItemToScene(self.graphicsView.scene())
|
2803 |
|
item.transfer.onRemoved.connect(self.itemRemoved)
|
|
2803 |
if len(textItems) > 1:
|
|
2804 |
angle = None
|
|
2805 |
for item in textItems:
|
|
2806 |
if angle is None:
|
|
2807 |
angle = item.angle
|
|
2808 |
else:
|
|
2809 |
if angle != item.angle:
|
|
2810 |
return
|
|
2811 |
|
|
2812 |
modifiers = QApplication.keyboardModifiers()
|
|
2813 |
enter_or_space = ' ' if modifiers == Qt.ControlModifier else '\n'
|
|
2814 |
x_or_y = 0 if (modifiers == Qt.ControlModifier and angle == 0) or (modifiers != Qt.ControlModifier and angle == 1.57) else 1
|
|
2815 |
|
|
2816 |
textItems = sorted(textItems, key=lambda text: text.loc[x_or_y]) if textItems[0].angle == 0 else ( \
|
|
2817 |
sorted(textItems, key=lambda text: text.loc[x_or_y]) if textItems[0].angle == 1.57 else ( \
|
|
2818 |
sorted(textItems, key=lambda text: text.loc[x_or_y], reverse=True) if textItems[0].angle == 4.71 else \
|
|
2819 |
sorted(textItems, key=lambda text: text.loc[x_or_y], reverse=True)))
|
|
2820 |
|
|
2821 |
if textItems[0].angle == 1.57 and modifiers == Qt.ControlModifier:
|
|
2822 |
textItems.reverse()
|
|
2823 |
|
|
2824 |
minX = sys.maxsize
|
|
2825 |
minY = sys.maxsize
|
|
2826 |
maxX = 0
|
|
2827 |
maxY = 0
|
|
2828 |
newText = ''
|
|
2829 |
|
|
2830 |
for text in textItems:
|
|
2831 |
if text.loc[0] < minX: minX = text.loc[0]
|
|
2832 |
if text.loc[1] < minY: minY = text.loc[1]
|
|
2833 |
if text.loc[0] + text.size[0] > maxX: maxX = text.loc[0] + text.size[0]
|
|
2834 |
if text.loc[1] + text.size[1] > maxY: maxY = text.loc[1] + text.size[1]
|
|
2835 |
newText = newText + text.text() + enter_or_space
|
|
2836 |
text.transfer.onRemoved.emit(text)
|
|
2837 |
newText = newText[:-1]
|
|
2838 |
|
|
2839 |
textInfo = TextInfo(newText, minX, minY, maxX - minX, maxY - minY, textItems[0].angle)
|
|
2840 |
x = textInfo.getX()
|
|
2841 |
y = textInfo.getY()
|
|
2842 |
angle = textInfo.getAngle()
|
|
2843 |
text = textInfo.getText()
|
|
2844 |
width = textInfo.getW()
|
|
2845 |
height = textInfo.getH()
|
|
2846 |
item = TextItemFactory.instance().createTextItem(textInfo)
|
|
2847 |
if item is not None:
|
|
2848 |
item.loc = [x, y]
|
|
2849 |
item.size = (width, height)
|
|
2850 |
item.angle = angle
|
|
2851 |
item.area = textItems[0].area
|
|
2852 |
item.setDefaultTextColor(Qt.blue)
|
|
2853 |
item.addTextItemToScene(self.graphicsView.scene())
|
|
2854 |
item.transfer.onRemoved.connect(self.itemRemoved)
|
|
2855 |
# up to here
|
2804 |
2856 |
elif event.key() == Qt.Key_D:
|
2805 |
2857 |
# pop up development toolkit dialog
|
2806 |
2858 |
from DevelopmentToolkitDialog import QDevelopmentToolkitDialog
|
... | ... | |
2853 |
2905 |
|
2854 |
2906 |
symbolItems = [symbol for symbol in self.graphicsView.scene().selectedItems() if
|
2855 |
2907 |
issubclass(type(symbol), SymbolSvgItem)]
|
2856 |
|
if symbolItems and len(symbolItems) is not 1:
|
|
2908 |
if len(symbolItems) is not 1:
|
2857 |
2909 |
return
|
2858 |
2910 |
|
2859 |
2911 |
target_symbol = symbolItems[0]
|