CircuitLayout

 view release on metacpan or  search on metacpan

Examples/GDS2Tool/gds2tool  view on Meta::CPAN

{
    $MW = new MainWindow(
        -background => WhiteColor,
        -foreground => DarkBlueColor, 
    );
}

$MW -> setPalette(
    'activeBackground' => LightBlueColor, 
    'activeForeground' => WhiteColor, 
    'background' => LightGrayColor,
    'foreground' => BlackColor,
);
$MW -> title("GDS2 Tool $VERSION"); 
open(ICON,'>/tmp/gds2tool.xbm');
print ICON dumpIconXbm();
close ICON;
$MW -> iconbitmap('@/tmp/gds2tool.xbm');
`/bin/rm -f /tmp/gds2tool.xbm`;
$MW -> iconname('GDS2Tool'); 
#$MW -> minsize(5, 4); 

###### bottom area #####
my $bottomArea = $MW -> Frame(-relief => 'raised', -borderwidth => 2);
$bottomArea -> pack(
    -fill => 'x', 
    -side => 'bottom', 
); 

### status bar widget
our $G_statusText = "hello $G_user";
my $statusBar = $bottomArea -> Label(
    -anchor       => 'w',
    -borderwidth  => 1,
    -relief       => 'sunken',
    -textvariable => \$G_statusText, 
    -width        => 60,
);

### xy status bar widget
our $G_xyStatusText='x:y';
my $xyStatusBar = $bottomArea -> Label(
    -anchor       => 'w',
    -borderwidth  => 1,
    -relief       => 'sunken',
    -textvariable => \$G_xyStatusText, 
    -width        => 60,
);
### mouse status bar widget
our $G_mouseInfoText='mouse buttons:    nothing  |  nothing  |  nothing';
our $G_mouseMode = 'probe';
my $mouseInfoBar = $bottomArea -> Label(
    -anchor       => 'w',
    -borderwidth  => 1,
    -relief       => 'sunken',
    -textvariable => \$G_mouseInfoText, 
    -width        => 60,
);

###### start top menu bar #####
my $topMenu = $MW -> Frame(-relief => 'raised', -borderwidth => 2);
$topMenu -> pack(-fill => 'x');

$statusBar -> pack(-side => 'bottom', -fill => 'x', -padx => 2, -pady => 2);
$xyStatusBar -> pack(-side => 'right', -fill => 'x', -padx => 2, -pady => 2);
$mouseInfoBar -> pack(-side => 'bottom', -fill => 'x', -padx => 2, -pady => 2);

### canvas
our $G_canvas2;
our $G_canvas = $MW -> WorldCanvas(-height => 300, -width => 500, -bg => BlackColor);
$G_canvas -> configure(-changeView => [\&changeView, $G_canvas2]); ## -configure appends bbox coords...
##$canvas -> configure(-font => '-adobe-courier-bold-r-normal--17-120-*-*-*-*-*-*'); ##TODO 
showViewWindow();
$G_viewWindow -> withdraw;
showGridWindow();
$G_gridWindow -> withdraw;

##### options menu #####
my $fileMenu = $topMenu -> Menubutton(-text => 'File', -underline => 0);
### open
$fileMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Open ...', 
    -command          => sub {
        $G_gds2FileNameIn = $MW -> getOpenFile(
            -defaultextension => '.gds2',
            -filetypes  => [
                ['GDSII Files', ['.gds2' , '.gds', '.sf', '.gdsii']],
                ['All Files', '*'],
            ],
            -initialdir => cwd(),
            -title      => 'GDS2 file',
        );
        if ((defined $G_gds2FileNameIn) && ($G_gds2FileNameIn ne ''))
        {
            if ($topCell eq '')
            {
                $topCell = basename($G_gds2FileNameIn);
                $topCell =~ s|.*/||; ## TODO
                $topCell =~ s/\..*//; ## TODO
                print NOTE,"set cell to $topCell\n";
            }
            readGDS2(-fileName => $G_gds2FileNameIn, -cell => $topCell);       
            $G_canvas -> viewFit(-border => 0, ['layout=true']);
            $G_canvas -> viewFit(-border => 0.02, ['layout=true']);
            #createAxis($G_canvas);
        }
        if ($MW -> colormapfull())
        {
            print WARNING."Colormap is full. Try -privateColorMap command line option\n";
        }
    }, 
);
$fileMenu -> pack(-side=>'left');

### clear
$fileMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -command          => sub { 
        $G_canvas -> delete('all'); 
        $G_canvas2 -> delete('all'); 
        @G_selected = ();
    },
    -label            => 'Clear', 
);
$fileMenu -> pack(-side=>'left');

### quit
$fileMenu -> command(
    -activebackground => RedColor, 
    -activeforeground => WhiteColor, 
    -command          => sub { $MW -> destroy; exit(1); }, 
    -label            => 'Quit', 
);
$fileMenu -> pack(-side=>'left');

### view menu
my $modeMenu = $topMenu -> Menubutton(-text => 'Set Mode', -underline => 0);
#$modeMenu -> separator;

### pan
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Pan', 
    -command          => sub {
        $G_mouseMode = 'pan';
        setCursor();
        $G_mouseInfoText='mouse buttons:    click pan  |  drag pan  |  redraw  ';
        $G_canvas -> CanvasBind('<Button-1>' => [\&pan, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-2>' => sub {
            my ($c) = @_;
            my $e = $c -> XEvent;
            $c -> scan('mark', $e -> x, $e -> y);
        });
        $G_canvas -> CanvasBind('<B2-Motion>' => sub {
            my ($c) = @_;
            my $e = $c -> XEvent;
            $c -> scan('dragto', $e -> x, $e -> y);
        });
        $G_canvas -> CanvasBind('<Button-3>' => \&redraw);
    },
);

### ruler
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Ruler', 
    -command          => sub {
        $G_mouseMode = 'ruler';
        setCursor();
        $G_mouseInfoText='mouse buttons:    ruler  |  multisegment ruler  |  finish ruler';
        $G_canvas -> CanvasBind('<Button-1>' => [\&ruler, 1, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-2>' => [\&ruler, 2, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-3>' => [\&ruler, 0, Ev('x'), Ev('y')]);
    },
);

### select
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Select', 
    -command          => sub {
        $G_mouseMode = 'select';
        setCursor();
        $G_mouseInfoText='mouse buttons:    select  |  add select  |  window select';
        $G_canvas -> CanvasBind('<Button-1>' => [\&selectPoint, TRUE]);
        $G_canvas -> CanvasBind('<Button-2>' => [\&selectPoint, FALSE]);
        $G_canvas -> configure(-bandColor => BrightYellowColor);
        $G_canvas -> CanvasBind('<Button-3>' => sub {
            $G_canvas -> CanvasFocus;
            $G_canvas -> rubberBand(0);
        });
        $G_canvas -> CanvasBind('<B3-Motion>' => sub { $G_canvas -> rubberBand(1); });
        $G_canvas -> CanvasBind('<ButtonRelease-3>' => sub
        {
            my @box = $G_canvas -> rubberBand(2);
            my @ids = $G_canvas -> find('enclosed', @box);
            foreach my $id (@ids)
            {
                push @G_selected, $id;
                my @tags = $G_canvas -> gettags($id);
                my $tags = "@tags";
                $tags =~ s/selected=false/selected=true/;
                @tags=split(/\s/,$tags);
                $G_canvas -> itemconfigure($id,-tags=>\@tags,-stipple=>'',-fill=>undef,-outline=>WhiteColor) if ("@tags" =~ m/type=boundary/);
                $G_canvas -> itemconfigure($id,-tags=>\@tags,-fill=>WhiteColor) if ("@tags" =~ m/type=path/ || "@tags" =~ m/type=text\b/);
            }
        });
    },
);

### unselect
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'unSelect', 
    -command          => sub
    {
        $G_mouseMode = 'unselect';
        setCursor();
        $G_mouseInfoText='mouse buttons:    unselect  |  window inside unselect  |  window outside unselect';
        $G_canvas -> CanvasBind('<Button-1>' => [\&selectPoint, FALSE, FALSE]);
        $G_canvas -> CanvasBind('<Button-2>' => [\&selectPoint, FALSE, FALSE]);
        $G_canvas -> configure(-bandColor => BrightYellowColor);
        $G_canvas -> CanvasBind('<Button-3>' => sub {
            $G_canvas -> CanvasFocus;
            $G_canvas -> rubberBand(0);
        });
        $G_canvas -> CanvasBind('<B3-Motion>' => sub { $G_canvas -> rubberBand(1); });
        $G_canvas -> CanvasBind('<ButtonRelease-3>' => sub
        {
            my @box = $G_canvas -> rubberBand(2);
            my @ids = $G_canvas -> find('enclosed', @box);
            unselectFromArray($G_canvas,@ids);
        });
    },
);

### zoom in
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Zoom In', 
    -command          => sub {
        $G_mouseMode = 'zoom in';
        setCursor();
        $G_mouseInfoText='mouse buttons:    Zoom in window  |  Zoom In x 2  |  Zoom In x 5';
        $G_canvas -> CanvasBind('<Button-1>' => [\&zoom, 0, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-2>' => [\&zoom, 2, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-3>' => [\&zoom, 5, Ev('x'), Ev('y')]);
    },
);


### zoom out 
$modeMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Zoom Out', 
    -command          => sub {
        $G_mouseMode = 'zoom out';
        setCursor();
        $G_mouseInfoText='mouse buttons:    Full size  |  Zoom Out x 2  |  Zoom Out x 5';
        $G_canvas -> CanvasBind('<Button-1>' => [\&zoom, 1, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-2>' => [\&zoom, 0.5, Ev('x'), Ev('y')]);
        $G_canvas -> CanvasBind('<Button-3>' => [\&zoom, 0.2, Ev('x'), Ev('y')]);
    },
);

$modeMenu -> pack(-side=>'left');

### info menu
my $infoMenu = $topMenu -> Menubutton(-text => 'Info', -underline => 0);

### ruler
$infoMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Ruler  (r)', 
    -command          => sub {
        $G_mouseMode = 'ruler';
        setCursor();
        $G_statusText='Enter start coordinate for ruler';
    },
);

$infoMenu -> pack(-side=>'left');

### window menu
my $windowMenu = $topMenu -> Menubutton(-text => 'Windows', -underline => 0);
### grid window
$windowMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Grid', 
    -command          => \&showGridWindow,
);

### info window
$windowMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Info', 
    -command          => \&showInfoWindow,
);

### layer window
$windowMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Layers', 
    -command          => \&showLayerWindow,
);

### 2nd view window
$windowMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Full view', 
    -command          => \&showViewWindow,
);

### binding help
$windowMenu -> command(
    -activebackground => LightBlueColor, 
    -activeforeground => WhiteColor, 
    -label            => 'Key bindings', 
    -command          => \&showKeyBindings,
);
$windowMenu -> pack(-side=>'left');

#######
$MW -> bind( '<Any-KeyPress>' => sub 
    {
        my($c) = @_;
        my $e = $c -> XEvent;
        my( $x, $y, $W, $A ); ## $G_keyLast;
        ( $x, $y, $G_keyLast) = ($e -> x, $e -> y, $e -> K);
        if ($G_keyLast eq 'Escape') ## 
        {
            $G_canvas -> CanvasBind('<Button-1>' => '');
            $G_canvas -> CanvasBind('<Button-2>' => '');
            $G_canvas -> CanvasBind('<Button-3>' => '');
            $G_mouseInfoText='mouse buttons:    nothing  |  nothing  |  nothing';
            $G_mouseMode = 'probe';
        }
        elsif ($G_keyLast eq 'Delete')
        {
            $G_canvas -> delete('type=drawingTmp');
            $G_canvas -> delete('type=rulerTmp');
            $G_canvas -> delete('type=ruler');
        }
        elsif ($G_keyLast eq 'Left') ## pan left
        {
            my $geom = $G_canvas -> geometry();
            my ($xCtr,$yCtr) = split(/[xX]/,$geom);
            $yCtr =~ s/[\+\-].*$//;
            my $amount = $xCtr / 4;
            $xCtr /= 2;
            $yCtr /= 2;
            pan($G_canvas, $xCtr - $amount, $yCtr);
        }
        elsif ($G_keyLast eq 'Right') ## pan Right
        {
            my $geom = $G_canvas -> geometry();
            my ($xCtr,$yCtr) = split(/[xX]/,$geom);
            $yCtr =~ s/[\+\-].*$//;
            my $amount = $xCtr / 4;
            $xCtr /= 2;
            $yCtr /= 2;
            pan($G_canvas, $xCtr + $amount, $yCtr);
        }
        elsif ($G_keyLast eq 'Up') ## pan Up
        {
            my $geom = $G_canvas -> geometry();
            my ($xCtr,$yCtr) = split(/[xX]/,$geom);
            $yCtr =~ s/[\+\-].*$//;
            my $amount = $yCtr / 4;
            $xCtr /= 2;
            $yCtr /= 2;
            pan($G_canvas, $xCtr, $yCtr - $amount);
        }
        elsif ($G_keyLast eq 'Down') ## pan Down
        {
            my $geom = $G_canvas -> geometry();
            my ($xCtr,$yCtr) = split(/[xX]/,$geom);
            $yCtr =~ s/[\+\-].*$//;
            my $amount = $yCtr / 4;
            $xCtr /= 2;
            $yCtr /= 2;



( run in 1.802 second using v1.01-cache-2.11-cpan-39bf76dae61 )