27 #include "../common/Exception.h"
28 #include "../common/PlatformUtils.h"
29 #include "../common/STLUtils.h"
30 #include "../common/Translator.h"
42 #include <boost/foreach.hpp>
43 #include <boost/property_tree/ptree.hpp>
44 #include <boost/property_tree/json_parser.hpp>
62 f.open(jsonf.c_str());
72 boost::property_tree::ptree pt;
73 boost::property_tree::json_parser::read_json(f,pt);
74 BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(
"ramps"))
76 std::string name = v.second.get<std::string>(
"name");
83 BOOST_FOREACH(boost::property_tree::ptree::value_type &t, v.second.get_child(
"schemes"))
85 std::string name = t.second.get<std::string>(
"name");
89 std::vector<te::color::RGBAColor>* rgbaVec =
new std::vector<te::color::RGBAColor>();
91 BOOST_FOREACH(boost::property_tree::ptree::value_type &c, t.second.get_child(
"values"))
93 unsigned int red = c.second.get<
unsigned int>(
"red");
94 unsigned int green = c.second.get<
unsigned int>(
"green");
95 unsigned int blue = c.second.get<
unsigned int>(
"blue");
100 cs->push_back(rgbaVec);
108 catch(boost::property_tree::json_parser::json_parser_error &je)
110 std::string errmsg =
"Error parsing: " + je.filename() +
": " + je.message();
114 catch (std::exception
const& e)
116 std::cerr << e.what() << std::endl;
128 m_catalogs.push_back(c);
129 m_catalogIdxByName.insert(std::map<std::string, ColorSchemeCatalog*>::value_type(c->
getName(), c));
137 std::map<std::string, ColorSchemeCatalog*>::iterator itProjectIdxByName = m_catalogIdxByName.find(c->
getName());
139 if(itProjectIdxByName != m_catalogIdxByName.end())
144 for(; i < m_catalogs.size(); ++i)
146 if(m_catalogs[i]->getName() == c->
getName())
150 if(i == m_catalogs.size())
154 m_catalogs.erase(m_catalogs.begin() + i);
155 m_catalogIdxByName.erase(itProjectIdxByName);
168 std::map<std::string, ColorSchemeCatalog*>::const_iterator it = m_catalogIdxByName.find(name);
170 if(it != m_catalogIdxByName.end())
176 std::pair<std::vector<te::color::ColorSchemeCatalog*>::const_iterator,
179 return std::pair<std::vector<te::color::ColorSchemeCatalog*>::const_iterator,
180 std::vector<te::color::ColorSchemeCatalog*>::const_iterator>(m_catalogs.begin(), m_catalogs.end());
190 return m_catalogs.empty();
199 m_catalogIdxByName.clear();
ColorSchemeCatalog * findByName(const std::string &name) const
It returns the catalog identified by a given name or NULL if none is found.
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib.
This class represents a group of color schemes.
void erase(ColorSchemeCatalog *c)
It removes the catalog from the manager and clears it resources.
It models the concept of color scheme.
#define TE_TR(message)
It marks a string in order to get translated.
void clear()
It unloads all catalogs managed by ColorSchemeCatalogManager.
bool isEmpty() const
It returns true if the manager contains at least one catalog. If no catalog exists, it returns false.
The ColorSchemeCatalogManager is a singleton that can be used to manage all loaded color scheme catal...
void push_back(ColorSchemeGroup *group)
It adds a new group to the catalog and sets its relationship.
void disconnect(ColorSchemeCatalog *c)
It removes the internal reference to the catalog.
void init()
Inializes the manager from a JSON file containing instances of color schemes.
const std::string & getName() const
It returns the catalog name.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
void insert(ColorSchemeCatalog *c)
It inserts a new catalog that will be managed by ColorSchemeCatalogManager.
const std::vector< ColorSchemeCatalog * > & getCatalogs() const
It returns the list of catalogs available in the system.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
The concept of color scheme.
ColorSchemeCatalogManager()
It initializes the Singleton.
This class represents a group of color schemes.
A catalog for color schemes.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
A catalog for color schemes groups.
std::pair< std::vector< ColorSchemeCatalog * >::const_iterator, std::vector< ColorSchemeCatalog * >::const_iterator > getIterator() const
It returns a pair of iterators over the catalogs of this manager.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
~ColorSchemeCatalogManager()
Destructor.