This file is indexed.

/usr/lib/python3/dist-packages/gvbmod/drawers.py is in gvb 1.4-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# GVB - a GTK+/GNOME vibrations simulator
#
# Copyright © 2008-2013 Pietro Battiston
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


from gi.repository import Gtk, Gdk
from scipy import shape
from time import time
from cairo import ImageSurface, FORMAT_ARGB32, Context

def one_basic(cr, size, pos, speeds = None):
    spaced=1./(len(pos)+1)

    cr.scale(size[0], size[1]/4)
    cr.translate(0, 2)
    cr.set_line_width(.01)
    cr.set_source_rgb(1,0,0)

    cr.move_to(0,0)

    xposition=0
    for ypos in pos:
        xposition=xposition+spaced

        cr.line_to(xposition, -ypos)
    cr.line_to(1,0)
    cr.stroke()


def with_speeds(cr, size, pos, speeds):
    n = len(pos)
    spaced=1./(n+1)
    coeff = .1*n
    cr.scale(size[0], size[1]/4)
    cr.translate(0, 2)
    cr.set_line_width(.1/n)
    cr.set_source_rgb(1,0,0)


    cr.move_to(0,0)

    xposition=spaced
    for idx in range(len(pos)):
        cr.move_to(xposition,-pos[idx])
        cr.rel_line_to(0,-speeds[idx]*coeff)
        cr.stroke()
        xposition=xposition+spaced

    cr.set_line_width(.02)
    cr.set_source_rgb(0,0,1)
    cr.move_to(0,0)

    xposition=0
    for ypos in pos:
        xposition=xposition+spaced

        cr.line_to(xposition, -ypos)
    cr.line_to(1,0)
    cr.stroke()


def temperature(cr, size, pos, speeds = None):
    spaced=1./(len(pos))

    cr.scale(size[0], size[1]/4)
    cr.translate(0, 2)
    cr.set_line_width(.5)
    cr.set_source_rgb(1,0,0)

    cr.move_to(0,0)

    xposition=0
    for ypos in pos:
        cr.move_to(xposition,0)
        xposition=xposition+spaced

        if ypos >= 1:
            cr.set_source_rgb(1,1,1)
        elif ypos > .5:
            cr.set_source_rgb((1-ypos)/2,(1-ypos)/2,0)
        elif ypos > 0:
            cr.set_source_rgb(ypos/2, 1-1.5*ypos, 0)
        elif ypos > -.5:
            cr.set_source_rgb(0,1+2*ypos,-ypos)
        else:
            cr.set_source_rgb(0,0,1+ypos)
        cr.line_to(xposition, 0)
        cr.stroke()


def _two_colours(cr, pos, size, speeds = None):
    hspaced=1./shape(pos)[0]
    vspaced=1./shape(pos)[1]

    cr.scale(size[0], size[1])
    yposition=0
    for ypos in pos:
        xposition=0

        for xpos in ypos:
            if xpos > 0:
                cr.set_source_rgb(1-xpos,1,1)
            else:
                cr.set_source_rgb(1,1+xpos,1)
            cr.rectangle(xposition, yposition, hspaced, vspaced)
            cr.fill()
            xposition=xposition+hspaced
        yposition=yposition+vspaced


def colours(cr, size, pos, speeds = None):
    hspaced=1./shape(pos)[0]
    vspaced=1./shape(pos)[1]

    cr.scale(size[0], size[1])
    cr.translate(0, vspaced/2)
    cr.set_line_width(vspaced)
    yposition=0
    for ypos in pos:
        xposition=0
        cr.move_to(0,yposition)

        for xpos in ypos:
            cr.move_to(xposition, yposition)
            xposition=xposition+hspaced

            if xpos >= 1:
                cr.set_source_rgb(1,1,1)
            elif xpos > .5:
                cr.set_source_rgb((1-xpos)/2,(1-xpos)/2,0)
            elif xpos > 0:
                cr.set_source_rgb(xpos/2, 1-1.5*xpos, 0)
            elif xpos > -.5:
                cr.set_source_rgb(0,1+2*xpos,-xpos)
            else:
                cr.set_source_rgb(0,0,1+xpos)

            cr.line_to(xposition, yposition)
            cr.stroke()
        yposition=yposition+vspaced



def trid(cr, size, pos, speeds = None):
    m,n=shape(pos)

    vspaced=1./(3*n)

    yposition=.3

    cr.set_line_join(2)

    pos = pos * .5

    tr = ([[yposition for i in range(n+2)]]
        +[[yposition+(j+1)*vspaced]+[yposition + (j+1)*vspaced-pos[j][i]/2 for i in range(n)]+[yposition+(j+1)*vspaced] for j in range(m)]
        +[[yposition+(m+1)*vspaced for i in range(n+2)]])

    cr.scale(size[0], size[1])

    cr.set_line_width(.001)

    top_margin = .1

    for row_idx in range(m+1):
        margin = top_margin*(1-(row_idx/m))
        marg_under = top_margin*(1-((row_idx+1)/m))
        hspaced=(1-2*margin)/(n+3)
        xposition = margin + hspaced
        hsp_under=(1-2*marg_under)/(n+3)
        xpos_under = marg_under + hsp_under

        for col_idx in range(n+1):
            if tr[row_idx][col_idx+1] > tr[row_idx+1][col_idx+1]:
                cr.set_source_rgba(1,0,0,.8)
            else:
                cr.set_source_rgba(0,1,0,.8)
            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xposition + hspaced, tr[row_idx][col_idx+1])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.close_path()
            cr.fill()

            if tr[row_idx][col_idx] > tr[row_idx+1][col_idx]:
                cr.set_source_rgba(1,0,0,.8)
            else:
                cr.set_source_rgba(0,1,0,.8)
            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.line_to(xpos_under, tr[row_idx+1][col_idx])
            cr.close_path()
            cr.fill()

            cr.set_source_rgb(0,0,0)

            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xposition + hspaced, tr[row_idx][col_idx+1])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.line_to(xpos_under, tr[row_idx+1][col_idx])
            cr.close_path()
            cr.stroke()
            xposition=xposition+hspaced
            xpos_under=xpos_under+hsp_under

def trid_speeds(cr, size, pos, speeds = None):
    m,n=shape(pos)

    vspaced=1./(3*n)

    coeff = .05*max(m,n)

    yposition=.3

    cr.set_line_join(2)

    pos = pos * .5

    tr = ([[yposition for i in range(n+2)]]
        +[[yposition+(j+1)*vspaced]+[yposition + (j+1)*vspaced-pos[j][i]/2 for i in range(n)]+[yposition+(j+1)*vspaced] for j in range(m)]
        +[[yposition+(m+1)*vspaced for i in range(n+2)]])

    cr.scale(size[0], size[1])
    cr.set_line_width(.001)

    top_margin = .1

    for row_idx in range(m+1):
        margin = top_margin*(1-(row_idx/m))
        marg_under = top_margin*(1-((row_idx+1)/m))
        hspaced=(1-2*margin)/(n+3)
        xposition = margin + hspaced
        hsp_under=(1-2*marg_under)/(n+3)
        xpos_under = marg_under + hsp_under
#        print ypos
        for col_idx in range(n+1):
            cr.set_line_width(.001)
            if tr[row_idx][col_idx+1] > tr[row_idx+1][col_idx+1]:
                cr.set_source_rgba(0,0,1,.8)
            else:
                cr.set_source_rgba(0,1,0,.8)
            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xposition + hspaced, tr[row_idx][col_idx+1])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.close_path()
            cr.fill()

            if tr[row_idx][col_idx] > tr[row_idx+1][col_idx]:
                cr.set_source_rgba(0,0,1,.8)
            else:
                cr.set_source_rgba(0,1,0,.8)
            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.line_to(xpos_under, tr[row_idx+1][col_idx])
            cr.close_path()
            cr.fill()

            cr.set_source_rgb(0,0,0)

            cr.move_to(xposition, tr[row_idx][col_idx])
            cr.line_to(xposition + hspaced, tr[row_idx][col_idx+1])
            cr.line_to(xpos_under + hsp_under, tr[row_idx+1][col_idx+1])
            cr.line_to(xpos_under, tr[row_idx+1][col_idx])
            cr.close_path()
            cr.stroke()

            if row_idx != 0 and col_idx != 0:
                cr.set_line_width(.1/n)

                cr.set_source_rgba(1,0,0,.5)
                cr.move_to(xposition, tr[row_idx][col_idx])
                cr.rel_line_to(0,-speeds[row_idx-1][col_idx-1]*coeff)
                cr.stroke()

            xposition=xposition+hspaced
            xpos_under=xpos_under+hsp_under

drawers_1d = {
                'wave' :    one_basic,
                'temp' :    temperature,
                'speeds':    with_speeds
            }

drawers_2d = {
                'geo' :        colours,
                '3D' :        trid,
                'speeds':    trid_speeds
            }


drawers_dict={ 1: drawers_1d, 2: drawers_2d }
drawers = {1: ['wave', 'temp', 'speeds'], 2: ['3D', 'geo', 'speeds']}

class Drawer():
    def __init__(self, drawing, combo, dr_type = None):
        self.drawing = drawing
        self.dumpdir = None
        self.combo = combo
        self.active = True
        self.points = None
        self.dim = None
        self.ready = False
        self.drawn = 0
        self.dr_type = dr_type
        self.combo.connect('changed', self.change_drawer)
        if hasattr(self.drawing, 'signals_ids'):
            # This means that the drawing area was already drawn by another
            # drawer. This one is a possessive guy and want her to forget him.
            for signal_id in self.drawing.signals_ids:
                self.drawing.disconnect(signal_id)
        
        # Throw away all his ids! You're mine now!
        self.drawing.signals_ids = []
        self.drawing.signals_ids.append(self.drawing.connect('draw', self.redraw))
        self.size = None

    def draw(self, cr):
        if self.dim != len(self.points.shape):
            raise
        if not self.drawing.get_window():
            return
        if self.dumpdir:
            try:
                cr.set_source_surface(self._last_surface, 0, 0)
            except AttributeError:
                # Still no surface ready
                pass

        before=time()
        if not hasattr(self, 'drawer'):
            return
        size = self.drawing.get_allocated_width(), self.drawing.get_allocated_height()

        cr.rectangle(0, 0, *size)
        cr.set_source_rgb(1, 1, 1)
        cr.fill()
        
        self.drawer(cr, size, self.points.pos, self.points.speeds)
        self.drawn=time()
        self.drawing_time = self.drawn-before

    def dump_draw(self):

        self._last_surface = ImageSurface(FORMAT_ARGB32, self.size[0], self.size[1])

        self.cr = Context(self._last_surface)

        before=time()
        self.drawer(self.cr, self.size, self.points.pos, self.points.speeds)

        self._last_surface.write_to_png('%s/%08d.png' % (self.dumpdir,
                                                         self.dumpindex))
        self.dumpindex += 1
        self.drawn=time()
        self.drawing_time = self.drawn-before
        self.invalidate()
    
    def invalidate(self):
        self.drawing.queue_draw()
    
    def redraw(self, widget, cr):
        self.draw(cr)

    def change_drawer(self, combo):
        self.dr_type = self.combo.get_active_text()
        if self.dr_type in drawers[self.dim]:
            self.drawer=drawers_dict[self.dim][self.dr_type]
            self.drawing.queue_draw()


    def configure(self, points=None, dim=None):
        if not self.active:
            return

        if points:
            self.points = points
            dim = len(shape(points.pos))

        if dim:
            if self.dim != dim:
                self.dim = dim
                self.build_menu()
                self.ready = True
        else:
            return

#        if not (self.points and len(shape(self.points.pos)) == self.dim):    #I won't change dimension if they don't tell me!
#            return

    def build_menu(self):
        combo_model = Gtk.ListStore(str)
        for item in drawers[self.dim]:
            combo_model.append([item])
        self.combo.set_model(combo_model)
        if self.dr_type in drawers[self.dim]:
            self.combo.set_active(drawers[self.dim].index(self.dr_type))
        else:
            self.combo.set_active(0)

    def dump(self, dumpdir):
        print("dumping in", dumpdir)
        self.dumpindex = 0

        if dumpdir:                #This is a "start" command
            self.dumpdir = dumpdir
            self.size = self.drawing.get_allocated_width(), self.drawing.get_allocated_height()
            self.points.changed = self.dump_draw
        else:                        #This is a "stop" command
            self.dumpdir = None
            self.size = None
            self.points.changed = self.invalidate