Apply patch #18: Valuenode Type Power. Thanks to nikitakit.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode.cpp
3 **      \brief Implementation of the "Placeholder" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **  Copyright (c) 2008 Carlos López
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #define SYNFIG_NO_ANGLE
28
29 //#define HAS_HASH_MAP 1
30
31 #ifdef USING_PCH
32 #       include "pch.h"
33 #else
34 #ifdef HAVE_CONFIG_H
35 #       include <config.h>
36 #endif
37
38 #include "valuenode.h"
39 #include "general.h"
40 #include "canvas.h"
41 #include "paramdesc.h"
42 #include "releases.h"
43
44 #include "valuenode_const.h"
45 #include "valuenode_linear.h"
46 #include "valuenode_composite.h"
47 #include "valuenode_reference.h"
48 #include "valuenode_greyed.h"
49 #include "valuenode_scale.h"
50 #include "valuenode_blinecalctangent.h"
51 #include "valuenode_blinecalcvertex.h"
52 #include "valuenode_blinecalcwidth.h"
53 #include "valuenode_blinereversetangent.h"
54 #include "valuenode_segcalctangent.h"
55 #include "valuenode_segcalcvertex.h"
56 #include "valuenode_repeat_gradient.h"
57 #include "valuenode_stripes.h"
58 #include "valuenode_range.h"
59 #include "valuenode_add.h"
60 #include "valuenode_subtract.h"
61 #include "valuenode_timedswap.h"
62 #include "valuenode_twotone.h"
63 #include "valuenode_bline.h"
64 #include "valuenode_dynamiclist.h"
65 #include "valuenode_radialcomposite.h"
66 #include "valuenode_gradientrotate.h"
67 #include "valuenode_sine.h"
68 #include "valuenode_cos.h"
69 #include "valuenode_atan2.h"
70 #include "valuenode_exp.h"
71 #include "valuenode_switch.h"
72 #include "valuenode_timeloop.h"
73 #include "valuenode_reciprocal.h"
74 #include "valuenode_duplicate.h"
75 #include "valuenode_integer.h"
76 #include "valuenode_step.h"
77 #include "valuenode_vectorangle.h"
78 #include "valuenode_vectorlength.h"
79 #include "valuenode_vectorx.h"
80 #include "valuenode_vectory.h"
81 #include "valuenode_gradientcolor.h"
82 #include "valuenode_dotproduct.h"
83 #include "valuenode_timestring.h"
84 #include "valuenode_realstring.h"
85 #include "valuenode_join.h"
86 #include "valuenode_anglestring.h"
87 #include "valuenode_intstring.h"
88 #include "valuenode_log.h"
89 #include "valuenode_pow.h"
90
91 #include "layer.h"
92
93 #endif
94
95 /* === U S I N G =========================================================== */
96
97 using namespace std;
98 using namespace etl;
99 using namespace synfig;
100
101 /* === M A C R O S ========================================================= */
102
103 /* === G L O B A L S ======================================================= */
104
105 static int value_node_count(0);
106
107 static LinkableValueNode::Book *book_;
108
109
110 ValueNode::LooseHandle
111 synfig::find_value_node(const GUID& guid)
112 {
113         return guid_cast<ValueNode>(guid);
114 }
115
116 /* === P R O C E D U R E S ================================================= */
117
118 /* === M E T H O D S ======================================================= */
119
120 bool
121 ValueNode::subsys_init()
122 {
123         book_=new LinkableValueNode::Book();
124
125 #define ADD_VALUENODE(class,name,local,version)                                                                                                 \
126         (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create);            \
127         (*book_)[name].check_type=&class::check_type;                                                                                           \
128         (*book_)[name].local_name=local;                                                                                                                        \
129         (*book_)[name].release_version=version
130
131 #define ADD_VALUENODE2(class,name,local,version)                                                                                                \
132         (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create_from);       \
133         (*book_)[name].check_type=&class::check_type;                                                                                           \
134         (*book_)[name].local_name=local;                                                                                                                        \
135         (*book_)[name].release_version=version
136
137         ADD_VALUENODE(ValueNode_Linear,                   "linear",                       _("Linear"),                   RELEASE_VERSION_0_61_06);
138         ADD_VALUENODE(ValueNode_Composite,                "composite",            _("Composite"),                RELEASE_VERSION_0_61_06);
139         ADD_VALUENODE(ValueNode_RadialComposite,  "radial_composite", _("Radial Composite"), RELEASE_VERSION_0_61_06);
140         ADD_VALUENODE(ValueNode_Reference,                "reference",            _("Reference"),                RELEASE_VERSION_0_61_06);
141         ADD_VALUENODE(ValueNode_Scale,                    "scale",                        _("Scale"),                    RELEASE_VERSION_0_61_06);
142         ADD_VALUENODE(ValueNode_SegCalcTangent,   "segcalctangent",       _("Segment Tangent"),  RELEASE_VERSION_0_61_06);
143         ADD_VALUENODE(ValueNode_SegCalcVertex,    "segcalcvertex",        _("Segment Vertex"),   RELEASE_VERSION_0_61_06);
144         ADD_VALUENODE(ValueNode_Stripes,                  "stripes",              _("Stripes"),                  RELEASE_VERSION_0_61_06);
145         ADD_VALUENODE(ValueNode_Subtract,                 "subtract",             _("Subtract"),                 RELEASE_VERSION_0_61_06);
146         ADD_VALUENODE(ValueNode_TwoTone,                  "twotone",              _("Two-Tone"),                 RELEASE_VERSION_0_61_06);
147         ADD_VALUENODE(ValueNode_BLine,                    "bline",                        _("BLine"),                    RELEASE_VERSION_0_61_06);
148         ADD_VALUENODE2(ValueNode_DynamicList,     "dynamic_list",         _("Dynamic List"),     RELEASE_VERSION_0_61_06);
149         ADD_VALUENODE(ValueNode_GradientRotate,   "gradient_rotate",  _("Gradient Rotate"),      RELEASE_VERSION_0_61_06);
150         ADD_VALUENODE(ValueNode_Sine,                     "sine",                         _("Sine"),                     RELEASE_VERSION_0_61_06);
151
152         ADD_VALUENODE(ValueNode_TimedSwap,                "timed_swap",           _("Timed Swap"),               RELEASE_VERSION_0_61_07); // SVN r610
153         ADD_VALUENODE(ValueNode_Repeat_Gradient,  "repeat_gradient",  _("Repeat Gradient"),      RELEASE_VERSION_0_61_07); // SVN r666
154         ADD_VALUENODE(ValueNode_Exp,                      "exp",                          _("Exponential"),              RELEASE_VERSION_0_61_07); // SVN r739
155         ADD_VALUENODE(ValueNode_Add,                      "add",                          _("Add"),                              RELEASE_VERSION_0_61_07); // SVN r742
156         ADD_VALUENODE(ValueNode_BLineCalcTangent, "blinecalctangent", _("BLine Tangent"),        RELEASE_VERSION_0_61_07); // SVN r744
157         ADD_VALUENODE(ValueNode_BLineCalcVertex,  "blinecalcvertex",  _("BLine Vertex"),         RELEASE_VERSION_0_61_07); // SVN r744
158         ADD_VALUENODE(ValueNode_Range,                    "range",                        _("Range"),                    RELEASE_VERSION_0_61_07); // SVN r776
159
160         ADD_VALUENODE(ValueNode_Switch,                   "switch",                       _("Switch"),                   RELEASE_VERSION_0_61_08); // SVN r923
161         ADD_VALUENODE(ValueNode_Cos,                      "cos",                          _("Cos"),                              RELEASE_VERSION_0_61_08); // SVN r1111
162         ADD_VALUENODE(ValueNode_Atan2,                    "atan2",                        _("aTan2"),                    RELEASE_VERSION_0_61_08); // SVN r1132
163         ADD_VALUENODE(ValueNode_BLineRevTangent,  "blinerevtangent",  _("Reverse Tangent"),      RELEASE_VERSION_0_61_08); // SVN r1162
164         ADD_VALUENODE(ValueNode_TimeLoop,                 "timeloop",             _("Time Loop"),                RELEASE_VERSION_0_61_08); // SVN r1226
165         ADD_VALUENODE(ValueNode_Reciprocal,               "reciprocal",           _("Reciprocal"),               RELEASE_VERSION_0_61_08); // SVN r1238
166         ADD_VALUENODE(ValueNode_Duplicate,                "duplicate",            _("Duplicate"),                RELEASE_VERSION_0_61_08); // SVN r1267
167         ADD_VALUENODE(ValueNode_Integer,                  "fromint",              _("From Integer"),     RELEASE_VERSION_0_61_08); // SVN r1267
168         ADD_VALUENODE(ValueNode_Step,                     "step",                         _("Step"),                     RELEASE_VERSION_0_61_08); // SVN r1691
169         ADD_VALUENODE(ValueNode_BLineCalcWidth,   "blinecalcwidth",       _("BLine Width"),              RELEASE_VERSION_0_61_08); // SVN r1694
170
171         ADD_VALUENODE(ValueNode_VectorAngle,      "vectorangle",          _("Vector Angle"),     RELEASE_VERSION_0_61_09); // SVN r1880
172         ADD_VALUENODE(ValueNode_VectorLength,     "vectorlength",         _("Vector Length"),    RELEASE_VERSION_0_61_09); // SVN r1881
173         ADD_VALUENODE(ValueNode_VectorX,                  "vectorx",              _("Vector X"),                 RELEASE_VERSION_0_61_09); // SVN r1882
174         ADD_VALUENODE(ValueNode_VectorY,                  "vectory",              _("Vector Y"),                 RELEASE_VERSION_0_61_09); // SVN r1882
175         ADD_VALUENODE(ValueNode_GradientColor,    "gradientcolor",        _("Gradient Color"),   RELEASE_VERSION_0_61_09); // SVN r1885
176         ADD_VALUENODE(ValueNode_DotProduct,               "dotproduct",           _("Dot Product"),              RELEASE_VERSION_0_61_09); // SVN r1891
177         ADD_VALUENODE(ValueNode_TimeString,               "timestring",           _("Time String"),              RELEASE_VERSION_0_61_09); // SVN r2000
178         ADD_VALUENODE(ValueNode_RealString,               "realstring",           _("Real String"),              RELEASE_VERSION_0_61_09); // SVN r2003
179         ADD_VALUENODE(ValueNode_Join,                     "join",                         _("Joined List"),              RELEASE_VERSION_0_61_09); // SVN r2007
180         ADD_VALUENODE(ValueNode_AngleString,      "anglestring",          _("Angle String"),     RELEASE_VERSION_0_61_09); // SVN r2010
181         ADD_VALUENODE(ValueNode_IntString,                "intstring",            _("Int String"),               RELEASE_VERSION_0_61_09); // SVN r2010
182         ADD_VALUENODE(ValueNode_Logarithm,                "logarithm",            _("Logarithm"),                RELEASE_VERSION_0_61_09); // SVN r2034
183
184         ADD_VALUENODE(ValueNode_Greyed,                   "greyed",                       _("Greyed"),                   RELEASE_VERSION_0_61_10); // SVN r2305
185         ADD_VALUENODE(ValueNode_Pow,              "power",                _("Power"),            RELEASE_VERSION_0_61_09); // SVN r2362
186
187 #undef ADD_VALUENODE
188 #undef ADD_VALUENODE2
189
190         return true;
191 }
192
193 bool
194 ValueNode::subsys_stop()
195 {
196         delete book_;
197 /*      if(global_value_node_map.size() || value_node_count)
198         {
199                 if(value_node_count)
200                         synfig::error("%d ValueNodes haven't been destroyed yet!",value_node_count);
201
202                 if(global_value_node_map.size()!=value_node_count)
203                         synfig::error("value node count mismatch! map.size()!=value_node_count (%d!=%d)",global_value_node_map.size(),value_node_count);
204
205                 GlobalValueNodeMap::iterator iter;
206                 for(iter=global_value_node_map.begin();iter!=global_value_node_map.end();++iter)
207                 {
208                         if(!iter->second->is_exported())
209                                 synfig::info(_("%s: count:%d name:%s type:%s"),
210                                         iter->first.get_string().c_str(),
211                                         iter->second->count(),
212                                         iter->second->get_name().c_str(),
213                                         ValueBase::type_local_name(iter->second->get_type()).c_str()
214                                 );
215                         else
216                                 synfig::info(_("%s: id:%s count:%d name:%s type:%s"),
217                                         iter->first.get_string().c_str(),
218                                         iter->second->get_id().c_str(),
219                                         iter->second->count(),
220                                         iter->second->get_name().c_str(),
221                                         ValueBase::type_local_name(iter->second->get_type()).c_str()
222                                 );
223                 }
224         }
225 */
226         return true;
227 }
228
229 ValueNode::ValueNode(ValueBase::Type type):type(type)
230 {
231         value_node_count++;
232 }
233
234 LinkableValueNode::Book&
235 LinkableValueNode::book()
236 {
237         return *book_;
238 }
239
240 LinkableValueNode::Handle
241 LinkableValueNode::create(const String &name, const ValueBase& x)
242 {
243         if(!book().count(name))
244                 return 0;
245
246         if (!check_type(name, x.get_type()) &&
247                 // the Duplicate ValueNode is an exception - we don't want the
248                 // user creating it for themselves, so check_type() fails for
249                 // it even when it is valid
250                 !(name == "duplicate" && x.get_type() == ValueBase::TYPE_REAL))
251         {
252                 error(_("Bad type: ValueNode '%s' doesn't accept type '%s'"), book()[name].local_name.c_str(), ValueBase::type_local_name(x.get_type()).c_str());
253                 return 0;
254         }
255
256         return book()[name].factory(x);
257 }
258
259 bool
260 LinkableValueNode::check_type(const String &name, ValueBase::Type x)
261 {
262         if(!book().count(name) || !book()[name].check_type)
263                 return false;
264         return book()[name].check_type(x);
265 }
266
267 bool
268 LinkableValueNode::set_link(int i,ValueNode::Handle x)
269 {
270         ValueNode::Handle previous(get_link(i));
271
272         if(set_link_vfunc(i,x))
273         {
274                 // Fix 2412072: remove the previous link from the parent_set unless one of the other links is also
275                 // using it when we convert a value to 'switch', both 'on' and 'off' are linked to the same valuenode
276                 // if we then disconnect one of the two, the one we disconnect is set to be a new valuenode_const
277                 // and the previously shared value is removed from the parent set even though the other is still
278                 // using it
279                 if(previous)
280                 {
281                         int size = link_count(), index;
282                         for (index=0; index < size; ++index)
283                         {
284                                 if (i == index) continue;
285                                 if (get_link(index) == previous)
286                                         break;
287                         }
288                         if (index == size)
289                                 remove_child(previous.get());
290                 }
291                 add_child(x.get());
292
293                 if(!x->is_exported() && get_parent_canvas())
294                 {
295                         x->set_parent_canvas(get_parent_canvas());
296                 }
297                 changed();
298                 return true;
299         }
300         return false;
301 }
302
303 ValueNode::LooseHandle
304 LinkableValueNode::get_link(int i)const
305 {
306         return get_link_vfunc(i);
307 }
308
309 void
310 LinkableValueNode::unlink_all()
311 {
312         for(int i=0;i<link_count();i++)
313         {
314                 ValueNode::LooseHandle value_node(get_link(i));
315                 if(value_node)
316                         value_node->parent_set.erase(this);
317         }
318 }
319
320 ValueNode::~ValueNode()
321 {
322         value_node_count--;
323
324         begin_delete();
325 }
326
327 void
328 ValueNode::on_changed()
329 {
330         etl::loose_handle<Canvas> parent_canvas = get_parent_canvas();
331         if(parent_canvas)
332                 do                                              // signal to all the ancestor canvases
333                         parent_canvas->signal_value_node_changed()(this);
334                 while (parent_canvas = parent_canvas->parent());
335         else if(get_root_canvas())
336                 get_root_canvas()->signal_value_node_changed()(this);
337
338         Node::on_changed();
339 }
340
341 int
342 ValueNode::replace(etl::handle<ValueNode> x)
343 {
344         if(x.get()==this)
345                 return 0;
346
347         while(parent_set.size())
348         {
349                 (*parent_set.begin())->add_child(x.get());
350                 (*parent_set.begin())->remove_child(this);
351                 //x->parent_set.insert(*parent_set.begin());
352                 //parent_set.erase(parent_set.begin());
353         }
354         int r(RHandle(this).replace(x));
355         x->changed();
356         return r;
357 }
358
359 void
360 ValueNode::set_id(const String &x)
361 {
362         if(name!=x)
363         {
364                 name=x;
365                 signal_id_changed_();
366         }
367 }
368
369 String
370 ValueNode::get_description(bool show_exported_name)const
371 {
372         String ret(_("ValueNode"));
373
374         if (dynamic_cast<const LinkableValueNode*>(this))
375                 return (dynamic_cast<const LinkableValueNode*>(this))->get_description(-1, show_exported_name);
376
377         if (show_exported_name && !is_exported())
378                 show_exported_name = false;
379
380         if (show_exported_name)
381                 ret += strprintf(" (%s)", get_id().c_str());
382
383         return ret;
384 }
385
386 ValueNodeList::ValueNodeList():
387         placeholder_count_(0)
388 {
389 }
390
391 bool
392 ValueNodeList::count(const String &id)const
393 {
394         const_iterator iter;
395
396         if(id.empty())
397                 return false;
398
399         for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter)
400                 ;
401
402         if(iter==end())
403                 return false;
404
405         return true;
406 }
407
408 ValueNode::Handle
409 ValueNodeList::find(const String &id)
410 {
411         iterator iter;
412
413         if(id.empty())
414                 throw Exception::IDNotFound("Empty ID");
415
416         for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter)
417                 ;
418
419         if(iter==end())
420                 throw Exception::IDNotFound("ValueNode in ValueNodeList: "+id);
421
422         return *iter;
423 }
424
425 ValueNode::ConstHandle
426 ValueNodeList::find(const String &id)const
427 {
428         const_iterator iter;
429
430         if(id.empty())
431                 throw Exception::IDNotFound("Empty ID");
432
433         for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter)
434                 ;
435
436         if(iter==end())
437                 throw Exception::IDNotFound("ValueNode in ValueNodeList: "+id);
438
439         return *iter;
440 }
441
442 ValueNode::Handle
443 ValueNodeList::surefind(const String &id)
444 {
445         if(id.empty())
446                 throw Exception::IDNotFound("Empty ID");
447
448         ValueNode::Handle value_node;
449
450         try
451         {
452                 value_node=find(id);
453         }
454         catch(Exception::IDNotFound)
455         {
456                 value_node=PlaceholderValueNode::create();
457                 value_node->set_id(id);
458                 push_back(value_node);
459                 placeholder_count_++;
460         }
461
462         return value_node;
463 }
464
465 bool
466 ValueNodeList::erase(ValueNode::Handle value_node)
467 {
468         assert(value_node);
469
470         iterator iter;
471
472         for(iter=begin();iter!=end();++iter)
473                 if(value_node.get()==iter->get())
474                 {
475                         std::list<ValueNode::RHandle>::erase(iter);
476                         if(PlaceholderValueNode::Handle::cast_dynamic(value_node))
477                                 placeholder_count_--;
478                         return true;
479                 }
480         return false;
481 }
482
483 bool
484 ValueNodeList::add(ValueNode::Handle value_node)
485 {
486         if(!value_node)
487                 return false;
488         if(value_node->get_id().empty())
489                 return false;
490
491         try
492         {
493                 ValueNode::RHandle other_value_node=find(value_node->get_id());
494                 if(PlaceholderValueNode::Handle::cast_dynamic(other_value_node))
495                 {
496                         other_value_node->replace(value_node);
497                         placeholder_count_--;
498                         return true;
499                 }
500
501                 return false;
502         }
503         catch(Exception::IDNotFound)
504         {
505                 push_back(value_node);
506                 return true;
507         }
508
509         return false;
510 }
511
512 void
513 ValueNodeList::audit()
514 {
515         iterator iter,next;
516
517         for(next=begin(),iter=next++;iter!=end();iter=next++)
518                 if(iter->count()==1)
519                         std::list<ValueNode::RHandle>::erase(iter);
520 }
521
522
523 String
524 PlaceholderValueNode::get_name()const
525 {
526         return "placeholder";
527 }
528
529 String
530 PlaceholderValueNode::get_local_name()const
531 {
532         return _("Placeholder");
533 }
534
535 ValueNode*
536 PlaceholderValueNode::clone(const GUID& deriv_guid)const
537 {
538         ValueNode* ret(new PlaceholderValueNode());
539         ret->set_guid(get_guid()^deriv_guid);
540         return ret;
541 }
542
543 PlaceholderValueNode::Handle
544 PlaceholderValueNode::create(ValueBase::Type type)
545 {
546         return new PlaceholderValueNode(type);
547 }
548
549 ValueBase
550 PlaceholderValueNode::operator()(Time /*t*/)const
551 {
552         assert(0);
553         return ValueBase();
554 }
555
556 PlaceholderValueNode::PlaceholderValueNode(ValueBase::Type type):
557         ValueNode(type)
558 {
559 }
560
561 ValueNode*
562 LinkableValueNode::clone(const GUID& deriv_guid)const
563 {
564         {
565                 ValueNode* x(find_value_node(get_guid()^deriv_guid).get());
566                 if(x)
567                         return x;
568         }
569
570         int i;
571         LinkableValueNode *ret=create_new();
572         ret->set_guid(get_guid()^deriv_guid);
573
574         for(i=0;i<link_count();i++)
575         {
576                 ValueNode::Handle link=get_link_vfunc(i);
577                 if(!link->is_exported())
578                 {
579                         ValueNode::LooseHandle value_node(find_value_node(link->get_guid()^deriv_guid));
580                         if(!value_node)
581                                 value_node=link->clone(deriv_guid);
582                         ret->set_link(i,value_node);
583                 }
584                 else
585                         ret->set_link(i,link);
586         }
587
588         return ret;
589 }
590
591 String
592 ValueNode::get_relative_id(etl::loose_handle<const Canvas> x)const
593 {
594         assert(is_exported());
595         assert(canvas_);
596
597         if(x.get()==canvas_.get())
598                 return get_id();
599
600         return canvas_->_get_relative_id(x)+':'+get_id();
601 }
602
603 void
604 ValueNode::set_parent_canvas(etl::loose_handle<Canvas> x)
605 {
606         canvas_=x; if(x) root_canvas_=x->get_root();
607 }
608
609 void
610 ValueNode::set_root_canvas(etl::loose_handle<Canvas> x)
611 {
612         root_canvas_=x->get_root();
613 }
614
615 void LinkableValueNode::get_times_vfunc(Node::time_set &set) const
616 {
617         ValueNode::LooseHandle  h;
618
619         int size = link_count();
620
621         //just add it to the set...
622         for(int i=0; i < size; ++i)
623         {
624                 h = get_link(i);
625
626                 if(h)
627                 {
628                         const Node::time_set &tset = h->get_times();
629                         set.insert(tset.begin(),tset.end());
630                 }
631         }
632 }
633
634 String
635 LinkableValueNode::get_description(int index, bool show_exported_name)const
636 {
637         String description;
638
639         if (index == -1)
640         {
641                 if (show_exported_name && is_exported())
642                         description += strprintf(" (%s)", get_id().c_str());
643         }
644         else
645         {
646                 description = String(":") + link_local_name(index);
647
648                 if (show_exported_name)
649                 {
650                         ValueNode::LooseHandle link(get_link(index));
651                         if (link->is_exported())
652                                 description += strprintf(" (%s)", link->get_id().c_str());
653                 }
654         }
655
656         const synfig::Node* node = this;
657         LinkableValueNode::ConstHandle parent_linkable_vn = 0;
658
659         // walk up through the valuenodes trying to find the layer at the top
660         while (!node->parent_set.empty() && !dynamic_cast<const Layer*>(node))
661         {
662                 LinkableValueNode::ConstHandle linkable_value_node(dynamic_cast<const LinkableValueNode*>(node));
663                 if (linkable_value_node)
664                 {
665                         String link;
666                         int cnt = linkable_value_node->link_count();
667                         for (int i = 0; i < cnt; i++)
668                                 if (linkable_value_node->get_link(i) == parent_linkable_vn)
669                                 {
670                                         link = String(":") + linkable_value_node->link_local_name(i);
671                                         break;
672                                 }
673
674                         description = linkable_value_node->get_local_name() + link + (parent_linkable_vn?">":"") + description;
675                 }
676                 node = *node->parent_set.begin();
677                 parent_linkable_vn = linkable_value_node;
678         }
679
680         Layer::ConstHandle parent_layer(dynamic_cast<const Layer*>(node));
681         if(parent_layer)
682         {
683                 String param;
684                 const Layer::DynamicParamList &dynamic_param_list(parent_layer->dynamic_param_list());
685                 // loop to find the parameter in the dynamic parameter list - this gives us its name
686                 for (Layer::DynamicParamList::const_iterator iter = dynamic_param_list.begin(); iter != dynamic_param_list.end(); iter++)
687                         if (iter->second == parent_linkable_vn)
688                                 param = String(":") + parent_layer->get_param_local_name(iter->first);
689                 description = strprintf("(%s)%s>%s",
690                                                                 parent_layer->get_non_empty_description().c_str(),
691                                                                 param.c_str(),
692                                                                 description.c_str());
693         }
694
695         return description;
696 }