1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef INKSCAPE_LIVEPATHEFFECT_ENUM_H
3 #define INKSCAPE_LIVEPATHEFFECT_ENUM_H
4 
5 /*
6  * Inkscape::LivePathEffect::EffectType
7  *
8  * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
9  *
10  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11  */
12 
13 #include "util/enums.h"
14 
15 namespace Inkscape {
16 namespace LivePathEffect {
17 
18 //Please fill in the same order than in effect.cpp:98
19 enum EffectType {
20     BEND_PATH = 0,
21     GEARS,
22     PATTERN_ALONG_PATH,
23     CURVE_STITCH,
24     VONKOCH,
25     KNOT,
26     CONSTRUCT_GRID,
27     SPIRO,
28     ENVELOPE,
29     INTERPOLATE,
30     ROUGH_HATCHES,
31     SKETCH,
32     RULER,
33     POWERSTROKE,
34     CLONE_ORIGINAL,
35     SIMPLIFY,
36     LATTICE2,
37     PERSPECTIVE_ENVELOPE,
38     INTERPOLATE_POINTS,
39     TRANSFORM_2PTS,
40     SHOW_HANDLES,
41     ROUGHEN,
42     BSPLINE,
43     JOIN_TYPE,
44     TAPER_STROKE,
45     MIRROR_SYMMETRY,
46     COPY_ROTATE,
47     ATTACH_PATH,
48     FILL_BETWEEN_STROKES,
49     FILL_BETWEEN_MANY,
50     ELLIPSE_5PTS,
51     BOUNDING_BOX,
52     MEASURE_SEGMENTS,
53     FILLET_CHAMFER,
54     BOOL_OP,
55     POWERCLIP,
56     POWERMASK,
57     PTS2ELLIPSE,
58     OFFSET,
59     DASHED_STROKE,
60     ANGLE_BISECTOR,
61     CIRCLE_WITH_RADIUS,
62     CIRCLE_3PTS,
63     EXTRUDE,
64     LINE_SEGMENT,
65     PARALLEL,
66     PERP_BISECTOR,
67     TANGENT_TO_CURVE,
68     SLICE,
69     // PUT NEW LPE BEFORE EXPERIMENTAL IN THE SAME ORDER AS IN effect.cpp
70     DOEFFECTSTACK_TEST,
71     DYNASTROKE,
72     LATTICE,
73     PATH_LENGTH,
74     RECURSIVE_SKELETON,
75     TEXT_LABEL,
76     EMBRODERY_STITCH,
77     INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being
78                 // last. - johan)
79 };
80 
81 template <typename E>
82 struct EnumEffectData {
83     E id;
84     const Glib::ustring label;
85     const Glib::ustring key;
86     const Glib::ustring icon;
87     const Glib::ustring untranslated_label;
88     const Glib::ustring description;
89     const bool on_path;
90     const bool on_shape;
91     const bool on_group;
92     const bool on_image;
93     const bool on_text;
94     const bool experimental;
95 };
96 
97 const Glib::ustring empty_string("");
98 
99 /**
100  * Simplified management of enumerations of LPE items with UI labels.
101  *
102  * @note that get_id_from_key and get_id_from_label return 0 if it cannot find an entry for that key string.
103  * @note that get_label and get_key return an empty string when the requested id is not in the list.
104  */
105 template <typename E>
106 class EnumEffectDataConverter {
107   public:
108     typedef EnumEffectData<E> Data;
109 
EnumEffectDataConverter(const EnumEffectData<E> * cd,const unsigned int length)110     EnumEffectDataConverter(const EnumEffectData<E> *cd, const unsigned int length)
111         : _length(length)
112         , _data(cd)
113     {
114     }
115 
get_id_from_label(const Glib::ustring & label)116     E get_id_from_label(const Glib::ustring &label) const
117     {
118         for (unsigned int i = 0; i < _length; ++i) {
119             if (_data[i].label == label)
120                 return _data[i].id;
121         }
122 
123         return (E)0;
124     }
125 
get_id_from_key(const Glib::ustring & key)126     E get_id_from_key(const Glib::ustring &key) const
127     {
128         for (unsigned int i = 0; i < _length; ++i) {
129             if (_data[i].key == key)
130                 return _data[i].id;
131         }
132 
133         return (E)0;
134     }
135 
is_valid_key(const Glib::ustring & key)136     bool is_valid_key(const Glib::ustring &key) const
137     {
138         for (unsigned int i = 0; i < _length; ++i) {
139             if (_data[i].key == key)
140                 return true;
141         }
142 
143         return false;
144     }
145 
is_valid_id(const E id)146     bool is_valid_id(const E id) const
147     {
148         for (unsigned int i = 0; i < _length; ++i) {
149             if (_data[i].id == id)
150                 return true;
151         }
152         return false;
153     }
154 
get_label(const E id)155     const Glib::ustring &get_label(const E id) const
156     {
157         for (unsigned int i = 0; i < _length; ++i) {
158             if (_data[i].id == id)
159                 return _data[i].label;
160         }
161 
162         return empty_string;
163     }
164 
get_key(const E id)165     const Glib::ustring &get_key(const E id) const
166     {
167         for (unsigned int i = 0; i < _length; ++i) {
168             if (_data[i].id == id)
169                 return _data[i].key;
170         }
171 
172         return empty_string;
173     }
174 
get_icon(const E id)175     const Glib::ustring &get_icon(const E id) const
176     {
177         for (unsigned int i = 0; i < _length; ++i) {
178             if (_data[i].id == id)
179                 return _data[i].icon;
180         }
181 
182         return empty_string;
183     }
184 
get_untranslated_label(const E id)185     const Glib::ustring &get_untranslated_label(const E id) const
186     {
187         for (unsigned int i = 0; i < _length; ++i) {
188             if (_data[i].id == id)
189                 return _data[i].untranslated_label;
190         }
191 
192         return empty_string;
193     }
194 
get_description(const E id)195     const Glib::ustring &get_description(const E id) const
196     {
197         for (unsigned int i = 0; i < _length; ++i) {
198             if (_data[i].id == id)
199                 return _data[i].description;
200         }
201 
202         return empty_string;
203     }
204 
get_on_path(const E id)205     const bool get_on_path(const E id) const
206     {
207         for (unsigned int i = 0; i < _length; ++i) {
208             if (_data[i].id == id)
209                 return _data[i].on_path;
210         }
211 
212         return false;
213     }
214 
get_on_shape(const E id)215     const bool get_on_shape(const E id) const
216     {
217         for (unsigned int i = 0; i < _length; ++i) {
218             if (_data[i].id == id)
219                 return _data[i].on_shape;
220         }
221 
222         return false;
223     }
224 
get_on_group(const E id)225     const bool get_on_group(const E id) const
226     {
227         for (unsigned int i = 0; i < _length; ++i) {
228             if (_data[i].id == id)
229                 return _data[i].on_group;
230         }
231 
232         return false;
233     }
234 
get_on_image(const E id)235     const bool get_on_image(const E id) const
236     {
237         for (unsigned int i = 0; i < _length; ++i) {
238             if (_data[i].id == id)
239                 return _data[i].on_image;
240         }
241 
242         return false;
243     }
244 
get_on_text(const E id)245     const bool get_on_text(const E id) const
246     {
247         for (unsigned int i = 0; i < _length; ++i) {
248             if (_data[i].id == id)
249                 return _data[i].on_text;
250         }
251 
252         return false;
253     }
254 
get_experimental(const E id)255     const bool get_experimental(const E id) const
256     {
257         for (unsigned int i = 0; i < _length; ++i) {
258             if (_data[i].id == id)
259                 return _data[i].experimental;
260         }
261 
262         return false;
263     }
264 
data(const unsigned int i)265     const EnumEffectData<E> &data(const unsigned int i) const { return _data[i]; }
266 
267     const unsigned int _length;
268 
269   private:
270     const EnumEffectData<E> *_data;
271 };
272 
273 extern const EnumEffectData<EffectType> LPETypeData[];             /// defined in effect.cpp
274 extern const EnumEffectDataConverter<EffectType> LPETypeConverter; /// defined in effect.cpp
275 
276 } //namespace LivePathEffect
277 } //namespace Inkscape
278 
279 #endif
280 
281 /*
282   Local Variables:
283   mode:c++
284   c-file-style:"stroustrup"
285   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
286   indent-tabs-mode:nil
287   fill-column:99
288   End:
289 */
290 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
291