-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMapping.h
206 lines (159 loc) · 5.78 KB
/
Mapping.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Mapping.h
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2016 Dame Diongue -- baydamd(@)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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAPPING_H_
#define MAPPING_H_
#include <QtGlobal>
#include "Shape.h"
#include "Paint.h"
#include "Element.h"
#include "UidAllocator.h"
#include "MetaObjectRegistry.h"
namespace mmp {
// TODO: replace by ProjectAttribute
//#include "ProjectWriter.h"
/**
* Mapping is the central concept of this software.
*
* A Mapping represents a relationship between an input Paint and
* and output Shape where the paint (possibly modified by some other
* attributes or an input Shape in the case of TextureMapping) is
* projected on the output shape.
*
* Mapping instances are stacked as layers by the MappingManager. One
* can thus change their opacity level, toggle their visibility, set
* them in "solo" mode and lock them.
*/
class Mapping : public Element
{
Q_OBJECT
Q_PROPERTY(bool solo READ isSolo WRITE setSolo)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
Q_PROPERTY(int depth READ getDepth WRITE setDepth)
// Q_PROPERTY(MShape::ptr shape READ getShape)
// Q_PROPERTY(MShape::ptr inputShape READ getInputShape)
Q_PROPERTY(bool hasInputShape READ hasInputShape STORED false)
// Q_PROPERTY(Paint::ptr paint READ getPaint WRITE setPaint)
protected:
/// The input Paint instance.
Paint::ptr _paint;
/// The output Shape instance.
MShape::ptr _shape;
/// The (optional) input Shape instance.
MShape::ptr _inputShape;
private:
static UidAllocator allocator;
bool _isSolo;
bool _isVisible;
int _depth; // depth of the layer
protected:
Mapping(int id=NULL_UID);
Mapping(Paint::ptr paint, uid id=NULL_UID);
Mapping(Paint::ptr paint, MShape::ptr shape, uid id=NULL_UID);
Mapping(Paint::ptr paint, MShape::ptr shape, MShape::ptr inputShape, uid id=NULL_UID);
public:
typedef QSharedPointer<Mapping> ptr;
virtual ~Mapping();
static const UidAllocator& getUidAllocator() { return allocator; }
/**
* Sets up this Mapping: its Paint and its Shape.
* Calls the build() method of its Paint and Shape.
*/
virtual void build() {
_paint->build();
_shape->build();
if (hasInputShape())
_inputShape->build();
}
/// The type of the mapping (expressed as a string).
virtual QString getType() const = 0;
/// Returns the paint.
Paint::ptr getPaint() const { return _paint; }
/// Returns the (output) shape.
MShape::ptr getShape() const { return _shape; }
/// Returns true iff the mapping possesses an input (source) shape.
virtual bool hasInputShape() const { return !_inputShape.isNull(); }
/// Returns the input (source) shape (if this mapping has one) or a null pointer if not.
virtual MShape::ptr getInputShape() const { return _inputShape; }
virtual void setSolo(bool solo);
virtual void setVisible(bool visible);
virtual void setDepth(int depth);
virtual void setLocked(bool locked);
virtual bool isSolo() const { return _isSolo; }
virtual bool isVisible() const { return _isVisible; }
virtual int getDepth() const { return _depth; }
virtual void toggleSolo() { setSolo(!isSolo()); }
virtual void toggleVisible() { setVisible(!isVisible()); }
virtual float getComputedOpacity() const { return getOpacity() * _paint->getOpacity(); }
virtual void setPaint(Paint::ptr p) { _paint = p; }
virtual void setShape(MShape::ptr s) { _shape = s; }
virtual void setInputShape(MShape::ptr s) { _inputShape = s; }
virtual void read(const QDomElement& obj);
virtual void write(QDomElement& obj);
protected:
virtual QList<QString> _propertiesAttributes() const
{ return Element::_propertiesAttributes() << "solo" << "visible" << "depth"; }
void _readShape(const QDomElement& obj, bool isOutput);
void _writeShape(QDomElement& obj, bool isOutput);
};
/**
* Mapping of a Color paint into a shape.
*/
class ColorMapping : public Mapping
{
Q_OBJECT
public:
Q_INVOKABLE ColorMapping(int id=NULL_UID)
: Mapping(id) {}
ColorMapping(Paint::ptr paint, MShape::ptr shape,
uid id=NULL_UID)
: Mapping(paint, shape, id) {}
/// Returns true iff the mapping possesses an input (source) shape.
virtual bool hasInputShape() const { return false; }
virtual QString getType() const {
return getShape()->getType() + "_color";
}
};
/**
* Object whose paint is an image texture. In the case of a texture mapping we require
* an additional input shape to specify the area on the image where we pick the pixels.
*/
class TextureMapping : public Mapping
{
Q_OBJECT
public:
Q_INVOKABLE TextureMapping(int id=NULL_UID)
: Mapping(id) {}
TextureMapping(Paint::ptr paint,
MShape::ptr shape,
MShape::ptr inputShape, uid id=NULL_UID)
: Mapping(paint, shape, inputShape, id)
{
// Only supports shape of the same type (for now).
Q_ASSERT(shape->getType() == inputShape->getType());
}
/// Returns true iff the mapping possesses an input (source) shape.
virtual bool hasInputShape() const { return true; }
virtual QString getType() const {
return getShape()->getType() + "_texture";
}
};
}
#endif /* MAPPING_H_ */