1.ngmenu.geometry add command -label "Scan CSG Geometry" -command { Ng_ParseGeometry }
2.ngmenu.geometry add command -label "CSG Options..." -command geometryoptionsdialog
3
4# only intern version !
5# .ngmenu.geometry add separator
6# .ngmenu.geometry add command -label "New Primitive"  \
7#     -command newprimitivedialog -accelerator "<n><p>"
8# .ngmenu.geometry add command -label "Edit Primitive" \
9#     -command editprimitivedialog -accelerator "<e><p>"
10# .ngmenu.geometry add command -label "Edit Solid" \
11#     -command newsoliddialog -accelerator "<e><s>"
12# .ngmenu.geometry add command -label "Choose Top Level " \
13#     -command topleveldialog
14# .ngmenu.geometry add command -label "Identify" \
15#     -command identifydialog
16.ngmenu.geometry add command -label "CSG Properties..." \
17    -command topleveldialog2
18
19
20
21
22
23
24
25
26
27
28
29proc geometryoptionsdialog { } {
30
31
32    set w .geometry_dlg
33
34    if {[winfo exists .geometry_dlg] == 1} {
35	wm withdraw $w
36	wm deiconify $w
37	focus $w
38    } {
39
40	toplevel $w
41
42	global geooptions
43
44	Ng_GeometryOptions get
45
46	checkbutton $w.drawcsg -text "Draw Geometry" \
47	-variable geooptions.drawcsg
48	pack $w.drawcsg
49
50	frame $w.fac
51	pack $w.fac -pady 5
52	ttk::label $w.fac.lab -text "Facets:";
53	entry $w.fac.ent -width 8 -relief sunken \
54	    -textvariable geooptions.facets
55	pack $w.fac.lab $w.fac.ent  -side left
56
57
58	frame $w.det
59	pack $w.det -pady 5
60	ttk::label $w.det.lab -text "Detail:";
61	entry $w.det.ent -width 8 -relief sunken \
62	    -textvariable geooptions.detail
63	pack $w.det.lab $w.det.ent  -side left
64
65	frame $w.cox
66	pack $w.cox -pady 5
67	ttk::label $w.cox.lab -text "min/max x:";
68	entry $w.cox.ent1 -width 8 -relief sunken \
69	    -textvariable geooptions.minx
70	entry $w.cox.ent2 -width 8 -relief sunken \
71	    -textvariable geooptions.maxx
72	pack $w.cox.lab $w.cox.ent1 \
73	    $w.cox.ent2  -side left
74
75	frame $w.coy
76	pack $w.coy -pady 5
77	ttk::label $w.coy.lab -text "min/max y:";
78	entry $w.coy.ent1 -width 8 -relief sunken \
79	    -textvariable geooptions.miny
80	entry $w.coy.ent2 -width 8 -relief sunken \
81	    -textvariable geooptions.maxy
82	pack $w.coy.lab $w.coy.ent1 \
83	    $w.coy.ent2  -side left
84
85	frame $w.coz
86	pack $w.coz -pady 5
87	ttk::label $w.coz.lab -text "min/max z:";
88	entry $w.coz.ent1 -width 8 -relief sunken \
89	    -textvariable geooptions.minz
90	entry $w.coz.ent2 -width 8 -relief sunken \
91	    -textvariable geooptions.maxz
92	pack $w.coz.lab $w.coz.ent1 \
93	    $w.coz.ent2  -side left
94
95
96
97# 	tixButtonBox $w.bbox -orientation horizontal
98# 	$w.bbox add ok    -text Apply  -underline 0 -width 5 \
99# 	    -command { Ng_GeometryOptions set }
100
101# 	$w.bbox add close -text Done   -underline 0 -width 5 \
102# 	    -command {
103# 		Ng_GeometryOptions set
104# 		destroy .geometry_dlg
105# 	    }
106# 	pack $w.bbox -side bottom -fill x
107
108
109 	frame $w.bu
110	pack $w.bu -fill x -ipady 3
111
112
113 	ttk::button $w.bu.app -text "Apply" -command {
114 	    Ng_GeometryOptions set
115 	}
116 	ttk::button $w.bu.ok -text "Done" -command {
117 	    Ng_GeometryOptions set
118 	    destroy .geometry_dlg
119 	}
120 	pack  $w.bu.app $w.bu.ok -side left -expand yes
121
122
123	wm withdraw $w
124	wm geom $w +100+100
125	wm deiconify $w
126	wm title $w "Geometry options"
127	focus $w
128    }
129}
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147#
148#
149#   Edit primitive
150#
151#
152proc editprimitivedialog2 { name } {
153
154    global w classname
155
156    set w .ep_dlg
157    toplevel .$w
158
159    Ng_GetPrimitiveData $name classname valuelist
160
161
162    ttk::label $w.lab1 -text "Primitive Name:  $name";
163    ttk::label $w.lab2 -text "Primitive Class: $classname";
164    pack $w.lab1 $w.lab2 -fill x -pady 1m -padx 5m
165
166    frame $w.specific -relief groove
167
168    global spec
169    set spec(sphere) { cx cy cz rad }
170    set spec(cylinder) { ax ay az bx by bz rad }
171    set spec(plane) { px py pz nx ny nz }
172    set spec(cone) { ax ay az bx by bz ra rb }
173    set spec(brick) { p1x p1y p1z p2x p2y p2z p3x p3y p3z p4x p4y p4z }
174
175    set cnt 0
176    foreach field $spec($classname) {
177
178	frame $w.specific.f$cnt
179	pack $w.specific.f$cnt -side top -anchor ne
180
181	ttk::label $w.specific.f$cnt.lab -text "$field"
182	entry $w.specific.f$cnt.ent -textvariable dataval($cnt) \
183	    -width 6 -relief sunken
184	pack $w.specific.f$cnt.ent $w.specific.f$cnt.lab -side right
185	$w.specific.f$cnt.ent delete 0 end
186	$w.specific.f$cnt.ent insert 0 [lindex $valuelist $cnt]
187	set cnt [expr $cnt + 1]
188    }
189    pack $w.specific
190
191
192    ttk::button $w.cancel -text "cancel" -command {
193	destroy $w
194    }
195
196    ttk::button $w.ok -text "ok" -command {
197
198	set valuelist ""
199	set cnt 0
200	foreach field $spec($classname) {
201	    lappend valuelist $dataval($cnt)
202	    set cnt [expr $cnt + 1]
203	}
204	Ng_SetPrimitiveData $name $valuelist
205	destroy $w
206    }
207    pack  $w.cancel $w.ok -side left -expand yes
208
209    bind $w <Return> { $w.ok  invoke}
210    bind $w <Escape> { $w.cancel  invoke}
211
212
213    wm withdraw $w
214    wm geom $w +100+100
215    wm deiconify $w
216
217#    grab $w
218    focus $w.specific.f0.ent
219}
220
221
222
223#
224#
225#      Select primitve to edit
226#
227#
228
229proc editprimitivedialog { } {
230    global w
231
232    set w .ep_dlg
233    toplevel $w
234
235    frame $w.frame -borderwidth 5m
236    pack $w.frame -side top -expand yes -fill y
237
238    listbox $w.frame.list -yscroll "$w.frame.scroll set" -setgrid 1 -height 12
239    scrollbar $w.frame.scroll -command "$w.frame.list yview"
240    pack $w.frame.scroll -side right -fill y
241    pack $w.frame.list -side left -expand 1 -fill both
242
243
244    Ng_GetPrimitiveList primlist
245    foreach el $primlist {
246	$w.frame.list insert end $el }
247
248    ttk::button $w.cancel -text "cancel" -command { destroy $w }
249    ttk::button $w.ok -text "ok" -command {
250	set name [.ep_dlg.frame.list get active]
251	puts "name=($name)"
252	destroy $w
253	if { $name != "" } { editprimitivedialog2 $name }
254    }
255
256    bind $w <Escape> { $w.cancel invoke }
257    bind $w <Return> { $w.ok invoke }
258
259
260    pack  $w.cancel $w.ok -side left -expand yes
261
262    wm withdraw $w
263    wm geom $w +100+100
264    wm deiconify $w
265
266#    grab $w
267    focus $w.frame.list
268}
269
270
271
272#
273#
274#         Create new primitive
275#
276#
277proc newprimitivedialog { } {
278
279    global w name
280
281    set w .ap_dlg
282
283    toplevel $w
284
285    set name ""
286    frame $w.f1
287    pack $w.f1 -pady 2m
288    ttk::label $w.f1.lab -text "Primitive Name: ";
289    entry $w.f1.ent -width 5 -relief sunken \
290	-textvariable name
291    pack $w.f1.lab $w.f1.ent -side left
292
293    frame $w.frame -borderwidth .5c
294    pack $w.frame -side top -expand yes -fill y
295
296    listbox $w.frame.list -yscroll "$w.frame.scroll set" -setgrid 1 -height 8
297    scrollbar $w.frame.scroll -command "$w.frame.list yview"
298    pack $w.frame.scroll -side right -fill y
299    pack $w.frame.list -side left -expand 1 -fill both
300
301    $w.frame.list insert 0 sphere cylinder plane cone brick
302    $w.frame.list activate 0
303
304    ttk::button $w.ok -text "ok" -command {
305	Ng_CreatePrimitive [$w.frame.list get active]  $name
306	destroy $w
307	editprimitivedialog2 $name
308    }
309
310    ttk::button $w.cancel -text "cancel" -command {
311	destroy $w
312    }
313
314    pack  $w.cancel $w.ok -side left -expand yes -pady 2m
315
316
317    bind $w <Escape> { $w.cancel invoke }
318    bind $w <Return> { $w.ok invoke }
319
320    wm withdraw $w
321    wm geom $w +100+100
322    wm deiconify $w
323
324#    grab $w
325    focus $w.f1.ent
326}
327
328
329
330
331
332
333proc newsoliddialog { } {
334
335    global w name val sollist
336
337    set w .ns_dlg
338    toplevel $w
339
340    set name ""
341    frame $w.f1
342    ttk::label $w.f1.lab -text "Solid Name: ";
343    entry $w.f1.ent -width 5 -relief sunken \
344	-textvariable name
345    $w.f1.ent delete 0 end
346    ttk::button $w.f1.getsel -text "Get Selected" -command {
347	$w.f1.ent delete 0 end
348	$w.f1.ent insert 0 [$w.f3.list get active]
349	$w.bu.get invoke
350    }
351    pack $w.f1.getsel -side bottom
352    pack $w.f1.ent $w.f1.lab -side right
353
354
355    frame $w.f3 -borderwidth .5c
356    listbox $w.f3.list -yscroll "$w.f3.scroll set" -setgrid 1 -height 12
357    scrollbar $w.f3.scroll -command "$w.f3.list yview"
358    pack $w.f3.scroll -side right -fill y
359    pack $w.f3.list -side left -expand 1 -fill both
360
361    Ng_GetSolidList sollist
362    foreach el $sollist {
363	$w.f3.list insert end $el }
364
365    frame $w.f2
366    ttk::label $w.f2.lab -text "Solid Description: ";
367    pack $w.f2.lab
368
369
370    entry $w.f2.ent -width 100 -relief sunken \
371	-textvariable val  -xscrollcommand "$w.f2.scr set"
372    scrollbar $w.f2.scr -relief sunken -orient horiz -command \
373	"$w.f2.ent xview"
374    $w.f2.ent delete 0 end
375    pack $w.f2.ent $w.f2.scr -fill x
376
377
378
379    frame $w.bu
380    ttk::button $w.bu.close -text "close" -command {
381	destroy $w
382    }
383
384    ttk::button $w.bu.get -text "get data" -command {
385	Ng_GetSolidData $name val
386    }
387
388    ttk::button $w.bu.set -text "set data" -command {
389	Ng_SetSolidData $name $val
390    }
391
392    pack $w.bu.get $w.bu.set $w.bu.close -side left
393
394
395    pack $w.bu -pady 5 -side bottom                     ;# buttons
396    pack $w.f2 -pady 5 -side bottom                     ;# edit field
397    pack $w.f1 -pady 5 -side left                       ;# name
398    pack $w.f3 -side left -expand yes -fill y           ;# listbox
399
400
401
402    bind $w <Escape> { $w.bu.close invoke }
403
404    wm withdraw $w
405    wm geom $w +100+100
406    wm deiconify $w
407
408#    grab $w
409    focus $w
410}
411
412
413
414
415
416
417
418#
419#  Edit top level objects
420#
421#
422
423
424proc toplevelproperties { w solname surfname } {
425
426    global properties
427
428    Ng_TopLevel getprop $solname $surfname properties
429
430
431    set w .tlprop_dlg
432
433    if {[winfo exists $w] == 1} {
434	wm withdraw $w
435	wm deiconify $w
436	focus $w
437    } {
438	toplevel $w
439
440	ttk::label $w.lab1 -text "Red"
441	scale $w.scale1 -orient horizontal -length 300 -from 0 -to 1 \
442	    -resolution 0.01  -tickinterval 0.2 \
443	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(red)
444
445	ttk::label $w.lab2 -text "Green"
446	scale $w.scale2 -orient horizontal -length 300 -from 0 -to 1 \
447	    -resolution 0.01  -tickinterval 0.2 \
448	-command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(green)
449
450	ttk::label $w.lab3 -text "Blue"
451	scale $w.scale3 -orient horizontal -length 300 -from 0 -to 1 \
452	    -resolution 0.01  -tickinterval 0.2 \
453	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } -variable  properties(blue)
454
455
456	pack $w.lab1 $w.scale1 $w.lab2 $w.scale2 $w.lab3 $w.scale3
457
458	checkbutton $w.cb4 -text "Visible" \
459	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } \
460	    -variable properties(visible)
461
462	checkbutton $w.cb5 -text "Transparent" \
463	    -command { Ng_TopLevel setprop $solname $surfname properties; redraw } \
464	    -variable properties(transp)
465
466
467	pack  $w.cb4 $w.cb5
468
469
470	frame $w.bu
471	pack $w.bu -fill x
472	ttk::button $w.bu.ok -text "Ok" -command "destroy .tlprop_dlg"
473	pack $w.bu.ok  -expand yes
474
475	wm withdraw $w
476	wm geom $w +100+100
477	wm deiconify $w
478	focus $w
479    }
480    wm title $w "Properties $solname $surfname"
481}
482
483
484
485
486
487
488proc topleveldialog { } {
489
490    global w name val sollist
491
492    set w .tl_dlg
493    toplevel $w
494
495
496
497    frame $w.sol -borderwidth .5c
498    listbox $w.sol.list -yscroll "$w.sol.scroll set" -setgrid 1 -height 12
499    scrollbar $w.sol.scroll -command "$w.sol.list yview"
500    pack $w.sol.scroll -side right -fill y
501    pack $w.sol.list -side left -expand 1 -fill both
502
503    Ng_GetSolidList sollist
504    foreach el $sollist {
505	$w.sol.list insert end $el }
506    Ng_GetPrimitiveList sollist
507    foreach el $sollist {
508	$w.sol.list insert end $el }
509
510
511
512
513    frame $w.sul -borderwidth .5c
514    listbox $w.sul.list -yscroll "$w.sul.scroll set" -setgrid 1 -height 12
515    scrollbar $w.sul.scroll -command "$w.sul.list yview"
516    pack $w.sul.scroll -side right -fill y
517    pack $w.sul.list -side left -expand 1 -fill both
518
519    Ng_GetSurfaceList sollist
520    foreach el $sollist {
521	$w.sul.list insert end $el }
522
523
524
525
526
527    frame $w.topl -borderwidth .5c
528    listbox $w.topl.list -yscroll "$w.topl.scroll set" -setgrid 1 -height 12 \
529	-command { puts hi }
530    scrollbar $w.topl.scroll -command "$w.topl.list yview"
531    pack $w.topl.scroll -side right -fill y
532    pack $w.topl.list -side left -expand 1 -fill both
533
534    Ng_TopLevel getlist sollist
535    puts $sollist
536    foreach el $sollist {
537	set hel "[ lindex $el 0 ]"
538	if { [ llength $el ] == 2 } {
539	    set hel "[ lindex $el 1 ] on [ lindex $el 0 ]"
540	}
541	$w.topl.list insert end $hel
542    }
543
544
545    frame $w.bu
546
547    ttk::button $w.bu.close -text "close" -command {
548	destroy $w
549    }
550    ttk::button $w.bu.addsol -text "Add Solid" -command {
551	set solname [$w.sol.list get active]
552	Ng_TopLevel set $solname ""
553	Ng_ParseGeometry
554	$w.topl.list insert end $solname
555    }
556
557    ttk::button $w.bu.addsurf -text "Add Surface" -command {
558	set solname [$w.sol.list get active]
559	set surfname [$w.sul.list get active]
560	Ng_TopLevel set $solname $surfname
561	Ng_ParseGeometry
562	puts "$solname on $surfname"
563	$w.topl.list insert end "$surfname on $solname"
564    }
565
566    ttk::button $w.bu.remsol -text "Remove" -command {
567	set solname [$w.topl.list get active]
568	set surfname ""
569	if { [llength $solname] == 3 } {
570	    set surfname [lindex $solname 0]
571	    set solname [lindex $solname 2]
572	}
573	Ng_TopLevel remove $solname $surfname
574	Ng_ParseGeometry
575	$w.topl.list delete active
576    }
577
578    ttk::button $w.bu.prop -text "Properties" -command {
579	set solname [$w.topl.list get active]
580	set surfname ""
581	if { [llength $solname] == 3 } {
582	    set surfname [lindex $solname 0]
583	    set solname [lindex $solname 2]
584	}
585	toplevelproperties tlp $solname $surfname
586    }
587
588
589
590
591    pack  $w.bu.close $w.bu.addsol $w.bu.addsurf $w.bu.remsol $w.bu.prop  -side left
592
593
594    pack $w.bu -side bottom
595    pack $w.sol -side left -expand yes -fill y           ;# listbox
596    pack $w.sul -side left -expand yes -fill y           ;# listbox
597    pack $w.topl -side left -expand yes -fill y           ;# listbox
598
599
600    bind $w <Escape> { $w.bu.close invoke }
601
602    wm withdraw $w
603    wm geom $w +100+100
604    wm deiconify $w
605
606#    grab $w
607    focus $w
608}
609
610
611
612
613
614
615proc topleveldialog2 { } {
616    set w .tl2_dlg
617
618    if {[winfo exists .tl2_dlg] == 1} {
619	wm withdraw $w
620	wm deiconify $w
621	focus $w
622    } {
623	toplevel $w
624
625	global name val sollist
626
627	frame $w.topl -borderwidth .5c
628	listbox $w.topl.list -yscroll "$w.topl.scroll set" -setgrid 1 -height 12
629	scrollbar $w.topl.scroll -command "$w.topl.list yview"
630	pack $w.topl.scroll -side right -fill y
631	pack $w.topl.list -side left -expand 1 -fill both
632
633	Ng_TopLevel getlist sollist
634	puts $sollist
635	set i 1
636	foreach el $sollist {
637	    set hel "$i: [ lindex $el 0 ]"
638	    if { [ llength $el ] == 2 } {
639		set hel "$i: [ lindex $el 1 ] on [ lindex $el 0 ]"
640	    }
641	    incr i
642	    $w.topl.list insert end $hel }
643
644
645	frame $w.bu
646
647	ttk::button $w.bu.close -text "close" -command {
648	    destroy .tl2_dlg
649	}
650
651
652	ttk::button $w.bu.prop -text "Properties" -command {
653	    set solname [.tl2_dlg.topl.list get active]
654	    set surfname ""
655	    if { [llength $solname] == 2 } {
656		set solname [lindex $solname 1]
657	    }
658	    if { [llength $solname] == 4 } {
659		set surfname [lindex $solname 1]
660		set solname [lindex $solname 3]
661	    }
662	    toplevelproperties tlp $solname $surfname
663	}
664
665	pack $w.bu.close $w.bu.prop  -side left
666	pack $w.bu -side bottom
667	pack $w.topl -side left -expand yes -fill y           ;# listbox
668
669	bind .tl2_dlg.topl.list <Double-1> {
670	    set solname [.tl2_dlg.topl.list get  @%x,%y]
671	    set surfname ""
672	    if { [llength $solname] == 2 } {
673		set solname [lindex $solname 1]
674	    }
675	    if { [llength $solname] == 4 } {
676		set surfname [lindex $solname 1]
677		set solname [lindex $solname 3]
678	    }
679	    toplevelproperties tlp $solname $surfname
680	}
681
682	bind .tl2_dlg <Escape> { .tl2_dlg.bu.close invoke }
683
684	wm withdraw $w
685	wm geom $w +100+100
686	wm deiconify $w
687	wm title $w "Top-Level Options"
688	focus $w
689    }
690}
691
692
693
694
695
696