[gnumeric] scenarios: switch solver to new api.



commit 6c5f02b4466dce00ca7fdac5558277d2f42a5792
Author: Morten Welinder <terra gnome org>
Date:   Wed Nov 25 09:31:40 2009 -0500

    scenarios: switch solver to new api.

 src/dialogs/dialog-solver.c |   21 +++++++++++----------
 src/tools/scenarios.c       |    7 ++++++-
 2 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index c29745b..247264d 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -777,18 +777,19 @@ static void
 solver_add_scenario (SolverState *state, GnmSolverResult *res, gchar const *name)
 {
 	GnmSolverParameters *param = state->sheet->solver_parameters;
-	GnmValue         *input_range;
-	gchar const      *comment = _("Optimal solution created by solver.\n");
-	GnmScenario       *scenario;
+	GnmValue const *vinput;
+	char const *comment = _("Optimal solution created by solver.\n");
+	GnmScenario *sc;
+	GnmSheetRange sr;
 
-	input_range = gnm_expr_entry_parse_as_value (state->change_cell_entry,
-						     state->sheet);
+	vinput = gnm_solver_param_get_input (param);
+	gnm_sheet_range_from_value (&sr, vinput);
+
+	sc = gnm_sheet_scenario_new (param->sheet, name);
+	gnm_scenario_set_comment (sc, comment);
+	gnm_scenario_add_area (sc, &sr, TRUE);
 
-	scenario_add_new (name, input_range,
-			  value_peek_string (gnm_solver_param_get_input (param)),
-			  comment, state->sheet, &scenario);
-	gnm_sheet_scenario_add (scenario->sheet, scenario);
-	value_release (input_range);
+	gnm_sheet_scenario_add (sc->sheet, sc);
 }
 
 /**
diff --git a/src/tools/scenarios.c b/src/tools/scenarios.c
index 2e99ca5..794c9b3 100644
--- a/src/tools/scenarios.c
+++ b/src/tools/scenarios.c
@@ -94,6 +94,9 @@ scenario_for_each_value (GnmScenario *s, ScenarioValueCB fn, gpointer data)
 {
 	int        i, j, cols, pos;
 
+	if (!s->changing_cells)
+		return;
+
 	cols = s->range.end.col - s->range.start.col + 1;
 	for (i = s->range.start.row; i <= s->range.end.row; i++)
 		for (j = s->range.start.col; j <= s->range.end.col; j++) {
@@ -181,7 +184,9 @@ cb_save_cells (GnmCellIter const *iter, gpointer user)
 
 	/* FIXME: Think about arrays.  */
 
-	sr.sheet = cell->base.sheet;
+	sr.sheet = (cell->base.sheet == pdata->sc->sheet)
+		? NULL
+		: cell->base.sheet;
 	sr.range.start = sr.range.end = iter->pp.eval;
 	gnm_scenario_item_set_range (sci, &sr);
 	gnm_scenario_item_set_value (sci, cell->value);



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