Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
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
B-ASIC - Better ASIC Toolbox
Commits
c6fb1fbf
Commit
c6fb1fbf
authored
2 years ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Improve orthogonal drawing
parent
5843a3f3
No related branches found
No related tags found
No related merge requests found
Pipeline
#88091
passed
2 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
b_asic/GUI/arrow.py
+87
-11
87 additions, 11 deletions
b_asic/GUI/arrow.py
with
87 additions
and
11 deletions
b_asic/GUI/arrow.py
+
87
−
11
View file @
c6fb1fbf
...
@@ -2,7 +2,7 @@ from qtpy.QtCore import QPointF
...
@@ -2,7 +2,7 @@ from qtpy.QtCore import QPointF
from
qtpy.QtGui
import
QPen
,
QPainterPath
from
qtpy.QtGui
import
QPen
,
QPainterPath
from
qtpy.QtWidgets
import
QGraphicsPathItem
,
QMenu
from
qtpy.QtWidgets
import
QGraphicsPathItem
,
QMenu
from
b_asic.GUI._preferences
import
LINECOLOR
,
PORTHEIGHT
,
PORTWIDTH
from
b_asic.GUI._preferences
import
GRID
,
LINECOLOR
,
PORTHEIGHT
,
PORTWIDTH
from
b_asic.signal
import
Signal
from
b_asic.signal
import
Signal
...
@@ -83,9 +83,11 @@ class Arrow(QGraphicsPathItem):
...
@@ -83,9 +83,11 @@ class Arrow(QGraphicsPathItem):
ORTHOGONAL
=
True
ORTHOGONAL
=
True
OFFSET
=
2
*
PORTWIDTH
OFFSET
=
2
*
PORTWIDTH
self
.
setPen
(
QPen
(
LINECOLOR
,
3
))
self
.
setPen
(
QPen
(
LINECOLOR
,
3
))
x0
=
self
.
source
.
operation
.
x
()
+
self
.
source
.
x
()
+
PORTWIDTH
source_flipped
=
self
.
source
.
operation
.
is_flipped
()
destination_flipped
=
self
.
destination
.
operation
.
is_flipped
()
x0
=
self
.
source
.
operation
.
x
()
+
self
.
source
.
x
()
+
(
PORTWIDTH
if
not
source_flipped
else
0
)
y0
=
self
.
source
.
operation
.
y
()
+
self
.
source
.
y
()
+
PORTHEIGHT
/
2
y0
=
self
.
source
.
operation
.
y
()
+
self
.
source
.
y
()
+
PORTHEIGHT
/
2
x1
=
self
.
destination
.
operation
.
x
()
+
self
.
destination
.
x
()
x1
=
self
.
destination
.
operation
.
x
()
+
self
.
destination
.
x
()
+
(
0
if
not
destination_flipped
else
PORTWIDTH
)
y1
=
(
y1
=
(
self
.
destination
.
operation
.
y
()
self
.
destination
.
operation
.
y
()
+
self
.
destination
.
y
()
+
self
.
destination
.
y
()
...
@@ -93,16 +95,90 @@ class Arrow(QGraphicsPathItem):
...
@@ -93,16 +95,90 @@ class Arrow(QGraphicsPathItem):
)
)
xmid
=
(
x0
+
x1
)
/
2
xmid
=
(
x0
+
x1
)
/
2
ymid
=
(
y0
+
y1
)
/
2
ymid
=
(
y0
+
y1
)
/
2
both_flipped
=
source_flipped
and
destination_flipped
any_flipped
=
source_flipped
or
destination_flipped
p
=
QPainterPath
(
QPointF
(
x0
,
y0
))
p
=
QPainterPath
(
QPointF
(
x0
,
y0
))
if
y0
==
y1
or
not
ORTHOGONAL
:
# TODO: Simplify or create a better router
if
not
ORTHOGONAL
:
pass
pass
elif
abs
(
x0
-
x1
)
<=
OFFSET
/
2
:
elif
y0
==
y1
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
))
if
not
any_flipped
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
ymid
))
if
x0
<=
x1
:
p
.
lineTo
(
QPointF
(
x0
-
OFFSET
,
ymid
))
pass
p
.
lineTo
(
QPointF
(
x0
-
OFFSET
,
y1
))
else
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
-
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
-
OFFSET
,
y0
))
elif
both_flipped
:
if
x1
<=
x0
:
pass
else
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
-
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
-
OFFSET
,
y0
))
elif
source_flipped
:
if
x0
<=
x1
:
p
.
lineTo
(
QPointF
(
x0
-
OFFSET
,
y0
))
p
.
lineTo
(
QPointF
(
x0
-
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
else
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
else
:
if
x1
<=
x0
:
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
else
:
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
p
.
lineTo
(
QPointF
(
xmid
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
+
OFFSET
,
y0
+
OFFSET
))
p
.
lineTo
(
QPointF
(
x1
+
OFFSET
,
y0
))
elif
abs
(
x0
-
x1
)
<=
GRID
:
if
both_flipped
or
not
any_flipped
:
offset
=
-
OFFSET
if
both_flipped
else
OFFSET
p
.
lineTo
(
QPointF
(
x0
+
offset
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
offset
,
ymid
))
p
.
lineTo
(
QPointF
(
x0
-
offset
,
ymid
))
p
.
lineTo
(
QPointF
(
x0
-
offset
,
y1
))
else
:
offset
=
-
OFFSET
if
source_flipped
else
-
OFFSET
p
.
lineTo
(
QPointF
(
x0
+
offset
,
y0
))
p
.
lineTo
(
QPointF
(
x0
+
offset
,
y1
))
else
:
else
:
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
if
not
any_flipped
:
p
.
lineTo
(
QPointF
(
xmid
,
y1
))
if
x0
<=
x1
:
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
p
.
lineTo
(
QPointF
(
xmid
,
y1
))
else
:
p
.
lineTo
(
x0
+
OFFSET
,
y0
)
p
.
lineTo
(
x0
+
OFFSET
,
ymid
)
p
.
lineTo
(
x1
-
OFFSET
,
ymid
)
p
.
lineTo
(
x1
-
OFFSET
,
y1
)
elif
both_flipped
:
if
x0
>=
x1
:
p
.
lineTo
(
QPointF
(
xmid
,
y0
))
p
.
lineTo
(
QPointF
(
xmid
,
y1
))
else
:
p
.
lineTo
(
x0
-
OFFSET
,
y0
)
p
.
lineTo
(
x0
-
OFFSET
,
ymid
)
p
.
lineTo
(
x1
+
OFFSET
,
ymid
)
p
.
lineTo
(
x1
+
OFFSET
,
y1
)
elif
source_flipped
:
xmin
=
min
(
x0
,
x1
)
-
OFFSET
p
.
lineTo
(
QPointF
(
xmin
,
y0
))
p
.
lineTo
(
QPointF
(
xmin
,
y1
))
else
:
xmax
=
max
(
x0
,
x1
)
+
OFFSET
p
.
lineTo
(
QPointF
(
xmax
,
y0
))
p
.
lineTo
(
QPointF
(
xmax
,
y1
))
p
.
lineTo
(
QPointF
(
x1
,
y1
))
p
.
lineTo
(
QPointF
(
x1
,
y1
))
self
.
setPath
(
p
)
self
.
setPath
(
p
)
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