[GRASS-SVN] r47918 - in grass/trunk: gui/wxpython/gui_modules gui/wxpython/icons include lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 28 09:09:05 EDT 2011


Author: annakrat
Date: 2011-08-28 06:09:05 -0700 (Sun, 28 Aug 2011)
New Revision: 47918

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxnviz.py
   grass/trunk/gui/wxpython/icons/icon.py
   grass/trunk/include/ogsf_proto.h
   grass/trunk/lib/ogsf/GS2.c
Log:
wxNviz: view history

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -368,7 +368,10 @@
                 if '3D' in self._layerManager.gm_cb.GetPage(page).maptree.mapdisplay.toolbars['map'].combo.GetString(1):
                     self._layerManager.gm_cb.GetPage(page).maptree.mapdisplay.toolbars['map'].combo.Delete(1)
         self.toolbars['map'].Enable2D(False)
-        
+        # add rotate tool to map toolbar
+        self.toolbars['map'].InsertTool((('rotate', Icons['nviz']['rotate'],
+                                          self.OnRotate, wx.ITEM_CHECK,7),)) # 7 is position
+        self.toolbars['map'].ChangeToolsDesc(mode2d = False)
         # update status bar
         self.statusbarWin['toggle'].Enable(False)
         
@@ -401,6 +404,7 @@
             
             self.MapWindow3D.OnPaint(None) # -> LoadData
             self.MapWindow3D.Show()
+            self.MapWindow3D.ResetViewHistory()            
             self.MapWindow3D.UpdateView(None)
         else:
             self.MapWindow = self.MapWindow3D
@@ -416,7 +420,7 @@
             
             # add Nviz notebookpage
             self._layerManager.AddNvizTools()
-            
+            self.MapWindow3D.ResetViewHistory()
             for page in ('view', 'light', 'fringe', 'constant', 'cplane'):
                 self._layerManager.nviz.UpdatePage(page)
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -103,6 +103,9 @@
         self.cplanes = list()
         # list of query points
         self.qpoints = list()
+        # list of past views
+        self.viewhistory  = []
+        self.saveHistory = False
         # overlays
         self.overlays = {}
         self.imagedict = {}
@@ -352,46 +355,24 @@
     def OnMouseWheel(self, event):
         """!Change perspective"""
         wheel = event.GetWheelRotation()
-        current  = event.GetPositionTuple()[:]
         Debug.msg (5, "GLWindow.OnMouseMotion(): wheel = %d" % wheel)
-        prev_value = self.view['persp']['value']
-        if wheel > 0:
-            value = -1 * self.view['persp']['step']
-        else:
-            value = self.view['persp']['step']
-        self.view['persp']['value'] +=  value
-        if self.view['persp']['value'] < 1:
-            self.view['persp']['value'] = 1
-        elif self.view['persp']['value'] > 180:
-            self.view['persp']['value'] = 180
-        
-        if prev_value !=  self.view['persp']['value']:
-            if hasattr(self.lmgr, "nviz"):
-                self.lmgr.nviz.UpdateSettings()
-                
-                self._display.SetView(self.view['position']['x'], self.view['position']['y'],
-                                      self.iview['height']['value'],
-                                      self.view['persp']['value'],
-                                      self.view['twist']['value'])
+        self.DoZoom(zoomtype = wheel, pos = event.GetPositionTuple())
             
-            # redraw map
-            self.DoPaint()
+        # update statusbar
+        ### self.parent.StatusbarUpdate()
             
-            # update statusbar
-            ### self.parent.StatusbarUpdate()
-            
     def OnLeftDown(self, event):
         """!On left mouse down"""
         self.mouse['begin'] = event.GetPositionTuple()
         self.mouse['tmp'] = event.GetPositionTuple()
         if self.mouse['use'] == "lookHere":
-            pos = event.GetPosition()
             size = self.GetClientSize()
-            self._display.LookHere(pos[0], size[1] - pos[1])
-            self.Refresh(False)
+            self._display.LookHere(self.mouse['begin'][0], size[1] - self.mouse['begin'][1])
             focus = self._display.GetFocus()
             for i, coord in enumerate(('x', 'y', 'z')):
                 self.iview['focus'][coord] = focus[i]
+            self.saveHistory = True
+            self.Refresh(False)
             toggle = self.lmgr.nviz.FindWindowByName('here')
             toggle.SetValue(False)
             self.mouse['use'] = 'pointer'
@@ -467,7 +448,40 @@
         
         return (x, y)
     
+    def DoZoom(self, zoomtype, pos):
+        """!Change perspective and focus"""
+        
+        prev_value = self.view['persp']['value']
+        if zoomtype > 0:
+            value = -1 * self.view['persp']['step']
+        else:
+            value = self.view['persp']['step']
+        self.view['persp']['value'] +=  value
+        if self.view['persp']['value'] < 1:
+            self.view['persp']['value'] = 1
+        elif self.view['persp']['value'] > 180:
+            self.view['persp']['value'] = 180
+        
+        if prev_value !=  self.view['persp']['value']:
+            if hasattr(self.lmgr, "nviz"):
+                self.lmgr.nviz.UpdateSettings()
+                x, y = pos[0], self.GetClientSize()[1] - pos[1]
+                result = self._display.GetPointOnSurface(x, y)
+                if result[0]:
+                    self._display.LookHere(x, y)
+                    focus = self._display.GetFocus()
+                    for i, coord in enumerate(('x', 'y', 'z')):
+                        self.iview['focus'][coord] = focus[i]
+                self._display.SetView(self.view['position']['x'], self.view['position']['y'],
+                                      self.iview['height']['value'],
+                                      self.view['persp']['value'],
+                                      self.view['twist']['value'])
+                self.saveHistory = True
+            # redraw map
+            self.DoPaint()
+            
     def OnLeftUp(self, event):
+        self.mouse['end'] = event.GetPositionTuple()
         if self.mouse["use"] == "query":
             layers = self.GetSelectedLayer(multi = True)
             
@@ -500,9 +514,13 @@
             
         elif self.mouse['use'] == 'rotate':
             self._display.UnsetRotation()
+            self.iview['rotation'] = self._display.GetRotationMatrix()
+            self.saveHistory = True
             self.render['quick'] = False
             self.Refresh(False)
-            
+        
+        elif self.mouse['use'] == 'zoom':
+            self.DoZoom(zoomtype = self.zoomtype, pos = self.mouse['end'])
         event.Skip()
             
     def OnDClick(self, event):
@@ -547,7 +565,66 @@
         self.pdc.DrawToDC(dc)
         del odc
         self.mouse['tmp'] = (event.GetX(), event.GetY()) 
-                       
+        
+    def ZoomBack(self):
+        """!Set previous view in history list
+        """
+        view = {}
+        if len(self.viewhistory) > 1:
+            self.viewhistory.pop()
+            view = copy.deepcopy(self.viewhistory[-1])
+        
+        # disable tool if stack is empty
+        if len(self.viewhistory) < 2: # disable tool
+            toolbar = self.parent.toolbars['map']
+            toolbar.Enable('zoomback', enable = False)
+            
+        # set view and update nviz view page
+        self.lmgr.nviz.UpdateState(view = view[0], iview = view[1])
+        self.lmgr.nviz.UpdatePage('view')
+        # update map
+        self.Refresh(False)
+
+    def ViewHistory(self, view, iview):
+        """!Manages a list of last 10 views
+        
+        @param view view dictionary
+        @param iview view dictionary (internal)
+        
+        @return removed history item if exists (or None)
+        """
+        removed = None
+        hview = copy.deepcopy(view)
+        hiview = copy.deepcopy(iview)
+        
+        if not (self.viewhistory and self.viewhistory[-1] == (hview, hiview)):  
+            self.viewhistory.append((hview, hiview))
+            
+        if len(self.viewhistory) > 10:
+            removed = self.viewhistory.pop(0)
+        
+        if removed:
+            Debug.msg(4, "GLWindow.ViewHistory(): hist=%s, removed=%s" %
+                      (self.viewhistory, removed))
+        else:
+            Debug.msg(4, "GLWindow.ViewHistory(): hist=%s" %
+                      (self.viewhistory))
+        
+        # update toolbar
+        if len(self.viewhistory) > 1:
+            enable = True
+        else:
+            enable = False
+        
+        toolbar = self.parent.toolbars['map']
+        toolbar.Enable('zoomback', enable)
+        
+        return removed     
+    
+    def ResetViewHistory(self):
+        """!Reset view history"""
+        self.viewhistory = list()
+        
     def OnQuerySurface(self, event):
         """!Query surface on given position"""
         size = self.GetClientSizeTuple()
@@ -599,19 +676,27 @@
     def UpdateView(self, event):
         """!Change view settings"""
         data = self.view
+        
+        ## multiple z-exag value from slider by original value computed in ogsf so it scales
+        ## correctly with maps of different height ranges        
+        if event and event.zExag and 'value' in data['z-exag']:
+            self._display.SetZExag(self.iview['z-exag']['original'] * data['z-exag']['value'])
+            
         self._display.SetView(data['position']['x'], data['position']['y'],
                               self.iview['height']['value'],
                               data['persp']['value'],
                               data['twist']['value'])
         
-        ## multiple z-exag value from slider by original value computed in ogsf so it scales
-        ## correctly with maps of different height ranges        
-        if event and event.zExag and 'value' in data['z-exag']:
-            self._display.SetZExag(self.iview['z-exag']['original'] * data['z-exag']['value'])
         if self.iview['focus']['x'] != -1:
             self._display.SetFocus(self.iview['focus']['x'], self.iview['focus']['y'],
                                    self.iview['focus']['z'])
+        if 'rotation' in self.iview:
+            if self.iview['rotation']:
+                self._display.SetRotationMatrix(self.iview['rotation'])
+            else:
+                self._display.ResetRotation()
         
+        self.saveHistory = True
         if event:
             event.Skip()
 
@@ -644,6 +729,9 @@
         if self.render['quick'] is False:
             self.parent.statusbarWin['progress'].SetValue(1)
             self._display.Draw(False, -1)
+            if self.saveHistory:
+                self.ViewHistory(view = self.view, iview = self.iview)
+                self.saveHistory = False
         elif self.render['quick'] is True:
             # quick
             mode = wxnviz.DRAW_QUICK_SURFACE | wxnviz.DRAW_QUICK_VOLUME
@@ -1281,6 +1369,7 @@
         self.view['twist']['value'] = UserSettings.Get(group = 'nviz', key = 'view',
                                                        subkey = ('twist', 'value'))
         self._display.ResetRotation()
+        self.iview['rotation'] = None
         self._display.LookAtCenter()
         focus = self.iview['focus']
         focus['x'], focus['y'], focus['z'] = self._display.GetFocus()

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -2544,6 +2544,7 @@
             self._display.LookAtCenter()
             focus = self.mapWindow.iview['focus']
             focus['x'], focus['y'], focus['z'] = self._display.GetFocus()
+            self.mapWindow.saveHistory = True
             self.mapWindow.Refresh(False)
         elif name == 'top':
             self.mapWindow.view['position']['x'] = 0.5
@@ -2559,7 +2560,7 @@
             else:
                 self.mapWindow.mouse['use'] = 'default'
                 self.mapWindow.SetCursor(self.mapWindow.cursors['default'])
-          
+            
     def OnResetView(self, event):
         """!Reset to default view (view page)"""
         self.mapWindow.ResetView()

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -707,6 +707,7 @@
         self.internalSettings['nviz']['view']['height']['value'] = -1
         self.internalSettings['nviz']['view']['z-exag'] = {}
         self.internalSettings['nviz']['view']['z-exag']['original'] = 1
+        self.internalSettings['nviz']['view']['rotation'] = None
         self.internalSettings['nviz']['view']['focus'] = {}
         self.internalSettings['nviz']['view']['focus']['x'] = -1
         self.internalSettings['nviz']['view']['focus']['y'] = -1

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -333,6 +333,19 @@
         self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
         self.parent._mgr.Update()
         
+    def ChangeToolsDesc(self, mode2d):
+        """!Change description of zoom tools for 2D/3D view"""
+        if mode2d:
+            set = 'displayWindow'
+        else:
+            set = 'nviz'
+        for i, data in enumerate(self._data):
+            for tool, toolname in (('zoomin', 'zoomIn'),('zoomout', 'zoomOut')):
+                if data[0] == tool:
+                    tmp = list(data)
+                    tmp[4] = Icons[set][toolname].GetDesc()
+                    self._data[i] = tuple(tmp)
+                
     def OnSelectTool(self, event):
         """!Select / enable tool available in tools list
         """
@@ -341,13 +354,10 @@
         if tool == self.toolId['2d']:
             self.ExitToolbars()
             self.Enable2D(True)
+            self.ChangeToolsDesc(mode2d = True)            
         
         elif tool == self.toolId['3d'] and \
                 not (self.parent.MapWindow3D and self.parent.IsPaneShown('3d')):
-            self.InsertTool((('rotate', Icons['nviz']['rotate'],
-                              self.parent.OnRotate,
-                              wx.ITEM_CHECK,7),)) # 7 is position
-                                              
             self.ExitToolbars()
             self.parent.AddNviz()
             
@@ -367,9 +377,6 @@
     def Enable2D(self, enabled):
         """!Enable/Disable 2D display mode specific tools"""
         for tool in (self.pan,
-                     self.zoomin,
-                     self.zoomout,
-                     self.zoomback,
                      self.zoommenu,
                      self.analyze,
                      self.printmap):

Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -1835,3 +1835,19 @@
     def ResetRotation(self):
         """!Reset scene rotation"""
         Nviz_init_rotation()
+        
+    def GetRotationMatrix(self):
+        """!Get rotation matrix"""
+        matrix = (c_double * 16)()
+        GS_get_rotation_matrix(byref(matrix))
+        returnMatrix = []
+        for item in matrix:
+            returnMatrix.append(item)
+        return returnMatrix
+        
+    def SetRotationMatrix(self, matrix):
+        """!Set rotation matrix"""
+        mtrx = (c_double * 16)()
+        for i in range(len(matrix)):
+            mtrx[i] = matrix[i]
+        GS_set_rotation_matrix(byref(mtrx))

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/gui/wxpython/icons/icon.py	2011-08-28 13:09:05 UTC (rev 47918)
@@ -333,9 +333,15 @@
                                desc = _('Settings dialog for georectification tool')),
         },
     'nviz' : {
-        'rotate': MetaIcon(img = iconSet.get('3d-rotate', wx.ART_ERROR),
+        'rotate':   MetaIcon(img = iconSet.get('3d-rotate', wx.ART_ERROR),
                              label = _('Rotate 3D scene'),
-                             desc = _('Drag with mouse to rotate 3D scene')),                            
+                             desc = _('Drag with mouse to rotate 3D scene')), 
+        'zoomIn':   MetaIcon(img = iconSet.get('zoom-in', wx.ART_ERROR),
+                            label = _('Zoom in'),
+                            desc = _('Click mouse to zoom')),
+        'zoomOut':  MetaIcon(img = iconSet.get('zoom-out', wx.ART_ERROR),
+                            label = _('Zoom out'),
+                            desc = _('Click mouse to unzoom')),
         'nviz_cmd': MetaIcon(img = iconSet.get('script-save', wx.ART_ERROR),
                              label = _('Generate command for nviz_cmd'),
                              desc = _('Generate command for nviz_cmd based on current state')),

Modified: grass/trunk/include/ogsf_proto.h
===================================================================
--- grass/trunk/include/ogsf_proto.h	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/include/ogsf_proto.h	2011-08-28 13:09:05 UTC (rev 47918)
@@ -173,6 +173,8 @@
 void GS_set_viewdir(float *);
 void GS_set_fov(int);
 void GS_set_rotation(double, double, double, double);
+void GS_get_rotation_matrix(double *);
+void GS_set_rotation_matrix(double *);
 void GS_init_rotation(void);
 void GS_unset_rotation(void);
 int GS_get_fov(void);

Modified: grass/trunk/lib/ogsf/GS2.c
===================================================================
--- grass/trunk/lib/ogsf/GS2.c	2011-08-28 08:51:14 UTC (rev 47917)
+++ grass/trunk/lib/ogsf/GS2.c	2011-08-28 13:09:05 UTC (rev 47918)
@@ -2928,6 +2928,30 @@
     
 }
 /*!
+ * \brief Get rotation matrix
+ */ 
+void GS_get_rotation_matrix(double *matrix)
+{
+    int i;
+
+    for (i = 0; i < 16; i++) {
+	matrix[i] = Gv.rotate.rotMatrix[i];
+    }
+}
+
+/*!
+ * \brief Set rotation matrix
+ */ 
+void GS_set_rotation_matrix(double *matrix)
+{
+    int i;
+
+    for (i = 0; i < 16; i++) {
+	Gv.rotate.rotMatrix[i] = matrix[i];
+    }
+}
+
+/*!
    \brief Unset focus
  */
 void GS_set_nofocus(void)



More information about the grass-commit mailing list