1 | # This program is under CECILL_B licence. See footer for details. |
---|
2 | |
---|
3 | |
---|
4 | set load_start_time [clock milliseconds] |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | ############################################################## |
---|
10 | # Handle errors in thecode with a message # |
---|
11 | ############################################################## |
---|
12 | proc popup_error {msg {type exitcontinue} } { |
---|
13 | raise . |
---|
14 | .startup.l configure -text "Problem at startup\nClick here for more informations" |
---|
15 | # Display a pop up for the user |
---|
16 | set win ".popup" |
---|
17 | set ierror 0 |
---|
18 | puts "################" |
---|
19 | if {[winfo exists $win]} { |
---|
20 | destroy $win |
---|
21 | } |
---|
22 | |
---|
23 | switch $type { |
---|
24 | "exitcontinue" { |
---|
25 | puts "POPUP WARNING..." |
---|
26 | puts $msg |
---|
27 | set reply [tk_dialog $win "Error" $msg "" 0 exit continue] |
---|
28 | |
---|
29 | if {$reply == 0} { |
---|
30 | exit |
---|
31 | } |
---|
32 | } |
---|
33 | "strict" { |
---|
34 | puts "POPUP ERROR..." |
---|
35 | puts $msg |
---|
36 | |
---|
37 | tk_messageBox -icon error -message "$msg" |
---|
38 | exit |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | #################################### |
---|
49 | # Read the arguments |
---|
50 | |
---|
51 | ttk::frame .startup |
---|
52 | ttk::label .startup.l -text "Starting up GUI..." |
---|
53 | pack .startup -fill both |
---|
54 | pack .startup.l |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | if {[expr [llength $argv] % 2] != 0} { |
---|
59 | tk_messageBox -icon error -message "Error : arguments ($argv) are invalid." |
---|
60 | exit |
---|
61 | } |
---|
62 | |
---|
63 | foreach { keyword argument } $argv { |
---|
64 | # test keywords |
---|
65 | if {![string match -* $keyword ]} { |
---|
66 | tk_messageBox -icon error -message "Error : keyword must be like -*" |
---|
67 | exit |
---|
68 | } |
---|
69 | |
---|
70 | set varname [ string trim $keyword "-"] |
---|
71 | set listkeyword [list "code" "file" "config" "library" "plugins"] |
---|
72 | if {$varname in $listkeyword} { |
---|
73 | set key_$varname $argument |
---|
74 | } else { |
---|
75 | set listkey [join $listkeyword "\n-"] |
---|
76 | #foreach $item $listkeyword {set listkey "$listkey \n $item"} |
---|
77 | popup_error "Error : keyword -$varname is not recognized. \n Use one from \n \n-$listkey" strict |
---|
78 | exit |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | #################################### |
---|
85 | #Initialize variables |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | global debug loading FunctionUsed solverList loadApplication configTree widgetInfo configPath pluginsPath starpack relaunchCmd |
---|
90 | global logHistory loadedProject metaTree requiredValue additionalWidgets |
---|
91 | global workingDir |
---|
92 | |
---|
93 | |
---|
94 | set workingDir [pwd] |
---|
95 | set configTree "" |
---|
96 | set loadApplication "none" |
---|
97 | set loadedProject "none" |
---|
98 | set abort_cmd "" |
---|
99 | set widgetInfo(SetViewMode) "none" |
---|
100 | set widgetInfo(ReGrid) "no" |
---|
101 | set widgetInfo(nregrid) 0 |
---|
102 | set widgetInfo(form_to_update) "" |
---|
103 | set widgetInfo(tabfocus) "" |
---|
104 | set widgetInfo(fixedview) "1" |
---|
105 | set solverOrder(none) "0" |
---|
106 | set log_channel stdout |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | set debug 1 |
---|
111 | set wrapper 0 |
---|
112 | set TraceProfile 1 |
---|
113 | set tabscroll 1 |
---|
114 | |
---|
115 | set ndim 3 |
---|
116 | set requiredValue "" |
---|
117 | set widgetInfo(classApp) "" |
---|
118 | |
---|
119 | |
---|
120 | #################################### |
---|
121 | # Initialize the pathes |
---|
122 | |
---|
123 | set pathEngine [file normalize [file dirname [info script]]] |
---|
124 | |
---|
125 | if {"vfs" ni [package names]} { |
---|
126 | #The project has NOT been starpacked / classical behavior |
---|
127 | set starpack 0 |
---|
128 | set topPath [file dirname $pathEngine ] |
---|
129 | set relaunchCmd "[file normalize [info nameofexecutable]] [file normalize $argv0] " |
---|
130 | } else { |
---|
131 | # The project has been starpacked |
---|
132 | set starpack 1 |
---|
133 | set topPath [file dirname $starkit::topdir] |
---|
134 | set relaunchCmd [file normalize [info nameofexecutable]] |
---|
135 | } |
---|
136 | |
---|
137 | # Gittag |
---|
138 | set gittag_file [file join $topPath "gittag"] |
---|
139 | if {[file exists $gittag_file ]} { |
---|
140 | set engine_version [read [ open $gittag_file ]] |
---|
141 | } else { |
---|
142 | set engine_version "- No gittag -" |
---|
143 | } |
---|
144 | |
---|
145 | # Config |
---|
146 | #set configPath [file normalize [file join $topPath "myconfig.xml"]] |
---|
147 | if {[info exists key_config]} { |
---|
148 | set configPathtmp [file normalize [file join [pwd] $key_config]] |
---|
149 | if {[file exists $configPathtmp]} { |
---|
150 | set configPath $configPathtmp |
---|
151 | } else { |
---|
152 | file copy -force $configPath $::env(HOME) |
---|
153 | popup_error "The config file provided $configPathtmp does not exists. A template has been copied on your \$HOME." strict |
---|
154 | } |
---|
155 | } else { |
---|
156 | file copy -force $configPath $::env(HOME) |
---|
157 | popup_error "You must specify a config file with -config option. A template has been copied on your \$HOME." strict |
---|
158 | } |
---|
159 | if {![file exists $configPath]} { |
---|
160 | popup_error "Config file $configPath doesn't exist." strict |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | set relaunchCmd "$relaunchCmd -config $configPath" |
---|
165 | |
---|
166 | # library |
---|
167 | set libraryPath [file normalize [file join $topPath "library"]] |
---|
168 | if {[info exists key_library]} { |
---|
169 | set libraryPath [file normalize $key_library] |
---|
170 | set widgetInfo(libraryPath) $libraryPath |
---|
171 | |
---|
172 | } |
---|
173 | if {![file exists $libraryPath]} { |
---|
174 | popup_error "Library folder $libraryPath does not exist." strict |
---|
175 | } |
---|
176 | |
---|
177 | set relaunchCmd "$relaunchCmd -config $configPath -library $libraryPath" |
---|
178 | |
---|
179 | # plugin |
---|
180 | set pluginsPath [file normalize [file join $topPath "library" "DATA" "pluginscripts"]] |
---|
181 | if {[info exists key_plugins]} { |
---|
182 | set pluginsPath [file normalize $key_plugins] |
---|
183 | set widgetInfo(pluginsPath) $pluginsPath |
---|
184 | |
---|
185 | } |
---|
186 | if {![file exists $pluginsPath]} { |
---|
187 | popup_error "Plugins folder $pluginsPath does not exist." strict |
---|
188 | } |
---|
189 | |
---|
190 | set relaunchCmd "$relaunchCmd -config $configPath -plugins $pluginsPath" |
---|
191 | |
---|
192 | |
---|
193 | # XDR |
---|
194 | set XDRpath [file normalize [file join $topPath "XDRpy"]] |
---|
195 | if {![file exists $XDRpath]} { |
---|
196 | popup_error "XDR folder $XDRpath does not exist." strict |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | #################################### |
---|
201 | # Check if XDRpy folder is available in the the PYTHONPATH |
---|
202 | if {"PYTHONPATH" in [array names ::env]} { |
---|
203 | puts "PYTHONPATH content at startup : $::env(PYTHONPATH)" |
---|
204 | puts "XDRpy is expected at : $XDRpath" |
---|
205 | |
---|
206 | } else { |
---|
207 | puts "Warning , PYTHONPATH variable not set, no link possible with XDRpy" |
---|
208 | puts "The XDRpy library is expected to be located at \n: $XDRpath " |
---|
209 | puts "exiting..." |
---|
210 | exit |
---|
211 | } |
---|
212 | |
---|
213 | if { ![string match *XDRpy* $::env(PYTHONPATH)] } { |
---|
214 | puts "Warning , no pattern XDRpy found in PYTHONPATH" |
---|
215 | puts "The XDRpy library is expected to be located at : $XDRpath" |
---|
216 | puts "exiting..." |
---|
217 | exit |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | #################################### |
---|
228 | # Load the procedures |
---|
229 | |
---|
230 | |
---|
231 | if {$wrapper==1} { |
---|
232 | source [file join $pathEngine "wrapper.tcl"] |
---|
233 | } else { |
---|
234 | source [file join $pathEngine "unwrapped.tcl"] |
---|
235 | } |
---|
236 | |
---|
237 | source [file join $pathEngine "functions.tcl"] |
---|
238 | source [file join $pathEngine "functions_theme.tcl"] |
---|
239 | source [file join $pathEngine "functions_help.tcl"] |
---|
240 | source [file join $pathEngine "dTree.tcl"] |
---|
241 | source [file join $pathEngine "test_vartypes.tcl"] |
---|
242 | source [file join $pathEngine "create_gui.tcl"] |
---|
243 | source [file join $pathEngine "declare_icons.tcl"] |
---|
244 | source [file join $pathEngine "declare_faq.tcl"] |
---|
245 | source [file join $pathEngine "XMLparser.tcl"] |
---|
246 | source [file join $pathEngine "dTreeBrowser.tcl"] |
---|
247 | source [file join $pathEngine "treeAnalyser.tcl"] |
---|
248 | source [file join $pathEngine "create_entry.tcl"] |
---|
249 | source [file join $pathEngine "create_cluster.tcl"] |
---|
250 | source [file join $pathEngine "create_comment.tcl"] |
---|
251 | source [file join $pathEngine "create_comparator.tcl"] |
---|
252 | source [file join $pathEngine "create_action.tcl"] |
---|
253 | source [file join $pathEngine "create_choice.tcl"] |
---|
254 | source [file join $pathEngine "create_dynlist.tcl"] |
---|
255 | source [file join $pathEngine "create_graph.tcl"] |
---|
256 | source [file join $pathEngine "create_glance.tcl"] |
---|
257 | source [file join $pathEngine "create_info.tcl"] |
---|
258 | source [file join $pathEngine "create_emptyNode.tcl"] |
---|
259 | source [file join $pathEngine "create_multiple.tcl"] |
---|
260 | source [file join $pathEngine "create_metaTree.tcl"] |
---|
261 | source [file join $pathEngine "create_switch.tcl"] |
---|
262 | source [file join $pathEngine "create_browser.tcl"] |
---|
263 | source [file join $pathEngine "create_selection.tcl"] |
---|
264 | source [file join $pathEngine "create_tabs.tcl"] |
---|
265 | source [file join $pathEngine "create_main.tcl"] |
---|
266 | source [file join $pathEngine "create_modelframe.tcl"] |
---|
267 | source [file join $pathEngine "create_modelxor_light.tcl"] |
---|
268 | source [file join $pathEngine "create_solverframe.tcl"] |
---|
269 | source [file join $pathEngine "create_scrollform.tcl"] |
---|
270 | source [file join $pathEngine "create_switchform.tcl"] |
---|
271 | source [file join $pathEngine "create_status.tcl"] |
---|
272 | source [file join $pathEngine "create_timeline.tcl"] |
---|
273 | source [file join $pathEngine "create_window.tcl"] |
---|
274 | source [file join $pathEngine "create_viewer.tcl"] |
---|
275 | source [file join $pathEngine "color_utilities.tcl"] |
---|
276 | source [file join $pathEngine "metaWidget_functions.tcl"] |
---|
277 | source [file join $pathEngine "config.tcl"] |
---|
278 | source [file join $pathEngine "openpipe.tcl"] |
---|
279 | source [file join $pathEngine "recentProjects.tcl"] |
---|
280 | source [file join $pathEngine "genPyFromXMLtree.tcl"] |
---|
281 | source [file join $pathEngine "grapher_utilities.tcl"] |
---|
282 | source [file join $pathEngine "smartpacker.tcl"] |
---|
283 | source [file join $pathEngine "load_save.tcl"] |
---|
284 | |
---|
285 | |
---|
286 | if {[info exists additionalWidgets] == 0} { |
---|
287 | set additionalWidgets "" |
---|
288 | } |
---|
289 | |
---|
290 | foreach widget $additionalWidgets { |
---|
291 | source [file join $pathEngine "SOURCES_PRIV" create_$widget.tcl] |
---|
292 | } |
---|
293 | |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | .startup.l configure -image icon_gui_small -compound top |
---|
299 | |
---|
300 | |
---|
301 | #Build application list, then check |
---|
302 | set applicationList [glob -tails -type d -directory $libraryPath *] |
---|
303 | lremove applicationList DATA |
---|
304 | set widgetInfo(applicationList) $applicationList |
---|
305 | if {[info exists key_code]} { |
---|
306 | if {[lsearch $applicationList $key_code] < 0} { |
---|
307 | set listappl [join $applicationList "\n"] |
---|
308 | popup_error "Application $key_code was not found in the library.\n\n Applications available are:\n$listappl." strict |
---|
309 | } |
---|
310 | set loadApplication $key_code |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | |
---|
315 | if {[info exists key_file]} { |
---|
316 | set fileerror 0 |
---|
317 | if {[file extension $key_file] != ".xml"} { |
---|
318 | set fileerror "File $key_file is not an XML file." |
---|
319 | } |
---|
320 | if {![file exists $key_file]} { |
---|
321 | set fileerror "File $key_file was not found." |
---|
322 | } |
---|
323 | |
---|
324 | if {$fileerror != 0 } { |
---|
325 | set dir [file dirname $key_file] |
---|
326 | |
---|
327 | set listfile [join [glob -directory $dir "*.xml"] "\n"] |
---|
328 | |
---|
329 | set fileerror "$fileerror \n\n Other xml files in this directory are \n$listfile." |
---|
330 | |
---|
331 | popup_error $fileerror strict |
---|
332 | exit |
---|
333 | } |
---|
334 | set loadedProject [file normalize $key_file] |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | # declare fonts (see function.tcl) |
---|
339 | font_create |
---|
340 | ThemeUpdate [ getConfig "config gui appearance theme"] |
---|
341 | |
---|
342 | |
---|
343 | |
---|
344 | ############################ |
---|
345 | # Creating the Application # |
---|
346 | ############################ |
---|
347 | |
---|
348 | |
---|
349 | if {$loadApplication == "none"} { |
---|
350 | main_create |
---|
351 | |
---|
352 | } else { |
---|
353 | # make sure default solver is in solverList |
---|
354 | if {[lsearch $applicationList $loadApplication] < 0} { |
---|
355 | tk_messageBox -icon error -message "Application $loadApplication was not found in the library.\nApplications available : [split $applicationList {, }]" |
---|
356 | exit |
---|
357 | } |
---|
358 | |
---|
359 | set modelPath [file normalize [file join $libraryPath $loadApplication XML]] |
---|
360 | set codesPath [file join $libraryPath $loadApplication scripts] |
---|
361 | set dataPath [file join $libraryPath] |
---|
362 | |
---|
363 | set startNode "" |
---|
364 | set XMLtree "" |
---|
365 | set tmpTree "" |
---|
366 | set DStree "" |
---|
367 | set metaTree "" |
---|
368 | |
---|
369 | |
---|
370 | global DStree |
---|
371 | global XMLtree |
---|
372 | global tmpTree |
---|
373 | global metaTree |
---|
374 | |
---|
375 | |
---|
376 | |
---|
377 | dTree_init DStree |
---|
378 | dTree_init tmpTree |
---|
379 | |
---|
380 | fill_metaTree |
---|
381 | |
---|
382 | |
---|
383 | set browsemode [getConfig "config gui paths"] |
---|
384 | if { $browsemode == "constant"} { |
---|
385 | set workingDir [getConfig "config gui paths constant workingDir"] |
---|
386 | if {![file exists $workingDir]} { |
---|
387 | popup_error "Constant working dir $workingDir doest not exists\nTo fix the pb, edit your file $configPath \n with a valid path" strict |
---|
388 | } |
---|
389 | } else { |
---|
390 | set workingDir [pwd] |
---|
391 | } |
---|
392 | |
---|
393 | cd $workingDir |
---|
394 | smartpacker_getconfig |
---|
395 | |
---|
396 | |
---|
397 | |
---|
398 | OpenTeaXML2tree XMLtree $modelPath $dataPath |
---|
399 | |
---|
400 | |
---|
401 | set nodes_to_skip "" |
---|
402 | # Get the list of nodes to skip |
---|
403 | set filename [file join $modelPath "nodes_to_skip" ] |
---|
404 | if [file exists $filename ] { |
---|
405 | set chout [ open $filename r ] |
---|
406 | set content [ split [ read $chout] "\n" ] |
---|
407 | close $chout |
---|
408 | foreach line $content { |
---|
409 | if {$line != "" && [string index $line 0] != "#"} { |
---|
410 | lappend nodes_to_skip $line |
---|
411 | } |
---|
412 | } |
---|
413 | } |
---|
414 | |
---|
415 | # Get the list of solvers to add |
---|
416 | set solvers_to_add "" |
---|
417 | set filename [file join $modelPath "solvers_to_add" ] |
---|
418 | if [file exists $filename ] { |
---|
419 | set chout [ open $filename r ] |
---|
420 | set content [ split [ read $chout] "\n" ] |
---|
421 | close $chout |
---|
422 | foreach line $content { |
---|
423 | if {$line != "" && [string index $line 0] != "#"} { |
---|
424 | lappend solvers_to_add $line |
---|
425 | } |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | analyseModelTree XMLtree $nodes_to_skip $solvers_to_add |
---|
430 | |
---|
431 | if {[dTree_attrExists $XMLtree "root $loadApplication" "class"]} { |
---|
432 | set widgetInfo(classApp) [dTree_getAttribute $XMLtree "root $loadApplication" "class"] |
---|
433 | } |
---|
434 | log_create |
---|
435 | Start_think "" |
---|
436 | createWin . |
---|
437 | |
---|
438 | ttk::frame .main |
---|
439 | pack .main -side left -fill both -expand true |
---|
440 | set gui_win [gui_create -path ".main" -solver $loadApplication] |
---|
441 | wm title . " [string toupper $loadApplication]" |
---|
442 | |
---|
443 | updateTitle |
---|
444 | |
---|
445 | |
---|
446 | RefreshFamily "root" |
---|
447 | update |
---|
448 | |
---|
449 | smartpacker_initialize_gui $loadedProject |
---|
450 | |
---|
451 | |
---|
452 | bind . <Escape> {+Stop_think abort} |
---|
453 | bind . <Control-s> {Save_XML_File "save"} |
---|
454 | bind . <Control-h> {Window_help_generator} |
---|
455 | bind . <Control-q> {quit_gui} |
---|
456 | |
---|
457 | |
---|
458 | smartpacker_focus_correction |
---|
459 | |
---|
460 | |
---|
461 | set load_stop_time [clock milliseconds] |
---|
462 | set msgloadtime "Startup time : [format "%0.3f" [expr { ($load_stop_time - $load_start_time)*0.001 }]] s." |
---|
463 | log $msgloadtime |
---|
464 | |
---|
465 | Stop_think normal |
---|
466 | } |
---|
467 | |
---|
468 | |
---|
469 | destroy .startup |
---|
470 | |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | |
---|
475 | # Copyright CERFACS 2014 |
---|
476 | # |
---|
477 | # antoine.dauptain@cerfacs.fr |
---|
478 | # |
---|
479 | # This software is a computer program whose purpose is to ensure technology |
---|
480 | # transfer between academia and industry. |
---|
481 | # |
---|
482 | # This software is governed by the CeCILL-B license under French law and |
---|
483 | # abiding by the rules of distribution of free software. You can use, |
---|
484 | # modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
485 | # license as circulated by CEA, CNRS and INRIA at the following URL |
---|
486 | # "http://www.cecill.info". |
---|
487 | # |
---|
488 | # As a counterpart to the access to the source code and rights to copy, |
---|
489 | # modify and redistribute granted by the license, users are provided only |
---|
490 | # with a limited warranty and the software's author, the holder of the |
---|
491 | # economic rights, and the successive licensors have only limited |
---|
492 | # liability. |
---|
493 | # |
---|
494 | # In this respect, the user's attention is drawn to the risks associated |
---|
495 | # with loading, using, modifying and/or developing or reproducing the |
---|
496 | # software by the user in light of its specific status of free software, |
---|
497 | # that may mean that it is complicated to manipulate, and that also |
---|
498 | # therefore means that it is reserved for developers and experienced |
---|
499 | # professionals having in-depth computer knowledge. Users are therefore |
---|
500 | # encouraged to load and test the software's suitability as regards their |
---|
501 | # requirements in conditions enabling the security of their systems and/or |
---|
502 | # data to be ensured and, more generally, to use and operate it in the |
---|
503 | # same conditions as regards security. |
---|
504 | # |
---|
505 | # The fact that you are presently reading this means that you have had |
---|
506 | # knowledge of the CeCILL-B license and that you accept its terms. |
---|