//>>built
define("dojox/drawing/tools/custom/Vector",["dojo","../../util/oo","../../manager/_registry","../Arrow","../../defaults"],function(e,g,m,n,h){g=g.declare(n,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 d="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(d);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,d=a.x,f=a.y;this.keys.shift&&!this.style.zAxis&&(f=this.util.snapAngle(a,.25),d=f.x,f=f.y);if(this.keys.alt){var k=d>b?(d-b)/2:(b-d)/-2,l=f>c?(f-c)/2:(c-f)/-2;b-=k;d-=k;c-=l;f-=l}this.style.zAxis&&(a=this.zPoint(a),d=a.x,f=a.y);this.setPoints([{x:b,y:c},{x:d,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,d=0>a?a>-b:a<-b;return{x:d?a:-b/Math.tan(c),y:d?-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)}}});e.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(c){c.enabled&&(a=!0,h.zAxis=!0,c.select(),this.vectorTest(),this.zSelected=c)};this.zDeselect=function(c){c.enabled&&(a=!1,h.zAxis=!1,c.deselect(),this.vectorTest(),this.zSelected=null)};this.vectorTest=
function(){e.forEach(this.buttons,function(c){"vector"==c.toolType&&c.selected&&(this.drawing.currentStencil.style.zAxis=a)},this)};e.connect(this,"onRenderStencil",this,function(){this.zSelected&&this.zDeselect(this.zSelected)});var b=e.connect(this.drawing,"onSurfaceReady",this,function(){e.disconnect(b);e.connect(this.drawing.stencils,"onSelect",this,function(c){"vector"==c.shortType&&(c.style.zAxis?e.forEach(this.buttons,function(d){"vectorSecondary"==d.toolType&&this.zSelect(d)},this):e.forEach(this.buttons,
function(d){"vectorSecondary"==d.toolType&&this.zDeselect(d)},this))})})},postSetup:function(a){e.connect(a,"enable",function(){h.zAxisEnabled=!0});e.connect(a,"disable",function(){h.zAxisEnabled=!1})}});m.register(g.setup,"tool");return g});