- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# value_desc.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00022 /* ========================================================================= */
    00023
    00024 /* === S T A R T =========================================================== */
    00025
    00026 #ifndef __SYNFIG_APP_VALUE_DESC_H
    00027 #define __SYNFIG_APP_VALUE_DESC_H
    00028
    00029 /* === H E A D E R S ======================================================= */
    00030
    00031 #include <synfig/valuenode.h>
    00032 #include <synfig/string.h>
    00033 #include <synfig/layer.h>
    00034 #include <synfig/value.h>
    00035 #include <synfig/valuenode_animated.h>
    00036 #include <synfig/valuenode_const.h>
    00037 #include <synfig/canvas.h>
    00038
    00039 /* === M A C R O S ========================================================= */
    00040
    00041 /* === T Y P E D E F S ===================================================== */
    00042
    00043 /* === C L A S S E S & S T R U C T S ======================================= */
    00044
    00045 namespace synfigapp {
    00046
    00047 class ValueDesc
    00048 {
    00049     // Info for Layer parent
    00050     synfig::Layer::Handle layer;
    00051     synfig::String name;
    00052
    00053     // Info for ValueNode parent
    00054     synfig::ValueNode::Handle parent_value_node;
    00055     int index;                  // -2 if it's a waypoint, -1 if it's const, >=0 if it's LinkableValueNode
    00056     synfig::Time waypoint_time;
    00057
    00058     // Info for exported ValueNode
    00059     synfig::Canvas::Handle canvas;
    00060
    00061 public:
    00062     bool operator==(const ValueDesc &rhs)const
    00063     {
    00064         if((layer||rhs.layer) && layer!=rhs.layer)
    00065             return false;
    00066         if((!name.empty()||!rhs.name.empty()) && name!=rhs.name)
    00067             return false;
    00068         if(layer)
    00069             return true;
    00070         if((canvas||rhs.canvas) && canvas!=rhs.canvas)
    00071             return false;
    00072         if((parent_value_node||rhs.parent_value_node) && parent_value_node!=rhs.parent_value_node)
    00073             return false;
    00074         if(index!=rhs.index)
    00075             return false;
    00076         return true;
    00077     }
    00078     bool operator!=(const ValueDesc &rhs)const
    00079     {
    00080         return !operator==(rhs);
    00081     }
    00082
    00083
    00084     ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name):
    00085         layer(layer),
    00086         name(param_name) { }
    00087
    00088     ValueDesc(synfig::Layer::LooseHandle layer,const synfig::String& param_name):
    00089         layer(layer),
    00090         name(param_name) { }
    00091
    00092     ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,int index):
    00093         parent_value_node(parent_value_node),
    00094         index(index) { }
    00095
    00096 //  ValueDesc(synfig::LinkableValueNode::Handle parent_value_node,const synfig::String& param_name):
    00097 //      parent_value_node(parent_value_node),
    00098 //      index(parent_value_node->get_link_index_from_name(param_name)) { }
    00099
    00100     ValueDesc(synfig::ValueNode_Animated::Handle parent_value_node,synfig::Time waypoint_time):
    00101         parent_value_node(parent_value_node),
    00102         index(-2),
    00103         waypoint_time(waypoint_time) { }
    00104
    00105     ValueDesc(synfig::Canvas::Handle canvas,const synfig::String& name):
    00106         name(name),
    00107         canvas(canvas) { }
    00108
    00109     ValueDesc(synfig::ValueNode_Const::Handle parent_value_node):
    00110         parent_value_node(parent_value_node),
    00111         index(-1) { }
    00112
    00113     ValueDesc() { }
    00114
    00115     bool is_valid()const { return layer || parent_value_node || canvas; }
    00116     operator bool()const { return is_valid(); }
    00117
    00118     bool parent_is_layer_param()const { return (bool)layer; }
    00119     bool parent_is_value_node()const { return (bool)parent_value_node; }
    00120     bool parent_is_linkable_value_node()const { return parent_is_value_node() && index>=0; }
    00121     bool parent_is_value_node_const()const { return parent_is_value_node() && index==-1; }
    00122     bool parent_is_waypoint()const { return parent_is_value_node() && index==-2; }
    00123     bool parent_is_canvas()const { return (bool)canvas; }
    00124
    00125     bool is_value_node()const { return parent_is_value_node() || parent_is_canvas() || (parent_is_layer_param() && (bool)layer->dynamic_param_list().count(name)); }
    00126     bool is_const()const { return (parent_is_layer_param() && !layer->dynamic_param_list().count(name)) || parent_is_value_node_const(); }
    00127
    00128     synfig::Layer::Handle get_layer()const { assert(parent_is_layer_param()); return layer; }
    00129     const synfig::String& get_param_name()const { assert(parent_is_layer_param()); return name; }
    00130
    00131     synfig::ValueNode::Handle get_parent_value_node()const { assert(parent_is_value_node()); return parent_value_node; }
    00132     int get_index()const { assert(parent_is_linkable_value_node()); return index; }
    00133     synfig::Time get_waypoint_time()const { assert(parent_is_waypoint()); return waypoint_time; }
    00134
    00135     const synfig::String& get_value_node_id()const { assert(parent_is_canvas()); return name; }
    00136
    00137     synfig::Canvas::Handle get_canvas()const
    00138     {
    00139         if(canvas)
    00140             return canvas;
    00141         if(layer)
    00142             return layer->get_canvas();
    00143         if(parent_value_node)
    00144             return parent_value_node->get_root_canvas();
    00145         return 0;
    00146     }
    00147
    00148     synfig::ValueNode::Handle
    00149     get_value_node()const
    00150     {
    00151         if(parent_is_canvas())
    00152             return canvas->find_value_node(name);
    00153         if(parent_is_layer_param() && layer->dynamic_param_list().count(name))
    00154             return layer->dynamic_param_list().find(name)->second;
    00155         if(parent_is_linkable_value_node())
    00156             return (synfig::LinkableValueNode::Handle::cast_reinterpret(parent_value_node))->get_link(index);
    00157 //          return reinterpret_cast<synfig::LinkableValueNode*>(parent_value_node.get())->get_link(index);
    00158         if(parent_is_value_node_const())
    00159             return parent_value_node;
    00160         if(parent_is_waypoint())
    00161             return (synfig::ValueNode_Animated::Handle::cast_reinterpret(parent_value_node))->find(waypoint_time)->get_value_node();
    00162         return 0;
    00163     }
    00164
    00165     synfig::ValueBase
    00166     get_value(synfig::Time time=0)const
    00167     {
    00168         // if the value is constant, return that constant value (at *any* time, it doesn't matter which)
    00169         if(parent_is_value_node_const())
    00170             return (*parent_value_node)(0);
    00171         if(is_value_node() && get_value_node())
    00172             return (*get_value_node())(time);
    00173         if(parent_is_layer_param() && layer)
    00174             return layer->get_param(name);
    00175         return synfig::ValueBase();
    00176     }
    00177
    00178     synfig::ValueBase::Type
    00179     get_value_type()const
    00180     {
    00181         synfig::ValueNode::Handle value_node=get_value_node();
    00182         if(value_node)
    00183             return value_node->get_type();
    00184         return get_value().get_type();
    00185     }
    00186
    00187     bool
    00188     is_exported()const
    00189     {
    00190         return is_value_node() && get_value_node()->is_exported();
    00191     }
    00192
    00193     synfig::String
    00194     get_description(bool show_exported_name = true)const;
    00195 }; // END of class ValueDesc
    00196
    00197 }; // END of namespace synfigapp_instance
    00198
    00199 /* === E N D =============================================================== */
    00200
    00201 #endif