Changeset 622

Show
Ignore:
Timestamp:
04/30/07 14:39:18 (6 years ago)
Author:
ignotus21
Message:

Start of animation of graph.

Location:
branch/joao/umitMapper
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branch/joao/umitMapper/Coordinate.py

    r594 r622  
    4646        @return: Polar coordinates (r, t) 
    4747        """ 
    48         return (self.__r, self.__t) 
     48        return (self.__r, math.degrees(self.__t)) 
    4949 
    5050 
     
    5858        """ 
    5959        self.__r = r 
    60         self.__t = t 
     60        self.__t = math.radians(t) 
    6161 
    6262 
  • branch/joao/umitMapper/Interpolation.py

    r596 r622  
    7171        (af, bf) = self.__finalPoint 
    7272 
    73         return (a, bi + ((a - ai) * (bf - bi) / (af - ai))) 
     73        try: 
     74            result = (a, bi + ((a - ai) * (bf - bi) / (af - ai))) 
     75        except ZeroDivisionError: 
     76            result = (a, bf) 
     77 
     78        return result 
    7479 
    7580 
     
    8792 
    8893        aPass = float(af - ai) / numberOfPass 
    89         aList = arange(ai+aPass, af+aPass, aPass) 
     94 
     95        self.__interpolatedPoints = range(numberOfPass) 
    9096 
    9197        for i in range(numberOfPass): 
    92             self.__interpolatedPoints.insert( i, self.interpolate(aList[i]) ) 
     98            self.__interpolatedPoints[i] = self.interpolate(ai + (i + 1) * aPass) 
    9399 
    94100        return self.__interpolatedPoints 
  • branch/joao/umitMapper/RadialNet.py

    r620 r622  
    1919import gtk 
    2020import math 
     21import time 
    2122import pango 
    2223import drawing 
    2324import geometry 
     25import gobject 
    2426from gtk import gdk 
    2527from Coordinate import PolarCoordinate 
     28from Interpolation import Linear2DInterpolator 
    2629from Graph import Graph, Node 
    2730 
     
    3134    Radial network visualization widget 
    3235    """ 
    33  
    3436    def __init__(self, numberOfRings=3): 
    3537        """ 
     
    4749        """Store the center of widget""" 
    4850        self.__isInAnimation = False 
     51        """""" 
     52        self.exposedNodes = set([]) 
     53        """""" 
     54        self.__animationRate = 10 
     55        """""" 
    4956 
    5057        super(RadialNet, self).__init__() 
     
    5360        self.connect("button_release_event", self.button_release) 
    5461        self.connect("motion_notify_event", self.motion_notify) 
     62        self.connect("enter_notify_event", self.enter_notify) 
     63        self.connect("leave_notify_event", self.leave_notify) 
    5564 
    5665        self.add_events(gdk.BUTTON_PRESS_MASK | 
    5766                        gdk.BUTTON_RELEASE_MASK | 
     67                        gdk.ENTER_NOTIFY | 
     68                        gdk.LEAVE_NOTIFY | 
    5869                        gdk.POINTER_MOTION_MASK) 
     70 
     71 
     72    def notIsInAnimation(function): 
     73        """ 
     74        """ 
     75        def checkAnimationStatus(*args): 
     76            if args[0].__isInAnimation == True: 
     77                return True 
     78            return function(*args) 
     79 
     80        return checkAnimationStatus 
    5981 
    6082 
     
    78100 
    79101 
     102    @notIsInAnimation 
     103    def enter_notify(self, widget, event): 
     104        """ 
     105        """ 
     106 
     107 
     108    @notIsInAnimation 
     109    def leave_notify(self, widget, event): 
     110        """ 
     111        """ 
     112        for id in range(self.__graph.getNumberOfNodes()): 
     113            node = self.__graph.getNodeByID(id) 
     114            node.setDrawInfo('over', False) 
     115 
     116        self.queue_draw() 
     117         
     118 
     119    @notIsInAnimation 
    80120    def button_press(self, widget, event): 
    81121        """ 
     
    90130        event.window.set_cursor(gdk.Cursor(gtk.gdk.X_CURSOR)) 
    91131 
     132        if event.button == 1: 
     133            result = self.__getNodeByCoordinate(self.get_pointer()) 
     134 
     135            if ( result != None ): 
     136 
     137                node, point = result 
     138                self.anim(node.getID()) 
     139 
    92140        if event.button == 3: 
    93141 
     
    100148                x, y = point 
    101149 
    102                 nodeView = NodeView(node, (int(xw + x), int(yw + y)), self) 
    103                 nodeView.show_all() 
     150                if node.getID() not in self.exposedNodes: 
     151 
     152                    nodeView = NodeView(node, (int(xw + x), int(yw + y)), self) 
     153                    nodeView.show_all() 
     154                    self.exposedNodes.add(node.getID()) 
    104155         
    105156        return True 
    106157 
    107158 
     159    @notIsInAnimation 
    108160    def button_release(self, widget, event): 
    109161        """ 
     
    121173 
    122174 
     175    @notIsInAnimation 
    123176    def motion_notify(self, widget, event): 
    124177        """ 
     
    165218        self.context.clip() 
    166219 
    167         self.draw() 
    168  
    169         return False 
    170  
    171  
    172     def draw(self): 
     220        self.__draw() 
     221 
     222        return True 
     223 
     224 
     225    def __draw(self): 
    173226        """ 
    174227        Drawing method 
     
    191244 
    192245        # Drawing nodes and your connections 
    193  
    194         self.__calculateNodePositions() 
    195246 
    196247        connectionsList = set() 
     
    307358 
    308359                    theta = ((b - a) / 2) + a 
    309                     child.setPolarCoordinate(radius, math.radians(theta)) 
     360                    child.setPolarCoordinate(radius, theta) 
    310361 
    311362                    locNodes.append(j) 
     
    321372 
    322373 
     374    def anim(self, node_id): 
     375        """ 
     376        """ 
     377        self.__isInAnimation = True # Lock main draw functions and events 
     378 
     379        initialCoordinates = range(self.__graph.getNumberOfNodes()) 
     380        finalCoordinates = range(self.__graph.getNumberOfNodes()) 
     381        interpolatedCoordinates = range(self.__graph.getNumberOfNodes()) 
     382 
     383        for id in range(self.__graph.getNumberOfNodes()): 
     384 
     385            node = self.__graph.getNodeByID(id) 
     386            initialCoordinates[id] = node.getPolarCoordinate() 
     387 
     388        old_main_node_id = self.__graph.getMainNodeID() 
     389 
     390        self.__graph.setMainNodeByID(node_id) 
     391        self.__calculateNodePositions() 
     392 
     393        for id in range(self.__graph.getNumberOfNodes()): 
     394 
     395            node = self.__graph.getNodeByID(id) 
     396            finalCoordinates[id] = node.getPolarCoordinate() 
     397 
     398            ri, ti = initialCoordinates[id] 
     399            rf, tf = finalCoordinates[id] 
     400 
     401            interpolator = Linear2DInterpolator() 
     402            interpolator.setInitialPoint(ri, ti) 
     403            interpolator.setFinalPoint(rf, tf) 
     404            points = interpolator.getInterpolatedPoints(self.__animationRate) 
     405            interpolatedCoordinates[id] = points 
     406 
     407        self.__isInAnimation = False # Unlock main draw functions and events 
     408 
     409        for i in range(self.__animationRate): 
     410 
     411            for id in range(self.__graph.getNumberOfNodes()): 
     412 
     413                r, t = interpolatedCoordinates[id][i] 
     414                node = self.__graph.getNodeByID(id) 
     415                node.setPolarCoordinate(r, t) 
     416 
     417            self.queue_draw() 
     418 
     419 
     420 
    323421    def setGraph(self, graph): 
    324422        """ 
     
    328426        """ 
    329427        self.__graph = graph 
     428        self.__calculateNodePositions() 
    330429 
    331430 
     
    344443        self.move(position[0], position[1]) 
    345444        self.__button_press_position = self.get_pointer() 
    346         self.resize(200, 120) 
    347         self.modify_bg(gtk.STATE_NORMAL, gdk.color_parse("#ffffe0")) 
     445        self.resize(240, 120) 
    348446 
    349447        self.__node = node 
     
    370468        """ 
    371469        """ 
    372         body = gtk.VBox() 
    373         body.set_spacing(5) 
    374         body.set_border_width(5) 
    375         head = gtk.HBox() 
    376         head.set_spacing(5) 
    377         head.set_border_width(5) 
    378  
    379         bold_font = pango.FontDescription('monospace bold 8') 
     470        self.__content = gtk.VBox() 
     471        self.__content.set_spacing(2) 
     472        self.__content.set_border_width(3) 
     473        self.__body = gtk.VBox() 
     474        self.__head = gtk.HBox() 
     475        self.__head.set_spacing(2) 
     476 
     477        bold_font = pango.FontDescription('bold') 
    380478        normal_font = pango.FontDescription('monospace 8') 
    381479 
    382         color = gtk.EventBox() 
    383         color.set_size_request(15, 15) 
     480        color_event = gtk.EventBox() 
     481        color = gtk.Image() 
     482        color.set_from_file('image/border.png') 
     483        color_event.add(color) 
     484        color_event.set_size_request(15, 15) 
    384485        r, g, b = drawing.cairoToGdkColor(self.__node.getDrawInfo('color')) 
    385         color.modify_bg(gtk.STATE_NORMAL, gdk.Color(r, g, b)) 
    386  
     486        color_event.modify_bg(gtk.STATE_NORMAL, gdk.Color(r, g, b)) 
     487 
     488        title_event = gtk.EventBox() 
    387489        title = gtk.Label() 
    388490        title.set_markup(self.__node.getInformation('ip')) 
     
    410512        collapse_event.add_events(gdk.BUTTON_PRESS_MASK) 
    411513 
    412         head.pack_start(color, False, False, 0) 
    413         head.pack_start(title, False, False, 0) 
    414         head.pack_end(close_event, False, False, 0) 
    415         head.pack_end(expand_event, False, False, 0) 
    416         head.pack_end(collapse_event, False, False, 0) 
    417         body.pack_start(head, False, False, 0) 
    418  
    419         self.add(body) 
     514        text_scroll = gtk.ScrolledWindow() 
     515        text_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 
     516        text = gtk.TextView() 
     517        text_scroll.add(text) 
     518 
     519        self.__head.pack_start(color_event, False, False, 0) 
     520        self.__head.pack_start(title, False, False, 0) 
     521        self.__head.pack_end(close_event, False, False, 0) 
     522        self.__head.pack_end(expand_event, False, False, 0) 
     523        self.__head.pack_end(collapse_event, False, False, 0) 
     524        self.__body.pack_start(text_scroll, True, True, 0) 
     525 
     526        self.__content.pack_start(self.__head, False, False, 0) 
     527        self.__content.pack_start(self.__body, True, True, 0) 
     528 
     529        self.add(self.__content) 
    420530 
    421531 
     
    425535        self.__node.setDrawInfo('over', False) 
    426536        self.destroy() 
     537        self.__parent.exposedNodes.remove(self.__node.getID()) 
    427538        self.__parent.queue_draw() 
    428539 
     540        return True 
     541 
    429542 
    430543    def expand_window(self, widget, event): 
    431544        """ 
    432545        """ 
     546        self.present() 
     547        self.__body.show() 
     548 
    433549        if self.__COMPACTED == 1: 
    434             self.resize(400, 240) 
     550            self.resize(480, 240) 
    435551            self.__COMPACTED = 0 
    436552        else: 
    437             self.resize(200, 120) 
     553            self.resize(240, 120) 
    438554            self.__COMPACTED = 1 
    439555 
     556        return True 
     557 
    440558 
    441559    def collapse_window(self, widget, event): 
    442560        """ 
    443561        """ 
     562        self.present() 
     563 
    444564        if self.__COLLAPSED == 0: 
    445             self.resize(200, 30) 
     565            self.resize(240, 20) 
     566            self.__body.hide() 
    446567            self.__COLLAPSED = 1 
    447568        else: 
    448569            if self.__COMPACTED == 0: 
    449                 self.resize(400, 240) 
     570                self.resize(480, 240) 
    450571            else: 
    451                 self.resize(200, 120) 
     572                self.resize(240, 120) 
     573            self.__body.show() 
    452574            self.__COLLAPSED = 0 
    453575 
     576        return True 
     577 
    454578 
    455579    def button_press(self, widget, event): 
    456580        """ 
    457581        """ 
     582        self.present() 
    458583        self.__pressed = True 
    459584        self.__button_press_position = self.get_pointer() 
     
    488613        self.__node.setDrawInfo('over', True) 
    489614 
    490         if event.is_hint == True: 
    491  
    492             x, y, button_state = event.window.get_pointer() 
    493  
    494             if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed: 
    495  
    496                 xw, yw = event.window.get_root_origin() 
    497                 xd, yd = self.__button_press_position 
    498                 self.move(x + xw - xd, y + yw - yd) 
     615        x, y, button_state = event.window.get_pointer() 
     616 
     617        if button_state & gtk.gdk.BUTTON1_MASK and self.__pressed: 
     618 
     619            xw, yw = event.window.get_root_origin() 
     620            xd, yd = self.__button_press_position 
     621            self.move(x + xw - xd, y + yw - yd) 
    499622 
    500623        return True 
     
    636759 
    637760    radialnet.setGraph(graph) 
    638     radialnet.set_size_request(400, 400) 
     761    radialnet.set_size_request(640, 480) 
    639762 
    640763    window.add(radialnet)