1 /**************************************************************************
2 * This file is part of the Fraqtive program
3 * Copyright (C) 2004-2012 Michał Męciński
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **************************************************************************/
18
19 #ifndef DATASTRUCTURES_H
20 #define DATASTRUCTURES_H
21
22 #include <QPolygonF>
23 #include <QMetaType>
24 #include <QColor>
25
26 #include "generatorcore.h"
27
28 enum Fractal
29 {
30 MandelbrotFractal,
31 JuliaFractal
32 };
33
34 enum ExponentType
35 {
36 IntegralExponent,
37 RealExponent
38 };
39
40 class FractalType
41 {
42 public:
43 FractalType();
44
45 public:
setFractal(Fractal fractal)46 void setFractal( Fractal fractal ) { m_fractal = fractal; }
fractal()47 Fractal fractal() const { return m_fractal; }
48
setParameter(const QPointF & param)49 void setParameter( const QPointF& param ) { m_parameter = param; }
parameter()50 QPointF parameter() const { return m_fractal == JuliaFractal ? m_parameter : QPointF(); }
51
setExponentType(ExponentType type)52 void setExponentType( ExponentType type ) { m_exponentType = type; }
exponentType()53 ExponentType exponentType() const { return m_exponentType; }
54
setIntegralExponent(int exponent)55 void setIntegralExponent( int exponent ) { m_integralExponent = exponent; }
integralExponent()56 int integralExponent() const { return m_exponentType == IntegralExponent ? m_integralExponent : 0; }
57
setRealExponent(double exponent)58 void setRealExponent( double exponent ) { m_realExponent = exponent; }
realExponent()59 double realExponent() const { return m_exponentType == RealExponent ? m_realExponent : 0.0; }
60
setVariant(GeneratorCore::Variant variant)61 void setVariant( GeneratorCore::Variant variant ) { m_variant = variant; }
variant()62 GeneratorCore::Variant variant() const { return m_variant; }
63
64 public:
65 friend QDataStream& operator <<( QDataStream& stream, const FractalType& type );
66 friend QDataStream& operator >>( QDataStream& stream, FractalType& type );
67
68 friend bool operator ==( const FractalType& lhv, const FractalType& rhv );
69 friend bool operator !=( const FractalType& lhv, const FractalType& rhv ) { return !( lhv == rhv ); }
70
71 private:
72 Fractal m_fractal;
73 QPointF m_parameter;
74
75 ExponentType m_exponentType;
76 int m_integralExponent;
77 double m_realExponent;
78
79 GeneratorCore::Variant m_variant;
80 };
81
FractalType()82 inline FractalType::FractalType() :
83 m_fractal( MandelbrotFractal ),
84 m_exponentType( IntegralExponent ),
85 m_integralExponent( 0 ),
86 m_realExponent( 0.0 ),
87 m_variant( GeneratorCore::NormalVariant )
88 {
89 }
90
91 inline bool operator ==( const FractalType& lhv, const FractalType& rhv )
92 {
93 return ( lhv.m_fractal == rhv.m_fractal )
94 && ( lhv.m_fractal != JuliaFractal || ( lhv.m_parameter.x() == rhv.m_parameter.x() && lhv.m_parameter.y() == rhv.m_parameter.y() ) ) // exact compare
95 && ( lhv.m_exponentType == rhv.m_exponentType )
96 && ( lhv.m_exponentType != IntegralExponent || lhv.m_integralExponent == rhv.m_integralExponent )
97 && ( lhv.m_exponentType != RealExponent || qFuzzyCompare( lhv.m_realExponent, rhv.m_realExponent ) )
98 && ( lhv.m_variant == rhv.m_variant );
99 }
100
Q_DECLARE_METATYPE(FractalType)101 Q_DECLARE_METATYPE( FractalType )
102
103 class Position
104 {
105 public:
106 Position();
107
108 public:
109 void setCenter( const QPointF& center ) { m_center = center; }
110 QPointF center() const { return m_center; }
111
112 void setZoomFactor( double factor ) { m_zoomFactor = factor; }
113 double zoomFactor() const { return m_zoomFactor; }
114
115 void setAngle( double angle ) { m_angle = angle; }
116 double angle() const { return m_angle; }
117
118 public:
119 friend QDataStream& operator <<( QDataStream& stream, const Position& position );
120 friend QDataStream& operator >>( QDataStream& stream, Position& position );
121
122 friend bool operator ==( const Position& lhv, const Position& rhv );
123 friend bool operator !=( const Position& lhv, const Position& rhv ) { return !( lhv == rhv ); }
124
125 private:
126 QPointF m_center;
127 double m_zoomFactor; // log10
128 double m_angle; // degrees
129 };
130
Position()131 inline Position::Position() :
132 m_zoomFactor( 0.0 ),
133 m_angle( 0.0 )
134 {
135 }
136
137 inline bool operator ==( const Position& lhv, const Position& rhv )
138 {
139 return ( lhv.m_center.x() == rhv.m_center.x() && lhv.m_center.y() == rhv.m_center.y() ) // exact compare
140 && qFuzzyCompare( lhv.m_zoomFactor, rhv.m_zoomFactor )
141 && qFuzzyCompare( lhv.m_angle, rhv.m_angle );
142 }
143
Q_DECLARE_METATYPE(Position)144 Q_DECLARE_METATYPE( Position )
145
146 class Gradient
147 {
148 public:
149 Gradient() { }
150 Gradient( const QPolygonF& red, const QPolygonF& green, const QPolygonF& blue );
151
152 public:
153 void setRed( const QPolygonF& red ) { m_red = red; }
154 QPolygonF red() const { return m_red; }
155
156 void setGreen( const QPolygonF& green ) { m_green = green; }
157 QPolygonF green() const { return m_green; }
158
159 void setBlue( const QPolygonF& blue ) { m_blue = blue; }
160 QPolygonF blue() const { return m_blue; }
161
162 bool isEmpty() const;
163
164 public:
165 friend QDataStream& operator <<( QDataStream& stream, const Gradient& gradient );
166 friend QDataStream& operator >>( QDataStream& stream, Gradient& gradient );
167
168 friend bool operator ==( const Gradient& lhv, const Gradient& rhv );
169 friend bool operator !=( const Gradient& lhv, const Gradient& rhv ) { return !( lhv == rhv ); }
170
171 private:
172 QPolygonF m_red;
173 QPolygonF m_green;
174 QPolygonF m_blue;
175 };
176
Gradient(const QPolygonF & red,const QPolygonF & green,const QPolygonF & blue)177 inline Gradient::Gradient( const QPolygonF& red, const QPolygonF& green, const QPolygonF& blue ) :
178 m_red( red ),
179 m_green( green ),
180 m_blue( blue )
181 {
182 }
183
184 inline bool operator ==( const Gradient& lhv, const Gradient& rhv )
185 {
186 return ( lhv.m_red == rhv.m_red )
187 && ( lhv.m_green == rhv.m_green )
188 && ( lhv.m_blue == rhv.m_blue );
189 }
190
Q_DECLARE_METATYPE(Gradient)191 Q_DECLARE_METATYPE( Gradient )
192
193 class ColorMapping
194 {
195 public:
196 ColorMapping();
197
198 public:
199 void setMirrored( bool mirrored ) { m_mirrored = mirrored; }
200 bool isMirrored() const { return m_mirrored; }
201
202 void setReversed( bool reversed ) { m_reversed = reversed; }
203 bool isReversed() const { return m_reversed; }
204
205 void setScale( double scale ) { m_scale = scale; }
206 double scale() const { return m_scale; }
207
208 void setOffset( double offset ) { m_offset = offset; }
209 double offset() const { return m_offset; }
210
211 public:
212 friend QDataStream& operator <<( QDataStream& stream, const ColorMapping& mapping );
213 friend QDataStream& operator >>( QDataStream& stream, ColorMapping& mapping );
214
215 friend bool operator ==( const ColorMapping& lhv, const ColorMapping& rhv );
216 friend bool operator !=( const ColorMapping& lhv, const ColorMapping& rhv ) { return !( lhv == rhv ); }
217
218 private:
219 bool m_mirrored;
220 bool m_reversed;
221 double m_scale;
222 double m_offset;
223 };
224
ColorMapping()225 inline ColorMapping::ColorMapping() :
226 m_mirrored( false ),
227 m_reversed( false ),
228 m_scale( 0.0 ),
229 m_offset( 0.0 )
230 {
231 }
232
233 inline bool operator ==( const ColorMapping& lhv, const ColorMapping& rhv )
234 {
235 return ( lhv.m_mirrored == rhv.m_mirrored )
236 && ( lhv.m_reversed == rhv.m_reversed )
237 && qFuzzyCompare( lhv.m_scale, rhv.m_scale )
238 && qFuzzyCompare( lhv.m_offset, rhv.m_offset );
239 }
240
Q_DECLARE_METATYPE(ColorMapping)241 Q_DECLARE_METATYPE( ColorMapping )
242
243 class GeneratorSettings
244 {
245 public:
246 GeneratorSettings();
247
248 public:
249 void setCalculationDepth( double depth ) { m_calculationDepth = depth; }
250 double calculationDepth() const { return m_calculationDepth; }
251
252 void setDetailThreshold( double threshold ) { m_detailThreshold = threshold; }
253 double detailThreshold() const { return m_detailThreshold; }
254
255 public:
256 friend QDataStream& operator <<( QDataStream& stream, const GeneratorSettings& settings );
257 friend QDataStream& operator >>( QDataStream& stream, GeneratorSettings& settings );
258
259 friend bool operator ==( const GeneratorSettings& lhv, const GeneratorSettings& rhv );
260 friend bool operator !=( const GeneratorSettings& lhv, const GeneratorSettings& rhv ) { return !( lhv == rhv ); }
261
262 private:
263 double m_calculationDepth;
264 double m_detailThreshold;
265 };
266
GeneratorSettings()267 inline GeneratorSettings::GeneratorSettings() :
268 m_calculationDepth( 0.0 ),
269 m_detailThreshold( 0.0 )
270 {
271 }
272
273 inline bool operator ==( const GeneratorSettings& lhv, const GeneratorSettings& rhv )
274 {
275 return qFuzzyCompare( lhv.m_calculationDepth, rhv.m_calculationDepth )
276 && qFuzzyCompare( lhv.m_detailThreshold, rhv.m_detailThreshold );
277 }
278
279 Q_DECLARE_METATYPE( GeneratorSettings )
280
281 enum AntiAliasing
282 {
283 NoAntiAliasing,
284 LowAntiAliasing,
285 MediumAntiAliasing,
286 HighAntiAliasing
287 };
288
289 enum Resolution
290 {
291 LowResolution,
292 MediumResolution,
293 HighResolution,
294 VeryHighResolution
295 };
296
297 class ViewSettings
298 {
299 public:
300 ViewSettings();
301
302 public:
setAntiAliasing(AntiAliasing antiAliasing)303 void setAntiAliasing( AntiAliasing antiAliasing ) { m_antiAliasing = antiAliasing; }
antiAliasing()304 AntiAliasing antiAliasing() const { return m_antiAliasing; }
305
setMeshResolution(Resolution resolution)306 void setMeshResolution( Resolution resolution ) { m_meshResolution = resolution; }
meshResolution()307 Resolution meshResolution() const { return m_meshResolution; }
308
setHeightScale(double scale)309 void setHeightScale( double scale ) { m_heightScale = scale; }
heightScale()310 double heightScale() const { return m_heightScale; }
311
setCameraZoom(double Zoom)312 void setCameraZoom( double Zoom ) { m_cameraZoom = Zoom; }
cameraZoom()313 double cameraZoom() const { return m_cameraZoom; }
314
315 public:
316 friend QDataStream& operator <<( QDataStream& stream, const ViewSettings& settings );
317 friend QDataStream& operator >>( QDataStream& stream, ViewSettings& settings );
318
319 friend bool operator ==( const ViewSettings& lhv, const ViewSettings& rhv );
320 friend bool operator !=( const ViewSettings& lhv, const ViewSettings& rhv ) { return !( lhv == rhv ); }
321
322 private:
323 AntiAliasing m_antiAliasing;
324 Resolution m_meshResolution;
325 double m_heightScale;
326 double m_cameraZoom; // degrees
327 };
328
ViewSettings()329 inline ViewSettings::ViewSettings() :
330 m_antiAliasing( NoAntiAliasing ),
331 m_meshResolution( LowResolution ),
332 m_heightScale( 0.0 ),
333 m_cameraZoom( 0.0 )
334 {
335 }
336
337 inline bool operator ==( const ViewSettings& lhv, const ViewSettings& rhv )
338 {
339 return lhv.m_antiAliasing == rhv.m_antiAliasing
340 && lhv.m_meshResolution == rhv.m_meshResolution
341 && qFuzzyCompare( lhv.m_heightScale, rhv.m_heightScale )
342 && qFuzzyCompare( lhv.m_cameraZoom, rhv.m_cameraZoom );
343 }
344
Q_DECLARE_METATYPE(ViewSettings)345 Q_DECLARE_METATYPE( ViewSettings )
346
347 class Bookmark
348 {
349 public:
350 Bookmark();
351
352 public:
353 void setFractalType( const FractalType& type ) { m_fractalType = type; }
354 FractalType fractalType() const { return m_fractalType; }
355
356 void setPosition( const Position& position ) { m_position = position; }
357 Position position() const { return m_position; }
358
359 public:
360 friend QDataStream& operator <<( QDataStream& stream, const Bookmark& bookmark );
361 friend QDataStream& operator >>( QDataStream& stream, Bookmark& bookmark );
362
363 friend bool operator ==( const Bookmark& lhv, const Bookmark& rhv );
364 friend bool operator !=( const Bookmark& lhv, const Bookmark& rhv ) { return !( lhv == rhv ); }
365
366 private:
367 FractalType m_fractalType;
368 Position m_position;
369 };
370
Bookmark()371 inline Bookmark::Bookmark()
372 {
373 }
374
375 inline bool operator ==( const Bookmark& lhv, const Bookmark& rhv )
376 {
377 return ( lhv.m_fractalType == rhv.m_fractalType )
378 && ( lhv.m_position == rhv.m_position );
379 }
380
381 Q_DECLARE_METATYPE( Bookmark )
382
383 typedef QMap<QString, Bookmark> BookmarkMap;
384
385 class Preset
386 {
387 public:
388 Preset();
389
390 public:
setGradient(const Gradient & gradient)391 void setGradient( const Gradient& gradient ) { m_gradient = gradient; }
gradient()392 Gradient gradient() const { return m_gradient; }
393
setBackgroundColor(const QColor & color)394 void setBackgroundColor( const QColor& color ) { m_backgroundColor = color; }
backgroundColor()395 QColor backgroundColor() const { return m_backgroundColor; }
396
setColorMapping(const ColorMapping & mapping)397 void setColorMapping( const ColorMapping& mapping ) { m_colorMapping = mapping; }
colorMapping()398 ColorMapping colorMapping() const { return m_colorMapping; }
399
400 public:
401 friend QDataStream& operator <<( QDataStream& stream, const Preset& preset );
402 friend QDataStream& operator >>( QDataStream& stream, Preset& preset );
403
404 friend bool operator ==( const Preset& lhv, const Preset& rhv );
405 friend bool operator !=( const Preset& lhv, const Preset& rhv ) { return !( lhv == rhv ); }
406
407 private:
408 Gradient m_gradient;
409 QColor m_backgroundColor;
410 ColorMapping m_colorMapping;
411 };
412
Preset()413 inline Preset::Preset()
414 {
415 }
416
417 inline bool operator ==( const Preset& lhv, const Preset& rhv )
418 {
419 return ( lhv.m_gradient == rhv.m_gradient )
420 && ( lhv.m_backgroundColor == rhv.m_backgroundColor )
421 && ( lhv.m_colorMapping == rhv.m_colorMapping );
422 }
423
424 Q_DECLARE_METATYPE( Preset )
425
426 typedef QMap<QString, Preset> PresetMap;
427
428 class AnimationSettings
429 {
430 public:
431 AnimationSettings();
432
433 public:
setScrollingEnabled(bool enabled)434 void setScrollingEnabled( bool enabled ) { m_scrollingEnabled = enabled; }
isScrollingEnabled()435 bool isScrollingEnabled() const { return m_scrollingEnabled; }
436
setScrollingSpeed(double speed)437 void setScrollingSpeed( double speed ) { m_scrollingSpeed = speed; }
scrollingSpeed()438 double scrollingSpeed() const { return m_scrollingSpeed; }
439
setRotationEnabled(bool enabled)440 void setRotationEnabled( bool enabled ) { m_rotationEnabled = enabled; }
isRotationEnabled()441 bool isRotationEnabled() const { return m_rotationEnabled; }
442
setRotationSpeed(double speed)443 void setRotationSpeed( double speed ) { m_rotationSpeed = speed; }
rotationSpeed()444 double rotationSpeed() const { return m_rotationSpeed; }
445
446 public:
447 friend bool operator ==( const AnimationSettings& lhv, const AnimationSettings& rhv );
448 friend bool operator !=( const AnimationSettings& lhv, const AnimationSettings& rhv ) { return !( lhv == rhv ); }
449
450 private:
451 bool m_scrollingEnabled;
452 bool m_rotationEnabled;
453 double m_scrollingSpeed;
454 double m_rotationSpeed;
455 };
456
AnimationSettings()457 inline AnimationSettings::AnimationSettings() :
458 m_scrollingEnabled( false ),
459 m_rotationEnabled( false ),
460 m_scrollingSpeed( 0.0 ),
461 m_rotationSpeed( 0.0 )
462 {
463 }
464
465 inline bool operator ==( const AnimationSettings& lhv, const AnimationSettings& rhv )
466 {
467 return lhv.m_scrollingEnabled == rhv.m_scrollingEnabled
468 && lhv.m_rotationEnabled == rhv.m_rotationEnabled
469 && qFuzzyCompare( lhv.m_scrollingSpeed, rhv.m_scrollingSpeed )
470 && qFuzzyCompare( lhv.m_rotationSpeed, rhv.m_rotationSpeed );
471 }
472
473 class AnimationState
474 {
475 public:
476 AnimationState();
477
478 public:
setScrolling(double scrolling)479 void setScrolling( double scrolling ) { m_scrolling = scrolling; }
scrolling()480 double scrolling() const { return m_scrolling; }
481
setRotation(double rotation)482 void setRotation( double rotation ) { m_rotation = rotation; }
rotation()483 double rotation() const { return m_rotation; }
484
485 public:
486 friend bool operator ==( const AnimationState& lhv, const AnimationState& rhv );
487 friend bool operator !=( const AnimationState& lhv, const AnimationState& rhv ) { return !( lhv == rhv ); }
488
489 private:
490 double m_scrolling;
491 double m_rotation;
492 };
493
AnimationState()494 inline AnimationState::AnimationState() :
495 m_scrolling( 0.0 ),
496 m_rotation( 0.0 )
497 {
498 }
499
500 inline bool operator ==( const AnimationState& lhv, const AnimationState& rhv )
501 {
502 return qFuzzyCompare( lhv.m_scrolling, rhv.m_scrolling )
503 && qFuzzyCompare( lhv.m_rotation, rhv.m_rotation );
504 }
505
506 void registerDataStructures();
507
508 #endif
509