OpenCores
URL https://opencores.org/ocsvn/nocmodel/nocmodel/trunk

Subversion Repositories nocmodel

[/] [nocmodel/] [trunk/] [nocmodel/] [noc_guilib.py] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dargor
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
#
5
# Support for graphical representation of NoC objects
6
#
7
# Author:  Oscar Diaz
8
# Version: 0.1
9
# Date:    03-03-2011
10
 
11
#
12
# This code is free software; you can redistribute it and/or
13
# modify it under the terms of the GNU Lesser General Public
14
# License as published by the Free Software Foundation; either
15
# version 2.1 of the License, or (at your option) any later version.
16
#
17
# This code is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
# Lesser General Public License for more details.
21
#
22
# You should have received a copy of the GNU Lesser General Public
23
# License along with this library; if not, write to the
24
# Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
25
# Boston, MA  02111-1307  USA
26
#
27
 
28
#
29
# Changelog:
30
#
31
# 03-03-2011 : (OD) initial release
32
#
33
 
34
"""
35
================
36
NoCmodel Graphic utilities
37
================
38
 
39
This module declares functions to draw graphical representations of
40
NoCmodel objects.
41
 
42
"""
43
 
44
import matplotlib.pyplot as plt
45
import networkx as nx
46
 
47
from noc_base import *
48
 
49
def draw_noc(noc, rectangular=True, nodepos=None):
50
    """
51
    Draw a representation of a NoC
52
 
53
    Arguments:
54
    * noc: Model to draw
55
    * rectangular: If True assumes rectangular layout, with routers
56
      having coord_x and coord_y attributes. If false, expect router's
57
      positions in nodepos argument
58
    * nodepos: Optional dictionary where keys are router's indexes and values
59
      are tuples with x and y positions.
60
    """
61
    # node positions
62
    if rectangular:
63
        if nodepos == None:
64
            nodepos = {}
65
            for i in noc.router_list():
66
                nodepos[i.index] = (i.coord_x, i.coord_y)
67
    else:
68
        if nodepos == None:
69
            raise ValueError("For non-rectangular layouts this function needs argument 'nodepos'")
70
 
71
    # some parameters
72
    ip_relpos = (-0.3, 0.3) # relative to router
73
    # node labels
74
    nodelabels = {}
75
    for i in nodepos.iterkeys():
76
        nodelabels[i] = noc.node[i]["router_ref"].name
77
 
78
    # channel positions
79
    chpos = {}
80
    for i in noc.channel_list():
81
        ep = i.endpoints
82
        ep_1x = nodepos[ep[0].index][0]
83
        ep_1y = nodepos[ep[0].index][1]
84
        ep_2x = nodepos[ep[1].index][0]
85
        ep_2y = nodepos[ep[1].index][1]
86
        thepos = (ep_2x + ((ep_1x - ep_2x)/2.0), ep_2y + ((ep_1y - ep_2y)/2.0))
87
        chpos[i.index] = {"pos": thepos, "text": i.name}
88
 
89
    # start drawing
90
    nx.draw_networkx_nodes(noc, pos=nodepos, node_size=1000, node_color="blue", alpha=0.5)
91
    nx.draw_networkx_edges(noc, pos=nodepos, edge_color="black", alpha=1.0, width=3.0)
92
    nx.draw_networkx_labels(noc, pos=nodepos, labels=nodelabels, font_color="red")
93
 
94
    ax=plt.gca()
95
    # channel labels
96
    for i in chpos.itervalues():
97
        ax.text(i["pos"][0], i["pos"][1], i["text"], horizontalalignment="center", verticalalignment="top", bbox=dict(facecolor='red', alpha=0.2))
98
 
99
    # ipcore with channels and labels
100
    for i in noc.ipcore_list():
101
        thepos = nodepos[i.router_ref.index]
102
        # channel
103
        ax.arrow(thepos[0], thepos[1], ip_relpos[0], ip_relpos[1])
104
        # ip channel label
105
        ax.text(thepos[0]+(ip_relpos[0]/2), thepos[1]+(ip_relpos[1]/2), i.channel_ref.name, horizontalalignment="center", bbox=dict(facecolor='red', alpha=0.2))
106
        # box with ipcore labels
107
        ax.text(thepos[0]+ip_relpos[0], thepos[1]+ip_relpos[1], i.name, horizontalalignment="center", bbox=dict(facecolor='green', alpha=0.2))
108
 
109
    plt.show()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.