-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.py
181 lines (146 loc) · 5.84 KB
/
temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import math
import sys
import enum
from abc import ABC, abstractmethod
from kb_class import Module, Pxi2569, Kbk
from kb_nodes import KBK
from typing import List
from ui_elements.graph_items.modules import P2569
from ui_elements.graph_items.krossblocks import Kbk as Kbk_gi
from ui_elements.graph_items.module_or_kb_base import module_or_kb_base
from ui_elements.graph_items.link import LinkState, Link_scheme
from events import RemLink, SelectLink, AddLink, SelectSignal
from ui_elements.graph_items.node import Node, NodeState
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import QPoint, Qt, QSize, QRect
from PySide2.QtGui import QPainter, QFont, QColor, QPen
from PySide2.QtWidgets import (QApplication, QHBoxLayout,
QGraphicsScene, QWidget, QGraphicsView, QGraphicsItem, QGraphicsSceneMouseEvent)
from PySide2.QtSvg import *
from Link import Link, DLink
class Observer_for_widgets:
def event_from_widget(self, Event_from_widget):
pass
class Subject(ABC):
@abstractmethod
def attach(self, observer: Observer_for_widgets) -> None:
pass
@abstractmethod
def detach(self, observer: Observer_for_widgets) -> None:
pass
@abstractmethod
def notify(self) -> None:
pass
class Scheme(QWidget):
def __init__(self,parent):
super().__init__()
self.layt = QHBoxLayout()
self.view = GraphWidget(parent)
self.layt.addWidget(self.view)
self.setWindowTitle("Схема")
self.setLayout(self.layt)
# print(self.parent())
# print("ss")
def wheelEvent(self, event):
numDegrees = event.delta() / 8
numSteps = numDegrees / 15
if event.orientation() == Qt.Horizontal:
pass
else:
modifiers = QtGui.QGuiApplication.keyboardModifiers()
if modifiers == QtCore.Qt.ControlModifier:
if numSteps > 0:
self.view.scale(1.05, 1.05)
if numSteps < 0:
self.view.scale(0.95, 0.95)
event.accept()
def clc(self):
self.view.terminals[2].state = NodeState.highlight
print(self.view.terminals[2].num)
print(self.view.terminals[2].name)
self.view.highlight_links([Link("C 1", "M 100")])
self.view.refresh()
class GraphWidget(QGraphicsView, Observer_for_widgets):
def __init__(self,parent):
QGraphicsView.__init__(self)
self.timerId = 0
self.parent=parent
self.modules_gi: List[module_or_kb_base] = []
self.links: List[Link_scheme] = []
self.scene = QGraphicsScene(self)
self.scene.setItemIndexMethod(QGraphicsScene.NoIndex)
self.scene.setSceneRect(-785, -400, 1570, 800)
self.setScene(self.scene)
self.setCacheMode(QGraphicsView.CacheBackground)
self.setRenderHint(QPainter.Antialiasing)
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
self.setBackgroundBrush(QColor("lightgray"))
# self.parent.event_from_scheme()
def event_from_widget(self):
self.parent.event_from_scheme()
def add_module(self, module):
if isinstance(module, Kbk):
tmp = Kbk_gi(self)
tmp.setPos(0, 0)
self.modules_gi.append(tmp)
self.scene.addItem(tmp)
# print(tmp.parentObject())
if isinstance(module, Pxi2569):
tmp = P2569(self)
tmp.setPos(-130, 340)
self.modules_gi.append(tmp)
self.scene.addItem(tmp)
def refresh(self):
self.scene.update()
def clear_links(self):
for link in self.links:
self.scene.removeItem(link)
self.links.clear()
def add_links(self, list_of_links: List[Link]):
for module in self.modules_gi:
for nod in module.terminals:
nod.state = NodeState.normal
self.clear_links()
for link in list_of_links:
try:
self.print_link(link.node1, link.node2)
except:
pass
def highlight_links(self, list_of_links: List[Link]):
for module in self.modules_gi:
for nod in module.terminals:
nod.state = NodeState.normal
for printed_link in self.links:
printed_link.state = LinkState.normal
self.get_node_by_tag(printed_link.tag1).state = NodeState.used
self.get_node_by_tag(printed_link.tag2).state = NodeState.used
for link in list_of_links:
for printed_link in self.links:
if Link(link.node1, link.node2) == Link(printed_link.tag1, printed_link.tag2):
printed_link.state = LinkState.highlight
self.get_node_by_tag(link.node1).state = NodeState.highlight
self.get_node_by_tag(link.node2).state = NodeState.highlight
self.refresh()
def get_node_by_tag(self, tag):
for module in self.modules_gi:
for node in module.terminals:
if node.tag == tag:
return node
return None
def print_link(self, tag1, tag2):
# print(f"{tag1} {tag2}")
tag1_pos = self.get_node_by_tag(tag1).pos()
tag2_pos = self.get_node_by_tag(tag2).pos()
# print(f"{tag1_pos} {tag2_pos}")
self.links.append(Link_scheme(tag1_pos.x(), tag1_pos.y(), tag2_pos.x(), tag2_pos.y(), tag1, tag2))
self.scene.addItem(self.links[-1])
self.get_node_by_tag(tag1).state = NodeState.used
self.get_node_by_tag(tag2).state = NodeState.used
# self.scene.addLine(tag1_pos.x(),tag1_pos.y(),tag2_pos.x(),tag2_pos.y())
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = Scheme()
# widget.view.scale(0.8,0.8)
widget.show()
sys.exit(app.exec_())