1 /* === S I N F G =========================================================== */
2 /*! \file valuenode_scale.cpp
3 ** \brief Template File
5 ** $Id: valuenode_scale.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_scale.h"
33 #include "valuenode_const.h"
43 /* === U S I N G =========================================================== */
47 using namespace sinfg;
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 ValueNode_Scale::ValueNode_Scale():LinkableValueNode(sinfg::ValueBase::TYPE_NIL)
63 ValueNode_Scale::create(const ValueBase& x)
65 ValueNode_Scale* value_node;
68 case ValueBase::TYPE_VECTOR:
69 case ValueBase::TYPE_REAL:
70 case ValueBase::TYPE_TIME:
71 case ValueBase::TYPE_INTEGER:
72 case ValueBase::TYPE_ANGLE:
73 case ValueBase::TYPE_COLOR:
74 value_node=new ValueNode_Scale();
75 if(!value_node->set_value_node(ValueNode_Const::create(x)))
77 assert(value_node->get_value_node()->get_type()==x.get_type());
81 throw runtime_error("sinfg::ValueNode_Scale:Bad type "+ValueBase::type_name(x.get_type()));
84 assert(value_node->get_type()==x.get_type());
90 ValueNode_Scale::create_new()const
92 return new ValueNode_Scale();
95 sinfg::ValueNode_Scale::~ValueNode_Scale()
101 ValueNode_Scale::set_scalar(Real x)
103 set_link("scalar",ValueNode::Handle(ValueNode_Const::create(x)));
107 ValueNode_Scale::set_scalar(const ValueNode::Handle &x)
110 || x->get_type()!=ValueBase::TYPE_REAL
111 && !PlaceholderValueNode::Handle::cast_dynamic(x)
119 ValueNode_Scale::get_scalar()const
125 ValueNode_Scale::set_value_node(const ValueNode::Handle &x)
128 || ( get_type()==ValueBase::TYPE_NIL
129 && !check_type(x->get_type()) )
130 || ( get_type()!=ValueBase::TYPE_NIL
131 && x->get_type()!=get_type() ) &&
132 !PlaceholderValueNode::Handle::cast_dynamic(x)
136 assert(!(PlaceholderValueNode::Handle::cast_dynamic(x) && !get_type()));
141 set_type(x->get_type());
147 ValueNode_Scale::get_value_node()const
154 sinfg::ValueNode_Scale::operator()(Time t)const
156 if(!value_node || !scalar)
157 throw runtime_error(strprintf("ValueNode_Scale: %s",_("One or both of my parameters aren't set!")));
159 if(get_type()==ValueBase::TYPE_VECTOR)
160 return (*value_node)(t).get(Vector())*(*scalar)(t).get(Real());
162 if(get_type()==ValueBase::TYPE_REAL)
163 return (*value_node)(t).get(Real())*(*scalar)(t).get(Real());
165 if(get_type()==ValueBase::TYPE_TIME)
166 return (*value_node)(t).get(Time())*(*scalar)(t).get(Time());
168 if(get_type()==ValueBase::TYPE_INTEGER)
169 return (*value_node)(t).get(int())*(*scalar)(t).get(Real());
171 if(get_type()==ValueBase::TYPE_ANGLE)
172 return (*value_node)(t).get(Angle())*(*scalar)(t).get(Real());
174 if(get_type()==ValueBase::TYPE_COLOR)
176 Color ret((*value_node)(t).get(Color()));
177 Real s((*scalar)(t).get(Real()));
178 ret.set_r(ret.get_r()*s);
179 ret.set_g(ret.get_r()*s);
180 ret.set_b(ret.get_r()*s);
190 ValueNode_Scale::set_link_vfunc(int i,ValueNode::Handle x)
195 if(i==0 && !set_value_node(x))
198 if(i==1 && !set_scalar(x))
201 signal_child_changed()(i);signal_value_changed()();
206 ValueNode::LooseHandle
207 ValueNode_Scale::get_link_vfunc(int i)const
209 assert(i==0 || i==1);
218 ValueNode_Scale::link_count()const
224 ValueNode_Scale::link_local_name(int i)const
226 assert(i==0 || i==1);
235 ValueNode_Scale::link_name(int i)const
237 assert(i==0 || i==1);
246 ValueNode_Scale::get_link_index_from_name(const String &name)const
253 throw Exception::BadLinkName(name);
257 ValueNode_Scale::get_name()const
263 ValueNode_Scale::get_local_name()const
269 ValueNode_Scale::check_type(ValueBase::Type type)
272 type==ValueBase::TYPE_VECTOR ||
273 type==ValueBase::TYPE_REAL ||
274 type==ValueBase::TYPE_INTEGER ||
275 type==ValueBase::TYPE_COLOR ||
276 type==ValueBase::TYPE_ANGLE;