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