-
Notifications
You must be signed in to change notification settings - Fork 2
/
mgraph.h
1482 lines (1029 loc) · 61.9 KB
/
mgraph.h
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
/*
Copyright (C) 2022 BrerDawg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
hint
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//mgraph.h
//v1.08 mgraph 21-dec-2017
//v1.05 surface3d 06-jan-2018 //see also below 'to avoid windows error dlg: fl_line_style(): Could not create GDI pen object'
//v1.17 mgraph and fast_graph
//v1.18 mgraph
//v1.19 fast_graph
//v1.20 surface3d
//v1.22 fast_graph/mgraph
#ifndef mgraph_h
#define mgraph_h
#define _FILE_OFFSET_BITS 64 //large file handling, must be before all #include...
//#define _LARGE_FILES
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <locale.h>
#include <string>
#include <vector>
#include <wchar.h>
#include <algorithm>
#include <math.h>
#include <complex>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Enumerations.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_Input_Choice.H>
//#include "globals.h"
//#include "pref.h"
#include "GCProfile.h"
//#include "GCLed.h"
//#include "gclog.h"
//#include "gcthrd.h"
//#include "gcpipe.h"
//#include "matheval.h"
//#include "wrksheet.h"
//linux code
#ifndef compile_for_windows
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
//#include <X11/Xaw/Form.h> //64bit
//#include <X11/Xaw/Command.h> //64bit
#include <dirent.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <syslog.h> //MakeIniPathFilename(..) needs this
#endif
//windows code
#ifdef compile_for_windows
#include <windows.h>
#include <process.h>
#include <winnls.h>
#include <share.h>
#include <fcntl.h>
#include <io.h>
#include <iostream>
#include <fstream>
#include <conio.h>
#define WC_ERR_INVALID_CHARS 0x0080 //missing from gcc's winnls.h
#endif
using namespace std;
#define cn_mgraph_trace_max 64
#define cn_prev_plot_rec_max 4 //max num of previous plot histories to record, see 'prev_plot_rec_idx'
#define cn_surfplot_deg2rad M_PI / 180.0
#define cn_surfplot_rad2deg ( 180.0 / M_PI )
struct mg_colref
{
int r, g, b;
};
struct mg_col_tag
{
int r;
int g;
int b;
};
struct clip_coord_tag
{
int x, y;
};
//-----------------------
//surfaceplot
//v1.03 31-mar-2015 //adding surfaceplot_line_obj_tag
//v1.04 02-nov-2016
enum en_surfaceplot_line_style
{
en_spls_solid = FL_SOLID,
en_spls_dash = FL_DASH,
en_spls_dot = FL_DOT,
en_spls_dashdot = FL_DASHDOT,
en_spls_dashdotdot = FL_DASHDOTDOT,
en_spls_cap_flat = FL_CAP_FLAT,
en_spls_cap_round = FL_CAP_ROUND,
en_spls_cap_square = FL_CAP_SQUARE,
en_spls_cap_join_miter = FL_JOIN_MITER,
en_spls_cap_join_round = FL_JOIN_ROUND,
en_spls_cap_join_bevel = FL_JOIN_BEVEL,
};
//must be powers of 2, as anding used to test if active
enum en_plot_options_tag
{
en_po_none = 0,
en_po_dont_plot = 1,
en_po_show_centre_dot = 2,
en_po_show_normals = 4,
en_po_show_select_1 = 8,
en_po_show_select_2 = 16,
en_po_show_select_3 = 32,
};
enum en_which_corner_tag
{
en_cw_south_west, //x1,y1,z1
en_cw_south_east, //x2,y2,z2
en_cw_north_east, //x3,y3,z3
en_cw_north_west, //x4,y4,z4
};
//holds one user line obj to plot
struct surfaceplot_line_obj_tag
{
int x1, y1, x2, y2; //mathematical line representation, infinitely thin
double line_wid;
en_surfaceplot_line_style line_style;
int r, g, b;
//double gradient;
//double yintercept;
};
struct st_surfaceplot_val_tag //hold a entry in the surface grid, where x,y are also specified, used when text objs are displayed
{
double x;
double y;
double val; //height (on z-axis)
};
//holds one user text obj to plot
struct surfaceplot_text_obj_tag
{
double x, y; //location of text relative to x, y val passed in: build_surface2(..)
double val; //height (on z-axis)
string stext;
bool show_text_background; //set this to give text an outline or shadow look
mg_col_tag foregnd; //colour of text on top
mg_col_tag backgnd; //colour of below text (outline or shadow look)
int fontsize;
int font;
};
// !!!!!! to avoid Windows ERROR dlg: fl_line_style(): Could not create GDI pen object !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!! MAKE SURE YOU SET legal values for all below:
// !!!!!! grid_line_wid, grid_line_style, line_wid, line_wid,
// !!!!!! FOR st_surfplot_tag surfaceplot_line_obj_tag objects
struct st_surfplot_tag
{
double x1, y1, z1; //holds translated, rotated 3d coords
double x2, y2, z2;
double x3, y3, z3;
double x4, y4, z4;
double nx, ny, nz; //holds normals
double centrex, centrey, centrez; //holds centre coord of obj
int ix1,iy1; //holds pespective projected 2d coords
int ix2,iy2;
int ix3,iy3;
int ix4,iy4;
int inx, iny, inz;
int icx, icy; //holds pespective projected 2d coords of centre of obj
mg_col_tag colline;
mg_col_tag colfill;
mg_col_tag col_select_1;
mg_col_tag col_select_2;
mg_col_tag col_select_3;
bool show_text_background; //set this to give text an outline or shadow look
mg_col_tag foregnd; //colour of text on top
mg_col_tag backgnd; //colour of below text (outline or shadow look)
int font; //set to -1 for no change
int fontsize; //set to -1 for no change
int grid_line_wid; //grid line width
en_surfaceplot_line_style grid_line_style; //grid line style, see: en_surfaceplot_line_style
double face_angle; //holds angle of obj's normal to observer, 0 degrees means obj facing the observer, +90 obj facing upward, -90 means obj facing downward
//col_tag col_hightlight_x;
//col_tag col_hightlight_y;
//the highlighted east side rect is rectangle left of rect that has west side highlighted
//this is done so no matter what z-order the rectangles end up drawn with, the
//highlighted line will always be drawn highlighted
int hightlight_x_line; // 1 = west, 2 = east sides of this rectangle is hightlighted ( left hand side )
int hightlight_y_line; // 1 = south, 2 = north side of this rectangle is hightlighted ( nearest side of viewer )
bool valid;
unsigned int options; //refer en_plot_options_tag
int id; //holds unique id for ref
int line_wid; //user line obj
en_surfaceplot_line_style line_style; //user line obj
//double gradient; //line equations vars
//double yintercept;
string stext;
};
//holds one user line obj that has been broken down to surface rect line segments
struct surfaceplot_lineseg_obj_tag
{
vector<st_surfplot_tag> vlineobj; //used to hold user line segmented objs
vector<st_surfplot_tag> vzlineobj; //holds 2d surface rects in z order for plotting
};
class surface3d : public Fl_Double_Window
{
private:
bool left_button;
bool middle_button;
bool right_button;
bool ctrl_key;
bool shift_key;
double cap_rotz;
double cap_rotx;
double cap_roty;
int cap_offx;
int cap_offy;
int mousex, mousey;
int lb_press_x, lb_press_y;
int mb_press_x, mb_press_y;
int rb_press_x, rb_press_y;
int midx, midy;
int dimx, dimy;
int surfx, surfy;
double rotx;
double roty;
double rotz;
double rho;
double srotx; //holds trig rotation values for translate
double crotx;
double sroty;
double croty;
double srotz;
double crotz;
mg_col_tag col_ramp[ 10 ];
bool show_lines, show_filled;
int rect_count;
double valmin;
double valmax;
int selected_id;
double normals_length; //holds size of normals that will be plotted
double dminx, dminy;
double dmaxx, dmaxy;
vector<double> vampl; //holds actual amplitude at a grid points
vector<st_surfplot_tag> vsp; //holds 3d surface rectangles
vector<st_surfplot_tag> vzorder; //holds 2d surface rects in z order for plotting
vector<st_surfplot_tag> vdotmark; //used to mark objs in some way
vector<st_surfplot_tag> vzdotmark; //holds 2d surface rects in z order for plotting
//vector<st_surfplot_tag> vlineobj; //used to hold user line segmented objs
//vector<st_surfplot_tag> vzlineobj; //holds 2d surface rects in z order for plotting
vector<surfaceplot_line_obj_tag> vlo; //holds user line objs
vector<surfaceplot_lineseg_obj_tag> vlineseg; //used to user line segmented objs
vector<surfaceplot_text_obj_tag> vtext; //holds test objs
public:
int text_font;
int text_size;
mg_col_tag col_bkgd;
mg_col_tag col_line;
mg_col_tag col_hightlight_x;
mg_col_tag col_hightlight_y;
mg_col_tag col_fill;
bool force_col_fill;
bool bdotmark;
int grid_line_wid; //grid line width, !!!!!!!!! MUST be legal see: 'to avoid windows error dlg: fl_line_style(): Could not create GDI pen object'
en_surfaceplot_line_style grid_line_style; //grid line style, see: en_surfaceplot_line_style
double scale, scalex, scaley;
int offx, offy;
double ampl_gain;
double rotate_x;
double rotate_y;
double rotate_z;
int highlight_every_x;
int highlight_every_y;
double std_wheel_step;
double ctrl_wheel_step;
double shift_wheel_step;
double wheel_gain;
bool show_xyz_gain_text;
public:
surface3d( int x, int y, int w, int h, const char *label = 0 );
bool build_surface( vector<double> &o, int dim_x, int dim_y, bool fill, bool lines, vector<surfaceplot_line_obj_tag> &lo, vector<surfaceplot_text_obj_tag> &vtxt );
bool build_surface2( vector<st_surfaceplot_val_tag> &o, int dim_x, int dim_y, bool fill, bool lines, vector<surfaceplot_line_obj_tag> &lo, vector<surfaceplot_text_obj_tag> &vtxt );
private:
void draw();
int handle( int e );
void make_grid();
int find_rect_clicked( int xx, int yy );
void plot_obj( vector<st_surfplot_tag > &o, int ptr, bool fill, bool line, bool user_line_obj, bool user_text_obj );
void plot( bool line, bool fill );
//void plot_3d_rect2( int ptr, bool line, bool fill, col_tag colfill, col_tag colline );
//void plot_3d_rect( double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4, bool line, bool fill, col_tag colfill, col_tag colline );
//void plot_3d( double x1, double y1, double z1, double x2, double y2, double z2, col_tag col );
//void translate( double &x1, double &y1, double &z1 );
void set_translate_vals( double rotate_x, double rotate_y, double rotate_z );
void trans_rotate_persp_obj( vector<st_surfplot_tag> &vv, vector<st_surfplot_tag> &vt, int ptr );
void trans_rotate_project( vector<st_surfplot_tag> &vv, vector<st_surfplot_tag> &vt, int ptr );
void trans_rotate( vector<st_surfplot_tag> &vv, vector<st_surfplot_tag> &vt, int ptr );
void perpective_proj( vector<st_surfplot_tag> &vt, int ptr );
double sinc( double x );
void matrix_formula_gen();
void dissolve_col( double fader, mg_col_tag &col_a, mg_col_tag &col_b, mg_col_tag &col_fader );
void dissolve_ramp( double level, mg_col_tag &col );
//double scale_line( double &aa, double &bb, double scale );
void find_centre( st_surfplot_tag o, double ¢rex, double ¢rey, double ¢rez );
void get_centre( st_surfplot_tag o, double ¢rex, double ¢rey, double ¢rez );
void scale_surface( st_surfplot_tag &o, double scalex, double scaley );
void calc_centre( st_surfplot_tag &o );
void translate_obj( st_surfplot_tag &o, double dx, double dy, double dz );
void translate_obj2( st_surfplot_tag &o, double dx, double dy, double dz );
void translate_line_to( double &xx, double &yy, double &zz, double nx, double ny, double nz );
bool point_in_polygon( vector<int> &vx, vector<int> &vy, int xx, int yy );
void make_point_from_corner( st_surfplot_tag &vt1, double proportion, en_which_corner_tag which );
void make_point( double x1, double y1, double z1, double x2, double y2, double z2, double delta, double &xx, double &yy, double &zz );
//void make_centre( st_surfplot_tag &o, double &cx, double &cy, double &cz );
void calc_normals( st_surfplot_tag &o );
void rotate_point( double x1, double y1, double z1, double &x2, double &y2, double &z2, double thetax, double thetay, double thetaz );
};
//-----------------------
//-----------------------
//mgraph
//v1.07 30-may-2017
enum en_mgraph_line_style
{
en_mls_solid = FL_SOLID,
en_mls_dash = FL_DASH,
en_mls_dot = FL_DOT,
en_mls_dashdot = FL_DASHDOT,
en_mls_dashdotdot = FL_DASHDOTDOT,
en_mls_cap_flat = FL_CAP_FLAT,
en_mls_cap_round = FL_CAP_ROUND,
en_mls_cap_square = FL_CAP_SQUARE,
en_mls_cap_join_miter = FL_JOIN_MITER,
en_mls_cap_join_round = FL_JOIN_ROUND,
en_mls_cap_join_bevel = FL_JOIN_BEVEL,
};
struct pnt_tag
{
double x, y;
int r, g, b;
bool sel; //used for group selection
};
struct trace_tag
{
string label;
vector<pnt_tag>pnt;
int id; //this is useful to find the trace you want, if you don't know what order traces were push_back'd
mg_col_tag col;
double minx, maxx, miny, maxy;
en_mgraph_line_style line_style;
int line_thick;
bool vis;
bool lineplot; //connect sample points with lines
int border_left;
int border_right;
int border_top;
int border_bottom;
int clip_left; //clip rect for this trace
int clip_right;
int clip_top;
int clip_bottom;
int use_pos_y; //if >=0 will use this value as the trace id to get a specific y position, set to -1 for no offset
//NOTE: if 'use_scale_y' is set to a trace id, this parameter should also be set as so to maintain correct coord relationship
int use_scale_y; //if >=0 will use this value as the trace id to get a specific y scale, specify objs coords with similar range to trace coords,
//set to -1 for no scaling, where values represent integer pixels
double xunits_perpxl; //-1 means auto scaling, -2 means the use of graticle unit/division, so 1.0 amounts to 1 div
double yunits_perpxl; //-1 means auto scaling
//-2 means the use of graticle unit/division, so 1.0 amounts to 1 div
//-3 means scale using which ever is the larger absolute wise: maxy or miny absolute wise: i.e: the larger of either of these: fabs(ymax) or fabs(ymin)
bool b_limit_auto_scale_min_for_y; //set this to force auto y scaling min to 'limit_auto_scale_min_for_y'
double limit_auto_scale_min_for_y; //this value limits the allowable display scale reduction when very large sample transitions occur
bool b_limit_auto_scale_max_for_y; //set this to force auto y scaling max to 'limit_auto_scale_max_for_y'
double limit_auto_scale_max_for_y; //this value limits the allowable display scale magnification when only very small sample transitions occur
double scalex; //this allow individual trace scaling, 1.0 = no scaling
double scaley; //this allow individual trace scaling, 1.0 = no scaling
double posx;
double posy;
int plot_offsx; //pixel offsets just before plotting, not affected by override: 'use_pos_y', still allows independent trace offsets at pixel level
int plot_offsy;
int selected_idx;
int selected_pixel_rect_left;
int selected_pixel_rect_wid;
int selected_pixel_rect_top;
int selected_pixel_rect_hei;
int hover_sample_idx; //sample idx the mouse is hovering over, if any
int mousex_low_sample_idx; //lower sample idx mousex is nearest to (unlike 'hover_sample_idx',this does not req mouse to actually be within sample's rect, just the near it x-wise)
int mousex_high_sample_idx; //higher sample idx mousex is nearest to - see: 'get_mousex_sample_boundary_idx()'
bool show_as_spectrum;
double spectrum_baseline_y;
mg_col_tag single_sel_col;
mg_col_tag group_sel_trace_col; //used if 'pnt[xx].sel' is set
mg_col_tag group_sel_rect_col; //used if 'pnt[xx].sel' is set
bool sample_rect_hints_double_click; //set this if a left double click is to show all sample point rectangles, set COLOUR with 'sample_rect_hints_col', (rect are shown regardless of congestion settings in: 'sample_rect_hints_distancex','sample_rect_hints_distancey'
//----- helps stop over hinting if sample point rectangle distances are too close -----
bool sample_rect_hints; //if set the individual sample points are shown with a rect (if they don't cause congestion see below)
mg_col_tag sample_rect_hints_col;
vector<int>vrect_hints_px; //used JUST in draw(), [NOT for user], to build/display a list of sample point bounding rect hints
vector<int>vrect_hints_py;
vector<bool>vrect_hints_sel; //used JUST in draw(), [NOT for user], for: 'pnt[xx].sel'
//set these two vars zero to disable congestion detection
int sample_rect_hints_distancex; //helps stop over hinting if x plot distances are too close, e.g: if set to 15, then when rects are less than 15 pixels apart (caused by zooming out) the hinting is turned off.
int sample_rect_hints_distancey; //same as above, NOTE: if the graph is displaying y amplitudes, and you zooming into to a point on of the trace where only flat horizotal line is visible then
//enabling 'show_sample_rect_hints_distancey' will ERRONEOUSLY clear the rectangles even though they are far apart x-wise
bool sample_rect_flicker; //momentarily flickers sample rectangle hinting when mouse is moved
//------------------------------------------------------------------------------------
void (*left_click_cb_p_callback)( void *args ); //see add_trace() to init this to zero
void *left_click_cb_args;
void (*left_double_click_cb_p_callback)( void *args ); //see add_trace() to init this to zero
void *left_double_click_cb_args;
void (*middle_click_cb_p_callback)( void *args ); //see add_trace() to init this to zero
void *middle_click_cb_args;
void (*right_click_cb_p_callback)( void *args ); //see add_trace() to init this to zero
void *right_click_cb_args;
void (*right_double_click_cb_p_callback)( void *args ); //see add_trace() to init this to zero
void *right_double_click_cb_args;
void (*keydown_cb_p_callback)( void *args, int int0 ); //see add_trace() to init this to zero
void *keydown_cb_args;
void (*keyup_cb_p_callback)( void *args, int int0 ); //see add_trace() to init this to zero
void *keyup_cb_args;
void (*mousewheel_cb_p_callback)( void *args, int int0 ); //see add_trace() to init this to zero
void *mousewheel_cb_args;
//mouse callback values
//int0 holds mouse xpos as value between (left) 0 -->??(right)
//int1 holds mouse xpos as value between (top) 0 -->??(botm)
//dble0 holds mouse xpos as value between (left)-1.0 --> 0.0 --> +1.0 (right)
//dble1 holds mouse ypos as value between (botm)-1.0 --> 0.0 --> +1.0 (top)
void (*mousemove_cb_p_callback)( void *args, int int0, int int1, double dble0, double dble1 ); //see add_trace() to init this to zero
void *mousemove_cb_args;
};
struct st_mgraph_text_tag
{
int x;
int y;
string text;
int r;
int g;
int b;
int font;
int size;
};
//boolean to get the desired justification
enum en_mgraph_text_justify
{
en_tj_none=0, //text is left justified so its right of the coord, and vertically positioned so bottom of text is on the coord
en_tj_horiz_center=1, //text is horizontally centred to coord
en_tj_horiz_right=2, //text is left of the coord
en_tj_vert_center=4, //text is vertically centred to coord
en_tj_vert_top=8, //text is shifted downward so top of text is at coord
};
//mgraph draw object types -- see: 'st_mgraph_draw_obj_tag'
enum en_mgraph_draw_obj_type
{
en_dobt_point, //x1,y1
en_dobt_line, //x1,y1,x2,y2
en_dobt_rect, //x1,y1: first extreme, x2,y2: second extreme (does not use a wid or hei)
en_dobt_rectf, //x1,y1: first extreme, x2,y2: second extreme (does not use a wid or hei)
en_dobt_arc, //unfilled, define a bounding rect with: x1, y1, x2, y2, and start stop angles: arc1, arc2
en_dobt_pie, //filled, define a bounding rect with: x1, y1, x2, y2, and start stop angles: arc1, arc2
en_dobt_text, //just: x1,y1
en_dobt_polypoints, //see: fl_begin_points(), just: x1,y1
en_dobt_polyline, //see: fl_begin_line()
en_dobt_polygon, //unfilled polygon, no need to close polygon with a last point matching the first
en_dobt_polygonf, //filled polygon - see: fl_begin_polygon(), no need to close polygon with a last point matching the first, 3 coords make a triangle, go clockwise
en_dobt_polypoints_wnd_coords, //point coords are absolute window integer pixel coords (not relative to x1, y1, where 0 is top left, down is positive), assumes: 'use_pos_x = use_scale_x = use_pos_y = use_scale_y = -1;'
en_dobt_polyline_wnd_coords, //" "
en_dobt_polygon_wnd_coords, //" "
en_dobt_polygonf_wnd_coords, //" "
};
//holds one draw obj for mgraph
struct st_mgraph_draw_obj_tag
{
en_mgraph_draw_obj_type type;
bool visible;
int clip_left; //clip rect for this obj
int clip_right;
int clip_top;
int clip_bottom;
int use_pos_x; //if >=0 will use this value as the trace id to get a specific x position,set to -1 for no offset
//NOTE: if 'use_scale_x' is set to a trace id, this parameter should also be set as so to maintain correct coord relationship
int use_pos_y; //if >=0 will use this value as the trace id to get a specific y position, set to -1 for no offset
//NOTE: if 'use_scale_y' is set to a trace id, this parameter should also be set as so to maintain correct coord relationship
int use_scale_x; //if >=0 will use this value as the trace id to get a specific x scale, specify objs coords with similar range to trace coords,
//set to -1 for no scaling, where values represent integer pixels
int use_scale_y; //if >=0 will use this value as the trace id to get a specific y scale, specify objs coords with similar range to trace coords,
//set to -1 for no scaling, where values represent integer pixels
double x1;
double y1;
double x2; //rectangles don't use width or height, specify just two coords x1,y1, x2,y2 extremes
double y2; //for arcs and pies, x2=wid, y2=hei
vector<double> vpolyx; //for poly objs (fl_vertex types)
vector<double> vpolyy;
double arc1, arc2;
string stext;
en_mgraph_text_justify justify;
int r;
int g;
int b;
int font;
int font_size;
en_mgraph_line_style line_style;
int line_thick;
int draw_ordering; //0 = before grid, 1 = after graticle but before traces, 2 = after traces, and in order of being 'pushed'
};
class mgraph : public Fl_Box
{
private:
int woffx;
int woffy;
int sizex;
int sizey;
int mousex, mousey;
int double_click_left;
bool inside_control;
int idx_maxx;
int idx_maxy;
bool show_axisx;
bool show_axisy;
//double val_y_min, val_y_max, val_x_min, val_x_max;
int ref_id; //holds id of trace to use as reference, should not be negative, see: int z = vdrwobj[ i ].use_scale_x;
double ref_scalex; //used to reference other traces wrt to 1st trace
double ref_d_midx; //used to reference other traces wrt to 1st trace
int at_draw_ordering; //keep track of where drawing stages are at, for user's draw obj preferred ordering, 0 = before grid, 1 = after grid before traces, 2 = after traces
vector<double> vscalex; //keep each trace's params, also used for: vdrwobj
vector<double> vscaley;
vector<double> vtrace_scale_x;
vector<double> vtrace_scale_y;
vector<double> vtrace_positionx;
vector<double> vtrace_positiony;
vector<double> vtrace_dmidx;
vector<double> vtrace_dmidy;
vector<int> vtrace_offx;
vector<int> vtrace_offy;
vector<int> vtrace_wid;
vector<int> vtrace_hei;
vector<int> vtrace_midx;
vector<int> vtrace_midy;
vector<int> vtrace_id;
vector<int> vplot_offsx;
vector<int> vplot_offsy;
vector<int> vtrace_minx; //v1.16
void (*left_click_anywhere_cb_p_callback)( void *args ); //non trace specific
void *left_click_anywhere_cb_args;
void (*left_click_release_cb_p_callback)( void *args );
void *left_click_release_cb_args;
void (*left_double_click_anywhere_cb_p_callback)( void *args );
void *left_double_click_anywhere_cb_args;
void (*right_click_anywhere_cb_p_callback)( void *args );
void *right_click_anywhere_cb_args;
void (*right_double_click_anywhere_cb_p_callback)( void *args );
void *right_double_click_anywhere_cb_args;
void (*right_click_release_cb_p_callback)( void *args );
void *right_click_release_cb_args;
void (*mouseenter_cb_p_callback)( void *args );
void *mouseenter_cb_args;
void (*mouseleave_cb_p_callback)( void *args );
void *mouseleave_cb_args;
public:
bool left_button;
bool right_button;
bool middle_button;
int b_invert_wheel;
int mousewheel;
bool sample_rect_showing[cn_mgraph_trace_max]; //will toggle if user double clicks
vector<trace_tag>trce;
int rect_size;
int graph_id; //place a unique id value here
mg_col_tag border_col;
mg_col_tag background;
//int selected_sample;
//int selected_pixel_rect_left;
//int selected_pixel_rect_right;
//int selected_pixel_rect_top;
//int selected_pixel_rect_bot;
int bkgd_border_left; //use to size background rect
int bkgd_border_top;
int bkgd_border_right;
int bkgd_border_bottom;
int graticule_border_left; //use to size graticule rect
int graticule_border_top;
int graticule_border_right;
int graticule_border_bottom;
int graticle_count_y;
int graticle_count_x;
int grat_pixels_x;
int grat_pixels_y;
bool cro_graticle;
int htime_lissajous; //0 = htime,
//1 = channel 1-> H , channel 2-> V
//2 = channel 2-> H , channel 1-> V
//3 = channel 3-> H , channel 4-> V
//4 = channel 4-> H , channel 3-> V
mg_colref col_cursor_along_y; //cursors along y-axis (i.e. measuring time)
mg_colref col_cursor_along_x; //cursors along x-axis (i.e. measuring amplitude)
int cursor_sel; //0 and 1 are vert, 2 and 3 are horiz
bool show_cursors_along_y;
bool show_cursors_along_x;
bool show_vert_units_div;
bool show_horiz_units_div;
double cursor_along_y0; //cursors along y-axis (i.e. measuring time)
double cursor_along_y1;
double cursor_along_x0; //cursors along x-axis (i.e. measuring amplitude)
double cursor_along_x1;
st_mgraph_text_tag text_cursor_along_y; //holds text
st_mgraph_text_tag text_cursor_along_x;
st_mgraph_text_tag text_vert_units_div;
st_mgraph_text_tag text_horiz_units_div;
vector<st_mgraph_draw_obj_tag> vdrwobj; //holds additional obj for drawing
int last_clicked_trace; //this is not the trace_id, but index of trace in: vector<trace_tag>trce
int hover_trace_idx; //trace idx the mouse is hovering over, if any
bool use_line_clip; //set this to activate: line_clip(..)
//int clip_minx; //put some limits on line plotting attempts, see: mgraph::line_clip(..)
//int clip_maxx;
//int clip_miny;
//int clip_maxy;
int clip_minx; //includes widget x,y offset, downward is positive
int clip_maxx;
int clip_miny; //NOTE: 'clip_miny' here is in an decreasing direction up the screen
int clip_maxy;
int clip_vportleft; //upward is positive, for: 'line_clip()', 'clip_poly()' algorithm
int clip_vportright;
int clip_vporttop; //NOTE: 'clip_vporttop' here is in an increasing direction up the screen
int clip_vportbot;
int last_mousex; //holds pos vals covering the graticule (the border gaps being removed - also sent to: mousemove_cb_p_callback )
int last_mousey;
double last_nomalised_mousex; //holds pos vals covering the graticule (the border gaps being removed - also sent to: mousemove_cb_p_callback )
//(left)-1.0 --> 0.0 --> +1.0 (right)
double last_nomalised_mousey; //(botm)-1.0 --> 0.0 --> +1.0 (top)
int drw_cnt;
int mousemove_cnt;
public:
mgraph( int x, int y, int w, int h, const char *label = 0 );
~mgraph();
void clear_traces();
void clear_trace( int idx );
void add_trace( trace_tag &tr );
void render( int ref_id_in );
bool get_sample_count_for_trc( int trc, int &count );
bool get_sample_count_using_id( int trc_id, int &count );
bool get_selected_value( int trc, double &xx, double &yy );
bool get_selected_value_using_id( int trc_id, int &idx, double &xx, double &yy );
void get_trace_min_max( int trace, double &xmin, double &xmax, double &ymin, double &ymax );
void set_trace_visibility( int idx, bool visible );
bool get_selected_idx( int trc, int &sel_idx );
void set_selected_sample( int trc, int sel_sample_idx, int issue_which_callback );
bool get_hover_idx( int trc, int &hov_idx );
bool get_hover_value_using_id( int trc_id, int &idx, double &xx, double &yy );
bool get_left_edge_sample_idx( int trc, int &left_idx );
bool get_right_edge_sample_idx( int trc, int &right_idx );