1 ###### EOpenplot.tcl ############################################
3 # Copyright (C) 1998 William F. Schelter
4 # For distribution under GNU public License. See COPYING.tcl
6 # Time-stamp: "2024-03-20 15:13:35 villate"
8 #################################################################
10 #-----------------------------------------------------------------
12 # eval_openplot -- invoke OPENPLOT on the substring of Window given
13 # by thisRange, and substitute the result into resultRange, if the
14 # latter is not the empty list. If it is, then the window is placed
15 # on the next line from this command.
20 #----------------------------------------------------------------
23 proc eval_openplot
{ program w thisRange resultRange
} {
24 set tem
[eval $w get
$thisRange]
25 lappend tem
-windowname $name
26 foreach v
[getDimensions
$w $name] { lappend tem
$v }
27 set allowed
"plot2d plotdf plot3d scene"
29 if { [lsearch $allowed $f] >= 0 } {
30 $f {*}[lrange $tem 1 end
]
31 ShowPlotWindow
$w $name $thisRange $resultRange $desired
33 error [concat "$f" [mc
"not allowed, only"] "{$allowed}"]}
34 set name
[plotWindowName
$w $f]
35 set desired
[setDesiredDims
$w $name $thisRange ]
38 #-----------------------------------------------------------------
40 # plotWindowName -- checks preferences to see if separate or multiple
41 # or nontoplevel windows are desired, and chooses a name accordingly.
42 # in the first two cases it also assures that the toplevel window exists.
44 # Results: window name
46 # Side Effects: possibly make a new toplevel window.
48 #----------------------------------------------------------------
50 proc plotWindowName
{ w command
} {
51 upvar #0 maxima_default(plotwindow) plot
52 upvar #0 maxima_priv(plot,count) count
55 if { "$command" == "scene" } {
57 if { [winfo exists
$name ] } {
58 after cancel PlayStep
$name.plot.menubar.play
59 vtkCommand DeleteAllObjects
64 if { "[info proc setIcon]" != "" } {
65 after 1000 setIcon
$name
68 if { ![info exists plot
] ||
"$plot" == "embedded" } {
70 if { ![info exists counter
] } {set counter
0}
71 return $w.plot
[incr counter
]
74 if { "$plot" == "multiple" } {
75 if { ![info exists count
] } {
82 if { ![winfo exists
$name ] } {
84 set h
[expr {round
([winfo screenheight
$name]*.6) }]
85 set wid
[expr round
($h * 1.2) ]
86 set r1
[expr {round
(10+rand
()*30)} ]
87 set r2
[expr {round
(10+rand
()*30)} ]
88 wm geometry
$name ${wid
}x
${h
}+${r1
}+${r2
}
89 if { "[info proc setIcon]" != "" } {
90 after 1000 setIcon
$name
99 proc whereToPutPlot
{ w thisRange resultRange
} {
100 if { "$resultRange" != "" } {
101 eval $w delete
$resultRange
102 set at
[lindex $resultRange 0]
103 $w insert
$at " " { Tresult
}
104 set at
[$w index
"$at + 1char"]
106 set at
"[lindex $thisRange 1] lineend + 1 chars"
112 proc setDesiredDims
{ w name range
} {
113 #puts "setDesiredDims $w $name $range"
114 foreach v
[getTagsMatching
$w "^(width|height):" $range] {
116 lappend ans
[lindex $tem 0]Desired
[lindex $tem 1]
118 if { [info exists ans
] } {
125 proc getDimensions
{ w name
} {
126 # puts "getDimensions $w $name"
127 set parent
[winfo parent
$w]
129 catch { set scrollwidth
[ [winfo parent
$parent].scroll cget
-scrollwidth] }
130 set width
[winfo width
$w]
131 set height
[winfo height
$w]
132 #set width [getPercentDim [oget $name widthDesired] width $w]
133 catch {set width
[getPercentDim
[oget
$name widthDesired
] width
$w] }
134 catch {set height
[getPercentDim
[oget
$name heightDesired
] height
$w] }
136 set width
[expr {round
($width-4) }]
137 set height
[expr {round
($height-4)}]
138 #puts "using width,height=$width,$height"
141 set width
[expr {[oget
$parent width
] - 2*$scrollwidth}]
142 set height
[expr {round
(.85*[oget
$parent height
])}]
144 return " -width $width -height $height"
148 proc insertResult_openplot
{w args
} {
149 puts "insert=[$w index insert]"
152 proc ShowPlotWindow
{ w name thisRange resultRange desired
} {
153 if { "[winfo toplevel $w]" != "[winfo toplevel $name]" } {
154 $name config
-relief sunken
-borderwidth 2
155 pack $name -expand 1 -fill both
156 raise [winfo toplevel $name ]
159 oarraySet
$name $desired
160 set at
[whereToPutPlot
$w $thisRange $resultRange]
161 set col
[lindex [split $at .
] 1]
164 $w insert
$at "\n \n" "$name"
165 set at
[$w index
"$at +1char"]
167 # compute where we will try to display.
168 # try to leave top of window where it is, but if not
169 # scroll lines up just the amount necessary to make the
172 set h1
[winfo height
$w]
173 set h2
[oget
$name height
]
174 set begin
[$w index
@0,0]
176 set dl
[$w dlineinfo
$ind]
177 set y0
[lindex $dl 1]
180 while { [$w compare
$begin <= $ind] } {
181 set dl
[$w dlineinfo
$ind]
183 if { "$dl" == "" } { break }
184 if { $y0 - [lindex $dl 1] + $h2 +5 < $h1 } {
186 set ind
[$w index
"$ind - 1 line" ]
193 bind $name <Destroy
> "catch {$w yview [$w index @0,0] } ; eval $w delete \[$w tag nextrange $name 0.0 \]"
195 if { "$prev" != "" } { set ind
$prev }
196 $w insert
$at " " "$name center"
197 $w window create
$at+1char
-window $name
198 $w tag add
"center $name" $at "$at+2char"
201 # somehow the single button click gets run positioning the cursor
203 after 1 $w mark
set insert
[$w index insert
]
207 ## endsource eopenplot.tcl