Commit 1dc04233 authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

fiji_setup can now be configured to use Menubar, Control Frame, or both

parent b0f60d82
......@@ -15,11 +15,9 @@
#
# Description:
#
# FIJI Netlist class
# FIJI Netlist class: Functions to instrument & export a Verilog::Netlist
#-------------------------------------------------------------------------------
## @file
## @class FIJI::Netlist
......@@ -521,6 +519,7 @@ sub _select_driver($$) {
}
# prints the type of a connection
# and optionally pushes a hash {path=>...,type=>...,} onto the list @$conn_str_list_ref
#
# params
# connection the connection to print
......@@ -543,7 +542,7 @@ sub _connection_tostr($;$) {
$path = $connection->module->name;
$type = "ASSIGN";
}
push @{$conn_str_list_ref}, {path=>$path.$HIERSEP.$name,type=>$type};
push @{$conn_str_list_ref}, {path=>$path.$HIERSEP.$name,type=>$type} if defined $conn_str_list_ref;
return $type.": ".$path.$HIERSEP.$name;
}
......@@ -853,6 +852,11 @@ sub _export_module($) {
return $module_header."\n".$net_declarations."\n".$assigns."\n".$instantiations.$module_footer;
}
## @method splitnet($netpath)
# splits a hierarchical path of a net in the form of module1|module2|netname
# to the net object corresponding to "netname" in module "module2"
#
sub splitnet ($) {
my $logger = get_logger();
my ($self,$netpath) = @_;
......
......@@ -868,7 +868,7 @@ sub make_random_test {
# randomly generate a test pattern
# depending on
# PROB_xxx
# thank you http://www.perlmonks.org/?node_id=22094
# based on http://www.perlmonks.org/?node_id=22094
sub choose_random_fault {
my ($self) = @_;
my ($mark,$fault) = (0,undef);
......
......@@ -34,6 +34,12 @@ use Data::Dumper;
use FIJI::Settings;
use Tk::FIJISettingsViewer;
# 0 => classic, no menu GUI
# 1 => toplevel menu
# 2 => classic+menu GUI
use constant USE_MENU => 1;
use constant FILE_TYPES_CFG => [
['FIJI Configurations', ['.cfg', '*.ini']],
['All files' , '*' ],
......@@ -100,7 +106,16 @@ sub main {
);
$self->{'mw'} = $mw;
$self->{'ctrl'} = _ctrl_frame($self, $mw);
$self->{'menu'} = _menu($self,$mw);
if(!defined USE_MENU || USE_MENU == 1) {
$self->{'menu'} = $self->_menu($mw);
}
$mw->toplevel()->bind('<Control-o>' => sub { $self->_open_settings_file; });
$mw->toplevel()->bind('<Control-Shift-O>' => sub { $self->_open_netlist_file; });
$mw->toplevel()->bind("<Control-s>" => sub { $self->_save; });
$mw->toplevel()->bind("<Control-Shift-S>" => sub { $self->_save_as; });
$mw->toplevel()->bind("<F1>" => sub { $self->_show_documentation; });
$self->{'documentation_path'} = File::Spec->catpath($vol,$libdir,'fiji.pdf');
......@@ -191,45 +206,7 @@ sub _menu {
-label => 'Open',
-accelerator => 'Ctrl-o',
-underline => 0,
-command => sub {
my $logger = get_logger();
my $filename = $mw->FBox(
-type => 'open',
-title => 'Open FIJI Configuration file',
-filetypes => FILE_TYPES_CFG,
-initialdir => '.',
-initialfile => 'fiji.cfg'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open configuration action");
return;
}
my $tmp_settings = \%{ Clone::clone ($self->{'settings'}) };
$tmp_settings = FIJI::Settings->new('setup', $filename, $tmp_settings);
if (!ref($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
$mw->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
}
my $rv = $self->{'FIJISettingsViewer'}->settings($tmp_settings);
if (!defined($rv)) {
my $msg = "Could not update GUI correctly with new settings.";
$logger->error($msg);
$mw->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
} elsif (ref($rv) eq "FIJI::Settings") {
$self->{'settings'} = $tmp_settings;
${$self->{'ini_name'}} = $filename;
}
},
-command => [\&_open_settings_file, $self],
);
$file->separator;
$file->command(
......@@ -257,77 +234,14 @@ sub _menu {
-label => 'Load',
-accelerator => 'Ctrl-Shift-O',
-underline => 0,
-command => sub {
my $logger = get_logger();
my $filename = $mw->FBox(
-type => 'open',
-title => 'Open netlist file',
-filetypes => FILE_TYPES_NETLIST,
-initialdir => '.',
-initialfile => 'input.v'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open netlist action.");
return;
}
# Display "Busy" cursor
$self->{'mw'}->Busy();
$self->{'mw'}->update();
$logger->debug("Loading netlist...");
my $nl = new FIJI::Netlist();
if ($nl->read_file($filename) != 0) {
my $msg = "Netlist could not be loaded correctly from \"$filename\".";
$logger->error($msg);
$mw->Dialog(
-title => 'Open netlist failed!',
-text => "$msg!\n",
)->Show();
return;
}
$logger->debug("...done");
$logger->debug("Updating viewer...");
$self->{'mw'}->update();
if (!defined($self->{'FIJISettingsViewer'}->netlist($nl))) {
my $msg = "Could not update GUI correctly with new netlist.";
$logger->error($msg);
$mw->Dialog(
-title => 'Open netlist failed!',
-text => "$msg\n",
)->Show();
return;
}
${$self->{'nl_name'}} = $filename;
$logger->debug("...done");
# Done...
$self->{'mw'}->Unbusy();
$self->{'mw'}->update();
},
-command => [\&_open_netlist_file, $self],
);
$help->separator;
$help->command(
-label => 'Open Documentation',
-accelerator => 'F1',
-underline => 0,
-command => sub {
if($^O eq "MSWin32") {
system(1, "start ".$self->{'documentation_path'});
} elsif ($^O eq "linux") {
system("xdg-open ".$self->{'documentation_path'});
} else {
my $d = $mw->Dialog(-title=>"Open Documentation",
-buttons=>["OK"]);
$d->Label(-text=>"No default PDF viewer for OS \"".$^O."\"...")->pack(-side=>"top");
$d->Label(-text=>"Open")->pack(-side=>"left");
my $e = $d->Entry(-textvariable=>\$self->{'documentation_path'})->pack(-side=>"left");
$e->configure(-state=>"readonly");
$d->Label(-text=>"manually")->pack(-side=>"left");
$d->Show();
}
},
-command => [\&_show_documentation, $self],
);
$help->separator;
$help->command(
......@@ -372,143 +286,72 @@ sub _ctrl_frame {
#
$cfg_lbl = $fr_ctrl->Label(
-text => 'FIJI Configuration file',
)->pack(-side => 'top');
$cfg_btn_open = $fr_ctrl->Button(
-text => 'Open',
-command => sub {
my $logger = get_logger();
my $filename = $fr_ctrl->FBox(
-type => 'open',
-title => 'Open FIJI Configuration file',
-filetypes => FILE_TYPES_CFG,
-initialdir => '.',
-initialfile => 'fiji.cfg'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open configuration action");
return;
}
my $tmp_settings = \%{ Clone::clone ($self->{'settings'}) };
$tmp_settings = FIJI::Settings->new('setup', $filename, $tmp_settings);
if (!ref($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
$fr->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
}
my $rv = $self->{'FIJISettingsViewer'}->settings($tmp_settings);
if (!defined($rv)) {
my $msg = "Could not update GUI correctly with new settings.";
$logger->error($msg);
$fr->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
} elsif (ref($rv) eq "FIJI::Settings") {
$self->{'settings'} = $tmp_settings;
${$self->{'ini_name'}} = $filename;
}
},
);
$cfg_btn_open->focus();
$cfg_btn_save = $fr_ctrl->Button(
-text => 'Save',
-command => [\&_save, $self],
)->grid(
'-row' => 0,
'-column' => 0,
'-sticky' => 'w'
);
$fr->toplevel()->bind("<Control-s>" => [\&_save, $self]);
$cfg_btn_save_as = $fr_ctrl->Button(
-text => 'Save as',
-command => [\&_save_as, $self],
);
$fr->toplevel()->bind("<Control-Shift-S>" => [\&_save_as, $self]);
if(!defined USE_MENU || USE_MENU == 0) {
$cfg_btn_open = $fr_ctrl->Button(
-text => 'Open',
-command => [\&_open_settings_file, $self],
)->grid(
'-row' => 0,
'-column' => 1,
'-sticky' => 'ew'
);
$cfg_btn_open->focus();
$cfg_btn_save = $fr_ctrl->Button(
-text => 'Save',
-command => [\&_save, $self],
)->grid(
'-row' => 0,
'-column' => 2,
'-sticky' => 'ew'
);
$cfg_btn_save_as = $fr_ctrl->Button(
-text => 'Save as',
-command => [\&_save_as, $self],
)->grid(
'-row' => 0,
'-column' => 3,
'-sticky' => 'ew'
);
}
$cfg_entry = $fr_ctrl->Entry(
-textvariable => $self->{'ini_name'},
-state => 'disabled',
-disabledforeground => 'black',
-takefocus => 0, # default for disabled
);
Tk::grid(
$cfg_lbl, $cfg_btn_open, $cfg_btn_save, $cfg_btn_save_as, $cfg_entry,
)->grid(
'-row' => 0,
'-column' => 4,
'-sticky' => 'ew'
);
my $col = 0;
my $row = 1;
#
# Netlist file entries
#
$nl_lbl = $fr_ctrl->Label(
-text => 'Input netlist file',
)->grid(
'-row' => $row,
'-column' => $col++,
'-row' => 1,
'-column' => 0,
);
$nl_btn_open = $fr_ctrl->Button(
-text => 'Open',
-command => sub {
my $logger = get_logger();
my $filename = $fr_ctrl->FBox(
-type => 'open',
-title => 'Open netlist file',
-filetypes => FILE_TYPES_NETLIST,
-initialdir => '.',
-initialfile => 'input.v'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open netlist action.");
return;
}
# Display "Busy" cursor
$self->{'mw'}->Busy();
$self->{'mw'}->update();
$logger->debug("Loading netlist...");
my $nl = new FIJI::Netlist();
if ($nl->read_file($filename) != 0) {
my $msg = "Netlist could not be loaded correctly from \"$filename\".";
$logger->error($msg);
$fr->Dialog(
-title => 'Open netlist failed!',
-text => "$msg!\n",
)->Show();
return;
}
$logger->debug("...done");
$logger->debug("Updating viewer...");
$self->{'mw'}->update();
if (!defined($self->{'FIJISettingsViewer'}->netlist($nl))) {
my $msg = "Could not update GUI correctly with new netlist.";
$logger->error($msg);
$fr->Dialog(
-title => 'Open netlist failed!',
-text => "$msg\n",
)->Show();
return;
}
${$self->{'nl_name'}} = $filename;
$logger->debug("...done");
# Done...
$self->{'mw'}->Unbusy();
$self->{'mw'}->update();
},
)->grid(
'-row' => $row,
'-column' => $col++,
);
if(!defined USE_MENU || USE_MENU == 0) {
$nl_btn_open = $fr_ctrl->Button(
-text => 'Open',
-command => [\&_open_netlist_file, $self],
)->grid(
'-row' => 1,
'-column' => 1,
);
}
$nl_entry = $fr_ctrl->Entry(
-textvariable => $self->{'nl_name'},
......@@ -516,8 +359,8 @@ sub _ctrl_frame {
-disabledforeground => 'black',
-takefocus => 0, # default for disabled
)->grid(
'-row' => $row,
'-column' => $col++,
'-row' => 1,
'-column' => 2,
'-columnspan' => 4,
'-sticky' => 'ew',
);
......@@ -527,6 +370,125 @@ sub _ctrl_frame {
return $fr_ctrl;
}
sub _show_documentation {
my $self = shift;
my $mw = $self->{'mw'};
if($^O eq "MSWin32") {
system(1, "start ".$self->{'documentation_path'});
} elsif ($^O eq "linux") {
system("xdg-open ".$self->{'documentation_path'});
} else {
my $d = $mw->Dialog(-title=>"Open Documentation",
-buttons=>["OK"]);
$d->Label(-text=>"No default PDF viewer for OS \"".$^O."\"...")->pack(-side=>"top");
$d->Label(-text=>"Open")->pack(-side=>"left");
my $e = $d->Entry(-textvariable=>\$self->{'documentation_path'})->pack(-side=>"left");
$e->configure(-state=>"readonly");
$d->Label(-text=>"manually")->pack(-side=>"left");
$d->Show();
}
}
sub _open_settings_file {
my ($self) = @_;
my $mw = $self->{'mw'};
my $logger = get_logger();
my $filename = $mw->FBox(
-type => 'open',
-title => 'Open FIJI Configuration file',
-filetypes => FILE_TYPES_CFG,
-initialdir => '.',
-initialfile => 'fiji.cfg'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open configuration action");
return;
}
my $tmp_settings = \%{ Clone::clone ($self->{'settings'}) };
$tmp_settings = FIJI::Settings->new('setup', $filename, $tmp_settings);
if (!ref($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly: $tmp_settings";
$logger->error($msg);
$mw->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
}
my $rv = $self->{'FIJISettingsViewer'}->settings($tmp_settings);
if (!defined($rv)) {
my $msg = "Could not update GUI correctly with new settings.";
$logger->error($msg);
$mw->Dialog(
-title => 'Open FIJI Settings failed!',
-text => "$msg\n",
)->Show();
return;
} elsif (ref($rv) eq "FIJI::Settings") {
$self->{'settings'} = $tmp_settings;
${$self->{'ini_name'}} = $filename;
}
}
sub _open_netlist_file {
my $logger = get_logger();
my $self = shift;
my $mw = $self->{'mw'};
my $filename = $mw->FBox(
-type => 'open',
-title => 'Open netlist file',
-filetypes => FILE_TYPES_NETLIST,
-initialdir => '.',
-initialfile => 'input.v'
)->Show();
if (!defined($filename)) {
$logger->debug("User aborted open netlist action.");
return;
}
# Display "Busy" cursor
$self->{'mw'}->Busy();
$self->{'mw'}->update();
$logger->debug("Loading netlist...");
my $nl = new FIJI::Netlist();
if ($nl->read_file($filename) != 0) {
my $msg = "Netlist could not be loaded correctly from \"$filename\".";
$logger->error($msg);
$mw->Dialog(
-title => 'Open netlist failed!',
-text => "$msg!\n",
)->Show();
return;
}
$logger->debug("...done");
$logger->debug("Updating viewer...");
$self->{'mw'}->update();
if (!defined($self->{'FIJISettingsViewer'}->netlist($nl))) {
my $msg = "Could not update GUI correctly with new netlist.";
$logger->error($msg);
$mw->Dialog(
-title => 'Open netlist failed!',
-text => "$msg\n",
)->Show();
return;
}
${$self->{'nl_name'}} = $filename;
$logger->debug("...done");
# Done...
$self->{'mw'}->Unbusy();
$self->{'mw'}->update();
}
sub _overwrite_existing_file ($) {
my ($self, $filename) = @_;
my $logger = get_logger();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment