[GRASS-SVN] r48797 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 14 11:57:45 EDT 2011


Author: annakrat
Date: 2011-10-14 08:57:45 -0700 (Fri, 14 Oct 2011)
New Revision: 48797

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/wxnviz.py
Log:
wxNviz: synchronize overlays in 2d and 3d (legend, text labels)

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-10-14 15:22:54 UTC (rev 48796)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2011-10-14 15:57:45 UTC (rev 48797)
@@ -656,6 +656,12 @@
             self.MapWindow3D.ResetViewHistory()
             for page in ('view', 'light', 'fringe', 'constant', 'cplane'):
                 self._layerManager.nviz.UpdatePage(page)
+                
+        self.MapWindow3D.overlays = self.MapWindow2D.overlays
+        self.MapWindow3D.textdict = self.MapWindow2D.textdict
+        # update overlays needs to be called after because getClientSize
+        # is called during update and it must give reasonable values
+        wx.CallAfter(self.MapWindow3D.UpdateOverlays)
         
         self.SetStatusText("", 0)
         self._mgr.Update()
@@ -680,6 +686,8 @@
         # remove nviz notebook page
         self._layerManager.RemoveNvizTools()
         
+        self.MapWindow2D.overlays = self.MapWindow3D.overlays
+        self.MapWindow2D.textdict = self.MapWindow3D.textdict
         self.MapWindow.UpdateMap()
         self._mgr.Update()
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-10-14 15:22:54 UTC (rev 48796)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-10-14 15:57:45 UTC (rev 48797)
@@ -251,7 +251,8 @@
     def DrawImages(self):
         """!Draw overlay image"""
         for texture in self.imagelist:
-            texture.Draw()
+            if texture.IsActive():
+                texture.Draw()
             
     def GetLegendRect(self):
         """!Estimates legend size for dragging"""
@@ -264,6 +265,8 @@
         if size:
             wSize = self.GetClientSizeTuple()
             x, y = size[2]/100. * wSize[0], wSize[1] - (size[1]/100. * wSize[1])
+            x += self.overlays[1]['coords'][0]
+            y += self.overlays[1]['coords'][1]
             w = (size[3] - size[2])/100. * wSize[0]
             h = (size[1] - size[0])/100. * wSize[1]
             
@@ -307,39 +310,54 @@
         self.Map.RenderOverlays(force = True)
         
         # delete textures
-        overlays = self.Map.GetListOfLayers(l_type = "overlay", l_active = True)
         for texture in self.imagelist:
-            if texture.id not in [o.id for o in overlays] + self.textdict.keys():
-                self.imagelist.remove(texture)
-        # update images (legend)
-        for overlay in overlays:
-            if os.path.isfile(overlay.mapfile) and os.path.getsize(overlay.mapfile):
-                if overlay.id not in [t.id for t in self.imagelist]: # new
-                    self.CreateTexture(overlay)
+            # inactive overlays, remove text labels
+            if texture.GetId() < 100:
+                if not self.overlays[texture.GetId()]['layer'].IsActive():
+                    texture.SetActive(False)
                 else:
-                    for t in self.imagelist: # check if it is the same
-                        if t.id == overlay.id and sorted(t.cmd) != sorted(self.overlays[overlay.id]['cmd']):
+                    texture.SetActive(True)
+            else: # text label
+                if texture.GetId() not in self.textdict:
+                    self.imagelist.remove(texture)
+                    
+        # update images (only legend so far)
+        for oid, overlay in self.overlays.iteritems():
+            layer = overlay['layer']
+            if not layer.IsActive() or oid == 0: # 0 for barscale
+                continue
+            if oid not in [t.GetId() for t in self.imagelist]: # new
+                self.CreateTexture(overlay = layer)
+            else:
+                for t in self.imagelist:
+                    if t.GetId() == oid: # check if it is the same
+                        if not t.Corresponds(layer):
                             self.imagelist.remove(t)
-                            self.CreateTexture(overlay)
+                            t = self.CreateTexture(overlay = layer)
+                        # always set coordinates, needed for synchr. 2D and 3D modes
+                        t.SetCoords(overlay['coords'])
+
+                    
         # update text labels
         for textId in self.textdict.keys():
-            if textId not in [t.id for t in self.imagelist]:# new
+            if textId not in [t.GetId() for t in self.imagelist]:# new
                 self.CreateTexture(textId = textId)
             else:
-                for t in self.imagelist:# check if it is the same
-                    if not t.textDict:
-                        continue
-                    self.textdict[textId]['bbox'] = t.textDict['bbox'] # compare without bbox
-                    if t.id == textId and t.textDict and t.textDict != self.textdict[textId]:
-                        self.imagelist.remove(t)
-                        self.CreateTexture(textId = textId)
+                for t in self.imagelist:
+                    if t.GetId() == textId: # check if it is the same
+                        self.textdict[textId]['bbox'] = t.textDict['bbox']
+                        if not t.Corresponds(self.textdict[textId]):
+                            self.imagelist.remove(t)
+                            t = self.CreateTexture(textId = textId)
+                        # always set coordinates, needed for synchr. 2D and 3D modes
+                        t.SetCoords(self.textdict[textId]['coords'])
             
     def CreateTexture(self, overlay = None, textId = None):
         """!Create texture from overlay image or from textdict"""
         if overlay: # legend  
-            texture = wxnviz.Texture(filepath = overlay.mapfile, overlayId = overlay.id,
-                                     coords = list(self.overlays[overlay.id]['coords']),
-                                     cmd = self.overlays[overlay.id]['cmd'])
+            texture = wxnviz.ImageTexture(filepath = overlay.mapfile, overlayId = overlay.id,
+                                          coords = list(self.overlays[overlay.id]['coords']),
+                                          cmd = overlay.GetCmd())
             if overlay.id == 1: # legend
                 texture.SetBounds(self.GetLegendRect())
         else: # text
@@ -347,8 +365,8 @@
             self.textdict[textId]['coords'] = coords
             self.textdict[textId]['bbox'] = bbox
             file = self.DrawTextImage(self.textdict[textId], relCoords)
-            texture = wxnviz.Texture(filepath = file, overlayId = textId,
-                                     coords = coords, textDict = self.textdict[textId])
+            texture = wxnviz.TextTexture(filepath = file, overlayId = textId,
+                                         coords = coords, textDict = self.textdict[textId])
             bbox.OffsetXY(*relCoords)
             texture.SetBounds(bbox)
             
@@ -356,9 +374,12 @@
             gcmd.GMessage(parent = self, message = 
                           _("Image is too large, your OpenGL implementation "
                             "supports maximum texture size %d px.") % texture.maxSize)
-            return
+            return texture
+            
         self.imagelist.append(texture)
         
+        return texture
+        
     def FindObjects(self, mouseX, mouseY, radius):
         """Find object which was clicked on"""
         for texture in self.imagelist:
@@ -528,7 +549,15 @@
             self.mouse['use'] = 'pointer'
             self.SetCursor(self.cursors['default'])
         elif self.mouse['use'] == 'pointer':
-            if self.dragid > 0:    
+            if self.dragid > 0:
+                dx = self.mouse['end'][0] - self.mouse['begin'][0]
+                dy = self.mouse['end'][1] - self.mouse['begin'][1]
+                if self.dragid < 99:
+                    coords = self.overlays[self.dragid]['coords']
+                    self.overlays[self.dragid]['coords'] = [coords[0] + dx, coords[1] + dy]
+                else: # text
+                    coords = self.textdict[self.dragid]['coords']
+                    self.textdict[self.dragid]['coords'] = [coords[0] + dx, coords[1] + dy]
                 self.dragid = -1
                 self.render['quick'] = False
                 self.Refresh(False)
@@ -642,6 +671,7 @@
             if texture.id == id:
                 texture.MoveTexture(dx, dy)
 
+
         self.render['quick'] = True
         self.Refresh(False)
         

Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-10-14 15:22:54 UTC (rev 48796)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-10-14 15:57:45 UTC (rev 48797)
@@ -1863,14 +1863,12 @@
         
 class Texture(object):
     """!Class representing OpenGL texture"""
-    def __init__(self, filepath, overlayId, coords, cmd = None, textDict = None):
+    def __init__(self, filepath, overlayId, coords):
         """!Load image to texture
 
         @param filepath path to image file
         @param overlayId id of overlay (1 for legend, 101 and more for text)
         @param coords image coordinates
-        @param cmd d.legend command (or None)
-        @param textDict text info (or None)      
         """
         self.path = filepath
         self.image = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
@@ -1879,8 +1877,7 @@
         self.id = overlayId
         self.coords = list(coords)
         self.bounds = wx.Rect()
-        self.cmd = cmd
-        self.textDict = textDict
+        self.active = True
         
         # alpha needs to be initialized
         if not self.image.HasAlpha():
@@ -1965,4 +1962,69 @@
         self.coords[0] += dx
         self.coords[1] += dy
         self.bounds.OffsetXY(dx, dy)
+    
+    def SetCoords(self, coords):
+        """!Set coordinates"""
+        dx = coords[0] - self.coords[0]
+        dy = coords[1] - self.coords[1]
+        self.MoveTexture(dx, dy)
         
+    def GetId(self):
+        """!Returns image id."""
+        return self.id
+    
+    def SetActive(self, active = True):
+        self.active = active
+        
+    def IsActive(self):
+        return self.active
+        
+class ImageTexture(Texture):
+    """!Class representing OpenGL texture as an overlay image"""
+    def __init__(self, filepath, overlayId, coords, cmd):
+        """!Load image to texture
+
+        @param filepath path to image file
+        @param overlayId id of overlay (1 for legend)
+        @param coords image coordinates
+        @param cmd d.legend command      
+        """
+        Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
+        
+        self.cmd = cmd
+        
+    def GetCmd(self):
+        """!Returns overlay command."""
+        return self.cmd
+        
+    def Corresponds(self, item):
+        return sorted(self.GetCmd()) == sorted(item.GetCmd())
+        
+class TextTexture(Texture):
+    """!Class representing OpenGL texture as a text label"""
+    def __init__(self, filepath, overlayId, coords, textDict):
+        """!Load image to texture
+
+        @param filepath path to image file
+        @param overlayId id of overlay (101 and more for text)
+        @param coords text coordinates
+        @param textDict text properties      
+        """
+        Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
+        
+        self.textDict = textDict
+        
+    def GetTextDict(self):
+        """!Returns text properties."""
+        return self.textDict
+        
+        
+    def Corresponds(self, item):
+        t = self.GetTextDict()
+        for prop in t.keys():
+            if prop in ('coords','bbox'): continue
+            if t[prop] != item[prop]:
+                return False
+                
+        return True
+    



More information about the grass-commit mailing list