From b0ac74b597f00a1f222d7627e6ff760feb07bff7 Mon Sep 17 00:00:00 2001 From: dooglus Date: Tue, 25 Nov 2008 01:23:28 +0000 Subject: [PATCH] Allow waypoints to have their values exported, converted, etc. A work in progress. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2271 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-studio/trunk/src/gtkmm/canvasview.cpp | 10 ++ synfig-studio/trunk/src/synfigapp/Makefile.am | 4 +- .../src/synfigapp/actions/valuedescconnect.cpp | 18 +++ .../src/synfigapp/actions/valuedescdisconnect.cpp | 19 +++ .../src/synfigapp/actions/waypointconnect.cpp | 159 +++++++++++++++++++ .../trunk/src/synfigapp/actions/waypointconnect.h | 79 ++++++++++ .../src/synfigapp/actions/waypointdisconnect.cpp | 172 +++++++++++++++++++++ .../src/synfigapp/actions/waypointdisconnect.h | 80 ++++++++++ synfig-studio/trunk/src/synfigapp/value_desc.cpp | 2 + synfig-studio/trunk/src/synfigapp/value_desc.h | 15 +- 10 files changed, 554 insertions(+), 4 deletions(-) create mode 100644 synfig-studio/trunk/src/synfigapp/actions/waypointconnect.cpp create mode 100644 synfig-studio/trunk/src/synfigapp/actions/waypointconnect.h create mode 100644 synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.cpp create mode 100644 synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.h diff --git a/synfig-studio/trunk/src/gtkmm/canvasview.cpp b/synfig-studio/trunk/src/gtkmm/canvasview.cpp index 1abce20..791f87f 100644 --- a/synfig-studio/trunk/src/gtkmm/canvasview.cpp +++ b/synfig-studio/trunk/src/gtkmm/canvasview.cpp @@ -3319,6 +3319,16 @@ CanvasView::on_waypoint_clicked_canvasview(synfigapp::ValueDesc value_desc, } // ------------------------------------------------------------------------ + if (size == 1) + { + const synfigapp::ValueDesc value_desc(synfig::ValueNode_Animated::Handle::cast_reinterpret(waypoint.get_parent_value_node()), time); + get_instance()->make_param_menu(waypoint_menu,canvas_interface()->get_canvas(),value_desc,0.5f); + + // ------------------------------------------------------------------------ + waypoint_menu->items().push_back(Gtk::Menu_Helpers::SeparatorElem()); + } + + // ------------------------------------------------------------------------ waypoint_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Jump To"), sigc::bind(sigc::mem_fun(*canvas_interface(), &synfigapp::CanvasInterface::set_time), time))); diff --git a/synfig-studio/trunk/src/synfigapp/Makefile.am b/synfig-studio/trunk/src/synfigapp/Makefile.am index f6402e6..eb8506c 100644 --- a/synfig-studio/trunk/src/synfigapp/Makefile.am +++ b/synfig-studio/trunk/src/synfigapp/Makefile.am @@ -36,10 +36,10 @@ VALUENODE_ACTION_CC = \ WAYPOINT_ACTION_HH = \ actions/waypointadd.h actions/waypointremove.h actions/waypointset.h actions/waypointsetsmart.h \ - actions/waypointsimpleadd.h + actions/waypointsimpleadd.h actions/waypointconnect.h actions/waypointdisconnect.h WAYPOINT_ACTION_CC = \ actions/waypointadd.cpp actions/waypointremove.cpp actions/waypointset.cpp actions/waypointsetsmart.cpp \ - actions/waypointsimpleadd.cpp + actions/waypointsimpleadd.cpp actions/waypointconnect.cpp actions/waypointdisconnect.cpp TIMEPOINT_ACTION_HH = \ actions/timepointscopy.h actions/timepointsdelete.h actions/timepointsmove.h timegather.h diff --git a/synfig-studio/trunk/src/synfigapp/actions/valuedescconnect.cpp b/synfig-studio/trunk/src/synfigapp/actions/valuedescconnect.cpp index 7c2dfb2..01955cd 100644 --- a/synfig-studio/trunk/src/synfigapp/actions/valuedescconnect.cpp +++ b/synfig-studio/trunk/src/synfigapp/actions/valuedescconnect.cpp @@ -31,6 +31,7 @@ #endif #include "layerparamconnect.h" +#include "waypointconnect.h" #include "valuenodelinkconnect.h" #include "valuenodereplace.h" @@ -200,6 +201,23 @@ Action::ValueDescConnect::prepare() return; } else + if(value_desc.parent_is_waypoint()) + { + Action::Handle action(WaypointConnect::create()); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("parent_value_node",value_desc.get_parent_value_node()); + action->set_param("value_node", value_node); + action->set_param("waypoint_time",value_desc.get_waypoint_time()); + + assert(action->is_ready()); + if(!action->is_ready()) + throw Error(Error::TYPE_NOTREADY); + + add_action_front(action); + return; + } if(value_desc.parent_is_linkable_value_node()) { Action::Handle action(ValueNodeLinkConnect::create()); diff --git a/synfig-studio/trunk/src/synfigapp/actions/valuedescdisconnect.cpp b/synfig-studio/trunk/src/synfigapp/actions/valuedescdisconnect.cpp index 91c58ca..ea57fd0 100644 --- a/synfig-studio/trunk/src/synfigapp/actions/valuedescdisconnect.cpp +++ b/synfig-studio/trunk/src/synfigapp/actions/valuedescdisconnect.cpp @@ -31,6 +31,7 @@ #endif #include "layerparamdisconnect.h" +#include "waypointdisconnect.h" #include "valuenodelinkdisconnect.h" #include "valuenodereplace.h" @@ -177,6 +178,24 @@ Action::ValueDescDisconnect::prepare() return; } else + if(value_desc.parent_is_waypoint()) + { + Action::Handle action(WaypointDisconnect::create()); + + action->set_param("canvas",get_canvas()); + action->set_param("canvas_interface",get_canvas_interface()); + action->set_param("parent_value_node",value_desc.get_parent_value_node()); + action->set_param("waypoint_time",value_desc.get_waypoint_time()); + action->set_param("time",time); + + assert(action->is_ready()); + if(!action->is_ready()) + throw Error(Error::TYPE_NOTREADY); + + add_action_front(action); + return; + } + else if(value_desc.parent_is_linkable_value_node()) { Action::Handle action(ValueNodeLinkDisconnect::create()); diff --git a/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.cpp b/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.cpp new file mode 100644 index 0000000..b45df55 --- /dev/null +++ b/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.cpp @@ -0,0 +1,159 @@ +/* === S Y N F I G ========================================================= */ +/*! \file waypointconnect.cpp +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "waypointconnect.h" +#include + +#include + +#endif + +using namespace std; +using namespace etl; +using namespace synfig; +using namespace synfigapp; +using namespace Action; + +/* === M A C R O S ========================================================= */ + +ACTION_INIT(Action::WaypointConnect); +ACTION_SET_NAME(Action::WaypointConnect,"waypoint_connect"); +ACTION_SET_LOCAL_NAME(Action::WaypointConnect,N_("Connect Waypoint")); +ACTION_SET_TASK(Action::WaypointConnect,"connect"); +ACTION_SET_CATEGORY(Action::WaypointConnect,Action::CATEGORY_WAYPOINT); +ACTION_SET_PRIORITY(Action::WaypointConnect,0); +ACTION_SET_VERSION(Action::WaypointConnect,"0.0"); +ACTION_SET_CVS_ID(Action::WaypointConnect,"$Id$"); + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Action::WaypointConnect::WaypointConnect(): + waypoint_time_set(false) +{ +} + +Action::ParamVocab +Action::WaypointConnect::get_param_vocab() +{ + ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); + + ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE) + .set_local_name(_("Parent ValueNode")) + ); + + ret.push_back(ParamDesc("waypoint_time",Param::TYPE_TIME) + .set_local_name(_("Waypoint Time")) + ); + + ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE) + .set_local_name(_("ValueNode to be connected")) + ); + + return ret; +} + +bool +Action::WaypointConnect::is_candidate(const ParamList &x) +{ + return candidate_check(get_param_vocab(),x); +} + +bool +Action::WaypointConnect::set_param(const synfig::String& name, const Action::Param ¶m) +{ + if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE) + { + parent_value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node()); + + return static_cast(parent_value_node); + } + + if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE) + { + new_value_node=param.get_value_node(); + + return true; + } + + if(name=="waypoint_time" && param.get_type()==Param::TYPE_TIME) + { + waypoint_time=param.get_time(); + waypoint_time_set=true; + + return true; + } + + return Action::CanvasSpecific::set_param(name,param); +} + +bool +Action::WaypointConnect::is_ready()const +{ + if(!new_value_node || !parent_value_node || !waypoint_time_set) + return false; + return Action::CanvasSpecific::is_ready(); +} + +void +Action::WaypointConnect::perform() +{ + ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time)); + + old_value_node=iter->get_value_node(); + iter->set_value_node(new_value_node); + + /*set_dirty(true); + + if(get_canvas_interface()) + { + get_canvas_interface()->signal_value_node_changed()(parent_value_node); + }*/ +} + +void +Action::WaypointConnect::undo() +{ + ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time)); + + iter->set_value_node(old_value_node); + + /*set_dirty(true); + + if(get_canvas_interface()) + { + get_canvas_interface()->signal_value_node_changed()(parent_value_node); + }*/ +} diff --git a/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.h b/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.h new file mode 100644 index 0000000..fe97289 --- /dev/null +++ b/synfig-studio/trunk/src/synfigapp/actions/waypointconnect.h @@ -0,0 +1,79 @@ +/* === S Y N F I G ========================================================= */ +/*! \file valuenodeconnect.h +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_APP_ACTION_WAYPOINTCONNECT_H +#define __SYNFIG_APP_ACTION_WAYPOINTCONNECT_H + +/* === H E A D E R S ======================================================= */ + +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfigapp { + +class Instance; + +namespace Action { + +class WaypointConnect : + public Undoable, + public CanvasSpecific +{ +private: + + synfig::ValueNode_Animated::Handle parent_value_node; + synfig::ValueNode::Handle new_value_node; + synfig::ValueNode::Handle old_value_node; + synfig::Time waypoint_time; + bool waypoint_time_set; + +public: + + WaypointConnect(); + + static ParamVocab get_param_vocab(); + static bool is_candidate(const ParamList &x); + + virtual bool set_param(const synfig::String& name, const Param &); + virtual bool is_ready()const; + + virtual void perform(); + virtual void undo(); + + ACTION_MODULE_EXT +}; + +}; // END of namespace action +}; // END of namespace studio + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.cpp b/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.cpp new file mode 100644 index 0000000..fd0e753 --- /dev/null +++ b/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.cpp @@ -0,0 +1,172 @@ +/* === S Y N F I G ========================================================= */ +/*! \file waypointdisconnect.cpp +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "waypointdisconnect.h" +#include +#include + +#include + +#endif + +using namespace std; +using namespace etl; +using namespace synfig; +using namespace synfigapp; +using namespace Action; + +/* === M A C R O S ========================================================= */ + +ACTION_INIT(Action::WaypointDisconnect); +ACTION_SET_NAME(Action::WaypointDisconnect,"waypoint_disconnect"); +ACTION_SET_LOCAL_NAME(Action::WaypointDisconnect,N_("Disconnect Waypoint")); +ACTION_SET_TASK(Action::WaypointDisconnect,"disconnect"); +ACTION_SET_CATEGORY(Action::WaypointDisconnect,Action::CATEGORY_WAYPOINT); +ACTION_SET_PRIORITY(Action::WaypointDisconnect,0); +ACTION_SET_VERSION(Action::WaypointDisconnect,"0.0"); +ACTION_SET_CVS_ID(Action::WaypointDisconnect,"$Id$"); + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +Action::WaypointDisconnect::WaypointDisconnect(): + waypoint_time_set(false), + time_set(false) +{ +} + +Action::ParamVocab +Action::WaypointDisconnect::get_param_vocab() +{ + ParamVocab ret(Action::CanvasSpecific::get_param_vocab()); + + ret.push_back(ParamDesc("parent_value_node",Param::TYPE_VALUENODE) + .set_local_name(_("Parent ValueNode")) + ); + + ret.push_back(ParamDesc("waypoint_time",Param::TYPE_TIME) + .set_local_name(_("Waypoint Time")) + ); + + ret.push_back(ParamDesc("time",Param::TYPE_TIME) + .set_local_name(_("Time")) + .set_optional() + ); + + return ret; +} + +bool +Action::WaypointDisconnect::is_candidate(const ParamList &x) +{ + return candidate_check(get_param_vocab(),x); +} + +bool +Action::WaypointDisconnect::set_param(const synfig::String& name, const Action::Param ¶m) +{ + if(name=="parent_value_node" && param.get_type()==Param::TYPE_VALUENODE) + { + parent_value_node=ValueNode_Animated::Handle::cast_dynamic(param.get_value_node()); + + return static_cast(parent_value_node); + } + + if(name=="waypoint_time" && param.get_type()==Param::TYPE_TIME) + { + waypoint_time=param.get_time(); + waypoint_time_set=true; + + return true; + } + + if(name=="time" && param.get_type()==Param::TYPE_TIME) + { + time=param.get_time(); + time_set=true; + + return true; + } + + return Action::CanvasSpecific::set_param(name,param); +} + +bool +Action::WaypointDisconnect::is_ready()const +{ + if(!parent_value_node || !waypoint_time_set) + return false; + return Action::CanvasSpecific::is_ready(); +} + +void +Action::WaypointDisconnect::perform() +{ + ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time)); + + old_value_node=iter->get_value_node(); + + iter->set_value_node(ValueNode_Const::create((*old_value_node)(time_set ? time : waypoint_time))); + + /* + if(get_canvas()->get_time()!=time) + set_dirty(true); + else + set_dirty(false); + + if(get_canvas_interface()) + { + get_canvas_interface()->signal_value_node_changed()(parent_value_node); + } + */ +} + +void +Action::WaypointDisconnect::undo() +{ + ValueNode_Animated::WaypointList::iterator iter(parent_value_node->find(waypoint_time)); + + iter->set_value_node(old_value_node); + + /*if(get_canvas()->get_time()!=time) + set_dirty(true); + else + set_dirty(false); + + if(get_canvas_interface()) + { + get_canvas_interface()->signal_value_node_changed()(parent_value_node); + }*/ +} diff --git a/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.h b/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.h new file mode 100644 index 0000000..922d670 --- /dev/null +++ b/synfig-studio/trunk/src/synfigapp/actions/waypointdisconnect.h @@ -0,0 +1,80 @@ +/* === S Y N F I G ========================================================= */ +/*! \file waypointdisconnect.h +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2008 Chris Moore +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_APP_ACTION_WAYPOINTDISCONNECT_H +#define __SYNFIG_APP_ACTION_WAYPOINTDISCONNECT_H + +/* === H E A D E R S ======================================================= */ + +#include +#include + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace synfigapp { + +class Instance; + +namespace Action { + +class WaypointDisconnect : + public Undoable, + public CanvasSpecific +{ +private: + + synfig::ValueNode_Animated::Handle parent_value_node; + synfig::ValueNode::Handle old_value_node; + synfig::Time waypoint_time; + synfig::Time time; + bool waypoint_time_set; + bool time_set; + +public: + + WaypointDisconnect(); + + static ParamVocab get_param_vocab(); + static bool is_candidate(const ParamList &x); + + virtual bool set_param(const synfig::String& name, const Param &); + virtual bool is_ready()const; + + virtual void perform(); + virtual void undo(); + + ACTION_MODULE_EXT +}; + +}; // END of namespace action +}; // END of namespace studio + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-studio/trunk/src/synfigapp/value_desc.cpp b/synfig-studio/trunk/src/synfigapp/value_desc.cpp index ef0cffb..a613d12 100644 --- a/synfig-studio/trunk/src/synfigapp/value_desc.cpp +++ b/synfig-studio/trunk/src/synfigapp/value_desc.cpp @@ -77,6 +77,8 @@ ValueDesc::get_description(bool show_exported_name)const description = strprintf("%s %s", _("Const ValueNode"), value_node->get_description(show_exported_name).c_str()); } + else if (parent_is_waypoint()) + description = _("Waypoint"); else { warning("%s:%d didn't expect to get here", __FILE__, __LINE__); diff --git a/synfig-studio/trunk/src/synfigapp/value_desc.h b/synfig-studio/trunk/src/synfigapp/value_desc.h index 841b40e..ccc562a 100644 --- a/synfig-studio/trunk/src/synfigapp/value_desc.h +++ b/synfig-studio/trunk/src/synfigapp/value_desc.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -51,7 +52,8 @@ class ValueDesc // Info for ValueNode parent synfig::ValueNode::Handle parent_value_node; - int index; + int index; // -2 if it's a waypoint, -1 if it's const, >=0 if it's LinkableValueNode + synfig::Time waypoint_time; // Info for exported ValueNode synfig::Canvas::Handle canvas; @@ -69,7 +71,7 @@ public: return false; if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node) return false; - if((index>-1||rhs.index>-1) && index!=rhs.index) + if(index!=rhs.index) return false; return true; } @@ -95,6 +97,11 @@ public: // parent_value_node(parent_value_node), // index(parent_value_node->get_link_index_from_name(param_name)) { } + ValueDesc(synfig::ValueNode_Animated::Handle parent_value_node,synfig::Time waypoint_time): + parent_value_node(parent_value_node), + index(-2), + waypoint_time(waypoint_time) { } + ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name): name(name), canvas(canvas) { } @@ -112,6 +119,7 @@ public: bool parent_is_value_node()const { return (bool)parent_value_node; } bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; } bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; } + bool parent_is_waypoint()const { return parent_is_value_node() && index==-2; } bool parent_is_canvas()const { return (bool)canvas; } bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); } @@ -122,6 +130,7 @@ public: synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; } int get_index()const { assert(parent_is_linkable_value_node()); return index; } + synfig::Time get_waypoint_time()const { assert(parent_is_waypoint()); return waypoint_time; } const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; } @@ -148,6 +157,8 @@ public: // return reinterpret_cast(parent_value_node.get())->get_link(index); if(parent_is_value_node_const()) return parent_value_node; + if(parent_is_waypoint()) + return (synfig::ValueNode_Animated::Handle::cast_reinterpret(parent_value_node))->find(waypoint_time)->get_value_node(); return 0; } -- 2.7.4