File indexing completed on 2024-05-12 04:06:19

0001 /*
0002     SPDX-FileCopyrightText: 2010 Johannes Loehnert <loehnert.kde@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PALAPELISLICERS_GOLDBERG_ENGINE_H
0008 #define PALAPELISLICERS_GOLDBERG_ENGINE_H
0009 
0010 #include <Pala/SlicerJob>
0011 #include <QPainterPath>
0012 
0013 struct GBClassicPlugParams {
0014     bool flipped;
0015     bool is_plugless;
0016     bool is_straight;
0017     QLineF unit_x;
0018     qreal size_correction;
0019 
0020     // the rendered segment, so it only has to be rendered once.
0021     QPainterPath path;
0022     bool path_is_rendered;
0023 
0024     // start, end-angle: angle of ctl point at first and last node
0025     qreal startangle, endangle;
0026     // base roundness: how "curvy" the baseline is. 0..1.
0027     qreal baseroundness;
0028     // basepos, basewidth: x-center and distance of base points
0029     qreal basepos, basewidth;
0030     // knobsize: distance of knob ctl points from base points
0031     // knobangle, knobtilt: hard to describe.. they determine width
0032     // and asymmetry of the knob.
0033     qreal knobsize, knobangle, knobtilt;
0034 
0035 };
0036 
0037 
0038 class GoldbergEngine {
0039     public:
0040         int m_quickpreset;
0041         int m_flip_threshold;
0042         bool m_alternate_flip;
0043         int m_edge_curviness;
0044         qreal m_plug_size;
0045         qreal m_sigma_curviness;
0046         qreal m_sigma_basepos;
0047         qreal m_sigma_plugs;
0048         int m_irregular_relaxation_steps;
0049         bool m_outlines;
0050         // length of a "normal" border. 
0051         // determines the actual size of the knob.
0052         qreal m_length_base;
0053 
0054         explicit GoldbergEngine(Pala::SlicerJob *job);
0055 
0056         void set_dump_grid(bool dump);
0057         bool get_dump_grid();
0058 
0059         int get_image_width();
0060         int get_image_height();
0061 
0062         GBClassicPlugParams initEdge(bool is_straight);
0063         void reRandomizeEdge(GBClassicPlugParams &params, bool keep_endangles=false);
0064         // changes ctl point angles at the common end point to be equal.
0065         // the common endpoint of border1 and border2 is autodetected.
0066         void smooth_join(GBClassicPlugParams &border1, GBClassicPlugParams &border2);
0067 
0068         void makePieceFromPath(int piece_id, QPainterPath path);
0069         void addRelation(int piece1, int piece2);
0070         // checks if candidate intersects with an already set border.
0071         // If *offenders is given and the plugs intersect, a reference to the "other" border is added to the list.
0072         // If any plug is not rendered yet, this is done beforehands.
0073         bool plugsIntersect(GBClassicPlugParams &candidate, GBClassicPlugParams &other, QList<GBClassicPlugParams*>* offenders = nullptr);
0074         // checks if candidate is out of bounds (image frame).
0075         // If candidate is not rendered yet, this is done beforehands.
0076         bool plugOutOfBounds(GBClassicPlugParams &candidate);
0077         void makePlugless(GBClassicPlugParams &parameters);
0078 
0079         void addPlugToPath(QPainterPath& path, bool reverse, GBClassicPlugParams &parameters);
0080         void renderClassicPlug(GBClassicPlugParams &parameters);
0081 
0082         void dump_grid_image();
0083 
0084     protected:
0085         Pala::SlicerJob *m_job;
0086         QImage m_image;
0087         bool m_dump_grid;
0088         QImage *m_grid_image;
0089 };
0090 
0091 #endif // PALAPELISLICERS_GOLDBERG_ENGINE_H