#======================================================== # TkPlotApp #======================================================== package TkPlotApp; use MyTk::MyTkApplication; @ISA = qw(MyTkApplication); use strict; use TkPlotDoc; use TkPlotWindow; #============================================================ # 変数等取得関数 #============================================================ # TkData sub TkData { my ($this)=@_; return $this->{DataArray}; } sub SetTkData { my ($this, $d, $ModulePath) = @_; my $ret = $this->{DataArray} = $d; if($ret) { print "Load TkPlot Module: $ModulePath\n"; } else { print "Error: Can not load $ModulePath\n"; } return $ret; } #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my $class = shift; my $self = MyTkApplication->new(@_); my $this = bless $self, $class; my %LoadedModules; $this->{LoadedModules} = \%LoadedModules; my @WillLoadModules; $this->{WillLoadModules} = \@WillLoadModules; return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } sub Execute { my ($this, @a) = @_; return 0 if($this->Initialize() < 0); for(my $i = 0 ; $i < @a ; $i += 2) { my $key = $a[$i]; my $val = $a[$i+1]; print "key: $key = [$val]\n"; next if(!defined $val); $this->{$key} = $val; } my $Program = $this->Program(); $this->SetAppName($Program); $this->SetVersion($this->{-Version}); $this->SetTitle($this->{-WindowTitle}); my $ProgramPath = $this->SpeculateProgramPath($0, $this->{-BaseDir}); my $IniFile = $this->OpenIniFile($ProgramPath, 1); my $IniFilePath = $this->IniFile()->IniFile(); my $MyDir = $IniFile->MyDir(); if($this->OS() eq 'MSWin32' and !$this->Debug()) { # $this->FreeWin32Console(); } #========================================== # コマンドラインオプション読み込み #========================================== $this->AddArgument("--style", "--style: Set style for specific data", ''); $this->AddArgument("--NoAutoLoadModules", "--NoAutoLoadModules=[0|1]: Suppress autoload modulesa", 0); $this->AddArgument("--LoadModule", "--LoadModule=ModulePath: Load module ModulePath specified by relative path", ''); $this->AddArgument("--WorkDir", "--WorkDir=Dir: Read 'Dir' directory (ignore --ReadPrev", ''); $this->AddArgument("--ReadPrev", "--ReadPrev : Read previous Working Direcotry", 1); $this->AddArgument("--FilePathPane", "--FilePathPane=[TkPlot|Conventional]", 'TkPlot'); $this->AddArgument("--vertical", "--vertial : Align panes vertically", 0); $this->AddArgument("--help", "--help : Show this help", ''); #ここでは、引数エラーがあっても無視する。 #引数エラーはあとでチェック $this->ReadArgs(0); # exit 1 if($this->ReadArgs(0) != 1); my $Args = $this->Args(); my $Style = (defined $this->{-Style})? $this->{-Style} : $Args->GetGetArg("style"); my $LoadModule = (defined $this->{-LoadModule})? $this->{-LoadModule} : $Args->GetGetArg("LoadModule"); my $NoAutoLoadModules = (defined $this->{-NoAutoLoadModules})? $this->{-NoAutoLoadModules} : $Args->GetGetArg("NoAutoLoadModules"); #========================================== # 起動時引数に従う変更 #========================================== # --style オプションが指定されていた場合、Window TitleにStyleを設定 if($Style) { $this->SetTitle("${Style}Plot 2005/pl"); # アプリケーション名を再設定 $this->SetAppName("${Style}Plot"); } #========================================== # Iniファイル読み込み #========================================== # $this->ConfigureIniFileVariables(); #=============================================== # TkDataモジュール読み込み #=============================================== # --LoadModuleが指定された場合は、ここで読み込んでクラスを作成する my $TkData; if($LoadModule) { $TkData = $this->SetTkData($this->LoadAModule($LoadModule, $MyDir), $LoadModule); } unless($this->TkData()) { $TkData = $this->SetTkData(new TkPlotModule($this), "TkPlotModule"); unless($TkData) { $this->print(" TkPlotApp::LoadModules: Program terminated.\n\n"); return 2; } } #========================================== # カスタマイズ用の引数読み込みとIniファイル読み込み # デフォルトでは、$TkPlotData->ReadArgs()内でエラーが出ると停止する #========================================== $TkData->ReadArgs(); $TkData->ConfigureIniFileVariables(); $TkData->ConnectDocument(TkPlotDoc->new()); $TkData->CreateWindow(TkPlotWindow->new()); $TkData->MainLoop(); } #============================================================ # 初期化ファイルの設定 #============================================================ sub ConfigureIniFileVariables { my ($App) = @_; my $Style = $App->Args()->GetGetArg("style"); $Style = "General" unless($Style); $App->AddIniFileVariable("\\Preferences\\EditorPath", "EditorPath", "notepad.exe"); $App->AddIniFileVariable("\\Preferences\\StartAppPath", "StartAppPath", ""); $App->AddIniFileVariable("\\Preferences\\PSViewer1Path", "PSViewer1Path", ""); $App->AddIniFileVariable("\\Preferences\\PSViewer1Name", "PSViewer1Name", ""); $App->AddIniFileVariable("\\Preferences\\PSViewer2Path", "PSViewer2Path", ""); $App->AddIniFileVariable("\\Preferences\\PSViewer2Name", "PSViewer2Name", ""); $App->AddIniFileVariable("\\Preferences\\Debug", "Debug", 0); $App->AddIniFileVariable("\\FileContentText\\Font", "FileContentFont", "times,10.5,normal"); $App->AddIniFileVariable("\\LeftFrame\\Width", "LeftFrameWidth", 10); $App->AddIniFileVariable("\\$Style\\SetWindowPos", "SetWindowPos", 1); $App->AddIniFileVariable("\\$Style\\WorkDir", "WorkDir", ''); $App->AddIniFileVariable("\\$Style\\geometry", "geometry", ''); $App->AddIniFileVariable("\\$Style\\FileMask", "FileMask", ".*"); $App->AddIniFileVariable("\\$Style\\GraphFrame_GraphFont", "GraphFrameFont", "times,14,normal"); $App->AddIniFileVariable("\\$Style\\GraphFrame_GraphSymbolFont", "GraphFrameSymbolFont", "symbol,14,normal"); # $App->AddIniFileVariable("\\$Style\\GraphFrame_Position", "GraphFramePosition", "r0.20,0.80,0.80,0.10"); $App->AddIniFileVariable("\\$Style\\GraphFrame0_Position", "GraphFrame0Position", "r0.20,0.60,0.80,0.10"); $App->AddIniFileVariable("\\$Style\\GraphFrame1_Position", "GraphFrame1Position", "r0.20,0.80,0.80,0.60"); $App->AddIniFileVariable("\\$Style\\GraphFrame2_Position", "GraphFrame2Position", "r0.20,0.80,0.80,0.80"); # $App->AddIniFileVariable("\\$Style\\GraphFrameDOS0_Position", "GraphFrameDOS0Position", "r0.20,0.80,0.80,0.45"); # $App->AddIniFileVariable("\\$Style\\GraphFrameDOS1_Position", "GraphFrameDOS1Position", "r0.20,0.45,0.80,0.10"); $App->AddIniFileVariable("\\$Style\\ShowMousePosition", "ShowMousePosition", "1"); # $App->AddIniFileVariable("\\$Style\\vgeometry", "vgeometry", ''); # $App->AddIniFileVariable("\\GraphFrame0\\Position", "GraphFrame0Position", "100,450,450,50"); # $App->AddIniFileVariable("\\GraphFrame1\\Position", "GraphFrame1Position", "100,550,450,450"); # $App->AddIniFileVariable("\\GraphFrame2\\Position", "GraphFrame2Position", "100,650,450,550"); $App->ReadSetting(); #print "Style: $Style\n"; #print "GraphFrame0Position: $App->{EditorPath}\n"; #exit; $App->{Debug} = 0; $App->{LeftFrameWidth} = 50 unless($App->{LeftFrameWidth}); } sub AddLoadModule { my ($this, $Module) = @_; my $pWillLoadModules = $this->{'WillLoadModules'}; my $pLoadedModules = $this->{'LoadedModules'}; unless($pLoadedModules->{$Module}) { $pLoadedModules->{$Module} = 1; push(@$pWillLoadModules, $Module); } } sub LoadModules { my ($this) = @_; my $Args = $this->Args(); my $Style = $Args->GetGetArg("style"); my $IniFile = $this->IniFile(); my $pWillLoadModules = $this->{'WillLoadModules'}; my $pLoadedModules = $this->{'LoadedModules'}; my @Libs = (); my @GeneralLibs = (); my @TestLibs = (); my $TkPlotModulePath = Deps::MakePath($IniFile->MyDir(), 'dlib'); my $FileGlob = Deps::MakePath($TkPlotModulePath, 'Tk*.pm'); my @TkDataList = glob($FileGlob); for(my $i = 0 ; $i < @TkDataList ; $i++) { my $p = $TkDataList[$i]; $p = Deps::ExtractFileBody($p); $p = Deps::MakePath("dlib", $p); $p =~ s/\\/\//g; #すでに登録はモジュールは再度登録しない next if($pLoadedModules->{$p}); #print "p: $p\n"; if($p =~ /General/i) { print "Register General Lib [$p]\n"; push(@GeneralLibs, $p); } elsif($p =~ /test/i) { print "Register Test Lib [$p]\n"; push(@TestLibs, $p); } else { print "Register lib [$p]\n"; push(@Libs, $p); } #登録したモジュールの名前を%LoadedModulesハッシュ変数に登録 # require $p; $pLoadedModules->{$p} = 1; } #Generalファイルは最後に読み込む @$pWillLoadModules = (@$pWillLoadModules, @Libs, @TestLibs, @GeneralLibs); GeneralFileFormat::LoadTkPlotModules($pWillLoadModules, $pLoadedModules); return 1; } sub LoadAModule { my ($this, $Module, $dir) = @_; my $pLoadedModules = $this->{'LoadedModules'}; #読み込んだモジュールを登録 my $ModulePath = Utils::MakePath($dir, "$Module.pm", '/', 0); $ModulePath =~ s/\\/\//g; require $ModulePath; #if(!$pLoadedModules->{$Module}); $pLoadedModules->{$Module} = 1; my $ModuleName = $ModulePath; $ModuleName =~ s/^.*[\\\/](.*?)\.pm$/$1/i; #print "MN: $ModuleName\n"; my $pModule = new $ModuleName; return undef unless($pModule); $pModule->SetApplication($this); return $pModule; } 1;