source: tol/tolbase/lib/toltk/tolinspe.tcl @ 025a6ef

1941-docker-image-to-testdevel
Last change on this file since 025a6ef was 025a6ef, checked in by Jorge Pérez <josp.jorge@…>, 15 years ago

refs #1438, se corrije un error con las referencias a archivos incluidos

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@4185 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 128.6 KB
RevLine 
[6d7779d]1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : tolinspe.tcl
3# PURPOSE : This file contains a namespace called TolInspector with its
4#           functions. Its for creating a the TOL object inspector and
5#           managing its events.
6#/////////////////////////////////////////////////////////////////////////////
7
8package require bguifunction
9package require snit
10package require btable
11
12if { 0 && ![info exists toltk_script_path] } {
13  set toltk_script_path [file dirname [info script]]
14  source [file join $toltk_script_path init_toltk.tcl]
15}
16
17if {"unix" eq $::tcl_platform(platform)} {
18  foreach "but units" [list 4 -5 5 5] {
19    set comm [string map "%d $units" {
20      %W yview scroll %d units
21    }]
22    bind TreeView <$but> $comm
23  }
24} else {
25  bind TreeView <MouseWheel> {
26    %W yview scroll [expr int(-1*%D/36)] units
27  }
28}
29#
30##/////////////////////////////////////////////////////////////////////////////
31#proc dump { args } {
32##
33## PURPOSE: Auxiliary procedure to show a string
34##
35##/////////////////////////////////////////////////////////////////////////////
[c14b554]36#puts $args
[6d7779d]37#}
38
39#/////////////////////////////////////////////////////////////////////////////
40proc startupResources { } {
41#
42# PURPOSE: Establishes the preferences of the inspector
43#
44#/////////////////////////////////////////////////////////////////////////////   
45  global tcl_platform
46  global toltk_options
47  DynamicHelp::configure -background #FFFFC0
48  if {[string equal $tcl_platform(platform) "windows"]} {
49    set toltk_options(colors,SystemButtonFace) SystemButtonFace
50    set toltk_options(fonts,MenuNor)           {Tahoma 8}
51    set toltk_options(fonts,Fixed)             {{Courier New} 9}
52    set toltk_options(fonts,FixSmall)          {{Courier New} 8}
53    set toltk_options(fonts,Title1)            {Arial 9 bold}
54    set toltk_options(fonts,Label)             {Arial 9}
55    set toltk_options(fonts,TxtSmall)          {Arial 8}
56    set toltk_options(relief,ridge)            ridge
57  } else {
58    set toltk_options(colors,SystemButtonFace) #d4d4d4
59    set toltk_options(fonts,MenuNor)           {-*-helvetica-medium-r}
60    set toltk_options(fonts,Fixed)             {Courier 9}
61    set toltk_options(fonts,FixSmall)          {-*-courier-small-r}
62    set toltk_options(fonts,Title1)            {-*-helvetica-bold-r}
63    set toltk_options(fonts,Label)             {-*-helvetica-medium-r}
64    set toltk_options(fonts,TxtSmall)          {-*-helvetica-small-r}
65    set toltk_options(relief,ridge)            raised
66  }
67  option add *background         $toltk_options(colors,SystemButtonFace) user
68  option add *Label.font         $toltk_options(fonts,Label) user
69  option add *Radiobutton.font   $toltk_options(fonts,Label) user
70  option add *Checkbutton.font   $toltk_options(fonts,Label) user
71  option add *Button.font        $toltk_options(fonts,Label) user
72  option add *Menu.font          $toltk_options(fonts,MenuNor) user
73  option add *TitleFrame.l.font  $toltk_options(fonts,Title1) user
74  option add *Tabset.selectForeground black user
75
76  option readfile [file join $::toltk_script_path toltk.rc] user
77}
78
79#/////////////////////////////////////////////////////////////////////////////
80namespace eval ::TolInspector {
81#
82# PURPOSE: The purpose of this namespace is creating a the TOL object
83#          inspector and managing its events.
84# VARIABLES:
85#   data:
86#   regFunLst:    List array with functions defined by user
87#   tolset:       Name of the current TOL set variable
88#   tolindex:
89#   at_set:
90#   node_prefix:
91#   ht_tree:      Tree widget containing the TOL objects (:blt::treeview)
92#   blt_tree:     Tree widget containing the TOL objects (:blt::tree)
93#   w_tabset:     Tabset widget containing trees of variables and functions
94#   ht_vars:      Tree widget containing the tree of Variables
95#                 (:blt::treeview)
96#   blt_vartree:  Tree widget containing the tree of Variables (:blt::tree)
97#   data_menu:    Array with data of menus
98#   group_id:
99#   ht_funcs:     Tree widget containing the tree of Functions
100#                 (:blt::treeview)
101#   blt_functree: Tree widget containing the tree of Functions (:blt::tree)
102#   item_data:    Array to hold the full content & description of items
103#   item_id:      Current index of item to insert in ht_* starting from 1
104#   OnSelectItem: Command to invoke on SelectItem in ht_*
105#   OnBusyCmd:    Command to invoke when busy
106#   SubTypeImgs:  Images associated to types of set
107#
108#/////////////////////////////////////////////////////////////////////////////
109  variable data
110 
111  # List array with functions defined by user
112  variable regFunLst
113 
114  # name of the current TOL set variable.
115  variable tolset ""
[c14b554]116  variable tolindex ""
[6d7779d]117  # estas variables desapareceran cuando ::tol::forallchild admita scripts
118  # completos y no solo nombres de proc
119  variable at_set
120  variable node_prefix
121
[dd6e916]122  variable iterSet ""
[301385f]123  variable knownReference ""
124
[8e1d5d3]125  variable gra_parent ""
[6d7779d]126  # tree widget containing the TOL objects.
127  variable ht_tree   ;# is a ::blt::treeview
128  variable blt_tree  ;# is a ::blt::tree
129
130  # tabset widget containing trees of variables and functions
131  variable w_tabset
132
133  # list widget containing the variables. It's the window of
134  # the tab Variable
135  variable ht_vars      ;# is a ::blt::treeview
136  variable blt_vartree  ;# is a ::blt::tree
137 
138  variable data_menu
139  variable group_id -1
140
141  # list widget containing the functions. It's the window of
142  # the tab Functions
143  variable ht_funcs     ;# is a ::blt::treeview
144  variable blt_functree ;# is a ::blt::tree
145
146  # array to hold the full content & description of items
147  variable item_data
148
149  # current index of item to insert in ht_* starting from 1
150  variable item_id
151 
152  # tell if we are processing a SelectSet event
153
154  #variable selecting_set
155  #variable closing
156
157  # command to invoke on SelectItem in ht_*
158  variable OnSelectItem
159
160  # command to invoke when busy
161  variable OnBusyCmd ""
162
163  # images associated to types of set.
164  variable SubTypeImgs {
165    GenericSet MODFile PRJFile DIRFile TOLFile
166    BDCFile BDTFile BSTFile BMTFile BSIFile TSIFile BMIFile
167    StructuredSet TableSet}
168
169}
170
171#/////////////////////////////////////////////////////////////////////////////
172proc ::TolInspector::SubTypeImage { idx } {
173#/////////////////////////////////////////////////////////////////////////////
174  variable SubTypeImgs
175
176  #Tolcon_Trace "SubTypeImage $idx = [lindex $SubTypeImgs $idx]"
177  ::Bitmap::get [lindex $SubTypeImgs $idx]
178}
179
180#/////////////////////////////////////////////////////////////////////////////
181proc ::TolInspector::CreateColumns { ht } {
182#
183# PURPOSE: Creates the columns (index, name, content, path, description )
184#          of the tree of variables or functions
185#
186# PARAMETERS:
187#   ht: path of ::blt::treeview of variables or ::blt::treeview of functions
188#
189#/////////////////////////////////////////////////////////////////////////////
190  # main column ==> Name
191  $ht column configure treeView -text [mc "Name"] -justify left \
192      -bg white -activetitlebackground gray90 -pad 3
193  # index column
194  $ht column insert 0 Index \
195      -bg white -justify left -activetitlebackground gray90
196  # columns Content Path & Description
[6b3f93a]197  #(pgea) se oculta la columna correspondiente a la referencia
[29c8edd]198  $ht column insert end Content Description Path\
[6d7779d]199      -bg white -justify left -activetitlebackground gray90 -pad 3
[edd8cc0]200  $ht column insert end Reference -hide yes
[29c8edd]201  foreach c {Index Content Description Path} {
[6d7779d]202    $ht column configure $c -text [mc "$c"]
203  }
204  # associates the command of order to each one of the titles of the
205  # columns of the trees
206  foreach column [$ht column names] {
207    $ht column configure $column \
208      -command [list ::TolInspector::SortColumn $ht $column]
209  }
210}
211
212#/////////////////////////////////////////////////////////////////////////////
213proc ::TolInspector::SortColumn {ht column} {
214#
215# PURPOSE: Associates the command of order to the title of a column of the
216#          tree of variables or the tree of functions
217#
218# PARAMETERS:
219#   ht:     path of ::blt::treeview of variables or ::blt::treeview of
220#           functions
221#   column: name of the column of this tree
222#
223#///////////////////////////////////////////////////////////////////////////// 
224  set old [$ht sort cget -column]
225  set decreasing 0
226  if { "$old" == "$column" } {
227    set decreasing [$ht sort cget -decreasing]
228    set decreasing [expr !$decreasing]
229  }
230  $ht sort configure -decreasing $decreasing -column $column -mode integer
231  $ht configure -flat no
232  $ht sort auto yes
233
234  blt::busy hold $ht
235  update
236  blt::busy release $ht
237}
238
239
240#/////////////////////////////////////////////////////////////////////////////
241proc ::TolInspector::Create { w args } {
242#
243# PURPOSE: Creates the object inspector, that contains two panels with three
244#          treeviews and three trees.
245#           - One for the left side of the inspector (with grammars,
246#             included files, console objects and object's spool)
247#           - And two for the right one (one for variables tab and one for
248#             functions tab)
249#
250# PARAMETERS:
251#   w:    path where tol inspector must be created
252#   args: list of pairs {-option value} with options for the inspector.
253#      -onselcmd  Comand to execute when a node is selected
254#      -wleft     relative weight of left pane
255#      -wrigth    relative weight of rigth pane
256#
257#/////////////////////////////////////////////////////////////////////////////
258  global toltk_options
259  variable ht_tree
260  variable blt_tree
261  variable ht_vars
262  variable blt_vartree
263  variable data_menu
264  variable ht_funcs
265  variable blt_functree
266  variable w_tabset
267  variable OnSelectItem
268  variable OnBusyCmd ""
269
270  # this should be used insted of a lot of scalar variables.
271  # but, what can we do now?
272
273  variable widgets
274  variable data
275
276  array set data {
277    pool,objects ""
278  }
279
280  array set options {
281    -onselcmd ""
282    -wleft    3
283    -wright   7
284  }
285  array set options $args
286 
287  # initializes the command OnSelectItem to ""
288  set OnSelectItem $options(-onselcmd)
289
290  #variable selecting_set 0
291  #variable closing 0
292
293  #upvar \#0 ::TolTk::Images Images
294
295  # creation of PANED WINDOW MAIN
296  set pwMain [PanedWindow $w -side bottom -pad 0 -width 4]
297  # creation of pane left and pane right
298  set paneLeft  [$pwMain add -weight $options(-wleft)]
299  set paneRight [$pwMain add -weight $options(-wright)]
300  set widgets(panes,left)  $paneLeft
301  set widgets(panes,right) $paneRight
302 
303  # when a panel is destroyed, the item 'geometry,side' of the array variable
304  # data gives the value of the width of panel 'side' (left or right)
305  bind $paneLeft <Destroy> {
306    namespace eval  ::TolInspector {
307      variable data
308      variable widgets
309      set data(geometry,left)  [winfo width $widgets(panes,left)]
310    }
311  } 
312  bind $paneRight <Destroy> {
313    namespace eval  ::TolInspector {
314      variable data
315      variable widgets
316      set data(geometry,right)  [winfo width $widgets(panes,right)]
317    }
318  }
319  # bind for destruction of paned window main
320  bind $pwMain <Destroy> ::TolInspector::Destroy
321
322  # creation of pane left with tree with the TOL OBJECTS
323  CreatePaneLeft  $paneLeft
324  # creation of the right panel with TABSET of VARIABLES and FUNCTIONS
325  CreatePaneRight $paneRight
326  # creation of the menus
327  CreateMenus
328  # packing the panedwindowmain
329  pack $pwMain -fill both -expand yes
330
331  # esto es para evitar que aparezca el icono open cuando
332  # relleno estando el mouse sobre ht_*
333  $ht_vars  bind Entry <Enter>  ""
334  $ht_vars  bind Entry <Leave>  ""
335  $ht_funcs bind Entry <Enter>  ""
336  $ht_funcs bind Entry <Leave>  ""
337}
338
339#/////////////////////////////////////////////////////////////////////////////
340proc ::TolInspector::CreatePaneLeft { paneLeft } {
341#
342# PURPOSE: Creation of TREE LEFT with the TOL OBJECTS
343#
344# PARAMETERS:
345#   paneLeft:  path of the pane of the left in TolInspector
346#
347#/////////////////////////////////////////////////////////////////////////////
348  global toltk_options
349  variable blt_tree
350  variable ht_tree
351 
352  # creation of the ScrolledWindow of the left side
353  set sw1 [ScrolledWindow $paneLeft.sw -ipad 0 -borderwidth 0 -scrollbar both ]
354  # creation of the left tree
355  set blt_tree [::blt::tree create tree$sw1.ht]
356  set ht_tree [::blt::treeview $sw1.ht -tree $blt_tree -bg white \
357           -hideroot no -activeicons "" \
358           -selectbackground gray75 -selectforeground black \
359           -selectcommand ::TolInspector::SelectObject \
360           -highlightthickness 0 -font $toltk_options(fonts,Label)]
361  # configuration of the left tree
362  $ht_tree configure \
363           -closecommand  "::TolInspector::CloseObject %#" \
364           -opencommand   "::TolInspector::OpenObject %#"
365  $ht_tree style configure text -bg white     
366  $ht_tree column configure treeView -bg white
367  $ht_tree column insert end FileName -hide true 
368  # creation of the root node "Tol Objects"
369  set img [::Bitmap::get Objects]
370  $ht_tree entry configure root -label [mc "Tol Objects"]\
371           -icons [list $img $img]
[33b09bc]372
[6d7779d]373  # creation of the node father "Grammars"
374  set img [::Bitmap::get Grammars] 
375  set blt_idx [$blt_tree insert root -label "root-grammars"\
376           -tags "root-grammars"]
377  $ht_tree entry configure $blt_idx -label [mc "Grammars"]\
378           -icons [list $img $img]
379  # Inserts in the node of grammars a node by each grammar that exists in Tol
380  InsertGrammars
[33b09bc]381
382  # creation of the node father "Packages"
383  set img [::Bitmap::get "package"] 
384  set blt_idx [$blt_tree insert root -label "root-packages"\
385           -tags "root-packages"]
386  $ht_tree entry configure $blt_idx -label [mc "Packages"]\
387           -icons [list $img $img] -button yes
388
[6d7779d]389  # creation of the node father "Included Files"
390  set img [::Bitmap::get "Files"]
391  set blt_idx [$blt_tree insert root -label "root-files" -tags "root-files"]
392  $ht_tree entry configure $blt_idx -label [mc "Included Files"] \
393      -icons [list $img $img] -button yes
394  # creation of the node father "Console Objects" 
395  set img [::Bitmap::get "Console"]
396  set blt_idx [$blt_tree insert root -label "root-console"\
397          -tags "root-console"]
398  $ht_tree entry configure $blt_idx -label [mc "Console Objects"] \
399      -icons [list $img $img] -button yes
400  # creation of the node father "Objects' Spool"
401  set img [::Bitmap::get "pool"]
402  set blt_idx [$blt_tree insert root -label "root-pool" -tags "root-pool"]
403  $ht_tree entry configure $blt_idx -label [mc "Objects' Spool"] \
404      -icons [list $img $img] -button yes
405  # associates the tree to scrolled window
406  $sw1 setwidget $ht_tree
407  # packing
408  pack $sw1 -fill both -expand yes
409  # bind the focus on tree
410  bind $ht_tree  <Button-1> "::focus $ht_tree"
411}
412
413#/////////////////////////////////////////////////////////////////////////////
414proc ::TolInspector::CreatePaneRight { paneRight } {
415#
416# PURPOSE: Creation of the right pane with TABSET with VARIABLES and FUNCTIONS
417#
418# PARAMETERS:
419#   paneLeft:  path of the pane of the right in TolInspector
420#
421#/////////////////////////////////////////////////////////////////////////////
422  global toltk_options
423  variable w_tabset
424  variable blt_vartree
425  variable ht_vars
426  variable blt_functree
427  variable ht_funcs
428 
429  # creates the tabset to display the variables & functions   
430  #set w_tabset [::blt::tabset $paneRight.ts -relief flat\
431            -bd 0 -outerpad 0 -tier 2 -slant none -textside top \
432            -highlightthickness 0 -side left -rotate 90]
433  set w_tabset [::blt::tabset $paneRight.ts -relief flat\
434            -bd 0 -outerpad 0 -tier 2 -slant right -textside right \
435            -highlightthickness 0]
436  # creates the scrolled windows for each one of the tabs
437  set sw21 [ScrolledWindow $w_tabset.sw1]
438  set sw22 [ScrolledWindow $w_tabset.sw2]
439  # inserts in the tabset the tabs of functions and variables
440  $w_tabset insert end \
441      Variables -text [mc Variables] -selectbackground \#d9d9d9 -bg gray75 \
442      -image [::Bitmap::get Variables] -pady 0\
443      Functions -text [mc Functions] -selectbackground \#d9d9d9 -bg gray75 \
444      -image [::Bitmap::get Functions] -pady 0
445
446  # Creation of the right TREE RIGHT with VARIABLES
447  set blt_vartree [::blt::tree create tree$sw21.vars]
448  set ht_vars [::blt::treeview $sw21.vars -tree $blt_vartree -flat no\
449           -bg white -hideroot yes -linewidth 0 -activeicons {}\
450           -selectmode multiple\
451           -selectbackground gray75 -selectforeground black \
452           -highlightthickness 0 -font $toltk_options(fonts,Label)]
453  #tv_ordered_selection tvsel -tv $ht_vars
454  # configuration of the tree of variables
455  $ht_vars configure \
456    -opencommand   "::TolInspector::OpenVariable %#" \
457    -selectcommand "::TolInspector::SelectItem $ht_vars"
458  $ht_vars style configure text -bg white
459  bind $ht_vars  <Button-1> "::focus $ht_vars"
460   
461  # Creation of the right TREE RIGHT with FUNCTIONS
462  set blt_functree [::blt::tree create tree$sw22.funcs]
463  set ht_funcs [::blt::treeview $sw22.funcs -tree $blt_functree -flat no\
464          -bg white -hideroot yes -linewidth 0 -activeicons {} \
465          -selectmode multiple\
466          -selectbackground gray75 -selectforeground black \
467          -highlightthickness 0 -font $toltk_options(fonts,Label)]
468  # configuration of the tree of functions
469  $ht_funcs configure  -selectcommand "::TolInspector::SelectItem $ht_funcs"
470  $ht_funcs style configure text -bg white
471  bind $ht_funcs <Button-1> "::focus $ht_funcs"
472 
473  # associates the trees to scrolled windows
474  $sw21 setwidget $ht_vars
475  $sw22 setwidget $ht_funcs
476  # configure the tabs
477  $w_tabset tab configure Variables -window $sw21 -fill both -padx 0
478  $w_tabset tab configure Functions -window $sw22 -fill both -padx 0
479  # create the columns of the trees of variables and functions
480  CreateColumns $ht_vars
481  CreateColumns $ht_funcs
482  # packing the tabset
483  pack $w_tabset -fill both -expand yes
484  $w_tabset tab configure Variables\
485         -command "::TolInspector::SelectItem $ht_vars"
486  $w_tabset tab configure Functions\
487         -command "::TolInspector::SelectItem $ht_funcs"
488}
489
490#/////////////////////////////////////////////////////////////////////////////
491proc ::TolInspector::CreateMenus {} {
492#
493# PURPOSE: Create the menus of the trees
494#
495#/////////////////////////////////////////////////////////////////////////////
496  variable data_menu
497  variable ht_vars
498  variable ht_funcs
499  variable ht_tree
500
501  set data_menu(main)          [menu $ht_vars.m -tearoff 0]
502  set data_menu(Code,File)     [menu $data_menu(main).mcof -tearoff 0]
503  set data_menu(Complex,File)  [menu $data_menu(main).mcxf -tearoff 0]
504  set data_menu(Date,File)     [menu $data_menu(main).mdaf -tearoff 0]
505  set data_menu(Matrix,File)   [menu $data_menu(main).mmaf -tearoff 0]
[c14b554]506  set data_menu(VMatrix,File)  [menu $data_menu(main).mvmf -tearoff 0]
[6d7779d]507  set data_menu(Polyn,File)    [menu $data_menu(main).mpof -tearoff 0]
508  set data_menu(Ratio,File)    [menu $data_menu(main).mraf -tearoff 0]
509  set data_menu(Real,File)     [menu $data_menu(main).mref -tearoff 0]
510  set data_menu(Serie,File)    [menu $data_menu(main).msef -tearoff 0]
511  set data_menu(Set,File)      [menu $data_menu(main).mstf -tearoff 0]
512  set data_menu(File,File)     [menu $data_menu(main).mfif -tearoff 0]
513  set data_menu(Anything,File) [menu $data_menu(main).mspf -tearoff 0]
514  set data_menu(Text,File)     [menu $data_menu(main).mtef -tearoff 0]
515  set data_menu(TimeSet,File)  [menu $data_menu(main).mtif -tearoff 0]
[03885938]516  set data_menu(NameBlock,File)  [menu $data_menu(main).mnbf -tearoff 0]
[6d7779d]517
518  set data_menu(Code,Functions)     [menu $data_menu(main).mcofu -tearoff 0]
519  set data_menu(Complex,Functions)  [menu $data_menu(main).mcxfu -tearoff 0]
520  set data_menu(Date,Functions)     [menu $data_menu(main).mdafu -tearoff 0]
521  set data_menu(Matrix,Functions)   [menu $data_menu(main).mmafu -tearoff 0]
[c14b554]522  set data_menu(VMatrix,Functions)  [menu $data_menu(main).mvmfu -tearoff 0]
[6d7779d]523  set data_menu(Polyn,Functions)    [menu $data_menu(main).mpofu -tearoff 0]
524  set data_menu(Ratio,Functions)    [menu $data_menu(main).mrafu -tearoff 0]
525  set data_menu(Real,Functions)     [menu $data_menu(main).mrefu -tearoff 0]
526  set data_menu(Serie,Functions)    [menu $data_menu(main).msefu -tearoff 0]
527  set data_menu(Set,Functions)      [menu $data_menu(main).mstfu -tearoff 0]
528  set data_menu(File,Functions)     [menu $data_menu(main).mfifu -tearoff 0]
529  set data_menu(Anything,Functions) [menu $data_menu(main).mspfu -tearoff 0]
530  set data_menu(Text,Functions)     [menu $data_menu(main).mtefu -tearoff 0]
531  set data_menu(TimeSet,Functions)  [menu $data_menu(main).mtifu -tearoff 0]
[ca01e16]532  set data_menu(NameBlock,Functions)  [menu $data_menu(main).mnbfu -tearoff 0]
[6d7779d]533
534  set data_menu(Matrix,Table)       [menu $data_menu(main).mmat   -tearoff 0]
535  set data_menu(Matrix,Export)      [menu $data_menu(main).mmae   -tearoff 0]
536  set data_menu(Matrix,Draw)        [menu $data_menu(main).mmac   -tearoff 0]
537  set data_menu(Matrix,Export,BDT)  [menu $data_menu(main).mmaebdt -tearoff 0]
538  set data_menu(Serie,DrawAutocor)  [menu $data_menu(main).mseda  -tearoff 0]
539  set data_menu(Serie,TableAutocor) [menu $data_menu(main).mseta  -tearoff 0]
540  set data_menu(Set,Table)          [menu $data_menu(main).mstt   -tearoff 0]
541  set data_menu(Set,Table2)         [menu $data_menu(main).mstt2  -tearoff 0]
542  set data_menu(Set,Draw)           [menu $data_menu(main).mstd   -tearoff 0]
543  set data_menu(Set,Draw,Special)   [menu $data_menu(main).mstds  -tearoff 0]
544  set data_menu(Set,Draw,Special,M) [menu $data_menu(main).mstdsm -tearoff 0] 
545  set data_menu(File,View)          [menu $data_menu(main).mfiv   -tearoff 0]
546  set data_menu(File,Decompile)     [menu $data_menu(main).mfid   -tearoff 0]
547  set data_menu(TimeSet,View)       [menu $data_menu(main).mtiv   -tearoff 0]
548  #$ht_vars  bind Entry <Button-3> +[$ht_vars bind Entry <Button-1>]
549 
550  # composes the  menus for each one of the trees, depending the node
551  # that is selected
552  $ht_vars  bind all <Button-3> +[list ::TolInspector::PostVariable %X %Y]
553  $ht_funcs bind all <Button-3> +[list ::TolInspector::PostFunction %X %Y]
554  $ht_tree  bind all <Button-3> +[list ::TolInspector::PostTree     %X %Y]
555}
556
557#/////////////////////////////////////////////////////////////////////////////
558proc ::TolInspector::GetWeight { pane } {
559#
560# PURPOSE: Set data(geometry,$pane) to the value of the current geometry
561#          of the pane
562#
563# PARAMETERS:
564#   pane -> string with a value "left" or "right" for each one of panels
565#
566#/////////////////////////////////////////////////////////////////////////////
567  variable widgets
568  variable data
569
570  if {[winfo exists $widgets(panes,$pane)]} {
571    set data(geometry,$pane) [winfo width $widgets(panes,$pane)]
572  }
573  set data(geometry,$pane)
574}
575
576#/////////////////////////////////////////////////////////////////////////////
577proc ::TolInspector::Destroy { } {
578#
579# PURPOSE: Destroys the three trees of TolInspector and array with full
580#          content & description of items
581#
582#///////////////////////////////////////////////////////////////////////////// 
583  variable blt_tree
584  variable blt_vartree
585  variable blt_functree
586  variable item_data
587
588  ::blt::tree destroy $blt_tree
589  ::blt::tree destroy $blt_vartree
590  ::blt::tree destroy $blt_functree
591  unset item_data
592}
593
594#/////////////////////////////////////////////////////////////////////////////
595proc ::TolInspector::OneLine { str } {
596#
597# PURPOSE: Gives a string with carriage returns \n and return this string
598#          until the first carriage return that appears after a word,
599#          replacing the rest by ... if some word existed after that carriage
600#          return
601#          Examples: the str "a\n b c"     returns "a..."
602#                            "\n \n a\n b" returns "a..."
603#                            "\n \n a\n"   returns "a"
604# PARAMETERS:
605#   str -> string with \n
606#
607#/////////////////////////////////////////////////////////////////////////////
608  set str [string trim $str]
609  set lnidx [string first "\n" $str]
610  if { $lnidx != -1 } {
611    if { [incr lnidx -1] > 0 } {
612      return "[string range $str 0 $lnidx]..."
613    } else {
614      return "..."
615    }
616  }
617  set str
618}
619
620#/////////////////////////////////////////////////////////////////////////////
621proc ::TolInspector::TrimContent { grammar content } {
622#///////////////////////////////////////////////////////////////////////////// 
623  if { [string equal "Real" $grammar] } {
624     return [::TolConsole::Format $content]
625  } else {
626    if { [string equal \"\n\" $content] } {
627      set content {"\n"}
628    }
629    return [OneLine $content]
630    set content [string trim $content]
631    set lnidx [string first "\n" $content]
632    if { $lnidx != -1 } {
633      if { [incr lnidx -1] > 0 } {
634        return "[string range $content 0 $lnidx]..."
635      } else {
636        return "..."
637      }
638    }
639    set content
640  }
641}
642
643#/////////////////////////////////////////////////////////////////////////////
644  proc ::TolInspector::_InsertChild { args } {
645#
646# PURPOSE: este proc es para ancapsular desc en una lista
647#
648#/////////////////////////////////////////////////////////////////////////////
649  eval InsertChild [lrange $args 0 3] [list [list [lindex $args 4]]] [lrange $args 5 end]
650}
651
652#/////////////////////////////////////////////////////////////////////////////
653  proc ::TolInspector::InsertChild { args } {
654#
655# PURPOSE: Inserts a node in the corresponding treeview of the right panel.
656#
657# PARAMETERS:
658#   args[0] -> grammar
659#   args[1] -> name
660#   args[2] -> content
661#   args[3] -> path
662#   args[4] -> desc
663#   Si grammar == "Code"
[c14b554]664#    args[5] -> ¿es una variable?
665#   Si grammar == "Set" || "NameBlock"
[6d7779d]666#    args[5] -> indexes of the set
667#    args[6] -> is file?
668#    args[7] -> has subset?
669#    args[8] -> subtype
670#    args[end] -> "Reference {reference}" end > 4
671#
672#/////////////////////////////////////////////////////////////////////////////
673  variable ht_vars
674  variable blt_vartree
675  variable ht_funcs
676  variable blt_functree
[a6e4c78]677  variable gra_parent
[6d7779d]678
[c14b554]679  #puts "InsertChild: args=$args [info level 1]"
[6d7779d]680  set grammar [lindex $args 0]
[b96bc27]681  set name [ lindex $args 1 ]
[6d7779d]682  set content [lindex $args 2]
683  set path    [lindex $args 3]
684  set desc    [lindex [lindex $args 4] 0]
[a6e4c78]685
686
[6d7779d]687  if {[llength [lindex $args end]] >= 2} {
[c14b554]688    #set ref [list [lindex [lindex $args end] 0] [lrange [lindex $args end] 1 end]]
689    set ref [concat [lindex [lindex $args end] 0] [lrange [lindex $args end] 1 end]]
[6d7779d]690  } else {
691    set ref ""     
692  }
[c14b554]693  #puts "InsertChild: ref=$ref"
[6d7779d]694  switch $grammar {
695    Code {
696      set isvar [lindex $args 5]
697      if { [string equal $isvar "1"] } {
698        Insert_HTItem $ht_vars $blt_vartree $grammar $name $content $path $desc $ref
699      } else {
700        Insert_HTItem $ht_funcs $blt_functree $grammar $name $content $path $desc $ref
701      }
702    }
[c14b554]703    NameBlock -
[6d7779d]704    Set {
[025a6ef]705      puts "HTItem, ref = '$ref' '$args'"
[6d7779d]706      # args[5] is the index of the set object
707      # args[6] is the flag file
708      # args[8] is the subtype
709      Insert_HTItem $ht_vars $blt_vartree $grammar $name $content $path $desc \
710        [lindex $args 5] [lindex $args 6] [lindex $args 8] $ref
711    }
712    default {
713      Insert_HTItem $ht_vars $blt_vartree $grammar $name $content $path $desc $ref
714    }
715  }
716}
717
718# si grammar == "Set"
719#   args[0] -> indexes
[c14b554]720#   args[1] -> ¿is a file?
[6d7779d]721#   args[2] -> subtype
722
723#/////////////////////////////////////////////////////////////////////////////
724proc ::TolInspector::Insert_HTItem {ht tree grammar name content path desc args} {
725#/////////////////////////////////////////////////////////////////////////////
726  variable ht_tree
727  variable tolset
728  variable tolindex
[301385f]729  variable iterSet
730  variable knownReference
[6d7779d]731  variable node_prefix
732  variable item_data
733  variable item_id
[b96bc27]734  variable gra_parent
735
[6d7779d]736  #upvar \#0 ::TolTk::Images Images
737
[7a0e436f]738  #puts "ENTER: ::TolInspector::Insert_HTItem"
[dd6e916]739  if { $knownReference eq "" } {
740    set objRef $iterSet
741    lappend objRef $item_id
742  } else {
[7a0e436f]743    #puts "knownReference = $knownReference"
[dd6e916]744    set objRef $knownReference
745  }
746
[7a0e436f]747  #puts "\tobjRef = $objRef"
[b96bc27]748  if { $gra_parent eq "NameBlock" } {
749    array set info_member [ FilterNameBlockMember $name ]
750    if { !$info_member(-show) } {
[462fc07]751      incr item_id
[b96bc27]752      return
753    }
754    set fcolor $info_member(-fcolor)
755  } else {
756    set fcolor "black"
757  }
758
[6d7779d]759  set brief_cont [TrimContent $grammar $content]
760  set brief_desc [TrimContent DONTCARE $desc]
[c14b554]761  #puts "Insert_HTItem: args=$args"
[6d7779d]762  if {[llength [lindex $args end]] >= 2} {
763    set ref_value [lindex [lindex $args end] 1]
[c14b554]764  } elseif {[regexp -- "console" $node_prefix]} {
765    set ref_value [list Console]
[7a0e436f]766    eval lappend ref_value $tolindex $item_id
[6d7779d]767  } else {
768    set ref_value ""
769  }
[c14b554]770
771  #puts "Insert_HTItem: ref_value=$ref_value tolindex=$tolindex item_id=$item_id node_prefix=$node_prefix"
772  #puts "\ttolset=$tolset"
[6d7779d]773  set data [list Index      $item_id \
774                Content     $brief_cont \
775                Path        $path \
776                Description $brief_desc \
777                Reference   $ref_value]
778
[c14b554]779  if {$grammar eq "Set" || $grammar eq "NameBlock"} {
[6d7779d]780    if {[string length $tolset] || [regexp "console" $node_prefix]} {
781      # OJO: si tolset == "" no implica que no estemos en un Set
782      # por ejemplo un Set de la consola.
783      set item [GetItemName $node_prefix [lindex $args 0]]
784      #Tolcon_Trace "InsertHTItem. item(if): $item"
785    } else {
786      switch [lindex [$ht_tree get -full anchor] end] {
787        root-files {
788          set item file$item_id
789        }
790        root-console {
791          set item console$item_id
792        }
793        root-pool {
794          set item pool$item_id
795        }
796        default {
797          set item item$item_id
798        }
799      }
800    }
801    # aqui hay que pedir el bitmap en funcion del subtype: args[2]
[c14b554]802    if {$grammar eq "Set"} {
[7a0e436f]803      #puts "*******Set $objRef *******"
[c14b554]804      set icon_grammar [SubTypeImage [lindex $args 2]]
[7a0e436f]805      set data [lreplace $data 9 9 $objRef] 
[c14b554]806    } else {
[6b3f93a]807      #(pgea) se reemplaza el valor de la referencia en data
808      set data [lreplace $data 9 9 $objRef] 
[dd6e916]809      #(pgea) se utiliza la informacon de instancia
[025a6ef]810      puts "Tol_ClassOfFromReference $objRef"
[6b3f93a]811      set classOf [Tol_ClassOfFromReference $objRef]
[025a6ef]812      puts "Tol_InstanceContentFromReference $objRef"
[6b3f93a]813      set insCont [Tol_InstanceContentFromReference $objRef]
814      if {$insCont ne ""} {
815        set data [lreplace $data 3 3 [TrimContent $grammar $insCont]]
816      } elseif {$classOf ne ""} {
817        set data [lreplace $data 3 3 $classOf]
818      }
[e3362cc]819      set objAddress [ tol::info address $objRef ]
820      set icon_grammar [ ::ImageManager::getIconForInstance $objAddress ]
[c14b554]821    }
[dd6e916]822  } elseif { $grammar eq "Anything" } {
823    set item "item$item_id"
824    set anyType [ tol::info anything $objRef ]
825    set icon_grammar [ ::Bitmap::get $anyType ]
[6d7779d]826  } else {
827    set item "item$item_id"
[dd6e916]828    set icon_grammar [ ::Bitmap::get $grammar ]
[6d7779d]829  }
830  set idnew [$tree insert 0 -label $item]
831  set label [OneLine $name]
832  if {$label eq ""} {
833    if {[set label $brief_desc] eq ""} {
834      set label " "
835    }
836  }
837  $ht entry configure $idnew -label $label \
[b96bc27]838      -icons [list $icon_grammar $icon_grammar] -data $data \
839       -foreground $fcolor
[6d7779d]840  set item_data($item_id) [list $content $desc $grammar]
841  incr item_id
842}
843
844#/////////////////////////////////////////////////////////////////////////////
845proc ::TolInspector::ClearHiertables { } {
846#
847# PURPOSE:
848#
849#/////////////////////////////////////////////////////////////////////////////
850  variable w_tabset
851  variable ht_vars
852  variable ht_funcs
853  variable item_data
854  variable OnSelectItem
855
856  $ht_vars  entry delete root 0 end
857  $ht_funcs entry delete root 0 end
858  $ht_vars column  configure Index -hide no
859  $ht_funcs column configure Index -hide no
860  catch {
861    unset item_data
862  }
863  $w_tabset tab configure Variables -text [mc Variables] -state normal
864  $w_tabset tab configure Functions -state normal
865
866  if { [string length $OnSelectItem] } {
867    $OnSelectItem
868  }
869}
870
[33b09bc]871# este proc debe pasar a ser un getContainerReference
872#
873proc ::TolInspector::getPackageReference { treePath } {
874  variable ht_tree
875
[325ee5e]876  #puts "::TolInspector::getPackageReference $treePath"
[33b09bc]877  catch {
878    set typeContainer "NameBlock"
879    set order [ lindex  [ split [ lindex $treePath 2 ] "-" ] end ]
880    incr order -1
881    #puts "path,2 = [ lindex $treePath 2 ]"
882    #puts "order = $order"
[325ee5e]883    set idx [lindex [ $ht_tree entry children "root-packages"] $order]
[33b09bc]884    set nameContainer [ $ht_tree entry cget $idx -label ]
885    #puts "en root-package:"
886    #puts "\torder=$order"
887    #puts "\tidx=$idx"
[325ee5e]888    #puts "\tnameContainer=$nameContainer"
[33b09bc]889    set container [ list $typeContainer $nameContainer ]
890    if { [ llength $treePath ] > 3 } {
891      foreach c [ lrange $treePath 3 end-1 ] {
892        set orderItem [ lindex  [ split $c "-" ] end ]
893        lappend container $orderItem
894      }
895      set tolindex [ lindex  [ split [ lindex $treePath end ] "-" ] end ]
896    } else {
897      set tolindex [ list ]
898    }
899  } msg
900  #puts "::TolInspector::getPackageReference: $msg"
[325ee5e]901  #puts "::TolInspector::getPackageReference: [ list $container $tolindex ]"
[33b09bc]902  return [ list $container $tolindex ]
903}
904
[6d7779d]905#/////////////////////////////////////////////////////////////////////////////
906proc ::TolInspector::OpenObject { index } {
907#
908# PURPOSE: Script called each time a node in ht_tree (left treeview) is
909#          opened.
910#
911# PARAMETERS:
912#   index : The id of the node opened
913#
914#/////////////////////////////////////////////////////////////////////////////
915  variable tolset
916  variable tolindex
[301385f]917  variable iterSet
[6d7779d]918  variable at_set
919  variable node_prefix
920  variable ht_tree
921  variable data
922
[c14b554]923  #puts "OpenObject: index=$index"
924  set path [$ht_tree get -full $index]
[33b09bc]925  #puts "path = $path"
[6d7779d]926  if { $index } {
927    set parent1 [lindex $path 1]
[33b09bc]928    if { [set ispackage [string equal $parent1 "root-packages"]] ||
929         [set isfile [string equal $parent1 "root-files"]] ||
[6d7779d]930         [set isconsole [string equal $parent1 "root-console"]] ||
931         [string equal $parent1 "root-pool"] } {
932      set lpath [llength $path]
[c14b554]933      #puts "lpath = $lpath"
[6d7779d]934      if { $lpath == 2 } {
[33b09bc]935        if { $ispackage } {
936          InsertPackages
937        } elseif { $isfile } {
[6d7779d]938          InsertFiles
939        } elseif { $isconsole } {
940          InsertConsoleObj
941        } else {
942          InsertPoolObj
943        }
944      } else {
[c14b554]945        #puts "OpenObject: path = $path"
[6d7779d]946        set leaf [lindex $path end]
947        set leaf_info [split $leaf "-"]
948        set node_prefix [lindex $leaf_info 0]
949        set _tolset $tolset
[33b09bc]950        if { $parent1 eq "root-packages" } {
951          foreach {tolset tolindex} [ getPackageReference $path ] break
952        } elseif { [string equal $parent1 "root-pool"] } {
[6d7779d]953          #Tolcon_Trace "OpenObject. tolset=$tolset"
954          set tolset $data(pool,reference,[lindex $leaf_info 0])
[c14b554]955          #puts "OpenObject: Spool: tolset=$tolset, leaf_info=$leaf_info"
[6d7779d]956          if { $lpath == 3 } {
957            set tolindex [lrange $tolset 1 end]
958            set tolset [lindex $tolset 0]
959          } else {
960            set tolindex [lrange $leaf_info 1 end]
[c14b554]961                    if {[lindex $tolset 0] eq "Console"} {
962                      set tolset [lindex $tolset 0] 
963                    } else {
964                      set tolset [lrange $tolset 0 1]
965                    }
966            #set tolindex [lrange $tolset 1 end]
967            #set tolset [lindex $tolset 0]
968            #lappend tolindex [lindex $leaf_info end]
[6d7779d]969          }
970          #Tolcon_Trace "OpenObject. tolset=$tolset"
971        } elseif {[regexp -- "console(.+)" $node_prefix --> idx_con]} {
[c14b554]972          set tolset "Console"
[7a0e436f]973          #puts "OpenObject: Console: leaf_info = $leaf_info"
[6d7779d]974          if {[llength $leaf_info] == 1} {
975            set tolindex $idx_con
976          } else {
[c14b554]977            #set tolindex [list $idx_con [lrange $leaf_info 1 end]]
[6d7779d]978            set tolindex [lrange $leaf_info 1 end]
979          }
980        } else {
981          set idx [$ht_tree find -name $node_prefix]
982          array set aryData [$ht_tree entry cget $idx -data]
[c14b554]983          set tolset [list File $aryData(FileName)]
[6d7779d]984          #set tolset [$ht_tree entry cget [$ht_tree find -name $node_prefix] -label]
985          if { $lpath == 3 } {
986            set tolindex ""
987          } else {
988            set tolindex [lrange $leaf_info 1 end]
989          }
990        }
991        Busy
992        set at_set $index
[301385f]993        set iterSet [eval list $tolset $tolindex]
994        variable gra_parent [ GetParentGrammar $iterSet ]
995        ::tol::forallchild $iterSet ::TolInspector::InsertSubset
[6d7779d]996        set tolset $_tolset
997        NotBusy
998      }
999    }
1000  }
1001}
1002
1003#/////////////////////////////////////////////////////////////////////////////
[33b09bc]1004proc ::TolInspector::InsertPackages {} {
1005#
1006# PURPOSE: Inserts a node in ht_tree (left ::blt::treeview) for each TOL
1007#          packages
1008#
1009#/////////////////////////////////////////////////////////////////////////////
1010  variable ht_tree
1011  #upvar \#0 ::TolTk::Images Images
1012   
1013  set order 1
1014  foreach pkg [::tol::info packages] {
1015    # takes an icon with the same name that the grammar
1016    set img [ ::Bitmap::get NameBlock ]
1017    $ht_tree insert -at "root-packages" end package-$order -label $pkg\
1018          -icons [list $img $img] -button yes
1019    incr order
1020  }
1021}
1022
1023#/////////////////////////////////////////////////////////////////////////////
[6d7779d]1024proc ::TolInspector::InsertGrammars {} {
1025#
1026# PURPOSE: Inserts a node in ht_tree (left ::blt::treeview) for each TOL
1027#          grammar
1028#
1029#/////////////////////////////////////////////////////////////////////////////
1030  variable ht_tree
1031  #upvar \#0 ::TolTk::Images Images
1032   
1033  set id 1
1034  foreach g [::tol::info grammars] {
1035    # takes an icon with the same name that the grammar
1036    set img [::Bitmap::get $g]
1037    $ht_tree insert -at "root-grammars" end grammar-$id -label $g\
1038          -icons [list $img $img]
1039    incr id
1040  }
1041}
1042
1043#/////////////////////////////////////////////////////////////////////////////
1044proc ::TolInspector::InsertFiles { } {
1045#
1046# PURPOSE: Inserts a node in ht_tree (left treeview) for each Included file
1047#
1048#/////////////////////////////////////////////////////////////////////////////
1049  variable ht_tree
1050  variable blt_tree
1051
1052  set index 1
1053  #set img [::Bitmap::get "File"]
1054  foreach f [lreverse [::tol::info included]] {
1055    set finfo   [::tol::info included $f]
1056    set button  [lindex $finfo 3]
1057    set subtype [lindex $finfo 4]
1058    # tomar la imagen en funcion del subtype
1059    set img [SubTypeImage $subtype]
1060    set tag_file "file$index"
1061    set blt_idx [$blt_tree insert "root-files" \
1062             -label $tag_file -tags $tag_file]
[c14b554]1063    # Tail del fichero. Podría hacerse configurable por el usuario
[6d7779d]1064    set label [file tail $f]
1065    $ht_tree entry configure $blt_idx -label $label\
1066    -icons  [list $img $img] -button $button -data [list "FileName" $f]
1067    incr index
1068  }
1069}
1070
1071#/////////////////////////////////////////////////////////////////////////////
1072proc ::TolInspector::InsertConsoleObj { } {
1073#
1074# PURPOSE: Inserts a node in ht_tree (left treeview) for each Console object
1075#
1076#/////////////////////////////////////////////////////////////////////////////
1077  variable ht_tree
1078  variable has_button 0
1079   
1080  set index 1
1081  foreach co [::tol::console stack list] {
1082    set grammar [lindex $co 0]
[c14b554]1083    if {$grammar eq "Set" || $grammar eq "NameBlock"} {
[6d7779d]1084      # SUBTYPE: icono en funcion de [lindex $co 7]
[c14b554]1085      if {$grammar eq "Set"} {
1086        set icon [SubTypeImage [lindex $co 7]]
1087      } else  {
[301385f]1088        set objRef [ list "Console" $index ]
[e3362cc]1089        set objAddress [ tol::info address $objRef ]
1090        set icon [ ::ImageManager::getIconForInstance $objAddress ]
[c14b554]1091      }
[6d7779d]1092      set name [lindex $co 1]
1093      #tol::forallchild $name HasSubset
1094      set has_button [lindex $co 6]
1095      if {$name eq ""} {
1096        if {[set name [TrimContent DONTCARE [lindex $co 4]]] eq ""} {
1097          set name " "
1098        }
1099      }
1100      $ht_tree insert -at root-console end "console$index" -label $name \
1101          -icons  [list $icon $icon] -button $has_button -data [list "FileName" $index]
1102    }
1103    incr index
1104  }
1105}
1106
1107#/////////////////////////////////////////////////////////////////////////////
1108proc ::TolInspector::InsertPoolObj { } {
1109#
1110# PURPOSE: Inserts a node in ht_tree (left treeview) for each object in Spool
1111#
1112#/////////////////////////////////////////////////////////////////////////////
1113  variable data
1114  variable ht_tree
1115  array unset data pool,reference,*
1116  set index 1
1117
1118  foreach _obj $data(pool,objects) {
1119    #Tolcon_Trace "InsertPoolObj. _obj=$_obj"
1120    array set obj $_obj
[c14b554]1121    if { [string equal $obj(grammar) "Set"] || [string equal $obj(grammar) "NameBlock"] } {
[6d7779d]1122      #Si la referencia del objeto tiene espacios en la ruta, el
[c14b554]1123      # llength me daría > 1, por eso añado la 2ª parte de la condicion
[6d7779d]1124      if { ([llength $obj(reference)] > 1) && \
1125            ![string equal $obj(reference) $obj(objName)]} {
1126        set infoObj [::tol::info variable $obj(reference)]
1127      } else {
1128        if {[catch { set infoObj [concat [list "Set" $obj(reference)] \
1129                            [::tol::info included $obj(reference)]] }]} {
1130          set infoObj [concat [list "Set" $obj(reference)] \
1131                 [::tol::info variable "Set" $obj(reference)]]
1132        } else {
1133          # Insertamos el 1 de isFile
1134          set infoObj [linsert $infoObj 5 1]
1135        }
1136      }
1137      #Tolcon_Trace "infoObj=$infoObj"
1138      if {[set name [file tail [lindex $infoObj 1]]] eq ""} {
1139        if {[set name [TrimContent DONTCARE [lindex $infoObj 4]]] eq ""} {
1140          set name " "
1141        }
1142      }
1143      set has_button [lindex $infoObj 6]
[c14b554]1144      #set icon [SubTypeImage [lindex $infoObj 7]]
1145      if {$obj(grammar) eq "Set"} {
1146        set icon [SubTypeImage [lindex $infoObj 7]]
1147      } else  {
[7a0e436f]1148        #puts "en pool = $obj(reference)"
[e3362cc]1149        set objAddress [ tol::info address $objRef ]
1150        set icon [ ::ImageManager::getIconForInstance $objAddress ]
[c14b554]1151      }
1152
[301385f]1153      $ht_tree insert -at root-pool end "pool$index" -label $name \
1154          -icon [list $icon $icon] -button $has_button
[6d7779d]1155      #Tolcon_Trace "InsertPoolObj. name=$name"
1156      if { ([llength $obj(reference)] > 1) && \
1157            [string equal $obj(reference) $obj(objName)]} {
1158        set obj(reference) [list $obj(reference)]
1159      }
1160      set data(pool,reference,pool$index) $obj(reference)
1161    }
1162    incr index
1163  }
1164}
1165
[b96bc27]1166proc ::TolInspector::FilterNameBlockMember { name } {
[b9ea255]1167  set st_reg [ regexp {(.+::)?(_)?(\.)?(.*)} $name => p1 p2 p3 p4]
[b96bc27]1168  if { !$st_reg } {
1169    list -show 1 -fcolor "black" -name $name
1170  } elseif { $p2 eq "_" } {
1171    if { $p3 eq "." } {
[29c8edd]1172      if { [string match {autodoc.member.*} $p4] } {
1173        # es un elemento de autodocumentacion y no se muestra
1174        list -show 0
1175      } {
1176        # es un miembro de solo lectura
[b9ea255]1177        list -show 1 -fcolor "gray50" -name "_.$p4"
[29c8edd]1178      }
[b96bc27]1179    } else {
[67102d7]1180      # es un miembro oculto,
1181      set showPrivate [ Tol_GetViewPrivateMembers ]
1182      list -show $showPrivate -fcolor "gray75" -name "_$p4"
[b96bc27]1183    }
1184  } else {
1185    list -show 1 -fcolor "black" -name $p4
1186  }
1187}
1188
[6d7779d]1189#/////////////////////////////////////////////////////////////////////////////
1190proc ::TolInspector::InsertSubset { args } {
1191#
1192# PURPOSE: Inserts a node in ht_tree (left treeview) for each child of a Set
1193#
1194# PARAMETERS:
1195#   args[0] -> grammar
1196#   args[1] -> name
1197#   args[2] -> content
1198#   args[3] -> path
1199#   args[4] -> desc
1200#   Si grammar == "Set"
1201#    args[5] -> indexes of the set
1202#    args[6] -> is file?
1203#    args[7] -> has subset?
1204#    args[8] -> subtype
1205#
1206#/////////////////////////////////////////////////////////////////////////////
1207  variable ht_tree
1208  variable at_set
1209  variable tolset
[301385f]1210  variable iterSet
[6d7779d]1211  variable node_prefix
1212  variable has_button 0
1213  variable blt_tree
[a6e4c78]1214  variable gra_parent
[33b09bc]1215  catch {
[c14b554]1216  #puts "InsertSubset, args=$args"
1217  set grammar [lindex $args 0]
1218  if {$grammar eq "Set" || $grammar eq "NameBlock"} {
[e3362cc]1219    #puts "InsertSubset, args=$args"
[b96bc27]1220    if { $gra_parent eq "NameBlock" } {
1221      array set info_member [ FilterNameBlockMember [ lindex $args 1 ] ]
1222      if { !$info_member(-show) } {
1223        return
1224      }
1225      set name $info_member(-name)
1226      set fcolor $info_member(-fcolor)
1227    } else {
[8e1d5d3]1228      set name [ lindex $args 1 ]
[b96bc27]1229      set fcolor "black"
1230    }
[6d7779d]1231    set content [lindex $args 2]
[301385f]1232    # idx es el indice completo desde el Set root
[6d7779d]1233    set idx     [lindex $args 5]
1234    set isfile  [lindex $args 6]
1235    set has_button [lindex $args 7]
1236    set subtype [lindex $args 8]
1237    #tol::forallchild $tolset $idx HasSubset
[c14b554]1238    if {$grammar eq "Set"} {
1239      set icon [SubTypeImage $subtype]
1240    } else {
[301385f]1241      set objRef $iterSet
1242      lappend objRef [ lindex $idx end ]
[e3362cc]1243      set objAddress [ tol::info address $objRef ]
1244      set icon [ ::ImageManager::getIconForInstance $objAddress ]
[c14b554]1245    }
1246    # Tail por si es un fichero. Podría hacerse configurable por el usuario
[6d7779d]1247    set label [file tail $name]
[c14b554]1248    #puts [list InsertSubset, idx {lindex $args 5} = $idx]
[b96bc27]1249    set idnew [ $blt_tree insert $at_set \
1250                   -label [ GetItemName $node_prefix $idx ] ]
[6d7779d]1251
[c14b554]1252    #puts "InsertSubset, node_prefix = $node_prefix"
1253    #puts "InsertSubset, idnew = $idnew"
1254    #puts "InsertSubset, -label = [GetItemName $node_prefix $idx]"
[6d7779d]1255
1256    if {$label eq ""} {
1257      if {[set label [TrimContent DONTCARE [lindex $args 4]]] eq ""} {
1258        set label " "
1259      }
1260    }
1261    $ht_tree entry configure $idnew -label $label -button $has_button \
[b96bc27]1262      -icons [list $icon $icon] -foreground $fcolor
[6d7779d]1263  }
[33b09bc]1264} msg
1265#puts "InsertSubSet: $msg"
[6d7779d]1266}
1267
1268#/////////////////////////////////////////////////////////////////////////////
1269proc ::TolInspector::ClearConsoleObj { } {
1270#/////////////////////////////////////////////////////////////////////////////
1271  variable ht_tree
1272  variable data
1273   
1274  set idx_con [$ht_tree index root-console]
1275  $ht_tree entry delete $idx_con 0 end
1276   
1277  #Quitamos del spool todos los objetos que provengan de la consola
1278  foreach _obj $data(pool,objects) {
1279    array set obj $_obj
1280    if {[string equal $obj(origin) "root-console"]} {
1281      set idx [lsearch $data(pool,objects) $_obj]
1282      set data(pool,objects) [lreplace $data(pool,objects) $idx $idx]
1283    }
1284  }
1285  UpdatePoolObj
1286  #Finalmente limpiamos el stack de la consola de tol
1287  ::tol::console stack release
1288}
1289
1290#/////////////////////////////////////////////////////////////////////////////
1291proc ::TolInspector::ClearConsoleObjSel {ht} {
1292#/////////////////////////////////////////////////////////////////////////////
1293  variable vars_selected
1294  variable data
1295
1296  foreach var $vars_selected {
1297    set name [$ht entry cget $var -label]
1298    #puts "name=$name"
1299    #Quitamos del spool todos los objetos que provengan de la consola
1300    foreach _obj $data(pool,objects) {
1301      array set obj $_obj
1302      #puts "_obj=$_obj"
1303      if {[string equal $obj(origin) "root-console"] && [string equal $obj(objName) $name]} {
1304        set idx [lsearch $data(pool,objects) $_obj]
1305        set data(pool,objects) [lreplace $data(pool,objects) $idx $idx]
1306      }
1307    }
1308    UpdatePoolObj
1309    #Finalmente quitamos el objeto de la consola de tol
1310    ::tol::console stack release $name
1311  }
1312  UpdateConsoleObj
1313}
1314
1315#/////////////////////////////////////////////////////////////////////////////
1316proc ::TolInspector::UpdateFileRoot { } {
1317#///////////////////////////////////////////////////////////////////////////// 
1318  variable ht_tree
1319  set open 0
1320  set idx_file [$ht_tree index root-files]
1321  if { [$ht_tree entry isopen $idx_file] } {
1322    $ht_tree close $idx_file
1323    set open 1
1324  }
1325  if { [$ht_tree index focus] == $idx_file } {
1326    SelectObject
1327  }
1328  if $open {
1329    $ht_tree open $idx_file
1330  }
1331}
1332
1333#/////////////////////////////////////////////////////////////////////////////
1334proc ::TolInspector::UpdateConsoleObj { } {
1335#///////////////////////////////////////////////////////////////////////////// 
1336  variable ht_tree
1337
1338  set idx_con [$ht_tree index root-console]
1339  if { [$ht_tree entry isopen $idx_con] } {
1340    $ht_tree close $idx_con
1341  }
1342  $ht_tree selection anchor root-console
1343  $ht_tree selection mark root-console
1344  #Tolcon_Trace "Abierto el nodo root-console"
1345  if { [$ht_tree index focus] == $idx_con } {
1346    SelectObject
1347  }
1348}
1349
1350
1351#/////////////////////////////////////////////////////////////////////////////
1352proc ::TolInspector::UpdatePoolObj { } {
1353#///////////////////////////////////////////////////////////////////////////// 
1354  variable ht_tree
1355
1356  set idx_pool [$ht_tree index root-pool]
1357  if { [$ht_tree entry isopen $idx_pool] } {
1358    $ht_tree close $idx_pool
1359  }
1360  if { [$ht_tree index focus] == $idx_pool } {
1361    SelectObject
1362  }
1363}
1364
1365
1366#/////////////////////////////////////////////////////////////////////////////
1367proc ::TolInspector::SelectObject { } {
1368#
1369# PURPOSE: Script called each time a node in ht_tree (left treeview) is
1370#          selected.
1371#
1372#/////////////////////////////////////////////////////////////////////////////
1373  #Tolcon_Trace "LLAMADA A SELECTOBJECT"
1374  variable w_tabset
1375  variable ht_tree
[c14b554]1376  #variable set_type ""
[6d7779d]1377  variable tolset
1378  variable tolindex
1379  #variable closing
1380  variable node_prefix ""
1381  variable data
[025a6ef]1382  variable knownReference ""
[6d7779d]1383
1384  set index [$ht_tree index anchor]
1385   
1386  if { ![string length $index] } {
1387    ClearHiertables
1388    return
1389  }
1390  ClearHiertables
1391
[33b09bc]1392  set path [ $ht_tree get -full $index ]
[6d7779d]1393  set tolset ""
1394  if { $index } {
[c14b554]1395    #puts "SelectObject index = $index"
[33b09bc]1396    #puts "SelectObject: full = $path"
1397    set info_node [split [lindex $path end] "-"] ;# ojo si el path tiene -
[6d7779d]1398    set node_type [lindex $info_node 0]
1399    set node_name [lindex $info_node 1]
[c14b554]1400    #puts "SelectObject: info_node = $info_node"
[6d7779d]1401  } else {
1402    set node_type root
1403    set node_name root
1404  }
1405
1406  Busy
[33b09bc]1407  #puts "SelectObject: node_type = $node_type, node_name = $node_name"
[6d7779d]1408  switch -regexp $node_type  {
1409    root {
1410      switch $node_name {
1411        root -
1412        grammars {
1413          ClearHiertables
1414          #$w_tabset tab configure Variables -state disabled
1415          #$w_tabset tab configure Functions -state disabled
1416        }
[33b09bc]1417        package {
1418          puts "implementa el llenado del panel derecho"
1419        }
[6d7779d]1420        files {
1421          SelectFileRoot
1422        }
1423        console {
1424          SelectConsoleRoot
1425        }
1426        pool {
1427          SelectPoolRoot
1428        }
1429      }
1430    }
1431    grammar {
1432      SelectGrammar
1433    }
1434    default {
1435      set node_prefix $node_type
[7a0e436f]1436      #puts "SelectObject: node_prefix = $node_prefix"
[33b09bc]1437      if { $node_type eq "package" } {
1438        foreach {tolset tolindex} [ getPackageReference $path ] break
1439      } elseif {[regexp -- "pool" $node_type]} {
[6d7779d]1440        set tolset $data(pool,reference,[lindex $node_type 0])
[c14b554]1441        #puts "SelectObject: Spool: tolset=$tolset, info_node=$info_node"
[6d7779d]1442        if { [llength $info_node] == 1 } {
1443          set tolindex [lrange $tolset 1 end]
1444          set tolset [lindex $tolset 0]
1445        } else {
[c14b554]1446          #set tolindex [lrange $tolset 1 end]
1447          #set tolset [lindex $tolset 0]
1448          #lappend tolindex [lindex $info_node end]
[6d7779d]1449          set tolindex [lrange $info_node 1 end]
[33b09bc]1450          if {[lindex $tolset 0] eq "Console"} {
1451            set tolset [lindex $tolset 0] 
1452          } else {
1453            set tolset [lrange $tolset 0 1]
1454          }
[6d7779d]1455        }
1456      } elseif {[regexp -- "console(.+)" $node_type --> idx_con]} {
[33b09bc]1457        #puts "SelectObject: Console: tolset=$tolset info_node=$info_node idx_con=$idx_con"
[c14b554]1458        set tolset "Console"
[6d7779d]1459        #set idx [$ht_tree find -name $node_type]
1460        #array set aryData [$ht_tree entry cget $idx -data]
1461        #set tolindex [eval list $aryData(FileName) [lrange $info_node 1 end]]
1462        if {[llength $info_node] == 1} {
1463          set tolindex $idx_con
1464        } else {
1465          set tolindex [lrange $info_node 1 end]
[c14b554]1466          #set tolindex [concat [list $idx_con] $tolindex]
[6d7779d]1467        }
1468      } else {
1469        set idx [$ht_tree find -name $node_type]
1470        array set aryData [$ht_tree entry cget $idx -data]
[7a0e436f]1471        #puts "SelectObject: FileName=$aryData(FileName) info_node=$info_node"
[c14b554]1472        set tolset [list File $aryData(FileName)]
[6d7779d]1473        set tolindex [lrange $info_node 1 end]
[c14b554]1474        #set tolindex [lrange $info_node 2 end]
[6d7779d]1475      }
[7a0e436f]1476      #puts "SelectObject end: tolset=$tolset, tolindex=$tolindex"
[6d7779d]1477      SelectSet
1478    }
1479  }
1480  NotBusy
1481}
1482
1483#/////////////////////////////////////////////////////////////////////////////
1484proc ::TolInspector::SelectFileRoot { } {
1485#
1486# PURPOSE: Script called each time 'Included Files' node in ht_tree is
1487#          selected. Gets information about each node that must be in
1488#          included files, and inserts it in the right treeview.
1489#
1490#/////////////////////////////////////////////////////////////////////////////
1491  variable item_id 1
1492  variable w_tabset
[025a6ef]1493  variable knownReference ""
1494
[6d7779d]1495  ClearHiertables
1496  $w_tabset tab configure Variables -text [mc Files]
1497  #  $w_tabset tab configure Functions -state disabled
1498  $w_tabset select 0
1499  foreach f [lreverse [::tol::info included]] {
[025a6ef]1500    # this catch is needed because info include could return files not
1501    # realy included.
1502    if { [ catch { ::tol::info included $f } fi ] } continue
[6d7779d]1503    # tener en cuenta el subtype cuando lo retorne
[025a6ef]1504    set knownReference [ list "File" $f ]
[6d7779d]1505    InsertChild Set $f \
[025a6ef]1506        [lindex $fi 0] [lindex $fi 1] [list [lindex $fi 2]] $item_id 1 [lindex $fi 3] [lindex $fi 4]
[6d7779d]1507  }
1508}
1509
1510#/////////////////////////////////////////////////////////////////////////////
1511proc ::TolInspector::SelectConsoleRoot { } {
1512#
1513# PURPOSE: Script called each time 'Console Objects' node in ht_tree is
1514#          selected. Gets information about each node that must be in console,
1515#          and inserts it in the right treeview.
1516#
1517#/////////////////////////////////////////////////////////////////////////////
1518  variable w_tabset
1519  variable ht_vars
1520  variable ht_funcs
1521  variable item_id 1
[301385f]1522  variable iterSet "Console"
1523  variable knownReference ""
[6d7779d]1524
1525  ClearHiertables
[dd6e916]1526#(pgea) se quita la linea que oculta la columna del indice y que
[edd8cc0]1527#(pgea) el procedimimento anterior ClearHiertables muestra
1528#  $ht_vars column  configure Index -hide yes
[6d7779d]1529#  $w_tabset tab configure Functions -state disabled
1530 
1531  foreach co [::tol::console stack list] {
[c14b554]1532   #puts "SelectConsoleRoot: co = $co"
1533   set gra  [lindex $co 0]
[301385f]1534   set name [lindex $co 1]
1535   set cont [lindex $co 2]
1536   set path [lindex $co 3]
1537   set desc [lindex $co 4]
1538   set knownReference [ list Console $item_id ]
[6d7779d]1539    switch [lindex $co 0 ] {
1540      Code {
1541        InsertChild $gra $name $cont $path [list $desc] 0
1542      }
[c14b554]1543      NameBlock -
[6d7779d]1544      Set {
[c14b554]1545        #puts "switch: SelectConsoleRoot $gra"
[6d7779d]1546        InsertChild $gra $name $cont $path [list $desc] \
[c14b554]1547            $item_id [lindex $co 5] [lindex $co 6] [lindex $co 7] \
1548            [list Reference [list "Console" $item_id]]
[6d7779d]1549      }
1550      default {
[c14b554]1551        InsertChild $gra $name $cont $path [list $desc] \
1552            [list Reference [list "Console" $item_id]]
[6d7779d]1553      }
1554    }
1555  }
[301385f]1556  set knownReference ""
[6d7779d]1557}
1558
1559#/////////////////////////////////////////////////////////////////////////////
1560proc ::TolInspector::SelectPoolRoot { } {
1561#
1562# PURPOSE: Script called each time 'Spool Objects' node in ht_tree is
1563#          selected. Gets information about each node that must be in pool,
1564#          and inserts it in the right treeview.
1565#
1566#/////////////////////////////////////////////////////////////////////////////
1567  variable w_tabset
1568  variable ht_vars
1569  variable data
1570  variable item_id 1
[301385f]1571  variable knownReference ""
[6d7779d]1572
1573  ClearHiertables
1574  $ht_vars column  configure Index -hide yes
1575
1576  array unset data pool,variables,*
1577  # Para cada uno de los objetos que debe haber en el spool
[c14b554]1578  # busco la información del nodo y lo inserto en el treeview de la derecha
[6d7779d]1579  foreach _obj $data(pool,objects) {
1580    array set obj $_obj
1581    #Si la referencia del objeto tiene espacios en la ruta, el
[c14b554]1582    # llength me daría > 1, por eso añado la 2ª parte de la condicion
1583    #puts "SelectPoolRoot: obj(grammar)=$obj(grammar) obj(objName)=$obj(objName) obj(reference)=$obj(reference)"
[6d7779d]1584    if { ([llength $obj(reference)] > 1) && ![string equal $obj(reference) $obj(objName)]} {
1585      if {$obj(grammar) eq "Code"} {
1586        set infoObj [concat [list $obj(grammar) $obj(objName)] \
1587            [::tol::info function $obj(reference)]]
1588      } else  {
1589        set infoObj [::tol::info variable $obj(reference)]
1590      }
1591      #Tolcon_Trace "tol info (var|function) reference"
1592    } else {
1593      if {[catch { set infoObj [concat [list "Set" $obj(reference)] \
1594                          [::tol::info included $obj(reference)]] }]} {
1595        if {$obj(grammar) eq "Code"} {
1596          set infoObj [concat [list $obj(grammar) $obj(reference)] \
1597               [::tol::info function $obj(graApply) $obj(reference)]]
1598        } else  {
[c14b554]1599          #set infoObj [concat [list $obj(grammar) $obj(reference)] \
1600          #     [::tol::info variable $obj(grammar) $obj(reference)]]
1601          set infoObj [::tol::info variable [list $obj(grammar) $obj(reference)]]
[6d7779d]1602        }
1603        #Tolcon_Trace "tol info (var|function) Grammar nameGlobal"
1604      } else {
1605        # Insertamos el 1 de isFile
1606        set infoObj [linsert $infoObj 5 1]
1607        #Tolcon_Trace "tol info included"
1608      }
1609    }
1610    #Tolcon_Trace "INFOOBJ: $infoObj"
1611    set gra  [lindex $infoObj 0]
1612    set name [lindex $infoObj 1]
1613    set cont [lindex $infoObj 2]
1614    set path [lindex $infoObj 3]
1615    set desc [lindex $infoObj 4]
1616    set data(pool,variables,$item_id) $obj(reference)
1617
1618    switch $gra {
1619      Code {
1620        InsertChild $gra $name $cont $path [list $desc] 0 "Reference $obj(reference)"
1621      }
[c14b554]1622      Set -
1623      NameBlock {
[301385f]1624        set knownReference $obj(reference)
[6d7779d]1625        InsertChild $gra $name $cont $path [list $desc] \
1626            $item_id [lindex $infoObj 5] [lindex $infoObj 6] [lindex $infoObj 7] "Reference $obj(reference)"
[301385f]1627        set knownReference ""
[6d7779d]1628      }
1629      default {
1630        InsertChild $gra $name $cont $path [list $desc] "Reference $obj(reference)"
1631      }
1632    }
1633  } 
1634}
1635
1636#/////////////////////////////////////////////////////////////////////////////
1637proc ::TolInspector::SelectGrammar { } {
1638#
1639# PURPOSE: Script called each time a Grammar node in ht_tree is selected. Gets
1640#          information about each var and function of this grammar, and
1641#          inserts them in the right treeview.
1642#
1643#/////////////////////////////////////////////////////////////////////////////
1644  variable w_tabset
1645  variable ht_tree
1646  variable ht_vars
1647  variable ht_funcs
1648  variable item_id 1
1649  variable OnSelectItem
[a437416]1650  variable knownReference
[6d7779d]1651
[a437416]1652  set knownReference ""
[6d7779d]1653  ClearHiertables
1654  $ht_vars column  configure Index -hide yes
1655  $ht_funcs column configure Index -hide yes
1656  set grammar [$ht_tree entry cget anchor -label]
1657  if { [string compare $grammar "Anything"] } {
1658    if { [string length $OnSelectItem] } {
1659      $OnSelectItem [::tol::info grammars $grammar]
1660    }
1661    foreach var  [::tol::info variables $grammar] {
1662      if {[catch {
[c14b554]1663        set vinfo [::tol::info variables [list $grammar $var]]
[6d7779d]1664      } msg]} {
1665        Tol_HciWriter "<E>in ::TolInspector::SelectGrammar : $msg\n</E>"
1666        continue
1667      }
1668      if { [string equal $grammar "Code"] } {
1669        #Tolcon_Trace "Code : -- $vinfo --"
[c14b554]1670        InsertChild $grammar $var [lindex $vinfo 2] [lindex $vinfo 3] [list [lindex $vinfo 4]] 1 
[a437416]1671      } elseif { $grammar eq "Set" || $grammar eq "NameBlock" } {
[6d7779d]1672        #Tolcon_Trace "Set : -- $vinfo --"
[746525a]1673        set knownReference [ list $grammar $var ]
[c14b554]1674        InsertChild $grammar $var [lindex $vinfo 2] [lindex $vinfo 3] [list [lindex $vinfo 4]] \
1675          $item_id [lindex $vinfo 5] [lindex $vinfo 6] [lindex $vinfo 7]
[6d7779d]1676      } else {
[c14b554]1677        InsertChild $grammar $var [lindex $vinfo 2] [lindex $vinfo 3] [list [lindex $vinfo 4]] $item_id 0
[6d7779d]1678      } 
1679    }
1680  } else {
1681#    $w_tabset tab configure Variables -state disabled
1682#    $w_tabset select 1
1683  }
1684  foreach fun  [::tol::info functions $grammar] {
1685    set finfo [::tol::info functions $grammar $fun]
1686    InsertChild Code $fun [lindex $finfo 0] [lindex $finfo 1] [list [lindex $finfo 2]] 0   
1687  }
1688}
1689
1690#/////////////////////////////////////////////////////////////////////////////
1691proc ::TolInspector::SelectSet { } {
1692#
1693# PURPOSE: Script called each time a Set node in ht_tree is selected. Gets
1694#          information about each child of this set, and inserts it in the
1695#          right treeview.
1696#
1697#/////////////////////////////////////////////////////////////////////////////
1698  variable ht_tree
1699  variable ht_vars
1700  variable ht_funcs
1701 
1702  variable tolset
1703  variable tolindex
[301385f]1704  variable iterSet
[6d7779d]1705  variable var_id 1
1706  variable fun_id 1
1707  variable item_id
1708  #variable selecting_set
1709 
1710  #  if { $selecting_set } {
[c14b554]1711  #puts "eoooo ..."
[6d7779d]1712  #    return
1713  #  }
1714  ClearHiertables
1715  #  set selecting_set 1
1716  set item_id 1
[c14b554]1717 
1718  #puts "SelectSet: tolset=$tolset tolindex=$tolindex"
[301385f]1719  set iterSet [eval list $tolset $tolindex]
1720  variable gra_parent [ GetParentGrammar $iterSet ]
1721  ::tol::forallchild $iterSet ::TolInspector::_InsertChild
[6d7779d]1722  #  set selecting_set 0
1723}
1724
[a6e4c78]1725proc ::TolInspector::GetParentGrammar { set_ref } {
[16f893d]1726  set root [ lindex $set_ref 0 ]
1727  set L [ llength $set_ref ]
1728  if { ( $root eq "File" && $L <= 2 ) } {
1729    set root
[a6e4c78]1730  } else {
[16f893d]1731    lindex [ tol::info var $set_ref ] 0
[a6e4c78]1732  }
1733}
1734
[6d7779d]1735#/////////////////////////////////////////////////////////////////////////////
1736proc ::TolInspector::CloseObject { index } {
1737#
1738# PURPOSE: Script called each time a node in ht_tree (left treeview) is
1739#          closed.
1740#
1741# PARAMETERS:
1742#   index : The id of the node closed
1743#
1744#/////////////////////////////////////////////////////////////////////////////
1745  variable ht_tree
1746  #variable closing 1
1747  set path [$ht_tree get -full $index]
1748  if { $index } {
1749    set parent1 [lindex $path 1]
[33b09bc]1750    if { [string equal $parent1 "root-packages"] ||
1751         [string equal $parent1 "root-files"] ||
1752         [string equal $parent1 "root-console"] ||
1753         [string equal $parent1 "root-pool"] } {
[6d7779d]1754      $ht_tree entry delete $index 0 end
1755    }
1756  }
1757}
1758
1759#/////////////////////////////////////////////////////////////////////////////
1760proc ::TolInspector::HasSubset { args } {
1761#///////////////////////////////////////////////////////////////////////////// 
1762  if { [string equal [lindex $args 0] "Set"] } {
1763    variable has_button 1
1764    return 0
1765  }
1766  return 1
1767}
1768
1769#/////////////////////////////////////////////////////////////////////////////
1770proc ::TolInspector::OpenVariable { index } {
1771#
1772# PURPOSE: ????
1773#
1774# PARAMETERS:
1775#   index ->
1776#
1777#/////////////////////////////////////////////////////////////////////////////
1778  variable tolset     ;# Name of the current TOL set variable
1779  variable ht_vars    ;# ::blt::treeview of variables
1780  variable ht_tree    ;# ::blt::treeview left
1781  variable blt_tree   ;# ::blt::tree left
1782  variable item_data  ;# Array to hold the full content & description of items
1783 
1784  if { ![string length $index] } {
1785    return
1786  }
1787  set node_anchor [lindex [$ht_tree get -full anchor] end]
1788 
1789  set tree_index -1
[c14b554]1790  #puts "OpenVariable = $item_data([lindex [$ht_vars entry cget $index -data] end])"
1791  if { ![regexp -- "grammar-" $node_anchor] } {
1792    set grammar [lindex $item_data([lindex [$ht_vars entry cget $index -data] end]) 2]
1793    if {$grammar eq "Set" || $grammar eq "NameBlock"} {
1794      $ht_tree open anchor
1795      #puts "full = [$ht_vars get -full $index]"
1796      set local_name [lindex [$ht_vars get -full $index] end]
1797      set idx_anchor [$ht_tree index anchor]
1798      #puts "a buscar $local_name dentro de $idx_anchor"
1799      if {[set tree_index [$blt_tree findchild $idx_anchor $local_name]] == -1} {
1800        foreach idx [$ht_tree entry children anchor] {
1801          if { [string equal $local_name [lindex [$ht_tree get -full $idx] end]] } {
1802            set tree_index $idx
1803            break
1804          }
[6d7779d]1805        }
1806      }
1807    }
1808  }
1809  if { $tree_index != -1 } {
1810    update
1811    blt::tv::SetSelectionAnchor $ht_tree $tree_index
1812    set blt::tv::scroll 1
1813    #$ht_tree selection clearall
1814    #$ht_tree see $tree_index
1815    #$ht_tree focus $tree_index
1816    #$ht_tree selection set $tree_index
1817    #$ht_tree selection anchor $tree_index
1818    #set blt::Hiertable::scroll 1
1819  }
1820}
1821
1822#/////////////////////////////////////////////////////////////////////////////
1823proc ::TolInspector::SelectItem { ht } {
1824#
1825# PURPOSE: Procedure that is executed when the user selects an element of
1826#          the trees of variables orfunctions.
1827#          First it take all the arguments necessary of the node of tree to
1828#          execute the procedure stored in the variable OnSelectItem, and
1829#          later executes it passing those arguments.
1830#
1831# PARAMETERS: path of ht_* (::blt::treeview of variables or of functions)
1832#
1833#/////////////////////////////////////////////////////////////////////////////
1834 # variable w_text       ;# TODO: ????
1835  variable OnSelectItem ;#Command to invoke on SelectItem in ht_*
1836  variable item_data    ;# Array to hold the full content & description of items
1837 
1838  set entry [$ht index anchor] ;# id of entry selected 
1839  if { [string length $OnSelectItem] } {
1840    # there are associated command
1841    if { [string length $entry] } {
1842      # almost one entry of ht_* selected
1843      array set aryData [$ht entry cget $entry -data]
1844      set name [$ht entry cget $entry -label] ;# name of item
1845      set itemid $aryData(Index)              ;# id of item
1846      set path   $aryData(Path)               ;# path of file of item
[dd6e916]1847      #(pgea) se anyade la propiedad Reference
[6b3f93a]1848      set objRef $aryData(Reference)          ;# info of item
[6d7779d]1849      set full_data $item_data($itemid) ;# {value} {desc} {grammar}       
1850      set value [lindex $full_data 0]   ;# value of item PE:
1851                                         # Anything Field(Set s, Text nombre)
1852
1853      if { [string equal \"\n\" $value] } {
1854        # hasn't value       
1855        set value {"\n"}
1856      } else {
1857        set value [string trim $value]
1858      }
1859      set desc [string trim [lindex $full_data 1]]
1860      set grammar [lindex $full_data 2]
1861      set icon [lindex [$ht entry cget $entry -icons] 0]
[6b3f93a]1862      #(pgea) lista de argumentos que recibe ::TolConsole::OnInfo
1863      set args [list $icon $grammar $name $value $path $desc $objRef]
[6d7779d]1864    } else {
1865      set args ""
1866    }
1867    eval "$OnSelectItem $args"
1868  }
1869  return
1870#;# TODO: ????
1871#  if { [string length $entry] } {
1872#    FillText $ht $entry
1873#  } else {
1874#    $w_text delete 1.0 end
1875#  }
1876}
1877
1878#/////////////////////////////////////////////////////////////////////////////
[dd6e916]1879#(pgea) se usa?
[6d7779d]1880proc ::TolInspector::FillText { ht entry } {
1881#/////////////////////////////////////////////////////////////////////////////
1882  variable w_text
1883  variable item_data
1884  #upvar #0 ::TolTk::Images Images
1885
1886  $w_text delete 1.0 end
1887  array set aryData [$ht entry cget $entry -data]
1888  set name [$ht entry cget $entry -label]
1889  set itemid $aryData(Index)
1890  set full_data $item_data($itemid)
1891 
1892  set value [lindex $full_data 0]
1893  if { [string equal \"\n\" $value] } {
1894    set value {"\n"}
1895  }
1896  set desc [string trim [lindex $full_data 1]]
1897  set grammar [lindex $full_data 2]
1898  set icon [lindex [$ht entry cget $entry -icons] 0]
1899  foreach {prop val} [list "Grammar: " $grammar "Name: " $name "Value: " [string trim $value]] {
1900    set idx_start [$w_text index "end -1 chars"]
1901    $w_text insert end $prop
1902    set idx_end   [$w_text index "end -1 chars"]
1903    $w_text tag add tagLabel $idx_start $idx_end
1904    if {[string equal $prop "Grammar: "]} {
1905      $w_text image create end -image $icon
1906      $w_text insert end "  "
1907    }
1908    $w_text insert end "$val\n"
1909    $w_text tag add tagValue $idx_end [$w_text index "end -1 chars"]
1910  }
1911  $w_text tag configure tagLabel -font fnBold
1912  $w_text tag configure tagValue -wrap none
1913  if { [string length $desc] } {
1914    set idx_start [$w_text index "end -1 chars"]
1915    $w_text insert end "Description\n"
1916    set idx_end [$w_text index "end -1 chars"]
1917    $w_text tag add tagPropLabel $idx_start $idx_end
1918    $w_text insert end $desc
1919    $w_text tag add tagPropValue $idx_end [$w_text index "end -1 chars"]
1920    $w_text tag configure tagPropLabel -font fnBold -underline 1
1921    $w_text tag configure tagPropValue -wrap word
1922  }
1923}
1924
1925#proc ::TolInspector::GetIndexes { nodeid } {
1926#  variable ht_tree
1927#  # No se utiliza
1928#  # name is prefix-i1-i2-i3-...-in
1929#
1930#  if { $nodeid } {
1931#    lrange [split [$ht_tree get $nodeid] "-"] 1 end
1932#  } else list
1933#}
1934
1935#/////////////////////////////////////////////////////////////////////////////
1936proc ::TolInspector::GetItemName { prefix idx_list } {
1937#///////////////////////////////////////////////////////////////////////////// 
1938  set node_id $prefix
1939  foreach id $idx_list {
1940    append node_id "-$id"
1941  }
1942  set node_id
1943}
1944
1945#/////////////////////////////////////////////////////////////////////////////
1946proc ::TolInspector::OnBusy { cmd } {
1947#///////////////////////////////////////////////////////////////////////////// 
1948  variable OnBusyCmd $cmd
1949}
1950
1951#/////////////////////////////////////////////////////////////////////////////
1952proc ::TolInspector::Busy { } {
1953#///////////////////////////////////////////////////////////////////////////// 
1954  variable OnBusyCmd
1955  variable ht_tree
1956  variable ht_vars
1957
1958  $ht_tree configure -cursor watch
1959  $ht_vars configure -cursor watch
1960  if { [string length $OnBusyCmd] } {
1961    eval $OnBusyCmd 1
1962  }
1963}
1964
1965#/////////////////////////////////////////////////////////////////////////////
1966proc ::TolInspector::NotBusy { } {
1967#///////////////////////////////////////////////////////////////////////////// 
1968  variable OnBusyCmd
1969  variable ht_tree
1970  variable ht_vars
1971
1972  $ht_tree configure -cursor ""
1973  $ht_vars configure -cursor ""
1974
1975  if { [string length $OnBusyCmd] } {
1976    eval $OnBusyCmd 0
1977  }
1978}
1979
[67102d7]1980proc Tol_GetViewPrivateMembers { } {
1981  set viewOpt 0
1982  catch {
1983    # no funciona
1984    tol::console eval {
1985      Real __getViewPrivateMembers_tmp__ =
1986      TolConfigManager::Config::Various::View::PrivateMembers;
1987    }
1988    set x [ lindex [ tol::info variable { Real __getViewPrivateMembers_tmp__ } ] 2 ]
1989    tol::console stack release __getViewPrivateMembers_tmp__
1990    set viewOpt [ expr { int( $x ) } ]
1991   
1992  } msg
1993  #puts "Tol_GetViewPrivateMembers: $msg"
1994  return $viewOpt
1995}
1996
[ca01e16]1997proc Tol_ObjIsClassOf { obj_addr cls_name } {
1998  tol::console eval [ string map [ list %A $obj_addr %C $cls_name ] {
[57e34db]1999    Real __gui_check__ = IsInstanceOf( GetObjectFromAddress( "%A" ),"%C" )
[ca01e16]2000  } ]
2001  set info [ tol::info variable {Real __gui_check__} ]
2002  set x [ lindex $info 2 ]
2003  tol::console stack release __gui_check__
2004  expr { round($x) }
2005}
2006
[57e34db]2007proc Tol_ClassOf { obj_addr } {
2008  tol::console eval [ string map [ list %A $obj_addr ] {
2009    Text __gui_classof__ = {
2010      Anything obj = GetObjectFromAddress( "%A" );
2011      // WriteLn( "Tol_ClassOf " << Grammar( obj ) );
2012      Text If( Grammar( obj ) == "NameBlock", ClassOf( obj ), "" )
2013    }
2014  } ]
2015  set info [ tol::info variable {Text __gui_classof__} ]
2016  set x [ string trim [ lindex $info 2 ]  \" ]
2017  tol::console stack release __gui_classof__
2018  set x
2019}
2020
[301385f]2021proc Tol_ClassOfFromReference { objReference } {
2022  set addr [ ::tol::info address $objReference ]
2023  return [ Tol_ClassOf $addr ]
2024}
2025
[a566515]2026proc Tol_StructOf { obj_addr } {
2027  set tolcode [ string map [ list %A $obj_addr ]  {
2028    Text {
2029      Anything obj = GetObjectFromAddress( "%A" );
2030      // WriteLn( "Tol_StructOf " << Grammar( obj ) );
2031      Text If( Grammar( obj ) == "Set", StructName( obj ), "" )
2032    }
2033  } ]
2034  return [ lindex [ toltcl::eval $tolcode ] 0 ]
2035}
2036
2037proc Tol_StructOfFromReference { objReference } {
[025a6ef]2038  if { [ llength $objReference ] == 2 &&
2039       [ lindex $objReference 0 ] eq "File" } {
2040    return ""
2041  }
[a566515]2042  set addr [ ::tol::info address $objReference ]
2043  return [ Tol_StructOf $addr ]
2044}
2045
[dd6e916]2046#(pgea) nueva funcion para obtener la informacion de instancia
[6b3f93a]2047proc Tol_InstanceInfo { obj_addr } {
2048  tol::console eval [ string map [ list %A $obj_addr ] {
2049    Text __gui_instanceinfo__ = {
2050      Anything __intance__ = GetObjectFromAddress("%A");
2051      Text If(ObjectExist("Code", "__intance__::_.get.autodoc.info"),
2052        __intance__::_.get.autodoc.info(?), "")
2053    }
2054  } ]
2055  set info [ tol::info variable {Text __gui_instanceinfo__} ]
2056  set x [ string trim [ lindex $info 2 ]  \" ]
2057  tol::console stack release __gui_instanceinfo__
2058  set x
2059}
2060
[dd6e916]2061#(pgea) nueva funcion para obtener la informacion de instancia
[6b3f93a]2062proc Tol_InstanceInfoFromReference { objReference } {
2063  set addr [ ::tol::info address $objReference ]
2064  return [ Tol_InstanceInfo $addr ]
2065}
2066
[dd6e916]2067#(pgea) nueva funcion para obtener el contenido de la instancia
[6b3f93a]2068proc Tol_InstanceContent { obj_addr } {
2069  tol::console eval [ string map [ list %A $obj_addr ] {
2070    Text __gui_instancecontent__ = {
2071      Anything __intance__ = GetObjectFromAddress("%A");
2072      Text If(ObjectExist("Code", "__intance__::_.get.autodoc.content"),
2073        __intance__::_.get.autodoc.content(?), "")
2074    }
2075  } ]
2076  set info [ tol::info variable {Text __gui_instancecontent__} ]
2077  set x [ string trim [ lindex $info 2 ]  \" ]
2078  tol::console stack release __gui_instancecontent__
2079  set x
2080}
2081
[dd6e916]2082#(pgea) nueva funcion para obtener el contenido de la instancia
[6b3f93a]2083proc Tol_InstanceContentFromReference { objReference } {
2084  set addr [ ::tol::info address $objReference ]
2085  return [ Tol_InstanceContent $addr ]
2086}
2087
[57e34db]2088proc TolGui_GetMenuEntries { selection idx } {
[3a5bf7b]2089  #puts "TolGui_GetMenuEntries $selection $idx"
[57e34db]2090  array set instances {}
2091  array set menu_class {}
2092  set i 0
2093  foreach obj_info $selection {
2094    set tcl_ref [ lindex $obj_info 0 ]
2095    set obj_addr [ ::tol::info address $tcl_ref ]
[e206a36]2096    if { [ Tol_ObjIsClassOf $obj_addr "GuiTools::@MenuDesc" ] } {
[3f0542d]2097      set class [ Tol_ClassOf $obj_addr ]
[57e34db]2098      lappend instances($class) $obj_addr
2099      set name_inst [ lindex $obj_info 1 ]
2100      set menu_items [ TolGui_GetObjMenu $obj_addr ]
2101      # esto hace que estemos guardando la ultima instancia, asumimos
2102      # tambien que todas las instancia tienen la misma espcificacion
2103      # de menu
2104      if { ![ llength [ array names menu_class $class ] ] || $i == $idx } {
2105        set menu_class($class) \
2106            [ list $name_inst $obj_addr $menu_items ]
2107      }
2108    }
2109    incr i
2110  }
2111  set menu_info [ list ]
2112  foreach c [ array names instances ] {
[3f0542d]2113    lappend menu_info [ list $c $menu_class($c) $instances($c) ]
[57e34db]2114  }
[3a5bf7b]2115  #puts "$menu_info"
[57e34db]2116  set menu_info
2117}
2118
[3a5bf7b]2119proc TolGui_InsertEntriesFromMenuManager { targetMenu selection } {
2120  set addrList [ list ]
2121  foreach obj_info $selection {
2122    set tcl_ref [ lindex $obj_info 0 ]
2123    lappend addrList [ ::tol::info address $tcl_ref ]
2124  }
[e462ba2]2125  ::MenuManager::insertEntriesForSelection $targetMenu $addrList
[3a5bf7b]2126}
2127
[57e34db]2128proc TolGui_GetObjMenu { obj_addr } {
[ca01e16]2129  set try [ catch {
2130    tol::console eval [ string map [ list %A $obj_addr ] {
[e206a36]2131      GuiTools::@MenuDesc __aux_menu__ = GetObjectFromAddress("%A");
[ca01e16]2132      Set __gui_menu_entries__ = __aux_menu__::getMenuEntries(?)
2133    } ] } msg ]
2134  if { $try } {
[3f0542d]2135    puts "ERROR TolGui_GetObjMenu : $msg"
[ca01e16]2136    set result ""
2137  } else {
2138    set result [ TolObj2TclObj {Set __gui_menu_entries__} ]
2139  }
2140  tol::console stack release __aux_menu__
2141  tol::console stack release __gui_menu_entries__
2142  set result
2143}
2144
[57e34db]2145proc TolGui_InvokeMethod { method obj_addr } {
[3a5bf7b]2146  #puts "TolGui_InvokeMethod $method $obj_addr"
[ca01e16]2147  set try [ catch {
2148    tol::console eval [ string map [ list %A $obj_addr %M $method ] {
2149      NameBlock __aux_instance__ = GetObjectFromAddress("%A");
2150      Real __aux_result__ = __aux_instance__::%M(?)
2151    } ] } msg ]
2152  if { $try } {
2153    puts "ERROR TolGui_InvokeMethod : $msg"
2154  }
2155  tol::console stack release __aux_instance__
2156  tol::console stack release __aux_result__
2157}
[6d7779d]2158
[57e34db]2159proc TclList2SetOfText { lst } {
2160  set result [ list ]
2161  foreach i $lst {
[0318d73]2162    lappend result \"[string map {\" \\\"} $i]\"
[57e34db]2163  }
2164  return "SetOfText([join $result ,])"
2165}
2166
2167proc TolGui_InvokeGroup { cname function group } {
2168  set SOA [ TclList2SetOfText $group ]
2169  set try [ catch {
2170    tol::console eval \
2171        [ string map [ list %C $cname %F $function %S $SOA ] {
[75e0fdd]2172          Real __aux_result__ = {
2173            Set aux = EvalSet( %S, NameBlock( Text addr ) {
2174              NameBlock GetObjectFromAddress( addr )
2175            } );
2176            Real %C::%F( aux )
2177          }
[57e34db]2178        } ] } msg ]
2179  if { $try } {
2180    puts "ERROR TolGui_InvokeGroup : $msg"
2181  }
2182  tol::console stack release __aux_result__
2183}
2184
[6d7779d]2185#/////////////////////////////////////////////////////////////////////////////
2186proc ::TolInspector::PostVariable { x y } {
2187#
2188# PURPOSE: Composes a popup menu for variables and displays it. Its composed
2189#          depending on the node/s clicked by user.
2190#
2191# PARAMETERS:
2192#   x -> x-coordinate where popup menu is drawn
2193#   y -> y-coordinate where popup menu is drawn
2194#
2195#/////////////////////////////////////////////////////////////////////////////
2196  variable data_menu
2197  variable vars_selected
2198  variable options_selected
2199  variable ht_vars
2200  variable ht_tree
2201  variable item_data
2202  variable data
2203
2204  variable tolset
2205  variable tolindex
2206
2207  #User functions to contextual menu
2208  ::TolInspector::ReadUserFunctions
2209
2210  array unset options_selected
2211
2212  foreach it [array names data_menu] {
2213    $data_menu($it) delete 0 end
2214  }
2215  set InRootConsole [string equal [lindex [$ht_tree get -full anchor] end] "root-console"]
2216  set InRootPool  [string equal [lindex [$ht_tree get -full anchor] end] "root-pool"]
2217  set InRootFiles [string equal [lindex [$ht_tree get -full anchor] end] "root-files"]
[c14b554]2218  #puts "PostVariable: InRootConsole,InRootPool,InRootFiles = $InRootConsole,$InRootPool,$InRootFiles"
[6d7779d]2219  set node_act [$ht_vars index current]
[57e34db]2220  if { [string length $node_act] } {
[6d7779d]2221    set vars_selected [$ht_vars curselection]
2222    if { [lsearch $vars_selected $node_act] >= 0 } {
2223      foreach var $vars_selected {
2224        array set aryData [$ht_vars entry cget $var -data]
[7a0e436f]2225        #puts "PostVariable: aryData = [array get aryData]"
[6d7779d]2226        set itemid $aryData(Index)
2227        set path   $aryData(Path)
2228        set grammar [lindex $item_data($itemid) 2]
2229        set objName [$ht_vars entry cget $var -label]
[c14b554]2230        #puts "OBJECT=$objName, PATH=$path"
2231        if { $InRootPool } {
2232          set object $data(pool,variables,$itemid)
2233                } else {
2234          if {[llength $aryData(Reference)]} {
2235            #set object [lindex $aryData(Reference) 0]
[57e34db]2236            set object [lrange $aryData(Reference) 0 end]
[6d7779d]2237          } else {
2238            if { [string length $tolset] } {
[c14b554]2239              #set object [concat [list File $tolset] $tolindex $itemid]
2240              set object [concat $tolset $tolindex $itemid]
[7a0e436f]2241              #puts "tolset = $tolset"
[6d7779d]2242            } else {
2243              if [llength $objName] {
[c14b554]2244                set object [list $grammar $objName]
[6d7779d]2245              } else {
[7a0e436f]2246                set object $objName
[c14b554]2247              }
[6d7779d]2248            }
2249          }
2250        }
[c14b554]2251        #puts "PostVariable: OBJECT=$object OBJNAME=$objName TOLSET=$tolset PATH=$path GRAMMAR=$grammar"
[6d7779d]2252        switch -- $grammar {
2253          Code    -
2254          Complex -
2255          Date    -
2256          Matrix  -
[c14b554]2257          VMatrix -
[6d7779d]2258          Polyn   -
2259          Ratio   -
2260          Real    -
2261          Serie   -
[c14b554]2262          Anything -
[6d7779d]2263          Text    -
[ca01e16]2264          NameBlock -
[6d7779d]2265          TimeSet {
2266            lappend options_selected($grammar) [list $object $objName $path]
2267          }
2268          Set {
2269            # Si el objeto se da como referencia
2270            if { [llength $object] > 1 }  {
[7a0e436f]2271              #puts "PostVariable: Set: object = $object"
[c14b554]2272              if {$InRootFiles} {
2273                set isFile 1
2274              } else {
2275                set info [::tol::info var $object]
2276                set isFile [expr [lindex $info 7] == 4]
2277              }
[6d7779d]2278              #set desc [lindex $info 4]
2279            } else {
2280              if {[catch "::tol::info included $object" info]} {
[c14b554]2281                set info [::tol::info var [list Set $objName]]
2282                #set isFile [expr [lindex $info 5] == 4]
2283                set isFile [expr [lindex $info 7] == 4]
2284                #set desc [lindex $info 4]
[6d7779d]2285              } else {
2286                #set info [::tol::info included $objName]
2287                #set isFile [expr [lindex $info 4] == 4]
2288                set isFile 1
2289                #set desc ""
2290              }
2291            }
2292            if $isFile {
2293              lappend options_selected(File) [list $object $objName $path]
2294            } else {
2295              lappend options_selected($grammar) [list $object $objName $path]
2296            }
2297          }
2298        }
2299      }
2300      set grammar_selected [array names options_selected]
2301      if { [llength $grammar_selected] } {
2302        foreach grammar $grammar_selected {
2303          switch -- $grammar {
[c14b554]2304            VMatrix -
2305            Matrix  {
[6d7779d]2306              $data_menu(main) add cascade -label [mc "Export matrix"]\
2307              -menu $data_menu(Matrix,Export)
[c14b554]2308              if {[llength $options_selected($grammar)] == 1} {
2309                set object [lindex [lindex $options_selected($grammar) 0] 0]
[6d7779d]2310                $data_menu(main) add command -label [mc "Table matrix"] \
2311                  -command [list ::TolInspector::TableMatrix $object]
2312                $data_menu(Matrix,Export) add command -label "BDT" \
2313                  -command [list ::TolInspector::ExportBDTMatrix $object]
2314                $data_menu(main) add command -label [mc "Draw matrix"] \
2315                  -command [list ::TolInspector::DrawMatrix $object]
2316              } else {
2317                $data_menu(main) add cascade -label [mc "Table matrix"] \
2318                  -menu $data_menu(Matrix,Table)
2319                $data_menu(Matrix,Export) add cascade -label "BDT" \
2320                  -menu $data_menu(Matrix,Export,BDT)
2321                $data_menu(main) add cascade -label [mc "Draw matrix"] \
2322                  -menu $data_menu(Matrix,Draw)
2323                foreach objInfo $options_selected(Matrix) {
2324                  $data_menu(Matrix,Table) add command -label [lindex $objInfo 1]\
2325                    -command [list ::TolInspector::TableMatrix [lindex $objInfo 0]]
2326                  $data_menu(Matrix,Export,BDT) add command -label [lindex $objInfo 1]\
2327                    -command [list ::TolInspector::ExportBDTMatrix [lindex $objInfo 0]]
2328                  $data_menu(Matrix,Draw) add command -label [lindex $objInfo 1] \
2329                    -command [list ::TolInspector::DrawMatrix [lindex $objInfo 0]]
2330                }
2331              }
2332            }
2333            Serie   {
2334              if {[llength $options_selected(Serie)] == 1} {
2335                set lblSerie "serie"
2336              } else  {
2337                set lblSerie "series"
2338              }
2339              $data_menu(main) add command -label [mc "Draw $lblSerie"]\
2340              -command ::TolInspector::DrawSerie
2341              $data_menu(main) add command -label [mc "Table $lblSerie"]\
2342              -command ::TolInspector::TableSerie             
2343              if {[llength $options_selected(Serie)] == 1} {
2344                set object [lindex [lindex $options_selected(Serie) 0] 0]
2345                $data_menu(main) add command -label [mc "Draw autocorrelation"] \
2346                  -command [list ::TolInspector::DrawAutocorSerie $object]
2347                $data_menu(main) add command -label [mc "Table autocorrelation"] \
2348                  -command [list ::TolInspector::TableAutocorSerie $object]
2349              } else {
2350                $data_menu(main) add cascade -label [mc "Draw autocorrelation"] \
2351                  -menu $data_menu(Serie,DrawAutocor)
2352                $data_menu(main) add cascade -label [mc "Table autocorrelation"] \
2353                  -menu $data_menu(Serie,TableAutocor)
2354                foreach objInfo $options_selected(Serie) {
2355                  $data_menu(Serie,DrawAutocor) add command -label [lindex $objInfo 1]\
2356                    -command [list ::TolInspector::DrawAutocorSerie [lindex $objInfo 0]]
2357                  $data_menu(Serie,TableAutocor) add command -label [lindex $objInfo 1]\
2358                    -command [list ::TolInspector::TableAutocorSerie [lindex $objInfo 0]]
2359                }
2360              }
2361              $data_menu(main) add command -label [mc "Table statistics"]\
2362                  -command ::TolInspector::TableStatisticsSerie
2363            }
2364            TimeSet {
2365              if {[llength $options_selected(TimeSet)] == 1} {
2366                set object [lindex [lindex $options_selected(TimeSet) 0] 0]
2367                $data_menu(main) add command -label [mc "View timeset"] \
2368                  -command [list ::TolInspector::ViewTimeSet $object]
2369              } else {
2370                $data_menu(main) add cascade -label [mc "View timeset"] \
2371                  -menu $data_menu(TimeSet,View)
2372                foreach objInfo $options_selected(TimeSet) {
2373                  $data_menu(TimeSet,View) add command -label [lindex $objInfo 1] \
2374                    -command [list ::TolInspector::ViewTimeSet [lindex $objInfo 0]]
2375                }
2376              }
2377            }
[ca01e16]2378            NameBlock {
[3a5bf7b]2379              # entradas desde MenuManager
[0ea4b4d]2380              if 0 {
[3a5bf7b]2381              TolGui_InsertEntriesFromMenuManager \
2382                  $data_menu(main) \
2383                  $options_selected(NameBlock)
[0ea4b4d]2384              }
[3a5bf7b]2385              # entradas desde @MenuDesc
[0ea4b4d]2386              # @MenuDesc sera reemplazado, ver https://www.tol-project.org/ticket/1372
[0ce076c]2387              set sel_length [ llength $options_selected(NameBlock) ]
2388              if { $sel_length } {
[57e34db]2389                set idx_current [ lsearch $vars_selected $node_act ]
[0ce076c]2390                set all_nb_options \
2391                    [ TolGui_GetMenuEntries \
2392                          $options_selected(NameBlock) $idx_current ]
2393                set num_options [ llength $all_nb_options ]
[3a5bf7b]2394                #puts "num_options = $num_options"
[0ce076c]2395                foreach mi $all_nb_options {
[57e34db]2396                  set _cname [ lindex $mi 0 ]
2397                  set cname [ string map [ list @ "" . _ ] $_cname ]
[3a5bf7b]2398                  #puts "cname = $cname"
[57e34db]2399                  foreach { ninst obj_addr entries } [ lindex $mi 1 ] break
2400                  set instances [ lindex $mi 2 ]
[0ce076c]2401                  if { $num_options > 1 } {
[3a5bf7b]2402                  # creo el menu de la clase si no existe
2403                    set mclass $data_menu(main).cls$cname
2404                    if { ![ winfo exists $mclass ] } {
2405                      menu $mclass -tearoff 0
2406                    } else {
2407                      $mclass delete 0 end
2408                    }
[0ce076c]2409                    $data_menu(main) add cascade -label $cname -menu $mclass
2410                    set target_menu $mclass
2411                  } else {
2412                    set target_menu $data_menu(main)
2413                  }
[57e34db]2414                  foreach inst_entry $entries {
2415                    foreach { label single group } $inst_entry break
[0ce076c]2416                    set opt_label \
2417                        "$label [ expr { $sel_length>1 ? $ninst : {} } ]"
2418                    $target_menu add command -label $opt_label \
[ca01e16]2419                        -command [ list TolGui_InvokeMethod \
[57e34db]2420                                       $single $obj_addr ]
2421                    if { $group ne "" && [ llength $instances ] > 1 } {
2422                      # hay una funcion que se aplica a toda la seleccion
[0ce076c]2423                      $target_menu add command -label "$label All" \
[57e34db]2424                          -command [ list TolGui_InvokeGroup \
2425                                         $_cname $group $instances ]
2426                    }
[ca01e16]2427                  }
2428                }
2429              }
2430            }
[6d7779d]2431            Set {
2432              if {[llength $options_selected(Set)] == 1} {
2433                set object  [lindex [lindex $options_selected(Set) 0] 0]
2434                $data_menu(main) add command -label [mc "Table set"] \
2435                  -command [list ::TolInspector::TableSet $object]
2436                $data_menu(main) add command -label [mc "Draw set"] \
2437                  -command [list ::TolInspector::DrawSet $object]
2438                # menu special
2439                $data_menu(main) add cascade -label [mc "Draw set special"] \
2440                  -menu $data_menu(Set,Draw,Special)
2441                $data_menu(Set,Draw,Special) add command \
2442                   -label [mc SetGraphAllFirst] \
2443                  -command [list ::TolInspector::DrawSet $object 1]
2444                $data_menu(Set,Draw,Special) add command \
2445                  -label [mc SetGraphAllGeneric] \
2446                  -command [list ::TolInspector::DrawSet $object 2]
2447                $data_menu(Set,Draw,Special) add command \
2448                  -label [mc SetGraphEvenUneven] \
2449                  -command [list ::TolInspector::DrawSet $object 3]               
2450              } else {
2451                $data_menu(main) add cascade -label [mc "Table set"] \
2452                  -menu $data_menu(Set,Table)
2453                $data_menu(main) add cascade -label [mc "Draw set"] \
2454                  -menu $data_menu(Set,Draw)
2455                foreach objInfo $options_selected(Set) {
2456                  $data_menu(Set,Table) add command -label [lindex $objInfo 1] \
2457                    -command [list ::TolInspector::TableSet [lindex $objInfo 0]]
2458                  $data_menu(Set,Draw) add command -label [lindex $objInfo 1] \
2459                    -command [list ::TolInspector::DrawSet [lindex $objInfo 0]]
2460                }
2461                # menu special
2462                set i 0
2463                $data_menu(main) add cascade -label [mc "Draw set special"] \
2464                  -menu $data_menu(Set,Draw,Special,M)                 
2465                foreach objInfo $options_selected(Set) {
2466                  # exists menu previus ?
2467                  if {[winfo exists $data_menu(Set,Draw,Special,M).setdrawspecialm$i]} {
2468                    destroy $data_menu(Set,Draw,Special,M).setdrawspecialm$i
2469                  }
2470                  set mn \
2471                    [menu $data_menu(Set,Draw,Special,M).setdrawspecialm$i \
2472                      -tearoff 0]
2473                  $data_menu(Set,Draw,Special,M) add cascade \
2474                    -label [lindex $objInfo 1] -menu $mn
2475                  $mn add command -label [mc SetGraphAllFirst] \
2476                    -command [list ::TolInspector::DrawSet [lindex $objInfo 0] 1]
2477                  $mn add command -label [mc SetGraphAllGeneric] \
2478                    -command [list ::TolInspector::DrawSet [lindex $objInfo 0] 2]
2479                  $mn add command -label [mc SetGraphEvenUneven] \
2480                    -command [list ::TolInspector::DrawSet [lindex $objInfo 0] 3]                                 
2481                  incr i
2482                }               
2483              }
2484            }
2485            File {
2486              if {[llength $options_selected(File)] == 1} {
2487                set objName [lindex [lindex $options_selected(File) 0] 1]
2488                $data_menu(main) add command -label [mc "View file"] \
2489                  -command [list ::TolInspector::ViewFile $objName]
2490                if $InRootFiles {
2491                   $data_menu(main) add command -label [mc "Decompile file"] \
2492                     -command [list ::TolInspector::DecompileFile $objName]
2493                }
2494              } else {
2495                $data_menu(main) add cascade -label [mc "View file"] \
2496                  -menu $data_menu(File,View)
2497                foreach objInfo $options_selected(File) {
2498                  $data_menu(File,View) add command -label [lindex $objInfo 1] \
2499                    -command [list ::TolInspector::ViewFile [lindex $objInfo 1]]
2500                }
2501                if $InRootFiles {
2502                  $data_menu(main) add cascade -label [mc "Decompile file"] \
2503                    -menu $data_menu(File,Decompile)
2504                  foreach objInfo $options_selected(File) {
2505                    $data_menu(File,Decompile) add command -label [lindex $objInfo 1] \
2506                      -command [list ::TolInspector::DecompileFile [lindex $objInfo 1]]
2507                  }
2508                }
2509              }           
2510            }
2511          } ;# end del switch
[0ea4b4d]2512          # inserto las opciones definidas en MenuManager
2513          if { $grammar ne "Anything" } {
2514            TolGui_InsertEntriesFromMenuManager \
2515                $data_menu(main) \
2516                $options_selected($grammar)
2517          }
2518
[6d7779d]2519          $data_menu(main) add separator
2520          $data_menu(main) add cascade -label [mc "Functions"] \
2521             -menu $data_menu($grammar,Functions)
2522          ShowMenuUserFunc $grammar
2523          if {[llength $options_selected($grammar)] == 1} {
2524            set objName [lindex [lindex $options_selected($grammar) 0] 1]
2525            set path    [lindex [lindex $options_selected($grammar) 0] 2]
2526            $data_menu(main) add command -label [mc "View %1\$s's definition" $grammar] \
2527               -command [list ::TolInspector::ViewDefinition $objName $path $grammar]
2528          } else {
2529            $data_menu(main) add cascade -label [mc "View %1\$s's definition" $grammar] \
2530               -menu $data_menu($grammar,File)
2531            foreach objInfo $options_selected($grammar) {
2532              $data_menu($grammar,File) add command -label [lindex $objInfo 1]\
2533              -command [list ::TolInspector::ViewDefinition\
2534                              [lindex $objInfo 1] [lindex $objInfo 2] $grammar]
2535            }
2536          }
2537          $data_menu(main) add separator
2538        } ;#end del foreach
2539        if { $InRootPool } {
2540          $data_menu(main) add command -label [mc "Remove from spool"] \
2541            -command [list ::TolInspector::RemoveFromSpool $ht_vars]
2542        } else  {
2543          $data_menu(main) add command -label [mc "Add to spool"] \
2544            -command [list ::TolInspector::AddToSpool $ht_vars [lindex [$ht_tree get -full anchor] 1]]
2545        }
2546        $data_menu(main) add command -label [mc "To Eval window"] \
2547                -command [list ::TolInspector::AddToEvalWindow $ht_vars]
2548        $data_menu(main) add separator
[c14b554]2549        if { $InRootConsole} {
2550          $data_menu(main) add command -label [mc "Decompile"] \
2551            -command [list ::TolInspector::ClearConsoleObjSel $ht_vars]
2552          $data_menu(main) add separator
2553        }
[6d7779d]2554        $data_menu(main) add command -label [mc "Select all"] \
2555                -command [list ::TolInspector::SelectAll $ht_vars]
2556        $data_menu(main) add command -label [mc "Toggle selection"] \
2557                -command [list ::TolInspector::ToggleSelection $ht_vars]
2558        tk_popup $data_menu(main) $x $y
2559      } ;#end del if
2560    }
2561  }
2562}
2563
2564#/////////////////////////////////////////////////////////////////////////////
2565proc ::TolInspector::PostFunction { x y } {
2566#
2567# PURPOSE: Composes a popup menu for functions and displays it. Its composed
2568#          depending on the node/s clicked by user.
2569#
2570# PARAMETERS:
2571#   x -> x-coordinate where popup menu is drawn
2572#   y -> y-coordinate where popup menu is drawn
2573#
2574#/////////////////////////////////////////////////////////////////////////////
2575  variable data_menu
2576  variable vars_selected
2577  variable ht_funcs
2578  variable ht_tree
2579  variable item_data
2580  variable data
2581 
2582  variable tolset
2583  variable tolindex
2584 
2585  array unset options_selected
2586  foreach it [array names data_menu] {
2587    $data_menu($it) delete 0 end
2588  }
2589 
2590  set InRootPool  [string equal [lindex [$ht_tree get -full anchor] end] "root-pool"]
2591  set node_act [$ht_funcs index current]
2592  if { [string length $node_act] } {
2593    set vars_selected [$ht_funcs curselection]
2594    if { [lsearch $vars_selected $node_act] >= 0 } {
2595      foreach var $vars_selected {
2596        array set aryData [$ht_funcs entry cget $var -data]
2597        set itemid $aryData(Index)
2598        set path   $aryData(Path)
2599        set grammar [lindex $item_data($itemid) 2]
2600        set objName [$ht_funcs entry cget $var -label]
2601       
2602        if { $InRootPool } {
2603          set object $data(pool,variables,$itemid)
2604        } else {
2605          if { [string length $tolset] } {
2606            set object [concat [list $tolset] $tolindex $itemid]
2607          } else {
2608            set object $objName
2609          }
2610        }
[c14b554]2611        # La única gramática seleccionable en ht_funcs es Code
[6d7779d]2612        lappend code_selected [list $object $objName $path]
2613      }
2614   
2615      if {[llength $code_selected] == 1} {
2616        set objName [lindex [lindex $code_selected 0] 1]
2617        set path    [lindex [lindex $code_selected 0] 2]
2618        $data_menu(main) add command -label [mc "View %1\$s's definition" $grammar] \
2619                -command [list ::TolInspector::ViewDefinition $objName $path $grammar]
2620      } else {
2621        $data_menu(main) add cascade -label [mc "View %1\$s's definition" $grammar] \
2622                -menu $data_menu($grammar,File)
2623        foreach objInfo $code_selected {
2624          $data_menu($grammar,File) add command -label [lindex $objInfo 1]\
2625                -command [list ::TolInspector::ViewDefinition\
2626                [lindex $objInfo 1] [lindex $objInfo 2] $grammar]
2627        }
2628      }
2629 
2630      if { $InRootPool } {
2631         $data_menu(main) add command -label [mc "Remove from spool"] \
2632                  -command [list ::TolInspector::RemoveFromSpool $ht_funcs]
2633      } else  {
2634         $data_menu(main) add command -label [mc "Add to spool"] \
2635                  -command [list ::TolInspector::AddToSpool $ht_funcs [lindex [$ht_tree get -full anchor] 1]]
2636      }
2637      $data_menu(main) add command -label [mc "To Eval window"] \
2638                -command [list ::TolInspector::AddToEvalWindow $ht_funcs]
2639      $data_menu(main) add separator
2640      $data_menu(main) add command -label [mc "Select all"] \
2641              -command [list ::TolInspector::SelectAll $ht_funcs]
2642      $data_menu(main) add command -label [mc "Toggle selection"] \
2643              -command [list ::TolInspector::ToggleSelection $ht_funcs]
2644      tk_popup $data_menu(main) $x $y
2645    }
2646  }
2647}
2648
2649#/////////////////////////////////////////////////////////////////////////////
2650proc ::TolInspector::PostTree { x y } {
2651#
2652# PURPOSE: Composes a popup menu for left treeview and displays it. Its
2653#          composed depending on the node clicked by user.
2654#
2655# PARAMETERS:
2656#   x -> x-coordinate where popup menu is drawn
2657#   y -> y-coordinate where popup menu is drawn
2658#
2659#/////////////////////////////////////////////////////////////////////////////
2660  variable data_menu
2661  variable vars_selected
2662  variable ht_tree
2663  variable item_data
2664  variable data
2665  variable tolset
2666  variable tolindex
2667  variable item_id
[c14b554]2668  #puts "ht_tree: $ht_tree"
2669  #No terminado todavía
[6d7779d]2670  #return
2671  array unset options_selected
2672 
[bc68cb2]2673  #puts "::TolInspector::PostTree $x $y"
[6d7779d]2674  foreach it [array names data_menu] {
2675    $data_menu($it) delete 0 end
2676  }
2677  set InRootPool  [string equal [lindex [$ht_tree get -full anchor] end-1] "root-pool"]
[c14b554]2678  #puts "InRootPool: $InRootPool"
[6d7779d]2679  # InRootFiles has a value 1 if node is a File
2680  set InRootFiles [string equal [lindex [$ht_tree get -full anchor] end-1] "root-files"]
[c14b554]2681  #puts "InRootFiles: $InRootFiles"
[6d7779d]2682  # index of the selected node
2683  set node_act [$ht_tree index current]
[c14b554]2684  #puts "node_act: $node_act" 
[6d7779d]2685  if { [string length $node_act] } {
2686    set vars_selected [$ht_tree curselection]
[7a0e436f]2687    #puts "vars_selected: $vars_selected"     
[6d7779d]2688    if { [lsearch $vars_selected $node_act] >= 0 } { ;# Not root node
2689      set index [$ht_tree index anchor]
[7a0e436f]2690      #puts "index: $index"   
[6d7779d]2691      if { $index } {
2692        set info_node [split [lindex [$ht_tree get -full $index] end] "-"]
[7a0e436f]2693        #puts "info_node: $info_node" 
[6d7779d]2694        set node_type [lindex $info_node 0]
[7a0e436f]2695        #puts "node_type: $node_type"         
[6d7779d]2696        set node_name [lindex $info_node 1]
[7a0e436f]2697        #puts "node_name: $node_name"         
[6d7779d]2698      } else { ;# root node
2699        set node_type root
2700        set node_name root
2701      }
2702      # if user selects a root or a grammar doesn't nothing
2703      switch -regexp $node_type  {
2704        root -
2705        grammar { return }
2706      }
2707      # label of object showed in the tree
2708      set objName [$ht_tree entry cget $index -label]
[7a0e436f]2709      #puts "objName: $objName"
[6d7779d]2710      set object $objName
2711
2712      if {$InRootFiles} {
2713        array set aryData [$ht_tree entry cget $index -data]
2714        if [info exist aryData(FileName)]  {
2715          set objName $aryData(FileName)
2716        }
2717      }
[c14b554]2718      #puts "2objName: $objName"   
[6d7779d]2719      if { $InRootPool } {
[bc68cb2]2720        #puts "es InRootPool $item_id"       
[6d7779d]2721        set itemid $item_id
[bc68cb2]2722        #set object $data(pool,variables,$itemid)
2723        set object $data(pool,reference,$node_type)
[6d7779d]2724      } else {
[c14b554]2725        #puts "NO InRootPool"
[6d7779d]2726        if { [string length $tolset] } {         
2727          set object [concat [list $tolset] $tolindex]
2728        } else {
2729          set object $objName
2730        }
2731      }
[7a0e436f]2732      #puts "object = $objName '[$ht_tree entry cget $index -data]'"
[6d7779d]2733#Tolcon_Trace "***********************************" {red}
2734#Tolcon_Trace "index=$index, node_type=$node_type, node_name=$node_name" {red}
2735#Tolcon_Trace "tolset=$tolset, tolindex=$tolindex, aryData= [$ht_tree entry cget $index -data]" {red}
2736#Tolcon_Trace "object=$object, label=$objName" {red}
2737#Tolcon_Trace "***********************************" {red}
[bc68cb2]2738     
2739      #
2740      # TICKET: #1438
2741      # Por que se pregunta aqui por los objetos de consola?
2742      #
[6d7779d]2743      set stackList [::tol::console stack list]
[c14b554]2744      #puts "stackList: $stackList"
[6d7779d]2745      set stackValue {}
2746      foreach stackItem $stackList {
[c14b554]2747        #puts "stackItem: $stackItem"
2748        #puts "lindex $stackValue 1: [lindex $stackValue 1]"
2749        #puts "objName: $objName" 
[6d7779d]2750        if {[lindex $stackItem 1] eq $objName} {
2751          set stackValue $stackItem
2752        }
2753        break
2754      }
[c14b554]2755      #puts "stackValue: $stackValue"
[6d7779d]2756      set grammar [lindex $stackValue 0]     
[c14b554]2757      #puts "grammar: $grammar"
2758      #set full_data $item_data($index) ;# {value} {desc} {grammar}   
2759      #set grammar [lindex $full_data 2]
[6d7779d]2760     
[c14b554]2761      #foreach fun  [::tol::info functions $grammar] {
2762      #  set finfo [::tol::info functions $grammar $fun]
2763      #  InsertChild Code $fun [lindex $finfo 0] [lindex $finfo 1] [list [lindex $finfo 2]] 0   
2764      #}
[6d7779d]2765      if {[catch {set info [::tol::info included $objName]}]} {
2766        if { !($grammar eq "")} {
[c14b554]2767          if {[catch {set info [::tol::info var [list $grammar $object]}]} {
2768            #set info [concat [list "$grammar" $objName ] [::tol::info var $grammar $objName]]
2769                        set info [::tol::info var [list $grammar $objName]]
2770            #Tolcon_Trace "INFO de ::tol::info var Set objName"
[6d7779d]2771          } else  {
[c14b554]2772            set info [::tol::info var [list $grammar $object]]
2773            #Tolcon_Trace "INFO de ::tol::info var $grammar object"
[6d7779d]2774          }       
2775          set isFile [expr [lindex $info 5] == 4]
2776        } else {
2777          set isFile 0
2778        }
2779
2780      } else {
2781        set info [::tol::info included $objName]
[c14b554]2782        #Tolcon_Trace "INFO de ::tol::info included objName"
[6d7779d]2783        set isFile 1
2784      }
[c14b554]2785      #puts "paso"
[6d7779d]2786
2787      if $isFile {
[c14b554]2788        #puts "entro como fichero"       
[6d7779d]2789        $data_menu(main) add command -label [mc "View file"] \
2790                -command [list ::TolInspector::ViewFile $objName]
2791        if $InRootFiles {
2792          $data_menu(main) add command -label [mc "Decompile file"] \
2793                -command [list ::TolInspector::DecompileFile $objName]
2794        }
2795      } else {
[c14b554]2796        #puts "no entro como fichero"       
[6d7779d]2797        if { $grammar eq "Set" } {
2798          $data_menu(main) add command -label [mc "Table set"] \
2799                -command [list ::TolInspector::TableSet $object]
2800          $data_menu(main) add command -label [mc "Draw set"] \
2801                -command [list ::TolInspector::DrawSet $object]
2802        }
2803      }
2804      tk_popup $data_menu(main) $x $y
2805    }
2806  }
2807}
2808
2809
2810#/////////////////////////////////////////////////////////////////////////////
2811# Procedures asociated with tol inspector popup menu
2812#/////////////////////////////////////////////////////////////////////////////
2813
2814#/////////////////////////////////////////////////////////////////////////////
2815proc ::TolInspector::RemoveFromSpool {ht} {
2816#
2817# PURPOSE: Removes from spool all selected objects
2818#
2819#/////////////////////////////////////////////////////////////////////////////
2820  variable vars_selected
2821  variable item_data
2822  variable tolset
2823  variable tolindex
2824  variable data
2825
2826  foreach var $vars_selected {
2827    array set aryData [$ht entry cget $var -data]
2828    set itemid $aryData(Index)
2829    set path   $aryData(Path)
2830    set reference $aryData(Reference)
2831    set grammar [lindex $item_data($itemid) 2]
2832
2833    set objName [$ht entry cget $var -label]
2834
2835    set _objpool [list "grammar" $grammar "objName" $objName "reference" $reference "path" $path]
2836    if {$grammar eq "Code"} {
2837      set graApply [lindex $aryData(Content) 0]
2838      lappend _objpool "graApply" $graApply
2839    }
2840    #Tolcon_Trace "OBJPOOL on REMOVE: $_objpool"
2841
2842    # Buscamos el objeto (identificador: referencia)
2843    array set objpool $_objpool
2844    foreach _obj $data(pool,objects) {
2845      array set obj $_obj
2846      #Tolcon_Trace "obj(reference)=$obj(reference), objpool(reference)=$objpool(reference)"
2847      if {[string equal $obj(reference) $objpool(reference)]} {
2848        if {$obj(grammar) eq "Code"} {
2849          if {[string equal $obj(graApply) $objpool(graApply)]} {
2850            set idx [lsearch $data(pool,objects) $_obj]
2851            #Tolcon_Trace "El obj a quitar tiene idx=$idx"
2852            set data(pool,objects) [lreplace $data(pool,objects) $idx $idx]
2853          }
2854        } else {
2855          set idx [lsearch $data(pool,objects) $_obj]
2856          #Tolcon_Trace "El obj a quitar tiene idx=$idx"
2857          set data(pool,objects) [lreplace $data(pool,objects) $idx $idx]
2858        }
2859      }
2860    }
2861  }
2862  #Tolcon_Trace "P.O. after REMOVE: $data(pool,objects)"
2863  UpdatePoolObj
2864}
2865
2866#/////////////////////////////////////////////////////////////////////////////
2867proc ::TolInspector::AddToSpool {ht origin} {
2868#/////////////////////////////////////////////////////////////////////////////
2869  variable vars_selected
2870  variable item_data
2871  variable tolset
2872  variable tolindex
2873  variable data
2874
2875  foreach var $vars_selected {
2876    array set aryData [$ht entry cget $var -data]
2877    set itemid $aryData(Index)
2878    set path   $aryData(Path)
2879    set grammar [lindex $item_data($itemid) 2]
2880    set objName [$ht entry cget $var -label]
[c14b554]2881        #puts "AddToSpool: Reference=$aryData(Reference) tolset=$tolset grammar=$grammar"
[6d7779d]2882    if {[llength $aryData(Reference)]} {
2883      set reference $aryData(Reference)
2884    } else {
2885      if { [string length $tolset] } {
[c14b554]2886        #set object [concat [list $tolset] $tolindex $itemid]
2887        #set object [concat [list File $tolset] $tolindex $itemid]
2888        set object [concat $tolset $tolindex $itemid]
2889        #puts "AddToSpool: object=$object"
[6d7779d]2890        set reference [::tol::info reference $object]
2891      } else {
[c14b554]2892        if {$grammar eq "Set"} {
2893          #puts "AddToSpool: origin=$origin"
2894          set reference [::tol::info reference [list Set $objName]]
[6d7779d]2895          #Tolcon_Trace "reference de ::tol::info reference [list $objName]"
2896        } else {
[c14b554]2897          if [catch {set reference [::tol::info reference [list $grammar $objName]]}] {
[6d7779d]2898            set reference $objName
2899            #Tolcon_Trace "reference NO SE QUE PONER"
2900          }
2901          #Tolcon_Trace "reference de ::tol::info reference $grammar $objName"
2902        }
2903      }
2904    }
2905    set _objpool [list "origin" $origin "grammar" $grammar "objName" $objName "reference" $reference "path" $path]
2906    if {$grammar eq "Code"} {
2907      set graApply [lindex $aryData(Content) 0]
2908      lappend _objpool "graApply" $graApply
2909    }
2910    #Tolcon_Trace "***************"
2911    #Tolcon_Trace "OBJPOOL on ADD:"
2912    #Tolcon_Trace "***************"
2913    #foreach {key value} $_objpool {
2914    #  Tolcon_Trace "  $key=$value"
2915    #}
2916    set inserted 0
2917    # Si la referencia es igual, el objeto es el mismo (salvo para obj de tipo Code)
2918    array set objpool $_objpool
2919    foreach _obj $data(pool,objects) {
2920      array set obj $_obj
2921      if {[string equal $obj(reference) $objpool(reference)]} {
2922        #Si es de la gramatica Code miro a ver la gramatica sobre la que se aplica
2923        if {$objpool(grammar) eq "Code"} {
2924          if {[string equal $obj(graApply) $objpool(graApply)]} {
2925            set inserted 1
2926          }
2927        } else {
2928          set inserted 1
2929        }
2930      }
2931    }
2932    if {!$inserted} {
2933      lappend data(pool,objects) $_objpool
[c14b554]2934      #puts "AddToSpool: P.O. after ADD: $data(pool,objects)"
[6d7779d]2935    } else  {
[c14b554]2936      #puts "$_objpool ALREADY IN SPOOL"
[6d7779d]2937    }
2938  }
2939 
2940}
2941
2942#/////////////////////////////////////////////////////////////////////////////
2943proc ::TolInspector::AddToEvalWindow {ht} {
2944#
2945# PURPOSE: Adds names of selected objects (vars or functions) in treeview ht
2946#          to eval window
2947#
2948#/////////////////////////////////////////////////////////////////////////////
2949  variable ht_vars
2950  variable vars_selected
2951
2952  set names ""
2953  foreach var $vars_selected {   
2954    lappend names [$ht entry cget $var -label]
2955  }
2956  ::TolConsole::ToEvalWindow [ListToStr $names]
2957}
2958
2959
2960#/////////////////////////////////////////////////////////////////////////////
2961proc ::TolInspector::SelectAll {ht} {
2962#
2963# PURPOSE: Selects all nodes of a given treeview
2964#
2965# PARAMETERS:
2966#   ht -> treeview's path
2967#
2968#/////////////////////////////////////////////////////////////////////////////
2969  set found [$ht find]
2970  if {[llength $found] > 1} {
2971    $ht selection set [lindex $found 1] [lindex $found end]
2972  }
2973}
2974
2975
2976#/////////////////////////////////////////////////////////////////////////////
2977  proc ::TolInspector::ToggleSelection {ht} {
2978#
2979# PURPOSE: Toggles selection of nodes of a given treeview
2980#
2981# PARAMETERS:
2982#   ht -> treeview's path
2983#
2984#/////////////////////////////////////////////////////////////////////////////
2985  set found [$ht find]
2986  if {[llength $found] > 1} {
2987    $ht selection toggle [lindex $found 1] [lindex $found end]
2988  }
2989}
2990
2991#/////////////////////////////////////////////////////////////////////////////
2992proc ::TolInspector::DrawSet {setref {type 0}} {
2993#
2994# PURPOSE: Graph a Set. For it it calls to a form for the selection of
2995#          columns to graph
2996#
2997# PARAMETERS:
2998#   setref -> Set to graph
2999#   type   -> 0 for custom association of data columns
3000#          -> 1 for all data columns to first one
3001#          -> 2 for all data columns to generic
3002#          -> 3 for even data columns to odd ones
3003#
3004#/////////////////////////////////////////////////////////////////////////////
3005  variable group_id
3006  variable w_tabset
[c14b554]3007  #puts "::TolInspector::DrawSet. setref: $setref"
[6d7779d]3008  incr group_id
3009  if {[llength $setref] > 1} {
3010    set name [lindex [::tol::info variable $setref] 1]
3011  } else {
3012    set name $setref
3013  }
3014  set cmd tablecmd$group_id
3015  if {![catch {::tol::tableset create $cmd $setref}]} {
3016    switch $type {
3017      0 {
3018        set tl [::project::CreateForm \
3019          -width 500 -height 500 -type Graphs \
3020          -iniconfig Graph \
3021          -title [mc "Set graph: %s" $name] -helpkey "Tb4GraSet"]
3022        $tl withdraw
3023        set tlf [$tl getframe]
3024        if {[set Instance [::SetGraphDialog::Init $tlf.g $cmd $setref]] != 0} {
3025          bind $tlf.g <Destroy> +[list ::tol::tableset destroy $cmd]
3026          pack $tlf.g -fill both -expand yes
3027          $tl restore
3028          update
[c14b554]3029          # Esta opción se debe aplicar cuando el gráfico esté empacado
[6d7779d]3030          ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
3031        } else {
3032          destroy $tl
3033          return
3034        }
3035        $tl bind <Control-F4> [list $tl kill]             
3036      }
3037      1 -
3038      2 -
3039      3 {
3040        # windows
3041        set tl [::project::CreateForm \
3042          -title [mc "Set graph: %s" $name] -type Graphs -iniconfig SetGraph]
3043        $tl withdraw       
3044        set tlf [$tl getframe]
3045        set Instance [::SetGraphDialog::DrawSet $tlf.g $cmd $setref $type]
3046        bind $tlf.g <Destroy> +[list ::tol::tableset destroy $cmd]
3047        pack $tlf.g -fill both -expand yes
3048        $tl restore
3049        update
[c14b554]3050        # Esta opción se debe aplicar cuando el gráfico esté empacado       
[6d7779d]3051        ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
3052      }
3053    }
3054  } else {
3055    tk_messageBox -type ok -icon warning \
3056        -message [mc "Set is not graficable: %s" $::errorInfo] \
3057        -parent $w_tabset -title [mc "Warning"]
3058  }
3059}
3060
3061#/////////////////////////////////////////////////////////////////////////////
3062proc ::TolInspector::DrawMatrix {matref} {
3063#
3064# PURPOSE: draw the given matrix
3065#
3066# PARAMETERS:
3067#   matref -> reference to the tol matrix
3068#
3069#/////////////////////////////////////////////////////////////////////////////
3070  variable group_id
3071  variable w_tabset
3072
3073  incr group_id
3074  if {[llength $matref] > 1} {
3075    set name [lindex [::tol::info variable $matref] 1]
3076  } else {
3077    if { ([info exists obj]) } {
3078      set name $obj
3079    }
3080  }
3081  if { ([info exists name]) } {
3082    set cmd tablecmd$group_id
3083    if {![catch {::tol::tablematrix create $cmd $matref}]} {
3084      set tl [::project::CreateForm \
3085                  -width 500 -height 500 -type Graphs \
3086                  -iniconfig Graph \
3087                  -title [mc "Matrix graph: %s" $name] -helpkey "Tb4Gra"]
3088      $tl withdraw
3089   
3090      set tlf [$tl getframe]
3091      if {[set Instance [::SetGraphDialog::Init $tlf.g $cmd $matref]] != 0} {
3092        bind $tlf.g <Destroy> +[list ::tol::tablematrix destroy $cmd]
3093        pack $tlf.g -fill both -expand yes
3094            $tl restore
3095        update
[c14b554]3096        # Esta opción se debe aplicar cuando el gráfico esté empacado
[6d7779d]3097        ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
3098      } else {
3099        destroy $tl
3100        return
3101      }
3102      $tl bind <Control-F4> [list $tl kill]
3103    } else {
3104      tk_messageBox -type ok -icon warning \
3105        -message [mc "Matrix is not graficable: %s" $::errorInfo] \
3106        -parent $w_tabset -title [mc "Warning"]
3107    }
3108  }
3109}
3110
3111#/////////////////////////////////////////////////////////////////////////////
3112proc ::TolInspector::TableSet { set } {
3113#///////////////////////////////////////////////////////////////////////////// 
3114  variable w_tabset
3115  variable group_id
3116
3117  incr group_id
3118  if {[llength $set] > 1} {
3119    set nameSet [lindex [::tol::info variable $set] 1]
3120  } else {
3121    set nameSet $set
3122  }
3123  set setgrp group$group_id
3124  if {![catch {::tol::tableset create $setgrp $set}]} {
3125    # create
3126    set tl [::project::CreateForm \
3127        -title    "[mc "Set table"]: $nameSet" \
3128        -iniconfig SetTable \
3129        -type Tables -helpkey "Tb4Edt"
3130    ]
3131    set tlf [$tl getframe]
3132    # config
3133    btable $tlf.t -parent $tl \
3134                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
3135                  -iniconfig btable
3136    $tlf.t fillSet $setgrp
3137    pack $tlf.t -fill both -expand yes
3138    bind $tlf.t <Destroy> +[list ::tol::tableset destroy $setgrp]
3139    $tl bind <Control-F4> [list $tl kill]
3140    update
3141  } else {
3142    tk_messageBox -type ok -icon warning -message [mc "Set not tabulable"]\
3143        -parent $w_tabset -title [mc Warning]
3144  }
3145}
3146
3147#/////////////////////////////////////////////////////////////////////////////
3148proc ::TolInspector::TableMatrix { matrix } {
[c14b554]3149#/////////////////////////////////////////////////////////////////////////////
[6d7779d]3150  set mattb [::tol::matrix $matrix]
3151  # create
3152  set tl [::project::CreateForm \
[c14b554]3153              -title "[mc {Matrix table}]: [lindex $mattb 0]" \
3154              -iniconfig MatrixTable \
3155              -type Tables -helpkey "Tb4Edt"
[6d7779d]3156  ]
3157  set tlf [$tl getframe]
3158  # create matrix
3159  btable $tlf.t -parent $tl \
3160                -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
3161                -iniconfig btable
3162  $tlf.t fillMatrix $mattb
3163  $tl bind <Control-F4> [list $tl kill] 
3164  pack $tlf.t -fill both -expand yes
[c14b554]3165
3166  #if {$grammar == "VMatrix"} {
3167    #::tol::console stack release "zxw._.wxz"
3168  #}
[6d7779d]3169}
3170
3171#/////////////////////////////////////////////////////////////////////////////
3172proc ::TolInspector::ExportBDTMatrix { matrix } {
3173#/////////////////////////////////////////////////////////////////////////////
3174  variable group_id
3175 
3176  incr group_id
3177  set tl [toplevel .top$group_id]
3178  wm title $tl "ExportBDTMatrix"
3179 
3180  #pack $tl.t -fill both -expand yes
3181}
3182
3183#/////////////////////////////////////////////////////////////////////////////
3184proc ::TolInspector::DrawSerie { } {
3185#///////////////////////////////////////////////////////////////////////////// 
3186  variable options_selected
3187  upvar \#0 ::TolInspector::options_selected(Serie) series_selected
3188 
[c14b554]3189  #puts "DrawSerie: series_selected=$series_selected"
[6d7779d]3190  set series ""
3191  foreach it $series_selected {
3192    lappend series [lindex $it 0]
3193  }
3194  DrawSeries $series
3195}
3196
3197#/////////////////////////////////////////////////////////////////////////////
3198proc ::TolInspector::DrawSeries { series {gcf ""}} {
3199#///////////////////////////////////////////////////////////////////////////// 
3200  variable group_id
3201
3202  if { [llength $series] } {
3203    incr group_id
3204    # series     
3205    set sergrp group$group_id
3206    set t0 [time {
3207    eval "::tol::seriegrp create $sergrp $series"
3208    }]
3209    # name
3210    set name [$sergrp serie 0 name]
3211    if { [$sergrp serie size] > 1} {
3212      set name ${name}...
3213    }
3214    # create
3215    set t1 [time {
3216    set tl [::project::CreateForm \
3217        -title [mc "Series graph: %s" $name] \
3218        -type Graphs \
3219        -iniconfig SeriesGraph \
3220        -width 900 -height 650 -helpkey "Tb4GraSer"
3221           ]}]
3222    set tlf [$tl getframe]
3223    # configuration
3224    set t2 [time {
3225    set Instance [::SeriesGraph::Create $tlf.g $sergrp]
3226    }]
[c14b554]3227    #puts "t0 = $t0"
3228    #puts "t1 = $t1"
3229    #puts "t2 = $t2"
[6d7779d]3230    if { $gcf != "" } {
3231      ::bayesGraph::LoadGCF $Instance $gcf
3232    }
3233    bind $tlf.g <Destroy> +[list ::tol::seriegrp destroy $sergrp]
3234    pack $tlf.g -fill both -expand yes
3235    $tl bind <Control-F4> [list $tl kill]
3236    update
[c14b554]3237    # Esta opción se debe aplicar cuando el gráfico esté empacado
[6d7779d]3238    #::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
3239  }
3240}
3241
3242#/////////////////////////////////////////////////////////////////////////////
3243proc ::TolInspector::DrawAutocorSerie { serie } {
3244#///////////////////////////////////////////////////////////////////////////// 
3245  variable group_id
3246   
3247  incr group_id
3248  # title
3249 
3250  if {[llength $serie] > 1} {
3251    set nameSerie [lindex [::tol::info variable $serie] 1]
3252  } else {
3253    set nameSerie $serie
3254  }
3255  # create
3256  set tl [::project::CreateForm \
3257      -title "[mc "Autocorrelation graph"]: $nameSerie" \
3258      -iniconfig AutocorGraph \
3259      -type Graphs \
3260      -width 900 -height 650 -helpkey "Tb4GraAco"
3261  ]
3262  set tlf [$tl getframe]
3263  # configuration
3264  ::AutocorGraph::Create $tlf.g $serie
3265  $tl bind <Control-F4> "$tl kill; break"
3266  pack $tlf.g -fill both -expand yes
3267  update
3268}
3269
3270#/////////////////////////////////////////////////////////////////////////////
3271proc ::TolInspector::TableSerie { } {
3272#///////////////////////////////////////////////////////////////////////////// 
3273  variable options_selected
3274  variable group_id
3275  upvar \#0 ::TolInspector::options_selected(Serie) series_selected
3276
3277  set series ""
3278  foreach it $series_selected {
3279    lappend series [lindex $it 0]
3280  }
3281
3282  if { [llength $series] } {
3283    incr group_id
3284
3285    set sergrp group$group_id
3286    eval "::tol::seriegrp create $sergrp $series"
3287   
3288    # create
3289    set tl [::project::CreateForm \
3290        -title [mc "Time series table"] \
3291        -iniconfig SeriesTable \
3292        -type Tables -helpkey "Tb4Edt"
3293    ]
3294        set tlf [$tl getframe]
3295    # configuration
3296    btable $tlf.t -parent $tl \
3297                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
3298                  -iniconfig btable
3299    $tlf.t fillSerie $sergrp
3300    bind $tlf.t <Destroy> +[list ::tol::seriegrp destroy $sergrp]
3301    pack $tlf.t -fill both -expand yes
3302    $tl bind <Control-F4> [list $tl kill]
3303    update
3304  }
3305}
3306
3307#/////////////////////////////////////////////////////////////////////////////
3308proc ::TolInspector::TableAutocorSerie { serie } {
3309#///////////////////////////////////////////////////////////////////////////// 
3310  variable group_id
3311   
3312  incr group_id
3313  # title
3314  if {[llength $serie] > 1} {
3315    set nameSerie [lindex [::tol::info variable $serie] 1]
3316  } else {
3317    set nameSerie $serie
3318  }
3319  # create
3320  set tl [::project::CreateForm \
3321      -title "[mc "Autocorrelation table"]: $nameSerie" \
3322      -iniconfig AutocorGraphTable \
3323      -type Tables -helpkey "Tb4Edt"
3324  ]
3325  set tlf [$tl getframe]
3326  # configuration
3327  btable $tlf.t -parent $tl \
3328                -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
3329                -iniconfig btable
3330  $tlf.t fillAutocor $serie ""
3331  $tl bind <Control-F4> [list $tl kill]
3332  pack $tlf.t -fill both -expand yes
3333}
3334
3335#/////////////////////////////////////////////////////////////////////////////
3336proc ::TolInspector::TableStatisticsSerie { } {
3337#/////////////////////////////////////////////////////////////////////////////
3338  variable options_selected
3339  variable group_id
3340  upvar \#0 ::TolInspector::options_selected(Serie) series_selected
3341
3342  set series ""
3343  foreach it $series_selected {
3344    lappend series [lindex $it 0]
3345  }
3346
3347  if { [llength $series] } {
3348    incr group_id
3349
3350    set sergrp group$group_id
3351    eval "::tol::seriegrp create $sergrp $series"
3352    # create
3353    set tl [::project::CreateForm \
3354        -title [mc "Statistics table"] \
3355        -iniconfig StatisticsTable \
3356        -type Tables -helpkey "Tb4Edt"
3357    ]
3358    set tlf [$tl getframe]
3359    # configuration
3360    btable $tlf.t -parent $tl \
3361                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
3362                  -iniconfig btable
3363    $tlf.t fillStatistics $sergrp
3364    bind $tlf.t <Destroy> +[list ::tol::seriegrp destroy $sergrp]
3365    $tl bind <Control-F4> [list $tl kill]
3366    pack $tlf.t -fill both -expand yes
3367  }
3368}
3369
3370#/////////////////////////////////////////////////////////////////////////////
3371proc ::TolInspector::ViewTimeSet { tms args } {
3372#/////////////////////////////////////////////////////////////////////////////
3373  variable group_id
3374 
3375  incr group_id
3376 
[c14b554]3377  #puts "::TolInspector::ViewTimeSet $tms"
[6d7779d]3378  # args
3379  array set opts [list \
3380    -title "[mc "TimeSet calendar"]: $tms" \
3381    -geometry {}
3382  ]
3383  array set opts $args 
3384 
3385  # create
3386  set tl [::project::CreateForm \
3387      -title $opts(-title) \
3388      -iniconfig Calendar \
3389      -type TimeSets -width 470 -height 345 -helpkey "Tb4Cal"
3390  ]
3391  # geometry
3392  $tl setgeometry $opts(-geometry)
3393 
3394  set tlf [$tl getframe]
3395  # configuration
3396  set tmscmd tms$group_id
3397  ::tol::timeset create $tmscmd $tms
3398  ::CalendarTms::Create $tlf.t $tmscmd
3399  bind $tlf.t <Destroy> +[list ::tol::timeset destroy $tmscmd]
3400  bind $tl <Control-F4> [list $tl kill]
3401  pack $tlf.t -fill both -expand yes
3402 
3403  return $tl
3404}
3405
3406#/////////////////////////////////////////////////////////////////////////////
3407proc ::TolInspector::ViewDefinition {name path grammar} {
3408#/////////////////////////////////////////////////////////////////////////////
3409  variable w_tabset
3410  if {$path == ""} {
3411    tk_messageBox -type ok -icon warning\
3412      -message [mc "Object %1\$s is not defined in a tol file" $name]\
3413      -parent $w_tabset -title [mc Warning]
3414    return
3415  }
3416  set ext [file extension $path]
3417  switch -- $ext {
3418    .tol -
3419    .TOL {
3420      set Instance [::Editor::Open $path]
3421      update
3422      if {[string equal $grammar "Code"] ||
3423          [string equal $grammar "Anything"]} {
3424        append txtFind " " $name "( )*\\("
3425      } else {
[f4a032f]3426        #append txtFind $grammar "( )+" $name
3427        append txtFind $name
[6d7779d]3428      }
3429      #Me situo al principio del texto
3430      set editor [::Editor::GetText $Instance]
3431      tk::TextSetCursor $editor 1.0
3432      ::BayesText::FindShow $editor 1 $txtFind 1
3433      #::Editor::CmdFindNext $Instance $txtFind
3434    }
3435    .bst -
3436    .BST -
3437    .bdt -
3438    .BDT {
3439      # Igual luego se abre como tabla
3440      ::Editor::Open $path
3441    }
3442  }
3443}
3444
3445#/////////////////////////////////////////////////////////////////////////////
3446proc ::TolInspector::ViewFile {name} {
3447#
3448# PURPOSE:
3449#
3450# PARAMETERS:
3451#   name -> cadena con el nombre de un archivo o el de una variable
3452#           que hace referencia a un archivo
3453#
3454#/////////////////////////////////////////////////////////////////////////////
3455  #  En name puede venir el nombre de un archivo o el de una variable
3456  # que hace referencia a un archivo.
[c14b554]3457  #puts "ViewFile. name=$name"
[6d7779d]3458  if [file isfile $name] {
3459    set path $name
3460  } else  {
3461    set path [::tol::info path $name]
3462  }
3463  ::Editor::Open $path
3464}
3465
3466#/////////////////////////////////////////////////////////////////////////////
3467proc ::TolInspector::DecompileFile {name} {
3468#
3469# PURPOSE:
3470#
3471# PARAMETERS:
3472#   name -> cadena con el nombre de un archivo o el de una variable
3473#           que hace referencia a un archivo
3474#
3475# TODO: Actualmente en name solo puede llegar el nombre de un archivo
3476#
3477#/////////////////////////////////////////////////////////////////////////////
3478  variable data
[c14b554]3479  #puts "DECOMPILE 1.1, name=$name"
[6d7779d]3480  if {[file isfile $name]} {
3481    set path $name
3482  } else  {
3483    set path [::tol::info path $name]
3484  }
[c14b554]3485  #puts "DECOMPILE 1.2"
3486  #Comprobar si el archivo ya está abierto y si es así poner que no está compilado
[6d7779d]3487  if [namespace exists ::Editor] {
3488    foreach ins [namespace children ::Editor] {
3489      upvar \#0 ${ins}::data dataEd
3490      if [string equal $dataEd(nameFile) $path] {
3491        set dataEd(isCompiled) 0
3492      }
3493    }
3494  }
[c14b554]3495  #puts "DECOMPILE 1.3"
[6d7779d]3496  #Quitar del spool todos los objetos provenientes de este archivo
3497 
3498  foreach _obj $data(pool,objects) {
3499    array set obj $_obj
3500    #Tolcon_Trace "REFERENCIA: $obj(reference)"
3501    if {[string equal [lindex $obj(reference) 0] $path]} {
3502      set idx [lsearch $data(pool,objects) $_obj]
3503      set data(pool,objects) [lreplace $data(pool,objects) $idx $idx]
3504    }
3505  }
3506  ::tol::decompile $path
3507  ::TolInspector::UpdateFileRoot
3508}
3509
3510#/////////////////////////////////////////////////////////////////////////////
3511proc ::TolInspector::ReadUserFunctions {} {
3512#
3513# PURPOSE: Recorre el set global que tiene la definicion de funciones y va
3514#          guardando esa informacion en arrays para almacenarla finalmente en
3515#          regFunLst
3516#
3517#/////////////////////////////////////////////////////////////////////////////
3518  variable regFunLst
3519 
3520  #Set global que tiene la definicion de funciones
3521  set obj GuiFunction
3522
3523  if { [llength [set infAry [TclInfoVar Set $obj]] ] } {
[c14b554]3524    #Tolcon_Trace "ReadUserFunctions: infAry = $infAry"
[6d7779d]3525    array set info $infAry
3526    set nFun [lindex $info(CONTENT) 0]
3527    #Tolcon_Trace "Numero de funciones =$nFun"
3528    for  {set idf 1} {$idf <= $nFun} {incr idf} {
[c14b554]3529      array set ifNameFun [TclInfoRef [list Set $obj $idf 1]]
3530      array set ifNameGui [TclInfoRef [list Set $obj $idf 2]]
3531      array set ifTypeGui [TclInfoRef [list Set $obj $idf 3]]
3532      array set ifTypeOut [TclInfoRef [list Set $obj $idf 4]]
3533      array set ifParams  [TclInfoRef [list Set $obj $idf 5]]
[6d7779d]3534      #Hago lindex $a(CONTENT) 0 para quitar las comillas
3535      set regFun($idf,nameFun) [lindex $ifNameFun(CONTENT) 0]
3536      set regFun($idf,nameGui) [lindex $ifNameGui(CONTENT) 0]
3537      set regFun($idf,typeGui) [lindex $ifTypeGui(CONTENT) 0]
3538      set regFun($idf,typeOut) [lindex $ifTypeOut(CONTENT) 0]
3539      set nPar [lindex $ifParams(CONTENT) 0]
3540      #Tolcon_Trace "Numero de parametros =$nPar"
3541      for  {set idp 1} {$idp <= $nPar} {incr idp} {
[c14b554]3542        array set ipNameGui [TclInfoRef [list Set $obj $idf 5 $idp 1]]
3543        array set ipTypePar [TclInfoRef [list Set $obj $idf 5 $idp 2]]
3544        array set ipTypeSel [TclInfoRef [list Set $obj $idf 5 $idp 3]]
3545        array set ipListVal [TclInfoRef [list Set $obj $idf 5 $idp 4]]
[6d7779d]3546        set regPar($idp,nameGui) [lindex $ipNameGui(CONTENT) 0]
3547        set regPar($idp,typePar) [lindex $ipTypePar(CONTENT) 0]
3548        set regPar($idp,typeSel)         $ipTypeSel(CONTENT)
3549        set nVal [lindex $ipListVal(CONTENT) 0]
3550        #Tolcon_Trace "nVal=$nVal"
3551        set lstVal ""
3552        for  {set idv 1} {$idv <= $nVal} {incr idv} {
[c14b554]3553           array set iVal [TclInfoRef [list Set $obj $idf 5 $idp 4 $idv]]
[6d7779d]3554           lappend lstVal [lindex $iVal(CONTENT) 0]
3555        }
3556        set regPar($idp,lstVal) $lstVal
3557      }
3558      set regFun($idf,parameters) [array get regPar]
3559      array unset regPar
3560      #parray regFun
3561    }
3562    set regFunLst [array get regFun]
3563  } else {
3564    set regFunLst ""
3565  }
3566}
3567
3568#/////////////////////////////////////////////////////////////////////////////
3569proc ::TolInspector::ShowMenuUserFunc {gra} {
3570#
3571# PURPOSE: Muestra un menu contextual que...
3572#
3573#/////////////////////////////////////////////////////////////////////////////
3574  variable data_menu
3575  variable regFunLst
[c14b554]3576 
[7a0e436f]3577  #puts "ShowMenuUserFunc: gra=$gra"
[6d7779d]3578  if {[expr [info exist ::TolInspector::regFunLst] && [llength $regFunLst] ]} {
3579    array set regFun $regFunLst
3580    regsub -all ,nameGui \
3581       [array names regFun *,nameGui] "" lstFun
3582    foreach idf [lsort -integer $lstFun] {
3583      set typeGui [split $regFun($idf,typeGui) .]
3584      switch  [lindex $typeGui 0] {
3585        Ite - Set {
3586          if {[lindex $typeGui 1] eq $gra} {
3587            $data_menu($gra,Functions) add command -label [mc $regFun($idf,nameGui)]\
3588              -command [list ::TolInspector::CallUserFunction $gra $idf]
3589          }
3590        }
3591        default {
3592        }
3593      }
3594    }
3595  }
3596}
3597
3598#/////////////////////////////////////////////////////////////////////////////
3599proc ::TolInspector::CallUserFunction {grammar idx} {
3600#
3601# PURPOSE: Para los tipos de funciones Ite y Set, muestra un dialogo que
3602#          pide los
3603#
3604#/////////////////////////////////////////////////////////////////////////////
3605  variable regFunLst
3606  variable group_id
3607  variable data
3608  variable options_selected
3609
3610  upvar \#0 ::TolInspector::options_selected($grammar) items_selected
3611  #puts "CallUserFunction. grammar=$grammar, idx=$idx, items_selected=$items_selected"
3612 
[64bb607]3613  set all_objs [ list ]
[6d7779d]3614  foreach it $items_selected {
[64bb607]3615    set tcl_ref [ lindex $it 0 ]
3616    set obj_addr [ ::tol::info address $tcl_ref ]
3617    lappend all_objs "GetObjectFromAddress(\"$obj_addr\")"
[6d7779d]3618  }
3619
[64bb607]3620  if { [ llength $all_objs ] } {
[6d7779d]3621    incr group_id
3622    array set regFun $regFunLst
3623    set gui [bguifunction .t$group_id \
[64bb607]3624                 -title $regFun($idx,nameGui) \
3625                 -regpars $regFun($idx,parameters)]
[6d7779d]3626    set txtPars [join [$gui get values] ,]
3627    if {$txtPars ne ""} {
3628      set txtPars ",$txtPars"
3629    }
3630    destroy $gui
3631    set typeGui [split $regFun($idx,typeGui) .]
3632    switch [lindex $typeGui 0] {
3633      Ite {
[64bb607]3634        foreach obj $all_objs {
3635          set cmd "$regFun($idx,typeOut) $regFun($idx,nameFun) ($obj $txtPars)"
[c14b554]3636          #Tolcon_Trace "Ite.cmd=$cmd"
[6d7779d]3637          ::tol::console eval $cmd
3638          ::TolConsole::SaveEval $cmd
3639        }
3640      }
3641      Set {
[64bb607]3642        set obj_args [join $all_objs ,]
3643        set setCmd "SetOf[lindex $typeGui 1] ($obj_args)"
[6d7779d]3644        set cmd "$regFun($idx,typeOut) $regFun($idx,nameFun) ($setCmd $txtPars)"
[c14b554]3645        #Tolcon_Trace "Set.cmd=$cmd"
[6d7779d]3646        ::tol::console eval $cmd
3647        ::TolConsole::SaveEval $cmd
3648      }
3649      default {
3650      }
3651    }
3652    ::TolInspector::UpdateConsoleObj
3653  }
3654}
3655
3656namespace eval ::LoadStatus {
3657  variable data
3658}
3659
3660#proc ::LoadStatus::Show {file} {
3661#   
3662#  set f [toplevel .topStatus]
3663#  #wm protocol $path WM_DELETE_WINDOW [list ::Editor::OnDelete $this]
[c14b554]3664#  # bind Destroy más abajo
[6d7779d]3665# 
3666#  label $f.lfile -text $file
3667#  # frame y label para barra de estado
3668#  set data(sb,frame) [frame $f.fop -relief groove -bd 1 -height 7]
3669#  set data(sb,objs)  [label $f.fop.objs -relief groove -bd 1 -width 16]
3670#  set data(sb,files) [label $f.fop.files -text [mc "Not Compiled"] \
3671#          -relief raised -bd 1 -width 16]
3672#  set data(sb,time)  [label $f.fop.time -bd 1 -width 14]
3673#  set data(sb,rell)  [label $f.fop.rell -relief groove -bd 1]
3674# 
3675# 
3676#  # empaquetamos los label de estado
3677#  pack $f.fop.objs $f.fop.files $f.fop.time -side left
3678#  pack $f.fop.rell -expand true -fill x
3679# 
3680#  grid $f.lfile -sticky news
3681#  grid $f.fop   -sticky ews
3682# 
3683#  grid rowconfigure    $f 1 -weight 1
3684#  grid columnconfigure $f 0 -weight 1
3685#   
3686#}
3687#
3688#
3689#proc ::LoadStatus::Hide {w} {
3690#   
3691#
Note: See TracBrowser for help on using the repository browser.