1 # Copyright (c) 1999-2014 OPEN CASCADE SAS
3 # This file is part of Open CASCADE Technology software library.
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License version 2.1 as published
7 # by the Free Software Foundation, with special exception defined in the file
8 # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 # distribution for complete text of the license and disclaimer of any warranty.
11 # Alternatively, this file may be used under the terms of Open CASCADE
12 # commercial license or contractual agreement.
15 # Draw standard initialisation
18 #################################################
20 #################################################
25 puts -nonewline "Draw\[$Draw_CmdIndex\]> "
28 set tcl_prompt2 {puts -nonewline "> "}
31 #################################################
32 # the help command in TCL
33 #################################################
36 proc help {{command ""} {helpstring ""} {group "Procedures"}} {
38 global Draw_Helps Draw_Groups
43 foreach h [lsort [array names Draw_Groups]] {
48 foreach f [lsort $Draw_Groups($h)] {
54 for {set j [string length $f]} {$j < 15} {incr j} {
58 if {$i == 4} {set i 0}
62 } elseif {$helpstring == ""} {
66 foreach f [lsort [array names Draw_Helps]] {
67 if {[string match $command $f]} {
69 for {set j [string length $f]} {$j < 15} {incr j} {
72 puts " : $Draw_Helps($f)"
78 lappend Draw_Groups($group) $command
79 set Draw_Helps($command) $helpstring
85 help help {help pattern, or help command string group, to set help} {DRAW General Commands}
86 #################################################
87 # the getsourcefile command in TCL
88 #################################################
91 proc getsourcefile {{command ""}} {
93 global Draw_Helps Draw_Groups Draw_Files
99 foreach h [lsort [array names Draw_Groups]] {
100 lappend out "" "" "$h"
102 foreach f [lsort $Draw_Groups($h)] {
108 # check that the command has its source file set
110 foreach command_that_has_file [array names Draw_Files] {
111 if {($command_that_has_file == $f)} {
112 lappend out [format {%-20s %s} $f $Draw_Files($f)]
119 # getsourcefile fonction
121 foreach f [lsort [array names Draw_Files]] {
122 if {[string match $command $f]} {
123 lappend out [format {%-20s %s} $f $Draw_Files($f)]
128 return [join $out "\n"]
131 help getsourcefile {getsourcefile, or getsourcefile command } {DRAW General Commands}
133 #################################################
135 #################################################
137 #proc gwhatis {aVarName} {
139 # puts -nonewline $aVarName; puts -nonewline " is a "; puts [dtyp ${aVarName}]
145 if {$i == "."} {set i [dname $i]}
148 set __tmp_string "$i is a [dtyp $i]\n"
149 set __out_string "${__out_string}${__tmp_string}"
151 return ${__out_string}
154 help whatis "whatis object1 object2 ..."
156 #################################################
158 #################################################
162 set auto_path [linsert $auto_path 0 $lib]
163 if [file readable $lib/LibraryInit] {
164 puts "Loading $lib/LibraryInit"
165 uplevel "source $lib/LibraryInit"
170 if [file readable $file] {source $file} else {
172 foreach dir $auto_path {
173 if [file readable $dir/$file] {
174 uplevel #0 "source $dir/$file"
181 #################################################
183 #################################################
190 proc directory {{joker *}} {
192 foreach var [info globals $joker] {
193 if [isgdraw $var] {lappend res $var}
198 help directory {directory [pattern], list draw variables} {DRAW Variables management}
200 proc lsd {} { exec ls [datadir] }
204 foreach var [info globals] {
208 lappend schmurtz $var; unset $var
215 #################################################
217 #################################################
219 proc repeat {val script} {
220 for {set i 1} {$i <= $val} {incr i} {uplevel $script}
223 proc do {var start end args} {
224 global errorInfo errorCode
225 if {[llength args] == 1} {
229 set incr [lindex 1 args]
230 set body [lindex 2 args]
233 if {[dval $incr] < 0} {set rel >=} else {set rel <=}
234 for {dset v $start} {[dval v] $rel [dval end]} {dset v [dval v+($incr)]} {
235 set code [catch {uplevel $body} string]
237 return -code error -errorInfo $errorInfo -errorcode $errorCode $string
238 } elseif {$code == 2} {
239 return -code return $string
240 }elseif {$code == 3} {
242 } elseif {$code > 4} {
243 return -code $code $string
248 #################################################
249 # datadir, save, restore
250 #################################################
254 proc datadir {{dir ""}} {
257 if {![file isdirectory $dir]} {
258 error "datadir : $dir is not a directory"
260 set Draw_DataDir $dir
266 help datadir {datadir [directory]} "DRAW Variables management"
268 proc save {name {file ""}} {
269 if {$file == ""} {set file $name}
271 if {![isdraw n]} {error "save : $name is not a Draw variable"}
273 bsave n [file join $Draw_DataDir $file]
274 return [file join $Draw_DataDir $file]
277 help save {save variable [filename]} "DRAW Variables management"
279 proc restore {file {name ""}} {
281 # if name is not given explicitly, use name of the file w/o extension
282 set name [file rootname [file tail $file]]
285 uplevel #0 "brestore [file join $Draw_DataDir $file ] $name"
289 help restore {restore filename [variablename]} "DRAW Variables management"
291 #################################################
293 #################################################
301 #################################################
302 # display and donly with jokers
303 #################################################
308 foreach joker $args {
309 if { $joker == "." } {
311 set joker [lastrep id x y b]
313 foreach var [info globals $joker] {
316 set var [lastrep id x y b]
318 if [isgdraw $var] {lappend res $var}
321 uplevel #0 eval display $res
328 foreach joker $args {
329 if { $joker == "." } {
331 set joker [lastrep id x y b]
333 foreach var [info globals $joker] {
336 set var [lastrep id x y b]
338 if [isgdraw $var] {lappend res $var}
341 uplevel #0 eval donly $res
347 foreach joker $args {
348 if { $joker == "." } {
350 set joker [lastrep id x y b]
352 foreach var [info globals $joker] {
355 set var [lastrep id x y b]
357 if [isgdraw $var] {lappend res $var}
360 uplevel #0 eval donly $res