27 #include "../common/Exception.h" 28 #include "../common/STLUtils.h" 29 #include "../core/utils/Platform.h" 30 #include "../core/translator/Translator.h" 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 for(boost::property_tree::ptree::value_type &v: pt.get_child(
"ramps"))
76 std::string name = v.second.get<std::string>(
"name");
83 for(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 for(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;
168 std::map<std::string, ColorSchemeCatalog*>::const_iterator it =
m_catalogIdxByName.find(name);
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());
ColorSchemeCatalog * findByName(const std::string &name) const
It returns the catalog identified by a given name or NULL if none is found.
std::map< std::string, ColorSchemeCatalog * > m_catalogIdxByName
An index from catalog's name to catalog's instance (note: we can not have duplicated names)...
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_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
#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.
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.
std::vector< ColorSchemeCatalog * > m_catalogs
This is the list of all system's loaded catalogs.
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.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
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.