~ubuntu-branches/ubuntu/maverick/elmerfem/maverick

« back to all changes in this revision

Viewing changes to front/src/tcl/ecif_tk_coordinatePanel.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2009-04-08 16:58:46 UTC
  • Revision ID: james.westby@ubuntu.com-20090408165846-qydtxka1cvrjw2ix
Tags: upstream-5.5.0.svn.4096.dfsg
ImportĀ upstreamĀ versionĀ 5.5.0.svn.4096.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#/*****************************************************************************/
 
2
# *
 
3
# *  Elmer, A Finite Element Software for Multiphysical Problems
 
4
# *
 
5
# *  Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
 
6
# * 
 
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.
 
11
# * 
 
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.
 
16
# *
 
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.
 
21
# *
 
22
# *****************************************************************************/
 
23
  
 
24
#***********************************************************************
 
25
#Program:   ELMER Front 
 
26
#Module:    ecif_tk_coordinateDefPanel.tcl
 
27
#Language:  Tcl
 
28
#Date:      16.11.98
 
29
#Version:   1.00
 
30
#Author(s): Martti Verho
 
31
#Revisions: 
 
32
#
 
33
#Abstract:  A panel for defining the coordiante system
 
34
#
 
35
#************************************************************************
 
36
 
 
37
 
 
38
proc Coordinate::openPanel {} {
 
39
  ## This procedure displays the coordiante definition panel
 
40
  ## Global variables
 
41
  global Info Common Model Coordinate oldValues
 
42
  global platform
 
43
  upvar #0 Coordinate theArray
 
44
 
 
45
  set w $Coordinate(winName)
 
46
  set wgeom $Coordinate(winGeometry)
 
47
 
 
48
  set id [winfo atom $w]
 
49
  set Coordinate(winId) $id
 
50
 
 
51
  set Info(thisWindow) $w
 
52
 
 
53
  if { 1 == [Util::checkPanelWindow Coordinate $id $Coordinate(winTitle) $wgeom] } {
 
54
    return
 
55
  }  
 
56
 
 
57
  set Coordinate(dataChanged) 0
 
58
  set Coordinate(dataModified) 0
 
59
 
 
60
  set this $w
 
61
  toplevel $w
 
62
  focus $w
 
63
 
 
64
  wm title $w $Coordinate(winTitle)
 
65
  wm geometry $w $wgeom 
 
66
 
 
67
  Panel::resetFields Coordinate
 
68
 
 
69
  Panel::initFields Coordinate
 
70
 
 
71
  set id $Coordinate(parameterId)
 
72
  DataField::formDataFields Coordinate $Coordinate($id,data)
 
73
 
 
74
  Panel::backupFields Coordinate
 
75
  
 
76
  set Info(coordiantePanelApplied) 0
 
77
 
 
78
  #-----WIDGET CREATION
 
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
 
86
  
 
87
  # Coordinate system radiobuttons
 
88
  # ==============================
 
89
  #
 
90
  set fld COORDINATE_SYSTEM
 
91
  set m $w.f1.cd.1
 
92
  frame $m.lf
 
93
  label $m.lf.l  -anchor nw -text "Coordinate system: "
 
94
 
 
95
  # Add help event for the label
 
96
  set wdg $m.lf.l
 
97
  bind $wdg <ButtonPress-3> "Widget::genericButton-3 Coordinate $fld $wdg"
 
98
 
 
99
  frame $m.rf
 
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" 
 
107
  
 
108
  set Coordinate(allWidgets,$fld) ""
 
109
 
 
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}
 
113
 
 
114
  foreach i $coordinate_system_ids is_2d $is2D {
 
115
 
 
116
    set wdg $m.rf.r$i
 
117
 
 
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"
 
121
 
 
122
    $wdg configure -anchor w -state normal \
 
123
                   -variable Coordinate($fld) \
 
124
                   -indicatoron 1 \
 
125
                   -command "Coordinate::setCoordinateStatus" \
 
126
                   -selectcolor $Info(select_color)
 
127
 
 
128
    # Disable wrong dimensions
 
129
    if { $Model(GEOMETRY_DIMENSION) == "2D" && !$is_2d ||
 
130
         $Model(GEOMETRY_DIMENSION) == "3D" && $is_2d  
 
131
       } {
 
132
        $wdg configure -state disabled
 
133
    }
 
134
    
 
135
    lappend Coordinate(allWidgets,$fld) $wdg
 
136
    bind $wdg <ButtonRelease-1> "Panel::panelDataChanged 1 Coordinate $wdg {%A %K}"
 
137
  }
 
138
 
 
139
  #-Labels according to different coordinate types
 
140
  set label_index [Coordinate::getLabelIndex]
 
141
  set labels [lindex $Coordinate(coordinateLabels) $label_index]
 
142
 
 
143
  # Coordinate mapping entries
 
144
  # ==========================
 
145
  #
 
146
  set fld COORDINATE_MAPPING
 
147
  set m $w.f1.cd.2
 
148
  frame $m.lf
 
149
  label $m.lf.l  -anchor nw -text "Coordinate mapping:"
 
150
 
 
151
  # Add help event for the label
 
152
  set wdg $m.lf.l
 
153
  bind $wdg <ButtonPress-3> "Widget::genericButton-3 Coordinate $fld $wdg"
 
154
 
 
155
  frame $m.ef
 
156
 
 
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)
 
159
 
 
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)
 
162
 
 
163
  #-third entry needs special handling according to the dimension!
 
164
  label $m.ef.l3  -text [lindex $labels 2] -width 5
 
165
 
 
166
  set state normal
 
167
  set bg_color white
 
168
 
 
169
  if { $Model(SIMULATION_DIMENSION) != "3D" } {
 
170
    set state disabled
 
171
    set bg_color gray
 
172
  }
 
173
  entry $m.ef.e3  -textvariable Coordinate(COORDINATE_MAPPING_3) -width 2 \
 
174
                  -bg $bg_color -state $state -font $Info(entryFont)
 
175
 
 
176
 
 
177
  # Store widgets and set bindings
 
178
  set Coordinate(allWidgets,label,$fld) ""
 
179
  set Coordinate(allWidgets,$fld) ""
 
180
 
 
181
  foreach i { 1 2 3 } {
 
182
    set lbl $m.ef.l$i
 
183
    set wdg $m.ef.e$i
 
184
    
 
185
    set var $fld
 
186
    append var "_$i"
 
187
 
 
188
    lappend Coordinate(allWidgets,label,$fld) $lbl
 
189
    lappend Coordinate(allWidgets,$fld) $wdg
 
190
 
 
191
    set Coordinate(allWidgets,$var) $wdg
 
192
 
 
193
    bind $wdg <KeyRelease> "Panel::panelDataChanged 1 Coordinate $wdg {%A %K}"
 
194
    Widget::setEntryBindings non_standard Coordinate $var $wdg
 
195
  }
 
196
 
 
197
 
 
198
  # Set values
 
199
  #
 
200
  foreach i {0 1 2} n {1 2 3} {
 
201
 
 
202
    set var $fld
 
203
    append var "_$n"
 
204
    
 
205
    set Coordinate($var) [lindex $Coordinate($fld) $i]
 
206
 
 
207
    # NOTE: This is needed because mapping vars are not "normal"
 
208
    set Coordinate($var,err) 0
 
209
    set Coordinate($var,mod) 0
 
210
 
 
211
    set Coordinate($var,prev) $Coordinate($var)
 
212
    set Coordinate($var,err,prev) 0
 
213
    set Coordinate($var,mod,prev) 0
 
214
  }
 
215
  
 
216
 
 
217
  #---WIDGET PACKING
 
218
  set fpx $Info(framePadX1)
 
219
  set fpy $Info(framePadY1)
 
220
  set fpx3 $Info(framePadX3)
 
221
  set fpy3 $Info(framePadY3)
 
222
 
 
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
 
227
 
 
228
  #---Coordinates
 
229
 
 
230
  # Coordinate systems
 
231
  set m $w.f1.cd.1
 
232
  pack $m -side top  -anchor nw -fill x -padx $fpx -pady $fpy
 
233
  pack $m.lf -side top  
 
234
  pack $m.lf.l -side top -anchor nw  
 
235
  pack $m.rf -side top  
 
236
  foreach i $coordinate_system_ids {
 
237
    pack $m.rf.r$i -side top -anchor nw
 
238
  }  
 
239
 
 
240
  # Mapping
 
241
  set m $w.f1.cd.2
 
242
  pack $m -side top  -anchor nw -fill x -padx $fpx -pady $fpy
 
243
  pack $m.lf -side top  
 
244
  pack $m.lf.l -side top -anchor nw  
 
245
  pack $m.ef -side top  
 
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  
 
249
 
 
250
  #-----Buttons packing widgets packing
 
251
  pack $w.fB -side top  -padx $fpx -pady $fpy
 
252
  #-----Apply, Ok and cancel buttons creating and packing
 
253
 
 
254
  set ap $Info(defaultApplyState)
 
255
  set ca $Info(defaultCancelState)
 
256
 
 
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" \
 
259
                                  -state $ca]
 
260
  set ap_btn [button $w.fB.apply  -text Apply -command Coordinate::panelApply \
 
261
                                  -state $ap]
 
262
 
 
263
  focus $ok_btn
 
264
  set Coordinate(applyButton)  $ap_btn
 
265
  set Coordinate(cancelButton) $cn_btn
 
266
 
 
267
  pack $ok_btn $cn_btn $ap_btn -side left -padx $fpx 
 
268
 
 
269
  #-----Initialization
 
270
  #-Nothing so far
 
271
 
 
272
  
 
273
}
 
274
 
 
275
 
 
276
proc Coordinate::panelSave { {inform_front 1} } {
 
277
  global Info Coordinate Model
 
278
 
 
279
  set panel $Coordinate(parameterType)
 
280
 
 
281
  #--Store old values
 
282
  Panel::backupFields Coordinate
 
283
 
 
284
  set sdim1 $Model(SIMULATION_DIMENSION)
 
285
  Coordinate::applyCoordinateDimension $Coordinate(COORDINATE_SYSTEM)
 
286
  set sdim2 $Model(SIMULATION_DIMENSION)
 
287
 
 
288
  # If simulation dimension was changed
 
289
  #
 
290
  if { $sdim1 != "" && $sdim1 != $sdim2 } {
 
291
 
 
292
    StdPanelInit::updateEquationDataAndMasks 
 
293
    Equation::setOtherMasks
 
294
    StdPanelInit::createObjectTableMasks
 
295
    Equation::constructProblemMask
 
296
 
 
297
    # Solver variable dofs!
 
298
    set modified 0
 
299
    Solver::updateVariableDofs modified
 
300
    if { $modified } {
 
301
      Solver::panelSave
 
302
    }
 
303
 
 
304
    # Calculator variable dofs!
 
305
    set modified 0
 
306
    Calculator::updateVariableDofs modified
 
307
    if { $modified } {
 
308
      Calculator::okProcPre
 
309
      StdPanelExec::panelSave Calculator
 
310
    }
 
311
 
 
312
    Panel::checkMaskedParameters modified
 
313
  }
 
314
 
 
315
  #--Set vector data size
 
316
  set Coordinate(COORDINATE_MAPPING,dataSize) 3
 
317
 
 
318
  #--Form parameter data
 
319
  set Coordinate(ids) 1
 
320
  DataField::formNonStandardParameter Coordinate 1 "Coordinates1"
 
321
 
 
322
  #--Write data into model
 
323
  if {$inform_front} {
 
324
    set Model(Front,needsUpdate) 1
 
325
  }
 
326
 
 
327
  set Model(Solver,needsUpdate) 1
 
328
 
 
329
  Panel::panelDataChanged 0 Coordinate 
 
330
  Panel::panelDataModified 0 Coordinate 
 
331
  Util::cpp_exec coordinatePanelOk
 
332
}
 
333
 
 
334
 
 
335
proc Coordinate::panelOk {w} {
 
336
  global Coordinate
 
337
    
 
338
  #---No changes
 
339
  if { !$Coordinate(dataChanged) } {
 
340
    Panel::cancel $w; return
 
341
  }
 
342
 
 
343
  #---Error in data
 
344
  if { ![Coordinate::checkPanelData] } {
 
345
    return
 
346
  }
 
347
 
 
348
  #---Ok 
 
349
  Coordinate::panelSave
 
350
  Panel::cancel $w
 
351
}
 
352
 
 
353
 
 
354
proc Coordinate::panelApply {} {
 
355
  global Info Coordinate
 
356
 
 
357
  #---No changes
 
358
  if { !$Coordinate(dataChanged) } {
 
359
    return
 
360
  }
 
361
 
 
362
  if { ![Coordinate::checkPanelData] } {
 
363
    return
 
364
  }
 
365
   
 
366
  Coordinate::panelSave
 
367
 
 
368
  # This is needed to make mapping fields in
 
369
  # correct status in the panel
 
370
  Coordinate::setCoordinateStatus
 
371
}
 
372
 
 
373
 
 
374
proc Coordinate::getLabelIndex {} {
 
375
  global Coordinate
 
376
 
 
377
  switch $Coordinate(COORDINATE_SYSTEM) {
 
378
    "Cartesian 2D"        -
 
379
    "Cartesian 3D"        {return 0}
 
380
    "Axi Symmetric"       -
 
381
    "Cylindric Symmetric" -
 
382
    "Cylindrical"         {return 1}
 
383
    "Polar 2D"            -
 
384
    "Polar 3D"            {return 2}
 
385
  }
 
386
 
 
387
  #-Default if not found!
 
388
  return 0
 
389
}
 
390
 
 
391
 
 
392
proc Coordinate::updateLabels {} {
 
393
  global Coordinate
 
394
 
 
395
  set index [Coordinate::getLabelIndex]
 
396
  set Coordinate(coordinateLabelIndex) $index
 
397
  set labels [lindex $Coordinate(coordinateLabels) $index]
 
398
 
 
399
  foreach wid $Coordinate(allWidgets,label,COORDINATE_MAPPING) lbl $labels {
 
400
    set text $lbl
 
401
    append text ":"
 
402
    $wid configure -text $text
 
403
  }
 
404
}
 
405
 
 
406
proc Coordinate::panelCancel {w} {
 
407
  global Coordinate
 
408
 
 
409
  if { ![Panel::verifyCancel Coordinate] } {
 
410
    return
 
411
  }
 
412
 
 
413
  #---Reset into old values
 
414
  Panel::restoreFields Coordinate
 
415
 
 
416
  Panel::cancel $w
 
417
}
 
418
 
 
419
 
 
420
# Return 1 = ok, 0 = error
 
421
#
 
422
proc Coordinate::checkPanelData {} {
 
423
  global Info Coordinate Model
 
424
 
 
425
  # Coordinate mapping
 
426
  # ==================
 
427
  # we must have a list of {1 2 3} (in any order)!
 
428
  set mappings ""
 
429
  set is_ok 1
 
430
 
 
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
 
435
  # not editable
 
436
  #
 
437
  foreach i {3 2 1} {
 
438
    set var COORDINATE_MAPPING_$i
 
439
    set val [string trim $Coordinate($var)]
 
440
    set Coordinate($var) $val
 
441
 
 
442
    # NOTE: This is needed because mapping vars are not "normal"
 
443
    set Coordinate($var,err) 0
 
444
    set Coordinate($var,mod) 0
 
445
    set is_ok 1
 
446
 
 
447
    # Illegal value or same values
 
448
    #
 
449
    if { ($val < 1 || $val > 3) ||
 
450
         -1 != [lsearch $mappings $val]    
 
451
      } {
 
452
      set Coordinate($var,err) 1
 
453
      set is_ok 0
 
454
    }
 
455
 
 
456
    Widget::setFieldStatus Coordinate $var
 
457
  
 
458
    if {$is_ok} {
 
459
      lappend mappings $val
 
460
    }
 
461
  }
 
462
 
 
463
  #--If error
 
464
  if { 3 != [llength $mappings] } {
 
465
 
 
466
    set Info(messageIcon) error
 
467
    Message::dispOkMessage {"Incorrect coordinate mapping!"} \
 
468
                  "$Info(FRONT_NAME) error message" \
 
469
                  $Coordinate(winName) 
 
470
 
 
471
    return 0
 
472
  }
 
473
 
 
474
  set Coordinate(COORDINATE_MAPPING) "" 
 
475
 
 
476
  #--If mapping data ok
 
477
  foreach i {1 2 3} {
 
478
 
 
479
    set var COORDINATE_MAPPING_$i
 
480
 
 
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)
 
485
 
 
486
    lappend Coordinate(COORDINATE_MAPPING) $Coordinate($var)
 
487
  }
 
488
 
 
489
  # Ok
 
490
  return 1
 
491
}
 
492
 
 
493
 
 
494
# Set coordinate panel widgets state according
 
495
# to the model geometry dimension
 
496
#
 
497
proc Coordinate::setCoordinateStatus {} {
 
498
  global Coordinate
 
499
 
 
500
  Coordinate::updateLabels
 
501
 
 
502
  switch $Coordinate(COORDINATE_SYSTEM) {
 
503
    "Cartesian 2D"        -
 
504
    "Polar 2D"            -
 
505
    "Axi Symmetric"       { set activate_3 0 }
 
506
    "Cylindric Symmetric" -
 
507
    "Cartesian 3D"        -
 
508
    "Cylindrical"         -
 
509
    "Polar 3D"            { set activate_3 1 }
 
510
  }
 
511
 
 
512
  set wdg [lindex $Coordinate(allWidgets,COORDINATE_MAPPING) 2]
 
513
 
 
514
  if { $activate_3 } {
 
515
    $wdg configure -state normal -bg white
 
516
 
 
517
  } else {
 
518
    $wdg configure -state disabled -bg gray
 
519
 
 
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
 
524
 
 
525
    if { $Coordinate(COORDINATE_MAPPING_1) <= \
 
526
         $Coordinate(COORDINATE_MAPPING_2)
 
527
       } {
 
528
      set Coordinate(COORDINATE_MAPPING_1) 1
 
529
      set Coordinate(COORDINATE_MAPPING_2) 2
 
530
 
 
531
    } else { 
 
532
      set Coordinate(COORDINATE_MAPPING_1) 2
 
533
      set Coordinate(COORDINATE_MAPPING_2) 1
 
534
    }
 
535
 
 
536
  }
 
537
}
 
538
 
 
539
 
 
540
# Updates system according to the simulation dimension value
 
541
#
 
542
proc Coordinate::applyCoordinateDimension {coordinate_system} {
 
543
  global Coordinate Model
 
544
 
 
545
  switch $coordinate_system {
 
546
    "Cartesian 2D"        -
 
547
    "Polar 2D"            -
 
548
    "Axi Symmetric"       { set Model(SIMULATION_DIMENSION) "2D" }
 
549
    "Cylindric Symmetric" -
 
550
    "Cartesian 3D"        -
 
551
    "Cylindrical"         -
 
552
    "Polar 3D"            { set Model(SIMULATION_DIMENSION) "3D" }
 
553
  }
 
554
 
 
555
  set Coordinate(coordinateLabelIndex) [Coordinate::getLabelIndex]
 
556
}
 
557
 
 
558
 
 
559
# Set default coordinate system
 
560
#
 
561
proc Coordinate::setDefaultCoordinateSystem {} {
 
562
  global Coordinate Model
 
563
 
 
564
  if { $Model(GEOMETRY_DIMENSION) == "2D" } {
 
565
    set Coordinate(COORDINATE_SYSTEM) "Cartesian 2D"
 
566
 
 
567
  } else {
 
568
    set Coordinate(COORDINATE_SYSTEM) "Cartesian 3D"
 
569
  }
 
570
    
 
571
  # Store new value in the parameter
 
572
  set id $Coordinate(parameterId)
 
573
  DataField::setFieldValue Coordinate $id COORDINATE_SYSTEM $Coordinate(COORDINATE_SYSTEM)
 
574
 
 
575
  execNsProc Coordinate panelSave 0
 
576
}
 
577
 
 
578
 
 
579
 
 
580
# end ecif_tk_coordinateDefPanel.tcl
 
581
# ********************