diff options
author | Ninad Sathaye <ninad@nanorex.com> | 2008-09-19 20:13:08 +0000 |
---|---|---|
committer | Ninad Sathaye <ninad@nanorex.com> | 2008-09-19 20:13:08 +0000 |
commit | f0c357063b47be6b999c276ce29e317881f082d7 (patch) | |
tree | 2007fc0e9b61440d865fdb070c5a09c954d5ae26 | |
parent | 9544ca03ff8abff85dc2b27f7f006669452195b2 (diff) | |
download | nanoengineer-f0c357063b47be6b999c276ce29e317881f082d7.tar.gz nanoengineer-f0c357063b47be6b999c276ce29e317881f082d7.zip |
ported Plane_EditCommand to new api. Cleanup to fix many issues such as resizing bugs, model object (plane) doing ui calls etc. ; cleanup in update methods
-rwxr-xr-x | cad/src/commands/PlaneProperties/PlanePropertyManager.py | 104 | ||||
-rwxr-xr-x | cad/src/commands/PlaneProperties/Plane_EditCommand.py | 138 | ||||
-rwxr-xr-x | cad/src/model/Plane.py | 15 |
3 files changed, 157 insertions, 100 deletions
diff --git a/cad/src/commands/PlaneProperties/PlanePropertyManager.py b/cad/src/commands/PlaneProperties/PlanePropertyManager.py index 3d41dea6d..72b2b2312 100755 --- a/cad/src/commands/PlaneProperties/PlanePropertyManager.py +++ b/cad/src/commands/PlaneProperties/PlanePropertyManager.py @@ -7,6 +7,11 @@ History: ninad 20070602: Created. +Summer 2008: Urmi and Piotr added code to support image display and grid display + within Plane objects. + +TODO 2008-09-19: +See Plane_EditCommand.py """ from PyQt4.Qt import SIGNAL @@ -36,6 +41,8 @@ from utilities.prefs_constants import PlanePM_showGridLabels_prefs_key, PlanePM_ from utilities import debug_flags from widgets.prefs_widgets import connect_checkbox_with_boolean_pref +_superclass = EditCommand_PM + class PlanePropertyManager(EditCommand_PM): """ The PlanePropertyManager class provides a Property Manager for a @@ -63,26 +70,11 @@ class PlanePropertyManager(EditCommand_PM): self.isAlreadyConnected = False self.isAlreadyDisconnected = False - EditCommand_PM.__init__( self, command) - - - - msg = "Insert a Plane parallel to the screen. Note: This feature is "\ - "experimental for Alpha9 and has known bugs." - - # This causes the "Message" box to be displayed as well. - self.updateMessage(msg) - - # self.resized_from_glpane flag makes sure that the - #spinbox.valueChanged() - # signal is not emitted after calling spinbox.setValue. - self.resized_from_glpane = False - - # Hide Preview and Restore defaults button for Alpha9. + + # Hide Preview and Restore defaults buttons self.hideTopRowButtons(PM_RESTORE_DEFAULTS_BUTTON) - # needed to figure out if the model has changed or not - self.previousPMParams = None + self.gridColor = black self.gridXSpacing = 4.0 self.gridYSpacing = 4.0 @@ -763,17 +755,25 @@ class PlanePropertyManager(EditCommand_PM): """ Update the width and height spinboxes. @see: Plane.resizeGeometry() + This typically gets called when the plane is resized from the + 3D workspace (which marks assy as modified) .So, update the spinboxes + that represent the Plane's width and height, but do no emit 'valueChanged' + signal when the spinbox value changes. + + @see: Plane.resizeGeometry() + @see: self._update_UI_do_updates() + @see: Plane_EditCommand.command_update_internal_state() """ - # self.resized_from_glpane flag makes sure that the - # spinbox.valueChanged() - # signal is not emitted after calling spinbox.setValue(). - # This flag is used in change_plane_size method.-- Ninad 20070601 - if self.command and self.command.hasValidStructure(): - self.resized_from_glpane = True - self.heightDblSpinBox.setValue(self.command.struct.height) - self.widthDblSpinBox.setValue(self.command.struct.width) - self.win.glpane.gl_update() - self.resized_from_glpane = False + # blockSignals = True make sure that spinbox.valueChanged() + # signal is not emitted after calling spinbox.setValue(). This is done + #because the spinbox valu changes as a result of resizing the plane + #from the 3D workspace. + if self.command.hasValidStructure(): + self.heightDblSpinBox.setValue(self.command.struct.height, + blockSignals = True) + self.widthDblSpinBox.setValue(self.command.struct.width, + blockSignals = True) + def update_imageFile(self): """ @@ -850,15 +850,13 @@ class PlanePropertyManager(EditCommand_PM): gridXSpacing, gridYSpacing, originLocation, \ displayLabelStyle = params - # self.resized_from_glpane flag makes sure that the + # blockSignals = True flag makes sure that the # spinbox.valueChanged() # signal is not emitted after calling spinbox.setValue(). - # This flag is used in change_plane_size method.-- Ninad 20070601 - self.resized_from_glpane = True - self.widthDblSpinBox.setValue(width) - self.heightDblSpinBox.setValue(height) + self.widthDblSpinBox.setValue(width, blockSignals = True) + self.heightDblSpinBox.setValue(height, blockSignals = True) self.win.glpane.gl_update() - self.resized_from_glpane = False + self.gpColorTypeComboBox.setColor(gridColor) self.gridLineType = gridLineType @@ -868,6 +866,22 @@ class PlanePropertyManager(EditCommand_PM): self.gpOriginComboBox.setCurrentIndex(originLocation) self.gpPositionComboBox.setCurrentIndex(displayLabelStyle) + + + def getCurrrentDisplayParams(self): + """ + Returns a tuple containing current display parameters such as current + image path and grid display params. + @see: Plane_EditCommand.command_update_internal_state() which uses this + to decide whether to modify the structure (e.g. because of change in the + image path or display parameters.) + """ + imagePath = self.imageDisplayFileChooser.text + gridColor = self.gpColorTypeComboBox.getColor() + + return (imagePath, gridColor, self.gridLineType, + self.gridXSpacing, self.gridYSpacing, + self.originLocation, self.displayLabelStyle) def getParameters(self): """ @@ -889,7 +903,8 @@ class PlanePropertyManager(EditCommand_PM): @param newWidth: width in Angstroms. @type newWidth: float - """ + """ + print "****in change_plane_width" if self.aspectRatioCheckBox.isChecked(): self.command.struct.width = newWidth self.command.struct.height = self.command.struct.width / \ @@ -922,9 +937,8 @@ class PlanePropertyManager(EditCommand_PM): @param gl_update: Forces an update of the glpane. @type gl_update: bool """ - if not self.resized_from_glpane: - self.command.struct.width = self.widthDblSpinBox.value() - self.command.struct.height = self.heightDblSpinBox.value() + self.command.struct.width = self.widthDblSpinBox.value() + self.command.struct.height = self.heightDblSpinBox.value() if gl_update: self.command.struct.glpane.gl_update() @@ -995,6 +1009,20 @@ class PlanePropertyManager(EditCommand_PM): """ aspectRatio = self.command.struct.width / self.command.struct.height self.aspectRatioSpinBox.setValue(aspectRatio) + + def _update_UI_do_updates(self): + """ + Overrides superclass method. + @see: PM_Dialog._update_UI_do_updates() for documentation. + + @see: Plane.resizeGeometry() + @see: self.update_spinboxes() + @see: Plane_EditCommand.command_update_internal_state() + """ + #This typically gets called when the plane is resized from the + #3D workspace (which marks assy as modified) . So, update the spinboxes + #that represent the Plane's width and height. + self.update_spinboxes() def update_props_if_needed_before_closing(self): diff --git a/cad/src/commands/PlaneProperties/Plane_EditCommand.py b/cad/src/commands/PlaneProperties/Plane_EditCommand.py index 44f5c848a..ff17cd3b0 100755 --- a/cad/src/commands/PlaneProperties/Plane_EditCommand.py +++ b/cad/src/commands/PlaneProperties/Plane_EditCommand.py @@ -12,7 +12,8 @@ ninad 2007-10-05: Refactored, Also renamed PlaneGenerator to Plane_EditCommand while refactoring the old GeometryGeneratorBaseClass ninad 2007-12-26: Changes to make Plane_EditCommand a command on command stack - +Summer 2008: Urmi and Piotr added code to support image display and grid display + within Plane objects. @TODO 2008-04-15: Note that Plane_EditCommand was originally implemented before the command @@ -22,19 +23,22 @@ e.g. in its PM, the method update_props_if_needed_before_closing need to be revised because there is any easy way now, to know which command is currently active.Also a general clanup is due -- Ninad +TODO 2008-09-09 +Refactor update ui related code. e.g. see self.command_will_exit() -- +self.struct.updatecosmeticProps() should go inside a command_update method. +[-- Ninad] """ -import foundation.env as env + from utilities.Log import greenmsg from command_support.EditCommand import EditCommand from commands.PlaneProperties.PlanePropertyManager import PlanePropertyManager from model.Plane import Plane from commands.SelectAtoms.SelectAtoms_GraphicsMode import SelectAtoms_GraphicsMode from utilities.Comparison import same_vals -from utilities.prefs_constants import PlanePM_showGridLabels_prefs_key, PlanePM_showGrid_prefs_key - -from commands.PlaneProperties.PlanePropertyManager import PlanePropertyManager +from utilities.GlobalPreferences import USE_COMMAND_STACK +_superclass = EditCommand class Plane_EditCommand(EditCommand): """ The Plane_EditCommand class provides an editCommand Object. @@ -45,6 +49,8 @@ class Plane_EditCommand(EditCommand): #@NOTE: self.struct is the Plane object PM_class = PlanePropertyManager + + GraphicsMode_class = SelectAtoms_GraphicsMode cmd = greenmsg("Plane: ") # @@ -73,58 +79,59 @@ class Plane_EditCommand(EditCommand): featurename = "Reference Plane" from utilities.constants import CL_EDIT_GENERIC command_level = CL_EDIT_GENERIC + + #see self.command_update_internal_state() + _previous_display_params = None - GraphicsMode_class = SelectAtoms_GraphicsMode - - - def __init__(self, commandSequencer, struct = None): - """ - Constructs an Edit Controller Object. The editCommand, - depending on what client code needs it to do, may create a new plane - or it may be used for an existing plane. - - @param win: The NE1 main window. - @type win: QMainWindow - - @param struct: The model object (in this case plane) that the - Plane_EditCommand may create and/or edit - If struct object is specified, it means this - editCommand will be used to edit that struct. - @type struct: L{Plane} or None - - @see: L{Plane.__init__} - """ - EditCommand.__init__(self, commandSequencer) - self.struct = struct - - def Enter(self): + def command_entered(self): """ - Enter this command. - @see: EditCommand.Enter """ #See EditCommand.Enter for a detailed comment on why self.struct is #set to None while entering this command. - if self.struct: - self.struct = None - - EditCommand.Enter(self) - - def restore_gui(self): - """ - @see: EditCommand.restore_gui - """ - EditCommand.restore_gui(self) + self.struct = None + _superclass.command_entered(self) + + def command_will_exit(self): #Following call doesn't update the struct with steps similar to #ones in bug 2699. Instead calling struct.updateCosmeticProps directly - ##self.propMgr.update_props_if_needed_before_closing() - if self.hasValidStructure(): + #Note 2008-09-09: this code was copied from the former self.restore_gui. + #This needs to do inside an update method. + if self.hasValidStructure(): self.struct.updateCosmeticProps() + + _superclass.command_will_exit(self) + + + if not USE_COMMAND_STACK: + + def Enter(self): + """ + Enter this command. + @see: _superclass.Enter + """ + #See _superclass.Enter for a detailed comment on why self.struct is + #set to None while entering this command. + if self.struct: + self.struct = None + + _superclass.Enter(self) + + def restore_gui(self): + """ + @see: _superclass.restore_gui + """ + _superclass.restore_gui(self) + #Following call doesn't update the struct with steps similar to + #ones in bug 2699. Instead calling struct.updateCosmeticProps directly + ##self.propMgr.update_props_if_needed_before_closing() + if self.hasValidStructure(): + self.struct.updateCosmeticProps() def _getStructureType(self): """ Subclasses override this method to define their own structure type. - Returns the type of the structure this editCommand supports. + Returns the type of the structure this command supports. This is used in isinstance test. @see: EditCommand._getStructureType() (overridden here) """ @@ -232,26 +239,41 @@ class Plane_EditCommand(EditCommand): ##=====================================## + def command_update_internal_state(self): + """ + Extends the superclass method. + This method should replace model_changed() eventually. This method + calss self.model_changed at the moment. + @see:baseCommand.command_update_internal_state() for documentation + + @see: PlanePropertyManager._update_UI_do_updates() + @see: PlanePropertyManager.update_spinboxes() + @see: Plane.resizeGeometry() + """ + self.model_changed() + + def model_changed(self): #check first if the plane object exists first if not self.hasValidStructure(): - return + return - # piotr 080617 - # fixed plane resizing bug - should return if the plane - # is being interactively modified - if self.propMgr.resized_from_glpane: + #NOTE: The following ensures that the image path and other display + #prams are properly updated in the plane. Perhaps its better done using + #env.prefs? Revising this code to fix bugs in resizing because + #of the self._modifyStructure call. See also original code in + #Revision 12982 -- Ninad 2008-09-19 + + currentDisplayParams = self.propMgr.getCurrrentDisplayParams() + + if same_vals(currentDisplayParams, self._previous_display_params): return - #see if values in PM has changed - currentParams = self._gatherParameters() - - if same_vals(currentParams,self.propMgr.previousPMParams): - return + self._previous_display_params = currentDisplayParams - self.propMgr.previousPMParams = currentParams - self._modifyStructure(currentParams) + params = self._gatherParameters() + self._modifyStructure(params) def runCommand(self): """ @@ -270,7 +292,7 @@ class Plane_EditCommand(EditCommand): EditCommand API method/ """ - EditCommand.runCommand(self) + _superclass.runCommand(self) if self.hasValidStructure(): self._updatePropMgrParams() @@ -283,7 +305,7 @@ class Plane_EditCommand(EditCommand): def editStructure(self, struct = None): """ """ - EditCommand.editStructure(self, struct) + _superclass.editStructure(self, struct) if self.hasValidStructure(): self._updatePropMgrParams() diff --git a/cad/src/model/Plane.py b/cad/src/model/Plane.py index 179bd4f44..2fac3d643 100755 --- a/cad/src/model/Plane.py +++ b/cad/src/model/Plane.py @@ -668,6 +668,10 @@ class Plane(ReferenceGeometry): @param event: The mouse event. @type event: QEvent + + @see: PlanePropertyManager._update_UI_do_updates() + @see: PlanePropertyManager.update_spinboxes() + @see: Plane_EditCommand.command_update_internal_state() """ #NOTE: mouseray contains all the points @@ -744,10 +748,13 @@ class Plane(ReferenceGeometry): self.setHeight(new_h) self.recomputeCenter(totalOffset) - #update the width,height spinboxes(may be more in future)--Ninad20070601 - if self.editCommand and self.editCommand.propMgr: - self.editCommand.propMgr.update_spinboxes() - + + #assy.changed() required to make sure that the PM.update_UI() gets + #called (because model is changed) and the spinboxes (or other UI + #elements in the PM) get updated. + self.assy.changed() + + def edit(self): """ |