Config_PointerMessage.h
Config_Common.h
Config_ValidatorMessage.h
+ Config_Prop.h
+ Config_PropManager.h
)
SET(PROJECT_SOURCES
Config_PointerMessage.cpp
Config_Common.cpp
Config_ValidatorMessage.cpp
+ Config_PropManager.cpp
)
SET(XML_RESOURCES
--- /dev/null
+// File: Config_Prop.h
+// Created: 12 Aug 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef Config_Prop_H
+#define Config_Prop_H
+
+#include "Config_def.h"
+
+#include <string>
+#include <list>
+
+/// Class which describes a one property
+class Config_Prop
+{
+public:
+
+ enum PropType { Disabled, Space, Bool, Color, String, Selector,
+ DblSpin, IntSpin, Double, Integer,
+ GroupBox, Tab, Frame, Font, DirList, File,
+ Slider, Shortcut, ShortcutTree, BiColor, Background };
+
+
+ /**
+ * Creates a one property
+ * \param theSection - name of section (domain of using) of the property.
+ * \param theName - name (title) of the value.
+ * \param theType - type of the value.
+ * \param theValue - initial value of the property.
+ */
+ Config_Prop(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theTitle,
+ PropType theType,
+ const std::string& theValue ) {
+ mySection = theSection;
+ myName = theName;
+ myTitle = theTitle;
+ myType = theType;
+ myValue = theValue;
+ }
+
+ 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;
+ std::string myName;
+ std::string myTitle;
+ PropType myType;
+ std::string myValue;
+};
+
+typedef std::list<Config_Prop*> Config_Properties;
+
+#endif
\ No newline at end of file
--- /dev/null
+// File: Config_PropManager.cpp
+// Created: 13 Aug 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "Config_PropManager.h"
+
+
+
+std::vector<int> stringToRGB(const std::string& theColor);
+int stringToInteger(const std::string& theInt);
+double stringToDouble(const std::string& theDouble);
+
+
+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 = 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;
+}
+
+Config_Prop* Config_PropManager::findProp(const std::string& theSection,
+ const std::string& theName)
+{
+ 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()
+{
+ 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<std::string> Config_PropManager::getSections()
+{
+ // Return only non disabled sections
+ std::list<std::string> aSections;
+ Config_Properties::const_iterator aIt;
+ for (aIt = myProps.cbegin(); aIt != myProps.cend(); aIt++) {
+ const Config_Prop* aProp = (*aIt);
+ if (aProp->type() != Config_Prop::Disabled)
+ aSections.push_back(aProp->section());
+ }
+ aSections.unique();
+ return aSections;
+}
+
+Config_Properties Config_PropManager::getProperties(const std::string& theSection)
+{
+ Config_Properties aRes;
+ Config_Properties::iterator aIt;
+ for (aIt = myProps.begin(); aIt != myProps.end(); aIt++) {
+ Config_Prop* aProp = (*aIt);
+ if ((aProp->section() == theSection) && (aProp->type() != Config_Prop::Disabled))
+ aRes.push_back(aProp);
+ }
+ return aRes;
+}
+
+
+std::string Config_PropManager::string(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault)
+{
+ Config_Properties aProps = getProperties(theSection);
+ Config_Properties::const_iterator aIt;
+ for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) {
+ Config_Prop* aProp = (*aIt);
+ if (aProp->name() == theName)
+ return aProp->value();
+ }
+ return theDefault;
+}
+
+
+std::vector<int> 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<int> stringToRGB(const std::string& theColor)
+{
+ std::vector<int> aRes(3);
+
+ 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;
+}
+
+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);
+}
--- /dev/null
+// File: Config_PropManager.h
+// Created: 13 Aug 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef Config_PropManager_H
+#define Config_PropManager_H
+
+#include "Config_def.h"
+#include "Config_Prop.h"
+
+#include <map>
+#include <string>
+#include <vector>
+
+//! Class wihich let to register properties
+class CONFIG_EXPORT Config_PropManager
+{
+public:
+
+ /**
+ * Registers property parameters
+ * \param theOwnerId - name of owner (name of plugin for example)
+ * \param theSection - name of section (domain of using) of the property.
+ * \param theName - name (title) of the value.
+ * \param theType - type of the value.
+ * \param theValue - initial value of the property
+ * Returns True if the property succesfully registered
+ */
+ static bool registerProp(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theTitle,
+ Config_Prop::PropType theType,
+ const std::string& theValue);
+
+ static Config_Prop* findProp(const std::string& theSection,
+ const std::string& theName);
+
+ static Config_Properties getProperties();
+
+ //! Returns list of registered section names.
+ static std::list<std::string> getSections();
+
+ //! Returns list of properties by its owner and section.
+ static Config_Properties getProperties(const std::string& theSection);
+
+ //! Returns value of the property by its owner, section, and name
+ static std::string string(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault);
+ static std::vector<int> 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:
+ static Config_Properties myProps;
+};
+
+
+#endif
\ No newline at end of file
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
if (anAIS.IsNull())
return ;
- anAIS->SetColor(Quantity_Color((Quantity_NameOfColor)theColor));
+ Quantity_Color aColor((Quantity_NameOfColor)theColor);
+ anAIS->SetColor(aColor);
+ Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
+ if (!aDimAIS.IsNull()) {
+ aDimAIS->DimensionAspect()->SetCommonColor(aColor);
+ }
}
void GeomAPI_AISObject::setWidth(const double& theWidth)
anAIS->SetWidth(theWidth);
}
+void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
+{
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (anAIS.IsNull())
+ return ;
+ Quantity_Color aColor(theR/255., theG/255., theB/255., Quantity_TOC_RGB);
+ anAIS->SetColor(aColor);
+ Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
+ if (!aDimAIS.IsNull()) {
+ aDimAIS->DimensionAspect()->SetCommonColor(aColor);
+ }
+}
+
bool GeomAPI_AISObject::empty() const
{
Handle(AIS_InteractiveObject) anAIS =
*/
void setColor(const int& theColor);
+ /** \brief Assigns the color for the shape
+ * \param[in] theR value of the red component
+ * \param[in] theG value of the green component
+ * \param[in] theB value of the blue component
+ */
+ void setColor(int theR, int theG, int theB);
+
/// \brief Assigns the width of the lines of shape
void setWidth(const double& theWidth);
)
SET(PROJECT_LIBRARIES
+ Config
GeomAPI
GeomAlgoAPI
ModelAPI
TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
+ ../Config
../ModelAPI
../GeomAPI
../GeomAlgoAPI
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
+#include <Config_PropManager.h>
SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
{
if (!anAIS)
anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "distance_color", DISTANCE_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
class SketchPlugin_Line;
class GeomDataAPI_Point2D;
+#define DISTANCE_COLOR "#ff00ff"
+
/** \class SketchPlugin_ConstraintDistance
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines a distance
#include <GeomAPI_Lin2d.h>
#include <GeomAPI_Pnt2d.h>
+#include <Config_PropManager.h>
SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
if (!anAIS)
anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include <list>
+#define LENGTH_COLOR "#ff00ff"
+
/** \class SketchPlugin_ConstraintLength
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines a length of a line segment
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
+#include <Config_PropManager.h>
+
SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
{
}
if (!anAIS)
anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane);
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "parallel_color", PARALLEL_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+
+#define PARALLEL_COLOR "#ffff00"
+
/** \class SketchPlugin_ConstraintParallel
* \ingroup DataModel
* \brief Feature for creation of a new constraint parallelism of two lines
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
+#include <Config_PropManager.h>
+
SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
{
}
if (!anAIS)
anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
anAIS->createPerpendicular(aLine1, aLine2, aPlane);
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color", PERPENDICULAR_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+#define PERPENDICULAR_COLOR "#ffff00"
+
/** \class SketchPlugin_ConstraintPerpendicular
* \ingroup DataModel
* \brief Feature for creation of a new constraint for perpendicularity of two lines
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
+#include <Config_PropManager.h>
+
SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
{
}
if (!anAIS)
anAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject);
anAIS->createRadius(aCircle, aFlyoutPnt, aValue);
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "radius_color", RADIUS_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+#define RADIUS_COLOR "#ff00ff"
+
/** \class SketchPlugin_ConstraintRadius
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines
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()
#include <ModelAPI_Document.h>
#include <ModelAPI_Validator.h>
+#include <Config_PropManager.h>
+
using namespace std;
// the only created instance of this plugin
// register this plugin
ModelAPI_PluginManager::get()->registerPlugin(this);
+
+ // register sketcher properties
+ 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("Visualization",
+ "perpendicular_color", "Perpendicular constraint color",
+ Config_Prop::Color, PERPENDICULAR_COLOR);
+ Config_PropManager::registerProp("Visualization",
+ "distance_color", "Distance color",
+ Config_Prop::Color, DISTANCE_COLOR);
+ Config_PropManager::registerProp("Visualization",
+ "length_color", "Length color",
+ Config_Prop::Color, LENGTH_COLOR);
+ Config_PropManager::registerProp("Visualization",
+ "radius_color", "Radius color",
+ Config_Prop::Color, RADIUS_COLOR);
}
FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
#include <GeomAlgoAPI_SketchBuilder.h>
#include <ModelAPI_ResultConstruction.h>
+#include <Config_PropManager.h>
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()
{
{
boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
+ double aSize = Config_PropManager::integer("Sketch definition", "Size of planes", PLANE_SIZE);
boost::shared_ptr<GeomAPI_Shape> aFace =
- GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
+ GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, aSize);
theShapes.push_back(aFace);
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
aAIS = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
aAIS->createShape(aCompound);
- aAIS->setColor(SKETCH_PLANE_COLOR);
- aAIS->setWidth(SKETCH_WIDTH);
+
+ std::vector<int> 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;
}
#include <GeomAPI_IPresentable.h>
#include <list>
+/// 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.
#include <Events_Error.h>
#include <Events_Loop.h>
+#include <GeomAPI_XY.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
FeaturePtr aFeature = aDoc->feature(aRC);
if (myEntityFeatMap.find(aFeature) != myEntityFeatMap.end())
return true;
+ // search attributes of a feature to be parameters of constraint
+ std::list< boost::shared_ptr<ModelAPI_Attribute> >
+ aFeatAttrList = aFeature->data()->attributes(std::string());
+ std::list< boost::shared_ptr<ModelAPI_Attribute> >::const_iterator
+ aFAIter = aFeatAttrList.begin();
+ for ( ; aFAIter != aFeatAttrList.end(); aFAIter++)
+ if (myEntityAttrMap.find(*aFAIter) != myEntityAttrMap.end())
+ return true;
}
}
return false;
}
+// ============================================================================
+// Function: checkConstraintConsistence
+// Class: SketchSolver_ConstraintGroup
+// Purpose: verifies and changes parameters of the constraint
+// ============================================================================
+void SketchSolver_ConstraintGroup::checkConstraintConsistence(Slvs_Constraint& theConstraint)
+{
+ if (theConstraint.type == SLVS_C_PT_LINE_DISTANCE)
+ {
+ // Get constraint parameters and check the sign of constraint value
+
+ // point coordinates
+ int aPtPos = Search(theConstraint.ptA, myEntities);
+ int aPtParamPos = Search(myEntities[aPtPos].param[0], myParams);
+ boost::shared_ptr<GeomAPI_XY> aPoint(
+ new GeomAPI_XY(myParams[aPtParamPos].val, myParams[aPtParamPos+1].val));
+
+ // line coordinates
+ int aLnPos = Search(theConstraint.entityA, myEntities);
+ aPtPos = Search(myEntities[aLnPos].point[0], myEntities);
+ aPtParamPos = Search(myEntities[aPtPos].param[0], myParams);
+ boost::shared_ptr<GeomAPI_XY> aStart(
+ new GeomAPI_XY(-myParams[aPtParamPos].val, -myParams[aPtParamPos+1].val));
+ aPtPos = Search(myEntities[aLnPos].point[1], myEntities);
+ aPtParamPos = Search(myEntities[aPtPos].param[0], myParams);
+ boost::shared_ptr<GeomAPI_XY> aEnd(
+ new GeomAPI_XY(myParams[aPtParamPos].val, myParams[aPtParamPos+1].val));
+
+ aEnd = aEnd->added(aStart);
+ aPoint = aPoint->added(aStart);
+ if (aPoint->cross(aEnd) * theConstraint.valA < 0.0)
+ theConstraint.valA *= -1.0;
+ }
+}
+
// ============================================================================
// Function: changeConstraint
// Class: SketchSolver_ConstraintGroup
aDistance, aConstrEnt[0], aConstrEnt[1], aConstrEnt[2], aConstrEnt[3]);
myConstraints.push_back(aConstraint);
myConstraintMap[theConstraint] = aConstraint.h;
+ int aConstrPos = Search(aConstraint.h, myConstraints);
+ aConstrIter = myConstraints.begin() + aConstrPos;
}
+
+ checkConstraintConsistence(*aConstrIter);
return true;
}
*/
bool addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2);
+ /** \brief Verifies and changes parameters of constriant,
+ * e.g. sign of the distance between line and point
+ * \param[in,out] theConstraint SolveSpace constraint to be verified
+ */
+ void checkConstraintConsistence(Slvs_Constraint& theConstraint);
+
private:
// SolveSpace entities
Slvs_hGroup myID; ///< the index of the group
break;
}
}
- if (aResultOp)
+ if (aResultOp) {
resumeOperation(aResultOp);
+ validateCurrentOperation();
+ }
}
void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent)
}
+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)));
+ }
+ }
+}
+
+
//**********************************************************
//**********************************************************
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);
+
+ aPage = myPreferences->addItem(tr("Module"));
+ myPreferences->setItemIcon(aPage, QIcon(":pictures/module.png"));
+ createCustomPage(aPage);
}
void XGUI_PreferencesDlg::createViewerPage(int thePageId)
myPreferences->setItemProperty( "max", 10, aRowsNb );
}
+
+void XGUI_PreferencesDlg::createCustomPage(int thePageId)
+{
+ SUIT_ResourceMgr* aResMgr = XGUI_Preferences::resourceMgr();
+ bool isResModified = false;
+
+ // Make a Tab from each section
+ std::list<std::string> aSections = Config_PropManager::getSections();
+ std::list<std::string>::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::const_iterator aIt;
+ for (aIt = aProps.cbegin(); aIt != aProps.cend(); ++aIt) {
+ 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()) );
+ }
+ }
+}
+
+
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();
#include "XGUI.h"
+#include <Config_PropManager.h>
#include <SUIT_PreferenceMgr.h>
#include <QDialog>
static SUIT_ResourceMgr* resourceMgr();
+ static void updateCustomProps();
+
+ static void loadCustomProps();
+
private:
static SUIT_ResourceMgr* myResourceMgr;
};
void createEditors();
void createViewerPage(int thePageId);
void createMenuPage(int thePageId);
+ void createCustomPage(int thePageId);
+
+ void updateCustomProps();
XGUI_PreferencesMgr* myPreferences;
bool myIsChanged;
myMainWindow->show();
updateCommandStatus();
}
+ XGUI_Preferences::loadCustomProps();
onNew();
}
<file>pictures/eye_pencil_closed.png</file>
<file>pictures/view_prefs.png</file>
+ <file>pictures/module.png</file>
</qresource>
</RCC>