Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dfss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mpcs
dfss
Commits
2812ea2d
Commit
2812ea2d
authored
Apr 08, 2016
by
Loïck Bonniot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[d] Add basic dynamic view of events
parent
00f0e26a
Pipeline
#495
passed with stage
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
23 deletions
+137
-23
dfssd/gui/clients.go
dfssd/gui/clients.go
+13
-1
dfssd/gui/events.go
dfssd/gui/events.go
+74
-0
dfssd/gui/structures.go
dfssd/gui/structures.go
+22
-3
dfssd/gui/widget.ui
dfssd/gui/widget.ui
+17
-1
dfssd/gui/window.go
dfssd/gui/window.go
+11
-18
No files found.
dfssd/gui/clients.go
View file @
2812ea2d
...
...
@@ -86,5 +86,17 @@ func (w *Window) DrawArrow(xa, ya, xb, yb float64, rgb uint32) {
brush
.
SetColor
(
color
)
brush
.
SetStyle
(
ui
.
Qt_SolidPattern
)
scene
.
AddPathWithPathPenBrush
(
path
,
pen
,
brush
)
arrow
:=
scene
.
AddPathWithPathPenBrush
(
path
,
pen
,
brush
)
w
.
currentArrows
=
append
(
w
.
currentArrows
,
arrow
)
}
func
(
w
*
Window
)
RemoveArrows
()
{
scene
:=
w
.
graphics
.
Scene
()
for
_
,
arrow
:=
range
w
.
currentArrows
{
scene
.
RemoveItem
(
&
arrow
.
QGraphicsItem
)
defer
arrow
.
Delete
()
}
w
.
currentArrows
=
nil
}
dfssd/gui/events.go
0 → 100644
View file @
2812ea2d
package
gui
import
(
"fmt"
"time"
"math"
)
// TEMPORARY
const
quantum
=
100
// discretization argument for events (ns)
const
speed
=
500
// duration of a quantum (ms)
func
(
w
*
Window
)
StartSimulation
()
{
w
.
ticker
=
time
.
NewTicker
(
speed
*
time
.
Millisecond
)
go
subroutine
(
w
)
}
func
(
w
*
Window
)
DrawEvent
(
e
*
Event
)
{
xa
,
ya
:=
w
.
GetClientPosition
(
e
.
Sender
)
xb
,
yb
:=
w
.
GetClientPosition
(
e
.
Receiver
)
w
.
DrawArrow
(
xa
,
ya
,
xb
,
yb
,
colors
[
"red"
])
}
func
(
w
*
Window
)
PrintQuantumInformation
()
{
beginning
:=
w
.
scene
.
Events
[
0
]
.
Date
.
UnixNano
()
totalDuration
:=
w
.
scene
.
Events
[
len
(
w
.
scene
.
Events
)
-
1
]
.
Date
.
UnixNano
()
-
beginning
nbQuantum
:=
math
.
Ceil
(
float64
(
totalDuration
)
/
quantum
)
durationFromBeginning
:=
w
.
scene
.
currentTime
.
UnixNano
()
-
beginning
currentQuantum
:=
math
.
Ceil
(
float64
(
durationFromBeginning
)
/
quantum
)
+
1
w
.
progress
.
SetText
(
fmt
.
Sprint
(
currentQuantum
,
" / "
,
nbQuantum
))
}
func
subroutine
(
w
*
Window
)
{
for
_
=
range
w
.
ticker
.
C
{
nbEvents
:=
len
(
w
.
scene
.
Events
)
if
w
.
scene
.
currentEvent
>=
nbEvents
{
// TODO disable looping if needed
w
.
RemoveArrows
()
w
.
scene
.
currentEvent
=
0
// loop
w
.
Log
(
"Restarting simulation..."
)
continue
}
// Remove arrows from last tick
w
.
RemoveArrows
()
// Check that we have a least one event to read
if
nbEvents
==
0
{
continue
}
// Init first time
if
w
.
scene
.
currentEvent
==
0
{
w
.
scene
.
currentTime
=
w
.
scene
.
Events
[
0
]
.
Date
}
endOfQuantum
:=
w
.
scene
.
currentTime
.
Add
(
quantum
*
time
.
Nanosecond
)
for
i
:=
w
.
scene
.
currentEvent
;
i
<
nbEvents
;
i
++
{
e
:=
w
.
scene
.
Events
[
i
]
if
e
.
Date
.
After
(
endOfQuantum
)
||
e
.
Date
.
Equal
(
endOfQuantum
)
{
break
}
w
.
DrawEvent
(
&
e
)
w
.
scene
.
currentEvent
++
}
w
.
PrintQuantumInformation
()
w
.
scene
.
currentTime
=
endOfQuantum
}
}
dfssd/gui/structures.go
View file @
2812ea2d
...
...
@@ -2,8 +2,27 @@ package gui
import
(
"time"
"github.com/visualfc/goqt/ui"
)
// Window contains all information used to make the demonstrator works.
// It extends QMainWindow and cache several graphic informations.
// Do not attempt to instantiante it directly, use `NewWindow` function instead.
type
Window
struct
{
*
ui
.
QMainWindow
logField
*
ui
.
QTextEdit
graphics
*
ui
.
QGraphicsView
progress
*
ui
.
QLabel
scene
*
Scene
circleSize
float64
pixmaps
map
[
string
]
*
ui
.
QPixmap
currentArrows
[]
*
ui
.
QGraphicsPathItem
ticker
*
time
.
Ticker
}
// Client represents a DFSSC instance
type
Client
struct
{
Name
string
...
...
@@ -23,8 +42,7 @@ type Event struct {
Type
EventType
Sender
int
Receiver
int
Date
*
time
.
Time
Duration
*
time
.
Duration
Date
time
.
Time
}
// Scene holds the global scene for registered clients and signature events
...
...
@@ -32,5 +50,6 @@ type Scene struct {
Clients
[]
Client
Events
[]
Event
currentEvent
int
currentTime
time
.
Time
currentEvent
int
}
dfssd/gui/widget.ui
View file @
2812ea2d
...
...
@@ -141,7 +141,7 @@
<item>
<widget
class=
"QSlider"
name=
"speedSlider"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"
Preferred
"
vsizetype=
"Fixed"
>
<sizepolicy
hsizetype=
"
Expanding
"
vsizetype=
"Fixed"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
...
...
@@ -157,6 +157,22 @@
</property>
</widget>
</item>
<item>
<widget
class=
"QLabel"
name=
"progressLabel"
>
<property
name=
"minimumSize"
>
<size>
<width>
80
</width>
<height>
0
</height>
</size>
</property>
<property
name=
"text"
>
<string/>
</property>
<property
name=
"alignment"
>
<set>
Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
...
...
dfssd/gui/window.go
View file @
2812ea2d
...
...
@@ -2,21 +2,12 @@ package gui
import
(
"math"
"time"
"dfss"
"github.com/visualfc/goqt/ui"
)
type
Window
struct
{
*
ui
.
QMainWindow
logField
*
ui
.
QTextEdit
graphics
*
ui
.
QGraphicsView
scene
*
Scene
circleSize
float64
pixmaps
map
[
string
]
*
ui
.
QPixmap
}
func
NewWindow
()
*
Window
{
file
:=
ui
.
NewFileWithName
(
":/widget.ui"
)
loader
:=
ui
.
NewUiLoader
()
...
...
@@ -36,6 +27,7 @@ func NewWindow() *Window {
// Load dynamic elements from driver
w
.
logField
=
ui
.
NewTextEditFromDriver
(
widget
.
FindChild
(
"logField"
))
w
.
graphics
=
ui
.
NewGraphicsViewFromDriver
(
widget
.
FindChild
(
"graphicsView"
))
w
.
progress
=
ui
.
NewLabelFromDriver
(
widget
.
FindChild
(
"progressLabel"
))
// Load pixmaps
w
.
pixmaps
=
map
[
string
]
*
ui
.
QPixmap
{
...
...
@@ -56,8 +48,15 @@ func NewWindow() *Window {
Client
{
"signer2@insa-rennes.fr"
},
Client
{
"signer3@dfss.com"
},
}
w
.
scene
.
Events
=
[]
Event
{
Event
{
PROMISE
,
0
,
1
,
time
.
Unix
(
0
,
5
)},
Event
{
SIGNATURE
,
1
,
2
,
time
.
Unix
(
0
,
15
)},
Event
{
PROMISE
,
1
,
0
,
time
.
Unix
(
0
,
134
)},
Event
{
OTHER
,
0
,
1
,
time
.
Unix
(
0
,
402
)},
}
w
.
StatusBar
()
.
ShowMessage
(
"Ready"
)
w
.
StartSimulation
()
return
w
}
...
...
@@ -97,7 +96,6 @@ func (w *Window) OnResizeEvent(ev *ui.QResizeEvent) bool {
}
func
(
w
*
Window
)
initScene
()
{
// Save old scene
oldScene
:=
w
.
graphics
.
Scene
()
...
...
@@ -113,14 +111,9 @@ func (w *Window) initScene() {
w
.
DrawClients
()
w
.
DrawServers
()
// TEST
xa
,
ya
:=
w
.
GetClientPosition
(
0
)
xb
,
yb
:=
w
.
GetClientPosition
(
1
)
w
.
DrawArrow
(
xa
,
ya
,
xb
,
yb
,
colors
[
"red"
])
w
.
DrawArrow
(
xb
,
yb
,
xa
,
ya
,
colors
[
"red"
])
// Purge
if
oldScene
!=
nil
{
oldScene
.
Delete
()
w
.
RemoveArrows
()
defer
oldScene
.
Delete
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment