163efa4978efdaad8ca6ad2845bae85231ee8fbf
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / blinepointtangentsplit.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file blinepointtangentsplit.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "blinepointtangentsplit.h"
34 #include "valuedescset.h"
35
36 #include "activepointset.h"
37 #include "activepointadd.h"
38
39 #include "valuedescconnect.h"
40 #include <synfigapp/canvasinterface.h>
41
42 #include <synfigapp/general.h>
43
44 #endif
45
46 using namespace std;
47 using namespace etl;
48 using namespace synfig;
49 using namespace synfigapp;
50 using namespace Action;
51
52 /* === M A C R O S ========================================================= */
53
54 ACTION_INIT_NO_GET_LOCAL_NAME(Action::BLinePointTangentSplit);
55 ACTION_SET_NAME(Action::BLinePointTangentSplit,"bline_point_tangent_split");
56 ACTION_SET_LOCAL_NAME(Action::BLinePointTangentSplit,N_("Split Tangents"));
57 ACTION_SET_TASK(Action::BLinePointTangentSplit,"split");
58 ACTION_SET_CATEGORY(Action::BLinePointTangentSplit,Action::CATEGORY_VALUENODE);
59 ACTION_SET_PRIORITY(Action::BLinePointTangentSplit,0);
60 ACTION_SET_VERSION(Action::BLinePointTangentSplit,"0.0");
61 ACTION_SET_CVS_ID(Action::BLinePointTangentSplit,"$Id$");
62
63 /* === G L O B A L S ======================================================= */
64
65 /* === P R O C E D U R E S ================================================= */
66
67 /* === M E T H O D S ======================================================= */
68
69 Action::BLinePointTangentSplit::BLinePointTangentSplit()
70 {
71         time=(Time::begin()-1);
72         set_dirty(true);
73 }
74
75 synfig::String
76 Action::BLinePointTangentSplit::get_local_name()const
77 {
78         return strprintf(_("Split Tangents of '%s'"), ((ValueNode::Handle)(value_node))->get_description().c_str());
79 }
80
81 Action::ParamVocab
82 Action::BLinePointTangentSplit::get_param_vocab()
83 {
84         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
85
86         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
87                 .set_local_name(_("ValueNode of BLinePoint"))
88         );
89
90         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
91                 .set_local_name(_("Time"))
92         );
93
94         return ret;
95 }
96
97 bool
98 Action::BLinePointTangentSplit::is_candidate(const ParamList &x)
99 {
100         if(candidate_check(get_param_vocab(),x))
101         {
102                 ValueNode_Composite::Handle value_node;
103                 value_node=ValueNode_Composite::Handle::cast_dynamic(x.find("value_node")->second.get_value_node());
104                 if(!value_node || value_node->get_type()!=ValueBase::TYPE_BLINEPOINT)
105                         return false;
106                 synfig::Time time(x.find("time")->second.get_time());
107                 if((*value_node->get_link("split"))(time).get(bool())==true)
108                         return false;
109                 return true;
110         }
111         return false;
112 }
113
114 bool
115 Action::BLinePointTangentSplit::set_param(const synfig::String& name, const Action::Param &param)
116 {
117         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
118         {
119                 value_node=value_node.cast_dynamic(param.get_value_node());
120
121                 return (bool)(value_node);
122         }
123         if(name=="time" && param.get_type()==Param::TYPE_TIME)
124         {
125                 time=param.get_time();
126
127                 return true;
128         }
129
130         return Action::CanvasSpecific::set_param(name,param);
131 }
132
133 bool
134 Action::BLinePointTangentSplit::is_ready()const
135 {
136         if(!value_node)
137                 synfig::error("Missing or bad value_node");
138
139         if(time==(Time::begin()-1))
140                 synfig::error("Missing time");
141
142         if(!value_node || time==(Time::begin()-1))
143                 return false;
144         return Action::CanvasSpecific::is_ready();
145 }
146
147 void
148 Action::BLinePointTangentSplit::prepare()
149 {
150         clear();
151
152         Action::Handle action;
153
154         action=Action::create("value_desc_set");
155         if(!action)
156                 throw Error(_("Couldn't find action \"value_desc_set\""));
157
158         action->set_param("canvas",get_canvas());
159         action->set_param("canvas_interface",get_canvas_interface());
160         action->set_param("value_desc",ValueDesc(value_node,3));
161         action->set_param("time",time);
162         action->set_param("new_value",synfig::ValueBase(true));
163
164         assert(action->is_ready());
165         if(!action->is_ready())
166                 throw Error(Error::TYPE_NOTREADY);
167
168         add_action(action);
169 }