00001
00022
00023
00024
00025
00026 #ifndef __SYNFIG_LOADCANVAS_H
00027 #define __SYNFIG_LOADCANVAS_H
00028
00029
00030
00031 #include "string.h"
00032 #include "canvas.h"
00033 #include "valuenode.h"
00034 #include "vector.h"
00035 #include "value.h"
00036 #include "valuenode_subtract.h"
00037 #include "valuenode_animated.h"
00038 #include "valuenode_composite.h"
00039 #include "valuenode_dynamiclist.h"
00040 #include "keyframe.h"
00041 #include "guid.h"
00042
00043
00044
00045
00046
00047
00048
00049 namespace xmlpp { class Node; class Element; };
00050
00051 namespace synfig {
00052
00056 class CanvasParser
00057 {
00058
00059
00060
00061
00062 private:
00063
00064 int max_warnings_;
00065
00066 int total_warnings_;
00067
00068 int total_errors_;
00069
00070 bool allow_errors_;
00071
00072 String filename;
00073
00074 String path;
00075
00076 String errors_text;
00077 String warnings_text;
00078
00079 GUID guid_;
00080
00081
00082
00083
00084
00085 public:
00086
00087 CanvasParser():
00088 max_warnings_ (1000),
00089 total_warnings_ (0),
00090 total_errors_ (0),
00091 allow_errors_ (false)
00092 { }
00093
00094
00095
00096
00097
00098 public:
00099
00101 CanvasParser &set_allow_errors(bool x) { allow_errors_=x; return *this; }
00102
00104 CanvasParser &set_max_warnings(int i) { max_warnings_=i; return *this; }
00105
00107 int get_max_warnings() { return max_warnings_; }
00108
00110 int error_count()const { return total_errors_; }
00111
00113 int warning_count()const { return total_warnings_; }
00114
00115 void set_path(const synfig::String& x) { path=x; }
00116
00117 const synfig::String& get_path()const { return path; }
00118
00119 const synfig::String& get_errors_text()const { return errors_text; }
00120 const synfig::String& get_warnings_text()const { return warnings_text; }
00121
00122 static void register_canvas_in_map(Canvas::Handle canvas, String as);
00123
00124 #ifdef _DEBUG
00125 static void show_canvas_map(String file, int line, String text);
00126 #endif // _DEBUG
00127
00129 Canvas::Handle parse_from_file_as(const String &filename,const String &as,String &errors);
00130
00131 static std::set<String> loading_;
00132
00133 private:
00134
00135
00136
00137 void error(xmlpp::Node *node,const String &text);
00138 void fatal_error(xmlpp::Node *node,const String &text);
00139 void warning(xmlpp::Node *node,const String &text);
00140 void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
00141 void error_unexpected_element(xmlpp::Node *node,const String &got);
00142
00143
00144
00145 Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
00146 void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
00147 etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
00148 ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
00149 etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
00150
00151
00152
00153 Real parse_real(xmlpp::Element *node);
00154 Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
00155 int parse_integer(xmlpp::Element *node);
00156 Vector parse_vector(xmlpp::Element *node);
00157 Color parse_color(xmlpp::Element *node);
00158 Angle parse_angle(xmlpp::Element *node);
00159 String parse_string(xmlpp::Element *node);
00160 bool parse_bool(xmlpp::Element *node);
00161 Segment parse_segment(xmlpp::Element *node);
00162 ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
00163 Gradient parse_gradient(xmlpp::Element *node);
00164 BLinePoint parse_bline_point(xmlpp::Element *node);
00165
00166 Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
00167
00168
00169
00170 etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
00171 etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
00172 etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
00173 etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
00174
00175 };
00176
00177
00178
00180
00181 extern Canvas::Handle open_canvas(const String &filename,String &errors,String &warnings);
00182 extern Canvas::Handle open_canvas_as(const String &filename,const String &as,String &errors,String &warnings);
00183
00184 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
00185
00186 };
00187
00188
00189
00190 #endif