1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_subtract.cpp
3 ** \brief Template File
5 ** $Id: valuenode_subtract.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include "valuenode_subtract.h"
33 #include "valuenode_const.h"
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 synfig::ValueNode_Subtract::ValueNode_Subtract():LinkableValueNode(synfig::ValueBase::TYPE_NIL)
62 ValueNode_Subtract::create_new()const
64 return new ValueNode_Subtract();
68 ValueNode_Subtract::create(const ValueBase& x)
70 ValueBase::Type id(x.get_type());
72 ValueNode_Subtract* value_node=new ValueNode_Subtract();
75 case ValueBase::TYPE_NIL:
77 case ValueBase::TYPE_VECTOR:
78 case ValueBase::TYPE_REAL:
79 case ValueBase::TYPE_INTEGER:
80 case ValueBase::TYPE_ANGLE:
81 value_node->set_link("rhs",ValueNode_Const::create(ValueBase(id)));
82 value_node->set_link("lhs",ValueNode_Const::create(ValueBase(id)));
83 assert(value_node->get_rhs()->get_type()==id);
84 assert(value_node->get_lhs()->get_type()==id);
88 throw runtime_error("synfig::ValueNode_Subtract:Bad type "+ValueBase::type_name(id));
90 assert(value_node->get_type()==id);
95 synfig::ValueNode_Subtract::~ValueNode_Subtract()
101 ValueNode_Subtract::set_scalar(Real x)
103 set_link("scalar",ValueNode_Const::create(x));
107 synfig::ValueNode_Subtract::set_scalar(ValueNode::Handle x)
109 if(x->get_type()!=ValueBase::TYPE_REAL&& !PlaceholderValueNode::Handle::cast_dynamic(x))
116 synfig::ValueNode_Subtract::set_lhs(ValueNode::Handle a)
120 if(PlaceholderValueNode::Handle::cast_dynamic(a))
124 set_type(ValueBase::TYPE_NIL);
126 if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR)
127 set_type(ValueBase::TYPE_VECTOR);
129 if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL)
130 set_type(ValueBase::TYPE_REAL);
132 if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER)
133 set_type(ValueBase::TYPE_INTEGER);
135 if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE)
136 set_type(ValueBase::TYPE_ANGLE);
138 if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR)
139 set_type(ValueBase::TYPE_COLOR);
142 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()));
143 set_type(ValueBase::TYPE_NIL);
150 synfig::ValueNode_Subtract::set_rhs(ValueNode::Handle b)
154 if(PlaceholderValueNode::Handle::cast_dynamic(b))
158 set_type(ValueBase::TYPE_NIL);
160 if(ref_a->get_type()==ValueBase::TYPE_VECTOR && ref_a->get_type()==ValueBase::TYPE_VECTOR)
161 set_type(ValueBase::TYPE_VECTOR);
163 if(ref_a->get_type()==ValueBase::TYPE_REAL && ref_a->get_type()==ValueBase::TYPE_REAL)
164 set_type(ValueBase::TYPE_REAL);
166 if(ref_a->get_type()==ValueBase::TYPE_INTEGER && ref_a->get_type()==ValueBase::TYPE_INTEGER)
167 set_type(ValueBase::TYPE_INTEGER);
169 if(ref_a->get_type()==ValueBase::TYPE_ANGLE && ref_a->get_type()==ValueBase::TYPE_ANGLE)
170 set_type(ValueBase::TYPE_ANGLE);
172 if(ref_a->get_type()==ValueBase::TYPE_COLOR && ref_a->get_type()==ValueBase::TYPE_COLOR)
173 set_type(ValueBase::TYPE_COLOR);
176 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()));
177 set_type(ValueBase::TYPE_NIL);
184 synfig::ValueNode_Subtract::operator()(Time t)const
187 throw runtime_error(strprintf("ValueNode_Subtract: %s",_("One or both of my parameters aren't set!")));
189 if(get_type()==ValueBase::TYPE_VECTOR)
190 return ((*ref_a)(t).get(Vector())-(*ref_b)(t).get(Vector()))*(*scalar)(t).get(Real());
192 if(get_type()==ValueBase::TYPE_REAL)
193 return ((*ref_a)(t).get(Vector::value_type())-(*ref_b)(t).get(Vector::value_type()))*(*scalar)(t).get(Real());
195 if(get_type()==ValueBase::TYPE_INTEGER)
196 return ((*ref_a)(t).get(int())-(*ref_b)(t).get(int()))*(*scalar)(t).get(Real());
198 if(get_type()==ValueBase::TYPE_ANGLE)
199 return ((*ref_a)(t).get(Angle())-(*ref_b)(t).get(Angle()))*(*scalar)(t).get(Real());
201 if(get_type()==ValueBase::TYPE_COLOR)
202 return ((*ref_a)(t).get(Color())-(*ref_b)(t).get(Color()))*(*scalar)(t).get(Real());
204 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()));
209 ValueNode_Subtract::set_link_vfunc(int i,ValueNode::Handle x)
215 if(set_lhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
216 else { return false; }
218 if(set_rhs(x)) { signal_child_changed()(i);signal_value_changed()(); return true; }
219 else { return false; }
222 signal_child_changed()(i);signal_value_changed()();
229 ValueNode::LooseHandle
230 ValueNode_Subtract::get_link_vfunc(int i)const
246 ValueNode_Subtract::link_count()const
252 ValueNode_Subtract::link_local_name(int i)const
268 ValueNode_Subtract::link_name(int i)const
284 ValueNode_Subtract::get_link_index_from_name(const String &name)const
292 throw Exception::BadLinkName(name);
296 ValueNode_Subtract::get_name()const
302 ValueNode_Subtract::get_local_name()const
304 return _("Subtract");
308 ValueNode_Subtract::check_type(ValueBase::Type type)
310 return type==ValueBase::TYPE_VECTOR
311 || type==ValueBase::TYPE_REAL
312 || type==ValueBase::TYPE_INTEGER
313 || type==ValueBase::TYPE_COLOR
314 || type==ValueBase::TYPE_ANGLE;