Пример #1
0
    def __init__(self, right, up, normal, mode, latticeType):
        shape.__init__(self, right, up, normal)
        # Each element is a dictionary object storing "carbon" info for a layer
        self.carbonPosDict = {}
        self.hedroPosDict = {}
        self.markedAtoms = {}
        # Each element is a dictionary for the bonds info for a layer
        self.bondLayers = {}

        self.displist = ColorSortedDisplayList()
        self.havelist = 0
        self.dispMode = mode
        self.latticeType = latticeType
        self.layerThickness = {}
        self.layeredCurves = {}  # A list of (merged bb, curves) for each layer
Пример #2
0
 def __init__(self):
     self.csdl = ColorSortedDisplayList()
     self.comparator = self._comparator_class()
     self.before_client_main_recompile() # get ready right away
     return
Пример #3
0
class ExtraChunkDisplayList(object, SubUsageTrackingMixin):
    """
    Holds one ColorSortedDisplayList used for doing some kind of extra
    drawing associated with a Chunk but not drawn as part of its main
    CSDL, along with the state that determines whether this CSDL is invalid,
    and under what conditions it will remain valid.
    
    Helps figure out when to invalidate it, redraw it, etc.
    """
    
    # class constants
    
    # Subclass must override, with a subclass of UsedValueTrackerAndComparator.
    _comparator_class = None
    
    # default values of instance variables
    
    ## valid = False -- WRONG, we use self.comparator.valid for this.

    def __init__(self):
        self.csdl = ColorSortedDisplayList()
        self.comparator = self._comparator_class()
        self.before_client_main_recompile() # get ready right away
        return

    def deallocate_displists(self):
        self.csdl.deallocate_displists()
    
    # == methods related to the client compiling its *main* display list
    # (not this extra one, but that's when it finds out what goes into
    #  this extra one, or that it needs it at all)
    
    def before_client_main_recompile(self): #e rename?
        self._drawing_functions = []
        return
    
    # During client main recompile.
    def add_another_drawing_function(self, func):
        self._drawing_functions.append( func)
        return

    def after_client_main_recompile(self): #e rename?
        ### todo: CALL THIS (when I figure out where to call it from)
        # (not urgent until it needs to do something)
        return

    # == methods for drawing self (with or without recompiling)

    def draw_nocolor_dl(self):
        if self.csdl.nocolor_dl:
            glCallList(self.csdl.nocolor_dl)
        else:
            print "unexpected: %r.draw_nocolor_dl with no nocolor_dl" % self
        return
    
    def draw_but_first_recompile_if_needed(
        self, glpane, selected = False, highlighted = False, wantlist = True):
        """
        Recompile self as needed, then draw.
        Only make internal display lists (in cases where we need to remake them)
        if wantlist is true.

        @param selected: whether to draw in selected or plain style. (The same
          csdl handles both.)

        @param highlighted: whether to draw highlighted, or not. (The same csdl
          handles both.)
        """
        graphicsMode = glpane.graphicsMode
            # note: ThumbView lacks this attribute;
            # for now, client code in Chunk worries about this,
            # and won't call us then. [bruce 080606 comment]
        context = graphicsMode
        if self.comparator.do_we_need_to_recompute(context):
            # maybe: also compare havelist, if some data not tracked
            if DEBUG_COMPARATOR:
                print "_draw_by_remaking in %r; valid = %r" % \
                      (self, self.comparator.valid)
            self._draw_by_remaking(glpane, selected, highlighted, wantlist)
        else:
            if DEBUG_COMPARATOR:
                print "_draw_by_reusing in %r" % self
            self._draw_by_reusing(glpane, selected, highlighted)
        return

    def _draw_by_remaking(self, glpane, selected, highlighted, wantlist):
        """
        """
        # modified from similar code in Chunk.draw
        if wantlist:
            match_checking_code = self.begin_tracking_usage()
                # note: method defined in superclass, SubUsageTrackingMixin
            ColorSorter.start(self.csdl, selected)
                ### REVIEW: is selected arg needed? guess yes,
                # since .finish will draw it based on the csdl state
                # which is determined by that arg. If so, this point needs
                # correcting in the docstring for csdl.draw().
        self.comparator.before_recompute()
        try:
            self._do_drawing()
        except:
            print_compact_traceback(
                "bug: exception in %r._do_drawing, skipping the rest: " % self)
            self.comparator.after_recompute()
                # note: sets self.comparator.valid (in spite of error)
            pass
        else:
            self.comparator.after_recompute()
        if wantlist:
            ColorSorter.finish()
            # needed by self.inval_display_list for gl_update
            self._glpane = glpane
            self.end_tracking_usage( match_checking_code,
                                     self.inval_display_list )
        return

    def _draw_by_reusing(self, glpane, selected, highlighted):
        """
        """
        # see also: code in Chunk.draw which uses its self.displist
        self.csdl.draw(selected = selected, highlighted = highlighted)
        return

    # ==

    def invalidate(self):
        self.comparator.invalidate()
        return

    def inval_display_list(self):
        """
        This is meant to be called when something whose usage we tracked
        (while making our display list) next changes.
        """
        # print "fyi: called %r.inval_display_list" % self # this happens
        self.invalidate()
        self._glpane.gl_update() # self._glpane should always exist
        return
    
    # ==
    
    def _do_drawing(self):
        # drawsphere(...), drawcylinder(...), drawpolycone(...), and so on.
        args = self._construct_args_for_drawing_functions()
        for func in self._drawing_functions:
            func(*args)
        return

    def _construct_args_for_drawing_functions(self):
        assert 0, "subclass must implement"
    
    pass # end of class ExtraChunkDisplayList