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 { Auto, 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; }
+ PropType type() const { return myType; }
+ std::string value() const { return myValue; }
+
+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::map<std::string, Config_Properties> Config_PropManager::myPropMap;
+
+
+
+bool Config_PropManager::registerProp(const std::string& theOwnerId,
+ 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);
+ }
+ return true;
+}
+
+std::list<std::string> Config_PropManager::getOwners()
+{
+ std::list<std::string> aKeys;
+ std::map<std::string, Config_Properties>::const_iterator aIt;
+ for (aIt = myPropMap.cbegin(); aIt != myPropMap.cend(); ++aIt)
+ aKeys.push_back((*aIt).first);
+ return aKeys;
+}
+
+Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId)
+{
+ return myPropMap[theOwnerId];
+}
+
+
+std::list<std::string> Config_PropManager::getSections(const std::string& theOwnerId)
+{
+ std::list<std::string> aSections;
+ Config_Properties aProps = getProperties(theOwnerId);
+ Config_Properties::const_iterator aIt;
+ for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) {
+ const Config_Prop* aProp = (*aIt);
+ aSections.push_back(aProp->section());
+ }
+ aSections.unique();
+ return aSections;
+}
+
+Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId,
+ const std::string& theSection)
+{
+ Config_Properties aProps = getProperties(theOwnerId);
+ Config_Properties aRes;
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); aIt++) {
+ Config_Prop* aProp = (*aIt);
+ if (aProp->section() == theSection)
+ aRes.push_back(aProp);
+ }
+ return aRes;
+}
+
+
+std::string Config_PropManager::value(const std::string& theOwnerId,
+ const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault)
+{
+ Config_Properties aProps = getProperties(theOwnerId, 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> stringToRGB(const std::string& theColor)
+{
+ std::vector<int> 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;
+
+ return aRes;
+}
\ No newline at end of file
--- /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& theOwnerId,
+ 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<std::string> getOwners();
+
+ //! Returns list of properties by its owner.
+ static Config_Properties getProperties(const std::string& theOwnerId);
+
+ //! Returns list of registered section names.
+ static std::list<std::string> getSections(const std::string& theOwnerId);
+
+ //! Returns list of properties by its owner and section.
+ static Config_Properties getProperties(const std::string& theOwnerId, 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);
+
+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<std::string, Config_Properties> myPropMap;
+};
+
+
+CONFIG_EXPORT std::vector<int> stringToRGB(const std::string& theColor);
+
+#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::string aColor = Config_PropManager::value("Sketcher", "Visualization",
+ "distance_color", DISTANCE_COLOR);
+ std::vector<int> aRGB = stringToRGB(aColor);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
class SketchPlugin_Line;
class GeomDataAPI_Point2D;
+#define DISTANCE_COLOR "255, 0, 255"
+
/** \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::string aColor = Config_PropManager::value("Sketcher", "Visualization",
+ "length_color", LENGTH_COLOR);
+ std::vector<int> aRGB = stringToRGB(aColor);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include <list>
+#define LENGTH_COLOR "255, 0, 255"
+
/** \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::string aColor = Config_PropManager::value("Sketcher", "Visualization",
+ "parallel_color", PARALLEL_COLOR);
+ std::vector<int> aRGB = stringToRGB(aColor);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+
+#define PARALLEL_COLOR "255, 255, 0"
+
/** \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::string aColor = Config_PropManager::value("Sketcher", "Visualization",
+ "perpendicular_color", PERPENDICULAR_COLOR);
+ std::vector<int> aRGB = stringToRGB(aColor);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+#define PERPENDICULAR_COLOR "255, 255, 0"
+
/** \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::string aColor = Config_PropManager::value("Sketcher", "Visualization",
+ "radius_color", RADIUS_COLOR);
+ std::vector<int> aRGB = stringToRGB(aColor);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
#include <SketchPlugin_Sketch.h>
#include "SketchPlugin_Constraint.h"
+#define RADIUS_COLOR "255, 0, 255"
+
/** \class SketchPlugin_ConstraintRadius
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines
#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("Sketcher", "Visualization",
+ "parallel_color", "Parallel constraint color",
+ Config_Prop::Color, PARALLEL_COLOR);
+ Config_PropManager::registerProp("Sketcher", "Visualization",
+ "perpendicular_color", "Perpendicular constraint color",
+ Config_Prop::Color, PERPENDICULAR_COLOR);
+ Config_PropManager::registerProp("Sketcher", "Visualization",
+ "distance_color", "Distance color",
+ Config_Prop::Color, DISTANCE_COLOR);
+ Config_PropManager::registerProp("Sketcher", "Visualization",
+ "length_color", "Length color",
+ Config_Prop::Color, LENGTH_COLOR);
+ Config_PropManager::registerProp("Sketcher", "Visualization",
+ "radius_color", "Radius color",
+ Config_Prop::Color, RADIUS_COLOR);
}
FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
void XGUI_PreferencesDlg::createEditors()
{
int aLFpage = myPreferences->addItem("Desktop");
- myPreferences->setItemIcon(aLFpage, QIcon(":pictures/view_prefs.png"));
+ //myPreferences->setItemIcon(aLFpage, QIcon(":pictures/view_prefs.png"));
createMenuPage(aLFpage);
createViewerPage(aLFpage);
+
+ std::list<std::string> aOwners = Config_PropManager::getOwners();
+ std::list<std::string>::const_iterator aIt;
+ for (aIt = aOwners.cbegin(); aIt != aOwners.cend(); ++ aIt) {
+ int aPage = myPreferences->addItem((*aIt).c_str());
+ createCustomPage(aPage, Config_PropManager::getProperties((*aIt)));
+ }
}
void XGUI_PreferencesDlg::createViewerPage(int thePageId)
myPreferences->setItemProperty( "max", 10, aRowsNb );
}
+
+void XGUI_PreferencesDlg::createCustomPage(int thePageId, Config_Properties& theProps)
+{
+ SUIT_ResourceMgr* aResMgr = XGUI_Preferences::resourceMgr();
+ bool isResModified = false;
+
+ // Sort by sections
+ QMap<QString, Config_Properties> 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<QString, Config_Properties>::iterator it;
+ for (it = aGroupMap.begin(); it != aGroupMap.end(); ++it) {
+ int aTab = myPreferences->addItem(it.key(), thePageId );
+ myPreferences->setItemProperty( "columns", 2, aTab );
+ Config_Properties& aProps = it.value();
+ 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()) );
+ }
+ }
+}
+
+
void XGUI_PreferencesDlg::accept()
{
myPreferences->store();
#include "XGUI.h"
+#include <Config_PropManager.h>
#include <SUIT_PreferenceMgr.h>
#include <QDialog>
void createEditors();
void createViewerPage(int thePageId);
void createMenuPage(int thePageId);
+ void createCustomPage(int thePageId, Config_Properties& theProps);
XGUI_PreferencesMgr* myPreferences;
bool myIsChanged;