#======================================================== # BandGraphFrameArray #======================================================== package BandGraphFrameArray; use MyTk::GraphFrameArray; @ISA = qw(GraphFrameArray); use strict; use MyTk::BandGraphFrame; #============================================================ # 変数等取得関数 #============================================================ #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $mw, $canvas) = @_; my $this = {}; bless $this; # $this->SUPER::new($mw, $canvas); $canvas = $mw->Canvas($canvas); # $this->{'Canvas'} = $canvas; $this->{'MainWindow'} = $mw; my @array; $this->{'GraphFrameArray'} = \@array; $this->SetShowMousePosition(0); my $App = $mw->App(); if($App) { my $f = $App->{'ShowMousePosition'}; $this->SetShowMousePosition($f) if($f); } $mw->bind($canvas, '', [ \&ShowPopupMenu, $this, Tk::Ev('X'), Tk::Ev('Y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LButtonDown', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LBUttonUp', Tk::Ev('x'), Tk::Ev('y'), Tk::Ev('X'), Tk::Ev('Y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-Move', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', [ \&SelTags, $this, 'Others-LButtonDouble', Tk::Ev('x'), Tk::Ev('y') ]); $mw->bind($canvas, '', sub { $this->SetCanvasSize(); } ); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 一般関数 #============================================================ sub AddGraphFrame { my ($this, $GraphFrame) = @_; my $pGraphFrameArray = $this->GetpGraphFrameArray(); my $idx = @$pGraphFrameArray; my $canvas = $this->Canvas(); unless($GraphFrame) { $GraphFrame = new BandGraphFrame($this->mw(), $idx); } push(@$pGraphFrameArray, $GraphFrame); $canvas->bind("Frame$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "Frame-LButtonDown" ] ); $canvas->bind("Frame$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "Frame-LButtonDClick" ] ); $canvas->bind("XScale$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "XScale-LButtonDown" ] ); $canvas->bind("XScale$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "XScale-LButtonDClick" ] ); $canvas->bind("YScale$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "YScale-LButtonDown" ] ); $canvas->bind("YScale$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "YScale-LButtonDClick" ] ); $canvas->bind("XCaption$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "XCaption-LButtonDown" ] ); $canvas->bind("XCaption$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "XCaption-LButtonDClick" ] ); $canvas->bind("YCaption$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "YCaption-LButtonDown" ] ); $canvas->bind("YCaption$idx", '', [ \&SelTags, $this->GetGraphFrame($idx), "YCaption-LButtonDClick" ] ); } sub Draw { my ($this, $canvas) = @_; #print "draw\n"; my $rect = $this->SUPER::Draw($canvas); return $rect; } sub SelTags { my ($canvas, $this, $command, $x, $y, $X, $Y) = @_; my $idx = $this->Index(); #print "command: $command idx: $idx\n"; if($command =~ /Others-LButtonDown/i) { if($canvas->{'PrevSelTime'} and $canvas->{'PrevSelTime'} < time() ) { $canvas->delete("SelectedBox"); } } if($command =~ /XScale/i) { if($command =~ /down/i) { my ($x0,$y0,$x1,$y1) = split(/,/, $canvas->{"XScale${idx}Rect"}); #print "xscale: $x0, $y0, $x1, $y1\n"; $canvas->delete("SelectedBox"); $canvas->DrawBox($x0, $y0, $x1, $y1, 1, "", "red", "SelectedBox"); } else { my $func = $this->{'ShowScaleDialogFunc'}; if($func) { &$func($this, $command, "X Scale"); } else { $this->ShowScaleDialog("X Scale"); } $canvas->{'PrevDialogTime'} = time(); } } elsif($command =~ /YScale/i) { if($command =~ /down/i) { my ($x0,$y0,$x1,$y1) = split(/,/, $canvas->{"YScale${idx}Rect"}); $canvas->delete("SelectedBox"); $canvas->DrawBox($x0, $y0, $x1, $y1, 1, "", "red", "SelectedBox"); } else { my $func = $this->{'ShowScaleDialogFunc'}; if($func) { &$func($this, $command, "Y Scale"); } else { $this->ShowScaleDialog("Y Scale"); } $canvas->{'PrevDialogTime'} = time(); } } elsif($command =~ /XCaption/i) { if($command =~ /down/i) { my ($x0,$y0,$x1,$y1) = split(/,/, $canvas->{"XCaption${idx}Rect"}); $canvas->delete("SelectedBox"); $canvas->DrawBox($x0, $y0, $x1, $y1, 1, "", "red", "SelectedBox"); } else { my $text = Dialog::InputDialog($this->mw(), "X Caption", $this->{'XCaption'}, 50, 1); if($text) { chomp($text); $this->{'XCaption'} = $text; $this->mw()->Redraw(); } $canvas->{'PrevDialogTime'} = time(); } } elsif($command =~ /YCaption/i) { if($command =~ /down/i) { my ($x0,$y0,$x1,$y1) = split(/,/, $canvas->{"YCaption${idx}Rect"}); $canvas->delete("SelectedBox"); $canvas->DrawBox($x0, $y0, $x1, $y1, 1, "", "red", "SelectedBox"); } else { my $text = Dialog::InputDialog($this->mw(), "Y Caption", $this->{'YCaption'}, 50, 1); if($text) { chomp($text); $this->{'YCaption'} = $text; $this->mw()->Redraw(); } $canvas->{'PrevDialogTime'} = time(); } } elsif($command =~ /frame/i) { if($command =~ /down/i) { $canvas->delete("SelectedBox"); $canvas->DrawBox($this->{'x0'}, $this->{'y0'}, $this->{'x1'}, $this->{'y1'}, 1, '', 'red', 'SelectedBox'); } else { $this->ShowGraphFrameDialog("Graph Frame"); $canvas->{'PrevDialogTime'} = time(); } } else { #$command =~ /others/i if($command =~ /LButtonDown/i) { if($canvas->{'PrevSelTime'} and $canvas->{'PrevSelTime'} < time()) { $canvas->delete("SelectedBox"); } if($canvas->{'PrevDialogTime'} and time()-$canvas->{'PrevDialogTime'} <= 1) { undef $this->{'PrevX'}; undef $this->{'PrevY'}; } else { $canvas->delete("SelRangeBox"); $this->{'PrevX'} = $x; $this->{'PrevY'} = $y; } } elsif($command =~ /Move/i) { #print "move:", $this->ShowMousePosition(), "\n"; if($this->ShowMousePosition()) { my $s = ""; $s = $s . "P:($x, $y)"; for(my $idx = 0 ; ; $idx++) { my $frame = $this->GetGraphFrame($idx); last unless($frame); my ($vx0, $vy0) = $frame->PositionToValue($x, $y); next unless($vx0); $vx0 = Utils::Round($vx0, 3, 1); $vy0 = Utils::Round($vy0, 3, 1); $s = $s . " F$idx:($vx0, $vy0)"; } $this->mw()->WriteStatusBar($s); } if($this->{'PrevX'}) { $canvas->delete("SelRangeBox"); $canvas->DrawBox($this->{'PrevX'}, $this->{'PrevY'}, $x, $y, 1, '', 'red', 'SelRangeBox'); } } elsif($command =~ /LButtonUp/i) { $this->SelRangeBoxMenu($this->{'PrevX'}, $this->{'PrevY'}, $x, $y, $X, $Y, $command); undef $this->{'PrevX'}; undef $this->{'PrevY'}; $canvas->delete("SelRangeBox"); } } #以外の場合は、前の赤枠を削除するための現在時間を記録する $canvas->{'PrevSelTime'} = time() unless($command =~ /move/i); } 1;