Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / valuenode_or.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_or.cpp
3 **      \brief Implementation of the "Or" valuenode conversion.
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 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 "valuenode_or.h"
35 #include "valuenode_const.h"
36 #include "general.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45
46 /* === M A C R O S ========================================================= */
47
48 /* === G L O B A L S ======================================================= */
49
50 /* === P R O C E D U R E S ================================================= */
51
52 /* === M E T H O D S ======================================================= */
53
54 ValueNode_Or::ValueNode_Or(const ValueBase &x):
55         LinkableValueNode(x.get_type())
56 {
57         Vocab ret(get_children_vocab());
58         set_children_vocab(ret);
59         bool value(x.get(bool()));
60
61         set_link("link1",        ValueNode_Const::create(bool(false)));
62         set_link("link2",        ValueNode_Const::create(bool(false)));
63         if (value)
64                 set_link("link1",ValueNode_Const::create(bool(true)));
65 }
66
67 ValueNode_Or*
68 ValueNode_Or::create(const ValueBase &x)
69 {
70         return new ValueNode_Or(x);
71 }
72
73 LinkableValueNode*
74 ValueNode_Or::create_new()const
75 {
76         return new ValueNode_Or(get_type());
77 }
78
79 ValueNode_Or::~ValueNode_Or()
80 {
81         unlink_all();
82 }
83
84 bool
85 ValueNode_Or::set_link_vfunc(int i,ValueNode::Handle value)
86 {
87         assert(i>=0 && i<link_count());
88
89         switch(i)
90         {
91         case 0: CHECK_TYPE_AND_SET_VALUE(link1_,    ValueBase::TYPE_BOOL);
92         case 1: CHECK_TYPE_AND_SET_VALUE(link2_,    ValueBase::TYPE_BOOL);
93         }
94         return false;
95 }
96
97 ValueNode::LooseHandle
98 ValueNode_Or::get_link_vfunc(int i)const
99 {
100         assert(i>=0 && i<link_count());
101
102         if(i==0) return link1_;
103         if(i==1) return link2_;
104         return 0;
105 }
106
107 ValueBase
108 ValueNode_Or::operator()(Time t)const
109 {
110         if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
111                 printf("%s:%d operator()\n", __FILE__, __LINE__);
112
113         bool link1     = (*link1_)   (t).get(bool());
114         bool link2     = (*link2_)   (t).get(bool());
115
116         return (link1 || link2);
117 }
118
119 String
120 ValueNode_Or::get_name()const
121 {
122         return "or";
123 }
124
125 String
126 ValueNode_Or::get_local_name()const
127 {
128         return _("OR");
129 }
130
131 bool
132 ValueNode_Or::check_type(ValueBase::Type type)
133 {
134         return type==ValueBase::TYPE_BOOL;
135 }
136
137 LinkableValueNode::Vocab
138 ValueNode_Or::get_children_vocab_vfunc()const
139 {
140         if(children_vocab.size())
141                 return children_vocab;
142
143         LinkableValueNode::Vocab ret;
144
145         ret.push_back(ParamDesc(ValueBase(),"link1")
146                 .set_local_name(_("Link1"))
147                 .set_description(_("Value node used for the OR boolean operation"))
148         );
149
150         ret.push_back(ParamDesc(ValueBase(),"link2")
151                 .set_local_name(_("Link2"))
152                 .set_description(_("Value node used for the OR boolean operation"))
153         );
154
155         return ret;
156 }