source: tol/tolbase/lib/toltk/bftrview.tcl

devel
Last change on this file was 4592f76, checked in by Pedro Gea <pgea@…>, 10 years ago

Refs #1933
Se sustituye el árbol del editor de PRJ's por un wtree.
Se prescinde del namespace ::BayesTreeview.

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

  • Property mode set to 100644
File size: 4.8 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : bftrview.tcl
3# PURPOSE : This file contains some utility functions for treeviews
4#           manipulation or generation.
5#/////////////////////////////////////////////////////////////////////////////
6
7#@ OBSOLETO
8
9#/////////////////////////////////////////////////////////////////////////////
10  namespace eval ::BayesTreeview {
11#
12# PURPOSE: The purpose of this namespace is organize code and functions and
13#          provides functions to manage treeviews.
14#
15#/////////////////////////////////////////////////////////////////////////////
16}
17
18#/////////////////////////////////////////////////////////////////////////////
19# Functions that convert between treeviews and especification files.
20#/////////////////////////////////////////////////////////////////////////////
21#   File is similar to a .ini file. There are two special items: ('children'
22#  and 'label') for each node.  Here's an example:
23#         [Root]
24#           Children=1
25#           Label=Nodo raiz
26#           Type=
27#           Data1=bla,bla,...
28#           DataN=bla,bla,...
29#         [1]
30#           Children=
31#           Label=Label del nodo 1
32#           Type=
33#           Data1=bla,bla,...
34#           DataN=bla,bla,...
35#
36#/////////////////////////////////////////////////////////////////////////////
37
38#/////////////////////////////////////////////////////////////////////////////
39  proc ::BayesTreeview::TreeviewFromFile {tv path {proc ""}} {
40#
41# PURPOSE: Loads a treeview info data from a text especification file of a
42#          treeview.
43#
44# PARAMETERS:
45#   tv   -> treeview's path
46#   path -> name of file
47#   proc -> procedure that converts type node to the path of the image of node
48#
49# RETURN: Returns 1 if treeview has been loaded correctly or 0 if not.
50#
51#/////////////////////////////////////////////////////////////////////////////
52  if ![file exists $path] {
53    return -code error "File $path doesn't exist"
54  }
55  Tolcon_Trace "Llamada a TreeviewFromFile"
56  set fd [iniparse:openfile $path]
57  NodeFromFile $tv root "" $fd $proc
58  iniparse:closefile $fd
59  return 1
60}
61
62
63#/////////////////////////////////////////////////////////////////////////////
64  proc ::BayesTreeview::TreeviewToFile {tv path} {
65#
66# PURPOSE: Saves a treeview info data into a text especification file of a
67#          treeview.
68#
69# PARAMETERS:
70#   tv   -> treeview's path
71#   path -> name of file
72#
73# RETURN: Returns 1 if file has been saved correctly or 0 if not.
74#
75#/////////////////////////////////////////////////////////////////////////////
76  #borrar archivo pq iniparse:openfile abre para solo lectura si existe
77  file delete $path
78  set fd [iniparse:openfile $path]
79  NodeToFile $tv root $fd
80  iniparse:closefile $fd
81  return 1
82}
83
84
85#/////////////////////////////////////////////////////////////////////////////
86  proc ::BayesTreeview::NodeToFile {tv index fd} {
87#
88# PURPOSE: Saves a treeview's node info data into a text file.
89#
90# PARAMETERS:
91#   tv    -> treeview's path
92#   index -> treeview node index
93#   fd    -> channel identifier of text file
94#
95#/////////////////////////////////////////////////////////////////////////////
96  set key $index
97
98  # Guardar data del nodo actual
99  array set aryData [$tv entry cget $index -data]
100  foreach item [array names aryData] {
101    writeini $fd $key $item $aryData($item)
102  }
103 
104  writeini $fd $key Label [$tv entry cget $index -label]
105  # Guardar sus hijos
106  writeini $fd $key Children [$tv entry children $index]
107
108  # Llamar recursivamente para los hijos
109  foreach child [$tv entry children $index] {
110    NodeToFile $tv $child $fd
111  }
112}
113
114
115#/////////////////////////////////////////////////////////////////////////////
116  proc ::BayesTreeview::NodeFromFile {tv index parent fd {imgFromType ""}} {
117#
118# PURPOSE: Loads a treeview's node info data from a text file.
119#
120# PARAMETERS:
121#   tv     -> treeview's path
122#   index  -> treeview node index
123#   parent -> treeview node's parent index
124#   fd     -> channel identifier of text file
125#
126#/////////////////////////////////////////////////////////////////////////////
127  set key $index
128
129  if ![string equal $parent ""] {
130    set idx [$tv insert -at $parent end $index ]
131  } else {
132    set idx root
133  }
134  # Configurar data del nodo actual
135  foreach item [readini $fd $key] {
136    set value [readini $fd $key $item]
137    if {[lsearch -exact [$tv column names] $item] != -1} {
138      $tv entry configure $idx -data [list $item $value]   
139    }
140    if [string equal $item "Label"] {
141      $tv entry configure $idx -label $value
142    }
143    if {[string equal $item "Type"] && ![string equal $imgFromType ""]} {
144      if ![string equal [set img [$imgFromType $value]] ""] {
145        $tv entry configure $idx -icons [list $img $img]
146      }
147    }
148  }
149  # Llamar recursivamente para los hijos
150  foreach child [readini $fd $key Children] {
151    NodeFromFile $tv $child $idx $fd $imgFromType
152  }
153}
Note: See TracBrowser for help on using the repository browser.