Exemple #1
0
static void
extract_settings (SolverState *state)
{
	GnmSolverParameters *param = state->sheet->solver_parameters;
	GtkTreeIter iter;
	GnmValue *target_range;
	GnmValue *input_range;
	GnmSolverFactory *factory = NULL;

	target_range = gnm_expr_entry_parse_as_value (state->target_entry,
						      state->sheet);
	input_range = gnm_expr_entry_parse_as_value (state->change_cell_entry,
						     state->sheet);

	gnm_solver_param_set_input (param, input_range);

	gnm_solver_param_set_target (param,
				     target_range
				     ? &target_range->v_range.cell.a
				     : NULL);

	param->problem_type =
		gnm_gui_group_value (state->gui, problem_type_group);
	param->options.model_type =
		gnm_gui_group_value (state->gui, model_type_group);

	if (gtk_combo_box_get_active_iter (state->algorithm_combo, &iter)) {
		gtk_tree_model_get (gtk_combo_box_get_model (state->algorithm_combo),
				    &iter, 1, &factory, -1);
		gnm_solver_param_set_algorithm (param, factory);
	} else
		gnm_solver_param_set_algorithm (param, NULL);

	param->options.max_iter = gtk_spin_button_get_value
		(GTK_SPIN_BUTTON (state->max_iter_entry));
	param->options.max_time_sec = gtk_spin_button_get_value
		(GTK_SPIN_BUTTON (state->max_time_entry));
	param->options.gradient_order = gtk_spin_button_get_value
		(GTK_SPIN_BUTTON (state->gradient_order_entry));

	GET_BOOL_ENTRY ("autoscale_button", options.automatic_scaling);
	GET_BOOL_ENTRY ("non_neg_button", options.assume_non_negative);
	GET_BOOL_ENTRY ("all_int_button", options.assume_discrete);
	GET_BOOL_ENTRY ("program", options.program_report);
	GET_BOOL_ENTRY ("sensitivity", options.sensitivity_report);

	g_free (param->options.scenario_name);
	param->options.scenario_name = g_strdup
		(gtk_entry_get_text (GTK_ENTRY (state->scenario_name_entry)));

	GET_BOOL_ENTRY ("optimal_scenario", options.add_scenario);

	value_release (target_range);
}
Exemple #2
0
/**
 * shuffle_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the data_shuffling.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
shuffle_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button, ShuffleState *state)
{
	data_analysis_output_t  *dao;
	data_shuffling_t        *ds;
	WorkbookControl         *wbc;
	GnmValue                *input;
	int                     type;

	/* This is free'ed by data_shuffling_free. */
	/* We later want to extend this to shuffle to other locations */
	dao = dao_init (NULL, InPlaceOutput);

	input = gnm_expr_entry_parse_as_value (
		GNM_EXPR_ENTRY (state->input_entry), state->sheet);

	if (dao->type == InPlaceOutput)
		dao_load_from_value (dao, input);

	type = gnm_gui_group_value (state->gui, shuffle_by);

	ds = data_shuffling (WORKBOOK_CONTROL (state->wbcg), dao,
			     state->sheet, input, type);

	wbc = WORKBOOK_CONTROL (state->wbcg);
	cmd_data_shuffle (wbc, ds, state->sheet);

	value_release (input);
	gtk_widget_destroy (state->dialog);
}
/**
 * random_cor_tool_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the appropriate tool.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
random_cor_tool_ok_clicked_cb (GtkWidget *button, RandomCorToolState *state)
{
	data_analysis_output_t  *dao;
	tools_data_random_cor_t  *data;
	gint err;

	data = g_new0 (tools_data_random_cor_t, 1);

	dao  = parse_output ((GnmGenericToolState *)state, NULL);
	err = entry_to_int (GTK_ENTRY (state->count_entry), &data->count, FALSE);
	data->matrix = gnm_expr_entry_parse_as_value
		(GNM_EXPR_ENTRY (state->base.input_entry),
		 state->base.sheet);

	data->variables = data->matrix->v_range.cell.b.row -
		data->matrix->v_range.cell.a.row + 1;

	data->matrix_type = gnm_gui_group_value
		(state->base.gui, matrix_group);


	if (!cmd_analysis_tool (GNM_WBC (state->base.wbcg),
				state->base.sheet,
				dao, data, tool_random_cor_engine, TRUE) &&
	    (button == state->base.ok_button))
		gtk_widget_destroy (state->base.dialog);
}
Exemple #4
0
gboolean
gnm_dao_is_finite (GnmDao *gdao)
{
	int grp_val;

	g_return_val_if_fail (gdao != NULL, FALSE);

	grp_val = gnm_gui_group_value (gdao->gui, dao_group);
	return ((grp_val == 2) || (grp_val == 3));
}
Exemple #5
0
static void
cb_set_sensitivity (G_GNUC_UNUSED GtkWidget *dummy, GnmDao *gdao)
{
	int grp_val = gnm_gui_group_value (gdao->gui, dao_group);

	gtk_widget_set_sensitive (gdao->clear_outputrange_button,
				  (grp_val == 2));
	gtk_widget_set_sensitive (gdao->retain_format_button,
				  (grp_val == 2));
	gtk_widget_set_sensitive (gdao->retain_comments_button,
				  (grp_val == 2));

}
Exemple #6
0
static void
cb_dialog_model_type_clicked (G_GNUC_UNUSED GtkWidget *button,
			      SolverState *state)
{
	GnmSolverModelType type;
	gboolean any;

	type = gnm_gui_group_value (state->gui, model_type_group);
	any = fill_algorithm_combo (state, type);

	if (!any) {
		go_gtk_notice_nonmodal_dialog
			(GTK_WINDOW (state->dialog),
			 &(state->warning_dialog),
			 GTK_MESSAGE_INFO,
			 _("Looking for a subject for your thesis? "
			   "Maybe you would like to write a solver for "
			   "Gnumeric?"));
	}
}
Exemple #7
0
static void
tabulate_ok_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd)
{
	GtkDialog *dialog = dd->dialog;
	GnmCell *resultcell;
	int dims = 0;
	int row;
	gboolean with_coordinates;
	GnmTabulateInfo *data;
	/* we might get the 4 below from the positon of some of the widgets inside the grid */
	int nrows = 4;
	GnmCell **cells;
	gnm_float *minima, *maxima, *steps;

	cells = g_new (GnmCell *, nrows);
	minima = g_new (gnm_float, nrows);
	maxima = g_new (gnm_float, nrows);
	steps = g_new (gnm_float, nrows);

	for (row = 1; row < nrows; row++) {
		GtkEntry *e_w;
		GnmExprEntry *w = GNM_EXPR_ENTRY (gtk_grid_get_child_at (dd->grid, COL_CELL, row + 1));

		if (!w || gnm_expr_entry_is_blank (w))
			continue;

		cells[dims] = single_cell (dd->sheet, w);
		if (!cells[dims]) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("You should introduce a single valid cell as dependency cell"));
			gnm_expr_entry_grab_focus (GNM_EXPR_ENTRY (w), TRUE);
			goto error;
		}
		if (gnm_cell_has_expr (cells[dims])) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("The dependency cells should not contain an expression"));
			gnm_expr_entry_grab_focus (GNM_EXPR_ENTRY (w), TRUE);
			goto error;
		}

		if (get_grid_float_entry (dd->grid, row, COL_MIN, cells[dims],
					   &(minima[dims]), &e_w, FALSE, 0.0)) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("You should introduce a valid number as minimum"));
			focus_on_entry (e_w);
			goto error;
		}

		if (get_grid_float_entry (dd->grid, row, COL_MAX, cells[dims],
					   &(maxima[dims]), &e_w, FALSE, 0.0)) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("You should introduce a valid number as maximum"));
			focus_on_entry (e_w);
			goto error;
		}

		if (maxima[dims] < minima[dims]) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("The maximum value should be bigger than the minimum"));
			focus_on_entry (e_w);
			goto error;
		}

		if (get_grid_float_entry (dd->grid, row, COL_STEP, cells[dims],
					   &(steps[dims]), &e_w, TRUE, 1.0)) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("You should introduce a valid number as step size"));
			focus_on_entry (e_w);
			goto error;
		}

		if (steps[dims] <= 0) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("The step size should be positive"));
			focus_on_entry (e_w);
			goto error;
		}

		dims++;
	}

	if (dims == 0) {
		go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
				 GTK_MESSAGE_ERROR,
				 _("You should introduce one or more dependency cells"));
		goto error;
	}

	{
		resultcell = single_cell (dd->sheet, dd->resultrangetext);

		if (!resultcell) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("You should introduce a single valid cell as result cell"));
			gnm_expr_entry_grab_focus (dd->resultrangetext, TRUE);
			goto error;
		}

		if (!gnm_cell_has_expr (resultcell)) {
			go_gtk_notice_dialog (GTK_WINDOW (dd->dialog),
					 GTK_MESSAGE_ERROR,
					 _("The target cell should contain an expression"));
			gnm_expr_entry_grab_focus (dd->resultrangetext, TRUE);
			goto error;
		}
	}

	{
		int i = gnm_gui_group_value (dd->gui, mode_group);
		with_coordinates = (i == -1) ? TRUE : (gboolean)i;
	}

	data = g_new (GnmTabulateInfo, 1);
	data->target = resultcell;
	data->dims = dims;
	data->cells = cells;
	data->minima = minima;
	data->maxima = maxima;
	data->steps = steps;
	data->with_coordinates = with_coordinates;

	if (!cmd_tabulate (GNM_WBC (dd->wbcg), data)) {
		gtk_widget_destroy (GTK_WIDGET (dialog));
		return;
	}

	g_free (data);
 error:
	g_free (minima);
	g_free (maxima);
	g_free (steps);
	g_free (cells);
}
Exemple #8
0
gboolean
gnm_dao_get_data (GnmDao *gdao, data_analysis_output_t **dao)
{
	gboolean dao_ready  = FALSE;
	int grp_val;

	g_return_val_if_fail (gdao != NULL, FALSE);

	grp_val = gnm_gui_group_value (gdao->gui, dao_group);

	dao_ready =  ((grp_val  != 2) ||
		      gnm_expr_entry_is_cell_ref
		      (GNM_EXPR_ENTRY (gdao->output_entry),
		       wb_control_cur_sheet (GNM_WBC (gdao->wbcg)),
		       TRUE));

	if (dao_ready && NULL != dao) {
		GtkWidget *button;
		GnmValue *output_range = NULL;

		switch (grp_val) {
		case 0:
		default:
			*dao = dao_init_new_sheet (*dao);
			break;
		case 1:
			*dao = dao_init (*dao, NewWorkbookOutput);
			break;
		case 2:
			output_range = gnm_expr_entry_parse_as_value
				(GNM_EXPR_ENTRY (gdao->output_entry),
				 wb_control_cur_sheet (GNM_WBC
						       (gdao->wbcg)));
			*dao = dao_init (*dao, RangeOutput);
			dao_load_from_value (*dao, output_range);
			value_release (output_range);
			break;
		case 3:
			(*dao) = dao_init ((*dao), InPlaceOutput);
			/* It is the callers responsibility to fill the */
			/* dao with the appropriate range. */
			break;
		}

		button = go_gtk_builder_get_widget (gdao->gui, "autofit_button");
		(*dao)->autofit_flag = gtk_toggle_button_get_active (
			GTK_TOGGLE_BUTTON (button));

		(*dao)->clear_outputrange = gtk_toggle_button_get_active (
			GTK_TOGGLE_BUTTON (gdao->clear_outputrange_button));
		(*dao)->retain_format = gtk_toggle_button_get_active (
			GTK_TOGGLE_BUTTON (gdao->retain_format_button));
		(*dao)->retain_comments = gtk_toggle_button_get_active (
			GTK_TOGGLE_BUTTON (gdao->retain_comments_button));

		(*dao)->put_formulas
			= (gtk_combo_box_get_active
			   (GTK_COMBO_BOX (gdao->put_menu))
			   != 0);
	}

	return dao_ready;
}