home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cayenne Software Inc. 1996
- #
- # File: @(#)doctool.tcl /main/hindenburg/4
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)doctool.tcl /main/hindenburg/4 18 Sep 1996 Copyright 1996 Cayenne Software Inc.
-
- # Start user added include file section
- require "document.tcl"
- require "browserobj.tcl"
- # End user added include file section
-
-
- Class DocTool : {Object} {
- constructor
- method destructor
- method startCommand
- method generateDocument
- method generateStructure
- method generateStructureAndContents
- method generateContents
- method print
- method updateDocDir
- method updateRepository
- method updateSections
- method setSection
- method removeSection
- method findSection
- method fileToList
- method editDsm
- method getSectionByName
- method getSectionById
- attribute structure
- attribute document
- attribute sectionByName
- attribute sectionById
- }
-
- constructor DocTool {class this name document} {
- set this [Object::constructor $class $this $name]
- $this document $document
- $this sectionByName [Dictionary new]
- $this sectionById [Dictionary new]
- # Start constructor user section
-
- # check the document directory
- set docDir [[$this document] directory]
- if {$docDir != ""} {
- if ![file exists $docDir] {
- wmtkfatal "Document directory '$docDir' does not \
- exists or permission denied"
- }
- } else {
- wmtkfatal "Document directory not specified"
- }
-
- # check the clientContext
- set cc [ClientContext::global]
- if [[$cc currentSystem] isNil] {
- # go down to the system
- $cc downLevel [[[$this document] system] name].document
- }
-
- # check if documented system exists
- if [[$document documentedSystem] isNil] {
- wmtkfatal "Invalid documented system."
- }
-
- # get the DSM
- set dsm [[$this document] findFileVersion ${DSysVDbObj::dsmName} dsm]
- if [$dsm isNil] {
- set dsm [[$this document] createFileVersion \
- ${DSysVDbObj::dsmName} doc 0 dsm matrix \
- [[$this document] configVersion]]
- }
-
- # make the fileinfo and load the dsm in the fileInfo structure
- $this structure [DocStructure new documentStructure]
- if {[[$this structure] load $dsm] == -1} {
- wmtkerror "Load document structure failed"
- }
-
- set localSections [[$this document] localFileVersions]
- # register all currently available sections
- foreach repObj [[$this document] localFileVersions] {
- $this setSection "[[$repObj file] name]" $repObj
- }
- set fileSections [[$this document] fileVersionReferences]
- foreach repObj [[$this document] fileVersionReferences] {
- $this setSection "[$repObj name]" $repObj
- }
- set propertySections [[$this document] propertyReferences]
- foreach repObj [[$this document] propertyReferences] {
- $this setSection "[rmWhiteSpace [$repObj name]]" $repObj
- }
-
- # update the section with the structure info
- $this updateSections
-
- # End constructor user section
- return $this
- }
-
- method DocTool::destructor {this} {
- # Start destructor user section
- # End destructor user section
- }
-
- method DocTool::startCommand {this args} {
-
-
- # return values:
- # -1: invalid number of args or invalid command
- # 0 : the specified command returned error(s)
- # 1 : the specified command did NOT return error(s)
-
- if {[llength $args] != 2 } {
- wmtkerror "invalid number of params"
- return -1
- }
-
- set editor [[$this document] editor]
- if [catch {$editor connect} reason] {
- wmtkerror "Connect editor failed: $reason"
- return -1
- }
-
- set result -1
-
- # first arg is the command
- # second arg is the objectid file document structure file
- case "[lindex $args 0]" in {
- {generateDocument} {
- set result [$this generateDocument [lindex $args 1]]
- }
- {generateStructure} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this generateStructure $ids]
- }
- {generateContents} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this generateContents $ids]
- }
- {generateStructureAndContents} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this generateStructureAndContents $ids]
- }
- {print} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this print $ids]
- }
- {updateDocDir} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this updateDocDir $ids 0]
- }
- {updateRepository} {
- set ids [$this fileToList [lindex $args 1]]
- set result [$this updateRepository $ids]
- }
- {default} {
- wmtkerror "Unknown command '[lindex $args 0]'"
- set result -1
- }
- }
- catch {$editor disconnect}
-
- return $result
- }
-
- method DocTool::generateDocument {this structureFile} {
-
- # make sure the dsm version is working
- # create new version if this one is frozen
- return [generator generateDocument $structureFile]
- }
-
- method DocTool::generateStructure {this objects} {
-
- # make sure the dsm version is working
- # create new version if this one is frozen
- foreach repId $objects {
- set section [$this getSectionById $repId]
- wmtkmessage "Generate structure for section '[$section uiName]'"
- $section generateStructure 0
- }
- return 1
- }
-
- method DocTool::generateStructureAndContents {this objects} {
-
- # first generate the structure of all the 'objects'
- $this generateStructure $objects
- # then generate the contents
- $this generateContents $objects
- return 1
- }
-
- method DocTool::generateContents {this objects} {
-
- foreach repId $objects {
- set section [$this getSectionById $repId]
- $section generateContents
- }
- return 1
- }
-
- method DocTool::print {this objects} {
-
- if {![$this updateDocDir $objects 1]} {
- return 0
- }
-
- foreach repId $objects {
- set section [$this getSectionById $repId]
- wmtkmessage "Print section '[$section uiName]'"
- $section print
- }
- return 1
- }
-
- method DocTool::updateDocDir {this objects ifNeeded} {
-
- foreach repId $objects {
- set section [$this getSectionById $repId]
- set uiName [$section uiName]
-
- if {$ifNeeded && [$section isDocDirUpToDate]} {
- wmtkmessage "Document directory for section '$uiName' is up to date"
- } else {
- wmtkmessage "Update document directory for section '$uiName'"
- $section updateDocDir
- }
- }
-
- return 1
- }
-
- method DocTool::updateRepository {this objects} {
-
- set result 1
-
- foreach repId $objects {
- set section [$this getSectionById $repId]
- wmtkmessage "Update repository for section '[$section uiName]'"
- if {![$section updateRepository]} {
- set result 0
- break
- }
- }
-
- if {$result == 0} {
- wmtkerror "Update repository failed"
- }
-
- return $result
- }
-
- method DocTool::updateSections {this} {
-
-
- # first remove all the structure info from the sections
- foreach section [[$this sectionByName] values] {
- if {![$section isA DocSection]} {
- # it is not a docsection , no reset needed
- continue
- }
- $section indentation 0
- $section _childSectionSet [List new]
- $section _parentSection ""
- }
-
- for {set comp [[$this structure] firstComponent]} \
- {$comp != ""} \
- {set comp [$comp next]} {
- set section [$this findSection [$comp uiName]]
- if {$section == ""} {
- wmtkmessage "[$comp uiName]: section not found"
- continue
- }
- $section indentation [$comp indentation]
- set parSet([$comp indentation]) $section
-
- set parentIndent [$comp indentation]
- incr parentIndent -1
- if {![catch {set parent $parSet($parentIndent)} reason]} {
- $parent addChildSection $section
- }
- }
- }
-
- method DocTool::setSection {this name section} {
- [$this sectionByName] set $name $section
- [$this sectionById] set [$section identity] $section
- }
-
- method DocTool::removeSection {this name} {
- set section [[$this sectionByName] set $name]
- [$this sectionByName] unset $name
- [$this sectionById] unset [$section identity]
- }
-
- method DocTool::findSection {this name} {
- #find the corresponding section
- return [$this getSectionByName [rmWhiteSpace $name]]
- }
-
- method DocTool::fileToList {this fileName} {
- set fid [open [lindex $fileName 0]]
- set ids [read -nonewline $fid]
- close $fid
- unlink $fileName
- return $ids
- }
-
- method DocTool::editDsm {this} {
- set struct [$this structure]
- set dsm [$struct diagram]
- if {"[$dsm getInfo Status]" == "frozen"} {
- set sv [$this document]
- set cv [$sv configVersion]
- set dsm [$sv derive -fileVersion $dsm $cv]
-
- # make the fileinfo and load the dsm in the fileInfo structure
- $struct delete
- $this structure [DocStructure new documentStructure]
- if {[[$this structure] load $dsm] == -1} {
- wmtkerror "Load document structure failed"
- return 0
- }
- }
- if {[$struct edit $dsm] == -1} {
- wmtkerror "Edit of document structure failed."
- return 0
- }
- return 1
- }
-
- # Do not delete this line -- regeneration end marker
-
- method DocTool::getSectionByName {this name} {
- return [[$this sectionByName] set $name]
- }
-
- method DocTool::getSectionById {this id} {
- return [[$this sectionById] set $id]
- }
-
-