Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorSergey BELASH <belash.sergey@opencascade.com>
Mon, 18 Aug 2014 12:12:23 +0000 (16:12 +0400)
committerSergey BELASH <belash.sergey@opencascade.com>
Mon, 18 Aug 2014 12:12:23 +0000 (16:12 +0400)
Conflicts:
src/XGUI/XGUI_MainMenu.cpp

29 files changed:
src/Config/CMakeLists.txt
src/Config/Config_Prop.h [new file with mode: 0644]
src/Config/Config_PropManager.cpp [new file with mode: 0644]
src/Config/Config_PropManager.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.h
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_Preferences.cpp
src/XGUI/XGUI_Preferences.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/module.png [new file with mode: 0644]

index aa7ea19e4b193254b0f5a06615dfbb560a492052..1b52cfbb8ab2741236d9036c9ac6fd669beea995 100644 (file)
@@ -15,6 +15,8 @@ SET(PROJECT_HEADERS
   Config_PointerMessage.h
   Config_Common.h
   Config_ValidatorMessage.h
+  Config_Prop.h
+  Config_PropManager.h
  )
  
 SET(PROJECT_SOURCES
@@ -27,6 +29,7 @@ SET(PROJECT_SOURCES
   Config_PointerMessage.cpp
   Config_Common.cpp
   Config_ValidatorMessage.cpp
+  Config_PropManager.cpp
 )
 
 SET(XML_RESOURCES
diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h
new file mode 100644 (file)
index 0000000..246df80
--- /dev/null
@@ -0,0 +1,70 @@
+// 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
diff --git a/src/Config/Config_PropManager.cpp b/src/Config/Config_PropManager.cpp
new file mode 100644 (file)
index 0000000..4fa3d70
--- /dev/null
@@ -0,0 +1,182 @@
+// 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);
+}
diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h
new file mode 100644 (file)
index 0000000..d650b0e
--- /dev/null
@@ -0,0 +1,65 @@
+// 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
index b2bb96faf0dcb7b2cb81c7fd7ebf3505cdec6fa9..ec44e1c6392da25dff9e702b0205e21885cf74b3 100644 (file)
@@ -234,7 +234,12 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   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)
@@ -245,6 +250,19 @@ 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 = 
index a874e5d3e8440f89b26c93f2468eb6b9371e0f21..12b29708be3a9e77ac87e1bf45f220abbc5dc7b3 100644 (file)
@@ -84,6 +84,13 @@ public:
    */
   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);
 
index d45087849ec89f9a252aea30cab8d64549fd5808..2cbe3e324921a683e456a8a7347dff55ec3cfcad 100644 (file)
@@ -39,6 +39,7 @@ SET(PROJECT_SOURCES
 )
 
 SET(PROJECT_LIBRARIES
+    Config
     GeomAPI
     GeomAlgoAPI
     ModelAPI
@@ -53,6 +54,7 @@ ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESO
 TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
 
 INCLUDE_DIRECTORIES(
+  ../Config
   ../ModelAPI
   ../GeomAPI
   ../GeomAlgoAPI
index de504f56ea4b1ca99cc88607c51d4dba6df46f09..4d043e48b1a2a49106529c0d77c0b36e94f97968 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 
+#include <Config_PropManager.h>
 
 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
 {
@@ -115,6 +116,10 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintDistance::getAISObje
   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;
 }
 
index afb687d09c49f1caa24932f4b821b6e9a38f556d..790068b952fdcb9c28cff1f0130aed8fd79a227b 100644 (file)
@@ -15,6 +15,8 @@
 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
index 28d2cf7d35b2b63dac6e836e0520cbb945efef88..fcd4a4053d3355b6d845d8cbcdf39fa8a969695b 100644 (file)
@@ -16,6 +16,7 @@
 #include <GeomAPI_Lin2d.h>
 #include <GeomAPI_Pnt2d.h>
 
+#include <Config_PropManager.h>
 
 
 SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
@@ -93,6 +94,10 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintLength::getAISObject
   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;
 }
 
index cc96258e31c7b34c3ced796cd0a513967d24a166..461cb5ac89240275a6ccf1143b563bbb6f10e2f8 100644 (file)
@@ -10,6 +10,8 @@
 #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
index e2cd9c53dd2d52ab8b5ee548dd945362999502ac..e9bcfd0a351db66b157dace6e24103a268765cb4 100644 (file)
@@ -15,6 +15,8 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Pnt.h>
 
+#include <Config_PropManager.h>
+
 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
 {
 }
@@ -77,6 +79,10 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintParallel::getAISObje
   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;
 }
 
index 0da78ca640301a9f3e265db8fd62f35ca80ada97..6e02e1c997b4fd2cfa5dc6fac88481682ac79d76 100644 (file)
@@ -9,6 +9,9 @@
 #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
index 4f6a0b77136a4e5ef3794a065b23e310233689ef..df192e8d9796d527c292922922d3d4207a3bb25f 100644 (file)
@@ -15,6 +15,8 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Pnt.h>
 
+#include <Config_PropManager.h>
+
 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
 {
 }
@@ -73,6 +75,10 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAI
   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;
 }
 
index 33ad334e01bc5d3a5cb6c655557b38360e1045fa..ac565f0763bed0b662e03426fee4b3fb88befbd2 100644 (file)
@@ -9,6 +9,8 @@
 #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
index b771035423ffbe373fbf492317700b4f997323e0..31b253d542b8010d97f6f19e47fe16f2cc34fef0 100644 (file)
@@ -19,6 +19,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 
+#include <Config_PropManager.h>
+
 SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
 {
 }
@@ -119,6 +121,10 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintRadius::getAISObject
   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;
 }
 
index 829a15512f59ff273e78e255a52df18a6255d9e6..a6f1e16aeee53bcadb2959f7cef0448b4aa4d2b7 100644 (file)
@@ -9,6 +9,8 @@
 #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 
index 1a44e28605da683a8a4e7e8b19e426a9c645568c..8f98701349e636a84b92ba8d11783f1d01aa796f 100644 (file)
@@ -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()
index 2a05d45641cd3c9e5dca8516904eec7bd6e224cd..eb0b16c3f7bb697ef7796cc62c67efb8aab8fe37 100644 (file)
@@ -15,6 +15,8 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Validator.h>
 
+#include <Config_PropManager.h>
+
 using namespace std;
 
 // the only created instance of this plugin
@@ -28,6 +30,33 @@ SketchPlugin_Plugin::SketchPlugin_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)
index b3cacc6ae777b297067e9935282790f6116cff84..0b0381ab7eb647bedd648eca91db1374a47409ab 100644 (file)
 #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()
 {
@@ -138,8 +134,9 @@ void addPlane(double theX, double theY, double theZ, std::list<boost::shared_ptr
 {
   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);
 }
 
@@ -160,8 +157,15 @@ boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::
       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;
   }
index 3c71a6505c29a65eb616adc9a7791d6a97888eb3..c0845fa8507fa342620064830496d2a8b23ad7b4 100644 (file)
 #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.
index 2640da058de85bb23f55476aec8b0eaaf48f44f6..0e5878091c721ed6fa5511c9586526e2a1bc30c8 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <Events_Error.h>
 #include <Events_Loop.h>
+#include <GeomAPI_XY.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
@@ -148,6 +149,14 @@ bool SketchSolver_ConstraintGroup::isInteract(
       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;
     }
   }
 
@@ -155,6 +164,41 @@ bool SketchSolver_ConstraintGroup::isInteract(
   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
@@ -260,7 +304,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
                           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;
 }
 
index a648fc9b3eba400012d669a34c8f581f40558c80..1ec22362731145288a1e2734ecba21065eadda46 100644 (file)
@@ -174,6 +174,12 @@ private:
    */
   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
index 7dca8e3c18700f6a101581e3ad8fafbe5c104e3c..236747a7df2a885bd30d908bb5a1833bcfc32208 100644 (file)
@@ -206,8 +206,10 @@ void XGUI_OperationMgr::onOperationStopped()
       break;
     }
   }
-  if (aResultOp)
+  if (aResultOp) {
     resumeOperation(aResultOp);
+    validateCurrentOperation();
+  }
 }
 
 void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent)
index 14fea9f987860c86ec41aa079e8d05e4699b6b85..266580799fa83ab4adb725b94ed823d820d8d395 100644 (file)
@@ -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,11 +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);
+
+  aPage = myPreferences->addItem(tr("Module"));
+  myPreferences->setItemIcon(aPage, QIcon(":pictures/module.png"));
+  createCustomPage(aPage);
 }
 
 void XGUI_PreferencesDlg::createViewerPage(int thePageId)
@@ -144,13 +177,52 @@ void XGUI_PreferencesDlg::createMenuPage(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();
index 90150c67f7c74e4d502297d25132b61a10226b95..a694c34ba60446a24db62af1ba804ba9c8c924d7 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "XGUI.h"
 
+#include <Config_PropManager.h>
 #include <SUIT_PreferenceMgr.h>
 #include <QDialog>
 
@@ -30,6 +31,10 @@ public:
 
   static SUIT_ResourceMgr* resourceMgr();
 
+  static void updateCustomProps();
+
+  static void loadCustomProps();
+
 private:
   static SUIT_ResourceMgr* myResourceMgr;
 };
@@ -75,6 +80,9 @@ private:
   void createEditors();
   void createViewerPage(int thePageId);
   void createMenuPage(int thePageId);
+  void createCustomPage(int thePageId);
+
+  void updateCustomProps();
   
   XGUI_PreferencesMgr* myPreferences;
   bool myIsChanged;
index 3d5441be77fa9b022830fd5e788ec24ace9d5bfb..021ab16b1ac00e857d3d0e8f9e6898a88e2080bc 100644 (file)
@@ -145,6 +145,7 @@ void XGUI_Workshop::startApplication()
     myMainWindow->show();
     updateCommandStatus();
   }
+  XGUI_Preferences::loadCustomProps();
   onNew();
 }
 
index 8a616c63812fefec59f886119648174f323043b7..07c5f4c9222fa875710815a3b5b4b1ba7aedc259 100644 (file)
@@ -62,5 +62,6 @@
      <file>pictures/eye_pencil_closed.png</file>
    
      <file>pictures/view_prefs.png</file>
+     <file>pictures/module.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/module.png b/src/XGUI/pictures/module.png
new file mode 100644 (file)
index 0000000..e44a041
Binary files /dev/null and b/src/XGUI/pictures/module.png differ