[gnumeric] solver xml: improve format for target cell.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] solver xml: improve format for target cell.
- Date: Mon, 9 Nov 2009 01:13:07 +0000 (UTC)
commit a6f5965e05383f25503c593d3b6719df2aaee6d8
Author: Morten Welinder <terra gnome org>
Date: Sun Nov 8 20:12:40 2009 -0500
solver xml: improve format for target cell.
ChangeLog | 5 +++++
src/tools/solver/ChangeLog | 1 +
src/tools/solver/solver.c | 29 ++++++++++++++++++++++++-----
src/xml-sax-write.c | 14 +++++++++-----
4 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5502c5b..a6f8af6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-08 Morten Welinder <terra gnome org>
+
+ * src/xml-sax-write.c (xml_write_solver): Write target cell as
+ cellref so we don't drop the sheet.
+
2009-11-07 Morten Welinder <terra gnome org>
* src/numbers.h: Resurrect long double support.
diff --git a/src/tools/solver/ChangeLog b/src/tools/solver/ChangeLog
index 218e72d..9cf10e0 100644
--- a/src/tools/solver/ChangeLog
+++ b/src/tools/solver/ChangeLog
@@ -1,6 +1,7 @@
2009-11-08 Morten Welinder <terra gnome org>
* solver.c (cb_grab_cells): Fix GList vs. GSList confusion.
+ (solver_param_read_sax): Read new target format.
2009-11-02 Morten Welinder <terra gnome org>
diff --git a/src/tools/solver/solver.c b/src/tools/solver/solver.c
index 6ce54fb..f3bd6a4 100644
--- a/src/tools/solver/solver.c
+++ b/src/tools/solver/solver.c
@@ -310,6 +310,7 @@ solver_param_read_sax (GsfXMLIn *xin, xmlChar const **attrs)
int col = -1, row = -1;
int ptype;
GnmParsePos pp;
+ gboolean old = FALSE;
static GsfXMLInNode const dtd[] = {
GSF_XML_IN_NODE (SHEET_SOLVER_CONSTR, SHEET_SOLVER_CONSTR, GNM, "Constr", GSF_XML_NO_CONTENT, &solver_constr_start, NULL),
@@ -320,17 +321,34 @@ solver_param_read_sax (GsfXMLIn *xin, xmlChar const **attrs)
parse_pos_init_sheet (&pp, sheet);
for (; attrs && attrs[0] && attrs[1] ; attrs += 2) {
- if (gnm_xml_attr_int (attrs, "ProblemType", &ptype))
+ if (gnm_xml_attr_int (attrs, "ProblemType", &ptype)) {
sp->problem_type = (SolverProblemType)ptype;
- else if (strcmp (CXML2C (attrs[0]), "Inputs") == 0) {
+ } else if (attr_eq (attrs[0], "Inputs")) {
GnmValue *v = value_new_cellrange_parsepos_str
(&pp,
CXML2C (attrs[1]),
GNM_EXPR_PARSE_DEFAULT);
gnm_solver_param_set_input (sp, v);
} else if (gnm_xml_attr_int (attrs, "TargetCol", &col) ||
- gnm_xml_attr_int (attrs, "TargetRow", &row) ||
- gnm_xml_attr_int (attrs, "MaxTime", &(sp->options.max_time_sec)) ||
+ gnm_xml_attr_int (attrs, "TargetRow", &row)) {
+ old = TRUE;
+ } else if (attr_eq (attrs[0], "Target")) {
+ GnmValue *v = value_new_cellrange_parsepos_str
+ (&pp,
+ CXML2C (attrs[1]),
+ GNM_EXPR_PARSE_DEFAULT);
+ GnmSheetRange sr;
+ GnmCellRef cr;
+
+ if (!v ||
+ (gnm_sheet_range_from_value (&sr, v), !range_is_singleton (&sr.range)))
+ continue;
+ gnm_cellref_init (&cr, sr.sheet,
+ sr.range.start.col,
+ sr.range.start.row,
+ TRUE);
+ gnm_solver_param_set_target (sp, &cr);
+ } else if (gnm_xml_attr_int (attrs, "MaxTime", &(sp->options.max_time_sec)) ||
gnm_xml_attr_int (attrs, "MaxIter", &(sp->options.max_iter)) ||
gnm_xml_attr_bool (attrs, "NonNeg", &(sp->options.assume_non_negative)) ||
gnm_xml_attr_bool (attrs, "Discr", &(sp->options.assume_discrete)) ||
@@ -344,7 +362,8 @@ solver_param_read_sax (GsfXMLIn *xin, xmlChar const **attrs)
; /* Nothing */
}
- if (col >= 0 && col < gnm_sheet_get_max_cols (sheet) &&
+ if (old &&
+ col >= 0 && col < gnm_sheet_get_max_cols (sheet) &&
row >= 0 && row < gnm_sheet_get_max_rows (sheet)) {
GnmCellRef cr;
gnm_cellref_init (&cr, NULL, col, row, TRUE);
diff --git a/src/xml-sax-write.c b/src/xml-sax-write.c
index 9a351be..71ea13e 100644
--- a/src/xml-sax-write.c
+++ b/src/xml-sax-write.c
@@ -977,11 +977,15 @@ xml_write_solver (GnmOutputXML *state)
target = gnm_solver_param_get_target (param);
if (target != NULL) {
- /* FIXME: This drops sheet */
- gsf_xml_out_add_int (state->output, "TargetCol",
- target->col);
- gsf_xml_out_add_int (state->output, "TargetRow",
- target->row);
+ GnmExpr const *expr = gnm_expr_new_cellref (target);
+ GnmParsePos pp;
+ char *txt = gnm_expr_as_string
+ (expr,
+ parse_pos_init_sheet (&pp, state->sheet),
+ state->convs);
+ gsf_xml_out_add_cstr (state->output, "Target", txt);
+ g_free (txt);
+ gnm_expr_free (expr);
}
gsf_xml_out_add_int (state->output, "ProblemType", param->problem_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]