1
#/*****************************************************************************/
3
# * Elmer, A Finite Element Software for Multiphysical Problems
5
# * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
7
# * This program is free software; you can redistribute it and/or
8
# * modify it under the terms of the GNU General Public License
9
# * as published by the Free Software Foundation; either version 2
10
# * of the License, or (at your option) any later version.
12
# * This program is distributed in the hope that it will be useful,
13
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# * GNU General Public License for more details.
17
# * You should have received a copy of the GNU General Public License
18
# * along with this program (in file fem/GPL-2); if not, write to the
19
# * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
# * Boston, MA 02110-1301, USA.
22
# *****************************************************************************/
24
#***********************************************************************
26
#Module: ecif_tk_coordinateDefPanel.tcl
30
#Author(s): Martti Verho
33
#Abstract: A panel for defining the coordiante system
35
#************************************************************************
38
proc Coordinate::openPanel {} {
39
## This procedure displays the coordiante definition panel
41
global Info Common Model Coordinate oldValues
43
upvar #0 Coordinate theArray
45
set w $Coordinate(winName)
46
set wgeom $Coordinate(winGeometry)
48
set id [winfo atom $w]
49
set Coordinate(winId) $id
51
set Info(thisWindow) $w
53
if { 1 == [Util::checkPanelWindow Coordinate $id $Coordinate(winTitle) $wgeom] } {
57
set Coordinate(dataChanged) 0
58
set Coordinate(dataModified) 0
64
wm title $w $Coordinate(winTitle)
67
Panel::resetFields Coordinate
69
Panel::initFields Coordinate
71
set id $Coordinate(parameterId)
72
DataField::formDataFields Coordinate $Coordinate($id,data)
74
Panel::backupFields Coordinate
76
set Info(coordiantePanelApplied) 0
79
#-We organise data into four frames. These frames are then
80
#-packed below each other and devided internally if needed.
81
frame $w.f1 ;#--Coordinate geometry
82
frame $w.f1.cd ;#--Coordinate related stuff
83
frame $w.f1.cd.1 -bd 2 -relief groove ;#--Coordinate systems
84
frame $w.f1.cd.2 -bd 2 -relief groove ;#--Coordinate mapping
85
frame $w.fB ;#--Buttons
87
# Coordinate system radiobuttons
88
# ==============================
90
set fld COORDINATE_SYSTEM
93
label $m.lf.l -anchor nw -text "Coordinate system: "
95
# Add help event for the label
97
bind $wdg <ButtonPress-3> "Widget::genericButton-3 Coordinate $fld $wdg"
100
radiobutton $m.rf.r1 -text "Cartesian 2D" -value "Cartesian 2D"
101
radiobutton $m.rf.r2 -text "Axi Symmetric" -value "Axi Symmetric"
102
radiobutton $m.rf.r3 -text "Cylindric Symmetric" -value "Cylindric Symmetric"
103
radiobutton $m.rf.r4 -text "Polar 2D" -value "Polar 2D"
104
radiobutton $m.rf.r5 -text "Cartesian 3D" -value "Cartesian 3D"
105
radiobutton $m.rf.r6 -text "Cylindrical" -value "Cylindrical"
106
radiobutton $m.rf.r7 -text "Polar 3D" -value "Polar 3D"
108
set Coordinate(allWidgets,$fld) ""
110
#-Set button variables etc.
111
set coordinate_system_ids {1 2 3 4 5 6 7}
112
set is2D {1 1 1 1 0 0 0}
114
foreach i $coordinate_system_ids is_2d $is2D {
118
# Add help event for the radiobutton, using text as field name!
119
set wfld [DataField::fieldNameSifToGui [$wdg cget -text]]
120
bind $wdg <ButtonPress-3> "Widget::genericButton-3 Coordinate $wfld $wdg"
122
$wdg configure -anchor w -state normal \
123
-variable Coordinate($fld) \
125
-command "Coordinate::setCoordinateStatus" \
126
-selectcolor $Info(select_color)
128
# Disable wrong dimensions
129
if { $Model(GEOMETRY_DIMENSION) == "2D" && !$is_2d ||
130
$Model(GEOMETRY_DIMENSION) == "3D" && $is_2d
132
$wdg configure -state disabled
135
lappend Coordinate(allWidgets,$fld) $wdg
136
bind $wdg <ButtonRelease-1> "Panel::panelDataChanged 1 Coordinate $wdg {%A %K}"
139
#-Labels according to different coordinate types
140
set label_index [Coordinate::getLabelIndex]
141
set labels [lindex $Coordinate(coordinateLabels) $label_index]
143
# Coordinate mapping entries
144
# ==========================
146
set fld COORDINATE_MAPPING
149
label $m.lf.l -anchor nw -text "Coordinate mapping:"
151
# Add help event for the label
153
bind $wdg <ButtonPress-3> "Widget::genericButton-3 Coordinate $fld $wdg"
157
label $m.ef.l1 -text [lindex $labels 0] -width 5
158
entry $m.ef.e1 -textvariable Coordinate(COORDINATE_MAPPING_1) -width 2 -font $Info(entryFont)
160
label $m.ef.l2 -text [lindex $labels 1] -width 5
161
entry $m.ef.e2 -textvariable Coordinate(COORDINATE_MAPPING_2) -width 2 -font $Info(entryFont)
163
#-third entry needs special handling according to the dimension!
164
label $m.ef.l3 -text [lindex $labels 2] -width 5
169
if { $Model(SIMULATION_DIMENSION) != "3D" } {
173
entry $m.ef.e3 -textvariable Coordinate(COORDINATE_MAPPING_3) -width 2 \
174
-bg $bg_color -state $state -font $Info(entryFont)
177
# Store widgets and set bindings
178
set Coordinate(allWidgets,label,$fld) ""
179
set Coordinate(allWidgets,$fld) ""
181
foreach i { 1 2 3 } {
188
lappend Coordinate(allWidgets,label,$fld) $lbl
189
lappend Coordinate(allWidgets,$fld) $wdg
191
set Coordinate(allWidgets,$var) $wdg
193
bind $wdg <KeyRelease> "Panel::panelDataChanged 1 Coordinate $wdg {%A %K}"
194
Widget::setEntryBindings non_standard Coordinate $var $wdg
200
foreach i {0 1 2} n {1 2 3} {
205
set Coordinate($var) [lindex $Coordinate($fld) $i]
207
# NOTE: This is needed because mapping vars are not "normal"
208
set Coordinate($var,err) 0
209
set Coordinate($var,mod) 0
211
set Coordinate($var,prev) $Coordinate($var)
212
set Coordinate($var,err,prev) 0
213
set Coordinate($var,mod,prev) 0
218
set fpx $Info(framePadX1)
219
set fpy $Info(framePadY1)
220
set fpx3 $Info(framePadX3)
221
set fpy3 $Info(framePadY3)
223
#-----Geometry & time widgets packing
224
#pack $w.f1 -side top -anchor nw -fill x -padx $fpx -pady $fpy
225
pack $w.f1 -side top -anchor nw -fill x -padx $fpx3 -pady $fpy3
226
pack $w.f1.cd -side left -anchor nw -fill x -padx $fpx -pady $fpy
232
pack $m -side top -anchor nw -fill x -padx $fpx -pady $fpy
234
pack $m.lf.l -side top -anchor nw
236
foreach i $coordinate_system_ids {
237
pack $m.rf.r$i -side top -anchor nw
242
pack $m -side top -anchor nw -fill x -padx $fpx -pady $fpy
244
pack $m.lf.l -side top -anchor nw
246
pack $m.ef.l1 $m.ef.e1 -side left -anchor nw
247
pack $m.ef.l2 $m.ef.e2 -side left -anchor nw
248
pack $m.ef.l3 $m.ef.e3 -side left -anchor nw
250
#-----Buttons packing widgets packing
251
pack $w.fB -side top -padx $fpx -pady $fpy
252
#-----Apply, Ok and cancel buttons creating and packing
254
set ap $Info(defaultApplyState)
255
set ca $Info(defaultCancelState)
257
set ok_btn [button $w.fB.ok -text OK -command "Coordinate::panelOk $this"]
258
set cn_btn [button $w.fB.cancel -text Cancel -command "Coordinate::panelCancel $this" \
260
set ap_btn [button $w.fB.apply -text Apply -command Coordinate::panelApply \
264
set Coordinate(applyButton) $ap_btn
265
set Coordinate(cancelButton) $cn_btn
267
pack $ok_btn $cn_btn $ap_btn -side left -padx $fpx
276
proc Coordinate::panelSave { {inform_front 1} } {
277
global Info Coordinate Model
279
set panel $Coordinate(parameterType)
282
Panel::backupFields Coordinate
284
set sdim1 $Model(SIMULATION_DIMENSION)
285
Coordinate::applyCoordinateDimension $Coordinate(COORDINATE_SYSTEM)
286
set sdim2 $Model(SIMULATION_DIMENSION)
288
# If simulation dimension was changed
290
if { $sdim1 != "" && $sdim1 != $sdim2 } {
292
StdPanelInit::updateEquationDataAndMasks
293
Equation::setOtherMasks
294
StdPanelInit::createObjectTableMasks
295
Equation::constructProblemMask
297
# Solver variable dofs!
299
Solver::updateVariableDofs modified
304
# Calculator variable dofs!
306
Calculator::updateVariableDofs modified
308
Calculator::okProcPre
309
StdPanelExec::panelSave Calculator
312
Panel::checkMaskedParameters modified
315
#--Set vector data size
316
set Coordinate(COORDINATE_MAPPING,dataSize) 3
318
#--Form parameter data
319
set Coordinate(ids) 1
320
DataField::formNonStandardParameter Coordinate 1 "Coordinates1"
322
#--Write data into model
324
set Model(Front,needsUpdate) 1
327
set Model(Solver,needsUpdate) 1
329
Panel::panelDataChanged 0 Coordinate
330
Panel::panelDataModified 0 Coordinate
331
Util::cpp_exec coordinatePanelOk
335
proc Coordinate::panelOk {w} {
339
if { !$Coordinate(dataChanged) } {
340
Panel::cancel $w; return
344
if { ![Coordinate::checkPanelData] } {
349
Coordinate::panelSave
354
proc Coordinate::panelApply {} {
355
global Info Coordinate
358
if { !$Coordinate(dataChanged) } {
362
if { ![Coordinate::checkPanelData] } {
366
Coordinate::panelSave
368
# This is needed to make mapping fields in
369
# correct status in the panel
370
Coordinate::setCoordinateStatus
374
proc Coordinate::getLabelIndex {} {
377
switch $Coordinate(COORDINATE_SYSTEM) {
379
"Cartesian 3D" {return 0}
381
"Cylindric Symmetric" -
382
"Cylindrical" {return 1}
384
"Polar 3D" {return 2}
387
#-Default if not found!
392
proc Coordinate::updateLabels {} {
395
set index [Coordinate::getLabelIndex]
396
set Coordinate(coordinateLabelIndex) $index
397
set labels [lindex $Coordinate(coordinateLabels) $index]
399
foreach wid $Coordinate(allWidgets,label,COORDINATE_MAPPING) lbl $labels {
402
$wid configure -text $text
406
proc Coordinate::panelCancel {w} {
409
if { ![Panel::verifyCancel Coordinate] } {
413
#---Reset into old values
414
Panel::restoreFields Coordinate
420
# Return 1 = ok, 0 = error
422
proc Coordinate::checkPanelData {} {
423
global Info Coordinate Model
427
# we must have a list of {1 2 3} (in any order)!
431
# Note: We check from end to start to display
432
# the possible same-value error for the smaller
433
# number, because this is sensible for 2D, where
434
# the 3rd coordinate should always be 3 when it is
438
set var COORDINATE_MAPPING_$i
439
set val [string trim $Coordinate($var)]
440
set Coordinate($var) $val
442
# NOTE: This is needed because mapping vars are not "normal"
443
set Coordinate($var,err) 0
444
set Coordinate($var,mod) 0
447
# Illegal value or same values
449
if { ($val < 1 || $val > 3) ||
450
-1 != [lsearch $mappings $val]
452
set Coordinate($var,err) 1
456
Widget::setFieldStatus Coordinate $var
459
lappend mappings $val
464
if { 3 != [llength $mappings] } {
466
set Info(messageIcon) error
467
Message::dispOkMessage {"Incorrect coordinate mapping!"} \
468
"$Info(FRONT_NAME) error message" \
474
set Coordinate(COORDINATE_MAPPING) ""
476
#--If mapping data ok
479
set var COORDINATE_MAPPING_$i
481
# NOTE: This is needed because mapping vars are not "normal"
482
set Coordinate($var,prev) $Coordinate($var)
483
set Coordinate($var,err,prev) $Coordinate($var,err)
484
set Coordinate($var,mod,prev) $Coordinate($var,mod)
486
lappend Coordinate(COORDINATE_MAPPING) $Coordinate($var)
494
# Set coordinate panel widgets state according
495
# to the model geometry dimension
497
proc Coordinate::setCoordinateStatus {} {
500
Coordinate::updateLabels
502
switch $Coordinate(COORDINATE_SYSTEM) {
505
"Axi Symmetric" { set activate_3 0 }
506
"Cylindric Symmetric" -
509
"Polar 3D" { set activate_3 1 }
512
set wdg [lindex $Coordinate(allWidgets,COORDINATE_MAPPING) 2]
515
$wdg configure -state normal -bg white
518
$wdg configure -state disabled -bg gray
520
# Note: We have to force a legal mapping if
521
# dimension is changed, in practice this means
522
# 2D and CylindricSymmetric changes
523
set Coordinate(COORDINATE_MAPPING_3) 3
525
if { $Coordinate(COORDINATE_MAPPING_1) <= \
526
$Coordinate(COORDINATE_MAPPING_2)
528
set Coordinate(COORDINATE_MAPPING_1) 1
529
set Coordinate(COORDINATE_MAPPING_2) 2
532
set Coordinate(COORDINATE_MAPPING_1) 2
533
set Coordinate(COORDINATE_MAPPING_2) 1
540
# Updates system according to the simulation dimension value
542
proc Coordinate::applyCoordinateDimension {coordinate_system} {
543
global Coordinate Model
545
switch $coordinate_system {
548
"Axi Symmetric" { set Model(SIMULATION_DIMENSION) "2D" }
549
"Cylindric Symmetric" -
552
"Polar 3D" { set Model(SIMULATION_DIMENSION) "3D" }
555
set Coordinate(coordinateLabelIndex) [Coordinate::getLabelIndex]
559
# Set default coordinate system
561
proc Coordinate::setDefaultCoordinateSystem {} {
562
global Coordinate Model
564
if { $Model(GEOMETRY_DIMENSION) == "2D" } {
565
set Coordinate(COORDINATE_SYSTEM) "Cartesian 2D"
568
set Coordinate(COORDINATE_SYSTEM) "Cartesian 3D"
571
# Store new value in the parameter
572
set id $Coordinate(parameterId)
573
DataField::setFieldValue Coordinate $id COORDINATE_SYSTEM $Coordinate(COORDINATE_SYSTEM)
575
execNsProc Coordinate panelSave 0
580
# end ecif_tk_coordinateDefPanel.tcl
581
# ********************