#=============================================== # TkTFT #=============================================== package TkTFT; use TkPlotModule; @ISA = qw(TkPlotModule); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use Tk::JPEG; use Utils; use Sci::Color; use Tk; use Tk::Balloon; use MyTk::Dialog; use MyTk::MyFrame; use MyTk::MyLabel; use MyTk::MyEntry; use MyTk::MyListbox; use MyTk::MyBrowseEntry; use MyTk::MyText; use MyTk::MyButton; use MyTk::MyMenubutton; use MyTk::MyCanvas; use MyTk::MyAdjuster; use MyTk::MyScale; use MyTk::GraphFrameArray; use GraphData; use Sci::GeneralFileFormat; #============================================================ # 変数等取得関数 #============================================================ sub FileType { return shift->{FileType}; } sub SetFileType { my ($this,$t)=@_; return $this->{FileType} = $t; } sub FileName { return shift->{FileName}; } sub SetFileName { my ($this,$f)=@_; return $this->{FileName} = $f; } sub SetDataArray { my ($this, $da)=@_; return $this->{DataArray} = $da; } sub DataArray { return shift->{DataArray}; } sub GetColor { return shift->{Color}; } sub ColorMapImage { return shift->{ColorMapImage}; } sub SetColorMapImage { my ($this,$m)=@_; return shift->{ColorMapImage} = $m; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $app) = @_; # my ($module, $app, $canvas) = @_; my $this = {}; bless $this; $this->SetApplication($app); # $this->SetCanvas($canvas); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ sub CreateSelectFilePane { my ($this) = @_; # $this->SUPER::CreateSelectFilePane(); } sub CreateWidgets { my ($this) = @_; my $mw = $this->mw(); my $canvas = $this->Canvas(); $this->SUPER::CreateWidgets(); my $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{VdsIdsFileLabel} = $Frame->MyLabel( -text => 'Vds-Ids:' )->pack(-side => 'left'); $this->{VdsIdsFileEntry} = $Frame->MyEntry( -takefocus => 1, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $this->{VdsIdsFileEntry}->focus(); $this->{VdsIdsFilePathButton} = $Frame->MyButton( -text => '&Choose', -takefocus => 1, -command => [ \&ChooseFile, $this, "VdsIds", $this->{VdsIdsFileEntry} ], )->pack(-side => 'left'); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{VgsIdsFileLabel} = $Frame->MyLabel( -text => 'Vgs-Ids:' )->pack(-side => 'left'); $this->{VgsIdsFileEntry} = $Frame->MyEntry( -takefocus => 1, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $this->{VgsIdsFileEntry}->focus(); $this->{VgsIdsFilePathButton} = $Frame->MyButton( -text => '&Choose', -takefocus => 1, -command => [ \&ChooseFile, $this, "VgsIds", $this->{VgsIdsFileEntry} ], )->pack(-side => 'left'); #ツールバーのOpenボタンをファイル読み込みにバインドする $mw->{OpenButton}->configure( -command => [ \&ChooseVdsIdsFile, $this, $this->{VdsIdsFileEntry} ], ); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); my $lsb1 = $this->{ChooseVdsIdsPlotTypeListBox} = $Frame->MyBrowseEntry( -label => "VdsIds plot:", -state => "readonly", -takefocus => 1, # -browsecmd => [\&SelChangeListBox, "VdsIds", $this], )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb1->AddItem("Vds-Ids"); $lsb1->AddItem("Vds-log(|Ids|)"); $lsb1->SetText("Vds-Ids"); my $lsb2 = $this->{ChooseVgsIdsPlotTypeListBox} = $Frame->MyBrowseEntry( -label => "VgsIds plot:", -state => "readonly", -takefocus => 1, # -browsecmd => [\&SelChangeListBox, "VgsIds", $this], )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $lsb2->AddItem("Vgs-Ids"); $lsb2->AddItem("Vgs-log(|Ids|)"); $lsb2->SetText("Vgs-Ids"); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{VthLabel} = $Frame->MyLabel( -text => 'Vth:' )->pack(-side => 'left'); $this->{VthScale} = $Frame->MyScale( -bigincrement => 10.0, -command => sub { print "Moved to ", $this->{VthScale}->GetValue(), "\n"; }, -cursor => 'hand2', #'sb_h_double_arrow', -orient => 'horizontal', #'vertical' -digits => 4, -from => 10, -to => 120, # -label => 'label', -showvalue => 1, -length => 30, -sliderlength => 10, -width => 5, -resolution => 1, -takefocus => 1, -tickinterval => 20, -variable => 30.0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); $Frame = $mw->MyFrame( )->pack(-anchor => 'nw', -fill => 'x'); $this->{uFELabel} = $Frame->MyLabel( -text => 'uFE:' )->pack(-side => 'left'); $this->{uFEScale} = $Frame->MyScale( -bigincrement => 10.0, -command => sub { print "Moved to ", $this->{uFEScale}->GetValue(), "\n"; }, -cursor => 'hand2', #'sb_h_double_arrow', -orient => 'horizontal', #'vertical' -digits => 4, -from => 10, -to => 120, # -label => 'label', -showvalue => 1, -length => 30, -sliderlength => 10, -width => 5, -resolution => 1, -takefocus => 1, -tickinterval => 20, -variable => 30.0, )->pack(-side => 'left', -expand => 'yes', -fill => 'x'); #$mw->bind('all', '', [\&CheckLogin, Ev('K'), 0]); #$mw->bind($ent, '', [\&CheckLogin, 'Enter', 1]); #$mw->bind($ent, '', [\&CheckLogin, 'Leave', 1]); #$mw->bind($ent, '', [\&CheckLogin, 'Property', 1]); #$mw->bind($ent, '', [\&CheckLogin, 'FocusIn', 1]); #$mw->bind($ent, '', [\&CheckLogin, 'FocusOut', 1]); # $this->{TFT} = new TFT; } sub CreateGraphFrame { my ($this, $canvas, $TargetData) = @_; $canvas = $this->Canvas(); my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); my $w = $canvas->width(); my $h = $canvas->height(); my $FileType = $this->FileType(); return undef unless($FileType); my $pDataArray = $this->DataArray(); return unless($pDataArray); if($FileType =~ /(Ids)/i) { my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); # $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); # my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); # my $FramePosStr1 = $App->{"GraphFrame1Position"}; # my $XScale1 = $GraphFrame1->GetXScale(0); # my $YScale1 = $GraphFrame1->GetYScale(0); # $GraphFrame1->SetPositionByStr($FramePosStr1); $GraphFrame0->SetXCaption("lambda / nm"); $GraphFrame0->SetYCaption("Spectrum"); # $GraphFrame1->SetXCaption(""); # $GraphFrame1->SetYCaption('Spectrum'); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); # $XScale1->SetScaleStringVisible(1); # $XScale1->SetCaptionVisible(0); $GraphFrame0->SetViewRange(0, 0, 1, 1); # $GraphFrame1->SetViewRange(0, 0, 1, 1); } } sub AssignGraphData { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $pDataArray = $this->DataArray(); my $FileType = $this->FileType(); my $TargetData = $pDataArray->{'TargetData'}; return unless($pDataArray); if($FileType =~ /(Ids)/i) { my $Data0 = $pDataArray->GetGraphData(0); # my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); # my $Data1 = $pDataArray->GetGraphData(1); # return unless($Data1); my $nData = $Data0->nData(); my $title = $Data0->Title(); for(my $i = 0 ; ; $i++) { my $pX0 = $Data0->GetDataArray("x$i"); last if(not defined $pX0); my $pY0 = $Data0->GetDataArray("y$i"); last if(not defined $pY0); my $nData0 = $GraphFrame0->AddGraphData($pX0, $pY0, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x${i}_Name"}, $Data0->{"y${i}_Name"}); } $GraphFrame0->SetYScalePlotType('x'); $GraphFrame0->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); } } sub AdjustViewRange { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $FileType = $this->FileType(); if($FileType =~ /(Ids)/i) { } } sub Draw { my ($this, $canvas, $TargetData) = @_; my $mw = $this->mw(); $canvas = $this->Canvas(); $mw->RefleshCanvas(); my $FileType = $this->FileType(); my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); $mw->RefleshCanvas(); $this->mw()->WriteStatusBar("Drawing ColorMap..."); $this->mw()->WriteStatusBar("Finish ColorMap."); } sub DeleteWidget { my ($this, $Frame) = @_; return undef unless($Frame); return 1; } sub AddWidget { my ($this, $Frame) = @_; return undef unless($Frame); # 左枠3列目作成: ファイルの内容を表示するセクションリストボックス # $this->mw()->CreateSectionListBox(); # 左枠4列目作成: ファイルの内容を表示するテキストボックス # $this->mw()->CreateFileContentTextBox(); return 1; } sub SetFileInfo { my ($this, $ListBox, $TextBox) = @_; return undef unless($ListBox); return undef unless($TextBox); $ListBox->ClearAll(); $TextBox->ClearText(); my $App = $this->App(); my @Font = split(/,/, $App->{"FileContentFont"}); $TextBox->configure(-font => \@Font) if(@Font > 0); my $DataArray = $App->TkData(); return undef unless($DataArray); # $TextBox->AddText("$nData\n"); return 1; } sub SelTags { my ($canvas, $this, $command, $x, $y, $X, $Y) = @_; #print "command: $command Pos: ($x, $y)\n"; if($command =~ /LButtonDown/i) { } elsif($command =~ /Move/i) { my $s = "($x,$y)"; $this->mw()->WriteStatusBar($s); } elsif($command =~ /LButtonUp/i) { } } sub SelChangeListBox { my ($this, $type, $lb) = @_; my $s = $lb->GetText(); if($s =~ /Solar/i) { } } sub ChooseFile { # $type: "VdsIds", "VgsIds" my ($this, $type, $widget) = @_; my $App = $this->App(); my $canvas = $this->Canvas(); my $mw = $this->mw(); my $dir = ''; unless($widget) { $dir = $this->App()->{'WorkDir'}; chdir($dir); } my $fmask = '*.csv'; my $defstr = ''; my $message = 'Choose file'; my $filepath = Dialog::OpenFileDialog($mw, 'open', $fmask, $defstr, $message, $dir); if($filepath) { my $DirPath = $this->SetWorkDir($filepath); if($widget) { $widget->SetText($filepath); } } $this->DrawSpectrum(); return $filepath; } 1;