OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [widget.pl] - Diff between revs 42 and 43

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 42 Rev 43
Line 1... Line 1...
use Glib qw/TRUE FALSE/;
use Glib qw/TRUE FALSE/;
#use Gtk2 '-init';
#use Gtk2 '-init';
use strict;
use strict;
use warnings;
use warnings;
 
 
 
require "common.pl";
 
 
 
use FindBin;
 
use lib $FindBin::Bin;
 
 
 
use ColorButton;
 
 
use Gtk2::Pango;
use Gtk2::Pango;
#use Tk::Animation;
#use Tk::Animation;
 
 
use String::Similarity;
 
 
 
 
 
sub find_the_most_similar_position{
 
        my ($item ,@list)=@_;
 
        my $most_similar_pos=0;
 
        my $lastsim=0;
 
        my $i=0;
 
        # convert item to lowercase
 
        $item = lc $item;
 
        foreach my $p(@list){
 
                my $similarity= similarity $item, $p;
 
                if ($similarity > $lastsim){
 
                        $lastsim=$similarity;
 
                        $most_similar_pos=$i;
 
                }
 
                $i++;
 
        }
 
        return $most_similar_pos;
 
}
 
 
 
##############
##############
# combo box
# combo box
#############
#############
sub gen_combo{
sub gen_combo{
        my ($combo_list, $combo_active_pos)= @_;
        my ($combo_list, $combo_active_pos)= @_;
Line 200... Line 185...
        return ($box,$entry);
        return ($box,$entry);
 
 
}
}
 
 
###########
###########
#
# checkbutton
###########
###########
 
 
sub def_h_labeled_checkbutton{
sub def_h_labeled_checkbutton{
        my ($label_name,$status)=@_;
        my ($label_name,$status)=@_;
        my $box = def_hbox(TRUE,0);
        my $box = def_hbox(TRUE,0);
Line 335... Line 320...
 
 
        }
        }
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$x,$y,TRUE);
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$x,$y,TRUE);
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
        return $image;
        return $image;
 
}
 
 
 
sub open_inline_image{
 
        my ($image_string,$x,$y,$unit)=@_;
 
        if(defined $unit){
 
                my($width,$hight)=max_win_size();
 
                if($unit eq 'percent'){
 
                        $x= ($x * $width)/100;
 
                        $y= ($y * $hight)/100;
 
                } # else its pixels
 
 
 
        }
 
        my $pixbuf = do {
 
        my $loader = Gtk2::Gdk::PixbufLoader->new();
 
        $loader->set_size(  $x,$y );
 
        $loader->write(  $image_string );
 
        $loader->close();
 
        $loader->get_pixbuf();
 
    };
 
 
 
 
 
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
 
 
 
        return $image;
}
}
 
 
 
 
 
 
sub def_image_button{
sub def_image_button{
        my ($image_file, $label_text, $homogeneous)=@_;
        my ($image_file, $label_text, $homogeneous, $mnemonic)=@_;
        # create box for image and label 
        # create box for image and label 
        $homogeneous = FALSE if(!defined $homogeneous);
        $homogeneous = FALSE if(!defined $homogeneous);
        my $box = def_hbox($homogeneous,0);
        my $box = def_hbox($homogeneous,0);
        my $image = def_icon($image_file) if(-f $image_file);
        my $image = def_icon($image_file) if(-f $image_file);
 
 
Line 355... Line 363...
        $box->pack_start($image, FALSE, FALSE, 0) if(-f $image_file);
        $box->pack_start($image, FALSE, FALSE, 0) if(-f $image_file);
        $box->set_border_width(0);
        $box->set_border_width(0);
        $box->set_spacing (0);
        $box->set_spacing (0);
        # Create a label for the button
        # Create a label for the button
        if(defined $label_text ) {
        if(defined $label_text ) {
                my $label = Gtk2::Label->new("  $label_text");
                my $label;
 
                $label = Gtk2::Label->new("  $label_text") unless (defined $mnemonic);
 
                $label = Gtk2::Label->new_with_mnemonic (" $label_text") if (defined $mnemonic);
                $box->pack_start($label, FALSE, FALSE, 0);
                $box->pack_start($label, FALSE, FALSE, 0);
        }
        }
 
 
 
 
        my $button = Gtk2::Button->new();
        my $button = Gtk2::Button->new();
Line 370... Line 380...
 
 
}
}
 
 
 
 
sub def_image_label{
sub def_image_label{
        my ($image_file, $label_text)=@_;
        my ($image_file, $label_text,$mnemonic)=@_;
        # create box for image and label 
        # create box for image and label 
        my $box = def_hbox(FALSE,1);
        my $box = def_hbox(FALSE,1);
        # now on to the image stuff
        # now on to the image stuff
        my $image = def_icon($image_file);
        my $image = def_icon($image_file);
        $box->pack_start($image, TRUE, FALSE, 0);
        $box->pack_start($image, TRUE, FALSE, 0);
        # Create a label for the button
        # Create a label for the button
        if(defined $label_text ) {
        if(defined $label_text ) {
                my $label = Gtk2::Label->new($label_text);
                my $label;
 
                $label = Gtk2::Label->new("  $label_text") unless (defined $mnemonic);
 
                $label = Gtk2::Label->new_with_mnemonic (" $label_text") if (defined $mnemonic);
                $box->pack_start($label, TRUE, FALSE, 0);
                $box->pack_start($label, TRUE, FALSE, 0);
        }
        }
 
 
        return $box;
        return $box;
 
 
Line 412... Line 424...
sub def_colored_button{
sub def_colored_button{
        my ($label_text,$color_num)=@_;
        my ($label_text,$color_num)=@_;
        # create box for image and label 
        # create box for image and label 
        my $box = def_hbox(FALSE,0);
        my $box = def_hbox(FALSE,0);
        my $font_size=get_defualt_font_size();
        my $font_size=get_defualt_font_size();
        my $size=($font_size==10)? 25:
 
                     ($font_size==9 )? 22:
 
                         ($font_size==8 )? 18:
 
                         ($font_size==7 )? 15:12 ;
 
        $box->set_border_width(0);
 
        $box->set_spacing (0);
 
        # Create a label for the button
 
        if(defined $label_text ) {
 
                my $label = gen_label_in_center("$label_text");
 
                $box->pack_start($label, TRUE, TRUE, 0);
 
        }
 
        my @clr_code=get_color($color_num);
 
        my $color = Gtk2::Gdk::Color->new (@clr_code);
 
 
 
        my $button = Gtk2::Button->new();
        my ($red,$green,$blue) = get_color($color_num);
        $button->modify_bg('normal',$color);
        my $button = ColorButton->new (red => $red, green => $green, blue => $blue, label=>"$label_text");
        $button->add($box);
 
        $button->set_border_width(0);
        $button->set_border_width(0);
        $button->show_all;
        $button->show_all;
        return $button;
        return $button;
 
 
}
}
 
 
 
 
 
 
 
 
sub show_gif{
sub show_gif{
 
 
        my $gif = shift;
        my $gif = shift;
        #my $mw=def_popwin_size(400,200,'hey');
 
        my $vbox = Gtk2::HBox->new (TRUE, 8);
        my $vbox = Gtk2::HBox->new (TRUE, 8);
    my $filename;
    my $filename;
      eval {
      eval {
##          $filename = demo_find_file ("floppybuddy.gif");
 
          $filename = main::demo_find_file ($gif);
          $filename = main::demo_find_file ($gif);
      };
      };
 
 
 
 
      my $image = Gtk2::Image->new_from_file ($gif);
      my $image = Gtk2::Image->new_from_file ($gif);
 
 
     $vbox->set_border_width (4);
     $vbox->set_border_width (4);
     my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
     my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
 
 
        my $frame = Gtk2::Frame->new;
        my $frame = Gtk2::Frame->new;
        $frame->set_shadow_type ('in');
        $frame->set_shadow_type ('in');
 
 
 
 
 
 
 
 
      # Animation
      # Animation
     $frame->add ($image);
     $frame->add ($image);
      $align->add ($frame);
      $align->add ($frame);
 
 
 
 
 
 
 
 
     $vbox->pack_start ($align, FALSE, FALSE, 0);
     $vbox->pack_start ($align, FALSE, FALSE, 0);
 
 
      # $mw->add ($vbox);
 
 
 
 
 
      # Progressive
 
 
 
 
 
 
 
 
 
        #$mw->show_all();
 
  return $vbox;
  return $vbox;
 
 
 
 
 
 
 
 
}
}
 
 
############
############
#       message_dialog
#       message_dialog
############
############
Line 769... Line 737...
  # Make it a bit nicer for text.
  # Make it a bit nicer for text.
  $tview->set_wrap_mode ('word');
  $tview->set_wrap_mode ('word');
  $tview->set_pixels_above_lines (2);
  $tview->set_pixels_above_lines (2);
  $tview->set_pixels_below_lines (2);
  $tview->set_pixels_below_lines (2);
 # $scrolled_window->set_placement('bottom_left' );
 # $scrolled_window->set_placement('bottom_left' );
 
 add_colors_to_textview($tview);
  return ($scrolled_window,$tview);
  return ($scrolled_window,$tview);
}
}
 
 
 
 
#################
#################
Line 798... Line 767...
        if(defined $widget) {$table->attach  ($widget , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
        if(defined $widget) {$table->attach  ($widget , $column, $column+1, $row,$row+1,'fill','shrink',2,2);$column++;}
        #$table->attach  ($tmp , $column+3, $column+4, $row,$row+1,'fill','shrink',2,2);
        #$table->attach  ($tmp , $column+3, $column+4, $row,$row+1,'fill','shrink',2,2);
}
}
 
 
 
 
#sub attach_widget_to_table2 {
 
#       my ($table,$row,$label,$inf_bt,$widget)=@_;
 
 
 
#       my $tmp=gen_label_in_left(" "); 
 
#       $table->attach  ($label , 0, 4,  $row,$row+1,'fill','shrink',2,2);
 
#       $table->attach  ($inf_bt , 4, 5, $row,$row+1,'fill','shrink',2,2);
 
#       $table->attach  ($widget , 5, 9, $row,$row+1,'fill','shrink',2,2);
 
#       $table->attach  ($tmp , 9, 10, $row,$row+1,'fill','shrink',2,2);
 
#}
 
 
 
 
 
######
 
#  state
 
#####
 
 
 
sub def_state{
 
        my ($initial)=@_;
 
        my $entry = Gtk2::Entry->new;
 
        $entry->set_text($initial);
 
        my $timeout=0;
 
        my @state= ($entry,$timeout);
 
        return \@state
 
 
 
}
 
 
 
 
 
 
 
 
 
 
 
sub set_gui_status{
 
        my ($object,$status,$timeout)=@_;
 
        $object->object_add_attribute('gui_status','status',$status);
 
        $object->object_add_attribute('gui_status','timeout',$timeout);
 
}
 
 
 
 
 
sub get_gui_status{
 
        my ($object)=@_;
 
        my $status= $object->object_get_attribute('gui_status','status');
 
        my $timeout=$object->object_get_attribute('gui_status','timeout');
 
        return ($status,$timeout);
 
}
 
 
 
 
 
 
 
##################
##################
#       show_info
#       show_info
##################
##################
sub show_info{
sub show_info{
Line 911... Line 836...
        my ($textview_ref,$color)=@_;
        my ($textview_ref,$color)=@_;
        my $buffer = $textview_ref->get_buffer();
        my $buffer = $textview_ref->get_buffer();
        $buffer->create_tag ("${color}_tag", foreground => $color);
        $buffer->create_tag ("${color}_tag", foreground => $color);
}
}
 
 
 
 
 
 
####################
 
#        file
 
##################
 
 
 
 
 
sub read_verilog_file{
 
        my @files            = @_;
 
        my %cmd_line_defines = ();
 
        my $quiet            = 1;
 
        my @inc_dirs         = ();
 
        my @lib_dirs         = ();
 
        my @lib_exts         = ();
 
        my $vdb = rvp->read_verilog(\@files,[],\%cmd_line_defines,
 
                          $quiet,\@inc_dirs,\@lib_dirs,\@lib_exts);
 
 
 
        my @problems = $vdb->get_problems();
 
        if (@problems) {
 
            foreach my $problem ($vdb->get_problems()) {
 
                print STDERR "$problem.\n";
 
            }
 
            # die "Warnings parsing files!";
 
        }
 
 
 
        return $vdb;
 
}
 
 
 
sub add_color_to_gd{
sub add_color_to_gd{
        foreach (my $i=0;$i<32;$i++ ) {
        foreach (my $i=0;$i<32;$i++ ) {
                my ($red,$green,$blue)=get_color($i);
                my ($red,$green,$blue)=get_color($i);
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
 
 
        }
        }
}
}
 
 
 
 
 
 
sub append_text_to_file {
 
        my  ($file_path,$text)=@_;
 
        open(my $fd, ">>$file_path") or die "could not open $file_path: $!";
 
        print $fd $text;
 
        close $fd;
 
}
 
 
 
 
 
 
 
 
 
sub save_file {
 
        my  ($file_path,$text)=@_;
 
        open my $fd, ">$file_path" or die "could not open $file_path: $!";
 
        print $fd $text;
 
        close $fd;
 
}
 
 
 
sub load_file {
 
        my $file_path=shift;
 
        my $str;
 
        if (-f "$file_path") {
 
 
 
                $str = do {
 
                        local $/ = undef;
 
                        open my $fh, "<", $file_path
 
                        or die "could not open $file_path: $!";
 
                        <$fh>;
 
                };
 
 
 
        }
 
        return $str;
 
}
 
 
 
 
 
 
 
 
 
sub merg_files {
 
        my  ($source_file_path,$dest_file_path)=@_;
 
        local $/=undef;
 
        open FILE, $source_file_path or die "Couldn't open file: $!";
 
        my $string = <FILE>;
 
        close FILE;
 
         append_text_to_file ($dest_file_path,$string);
 
}
 
 
 
 
 
 
 
sub copy_file_and_folders{
 
        my ($file_ref,$project_dir,$target_dir)=@_;
 
 
 
        foreach my $f(@{$file_ref}){
 
                my $name= basename($f);
 
                my $n="$project_dir$f";
 
                if (-f "$n") { #copy file
 
                        copy ("$n","$target_dir");
 
                }elsif(-f "$f" ){
 
                        copy ("$f","$target_dir");
 
                }elsif (-d "$n") {#copy folder
 
                        dircopy ("$n","$target_dir/$name");
 
                }elsif(-d "$f" ){
 
                        dircopy ("$f","$target_dir/$name");
 
 
 
                }
 
        }
 
 
 
}
 
 
 
 
 
sub remove_file_and_folders{
 
        my ($file_ref,$project_dir)=@_;
 
 
 
        foreach my $f(@{$file_ref}){
 
                my $name= basename($f);
 
                my $n="$project_dir$f";
 
                if (-f "$n") { #copy file
 
                        unlink ("$n");
 
                }elsif(-f "$f" ){
 
                        unlink ("$f");
 
                }elsif (-d "$n") {#copy folder
 
                        rmtree ("$n");
 
                }elsif(-d "$f" ){
 
                        rmtree ("$f");
 
                }
 
        }
 
 
 
}
 
 
 
sub read_file_cntent {
 
        my ($f,$project_dir)=@_;
 
        my $n="$project_dir$f";
 
        my $str;
 
        if (-f "$n") {
 
 
 
                $str = do {
 
                        local $/ = undef;
 
                        open my $fh, "<", $n
 
                        or die "could not open $n: $!";
 
                        <$fh>;
 
                };
 
 
 
        }elsif(-f "$f" ){
 
                $str = do {
 
                        local $/ = undef;
 
                        open my $fh, "<", $f
 
                        or die "could not open $f: $!";
 
                        <$fh>;
 
                };
 
 
 
 
 
        }
 
        return $str;
 
 
 
}
 
 
 
 
 
sub check_file_has_string {
 
    my ($file,$string)=@_;
 
    my $r;
 
    open(FILE,$file);
 
    if (grep{/$string/} <FILE>){
 
       $r= 1; #print "word  found\n";
 
    }else{
 
       $r= 0; #print "word not found\n";
 
    }
 
    close FILE;
 
    return $r;
 
}
 
 
 
 
 
###########
 
#  color
 
#########
 
 
 
 
 
 
 
 
 
 
 
 
 
sub get_color {
 
        my $num=shift;
 
 
 
        my @colors=(
 
        0x6495ED,#Cornflower Blue
 
        0xFAEBD7,#Antiquewhite
 
        0xC71585,#Violet Red
 
        0xC0C0C0,#silver
 
        0xADD8E6,#Lightblue     
 
        0x6A5ACD,#Slate Blue
 
        0x00CED1,#Dark Turquoise
 
        0x008080,#Teal
 
        0x2E8B57,#SeaGreen
 
        0xFFB6C1,#Light Pink
 
        0x008000,#Green
 
        0xFF0000,#red
 
        0x808080,#Gray
 
        0x808000,#Olive
 
        0xFF69B4,#Hot Pink
 
        0xFFD700,#Gold
 
        0xDAA520,#Goldenrod
 
        0xFFA500,#Orange
 
        0x32CD32,#LimeGreen
 
        0x0000FF,#Blue
 
        0xFF8C00,#DarkOrange
 
        0xA0522D,#Sienna
 
        0xFF6347,#Tomato
 
        0x0000CD,#Medium Blue
 
        0xFF4500,#OrangeRed
 
        0xDC143C,#Crimson       
 
        0x9932CC,#Dark Orchid
 
        0x800000,#marron
 
        0x800080,#Purple
 
        0x4B0082,#Indigo
 
        0xFFFFFF,#white 
 
        0x000000 #Black         
 
                );
 
 
 
        my $color=      ($num< scalar (@colors))? $colors[$num]: 0xFFFFFF;
 
        my $red=        ($color & 0xFF0000) >> 8;
 
        my $green=      ($color & 0x00FF00);
 
        my $blue=       ($color & 0x0000FF) << 8;
 
 
 
        return ($red,$green,$blue);
 
 
 
}
 
 
 
 
 
sub get_color_hex_string {
 
        my $num=shift;
 
 
 
        my @colors=(
 
        "6495ED",#Cornflower Blue
 
        "FAEBD7",#Antiquewhite
 
        "C71585",#Violet Red
 
        "C0C0C0",#silver
 
        "ADD8E6",#Lightblue     
 
        "6A5ACD",#Slate Blue
 
        "00CED1",#Dark Turquoise
 
        "008080",#Teal
 
        "2E8B57",#SeaGreen
 
        "FFB6C1",#Light Pink
 
        "008000",#Green
 
        "FF0000",#red
 
        "808080",#Gray
 
        "808000",#Olive
 
        "FF69B4",#Hot Pink
 
        "FFD700",#Gold
 
        "DAA520",#Goldenrod
 
        "FFA500",#Orange
 
        "32CD32",#LimeGreen
 
        "0000FF",#Blue
 
        "FF8C00",#DarkOrange
 
        "A0522D",#Sienna
 
        "FF6347",#Tomato
 
        "0000CD",#Medium Blue
 
        "FF4500",#OrangeRed
 
        "DC143C",#Crimson       
 
        "9932CC",#Dark Orchid
 
        "800000",#marron
 
        "800080",#Purple
 
        "4B0082",#Indigo
 
        "FFFFFF",#white 
 
        "000000" #Black         
 
                );
 
 
 
        my $color=      ($num< scalar (@colors))? $colors[$num]: "FFFFFF";
 
        return $color;
 
 
 
}
 
 
 
 
 
 
 
##############
 
#  clone_obj
 
#############
 
 
 
sub clone_obj{
 
        my ($self,$clone)=@_;
 
 
 
        foreach my $p (keys %$self){
 
                delete ($self->{$p});
 
        }
 
        foreach my $p (keys %$clone){
 
                $self->{$p}= $clone->{$p};
 
                my $ref= ref ($clone->{$p});
 
                if( $ref eq 'HASH' ){
 
 
 
                        foreach my $q (keys %{$clone->{$p}}){
 
                                $self->{$p}{$q}= $clone->{$p}{$q};
 
                                my $ref= ref ($self->{$p}{$q});
 
                                if( $ref eq 'HASH' ){
 
 
 
                                        foreach my $z (keys %{$clone->{$p}{$q}}){
 
                                                $self->{$p}{$q}{$z}= $clone->{$p}{$q}{$z};
 
                                                my $ref= ref ($self->{$p}{$q}{$z});
 
                                                if( $ref eq 'HASH' ){
 
 
 
                                                        foreach my $w (keys %{$clone->{$p}{$q}{$z}}){
 
                                                                $self->{$p}{$q}{$z}{$w}= $clone->{$p}{$q}{$z}{$w};
 
                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w});
 
                                                                if( $ref eq 'HASH' ){
 
 
 
 
 
                                                                        foreach my $m (keys %{$clone->{$p}{$q}{$z}{$w}}){
 
                                                                                $self->{$p}{$q}{$z}{$w}{$m}= $clone->{$p}{$q}{$z}{$w}{$m};
 
                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m});
 
                                                                                if( $ref eq 'HASH' ){
 
 
 
                                                                                        foreach my $n (keys %{$clone->{$p}{$q}{$z}{$w}{$m}}){
 
                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}= $clone->{$p}{$q}{$z}{$w}{$m}{$n};
 
                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n});
 
                                                                                                if( $ref eq 'HASH' ){
 
 
 
                                                                                                        foreach my $l (keys %{$clone->{$p}{$q}{$z}{$w}{$m}{$n}}){
 
                                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}{$l}= $clone->{$p}{$q}{$z}{$w}{$m}{$n}{$l};
 
                                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n}{$l});
 
                                                                                                                if( $ref eq 'HASH' ){
 
                                                                                                                }
 
                                                                                                        }
 
 
 
                                                                                                }#if                                                                                                            
 
                                                                                        }#n
 
                                                                                }#if
 
                                                                        }#m                                                     
 
                                                                }#if
 
                                                        }#w
 
                                                }#if
 
                                        }#z
 
                                }#if
 
                        }#q
 
                }#if    
 
        }#p
 
}#sub   
 
 
 
 
 
############
############
#       get file folder list
#       get file folder list
###########
###########
 
 
sub get_directory_name {
sub get_directory_name_widget {
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
        my $browse= def_image_button("icons/browse.png");
        my $browse= def_image_button("icons/browse.png");
 
 
        $browse->signal_connect("clicked"=> sub{
        $browse->signal_connect("clicked"=> sub{
                my $entry_ref=$_[1];
                my $entry_ref=$_[1];
Line 1282... Line 885...
 
 
        return $browse;
        return $browse;
 
 
}
}
 
 
sub get_project_dir{ #mpsoc directory address
 
        my $dir = Cwd::getcwd();
 
        my $project_dir   = abs_path("$dir/../../");
 
        return $project_dir;
 
}
 
 
 
 
sub get_dir_name {
 
        my ($object,$title,$attribute1,$attribute2,$open_in,$status,$timeout)= @_;
 
        my $dir;
 
        $title ='select directory' if(!defined $title);
 
        my $dialog = Gtk2::FileChooserDialog->new(
 
                $title, undef,
 
                #               'open',
 
                'select-folder',
 
                'gtk-cancel' => 'cancel',
 
                'gtk-ok'     => 'ok',
 
        );
 
        if(defined  $open_in){
 
                $dialog->set_current_folder ($open_in);
 
        }
 
 
sub remove_project_dir_from_addr{
        if ( "ok" eq $dialog->run ) {
        my $file=shift;
                        $dir = $dialog->get_filename;
        my $project_dir   = get_project_dir();
                                $object->object_add_attribute($attribute1,$attribute2,$dir);
        $file =~ s/$project_dir//;
                                set_gui_status($object,$status,$timeout) if(defined $status);
        return $file;
                                $dialog->destroy;
 
        }
}
}
 
 
sub add_project_dir_to_addr{
 
        my $file=shift;
 
        my $project_dir   = get_project_dir();
 
        return $file if(-f $file );
 
        return "$project_dir/$file";
 
 
 
}
 
 
 
sub get_file_name {
sub get_file_name {
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
        my $browse= def_image_button("icons/browse.png");
        my $browse= def_image_button("icons/browse.png");
 
 
Line 1541... Line 1148...
        my ($object,$attribute1,$attribute2,$content,$status,$timeout,$default)=@_;
        my ($object,$attribute1,$attribute2,$content,$status,$timeout,$default)=@_;
        my $widget = def_hbox(FALSE,0);
        my $widget = def_hbox(FALSE,0);
        my $value=$object->object_get_attribute($attribute1,$attribute2);
        my $value=$object->object_get_attribute($attribute1,$attribute2);
        $object->object_add_attribute($attribute1,$attribute2,  $default) if (!defined $value );
        $object->object_add_attribute($attribute1,$attribute2,  $default) if (!defined $value );
        $value = $default if (!defined $value );
        $value = $default if (!defined $value );
 
        if (defined $default){
 
                $object->object_add_attribute($attribute1,$attribute2,  $default) if  !(-d $value );
 
                $value = $default  if !(-d $value );
 
        };
 
 
 
        my $warning;
 
 
        my $entry=gen_entry($value);
        my $entry=gen_entry($value);
        $entry-> signal_connect("changed" => sub{
        $entry-> signal_connect("changed" => sub{
                my $new_param_value=$entry->get_text();
                my $new_param_value=$entry->get_text();
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
                set_gui_status($object,$status,$timeout) if (defined $status);
                set_gui_status($object,$status,$timeout) if (defined $status);
 
                unless (-d $new_param_value ){
 
                        if (!defined $warning){
 
                                $warning = def_icon("icons/warning.png");
 
                                $widget->pack_start( $warning, FALSE, FALSE, 0);
 
                                set_tip($warning,"$new_param_value is not a valid directory");
 
                                $widget->show_all;
 
                        }
 
 
 
                }else{
 
                        $warning->destroy if (defined $warning);
 
                        undef $warning;
 
 
 
                }
 
 
        });
        });
        my $browse= get_directory_name($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
        my $browse= get_directory_name_widget($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
 
 
        $widget->pack_start( $entry, FALSE, FALSE, 0);
        $widget->pack_start( $entry, FALSE, FALSE, 0);
        $widget->pack_start( $browse, FALSE, FALSE, 0);
        $widget->pack_start( $browse, FALSE, FALSE, 0);
 
 
 
         if(defined $value){
 
                unless (-d $value ){
 
                        $warning= def_icon("icons/warning.png");
 
                        $widget->pack_start( $warning, FALSE, FALSE, 0);
 
                        set_tip($warning,"$value is not a valid directory path");
 
                }
 
        }
        return $widget;
        return $widget;
}
}
 
 
 
 
 
 
Line 1578... Line 1215...
        return $widget;
        return $widget;
}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sub add_param_widget {
sub add_param_widget {
         my ($mpsoc,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
         my ($self,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
         my $label;
         my $label;
         $label =gen_label_in_left(" $name") if(defined $name);
         $label =gen_label_in_left(" $name") if(defined $name);
         my $widget;
         my $widget;
         my $value=$mpsoc->object_get_attribute($attribut1,$param);
         my $value=$self->object_get_attribute($attribut1,$param);
         if(! defined $value) {
         if(! defined $value) {
                        $mpsoc->object_add_attribute($attribut1,$param,$default);
                        $self->object_add_attribute($attribut1,$param,$default);
                        $mpsoc->object_add_attribute_order($attribut1,$param);
                        $self->object_add_attribute_order($attribut1,$param);
                        $value=$default;
                        $value=$default;
         }
         }
         if(! defined $new_status){
         if(! defined $new_status){
                $new_status='ref';
                $new_status='ref';
         }
         }
 
         if (! defined $loc){
 
                 $loc = "vertical";
 
         }
         if ($type eq "Entry"){
         if ($type eq "Entry"){
                $widget=gen_entry($value);
                $widget=gen_entry($value);
                $widget-> signal_connect("changed" => sub{
                $widget-> signal_connect("changed" => sub{
                        my $new_param_value=$widget->get_text();
                        my $new_param_value=$widget->get_text();
                        $mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
                        $self->object_add_attribute($attribut1,$param,$new_param_value);
                        set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
 
 
 
 
                });
                });
 
 
 
 
         }
         }
         elsif ($type eq "Combo-box"){
         elsif ($type eq "Combo-box"){
                 my @combo_list=split(",",$content);
                 my @combo_list=split(",",$content);
                 my $pos=get_pos($value, @combo_list) if(defined $value);
                 my $pos=get_pos($value, @combo_list) if(defined $value);
                 if(!defined $pos){
                 if(!defined $pos){
                        $mpsoc->object_add_attribute($attribut1,$param,$default);
                        $self->object_add_attribute($attribut1,$param,$default);
                        $pos=get_item_pos($default, @combo_list) if (defined $default);
                        $pos=get_item_pos($default, @combo_list) if (defined $default);
 
 
                 }
                 }
                #print " my $pos=get_item_pos($value, @combo_list);\n";
                #print " my $pos=get_item_pos($value, @combo_list);\n";
                 $widget=gen_combo(\@combo_list, $pos);
                 $widget=gen_combo(\@combo_list, $pos);
                 $widget-> signal_connect("changed" => sub{
                 $widget-> signal_connect("changed" => sub{
                 my $new_param_value=$widget->get_active_text();
                 my $new_param_value=$widget->get_active_text();
                 $mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
                 $self->object_add_attribute($attribut1,$param,$new_param_value);
                 set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                 set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
 
 
 
 
                 });
                 });
 
 
         }
         }
         elsif  ($type eq "Spin-button"){
         elsif  ($type eq "Spin-button"){
                  my ($min,$max,$step)=split(",",$content);
                  my ($min,$max,$step)=split(",",$content);
Line 1641... Line 1267...
                  $step=~ s/\D//g;
                  $step=~ s/\D//g;
                  $widget=gen_spin($min,$max,$step);
                  $widget=gen_spin($min,$max,$step);
                  $widget->set_value($value);
                  $widget->set_value($value);
                  $widget-> signal_connect("value_changed" => sub{
                  $widget-> signal_connect("value_changed" => sub{
                  my $new_param_value=$widget->get_value_as_int();
                  my $new_param_value=$widget->get_value_as_int();
                  $mpsoc->object_add_attribute($attribut1,$param,$new_param_value);
                  $self->object_add_attribute($attribut1,$param,$new_param_value);
                  set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                  set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
 
 
                  });
                  });
 
 
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
         }
         }
 
 
Line 1661... Line 1286...
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
 
 
                        my @chars = split("",$value);
                        my @chars = split("",$value);
                        #check if saved value match the size of check box
                        #check if saved value match the size of check box
                        if($chars[0] ne $content ) {
                        if($chars[0] ne $content ) {
                                $mpsoc->object_add_attribute($attribut1,$param,$default);
                                $self->object_add_attribute($attribut1,$param,$default);
                                $value=$default;
                                $value=$default;
                                @chars = split("",$value);
                                @chars = split("",$value);
                        }
                        }
                        #set initial value
                        #set initial value
 
 
Line 1683... Line 1308...
 
 
                                for (my $i=$content-1; $i >= 0; $i--){
                                for (my $i=$content-1; $i >= 0; $i--){
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
                                        else {$new_val="${new_val}0" ;}
                                        else {$new_val="${new_val}0" ;}
                                }
                                }
                                $mpsoc->object_add_attribute($attribut1,$param,$new_val);
                                $self->object_add_attribute($attribut1,$param,$new_val);
                                #print "\$new_val=$new_val\n";
                                #print "\$new_val=$new_val\n";
                                set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                                set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
                        });
                        });
                }
                }
 
 
 
 
 
 
 
 
        }
        }
        elsif ( $type eq "DIR_path"){
        elsif ( $type eq "DIR_path"){
                        $widget =get_dir_in_object ($mpsoc,$attribut1,$param,$value,'ref',10);
                        $widget =get_dir_in_object ($self,$attribut1,$param,$value,'ref',10,$default);
                        set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
        }
        }
        elsif ( $type eq "FILE_path"){ # use $content as extention
        elsif ( $type eq "FILE_path"){ # use $content as extention
                        $widget =get_file_name_object ($mpsoc,$attribut1,$param,$content,undef);
                        $widget =get_file_name_object ($self,$attribut1,$param,$content,undef);
                        set_gui_status($mpsoc,$new_status,$ref_delay) if(defined $ref_delay);
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
        }
        }
 
 
        else {
        else {
                 $widget =gen_label_in_left("unsuported widget type!");
                 $widget =gen_label_in_left("unsuported widget type!");
        }
        }
Line 1749... Line 1371...
}
}
 
 
 
 
 
 
 
 
################
 
#       general
 
#################
 
 
 
 
 
 
 
 
 
sub  trim { my $s = shift;  $s=~s/[\n]//gs; return $s };
 
 
 
sub remove_all_white_spaces($)
 
{
 
  my $string = shift;
 
  $string =~ s/\s+//g;
 
  return $string;
 
}
 
 
 
 
 
 
 
 
 
sub get_scolar_pos{
 
        my ($item,@list)=@_;
 
        my $pos;
 
        my $i=0;
 
        foreach my $c (@list)
 
        {
 
                if(  $c eq $item) {$pos=$i}
 
                $i++;
 
        }
 
        return $pos;
 
}
 
 
 
sub remove_scolar_from_array{
 
        my ($array_ref,$item)=@_;
 
        my @array=@{$array_ref};
 
        my @new;
 
        foreach my $p (@array){
 
                if($p ne $item ){
 
                        push(@new,$p);
 
                }
 
        }
 
        return @new;
 
}
 
 
 
sub replace_in_array{
 
        my ($array_ref,$item1,$item2)=@_;
 
        my @array=@{$array_ref};
 
        my @new;
 
        foreach my $p (@array){
 
                if($p eq $item1 ){
 
                        push(@new,$item2);
 
                }else{
 
                        push(@new,$p);
 
                }
 
        }
 
        return @new;
 
}
 
 
 
 
 
 
 
# return an array of common elemnts between two input arays 
 
sub get_common_array{
 
        my ($a_ref,$b_ref)=@_;
 
        my @A=@{$a_ref};
 
        my @B=@{$b_ref};
 
        my @C;
 
        foreach my $p (@A){
 
                if( grep (/^\Q$p\E$/,@B)){push(@C,$p)};
 
        }
 
        return  @C;
 
}
 
 
 
#a-b
 
sub get_diff_array{
 
        my ($a_ref,$b_ref)=@_;
 
        my @A=@{$a_ref};
 
        my @B=@{$b_ref};
 
        my @C;
 
        foreach my $p (@A){
 
                if( !grep  (/^\Q$p\E$/,@B)){push(@C,$p)};
 
        }
 
        return  @C;
 
 
 
}
 
 
 
 
 
 
 
sub compress_nums{
 
        my      @nums=@_;
 
        my @f=sort { $a <=> $b } @nums;
 
        my $s;
 
        my $ls;
 
        my $range=0;
 
        my $x;
 
 
 
 
 
        foreach my $p (@f){
 
                if(!defined $x) {
 
                        $s="$p";
 
                        $ls=$p;
 
 
 
                }
 
                else{
 
                        if($p-$x>1){ #gap exist
 
                                if( $range){
 
                                        $s=($x-$ls>1 )? "$s:$x,$p": "$s,$x,$p";
 
                                        $ls=$p;
 
                                        $range=0;
 
                                }else{
 
                                $s= "$s,$p";
 
                                $ls=$p;
 
 
 
                                }
 
 
 
                        }else {$range=1;}
 
 
 
 
 
 
 
                }
 
 
 
                $x=$p
 
        }
 
        if($range==1){ $s= ($x-$ls>1 )? "$s:$x":  "$s,$x";}
 
        #update $s($ls,$hs);
 
 
 
        return $s;
 
 
 
}
 
 
 
 
 
 
 
sub metric_conversion{
 
        my $size=shift;
 
        my $size_text=  $size==0  ? 'Error':
 
                        $size<(1 << 10)? $size:
 
                        $size<(1 << 20)? join (' ', ($size>>10,"K")) :
 
                        $size<(1 << 30)? join (' ', ($size>>20,"M")) :
 
                                         join (' ', ($size>>30,"G")) ;
 
return $size_text;
 
}
 
 
 
 
 
 
 
sub check_verilog_identifier_syntax {
 
        my $in=shift;
 
        my $error=0;
 
        my $message='';
 
# an Identifiers must begin with an alphabetic character or the underscore character
 
        if ($in =~ /^[0-9\$]/){
 
                return 'an Identifier must begin with an alphabetic character or the underscore character';
 
        }
 
 
 
 
 
#       Identifiers may contain alphabetic characters, numeric characters, the underscore, and the dollar sign (a-z A-Z 0-9 _ $ )
 
        if ($in =~ /[^a-zA-Z0-9_\$]+/){
 
                 print "use of illegal character after\n" ;
 
                 my @w= split /([^a-zA-Z0-9_\$]+)/, $in;
 
                 return "Contain illegal character of \"$w[1]\". Identifiers may contain alphabetic characters, numeric characters, the underscore, and the dollar sign (a-z A-Z 0-9 _ \$ )\n";
 
 
 
        }
 
 
 
 
 
# check Verilog reserved words
 
        my @keys =                      ("always","and","assign","automatic","begin","buf","bufif0","bufif1","case","casex","casez","cell","cmos","config","deassign","default","defparam","design","disable","edge","else","end","endcase","endconfig","endfunction","endgenerate","endmodule","endprimitive","endspecify","endtable","endtask","event","for","force","forever","fork","function","generate","genvar","highz0","highz1","if","ifnone","incdir","include","initial","inout","input","instance","integer","join","large","liblist","library","localparam","macromodule","medium","module","nand","negedge","nmos","nor","noshowcancelled","not","notif0","notif1","or","output","parameter","pmos","posedge","primitive","pull0","pull1","pulldown","pullup","pulsestyle_onevent","pulsestyle_ondetect","remos","real","realtime","reg","release","repeat","rnmos","rpmos","rtran","rtranif0","rtranif1","scalared","showcancelled","signed","small","specify","specparam","strong0","strong1","supply0","supply1","table","task","time","tran","tranif0","tranif1","tri","tri0","tri1","triand","trior","trireg","unsigned","use","vectored","wait","wand","weak0","weak1","while","wire","wor","xnor","xor");
 
        if( grep (/^$in$/,@keys)){
 
                return  "$in is a Verlig reserved word.";
 
        }
 
        return undef;
 
 
 
}
 
 
 
 
 
sub capture_number_after {
 
        my ($after,$text)=@_;
 
        my @q =split  (/$after/,$text);
 
        #my $d=$q[1];
 
        my @d = split (/[^0-9. ]/,$q[1]);
 
        return $d[0];
 
 
 
}
 
 
 
sub capture_string_between {
 
        my ($start,$text,$end)=@_;
 
        my @q =split  (/$start/,$text);
 
        my @d = split (/$end/,$q[1]);
 
        return $d[0];
 
}
 
 
 
 
 
sub make_undef_as_string {
 
        foreach my $p  (@_){
 
                $$p= 'undef' if (! defined $$p);
 
 
 
        }
 
}
 
 
 
 
 
1
1
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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