File: csgeom.tcl

package info (click to toggle)
netgen 6.2.1804%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,308 kB
  • sloc: cpp: 132,223; ansic: 22,816; tcl: 6,739; sh: 1,175; python: 725; makefile: 33
file content (695 lines) | stat: -rw-r--r-- 15,602 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
.ngmenu.geometry add command -label "Scan CSG Geometry" -command { Ng_ParseGeometry }
.ngmenu.geometry add command -label "CSG Options..." -command geometryoptionsdialog

# only intern version !
# .ngmenu.geometry add separator
# .ngmenu.geometry add command -label "New Primitive"  \
#     -command newprimitivedialog -accelerator "<n><p>"
# .ngmenu.geometry add command -label "Edit Primitive" \
#     -command editprimitivedialog -accelerator "<e><p>"
# .ngmenu.geometry add command -label "Edit Solid" \
#     -command newsoliddialog -accelerator "<e><s>"
# .ngmenu.geometry add command -label "Choose Top Level " \
#     -command topleveldialog 
# .ngmenu.geometry add command -label "Identify" \
#     -command identifydialog 
.ngmenu.geometry add command -label "CSG Properties..." \
    -command topleveldialog2 











proc geometryoptionsdialog { } {


    set w .geometry_dlg
    
    if {[winfo exists .geometry_dlg] == 1} {
	wm withdraw $w
	wm deiconify $w
	focus $w 
    } {

	toplevel $w
	
	global geooptions
	
	Ng_GeometryOptions get

	checkbutton $w.drawcsg -text "Draw Geometry" \
	-variable geooptions.drawcsg 
	pack $w.drawcsg

	frame $w.fac
	pack $w.fac -pady 5
	ttk::label $w.fac.lab -text "Facets:";
	entry $w.fac.ent -width 8 -relief sunken \
	    -textvariable geooptions.facets
	pack $w.fac.lab $w.fac.ent  -side left
	
 
	frame $w.det
	pack $w.det -pady 5
	ttk::label $w.det.lab -text "Detail:";
	entry $w.det.ent -width 8 -relief sunken \
	    -textvariable geooptions.detail
	pack $w.det.lab $w.det.ent  -side left
	
	frame $w.cox
	pack $w.cox -pady 5
	ttk::label $w.cox.lab -text "min/max x:";
	entry $w.cox.ent1 -width 8 -relief sunken \
	    -textvariable geooptions.minx
	entry $w.cox.ent2 -width 8 -relief sunken \
	    -textvariable geooptions.maxx
	pack $w.cox.lab $w.cox.ent1 \
	    $w.cox.ent2  -side left
	
	frame $w.coy
	pack $w.coy -pady 5
	ttk::label $w.coy.lab -text "min/max y:";
	entry $w.coy.ent1 -width 8 -relief sunken \
	    -textvariable geooptions.miny
	entry $w.coy.ent2 -width 8 -relief sunken \
	    -textvariable geooptions.maxy
	pack $w.coy.lab $w.coy.ent1 \
	    $w.coy.ent2  -side left
	
	frame $w.coz
	pack $w.coz -pady 5
	ttk::label $w.coz.lab -text "min/max z:";
	entry $w.coz.ent1 -width 8 -relief sunken \
	    -textvariable geooptions.minz
	entry $w.coz.ent2 -width 8 -relief sunken \
	    -textvariable geooptions.maxz
	pack $w.coz.lab $w.coz.ent1 \
	    $w.coz.ent2  -side left
	


# 	tixButtonBox $w.bbox -orientation horizontal
# 	$w.bbox add ok    -text Apply  -underline 0 -width 5 \
# 	    -command { Ng_GeometryOptions set }
	
# 	$w.bbox add close -text Done   -underline 0 -width 5 \
# 	    -command { 
# 		Ng_GeometryOptions set
# 		destroy .geometry_dlg
# 	    }
# 	pack $w.bbox -side bottom -fill x
	

 	frame $w.bu
	pack $w.bu -fill x -ipady 3


 	ttk::button $w.bu.app -text "Apply" -command {
 	    Ng_GeometryOptions set
 	}
 	ttk::button $w.bu.ok -text "Done" -command {
 	    Ng_GeometryOptions set
 	    destroy .geometry_dlg
 	}
 	pack  $w.bu.app $w.bu.ok -side left -expand yes
    

	wm withdraw $w
	wm geom $w +100+100
	wm deiconify $w
	wm title $w "Geometry options"
	focus $w
    }
}

















#
#
#   Edit primitive
#
#
proc editprimitivedialog2 { name } {

    global w classname

    set w .ep_dlg
    toplevel .$w

    Ng_GetPrimitiveData $name classname valuelist
        
    
    ttk::label $w.lab1 -text "Primitive Name:  $name";
    ttk::label $w.lab2 -text "Primitive Class: $classname";
    pack $w.lab1 $w.lab2 -fill x -pady 1m -padx 5m 
    
    frame $w.specific -relief groove

    global spec
    set spec(sphere) { cx cy cz rad }
    set spec(cylinder) { ax ay az bx by bz rad }
    set spec(plane) { px py pz nx ny nz }
    set spec(cone) { ax ay az bx by bz ra rb }
    set spec(brick) { p1x p1y p1z p2x p2y p2z p3x p3y p3z p4x p4y p4z } 
   
    set cnt 0
    foreach field $spec($classname) {

	frame $w.specific.f$cnt 
	pack $w.specific.f$cnt -side top -anchor ne

	ttk::label $w.specific.f$cnt.lab -text "$field"
	entry $w.specific.f$cnt.ent -textvariable dataval($cnt) \
	    -width 6 -relief sunken
	pack $w.specific.f$cnt.ent $w.specific.f$cnt.lab -side right
	$w.specific.f$cnt.ent delete 0 end
	$w.specific.f$cnt.ent insert 0 [lindex $valuelist $cnt]
	set cnt [expr $cnt + 1]
    }
    pack $w.specific


    ttk::button $w.cancel -text "cancel" -command {
	destroy $w 
    }

    ttk::button $w.ok -text "ok" -command {

	set valuelist ""
	set cnt 0
	foreach field $spec($classname) {
	    lappend valuelist $dataval($cnt)
	    set cnt [expr $cnt + 1]
	}
	Ng_SetPrimitiveData $name $valuelist
	destroy $w
    }
    pack  $w.cancel $w.ok -side left -expand yes

    bind $w <Return> { $w.ok  invoke}
    bind $w <Escape> { $w.cancel  invoke}
    

    wm withdraw $w
    wm geom $w +100+100
    wm deiconify $w

#    grab $w
    focus $w.specific.f0.ent
}



#
#
#      Select primitve to edit
#
#

proc editprimitivedialog { } {
    global w

    set w .ep_dlg
    toplevel $w

    frame $w.frame -borderwidth 5m
    pack $w.frame -side top -expand yes -fill y

    listbox $w.frame.list -yscroll "$w.frame.scroll set" -setgrid 1 -height 12
    scrollbar $w.frame.scroll -command "$w.frame.list yview"
    pack $w.frame.scroll -side right -fill y
    pack $w.frame.list -side left -expand 1 -fill both
    

    Ng_GetPrimitiveList primlist
    foreach el $primlist {
	$w.frame.list insert end $el }

    ttk::button $w.cancel -text "cancel" -command { destroy $w }
    ttk::button $w.ok -text "ok" -command {
	set name [.ep_dlg.frame.list get active]
	puts "name=($name)"
	destroy $w
	if { $name != "" } { editprimitivedialog2 $name }
    }
    
    bind $w <Escape> { $w.cancel invoke }
    bind $w <Return> { $w.ok invoke }
    

    pack  $w.cancel $w.ok -side left -expand yes

    wm withdraw $w
    wm geom $w +100+100
    wm deiconify $w

#    grab $w
    focus $w.frame.list
}



#
#
#         Create new primitive
#
#
proc newprimitivedialog { } {

    global w name

    set w .ap_dlg
    
    toplevel $w

    set name ""
    frame $w.f1
    pack $w.f1 -pady 2m
    ttk::label $w.f1.lab -text "Primitive Name: ";
    entry $w.f1.ent -width 5 -relief sunken \
	-textvariable name
    pack $w.f1.lab $w.f1.ent -side left
    
    frame $w.frame -borderwidth .5c
    pack $w.frame -side top -expand yes -fill y

    listbox $w.frame.list -yscroll "$w.frame.scroll set" -setgrid 1 -height 8 
    scrollbar $w.frame.scroll -command "$w.frame.list yview"
    pack $w.frame.scroll -side right -fill y
    pack $w.frame.list -side left -expand 1 -fill both
    
    $w.frame.list insert 0 sphere cylinder plane cone brick
    $w.frame.list activate 0
    
    ttk::button $w.ok -text "ok" -command {
	Ng_CreatePrimitive [$w.frame.list get active]  $name
	destroy $w
	editprimitivedialog2 $name
    }

    ttk::button $w.cancel -text "cancel" -command {
	destroy $w
    }
    
    pack  $w.cancel $w.ok -side left -expand yes -pady 2m


    bind $w <Escape> { $w.cancel invoke }
    bind $w <Return> { $w.ok invoke }

    wm withdraw $w
    wm geom $w +100+100
    wm deiconify $w

#    grab $w
    focus $w.f1.ent
}






proc newsoliddialog { } {

    global w name val sollist

    set w .ns_dlg
    toplevel $w

    set name ""
    frame $w.f1
    ttk::label $w.f1.lab -text "Solid Name: ";
    entry $w.f1.ent -width 5 -relief sunken \
	-textvariable name
    $w.f1.ent delete 0 end
    ttk::button $w.f1.getsel -text "Get Selected" -command { 
	$w.f1.ent delete 0 end
	$w.f1.ent insert 0 [$w.f3.list get active]
	$w.bu.get invoke
    }
    pack $w.f1.getsel -side bottom
    pack $w.f1.ent $w.f1.lab -side right


    frame $w.f3 -borderwidth .5c
    listbox $w.f3.list -yscroll "$w.f3.scroll set" -setgrid 1 -height 12
    scrollbar $w.f3.scroll -command "$w.f3.list yview"
    pack $w.f3.scroll -side right -fill y
    pack $w.f3.list -side left -expand 1 -fill both
    
    Ng_GetSolidList sollist
    foreach el $sollist {
	$w.f3.list insert end $el }

    frame $w.f2
    ttk::label $w.f2.lab -text "Solid Description: ";
    pack $w.f2.lab


    entry $w.f2.ent -width 100 -relief sunken \
	-textvariable val  -xscrollcommand "$w.f2.scr set"
    scrollbar $w.f2.scr -relief sunken -orient horiz -command \
	"$w.f2.ent xview"
    $w.f2.ent delete 0 end
    pack $w.f2.ent $w.f2.scr -fill x



    frame $w.bu
    ttk::button $w.bu.close -text "close" -command {
	destroy $w
    }

    ttk::button $w.bu.get -text "get data" -command {
	Ng_GetSolidData $name val
    }

    ttk::button $w.bu.set -text "set data" -command {
	Ng_SetSolidData $name $val
    }

    pack $w.bu.get $w.bu.set $w.bu.close -side left 


    pack $w.bu -pady 5 -side bottom                     ;# buttons
    pack $w.f2 -pady 5 -side bottom                     ;# edit field
    pack $w.f1 -pady 5 -side left                       ;# name
    pack $w.f3 -side left -expand yes -fill y           ;# listbox



    bind $w <Escape> { $w.bu.close invoke }

    wm withdraw $w
    wm geom $w +100+100
    wm deiconify $w

#    grab $w
    focus $w
}







#
#  Edit top level objects
#
#


proc toplevelproperties { w solname surfname } {

    global properties

    Ng_TopLevel getprop $solname $surfname properties


    set w .tlprop_dlg

    if {[winfo exists $w] == 1} {
	wm withdraw $w
	wm deiconify $w
	focus $w 
    } {
	toplevel $w
    
	ttk::label $w.lab1 -text "Red"
	scale $w.scale1 -orient horizontal -length 300 -from 0 -to 1 \
	    -resolution 0.01  -tickinterval 0.2 \
	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(red)
	
	ttk::label $w.lab2 -text "Green"
	scale $w.scale2 -orient horizontal -length 300 -from 0 -to 1 \
	    -resolution 0.01  -tickinterval 0.2 \
	-command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(green)
	
	ttk::label $w.lab3 -text "Blue"
	scale $w.scale3 -orient horizontal -length 300 -from 0 -to 1 \
	    -resolution 0.01  -tickinterval 0.2 \
	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(blue)

	
	pack $w.lab1 $w.scale1 $w.lab2 $w.scale2 $w.lab3 $w.scale3

	checkbutton $w.cb4 -text "Visible" \
	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } \
	    -variable properties(visible)
	
	checkbutton $w.cb5 -text "Transparent" \
	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } \
	    -variable properties(transp)
	
	
	pack  $w.cb4 $w.cb5
	
	
	frame $w.bu
	pack $w.bu -fill x
	ttk::button $w.bu.ok -text "Ok" -command "destroy .tlprop_dlg"
	pack $w.bu.ok  -expand yes
    
	wm withdraw $w
	wm geom $w +100+100
	wm deiconify $w
	focus $w
    }
    wm title $w "Properties $solname $surfname"
}






proc topleveldialog { } {

    global w name val sollist

    set w .tl_dlg
    toplevel $w



    frame $w.sol -borderwidth .5c
    listbox $w.sol.list -yscroll "$w.sol.scroll set" -setgrid 1 -height 12
    scrollbar $w.sol.scroll -command "$w.sol.list yview"
    pack $w.sol.scroll -side right -fill y
    pack $w.sol.list -side left -expand 1 -fill both
    
    Ng_GetSolidList sollist
    foreach el $sollist {
	$w.sol.list insert end $el }
    Ng_GetPrimitiveList sollist
    foreach el $sollist {
	$w.sol.list insert end $el }




    frame $w.sul -borderwidth .5c
    listbox $w.sul.list -yscroll "$w.sul.scroll set" -setgrid 1 -height 12
    scrollbar $w.sul.scroll -command "$w.sul.list yview"
    pack $w.sul.scroll -side right -fill y
    pack $w.sul.list -side left -expand 1 -fill both
    
    Ng_GetSurfaceList sollist
    foreach el $sollist {
	$w.sul.list insert end $el }





    frame $w.topl -borderwidth .5c
    listbox $w.topl.list -yscroll "$w.topl.scroll set" -setgrid 1 -height 12 \
	-command { puts hi }
    scrollbar $w.topl.scroll -command "$w.topl.list yview"
    pack $w.topl.scroll -side right -fill y
    pack $w.topl.list -side left -expand 1 -fill both
    
    Ng_TopLevel getlist sollist
    puts $sollist
    foreach el $sollist {
	set hel "[ lindex $el 0 ]"
	if { [ llength $el ] == 2 } {
	    set hel "[ lindex $el 1 ] on [ lindex $el 0 ]"
	}
	$w.topl.list insert end $hel 
    }


    frame $w.bu

    ttk::button $w.bu.close -text "close" -command {
	destroy $w
    }
    ttk::button $w.bu.addsol -text "Add Solid" -command {
	set solname [$w.sol.list get active]
	Ng_TopLevel set $solname ""
	Ng_ParseGeometry
	$w.topl.list insert end $solname
    }

    ttk::button $w.bu.addsurf -text "Add Surface" -command {
	set solname [$w.sol.list get active]
	set surfname [$w.sul.list get active]
	Ng_TopLevel set $solname $surfname
	Ng_ParseGeometry
	puts "$solname on $surfname"
	$w.topl.list insert end "$surfname on $solname"
    }

    ttk::button $w.bu.remsol -text "Remove" -command {
	set solname [$w.topl.list get active]
	set surfname ""
	if { [llength $solname] == 3 } {
	    set surfname [lindex $solname 0]
	    set solname [lindex $solname 2]
	}
	Ng_TopLevel remove $solname $surfname
	Ng_ParseGeometry
	$w.topl.list delete active
    }

    ttk::button $w.bu.prop -text "Properties" -command {
	set solname [$w.topl.list get active]
	set surfname ""
	if { [llength $solname] == 3 } {
	    set surfname [lindex $solname 0]
	    set solname [lindex $solname 2]
	}
	toplevelproperties tlp $solname $surfname
    }


    

    pack  $w.bu.close $w.bu.addsol $w.bu.addsurf $w.bu.remsol $w.bu.prop  -side left 


    pack $w.bu -side bottom
    pack $w.sol -side left -expand yes -fill y           ;# listbox
    pack $w.sul -side left -expand yes -fill y           ;# listbox
    pack $w.topl -side left -expand yes -fill y           ;# listbox


    bind $w <Escape> { $w.bu.close invoke }

    wm withdraw $w
    wm geom $w +100+100
    wm deiconify $w

#    grab $w
    focus $w
}






proc topleveldialog2 { } {
    set w .tl2_dlg
    
    if {[winfo exists .tl2_dlg] == 1} {
	wm withdraw $w
	wm deiconify $w
	focus $w 
    } {
	toplevel $w

	global name val sollist

	frame $w.topl -borderwidth .5c
	listbox $w.topl.list -yscroll "$w.topl.scroll set" -setgrid 1 -height 12
	scrollbar $w.topl.scroll -command "$w.topl.list yview"
	pack $w.topl.scroll -side right -fill y
	pack $w.topl.list -side left -expand 1 -fill both
	
	Ng_TopLevel getlist sollist
	puts $sollist
	set i 1
	foreach el $sollist {
	    set hel "$i: [ lindex $el 0 ]"
	    if { [ llength $el ] == 2 } {
		set hel "$i: [ lindex $el 1 ] on [ lindex $el 0 ]"
	    }
	    incr i
	    $w.topl.list insert end $hel }
	
	
	frame $w.bu
	
	ttk::button $w.bu.close -text "close" -command {
	    destroy .tl2_dlg
	}
	

	ttk::button $w.bu.prop -text "Properties" -command {
	    set solname [.tl2_dlg.topl.list get active]
	    set surfname ""
	    if { [llength $solname] == 2 } {
		set solname [lindex $solname 1]
	    }
	    if { [llength $solname] == 4 } {
		set surfname [lindex $solname 1]
		set solname [lindex $solname 3]
	    }
	    toplevelproperties tlp $solname $surfname
	}
	
	pack $w.bu.close $w.bu.prop  -side left 
	pack $w.bu -side bottom
	pack $w.topl -side left -expand yes -fill y           ;# listbox
		
	bind .tl2_dlg.topl.list <Double-1> {
	    set solname [.tl2_dlg.topl.list get  @%x,%y]
	    set surfname ""
	    if { [llength $solname] == 2 } {
		set solname [lindex $solname 1]
	    }
	    if { [llength $solname] == 4 } {
		set surfname [lindex $solname 1]
		set solname [lindex $solname 3]
	    }
	    toplevelproperties tlp $solname $surfname
	}
	
	bind .tl2_dlg <Escape> { .tl2_dlg.bu.close invoke }
	
	wm withdraw $w
	wm geom $w +100+100
	wm deiconify $w
	wm title $w "Top-Level Options"	
	focus $w
    }
}