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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 21 06:13:05 EDT 2008


Author: martinl
Date: 2008-07-21 06:13:04 -0400 (Mon, 21 Jul 2008)
New Revision: 32192

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
   grass/trunk/gui/wxpython/nviz/load.cpp
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/include/nviz.h
   grass/trunk/lib/nviz/map_obj.c
Log:
nviz2/wxGUI: initial steps towards 2d points support

Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-21 10:13:04 UTC (rev 32192)
@@ -403,11 +403,13 @@
 
     def UnloadRaster(self, id):
         """Unload raster map"""
+        idx = self.layers['raster']['id'].index(id)
+        layerName = self.layers['raster']['name']
+        
         if self.nvizClass.UnloadSurface(id) == 0:
             raise gcmd.NvizError(parent=self.parent,
-                                 message=_("Unable to unload raster map <%s>" % layer.name))
+                                 message=_("Unable to unload raster map <%s>" % layerName))
 
-        idx = self.layers['raster']['id'].index(id)
         del self.layers['raster']['name'][idx]
         del self.layers['raster']['id'][idx]
 
@@ -523,12 +525,17 @@
                                  'desc' : desc,
                                  'all' : False }
 
-    def LoadVector(self, layer):
-        """Load vector map overlay"""
+    def LoadVector(self, layer, points=False):
+        """Load vector map overlay
+
+        @param layer map layer instance
+        @param points if True load points instead of lines
+        """
         if layer.type != 'vector':
             return
 
-        id = self.nvizClass.LoadVector(str(layer.name))
+        id = self.nvizClass.LoadVector(str(layer.name), points)
+        print id, points
         if id < 0:
             raise gcmd.NvizError(parent=self.parent,
                                  message=_("Unable to load vector map <%s>" % layer.name))
@@ -538,24 +545,25 @@
 
         return id
 
-    def UnloadVector(self, id):
-        """Unload vector map overlay"""
-        if self.nvizClass.UnloadVector(id) == 0:
+    def UnloadVector(self, id, points=False):
+        """Unload vector map overlay
+
+        @param id data layer id
+        @param points if True unload points layer instead of lines layer
+        """
+        ret = self.nvizClass.UnloadVector(id, points)
+
+        idx = self.layers['vector']['id'].index(id)
+        layerName = self.layers['vector']['name'][idx]
+
+        if ret == 0:
             raise gcmd.NvizError(parent=self.parent,
-                                 message=_("Unable to unload vector map <%s>" % layer.name))
+                                 message=_("Unable to unload vector map <%s>" % layerName))
 
-        idx = self.layers['vector']['id'].index(id)
+        
         del self.layers['vector']['name'][idx]
         del self.layers['vector']['id'][idx]
 
-        if hasattr(self.parent, "nvizToolWin"):
-            toolWin = self.parent.nvizToolWin
-            # remove vector page
-            if toolWin.notebook.GetSelection() == toolWin.page['vector']['id']:
-                toolWin.notebook.RemovePage(toolWin.page['vector']['id'])
-                toolWin.page['vector']['id'] = -1
-                toolWin.page['settings']['id'] = 1
-
     def SetVectorDefaultProp(self, data):
         """Set default vector properties"""
         if UserSettings.Get(group='nviz', key='vector',
@@ -1284,7 +1292,10 @@
         showLines = wx.CheckBox(parent=panel, id=wx.ID_ANY,
                                 label=_("Show vector lines"))
         self.win['vector']['lines']['show'] = showLines.GetId()
-        showLines.SetValue(True)
+        showLines.SetValue(UserSettings.Get(group='nviz', key='vector',
+                                            subkey=['lines', 'show']))
+        self.UpdateVectorShow(showLines.GetId(),
+                              showLines.IsChecked())
         showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
 
         pageSizer.Add(item=showLines, proportion=0,
@@ -1378,8 +1389,11 @@
         showPoints = wx.CheckBox(parent=panel, id=wx.ID_ANY,
                                 label=_("Show vector points"))
         self.win['vector']['points']['show'] = showPoints.GetId()
-        showPoints.SetValue(False) # disable by default
-        showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
+        showPoints.SetValue(UserSettings.Get(group='nviz', key='vector',
+                                             subkey=['points', 'show']))
+        self.UpdateVectorShow(showPoints.GetId(),
+                              showPoints.IsChecked())
+        showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
 
         pageSizer.Add(item=showPoints, proportion=0,
                       flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
@@ -1695,6 +1709,7 @@
                                  label=_("Show points"))
         showPoints.SetValue(UserSettings.Get(group='nviz', key='vector',
                                              subkey=['points', 'show']))
+        self.win['settings']['vector']['points']['show'] = showPoints.GetId()
         gridSizer.Add(item=showPoints, pos=(row, 0))
 
         # icon size
@@ -1720,17 +1735,19 @@
         isym = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
                           choices=UserSettings.Get(group='nviz', key='vector',
                                                    subkey=['points', 'icon'], internal=True))
+        isym.SetName("selection")
         self.win['settings']['vector']['points']['symbol'] = isym.GetId()
         isym.SetSelection(UserSettings.Get(group='nviz', key='vector',
                                            subkey=['points', 'symbol']))
         gridSizer.Add(item=isym, flag=wx.ALIGN_CENTER_VERTICAL,
                       pos=(row, 3))
 
-        # icon symbol
+        # icon color
         gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
                                          label=_("color:")),
                       pos=(row, 4), flag=wx.ALIGN_CENTER_VERTICAL)
         icolor = csel.ColourSelect(panel, id=wx.ID_ANY)
+        icolor.SetName("color")
         self.win['settings']['vector']['points']['color'] = icolor.GetId()
         icolor.SetColour(UserSettings.Get(group='nviz', key='vector',
                                           subkey=['points', 'color']))
@@ -1956,10 +1973,16 @@
         for subgroup, key in settings.iteritems(): # view, surface, vector...
             for subkey, value in key.iteritems():
                 for subvalue in value.keys():
-                    # print subgroup, subkey, subvalue, value
-                    win = self.FindWindowById(self.win['settings'][subgroup][subkey][subvalue])
+                    # print subgroup, subkey, subvalue
+                    try: # TODO
+                        win = self.FindWindowById(self.win['settings'][subgroup][subkey][subvalue])
+                    except:
+                        continue
+                    
                     if win.GetName() == "selection":
                         value = win.GetSelection()
+                    elif win.GetName() == "color":
+                        value = win.GetColour()
                     else:
                         value = win.GetValue()
                     if subkey == 'pos':
@@ -2238,35 +2261,67 @@
         if self.parent.autoRender.IsChecked():
             self.mapWindow.Refresh(False)
 
-    def OnVectorShow(self, event):
-        """Show vector lines/points"""
-        checked = event.IsChecked()
-        
-        id = event.GetId()
-        sec = None
-        if id == self.win['vector']['lines']['show']:
-            sec = 'lines'
-        elif id == self.win['vector']['points']['show']:
-            sec = 'points'
+    def UpdateVectorShow(self, vecType, enabled):
+        """Enable/disable lines/points widgets
 
-        if sec is None:
-            return
+        @param vecType vector type (lines, points)
+        """
+        if vecType != 'lines' and vecType != 'points':
+            return False
 
-        for win in self.win['vector'][sec].keys():
+        for win in self.win['vector'][vecType].keys():
             if win == 'show':
                 continue
-            if type(self.win['vector'][sec][win]) == type({}):
-                for swin in self.win['vector'][sec][win].keys():
-                    if checked:
-                        self.FindWindowById(self.win['vector'][sec][win][swin]).Enable(True)
+            if type(self.win['vector'][vecType][win]) == type({}):
+                for swin in self.win['vector'][vecType][win].keys():
+                    if enabled:
+                        self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
                     else:
-                        self.FindWindowById(self.win['vector'][sec][win][swin]).Enable(False)
+                        self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
             else:
-                if checked:
-                    self.FindWindowById(self.win['vector'][sec][win]).Enable(True)
+                if enabled:
+                    self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
                 else:
-                    self.FindWindowById(self.win['vector'][sec][win]).Enable(False)
+                    self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
 
+        return True
+    
+    def OnVectorShow(self, event):
+        """Show vector lines/points"""
+        winId = event.GetId()
+
+        vecType = None
+        if winId == self.win['vector']['lines']['show']:
+            vecType = 'lines'
+        elif winId == self.win['vector']['points']['show']:
+            vecType = 'points'
+
+        if vecType is None:
+            return
+
+        checked = event.IsChecked()
+        mapLayer = self.mapWindow.GetSelectedLayer()
+        data = self.mapWindow.GetSelectedLayer(nviz=True)
+        id = data['object']['id']
+
+        if vecType == 'lines':
+            if checked:
+                self.mapWindow.LoadVector(mapLayer)
+            else:
+                self.mapWindow.UnloadVector(id)
+        else: # points
+            if checked:
+                self.mapWindow.LoadVector(mapLayer, points=True)
+            else:
+                self.mapWindow.UnloadVector(id, points=True)
+            
+        self.UpdateVectorShow(vecType, checked)
+        
+        if self.parent.autoRender.IsChecked():
+            self.mapWindow.Refresh(False)
+
+        event.Skip()
+    
     def OnVectorDisplay(self, event):
         """Display vector lines on surface/flat"""
         if event.GetSelection() == 0: # surface

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-21 10:13:04 UTC (rev 32192)
@@ -852,6 +852,15 @@
                     self.mapdisplay.MapWindow.UnloadRaster(id)
                 elif mapLayer.type == 'vector':
                     self.mapdisplay.MapWindow.UnloadVector(id)
+                    
+                    if hasattr(self.parent, "nvizToolWin"):
+                        toolWin = self.parent.nvizToolWin
+                        # remove vector page
+                        if toolWin.notebook.GetSelection() == toolWin.page['vector']['id']:
+                            toolWin.notebook.RemovePage(toolWin.page['vector']['id'])
+                            toolWin.page['vector']['id'] = -1
+                            toolWin.page['settings']['id'] = 1
+
                 data.pop('object')
                 data.pop('view')
 

Modified: grass/trunk/gui/wxpython/nviz/load.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/load.cpp	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/gui/wxpython/nviz/load.cpp	2008-07-21 10:13:04 UTC (rev 32192)
@@ -112,11 +112,12 @@
   \brief Load vector map overlay
 
   \param name vector map name
+  \param points if true load 2d points rather then 2d lines
 
   \return object id
   \return -1 on failure
 */
-int Nviz::LoadVector(const char *name)
+int Nviz::LoadVector(const char *name, bool points)
 {
     int id;
     char *mapset;
@@ -133,12 +134,19 @@
     mapset = G_find_vector2 (name, "");
     if (mapset == NULL) {
 	G_warning(_("Vector map <%s> not found"),
-		      name);
+		  name);
     }
 
-    id = Nviz_new_map_obj(MAP_OBJ_VECT,
-		     G_fully_qualified_name(name, mapset), 0.0,
-		     data);
+    if (points) {
+      id = Nviz_new_map_obj(MAP_OBJ_SITE,
+			    G_fully_qualified_name(name, mapset), 0.0,
+			    data);
+    }
+    else {
+      id = Nviz_new_map_obj(MAP_OBJ_VECT,
+			    G_fully_qualified_name(name, mapset), 0.0,
+			    data);
+    }
 
     G_debug(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id);
 
@@ -146,23 +154,34 @@
 }
   
 /*!
-  \brief Unload vector
+  \brief Unload vector set
 
-  \param id surface id
+  \param id vector set id
+  \param points vector points or lines set
 
   \return 1 on success
   \return 0 on failure
 */
-int Nviz::UnloadVector(int id)
+int Nviz::UnloadVector(int id, bool points)
 {
-    if (!GV_vect_exists(id)) {
-	return 0;
-    }
-
     G_debug(1, "Nviz::UnloadVector(): id=%d", id);
 
-    if (GV_delete_vector(id) < 0)
-      return 0;
+    if (points) {
+	if (!GP_site_exists(id)) {
+	    return 0;
+	}
+	
+	if (GP_delete_site(id) < 0)
+	    return 0;
+    }
+    else {
+	if (!GV_vect_exists(id)) {
+	    return 0;
+	}
+	
+	if (GV_delete_vector(id) < 0)
+	    return 0;
+    }
 
     return 1;
 }

Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-21 10:13:04 UTC (rev 32192)
@@ -60,8 +60,8 @@
     /* load.cpp */
     int LoadSurface(const char*, const char *, const char *);
     int UnloadSurface(int);
-    int LoadVector(const char *);
-    int UnloadVector(int);
+    int LoadVector(const char *, bool);
+    int UnloadVector(int, bool);
 
     /* draw.cpp */
     void Draw(bool);

Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/include/nviz.h	2008-07-21 10:13:04 UTC (rev 32192)
@@ -40,6 +40,7 @@
 #define MAP_OBJ_SURF 1
 #define MAP_OBJ_VOL 2
 #define MAP_OBJ_VECT 3
+#define MAP_OBJ_SITE 4
 
 #define DRAW_COARSE 0
 #define DRAW_FINE 1

Modified: grass/trunk/lib/nviz/map_obj.c
===================================================================
--- grass/trunk/lib/nviz/map_obj.c	2008-07-21 10:07:50 UTC (rev 32191)
+++ grass/trunk/lib/nviz/map_obj.c	2008-07-21 10:13:04 UTC (rev 32192)
@@ -100,7 +100,7 @@
 	if (name) {
 	    if (GV_load_vector(new_id, name) < 0) {
 		GV_delete_vector(new_id);
-		G_warning (_("Error loading vector <%s>"), name);
+		G_warning (_("Error loading vector map <%s>"), name);
 		return -1;
 	    }
 	}
@@ -116,7 +116,42 @@
 	}
 	G_free (surf_list);
     }
+    /* vector points overlay */
+    else if (type == MAP_OBJ_SITE) {
+	geosite * gp;
+	if (GP_num_sites() >= MAX_SITES) {
+	    G_warning (_("Maximum point vectors loaded!"));
+	    return -1;
+	}
+	
+	new_id = GP_new_site();
 
+	/* initizalize site attributes */
+	/* TODO: move to ogsflib */
+	gp = gp_get_site(new_id);
+
+	for (i = 0; i < GPT_MAX_ATTR; i++)
+	    gp->use_attr[i] = ST_ATT_NONE;
+
+
+	/* load vector points */
+	if (0 > GP_load_site(new_id, name)) {
+	    GP_delete_site(new_id);
+	    G_warning (_("Error loading point vector map <%s>"), name);
+	    return -1;
+	}
+
+	/* initialize display parameters */
+	GP_set_sitemode(new_id, ST_ATT_NONE, 0xFF0000, 2, 100, ST_X);
+	surf_list = GS_get_surf_list(&num_surfs);
+	if (num_surfs) {
+	    for (i = 0; i < num_surfs; i++) {
+		GP_select_surf(new_id, surf_list[i]);
+	    }
+	}
+	G_free (surf_list);
+    }
+
     /* initialize the client data filled for the new map object */
     client_data = (nv_clientdata *) G_malloc (sizeof(nv_clientdata));
 



More information about the grass-commit mailing list