From: vsv Date: Thu, 14 Aug 2014 15:35:33 +0000 (+0400) Subject: Preferences improvement X-Git-Tag: V_0.4.4~105^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1b587c92a6855e2bd217a65bb0295d0fd720e77d;p=modules%2Fshaper.git Preferences improvement --- diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h index 3e5ab7f42..246df8074 100644 --- a/src/Config/Config_Prop.h +++ b/src/Config/Config_Prop.h @@ -15,7 +15,7 @@ class Config_Prop { public: - enum PropType { Auto, Space, Bool, Color, String, Selector, + enum PropType { Disabled, Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, GroupBox, Tab, Frame, Font, DirList, File, Slider, Shortcut, ShortcutTree, BiColor, Background }; @@ -42,9 +42,20 @@ public: std::string section() const { return mySection; } std::string name() const { return myName; } + std::string title() const { return myTitle; } + void setTitle(const std::string& theTitle) { myTitle = theTitle; } + PropType type() const { return myType; } + void setType(PropType theType) { myType = theType; } + std::string value() const { return myValue; } + void setValue(const std::string& theValue) { myValue = theValue; } + + bool operator==(const Config_Prop* theProp) const + { + return (mySection == theProp->section()) && (myName == theProp->name()); + } private: std::string mySection; diff --git a/src/Config/Config_PropManager.cpp b/src/Config/Config_PropManager.cpp index b8593206d..4fa3d7090 100644 --- a/src/Config/Config_PropManager.cpp +++ b/src/Config/Config_PropManager.cpp @@ -5,83 +5,93 @@ #include "Config_PropManager.h" -std::map Config_PropManager::myPropMap; +std::vector stringToRGB(const std::string& theColor); +int stringToInteger(const std::string& theInt); +double stringToDouble(const std::string& theDouble); -bool Config_PropManager::registerProp(const std::string& theOwnerId, - const std::string& theSection, +Config_Properties Config_PropManager::myProps; + + + +bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName, const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue) { - Config_Prop* aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue); - return registerProp(theOwnerId, aProp); -} - -bool Config_PropManager::registerProp(const std::string& theOwnerId, - Config_Prop* theProp) -{ - if (myPropMap.find(theOwnerId) == myPropMap.end()) { - Config_Properties aPropList; - aPropList.push_back(theProp); - myPropMap[theOwnerId] = aPropList; - } else { - myPropMap[theOwnerId].push_back(theProp); + Config_Prop* aProp = findProp(theSection, theName); + if (aProp) { + if (aProp->type() == Config_Prop::Disabled) { + aProp->setType(theType); + aProp->setTitle(theTitle); + return true; + } + return false; } + aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue); + myProps.push_back(aProp); return true; } -std::list Config_PropManager::getOwners() +Config_Prop* Config_PropManager::findProp(const std::string& theSection, + const std::string& theName) { - std::list aKeys; - std::map::const_iterator aIt; - for (aIt = myPropMap.cbegin(); aIt != myPropMap.cend(); ++aIt) - aKeys.push_back((*aIt).first); - return aKeys; + Config_Properties::const_iterator aIt; + for (aIt = myProps.cbegin(); aIt != myProps.cend(); ++aIt) { + Config_Prop* aProp = (*aIt); + if ((aProp->section() == theSection) && (aProp->name() == theName)) + return aProp; + } + return NULL; } -Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId) + +Config_Properties Config_PropManager::getProperties() { - return myPropMap[theOwnerId]; + Config_Properties aRes; + Config_Properties::const_iterator aIt; + for (aIt = myProps.cbegin(); aIt != myProps.cend(); aIt++) { + Config_Prop* aProp = (*aIt); + if (aProp->type() != Config_Prop::Disabled) + aRes.push_back(aProp); + } + return aRes; } - -std::list Config_PropManager::getSections(const std::string& theOwnerId) +std::list Config_PropManager::getSections() { + // Return only non disabled sections std::list aSections; - Config_Properties aProps = getProperties(theOwnerId); Config_Properties::const_iterator aIt; - for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) { + for (aIt = myProps.cbegin(); aIt != myProps.cend(); aIt++) { const Config_Prop* aProp = (*aIt); - aSections.push_back(aProp->section()); + if (aProp->type() != Config_Prop::Disabled) + aSections.push_back(aProp->section()); } aSections.unique(); return aSections; } -Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId, - const std::string& theSection) +Config_Properties Config_PropManager::getProperties(const std::string& theSection) { - Config_Properties aProps = getProperties(theOwnerId); Config_Properties aRes; Config_Properties::iterator aIt; - for (aIt = aProps.begin(); aIt != aProps.end(); aIt++) { + for (aIt = myProps.begin(); aIt != myProps.end(); aIt++) { Config_Prop* aProp = (*aIt); - if (aProp->section() == theSection) + if ((aProp->section() == theSection) && (aProp->type() != Config_Prop::Disabled)) aRes.push_back(aProp); } return aRes; } -std::string Config_PropManager::value(const std::string& theOwnerId, - const std::string& theSection, +std::string Config_PropManager::string(const std::string& theSection, const std::string& theName, const std::string& theDefault) { - Config_Properties aProps = getProperties(theOwnerId, theSection); + Config_Properties aProps = getProperties(theSection); Config_Properties::const_iterator aIt; for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) { Config_Prop* aProp = (*aIt); @@ -92,30 +102,81 @@ std::string Config_PropManager::value(const std::string& theOwnerId, } +std::vector Config_PropManager::color(const std::string& theSection, + const std::string& theName, + const std::string& theDefault) +{ + std::string aStr = string(theSection, theName, theDefault); + return stringToRGB(aStr); +} + +int Config_PropManager::integer(const std::string& theSection, + const std::string& theName, + const std::string& theDefault) +{ + std::string aStr = string(theSection, theName, theDefault); + return stringToInteger(aStr); +} + +double Config_PropManager::real(const std::string& theSection, + const std::string& theName, + const std::string& theDefault) +{ + std::string aStr = string(theSection, theName, theDefault); + return stringToDouble(aStr); +} + + + std::vector stringToRGB(const std::string& theColor) { std::vector aRes(3); - int aPos = theColor.find(","); - char aBuf[10]; - // Get Red - std::size_t length = theColor.copy(aBuf, aPos, 0); - aBuf[length] = '\0'; - int aC = atoi(aBuf); - aRes[0] = aC; - - // Get Green - int aNPos = theColor.find(",", aPos + 1); - length = theColor.copy(aBuf, aNPos - aPos - 1, aPos + 1); - aBuf[length] = '\0'; - aC = atoi(aBuf); - aRes[1] = aC; - - // Get Green - length = theColor.copy(aBuf, theColor.length() - aNPos - 1, aNPos + 1); - aBuf[length] = '\0'; - aC = atoi(aBuf); - aRes[2] = aC; + if (theColor[0] == '#') { + char aBuf[3]; + char* aP; + aBuf[2] = '\0'; + + aBuf[0] = theColor[1]; + aBuf[1] = theColor[2]; + aRes[0] = strtol(aBuf, &aP, 16); + aBuf[0] = theColor[3]; + aBuf[1] = theColor[4]; + aRes[1] = strtol(aBuf, &aP, 16); + + aBuf[0] = theColor[5]; + aBuf[1] = theColor[6]; + aRes[2] = strtol(aBuf, &aP, 16); + } else { + int aPos = theColor.find(","); + char aBuf[10]; + // Get Red + std::size_t length = theColor.copy(aBuf, aPos, 0); + aBuf[length] = '\0'; + aRes[0] = atoi(aBuf); + + // Get Green + int aNPos = theColor.find(",", aPos + 1); + length = theColor.copy(aBuf, aNPos - aPos - 1, aPos + 1); + aBuf[length] = '\0'; + aRes[1] = atoi(aBuf); + + // Get Green + length = theColor.copy(aBuf, theColor.length() - aNPos - 1, aNPos + 1); + aBuf[length] = '\0'; + aRes[2] = atoi(aBuf); + } return aRes; -} \ No newline at end of file +} + +int stringToInteger(const std::string& theInt) +{ + return atoi(theInt.c_str()); +} + +double stringToDouble(const std::string& theDouble) +{ + char* p; + return strtod(theDouble.c_str(), &p); +} diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index 4a6d43226..d650b0e38 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -26,46 +26,40 @@ public: * \param theValue - initial value of the property * Returns True if the property succesfully registered */ - static bool registerProp(const std::string& theOwnerId, - const std::string& theSection, + static bool registerProp(const std::string& theSection, const std::string& theName, const std::string& theTitle, Config_Prop::PropType theType, const std::string& theValue); - //! Returns list of registered owners. - static std::list getOwners(); + static Config_Prop* findProp(const std::string& theSection, + const std::string& theName); - //! Returns list of properties by its owner. - static Config_Properties getProperties(const std::string& theOwnerId); + static Config_Properties getProperties(); //! Returns list of registered section names. - static std::list getSections(const std::string& theOwnerId); + static std::list getSections(); //! Returns list of properties by its owner and section. - static Config_Properties getProperties(const std::string& theOwnerId, const std::string& theSection); + static Config_Properties getProperties(const std::string& theSection); //! Returns value of the property by its owner, section, and name - static std::string value(const std::string& theOwnerId, - const std::string& theSection, - const std::string& theName, - const std::string& theDefault); + static std::string string(const std::string& theSection, + const std::string& theName, + const std::string& theDefault); + static std::vector color(const std::string& theSection, + const std::string& theName, + const std::string& theDefault); + static int integer(const std::string& theSection, + const std::string& theName, + const std::string& theDefault); + static double real(const std::string& theSection, + const std::string& theName, + const std::string& theDefault); private: - - /** - * Registers property parameters - * \param theOwnerId - name of owner (name of plugin for example) - * \param theProp - the Property object. - * Returns True if the property succesfully registered - */ - static bool registerProp(const std::string& theOwnerId, - Config_Prop* theProp); - - static std::map myPropMap; + static Config_Properties myProps; }; -CONFIG_EXPORT std::vector stringToRGB(const std::string& theColor); - #endif \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index de05942fe..4d043e48b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -118,9 +118,7 @@ boost::shared_ptr SketchPlugin_ConstraintDistance::getAISObje anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); // Set color from preferences - std::string aColor = Config_PropManager::value("Sketcher", "Visualization", - "distance_color", DISTANCE_COLOR); - std::vector aRGB = stringToRGB(aColor); + std::vector aRGB = Config_PropManager::color("Visualization", "distance_color", DISTANCE_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index b63c170c5..790068b95 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -15,7 +15,7 @@ class SketchPlugin_Line; class GeomDataAPI_Point2D; -#define DISTANCE_COLOR "255, 0, 255" +#define DISTANCE_COLOR "#ff00ff" /** \class SketchPlugin_ConstraintDistance * \ingroup DataModel diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 7e3ddfd5f..fcd4a4053 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -96,9 +96,7 @@ boost::shared_ptr SketchPlugin_ConstraintLength::getAISObject anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue); // Set color from preferences - std::string aColor = Config_PropManager::value("Sketcher", "Visualization", - "length_color", LENGTH_COLOR); - std::vector aRGB = stringToRGB(aColor); + std::vector aRGB = Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 52d26854a..461cb5ac8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -10,7 +10,7 @@ #include #include -#define LENGTH_COLOR "255, 0, 255" +#define LENGTH_COLOR "#ff00ff" /** \class SketchPlugin_ConstraintLength * \ingroup DataModel diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index ea09ad9cf..e9bcfd0a3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -81,9 +81,7 @@ boost::shared_ptr SketchPlugin_ConstraintParallel::getAISObje anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane); // Set color from preferences - std::string aColor = Config_PropManager::value("Sketcher", "Visualization", - "parallel_color", PARALLEL_COLOR); - std::vector aRGB = stringToRGB(aColor); + std::vector aRGB = Config_PropManager::color("Visualization", "parallel_color", PARALLEL_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h index 9b0570fc0..6e02e1c99 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.h @@ -10,7 +10,7 @@ #include "SketchPlugin_Constraint.h" -#define PARALLEL_COLOR "255, 255, 0" +#define PARALLEL_COLOR "#ffff00" /** \class SketchPlugin_ConstraintParallel * \ingroup DataModel diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index e844f559d..df192e8d9 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -77,9 +77,7 @@ boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAI anAIS->createPerpendicular(aLine1, aLine2, aPlane); // Set color from preferences - std::string aColor = Config_PropManager::value("Sketcher", "Visualization", - "perpendicular_color", PERPENDICULAR_COLOR); - std::vector aRGB = stringToRGB(aColor); + std::vector aRGB = Config_PropManager::color("Visualization", "perpendicular_color", PERPENDICULAR_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h index d6d54b33b..ac565f076 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h @@ -9,7 +9,7 @@ #include #include "SketchPlugin_Constraint.h" -#define PERPENDICULAR_COLOR "255, 255, 0" +#define PERPENDICULAR_COLOR "#ffff00" /** \class SketchPlugin_ConstraintPerpendicular * \ingroup DataModel diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 729564170..31b253d54 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -123,9 +123,7 @@ boost::shared_ptr SketchPlugin_ConstraintRadius::getAISObject anAIS->createRadius(aCircle, aFlyoutPnt, aValue); // Set color from preferences - std::string aColor = Config_PropManager::value("Sketcher", "Visualization", - "radius_color", RADIUS_COLOR); - std::vector aRGB = stringToRGB(aColor); + std::vector aRGB = Config_PropManager::color("Visualization", "radius_color", RADIUS_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index 6950b9c0c..a6f1e16ae 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -9,7 +9,7 @@ #include #include "SketchPlugin_Constraint.h" -#define RADIUS_COLOR "255, 0, 255" +#define RADIUS_COLOR "#ff00ff" /** \class SketchPlugin_ConstraintRadius * \ingroup DataModel diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 1a44e2860..8f9870134 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -16,8 +16,6 @@ using namespace std; -// face of the square-face displayed for selection of general plane -const double PLANE_SIZE = 200; SketchPlugin_Line::SketchPlugin_Line() : SketchPlugin_Feature() diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 28c20ff4e..eb0b16c3f 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -32,19 +32,29 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() ModelAPI_PluginManager::get()->registerPlugin(this); // register sketcher properties - Config_PropManager::registerProp("Sketcher", "Visualization", + Config_PropManager::registerProp("Sketch planes", + "planes_color", "Color", + Config_Prop::Color, SKETCH_PLANE_COLOR); + Config_PropManager::registerProp("Sketch planes", + "planes_size", "Size", + Config_Prop::Double, PLANE_SIZE); + Config_PropManager::registerProp("Sketch planes", + "planes_thikness", "Thickness", + Config_Prop::Integer, SKETCH_WIDTH); + + Config_PropManager::registerProp("Visualization", "parallel_color", "Parallel constraint color", Config_Prop::Color, PARALLEL_COLOR); - Config_PropManager::registerProp("Sketcher", "Visualization", + Config_PropManager::registerProp("Visualization", "perpendicular_color", "Perpendicular constraint color", Config_Prop::Color, PERPENDICULAR_COLOR); - Config_PropManager::registerProp("Sketcher", "Visualization", + Config_PropManager::registerProp("Visualization", "distance_color", "Distance color", Config_Prop::Color, DISTANCE_COLOR); - Config_PropManager::registerProp("Sketcher", "Visualization", + Config_PropManager::registerProp("Visualization", "length_color", "Length color", Config_Prop::Color, LENGTH_COLOR); - Config_PropManager::registerProp("Sketcher", "Visualization", + Config_PropManager::registerProp("Visualization", "radius_color", "Radius color", Config_Prop::Color, RADIUS_COLOR); } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index b3cacc6ae..0b0381ab7 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -14,14 +14,10 @@ #include #include +#include using namespace std; -const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color -const double SKETCH_WIDTH = 4.0; /// the plane edge width -// face of the square-face displayed for selection of general plane -const double PLANE_SIZE = 200; - SketchPlugin_Sketch::SketchPlugin_Sketch() { @@ -138,8 +134,9 @@ void addPlane(double theX, double theY, double theZ, std::list anOrigin(new GeomAPI_Pnt(0, 0, 0)); boost::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); + double aSize = Config_PropManager::integer("Sketch definition", "Size of planes", PLANE_SIZE); boost::shared_ptr aFace = - GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE); + GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, aSize); theShapes.push_back(aFace); } @@ -160,8 +157,15 @@ boost::shared_ptr SketchPlugin_Sketch:: boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); aAIS = boost::shared_ptr(new GeomAPI_AISObject()); aAIS->createShape(aCompound); - aAIS->setColor(SKETCH_PLANE_COLOR); - aAIS->setWidth(SKETCH_WIDTH); + + std::vector aRGB = Config_PropManager::color("Sketch definition", + "planes_color", + SKETCH_PLANE_COLOR); + aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); + + aAIS->setWidth(Config_PropManager::integer("Sketch definition", + "planes_thikness", + SKETCH_WIDTH)); } return aAIS; } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 3c71a6505..c0845fa85 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -12,6 +12,15 @@ #include #include +/// the plane edge color +#define SKETCH_PLANE_COLOR "#700000" + +/// the plane edge width +#define SKETCH_WIDTH "4" + +/// face of the square-face displayed for selection of general plane +#define PLANE_SIZE "200" + /**\class SketchPlugin_Sketch * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. diff --git a/src/XGUI/XGUI_Preferences.cpp b/src/XGUI/XGUI_Preferences.cpp index b310ba7ce..266580799 100644 --- a/src/XGUI/XGUI_Preferences.cpp +++ b/src/XGUI/XGUI_Preferences.cpp @@ -42,6 +42,35 @@ bool XGUI_Preferences::editPreferences(XGUI_Prefs& theModified) } +void XGUI_Preferences::updateCustomProps() +{ + Config_Properties aProps = Config_PropManager::getProperties(); + Config_Properties::iterator aIt; + for (aIt = aProps.begin(); aIt != aProps.end(); ++ aIt) { + Config_Prop* aProp = (*aIt); + QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()), + QString(aProp->name().c_str())); + if (!aVal.isNull()) + aProp->setValue(qPrintable(aVal)); + } +} + + +void XGUI_Preferences::loadCustomProps() +{ + QStringList aSections = myResourceMgr->sections(); + foreach (QString aSection, aSections) { + QStringList aParams = myResourceMgr->parameters(aSection); + foreach (QString aParam, aParams) { + Config_PropManager::registerProp(qPrintable(aSection), + qPrintable(aParam), + "", Config_Prop::Disabled, + qPrintable(myResourceMgr->stringValue(aSection, aParam))); + } + } +} + + //********************************************************** //********************************************************** @@ -78,18 +107,15 @@ XGUI_PreferencesDlg::~XGUI_PreferencesDlg() void XGUI_PreferencesDlg::createEditors() { - int aLFpage = myPreferences->addItem("Desktop"); - //myPreferences->setItemIcon(aLFpage, QIcon(":pictures/view_prefs.png")); + int aPage = myPreferences->addItem(tr("Desktop")); + myPreferences->setItemIcon(aPage, QIcon(":pictures/view_prefs.png")); - createMenuPage(aLFpage); - createViewerPage(aLFpage); + createMenuPage(aPage); + createViewerPage(aPage); - std::list aOwners = Config_PropManager::getOwners(); - std::list::const_iterator aIt; - for (aIt = aOwners.cbegin(); aIt != aOwners.cend(); ++ aIt) { - int aPage = myPreferences->addItem((*aIt).c_str()); - createCustomPage(aPage, Config_PropManager::getProperties((*aIt))); - } + aPage = myPreferences->addItem(tr("Module")); + myPreferences->setItemIcon(aPage, QIcon(":pictures/module.png")); + createCustomPage(aPage); } void XGUI_PreferencesDlg::createViewerPage(int thePageId) @@ -152,44 +178,35 @@ void XGUI_PreferencesDlg::createMenuPage(int thePageId) } -void XGUI_PreferencesDlg::createCustomPage(int thePageId, Config_Properties& theProps) +void XGUI_PreferencesDlg::createCustomPage(int thePageId) { SUIT_ResourceMgr* aResMgr = XGUI_Preferences::resourceMgr(); bool isResModified = false; - // Sort by sections - QMap aGroupMap; - Config_Properties::const_iterator aIt; - for (aIt = theProps.cbegin(); aIt != theProps.cend(); ++aIt) { - QString aGroup((*aIt)->section().c_str()); - if (aGroupMap.contains(aGroup)) { - aGroupMap[aGroup].push_back(*aIt); - } else { - Config_Properties aProps; - aProps.push_back(*aIt); - aGroupMap[aGroup] = aProps; - } - // check that the property is defined - QString aName((*aIt)->name().c_str()); - if (!aResMgr->hasValue(aGroup, aName)) { - aResMgr->setValue(aGroup, aName, QString((*aIt)->value().c_str())); - isResModified = true; - } - } - if (isResModified) - aResMgr->save(); - // Make a Tab from each section - QMap::iterator it; - for (it = aGroupMap.begin(); it != aGroupMap.end(); ++it) { - int aTab = myPreferences->addItem(it.key(), thePageId ); + std::list aSections = Config_PropManager::getSections(); + std::list::const_iterator it; + for (it = aSections.cbegin(); it != aSections.cend(); ++it) { + Config_Properties aProps = Config_PropManager::getProperties(*it); + int aTab = myPreferences->addItem(QString((*it).c_str()), thePageId ); myPreferences->setItemProperty( "columns", 2, aTab ); - Config_Properties& aProps = it.value(); + + Config_Properties::const_iterator aIt; for (aIt = aProps.cbegin(); aIt != aProps.cend(); ++aIt) { - myPreferences->addItem( QString((*aIt)->title().c_str()), aTab, - (SUIT_PreferenceMgr::PrefItemType)(*aIt)->type(), - QString((*aIt)->section().c_str()), - QString((*aIt)->name().c_str()) ); + Config_Prop* aProp = (*aIt); + // check that the property is defined + QString aSection(aProp->section().c_str()); + QString aName(aProp->name().c_str()); + if (!aResMgr->hasValue(aSection, aName)) { + aResMgr->setValue(aSection, aName, QString(aProp->value().c_str())); + isResModified = true; + } + // Add item + if (aProp->type() != Config_Prop::Disabled) + myPreferences->addItem( tr(aProp->title().c_str()), aTab, + (SUIT_PreferenceMgr::PrefItemType)aProp->type(), + QString(aProp->section().c_str()), + QString(aProp->name().c_str()) ); } } } @@ -199,9 +216,13 @@ void XGUI_PreferencesDlg::accept() { myPreferences->store(); myIsChanged = true; + + // Save custom properties + XGUI_Preferences::updateCustomProps(); QDialog::accept(); } + void XGUI_PreferencesDlg::modified(XGUI_Prefs& theModified) const { theModified = myPreferences->modified(); diff --git a/src/XGUI/XGUI_Preferences.h b/src/XGUI/XGUI_Preferences.h index bd30a31a5..a694c34ba 100644 --- a/src/XGUI/XGUI_Preferences.h +++ b/src/XGUI/XGUI_Preferences.h @@ -31,6 +31,10 @@ public: static SUIT_ResourceMgr* resourceMgr(); + static void updateCustomProps(); + + static void loadCustomProps(); + private: static SUIT_ResourceMgr* myResourceMgr; }; @@ -76,7 +80,9 @@ private: void createEditors(); void createViewerPage(int thePageId); void createMenuPage(int thePageId); - void createCustomPage(int thePageId, Config_Properties& theProps); + void createCustomPage(int thePageId); + + void updateCustomProps(); XGUI_PreferencesMgr* myPreferences; bool myIsChanged; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 3d5441be7..021ab16b1 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -145,6 +145,7 @@ void XGUI_Workshop::startApplication() myMainWindow->show(); updateCommandStatus(); } + XGUI_Preferences::loadCustomProps(); onNew(); } diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 8a616c638..07c5f4c92 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -62,5 +62,6 @@ pictures/eye_pencil_closed.png pictures/view_prefs.png + pictures/module.png diff --git a/src/XGUI/pictures/module.png b/src/XGUI/pictures/module.png new file mode 100644 index 000000000..e44a04188 Binary files /dev/null and b/src/XGUI/pictures/module.png differ