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