-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsc_surface.pro
1758 lines (1450 loc) · 73.3 KB
/
fsc_surface.pro
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; docformat = 'rst'
;
; NAME:
; FSC_Surface
;
; PURPOSE:
; The purpose of FSC_Surface is to create a window where a surface is displayed. Surfaces
; can be wire-framed, shaded surfaces, and surfaces with texture maps draped on top of
; them, among other types of surfaces. LEFT mouse button rotates the surface, MIDDLE
; mouse button zooms out from the surface, RIGHT mouse button zoom into the surface.
; Clicking on the surface axes will allow the user to move or translate the surface, and
; clicking on the plot title will allow the user to move the title.
;
;******************************************************************************************;
; ;
; Copyright (c) 2010, by Fanning Software Consulting, Inc. All rights reserved. ;
; ;
; Redistribution and use in source and binary forms, with or without ;
; modification, are permitted provided that the following conditions are met: ;
; ;
; * Redistributions of source code must retain the above copyright ;
; notice, this list of conditions and the following disclaimer. ;
; * Redistributions in binary form must reproduce the above copyright ;
; notice, this list of conditions and the following disclaimer in the ;
; documentation and/or other materials provided with the distribution. ;
; * Neither the name of Fanning Software Consulting, Inc. nor the names of its ;
; contributors may be used to endorse or promote products derived from this ;
; software without specific prior written permission. ;
; ;
; THIS SOFTWARE IS PROVIDED BY FANNING SOFTWARE CONSULTING, INC. ''AS IS'' AND ANY ;
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ;
; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT ;
; SHALL FANNING SOFTWARE CONSULTING, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, ;
; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;
; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ;
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;
;******************************************************************************************;
;
PRO CW_Light_Control_Intensity_Events, event
; Handles selection events from the Intensity Value widget.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, infoCarrier, Set_UValue=info, /No_Copy
ENDIF
; Get the info carrier.
parent = Widget_Info(event.id, /Parent)
infoCarrier = Widget_Info(parent, Find_by_UName='CW_LIGHT_CARRIER')
Widget_Control, infoCarrier, Get_UValue=info, /No_Copy
; Get the new intensity value.
info.theIntensity = *event.selection
; Change the intensity of the light.
info.theLight->SetProperty, Intensity=info.theIntensity
; Prepare to send an event that notifies the program.
event_pro = info.event_pro
tlb = info.tlb
top = event.top
parent = info.parent
name = info.name
intensity = info.theIntensity
color = info.theColor
hide = info.theHide
Widget_Control, infoCarrier, Set_UValue=info, /No_Copy
; Send the event.
IF event_pro NE "" THEN BEGIN
eventStruct = {CW_LIGHT_CONTROL, ID:tlb, TOP:parent, HANDLER:0L, $
NAME:name, INTENSITY:intensity, COLOR:color, HIDE:hide}
Widget_Control, parent, Send_Event=eventStruct
ENDIF
END ;------------------------------------------------------------------------------
PRO CW_Light_Control_Events, event
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, infoCarrier, Set_UValue=info, /No_Copy
ENDIF
; Get the info structure.
infoCarrier = Widget_Info(event.handler, Find_By_UName='CW_LIGHT_CARRIER')
Widget_Control, infoCarrier, Get_UValue=info, /No_Copy
; What kind of event is this? Branch appropriately.
Widget_Control, event.id, Get_UValue=thisEvent
CASE thisEvent OF
'COLOR': BEGIN
TVLCT, info.color, info.index
DEVICE, Decomposed=0, Get_Decomposed=theDecomposedState
setcolor_title = Widget_Info(event.id, /UNAME)
thisColor = PickColor(CURRENTCOLOR=info.color, Group_Leader=event.top, Title=setcolor_title)
thisColor = Reform(thisColor, 3, 1)
info.theLight->SetProperty, Color=thisColor
DEVICE, Decomposed=theDecomposedState
info.color = thisColor
END
'RESET': BEGIN
info.theColor = info.origColor
info.theIntensity = info.origIntensity
info.theHide = info.origHide
info.color = info.origColor
info.intensityID->SetSelection, info.origIntensity
IF info.origHide THEN BEGIN
Widget_Control, info.onButtonID, Set_Button=0
Widget_Control, info.offButtonID, Set_Button=1
ENDIF ELSE BEGIN
Widget_Control, info.onButtonID, Set_Button=1
Widget_Control, info.offButtonID, Set_Button=0
ENDELSE
info.theLight->SetProperty, Intensity=info.origIntensity, $
Color=info.origColor, Hide=info.origHide
END
'ON': BEGIN
info.theHide = 0
info.theLight->SetProperty, Hide=0
END
'OFF': BEGIN
info.theHide = 1
info.theLight->SetProperty, Hide=1
END
ENDCASE
; Prepare to send an event if requested.
event_pro = info.event_pro
tlb = info.tlb
top = event.top
parent = info.parent
name = info.name
intensity = info.theIntensity
color = info.theColor
hide = info.theHide
Widget_Control, infoCarrier, Set_UValue=info, /No_Copy
; Send the event.
IF event_pro NE "" THEN BEGIN
eventStruct = {CW_LIGHT_CONTROL, ID:tlb, TOP:parent, HANDLER:0L, $
NAME:name, INTENSITY:intensity, COLOR:color, HIDE:hide}
Widget_Control, parent, Send_Event=eventStruct
ENDIF
END ;------------------------------------------------------------------------------
FUNCTION CW_Light_Control, parent, theLight, Name=name, UValue=uvalue, Event_Pro=event_pro, $
LabelSize=labelsize, Index=index, Color=color, SETCOLOR_NAME=setColor_name
; This is a compound widget that allows one to manipulate various
; properties of light objects.
On_Error, 2
; Check parameters. Define defaults if necessary.
IF N_Elements(parent) EQ 0 THEN Message, 'Parent widget parameter is required 1st parameter.'
IF (N_Elements(theLight) EQ 0) OR (Size(theLight, /TName) NE 'OBJREF') THEN $
Message, 'Light Object Reference is required 2nd parameter.'
IF N_Elements(uvalue) EQ 0 THEN uvalue = "LIGHT_CONTROL"
IF N_Elements(event_pro) EQ 0 THEN event_pro = ""
IF N_Elements(index) EQ 0 THEN index = !D.Table_Size-2
IF N_Elements(setcolor_name) EQ 0 THEN setcolor_name = ""
IF N_Elements(color) EQ 0 THEN BEGIN
TVLCT, r, g, b, /Get
color = Reform([r[index], g[index], b[index]], 1, 3)
ENDIF ELSE color = Reform(color, 1, 3)
TVLCT, color, index
; Set the light properties.
theLight->GetProperty, Intensity=theIntensity, Hide=theHide, Color=theColor
IF N_Elements(name) EQ 0 THEN name = 'Light'
; Create the widgets.
tlb = Widget_Base(parent, Row=1, Base_Align_Center=1, $
Event_Pro='CW_Light_Control_Events')
IF N_Elements(labelsize) NE 0 THEN $
labelID = Widget_Label(tlb, Value=name + ': ', UNAME='CW_LIGHT_CARRIER', XSize=labelsize) ELSE $
labelID = Widget_Label(tlb, Value=name + ': ', UNAME='CW_LIGHT_CARRIER')
exBaseID = Widget_Base(tlb, Row=1, /Exclusive, /Frame)
onButtonID = Widget_Button(exBaseID, Value='On', UValue='ON')
offButtonID = Widget_Button(exBaseID, Value='Off', UValue='OFF')
IF theHide THEN Widget_Control, offbuttonID, /Set_Button ELSE $
Widget_Control, onbuttonID, /Set_Button
intensityValues = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
intensityID = FSC_Droplist(tlb, Title='Intensity:', Value = intensityValues, $
Event_Pro='CW_Light_Control_Intensity_Events', Format='(F3.1)', Spaces=[1,1])
intensityID->SetSelection, theIntensity
colorID = Widget_Button(tlb, Value='Set Color', UValue='COLOR', UNAME=setcolor_name)
resetID= Widget_Button(tlb, Value='Reset', UValue='RESET')
Widget_Control, tlb, /Realize
; Create info structure with information to run the program. Store it.
info = {theLight:theLight, name:name, theIntensity:theIntensity, theHide:theHide, color:color, $
theColor:theColor, Event_Pro:event_pro, origIntensity:theIntensity, index:index, $
origColor:theColor, origHide:theHide, tlb:tlb, parent:parent, intensityID:intensityID, $
onButtonID:onButtonID, offButtonID:offButtonID}
Widget_Control, labelID, Set_UValue=info, /No_Copy
RETURN, tlb
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Light_Done, event
Widget_Control, event.top, /Destroy
END ;--------------------------------------------------------------------
PRO FSC_Surface_Light_Controls_Event, event
Widget_Control, event.top, Get_UValue=info
info.theWindow->Draw, info.theView
END
;-------------------------------------------------------------------------
PRO FSC_Surface_Light_Controls, event
; Place the light control beside the current widget program.
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.top, TLB_Get_Size=sizes, TLB_Get_Offset=offsets
xpos = sizes[0] + offsets[0] + 10
ypos = offsets[1] + 100
; Lights only make sense with a solid surface.
info.thisSurface->SetProperty, Style=2, Shading=1
info.thisWindow->Draw, info.thisView
; Create widgets.
tlb = Widget_Base(Title='FSC_Surface Light Controls', Column=1, Group_Leader=event.top, $
UValue={theView:info.thisView, theWindow:info.thisWindow}, XOffset=xpos, YOffset=ypos)
dummy = CW_Light_Control(tlb, Name='Non-Rotating Light', info.nonRotatingLight, LabelSize=130, $
Event_Pro='FSC_Surface_Light_Controls_Event', Index=!D.Table_Size-18, Color=[255,255,255], $
SetColor_Name='Color for Non-Rotating Light')
dummy = CW_Light_Control(tlb, Name='Rotating Light', info.rotatingLight, LabelSize=130, $
Event_Pro='FSC_Surface_Light_Controls_Event', Index=!D.Table_Size-19, Color=[255,255,255], $
SetColor_Name='Color for Rotating Light')
dummy = CW_Light_Control(tlb, Name='Fill Light', info.fillLight, LabelSize=130, $
Event_Pro='FSC_Surface_Light_Controls_Event', Index=!D.Table_Size-20, Color=[255,255,255], $
SetColor_Name='Color for Fill Light')
dummy = CW_Light_Control(tlb, Name='Ambient Light', info.ambientLight, LabelSize=130, $
Event_Pro='FSC_Surface_Light_Controls_Event', Index=!D.Table_Size-21, Color=[255,255,255], $
SetColor_Name='Color for Ambient Light')
quit = Widget_Button(tlb, Value='Done', Event_Pro='FSC_Surface_Light_Done')
Widget_Control, tlb, /Realize
XManager, 'FSC_Surface_Light_Controls', tlb, /No_Block, Event_Handler='FSC_Surface_Light_Controls_Event'
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------------
PRO FSC_Surface_Axes_OnOff, event
; This event handler turns the surface axes on or off.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=uvalue
Widget_Control, event.id, Set_Value=uvalue, Set_UValue=buttonValue
CASE buttonValue OF
'Turn Axes ON': BEGIN
info.xaxis -> SetProperty, HIDE=0
info.yaxis -> SetProperty, HIDE=0
info.zaxis -> SetProperty, HIDE=0
END
; Not at all sure why this works!
'Turn Axes OFF': BEGIN
info.xaxis -> SetProperty, HIDE=1
info.yaxis -> SetProperty, HIDE=1
info.zaxis -> SetProperty, HIDE=1
END
ENDCASE
; Draw the graphic display.
info.thisWindow -> Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Bottom_OnOff, event
; This event handler turns the bottom color on or off.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=uvalue
Widget_Control, event.id, Set_Value=uvalue, Set_UValue=buttonValue
CASE buttonValue OF
'Bottom Color ON': info.thisSurface -> SetProperty, Bottom=info.bottom
; Not at all sure why this works!
'Bottom Color OFF': info.thisSurface -> SetProperty, Bottom=info.bottomOffPtr
ENDCASE
; Draw the graphic display.
info.thisWindow -> Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Change_Colors, event
; This event handler changes color tables for elevation shading.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=buttonUValue
CASE StrUpCase(buttonValue) OF
'TITLE COLOR': BEGIN
title = 'Set Title Color'
color = PickColorName(buttonUValue, TITLE=title, GROUP_LEADER=event.top)
info.tcolor = FSC_Color(color, /Triple, /Row)
info.plottitle -> SetProperty, COLOR=info.tcolor
END
'SURFACE COLOR': BEGIN
title = 'Set Surface Color'
color = PickColorName(buttonUValue, TITLE=title, GROUP_LEADER=event.top)
info.color = FSC_Color(color, /Triple, /Row)
info.thisSurface -> SetProperty, COLOR=info.color
END
'BACKGROUND COLOR': BEGIN
title = 'Set Background Color'
color = PickColorName(buttonUValue, TITLE=title, GROUP_LEADER=event.top)
info.background = FSC_Color(color, /Triple, /Row)
info.thisView -> SetProperty, COLOR=info.background
END
'AXIS COLOR': BEGIN
title = 'Set Axis Color'
color = PickColorName(buttonUValue, TITLE=title, GROUP_LEADER=event.top)
info.axiscolor = FSC_Color(color, /Triple, /Row)
info.xaxis -> SetProperty, COLOR=info.axiscolor
info.yaxis -> SetProperty, COLOR=info.axiscolor
info.zaxis -> SetProperty, COLOR=info.axiscolor
END
'BOTTOM COLOR': BEGIN
title = 'Set Bottom Color'
color = PickColorName(buttonUValue, TITLE=title, GROUP_LEADER=event.top)
info.bottom = FSC_Color(color, /Triple, /Row)
info.thisSurface -> SetProperty, BOTTOM=info.bottom
END
ENDCASE
; Set the user value to new color name.
Widget_Control, event.id, SET_UVALUE=color
; Draw the surface.
info.thisWindow -> Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Draw_Events, event
; Draw widget events handled here: expose events and trackball
; events. The trackball uses RSI-supplied TRACKBALL_DEFINE.PRO.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
drawTypes = ['PRESS', 'RELEASE', 'MOTION', 'SCROLL', 'EXPOSE']
thisEvent = drawTypes(event.type)
CASE thisEvent OF
'EXPOSE': BEGIN
; Expose events are NOT blocked by modal widgets, thus, it is possible
; to get an expose event here when it is not expected. This will cause
; an error, since info will be undefined. Check for this condition before
; processing.
IF N_Elements(info) EQ 0 THEN RETURN
END
'PRESS': BEGIN
item = info.thisWindow->Select(info.thisView, [event.x, event.y])
IF Obj_Valid(item[0]) THEN BEGIN
IF Obj_Class(item[0]) EQ 'IDLGRTEXT' THEN BEGIN
Widget_Control, event.id, /CLEAR_EVENTS
Widget_Control, event.id, EVENT_PRO='FSC_SURFACE_MOVE_TITLE'
info.xstart = event.x
info.ystart = event.y
info.selectedItem = item[0]
Widget_Control, event.top, Set_UValue=info, /No_Copy
Widget_Control, event.id, DRAW_MOTION_EVENTS=1
RETURN
ENDIF
IF Obj_Class(item[0]) EQ 'IDLGRAXIS' THEN BEGIN
Widget_Control, event.id, /CLEAR_EVENTS
Widget_Control, event.id, EVENT_PRO='FSC_SURFACE_MOVE_SURFACE'
info.xstart = event.x
info.ystart = event.y
info.selectedItem = item[0]
Widget_Control, event.top, Set_UValue=info, /No_Copy
Widget_Control, event.id, DRAW_MOTION_EVENTS=1
RETURN
ENDIF
ENDIF
; Zoom out on middle, zoom in on right, rotate on left.
possibleButtons = ['NONE', 'LEFT', 'MIDDLE', 'NONE', 'RIGHT']
thisButton = possibleButtons(event.press)
CASE thisButton OF
'RIGHT': BEGIN
info.thisView->GetProperty, Viewplane_Rect=thisRect
thisRect(0) = (thisRect(0) + 0.05) < thisRect(2)
thisRect(1) = (thisRect(1) + 0.05) < thisRect(3)
thisRect(2) = (thisRect(2) - 0.1) > thisRect(0)
thisRect(3) = (thisRect(3) - 0.1) > thisRect(1)
info.thisView->SetProperty, Viewplane_Rect=thisRect
END
'MIDDLE': BEGIN
info.thisView->GetProperty, Viewplane_Rect=thisRect
thisRect(0) = thisRect(0) - 0.05
thisRect(1) = thisRect(1) - 0.05
thisRect(2) = thisRect(2) + 0.1
thisRect(3) = thisRect(3) + 0.1
info.thisView->SetProperty, Viewplane_Rect=thisRect
END
'LEFT': BEGIN
Widget_Control, event.id, Draw_Motion_Events=1 ; Motion events ON.
info.thisWindow->SetProperty, Quality=info.dragQuality ; Set Drag Quality.
END
ELSE:
ENDCASE
END
'RELEASE': BEGIN
Widget_Control, event.id, Draw_Motion_Events=0 ; Motion events OFF.
info.thisWindow->SetProperty, Quality=2 ; Drag Quality to High.
END
'MOTION': BEGIN ; Trackball events
END
ELSE: ; Fall though, don't care.
ENDCASE
; Does the trackball need updating? If so, update.
needUpdate = info.thisTrackball -> Update(event, Transform=thisTransform)
IF needUpdate THEN BEGIN
info.thisModel->GetProperty, Transform=modelTransform
info.thisModel->SetProperty, Transform=modelTransform # thisTransform
ENDIF
; Draw the view. If this program STILL throws floating point exceptions,
; comment this line out and uncomment the code below it. Dishonest as
; all get out, but it works fine. :-)
info.thisWindow->Draw, info.thisView
;currentExcept = !Except
;!Except = 0
;info.thisWindow -> Draw, info.thisView
;dummy = Check_Math()
;!Except = currentExcept
; Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Elevation_Colors, event
; This event handler changes color tables for elevation shading.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What kind of event is this? Could be from Change Colors button
; or from XCOLORS itself.
thisEvent = Tag_Names(event, /Structure_Name)
CASE thisEvent OF
"WIDGET_BUTTON": BEGIN
IF info.colortable EQ -1 THEN BEGIN
TVLCT, info.r, info.g, info.b
ENDIF ELSE BEGIN
CTLoad, info.colortable, BREWER=info.brewer, REVERSE=info.reverse
ENDELSE
Print, 'Info.Reverse set to on button event:', info.reverse
XColors, Group_Leader=event.top, NotifyID=[event.id, event.top], $
Title="FSC_Surface Elevation Shading Colors", BREWER=info.brewer, $
INDEX=info.colortable, REVERSE=info.reverse
ENDCASE
"XCOLORS_LOAD": BEGIN
info.r = event.r
info.g = event.g
info.b = event.b
info.colortable = event.index
info.brewer = event.brewer
info.reverse = event.reversed
Print, 'Info.Reverse set to on XColors event:', info.reverse
IF Obj_Valid(info.colorPalette) THEN info.colorPalette->SetProperty, $
Red=event.r, Green=event.g, Blue=event.b
ENDCASE
ENDCASE
; Draw the graphic display.
info.thisWindow -> Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Elevation_Shading, event
; This event handler sets up elevation shading for the surface.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=uvalue
Widget_Control, event.id, Set_Value=uvalue, Set_UValue=buttonValue
CASE buttonValue OF
'Elevation Shading ON': BEGIN
s = Size(info.data, /Dimensions)
info.zAxis->GetProperty, CRange=zrange
info.thisSurface->SetProperty, Palette=info.colorPalette, $
Vert_Colors=Reform(BytScl(info.data, /NAN, Min=Min(zrange), $
Max=Max(zrange)), s[0]*s[1]), Bottom=info.bottomOffPtr, Specular=""
Widget_Control, info.bottomID, Set_Value='Bottom Color ON'
Widget_Control, info.bottomID, Set_UValue='Bottom Color OFF'
ENDCASE
'Elevation Shading OFF': BEGIN
info.thisSurface->SetProperty, Palette=Obj_New(), Vert_Colors=0, $
Bottom=info.bottom, SPECULAR=info.specularColor
Widget_Control, info.bottomID, Set_Value='Bottom Color OFF'
Widget_Control, info.bottomID, Set_UValue='Bottom Color ON'
ENDCASE
ENDCASE
; Draw the graphic display.
info.thisWindow->Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Exit, event
; Exit the program. This will cause the CLEANUP
; routine to be called automatically.
Widget_Control, event.top, /Destroy
END ;-----------------------------------------------------------------------------------------
PRO FSC_Surface_Move_Surface, event
; This event handler moves the surface.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
drawTypes = ['PRESS', 'RELEASE', 'MOTION', 'SCROLL', 'EXPOSE']
thisEvent = drawTypes(event.type)
CASE thisEvent OF
'RELEASE': BEGIN
Widget_Control, event.id, /CLEAR_EVENTS
Widget_Control, event.id, EVENT_PRO='FSC_SURFACE_DRAW_EVENTS'
Widget_Control, event.id, DRAW_MOTION_EVENTS=0
info.xstart = -1
info.ystart = -1
info.selectedItem = Obj_New()
END
'MOTION': BEGIN
delta_x = (event.x - info.xstart) / Float(info.xsize)
delta_y = (event.y - info.ystart) / Float(info.ysize)
info.thisModel -> Translate, 2*delta_x, 2*delta_y, 0
info.thisWindow -> Draw, info.thisView
info.xstart = event.x
info.ystart = event.y
END
ENDCASE
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Move_Title, event
; This event handler moves the surface title.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
drawTypes = ['PRESS', 'RELEASE', 'MOTION', 'SCROLL', 'EXPOSE']
thisEvent = drawTypes(event.type)
CASE thisEvent OF
'RELEASE': BEGIN
Widget_Control, event.id, /CLEAR_EVENTS
Widget_Control, event.id, EVENT_PRO='FSC_SURFACE_DRAW_EVENTS'
Widget_Control, event.id, DRAW_MOTION_EVENTS=0
info.xstart = -1
info.ystart = -1
info.selectedItem = Obj_New()
END
'MOTION': BEGIN
delta_x = (event.x - info.xstart) / Float(info.xsize)
delta_y = (event.y - info.ystart) / Float(info.ysize)
info.textModel -> Translate, 2*delta_x, 2*delta_y, 0
info.thisWindow -> Draw, info.thisView
info.xstart = event.x
info.ystart = event.y
END
ENDCASE
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Output, event
; This event handler creates GIF and JPEG files.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Get a snapshop of window contents. (TVRD equivalent.)
info.thisWindow->GetProperty, Image_Data=snapshot
; What kind of file is wanted?
Widget_Control, event.id, GET_UValue=whichFileType
CASE whichFileType OF
'GIF': BEGIN
; Because we are using RGB color for this model, we have
; a 3-m-n array. Use Color_Quan to create a 2D image and
; appropriate color tables for the GIF file.
image2D = Color_Quan(snapshot, 1, r, g, b)
filename = Dialog_Pickfile(/Write, File='fsc_surface.gif')
IF filename NE '' THEN Write_GIF, filename, image2d, r, g, b
END
'JPEG': BEGIN
filename = Dialog_Pickfile(/Write, File='fsc_surface.jpg')
IF filename NE '' THEN Write_JPEG, filename, snapshot, True=1, Quality=100
END
'TIFF': BEGIN
filename = Dialog_Pickfile(/Write, File='fsc_surface.tif')
IF filename NE '' THEN BEGIN
; TIFF files should have their Y direction reversed for
; compatibility with most other software.
Write_TIFF, filename, Reverse(snapshot,3)
ENDIF
END
'BMP': BEGIN
filename = Dialog_Pickfile(/Write, File='fsc_surface.bmp')
IF filename NE '' THEN Write_BMP, filename, snapshot
END
'PNG': BEGIN
filename = Dialog_Pickfile(/Write, File='fsc_surface.png')
IF filename NE '' THEN Write_PNG, filename, snapshot
END
'PS': BEGIN
filename = Dialog_Pickfile(/Write, File='fsc_surface.ps')
IF filename NE '' THEN BEGIN
resolution = [2.54, 2.54]/ 600; 600 pixels per inch
viewDimensions = [info.xsize, info.ysize] / 100.0 ; 100 pixels in size = 1 inch
clipboard = Obj_New('IDLgrClipboard', Dimensions=viewDimensions, Resolution=resolution, Unit=1)
clipboard->Draw, info.thisView, /Postscript, Filename=filename, /Vector
Obj_Destroy, clipboard
ENDIF
END
ENDCASE
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Properties, event
; Event handler to set program properties.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What property is wanted?
Widget_Control, event.id, Get_UValue=newProperty
CASE newProperty OF
'ORIGINAL_T3D': info.thisModel->SetProperty, Transform=info.origTransform
'DRAG_LOW': BEGIN
info.dragQuality = 0
Widget_Control, info.dragLowID, Sensitive=0
Widget_Control, info.dragMedID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=1
END
'DRAG_MEDIUM': BEGIN
info.dragQuality = 1
Widget_Control, info.dragMedID, Sensitive=0
Widget_Control, info.dragLowID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=1
END
'DRAG_HIGH': BEGIN
info.dragQuality = 2
Widget_Control, info.dragMedID, Sensitive=1
Widget_Control, info.dragLowID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=0
END
ENDCASE
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Resize, event
; The only events generated by this simple program are resize
; events, which are handled here.
; Get the info structure.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Resize the draw widget. This is the proper way to do this
; in object graphics, but it does not always work in UNIX
; versions of IDL. If it doesn't work for you, comment the
; first line out and try the second. The second line is more
; portable, but not exactly the proper "object" way. :-(
info.thisWindow->SetProperty, Dimension=[event.x, event.y]
;Widget_Control, info.drawID, Draw_XSize=event.x, Draw_YSize=event.y
; Store the new size.
info.xsize = event.x
info.ysize = event.y
; Redisplay the graphic.
info.thisWindow->Draw, info.thisView
; Update the trackball objects location in the center of the window.
info.thisTrackball->Reset, [event.x/2, event.y/2], (event.y/2) < (event.x/2)
; Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO FSC_Surface_Skirt_OnOff, event
; This event handler turns the skirt on or off.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=uvalue
Widget_Control, event.id, Set_Value=uvalue, Set_UValue=buttonValue
CASE buttonValue OF
'Turn Skirt ON': info.thisSurface -> SetProperty, SHOW_SKIRT=1
'Turn Skirt OFF': info.thisSurface -> SetProperty, SHOW_SKIRT=0
ENDCASE
; Draw the graphic display.
info.thisWindow -> Draw, info.thisView
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Style, event
; Event handler to select surface style.
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
IF N_Elements(info) NE 0 THEN Widget_Control, event.top, Set_UValue=info, /No_Copy
ENDIF
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Make sure lights are turned on.
info.nonRotatingLight->SetProperty, Hide=0
info.rotatingLight->SetProperty, Hide=0
info.fillLight->SetProperty, Hide=0
info.ambientLight->SetProperty, Hide=0
info.thisSurface->SetProperty, Color=info.color
; What style is wanted?
Widget_Control, event.id, Get_UValue=newStyle
CASE newStyle OF
'DOTS': info.thisSurface->SetProperty, Style=0
'MESH': info.thisSurface->SetProperty, Style=1
'SOLID': info.thisSurface->SetProperty, Style=2, Shading=1
'XPARALLEL': info.thisSurface->SetProperty, Style=3
'YPARALLEL': info.thisSurface->SetProperty, Style=4
'WIRELEGO': info.thisSurface->SetProperty, Style=5
'SOLIDLEGO': info.thisSurface->SetProperty, Style=6
'HIDDEN': BEGIN
Widget_Control, event.id, Get_Value=buttonValue
IF buttonValue EQ 'Hidden Lines OFF' THEN BEGIN
setting = 0
hlvalue = 'Hidden Lines ON'
ENDIF ELSE BEGIN
setting = 1
hlvalue = 'Hidden Lines OFF'
ENDELSE
Widget_Control, event.id, Set_Value=hlvalue
info.thisSurface->SetProperty, Hidden_Lines=setting
ENDCASE
ENDCASE
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
; Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END ;------------------------------------------------------------------------------
PRO FSC_Surface_Cleanup, tlb
; Come here when program dies. Free all created objects.
Widget_Control, tlb, Get_UValue=info
IF N_Elements(info) NE 0 THEN BEGIN
Ptr_Free, info.bottomOffPtr
Obj_Destroy, info.thisContainer
ENDIF
END ;------------------------------------------------------------------------------
FUNCTION FSC_Surface_Aspect, aspectRatio, MARGIN=margin, WindowAspect=wAspectRatio
; This function calculates the correct aspect ratio for display.
ON_ERROR, 2
; Check for aspect ratio parameter and possibilities.
IF N_PARAMS() EQ 0 THEN aspectRatio = 1.0
IF aspectRatio EQ 0 THEN BEGIN
MESSAGE, 'Aspect Ratio of 0. Changing to 1...', /Informational
aspectRatio = 1.0
ENDIF
s = SIZE(aspectRatio)
IF s(s(0)+1) NE 4 THEN $
MESSAGE, 'Aspect Ratio is not a FLOAT. Take care...', /Informational
; Check for margins.
IF N_ELEMENTS(margin) EQ 0 THEN margin = 0
; Error checking.
IF margin LT 0 OR margin GE 0.5 THEN $
MESSAGE, 'The MARGIN keyword value must be between 0.0 and 0.5.'
; Calculate the aspect ratio of the current window.
IF N_Elements(wAspectRatio) EQ 0 THEN wAspectRatio = FLOAT(!D.Y_VSIZE) / !D.X_VSIZE
; Calculate normalized positions in window.