Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
1f645003
Commit
1f645003
authored
Apr 08, 2016
by
Loïck Bonniot
Browse files
[d] Improve timer management and add controls
parent
2812ea2d
Pipeline
#502
passed with stage
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dfssd/gui/application.qrc
View file @
1f645003
...
...
@@ -4,5 +4,10 @@
<file>images/server_key.png</file>
<file>images/server_connect.png</file>
<file>images/node_magnifier.png</file>
<file>images/control_play.png</file>
<file>images/control_play_blue.png</file>
<file>images/control_pause.png</file>
<file>images/control_pause_blue.png</file>
<file>images/control_rewind_blue.png</file>
</qresource>
</RCC>
dfssd/gui/events.go
View file @
1f645003
...
...
@@ -4,17 +4,14 @@ import (
"fmt"
"time"
"math"
"github.com/visualfc/goqt/ui"
)
// 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
)
...
...
@@ -22,24 +19,30 @@ func (w *Window) DrawEvent(e *Event) {
}
func
(
w
*
Window
)
PrintQuantumInformation
()
{
if
len
(
w
.
scene
.
Events
)
==
0
{
w
.
progress
.
SetText
(
"No event"
)
return
}
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
if
w
.
scene
.
currentEvent
==
0
{
currentQuantum
=
0
}
w
.
progress
.
SetText
(
fmt
.
Sprint
(
currentQuantum
,
" / "
,
nbQuantum
))
}
func
subroutine
(
w
*
Window
)
{
for
_
=
range
w
.
ticker
.
C
{
func
(
w
*
Window
)
initTimer
()
{
w
.
timer
=
ui
.
NewTimerWithParent
(
w
)
w
.
timer
.
OnTimeout
(
func
()
{
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
w
.
replayButton
.
Click
()
return
}
// Remove arrows from last tick
...
...
@@ -47,7 +50,7 @@ func subroutine(w *Window) {
// Check that we have a least one event to read
if
nbEvents
==
0
{
continue
return
}
// Init first time
...
...
@@ -70,5 +73,5 @@ func subroutine(w *Window) {
w
.
PrintQuantumInformation
()
w
.
scene
.
currentTime
=
endOfQuantum
}
}
)
}
dfssd/gui/
client
s.go
→
dfssd/gui/
graphic
s.go
View file @
1f645003
File moved
dfssd/gui/images/control_pause.png
0 → 100644
View file @
1f645003
1.81 KB
dfssd/gui/images/control_pause_blue.png
0 → 100644
View file @
1f645003
1.92 KB
dfssd/gui/images/control_play.png
0 → 100644
View file @
1f645003
1.76 KB
dfssd/gui/images/control_play_blue.png
0 → 100644
View file @
1f645003
1.92 KB
dfssd/gui/images/control_rewind_blue.png
0 → 100644
View file @
1f645003
2 KB
dfssd/gui/structures.go
View file @
1f645003
...
...
@@ -15,12 +15,15 @@ type Window struct {
logField
*
ui
.
QTextEdit
graphics
*
ui
.
QGraphicsView
progress
*
ui
.
QLabel
playButton
*
ui
.
QPushButton
stopButton
*
ui
.
QPushButton
replayButton
*
ui
.
QPushButton
scene
*
Scene
circleSize
float64
pixmaps
map
[
string
]
*
ui
.
QPixmap
currentArrows
[]
*
ui
.
QGraphicsPathItem
ti
ck
er
*
time
.
Tick
er
ti
m
er
*
ui
.
QTim
er
}
// Client represents a DFSSC instance
...
...
dfssd/gui/widget.ui
View file @
1f645003
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
CalculatorF
or
m
</class>
<widget
class=
"QWidget"
name=
"
CalculatorF
or
m
"
>
<class>
Demonstrat
or
</class>
<widget
class=
"QWidget"
name=
"
Demonstrat
or"
>
<property
name=
"enabled"
>
<bool>
true
</bool>
</property>
...
...
@@ -66,10 +66,32 @@
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Play
</string>
<property
name=
"maximumSize"
>
<size>
<width>
40
</width>
<height>
40
</height>
</size>
</property>
<property
name=
"default"
>
<property
name=
"focusPolicy"
>
<enum>
Qt::NoFocus
</enum>
</property>
<property
name=
"flat"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"stopButton"
>
<property
name=
"maximumSize"
>
<size>
<width>
40
</width>
<height>
40
</height>
</size>
</property>
<property
name=
"focusPolicy"
>
<enum>
Qt::NoFocus
</enum>
</property>
<property
name=
"flat"
>
<bool>
true
</bool>
</property>
</widget>
...
...
@@ -82,8 +104,17 @@
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"text"
>
<string>
Replay
</string>
<property
name=
"maximumSize"
>
<size>
<width>
40
</width>
<height>
40
</height>
</size>
</property>
<property
name=
"focusPolicy"
>
<enum>
Qt::NoFocus
</enum>
</property>
<property
name=
"flat"
>
<bool>
true
</bool>
</property>
</widget>
</item>
...
...
@@ -108,6 +139,9 @@
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"focusPolicy"
>
<enum>
Qt::TabFocus
</enum>
</property>
<property
name=
"suffix"
>
<string>
us
</string>
</property>
...
...
@@ -146,6 +180,9 @@
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<property
name=
"focusPolicy"
>
<enum>
Qt::TabFocus
</enum>
</property>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
...
...
dfssd/gui/window.go
View file @
1f645003
...
...
@@ -29,18 +29,23 @@ func NewWindow() *Window {
w
.
graphics
=
ui
.
NewGraphicsViewFromDriver
(
widget
.
FindChild
(
"graphicsView"
))
w
.
progress
=
ui
.
NewLabelFromDriver
(
widget
.
FindChild
(
"progressLabel"
))
w
.
playButton
=
ui
.
NewPushButtonFromDriver
(
widget
.
FindChild
(
"playButton"
))
w
.
stopButton
=
ui
.
NewPushButtonFromDriver
(
widget
.
FindChild
(
"stopButton"
))
w
.
replayButton
=
ui
.
NewPushButtonFromDriver
(
widget
.
FindChild
(
"replayButton"
))
// Load pixmaps
w
.
pixmaps
=
map
[
string
]
*
ui
.
QPixmap
{
"ttp"
:
ui
.
NewPixmapWithFilenameFormatFlags
(
":/images/server_key.png"
,
""
,
ui
.
Qt_AutoColor
),
"platform"
:
ui
.
NewPixmapWithFilenameFormatFlags
(
":/images/server_connect.png"
,
""
,
ui
.
Qt_AutoColor
),
}
// Load icon
w
.
SetWindowIcon
(
ui
.
NewIconWithFilename
(
":/images/node_magnifier.png"
)
)
// Load icon
s
w
.
addIcons
(
)
// Add actions
w
.
addActions
()
w
.
initScene
()
w
.
initTimer
()
// TEST ONLY
w
.
scene
.
Clients
=
[]
Client
{
...
...
@@ -56,16 +61,38 @@ func NewWindow() *Window {
}
w
.
StatusBar
()
.
ShowMessage
(
"Ready"
)
w
.
StartSimul
ation
()
w
.
PrintQuantumInform
ation
()
return
w
}
func
(
w
*
Window
)
OnResizeEvent
(
ev
*
ui
.
QResizeEvent
)
bool
{
w
.
initScene
()
return
true
}
func
(
w
*
Window
)
Log
(
str
string
)
{
w
.
logField
.
Append
(
str
)
w
.
logField
.
EnsureCursorVisible
()
}
func
(
w
*
Window
)
addIcons
()
{
w
.
SetWindowIcon
(
ui
.
NewIconWithFilename
(
":/images/node_magnifier.png"
))
var
i
*
ui
.
QIcon
i
=
ui
.
NewIconWithFilename
(
":/images/control_play_blue.png"
)
i
.
AddFileWithFilenameSizeModeState
(
":/images/control_play.png"
,
ui
.
NewSizeWithWidthHeight
(
32
,
32
),
ui
.
QIcon_Disabled
,
ui
.
QIcon_Off
)
w
.
playButton
.
SetIcon
(
i
)
i
=
ui
.
NewIconWithFilename
(
":/images/control_pause_blue.png"
)
i
.
AddFileWithFilenameSizeModeState
(
":/images/control_pause.png"
,
ui
.
NewSizeWithWidthHeight
(
32
,
32
),
ui
.
QIcon_Disabled
,
ui
.
QIcon_Off
)
w
.
stopButton
.
SetIcon
(
i
)
i
=
ui
.
NewIconWithFilename
(
":/images/control_rewind_blue.png"
)
w
.
replayButton
.
SetIcon
(
i
)
}
func
(
w
*
Window
)
addActions
()
{
// MENU BAR
openAct
:=
ui
.
NewActionWithTextParent
(
"&Open"
,
w
)
openAct
.
SetShortcuts
(
ui
.
QKeySequence_Open
)
openAct
.
SetStatusTip
(
"Open a demonstration file"
)
...
...
@@ -88,11 +115,29 @@ func (w *Window) addActions() {
w
.
MenuBar
()
.
AddAction
(
openAct
)
w
.
MenuBar
()
.
AddAction
(
saveAct
)
}
func
(
w
*
Window
)
OnResizeEvent
(
ev
*
ui
.
QResizeEvent
)
bool
{
w
.
initScene
()
return
true
// SIMULATION CONTROL
w
.
playButton
.
OnClicked
(
func
()
{
w
.
playButton
.
SetDisabled
(
true
)
w
.
stopButton
.
SetDisabled
(
false
)
w
.
timer
.
StartWithMsec
(
500
)
w
.
Log
(
"Started simulation"
)
})
w
.
stopButton
.
OnClicked
(
func
()
{
w
.
playButton
.
SetDisabled
(
false
)
w
.
stopButton
.
SetDisabled
(
true
)
w
.
timer
.
Stop
()
w
.
Log
(
"Paused simulation"
)
})
w
.
stopButton
.
SetDisabled
(
true
)
w
.
replayButton
.
OnClicked
(
func
()
{
w
.
RemoveArrows
()
w
.
scene
.
currentEvent
=
0
w
.
PrintQuantumInformation
()
w
.
Log
(
"Restarting simulation"
)
})
}
func
(
w
*
Window
)
initScene
()
{
...
...
Write
Preview
Supports
Markdown
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