1 /* === S Y N F I G ========================================================= */
3 ** \brief Header file for implementation of the "Placeholder" valuenode conversion.
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === S T A R T =========================================================== */
26 #ifndef __SYNFIG_VALUENODE_H
27 #define __SYNFIG_VALUENODE_H
29 /* === H E A D E R S ======================================================= */
36 #include <ETL/stringf>
37 #include "exception.h"
39 #include <sigc++/signal.h>
42 #ifndef SYNFIG_NO_ANGLE
50 /* === M A C R O S ========================================================= */
52 #define CHECK_TYPE_AND_SET_VALUE(variable, type) \
53 /* I don't think this ever happens - maybe remove this code? */ \
54 if (get_type() == ValueBase::TYPE_NIL) { \
55 warning("%s:%d get_type() IS nil sometimes!", \
56 __FILE__, __LINE__); \
59 if (get_type() != ValueBase::TYPE_NIL && \
60 !(ValueBase::same_type_as(value->get_type(), type)) && \
61 !PlaceholderValueNode::Handle::cast_dynamic(value)) { \
62 error(_("%s:%d wrong type for %s: need %s but got %s"), \
64 link_local_name(i).c_str(), \
65 ValueBase::type_local_name(type).c_str(), \
66 ValueBase::type_local_name(value->get_type()).c_str()); \
70 signal_child_changed()(i); \
71 signal_value_changed()(); \
74 /* === T Y P E D E F S ===================================================== */
76 /* === C L A S S E S & S T R U C T S ======================================= */
81 class LinkableValueNode;
87 class ValueNode : public synfig::Node
90 friend class LinkableValueNode;
93 -- ** -- T Y P E S -----------------------------------------------------------
98 typedef etl::handle<ValueNode> Handle;
100 typedef etl::loose_handle<ValueNode> LooseHandle;
102 typedef etl::handle<const ValueNode> ConstHandle;
104 typedef etl::rhandle<ValueNode> RHandle;
107 static bool subsys_init();
109 static bool subsys_stop();
112 -- ** -- D A T A -------------------------------------------------------------
116 ValueBase::Type type;
118 etl::loose_handle<Canvas> canvas_;
119 etl::loose_handle<Canvas> root_canvas_;
122 -- ** -- S I G N A L S -------------------------------------------------------
127 //! ValueBase Changed
128 sigc::signal<void> signal_value_changed_;
130 //! Children Reordered
131 sigc::signal<void,int*> signal_children_reordered_;
134 sigc::signal<void,int> signal_child_changed_;
137 sigc::signal<void,int> signal_child_removed_;
140 sigc::signal<void,int> signal_child_inserted_;
143 sigc::signal<void> signal_id_changed_;
146 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
151 //! ValueBase Changed
152 sigc::signal<void>& signal_value_changed() { return signal_value_changed_; }
154 //! Children Reordered
155 sigc::signal<void,int*>& signal_children_reordered() { return signal_children_reordered_; }
158 sigc::signal<void,int>& signal_child_changed() { return signal_child_changed_; }
161 sigc::signal<void,int>& signal_child_removed() { return signal_child_removed_; }
164 sigc::signal<void,int>& signal_child_inserted() { return signal_child_inserted_; }
167 sigc::signal<void>& signal_id_changed() { return signal_id_changed_; }
170 -- ** -- C O N S T R U C T O R S ---------------------------------------------
175 ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
179 virtual ~ValueNode();
182 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
187 //! Returns the value of the ValueNode at time \a t
188 virtual ValueBase operator()(Time /*t*/)const
189 { return ValueBase(); }
191 //! \internal Sets the id of the ValueNode
192 void set_id(const String &x);
194 //! Returns the id of the ValueNode
195 /*! The ID is used for keeping track of a
196 ** specific instance of a ValueNode. */
197 const String &get_id()const { return name; }
199 //! Returns the name of the ValueNode type
200 virtual String get_name()const=0;
202 //! Returns the localized name of the ValueNode type
203 virtual String get_local_name()const=0;
205 //! Return a full description of the ValueNode and its parentage
206 virtual String get_description(bool show_exported_name = true)const;
210 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
213 bool is_exported()const { return !get_id().empty(); }
215 //! Returns the type of the ValueNode
216 ValueBase::Type get_type()const { return type; }
218 //! Returns a handle to the parent canvas, if it has one.
219 etl::loose_handle<Canvas> get_parent_canvas()const { return canvas_; }
221 //! Returns a handle to the parent canvas, if it has one.
222 etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
225 void set_parent_canvas(etl::loose_handle<Canvas> x);
228 void set_root_canvas(etl::loose_handle<Canvas> x);
231 String get_relative_id(etl::loose_handle<const Canvas> x)const;
233 int replace(etl::handle<ValueNode> x);
236 //! Sets the type of the ValueNode
237 void set_type(ValueBase::Type t) { type=t; }
239 virtual void on_changed();
240 }; // END of class ValueNode
242 /*! \class PlaceholderValueNode
245 class PlaceholderValueNode : public ValueNode
248 typedef etl::handle<PlaceholderValueNode> Handle;
249 typedef etl::loose_handle<PlaceholderValueNode> LooseHandle;
250 typedef etl::handle<const PlaceholderValueNode> ConstHandle;
251 typedef etl::rhandle<PlaceholderValueNode> RHandle;
255 PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
259 virtual ValueBase operator()(Time t)const;
261 virtual String get_name()const;
263 virtual String get_local_name()const;
265 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
267 static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
270 virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
271 }; // END of class PlaceholderValueNode
274 /*! \class LinkableValueNode
277 class LinkableValueNode : public ValueNode
279 friend class ValueNode;
282 typedef etl::handle<LinkableValueNode> Handle;
284 typedef etl::loose_handle<LinkableValueNode> LooseHandle;
286 typedef etl::handle<const LinkableValueNode> ConstHandle;
288 typedef etl::rhandle<LinkableValueNode> RHandle;
291 //! Type that represents a pointer to a ValueNode's constructor
292 /*! As a pointer to the constructor, it represents a "factory" of
293 ** objects of this class.
295 typedef LinkableValueNode* (*Factory)(const ValueBase&);
297 typedef bool (*CheckType)(ValueBase::Type);
303 CheckType check_type;
304 ReleaseVersion release_version; // which version of synfig introduced this valuenode type
307 //! Book of types of linkable value nodes indexed by type name.
308 /*! While the sifz file is read, each time a new LinkableValueNode entry
309 ** is found, the factory constructor that the "factory" pointer member
310 ** of the "BookEntry" struct points to, is called, and a new object of
311 ** that type is created.
312 ** \sa LinkableValueNode::Factory
314 typedef std::map<String,BookEntry> Book;
318 static Handle create(const String &name, const ValueBase& x);
320 static bool check_type(const String &name, ValueBase::Type x);
323 LinkableValueNode(ValueBase::Type type=ValueBase::TYPE_NIL):
327 virtual bool set_link_vfunc(int i,ValueNode::Handle x)=0;
333 virtual int link_count()const=0;
335 virtual String link_local_name(int i)const=0;
337 virtual String link_name(int i)const=0;
339 virtual int get_link_index_from_name(const String &name)const=0;
341 virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
343 bool set_link(int i,ValueNode::Handle x);
344 bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x); }
346 ValueNode::LooseHandle get_link(int i)const;
347 ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
350 get_description(int index = -1, bool show_exported_name = true)const;
353 //! Sets the type of the ValueNode
354 void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
356 virtual ValueNode::LooseHandle get_link_vfunc(int i)const=0;
358 // Wrapper for new operator, used by clone()
359 virtual LinkableValueNode* create_new()const=0;
361 virtual void get_times_vfunc(Node::time_set &set) const;
362 }; // END of class LinkableValueNode
364 /*! \class ValueNodeList
365 ** \brief A searchable value_node list container
366 ** \warning Do not confuse with ValueNode_DynamicList!
369 class ValueNodeList : public std::list<ValueNode::RHandle>
371 int placeholder_count_;
375 //! Finds the ValueNode in the list with the given \a name
376 /*! \return If found, returns a handle to the ValueNode.
377 ** Otherwise, returns an empty handle.
379 ValueNode::Handle find(const String &name);
381 //! Finds the ValueNode in the list with the given \a name
382 /*! \return If found, returns a handle to the ValueNode.
383 ** Otherwise, returns an empty handle.
385 ValueNode::ConstHandle find(const String &name)const;
387 //! Removes the \a value_node from the list
388 bool erase(ValueNode::Handle value_node);
391 bool add(ValueNode::Handle value_node);
394 bool count(const String &id)const;
396 //! Similar to find, but will create a placeholder value_node if it cannot be found.
397 ValueNode::Handle surefind(const String &name);
399 //! Removes any value_nodes with reference counts of 1.
402 //! Placeholder Count
403 int placeholder_count()const { return placeholder_count_; }
406 ValueNode::LooseHandle find_value_node(const GUID& guid);
408 }; // END of namespace synfig
410 /* === E N D =============================================================== */