| 1 |
# HubProc.tcl: This is the ASCEND Hub -- what others call an event broker. |
| 2 |
# by Benjamin A. Allan and Kirk A. Abbott |
| 3 |
# Created: January 1994 |
| 4 |
# Part of ASCEND |
| 5 |
# Revision: $Revision: 1.15 $ |
| 6 |
# Last modified on: $Date: 1998/06/18 15:54:46 $ |
| 7 |
# Last modified by: $Author: mthomas $ |
| 8 |
# Revision control file: $RCSfile: HubProc.tcl,v $ |
| 9 |
# |
| 10 |
# This file is part of the ASCEND Tcl/Tk Interface. |
| 11 |
# |
| 12 |
# Copyright (C) 1994-1998 Carnegie Mellon University |
| 13 |
# |
| 14 |
# The ASCEND Tcl/Tk Interface is free software; you can redistribute |
| 15 |
# it and/or modify it under the terms of the GNU General Public |
| 16 |
# License as published by the Free Software Foundation; either |
| 17 |
# version 2 of the License, or (at your option) any later version. |
| 18 |
# |
| 19 |
# The ASCEND Tcl/Tk Interface is distributed in hope that it will be |
| 20 |
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 21 |
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
# GNU General Public License for more details. |
| 23 |
# |
| 24 |
# You should have received a copy of the GNU General Public License |
| 25 |
# along with the program; if not, write to the Free Software |
| 26 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the |
| 27 |
# file named COPYING. COPYING is found in ../compiler. |
| 28 |
|
| 29 |
# |
| 30 |
# proc set_HUB_Defaults {} |
| 31 |
#------------------------------------------------------------------------ |
| 32 |
# This is the ascend HUB. It acts as the event broker for disptching |
| 33 |
# update info for other windows and variables. Any information of interest |
| 34 |
# should be registered with the HUB. New events and their respective actions |
| 35 |
# should be registered in the HUB_Table. Care should be taken that cycles |
| 36 |
# are not created, such that unnecessary updating is done. Every function |
| 37 |
# registered MUST be able to handle 1 argument which is a list which might |
| 38 |
# be empty: |
| 39 |
# |
| 40 |
# proc myfunc {{list ""}} { |
| 41 |
# foreach item $list { |
| 42 |
# puts "$item" |
| 43 |
# } |
| 44 |
# } |
| 45 |
#------------------------------------------------------------------------ |
| 46 |
proc set_HUB_Defaults {} { |
| 47 |
|
| 48 |
global HUB_Table |
| 49 |
|
| 50 |
#------ EVENT ------------------------ INTERESTED functions ------------ |
| 51 |
|
| 52 |
set HUB_Table(SYSFLUSH) [list \ |
| 53 |
Script_Record_Flush \ |
| 54 |
] |
| 55 |
|
| 56 |
set HUB_Table(SIMDELETEDONE) [list \ |
| 57 |
Probe_HandleNewInstances \ |
| 58 |
] |
| 59 |
|
| 60 |
set HUB_Table(SIMDELETED) [list \ |
| 61 |
Probe_HandleSimsDelete \ |
| 62 |
Probe_UserData_HandleSimsDelete \ |
| 63 |
Brow_HandleSimsDelete \ |
| 64 |
Solve_HandleSimsDelete \ |
| 65 |
Script_Record_Delete \ |
| 66 |
Announce_sims_Deleted] |
| 67 |
|
| 68 |
set HUB_Table(LIBDESTROYED) [list \ |
| 69 |
Script_Record_DeleteTypes \ |
| 70 |
Solve_HandleTypesDelete \ |
| 71 |
Sims_HandleTypesDelete \ |
| 72 |
Type_Handle_Sourceread \ |
| 73 |
Units_HandleLibDestroyed] |
| 74 |
|
| 75 |
set HUB_Table(SOLVINGDONE) [list \ |
| 76 |
Probe_HandleVariableUpdated \ |
| 77 |
Brow_HandleVariableUpdated] |
| 78 |
|
| 79 |
set HUB_Table(VARIABLEUPDATED) [list \ |
| 80 |
Probe_HandleVariableUpdated \ |
| 81 |
Brow_HandleVariableUpdated] |
| 82 |
|
| 83 |
set HUB_Table(INSTANCEMOVED) [list \ |
| 84 |
Probe_HandleInstanceMoved \ |
| 85 |
Probe_UserData_HandleInstanceMoved \ |
| 86 |
Solve_HandleInstanceMoved \ |
| 87 |
Sims_HandleInstanceMoved] |
| 88 |
|
| 89 |
set HUB_Table(INSTANCERESUMED) [list \ |
| 90 |
Probe_HandleNewInstances \ |
| 91 |
Script_Record_Resume] |
| 92 |
|
| 93 |
set HUB_Table(BOOLEANUPDATED) [list \ |
| 94 |
Solve_HandleBooleanUpdated] |
| 95 |
|
| 96 |
set HUB_Table(WHENVARUPDATED) [list \ |
| 97 |
Solve_HandleWhenVarUpdated] |
| 98 |
|
| 99 |
set HUB_Table(TYPEHIDDEN) [list \ |
| 100 |
Brow_HandleTypeHidden] |
| 101 |
|
| 102 |
set HUB_Table(SOURCEREAD) [list \ |
| 103 |
Units_HandleSourceRead \ |
| 104 |
Type_Handle_Sourceread \ |
| 105 |
Notes_Handle_Sourceread \ |
| 106 |
Script_Record_Read] |
| 107 |
|
| 108 |
set HUB_Table(UNITSUPDATED) [list \ |
| 109 |
Solve_HandlePrecisionUpdated \ |
| 110 |
Probe_HandleVariableUpdated \ |
| 111 |
Brow_HandleVariableUpdated] |
| 112 |
|
| 113 |
set HUB_Table(SIMCREATED) [list \ |
| 114 |
Script_Record_Compile \ |
| 115 |
Library_Handle_Configure \ |
| 116 |
Probe_HandleNewInstances] |
| 117 |
set HUB_Table(SOLVINGSTARTED) \ |
| 118 |
[list Script_Record_Solve ] |
| 119 |
set HUB_Table(DATAREAD) \ |
| 120 |
[list Script_Record_ValueRead ] |
| 121 |
set HUB_Table(DATAWRITE) \ |
| 122 |
[list Script_Record_ValueWrite ] |
| 123 |
set HUB_Table(CLEARVARS) [list \ |
| 124 |
Script_Record_ClearVars \ |
| 125 |
Probe_HandleVariableUpdated \ |
| 126 |
Brow_HandleVariableUpdated] |
| 127 |
|
| 128 |
set HUB_Table(INSTREFINED) [list \ |
| 129 |
Brow_HandleInstRefined \ |
| 130 |
Probe_HandleNewInstances \ |
| 131 |
Script_Record_Refine] |
| 132 |
|
| 133 |
set HUB_Table(INSTMERGED) [list \ |
| 134 |
Brow_HandleInstMerged \ |
| 135 |
Probe_HandleNewInstances \ |
| 136 |
Script_Record_Merge] |
| 137 |
|
| 138 |
set HUB_Table(INSTBROWSED) \ |
| 139 |
[list Script_Record_Browse ] |
| 140 |
set HUB_Table(VALUESET) \ |
| 141 |
[list Script_Record_Assign ] |
| 142 |
set HUB_Table(PLOTMADE) \ |
| 143 |
[list Script_Record_Plot ] |
| 144 |
set HUB_Table(PROCRUN) \ |
| 145 |
[list Script_Record_Run ] |
| 146 |
set HUB_Table(INSTPROBED) \ |
| 147 |
[list Script_Record_Probe ] |
| 148 |
set HUB_Table(DISPLAYFILLED) \ |
| 149 |
[list Script_Record_Display ] |
| 150 |
set HUB_Table(WINDOWPRINTED) \ |
| 151 |
[list Script_Record_Print ] |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
#Document your event semantics here: |
| 157 |
|
| 158 |
#SIMDELETEDONE |
| 159 |
# meaning: one or more simulations are now gone |
| 160 |
|
| 161 |
#SIMDELETED simname |
| 162 |
# meaning: if you are looking at sim, forget him as he is about to die. |
| 163 |
|
| 164 |
#SYSFLUSH |
| 165 |
# meaning: clear the thing in the solver window. |
| 166 |
# should have a number added to support multiple systems. |
| 167 |
|
| 168 |
#INSTANCEMOVED qlfdid |
| 169 |
# meaning: everybody repoint to or forget about any and all parts of the |
| 170 |
# simulaton corresponding to the given qualified id. There is a particluar |
| 171 |
# Case with the Browser and Script as they might have originated the message |
| 172 |
# themselves. As a result they are not registered under this event. |
| 173 |
|
| 174 |
#INSTREFINED instancename type |
| 175 |
#INSTMERGED instancename1 instancename2 |
| 176 |
#INSTANCERESUMED instancename |
| 177 |
# these are 'informational' messages only. The INSTANCEMOVED message |
| 178 |
# is still the one for C housekeeping. These messages should be sent |
| 179 |
# AFTER a merge or refine so that windows may be updated to reflect the |
| 180 |
# new state of the world after a merge or refine. |
| 181 |
|
| 182 |
#LIBDESTROYED |
| 183 |
# meaning: All types in the interface library have been deleted. |
| 184 |
|
| 185 |
#SOLVINGDONE instancename |
| 186 |
# meaning: solver has finished some execution step and updated real vars |
| 187 |
# probably throughout the sim that instancename is a part of |
| 188 |
|
| 189 |
#VARIABLEUPDATED instancename |
| 190 |
# meaning: internal value of a real/integer may have changed/been set |
| 191 |
# Redisplay if you are interested in instancename or another of its |
| 192 |
# aliases. |
| 193 |
|
| 194 |
#BOOLEANUPDATED instancename |
| 195 |
# meaning: boolean, which generally means model structure change or reset |
| 196 |
# This forces a solver flush if instancename is not given. |
| 197 |
|
| 198 |
#WHENVARUPDATED instancename |
| 199 |
# meaning: boolean, symbol or integer member of a list of whenvars have |
| 200 |
# changed which means model structure change |
| 201 |
# This forces a solver flush |
| 202 |
|
| 203 |
#TYPEHIDDEN |
| 204 |
# meaning: The TYPESHOW bit of a type description has changed. |
| 205 |
# It call for a Update_ChildBox in the browser |
| 206 |
# |
| 207 |
|
| 208 |
#SOURCEREAD filename |
| 209 |
# meaning: new file just successfully read into library |
| 210 |
# type hierarchy may have changed. |
| 211 |
|
| 212 |
#UNITSUPDATED |
| 213 |
# meaning: display value precision or display units changed. |
| 214 |
# redisplay if you want to stay current |
| 215 |
# |
| 216 |
# The following are principally of script interest, though others may |
| 217 |
# also want to look at them if we start accumulating instance history |
| 218 |
# data, for example, as Art has proposed. |
| 219 |
|
| 220 |
#SIMCREATED simname |
| 221 |
# something has been compiled |
| 222 |
|
| 223 |
#DATAREAD filename |
| 224 |
# a values file has been read. the fact that this may have changed something |
| 225 |
# is handled distinctly by VARIABLEUPDATED/BOOLEANUPDATED. |
| 226 |
|
| 227 |
#DATAWRITE instancename filename |
| 228 |
# a values file has been written for instancename |
| 229 |
|
| 230 |
#CLEARVARS instancename |
| 231 |
# all fixed flags in instance have been set to FALSE |
| 232 |
|
| 233 |
#INSTPROBED instancename style |
| 234 |
# instance exported to probe in the style indicated |
| 235 |
# styles are at present ONE (just the item) ALL (probeall meaning) |
| 236 |
|
| 237 |
#INSTBROWSED instancename |
| 238 |
# instance exported to browser |
| 239 |
|
| 240 |
#SOLVINGSTARTED instname solvername |
| 241 |
# Execute.Solve button pushed |
| 242 |
|
| 243 |
#VALUESET instancename value [units] |
| 244 |
# A variable assignment has been done as indicated |
| 245 |
# The fact that this may have changed something |
| 246 |
# is handled distinctly by VARIABLEUPDATED/BOOLEANUPDATED. |
| 247 |
|
| 248 |
#PLOTMADE instancename filename |
| 249 |
# A plot has been made using the currently set plot type |
| 250 |
|
| 251 |
#PROCRUN qlfpid |
| 252 |
# an initialization procedure qlfpid has been executed. |
| 253 |
|
| 254 |
#DISPLAYFILLED |
| 255 |
# something sent to display window |
| 256 |
|
| 257 |
#WINDOWPRINTED window |
| 258 |
# window dumped to printer |
| 259 |
|
| 260 |
# |
| 261 |
# proc HUB_Message_to_HUB {event args} { |
| 262 |
#------------------------------------------------------------------------ |
| 263 |
# Call this function with the event name and any other arguments you wish. |
| 264 |
# All arguments other than the first will be put into the args list. |
| 265 |
# The event will be looked up in global array HUB_Table and the |
| 266 |
# args list passed on to each routine in HUB_Table(event). Routines |
| 267 |
# will be called in the order they appear within the list HUB_Table($event). |
| 268 |
# If the Hub cannot successfully run all routines, it will return 1, else |
| 269 |
# will return 0. Failure of one routine will not stop others from being |
| 270 |
# called. |
| 271 |
# Initiating an event without the arguments indicated above will not be |
| 272 |
# fatal, but may leave the system in an undesirable state or a state more |
| 273 |
# drastically disturbed than is necessary. |
| 274 |
#------------------------------------------------------------------------ |
| 275 |
proc HUB_Message_to_HUB {event args} { |
| 276 |
global HUB_Table |
| 277 |
|
| 278 |
if {[catch {set activitylist $HUB_Table($event)} ]} { |
| 279 |
puts stderr "Interface broker called with unknown event $event" |
| 280 |
return 1 |
| 281 |
} |
| 282 |
set error 0 |
| 283 |
set nok "" |
| 284 |
foreach activity $activitylist { |
| 285 |
if {[catch "$activity $args" nok]} { |
| 286 |
#_don't put {} around the the catch body -- it messes the recording. |
| 287 |
puts "Interface broker error in call:\n $activity $args \n$nok" |
| 288 |
set error 1 |
| 289 |
} |
| 290 |
} |
| 291 |
return $error |
| 292 |
} |
| 293 |
|
| 294 |
proc Announce_sims_Deleted {sims} { |
| 295 |
puts "$sims has been deleted." |
| 296 |
} |