1 | # This program is under CECILL_B licence. See footer for details. |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | proc loadProject {fileName } { |
---|
7 | global widgetInfo loadedProject workingDir |
---|
8 | global DStree metaTree |
---|
9 | |
---|
10 | |
---|
11 | # start timer |
---|
12 | set load_start_time [clock milliseconds] |
---|
13 | |
---|
14 | |
---|
15 | # load projet into a loadtree |
---|
16 | dTree_init loadTree |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | xml2tree $fileName loadTree "DStree" |
---|
22 | set loadedProject $fileName |
---|
23 | updateTitle |
---|
24 | cd [file dirname $loadedProject] |
---|
25 | # If it doesn't exist, create directory according to file name |
---|
26 | set dirName [file tail [file rootname $fileName]] |
---|
27 | if {$widgetInfo(classApp) != "nanoapp"} { |
---|
28 | if {![file exists $dirName]} { |
---|
29 | file mkdir $dirName |
---|
30 | } |
---|
31 | cd $dirName |
---|
32 | } |
---|
33 | set workingDir [pwd] |
---|
34 | |
---|
35 | |
---|
36 | startup_log_channel |
---|
37 | |
---|
38 | |
---|
39 | # Moving meta into metaTree |
---|
40 | # Moving dataset into DStree |
---|
41 | dTree_init DStree |
---|
42 | |
---|
43 | if {[dTree_nodeExists $loadTree "root dataset"] && [dTree_nodeExists $loadTree "root dataset meta"]} { |
---|
44 | dTree_init metaTree |
---|
45 | dTree_moveBranch loadTree "root dataset meta" metaTree "root" |
---|
46 | foreach child [dTree_getChildren $loadTree "root dataset"] { |
---|
47 | dTree_moveBranch loadTree "root dataset $child" DStree "root" |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | RefreshFamily "root" |
---|
53 | set nb_of_validations 1 |
---|
54 | for {set x 0} {$x < $nb_of_validations } {incr x} { |
---|
55 | CheckValidationStatus "root" |
---|
56 | } |
---|
57 | |
---|
58 | # update Meta data |
---|
59 | dTree_setAttribute metaTree "root meta project address" "value" "[file normalize $fileName]" |
---|
60 | dTree_setAttribute metaTree "root meta project name" "value" "[file tail [file rootname $fileName]]" |
---|
61 | |
---|
62 | # monitor time |
---|
63 | set load_stop_time [clock milliseconds] |
---|
64 | set msgloadtime "Loading time : [printtime $load_start_time $load_stop_time ] s." |
---|
65 | puts $msgloadtime |
---|
66 | log $msgloadtime |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | proc startup_log_channel {} { |
---|
72 | global workingDir log_channel loadedProject loadApplication |
---|
73 | |
---|
74 | if {$log_channel != "stdout"} { |
---|
75 | close $log_channel |
---|
76 | } |
---|
77 | set log_channel [ open [file join $workingDir "trace.log"] a+ ] |
---|
78 | |
---|
79 | fconfigure $log_channel -blocking 0 |
---|
80 | |
---|
81 | puts $log_channel "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" |
---|
82 | puts $log_channel "Application $loadApplication" |
---|
83 | puts $log_channel "Project $loadedProject" |
---|
84 | puts $log_channel "Date [clock format [clock seconds]]" |
---|
85 | puts $log_channel "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" |
---|
86 | |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | proc loadProject_as_part {fileName } { |
---|
91 | global widgetInfo loadedProject workingDir |
---|
92 | global DStree metaTree |
---|
93 | |
---|
94 | Start_think "" |
---|
95 | # start timer |
---|
96 | set load_start_time [clock milliseconds] |
---|
97 | |
---|
98 | |
---|
99 | # load projet into a loadtree |
---|
100 | dTree_init loadTree |
---|
101 | |
---|
102 | |
---|
103 | #################################### |
---|
104 | # fork btw CSV and XML , deprecated |
---|
105 | # set fileExtension [string tolower [file extension $fileName]] |
---|
106 | #if $fileExtension == ".xml" |
---|
107 | #################################### |
---|
108 | |
---|
109 | |
---|
110 | xml2tree $fileName loadTree "DStree" |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | set ProjectToAdd $fileName |
---|
116 | updateTitle |
---|
117 | set filesToCopy [glob -nocomplain -directory [file rootname $ProjectToAdd] "*"] |
---|
118 | |
---|
119 | foreach subfile $filesToCopy { |
---|
120 | debug "Copying $subfile in $workingDir ..." |
---|
121 | if {[catch { file copy -force $subfile $workingDir } pbcopy ]} { |
---|
122 | warning "$pbcopy" |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | #################################### |
---|
127 | # fork btw CSV and XML , deprecated |
---|
128 | #if $fileExtension == ".xml" |
---|
129 | #elseif $fileExtension == ".csv" |
---|
130 | #if $loadedProject == "none" |
---|
131 | # error "An xml project needs to be first loaded" |
---|
132 | # return |
---|
133 | #csv2tree $fileName loadTree |
---|
134 | #################################### |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | # Moving meta into metaTree |
---|
139 | # Moving dataset into dummy tree |
---|
140 | dTree_init dummyTree |
---|
141 | if {[dTree_nodeExists $loadTree "root dataset"] } { |
---|
142 | foreach child [dTree_getChildren $loadTree "root dataset"] { |
---|
143 | dTree_moveBranch loadTree "root dataset $child" dummyTree "root" |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | # compare the present tree with the loaded tree |
---|
151 | set refreshList "" |
---|
152 | set comparisonList "" |
---|
153 | dTree_compareBranch $DStree $dummyTree "root" 0 comparisonList |
---|
154 | # Merging first and fourth list |
---|
155 | set modificationList [lsort -unique [concat [lindex $comparisonList 0] [lindex $comparisonList 1]]] |
---|
156 | |
---|
157 | |
---|
158 | # Applying differences |
---|
159 | foreach addr [lsort -unique [lindex $modificationList]] { |
---|
160 | debug ">>> Grafting branch on current memory : [lindex $addr end] ..." |
---|
161 | |
---|
162 | dTree_copyBranch dummyTree $addr DStree [lrange $addr 0 end-1] |
---|
163 | } |
---|
164 | RefreshFamily "root" |
---|
165 | CheckValidationStatus "root" |
---|
166 | |
---|
167 | |
---|
168 | # monitor time |
---|
169 | set load_stop_time [clock milliseconds] |
---|
170 | set msgloadtime "Loading time : [printtime $load_start_time $load_stop_time ] s." |
---|
171 | puts $msgloadtime |
---|
172 | log $msgloadtime |
---|
173 | Stop_think normal |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | proc loadDataset {fileName} { |
---|
186 | global DStree |
---|
187 | global metaTree |
---|
188 | global tmpTree |
---|
189 | |
---|
190 | dTree_init loadTree |
---|
191 | parseFile $fileName loadTree "" "DStree" |
---|
192 | |
---|
193 | dTree_init metaTree |
---|
194 | dTree_rmBranch loadTree "root dataset meta config" |
---|
195 | dTree_moveBranch loadTree "root dataset meta" metaTree "root" |
---|
196 | |
---|
197 | #dTree_rmBranch loadTree "root dataset DATA" |
---|
198 | |
---|
199 | dTree_init dummyTree |
---|
200 | foreach child [dTree_getChildren $loadTree "root dataset"] { |
---|
201 | dTree_moveBranch loadTree "root dataset $child" dummyTree "root" |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | set refreshList "" |
---|
206 | |
---|
207 | set comparisonList "" |
---|
208 | dTree_compareBranch $tmpTree $dummyTree "root" 1 comparisonList |
---|
209 | |
---|
210 | # Merging first and fourth list |
---|
211 | set modificationList [lsort -unique [concat [lindex $comparisonList 0] [lindex $comparisonList 3]]] |
---|
212 | |
---|
213 | |
---|
214 | # Detecting if all the tree is to be copied |
---|
215 | if {[lsearch -exact $modificationList "root"] != -1} { |
---|
216 | set DStree $dummyTree |
---|
217 | RefreshFamily "root" |
---|
218 | for {set x 0} {$x < $::NUMBER_OF_VALIDATION } {incr x} { |
---|
219 | CheckValidationStatus "root" |
---|
220 | } |
---|
221 | return |
---|
222 | } |
---|
223 | |
---|
224 | # Applying Differences |
---|
225 | foreach addr $modificationList { |
---|
226 | dTree_copyBranch dummyTree $addr DStree [lrange $addr 0 end-1] |
---|
227 | } |
---|
228 | |
---|
229 | # We need to reconstruct interface (multiple which depends on an unknown list have to be initialized) |
---|
230 | foreach a $modificationList { |
---|
231 | set addr [tree2gui $a] |
---|
232 | RefreshFamily "$addr" |
---|
233 | CheckValidationStatus "$addr" |
---|
234 | } |
---|
235 | |
---|
236 | } |
---|
237 | |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | proc saveProject { where filetype mode } { |
---|
243 | # "where" : self or filename, for save as or save |
---|
244 | # "filetype" : csv and xml |
---|
245 | # "mode" : all , green only |
---|
246 | |
---|
247 | |
---|
248 | global DStree metaTree tmpTree |
---|
249 | global loadApplication loadedProject widgetInfo workingDir log_channel |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | # build saveTree |
---|
254 | set saveTree "" |
---|
255 | dTree_init saveTree |
---|
256 | dTree_addNode saveTree "root" "dataset" |
---|
257 | switch $mode { |
---|
258 | "all" { |
---|
259 | foreach child [dTree_getChildren $tmpTree "root"] { |
---|
260 | dTree_copyBranch tmpTree "root $child" saveTree "root dataset" |
---|
261 | } |
---|
262 | } |
---|
263 | "greenonly" { |
---|
264 | foreach child [dTree_getChildren $tmpTree "root"] { |
---|
265 | dTree_copyBranch DStree "root $child" saveTree "root dataset" |
---|
266 | } |
---|
267 | } |
---|
268 | default { |
---|
269 | error "saveProject mode $mode not understood" |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | switch $where { |
---|
275 | "self" { |
---|
276 | set fileName $loadedProject |
---|
277 | log "Saving Project in file $fileName " |
---|
278 | } |
---|
279 | default { |
---|
280 | set fileName $where |
---|
281 | log "Saving Project As file $fileName " |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | # re-setting the projet |
---|
290 | #newRecentProject $fileName $loadApplication |
---|
291 | set loadedProject $fileName |
---|
292 | updateTitle |
---|
293 | cd [file dirname $loadedProject] |
---|
294 | # If it doesn't exist, we create directory according to file name |
---|
295 | set dirName [file tail [file rootname $fileName]] |
---|
296 | if {$widgetInfo(classApp) != "nanoapp" } { |
---|
297 | if {![file exists $dirName]} { |
---|
298 | file mkdir $dirName |
---|
299 | } |
---|
300 | cd $dirName |
---|
301 | } |
---|
302 | |
---|
303 | dTree_setAttribute metaTree "root meta project name" "value" "[file tail [file rootname $fileName]]" |
---|
304 | dTree_setAttribute metaTree "root meta project address" "value" "[file normalize $fileName]" |
---|
305 | dTree_copyBranch metaTree "root meta" saveTree "root dataset" |
---|
306 | |
---|
307 | set workingDir [pwd] |
---|
308 | |
---|
309 | |
---|
310 | switch $where { |
---|
311 | "self" { |
---|
312 | flush $log_channel |
---|
313 | } |
---|
314 | default { |
---|
315 | startup_log_channel |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | |
---|
320 | # actual saving |
---|
321 | switch $filetype { |
---|
322 | "xml" { |
---|
323 | tree2xml $fileName $saveTree |
---|
324 | } |
---|
325 | "csv" { |
---|
326 | tree2csv $fileName $saveTree |
---|
327 | } |
---|
328 | default { |
---|
329 | error "saveProject filetype $filetype not understood" |
---|
330 | } |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | proc saveDataset {file callingAddress} { |
---|
335 | global metaTree configTree tmpTree XMLtree loadedProject |
---|
336 | global configPath |
---|
337 | fill_metaTree |
---|
338 | set pipeTree "" |
---|
339 | dTree_init pipeTree |
---|
340 | dTree_addNode pipeTree "root" "dataset" |
---|
341 | dTree_setAttribute metaTree "root meta project name" "value" "[file tail [file rootname $loadedProject]]" |
---|
342 | dTree_setAttribute metaTree "root meta project address" "value" "[file normalize $loadedProject]" |
---|
343 | dTree_copyBranch metaTree "root meta" pipeTree "root dataset" |
---|
344 | |
---|
345 | dTree_setAttribute pipeTree "root dataset meta scriptSuccess" "value" 1 |
---|
346 | dTree_setAttribute pipeTree "root dataset meta action callingAddress" "value" $callingAddress |
---|
347 | |
---|
348 | |
---|
349 | # Adding DATA |
---|
350 | #dTree_copyBranch XMLtree "root DATA" pipeTree "root dataset" |
---|
351 | |
---|
352 | |
---|
353 | # Adding extra-informations |
---|
354 | |
---|
355 | dTree_init configTree |
---|
356 | if {[file exists $configPath]} { |
---|
357 | parseFile $configPath configTree "" "DStree" |
---|
358 | dTree_copyBranch configTree "root dataset config" pipeTree "root dataset meta" |
---|
359 | } else { |
---|
360 | close [open $configPath "w"] |
---|
361 | } |
---|
362 | |
---|
363 | |
---|
364 | foreach child [dTree_getChildren $tmpTree "root"] { |
---|
365 | dTree_copyRelevantBranch tmpTree "root $child" pipeTree "root dataset" |
---|
366 | } |
---|
367 | |
---|
368 | tree2xml $file $pipeTree |
---|
369 | } |
---|
370 | |
---|
371 | |
---|
372 | # Copyright CERFACS 2014 |
---|
373 | # |
---|
374 | # antoine.dauptain@cerfacs.fr |
---|
375 | # |
---|
376 | # This software is a computer program whose purpose is to ensure technology |
---|
377 | # transfer between academia and industry. |
---|
378 | # |
---|
379 | # This software is governed by the CeCILL-B license under French law and |
---|
380 | # abiding by the rules of distribution of free software. You can use, |
---|
381 | # modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
382 | # license as circulated by CEA, CNRS and INRIA at the following URL |
---|
383 | # "http://www.cecill.info". |
---|
384 | # |
---|
385 | # As a counterpart to the access to the source code and rights to copy, |
---|
386 | # modify and redistribute granted by the license, users are provided only |
---|
387 | # with a limited warranty and the software's author, the holder of the |
---|
388 | # economic rights, and the successive licensors have only limited |
---|
389 | # liability. |
---|
390 | # |
---|
391 | # In this respect, the user's attention is drawn to the risks associated |
---|
392 | # with loading, using, modifying and/or developing or reproducing the |
---|
393 | # software by the user in light of its specific status of free software, |
---|
394 | # that may mean that it is complicated to manipulate, and that also |
---|
395 | # therefore means that it is reserved for developers and experienced |
---|
396 | # professionals having in-depth computer knowledge. Users are therefore |
---|
397 | # encouraged to load and test the software's suitability as regards their |
---|
398 | # requirements in conditions enabling the security of their systems and/or |
---|
399 | # data to be ensured and, more generally, to use and operate it in the |
---|
400 | # same conditions as regards security. |
---|
401 | # |
---|
402 | # The fact that you are presently reading this means that you have had |
---|
403 | # knowledge of the CeCILL-B license and that you accept its terms. |
---|