home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
moduleedar.tcl
< prev
next >
Wrap
Text File
|
1997-11-21
|
14KB
|
540 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)moduleedar.tcl /main/titanic/18
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)moduleedar.tcl /main/titanic/18 21 Nov 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
require "custmodobj.tcl"
require "custobjvie.tcl"
require "addreqmodh.tcl"
# End user added include file section
require "custdefsar.tcl"
Class ModuleEdArea : {CustDefsArea} {
constructor
method destructor
method read
method insertObjects
method newObjects
method createObject
method clearArea
method readUserObjects
method addRequiredModules
method getActiveObjectList
method findUnsatisfiedRequirements
method checkRequirements
method findConflicts
method checkConflicts
method findNonExistingLocations
method checkExistence
method findAllInvalidObjs
method checkAll
method dropEvent
method save
}
constructor ModuleEdArea {class this name} {
set this [CustDefsArea::constructor $class $this $name]
# Start constructor user section
# Order of entries is of importance in the module editor
$this userLevelAlwaysLast 1
$this rowCount 12
$this columnCount 80
$this font "[m4_var get M4_font -context uce]"
$this mode DETAIL
$this destinationSet "MODULE dropEvent"
BrowsHeader new $this.name -label "Long Name" -width 32
BrowsHeader new $this.type -label Type -width 20
BrowsHeader new $this.state -label "Select State" -width 13
BrowsHeader new $this.specLevel -label Level -width 16
BrowsHeader new $this.path -label Location -width 75
# End constructor user section
return $this
}
method ModuleEdArea::destructor {this} {
# Start destructor user section
# End destructor user section
$this CustDefsArea::destructor
}
method ModuleEdArea::read {this object type} {
set index [llength [$this objectSet]]
foreach module [$this readConfig $object modules modules] {
set spec ""
lappend spec name
lappend spec [lindex $module 0]
lappend spec index
lappend spec $index
lappend spec select-state
lappend spec [lindex $module 1]
lappend spec location
set location [lindex $module 2]
if $win95 {
regsub -all {\\\\} $location {\\} location
}
lappend spec $location
$this createObject $spec $type
incr index
}
}
method ModuleEdArea::insertObjects {this locations {beforeObj ""}} {
$this isChanged 1
if {$beforeObj == ""} {
# append new objects to the end
set index [llength [$this objectSet]]
} else {
set index [$beforeObj index]
set len [llength $locations]
# make place for new objects
foreach obj [$this objectSet] {
if {[$obj index] >= $index} {
$obj index [expr {[$obj index] + $len}]
}
}
}
set user 0
if {[$this _level] == "user"} {
set user 1
}
set insertedObjects ""
foreach location $locations {
set propDict [[ModuleDB::global] getModulePropDict $location]
set moduleName [$propDict set "name"]
set spec ""
lappend spec name
lappend spec $moduleName
lappend spec location
lappend spec $location
lappend spec select-state
lappend spec "on"
lappend spec index
lappend spec $index
lappend spec userDefined
lappend spec $user
set newObject [$this createObject $spec [$this _level]]
lappend insertedObjects $newObject
incr index
}
$this sort -command ModuleEdArea::sort
return $insertedObjects
}
method ModuleEdArea::newObjects {this locations} {
set beforeObj ""
if {[$this _level] != "user"} {
foreach obj [$this objectSet] {
if {[$obj specLevel] == "user"} {
set beforeObj $obj
break
}
}
}
set insertedObjects [$this insertObjects $locations $beforeObj]
# The 'Select Module' Dialog has selectionPolicy 'BROWSE', so the
# insertedObjects list will contain only one object
set obj [lindex $insertedObjects 0]
[AddReqModHandler::global] addRequiredModules $obj 0
}
method ModuleEdArea::createObject {this objSpec level} {
global classCount
set object [CustModObject new $this.Object$classCount $objSpec]
incr classCount
$this adjustCreatedObject $object $level
# update the object-details in the view
$object updateView
return $object
}
method ModuleEdArea::clearArea {this} {
foreach obj [$this objectSet] {
$obj delete
}
.main selectionChanged
}
method ModuleEdArea::readUserObjects {this} {
set file [path_name concat [location ~ icase] modules modules]
if [file exists $file] {
set index [llength [$this objectSet]]
foreach module [readConfigurationFile $file] {
set spec ""
lappend spec name
lappend spec [lindex $module 0]
lappend spec index
lappend spec $index
lappend spec select-state
lappend spec [lindex $module 1]
lappend spec location
set location [lindex $module 2]
if $win95 {
regsub -all {\\\\} $location {\\} location
}
lappend spec $location
$this createObject $spec user
incr index
}
}
}
method ModuleEdArea::addRequiredModules {this obj} {
set addReqModHdlr [AddReqModHandler::global]
$addReqModHdlr addRequiredModules $obj
}
method ModuleEdArea::getActiveObjectList {this} {
set activeObjList [List new]
foreach obj [$this objectSet] {
set objName [$obj name]
set objLoc [$obj location]
set index 0
set mustAppend [expr {([$obj select-state] == "on") ? 1 : 0}]
$activeObjList foreach activeObj {
set activeObjName [$activeObj name]
set activeObjLoc [$activeObj location]
if {$objName == $activeObjName} {
# obj 'objName' is already active
if {[$obj select-state] == "on" &&
$objLoc == $activeObjLoc} {
# ignore obj
set mustAppend 0
} else {
# remove activeObj
$activeObjList remove $index
}
break
}
incr index
}
if {$mustAppend} {
# obj 'objName' in 'objLoc' was not yet active:
# append obj
$activeObjList append $obj
}
}
return $activeObjList
}
method ModuleEdArea::findUnsatisfiedRequirements {this objs info} {
upvar $objs objList
upvar $info infoList
set curNames [Dictionary new]
set curTypes [Dictionary new]
[$this getActiveObjectList] foreach obj {
set requirements [$obj getRequiredElements]
set reqModules [lindex $requirements 0]
foreach reqModule $reqModules {
if [$curNames exists $reqModule] {
continue
}
lappend infoList "[$obj longName]"
lappend infoList "No module '$reqModule' found."
lappend objList $obj
}
$curNames set [$obj name] 1
set reqModTypes [lindex $requirements 1]
foreach reqModType $reqModTypes {
if [$curTypes exists $reqModType] {
continue
}
lappend infoList "[$obj longName]"
lappend infoList "No module type '$reqModType' found."
lappend objList $obj
}
$curTypes set [$obj type] 1
}
return [llength $objList]
}
method ModuleEdArea::checkRequirements {this} {
set objList {}
set infoList {}
set nrOfErrors [$this findUnsatisfiedRequirements objList infoList]
if {$nrOfErrors == 0} {
wmtkinfo "All requirements are available."
return
}
# make a simple object that can be handled by the infodialog
ClassMaker::extend GCObject InfoObject {infoList} 0
set infoObject [InfoObject new]
$infoObject infoList $infoList
.main showObjectInfo $infoObject
}
method ModuleEdArea::findConflicts {this objs info} {
upvar $objs objList
upvar $info infoList
set activeObjList [$this getActiveObjectList]
$activeObjList foreach obj {
set conflicts [$obj getConflictingElements]
set conflictModules [lindex $conflicts 0]
foreach conflictModule $conflictModules {
$activeObjList foreach otherObj {
if {$obj == $otherObj} {
# no conflict with itself
continue
}
if {[$otherObj name] != $conflictModule} {
continue
}
lappend infoList "[$obj longName]"
lappend infoList "Conflict with module '[\
$otherObj longName]'."
lappend objList $obj
}
}
set conflictModTypes [lindex $conflicts 1]
foreach conflictModType $conflictModTypes {
$activeObjList foreach otherObj {
if {$obj == $otherObj} {
# no conflict with itself
continue
}
if {$conflictModType != [$otherObj type]} {
continue
}
lappend infoList "[$obj longName]"
lappend infoList "Type conflict with module '[\
$otherObj longName]'\
(type '$conflictModType')."
lappend objList $obj
}
}
}
return [llength $objList]
}
method ModuleEdArea::checkConflicts {this} {
set objList {}
set infoList {}
set nrOfErrors [$this findConflicts objList infoList]
if {$nrOfErrors == 0} {
wmtkinfo "No conflicts found."
return
}
# make a simple object that can be handled by the infodialog
ClassMaker::extend GCObject InfoObject {infoList} 0
set infoObject [InfoObject new]
$infoObject infoList $infoList
.main showObjectInfo $infoObject
}
method ModuleEdArea::findNonExistingLocations {this objs info} {
upvar $objs objList
upvar $info infoList
[$this getActiveObjectList] foreach obj {
if [file exists [$obj location]] {
continue
}
lappend infoList "[$obj longName]"
lappend infoList "Location '[$obj location]' does not exist."
lappend objList $obj
}
return [llength $objList]
}
method ModuleEdArea::checkExistence {this} {
set objList {}
set infoList {}
set nrOfErrors [$this findNonExistingLocations objList infoList]
if {$nrOfErrors == 0} {
wmtkinfo "All module locations exist."
return
}
# make a simple object that can be handled by the infodialog
ClassMaker::extend GCObject InfoObject {infoList} 0
set infoObject [InfoObject new]
$infoObject infoList $infoList
.main showObjectInfo $infoObject
}
method ModuleEdArea::findAllInvalidObjs {this objs info {editablesOnly 0}} {
upvar $objs objList
upvar $info infoList
$this findUnsatisfiedRequirements objList infoList
$this findConflicts objList infoList
$this findNonExistingLocations objList infoList
if $editablesOnly {
set i 0
foreach obj $objList {
if [$obj editable] {
incr i
continue
}
# remove obj from objList and info from infoList
set objList [lreplace $objList $i $i]
set j [expr 2 * $i]
set infoList [lreplace $infoList $j [incr j]]
}
}
return [llength $objList]
}
method ModuleEdArea::checkAll {this} {
set objList {}
set infoList {}
set nrOfErrors [$this findAllInvalidObjs objList infoList]
if {$nrOfErrors == 0} {
wmtkinfo "All modules are OK."
return
}
# make a simple object that can be handled by the infodialog
ClassMaker::extend GCObject InfoObject {infoList} 0
set infoObject [InfoObject new]
$infoObject infoList $infoList
.main showObjectInfo $infoObject
}
method ModuleEdArea::dropEvent {this droppedObject srcIsDst droppedAfterObject droppedForObject} {
if {$srcIsDst == 0} {
wmtkerror "Drag & drop between tools is not supported (yet)."
return
}
if {![$droppedObject editable]} {
wmtkerror "Object not moved, reason: object not editable."
return
}
if {$droppedForObject != ""} {
if {[$droppedForObject specLevel] != [$droppedObject specLevel]} {
wmtkerror "Object can not be moved to an other higher level."
return
}
}
set newIndex 0
set oldIndex [$droppedObject index]
if {$droppedAfterObject != ""} {
set newIndex [$droppedAfterObject index]
if {$newIndex < $oldIndex} {
incr newIndex
}
}
foreach obj [$this objectSet] {
set objIndex [$obj index]
if {$objIndex >= $newIndex && $objIndex < $oldIndex} {
$obj index [expr $objIndex + 1]
} elseif {$objIndex > $oldIndex && $objIndex <= $newIndex} {
$obj index [expr $objIndex - 1]
}
}
$droppedObject index $newIndex
$this sort -command "ModuleEdArea::sort"
$this isChanged 1
}
method ModuleEdArea::save {this} {
# Check if everything is OK
set info {}
set objs {}
set editablesOnly 1
if {[$this findAllInvalidObjs objs info $editablesOnly] == 0} {
$this CustEdArea::save
return
}
ClassMaker::extend YesNoWarningDialog SaveWarning {edArea invalidObjs \
saveAction}
SaveWarning new .main.saveWarning -title "Warning On Save"
.main.saveWarning delHelpButton
.main.saveWarning invalidObjs $objs
.main.saveWarning edArea $this
.main.saveWarning saveAction ""
if [isCommand [.main notSaved]] {
.main.saveWarning saveAction [[.main notSaved] action]
# cancel the NotSavedDialog action for now
[.main notSaved] action ""
}
set warning "Check detected error(s) in the module specifications.\
\n\n\Do you want to correct them yourself before saving?"
.main.saveWarning message $warning
.main.saveWarning noPressed {
set invalidObjs [%this invalidObjs]
while {![lempty $invalidObjs]} {
foreach obj $invalidObjs {
$obj select-state "off"
$obj updateView
}
# recursive check ...
set invalidObjs {}
[%this edArea] findAllInvalidObjs invalidObjs info 1
}
CustEdArea::save [%this edArea]
# go on from where we leave the normal procedure
if {[%this saveAction] != ""} {
eval [%this saveAction]
}
}
.main.saveWarning popUp
}
proc ModuleEdArea::sort {elmA elmB} {
set idxA [$elmA index]
set idxB [$elmB index]
if {$idxA > $idxB} {
return 1
} elseif {$idxB > $idxA} {
return -1
} else {
return 0
}
}
# Do not delete this line -- regeneration end marker