-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAutoIntegrateGUI.js
More file actions
8699 lines (7811 loc) · 447 KB
/
AutoIntegrateGUI.js
File metadata and controls
8699 lines (7811 loc) · 447 KB
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
/*
AutoIntegrate GUI components.
Interface functions:
See end of the file.
Interface objects:
AutoIntegrateDialog
This product is based on software from the PixInsight project, developed
by Pleiades Astrophoto and its contributors (https://pixinsight.com/).
Copyright (c) 2018-2026 Jarmo Ruuth.
Window name prefix and icon location code
Copyright (c) 2021 rob pfile.
Crop to common area code
Copyright (c) 2022 Jean-Marc Lugrin.
Window name prefix and icon location code
Copyright (c) 2021 rob pfile.
This product is based on software from the PixInsight project, developed
by Pleiades Astrophoto and its contributors (https://pixinsight.com/).
*/
#ifndef AUTOINTEGRATEGUI_JS
#define AUTOINTEGRATEGUI_JS
#include "AutoIntegrateMetricsVisualizer.js"
#include "AutoIntegrateTutorial.js"
#include "AutoIntegrateGUITools.js"
#include "AutoIntegrateEnhancementsGUI.js"
function AutoIntegrateNarrowbandSelectMultipleDialog(global, mappings_list)
{
this.__base__ = Dialog;
this.__base__();
this.restyle();
var self = this;
this.labelWidth = this.font.width( "Object identifier:M" );
this.editWidth = this.font.width( 'M' )*40;
this.names = mappings_list;
this.narrowbandSelectMultipleLabel = new Label( this );
this.narrowbandSelectMultipleLabel.text = "Select mappings:"
this.select_Sizer = new VerticalSizer;
this.select_Sizer.spacing = 6;
var current_mappings = mappings_list.split(",");
var checked_status = [];
for (var i = 0; i < global.narrowBandPalettes.length; i++) {
if (!global.narrowBandPalettes[i].checkable) {
continue;
}
var checked = false;
for (var j = 0; j < current_mappings.length; j++) {
if (global.narrowBandPalettes[i].name == current_mappings[j].trim()) {
checked = true;
break;
}
}
checked_status[i] = checked
var cb = new CheckBox( this );
cb.text = global.narrowBandPalettes[i].name;
cb.toolTip = "<p>R: " + global.narrowBandPalettes[i].R + ", G: " + global.narrowBandPalettes[i].G + ", B: " + global.narrowBandPalettes[i].B + "</p>";
cb.checked = checked;
cb.index = i;
cb.onClick = function(checked) {
checked_status[this.index] = checked;
}
this.select_Sizer.add( cb );
}
this.select_Sizer.addStretch();
// Common Buttons
this.ok_Button = new PushButton( this );
this.ok_Button.text = "OK";
this.ok_Button.icon = this.scaledResource( ":/icons/ok.png" );
this.ok_Button.onClick = function()
{
self.names = "";
for (var i = 0; i < global.narrowBandPalettes.length; i++) {
if (checked_status[i]) {
if (self.names == "") {
self.names = global.narrowBandPalettes[i].name;
} else {
self.names = self.names + ", " + global.narrowBandPalettes[i].name;
}
}
}
self.dialog.ok();
};
this.cancel_Button = new PushButton( this );
this.cancel_Button.text = "Cancel";
this.cancel_Button.icon = this.scaledResource( ":/icons/cancel.png" );
this.cancel_Button.onClick = function()
{
self.dialog.cancel();
};
this.buttons_Sizer = new HorizontalSizer;
this.buttons_Sizer.spacing = 6;
this.buttons_Sizer.addStretch();
this.buttons_Sizer.add( this.ok_Button );
this.buttons_Sizer.add( this.cancel_Button );
this.sizer = new VerticalSizer;
this.sizer.margin = 6;
this.sizer.spacing = 4;
this.sizer.add( this.narrowbandSelectMultipleLabel );
this.sizer.add( this.select_Sizer );
this.sizer.add( this.buttons_Sizer );
this.windowTitle = "Select Narrowband Mappings";
this.ensureLayoutUpdated();
this.adjustToContents();
}
AutoIntegrateNarrowbandSelectMultipleDialog.prototype = new Dialog;
function AutoIntegrateGUI(global, util, engine, flowchart)
{
this.__base__ = Object;
this.__base__();
if (global.debug) console.writeln("AutoIntegrateGUI");
var guitools = new AutoIntegrateGUITools(this, global, util, engine);
this.guitools = guitools;
var enhancements_gui = null;
var par = global.par;
var ppar = global.ppar;
var dialog_mode = 1; // 0 = minimized, 1 = normal, 2 = maximized
var dialog_old_position = null;
var dialog_min_position = null;
var infoLabel;
var imageInfoLabel;
var windowPrefixHelpTips; // For updating tooTip
var autoContinueWindowPrefixHelpTips; // For updating tooTip
var closeAllPrefixButton; // For updating toolTip
var windowPrefixComboBox = null; // For updating prefix name list
var autoContinueWindowPrefixComboBox = null; // For updating prefix name list
var outputDirEdit; // For updating output root directory
var previewControl = null; // For updating preview window
var previewInfoLabel = null; // For updating preview info text
var histogramControl = null; // For updating histogram window
var mainTabBox = null; // For switching to preview tab
var filtering_changed = false; // Filtering settings have changed
var is_some_preview = false;
var preview_size_changed = false;
var preview_keep_zoom = false;
var current_selected_file_name = null;
var current_selected_file_filter = null;
var monochrome_text = "Monochrome: ";
var blink_window = null;
var blink_zoom = false;
var blink_zoom_x = 0;
var blink_zoom_y = 0;
var filterSectionbars = [];
var filterSectionbarcontrols = [];
var extract_channel_mapping_values = [ "None", "LRGB", "HSO", "HOS" ];
var RGBNB_mapping_values = [ 'H', 'S', 'O', '' ];
var use_weight_values = [ 'Generic', 'Noise', 'Stars', 'PSF Signal', 'PSF Signal scaled', 'FWHM scaled', 'Eccentricity scaled', 'SNR scaled', 'Star count' ];
var filter_limit_values = [ 'None', 'FWHM', 'Eccentricity', 'PSFSignal', 'PSFPower', 'SNR', 'Stars'];
var filter_sort_values = [ 'SSWEIGHT', 'FWHM', 'Eccentricity', 'PSFSignal', 'PSFPower', 'SNR', 'Stars', 'File name' ];
var outliers_methods = [ 'Two sigma', 'One sigma', 'IQR' ];
var use_linear_fit_values = [ 'Auto', 'Min RGB', 'Max RGB', 'Min LRGB', 'Max LRGB', 'Red', 'Green', 'Blue', 'Luminance', 'No linear fit' ];
var use_clipping_values = [ 'Auto1', 'Auto2', 'Percentile', 'Sigma', 'Averaged sigma', 'Winsorised sigma', 'Linear fit', 'ESD', 'None' ];
var narrowband_linear_fit_values = [ 'Auto', 'Min', 'Max', 'H', 'S', 'O', 'None' ];
var imageintegration_normalization_values = [ 'Additive', 'Adaptive', 'None' ];
var imageintegration_combination_values = [ 'Average', 'Median', 'Minimum', 'Maximum' ];
var noise_reduction_strength_values = [ '0', '1', '2', '3', '4', '5', '6'];
var column_count_values = [ 'Auto', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20' ];
var binning_values = [ 'None', 'Color', 'L and color'];
var spcc_white_reference_values = [ 'Average Spiral Galaxy', 'Photon Flux' ];
var target_binning_values = [ 'Auto', 'None', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ];
var target_drizzle_values = [ 'Auto', 'None', '2', '4' ];
var target_type_values = [ 'Default', 'Galaxy', 'Nebula', 'Star cluster' ];
var graxpert_batch_size_values = [ '1', '2', '4', '8', '16', '32' ];
var RGBHa_preset_values = [ 'Combine Continuum Subtract', 'SPCC Continuum Subtract' ];
var RGBHa_prepare_method_values = [ 'Continuum Subtract', 'Basic' ];
var RGBHa_combine_time_values = [ 'Stretched', 'SPCC linear' ];
var RGBHa_combine_method_values = [ 'Bright structure add', 'Screen', 'Med subtract add', 'Max', 'Add', 'None' ];
var color_calibration_time_values = [ 'auto', 'linear', 'nonlinear', 'both' ];
var RGBHa_test_values = [ 'Mapping', 'Continuum', 'All mappings' ];
var fast_mode_values = [ 'S', 'M' ];
var drizzle_function_values = [ 'Square', 'Circular', 'Gaussian' ];
var screen_size = "Unknown"; // Screen wxh size as a string
var screen_width = 0; // Screen width in pixels
var screen_height = 0; // Screen height in pixels
var metricsVisualizerToolTip = "<p>Show SubframeSelector metrics visualizer dialog.</p>" +
"<p>Before using metrics visualizer, ensure that you have loaded light files.</p>" +
"<p>Filtering settings in the <i>Preprocessing / Weighting and filtering settings</i> section " +
"are used for visualization.</p>" +
"<p>If no filtering rules are set then default settings are used.</p>";
var exclusion_area_image_window_list = null;
function update_enhancements_target_image_window_list(current_item)
{
exclusion_area_image_window_list = enhancements_gui.update_enhancements_target_image_window_list(current_item);
// Exclusion area image list is kept in sync with extra_target_image_window_list
guitools.exclusionAreasComboBox.clear();
for (var i = 0; i < exclusion_area_image_window_list.length; i++) {
guitools.exclusionAreasComboBox.addItem( exclusion_area_image_window_list[i] );
}
}
function close_undo_images()
{
enhancements_gui.close_undo_images();
}
function forceNewHistogram(target_win)
{
try {
if (!target_win.mainView.deleteProperty("Histogram16")) {
// console.writeln("Failed to delete property Histogram16");
}
} catch(err) {
// console.writeln("Failed to delete property Histogram16 : " + err);
}
}
function flowchartUpdated()
{
if (par.show_flowchart.val && !global.get_flowchart_data) {
if (global.debug) console.writeln("flowchartUpdated");
try {
var obj = flowchart.flowchartGraph(global.flowchartData, guitools.current_preview.image, guitools.current_preview.txt);
if (obj) {
updatePreviewImage(previewControl, obj.image, obj.text, histogramControl, global.enhancements_target_histogram_info, true);
}
} catch (ex) {
console.writeln("flowchartUpdated: " + ex);
}
}
}
function copyFileNames(fileNames)
{
if (fileNames == null) {
return null;
}
var copy = [];
for (var i = 0; i < fileNames.length; i++) {
copy[i] = fileNames[i];
}
return copy;
}
function generateNewFlowchartData(parent)
{
var savedOutputRootDir = global.outputRootDir;
util.beginLog();
console.writeln("generateNewFlowchartData");
console.flush();
getFilesFromTreebox(parent.dialog);
if (global.lightFileNames == null) {
console.criticalln("No files, cannot generate flowchart data");
util.endLog();
return false;
}
var succp = true;
guitools.current_preview.image = null;
guitools.current_preview.image_versions = [];
flowchart.flowchartReset();
console.writeln("generateNewFlowchartData: copy file names");
var lightFileNamesCopy = copyFileNames(global.lightFileNames);
var darkFileNamesCopy = copyFileNames(global.darkFileNames);
var biasFileNamesCopy = copyFileNames(global.biasFileNames);
var flatdarkFileNamesCopy = copyFileNames(global.flatdarkFileNames);
var flatFileNamesCopy = copyFileNames(global.flatFileNames);
// Use prefix when running flowchart to avoid name conflicts
var saved_win_prefix = ppar.win_prefix;
ppar.win_prefix = "AutoIntegrateFlowchart_";
// global.all_windows is a special case if we run the script multiple times
var old_all_windows = global.all_windows;
global.all_windows = [];
util.fixAllWindowArrays(ppar.win_prefix);
util.closeAllWindows(false, false);
global.get_flowchart_data = true;
try {
engine.autointegrateProcessingEngine(parent.dialog, false, false, "Generate flowchart data");
} catch (x) {
util.addCriticalStatus("generateNewFlowchartData failed calling autointegrateProcessingEngine:" + x);
global.flowchartData = null;
global.is_processing = global.processing_state.none;
succp = false;
}
global.get_flowchart_data = false;
// Close all windows with flowchart prefix
util.fixAllWindowArrays(ppar.win_prefix);
util.closeAllWindows(false, false);
// restore original prefix
ppar.win_prefix = saved_win_prefix;
util.fixAllWindowArrays(ppar.win_prefix);
util.closeAllWindowsFromArray(global.flowchartWindows);
global.flowchartWindows = [];
console.writeln("generateNewFlowchartData: restore original file names");
global.lightFileNames = lightFileNamesCopy;
global.darkFileNames = darkFileNamesCopy;
global.biasFileNames = biasFileNamesCopy;
global.flatdarkFileNames = flatdarkFileNamesCopy;
global.flatFileNames = flatFileNamesCopy;
global.all_windows = old_all_windows;
util.runGarbageCollection();
console.flush();
console.writeln("generateNewFlowchartData done");
console.flush();
engine.writeProcessingStepsAndEndLog(null, false, "AutoFlowchart", false);
console.writeln("AutoFlowchart log written");
console.flush();
global.outputRootDir = savedOutputRootDir;
return succp;
}
function isbatchNarrowbandPaletteMode()
{
return (par.custom_R_mapping.val == "All" && par.custom_G_mapping.val == "All" && par.custom_B_mapping.val == "All") ||
par.use_narrowband_multiple_mappings.val;
}
function previewControlCleanup(control)
{
control.zoomIn_Button.onClick = null;
control.zoomOut_Button.onClick = null;
control.zoom11_Button.onClick = null;
control.zoomFit_Button.onClick = null;
control.scrollbox.onHorizontalScrollPosUpdated = null;
control.scrollbox.onVerticalScrollPosUpdated = null;
control.forceRedraw = null;
control.scrollbox.viewport.onMouseWheel = null;
control.scrollbox.viewport.onClick = null;
control.scrollbox.viewport.onMouseMove = null;
control.scrollbox.viewport.onMouseRelease = null;
control.scrollbox.viewport.onResize = null;
control.scrollbox.viewport.onPaint = null;
control.image = null;
control.imgWin = null;
}
function previewCleanup(previewObj)
{
previewControlCleanup(previewObj.control);
previewObj.control = null;
previewObj.infolabel = null;
previewObj.statuslabel = null;
}
function variableCleanup()
{
infoLabel = null;
imageInfoLabel = null;
windowPrefixHelpTips = null;
closeAllPrefixButton = null;
windowPrefixComboBox = null;
outputDirEdit = null;
previewControl = null;
previewInfoLabel = null;
mainTabBox = null;
}
function exitCleanup(dialog)
{
// console.writeln("exitCleanup");
if (blink_window != null) {
blink_window.forceClose();
blink_window = null;
}
close_undo_images(true);
if (global.use_preview) {
if (dialog.previewObj != null) {
previewCleanup(dialog.previewObj);
dialog.previewObj = null;
}
}
if (guitools.current_preview.imgWin != null) {
guitools.current_preview.imgWin.forceClose();
guitools.current_preview.imgWin = null;
}
variableCleanup();
util.checkEvents();
}
// Create a table of known prefix names for toolTip
// Also update window prefix combo box list
function setWindowPrefixHelpTip(default_prefix)
{
var prefix_list = "<table><tr><th>Col</th><th>Name</th><th>Icon count</th></tr>";
if (ppar.prefixArray.length == 0) {
prefix_list = prefix_list + "<tr><td></td><td><i>No prefixes</i></td><td></td></tr>";
} else {
for (var i = 0; i < ppar.prefixArray.length; i++) {
if (ppar.prefixArray[i] != null && ppar.prefixArray[i][1] != '-') {
prefix_list = prefix_list + "<tr><td>" + (ppar.prefixArray[i][0] + 1) + '</td><td>' + ppar.prefixArray[i][1] + '</td><td>' + ppar.prefixArray[i][2] + '</td></tr>';
}
}
}
prefix_list = prefix_list + "</table>";
windowPrefixHelpTips.toolTip = "<p>Current Window Prefixes:</p><p> " + prefix_list + "</p>";
closeAllPrefixButton.toolTip = "<p>Close all windows that are created by this script using <b>all known prefixes</b> (which can be empty prefix).</p>" +
"<p>Prefixes used to close windows are default empty prefix, prefix in the Window Prefix box and all saved window prefixes. " +
"All saved prefix information is cleared after this operation.</p>" +
"<p>To close windows with current prefix use Close all button.</p>" +
windowPrefixHelpTips.toolTip;
windowPrefixComboBox.clear();
autoContinueWindowPrefixComboBox.clear();
var pa = get_win_prefix_combobox_array(default_prefix);
guitools.addArrayToComboBox(windowPrefixComboBox, pa);
guitools.addArrayToComboBox(autoContinueWindowPrefixComboBox, pa);
windowPrefixComboBox.editText = validateWindowPrefix(ppar.win_prefix);
windowPrefixComboBox.currentItem = pa.indexOf(validateWindowPrefix(ppar.win_prefix));
}
function fix_win_prefix_array()
{
var new_prefix_array = [];
for (var i = 0; i < ppar.prefixArray.length; i++) {
if (ppar.prefixArray[i] == null) {
continue;
} else if (!Array.isArray(ppar.prefixArray[i])) {
// bug fix, mark as free
continue;
} else if (ppar.prefixArray[i][1] != '-') {
new_prefix_array[new_prefix_array.length] = ppar.prefixArray[i];
}
}
ppar.prefixArray = new_prefix_array;
}
function get_win_prefix_combobox_array(default_prefix)
{
default_prefix = validateWindowPrefix(default_prefix);
var name_array = [default_prefix];
for (var i = 0; i < ppar.prefixArray.length; i++) {
if (ppar.prefixArray[i] != null && ppar.prefixArray[i][1] != '-') {
var add_name = validateWindowPrefix(ppar.prefixArray[i][1]);
if (add_name != default_prefix) {
name_array[name_array.length] = add_name;
}
}
}
return name_array;
}
// Find a prefix from the prefix array. Returns -1 if not
// found.
function findPrefixIndex(prefix)
{
for (var i = 0; i < ppar.prefixArray.length; i++) {
if (ppar.prefixArray[i][1] == prefix) {
return i;
}
}
return -1;
}
// Find a new free column position for a prefix. Prefix name '-'
// is used to mark a free position.
function findNewPrefixIndex(find_free_column)
{
if (find_free_column) {
/* First mark all reserved column positions. */
var reserved_columns = [];
for (var i = 0; i < ppar.prefixArray.length; i++) {
if (ppar.prefixArray[i][1] != '-') {
reserved_columns[ppar.prefixArray[i][0]] = true;
}
}
/* Then find the first unused column position. */
for (var i = 0; i < reserved_columns.length; i++) {
if (reserved_columns[i] != true) {
break;
}
}
var index = ppar.prefixArray.length;
ppar.prefixArray[index] = [i, '-', 0];
return index;
} else {
// Just return a new slot at the end of the array
var index = ppar.prefixArray.length;
ppar.prefixArray[index] = [0, '-', 0];
return index;
}
}
// Save persistent settings
function savePersistentSettings(from_exit)
{
if (global.do_not_write_settings) {
console.noteln("Do not save interface settings to persistent module settings.");
} else {
console.noteln("Save persistent settings");
Settings.write (SETTINGSKEY + "/prefixName", DataType_String, ppar.win_prefix);
Settings.write (SETTINGSKEY + "/prefixArray", DataType_String, JSON.stringify(ppar.prefixArray));
if (par.use_manual_icon_column.val) {
Settings.write (SETTINGSKEY + "/global.columnCount", DataType_Int32, ppar.userColumnCount);
}
Settings.write (SETTINGSKEY + "/previewSettings", DataType_String, JSON.stringify(ppar.preview));
Settings.write (SETTINGSKEY + "/useSingleColumn", DataType_Boolean, ppar.use_single_column);
Settings.write (SETTINGSKEY + "/useMoreTabs", DataType_Boolean, ppar.use_more_tabs);
Settings.write (SETTINGSKEY + "/filesInTab", DataType_Boolean, ppar.files_in_tab);
Settings.write (SETTINGSKEY + "/showStartupImage", DataType_Boolean, ppar.show_startup_image);
Settings.write (SETTINGSKEY + "/startupImageName", DataType_String, ppar.startup_image_name);
Settings.write (SETTINGSKEY + "/savedVersion", DataType_String, global.autointegrate_version);
Settings.write (SETTINGSKEY + "/savedInterfaceVersion", DataType_Int32, global.interface_version);
}
if (!from_exit) {
setWindowPrefixHelpTip(ppar.win_prefix);
}
}
/***************************************************************************
*
* Dialog functions are below this point
*
*/
function Autorun(parent)
{
console.writeln("AutoRun");
var stopped = true;
var success = true;
var first_step = true;
var savedOutputRootDir = global.outputRootDir;
var batch_narrowband_palette_mode = isbatchNarrowbandPaletteMode();
var batch_files = [];
var substack_mode = par.substack_mode.val;
var substack_files = [];
var substack_size = global.lightFileNames ? global.lightFileNames.length / par.substack_count.val : 0;
var substack_saved_lightFileNames = global.lightFileNames;
var saved_integrate_only = par.integrate_only.val;
if (substack_mode && global.lightFileNames) {
console.writeln("AutoRun substack size " + substack_size);
for (var i = 0; i < global.lightFileNames.length; i += substack_size) {
substack_files[substack_files.length] = global.lightFileNames.slice(i, i + substack_size);
}
par.integrate_only.val = true;
}
global.substack_number = 0;
if (par.batch_mode.val) {
stopped = false;
// Ask files before processing
console.writeln("AutoRun in batch mode");
for (var i = 0; ; i++) {
console.writeln("File names for batch " + (i + 1));
console.noteln("Click Cancel when all files are selected.");
var caption = "Select files for batch " + (i + 1) + ", Cancel ends the batch files";
if (par.open_directory.val) {
var lights = engine.openDirectoryFiles(caption, par.directory_files.val, true, true, global.pages.LIGHTS);
} else {
var lights = engine.openImageFiles(caption, true, false, true);
}
if (lights == null || lights.length == 0) {
break;
}
batch_files[batch_files.length] = lights;
}
if (batch_files.length == 0) {
console.writeln("No files selected for a batch. Stopped.");
return false;
}
var txt = "Batch processing " + batch_files.length + " panels. Do you want to proceed?";
var response = new MessageBox(txt, "AutoIntegrate", StdIcon_Question, StdButton_Yes, StdButton_No ).execute();
if (response != StdButton_Yes) {
console.writeln("Batch processing not started.");
return false;
}
global.lightFileNames = null; // Use files given here
} else {
console.writeln("AutoRun in normal mode");
}
do {
if (global.lightFileNames == null && !par.generate_masters_only.val) {
if (par.batch_mode.val) {
global.lightFileNames = batch_files.shift();
} else if (par.open_directory.val) {
global.lightFileNames = engine.openDirectoryFiles("Lights", par.directory_files.val, true, false, global.pages.LIGHTS);
} else {
global.lightFileNames = engine.openImageFiles("Lights", true, false, false);
}
if (global.lightFileNames != null) {
parent.dialog.treeBox[global.pages.LIGHTS].clear();
addFilesToTreeBox(parent.dialog, global.pages.LIGHTS, global.lightFileNames);
updateInfoLabel(parent.dialog);
updateExclusionAreaLabel(parent);
}
}
if (substack_mode) {
console.writeln("Get next substack");
if (substack_files.length == 0) {
console.writeln("AutoRun substack completed");
break;
}
global.lightFileNames = substack_files.shift();
console.writeln("AutoRun substack length " + global.lightFileNames.length + " files.");
if (global.lightFileNames == null || global.lightFileNames.length == 0) {
console.writeln("AutoRun substack completed");
break;
} else {
stopped = false;
}
}
if (global.lightFileNames != null || par.generate_masters_only.val) {
if (batch_narrowband_palette_mode && global.lightFileNames != null) {
var filteredFiles = engine.getFilterFiles(global.lightFileNames, global.pages.LIGHTS, '');
if (!filteredFiles.narrowband) {
batch_narrowband_palette_mode = false;
}
}
if (first_step) {
if (substack_mode) {
global.substack_number = 1;
console.writeln("AutoRun in substack mode, substack " + global.substack_number);
} else if (par.batch_mode.val) {
console.writeln("AutoRun in batch mode");
} else if (batch_narrowband_palette_mode) {
console.writeln("AutoRun in narrowband palette batch mode");
} else {
console.writeln("AutoRun");
}
first_step = false;
} else {
global.user_selected_reference_image = [];
if (substack_mode) {
global.substack_number++;
console.writeln("AutoRun in substack mode, substack " + global.substack_number);
}
}
flowchart.flowchartReset();
if (par.run_get_flowchart_data.val && global.use_preview) {
if (substack_mode) {
console.writeln("Do not get flowchart data for substack mode");
} else if (batch_narrowband_palette_mode || par.batch_mode.val) {
console.writeln("Do not get flowchart data for batch mode");
} else {
let succ = generateNewFlowchartData(parent);
}
} else {
console.writeln("Do not get flowchart data");
}
try {
if (batch_narrowband_palette_mode) {
engine.autointegrateNarrowbandPaletteBatch(parent.dialog, false);
} else {
engine.autointegrateProcessingEngine(parent.dialog, false, false, "AutoRun");
}
update_enhancements_target_image_window_list(null);
}
catch(err) {
console.criticalln(err);
console.criticalln("Processing stopped!");
engine.writeProcessingStepsAndEndLog(null, false, null, true);
global.is_processing = global.processing_state.none;
stopped = true;
success = false;
}
if (par.batch_mode.val) {
global.outputRootDir = savedOutputRootDir;
global.lightFileNames = null;
console.writeln("AutoRun in batch mode");
util.closeAllWindows(par.keep_integrated_images.val, true);
}
if (substack_mode) {
console.writeln("AutoRun in substack mode, close windows");
util.closeAllWindows(par.keep_integrated_images.val, true);
console.writeln("AutoRun in substack mode, continue to next substack.");
}
} else {
stopped = true;
}
if (global.cancel_processing) {
stopped = true;
console.writeln("Processing cancelled!");
success = false;
}
} while (!stopped);
global.outputRootDir = savedOutputRootDir;
par.integrate_only.val = saved_integrate_only;
global.lightFileNames = substack_saved_lightFileNames;
global.substack_number = 0;
return success;
}
function filesOptionsSizer(parent, name, toolTip)
{
var label = guitools.newSectionLabel(parent, name);
global.rootingArr.push(label);
label.toolTip = util.formatToolTip(toolTip);
var labelempty = new Label( parent );
labelempty.text = " ";
global.rootingArr.push(labelempty);
var sizer = new VerticalSizer;
sizer.margin = 6;
sizer.spacing = 4;
sizer.add( label );
sizer.add( labelempty );
return sizer;
}
function showOrHideFilterSectionBar(pageIndex)
{
switch (pageIndex) {
case global.pages.LIGHTS:
var show = par.lights_add_manually.val || par.skip_autodetect_filter.val;
break;
case global.pages.FLATS:
var show = par.flats_add_manually.val || par.skip_autodetect_filter.val;
break;
case global.pages.FLAT_DARKS:
var show = par.flatdarks_add_manually.val || par.skip_autodetect_filter.val;
break;
default:
util.throwFatalError("showOrHideFilterSectionBar bad pageIndex " + pageIndex);
}
if (show) {
filterSectionbars[pageIndex].show();
filterSectionbarcontrols[pageIndex].visible = true;
} else {
filterSectionbars[pageIndex].hide();
filterSectionbarcontrols[pageIndex].visible = false;
}
}
function lightsOptions(parent)
{
var sizer = filesOptionsSizer(parent, "Add light images", parent.filesToolTip[global.pages.LIGHTS]);
var debayerLabel = new Label( parent );
global.rootingArr.push(debayerLabel);
debayerLabel.text = "Debayer";
debayerLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
debayerLabel.toolTip = "<p>Select bayer pattern for debayering color/OSC/RAW/DSLR files.</p>" +
"<p>Auto option tries to recognize debayer pattern from image metadata.</p>" +
"<p>If images are already debayered choose none which does not do debayering.</p>";
var debayerCombobox = guitools.newComboBox(parent, par.debayer_pattern, global.debayerPattern_values, debayerLabel.toolTip);
global.rootingArr.push(debayerCombobox);
var extractChannelsLabel = new Label( parent );
global.rootingArr.push(extractChannelsLabel);
extractChannelsLabel.text = "Extract channels";
extractChannelsLabel.textAlignment = TextAlign_Left|TextAlign_VertCenter;
extractChannelsLabel.toolTip =
"<p>Extract channels from color/OSC/RAW/DSLR files.</p>" +
"<p>Channel extraction is done right after debayering. After channels are extracted " +
"processing continues as mono processing with separate filter files.</p>" +
"<p>Option LRGB extract lightness channels as L and color channels as separate R, G and B files.</p>" +
"<p>Option HOS extract channels as RGB=HOS and option HSO extract channels RGB=HSO. " +
"Resulting channels can then be mixed as needed using PixMath expressions in <i>Settings / Narrowband processing</i> " +
"section.</p>" +
"<p>Channel files have a channel name (_L, _R, etc.) at the end of the file name. Script " +
"can then automatically recognize files as filter files.</p>"
;
var extractChannelsCombobox = guitools.newComboBox(parent, par.extract_channel_mapping, extract_channel_mapping_values, extractChannelsLabel.toolTip);
global.rootingArr.push(extractChannelsCombobox);
var add_manually_checkbox = guitools.newCheckBox(parent, "Add manually", par.lights_add_manually,
"<p>Add light files manually by selecting files for each filter.</p>" );
global.rootingArr.push(add_manually_checkbox);
add_manually_checkbox.onClick = function(checked) {
add_manually_checkbox.aiParam.val = checked;
showOrHideFilterSectionBar(global.pages.LIGHTS);
}
var interated_lights_checkbox = guitools.newCheckBox(parent, "Integrated lights", par.integrated_lights,
"<p>If checked consider light files to be integrated files for AutoContinue.</p>" +
"<p>It is useful for example when using integrated lights from WBPP as there is no need to rename images.</p>");
global.rootingArr.push(interated_lights_checkbox);
var monochrome_image_CheckBox = guitools.newCheckBoxEx(parent, "Force monochrome", par.monochrome_image,
"<p>Force creation of a monochrome image. All images are treated as Luminance files and stacked together. " +
"Quite a few processing steps are skipped with this option.</p>",
function(checked) {
monochrome_image_CheckBox.aiParam.val = checked;
updateSectionsInTreeBox(parent.treeBox[global.pages.LIGHTS]);
});
global.rootingArr.push(monochrome_image_CheckBox);
var sortAndFilterButton = new PushButton( parent );
sortAndFilterButton.text = "Sort and filter";
sortAndFilterButton.icon = parent.scaledResource(":/icons/filter.png");
sortAndFilterButton.toolTip = "<p>Filter and sort files based on current weighting and filtering settings in the " +
"<i>Preprocessing / Weighting and filtering settings</i> section.</p>" +
"<p>Without any filtering rules files are just sorted by the sort order " +
"given in the <i>Preprocessing / Weighting and filtering settings</i> section.</p>" +
"<p>Using the mouse hover over the file name you can see the " +
"filtering and weighting information for the file.</p>";
sortAndFilterButton.onClick = function()
{
try {
util.addStatusInfo("Sorting and filtering files");
filterTreeBoxFiles(parent.dialog, parent.dialog.tabBox.currentPageIndex);
} catch (e) {
console.criticalln("Sorting and filtering files: " + e);
}
};
global.rootingArr.push(sortAndFilterButton);
var metricsVisualizerButton = new PushButton( parent );
metricsVisualizerButton.text = "Metrics visualizer";
metricsVisualizerButton.icon = parent.scaledResource(":/icons/chart.png");
metricsVisualizerButton.toolTip = metricsVisualizerToolTip;
metricsVisualizerButton.onClick = function()
{
try {
metricsVisualizerFilters(parent);
} catch (e) {
console.criticalln("Metrics visualizer: " + e);
}
};
global.rootingArr.push(metricsVisualizerButton);
var exclusionAreasButton = new PushButton( parent );
exclusionAreasButton.text = "Exclusion areas";
exclusionAreasButton.toolTip = "<p>Select exclusion areas for DBE.</p>";
exclusionAreasButton.onClick = function()
{
try {
guitools.getExclusionAreas();
} catch (e) {
console.criticalln("Exclusion areas: " + e);
}
};
global.rootingArr.push(exclusionAreasButton);
sizer.add(debayerLabel);
sizer.add(debayerCombobox);
sizer.add(extractChannelsLabel);
sizer.add(extractChannelsCombobox);
sizer.add(monochrome_image_CheckBox);
sizer.add(add_manually_checkbox);
sizer.add(interated_lights_checkbox);
sizer.addStretch();
sizer.add(sortAndFilterButton);
sizer.add(metricsVisualizerButton);
sizer.add(exclusionAreasButton);
return sizer;
}
function biasOptions(parent)
{
var sizer = filesOptionsSizer(parent, "Add bias images", parent.filesToolTip[global.pages.BIAS]);
var checkbox = guitools.newCheckBox(parent, "SuperBias", par.create_superbias,
"<p>Create SuperBias from bias files.</p>" +
"<p>For modern CMOS sensors you should not use superbias.</p>" +
"<p>For CCD sensors you can use superbias.</p>");
var checkbox2 = guitools.newCheckBox(parent, "Master files", par.bias_master_files,
"<p>Files are master files.</p>" +
"<p>When there are multiple master files, they are matched by resolution.</p>" );
parent.biasMasterFilesCheckBox = checkbox2;
var checkbox3 = guitools.newCheckBox(parent, "Use on lights", par.bias_use_on_lights,
"<p>Use bias files on light frames.</p>" +
"<p>If there are master dark files, bias files are ignored on light frames unless explicitly enabled.</p>");
var checkbox4 = guitools.newCheckBox(parent, "Use on darks", par.bias_use_on_darks,
"<p>Use bias files on dark frames.</p>" +
"<p>For modern CMOS sensors you should not use bias files on dark frames.</p>" +
"<p>For CCD sensors you can use bias files on dark frames.</p>");
sizer.add(checkbox);
sizer.add(checkbox2);
sizer.add(checkbox3);
sizer.add(checkbox4);
sizer.addStretch();
return sizer;
}
function darksOptions(parent)
{
var sizer = filesOptionsSizer(parent, "Add dark images", parent.filesToolTip[global.pages.DARKS]);
var checkbox = guitools.newCheckBox(parent, "Pre-calibrate", par.pre_calibrate_darks,
"<p>If checked darks are pre-calibrated with bias and not during ImageCalibration.</p>" );
var checkbox2 = guitools.newCheckBox(parent, "Optimize", par.optimize_darks,
"<p>If checked darks are optimized when calibrating lights.</p>" +
"<p>For modern CMOS cameras optimization should not be used.</p>" +
"<p>For CCD cameras it can be used.</p>");
var checkbox3 = guitools.newCheckBox(parent, "Master files", par.dark_master_files,
"<p>Files are master files.</p>" +
"<p>When there are multiple master files in a group, they are matched by resolution.</p>" );
parent.darkMasterFilesCheckBox = checkbox3;
sizer.add(checkbox);
sizer.add(checkbox2);
sizer.add(checkbox3);
sizer.addStretch();
return sizer;
}
function flatsOptions(parent)
{
var sizer = filesOptionsSizer(parent, "Add flat images", parent.filesToolTip[global.pages.FLATS]);
var checkboxMaster = guitools.newCheckBox(parent, "Master files", par.flat_master_files,
"<p>Files are master files.</p>" +
"<p>When there are multiple master files in a group, they are matched by resolution.</p>" );
parent.flatMasterFilesCheckBox = checkboxMaster;
global.rootingArr.push(checkboxMaster);
var checkboxStars = guitools.newCheckBox(parent, "Stars in flats", par.stars_in_flats,
"<p>If you have stars in your flats then checking this option will lower percentile " +
"clip values and should help remove the stars.</p>" );
global.rootingArr.push(checkboxStars);
var checkboxDarks = guitools.newCheckBox(parent, "Use darks", par.use_darks_on_flat_calibrate,
"<p>If selected then darks are used for flat calibration.</p>");
global.rootingArr.push(checkboxDarks);
var checkboxManual = guitools.newCheckBox(parent, "Add manually", par.flats_add_manually,
"<p>Add flat files manually by selecting files for each filter.</p>" );
global.rootingArr.push(checkboxManual);
checkboxManual.onClick = function(checked) {
checkboxManual.aiParam.val = checked;
showOrHideFilterSectionBar(global.pages.FLATS);
}
sizer.add(checkboxMaster);
sizer.add(checkboxStars);
sizer.add(checkboxDarks);
sizer.add(checkboxManual);
sizer.addStretch();
return sizer;
}
function flatdarksOptions(parent)
{
var sizer = filesOptionsSizer(parent, "Add flat dark images", parent.filesToolTip[global.pages.FLAT_DARKS]);
var checkbox = guitools.newCheckBox(parent, "Master files", par.flat_dark_master_files,
"<p>Files are master files.</p>" +
"<p>When there are multiple master files in a group, they are matched by resolution.</p>" );
parent.flatDarkMasterFilesCheckBox = checkbox;