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] - Blame information for rev 34

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

Line No. Rev Author Line
1 16 alirezamon
use Glib qw/TRUE FALSE/;
2
#use Gtk2 '-init';
3
use strict;
4
use warnings;
5
 
6 25 alirezamon
 
7
 
8 16 alirezamon
use Gtk2::Pango;
9 25 alirezamon
#use Tk::Animation;
10 16 alirezamon
 
11
##############
12
# combo box
13
#############
14
sub gen_combo{
15
        my ($combo_list, $combo_active_pos)= @_;
16
        my $combo = Gtk2::ComboBox->new_text;
17
 
18
        combo_set_names($combo,$combo_list);
19 25 alirezamon
        $combo->set_active($combo_active_pos) if(defined $combo_active_pos);
20 16 alirezamon
 
21
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
22
        #$combo->modify_font($font);
23
 
24
 
25
        return $combo;
26
}
27
 
28
 
29
sub combo_set_names {
30
        my ( $combo, $list_ref ) = @_;
31
        my @list=@{$list_ref};
32
        #print "$list[0]\n";
33
        for my $item (@list){$combo->append_text($item);}
34
}
35
 
36
 
37
sub gen_combo_help {
38
        my ($help, @combo_list, $pos)= @_;
39
        my $box = def_hbox(FALSE, 0);
40
        my $combo= gen_combo(@combo_list, $pos);
41
        my $button=def_image_button("icons/help.png");
42
 
43
        $button->signal_connect("clicked" => sub {message_dialog($help);});
44
 
45
        $box->pack_start( $combo, FALSE, FALSE, 3);
46
        $box->pack_start( $button, FALSE, FALSE, 3);
47
        $box->show_all;
48
 
49
        return ($box,$combo);
50
}
51
 
52
 
53
sub def_h_labeled_combo{
54
                my ($label_name,$combo_list,$combo_active_pos)=@_;
55
                my $box = def_hbox(TRUE,0);
56
                my $label= gen_label_in_left($label_name);
57
                my $combo= gen_combo($combo_list, $combo_active_pos);
58
                $box->pack_start( $label, FALSE, FALSE, 3);
59
                $box->pack_start( $combo, FALSE, TRUE, 3);
60
                return ($box,$combo);
61
}
62
 
63
sub def_h_labeled_combo_scaled{
64
                my ($label_name,$combo_list,$combo_active_pos,$lable_w,$comb_w)=@_;
65
                my $table= def_table(1,3,TRUE);
66
                my $label= gen_label_in_left($label_name);
67
                my $combo= gen_combo($combo_list, $combo_active_pos);
68
                $table->attach_defaults ($label, 0, $lable_w, 0, 1);
69
                $table->attach_defaults ($combo, 1, $lable_w+$comb_w, 0, 1);
70
 
71
 
72
 
73
 
74
                return ($table,$combo);
75
}
76
 
77
 
78
##############
79
# spin button
80
#############
81
sub gen_spin{
82
        my ($min,$max,$step)= @_;
83
        my $spin = Gtk2::SpinButton->new_with_range ($min, $max, $step);
84
        return $spin;
85
}
86
 
87
 
88
 
89
sub gen_spin_help {
90
        my ($help, $min,$max,$step)= @_;
91
        my $box = def_hbox(FALSE, 0);
92
        my $spin= gen_spin($min,$max,$step);
93
        my $button=def_image_button("icons/help.png");
94
 
95
        $button->signal_connect("clicked" => sub {message_dialog($help);});
96
 
97
        $box->pack_start( $spin, FALSE, FALSE, 3);
98
        $box->pack_start( $button, FALSE, FALSE, 3);
99
        $box->show_all;
100
 
101
        return ($box,$spin);
102
}
103
 
104
 
105
#############
106
#  entry
107
#############
108
sub gen_entry{
109
        my ($initial) = @_;
110
        my $entry = Gtk2::Entry->new;
111
        if(defined $initial){ $entry->set_text($initial)};
112
        return $entry;
113
}
114
 
115
 
116
sub gen_entry_help{
117
        my ($help, $init)= @_;
118
        my $box = def_hbox(FALSE, 0);
119
        my $entry= gen_entry ($init);
120
        my $button=def_image_button("icons/help.png");
121
 
122
        $button->signal_connect("clicked" => sub {message_dialog($help);});
123
 
124
        $box->pack_start( $entry, FALSE, FALSE, 3);
125
        $box->pack_start( $button, FALSE, FALSE, 3);
126
        $box->show_all;
127
 
128
        return ($box,$entry);
129
}
130
 
131
sub def_h_labeled_entry{
132
        my ($label_name,$initial)=@_;
133
        my $box = def_hbox(TRUE,0);
134
        my $label= gen_label_in_left($label_name);
135
        my $entry =gen_entry($initial);
136
        $box->pack_start( $label, FALSE, FALSE, 3);
137
        $box->pack_start( $entry, FALSE, FALSE, 3);
138
        return ($box,$entry);
139
 
140 24 alirezamon
}
141 16 alirezamon
 
142 24 alirezamon
sub def_h_labeled_entry_help{
143
        my ($help,$label_name,$initial)=@_;
144
        my $box = def_hbox(TRUE,0);
145
        my $label= gen_label_in_left($label_name);
146
        my ($b,$entry) =gen_entry_help($help,$initial);
147
        $box->pack_start( $label, FALSE, FALSE, 3);
148
        $box->pack_start( $b, FALSE, FALSE, 3);
149
        return ($box,$entry);
150
 
151
}
152
 
153 17 alirezamon
##############
154
# ComboBoxEntry
155
##############
156 16 alirezamon
 
157 17 alirezamon
sub gen_combo_entry{
158 25 alirezamon
        my ($list_ref,$pos)=@_;
159 17 alirezamon
        my @list=@{$list_ref};
160
 
161
        my $combo_box_entry = Gtk2::ComboBoxEntry->new_text;
162
        foreach my $p (@list){
163
                $combo_box_entry->append_text($p);
164
        }
165 25 alirezamon
        $pos=0 if(! defined $pos );
166
        $combo_box_entry->set_active($pos);
167 17 alirezamon
        return $combo_box_entry;
168
}
169
 
170 25 alirezamon
 
171
sub def_h_labeled_combo_entry_help{
172
        my ($help,$label_name,$list_ref,$initial)=@_;
173
        my $box = def_hbox(TRUE,0);
174
        my $label= gen_label_in_left($list_ref);
175
        my ($b,$entry) =gen_combo_entry($help,$initial);
176
        $box->pack_start( $label, FALSE, FALSE, 3);
177
        $box->pack_start( $b, FALSE, FALSE, 3);
178
        return ($box,$entry);
179
 
180
}
181
 
182 24 alirezamon
###########
183
#
184
###########
185
 
186
sub def_h_labeled_checkbutton{
187
        my ($label_name,$status)=@_;
188
        my $box = def_hbox(TRUE,0);
189
        my $label= gen_label_in_left($label_name);
190
        my $check= Gtk2::CheckButton->new;
191
        #if($status==1) $check->
192
        $box->pack_start( $label, FALSE, FALSE, 3);
193
        $box->pack_start( $check, FALSE, FALSE, 3);
194
        return ($box,$check);
195
 
196
}
197
 
198
 
199
 
200
 
201 16 alirezamon
#############
202
#  label
203
############
204
 
205
sub gen_label_in_left{
206
        my ($data)=@_;
207
        my $label   = Gtk2::Label->new($data);
208
        $label->set_alignment( 0, 0.5 );
209
        #my $font = Gtk2::Pango::FontDescription->from_string('Tahoma 5');
210
        #$label->modify_font($font);
211
        return $label;
212
}
213
 
214
 
215
sub gen_label_in_center{
216
        my ($data)=@_;
217
        my $label   = Gtk2::Label->new($data);
218
        return $label;
219
}
220
 
221
sub def_label{
222
        my @data=@_;
223
        my $label   = Gtk2::Label->new(@data);
224
        $label->set_alignment( 0, 0.5 );
225
        return $label;
226
 
227
}
228
 
229
 
230
sub box_label{
231
        my( $homogeneous, $spacing, $name)=@_;
232
        my $box=def_hbox($homogeneous, $spacing);
233
        my $label= def_label($name);
234
        $box->pack_start( $label, FALSE, FALSE, 3);
235
        return $box;
236
}
237
 
238
 
239
sub def_title_box{
240
        my( $homogeneous, $spacing, @labels)=@_;
241
        my $box=def_hbox($homogeneous, $spacing);
242
        foreach my $label (@labels){
243
                my $labelbox=box_label($homogeneous, $spacing, $label);
244
                $box->pack_start( $labelbox, FALSE, FALSE, 3);
245
 
246
        }
247
        return $box;
248
}
249
 
250
 
251
sub gen_label_help {
252
        my ($help, $label_name)= @_;
253
        my $box = def_hbox(FALSE, 0);
254
        my $label= gen_label_in_left($label_name);
255
        my $button=def_image_button("icons/help.png");
256
 
257
        $button->signal_connect("clicked" => sub {message_dialog($help);});
258
 
259
        $box->pack_start( $label, FALSE, FALSE, 0);
260
        $box->pack_start( $button, FALSE, FALSE, 0);
261
        $box->set_spacing (0);
262
        $box->show_all;
263
 
264
        return $box;
265
 
266
 
267
}
268
 
269
 
270
 
271
 
272
##############
273
# button
274
#############
275
 
276
 
277
sub button_box{
278
# create a new button
279
        my @label=@_;
280
        my $button = Gtk2::Button->new_from_stock(@label);
281
        my $box=def_hbox(TRUE,5);
282
        $box->pack_start($button,   FALSE, FALSE,0);
283
 
284
        return ($box,$button);
285
 
286
}
287
 
288
 
289 34 alirezamon
sub def_icon{
290 16 alirezamon
        my $image_file=shift;
291 25 alirezamon
        my $font_size=get_defualt_font_size();
292 16 alirezamon
        my $size=($font_size==10)? 25:
293
                     ($font_size==9 )? 22:
294
                         ($font_size==8 )? 18:
295
                         ($font_size==7 )? 15:12 ;
296
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$size,$size,FALSE);
297
 
298
 
299
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
300
        return $image;
301
 
302
}
303
 
304
 
305 34 alirezamon
sub open_image{
306
        my ($image_file,$x,$y,$unit)=@_;
307
        if(defined $unit){
308
                my($width,$hight)=max_win_size();
309
                if($unit eq 'percent'){
310
                        $x= ($x * $width)/100;
311
                        $y= ($y * $hight)/100;
312
                } # else its pixels
313
 
314
        }
315
        my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($image_file,$x,$y,TRUE);
316
        my $image = Gtk2::Image->new_from_pixbuf($pixbuf);
317
        return $image;
318 16 alirezamon
 
319 34 alirezamon
}
320
 
321
 
322
 
323 16 alirezamon
sub def_image_button{
324 25 alirezamon
        my ($image_file, $label_text, $homogeneous)=@_;
325 16 alirezamon
        # create box for image and label 
326 25 alirezamon
        $homogeneous = FALSE if(!defined $homogeneous);
327
        my $box = def_hbox($homogeneous,0);
328 34 alirezamon
        my $image = def_icon($image_file) if(-f $image_file);
329 16 alirezamon
 
330
 
331
        # now on to the image stuff
332
        #my $image = Gtk2::Image->new_from_file($image_file);
333 34 alirezamon
        $box->pack_start($image, FALSE, FALSE, 0) if(-f $image_file);
334 16 alirezamon
        $box->set_border_width(0);
335
        $box->set_spacing (0);
336
        # Create a label for the button
337
        if(defined $label_text ) {
338
                my $label = Gtk2::Label->new("  $label_text");
339
                $box->pack_start($label, FALSE, FALSE, 0);
340
        }
341
 
342
 
343
        my $button = Gtk2::Button->new();
344
        $button->add($box);
345
        $button->set_border_width(0);
346
        $button->show_all;
347
        return $button;
348
 
349
}
350
 
351
 
352
sub def_image_label{
353
        my ($image_file, $label_text)=@_;
354
        # create box for image and label 
355
        my $box = def_hbox(FALSE,1);
356
        # now on to the image stuff
357 34 alirezamon
        my $image = def_icon($image_file);
358 16 alirezamon
        $box->pack_start($image, TRUE, FALSE, 0);
359
        # Create a label for the button
360
        if(defined $label_text ) {
361
                my $label = Gtk2::Label->new($label_text);
362
                $box->pack_start($label, TRUE, FALSE, 0);
363
        }
364
 
365
        return $box;
366
 
367
}
368
 
369
 
370
sub gen_button_message {
371
        my ($help, $image_file,$label_name)= @_;
372
        my $box = def_hbox(FALSE, 0);
373
        my $label= gen_label_in_center($label_name) if(defined $label_name);
374
        my $button=def_image_button($image_file);
375
 
376
        if(defined $help ){$button->signal_connect("clicked" => sub {message_dialog($help);});}
377
 
378
        $box->pack_start( $label, FALSE, FALSE, 0) if(defined $label_name);
379
        $box->pack_start( $button, FALSE, FALSE, 0);
380
        $box->set_border_width(0);
381
        $box->set_spacing (0);
382
        $box->show_all;
383
 
384
        return $box;
385
 
386
 
387
}
388
 
389
 
390
sub def_colored_button{
391
        my ($label_text,$color_num)=@_;
392
        # create box for image and label 
393
        my $box = def_hbox(FALSE,0);
394 25 alirezamon
        my $font_size=get_defualt_font_size();
395 16 alirezamon
        my $size=($font_size==10)? 25:
396
                     ($font_size==9 )? 22:
397
                         ($font_size==8 )? 18:
398
                         ($font_size==7 )? 15:12 ;
399
        $box->set_border_width(0);
400
        $box->set_spacing (0);
401
        # Create a label for the button
402
        if(defined $label_text ) {
403
                my $label = gen_label_in_center("$label_text");
404
                $box->pack_start($label, TRUE, TRUE, 0);
405
        }
406
        my @clr_code=get_color($color_num);
407
        my $color = Gtk2::Gdk::Color->new (@clr_code);
408
 
409
        my $button = Gtk2::Button->new();
410
        $button->modify_bg('normal',$color);
411
        $button->add($box);
412
        $button->set_border_width(0);
413
        $button->show_all;
414
        return $button;
415
 
416
}
417
 
418
 
419
 
420
 
421 25 alirezamon
sub show_gif{
422 16 alirezamon
 
423 25 alirezamon
        my $gif = shift;
424
        #my $mw=def_popwin_size(400,200,'hey');
425
        my $vbox = Gtk2::HBox->new (TRUE, 8);
426
    my $filename;
427
      eval {
428
##          $filename = demo_find_file ("floppybuddy.gif");
429
          $filename = main::demo_find_file ($gif);
430
      };
431
 
432
 
433
      my $image = Gtk2::Image->new_from_file ($gif);
434
 
435
     $vbox->set_border_width (4);
436
     my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
437
 
438
        my $frame = Gtk2::Frame->new;
439
        $frame->set_shadow_type ('in');
440 16 alirezamon
 
441 25 alirezamon
 
442
 
443
 
444
      # Animation
445
     $frame->add ($image);
446
      $align->add ($frame);
447 16 alirezamon
 
448 25 alirezamon
 
449
 
450
 
451
     $vbox->pack_start ($align, FALSE, FALSE, 0);
452
 
453
      # $mw->add ($vbox);
454
 
455
 
456
      # Progressive
457
 
458
 
459
 
460
 
461
        #$mw->show_all();
462
  return $vbox;
463
 
464
 
465
 
466
 
467
}
468
 
469 16 alirezamon
############
470
#       message_dialog
471
############
472
 
473
sub message_dialog {
474 34 alirezamon
  my ($message,$type)=@_;
475
  $type = 'info' if (!defined $type);
476 16 alirezamon
  my $window;
477
  my $dialog = Gtk2::MessageDialog->new ($window,
478
                                   [qw/modal destroy-with-parent/],
479 34 alirezamon
                                   $type,
480 16 alirezamon
                                   'ok',
481 34 alirezamon
                                    $message);
482 16 alirezamon
  $dialog->run;
483
  $dialog->destroy;
484
 
485
}
486
 
487
 
488
############
489
# window
490
###########
491
 
492
sub def_win {
493
        my @titel=shift;
494
        my $window = Gtk2::Window->new('toplevel');
495
        $window->set_title(@titel);
496
        $window->set_position("center");
497
        $window->set_default_size(100, 100);
498
        $window->set_border_width(20);
499
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
500
        return $window;
501
 
502
}
503
 
504
 
505
sub def_win_size {
506
        my $x=shift;
507
        my $y=shift;
508
        my @titel=shift;
509
        my $window = Gtk2::Window->new('toplevel');
510
        $window->set_title(@titel);
511
        $window->set_position("center");
512
        $window->set_default_size($x, $y);
513
        $window->set_border_width(20);
514
        $window->signal_connect (delete_event => sub { Gtk2->main_quit });
515
        return $window;
516
 
517
}
518
 
519
 
520
sub def_popwin_size {
521 34 alirezamon
        my ($x,$y,$titel,$unit)=@_;
522
        if(defined $unit){
523
                my($width,$hight)=max_win_size();
524
                if($unit eq 'percent'){
525
                        $x= ($x * $width)/100;
526
                        $y= ($y * $hight)/100;
527
                } # else its pixels
528
 
529
        }
530 16 alirezamon
        #my $window = Gtk2::Window->new('popup');
531
        my $window = Gtk2::Window->new('toplevel');
532 34 alirezamon
        $window->set_title($titel);
533 16 alirezamon
        $window->set_position("center");
534
        $window->set_default_size($x, $y);
535
        $window->set_border_width(20);
536
        $window->signal_connect (delete_event => sub { $window->destroy });
537
        return $window;
538
 
539
}
540
 
541
 
542 25 alirezamon
 
543
 
544
 
545 16 alirezamon
sub def_scrolled_window_box{
546
 
547
        my $window =  def_popwin_size(@_);
548
        my $box=def_vbox(TRUE,5);
549
        my $scrolled_window = new Gtk2::ScrolledWindow (undef, undef);
550
        $scrolled_window->set_policy( "automatic", "automatic" );
551
        $scrolled_window->add_with_viewport($box);
552
 
553
 
554
 
555
        $window->add($scrolled_window);
556
        $window->show_all;
557
        $box->show_all;
558
 
559
        return ($box,$window);
560
 
561
}
562
 
563
sub max_win_size{
564
        my $screen =Gtk2::Gdk::Screen->get_default();
565
        my $hight = $screen->get_height();
566
        my $width = $screen->get_width();
567
        return ($width,$hight);
568
}
569
 
570
 
571 25 alirezamon
sub get_defualt_font_size{
572 16 alirezamon
        my($width,$hight)=max_win_size();
573
        #print "($width,$hight)\n";
574
        my $font_size=($width>=1600)? 10:
575
                              ($width>=1400)? 9:
576 34 alirezamon
                                  ($width>=1200)? 9:
577 16 alirezamon
                                  ($width>=1000)? 7:6;
578 25 alirezamon
        #print "$font_size\n";  
579 16 alirezamon
        return $font_size;
580
}
581
 
582
 
583 25 alirezamon
sub set_defualt_font_size{
584
        my $font_size=get_defualt_font_size();
585
 
586 16 alirezamon
                Gtk2::Rc->parse_string(<<__);
587
                        style "normal" {
588 25 alirezamon
                                font_name ="Verdana $font_size"
589 16 alirezamon
                        }
590
                        widget "*" style "normal"
591
__
592
 
593
}
594
 
595
 
596
##############
597
#       box
598
#############
599
 
600
sub def_hbox {
601
        my( $homogeneous, $spacing)=@_;
602
        my $box = Gtk2::HBox->new($homogeneous, $spacing);
603
        $box->set_border_width(2);
604
        return $box;
605
}
606
 
607
sub def_vbox {
608
        my $box = Gtk2::VBox->new(FALSE, 0);
609
        $box->set_border_width(2);
610
        return $box;
611
}
612
 
613
sub def_pack_hbox{
614
        my( $homogeneous, $spacing , @box_list)=@_;
615
        my $box=def_hbox($homogeneous, $spacing);
616
        foreach my $subbox (@box_list){
617
                $box->pack_start( $subbox, FALSE, FALSE, 3);
618
        }
619
        return $box;
620
 
621
 
622
}
623
 
624 34 alirezamon
sub def_pack_vbox{
625
        my( $homogeneous, $spacing , @box_list)=@_;
626
        my $box=def_vbox($homogeneous, $spacing);
627
        foreach my $subbox (@box_list){
628
                $box->pack_start( $subbox, FALSE, FALSE, 3);
629
        }
630
        return $box;
631 16 alirezamon
 
632 34 alirezamon
}
633 16 alirezamon
 
634 34 alirezamon
 
635
##########
636
# Paned
637
#########
638
 
639
 
640
sub gen_vpaned {
641
        my ($w1,$loc,$w2) = @_;
642
        my $vpaned = Gtk2::VPaned -> new;
643
        my($width,$hight)=max_win_size();
644
 
645
 
646
        $vpaned -> pack1($w1, TRUE, TRUE);
647
        $vpaned -> set_position ($hight*$loc);
648
        $vpaned -> pack2($w2, TRUE, TRUE);
649
 
650
        return $vpaned;
651
}
652
 
653
 
654
sub gen_hpaned {
655
        my ($w1,$loc,$w2) = @_;
656
        my $hpaned = Gtk2::HPaned -> new;
657
        my($width,$hight)=max_win_size();
658
 
659
 
660
        $hpaned -> pack1($w1, TRUE, TRUE);
661
        $hpaned -> set_position ($width*$loc);
662
        $hpaned -> pack2($w2, TRUE, TRUE);
663
 
664
        return $hpaned;
665
}
666
 
667 16 alirezamon
#############
668
# text_view 
669
############
670
 
671
sub create_text {
672
  my $scrolled_window = Gtk2::ScrolledWindow->new;
673
  $scrolled_window->set_policy ('automatic', 'automatic');
674
  $scrolled_window->set_shadow_type ('in');
675
  my $tview = Gtk2::TextView->new();
676
  $scrolled_window->add ($tview);
677
  $tview->show_all;
678
  # Make it a bit nicer for text.
679
  $tview->set_wrap_mode ('word');
680
  $tview->set_pixels_above_lines (2);
681
  $tview->set_pixels_below_lines (2);
682
  return ($scrolled_window,$tview);
683
}
684
 
685
 
686
#################
687
#       table
688
################
689
 
690
sub def_table{
691
        my ($row,$col,$homogeneous)=@_;
692
        my $table = Gtk2::Table->new ($row, $col, $homogeneous);
693
        $table->set_row_spacings (0);
694
        $table->set_col_spacings (0);
695
        return $table;
696
 
697
}
698
 
699
 
700
 
701
 
702
 
703
 
704
######
705
#  state
706
#####
707
 
708
sub def_state{
709
        my ($initial)=@_;
710
        my $entry = Gtk2::Entry->new;
711
        $entry->set_text($initial);
712
        my $timeout=0;
713
        my @state= ($entry,$timeout);
714
        return \@state
715
 
716
}
717
 
718 25 alirezamon
 
719
 
720
 
721
 
722
sub set_gui_status{
723
        my ($object,$status,$timeout)=@_;
724
        $object->object_add_attribute('gui_status','status',$status);
725
        $object->object_add_attribute('gui_status','timeout',$timeout);
726 16 alirezamon
}
727
 
728
 
729 25 alirezamon
sub get_gui_status{
730
        my ($object)=@_;
731
        my $status= $object->object_get_attribute('gui_status','status');
732
        my $timeout=$object->object_get_attribute('gui_status','timeout');
733
        return ($status,$timeout);
734 16 alirezamon
}
735
 
736
 
737
 
738
##################
739
#       show_info
740
##################
741
sub show_info{
742
        my ($textview_ref,$info)=@_;
743
        my $buffer = $$textview_ref->get_buffer();
744
        $buffer->set_text($info);
745
}
746
 
747 25 alirezamon
sub add_info{
748
        my ($textview_ref,$info)=@_;
749
        my $buffer = $$textview_ref->get_buffer();
750
        my $textiter = $buffer->get_end_iter();
751
        #Insert some text into the buffer
752
        $buffer->insert($textiter,$info);
753
 
754
}
755 16 alirezamon
 
756 34 alirezamon
sub show_colored_info{
757
        my ($textview_ref,$info,$color)=@_;
758
        my $buffer = $$textview_ref->get_buffer();
759
        #$buffer->set_text($info);
760
        my $textiter = $buffer->get_start_iter();
761
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
762
}
763 16 alirezamon
 
764 34 alirezamon
sub add_colored_info{
765
        my ($textview_ref,$info,$color)=@_;
766
        my $buffer = $$textview_ref->get_buffer();
767
        my $textiter = $buffer->get_end_iter();
768
        #Insert some text into the buffer
769
        #$buffer->insert($textiter,$info);
770
        $buffer->insert_with_tags_by_name ($textiter, "$info", "${color}_tag");
771
 
772
}
773 25 alirezamon
 
774 34 alirezamon
sub add_colored_tag{
775
        my ($textview_ref,$color)=@_;
776
        my $buffer = $textview_ref->get_buffer();
777
        $buffer->create_tag ("${color}_tag", foreground => $color);
778
}
779
 
780
 
781
 
782 16 alirezamon
####################
783 34 alirezamon
#        file
784 16 alirezamon
##################
785
 
786
 
787 34 alirezamon
sub read_verilog_file{
788 16 alirezamon
        my @files            = @_;
789
        my %cmd_line_defines = ();
790
        my $quiet            = 1;
791
        my @inc_dirs         = ();
792
        my @lib_dirs         = ();
793
        my @lib_exts         = ();
794
        my $vdb = rvp->read_verilog(\@files,[],\%cmd_line_defines,
795
                          $quiet,\@inc_dirs,\@lib_dirs,\@lib_exts);
796
 
797
        my @problems = $vdb->get_problems();
798
        if (@problems) {
799
            foreach my $problem ($vdb->get_problems()) {
800
                print STDERR "$problem.\n";
801
            }
802
            # die "Warnings parsing files!";
803
        }
804
 
805
        return $vdb;
806
}
807
 
808 25 alirezamon
sub add_color_to_gd{
809
        foreach (my $i=0;$i<32;$i++ ) {
810 34 alirezamon
                my ($red,$green,$blue)=get_color($i);
811
                add_colour("my_color$i"=>[$red>>8,$green>>8,$blue>>8]);
812 25 alirezamon
 
813 34 alirezamon
        }
814
}
815
 
816
 
817
 
818
sub append_text_to_file {
819
        my  ($file_path,$text)=@_;
820
        open(my $fd, ">>$file_path");
821
        print $fd $text;
822
        close $fd;
823
}
824
 
825
 
826
 
827
 
828
sub save_file {
829
        my  ($file_path,$text)=@_;
830
        open(my $fd, ">$file_path");
831
        print $fd $text;
832
        close $fd;
833
}
834
 
835
sub load_file {
836
        my $file_path=shift;
837
        my $str;
838
        if (-f "$file_path") {
839
 
840
                $str = do {
841
                        local $/ = undef;
842
                        open my $fh, "<", $file_path
843
                        or die "could not open $file_path: $!";
844
                        <$fh>;
845
                };
846
 
847 25 alirezamon
        }
848 34 alirezamon
        return $str;
849 25 alirezamon
}
850 16 alirezamon
 
851 25 alirezamon
 
852 34 alirezamon
 
853
 
854
sub merg_files {
855
        my  ($source_file_path,$dest_file_path)=@_;
856
        local $/=undef;
857
        open FILE, $source_file_path or die "Couldn't open file: $!";
858
        my $string = <FILE>;
859
        close FILE;
860
         append_text_to_file ($dest_file_path,$string);
861
}
862
 
863
 
864
 
865
sub copy_file_and_folders{
866
        my ($file_ref,$project_dir,$target_dir)=@_;
867
 
868
        foreach my $f(@{$file_ref}){
869
                my $name= basename($f);
870
                my $n="$project_dir$f";
871
                if (-f "$n") { #copy file
872
                        copy ("$n","$target_dir");
873
                }elsif(-f "$f" ){
874
                        copy ("$f","$target_dir");
875
                }elsif (-d "$n") {#copy folder
876
                        dircopy ("$n","$target_dir/$name");
877
                }elsif(-d "$f" ){
878
                        dircopy ("$f","$target_dir/$name");
879
 
880
                }
881
        }
882
 
883
}
884
 
885
sub read_file_cntent {
886
        my ($f,$project_dir)=@_;
887
        my $n="$project_dir$f";
888
        my $str;
889
        if (-f "$n") {
890
 
891
                $str = do {
892
                        local $/ = undef;
893
                        open my $fh, "<", $n
894
                        or die "could not open $n: $!";
895
                        <$fh>;
896
                };
897
 
898
        }elsif(-f "$f" ){
899
                $str = do {
900
                        local $/ = undef;
901
                        open my $fh, "<", $f
902
                        or die "could not open $f: $!";
903
                        <$fh>;
904
                };
905
 
906
 
907
        }
908
        return $str;
909
 
910
}
911
 
912
 
913
sub check_file_has_string {
914
    my ($file,$string)=@_;
915
    my $r;
916
    open(FILE,$file);
917
    if (grep{/$string/} <FILE>){
918
       $r= 1; #print "word  found\n";
919
    }else{
920
       $r= 0; #print "word not found\n";
921
    }
922
    close FILE;
923
    return $r;
924
}
925
 
926
 
927
###########
928
#  color
929
#########
930
 
931
 
932
 
933
 
934
 
935 25 alirezamon
 
936 16 alirezamon
sub get_color {
937
        my $num=shift;
938
 
939
        my @colors=(
940
        0x6495ED,#Cornflower Blue
941
        0xFAEBD7,#Antiquewhite
942
        0xC71585,#Violet Red
943 25 alirezamon
        0xC0C0C0,#silver
944 16 alirezamon
        0xADD8E6,#Lightblue     
945
        0x6A5ACD,#Slate Blue
946
        0x00CED1,#Dark Turquoise
947
        0x008080,#Teal
948
        0x2E8B57,#SeaGreen
949
        0xFFB6C1,#Light Pink
950
        0x008000,#Green
951
        0xFF0000,#red
952
        0x808080,#Gray
953
        0x808000,#Olive
954
        0xFF69B4,#Hot Pink
955
        0xFFD700,#Gold
956
        0xDAA520,#Goldenrod
957
        0xFFA500,#Orange
958
        0x32CD32,#LimeGreen
959
        0x0000FF,#Blue
960
        0xFF8C00,#DarkOrange
961
        0xA0522D,#Sienna
962
        0xFF6347,#Tomato
963
        0x0000CD,#Medium Blue
964
        0xFF4500,#OrangeRed
965
        0xDC143C,#Crimson       
966
        0x9932CC,#Dark Orchid
967
        0x800000,#marron
968
        0x800080,#Purple
969
        0x4B0082,#Indigo
970 25 alirezamon
        0xFFFFFF,#white 
971
        0x000000 #Black         
972 16 alirezamon
                );
973
 
974
        my $color=      ($num< scalar (@colors))? $colors[$num]: 0xFFFFFF;
975
        my $red=        ($color & 0xFF0000) >> 8;
976
        my $green=      ($color & 0x00FF00);
977
        my $blue=       ($color & 0x0000FF) << 8;
978
 
979
        return ($red,$green,$blue);
980
 
981
}
982
 
983
 
984 34 alirezamon
sub get_color_hex_string {
985
        my $num=shift;
986
 
987
        my @colors=(
988
        "6495ED",#Cornflower Blue
989
        "FAEBD7",#Antiquewhite
990
        "C71585",#Violet Red
991
        "C0C0C0",#silver
992
        "ADD8E6",#Lightblue     
993
        "6A5ACD",#Slate Blue
994
        "00CED1",#Dark Turquoise
995
        "008080",#Teal
996
        "2E8B57",#SeaGreen
997
        "FFB6C1",#Light Pink
998
        "008000",#Green
999
        "FF0000",#red
1000
        "808080",#Gray
1001
        "808000",#Olive
1002
        "FF69B4",#Hot Pink
1003
        "FFD700",#Gold
1004
        "DAA520",#Goldenrod
1005
        "FFA500",#Orange
1006
        "32CD32",#LimeGreen
1007
        "0000FF",#Blue
1008
        "FF8C00",#DarkOrange
1009
        "A0522D",#Sienna
1010
        "FF6347",#Tomato
1011
        "0000CD",#Medium Blue
1012
        "FF4500",#OrangeRed
1013
        "DC143C",#Crimson       
1014
        "9932CC",#Dark Orchid
1015
        "800000",#marron
1016
        "800080",#Purple
1017
        "4B0082",#Indigo
1018
        "FFFFFF",#white 
1019
        "000000" #Black         
1020
                );
1021
 
1022
        my $color=      ($num< scalar (@colors))? $colors[$num]: "FFFFFF";
1023
        return $color;
1024
 
1025
}
1026 16 alirezamon
 
1027
 
1028 34 alirezamon
 
1029 16 alirezamon
##############
1030
#  clone_obj
1031
#############
1032
 
1033
sub clone_obj{
1034
        my ($self,$clone)=@_;
1035
 
1036
        foreach my $p (keys %$self){
1037
                delete ($self->{$p});
1038
        }
1039
        foreach my $p (keys %$clone){
1040
                $self->{$p}= $clone->{$p};
1041
                my $ref= ref ($clone->{$p});
1042
                if( $ref eq 'HASH' ){
1043
 
1044
                        foreach my $q (keys %{$clone->{$p}}){
1045
                                $self->{$p}{$q}= $clone->{$p}{$q};
1046
                                my $ref= ref ($self->{$p}{$q});
1047
                                if( $ref eq 'HASH' ){
1048
 
1049
                                        foreach my $z (keys %{$clone->{$p}{$q}}){
1050
                                                $self->{$p}{$q}{$z}= $clone->{$p}{$q}{$z};
1051
                                                my $ref= ref ($self->{$p}{$q}{$z});
1052
                                                if( $ref eq 'HASH' ){
1053
 
1054
                                                        foreach my $w (keys %{$clone->{$p}{$q}{$q}}){
1055
                                                                $self->{$p}{$q}{$z}{$w}= $clone->{$p}{$q}{$z}{$w};
1056
                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w});
1057
                                                                if( $ref eq 'HASH' ){
1058
 
1059
 
1060
                                                                        foreach my $m (keys %{$clone->{$p}{$q}{$q}{$w}}){
1061
                                                                                $self->{$p}{$q}{$z}{$w}{$m}= $clone->{$p}{$q}{$z}{$w}{$m};
1062
                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m});
1063
                                                                                if( $ref eq 'HASH' ){
1064
 
1065
                                                                                        foreach my $n (keys %{$clone->{$p}{$q}{$q}{$w}{$m}}){
1066
                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}= $clone->{$p}{$q}{$z}{$w}{$m}{$n};
1067
                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n});
1068
                                                                                                if( $ref eq 'HASH' ){
1069
 
1070
                                                                                                        foreach my $l (keys %{$clone->{$p}{$q}{$q}{$w}{$m}{$n}}){
1071
                                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}{$l}= $clone->{$p}{$q}{$z}{$w}{$m}{$n}{$l};
1072
                                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n}{$l});
1073
                                                                                                                if( $ref eq 'HASH' ){
1074
                                                                                                                }
1075
                                                                                                        }
1076
 
1077
                                                                                                }#if                                                                                                            
1078
                                                                                        }#n
1079
                                                                                }#if
1080
                                                                        }#m                                                     
1081
                                                                }#if
1082
                                                        }#w
1083
                                                }#if
1084
                                        }#z
1085
                                }#if
1086
                        }#q
1087
                }#if    
1088
        }#p
1089
}#sub   
1090
 
1091
 
1092 25 alirezamon
############
1093
#       get file folder list
1094
###########
1095
 
1096
sub get_directory_name {
1097
        my ($object,$title,$entry,$attribute1,$attribute2,$status,$timeout)= @_;
1098
        my $browse= def_image_button("icons/browse.png");
1099
 
1100
        $browse->signal_connect("clicked"=> sub{
1101
                my $entry_ref=$_[1];
1102
                my $file;
1103
                $title ='select directory' if(!defined $title);
1104
                my $dialog = Gtk2::FileChooserDialog->new(
1105
                        $title, undef,
1106
                        #               'open',
1107
                        'select-folder',
1108
                        'gtk-cancel' => 'cancel',
1109
                        'gtk-ok'     => 'ok',
1110
                        );
1111
 
1112
 
1113
                        if ( "ok" eq $dialog->run ) {
1114
                        $file = $dialog->get_filename;
1115
                                $$entry_ref->set_text($file);
1116
                                $object->object_add_attribute($attribute1,$attribute2,$file);
1117
                                set_gui_status($object,$status,$timeout) if(defined $status);
1118
                                #check_input_file($file,$socgen,$soc_state,$info);
1119
                                #print "file = $file\n";
1120
                         }
1121
                        $dialog->destroy;
1122
 
1123
 
1124
 
1125
                } , \$entry);
1126
 
1127
        return $browse;
1128
 
1129
}
1130
 
1131
 
1132
sub get_file_name {
1133
        my ($object,$title,$entry,$attribute1,$attribute2,$extension,$lable,$open_in)= @_;
1134
        my $browse= def_image_button("icons/browse.png");
1135 34 alirezamon
        my $dir = Cwd::getcwd();
1136
        my $project_dir   = abs_path("$dir/../../"); #mpsoc directory address
1137 25 alirezamon
 
1138
        $browse->signal_connect("clicked"=> sub{
1139
                my $entry_ref=$_[1];
1140
                my $file;
1141
                $title ='select directory' if(!defined $title);
1142
                my $dialog = Gtk2::FileChooserDialog->new(
1143
                'Select a File', undef,
1144
                'open',
1145
                'gtk-cancel' => 'cancel',
1146
                'gtk-ok'     => 'ok',
1147
                );
1148
         if(defined $extension){
1149
                my $filter = Gtk2::FileFilter->new();
1150
                $filter->set_name($extension);
1151
                $filter->add_pattern("*.$extension");
1152
                $dialog->add_filter ($filter);
1153
         }
1154
          if(defined  $open_in){
1155
                $dialog->set_current_folder ($open_in);
1156
                # print "$open_in\n";
1157
 
1158
        }
1159
 
1160
                        if ( "ok" eq $dialog->run ) {
1161 34 alirezamon
                                $file = $dialog->get_filename;
1162
                                #remove $project_dir form beginig of each file
1163
                                $file =~ s/$project_dir//;
1164 25 alirezamon
                                $$entry_ref->set_text($file);
1165 34 alirezamon
                                $object->object_add_attribute($attribute1,$attribute2,$file) if(defined $object);
1166 25 alirezamon
                                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1167 34 alirezamon
                                if(defined $lable){
1168
                                        $lable->set_markup("<span  foreground= 'black' ><b>$name$suffix</b></span>");
1169
                                        $lable->show;
1170
                                }
1171 25 alirezamon
 
1172
                                #check_input_file($file,$socgen,$soc_state,$info);
1173
                                #print "file = $file\n";
1174
                         }
1175
                        $dialog->destroy;
1176
 
1177
 
1178
 
1179
                } , \$entry);
1180
 
1181
        return $browse;
1182
 
1183
}
1184
 
1185
 
1186
#################
1187
#       widget update object
1188
#################
1189
 
1190
sub gen_entry_object {
1191
        my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
1192
        my $old=$object->object_get_attribute($attribute1,$attribute2);
1193
        my $widget;
1194
        if(defined $old ){
1195
                $widget=gen_entry($old);
1196
        }
1197
        else
1198
        {
1199
                $widget=gen_entry($default);
1200
                $object->object_add_attribute($attribute1,$attribute2,$default);
1201
        }
1202
        $widget-> signal_connect("changed" => sub{
1203
                my $new_param_value=$widget->get_text();
1204
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1205
                set_gui_status($object,$status,$timeout) if (defined $status);
1206
        });
1207
        return $widget;
1208
}
1209
 
1210
 
1211
sub gen_combobox_object {
1212
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1213
        my @combo_list=split(",",$content);
1214
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1215
        my $pos;
1216
        $pos=get_pos($value, @combo_list) if (defined $value);
1217
        if(!defined $pos && defined $default){
1218
                $object->object_add_attribute($attribute1,$attribute2,$default);
1219
                $pos=get_item_pos($default, @combo_list);
1220
        }
1221
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1222
        my $widget=gen_combo(\@combo_list, $pos);
1223
        $widget-> signal_connect("changed" => sub{
1224
                my $new_param_value=$widget->get_active_text();
1225
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1226
                set_gui_status($object,$status,$timeout) if (defined $status);
1227
         });
1228
        return $widget;
1229
 
1230
 
1231
}
1232
 
1233
 
1234
sub gen_comboentry_object {
1235
        my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1236
        my @combo_list=split(",",$content);
1237
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1238
        my $pos;
1239
        $pos=get_pos($value, @combo_list) if (defined $value);
1240
        if(!defined $pos && defined $default){
1241
                $object->object_add_attribute($attribute1,$attribute2,$default);
1242
                $pos=get_item_pos($default, @combo_list);
1243
        }
1244
        #print " my $pos=get_item_pos($value, @combo_list);\n";
1245
        my $widget=gen_combo_entry(\@combo_list, $pos);
1246
        ($widget->child)->signal_connect('changed' => sub {
1247
                my ($entry) = @_;
1248
                my $new_param_value=$entry->get_text();
1249
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1250
                set_gui_status($object,$status,$timeout) if (defined $status);
1251
         });
1252
        return $widget;
1253
 
1254
}
1255
 
1256
 
1257
 
1258
sub gen_spin_object {
1259
        my ($object,$attribute1,$attribute2,$content, $default,$status,$timeout)=@_;
1260
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1261
        my ($min,$max,$step)=split(",",$content);
1262
        if(!defined $value){
1263
                $value=$default;
1264
                $object->object_add_attribute($attribute1,$attribute2,$value);
1265
        }
1266
        $value=~ s/\D//g;
1267
        $min=~ s/\D//g;
1268
        $max=~ s/\D//g;
1269
        $step=~ s/\D//g;
1270
        my $widget=gen_spin($min,$max,$step);
1271
        $widget->set_value($value);
1272
        $widget-> signal_connect("value_changed" => sub{
1273
                my $new_param_value=$widget->get_value_as_int();
1274
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1275
                set_gui_status($object,$status,$timeout) if (defined $status);
1276
        });
1277
        return $widget;
1278
}
1279
 
1280
 
1281 34 alirezamon
sub gen_check_box_object_array {
1282
                my ($object,$attribute1,$attribute2,$content,$default,$status,$timeout)=@_;
1283
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1284
                $value = $default if (!defined $value);
1285 25 alirezamon
                my $widget = def_hbox(FALSE,0);
1286
                my @check;
1287
                for (my $i=0;$i<$content;$i++){
1288
                        $check[$i]= Gtk2::CheckButton->new;
1289
                }
1290
                for (my $i=0;$i<$content;$i++){
1291
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1292
 
1293
                        my @chars = split("",$value);
1294
                        #check if saved value match the size of check box
1295
                        if($chars[0] ne $content ) {
1296
                                $object->object_add_attribute($attribute1,$attribute2,$default);
1297
                                $value=$default;
1298
                                @chars = split("",$value);
1299
                        }
1300
                        #set initial value
1301
 
1302
                        #print "\@chars=@chars\n";
1303
                        for (my $i=0;$i<$content;$i++){
1304
                                my $loc= (scalar @chars) -($i+1);
1305
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1306
                                        else {$check[$i]->set_active(FALSE);}
1307
                        }
1308
 
1309
 
1310
                        #get new value
1311
                        $check[$i]-> signal_connect("toggled" => sub{
1312
                                my $new_val="$content\'b";
1313
 
1314
                                for (my $i=$content-1; $i >= 0; $i--){
1315
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1316
                                        else {$new_val="${new_val}0" ;}
1317
                                }
1318
                                $object->object_add_attribute($attribute1,$attribute2,$new_val);
1319
                                #print "\$new_val=$new_val\n";
1320
                                set_gui_status($object,$status,$timeout) if (defined $status);
1321
                        });
1322
        }
1323
        return $widget;
1324
 
1325
}
1326
 
1327
 
1328
 
1329 34 alirezamon
 
1330
 
1331
sub gen_check_box_object {
1332
                my ($object,$attribute1,$attribute2,$default,$status,$timeout)=@_;
1333
                my $value=$object->object_get_attribute($attribute1,$attribute2);
1334
                if (!defined $value){
1335
                        #set initial value
1336
                        $object->object_add_attribute($attribute1,$attribute2,$default);
1337
                        $value = $default
1338
                }
1339
                my $widget = Gtk2::CheckButton->new;
1340
                if($value == 1) {$widget->set_active(TRUE);}
1341
                else {$widget->set_active(FALSE);}
1342
 
1343
                #get new value
1344
                $widget-> signal_connect("toggled" => sub{
1345
                        my $new_val;
1346
                        if($widget->get_active()) {$new_val=1;}
1347
                        else {$new_val=0;}
1348
                        $object->object_add_attribute($attribute1,$attribute2,$new_val);
1349
                        #print "\$new_val=$new_val\n";
1350
                        set_gui_status($object,$status,$timeout) if (defined $status);
1351
                });
1352
 
1353
        return $widget;
1354
 
1355
}
1356
 
1357
 
1358
 
1359
 
1360
 
1361
 
1362 25 alirezamon
sub get_dir_in_object {
1363
        my ($object,$attribute1,$attribute2,$content,$status,$timeout)=@_;
1364
        my $widget = def_hbox(FALSE,0);
1365
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1366
        my $entry=gen_entry($value);
1367
        $entry-> signal_connect("changed" => sub{
1368
                my $new_param_value=$entry->get_text();
1369
                $object->object_add_attribute($attribute1,$attribute2,$new_param_value);
1370
                set_gui_status($object,$status,$timeout) if (defined $status);
1371
        });
1372
        my $browse= get_directory_name($object,undef,$entry,$attribute1,$attribute2,$status,$timeout);
1373
        $widget->pack_start( $entry, FALSE, FALSE, 0);
1374
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1375
        return $widget;
1376
}
1377
 
1378
 
1379
 
1380
 
1381
sub get_file_name_object {
1382
        my ($object,$attribute1,$attribute2,$extension,$open_in)=@_;
1383
        my $widget = def_hbox(FALSE,0);
1384
        my $value=$object->object_get_attribute($attribute1,$attribute2);
1385
        my $lable;
1386
        if(defined $value){
1387
                my ($name,$path,$suffix) = fileparse("$value",qr"\..[^.]*$");
1388
                $lable=gen_label_in_center($name.$suffix);
1389
 
1390
        } else {
1391 34 alirezamon
                        $lable=gen_label_in_center("Selecet a file");
1392 32 alirezamon
                        $lable->set_markup("<span  foreground= 'red' ><b>No file has been selected yet</b></span>");
1393 25 alirezamon
        }
1394
        my $entry=gen_entry();
1395
        my $browse= get_file_name($object,undef,$entry,$attribute1,$attribute2,$extension,$lable,$open_in);
1396
        $widget->pack_start( $lable, FALSE, FALSE, 0);
1397
        $widget->pack_start( $browse, FALSE, FALSE, 0);
1398
        return $widget;
1399
}
1400
 
1401 16 alirezamon
################
1402 25 alirezamon
# ADD info and label to widget
1403
################
1404
 
1405
 
1406
sub labele_widget_info{
1407
        my ($label_name,$widget,$info)=@_;
1408
        my $box = def_hbox(FALSE,0);
1409
        #label
1410
        if(defined $label_name){
1411
                my $label= gen_label_in_left($label_name);
1412
                $box->pack_start( $label, FALSE, FALSE, 3);
1413
        }
1414
        $box->pack_start( $widget, FALSE, FALSE, 3);
1415
        #info   
1416
        if(defined $info){
1417
                my $button=def_image_button("icons/help.png");
1418
                $button->signal_connect("clicked" => sub {message_dialog($info);});
1419
                $box->pack_start( $button, FALSE, FALSE, 3);
1420
        }
1421
        $box->show_all;
1422
        return $box;
1423
}
1424
 
1425
 
1426
 
1427
 
1428
################
1429 16 alirezamon
#       general
1430
#################
1431
 
1432
 
1433
 
1434
 
1435
sub  trim { my $s = shift;  $s=~s/[\n]//gs; return $s };
1436
 
1437
sub remove_all_white_spaces($)
1438
{
1439
  my $string = shift;
1440
  $string =~ s/\s+//g;
1441
  return $string;
1442
}
1443
 
1444
 
1445
 
1446
 
1447
sub get_scolar_pos{
1448
        my ($item,@list)=@_;
1449
        my $pos;
1450
        my $i=0;
1451
        foreach my $c (@list)
1452
        {
1453
                if(  $c eq $item) {$pos=$i}
1454
                $i++;
1455
        }
1456
        return $pos;
1457
}
1458
 
1459
sub remove_scolar_from_array{
1460
        my ($array_ref,$item)=@_;
1461
        my @array=@{$array_ref};
1462
        my @new;
1463
        foreach my $p (@array){
1464
                if($p ne $item ){
1465
                        push(@new,$p);
1466
                }
1467
        }
1468
        return @new;
1469
}
1470
 
1471
sub replace_in_array{
1472
        my ($array_ref,$item1,$item2)=@_;
1473
        my @array=@{$array_ref};
1474
        my @new;
1475
        foreach my $p (@array){
1476
                if($p eq $item1 ){
1477
                        push(@new,$item2);
1478
                }else{
1479
                        push(@new,$p);
1480
                }
1481
        }
1482
        return @new;
1483
}
1484
 
1485
 
1486
 
1487
# return an array of common elemnts between two input arays 
1488
sub get_common_array{
1489
        my ($a_ref,$b_ref)=@_;
1490
        my @A=@{$a_ref};
1491
        my @B=@{$b_ref};
1492
        my @C;
1493
        foreach my $p (@A){
1494
                if( grep (/^$p$/,@B)){push(@C,$p)};
1495
        }
1496
        return  @C;
1497
}
1498
 
1499
#a-b
1500
sub get_diff_array{
1501
        my ($a_ref,$b_ref)=@_;
1502
        my @A=@{$a_ref};
1503
        my @B=@{$b_ref};
1504
        my @C;
1505
        foreach my $p (@A){
1506
                if( !grep (/^$p$/,@B)){push(@C,$p)};
1507
        }
1508
        return  @C;
1509
 
1510
}
1511
 
1512
 
1513
 
1514
sub compress_nums{
1515
        my      @nums=@_;
1516
        my @f=sort { $a <=> $b } @nums;
1517
        my $s;
1518
        my $ls;
1519
        my $range=0;
1520
        my $x;
1521
 
1522
 
1523
        foreach my $p (@f){
1524
                if(!defined $x) {
1525
                        $s="$p";
1526
                        $ls=$p;
1527
 
1528
                }
1529
                else{
1530
                        if($p-$x>1){ #gap exist
1531
                                if( $range){
1532
                                        $s=($x-$ls>1 )? "$s:$x,$p": "$s,$x,$p";
1533
                                        $ls=$p;
1534
                                        $range=0;
1535
                                }else{
1536
                                $s= "$s,$p";
1537
                                $ls=$p;
1538
 
1539
                                }
1540
 
1541
                        }else {$range=1;}
1542
 
1543
 
1544
 
1545
                }
1546
 
1547
                $x=$p
1548
        }
1549
        if($range==1){ $s= ($x-$ls>1 )? "$s:$x":  "$s,$x";}
1550
        #update $s($ls,$hs);
1551
 
1552
        return $s;
1553
 
1554
}
1555
 
1556
 
1557 24 alirezamon
 
1558
sub metric_conversion{
1559
        my $size=shift;
1560
        my $size_text=  $size==0  ? 'Error':
1561
                        $size<(1 << 10)? $size:
1562
                        $size<(1 << 20)? join (' ', ($size>>10,"K")) :
1563
                        $size<(1 << 30)? join (' ', ($size>>20,"M")) :
1564
                                         join (' ', ($size>>30,"G")) ;
1565
return $size_text;
1566
}
1567
 
1568 34 alirezamon
 
1569
 
1570
sub check_verilog_identifier_syntax {
1571
        my $in=shift;
1572
        my $error=0;
1573
        my $message='';
1574
# an Identifiers must begin with an alphabetic character or the underscore character
1575
        if ($in =~ /^[0-9\$]/){
1576
                return 'an Identifier must begin with an alphabetic character or the underscore character';
1577
        }
1578
 
1579
 
1580
#       Identifiers may contain alphabetic characters, numeric characters, the underscore, and the dollar sign (a-z A-Z 0-9 _ $ )
1581
        if ($in =~ /[^a-zA-Z0-9_\$]+/){
1582
                 print "use of illegal character after\n" ;
1583
                 my @w= split /([^a-zA-Z0-9_\$]+)/, $in;
1584
                 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";
1585
 
1586
        }
1587
 
1588
 
1589
# check Verilog reserved words
1590
        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");
1591
        if( grep (/^$in$/,@keys)){
1592
                return  "$in is a Verlig reserved word.";
1593
        }
1594
        return undef;
1595
 
1596
}
1597
 
1598
 
1599
 
1600
 
1601
 
1602 16 alirezamon
1

powered by: WebSVN 2.1.0

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