
    ը	fD                         d Z ddlZddlZddlmZ ddlZddlZddlmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ dZ G d de      Zy)a  
@package gcp.mapdisplay

@brief Display to manage ground control points with two toolbars, one
for various display management functions, one for manipulating GCPs.

Classes:
- mapdisplay::MapPanel

(C) 2006-2011 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Markus Metz
    N)	globalvar)
MapToolbar)GCPDisplayToolbarGCPManToolbar)PrintOptions)GMessage)GetImageHandlersImageSizeDialog)SingleMapPanel)Menu)BufferedMapWindowc                       e Zd ZdZ ed      dgdddfdZd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)MapPanelzhMain frame for map display window. Drawing takes place in
    child double buffered drawing window.
    zManage Ground Control PointsgcpdispNGCPMapWindowc           
          t        j                   f||||||d| | _        d j                  _        |D ]  }	 j                  |	         j                  d   j                   _         j                  j                  d        j                  j                   _         j                  j                   _         j                  j                  dd       t        j                   t        j"                  t        j$                  t        j&                  t        j(                  t*        j,                  t*        j.                  g}
 j1                  |
       _         j                  j5                  d       t7          j                  t8        j:                   j                   j                         _         j                  j5                  d       t7          j                  t8        j:                   j                   j                         _         j<                   _          j                   _!         jE                   j<                          jE                   j>                          j<                  jG                  d	        j>                  jG                  d	        j<                  jH                  jK                   fd
        j>                  jH                  jK                   fd        jM                   j                          jM                   j                          jO                         jQ                           j                  jS                  t8        jT                   jV                          jS                  t8        jX                   jZ                          j]                          _/        d j                  _0         j^                  jc                  d        je                           j<                  jg                         \  }} j>                  jg                         \  }}||z   dz  } j                  ji                  d      jk                           j                  jm                           j                  ji                  d      jo                  ||f        j                  ji                  d      jo                  ||f        jp                  r* j                  ji                  d      js                          n j                  ju                  d       tw        jx                         dk7  r j                  jm                          t{          j@                         _>        d _?         j<                   _          j                   _!        i  _@        d j                  d<   d j                  d<   d j                  d<   d j                  d<   d _A        y)ai  Main map display window with toolbars, statusbar and
        DrawWindow

        :param giface: GRASS interface instance
        :param title: window title
        :param toolbars: array of activated toolbars, e.g. ['map', 'digit']
        :param map: instance of render.Map
        :param auimgs: AUI manager
        :param kwargs: wx.Frame attributes
        )parentgifacetitleMapauimgrnameTr   r   g      ?source)r   r   id
propertiesr   targetcrossc                  :     j                   j                        S N)_setActiveMapWindowSrcMapWindowselfs   //usr/lib/grass83/gui/wxpython/gcp/mapdisplay.py<lambda>z#MapPanel.__init__.<locals>.<lambda>       D,,T->->?     c                  :     j                   j                        S r   )r    TgtMapWindowr"   s   r$   r%   z#MapPanel.__init__.<locals>.<lambda>   r&   r'   )r      )d         FWindowsN
attributescategorybarscalelegend)Br   __init___gifacemapWindowPropertiesalignExtent
AddToolbartoolbars	togglemap	activemapSetSelectiongrwizSrcMapTgtMap_mgrSetDockSizeConstraintsbSbCoordinatesSbRegionExtentSbCompRegionExtentSbDisplayGeometry
SbMapScalesbgcp	SbGoToGCP
SbRMSErrorCreateStatusbar	statusbar	SwitchEnvr   wxID_ANYr!   r)   	MapWindowr   _setUpMapWindowSetNamedCursormouseEnteredconnect_initMapGetMapToolbarSelectDefaultBind
EVT_CHOICEOnUpdateActiveEVT_SIZEOnSizeCreateGCPListlistsbItemSetSize	_addPanesGetSizeGetPaneHideUpdateBestSizeshow_targetShowEnableplatformsystemr   printoptdigitdialogsdecorationDialog)r#   r   r   r   r8   r   r   r   kwargstoolbstatusbarItemssrcwidth	srcheighttgtwidth	tgtheights   `              r$   r3   zMapPanel.__init__.   s   , 			
		
 		
 /3  ,
  	#EOOE"	# y1;;##A&jj''jj''		''S1 !!  MMOO
 --n=
 	

X&-<<yy//
 	

X&-<<yy//
 **;;T../T../((1((1&&..?	
 	&&..?	
 	$++&$++&**,
 	BMM4+>+>?		"++t{{+ &&(	 +,  ' 			*%"//779)"//779)x'1,		(#((*				(#,,h	-BC		(#,,h	-BCIIh',,.NN!!%(??	)II
 %T4>>:
 
 **;; %)\"#'Z #'Z !%X $r'   c                      |j                   j                   fd       |j                  j                   fd       |j                  j                   j                         y )Nc                  F     j                         j                  dd      S )NzoombackTenablerU   rh   r"   s   r$   r%   z*MapPanel._setUpMapWindow.<locals>.<lambda>   s     D&&(//
4/H r'   c                  F     j                         j                  dd      S )Nrx   Fry   r{   r"   s   r$   r%   z*MapPanel._setUpMapWindow.<locals>.<lambda>   s     D&&(//
5/I r'   )zoomHistoryAvailablerS   zoomHistoryUnavailablemouseMovingCoordinatesChangedr#   	mapWindows   ` r$   rP   zMapPanel._setUpMapWindow   sQ     	&&..H	
 	((00I	
 	%%d&=&=>r'   c                    |dk(  rJd| j                   vr.t        | | j                  | j                        | j                   d<   | j                  j                  | j                   d   t        j                  j                         j                  d      j                  t        d            j                         j                         j                  d      j                  d      j!                  d      j#                  d      j%                  d      j'                  d      j)                  | j                   d   j+                                      n\|dk(  rVd| j                   vr#t-        | | j                        | j                   d<   | j                  j                  | j                   d   t        j                  j                         j                  d      j                  t        d	            j                         j                         j                  d      j                  d      j!                  d      j#                  d      j%                  d      j'                  d             | j.                  s | j                   d   j1                  d
d       d| j                   vrt3        |       | j                   d<   | j                  j                  | j                   d   t        j                  j                         j                  d      j                  t        d            j                         j                         j5                  d      j                  d      j                  d      j!                  d      j#                  d      j%                  d      j'                  d             | j                  j7                          y)a(  Add defined toolbar to the window

        Currently known toolbars are:
         - 'map'     - basic map toolbar
         - 'vdigit'  - vector digitizer
         - 'gcpdisp' - GCP Manager, Display
         - 'gcpman'  - GCP Manager, points management
         - 'nviz'    - 3D view mode
        map
maptoolbarzMap ToolbarFTr-   r   gcpdisplaytoolbarzGCP Display toolbarzoommenury   gcpmangcpmanagertoolbarzGCP Manager toolbar   N)r8   r   _toolSwitcherr4   r?   AddPanerM   auiAuiPaneInfoNameCaption_ToolbarPaneTopLeftDockableRightDockableBottomDockableTopDockableCloseButtonLayerre   ra   r   rf   rh   r   Rowrd   )r#   r   s     r$   r7   zMapPanel.AddToolbar   s    5=DMM)'1$,,dll(e$ IIe$""$l#=)*e$u%&T"U#q4==/779;" Y-+<T4CUCU+Vi(IIi(""$)*012e$u%&T"U#q ##i(//
5/It}},*7*=h'IIh'""$)*012Qe$u%&T"U#q  			r'   c                    | j                   j                  | j                  t        j                  j                         j                  d      j                  t        d            j                  d      j                  d      j                         j                  d      j                  d      j                  d      j                         j!                  d      j#                  d             | j                   j                  | j$                  t        j                  j                         j                  d      j                  t        d	            j'                  d      j                  d      j                  d      j)                  d      j+                                | j                   j                  | j,                  t        j                  j                         j                  d
      j                  t        d            j'                  d      j                  d      j                  d      j)                  d      j/                         j!                  d             | j1                          y)z5Add mapwindows, toolbars and statusbar to aui managergcplistzGCP ListF)iX     Tr   )r   r+   r   zSource Displayr   zTarget Displayr   N)r?   r   r]   rM   r   r   r   r   r   r   r   	PinButtonFloatingSizer   DestroyOnCloser   r   MinSizer!   Dockable	FloatableCentrer)   RightAddStatusbarPaner"   s    r$   r`   zMapPanel._addPanes/  s   		IIFF T)_WQz]#\% ]5!Y[\*%[^D!SUU1XWZ 	
 			FF T(^WQ'()Xe_[^D!YuVX
	
 			FF T(^WQ'()Xe_[^D!YuUWU1X	
 	r'   c                     | j                         j                  |j                  |j                         |j	                          y)z*
        Update progress bar info
        N)GetProgressBarUpdateProgresslayerr   Skipr#   events     r$   OnUpdateProgresszMapPanel.OnUpdateProgressZ  s.     	,,U[[%))D

r'   c                 z    | j                  |       | j                  j                          |j                          y)zc
        Change choicebook page to match display.
        Or set display for georectifying
        N)	OnPointerrO   SetFocusr   r   s     r$   OnFocuszMapPanel.OnFocusb  s)     	u!

r'   c                 <    | j                   j                  d       y)z"Re-display current map compositionFrenderN)rO   	UpdateMapr   s     r$   OnDrawzMapPanel.OnDrawp  s       .r'   c                 D   | j                   j                  t        j                        }|D ]  }| j                   j	                  |        | j
                  j                  d       | j                  r| j                  j                  d       | j                          y)z*Re-render map composition (each map layer))r   Tr   N)
r   GetListOfLayersr   
QUERYLAYERDeleteLayerr!   r   rf   r)   StatusbarUpdate)r#   r   qlayerr   s       r$   OnRenderzMapPanel.OnRendert  s     ))y/C/C)D 	(EHH  '	( 	##4#0''t'4 	r'   c                     | j                   j                          | j                  j                          | j                   j                  d       | j                  j                  d       y)zPointer button clickedr   N)r!   SetModePointerr)   rQ   r   s     r$   r   zMapPanel.OnPointer  sN    ((*((*((1((1r'   c                 l    | j                   j                          | j                  j                          y)zZoom in the map.N)r!   SetModeZoomInr)   r   s     r$   OnZoomInzMapPanel.OnZoomIn  s&    '')'')r'   c                 l    | j                   j                          | j                  j                          y)zZoom out the map.N)r!   SetModeZoomOutr)   r   s     r$   	OnZoomOutzMapPanel.OnZoomOut  s&    ((*((*r'   c                 l    | j                   j                          | j                  j                          y)zPanning, set mouse to dragN)r!   
SetModePanr)   r   s     r$   OnPanzMapPanel.OnPan  s&    $$&$$&r'   c                     | j                   j                          | j                   | j                  k(  r| j                  }n%| j                   | j                  k(  r| j                  }j                          y)z"
        Erase the canvas
        N)rO   EraseMapr!   r)   )r#   r   wins      r$   OnErasezMapPanel.OnErase  sW     	!>>T...##C^^t000##Cr'   c                 z   | j                   j                  }|st        | t        d             yt	        |      \  }}t        |       }|j                          |j                         t        j                  k7  r|j                          y|j                         \  }}|j                          t        j                  | t        d      |t        j                  t        j                  z        }|j                         t        j                  k(  r|j                         }|s|j                          yt         j"                  j%                  |      \  }	}
||j'                            d   }||j'                            d   }|
|k7  r|	dz   |z   }| j                   j)                  ||||       |j                          y)	zSave map to imagez2Nothing to render (empty map). Operation canceled.)r   messageNz?Choose a file name to save the image (no need to add extension))r   r   wildcardstyletypeext.)rO   imgr   r   r	   r
   CentreOnParent	ShowModalrM   ID_OKDestroy	GetValues
FileDialogFD_SAVEFD_OVERWRITE_PROMPTGetPathospathsplitextGetFilterIndex
SaveToFile)r#   r   r   filetypeltypedlgwidthheightr   baser   fileTypeextTypes                r$   r   zMapPanel.SaveToFile  sj   nn  NO *3/% d#==?bhh&KKMv mmT **r555
 ==?bhh&;;=D((.ID#S//126:HC..01%8Gg~czG+NN%%dHeVDr'   c                 :   t        j                         }t               }t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  j                  |       | j                  |       |j                          y)z?
        Print options and output menu for map display
        z
Page setupzPrint previewzPrint displayN)rM   GetMousePositionr   MenuItemrN   r   
AppendItemrW   EVT_MENUrk   OnPageSetupOnPrintPreview	OnDoPrint	PopupMenur   )r#   r   point	printmenusetuppreviewdoprints          r$   	PrintMenuzMapPanel.PrintMenu  s    ##%F	Iryy!L/BU#		"++t}}88%@++iAo4FGW%		"++t}};;WE++iAo4FGW%		"++t}}66@ 	y!r'   c                 <    | j                   j                  d       y)zQ
        Set display extents to match selected raster map (ignore NULLs)
        T)ignoreNullsN)rO   	ZoomToMapr   s     r$   OnZoomToRasterzMapPanel.OnZoomToRaster  s     	  T 2r'   c                 <    | j                   j                  d       y)zKSet display geometry to match extents in
        saved region file
        T)zoomOnlyN)rO   	SetRegionr   s     r$   OnZoomToSavedzMapPanel.OnZoomToSaved  s     	  $ /r'   c                 8    | j                   j                          y)zNSet computational region (WIND file) to match display
        extents
        N)rO   DisplayToWindr   s     r$   OnDisplayToWindzMapPanel.OnDisplayToWind  s     	$$&r'   c                 8    | j                   j                          y)z*Save display extents to named region file.N)rO   SaveDisplayRegionr   s     r$   r  zMapPanel.SaveDisplayRegion  s    ((*r'   c                    t        j                         }t               }t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  |       t        j                  |t         j                  t        d            }|j                  |       | j                  t         j                  | j                  |       | j                  |       |j                          y)zPopup Zoom menuz0Zoom to computational region (set with g.region)zZoom to default regionzZoom to saved regionz%Set computational region from displayz%Save display geometry to named regionN)rM   r   r   r   rN   r   r   rW   r   OnZoomToWindOnZoomToDefaultr  r  r  r   r   )	r#   r   r   r   zoomwindzoomdefault	zoomsavedsavewindsavezooms	            r$   
OnZoomMenuzMapPanel.OnZoomMenu  s   ##%6 ;;bii#U!V
 	H%		"++t00(;kk(BIIq9Q7RSK(		"++t33[AKK"))Q7M5NO	I&		"++t119=;;bii#J!K
 	H%		"++t33X>;;bii#J!K
 	H%		"++t55x@ 	x r'   c                     | j                   S r   )r!   r"   s    r$   GetSrcWindowzMapPanel.GetSrcWindow(         r'   c                     | j                   S r   )r)   r"   s    r$   GetTgtWindowzMapPanel.GetTgtWindow+  r  r'   c                     | j                   S r   )rf   r"   s    r$   GetShowTargetzMapPanel.GetShowTarget.  s    r'   c                      | j                   d   S )z"Returns toolbar with zooming toolsr   )r8   r"   s    r$   rU   zMapPanel.GetMapToolbar1  s    }}Y''r'   c                     | j                   |k(  s:|| _         |j                  | _        | j                  |       | j                          y y r   )rO   r   UpdateActiver   r   s     r$   r    zMapPanel._setActiveMapWindow5  s<    ~~*&DN }}DHi(MMO +r'   )__name__
__module____qualname____doc__r   r3   rP   r7   r`   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  rU   r     r'   r$   r   r   )   s     ./g%R	?KZ) V/2*
+
'
,\030'+#J!! (r'   r   ) r  r   ri   corer   rM   wx.auimapdisp.toolbarsr   gcp.toolbarsr   r   mapdisp.gprintr   	core.gcmdr   gui_core.dialogsr	   r
   gui_core.mapdispr   gui_core.wrapr   mapwin.bufferedr   mapdisp.statusbarrK   rA   gcp.statusbarrG   cmdfilenamer   r  r'   r$   <module>r-     sN   " 
   	  ' 9 '  > +  -   R~ Rr'   