From: nds Date: Wed, 16 Sep 2015 11:03:34 +0000 (+0300) Subject: Issue #948 Wrong display after Sketch edition X-Git-Tag: V_1.4.0~59 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=bff91ccd66e7d51923fe1582658dcedc08e4d86c;p=modules%2Fshaper.git Issue #948 Wrong display after Sketch edition Save/restore hidden state of feature/results. --- diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 7c9c78248..46a17a931 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -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 aResults = aFeature->results(); + std::list::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 aResults = aFeature->results(); + std::list::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); diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index 0d2afdd9b..f9d850fb8 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -14,12 +14,15 @@ #include #include +#include #include #include #include #include +#include + 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 myVisualizedObjects; + /// Editing feature flag bool myIsEditing; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 9bccd1ab0..6127d1c76 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -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::const_iterator aIt; Events_Loop* aLoop = Events_Loop::loop(); static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (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::const_iterator anIt = aResults.begin(), aLast = aResults.end(); - for (; anIt != aLast; anIt++) { + for (; anIt != aLast && !isObjectFound; anIt++) { isObjectFound = *anIt == theObject; } } diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index 8db3733d2..ee65e8a09 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -63,6 +63,10 @@ //#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_ptrdisplayer(); + 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_ptrgetKind(); + 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(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_ptrdeactivateActiveObject(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_ptrviewer()->fitAll(); customizeCurrentObject(); aDisplayer->updateViewer(); } @@ -364,6 +377,8 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptrmodule()->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_ptrprocessEvent(theMsg); if (aDisplayed) { + if (aFirstVisualizedBody) + myWorkshop->viewer()->fitAll(); customizeCurrentObject(); workshop()->displayer()->updateViewer(); } @@ -528,7 +545,7 @@ void XGUI_WorkshopListener::addFeature(const std::shared_ptr(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); diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index 16a0de871..14c2edbfd 100755 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -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