#=============================================== # TkGULP #=============================================== package TkGULP; use Crystal::GULP; use TkPlotModule; @ISA = qw(GULP TkPlotModule); #公開したいサブルーチン #@EXPORT = qw(DelSpace Reduce01 MakePath RegExpQuote); use strict; use Utils; use MyTk::GraphFrameArray; use MyTk::BandGraphFrameArray; use MyTk::EnergyLevelGraphFrameArray; use GraphData; #============================================================ # 変数等取得、再定義関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ 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 CheckFileType { my ($path) = @_; return GULP::CheckFileType($path); } sub Read { my ($this, $filename, $TargetData) = @_; my $s = ''; if($TargetData) { $s = " for $TargetData"; # return $this->Draw(undef, $TargetData); } my $App = $this->App(); $this->mw()->WriteStatusBar("Reading $filename$s..."); my $ret = $this->ReadFiles($filename, $TargetData); $this->mw()->WriteStatusBar("Finish reading $filename$s..."); $App->print(" Finish reading $filename$s...\n"); } sub CreateGraphFrame { my ($this, $canvas, $TargetData) = @_; $canvas = $this->Canvas($canvas); # $this->SetCanvas($canvas) if($canvas); # $canvas = $this->Canvas() unless($canvas); my $App = $this->App(); my $pDataArray = $App->TkData(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); my $w = $canvas->width(); my $h = $canvas->height(); my $FileType = $this->FileType(); $TargetData = $pDataArray->{'TargetData'} unless(defined $TargetData); if($FileType eq "GULP DENS file") { my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrameDOS0Position"}; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); $GraphFrame0->SetXCaption("Wave number / cm-1"); $GraphFrame0->SetYCaption('Phonon DOS'); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); $GraphFrame0->SetViewRange(0, 0, 1, 1); # $GraphFrameArray->SetShowScaleDialogCallback(sub { $this->ShowScaleDialog(@_) } ); } elsif($FileType eq "GULP DISP file") { my $GraphFrameArray = $this->{'GraphFrameArray'} = new BandGraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); $GraphFrameArray->AddGraphFrame(); my $GraphFrame0 = $GraphFrameArray->GetGraphFrame(0); my $FramePosStr0 = $App->{"GraphFrame0Position"}; my $XScale0 = $GraphFrame0->GetXScale(0); my $YScale0 = $GraphFrame0->GetYScale(0); $GraphFrame0->SetPositionByStr($FramePosStr0); $GraphFrame0->SetXCaption("k"); $GraphFrame0->SetYCaption("Wave number / cm-1"); $XScale0->SetScaleStringVisible(1); $XScale0->SetCaptionVisible(1); $GraphFrame0->SetViewRange(0, 0, 1, 1); } else { my $GraphFrameArray = $this->{'GraphFrameArray'} = new GraphFrameArray($this->mw()); $GraphFrameArray->SetCanvasSize($w, $h); } } sub ShowScaleDialog { my ($this, $GraphFrame, $command, $Title, @a) = @_; #$command: "XScale" "YScale" #最初の4つのundefはViewRangeに現在値を使う #次の2つのundefはPlotTypeに現在値を使う設定 #そのあとの1,0は、X,Y軸のPlotTypeの同期をおこなうかどうか #最後の1は、ScaleDialogでOKを押されたらグラフの再描画を行う #  Y軸のViewRangeは同期するが、PlotTypeの同期は無視する return $GraphFrame->ShowScaleDialog($Title, undef, undef, undef, undef, undef, undef, 1, 0, 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 eq "GULP DENS file") { my $GraphFrame1 = $GraphFrameArray->GetGraphFrame(1); my $Data0 = $pDataArray->GetGraphData(0); return unless($Data0); my $nData = $Data0->nData(); my $title = $Data0->Title(); my $pX0 = $Data0->GetDataArray("x0"); last if(not defined $pX0); my $pY0 = $Data0->GetDataArray("y0"); last if(not defined $pY0); my $nData0 = $GraphFrame0->AddGraphData($pX0, $pY0, 1, "auto", "", 6, "red", 0, "red", "XAutoSkip", $Data0->{"x0_Name"}, $Data0->{"y0_Name"}); $GraphFrame0->SetYScalePlotType('x'); $GraphFrame0->CalMinMax(); $GraphFrame0->AdjustViewRange(0.05, 0.05, 0.05, 0.05); # if($GraphFrame1) { # $GraphFrame0->AddSynchronousFrame('x', $GraphFrame1); # } } elsif($FileType eq "GULP DISP file") { my @GraphFrame; for(my $id = 0 ; ; $id++) { $GraphFrame[$id] = $GraphFrameArray->GetGraphFrame($id); last unless($GraphFrame[$id]); my $Data = $pDataArray->GetGraphData($id); my $pX0 = $Data->GetDataArray('x0'); my $linecolor; $linecolor = 'black' if($id == 0); $linecolor = 'red' if($id == 1); for(my $i = 0 ; ; $i++) { my $pY = $Data->GetDataArray("y$i"); last unless($pY); my $nData = $GraphFrame[$id]->AddGraphData($pX0, $pY, 1, $linecolor, "", 6, "red", 0, "red", "XAutoSkip", $Data->{"x0_Name"}, $Data->{"y${i}_Name"}); my $data = $GraphFrame[$id]->GetPlotData($nData-1); } $GraphFrame[$id]->CalMinMax(); $GraphFrame[$id]->AdjustViewRange(0.05, 0.05, 0.05, 0.05); $GraphFrame[$id]->{'pBandBoundaryDistances'} = $pDataArray->{'pBandBoundaryDistances'}; $GraphFrame[$id]->{'pBandBoundaryPositions'} = $pDataArray->{'pBandBoundaryPositions'}; $GraphFrame[$id]->{'pKPointName'} = $pDataArray->{'pKPointNameArray'}; } if($GraphFrame[1]) { $GraphFrame[0]->AddSynchronousFrame('x', $GraphFrame[1]); $GraphFrame[0]->AddSynchronousFrame('y', $GraphFrame[1]); $GraphFrame[1]->AddSynchronousFrame('x', $GraphFrame[0]); $GraphFrame[1]->AddSynchronousFrame('y', $GraphFrame[0]); } } $this->AdjustViewRange(); } sub AdjustViewRange { my ($this) = @_; my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $FileType = $this->FileType(); if($FileType eq "GULP DENS file") { } elsif($FileType eq "GULP DISP file") { } } sub Draw { my ($this, $canvas, $TargetData) = @_; my $mw; my $GraphFrameArray; my $App = $this->App(); my $font = $App->{'GraphFrameFont'}; my @font = split(/,/, $font) if($font); $canvas = $this->Canvas($canvas); $mw = $this->mw(); $GraphFrameArray = $this->GetGraphFrameArray(); if($font) { $canvas->SetFont(\@font); $GraphFrameArray->SetFont(\@font); } my $w = $canvas->width(); my $h = $canvas->height(); $GraphFrameArray->SetCanvasSize($w, $h); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my @GraphFrame = @$pGraphFrame; my $pDataArray = $this->DataArray(); my $pData = $pDataArray->GetGraphData(0); $TargetData = $pDataArray->{'TargetData'} unless($TargetData); my $FileType = $this->FileType(); #Phonon DOS if($FileType eq "GULP DENS file") { $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing DOS..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing DOS."); return; } #Phonon Eigenval if($FileType eq "GULP DISP file") { $mw->RefleshCanvas(); $mw->WriteStatusBar("Drawing Phonon dispersion..."); $mw->Balloon()->detach($canvas); $GraphFrameArray->Draw($canvas); $this->mw()->WriteStatusBar("Finish Drawing Phonon dispersion."); return; } } 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); my $GraphFrameArray = $this->GetGraphFrameArray(); my $pGraphFrame = $GraphFrameArray->GetpGraphFrameArray(); my $GraphFrame0 = $pGraphFrame->[0]; my $pDataArray = $DataArray->DataArray(); return undef unless($pDataArray); my $Data = $pDataArray->GetGraphData(0); return undef unless($Data); if($this->FileType() eq "GULP Output file") { # $ListBox->AddItem("EnergyConvergence"); # $ListBox->AddItem("ForceConvergence(RMS)"); # $ListBox->AddItem("ForceConvergence(AtomRange:1-3)"); # $ListBox->AddItem("ForceConvergence"); # $ListBox->AddItem("EnergyLevels"); } return 1; } #============================================================ # 一般関数 #============================================================ #============================================================ # bind応答関数 #============================================================ 1;