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