
    ը	f=                     P    d Z ddlmZ ddlZddlmZ  G d d      Z G d d      Zy)	a  
@package mapwin.graphics

@brief Map display canvas - buffered window.

Classes:
 - graphics::GraphicsSet
 - graphics::GraphicsSetItem

(C) 2006-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 Stepan Turek <stepan.turek seznam.cz> (handlers support, GraphicsSet)
    )copyN)NewIdc                   p    e Zd Z	 	 	 ddZd Zd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)GraphicsSetNc                    t        j                  t         j                  dt         j                        t        j                  t         j                  dt         j                        t        j                  t         j
                  dt         j                        t        j                  t         j                  dt         j                        d| _        dt         j                  i| _	        g | _
        i | _        || _        || _        || _        || _        || _        |r|| _        y| j                  dk(  rd| j                  d<   i | j                  d<   t        j$                  | j                  d   t         j&                  t         j(                  t         j*                  	      | j                  d   d
<   d| j                  d   d<   | j                  j,                  | _        y| j                  dk(  r| j                  j.                  | _        y| j                  dk(  r| j                  j0                  | _        y| j                  dk(  r| j                  j2                  | _        yy)zClass, which contains instances of GraphicsSetItem and
        draws them For description of parameters look at method
        RegisterGraphicsToDraw in BufferedWindow class.
           )colourwidthstyle)defaultselectedunusedhighestr   point   sizetext)	pointSizefamilyr   weightfontTactiveline	rectanglepolygonN)wxPenBLACKSOLIDGREEN
LIGHT_GREYREDpensTRANSPARENT_BRUSHbrushes	itemsList
propertiesgraphicsTypeparentMapWinsetStatusFunc	mapCoordspdcdrawFuncFontFONTFAMILY_DEFAULTFONTSTYLE_NORMALFONTWEIGHT_NORMAL	DrawCrossDrawPolylinesDrawRectangleDrawPolygon)selfr)   r(   r,   r*   r-   r+   s          0/usr/lib/grass83/gui/wxpython/mapwin/graphics.py__init__zGraphicsSet.__init__   s    vvRXXQbhhGbhharxxHffBMM"((KvvRVV1BHHE	
	 "2#7#78 ((*"$DM')&'DOOF#&(DOOF#.0gg//&1,,))++	/DOOF#F+ 15DOOF#H- --77DM&( --;;DM+- --;;DM)+ --99DM ,    c           
      $
   d}| j                   D ]  }| j                  |j                                | j                  | j                  ||       |j	                  d      du r|dz  }Z| j
                  dk(  r|j	                  d      r.| j                  |j	                  d         | j                  _        n| j                  d   | j                  _        | j                  r*| j                  j                  |j                               }n|j                         }| j                  d	   }|j	                  d
      }|d| j                  d<   nh|d   |z   |d   |z   ||g| j                  d   d<   | j                  j                  j                         | j                  d   d<   || j                  d   d<   | j                  | j                  |j                         || j                  d   | j                  d	          n| j
                  dk(  r|j	                  d      r| j                  |j	                  d         }n| j                  d   }| j                  r8|j                         D cg c]  }| j                  j                  |       c}}n|j                         }| j                  | j                  |||j                                n)| j
                  dk(  r	|j	                  d      r| j                  |j	                  d         }n| j                  d   }|j	                  d      r| j                   |j	                  d         }n| j                   d   }| j                  r8|j                         D cg c]  }| j                  j                  |       c}}n|j                         }| j                  | j                  |||j                         |d   |d          n| j
                  dk(  r |j	                  d      r| j                  |j	                  d         }n| j                  d   }|j	                  d      r| j                   |j	                  d         }n| j                   d   }| j                  r8|j                         D cg c]  }| j                  j                  |       c}}n|j                         }| j                  | j                  ||||j                                |dz  } yc c}w c c}w c c}w )zDraws all containing items.r   NhideT   r   penNamer   r   labelr   coordscolor)r,   drawidr?   r   r   r   )r,   penr?   rA   r   	brushName)r,   rB   brushrA   point1point2r   )r,   rB   rD   r?   rA   )r&   _clearIdGetIdr*   GetPropertyValr(   r#   r)   rB   r+   
Cell2Pixel	GetCoordsr'   	GetColourr-   r,   r%   )r6   itemOrderNumitemr?   r   r>   rB   rD   s           r7   DrawzGraphicsSet.DrawT   st   NN l	DMM$**,'!!-""46""6*d2!  G+&&y1,0IId6I6I)6T,UD%%),0IIi,@D%%)>>!..99$..:JKF!^^-Fv.++G4=.2DOOF+ q	D(q	D(	9DOOF+H5 8<7H7H7L7L7V7V7XDOOF+G46;DOOF+F3::<!00   ""f,&&y1))D$7$7	$BCC))I.C>> '+nn&6" ))44V<F
 "^^-F$((F4::<X""k1&&y1))D$7$7	$BCC))I.C&&{3 LL)<)<[)IJE LL3E>> '+nn&6" ))44V<F
 "^^-F::<!!9!!9   ""i/&&y1))D$7$7	$BCC))I.C&&{3 LL)<)<[)IJE LL3E>> '+nn&6" ))44V<F
 "^^-F!::<   ALYl	b&4s   ,"T="T"Tc                 Z    t        ||||      }| j                  j                  |       |S )a  Append item to the list.

        Added item is put to the last place in drawing order.
        Could be 'point' or 'line' according to graphicsType.

        :param coords: list of east, north coordinates (double) of item.
                       Example:

                           * point: [1023, 122]
                           * line: [[10, 12],[20,40],[23, 2334]]
                           * rectangle: [[10, 12], [33, 45]]
        :param penName: the 'default' pen is used if is not defined
        :type penName: str
        :param label: label, which will be drawn with point. It is
                      relevant just for 'point' type.
        :type label: str
        :param hide: if it is True, the item is not drawn when self.Draw
                     is called. Hidden items are also counted in drawing
                     order.
        :type hide: bool
        :return: (GraphicsSetItem) - added item reference
        )r?   r=   r>   r;   )GraphicsSetItemr&   append)r6   r?   r=   r>   r;   rN   s         r7   AddItemzGraphicsSet.AddItem   s,    . fgUQUVd#r9   c                 Z    	 | j                   j                  |       y# t        $ r Y yw xY w)zDeletes item

        :param item: (GraphicsSetItem) - item to remove

        :return: True if item was removed
        :return: False if item was not found
        FT)r&   remove
ValueErrorr6   rN   s     r7   
DeleteItemzGraphicsSet.DeleteItem   s2    	NN!!$'   		s    	**c                 ,    t        | j                        S )zReturns list of all containing instances of GraphicsSetItem,
        in order as they are drawn. If you want to change order of
        drawing use: SetItemDrawOrder method.
        )r   r&   r6   s    r7   GetAllItemszGraphicsSet.GetAllItems   s     DNN##r9   c                      | j                   |   S )a   Get given item from the list.

        :param drawNum: drawing order (index) number of item
        :type drawNum: int

        :return: instance of GraphicsSetItem which is drawn in drawNum order
        :return: False if drawNum was out of range
        )r&   )r6   drawNums     r7   GetItemzGraphicsSet.GetItem   s     ~~g&&r9   c                 @    || j                   v r|| j                   |<   yy)a`  Set property value

        :param propName: - property name: "size", "text"
                         - both properties are relevant for "point" type
        :type propName: str
        :param propVal: property value to be set

        :return: True if value was set
        :return: False if propName is not "size" or "text" or type is "line"
        TFr'   r6   propNamepropVals      r7   SetPropertyValzGraphicsSet.SetPropertyVal  s$     t&(/DOOH%r9   c                 j    || j                   v r| j                   |   S t        t        d      |z        )a'  Get property value

        Raises KeyError if propName is not "size" or "text" or type is
        "line"

        :param propName: property name: "size", "text" both properties
               are relevant for "point" type
        :type propName: str

        :return: value of property
        Property does not exist: %sr'   KeyError_r6   rb   s     r7   rI   zGraphicsSet.GetPropertyVal  5     t&??8,,q678DEEr9   c                 @    || j                   v ry|| j                   |<   y)zAdd pen

        :param penName: name of added pen
        :type penName: str
        :param pen: added pen
        :type pen: Wx.Pen

        :return: True - if pen was added
        :return: False - if pen already exists
        FTr#   )r6   r=   rB   s      r7   AddPenzGraphicsSet.AddPen'  s$     dii 		'r9   c                 >    || j                   v r| j                   |   S y)zGet existing pen

        :param penName: name of pen
        :type penName: str

        :return: wx.Pen reference if is found
        :return: None if penName was not found
        Nrm   )r6   r=   s     r7   GetPenzGraphicsSet.GetPen8  s"     dii99W%%r9   c                 @    || j                   v ry|| j                   |<   y)zAdd brush

        :param brushName: name of added brush
        :type brushName: str
        :param brush: added brush
        :type brush: wx.Brush

        :return: True - if brush was added
        :return: False - if brush already exists
        FTr%   )r6   rC   rD   s      r7   AddBrushzGraphicsSet.AddBrushF  s$     $"'Yr9   c                 >    || j                   v r| j                   |   S y)zGet existing brush

        :param brushName: name of brush
        :type brushName: str

        :return: wx.Brush reference if is found
        :return: None if brushName was not found
        Nrr   )r6   rC   s     r7   GetBrushzGraphicsSet.GetBrushW  s"     $<<	**r9   c                     |t        | j                        k  rb|dk\  r]|| j                  v rO| j                  j                  || j                  j                  | j                  j	                  |                   yy)a  Set draw order for item

        :param item: (GraphicsSetItem)
        :param drawNum: drawing order of item to be set
        :type drawNum: int

        :return: True if order was changed
        :return: False if drawNum is out of range or item was not found
        r   TF)lenr&   insertpopindex)r6   rN   r]   s      r7   SetItemDrawOrderzGraphicsSet.SetItemDrawOrdere  sc     S((W\ddnn>TNN!!++DNN,@,@,FG r9   c                 X    	 | j                   j                  |      S # t        $ r Y yw xY w)zGet draw order for given item

        :param item: (GraphicsSetItem)

        :return: (int) - drawing order of item
        :return: None - if item was not found
        N)r&   rz   rV   rW   s     r7   GetItemDrawOrderzGraphicsSet.GetItemDrawOrderw  s.    	>>''-- 		s    	))c                 J    	 | j                   j                  |       y#  Y yxY w)z,Clears old object before drawing new object.N)r,   ClearId)r6   rA   s     r7   rG   zGraphicsSet._clearId  s#    	HHV$	s    ")NNT)NNF)__name__
__module____qualname__r8   rO   rS   rX   r[   r^   rd   rI   rn   rp   rs   ru   r{   r}   rG    r9   r7   r   r      s\     7:rob8$	'"F"""$r9   r   c                   8    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	y)
rQ   Nc                 H    || _         ||||d| _        t               | _        y)aF  Could be point or line according to graphicsType in
        GraphicsSet class

        :param coords: list of coordinates (double) of item
                       Example: point: [1023, 122]
                                line: [[10, 12],[20,40],[23, 2334]]
                                rectangle: [[10, 12], [33, 45]]
        :param penName: if it is not defined 'default' pen is used
        :type penName: str
        :param brushName: if it is not defined 'default' brush is used
        :type brushName: str
        :param label: label, which will be drawn with point. It is
                      relevant just for 'point' type
        :type label: str
        :param hide: if it is True, item is not drawn Hidden items are
                     also counted in drawing order in GraphicsSet class.
        :type hide: bool
        )r=   rC   r;   r>   N)r?   r'   r   id)r6   r?   r=   rC   r>   r;   s         r7   r8   zGraphicsSetItem.__init__  s-    &  "	
 'r9   c                 @    || j                   vrd| j                   |<   yy)zAdds new property, to set it, call SetPropertyVal afterwards.

        :param propName - name of the newly defined property
        :type propName: str
        Nr`   rj   s     r7   AddPropertyzGraphicsSetItem.AddProperty  s#     4??*(,DOOH% +r9   c                 @    || j                   v r|| j                   |<   yy)a  Set property value

        :param propName: - property name: "penName", "hide" or "label"
                         - property "label" is relevant just for 'point' type
                         - or newly defined property name
        :type propName: str
        :param propVal: property value to be set

        :return: True if value was set
        :return: False if propName is not "penName", "hide" or "label"
        TFr`   ra   s      r7   rd   zGraphicsSetItem.SetPropertyVal  s$     t&(/DOOH%r9   c                 j    || j                   v r| j                   |   S t        t        d      |z        )aC  Get property value

        Raises KeyError if propName is not "penName", "hide" or
        "label".

        :param propName: - property name: "penName", "hide" or "label"
                         - property "label" is relevant just for 'point' type
        :type propName: str

        :return: value of property
        rf   rg   rj   s     r7   rI   zGraphicsSetItem.GetPropertyVal  rk   r9   c                     || _         y)a8  Set coordinates of item

        :param coords: list of east, north coordinates (double) of item
                       Example:

                           * point: [1023, 122]
                           * line: [[10, 12],[20,40],[23, 2334]]
                           * rectangle: [[10, 12], [33, 45]]
        Nr?   )r6   r?   s     r7   	SetCoordszGraphicsSetItem.SetCoords  s     r9   c                     | j                   S )z;Get item coordinates

        :return: coordinates
        r   rZ   s    r7   rK   zGraphicsSetItem.GetCoords  s    
 {{r9   c                     | j                   S )zGet item id (drawing id).)r   rZ   s    r7   rH   zGraphicsSetItem.GetId  s    wwr9   )NNNF)
r   r   r   r8   r   rd   rI   r   rK   rH   r   r9   r7   rQ   rQ     s&    :-$F"
r9   rQ   )__doc__r   r   gui_core.wrapr   r   rQ   r   r9   r7   <module>r      s.   $  	 o od_ _r9   