Commit a6f5965e authored by Morten Welinder's avatar Morten Welinder

solver xml: improve format for target cell.

parent 3f5ceef5
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.
......
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>
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment