chalk

kis_load_visitor.h
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef KIS_LOAD_VISITOR_H_
20#define KIS_LOAD_VISITOR_H_
21
22#include <tqrect.h>
23#include "kis_types.h"
24#include "kis_layer_visitor.h"
25#include "kis_image.h"
26#include "kis_selection.h"
27#include "kis_layer.h"
28#include "kis_paint_layer.h"
29#include "kis_group_layer.h"
30#include "kis_adjustment_layer.h"
31#include "kis_filter_configuration.h"
32
33#include "kis_datamanager.h"
34
35class KisLoadVisitor : public KisLayerVisitor {
36public:
37 KisLoadVisitor(KisImageSP img, KoStore *store, TQMap<KisLayerSP, TQString> &layerFilenames) :
38 KisLayerVisitor(),
39 m_layerFilenames(layerFilenames)
40 {
41 m_external = false;
42 m_img = img;
43 m_store = store;
44 }
45
46public:
47 void setExternalUri(TQString &uri)
48 {
49 m_external = true;
50 m_uri = uri;
51 }
52
53 virtual bool visit(KisPaintLayer *layer)
54 { //connect(*layer->paintDevice(), TQ_SIGNAL(ioProgress(TQ_INT8)), m_img, TQ_SLOT(slotIOProgress(TQ_INT8)));
55
56 TQString location = m_external ? TQString() : m_uri;
57 location += m_img->name() + "/layers/" + m_layerFilenames[layer];
58
59 // Layer data
60 if (m_store->open(location)) {
61 if (!layer->paintDevice()->read(m_store)) {
62 layer->paintDevice()->disconnect();
63 m_store->close();
64 //IODone();
65 return false;
66 }
67
68 m_store->close();
69 }
70
71 // icc profile
72 location = m_external ? TQString() : m_uri;
73 location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".icc";
74
75 if (m_store->hasFile(location)) {
76 TQByteArray data;
77 m_store->open(location);
78 data = m_store->read(m_store->size());
79 m_store->close();
80 // Create a colorspace with the embedded profile
81 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(layer->paintDevice()->colorSpace()->id(),
82 new KisProfile(data));
83 // replace the old colorspace
84 layer->paintDevice()->setData(layer->paintDevice()->dataManager(), cs);
85 TQRect rc = layer->paintDevice()->extent();
86 kdDebug() << "After loading " << layer->name() << " extent is: " << rc.x() << ", " << rc.y() << ", " << rc.width() << ", " << rc.height() << endl;
87 layer->setDirty(rc);
88 kdDebug(DBG_AREA_FILE) << "Opened icc information, size is " << data.size() << endl;
89 }
90
91 // mask
92 if (layer->hasMask()) { // We set this in KisDoc::loadPaintLayer
93 KisPaintDeviceSP mask = layer->getMask();
94 location = m_external ? TQString() : m_uri;
95 location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".mask";
96
97 // Layer data
98 if (m_store->open(location)) {
99 if (!mask->read(m_store)) {
100 mask->disconnect();
101 m_store->close();
102 //IODone();
103 return false;
104 }
105
106 m_store->close();
107 }
108 layer->setDirty(); // Update the entire layer
109 }
110
111 return true;
112
113 }
114
115 virtual bool visit(KisGroupLayer *layer)
116 {
117 KisLoadVisitor visitor(m_img,m_store ,m_layerFilenames);
118
119 if(m_external)
120 visitor.setExternalUri(m_uri);
121
122 KisLayerSP child = layer->firstChild();
123
124 while(child)
125 {
126 child->accept(visitor);
127 child = child->nextSibling();
128 }
129
130 layer->setDirty(m_img->bounds());
131 return true;
132 }
133
134 virtual bool visit(KisPartLayer *)
135 {
136 return true;
137 }
138
139 virtual bool visit(KisAdjustmentLayer* layer)
140 {
141 //connect(*layer->paintDevice(), TQ_SIGNAL(ioProgress(TQ_INT8)), m_img, TQ_SLOT(slotIOProgress(TQ_INT8)));
142
143 // The selection -- if present. If not, we simply cannot open the dratted thing.
144 TQString location = m_external ? TQString() : m_uri;
145 location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".selection";
146 if (m_store->hasFile(location)) {
147 m_store->open(location);
148 KisSelectionSP selection = new KisSelection();
149 if (!selection->read(m_store)) {
150 selection->disconnect();
151 m_store->close();
152 }
153 else {
154 layer->setSelection( selection );
155 }
156 m_store->close();
157 }
158
159 // filter configuration
160 location = m_external ? TQString() : m_uri;
161 location += m_img->name() + "/layers/" + m_layerFilenames[layer] + ".filterconfig";
162
163 if (m_store->hasFile(location) && layer->filter()) {
164 TQByteArray data;
165 m_store->open(location);
166 data = m_store->read(m_store->size());
167 m_store->close();
168 if (!data.isNull()) {
169 KisFilterConfiguration * kfc = layer->filter();
170 kfc->fromXML(TQString(data));
171 }
172 }
173
174 return true;
175
176 }
177
178private:
179 KisImageSP m_img;
180 KoStore *m_store;
181 bool m_external;
182 TQString m_uri;
183 TQMap<KisLayerSP, TQString> m_layerFilenames;
184};
185
186#endif // KIS_LOAD_VISITOR_H_
187
Class that contains a KisFilter and optionally a KisSelection.
void setSelection(KisSelectionSP selection)
Set the selction of this adjustment layer to a copy of selection.
KisColorSpace * getColorSpace(const KisID &csID, const TQString &profileName)
Return the colorspace + profile as named, or NULL if impossible combination.
A colorspace is the definition of a certain color model in Chalk.
A KisFilterConfiguration is the serializable representation of the filter parameters.
virtual void fromXML(const TQString &)
Fill the filter configuration object from the XML encoded representation in s.
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
This layer is of a type that can be painted on.
KisPaintDeviceSP getMask()
Returns the layer mask's device. Creates one if there is currently none.
virtual void setDirty(bool propagate=true)
Overridden to call the private convertMaskToSelection.
bool hasMask() const
Does this layer have a layer mask?
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.
KisSelection contains a byte-map representation of a layer, where the value of a byte signifies wheth...