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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 10 06:49:50 EDT 2011


Author: annakrat
Date: 2011-06-10 03:49:50 -0700 (Fri, 10 Jun 2011)
New Revision: 46654

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/wxnviz.py
   grass/trunk/include/nviz.h
   grass/trunk/lib/nviz/cplanes_obj.c
   grass/trunk/lib/nviz/position.c
Log:
wxNviz: cutting planes

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-06-10 10:49:50 UTC (rev 46654)
@@ -403,7 +403,7 @@
             self.MapWindow = self.MapWindow3D
             # add Nviz notebookpage
             self._layerManager.AddNviz()
-            for page in ('view', 'light', 'fringe', 'constant'):
+            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-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-06-10 10:49:50 UTC (rev 46654)
@@ -45,6 +45,7 @@
 wxUpdateProperties, EVT_UPDATE_PROP  = NewEvent()
 wxUpdateView,       EVT_UPDATE_VIEW  = NewEvent()
 wxUpdateLight,      EVT_UPDATE_LIGHT = NewEvent()
+wxUpdateCPlane,     EVT_UPDATE_CPLANE = NewEvent()
 
 class NvizThread(Thread):
     def __init__(self, log, progressbar, window):
@@ -95,6 +96,8 @@
         self.layers  = list()
         # list of constant surfaces
         self.constants = list()
+        # list of cutting planes
+        self.cplanes = list()
         # list of query points
         self.qpoints = list()
         
@@ -148,9 +151,19 @@
         self.Bind(EVT_UPDATE_PROP,  self.UpdateMapObjProperties)
         self.Bind(EVT_UPDATE_VIEW,  self.UpdateView)
         self.Bind(EVT_UPDATE_LIGHT, self.UpdateLight)
+        self.Bind(EVT_UPDATE_CPLANE, self.UpdateCPlane)
         
         self.Bind(wx.EVT_CLOSE, self.OnClose)
         
+        #cplanes cannot be initialized now
+        wx.CallAfter(self.InitCPlanes)
+        
+    def InitCPlanes(self):
+        """!Initialize cutting planes list"""
+        for i in range(self._display.GetCPlanesCount()):
+            cplane = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'cplane'))
+            self.cplanes.append(cplane)
+            
     def OnClose(self, event):
         # cleanup when window actually closes (on quit) and not just is hidden
         self.Reset()
@@ -192,6 +205,7 @@
             if hasattr(self.lmgr, "nviz"):
                 self.lmgr.nviz.UpdatePage('view')
                 self.lmgr.nviz.UpdatePage('light')
+                self.lmgr.nviz.UpdatePage('cplane')
                 layer = self.GetSelectedLayer()
                 if layer:
                     if layer.type ==  'raster':
@@ -696,7 +710,29 @@
         id = self.constants[index]['constant']['object']['id']
         self._display.UnloadSurface(id)
         del self.constants[index]
-        
+    
+    def SelectCPlane(self, index):
+        """!Select cutting plane"""
+        for plane in range (self._display.GetCPlanesCount()):
+            if plane == index:
+                self._display.SelectCPlane(plane)
+            else:
+                self._display.UnselectCPlane(plane)
+    
+    def UpdateCPlane(self, event):
+        """!Change cutting plane settings"""
+        current = event.current
+        for each in event.update:
+            if each == 'rotation':
+                self._display.SetCPlaneRotation(0, self.cplanes[current]['rotation']['tilt'],
+                                                   self.cplanes[current]['rotation']['rot'])
+            if each == 'position':
+                self._display.SetCPlaneTranslation(self.cplanes[current]['position']['x'],
+                                                   self.cplanes[current]['position']['y'],
+                                                   self.cplanes[current]['position']['z'])
+            if each == 'shading':
+                self._display.SetFenceColor(self.cplanes[current]['shading'])
+            
     def UnloadRaster(self, item):
         """!Unload 2d raster map
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2011-06-10 10:49:50 UTC (rev 46654)
@@ -48,7 +48,8 @@
 import gcmd
 from preferences import globalSettings as UserSettings
 try:
-    from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
+    from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties,\
+                            wxUpdateCPlane
     import wxnviz
 except ImportError:
     pass
@@ -142,6 +143,10 @@
         # appearance page
         self.AddPage(page = self._createAppearancePage(),
                      text = " %s " % _("Appearance"))
+                    
+        # analysis page
+        self.AddPage(page = self._createAnalysisPage(),
+                     text = " %s " % _("Analysis"))
         
         self.UpdateSettings()
         self.pageChanging = False
@@ -157,7 +162,8 @@
         
         self.Update()
         wx.CallAfter(self.SetPage, 'view')
-        wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear))       
+        wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
+                                            self.foldpanelAnalysis))       
         wx.CallAfter(self.SetInitialMaps)
         
     def SetInitialMaps(self):
@@ -187,7 +193,8 @@
     def OnSize(self, event):
         """!After window is resized, update scrolling"""
         # workaround to resize captionbars of foldpanelbar
-        wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear)) 
+        wx.CallAfter(self.UpdateScrolling, (self.foldpanelData, self.foldpanelAppear,
+                                            self.foldpanelAnalysis)) 
         event.Skip()
            
     def OnPressCaption(self, event):
@@ -451,6 +458,25 @@
         self.mainPanelAppear.Fit()
         return self.mainPanelAppear
     
+    def _createAnalysisPage(self):
+        """!Create data analysis (cutting planes, ...) page"""
+        self.mainPanelAnalysis = ScrolledPanel(parent = self)
+        self.mainPanelAnalysis.SetupScrolling(scroll_x = False)
+        self.foldpanelAnalysis = fpb.FoldPanelBar(parent = self.mainPanelAnalysis, id = wx.ID_ANY,
+                                style = fpb.FPB_DEFAULT_STYLE, extraStyle = fpb.FPB_SINGLE_FOLD)
+        self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
+        # cutting planes page
+        cplanePanel = self.foldpanelAnalysis.AddFoldPanel(_("Cutting planes"), collapsed = False)
+        self.foldpanelAnalysis.AddFoldPanelWindow(cplanePanel, 
+            window = self._createCPlanePage(parent = cplanePanel), flags = fpb.FPB_ALIGN_WIDTH)
+        
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        sizer.Add(self.foldpanelAnalysis, proportion = 1, flag = wx.EXPAND)
+        self.mainPanelAnalysis.SetSizer(sizer)
+        self.mainPanelAnalysis.Layout()
+        self.mainPanelAnalysis.Fit()
+        return self.mainPanelAnalysis
+        
     def _createSurfacePage(self, parent):
         """!Create view settings page"""
         panel = wx.Panel(parent = parent, id = wx.ID_ANY)
@@ -743,7 +769,138 @@
         panel.Fit()
         
         return panel
-    
+    def _createCPlanePage(self, parent):
+        """!Create cutting planes page"""  
+        panel = wx.Panel(parent = parent, id = wx.ID_ANY)
+        self.page['cplane'] = { 'id' : 4, 
+                                'notebook' : self.foldpanelData.GetId() }
+        self.win['cplane'] = {}
+        
+        pageSizer = wx.BoxSizer(wx.VERTICAL)
+        box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
+                            label = " %s " % (_("Cutting planes")))
+        boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+        horSizer = wx.BoxSizer(wx.HORIZONTAL)
+        
+        # planes
+        horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Active cutting plane:")),
+                     flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
+        choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = [])
+        self.win['cplane']['planes'] = choice.GetId()
+        choice.Bind(wx.EVT_CHOICE, self.OnCPlaneSelection)
+        horSizer.Add(item = choice, flag = wx.ALL, border = 5)
+        
+        # shading
+        horSizer.Add(item = wx.Size(-1, -1), proportion = 1)
+        horSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Shading:")),
+                     flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
+        choices = [_("clear"),
+                   _("top color"),
+                   _("bottom color"),
+                   _("blend"),
+                   _("shaded")]
+        choice = wx.Choice(parent = panel, id = wx.ID_ANY, choices = choices)
+        self.win['cplane']['shading'] = choice.GetId()
+        choice.Bind(wx.EVT_CHOICE, self.OnCPlaneShading)
+        horSizer.Add(item = choice, flag = wx.ALL, border = 5)
+        boxSizer.Add(item = horSizer, flag = wx.EXPAND)
+        
+        gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
+        # XYZ position
+        self.win['cplane']['position'] = {}
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("X:")),
+                      pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Y:")),
+                      pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Height:")),
+                      pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
+        self._createControl(panel, data = self.win['cplane']['position'], name = 'x', size = 250,
+                            range = (-1000, 1000), sliderHor = True,
+                            bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
+        self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetValue(0)
+        self.FindWindowById(self.win['cplane']['position']['x']['text']).SetValue(0)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['slider']),
+                      pos = (0, 1),  flag = wx.EXPAND|wx.ALIGN_RIGHT)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['x']['text']),
+                      pos = (0, 2),
+                      flag = wx.ALIGN_CENTER)
+                    
+        self._createControl(panel, data = self.win['cplane']['position'], name = 'y', size = 250,
+                            range = (-1000, 1000), sliderHor = True,
+                            bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
+        self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetValue(0)
+        self.FindWindowById(self.win['cplane']['position']['y']['text']).SetValue(0)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['slider']),
+                      pos = (1, 1),  flag = wx.EXPAND|wx.ALIGN_RIGHT)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['y']['text']),
+                      pos = (1, 2),
+                      flag = wx.ALIGN_CENTER)
+                    
+        self._createControl(panel, data = self.win['cplane']['position'], name = 'z', size = 250,
+                            range = (-1000, 1000), sliderHor = True,
+                            bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
+        self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(0)
+        self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(0)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['slider']),
+                      pos = (2, 1),  flag = wx.EXPAND|wx.ALIGN_RIGHT)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['position']['z']['text']),
+                      pos = (2, 2),
+                      flag = wx.ALIGN_CENTER)
+        
+        # rotation
+        self.win['cplane']['rotation'] = {}
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Rotation:")),
+                      pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Tilt:")),
+                      pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
+        self._createControl(panel, data = self.win['cplane']['rotation'], name = 'rot', size = 250,
+                            range = (0, 360), sliderHor = True,
+                            bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
+        self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']).SetValue(0)
+        self.FindWindowById(self.win['cplane']['rotation']['rot']['text']).SetValue(0)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['slider']),
+                      pos = (3, 1),  flag = wx.EXPAND|wx.ALIGN_RIGHT)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['rot']['text']),
+                      pos = (3, 2),
+                      flag = wx.ALIGN_CENTER)
+                    
+        self._createControl(panel, data = self.win['cplane']['rotation'], name = 'tilt', size = 250,
+                            range = (0, 360), sliderHor = True,
+                            bind = (self.OnCPlaneChanging, self.OnCPlaneChangeDone, self.OnCPlaneChangeText))
+        self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']).SetValue(0)
+        self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']).SetValue(0)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['slider']),
+                      pos = (4, 1),  flag = wx.EXPAND|wx.ALIGN_RIGHT)
+        gridSizer.Add(item = self.FindWindowById(self.win['cplane']['rotation']['tilt']['text']),
+                      pos = (4, 2),
+                      flag = wx.ALIGN_CENTER)
+        boxSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND|wx.ALL, border = 5)
+                    
+        horSizer = wx.BoxSizer(wx.HORIZONTAL)
+        horSizer.Add(item = wx.Size(-1, -1), proportion = 1, flag = wx.ALL, border = 5)            
+
+        # reset
+        reset = wx.Button(parent = panel, id = wx.ID_ANY, label = _("Reset"))
+        self.win['cplane']['reset'] = reset.GetId()
+        reset.Bind(wx.EVT_BUTTON, self.OnCPlaneReset)
+        horSizer.Add(item = reset, flag = wx.ALL, border = 5)
+        boxSizer.Add(horSizer, proportion = 0, flag = wx.EXPAND)            
+        
+        
+        pageSizer.Add(boxSizer, proportion = 0, flag = wx.EXPAND)
+        
+        panel.SetSizer(pageSizer)
+        panel.Fit()    
+        
+        return panel
+        
     def _createConstantPage(self, parent):
         """!Create constant page"""
         panel = wx.Panel(parent = parent, id = wx.ID_ANY)
@@ -2039,12 +2196,17 @@
     def EnablePage(self, name, enabled = True):
         """!Enable/disable all widgets on page"""
         for key, item in self.win[name].iteritems():
-            if key in ('map', 'surface', 'new'):
+            if key in ('map', 'surface', 'new','planes'):
                 continue
             if type(item) == types.DictType:
-                for sitem in self.win[name][key].itervalues():
-                    if type(sitem) == types.IntType:
-                        self.FindWindowById(sitem).Enable(enabled)
+                for skey, sitem in self.win[name][key].iteritems():
+                    if type(sitem) == types.DictType:
+                        for ssitem in self.win[name][key][skey].itervalues():
+                            if type(ssitem) == types.IntType:
+                                self.FindWindowById(ssitem).Enable(enabled)
+                    else:
+                        if type(sitem) == types.IntType:
+                            self.FindWindowById(sitem).Enable(enabled)
             else:
                 if type(item) == types.IntType:
                     self.FindWindowById(item).Enable(enabled)
@@ -2816,7 +2978,85 @@
             self.mapWindow.Refresh(False)
         
         event.Skip()
+    
+    def OnCPlaneSelection(self, event):
+        """!Cutting plane selected"""
+        plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
+        try:
+            planeIndex = int(plane.split()[1])
+            self.EnablePage("cplane", enabled = True)
+        except:
+            planeIndex = -1
+            self.EnablePage("cplane", enabled = False)
+        self.mapWindow.SelectCPlane(planeIndex)
+        if self.mapDisplay.statusbarWin['render'].IsChecked():
+            self.mapWindow.Refresh(False)
+        self.UpdateCPlanePage(planeIndex)
         
+    def OnCPlaneChanging(self, event):
+        """!Cutting plane is changing"""
+        plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
+        try:
+            planeIndex = int(plane.split()[1])
+        except:#TODO disabled page
+            planeIndex = -1
+    
+        if event.GetId() in (self.win['cplane']['rotation']['rot'].values() +
+                            self.win['cplane']['rotation']['tilt'].values()):
+            action = 'rotation'
+        else:
+            action = 'position'
+        data = self.mapWindow.cplanes[planeIndex][action]
+        self.OnScroll(event, self.win['cplane'][action], data)
+        
+        event = wxUpdateCPlane(update = (action,), current = planeIndex)
+        wx.PostEvent(self.mapWindow, event)
+
+    def OnCPlaneChangeDone(self, event):
+        """!Cutting plane change done"""
+        if self.mapDisplay.statusbarWin['render'].IsChecked():
+            self.mapWindow.Refresh(False)
+            
+    def OnCPlaneChangeText(self, event):
+        """!Cutting plane changed by textctrl"""
+        for axis in ('x', 'y', 'z'):
+            if event.GetId() == self.win['cplane']['position'][axis]['text']:
+                value = self.FindWindowById(event.GetId()).GetValue()
+                slider = self.FindWindowById(self.win['cplane']['position'][axis]['slider'])
+                self.AdjustSliderRange(slider = slider, value = value)
+        self.OnCPlaneChanging(event = event)
+        self.OnCPlaneChangeDone(None)   
+        
+    def OnCPlaneShading(self, event):
+        """!Cutting plane shading changed"""
+        shading = self.FindWindowById(self.win['cplane']['shading']).GetSelection()
+        plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
+        try:
+            planeIndex = int(plane.split()[1])
+        except:#TODO disabled page
+            planeIndex = -1
+            
+        self.mapWindow.cplanes[planeIndex]['shading'] = shading
+        
+        event = wxUpdateCPlane(update = ('shading',), current = planeIndex)
+        wx.PostEvent(self.mapWindow, event)
+        
+        self.OnCPlaneChangeDone(None)
+        
+    def OnCPlaneReset(self, event):
+        """!Reset current cutting plane"""
+        plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
+        try:
+            planeIndex = int(plane.split()[1])
+        except:#TODO disabled page
+            planeIndex = -1
+        self.mapWindow.cplanes[planeIndex] = copy.deepcopy(UserSettings.Get(group = 'nviz',
+                                                                            key = 'cplane'))
+        event = wxUpdateCPlane(update = ('position','rotation','shading'), current = planeIndex)
+        wx.PostEvent(self.mapWindow, event)
+        self.OnCPlaneChangeDone(None)
+        self.UpdateCPlanePage(planeIndex)
+        
     def UpdatePage(self, pageId):
         """!Update dialog (selected page)"""
         self.pageChanging = True
@@ -2872,16 +3112,44 @@
             if self.mapWindow.constants:
                 surface = self.FindWindowById(self.win['constant']['surface'])
                 for item in self.mapWindow.constants:
-                    surface.Append(item['name'])
+                    surface.Append(_("constant") + str(item['constant']['object']['name']))
                 surface.SetSelection(0)
                 self.OnConstantSelection(None)
                 self.EnablePage('constant', True)
-                
-                
+        elif pageId == 'cplane':
+            count = self._display.GetCPlanesCount()
+            choices = [_("None"),]
+            for plane in range(count):
+                choices.append("%s %i" % (_("Plane"), plane))
+            self.FindWindowById(self.win['cplane']['planes']).SetItems(choices)
+            self.FindWindowById(self.win['cplane']['planes']).SetSelection(0)
             
+            xyRange, zRange = self._display.GetXYRange(), self._display.GetZRange()
+            if xyRange > 0: # GTK warning
+                self.FindWindowById(self.win['cplane']['position']['x']['slider']).SetRange(-xyRange/2., xyRange/2.)
+                self.FindWindowById(self.win['cplane']['position']['y']['slider']).SetRange(-xyRange/2., xyRange/2.)
+            if zRange[0] - zRange[1] > 0:
+                self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetRange(zRange[0], zRange[1])
+            self.FindWindowById(self.win['cplane']['position']['z']['slider']).SetValue(zRange[0])
+            self.FindWindowById(self.win['cplane']['position']['z']['text']).SetValue(zRange[0])
+            self.OnCPlaneSelection(None)
+            
+            
         self.Update()
         self.pageChanging = False
-        
+    
+    def UpdateCPlanePage(self, index):
+        """!Update widgets according to selected clip plane"""
+        if index == -1:   
+            return
+        data = self.mapWindow.cplanes[index]
+        for widget in ('text', 'slider'):
+            for axes in ('x', 'y', 'z'):
+                self.FindWindowById(self.win['cplane']['position'][axes][widget]).SetValue(data['position'][axes])
+            for each in ('tilt', 'rot'):
+                self.FindWindowById(self.win['cplane']['rotation'][each][widget]).SetValue(data['rotation'][each])
+        self.FindWindowById(self.win['cplane']['shading']).SetSelection(data['shading'])
+                
     def UpdateSurfacePage(self, layer, data, updateName = True):
         """!Update surface page"""
         ret = gcmd.RunCommand('r.info',

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-06-10 10:49:50 UTC (rev 46654)
@@ -551,6 +551,18 @@
                         'value' : 60,
                         },
                     },
+                'cplane' : {
+                    'shading': 0,
+                    'rotation':{
+                        'rot': 0, 
+                        'tilt': 0
+                        }, 
+                    'position':{
+                        'x' : 0,
+                        'y' : 0,
+                        'z' : 0
+                    }   
+                },
                 'light' : {
                     'position' : {
                         'x' : 0.68,

Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-06-10 10:49:50 UTC (rev 46654)
@@ -1221,6 +1221,80 @@
         
         return 1
 
+    def GetCPlanesCount(self):
+        """!Returns number of cutting planes"""
+        return Nviz_num_cplanes(self.data) 
+    
+    def GetCPlaneRotation(self):
+        """!Returns rotation parameters of current cutting plane"""
+        x, y, z = c_float(), c_float(), c_float()
+        
+        current = Nviz_get_current_cplane(self.data)
+        Nviz_get_cplane_rotation(self.data, current, byref(x), byref(y), byref(z))
+        
+        return x.value, y.value, z.value
+    
+    def GetCPlaneTranslation(self):
+        """!Returns translation parameters of current cutting plane"""
+        x, y, z = c_float(), c_float(), c_float()
+        
+        current = Nviz_get_current_cplane(self.data)
+        Nviz_get_cplane_translation(self.data, current, byref(x), byref(y), byref(z))
+        
+        return x.value, y.value, z.value
+    
+    def SetCPlaneRotation(self, x, y, z):
+        """!Set current clip plane rotation
+        
+        @param x,y,z rotation parameters
+        """
+        current = Nviz_get_current_cplane(self.data)
+        Nviz_set_cplane_rotation(self.data, current, x, y, z)
+        Nviz_draw_cplane(self.data, -1, -1)
+    
+    def SetCPlaneTranslation(self, x, y, z):
+        """!Set current clip plane translation
+        
+        @param x,y,z translation parameters
+        """
+        current = Nviz_get_current_cplane(self.data)
+        Nviz_set_cplane_translation(self.data, current, x, y, z)
+        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 SelectCPlane(self, index):
+        """!Select cutting plane
+        
+        @param index index of cutting plane
+        """
+        Nviz_on_cplane(self.data, index)
+    
+    def UnselectCPlane(self, index):
+        """!Unselect cutting plane
+        
+        @param index index of cutting plane
+        """
+        Nviz_off_cplane(self.data, index)
+        
+    def SetFenceColor(self, index):
+        """!Select current cutting plane
+        
+        @param index type of fence - from 0 (off) to 4
+        """    
+        
+        Nviz_set_fence_color(self.data, index)
+            
+    def GetXYRange(self):
+        """!Get xy range"""
+        return Nviz_get_xyrange(self.data)
+    
+    def GetZRange(self):
+        """!Get z range"""
+        min, max = c_float(), c_float()
+        Nviz_get_zrange(self.data, byref(min), byref(max))
+        return min.value, max.value
+    
     def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
         """!Save current GL screen to ppm/tif file
 
@@ -1269,7 +1343,7 @@
         x   = c_float()
         y   = c_float()
         z   = c_float()
-        Debug.msg(5, "GLWindow.GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
+        Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
         num = GS_get_selected_point_on_surface(sx, sy, byref(sid), byref(x), byref(y), byref(z))
         if num == 0:
             return (None, None, None, None)

Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/include/nviz.h	2011-06-10 10:49:50 UTC (rev 46654)
@@ -137,9 +137,18 @@
 
 /* cplanes_obj.c */
 int Nviz_new_cplane(nv_data *, int);
+int Nviz_on_cplane(nv_data *, int);
 int Nviz_off_cplane(nv_data *, int);
 int Nviz_draw_cplane(nv_data *, int, int);
+int Nviz_num_cplanes(nv_data *);
+int Nviz_get_current_cplane(nv_data *);
+int Nviz_set_cplane_rotation(nv_data *, int, float, float, float);
+int Nviz_get_cplane_rotation(nv_data *, int, float *, float *, float *);
+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);
 
+
 /* draw.c */
 int Nviz_draw_all_surf(nv_data *);
 int Nviz_draw_all_vect();
@@ -183,6 +192,8 @@
 void Nviz_init_view(nv_data *);
 int Nviz_set_focus_state(int);
 int Nviz_set_focus_map(int, int);
+float Nviz_get_xyrange(nv_data *);
+int Nviz_get_zrange(nv_data *, float *, float *);
 
 /* render.c */
 struct render_window *Nviz_new_render_window();

Modified: grass/trunk/lib/nviz/cplanes_obj.c
===================================================================
--- grass/trunk/lib/nviz/cplanes_obj.c	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/lib/nviz/cplanes_obj.c	2011-06-10 10:49:50 UTC (rev 46654)
@@ -36,6 +36,21 @@
 }
 
 /*!
+   \brief Turn on (make current) the given clip plane.
+
+   \param data nviz data
+   \param cplane id
+ */
+int Nviz_on_cplane(nv_data * data, int id)
+{
+    data->cur_cplane = id;
+    data->cp_on[id] = 1;
+    GS_set_cplane(id);
+
+    return 1;
+}
+
+/*!
    \brief Turn off (make inactive) the given clip plane
 
    \param data nviz data
@@ -118,3 +133,112 @@
 
     return;
 }
+/*!
+   \brief Return the number of clip planes objects currently allocated.
+   
+   \param data nviz data
+ */
+int Nviz_num_cplanes(nv_data * data)
+{
+	return data->num_cplanes;
+}
+
+/*!
+   \brief Get the current active cutplane.
+   
+   \param data nviz data
+ */
+int Nviz_get_current_cplane(nv_data * data)
+{
+	return data->cur_cplane;
+}
+
+/*!
+   \brief Set the rotation for the current clip plane.
+   
+   \param data nviz data
+   \param id id of current clip plane
+   \param dx,dy,dz rotation parameters
+   
+   \return 1 
+
+ */
+int Nviz_set_cplane_rotation(nv_data * data, int id, float dx, float dy, float dz)
+{
+    data->cp_rot[id][X] = dx;
+    data->cp_rot[id][Y] = dy;
+    data->cp_rot[id][Z] = dz;
+    GS_set_cplane_rot(id, data->cp_rot[id][X], data->cp_rot[id][Y],
+		      data->cp_rot[id][Z]);
+
+    cp_draw(data, data->cur_cplane, -1, -1);
+    
+    return 1;
+}
+/*!
+   \brief Get the rotation values for the current clip plane.
+   
+   \param data nviz data
+   \param id id of current clip plane
+   \param dx,dy,dz rotation parameters
+   
+   \return 1
+   
+ */
+int Nviz_get_cplane_rotation(nv_data * data, int id, float *dx, float *dy, float *dz)
+{
+    *dx = data->cp_rot[id][X];
+    *dy = data->cp_rot[id][Y];
+    *dz = data->cp_rot[id][Z];
+
+    return 1;
+}
+
+/*!
+   \brief Set the translation for the current clip plane.
+
+   \param data nviz data
+   \param id id of current clip plane
+   \param dx,dy,dz values for setting translation
+   
+   \return 1
+ */
+int Nviz_set_cplane_translation(nv_data * data, int id, float dx, float dy, float dz)
+{
+    data->cp_trans[id][X] = dx;
+    data->cp_trans[id][Y] = dy;
+    data->cp_trans[id][Z] = dz;
+    GS_set_cplane_trans(id, data->cp_trans[id][X], data->cp_trans[id][Y],
+			data->cp_trans[id][Z]);
+
+    cp_draw(data, data->cur_cplane, -1, -1);
+    
+    return 1;
+}
+/*!
+   \brief Get the translation values for the current clip plane.
+   
+   \param data nviz data
+   \param id id of current clip plane
+   \param dx,dy,dz translation parameters
+ */
+int Nviz_get_cplane_translation(nv_data * data, int id, float *dx, float *dy, float *dz)
+{
+    *dx = data->cp_trans[id][X];
+    *dy = data->cp_trans[id][Y];
+    *dz = data->cp_trans[id][Z];
+
+    return 1;
+}
+/*!
+   \brief Set appropriate fence color
+   
+   \param type type of fence (FC_ABOVE, FC_BELOW, FC_BLEND, FC_GREY, FC_OFF)
+ */
+int Nviz_set_fence_color(nv_data * data, int type)
+{
+	GS_set_fencecolor(type);
+
+    return 1;
+
+}

Modified: grass/trunk/lib/nviz/position.c
===================================================================
--- grass/trunk/lib/nviz/position.c	2011-06-10 09:49:06 UTC (rev 46653)
+++ grass/trunk/lib/nviz/position.c	2011-06-10 10:49:50 UTC (rev 46654)
@@ -109,3 +109,23 @@
 
     return id;
 }
+/*!
+   \brief Get xy range
+
+   \param data nviz data
+ */
+float Nviz_get_xyrange(nv_data * data)
+{
+   return data->xyrange;
+}
+/*!
+   \brief Get z range
+
+   \param data nviz data
+   \param min,max z range
+ */
+int Nviz_get_zrange(nv_data * data, float *min, float *max)
+{
+	GS_get_zrange_nz(min, max);
+	return 1;
+}



More information about the grass-commit mailing list