source: tol/tolbase/lib/toltk/tolinspe.tcl @ 03885938

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

closes #866 : debia inicializarse el elemento NameBlock,File dentro de data_menu

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

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