|
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 |
|
|
5
|
19 |
/* Declaring the Renkan Namespace Rkns and Default values */ |
|
1
|
20 |
|
|
3
|
21 |
Rkns = { |
|
5
|
22 |
_MIN_DRAG_DISTANCE: 4, |
|
4
|
23 |
_NODE_RADIUS: 20, |
|
|
24 |
_NODE_FONT_SIZE: 14, |
|
|
25 |
_ARROW_LENGTH: 20, |
|
|
26 |
_ARROW_WIDTH: 15, |
|
|
27 |
_RENDER: 1, |
|
|
28 |
_SAVE: 2, |
|
|
29 |
_RENDER_AND_SAVE: 3 |
|
3
|
30 |
} |
|
1
|
31 |
|
|
|
32 |
Rkns.$ = jQuery; |
|
|
33 |
|
|
|
34 |
Rkns._ = _; |
|
|
35 |
|
|
|
36 |
Rkns.Serializers = {}; |
|
|
37 |
|
|
|
38 |
Rkns.Serializers._Base = function(_project) { |
|
|
39 |
if (typeof _project !== "undefined") { |
|
|
40 |
this._project = _project; |
|
|
41 |
this._callbackQueue = []; |
|
|
42 |
this._loaded = false; |
|
|
43 |
} |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
Rkns.Serializers._Base.prototype.deserialize = function() {} |
|
|
47 |
|
|
|
48 |
Rkns.Serializers._Base.prototype.deferCallback = function(_callback) { |
|
|
49 |
var _this = this; |
|
|
50 |
Rkns._.defer(function() { |
|
|
51 |
_callback.call(_this); |
|
|
52 |
}); |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
Rkns.Serializers._Base.prototype.handleCallbacks = function() { |
|
|
56 |
this._loaded = true; |
|
|
57 |
while (this._callbackQueue.length) { |
|
|
58 |
this.deferCallback(this._callbackQueue.splice(0,1)[0]); |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
Rkns.Serializers._Base.prototype.onLoad = function(_callback) { |
|
|
63 |
if (this._loaded) { |
|
|
64 |
this.deferCallback(_callback); |
|
|
65 |
} else { |
|
|
66 |
this._callbackQueue.push(_callback); |
|
|
67 |
} |
|
|
68 |
} |
|
|
69 |
|
|
4
|
70 |
Rkns.Serializers._Base.prototype.save = function() {} |
|
|
71 |
|
|
1
|
72 |
Rkns.Renderers = {}; |
|
|
73 |
|
|
|
74 |
Rkns.Renderers._Base = function(_project) { |
|
|
75 |
if (typeof _project !== "undefined") { |
|
|
76 |
this._project = _project; |
|
|
77 |
} |
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
Rkns.Project = function(_opts) { |
|
|
81 |
if (typeof _opts.serializer == "undefined") { |
|
|
82 |
_opts.serializer = "BasicJson"; |
|
|
83 |
} |
|
|
84 |
if (typeof _opts.renderer == "undefined") { |
|
|
85 |
_opts.renderer = "Paper"; |
|
|
86 |
} |
|
5
|
87 |
if (typeof _opts.language == "undefined" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
|
88 |
_opts.language = "en"; |
|
|
89 |
} |
|
|
90 |
this.l10n = Rkns.i18n[_opts.language]; |
|
1
|
91 |
this._opts = _opts; |
|
|
92 |
this.users = new Rkns.Model.List(); |
|
|
93 |
this.nodes = new Rkns.Model.List(); |
|
|
94 |
this.edges = new Rkns.Model.List(); |
|
4
|
95 |
if (typeof this._opts.user === "object") { |
|
|
96 |
this.current_user = this.addUser(this._opts.user) |
|
|
97 |
} |
|
1
|
98 |
this.serializer = new Rkns.Serializers[_opts.serializer](this); |
|
|
99 |
this.renderer = new Rkns.Renderers[_opts.renderer](this); |
|
|
100 |
var _this = this; |
|
|
101 |
this.serializer.onLoad(function() { |
|
4
|
102 |
if (typeof _this.current_user === "undefined") { |
|
|
103 |
_this.current_user = _proj.users[0]; |
|
|
104 |
} |
|
1
|
105 |
_this.renderer.draw(); |
|
2
|
106 |
}); |
|
1
|
107 |
} |
|
|
108 |
|
|
4
|
109 |
Rkns.Project.prototype.addNode = function(_props, _render_save) { |
|
|
110 |
var _node = new Rkns.Model.Node(this, _props); |
|
|
111 |
this.nodes.push(_node); |
|
|
112 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._RENDER)) { |
|
5
|
113 |
var _controller = this.renderer.addController("Node", _node); |
|
4
|
114 |
_controller.redraw(); |
|
|
115 |
} |
|
|
116 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._SAVE)) { |
|
|
117 |
this.serializer.save(); |
|
|
118 |
} |
|
|
119 |
return _node; |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
Rkns.Project.prototype.addEdge = function(_props, _render_save) { |
|
|
123 |
var _edge = new Rkns.Model.Edge(this, _props); |
|
|
124 |
this.edges.push(_edge); |
|
|
125 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._RENDER)) { |
|
5
|
126 |
var _controller = this.renderer.addController("Edge", _edge); |
|
4
|
127 |
_controller.redraw(); |
|
|
128 |
} |
|
|
129 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._SAVE)) { |
|
|
130 |
this.serializer.save(); |
|
|
131 |
} |
|
|
132 |
return _edge; |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
Rkns.Project.prototype.addUser = function(_props, _render_save) { |
|
|
136 |
var _user = new Rkns.Model.User(this, _props); |
|
|
137 |
this.users.push(_user); |
|
|
138 |
return _user; |
|
|
139 |
} |
|
|
140 |
|
|
5
|
141 |
Rkns.Project.prototype.updateElement = function(_element, _props, _render_save) { |
|
|
142 |
Rkns._(_props).each(function(_v, _k) { |
|
|
143 |
_element[_k] = _v; |
|
|
144 |
}); |
|
|
145 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._RENDER)) { |
|
|
146 |
console.log("Shall redraw"); |
|
|
147 |
if (typeof _element.__controller !== "undefined") { |
|
|
148 |
_element.__controller.redraw(); |
|
|
149 |
} else { |
|
|
150 |
this._renderer.redraw(); |
|
|
151 |
} |
|
|
152 |
} |
|
|
153 |
if (typeof _render_save !== "undefined" && (_render_save&Rkns._SAVE)) { |
|
|
154 |
this.serializer.save(); |
|
|
155 |
} |
|
|
156 |
} |
|
|
157 |
|
|
1
|
158 |
/* Utility functions */ |
|
|
159 |
|
|
|
160 |
Rkns.Utils = { |
|
|
161 |
_ID_AUTO_INCREMENT : 0, |
|
|
162 |
_ID_BASE : (function(_d) { |
|
|
163 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
164 |
function fillrand(n) { |
|
|
165 |
var _res = '' |
|
|
166 |
for (var i=0; i<n; i++) { |
|
|
167 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
168 |
} |
|
|
169 |
return _res; |
|
|
170 |
} |
|
|
171 |
return _d.getUTCFullYear() + '-' |
|
|
172 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
173 |
+ pad(_d.getUTCDate()) + '-' |
|
|
174 |
+ fillrand(16); |
|
|
175 |
})(new Date()), |
|
|
176 |
getUID : function(_base) { |
|
|
177 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
178 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
179 |
while (_n.length < 4) { |
|
|
180 |
_n = '0' + _n |
|
|
181 |
} |
|
|
182 |
return _base + this._ID_BASE + '-' + _n; |
|
|
183 |
}, |
|
|
184 |
inherit : function(_baseClass, _callbefore) { |
|
|
185 |
var _class = function() { |
|
|
186 |
if (typeof _callbefore === "function") { |
|
|
187 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
188 |
} |
|
|
189 |
if (typeof _baseClass.prototype._init !== "function") { |
|
|
190 |
_baseClass.prototype._init = function() {} |
|
|
191 |
} |
|
|
192 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
193 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
194 |
} |
|
|
195 |
_class.prototype = new _baseClass(); |
|
|
196 |
return _class; |
|
|
197 |
} |
|
|
198 |
} |