App-PLab

 view release on metacpan or  search on metacpan

bin/PrLenS  view on Meta::CPAN

      return;
   }

   return unless $btn == mb::Left;
   return unless defined $w-> {markState};
   my ( $ax, $ay) = $self-> screen2point( $x, $y);
   return unless ( $ax >= 0 && $ay >= 0 && $ax < $w->{IVx} && $ay < $w->{IVy});
   my $ary = undef;
   $ary = ($w->{ markState} == 16) ? $w-> {branches} : $w-> {$w-> {layers}->[$w-> {markState}]};
   return unless defined $ary;

   if ( $w->{ markState} == 16) {
      if ( ! $w->{ binfo}->{ drawMode}) {
         $w-> initiate_draw_mode( $x, $y);
      }

      my ( $bn) = $w->{ binfo}->{ branchNumber};
      push @{ $w->{ branches}->[ $bn]}, [ int($ax), int($ay)];
      $w->{ binfo}->{ removeLastPoint} = 1;
      $w-> modified(1);
   }
   else {
      my ($i,$x1,$x2,$y1,$y2);


      # search for an existing point
      for ( $i = 0; $i < scalar @$ary; $i++)
      {
         ($x1,$y1) = split ' ', $$ary[$i];
         ($x2,$y2) = map { $_ + 6; } ($x1,$y1);
         ($x1,$y1) = map { $_ - 6; } ($x1,$y1);
         last if $ax >= $x1 && $ax <= $x2 && $ay >= $y1 && $ay <= $y2;
      }

      $w-> modified( 1); 
      my $layer = ucfirst $w-> {layers}->[$w-> {markState}];
      if ( $i < scalar @$ary)
      {
         # removing existing point
         ($ax, $ay) = split(' ', splice( @$ary, $i, 1));
         $w-> {"n$layer"}--;
         $w-> {"total$layer"}--;
      }
      else
      {
         # adding new point
	 $ax = int($ax);
	 $ay = int($ay);
         push @$ary, "$ax $ay";
         $w-> {"n$layer"}++;
         $w-> {"total$layer"}++;
      }
      my $zp = $self-> zoom * $w->{ini}->{PointSize};
      $zp = 4 if $zp < 4;
      ($x1, $x2, $y1, $y2) = map { ($_ - $zp - 2, $_ + $zp + 2); } ($ax,$ay);
      $self-> invalidate_rect( $self-> point2screen( $x1, $y1, $x2, $y2));
   }
   $w-> update_state;
}

sub update_state
{
   my $w = $_[0];
   my $cp = $w-> ToolBar-> CellsProcesses;
   if ( !defined $w-> {file})
   {
      $w-> sb_text( "No file loaded");
      $cp-> text( "???:???");
   }
   else
   { 
       my $text1 = '';
       my @text2;
       for ( @{$w->{layers}}) {
          my $u = ucfirst $_;
          $text1 .= "$u: ".$w->{"n$u"}." (".$w->{"total$u"}.") ";
          next if $_ eq 'cells';
          push @text2, "(" . ($w->{totalCells} ? sprintf("%.4g",$w->{"total$u"} / $w->{totalCells}) 
                                               : "NONE") . ")";
       }
       $w-> sb_text( $text1 . ' Ratio: '. join(',',@text2));
       $cp-> text( join( ':', map { sprintf "%03d", $w->{ 'n' . ucfirst $_} } @{$w->{layers}}));
   }
   $w-> show_stats( undef, 1);
}


sub IV_Paint
{
   my ( $w, $self, $canvas) = @_;

   my $image = $self-> {image};
   $self-> {image} = $w-> {preprocessedImage} if $w-> {preprocessedImage};
   $self-> on_paint( $canvas);
   $self-> {image} = $image;

   return unless $image;
   
   my $z  = $self-> zoom;
   my $zp = $z * $w->{ini}->{PointSize};
   $zp = 4 if $zp < 4;
   $canvas-> translate( $self-> point2screen( 0, 0));
   my ($x, $y, $iw, $ih) = ( $self-> size, $image-> size);
   my $dx = sprintf( '%d', $iw / 20);
   my $dy = sprintf( '%d', $ih / 20);
   my $szy = sprintf( '%d', ($ih - 2 * $dy) / $w-> {ini}-> {nLines});

   $dx *= $z;
   $dy *= $z;
   $iw *= $z;
   $ih *= $z;
   $szy *= $z;
   
   $canvas-> set( lineWidth => 2, color => $w-> {ini}-> {Color_Frame});
   $canvas-> line( $dx, $dy, $iw - $dx, $dy);
   $canvas-> line( $iw - $dx, $dy, $iw - $dx, 0);
   $canvas-> line( $dx, $dy, $dx, $ih);
   $canvas-> linePattern( lp::LongDash);
   $canvas-> line( $dx, $ih - $dy, $iw - $dx, $ih - $dy);
   $canvas-> line( $iw - $dx, $ih - $dy, $iw - $dx, $dy);
   $canvas-> set( lineWidth => 1, linePattern => lp::Solid);



( run in 1.092 second using v1.01-cache-2.11-cpan-2398b32b56e )