**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+** Copyright (c) 2007 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
Real
-CanvasParser::parse_real(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_real(xmlpp::Element *element)
{
assert(element->get_name()=="real");
}
int
-CanvasParser::parse_integer(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_integer(xmlpp::Element *element)
{
assert(element->get_name()=="integer");
return atoi(val.c_str());
}
+// see 'minor hack' at the end of parse_vector() below
+// making this 'static' to give it file local scope
+// stops it working (where working means working around
+// bug #1509627)
+Vector &canvas_parser_vector_id(Vector &vector)
+{
+ return vector;
+}
+
Vector
-CanvasParser::parse_vector(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_vector(xmlpp::Element *element)
{
assert(element->get_name()=="vector");
else
error_unexpected_element(child,child->get_name());
}
- return vect;
+ // Minor hack - gcc 4.1.2 and earlier think that we're not using
+ // 'vect' and optimize it out at -O2 and higher. This convinces
+ // them that we are really using it.
+ return canvas_parser_vector_id(vect);
+ // When the bug is fixed, we can just do this instead:
+ // return vect;
}
Color
-CanvasParser::parse_color(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_color(xmlpp::Element *element)
{
assert(element->get_name()=="color");
return Color();
}
- Color color;
+ Color color(0);
xmlpp::Element::NodeList list = element->get_children();
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
}
synfig::String
-CanvasParser::parse_string(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_string(xmlpp::Element *element)
{
assert(element->get_name()=="string");
}
bool
-CanvasParser::parse_bool(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_bool(xmlpp::Element *element)
{
assert(element->get_name()=="bool");
}
Gradient
-CanvasParser::parse_gradient(xmlpp::Element *node,Canvas::Handle canvas)
+CanvasParser::parse_gradient(xmlpp::Element *node)
{
assert(node->get_name()=="gradient");
Gradient ret;
else
{
Gradient::CPoint cpoint;
- cpoint.color=parse_color(child,canvas);
+ cpoint.color=parse_color(child);
if(!child->get_attribute("pos"))
{
}
Segment
-CanvasParser::parse_segment(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_segment(xmlpp::Element *element)
{
assert(element->get_name()=="segment");
continue;
}
- seg.p1=parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas);
+ seg.p1=parse_vector(dynamic_cast<xmlpp::Element*>(*iter));
}
else
if(child->get_name()=="t1")
continue;
}
- seg.t1=parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas);
+ seg.t1=parse_vector(dynamic_cast<xmlpp::Element*>(*iter));
}
else
if(child->get_name()=="p2")
continue;
}
- seg.p2=parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas);
+ seg.p2=parse_vector(dynamic_cast<xmlpp::Element*>(*iter));
}
else
if(child->get_name()=="t2")
continue;
}
- seg.t2=parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas);
+ seg.t2=parse_vector(dynamic_cast<xmlpp::Element*>(*iter));
}
else
error_unexpected_element(child,child->get_name());
}
BLinePoint
-CanvasParser::parse_bline_point(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_bline_point(xmlpp::Element *element)
{
assert(element->get_name()=="bline_point");
if(element->get_children().empty())
continue;
}
- ret.set_vertex(parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas));
+ ret.set_vertex(parse_vector(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Tangent 1
continue;
}
- ret.set_tangent1(parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas));
+ ret.set_tangent1(parse_vector(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// Tangent 2
continue;
}
- ret.set_tangent2(parse_vector(dynamic_cast<xmlpp::Element*>(*iter),canvas));
+ ret.set_tangent2(parse_vector(dynamic_cast<xmlpp::Element*>(*iter)));
ret.set_split_tangent_flag(true);
}
else
continue;
}
- ret.set_width(parse_real(dynamic_cast<xmlpp::Element*>(*iter),canvas));
+ ret.set_width(parse_real(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
// origin
continue;
}
- ret.set_origin(parse_real(dynamic_cast<xmlpp::Element*>(*iter),canvas));
+ ret.set_origin(parse_real(dynamic_cast<xmlpp::Element*>(*iter)));
}
else
error_unexpected_element(child,child->get_name());
}
Angle
-CanvasParser::parse_angle(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_angle(xmlpp::Element *element)
{
assert(element->get_name()=="angle");
CanvasParser::parse_value(xmlpp::Element *element,Canvas::Handle canvas)
{
if(element->get_name()=="real")
- return parse_real(element,canvas);
+ return parse_real(element);
else
if(element->get_name()=="time")
return parse_time(element,canvas);
else
if(element->get_name()=="integer")
- return parse_integer(element,canvas);
+ return parse_integer(element);
else
if(element->get_name()=="string")
- return parse_string(element,canvas);
+ return parse_string(element);
else
if(element->get_name()=="vector")
- {
- return parse_vector(element,canvas);
- }
+ return parse_vector(element);
else
if(element->get_name()=="color")
- return parse_color(element,canvas);
+ return parse_color(element);
else
if(element->get_name()=="segment")
- return parse_segment(element,canvas);
+ return parse_segment(element);
else
if(element->get_name()=="list")
return parse_list(element,canvas);
else
if(element->get_name()=="gradient")
- return parse_gradient(element,canvas);
+ return parse_gradient(element);
else
if(element->get_name()=="bool")
- return parse_bool(element,canvas);
+ return parse_bool(element);
else
//if(element->get_name()=="canvas")
// return parse_canvas(element,canvas,true); // inline canvas
//else
if(element->get_name()=="angle" || element->get_name()=="degrees" || element->get_name()=="radians" || element->get_name()=="rotations")
- return parse_angle(element,canvas);
+ return parse_angle(element);
else
if(element->get_name()=="bline_point")
- return parse_bline_point(element,canvas);
+ return parse_bline_point(element);
else
if(element->get_name()=="canvas")
return ValueBase(parse_canvas(element,canvas,true));
return value_node;
}
-// This function is a phase-out hack for the timed swap value node
-etl::handle<ValueNode_Animated>
-CanvasParser::parse_timedswap(xmlpp::Element *node,Canvas::Handle canvas)
-{
- ValueNode_TimedSwap::Handle timed_swap(parse_linkable_value_node(node,canvas));
-
- assert(timed_swap);
-
- ValueNode_Animated::Handle animated(ValueNode_Animated::create(timed_swap->get_type()));
-
- animated->set_root_canvas(canvas->get_root());
-
- assert(animated);
-
- Time swap_time, swap_length;
- (*timed_swap->get_swap_time())(0).put(&swap_time);
- (*timed_swap->get_swap_length())(0).put(&swap_length);
-
- animated->new_waypoint(swap_time-swap_length,timed_swap->get_before());
- animated->new_waypoint(swap_time,timed_swap->get_after());
-
- return animated;
-}
-
-
-handle<ValueNode_Subtract>
-CanvasParser::parse_subtract(xmlpp::Element *element,Canvas::Handle canvas)
-{
- assert(element->get_name()=="subtract");
-
- handle<ValueNode_Subtract> value_node;
- handle<ValueNode> lhs,rhs,scalar;
-
- if(element->get_attribute("type"))
- {
- ValueBase::Type type=ValueBase::ident_type(element->get_attribute("type")->get_value());
-
- if(!type)
- {
- error(element,"Bad type in <subtract>");
- return ValueNode_Subtract::Handle();
- }
- value_node=ValueNode_Subtract::create(type);
- }
- else
- value_node=ValueNode_Subtract::create();
-
- if(!value_node)
- {
- error(element,strprintf(_("Unable to create <subtract>")));
- return handle<ValueNode_Subtract>();
- }
-
- //if(element->get_attribute("scalar"))
- //{
- // value_node->set_scalar(atof(element->get_attribute("scalar")->get_value().c_str()));
- //}
-
- try
- {
- if(element->get_attribute("scalar"))
- {
- // This is for compatibility with older versions of the file format
- String value(element->get_attribute("scalar")->get_value());
- if((value[0]<='9' && value[0]>='0') || value[0]=='-')
- {
- warning(element, _("Use of a real value where the ID should be is deprecated"));
- value_node->set_scalar(atof(value.c_str()));
- }
- else
- value_node->set_scalar(canvas->surefind_value_node(value));
- scalar=value_node->get_scalar();
- }
-
- if(element->get_attribute("lhs"))
- {
- lhs=canvas->surefind_value_node(element->get_attribute("lhs")->get_value());
- value_node->set_lhs(lhs);
- }
-
- if(element->get_attribute("rhs"))
- {
- rhs=canvas->surefind_value_node(element->get_attribute("rhs")->get_value());
- value_node->set_rhs(rhs);
- }
- }
- catch (Exception::IDNotFound)
- {
- error(element,"attribute in <subtract> references unknown ID");
- }
- catch (Exception::FileNotFound)
- {
- error(element,"Unable to open external file referenced in ID");
- }
-
- xmlpp::Element::NodeList list = element->get_children();
- for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
- {
- xmlpp::Element *child(dynamic_cast<xmlpp::Element*>(*iter));
- if(!child)
- continue;
- else
- if(child->get_name()=="lhs")
- {
- if(lhs)
- {
- error(child,"LHS component of <subtract> already defined!");
- continue;
- }
-
- xmlpp::Element::NodeList list = child->get_children();
- xmlpp::Element::NodeList::iterator iter;
-
- // Search for the first non-text XML element
- for(iter = list.begin(); iter != list.end(); ++iter)
- if(dynamic_cast<xmlpp::Element*>(*iter)) break;
-
- if(iter==list.end())
- {
- error(child,_("<lhs> is missing its contents"));
- continue;
- }
-
- lhs=parse_value_node(dynamic_cast<xmlpp::Element*>(*iter),canvas);
-
- if(lhs)
- value_node->set_lhs(lhs);
- else
- {
- error((*iter),"Parse of LHS ValueNode failed");
- }
-
- // \todo do a search for more elements and warn if they are found
- }
- else
- if(child->get_name()=="rhs")
- {
- if(rhs)
- {
- error(child,"RHS component of <subtract> already defined!");
- continue;
- }
-
- xmlpp::Element::NodeList list = child->get_children();
- xmlpp::Element::NodeList::iterator iter;
-
- // Search for the first non-text XML element
- for(iter = list.begin(); iter != list.end(); ++iter)
- if(dynamic_cast<xmlpp::Element*>(*iter)) break;
-
- if(iter==list.end())
- {
- error(child,_("<rhs> is missing its contents"));
- continue;
- }
-
- rhs=parse_value_node(dynamic_cast<xmlpp::Element*>(*iter),canvas);
-
- if(rhs)
- value_node->set_rhs(rhs);
- else
- {
- error((*iter),"Parse of RHS ValueNode failed");
- }
-
- // \todo do a search for more elements and warn if they are found
- }
- else
- if(child->get_name()=="scalar")
- {
- if(scalar)
- {
- error(child,"scalar component of <subtract> already defined!");
- continue;
- }
-
- xmlpp::Element::NodeList list = child->get_children();
- xmlpp::Element::NodeList::iterator iter;
-
- // Search for the first non-text XML element
- for(iter = list.begin(); iter != list.end(); ++iter)
- if(dynamic_cast<xmlpp::Element*>(*iter)) break;
-
- if(iter==list.end())
- {
- error(child,_("<scalar> is missing its contents"));
- continue;
- }
-
- scalar=parse_value_node(dynamic_cast<xmlpp::Element*>(*iter),canvas);
-
- if(scalar)
- value_node->set_scalar(scalar);
- else
- {
- error((*iter),"Parse of scalar ValueNode failed");
- }
-
- // \todo do a search for more elements and warn if they are found
- }
- else
- error_unexpected_element(child,child->get_name());
- }
-
- if(!value_node->get_rhs() || !value_node->get_lhs() || !value_node->get_scalar())
- error(element,"<subtract> is missing LHS, RHS, or SCALAR");
-
- if(value_node->get_rhs() == value_node->get_lhs())
- warning(element,"LHS is equal to RHS in <subtract>, so this value_node will always be zero!");
-
- return value_node;
-}
-
etl::handle<LinkableValueNode>
CanvasParser::parse_linkable_value_node(xmlpp::Element *element,Canvas::Handle canvas)
{
if(element->get_name()=="hermite" || element->get_name()=="animated")
value_node=parse_animated(element,canvas);
else
- if(element->get_name()=="subtract")
- value_node=parse_subtract(element,canvas);
- else
if(element->get_name()=="composite")
value_node=parse_composite(element,canvas);
else
if(element->get_name()=="bline") // This is not a typo. The dynamic list parser will parse a bline.
value_node=parse_dynamic_list(element,canvas);
else
- if(element->get_name()=="timed_swap")
- value_node=parse_timedswap(element,canvas);
- else
if(LinkableValueNode::book().count(element->get_name()))
value_node=parse_linkable_value_node(element,canvas);
else
if(canvas->value_node_list().placeholder_count())
{
- error(element,strprintf(_("Canvas %s has undefined ValueNodes"),canvas->get_id().c_str()));
+ String nodes;
+ for (ValueNodeList::const_iterator iter = canvas->value_node_list().begin(); iter != canvas->value_node_list().end(); iter++)
+ if(PlaceholderValueNode::Handle::cast_dynamic(*iter))
+ {
+ if (nodes != "") nodes += ", ";
+ nodes += "'" + (*iter)->get_id() + "'";
+ }
+ error(element,strprintf(_("Canvas '%s' has undefined %s: %s"),
+ canvas->get_id().c_str(),
+ canvas->value_node_list().placeholder_count() == 1 ? _("ValueNode") : _("ValueNodes"),
+ nodes.c_str()));
}
return canvas;