-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalcpa.c
5823 lines (4744 loc) · 154 KB
/
calcpa.c
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
// hskymon from HDS OPE file Editor
// New SkyMonitor for Subaru Gen2
// calcpa.c --- calculation and plot for celecial targets
//
// 2017.6.1 A.Tajitsu
#include"main.h"
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include <cairo-pdf.h>
//// Global args.
extern gboolean flagProp;
extern gboolean flagChildDialog;
extern gboolean flagTree;
extern gboolean flagPlot;
extern gboolean flagFC;
extern gboolean flagADC;
extern gboolean flagPAM;
extern int debug_flg;
extern gboolean flag_getDSS;
extern gboolean flag_getFCDB;
extern pid_t fc_pid;
extern pid_t fcdb_pid;
extern pid_t stddb_pid;
double adrad(double zrad, double wlnm,double h,double t,double p,double f);
double new_tu(int iyear, int month, int iday);
void calc_moon_skymon();
void close_plot();
#ifdef USE_GTK3
gboolean draw_plot_cb();
#else
gboolean expose_plot_cairo();
#endif
gboolean configure_plot_cb();
gboolean resize_plot_cairo();
gboolean refresh_plot();
void do_plot_moon();
void do_plot_pam();
gboolean update_plot();
void cc_get_plot_mode();
void cc_get_plot_all();
void cc_get_plot_center();
void get_plot_time_current();
void get_plot_time_midnight();
void get_plot_time();
gdouble set_ul();
gdouble hdspa_deg();
void do_print();
static void draw_page();
void calc_moon_topocen();
gdouble get_moon_sep();
gdouble get_meridian_JD();
gdouble get_julian_from_local_date();
gboolean plot_button_signal();
#ifdef USE_GTK3
GdkPixbuf *pixbuf_plot=NULL;
#else
GdkPixmap *pixmap_plot=NULL;
#endif
gdouble paz_moon[200],pel_moon[200], jd_moon[200];
gdouble JD_moon_stock;
struct ln_zonedate moon_transit;
gdouble moon_tr_el;
gint i_moon_max;
void close_plot(GtkWidget *w, gpointer gdata)
{
typHOE *hg;
hg=(typHOE *)gdata;
if(hg->plot_timer!=-1){
g_source_remove(hg->plot_timer);
hg->plot_timer=-1;
}
gtk_widget_destroy(GTK_WIDGET(hg->plot_main));
flagPlot=FALSE;
}
void cc_get_plot_mode (GtkWidget *widget, gint * gdata)
{
GtkTreeIter iter;
typHOE *hg;
hg=(typHOE *)gdata;
if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)){
gint n;
GtkTreeModel *model;
model=gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
gtk_tree_model_get (model, &iter, 1, &n, -1);
hg->plot_mode=n;
refresh_plot(widget, (gpointer)hg);
}
}
void cc_get_plot_all (GtkWidget *widget, gint * gdata)
{
GtkTreeIter iter;
typHOE *hg;
hg=(typHOE *)gdata;
if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)){
gint n;
GtkTreeModel *model;
model=gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
gtk_tree_model_get (model, &iter, 1, &n, -1);
hg->plot_all=n;
refresh_plot(widget, (gpointer)hg);
}
}
void cc_get_plot_center (GtkWidget *widget, gint * gdata)
{
GtkTreeIter iter;
typHOE *hg;
hg=(typHOE *)gdata;
if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)){
gint n;
GtkTreeModel *model;
model=gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
gtk_tree_model_get (model, &iter, 1, &n, -1);
hg->plot_center=n;
get_plot_time(hg);
refresh_plot(widget, (gpointer)hg);
}
}
void get_plot_time_current(typHOE *hg, gdouble delta_hst){
int iyear;
int month;
int iday;
int hour, min;
gdouble sec;
gdouble JD;
struct ln_zonedate zonedate;
if(hg->skymon_mode==SKYMON_SET){
iyear=hg->skymon_year;
month=hg->skymon_month;
iday=hg->skymon_day;
hour=hg->skymon_hour;
min=hg->skymon_min;
sec=0.0;
}
else{
get_current_obs_time(hg,&iyear, &month, &iday, &hour, &min, &sec);
}
JD = get_julian_from_local_date(iyear,month,iday,hour,min,sec,
(long)hg->obs_timezone*60);
hg->plot_jd0 = JD - delta_hst*0.25/24;
hg->plot_jd1 = JD + delta_hst*0.75/24;
}
void get_plot_time_midnight(typHOE *hg, gdouble delta_hst){
int iyear;
int month;
int iday;
int hour, min;
gdouble sec;
gdouble JD;
struct ln_zonedate zonedate;
if(hg->skymon_mode==SKYMON_SET){
iyear=hg->skymon_year;
month=hg->skymon_month;
iday=hg->skymon_day;
hour=hg->skymon_hour;
min=hg->skymon_min;
sec=0.0;
}
else{
get_current_obs_time(hg,&iyear, &month, &iday, &hour, &min, &sec);
}
if(hour<10){ // Show tonight
JD = get_julian_from_local_date(iyear,month,iday,0,0,0.0,
(long)hg->obs_timezone*60);
}
else{ // Show the next night
JD = get_julian_from_local_date(iyear,month,iday,0,0,0.0,
(long)hg->obs_timezone*60)+1.0;
}
if(hg->plot_zoom!=0){
if(hg->plot_zoom>0){
JD+=14.0/24.0*hg->plot_zoomr;
}
}
hg->plot_jd0 = JD - delta_hst*0.5/24;
hg->plot_jd1 = JD + delta_hst*0.5/24;
}
void get_plot_time_meridian(typHOE *hg, gdouble delta_hst){
int iyear;
int month;
int iday;
int hour, min;
gdouble sec;
gdouble JD;
struct ln_zonedate zonedate;
JD = get_meridian_JD(hg);
my_get_local_date(JD, &zonedate,hg->obs_timezone);
hg->plot_jd0 = JD - delta_hst*0.5/24;
hg->plot_jd1 = JD + delta_hst*0.5/24;
}
void get_plot_time(typHOE *hg){
switch(hg->plot_center){
case PLOT_CENTER_MIDNIGHT:
get_plot_time_midnight(hg, 14.0*(gdouble)(10-hg->plot_zoom)/10.);
break;
case PLOT_CENTER_CURRENT:
get_plot_time_current(hg, 10.0*(gdouble)(10-hg->plot_zoom)/10.);
break;
case PLOT_CENTER_MERIDIAN:
get_plot_time_meridian(hg, 12.0*(gdouble)(10-hg->plot_zoom)/10.);
break;
}
}
// Create Plot Window
void create_plot_dialog(typHOE *hg)
{
GtkWidget *vbox;
GtkWidget *hbox, *hbox1, *ebox;
GtkWidget *frame, *check, *label, *button;
GSList *group=NULL;
GtkAdjustment *adj;
GtkWidget *menubar;
GdkPixbuf *icon;
hg->plot_main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(hg->plot_main), "Sky Monitor : Plot Window");
my_signal_connect(hg->plot_main,
"destroy",
close_plot,
(gpointer)hg);
vbox = gtkut_vbox_new(FALSE,0);
gtk_container_add (GTK_CONTAINER (hg->plot_main), vbox);
hbox = gtkut_hbox_new(FALSE,0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
frame = gtkut_frame_new ("<b>Parameter</b>");
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
{
GtkWidget *combo;
GtkListStore *store;
GtkTreeIter iter, iter_set;
GtkCellRenderer *renderer;
store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Elevation",
1, PLOT_EL, -1);
if(hg->plot_mode==PLOT_EL) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Azimuth",
1, PLOT_AZ, -1);
if(hg->plot_mode==PLOT_AZ) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Atmospheric Dispersion",
1, PLOT_AD, -1);
if(hg->plot_mode==PLOT_AD) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "AD-PA vs El.",
1, PLOT_ADPAEL, -1);
if(hg->plot_mode==PLOT_ADPAEL) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Separation from the Moon",
1, PLOT_MOONSEP, -1);
if(hg->plot_mode==PLOT_MOONSEP) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "HDS PA w/o ImR",
1, PLOT_HDSPA, -1);
if(hg->plot_mode==PLOT_HDSPA) iter_set=iter;
combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_container_add (GTK_CONTAINER (frame), combo);
g_object_unref(store);
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo),renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combo), renderer, "text",0,NULL);
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo),&iter_set);
gtk_widget_show(combo);
my_signal_connect (combo,"changed",cc_get_plot_mode,
(gpointer)hg);
}
frame = gtkut_frame_new ("<b>Action</b>");
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
hbox1 = gtkut_hbox_new(FALSE,0);
gtk_container_add (GTK_CONTAINER (frame), hbox1);
#ifdef USE_GTK3
button=gtkut_button_new_from_icon_name(NULL,"view-refresh");
#else
button=gtkut_button_new_from_stock(NULL,GTK_STOCK_REFRESH);
#endif
my_signal_connect (button, "clicked",
G_CALLBACK (refresh_plot), (gpointer)hg);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Refresh");
#endif
#ifdef USE_GTK3
button=gtkut_button_new_from_icon_name(NULL,"window-close");
#else
button=gtkut_button_new_from_stock(NULL,GTK_STOCK_CANCEL);
#endif
my_signal_connect (button, "clicked",
G_CALLBACK (close_plot), (gpointer)hg);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Close");
#endif
icon = gdk_pixbuf_new_from_resource ("/icons/pdf_icon.png", NULL);
button=gtkut_button_new_from_pixbuf(NULL, icon);
g_object_unref(icon);
my_signal_connect (button, "clicked",
G_CALLBACK (do_save_plot_pdf), (gpointer)hg);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Save as PDF");
#endif
#ifdef USE_GTK3
button=gtkut_button_new_from_icon_name(NULL,"document-print");
#else
button=gtkut_button_new_from_stock(NULL,GTK_STOCK_PRINT);
#endif
my_signal_connect (button, "clicked",
G_CALLBACK (do_print), (gpointer)hg);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Print Out");
#endif
icon = gdk_pixbuf_new_from_resource ("/icons/moon_icon.png", NULL);
button=gtkut_toggle_button_new_from_pixbuf(NULL, icon);
g_object_unref(icon);
gtk_container_set_border_width (GTK_CONTAINER (button), 0);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),hg->plot_moon);
my_signal_connect(button,"toggled",
G_CALLBACK (do_plot_moon),
(gpointer)hg);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Plot Moon");
#endif
icon = gdk_pixbuf_new_from_resource ("/icons/lgs_icon.png", NULL);
button=gtkut_toggle_button_new_from_pixbuf(NULL, icon);
g_object_unref(icon);
gtk_container_set_border_width (GTK_CONTAINER (button), 0);
gtk_box_pack_start(GTK_BOX(hbox1),button,FALSE,FALSE,0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),hg->plot_pam);
my_signal_connect(button,"toggled",
G_CALLBACK (do_plot_pam),
(gpointer)hg);
#ifdef __GTK_TOOLTIP_H__
gtk_widget_set_tooltip_text(button,
"Overlay LGS Collisions");
#endif
frame = gtkut_frame_new ("<b>Plot</b>");
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
{
GtkWidget *combo;
GtkListStore *store;
GtkTreeIter iter, iter_set;
GtkCellRenderer *renderer;
store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Single Object",
1, PLOT_ALL_SINGLE, -1);
if(hg->plot_all==PLOT_ALL_SINGLE) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Selected Objects",
1, PLOT_ALL_SELECTED, -1);
if(hg->plot_all==PLOT_ALL_SELECTED) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "All Objects",
1, PLOT_ALL_ALL, -1);
if(hg->plot_all==PLOT_ALL_ALL) iter_set=iter;
combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_container_add (GTK_CONTAINER (frame), combo);
g_object_unref(store);
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo),renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combo), renderer, "text",0,NULL);
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo),&iter_set);
gtk_widget_show(combo);
my_signal_connect (combo,"changed",cc_get_plot_all,
(gpointer)hg);
}
frame = gtkut_frame_new ("<b>Centered on</b>");
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (frame), 3);
hbox1 = gtkut_hbox_new(FALSE,0);
gtk_container_add (GTK_CONTAINER (frame), hbox1);
{
GtkWidget *combo;
GtkListStore *store;
GtkTreeIter iter, iter_set;
GtkCellRenderer *renderer;
store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "MidNight",
1, PLOT_CENTER_MIDNIGHT, -1);
if(hg->plot_center==PLOT_CENTER_MIDNIGHT) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Current",
1, PLOT_CENTER_CURRENT, -1);
if(hg->plot_center==PLOT_CENTER_CURRENT) iter_set=iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, "Meridian",
1, PLOT_CENTER_MERIDIAN, -1);
if(hg->plot_center==PLOT_CENTER_MERIDIAN) iter_set=iter;
combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
gtk_box_pack_start(GTK_BOX(hbox1),combo,FALSE,FALSE,0);
g_object_unref(store);
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo),renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combo), renderer, "text",0,NULL);
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo),&iter_set);
gtk_widget_show(combo);
my_signal_connect (combo,"changed",cc_get_plot_center,
(gpointer)hg);
}
// Drawing Area
ebox=gtk_event_box_new();
gtk_box_pack_start(GTK_BOX(vbox), ebox, TRUE, TRUE, 0);
hg->plot_dw = gtk_drawing_area_new();
gtk_widget_set_events(hg->plot_dw, GDK_SCROLL_MASK |
GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK);
#ifdef USE_GTK3
my_signal_connect(hg->plot_dw,
"draw",
draw_plot_cb,
(gpointer)hg);
#else
my_signal_connect(hg->plot_dw,
"expose-event",
expose_plot_cairo,
(gpointer)hg);
#endif
my_signal_connect(hg->plot_dw,
"configure-event",
configure_plot_cb,
(gpointer)hg);
my_signal_connect(hg->plot_dw,
"scroll-event",
resize_plot_cairo,
(gpointer)hg);
gtk_widget_set_size_request (hg->plot_dw, (gint)(hg->sz_plot*1.5), hg->sz_plot);
gtk_container_add(GTK_CONTAINER(ebox), hg->plot_dw);
gtk_widget_set_app_paintable(hg->plot_dw, TRUE);
gtk_widget_show(hg->plot_dw);
gtk_widget_set_events(ebox, GDK_BUTTON_PRESS_MASK);
my_signal_connect(ebox,
"button-press-event",
plot_button_signal,
(gpointer)hg);
gtk_widget_show_all(hg->plot_main);
hg->plot_timer=g_timeout_add(PLOT_INTERVAL,
(GSourceFunc)update_plot,
(gpointer)hg);
gdk_window_deiconify(gtk_widget_get_window(hg->plot_main));
gdk_window_raise(gtk_widget_get_window(hg->plot_main));
draw_plot_cairo(hg->plot_dw,hg);
}
gboolean plot_button_signal(GtkWidget *widget,
GdkEventButton *event,
gpointer userdata){
typHOE *hg;
gint x,y;
gint i_slot, i_slot_max, i_sel=-1;
gint r_min=15, r;
hg=(typHOE *)userdata;
if (!hg->plot_pam) return(FALSE);
if (hg->lgs_pam_i_max<=0) return(FALSE);
if ( event->button==1 ) {
#ifdef USE_GTK3
gdk_window_get_device_position(gtk_widget_get_window(widget),
event->device, &x,&y,NULL);
#else
gdk_window_get_pointer(gtk_widget_get_window(widget),&x,&y,NULL);
#endif
i_slot_max=hg->lgs_pam[hg->obj[hg->plot_i].pam].line;
for(i_slot=0;i_slot<i_slot_max;i_slot++){
if(hg->pam_x[i_slot]>0){
r=abs(hg->pam_x[i_slot]-x);
if(r<r_min){
i_sel=i_slot;
r_min=r;
}
}
}
hg->pam_slot_i=i_sel;
if(i_sel>=0){
refresh_plot(NULL, (gpointer)hg);
if(!flagPAM){
create_pam_dialog(hg);
}
{
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(hg->pam_tree));
GtkTreePath *path;
GtkTreeIter iter;
path=gtk_tree_path_new_first();
for(i_slot=0;i_slot<i_slot_max;i_slot++){
if(i_slot==hg->pam_slot_i){
gtk_widget_grab_focus (hg->pam_tree);
gtk_tree_view_set_cursor(GTK_TREE_VIEW(hg->pam_tree), path, NULL, FALSE);
break;
}
else{
gtk_tree_path_next(path);
}
}
gtk_tree_path_free(path);
}
}
}
return FALSE;
}
gboolean draw_plot_cairo(GtkWidget *widget, typHOE *hg){
cairo_t *cr;
cairo_surface_t *surface;
cairo_text_extents_t extents;
double x,y;
gint i_list;
gint from_set, to_rise;
double dx,dy,dy2,lx,ly;
double y0,y1,ymin,ymax;
double x_pos, y_pos;
double paz[200],pel[200],ppa[200],pad[200], pjd[200];
double sep[200],phpa[200];
double alambda; //=LONGITUDE_SUBARU; //longitude[deg]
double alamh; //=alambda/360.*24.; //[hour]
double phi; //=LATITUDE_SUBARU; //latitude [deg]
double sinphi; //=sin(pi*phi/180.0);
double cosphi; //=cos(pi*phi/180.0);
//### constants #####
// for AD
double h=0.00130;
double t=273.0; //[K]
double f=0.0; //[hPa]
//#### input #######
char *tmp;
int iyear;
int month;
int iday;
int hour, min;
gdouble sec;
gfloat ihst0, ihst1;
gdouble jd0, jd1;
gfloat ihst1_moon;
//int ihst0=17, ihst1=31;
double a0,d0,d0rad;
double ut,d_ut;
double flst, ha;
double el0, az0;
double el0d, d1rad, d1, ume1, den1, ha1rad, ha1;
double delta_a, delta_d, pa, padeg;
double zrad, ad1, ad0, adsec;
double a1;
int i,iend;
int width, height;
struct ln_zonedate zonedate, zonedate0, zonedate1;
struct ln_date date;
struct ln_equ_posn oequ, oequ_geoc;
struct ln_equ_posn oequ_prec;
struct ln_rst_time orst;
struct ln_hrz_posn ohrz;
struct ln_date odate;
struct ln_zonedate transit;
struct ln_lnlat_posn observer;
double JD, JD_hst, JD_mt, JD_tr, JD_tr0;
gboolean Flag_moon=FALSE;
double hst_mt;
gdouble y_tr;
gdouble scale;
gboolean plot_flag=FALSE;
gint time_label, d_time_label;
gfloat min_offset;
gdouble atw_set, atw_rise, sun_rise, sun_set;
gdouble cx0;
if(!flagPlot) return (FALSE);
get_plot_time(hg);
my_get_local_date(hg->plot_jd0, &zonedate0,hg->obs_timezone);
ihst0=set_ul(0., (float)zonedate0.hours+(float)zonedate0.minutes/60., 24.);
my_get_local_date(hg->plot_jd1, &zonedate1,hg->obs_timezone);
ihst1=set_ul(0., (float)zonedate1.hours+(float)zonedate1.minutes/60., 24.);
/*
printf("zoom=%d Start=%d/%d/%d %d:%d -- End=%d/%d/%d %d:%d\n",
hg->plot_zoom,
zonedate0.years,zonedate0.months,zonedate0.days,
zonedate0.hours,zonedate0.minutes,
zonedate1.years,zonedate1.months,zonedate1.days,
zonedate1.hours,zonedate1.minutes);
*/
while(ihst1<ihst0){
ihst1+=24;
}
observer.lat = hg->obs_latitude;
observer.lng = hg->obs_longitude;
if(hg->plot_output==PLOT_OUTPUT_PDF){
width= (gint)(hg->sz_plot*1.5);
height= hg->sz_plot;
scale=1.0;
dx=width*0.1;
dy=height*0.1;
lx=width*0.8;
if(hg->plot_pam){
dy2=height*0.2;
ly=height*0.7;
}
else{
dy2=height*0.1;
ly=height*0.8;
}
surface = cairo_pdf_surface_create(hg->filename_pdf, width, height);
cr = cairo_create(surface);
}
else if (hg->plot_output==PLOT_OUTPUT_PRINT){
width = (gint)gtk_print_context_get_width(hg->context);
height = (gint)(gtk_print_context_get_height(hg->context)*0.5);
#ifdef USE_WIN32
scale=(gdouble)width/(gdouble)(hg->sz_plot*1.5);
#else
scale=1.0;
#endif
dx=width*0.1;
dy=height*0.1;
lx=width*0.8;
if(hg->plot_pam){
dy2=height*0.2;
ly=height*0.7;
}
else{
dy2=height*0.1;
ly=height*0.8;
}
cr = gtk_print_context_get_cairo_context (hg->context);
cairo_set_source_rgb(cr, 1, 1, 1);
}
else{
GtkAllocation *allocation=g_new(GtkAllocation, 1);
gtk_widget_get_allocation(widget,allocation);
width= allocation->width;
height= allocation->height;
g_free(allocation);
if(width<=1){
gtk_window_get_size(GTK_WINDOW(hg->skymon_main), &width, &height);
}
scale=1.0;
dx=width*0.1;
dy=height*0.1;
lx=width*0.8;
if(hg->plot_pam){
dy2=height*0.2;
ly=height*0.7;
}
else{
dy2=height*0.1;
ly=height*0.8;
}
#ifdef USE_GTK3
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
width, height);
cr = cairo_create(surface);
#else
if(pixmap_plot) g_object_unref(G_OBJECT(pixmap_plot));
pixmap_plot = gdk_pixmap_new(gtk_widget_get_window(widget),
width,
height,
-1);
cr = gdk_cairo_create(pixmap_plot);
#endif
}
if(hg->plot_output==PLOT_OUTPUT_PDF){
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
}
else if (hg->plot_output==PLOT_OUTPUT_PRINT){
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
}
else{
cairo_set_source_rgba(cr, 1.0, 0.9, 0.8, 1.0);
}
/* draw the background */
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
// Object Name etc.
cairo_select_font_face (cr, hg->fontfamily_all, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
tmp=g_strdup_printf("\"%s\" RA=%09.2f Dec=%+010.2f Equinox=%7.2f",
hg->obj[hg->plot_i].name,
hg->obj[hg->plot_i].ra,
hg->obj[hg->plot_i].dec,
hg->obj[hg->plot_i].equinox);
cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, 1.0);
cairo_set_font_size (cr, (gdouble)hg->skymon_allsz*1.2*scale);
cairo_text_extents (cr, tmp, &extents);
cairo_move_to(cr,width/2-extents.width/2,+extents.height);
cairo_show_text(cr, tmp);
if(tmp) g_free(tmp);
/* draw a rectangle */
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
cairo_rectangle(cr, dx,dy2, lx,ly);
cairo_fill(cr);
switch(hg->plot_mode){
case PLOT_EL:
// El
{
gfloat x0;
cairo_set_source_rgba(cr, 1.0, 1.0, 0, 0.2);
cairo_rectangle(cr, dx, dy2, lx,ly*10/90);
cairo_fill(cr);
cairo_set_source_rgba(cr, 1.0, 1.0, 0, 0.2);
cairo_rectangle(cr, dx, dy2+ly*(90-30)/90, lx,ly*15/90);
cairo_fill(cr);
cairo_set_source_rgba(cr, 1.0, 0, 0, 0.2);
cairo_rectangle(cr, dx, dy2+ly*(90-15)/90, lx,ly*15/90);
cairo_fill(cr);
cairo_set_source_rgba(cr, 1.0, 0.6, 0.4, 1.0);
cairo_move_to ( cr, dx, dy2);
cairo_line_to ( cr, width-dx, dy2);
cairo_line_to ( cr, width-dx, height-dy);
cairo_line_to ( cr, dx, height-dy);
cairo_line_to ( cr, dx, dy2);
cairo_set_line_width(cr,2.0*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*60/90);
cairo_line_to ( cr, width-dx, height-dy-ly*60/90);
cairo_set_line_width(cr,1.0*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*30/90);
cairo_line_to ( cr, width-dx, height-dy-ly*30/90);
cairo_set_line_width(cr,1.0*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*15/90);
cairo_line_to ( cr, width-dx, height-dy-ly*15/90);
cairo_set_line_width(cr,1.0*scale);
cairo_stroke(cr);
if(ihst1-ihst0<5.0){
cairo_move_to ( cr, dx, height-dy-ly*70/90);
cairo_line_to ( cr, width-dx, height-dy-ly*70/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*80/90);
cairo_line_to ( cr, width-dx, height-dy-ly*80/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*50/90);
cairo_line_to ( cr, width-dx, height-dy-ly*50/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*40/90);
cairo_line_to ( cr, width-dx, height-dy-ly*40/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*20/90);
cairo_line_to ( cr, width-dx, height-dy-ly*20/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
}
else{
cairo_move_to ( cr, dx, height-dy-ly*75/90);
cairo_line_to ( cr, width-dx, height-dy-ly*75/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
cairo_move_to ( cr, dx, height-dy-ly*45/90);
cairo_line_to ( cr, width-dx, height-dy-ly*45/90);
cairo_set_line_width(cr,0.5*scale);
cairo_stroke(cr);
}
// El Text
cairo_select_font_face (cr, hg->fontfamily_all, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_source_rgba(cr, 0.2, 0.4, 0.1, 0.8);
cairo_set_font_size (cr, (gdouble)hg->skymon_allsz*scale);
cairo_text_extents (cr, "90", &extents);
x = dx-extents.width-5*scale;
y = dy2-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "90");
cairo_text_extents (cr, "60", &extents);
x = dx-extents.width-5*scale;
y = dy2+ly*(90-60)/90-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "60");
cairo_text_extents (cr, "30", &extents);
x = dx-extents.width-5*scale;
y = dy2+ly*(90-30)/90-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "30");
cairo_text_extents (cr, "15", &extents);
x = dx-extents.width-5*scale;
y = dy2+ly*(90-15)/90-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "15");
cairo_text_extents (cr, "0", &extents);
x = dx-extents.width-5*scale;
y = dy2+ly-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "0");
cairo_text_extents (cr, "80", &extents);
x = dx+lx+5*scale;
y = dy2+ly*(90-80)/90-(extents.height/2 + extents.y_bearing);
cairo_move_to(cr, x, y);
cairo_show_text(cr, "80");
x0=extents.width;
cairo_save (cr);
cairo_translate (cr, dx-x0, height/2);
cairo_rotate (cr,M_PI/2);
cairo_select_font_face (cr, hg->fontfamily_all, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
cairo_set_source_rgba(cr, 0.2, 0.4, 0.1, 0.8);
cairo_set_font_size (cr, (gdouble)hg->skymon_allsz*1.4*scale);