1 /*
2  * This file is part of Siril, an astronomy image processor.
3  * Copyright (C) 2005-2011 Francois Meyer (dulle at free.fr)
4  * Copyright (C) 2012-2020 team free-astro (see more in AUTHORS file)
5  * Reference site is https://free-astro.org/index.php/Siril
6  *
7  * Siril is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Siril is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Siril. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <gtk/gtk.h>
22 #include "core/siril_actions.h"
23 
24 static GActionEntry win_entries[] = {
25 		{ "close", close_action_activate },
26 		{ "undo", undo_action_activate },
27 		{ "redo", redo_action_activate },
28 		{ "scripts", scripts_action_activate },
29 		{ "updates", updates_action_activate },
30 		{ "full-screen", full_screen_activated},
31 		{ "hide-show-toolbar", toolbar_activate },
32 		{ "shortcuts", keyboard_shortcuts_activated},
33 		{ "cwd", cwd_action_activate },
34 
35 		{ "conversion", tab_conversion_activate },
36 		{ "sequence", tab_sequence_activate },
37 		{ "registration", tab_registration_activate },
38 		{ "prepro", tab_prepro_activate },
39 		{ "plot", tab_plot_activate },
40 		{ "stacking", tab_stacking_activate },
41 		{ "logs", tab_logs_activate }
42 };
43 
44 static GActionEntry image_entries[] = {
45 		{ "bit-depth", NULL },
46 		{ "zoom-out", zoom_out_activate },
47 		{ "zoom-in", zoom_in_activate },
48 		{ "zoom-fit", zoom_fit_activate, NULL, "true", change_zoom_fit_state },
49 		{ "zoom-one", zoom_one_activate },
50 		{ "negative-view", negative_view_activate, NULL, "false", negative_view_state },
51 		{ "color-map", color_map_activate, NULL, "false", color_map_state },
52 		{ "snapshot", snapshot_action_activate },
53 		{ "fits-header", image_fits_header_activate },
54 		{ "statistics", statistics_activate },
55 		{ "evaluate-noise", noise_activate },
56 		{ "astrometry", astrometry_activate },
57 		{ "image-information", image_information_activate },
58 		{ "dyn-psf", dyn_psf_activate },
59 		{ "annotate-object", annotate_object_activate, NULL, "false", annotate_object_state },
60 		{ "search-object", search_object_activate },
61 		{ "seq-list", seq_list_activate },
62 		{ "pickstar", pick_star_activate }
63 };
64 
65 static GActionEntry rgb_processing_entries[] = {
66 		{"remove-green-processing", remove_green_activate },
67 		{"saturation-processing", saturation_activate },
68 		{"color-calib-processing", color_calib_activate },
69 		{"pcc-processing", pcc_activate },
70 		{"split-channel-processing", split_channel_activate }
71 };
72 
73 static GActionEntry any_processing_entries[] = {
74 		{"negative-processing", negative_activate },
75 		{"histo-processing", histo_activate },
76 		{"fix-banding-processing", fix_banding_activate },
77 		{"cosmetic-processing", cosmetic_activate },
78 		{"background-extr-processing", background_extr_activate }
79 };
80 
81 static GActionEntry any_mono_processing_entries[] = {
82 		{"split-cfa-processing", split_cfa_activate }
83 };
84 
85 static GActionEntry single_processing_entries[] = {
86 		{"asinh-processing", asinh_activate },
87 		{"deconvolution-processing", deconvolution_activate },
88 		{"resample-processing", resample_activate },
89 		{"rotation-processing", rotation_activate },
90 		{"rotation90-processing", rotation90_activate },
91 		{"rotation270-processing", rotation270_activate },
92 		{"mirrorx-processing", mirrorx_activate },
93 		{"mirrory-processing", mirrory_activate },
94 		{"wavelets-processing", wavelets_activate },
95 		{"split-wavelets-processing", split_wavelets_activate },
96 		{"medianfilter-processing", medianfilter_activate },
97 		{"rgradient-processing", rgradient_activate },
98 		{"clahe-processing", clahe_activate },
99 		{"linearmatch-processing", linearmatch_activate }
100 };
101 
102 static GActionEntry none_processing_entries[] = {
103 		{"fft-processing", fft_activate },
104 		{"rgb-compositing-processing", rgb_compositing_activate }
105 };
106 
_siril_window_enable_action_group(GActionMap * map,const gchar ** group,gboolean enable)107 static void _siril_window_enable_action_group(GActionMap *map,
108 		const gchar **group, gboolean enable) {
109 	GAction *action;
110 
111 	for (const gchar **it = group; *it != NULL; it++) {
112 		action = g_action_map_lookup_action(map, *it);
113 		if (G_LIKELY(action))
114 			g_simple_action_set_enabled(G_SIMPLE_ACTION(action), enable);
115 		else
116 			g_warning("Action not found in action group: %s", *it);
117 	}
118 }
119 
siril_window_enable_image_actions(GtkApplicationWindow * window,gboolean enable)120 void siril_window_enable_image_actions(GtkApplicationWindow *window, gboolean enable) {
121 	static const gchar *image_actions[] = {
122 		"bit-depth",
123 		"zoom-out",
124 		"zoom-in",
125 		"zoom-fit",
126 		"zoom-one",
127 		"negative-view",
128 		"color-map",
129 		"snapshot",
130 		"statistics",
131 		"evaluate-noise",
132 		"astrometry",
133 		"image-information",
134 	    "dyn-psf",
135         "search-object",
136 		"seq-list",
137 		NULL,
138 	};
139 	_siril_window_enable_action_group(G_ACTION_MAP(window), image_actions, enable);
140 }
141 
siril_window_enable_rgb_proc_actions(GtkApplicationWindow * window,gboolean enable)142 void siril_window_enable_rgb_proc_actions(GtkApplicationWindow *window, gboolean enable) {
143 	static const gchar *rgb_processing_actions[] = {
144 		"remove-green-processing",
145 		"saturation-processing",
146 		"color-calib-processing",
147 		"pcc-processing",
148 		"split-channel-processing",
149 		NULL,
150 	};
151 	_siril_window_enable_action_group(G_ACTION_MAP(window), rgb_processing_actions, enable);
152 }
153 
siril_window_enable_any_proc_actions(GtkApplicationWindow * window,gboolean enable)154 void siril_window_enable_any_proc_actions(GtkApplicationWindow *window, gboolean enable) {
155 	static const gchar *any_processing_actions[] = {
156 		"negative-processing",
157 		"histo-processing",
158 		"fix-banding-processing",
159 		"cosmetic-processing",
160 		"background-extr-processing",
161 		NULL,
162 	};
163 	_siril_window_enable_action_group(G_ACTION_MAP(window), any_processing_actions, enable);
164 }
165 
siril_window_enable_any_mono_proc_actions(GtkApplicationWindow * window,gboolean enable)166 void siril_window_enable_any_mono_proc_actions(GtkApplicationWindow *window, gboolean enable) {
167 	static const gchar *any_mono_processing_actions[] = {
168 		"split-cfa-processing",
169 		NULL,
170 	};
171 	_siril_window_enable_action_group(G_ACTION_MAP(window), any_mono_processing_actions, enable);
172 }
173 
siril_window_enable_single_proc_actions(GtkApplicationWindow * window,gboolean enable)174 void siril_window_enable_single_proc_actions(GtkApplicationWindow *window, gboolean enable) {
175 	static const gchar *single_processing_actions[] = {
176 		"asinh-processing",
177 		"deconvolution-processing",
178 		"resample-processing",
179 		"rotation-processing",
180 		"rotation90-processing",
181 		"rotation270-processing",
182 		"mirrorx-processing",
183 		"mirrory-processing",
184 		"wavelets-processing",
185 		"split-wavelets-processing",
186 		"medianfilter-processing",
187 		"rgradient-processing",
188 		"clahe-processing",
189 		"linearmatch-processing",
190 		NULL,
191 	};
192 	_siril_window_enable_action_group(G_ACTION_MAP(window), single_processing_actions, enable);
193 }
194 
siril_window_enable_none_proc_actions(GtkApplicationWindow * window,gboolean enable)195 void siril_window_enable_none_proc_actions(GtkApplicationWindow *window, gboolean enable) {
196 	static const gchar *none_processing_actions[] = {
197 		"fft-processing",
198 		"rgb-compositing-processing",
199 		NULL,
200 	};
201 	_siril_window_enable_action_group(G_ACTION_MAP(window), none_processing_actions, enable);
202 }
203 
siril_window_map_actions(GtkApplicationWindow * window)204 void siril_window_map_actions(GtkApplicationWindow *window) {
205 	g_action_map_add_action_entries(G_ACTION_MAP(window), win_entries, G_N_ELEMENTS(win_entries), window);
206 	g_action_map_add_action_entries(G_ACTION_MAP(window), image_entries, G_N_ELEMENTS(image_entries), window);
207 	g_action_map_add_action_entries(G_ACTION_MAP(window), rgb_processing_entries, G_N_ELEMENTS(rgb_processing_entries), window);
208 	g_action_map_add_action_entries(G_ACTION_MAP(window), any_processing_entries, G_N_ELEMENTS(any_processing_entries), window);
209 	g_action_map_add_action_entries(G_ACTION_MAP(window), any_mono_processing_entries, G_N_ELEMENTS(any_mono_processing_entries), window);
210 	g_action_map_add_action_entries(G_ACTION_MAP(window), single_processing_entries, G_N_ELEMENTS(single_processing_entries), window);
211 	g_action_map_add_action_entries(G_ACTION_MAP(window), none_processing_entries, G_N_ELEMENTS(none_processing_entries), window);
212 }
213