/* * ParameterAxes.cc * * Created on: Dec 5, 2013 * Author: amdadev */ #ifndef PARAMETERAXES_CC #define PARAMETERAXES_CC #include "ParameterAxes.hh" #include #include #include #include #include #include #include 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. */ SeriesProperties* ParameterAxes::addYSerieProperties(const SeriesProperties& s_) { _ySeriesProperties.push_back(s_); return &_ySeriesProperties.back(); } /** * 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_) { _xSeriesProperties.push_back(s_); } void ParameterAxes::addSpectroProperties(std::shared_ptr pSPectroProperties){ _spectroPropertiesPtr = pSPectroProperties; } void ParameterAxes::addSauvaudProperties(std::shared_ptr pSauvaudProperties){ _sauvaudPropertiesPtr = pSauvaudProperties; } void ParameterAxes::addIntervalsProperties(std::shared_ptr pIntervalsProperties){ _intervalsPropertiesPtr = pIntervalsProperties; } void ParameterAxes::addColorSerieProperties(const ColorSeriesProperties& s_) { _colorSeriesProperties.push_back(s_); } /** * Get the list of indexes used for a parameter */ std::vector ParameterAxes::getParamUsedIndexes(std::string paramId_) { std::vector keyset; if (_spectroPropertiesPtr != nullptr) { if (_spectroPropertiesPtr->getParamId() == paramId_) { keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1)); return keyset; } } if (_sauvaudPropertiesPtr != nullptr) { if (_sauvaudPropertiesPtr->getParamId() == paramId_) { keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1)); return keyset; } } if (_intervalsPropertiesPtr != nullptr) { if (_intervalsPropertiesPtr->getParamId() == paramId_) { keyset.push_back(AMDA::Common::ParameterIndexComponent(-1,-1)); return keyset; } } for (std::vector::iterator it = _ySeriesProperties.begin(); it != _ySeriesProperties.end(); ++it) { // add index only if serie has same paramId to not store // unused values if (it->getParamId() == paramId_) { keyset.push_back(it->getIndex()); } } for (std::vector::iterator it = _xSeriesProperties.begin(); it != _xSeriesProperties.end(); ++it) { // same remark if (it->getParamId() == paramId_) { keyset.push_back(it->getIndex()); } } for (std::vector::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; } /** * 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()); } /** * 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()); } /* * 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; std::vector::iterator it; for (it = _ySeriesProperties.begin(); it != _ySeriesProperties.end(); ++it) { os.str(""); os << prefix_ << "yserie" << "."; subPrefix = os.str(); it->dump(out_, subPrefix); } std::vector::iterator xit; for (xit = _xSeriesProperties.begin(); xit != _xSeriesProperties.end(); ++xit) { os.str(""); os << prefix_ << "xserie" << "."; subPrefix = os.str(); xit->dump(out_, subPrefix); } if (_spectroPropertiesPtr != nullptr) { os.str(""); os << prefix_ << "spectro" << "."; subPrefix = os.str(); _spectroPropertiesPtr->dump(out_, subPrefix); } if (_sauvaudPropertiesPtr != nullptr) { os.str(""); os << prefix_ << "sauvaud" << "."; subPrefix = os.str(); _sauvaudPropertiesPtr->dump(out_, subPrefix); } if (_intervalsPropertiesPtr != nullptr) { os.str(""); os << prefix_ << "intervals" << "."; subPrefix = os.str(); _intervalsPropertiesPtr->dump(out_, subPrefix); } std::vector::iterator colorit; for (colorit = _colorSeriesProperties.begin(); colorit != _colorSeriesProperties.end(); ++colorit) { os.str(""); os << prefix_ << "color" << "."; 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; const std::vector::const_iterator end = prop_._ySeriesProperties.end(); std::vector::const_iterator it; for (it = prop_._ySeriesProperties.begin(); it != end; ++it) { out_ << (*it) << std::endl; } out_ << " }" << std::endl; out_ << "}" << std::endl; return out_; } } // end namespace plot #endif // PARAMETERAXES_CC