Salome HOME
#1277 SKETCH : Bad restitution coordinates in the point creation panel
authornds <nds@opencascade.com>
Sat, 20 Feb 2016 09:21:00 +0000 (12:21 +0300)
committernds <nds@opencascade.com>
Sat, 20 Feb 2016 09:21:23 +0000 (12:21 +0300)
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_OperationPrs.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/PartSet/PartSet_WidgetPoint2dDistance.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h

index 90d41cdff80f67b6bfefc004b5dc7a05d1750a29..1640f4137f7cc76a4c1f7902dc460feb7036456a 100755 (executable)
@@ -129,39 +129,6 @@ void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a
   // the presentation is not used in the selection
 }
 
-bool PartSet_OperationPrs::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
-{
-  bool aVisible = false;
-  GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
-  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-  if (aPrs.get() || aResult.get()) {
-    aVisible = theDisplayer->isVisible(theObject);
-    // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
-    // visible. It is useful for highlight presentation where compsolid shape is selectable
-    if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
-      ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
-      if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
-        bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
-        for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
-          anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
-        }
-        aVisible = anAllSubsVisible;
-      }
-    }
-  }
-  else {
-    // check if all results of the feature are visible
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-    std::list<ResultPtr> aResults = aFeature->results();
-    std::list<ResultPtr>::const_iterator aIt;
-    aVisible = !aResults.empty();
-    for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-      aVisible = aVisible && theDisplayer->isVisible(*aIt);
-    }
-  }
-  return aVisible;
-}
-
 bool isSubObject(const ObjectPtr& theObject, const FeaturePtr& theFeature)
 {
   bool isSub = false;
@@ -224,7 +191,7 @@ void PartSet_OperationPrs::appendShapeIfVisible(ModuleBase_IWorkshop* theWorksho
                               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
 {
   XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(theWorkshop)->displayer();
-  if (isVisible(aDisplayer, theObject)) {
+  if (XGUI_Displayer::isVisible(aDisplayer, theObject)) {
     if (theGeomShape.get()) {
       if (theObjectShapes.contains(theObject))
         theObjectShapes[theObject].append(theGeomShape);
index adafbdfb81573cd8a2fcfecf6ab51cd20cba914e..6ea0ac622a5a5ceb3cd0fba895b3d269ca4b79c7 100755 (executable)
@@ -74,13 +74,6 @@ protected:
   QMap<ObjectPtr, QList<GeomShapePtr> >& featureShapes() { return myFeatureShapes; }
 
 private:
-  /// Return true if the object is visible. If the object is feature, it returns true
-  /// if all results of the feature are shown
-  /// \param theDisplayer a displayer
-  /// \param theObject an object
-  /// \return a boolean value
-  static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
-
   /// Fills the map by the feature object and shapes, which should be visuaziled
   /// Gets feature attributes, collect objects to whom the attributes refer
   /// \param theFeature a current feature
index eaa3ec7d15be5ec6b18b32ab689bf44a40eb3ef9..072143b246a068559e3934899894b8e41a769ef1 100644 (file)
@@ -8,6 +8,10 @@
 #include <PartSet_Tools.h>
 #include <PartSet_Module.h>
 
+#include <XGUI_Tools.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
 #include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IViewer.h>
@@ -57,7 +61,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
                                              const Config_WidgetAPI* theData,
                                              const std::string& theParentId)
 : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop),
-  myValueIsCashed(false), myXValueInCash(0), myYValueInCash(0)
+  myValueIsCashed(false), myIsFeatureVisibleInCash(true),
+  myXValueInCash(0), myYValueInCash(0)
 {
   if (MyFeaturesForCoincedence.isEmpty()) {
     MyFeaturesForCoincedence << SketchPlugin_Line::ID().c_str()
@@ -121,12 +126,9 @@ bool PartSet_WidgetPoint2D::resetCustom()
   }
   else {
     if (myValueIsCashed) {
-      // fill the control widgets by the cashed value
-      restoreCurentValue();
-      // store value to the model
-      storeValueCustom();
-      setValueState(Stored);
-      aDone = false;
+      // if the restored value should be hidden, aDone = true to set
+      // reset state for the widget in the parent
+      aDone = restoreCurentValue();
     }
     else {
       bool isOk;
@@ -275,15 +277,34 @@ void PartSet_WidgetPoint2D::storeCurentValue()
     return;
 
   myValueIsCashed = true;
+  myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
+                       XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
   myXValueInCash = myXSpin->value();
   myYValueInCash = myYSpin->value();
 }
 
-void PartSet_WidgetPoint2D::restoreCurentValue()
+bool PartSet_WidgetPoint2D::restoreCurentValue()
 {
+  bool aRestoredAndHidden = true;
+
+  bool isVisible = myIsFeatureVisibleInCash;
+  // fill the control widgets by the cashed value
+
   myValueIsCashed = false;
+  myIsFeatureVisibleInCash = true;
   ModuleBase_Tools::setSpinValue(myXSpin, myXValueInCash);
   ModuleBase_Tools::setSpinValue(myYSpin, myYValueInCash);
+
+  // store value to the model
+  storeValueCustom();
+  if (isVisible) {
+    setValueState(Stored);
+    aRestoredAndHidden = false;
+  }
+  else
+    aRestoredAndHidden = true;
+
+  return aRestoredAndHidden;
 }
 
 QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
index a66e11a923e584f203b3e1915cdb9bc2d2ae7d54..d4271e5589c6c4d8319a8b29427d37f9b4af21a5 100755 (executable)
@@ -124,7 +124,8 @@ protected:
   void storeCurentValue();
 
   /// Restore cashed value in the model attribute
-  void restoreCurentValue();
+  /// \return boolean state if the restored feature shoud be hidden
+  bool restoreCurentValue();
 
   /// Fills the widget with default values
   /// \return true if the widget current value is reset
@@ -191,6 +192,7 @@ private:
   CompositeFeaturePtr mySketch;
 
   bool myValueIsCashed; /// boolean state if the value is cashed during value state change
+  bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
   double myXValueInCash; /// the cashed X value during value state change
   double myYValueInCash; /// the cashed Y value during value state change
 };
index 562604dc05578878b5ef62c137adebad2296788b..9e92051b7964bace54cb3943faae3cf5215c1b58 100644 (file)
@@ -7,6 +7,10 @@
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_Tools.h"
 
+#include <XGUI_Tools.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
 #include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewWindow.h>
@@ -26,7 +30,8 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
                                                              ModuleBase_IWorkshop* theWorkshop,
                                                              const Config_WidgetAPI* theData,
                                                              const std::string& theParentId)
- : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop)
+: ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop),
+  myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0)
 {
   myFirstPntName = theData->getProperty("first_point");
 }
@@ -35,6 +40,24 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
 {
 }
 
+bool PartSet_WidgetPoint2dDistance::resetCustom()
+{
+  bool aDone = false;
+  if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) {
+    aDone = false;
+  }
+  else {
+    if (myValueIsCashed) {
+      // if the restored value should be hidden, aDone = true to set
+      // reset state for the widget in the parent
+      aDone = restoreCurentValue();
+    }
+    else
+      aDone = ModuleBase_WidgetDoubleValue::resetCustom();
+  }
+  return aDone;
+}
+
 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
 {
@@ -115,12 +138,50 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
+  if (myState != ModifiedInViewer)
+    storeCurentValue();
+
   bool isBlocked = blockValueState(true);
   setPoint(feature(), aPnt);
   blockValueState(isBlocked);
   setValueState(ModifiedInViewer);
 }
 
+void PartSet_WidgetPoint2dDistance::storeCurentValue()
+{
+  // do not use cash if a variable is used
+  if (mySpinBox->hasVariable())
+    return;
+
+  myValueIsCashed = true;
+  myIsFeatureVisibleInCash = XGUI_Displayer::isVisible(
+                       XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature);
+  myValueInCash = mySpinBox->value();
+}
+
+bool PartSet_WidgetPoint2dDistance::restoreCurentValue()
+{
+  bool aRestoredAndHidden = true;
+
+  bool isVisible = myIsFeatureVisibleInCash;
+  // fill the control widgets by the cashed value
+
+  myValueIsCashed = false;
+  myIsFeatureVisibleInCash = true;
+  ModuleBase_Tools::setSpinValue(mySpinBox, myValueInCash);
+
+  // store value to the model
+  storeValueCustom();
+  if (isVisible) {
+    setValueState(Stored);
+    aRestoredAndHidden = false;
+  }
+  else
+    aRestoredAndHidden = true;
+
+  return aRestoredAndHidden;
+}
+
 bool PartSet_WidgetPoint2dDistance::processEnter()
 {
   bool isModified = getValueState() == ModifiedInPP;
index 7b350d33edd8623e5e9a265bb1c89fe4d5c1010e..1cac83c89ea5bd2fd17db03dc1372fddbac8ca09 100644 (file)
@@ -74,6 +74,17 @@ public slots:
   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
 
 protected:
+  /// Store current value in cashed value
+  void storeCurentValue();
+
+  /// Restore cashed value in the model attribute
+  /// \return boolean state if the restored feature shoud be hidden
+  bool restoreCurentValue();
+
+  /// Fills the widget with default values
+  /// \return true if the widget current value is reset
+  virtual bool resetCustom();
+
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
@@ -96,6 +107,10 @@ protected:
 
   /// Reference to sketch
   CompositeFeaturePtr mySketch;
+
+  bool myValueIsCashed; /// boolean state if the value is cashed during value state change
+  bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
+  double myValueInCash; /// the cashed X value during value state change
 };
 
 #endif
index dd84ebdb7e32e5332f12b0fb449de55486409e77..768c0d419a87515950c933273d7c7d2f03cc5456 100644 (file)
@@ -410,6 +410,40 @@ int XGUI_Displayer::getSelectionMode(int theShapeType)
     AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theShapeType);
 }
 
+bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject)
+{
+  bool aVisible = false;
+  GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aPrs.get() || aResult.get()) {
+    aVisible = theDisplayer->isVisible(theObject);
+    // compsolid is not visualized in the viewer, but should have presentation when all sub solids are
+    // visible. It is useful for highlight presentation where compsolid shape is selectable
+    if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultCompSolid::group()) {
+      ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+      if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids
+        bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0;
+        for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) {
+          anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i));
+        }
+        aVisible = anAllSubsVisible;
+      }
+    }
+  }
+  else {
+    // check if all results of the feature are visible
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+    std::list<ResultPtr> aResults = aFeature->results();
+    std::list<ResultPtr>::const_iterator aIt;
+    aVisible = !aResults.empty();
+    for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+      aVisible = aVisible && theDisplayer->isVisible(*aIt);
+    }
+  }
+  return aVisible;
+}
+
+
 void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
                                      const bool theUpdateViewer)
 {
index 5a325fc8c4994ebd90f1305d6a963b736f216111..dd221d7bf9cbb9b9398e501f31fa1858270c48e6 100644 (file)
@@ -247,6 +247,13 @@ class XGUI_EXPORT XGUI_Displayer: public QObject
   /// \param theShapeType a shape type from TopAbs_ShapeEnum
   static int getSelectionMode(int theShapeType);
 
+  /// Return true if the object is visible. If the object is feature, it returns true
+  /// if all results of the feature are shown
+  /// \param theDisplayer a displayer
+  /// \param theObject an object
+  /// \return a boolean value
+  static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
+
 signals:
   /// Signal on object display
   /// \param theObject a data object