1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_subtract.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include "valuenode_subtract.h"
34 #include "valuenode_const.h"
43 /* === U S I N G =========================================================== */
47 using namespace synfig;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 synfig::ValueNode_Subtract::ValueNode_Subtract():LinkableValueNode(synfig::ValueBase::TYPE_NIL)
63 ValueNode_Subtract::create_new()const
65 return new ValueNode_Subtract();
69 ValueNode_Subtract::create(const ValueBase& x)
71 ValueBase::Type id(x.get_type());
73 ValueNode_Subtract* value_node=new ValueNode_Subtract();
76 case ValueBase::TYPE_NIL:
78 case ValueBase::TYPE_ANGLE:
79 case ValueBase::TYPE_COLOR:
80 case ValueBase::TYPE_INTEGER:
81 case ValueBase::TYPE_REAL:
82 case ValueBase::TYPE_VECTOR:
83 value_node->set_link("lhs",ValueNode_Const::create(ValueBase(id)));
84 value_node->set_link("rhs",ValueNode_Const::create(ValueBase(id)));
88 throw runtime_error("synfig::ValueNode_Subtract:Bad type "+ValueBase::type_name(id));
91 assert(value_node->get_lhs()->get_type()==id);
92 assert(value_node->get_rhs()->get_type()==id);
94 assert(value_node->get_type()==id);
99 synfig::ValueNode_Subtract::~ValueNode_Subtract()
105 ValueNode_Subtract::set_scalar(Real x)
107 set_link("scalar",ValueNode_Const::create(x));
111 synfig::ValueNode_Subtract::set_scalar(ValueNode::Handle x)
113 if(x->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(x))
120 synfig::ValueNode_Subtract::set_lhs(ValueNode::Handle a)
124 if(PlaceholderValueNode::Handle::cast_dynamic(a))
128 set_type(ValueBase::TYPE_NIL);
130 if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE)
131 set_type(ValueBase::TYPE_ANGLE);
133 if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR)
134 set_type(ValueBase::TYPE_COLOR);
136 if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER)
137 set_type(ValueBase::TYPE_INTEGER);
139 if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL)
140 set_type(ValueBase::TYPE_REAL);
142 if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR)
143 set_type(ValueBase::TYPE_VECTOR);
146 synfig::warning(get_id()+":(set_a):"+strprintf(_("Types seem to be off for ValueNodes %s and %s"),ref_a->get_id().c_str(),ref_b->get_id().c_str()));
147 set_type(ValueBase::TYPE_NIL);
154 synfig::ValueNode_Subtract::set_rhs(ValueNode::Handle b)
158 if(PlaceholderValueNode::Handle::cast_dynamic(b))
162 set_type(ValueBase::TYPE_NIL);
164 if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE)
165 set_type(ValueBase::TYPE_ANGLE);
167 if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR)
168 set_type(ValueBase::TYPE_COLOR);
170 if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER)
171 set_type(ValueBase::TYPE_INTEGER);
173 if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL)
174 set_type(ValueBase::TYPE_REAL);
176 if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR)
177 set_type(ValueBase::TYPE_VECTOR);
180 synfig::warning(get_id()+":(set_b):"+strprintf(_("Types seem to be off for ValueNodes %s and %s"),ref_a->get_id().c_str(),ref_b->get_id().c_str()));
181 set_type(ValueBase::TYPE_NIL);
188 synfig::ValueNode_Subtract::operator()(Time t)const
191 throw runtime_error(strprintf("ValueNode_Subtract: %s",_("One or both of my parameters aren't set!")));
192 if(get_type()==ValueBase::TYPE_ANGLE)
193 return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real());
194 if(get_type()==ValueBase::TYPE_COLOR)
195 return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
196 if(get_type()==ValueBase::TYPE_INTEGER)
197 return ((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real());
198 if(get_type()==ValueBase::TYPE_REAL)
199 return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
200 if(get_type()==ValueBase::TYPE_VECTOR)
201 return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real());
203 synfig::error(get_id()+':'+strprintf(_("Cannot subtract types of %s and %s"),ValueBase::type_name(ref_a->get_type()).c_str(),ValueBase::type_name(ref_b->get_type()).c_str()));
208 ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle x)
214 if(set_lhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
215 else { return false; }
217 if(set_rhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
218 else { return false; }
221 signal_child_changed()(i);signal_value_changed()();
228 ValueNode::LooseHandle
229 ValueNode_Subtract::get_link_vfunc(int i)const
245 ValueNode_Subtract::link_count()const
251 ValueNode_Subtract::link_local_name(int i)const
268 ValueNode_Subtract::link_name(int i)const
285 ValueNode_Subtract::get_link_index_from_name(const String &name)const
293 throw Exception::BadLinkName(name);
297 ValueNode_Subtract::get_name()const
303 ValueNode_Subtract::get_local_name()const
305 return _("Subtract");
309 ValueNode_Subtract::check_type(ValueBase::Type type)
311 return type==ValueBase::TYPE_ANGLE
312 || type==ValueBase::TYPE_COLOR
313 || type==ValueBase::TYPE_INTEGER
314 || type==ValueBase::TYPE_REAL
315 || type==ValueBase::TYPE_VECTOR;