home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cayenne Software Inc. 1997
- #
- # File: @(#)exportdiag.tcl /main/titanic/2
- # Author: hale, disc
- # Description: Class to export diagrams to tcl
- #
- #---------------------------------------------------------------------------
- # SccsId = @(#)exportdiag.tcl /main/titanic/2 5 Nov 1997 Copyright 1997 Cayenne Software Inc.
-
- if {![lempty [info commands ExportDiagram2TclDialog]]} {
- return
- }
-
- require platform.tcl
-
- Class ExportDiagram2TclDialog : {TemplateDialog} {
- constructor
- method handleOkPressed
- method handleCancelPressed
- method handleHelpPressed
- method popUp
- method doExport
- method glob
-
- method grabFileName
- method startFileChooser
-
- attribute fileVersions
- attribute fileName
- attribute cursorIndex
- attribute fileType
- attribute exportName
- attribute helpWin
- }
-
- constructor ExportDiagram2TclDialog {class this name} {
- set this [TemplateDialog::constructor $class $this $name]
-
- $this fileName [string trimright [path_name concat [M4Login::getHomeDir] .] .]
- $this fileType "tcl"
- $this helpWin .main.exportdiag2tclHelp
-
- $this config -title "Export" \
- -okPressed "%this handleOkPressed" \
- -helpPressed "%this handleHelpPressed" \
- -cancelPressed "%this handleCancelPressed" \
- -modal 1 \
- -autoPopDown 0
-
- interface DlgColumn $this.c {
- NamedGroup n0 {
- label "Diagrams to be Exported"
- DlgColumn c0 {
- Label diagramName {
- }
- }
- }
-
- Label white1 {
- }
-
- NamedGroup n1 {
- label "Export File"
- DlgColumn c1 {
- SingleLineText fileName {
- columnCount 40
- }
- CheckButton addFileType {
- label "Type defaults to `tcl'"
- state 1
- }
- DlgRow fileRow {
- PushButton grabFileName {
- label "Default Name"
- }
- PushButton startFileChooser {
- label "Browse..."
- }
- }
- }
- }
-
- Label white2 {
- }
-
- NamedGroup n2 {
- label "Export Options"
- DlgColumn c2 {
- CheckButton appendToFile {
- label "Append output to export file"
- state 0
- }
- CheckButton globalView {
- label "Global View (properties are exported at most once)"
- state 0
- }
- CheckButton implicitExport {
- label "Implicit Export (members of CD classes are exported)"
- state 0
- }
- DlgRow levelRow {
- spaceType NONE
- Label levelStart {
- text " Omit levelpath from:"
- }
- OptionMenu defaultLevel {
- entrySet {System Phase Configuration Project N/A}
- selected System
- }
- }
- }
- }
- }
-
- if 0 {
- if {!$win95} {
- foreach item {n0 n1 n2} {
- $this.c.$item font "helvetica-bold-14"
- }
- foreach item {n0.c0.diagramName n1.c1.fileName} {
- $this.c.$item font "courier-normal-12"
- }
- $this.c.n1.c1.addFileType font "times-normal-12"
- foreach item {appendToFile globalView implicitExport levelRow.levelStart} {
- $this.c.n2.c2.$item font "times-normal-12"
- }
- } else {
- foreach item {n0 n1 n2} {
- $this.c.$item font "Arial-bold-14"
- }
- foreach item {n0.c0.diagramName n1.c1.fileName} {
- $this.c.$item font "Courier New-normal-16"
- }
- $this.c.n1.c1.addFileType font "Times New Roman-normal-16"
- foreach item {appendToFile globalView implicitExport levelRow.levelStart} {
- $this.c.n2.c2.$item font "Times New Roman-normal-16"
- }
- }
- } # 0
-
- $this.c.n1.c1.fileRow.startFileChooser activated "$this startFileChooser"
- $this.c.n1.c1.fileRow.grabFileName activated "$this grabFileName"
-
- return $this
- }
-
- method ExportDiagram2TclDialog::handleOkPressed {this} {
- $this fileName [$this.c.n1.c1.fileName text]
- $this cursorIndex [$this.c.n1.c1.fileName cursorIndex]
-
- if {[lempty [path_name base [$this fileName]]]} {
- set box .main.ExportDiagram2TclDialog::checkFileGiven
- if {![isCommand $box]} {
- ErrorDialog new $box \
- -title "Error" \
- -message "No export file specified."
- $box delHelpButton
- }
- $box popUp
- return
- }
-
- set toFile [$this glob [$this fileName]]
- if {[$this.c.n1.c1.addFileType state] && [path_name type $toFile] == ""} {
- regsub {\.[.]*$} $toFile {} toFile
- append toFile ".[$this fileType]"
- }
- $this exportName $toFile
-
- $this doExport
- }
-
-
- method ExportDiagram2TclDialog::handleCancelPressed {this} {
- if {[isCommand [$this helpWin]]} {
- [$this helpWin] popDown
- [$this helpWin] delete
- }
- }
-
-
- method ExportDiagram2TclDialog::handleHelpPressed {this} {
- set win [$this helpWin]
- if {![isCommand $win]} {
- TemplateDialog new $win
- $win title "Help on Export"
- $win delCancelButton
- $win delHelpButton
-
- interface DlgColumn $win.c {
- MultiLineText help {
- editable 0
- columnCount 62
- rowCount 25
- }
- }
-
- set file [m4_path_name etc exporthelp.txt]
- if {$win95} {
- if {[catch {set fd [open $file r]} reason]} {
- wmtkerror $reason
- return
- }
- $win.c.help text [read $fd]
- close $fd
- # $win.c.help font "Courier New-normal-16"
- } else {
- $win.c.help readFile $file
- }
- }
- $win popUp
- }
-
-
- method ExportDiagram2TclDialog::popUp {this fileVersions} {
- $this fileVersions $fileVersions
-
- set nrFiles [llength $fileVersions]
- set tail ""
- if {$nrFiles > 1} {
- set tail s
- }
- $this.c.n0 label "Diagram$tail to be Exported"
-
- set diags ""
- set pro ""
- foreach fileV $fileVersions {
- set diags "${diags}${pro}[[$fileV file] qualifiedName].[[$fileV file] type]"
- if {$nrFiles > 1 && $pro != ""} {
- break
- }
- set pro ", "
- }
- if {$nrFiles > 2} {
- set diags "$diags, ..."
- }
- $this.c.n0.c0.diagramName text $diags
-
- $this.c.n1.c1.fileName text [$this fileName]
- $this cursorIndex [string length [$this fileName]]
- $this.c.n1.c1.fileName cursorIndex [$this cursorIndex]
-
- return [$this TemplateDialog::popUp]
- }
-
-
- method ExportDiagram2TclDialog::doExport {this {doCheck 1}} {
- # handle file name on MS Windows platform
- set fileName [list [$this exportName]]
-
- set implicit [$this.c.n2.c2.implicitExport state]
- set global [$this.c.n2.c2.globalView state]
- set defLevel [$this.c.n2.c2.levelRow.defaultLevel selected]
- set append [$this.c.n2.c2.appendToFile state]
- set args {}
-
- if {!$implicit} {
- lappend args "-e"
- }
- if {$global} {
- lappend args "-g"
- }
- if {$defLevel != "N/A"} {
- switch $defLevel {
- Project {set level proj}
- Configuration {set level conf}
- Phase {set level phase}
- default {set level system}
- }
- lappend args "-d$level"
- }
- if {$append} {
- set outArg "$fileName a"
- } else {
- set outArg "$fileName w"
- }
-
- if {$doCheck && [file exists [join $fileName]] && !$append} {
- set box .main.ExportDiagram2TclDialog::checkFileExists
- if {![isCommand $box]} {
- YesNoWarningDialog new $box \
- -title "Warning" \
- -yesPressed "$this doExport 0"
- $box delHelpButton
- $box delCancelButton
- }
- $box message "File `[join $fileName]' already exists. Overwrite?"
- $box popUp
- return
- }
-
- set tmpFile [BasicFS::tmpFile]
- if {[catch {set fd [open $tmpFile w]} reason]} {
- wmtkerror $reason
- return
- }
- puts $fd $args
- puts $fd $outArg
- foreach fileV [$this fileVersions] {
- puts $fd [$fileV identity]
- }
- close $fd
-
- if {[isCommand [$this helpWin]]} {
- [$this helpWin] popDown
- [$this helpWin] delete
- }
- $this popDown
-
- set script "[m4_path_name bin otsh$EXE_EXT] \
- -f [m4_path_name tcl exportetfe.tcl] \
- -- $tmpFile"
- .main startCommand mtool $script "" "Starting OTSh..." {0 0} 0
- }
-
-
- method ExportDiagram2TclDialog::glob {this d} {
- return [path_name concat [file dirname $d] [file tail $d]]
- }
-
-
- method ExportDiagram2TclDialog::grabFileName {this} {
- set curFileName [$this.c.n1.c1.fileName text]
- set curPath [path_name directory $curFileName]
-
- if {[llength [$this fileVersions]] > 1} {
- set systemVersion [[ClientContext::global] currentSystem]
- set newFileName [path_name concat $curPath \
- [[$systemVersion system] name]]
- } else {
- set fileVersion [lindex [$this fileVersions] 0]
- set newFileName [path_name concat $curPath \
- [[$fileVersion file] name]]
- }
-
- $this.c.n1.c1.fileName text $newFileName
- $this.c.n1.c1.fileName cursorIndex [string length $newFileName]
- }
-
-
- method ExportDiagram2TclDialog::startFileChooser {this} {
- uplevel #0 {
- require classmaker.tcl
- }
-
- set box .main.ExportDiagram2TclDialog::fileChooser
- if {![isCommand $box]} {
- set filter "*.tcl"
- if {$win95} {
- set filter "TCL Files (*.tcl)|*.tcl|All Files (*.*)|*|"
- }
- ClassMaker::extend FileChooser MyClass myAttr
- MyClass new $box \
- -myAttr $this \
- -selectionPolicy SINGLE \
- -title "Export" \
- -filter $filter \
- -cancelPressed {%this delete} \
- -okPressed {
- set newFileName \
- [lindex [.main.ExportDiagram2TclDialog::fileChooser \
- selectedSet] 0]
- [%this myAttr].c.n1.c1.fileName text $newFileName
- [%this myAttr].c.n1.c1.fileName cursorIndex \
- [string length $newFileName]
- }
- $box delHelpButton
- }
- $box directory [path_name directory [$this.c.n1.c1.fileName text]]
- $box popUp
- }
-