
    ը	f1%                         d Z ddlZddl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mZmZmZmZ ddlmZmZ  G d	 d
e      Z G d de      Zy)aR  
@package animation.data

@brief animation data structures

Classes:
 - data::AnimationData
 - data::AnimationLayer


(C) 2013 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 Anna Petrasova <kratochanna gmail.com>
    N)parse_key_val)core)
GException)NvizTask)validateMapNamesgetRegisteredMapscheckSeriesCompatibilityvalidateTimeseriesNameinterpolate)	LayerListLayerc                      e Zd Zd Zd Zd Z eee      Zd Zd Z	 eee	      Z
d Zd Z eee      Zd	 Z ee
      Zd Z ee
      Zd Zd Z eee      Zd Zd Z eee      Zd Zd Z ee
      Zd Zd Z eee      Zd Zd Z eee      Z d Z! ee!
      Z"d Z#d Z$ ee$e#      Z%d Z&d Z'd Z( ee'e(      Z)d Z*d Z+ ee*e+      Z,d Z-d  Z. ee-e.      Z/d! Z0d%d#Z1d$ Z2y")&AnimationDatac                 |   d | _         d| _        d | _        d | _        d | _        d | _        dt        d      fdt        d      fg| _        d| _        t               | _
        | j                  j                         | _        | j                  d   | _        d | _        d | _        d | _        d | _        d | _        d | _        y )Nr   2dz2D view3dz3D view)_name_windowIndex
_layerList_firstStdsNameType	_mapCount
_cmdMatrix_
_viewModesviewModer   nvizTaskListMapParameters_nvizParametersnvizParameterworkspaceFile	legendCmd_startRegion
_endRegion_zoomRegionValue_regionsselfs    //usr/lib/grass83/gui/wxpython/animation/data.py__init__zAnimationData.__init__%   s    
 #' !I,/$)1EF 
#}}>>@!11!4!  $    c                     | j                   S Nr   r&   s    r(   GetNamezAnimationData.GetName=       zzr*   c                 D    |dk(  rt        t        d            || _        y )N zNo animation name selected.)
ValueErrorr   r   )r'   names     r(   SetNamezAnimationData.SetName@   s!    2:Q<=>>
r*   fgetfsetc                     | j                   S r,   r   r&   s    r(   GetWindowIndexzAnimationData.GetWindowIndexG          r*   c                     || _         y r,   r9   )r'   windowIndexs     r(   SetWindowIndexzAnimationData.SetWindowIndexJ   s
    'r*   c                 r   g }g }|D ]  }|j                   st        |d      s|j                  dv rE|j                  |j                  |j                  f       |j                  |j                  f| _        p|j                  |j                          |sd| _        t        ||      }|| _        || _	        y)zU
        Throws GException if layer list's combination of stds is not valid.
        mapsstrdsstvdsstr3dsNN)mapSeriesListtimeseriesListN)
activehasattrmapTypeappendr3   r   r@   r	   r   r   )r'   	layerListrF   rG   layercounts         r(   SetLayerListzAnimationData.SetLayerListO   s      	7E||v 6==$@@"))5::u}}*EF.3jj%--.GD+!((%**6	7 &0D#('
 #r*   c                     | j                   S r,   )r   r&   s    r(   GetLayerListzAnimationData.GetLayerListe       r*   c                     | j                   S r,   )r   r&   s    r(   GetFirstStdsNameTypez"AnimationData.GetFirstStdsNameTypej   s    &&&r*   r6   c                     | j                   S r,   )r   r&   s    r(   GetMapCountzAnimationData.GetMapCounto       ~~r*   c                     | j                   S r,   r   r&   s    r(   GetCmdMatrixzAnimationData.GetCmdMatrixt   rR   r*   c                     || _         y r,   rZ   )r'   	cmdMatrixs     r(   SetCmdMatrixzAnimationData.SetCmdMatrixw   s	    #r*   c                     | j                   S r,   )_workspaceFiler&   s    r(   GetWorkspaceFilezAnimationData.GetWorkspaceFile|       """r*   c                    |d | _         y |dk(  rt        t        d            t        j                  j                  |      st        t        d      |z        || _         | j                  j                  | j                         y )Nr1   zNo workspace file selected.zFile %s not found)
r`   r2   r   ospathexistsIOErrorr   Loadr    )r'   fileNames     r(   SetWorkspaceFilezAnimationData.SetWorkspaceFile   sq    "&Dr>Q<=>>ww~~h'!/08;<<&4--.r*   c                 \    || _         t        d      |dz   z  | _        t               | _        y )NzAnimation %d   )r=   r   r3   r   rL   )r'   r=   animationIndexs      r(   SetDefaultValueszAnimationData.SetDefaultValues   s)    &n%!);<	"r*   c                     | j                   S r,   )r   r&   s    r(   GetNvizParameterszAnimationData.GetNvizParameters   s    ###r*   c                     | j                   S r,   _nvizParameterr&   s    r(   GetNvizParameterzAnimationData.GetNvizParameter   rb   r*   c                     || _         y r,   rr   )r'   params     r(   SetNvizParameterzAnimationData.SetNvizParameter   s
    #r*   c                     | j                   S r,   	_viewModer&   s    r(   GetViewModezAnimationData.GetViewMode   rX   r*   c                     || _         y r,   ry   )r'   modes     r(   SetViewModezAnimationData.SetViewMode   s	    r*   c                     | j                   S r,   )r   r&   s    r(   GetViewModeszAnimationData.GetViewModes   rR   r*   c                     || _         y r,   
_legendCmd)r'   cmds     r(   SetLegendCmdzAnimationData.SetLegendCmd   s	    r*   c                     | j                   S r,   r   r&   s    r(   GetLegendCmdzAnimationData.GetLegendCmd   rR   r*   c                     | j                   r| j                  sg S | j                  j                  | j                  | j                        }| j                  j                         }||dS )N)rL   	paramName)commandsregion)r    r   r   GetCommandSeriesr   	GetRegion)r'   cmdsr   s      r(   GetNvizCommandszAnimationData.GetNvizCommands   s]    !!I}}--oo1C1C . 
 ((* F33r*   c                     || _         y r,   r"   r'   r   s     r(   SetStartRegionzAnimationData.SetStartRegion   s
    "r*   c                     | j                   S r,   r   r&   s    r(   GetStartRegionzAnimationData.GetStartRegion   r;   r*   )r7   r6   c                     || _         y r,   r#   r   s     r(   SetEndRegionzAnimationData.SetEndRegion   s	     r*   c                     | j                   S r,   r   r&   s    r(   GetEndRegionzAnimationData.GetEndRegion   rR   r*   c                     || _         y r,   r$   )r'   values     r(   SetZoomRegionValuez AnimationData.SetZoomRegionValue   s
     %r*   c                     | j                   S r,   r   r&   s    r(   GetZoomRegionValuez AnimationData.GetZoomRegionValue   s    $$$r*   c                     | j                  | j                  | j                  | j                  | j                         | j
                  S r,   )_computeRegionsr   r"   r#   r$   r%   r&   s    r(   
GetRegionszAnimationData.GetRegions   s9    NND--t@U@U	
 }}r*   Nc           	         t        t        j                               }|r0t        t        t        j                  dd|      t
                    }|d= |d= |d= d|v r|d= d	|v r|d	= g }t        | j                        D ]&  }|j                  t        j                  |             ( || _
        |s|sy
t        t        j                  dd|      t
              }|rlt        t        j                  dd|      t
              }	dD ]8  }
t        ||
   |	|
   | j                        }t        ||      D ]
  \  }}|||
<    : || _
        y
|rt        | j                        D ]  }||   dxx   |d   |z  z  cc<   ||   dxx   |d   |z  z  cc<   ||   dxx   |d   |z  z  cc<   ||   dxx   |d   |z  z  cc<   ||   d   ||   d   k  s||   d   ||   d   k  s~||dz
     ||<    || _
        y
)zmComputes regions based on start region and end region or zoom value
        for each of the animation frames.zg.regiongu)flagsr   )val_typecellscolsrows
projectionzoneN)nsewnsresewresr   r   r   rl   r   r   )dictgcorer   r   read_commandfloatranger   rK   copyr%   r   zip)r'   rN   startRegion	endRegion	zoomValuer   regionsistartRegionDictendRegionDictkeyvaluesr   s                r(   r   zAnimationData._computeRegions   s+    elln%&&zkR"F 7O6N6N6!|$Vvt~~& 	.ANN499V,-	.Y'zkJ
 )"":T)LM > ($#C(-*<dnn &)%9 (ME6"'F3K(	(*   4>>* 0
39Q<!#33
39Q<!#33
39Q<!#33
39Q<!#33 AJsOgajo5qz#C8!(QGAJ0  r*   c                 :    | j                   d| j                  dS )N())	__class____dict__r&   s    r(   __repr__zAnimationData.__repr__  s    >>4==99r*   rE   )3__name__
__module____qualname__r)   r.   r4   propertyr3   r:   r>   r=   rO   rQ   rL   rT   firstStdsNameTyperW   mapCountr[   r^   r]   ra   rj   r    rn   rp   nvizParametersrt   rw   r   r{   r~   r   r   	viewModesr   r   r!   r   r   r   r   r   r   r   r   r   zoomRegionValuer   r   r    r*   r(   r   r   $   sv   0
 w/D!( ^DK$, l>I' !&:; [)H$ l>I#/ "29IJM%
$ #45N#$ "29IJM [{;H l+I l>I	4#! ^DK! l>I&% $6=OPO8 t:r*   r   c                   N    e Zd ZdZd Zd Zd Z eee      Zd Z	 ee	      Z
y)		AnimLayerzNAnimation layer allows adding either space-time dataset
    or series of maps.c                 v    t        j                  |        | j                  j                  g d       g | _        y )NrA   )r   r)   	_mapTypesextend_mapsr&   s    r(   r)   zAnimLayer.__init__!  s(    t:;
r*   c                    | j                   s| j                  t        d      | j                  dv r3	 t        || j                        }t	        || j                        | _        n*t        |j                  d      | j                        | _        || _        || _        y # t        t        j                  f$ r}t        t        |            d }~ww xY w)Nz7To set layer name, the type of layer must be specified.rA   ,)hidden_mapTyper2   r
   r   r   r   r   ScriptErrorstrr   splitr   label)r'   r3   r   s      r(   r4   zAnimLayer.SetName&  s    {{}}$ M  }} <<-1$FD!24!GDJ .djjot}}M


 #E$5$56 -$SV,,-s   1B C7CCc                     | j                   S r,   r-   r&   s    r(   r.   zAnimLayer.GetName7  r/   r*   r5   c                     | j                   S r,   )r   r&   s    r(   GetMapszAnimLayer.GetMaps<  r/   r*   rU   N)r   r   r   __doc__r)   r4   r.   r   r3   r   r@   r   r*   r(   r   r     s5    
" w/D !Dr*   r   )r   rd   r   grass.script.utilsr   grass.scriptr   r   	core.gcmdr   animation.nviztaskr   animation.utilsr   r   r	   r
   r   core.layerlistr   r   objectr   r   r   r*   r(   <module>r      sH   " 
  , &   '  ,v:F v:r"" ""r*   