Blame view

src/ParamOutputImpl/Plot/ParameterAxes.cc 6.12 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * ParameterAxes.cc
 *
 *  Created on: Dec 5, 2013
 *      Author: amdadev
 */

#ifndef PARAMETERAXES_CC
#define PARAMETERAXES_CC

#include "ParameterAxes.hh"

#include <iosfwd>

#include <iostream>
#include <sstream>
#include <map>
#include <stdexcept>
#include <utility>
#include <cstring>

namespace plot {
/**
 * add a new series properties. If a series with the same index
 * already exist, it will be overridden.
 * _index field of SerieProperties must have been properly set
 * before calling this method.
 * @param series properties to add.
 */
2fc1f2f8   Benjamin Renard   Full rework for s...
30
31
32
SeriesProperties* ParameterAxes::addYSerieProperties(const SeriesProperties& s_) {
	_ySeriesProperties.push_back(s_);
	return &_ySeriesProperties.back();
fbe3c2bb   Benjamin Renard   First commit
33
34
35
36
37
38
39
40
41
42
}

/**
 * adds a new X series. If a series with the same index
 * already exist, it will be overridden.
 * _index field of SerieProperties must have been properly set
 * before calling this method.
 * @param series properties to add, with no drawing settings, just index and xAxis
 */
void ParameterAxes::addXSerieProperties(const XSeriesProperties& s_) {
c46af5a8   Benjamin Renard   Implements multi ...
43
	_xSeriesProperties.push_back(s_);
fbe3c2bb   Benjamin Renard   First commit
44
45
46
47
48
49
}

void ParameterAxes::addSpectroProperties(std::shared_ptr<SpectroProperties> pSPectroProperties){
	_spectroPropertiesPtr = pSPectroProperties;
}

793c4351   Hacene SI HADJ MOHAND   creation de class...
50
51
52
53
void ParameterAxes::addSauvaudProperties(std::shared_ptr<SauvaudProperties> pSauvaudProperties){
	_sauvaudPropertiesPtr = pSauvaudProperties;
}

e257cfb9   Benjamin Renard   First implementat...
54
55
56
57
void ParameterAxes::addIntervalsProperties(std::shared_ptr<IntervalsProperties> pIntervalsProperties){
	_intervalsPropertiesPtr = pIntervalsProperties;
}

fbe3c2bb   Benjamin Renard   First commit
58
59
60
61
62
void ParameterAxes::addColorSerieProperties(const ColorSeriesProperties& s_) {
	_colorSeriesProperties.push_back(s_);
}

/**
fbe3c2bb   Benjamin Renard   First commit
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 * Get the list of indexes used for a parameter
 */
std::vector<AMDA::Common::ParameterIndexComponent> ParameterAxes::getParamUsedIndexes(std::string paramId_) {
	std::vector<AMDA::Common::ParameterIndexComponent> keyset;

	if (_spectroPropertiesPtr != nullptr)
	{
		if (_spectroPropertiesPtr->getParamId() == paramId_)
		{
			keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));
			return keyset;
		}

	}
793c4351   Hacene SI HADJ MOHAND   creation de class...
77
78
79
80
81
82
83
84
85
86
87
        
        	if (_sauvaudPropertiesPtr != nullptr)
	{
		if (_sauvaudPropertiesPtr->getParamId() == paramId_)
		{
			keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));
			return keyset;
		}

	}

fbe3c2bb   Benjamin Renard   First commit
88

e257cfb9   Benjamin Renard   First implementat...
89
90
91
92
93
94
95
96
97
	if (_intervalsPropertiesPtr != nullptr)
	{
		if (_intervalsPropertiesPtr->getParamId() == paramId_)
		{
			keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));
			return keyset;
		}
	}

2fc1f2f8   Benjamin Renard   Full rework for s...
98
	for (std::vector<SeriesProperties>::iterator it =
fbe3c2bb   Benjamin Renard   First commit
99
100
101
			_ySeriesProperties.begin(); it != _ySeriesProperties.end(); ++it) {
			// add index only if serie has same paramId to not store
			// unused values
2fc1f2f8   Benjamin Renard   Full rework for s...
102
103
		if (it->getParamId() == paramId_) {
			keyset.push_back(it->getIndex());
fbe3c2bb   Benjamin Renard   First commit
104
105
106
		}
	}

c46af5a8   Benjamin Renard   Implements multi ...
107
	for (std::vector<XSeriesProperties>::iterator it =
fbe3c2bb   Benjamin Renard   First commit
108
109
			_xSeriesProperties.begin(); it != _xSeriesProperties.end(); ++it) {
			// same remark
c46af5a8   Benjamin Renard   Implements multi ...
110
111
		if (it->getParamId() == paramId_) {
			keyset.push_back(it->getIndex());
fbe3c2bb   Benjamin Renard   First commit
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
		}
	}

	for (std::vector<ColorSeriesProperties>::iterator it =
			_colorSeriesProperties.begin(); it != _colorSeriesProperties.end(); ++it) {
			// same remark
		for (auto itColorParam : it->getColorParamIds())
		{
			if (itColorParam.second == paramId_)
				keyset.push_back(it->getIndex());
		}
	}

	return keyset;
}

/**
fbe3c2bb   Benjamin Renard   First commit
129
130
131
132
133
134
135
136
137
138
139
140
 * Get color serie properties by id
 */
 ColorSeriesProperties& ParameterAxes::getColorSeriePropertiesById(int id_) {
	for (auto &prop : _colorSeriesProperties)
		if (prop.getId() == id_)
			return prop;

	std::ostringstream errmsg;
	errmsg << "id '" << id_ << "' not found." << std::endl;
	throw std::out_of_range(errmsg.str());
}

c46af5a8   Benjamin Renard   Implements multi ...
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
 * Get x serie properties by id
 */
XSeriesProperties& ParameterAxes::getXSeriePropertiesById(int id_) {
        for (auto &prop : _xSeriesProperties)
                if (prop.getId() == id_)
                        return prop;

        std::ostringstream errmsg;
        errmsg << "id '" << id_ << "' not found." << std::endl;
        throw std::out_of_range(errmsg.str());
}

fbe3c2bb   Benjamin Renard   First commit
154
155
156
157
158
159
160
161
162
/*
 * Dumps properties for test.
 */
void ParameterAxes::dump(std::ostream& out_, std::string& prefix_) {
	out_ << "[DEFAULT PARAMETER AXES]" << std::endl;
	std::string subPrefix = prefix_ + "default";
	_defaultProperties.dump(out_, subPrefix);

	std::ostringstream os;
2fc1f2f8   Benjamin Renard   Full rework for s...
163
	std::vector<SeriesProperties>::iterator it;
fbe3c2bb   Benjamin Renard   First commit
164
165
166
	for (it = _ySeriesProperties.begin(); it != _ySeriesProperties.end();
			++it) {
		os.str("");
2fc1f2f8   Benjamin Renard   Full rework for s...
167
		os << prefix_ << "yserie" << ".";
fbe3c2bb   Benjamin Renard   First commit
168
		subPrefix = os.str();
2fc1f2f8   Benjamin Renard   Full rework for s...
169
		it->dump(out_, subPrefix);
fbe3c2bb   Benjamin Renard   First commit
170
171
	}

c46af5a8   Benjamin Renard   Implements multi ...
172
	std::vector<XSeriesProperties>::iterator xit;
fbe3c2bb   Benjamin Renard   First commit
173
174
175
	for (xit = _xSeriesProperties.begin(); xit != _xSeriesProperties.end();
			++xit) {
		os.str("");
2fc1f2f8   Benjamin Renard   Full rework for s...
176
		os << prefix_ << "xserie" << ".";
fbe3c2bb   Benjamin Renard   First commit
177
		subPrefix = os.str();
c46af5a8   Benjamin Renard   Implements multi ...
178
		xit->dump(out_, subPrefix);
fbe3c2bb   Benjamin Renard   First commit
179
180
181
182
183
184
185
186
187
	}

	if (_spectroPropertiesPtr != nullptr)
	{
		os.str("");
		os << prefix_ << "spectro" << ".";
		subPrefix = os.str();
		_spectroPropertiesPtr->dump(out_, subPrefix);
	}
793c4351   Hacene SI HADJ MOHAND   creation de class...
188
189
190
191
192
193
194
195
        
        	if (_sauvaudPropertiesPtr != nullptr)
	{
		os.str("");
		os << prefix_ << "sauvaud" << ".";
		subPrefix = os.str();
		_sauvaudPropertiesPtr->dump(out_, subPrefix);
	}
fbe3c2bb   Benjamin Renard   First commit
196

e257cfb9   Benjamin Renard   First implementat...
197
198
199
200
201
202
203
204
	if (_intervalsPropertiesPtr != nullptr)
	{
		os.str("");
		os << prefix_ << "intervals" << ".";
		subPrefix = os.str();
		_intervalsPropertiesPtr->dump(out_, subPrefix);
	}

fbe3c2bb   Benjamin Renard   First commit
205
206
207
208
	std::vector<ColorSeriesProperties>::iterator colorit;
	for (colorit = _colorSeriesProperties.begin(); colorit != _colorSeriesProperties.end();
			++colorit) {
		os.str("");
2fc1f2f8   Benjamin Renard   Full rework for s...
209
		os << prefix_ << "color"  << ".";
fbe3c2bb   Benjamin Renard   First commit
210
211
212
213
214
215
216
217
218
219
220
		subPrefix = os.str();
		colorit->dump(out_, subPrefix);
	}
}

std::ostream& operator<<(std::ostream& out_, const ParameterAxes& prop_) {
	out_ << "[PARAMETER AXES]" << std::endl;
	out_ << "{" << std::endl;
	out_ << "  name =" << prop_._originalParamId << std::endl;
	out_ << "  default properties = " << prop_._defaultProperties << std::endl;
	out_ << "  {" << std::endl;
2fc1f2f8   Benjamin Renard   Full rework for s...
221
	const std::vector<SeriesProperties>::const_iterator end =
fbe3c2bb   Benjamin Renard   First commit
222
			prop_._ySeriesProperties.end();
2fc1f2f8   Benjamin Renard   Full rework for s...
223
	std::vector<SeriesProperties>::const_iterator it;
fbe3c2bb   Benjamin Renard   First commit
224
	for (it = prop_._ySeriesProperties.begin(); it != end; ++it) {
2fc1f2f8   Benjamin Renard   Full rework for s...
225
		out_ << (*it) << std::endl;
fbe3c2bb   Benjamin Renard   First commit
226
227
228
229
230
231
232
233
234
	}
	out_ << "  }" << std::endl;
	out_ << "}" << std::endl;
	return out_;
}

} // end namespace plot

#endif // PARAMETERAXES_CC