def draw_tree(self, tree): ''' Draw the tree. ''' if self.gui_project: self.clickable_map = {} self.active_node = self.gui_project.active_node try: self.active_soft_block = self.active_node.soft_get_block() except AttributeError: self.active_soft_block = None sizes = [] pos = vectorish.add((connector_length, connector_length), self.origin) for root in tree.roots: size = self.draw_sub_tree( pos, tree, root.soft_get_block() ) pos = vectorish.add(pos, (size[0], 0)) sizes.append(size) width = sum(size[0] for size in sizes) + \ (connector_length * len(sizes)) height = max(size[1] for size in sizes) + connector_length return (self.clickable_map, (width, height))
def draw_tree(self, tree): ''' Draw the tree. ''' if self.gui_project: self.clickable_map = {} self.active_node = self.gui_project.active_node try: self.active_soft_block = self.active_node.soft_get_block() except AttributeError: self.active_soft_block = None sizes = [] pos = vectorish.add((connector_length, connector_length), self.origin) for root in tree.roots: size = self.draw_sub_tree(pos, tree, root.soft_get_block()) pos = vectorish.add(pos, (size[0], 0)) sizes.append(size) width = sum(size[0] for size in sizes) + \ (connector_length * len(sizes)) height = max(size[1] for size in sizes) + connector_length return (self.clickable_map, (width, height))
def draw_tree(self, tree): ''' Draw the tree. This will only use the part of the tree that springs from the first root! ''' self.clickable_map = {} self.active_node = self.gui_project.active_node try: self.active_soft_block = self.active_node.soft_get_block() except AttributeError: self.active_soft_block = None size = self.draw_sub_tree( vectorish.add( (connector_length, connector_length), self.origin ), tree, tree.roots[0].soft_get_block() ) (width, height) = vectorish.add(size, (connector_length, connector_length)) return (self.clickable_map, (width, height))
def draw_end(self, point, tree, start): assert isinstance(start, garlicsim.data_structures.End) if start.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[start.step_profile]) else: color = wx.Colour(204, 204, 204) bitmap = my_color_replaced_bitmap( self.tree_browser.elements['Untouched End'], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color)) self.DrawBitmapPoint(bitmap, point, useMask=True) bitmap_size = bitmap.GetSize() temp = (point[0], point[1], point[0] + bitmap_size[0], point[1] + bitmap_size[1]) self.clickable_map[temp] = start last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add(point, (bitmap_size[0] - 1, bitmap_size[1] // 2)) return (max_width, max(total_height, bitmap_size[1] + connector_length))
def draw_end(self, point, tree, start): assert isinstance(start, garlicsim.data_structures.End) if start.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[start.step_profile] ) else: color = wx.Colour(204, 204, 204) bitmap = my_color_replaced_bitmap( self.tree_browser.elements['Untouched End'], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color) ) self.DrawBitmapPoint(bitmap, point, useMask=True) bitmap_size = bitmap.GetSize() temp = (point[0], point[1], point[0] + bitmap_size[0], point[1] + bitmap_size[1]) self.clickable_map[temp] = start last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add( point, ( bitmap_size[0] - 1, bitmap_size[1] // 2 ) ) return ( max_width, max( total_height, bitmap_size[1] + connector_length ) )
def draw_end(self, point, tree, start): assert isinstance(start, garlicsim.data_structures.End) bitmap = self.tree_browser.elements['Untouched End'] self.DrawBitmapPoint(bitmap, point, useMask=True) bitmap_size = bitmap.GetSize() temp = (point[0], point[1], point[0] + bitmap_size[0], point[1] + bitmap_size[1]) self.clickable_map[temp] = start last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add( point, ( bitmap_size[0] - 1, bitmap_size[1] // 2 ) ) return ( max_width, max( total_height, bitmap_size[1] + connector_length ) )
def draw_sub_tree(self, point, tree, start): if start.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[start.step_profile]) else: color = wx.Colour(204, 204, 204) make_block_stripe = False if isinstance(start, garlicsim.data_structures.Block): type = 'Block' kids = start[-1].children if start == self.active_soft_block: make_block_stripe = True type = 'Active ' + type elif isinstance(start, garlicsim.data_structures.Node): kids = start.children if start.touched: type = 'Touched' else: type = 'Untouched' if start.still_in_editing: type = 'Unfinalized ' + type if start == self.active_soft_block: type = 'Active ' + type else: raise Exception if make_block_stripe is True: bitmap = my_color_replaced_bitmap( self.tree_browser.elements['Block'], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color)) bitmap_size = bitmap.GetSize() self.gc.DrawBitmap(bitmap, point[0], point[1], bitmap_size[0], bitmap_size[1]) bitmap_size = bitmap.GetSize() second_bitmap = self.tree_browser.elements[type] slice = [None, None] length = float(len(start)) slice[0] = start.index(self.active_node) / length slice[1] = slice[0] + (1 / length) screen_slice = [ floor(point[0] + 4 + (bitmap_size[0] - 8) * slice[0]), ceil(point[0] + 4 + (bitmap_size[0] - 8) * slice[1]) ] self.pen.SetWidth(0) self.pen.SetStyle(wx.TRANSPARENT) self.gc.SetPen(self.pen) self.gc.SetBrush(wx.Brush(wx.Colour(255, 153, 51))) self.gc.DrawRectangle(screen_slice[0], point[1] + 4, screen_slice[1] - screen_slice[0], bitmap_size[1] - 8) else: bitmap = my_color_replaced_bitmap( self.tree_browser.elements[type], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color)) bitmap_size = bitmap.GetSize() self.gc.DrawBitmap(bitmap, point[0], point[1], bitmap_size[0], bitmap_size[1]) temp = (point[0] + 1, point[1], point[0] + bitmap_size[0] - 2, point[1] + bitmap_size[1]) self.clickable_map[temp] = start del temp last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add(point, (bitmap_size[0] - 1, bitmap_size[1] // 2)) for kid in kids: line_end = vectorish.add( point, (self_width + 1, total_height + bitmap_size[1] // 2)) temp = vectorish.add(point, (self_width, total_height)) (new_width, new_height) = \ self.draw_sub_tree(temp, tree, kid.soft_get_block()) del temp if kid.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[kid.step_profile]) else: color = wx.Colour(0, 0, 0) self.pen.SetColour(wx.Colour(0, 0, 0)) self.pen.SetWidth(1) self.pen.SetStyle(wx.SOLID) self.gc.SetPen(self.pen) self.gc.StrokeLine(line_start[0], line_start[1], line_end[0], line_end[1]) max_width = max(max_width, self_width + new_width) total_height += new_height ends = start.ends if isinstance(start, garlicsim.data_structures.Node)\ else start[-1].ends for end in ends: line_end = vectorish.add( point, (self_width + 1, total_height + bitmap_size[1] // 2)) temp = vectorish.add(point, (self_width, total_height)) (new_width, new_height) = \ self.draw_end(temp, tree, end) del temp if end.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[end.step_profile]) else: color = wx.Colour(0, 0, 0) self.pen.SetColour(wx.Colour(0, 0, 0)) self.pen.SetWidth(1) self.pen.SetStyle(wx.SOLID) self.gc.SetPen(self.pen) self.gc.StrokeLine(line_start[0], line_start[1], line_end[0], line_end[1]) max_width = max(max_width, self_width + new_width) total_height += new_height return (max_width, max(total_height, bitmap_size[1] + connector_length))
def draw_sub_tree(self, point, tree, start): if start.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[start.step_profile] ) else: color = wx.Colour(204, 204, 204) make_block_stripe = False if isinstance(start, garlicsim.data_structures.Block): type = 'Block' kids = start[-1].children if start == self.active_soft_block: make_block_stripe = True type = 'Active ' + type elif isinstance(start, garlicsim.data_structures.Node): kids = start.children if start.touched: type = 'Touched' else: type = 'Untouched' if start.still_in_editing: type = 'Unfinalized ' + type if start == self.active_soft_block: type = 'Active ' + type else: raise Exception if make_block_stripe is True: bitmap = my_color_replaced_bitmap( self.tree_browser.elements['Block'], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color) ) bitmap_size = bitmap.GetSize() self.gc.DrawBitmap(bitmap, point[0], point[1], bitmap_size[0], bitmap_size[1]) bitmap_size = bitmap.GetSize() second_bitmap = self.tree_browser.elements[type] slice = [None, None] length = float(len(start)) slice[0] = start.index(self.active_node) / length slice[1] = slice[0] + (1 / length) screen_slice = [ floor(point[0] + 4 + (bitmap_size[0] - 8) * slice[0]), ceil(point[0] + 4 + (bitmap_size[0] - 8) * slice[1]) ] self.pen.SetWidth(0) self.pen.SetStyle(wx.TRANSPARENT) self.gc.SetPen(self.pen) self.gc.SetBrush(wx.Brush(wx.Colour(255, 153, 51))) self.gc.DrawRectangle(screen_slice[0], point[1] + 4, screen_slice[1] - screen_slice[0], bitmap_size[1] - 8) else: bitmap = my_color_replaced_bitmap( self.tree_browser.elements[type], (0, 255, 0), wx_tools.wx_color_to_big_rgb(color) ) bitmap_size = bitmap.GetSize() self.gc.DrawBitmap(bitmap, point[0], point[1], bitmap_size[0], bitmap_size[1]) temp = (point[0] + 1, point[1], point[0] + bitmap_size[0] - 2, point[1] + bitmap_size[1]) self.clickable_map[temp] = start del temp last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add( point, ( bitmap_size[0] - 1, bitmap_size[1] // 2 ) ) for kid in kids: line_end = vectorish.add( point, ( self_width + 1, total_height + bitmap_size[1] // 2 ) ) temp = vectorish.add(point, (self_width, total_height)) (new_width, new_height) = \ self.draw_sub_tree(temp, tree, kid.soft_get_block()) del temp if kid.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[kid.step_profile] ) else: color = wx.Colour(0, 0, 0) self.pen.SetColour(wx.Colour(0, 0, 0)) self.pen.SetWidth(1) self.pen.SetStyle(wx.SOLID) self.gc.SetPen(self.pen) self.gc.StrokeLine(line_start[0], line_start[1], line_end[0], line_end[1]) max_width = max(max_width, self_width + new_width) total_height += new_height ends = start.ends if isinstance(start, garlicsim.data_structures.Node)\ else start[-1].ends for end in ends: line_end = vectorish.add( point, ( self_width + 1, total_height + bitmap_size[1] // 2 ) ) temp = vectorish.add(point, (self_width, total_height)) (new_width, new_height) = \ self.draw_end(temp, tree, end) del temp if end.step_profile: color = garlicsim_wx.misc.colors.hue_to_light_color( self.gui_project.step_profiles_to_hues[end.step_profile] ) else: color = wx.Colour(0, 0, 0) self.pen.SetColour(wx.Colour(0, 0, 0)) self.pen.SetWidth(1) self.pen.SetStyle(wx.SOLID) self.gc.SetPen(self.pen) self.gc.StrokeLine(line_start[0], line_start[1], line_end[0], line_end[1]) max_width = max(max_width, self_width + new_width) total_height += new_height return ( max_width, max( total_height, bitmap_size[1] + connector_length ) )
def draw_sub_tree(self, point, tree, start): make_block_stripe = False if isinstance(start, garlicsim.data_structures.Block): type = "Block" kids = start[-1].children if start == self.active_soft_block: make_block_stripe = True type = "Active " + type elif isinstance(start, garlicsim.data_structures.Node): kids = start.children if start.touched: type = "Touched" else: type = "Untouched" if start == self.active_soft_block: type = "Active " + type else: raise StandardError if make_block_stripe is True: bitmap = self.elements["Block"] self.DrawBitmapPoint(bitmap, point, useMask=True) bitmap_size = bitmap.GetSize() second_bitmap = self.elements[type] slice = [None, None] length = float(len(start)) slice[0] = start.index(self.active_node) / length slice[1] = slice[0] + (1 / length) screen_slice = [ floor(point[0] + 2 + (bitmap_size[0] - 4) * slice[0]), ceil(point[0] + 2 + (bitmap_size[0] - 4) * slice[1]) ] region = wx.Region(screen_slice[0], point[1], screen_slice[1] - screen_slice[0], bitmap_size[1]) self.SetClippingRegionAsRegion(region) self.DrawBitmapPoint(second_bitmap, point, useMask=True) self.DestroyClippingRegion() else: bitmap = self.elements[type] self.DrawBitmapPoint(bitmap, point, useMask=True) bitmap_size = bitmap.GetSize() temp = (point[0], point[1], point[0] + bitmap_size[0], point[1] + bitmap_size[1]) self.clickable_map[temp] = start del temp last_height = 0 total_height = 0 self_width = bitmap_size[0] + connector_length max_width = self_width line_start = vectorish.add( point, ( bitmap_size[0] - 1, bitmap_size[1] // 2 ) ) for kid in kids: line_end = vectorish.add( point, ( self_width + 1, total_height + bitmap_size[1] // 2 ) ) temp = vectorish.add(point, (self_width, total_height)) (new_width, new_height) = \ self.draw_sub_tree(temp, tree, kid.soft_get_block()) del temp self.DrawLinePoint(line_start, line_end) max_width = max(max_width, self_width + new_width) total_height += new_height return ( max_width, max( total_height, bitmap_size[1] + connector_length ) )