source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/genPyFromXMLtree.tcl @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 6.1 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3proc genPyFromXMLtree {} {
4    global XMLtree loadApplication
5   
6    if {[catch {
7       genPyOutput "from XDR import *\n"
8       genPyOutput "###########################"
9       genPyOutput "# INITIALIZATION\n"
10       genPyOutput "init()\n"
11       
12       genPyFromNode "root $loadApplication" "" "0 0" ""
13       
14       genPyOutput "\n\n#########################\n# FINISHING"
15       genPyOutput "finish()"
16    } err err2]} { 
17        genPyOutput "[lindex $err2 7]"
18    }
19}
20
21proc genPyOutput {txt} {
22    puts $txt
23} 
24
25proc genPyConstructPattern {node scheme multiples} {
26    global XMLtree
27   
28    set l [llength $scheme]   
29    # Activating one part at a time on the address descriptor until descriptor is unique
30    for {set i 1} {$i < $l} {incr i} {
31       
32        # Pattern construction
33        set pattern ""
34        for {set j 0} {$j < $l} {incr j} {
35            if {[lindex $scheme $j] == 1} {
36                lappend pattern [lindex $node $j]
37            }
38        }
39        set pattern [join $pattern " "]
40       
41        if {[llength [dTree_searchNode $XMLtree $pattern]] == 1} {
42            break
43        }
44        set nextId [expr {$l-$i-1}]
45        if {[lsearch $multiples $nextId] > -1} {
46            lset scheme $nextId 0
47        } else {
48            lset scheme $nextId 1
49        }
50    }
51    set pythonArgs ""   
52    foreach elt [split $pattern " "] {
53        # If multiple , qqch !
54        set pythonArgs [lreplace $pythonArgs 0 -1 "\"$elt\""]
55    }
56   
57    foreach mul $multiples {
58        lappend pythonArgs "multiple${mul}"
59    }
60    return $pythonArgs
61}
62
63proc genPyFromNode {node indent mandatory multiples} {
64    global XMLtree
65   
66    set newIndent ""
67    set childNotDone 1
68   
69    #set attrs [dTree_getAttributes $XMLtree $node]
70    if {[catch {set type [dTree_getAttribute $XMLtree $node "nodeType"]} err]} {
71        log $err
72        set type "undefined" 
73    }
74   
75    set name [lindex $node end]
76   
77   
78   
79    # Dealing with existifs
80    if {[dTree_attrExists $XMLtree $node "existif"]} {
81        set scheme $mandatory
82        lset scheme end 1       
83        set pythonArgs [genPyConstructPattern $node $scheme $multiples]       
84        genPyOutput "${indent}if nodeExists([join $pythonArgs {,}]):"
85        genPyOutput "${indent}   pass"
86        set indent "${indent}   "
87    }
88   
89    #genPyOutput "${indent}[lindex $node end] is a $type"
90   
91    switch $type {
92        tab {
93            genPyOutput "\n\n${indent}###########################"
94            genPyOutput "${indent}# Tab : $name "
95            genPyOutput "${indent}##################\n"           
96        }
97       
98        model {
99            genPyOutput "${indent}# Model : $name"
100        }
101       
102       
103        choice -
104        param {
105            # Construct list of params
106            set scheme $mandatory
107            lset scheme end 1
108#            genPyOutput "---------  $node"
109#            genPyOutput "---------  $scheme"
110            set pythonArgs [genPyConstructPattern $node $scheme $multiples]                       
111                       
112            genPyOutput "${indent}print getValue([join $pythonArgs {,}])"
113        }
114       
115        xor {
116            set childNotDone 0
117            set scheme $mandatory
118            lset scheme end 1           
119            set pythonArgs [genPyConstructPattern $node $scheme $multiples]           
120            foreach child [dTree_getChildren $XMLtree $node] {
121                genPyOutput "${indent}if getValue([join $pythonArgs {,}]) == \"$child\" :\n${indent}   pass"
122                genPyFromNode "$node $child" "${indent}   " "$mandatory 0" "$multiples"
123            }           
124        }
125       
126        multiple {
127            set scheme $mandatory
128            lset scheme end 1           
129            set pythonArgs [genPyConstructPattern $node $scheme $multiples]
130            genPyOutput "${indent}for multiple[llength $node] in getChildrenName([join $pythonArgs {,}]):"           
131            set newIndent "   "
132            lappend multiples [llength $node]
133
134        }
135       
136        item {
137            # Do nothing
138        }
139        action -
140        solver -
141        option -
142        info {
143            # Do nothing
144        }
145       
146       
147    }
148    if {$childNotDone} {
149        foreach child [dTree_getChildren $XMLtree $node] {
150            genPyFromNode "$node $child" "${indent}$newIndent" "$mandatory 0" "$multiples"
151        }
152    }
153}
154
155
156#  Copyright CERFACS 2014
157#   
158#  antoine.dauptain@cerfacs.fr
159#   
160#  This software is a computer program whose purpose is to ensure technology
161#  transfer between academia and industry.
162#   
163#  This software is governed by the CeCILL-B license under French law and
164#  abiding by the rules of distribution of free software.  You can  use,
165#  modify and/ or redistribute the software under the terms of the CeCILL-B
166#  license as circulated by CEA, CNRS and INRIA at the following URL
167#  "http://www.cecill.info".
168#   
169#  As a counterpart to the access to the source code and  rights to copy,
170#  modify and redistribute granted by the license, users are provided only
171#  with a limited warranty  and the software's author,  the holder of the
172#  economic rights,  and the successive licensors  have only  limited
173#  liability.
174#   
175#  In this respect, the user's attention is drawn to the risks associated
176#  with loading,  using,  modifying and/or developing or reproducing the
177#  software by the user in light of its specific status of free software,
178#  that may mean  that it is complicated to manipulate,  and  that  also
179#  therefore means  that it is reserved for developers  and  experienced
180#  professionals having in-depth computer knowledge. Users are therefore
181#  encouraged to load and test the software's suitability as regards their
182#  requirements in conditions enabling the security of their systems and/or
183#  data to be ensured and,  more generally, to use and operate it in the
184#  same conditions as regards security.
185#   
186#  The fact that you are presently reading this means that you have had
187#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.