home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / diagramedi.tcl < prev    next >
Text File  |  1997-03-07  |  29KB  |  1,043 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           @(#)diagramedi.tcl    /main/hindenburg/15
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)diagramedi.tcl    /main/hindenburg/15   7 Mar 1997 Copyright 1997 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12.  
  13. require edwmtarea.tcl
  14. require edpropcont.tcl
  15. require propstruct.tcl
  16. require labelpartn.tcl
  17. require showversio.tcl
  18. require systemutil.tcl
  19. require editoropti.tcl
  20. require m4vardescr.tcl
  21.  
  22. # Hidden component types.
  23. #
  24. global hiddenCompTypes
  25.  
  26. set hiddenCompTypes(link_attrib) 1
  27.  
  28. set hiddenCompTypes(attribute) 1
  29. set hiddenCompTypes(method) 1
  30. set hiddenCompTypes(parameter) 1
  31.  
  32. set hiddenCompTypes(activity) 1
  33. set hiddenCompTypes(state_action) 1
  34.  
  35. global compIndent
  36. set compIndent [Dictionary new -contents {
  37.     parameter    "        "
  38.     attribute    "    "
  39.     method        "    "
  40.     link_attrib    "    "
  41.     activity    "    "
  42.     state_action    "    "
  43. }]
  44.  
  45. # End user added include file section
  46.  
  47. require "wmttool.tcl"
  48.  
  49. Class DiagramEditor : {WmtTool MainWindow} {
  50.     method destructor
  51.     constructor
  52.     method createEdAreaPopUpMenu
  53.     method startEdit
  54.     method context
  55.     method fileVersion
  56.     method changeFileVersion
  57.     method addFileHistory
  58.     method historyActivated
  59.     method renumberFileHistory
  60.     method setFileHistory
  61.     method saveFileHistory
  62.     method addContextArea
  63.     method updateToolBar
  64.     method updateWmtArea
  65.     method editProperties
  66.     method removeProperties
  67.     method showProperties
  68.     method createPropContainers
  69.     method editDiagramProperties
  70.     method removeDiagramProperties
  71.     method showDiagramProperties
  72.     method createDiagPropContainer
  73.     method indent
  74.     method releasePropContainers
  75.     method startReport
  76.     method save
  77.     method edit
  78.     method push
  79.     method doEdit
  80.     method read
  81.     method doRead
  82.     method print
  83.     method doPrint
  84.     method openByName
  85.     method open
  86.     method close
  87.     method doClose
  88.     method exit
  89.     method doExit
  90.     method newEditor
  91.     method askDecName
  92.     method decompose
  93.     method zoom
  94.     method popupNotSaved
  95.     method popupCloseExit
  96.     method popUpPrintOptions
  97.     method popUpNameDialog
  98.     method popUpScopeDialog
  99.     method enDisableMenuEntries
  100.     method helpOnContext
  101.     method helpOnName
  102.     method checkContents
  103.     method checkLocalModel
  104.     method removeUnreferencedItems
  105.     method createOpenByName
  106.     method editorArea
  107.     method addPropContainer
  108.     method removePropContainer
  109.     attribute _fileVersion
  110.     attribute systemVersion
  111.     attribute configVersion
  112.     attribute fileStack
  113.     attribute selectedItem
  114.     attribute historyCount
  115.     attribute selPopDlg
  116.     attribute permanentReadOnly
  117.     attribute m4VarDes
  118.     attribute options
  119.     attribute openByNameDlg
  120.     attribute printOptions
  121.     attribute openKnowledgeDB
  122.     attribute propKnowledgeDB
  123.     attribute panel
  124.     attribute _editorArea
  125.     attribute moduleHdlr
  126.     attribute genericMenuHdlr
  127.     attribute specificMenuHdlr
  128.     attribute objHdlr
  129.     attribute propContainerSet
  130.     attribute readDiagram
  131.     attribute closeExit
  132.     attribute notSaved
  133.     attribute fileHistorySet
  134.     attribute wmtArea
  135. }
  136.  
  137. method DiagramEditor::destructor {this} {
  138.     # Start destructor user section
  139.  
  140.     $this saveToolBarPresence ude
  141.     $this saveContextAreaPresence ude
  142.     $this saveMessageAreaPresence ude
  143.  
  144.     [$this options] delete
  145.     [$this propKnowledgeDB] delete
  146.     [$this openKnowledgeDB] delete
  147.     [$this genericMenuHdlr] delete
  148.     if [isCommand [$this objHdlr]] {
  149.         [$this objHdlr] delete
  150.     }
  151.  
  152.     # End destructor user section
  153.     $this WmtTool::destructor
  154. }
  155.  
  156. constructor DiagramEditor {class this name} {
  157.     set this [MainWindow::constructor $class $this $name]
  158.     WmtTool::constructor $class $this $name
  159.  
  160.     $this m4VarDes [M4VarDescription new $this.m4VarDes]
  161.     $this options [EditorOptions new $this.options]
  162.  
  163.     MenuBar new $this.bar
  164.     $this genericMenuHdlr [CustEdMenuHandler new diagram]
  165.     $this setToolBarPresence ude
  166.     DlgColumn new $this.c
  167.     $this setContextAreaPresence ude
  168.     HorSeparator new $this.c.sep
  169.     DlgRow new $this.c.r -spaceType NONE
  170.     $this setMessageAreaPresence ude
  171.  
  172.     $this config \
  173.         -propContainerSet [List new] \
  174.         -fileHistorySet [List new] \
  175.         -historyCount 0 \
  176.         -permanentReadOnly 0 \
  177.         -closed {%this exit} \
  178.         -exitButton [$this menuBar].file.menu.exit \
  179.         -propKnowledgeDB [PropKnowledgeDB new $this.propKnowledgeDB] \
  180.         -openKnowledgeDB [OpenKnowledgeDB new $this.openKnowledgeDB]
  181.  
  182.     # Use some trickery to set the right icon
  183.     $this icon [$this diagramType]e
  184.     $this iconTitle [string toupper [$this icon]]
  185.  
  186.     global classCount
  187.     set classCount 1
  188.     # take care of the generic entries
  189.     [$this genericMenuHdlr] setCurrentContext
  190.  
  191.     ClassMaker::extend CustMenuPushButton HistMenuButton file
  192.  
  193.     return $this
  194. }
  195.  
  196. method DiagramEditor::createEdAreaPopUpMenu {this} {
  197.     EdAreaPopUpMenu new [$this editorArea].pop -poppedUp {
  198.         [.main editorArea].pop entrySet [concat \
  199.             [[.main genericMenuHdlr] getValidPopUpEntrySet] \
  200.             [[.main specificMenuHdlr] getValidPopUpEntrySet]]
  201.     }
  202. }
  203.  
  204. method DiagramEditor::startEdit {this fv} {
  205.     $this setFileHistory [[$fv file] type]
  206.     $this edit $fv
  207. }
  208.  
  209. method DiagramEditor::context {this} {
  210.     set corp [[ClientContext::global] currentCorporate]
  211.     set configV [$this configVersion]
  212.     set systemV [$this systemVersion]
  213.     set fileV [$this fileVersion]
  214.     set proj [$configV project]
  215.     set phaseV [$configV findPhaseVersion -byPhase [$systemV phase]]
  216.     return "$corp $proj $configV $phaseV $systemV $fileV"
  217. }
  218.  
  219. method DiagramEditor::fileVersion {this {fv -}} {
  220.     if {$fv == "-"} {
  221.         return [$this _fileVersion]
  222.     }
  223.     $this changeFileVersion $fv
  224.  
  225.     set context [$this context]
  226.     set cc [ClientContext::global]
  227.     set cntStr /[[lvarpop context] identity]
  228.     append cntStr /[[lvarpop context] identity]
  229.     append cntStr /[[lvarpop context] identity]
  230.     append cntStr /[[lvarpop context] identity]
  231.     append cntStr /[[lvarpop context] identity]
  232.     if {![$fv isNil]} {
  233.         append cntStr /[$fv identity]
  234.         $this addFileHistory [$fv file]
  235.     }
  236.     $cc setLevelIds $cntStr
  237. }
  238.  
  239. method DiagramEditor::changeFileVersion {this fv} {
  240.     if [$fv isNil] {
  241.         set name ""
  242.     } else {
  243.         set name [[$fv file] qualifiedName :]
  244.     }
  245.     $this _fileVersion $fv
  246.     $this iconTitle $name
  247.  
  248.     set title [$this title]
  249.     set hyphen [string last "-" $title]
  250.     if {$hyphen < 0} {
  251.         set title "- $title"
  252.     } else {
  253.         set title [string range $title $hyphen end]
  254.     }
  255.     set title "$name $title"
  256.     $this title $title
  257. }
  258.  
  259. method DiagramEditor::addFileHistory {this file} {
  260.     set index [expr [[$this exitButton] index] - 1 - \
  261.             [[$this fileHistorySet] length]]
  262.     [$this fileHistorySet] foreach entry {
  263.         if {$file != [$entry file]} {
  264.             continue
  265.         }
  266.         [$this fileHistorySet] removeValue $entry
  267.         [$this fileHistorySet] insert $entry
  268.         $this renumberFileHistory
  269.         $entry index $index
  270.         return
  271.     }
  272.  
  273.     set latest [expr [$this historyCount] + 1]
  274.     HistMenuButton new [$this menuBar].file.menu.his$latest \
  275.         -label "1 [$file qualifiedName :]" -mnemonic 1 -file $file \
  276.         -operations edit -activated "$this historyActivated %this" \
  277.         -index $index -hintText "Opens [$file qualifiedName :]."
  278.     [$this fileHistorySet] insert [$this menuBar].file.menu.his$latest
  279.     $this historyCount $latest
  280.     $this renumberFileHistory
  281.  
  282.     if {[[$this fileHistorySet] length] > 5} {
  283.         [[$this fileHistorySet] index end] delete
  284.         [$this fileHistorySet] remove end
  285.     }
  286. }
  287.  
  288. method DiagramEditor::historyActivated {this entry} {
  289.     set fv [[$this systemVersion] findFileVersion -byFile [$entry file]]
  290.     if [$fv isNil] {
  291.         wmtkerror "No version of [[$entry file] qualifiedName :] found"
  292.         [$this fileHistorySet] removeValue $entry
  293.         $this renumberFileHistory
  294.         $entry delete
  295.     } else {
  296.         $this edit $fv
  297.     }
  298. }
  299.  
  300. method DiagramEditor::renumberFileHistory {this} {
  301.     set m 1
  302.     set sv [$this systemVersion]
  303.     [$this fileHistorySet] foreach entry {
  304.         if [[$sv findFileVersion -byFile [$entry file]] isNil] {
  305.             $entry delete
  306.             [$this fileHistorySet] removeValue $entry
  307.             $this renumberFileHistory
  308.             return
  309.         }
  310.         $entry config -mnemonic $m \
  311.             -label "$m [[$entry file] qualifiedName :]"
  312.         incr m
  313.     }
  314. }
  315.  
  316. method DiagramEditor::setFileHistory {this context} {
  317.     set history [m4_var get M4_file_history -context $context]
  318.     if {"$history" == ""} {
  319.         return
  320.     }
  321.     if {[[[$this systemVersion] system] identity] != [lindex $history 0]} {
  322.         return
  323.     }
  324.     set history [lrange $history 1 [expr [llength $history] - 1]]
  325.     foreach fileId $history {
  326.         catch {$this addFileHistory [File new $fileId]}
  327.     }
  328. }
  329.  
  330. method DiagramEditor::saveFileHistory {this context} {
  331.     set history [[[$this systemVersion] system] identity]
  332.     [$this fileHistorySet] foreach entry {
  333.         set history [linsert $history 1 [[$entry file] identity]]
  334.     }
  335.     if {$history != [m4_var get M4_file_history -context $context]} {
  336.         m4_var set M4_file_history $history -context $context
  337.     }
  338. }
  339.  
  340. method DiagramEditor::addContextArea {this} {
  341.     $this wmtArea [EdWmtArea new $this.c.wmtArea]
  342. }
  343.  
  344. method DiagramEditor::updateToolBar {this} {
  345.     [$this genericMenuHdlr] setCurrentContext
  346.     [$this specificMenuHdlr] setCurrentContext
  347. }
  348.  
  349. method DiagramEditor::updateWmtArea {this} {
  350.     if {[$this wmtArea] != ""} {
  351.         [$this wmtArea] notify
  352.     }
  353. }
  354.  
  355. method DiagramEditor::editProperties {this} {
  356.     busy {
  357.         set editorArea [$this editorArea]
  358.         if [catch {
  359.             set selComps [$editorArea editSelectedComponents]
  360.         } msg] {
  361.             wmtkerror $msg
  362.             return
  363.         }
  364.         $this createPropContainers $selComps 1
  365.         if {[[$this propContainerSet] contents] == ""} {
  366.             wmtkerror "There are no properties defined for the selected object(s)"
  367.             return
  368.         }
  369.         # Don't reuse a PropertyDialog:
  370.         # The initial size does not change to fit new contents.
  371.         uplevel #0 require propertydi.tcl
  372.         PropertyDialog new $this.editProperties $this \
  373.             -editable 1 \
  374.             -title "Edit Properties" \
  375.             -helpPressed {.main helpOnName editProperties}
  376.         $this.editProperties popUp
  377.     }
  378. }
  379.  
  380. method DiagramEditor::removeProperties {this} {
  381.     busy {
  382.         set editorArea [$this editorArea]
  383.         if [catch {
  384.             set selComps [$editorArea editSelectedComponents]
  385.         } msg] {
  386.             wmtkerror $msg
  387.             return
  388.         }
  389.         $this createPropContainers $selComps 1
  390.         # Don't reuse a RmPropDialog:
  391.         # The initial size does not change to fit new contents.
  392.         uplevel #0 require rmpropdial.tcl
  393.         RmPropDialog new $this.removeProperties $this \
  394.             -title "Delete Properties" \
  395.             -helpPressed {.main helpOnName selectMany}
  396.         $this.removeProperties popUp
  397.     }
  398. }
  399.  
  400. method DiagramEditor::showProperties {this} {
  401.     busy {
  402.         set editorArea [$this editorArea]
  403.         if [catch {
  404.             set selComps [$editorArea getSelectedComponents]
  405.         } msg] {
  406.             wmtkerror $msg
  407.             return
  408.         }
  409.         $this createPropContainers $selComps 0
  410.         if {[[$this propContainerSet] contents] == ""} {
  411.             wmtkerror "There are no properties defined for the selected object(s)"
  412.             return
  413.         }
  414.         # Don't reuse a PropertyDialog:
  415.         # The initial size does not change to fit new contents.
  416.         uplevel #0 require propertydi.tcl
  417.         PropertyDialog new $this.editProperties $this \
  418.             -editable 0 \
  419.             -title "Show Properties" \
  420.             -helpPressed {.main helpOnName editProperties}
  421.         $this.editProperties popUp
  422.     }
  423. }
  424.  
  425. method DiagramEditor::createPropContainers {this selComps edit} {
  426.     set propStructList [List new]
  427.     set configV [$this configVersion]
  428.     set phaseV [[ClientContext::global] currentPhase]
  429.     set fileV [$this fileVersion]
  430.     set propKnowledgeDB [$this propKnowledgeDB]
  431.     PropLocation new .propLocation \
  432.         -phaseType [[$phaseV phase] type] \
  433.         -diagramType [[$fileV file] type]
  434.     set maxNameLength 0
  435.     foreach obj $selComps {
  436.         set count 0
  437.         set labs [llength [$obj labelSet]]
  438.         .propLocation componentType [$obj type]
  439.         if {[$obj getProperty initiator] == 1} {
  440.             .propLocation condition "INITIATOR"
  441.         } elseif {[$obj getProperty key] == 1} {
  442.             .propLocation condition "KEY"
  443.         } else {
  444.             .propLocation condition "NOKEY"
  445.         }
  446.         set indent [$this indent [$obj type]]
  447.         foreach lab [$obj labelSet] {
  448.             .propLocation labelType [$lab type]
  449.             foreach itm [$lab itemRefSet] {
  450.                 .propLocation containerKind Component
  451.                 .propLocation containerType [$obj type]
  452.                 set compPropDefs [$propKnowledgeDB \
  453.                         definitions .propLocation]
  454.                 .propLocation containerKind Item
  455.                 .propLocation containerType [$itm type]
  456.                 set itemPropDefs [$propKnowledgeDB \
  457.                         definitions .propLocation]
  458.                 if {"$compPropDefs$itemPropDefs" == ""} {
  459.                     continue
  460.                 }
  461.                 set objName $indent[$itm itemName]
  462.                 set objNameLength [string length $objName]
  463.                 if {$objNameLength > $maxNameLength} {
  464.                     set maxNameLength $objNameLength
  465.                 }
  466.                 set labIdx [$obj type],[$lab type],[$itm type]
  467.                 if [info exists labelPartName($labIdx)] {
  468.                     set objType $labelPartName($labIdx)
  469.                 } else {
  470.                     set objType [$obj longName]
  471.                     if {$labs > 1} {
  472.                         set labType [$lab longName]
  473.                         set objType "$objType $labType"
  474.                     }
  475.                 }
  476.                 $propStructList append [PropStruct new \
  477.                     -name $objName \
  478.                     -type $objType \
  479.                     -compPropDefs $compPropDefs \
  480.                     -containerKey [.propLocation asString] \
  481.                     -component $obj \
  482.                     -itemRef $itm \
  483.                     -itemPropDefs $itemPropDefs]
  484.                 incr count
  485.             }
  486.         }
  487.         if {$count == 0} {
  488.             .propLocation containerKind Component
  489.             .propLocation containerType [$obj type]
  490.             .propLocation labelType ""
  491.             set compPropDefs [$propKnowledgeDB \
  492.                     definitions .propLocation]
  493.             if {[llength $compPropDefs] > 0} {
  494.                 $propStructList append [PropStruct new \
  495.                     -type [$obj longName] \
  496.                     -compPropDefs $compPropDefs \
  497.                     -containerKey [.propLocation asString] \
  498.                     -component $obj]
  499.             }
  500.         }
  501.     }
  502.     .propLocation delete
  503.     set formatString "%-*.*s  %s"
  504.     set cntList [List new]
  505.     $propStructList foreach propStruct {
  506.         set pres [format $formatString $maxNameLength $maxNameLength \
  507.                  [$propStruct name] [$propStruct type]]
  508.         set cnt [EdPropContainer new -editable $edit \
  509.             -propertyKey [$propStruct containerKey] \
  510.             -propertyPresentation $pres \
  511.             -holderComp [$propStruct component] \
  512.             -itemRef [$propStruct itemRef]]
  513.         if {[$cnt getPropInfoMethods]} {
  514.             foreach propDef [$propStruct compPropDefs] {
  515.                 $cnt addPropDefinition $propDef
  516.             }
  517.             foreach propDef [$propStruct itemPropDefs] {
  518.                 $cnt addPropDefinition $propDef
  519.             }
  520.             $cnt storePropInfoMethods
  521.         } else {
  522.             foreach propDef [$propStruct compPropDefs] {
  523.                 $cnt addSpecificPropDef $propDef holderComp
  524.             }
  525.             foreach propDef [$propStruct itemPropDefs] {
  526.                 $cnt addSpecificPropDef $propDef itemPropInfo
  527.             }
  528.             $cnt storePropInfoMethods
  529.         }
  530.         $cntList append $cnt
  531.     }
  532.     $this propContainerSet $cntList
  533. }
  534.  
  535. method DiagramEditor::editDiagramProperties {this} {
  536.     $this createDiagPropContainer 1
  537.     # Don't reuse a PropertyDialog:
  538.     # The initial size does not change to fit new contents.
  539.     uplevel #0 require propertydi.tcl
  540.     PropertyDialog new $this.editProperties $this \
  541.         -editable 1 \
  542.         -title "Edit Diagram Properties" \
  543.         -helpPressed {.main helpOnName editDiagramProperties}
  544.     $this.editProperties popUp
  545. }
  546.  
  547. method DiagramEditor::removeDiagramProperties {this} {
  548.     $this createDiagPropContainer 1
  549.     # Don't reuse a RmPropDialog:
  550.     # The initial size does not change to fit new contents.
  551.     uplevel #0 require rmpropdial.tcl
  552.     RmPropDialog new $this.removeProperties $this \
  553.         -title "Delete Diagram Properties" \
  554.         -helpPressed {.main helpOnName selectMany}
  555.     $this.removeProperties popUp
  556. }
  557.  
  558. method DiagramEditor::showDiagramProperties {this} {
  559.     $this createDiagPropContainer 0
  560.     # Don't reuse a PropertyDialog:
  561.     # The initial size does not change to fit new contents.
  562.     uplevel #0 require propertydi.tcl
  563.     PropertyDialog new $this.editProperties $this \
  564.         -editable 0 \
  565.         -title "Show Diagram Properties" \
  566.         -helpPressed {.main helpOnName editDiagramProperties}
  567.     $this.editProperties popUp
  568. }
  569.  
  570. method DiagramEditor::createDiagPropContainer {this edit} {
  571.     set phase [[[ClientContext::global] currentPhase] phase]
  572.     set file [[$this fileVersion] file]
  573.     PropLocation new .propLocation \
  574.         -containerKind Graph \
  575.         -containerType [$file type] \
  576.         -phaseType [$phase type]
  577.     $this propContainerSet [List new]
  578.     set propDefs [[$this propKnowledgeDB] definitions .propLocation]
  579.     if {[llength $propDefs] == 0} {
  580.         .propLocation delete
  581.         return
  582.     }
  583.     set cnt [EdPropContainer new -editable $edit \
  584.         -propertyKey [.propLocation asString] \
  585.         -propertyPresentation "[$file name]  [$file type]" \
  586.         -diagPropInfo [[$this editorArea] propInfo]]
  587.     foreach propDef $propDefs {
  588.         $cnt addSpecificPropDef $propDef diagPropInfo
  589.     }
  590.     .propLocation delete
  591.     [$this propContainerSet] append $cnt
  592. }
  593.  
  594. method DiagramEditor::indent {this compType} {
  595.     return [$compIndent set $compType]
  596. }
  597.  
  598. method DiagramEditor::releasePropContainers {this} {
  599.     [$this editorArea] releaseSelectedComponents
  600. }
  601.  
  602. method DiagramEditor::startReport {this file comment} {
  603.     if [[$this editorArea] isChanged] {
  604.         $this popupNotSaved "startReportInMtool \"$file\" \"$comment\""
  605.     } else {
  606.         startReportInMtool $file $comment
  607.     }
  608. }
  609.  
  610. method DiagramEditor::save {this} {
  611.     busy {
  612.         wmtkmessage "Saving..."
  613.         [$this editorArea] save
  614.         wmtkmessage "Done"
  615.     }
  616. }
  617.  
  618. method DiagramEditor::edit {this fv} {
  619.     if [[$this editorArea] isChanged] {
  620.         $this popupNotSaved "$this doEdit $fv"
  621.     } else {
  622.         $this doEdit $fv
  623.     }
  624. }
  625.  
  626. method DiagramEditor::push {this fv} {
  627.     set stack [$this fileStack]
  628.     lappend stack [[$this fileVersion] file]
  629.     $this fileStack $stack
  630.     $this doEdit $fv
  631. }
  632.  
  633. method DiagramEditor::doEdit {this fv} {
  634.     busy {
  635.         if {[$this fileVersion] == ""} {
  636.             wmtkmessage "Loading ..."
  637.         } elseif {[$this fileVersion] == $fv ||
  638.               [[$this fileVersion] file] == [$fv file]} {
  639.             wmtkmessage "Reloading ..."
  640.             # dummy call updating cache used for getting status
  641.             $fv initialScope
  642.             if {[$fv status] == "noStatus" ||
  643.                 [$fv status] == "backGround"} {
  644.                 set file [$fv file]
  645.                 set sv [$this systemVersion]
  646.                 set fv [$sv findFileVersion -byFile $file]
  647.                 if [$fv isNil] {
  648.                     set name [$file qualifiedName :]
  649.                     wmtkerror "No version of $name found"
  650.                     return
  651.                 }
  652.             }
  653.         } else {
  654.             wmtkmessage "Loading ..."
  655.         }
  656.         if [$this permanentReadOnly] {
  657.             if [catch {[$this editorArea] load $fv} msg] {
  658.                 wmtkerror $msg
  659.                 set fv [ORB::nil]
  660.                 wmtkmessage "Not done"
  661.             } else {
  662.                 wmtkmessage "Loaded read-only"
  663.             }
  664.             if {[$this fileVersion] != $fv} {
  665.                 $this fileVersion $fv
  666.             }
  667.             return
  668.         }
  669.         if [catch {[$this editorArea] edit $fv} msg] {
  670.             # Edit failed, try load
  671.             if [catch {[$this editorArea] load $fv} loadMsg] {
  672.                 wmtkerror "Edit failed:\n${msg}\nLoad failed:\n$loadMsg"
  673.                 wmtkmessage "Not done"
  674.                 set fv [ORB::nil]
  675.             } else {
  676.                 wmtkmessage "Loaded read-only"
  677.                 wmtkwarning $msg
  678.             }
  679.         } else {
  680.             wmtkmessage Done
  681.         }
  682.         if {[$this fileVersion] != $fv} {
  683.             $this fileVersion $fv
  684.         }
  685.     }
  686. }
  687.  
  688. method DiagramEditor::read {this} {
  689.     set dlg [$this readDiagram]
  690.     if {$dlg == ""} {
  691.         uplevel #0 require readdiagra.tcl
  692.         set dlg [ReadDiagram new $this.read -editor $this]
  693.         $this readDiagram $dlg
  694.     }
  695.     $dlg popUp
  696. }
  697.  
  698. method DiagramEditor::doRead {this fv} {
  699.     busy {
  700.         wmtkmessage "Reading..."
  701.         if [catch {[$this editorArea] read $fv} msg] {
  702.             wmtkerror $msg
  703.             wmtkmessage "Not done"
  704.         } else {
  705.             wmtkmessage Done
  706.         }
  707.     }
  708. }
  709.  
  710. method DiagramEditor::print {this} {
  711.     if [[$this editorArea] isChanged] {
  712.         $this popupNotSaved "$this doPrint"
  713.     } else {
  714.         $this doPrint
  715.     }
  716. }
  717.  
  718. method DiagramEditor::doPrint {this} {
  719.     busy {
  720.         uplevel #0 require print.tcl
  721.         set fv [$this fileVersion]
  722.         set optionsBox [$this printOptions]
  723.         if {$optionsBox != ""} {
  724.             set args [$optionsBox printOptions]
  725.         }
  726.         lappend args -configVersion [$this configVersion]
  727.         lappend args -systemVersion [$this systemVersion]
  728.         lappend args $fv
  729.         eval Print::printDiagrams $args
  730.     }
  731. }
  732.  
  733. method DiagramEditor::openByName {this} {
  734.     uplevel #0 require openbyname.tcl
  735.     set obn [$this openByNameDlg]
  736.     if {$obn == ""} {
  737.         set obn [$this createOpenByName]
  738.         $this openByNameDlg $obn
  739.     }
  740.     if [[$this editorArea] isChanged] {
  741.         $this popupNotSaved "$obn popUp"
  742.     } else {
  743.         $obn popUp
  744.     }
  745. }
  746.  
  747. method DiagramEditor::open {this} {
  748.     if [[$this editorArea] isChanged] {
  749.         return
  750.     }
  751.     busy {
  752.         uplevel #0 require selectitem.tcl
  753.         SelectItem new $this.items -editor $this
  754.         uplevel #0 require opendiagra.tcl
  755.         OpenDiagram new $this.open -editor $this
  756.         $this selPopDlg $this.open
  757.         $this.items popUp
  758.     }
  759. }
  760.  
  761. method DiagramEditor::close {this} {
  762.     if {[llength [$this fileStack]] == 0} {
  763.         $this popupCloseExit "$this exit"
  764.     } elseif [[$this editorArea] isChanged] {
  765.         $this popupNotSaved "$this doClose"
  766.     } else {
  767.         $this doClose
  768.     }
  769. }
  770.  
  771. method DiagramEditor::doClose {this} {
  772.     set stack [$this fileStack]
  773.     set last [llength $stack]
  774.     set file [lindex $stack [incr last -1]]
  775.     $this fileStack [lrange $stack 0 [incr last -1]]
  776.     set sv [$this systemVersion]
  777.     set fv [$sv findFileVersion -byFile $file]
  778.     if [$fv isNil] {
  779.         wmtkerror "No version of [$file qualifiedName :] found"
  780.     } else {
  781.         $this doEdit $fv
  782.     }
  783. }
  784.  
  785. method DiagramEditor::exit {this} {
  786.     if [[$this editorArea] isChanged] {
  787.         $this popupNotSaved "$this doExit"
  788.     } else {
  789.         $this doExit
  790.     }
  791. }
  792.  
  793. method DiagramEditor::doExit {this} {
  794.     $this busy TRUE
  795.     wmtkmessage "Exiting ..."
  796.     [$this editorArea] quit
  797.     $this stop
  798. }
  799.  
  800. method DiagramEditor::newEditor {this sv fv} {
  801.     set dfl [$fv file]
  802.     set fId [$fv identity]
  803.     set sId [$sv identity]
  804.     set cId [[$this configVersion] identity]
  805.     set presName "[$dfl name].[$dfl type]"
  806.     set dflQual [[$dfl item] qualifier]
  807.     if {![$dflQual isNil]} {
  808.         set presName "[$dflQual name]:$presName"
  809.     }
  810.     set msg "Starting ude for '$presName'"
  811.     set script "SystemUtilities::fork otk \
  812.         ude -c [list [get_comm_name]] $fId $sId $cId"
  813.     $this startCommand tcl "$script" "" "$msg" {0 0} 1
  814. }
  815.  
  816. method DiagramEditor::askDecName {this sv qualItem fileType} {
  817.     if {![isCommand $this.askDecName]} {
  818.         ClassMaker::extend EntryDialog DecNameDialog {
  819.                     editor sysVers qualItem fileType}
  820.         DecNameDialog new $this.askDecName \
  821.             -modal yes \
  822.             -editor $this \
  823.             -message Name: \
  824.             -helpPressed {.main helpOnName askDecName} \
  825.             -okPressed {
  826.                 [%this editor] decompose [%this sysVers] \
  827.                 [%this qualItem] [%this entry] [%this fileType]
  828.             }
  829.     }
  830.     $this.askDecName config \
  831.         -title "Create [string toupper $fileType] for [$qualItem name]" \
  832.         -sysVers $sv -qualItem $qualItem -fileType $fileType -entry ""
  833.     $this.askDecName popUp
  834. }
  835.  
  836. method DiagramEditor::decompose {this sv qualItem fileName fileType} {
  837.     set configV [$this configVersion]
  838.     set scopePhase [fileHasScopePhase $fileType]
  839.     set itemType [file2itemtype $fileType]
  840.     set presName "$fileName.$fileType"
  841.     if {$qualItem != ""} {
  842.         set presName "[$qualItem name]:$presName"
  843.     }
  844.     wmtkmessage "Creating '$presName'"
  845.     busy {
  846.         if [catch {
  847.             if {"$qualItem" == ""} {
  848.                 set decFileV [$sv createFileVersion $fileName \
  849.                 $itemType $scopePhase $fileType graph $configV]
  850.             } else {
  851.                 set fItm [$qualItem findCreateItem \
  852.                     $fileName $itemType]
  853.                 set decFileV [$sv createFileVersion $fItm \
  854.                     $scopePhase $fileType graph $configV]
  855.             }
  856.         } msg] {
  857.             wmtkerror $msg
  858.             return
  859.         }
  860.     }
  861.     if {$sv == [$this systemVersion] &&
  862.         $fileType == [[[$this fileVersion] file] type]} {
  863.         $this push $decFileV
  864.     } else {
  865.         $this newEditor $sv $decFileV
  866.     }
  867. }
  868.  
  869. method DiagramEditor::zoom {this factor} {
  870.     busy {
  871.         set area [$this editorArea]
  872.         set scale [expr {[$area scale] * $factor}]
  873.         if {$scale < 0.1} {
  874.             wmtkmessage "Minimum zoom factor reached"
  875.             return
  876.         }
  877.         if {$scale > 3} {
  878.             wmtkmessage "Maximum zoom factor reached"
  879.             return
  880.         }
  881.         wmtkmessage "Scale factor is now [format %.2f $scale]"
  882.         $area scale $scale
  883.     }
  884. }
  885.  
  886. method DiagramEditor::popupNotSaved {this action} {
  887.     set notSaved [$this notSaved]
  888.     if {$notSaved == ""} {
  889.         uplevel #0 require notsaveddi.tcl
  890.         set notSaved [NotSavedDialog new $this.notSaved -editor $this]
  891.         $this notSaved $notSaved
  892.     }
  893.     $notSaved action $action
  894.     $notSaved popUp
  895. }
  896.  
  897. method DiagramEditor::popupCloseExit {this action} {
  898.     set closeExit [$this closeExit]
  899.     if {$closeExit == ""} {
  900.         uplevel #0 require closeexitd.tcl
  901.         set closeExit [CloseExitDialog new $this.close]
  902.         $this closeExit $closeExit
  903.     }
  904.     $closeExit action $action
  905.     $closeExit popUp
  906. }
  907.  
  908. method DiagramEditor::popUpPrintOptions {this} {
  909.     set printOptions [$this printOptions]
  910.     if {$printOptions == ""} {
  911.         uplevel #0 require printoptio.tcl
  912.         set printOptions [PrintOptionsDialog new $this.printOptions]
  913.         $this printOptions $printOptions
  914.     }
  915.     $printOptions config -diagram [$this fileVersion] \
  916.         -readOnly [[$this editorArea] readOnly] \
  917.         -props [[$this editorArea] propInfo]
  918.     $printOptions popUp
  919. }
  920.  
  921. method DiagramEditor::popUpNameDialog {this} {
  922.     if {[isCommand $this.items] || [isCommand $this.changeName]} {
  923.         wmtkerror "Another dialog is busy"
  924.         return
  925.     }
  926.     uplevel #0 require selectitem.tcl
  927.     SelectItem new $this.items \
  928.         -editor $this \
  929.         -cancelPressed "$this.changeName delete; %this delete"
  930.     uplevel #0 require itemnamech.tcl
  931.     ItemNameChangeDialog new $this.changeName $this \
  932.         -configV [$this configVersion] \
  933.         -keeper [$this fileVersion]
  934.     $this selPopDlg $this.changeName
  935.     $this.items popUp
  936. }
  937.  
  938. method DiagramEditor::popUpScopeDialog {this} {
  939.     if {[isCommand $this.items] || [isCommand $this.changeScope]} {
  940.         wmtkerror "Another dialog is busy"
  941.         return
  942.     }
  943.     uplevel #0 require selectitem.tcl
  944.     SelectItem new $this.items \
  945.         -editor $this \
  946.         -cancelPressed "$this.changeScope delete; %this delete"
  947.     uplevel #0 require scopechang.tcl
  948.     ScopeChangeDialog new $this.changeScope \
  949.         -configV [$this configVersion] \
  950.         -systemV [$this systemVersion] \
  951.         -diagram [$this fileVersion] \
  952.         -editor $this
  953.     $this selPopDlg $this.changeScope
  954.     $this.items popUp
  955. }
  956.  
  957. method DiagramEditor::enDisableMenuEntries {this} {
  958.     [$this genericMenuHdlr] areaChanged
  959.     [$this specificMenuHdlr] areaChanged
  960. }
  961.  
  962. method DiagramEditor::helpOnContext {this} {
  963.     set area [$this editorArea]
  964.     # Get selected components. Throw away "hidden" components.
  965.     set comps ""
  966.     global hiddenCompTypes
  967.     foreach comp [$area getSelectedComponents] {
  968.         if {![info exists hiddenCompTypes([$comp type])]} {
  969.             lappend comps $comp
  970.         }
  971.     }
  972.     if {[llength $comps] == 1} {
  973.         # Show help based on type of selected component.
  974.         set localKey [$comps type]
  975.     } else {
  976.         # Show generic help, based on type of diagram.
  977.         set localKey [[[$this fileVersion] file] type]
  978.     }
  979.     $area releaseSelectedComponents
  980.     $this helpOnName $localKey
  981. }
  982.  
  983. method DiagramEditor::helpOnName {this name} {
  984.     uplevel #0 require edsymb2url.tcl
  985.     global short2url
  986.     if [catch {set url $short2url($name)}] {
  987.         wmtkerror "Sorry, no help available for '$name'"
  988.     } else {
  989.         showHelp $url
  990.     }
  991. }
  992.  
  993. method DiagramEditor::checkContents {this} {
  994.     set file [[$this fileVersion] file]
  995.     set script "[quoteIf [m4_path_name bin otsh$EXE_EXT]] \
  996.         -c [$file qualifiedName].[$file type]"
  997.     $this startCommand mtool $script "" "Starting 'Check'" {0 0} 0
  998. }
  999.  
  1000. method DiagramEditor::checkLocalModel {this} {
  1001.     set file [[$this fileVersion] file]
  1002.     set args "-f check.tcl -S [$file qualifiedName].[$file type]"
  1003.     set script "[quoteIf [m4_path_name bin otsh$EXE_EXT]] $args"
  1004.     $this startCommand mtool $script "" "Starting 'Check'" {0 0} 0
  1005. }
  1006.  
  1007. method DiagramEditor::removeUnreferencedItems {this} {
  1008.     set fv [$this fileVersion]
  1009.     set script "busy \{ $fv removeUnusedDeclarations \}"
  1010.     if [[$this editorArea] isChanged] {
  1011.         $this popupNotSaved $script
  1012.     } else {
  1013.         eval $script
  1014.     }
  1015. }
  1016.  
  1017. method DiagramEditor::createOpenByName {this} {
  1018.     return [OpenByName new $this.obn -editor $this]
  1019. }
  1020.  
  1021. method DiagramEditor::editorArea {this {newArea -}} {
  1022.     if {$newArea == "-"} {
  1023.         return [$this _editorArea]
  1024.     }
  1025.     $this _editorArea $newArea
  1026.     set focusButton "[$this menuBar].options.menu.pointerfocus"
  1027.     if [isCommand $focusButton] {
  1028.         $focusButton state [$newArea pointerFocus]
  1029.     }
  1030. }
  1031.  
  1032. # Do not delete this line -- regeneration end marker
  1033.  
  1034. method DiagramEditor::addPropContainer {this newPropContainer} {
  1035.     [$this propContainerSet] append $newPropContainer
  1036.  
  1037. }
  1038.  
  1039. method DiagramEditor::removePropContainer {this oldPropContainer} {
  1040.     [$this propContainerSet] removeValue $oldPropContainer
  1041. }
  1042.  
  1043.