Add information about which valuenode types were added in which release. Don't save...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 8 Feb 2008 14:03:38 +0000 (14:03 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 8 Feb 2008 14:03:38 +0000 (14:03 +0000)
git-svn-id: http://svn.voria.com/code@1626 1f10aa63-cdf2-0310-b900-c93c546f37ac

12 files changed:
synfig-core/trunk/src/modules/mod_noise/main.cpp
synfig-core/trunk/src/synfig/Makefile.am
synfig-core/trunk/src/synfig/module.h
synfig-core/trunk/src/synfig/releases.h [new file with mode: 0644]
synfig-core/trunk/src/synfig/savecanvas.cpp
synfig-core/trunk/src/synfig/savecanvas.h
synfig-core/trunk/src/synfig/valuenode.cpp
synfig-core/trunk/src/synfig/valuenode.h
synfig-core/trunk/src/synfig/valuenode_composite.cpp
synfig-core/trunk/src/synfig/valuenode_radialcomposite.cpp
synfig-studio/trunk/src/gtkmm/app.cpp
synfig-studio/trunk/src/gtkmm/instance.cpp

index f9ef6dd..e4e8d1d 100644 (file)
@@ -62,6 +62,6 @@ MODULE_INVENTORY_BEGIN(libmod_noise)
        END_LAYERS
 
        BEGIN_VALUENODES
-               VALUENODE(synfig::ValueNode_Random, "random", _("Random"))
+               VALUENODE(synfig::ValueNode_Random, "random", _("Random"), synfig::RELEASE_VERSION_0_61_08) // SVN r907
        END_VALUENODES
 MODULE_INVENTORY_END
index 4f5d9b7..4895302 100644 (file)
@@ -51,8 +51,8 @@ VALUESOURCES = \
        blinepoint.cpp gradient.cpp value.cpp
 
 SYNFIGHEADERS = \
-       angle.h canvasbase.h general.h guidset.h interpolation.h nodebase.h protocol.h quick_rng.h real.h segment.h     \
-       smartfile.h string.h string_decl.h surfacenew.h synfig.h types.h vector.h version.h                             \
+       angle.h canvasbase.h general.h guidset.h interpolation.h nodebase.h protocol.h quick_rng.h real.h releases.h    \
+       segment.h smartfile.h string.h string_decl.h surfacenew.h synfig.h types.h vector.h version.h                   \
        activepoint.h   blur.h   canvas.h   color.h   context.h   curve_helper.h   curveset.h   distance.h              \
        exception.h   gamma.h   guid.h   importer.h   keyframe.h   layer.h   loadcanvas.h   main.h   module.h           \
        mutex.h   node.h   palette.h   paramdesc.h   polynomial_root.h   rect.h   renddesc.h   render.h                 \
index 6aab53a..e618820 100644 (file)
@@ -31,6 +31,7 @@
 #include <ETL/handle>
 #include <map>
 #include "string.h"
+#include "releases.h"
 #include <utility>
 #include "vector.h"
 #include "color.h"
 //! Marks the start of the valuenodes in the module's inventory
 #define BEGIN_VALUENODES { synfig::LinkableValueNode::Book &book(synfig::LinkableValueNode::book());
 
-#define VALUENODE(class,name,local)                                                                                                                            \
+#define VALUENODE(class,name,local,version)                                                                                                            \
        book[name].factory=reinterpret_cast<synfig::LinkableValueNode::Factory>(&class::create);        \
        book[name].check_type=&class::check_type;                                                                                                       \
-       book[name].local_name=local;
+       book[name].local_name=local;                                                                                                                            \
+       book[name].release_version=version;
 
 //! Marks the end of the valuenodes in the module's inventory
 #define END_VALUENODES }
diff --git a/synfig-core/trunk/src/synfig/releases.h b/synfig-core/trunk/src/synfig/releases.h
new file mode 100644 (file)
index 0000000..9ff3dd0
--- /dev/null
@@ -0,0 +1,49 @@
+/* === S Y N F I G ========================================================= */
+/*!    \file releases.h
+**     \brief Define the synfig releases, for tying to features
+**
+**     $Id$
+**
+**     \legal
+**     Copyright (c) 2008 Chris Moore
+**
+**     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.
+**
+**     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 __SYNFIG_RELEASE_VERSION_H
+#define __SYNFIG_RELEASE_VERSION_H
+
+/* === H E A D E R S ======================================================= */
+
+/* === M A C R O S ========================================================= */
+
+/* === C L A S S E S & S T R U C T S ======================================= */
+
+namespace synfig {
+
+       typedef enum
+       {
+               RELEASE_VERSION_0_61_06,
+               RELEASE_VERSION_0_61_07,
+               RELEASE_VERSION_0_61_08,
+
+               RELEASE_VERSION_END
+       } ReleaseVersion;
+
+}; // END of namespace synfig
+
+/* === E N D =============================================================== */
+
+#endif
index 1c2f4c6..d0cb3cd 100644 (file)
@@ -79,7 +79,8 @@ using namespace synfig;
 
 /* === G L O B A L S ======================================================= */
 
-FileVersion save_canvas_version;
+ReleaseVersion save_canvas_version = ReleaseVersion(RELEASE_VERSION_END-1);
+int valuenode_too_new_count;
 
 /* === P R O C E D U R E S ================================================= */
 
@@ -472,7 +473,26 @@ xmlpp::Element* encode_dynamic_list(xmlpp::Element* root,ValueNode_DynamicList::
 xmlpp::Element* encode_linkable_value_node(xmlpp::Element* root,LinkableValueNode::ConstHandle value_node,Canvas::ConstHandle canvas=0)
 {
        assert(value_node);
-       root->set_name(value_node->get_name());
+
+       String name(value_node->get_name());
+       ReleaseVersion saving_version(get_file_version());
+       ReleaseVersion feature_version(LinkableValueNode::book()[name].release_version);
+
+       if (saving_version < feature_version)
+       {
+               valuenode_too_new_count++;
+               warning("can't save <%s> valuenodes in this old file format version", name.c_str());
+
+               ValueBase value((*value_node)(0));
+               encode_value(root,value,canvas);
+
+               // ValueNode_Const::ConstHandle const_value(ValueNode_Const::create((*value_node)(0)));
+               // encode_value_node(root,const_value,canvas);
+
+               return root;
+       }
+
+       root->set_name(name);
 
        root->set_attribute("type",ValueBase::type_name(value_node->get_type()));
 
@@ -716,6 +736,18 @@ xmlpp::Element* encode_canvas(xmlpp::Element* root,Canvas::ConstHandle canvas)
        return root;
 }
 
+xmlpp::Element* encode_canvas_toplevel(xmlpp::Element* root,Canvas::ConstHandle canvas)
+{
+       valuenode_too_new_count = 0;
+
+       xmlpp::Element* ret = encode_canvas(root, canvas);
+
+       if (valuenode_too_new_count)
+               warning("saved %d valuenodes as constant values in old file format\n", valuenode_too_new_count);
+
+       return ret;
+}
+
 bool
 synfig::save_canvas(const String &filename, Canvas::ConstHandle canvas)
 {
@@ -733,7 +765,7 @@ synfig::save_canvas(const String &filename, Canvas::ConstHandle canvas)
                assert(canvas);
                xmlpp::Document document;
 
-               encode_canvas(document.create_root_node("canvas"),canvas);
+               encode_canvas_toplevel(document.create_root_node("canvas"),canvas);
 
                document.write_to_file_formatted(tmp_filename);
        }
@@ -771,18 +803,18 @@ synfig::canvas_to_string(Canvas::ConstHandle canvas)
 
        xmlpp::Document document;
 
-       encode_canvas(document.create_root_node("canvas"),canvas);
+       encode_canvas_toplevel(document.create_root_node("canvas"),canvas);
 
        return document.write_to_string_formatted();
 }
 
 void
-synfig::set_file_version(FileVersion version)
+synfig::set_file_version(ReleaseVersion version)
 {
        save_canvas_version = version;
 }
 
-FileVersion
+ReleaseVersion
 synfig::get_file_version()
 {
        return save_canvas_version;
index 6319c7b..427a68f 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "string.h"
 #include "canvas.h"
+#include "releases.h"
 
 /* === M A C R O S ========================================================= */
 
@@ -40,12 +41,6 @@ namespace synfig {
 
 /* === E X T E R N S ======================================================= */
 
-typedef enum
-{
-       FILE_VERSION_0_61_08,
-       FILE_VERSION_0_61_07,
-} FileVersion;
-
 //!    Saves a canvas to \a filename
 /*!    \return \c true on success, \c false on error. */
 bool save_canvas(const String &filename, Canvas::ConstHandle canvas);
@@ -53,8 +48,8 @@ bool save_canvas(const String &filename, Canvas::ConstHandle canvas);
 //! Stores a Canvas in a string in XML format
 String canvas_to_string(Canvas::ConstHandle canvas);
 
-void set_file_version(FileVersion version);
-FileVersion get_file_version();
+void set_file_version(ReleaseVersion version);
+ReleaseVersion get_file_version();
 
 }; // END of namespace synfig
 
index 44a1b43..cde5c55 100644 (file)
@@ -38,6 +38,7 @@
 #include "general.h"
 #include "canvas.h"
 #include "paramdesc.h"
+#include "releases.h"
 
 #include "valuenode_const.h"
 #include "valuenode_linear.h"
@@ -104,45 +105,49 @@ ValueNode::subsys_init()
 {
        book_=new LinkableValueNode::Book();
 
-#define ADD_VALUENODE(class,name,local)                                                                                                                        \
+#define ADD_VALUENODE(class,name,local,version)                                                                                                        \
        (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create);            \
        (*book_)[name].check_type=&class::check_type;                                                                                           \
-       (*book_)[name].local_name=local
+       (*book_)[name].local_name=local;                                                                                                                        \
+       (*book_)[name].release_version=version
 
-#define ADD_VALUENODE2(class,name,local)                                                                                                               \
+#define ADD_VALUENODE2(class,name,local,version)                                                                                               \
        (*book_)[name].factory=reinterpret_cast<LinkableValueNode::Factory>(&class::create_from);       \
        (*book_)[name].check_type=&class::check_type;                                                                                           \
-       (*book_)[name].local_name=local
-
-       ADD_VALUENODE(ValueNode_Linear,                 "linear",                       _("Linear")                             );
-       ADD_VALUENODE(ValueNode_Composite,              "composite",            _("Composite")                  );
-       ADD_VALUENODE(ValueNode_RadialComposite,"radial_composite",     _("Radial Composite")   );
-       ADD_VALUENODE(ValueNode_Reference,              "reference",            _("Reference")                  );
-       ADD_VALUENODE(ValueNode_Repeat_Gradient,"repeat_gradient",      _("Repeat Gradient")    );
-       ADD_VALUENODE(ValueNode_Scale,                  "scale",                        _("Scale")                              );
-       ADD_VALUENODE(ValueNode_BLineCalcTangent,"blinecalctangent",_("BLine Tangent")          );
-       ADD_VALUENODE(ValueNode_BLineCalcVertex,"blinecalcvertex",      _("BLine Vertex")               );
-       ADD_VALUENODE(ValueNode_BLineRevTangent,"blinerevtangent",      _("Reverse Tangent")    );
-       ADD_VALUENODE(ValueNode_SegCalcTangent, "segcalctangent",       _("Segment Tangent")    );
-       ADD_VALUENODE(ValueNode_SegCalcVertex,  "segcalcvertex",        _("Segment Vertex")             );
-       ADD_VALUENODE(ValueNode_Stripes,                "stripes",                      _("Stripes")                    );
-       ADD_VALUENODE(ValueNode_Range,                  "range",                        _("Range")                              );
-       ADD_VALUENODE(ValueNode_Add,                    "add",                          _("Add")                                );
-       ADD_VALUENODE(ValueNode_Subtract,               "subtract",                     _("Subtract")                   );
-       ADD_VALUENODE(ValueNode_TimedSwap,              "timed_swap",           _("Timed Swap")                 );
-       ADD_VALUENODE(ValueNode_TwoTone,                "twotone",                      _("Two-Tone")                   );
-       ADD_VALUENODE(ValueNode_BLine,                  "bline",                        _("BLine")                              );
-       ADD_VALUENODE2(ValueNode_DynamicList,   "dynamic_list",         _("Dynamic List")               );
-       ADD_VALUENODE(ValueNode_GradientRotate, "gradient_rotate",      _("Gradient Rotate")    );
-       ADD_VALUENODE(ValueNode_Sine,                   "sine",                         _("Sine")                               );
-       ADD_VALUENODE(ValueNode_Cos,                    "cos",                          _("Cos")                                );
-       ADD_VALUENODE(ValueNode_Atan2,                  "atan2",                        _("aTan2")                              );
-       ADD_VALUENODE(ValueNode_Exp,                    "exp",                          _("Exponential")                );
-       ADD_VALUENODE(ValueNode_Switch,                 "switch",                       _("Switch")                             );
-       ADD_VALUENODE(ValueNode_TimeLoop,               "timeloop",                     _("Time Loop")                  );
-       ADD_VALUENODE(ValueNode_Reciprocal,             "reciprocal",           _("Reciprocal")                 );
-       ADD_VALUENODE(ValueNode_Duplicate,              "duplicate",            _("Duplicate")                  );
-       ADD_VALUENODE(ValueNode_Integer,                "fromint",                      _("From Integer")               );
+       (*book_)[name].local_name=local;                                                                                                                        \
+       (*book_)[name].release_version=version
+
+       ADD_VALUENODE(ValueNode_Linear,                 "linear",                       _("Linear")                      ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Composite,              "composite",            _("Composite")           ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_RadialComposite,"radial_composite",     _("Radial Composite"),RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Reference,              "reference",            _("Reference")           ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Scale,                  "scale",                        _("Scale")                       ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_SegCalcTangent, "segcalctangent",       _("Segment Tangent") ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_SegCalcVertex,  "segcalcvertex",        _("Segment Vertex")      ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Stripes,                "stripes",                      _("Stripes")             ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Subtract,               "subtract",                     _("Subtract")            ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_TwoTone,                "twotone",                      _("Two-Tone")            ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_BLine,                  "bline",                        _("BLine")                       ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE2(ValueNode_DynamicList,   "dynamic_list",         _("Dynamic List")        ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_GradientRotate, "gradient_rotate",      _("Gradient Rotate") ,RELEASE_VERSION_0_61_06);
+       ADD_VALUENODE(ValueNode_Sine,                   "sine",                         _("Sine")                        ,RELEASE_VERSION_0_61_06);
+
+       ADD_VALUENODE(ValueNode_TimedSwap,              "timed_swap",           _("Timed Swap")          ,RELEASE_VERSION_0_61_07); // SVN r610
+       ADD_VALUENODE(ValueNode_Repeat_Gradient,"repeat_gradient",      _("Repeat Gradient") ,RELEASE_VERSION_0_61_07); // SVN r666
+       ADD_VALUENODE(ValueNode_Exp,                    "exp",                          _("Exponential")         ,RELEASE_VERSION_0_61_07); // SVN r739
+       ADD_VALUENODE(ValueNode_Add,                    "add",                          _("Add")                         ,RELEASE_VERSION_0_61_07); // SVN r742
+       ADD_VALUENODE(ValueNode_BLineCalcTangent,"blinecalctangent",_("BLine Tangent")   ,RELEASE_VERSION_0_61_07); // SVN r744
+       ADD_VALUENODE(ValueNode_BLineCalcVertex,"blinecalcvertex",      _("BLine Vertex")        ,RELEASE_VERSION_0_61_07); // SVN r744
+       ADD_VALUENODE(ValueNode_Range,                  "range",                        _("Range")                       ,RELEASE_VERSION_0_61_07); // SVN r776
+
+       ADD_VALUENODE(ValueNode_Switch,                 "switch",                       _("Switch")                      ,RELEASE_VERSION_0_61_08); // SVN r923
+       ADD_VALUENODE(ValueNode_Cos,                    "cos",                          _("Cos")                         ,RELEASE_VERSION_0_61_08); // SVN r1111
+       ADD_VALUENODE(ValueNode_Atan2,                  "atan2",                        _("aTan2")                       ,RELEASE_VERSION_0_61_08); // SVN r1132
+       ADD_VALUENODE(ValueNode_BLineRevTangent,"blinerevtangent",      _("Reverse Tangent") ,RELEASE_VERSION_0_61_08); // SVN r1162
+       ADD_VALUENODE(ValueNode_TimeLoop,               "timeloop",                     _("Time Loop")           ,RELEASE_VERSION_0_61_08); // SVN r1226
+       ADD_VALUENODE(ValueNode_Reciprocal,             "reciprocal",           _("Reciprocal")          ,RELEASE_VERSION_0_61_08); // SVN r1238
+       ADD_VALUENODE(ValueNode_Duplicate,              "duplicate",            _("Duplicate")           ,RELEASE_VERSION_0_61_08); // SVN r1267
+       ADD_VALUENODE(ValueNode_Integer,                "fromint",                      _("From Integer")        ,RELEASE_VERSION_0_61_08); // SVN r1267
 
 #undef ADD_VALUENODE
 #undef ADD_VALUENODE2
index 62940c3..f844f9d 100644 (file)
@@ -30,6 +30,7 @@
 #include "vector.h"
 #include "value.h"
 #include "string.h"
+#include "releases.h"
 #include <ETL/handle>
 #include <ETL/stringf>
 #include "exception.h"
@@ -312,6 +313,7 @@ public:
                String local_name;
                Factory factory;
                CheckType check_type;
+               ReleaseVersion release_version; // which version of synfig introduced this valuenode type
        };
 
        typedef std::map<String,BookEntry> Book;
index 102690a..e5c6e71 100644 (file)
@@ -310,7 +310,7 @@ ValueNode_Composite::link_name(int i)const
 {
        assert(i>=0 && i<link_count());
 
-       if (get_file_version() == FILE_VERSION_0_61_07)
+       if (get_file_version() < RELEASE_VERSION_0_61_08)
                return strprintf("c%d",i+1);
 
        switch(get_type())
index e93174c..8966a47 100644 (file)
@@ -227,7 +227,7 @@ ValueNode_RadialComposite::link_name(int i)const
 {
        assert(i>=0 && i<link_count());
 
-       if (get_file_version() == FILE_VERSION_0_61_07)
+       if (get_file_version() < RELEASE_VERSION_0_61_08)
                return strprintf("c%d",i);
 
        switch(get_type())
index 1025f07..979939d 100644 (file)
@@ -1757,9 +1757,10 @@ App::dialog_save_file(const std::string &title, std::string &filename, std::stri
        {
                file_type_enum = manage(new Widget_Enum());
                file_type_enum->set_param_desc(ParamDesc().set_hint("enum")
-                                                                          .add_enum_value(synfig::FILE_VERSION_0_61_08, "0.61.08", strprintf("0.61.08 (%s)", _("current")))
-                                                                          .add_enum_value(synfig::FILE_VERSION_0_61_07, "0.61.07", strprintf("0.61.07 %s", _("and older"))));
-               file_type_enum->set_value(0);
+                                                                          .add_enum_value(synfig::RELEASE_VERSION_0_61_08, "0.61.08", strprintf("0.61.08 (%s)", _("current")))
+                                                                          .add_enum_value(synfig::RELEASE_VERSION_0_61_07, "0.61.07", "0.61.07")
+                                                                          .add_enum_value(synfig::RELEASE_VERSION_0_61_06, "0.61.06", strprintf("0.61.06 %s", _("and older"))));
+               file_type_enum->set_value(RELEASE_VERSION_END-1); // default to the most recent version
 
                Gtk::HBox *hbox = manage(new Gtk::HBox);
                hbox->pack_start(*manage(new Gtk::Label(_("File Format Version: "))),Gtk::PACK_SHRINK,0);
@@ -1790,7 +1791,7 @@ App::dialog_save_file(const std::string &title, std::string &filename, std::stri
 
     if(dialog->run() == GTK_RESPONSE_ACCEPT) {
                if (preference == ANIMATION_DIR_PREFERENCE)
-                       set_file_version(synfig::FileVersion(file_type_enum->get_value()));
+                       set_file_version(synfig::ReleaseVersion(file_type_enum->get_value()));
         filename = dialog->get_filename();
                info("Saving preference %s = '%s' in App::dialog_save_file()", preference.c_str(), dirname(filename).c_str());
                _preferences.set_value(preference, dirname(filename));
index e148787..67f6f85 100644 (file)
@@ -42,6 +42,7 @@
 #include <sigc++/adaptors/hide.h>
 #include "toolbox.h"
 #include "onemoment.h"
+#include <synfig/savecanvas.h>
 
 #include "autorecover.h"
 #include <sigc++/retype_return.h>
@@ -312,7 +313,10 @@ studio::Instance::dialog_save_as()
                }
 
                if(save_as(filename))
+               {
+                       synfig::set_file_version(ReleaseVersion(RELEASE_VERSION_END-1));
                        return true;
+               }
 
                App::dialog_error_blocking("SaveAs - Error","Unable to save to '" + filename + "'");
        }