Added copyright lines for files I've edited this year.
[synfig.git] / synfig-core / trunk / src / synfig / valuenode.h
index a9d9f89..bf58504 100644 (file)
@@ -1,34 +1,37 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file valuenode.h
-**     \brief Template Header
+**     \brief Header file for implementation of the "Placeholder" valuenode conversion.
 **
-**     $Id: valuenode.h,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
 
 /* === S T A R T =========================================================== */
 
-#ifndef __SINFG_VALUENODE_H
-#define __SINFG_VALUENODE_H
+#ifndef __SYNFIG_VALUENODE_H
+#define __SYNFIG_VALUENODE_H
 
 /* === H E A D E R S ======================================================= */
 
 #include "vector.h"
 #include "value.h"
 #include "string.h"
+#include "releases.h"
 #include <ETL/handle>
 #include <ETL/stringf>
 #include "exception.h"
@@ -36,7 +39,7 @@
 #include <sigc++/signal.h>
 #include "guid.h"
 
-#ifndef SINFG_NO_ANGLE
+#ifndef SYNFIG_NO_ANGLE
 #include <ETL/angle>
 #endif
 
 # define DCAST_HACK_ENABLE()
 #endif
 
+#define CHECK_TYPE_AND_SET_VALUE(variable, type)                                               \
+       /* I don't think this ever happens - maybe remove this code? */         \
+       if (get_type() == ValueBase::TYPE_NIL) {                                                        \
+               warning("%s:%d get_type() IS nil sometimes!",                                   \
+                               __FILE__, __LINE__);                                                                    \
+               return false;                                                                                                   \
+       }                                                                                                                                       \
+       if (get_type() != ValueBase::TYPE_NIL &&                                                        \
+               !(ValueBase::same_type_as(value->get_type(), type)) &&                  \
+               !PlaceholderValueNode::Handle::cast_dynamic(value)) {                   \
+               error(_("%s:%d wrong type for %s: need %s but got %s"),                 \
+                         __FILE__, __LINE__,                                                                           \
+                         link_local_name(i).c_str(),                                                           \
+                         ValueBase::type_local_name(type).c_str(),                                     \
+                         ValueBase::type_local_name(value->get_type()).c_str());       \
+               return false;                                                                                                   \
+       }                                                                                                                                       \
+       variable = value;                                                                                                       \
+       signal_child_changed()(i);                                                                                      \
+       signal_value_changed()();                                                                                       \
+       return true
+
 /* === T Y P E D E F S ===================================================== */
 
 /* === C L A S S E S & S T R U C T S ======================================= */
 
-namespace sinfg {
+namespace synfig {
 
 class Canvas;
 class LinkableValueNode;
 class Layer;
-       
+
 /*!    \class ValueNode
 **     \todo writeme
 */
-class ValueNode : public sinfg::Node
+class ValueNode : public synfig::Node
 {
        friend class Layer;
        friend class LinkableValueNode;
-               
+
        /*
  --    ** -- T Y P E S -----------------------------------------------------------
        */
@@ -104,7 +129,7 @@ private:
        String name;
        etl::loose_handle<Canvas> canvas_;
        etl::loose_handle<Canvas> root_canvas_;
-       
+
        /*
  -- ** -- S I G N A L S -------------------------------------------------------
        */
@@ -112,22 +137,22 @@ private:
 private:
 
        //!     ValueBase Changed
-       sigc::signal<void> signal_value_changed_;       
+       sigc::signal<void> signal_value_changed_;
 
        //!     Children Reordered
-       sigc::signal<void,int*> signal_children_reordered_;     
+       sigc::signal<void,int*> signal_children_reordered_;
 
        //!     Child Changed
-       sigc::signal<void,int> signal_child_changed_;   
+       sigc::signal<void,int> signal_child_changed_;
 
        //!     Child Removed
-       sigc::signal<void,int> signal_child_removed_;   
+       sigc::signal<void,int> signal_child_removed_;
 
        //!     Child Inserted
-       sigc::signal<void,int> signal_child_inserted_;  
+       sigc::signal<void,int> signal_child_inserted_;
 
        //!     ID Changed
-       sigc::signal<void> signal_id_changed_;  
+       sigc::signal<void> signal_id_changed_;
 
        /*
  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
@@ -158,7 +183,7 @@ public:
        */
 
 protected:
-       
+
        ValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
 
 public:
@@ -172,7 +197,7 @@ public:
 public:
 
        //! Returns the value of the ValueNode at time \a t
-       virtual ValueBase operator()(Time t)const
+       virtual ValueBase operator()(Time /*t*/)const
                { return ValueBase(); }
 
        //! \internal Sets the id of the ValueNode
@@ -189,13 +214,16 @@ public:
        //! Returns the localized name of the ValueNode type
        virtual String get_local_name()const=0;
 
+       //! Return a full description of the ValueNode and its parentage
+       virtual String get_description(bool show_exported_name = true)const;
+
 
        //! \writeme
        virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
 
        //! \writeme
        bool is_exported()const { return !get_id().empty(); }
-       
+
        //! Returns the type of the ValueNode
        ValueBase::Type get_type()const { return type; }
 
@@ -204,24 +232,24 @@ public:
 
        //! Returns a handle to the parent canvas, if it has one.
        etl::loose_handle<Canvas> get_root_canvas()const { return root_canvas_; }
-       
+
        //! \writeme
        void set_parent_canvas(etl::loose_handle<Canvas> x);
 
        //! \writeme
        void set_root_canvas(etl::loose_handle<Canvas> x);
-       
+
        //! \writeme
        String get_relative_id(etl::loose_handle<const Canvas> x)const;
-       
+
        int replace(etl::handle<ValueNode> x);
-       
+
 protected:
        //! Sets the type of the ValueNode
        void set_type(ValueBase::Type t) { type=t; }
 
        virtual void on_changed();
-       
+
 public:
        DCAST_HACK_BASECLASS();
        DCAST_HACK_ID(0);
@@ -243,7 +271,7 @@ private:
        PlaceholderValueNode(ValueBase::Type type=ValueBase::TYPE_NIL);
 
 public:
-       
+
        virtual ValueBase operator()(Time t)const;
 
        virtual String get_name()const;
@@ -255,7 +283,7 @@ public:
        static Handle create(ValueBase::Type type=ValueBase::TYPE_NIL);
 
 protected:
-       virtual void get_times_vfunc(Node::time_set &set) const {}
+       virtual void get_times_vfunc(Node::time_set &/*set*/) const {}
 }; // END of class PlaceholderValueNode
 
 
@@ -285,9 +313,10 @@ public:
        {
                String local_name;
                Factory factory;
-               CheckType check_type;           
+               CheckType check_type;
+               ReleaseVersion release_version; // which version of synfig introduced this valuenode type
        };
-       
+
        typedef std::map<String,BookEntry> Book;
 
        static Book& book();
@@ -306,7 +335,7 @@ protected:
        void unlink_all();
 
 public:
-       
+
        virtual int link_count()const=0;
 
        virtual String link_local_name(int i)const=0;
@@ -314,15 +343,18 @@ public:
        virtual String link_name(int i)const=0;
 
        virtual int get_link_index_from_name(const String &name)const=0;
-               
+
        virtual ValueNode* clone(const GUID& deriv_guid=GUID())const;
 
        bool set_link(int i,ValueNode::Handle x);
-       bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x);      }               
-               
+       bool set_link(const String &name,ValueNode::Handle x) { return set_link(get_link_index_from_name(name),x);      }
+
        ValueNode::LooseHandle get_link(int i)const;
        ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
 
+       String
+       get_description(int index, bool show_exported_name = true)const;
+
 protected:
        //! Sets the type of the ValueNode
        void set_type(ValueBase::Type t) { ValueNode::set_type(t); }
@@ -331,7 +363,7 @@ protected:
 
        // Wrapper for new operator, used by clone()
        virtual LinkableValueNode* create_new()const=0;
-       
+
        virtual void get_times_vfunc(Node::time_set &set) const;
 }; // END of class LinkableValueNode
 
@@ -372,14 +404,14 @@ public:
 
        //! Removes any value_nodes with reference counts of 1.
        void audit();
-       
+
        //! Placeholder Count
        int placeholder_count()const { return placeholder_count_; }
 };
 
 ValueNode::LooseHandle find_value_node(const GUID& guid);
 
-}; // END of namespace sinfg
+}; // END of namespace synfig
 
 /* === E N D =============================================================== */