/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/toolbars/_VertexMover",["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/has","dojo/sniff","dojo/dom-style","dojox/gfx/Moveable","esri/kernel","esri/geometry/Point","esri/graphic","esri/geometry/webMercatorUtils"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b){var VM=_1(null,{declaredClass:"esri.toolbars.VertexMover",constructor:function(_c,_d,_e,_f,_10,_11,_12,_13){this.point=_c;this.symbol=_d;this.relatedGraphic=_e;this.segIndex=_f;this.ptIndex=_10;this.segLength=_11;this.editor=_12;this.map=_12.map;this._scratchGL=_12.toolbar._scratchGL;this._placeholder=_13||false;this._type=_e.geometry.type;this._init();this._enable();},refresh:function(_14){if(_14||this._needRefresh()){this._disable();this._enable();}},destroy:function(){this._disable();if(this.graphic){this._scratchGL.remove(this.graphic);}this.point=this.symbol=this.graphic=this.relatedGraphic=this.segIndex=this.ptIndex=this.segLength=this.editor=this.map=this._scratchGL=null;},_init:function(){var _15=new _9(this.point.toJson());var _16=new _a(_15,this.symbol);switch(this._type){case "multipoint":_16._shape=this.relatedGraphic.getDojoShape().children[this.ptIndex];break;case "polyline":case "polygon":this._scratchGL.add(_16);break;}this.graphic=_16;},_enable:function(){var _17=this.graphic.getDojoShape();if(_17){_17._hasMover=true;this._moveable=this._getMoveable(_17);var _18=_17.getEventSource();if(_18){_6.set(_18,"cursor",this.editor.toolbar._cursors[this._placeholder?"move-gv":"move-v"]);}}},_disable:function(){var _19=this._moveable;if(_19){_3.disconnect(this._startHandle);_3.disconnect(this._firstHandle);_3.disconnect(this._movingHandle);_3.disconnect(this._stopHandle);var _1a=_19.shape;if(_1a){var _1b=_1a.getEventSource();if(_1b){_6.set(_1b,"cursor",null);}}_19.destroy();this._moveable=null;}},_needRefresh:function(){var _1c=this.graphic.getDojoShape(),_1d=false;if(_1c){switch(this._type){case "multipoint":var _1e=this.relatedGraphic.getDojoShape();if(_1e){var _1f=_1e.children[this.ptIndex];if(_1c!==_1f){_1c=_1f;this.graphic._shape=_1c;_1d=true;}}break;case "polyline":case "polygon":_1d=!_1c._hasMover;break;}}return _1d;},_getMoveable:function(_20){var _21=new _7(_20,_5("mac")&&_5("ff")&&!_4("esri-touch")&&{leftButtonOnly:true});this._startHandle=_3.connect(_21,"onMoveStart",this,this._moveStartHandler);this._firstHandle=_3.connect(_21,"onFirstMove",this,this._firstMoveHandler);this._movingHandle=_3.connect(_21,"onMoving",this,this._movingHandler);this._stopHandle=_3.connect(_21,"onMoveStop",this,this._moveStopHandler);return _21;},_getPtIndex:function(){return this.ptIndex+(this._placeholder?1:0);},_getInfo:function(){return {graphic:this.graphic,isGhost:this._placeholder,segmentIndex:this.segIndex,pointIndex:this._getPtIndex()};},_moveStartHandler:function(_22){var map=this.map;if(map.snappingManager){map.snappingManager._setUpSnapping();}_22.shape.moveToFront();this.constructor.onMoveStart(this);this.editor.toolbar.onVertexMoveStart(this.relatedGraphic,this._getInfo());},_firstMoveHandler:function(_23){var _24=_23.shape;var _25=this._getControlEdges();var _26=this._scratchGL._div;var i,_27=[],_28=_23.host.shape._wrapOffsets[0]||0;for(i=0;i<_25.length;i++){var _29=_25[i];_29.x1+=_28;_29.x2+=_28;_27.push([_26.createLine({x1:_29.x1,y1:_29.y1,x2:_29.x2,y2:_29.y2}).setStroke(this.editor._lineStroke),_29.x1,_29.y1,_29.x2,_29.y2]);}_24._lines=_27;_23.shape.moveToFront();this.constructor.onFirstMove(this);this.editor.toolbar.onVertexFirstMove(this.relatedGraphic,this._getInfo());},_movingHandler:function(_2a){var _2b=_2a.shape,tx=_2b.getTransform();var i,_2c=_2b._lines;for(i=0;i<_2c.length;i++){var _2d=_2c[i];_2d[0].setShape({x1:_2d[1]+tx.dx,y1:_2d[2]+tx.dy,x2:_2d[3],y2:_2d[4]});}this.editor.toolbar.onVertexMove(this.relatedGraphic,this._getInfo(),tx);},_moveStopHandler:function(_2e){var _2f=_2e.shape,_30=this.editor.toolbar,tx=_2f.getTransform(),map=this.map,_31=this.graphic,_32=_30._geo?_b.geographicToWebMercator(_31.geometry):_31.geometry;var i,_33=_2f._lines;if(_33){for(i=0;i<_33.length;i++){_33[i][0].removeShape();}_2f._lines=null;}var ph=false,_34=true,_35=this._getInfo();if(tx&&(tx.dx||tx.dy)){if(this._placeholder){this._placeholder=false;ph=true;}}else{_34=false;}var _36;if(map.snappingManager){_36=map.snappingManager._snappingPoint;}var _37=_36||map.toMap(map.toScreen(_32).offset(tx.dx,tx.dy));if(map.snappingManager){map.snappingManager._killOffSnapping();}_2f.setTransform(null);_31.setGeometry(_30._geo?_b.webMercatorToGeographic(_37,true):_37);this.constructor.onMoveStop(this,tx);_30.onVertexMoveStop(this.relatedGraphic,_35,tx);if(!_34){_30.onVertexClick(this.relatedGraphic,_35);}if(ph){_30.onVertexAdd(this.relatedGraphic,this._getInfo());}},_getControlEdges:function(){var map=this.map;var _38=this.relatedGraphic.geometry;var _39=this.segIndex,_3a=this.ptIndex,_3b=this.segLength;var _3c=this._scratchGL._div;var _3d=_3c.getTransform();var sdx=_3d.dx,sdy=_3d.dy;var pt=map.toScreen(this.graphic.geometry);var x=pt.x-sdx,y=pt.y-sdy;var _3e=[];var _3f=this.editor._getControlPoints(this,_38,_39,_3a,_3b);if(_3f[0]){_3e.push({x1:x,y1:y,x2:_3f[0].x-sdx,y2:_3f[0].y-sdy});}if(_3f[1]){_3e.push({x1:x,y1:y,x2:_3f[1].x-sdx,y2:_3f[1].y-sdy});}return _3e;}});if(_4("extend-esri")){_2.setObject("toolbars.VertexMover",VM,_8);}_2.mixin(VM,{onMoveStart:function(){},onFirstMove:function(){},onMoveStop:function(){}});return VM;});