Pārlūkot izejas kodu

nviz2/wxGUI: improved 2d vector points support

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32226 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 17 gadi atpakaļ
vecāks
revīzija
36da01dddb

+ 7 - 4
gui/wxpython/gui_modules/mapdisp.py

@@ -163,12 +163,12 @@ class MapWindow(object):
     def OnZoomToRaster(self, event):
         pass
 
-    def GetSelectedLayer(self, nviz=False, index=False):
+    def GetSelectedLayer(self, type='layer'):
         """Get selected layer from layer tree
 
-        @param nviz get nviz properties instead
+        @param type 'item' / 'layer' / 'nviz'
 
-        @return map layer instance
+        @return layer / map layer properties / nviz properties
         @return None on failure
         """
         # get currently selected map layer
@@ -179,8 +179,11 @@ class MapWindow(object):
         if not item.IsChecked():
             return None
 
+        if type == 'item':
+            return item
+        
         try:
-            if nviz:
+            if type == 'nviz':
                 layer = self.tree.GetPyData(item)[0]['nviz']
             else:
                 layer = self.tree.GetPyData(item)[0]['maplayer']

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 464 - 179
gui/wxpython/gui_modules/nviz.py


+ 13 - 9
gui/wxpython/gui_modules/preferences.py

@@ -397,8 +397,10 @@ class Settings:
                     'points' : {
                         'show' : False,
                         'size' : 100,
-                        'symbol' : 1,
+                        'width' : 2,
+                        'marker' : 2,
                         'color' : (0, 0, 255, 255), # blue
+                        'height' : 0,
                         }
                     },
                 'settings': {
@@ -461,14 +463,16 @@ class Settings:
         self.internalSettings['nviz']['view']['height']['value'] = -1
         self.internalSettings['nviz']['vector'] = {}
         self.internalSettings['nviz']['vector']['points'] = {}
-        self.internalSettings['nviz']['vector']['points']['icon'] = ('x',
-                                                                     _("sphere"),
-                                                                     _("diamond"),
-                                                                     _("cube"),
-                                                                     _("box"),
-                                                                     _("gyro"),
-                                                                     _("aster"),
-                                                                     _("histogram"))
+        self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
+                                                                       _("box"),
+                                                                       _("sphere"),
+                                                                       _("cube"),
+                                                                       _("diamond"),
+                                                                       _("dtree"),
+                                                                       _("ctree"),
+                                                                       _("aster"),
+                                                                       _("gyro"),
+                                                                       _("histogram"))
     def ReadSettingsFile(self, settings=None):
         """Reads settings file (mapset, location, gisdbase)"""
         if settings is None:

+ 10 - 27
gui/wxpython/gui_modules/wxgui_utils.py

@@ -829,43 +829,32 @@ class LayerTree(CT.CustomTreeCtrl):
             # nviz - load/unload data layer
             mapLayer = self.GetPyData(item)[0]['maplayer']
 
-            busy = wx.BusyInfo(message=_("Please wait, updating data..."),
-                               parent=self.mapdisplay)
-
-            wx.Yield()            
+            self.mapdisplay.SetStatusText(_("Please wait, updating data..."), 0)
 
             if checked: # enable
-                id = -1
                 if mapLayer.type == 'raster':
-                    id = self.mapdisplay.MapWindow.LoadRaster(mapLayer)
+                    self.mapdisplay.MapWindow.LoadRaster(item)
                 elif mapLayer.type == 'vector':
-                    id = self.mapdisplay.MapWindow.LoadVector(mapLayer)
-
-                if id > 0:
-                    self.mapdisplay.MapWindow.SetLayerData(item, id)
-                    self.mapdisplay.MapWindow.UpdateLayerProperties(item)
+                    self.mapdisplay.MapWindow.LoadVector(item)
 
             else: # disable
                 data = self.GetPyData(item)[0]['nviz']
-                id = data['object']['id']
+
                 if mapLayer.type == 'raster':
-                    self.mapdisplay.MapWindow.UnloadRaster(id)
+                    self.mapdisplay.MapWindow.UnloadRaster(item)
                 elif mapLayer.type == 'vector':
-                    self.mapdisplay.MapWindow.UnloadVector(id)
+                    self.mapdisplay.MapWindow.UnloadVector(item)
                     
-                    if hasattr(self.parent, "nvizToolWin"):
-                        toolWin = self.parent.nvizToolWin
+                    if hasattr(self.mapdisplay, "nvizToolWin"):
+                        toolWin = self.mapdisplay.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')
+            self.mapdisplay.SetStatusText("", 0)
 
-            busy.Destroy()
-        
         # redraw map if auto-rendering is enabled
         if self.mapdisplay.autoRender.GetValue(): 
             self.mapdisplay.OnRender(None)
@@ -1169,13 +1158,7 @@ class LayerTree(CT.CustomTreeCtrl):
                 id = -1
                 if mapLayer.type == 'raster':
                     if not mapWin.IsLoaded(layer):
-                        id = mapWin.LoadRaster(mapLayer)
-                        if id > 0:
-                            self.mapdisplay.MapWindow.SetLayerData(layer, id)
-                            self.mapdisplay.MapWindow.UpdateLayerProperties(layer)
-
-                        self.mapdisplay.nvizToolWin.UpdatePage('surface')
-                        self.mapdisplay.nvizToolWin.SetPage('surface')
+                        mapWin.LoadRaster(layer)
 
                 elif mapLayer.type == 'vector':
                     if not mapWin.IsLoaded(layer):

+ 5 - 2
gui/wxpython/nviz/nviz.h

@@ -85,8 +85,11 @@ public:
 
     /* vector */
     int SetVectorLineMode(int, const char *, int, int);
-    int SetVectorHeight(int, float);
-    int SetVectorSurface(int, int);
+    int SetVectorLineHeight(int, float);
+    int SetVectorLineSurface(int, int);
+    int SetVectorPointMode(int, const char*, int, float, int);
+    int SetVectorPointHeight(int, float);
+    int SetVectorPointSurface(int, int);
 };
 
 #endif /* WXNVIZ_H */

+ 11 - 1
gui/wxpython/nviz/nviz_types.i

@@ -36,4 +36,14 @@
 #define DM_GRID_WIRE 0x00000400
 #define DM_GRID_SURF 0x00000800
 
-#define WC_COLOR_ATT 0xFF000000
+/* site markers */
+#define ST_X          1
+#define ST_BOX        2
+#define ST_SPHERE     3
+#define ST_CUBE       4
+#define ST_DIAMOND    5
+#define ST_DEC_TREE   6
+#define ST_CON_TREE   7
+#define ST_ASTER      8
+#define ST_GYRO       9
+#define ST_HISTOGRAM  10

+ 103 - 15
gui/wxpython/nviz/vector.cpp

@@ -19,12 +19,16 @@
 #include "nviz.h"
 
 /**
-   \brief Set mode of vector overlay
+   \brief Set mode of vector line overlay
 
    \param id vector id
    \param color_str color string
    \param width line width
-   \param flat
+   \param flat display flat or on surface
+
+   \return -1 vector set not found
+   \return -2 on failure
+   \return 1 on success
 */
 int Nviz::SetVectorLineMode(int id, const char *color_str,
 			    int width, int flat)
@@ -32,7 +36,7 @@ int Nviz::SetVectorLineMode(int id, const char *color_str,
     int color;
 
     if(!GV_vect_exists(id))
-	return 0;
+	return -1;
 
     G_debug(1, "Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
 	    id, color_str, width, flat);
@@ -42,26 +46,26 @@ int Nviz::SetVectorLineMode(int id, const char *color_str,
 
     /* use memory by default */
     if (GV_set_vectmode(id, 1, color, width, flat) < 0)
-	return 0;
+	return -2;
     
     return 1;
 }
 
 /**
-  \brief Set vector height above surface
+  \brief Set vector height above surface (lines)
 
   \param id vector set id
   \param height
 
+  \return -1 vector set not found
   \return 1 on success
-  \return 0 on failure
 */
-int Nviz::SetVectorHeight(int id, float height)
+int Nviz::SetVectorLineHeight(int id, float height)
 {
     if(!GV_vect_exists(id))
-	return 0;
+	return -1;
 
-    G_debug(1, "Nviz::SetVectorHeight(): id=%d, height=%f",
+    G_debug(1, "Nviz::SetVectorLineHeight(): id=%d, height=%f",
 	    id, height);
 
     GV_set_trans(id, 0.0, 0.0, height);
@@ -70,21 +74,105 @@ int Nviz::SetVectorHeight(int id, float height)
 }
 
 /**
-   \brief Set reference surface of vector set
+   \brief Set reference surface of vector set (lines)
 
    \param id vector set id
    \param surf_id surface id
 
    \return 1 on success
-   \return 0 on failure
+   \return -1 vector set not found
+   \return -2 surface not found
+   \return -3 on failure
 */
-int Nviz::SetVectorSurface(int id, int surf_id)
+int Nviz::SetVectorLineSurface(int id, int surf_id)
 {
-    if (!GS_surf_exists(surf_id) || !GV_vect_exists(id))
-	return 0;
+    if (!GV_vect_exists(id))
+	return -1;
+    
+    if (!GS_surf_exists(surf_id))
+	return -2;
 
     if (GV_select_surf(id, surf_id) < 0)
-	return 0;
+	return -3;
+
+    return 1;
+}
+
+/**
+   \brief Set mode of vector point overlay
+
+   \param id vector id
+   \param color_str color string
+   \param width line width
+   \param flat
+
+   \return -1 vector set not found
+*/
+int Nviz::SetVectorPointMode(int id, const char *color_str,
+			     int width, float size, int marker)
+{
+    int color;
+
+    if(!GP_site_exists(id))
+	return -1;
+
+    G_debug(1, "Nviz::SetVectorPointMode(): id=%d, color=%s, "
+	    "width=%d, size=%f, marker=%d",
+	    id, color_str, width, size, marker);
+
+
+    color = Nviz_color_from_str(color_str);
+
+    if (GP_set_sitemode(id, ST_ATT_NONE,
+			color, width, size, marker) < 0)
+	return -2;
+    
+    return 1;
+}
+
+/**
+  \brief Set vector height above surface (points)
+
+  \param id vector set id
+  \param height
+
+  \return -1 vector set not found
+  \return 1 on success
+*/
+int Nviz::SetVectorPointHeight(int id, float height)
+{
+    if(!GP_site_exists(id))
+	return -1;
+
+    G_debug(1, "Nviz::SetVectorPointHeight(): id=%d, height=%f",
+	    id, height);
+
+    GP_set_trans(id, 0.0, 0.0, height);
+
+    return 1;
+}
+
+/**
+   \brief Set reference surface of vector set (points)
+
+   \param id vector set id
+   \param surf_id surface id
+
+   \return 1 on success
+   \return -1 vector set not found
+   \return -2 surface not found
+   \return -3 on failure
+*/
+int Nviz::SetVectorPointSurface(int id, int surf_id)
+{
+    if (!GP_site_exists(id))
+	return -1;
+    
+    if (!GS_surf_exists(surf_id))
+	return -2;
+
+    if (GP_select_surf(id, surf_id) < 0)
+	return -3;
 
     return 1;
 }