-
Notifications
You must be signed in to change notification settings - Fork 16
/
XYPlotWin.cpp
2534 lines (2248 loc) · 77.5 KB
/
XYPlotWin.cpp
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
// ---------------------------------------------------------------
// XYPlotWin.cpp
// ---------------------------------------------------------------
#include <AMReX_ParallelDescriptor.H>
#include <Xm/AtomMgr.h>
#include <Xm/Protocols.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeB.h>
#include <Xm/PushBG.h>
#include <Xm/PushB.h>
#include <Xm/CascadeBG.h>
#include <Xm/Frame.h>
#include <Xm/ScrolledW.h>
#include <Xm/DrawingA.h>
#include <Xm/Text.h>
#include <Xm/DialogS.h>
#include <Xm/LabelG.h>
#include <Xm/ToggleBG.h>
#include <Xm/ToggleB.h>
#include <Xm/FileSB.h>
#include <Xm/MessageB.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <XYPlotWin.H>
#include <AVPApp.H>
#include <PltApp.H>
#include <PltAppState.H>
#include <GraphicsAttributes.H>
#include <AMReX_AmrData.H>
#include <AMReX_DataServices.H>
#include <iostream>
#include <iomanip>
#include <limits>
#include <cmath>
#include <cstdlib>
using std::setw;
using std::cout;
using std::cerr;
using std::endl;
using namespace amrex;
#define MARK (fprintf(stderr, "Mark at file %s, line %d.\n", __FILE__, __LINE__))
#define nlog10(x) (x == 0.0 ? 0.0 : log10(x) + 1e-15)
// Hack fix for compiler bug for window manager calls
#ifndef FALSE
#define FALSE false
#endif
// Bitmap data for various data mark styles
static char markBits[8][8] = {
{0x00, 0x00, 0x1c, 0x1c, 0x1c, 0x00, 0x00, 0x00},
{0x00, 0x3e, 0x22, 0x22, 0x22, 0x3e, 0x00, 0x00},
{0x00, 0x1c, 0x36, 0x22, 0x36, 0x1c, 0x00, 0x00},
{0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00},
{0x00, 0x08, 0x14, 0x22, 0x14, 0x08, 0x00, 0x00},
{0x00, 0x1c, 0x14, 0x1c, 0x14, 0x1c, 0x00, 0x00},
{0x00, 0x1c, 0x2a, 0x36, 0x2a, 0x1c, 0x00, 0x00},
{0x00, 0x3e, 0x1c, 0x08, 0x1c, 0x3e, 0x00, 0x00}
};
static param_style param_null_style = {STYLE, 0, (char *) 0};
#include <cctype>
using std::endl;
// Some macros for obtaining parameters.
#define PM_INT(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.intv.value : (BL_ASSERT(0), (int) 0))
#define PM_STRING(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.strv.value : (BL_ASSERT(0), (char *) 0))
#define PM_COLOR(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.pixv.value : (BL_ASSERT(0), param_null_color))
#define PM_FONT(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.fontv.value : (BL_ASSERT(0), (XFontStruct *) 0))
#define PM_STYLE(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.stylev : (BL_ASSERT(0), param_null_style))
#define PM_BOOL(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.boolv.value : (BL_ASSERT(0), 0))
#define PM_DBL(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
param_temp.dblv.value : (BL_ASSERT(0), 0.0))
#define PM_PIXEL(name) ((parameters->Get_Parameter(const_cast<char *>(name), ¶m_temp)) ? \
pal->makePixel(param_temp.pixv.iColorMapSlot) : (BL_ASSERT(0), (Pixel) 0))
// -------------------------------------------------------------------
XYPlotWin::~XYPlotWin() {
if(pltParent->PaletteCBQ()) {
XtRemoveAllCallbacks(pltParent->GetPalArea(), XmNinputCallback);
pltParent->SetPaletteCBQ(false);
}
if(pltParent->GetXYPlotWin(whichType) == this) {
pltParent->DetachXYPlotWin(whichType);
}
CBdoClearData(None, NULL, NULL);
if(wOptionsDialog != None) {
XtDestroyWidget(wOptionsDialog);
}
if(wExportFileDialog != None) {
XtDestroyWidget(wExportFileDialog);
}
XtDestroyWidget(wXYPlotTopLevel);
delete gaPtr;
delete [] Xsegs[0];
delete [] Xsegs[1];
delete [] XUnitText;
delete [] YUnitText;
delete [] formatY;
delete [] formatX;
delete [] pltTitle;
// delete all the call back parameter structs
int nSize;
for(nSize = 0; nSize < xycbdPtrs.size(); ++nSize) {
delete xycbdPtrs[nSize];
}
for(nSize = 0; nSize < xymenucbdPtrs.size(); ++nSize) {
delete xymenucbdPtrs[nSize];
}
colorChangeItem = nullptr;
pltParent = nullptr;
}
// -------------------------------------------------------------------
XYPlotWin::XYPlotWin(char *title, XtAppContext app, Widget w, AVPApp *parent,
int type, int curr_frame)
: appContext(app),
wTopLevel(w),
pltParent(parent),
whichType(type),
currFrame(curr_frame)
{
int idx;
char buffer[Amrvis::BUFSIZE];
pltTitle = new char[strlen(title) + 1];
strcpy(pltTitle, title);
params param_temp; // temporary parameter grabbing slot
colorChangeItem = nullptr;
// Store some local stuff from the parent.
parameters = pltParent->GetXYPlotParameters();
wExportFileDialog = None;
wOptionsDialog = None;
// Standard flags.
zoomedInQ = false;
saveDefaultQ = 0;
animatingQ = false;
#if (BL_SPACEDIM != 3)
currFrame = 0;
#endif
// Create empty dataset list.
numDrawnItems = 0;
numItems = 0;
SetBoundingBox();
iCurrHint = 1;
char testc[] = "WM_DELETE_WINDOW";
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(wTopLevel),
//"WM_DELETE_WINDOW", false);
testc, false);
// -------------------------------------------------------- main window
int winOffsetX, winOffsetY;
int winWidth = PM_INT("InitialWindowWidth");
int winHeight = PM_INT("InitialWindowHeight");
if(whichType == Amrvis::XDIR) {
winOffsetX = PM_INT("InitialXWindowOffsetX");
winOffsetY = PM_INT("InitialXWindowOffsetY");
} else if(whichType == Amrvis::YDIR) {
winOffsetX = PM_INT("InitialYWindowOffsetX");
winOffsetY = PM_INT("InitialYWindowOffsetY");
} else {
winOffsetX = PM_INT("InitialZWindowOffsetX");
winOffsetY = PM_INT("InitialZWindowOffsetY");
}
sprintf(buffer, "%s %c Value 1D plot", pltTitle, whichType + 'X');
wXYPlotTopLevel = XtVaCreatePopupShell(buffer, topLevelShellWidgetClass,
wTopLevel,
XmNscrollingPolicy, XmAUTOMATIC,
XmNdeleteResponse, XmDO_NOTHING,
XmNx, winOffsetX,
XmNy, winOffsetY,
NULL);
XmAddWMProtocolCallback(wXYPlotTopLevel, WM_DELETE_WINDOW,
(XtCallbackProc) CBcloseXYPlotWin,
(XtPointer) this);
Widget wControlArea, wLegendArea;
Widget wExportButton, wOptionsButton, wCloseButton;
Widget wAllButton, wNoneButton, wClearButton;
XmString label_str1, label_str2, label_str3;
wControlArea = XtVaCreateManagedWidget("controlArea", xmFormWidgetClass,
wXYPlotTopLevel,
NULL);
// -------------------------------------------------------- legend
wLegendArea = XtVaCreateManagedWidget("legendarea", xmFormWidgetClass,
wControlArea,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
wLegendMenu = XtVaCreateManagedWidget("legendmenu", xmFormWidgetClass,
wLegendArea,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
label_str1 = XmStringCreateSimple(const_cast<char *> ("Export"));
label_str2 = XmStringCreateSimple(const_cast<char *> ("Options"));
label_str3 = XmStringCreateSimple(const_cast<char *> ("Close"));
wExportButton = XtVaCreateManagedWidget("Export", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str1,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
AddStaticCallback(wExportButton, XmNactivateCallback,
&XYPlotWin::CBdoExportFileDialog, NULL);
wOptionsButton = XtVaCreateManagedWidget("options", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str2,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, wExportButton,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
AddStaticCallback(wOptionsButton, XmNactivateCallback,
&XYPlotWin::CBdoOptions, NULL);
wCloseButton = XtVaCreateManagedWidget("close", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str3,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, wOptionsButton,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
XtAddCallback(wCloseButton, XmNactivateCallback,
(XtCallbackProc) CBcloseXYPlotWin, (XtPointer) this);
XmStringFree(label_str1);
XmStringFree(label_str2);
XmStringFree(label_str3);
label_str1 = XmStringCreateSimple(const_cast<char *>("All"));
label_str2 = XmStringCreateSimple(const_cast<char *>("None"));
label_str3 = XmStringCreateSimple(const_cast<char *>("Clear"));
wAllButton = XtVaCreateManagedWidget("All", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str1,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wExportButton,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
AddStaticCallback(wAllButton, XmNactivateCallback,
&XYPlotWin::CBdoSelectAllData, NULL);
wNoneButton = XtVaCreateManagedWidget("None", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str2,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, wAllButton,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wOptionsButton,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
AddStaticCallback(wNoneButton, XmNactivateCallback,
&XYPlotWin::CBdoDeselectAllData, NULL);
wClearButton = XtVaCreateManagedWidget("Clear", xmPushButtonGadgetClass,
wLegendMenu,
XmNlabelString, label_str3,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, wNoneButton,
XmNleftOffset, 2,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wCloseButton,
XmNtopOffset, 2,
XmNwidth, 60,
NULL);
AddStaticCallback(wClearButton, XmNactivateCallback,
&XYPlotWin::CBdoClearData, NULL);
XmStringFree(label_str1);
XmStringFree(label_str2);
XmStringFree(label_str3);
wScrollArea = XtVaCreateManagedWidget("scrollArea", xmScrolledWindowWidgetClass,
wLegendArea,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, wLegendMenu,
XmNtopOffset, 2,
XmNscrollingPolicy, XmAUTOMATIC,
NULL);
wLegendButtons = XtVaCreateManagedWidget("legendbuttons", xmFormWidgetClass,
wScrollArea,
NULL);
XtVaSetValues(wScrollArea, XmNworkWindow, wLegendButtons, NULL);
XtManageChild(wLegendMenu);
XtManageChild(wLegendButtons);
XtManageChild(wScrollArea);
XtManageChild(wLegendArea);
// PLOT
wPlotWin = XtVaCreateManagedWidget("plotwin", xmDrawingAreaWidgetClass,
wControlArea,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, wLegendArea,
XmNwidth, winWidth,
XmNheight, winHeight,
NULL);
AddStaticCallback(wPlotWin, XmNexposeCallback,
&XYPlotWin::CBdoDrawPlot, NULL);
AddStaticCallback(wPlotWin, XmNresizeCallback,
&XYPlotWin::CBdoRedrawPlot, NULL);
AddStaticCallback(wPlotWin, XmNinputCallback,
&XYPlotWin::CBdoRubberBanding, NULL);
AddStaticEventHandler(wPlotWin, PointerMotionMask | LeaveWindowMask,
&XYPlotWin::CBdoDrawLocation, NULL);
XtManageChild(wPlotWin);
XtManageChild(wControlArea);
XtPopup(wXYPlotTopLevel, XtGrabNone);
pWindow = XtWindow(wPlotWin);
SetPalette();
gaPtr = new GraphicsAttributes(wXYPlotTopLevel);
disp = gaPtr->PDisplay();
vis = gaPtr->PVisual();
if(vis != XDefaultVisual(disp, gaPtr->PScreenNumber())) {
XtVaSetValues(wXYPlotTopLevel, XmNvisual, vis, XmNdepth, 8, NULL);
}
cursor = XCreateFontCursor(disp, XC_left_ptr);
zoomCursor = XCreateFontCursor(disp, XC_sizing);
XtVaGetValues(wPlotWin,
XmNforeground, &foregroundPix,
XmNbackground, &backgroundPix,
NULL);
Palette *pal = pltParent->GetPalettePtr();
gridPix = PM_PIXEL("GridColor");
textPix = PM_PIXEL("TextColor");
labeltextFont = PM_FONT("LabelFont");
titletextFont = PM_FONT("TitleFont");
// gc's for labels and titles, rubber banding, segments, and dots.
XGCValues gcvals;
gcvals.font = labeltextFont->fid;
gcvals.foreground = textPix;
labeltextGC = XCreateGC(disp, pWindow, GCFont | GCForeground, &gcvals);
gcvals.font = titletextFont->fid;
titletextGC = XCreateGC(disp, pWindow, GCFont | GCForeground, &gcvals);
gcvals.function = GXxor;
rbGC = XCreateGC(disp, gaPtr->PRoot(), GCFunction, &gcvals);
segGC = XCreateGC(disp, gaPtr->PRoot(), 0, NULL);
dotGC = XCreateGC(disp, gaPtr->PRoot(), 0, NULL);
// Allocate space for XSegment's
numXsegs = NUM_INIT_XSEGS;
Xsegs[0] = new XSegment[numXsegs];
Xsegs[1] = new XSegment[numXsegs];
// Get parameters and attributes out of parameters database
// and initialize bitmaps for line styles
markQ = PM_BOOL("Markers");
tickQ = PM_BOOL("Ticks");
axisQ = PM_BOOL("TickAxis");
boundBoxQ = PM_BOOL("BoundBox");
plotLinesQ = PM_BOOL("PlotLines");
dispHintsQ = PM_BOOL("DisplayHints");
gridW = PM_INT("GridWidth");
lineW = PM_INT("LineWidth");
dotW = PM_INT("DotWidth");
char *str;
if(whichType == Amrvis::XDIR) {
str = PM_STRING("XUnitTextX");
} else if(whichType == Amrvis::YDIR) {
str = PM_STRING("XUnitTextY");
} else {
str = PM_STRING("XUnitTextZ");
}
XUnitText = new char[strlen(str) + 1];
strcpy(XUnitText, str);
str = PM_STRING("YUnitText");
YUnitText = new char[strlen(str) + 1];
strcpy(YUnitText, str);
str = PM_STRING("FormatX");
formatX = new char[strlen(str) + 1];
strcpy(formatX, str);
str = PM_STRING("FormatY");
formatY = new char[strlen(str) + 1];
strcpy(formatY, str);
gridStyle = PM_STYLE("GridStyle");
for(idx = 0; idx < 8; ++idx) {
sprintf(buffer, "%d.Style", idx);
parameters->Get_Parameter(buffer, ¶m_temp);
AllAttrs[idx].lineStyleLen = param_temp.stylev.len;
strncpy(AllAttrs[idx].lineStyle, param_temp.stylev.dash_list,
param_temp.stylev.len);
AllAttrs[idx].markStyle =
XCreateBitmapFromData(disp, pWindow, markBits[idx], 8, 8);
}
for(idx = 0; idx != 8; ++idx) {
lineFormats[idx] = 0x0;
}
// Set up the device information structure.
devInfo.maxSegs = numXsegs;
devInfo.areaW = devInfo.areaH = 0; // Set later
devInfo.bdrPad = BORDER_PADDING;
devInfo.axisPad = AXIS_PADDING;
devInfo.tickLen = TICKLENGTH;
devInfo.axisW = XTextWidth(labeltextFont, "8", 1);
devInfo.titleW = XTextWidth(titletextFont, "8", 1);
devInfo.axisH = labeltextFont->max_bounds.ascent +
labeltextFont->max_bounds.descent;
devInfo.titleH = titletextFont->max_bounds.ascent +
titletextFont->max_bounds.descent;
xycbdPtrs.reserve(512); // arbitrarily
xymenucbdPtrs.reserve(512); // arbitrarily
}
#if (BL_SPACEDIM != 3)
// -------------------------------------------------------------------
void XYPlotWin::InitializeAnimation(int curr_frame, int num_frames) {
if(animatingQ) {
return;
}
PltAppState *pas = pltParent->GetPltAppState();
Real gmin(std::numeric_limits<Real>::max());
Real gmax(std::numeric_limits<Real>::lowest());
Real fmin, fmax;
animatingQ = true;
currFrame = curr_frame;
numFrames = num_frames;
for(list<XYPlotLegendItem *>::iterator ptr = legendList.begin();
ptr != legendList.end(); ++ptr)
{
if((*ptr)->XYPLIlist->CopiedFrom() != NULL) {
::XYPlotDataList *tempList = (*ptr)->XYPLIlist;
(*ptr)->XYPLIlist = pltParent->CreateLinePlot(Amrvis::ZPLANE, whichType,
(*ptr)->XYPLIlist->MaxLevel(),
(*ptr)->XYPLIlist->Gridline(),
&((*ptr)->XYPLIlist->DerivedName()));
delete tempList;
}
(*ptr)->anim_lists = new Vector<::XYPlotDataList *>(numFrames);
(*ptr)->ready_list = new Vector<char>(numFrames, 0);
// =================
string sDerName = (*ptr)->XYPLIlist->DerivedName();
const AmrData &amrData = pltParent->GetDataServicesPtr()->AmrDataRef();
int snum = amrData.StateNumber(sDerName);
Amrvis::MinMaxRangeType mmrt = pas->GetMinMaxRangeType();
for(int iframe(0); iframe < numFrames; ++iframe) {
pas->GetMinMax(mmrt, iframe, snum, fmin, fmax);
gmin = std::min(gmin, fmin);
gmax = std::max(gmax, fmax);
}
// =================
}
lloY = gmin;
hhiY = gmax;
if(zoomedInQ == false) {
SetBoundingBox();
CBdoRedrawPlot(None, NULL, NULL);
}
}
// -------------------------------------------------------------------
void XYPlotWin::UpdateFrame(int frame) {
::XYPlotDataList *tempList;
int num_lists_changed(0);
char buffer[Amrvis::BUFSIZE];
sprintf(buffer, "%s %c Value 1D plot",
AVGlobals::StripSlashes(pltParent->GetFileName()).c_str(),
whichType + 'X');
XtVaSetValues(wXYPlotTopLevel, XmNtitle, buffer, NULL);
if( ! animatingQ && zoomedInQ == false) {
lloY = std::numeric_limits<Real>::max();
hhiY = std::numeric_limits<Real>::lowest();
}
for(list<XYPlotLegendItem *>::iterator ptr = legendList.begin();
ptr != legendList.end(); ++ptr)
{
if((*ptr)->drawQ == true) {
++num_lists_changed;
}
if(animatingQ) {
(*(*ptr)->anim_lists)[currFrame] = (*ptr)->XYPLIlist;
(*(*ptr)->ready_list)[currFrame] = 1;
if((*(*ptr)->ready_list)[frame]) {
(*ptr)->XYPLIlist = (*(*ptr)->anim_lists)[frame];
continue;
}
} else {
tempList = (*ptr)->XYPLIlist;
}
int level((*ptr)->XYPLIlist->CurLevel());
(*ptr)->XYPLIlist = pltParent->CreateLinePlot(Amrvis::ZPLANE, whichType,
(*ptr)->XYPLIlist->MaxLevel(),
(*ptr)->XYPLIlist->Gridline(),
&(*ptr)->XYPLIlist->DerivedName());
(*ptr)->XYPLIlist->SetLevel(level);
(*ptr)->XYPLIlist->UpdateStats();
if((*ptr)->XYPLIlist->NumPoints() > numXsegs) {
numXsegs = (*ptr)->XYPLIlist->NumPoints() + 5;
delete [] Xsegs[0];
Xsegs[0] = new XSegment[numXsegs];
delete [] Xsegs[1];
Xsegs[1] = new XSegment[numXsegs];
}
if( ! animatingQ) {
delete tempList;
if(zoomedInQ == false && (*ptr)->drawQ == true) {
UpdateBoundingBox((*ptr)->XYPLIlist);
}
}
}
currFrame = frame;
if(num_lists_changed == 0) {
return;
}
if(animatingQ) {
clearData();
drawGridAndAxis();
drawData();
} else {
if(zoomedInQ == false) {
SetBoundingBox();
}
CBdoRedrawPlot(None, NULL, NULL);
}
}
// -------------------------------------------------------------------
void XYPlotWin::StopAnimation() {
if( ! animatingQ) {
return;
}
animatingQ = false;
for(list<XYPlotLegendItem *>::iterator ptr = legendList.begin();
ptr != legendList.end(); ++ptr)
{
for(int ii(0); ii != numFrames; ++ii) {
if((*(*ptr)->ready_list)[ii] &&
(*(*ptr)->anim_lists)[ii] != (*ptr)->XYPLIlist)
{
delete (*(*ptr)->anim_lists)[ii];
}
}
delete (*ptr)->ready_list;
delete (*ptr)->anim_lists;
}
lloY = std::numeric_limits<Real>::max();
hhiY = std::numeric_limits<Real>::lowest();
for(list<XYPlotLegendItem *>::iterator ptr = legendList.begin();
ptr != legendList.end(); ++ptr)
{
if((*ptr)->drawQ == true) {
UpdateBoundingBox((*ptr)->XYPLIlist);
}
}
if(zoomedInQ == false) {
SetBoundingBox();
CBdoRedrawPlot(None, NULL, NULL);
}
}
#endif
// -------------------------------------------------------------------
#define TRANX(xval) (((double) ((xval) - iXOrgX)) * dXUnitsPerPixel + dUsrOrgX)
#define TRANY(yval) (dUsrOppY - (((double) ((yval) - iXOrgY)) * dYUnitsPerPixel))
#define SCREENX(userX) \
(((int) (((userX) - dUsrOrgX)/dXUnitsPerPixel + 0.5)) + iXOrgX)
#define SCREENY(userY) \
(iXOppY - ((int) (((userY) - dUsrOrgY)/dYUnitsPerPixel + 0.5)))
// (iXOppY - ((int) (log10(((userY) - dUsrOrgY)/dYUnitsPerPixel + 0.5))))
// -------------------------------------------------------------------
void XYPlotWin::SetBoundingBox(double lowXIn, double lowYIn,
double highXIn, double highYIn)
{
//cout << "?????????????? >>>>>> _in XYPlotWin::SetBoundingBox" << endl;
//cout << "lowXIn lowYIn highXIn highYIn = " << lowXIn << " " << lowYIn << " " << highXIn << " " << highYIn << endl;
//cout << "lloX lloY hhiX hhiY = " << lloX << " " << lloY << " " << hhiX << " " << hhiY << endl;
double pad;
if(highXIn > lowXIn) {
loX = lowXIn;
hiX = highXIn;
} else {
if(numDrawnItems == 0) {
loX = -1.0;
loY = -1.0;
hiX = 1.0;
hiY = 1.0;
lloX = std::numeric_limits<Real>::max();
lloY = std::numeric_limits<Real>::max();
hhiX = std::numeric_limits<Real>::lowest();
hhiY = std::numeric_limits<Real>::lowest();
return;
}
loX = lloX;
hiX = hhiX;
}
if(highYIn > lowYIn) {
loY = lowYIn;
hiY = highYIn;
} else {
loY = lloY;
hiY = hhiY;
}
// Increase the padding for aesthetics
if(hiX - loX == 0.0) {
pad = std::max(0.5, std::fabs(hiX * 0.5));
hiX += pad;
loX -= pad;
}
if(hiY - loY == 0.0) {
pad = std::max(0.5, std::fabs(hiY * 0.5));
hiY += pad;
loY -= pad;
}
if(zoomedInQ == false) {
// Add 10% padding to bounding box
pad = (hiX - loX) * 0.05;
loX -= pad;
hiX += pad;
pad = (hiY - loY) * 0.05;
loY -= pad;
hiY += pad;
}
//cout << "loX loY hiX hiY = " << loX << " " << loY << " " << hiX << " " << hiY << endl;
//cout << "?????????????? <<<<<< _out XYPlotWin::SetBoundingBox" << endl;
}
// -------------------------------------------------------------------
void XYPlotWin::CBdoRedrawPlot(Widget /*w*/, XtPointer, XtPointer) {
XClearWindow(disp, pWindow);
CBdoDrawPlot(None, NULL, NULL);
}
// -------------------------------------------------------------------
void XYPlotWin::CalculateBox() {
XWindowAttributes win_attr;
XGetWindowAttributes(disp, pWindow, &win_attr);
devInfo.areaW = win_attr.width;
devInfo.areaH = win_attr.height;
// Figure out the transformation constants. Draw only if valid.
// First, we figure out the origin in the X window. Above the space we
// have the title and the Y axis unit label. To the left of the space we
// have the Y axis grid labels.
// Here we make an arbitrary label to find out how big an offset we need
char buff[128];
sprintf(buff, formatY, -200.0);
XCharStruct bb;
int dir, ascent, descent;
XTextExtents(labeltextFont, buff, strlen(buff), &dir, &ascent, &descent, &bb);
iXOrgX = 2 * devInfo.bdrPad + bb.rbearing - bb.lbearing;
if(dispHintsQ) {
iXOrgY = devInfo.bdrPad + (5 * devInfo.axisH) / 2;
} else {
iXOrgY = devInfo.bdrPad + (3 * devInfo.axisH) / 2;
}
// Now we find the lower right corner. Below the space we have the X axis
// grid labels. To the right of the space we have the X axis unit label
// and the legend. We assume the worst case size for the unit label.
iXOppX = devInfo.areaW - devInfo.bdrPad - devInfo.axisW;
iXOppY = devInfo.areaH - devInfo.bdrPad - (2 * devInfo.axisH);
iXLocWinX = devInfo.bdrPad + (30 * devInfo.axisW);
iXLocWinY = devInfo.areaH - devInfo.bdrPad - devInfo.axisH;
// Is the drawing area too small?
if((iXOrgX >= iXOppX) || (iXOrgY >= iXOppY)) {
return;
}
// We now have a bounding box for the drawing region. Figure out the units
// per pixel using the data set bounding box.
dXUnitsPerPixel = (hiX - loX) / ((double) (iXOppX - iXOrgX));
dYUnitsPerPixel = (hiY - loY) / ((double) (iXOppY - iXOrgY));
// Find origin in user coordinate space. We keep the center of the
// original bounding box in the same place.
double bbCenX((loX + hiX) * 0.5);
double bbCenY((loY + hiY) * 0.5);
double bbHalfWidth(((double) (iXOppX - iXOrgX)) * 0.5 * dXUnitsPerPixel);
double bbHalfHeight(((double) (iXOppY - iXOrgY)) * 0.5 * dYUnitsPerPixel);
dUsrOrgX = bbCenX - bbHalfWidth;
dUsrOrgY = bbCenY - bbHalfHeight;
dUsrOppX = bbCenX + bbHalfWidth;
dUsrOppY = bbCenY + bbHalfHeight;
}
// -------------------------------------------------------------------
void XYPlotWin::CBdoDrawPlot(Widget, XtPointer, XtPointer) {
CalculateBox();
// Everything is defined so we can now use the SCREENX and SCREENY
// transformations.
drawGridAndAxis();
drawData();
if(dispHintsQ) {
drawHint();
}
XFlush(disp);
}
// -------------------------------------------------------------------
void XYPlotWin::AddDataList(::XYPlotDataList *new_list,
XYPlotLegendItem *insert_after)
{
if(++numItems > 64) {
// Too many data lists to assign unique color/style. Delete.
PrintMessage(const_cast<char *>("Too many lines in plotter!\n"));
numItems = 64;
delete new_list;
return;
}
// Find a unique color and style.
int i, j;
char mask;
for(i = 0; lineFormats[i] == 0xff; ++i) {
; // do nothing
}
for(j = 0, mask = 0x1; lineFormats[i] & mask; ++j, mask = mask << 1) {
; // do nothing
}
XYPlotLegendItem *new_item = new XYPlotLegendItem;
new_item->XYPLIlist = new_list;
lineFormats[i] |= mask;
new_item->style = i;
new_item->color = j;
new_item->pixel = AllAttrs[j].pixelValue;
// Append this new list to our data set list.
new_item->frame =
XtVaCreateManagedWidget("frame", xmFrameWidgetClass,
wLegendButtons,
XmNshadowType, XmSHADOW_ETCHED_IN,
XmNhighlightPixmap, NULL,
XmNtopShadowColor, foregroundPix,
XmNbottomShadowColor, foregroundPix,
//XmNtopAttachment, XmATTACH_WIDGET,
XmNtopOffset, 0,
NULL);
new_item->wid = XtVaCreateManagedWidget("button", xmDrawingAreaWidgetClass,
new_item->frame,
XmNwidth, 155,
XmNheight, ((BL_SPACEDIM == 3) ?
(15 + 2 * devInfo.axisH) :
(15 + devInfo.axisH)),
NULL);
pltParent->GetPalettePtr()->SetWindowPalette(pltParent->GetPaletteName(),
XtWindow(new_item->wid));
Widget wid, levelmenu;
char buffer[Amrvis::BUFSIZE];
new_item->menu = XmCreatePopupMenu(new_item->wid, const_cast<char *>("popup"), NULL, 0);
if(new_list->MaxLevel() != 0) {
XmString label_str = XmStringCreateSimple(const_cast<char *>("Level"));
levelmenu = XmCreatePulldownMenu(new_item->menu, const_cast<char *>("pulldown"), NULL, 0);
XtVaCreateManagedWidget("Level", xmCascadeButtonGadgetClass,
new_item->menu,
XmNsubMenuId, levelmenu,
XmNlabelString, label_str,
XmNmnemonic, 'L',
NULL);
XmStringFree(label_str);
for(int ii(0); ii <= new_list->MaxLevel(); ++ii) {
sprintf(buffer, "%d/%d", ii, new_list->MaxLevel());
wid = XtVaCreateManagedWidget(buffer, xmPushButtonGadgetClass,
levelmenu, NULL);
if(ii < 10) {
XtVaSetValues(wid, XmNmnemonic, ii + '0', NULL);
}
XYMenuCBData *xymenucb = new XYMenuCBData(new_item, ii);
int nSize(xymenucbdPtrs.size());
xymenucbdPtrs.resize(nSize + 1);
xymenucbdPtrs[nSize] = xymenucb;
AddStaticCallback(wid, XmNactivateCallback, &XYPlotWin::CBdoSetListLevel,
xymenucb);
}
}
wid = XtVaCreateManagedWidget("Copy", xmPushButtonGadgetClass,
new_item->menu,
XmNmnemonic, 'C',
NULL);
AddStaticCallback(wid, XmNactivateCallback, &XYPlotWin::CBdoCopyDataList,
new_item);
wid = XtVaCreateManagedWidget("Delete", xmPushButtonGadgetClass,
new_item->menu,
XmNmnemonic, 'D',
NULL);
AddStaticCallback(wid, XmNactivateCallback,
&XYPlotWin::CBdoRemoveDataList, new_item);
wChooseColor = XtVaCreateManagedWidget("Choose color", xmPushButtonGadgetClass,
new_item->menu,
XmNmnemonic, 'o',
NULL);
AddStaticCallback(wChooseColor, XmNactivateCallback,
&XYPlotWin::CBdoInitializeListColorChange, new_item);
if(insert_after == NULL) {
new_item->drawQ = true; // Default to draw.
++numDrawnItems;
new_list->UpdateStats(); // Find extremes, number of points.
UpdateBoundingBox(new_list);
if(zoomedInQ == false) {
SetBoundingBox();
}
if(new_list->NumPoints() > numXsegs) {
numXsegs = new_list->NumPoints() + 5;
delete [] Xsegs[0];
Xsegs[0] = new XSegment[numXsegs];
delete [] Xsegs[1];
Xsegs[1] = new XSegment[numXsegs];
}
legendList.push_back(new_item);
} else {
new_item->drawQ = insert_after->drawQ;
if(new_item->drawQ == true) {
++numDrawnItems;
} else {
XtVaSetValues(new_item->frame,
XmNtopShadowColor, backgroundPix,
XmNbottomShadowColor, backgroundPix,
NULL);
}
// find the item
for(list<XYPlotLegendItem *>::iterator ptr = legendList.begin();
ptr != legendList.end(); ++ptr)
{
if((*ptr) == insert_after) {
++ptr; // so we can insert before
legendList.insert(ptr, new_item);
break;
}
}
}
ReattachLegendFrames();
AddStaticCallback(new_item->wid, XmNinputCallback,
&XYPlotWin::CBdoSelectDataList, new_item);
AddStaticCallback(new_item->wid, XmNexposeCallback,
&XYPlotWin::CBdoDrawLegendItem, new_item);
XtManageChild(new_item->frame);
if(new_item->drawQ == true) {
CBdoRedrawPlot(None, NULL, NULL);
}
}
// -------------------------------------------------------------------
void XYPlotWin::ReattachLegendFrames() {
if(legendList.empty()) {
return;
}
list<XYPlotLegendItem *>::iterator liitem = legendList.begin();
XtVaSetValues((*liitem)->frame,
XmNtopAttachment, XmATTACH_FORM,
NULL);
list<XYPlotLegendItem *>::iterator liprevitem = liitem;
++liitem;
while(liitem != legendList.end()) {
XtVaSetValues((*liitem)->frame,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, (*liprevitem)->frame,
NULL);
++liprevitem;
++liitem;
}
}
// -------------------------------------------------------------------
void XYPlotWin::UpdateBoundingBox(::XYPlotDataList *xypdl) {
//cout << "???????????????????? _in XYPlotWin::UpdateBoundingBox" << endl;
if(xypdl->StartX() < lloX) {
lloX = xypdl->StartX();
}
if(xypdl->EndX() > hhiX) {
hhiX = xypdl->EndX();
}
if(xypdl->XYPDLLoY(xypdl->CurLevel()) < lloY) {
lloY = xypdl->XYPDLLoY(xypdl->CurLevel());
}
if(xypdl->XYPDLHiY(xypdl->CurLevel()) > hhiY) {
hhiY = xypdl->XYPDLHiY(xypdl->CurLevel());
}
}
// -------------------------------------------------------------------
double XYPlotWin::InitGrid(double low, double high, double step) {
// Hack fix for graphs of large constant graphs. Sometimes the
// step is too small in comparison to the size of the grid itself,
// and rounding error takes its toll. We "fix" this by multiplying
// the step by an arbitrary number > 1 (1.2) when this happens.
double gridHigh;
int iLoopCheck(0);
while(true) {
dGridStep = roundUp(step);
gridHigh = (ceil(high / dGridStep) + 1.0) * dGridStep;
if(gridHigh + dGridStep != gridHigh) {
break;
}
if(step < DBL_EPSILON) {
step = DBL_EPSILON;
}
step *= 1.2;
++iLoopCheck;
if(iLoopCheck > 1000) {
break;
}
}
dGridBase = (floor(low / dGridStep) + 1.0) * dGridStep;
return dGridBase;
}
// -------------------------------------------------------------------