<s> import math <EOL> import numpy as np <EOL> from OpenGL . GL import * <EOL> from Torus5dModule import * <EOL> from boxfish . gl . glutils import * <EOL> from OpenGL . GLUT import * <EOL> from OpenGL . GLE import glePolyCylinder <EOL> class Torus5dViewSlice4d ( Torus5dGLWidget ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent , dataModel ) : <EOL> '''<STR_LIT>''' <EOL> super ( Torus5dViewSlice4d , self ) . __init__ ( parent , dataModel , rotation = True ) <EOL> self . resizeSignal . connect ( self . updateDrawing ) <EOL> self . drawELinks = False <EOL> self . drawOnlyELinks = False <EOL> self . plane_spacing = <NUM_LIT:10> <EOL> self . drawDepthLinks = False <EOL> self . drawOnlyDepthLinks = False <EOL> self . switchedCurrentEDim = False <EOL> self . link_width = <NUM_LIT> <EOL> self . right_drag = False <EOL> self . insetEDim = True <EOL> self . oldInsetEDim = False <EOL> self . eDimSpacingFactor = <NUM_LIT> <EOL> self . toolBarSelected = False <EOL> self . toolBarPos = '<STR_LIT:right>' <EOL> self . toolBarFlip = False <EOL> self . iconAspectRatio = <NUM_LIT> <EOL> self . numIcons = <NUM_LIT:5> <EOL> self . showGrid = True <EOL> Qt . ShiftModifier = False <EOL> self . widget3dLists = [ ] <EOL> self . nodeList = DisplayList ( self . drawNodes ) <EOL> self . linkList = DisplayList ( self . drawLinks ) <EOL> self . gridList = DisplayList ( self . drawGrid ) <EOL> self . widget3dLists . append ( self . nodeList ) <EOL> self . widget3dLists . append ( self . linkList ) <EOL> self . widget3dLists . append ( self . gridList ) <EOL> self . widget2dLists = [ ] <EOL> self . toolBarList = DisplayList ( self . drawToolBar ) <EOL> self . widget2dLists . append ( self . toolBarList ) <EOL> self . updateAxis ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> shape = property ( fget = lambda self : self . dataModel . shape ) <EOL> view_planes = property ( fget = lambda self : self . dataModel . view_planes ) <EOL> current_planes = property ( fget = lambda self : self . dataModel . current_planes ) <EOL> def initializeGL ( self ) : <EOL> '''<STR_LIT>''' <EOL> super ( Torus5dViewSlice4d , self ) . initializeGL ( ) <EOL> glEnable ( GL_BLEND ) <EOL> glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) <EOL> glLineWidth ( self . link_width ) <EOL> def resetView ( self ) : <EOL> slice_shape = self . getSliceShape ( ) <EOL> w_span , h_span = slice_shape [ <NUM_LIT:0> ] , slice_shape [ <NUM_LIT:1> ] <EOL> if w_span != <NUM_LIT:0> and h_span != <NUM_LIT:0> : <EOL> spans = self . getSliceSpan ( slice_shape ) <EOL> aspect = self . width ( ) / float ( self . height ( ) ) <EOL> fovy = float ( self . fov ) * math . pi / <NUM_LIT> <EOL> disty = spans [ <NUM_LIT:1> ] / <NUM_LIT> / math . tan ( fovy ) <EOL> fovx = fovy * aspect <EOL> distx = spans [ <NUM_LIT:0> ] / <NUM_LIT> / math . tan ( fovx ) <EOL> self . translation = [ <NUM_LIT:0> , <NUM_LIT:0> , - <NUM_LIT> * max ( distx , disty ) ] <EOL> def update ( self , colors = True , nodes = True , links = True , reset = True ) : <EOL> '''<STR_LIT>''' <EOL> if colors : super ( Torus5dViewSlice4d , self ) . update ( ) <EOL> if reset : self . resetView ( ) <EOL> self . updateDrawing ( nodes , links ) <EOL> def updateDrawing ( self , nodes = True , links = True , grid = True , toolBar = True ) : <EOL> '''<STR_LIT>''' <EOL> if nodes : self . nodeList . update ( ) <EOL> if links : self . linkList . update ( ) <EOL> if grid : self . gridList . update ( ) <EOL> if toolBar : <EOL> self . updateToolBarPos ( ) <EOL> self . toolBarList . update ( ) <EOL> self . paintEvent ( None ) <EOL> def updateAxis ( self , axis , axis_index = - <NUM_LIT:1> ) : <EOL> '''<STR_LIT>''' <EOL> if self . axis != axis or self . axis_index != axis_index : <EOL> if axis_index == - <NUM_LIT:1> : <EOL> if self . axis == axis : <EOL> self . axis_index = self . getNextAxisIndex ( ) <EOL> else : <EOL> self . axis_index = <NUM_LIT:0> <EOL> self . axis = axis <EOL> else : <EOL> self . axis = axis <EOL> self . axis_index = axis_index <EOL> self . update ( colors = False , links = True , nodes = True , reset = True ) <EOL> def updateToolBarPos ( self ) : <EOL> '''<STR_LIT>''' <EOL> w_horiz = self . width ( ) <EOL> eff_size = min ( self . width ( ) , self . height ( ) ) <EOL> w_vert = max ( int ( eff_size * <NUM_LIT> ) , <NUM_LIT:50> ) <EOL> w_vert = min ( w_vert , <NUM_LIT> ) <EOL> h_horiz = max ( int ( eff_size * <NUM_LIT> ) , <NUM_LIT:50> ) <EOL> h_horiz = min ( h_horiz , <NUM_LIT> ) <EOL> h_vert = self . height ( ) <EOL> x_right = int ( self . width ( ) - w_vert ) <EOL> y_top = int ( self . height ( ) - h_horiz ) <EOL> y_right = x_left = y_left = x_top = x_bottom = y_bottom = <NUM_LIT:0> <EOL> self . toolBarDims = { '<STR_LIT:left>' : [ [ x_left , x_left + w_vert ] , [ y_left , y_left + h_vert ] ] , <EOL> '<STR_LIT:right>' : [ [ x_right , x_right + w_vert ] , [ y_right , y_right + h_vert ] ] , <EOL> '<STR_LIT>' : [ [ x_top , x_top + w_horiz ] , [ y_top , y_top + h_horiz ] ] , <EOL> '<STR_LIT>' : [ [ x_bottom , x_bottom + w_horiz ] , [ y_bottom , y_bottom + h_horiz ] ] } <EOL> def updateIconHitBoxes ( self , indicies , vals ) : <EOL> '''<STR_LIT>''' <EOL> for i in indicies : <EOL> self . iconHitBoxes [ i ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] += vals [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . iconHitBoxes [ i ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] += vals [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> self . iconHitBoxes [ i ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] += vals [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> self . iconHitBoxes [ i ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] += vals [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> def getAxisLabelColor ( self , val ) : <EOL> if val == '<STR_LIT:a>' : <EOL> color = ( <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ) <EOL> elif val == '<STR_LIT:b>' : <EOL> color = ( <NUM_LIT:0.1> , <NUM_LIT:0.1> , <NUM_LIT:1.> , <NUM_LIT:1.> ) <EOL> elif val == '<STR_LIT:c>' : <EOL> color = ( <NUM_LIT:1.> , <NUM_LIT:0.5> , <NUM_LIT:0.1> , <NUM_LIT:1.> ) <EOL> elif val == '<STR_LIT:d>' : <EOL> color = ( <NUM_LIT> , <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT:1.> ) <EOL> elif val == '<STR_LIT:e>' : <EOL> color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.1> , <NUM_LIT:1.> ) <EOL> elif val == <NUM_LIT:0> : <EOL> color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.> ) <EOL> return tuple ( list ( np . add ( color [ : <NUM_LIT:3> ] , <NUM_LIT> ) ) + [ <NUM_LIT:1.> ] ) <EOL> def getCylinderIndex ( self , node , shape , axis ) : <EOL> """<STR_LIT>""" <EOL> dims = shape [ : axis ] + shape [ axis + <NUM_LIT:1> : ] <EOL> num_cylinders = ( min ( dims ) + <NUM_LIT:1> ) / <NUM_LIT:2> <EOL> nonaxis = node [ : axis ] + node [ axis + <NUM_LIT:1> : ] <EOL> d_near_edge = [ min ( abs ( d - n - <NUM_LIT:1> ) , n ) for n , d in zip ( nonaxis , dims ) ] <EOL> return num_cylinders - min ( d_near_edge ) - <NUM_LIT:1> <EOL> def getNextAxisIndex ( self ) : <EOL> '''<STR_LIT>''' <EOL> numIndicies = len ( self . axis_map [ self . axis ] ) <EOL> if self . axis_index == numIndicies - <NUM_LIT:1> : <EOL> return <NUM_LIT:0> <EOL> else : return self . axis_index + <NUM_LIT:1> <EOL> def getNextNode ( self , point , axis , amount ) : <EOL> """<STR_LIT>""" <EOL> p = list ( point ) <EOL> p [ axis ] += amount <EOL> return tuple ( p ) <EOL> def getNodePos2d ( self , node , shape , axis = <NUM_LIT:2> , scale = <NUM_LIT:1> ) : <EOL> '''<STR_LIT>''' <EOL> dim = range ( <NUM_LIT:3> ) <EOL> dim . remove ( axis ) <EOL> node2d = np . zeros ( <NUM_LIT:3> ) <EOL> for d in dim : <EOL> node2d [ d ] = scale * self . getSliceCoord ( shape , axis , node , d ) <EOL> node2d [ <NUM_LIT:0> ] += self . getNodeXOffset ( node [ <NUM_LIT:3> ] ) <EOL> node2d *= self . axis_directions <EOL> return node2d <EOL> def getNodePos3d ( self , node , shape = None , axis = None , scale = <NUM_LIT:1> ) : <EOL> '''<STR_LIT>''' <EOL> if shape == None : <EOL> shape = self . shape <EOL> if axis == None : <EOL> axis = self . axis <EOL> w , h , d = self . getSliceDims ( ) <EOL> slice_shape = self . getSliceShape ( ) <EOL> z_dist = node [ d ] * self . plane_spacing * self . axis_directions [ <NUM_LIT:2> ] <EOL> node2d = self . getNodePos2d ( tuple ( self . getSliceNode ( node ) + [ node [ <NUM_LIT:4> ] ] ) , slice_shape ) <EOL> return [ node2d [ <NUM_LIT:0> ] , node2d [ <NUM_LIT:1> ] , z_dist ] <EOL> def getNodeXOffset ( self , e_val ) : <EOL> '''<STR_LIT>''' <EOL> if self . insetEDim : <EOL> return ( self . getSliceSpan ( ) [ <NUM_LIT:0> ] * self . eDimSpacingFactor ) / <NUM_LIT> <EOL> elif not self . insetEDim and e_val == <NUM_LIT:1> : <EOL> return ( self . getSliceSpan ( ) [ <NUM_LIT:0> ] * self . eDimSpacingFactor ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def getSliceCoord ( self , shape , axis , node , dim ) : <EOL> lsize = self . link_pack_factor <EOL> center = float ( shape [ dim ] - <NUM_LIT:1> ) / <NUM_LIT:2> <EOL> if center == node [ dim ] : <EOL> if dim == <NUM_LIT:1> : <EOL> offset_edim = lsize * self . elink_offset_center_y <EOL> else : <EOL> offset_edim = lsize * self . elink_offset_center_x <EOL> else : <EOL> if dim == <NUM_LIT:1> : <EOL> offset_edim = np . sign ( center - node [ dim ] ) * lsize * self . elink_offset_diagonal_y <EOL> else : <EOL> offset_edim = np . sign ( center - node [ dim ] ) * lsize * self . elink_offset_diagonal_x <EOL> inset_axis = node [ axis ] * lsize * np . sign ( center - node [ dim ] ) <EOL> even = ( shape [ dim ] % <NUM_LIT:2> == <NUM_LIT:0> ) <EOL> if dim == <NUM_LIT:1> : <EOL> lgroup = ( shape [ axis ] - <NUM_LIT:1> ) + <NUM_LIT:3> + self . gap <EOL> else : <EOL> lgroup = ( shape [ axis ] - <NUM_LIT:1> ) + <NUM_LIT> + self . gap <EOL> if not self . insetEDim : <EOL> offset_edim = <NUM_LIT:0> <EOL> return lgroup * ( node [ dim ] + int ( even and node [ dim ] > center ) ) + node [ <NUM_LIT:3> ] * offset_edim + inset_axis <EOL> def getSliceDims ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . axis_map [ self . axis ] [ self . axis_index ] <EOL> def getSliceNode ( self , node5d ) : <EOL> w , h , d = self . getSliceDims ( ) <EOL> return [ node5d [ w ] , node5d [ h ] , node5d [ self . axis ] ] <EOL> def getSliceShape ( self ) : <EOL> '''<STR_LIT>''' <EOL> w , h , d = self . getSliceDims ( ) <EOL> return [ self . shape [ w ] , self . shape [ h ] , self . shape [ self . axis ] ] <EOL> def getSliceSpan ( self , shape = None , axis = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> if shape == None : <EOL> shape = self . getSliceShape ( ) <EOL> if len ( shape ) != <NUM_LIT:3> : <EOL> return <EOL> w_span = abs ( self . getSliceCoord ( shape , axis , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:0> ) - <EOL> self . getSliceCoord ( shape , axis , [ shape [ <NUM_LIT:0> ] - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:0> ) ) <EOL> h_span = abs ( self . getSliceCoord ( shape , axis , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:1> ) - <EOL> self . getSliceCoord ( shape , axis , [ <NUM_LIT:0> , shape [ <NUM_LIT:1> ] - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:1> ) ) <EOL> d_span = abs ( self . getSliceCoord ( shape , axis , [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:2> ) - <EOL> self . getSliceCoord ( shape , axis , [ <NUM_LIT:0> , <NUM_LIT:0> , shape [ <NUM_LIT:2> ] - <NUM_LIT:1> , <NUM_LIT:0> ] , <NUM_LIT:2> ) ) <EOL> return [ w_span , h_span , d_span ] <EOL> def paintEvent ( self , event ) : <EOL> with setupPaintEvent ( self ) : <EOL> glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) <EOL> glGetError ( ) <EOL> self . orient_scene ( ) <EOL> self . draw ( ) <EOL> super ( Torus5dViewSlice4d , self ) . paintEvent ( None ) <EOL> def draw ( self ) : <EOL> for func in self . widget3dLists : <EOL> func ( ) <EOL> with overlays2D ( self . width ( ) , self . height ( ) , self . bg_color ) : <EOL> for func in self . widget2dLists : <EOL> func ( ) <EOL> def drawGrid ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . showGrid : <EOL> return <EOL> offset_y = - <NUM_LIT:3> <EOL> step_size = <NUM_LIT:3> <EOL> start_x , start_y , start_z = self . getNodePos3d ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> if self . insetEDim : <EOL> end_node = [ self . shape [ i ] - <NUM_LIT:1> if i != self . axis and i != len ( self . shape ) - <NUM_LIT:1> <EOL> else <NUM_LIT:0> for i in range ( len ( self . shape ) ) ] <EOL> else : <EOL> end_node = [ self . shape [ i ] - <NUM_LIT:1> if i != self . axis else <NUM_LIT:0> <EOL> for i in range ( len ( self . shape ) ) ] <EOL> end_x , end_y , end_z = self . getNodePos3d ( end_node ) <EOL> grid_y = min ( start_y , end_y ) + offset_y <EOL> grid_x_start = min ( start_x , end_x ) - <NUM_LIT> * abs ( start_x - end_x ) <EOL> grid_x_end = max ( start_x , end_x ) + <NUM_LIT> * abs ( start_x - end_x ) <EOL> grid_z_start = min ( start_z , end_z ) - <NUM_LIT> * abs ( start_z - end_z ) <EOL> grid_z_end = max ( start_z , end_z ) + <NUM_LIT> * abs ( start_z - end_z ) <EOL> grey_value = ( self . bg_color [ <NUM_LIT:0> ] + self . bg_color [ <NUM_LIT:1> ] + self . bg_color [ <NUM_LIT:2> ] ) / <NUM_LIT:3> <EOL> if grey_value >= <NUM_LIT> : <EOL> line_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> else : <EOL> line_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> glColor4f ( * line_color ) <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> with glMatrix ( ) : <EOL> self . centerView ( self . getSliceShape ( ) ) <EOL> for i in np . arange ( grid_x_start , grid_x_end , step_size ) : <EOL> for j in np . arange ( grid_z_start , grid_z_end , step_size ) : <EOL> with glSection ( GL_LINE_LOOP ) : <EOL> glVertex3f ( i , grid_y , j ) <EOL> glVertex3f ( i + step_size , grid_y , j ) <EOL> glVertex3f ( i + step_size , grid_y , j + step_size ) <EOL> glVertex3f ( i , grid_y , j + step_size ) <EOL> def drawLinks ( self ) : <EOL> self . drawLinks3d ( self . link_colors ) <EOL> def drawNodes ( self ) : <EOL> if self . node_colors . shape [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> return <EOL> glPushMatrix ( ) <EOL> slice_shape = self . getSliceShape ( ) <EOL> self . centerView ( slice_shape ) <EOL> w , h , d = self . getSliceDims ( ) <EOL> higher_dims = [ i for i in range ( len ( self . shape ) ) if i not in [ w , h , d , self . axis ] ] <EOL> for node5d in np . ndindex ( * self . shape ) : <EOL> glPushMatrix ( ) <EOL> if ( node5d [ d ] , node5d [ <NUM_LIT:4> ] ) in self . view_planes [ d ] : <EOL> node3d = self . getNodePos3d ( node5d , self . shape , self . axis ) <EOL> glTranslatef ( * node3d ) <EOL> index = [ node5d [ i ] for i in range ( len ( self . shape ) ) ] <EOL> glColor4f ( * self . node_colors [ index [ <NUM_LIT:0> ] , index [ <NUM_LIT:1> ] , index [ <NUM_LIT:2> ] , index [ <NUM_LIT:3> ] , index [ <NUM_LIT:4> ] ] ) <EOL> notGlutSolidCube ( self . node_size ) <EOL> glPopMatrix ( ) <EOL> glPopMatrix ( ) <EOL> def drawToolBar ( self ) : <EOL> if max ( self . shape ) == <NUM_LIT:0> : <EOL> return <EOL> self . bright_bg_color = ( ( self . bg_color [ <NUM_LIT:0> ] + self . bg_color [ <NUM_LIT:1> ] + self . bg_color [ <NUM_LIT:2> ] ) / <NUM_LIT:3> ) >= <NUM_LIT:0.5> <EOL> if self . bright_bg_color : <EOL> fill_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> line_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> else : <EOL> fill_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> line_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> glEnable ( GL_BLEND ) <EOL> glBlendFunc ( GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) <EOL> x = self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> w = self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] - x <EOL> y = self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> h = self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] - y <EOL> self . iconHitBoxes = [ [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:0> , <NUM_LIT:0> ] ] for i in range ( self . numIcons ) ] <EOL> setup_overlay2D ( x , y , w , h ) <EOL> with glMatrix ( ) : <EOL> glLoadIdentity ( ) <EOL> glTranslatef ( x , y , <NUM_LIT:0.> ) <EOL> self . updateIconHitBoxes ( range ( self . numIcons ) , [ [ x , x ] , [ y , y ] ] ) <EOL> if self . toolBarSelected : <EOL> if self . bright_bg_color : <EOL> glColor4f ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.1> ) <EOL> else : <EOL> glColor4f ( <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:1.> , <NUM_LIT:0.1> ) <EOL> if self . toolBarPos == '<STR_LIT>' or self . toolBarPos == '<STR_LIT>' : <EOL> eff_w = w <EOL> eff_h = h * self . iconAspectRatio <EOL> else : <EOL> eff_w = w <EOL> eff_h = h <EOL> with glMatrix ( ) : <EOL> if self . toolBarPos == '<STR_LIT>' : <EOL> glTranslatef ( <NUM_LIT:0.> , h - eff_h , <NUM_LIT:0.> ) <EOL> self . updateIconHitBoxes ( range ( self . numIcons ) , [ [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ h - eff_h , h - eff_h ] ] ) <EOL> with glSection ( GL_QUADS ) : <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , - <NUM_LIT> ) <EOL> glVertex3f ( eff_w , <NUM_LIT:0.> , - <NUM_LIT> ) <EOL> glVertex3f ( eff_w , eff_h , - <NUM_LIT> ) <EOL> glVertex3f ( <NUM_LIT:0.> , eff_h , - <NUM_LIT> ) <EOL> if self . toolBarPos == '<STR_LIT:left>' or self . toolBarPos == '<STR_LIT:right>' : <EOL> width_lrg = w * <NUM_LIT> <EOL> height_lrg = width_lrg * self . iconAspectRatio <EOL> width_sm = width_lrg <EOL> height_sm = width_sm / <NUM_LIT> <EOL> center_sm = ( width_lrg - width_sm ) / <NUM_LIT> <EOL> else : <EOL> width_lrg = h * <NUM_LIT> <EOL> height_lrg = width_lrg * self . iconAspectRatio <EOL> width_sm = width_lrg <EOL> height_sm = width_sm / <NUM_LIT> <EOL> center_sm = ( height_lrg - height_sm ) / <NUM_LIT> <EOL> space = width_lrg * <NUM_LIT:0.1> <EOL> icon_x = w - width_lrg - space <EOL> if self . toolBarPos == '<STR_LIT>' : <EOL> icon_y = space <EOL> else : <EOL> icon_y = h - height_lrg - space <EOL> if self . toolBarPos == '<STR_LIT:left>' or self . toolBarPos == '<STR_LIT:right>' : <EOL> spread_button_x = w - space - width_sm - center_sm <EOL> spread_button_y = icon_y - <NUM_LIT:2> * space - height_sm <EOL> link_button_x = spread_button_x <EOL> link_button_y = spread_button_y - <NUM_LIT:2> * space - height_sm <EOL> if self . toolBarFlip : <EOL> icon_y = space <EOL> spread_button_y = icon_y + height_lrg + <NUM_LIT:2> * space <EOL> link_button_y = spread_button_y + height_sm + <NUM_LIT:2> * space <EOL> else : <EOL> spread_button_x = icon_x - <NUM_LIT:2> * space - width_sm <EOL> if self . toolBarPos == '<STR_LIT>' : <EOL> spread_button_y = space + center_sm <EOL> else : <EOL> spread_button_y = h - space - height_sm - center_sm <EOL> link_button_x = spread_button_x - <NUM_LIT:2> * space - width_sm <EOL> link_button_y = spread_button_y <EOL> if self . toolBarFlip : <EOL> icon_x = space <EOL> spread_button_x = icon_x + width_lrg + <NUM_LIT:2> * space <EOL> link_button_x = spread_button_x + width_sm + <NUM_LIT:2> * space <EOL> self . drawButtonViewToggle ( icon_x , icon_y , width_lrg , height_lrg , line_color , fill_color ) <EOL> self . drawButtonPlusMinus ( spread_button_x , spread_button_y , width_sm , height_sm , line_color , fill_color ) <EOL> self . drawButtonLinkToggle ( link_button_x , link_button_y , width_sm , height_sm , line_color , fill_color ) <EOL> glDisable ( GL_BLEND ) <EOL> def centerView ( self , slice_shape , axis = <NUM_LIT:2> , scale = <NUM_LIT:1> ) : <EOL> half_spans = np . array ( self . getSliceSpan ( slice_shape ) , np . float ) / - <NUM_LIT:2> <EOL> half_spans [ axis ] = <NUM_LIT:0> <EOL> half_spans *= self . axis_directions <EOL> half_spans *= scale <EOL> if self . insetEDim : <EOL> half_spans [ <NUM_LIT:0> ] -= self . getNodeXOffset ( <NUM_LIT:1> ) <EOL> else : <EOL> half_spans [ <NUM_LIT:0> ] -= self . getNodeXOffset ( <NUM_LIT:1> ) / <NUM_LIT> <EOL> glTranslatef ( * half_spans ) <EOL> def drawButtonLinkToggle ( self , x , y , w , h , line_color , fill_color ) : <EOL> deselect_color = np . divide ( np . add ( line_color , fill_color ) , <NUM_LIT> ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( x , y , <NUM_LIT:0.> ) <EOL> self . updateIconHitBoxes ( [ <NUM_LIT:3> ] , [ [ x , x + w / <NUM_LIT> ] , [ y , y + h ] ] ) <EOL> self . updateIconHitBoxes ( [ <NUM_LIT:4> ] , [ [ x + w / <NUM_LIT> , x + w ] , [ y , y + h ] ] ) <EOL> border_width = <NUM_LIT:1.> <EOL> self . drawRectSplit ( w , h , border_width , line_color , fill_color ) <EOL> glTranslatef ( border_width , border_width , <NUM_LIT:0.> ) <EOL> w = ( w - <NUM_LIT:3> * border_width ) / <NUM_LIT> <EOL> h = h - <NUM_LIT:2> * border_width <EOL> w_dim , h_dim , d_dim = self . getSliceDims ( ) <EOL> d_char = self . parent . agent . coords [ d_dim ] <EOL> if self . drawDepthLinks : <EOL> glColor4f ( * self . getAxisLabelColor ( d_char ) ) <EOL> else : <EOL> glColor4f ( * deselect_color ) <EOL> self . drawBorderPrecise ( w , h , <NUM_LIT> , <NUM_LIT:0.1> ) <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> glColor4f ( * line_color ) <EOL> eff_size = min ( w , h ) <EOL> scale_factor = eff_size * <NUM_LIT> <EOL> with glMatrix ( ) : <EOL> glTranslatef ( w * <NUM_LIT> , h * <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glScalef ( scale_factor , scale_factor , <NUM_LIT:1.> ) <EOL> glutStrokeCharacter ( GLUT_STROKE_ROMAN , ord ( d_char ) ) <EOL> glTranslatef ( w + border_width , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> e_char = self . parent . agent . coords [ <NUM_LIT:4> ] <EOL> if self . drawELinks : <EOL> glColor4f ( * self . getAxisLabelColor ( e_char ) ) <EOL> else : <EOL> glColor4f ( * deselect_color ) <EOL> self . drawBorderPrecise ( w , h , <NUM_LIT> , <NUM_LIT:0.1> ) <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> glColor4f ( * line_color ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( w * <NUM_LIT> , h * <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glScalef ( scale_factor , scale_factor , <NUM_LIT:1.> ) <EOL> glutStrokeCharacter ( GLUT_STROKE_ROMAN , ord ( e_char ) ) <EOL> def drawButtonPlusMinus ( self , x , y , w , h , line_color , fill_color ) : <EOL> with glMatrix ( ) : <EOL> glTranslatef ( x , y , <NUM_LIT:0.> ) <EOL> self . updateIconHitBoxes ( [ <NUM_LIT:1> ] , [ [ x , x + w / <NUM_LIT> ] , [ y , y + h ] ] ) <EOL> self . updateIconHitBoxes ( [ <NUM_LIT:2> ] , [ [ x + w / <NUM_LIT> , x + w ] , [ y , y + h ] ] ) <EOL> border_width = <NUM_LIT:1.> <EOL> self . drawRectSplit ( w , h , border_width , line_color , fill_color ) <EOL> glTranslatef ( border_width , border_width , <NUM_LIT:0.> ) <EOL> if self . bright_bg_color : <EOL> offset = - <NUM_LIT:0.1> <EOL> else : <EOL> offset = <NUM_LIT:0.1> <EOL> sign_color = ( line_color [ <NUM_LIT:0> ] + offset , line_color [ <NUM_LIT:1> ] + offset , line_color [ <NUM_LIT:2> ] + offset , line_color [ <NUM_LIT:3> ] ) <EOL> w = ( w - <NUM_LIT:3> * border_width ) / <NUM_LIT> <EOL> h = h - <NUM_LIT:2> * border_width <EOL> line_len = min ( w , h ) * <NUM_LIT> <EOL> x_start = w - line_len <EOL> x_end = w - x_start <EOL> y_start = h - line_len <EOL> y_end = h - y_start <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> glColor4f ( * sign_color ) <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( x_start , h / <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glVertex3f ( x_end , h / <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glTranslatef ( border_width + w , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( x_start , h / <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glVertex3f ( x_end , h / <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glVertex3f ( w / <NUM_LIT> , y_start , <NUM_LIT:0.> ) <EOL> glVertex3f ( w / <NUM_LIT> , y_end , <NUM_LIT:0.> ) <EOL> def drawButtonViewToggle ( self , x , y , w , h , line_color , fill_color ) : <EOL> '''<STR_LIT>''' <EOL> e0_color = ( <NUM_LIT:0.1> , <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT:1.> ) <EOL> e1_color = ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.1> , <NUM_LIT:1.> ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( x , y , <NUM_LIT:0.> ) <EOL> self . updateIconHitBoxes ( [ <NUM_LIT:0> ] , [ [ x , x + w ] , [ y , y + h ] ] ) <EOL> if self . drawELinks : <EOL> alpha_offset = <NUM_LIT> <EOL> line_color = list ( line_color ) <EOL> line_color [ <NUM_LIT:3> ] = max ( <NUM_LIT:0.> , line_color [ <NUM_LIT:3> ] - alpha_offset * <NUM_LIT> ) <EOL> line_color = tuple ( line_color ) <EOL> e0_color = list ( e0_color ) <EOL> e0_color [ <NUM_LIT:3> ] = max ( <NUM_LIT:0.> , e0_color [ <NUM_LIT:3> ] - alpha_offset ) <EOL> e0_color = tuple ( e0_color ) <EOL> e1_color = list ( e1_color ) <EOL> e1_color [ <NUM_LIT:3> ] = max ( <NUM_LIT:0.> , e1_color [ <NUM_LIT:3> ] - alpha_offset ) <EOL> e1_color = tuple ( e1_color ) <EOL> self . drawRect ( w , h , - <NUM_LIT> , line_color ) <EOL> border_width = <NUM_LIT:1> <EOL> glTranslatef ( border_width , border_width , <NUM_LIT:0.> ) <EOL> self . drawRect ( w - <NUM_LIT:2> * border_width , h - <NUM_LIT:2> * border_width , - <NUM_LIT:0.1> , fill_color ) <EOL> w -= <NUM_LIT:2> * border_width <EOL> h -= <NUM_LIT:2> * border_width <EOL> if self . insetEDim : <EOL> arrow_dir = [ '<STR_LIT:left>' , '<STR_LIT:right>' ] <EOL> glColor4f ( * e0_color ) <EOL> with glMatrix ( ) : <EOL> size = h * <NUM_LIT> <EOL> rect_min_x = ( w - ( h * <NUM_LIT> ) ) / <NUM_LIT> <EOL> rect_min_y = h * <NUM_LIT> <EOL> glTranslatef ( rect_min_x , rect_min_y , <NUM_LIT:0.> ) <EOL> self . drawBorderRegular ( size , size , <NUM_LIT> , <NUM_LIT:0.> ) <EOL> glColor4f ( * e1_color ) <EOL> with glMatrix ( ) : <EOL> sm_rect_x = ( w - ( h * <NUM_LIT> ) ) / <NUM_LIT> <EOL> sm_rect_y = h * <NUM_LIT> <EOL> glTranslatef ( sm_rect_x , sm_rect_y , <NUM_LIT:0.> ) <EOL> self . drawBorderRegular ( h * <NUM_LIT> , h * <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.> ) <EOL> else : <EOL> arrow_dir = [ '<STR_LIT:right>' , '<STR_LIT:left>' ] <EOL> border_width = <NUM_LIT> <EOL> size = h * <NUM_LIT:0.5> <EOL> space = ( w - ( <NUM_LIT:2> * size ) ) / <NUM_LIT> <EOL> rect_min_x = space <EOL> rect_min_y = h * <NUM_LIT> <EOL> offset_y = ( h - rect_min_y - size ) / <NUM_LIT> <EOL> glColor4f ( * e0_color ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( rect_min_x , rect_min_y + offset_y , <NUM_LIT:0.> ) <EOL> self . drawBorderRegular ( size , size , border_width , <NUM_LIT:0.> ) <EOL> glColor4f ( * e1_color ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( rect_min_x + size + space , rect_min_y + offset_y , <NUM_LIT:0.> ) <EOL> self . drawBorderRegular ( size , size , border_width , <NUM_LIT:0.> ) <EOL> arrow_w = w * <NUM_LIT> <EOL> arrow_h = rect_min_y * <NUM_LIT> <EOL> arrow_y = ( rect_min_y - arrow_h ) / <NUM_LIT> <EOL> glColor4f ( * e0_color ) <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( w * <NUM_LIT> , arrow_y , <NUM_LIT:0.> ) <EOL> self . drawArrow ( arrow_w , arrow_h , <NUM_LIT:0.> , arrow_dir [ <NUM_LIT:0> ] ) <EOL> glColor4f ( * e1_color ) <EOL> glLineWidth ( <NUM_LIT:1.> ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( w * <NUM_LIT> , arrow_y , <NUM_LIT:0.> ) <EOL> self . drawArrow ( arrow_w , arrow_h , <NUM_LIT:0.> , arrow_dir [ <NUM_LIT:1> ] ) <EOL> def drawLinks3d ( self , link_colors ) : <EOL> if self . link_colors . shape [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> return <EOL> glPushMatrix ( ) <EOL> slice_shape = self . getSliceShape ( ) <EOL> if max ( slice_shape ) != <NUM_LIT:0> : self . centerView ( slice_shape ) <EOL> w , h , d = self . getSliceDims ( ) <EOL> for start_node in np . ndindex ( * self . shape ) : <EOL> if ( start_node [ d ] , start_node [ <NUM_LIT:4> ] ) in self . view_planes [ d ] : <EOL> colors = link_colors [ start_node ] <EOL> start_cyl = self . getCylinderIndex ( ( start_node [ w ] , start_node [ h ] , start_node [ self . axis ] ) , <EOL> slice_shape , <NUM_LIT:2> ) <EOL> start = np . array ( self . getNodePos3d ( start_node , self . shape , self . axis ) ) <EOL> if self . drawDepthLinks : <EOL> end_node = self . getNextNode ( start_node , d , <NUM_LIT:1> ) <EOL> end = np . array ( self . getNodePos3d ( end_node , self . shape , self . axis ) ) <EOL> glColor4f ( * colors [ d ] ) <EOL> self . drawLinkCylinder ( start , end ) <EOL> if self . drawOnlyELinks or self . drawOnlyDepthLinks : <EOL> possible_dims = [ <NUM_LIT:4> ] <EOL> else : <EOL> possible_dims = [ w , h , self . axis , <NUM_LIT:4> ] <EOL> for dim in possible_dims : <EOL> end_node = self . getNextNode ( start_node , dim , <NUM_LIT:1> ) <EOL> if self . drawELinks and dim == <NUM_LIT:4> : <EOL> if start_node [ <NUM_LIT:4> ] == <NUM_LIT:0> : other_edim = <NUM_LIT:1> <EOL> else : other_edim = <NUM_LIT:0> <EOL> if ( ( start_node [ d ] , <NUM_LIT:0> ) in self . view_planes [ d ] or <EOL> ( start_node [ d ] , <NUM_LIT:1> ) in self . view_planes [ d ] ) : <EOL> end = np . array ( self . getNodePos3d ( end_node , self . shape , self . axis ) ) <EOL> glColor4f ( * colors [ dim ] ) <EOL> self . drawLinkCylinder ( start , end ) <EOL> continue <EOL> continue <EOL> if dim == <NUM_LIT:4> and not self . drawELinks : <EOL> continue <EOL> if end_node [ dim ] >= self . shape [ dim ] : <EOL> continue <EOL> end_cyl = self . getCylinderIndex ( ( end_node [ w ] , end_node [ h ] , end_node [ self . axis ] ) , <EOL> slice_shape , <NUM_LIT:2> ) <EOL> if start_cyl == end_cyl : <EOL> if start_cyl == <NUM_LIT:0> : <EOL> for t in [ w , h , self . axis ] : <EOL> if t != self . axis and t != dim : break <EOL> left_node = self . getNextNode ( start_node , t , - <NUM_LIT:1> ) <EOL> left_cyl = self . getCylinderIndex ( ( left_node [ w ] , left_node [ h ] , left_node [ self . axis ] ) , <EOL> slice_shape , <NUM_LIT:2> ) <EOL> right_node = self . getNextNode ( start_node , t , <NUM_LIT:1> ) <EOL> right_cyl = self . getCylinderIndex ( ( right_node [ w ] , right_node [ h ] , right_node [ self . axis ] ) , <EOL> slice_shape , <NUM_LIT:2> ) <EOL> if end_cyl == right_cyl and end_cyl == left_cyl : <EOL> continue <EOL> end = np . array ( self . getNodePos3d ( end_node , self . shape , self . axis ) ) <EOL> glColor4f ( * colors [ dim ] ) <EOL> self . drawLinkCylinder ( start , end ) <EOL> glPopMatrix ( ) <EOL> def drawArrow ( self , w , h , z_dist , direction ) : <EOL> '''<STR_LIT>''' <EOL> if direction == '<STR_LIT:left>' or direction == '<STR_LIT:right>' : <EOL> arrow_w = <NUM_LIT> <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , h * <NUM_LIT:0.5> , <NUM_LIT:0.> ) <EOL> glVertex3f ( w , h * <NUM_LIT:0.5> , <NUM_LIT:0.> ) <EOL> if direction == '<STR_LIT:right>' : <EOL> glTranslate ( w * ( <NUM_LIT:1> - arrow_w ) , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> self . drawArrowHead ( w * arrow_w , h , <NUM_LIT:0.1> , <NUM_LIT:1.> , direction ) <EOL> elif direction == '<STR_LIT>' or direction == '<STR_LIT>' : <EOL> arrow_h = <NUM_LIT> <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( w * <NUM_LIT:0.5> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> glVertex3f ( w * <NUM_LIT:0.5> , h , <NUM_LIT:0.> ) <EOL> if direction == '<STR_LIT>' : <EOL> glTranslatef ( <NUM_LIT:0.> , h * <NUM_LIT> , <NUM_LIT:0.> ) <EOL> self . drawArrowHead ( w , h * arrow_h , <NUM_LIT:0.1> , <NUM_LIT:1.> , direction ) <EOL> def drawBorderPrecise ( self , w , h , border_width , z_dist ) : <EOL> '''<STR_LIT>''' <EOL> glLineWidth ( border_width ) <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , border_width / <NUM_LIT> , z_dist ) <EOL> glVertex3f ( w , border_width / <NUM_LIT> , z_dist ) <EOL> glVertex3f ( w - ( border_width / <NUM_LIT> ) , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w - ( border_width / <NUM_LIT> ) , h , z_dist ) <EOL> glVertex3f ( w , h - ( border_width / <NUM_LIT> ) , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , h - ( border_width / <NUM_LIT> ) , z_dist ) <EOL> glVertex3f ( border_width / <NUM_LIT> , h , z_dist ) <EOL> glVertex3f ( border_width / <NUM_LIT> , <NUM_LIT:0.> , z_dist ) <EOL> def drawBorderRegular ( self , w , h , line_width , z_dist ) : <EOL> glLineWidth ( line_width ) <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , h , z_dist ) <EOL> glVertex3f ( w , h , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , h , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , h , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , z_dist ) <EOL> def drawLinkCylinder ( self , start , end ) : <EOL> v = end - start <EOL> cyl_points = [ tuple ( p ) for p in [ start - v , start , end , end + v ] ] <EOL> glePolyCylinder ( cyl_points , None , self . link_width / <NUM_LIT> ) <EOL> def drawLinkLine ( self , start , end ) : <EOL> """<STR_LIT>""" <EOL> glBegin ( GL_LINES ) <EOL> glVertex3fv ( start ) <EOL> glVertex3fv ( end ) <EOL> glEnd ( ) <EOL> def drawRect ( self , w , h , z_dist , color ) : <EOL> glColor4f ( * color ) <EOL> with glSection ( GL_QUADS ) : <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , h , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , h , z_dist ) <EOL> def drawRectSplit ( self , w , h , border_width , line_color , fill_color ) : <EOL> self . drawRect ( w , h , - <NUM_LIT> , line_color ) <EOL> glColor4f ( * line_color ) <EOL> glLineWidth ( border_width ) <EOL> with glSection ( GL_LINES ) : <EOL> glVertex3f ( w / <NUM_LIT> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> glVertex3f ( w / <NUM_LIT> , h , <NUM_LIT:0.> ) <EOL> with glMatrix ( ) : <EOL> glTranslatef ( border_width , border_width , <NUM_LIT:0.> ) <EOL> w -= <NUM_LIT:2> * border_width <EOL> h -= <NUM_LIT:2> * border_width <EOL> self . drawRect ( w , h , - <NUM_LIT:0.1> , fill_color ) <EOL> def drawArrowHead ( self , w , h , z_dist , size , direction ) : <EOL> '''<STR_LIT>''' <EOL> if direction == '<STR_LIT:left>' : <EOL> glTranslatef ( - <NUM_LIT:1> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> with glSection ( GL_TRIANGLES ) : <EOL> glVertex3f ( w , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , h , z_dist ) <EOL> glVertex3f ( w * ( <NUM_LIT:1> - size ) , h * <NUM_LIT:0.5> , z_dist ) <EOL> elif direction == '<STR_LIT:right>' : <EOL> glTranslatef ( <NUM_LIT:1> , <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> with glSection ( GL_TRIANGLES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w * size , h * <NUM_LIT:0.5> , z_dist ) <EOL> glVertex3f ( <NUM_LIT:0.> , h , z_dist ) <EOL> elif direction == '<STR_LIT>' : <EOL> glTranslatef ( <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ) <EOL> with glSection ( GL_TRIANGLES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w , <NUM_LIT:0.> , z_dist ) <EOL> glVertex3f ( w * <NUM_LIT:0.5> , h * size , z_dist ) <EOL> elif direction == '<STR_LIT>' : <EOL> glTranslatef ( <NUM_LIT:0.> , - <NUM_LIT:1.> , <NUM_LIT:0.> ) <EOL> with glSection ( GL_TRIANGLES ) : <EOL> glVertex3f ( <NUM_LIT:0.> , h , z_dist ) <EOL> glVertex3f ( w , h , z_dist ) <EOL> glVertex3f ( w * <NUM_LIT:0.5> , h * ( <NUM_LIT:1> - size ) , z_dist ) <EOL> def changeBounds ( self , lower = True , inc = True ) : <EOL> '''<STR_LIT>''' <EOL> if lower and inc : <EOL> self . lowerBound = min ( self . lowerBound + self . delta , <NUM_LIT:1> ) <EOL> elif lower : <EOL> self . lowerBound = max ( self . lowerBound - self . delta , <NUM_LIT:0> ) <EOL> elif not lower and inc : <EOL> self . upperBound = min ( self . upperBound + self . delta , <NUM_LIT:1> ) <EOL> elif not lower and not inc : <EOL> self . upperBound = max ( self . upperBound - self . delta , <NUM_LIT:0> ) <EOL> self . update ( colors = True , links = True , nodes = False , reset = False ) <EOL> def changeDLinkView ( self ) : <EOL> if self . drawDepthLinks and not self . drawOnlyDepthLinks and not self . drawOnlyELinks : <EOL> self . drawOnlyDepthLinks = True <EOL> elif self . drawDepthLinks : <EOL> self . drawDepthLinks = False <EOL> self . drawOnlyDepthLinks = False <EOL> else : <EOL> self . drawDepthLinks = True <EOL> self . updateDrawing ( ) <EOL> def changeELinkOffset ( self , centerX = False , centerY = False , diagonalX = False , diagonalY = False , inc = True ) : <EOL> val = <NUM_LIT> if inc else - <NUM_LIT> <EOL> if centerX : <EOL> self . elink_offset_center_x += val <EOL> if not inc : self . elink_offset_center_x = max ( <NUM_LIT> , self . elink_offset_center_x ) <EOL> if centerY : <EOL> self . elink_offset_center_y += val <EOL> if not inc : self . elink_offset_center_y = max ( <NUM_LIT> , self . elink_offset_center_y ) <EOL> if diagonalX : <EOL> self . elink_offset_diagonal_x += val <EOL> if not inc : self . elink_offset_diagonal_x = max ( <NUM_LIT> , self . elink_offset_diagonal_x ) <EOL> if diagonalY : <EOL> self . elink_offset_diagonal_y += val <EOL> if not inc : self . elink_offset_diagonal_y = max ( <NUM_LIT> , self . elink_offset_diagonal_y ) <EOL> self . updateDrawing ( ) <EOL> def changeGridStatus ( self ) : <EOL> if self . showGrid : <EOL> self . showGrid = False <EOL> else : <EOL> self . showGrid = True <EOL> self . updateDrawing ( ) <EOL> def changeToriView ( self ) : <EOL> if not self . drawELinks and self . insetEDim : <EOL> self . insetEDim = False <EOL> elif not self . drawELinks : <EOL> self . insetEDim = True <EOL> self . updateDrawing ( ) <EOL> def changeELinkView ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . insetEDim and not self . drawELinks : <EOL> self . oldInsetEDim = self . insetEDim <EOL> self . insetEDim = True <EOL> self . drawELinks = True <EOL> elif self . drawELinks and not self . drawOnlyELinks and not self . drawOnlyDepthLinks : <EOL> self . drawOnlyELinks = True <EOL> elif self . drawELinks : <EOL> self . drawELinks = False <EOL> self . insetEDim = self . oldInsetEDim <EOL> self . drawOnlyELinks = False <EOL> elif not self . drawELinks and self . drawOnlyDepthLinks : <EOL> self . drawELinks = True <EOL> self . drawOnlyELinks = True <EOL> self . oldInsetEDim = self . insetEDim <EOL> else : <EOL> self . drawELinks = True <EOL> self . oldInsetEDim = self . insetEDim <EOL> self . updateDrawing ( ) <EOL> def changeGapFactor ( self , inc = True ) : <EOL> val = <NUM_LIT:0.5> if inc else - <NUM_LIT:0.5> <EOL> self . gap += val <EOL> if not inc : self . gap = max ( <NUM_LIT:0.5> , self . gap ) <EOL> self . updateDrawing ( ) <EOL> def changeLinkWidth ( self , inc = True ) : <EOL> val = <NUM_LIT:1> if inc else - <NUM_LIT:1> <EOL> self . link_width += val <EOL> if not inc : self . link_width = max ( <NUM_LIT:1> , self . link_width ) <EOL> glLineWidth ( self . link_width ) <EOL> self . updateDrawing ( ) <EOL> def changeNodeLinkBounds ( self , lower , upper , links = True ) : <EOL> if links : <EOL> self . lowerBoundLinks = lower <EOL> self . upperBoundLinks = upper <EOL> else : <EOL> self . lowerBoundNodes = lower <EOL> self . upperBoundNodes = upper <EOL> def changeNodeSize ( self , inc ) : <EOL> val = <NUM_LIT> if inc else - <NUM_LIT> <EOL> self . node_size += val <EOL> if not inc : self . node_size = max ( <NUM_LIT> , self . node_size ) <EOL> self . updateDrawing ( ) <EOL> def changePackFactor ( self , links = False , nodes = False , inc = True ) : <EOL> val = <NUM_LIT:0.1> if inc else - <NUM_LIT:0.1> <EOL> if links : <EOL> self . link_pack_factor += val <EOL> if not inc : self . link_pack_factor = max ( <NUM_LIT:0.1> , self . link_pack_factor ) <EOL> if nodes : <EOL> self . node_pack_factor += val <EOL> if not inc : self . node_pack_factor = max ( <NUM_LIT:0.1> , self . node_pack_factor ) <EOL> self . updateDrawing ( ) <EOL> def changePlaneSpacing ( self , inc = True ) : <EOL> if inc : <EOL> if self . plane_spacing >= <NUM_LIT:1> : self . plane_spacing += <NUM_LIT:1> <EOL> else : self . plane_spacing += <NUM_LIT> <EOL> else : <EOL> if self . plane_spacing <= <NUM_LIT:1> : self . plane_spacing -= <NUM_LIT> <EOL> else : self . plane_spacing -= <NUM_LIT:1> <EOL> self . updateDrawing ( ) <EOL> def keyPressEvent ( self , event ) : <EOL> key_map = { <EOL> "<STR_LIT:e>" : lambda : self . changeELinkView ( ) , <EOL> "<STR_LIT:d>" : lambda : self . changeDLinkView ( ) , <EOL> "<STR_LIT:=>" : lambda : self . changePlaneSpacing ( inc = True ) , <EOL> "<STR_LIT:+>" : lambda : self . changePlaneSpacing ( inc = True ) , <EOL> "<STR_LIT:->" : lambda : self . changePlaneSpacing ( inc = False ) , <EOL> "<STR_LIT:_>" : lambda : self . changePlaneSpacing ( inc = False ) , <EOL> "<STR_LIT:f>" : lambda : self . resetRotation ( ) , <EOL> "<STR_LIT:F>" : lambda : self . resetRotation ( ) , <EOL> "<STR_LIT:l>" : lambda : self . changeLinkWidth ( inc = True ) , <EOL> "<STR_LIT:L>" : lambda : self . changeLinkWidth ( inc = False ) , <EOL> "<STR_LIT:n>" : lambda : self . changeNodeSize ( inc = True ) , <EOL> "<STR_LIT:N>" : lambda : self . changeNodeSize ( inc = False ) , <EOL> "<STR_LIT:<>" : lambda : self . changeBounds ( lower = True , inc = False ) , <EOL> "<STR_LIT:>>" : lambda : self . changeBounds ( lower = True , inc = True ) , <EOL> "<STR_LIT:U+002C>" : lambda : self . changeBounds ( upper = True , inc = False ) , <EOL> "<STR_LIT:.>" : lambda : self . changeBounds ( upper = True , inc = True ) <EOL> } <EOL> if event . text ( ) in key_map : <EOL> key_map [ event . text ( ) ] ( ) <EOL> else : <EOL> super ( Torus5dViewSlice4d , self ) . keyPressEvent ( event ) <EOL> def mousePressEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> super ( Torus5dViewSlice4d , self ) . mousePressEvent ( event ) <EOL> if max ( self . shape ) == <NUM_LIT:0> : <EOL> return <EOL> x = event . x ( ) <EOL> y = self . height ( ) - event . y ( ) <EOL> if event . button ( ) == Qt . LeftButton : <EOL> found = False <EOL> for i in range ( self . numIcons ) : <EOL> if x >= self . iconHitBoxes [ i ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] and x <= self . iconHitBoxes [ i ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] and y >= self . iconHitBoxes [ i ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] and y <= self . iconHitBoxes [ i ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] : <EOL> found = True <EOL> if i == <NUM_LIT:0> : <EOL> self . changeToriView ( ) <EOL> elif i == <NUM_LIT:1> : <EOL> self . changePlaneSpacing ( inc = False ) <EOL> elif i == <NUM_LIT:2> : <EOL> self . changePlaneSpacing ( inc = True ) <EOL> elif i == <NUM_LIT:3> : <EOL> self . changeDLinkView ( ) <EOL> elif i == <NUM_LIT:4> : <EOL> self . changeELinkView ( ) <EOL> if not found and x >= self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] and x <= self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] and y >= self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] and y <= self . toolBarDims [ self . toolBarPos ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] : <EOL> self . toolBarSelected = True <EOL> self . updateDrawing ( nodes = False , links = False , grid = False ) <EOL> elif event . button ( ) == Qt . RightButton : <EOL> self . right_drag = True <EOL> def mouseReleaseEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> super ( Torus5dViewSlice4d , self ) . mouseReleaseEvent ( event ) <EOL> if max ( self . shape ) == <NUM_LIT:0> : <EOL> return <EOL> if self . toolBarSelected : <EOL> self . toolBarSelected = False <EOL> self . updateDrawing ( nodes = False , links = False , grid = False ) <EOL> if self . right_drag : <EOL> self . right_drag = False <EOL> def mouseMoveEvent ( self , event ) : <EOL> if self . toolBarSelected : <EOL> x = event . x ( ) <EOL> y = self . height ( ) - event . y ( ) <EOL> pos = self . toolBarPos <EOL> outside = ( x < self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] or <EOL> x > self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] or <EOL> y < self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] or <EOL> y > self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> check_list = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:left>' , '<STR_LIT:right>' ] ) <EOL> check_list . remove ( pos ) <EOL> half_w = self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] + ( self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] - self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) / <NUM_LIT> <EOL> half_h = self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] + ( self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] - self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) / <NUM_LIT> <EOL> if ( ( pos == '<STR_LIT:right>' or pos == '<STR_LIT:left>' ) and y < half_h ) or ( ( pos == '<STR_LIT>' or pos == '<STR_LIT>' ) and x < half_w ) : <EOL> if not self . toolBarFlip : <EOL> self . toolBarFlip = True <EOL> self . updateDrawing ( nodes = False , links = False , grid = False ) <EOL> else : <EOL> if self . toolBarFlip : <EOL> self . toolBarFlip = False <EOL> self . updateDrawing ( nodes = False , links = False , grid = False ) <EOL> if outside : <EOL> for pos in check_list : <EOL> if ( x >= self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] and x <= <EOL> self . toolBarDims [ pos ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] and y >= <EOL> self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] and y <= <EOL> self . toolBarDims [ pos ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) : <EOL> self . toolBarPos = pos <EOL> self . updateDrawing ( nodes = False , links = False , grid = False ) <EOL> break <EOL> else : <EOL> super ( Torus5dViewSlice4d , self ) . mouseMoveEvent ( event ) <EOL> def resetRotation ( self ) : <EOL> self . rotation = np . identity ( <NUM_LIT:4> ) <EOL> self . updateDrawing ( ) <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" </s>
