
    ը	fU              
       Z   d Z ddlZddlZddlZddlmZ ddlmc 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  ed ed             ed ed            ed    ed ed             ed ed            ed   dZ G d dej:                        Zy)ae  
@package wxplot.base

@brief Base classes for iinteractive plotting using PyPlot

Classes:
 - base::PlotIcons
 - base::BasePlotFrame

(C) 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 Michael Barton, Arizona State University
    N)randint)ICONDIR)UserSettings)
TextDialog	OptDialog)Map)MetaIcon)	BaseIcons)MenushowzDraw/re-draw plot)imglabelzlayer-raster-profilez.Draw transect in map display window to profilesettingsstatszPlot statisticssavezSave profile data to CSV filequit)drawtransectoptions
statisticsr   r   c                       e Zd ZdZdd ej
                  dd      ej                  g 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d Z d Z!y) BasePlotFramez#Abstract PyPlot display frame classNi  i  c                    t        j                  j                  | |ft         j                  ||d| || _        || _        t               | _        || _        i | _        d| _	        t         j                  t         j                  t         j                  t         j                  t         j                  d| _        t         j                   t         j                  d| _        | j%                  t        j&                  t(        j*                  j-                  t.        d      t         j0                               | j3                  dd      | _        | j4                  j7                  d	d
g       t9        j:                  |       | _        | j>                  | j<                  _         | j<                  jB                  jE                  t         jF                  | jH                         | j<                  jB                  jE                  t         jJ                  | jL                         g | _'        d | _        d| _(        d| _)        d| _*        | jW                          | jY                          y )N)idsizestyle )soliddotz	long-dashz
short-dashzdot-dash)transparentr   z	grass.ico   r   )numberr   )-wxFrame__init__ID_ANYparent_gifacer   
rasterListrasterplottypeSOLIDDOT	LONG_DASH
SHORT_DASHDOT_DASHlinestyledictTRANSPARENT
ptfilldictSetIconIconospathjoinr   BITMAP_TYPE_ICOCreateStatusBar	statusbarSetStatusWidthsplot
PlotCanvasclientDrawPointLabelpointLabelFunccanvasBindEVT_LEFT_DOWNOnMouseLeftDown
EVT_MOTIONOnMotionplotlistptitlexlabelylabelCentreOnScreen_createColorDict)selfr)   gifacer   r   r+   kwargss          ,/usr/lib/grass83/gui/wxpython/wxplot/base.pyr'   zBasePlotFrame.__init__3   s    	$W2994uWPVW5$ XX66--
 +-..288L
 	RWWRWW\\';?ASASTU
 --Qa-@&&Bx0 ood+ &*%8%8" 	 0 0$2F2FG 	t}}=	    c                 `   i | _         t        j                  t        j                        D ]  }|dk(  r	t        t        j                  |   d   dz        }t        t        j                  |   d   dz        }t        t        j                  |   d   dz        }|||df| j                   |<    y)zkCreate color dictionary to return wx.Colour tuples
        for assigning colors to images in imagery groupswhiter         r!   N)	colorDictsixiterkeysgrassnamed_colorsint)rP   clrrgbs        rS   rO   zBasePlotFrame._createColorDicts   s     << 2 23 	1Cg~E&&s+A.45AE&&s+A.45AE&&s+A.45A#$aC.DNN3	1rT   c                    || _         i | _        i | j                  d<   t        j                  | j                   d      | j                  d   d<   t	        j
                  | j                  d   d   d   | j                  d   d   d   | j                  d   d   d   | j                  d   d   d         | _        i | j                  d<   t        j                  | j                   d      | j                  d<   t        | j                  d   d	         }t        d
 |j                  d      j                  d      D              | j                  d   d	<   | j                   dk(  rt        j                  | j                   d      | j                  d<   t        | j                  d   d         }t        d |j                  d      j                  d      D              | j                  d   d<   t        j                  | j                   d      | j                  d<   t        | j                  d   d         }t        d |j                  d      j                  d      D              | j                  d   d<   i | j                  d<   t        j                  | j                   d      | j                  d   d<   d| j                  d   d<   i | j                  d<   t        j                  | j                   d      | j                  d   d<   d| j                  d   d<   t        j                  | j                   d      | j                  d<   d| _        d| _        d| j                  _        | j                  d   d   d   dk(  rd| j                  _        n$| j                  d   d   d   | j                  _        | j                  d   d   d   dk(  rd| j                  _        y| j                  d   d   d   | j                  _        y)z"Initialize options for entire plotfontgroupkeypropdefaultSizefamilyr   weightr,   pcolorc              3   2   K   | ]  }t        |        y wNr^   .0colvals     rS   	<genexpr>z-BasePlotFrame.InitPlotOpts.<locals>.<genexpr>   s      4
"CK4
   z(),profilemarkercolorc              3   2   K   | ]  }t        |        y wrn   ro   rp   s     rS   rs   z-BasePlotFrame.InitPlotOpts.<locals>.<genexpr>   s      7 &F7rt   gridc              3   2   K   | ]  }t        |        y wrn   ro   rp   s     rS   rs   z-BasePlotFrame.InitPlotOpts.<locals>.<genexpr>   s      1
"CK1
rt   x-axisNaxisy-axislegendF)FFtypecustommin)r-   
propertiesr   Getr%   Fontwx_fontstrtuplestripsplitzoomdragrA   logScalexSpecySpec)rP   r-   colstrs      rS   InitPlotOptszBasePlotFrame.InitPlotOpts   s    "$*6*:*:--V+
' wwOOF#F+M:OOF#F+H5OOF#F+G4OOF#F+H5	
 %'!$0$4$44==h$W!T__X.x89.3 4
&,ll4&8&>&>s&C4
 /
!(+ ==I%(4(8(8mm)DOOH% 27;<F16 7*0,,t*<*B*B3*G7 2DOOH%g. #/"2"2F"ST__V,W56+0 1
&,ll4&8&>&>s&C1
 ,
( %'!,8,<,<--X-
!&) -1!&)$&!,8,<,<--X-
!&) -1!&)$0$4$44==h$W!		  .??8$V,V4@ %DKK $ 9& A& IDKK??8$V,V4@ %DKK $ 9& A& IDKKrT   c                 
   i }t        j                  | j                  d      | j                  d<   |D ]  }|j	                  |      }	 t        j                  |      }| j                  d   | j                  |<   i ||<   d||   d<   |d   dvr|d   ||   d<   |||   d<   g ||   d<   d||   d	<   |d
   ||   d
<   | j                  d   d   | j                  d   d   ||   d<   nd||   d<   | j                  d   d   .| j                  d   d   dk7  r| j                  d   d   ||   d<   nd||   d<   |t        | j                        k  ry|dk(  rP| j                  d   d   | j                  d   d   ||   d<   M| j                  | j                  |      ||   d<   q| j                  | j                  |      ||   d<   t        dd      }t        dd      }t        dd      }|||df||   d<    |S #  Y xY w)z3Initialize or update raster dictionary for plottingr,   re   r   unitsz(none)z"none"r   NplegenddatalistNplinedatatypepwidthrX   pstyler   r   rl   rW   )r   r   r-   r   indexr\   raster_infor,   len	colorListrY   r   )	rP   r+   r-   rdictr`   idxretrb   ra   s	            rS   InitRasterOptszBasePlotFrame.InitRasterOpts   sO    $0$4$44==h$W! 3	4A""1%C''*
 "__X6DKKNE!H "E!HW7|#AA$'La!"#E!HY#%E!HZ  $E!HW#&z?E!HZ 
 x(2>%)__X%>x%Ha"%&a" )(3?OOH-h72=%)__X%>x%Ha"%,a"S((!8x0:F-1__X-Fx-Pa*-1^^DNN3<O-Pa*)-s8K)LE!HX&AsOAsOAsO&'As^a"g3	4j as   	G==Hc                    t        |      dk(  ryi }|D ]I  }|j                  |      }	 t        j                  |d         }t        j                  |d         }t	        j
                  |d      | j                  |<   i ||<   i ||   d<   i ||   d<   d||   d   d<   d||   d   d<   |d   dvr|d   ||   d   d<   |d   dvr|d   ||   d   d<   |d   j                  d	      d   d
z   |d   j                  d	      d   z   ||   d<   g ||   d<   |d   ||   d   d<   |d   ||   d   d<   | j                  d   d   .| j                  d   d   dk7  r| j                  d   d   ||   d<   nd||   d<   | j                  d   d   | j                  d   d   ||   d<   nd||   d<   | j                  d   d   .| j                  d   d   dk7  r| j                  d   d   ||   d<   nd||   d<   |t        | j                        k  r$| j                  | j                  |      ||   d<   t        dd      }t        dd      }	t        dd      }
||
|	df||   d<   L |S #  Y TxY w)zdInitialize or update raster dictionary with raster pairs for
        bivariate scatterplots
        r   NrX   rastersre   r   r   r   @z vs r   r   r   r,   ptyper   psizepfillr   rl   rW   )r   r   r\   r   r   r   r,   r   r   r   rY   r   )rP   r+   r-   r   rpairr   ret0ret1r`   rb   ra   s              rS   InitRasterPairszBasePlotFrame.InitRasterPairs  s   
 z?a >	8E""5)C((q2((q2 ".!1!1I"DKK E%L E%LO E%LO')E%LOG$')E%LOG$G}$BB+/=eQ(G}$BB+/=eQ( as#A&/%(..2Ea2HH %L# (*E%L$*.z*:E%LOJ'*.z*:E%LOJ' )'2>OOH-g6"<(,(A'(JeW%(-eW%x(1=(,(A'(JeW%()eW%)'2>OOH-g6"<(,(A'(JeW%(/eW%c$..)))-s8K)LeX&AsOAsOAsO*+Q3eX&}>	8@ ss   0I##I(c                    | j                   j                  | j                         | j                  d   d   d   | j                   _        | j                  d   d   d   | j                   _        | j                  | j                   _        | j                  | j                   _	        | j                  d   d   d   dk(  rd| j                   _
        n$| j                  d   d   d   | j                   _
        | j                  d	   d   d   dk(  rd| j                   _        n$| j                  d	   d   d   | j                   _        | j                  d   d   d   dk(  rf| j                  d   d   d   | j                  d   d   d
   k  r;| j                  d   d   d   | j                  d   d   d
   f| j                  d   d<   nd| j                  d   d<   | j                  d	   d   d   dk(  rf| j                  d	   d   d   | j                  d	   d   d
   k  r;| j                  d	   d   d   | j                  d	   d   d
   f| j                  d	   d<   nd| j                  d	   d<   | j                  d   d   d   r#d| j                  d   d<   d| j                   _
        | j                  d	   d   d   r#d| j                  d	   d<   d| j                   _        | j                  d   d   d   | j                  d	   d   d   f| j                   _        | j                  d   d   | j                   _        t        j                  t        j                   | j                  d   d   d   | j                  d   d   d   | j                  d   d   d   d            }|| j                   _        | j                  d   d   d   | j                   _        | j                  d   d   | j                   _        y)zSet plot and text optionsrd   rh   	titleSizeaxisSizer|   r   r   r   r~   maxr}   Nlogrz   enabledrx   r   rX   r!   rW   )colour
legendSizer   )rA   SetFontr   r   fontSizeTitlefontSizeAxisr   
enableZoomr   
enableDragr   r   r   
enableGridr%   PenColourgridPenfontSizeLegendenableLegend)rP   gridpens     rS   SetGraphStylezBasePlotFrame.SetGraphStyleM  s   DLL)$(OOF$;F$CK$P!#'??6#:6#B:#N !%!%
 ??8$V,V4@ %DKK $ 9& A& IDKK??8$V,V4@ %DKK $ 9& A& IDKK OOH%f-f5A)&1%8ooh'/67 )&1%8)&1%81DOOH%f-
 15DOOH%f- OOH%f-f5A)&1%8ooh'/67 )&1%8)&1%81DOOH%f-
 15DOOH%f-??8$V,U304DOOH%f- %DKK??8$V,U304DOOH%f- %DKK OOH%f-e4OOH%f-e4 
 "&!8!C&&99'03'03'03	
 &
 &*__V%<V%D\%R"#'??8#<Y#G rT   c                 >   | j                         \  }}t        j                  || j                  ||      | _        | j                  d   d   d   dk(  rd| j
                  _        n$| j                  d   d   d   | j
                  _        | j                  d   d   d   dk(  rd| j
                  _        n$| j                  d   d   d   | j
                  _        | j
                  j                  | j                  | j                  d   d   | j                  d   d          y)	z1Draw line and point plot from list plot elements.r|   rh   r   r   r   r~   r}   N)	_getPlotLabelsr?   PlotGraphicsrK   r   rA   r   r   Draw)rP   rJ   rL   rM   s       rS   DrawPlotzBasePlotFrame.DrawPlot  s    ,,.%%hVVL	??8$V,V4@ %DKK $ 9& A& IDKK??8$V,V4@ %DKK $ 9& A& IDKKIIOOH%f-OOH%f-	
rT   c                    |j                  t        j                  t        j                               |j	                  t        j
                  t        j                  t        j                               |d   \  }}|j                  |dz
  |dz
  dd       |d   \  }}|d   }|d   }|d   }	d||	|||fz  }
|j                  |
||d	z          y
)ak  This is the function that defines how the pointLabels are
        plotted dc - DC that will be passed mDataDict - Dictionary
        of data that you want to use for the pointLabel

        As an example I have decided I want a box at the curve
        point with some text information about the curve plotted
        below.  Any wxDC method can be used.
        scaledXY   
   pointXYcurveNumpIndexr   z(Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %irX   N)	SetPenr%   r   BLACKSetBrushBrushr.   DrawRectangleDrawText)rP   dc	mDataDictsxsypxpycNumpntInr   ss              rS   rB   zBasePlotFrame.DrawPointLabel  s     			"&&"#
BHHRXXrxx01:&B
aaR09%B$(#8$6$BPU9VV
Ar26"rT   c                     d| _         d| _        | j                   | j                  _        | j                  | j                  _        y)z#Enable zooming and disable draggingTFN)r   r   rA   r   r   rP   events     rS   OnZoomzBasePlotFrame.OnZoom  s0    		!%!%rT   c                     d| _         d| _        | j                  | j                  _        | j                   | j                  _        y)z#Enable dragging and disable zoomingFTN)r   r   rA   r   r   r   s     rS   OnDragzBasePlotFrame.OnDrag  s0    		!%!%rT   c                     | j                          | j                  j                          | j                  j                          y)z/Redraw the plot window. Unzoom to original sizeN)UpdateLabelsrA   ResetRedrawr   s     rS   OnRedrawzBasePlotFrame.OnRedraw  s.    rT   c                 8    | j                   j                          y)zErase the plot windowN)rA   Clearr   s     rS   OnErasezBasePlotFrame.OnErase  s    rT   c                 8    | j                   j                          y)zSave plot to graphics fileN)rA   SaveFiler   s     rS   
SaveToFilezBasePlotFrame.SaveToFile  s    rT   c                     | j                  t        d      d| j                  j                  |      z  z          |j	                          y )NzLeft Mouse Down at Point:z (%.4f, %.4f))SetStatusText_rA   _getXYSkipr   s     rS   rG   zBasePlotFrame.OnMouseLeftDown  s>    )*_t{{?Q?QRW?X-XX	
 	

rT   c                    | j                   j                  rg| j                   j                  | j                   j                  |      d      }|g k7  r,|\  }}}}}}|||||d}	| j                   j	                  |	       |j                          y)z,Indicate when mouse is outside the plot areaT)pointScaled)r   r   r   r   r   N)rA   enablePointLabelGetClosestPointr   UpdatePointLabelr   )
rP   r   dlstr   r   r   r   r   distancer   s
             rS   rI   zBasePlotFrame.OnMotion  s    ;;'' ;;..""5)t / D rzHLE&&'8X !)$$& (	 ,,Y7

rT   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                  |       | j                  |       |j                          y)z$Popup menu for plot and text optionsText settingsPlot settingsN)r%   GetMousePositionr   MenuItemr(   r   
AppendItemrE   EVT_MENUPlotTextPlotOptions	PopupMenuDestroy)rP   r   pointpoptsettextsetgrids         rS   PlotOptionsMenuzBasePlotFrame.PlotOptionsMenu   s    ##%v++dBIIq/AB 		"++t}}g6++dBIIq/AB 		"++t//9 	trT   c                     t        j                  | t        d      t        d      t         j                  t         j                  z        }|j                          |j                          y)z)Creates a 'not functional' message dialogz"This feature is not yet functionalzUnder Construction)r)   messagecaptionr   N)r%   MessageDialogr   OKICON_INFORMATION	ShowModalr  rP   dlgs     rS   NotFunctionalzBasePlotFrame.NotFunctional  sM    :;*+%%"---	
 	rT   c                     d }| j                   }| j                  d   d   d   r ||      }| j                  }| j                  d   d   d   r ||      }||fS )Nc                     d| z   dz   S )Nzlog( z ) )txts    rS   r   z)BasePlotFrame._getPlotLabels.<locals>.log  s    S=4''rT   r|   rh   r   r~   )rL   r   rM   )rP   r   xys       rS   r   zBasePlotFrame._getPlotLabels  sb    	( KK??8$V,U3AAKK??8$V,U3AA!trT   c                     |j                   | _         |j                  | _        |j                  | _        | j                  r|j                   | j                  _        | j                  d       y)z(Custom text settings for histogram plot.N)r   )rK   rL   rM   r?   titler   r  s     rS   
OnPlotTextzBasePlotFrame.OnPlotText+  sG    jjjjjj99!jjDIIOD!rT   c                 b   | j                         \  }}| j                  j                  | j                         | j                  d   d   d   | j                  _        | j                  d   d   d   | j                  _        | j                  r#|| j                  _        || j                  _	        y y )Nrd   rh   r   r   )
r   rA   r   r   r   r   r   r?   xLabelyLabel)rP   r  r  s      rS   r   zBasePlotFrame.UpdateLabels6  s    ""$1DLL)$(OOF$;F$CK$P!#'??6#:6#B:#N 99 DII DII rT   c           	      .   t        | | j                  t        j                  | j                  t        d            }|j                         }|t        j                  k(  s&|t        j                  k(  s|t        j                  k(  r|j                          yy)z9Set custom text values for profile title and axis labels.r   r)   rQ   r   r-   r  N)r   r*   r%   r(   r-   r   r  ID_SAVEID_OK	ID_CANCELr  rP   r   r  btnvals       rS   r  zBasePlotFrame.PlotTextA  sj    <<yy]]O$
 RZZ6RXX#52<<9OKKM :PrT   c           	      L   t        | | j                  t        j                  | j                  t        d            }|j                         }|t        j                  k(  s&|t        j                  k(  s|t        j                  k(  r|j                          | j                          y)zSet various profile options, including: line width, color,
        style; marker size, color, fill, and style; grid and legend
        options.  Calls OptDialog class.
        r   r!  N)r   r*   r%   r(   r-   r   r  r"  r#  r$  r  Updater%  s       rS   r  zBasePlotFrame.PlotOptionsO  so     <<yy]]O$
 RZZ6RXX#52<<9OKKMrT   c                    t        j                         }t               }t        d      | j                  ft        d      | j
                  ft        d      | j                  ffD ]\  \  }}t        j                  |t         j                  |      }|j                  |       | j                  t         j                  ||       ^ | j                  |       |j                          y)zPrint options and output menuz
Page setupzPrint previewzPrint displayN)r%   r   r   r   OnPageSetupOnPrintPreview	OnDoPrintr   r(   r   rE   r   r  r  )rP   r   r  	printmenur  handleritems          rS   	PrintMenuzBasePlotFrame.PrintMenub  s    ##%F	|_d../!4!450
 	2NE7
 ;;y"))U;D  &IIbkk7D1	2 	y!rT   c                 8    | j                   j                          y rn   )rA   	PageSetupr   s     rS   r*  zBasePlotFrame.OnPageSetupt  s    rT   c                 8    | j                   j                          y rn   )rA   PrintPreviewr   s     rS   r+  zBasePlotFrame.OnPrintPrevieww  s      "rT   c                 8    | j                   j                          y rn   )rA   Printoutr   s     rS   r,  zBasePlotFrame.OnDoPrintz  s    rT   c                 &    | j                  d       y )NT)Closer   s     rS   OnQuitzBasePlotFrame.OnQuit}  s    

4rT   )"__name__
__module____qualname____doc__r%   SizeDEFAULT_FRAME_STYLEr'   rO   r   r   r   r   r   rB   r   r   r   r   r   rG   rI   r	  r  r   r  r   r  r  r0  r*  r+  r,  r9  r  rT   rS   r   r   0   s    - RWWS#$$> @1CJJ;zIVLH\
*#.++.$		"	!&$ #rT   r   )r=  r8   rZ   r%   randomr   wx.lib.plotlibr?   core.globalvarr   core.settingsr   wxplot.dialogsr   r   core.renderr   
icons.iconr	   gui_core.toolbarsr
   gui_core.wrapr   grass.scriptscriptr\   r   	PlotIconsr&   r   r  rT   rS   <module>rM     s   " 
 
 	    " & 0   '   q)<'=>"@A $wa0A.BCq)H'IJf
	N	BHH N	rT   