Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode.cpp
index 44a1b43..d1e3256 100644 (file)
@@ -6,7 +6,8 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-**     Copyright (c) 2007 Chris Moore
+**     Copyright (c) 2007, 2008 Chris Moore
+**  Copyright (c) 2008 Carlos López
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
 #include "general.h"
 #include "canvas.h"
 #include "paramdesc.h"
+#include "releases.h"
 
 #include "valuenode_const.h"
 #include "valuenode_linear.h"
 #include "valuenode_composite.h"
 #include "valuenode_reference.h"
+#include "valuenode_greyed.h"
 #include "valuenode_scale.h"
 #include "valuenode_blinecalctangent.h"
 #include "valuenode_blinecalcvertex.h"
+#include "valuenode_blinecalcwidth.h"
 #include "valuenode_blinereversetangent.h"
 #include "valuenode_segcalctangent.h"
 #include "valuenode_segcalcvertex.h"
 #include "valuenode_reciprocal.h"
 #include "valuenode_duplicate.h"
 #include "valuenode_integer.h"
+#include "valuenode_step.h"
+#include "valuenode_vectorangle.h"
+#include "valuenode_vectorlength.h"
+#include "valuenode_vectorx.h"
+#include "valuenode_vectory.h"
+#include "valuenode_gradientcolor.h"
+#include "valuenode_dotproduct.h"
+#include "valuenode_timestring.h"
+#include "valuenode_realstring.h"
+#include "valuenode_join.h"
+#include "valuenode_anglestring.h"
+#include "valuenode_intstring.h"
+#include "valuenode_log.h"
+#include "valuenode_pow.h"
+#include "valuenode_compare.h"
+#include "valuenode_not.h"
+#include "valuenode_and.h"
+#include "valuenode_or.h"
 
 #include "layer.h"
 
@@ -104,45 +126,71 @@ ValueNode::subsys_init()
 {
        book_=new LinkableValueNode::Book();
 
-#define ADD_VALUENODE(class,name,local)                                                                                                                        \
+#define ADD_VALUENODE(class,name,local,version)                                                                                                        \
        (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create);            \
        (*book_)[name].check_type=&class::check_type;                                                                                           \
-       (*book_)[name].local_name=local
+       (*book_)[name].local_name=local;                                                                                                                        \
+       (*book_)[name].release_version=version
 
-#define ADD_VALUENODE2(class,name,local)                                                                                                               \
+#define ADD_VALUENODE2(class,name,local,version)                                                                                               \
        (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create_from);       \
        (*book_)[name].check_type=&class::check_type;                                                                                           \
-       (*book_)[name].local_name=local
-
-       ADD_VALUENODE(ValueNode_Linear,                 "linear",                       _("Linear")                             );
-       ADD_VALUENODE(ValueNode_Composite,              "composite",            _("Composite")                  );
-       ADD_VALUENODE(ValueNode_RadialComposite,"radial_composite",     _("Radial Composite")   );
-       ADD_VALUENODE(ValueNode_Reference,              "reference",            _("Reference")                  );
-       ADD_VALUENODE(ValueNode_Repeat_Gradient,"repeat_gradient",      _("Repeat Gradient")    );
-       ADD_VALUENODE(ValueNode_Scale,                  "scale",                        _("Scale")                              );
-       ADD_VALUENODE(ValueNode_BLineCalcTangent,"blinecalctangent",_("BLine Tangent")          );
-       ADD_VALUENODE(ValueNode_BLineCalcVertex,"blinecalcvertex",      _("BLine Vertex")               );
-       ADD_VALUENODE(ValueNode_BLineRevTangent,"blinerevtangent",      _("Reverse Tangent")    );
-       ADD_VALUENODE(ValueNode_SegCalcTangent, "segcalctangent",       _("Segment Tangent")    );
-       ADD_VALUENODE(ValueNode_SegCalcVertex,  "segcalcvertex",        _("Segment Vertex")             );
-       ADD_VALUENODE(ValueNode_Stripes,                "stripes",                      _("Stripes")                    );
-       ADD_VALUENODE(ValueNode_Range,                  "range",                        _("Range")                              );
-       ADD_VALUENODE(ValueNode_Add,                    "add",                          _("Add")                                );
-       ADD_VALUENODE(ValueNode_Subtract,               "subtract",                     _("Subtract")                   );
-       ADD_VALUENODE(ValueNode_TimedSwap,              "timed_swap",           _("Timed Swap")                 );
-       ADD_VALUENODE(ValueNode_TwoTone,                "twotone",                      _("Two-Tone")                   );
-       ADD_VALUENODE(ValueNode_BLine,                  "bline",                        _("BLine")                              );
-       ADD_VALUENODE2(ValueNode_DynamicList,   "dynamic_list",         _("Dynamic List")               );
-       ADD_VALUENODE(ValueNode_GradientRotate, "gradient_rotate",      _("Gradient Rotate")    );
-       ADD_VALUENODE(ValueNode_Sine,                   "sine",                         _("Sine")                               );
-       ADD_VALUENODE(ValueNode_Cos,                    "cos",                          _("Cos")                                );
-       ADD_VALUENODE(ValueNode_Atan2,                  "atan2",                        _("aTan2")                              );
-       ADD_VALUENODE(ValueNode_Exp,                    "exp",                          _("Exponential")                );
-       ADD_VALUENODE(ValueNode_Switch,                 "switch",                       _("Switch")                             );
-       ADD_VALUENODE(ValueNode_TimeLoop,               "timeloop",                     _("Time Loop")                  );
-       ADD_VALUENODE(ValueNode_Reciprocal,             "reciprocal",           _("Reciprocal")                 );
-       ADD_VALUENODE(ValueNode_Duplicate,              "duplicate",            _("Duplicate")                  );
-       ADD_VALUENODE(ValueNode_Integer,                "fromint",                      _("From Integer")               );
+       (*book_)[name].local_name=local;                                                                                                                        \
+       (*book_)[name].release_version=version
+
+       ADD_VALUENODE(ValueNode_Linear,                   "linear",                       _("Linear"),                   RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Composite,                "composite",            _("Composite"),                RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_RadialComposite,  "radial_composite", _("Radial Composite"), RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Reference,                "reference",            _("Reference"),                RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Scale,                    "scale",                        _("Scale"),                    RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_SegCalcTangent,   "segcalctangent",       _("Segment Tangent"),  RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_SegCalcVertex,    "segcalcvertex",        _("Segment Vertex"),   RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Stripes,                  "stripes",              _("Stripes"),                  RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Subtract,                 "subtract",             _("Subtract"),                 RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_TwoTone,                  "twotone",              _("Two-Tone"),                 RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_BLine,                    "bline",                        _("BLine"),                    RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE2(ValueNode_DynamicList,     "dynamic_list",         _("Dynamic List"),     RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_GradientRotate,   "gradient_rotate",  _("Gradient Rotate"),      RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Sine,                     "sine",                         _("Sine"),                     RELEASE_VERSION_0_61_06);
+
+       ADD_VALUENODE(ValueNode_TimedSwap,                "timed_swap",           _("Timed Swap"),               RELEASE_VERSION_0_61_07); // SVN r610
+       ADD_VALUENODE(ValueNode_Repeat_Gradient,  "repeat_gradient",  _("Repeat Gradient"),      RELEASE_VERSION_0_61_07); // SVN r666
+       ADD_VALUENODE(ValueNode_Exp,                      "exp",                          _("Exponential"),              RELEASE_VERSION_0_61_07); // SVN r739
+       ADD_VALUENODE(ValueNode_Add,                      "add",                          _("Add"),                              RELEASE_VERSION_0_61_07); // SVN r742
+       ADD_VALUENODE(ValueNode_BLineCalcTangent, "blinecalctangent", _("BLine Tangent"),        RELEASE_VERSION_0_61_07); // SVN r744
+       ADD_VALUENODE(ValueNode_BLineCalcVertex,  "blinecalcvertex",  _("BLine Vertex"),         RELEASE_VERSION_0_61_07); // SVN r744
+       ADD_VALUENODE(ValueNode_Range,                    "range",                        _("Range"),                    RELEASE_VERSION_0_61_07); // SVN r776
+
+       ADD_VALUENODE(ValueNode_Switch,                   "switch",                       _("Switch"),                   RELEASE_VERSION_0_61_08); // SVN r923
+       ADD_VALUENODE(ValueNode_Cos,                      "cos",                          _("Cos"),                              RELEASE_VERSION_0_61_08); // SVN r1111
+       ADD_VALUENODE(ValueNode_Atan2,                    "atan2",                        _("aTan2"),                    RELEASE_VERSION_0_61_08); // SVN r1132
+       ADD_VALUENODE(ValueNode_BLineRevTangent,  "blinerevtangent",  _("Reverse Tangent"),      RELEASE_VERSION_0_61_08); // SVN r1162
+       ADD_VALUENODE(ValueNode_TimeLoop,                 "timeloop",             _("Time Loop"),                RELEASE_VERSION_0_61_08); // SVN r1226
+       ADD_VALUENODE(ValueNode_Reciprocal,               "reciprocal",           _("Reciprocal"),               RELEASE_VERSION_0_61_08); // SVN r1238
+       ADD_VALUENODE(ValueNode_Duplicate,                "duplicate",            _("Duplicate"),                RELEASE_VERSION_0_61_08); // SVN r1267
+       ADD_VALUENODE(ValueNode_Integer,                  "fromint",              _("From Integer"),     RELEASE_VERSION_0_61_08); // SVN r1267
+       ADD_VALUENODE(ValueNode_Step,                     "step",                         _("Step"),                     RELEASE_VERSION_0_61_08); // SVN r1691
+       ADD_VALUENODE(ValueNode_BLineCalcWidth,   "blinecalcwidth",       _("BLine Width"),              RELEASE_VERSION_0_61_08); // SVN r1694
+
+       ADD_VALUENODE(ValueNode_VectorAngle,      "vectorangle",          _("Vector Angle"),     RELEASE_VERSION_0_61_09); // SVN r1880
+       ADD_VALUENODE(ValueNode_VectorLength,     "vectorlength",         _("Vector Length"),    RELEASE_VERSION_0_61_09); // SVN r1881
+       ADD_VALUENODE(ValueNode_VectorX,                  "vectorx",              _("Vector X"),                 RELEASE_VERSION_0_61_09); // SVN r1882
+       ADD_VALUENODE(ValueNode_VectorY,                  "vectory",              _("Vector Y"),                 RELEASE_VERSION_0_61_09); // SVN r1882
+       ADD_VALUENODE(ValueNode_GradientColor,    "gradientcolor",        _("Gradient Color"),   RELEASE_VERSION_0_61_09); // SVN r1885
+       ADD_VALUENODE(ValueNode_DotProduct,               "dotproduct",           _("Dot Product"),              RELEASE_VERSION_0_61_09); // SVN r1891
+       ADD_VALUENODE(ValueNode_TimeString,               "timestring",           _("Time String"),              RELEASE_VERSION_0_61_09); // SVN r2000
+       ADD_VALUENODE(ValueNode_RealString,               "realstring",           _("Real String"),              RELEASE_VERSION_0_61_09); // SVN r2003
+       ADD_VALUENODE(ValueNode_Join,                     "join",                         _("Joined List"),              RELEASE_VERSION_0_61_09); // SVN r2007
+       ADD_VALUENODE(ValueNode_AngleString,      "anglestring",          _("Angle String"),     RELEASE_VERSION_0_61_09); // SVN r2010
+       ADD_VALUENODE(ValueNode_IntString,                "intstring",            _("Int String"),               RELEASE_VERSION_0_61_09); // SVN r2010
+       ADD_VALUENODE(ValueNode_Logarithm,                "logarithm",            _("Logarithm"),                RELEASE_VERSION_0_61_09); // SVN r2034
+
+       ADD_VALUENODE(ValueNode_Greyed,                   "greyed",                       _("Greyed"),                   RELEASE_VERSION_0_61_10); // SVN r2305
+       ADD_VALUENODE(ValueNode_Pow,                  "power",                _("Power"),                    RELEASE_VERSION_0_61_10); // SVN r2362
+       ADD_VALUENODE(ValueNode_Compare,                  "compare",              _("Compare"),                  RELEASE_VERSION_0_61_10); // SVN r2364
+       ADD_VALUENODE(ValueNode_Not,                  "not",                      _("Not"),                              RELEASE_VERSION_0_61_10); // SVN r2364
+       ADD_VALUENODE(ValueNode_And,                  "and",                      _("And"),                              RELEASE_VERSION_0_61_10); // SVN r2364
+       ADD_VALUENODE(ValueNode_Or,                       "or",                   _("Or"),                                       RELEASE_VERSION_0_61_10); // SVN r2364
 
 #undef ADD_VALUENODE
 #undef ADD_VALUENODE2
@@ -231,8 +279,23 @@ LinkableValueNode::set_link(int i,ValueNode::Handle x)
 
        if(set_link_vfunc(i,x))
        {
+               // Fix 2412072: remove the previous link from the parent_set unless one of the other links is also
+               // using it when we convert a value to 'switch', both 'on' and 'off' are linked to the same valuenode
+               // if we then disconnect one of the two, the one we disconnect is set to be a new valuenode_const
+               // and the previously shared value is removed from the parent set even though the other is still
+               // using it
                if(previous)
-                       remove_child(previous.get());
+               {
+                       int size = link_count(), index;
+                       for (index=0; index < size; ++index)
+                       {
+                               if (i == index) continue;
+                               if (get_link(index) == previous)
+                                       break;
+                       }
+                       if (index == size)
+                               remove_child(previous.get());
+               }
                add_child(x.get());
 
                if(!x->is_exported() && get_parent_canvas())
@@ -506,12 +569,11 @@ PlaceholderValueNode::PlaceholderValueNode(ValueBase::Type type):
 ValueNode*
 LinkableValueNode::clone(const GUID& deriv_guid)const
 {
-       // printf("%s:%d clone()\n", __FILE__, __LINE__);
-       { ValueNode* x(find_value_node(get_guid()^deriv_guid).get()); if(x)
-                                                                                                                                 {
-                                                                                                                                         printf("VALUENODE FOUND VALUENODE\n");
-                                                                                                                                         return x;
-                                                                                                                                 }}
+       {
+               ValueNode* x(find_value_node(get_guid()^deriv_guid).get());
+               if(x)
+                       return x;
+       }
 
        int i;
        LinkableValueNode *ret=create_new();