From 933391e568dac0fa4409875800a331d219fe9b59 Mon Sep 17 00:00:00 2001 From: dooglus Date: Fri, 8 Feb 2008 14:03:38 +0000 Subject: [PATCH] Add information about which valuenode types were added in which release. Don't save new types in old format files. git-svn-id: http://svn.voria.com/code@1626 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/modules/mod_noise/main.cpp | 2 +- synfig-core/trunk/src/synfig/Makefile.am | 4 +- synfig-core/trunk/src/synfig/module.h | 6 +- synfig-core/trunk/src/synfig/releases.h | 49 +++++++++++++++ synfig-core/trunk/src/synfig/savecanvas.cpp | 44 +++++++++++-- synfig-core/trunk/src/synfig/savecanvas.h | 11 +--- synfig-core/trunk/src/synfig/valuenode.cpp | 73 ++++++++++++---------- synfig-core/trunk/src/synfig/valuenode.h | 2 + .../trunk/src/synfig/valuenode_composite.cpp | 2 +- .../trunk/src/synfig/valuenode_radialcomposite.cpp | 2 +- synfig-studio/trunk/src/gtkmm/app.cpp | 9 +-- synfig-studio/trunk/src/gtkmm/instance.cpp | 4 ++ 12 files changed, 149 insertions(+), 59 deletions(-) create mode 100644 synfig-core/trunk/src/synfig/releases.h diff --git a/synfig-core/trunk/src/modules/mod_noise/main.cpp b/synfig-core/trunk/src/modules/mod_noise/main.cpp index f9ef6dd..e4e8d1d 100644 --- a/synfig-core/trunk/src/modules/mod_noise/main.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/main.cpp @@ -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 diff --git a/synfig-core/trunk/src/synfig/Makefile.am b/synfig-core/trunk/src/synfig/Makefile.am index 4f5d9b7..4895302 100644 --- a/synfig-core/trunk/src/synfig/Makefile.am +++ b/synfig-core/trunk/src/synfig/Makefile.am @@ -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 \ diff --git a/synfig-core/trunk/src/synfig/module.h b/synfig-core/trunk/src/synfig/module.h index 6aab53a..e618820 100644 --- a/synfig-core/trunk/src/synfig/module.h +++ b/synfig-core/trunk/src/synfig/module.h @@ -31,6 +31,7 @@ #include #include #include "string.h" +#include "releases.h" #include #include "vector.h" #include "color.h" @@ -123,10 +124,11 @@ //! 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(&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 index 0000000..9ff3dd0 --- /dev/null +++ b/synfig-core/trunk/src/synfig/releases.h @@ -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 diff --git a/synfig-core/trunk/src/synfig/savecanvas.cpp b/synfig-core/trunk/src/synfig/savecanvas.cpp index 1c2f4c6..d0cb3cd 100644 --- a/synfig-core/trunk/src/synfig/savecanvas.cpp +++ b/synfig-core/trunk/src/synfig/savecanvas.cpp @@ -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; diff --git a/synfig-core/trunk/src/synfig/savecanvas.h b/synfig-core/trunk/src/synfig/savecanvas.h index 6319c7b..427a68f 100644 --- a/synfig-core/trunk/src/synfig/savecanvas.h +++ b/synfig-core/trunk/src/synfig/savecanvas.h @@ -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 diff --git a/synfig-core/trunk/src/synfig/valuenode.cpp b/synfig-core/trunk/src/synfig/valuenode.cpp index 44a1b43..cde5c55 100644 --- a/synfig-core/trunk/src/synfig/valuenode.cpp +++ b/synfig-core/trunk/src/synfig/valuenode.cpp @@ -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(&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(&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 diff --git a/synfig-core/trunk/src/synfig/valuenode.h b/synfig-core/trunk/src/synfig/valuenode.h index 62940c3..f844f9d 100644 --- a/synfig-core/trunk/src/synfig/valuenode.h +++ b/synfig-core/trunk/src/synfig/valuenode.h @@ -30,6 +30,7 @@ #include "vector.h" #include "value.h" #include "string.h" +#include "releases.h" #include #include #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 Book; diff --git a/synfig-core/trunk/src/synfig/valuenode_composite.cpp b/synfig-core/trunk/src/synfig/valuenode_composite.cpp index 102690a..e5c6e71 100644 --- a/synfig-core/trunk/src/synfig/valuenode_composite.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_composite.cpp @@ -310,7 +310,7 @@ ValueNode_Composite::link_name(int i)const { assert(i>=0 && i=0 && iset_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)); diff --git a/synfig-studio/trunk/src/gtkmm/instance.cpp b/synfig-studio/trunk/src/gtkmm/instance.cpp index e148787..67f6f85 100644 --- a/synfig-studio/trunk/src/gtkmm/instance.cpp +++ b/synfig-studio/trunk/src/gtkmm/instance.cpp @@ -42,6 +42,7 @@ #include #include "toolbox.h" #include "onemoment.h" +#include #include "autorecover.h" #include @@ -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 + "'"); } -- 2.7.4