home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Westmount Technology 1994
- #
- # File: @(#)print.tcl /main/hindenburg/2
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)print.tcl /main/hindenburg/2 9 Jan 1997 Copyright 1994 Westmount Technology
-
- # Start user added include file section
-
- global Print::options
- set Print::options {
- doPrintBox title scale autoScale orientation horNumPages verNumPages
- pageWidth pageHeight file type printer configVersion systemVersion
- }
-
- # End user added include file section
-
-
- Class Print : {Object} {
- constructor
- method destructor
- }
-
- constructor Print {class this name} {
- set this [Object::constructor $class $this $name]
- # Start constructor user section
- # End constructor user section
- return $this
- }
-
- method Print::destructor {this} {
- # Start destructor user section
- # End destructor user section
- }
-
-
- # Print diagrams.
- #
- proc Print::printDiagrams {args} {
- Print::processOptions options i $args
- set diagrams [lrange $args $i end]
-
- # Process context.
- #
- eval [[ClientContext::global] getCustomFileContents printbox tcl tcl]
- if {![info exists options(configVersion)]} {
- error "exportDiagram needs -configVersion <configVersion>"
- }
- if {![info exists options(systemVersion)]} {
- error "exportDiagram needs -systemVersion <systemVersion>"
- }
-
- # Configure Printer.
- #
- set printer [Printer new]
- if [info exists options(pageWidth)] {
- $printer pageWidth $options(pageWidth)
- }
- if [info exists options(pageHeight)] {
- $printer pageHeight $options(pageHeight)
- }
- if [info exists options(printer)] {
- $printer id $options(printer)
- }
- if [info exists options(title)] {
- set title $options(title)
- } else {
- set diag [lindex $diagrams 0]
- set file [$diag file]
- set title "[$file qualifiedName :].[$file type]"
- }
-
- # Open printer.
- #
- if [info exists options(file)] {
- if [catch {$printer openFile $title $options(file)} msg] {
- wmtkerror $msg
- return
- }
- } else {
- if [catch {$printer openPrinter $title} msg] {
- wmtkerror $msg
- return
- }
- }
-
- # Print each diagram in the list.
- #
- foreach diag $diagrams {
- set file [$diag file]
- set diagName "[$file qualifiedName :].[$file type]"
- wmtkmessage "Printing diagram '$diagName'..."
- set type [string toupper [$file type]]
- set printOut [${type}PrintOut new -diagram $diag \
- -infoBoxSize [expr {${DiagramPrintOut::offset} + 2}] \
- -infoBoxLocation ${DiagramPrintOut::location} ]
- if {$type == "CAD"} {
- $printOut config \
- -configVersion $options(configVersion) \
- -systemVersion $options(systemVersion) \
- }
- Print::setOptions $printOut options
- $printer print $printOut
- $printOut delete
- }
- if [catch {$printer close} msg] {
- wmtkerror $msg
- }
- wmtkmessage "Done"
- $printer delete
- }
-
-
- # Export a diagram to a file in a certain format.
- #
- proc Print::exportDiagram {args} {
- Print::processOptions options i $args
-
- set diag [lrange $args $i end]
- set file [$diag file]
- set diagName "[$file qualifiedName :].[$file type]"
- wmtkmessage "Exporting diagram '$diagName'..."
-
- # Process context.
- #
- if {![info exists options(configVersion)]} {
- error "exportDiagram needs -configVersion <configVersion>"
- }
- if {![info exists options(systemVersion)]} {
- error "exportDiagram needs -systemVersion <systemVersion>"
- }
-
- # Configure Printer.
- #
- set printer [Printer new]
- if [info exists options(pageWidth)] {
- $printer pageWidth $options(pageWidth)
- }
- if [info exists options(pageHeight)] {
- $printer pageHeight $options(pageHeight)
- }
- if [info exists options(printer)] {
- $printer id $options(printer)
- }
- if [info exists options(title)] {
- set title $options(title)
- } else {
- set title $diagName
- }
- if {![info exists options(file)]} {
- error "exportDiagram needs -file option"
- }
- set file $options(file)
- if {![info exists options(type)]} {
- error "exportDiagram needs -type option"
- }
- set exportType $options(type)
-
- # Export the diagram.
- #
- set type [string toupper [[$diag file] type]]
- set printOut [${type}PrintOut new -diagram $diag]
- if {$type == "CAD"} {
- $printOut config \
- -configVersion $options(configVersion) \
- -systemVersion $options(systemVersion) \
- }
- Print::setOptions $printOut options
- # Export is always without info box, single page, auto-scale.
- $printOut doInfoBox 0
- $printOut horNumPages 1
- $printOut verNumPages 1
- $printOut autoScale 1
-
- if [catch {
- $printer printEncapsulated $printOut $title $file $exportType
- } msg] {
- wmtkerror $msg
- }
- $printer delete
- wmtkmessage "Done"
- }
-
- proc Print::processOptions {options_array index argv} {
- upvar $options_array options
- upvar $index i
- foreach opt ${Print::options} {
- set $opt ""
- set isOpt($opt) 1
- }
- set argc [llength $argv]
- for {set i 0} {$i < $argc} {incr i} {
- set arg [lindex $argv $i]
- if {[string range $arg 0 0] != "-"} {
- break
- }
- set opt [string range $arg 1 end]
- if {![info exists isOpt($opt)]} {
- error "unknown option $arg"
- }
- incr i
- set options($opt) [lindex $argv $i]
- }
- }
-
-
- # Set print options in $printOut. Command line options in 'options_array'
- # override options saved in the diagram, which override the defaults.
- #
- proc Print::setOptions {printOut options_array} {
- upvar $options_array options
- set diag [$printOut diagram]
- set props [PIPropInfo new]
- $props load $diag
- if [info exists options(doPrintBox)] {
- $printOut doInfoBox $options(doPrintBox)
- } else {
- set doInfoBox [$props getProperty M4_print_box]
- if {$doInfoBox != ""} {
- $printOut doInfoBox $doInfoBox
- }
- }
- if [info exists options(title)] {
- $printOut title $options(title)
- } else {
- set title [$props getProperty M4_ps_title]
- if {$title != ""} {
- $printOut title $title
- }
- }
- if [info exists options(scale)] {
- $printOut scale $options(scale)
- } else {
- set scale [$props getProperty M4_ps_scale]
- if {$scale != ""} {
- $printOut scale $scale
- }
- }
- if [info exists options(autoScale)] {
- $printOut autoScale $options(autoScale)
- } else {
- set autoScale [$props getProperty M4_ps_auto_scale]
- if {$autoScale != ""} {
- $printOut autoScale $autoScale
- }
- }
- if [info exists options(orientation)] {
- $printOut landscape [expr {$options(orientation) == "landscape"}]
- } else {
- set landscape [$props getProperty M4_ps_mode]
- if {$landscape != ""} {
- $printOut landscape [expr {$landscape == "landscape"}]
- }
- }
- if [info exists options(horNumPages)] {
- $printOut horNumPages $options(horNumPages)
- } else {
- set horNumPages [$props getProperty M4_ps_columns]
- if {$horNumPages != ""} {
- $printOut horNumPages $horNumPages
- }
- }
- if [info exists options(verNumPages)] {
- $printOut verNumPages $options(verNumPages)
- } else {
- set verNumPages [$props getProperty M4_ps_rows]
- if {$verNumPages != ""} {
- $printOut verNumPages $verNumPages
- }
- }
- $props delete
- }
-
- # Do not delete this line -- regeneration end marker
-
-