[GRASS-SVN] r46933 - in grass/trunk: gui/wxpython/gui_modules include lib/nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 3 07:06:03 EDT 2011


Author: annakrat
Date: 2011-07-03 04:06:03 -0700 (Sun, 03 Jul 2011)
New Revision: 46933

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.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/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxnviz.py
   grass/trunk/include/nviz.h
   grass/trunk/lib/nviz/cplanes_obj.c
Log:
wxNviz: a try for interactive setting of cutting plane position

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-07-03 11:06:03 UTC (rev 46933)
@@ -78,6 +78,7 @@
                 e, n = self.Pixel2Cell(event.GetPositionTuple())
             except (TypeError, ValueError):
                 self.parent.statusbar.SetStatusText("", 0)
+                event.Skip()
                 return
             
             updated = False

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-07-03 11:06:03 UTC (rev 46933)
@@ -228,54 +228,95 @@
         self.UpdateMap()
                 
     def OnMouseAction(self, event):
-        # change perspective with mouse wheel
+        """!Handle mouse events"""
+        # zoom with mouse wheel
+        if event.GetWheelRotation() != 0:
+            self.OnMouseWheel(event)
+            
+        # left mouse button pressed
+        elif event.LeftDown():
+            self.OnLeftDown(event)
+        
+        # left mouse button released
+        elif event.LeftUp():
+            self.OnLeftUp(event)
+        
+        # dragging
+        elif event.Dragging():
+            self.OnDragging(event)
+        
+        event.Skip()
+
+    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'] > 100:
+            self.view['persp']['value'] = 100
         
-        if wheel !=  0:
-            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'] > 100:
-                self.view['persp']['value'] = 100
+        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'])
             
-            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'])
-                
-                # redraw map
-                self.DoPaint()
-                
-                # update statusbar
-                ### self.parent.StatusbarUpdate()
+            # redraw map
+            self.DoPaint()
+            
+            # update statusbar
+            ### self.parent.StatusbarUpdate()
+            
+    def OnLeftDown(self, event):
+        """!On left mouse down"""
+        if self.mouse['use'] == "lookHere":
+            pos = event.GetPosition()
+            size = self.GetClientSize()
+            self._display.LookHere(pos[0], size[1] - pos[1])
+            self.Refresh(False)
+            focus = self._display.GetFocus()
+            for i, coord in enumerate(('x', 'y', 'z')):
+                self.iview['focus'][coord] = focus[i]
+            toggle = self.lmgr.nviz.FindWindowByName('here')
+            toggle.SetValue(False)
+            self.mouse['use'] = 'default'
+            self.SetCursor(self.cursors['default'])
+            
+        if self.mouse['use'] == "cplane":   
+            pos = event.GetPosition()
+            size = self.GetClientSize()
+            x, y, z = self._display.SetCPlaneInteractively(pos[0], size[1] - pos[1])
+            if x is not None: 
+                idx = self._display.GetCPlaneCurrent()
+                self.cplanes[idx]['position']['x'] = x
+                self.cplanes[idx]['position']['y'] = y
+                self.render['quick'] = True
+            
+        event.Skip()    
         
-        if event.LeftDown():
-            if self.mouse['use'] == "lookHere":
-                pos = event.GetPosition()
-                size = self.GetClientSize()
-                self._display.LookHere(pos[0], size[1] - pos[1])
-                self.Refresh(False)
-                focus = self._display.GetFocus()
-                for i, coord in enumerate(('x', 'y', 'z')):
-                    self.iview['focus'][coord] = focus[i]
-                toggle = self.lmgr.nviz.FindWindowByName('here')
-                toggle.SetValue(False)
-                self.mouse['use'] = 'default'
-                self.SetCursor(self.cursors['default'])
+    def OnDragging(self, event):
+        if self.mouse['use'] == "cplane":  
+            idx = self._display.GetCPlaneCurrent() 
+            pos = event.GetPosition()
+            size = self.GetClientSize()
+            x, y, z = self._display.SetCPlaneInteractively(pos[0], size[1] - pos[1])
+            if x is not None: 
+                self.cplanes[idx]['position']['x'] = x
+                self.cplanes[idx]['position']['y'] = y 
                 
         event.Skip()
-
+            
     def Pixel2Cell(self, (x, y)):
         """!Convert image coordinates to real word coordinates
 
@@ -286,7 +327,7 @@
         """
         size = self.GetClientSize()
         # UL -> LL
-        sid, x, y, z = self._display.GetPointOnSurface(x, y)
+        sid, x, y, z = self._display.GetPointOnSurface(x, size[1] - y)
         
         if not sid:
             return None
@@ -299,6 +340,13 @@
             self.OnQuerySurface(event)
         elif self.mouse["use"] == "nvizQueryVector":
             self.OnQueryVector(event)
+        elif self.mouse["use"] == 'cplane':
+            self.lmgr.nviz.OnCPlaneChangeDone(None)
+            idx = self._display.GetCPlaneCurrent() 
+            self.lmgr.nviz.UpdateCPlanePage(idx)
+            self.lmgr.nviz.FindWindowByName('cplaneHere').SetValue(False)
+            self.mouse['use'] = 'default'
+            self.SetCursor(self.cursors['default'])
     
     def OnQuerySurface(self, event):
         """!Query surface on given position"""
@@ -1292,7 +1340,7 @@
                 return data['volume']['object']['id']
         return -1
     
-    def Nviz_cmd_command(self):
+    def NvizCmdCommand(self):
         """!Generate command for nviz_cmd according to current state"""
         cmd = 'nviz_cmd '
         
@@ -1502,7 +1550,11 @@
         cmd += subcmd
         
         return cmd
-
+    
+    def OnNvizCmd(self):
+        """!Generate and write command to command output"""
+        self.log.WriteLog(self.NvizCmdCommand(), switchPage = True)
+        
     def SaveToFile(self, FileName, FileType, width, height):
         """!This draws the DC to a buffer that can be saved to a file.
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-07-03 11:06:03 UTC (rev 46933)
@@ -833,7 +833,13 @@
         gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['text']),
                       pos = (1, 2),
                       flag = wx.ALIGN_CENTER)
-                    
+        posButton = wx.ToggleButton(parent = panel, id = wx.ID_ANY, label = _("On display"))
+        posButton.Bind(wx.EVT_TOGGLEBUTTON, self.OnCPlanePos)
+        posButton.SetName('cplaneHere')
+        self.win['cplane']['cplaneHere'] = posButton.GetId()
+        
+        gridSizer.Add(item = posButton, pos = (0, 3), span = (2, 1), flag = wx.EXPAND)
+                 
         self._createControl(panel, data = self.win['cplane']['position'], name = 'z', size = 250,
                             range = (-1000, 1000), sliderHor = True,
                             bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
@@ -3092,6 +3098,17 @@
         self.OnCPlaneChangeDone(None)
         self.UpdateCPlanePage(planeIndex)
         
+    def OnCPlanePos(self, event): 
+        plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
+        try:
+            planeIndex = int(plane.split()[1])
+        except:#TODO disabled page
+            planeIndex = -1
+        self.mapWindow.mouse['use'] = 'cplane'
+        self.mapWindow.SetCursor(self.mapWindow.cursors["cross"])
+        self.parent.curr_page.maptree.mapdisplay.SetFocus()
+        self.parent.curr_page.maptree.mapdisplay.Raise()
+        
     def UpdatePage(self, pageId):
         """!Update dialog (selected page)"""
         self.pageChanging = True

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-07-03 11:06:03 UTC (rev 46933)
@@ -1349,8 +1349,7 @@
         
     def OnNvizCmd(self, event):
         """!Show nviz_cmd command"""
-        cmd = self.parent.MapWindow.Nviz_cmd_command()
-        self.lmgr.GetLogWindow().WriteLog(text = cmd, switchPage = True)
+        self.parent.MapWindow.OnNvizCmd()
         
     def OnHelp(self, event):
         """!Show 3D view mode help"""

Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-07-03 11:06:03 UTC (rev 46933)
@@ -1237,7 +1237,10 @@
             return -2
         
         return 1
-
+    
+    def GetCPlaneCurrent(self):
+        return Nviz_get_current_cplane(self.data)
+    
     def GetCPlanesCount(self):
         """!Returns number of cutting planes"""
         return Nviz_num_cplanes(self.data) 
@@ -1279,7 +1282,18 @@
         Nviz_draw_cplane(self.data, -1, -1) 
         Debug.msg(3, "Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%f",
                   current, x, y, z)
-           
+                
+    def SetCPlaneInteractively(self, x, y):
+        current = Nviz_get_current_cplane(self.data)
+        ret = Nviz_set_cplane_here(self.data, current, x, y)
+        if ret:
+            Nviz_draw_cplane(self.data, -1, -1)
+            x, y, z = self.GetCPlaneTranslation()
+            return x, y, z
+        else:
+            return None, None, None
+        
+        
     def SelectCPlane(self, index):
         """!Select cutting plane
         

Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/include/nviz.h	2011-07-03 11:06:03 UTC (rev 46933)
@@ -143,6 +143,7 @@
 int Nviz_set_cplane_translation(nv_data *, int, float, float, float);
 int Nviz_get_cplane_translation(nv_data *, int, float *, float *, float *);
 int Nviz_set_fence_color(nv_data *, int);
+int Nviz_set_cplane_here(nv_data *, int, float, float);
 
 
 /* draw.c */

Modified: grass/trunk/lib/nviz/cplanes_obj.c
===================================================================
--- grass/trunk/lib/nviz/cplanes_obj.c	2011-07-02 09:04:16 UTC (rev 46932)
+++ grass/trunk/lib/nviz/cplanes_obj.c	2011-07-03 11:06:03 UTC (rev 46933)
@@ -15,6 +15,7 @@
 #include <grass/nviz.h>
 
 static void cp_draw(nv_data *, int, int, int);
+static geoview Gv;
 
 /*!
    \brief Creates a clip plane object
@@ -242,3 +243,44 @@
     return 1;
 
 }
+int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
+{
+    float x, y, z, len, los[2][3];
+    float dx, dy, dz;
+    float n, s, w, e;
+    Point3 realto, dir;
+    int id;
+    geosurf *gs;
+
+    if (GS_get_selected_point_on_surface(sx, sy, &id, &x, &y, &z)) {
+	gs = gs_get_surf(id);
+	if (gs) {
+	    realto[X] = x - gs->ox + gs->x_trans;
+	    realto[Y] = y - gs->oy + gs->y_trans;
+	    realto[Z] = z + gs->z_trans;
+	}
+	else
+	    return 0;
+    }
+    else {
+	if (gsd_get_los(los, (short)sx, (short)sy)) {
+	    len = GS_distance(Gv.from_to[FROM], Gv.real_to);
+	    GS_v3dir(los[FROM], los[TO], dir);
+	    GS_v3mult(dir, len);
+	    realto[X] = Gv.from_to[FROM][X] + dir[X];
+	    realto[Y] = Gv.from_to[FROM][Y] + dir[Y];
+	    realto[Z] = Gv.from_to[FROM][Z] + dir[Z];
+	}
+	else
+	    return 0;
+    }  
+    Nviz_get_cplane_translation(data, cplane, &dx, &dy, &dz);
+
+    GS_get_region(&n, &s, &w, &e);
+    dx = realto[X] - (e - w) / 2.;
+    dy = realto[Y] - (n - s) / 2.;
+
+    Nviz_set_cplane_translation(data, cplane, dx, dy, dz);
+
+    return 1;
+}



More information about the grass-commit mailing list