-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectionBar.py
193 lines (159 loc) · 5.81 KB
/
selectionBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from math import *
from euclid import *
from omega import *
from omegaToolkit import *
from cyclops import *
import icecloud
# load the plot GPU program
shaderPath = "icecloud/shaders/";
plotProgram = ProgramAsset()
plotProgram.name = "plot2"
plotProgram.vertexShaderName = shaderPath + "plot.vert"
plotProgram.fragmentShaderName = shaderPath + "plot.frag"
plotProgram.geometryShaderName = shaderPath + "plot.geom"
plotProgram.geometryOutVertices = 4
plotProgram.geometryInput = PrimitiveType.Points
plotProgram.geometryOutput = PrimitiveType.TriangleStrip
getSceneManager().addProgram(plotProgram)
# Create the material and uniforms used to draw the selection bar
xboundsu = Uniform.create('unif_XBounds', UniformType.Vector2f, 1)
yboundsu = Uniform.create('unif_YBounds', UniformType.Vector2f, 1)
xu = Uniform.create('unif_XAxisId', UniformType.Int, 1)
yu = Uniform.create('unif_YAxisId', UniformType.Int, 1)
pointScale = Uniform.create('pointScale', UniformType.Float, 1)
pointScale.setFloat(0.002)
selectionPlotMaterial = Material.create()
selectionPlotMaterial.setProgram('plot2')
selectionPlotMaterial.attachUniform(pointScale)
selectionPlotMaterial.attachUniform(xboundsu)
selectionPlotMaterial.attachUniform(yboundsu)
selectionPlotMaterial.attachUniform(xu)
selectionPlotMaterial.attachUniform(yu)
selectionPlotMaterial.setDepthTestEnabled(False)
selectionPlotMaterial.setAdditive(True)
selectionPlotMaterial.setTransparent(True)
activeDive = None
PLOT_PANEL_COLOR = "#aaaaff"
SELECTOR_COLOR = "#8888ffff"
# axis constants
AXIS_X = 0
AXIS_Y = 1
AXIS_DEPTH = 2
AXIS_ANGLE = 3
AXIS_RANGE = 4
AXIS_TIMESTAMP = 5
plotWidth = 2000
plotHeight = 480
container = Container.create(ContainerLayout.LayoutFree, icecloud.uiroot)
container.setStyle("fill: #000000; border: 1 {0}".format(PLOT_PANEL_COLOR))
container.setAutosize(True)
container.setPosition(Vector2(16, 16))
container.setEnabled(False)
#container.setScale(4)
container.setCenter(Vector2(2000,2000))
container.setDraggable(True)
# create camera
camera = getOrCreateCamera('selectionCamera')
camera.setEnabled(True)
coutput = PixelData.create(plotWidth, plotHeight, PixelFormat.FormatRgba)
camera.getOutput(0).setReadbackTarget(coutput)
camera.getOutput(0).setEnabled(True)
camera.setFlag(Material.CameraDrawExplicitMaterials)
camera.setBackgroundColor(Color(0,0,0,1))
camera.clearColor(True)
camera.setCullingEnabled(False)
# Update bar every 2 seconds.
camera.setMaxFps(0.5)
selectionPlotMaterial.setCamera(camera)
img = Image.create(container)
img.setData(coutput)
offs = container.getMargin() + container.getPadding() / 2
img.setPosition(Vector2(offs,offs))
selector = Widget.create(container)
selector.setStyle('fill: {0}'.format(SELECTOR_COLOR))
selector.setAlpha(0.5)
selector.setLayer(WidgetLayer.Front)
selector.setSize(Vector2(100, plotHeight))
selector.setPosition(Vector2(offs,offs))
selectionStart = 0
selectionEnd = 0
diveName = Label.create(container)
diveName.setLayer(WidgetLayer.Front)
diveName.setPosition(Vector2(offs,offs))
diveName.setText("")
def setActiveDive(dive):
global activeDive
if(activeDive != None):
activeDive.pointsObject.removeMaterial(selectionPlotMaterial)
activeDive = dive
if(activeDive != None):
diveName.setText(activeDive.label)
activeDive.pointsObject.addMaterial(selectionPlotMaterial)
tmin = activeDive.diveInfo['minB']
tmax = activeDive.diveInfo['maxB']
xboundsu.setVector2f(Vector2(tmin, tmax))
print("bounds: {0} {1}".format(tmin, tmax))
# Hardcoded depth bounds
yboundsu.setVector2f(Vector2(-10, 60))
xu.setInt(AXIS_TIMESTAMP)
yu.setInt(AXIS_DEPTH)
def setSelection(start, end):
global selectionStart
global selectionEnd
global selection
selectionStart = start
selectionEnd = end
if(activeDive != None):
activeDive.selection.setVector2f(Vector2(selectionStart, selectionEnd))
mcc = getMissionControlClient()
if(mcc):
mcc.postCommand('@endurance*:icecloud.dives["{0}"].setActive(True)'.format(activeDive.id))
mcc.postCommand('@endurance*:icecloud.dives["{0}"].selection.setVector2f(Vector2({1}, {2}))'.format(
activeDive.id, selectionStart, selectionEnd))
# Adjust selection widget
ssx = selectionStart * plotWidth
sex = selectionEnd * plotWidth
selector.setPosition(Vector2(ssx + offs, offs))
selector.setWidth(sex - ssx)
setSelection(0.0, 0.0)
#-------------------------------------------------------------------------------
# Selection bar interaction
selectionMoveSpeed = 0
selectionSizeSpeed = 0
def onEvent():
global selectionMoveSpeed
global selectionSizeSpeed
e = getEvent()
if(e.isButtonDown(EventFlags.ButtonLeft)):
selectionMoveSpeed = -0.2
elif(e.isButtonDown(EventFlags.ButtonRight)):
selectionMoveSpeed = 0.2
elif(e.isButtonDown(EventFlags.ButtonUp)):
selectionSizeSpeed = 0.2
elif(e.isButtonDown(EventFlags.ButtonDown)):
selectionSizeSpeed = -0.2
elif(e.getType() == EventType.Up):
selectionMoveSpeed = 0.0
selectionSizeSpeed = 0.0
def onUpdate(frame, time, dt):
global selectionMoveSpeed
global selectionSizeSpeed
global selectionStart
global selectionEnd
size = selectionEnd - selectionStart
center = selectionStart + size / 2
center += selectionMoveSpeed * dt
size += selectionSizeSpeed * dt
if(size <= 0.01): size = 0.01
if(center < 0 ): center = 0
if(center > 1): center = 1
start = center - size / 2
end = center + size / 2
setSelection(start, end)
# Animate selection color
if(activeDive != None):
cv = abs(sin(time * 2))
sc = Color(1 - cv, 1, 0, 1)
activeDive.selectionColor.setColor(sc)
setEventFunction(onEvent)
setUpdateFunction(onUpdate)