moreupdates
[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: loadcanvas.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_LOADCANVAS_H
25 #define __SYNFIG_LOADCANVAS_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include "string.h"
30 #include "canvas.h"
31 #include "valuenode.h"
32 #include "vector.h"
33 #include "value.h"
34 #include "valuenode_subtract.h"
35 #include "valuenode_animated.h"
36 #include "valuenode_composite.h"
37 #include "valuenode_const.h"
38 #include "valuenode_linear.h"
39 #include "valuenode_dynamiclist.h"
40 #include "valuenode_reference.h"
41 #include "valuenode_timedswap.h"
42 #include "keyframe.h"
43 #include "guid.h"
44
45 /* === M A C R O S ========================================================= */
46
47 /* === T Y P E D E F S ===================================================== */
48
49 /* === C L A S S E S & S T R U C T S ======================================= */
50
51 namespace xmlpp { class Node; class Element; };
52
53 namespace synfig {
54
55 /*!     \class CanvasParser
56 **      \todo writeme
57 */
58 class CanvasParser
59 {
60         /*
61  --     ** -- D A T A -------------------------------------------------------------
62         */
63
64 private:
65
66         int max_warnings_;
67
68     int total_warnings_;
69
70     int total_errors_;
71
72         bool allow_errors_;
73
74         String filename;
75
76         String path;
77
78         GUID guid_;
79
80         /*
81  --     ** -- C O N S T R U C T O R S ---------------------------------------------
82         */
83
84 public:
85
86         CanvasParser():
87                 max_warnings_   (1000),
88                 total_warnings_ (0),
89                 total_errors_   (0),
90                 allow_errors_   (false)
91         { }
92
93         /*
94  --     ** -- M E M B E R   F U N C T I O N S -------------------------------------
95         */
96
97 public:
98
99         //! \todo writeme
100         CanvasParser &set_allow_errors(bool x) { allow_errors_=x; return *this; }
101
102         //! Sets the maximum number of warnings before a fatal error is thrown
103         CanvasParser &set_max_warnings(int i) { max_warnings_=i; return *this; }
104
105         //! Returns the maximum number of warnings before a fatal_error is thrown
106         int get_max_warnings() { return max_warnings_; }
107
108         //! Returns the number of errors in the last parse
109         int error_count()const { return total_errors_; }
110
111         //! Returns the number of warnings in the last parse
112         int warning_count()const { return total_warnings_; }
113
114         void set_path(const synfig::String& x) { path=x; }
115
116         const synfig::String& get_path()const { return path; }
117         
118         //! \todo writeme
119         Canvas::Handle parse_from_file(const String &filename);
120
121         Canvas::Handle parse_from_file_as(const String &filename,const String &as);
122
123         //! \todo writeme
124         Canvas::Handle parse_from_string(const String &data);
125
126 private:
127
128         // Error/Warning handling functions
129
130         void error(xmlpp::Node *node,const String &text);
131         void fatal_error(xmlpp::Node *node,const String &text);
132         void warning(xmlpp::Node *node,const String &text);
133         void error_unexpected_element(xmlpp::Node *node,const String &got, const String &expected);
134         void error_unexpected_element(xmlpp::Node *node,const String &got);
135
136         // Parsing Functions
137
138         Canvas::Handle parse_canvas(xmlpp::Element *node,Canvas::Handle parent=0,bool inline_=false, String path=".");
139         void parse_canvas_defs(xmlpp::Element *node,Canvas::Handle canvas);
140         etl::handle<Layer> parse_layer(xmlpp::Element *node,Canvas::Handle canvas);
141         ValueBase parse_value(xmlpp::Element *node,Canvas::Handle canvas);
142         etl::handle<ValueNode> parse_value_node(xmlpp::Element *node,Canvas::Handle canvas);
143
144         // ValueBase Parsing Functions
145
146         Real parse_real(xmlpp::Element *node,Canvas::Handle canvas);
147         Time parse_time(xmlpp::Element *node,Canvas::Handle canvas);
148         int parse_integer(xmlpp::Element *node,Canvas::Handle canvas);
149         Vector parse_vector(xmlpp::Element *node,Canvas::Handle canvas);
150         Color parse_color(xmlpp::Element *node,Canvas::Handle canvas);
151         Angle parse_angle(xmlpp::Element *node,Canvas::Handle canvas);
152         String parse_string(xmlpp::Element *node,Canvas::Handle canvas);
153         bool parse_bool(xmlpp::Element *node,Canvas::Handle canvas);
154         Segment parse_segment(xmlpp::Element *node,Canvas::Handle canvas);
155         ValueBase parse_list(xmlpp::Element *node,Canvas::Handle canvas);
156         Gradient parse_gradient(xmlpp::Element *node,Canvas::Handle canvas);
157         BLinePoint parse_bline_point(xmlpp::Element *node,Canvas::Handle canvas);
158
159         Keyframe parse_keyframe(xmlpp::Element *node,Canvas::Handle canvas);
160
161         // ValueNode Parsing Functions
162
163         etl::handle<ValueNode_Animated> parse_animated(xmlpp::Element *node,Canvas::Handle canvas);
164         etl::handle<ValueNode_Subtract> parse_subtract(xmlpp::Element *node,Canvas::Handle canvas);
165         etl::handle<ValueNode_Animated> parse_timedswap(xmlpp::Element *node,Canvas::Handle canvas);
166         etl::handle<LinkableValueNode> parse_linkable_value_node(xmlpp::Element *node,Canvas::Handle canvas);
167         etl::handle<ValueNode_Composite> parse_composite(xmlpp::Element *node,Canvas::Handle canvas);
168         etl::handle<ValueNode_DynamicList> parse_dynamic_list(xmlpp::Element *node,Canvas::Handle canvas);
169
170 }; // END of CanvasParser
171
172 /* === E X T E R N S ======================================================= */
173
174 //!     Loads a canvas from \a filename
175 /*!     \return The Canvas's handle on success, an empty handle on failure */
176 extern Canvas::Handle open_canvas(const String &filename);
177 extern Canvas::Handle open_canvas_as(const String &filename,const String &as);
178
179 //! Retrieves a Canvas from a string in XML format
180 extern Canvas::Handle string_to_canvas(const String &data);
181
182 std::map<synfig::String, etl::loose_handle<Canvas> >& get_open_canvas_map();
183
184 }; // END of namespace synfig
185
186 /* === E N D =============================================================== */
187
188 #endif