1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * dialog-analysis-tool-principal-components.c:
6 * Andreas J. Guelzow <aguelzow@taliesin.ca>
8 * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
25 #include <glib/gi18n-lib.h>
28 #include "analysis-principal-components.h"
29 #include "analysis-tools.h"
32 #include <workbook-control.h>
34 #include <workbook-view.h>
36 #include <parse-util.h>
37 #include <gnm-format.h>
38 #include <tool-dialogs.h>
39 #include <dao-gui-utils.h>
42 #include <number-match.h>
44 #include <selection.h>
49 #include <widgets/gnm-dao.h>
50 #include <widgets/gnumeric-expr-entry.h>
55 #define PRINCIPAL_COMPONENTS_KEY "analysistools-principal-components-dialog"
57 static char const * const grouped_by_group
[] = {
65 principal_components_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
66 GenericToolState
*state
)
70 /* Checking Input Range */
71 input_range
= gnm_expr_entry_parse_as_list (
72 GNM_EXPR_ENTRY (state
->input_entry
), state
->sheet
);
73 if (input_range
== NULL
) {
74 gtk_label_set_text (GTK_LABEL (state
->warning
),
75 _("The input range is invalid."));
76 gtk_widget_set_sensitive (state
->ok_button
, FALSE
);
79 range_list_destroy (input_range
);
81 /* Checking Output Page */
82 if (!gnm_dao_is_ready (GNM_DAO (state
->gdao
))) {
83 gtk_label_set_text (GTK_LABEL (state
->warning
),
84 _("The output specification "
86 gtk_widget_set_sensitive (state
->ok_button
, FALSE
);
90 gtk_label_set_text (GTK_LABEL (state
->warning
), "");
91 gtk_widget_set_sensitive (state
->ok_button
, TRUE
);
97 * principal_components_tool_ok_clicked_cb:
103 principal_components_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
104 GenericToolState
*state
)
106 data_analysis_output_t
*dao
;
107 analysis_tools_data_generic_t
*data
;
111 if (state
->warning_dialog
!= NULL
)
112 gtk_widget_destroy (state
->warning_dialog
);
114 data
= g_new0 (analysis_tools_data_generic_t
, 1);
115 dao
= parse_output (state
, NULL
);
117 data
->input
= gnm_expr_entry_parse_as_list (
118 GNM_EXPR_ENTRY (state
->input_entry
), state
->sheet
);
119 data
->group_by
= gnm_gui_group_value (state
->gui
, grouped_by_group
);
121 w
= go_gtk_builder_get_widget (state
->gui
, "labels_button");
122 data
->labels
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
));
124 if (cmd_analysis_tool (GNM_WBC (state
->wbcg
), state
->sheet
,
126 analysis_tool_principal_components_engine
,
129 text
= g_strdup_printf (
130 _("An unexpected error has occurred."));
131 error_in_entry ((GenericToolState
*) state
,
132 GTK_WIDGET (state
->input_entry
), text
);
135 gtk_widget_destroy (state
->dialog
);
142 * dialog_principal_components_tool:
146 * Show the dialog (guru).
150 dialog_principal_components_tool (WBCGtk
*wbcg
, Sheet
*sheet
)
152 GenericToolState
*state
;
153 char const * plugins
[] = { "Gnumeric_fnstat",
155 "Gnumeric_fnlogical",
158 if ((wbcg
== NULL
) ||
159 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
162 /* Only pop up one copy per workbook */
163 if (gnm_dialog_raise_if_exists (wbcg
, PRINCIPAL_COMPONENTS_KEY
))
166 state
= g_new0 (GenericToolState
, 1);
168 if (dialog_tool_init (state
, wbcg
, sheet
,
169 GNUMERIC_HELP_LINK_PRINCIPAL_COMPONENTS
,
170 "res:ui/principal-components.ui", "PrincipalComponents",
171 _("Could not create the Principal Components Analysis Tool dialog."),
172 PRINCIPAL_COMPONENTS_KEY
,
173 G_CALLBACK (principal_components_tool_ok_clicked_cb
), NULL
,
174 G_CALLBACK (principal_components_tool_update_sensitivity_cb
),
175 GNM_EE_SINGLE_RANGE
))
178 gnm_dao_set_put (GNM_DAO (state
->gdao
), TRUE
, TRUE
);
179 principal_components_tool_update_sensitivity_cb (NULL
, state
);
180 tool_load_selection ((GenericToolState
*)state
, TRUE
);