From 842e49189c67871be0c0d27eaa695be4bd63f1da Mon Sep 17 00:00:00 2001
From: Bruce Smith <bruce@nanorex.com>
Date: Wed, 11 Mar 2009 00:47:28 +0000
Subject: split many Draw methods into their 4 new parts; not fully tested

---
 .../LineMode/Line_GraphicsMode.py                  |  78 +++++++++------
 .../temporary_commands/RotateAboutPoint_Command.py | 111 +++++----------------
 cad/src/temporary_commands/TemporaryCommand.py     |  52 +++++-----
 3 files changed, 102 insertions(+), 139 deletions(-)

(limited to 'cad/src/temporary_commands')

diff --git a/cad/src/temporary_commands/LineMode/Line_GraphicsMode.py b/cad/src/temporary_commands/LineMode/Line_GraphicsMode.py
index 6c9ae02cc..77407892e 100644
--- a/cad/src/temporary_commands/LineMode/Line_GraphicsMode.py
+++ b/cad/src/temporary_commands/LineMode/Line_GraphicsMode.py
@@ -1,8 +1,8 @@
-# Copyright 2007-2008 Nanorex, Inc.  See LICENSE file for details. 
+# Copyright 2007-2009 Nanorex, Inc.  See LICENSE file for details. 
 """
 @author:    Ninad
 @version:   $Id$
-@copyright: 2007-2008 Nanorex, Inc.  See LICENSE file for details.
+@copyright: 2007-2009 Nanorex, Inc.  See LICENSE file for details.
 @license:   GPL
 
 History:
@@ -22,18 +22,18 @@ TODOs:
 
 """
 
-from commands.Select.Select_GraphicsMode import Select_GraphicsMode
-
-from graphics.drawing.CS_draw_primitives import drawline
-from graphics.drawing.CS_draw_primitives import drawsphere
 from utilities.constants import black, darkred, blue
+from utilities.prefs_constants import DarkBackgroundContrastColor_prefs_key
+from utilities.prefs_constants import cursorTextFontSize_prefs_key
 
 from geometry.VQT import vlen, norm, angleBetween, V, ptonline
 
 import foundation.env as env
-from utilities.prefs_constants import DarkBackgroundContrastColor_prefs_key
-from utilities.prefs_constants import cursorTextFontSize_prefs_key
 
+from graphics.drawing.CS_draw_primitives import drawline
+from graphics.drawing.CS_draw_primitives import drawsphere
+
+from commands.Select.Select_GraphicsMode import Select_GraphicsMode
 
 STARTPOINT_SPHERE_RADIUS = 1.0
 STARTPOINT_SPHERE_DRAWLEVEL = 2
@@ -66,9 +66,6 @@ class Line_GraphicsMode( Select_GraphicsMode ):
     # free drag the mouse (bare motion) 
     endPoint2 = None
 
-
-    #Rubberband line color
-    rubberband_line_color = env.prefs[DarkBackgroundContrastColor_prefs_key]
     rubberband_line_width = 1  #thickness or 'width' for drawer.drawline
 
     endPoint1_sphereColor = darkred
@@ -79,14 +76,14 @@ class Line_GraphicsMode( Select_GraphicsMode ):
     _standardAxisVectorForDrawingSnapReference = None
 
     #Flag that determines whether the cursor text should be rendered in 
-    #self.Draw. Example: This class draws cursor text at the end of the draw 
-    #method. Subclass of this class (say DnaLine_GM) calls this Draw mthod 
-    #and then do some more drawing and then again want to draw the cursor text
+    #self.Draw_other. Example: This class draws cursor text at the end of the draw 
+    #method. Subclass of this class (say DnaLine_GM) calls this Draw_other method 
+    #and then do some more drawing and then again want to draw the cursor text.
     #So that subclass can temporarily suppress cursor text. 
-    #@see: DnaLine_GM.Draw()
+    #@see: DnaLine_GM.Draw_other()
     _ok_to_render_cursor_text = True
 
-    #cursor text. ##@@ rename it to 'cursorText' -- Ninad
+    #cursor text. ##@@ todo: rename it to 'cursorText' -- Ninad
     text = ''
 
     #the drawing plane on which the line (or the structure in subclasses) 
@@ -350,16 +347,16 @@ class Line_GraphicsMode( Select_GraphicsMode ):
 
     def _drawSnapReferenceLines(self):
         """
-        Draw the snap reference lines as dottedt lines. Example, if the 
+        Draw the snap reference lines as dotted lines. Example, if the 
         moving end of the rubberband line is 'close enough' to a standard axis 
         vector, that point is 'snapped' soi that it lies on the axis. When this 
         is done, program draws a dotted line from origin to the endPoint2 
         indicating that the endpoint is snapped to that axis line.
 
-        This method is called inside the self.Draw method. 
+        This method is called inside the self.Draw_other method. 
 
         @see: self._snapEndPointToStandardAxis 
-        @see: self.Draw
+        @see: self.Draw_other
         """
         if self.endPoint2 is None:
             return
@@ -370,22 +367,39 @@ class Line_GraphicsMode( Select_GraphicsMode ):
                      dashEnabled = True, 
                      stipleFactor = 4,
                      width = 2)
+        return
 
-
-    def Draw(self):
+    def Draw_other(self):
         """
-        Draw method for this temporary mode. 
         """
-        _superclass_for_GM.Draw(self)
+        _superclass_for_GM.Draw_other(self)
 
         #This fixes NFR bug  2803
         #Don't draw the Dna rubberband line if the cursor is over the confirmation
-        #corner. But make sure to call superclass.Draw method before doing this 
+        #corner. But make sure to call superclass.Draw_other method before doing this 
         #check because we need to draw the rest of the model in the graphics 
-        #mode!. @see: DnaLineMode_GM.Draw() which does similar thing to not 
+        #mode!. @see: DnaLineMode_GM.Draw_other() which does similar thing to not 
         #draw the rubberband line when the cursor is on the confirmation corner
         handler = self.o.mouse_event_handler
         if handler is not None and handler is self._ccinstance:
+            ##### REVIEW:
+            #
+            # 1. This is probably incorrect in principle, as a way of
+            # deciding what to draw. The mouse event handling methods
+            # should set an attribute which directly specifies whether
+            # the next call of Draw_other (or other Draw methods)
+            # should draw the rubberband line or not.
+            # (Or which affects the value of an access method, e.g.
+            #  something like self.should_draw_rubberband_lines().)
+            #
+            # 2. Why is update_cursor called here? Any call of update_cursor
+            # inside a specific Draw method seems suspicious.
+            #
+            # 3. This needs refactoring to merge with common code in its
+            # subclass DnaLineMode_GM, and to consider doing the same
+            # thing in its other 3 subclasses.
+            #
+            # [bruce 090310 comments]
             self.update_cursor()
             return
 
@@ -398,7 +412,7 @@ class Line_GraphicsMode( Select_GraphicsMode ):
                            STARTPOINT_SPHERE_DRAWLEVEL,
                            opacity = self.endPoint1_sphereOpacity
                            )            
-            drawline(self.rubberband_line_color, 
+            drawline(env.prefs[DarkBackgroundContrastColor_prefs_key], 
                      self.endPoint1, 
                      self.endPoint2,
                      width = self.rubberband_line_width,
@@ -416,6 +430,8 @@ class Line_GraphicsMode( Select_GraphicsMode ):
             return
 
         self.text = ''
+            #### REVIEW: why do we set an attribute here? That's very
+            # suspicious in any drawing method. [bruce 090310 comment]
         textColor = black
 
         #Draw the text next to the cursor that gives info about 
@@ -423,7 +439,7 @@ class Line_GraphicsMode( Select_GraphicsMode ):
         #cleanup. e.g. callbackMethodForCursorTextString should be simply
         #self.command.getCursorText() and like that. -- Ninad2008-04-17
         if self.command and hasattr(self.command, 
-                                    'callbackMethodForCursorTextString'):            
+                                    'callbackMethodForCursorTextString'):
             self.text, textColor = self.command.callbackMethodForCursorTextString(
                 self.endPoint1, 
                 self.endPoint2)            
@@ -435,9 +451,9 @@ class Line_GraphicsMode( Select_GraphicsMode ):
             if distString:
                 #This could be a user preference. At the moment, subclasses
                 #may return an empty string for distance. 
-                self.text = "%5.2fA, %s"%(dist, thetaString)
+                self.text = "%5.2fA, %s" % (dist, thetaString)
             else:
-                self.text = "%s"%(thetaString)
+                self.text = "%s" % (thetaString,)
 
         self.glpane.renderTextNearCursor(self.text, 
                                          textColor = textColor,
@@ -526,3 +542,7 @@ class Line_GraphicsMode( Select_GraphicsMode ):
         self.endPoint1 = None
         self.endPoint2 = None
 
+    pass
+
+# end
+
diff --git a/cad/src/temporary_commands/RotateAboutPoint_Command.py b/cad/src/temporary_commands/RotateAboutPoint_Command.py
index 3f49f2226..82caa91b7 100644
--- a/cad/src/temporary_commands/RotateAboutPoint_Command.py
+++ b/cad/src/temporary_commands/RotateAboutPoint_Command.py
@@ -13,28 +13,32 @@ conference. This may be revised further.
 -- Need documentation
 """
 
-from temporary_commands.LineMode.Line_Command import Line_Command
-from temporary_commands.LineMode.Line_GraphicsMode import Line_GraphicsMode
-import foundation.env as env
-from utilities.prefs_constants import atomHighlightColor_prefs_key
-from model.chem import Atom # for isinstance check as of 2008-04-17
-
-from geometry.VQT import cross, norm, Q
 from Numeric import dot
-import math
-from graphics.drawing.CS_draw_primitives import drawline
+import math # for pi
+
+from utilities.prefs_constants import atomHighlightColor_prefs_key
 from utilities.constants import black
 from utilities.prefs_constants import DarkBackgroundContrastColor_prefs_key
 from utilities.debug import print_compact_stack, print_compact_traceback
 
-PI = 3.141593
+from geometry.VQT import cross, norm, Q
+
+import foundation.env as env
+
+from graphics.drawing.CS_draw_primitives import drawline
+
+from model.chem import Atom # for isinstance check as of 2008-04-17
+
+from temporary_commands.LineMode.Line_Command import Line_Command
+from temporary_commands.LineMode.Line_GraphicsMode import Line_GraphicsMode
+
+# ==
 
 _superclass_for_GM = Line_GraphicsMode
 
 class RotateAboutPoint_GraphicsMode(Line_GraphicsMode):
 
     pivotPoint = None
-    referece_line_color = env.prefs[DarkBackgroundContrastColor_prefs_key]
 
     def Enter_GraphicsMode(self):
         #TODO: use this more widely,  than calling grapicsMode.resetVariables
@@ -42,16 +46,14 @@ class RotateAboutPoint_GraphicsMode(Line_GraphicsMode):
         #-- Ninad 2008-04-17
         self.resetVariables() # For safety
         
-    def Draw(self):
+    def Draw_other(self):
         """
-        Draw method for this temporary mode. 
         """
-        _superclass_for_GM.Draw(self)
+        _superclass_for_GM.Draw_other(self)
         
-
         if len(self.command.mouseClickPoints) >= 2:
             #Draw reference vector.             
-            drawline(self.referece_line_color,
+            drawline(env.prefs[DarkBackgroundContrastColor_prefs_key],
                      self.command.mouseClickPoints[0], 
                      self.command.mouseClickPoints[1], 
                      width = 4,
@@ -171,12 +173,12 @@ class RotateAboutPoint_GraphicsMode(Line_GraphicsMode):
         
         if len(self.command.mouseClickPoints) < 2:
             theta = self.glpane.get_angle_made_with_screen_right(vec) 
-            thetaString = "%5.2f deg"%(theta)
+            thetaString = "%5.2f deg" % (theta,)
         else:            
             ref_vector = norm(self.command.mouseClickPoints[1] - self.pivotPoint)
             quat = Q(vec, ref_vector)
-            theta = quat.angle*180.0/PI
-            thetaString = "%5.2f deg"%(theta)
+            theta = quat.angle * 180.0 / math.pi
+            thetaString = "%5.2f deg" % (theta,)
         
         return thetaString
 
@@ -196,6 +198,9 @@ class RotateAboutPoint_GraphicsMode(Line_GraphicsMode):
         else:
             self.glpane.setCursor(self.win.rotateAboutPointCursor)
 
+    pass # end of class RotateAboutPoint_GraphicsMode
+
+# ==
 
 class RotateAboutPoint_Command(Line_Command):
     
@@ -222,7 +227,7 @@ class RotateAboutPoint_Command(Line_Command):
         """
         
         if len(self.mouseClickPoints) != self.mouseClickLimit:
-            print_compact_stack("Rotate about point bug: mouseclick points != mouseclicklimit")
+            print_compact_stack("Rotate about point bug: mouseclick points != mouseclicklimit: ")
             return
             
         
@@ -270,71 +275,6 @@ class RotateAboutPoint_Command(Line_Command):
 
         self.glpane.gl_update()
         return
-
-    
-
-    def ORIG_rotateAboutPoint(self): #THIS IS NOT USED AS OF NOV 28, 2008 SCHEDULED FOR REMOVAL
-        """
-        Rotates the selected entities along the specified vector, about the
-        specified pivot point (pivot point it the starting point of the
-        drawn vector.
-        """
-        startPoint = self.mouseClickPoints[0]
-        endPoint = self.mouseClickPoints[1]
-        pivotAtom = self.graphicsMode.pivotAtom
-        #initial assignment of reference_vec. The selected movables will be
-        #rotated by the angle between this vector and the lineVector
-        reference_vec = self.glpane.right
-        if isinstance(pivotAtom, Atom) and not pivotAtom.molecule.isNullChunk():
-            ##if env.prefs[foo_prefs_key]:
-            if True:
-                reference_vec = norm(self.glpane.right*pivotAtom.posn())
-            else:
-                mol = pivotAtom.molecule
-                reference_vec, node_junk = mol.getAxis_of_self_or_eligible_parent_node(
-                    atomAtVectorOrigin = pivotAtom)
-                del node_junk
-        else:
-            reference_vec = self.glpane.right
-                   
-            
-        lineVector = endPoint - startPoint
-
-        quat1 = Q(lineVector, reference_vec)
-        
-        
-        #DEBUG Disabled temporarily . will not be used
-        if dot(lineVector, reference_vec) < 0:
-            theta = math.pi - quat1.angle
-        else:
-            theta = quat1.angle
-
-        #TEST_DEBUG-- Works fine
-        theta = quat1.angle
-
-        rot_axis = cross(lineVector, reference_vec)
-        
-        
-        if dot(lineVector, reference_vec) < 0:
-            rot_axis = - rot_axis
-
-        cross_prod_1 = norm(cross(reference_vec, rot_axis))
-        cross_prod_2 = norm(cross(lineVector, rot_axis))
-
-        if dot(cross_prod_1, cross_prod_2) < 0:
-            quat2 = Q(rot_axis, theta)
-        else:
-            quat2 = Q(rot_axis, - theta)
-
-        movables = self.graphicsMode.getMovablesForLeftDragging()
-        self.assy.rotateSpecifiedMovables(
-            quat2,
-            movables = movables,
-            commonCenter = startPoint)
-
-        self.glpane.gl_update()
-        return
-
     
     def _results_for_request_command_caller(self):
         """
@@ -351,7 +291,6 @@ class RotateAboutPoint_Command(Line_Command):
         #calls it with this method's return value
         return ()
     
-    
     pass # end of class RotateAboutPoint_Command
 
 # end
diff --git a/cad/src/temporary_commands/TemporaryCommand.py b/cad/src/temporary_commands/TemporaryCommand.py
index 5acc67298..be35de452 100644
--- a/cad/src/temporary_commands/TemporaryCommand.py
+++ b/cad/src/temporary_commands/TemporaryCommand.py
@@ -1,11 +1,11 @@
-# Copyright 2007-2008 Nanorex, Inc.  See LICENSE file for details.
+# Copyright 2007-2009 Nanorex, Inc.  See LICENSE file for details.
 """
 TemporaryCommand.py -- provides several kinds of TemporaryCommand superclasses
 (so far, just TemporaryCommand_Overdrawing, used for Zoom/Pan/Rotate).
 
 @author:    Mark, Bruce
 @version:   $Id$
-@copyright: 2007-2008 Nanorex, Inc.  See LICENSE file for details.
+@copyright: 2007-2009 Nanorex, Inc.  See LICENSE file for details.
 @license:   GPL
 """
 
@@ -58,32 +58,36 @@ class ESC_to_exit_GraphicsMode_preMixin(commonGraphicsMode):
 
 class Overdrawing_GraphicsMode_preMixin(commonGraphicsMode):
     """
-    A pre-mixin class for GraphicsModes which overrides their Draw method
-    to do the saved prior command's drawing
+    A pre-mixin class for GraphicsModes which want to override their
+    Draw_* methods to do the parent command's drawing
     (perhaps in addition to their own, if they subclass this
-     and further extend its Draw method, or if they do incremental
+     and further extend its Draw_* methods, or if they do incremental
      OpenGL drawing in event handler methods).
 
-    (If there is no saved prior command, which I think never happens
-     given how this is used as of 071012, this just calls super(...).Draw()
-     followed by (KLUGE) self.glpane.assy.draw(self.glpane).
-     TODO: clean that up. (Standard flag for drawing model??
-     Same one as in extrudeMode, maybe other commands.))
+    (If there is no parent command, which I think never happens
+     given how this is used as of 071012, this will raise an exception
+     when any of its Draw_* methods are called.)
+
+    @see: related class Delegating_GraphicsMode
     """
-    def Draw(self):
-        drew = self.commandSequencer.parentCommand_Draw( self.command)
-            # doing this fixes the bug in which Pan etc doesn't show the right things
-            # for BuildCrystal or Extrude modes (e.g. bond-offset spheres in Extrude)
-        if not drew:
-            # (This means no prior command was found. It is unrelated to any Draw method
-            #  return value, since there isn't one.)
-            # I think this can't happen, since our subclasses always run as a temporary
-            # command while suspending another one:
-            print "fyi: %s using fallback Draw code (I suspect this can never happen)" % self
-            super(Overdrawing_GraphicsMode_preMixin, self).Draw()
-            self.glpane.assy.draw(self.glpane)
-                # TODO: use flag in super Draw for whether it should do this; see docstring for more info
-        return
+    #bruce 090310 revised this
+    def Draw_preparation(self):
+        self.parentGraphicsMode.Draw_preparation()
+    
+    def Draw_axes(self):
+        self.parentGraphicsMode.Draw_axes()
+    
+    def Draw_model(self):
+        self.parentGraphicsMode.Draw_model()
+    
+    def Draw_other(self):
+        # doing this fixes the bug in which Pan etc doesn't show the right things
+        # for BuildCrystal or Extrude modes (e.g. bond-offset spheres in Extrude)
+        self.parentGraphicsMode.Draw_other()
+    
+    def Draw_after_highlighting(self, pickCheckOnly = False):
+        #bruce 090310 new feature (or bugfix) -- delegate this too
+        self.parentGraphicsMode.Draw_after_highlighting(pickCheckOnly = pickCheckOnly)
 
     pass
 
-- 
cgit v1.2.3