-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMappingManager.cpp
123 lines (106 loc) · 3.43 KB
/
MappingManager.cpp
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
/*
* MappingManager.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)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/>.
*/
#include "MappingManager.h"
MappingManager::MappingManager()
{
// TODO Auto-generated constructor stub
}
std::map<uint, Mapping::ptr> MappingManager::getPaintMappings(const Paint::ptr paint) const
{
std::map<uint, Mapping::ptr> paintMappings;
for (std::vector<Mapping::ptr>::const_iterator it = mappingVector.begin(); it != mappingVector.end(); ++it)
{
if ((*it)->getPaint() == paint)
paintMappings[(*it)->getId()] = *it;
}
return paintMappings;
}
std::map<uint, Mapping::ptr> MappingManager::getPaintMappingsById(uint paintId) const
{
return getPaintMappings( paintMap.at(paintId) );
}
uint MappingManager::addPaint(Paint::ptr paint)
{
paintVector.push_back(paint);
paintMap[paint->getId()] = paint;
return paint->getId();
}
uint MappingManager::addImage(const QString imagePath, int frameWidth, int frameHeight)
{
Image* img = new Image(imagePath);
img->setPosition( (frameWidth - img->getWidth() ) / 2.0f,
(frameHeight - img->getHeight()) / 2.0f );
return addPaint(Paint::ptr(img));
}
//bool MappingManager::removePaint(Paint::ptr paint)
//{
//
//}
uint MappingManager::addMapping(Mapping::ptr mapping)
{
// Make sure the paint to which this mapping refers to exists in the manager.
Q_ASSERT (std::find(paintVector.begin(), paintVector.end(), mapping->getPaint()) != paintVector.end());
mappingVector.push_back(mapping);
mappingMap[mapping->getId()] = mapping;
return mapping->getId();
}
uint MappingManager::addLayer(Mapping::ptr mapping)
{
addMapping(mapping);
Layer::ptr layer(new Layer);
layer->setMapping(mapping);
mapping->setLayer(layer.get());
layerVector.push_back(layer);
layerMap[layer->getId()] = layer;
return layer->getId();
}
std::vector<Layer::ptr> MappingManager::getVisibleLayers() const
{
std::vector<Layer::ptr> visible;
bool hasSolo = false;
for (std::vector<Layer::ptr>::const_iterator it = layerVector.begin(); it != layerVector.end(); ++it)
{
if ((*it)->isSolo())
{
hasSolo = true;
break;
}
}
for (std::vector<Layer::ptr>::const_iterator it = layerVector.begin(); it != layerVector.end(); ++it)
{
// Solo has priority over invisible (mute)
if ( (hasSolo && (*it)->isSolo()) || (!hasSolo && (*it)->isVisible()) )
visible.push_back(*it);
}
return visible;
}
void MappingManager::reorderLayers(std::vector<uint> layerIds)
{
Q_ASSERT( layerIds.size() == layerVector.size() );
// TODO: do a better check than this...
layerVector.clear();
for (std::vector<uint>::iterator it = layerIds.begin(); it != layerIds.end(); ++it)
{
Q_ASSERT( layerMap.find(*it) != layerMap.end() );
layerVector.push_back( layerMap[*it] );
}
}
//bool MappingManager::removeMapping(Mapping::ptr mapping)
//{
//}