@@ -50,6 +50,7 @@ extern TkUtil::PythonSession* createMgx3DPythonSession ( );
5050#include < TkUtil/Process.h>
5151#include < TkUtil/ThreadManager.h>
5252#include < TkUtil/ThreadPool.h>
53+ #include < PrefsXerces/XMLLoader.h>
5354
5455#include < signal.h>
5556#include < unistd.h>
@@ -231,6 +232,7 @@ static TkUtil::Color nextColor (
231232TkUtil::Log::TYPE Context::m_logMask = TkUtil::Log::PRODUCTION;
232233TkUtil::ArgumentsMap Context::m_argumentsMap;
233234TkUtil::Charset Context::m_outCharset (TkUtil::Charset::UTF_8);
235+ std::map<std::string, TkUtil::Color> Context::m_groups_colors;
234236
235237TkUtil::Color Context::m_initial_geom_displayColor (255 , 0 , 127 );
236238TkUtil::Color Context::m_initial_topo_displayColor (0 , 1 , 1 ); // Initialisé dans initialize
@@ -705,6 +707,30 @@ void Context::initialize (int argc, char* argv [])
705707 255 *Internal::InternalPreferences::instance ( )._topoColorWithoutProj .getRed ( ),
706708 255 *Internal::InternalPreferences::instance ( )._topoColorWithoutProj .getGreen ( ),
707709 255 *Internal::InternalPreferences::instance ( )._topoColorWithoutProj .getBlue ( )); // bleu, pas de proj
710+
711+ // Chargement des éventuelles associations nom de groupes -> couleurs transmises à la ligne de commande via un fichier xml :
712+ std::string fileName;
713+ try
714+ {
715+ if (true == m_argumentsMap.hasArg (" --groupsColors" ))
716+ {
717+ fileName = m_argumentsMap.getArgValue (" --groupsColors" , std::string ( ), true );
718+ std::cout << " Chargement des propriétés d'affichage des entités pour cette session depuis le fichier " << fileName << " ..." << std::endl;
719+ std::unique_ptr<Preferences::Section> mainSection (Preferences::XMLLoader::load (fileName));
720+ Preferences::Section& groupsSection = mainSection->getSection (" Groups" );
721+ loadGroupsColors (groupsSection);
722+ std::cout << " Propriétés d'affichage des entités chargées." << std::endl;
723+ } // if (true == m_argumentsMap.hasArg ("--groupsColors"))
724+ }
725+ catch (const TkUtil::Exception& exc)
726+ {
727+ std::cerr << " Echec du chargement des propriétés d'affichage des entités depuis le fichier \" " << fileName << " \" :" << std::endl
728+ << exc.getFullMessage ( ) << std::endl;
729+ }
730+ catch (...)
731+ {
732+ std::cerr << " Echec du chargement des propriétés d'affichage des entités depuis le fichier \" " << fileName << " \" : erreur non documentée." << std::endl;
733+ }
708734}
709735/* ----------------------------------------------------------------------------*/
710736void Context::finalize ( )
@@ -948,6 +974,27 @@ std::string Context::createName (const std::string& base) const
948974 return name.iso ( );
949975} // Context::createName
950976/* ----------------------------------------------------------------------------*/
977+ void Context::loadGroupsColors (const Preferences::Section& section)
978+ {
979+ const std::vector<Preferences::Section*>& groups = section.getSections ( );
980+ for (std::vector<Preferences::Section*>::const_iterator itg = groups.begin ( ); groups.end ( ) != itg; itg++)
981+ {
982+ try
983+ {
984+ Preferences::NamedValue& namedValue = (*itg)->getNamedValue (" color" );
985+ Preferences::ColorNamedValue* colorValue = dynamic_cast <Preferences::ColorNamedValue*>(&namedValue);
986+ if (0 != colorValue)
987+ {
988+ TkUtil::Color color ((unsigned char )(255 * colorValue->getRed ( )), (unsigned char )(255 * colorValue->getGreen ( )), (unsigned char )(255 * colorValue->getBlue ( )));
989+ m_groups_colors.insert_or_assign ((*itg)->getName ( ), color);
990+ } // if (0 != colorValue)
991+ }
992+ catch (...)
993+ {
994+ }
995+ } // for (std::vector<Preferences::Section*>::const_iterator itg = groups.begin ( ); groups.end ( ) != itg; itg++)
996+ } // Context::loadGroupsColors
997+ /* ----------------------------------------------------------------------------*/
951998unsigned long Context::newUniqueId ()
952999{
9531000 return getNameManager ().getUniqueId ();
@@ -1370,6 +1417,34 @@ void Context::newGraphicalRepresentation (Utils::Entity& entity)
13701417 entity.getDisplayProperties ( ).setGraphicalRepresentation (representation);
13711418} // Context::newGraphicalRepresentation
13721419/* ----------------------------------------------------------------------------*/
1420+ bool Context::getGroupColor (const std::vector<Group::GroupEntity*>& groups, TkUtil::Color& color)
1421+ {
1422+ for (std::vector<Group::GroupEntity*>::const_iterator itg = groups.begin ( ); groups.end ( ) != itg; itg++)
1423+ {
1424+ try
1425+ {
1426+ color = getGroupColor ((*itg)->getName ( ));
1427+ return true ;
1428+ }
1429+ catch (...)
1430+ {
1431+ }
1432+ } // for (std::vector<Group::GroupEntity*>::const_iterator itg = groups.begin ( ); groups.end ( ) != itg; itg++)
1433+
1434+ return false ;
1435+ } // Context::getGroupColor
1436+ /* ----------------------------------------------------------------------------*/
1437+ TkUtil::Color Context::getGroupColor (const std::string& name)
1438+ {
1439+ const std::map<std::string, TkUtil::Color>::iterator it = m_groups_colors.find (name);
1440+ if (m_groups_colors.end ( ) != it)
1441+ return it->second ;
1442+
1443+ TkUtil::UTF8String message;
1444+ message << " Context::groupColor. Couleur pour le groupe de données \" " << name << " \" non recensée." ;
1445+ throw TkUtil::Exception (message);
1446+ } // Context::getGroupColor
1447+ /* ----------------------------------------------------------------------------*/
13731448void Context::undo ()
13741449{
13751450 getCommandManager ().undo ();
0 commit comments