def _draw_jig(self, glpane, color, highlighted=False):
        """
        [overrides superclass method]
        """
        del color
        self._update_props()
        if not self._should_draw():
            return

        drawrad = 0.1
        posns = [a.posn() for a in self.atoms]
        normcolor = self._drawing_color()

        # russ 080530: Support for patterned highlighting drawing modes.
        selected = self.picked
        patterned = isPatternedDrawing(select=selected, highlight=highlighted)
        if patterned:
            # Patterned selection drawing needs the normal drawing first.
            drawcylinder(normcolor, posns[0], posns[1], drawrad)
            startPatternedDrawing(select=selected, highlight=highlighted)
            pass
        # Draw solid color, or overlay pattern in highlight or selection color.
        drawcylinder(
            (highlighted and env.prefs[hoverHighlightingColor_prefs_key]
             or selected and env.prefs[selectionColor_prefs_key] or normcolor),
            posns[0], posns[1], drawrad)
        if patterned:
            # Reset from patterned drawing mode.
            endPatternedDrawing(select=selected, highlight=highlighted)
            pass
        return
    def _draw_jig(self, glpane, color, highlighted = False):
        """
        [overrides superclass method]
        """
        del color
        self._update_props()
        if not self._should_draw():
            return

        drawrad = 0.1
        posns = [a.posn() for a in self.atoms]
        normcolor = self._drawing_color()

        # russ 080530: Support for patterned highlighting drawing modes.
        selected = self.picked
        patterned = isPatternedDrawing(select=selected, highlight=highlighted)
        if patterned:
            # Patterned selection drawing needs the normal drawing first.
            drawcylinder( normcolor, posns[0], posns[1], drawrad)
            startPatternedDrawing(select=selected, highlight=highlighted)
            pass
        # Draw solid color, or overlay pattern in highlight or selection color.
        drawcylinder(
            (highlighted and env.prefs[hoverHighlightingColor_prefs_key] or
             selected and env.prefs[selectionColor_prefs_key] or
             normcolor), posns[0], posns[1], drawrad)
        if patterned:
            # Reset from patterned drawing mode.
            endPatternedDrawing(select=selected, highlight=highlighted)
            pass
        return
예제 #3
0
    def finish():
        """
        Finish sorting - objects recorded since "start" will
        be sorted and invoked now.
        """
        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False)  #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter.parent_csdl
        if drawing_globals.use_c_renderer:
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print("using C renderer: VBO %s enabled" %
                      (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel,
                                                     1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist

        else:
            if debug_which_renderer:
                print(
                    "using Python renderer: use_color_sorted_dls %s enabled" %
                    (drawing_globals.use_color_sorted_dls and 'IS'
                     or 'is NOT'))
                print(
                    "using Python renderer: use_color_sorted_vbos %s enabled" %
                    (drawing_globals.use_color_sorted_vbos and 'IS'
                     or 'is NOT'))
            color_groups = len(ColorSorter.sorted_by_color)
            objects_drawn = 0

            if (not (drawing_globals.allow_color_sorting
                     and drawing_globals.use_color_sorted_dls)
                    or (ColorSortedDisplayList.cache_ColorSorter
                        and drawing_globals.allow_color_sorting
                        and drawing_globals.use_color_sorted_vbos)
                    #russ 080225 Added, 080320 VBO experiment.
                    or parent_csdl is None):

                # Either all in one display list, or immediate-mode drawing.
                objects_drawn += ColorSorter.draw_sorted(
                    ColorSorter.sorted_by_color)

                #russ 080225: Moved glEndList here for displist re-org.
                if parent_csdl is not None:
                    #russ 080320: Experiment with VBO drawing from cached
                    #ColorSorter lists.
                    if (ColorSortedDisplayList.cache_ColorSorter
                            and drawing_globals.allow_color_sorting
                            and drawing_globals.use_color_sorted_vbos):
                        # Remember the ColorSorter lists for use as a
                        # pseudo-display-list.
                        parent_csdl.sorted_by_color = \
                                   ColorSorter.sorted_by_color
                    else:
                        # Terminate a single display list, created when color
                        # sorting is turned off.  Started in ColorSorter.start .
                        glEndList()
                    pass
                pass

            else:  #russ 080225

                parent_csdl.reset()
                selColor = env.prefs[selectionColor_prefs_key]

                # First build the lower level per-color sublists of primitives.
                for color, funcs in ColorSorter.sorted_by_color.iteritems():
                    sublists = [glGenLists(1), 0]

                    # Remember the display list ID for this color.
                    parent_csdl.per_color_dls.append([color, sublists])

                    glNewList(sublists[0], GL_COMPILE)
                    opacity = color[3]

                    if opacity == -1:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by an opacity of -1 (4th component of the color.)
                        glDisable(GL_LIGHTING)  # Don't forget to re-enable it!
                        pass

                    for func, params, name in funcs:
                        objects_drawn += 1
                        if name != 0:
                            glPushName(name)
                        func(params)
                        if name != 0:
                            glPopName()
                            pass
                        continue

                    if opacity == -1:
                        # Enable lighting after drawing "unshaded" objects.
                        glEnable(GL_LIGHTING)
                        pass
                    glEndList()

                    if opacity == -2:
                        # piotr 080419: Special case for drawpolycone_multicolor
                        # create another display list that ignores
                        # the contents of color_array.
                        # Remember the display list ID for this color.

                        sublists[1] = glGenLists(1)

                        glNewList(sublists[1], GL_COMPILE)

                        for func, params, name in funcs:
                            objects_drawn += 1
                            if name != 0:
                                glPushName(name)
                            if func == drawpolycone_multicolor_worker:
                                # Just to be sure, check if the func
                                # is drawpolycone_multicolor_worker
                                # and call drawpolycone_worker instead.
                                # I think in the future we can figure out
                                # a more general way of handling the
                                # GL_COLOR_MATERIAL objects. piotr 080420
                                pos_array, color_array, rad_array = params
                                drawpolycone_worker((pos_array, rad_array))
                            elif func == drawtriangle_strip_worker:
                                # piotr 080710: Multi-color modification
                                # for triangle_strip primitive (used by
                                # reduced protein style).
                                pos_array, normal_array, color_array = params
                                drawtriangle_strip_worker(
                                    (pos_array, normal_array, None))
                            if name != 0:
                                glPopName()
                                pass
                            continue
                        glEndList()

                    continue

                # Now the upper-level lists call all of the per-color sublists.
                # One with colors.
                color_dl = parent_csdl.color_dl = glGenLists(1)
                glNewList(color_dl, GL_COMPILE)

                for color, dls in parent_csdl.per_color_dls:

                    opacity = color[3]
                    if opacity < 0:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by a negative alpha.
                        glColor3fv(color[:3])
                        # piotr 080417: for opacity == -2, i.e. if
                        # GL_COLOR_MATERIAL is enabled, the color is going
                        # to be ignored, anyway, so it is not necessary
                        # to be tested here
                    else:
                        apply_material(color)

                    glCallList(dls[0])

                    continue
                glEndList()

                # A second one without any colors.
                nocolor_dl = parent_csdl.nocolor_dl = glGenLists(1)
                glNewList(nocolor_dl, GL_COMPILE)
                for color, dls in parent_csdl.per_color_dls:
                    opacity = color[3]

                    if opacity == -2 \
                       and dls[1] > 0:
                        # piotr 080420: If GL_COLOR_MATERIAL is enabled,
                        # use a regular, single color dl rather than the
                        # multicolor one. Btw, dls[1] == 0 should never
                        # happen.
                        glCallList(dls[1])
                    else:
                        glCallList(dls[0])

                glEndList()

                # A third DL implements the selected appearance.
                selected_dl = parent_csdl.selected_dl = glGenLists(1)
                glNewList(selected_dl, GL_COMPILE)
                # russ 080530: Support for patterned selection drawing modes.
                patterned = isPatternedDrawing(select=True)
                if patterned:
                    # Patterned drawing needs the colored dl drawn first.
                    glCallList(color_dl)
                    startPatternedDrawing(select=True)
                    pass
                # Draw solid color (unpatterned) or an overlay pattern, in the
                # selection color.
                apply_material(selColor)
                glCallList(nocolor_dl)
                if patterned:
                    # Reset from patterning drawing mode.
                    endPatternedDrawing(select=True)
                glEndList()

                # Use either the normal-color display list or the selected one.
                parent_csdl.selectDl()

                # Draw the newly-built display list.
                parent_csdl.draw_dl()
                pass

            ColorSorter.sorted_by_color = None
            pass
        ColorSorter.sorting = False
        return
예제 #4
0
    def draw(self,
             highlighted=False,
             selected=False,
             patterning=True,
             highlight_color=None):
        """
        Simple all-in-one interface to CSDL drawing.

        Allocate a CSDL in the parent class and fill it with the ColorSorter:
            self.csdl = ColorSortedDisplayList()
            ColorSorter.start(self.csdl)
            drawsphere(...), drawcylinder(...), drawpolycone(...), and so on.
            ColorSorter.finish()

        Then when you want to draw the display lists call csdl.draw() with the
        desired options:

        @param highlighted: Whether to draw highlighted.

        @param selected: Whether to draw selected.

        @param patterning: Whether to apply patterned drawing styles for
          highlighting and selection, according to the prefs settings.
          If not set, it's as if the solid-color prefs are chosen.

        @param highlight_color: Option to over-ride the highlight color set in
          the color scheme preferences.
        """

        patterned_highlighting = (patterning and
                                  isPatternedDrawing(highlight=highlighted))
        halo_selection = (selected and env.prefs[selectionColorStyle_prefs_key]
                          == SS_HALO)
        halo_highlighting = (
            highlighted
            and env.prefs[hoverHighlightingColorStyle_prefs_key] == HHS_HALO)
        # Normal or selected drawing are done before a patterned highlight
        # overlay, and also when not highlighting at all.  You'd think that when
        # we're drawing a solid highlight appearance, there'd be no need to draw
        # the normal appearance first, because it will be obscured by the
        # highlight.  But halo selection extends beyond the object and is only
        # obscured by halo highlighting.  [russ 080610]
        if (patterned_highlighting or not highlighted
                or (halo_selection and not halo_highlighting)):
            if selected:
                # Draw the selected appearance.  If the selection mode is
                # patterned, the selected_dl does first normal drawing and then
                # draws an overlay.
                glCallList(self.selected_dl)
            else:
                # Plain, old, solid drawing of the base object appearance.
                glCallList(self.color_dl)
                pass

        if highlighted:
            if patterned_highlighting:
                # Set up a patterned drawing mode for the following draw.
                startPatternedDrawing(highlight=highlighted)
                pass

            # Draw a highlight overlay (solid, or in an overlay pattern.)
            apply_material(highlight_color is not None and highlight_color
                           or env.prefs[hoverHighlightingColor_prefs_key])
            glCallList(self.nocolor_dl)

            if patterned_highlighting:
                # Reset from a patterned drawing mode set up above.
                endPatternedDrawing(highlight=highlighted)
                pass

            pass
        return
예제 #5
0
    def finish():
        """
        Finish sorting - objects recorded since "start" will
        be sorted and invoked now.
        """
        from utilities.debug_prefs import debug_pref, Choice_boolean_False
        debug_which_renderer = debug_pref(
            "debug print which renderer",
            Choice_boolean_False) #bruce 060314, imperfect but tolerable

        parent_csdl = ColorSorter.parent_csdl
        if drawing_globals.use_c_renderer:
            quux.shapeRendererInit()
            if debug_which_renderer:
                #bruce 060314 uncommented/revised the next line; it might have
                # to come after shapeRendererInit (not sure); it definitely has
                # to come after a graphics context is created and initialized.
                # 20060314 grantham - yes, has to come after
                # quux.shapeRendererInit .
                enabled = quux.shapeRendererGetInteger(quux.IS_VBO_ENABLED)
                print ("using C renderer: VBO %s enabled" %
                       (('is NOT', 'is')[enabled]))
            quux.shapeRendererSetUseDynamicLOD(0)
            if ColorSorter.sphereLevel != -1:
                quux.shapeRendererSetStaticLODLevels(ColorSorter.sphereLevel, 1)
            quux.shapeRendererStartDrawing()
            ColorSorter._cur_shapelist.draw()
            quux.shapeRendererFinishDrawing()
            ColorSorter.sorting = False

            # So chunks can actually record their shapelist
            # at some point if they want to
            # ColorSorter._cur_shapelist.petrify()
            # return ColorSorter._cur_shapelist      

        else:
            if debug_which_renderer:
                print ("using Python renderer: use_color_sorted_dls %s enabled"
                       % (drawing_globals.use_color_sorted_dls and 'IS'
                          or 'is NOT'))
                print ("using Python renderer: use_color_sorted_vbos %s enabled"
                       % (drawing_globals.use_color_sorted_vbos and 'IS'
                          or 'is NOT'))
            color_groups = len(ColorSorter.sorted_by_color)
            objects_drawn = 0

            if (not (drawing_globals.allow_color_sorting and
                     drawing_globals.use_color_sorted_dls)
                or (ColorSortedDisplayList.cache_ColorSorter and
                    drawing_globals.allow_color_sorting and
                    drawing_globals.use_color_sorted_vbos)
                #russ 080225 Added, 080320 VBO experiment.
                or parent_csdl is None):

                # Either all in one display list, or immediate-mode drawing.
                objects_drawn += ColorSorter.draw_sorted(
                    ColorSorter.sorted_by_color)

                #russ 080225: Moved glEndList here for displist re-org.
                if parent_csdl is not None:
                    #russ 080320: Experiment with VBO drawing from cached
                    #ColorSorter lists.
                    if (ColorSortedDisplayList.cache_ColorSorter and
                        drawing_globals.allow_color_sorting and
                        drawing_globals.use_color_sorted_vbos):
                        # Remember the ColorSorter lists for use as a
                        # pseudo-display-list.
                        parent_csdl.sorted_by_color = \
                                   ColorSorter.sorted_by_color
                    else:
                        # Terminate a single display list, created when color
                        # sorting is turned off.  Started in ColorSorter.start .
                        glEndList()
                    pass
                pass

            else: #russ 080225

                parent_csdl.reset()
                selColor = env.prefs[selectionColor_prefs_key]

                # First build the lower level per-color sublists of primitives.
                for color, funcs in ColorSorter.sorted_by_color.iteritems():
                    sublists = [glGenLists(1), 0]

                    # Remember the display list ID for this color.
                    parent_csdl.per_color_dls.append([color, sublists])

                    glNewList(sublists[0], GL_COMPILE)
                    opacity = color[3]

                    if opacity == -1:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by an opacity of -1 (4th component of the color.)
                        glDisable(GL_LIGHTING) # Don't forget to re-enable it!
                        pass

                    for func, params, name in funcs:
                        objects_drawn += 1
                        if name != 0:
                            glPushName(name)
                        func(params)
                        if name != 0:
                            glPopName()
                            pass
                        continue

                    if opacity == -1:
                        # Enable lighting after drawing "unshaded" objects.
                        glEnable(GL_LIGHTING)
                        pass
                    glEndList()

                    if opacity == -2:
                        # piotr 080419: Special case for drawpolycone_multicolor
                        # create another display list that ignores
                        # the contents of color_array.
                        # Remember the display list ID for this color.

                        sublists[1] = glGenLists(1)

                        glNewList(sublists[1], GL_COMPILE)

                        for func, params, name in funcs:
                            objects_drawn += 1
                            if name != 0:
                                glPushName(name)
                            if func == drawpolycone_multicolor_worker:
                                # Just to be sure, check if the func
                                # is drawpolycone_multicolor_worker
                                # and call drawpolycone_worker instead.
                                # I think in the future we can figure out 
                                # a more general way of handling the 
                                # GL_COLOR_MATERIAL objects. piotr 080420
                                pos_array, color_array, rad_array = params
                                drawpolycone_worker((pos_array, rad_array))
                            elif func == drawtriangle_strip_worker:
                                # piotr 080710: Multi-color modification
                                # for triangle_strip primitive (used by 
                                # reduced protein style).
                                pos_array, normal_array, color_array = params
                                drawtriangle_strip_worker((pos_array, 
                                                           normal_array,
                                                           None))
                            if name != 0:
                                glPopName()
                                pass
                            continue
                        glEndList()

                    continue

                # Now the upper-level lists call all of the per-color sublists.
                # One with colors.
                color_dl = parent_csdl.color_dl = glGenLists(1)
                glNewList(color_dl, GL_COMPILE)

                for color, dls in parent_csdl.per_color_dls:

                    opacity = color[3]
                    if opacity < 0:
                        #russ 080306: "Unshaded colors" for lines are signaled
                        # by a negative alpha.
                        glColor3fv(color[:3])
                        # piotr 080417: for opacity == -2, i.e. if
                        # GL_COLOR_MATERIAL is enabled, the color is going 
                        # to be ignored, anyway, so it is not necessary
                        # to be tested here
                    else:
                        apply_material(color)

                    glCallList(dls[0])

                    continue
                glEndList()

                # A second one without any colors.
                nocolor_dl = parent_csdl.nocolor_dl = glGenLists(1)
                glNewList(nocolor_dl, GL_COMPILE)
                for color, dls in parent_csdl.per_color_dls:                    
                    opacity = color[3]

                    if opacity == -2 \
                       and dls[1] > 0:
                        # piotr 080420: If GL_COLOR_MATERIAL is enabled,
                        # use a regular, single color dl rather than the
                        # multicolor one. Btw, dls[1] == 0 should never 
                        # happen.
                        glCallList(dls[1])
                    else:
                        glCallList(dls[0])

                glEndList()

                # A third DL implements the selected appearance.
                selected_dl = parent_csdl.selected_dl = glGenLists(1)
                glNewList(selected_dl, GL_COMPILE)
                # russ 080530: Support for patterned selection drawing modes.
                patterned = isPatternedDrawing(select = True)
                if patterned:
                    # Patterned drawing needs the colored dl drawn first.
                    glCallList(color_dl)
                    startPatternedDrawing(select = True)
                    pass
                # Draw solid color (unpatterned) or an overlay pattern, in the
                # selection color.
                apply_material(selColor)
                glCallList(nocolor_dl)
                if patterned:
                    # Reset from patterning drawing mode.
                    endPatternedDrawing(select = True)
                glEndList()

                # Use either the normal-color display list or the selected one.
                parent_csdl.selectDl()

                # Draw the newly-built display list.
                parent_csdl.draw_dl()
                pass

            ColorSorter.sorted_by_color = None
            pass
        ColorSorter.sorting = False
        return
예제 #6
0
    def draw(self, highlighted = False, selected = False,
             patterning = True, highlight_color = None):
        """
        Simple all-in-one interface to CSDL drawing.

        Allocate a CSDL in the parent class and fill it with the ColorSorter:
            self.csdl = ColorSortedDisplayList()
            ColorSorter.start(self.csdl)
            drawsphere(...), drawcylinder(...), drawpolycone(...), and so on.
            ColorSorter.finish()

        Then when you want to draw the display lists call csdl.draw() with the
        desired options:

        @param highlighted: Whether to draw highlighted.

        @param selected: Whether to draw selected.

        @param patterning: Whether to apply patterned drawing styles for
          highlighting and selection, according to the prefs settings.
          If not set, it's as if the solid-color prefs are chosen.

        @param highlight_color: Option to over-ride the highlight color set in
          the color scheme preferences.
        """

        patterned_highlighting = (patterning and
                                  isPatternedDrawing(highlight = highlighted))
        halo_selection = (selected and
                          env.prefs[selectionColorStyle_prefs_key] == SS_HALO)
        halo_highlighting = (highlighted and
                             env.prefs[hoverHighlightingColorStyle_prefs_key] == HHS_HALO)
        # Normal or selected drawing are done before a patterned highlight
        # overlay, and also when not highlighting at all.  You'd think that when
        # we're drawing a solid highlight appearance, there'd be no need to draw
        # the normal appearance first, because it will be obscured by the
        # highlight.  But halo selection extends beyond the object and is only
        # obscured by halo highlighting.  [russ 080610]
        if (patterned_highlighting or not highlighted or
            (halo_selection and not halo_highlighting)) :
            if selected:
                # Draw the selected appearance.  If the selection mode is
                # patterned, the selected_dl does first normal drawing and then
                # draws an overlay.
                glCallList(self.selected_dl)
            else:
                # Plain, old, solid drawing of the base object appearance.
                glCallList(self.color_dl)
                pass

        if highlighted:
            if patterned_highlighting:
                # Set up a patterned drawing mode for the following draw.
                startPatternedDrawing(highlight = highlighted)
                pass

            # Draw a highlight overlay (solid, or in an overlay pattern.)
            apply_material(highlight_color is not None and highlight_color
                           or env.prefs[hoverHighlightingColor_prefs_key])
            glCallList(self.nocolor_dl)

            if patterned_highlighting:
                # Reset from a patterned drawing mode set up above.
                endPatternedDrawing(highlight = highlighted)
                pass

            pass
        return