/*
 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/edit",["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/_base/array","dojo/_base/Color","dojo/has","esri/kernel","esri/lang","esri/sniff","esri/toolbars/_toolbar","esri/toolbars/_Box","esri/toolbars/_GraphicMover","esri/toolbars/_VertexEditor","esri/symbols/SimpleMarkerSymbol","esri/symbols/SimpleLineSymbol"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f){var EDT=_1(_a,{declaredClass:"esri.toolbars.Edit",constructor:function(map,_10){this._map=map;this._tool=0;if(this._map.loaded){this._scratchGL=map.graphics;}else{var _11=_3.connect(this._map,"onLoad",this,function(){_3.disconnect(_11);_11=null;this._scratchGL=this._map.graphics;});}var _12=_6("esri-touch")||_6("esri-pointer");this._defaultOptions=_2.mixin({vertexSymbol:new _e(_e.STYLE_CIRCLE,_12?20:12,new _f(_f.STYLE_SOLID,new _5([0,0,0,0.5]),1),new _5([128,128,128])),ghostVertexSymbol:new _e(_e.STYLE_CIRCLE,_12?18:10,new _f(_f.STYLE_SOLID,new _5([0,0,0,0.5]),1),new _5([255,255,255,0.75])),ghostLineSymbol:new _f(_f.STYLE_DOT,new _5([128,128,128]),2),allowDeleteVertices:true,allowAddVertices:true,rotateHandleOffset:_12?24:16,boxLineSymbol:new _f(_f.STYLE_DASH,new _5([64,64,64]),1),boxHandleSymbol:new _e(_e.STYLE_SQUARE,_12?16:9,new _f(_f.STYLE_SOLID,new _5([0,0,0,0.5]),1),new _5([255,255,255,0.75]))},_10||{});},activate:function(_13,_14,_15){this.deactivate();this._graphic=_14;this._options=_2.mixin(_2.mixin({},this._defaultOptions),_15||{});var _16=EDT.MOVE,_17=EDT.EDIT_VERTICES,_18=EDT.SCALE,_19=EDT.ROTATE,_1a=false,_1b=false,box=false,map=this._map,_1c=map.spatialReference,_1d=_14.geometry.spatialReference;this._geo=!!(_1c&&_1d&&!_1c.equals(_1d)&&_1c.isWebMercator()&&_1d.wkid===4326);if((_13&_16)===_16){_1a=this._enableMove(_14);}var _1e=((_13&_18)===_18),_1f=((_13&_19)===_19);if(_1e||_1f){box=this._enableBoxEditing(_14,_1e,_1f);}if((_13&_17)===_17){_1b=this._enableVertexEditing(_14);}if(!(_1a||_1b||box)){throw new Error("[esri.toolbars.Edit::activate] Unable to activate the tool. Check if the tool is valid for the given geometry type.");}this._tool=_13;if(this._tool){this._mapPanEndHandle=_3.connect(map,"onPanEnd",this,this._mapPanEndHandler);this._mapExtChgHandle=_3.connect(map,"onExtentChange",this,this._mapExtentChangeHandler);this.onActivate(this._tool,_14);}if(map.snappingManager&&(_1a||_1b)){map.snappingManager._startSelectionLayerQuery();}},deactivate:function(){var _20=this._tool,_21=this._graphic;if(!_20){return;}var _22=!!this._modified;this._clear();_3.disconnect(this._mapPanEndHandle);_3.disconnect(this._mapExtChgHandle);this._mapPanEndHandle=this._mapExtChgHandle=null;this._graphic=this._geo=null;this.onDeactivate(_20,_21,{isModified:_22});if(this._map.snappingManager){this._map.snappingManager._stopSelectionLayerQuery();}},refresh:function(){this._refreshMoveables(true);},getCurrentState:function(){return {tool:this._tool,graphic:this._graphic,isModified:!!this._modified};},onActivate:function(_23,_24){},onDeactivate:function(_25,_26,_27){},onGraphicMoveStart:function(_28){},onGraphicFirstMove:function(_29){this._modified=true;},onGraphicMove:function(_2a,_2b){},onGraphicMoveStop:function(_2c,_2d){},onGraphicClick:function(_2e,_2f){},onVertexMoveStart:function(_30,_31){},onVertexFirstMove:function(_32,_33){this._modified=true;},onVertexMove:function(_34,_35,_36){},onVertexMoveStop:function(_37,_38,_39){},onVertexAdd:function(_3a,_3b){this._modified=true;},onVertexClick:function(_3c,_3d){},onVertexMouseOver:function(_3e,_3f){},onVertexMouseOut:function(_40,_41){},onVertexDelete:function(_42,_43){this._modified=true;},onScaleStart:function(_44){},onScaleFirstMove:function(_45){this._modified=true;},onScale:function(_46,_47){},onScaleStop:function(_48,_49){},onRotateStart:function(_4a){},onRotateFirstMove:function(_4b){this._modified=true;},onRotate:function(_4c,_4d){},onRotateStop:function(_4e,_4f){},_eventMap:{activate:["tool","graphic"],deactivate:["tool","graphic","info"],"graphic-move-start":["graphic"],"graphic-first-move":["graphic"],"graphic-move":["graphic","transform"],"graphic-move-stop":["graphic","transform"],"graphic-click":["graphic","info"],"vertex-move-start":["graphic","vertexinfo"],"vertex-first-move":["graphic","vertexinfo"],"vertex-move":["graphic","vertexinfo","transform"],"vertex-move-stop":["graphic","vertexinfo","transform"],"vertex-add":["graphic","vertexinfo"],"vertex-click":["graphic","vertexinfo"],"vertex-mouse-over":["graphic","vertexinfo"],"vertex-mouse-out":["graphic","vertexinfo"],"vertex-delete":["graphic","vertexinfo"],"scale-start":["graphic"],"scale-first-move":["graphic"],scale:["graphic","info"],"scale-stop":["graphic","info"],"rotate-start":["graphic"],"rotate-first-move":["graphic"],rotate:["graphic","info"],"rotate-stop":["graphic","info"]},_enableMove:function(_50){var map=this._map,_51=_50.geometry.type;switch(_51){case "point":case "polyline":case "polygon":this._graphicMover=new _c(_50,map,this);return true;case "multipoint":break;}return false;},_enableVertexEditing:function(_52){var map=this._map,_53=_52.geometry.type;switch(_53){case "point":break;case "multipoint":case "polyline":case "polygon":this._vertexEditor=_d.create(_52,map,this);return true;}return false;},_enableBoxEditing:function(_54,_55,_56){var map=this._map,_57=_54.geometry.type;switch(_57){case "point":case "multipoint":break;case "polyline":case "polygon":this._boxEditor=new _b(_54,map,this,_55,_56,this._options.uniformScaling);return true;}return false;},_disableMove:function(){var _58=this._graphicMover;if(_58){_58.destroy();this._graphicMover=null;}},_disableVertexEditing:function(){var _59=this._vertexEditor;if(_59){_59.destroy();this._vertexEditor=null;}},_disableBoxEditing:function(){var box=this._boxEditor;if(box){box.destroy();this._boxEditor=null;}},_clear:function(){this._disableMove();this._disableVertexEditing();this._disableBoxEditing();this._tool=0;this._modified=false;},_mapPanEndHandler:function(){this._refreshMoveables();},_mapExtentChangeHandler:function(e,d,_5a){if(_5a){this._refreshMoveables();}},_refreshMoveables:function(_5b){var _5c=_4.filter([this._graphicMover,this._vertexEditor,this._boxEditor],_8.isDefined);_4.forEach(_5c,function(mov){mov.refresh(_5b);});},_beginOperation:function(_5d){_4.forEach(this._getAffectedTools(_5d),function(_5e){_5e.suspend();});},_endOperation:function(_5f){_4.forEach(this._getAffectedTools(_5f),function(_60){_60.resume();});},_getAffectedTools:function(_61){var _62=[];switch(_61){case "MOVE":_62=[this._vertexEditor,this._boxEditor];break;case "VERTICES":_62=[this._boxEditor];break;case "BOX":_62=[this._vertexEditor];break;}_62=_4.filter(_62,_8.isDefined);return _62;}});_2.mixin(EDT,{MOVE:1,EDIT_VERTICES:2,SCALE:4,ROTATE:8});if(_6("extend-esri")){_2.setObject("toolbars.Edit",EDT,_7);}return EDT;});