]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #948 Wrong display after Sketch edition
authornds <nds@opencascade.com>
Wed, 16 Sep 2015 11:03:34 +0000 (14:03 +0300)
committernds <nds@opencascade.com>
Wed, 16 Sep 2015 11:03:56 +0000 (14:03 +0300)
Save/restore hidden state of feature/results.

src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_OperationFeature.h
src/PartSet/PartSet_SketcherMgr.cpp
src/XGUI/XGUI_WorkshopListener.cpp
src/XGUI/XGUI_WorkshopListener.h

index 7c9c78248c62baea80df69542059700ff46cb584..46a17a9314454205efe28aeda5b8218c8dafd785 100755 (executable)
@@ -72,6 +72,51 @@ bool ModuleBase_OperationFeature::isValid() const
   return aValid && isDone;
 }
 
+void ModuleBase_OperationFeature::startOperation()
+{
+  FeaturePtr aFeature = feature();
+  if (!aFeature.get() || !isEditOperation())
+    return;
+
+  // store hidden result features
+  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr>::const_iterator aIt;
+  for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+    ObjectPtr anObject = *aIt;
+    if (anObject.get() && !anObject->isDisplayed()) {
+      myVisualizedObjects.insert(*aIt);
+      anObject->setDisplayed(true);
+    }
+  }
+  if (!aFeature->isDisplayed()) {
+    myVisualizedObjects.insert(*aIt);
+    aFeature->setDisplayed(true);
+  }
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
+void ModuleBase_OperationFeature::stopOperation()
+{
+  FeaturePtr aFeature = feature();
+  if (!aFeature.get() || !isEditOperation())
+    return;
+
+  // store hidden result features
+  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr>::const_iterator aIt;
+  for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+    ObjectPtr anObject = *aIt;
+    if (anObject.get() && myVisualizedObjects.find(anObject) != myVisualizedObjects.end()) {
+      anObject->setDisplayed(false);
+    }
+  }
+  if (myVisualizedObjects.find(aFeature) != myVisualizedObjects.end()) {
+    aFeature->setDisplayed(false);
+  }
+  if (myVisualizedObjects.size() > 0)
+    Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
 FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage)
 {
   if (myParentFeature.get()) {
@@ -119,6 +164,11 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
   return false;
 }
 
+bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject)
+{
+  return myVisualizedObjects.find(theObject) != myVisualizedObjects.end();
+}
+
 void ModuleBase_OperationFeature::start()
 {
   setIsModified(false);
index 0d2afdd9ba8e7dcdd5116f9aa5f559c3191ad970..f9d850fb8ac4e351ad63dd316b8f09e6b24aa90b 100755 (executable)
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <ModelAPI_Object.h>
 #include <ModelAPI_CompositeFeature.h>
 
 #include <QObject>
 #include <QString>
 #include <QStringList>
 
+#include <set>
+
 class ModuleBase_ModelWidget;
 class ModuleBase_ISelection;
 class ModuleBase_IViewer;
@@ -75,6 +78,11 @@ Q_OBJECT
   /// Returns True if the current operation works with the given object (feature or result)
   virtual bool hasObject(ObjectPtr theObj) const;
 
+  /// Returns true if the object is displayed when the operation was started
+  /// \param theObject a feature or result of the operation feature
+  /// \return boolean value whether the object display state was changed
+  virtual bool isDisplayedOnStart(ObjectPtr theObject);
+
   /// Initialisation of operation with preliminary selection
   /// \param theSelection an instance of Selection class
   /// \param theViewer a viewer to have the viewer the eye position
@@ -123,6 +131,12 @@ signals:
   bool commit();
 
  protected:
+  /// Displays the feature/results if it is hidden. It will be hided in stopOperation
+  virtual void startOperation();
+
+  /// Hide feature/results if they were hided on start
+  virtual void stopOperation();
+
   /// Creates an operation new feature
   /// \param theFlushMessage the flag whether the create message should be flushed
   /// \returns the created feature
@@ -135,6 +149,10 @@ signals:
    /// The operation feature to be handled
   FeaturePtr myFeature;
 
+  /// a list of hidden objects, whic are diplayed by operation start
+  /// and should be hidden by operation stop
+  std::set<ObjectPtr> myVisualizedObjects;
+
   /// Editing feature flag
   bool myIsEditing;
 
index 9bccd1ab05971ce0b530916fb2523b40045ea08a..6127d1c7639020ee3eeed157756afbb6bd002e0c 100644 (file)
@@ -852,7 +852,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     aConnector->activateModuleSelectionModes();
 }
 
-void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* /* theOperation*/)
+void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
 {
   myIsMouseOverWindow = false;
   myIsConstraintsShown = true;
@@ -893,13 +893,19 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* /* theOperation*/)
     std::list<ResultPtr>::const_iterator aIt;
     Events_Loop* aLoop = Events_Loop::loop();
     static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+    ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                                                           (theOperation);
     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-      (*aIt)->setDisplayed(true);
-      // this display event is needed because sketch already may have "displayed" state,
-      // but not displayed while it is still active (issue 613, abort of existing sketch)
-      ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
+      if (!aFOperation->isDisplayedOnStart(*aIt)) {
+        (*aIt)->setDisplayed(true);
+        // this display event is needed because sketch already may have "displayed" state,
+        // but not displayed while it is still active (issue 613, abort of existing sketch)
+        ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
+      }
     }
-    myCurrentSketch->setDisplayed(true);
+    if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
+      myCurrentSketch->setDisplayed(true);
     
     myCurrentSketch = CompositeFeaturePtr();
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
@@ -1022,7 +1028,7 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
         isObjectFound = true;
       else {
         std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
-        for (; anIt != aLast; anIt++) {
+        for (; anIt != aLast && !isObjectFound; anIt++) {
           isObjectFound = *anIt == theObject;
         }
       }
index 8db3733d20c00aa14a30175b32ea1c8500e71f39..ee65e8a099d9d366cfeb7ca632d9c981906f2086 100755 (executable)
 //#define DEBUG_FEATURE_UPDATED
 //#define DEBUG_RESULT_COMPSOLID
 
+#ifdef DEBUG_FEATURE_REDISPLAY
+const std::string DebugFeatureKind = "Extrusion";
+#endif
+
 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
   : myWorkshop(theWorkshop),
     myUpdatePrefs(false)
@@ -277,6 +281,8 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
 
   XGUI_Workshop* aWorkshop = workshop();
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  bool aFirstVisualizedBody = false;
+
   bool aRedisplayed = false;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
     ObjectPtr aObj = (*aIt);
@@ -299,6 +305,17 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
         qDebug("COMPSOLID sub-object");
     }
 #endif
+    #ifdef DEBUG_FEATURE_REDISPLAY
+      QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+      if (aFeature.get()) {
+        std::string aKind = aFeature->getKind();
+        if (aKind == DebugFeatureKind) {
+          qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj))
+                                            .arg(aHide).arg(anObjInfo).toStdString().c_str());
+        }
+      }
+    #endif
     if (aHide) {
       aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
       #ifdef DEBUG_FEATURE_REDISPLAY
@@ -315,12 +332,6 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
       #ifdef DEBUG_FEATURE_REDISPLAY
         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
-        /*FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
-        if (aFeature.get()) {
-          std::string aKind = aFeature->getKind();
-          if (aKind == "SketchMultiRotation")
-            bool aValue = true;
-        }*/
       #endif
 
       if (isVisibleObject)  { // redisplay visible object
@@ -337,7 +348,7 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
           aWorkshop->deactivateActiveObject(aObj, false);
         }
       } else { // display object if the current operation has it
-        if (displayObject(aObj)) {
+        if (displayObject(aObj, aFirstVisualizedBody)) {
           aRedisplayed = true;
           // Deactivate object of current operation from selection
           aWorkshop->deactivateActiveObject(aObj, false);
@@ -346,6 +357,8 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
     }
   }
   if (aRedisplayed) {
+    if (aFirstVisualizedBody)
+      myWorkshop->viewer()->fitAll();
     customizeCurrentObject();
     aDisplayer->updateViewer();
   }
@@ -364,6 +377,8 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
 #endif
 
+  bool aFirstVisualizedBody = false;
+
   //bool aHasPart = false;
   bool aDisplayed = false;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
@@ -391,7 +406,7 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
       // with list of displayed objects
       if (myWorkshop->module()->canDisplayObject(anObject)) {
         anObject->setDisplayed(true);
-        aDisplayed = displayObject(*aIt);
+        aDisplayed = displayObject(*aIt, aFirstVisualizedBody);
       } else 
         anObject->setDisplayed(false);
     }
@@ -400,6 +415,8 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
   //if (myObjectBrowser)
   //  myObjectBrowser->processEvent(theMsg);
   if (aDisplayed) {
+    if (aFirstVisualizedBody)
+      myWorkshop->viewer()->fitAll();
     customizeCurrentObject();
     workshop()->displayer()->updateViewer();
   }
@@ -528,7 +545,7 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessa
 
 
 //**************************************************************
-bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj)
+bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
 {
 #ifdef DEBUG_RESULT_COMPSOLID
   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
@@ -553,7 +570,7 @@ bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj)
     int aNb = aDisplayer->objectsCount();
     aDisplayed = aDisplayer->display(theObj, false);
     if (aNb == 0)
-      myWorkshop->viewer()->fitAll();
+      theFirstVisualizedBody = true;
   } else 
     aDisplayed = aDisplayer->display(theObj, false);
 
index 16a0de8712c1b522f2ad8417ee4265fc3d1d1d88..14c2edbfd75f76e719787cb97603365c56d416c9 100755 (executable)
@@ -69,8 +69,10 @@ protected:
   /// Displaus object and fit all viewer if the object is first (update viewer will not be called)
   /// Asks the module whether the object can be displayed
   /// \param theObj an object
+  /// \param theFirstVisualizedBody an output state whether there are not object displayed in the view
+  /// and the displayed object is a body
   /// \return true if the object is displayed
-  bool displayObject(ObjectPtr theObj);
+  bool displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody);
 
   /// Calls the module method of cusomize object for the feature of the current operation
   /// \return true if the object is modified