-
Notifications
You must be signed in to change notification settings - Fork 22
/
cu_skychart.pas
9050 lines (8871 loc) · 300 KB
/
cu_skychart.pas
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
unit cu_skychart;
{
Copyright (C) 2002 Patrick Chevalley
http://www.ap-i.net
pch@ap-i.net
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.
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.
}
{
Skychart computation component
}
{$mode objfpc}{$H+}
interface
uses
u_translation, gcatunit, UScaleDPI,
BGRABitmap, BGRABitmapTypes, contnrs, FPCanvas,
cu_plot, cu_catalog, cu_fits, u_constant, cu_planet, cu_database,
u_projection, u_util,
pu_addlabel, SysUtils, Classes, Math, Types, Buttons, Dialogs,
Forms, StdCtrls, Controls, ExtCtrls, Graphics, FPImage, LCLType, IntfGraphics;
type
Tint2func = procedure(i, j: integer) of object;
Tfloat2func = procedure(n: string; x, y: double) of object;
TDrawHorizonThread = class(TThread)
public
horizonpicture: TBGRABitmap;
hbmp: TBGRABitmap;
col2: TBGRAPixel;
cfgsc: Tconf_skychart;
working, lowquality: boolean;
num, id: integer;
procedure Execute; override;
constructor Create(CreateSuspended: boolean);
end;
Tskychart = class(TComponent)
private
Fplot: TSplot;
FFits: TFits;
Fcatalog: Tcatalog;
Fplanet: Tplanet;
Fcdb: Tcdcdb;
FShowDetailXY: Tint2func;
FonTelescopeMove: Tfloat2func;
fsat: textfile;
constlabelindex: integer;
bgcra, bgcde, bgfov, bgmis, bgmas, bgrot: double;
bgvalid, HorizonDone: boolean;
bgw, bgh, bgproj, bgflipx, bgflipy: integer;
nebmagmin, nebmagmax: single;
FObjectListLabels: TStringList;
FUpdObsList: boolean;
FUpdObsListTime: TNotifyEvent;
FRefreshImage: TNotifyEvent;
procedure DrawSatel(j, ipla: integer; ra, Dec, ma, diam, pixscale, rot: double;
hidesat, showhide: boolean; ra2000, de2000: double);
procedure InitLabels;
procedure SetLabel(id: integer; xx, yy: single; radius, fontnum, labelnum: integer;
txt: string; align: TLabelAlign = laLeft; orient: single = 0; priority: integer = 5;
opt: boolean = True; lsize: single = -1);
procedure EditLabelPos(lnum, x, y, w, h: integer; moderadec: boolean);
procedure EditLabelTxt(lnum, x, y, w, h: integer; mode: boolean);
procedure DefaultLabel(lnum: integer);
procedure DeleteLabel(lnum: integer);
procedure LabelClick(lnum: integer);
procedure SetImage(Value: TCanvas);
procedure DrawHorizonPicture(hbmp: TBGRABitmap);
function DrawRAline(ra, de, dd, dra: double; drawlabel: boolean; col,linewidth,dir,lh,lt: integer; linestyle: TFPPenStyle; var labelok:boolean): boolean;
function DrawDEline(ra, de, da,dde,ra1: double; drawlabel: boolean; col,linewidth,dir,lh,lt: integer; linestyle: TFPPenStyle; var labelok:boolean): boolean;
public
cfgsc: Tconf_skychart;
labels: array[1..maxlabels] of Tobjlabel;
numlabels: integer;
dsopos: array[1..maxlabels] of TPoint;
numdsopos: integer;
bgbmp: Tbitmap;
bgsettingchange: boolean;
function CenterRot: double;
procedure ResetAllLabel;
procedure AddNewLabel(ra, Dec: double);
procedure SetLang;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property plot: TSplot read Fplot;
property catalog: Tcatalog read Fcatalog write Fcatalog;
property planet: Tplanet read Fplanet write Fplanet;
property cdb: Tcdcdb read Fcdb write Fcdb;
property Fits: TFits read FFits write FFits;
property ObjectListLabels: TStringList read FObjectListLabels
write FObjectListLabels;
property UpdObsList: boolean read FUpdObsList write FUpdObsList;
function Refresh(newtime: boolean): boolean;
function InitCatalog(fov:double): boolean;
function InitTime(newtime: boolean): boolean;
function InitChart(full: boolean = True): boolean;
function InitColor: boolean;
function GetFieldNum(fov: double): integer;
function InitCoordinates: boolean;
function InitObservatory: boolean;
function DrawCustomlabel: boolean;
procedure DrawObsListLabel;
function DrawStars: boolean;
function DrawVarStars: boolean;
function DrawDblStars: boolean;
function DrawDeepSkyObject: boolean;
function DrawImagesList: boolean;
function DrawOutline: boolean;
function DrawDSL: boolean;
function DrawMilkyWay: boolean;
function DrawPlanet: boolean;
procedure DrawEarthShadow(AR, DE, SunDist, MoonDist, MoonDistTopo, flatten: double);
function DrawAsteroidMark: boolean;
function DrawAsteroid: boolean;
function DrawCometMark: boolean;
function DrawComet: boolean;
function DrawBodies: boolean;
procedure DrawArtSat;
function CloseSat: integer;
function FindArtSat(x1, y1, x2, y2: double; nextobj: boolean;
var nom, ma, desc: string): boolean;
function DrawOrbitPath: boolean;
procedure DrawPrePointLine;
procedure DrawGrid(drawlabel: boolean);
procedure DrawAltAzEqGrid;
procedure DrawPole(pole: integer);
procedure DrawEqGrid(drawlabel: boolean; altstyle: boolean = False);
procedure DrawAzGrid(drawlabel: boolean);
procedure DrawGalGrid(drawlabel: boolean);
procedure DrawEclGrid(drawlabel: boolean);
procedure DrawTelescopeLimit;
procedure DrawMeridian;
procedure DrawScale;
procedure DrawBorder;
function DrawConstL: boolean;
function DrawConstB: boolean;
function DrawHorizon: boolean;
function DrawEcliptic: boolean;
function DrawGalactic: boolean;
function DrawEquator: boolean;
function DrawPlanisphereDate: boolean;
function DrawPlanisphereTime: boolean;
procedure OptimizeLabels;
function DrawLabels: boolean;
procedure DrawLegend;
procedure DrawSearchMark(ra, de: double; moving: boolean);
procedure DrawFinderMark(ra, de: double; moving: boolean; num: integer; mark: integer = 0);
procedure DrawEyepieceMask;
procedure DrawCircle;
procedure DrawTarget;
procedure DrawCompass;
procedure DrawCRose;
function TelescopeMove(ra, Dec: double): boolean;
function Telescope2Move(ra, Dec: double): boolean;
procedure GetCoord(x, y: integer; var ra, Dec, a, h, l, b, le, be: double);
procedure MoveCenter(loffset, boffset: double);
procedure MoveChart(ns, ew: integer; movefactor: double);
procedure MovetoXY(X, Y: integer);
procedure MovetoRaDec(ra, Dec: double);
procedure Zoom(zoomfactor: double);
procedure SetFOV(f: double);
function PoleRot2000(ra, Dec: double): double;
procedure FormatCatRec(rec: Gcatrec; var desc: string);
procedure FindRiseSet(mode: integer);
function FindatRaDec(ra, Dec, dx: double; searchcenter: boolean;
showall: boolean = False; ftype: integer = ftAll; planetcenter: boolean = False): boolean;
procedure GetLabPos(ra, Dec, r: double; w, h: integer; var x, y: integer);
procedure FindList(ra, Dec, dx, dy: double; var Text, msg: string; showall, allobject, trunc, usefov: boolean; maxln:integer=1000);
procedure FindListWin(var Text, msg: string; showall, allobject: boolean);
property OnShowDetailXY: Tint2func read FShowDetailXY write FShowDetailXY;
function GetChartInfo(sep: string = blank): string;
function GetChartPos: string;
procedure LoadHorizon;
procedure LoadHorizonPicture(fname: string);
property Image: TCanvas write SetImage;
property onRefreshImage: TNotifyEvent read FRefreshImage write FRefreshImage;
property onUpdObsListTime: TNotifyEvent read FUpdObsListTime write FUpdObsListTime;
property onTelescopeMove: Tfloat2func read FonTelescopeMove write FonTelescopeMove;
end;
implementation
function doSimLabel(simnb, step, simlabel: integer): boolean;
begin
Result := False;
case simlabel of
-1000.. -1: Result := ((step mod abs(simlabel)) = 0); // one of ...
0: Result := (simnb = 1); // none if more than one point
1: Result := (step = 0); // first
2: Result := (step = simnb - 1); // last
3: Result := True; // every
end;
end;
constructor Tskychart.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// set safe value
cfgsc := Tconf_skychart.Create;
cfgsc.quick := False;
cfgsc.JDChart := jd2000;
cfgsc.lastJDchart := -1E25;
cfgsc.racentre := 0;
cfgsc.decentre := 0;
cfgsc.fov := 1;
cfgsc.theta := 0;
cfgsc.projtype := 'A';
cfgsc.ProjPole := Equat;
cfgsc.FlipX := 1;
cfgsc.FlipY := 1;
cfgsc.WindowRatio := 1;
cfgsc.BxGlb := 1;
cfgsc.ByGlb := 1;
cfgsc.AxGlb := 0;
cfgsc.AyGlb := 0;
cfgsc.xshift := 0;
cfgsc.yshift := 0;
cfgsc.xmin := 0;
cfgsc.xmax := 100;
cfgsc.ymin := 0;
cfgsc.ymax := 100;
cfgsc.RefractionOffset := 0;
cfgsc.AsteroidLstSize := 0;
cfgsc.CometLstSize := 0;
cfgsc.nummodlabels := 0;
cfgsc.posmodlabels := 0;
cfgsc.numcustomlabels := 0;
cfgsc.poscustomlabels := 0;
cfgsc.LeftMargin := 0;
cfgsc.RightMargin := 0;
cfgsc.TopMargin := 0;
cfgsc.BottomMargin := 0;
Fplot := TSplot.Create(AOwner);
Fplot.OnEditLabelPos := @EditLabelPos;
Fplot.OnEditLabelTxt := @EditLabelTxt;
Fplot.OnDefaultLabel := @DefaultLabel;
Fplot.OnDeleteLabel := @DeleteLabel;
Fplot.OnDeleteAllLabel := @ResetAllLabel;
Fplot.OnLabelClick := @LabelClick;
bgbmp := Tbitmap.Create;
bgsettingchange := False;
bgvalid := False;
end;
destructor Tskychart.Destroy;
begin
try
Fplot.Free;
cfgsc.Free;
bgbmp.Free;
inherited Destroy;
except
writetrace('error destroy ' + Name);
end;
end;
procedure Tskychart.SetLang;
begin
if f_addlabel <> nil then
f_addlabel.SetLang;
Fplot.editlabelmenu.Items[2].Caption := rsMoveLabel;
Fplot.editlabelmenu.Items[3].Caption := rsOffsetLabel;
Fplot.editlabelmenu.Items[4].Caption := rsEditLabel;
Fplot.editlabelmenu.Items[5].Caption := rsDefaultLabel;
Fplot.editlabelmenu.Items[6].Caption := rsHideLabel;
Fplot.editlabelmenu.Items[7].Caption := rsResetAllLabe;
end;
procedure Tskychart.SetImage(Value: TCanvas);
begin
FPlot.Image := Value;
end;
function Tskychart.Refresh(newtime: boolean): boolean;
var
savmag: double;
savebg: Tcolor;
savfilter, saveautofilter, savfillmw, scopemark, savApparentPos: boolean;
saveplaplot: integer;
step: string;
begin
try
step:='Init';
if VerboseMsg then
begin
if cfgsc.quick and FPlot.cfgplot.red_move then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Simplified Refresh')
else
WriteTrace('SkyChart ' + cfgsc.chartname + ': Full Refresh');
end;
savmag := Fcatalog.cfgshr.StarMagFilter[cfgsc.FieldNum];
savApparentPos := cfgsc.ApparentPos;
savfilter := Fcatalog.cfgshr.StarFilter;
saveautofilter := Fcatalog.cfgshr.AutoStarFilter;
savfillmw := cfgsc.FillMilkyWay;
scopemark := cfgsc.ScopeMark;
saveplaplot := Fplot.cfgplot.plaplot;
savebg := Fplot.cfgplot.color[0];
newtime := newtime or (cfgsc.fov > (10 * minarc));
try
chdir(appdir);
// initialize chart value
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init');
cfgsc.msg := '';
step:='Init observatory';
InitObservatory;
step:='Init time';
InitTime(newtime);
step:='Init chart';
InitChart;
step:='Init coordinates';
InitCoordinates; // now include ComputePlanet
if cfgsc.quick and FPlot.cfgplot.red_move then
begin
Fcatalog.cfgshr.StarFilter := True;
//if Fplot.cfgplot.plaplot=2 then Fplot.cfgplot.plaplot := 1;
end
else
begin
step:='Init labels';
InitLabels;
end;
step:='Init color';
InitColor; // after ComputePlanet
// draw objects
HorizonDone := False;
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Open catalogs');
step:='Open catalog';
Fcatalog.OpenCat(cfgsc);
step:='Init catalog';
InitCatalog(cfgsc.fov);
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': begin drawing');
// first the extended object
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
step:='draw images 1';
// the images first on canvas that not support the transparency
if cfgsc.PlotImageFirst then
begin
if cfgsc.ShowHorizonPicture and (not HorizonDone) then
DrawHorizon;
if cfgsc.ShowImageList then
DrawImagesList;
end;
DrawMilkyWay; // most extended first
// EQ grid in ALt/Az mode
DrawAltAzEqGrid;
// then the horizon line if transparent
if (not cfgsc.horizonopaque) and (not HorizonDone) then
DrawHorizon;
end;
// the DSO
step:='draw dso';
DrawDeepSkyObject;
step:='draw lines 1';
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
if cfgsc.showline then
begin
DrawDSL;
end;
DrawOutline;
DrawCometMark;
DrawComet;
end;
if not (cfgsc.ShowPlanet and FPlot.cfgplot.TransparentPlanet and
(FPlot.cfgplot.plaplot = 1)) then
begin
// then the lines if planet opaque or not line mode
DrawGrid(False);
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
DrawConstL;
DrawConstB;
DrawEcliptic;
DrawGalactic;
DrawEquator;
DrawPrePointLine;
DrawTelescopeLimit;
end;
end;
// the stars
step:='draw stars';
if cfgsc.showstars then
DrawStars;
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
if cfgsc.showstars then
DrawDblStars;
if cfgsc.showstars then
DrawVarStars;
end;
// the planets
step:='draw planets';
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
DrawAsteroidMark;
DrawAsteroid;
DrawBodies;
if cfgsc.SimLine then
DrawOrbitPath;
end;
if cfgsc.ShowPlanetValid then
DrawPlanet;
step:='draw lines 2';
if (cfgsc.ShowPlanet and FPlot.cfgplot.TransparentPlanet and
(FPlot.cfgplot.plaplot = 1)) then
begin
// then the lines if planet transparent + line mode
DrawGrid(False);
if not (cfgsc.quick and FPlot.cfgplot.red_move) then
begin
DrawConstL;
DrawConstB;
DrawEcliptic;
DrawGalactic;
DrawEquator;
DrawPrePointLine;
DrawTelescopeLimit;
end;
end;
// Finder mark
DrawCircle;
// Artificials satellites
step:='draw satellites';
if cfgsc.ShowArtSat then
DrawArtSat;
// BG image
step:='draw image list';
if (not (cfgsc.quick and FPlot.cfgplot.red_move)) and (not cfgsc.PlotImageFirst) and
cfgsc.ShowImageList then
DrawImagesList;
// the labels
step:='draw label';
if (not (cfgsc.quick and FPlot.cfgplot.red_move)) and cfgsc.showlabelall then
DrawLabels;
// the horizon line if not transparent
step:='draw horizon';
if (not (cfgsc.quick and FPlot.cfgplot.red_move)) and (not HorizonDone) then
DrawHorizon;
// the coordinates grid labels
step:='draw grid';
if cfgsc.ShowGridNum then
DrawGrid(True);
// Mask the chart outside of eyepiece
step:='draw mask';
DrawEyepieceMask;
// the compass and scale
step:='draw compass';
DrawCompass;
DrawTarget;
// Planisphere
step:='draw planisphere';
DrawPlanisphereTime;
DrawPlanisphereDate;
// Draw the chart border
step:='draw border';
DrawBorder;
// the chart legend
step:='draw legend';
DrawLegend;
// refresh telescope mark
if scopemark then
cfgsc.ScopeMark := True;
Result := True;
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': end drawing');
step:='finalize';
finally
Fcatalog.CloseCat;
cfgsc.ApparentPos := savApparentPos;
if cfgsc.quick and FPlot.cfgplot.red_move then
begin
Fcatalog.cfgshr.StarMagFilter[cfgsc.FieldNum] := savmag;
Fcatalog.cfgshr.StarFilter := savfilter;
Fcatalog.cfgshr.AutoStarFilter := saveautofilter;
Fplot.cfgplot.plaplot := saveplaplot;
end;
Fplot.cfgplot.color[0] := savebg;
cfgsc.FillMilkyWay := savfillmw;
cfgsc.quick := False;
end;
step:='refresh image';
if assigned(FRefreshImage) then
FRefreshImage(self);
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': end Refresh');
except
on E: Exception do begin
cfgsc.msg := 'Draw chart, '+step+' error: ' + E.Message;
WriteTrace(cfgsc.msg); // better to write the error two time than risk the message is overwriten
end;
end;
end;
function Tskychart.InitCatalog(fov:double): boolean;
var
i,FieldNum: integer;
mag, magmax, f: double;
vostar_magmax: double;
procedure InitStarC(cat: integer; defaultmag: double);
{ determine if the star catalog is active at this scale }
begin
if Fcatalog.cfgcat.starcatdef[cat - BaseStar] and
(FieldNum >= Fcatalog.cfgcat.starcatfield[cat - BaseStar, 1]) and
(FieldNum <= Fcatalog.cfgcat.starcatfield[cat - BaseStar, 2]) then
begin
Fcatalog.cfgcat.starcaton[cat - BaseStar] := True;
magmax := max(magmax, defaultmag);
if Fcatalog.cfgshr.StarFilter then
mag := MinValue([defaultmag, Fcatalog.cfgcat.StarMagMax])
else
mag := defaultmag;
Fplot.cfgchart.min_ma := MaxValue([Fplot.cfgchart.min_ma, mag]);
end
else
Fcatalog.cfgcat.starcaton[cat - BaseStar] := False;
end;
procedure InitVarC(cat: integer);
{ determine if the variable star catalog is active at this scale }
begin
if Fcatalog.cfgcat.varstarcatdef[cat - BaseVar] and
(FieldNum >= Fcatalog.cfgcat.varstarcatfield[cat - BaseVar, 1]) and
(FieldNum <= Fcatalog.cfgcat.varstarcatfield[cat - BaseVar, 2]) then
Fcatalog.cfgcat.varstarcaton[cat - BaseVar] := True
else
Fcatalog.cfgcat.varstarcaton[cat - BaseVar] := False;
end;
procedure InitDblC(cat: integer);
{ determine if the double star catalog is active at this scale }
begin
if Fcatalog.cfgcat.dblstarcatdef[cat - BaseDbl] and
(FieldNum >= Fcatalog.cfgcat.dblstarcatfield[cat - BaseDbl, 1]) and
(FieldNum <= Fcatalog.cfgcat.dblstarcatfield[cat - BaseDbl, 2]) then
Fcatalog.cfgcat.dblstarcaton[cat - BaseDbl] := True
else
Fcatalog.cfgcat.dblstarcaton[cat - BaseDbl] := False;
end;
procedure InitNebC(cat: integer);
{ determine if the nebulae catalog is active at this scale }
begin
if Fcatalog.cfgcat.nebcatdef[cat - BaseNeb] and
(FieldNum >= Fcatalog.cfgcat.nebcatfield[cat - BaseNeb, 1]) and
(FieldNum <= Fcatalog.cfgcat.nebcatfield[cat - BaseNeb, 2]) then
Fcatalog.cfgcat.nebcaton[cat - BaseNeb] := True
else
Fcatalog.cfgcat.nebcaton[cat - BaseNeb] := False;
end;
begin
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init catalogs');
vostar_magmax := Fcatalog.GetVOstarmag;
if fov=cfgsc.fov then
FieldNum:=cfgsc.FieldNum
else
FieldNum := GetFieldNum(fov - musec);
if Fcatalog.cfgshr.AutoStarFilter then
begin
f := fov - 15 * minarc;
if (f > minarc) or cfgsc.Quick then
Fcatalog.cfgcat.StarMagMax :=
max(5,
round(10 * (
Fcatalog.cfgshr.AutoStarFilterMag + 2.4 * log10((pid2*pid2) / (f*f*(1+2*cos(min(3*f,pid2)) ))))
) / 10
)
else
Fcatalog.cfgcat.StarMagMax := 99;
end
else
Fcatalog.cfgcat.StarMagMax := Fcatalog.cfgshr.StarMagFilter[FieldNum];
if cfgsc.quick and FPlot.cfgplot.red_move then begin
Fcatalog.cfgcat.Quick := true;
Fcatalog.cfgcat.StarMagMax := min(16,Fcatalog.cfgcat.StarMagMax - 2);
end
else
Fcatalog.cfgcat.Quick := false;
Fcatalog.cfgcat.NebMagMax := Fcatalog.cfgshr.NebMagFilter[FieldNum];
Fcatalog.cfgcat.NebSizeMin := Fcatalog.cfgshr.NebSizeFilter[FieldNum];
Fplot.cfgchart.min_ma := 1;
magmax := 1;
{ activate the star catalog}
InitStarC(dsbase, 5.5);
InitStarC(bsc, 6.5);
InitStarC(sky2000, 9.5);
InitStarC(DefStar, 10);
InitStarC(tyc, 11);
InitStarC(tyc2, 12);
InitStarC(dstyc, 12);
InitStarC(tic, 12);
InitStarC(gsc, 14.5);
InitStarC(gscf, 14.5);
InitStarC(gscc, 14.5);
InitStarC(dsgsc, 14.5);
InitStarC(microcat, 16);
InitStarC(hn290, Fcatalog.Get290MagMax);
InitStarC(gaia, Fcatalog.GetGaiaMagMax);
InitStarC(usnoa, 18);
InitStarC(usnob, 21);
InitStarC(vostar, vostar_magmax);
{ activate the other catalog }
InitVarC(gcvs);
InitDblC(wds);
for i := 1 to MaxNebCatalog do
Fcatalog.cfgcat.nebcaton[i] := False;
if Fcatalog.cfgcat.nebcatdef[uneb - BaseNeb] then
InitNebC(uneb);
if Fcatalog.cfgcat.nebcatdef[voneb - BaseNeb] then
InitNebC(voneb);
if cfgsc.shownebulae then
begin
InitNebC(sac);
InitNebC(ngc);
InitNebC(lbn);
InitNebC(sh2);
InitNebC(drk);
InitNebC(rc3);
InitNebC(pgc);
InitNebC(ocl);
InitNebC(gcm);
InitNebC(gpn);
end;
Fcatalog.cfgcat.starcaton[gcstar - BaseStar] := False;
Fcatalog.cfgcat.varstarcaton[gcvar - Basevar] := False;
Fcatalog.cfgcat.dblstarcaton[gcdbl - Basedbl] := False;
Fcatalog.cfgcat.nebcaton[gcneb - Baseneb] := False;
Fcatalog.cfgcat.lincaton[gclin - Baselin] := False;
for i := 1 to Fcatalog.cfgcat.GCatNum do
if Fcatalog.cfgcat.GCatLst[i - 1].Actif and
(FieldNum >= Fcatalog.cfgcat.GCatLst[i - 1].min) and
(FieldNum <= Fcatalog.cfgcat.GCatLst[i - 1].max) then
begin
Fcatalog.cfgcat.GCatLst[i - 1].CatOn := True;
case Fcatalog.cfgcat.GCatLst[i - 1].cattype of
rtstar:
begin
magmax := max(magmax, Fcatalog.cfgcat.GCatLst[i - 1].magmax);
Fcatalog.cfgcat.starcaton[gcstar - BaseStar] := True;
if Fcatalog.cfgshr.StarFilter then
mag := min(Fcatalog.cfgcat.GCatLst[i - 1].magmax, Fcatalog.cfgcat.StarMagMax)
else
mag := Fcatalog.cfgcat.GCatLst[i - 1].magmax;
Fplot.cfgchart.min_ma := max(Fplot.cfgchart.min_ma, mag);
end;
rtvar: Fcatalog.cfgcat.varstarcaton[gcvar - Basevar] := True;
rtdbl: Fcatalog.cfgcat.dblstarcaton[gcdbl - Basedbl] := True;
rtneb: if cfgsc.shownebulae then
Fcatalog.cfgcat.nebcaton[gcneb - Baseneb] := True;
rtlin: Fcatalog.cfgcat.lincaton[gclin - Baselin] := True;
end;
end
else
Fcatalog.cfgcat.GCatLst[i - 1].CatOn := False;
// Store mag limit for this chart
Fplot.cfgchart.max_catalog_mag := magmax;
cfgsc.StarFilter := Fcatalog.cfgshr.StarFilter;
cfgsc.StarMagMax := Fcatalog.cfgcat.StarMagMax;
cfgsc.NebFilter := Fcatalog.cfgshr.NebFilter;
cfgsc.NebMagMax := Fcatalog.cfgcat.NebMagMax;
if cfgsc.quick and FPlot.cfgplot.red_move and
(Fplot.cfgchart.min_ma = Fcatalog.cfgcat.StarMagMax) then
Fplot.cfgchart.min_ma := Fplot.cfgchart.min_ma + 2;
cfgsc.ONGCimg := FFits.ImagesForCatalog('ONGC');
Result := True;
end;
function Tskychart.InitTime(newtime: boolean): boolean;
var
xp, yp, MJD, A, C: double;
begin
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init time');
if newtime and cfgsc.UseSystemTime and (not cfgsc.quick) then
SetCurrentTime(cfgsc);
cfgsc.DT_UT := DTminusUT(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay, cfgsc);
cfgsc.DT_UTerr := DTminusUTError(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay, cfgsc);
cfgsc.CurJDTT := jd(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay, cfgsc.CurTime -
cfgsc.TimeZone + cfgsc.DT_UT); // TT
cfgsc.CurJDUT := jd(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay, cfgsc.CurTime -
cfgsc.TimeZone);
// UT
cfgsc.jd0 := jd(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay, 0);
// thing to do when the date change
if (not (cfgsc.TrackOn and ((cfgsc.TrackType <= TTplanet) or (cfgsc.TrackType = TTequat)))) and
(((cfgsc.FindType < ftPla) and (abs(cfgsc.CurJDTT - cfgsc.FindJD) > (3652))) or
// 10 year limit for precession
((cfgsc.FindType >= ftPla) and (abs(cfgsc.CurJDTT - cfgsc.LastJD) >
(30 / 86400))) // 30 sec. limit for moving objects
) then
begin
cfgsc.FindOk := False; // last search no longuer valid
end;
if ((FUpdObsList) and (abs(cfgsc.CurJDTT - cfgsc.LastJD) > (1 / 1440))) then
begin
if assigned(FUpdObsListTime) then
FUpdObsListTime(self);
end;
if cfgsc.CurJDTT <> cfgsc.LastJD then
begin
if not cfgsc.NewArtSat then
cfgsc.ShowArtSat := False; // satellite position not valid
end;
cfgsc.LastJD := cfgsc.CurJDTT;
if (cfgsc.Equinoxtype = 2) then
begin // use equinox of the date
cfgsc.JDChart := jd(cfgsc.CurYear, cfgsc.CurMonth, cfgsc.CurDay,
cfgsc.CurTime - cfgsc.TimeZone); // UT
cfgsc.EquinoxName := rsDate;
end
else
begin
cfgsc.JDChart := cfgsc.DefaultJDChart;
cfgsc.EquinoxName := cfgsc.EquinoxChart;
end;
if (cfgsc.lastJDchart < -1E20) then
cfgsc.lastJDchart := cfgsc.JDchart; // initial value
// position of J2000 pole in current coordinates
cfgsc.rap2000 := 0;
cfgsc.dep2000 := pid2;
precession(jd2000, cfgsc.JDChart, cfgsc.rap2000, cfgsc.dep2000);
// Pole motion (must be done after setting the time)
xp := cfgsc.ObsXP;
yp := cfgsc.ObsYP;
if (xp = 0) and (yp = 0) and (cfgsc.CurJDUT > jd2000) and (cfgsc.CurJDUT < 2458849.5) then
begin // 2000-2020
// compute predicted value using formula in 3 January 2013 IERS BULLETIN-A
MJD := cfgsc.CurJDUT - 2400000.5;
A := 2 * pi * (MJD - 56295) / 365.25;
C := 2 * pi * (MJD - 56295) / 435;
xp := 0.0940 - 0.0383 * cos(A) - 0.1277 * sin(A) + 0.0101 * cos(C) + 0.0530 * sin(C);
yp := 0.3393 - 0.1066 * cos(A) + 0.0261 * sin(A) + 0.0530 * cos(C) - 0.0101 * sin(C);
end;
if (xp = 0) and (yp = 0) then
begin
cfgsc.ObsELONG := -deg2rad * cfgsc.ObsLongitude;
cfgsc.ObsPHI := deg2rad * cfgsc.ObsLatitude;
cfgsc.ObsDAZ := 0;
end
else
sla_POLMO(-deg2rad * cfgsc.ObsLongitude, deg2rad * cfgsc.ObsLatitude,
deg2rad * XP / 3600, deg2rad * YP / 3600, cfgsc.ObsELONG, cfgsc.ObsPHI, cfgsc.ObsDAZ);
Result := True;
end;
function Tskychart.InitObservatory: boolean;
var
u, p, r90, rm, dip, ht: double;
const
ratio = 0.99664719;
H0 = 6378140.0;
SOLSID = 1.00273790935; // Ratio between solar and sidereal time
C = 173.14463331; // Speed of light (AU per day)
begin
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init observatory');
cfgsc.tz.Longitude:=cfgsc.ObsLongitude;
cfgsc.TimeZone := cfgsc.tz.SecondsOffset / 3600;
p := deg2rad * cfgsc.ObsLatitude;
u := arctan(ratio * tan(p));
cfgsc.ObsRoSinPhi := ratio * sin(u) + (cfgsc.ObsAltitude / H0) * sin(p);
cfgsc.ObsRoCosPhi := cos(u) + (cfgsc.ObsAltitude / H0) * cos(p);
// compute refraction constant
cfgsc.ObsRefractionCor := (cfgsc.ObsPressure / 1010) * (283 / (273 + cfgsc.ObsTemperature));
sla_REFCO(cfgsc.ObsAltitude, 273.15 + cfgsc.ObsTemperature, cfgsc.ObsPressure,
cfgsc.ObsRH, RefractionWavelength, deg2rad * cfgsc.ObsLatitude, cfgsc.ObsTlr,
1E-8, cfgsc.ObsRefA, cfgsc.ObsRefb);
// horizon dip (Wittmann, 1997 Astron. Nachr. 318)
if cfgsc.ShowHorizonDepression and (cfgsc.ObsAltitude > 10) then
begin
r90 := 0;
Refraction(r90, True, cfgsc, 2);
r90 := rad2deg * r90;
rm := r90 * ((2 * exp(cfgsc.ObsAltitude / 8000)) / (1 + exp(-cfgsc.ObsAltitude / 12300)));
dip := sqrt(cfgsc.ObsAltitude) * 0.02931;
ht := dip + rm;
cfgsc.ObsHorizonDepression := min(0, -deg2rad * ht);
end
else
begin
cfgsc.ShowHorizonDepression := False;
cfgsc.ObsHorizonDepression := 0;
end;
// diurnal abberation
sla_GEOC(p, cfgsc.ObsAltitude, cfgsc.ObsRAU, cfgsc.ObsZAU);
cfgsc.Diurab := PI2 * cfgsc.ObsRAU * SOLSID / C;
// horizon drawing
if cfgsc.HorizonFile<>'' then LoadHorizon;
if cfgsc.ShowHorizonPicture then LoadHorizonPicture(cfgsc.HorizonPictureFile);
cfgsc.ShowHorizonPicture := cfgsc.ShowHorizonPicture and cfgsc.horizonpicturevalid;
Result := True;
end;
function Tskychart.InitChart(full: boolean = True): boolean;
var
w, h: double;
begin
// do not add more function here as this is also called at the chart create
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init chart');
if full then
begin
// we must know the projection now
w := cfgsc.fov;
h := cfgsc.fov / cfgsc.WindowRatio;
w := MaxValue([w, h]);
cfgsc.FieldNum := GetFieldNum(w - musec);
cfgsc.projtype := (cfgsc.projname[cfgsc.fieldnum] + 'A')[1];
// full sky button
if (cfgsc.ProjPole = Altaz) and ((cfgsc.projtype = 'T') or
(cfgsc.projtype = 'S') or (cfgsc.ProjEquatorCentered)) and (cfgsc.fov > pi) and
(abs(cfgsc.hcentre) > pid4) then
cfgsc.projtype := 'A';
end;
cfgsc.xmin := cfgsc.LeftMargin;
cfgsc.ymin := cfgsc.TopMargin;
cfgsc.xmax := Fplot.cfgchart.Width - cfgsc.RightMargin;
cfgsc.ymax := Fplot.cfgchart.Height - cfgsc.BottomMargin;
Fplot.cfgplot.xmin := cfgsc.xmin;
Fplot.cfgplot.ymin := cfgsc.ymin;
Fplot.cfgplot.xmax := cfgsc.xmax;
Fplot.cfgplot.ymax := cfgsc.ymax;
ScaleWindow(cfgsc);
Result := True;
end;
function Tskychart.InitColor: boolean;
var
i,n: integer;
p: PBGRAPixel;
begin
if VerboseMsg then
WriteTrace('SkyChart ' + cfgsc.chartname + ': Init colors');
if Fplot.cfgplot.color[0] > Fplot.cfgplot.color[11] then
begin // white background
Fplot.cfgplot.AutoSkyColor := False;
Fplot.cfgplot.autoskycolorValid := False;
Fplot.cfgplot.StarPlot := 0;
Fplot.cfgplot.NebPlot := 0;
cfgsc.FillMilkyWay := False;
cfgsc.WhiteBg := True;
end
else
cfgsc.WhiteBg := False;
if (cfgsc.fov > 10 * deg2rad) then
begin
if cfgsc.CurSunH > 0 then begin
i := 1;
n := 0;
end
else if cfgsc.CurSunH > -5 * deg2rad then begin
i := 2;
n := 30;
end
else if cfgsc.CurSunH > -11 * deg2rad then begin
i := 3;
n := 50;
end
else if cfgsc.CurSunH > -13 * deg2rad then begin
i := 4;
n := 70;
end
else if cfgsc.CurSunH > -15 * deg2rad then begin
i := 5;
n := 90;
end
else if cfgsc.CurSunH > -17 * deg2rad then begin
i := 6;
n := 110;
end
else begin
i := 7;
n := 130;
end;
end
else
if cfgsc.CurSunH > 0 then begin
i := 5;
n := 90;
end
else if cfgsc.CurSunH > -5 * deg2rad then begin
i := 5;
n := 90;
end
else if cfgsc.CurSunH > -11 * deg2rad then begin
i := 6;
n := 110;
end
else if cfgsc.CurSunH > -13 * deg2rad then begin
i := 6;
n := 110;
end
else if cfgsc.CurSunH > -15 * deg2rad then begin
i := 7;
n := 130;
end
else if cfgsc.CurSunH > -17 * deg2rad then begin
i := 7;
n := 130;
end
else begin
i := 7;
n := 130;
end;
if (i >= 5) and (cfgsc.CurMoonH > 0) then
begin
if (cfgsc.CurMoonIllum > 0.1) and (cfgsc.CurMoonIllum < 0.5) then begin
i := i - 1;
n := n - 20;
end;
if (cfgsc.CurMoonIllum >= 0.5) then begin
i := i - 2;
n := n - 50;
end;
if i < 5 then begin
i := 5;
n := 90;
end;
end;
if Fplot.cfgplot.autoskycolorValid and (cfgsc.Projpole = AltAz) then
begin
Fplot.cfgplot.color[0] := Fplot.cfgplot.SkyColor[i];
end
else
Fplot.cfgplot.color[0] := Fplot.cfgplot.bgColor;
Fplot.cfgplot.backgroundcolor := Fplot.cfgplot.color[0];
if not cfgsc.DarkenHorizonPicture then n:=0;
if cfgsc.horizonpicturevalid and (n <> cfgsc.horizondarken) then
begin
cfgsc.horizondarken := n;
cfgsc.horizonpicturedark.Assign(cfgsc.horizonpicture);
p := cfgsc.horizonpicturedark.Data;
for i := cfgsc.horizonpicturedark.NbPixels-1 downto 0 do
begin
if p^.alpha>0 then begin
p^.red := max(0,p^.red-n);
p^.green := max(0,p^.green-n);
p^.blue := max(0,p^.blue-n);
end;
inc(p);
end;
cfgsc.horizonpicturedark.InvalidateBitmap;
end;
Fplot.init(Fplot.cfgchart.Width, Fplot.cfgchart.Height);
if Fplot.cfgchart.onprinter and (Fplot.cfgplot.starplot = 0) and
(Fplot.cfgplot.color[1] <> clBlack) then
begin
Fplot.cfgplot.color[0] := clBlack;
Fplot.cfgplot.color[11] := clWhite;
end;
Result := True;
end;
function Tskychart.GetFieldNum(fov: double): integer;
var
i: integer;
begin
fov := rad2deg * fov;
if fov > 360 then
fov := 360;
Result := MaxField;
if Fcatalog <> nil then
for i := 0 to MaxField do
if Fcatalog.cfgshr.FieldNum[i] > fov then