|
1
|
1 |
/* |
|
|
2 |
* Copyright 2012 Institut de recherche et d'innovation |
|
|
3 |
* contributor(s) : Samuel Huron, Raphael Velt |
|
|
4 |
* |
|
|
5 |
* contact@iri.centrepompidou.fr |
|
|
6 |
* http://www.iri.centrepompidou.fr |
|
|
7 |
* |
|
|
8 |
* This software is a computer program whose purpose is to show and add annotations on a video . |
|
|
9 |
* This software is governed by the CeCILL-C license under French law and |
|
|
10 |
* abiding by the rules of distribution of free software. You can use, |
|
|
11 |
* modify and/ or redistribute the software under the terms of the CeCILL-C |
|
|
12 |
* license as circulated by CEA, CNRS and INRIA at the following URL |
|
|
13 |
* "http://www.cecill.info". |
|
|
14 |
* |
|
|
15 |
* The fact that you are presently reading this means that you have had |
|
|
16 |
* knowledge of the CeCILL-C license and that you accept its terms. |
|
|
17 |
*/ |
|
|
18 |
|
|
|
19 |
/* Declaring the Renkan Namespace Rkns */ |
|
|
20 |
|
|
3
|
21 |
Rkns = { |
|
|
22 |
_FROM_GRAPHICS: 0, |
|
|
23 |
_FROM_DATA: 1 |
|
|
24 |
} |
|
1
|
25 |
|
|
|
26 |
Rkns.$ = jQuery; |
|
|
27 |
|
|
|
28 |
Rkns._ = _; |
|
|
29 |
|
|
|
30 |
Rkns.Serializers = {}; |
|
|
31 |
|
|
|
32 |
Rkns.Serializers._Base = function(_project) { |
|
|
33 |
if (typeof _project !== "undefined") { |
|
|
34 |
this._project = _project; |
|
|
35 |
this._callbackQueue = []; |
|
|
36 |
this._loaded = false; |
|
|
37 |
} |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
Rkns.Serializers._Base.prototype.deserialize = function() {} |
|
|
41 |
|
|
|
42 |
Rkns.Serializers._Base.prototype.deferCallback = function(_callback) { |
|
|
43 |
var _this = this; |
|
|
44 |
Rkns._.defer(function() { |
|
|
45 |
_callback.call(_this); |
|
|
46 |
}); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
Rkns.Serializers._Base.prototype.handleCallbacks = function() { |
|
|
50 |
this._loaded = true; |
|
|
51 |
while (this._callbackQueue.length) { |
|
|
52 |
this.deferCallback(this._callbackQueue.splice(0,1)[0]); |
|
|
53 |
} |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
Rkns.Serializers._Base.prototype.onLoad = function(_callback) { |
|
|
57 |
if (this._loaded) { |
|
|
58 |
this.deferCallback(_callback); |
|
|
59 |
} else { |
|
|
60 |
this._callbackQueue.push(_callback); |
|
|
61 |
} |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
Rkns.Renderers = {}; |
|
|
65 |
|
|
|
66 |
Rkns.Renderers._Base = function(_project) { |
|
|
67 |
if (typeof _project !== "undefined") { |
|
|
68 |
this._project = _project; |
|
|
69 |
} |
|
|
70 |
} |
|
|
71 |
|
|
|
72 |
Rkns.Project = function(_opts) { |
|
|
73 |
if (typeof _opts.serializer == "undefined") { |
|
|
74 |
_opts.serializer = "BasicJson"; |
|
|
75 |
} |
|
|
76 |
if (typeof _opts.renderer == "undefined") { |
|
|
77 |
_opts.renderer = "Paper"; |
|
|
78 |
} |
|
|
79 |
this._opts = _opts; |
|
|
80 |
this.users = new Rkns.Model.List(); |
|
|
81 |
this.nodes = new Rkns.Model.List(); |
|
|
82 |
this.edges = new Rkns.Model.List(); |
|
|
83 |
this.serializer = new Rkns.Serializers[_opts.serializer](this); |
|
|
84 |
this.renderer = new Rkns.Renderers[_opts.renderer](this); |
|
|
85 |
var _this = this; |
|
|
86 |
this.serializer.onLoad(function() { |
|
|
87 |
_this.renderer.draw(); |
|
2
|
88 |
}); |
|
1
|
89 |
} |
|
|
90 |
|
|
|
91 |
/* Utility functions */ |
|
|
92 |
|
|
|
93 |
Rkns.Utils = { |
|
|
94 |
_ID_AUTO_INCREMENT : 0, |
|
|
95 |
_ID_BASE : (function(_d) { |
|
|
96 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
97 |
function fillrand(n) { |
|
|
98 |
var _res = '' |
|
|
99 |
for (var i=0; i<n; i++) { |
|
|
100 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
101 |
} |
|
|
102 |
return _res; |
|
|
103 |
} |
|
|
104 |
return _d.getUTCFullYear() + '-' |
|
|
105 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
106 |
+ pad(_d.getUTCDate()) + '-' |
|
|
107 |
+ fillrand(16); |
|
|
108 |
})(new Date()), |
|
|
109 |
getUID : function(_base) { |
|
|
110 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
111 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
112 |
while (_n.length < 4) { |
|
|
113 |
_n = '0' + _n |
|
|
114 |
} |
|
|
115 |
return _base + this._ID_BASE + '-' + _n; |
|
|
116 |
}, |
|
|
117 |
inherit : function(_baseClass, _callbefore) { |
|
|
118 |
var _class = function() { |
|
|
119 |
if (typeof _callbefore === "function") { |
|
|
120 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
121 |
} |
|
|
122 |
if (typeof _baseClass.prototype._init !== "function") { |
|
|
123 |
_baseClass.prototype._init = function() {} |
|
|
124 |
} |
|
|
125 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
126 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
127 |
} |
|
|
128 |
_class.prototype = new _baseClass(); |
|
|
129 |
return _class; |
|
|
130 |
} |
|
|
131 |
} |