commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7724 - in grc/branches/grc_reloaded: notes src/grc sr


From: jblum
Subject: [Commit-gnuradio] r7724 - in grc/branches/grc_reloaded: notes src/grc src/grc/elements src/grc/gui/elements
Date: Sun, 17 Feb 2008 18:32:40 -0700 (MST)

Author: jblum
Date: 2008-02-17 18:32:40 -0700 (Sun, 17 Feb 2008)
New Revision: 7724

Modified:
   grc/branches/grc_reloaded/notes/todo.txt
   grc/branches/grc_reloaded/src/grc/Constants.py
   grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Port.py
Log:
auto remove connections, and connection arrow on sinks

Modified: grc/branches/grc_reloaded/notes/todo.txt
===================================================================
--- grc/branches/grc_reloaded/notes/todo.txt    2008-02-17 18:05:42 UTC (rev 
7723)
+++ grc/branches/grc_reloaded/notes/todo.txt    2008-02-18 01:32:40 UTC (rev 
7724)
@@ -1,6 +1,5 @@
 ############ GRC Reloaded: #############
 restore preferences
-fix connections
 reload(usrp) in usrp diagnostics
 generate code
 setup.py for grc
@@ -18,6 +17,7 @@
 -socket controllers should be intelligent on shrinkage
 -usrp transmit dies in lock/unlock
 -audio dies lock/unlock
+-auto scrolling problems
 
 ############   Features to Add:        ####################
 -startup tips
@@ -42,7 +42,6 @@
 -add the concept of a current working directory
 -auto param to usrp diagnose dialog
 -use popen3 once it works in cygwin
--arrow like images for socket, to replace in/out strings
 
 ############   Get GTK Stock IDs:      ####################
 gtk.stock_list_ids()

Modified: grc/branches/grc_reloaded/src/grc/Constants.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/Constants.py      2008-02-17 18:05:42 UTC 
(rev 7723)
+++ grc/branches/grc_reloaded/src/grc/Constants.py      2008-02-18 01:32:40 UTC 
(rev 7724)
@@ -53,6 +53,12 @@
 ##The length that a connection must extend from the initial length times the 
index of the port, after this length, the connection may have a bend.
 CONNECTOR_EXTENSION_LENGTH = 11
 
+##The length of the connector arrow base in pixels
+CONNECTOR_ARROW_BASE = 13
+
+##The length of the connector arrow height in pixels
+CONNECTOR_ARROW_HEIGHT = 17
+
 
######################################################################################################
 ## Signal block rotations
 
######################################################################################################

Modified: grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py     2008-02-17 
18:05:42 UTC (rev 7723)
+++ grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py     2008-02-18 
01:32:40 UTC (rev 7724)
@@ -112,8 +112,8 @@
                        element = element.get_parent()  
                #remove block, remove all involved connections                  
        
                if element.is_block():  
-                       #TODO                   
-                       pass
+                       for port in element.get_sources() + element.get_sinks():
+                               map(lambda c: self.remove_element(c), 
port.get_connections())
                #remove a connection
                elif element.is_connection(): pass
                self.get_elements().remove(element)

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-02-17 18:05:42 UTC (rev 7723)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-02-18 01:32:40 UTC (rev 7724)
@@ -23,6 +23,7 @@
 import Utils
 from Element import Element
 import Colors
+from grc.Constants import CONNECTOR_ARROW_BASE,CONNECTOR_ARROW_HEIGHT
 
 class Connection(Element):
        """A graphical connection for ports."""         
@@ -49,10 +50,47 @@
                sink = self.get_sink()
                source = self.get_source()
                deltaAngle = abs(source.get_connector_direction() - 
sink.get_connector_direction())
-               (x1, y1) = source.get_connector_coordinates()[1]
-               self.add_line(*source.get_connector_coordinates())
-               (x2, y2) = sink.get_connector_coordinates()[1]
-               self.add_line(*sink.get_connector_coordinates())
+               
+               #get the source coordinate
+               x, y = source.get_connector_coordinate()
+               connector_length = source.get_connector_length()
+               if source.get_rotation() == 0:
+                       x = x + connector_length
+               elif source.get_rotation() == 90:
+                       y = y - connector_length
+               elif source.get_rotation() == 180:
+                       x = x - connector_length
+               elif source.get_rotation() == 270:
+                       y = y + connector_length                
+               self.add_line((x, y), source.get_connector_coordinate())
+               x1, y1 = x, y
+               
+               #get the sink coordinate
+               x, y = sink.get_connector_coordinate()
+               connector_length = sink.get_connector_length() + 
CONNECTOR_ARROW_HEIGHT
+               if sink.get_rotation() == 0:
+                       x = x - connector_length
+               elif sink.get_rotation() == 90:
+                       y = y + connector_length
+               elif sink.get_rotation() == 180:
+                       x = x + connector_length
+               elif sink.get_rotation() == 270:
+                       y = y - connector_length
+               self.add_line((x, y), sink.get_connector_coordinate())
+               x2, y2 = x, y   
+               
+               #build the arrows
+               x, y = sink.get_connector_coordinate()
+               if sink.get_rotation() == 0:
+                       self._arrow = [(x, y), (x-CONNECTOR_ARROW_HEIGHT, 
y-CONNECTOR_ARROW_BASE/2), (x-CONNECTOR_ARROW_HEIGHT, y+CONNECTOR_ARROW_BASE/2)]
+               elif sink.get_rotation() == 90:
+                       self._arrow = [(x, y), (x-CONNECTOR_ARROW_BASE/2, 
y+CONNECTOR_ARROW_HEIGHT), (x+CONNECTOR_ARROW_BASE/2, y+CONNECTOR_ARROW_HEIGHT)]
+               elif sink.get_rotation() == 180:
+                       self._arrow = [(x, y), (x+CONNECTOR_ARROW_HEIGHT, 
y-CONNECTOR_ARROW_BASE/2), (x+CONNECTOR_ARROW_HEIGHT, y+CONNECTOR_ARROW_BASE/2)]
+               elif sink.get_rotation() == 270:
+                       self._arrow = [(x, y), (x-CONNECTOR_ARROW_BASE/2, 
y-CONNECTOR_ARROW_HEIGHT), (x+CONNECTOR_ARROW_BASE/2, 
y-CONNECTOR_ARROW_HEIGHT)]                                      
+               
+               #add the horizontal and vertical lines in this connection
                if deltaAngle == 180:
                        W = abs(x1 - x2)
                        H = abs(y1 - y2)
@@ -88,15 +126,7 @@
                """
                self.update()   
                Element.draw(self, window)      
-               gc = self.get_gc()                                      
-               #draw error lines around the existing lines when data types do 
not match
-               if not self.is_valid():
-                       gc.foreground = Colors.ERROR_COLOR      
-                       for (x1, y1),(x2, y2) in 
self.lines_dict[self.get_rotation()]:
-                               if x1 == x2 and x1 > 0 and x2 > 0: #vertical
-                                       window.draw_line(gc, x1-1, y1, x2-1, y2)
-                                       window.draw_line(gc, x1+1, y1, x2+1, y2)
-                               elif y1 == y2 and y1 > 0 and y2 > 0: #horizontal
-                                       window.draw_line(gc, x1, y1-1, x2, y2-1)
-                                       window.draw_line(gc, x1, y1+1, x2, y2+1)
-                       
+               gc = self.get_gc()
+               if not self.is_valid(): gc.foreground = Colors.ERROR_COLOR      
                        
+               #draw arrow on sink port                
+               window.draw_polygon(gc, True, self._arrow)

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Port.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Port.py      2008-02-17 
18:05:42 UTC (rev 7723)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Port.py      2008-02-18 
01:32:40 UTC (rev 7724)
@@ -43,48 +43,41 @@
                """Create new areas and labels for the port."""
                self.clear()
                self.BG_color = Colors.get_color(self.get_color())
-               self._create_labels()           
-               #add the input/output area for each rotation angle      
+               self._create_labels()   
+               #get current rotation
                rotation = self.get_rotation()          
-               conExtLen = CONNECTOR_EXTENSION_LENGTH
-               conExtInitLen = CONNECTOR_EXTENSION_INITIAL_LENGTH
-               conOff = PORT_HEIGHT/2
+               #get all sibling ports  
+               if self.is_source(): ports = self.get_parent().get_sources()
+               elif self.is_sink(): ports = self.get_parent().get_sinks()      
        
                #get a numeric index for this port relative to its sibling ports
-               if self.is_source():
-                       index = self.get_parent().get_sources().index(self)
-               elif self.is_sink():
-                       index = self.get_parent().get_sinks().index(self)       
                        
-               #get the number of sibling ports (including self)
-               if self.is_sink(): length = len(self.get_parent().get_sinks())
-               elif self.is_source(): length = 
len(self.get_parent().get_sources())
-               offset = (self.get_parent().H - length*PORT_HEIGHT - 
(length-1)*PORT_SEPARATION)/2      
-               #reverse the order of ports             
-               if rotation == 180 or rotation == 270: index = length-index-1   
+               index = ports.index(self)
+               length = len(ports)     
+               #reverse the order of ports     for these rotations             
+               if rotation in (180, 270): index = length-index-1
+               offset = (self.get_parent().H - length*PORT_HEIGHT - 
(length-1)*PORT_SEPARATION)/2                      
                #create areas and connector coordinates
                if (self.is_sink() and rotation == 0) or (self.is_source() and 
rotation == 180):                
                        x = -1*PORT_WIDTH
                        y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
                        self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
-                       if self.is_connected(): 
-                               self.__set_connector_coordinates((x-1, 
y+conOff),(x-conExtInitLen-conExtLen*index, y+conOff))
+                       self._connector_coordinate = (x-1, y+PORT_HEIGHT/2)
                elif (self.is_source() and rotation == 0) or (self.is_sink() 
and rotation == 180):      
                        x = self.get_parent().W
                        y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
                        self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
-                       if self.is_connected(): 
-                               
self.__set_connector_coordinates((x+1+PORT_WIDTH, 
y+conOff),(x+conExtInitLen+PORT_WIDTH+conExtLen*index, y+conOff))
+                       self._connector_coordinate = (x+1+PORT_WIDTH, 
y+PORT_HEIGHT/2)
                elif (self.is_source() and rotation == 90) or (self.is_sink() 
and rotation == 270):             
                        y = -1*PORT_WIDTH
                        x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
                        self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
-                       if self.is_connected(): 
-                               self.__set_connector_coordinates((x+conOff, 
y-1),(x+conOff, y-conExtInitLen-conExtLen*index))
+                       self._connector_coordinate = (x+PORT_HEIGHT/2, y-1)
                elif (self.is_sink() and rotation == 90) or (self.is_source() 
and rotation == 270):     
                        y = self.get_parent().W
                        x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
                        self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
-                       if self.is_connected(): 
-                               self.__set_connector_coordinates((x+conOff, 
y+1+PORT_WIDTH),(x+conOff, y+PORT_WIDTH+conExtInitLen+conExtLen*index))
+                       self._connector_coordinate = (x+PORT_HEIGHT/2, 
y+1+PORT_WIDTH)
+               #the connector length
+               self._connector_length = CONNECTOR_EXTENSION_INITIAL_LENGTH + 
CONNECTOR_EXTENSION_LENGTH*index
                        
        def _create_labels(self):
                """Create the labels for the socket."""
@@ -122,27 +115,14 @@
                elif self.is_vertical(): 
                        window.draw_image(gc, self.vertical_label, 0, 0, 
x+X+(PORT_HEIGHT-self.h)/2, y+Y+(PORT_WIDTH-self.w)/2, -1, -1)
        
-       def __set_connector_coordinates(self, coor_inner, coor_outer, 
rotation=None):
+       def get_connector_coordinate(self):
                """!
-               Set the coordinates that connectors may attach to.
-               The connector coordinates are associated with a rotation. If 
rotation is not specified, the element's current rotation is used.
-               @param coor_inner the corrdinate on the socket
-               @param coor_outer the coordinate out of the socket
-               @param rotation rotation in degrees
+               Get the coordinate where connections may attach to.
+               @return the connector coordinate (x, y) tuple
                """
-               rotation = rotation or self.get_rotation()
-               self.connector_coordinates[rotation] = coor_inner, coor_outer   
-       
-       def get_connector_coordinates(self, rotation=None):
-               """!
-               Get the coordinates that Connections may attach to.
-               @param rotation rotation in degrees
-               @return the connector coordinates ((xin, yin), (xout, yout)) 
tuple
-               """
-               if rotation == None: rotation = self.get_rotation()     
+               x,y = self._connector_coordinate
                X,Y = self.get_coordinate()     
-               (x1,y1),(x2,y2)= self.connector_coordinates[rotation]
-               return (x1+X, y1+Y), (x2+X, y2+Y)
+               return (x+X, y+Y)
                        
        def get_connector_direction(self):
                """!
@@ -154,6 +134,14 @@
                if self.is_source(): return self.get_rotation()
                elif self.is_sink(): return (self.get_rotation() + 180)%360     
                
+       def get_connector_length(self):
+               """!
+               Get the length of the connector.
+               The connector length increases as the port index changes.
+               @return the length in pixels
+               """
+               return self._connector_length
+               
        def get_rotation(self):
                """!
                Get the parent's rotation rather than self.





reply via email to

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