Salome HOME
Replace Display/Erase by setDisplayed
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 21 May 2015 14:25:46 +0000 (17:25 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 21 May 2015 14:25:46 +0000 (17:25 +0300)
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/Model/Model_Document.cpp
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_Events.h
src/PartSet/PartSet_SketcherMgr.cpp
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp

index b2ced2b57b3ef5372fa45dbaf9ddcb9a3b316240..f3ef02d96f74386779af970e047e0496363f9433 100644 (file)
@@ -55,17 +55,16 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
 
     // hides the created features, the precondition is that the feature's results have been
     // already built, so the createPlane/Points method calls the execute function for the planes
-    static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE);
     std::list<FeaturePtr >::const_iterator aFIter = aFeatures.begin();
     for (; aFIter != aFeatures.cend(); aFIter++) {
       FeaturePtr aPlane = *aFIter;
       const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aPlane->results();
       std::list<ResultPtr >::const_iterator aRIter = aResults.begin();
       for (; aRIter != aResults.cend(); aRIter++) {
-        ModelAPI_EventCreator::get()->sendUpdated(*aRIter, HIDE_DISP);
+        (*aRIter)->setDisplayed(false);
       }
     }
-    Events_Loop::loop()->flush(HIDE_DISP);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 
     // the viewer update should be unblocked in order to avoid the features blinking before they are
     // hidden
index e5c87013ede6a926641a0f41b1c82a0c4fa167aa..b1477e5c8f727c8d723ef6319533a0d2e7986a04 100644 (file)
@@ -324,7 +324,6 @@ bool Model_Document::finishOperation()
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-  aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
   // this must be here just after everything is finished but before real transaction stop
   // to avoid messages about modifications outside of the transaction
index 30abf9ddffa1ca3158e5c146e63656d5b3c324ad..7a8e5277bc898c2da6839497a2dc0d68bba3957f 100644 (file)
@@ -144,8 +144,7 @@ void Model_Update::processOperation(const bool theTotalUpdate)
         for(int a = aBase->size() - 1; a >= 0; a--) {
           ResultPtr aSketchRes = aBase->value(a)->context();
           if (aSketchRes) {
-            static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE);
-            ModelAPI_EventCreator::get()->sendUpdated(aSketchRes, HIDE_DISP);
+            aSketchRes->setDisplayed(false);
           }
         }
       }
index 69153a98847fc449c4962a6aeb0145a27ae4983d..89be2d89985c956e785d783abde00e6b0f93ed25 100644 (file)
@@ -36,10 +36,6 @@ static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
 static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
 /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage)
 static const char * EVENT_PLUGIN_LOADED = "PliginLoaded";
-/// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
-static const char * EVENT_OBJECT_TOSHOW = "ObjectShow";
-/// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
-static const char * EVENT_OBJECT_TOHIDE = "ObjectHide";
 //
 static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged";
 
index f3d5bfa320deb4f71dcd88151bbf8852f2f34089..9394b1a6bb190628bbdd67204583f90df7a3f207 100644 (file)
@@ -677,15 +677,14 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   // Display all sketcher sub-Objects
   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
   // Hide sketcher result
   std::list<ResultPtr> aResults = myCurrentSketch->results();
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-    aDisplayer->erase((*aIt), false);
+    (*aIt)->setDisplayed(false);
   }
-  aDisplayer->erase(myCurrentSketch, false);
+  myCurrentSketch->setDisplayed(false);
 
   // Display sketcher objects
   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
@@ -693,9 +692,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     std::list<ResultPtr> aResults = aFeature->results();
     std::list<ResultPtr>::const_iterator aIt;
     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-      aDisplayer->display((*aIt), false);
+      (*aIt)->setDisplayed(true);
     }
-    aDisplayer->display(aFeature, false);
+    aFeature->setDisplayed(true);
   }
 
   if (myPlaneFilter.IsNull()) 
@@ -707,7 +706,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
     myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
   }
-  aDisplayer->updateViewer();
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   // all sketch objects should be activated in the sketch selection modes by edit operation start
   if (theOperation->isEditOperation())
     activateObjectsInSketchMode(true);
@@ -722,10 +721,10 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
   activateObjectsInSketchMode(false);
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
-  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
   DataPtr aData = myCurrentSketch->data();
   if ((!aData) || (!aData->isValid())) {
+    XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     // The sketch was aborted
     myCurrentSketch = CompositeFeaturePtr();
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
@@ -736,7 +735,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
     foreach (ObjectPtr aObj, aObjects) {
       DataPtr aObjData = aObj->data();
       if ((!aObjData) || (!aObjData->isValid()))
-        aDisplayer->erase(aObj);
+        aObj->setDisplayed(false);
     }
     return; 
   }
@@ -746,21 +745,21 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
     std::list<ResultPtr> aResults = aFeature->results();
     std::list<ResultPtr>::const_iterator aIt;
     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-      aDisplayer->erase((*aIt), false);
+      (*aIt)->setDisplayed(false);
     }
-    aDisplayer->erase(aFeature, false);
+    aFeature->setDisplayed(false);
   }
   // Display sketcher result
   std::list<ResultPtr> aResults = myCurrentSketch->results();
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
-    aDisplayer->display((*aIt), false);
+    (*aIt)->setDisplayed(true);
   }
-  aDisplayer->display(myCurrentSketch);
+  myCurrentSketch->setDisplayed(true);
     
   myCurrentSketch = CompositeFeaturePtr();
   myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
-  aDisplayer->updateViewer();
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
@@ -810,8 +809,9 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
     // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch 
     // nested features can be visualized
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-    if (aFeature.get() != NULL && aFeature == activeSketch())
+    if (aFeature.get() != NULL && aFeature == activeSketch()) {
       aCanDisplay = false;
+    }
   }
   else { // there are no an active sketch
     // 2. sketch sub-features should not be visualized if the sketch operation is not active
@@ -819,8 +819,9 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
     if (aFeature.get() != NULL) {
       std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
                               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-      if (aSketchFeature.get())
+      if (aSketchFeature.get()) {
         aCanDisplay = false;
+      }
     }
   }
 
@@ -842,8 +843,10 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
       }
     }
   }
-  if (!isObjectFound)
+  if (!isObjectFound) {
+    theObject->setDisplayed(aCanDisplay); // If it be set into True - set to False
     return aCanDisplay;
+  }
 
   // 4. For created nested feature operation do not display the created feature if
   // the mouse curstor leaves the OCC window.
@@ -866,6 +869,7 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
     }
   }
   #endif
+  theObject->setDisplayed(aCanDisplay); // If it be set into True - set to False
   return aCanDisplay;
 }
 
@@ -1061,28 +1065,27 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
 
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
-  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
   // 1. change visibility of the object itself, here the presentable object is processed,
   // e.g. constraints features
   FeaturePtr aFeature = theOperation->feature();
   std::list<ResultPtr> aResults = aFeature->results();
   if (isToDisplay)
-    aDisplayer->display(aFeature, false);
+    aFeature->setDisplayed(true);
   else
-    aDisplayer->erase(aFeature, false);
+    aFeature->setDisplayed(false);
 
   // change visibility of the object results, e.g. non-constraint features
   std::list<ResultPtr>::const_iterator aIt;
   for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
     if (isToDisplay) {
-      aDisplayer->display(*aIt, false);
+      (*aIt)->setDisplayed(true);
     }
     else {
-      aDisplayer->erase(*aIt, false);
+      (*aIt)->setDisplayed(false);
     }
   }
-  aDisplayer->updateViewer();
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
 void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive)
@@ -1152,17 +1155,16 @@ void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn)
 
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
-  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
 
   const QStringList& aConstrIds = constraintsIdList();
   for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
     FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
     if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) {
       if (myIsConstraintsShown) 
-        aDisplayer->display(aSubFeature, false);
+        aSubFeature->setDisplayed(true);
       else
-        aDisplayer->erase(aSubFeature, false);
+        aSubFeature->setDisplayed(false);
     }
   }
-  aDisplayer->updateViewer();
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
index ff696de22d3e2f713743f9b80a71485d17e02eb8..88f167b96b0471363ac67017334f9b17a4bcb912 100644 (file)
@@ -152,7 +152,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
       ObjectPtr aObject = aObjects.first();
       if (aObject) {
         if (!hasFeature) {
-          if (aDisplayer->isVisible(aObject)) {
+          if (aObject->isDisplayed()) {
             if (aDisplayer->canBeShaded(aObject)) {
               if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading)
                 aMenu->addAction(action("WIREFRAME_CMD"));
@@ -228,7 +228,7 @@ void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
       foreach(ObjectPtr aObject, aObjects)
       {
         ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
-        if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
+        if (aRes && aRes->isDisplayed()) {
           isVisible = true;
           canBeShaded = myWorkshop->displayer()->canBeShaded(aObject);
           isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading);      
index f1b617d851568117d410c7d8164e82df3c01aa15..9da339e98200157b890975108122c2b3517d9dbe 100644 (file)
@@ -165,8 +165,6 @@ void XGUI_Workshop::startApplication()
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->registerListener(this, Events_LongOp::eventID());
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
 
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
@@ -348,24 +346,6 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
     } else {
       QApplication::restoreOverrideCursor();
     }
-  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
-    std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
-    const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
-    QObjectPtrList aList;
-    std::set<ObjectPtr>::const_iterator aIt;
-    for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
-      aList.append(*aIt);
-    showObjects(aList, true);
-  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
-    std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
-        std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
-    const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
-    QObjectPtrList aList;
-    std::set<ObjectPtr>::const_iterator aIt;
-    for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
-      aList.append(*aIt);
-    showObjects(aList, false);
   }
   //An operation passed by message. Start it, process and commit.
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
@@ -1253,8 +1233,12 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     setDisplayMode(aObjects, XGUI_Displayer::Shading);
   else if (theId == "WIREFRAME_CMD")
     setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
-  else if (theId == "HIDEALL_CMD")
-    myDisplayer->eraseAll();
+  else if (theId == "HIDEALL_CMD") {
+    QObjectPtrList aList = myDisplayer->displayedObjects();
+    foreach (ObjectPtr aObj, aList)
+      aObj->setDisplayed(false);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  }
 }
 
 //**************************************************************
@@ -1524,7 +1508,13 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
 //**************************************************************
 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
 {
-  myDisplayer->showOnly(theList);
+  QObjectPtrList aList = myDisplayer->displayedObjects();
+  foreach (ObjectPtr aObj, aList)
+    aObj->setDisplayed(false);
+  foreach (ObjectPtr aObj, theList)
+    aObj->setDisplayed(true);
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+
 }