commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8242 - in grc/branches/grc_reloaded/src/grc: elements


From: jblum
Subject: [Commit-gnuradio] r8242 - in grc/branches/grc_reloaded/src/grc: elements gui/elements
Date: Tue, 22 Apr 2008 00:17:58 -0600 (MDT)

Author: jblum
Date: 2008-04-22 00:17:57 -0600 (Tue, 22 Apr 2008)
New Revision: 8242

Modified:
   grc/branches/grc_reloaded/src/grc/elements/Block.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
Log:
caching for connection calculations

Modified: grc/branches/grc_reloaded/src/grc/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-04-22 04:08:52 UTC 
(rev 8241)
+++ grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-04-22 06:17:57 UTC 
(rev 8242)
@@ -173,6 +173,11 @@
        def get_source(self, key): return self._sources[key]
        def get_sources(self): return self._sources.values()
        
+       def get_connections(self):
+               connections = list()
+               for port in self.get_sources() + self.get_sinks(): 
connections.extend(port.get_connections())
+               return connections
+       
        def resolve_dependencies(self, tmpl):
                """
                Resolve a paramater dependency with cheetah templates.

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-04-22 
04:08:52 UTC (rev 8241)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-04-22 
06:17:57 UTC (rev 8242)
@@ -103,9 +103,6 @@
                @param rot the rotation in degrees
                """
                self.get_param('gui_rotation').set_value(str(rot))
-               #update connections for this block
-               for port in self.get_sources() + self.get_sinks():
-                       for connection in port.get_connections(): 
connection.update()
        
        def update(self):
                """Update the block, parameters, and ports when a change 
occurs."""

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-04-22 04:08:52 UTC (rev 8241)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-04-22 06:17:57 UTC (rev 8242)
@@ -43,9 +43,14 @@
                @return 0
                """
                return 0        
-               
+                               
        def update(self):
                """Precalculate relative coordinates."""        
+               self._sink_rot = None
+               self._source_rot = None
+               self._sink_coor = None
+               self._source_coor = None
+               
                sink = self.get_sink()
                source = self.get_source()
                
@@ -83,10 +88,13 @@
                elif sink.get_rotation() == 180:
                        self.arrow = [(0, 0), (0+CONNECTOR_ARROW_HEIGHT, 
0-CONNECTOR_ARROW_BASE/2), (0+CONNECTOR_ARROW_HEIGHT, 0+CONNECTOR_ARROW_BASE/2)]
                elif sink.get_rotation() == 270:
-                       self.arrow = [(0, 0), (0-CONNECTOR_ARROW_BASE/2, 
0-CONNECTOR_ARROW_HEIGHT), (0+CONNECTOR_ARROW_BASE/2, 
0-CONNECTOR_ARROW_HEIGHT)]                                       
-       
-       def _draw(self):
-               """Add the horizontal and vertical lines that will connect the 
two parameters."""
+                       self.arrow = [(0, 0), (0-CONNECTOR_ARROW_BASE/2, 
0-CONNECTOR_ARROW_HEIGHT), (0+CONNECTOR_ARROW_BASE/2, 0-CONNECTOR_ARROW_HEIGHT)]
+                       
+               self._update_after_move()                                       
+
+       def _update_after_move(self):
+               """Calculate coordinates."""    
+
                self.clear()            
                
                #source connector
@@ -131,14 +139,24 @@
                                Utils.get_angle_from_coordinates((x2,y2),p1) == 
(sink.get_connector_direction()+180)%360: p = p2
                        else: p = p1
                        self.add_line((x1,y1),p)
-                       self.add_line((x2,y2),p)        
+                       self.add_line((x2,y2),p)
                
        def draw(self, window):
                """!
                Draw the connection.
                @param window the gtk window to draw on
-               """
-               self._draw()    
+               """     
+               sink = self.get_sink()
+               source = self.get_source()
+               #check for changes
+               if self._sink_rot != sink.get_rotation() or self._source_rot != 
source.get_rotation(): self.update()
+               elif self._sink_coor != sink.get_coordinate() or 
self._source_coor != source.get_coordinate(): self._update_after_move()
+               #cache values
+               self._sink_rot = sink.get_rotation()
+               self._source_rot = source.get_rotation()
+               self._sink_coor = sink.get_coordinate()
+               self._source_coor = source.get_coordinate()
+               #draw
                Element.draw(self, window)      
                gc = self.get_gc()
                if not self.is_valid(): gc.foreground = Colors.ERROR_COLOR      
                        





reply via email to

[Prev in Thread] Current Thread [Next in Thread]