<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import numpy as np <EOL> from ... import glsl , gloo <EOL> from . . visual import Visual <EOL> from . line import LineVisual <EOL> ARROW_TYPES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> class _ArrowHeadVisual ( Visual ) : <EOL> """<STR_LIT>""" <EOL> ARROWHEAD_VERTEX_SHADER = glsl . get ( '<STR_LIT>' ) <EOL> ARROWHEAD_FRAGMENT_SHADER = glsl . get ( '<STR_LIT>' ) <EOL> _arrow_vtype = np . dtype ( [ <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT:size>' , np . float32 , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:4> ) , <EOL> ( '<STR_LIT>' , np . float32 , <NUM_LIT:1> ) <EOL> ] ) <EOL> def __init__ ( self , parent ) : <EOL> Visual . __init__ ( self , self . ARROWHEAD_VERTEX_SHADER , <EOL> self . ARROWHEAD_FRAGMENT_SHADER ) <EOL> self . _parent = parent <EOL> self . set_gl_state ( depth_test = False , blend = True , <EOL> blend_func = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . _draw_mode = '<STR_LIT>' <EOL> def _prepare_transforms ( self , view ) : <EOL> xform = view . transforms . get_transform ( ) <EOL> view . view_program . vert [ '<STR_LIT>' ] = xform <EOL> def _prepare_draw ( self , view = None ) : <EOL> if self . _parent . _arrows_changed : <EOL> self . _prepare_vertex_data ( ) <EOL> self . shared_program . bind ( self . _arrow_vbo ) <EOL> self . shared_program [ '<STR_LIT>' ] = <NUM_LIT:1.0> <EOL> self . shared_program . frag [ '<STR_LIT>' ] = self . _parent . arrow_type <EOL> self . shared_program . frag [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> def _prepare_vertex_data ( self ) : <EOL> arrows = self . _parent . arrows <EOL> if arrows is None : <EOL> return np . array ( [ ] , dtype = self . _arrow_vtype ) <EOL> v = np . zeros ( len ( arrows ) , dtype = self . _arrow_vtype ) <EOL> v [ '<STR_LIT>' ] = arrows [ : , <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> v [ '<STR_LIT>' ] = arrows [ : , <NUM_LIT:2> : <NUM_LIT:4> ] <EOL> v [ '<STR_LIT:size>' ] [ : ] = self . _parent . arrow_size <EOL> v [ '<STR_LIT>' ] [ : ] = self . _parent . _interpret_color ( ) <EOL> v [ '<STR_LIT>' ] [ : ] = self . _parent . width <EOL> self . _arrow_vbo = gloo . VertexBuffer ( v ) <EOL> class ArrowVisual ( LineVisual ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pos = None , color = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:1> ) , width = <NUM_LIT:1> , <EOL> connect = '<STR_LIT>' , method = '<STR_LIT>' , antialias = False , arrows = None , <EOL> arrow_type = '<STR_LIT>' , arrow_size = None ) : <EOL> self . _arrows_changed = False <EOL> self . _arrow_type = None <EOL> self . _arrow_size = None <EOL> self . _arrows = None <EOL> self . arrow_type = arrow_type <EOL> self . arrow_size = arrow_size <EOL> self . arrow_head = _ArrowHeadVisual ( self ) <EOL> LineVisual . __init__ ( self , pos , color , width , connect , method , <EOL> antialias ) <EOL> ArrowVisual . set_data ( self , arrows = arrows ) <EOL> self . add_subvisual ( self . arrow_head ) <EOL> def set_data ( self , pos = None , color = None , width = None , connect = None , <EOL> arrows = None ) : <EOL> """<STR_LIT>""" <EOL> if arrows is not None : <EOL> self . _arrows = arrows <EOL> self . _arrows_changed = True <EOL> LineVisual . set_data ( self , pos , color , width , connect ) <EOL> @ property <EOL> def arrow_type ( self ) : <EOL> return self . _arrow_type <EOL> @ arrow_type . setter <EOL> def arrow_type ( self , value ) : <EOL> if value not in ARROW_TYPES : <EOL> raise ValueError ( <EOL> "<STR_LIT>" . format ( <EOL> value , "<STR_LIT:U+002CU+0020>" . join ( ARROW_TYPES ) <EOL> ) <EOL> ) <EOL> if value == self . _arrow_type : <EOL> return <EOL> self . _arrow_type = value <EOL> self . _arrows_changed = True <EOL> @ property <EOL> def arrow_size ( self ) : <EOL> return self . _arrow_size <EOL> @ arrow_size . setter <EOL> def arrow_size ( self , value ) : <EOL> if value is None : <EOL> self . _arrow_size = <NUM_LIT> <EOL> else : <EOL> if value <= <NUM_LIT:0.0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _arrow_size = value <EOL> self . _arrows_changed = True <EOL> @ property <EOL> def arrows ( self ) : <EOL> return self . _arrows </s>
