Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc2 / 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 #endif
43
44 using namespace std;
45 using namespace etl;
46 using namespace synfig;
47 using namespace synfigapp;
48 using namespace Action;
49
50 /* === M A C R O S ========================================================= */
51
52 ACTION_INIT(Action::BLinePointTangentSplit);
53 ACTION_SET_NAME(Action::BLinePointTangentSplit,"bline_point_tangent_split");
54 ACTION_SET_LOCAL_NAME(Action::BLinePointTangentSplit,_("Split Tangents"));
55 ACTION_SET_TASK(Action::BLinePointTangentSplit,"split");
56 ACTION_SET_CATEGORY(Action::BLinePointTangentSplit,Action::CATEGORY_VALUENODE);
57 ACTION_SET_PRIORITY(Action::BLinePointTangentSplit,0);
58 ACTION_SET_VERSION(Action::BLinePointTangentSplit,"0.0");
59 ACTION_SET_CVS_ID(Action::BLinePointTangentSplit,"$Id$");
60
61 /* === G L O B A L S ======================================================= */
62
63 /* === P R O C E D U R E S ================================================= */
64
65 /* === M E T H O D S ======================================================= */
66
67 Action::BLinePointTangentSplit::BLinePointTangentSplit()
68 {
69         time=(Time::begin()-1);
70         set_dirty(true);
71 }
72
73 Action::ParamVocab
74 Action::BLinePointTangentSplit::get_param_vocab()
75 {
76         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
77
78         ret.push_back(ParamDesc("value_node",Param::TYPE_VALUENODE)
79                 .set_local_name(_("ValueNode of BLinePoint"))
80         );
81
82         ret.push_back(ParamDesc("time",Param::TYPE_TIME)
83                 .set_local_name(_("Time"))
84         );
85
86         return ret;
87 }
88
89 bool
90 Action::BLinePointTangentSplit::is_candidate(const ParamList &x)
91 {
92         if(candidate_check(get_param_vocab(),x))
93         {
94                 ValueNode_Composite::Handle value_node;
95                 value_node=ValueNode_Composite::Handle::cast_dynamic(x.find("value_node")->second.get_value_node());
96                 if(!value_node || value_node->get_type()!=ValueBase::TYPE_BLINEPOINT)
97                         return false;
98                 synfig::Time time(x.find("time")->second.get_time());
99                 if((*value_node->get_link("split"))(time).get(bool())==true)
100                         return false;
101                 return true;
102         }
103         return false;
104 }
105
106 bool
107 Action::BLinePointTangentSplit::set_param(const synfig::String& name, const Action::Param &param)
108 {
109         if(name=="value_node" && param.get_type()==Param::TYPE_VALUENODE)
110         {
111                 value_node=value_node.cast_dynamic(param.get_value_node());
112
113                 return (bool)(value_node);
114         }
115         if(name=="time" && param.get_type()==Param::TYPE_TIME)
116         {
117                 time=param.get_time();
118
119                 return true;
120         }
121
122         return Action::CanvasSpecific::set_param(name,param);
123 }
124
125 bool
126 Action::BLinePointTangentSplit::is_ready()const
127 {
128         if(!value_node)
129                 synfig::error("Missing or bad value_node");
130
131         if(time==(Time::begin()-1))
132                 synfig::error("Missing time");
133
134         if(!value_node || time==(Time::begin()-1))
135                 return false;
136         return Action::CanvasSpecific::is_ready();
137 }
138
139 void
140 Action::BLinePointTangentSplit::prepare()
141 {
142         clear();
143
144         Action::Handle action;
145
146         action=Action::create("value_desc_set");
147         if(!action)
148                 throw Error(_("Couldn't find action \"value_desc_set\""));
149
150         action->set_param("canvas",get_canvas());
151         action->set_param("canvas_interface",get_canvas_interface());
152         action->set_param("value_desc",ValueDesc(value_node,3));
153         action->set_param("time",time);
154         action->set_param("new_value",synfig::ValueBase(true));
155
156         assert(action->is_ready());
157         if(!action->is_ready())
158                 throw Error(Error::TYPE_NOTREADY);
159
160         add_action(action);
161 }