1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2010, 2011, 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-dialog-action-logistic.h"
21 #include "psppire-value-entry.h"
23 #include "dialog-common.h"
25 #include <ui/syntax-gen.h>
26 #include "psppire-var-view.h"
28 #include "psppire-dialog.h"
29 #include "builder-wrapper.h"
30 #include "psppire-dict.h"
31 #include "libpspp/str.h"
34 #define _(msgid) gettext (msgid)
35 #define N_(msgid) msgid
39 psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class);
41 G_DEFINE_TYPE (PsppireDialogActionLogistic, psppire_dialog_action_logistic, PSPPIRE_TYPE_DIALOG_ACTION);
44 dialog_state_valid (gpointer data)
46 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (data);
48 const gchar *text = gtk_entry_get_text (GTK_ENTRY (rd->dep_var));
50 GtkTreeModel *indep_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars));
54 return 0 != strcmp ("", text) &&
55 gtk_tree_model_get_iter_first (indep_vars, ¬used);
59 refresh (PsppireDialogAction *rd_)
61 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (rd_);
63 GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars));
64 gtk_list_store_clear (GTK_LIST_STORE (liststore));
66 gtk_entry_set_text (GTK_ENTRY (rd->dep_var), "");
71 on_opts_clicked (PsppireDialogActionLogistic *act)
75 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(act->conf_checkbox), act->conf);
76 gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->conf_entry), act->conf_level);
77 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(act->const_checkbox), act->constant);
79 gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->cut_point_entry), act->cut_point);
80 gtk_spin_button_set_value (GTK_SPIN_BUTTON (act->iterations_entry), act->max_iterations);
83 ret = psppire_dialog_run (PSPPIRE_DIALOG (act->opts_dialog));
85 if ( ret == PSPPIRE_RESPONSE_CONTINUE )
87 act->conf = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(act->conf_checkbox));
88 act->conf_level = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->conf_entry));
90 act->constant = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(act->const_checkbox));
92 act->cut_point = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->cut_point_entry));
93 act->max_iterations = gtk_spin_button_get_value (GTK_SPIN_BUTTON (act->iterations_entry));
99 psppire_dialog_action_logistic_activate (GtkAction *a)
101 PsppireDialogActionLogistic *act = PSPPIRE_DIALOG_ACTION_LOGISTIC (a);
102 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
103 GtkWidget *opts_button;
105 GtkBuilder *xml = builder_new ("logistic.ui");
107 pda->dialog = get_widget_assert (xml, "logistic-dialog");
108 pda->source = get_widget_assert (xml, "dict-view");
109 act->cut_point = 0.5;
110 act->max_iterations = 20;
111 act->constant = true;
113 act->conf_level = 95;
115 act->dep_var = get_widget_assert (xml, "dependent-entry");
116 act->indep_vars = get_widget_assert (xml, "indep-view");
117 act->opts_dialog = get_widget_assert (xml, "options-dialog");
118 act->conf_checkbox = get_widget_assert (xml, "checkbutton2");
119 act->conf_entry = get_widget_assert (xml, "spinbutton1");
120 act->const_checkbox = get_widget_assert (xml, "checkbutton1");
122 act->iterations_entry = get_widget_assert (xml, "spinbutton3");
123 act->cut_point_entry = get_widget_assert (xml, "spinbutton2");
125 opts_button = get_widget_assert (xml, "options-button");
127 g_signal_connect_swapped (opts_button, "clicked",
128 G_CALLBACK (on_opts_clicked), act);
130 g_signal_connect (act->conf_checkbox, "toggled",
131 G_CALLBACK (set_sensitivity_from_toggle),
134 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(act->conf_checkbox), TRUE);
135 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(act->conf_checkbox), FALSE);
137 g_object_unref (xml);
139 psppire_dialog_action_set_refresh (pda, refresh);
141 psppire_dialog_action_set_valid_predicate (pda,
144 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate)
145 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate (pda);
151 generate_syntax (PsppireDialogAction *a)
153 PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (a);
156 const gchar *dep = gtk_entry_get_text (GTK_ENTRY (rd->dep_var));
158 ds_init_cstr (&str, "LOGISTIC REGRESSION ");
160 ds_put_cstr (&str, dep);
162 ds_put_cstr (&str, " WITH ");
164 psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (rd->indep_vars), 0, &str);
166 ds_put_cstr (&str, "\n\t/CRITERIA =");
168 syntax_gen_pspp (&str, " CUT(%g)", rd->cut_point);
170 syntax_gen_pspp (&str, " ITERATE(%d)", rd->max_iterations);
174 syntax_gen_pspp (&str, "\n\t/PRINT = CI(%g)", rd->conf_level);
178 ds_put_cstr (&str, "\n\t/NOORIGIN");
180 ds_put_cstr (&str, "\n\t/ORIGIN");
182 ds_put_cstr (&str, ".\n");
184 text = ds_steal_cstr (&str);
192 psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class)
194 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
196 action_class->activate = psppire_dialog_action_logistic_activate;
198 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
203 psppire_dialog_action_logistic_init (PsppireDialogActionLogistic *act)