Remove ancient trunk folder from svn repository
[synfig.git] / synfig-core / src / synfig / loadcanvas.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file loadcanvas.h
3 **      \brief writeme
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **      Copyright (c) 2009 Carlos A. Sosa Navarro
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === S T A R T =========================================================== */
26
27 #ifndef __SYNFIG_LOADCANVAS_H
28 #define __SYNFIG_LOADCANVAS_H
29
30 /* === H E A D E R S ======================================================= */
31
32 #include "string.h"
33 #include "canvas.h"
34 #include "valuenode.h"
35 #include "vector.h"
36 #include "value.h"
37 #include "valuenode_subtract.h"
38 #include "valuenode_animated.h"
39 #include "valuenode_composite.h"
40 #include "valuenode_dynamiclist.h"
41 #include "keyframe.h"
42 #include "guid.h"
43
44 /* === M A C R O S ========================================================= */
45
46 /* === T Y P E D E F S ===================================================== */
47
48 /* === C L A S S E S & S T R U C T S ======================================= */
49
50 namespace xmlpp { class Node; class Element; };
51
52 namespace synfig {
53
54 /*!     \class CanvasParser
55 **      \todo writeme
56 */
57 class CanvasParser
58 {
59         /*
60  --     ** -- D A T A -------------------------------------------------------------
61         */
62
63 private:
64
65         int max_warnings_;
66
67     int total_warnings_;
68
69     int total_errors_;
70
71         bool allow_errors_;
72
73         String filename;
74
75         String path;
76
77         String errors_text;
78         String warnings_text;
79
80         GUID guid_;
81
82         /*
83  --     ** -- C O N S T R U C T O R S ---------------------------------------------
84         */
85
86 public:
87
88         CanvasParser():
89                 max_warnings_   (1000),
90                 total_warnings_ (0),
91                 total_errors_   (0),
92                 allow_errors_   (false)
93         { }
94
95         /*
96  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
97         */
98
99 public:
100
101         //! \todo writeme
102         CanvasParser &set_allow_errors(bool x) { allow_errors_=x; return *this; }
103
104         //! Sets the maximum number of warnings before a fatal error is thrown
105         CanvasParser &set_max_warnings(int i) { max_warnings_=i; return *this; }
106
107         //! Returns the maximum number of warnings before a fatal_error is thrown
108         int get_max_warnings() { return max_warnings_; }
109
110         //! Returns the number of errors in the last parse
111         int error_count()const { return total_errors_; }
112
113         //! Returns the number of warnings in the last parse
114         int warning_count()const { return total_warnings_; }
115
116         void set_path(const synfig::String& x) { path=x; }
117
118         const synfig::String& get_path()const { return path; }
119
120         const synfig::String& get_errors_text()const { return errors_text; }
121         const synfig::String& get_warnings_text()const { return warnings_text; }
122
123         static void register_canvas_in_map(Canvas::Handle canvas, String as);
124
125 #ifdef _DEBUG
126         static void show_canvas_map(String file, int line, String text);
127 #endif  // _DEBUG
128
129         //! \todo writeme
130         Canvas::Handle parse_from_file_as(const String &filename,const String &as,String &errors);
131         Canvas::Handle parse_as(xmlpp::Element* node,String &errors);
132
133         static std::set<String> loading_;
134
135 private:
136
137         // Error/Warning handling functions
138
139         void error(xmlpp::Node *node,const String &text);
140         void fatal_error(xmlpp::Node *node,const String &text);
141         void warning(xmlpp::Node *node,const String &text);
142         void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
143         void error_unexpected_element(xmlpp::Node *node,const String &got);
144
145         // Parsing Functions
146
147         Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
148         void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
149         etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
150         ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
151         etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
152
153         // ValueBase Parsing Functions
154
155         Real parse_real(xmlpp::Element *node);
156         Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
157         int parse_integer(xmlpp::Element *node);
158         Vector parse_vector(xmlpp::Element *node);
159         Color parse_color(xmlpp::Element *node);
160         Angle parse_angle(xmlpp::Element *node);
161         String parse_string(xmlpp::Element *node);
162         bool parse_bool(xmlpp::Element *node);
163         Segment parse_segment(xmlpp::Element *node);
164         ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
165         Gradient parse_gradient(xmlpp::Element *node);
166         BLinePoint parse_bline_point(xmlpp::Element *node);
167
168         Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
169
170         // ValueNode Parsing Functions
171
172         etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
173         etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
174         etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
175         etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
176
177 }; // END of CanvasParser
178
179 /* === E X T E R N S ======================================================= */
180
181 //!     Loads a canvas from \a filename
182 /*!     \return The Canvas's handle on success, an empty handle on failure */
183 extern Canvas::Handle open_canvas(xmlpp::Element* node,String &errors,String &warnings);
184 extern Canvas::Handle open_canvas(const String &filename,String &errors,String &warnings);
185 extern Canvas::Handle open_canvas_as(const String &filename,const String &as,String &errors,String &warnings);
186
187 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
188
189 }; // END of namespace synfig
190
191 /* === E N D =============================================================== */
192
193 #endif