Salome HOME
Issue #1660: Ability to change the deflection coefficient
authornds <nds@opencascade.com>
Wed, 27 Jul 2016 05:21:49 +0000 (08:21 +0300)
committernds <nds@opencascade.com>
Wed, 27 Jul 2016 05:21:49 +0000 (08:21 +0300)
21 files changed:
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/Model/Model_ResultCompSolid.cpp
src/Model/Model_ResultCompSolid.h
src/Model/Model_ResultConstruction.cpp
src/Model/Model_ResultConstruction.h
src/Model/Model_ResultGroup.cpp
src/Model/Model_ResultGroup.h
src/Model/Model_ResultPart.cpp
src/ModelAPI/ModelAPI_Result.cpp
src/ModelAPI/ModelAPI_Result.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_CustomPrs.cpp
src/XGUI/XGUI_CustomPrs.h
src/XGUI/XGUI_DeflectionDialog.cpp [new file with mode: 0755]
src/XGUI/XGUI_DeflectionDialog.h [new file with mode: 0755]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 3f7646688b80eab7f6c9736522d5c8b05eec0de3..74c1e1344d81dc480eccc437576e87e86785fb4d 100644 (file)
@@ -374,6 +374,34 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
   theB = (int)(aColor.Blue()*255.);
 }
 
+bool GeomAPI_AISObject::setDeflection(const double theDeflection)
+{
+  bool isModified = false;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+    if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) {
+      aDrawer->SetDeviationCoefficient(theDeflection);
+      isModified = true;
+    }
+  }
+
+  return isModified;
+}
+
+double GeomAPI_AISObject::getDeflection() const
+{
+  double aDeflection = -1;
+
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+    aDeflection = aDrawer->DeviationCoefficient();
+  }
+  return aDeflection;
+}
+
+
 bool GeomAPI_AISObject::empty() const
 {
   Handle(AIS_InteractiveObject) anAIS = const_cast<GeomAPI_AISObject*>(this)
index 18fd8fa94ff576a38c69d0048d96d3996c088419..1030aa06b278050920d546d74d4ccbc27fd51ed9 100644 (file)
@@ -122,6 +122,18 @@ class GeomAPI_AISObject : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   void getColor(int& theR, int& theG, int& theB);
 
+  /** \brief Assigns the deflection to the shape
+   *  \param[in] theDeflection value of deflection
+   */
+  GEOMAPI_EXPORT 
+  bool setDeflection(const double theDeflection);
+
+  /** \brief Returns deflection for the shape
+   *  \return double value
+   */
+  GEOMAPI_EXPORT 
+  double getDeflection() const;
+
   /// \return Current width of the lines of shape
   GEOMAPI_EXPORT 
   double width();
index 714d984e8e49e631abd123e79fa6304c49354d61..80bce61ab64f34182544043f4b18c45e0ef3132e 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <Model_ResultBody.h>
 #include <Model_BodyBuilder.h>
-#include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_Tools.h>
 #include <Config_PropManager.h>
 #include <ModelAPI_Events.h>
@@ -22,13 +21,6 @@ Model_ResultBody::Model_ResultBody()
   myConnect = ConnectionNotComputed;
 }
 
-void Model_ResultBody::initAttributes()
-{
-  // append the color attribute. It is empty, the attribute will be filled by a request
-  DataPtr aData = data();
-  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
   std::string& theDefault)
 {
index be5ac8e1dba9c7eae478450aacd1654c94559e0f..e0ae333671812a38b5535a93aca20fb3113e9099 100644 (file)
@@ -34,9 +34,6 @@ class Model_ResultBody : public ModelAPI_ResultBody
   bool myWasConcealed;
 
 public:
-  /// Request for initialization of data model of the result: adding all attributes
-  virtual void initAttributes();
-
   /// Returns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
                                             std::string& theDefault);
index f7cbeba3ce63902964d5bc25827e3b9206cef889..00ca3915dcf558830a21b2eff65517d88e287793 100755 (executable)
@@ -10,8 +10,6 @@
 #include <Model_Objects.h>
 #include <Model_BodyBuilder.h>
 #include <Model_Document.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
 #include <Events_Loop.h>
@@ -32,12 +30,6 @@ Model_ResultCompSolid::~Model_ResultCompSolid()
   updateSubs(std::shared_ptr<GeomAPI_Shape>()); // erase sub-results
 }
 
-void Model_ResultCompSolid::initAttributes()
-{
-  DataPtr aData = data();
-  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
 void Model_ResultCompSolid::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
 {
   ModelAPI_ResultCompSolid::store(theShape);
index ba92674e8c80a03228a3349655dc711447eef05a..60ab44b0d2a48c6adbce3f2e54406e5da86d83e4 100755 (executable)
@@ -31,9 +31,6 @@ public:
   /// Removes the stored builders
   MODEL_EXPORT virtual ~Model_ResultCompSolid();
 
-  /// Request for initialization of data model of the object: adding all attributes
-  MODEL_EXPORT virtual void initAttributes();
-
   /// Stores the shape (called by the execution method). Creates sub-results for compsolid.
   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
index a882b99d6a9ad5dc41bd8b318e2432d301c4e1de..c1fea070837f1854f1be7aeb0b692dd846724ebb 100644 (file)
@@ -6,20 +6,12 @@
 
 #include <Model_ResultConstruction.h>
 
-#include <ModelAPI_AttributeIntArray.h>
 #include <Config_PropManager.h>
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
 
-void Model_ResultConstruction::initAttributes()
-{
-  // append the color attribute. It is empty, the attribute will be filled by a request
-  DataPtr aData = data();
-  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
                                        std::string& theDefault)
 {
index bddac21ee1f8ee2bd8feba7f7bcfca9f552d857a..837add0fb0c6e05aafb49aae55bf0e524b9c36aa 100644 (file)
@@ -27,9 +27,6 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction
   bool myIsInHistory;
   bool myIsInfinite;
  public:
-  /// Request for initialization of data model of the result: adding all attributes
-  virtual void initAttributes();
-
   /// Retuns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
                                             std::string& theDefault);
index c952c8b9d64d926ac055d1938c4c12cdab682b9e..8b4a39d559de324ad0e0933d33e867fe713eac23 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <Model_ResultGroup.h>
 #include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeIntArray.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
@@ -17,13 +16,6 @@ Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData
   myOwnerData = theOwnerData;
 }
 
-void Model_ResultGroup::initAttributes()
-{
-  // append the color attribute. It is empty, the attribute will be filled by a request
-  DataPtr aData = data();
-  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
-}
-
 void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
                                        std::string& theDefault)
 {
index 2252d455eeadd42782e7b331a35c3dc69a303ae7..e6e4a15b827bc76fec763098ae35f3413d9c2ee9 100644 (file)
@@ -20,8 +20,6 @@ class Model_ResultGroup : public ModelAPI_ResultGroup
 {
   std::shared_ptr<ModelAPI_Data> myOwnerData;  ///< data of owner of this result
 public:
-  /// Request for initialization of data model of the result: adding all attributes
-  virtual void initAttributes();
 
   /// Retuns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
index d4d10de3b6d9ae588f7b91d5e3c2c296656df566..c6d27798b38cb24241aaf6a25fbb022cc0a54d6c 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <Model_Document.h>
 #include <Model_Application.h>
 #include <Events_Loop.h>
@@ -36,6 +37,7 @@ void Model_ResultPart::initAttributes()
     data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId()));
   data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
   data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId());
+  data()->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
 
   if (aDocRef->isInitialized() && // initialized immideately means already exist and will be loaded
       !Model_Application::getApplication()->hasDocument(aDocRef->docId()))
index cefbd7af8310d7d2119ced6737c347304fc2e5e3..187a1fc8271f608506ca716df73cf4d23a4f05ab 100644 (file)
@@ -8,12 +8,23 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
+
 #include <Events_Loop.h>
 
 ModelAPI_Result::~ModelAPI_Result()
 {
 }
 
+void ModelAPI_Result::initAttributes()
+{
+  // append the color attribute. It is empty, the attribute will be filled by a request
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
+  aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
 {
   if (myIsDisabled != theFlag) {
index bf15dfeecbf14761ba31f9c28490c1ac070bd6d1..c0958c7c0a025250dd335a04d8f986e7c3d7d563 100644 (file)
@@ -34,6 +34,14 @@ class ModelAPI_Result : public ModelAPI_Object
     return MY_COLOR_ID;
   }
 
+  /// Reference to the deflection of the result.
+  /// The double value is used. The values is in [0, 1] range
+  inline static const std::string& DEFLECTION_ID()
+  {
+    static const std::string MY_DEFLECTION_ID("Deflection");
+    return MY_DEFLECTION_ID;
+  }
+
   /// Returns true if the result is concealed from the data tree (referenced by other objects)
   MODELAPI_EXPORT virtual bool isConcealed();
 
@@ -53,7 +61,7 @@ class ModelAPI_Result : public ModelAPI_Object
   MODELAPI_EXPORT virtual bool isDisabled();
 
   /// Request for initialization of data model of the result: adding all attributes
-  virtual void initAttributes() {};
+  MODELAPI_EXPORT virtual void initAttributes();
 
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Result();
index 2a8561f4a3d597f128b5fcf257224105e1dcd39d..222f5d2aa3e0293295624f7900b90f6a052cb8e4 100644 (file)
@@ -10,6 +10,7 @@ SET(PROJECT_HEADERS
        XGUI_ContextMenuMgr.h
        XGUI_CustomPrs.h
        XGUI_DataModel.h
+       XGUI_DeflectionDialog.h
        XGUI_Displayer.h
        XGUI_ErrorDialog.h
        XGUI_ErrorMgr.h
@@ -41,6 +42,7 @@ SET(PROJECT_SOURCES
        XGUI_ContextMenuMgr.cpp
        XGUI_CustomPrs.cpp
        XGUI_DataModel.cpp
+       XGUI_DeflectionDialog.cpp
        XGUI_Displayer.cpp
        XGUI_ErrorDialog.cpp
        XGUI_ErrorMgr.cpp
index d7a7d1579bba55d1f7f454576ef4dc040d1d209c..7cca98e116c5e5006644a60042b3a2ed38c778f9 100644 (file)
@@ -86,6 +86,9 @@ void XGUI_ContextMenuMgr::createActions()
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/color.png"), tr("Color..."), aDesktop);
   addAction("COLOR_CMD", aAction);
 
+  aAction = ModuleBase_Tools::createAction(QIcon(""), tr("Deflection..."), aDesktop);
+  addAction("DEFLECTION_CMD", aAction);
+
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), aDesktop);
   addAction("SHOW_CMD", aAction);
 
@@ -322,6 +325,9 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu()
   if (myWorkshop->canChangeColor())
     action("COLOR_CMD")->setEnabled(true);
 
+  if (myWorkshop->canChangeDeflection())
+    action("DEFLECTION_CMD")->setEnabled(true);
+
   ModuleBase_IModule* aModule = myWorkshop->module();
   if (aModule)
     aModule->updateObjectBrowserMenu(myActions);
@@ -408,6 +414,9 @@ void XGUI_ContextMenuMgr::updateViewerMenu()
   if (myWorkshop->canChangeColor())
     action("COLOR_CMD")->setEnabled(true);
 
+  if (myWorkshop->canChangeDeflection())
+    action("DEFLECTION_CMD")->setEnabled(true);
+
   action("DELETE_CMD")->setEnabled(true);
 }
 
@@ -438,6 +447,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(mySeparator);
   aList.append(action("RENAME_CMD"));
   aList.append(action("COLOR_CMD"));
+  aList.append(action("DEFLECTION_CMD"));
   aList.append(action("SHOW_FEATURE_CMD"));
   myObjBrowserMenus[ModelAPI_ResultConstruction::group()] = aList;
 
@@ -454,6 +464,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu()
   aList.append(mySeparator);
   aList.append(action("RENAME_CMD"));
   aList.append(action("COLOR_CMD"));
+  aList.append(action("DEFLECTION_CMD"));
   aList.append(action("SHOW_FEATURE_CMD"));
   myObjBrowserMenus[ModelAPI_ResultBody::group()] = aList;
   // Group menu
@@ -488,6 +499,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(action("SHOW_ONLY_CMD"));
   aList.append(mySeparator);
   aList.append(action("COLOR_CMD"));
+  aList.append(action("DEFLECTION_CMD"));
   myViewerMenu[ModelAPI_ResultConstruction::group()] = aList;
   // Result part menu
   myViewerMenu[ModelAPI_ResultPart::group()] = aList;
@@ -501,6 +513,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu()
   aList.append(action("SHOW_ONLY_CMD"));
   aList.append(mySeparator);
   aList.append(action("COLOR_CMD"));
+  aList.append(action("DEFLECTION_CMD"));
   myViewerMenu[ModelAPI_ResultBody::group()] = aList;
   // Group menu
   myViewerMenu[ModelAPI_ResultGroup::group()] = aList;
@@ -535,6 +548,8 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const
       aActions.append(mySeparator);
       //aActions.append(action("MOVE_CMD"));
       aActions.append(action("COLOR_CMD"));
+      aActions.append(action("DEFLECTION_CMD"));
+
       aActions.append(action("CLEAN_HISTORY_CMD"));
       aActions.append(action("DELETE_CMD"));
   }
@@ -581,6 +596,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
   // hide all is shown always even if selection in the viewer is empty
   aActions.append(action("HIDEALL_CMD"));
   aActions.append(action("COLOR_CMD"));
+  aActions.append(action("DEFLECTION_CMD"));
 
   theMenu->addActions(aActions);
 
index 5878f463599e57b687319f861460fbeb8e39d851..373eb2fe6e4569b712544d41efa8ddd7cdff16bc 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModuleBase_IModule.h>
 
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Session.h>
 #include <Config_PropManager.h>
 
 #include <vector>
 #include <QColor>
 
+double getDeflection(const ResultPtr& theResult)
+{
+  double aDeflection = -1;
+  // get color from the attribute of the result
+  if (theResult.get() != NULL &&
+      theResult->data()->attribute(ModelAPI_Result::DEFLECTION_ID()).get() != NULL) {
+    AttributeDoublePtr aDoubleAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
+    if (aDoubleAttr.get() && aDoubleAttr->isInitialized())
+      aDeflection = aDoubleAttr->value();
+  }
+  return aDeflection;
+}
 
-void getColor(ResultPtr theResult, std::vector<int>& theColor)
+void getColor(const ResultPtr& theResult, std::vector<int>& theColor)
 {
   theColor.clear();
   // get color from the attribute of the result
@@ -55,18 +68,31 @@ void XGUI_CustomPrs::getDefaultColor(ObjectPtr theObject, const bool isEmptyColo
   }
 }
 
+double XGUI_CustomPrs::getDefaultDeflection(const ObjectPtr& theObject)
+{
+  return Config_PropManager::real("Visualization", "result_deflection", "0.001");
+}
+
 XGUI_CustomPrs::XGUI_CustomPrs(XGUI_Workshop* theWorkshop)
 : myWorkshop(theWorkshop)
 {
 }
 
-void XGUI_CustomPrs::getResultColor(ResultPtr theResult, std::vector<int>& theColor)
+void XGUI_CustomPrs::getResultColor(const ResultPtr& theResult, std::vector<int>& theColor)
 {
   getColor(theResult, theColor);
   if (theColor.empty())
     getDefaultColor(theResult, false, theColor);
 }
 
+double XGUI_CustomPrs::getResultDeflection(const ResultPtr& theResult)
+{
+  double aDeflection = getDeflection(theResult);
+  if (aDeflection < 0)
+    aDeflection = getDefaultDeflection(theResult);
+  return aDeflection;
+}
+
 bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                            std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
 {
@@ -84,6 +110,8 @@ bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr the
       aColor[2] = aNewColor.blue();
     }
     aCustomized = !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+    aCustomized = thePrs->setDeflection(getResultDeflection(theResult)) | aCustomized;
   }
   ModuleBase_IModule* aModule = myWorkshop->module();
   aCustomized = aModule->customisePresentation(theResult, thePrs, theCustomPrs) || aCustomized;
index c7fe0bc0b1819dd3f40cf5f6aa4f277a8a62cd14..4859339ca474c535b433d84bd09a1858d44928d7 100644 (file)
@@ -34,7 +34,12 @@ public:
   /// Returns color of a result object
   /// \param theResult a result object
   /// \param theColor a color in form of RGB vector
-  static void getResultColor(ResultPtr theResult, std::vector<int>& theColor);
+  static void getResultColor(const ResultPtr& theResult, std::vector<int>& theColor);
+
+  /// Returns deflection of a result object
+  /// \param theResult a result object
+  /// \return theDeflection a real value
+  static double getResultDeflection(const ResultPtr& theResult);
 
   /// Returns the default object color. It obtains colorConfigInfo of the object
   /// and find it in preferences. If there are no this color in preference and an empty
@@ -45,6 +50,10 @@ public:
   static void XGUI_EXPORT getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
                                           std::vector<int>& theColor);
 
+  /// Returns the default deflection value. The value is obtained from the application preferences
+  /// \param theObject an investigated object
+  /// \return deflection value
+  static double XGUI_EXPORT getDefaultDeflection(const ObjectPtr& theObject);
 
 protected:
   XGUI_Workshop* myWorkshop; ///< the current workshop
diff --git a/src/XGUI/XGUI_DeflectionDialog.cpp b/src/XGUI/XGUI_DeflectionDialog.cpp
new file mode 100755 (executable)
index 0000000..11f93ff
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_DeflectionDialog.cpp
+// Created:     27 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#include <XGUI_DeflectionDialog.h>
+
+#include <ModelAPI_Tools.h>
+
+#include <QDoubleSpinBox>
+
+#include <QLabel>
+#include <QButtonGroup>
+#include <QGridLayout>
+#include <QRadioButton>
+#include <QDialogButtonBox>
+
+XGUI_DeflectionDialog::XGUI_DeflectionDialog(QWidget* theParent)
+  : QDialog(theParent)
+{
+  setWindowTitle("Deflection");
+  QGridLayout* aLay = new QGridLayout(this);
+
+  myDeflection = new QDoubleSpinBox(this);
+  myDeflection->setRange(0, 1);
+  aLay->addWidget(new QLabel("Deviation", this), 0, 0);
+  aLay->addWidget(myDeflection, 0, 1);
+
+  QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+                                                    Qt::Horizontal, this);
+  connect(aButtons, SIGNAL(accepted()), this, SLOT(accept()));
+  connect(aButtons, SIGNAL(rejected()), this, SLOT(reject()));
+  aLay->addWidget(aButtons, 1, 0, 1, 2);
+}
+
+void XGUI_DeflectionDialog::setDeflection(const double& theValue)
+{
+  myDeflection->setValue(theValue);
+}
+
+double XGUI_DeflectionDialog::getDeflection() const
+{
+  return myDeflection->value();
+}
diff --git a/src/XGUI/XGUI_DeflectionDialog.h b/src/XGUI/XGUI_DeflectionDialog.h
new file mode 100755 (executable)
index 0000000..0ec10ab
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        XGUI_DeflectionDialog.hxx
+// Created:     27 Jul 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_DeflectionDialog_H
+#define XGUI_DeflectionDialog_H
+
+#include "XGUI.h"
+
+#include <QDialog>
+
+class QButtonGroup;
+class QDoubleSpinBox;
+
+/**
+* \ingroup GUI
+* A class of dialog to chose a deflection value. The deflection value is in range [0, 1]
+*/ 
+class XGUI_DeflectionDialog : public QDialog
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent a parent widget for the dialog
+  XGUI_EXPORT XGUI_DeflectionDialog(QWidget* theParent);
+
+  XGUI_EXPORT virtual ~XGUI_DeflectionDialog() {};
+
+  /// Initializes the dialog with the given value.
+  /// \param theValue the deflection value
+  void setDeflection(const double& theDeflection);
+
+  /// Returns the current deflection value.
+  /// \return a double value
+  double getDeflection() const;
+
+private:
+  QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice
+  QDoubleSpinBox* myDeflection; /// a deflection value
+};
+
+#endif
index 72574632fa5ce0246af994ff04b8de1eea16c478..0aa4a019e8eabbaac6bdfaf9fd44e80dc7e327ff 100755 (executable)
@@ -6,6 +6,7 @@
 #include "XGUI_ActionsMgr.h"
 #include "XGUI_MenuMgr.h"
 #include "XGUI_ColorDialog.h"
+#include "XGUI_DeflectionDialog.h"
 #include "XGUI_ContextMenuMgr.h"
 #include "XGUI_Displayer.h"
 #include "XGUI_ErrorDialog.h"
@@ -36,6 +37,7 @@
 
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
@@ -205,7 +207,10 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
                                    Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
   Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
                                    Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
-  
+
+  Config_PropManager::registerProp("Visualization", "result_deflection", "Result deflection",
+                                   Config_Prop::Double, "0.001");
+
   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true))
     myViewerSelMode.append(TopAbs_FACE);
   if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true))
@@ -1774,6 +1779,92 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
   updateCommandStatus();
 }
 
+//**************************************************************
+bool XGUI_Workshop::canChangeDeflection() const
+{
+  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+
+  std::set<std::string> aTypes;
+  aTypes.insert(ModelAPI_ResultGroup::group());
+  aTypes.insert(ModelAPI_ResultConstruction::group());
+  aTypes.insert(ModelAPI_ResultBody::group());
+  aTypes.insert(ModelAPI_ResultPart::group());
+
+  return hasResults(aObjects, aTypes);
+}
+
+void setDeflection(ResultPtr theResult, const double theDeflection)
+{
+  if (!theResult.get())
+    return;
+
+  AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
+  if (aDeflectionAttr.get() != NULL)
+    aDeflectionAttr->setValue(theDeflection);
+}
+
+
+//**************************************************************
+void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
+{
+  AttributeDoublePtr aDoubleAttr;
+  // 1. find the current color of the object. This is a color of AIS presentation
+  // The objects are iterated until a first valid color is found 
+  double aDeflection = -1;
+  foreach(ObjectPtr anObject, theObjects) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+    if (aResult.get()) {
+      aDeflection = XGUI_CustomPrs::getResultDeflection(aResult);
+    }
+    else {
+      // TODO: remove the obtaining a color from the AIS object
+      // this does not happen never because:
+      // 1. The color can be changed only on results
+      // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
+      AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+      if (anAISObj.get()) {
+        aDeflection = anAISObj->getDeflection();
+      }
+    }
+    if (aDeflection > 0)
+      break;
+  }
+  if (aDeflection < 0)
+    return;
+
+  if (!abortAllOperations())
+  return; 
+  // 2. show the dialog to change the value
+  XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop());
+  aDlg->setDeflection(aDeflection);
+  aDlg->move(QCursor::pos());
+  bool isDone = aDlg->exec() == QDialog::Accepted;
+  if (!isDone)
+    return;
+
+  // 3. abort the previous operation and start a new one
+  SessionPtr aMgr = ModelAPI_Session::get();
+  QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text();
+  aMgr->startOperation(aDescription.toStdString());
+
+  // 4. set the value to all results
+  aDeflection = aDlg->getDeflection();
+  foreach(ObjectPtr anObj, theObjects) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL) {
+      ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+      if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
+        for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) {
+          setDeflection(aCompsolidResult->subResult(i), aDeflection);
+        }
+      }
+      setDeflection(aResult, aDeflection);
+    }
+  }
+  aMgr->finishOperation();
+  updateCommandStatus();
+}
+
 //**************************************************************
 #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \
 for (int i = 0; i < aDoc->size(aGroupName); i++) { \
index 81f6d7a91b35cd8064ab06d1bed82386718e6bf1..ba9814db7000b729f4b76caed1fce7b94df4d97d 100755 (executable)
@@ -196,11 +196,20 @@ Q_OBJECT
   //! \return boolean value
   bool canChangeColor() const;
 
-  //! Change color of the features if it is possible
+  //! Change color of the results if it is possible
   //! The operation is available for construction, body and group results
   //! theObjects a list of selected objects
   void changeColor(const QObjectPtrList& theObjects);
 
+  //! Returns true if there is at least one selected body/construction/group result
+  //! \return boolean value
+  bool canChangeDeflection() const;
+
+  //! Change deflection of the results if it is possible
+  //! The operation is available for construction, body and group results
+  //! theObjects a list of selected objects
+  void changeDeflection(const QObjectPtrList& theObjects);
+
   //! Show the given features in 3d Viewer
   void showObjects(const QObjectPtrList& theList, bool isVisible);