home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
et.tcl
< prev
next >
Wrap
Text File
|
1997-02-13
|
45KB
|
1,985 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1995 by Cadre Technologies Inc.
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cadre Technologies Inc.
#
#---------------------------------------------------------------------------
#
# File : @(#)et.tcl /main/hindenburg/19
# Author : Discovery
# Original date : June 1995
# Description : Cadre TCL utilities
# Description : Tcl Script to generate file in import tool format
# The client context (M4_levelpath) should be set to
# the diagram for which a script should be generated
# Command line
# options :
# -a<file> append output to file <file>
# -x | -e create CDM's explicitly (see -i option)
# -f<id> before exporting, do a downLevel to file with
# identity <id>, e.g.
# -fGraph:Uj0DhZzJTWPoAAAAzAGcAAQAAABYA
# -g global view, don't export properties of
# scopePhaseRef workitems
# -i create CDM's implicitly from within CAD's
# -l local view, export all properties
# -d<level> use defaults ("") upto (including) <level>
# level can be "proj", "conf", "phase" or "system"
# -o<file> write output to file <file>
# -vi<ver> set input version to <ver>, e.g. -vi4000
# -vo<ver> set output version to <ver>
#
# defaults : -i -l -ostdout -vi<current_ver> -vo<current_ver>
# hint : When exporting an entire Phase, use both '-g'
# and '-e' option for all of its FileVersions.
# Usage : otsh <otsh_options> -- <et.tcl_options>
#
#---------------------------------------------------------------------------
#
# @(#)et.tcl /main/hindenburg/19 13 Feb 1997 Copyright 1996 Cadre Technologies Inc.
#
#---------------------------------------------------------------------------
global SCCS_W; set SCCS_W "
@(#)et.tcl /main/hindenburg/19
"
global compCount; set compCount 0
global compCache
global etCache
global cdmCache
global lblConv
global outFile
global clientContext; set clientContext [ClientContext::global]
#
# escapeStr:
#
# For an input string, escape characters with a special meaning in
# TCL, i.e. '[', ']', '$', '"' and '\n'.
#
proc escapeStr {{str ""}} {
set q "\\\\"
set newStr ""
set esc 0
set len [string length $str]
for {set i 0} {$i < $len} {incr i} {
set c [string index $str $i]
if {$c == {-}} {set c "X-"}
switch -exact "$c" {
"\\" {
if {$esc} {
set newStr "${newStr}${q}${q}"
set esc 0
} else {
set esc 1
}
}
"\n" {
if {$esc} {
set newStr "${newStr}${q}\\n"
set esc 0
} else {
set newStr "${newStr}\\n"
}
}
"X-" {
if {$esc} {
set newStr "${newStr}${q}-"
set esc 0
} else {
set newStr "${newStr}-"
}
}
{[} -
{]} -
{"} -
{$} {
if {$esc} {
set newStr "${newStr}${q}\\$c"
set esc 0
} else {
set newStr "${newStr}\\$c"
}
}
"n" {
if {$esc} {
set newStr "${newStr}${q}$c"
set esc 0
} else {
set newStr "${newStr}$c"
}
}
default {
if {$esc} {
set newStr "${newStr}${q}$c"
set esc 0
} else {
set newStr "${newStr}$c"
}
}
}
}
return $newStr
}
proc cc_hack {} {
global verOut
if {$verOut < 5100} {
puts $outFile "if {\[\[ClientContext::global\] currentLevel\] == \"File\"} {\[ClientContext::global\] upLevel}"
}
}
proc fileHasScopePhase {clientContext} {
set configV [$clientContext currentConfig]
set systemV [$clientContext currentSystem]
set fileV [$clientContext currentFile]
set fwitem [$systemV findDeclaration [[$fileV file] item] $configV]
if {[$fwitem scope] == "scopeSystem"} { return 0 }
return 1
}
#
# 4000 -> 4001+ label conversion
#
proc initLabelConv {} {
global lblConv readOnlyLbl
set lblConv(link_attrib:name) name_type
set lblConv(link_attrib:type) name_type
set lblConv(link_attrib:modifiers) name_type
set lblConv(link_attrib:colon) name_type
set lblConv(link_attrib:init_value) name_type
set lblConv(attribute:name) name_type
set lblConv(attribute:type) name_type
set lblConv(attribute:modifiers) name_type
set lblConv(attribute:colon) name_type
set lblConv(attribute:init_value) name_type
set lblConv(method:name) name_type
set lblConv(method:type) name_type
set lblConv(method:modifiers) name_type
set lblConv(method:left_parenth) name_type
set lblConv(method:right_parenth) name_type
set lblConv(method:colon) name_type
set lblConv(method:constraint) name_type
set lblConv(parameter:name) name_type
set lblConv(parameter:type) name_type
set lblConv(parameter:colon) name_type
set lblConv(parameter:comma) name_type
set lblConv(etd_object:name) name_type
set lblConv(etd_object:type) name_type
set lblConv(etd_object:colon) name_type
set lblConv(etd_initiator:name) name_type
set lblConv(etd_initiator:type) name_type
set lblConv(etd_initiator:colon) name_type
set lblConv(activity:do) name
#
# Boolean 0/1
set readOnlyLbl(etd_object:editor_only) 1
set readOnlyLbl(etd_initiator:editor_only) 1
}
#
# Return nodes and connectors in sorted order to prevent the generation
# of forward references.
#
proc getSortedObjects {} {
set sortedObjects ""
foreach expNode $exportNodeList {
if {![$expNode delayed]} {
lappend sortedObjects $expNode
}
}
foreach expNode $exportNodeList {
if {[$expNode delayed]} {
lappend sortedObjects $expNode
}
}
foreach expConn $exportConnList {
if {[$expConn delayed] == "0"} {
lappend sortedObjects $expConn
}
}
foreach expConn $exportConnList {
if {[$expConn delayed] == "1"} {
lappend sortedObjects $expConn
}
}
foreach expCono $exportConoList {
lappend sortedObjects $expCono
}
foreach expConn $exportConnList {
if {[$expConn delayed] == "2"} {
lappend sortedObjects $expConn
}
}
return $sortedObjects
}
#
# ExportObject:
#
# Base class for all export objects
#
Class ExportObject : GCObject {
#
# Repository object for this Export Object
#
attribute repObject
#
# Name used for this object in generated script
#
attribute exportName
constructor
method addLabels
method addProperties
}
constructor ExportObject {class object name dbComp} {
set this [GCObject::constructor $class $object]
global compCount
incr compCount
$this repObject $dbComp
$this exportName $name$compCount
global compCache
set compCache($dbComp) [$this exportName]
global etCache
set etCache($dbComp) $this
return $this
}
method ExportObject::addLabels {this {comp ""}} {
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set compType [$comp type]
if {$compType == "Segment"} {
if {[[$this repObject] type] == "Segment"} {
set compType [[[$this connector] repObject] type]
} else {
set compType [[$this repObject] type]
}
}
set labelType [$label type]
global readOnlyLbl
if {[info exists readOnlyLbl($compType:$labelType)]} {
set put [expr 1 - $readOnlyLbl($compType:$labelType)]
} else {
set put 1
}
if {$put} {
puts $outFile "\$[$this exportName] setLabel \"$labelType\" \"[escapeStr [$label value]]\""
}
}
}
method ExportObject::addProperties {this {comp ""}} {
if {$comp == ""} {
set comp [$this repObject]
}
#
# Component properties
#
foreach prop [$comp properties] {
puts $outFile "\$[$this exportName] setProp \"[$prop name]\" \"[escapeStr [$prop value]]\""
}
#
# Item Properties
#
global globalView
set configV [$clientContext currentConfig]
foreach label [$comp labels] {
foreach itemRef [$label itemRefs] {
set item [$itemRef item]
if {[$item isNil]} {
continue
}
set diag [$itemRef diagram]
set workitem [$diag findDeclaration $item $configV]
if {[$workitem isNil]} {
continue
}
global lblConv
set compType [$comp type]
set labelType [$label type]
if {[info exists lblConv($compType:$labelType)]} {
set labelType $lblConv($compType:$labelType)
}
set scopeKey "$labelType:[$workitem type]"
if {![info exists scoped($scopeKey)]} {
set scoped($scopeKey) ""
# qualified items inherit their scope from the qualifier
if {[[$item qualifier] isNil]} {
set scope [$workitem scope]
if {$scope == "scopePhaseDef" || $scope == "scopePhaseRef"} {
set scope scopePhase
}
puts $outFile "\$[$this exportName] setScope \"$labelType\" \"[$workitem type]\" \"$scope\""
if {$globalView && [$workitem scope] == "scopePhaseRef"} {
return
}
}
}
set propObj [$workitem properties]
if {[$propObj isNil]} {
continue
}
foreach prop [$propObj properties] {
puts $outFile "\$[$this exportName] setProp \"[$prop name]\" \"[escapeStr [$prop value]]\" \"$labelType\" \"[$workitem type]\""
}
}
}
}
#
# Static member getExportObject
#
proc ExportObject__getExportObject {dbObject} {
if {[info exists compCache($dbObject)]} {
return $compCache($dbObject)
}
return ""
#
# Assume from object is segment, while we need a connector
#
#return $compCache([$dbObject connector])
}
#
# ExportSegm
#
# Class used to export segments
# A segment is just as much delayed as its connector is.
#
Class ExportSegm : ExportObject {
attribute isFirst
attribute connector
constructor
method generate
}
constructor ExportSegm {class object dbSegm conn {inIsFirst 0}} {
set this [ExportObject::constructor $class $object segm $dbSegm]
$this isFirst $inIsFirst
$this connector $conn
return $this
}
method ExportSegm::generate {this} {
set segm [$this repObject]
if {[$this isFirst]} {
puts $outFile "set [$this exportName] \[\$[[$this connector] exportName] getFirstSegm\]"
} else {
puts $outFile "set [$this exportName] \[\$[[$this connector] exportName] addSegm [$segm startX] [$segm startY]\]"
}
$this addLabels
$this addProperties
}
global exportConnList; set exportConnList ""
#
# ExportConn
#
# Class used to export connectors
# A connector can be 'delayed', i.e. it can be a connector connected
# to other connectors. Since we need to identify the objects the
# connector connects, they must have been created before we can
# create the connector. So the generation of certain connectors (e.g.
# the loop connector in a CAD) is delayed until after all normal
# connectors have been processed.
#
Class ExportConn : ExportObject {
attribute delayed
attribute segmentList
constructor
method generate
}
constructor ExportConn {class object dbConn} {
set this [ExportObject::constructor $class $object conn $dbConn]
case [$dbConn type] {
{constraint event_msg loop} {
$this delayed 1
}
{note_conn} {
$this delayed 2
}
default {
$this delayed 0
}
}
#
# create ordered list of segments
# first, search for first segment (has no previous segment)
# then, add all its following segments
#
set conn [$this repObject]
foreach segm [$conn segments] {
set prev [$segm previous]
if {[$prev isNil]} {
lappend tmpList [ExportSegm new $segm $this 1]
break
}
}
while {![[$segm next] isNil] } {
set segm [$segm next]
lappend tmpList [ExportSegm new $segm $this 0]
}
$this segmentList $tmpList
global exportConnList
lappend exportConnList $this
return $this
}
method ExportConn::generate {this {genNew 1}} {
set conn [$this repObject]
set expFromObject [ExportObject__getExportObject [$conn from]]
set expToObject [ExportObject__getExportObject [$conn to]]
#set segment [lindex [$conn segments] 0]
set segment [[lindex [$this segmentList] 0] repObject]
if {$genNew} {
puts $outFile ""
puts $outFile "set [$this exportName] \[\$diag addConn [$conn type] \$$expFromObject \$$expToObject [$segment startX] [$segment startY] [$conn endX] [$conn endY]\]"
}
$this addLabels
$this addProperties
#foreach segment [$conn segments] { $this addLabels $segment }
foreach segment [$this segmentList] {
$segment generate
}
}
global exportConoList; set exportConoList ""
#
# ExportCono
#
# Export class for connected nodes. A cono is delayed when its super
# component is also a cono and when this super cono is not generated yet.
#
Class ExportCono : ExportObject {
attribute delayed
attribute generated
attribute super
constructor
method generate
method getSuper
}
constructor ExportCono {class object dbCono} {
set this [ExportObject::constructor $class $object cono $dbCono]
$this delayed 0
$this generated 0
$this super ""
#
# sort exportConoList on x coordinate
#
global exportConoList
set cono [$this repObject]
set x [$cono x]
set l [llength $exportConoList]
for {set i 0} {$i < $l} {incr i} {
set c [lindex $exportConoList $i]
if {$x < [[$c repObject] x]} {
set exportConoList [linsert $exportConoList $i $this]
return $this
}
}
lappend exportConoList $this
return $this
}
method ExportCono::generate {this} {
if [$this generated] {
return 0
}
set super [$this getSuper]
if {$super == "" || ([$this delayed] && ![$super generated])} {
return 1
}
set dbCono [$this repObject]
set superId [ExportObject__getExportObject [$super repObject]]
puts $outFile ""
puts $outFile "set [$this exportName] \[\$diag addCono [$dbCono type] \$$superId [$dbCono x] [$dbCono y] [$dbCono sizeX] [$dbCono sizeY]\]"
$this addLabels
$this addProperties
$this delayed 0
$this generated 1
return 0
}
method ExportCono::getSuper {this} {
if {[$this super] != ""} {
return [$this super]
}
set dbSuper [[$this repObject] from]
if {[info exists etCache($dbSuper)]} {
$this super $etCache($dbSuper)
} elseif {[$dbSuper objType] == "ConnectedNode"} {
# set 'delayed' if dbSuper is a cono too
#
$this delayed 1
$this super $etCache($dbSuper)
}
return [$this super]
}
global exportNodeList; set exportNodeList ""
#
# ExportNode
#
# Export class for nodes. Nodes can be delayed because of composite
# nodes (e.g. generalization node + generalization connectors).
# These are delayed because the connectors connect to other nodes
# that must be generated first.
#
Class ExportNode : ExportObject {
attribute delayed
constructor
method generate
}
constructor ExportNode {class object dbNode {delay 0}} {
set this [ExportObject::constructor $class $object node $dbNode]
$this delayed $delay
global exportNodeList
lappend exportNodeList $this
return $this
}
method ExportNode::generate {this} {
set dbNode [$this repObject]
puts $outFile ""
puts $outFile "set [$this exportName] \[\$diag addNode [$dbNode type] [$dbNode x] [$dbNode y] [$dbNode sizeX] [$dbNode sizeY]\]"
$this addLabels
$this addProperties
}
#
# ExportRow
#
# Export class for rows.
#
Class ExportRow : ExportObject {
constructor
method generate
method exportCells
}
constructor ExportRow {class object dbRow} {
set this [ExportObject::constructor $class $object row $dbRow]
return $this
}
method ExportRow::generate {this} {
set dbRow [$this repObject]
puts $outFile ""
puts $outFile "set [$this exportName] \[\$diag addRow [$dbRow type] [$dbRow height]\]"
$this addLabels
$this addProperties
#
# Workaround for problem in repository: cells are not sorted
#
# foreach cell [$[$this repObject] rows]
#
set firstCell [lindex [[$this repObject] cells] 0]
set cellList ""
if {$firstCell != ""} {
while {![[$firstCell previous] isNil]} {
set firstCell [$firstCell previous]
}
for {} {![$firstCell isNil]} {set firstCell [$firstCell next]} {
lappend cellList $firstCell
}
}
$this exportCells $cellList
}
method ExportRow::exportCells {this cellList } {
foreach cell $cellList {
[ExportCell new $cell $this] generate
}
}
#
# ExportCell
#
# Export class for cells of a row.
#
Class ExportCell : ExportObject {
attribute row
constructor
method generate
}
constructor ExportCell {class object dbCell inRow} {
set this [ExportObject::constructor $class $object cell $dbCell]
$this row $inRow
return $this
}
method ExportCell::generate {this} {
set dbCell [$this repObject]
puts $outFile ""
puts $outFile "set [$this exportName] \[\$[[$this row] exportName] addCell [$dbCell type] [$dbCell width]\]"
$this addLabels
$this addProperties
}
#
# ExportCdmRow
#
# Export class for CDM rows.
#
Class ExportCdmRow : ExportRow {
constructor
method exportCells
method addLabels
}
constructor ExportCdmRow {class object dbRow} {
set this [ExportRow::constructor $class $object $dbRow]
return $this
}
method ExportCdmRow::exportCells {this cellList } {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
foreach cell $cellList {
[ExportCdmCell new $cell $this] generate
}
} else {
foreach cell $cellList {
[ExportCell new $cell $this] generate
}
}
}
method ExportCdmRow::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _modifiers ""
set _left_parenth ""
set _right_parenth ""
set _colon ""
set _init_value ""
set _constraint ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
if {[$comp type] == "attribute"} {
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_modifiers}${_name}${_colon}${_type}${_init_value}"]\""
} else {
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_modifiers}${_name}${_left_parenth}${_right_parenth}${_colon}${_type}${_constraint}"]\""
}
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCdmCell
#
# Export class for cells of a Cdm row.
#
Class ExportCdmCell : ExportCell {
constructor
method addLabels
}
constructor ExportCdmCell {class object dbCell inRow} {
set this [ExportCell::constructor $class $object $dbCell $inRow]
return $this
}
method ExportCdmCell::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _colon ""
set _comma ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_name}${_colon}${_type}${_comma}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCadParam
#
# Export object for a method parameter
#
Class ExportCadParam : ExportObject {
attribute cadMethod
constructor
method generate
method addLabels
}
constructor ExportCadParam {class object dbParam master} {
set this [ExportObject::constructor $class $object param $dbParam]
$this cadMethod $master
return $this
}
method ExportCadParam::generate {this} {
global verOut
puts $outFile ""
puts -nonewline $outFile "set [$this exportName] \[\$[[$this cadMethod] exportName] addParam"
if {$verOut == 4000} {
puts $outFile " \"\" \"\" \"\" \"\"\]"
} else {
puts $outFile "\]"
}
$this addLabels
$this addProperties
}
method ExportCadParam::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _colon ""
set _comma ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_name}${_colon}${_type}${_comma}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCadAttribute
#
# Export object for a CAD attribute
#
Class ExportCadAttribute : ExportObject {
attribute cadClass
constructor
method generate
method addLabels
}
constructor ExportCadAttribute {class object dbObject master} {
set this [ExportObject::constructor $class $object attribute $dbObject]
$this cadClass $master
return $this
}
method ExportCadAttribute::generate {this} {
global verOut
puts $outFile ""
puts -nonewline $outFile "set [$this exportName] \[\$[[$this cadClass] exportName] addAttrib"
if {$verOut == 4000} {
puts $outFile " \"\" \"\" \"\" \"\" \"\"\]"
} else {
puts $outFile "\]"
}
$this addLabels
$this addProperties
}
method ExportCadAttribute::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _modifiers ""
set _colon ""
set _init_value ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_modifiers}${_name}${_colon}${_type}${_init_value}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCadMethod
#
# Export object for a CAD method
#
Class ExportCadMethod : ExportObject {
attribute cadClass
constructor
method generate
method addLabels
}
constructor ExportCadMethod {class object dbObject master} {
set this [ExportObject::constructor $class $object method $dbObject]
$this cadClass $master
return $this
}
method ExportCadMethod::generate {this} {
global verOut
puts $outFile ""
puts -nonewline $outFile "set [$this exportName] \[\$[[$this cadClass] exportName] addMethod"
if {$verOut == 4000} {
puts $outFile " \"\" \"\" \"\" \"\" \"\" \"\" \"\"\]"
} else {
puts $outFile "\]"
}
$this addLabels
$this addProperties
foreach cell [[$this repObject] cells] {
set param [ExportCadParam new $cell $this]
$param generate
}
}
method ExportCadMethod::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _modifiers ""
set _left_parenth ""
set _right_parenth ""
set _colon ""
set _constraint ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_modifiers}${_name}${_left_parenth}${_right_parenth}${_colon}${_type}${_constraint}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCadClass
#
# Special class for a CadClass: the CDM for this class must also be
# loaded, to be able to generate methods and attributes.
#
Class ExportCadClass : ExportNode {
constructor
method generate
}
constructor ExportCadClass {class object dbObject} {
set this [ExportNode::constructor $class $object $dbObject]
return $this
}
method ExportCadClass::generate {this} {
ExportNode::generate $this
global explicitCreate
if {$explicitCreate} {
return
}
set node [$this repObject]
set nodeName "noname"
foreach label [$node labels] {
if {[$label type] == "name"} {
set nodeName [$label value]
}
}
if {$nodeName == ""} {
return
}
set systemV [$clientContext currentSystem]
set fileV [$systemV findFileVersion $nodeName cdm]
# CDM's are created only once per CAD
global cdmCache
if {![$fileV isNil] && ![info exists cdmCache($fileV)]} {
set cdmCache($fileV) 1
#
# Workaround for problem in repository: rows are not sorted
#
# foreach row [$fileV rows]
#
set firstRow [lindex [$fileV rows] 0]
set rowList ""
if {$firstRow != ""} {
while {![[$firstRow previous] isNil]} {
set firstRow [$firstRow previous]
}
for {} {![$firstRow isNil]} {set firstRow [$firstRow next]} {
lappend rowList $firstRow
}
}
foreach row $rowList {
if {[$row type] == "attribute"} {
set attribute [ExportCadAttribute new $row $this]
$attribute generate
}
if {[$row type] == "method"} {
set method [ExportCadMethod new $row $this]
$method generate
}
}
}
}
#
# ExportCadLinkAttrib
#
# Special class for a Link Attribute of a Link Attribute Box
#
Class ExportCadLinkAttrib : ExportCono {
constructor
method generate
method addLabels
}
constructor ExportCadLinkAttrib {class object dbObject} {
set this [ExportCono::constructor $class $object $dbObject]
return $this
}
method ExportCadLinkAttrib::generate {this} {
global verOut
set superId [ExportObject__getExportObject [[$this repObject] from]]
puts $outFile ""
puts -nonewline $outFile "set [$this exportName] \[\$$superId addAttrib"
if {$verOut == 4000} {
puts $outFile " \"\" \"\" \"\" \"\" \"\"\]"
} else {
puts $outFile "\]"
}
$this addLabels
$this addProperties
}
method ExportCadLinkAttrib::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _modifiers ""
set _colon ""
set _init_value ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_modifiers}${_name}${_colon}${_type}${_init_value}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportRakeNode
#
# Special class for CAD and MGD generalization nodes
#
Class ExportRakeNode : ExportNode {
constructor
method generate
}
constructor ExportRakeNode {class object dbRake {delay 1}} {
set this [ExportNode::constructor $class $object $dbRake $delay]
return $this
}
method ExportRakeNode::generate {this} {
global verOut
set comp [$this repObject]
set connectorsIn [$comp connectorsIn]
set connectorsOut [$comp connectorsOut]
set connIn [lvarpop connectorsIn]
set connOut [lvarpop connectorsOut]
if {($connIn == "") || ($connOut == "")} {
puts stderr "WARNING: no code generated for generalization node"
return ""
}
set baseClass [$connIn from]
set derivedClass [$connOut to]
set segment [lindex [$connIn segments] 0]
puts $outFile ""
puts $outFile "set [$this exportName] \[\$diag addRake [$comp type] \$$compCache($baseClass) \$$compCache($derivedClass) [$segment startX] [$segment startY] [$connOut endX] [$connOut endY] [$comp y]\]"
$this addLabels
$this addProperties
#
# handle conn's
#
if {$verOut >= 4001} {
set conn [ExportConn new $connIn]
puts $outFile "\nset [$conn exportName] \[\$[$this exportName] getInConn\]"
$conn generate 0
}
foreach conn $connectorsIn {
[ExportConn new $conn] generate
}
if {$verOut >= 4001} {
set conn [ExportConn new $connOut]
puts $outFile "\nset [$conn exportName] \[\$[$this exportName] getFirstOutConn\]"
$conn generate 0
}
foreach conn $connectorsOut {
[ExportConn new $conn] generate
}
}
#
# ExportEtdNode
#
# Export object for an ETD nodes
# Introduced for 4000 -> 4001 conversion
#
Class ExportEtdNode : ExportNode {
constructor
method addLabels
}
constructor ExportEtdNode {class object dbObject} {
set this [ExportNode::constructor $class $object $dbObject]
return $this
}
method ExportEtdNode::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _type ""
set _colon ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name_type\" \"[escapeStr "${_name}${_colon}${_type}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportStdCono
#
# Special class for STD State Action and STD Activity
#
Class ExportStdCono : ExportCono {
constructor
method generate
method addLabels
}
constructor ExportStdCono {class object dbObject} {
set this [ExportCono::constructor $class $object $dbObject]
return $this
}
method ExportStdCono::generate {this} {
global verOut
set _type [[$this repObject] type]
set superId [ExportObject__getExportObject [[$this repObject] from]]
puts $outFile ""
if {[[$this repObject] type] == "state_action"} {
puts -nonewline $outFile "set [$this exportName] \[\$$superId addStateAction"
if {$verOut == 4000} {
puts $outFile " \"\" \"\" \"\"]"
} else {
puts $outFile "\]"
}
} else {
puts -nonewline $outFile "set [$this exportName] \[\$$superId addActivity"
if {$verOut == 4000} {
puts $outFile " \"\" \"\"\]"
} else {
puts $outFile "\]"
}
}
$this addLabels
$this addProperties
}
method ExportStdCono::addLabels {this {comp ""}} {
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
set _name ""
set _do ""
if {$comp == ""} {
set comp [$this repObject]
}
foreach label [$comp labels] {
set labelType [$label type]
set _$labelType [$label value]
}
puts $outFile "\$[$this exportName] setLabel \"name\" \"[escapeStr "${_do}${_name}"]\""
} else {
ExportObject::addLabels $this $comp
}
}
#
# ExportCAD
#
# Generate import tool script for this class
#
Class ExportCAD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportCAD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportCAD::generate {this} {
putNewDiagram CAD
foreach node [[$this fileV] nodes] {
case [$node type] {
{cad_class cad_container} {
ExportCadClass new $node
}
{generalization overlap_gen} {
ExportRakeNode new $node
}
default {
ExportNode new $node
}
}
}
foreach conn [[$this fileV] connectors] {
case [$conn type] {
{generalization_conn overlap_gen_conn} {
continue
}
default {
ExportConn new $conn
}
}
}
foreach cono [[$this fileV] connectedNodes] {
case [$cono type] {
{link_attrib} {
ExportCadLinkAttrib new $cono
}
default {
ExportCono new $cono
}
}
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportCCD
#
# Generate import tool script for this class
#
Class ExportCCD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportCCD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportCCD::generate {this} {
putNewDiagram CCD
foreach node [[$this fileV] nodes] {
ExportNode new $node
}
foreach conn [[$this fileV] connectors] {
ExportConn new $conn
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportCDM
#
# Generate import tool script for this class
#
Class ExportCDM : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportCDM {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportCDM::generate {this} {
putNewDiagram CDM
#
# Workaround for problem in repository: rows are not sorted
#
# foreach row [$fileV rows]
#
set firstRow [lindex [[$this fileV] rows] 0]
set rowList ""
if {$firstRow != ""} {
while {![[$firstRow previous] isNil]} {
set firstRow [$firstRow previous]
}
for {} {![$firstRow isNil]} {set firstRow [$firstRow next]} {
lappend rowList $firstRow
}
}
global verIn verOut
if {$verIn == 4000 && $verOut >= 4001} {
foreach row $rowList {
[ExportCdmRow new $row] generate
}
} else {
foreach row $rowList {
[ExportRow new $row] generate
}
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportDFD
#
# Generate import tool script for this class
#
Class ExportDFD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportDFD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportDFD::generate {this} {
putNewDiagram DFD
foreach node [[$this fileV] nodes] {
ExportNode new $node
}
foreach conn [[$this fileV] connectors] {
ExportConn new $conn
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportETD
#
# Generate import tool script for this class
#
Class ExportETD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportETD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportETD::generate {this} {
global verOut
set file [[$clientContext currentFile] file]
set diagName [$file name]
if {$verOut >= 5100} {
set qualifier [[$file item] qualifier]
if {![$qualifier isNil] && [$qualifier isA Item]} {
set diagName "[$qualifier name]:$diagName"
} else {
puts stderr "WARNING: ETD filename '$diagName' is not qualified!"
return
}
}
putNewDiagram ETD $diagName
foreach node [[$this fileV] nodes] {
ExportEtdNode new $node
}
foreach conn [[$this fileV] connectors] {
ExportConn new $conn
}
global compCache
foreach cono [[$this fileV] connectedNodes] {
if {![info exists compCache($cono)]} {
ExportCono new $cono
}
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportMGD
#
# Generate import tool script for this class
#
Class ExportMGD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportMGD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportMGD::generate {this} {
putNewDiagram MGD
foreach node [[$this fileV] nodes] {
case [$node type] {
{message_gen} {
ExportRakeNode new $node
}
default {
ExportNode new $node
}
}
}
foreach conn [[$this fileV] connectors] {
case [$conn type] {
{message_gen_conn} {
continue
}
default {
ExportConn new $conn
}
}
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportSTD
#
# Generate import tool script for this class
#
Class ExportSTD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportSTD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportSTD::generate {this} {
set file [[$clientContext currentFile] file]
set diagName [$file name]
set qualifier [[$file item] qualifier]
if {![$qualifier isNil] && [$qualifier isA Item]} {
set diagName "[$qualifier name]:$diagName"
} else {
puts stderr "ERROR: STD filename '$diagName' must be qualified."
return
}
putNewDiagram STD $diagName
foreach node [[$this fileV] nodes] {
ExportNode new $node
}
foreach conn [[$this fileV] connectors] {
ExportConn new $conn
}
foreach cono [[$this fileV] connectedNodes] {
ExportStdCono new $cono
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# ExportUCD
#
# Generate import tool script for this class
#
Class ExportUCD : GCObject {
attribute fileV
constructor
method generate
}
constructor ExportUCD {class object fileVersion} {
set this [GCObject::constructor $class $object]
$this fileV $fileVersion
return $this
}
method ExportUCD::generate {this} {
putNewDiagram UCD
foreach node [[$this fileV] nodes] {
ExportNode new $node
}
foreach conn [[$this fileV] connectors] {
ExportConn new $conn
}
foreach object [getSortedObjects] {
$object generate
}
puts $outFile ""
puts $outFile "\$diag save"
cc_hack
}
#
# End of diagram classes
#
global readOnlyLbl
# Boolean 0/1
set readOnlyLbl(cad_class:attributes) 1
set readOnlyLbl(cad_class:methods) 1
set readOnlyLbl(cad_container:attributes) 1
set readOnlyLbl(cad_container:methods) 1
set readOnlyLbl(link_attr_box:attributes) 1
set readOnlyLbl(state:editor_only) 1
set readOnlyLbl(transition:editor_only) 0
set readOnlyLbl(Segment:editor_only) 1
global clientContext
#
# Main routine
#
proc exportDiagram {} {
global exportNodeList; set exportNodeList ""
global exportConnList; set exportConnList ""
global exportConoList; set exportConoList ""
global compCache; catch {unset compCache}
global cdmCache; catch {unset cdmCache}
set fileV [$clientContext currentFile]
if {[$fileV isNil]} {
puts stderr "ERROR: unable to determine diagram from Client Context"
return 1
}
case [[$fileV file] type] {
{cad} {
set diag [ExportCAD new $fileV]
$diag generate
}
{ccd} {
set diag [ExportCCD new $fileV]
$diag generate
}
{cdm} {
set diag [ExportCDM new $fileV]
$diag generate
}
{dfd} {
set diag [ExportDFD new $fileV]
$diag generate
}
{etd} {
set diag [ExportETD new $fileV]
$diag generate
}
{mgd} {
set diag [ExportMGD new $fileV]
$diag generate
}
{std} {
set diag [ExportSTD new $fileV]
$diag generate
}
{ucd} {
set diag [ExportUCD new $fileV]
$diag generate
}
default {
puts stderr "ERROR: specified diagramtype is not supported"
return 1
}
}
}
proc setOutFile {{fileName ""} {appendFile 0}} {
global outFile
if {$fileName == "" || $fileName == "stdout"} {
set outFile stdout
} else {
if {$appendFile} {
set mode "a"
} else {
set mode "w"
}
if [catch {set outFile [open $fileName $mode]} msg] {
puts stderr "ERROR: $msg"
puts stderr "MESSAGE: exporting to stdout"
set outFile stdout
}
}
return $outFile
}
proc putNewDiagram {diagType {diagName ""}} {
global itDefaults
if {$diagName == ""} {
set diagName [[[$clientContext currentFile] file] name]
}
set sysName [[[$clientContext currentSystem] system] name]
set phaseName [[[$clientContext currentPhase] phase] name]
set phaseType [[[$clientContext currentPhase] phase] type]
set confName [[[$clientContext currentConfig] config] name]
set confVers [[$clientContext currentConfig] versionName]
set projName [[$clientContext currentProject] name]
switch -glob $itDefaults {
s* {set level 4}
ph* {set level 3}
c* {set level 2}
pr* {set level 1}
default {set level 0}
}
if {$level > 0} {set projName ""}
if {$level > 1} {set confName "" ; set confVers ""}
if {$level > 2} {set phaseName "" ; set phaseType ""}
if {$level > 3} {set sysName ""}
puts $outFile "set diag \[$diagType new $diagName \"$sysName\" \"$phaseName\" \"$phaseType\" \"$confName\" \"$confVers\" \"$projName\" [fileHasScopePhase $clientContext]\]"
}
proc putHeader {verIn verOut etArgs} {
set verLabel [versionInfo versionLabel]
set tmp [string trim $SCCS_W "\n%"]
if {$tmp != "W"} {
regsub "^@.#." $tmp {} tmp
set idLabel $tmp
} else {
set idLabel "et.tcl $verLabel\t[versionInfo dateLabel]"
}
puts $outFile "\n# Generator: $idLabel"
puts $outFile "# Argument(s): $etArgs"
puts $outFile "# Interpreter to use: Otsh $verLabel"
puts $outFile "#"
puts $outFile "OTShRegister::importTool"
puts $outFile ""
}
proc downLevelToFile {fileV_id} {
if {[$clientContext currentLevel] == "File"} {
$clientContext upLevel
}
switch -glob $fileV_id {
Graph* {set fileV [Graph new $fileV_id]}
default {set fileV [Matrix new $fileV_id]}
}
$clientContext downLevelId $fileV
}
proc exportTool {{argv {}}} {
regsub {/.*} [versionInfo maintVersion] {} maintVersion
set maintVersion [expr $maintVersion + 0]
if {[expr $maintVersion < 10]} {set maintVersion "0$maintVersion"}
set version "[versionInfo majorVersion][versionInfo minorVersion]$maintVersion"
global explicitCreate; set explicitCreate 0
global globalView; set globalView 0
global verIn; set verIn $version
global verOut; set verOut $version
global lblConv; catch {unset lblConv}
global itDefaults; set itDefaults "none"
set fileName ""
set appendFile 0
set etArgs $argv
while {![lempty $argv]} {
set arg [lvarpop argv]
switch -glob -- $arg {
-a* { set fileName [string range $arg 2 end]
set appendFile 1 }
-x* -
-e* { set explicitCreate 1 }
-f* { downLevelToFile [string range $arg 2 end] }
-g* { set globalView 1 }
-i* { set explicitCreate 0 }
-l* { set globalView 0 }
-o* { set fileName [string range $arg 2 end]
set appendFile 0 }
-d* { set itDefaults [string range $arg 2 end] }
-vi* { set verIn [string range $arg 3 end] }
-vo* { set verOut [string range $arg 3 end] }
-* { puts stderr "WARNING: '$arg': illegal option" }
* { puts stderr "WARNING: '$arg': illegal argument" }
}
}
if {$verOut < $verIn} {
puts stderr "ERROR: output version number ($verOut) must be greater then input version number ($verIn)"
return 1
}
if {$verIn == 4000 && $verOut >= 4001} {
initLabelConv
}
set outFile [setOutFile $fileName $appendFile]
putHeader $verIn $verOut $etArgs
if [catch {exportDiagram}] {
if {$outFile != "stdout"} {close $outFile}
puts stderr "ERROR: $errorInfo"
return 2
}
if {$outFile != "stdout"} {
close $outFile
}
return 0
}
global et_dont_run
if [catch {set et_dont_run}] {
exportTool $argv
}