/*! \file loadcanvas.cpp
** \brief writeme
**
-** $Id: loadcanvas.cpp,v 1.3 2005/01/04 23:40:44 darco Exp $
+** $Id$
**
** \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
int test_class::bleh(0);
test_class test_class_instance;
-*/
+*/
/* === M A C R O S ========================================================= */
static void _canvas_file_name_changed(Canvas *x)
{
std::map<synfig::String, etl::loose_handle<Canvas> >::iterator iter;
-
+
for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter)
if(iter->second==x)
break;
return;
get_open_canvas_map().erase(iter->first);
get_open_canvas_map()[etl::absolute_path(x->get_file_name())]=x;
-
+
}
Canvas::Handle
if(parser.error_count())
return Canvas::Handle();
-
+
return canvas;
}
if(parser.error_count())
return Canvas::Handle();
-
+
return canvas;
}
error(element,strprintf(_("<%s> is missing \"%s\" attribute"),"real","time"));
return Keyframe();
}
-
+
Keyframe ret(Time(element->get_attribute("time")->get_value(),canvas->rend_desc().get_frame_rate()));
if(element->get_children().empty())
return ret;
-
+
if(element->get_child_text()->get_content().empty())
return ret;
-
+
ret.set_description(element->get_child_text()->get_content());
- return ret;
+ return ret;
}
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");
warning(element, "Undefined value in <string>");
return synfig::String();
}
-
+
if(element->get_child_text()->get_content().empty())
{
warning(element, "Content element of <string> appears to be empty");
return synfig::String();
}
-
+
return element->get_child_text()->get_content();
}
bool
-CanvasParser::parse_bool(xmlpp::Element *element,Canvas::Handle canvas)
+CanvasParser::parse_bool(xmlpp::Element *element)
{
assert(element->get_name()=="bool");
return false;
error(element,strprintf(_("Bad value \"%s\" in <%s>"),val.c_str(),"bool"));
-
+
return false;
}
Gradient
-CanvasParser::parse_gradient(xmlpp::Element *node,Canvas::Handle canvas)
+CanvasParser::parse_gradient(xmlpp::Element *node)
{
assert(node->get_name()=="gradient");
Gradient ret;
-
+
xmlpp::Element::NodeList list = node->get_children();
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
{
else
{
Gradient::CPoint cpoint;
- cpoint.color=parse_color(child,canvas);
+ cpoint.color=parse_color(child);
if(!child->get_attribute("pos"))
{
}
cpoint.pos=atof(child->get_attribute("pos")->get_value().c_str());
-
+
ret.push_back(cpoint);
}
}
}
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
+ // Tangent 1
if(child->get_name()=="t1" || child->get_name()=="tangent")
{
xmlpp::Element::NodeList list = child->get_children();
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
+ // Tangent 2
if(child->get_name()=="t2")
{
xmlpp::Element::NodeList list = child->get_children();
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));
error(element,"Bad type in <animated>");
return ValueNode_Animated::Handle();
}
-
+
ValueNode_Animated::Handle value_node=ValueNode_Animated::create(type);
if(!value_node)
Time time(child->get_attribute("time")->get_value(),canvas->rend_desc().get_frame_rate());
-
+
ValueNode::Handle waypoint_value_node;
-
+ xmlpp::Element::NodeList list = child->get_children();
+
if(child->get_attribute("use"))
{
- waypoint_value_node=canvas->surefind_value_node(child->get_attribute("use")->get_value());
+ if(!list.empty())
+ warning(child,_("Found \"use\" attribute for <waypoint>, but it wasn't empty. Ignoring contents..."));
+
+ // the waypoint might look like this, in which case we won't find "mycanvas" in the list of valuenodes, 'cos it's a canvas
+ //
+ // <animated type="canvas">
+ // <waypoint time="0s" use="mycanvas"/>
+ // </animated>
+ if (type==ValueBase::TYPE_CANVAS)
+ waypoint_value_node=ValueNode_Const::create(canvas->surefind_canvas(child->get_attribute("use")->get_value()));
+ else
+ waypoint_value_node=canvas->surefind_value_node(child->get_attribute("use")->get_value());
}
else
{
error(child, strprintf(_("<%s> is missing its data"),"waypoint"));
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, strprintf(_("<%s> is missing its data"),"waypoint"));
continue;
}
-
+
waypoint_value_node=parse_value_node(dynamic_cast<xmlpp::Element*>(*iter),canvas);
-
+
/*
ValueBase data=parse_value(dynamic_cast<xmlpp::Element*>(*iter),canvas);
-
+
if(!data.is_valid())
{
error(child,_("Bad data for <waypoint>"));
error(child,_("Bad data for <waypoint>"));
continue;
}
-
+
/*! HACK -- This is a temporary fix to help repair some
** weirdness that is currently going on (10-21-2004).
** This short circuits the linking of waypoints,
** away with something like this pretty easily.
*/
waypoint_value_node=waypoint_value_node->clone();
-
+
// Warn if there is trash after the param value
for(iter++; iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter))
else
error(child,strprintf(_("\"%s\" not a valid value for attribute \"%s\" in <%s>"),val.c_str(),"before","waypoint"));
}
-
+
if(child->get_attribute("after"))
{
string val=child->get_attribute("after")->get_value();
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)
{
handle<LinkableValueNode> value_node;
ValueBase::Type type;
-
+
// Determine the type
if(element->get_attribute("type"))
{
}
value_node=LinkableValueNode::create(element->get_name(),type);
-
+
if(!value_node)
{
error(element,"Unknown ValueNode type "+element->get_name());
return 0;
- }
+ }
if(value_node->get_type()!=type)
{
error(element,"ValueNode did not accept type");
return 0;
- }
+ }
value_node->set_root_canvas(canvas->get_root());
if(element->get_attribute(value_node->link_name(i)))
try {
String id(element->get_attribute(value_node->link_name(i))->get_value());
-
+
if(!value_node->set_link(i,
canvas->surefind_value_node(
id
)
)
- ) error(element,strprintf(_("Unable to set link \"%s\" to ValueNode \"%s\" (link #%d in \"%s\")"),value_node->link_name(i).c_str(),id.c_str(),i,value_node->get_name().c_str()));
+ ) error(element,strprintf(_("Unable to set link \"%s\" to ValueNode \"%s\" (link #%d in \"%s\")"),value_node->link_name(i).c_str(),id.c_str(),i,value_node->get_name().c_str()));
}
catch(Exception::IDNotFound)
{
element->get_attribute(value_node->link_name(i))->get_value().c_str()));
throw;
}
- }
-
+ }
+
xmlpp::Element::NodeList list = element->get_children();
}
// \todo do a search for more elements and warn if they are found
-
+
}
catch(Exception::BadLinkName)
{
{
error(child,strprintf(_("<%s> has a bad value"),name.c_str()));
break;
- }
+ }
// \todo do a search for more elements and warn if they are found
break;
CanvasParser::parse_dynamic_list(xmlpp::Element *element,Canvas::Handle canvas)
{
assert(element->get_name()=="dynamic_list" || element->get_name()=="bline");
-
+
const float fps(canvas?canvas->rend_desc().get_frame_rate():0);
if(!element->get_attribute("type"))
else
bline_value_node->set_loop(false);
}
-
- }
+
+ }
else
value_node=ValueNode_DynamicList::create(type);
if(child->get_name()=="entry")
{
ValueNode_DynamicList::ListEntry list_entry;
-
+
// Parse begin/end waypoints
{
typedef synfig::ValueNode_DynamicList::ListEntry::Activepoint Activepoint;
String begin_sequence;
String end_sequence;
-
+
ActivepointList &timing_info(list_entry.timing_info);
-
+
if(child->get_attribute("begin"))
begin_sequence=child->get_attribute("begin")->get_value();
if(child->get_attribute("off"))
end_sequence=child->get_attribute("off")->get_value();
-
+
// clear out any auto-start
if(!begin_sequence.empty())
timing_info.clear();
-
+
//! \optimize
while(!begin_sequence.empty())
{
String::iterator iter(find(begin_sequence.begin(),begin_sequence.end(),','));
- String timecode(begin_sequence.begin(), iter);
+ String timecode(begin_sequence.begin(), iter);
int priority=0;
-
+
+ // skip whitespace before checking for a priority
+ while (isspace(timecode[0]))
+ timecode=timecode.substr(1);
+
// If there is a priority, then grab it and remove
// it from the timecode
if(timecode[0]=='p')
timecode=String(timecode.begin()+space+1,timecode.end());
//synfig::info("priority: %d timecode: %s",priority,timecode.c_str());
}
-
+
timing_info.push_back(
Activepoint(
Time(
priority
)
);
-
+
if(iter==begin_sequence.end())
begin_sequence.clear();
else
while(!end_sequence.empty())
{
String::iterator iter(find(end_sequence.begin(),end_sequence.end(),','));
- String timecode(end_sequence.begin(), iter);
+ String timecode(end_sequence.begin(), iter);
int priority=0;
-
+
+ // skip whitespace before checking for a priority
+ while (isspace(timecode[0]))
+ timecode=timecode.substr(1);
+
// If there is a priority, then grab it and remove
// it from the timecode
if(timecode[0]=='p')
timecode=String(timecode.begin()+space+1,timecode.end());
//synfig::info("priority: %d timecode: %s",priority,timecode.c_str());
}
-
+
timing_info.push_back(
Activepoint(
Time(
else
end_sequence=String(iter+1,end_sequence.end());
}
-
+
timing_info.sort();
}
if(child->get_attribute("use"))
{
+ // \todo does this need to be able to read 'use="canvas"', like waypoints can now? (see 'surefind_canvas' in this file)
string id=child->get_attribute("use")->get_value();
try
{
{
handle<ValueNode> value_node;
assert(element);
-
+
GUID guid;
-
+
if(element->get_attribute("guid"))
{
guid=GUID(element->get_attribute("guid")->get_value())^canvas->get_root()->get_guid();
if(value_node)
return value_node;
}
-
+
// If ValueBase::ident_type() recognises the name, then we know it's a ValueBase
if(element->get_name()!="canvas" && ValueBase::ident_type(element->get_name()))
- {
+ {
ValueBase data=parse_value(element,canvas);
if(!data.is_valid())
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()))
+ if(LinkableValueNode::book().count(element->get_name()))
value_node=parse_linkable_value_node(element,canvas);
else
if(element->get_name()=="canvas")
error(element, "Expected a ValueNode");
}
-
+
value_node->set_root_canvas(canvas->get_root());
-
-
+
+
// If we were successful, and our element has
// an ID attribute, go ahead and add it to the
// value_node list
catch(Exception::BadLinkName)
{
warning(element,strprintf(_("Bad ID \"%s\""),id.c_str()));
- return value_node;
+ return value_node;
}
catch(Exception::IDAlreadyExists)
{
Layer::Handle
CanvasParser::parse_layer(xmlpp::Element *element,Canvas::Handle canvas)
{
-
+
assert(element->get_name()=="layer");
Layer::Handle layer;
// Handle the description
if(element->get_attribute("desc"))
layer->set_description(element->get_attribute("desc")->get_value());
-
+
if(element->get_attribute("active"))
layer->set_active(element->get_attribute("active")->get_value()=="false"?false:true);
for(iter++; iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::Element*>(*iter))
warning((*iter),strprintf(_("Unexpected element <%s> after <param> data, ignoring..."),(*iter)->get_name().c_str()));
- continue;
+ continue;
}
else
error_unexpected_element(child,child->get_name());
Canvas::Handle
CanvasParser::parse_canvas(xmlpp::Element *element,Canvas::Handle parent,bool inline_, String filename)
{
-
+
if(element->get_name()!="canvas")
{
error_unexpected_element(element,element->get_name(),"canvas");
}
Canvas::Handle canvas;
-
-
+
+
if(parent && (element->get_attribute("id") || inline_))
{
if(inline_)
if(element->get_attribute("yres"))
canvas->rend_desc().set_y_res(atof(element->get_attribute("yres")->get_value().c_str()));
-
+
if(element->get_attribute("fps"))
canvas->rend_desc().set_frame_rate(atof(element->get_attribute("fps")->get_value().c_str()));
{
string values=element->get_attribute("bgcolor")->get_value();
Color bg;
-
+
bg.set_r(atof(string(values.data(),values.find(' ')).c_str()));
values=string(values.begin()+values.find(' ')+1,values.end());
-
+
bg.set_g(atof(string(values.data(),values.find(' ')).c_str()));
values=string(values.begin()+values.find(' ')+1,values.end());
-
+
bg.set_b(atof(string(values.data(),values.find(' ')).c_str()));
values=string(values.begin()+values.find(' ')+1,values.end());
-
+
bg.set_a(atof(values.c_str()));
canvas->rend_desc().set_bg_color(bg);
warning(child,_("Inline canvases cannot have metadata"));
continue;
}
-
+
String name,content;
-
+
if(!child->get_attribute("name"))
{
warning(child,_("<meta> must have a name"));
warning(child,_("<meta> must have content"));
continue;
}
-
+
canvas->set_meta_data(child->get_attribute("name")->get_value(),child->get_attribute("content")->get_value());
}
else if(child->get_name()=="name")
{
xmlpp::Element::NodeList list = child->get_children();
-
+
// If we don't have any name, warn
if(list.empty())
warning(child,_("blank \"name\" entitity"));
-
+
string tmp;
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::TextNode*>(*iter))tmp+=dynamic_cast<xmlpp::TextNode*>(*iter)->get_content();
else
if(child->get_name()=="desc")
{
-
+
xmlpp::Element::NodeList list = child->get_children();
-
+
// If we don't have any description, warn
if(list.empty())
warning(child,_("blank \"desc\" entitity"));
-
+
string tmp;
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::TextNode*>(*iter))tmp+=dynamic_cast<xmlpp::TextNode*>(*iter)->get_content();
else
if(child->get_name()=="author")
{
-
+
xmlpp::Element::NodeList list = child->get_children();
-
+
// If we don't have any description, warn
if(list.empty())
warning(child,_("blank \"author\" entitity"));
-
+
string tmp;
for(xmlpp::Element::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
if(dynamic_cast<xmlpp::TextNode*>(*iter))tmp+=dynamic_cast<xmlpp::TextNode*>(*iter)->get_content();
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;
const ValueNodeList& value_node_list(canvas->value_node_list());
-
+
again:
ValueNodeList::const_iterator iter;
for(iter=value_node_list.begin();iter!=value_node_list.end();++iter)
goto again;
}
}
-
+
return canvas;
}
}