summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Smith <bruce@nanorex.com>2009-02-19 22:24:28 +0000
committerBruce Smith <bruce@nanorex.com>2009-02-19 22:24:28 +0000
commitcbf2ccadf75815aebf689404f457a72b4cefa36f (patch)
tree2acee487b3e3a7a4988d68b85dc1d2ce109f5eb6
parent94d1ca934446e57802fd812d2b947006b6adc948 (diff)
downloadnanoengineer-cbf2ccadf75815aebf689404f457a72b4cefa36f.tar.gz
nanoengineer-cbf2ccadf75815aebf689404f457a72b4cefa36f.zip
refactor glpane interface to draw_glpane_label
-rwxr-xr-xcad/src/command_support/GraphicsMode.py22
-rw-r--r--cad/src/graphics/model_drawing/PartDrawer.py41
-rw-r--r--cad/src/graphics/widgets/GLPane_rendering_methods.py14
-rw-r--r--cad/src/graphics/widgets/GLPane_text_and_color_methods.py54
-rwxr-xr-xcad/src/model/part.py15
-rwxr-xr-xcad/src/outtakes/prefsTree.py2
6 files changed, 82 insertions, 66 deletions
diff --git a/cad/src/command_support/GraphicsMode.py b/cad/src/command_support/GraphicsMode.py
index 5f174e04c..519c746ef 100755
--- a/cad/src/command_support/GraphicsMode.py
+++ b/cad/src/command_support/GraphicsMode.py
@@ -1,9 +1,9 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
GraphicsMode.py -- base class for "graphics modes" (display and GLPane event handling)
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
History:
@@ -565,6 +565,24 @@ class basicGraphicsMode(GraphicsMode_API):
"""
selobj.draw_in_abs_coords(glpane, hicolor)
+ def draw_glpane_label(self, glpane):
+ """
+ #doc [see doc in the glpane method we call] [#doc coord sys when called]
+
+ @note: called from GLPane.paintGL shortly after graphicsMode.Draw()
+ """
+ #bruce 090219 moved this here from part.py, renamed from draw_text_label
+ # (after refactoring it the prior day, 090218)
+
+ # (note: caller catches exceptions, so we don't have to bother)
+
+ text = self.glpane.part.glpane_label_text()
+ if text:
+ glpane.draw_glpane_label_text(text)
+ return
+
+ # ==
+
def end_selection_from_GLPane(self):
"""
GraphicsMode API method that decides whether to do some additional
diff --git a/cad/src/graphics/model_drawing/PartDrawer.py b/cad/src/graphics/model_drawing/PartDrawer.py
index 38087344e..dd167f600 100644
--- a/cad/src/graphics/model_drawing/PartDrawer.py
+++ b/cad/src/graphics/model_drawing/PartDrawer.py
@@ -14,20 +14,11 @@ Written over several years as part of class Part in part.py.
Bruce 090218 split this out of class Part.
TODO: also move part of before_drawing_model, after_drawing_model,
-and draw into here from Part; add DrawingSet features.
+and draw into here from Part; add DrawingSet features...
+Oops, changed my mind, this whole class is misguided
+and is now being cannibalized.
"""
-
-from OpenGL.GL import GL_LIGHTING
-from OpenGL.GL import glDisable
-from OpenGL.GL import GL_DEPTH_TEST
-from OpenGL.GL import glPushMatrix
-from OpenGL.GL import glPopMatrix
-from OpenGL.GL import glEnable
-
-from PyQt4.Qt import Qt
-from PyQt4.Qt import QFont, QString
-
from graphics.drawing.DrawingSet import DrawingSet
# ==
@@ -49,32 +40,6 @@ class PartDrawer(object):
# are not sensible to define here for now, but they can call methods
# in self.
- def draw_text_label(self, glpane, text):
- """
- #doc; called from GLPane.paintGL just after it calls mode.Draw()
- """
- # caller catches exceptions, so we don't have to bother
-
- del self
-
- glDisable(GL_LIGHTING)
- glDisable(GL_DEPTH_TEST)
- # Note: disabling GL_DEPTH_TEST properly affects 2d renderText
- # (as used here), but not 3d renderText. For more info see
- # today's comments in Guides.py. [bruce 081204 comment]
- glPushMatrix() # REVIEW: needed? [bruce 081204 question]
- font = QFont(QString("Helvetica"), 24, QFont.Bold)
- glpane.qglColor(Qt.red) # this needs to be impossible to miss -- not nice-looking!
- #e tho it might be better to pick one of several bright colors
- # by hashing the partname, so as to change the color when the part changes.
- # this version of renderText uses window coords (0,0 at upper left)
- # rather than model coords (but I'm not sure what point on the string-image
- # we're setting the location of here -- guessing it's bottom-left corner):
- glpane.renderText(25,40, QString(text), font)
- glPopMatrix()
- glEnable(GL_DEPTH_TEST)
- glEnable(GL_LIGHTING)
- return
def draw_drawingsets(self):
"""
diff --git a/cad/src/graphics/widgets/GLPane_rendering_methods.py b/cad/src/graphics/widgets/GLPane_rendering_methods.py
index 0d3dc405c..39988fdc3 100644
--- a/cad/src/graphics/widgets/GLPane_rendering_methods.py
+++ b/cad/src/graphics/widgets/GLPane_rendering_methods.py
@@ -13,6 +13,8 @@ TEST_DRAWING = False # True ## Debug/test switch. Never check in a True value.
if TEST_DRAWING:
from prototype.test_drawing import test_drawing
+ # review: is this needed here for its side effects?
+ # guess yes, should document if so.
pass
from OpenGL.GL import GL_DEPTH_BUFFER_BIT
@@ -464,7 +466,7 @@ class GLPane_rendering_methods(GLPane_image_methods):
# -- glRenderMode(GL_RENDER) in effect; reduced projection matrix and viewport (one pixel.)
# - 'main' -- normal drawing, main coordinate system for model (includes trackball/zoom effect)
# - 'main/Draw_after_highlighting' -- normal drawing, but after selobj is drawn ###e which coord system?
- # - 'main/draw_text_label' -- ###e
+ # - 'main/draw_glpane_label' -- ###e
# - 'selobj' -- we're calling selobj.draw_in_abs_coords (not drawing the entire model), within same coordsys as 'main'
# - 'selobj/preDraw_glselect_dict' -- like selobj, but color buffer drawing is off ###e which coord system, incl projection??
# [end]
@@ -698,16 +700,18 @@ class GLPane_rendering_methods(GLPane_image_methods):
# let parts (other than the main part) draw a text label, to warn
# the user that the main part is not being shown [bruce 050408]
+ # [but let the GM control this: moved and renamed
+ # part.draw_text_label -> GM.draw_glpane_label; bruce 090219]
try:
- self.set_drawing_phase('main/draw_text_label') #bruce 070124
- self.part.draw_text_label(self)
+ self.set_drawing_phase('main/draw_glpane_label') #bruce 070124, renamed 090219
+ self.graphicsMode.draw_glpane_label(self)
except:
# if this happens at all, it'll happen too often to bother non-debug
# users with a traceback (but always print an error message)
if debug_flags.atom_debug:
- print_compact_traceback( "atom_debug: exception in self.part.draw_text_label(self): " )
+ print_compact_traceback( "atom_debug: exception in self.graphicsMode.draw_glpane_label(self): " )
else:
- print "bug: exception in self.part.draw_text_label; use ATOM_DEBUG to see details"
+ print "bug: exception in self.graphicsMode.draw_glpane_label; use ATOM_DEBUG to see details"
self.set_drawing_phase('?')
# draw the compass (coordinate-orientation arrows) in chosen corner
diff --git a/cad/src/graphics/widgets/GLPane_text_and_color_methods.py b/cad/src/graphics/widgets/GLPane_text_and_color_methods.py
index 37429e9db..19534393d 100644
--- a/cad/src/graphics/widgets/GLPane_text_and_color_methods.py
+++ b/cad/src/graphics/widgets/GLPane_text_and_color_methods.py
@@ -1,4 +1,4 @@
-# Copyright 2004-2008 Nanorex, Inc. See LICENSE file for details.
+# Copyright 2004-2009 Nanorex, Inc. See LICENSE file for details.
"""
GLPane_text_and_color_methods.py - methods for GLPane related to
text rendering or backgroundColor/backgroundGradient
@@ -6,7 +6,7 @@ text rendering or backgroundColor/backgroundGradient
(Maybe it should be renamed GLPane_text_and_background_methods?)
@version: $Id$
-@copyright: 2004-2008 Nanorex, Inc. See LICENSE file for details.
+@copyright: 2004-2009 Nanorex, Inc. See LICENSE file for details.
bruce 080910 split this out of class GLPane
"""
@@ -14,6 +14,7 @@ bruce 080910 split this out of class GLPane
from OpenGL.GL import glEnable
from OpenGL.GL import glDisable
from OpenGL.GL import GL_LIGHTING
+from OpenGL.GL import GL_DEPTH_TEST
from OpenGL.GL import glClear
from OpenGL.GL import glClearColor
@@ -32,19 +33,17 @@ from OpenGL.GL import glLoadIdentity
from OpenGL.GL import glPushMatrix
from OpenGL.GL import glPopMatrix
+
from OpenGL.GLU import gluUnProject, gluProject
-from graphics.drawing.drawers import drawFullWindow
-
-from widgets.widget_helpers import RGBf_to_QColor
-
from PyQt4.Qt import QFontMetrics
from PyQt4.Qt import QFont, QString
from PyQt4.Qt import QPalette
from PyQt4.Qt import QColor
+from PyQt4.Qt import Qt
+
-import foundation.env as env
from utilities.debug import print_compact_stack
from utilities.constants import black, white
@@ -62,6 +61,14 @@ from utilities.prefs_constants import backgroundGradient_prefs_key
from utilities.prefs_constants import originAxisColor_prefs_key
+import foundation.env as env
+
+from graphics.drawing.drawers import drawFullWindow
+
+from widgets.widget_helpers import RGBf_to_QColor
+
+# ==
+
assert bgSOLID == 0 # some code in GLPane depends on this
# ==
@@ -110,6 +117,39 @@ class GLPane_text_and_color_methods(object):
private mixin for providing text- and color-related methods
to class GLPane
"""
+
+ def draw_glpane_label_text(self, text):
+ """
+ Draw a text label for the glpane as a whole.
+
+ @note: called indirectly from GLPane.paintGL shortly after
+ it calls graphicsMode.Draw(), via GraphicsMode.draw_glpane_label
+ """
+ #bruce 090219 moved this here from part of Part.draw_text_label
+ # (after a temporary stop in the short-lived class PartDrawer);
+ # the other part is now our caller GraphicsMode.draw_glpane_label.
+
+ # (note: caller catches exceptions, so we don't have to bother)
+
+ glDisable(GL_LIGHTING)
+ glDisable(GL_DEPTH_TEST)
+ # Note: disabling GL_DEPTH_TEST properly affects 2d renderText
+ # (as used here), but not 3d renderText. For more info see
+ # today's comments in Guides.py. [bruce 081204 comment]
+ glPushMatrix() # REVIEW: needed? [bruce 081204 question]
+ font = QFont(QString("Helvetica"), 24, QFont.Bold)
+ self.qglColor(Qt.red) # this needs to be impossible to miss -- not nice-looking!
+ #e tho it might be better to pick one of several bright colors
+ # by hashing the partname, so as to change the color when the part changes.
+ # this version of renderText uses window coords (0,0 at upper left)
+ # rather than model coords (but I'm not sure what point on the string-image
+ # we're setting the location of here -- guessing it's bottom-left corner):
+ self.renderText(25,40, QString(text), font)
+ glPopMatrix()
+ glEnable(GL_DEPTH_TEST)
+ glEnable(GL_LIGHTING)
+ return
+
def renderTextAtPosition(self,
position,
textString,
diff --git a/cad/src/model/part.py b/cad/src/model/part.py
index 8fa3e1cec..220016148 100755
--- a/cad/src/model/part.py
+++ b/cad/src/model/part.py
@@ -1153,18 +1153,7 @@ class Part( jigmakers_Mixin, InvalMixin, StateMixin,
del self._drawing_frame_class # expose class default value
return
- def draw_text_label(self, glpane):
- """
- #doc; called from GLPane.paintGL just after it calls mode.Draw()
- """
- # caller catches exceptions, so we don't have to bother
- text = self.glpane_text()
- if text:
- #bruce 090218 refactored this
- self._drawer.draw_text_label(glpane, text)
- return
-
- def glpane_text(self):
+ def glpane_label_text(self): #bruce 090219 renamed from glpane_text
return "" # default implem, subclasses might override this
def writepov(self, f, dispdef): # revised, bruce 090218
@@ -1337,7 +1326,7 @@ class MainPart(Part):
pass
class ClipboardItemPart(Part):
- def glpane_text(self):
+ def glpane_label_text(self):
#e abbreviate long names...
return "%s (%s)" % (self.topnode.name, self.location_name())
def location_name(self):
diff --git a/cad/src/outtakes/prefsTree.py b/cad/src/outtakes/prefsTree.py
index 3e72bc717..77315cd70 100755
--- a/cad/src/outtakes/prefsTree.py
+++ b/cad/src/outtakes/prefsTree.py
@@ -147,7 +147,7 @@ class MainPrefsGroupPart(Part):
[public, meant to be imported and used by code in assembly.py]
"""
def immortal(self): return True
- def glpane_text(self):
+ def glpane_label_text(self):
return "(preferences area; not in the mmp file)"
def location_name(self):
return "prefs tree" #k used??