Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simuDAtor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
simuDAtor
Commits
01055c2b
Commit
01055c2b
authored
9 months ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
moved the painting to the actual paint method, the lines still refuse to work correctly
parent
4e12e91a
No related branches found
No related tags found
No related merge requests found
Pipeline
#134594
failed
9 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/simudator/gui/signal_graphics_item.py
+36
-48
36 additions, 48 deletions
src/simudator/gui/signal_graphics_item.py
with
36 additions
and
48 deletions
src/simudator/gui/signal_graphics_item.py
+
36
−
48
View file @
01055c2b
...
@@ -67,9 +67,7 @@ class SignalGraphicsItem(QGraphicsWidget):
...
@@ -67,9 +67,7 @@ class SignalGraphicsItem(QGraphicsWidget):
local_start
=
self
.
mapFromScene
(
start_point
)
local_start
=
self
.
mapFromScene
(
start_point
)
local_end
=
self
.
mapFromScene
(
end_point
)
local_end
=
self
.
mapFromScene
(
end_point
)
self
.
_init_line_points
(
start_point
,
end_point
)
self
.
_init_line_points
(
local_start
,
local_end
)
self
.
drawSignal
()
# Used to lock layout
# Used to lock layout
self
.
is_locked
=
False
self
.
is_locked
=
False
...
@@ -120,41 +118,6 @@ class SignalGraphicsItem(QGraphicsWidget):
...
@@ -120,41 +118,6 @@ class SignalGraphicsItem(QGraphicsWidget):
self
.
setVisible
(
True
)
self
.
setVisible
(
True
)
self
.
drawSignal
()
self
.
drawSignal
()
def
drawSignal
(
self
)
->
None
:
"""
Draws the signal as a collection of orthogonal line segments which
can be moved and split into smaller segments. Each segment is joined
to another segment at its end points, except for the two end segments
which are connected to module ports.
"""
# Remove old lines from the GUI
while
self
.
lines
:
item
=
self
.
lines
.
pop
()
item
.
setParentItem
(
None
)
# Remove old lines form the GUI
while
self
.
_line_segments
:
item
=
self
.
_line_segments
.
pop
()
item
.
setParentItem
(
None
)
# Draw lines from the first to the second point, from the second
# to the third point and so on
prev_point
=
self
.
points
[
0
]
for
point
in
self
.
points
[
1
:]:
# Coordinates
# Bounded box for clicking
x1
=
prev_point
.
x
()
y1
=
prev_point
.
y
()
x2
=
point
.
x
()
y2
=
point
.
y
()
# line = QGraphicsLineItem(x1, y1, x2, y2, self)
# line.setPen(ColorScheme.Signal)
segment
=
LineSegment
(
prev_point
,
point
,
self
)
self
.
_line_segments
.
append
(
segment
)
# self.lines.append(line)
prev_point
=
point
def
splitLine
(
self
,
start_point_index
:
int
,
end_point_index
:
int
)
->
None
:
def
splitLine
(
self
,
start_point_index
:
int
,
end_point_index
:
int
)
->
None
:
"""
"""
Splits an existing line of two segments into a new line of four line
Splits an existing line of two segments into a new line of four line
...
@@ -350,6 +313,32 @@ class SignalGraphicsItem(QGraphicsWidget):
...
@@ -350,6 +313,32 @@ class SignalGraphicsItem(QGraphicsWidget):
def
paint
(
self
,
*
args
):
def
paint
(
self
,
*
args
):
# This avoids errors, it is a pure virtual function that
# This avoids errors, it is a pure virtual function that
# needs an implementation
# needs an implementation
# Remove old lines from the GUI
while
self
.
lines
:
item
=
self
.
lines
.
pop
()
item
.
setParentItem
(
None
)
# Remove old lines form the GUI
while
self
.
_line_segments
:
item
=
self
.
_line_segments
.
pop
()
item
.
setParentItem
(
None
)
# Draw lines from the first to the second point, from the second
# to the third point and so on
prev_point
=
self
.
points
[
0
]
for
point
in
self
.
points
[
1
:]:
# Coordinates
# Bounded box for clicking
x1
=
prev_point
.
x
()
y1
=
prev_point
.
y
()
x2
=
point
.
x
()
y2
=
point
.
y
()
# line = QGraphicsLineItem(x1, y1, x2, y2, self)
# line.setPen(ColorScheme.Signal)
segment
=
LineSegment
(
prev_point
,
point
,
self
)
self
.
_line_segments
.
append
(
segment
)
# self.lines.append(line)
prev_point
=
point
pass
pass
def
distance_sq
(
self
,
point1
,
point2
):
def
distance_sq
(
self
,
point1
,
point2
):
...
@@ -444,8 +433,6 @@ class SignalGraphicsItem(QGraphicsWidget):
...
@@ -444,8 +433,6 @@ class SignalGraphicsItem(QGraphicsWidget):
end_point
.
setX
(
new_end_point
.
x
())
end_point
.
setX
(
new_end_point
.
x
())
neighbour_point
.
setX
(
new_end_point
.
x
())
neighbour_point
.
setX
(
new_end_point
.
x
())
self
.
drawSignal
()
def
toggleVisibility
(
self
)
->
None
:
def
toggleVisibility
(
self
)
->
None
:
"""
"""
Toggles the visibility of the signal.
Toggles the visibility of the signal.
...
@@ -464,9 +451,6 @@ class SignalGraphicsItem(QGraphicsWidget):
...
@@ -464,9 +451,6 @@ class SignalGraphicsItem(QGraphicsWidget):
def
setPoints
(
self
,
points
:
list
[
QPointF
])
->
None
:
def
setPoints
(
self
,
points
:
list
[
QPointF
])
->
None
:
self
.
points
=
points
self
.
points
=
points
# Redraw the signal
self
.
drawSignal
()
class
LineSegment
(
QGraphicsWidget
):
class
LineSegment
(
QGraphicsWidget
):
""""""
""""""
...
@@ -478,15 +462,14 @@ class LineSegment(QGraphicsWidget):
...
@@ -478,15 +462,14 @@ class LineSegment(QGraphicsWidget):
self
.
_parent
=
parent
self
.
_parent
=
parent
self
.
_start_pos
=
start_pos
self
.
_margin
=
5
self
.
_end_pos
=
end_pos
self
.
_calc_area
(
start_pos
,
end_pos
)
self
.
_calc_area
(
start_pos
,
end_pos
)
def
_calc_area
(
self
,
start_pos
:
QPointF
,
end_pos
:
QPointF
):
def
_calc_area
(
self
,
start_pos
:
QPointF
,
end_pos
:
QPointF
):
#
start_pos = self.mapFrom
Scene(
start_pos)
start_pos
=
self
.
mapFrom
Item
(
self
.
_parent
,
start_pos
)
#
end_pos = self.mapFrom
Scene(
end_pos)
end_pos
=
self
.
mapFrom
Item
(
self
.
_parent
,
end_pos
)
self
.
_start_pos
=
start_pos
self
.
_start_pos
=
start_pos
self
.
_end_pos
=
end_pos
self
.
_end_pos
=
end_pos
...
@@ -497,7 +480,12 @@ class LineSegment(QGraphicsWidget):
...
@@ -497,7 +480,12 @@ class LineSegment(QGraphicsWidget):
)
)
width
=
max
(
self
.
_start_pos
.
x
(),
self
.
_end_pos
.
x
())
-
top_left
.
x
()
width
=
max
(
self
.
_start_pos
.
x
(),
self
.
_end_pos
.
x
())
-
top_left
.
x
()
height
=
max
(
self
.
_start_pos
.
y
(),
self
.
_end_pos
.
y
())
-
top_left
.
y
()
height
=
max
(
self
.
_start_pos
.
y
(),
self
.
_end_pos
.
y
())
-
top_left
.
y
()
self
.
setGeometry
(
top_left
.
x
()
-
5
,
top_left
.
y
()
-
5
,
width
+
10
,
height
+
10
)
self
.
setGeometry
(
top_left
.
x
()
-
self
.
_margin
,
top_left
.
y
()
-
self
.
_margin
,
width
+
2
*
self
.
_margin
,
height
+
2
*
self
.
_margin
,
)
def
update_position
(
self
,
start_pos
:
QPointF
,
end_pos
:
QPointF
):
def
update_position
(
self
,
start_pos
:
QPointF
,
end_pos
:
QPointF
):
self
.
_calc_area
(
start_pos
,
end_pos
)
self
.
_calc_area
(
start_pos
,
end_pos
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment