X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode.cpp;h=51cd1ffba83879c0e2884cfb8d475c18c86c2cc1;hb=cdd61095e448109f06e50f2ea461459413082220;hp=81a9fa288ded3d77f2f74fae007c2456df8e4f20;hpb=63e709f66d50c124cc0ece2325f4773ac4ae7b20;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode.cpp b/synfig-core/trunk/src/synfig/valuenode.cpp index 81a9fa2..51cd1ff 100644 --- a/synfig-core/trunk/src/synfig/valuenode.cpp +++ b/synfig-core/trunk/src/synfig/valuenode.cpp @@ -37,6 +37,7 @@ #include "valuenode.h" #include "general.h" #include "canvas.h" +#include "paramdesc.h" #include "valuenode_const.h" #include "valuenode_linear.h" @@ -201,6 +202,17 @@ LinkableValueNode::create(const String &name, const ValueBase& x) { if(!book().count(name)) return 0; + + if (!check_type(name, x.get_type()) && + // the Duplicate ValueNode is an exception - we don't want the + // user creating it for themselves, so check_type() fails for + // it even when it is valid + !(name == "duplicate" && x.get_type() == ValueBase::TYPE_REAL)) + { + 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()); + return 0; + } + return book()[name].factory(x); } @@ -299,6 +311,15 @@ ValueNode::set_id(const String &x) } } +String +ValueNode::get_description(bool show_exported_name)const +{ + if (dynamic_cast(this)) + return (dynamic_cast(this))->get_description(-1, show_exported_name); + + return "ValueNode"; +} + ValueNodeList::ValueNodeList(): placeholder_count_(0) { @@ -312,7 +333,8 @@ ValueNodeList::count(const String &id)const if(id.empty()) return false; - for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter); + for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter) + ; if(iter==end()) return false; @@ -328,7 +350,8 @@ ValueNodeList::find(const String &id) if(id.empty()) throw Exception::IDNotFound("Empty ID"); - for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter); + for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter) + ; if(iter==end()) throw Exception::IDNotFound("ValueNode in ValueNodeList: "+id); @@ -344,7 +367,8 @@ ValueNodeList::find(const String &id)const if(id.empty()) throw Exception::IDNotFound("Empty ID"); - for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter); + for(iter=begin();iter!=end() && id!=(*iter)->get_id();++iter) + ; if(iter==end()) throw Exception::IDNotFound("ValueNode in ValueNodeList: "+id); @@ -544,3 +568,59 @@ void LinkableValueNode::get_times_vfunc(Node::time_set &set) const } } } + +String +LinkableValueNode::get_description(int index, bool show_exported_name)const +{ + String description; + + if (show_exported_name && !is_exported()) + show_exported_name = false; + + if (index != -1) + description = String(":") + link_local_name(index); + + const synfig::Node* node = this; + LinkableValueNode::ConstHandle parent_linkable_vn = 0; + + // walk up through the valuenodes trying to find the layer at the top + while (!node->parent_set.empty() && !dynamic_cast(node)) + { + LinkableValueNode::ConstHandle linkable_value_node(dynamic_cast(node)); + if (linkable_value_node) + { + String link; + int cnt = linkable_value_node->link_count(); + for (int i = 0; i < cnt; i++) + if (linkable_value_node->get_link(i) == parent_linkable_vn) + { + link = String(":") + linkable_value_node->link_local_name(i); + break; + } + + description = linkable_value_node->get_local_name() + link + (parent_linkable_vn?">":"") + description; + } + node = *node->parent_set.begin(); + parent_linkable_vn = linkable_value_node; + } + + Layer::ConstHandle parent_layer(dynamic_cast(node)); + if(parent_layer) + { + String param; + const Layer::DynamicParamList &dynamic_param_list(parent_layer->dynamic_param_list()); + // loop to find the parameter in the dynamic parameter list - this gives us its name + for (Layer::DynamicParamList::const_iterator iter = dynamic_param_list.begin(); iter != dynamic_param_list.end(); iter++) + if (iter->second == parent_linkable_vn) + param = String(":") + parent_layer->get_param_local_name(iter->first); + description = strprintf("(%s)%s>%s", + parent_layer->get_non_empty_description().c_str(), + param.c_str(), + description.c_str()); + } + + if (show_exported_name) + description += strprintf(" (%s)", get_id().c_str()); + + return description; +}