kis_qmic_applicator.cpp 3.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
18
#include "kis_qmic_applicator.h"
19 20 21

#include <kis_image_signal_router.h>
#include <kis_processing_applicator.h>
22

23
#include <kis_image.h>
24
#include <kis_selection.h>
25

26 27 28
#include "kis_import_qmic_processing_visitor.h"
#include "kis_qmic_synchronize_layers_command.h"
#include "kis_qmic_synchronize_image_size_command.h"
29

30
KisQmicApplicator::KisQmicApplicator()
31 32 33
{
}

34
KisQmicApplicator::~KisQmicApplicator()
35 36 37
{
}

38
void KisQmicApplicator::setProperties(KisImageWSP image, KisNodeSP node, QVector<gmic_image<float> *> images, const KUndo2MagicString &actionName, KisNodeListSP kritaNodes)
39
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
40
    dbgPlugins << "KisQmicApplicator::setProperties();" << ppVar(image) << ppVar(node) << images.size() << actionName << kritaNodes->count();
41

42 43 44 45
    m_image = image;
    m_node = node;
    m_actionName = actionName;
    m_kritaNodes = kritaNodes;
46
    m_images = images;
47 48
}

49

Boudewijn Rempt's avatar
Boudewijn Rempt committed
50
void KisQmicApplicator::apply()
51
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
52
    dbgPlugins << "Request for applying the result";
53 54
    cancel();

55
    KisImageSignalVector emitSignals;
56
    emitSignals << ComplexSizeChangedSignal() << ModifiedSignal;
57

58 59 60 61 62
    m_applicator.reset(
        new KisProcessingApplicator(m_image, m_node,
                                    KisProcessingApplicator::RECURSIVE |
                                    KisProcessingApplicator::NO_UI_UPDATES,
                                    emitSignals, m_actionName));
Boudewijn Rempt's avatar
Boudewijn Rempt committed
63
    dbgPlugins << "Created applicator " << m_applicator;
64

65
    m_gmicData = KisQmicDataSP(new KisQmicData());
66

67 68
    QRect layerSize;
    KisSelectionSP selection = m_image->globalSelection();
69
    if (selection) {
70 71
        layerSize = selection->selectedExactRect();
    }
72
    else {
73
        layerSize = QRect(0, 0, m_image->width(), m_image->height());
74
    }
75

76
   if (!selection) {
77
        // synchronize Krita image size with biggest gmic layer size
78
        m_applicator->applyCommand(new KisQmicSynchronizeImageSizeCommand(m_images, m_image));
79
    }
80

81
    // synchronize layer count
82
    m_applicator->applyCommand(new KisQmicSynchronizeLayersCommand(m_kritaNodes, m_images, m_image, layerSize, selection), KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE);
83

84
    KisProcessingVisitorSP  importVisitor = new KisImportQmicProcessingVisitor(m_kritaNodes, m_images, layerSize, selection);
85 86
    m_applicator->applyVisitor(importVisitor, KisStrokeJobData::SEQUENTIAL); // undo information is stored in this visitor
    m_applicator->explicitlyEmitFinalSignals();
87
    emit gmicFinished(true, 0, "done!");
88 89
}

90
void KisQmicApplicator::cancel()
91
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
92
    dbgPlugins << "KisQmicApplicator::cancel";
93
    if (m_applicator) {
94

95 96
        dbgPlugins << "Cancelling applicator!";
        m_applicator->cancel();
97 98

        dbgPlugins << "deleting applicator: " << m_applicator;
99
        m_applicator.reset();
100
    }
101
    else  {
102 103 104 105
        dbgPlugins << "Cancelling applicator: No! Reason: Null applicator!";
    }
}

106
void KisQmicApplicator::finish()
107
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
108 109
    dbgPlugins << "Applicator " << m_applicator << " finished";
    if (m_applicator) {
110
        m_applicator->end();
111
        m_applicator.reset();
112
    }
113 114
}

115
float KisQmicApplicator::getProgress() const
116
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
117
    dbgPlugins << "KisQmicApplicator::getProgress";
118 119

    if (m_gmicData) {
120
        m_gmicData->progress();
121
    }
122
    return KisQmicData::INVALID_PROGRESS_VALUE;
123
}