1 /* === S Y N F I G ========================================================= */
2 /*! \file valuenode_or.cpp
3 ** \brief Implementation of the "Or" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
10 ** Copyright (c) 2009 Nikita Kitaev
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.
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.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "valuenode_or.h"
35 #include "valuenode_const.h"
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 ValueNode_Or::ValueNode_Or(const ValueBase &x):
55 LinkableValueNode(x.get_type())
57 Vocab ret(get_children_vocab());
58 set_children_vocab(ret);
59 bool value(x.get(bool()));
61 set_link("link1", ValueNode_Const::create(bool(false)));
62 set_link("link2", ValueNode_Const::create(bool(false)));
64 set_link("link1",ValueNode_Const::create(bool(true)));
68 ValueNode_Or::create(const ValueBase &x)
70 return new ValueNode_Or(x);
74 ValueNode_Or::create_new()const
76 return new ValueNode_Or(get_type());
79 ValueNode_Or::~ValueNode_Or()
85 ValueNode_Or::set_link_vfunc(int i,ValueNode::Handle value)
87 assert(i>=0 && i<link_count());
91 case 0: CHECK_TYPE_AND_SET_VALUE(link1_, ValueBase::TYPE_BOOL);
92 case 1: CHECK_TYPE_AND_SET_VALUE(link2_, ValueBase::TYPE_BOOL);
97 ValueNode::LooseHandle
98 ValueNode_Or::get_link_vfunc(int i)const
100 assert(i>=0 && i<link_count());
102 if(i==0) return link1_;
103 if(i==1) return link2_;
108 ValueNode_Or::link_count()const
114 ValueNode_Or::link_local_name(int i)const
116 assert(i>=0 && i<link_count());
118 if(i==0) return _("Link1");
119 if(i==1) return _("Link2");
124 ValueNode_Or::link_name(int i)const
126 assert(i>=0 && i<link_count());
128 if(i==0) return "link1";
129 if(i==1) return "link2";
134 ValueNode_Or::get_link_index_from_name(const String &name)const
136 if(name=="link1") return 0;
137 if(name=="link2") return 1;
139 throw Exception::BadLinkName(name);
143 ValueNode_Or::operator()(Time t)const
145 if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
146 printf("%s:%d operator()\n", __FILE__, __LINE__);
148 bool link1 = (*link1_) (t).get(bool());
149 bool link2 = (*link2_) (t).get(bool());
151 return (link1 || link2);
155 ValueNode_Or::get_name()const
161 ValueNode_Or::get_local_name()const
167 ValueNode_Or::check_type(ValueBase::Type type)
169 return type==ValueBase::TYPE_BOOL;
172 LinkableValueNode::Vocab
173 ValueNode_Or::get_children_vocab_vfunc()const
175 if(children_vocab.size())
176 return children_vocab;
178 LinkableValueNode::Vocab ret;
180 ret.push_back(ParamDesc(ValueBase(),"link1")
181 .set_local_name(_("Link1"))
182 .set_description(_("Value node used for the OR boolean operation"))
185 ret.push_back(ParamDesc(ValueBase(),"link2")
186 .set_local_name(_("Link2"))
187 .set_description(_("Value node used for the OR boolean operation"))