Merge branch 'genete_static_values'
[synfig.git] / synfig-core / src / synfig / savecanvas.cpp
index a2ae0d9..34f3fbd 100644 (file)
 #include "savecanvas.h"
 #include "general.h"
 #include "valuenode.h"
-#include "valuenode_subtract.h"
 #include "valuenode_animated.h"
-#include "valuenode_composite.h"
 #include "valuenode_const.h"
-#include "valuenode_linear.h"
 #include "valuenode_dynamiclist.h"
 #include "valuenode_reference.h"
-#include "valuenode_segcalctangent.h"
-#include "valuenode_segcalcvertex.h"
 #include "valuenode_bline.h"
 #include "time.h"
 #include "keyframe.h"
@@ -96,75 +91,90 @@ xmlpp::Element* encode_keyframe(xmlpp::Element* root,const Keyframe &kf, float f
        return root;
 }
 
+xmlpp::Element* encode_static(xmlpp::Element* root,bool s)
+{
+       if(s)
+               root->set_attribute("static", s?"true":"false");
+       return root;
+}
+
 
-xmlpp::Element* encode_real(xmlpp::Element* root,Real v)
+xmlpp::Element* encode_real(xmlpp::Element* root,Real v,bool s=false)
 {
        root->set_name("real");
-       root->set_attribute("value",strprintf(VECTOR_VALUE_TYPE_FORMAT,v));
+       root->set_attribute("value",strprintf(VECTOR_VALUE_TYPE_FORMAT,v));
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_time(xmlpp::Element* root,Time t, float /*fps*/=0)
+xmlpp::Element* encode_time(xmlpp::Element* root,Time t,bool s=false)
 {
        root->set_name("time");
-       //root->set_attribute("value",t.get_string(fps));
-       root->set_attribute("value",t.get_string());
+       root->set_attribute("value",t.get_string());
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_integer(xmlpp::Element* root,int i)
+xmlpp::Element* encode_integer(xmlpp::Element* root,int i,bool s=false)
 {
        root->set_name("integer");
        root->set_attribute("value",strprintf("%i",i));
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_bool(xmlpp::Element* root,bool b)
+xmlpp::Element* encode_bool(xmlpp::Element* root, bool b,bool s=false)
 {
        root->set_name("bool");
        root->set_attribute("value",b?"true":"false");
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_string(xmlpp::Element* root,const String &str)
+xmlpp::Element* encode_string(xmlpp::Element* root,const String &str,bool s=false)
 {
        root->set_name("string");
        root->set_child_text(str);
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_vector(xmlpp::Element* root,Vector vect)
+xmlpp::Element* encode_vector(xmlpp::Element* root,Vector vect,bool s=false)
 {
        root->set_name("vector");
        root->add_child("x")->set_child_text(strprintf(VECTOR_VALUE_TYPE_FORMAT,(float)vect[0]));
        root->add_child("y")->set_child_text(strprintf(VECTOR_VALUE_TYPE_FORMAT,(float)vect[1]));
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_color(xmlpp::Element* root,Color color)
+xmlpp::Element* encode_color(xmlpp::Element* root,Color color,bool s=false)
 {
        root->set_name("color");
        root->add_child("r")->set_child_text(strprintf(COLOR_VALUE_TYPE_FORMAT,(float)color.get_r()));
        root->add_child("g")->set_child_text(strprintf(COLOR_VALUE_TYPE_FORMAT,(float)color.get_g()));
        root->add_child("b")->set_child_text(strprintf(COLOR_VALUE_TYPE_FORMAT,(float)color.get_b()));
        root->add_child("a")->set_child_text(strprintf(COLOR_VALUE_TYPE_FORMAT,(float)color.get_a()));
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_angle(xmlpp::Element* root,Angle theta)
+xmlpp::Element* encode_angle(xmlpp::Element* root,Angle theta,bool s=false)
 {
        root->set_name("angle");
        root->set_attribute("value",strprintf("%f",(float)Angle::deg(theta).get()));
+       encode_static(root, s);
        return root;
 }
 
-xmlpp::Element* encode_segment(xmlpp::Element* root,Segment seg)
+xmlpp::Element* encode_segment(xmlpp::Element* root,Segment seg,bool s=false)
 {
        root->set_name("segment");
        encode_vector(root->add_child("p1")->add_child("vector"),seg.p1);
        encode_vector(root->add_child("t1")->add_child("vector"),seg.t1);
        encode_vector(root->add_child("p2")->add_child("vector"),seg.p2);
        encode_vector(root->add_child("t2")->add_child("vector"),seg.t2);
+       encode_static(root, s);
        return root;
 }
 
@@ -183,10 +193,10 @@ xmlpp::Element* encode_bline_point(xmlpp::Element* root,BLinePoint bline_point)
        return root;
 }
 
-xmlpp::Element* encode_gradient(xmlpp::Element* root,Gradient x)
+xmlpp::Element* encode_gradient(xmlpp::Element* root,Gradient x,bool s=false)
 {
        root->set_name("gradient");
-
+       encode_static(root, s);
        Gradient::const_iterator iter;
        x.sort();
        for(iter=x.begin();iter!=x.end();iter++)
@@ -218,30 +228,27 @@ xmlpp::Element* encode_value(xmlpp::Element* root,const ValueBase &data,Canvas::
        switch(data.get_type())
        {
        case ValueBase::TYPE_REAL:
-               return encode_real(root,data.get(Real()));
+               return encode_real(root,data.get(Real()), data.get_static());
        case ValueBase::TYPE_TIME:
-               if(canvas)
-                       return encode_time(root,data.get(Time()),canvas->rend_desc().get_frame_rate());
-               else
-                       return encode_time(root,data.get(Time()));
+               return encode_time(root,data.get(Time()), data.get_static());
        case ValueBase::TYPE_INTEGER:
-               return encode_integer(root,data.get(int()));
+               return encode_integer(root,data.get(int()), data.get_static());
        case ValueBase::TYPE_COLOR:
-               return encode_color(root,data.get(Color()));
+               return encode_color(root,data.get(Color()), data.get_static());
        case ValueBase::TYPE_VECTOR:
-               return encode_vector(root,data.get(Vector()));
+               return encode_vector(root,data.get(Vector()), data.get_static());
        case ValueBase::TYPE_ANGLE:
-               return encode_angle(root,data.get(Angle()));
+               return encode_angle(root,data.get(Angle()), data.get_static());
        case ValueBase::TYPE_BOOL:
-               return encode_bool(root,data.get(bool()));
+               return encode_bool(root,data.get(bool()), data.get_static());
        case ValueBase::TYPE_STRING:
-               return encode_string(root,data.get(String()));
+               return encode_string(root,data.get(String()), data.get_static());
        case ValueBase::TYPE_SEGMENT:
-               return encode_segment(root,data.get(Segment()));
+               return encode_segment(root,data.get(Segment()), data.get_static());
        case ValueBase::TYPE_BLINEPOINT:
                return encode_bline_point(root,data.get(BLinePoint()));
        case ValueBase::TYPE_GRADIENT:
-               return encode_gradient(root,data.get(Gradient()));
+               return encode_gradient(root,data.get(Gradient()), data.get_static());
        case ValueBase::TYPE_LIST:
                return encode_list(root,data,canvas);
        case ValueBase::TYPE_CANVAS:
@@ -270,10 +277,8 @@ xmlpp::Element* encode_animated(xmlpp::Element* root,ValueNode_Animated::ConstHa
        for(iter=waypoint_list.begin();iter!=waypoint_list.end();++iter)
        {
                xmlpp::Element *waypoint_node=root->add_child("waypoint");
-               //waypoint_node->set_attribute("time",iter->get_time().get_string(canvas->rend_desc().get_frame_rate()));
                waypoint_node->set_attribute("time",iter->get_time().get_string());
 
-               //waypoint_node->add_child(encode_value(iter->get_value(),canvas));
                if(iter->get_value_node()->is_exported())
                        waypoint_node->set_attribute("use",iter->get_value_node()->get_relative_id(canvas));
                else {
@@ -345,44 +350,6 @@ xmlpp::Element* encode_animated(xmlpp::Element* root,ValueNode_Animated::ConstHa
        return root;
 }
 
-xmlpp::Element* encode_subtract(xmlpp::Element* root,ValueNode_Subtract::ConstHandle value_node,Canvas::ConstHandle canvas=0)
-{
-       assert(value_node);
-       root->set_name("subtract");
-
-       ValueNode::ConstHandle lhs=value_node->get_lhs();
-       ValueNode::ConstHandle rhs=value_node->get_rhs();
-       ValueNode::ConstHandle scalar=value_node->get_scalar();
-
-       assert(lhs);
-       assert(rhs);
-
-       root->set_attribute("type",ValueBase::type_name(value_node->get_type()));
-
-       if(lhs==rhs)
-               warning("LHS is equal to RHS, this <subtract> will always be zero!");
-
-       //if(value_node->get_scalar()!=1)
-       //      root->set_attribute("scalar",strprintf(VECTOR_VALUE_TYPE_FORMAT,value_node->get_scalar()));
-
-       if(!scalar->get_id().empty())
-               root->set_attribute("scalar",scalar->get_relative_id(canvas));
-       else
-               encode_value_node(root->add_child("scalar")->add_child("value_node"),scalar,canvas);
-
-       if(!lhs->get_id().empty())
-               root->set_attribute("lhs",lhs->get_relative_id(canvas));
-       else
-               encode_value_node(root->add_child("lhs")->add_child("value_node"),lhs,canvas);
-
-       if(!rhs->get_id().empty())
-               root->set_attribute("rhs",rhs->get_relative_id(canvas));
-       else
-               encode_value_node(root->add_child("rhs")->add_child("value_node"),rhs,canvas);
-
-       return root;
-}
-
 xmlpp::Element* encode_dynamic_list(xmlpp::Element* root,ValueNode_DynamicList::ConstHandle value_node,Canvas::ConstHandle canvas=0)
 {
        assert(value_node);
@@ -480,9 +447,6 @@ xmlpp::Element* encode_linkable_value_node(xmlpp::Element* root,LinkableValueNod
                ValueBase value((*value_node)(0));
                encode_value(root,value,canvas);
 
-               // ValueNode_Const::ConstHandle const_value(ValueNode_Const::create((*value_node)(0)));
-               // encode_value_node(root,const_value,canvas);
-
                return root;
        }
 
@@ -512,9 +476,6 @@ xmlpp::Element* encode_value_node(xmlpp::Element* root,ValueNode::ConstHandle va
        if(ValueNode_Animated::ConstHandle::cast_dynamic(value_node))
                encode_animated(root,ValueNode_Animated::ConstHandle::cast_dynamic(value_node),canvas);
        else
-       if(ValueNode_Subtract::ConstHandle::cast_dynamic(value_node))
-               encode_subtract(root,ValueNode_Subtract::ConstHandle::cast_dynamic(value_node),canvas);
-       else
        if(ValueNode_DynamicList::ConstHandle::cast_dynamic(value_node))
                encode_dynamic_list(root,ValueNode_DynamicList::ConstHandle::cast_dynamic(value_node),canvas);
        else if(ValueNode_Const::ConstHandle::cast_dynamic(value_node))
@@ -607,6 +568,8 @@ xmlpp::Element* encode_layer(xmlpp::Element* root,Layer::ConstHandle layer)
                                        xmlpp::Element *node=root->add_child("param");
                                        node->set_attribute("name",iter->get_name());
                                        node->set_attribute("use",child->get_relative_id(layer->get_canvas()));
+                                       if(value.get_static())
+                                               node->set_attribute("static", value.get_static()?"true":"false");
                                        continue;
                                }
                        }
@@ -697,7 +660,11 @@ xmlpp::Element* encode_canvas(xmlpp::Element* root,Canvas::ConstHandle canvas)
        }
 
        // Output the <defs> section
-       //! \todo check where the parentheses should really go - around the && or the ||?
+       //! Check where the parentheses should really go - around the && or the ||?
+       //! If children is not empty (there are exported canvases in the current canvas)
+       //! they must be listed in the defs section regardless the result of check the
+       //! Value Node list (exported value nodes in the canvas) and if the canvas is
+       //! in line or not. Inline canvases cannot have exported canvases inside.
        if((!canvas->is_inline() && !canvas->value_node_list().empty()) || !canvas->children().empty())
        {
                xmlpp::Element *node=root->add_child("defs");