[GRASS-SVN] r31828 - in grass-addons/visualization/nviz2/wxpython: . nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 23 11:55:11 EDT 2008


Author: martinl
Date: 2008-06-23 11:55:11 -0400 (Mon, 23 Jun 2008)
New Revision: 31828

Modified:
   grass-addons/visualization/nviz2/wxpython/mapdisp.py
   grass-addons/visualization/nviz2/wxpython/nviz.py
   grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
   grass-addons/visualization/nviz2/wxpython/toolbars.py
Log:
nviz2: initial wxnviz prototype under development

Modified: grass-addons/visualization/nviz2/wxpython/mapdisp.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/mapdisp.py	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/mapdisp.py	2008-06-23 15:55:11 UTC (rev 31828)
@@ -3,6 +3,7 @@
 
 CLASSES:
  - Command
+ - MapWindow
  - BufferedWindow
  - MapFrame
  - MapApp
@@ -122,7 +123,11 @@
         sys.exit()
 
 class MapWindow(object):
-    """Generic map window class"""
+    """Abstract map window class
+
+    Parent for BufferedWindow class (2D display mode) and
+    GLWindow (3D display mode)
+    """
     def __init__(self, parent, id,
                  pos=wx.DefaultPosition,
                  size=wx.DefaultSize,
@@ -130,6 +135,28 @@
                  Map=None, tree=None, gismgr=None):
         pass
 
+    def EraseMap(self):
+        """
+        Erase the canvas (virtual method)
+        """
+        pass
+
+    def UpdateMap(self):
+        """
+        Updates the canvas anytime there is a change to the
+        underlaying images or to the geometry of the canvas.
+        """
+        pass
+
+    def OnLeftDown(self, event):
+        pass
+
+    def OnLeftUp(self, event):
+        pass
+
+    def OnMouseMotion(self, event):
+        pass
+
 class BufferedWindow(MapWindow, wx.Window):
     """
     A Buffered window class.
@@ -722,7 +749,7 @@
 
     def EraseMap(self):
         """
-        Erase the map display
+        Erase the canvas
         """
         self.Draw(self.pdc, pdctype='clear')
 
@@ -2380,11 +2407,14 @@
         #
         # Init map display (buffered DC & set default cursor)
         #
-        self.MapWindow = BufferedWindow(self, id=wx.ID_ANY,
-                                        Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+        self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,
+                                          Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+        # default is 2D display mode
+        self.MapWindow = self.MapWindow2D
         self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
         self.MapWindow.SetCursor(self.cursors["default"])
-        self.MapWindowGL = None # used by Nviz (default is 2D display mode)
+        # used by Nviz (3D display mode)
+        self.MapWindow3D = None 
 
         #
         # initialize region values
@@ -2513,17 +2543,23 @@
             #
             # create GL window & NVIZ toolbar
             #
-            self.MapWindowGL = nviz.GLWindow(self, id=wx.ID_ANY,
+            if not self.MapWindow3D:
+                self.MapWindow3D = nviz.GLWindow(self, id=wx.ID_ANY,
                                              Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+            
+            #
+            # add Nviz toolbar and disable 2D display mode tools
+            #
             self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
+            self.toolbars['map'].Enable2D(False)
 
             #
             # switch from MapWindow to MapWindowGL
             # add nviz toolbar
             #
-            self._mgr.DetachPane(self.MapWindow)
-            self.MapWindow.Hide()
-            self._mgr.AddPane(self.MapWindowGL, wx.aui.AuiPaneInfo().CentrePane().
+            self._mgr.DetachPane(self.MapWindow2D)
+            self.MapWindow2D.Hide()
+            self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
                               Dockable(False).BestSize((-1,-1)).
                               CloseButton(False).DestroyOnClose(True).
                               Layer(0))
@@ -2534,6 +2570,7 @@
                               LeftDockable(False).RightDockable(False).
                               BottomDockable(False).TopDockable(True).
                               CloseButton(False).Layer(2))
+            self.MapWindow = self.MapWindow3D
             
         self._mgr.Update()
 
@@ -2559,16 +2596,20 @@
         self.toolbars[name] = None
 
         if name == 'nviz':
+            # unload data
+            self.MapWindow3D.Reset()
             # switch from MapWindowGL to MapWindow
-            self._mgr.DetachPane(self.MapWindowGL)
-            self.MapWindowGL.Hide()
-            self.MapWindow.Show()
-            self._mgr.AddPane(self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().
+            self._mgr.DetachPane(self.MapWindow3D)
+            self.MapWindow3D.Hide()
+            self.MapWindow2D.Show()
+            self._mgr.AddPane(self.MapWindow2D, wx.aui.AuiPaneInfo().CentrePane().
                               Dockable(False).BestSize((-1,-1)).
                               CloseButton(False).DestroyOnClose(True).
                               Layer(0))
+            self.MapWindow = self.MapWindow2D
         
         self.toolbars['map'].combo.SetValue ("Tools")
+        self.toolbars['map'].Enable2D(True)
 
         self._mgr.Update()
 

Modified: grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	2008-06-23 15:55:11 UTC (rev 31828)
@@ -28,3 +28,13 @@
 
     return;
 }
+
+/*!
+  \brief Erase map display (with background color)
+*/
+void Nviz::EraseMap()
+{
+    GS_clear(data->bgcolor);
+
+    return;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-23 15:55:11 UTC (rev 31828)
@@ -33,10 +33,6 @@
 
     data = (nv_data*) G_malloc(sizeof (nv_data));
 
-    /* initialize render window */
-    rwind = Nviz_new_render_window();
-    Nviz_init_render_window(rwind);
-
     /* GLCanvas */
     glCanvas = NULL;
 }
@@ -46,12 +42,8 @@
 */
 Nviz::~Nviz()
 {
-    Nviz_destroy_render_window(rwind);
-
-    G_free((void *) rwind);
     G_free((void *) data);
 
-    rwind = NULL;
     data = NULL;
     glCanvas = NULL;
 }
@@ -64,9 +56,6 @@
 */
 int Nviz::SetDisplay(void *display)
 {
-    if (!rwind)
-	return 0;
-
     glCanvas = (wxGLCanvas *) display;
     // glCanvas->SetCurrent();
 
@@ -95,6 +84,24 @@
     return;
 }
 
+/*!
+  \brief Reset session
+
+  Unload all data layers
+
+  @todo vector, volume
+*/
+void Nviz::Reset()
+{
+    int i;
+    int *surf_list, nsurfs;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+    for (i = 0; i < nsurfs; i++) {
+	GS_delete_surface(surf_list[i]);
+    }
+}
+
 void swap_gl()
 {
     return;

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-23 15:55:11 UTC (rev 31828)
@@ -25,7 +25,6 @@
 class Nviz
 {
 private:
-    struct render_window *rwind;
     nv_data *data;
     wxGLCanvas *glCanvas;
 
@@ -36,23 +35,32 @@
     /* destructor */
     ~Nviz();
 
+    /* change_view.cpp */
     int ResizeWindow(int, int);
 
     /* set */
+    /* init.cpp */
     int SetDisplay(void *);
+    void Reset();
 
     /* lights */
+    /* lights.cpp */
     void SetLightsDefault();
     
     /* viewport */
+    /* change_view.cpp */
     void SetViewportDefault();
+    /* init.cpp */
     void InitView();
 
     /* load data */
+    /* load.cpp */
     int LoadRaster(const char*, const char *, const char *);
 
     /* draw */
+    /* draw.cpp */
     void Draw();
+    void EraseMap();
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-23 15:55:11 UTC (rev 31828)
@@ -48,9 +48,13 @@
                  style=wx.NO_FULL_REPAINT_ON_RESIZE,
                  Map=None, tree=None, gismgr=None):
 
+        self.Map = Map
+        self.tree = tree
+        self.gismgr = gismgr
+
         glcanvas.GLCanvas.__init__(self, parent, id)
-        # MapWindow.__init__(self, parent, id, pos, size, style,
-        #                   Map, tree, gismgr)
+        MapWindow.__init__(self, parent, id, pos, size, style,
+                           Map, tree, gismgr)
 
 
         self.parent = parent # MapFrame
@@ -73,17 +77,19 @@
         #
         self.nvizClass.SetDisplay(self)
 
+        #
         # initialize mouse position
-        # self.lastx = self.x = 30
-        # self.lasty = self.y = 30
+        #
+        self.lastX = self.x = 30
+        self.lastY = self.y = 30
 
         self.size = None
         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
         self.Bind(wx.EVT_SIZE, self.OnSize)
         self.Bind(wx.EVT_PAINT, self.OnPaint)
-        #        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
-        #        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
-        #        self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
+        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
+        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
+        self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
 
     def OnEraseBackground(self, event):
         pass # do nothing, to avoid flashing on MSW
@@ -106,16 +112,73 @@
         self.SetCurrent()
         if not self.init:
             self.nvizClass.InitView()
-            self.nvizClass.LoadRaster("elevation", None, None);
+            self.LoadDataLayers()
             self.nvizClass.SetViewportDefault()
             self.nvizClass.SetLightsDefault()
             self.init = True
-        self.OnDraw()
+        self.DrawMap()
 
-    def OnDraw(self):
+    def OnMouseMotion(self, event):
+        if event.Dragging() and event.LeftIsDown():
+            self.lastX = self.lastY = self.x = self.y
+            self.x, self.y = event.GetPosition()
+            self.Refresh(False)
+
+    def OnLeftDown(self, event):
+        self.CaptureMouse()
+        self.x, self.y = self.lastX, self.lastY = event.GetPosition()
+        
+    def OnLeftUp(self, event):
+        self.ReleaseMouse()
+
+    def DrawMap(self):
         """Draw data layers"""
-        Debug.msg(3, "GLCanvas.OnDraw()")
+        Debug.msg(3, "GLCanvas.Draw()")
 
         self.nvizClass.Draw()
+
+        #         if self.size is None:
+        #             self.size = self.GetClientSize()
+        
+        #         w, h = self.size
+        #         w = max(w, 1.0)
+        #         h = max(h, 1.0)
+        #         xScale = 180.0 / w
+        #         yScale = 180.0 / h
+        #         glRotatef((self.y - self.lastY) * yScale, 1.0, 0.0, 0.0);
+        #         glRotatef((self.x - self.lastX) * xScale, 0.0, 1.0, 0.0);
+
         self.SwapBuffers()
 
+    def EraseMap(self):
+        """
+        Erase the canvas
+        """
+        self.nvizClass.EraseMap()
+        self.SwapBuffers()
+
+    def UpdateMap(self, render=True):
+        """
+        Updates the canvas anytime there is a change to the
+        underlaying images or to the geometry of the canvas.
+
+        @todo render=False
+
+        @param render re-render map composition
+        """
+        self.nvizClass.Draw()
+        self.SwapBuffers()
+
+    def LoadDataLayers(self):
+        """Load raster/vector from current layer tree
+
+        @todo volumes
+        """
+        for raster in self.Map.GetListOfLayers(l_type='raster', l_active=True):
+            print raster.name
+            self.nvizClass.LoadRaster(str(raster.name), None, None);
+
+    def Reset(self):
+        """Reset (unload data)"""
+        self.nvizClass.Reset()
+        self.init = False

Modified: grass-addons/visualization/nviz2/wxpython/toolbars.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/toolbars.py	2008-06-23 13:38:31 UTC (rev 31827)
+++ grass-addons/visualization/nviz2/wxpython/toolbars.py	2008-06-23 15:55:11 UTC (rev 31828)
@@ -201,6 +201,21 @@
         elif tool == "Nviz" and not self.mapdisplay.toolbars['nviz']:
             self.mapdisplay.AddToolbar("nviz")
 
+    def Enable2D(self, enabled):
+        """Enable/Disable 2D display mode specific tools"""
+        for tool in (self.pointer,
+                     self.query,
+                     self.pan,
+                     self.zoomin,
+                     self.zoomout,
+                     self.zoomback,
+                     self.zoommenu,
+                     self.analyze,
+                     self.dec,
+                     self.savefile,
+                     self.printmap):
+            self.toolbar.EnableTool(tool, enabled)
+
 class GRToolbar(AbstractToolbar):
     """
     Georectify Display toolbar



More information about the grass-commit mailing list