gnumeric r17295 - in trunk/src: . dialogs tools tools/solver widgets



Author: mortenw
Date: Fri Apr  3 20:40:07 2009
New Revision: 17295
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17295&view=rev

Log:
2009-04-03  Morten Welinder  <terra gnome org>

	* dao.c (dao_init_new_sheet): New shorthand.  Use everywhere.



Modified:
   trunk/src/commands.c
   trunk/src/dialogs/dialog-scenarios.c
   trunk/src/tools/ChangeLog
   trunk/src/tools/dao.c
   trunk/src/tools/dao.h
   trunk/src/tools/scenarios.c
   trunk/src/tools/simulation.c
   trunk/src/tools/solver/reports-write.c
   trunk/src/widgets/gnm-dao.c

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Fri Apr  3 20:40:07 2009
@@ -5942,7 +5942,7 @@
 	CmdScenarioMngr *me = CMD_SCENARIO_MNGR (cmd);
 	data_analysis_output_t dao;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = me->cmd.sheet;
 	scenario_free (me->sc->undo);
 	me->sc->undo = scenario_show (wbc, me->sc->redo, NULL, &dao);
@@ -5958,7 +5958,7 @@
 	scenario_t      *tmp;
 	data_analysis_output_t dao;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = me->cmd.sheet;
 	tmp = scenario_copy (me->sc->undo, dao.sheet);
 	scenario_show (wbc, NULL, tmp, &dao);
@@ -5994,7 +5994,7 @@
 	me->cmd.size  = 1;
 	me->cmd.cmd_descriptor = g_strdup (_("Scenario Show"));
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = me->cmd.sheet;
 	me->sc->redo = scenario_show (wbc, me->sc->undo, NULL, &dao);
 

Modified: trunk/src/dialogs/dialog-scenarios.c
==============================================================================
--- trunk/src/dialogs/dialog-scenarios.c	(original)
+++ trunk/src/dialogs/dialog-scenarios.c	Fri Apr  3 20:40:07 2009
@@ -163,7 +163,7 @@
 	comment = g_strdup (gtk_text_buffer_get_text (buf, &start, &end,
 						      FALSE));
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = state->base.sheet;
 
 	wbc = WORKBOOK_CONTROL (state->base.wbcg);
@@ -415,7 +415,7 @@
 	scenario_cmd_t         *cmd = g_new (scenario_cmd_t, 1);
 
 	if (state->scenario_state->current) {
-		dao_init (&dao, NewSheetOutput);
+		dao_init_new_sheet (&dao);
 		dao.sheet = state->base.sheet;
 		wbc = WORKBOOK_CONTROL (state->base.wbcg);
 
@@ -442,7 +442,7 @@
 	if (state->scenario_state->old_values == NULL)
 		return;
 	wbc = WORKBOOK_CONTROL (state->base.wbcg);
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = state->base.sheet;
 	scenario_show (wbc, NULL,
 		       (scenario_t *) state->scenario_state->old_values,
@@ -502,7 +502,7 @@
 
 	selection = gtk_tree_view_get_selection
 	        (GTK_TREE_VIEW (state->scenario_state->scenarios_treeview));
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = state->base.sheet;
 	if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
 		return;
@@ -536,7 +536,7 @@
 
 	selection = gtk_tree_view_get_selection
 	        (GTK_TREE_VIEW (state->scenario_state->scenarios_treeview));
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = state->base.sheet;
 	if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
 		return;

Modified: trunk/src/tools/dao.c
==============================================================================
--- trunk/src/tools/dao.c	(original)
+++ trunk/src/tools/dao.c	Fri Apr  3 20:40:07 2009
@@ -76,8 +76,8 @@
 	dao->start_row         = 0;
 	dao->offset_col        = 0;
 	dao->offset_row        = 0;
-	dao->cols              = gnm_sheet_get_max_cols (NULL);
-	dao->rows              = gnm_sheet_get_max_rows (NULL);
+	dao->cols              = 1;  /* Fixed in dao_prepare_output */
+	dao->rows              = 1;
 	dao->sheet             = NULL;
 	dao->autofit_flag      = TRUE;
 	dao->clear_outputrange = TRUE;
@@ -90,6 +90,12 @@
 	return dao;
 }
 
+data_analysis_output_t *
+dao_init_new_sheet (data_analysis_output_t *dao)
+{
+	return dao_init (dao, NewSheetOutput);
+}
+
 void dao_free (data_analysis_output_t *dao)
 {
 	go_slist_free_custom (dao->sos, g_object_unref);
@@ -225,12 +231,12 @@
 		    const char *name)
 {
 	char *unique_name;
-	Sheet *old_sheet = wb_control_cur_sheet (wbc);
 
 	if (wbc)
 		dao->wbc = wbc;
 
 	if (dao->type == NewSheetOutput) {
+		Sheet *old_sheet = wb_control_cur_sheet (dao->wbc);
 		Workbook *wb = wb_control_get_workbook (dao->wbc);
 		char *name_with_counter = g_strdup_printf ("%s (1)", name);
 		unique_name = workbook_sheet_get_free_name
@@ -243,6 +249,7 @@
 		dao->start_col = dao->start_row = 0;
 		workbook_sheet_attach (wb, dao->sheet);
 	} else if (dao->type == NewWorkbookOutput) {
+		Sheet *old_sheet = wb_control_cur_sheet (dao->wbc);
 		Workbook *wb = workbook_new ();
 		dao->rows = gnm_sheet_get_max_rows (old_sheet);
 		dao->cols = gnm_sheet_get_max_cols (old_sheet);

Modified: trunk/src/tools/dao.h
==============================================================================
--- trunk/src/tools/dao.h	(original)
+++ trunk/src/tools/dao.h	Fri Apr  3 20:40:07 2009
@@ -56,6 +56,7 @@
 
 data_analysis_output_t *dao_init (data_analysis_output_t *dao, 
 				  data_analysis_output_type_t type);
+data_analysis_output_t *dao_init_new_sheet (data_analysis_output_t *dao);
 data_analysis_output_t *dao_load_from_value (data_analysis_output_t *dao,
 					     GnmValue *output_range);
 void dao_free (data_analysis_output_t *dao);

Modified: trunk/src/tools/scenarios.c
==============================================================================
--- trunk/src/tools/scenarios.c	(original)
+++ trunk/src/tools/scenarios.c	Fri Apr  3 20:40:07 2009
@@ -616,7 +616,7 @@
 	int        i, j, col, tmp_row = 4 + cb->row;
 	GnmRange      r;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
 	dao.sheet = cb->sheet;
 
 	dao_set_cell (&cb->dao, 0, 3 + cb->row++, _("Result Cells:"));
@@ -684,7 +684,7 @@
 	GList        *scenarios = sheet->scenarios;
 
 	/* Initialize: Currently only new sheet output supported. */
-	dao_init (&cb.dao, NewSheetOutput);
+	dao_init_new_sheet (&cb.dao);
 	dao_prepare_output (wbc, &cb.dao, _("Scenario Summary"));
 
 	/* Titles. */

Modified: trunk/src/tools/simulation.c
==============================================================================
--- trunk/src/tools/simulation.c	(original)
+++ trunk/src/tools/simulation.c	Fri Apr  3 20:40:07 2009
@@ -96,7 +96,7 @@
 		}
 
 		if (outputs)
-			outputs [i++][iter] = value_get_as_float (cell->value);
+			outputs[i++][iter] = value_get_as_float (cell->value);
 	}
 
 	return NULL;
@@ -122,7 +122,7 @@
 		}
 
 		if (outputs)
-			outputs [i++][iter] = value_get_as_float (cell->value);
+			outputs[i++][iter] = value_get_as_float (cell->value);
 	}
 
 	return NULL;
@@ -148,78 +148,78 @@
 
 	/* Initialize. */
 	for (i = 0; i < sim->n_vars; i++)
-		stats->errmask [i] = 0;
+		stats->errmask[i] = 0;
 
 	/* Calculate stats. */
 	for (i = 0; i < sim->n_vars; i++) {
 		/* Min */
-		error = gnm_range_min (outputs [i], sim->n_iterations, &x);
-		stats->min [i] = x;
+		error = gnm_range_min (outputs[i], sim->n_iterations, &x);
+		stats->min[i] = x;
 
 		/* Mean */
-		error = gnm_range_average (outputs [i], sim->n_iterations, &x);
-		stats->mean [i] = x;
+		error = gnm_range_average (outputs[i], sim->n_iterations, &x);
+		stats->mean[i] = x;
 
 		/* Max */
-		error = gnm_range_max (outputs [i], sim->n_iterations, &x);
-		stats->max [i] = x;
+		error = gnm_range_max (outputs[i], sim->n_iterations, &x);
+		stats->max[i] = x;
 
 		/* Median */
-		error = gnm_range_median_inter (outputs [i], sim->n_iterations,
+		error = gnm_range_median_inter (outputs[i], sim->n_iterations,
 					    &x);
 		if (error)
-			stats->errmask [i] |= MedianErr;
+			stats->errmask[i] |= MedianErr;
 		else
-			stats->median [i] = x;
+			stats->median[i] = x;
 
 		/* Mode */
-		error = gnm_range_mode (outputs [i], sim->n_iterations, &x);
+		error = gnm_range_mode (outputs[i], sim->n_iterations, &x);
 		if (error)
-			stats->errmask [i] |= ModeErr;
+			stats->errmask[i] |= ModeErr;
 		else
-			stats->mode [i] = x;
+			stats->mode[i] = x;
 
 		/* Standard deviation */
-		error = gnm_range_stddev_pop (outputs [i], sim->n_iterations, &x);
+		error = gnm_range_stddev_pop (outputs[i], sim->n_iterations, &x);
 		if (error)
-			stats->errmask [i] |= VarErr;
+			stats->errmask[i] |= VarErr;
 		else
-			stats->stddev [i] = x;
+			stats->stddev[i] = x;
 
 		/* Variance */
-		error = gnm_range_var_pop (outputs [i], sim->n_iterations, &x);
+		error = gnm_range_var_pop (outputs[i], sim->n_iterations, &x);
 		if (error)
-			stats->errmask [i] |= VarErr;
+			stats->errmask[i] |= VarErr;
 		else
-			stats->var [i] = x;
+			stats->var[i] = x;
 
 		/* Skewness */
-		error = gnm_range_skew_est (outputs [i], sim->n_iterations, &x);
+		error = gnm_range_skew_est (outputs[i], sim->n_iterations, &x);
 		if (error)
-			stats->errmask [i] |= SkewErr;
+			stats->errmask[i] |= SkewErr;
 		else
-			stats->skew [i] = x;
+			stats->skew[i] = x;
 
 		/* Kurtosis */
-		error = gnm_range_kurtosis_m3_est (outputs [i], sim->n_iterations,
+		error = gnm_range_kurtosis_m3_est (outputs[i], sim->n_iterations,
 					       &x);
 		if (error)
-			stats->errmask [i] |= KurtosisErr;
+			stats->errmask[i] |= KurtosisErr;
 		else
-			stats->kurtosis [i] = x;
+			stats->kurtosis[i] = x;
 
 		/* Range */
-		stats->range [i] = stats->max [i] - stats->min [i];
+		stats->range[i] = stats->max[i] - stats->min[i];
 
 		/* Confidence (95%) */
-		stats->confidence [i] = -qnorm (0.05, 0, 1, TRUE, FALSE)
-			* (stats->stddev [i] / gnm_sqrt (sim->n_iterations));
+		stats->confidence[i] = -qnorm (0.05, 0, 1, TRUE, FALSE)
+			* (stats->stddev[i] / gnm_sqrt (sim->n_iterations));
 
 		/* Lower Confidence (95%) */
-		stats->lower [i] = stats->mean [i] - stats->confidence [i] / 2;
+		stats->lower[i] = stats->mean[i] - stats->confidence[i] / 2;
 
 		/* upper Confidence (95%) */
-		stats->upper [i] = stats->mean [i] + stats->confidence [i] / 2;
+		stats->upper[i] = stats->mean[i] + stats->confidence[i] / 2;
 	}
 }
 
@@ -233,7 +233,7 @@
 
 	dao_prepare_output (wbc, dao, _("Simulation Report"));
 	if (dao->type == NewSheetOutput || dao->type == NewWorkbookOutput)
-		dao->sheet->hide_grid = TRUE;
+		g_object_set (dao->sheet, "display-grid", FALSE, NULL);
 
 	/*
 	 * Set this to fool the autofit_column function.  (It will be
@@ -261,50 +261,50 @@
 
 		for (i = 0; i < sim->n_vars; i++) {
 			dao_set_cell (dao, 1, i + 7 + n * rinc,
-				      sim->cellnames [i]);
+				      sim->cellnames[i]);
 			dao_set_bold (dao, 1, i + 7 + n * rinc, 1,
 				      i + 7 + n * rinc);
 			dao_set_cell_float (dao, 2, i + 7 + n * rinc,
-					    stats [t]->min [i]);
+					    stats[t]->min[i]);
 			dao_set_cell_float (dao, 3, i + 7 + n * rinc,
-					    stats [t]->mean [i]);
+					    stats[t]->mean[i]);
 			dao_set_cell_float (dao, 4, i + 7 + n * rinc,
-					    stats [t]->max [i]);
+					    stats[t]->max[i]);
 			dao_set_cell_float (dao, 5, i + 7 + n * rinc,
-					    stats [t]->median [i]);
+					    stats[t]->median[i]);
 			dao_set_cell_float_na
-				(dao, 6, i + 7 + n * rinc, stats [t]->mode [i],
-				 ! (stats [t]->errmask [i] & ModeErr));
+				(dao, 6, i + 7 + n * rinc, stats[t]->mode[i],
+				 ! (stats[t]->errmask[i] & ModeErr));
 			dao_set_cell_float_na
 				(dao, 7, i + 7 + n * rinc,
-				 stats [t]->stddev [i],
-				 ! (stats [t]->errmask [i] & StddevErr));
+				 stats[t]->stddev[i],
+				 ! (stats[t]->errmask[i] & StddevErr));
 			dao_set_cell_float_na
-				(dao, 8, i + 7 + n * rinc, stats [t]->var [i],
-				 ! (stats [t]->errmask [i] & VarErr));
+				(dao, 8, i + 7 + n * rinc, stats[t]->var[i],
+				 ! (stats[t]->errmask[i] & VarErr));
 			dao_set_cell_float_na
-				(dao, 9, i + 7 + n * rinc, stats [t]->skew [i],
-				 ! (stats [t]->errmask [i] & SkewErr));
+				(dao, 9, i + 7 + n * rinc, stats[t]->skew[i],
+				 ! (stats[t]->errmask[i] & SkewErr));
 			dao_set_cell_float_na
 				(dao, 10, i + 7 + n * rinc,
-				 stats [t]->kurtosis [i],
-				 ! (stats [t]->errmask [i] & KurtosisErr));
+				 stats[t]->kurtosis[i],
+				 ! (stats[t]->errmask[i] & KurtosisErr));
 			dao_set_cell_float (dao, 11, i + 7 + n * rinc,
-					    stats [t]->range [i]);
+					    stats[t]->range[i]);
 			dao_set_cell_float (dao, 12, i + 7 + n * rinc,
 					    sim->n_iterations);
 			dao_set_cell_float_na
 				(dao, 13, i + 7 + n * rinc,
-				 stats [t]->confidence [i],
-				 ! (stats [t]->errmask [i] & StddevErr));
+				 stats[t]->confidence[i],
+				 ! (stats[t]->errmask[i] & StddevErr));
 			dao_set_cell_float_na
 				(dao, 14, i + 7 + n * rinc,
-				 stats [t]->lower [i],
-				 ! (stats [t]->errmask [i] & StddevErr));
+				 stats[t]->lower[i],
+				 ! (stats[t]->errmask[i] & StddevErr));
 			dao_set_cell_float_na
 				(dao, 15, i + 7 + n * rinc,
-				 stats [t]->upper [i],
-				 ! (stats [t]->errmask [i] & StddevErr));
+				 stats[t]->upper[i],
+				 ! (stats[t]->errmask[i] & StddevErr));
 		}
 	}
 
@@ -365,19 +365,19 @@
 	sim->cellnames = g_new (gchar *, sim->n_vars);
 	outputs        = g_new (gnm_float *, sim->n_vars);
 	for (i = 0; i < sim->n_vars; i++)
-		outputs [i] = g_new (gnm_float, sim->n_iterations);
+		outputs[i] = g_new (gnm_float, sim->n_iterations);
 
 	stats     = g_new (simstats_t *, sim->last_round + 1);
 	for (i = 0; i <= sim->last_round; i++) {
-		stats [i] = g_new (simstats_t, 1);
-		init_stats (stats [i], sim);
+		stats[i] = g_new (simstats_t, 1);
+		init_stats (stats[i], sim);
 	}
 
 	i = 0;
 	for (cur = sim->list_outputs; cur != NULL; cur = cur->next) {
 		GnmCell *cell = (GnmCell *) cur->data;
 
-		sim->cellnames [i++] =
+		sim->cellnames[i++] =
 			(gchar *) dao_find_name (sheet, cell->pos.col,
 						 cell->pos.row);
 	}
@@ -388,7 +388,7 @@
 		gchar *prefix = _("(Input) ");
 		gchar *buf = g_strdup_printf ("%s %s", prefix, tmp);
 		g_free (tmp);
-		sim->cellnames [i++] = buf;
+		sim->cellnames[i++] = buf;
 	}
 
 	/* Run the simulations. */
@@ -409,7 +409,7 @@
 			if (err != NULL)
 				goto out;
 		}
-		create_stats (sim, outputs, stats [round]);
+		create_stats (sim, outputs, stats[round]);
 	}
  out:
 	sheet->simulation_round = 0;
@@ -418,7 +418,7 @@
 
 	/* Free results storage. */
 	for (i = 0; i < sim->n_vars; i++)
-		g_free (outputs [i]);
+		g_free (outputs[i]);
 	g_free (outputs);
 
 	if (err == NULL) {
@@ -441,17 +441,16 @@
 	if (sim == NULL)
 		return;
 
-
 	/* Free statistics storage. */
 	for (i = 0; i <= sim->last_round; i++)
-		free_stats (sim->stats [i], sim);
+		free_stats (sim->stats[i], sim);
 
 	g_free (sim->stats);
 
 
 	/* Free the names of the cells. */
 	for (i = 0; i < sim->n_vars; i++)
-		g_free (sim->cellnames [i]);
+		g_free (sim->cellnames[i]);
 
 	g_free (sim->cellnames);
 }

Modified: trunk/src/tools/solver/reports-write.c
==============================================================================
--- trunk/src/tools/solver/reports-write.c	(original)
+++ trunk/src/tools/solver/reports-write.c	Fri Apr  3 20:40:07 2009
@@ -61,7 +61,7 @@
 	GnmCell                   *cell;
 	int                    i, vars;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Answer Report"));
 
 	dao.sheet->hide_grid = TRUE;
@@ -210,7 +210,7 @@
 	GnmCell                   *cell;
 	int                    i, vars;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Sensitivity Report"));
 
 	dao.sheet->hide_grid = TRUE;
@@ -371,7 +371,7 @@
 	GnmCell                   *cell;
 	int                    vars, i;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Limits Report"));
 
 	dao.sheet->hide_grid = TRUE;
@@ -498,7 +498,7 @@
 	int                    mat_size, i;
 	GnmValue              *v;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Performance Report"));
 
 	dao.sheet->hide_grid = TRUE;
@@ -762,7 +762,7 @@
         data_analysis_output_t dao;
 	int                    i, col, row, max_col, n, vars;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Program Report"));
 
 	dao.sheet->hide_grid = TRUE;
@@ -941,7 +941,7 @@
 {
         data_analysis_output_t dao;
 
-	dao_init (&dao, NewSheetOutput);
+	dao_init_new_sheet (&dao);
         dao_prepare_output (wbc, &dao, _("Dual Program Report"));
 
 	dao.sheet->hide_grid = TRUE;

Modified: trunk/src/widgets/gnm-dao.c
==============================================================================
--- trunk/src/widgets/gnm-dao.c	(original)
+++ trunk/src/widgets/gnm-dao.c	Fri Apr  3 20:40:07 2009
@@ -294,7 +294,7 @@
 		switch (grp_val) {
 		case 0:
 		default:
-			*dao = dao_init (*dao, NewSheetOutput);
+			*dao = dao_init_new_sheet (*dao);
 			break;
 		case 1:
 			*dao = dao_init (*dao, NewWorkbookOutput);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]