File indexing completed on 2024-05-19 05:47:30

0001 /***************************************************************************
0002  *   Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
0003  *
0004  *   This library is free software; you can redistribute it and/or
0005  *   modify it under the terms of the GNU Library General Public
0006  *   License as published by the Free Software Foundation; either
0007  *   version 2 of the License, or (at your option) any later version.
0008  *
0009  *   This library is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU Library General Public License for more details.
0013  *
0014  *   You should have received a copy of the GNU Library General Public License
0015  *   along with this program; if not, write to the Free Software
0016  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017  ***************************************************************************/
0018 
0019 #ifndef LIBPALA_SLICER_H
0020 #define LIBPALA_SLICER_H
0021 
0022 #if defined(MAKE_LIBPALA) || defined(USE_LOCAL_LIBPALA)
0023 # include "libpala_export.h"
0024 #else
0025 # include <libpala/libpala_export.h>
0026 #endif
0027 
0028 #include <QObject>
0029 #include <QVariant>
0030 
0031 namespace Pala
0032 {
0033     class SlicerJob;
0034     class SlicerMode;
0035     class SlicerProperty;
0036     class SlicerPropertySet;
0037 
0038     /**
0039      * \class Slicer slicer.h <Pala/Slicer>
0040      * \brief Representation of a slicing algorithm.
0041      *
0042      * This class represents a slicing algorithm. It has to be subclassed by slicing plugin developers. Subclasses need to implement
0043      * \li the constructor (where the slicer's properties and, if used, the modes have to be instantiated)
0044      * \li the run() method (where the actual slicing is performed).
0045      *
0046      * Additionally, the class must be flagged as entry point into the plugin, with the following code:
0047 \code
0048 class MySlicer : public Pala::Slicer { ... };
0049 
0050 #include <KPluginFactory>
0051 #include <KPluginLoader>
0052 
0053 K_PLUGIN_FACTORY(MySlicerFactory, registerPlugin<MySlicer>();)
0054 K_EXPORT_PLUGIN(MySlicerFactory("myslicer"))
0055 \endcode
0056      * In the last line, put inside the string literal the file name of the plugin library (e.g. \a myslicer is the name for a library  \a libmyslicer.so on unixoid systems, or \a myslicer.dll on Windows systems).
0057      */
0058     class LIBPALA_EXPORT Slicer : public QObject
0059     {
0060         Q_OBJECT
0061         public:
0062             /**
0063              * \brief Behavioral flags of a slicer.
0064              * These flags can be used to programmatically configure the behavior of libpala for a single slicer. You should only set the slicer's flags once in the constructor, and not modify it later. (The latter might cause unexpected behavior.)
0065              * \see setFlags
0066              */
0067             enum SlicerFlag
0068             {
0069                 NoFlags = 0x0,
0070                 AllowFullTransparency = 0x1 ///< By default, libpala will increase the minimum alpha value of input images to avoid invisible pieces. Set this flag if you rely on the alpha channel in your slicing algorithm.
0071             };
0072             Q_DECLARE_FLAGS(SlicerFlags, SlicerFlag)
0073 
0074             /**
0075              * \brief Constructs a new Slicer object.
0076              * In any subclass, the constructor signature has to be the same (due to the way the plugin loader works). The arguments should be passed to this constructor and ignored by the subclass implementation, as their format might change without notice in future versions.
0077              */
0078             explicit Slicer(QObject* parent = nullptr, const QVariantList& args = QVariantList());
0079             ///Deletes this slicer, and all properties and modes which have been added with addProperty() and addMode().
0080             ~Slicer() override;
0081 
0082             //The following function belongs to the interface to the Palapeli application. It is not documented because the documentation is targeted at slicer developers.
0083             ///\internal
0084             ///\since libpala 1.2 (KDE SC 4.6)
0085             QList<const Pala::SlicerMode*> modes() const;
0086             ///\internal
0087             ///\deprecated because sorting order is not right
0088             QMap<QByteArray, const Pala::SlicerProperty*> properties() const;
0089             ///\internal
0090             ///\since libpala 1.2 (KDE SC 4.6)
0091             QList<const Pala::SlicerProperty*> propertyList() const; //BIC: rename to properties()
0092             ///\internal
0093             SlicerFlags flags() const;
0094             ///\internal
0095             bool process(Pala::SlicerJob* job); //a wrapper function for Pala::Slicer::run
0096             //BIC: constify method
0097 
0098             //This class is the only interface that slicers can use to communicate with Palapeli, and it is only instantiated very few times (one instance per slicer plugin), so it should be reasonable to reserve some space in the virtual table for future additions.
0099             //RESERVE_VIRTUAL_5
0100         protected:
0101             ///Add the given property to the property list of this slicer. The slicer will take care of destructing the given Pala::SlicerProperty instance when it is destructed.
0102             ///Use this method in the subclass constructors to fill the slicer with properties. Properties let the user control how the slicing is done.
0103             ///\warning It is not safe to add new properties outside the constructor of a Pala::Slicer subclass.
0104             void addProperty(const QByteArray& key, Pala::SlicerProperty* property);
0105             //BIC: make interface similar to setMode()
0106             ///Add an operation mode to this slicer. The slicer will take care of destructing the given Pala::SlicerMode instance when it is destructed.
0107             ///You may use modes e.g. if your slicer includes different slicing algorithms at once which might need a different set of properties (see Pala::SlicerMode documentation for details). If you choose not to use modes, just ignore this function and all other functions concerning modes.
0108             ///\warning It is not safe to add new modes outside the constructor of a Pala::Slicer subclass.
0109             ///\since libpala 1.2 (KDE SC 4.6)
0110             void addMode(Pala::SlicerMode* mode);
0111 
0112             friend class SlicerPropertySet;
0113             ///\see Pala::Slicer::SlicerFlags
0114             void setFlags(SlicerFlags flags);
0115 
0116             /**
0117              * \brief The slicing algorithm.
0118              * Implement the slicing algorithm in this method. The slicing algorithm should always respect the current values of the slicer's properties, as defined through the addProperty() method.
0119              * \returns whether the operation has been completed successfully
0120              * \see Pala::SlicerJob
0121              */
0122             virtual bool run(Pala::SlicerJob* job) = 0;
0123             //BIC: constify method
0124         private:
0125             class Private;
0126             Private* const p;
0127     };
0128 }
0129 
0130 Q_DECLARE_OPERATORS_FOR_FLAGS(Pala::Slicer::SlicerFlags)
0131 
0132 #endif // LIBPALA_SLICER_H