
    ը	f                         d Z ddl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mZ ddl ddl ddlmZ  G d	 d
e      Z G d de      Z G d de      Zy# e$ r Y /w xY w)a  
@package iclass.digit

@brief wxIClass digitizer classes

Classes:
 - digit::IClassVDigit
 - digit::IClassVDigitWindow

(C) 2006-2012 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 Vaclav Petras <wenzeslaus gmail.com>
@author Anna Kratochvilova <kratochanna gmail.com>
    N)VDigitWindow)IVDigit)DisplayDriver	TYPE_AREA)GWarning)	G_verboseG_set_verbose)*c                   J     e Zd ZdZd Z fdZd Zd Z fdZd Z	d Z
 xZS )	IClassVDigitWindowz;Class similar to VDigitWindow but specialized for wxIClass.c                 8    t        j                  | ||||       y)z

        @a parent should has toolbar providing current class (category).

        :param parent: gui parent
        :param map: map renderer instance
        )parentgifaceMap
propertiesN)r   __init__)selfr   r   mapr   s        -/usr/lib/grass83/gui/wxpython/iclass/digit.pyr   zIClassVDigitWindow.__init__'   s     	CJ	
    c                    | j                   j                         }|sy t        j                         }| j	                  |j                               \  }}|d   |cxk  r|d   k  rn n|d   |cxk  r|d   k  s#n t        | j                  t        d             y | j                         }||dk(  rt        j                  | j                  t        d      t        d	      t        j                  
      }|j                         t        j                  k(  r| j                  j                  d        |j!                          |j#                          y t$        t&        | S  |       y )NsnwezYou are trying to create a training area outside the computational region. Please, use g.region to set the appropriate region first.)r   messageaddLinezvIn order to create a training area, you have to select class first.

There is no class yet, do you want to create one?zNo class selected)r   r   captionstyle)toolbar	GetActiongrassregion
Pixel2CellGetPositionr   r   _GetCurrentCategorywxMessageDialogYES_NO	ShowModalID_YESOnCategoryManagerDestroySkipsuperr   _onLeftDown)	r   eventactionr#   r   r   catdlg	__class__s	           r   r1   zIClassVDigitWindow._onLeftDown3   s'   '')u00231C[A,,6#;!3Rvc{3R{{P %%';6Y.""{{1 -.ii
C }}"))+--d3KKMJJL $3E:r   c                      y)NF r   s    r   
_addRecordzIClassVDigitWindow._addRecord^   s    r   c                      y Nr8   r9   s    r   
_updateATMzIClassVDigitWindow._updateATMa   s    r   c                 d    t         t        |   |       | j                  j	                  d       y )NT)changes)r0   r   
_onRightUpr   UpdateChangeState)r   r2   r6   s     r   r@   zIClassVDigitWindow._onRightUpd   s(     $259%%d%3r   c                 T    | j                   j                  d      j                         S )zReturns current category (class).

        Category should be assigned to new features (areas).
        It is taken from parent's toolbar.
        iClass)r   
GetToolbarGetSelectedCategoryIdxr9   s    r   r'   z%IClassVDigitWindow.GetCurrentCategoryh   s"     {{%%h/FFHHr   c                     | j                   j                  |      j                  d      D cg c]  }t        |       c}dd \  }}}t	        j
                  |||      S c c}w )z(Get color associated with given category:N   )r   GetClassColorsplitintr(   Colour)r   r4   xrgbs         r   GetCategoryColorz#IClassVDigitWindow.GetCategoryColorp   sV    #';;#<#<S#A#G#G#LMa3q6MbqQ1ayyAq!! Ns   A )__name__
__module____qualname____doc__r   r1   r:   r=   r@   r'   rQ   __classcell__)r6   s   @r   r   r   $   s+    E

);V4I"r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd	dZd Z	y)
IClassVDigitz6Class similar to IVDigit but specialized for wxIClass.c                 \    t        j                  | ||t               d| j                  d<   y )N)driverTcloseBoundary)r   r   IClassDisplayDriver	_settings)r   r   	mapwindows      r   r   zIClassVDigit.__init__y   s%    vy9LM*.'r   c                      y)N   r8   r9   s    r   _getNewFeaturesLayerz!IClassVDigit._getNewFeaturesLayer}   s    r   c                 :    | j                   j                         }|S r<   )	mapWindowr'   )r   r4   s     r   _getNewFeaturesCatzIClassVDigit._getNewFeaturesCat   s    nn//1
r   c                 @    |D ]  }t        | j                  d|        y)zbDelete areas (centroid+boundaries) by categories

        :param cats: list of categories
        r`   N)Vedit_delete_areas_cat	poMapInfo)r   catsr4   s      r   DeleteAreasByCatzIClassVDigit.DeleteAreasByCat   s#    
  	;C"4>>1c:	;r   c                    | j                   syt        t                     }|s|rt        }nt        }n|rt
        }nt        }|r |||d      dk(  r-yt        t        | j                               } ||||      dk(  ryt               }t        d       t        | j                   |      dk(  rt        |       yt        |       t        |       t        |      }t        |       |S )aB  Make a copy of open vector map

        Note: Attributes are not copied

        :param name: name for a copy
        :param tmp: True for temporary map
        :param bool update: True if copy target vector map (poMapInfoNew)
        exist

        :return: number of copied features
        :return: -1 on error
         r`   )rg   pointerMap_infoVect_open_updateVect_open_newVect_open_tmp_updateVect_open_tmp_newbool
Vect_is_3dr   r	   Vect_copy_map_lines
Vect_buildVect_get_num_lines
Vect_close)	r   nametmpupdatepoMapInfoNewopen_fnis3Dverboserets	            r   CopyMapzIClassVDigit.CopyMap   s     ~~xz**'.+|T2."4
4>>23D|T40B6+bt~~|<A'"< g .< 
r   c                     | j                   S )z,Returns Map_info() struct of open vector map)rg   r9   s    r   
GetMapInfozIClassVDigit.GetMapInfo   s    ~~r   N)FF)
rR   rS   rT   rU   r   ra   rd   ri   r   r   r8   r   r   rX   rX   v   s$    @/;3jr   rX   c                   (    e Zd ZdZd Zd Zd Zd Zy)r\   z{Class similar to DisplayDriver but specialized for wxIClass

    .. todo::
        needs refactoring (glog, gprogress)
    c           	      H    t        j                  | ||||||       d| _        y )Nrk   )r   r   _cat)r   device	deviceTmpmapObjwindowglog	gprogresss          r   r   zIClassDisplayDriver.__init__   s#    tVYiX	r   c                     |j                   t        k(  r't        | j                  |j                  d      | _        n|j                   t        k(  ryt        j                  | |       y)zMDraw given object to the device

        :param robj: object to draw
        r`   N)	typer   Vect_get_area_catrg   fidr   TYPE_CENTROIDINr   _drawObject)r   robjs     r   r   zIClassDisplayDriver._drawObject   sG    
 99	!)$..$((AFDIYY/)!!$-r   c                     t        j                  | |      \  }}| j                  dkD  rP|t        k(  rGt	        j
                  | j                  j                  | j                        t        j                        }||fS )zzDefine pen/brush based on rendered object)

        :param rtype: type of the object

        :return: pen, brush
        r   )	r   
_definePenr   r   r(   Brushr   rQ   SOLID)r   rtypepenbrushs       r   r   zIClassDisplayDriver._definePen   s]     #--dE:
U99q=Ui/HHT[[99$))DbhhOEEzr   c                 n    t               }t        d       t        j                  |        t        |       y)z#Close training areas map - be quietr   N)r   r	   r   CloseMap)r   	verbositys     r   r   zIClassDisplayDriver.CloseMap   s'    K	at$i r   N)rR   rS   rT   rU   r   r   r   r   r8   r   r   r\   r\      s    	.!r   r\   )rU   r(   vdigit.mapwindowr   vdigit.wxdigitr   vdigit.wxdisplayr   r   	core.gcmdr   grass.lib.gisr   r	   grass.lib.vectorgrass.lib.veditImportErrorgrass.scriptscriptr"   r   rX   r\   r8   r   r   <module>r      sm   $ 
 ) " 5 	6"! O" O"dM7 M`(!- (!Q  		s   A A$#A$