#!/usr/bin/perl use Tk; use Tk::FileSelect; use Cwd; #### #### All Code by Steve Michel #### # PLT uses 1016 units per inch $DumbLoop = 0; $xX = 18; $yY = 11; $pltUnits = 1016; $DisplayFactor = 16; $Units = $pltUnits / $DisplayFactor; ## 63.5 units per inch = 1016 / 16 $xRange = $xX*$Units; ## 18 inches times 63.5 units per inch $yRange = $yY*$Units; ## 11 inches times 63.5 units per inch $WindowWidth = 1240; $WindowHigh = 950; $WinCentX = ($WindowWidth - $xRange)/2; $WinCentY = ($WindowWidth - $xRange)/2; $pos = 200; $color = '#AAAAAAAAAAAA'; $color2 = '#BBBBBBBBBBBB'; $bg = '#9999EEEE9999'; my $mw = MainWindow->new; $mw->title ("PLT Reader"); my $canvas = $mw->Canvas(-width => $WindowWidth, -height => $WindowHigh,-background => $bg)->grid; $mw->waitVisibility; $canvas->createPolygon ($WinCentX, ($WinCentY+$yRange), ($WinCentX+$xRange), ($WinCentY+$yRange), ($WinCentX+$xRange), $WinCentY, $WinCentX, $WinCentY, -fill => 'gray', -outline => 'black'); #create Vert grid fine $id = $canvas->createText ($WinCentX ,20, -text => " PLT values:"); $id = $canvas->createText ($WinCentX ,($WinCentY+$yRange+10), -text => "Inch values:"); for ($i=.25;$i<=18;$i=$i+.25) { $XVal = ($i * $Units)+ $WinCentX ; $PrintXVal = ($i * $Units); $canvas->createLine ($XVal, ($WinCentY+$yRange), $XVal, $WinCentY, -fill => $color); } #create Horiz grid for ($i=.25;$i<=10.75;$i=$i+.25) { $YVal = ($i * $Units) + $WinCentY ; $inchThing = $yY - $i; $pltThing = ($inchThing * $Units); $canvas->createLine ($WinCentX, $YVal, ($WinCentX+$xRange), $YVal, -fill => $color); $Loop = $Loop - 1; } #create Vert grid for ($i=1;$i<=18;$i++) { $XVal = ($i * $Units)+ $WinCentX ; $PrintXVal = ($i * $pltUnits); $canvas->createLine ($XVal, ($WinCentY+$yRange), $XVal, $WinCentY, -fill => 'black'); $id = $canvas->createText ($XVal,20, -text => $PrintXVal); $id = $canvas->createText ($XVal,($WinCentY+$yRange+10), -text => $i); } #create Horiz grid for ($i=0;$i<=10;$i++) { $YVal = ($i * $Units) + $WinCentY ; $inchThing = $yY - $i; $pltThing = ($inchThing * $pltUnits); $canvas->createLine ($WinCentX, $YVal, ($WinCentX+$xRange), $YVal, -fill => 'black' ); $id = $canvas->createText (($WinCentX+$xRange)+15, $YVal, -text => $pltThing); $id = $canvas->createText (($WinCentX-10),$YVal, -text => $inchThing); $Loop = $Loop - 1; } $canvas->createPolygon (50, 820, 350, 820, 350, 870, 50, 870, -fill => 'gray'); $bttnNEW = $canvas->Button(-text => "Open First", -relief => 'ridge', -foreground => "red", -command => sub { &OpenNew }); $id = $canvas->createWindow(50, 800, -window => $bttnNEW); $bttn = $canvas->Button(-text => " Exit ", -relief => 'ridge', -foreground => "red", -command => sub { exit }); $id = $canvas->createWindow(1210, 890, -window => $bttn); MainLoop; sub OpenNew { #my $mw = MainWindow->new; my $top = MainWindow->new; $fs = $top->FileSelect (-directory => Cwd::cwd(), # Alias: -initialdir -initialfile => "fileselect.pl", -filter => "*.plt", -filelabel => "File", -filelistlabel => "Files", -dirlabel => "Current Working Directory", -dirlistlabel => "Directory List", # -verify => ['-T'], # accept only text files ); $XYZFile[$DumbLoop] = $fs->Show; $top->destroy() if Tk::Exists($top); $canvas->createPolygon (50, 820, 350, 820, 350, 870, 50, 870, -fill => 'gray'); $id = $canvas->createText (200,828, -text => $XYZFile[$DumbLoop] ); my @split_XYZFile = split(/\// , $XYZFile[$DumbLoop]); my $XYZFileName = $split_XYZFile[$#split_XYZFile]; $id = $canvas->createText (200,842, -text => $XYZFileName); my @split_XYZFile2 = split(/\./, $XYZFile[$DumbLoop]); my $XYZFileRoot = $split_XYZFile2[0]; my @split_XYZFile3 = split(/\./, $XYZFile[$DumbLoop]); my $XYZFileNum = $split_XYZFile2[1]; $id = $canvas->createText (200,856, -text => $XYZFileRoot . "." . $XYZFileNum . ".txt"); open (FILEHANDLE, $XYZFile[$DumbLoop]); while () { push(@lines,$_) } $listNum = @lines; open (FILEIN, ">" . $XYZFileRoot . "." . $XYZFileNum . ".txt"); $Dele = "IN"; #$Delt = "VS10"; $Delt2 = "SP1"; $Delt3 = ";"; $Delt4 = "PU;PU;SP0;"; $x = "X "; $y = "Y "; $z = "Z "; $PU = "U,"; $PD = "D,"; $uu = "U"; $dd = "D"; $lineNum = 0; open (FILEHANDLE, $XYZFile[$DumbLoop]); while() { chomp; s/$Delt4//g; s/$Dele//g; # s/$Delt//g; s/$Delt2//g; s/$Delt3//g; s///g; s/$uu/$PU/g; s/$dd/$PD/g; print FILEIN ("$_"); print FILEIN ("\n"); $lineNum = $lineNum + 1; } #print $lineNum; #print "\n"; $pVal = "Pen"; $xCord = 0; $yCord = 0; open (FILEIN, $XYZFileRoot . "." . $XYZFileNum . ".txt"); while () { push(@splines,$_) } $listNum2 = @splines; for ($Loop = 0; $Loop < $lineNum; $Loop++){ chomp ($splines[$Loop]); $ThisLine = $splines[$Loop]; my @split_ThisLine = split(/,/, $ThisLine); $pVal[$Loop] = $split_ThisLine[0]; $xCord[$Loop] = $split_ThisLine[1]; $yCord[$Loop] = $split_ThisLine[2]; } $test = 0; $test2 = 0; $test3 = 0; for ($Loop = 0; $Loop < $listNum2; $Loop++){ if ($pVal[$Loop] eq ""){ $test = 0;} if ($pVal[$Loop] ne ""){ $test = 1;} if ($pVal[$Loop+1] eq ""){ $test2 = 0;} if ($pVal[$Loop+1] ne ""){ $test2 = 1;} $test3 = $test + $test2; if ($test3 ==2 ){ $xStart[$Loop] = ($xCord[$Loop]/$DisplayFactor)+$WinCentX; $yStart[$Loop] = ($yRange) - (($yCord[$Loop]/$DisplayFactor)); $xDest[$Loop] = ($xCord[$Loop+1]/$DisplayFactor)+$WinCentX; $yDest[$Loop] = ($yRange) - (($yCord[$Loop+1]/$DisplayFactor)); } } for ($Loop = 0; $Loop < $listNum2; $Loop++){ if ($pVal[$Loop] eq "PD"){ $id = $canvas->createLine ($xStart[$Loop], ($yStart[$Loop]+48), $xDest[$Loop], ($yDest[$Loop]+48), -fill => 'red', -arrow => "last", -arrowshape => [ 3, 4, 2]); } } $DumbLoop++; close (FILEIN); } ################################## #####################################