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
11dcecc3
Commit
11dcecc3
authored
Apr 08, 2016
by
Loïck Bonniot
Browse files
[d] Add some documentation
parent
f2c44b6c
Pipeline
#504
passed with stage
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dfssd/gui/colors.go
View file @
11dcecc3
package
gui
package
gui
// This file stores useful colors
import
"github.com/visualfc/goqt/ui"
import
"github.com/visualfc/goqt/ui"
var
colors
=
map
[
string
]
uint32
{
var
colors
=
map
[
string
]
uint32
{
...
...
dfssd/gui/events.go
View file @
11dcecc3
package
gui
package
gui
// This file handles event timers and imports.
import
(
import
(
"fmt"
"fmt"
"math"
"math"
...
@@ -45,6 +47,7 @@ func (w *Window) AddEvent(e *api.Log) {
...
@@ -45,6 +47,7 @@ func (w *Window) AddEvent(e *api.Log) {
}
}
}
}
// DrawEvent triggers the appropriate draw action for a spectific event.
func
(
w
*
Window
)
DrawEvent
(
e
*
Event
)
{
func
(
w
*
Window
)
DrawEvent
(
e
*
Event
)
{
xa
,
ya
:=
w
.
GetClientPosition
(
e
.
Sender
)
xa
,
ya
:=
w
.
GetClientPosition
(
e
.
Sender
)
xb
,
yb
:=
w
.
GetClientPosition
(
e
.
Receiver
)
xb
,
yb
:=
w
.
GetClientPosition
(
e
.
Receiver
)
...
@@ -62,6 +65,7 @@ func (w *Window) DrawEvent(e *Event) {
...
@@ -62,6 +65,7 @@ func (w *Window) DrawEvent(e *Event) {
w
.
DrawArrow
(
xa
,
ya
,
xb
,
yb
,
colors
[
color
])
w
.
DrawArrow
(
xa
,
ya
,
xb
,
yb
,
colors
[
color
])
}
}
// PrintQuantumInformation triggers the update of the "x / y" quantum information.
func
(
w
*
Window
)
PrintQuantumInformation
()
{
func
(
w
*
Window
)
PrintQuantumInformation
()
{
if
len
(
w
.
scene
.
Events
)
==
0
{
if
len
(
w
.
scene
.
Events
)
==
0
{
w
.
progress
.
SetText
(
"No event"
)
w
.
progress
.
SetText
(
"No event"
)
...
@@ -80,6 +84,7 @@ func (w *Window) PrintQuantumInformation() {
...
@@ -80,6 +84,7 @@ func (w *Window) PrintQuantumInformation() {
w
.
progress
.
SetText
(
fmt
.
Sprint
(
currentQuantum
,
" / "
,
nbQuantum
))
w
.
progress
.
SetText
(
fmt
.
Sprint
(
currentQuantum
,
" / "
,
nbQuantum
))
}
}
// initTimer is called during window initialization. It initializes the timeout signal called for each refresh.
func
(
w
*
Window
)
initTimer
()
{
func
(
w
*
Window
)
initTimer
()
{
w
.
timer
=
ui
.
NewTimerWithParent
(
w
)
w
.
timer
=
ui
.
NewTimerWithParent
(
w
)
...
@@ -128,6 +133,7 @@ func (w *Window) initTimer() {
...
@@ -128,6 +133,7 @@ func (w *Window) initTimer() {
})
})
}
}
// identifierToIndex is used to retrieve a client index from its name, inserting a new client if needed.
func
(
s
*
Scene
)
identifierToIndex
(
identifier
string
)
int
{
func
(
s
*
Scene
)
identifierToIndex
(
identifier
string
)
int
{
if
identifier
==
"platform"
{
if
identifier
==
"platform"
{
return
-
1
return
-
1
...
...
dfssd/gui/graphics.go
View file @
11dcecc3
package
gui
package
gui
// This file handles complex graphic primitives for the demonstrator.
import
(
import
(
"math"
"math"
"github.com/visualfc/goqt/ui"
"github.com/visualfc/goqt/ui"
)
)
const
ARROW_T
=
math
.
Pi
/
6
// These two constants are used to configure arrows
const
ARROW_L
=
15
const
ARROW_T
=
math
.
Pi
/
6
// angle
const
ARROW_L
=
15
// side length
// DrawClients draws the different clients in a circle.
func
(
w
*
Window
)
DrawClients
()
{
func
(
w
*
Window
)
DrawClients
()
{
scene
:=
w
.
graphics
.
Scene
()
scene
:=
w
.
graphics
.
Scene
()
for
i
,
c
:=
range
w
.
scene
.
Clients
{
for
i
,
c
:=
range
w
.
scene
.
Clients
{
...
@@ -25,6 +29,7 @@ func (w *Window) DrawClients() {
...
@@ -25,6 +29,7 @@ func (w *Window) DrawClients() {
}
}
}
}
// GetClientPosition translates a client index into its cartesian coordinates.
func
(
w
*
Window
)
GetClientPosition
(
i
int
)
(
x
,
y
float64
)
{
func
(
w
*
Window
)
GetClientPosition
(
i
int
)
(
x
,
y
float64
)
{
if
i
<
0
{
if
i
<
0
{
return
w
.
GetServerPosition
(
i
==
-
1
)
return
w
.
GetServerPosition
(
i
==
-
1
)
...
@@ -35,6 +40,7 @@ func (w *Window) GetClientPosition(i int) (x, y float64) {
...
@@ -35,6 +40,7 @@ func (w *Window) GetClientPosition(i int) (x, y float64) {
return
math
.
Cos
(
angle
)
*
(
w
.
circleSize
/
2
),
math
.
Sin
(
angle
)
*
(
w
.
circleSize
/
2
)
return
math
.
Cos
(
angle
)
*
(
w
.
circleSize
/
2
),
math
.
Sin
(
angle
)
*
(
w
.
circleSize
/
2
)
}
}
// GetServerPosition translates a server into its cartesian coordinates.
func
(
w
*
Window
)
GetServerPosition
(
platform
bool
)
(
x
,
y
float64
)
{
func
(
w
*
Window
)
GetServerPosition
(
platform
bool
)
(
x
,
y
float64
)
{
x
=
w
.
circleSize
/
2
+
150
x
=
w
.
circleSize
/
2
+
150
y
=
0
y
=
0
...
@@ -44,12 +50,13 @@ func (w *Window) GetServerPosition(platform bool) (x, y float64) {
...
@@ -44,12 +50,13 @@ func (w *Window) GetServerPosition(platform bool) (x, y float64) {
return
return
}
}
// DrawServers draws the DFSS main servers (ttp and platform)
func
(
w
*
Window
)
DrawServers
()
{
func
(
w
*
Window
)
DrawServers
()
{
scene
:=
w
.
graphics
.
Scene
()
scene
:=
w
.
graphics
.
Scene
()
ttp
:=
scene
.
AddPixmap
(
w
.
pixmaps
[
"ttp"
])
ttp
:=
scene
.
AddPixmap
(
w
.
pixmaps
[
"ttp"
])
x
,
y
:=
w
.
GetServerPosition
(
false
)
x
,
y
:=
w
.
GetServerPosition
(
false
)
ttp
.
SetPosFWithXY
(
x
-
32
,
y
-
16
)
ttp
.
SetPosFWithXY
(
x
-
32
,
y
-
16
)
// we are shifting here a bit for better arrow display
ttp
.
SetToolTip
(
"TTP"
)
ttp
.
SetToolTip
(
"TTP"
)
platform
:=
scene
.
AddPixmap
(
w
.
pixmaps
[
"platform"
])
platform
:=
scene
.
AddPixmap
(
w
.
pixmaps
[
"platform"
])
...
@@ -58,6 +65,7 @@ func (w *Window) DrawServers() {
...
@@ -58,6 +65,7 @@ func (w *Window) DrawServers() {
platform
.
SetToolTip
(
"Platform"
)
platform
.
SetToolTip
(
"Platform"
)
}
}
// DrawArrow is the graphic primitive for drawing an arrow between A and B points
func
(
w
*
Window
)
DrawArrow
(
xa
,
ya
,
xb
,
yb
float64
,
rgb
uint32
)
{
func
(
w
*
Window
)
DrawArrow
(
xa
,
ya
,
xb
,
yb
float64
,
rgb
uint32
)
{
scene
:=
w
.
graphics
.
Scene
()
scene
:=
w
.
graphics
.
Scene
()
...
@@ -94,6 +102,7 @@ func (w *Window) DrawArrow(xa, ya, xb, yb float64, rgb uint32) {
...
@@ -94,6 +102,7 @@ func (w *Window) DrawArrow(xa, ya, xb, yb float64, rgb uint32) {
w
.
currentArrows
=
append
(
w
.
currentArrows
,
arrow
)
w
.
currentArrows
=
append
(
w
.
currentArrows
,
arrow
)
}
}
// RemoveArrows remove every arrow present in the graphic area, and delete them for better memory management.
func
(
w
*
Window
)
RemoveArrows
()
{
func
(
w
*
Window
)
RemoveArrows
()
{
scene
:=
w
.
graphics
.
Scene
()
scene
:=
w
.
graphics
.
Scene
()
...
...
dfssd/gui/save.go
View file @
11dcecc3
package
gui
package
gui
// This file handles open/save feature.
import
(
import
(
"encoding/json"
"encoding/json"
"io/ioutil"
"io/ioutil"
...
...
dfssd/gui/structures.go
View file @
11dcecc3
package
gui
package
gui
// This file stores strucutures used in GUI for fast documentation.
import
(
import
(
"time"
"time"
...
...
dfssd/gui/window.go
View file @
11dcecc3
// Package gui is the graphic part of the dfssd program.
package
gui
package
gui
// This file is the entry point of the gui package.
// It handles window instantiation and basic operations on it.
import
(
import
(
"math"
"math"
"time"
"time"
...
@@ -8,6 +12,7 @@ import (
...
@@ -8,6 +12,7 @@ import (
"github.com/visualfc/goqt/ui"
"github.com/visualfc/goqt/ui"
)
)
// NewWindow creates and initialiaze a new dfssd main window.
func
NewWindow
()
*
Window
{
func
NewWindow
()
*
Window
{
file
:=
ui
.
NewFileWithName
(
":/widget.ui"
)
file
:=
ui
.
NewFileWithName
(
":/widget.ui"
)
loader
:=
ui
.
NewUiLoader
()
loader
:=
ui
.
NewUiLoader
()
...
@@ -52,17 +57,22 @@ func NewWindow() *Window {
...
@@ -52,17 +57,22 @@ func NewWindow() *Window {
return
w
return
w
}
}
// OnResizeEvent is called by Qt each time an user tries to resize the window.
// We have to redraw the whole scene to adapt.
func
(
w
*
Window
)
OnResizeEvent
(
ev
*
ui
.
QResizeEvent
)
bool
{
func
(
w
*
Window
)
OnResizeEvent
(
ev
*
ui
.
QResizeEvent
)
bool
{
w
.
initScene
()
w
.
initScene
()
return
true
return
true
}
}
// Log is used to print a new line in the log area of the window.
// It should be thread-safe.
func
(
w
*
Window
)
Log
(
str
string
)
{
func
(
w
*
Window
)
Log
(
str
string
)
{
str
=
time
.
Now
()
.
Format
(
"[15:04:05.000] "
)
+
str
str
=
time
.
Now
()
.
Format
(
"[15:04:05.000] "
)
+
str
w
.
logField
.
Append
(
str
)
w
.
logField
.
Append
(
str
)
w
.
logField
.
EnsureCursorVisible
()
w
.
logField
.
EnsureCursorVisible
()
}
}
// addIcons adds icons to control buttons, since we cannot add them directly in QtCreator.
func
(
w
*
Window
)
addIcons
()
{
func
(
w
*
Window
)
addIcons
()
{
w
.
SetWindowIcon
(
ui
.
NewIconWithFilename
(
":/images/node_magnifier.png"
))
w
.
SetWindowIcon
(
ui
.
NewIconWithFilename
(
":/images/node_magnifier.png"
))
...
@@ -79,6 +89,7 @@ func (w *Window) addIcons() {
...
@@ -79,6 +89,7 @@ func (w *Window) addIcons() {
w
.
replayButton
.
SetIcon
(
i
)
w
.
replayButton
.
SetIcon
(
i
)
}
}
// addActions adds action listenners to interactive parts of the window.
func
(
w
*
Window
)
addActions
()
{
func
(
w
*
Window
)
addActions
()
{
// MENU BAR
// MENU BAR
openAct
:=
ui
.
NewActionWithTextParent
(
"&Open"
,
w
)
openAct
:=
ui
.
NewActionWithTextParent
(
"&Open"
,
w
)
...
@@ -125,6 +136,8 @@ func (w *Window) addActions() {
...
@@ -125,6 +136,8 @@ func (w *Window) addActions() {
})
})
}
}
// initScene creates the Qt graphic scene associated to our custom scene.
// It draws the base circle, clients and servers, and do some memory management for us.
func
(
w
*
Window
)
initScene
()
{
func
(
w
*
Window
)
initScene
()
{
// Save old scene
// Save old scene
oldScene
:=
w
.
graphics
.
Scene
()
oldScene
:=
w
.
graphics
.
Scene
()
...
...
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