Code

add todo comment to make code prettier
[inkscape.git] / src / extension / internal / pov-out.h
1 /*
2  * A simple utility for exporting Inkscape svg Shapes as PovRay bezier
3  * prisms.  Note that this is output-only, and would thus seem to be
4  * better placed as an 'export' rather than 'output'.  However, Export
5  * handles all or partial documents, while this outputs ALL shapes in
6  * the current SVG document.
7  *
8  * Authors:
9  *   Bob Jamison <ishmal@inkscape.org>
10  *
11  * Copyright (C) 2004-2008 Authors
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifndef EXTENSION_INTERNAL_POV_OUT_H
17 #define EXTENSION_INTERNAL_POV_OUT_H
19 #include <glib.h>
20 #include "extension/implementation/implementation.h"
22 namespace Inkscape
23 {
24 namespace Extension
25 {
26 namespace Internal
27 {
31 /**
32  * Output bezier splines in POVRay format.
33  * 
34  * For information, @see:  
35  * http://www.povray.org 
36  */ 
37 class PovOutput : public Inkscape::Extension::Implementation::Implementation
38 {
41 public:
43     /**
44      * Our internal String definition
45      */
46     typedef Glib::ustring String;
49     /**
50      * Check whether we can actually output using this module
51      */
52         bool check (Inkscape::Extension::Extension * module);
54     /**
55      * API call to perform the output to a file
56      */
57         void save (Inkscape::Extension::Output *mod,
58                    SPDocument *doc, const gchar *uri);
60     /**
61      * Inkscape runtime startup call.
62      */
63         static void init(void);
64         
65     /**
66      * Reset variables to initial state
67      */
68         void reset();
69         
70 private:
72         /**
73          * Format text to our output buffer
74          */             
75         void out(const char *fmt, ...) G_GNUC_PRINTF(2,3);
77     /**
78      * Output a 2d vector
79      */
80     void vec2(double a, double b);
82     /**
83      * Output a 3d vector
84      */
85     void vec3(double a, double b, double c);
87     /**
88      * Output a 4d vector
89      */
90     void vec4(double a, double b, double c, double d);
92     /**
93      * Output an rgbf color vector
94      */
95     void rgbf(double r, double g, double b, double f);
97     /**
98      * Output one bezier's start, start-control, 
99      *      end-control, and end nodes
100      */
101     void segment(int segNr, double a0, double a1,
102                             double b0, double b1,
103                             double c0, double c1,
104                             double d0, double d1);
107     /**
108      * Output the file header
109      */
110     void doHeader();
112     /**
113      * Output the file footer
114      */
115     void doTail();
117     /**
118      * Output the SVG document's curve data as POV curves
119      */
120     void doCurves(SPDocument *doc);
122     /**
123      * Actual method to save document
124      */
125         void saveDocument(SPDocument *doc, const gchar *uri);
128     /**
129      * used for saving information about shapes
130      */
131     class PovShapeInfo
132     {
133     public:
134         PovShapeInfo()
135             {}
136         PovShapeInfo(const PovShapeInfo &other)
137             { assign(other); }
138         PovShapeInfo operator=(const PovShapeInfo &other)
139             { assign(other); return *this; }
140         virtual ~PovShapeInfo()
141             {}
142         String id;
143         String color;
145     private:
146         void assign(const PovShapeInfo &other)
147             {
148             id    = other.id;
149             color = other.color;
150             }
151     };
153     //A list for saving information about the shapes
154     std::vector<PovShapeInfo> povShapes;
155     
156     //For formatted output
157         String outbuf;
159     //For statistics
160     int nrNodes;
161     int nrSegments;
162     int nrShapes;
164 };
169 }  // namespace Internal
170 }  // namespace Extension
171 }  // namespace Inkscape
175 #endif /* EXTENSION_INTERNAL_POV_OUT_H */