home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / doctool.tcl < prev    next >
Text File  |  1996-09-18  |  9KB  |  351 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)doctool.tcl    /main/hindenburg/4
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)doctool.tcl    /main/hindenburg/4   18 Sep 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "document.tcl"
  13. require "browserobj.tcl"
  14. # End user added include file section
  15.  
  16.  
  17. Class DocTool : {Object} {
  18.     constructor
  19.     method destructor
  20.     method startCommand
  21.     method generateDocument
  22.     method generateStructure
  23.     method generateStructureAndContents
  24.     method generateContents
  25.     method print
  26.     method updateDocDir
  27.     method updateRepository
  28.     method updateSections
  29.     method setSection
  30.     method removeSection
  31.     method findSection
  32.     method fileToList
  33.     method editDsm
  34.     method getSectionByName
  35.     method getSectionById
  36.     attribute structure
  37.     attribute document
  38.     attribute sectionByName
  39.     attribute sectionById
  40. }
  41.  
  42. constructor DocTool {class this name document} {
  43.     set this [Object::constructor $class $this $name]
  44.     $this document $document
  45.     $this sectionByName [Dictionary new]
  46.     $this sectionById [Dictionary new]
  47.     # Start constructor user section
  48.  
  49.     # check the document directory
  50.     set docDir [[$this document] directory]
  51.     if {$docDir != ""} {
  52.         if ![file exists $docDir] {
  53.             wmtkfatal "Document directory '$docDir' does not \
  54.                     exists or permission denied"
  55.         }
  56.     } else {
  57.         wmtkfatal "Document directory not specified"
  58.     }
  59.  
  60.     # check the clientContext
  61.     set cc [ClientContext::global]
  62.     if [[$cc currentSystem] isNil] {
  63.         # go down to the system
  64.         $cc downLevel [[[$this document] system] name].document
  65.     }
  66.  
  67.     # check if documented system exists
  68.     if [[$document documentedSystem] isNil] {
  69.         wmtkfatal "Invalid documented system."
  70.     }
  71.  
  72.     # get the DSM
  73.     set dsm [[$this document] findFileVersion ${DSysVDbObj::dsmName} dsm]
  74.     if [$dsm isNil] {
  75.         set dsm [[$this document] createFileVersion \
  76.                 ${DSysVDbObj::dsmName} doc 0 dsm matrix \
  77.                 [[$this document] configVersion]]
  78.     }
  79.  
  80.     # make the fileinfo and load the dsm in the fileInfo structure
  81.     $this structure [DocStructure new documentStructure]
  82.     if {[[$this structure] load $dsm] == -1} {
  83.         wmtkerror "Load document structure failed"
  84.     }
  85.  
  86.      set localSections [[$this document] localFileVersions]
  87.     # register all currently available sections
  88.     foreach repObj [[$this document] localFileVersions] {
  89.         $this setSection "[[$repObj file] name]" $repObj
  90.     }
  91.      set fileSections [[$this document] fileVersionReferences]
  92.     foreach repObj [[$this document] fileVersionReferences] {
  93.         $this setSection "[$repObj name]" $repObj
  94.     }
  95.     set propertySections [[$this document] propertyReferences]
  96.     foreach repObj [[$this document] propertyReferences] {
  97.         $this setSection "[rmWhiteSpace [$repObj name]]" $repObj
  98.     }
  99.  
  100.     # update the section with the structure info
  101.     $this updateSections
  102.  
  103.     # End constructor user section
  104.     return $this
  105. }
  106.  
  107. method DocTool::destructor {this} {
  108.     # Start destructor user section
  109.     # End destructor user section
  110. }
  111.  
  112. method DocTool::startCommand {this args} {
  113.  
  114.  
  115.     # return values:
  116.     #    -1: invalid number of args or invalid command
  117.     #    0 : the specified command returned error(s)
  118.     #    1 : the specified command did NOT return error(s)
  119.  
  120.     if {[llength $args] != 2 } {
  121.         wmtkerror "invalid number of params"
  122.         return -1
  123.     }
  124.  
  125.     set editor [[$this document] editor]
  126.     if [catch {$editor connect} reason] {
  127.         wmtkerror "Connect editor failed: $reason"
  128.         return -1
  129.     }
  130.  
  131.     set result -1
  132.  
  133.     # first arg is the command
  134.     # second arg is the objectid file  document structure file
  135.     case "[lindex $args 0]" in {
  136.         {generateDocument} {
  137.             set result [$this generateDocument [lindex $args 1]]
  138.         }
  139.         {generateStructure} {
  140.             set ids [$this fileToList [lindex $args 1]]
  141.             set result [$this generateStructure $ids]
  142.         }
  143.         {generateContents} {
  144.             set ids [$this fileToList [lindex $args 1]]
  145.             set result [$this generateContents $ids]
  146.         }
  147.         {generateStructureAndContents} {
  148.             set ids [$this fileToList [lindex $args 1]]
  149.             set result [$this generateStructureAndContents $ids]
  150.         }
  151.         {print} {
  152.             set ids [$this fileToList [lindex $args 1]]
  153.             set result [$this print $ids]
  154.         }
  155.         {updateDocDir} {
  156.             set ids [$this fileToList [lindex $args 1]]
  157.             set result [$this updateDocDir $ids 0]
  158.         }
  159.         {updateRepository} {
  160.             set ids [$this fileToList [lindex $args 1]]
  161.             set result [$this updateRepository $ids]
  162.         }
  163.         {default} {
  164.             wmtkerror "Unknown command '[lindex $args 0]'"
  165.             set result -1
  166.         }
  167.     }
  168.     catch {$editor disconnect}
  169.  
  170.     return $result
  171. }
  172.  
  173. method DocTool::generateDocument {this structureFile} {
  174.  
  175.     # make sure the dsm version is working
  176.     # create new version if this one is frozen
  177.     return [generator generateDocument $structureFile]
  178. }
  179.  
  180. method DocTool::generateStructure {this objects} {
  181.  
  182.     # make sure the dsm version is working
  183.     # create new version if this one is frozen
  184.     foreach repId $objects {
  185.         set section [$this getSectionById $repId]
  186.         wmtkmessage "Generate structure for section '[$section uiName]'"
  187.         $section generateStructure 0
  188.     }
  189.     return 1
  190. }
  191.  
  192. method DocTool::generateStructureAndContents {this objects} {
  193.  
  194.     # first generate the structure of all the 'objects'
  195.     $this generateStructure $objects
  196.     # then generate the contents
  197.     $this generateContents $objects
  198.     return 1
  199. }
  200.  
  201. method DocTool::generateContents {this objects} {
  202.  
  203.     foreach repId $objects {
  204.         set section [$this getSectionById $repId]
  205.         $section generateContents
  206.     }
  207.     return 1
  208. }
  209.  
  210. method DocTool::print {this objects} {
  211.  
  212.     if {![$this updateDocDir $objects 1]} {
  213.         return 0
  214.     }
  215.  
  216.     foreach repId $objects {
  217.         set section [$this getSectionById $repId]
  218.         wmtkmessage "Print section '[$section uiName]'"
  219.         $section print
  220.     }
  221.     return 1
  222. }
  223.  
  224. method DocTool::updateDocDir {this objects ifNeeded} {
  225.  
  226.     foreach repId $objects {
  227.     set section [$this getSectionById $repId]
  228.     set uiName [$section uiName]
  229.  
  230.     if {$ifNeeded && [$section isDocDirUpToDate]} {
  231.         wmtkmessage "Document directory for section '$uiName' is up to date"
  232.     } else {
  233.         wmtkmessage "Update document directory for section '$uiName'"
  234.         $section updateDocDir
  235.     }
  236.     }
  237.  
  238.     return 1
  239. }
  240.  
  241. method DocTool::updateRepository {this objects} {
  242.  
  243.     set result 1
  244.  
  245.     foreach repId $objects {
  246.         set section [$this getSectionById $repId]
  247.         wmtkmessage "Update repository for section '[$section uiName]'"
  248.         if {![$section updateRepository]} {
  249.             set result 0
  250.             break
  251.         }
  252.     }
  253.  
  254.     if {$result == 0} {
  255.         wmtkerror "Update repository failed"
  256.     }
  257.  
  258.     return $result
  259. }
  260.  
  261. method DocTool::updateSections {this} {
  262.  
  263.  
  264.     # first remove all the structure info from the sections
  265.     foreach section [[$this sectionByName] values] {
  266.         if {![$section isA DocSection]} {
  267.             # it is not a docsection , no reset needed
  268.             continue
  269.         }
  270.         $section indentation 0
  271.         $section _childSectionSet [List new]
  272.         $section _parentSection ""
  273.     }
  274.  
  275.     for {set comp [[$this structure] firstComponent]} \
  276.         {$comp != ""} \
  277.         {set comp [$comp next]} {
  278.         set section [$this findSection [$comp uiName]]
  279.         if {$section == ""} {
  280.             wmtkmessage "[$comp uiName]: section not found"
  281.             continue
  282.         }
  283.         $section indentation [$comp indentation]
  284.         set parSet([$comp indentation]) $section
  285.  
  286.         set parentIndent [$comp indentation]
  287.         incr parentIndent -1
  288.         if {![catch {set parent $parSet($parentIndent)} reason]} {
  289.             $parent addChildSection $section
  290.         }
  291.     }
  292. }
  293.  
  294. method DocTool::setSection {this name section} {
  295.     [$this sectionByName] set $name $section
  296.     [$this sectionById] set [$section identity] $section
  297. }
  298.  
  299. method DocTool::removeSection {this name} {
  300.     set section [[$this sectionByName] set $name]
  301.     [$this sectionByName] unset $name
  302.     [$this sectionById] unset [$section identity]
  303. }
  304.  
  305. method DocTool::findSection {this name} {
  306.     #find the corresponding section
  307.     return [$this getSectionByName [rmWhiteSpace $name]]
  308. }
  309.  
  310. method DocTool::fileToList {this fileName} {
  311.     set fid [open [lindex $fileName 0]]
  312.     set ids [read -nonewline $fid]
  313.     close $fid
  314.     unlink $fileName
  315.     return $ids
  316. }
  317.  
  318. method DocTool::editDsm {this} {
  319.     set struct [$this structure]
  320.     set dsm [$struct diagram]
  321.     if {"[$dsm getInfo Status]" == "frozen"} {
  322.         set sv [$this document]
  323.         set cv [$sv configVersion]
  324.         set dsm [$sv derive -fileVersion $dsm $cv]
  325.  
  326.         # make the fileinfo and load the dsm in the fileInfo structure
  327.         $struct delete
  328.         $this structure [DocStructure new documentStructure]
  329.         if {[[$this structure] load $dsm] == -1} {
  330.             wmtkerror "Load document structure failed"
  331.             return 0
  332.         }
  333.     }
  334.     if {[$struct edit $dsm] == -1} {
  335.         wmtkerror "Edit of document structure failed."
  336.         return 0
  337.     }
  338.     return 1
  339. }
  340.  
  341. # Do not delete this line -- regeneration end marker
  342.  
  343. method DocTool::getSectionByName {this name} {
  344.     return [[$this sectionByName] set $name]
  345. }
  346.  
  347. method DocTool::getSectionById {this id} {
  348.     return [[$this sectionById] set $id]
  349. }
  350.  
  351.