From: Carlos Lopez Date: Sat, 11 Sep 2010 14:17:32 +0000 (+0200) Subject: Copy tangent Link Smart code to normal link action and hide Link Smart action temporarly X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1c82886488c71b2b67bba05bcaf94c3a66caad4e;p=synfig.git Copy tangent Link Smart code to normal link action and hide Link Smart action temporarly --- diff --git a/synfig-studio/src/synfigapp/actions/valuedesclink.cpp b/synfig-studio/src/synfigapp/actions/valuedesclink.cpp index 7f98228..2f473ee 100644 --- a/synfig-studio/src/synfigapp/actions/valuedesclink.cpp +++ b/synfig-studio/src/synfigapp/actions/valuedesclink.cpp @@ -7,6 +7,7 @@ ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** Copyright (c) 2007, 2008 Chris Moore +** Copyright (c) 2010 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 @@ -34,6 +35,7 @@ #include #include +#include #include @@ -62,7 +64,8 @@ ACTION_SET_CVS_ID(Action::ValueDescLink,"$Id$"); /* === M E T H O D S ======================================================= */ -Action::ValueDescLink::ValueDescLink(): poison(false), status_level(0) +Action::ValueDescLink::ValueDescLink(): +poison(false), status_level(0), link_scalar(0.0) { } @@ -72,7 +75,7 @@ Action::ValueDescLink::get_param_vocab() ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC) - .set_local_name(_("ValueDesc to link")) + .set_local_name(_("ValueDesc to smart link")) .set_requires_multiple() ); @@ -116,6 +119,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param } link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); status_message = _("Used exported ValueNode ('") + link_value_node->get_id() + _("')."); } else if(value_desc.is_value_node()) @@ -125,6 +129,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 1; status_message = _("Using the only available ValueNode."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if(link_value_node->is_exported()) { @@ -138,6 +143,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 2; status_message = _("Using the most referenced ValueNode."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if (status_level <= 2) { @@ -152,6 +158,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 3; status_message = _("There's a tie for most referenced; using the animated ValueNode."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if(ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()) && !ValueNode_Const::Handle::cast_dynamic(link_value_node)) { @@ -173,6 +180,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 4; status_message = _("There's a tie for most referenced, and both are animated; using the one with the most waypoints."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if (status_level <= 4) { @@ -192,6 +200,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 4; status_message = _("There's a tie for most referenced, and both are linkable value node animated; using the one with the most waypoints."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if (status_level <= 4) { @@ -207,6 +216,7 @@ Action::ValueDescLink::set_param(const synfig::String& name, const Action::Param status_level = 5; status_message = _("Everything is tied; using the least recently modified value."); link_value_node=value_desc.get_value_node(); + link_scalar=value_desc.get_scalar(); } else if (status_level <= 5) { @@ -281,25 +291,56 @@ Action::ValueDescLink::prepare() add_action_front(action); } - /* - if(!link_value_node->is_exported()) - { - Action::Handle action(Action::create("ValueNodeAdd")); - - action->set_param("canvas",get_canvas()); - action->set_param("canvas_interface",get_canvas_interface()); - action->set_param("new",link_value_node); - action->set_param("name",strprintf(_("Unnamed%08d"),synfig::UniqueID().get_uid())); - - assert(action->is_ready()); - if(!action->is_ready()) - throw Error(Error::TYPE_NOTREADY); - - add_action_front(action); - } - */ + // Check if the selected link value node is already a scale -1.0 Linkable Value Node + bool link_is_scaled(false); + if(synfig::ValueNode_Scale::Handle::cast_dynamic(link_value_node)) + { + synfig::ValueNode_Const::Handle scale_vn( + synfig::ValueNode_Const::Handle::cast_dynamic( + synfig::ValueNode_Scale::Handle::cast_dynamic(link_value_node)->get_link(1) + ) + ); + if(scale_vn) + if((*scale_vn)(synfig::Time(0))==synfig::ValueBase(Real(-1.0))) + link_is_scaled=true; + } std::list::iterator iter; + Real current_scalar(1.0); + bool found_inverse(false); + // Check if we are dealing the case of linking differnt types of tangents + for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter) + { + ValueDesc& v_desc(*iter); + // If parent is linkable value node + if(v_desc.parent_is_linkable_value_node()) + { + // if the link describe to any tangent (index 4 or 5), continue + if(v_desc.get_index() == 4 || v_desc.get_index() == 5) + { + synfig::Real iter_scalar=v_desc.get_scalar(); + // Let's compare the sign of scalar of the value node witht the current one + // and remember if a change of sign is seen. + if(iter_scalar*current_scalar < 0) // if they have different signs + { + found_inverse=true; + current_scalar=iter_scalar; + } + } + else + { + found_inverse=false; + break; + } + } + else + { + found_inverse=false; + break; + } + } + // found_inverse = true only if all they are tangents and some are inversed tangents + //Noe let's loop throug all the value desc for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter) { ValueDesc& value_desc(*iter); @@ -308,19 +349,115 @@ Action::ValueDescLink::prepare() // don't link it to itself if (value_desc.is_exported()) continue; + // Don't link the selected to itself (maybe it is redundant with the previous check) + if(value_desc.get_value_node() == link_value_node) + continue; + // If we found inverse means that all they are tangents and some are differnt scalar (different colors) + if(found_inverse) + { + //Check if the current value node has opposite scalar than the link + // value node to convert to scale -1.0 before connect. + // Check also if the link value node is NOT also a scale -1 + if( (value_desc.get_scalar()*link_scalar<0) && (link_is_scaled==false) ) + { + //Let's create a Scale Value Node + synfig::ValueNode::Handle scale_value_node=synfig::LinkableValueNode::create("scale",iter->get_value(time)); + if(!scale_value_node) + throw Error(Error::TYPE_BUG); + scale_value_node->set_parent_canvas(get_canvas()); + //Let's connect the new Scale Value Node to the value node + Action::Handle action1(Action::create("ValueDescConnect")); + if(!action1) + throw Error(Error::TYPE_CRITICAL); + action1->set_param("canvas",get_canvas()); + action1->set_param("canvas_interface",get_canvas_interface()); + action1->set_param("dest",value_desc); + action1->set_param("src",scale_value_node); + assert(action1->is_ready()); + if(!action1->is_ready()) + throw Error(Error::TYPE_NOTREADY); + add_action_front(action1); + + //Let's Connect the link value node to the scale value node link subparam + Action::Handle action2(Action::create("ValueNodeLinkConnect")); + if(!action2) + throw Error(Error::TYPE_CRITICAL); + + action2->set_param("canvas",get_canvas()); + action2->set_param("canvas_interface",get_canvas_interface()); + action2->set_param("parent_value_node",scale_value_node); + action2->set_param("index",0); + action2->set_param("value_node",link_value_node); + assert(action2->is_ready()); + if(!action2->is_ready()) + throw Error(Error::TYPE_NOTREADY); + add_action_front(action2); + + //Let's Set the scale to -1 + Action::Handle action3(Action::create("ValueNodeConstSet")); + if(!action3) + throw Error(Error::TYPE_CRITICAL); + + action3->set_param("canvas",get_canvas()); + action3->set_param("canvas_interface",get_canvas_interface()); + action3->set_param("value_node",synfig::LinkableValueNode::Handle::cast_dynamic(scale_value_node)->get_link(1)); + action3->set_param("new_value",synfig::ValueBase(Real(-1.0))); + assert(action3->is_ready()); + if(!action3->is_ready()) + throw Error(Error::TYPE_NOTREADY); + add_action_front(action3); + } + else if((iter->get_scalar()*link_scalar<0) && (link_is_scaled==true) ) + { + //Let's connect the link value node -> link to the value node + // There is not needed conversion to scale of the value node + // because the link value node is already a scale -1 + Action::Handle action4(Action::create("ValueDescConnect")); + if(!action4) + throw Error(Error::TYPE_CRITICAL); + action4->set_param("canvas",get_canvas()); + action4->set_param("canvas_interface",get_canvas_interface()); + action4->set_param("dest",value_desc); + action4->set_param("src",synfig::ValueNode_Scale::Handle::cast_dynamic(link_value_node)->get_link(0)); + assert(action4->is_ready()); + if(!action4->is_ready()) + throw Error(Error::TYPE_NOTREADY); + add_action_front(action4); + } + else + { + //Let's connect the link value node to the value node + Action::Handle action(Action::create("ValueDescConnect")); - Action::Handle action(Action::create("ValueDescConnect")); + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("src",link_value_node); + action->set_param("dest",value_desc); - action->set_param("canvas",get_canvas()); - action->set_param("canvas_interface",get_canvas_interface()); - action->set_param("src",link_value_node); - action->set_param("dest",value_desc); + assert(action->is_ready()); + if(!action->is_ready()) + throw Error(Error::TYPE_NOTREADY); - assert(action->is_ready()); - if(!action->is_ready()) - throw Error(Error::TYPE_NOTREADY); + add_action_front(action); + } + } // found inverse + else // Not found inverse so do a regualr link + { + //Let's connect the link value node to the value node + Action::Handle action(Action::create("ValueDescConnect")); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("src",link_value_node); + action->set_param("dest",value_desc); + + assert(action->is_ready()); + if(!action->is_ready()) + throw Error(Error::TYPE_NOTREADY); + + add_action_front(action); + } - add_action_front(action); } synfig::info("http://synfig.org/Linking#Tier_%d : %s", status_level, status_message.c_str()); diff --git a/synfig-studio/src/synfigapp/actions/valuedesclink.h b/synfig-studio/src/synfigapp/actions/valuedesclink.h index a72e78f..b32d442 100644 --- a/synfig-studio/src/synfigapp/actions/valuedesclink.h +++ b/synfig-studio/src/synfigapp/actions/valuedesclink.h @@ -53,6 +53,7 @@ private: int status_level; synfig::String status_message; synfig::Time time; + synfig::Real link_scalar; public: ValueDescLink(); diff --git a/synfig-studio/src/synfigapp/actions/valuedescsmartlink.cpp b/synfig-studio/src/synfigapp/actions/valuedescsmartlink.cpp index 0f30467..3114f5b 100644 --- a/synfig-studio/src/synfigapp/actions/valuedescsmartlink.cpp +++ b/synfig-studio/src/synfigapp/actions/valuedescsmartlink.cpp @@ -52,7 +52,7 @@ ACTION_INIT(Action::ValueDescSmartLink); ACTION_SET_NAME(Action::ValueDescSmartLink,"ValueDescSmartLink"); ACTION_SET_LOCAL_NAME(Action::ValueDescSmartLink,N_("Smart Link")); ACTION_SET_TASK(Action::ValueDescSmartLink,"connect"); -ACTION_SET_CATEGORY(Action::ValueDescSmartLink,Action::CATEGORY_VALUEDESC); +ACTION_SET_CATEGORY(Action::ValueDescSmartLink,Action::CATEGORY_HIDDEN); ACTION_SET_PRIORITY(Action::ValueDescSmartLink,0); ACTION_SET_VERSION(Action::ValueDescSmartLink,"0.0"); ACTION_SET_CVS_ID(Action::ValueDescSmartLink,"$Id$");