//>>built
define("dojox/drawing/tools/custom/Vector",["dojo","../../util/oo","../../manager/_registry","../Arrow","../../defaults"],function(d,g,k,l,h){g=g.declare(l,function(a){this.minimumSize=this.style.arrows.length;this.addShadow({size:3,mult:2})},{draws:!0,type:"dojox.drawing.tools.custom.Vector",minimumSize:30,showAngle:!0,changeAxis:function(a){a=void 0!==a?a:this.style.zAxis?0:1;if(0==a)this.style.zAxis=!1,this.data.cosphi=0;else{this.style.zAxis=!0;a=this.points;var b=this.zPoint();this.setPoints([{x:a[0].x,
y:a[0].y},{x:b.x,y:b.y}])}this.render()},_createZeroVector:function(a,b,c){b="hit"==a?this.minimumSize:this.minimumSize/6;var e="hit"==a?c.fill:null;b={cx:this.data.x1,cy:this.data.y1,rx:b,ry:b};this.remove(this[a]);this[a]=this.container.createEllipse(b).setStroke(c).setFill(e);this.util.attr(this[a],"drawingType","stencil")},_create:function(a,b,c){this.remove(this[a]);this[a]=this.container.createLine(b).setStroke(c);this._setNodeAtts(this[a])},onDrag:function(a){if(!this.created){var b=a.start.x,
c=a.start.y,e=a.x,f=a.y;this.keys.shift&&!this.style.zAxis&&(f=this.util.snapAngle(a,.25),e=f.x,f=f.y);if(this.keys.alt)var d=e>b?(e-b)/2:(b-e)/-2,g=f>c?(f-c)/2:(c-f)/-2,b=b-d,e=e-d,c=c-g,f=f-g;this.style.zAxis&&(a=this.zPoint(a),e=a.x,f=a.y);this.setPoints([{x:b,y:c},{x:e,y:f}]);this.render()}},onTransform:function(a){if(!this._isBeingModified)this.onTransformBegin();this.setPoints(this.points);this.render()},anchorConstrain:function(a,b){if(!this.style.zAxis)return null;var c=this.style.zAngle*
Math.PI/180,e=0>a?a>-b:a<-b;return{x:e?a:-b/Math.tan(c),y:e?-Math.tan(c)*a:b}},zPoint:function(a){if(void 0===a){if(!this.points[0])return null;a=this.pointsToData();a={start:{x:a.x1,y:a.y1},x:a.x2,y:a.y2}}var b=this.util.length(a),c=this.util.angle(a),c=0>c?360+c:c,c=135<c&&315>c?this.style.zAngle:this.util.oppAngle(this.style.zAngle);return this.util.pointOnCircle(a.start.x,a.start.y,b,c)},pointsToData:function(a){a=a||this.points;var b=0,c={start:{x:a[0].x,y:a[0].y},x:a[1].x,y:a[1].y};this.style.zAxis&&
this.util.length(c)>this.minimumSize&&(b=this.util.angle(c),b=0>b?360+b:b,b=135<b&&315>b?1:-1);return this.data={x1:a[0].x,y1:a[0].y,x2:a[1].x,y2:a[1].y,cosphi:b}},dataToPoints:function(a){a=a||this.data;if(a.radius||a.angle){var b=0,c=this.util.pointOnCircle(a.x,a.y,a.radius,a.angle);if(this.style.zAxis||a.cosphi&&0!=a.cosphi)this.style.zAxis=!0,b=135<a.angle&&315>a.angle?1:-1;this.data=a={x1:a.x,y1:a.y,x2:c.x,y2:c.y,cosphi:b}}return this.points=[{x:a.x1,y:a.y1},{x:a.x2,y:a.y2}]},render:function(){this.onBeforeRender(this);
this.getRadius()>=this.minimumSize?(this._create("hit",this.data,this.style.currentHit),this._create("shape",this.data,this.style.current)):(this.data.cosphi=0,this._createZeroVector("hit",this.data,this.style.currentHit),this._createZeroVector("shape",this.data,this.style.current))},onUp:function(a){if(!this.created&&this._downOnCanvas){this._downOnCanvas=!1;this.shape||(a.start.x=this.style.zAxis?a.start.x+100:a.start.x,a.y+=100,this.setPoints([{x:a.start.x,y:a.start.y},{x:a.x,y:a.y}]),this.render());
if(this.getRadius()<this.minimumSize){var b=this.points;this.setPoints([{x:b[0].x,y:b[0].y},{x:b[0].x,y:b[0].y}])}else b=this.points,a=this.style.zAxis?this.zPoint(a):this.util.snapAngle(a,this.angleSnap/180),this.setPoints([{x:b[0].x,y:b[0].y},{x:a.x,y:a.y}]);this.renderedOnce=!0;this.onRender(this)}}});d.setObject("dojox.drawing.tools.custom.Vector",g);g.setup={name:"dojox.drawing.tools.custom.Vector",tooltip:"Vector Tool",iconClass:"iconVector"};h.zAxisEnabled&&(g.setup.secondary={name:"vectorSecondary",
label:"z-axis",funct:function(a){a.selected?this.zDeselect(a):this.zSelect(a);a=this.drawing.stencils.selectedStencils;for(var b in a)if("vector"==a[b].shortType&&a[b].style.zAxis!=h.zAxis){var c=a[b];c.changeAxis();c.style.zAxis&&(c.deselect(),c.select())}},setup:function(){var a=h.zAxis;this.zSelect=function(b){b.enabled&&(a=!0,h.zAxis=!0,b.select(),this.vectorTest(),this.zSelected=b)};this.zDeselect=function(b){b.enabled&&(a=!1,h.zAxis=!1,b.deselect(),this.vectorTest(),this.zSelected=null)};this.vectorTest=
function(){d.forEach(this.buttons,function(b){"vector"==b.toolType&&b.selected&&(this.drawing.currentStencil.style.zAxis=a)},this)};d.connect(this,"onRenderStencil",this,function(){this.zSelected&&this.zDeselect(this.zSelected)});var b=d.connect(this.drawing,"onSurfaceReady",this,function(){d.disconnect(b);d.connect(this.drawing.stencils,"onSelect",this,function(a){"vector"==a.shortType&&(a.style.zAxis?d.forEach(this.buttons,function(a){"vectorSecondary"==a.toolType&&this.zSelect(a)},this):d.forEach(this.buttons,
function(a){"vectorSecondary"==a.toolType&&this.zDeselect(a)},this))})})},postSetup:function(a){d.connect(a,"enable",function(){h.zAxisEnabled=!0});d.connect(a,"disable",function(){h.zAxisEnabled=!1})}});k.register(g.setup,"tool");return g});