| 1 |
define(["dojo", "../util/oo", "../util/positioning"], |
| 2 |
function(dojo, oo, positioning){ |
| 3 |
|
| 4 |
|
| 5 |
return oo.declare( |
| 6 |
function( options){ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
this.stencil = options.stencil; |
| 11 |
this.util = options.stencil.util; |
| 12 |
this.mouse = options.stencil.mouse; |
| 13 |
|
| 14 |
this.stencil.connectMult([ |
| 15 |
["onDrag", this, "showAngle"], |
| 16 |
["onUp", this, "hideAngle"], |
| 17 |
["onTransformBegin", this, "showAngle"], |
| 18 |
["onTransform", this, "showAngle"], |
| 19 |
["onTransformEnd", this, "hideAngle"] |
| 20 |
]); |
| 21 |
}, |
| 22 |
{ |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
type:"dojox.drawing.tools.custom", |
| 33 |
angle:0, |
| 34 |
|
| 35 |
showAngle: function(){ |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
if(!this.stencil.selected && this.stencil.created){ return; } |
| 40 |
if(this.stencil.getRadius() < this.stencil.minimumSize){ |
| 41 |
this.hideAngle(); |
| 42 |
return; |
| 43 |
} |
| 44 |
var node = this.getAngleNode(); |
| 45 |
var d = this.stencil.pointsToData(); |
| 46 |
var pt = positioning.angle({x:d.x1,y:d.y1},{x:d.x2,y:d.y2}); |
| 47 |
var sc = this.mouse.scrollOffset(); |
| 48 |
var mx = this.stencil.getTransform(); |
| 49 |
var dx = mx.dx / this.mouse.zoom; |
| 50 |
var dy = mx.dy / this.mouse.zoom; |
| 51 |
pt.x /= this.mouse.zoom; |
| 52 |
pt.y /= this.mouse.zoom; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
var x = this.stencil._offX + pt.x - sc.left + dx; |
| 58 |
var y = this.stencil._offY + pt.y - sc.top + dy; |
| 59 |
dojo.style(node, { |
| 60 |
left: x + "px", |
| 61 |
top: y + "px", |
| 62 |
align:pt.align |
| 63 |
}); |
| 64 |
|
| 65 |
var angle=this.stencil.getAngle(); |
| 66 |
if(this.stencil.style.zAxis && this.stencil.shortType=="vector"){ |
| 67 |
node.innerHTML = this.stencil.data.cosphi > 0 ? "out of" : "into"; |
| 68 |
}else if(this.stencil.shortType=="line"){ |
| 69 |
node.innerHTML = this.stencil.style.zAxis?"out of":Math.ceil(angle%180); |
| 70 |
}else{ |
| 71 |
node.innerHTML = Math.ceil(angle); |
| 72 |
} |
| 73 |
}, |
| 74 |
|
| 75 |
getAngleNode: function(){ |
| 76 |
|
| 77 |
|
| 78 |
if(!this._angleNode){ |
| 79 |
this._angleNode = dojo.create("span", null, dojo.body()); |
| 80 |
dojo.addClass(this._angleNode, "textAnnotation"); |
| 81 |
dojo.style(this._angleNode, "opacity", 1); |
| 82 |
} |
| 83 |
return this._angleNode; |
| 84 |
}, |
| 85 |
|
| 86 |
hideAngle: function(){ |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
if(this._angleNode && dojo.style(this._angleNode, "opacity")>0.9){ |
| 91 |
|
| 92 |
dojo.fadeOut({node:this._angleNode, |
| 93 |
duration:500, |
| 94 |
onEnd: function(node){ |
| 95 |
dojo.destroy(node); |
| 96 |
} |
| 97 |
}).play(); |
| 98 |
this._angleNode = null; |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
); |
| 104 |
}); |