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