| author | durandn |
| Tue, 07 Jun 2016 10:46:20 +0200 | |
| changeset 612 | aa4987fede52 |
| parent 434 | 0d5998b32a7c |
| child 622 | 02e3c464223f |
| permissions | -rw-r--r-- |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
1 |
|
| 284 | 2 |
|
3 |
define(['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
4 |
'use strict'; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
5 |
|
| 284 | 6 |
var Utils = requtils.getUtils(); |
7 |
||
8 |
/* TempEdge Class Begin */ |
|
9 |
||
10 |
//var TempEdge = Renderer.TempEdge = Utils.inherit(Renderer._BaseRepresentation); |
|
11 |
var TempEdge = Utils.inherit(BaseRepresentation); |
|
12 |
||
13 |
_(TempEdge.prototype).extend({ |
|
14 |
_init: function() { |
|
15 |
this.renderer.edge_layer.activate(); |
|
16 |
this.type = "Temp-edge"; |
|
17 |
||
18 |
var _color = (this.project.get("users").get(this.renkan.current_user) || Utils._USER_PLACEHOLDER(this.renkan)).get("color"); |
|
19 |
this.line = new paper.Path(); |
|
20 |
this.line.strokeColor = _color; |
|
21 |
this.line.dashArray = [4, 2]; |
|
22 |
this.line.strokeWidth = this.options.selected_edge_stroke_width; |
|
23 |
this.line.add([0,0],[0,0]); |
|
24 |
this.line.__representation = this; |
|
25 |
this.arrow = new paper.Path(); |
|
26 |
this.arrow.fillColor = _color; |
|
27 |
this.arrow.add( |
|
28 |
[ 0, 0 ], |
|
29 |
[ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ], |
|
30 |
[ 0, this.options.edge_arrow_width ] |
|
31 |
); |
|
32 |
this.arrow.__representation = this; |
|
33 |
this.arrow_angle = 0; |
|
34 |
}, |
|
35 |
redraw: function() { |
|
36 |
var _p0 = this.from_representation.paper_coords, |
|
37 |
_p1 = this.end_pos, |
|
38 |
_a = _p1.subtract(_p0).angle, |
|
39 |
_c = _p0.add(_p1).divide(2); |
|
40 |
this.line.segments[0].point = _p0; |
|
41 |
this.line.segments[1].point = _p1; |
|
42 |
this.arrow.rotate(_a - this.arrow_angle); |
|
43 |
this.arrow.position = _c; |
|
44 |
this.arrow_angle = _a; |
|
45 |
}, |
|
46 |
paperShift: function(_delta) { |
|
47 |
if (!this.renderer.isEditable()) { |
|
48 |
this.renderer.removeRepresentation(_this); |
|
49 |
paper.view.draw(); |
|
50 |
return; |
|
51 |
} |
|
52 |
this.end_pos = this.end_pos.add(_delta); |
|
53 |
var _hitResult = paper.project.hitTest(this.end_pos); |
|
54 |
this.renderer.findTarget(_hitResult); |
|
55 |
this.redraw(); |
|
56 |
}, |
|
57 |
mouseup: function(_event, _isTouch) { |
|
58 |
var _hitResult = paper.project.hitTest(_event.point), |
|
59 |
_model = this.from_representation.model, |
|
60 |
_endDrag = true; |
|
61 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
62 |
var _target = _hitResult.item.__representation; |
|
63 |
if (_target.type.substr(0,4) === "Node") { |
|
64 |
var _destmodel = _target.model || _target.source_representation.model; |
|
65 |
if (_model !== _destmodel) { |
|
66 |
var _data = { |
|
67 |
id: Utils.getUID('edge'), |
|
68 |
created_by: this.renkan.current_user, |
|
69 |
from: _model, |
|
70 |
to: _destmodel |
|
71 |
}; |
|
72 |
if (this.renderer.isEditable()) { |
|
73 |
this.project.addEdge(_data); |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
if (_model === _target.model || (_target.source_representation && _target.source_representation.model === _model)) { |
|
79 |
_endDrag = false; |
|
80 |
this.renderer.is_dragging = true; |
|
81 |
} |
|
82 |
} |
|
83 |
if (_endDrag) { |
|
84 |
this.renderer.click_target = null; |
|
85 |
this.renderer.is_dragging = false; |
|
86 |
this.renderer.removeRepresentation(this); |
|
87 |
paper.view.draw(); |
|
88 |
} |
|
89 |
}, |
|
90 |
destroy: function() { |
|
91 |
this.arrow.remove(); |
|
92 |
this.line.remove(); |
|
93 |
} |
|
| 433 | 94 |
}).value(); |
| 284 | 95 |
|
96 |
/* TempEdge Class End */ |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
97 |
|
| 284 | 98 |
return TempEdge; |
99 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
100 |
}); |