Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 8706c57b7f9b6fec6efaf1de1b9dfc845035801a..646a41bfa8c070f70a6f183e566d8db0c59b2cb1 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)) {
@@ -466,7 +446,8 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
     ObjectPtr aObj = (*aIt);
 
     // Hide the object if it is invalid or concealed one
-    bool aHide = !aObj->data() || !aObj->data()->isValid();
+    bool aHide = !aObj->data() || !aObj->data()->isValid() || 
+      aObj->isDisabled() || (!aObj->isDisplayed());
     if (!aHide) { // check that this is not hidden result
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
       aHide = aRes && aRes->isConcealed();
@@ -487,21 +468,23 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
         // of redisplay is called. This modification is made in order to have the line is updated
         // by creation of a horizontal constraint on the line by preselection
         myDisplayer->redisplay(aObj, false);
-        if (myOperationMgr->hasOperation()) {
-          ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-          if (!aOperation->isEditOperation() &&
-              aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
+        //if (myOperationMgr->hasOperation()) {
+        //  ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
+        //  if (!aOperation->isEditOperation() &&
+        //      aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
+        if (!myModule->canActivateSelection(aObj)) {
+          if (myDisplayer->isActive(aObj))
             myDisplayer->deactivate(aObj);
         }
       } else { // display object if the current operation has it
-        ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-        if (aOperation && aOperation->hasObject(aObj)) {
-          ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-          #ifdef DEBUG_FEATURE_REDISPLAY
-            QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
-            qDebug(QString("  display object = %1").arg(anObjInfo).toStdString().c_str());
-          #endif
-          if (displayObject(aObj)) {
+        if (displayObject(aObj)) {
+          //ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
+          //if (aOperation && aOperation->hasObject(aObj)) {
+          if (!myModule->canActivateSelection(aObj)) {
+            #ifdef DEBUG_FEATURE_REDISPLAY
+              QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
+              qDebug(QString("  display object = %1").arg(anObjInfo).toStdString().c_str());
+            #endif
             // Deactivate object of current operation from selection
             if (myDisplayer->isActive(aObj))
               myDisplayer->deactivate(aObj);
@@ -533,16 +516,18 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpd
     ObjectPtr anObject = *aIt;
     // the validity of the data should be checked here in order to avoid display of the objects,
     // which were created, then deleted, but flush for the creation event happens after that
-    if (!anObject->data() || !anObject->data()->isValid())
-      continue;
-    //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
-    //if (aPart) {
-      //aHasPart = true;
-      // If a feature is created from the aplication's python console  
-      // it doesn't stored in the operation mgr and doesn't displayed
-    //} else {
-    isDisplayed = displayObject(*aIt);
-    //}
+    // we should not display disabled objects
+    bool aHide = !anObject->data() || !anObject->data()->isValid() || 
+      anObject->isDisabled() || (!anObject->isDisplayed());
+    if (!aHide) {
+      // setDisplayed has to be called in order to synchronize internal state of the object 
+      // with list of displayed objects
+      if (myModule->canDisplayObject(anObject)) {
+        anObject->setDisplayed(true);
+        isDisplayed = displayObject(*aIt);
+      } else 
+        anObject->setDisplayed(false);
+    }
   }
   //if (myObjectBrowser)
   //  myObjectBrowser->processEvent(theMsg);
@@ -600,11 +585,20 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   //myDisplayer->activateObjects(aModes);
   myModule->operationStopped(theOperation);
 
-  if (myOperationMgr->operationsCount() == 0) {
+  // if the operation is nested, do not deactivate objects
+  //if (myOperationMgr->operationsCount() == 0) {
     // Activate selection mode for all objects
-    QIntList aModes;
-    myDisplayer->activateObjects(aModes);
-  }
+  QIntList aModes;
+  // TODO: check on OCC_6.9.0
+  // the module current active modes should not be deactivated in order to save the objects selected
+  // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
+  // But, in OCC_6.8.0 this deselection does not happened automatically. It is necessary to call
+  // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
+  // the OCC_6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
+  // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
+  module()->activeSelectionModes(aModes);
+  myDisplayer->activateObjects(aModes);
+  //}
 }
 
 
@@ -838,7 +832,6 @@ void XGUI_Workshop::onOpen()
     } else if (anAnswer == QMessageBox::Cancel) {
       return;
     }
-    aSession->closeAll();
     myCurrentDir = "";
   }
 
@@ -854,9 +847,10 @@ void XGUI_Workshop::onOpen()
   }
   QApplication::setOverrideCursor(Qt::WaitCursor);
   myIsLoadingData = true;
+  aSession->closeAll();
   aSession->load(myCurrentDir.toLatin1().constData());
   myObjectBrowser->rebuildDataTree();
-  displayAllResults();
+  //displayAllResults();
   updateCommandStatus();
   myIsLoadingData = false;
   QApplication::restoreOverrideCursor();
@@ -1130,8 +1124,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
       "::title { position: relative; padding-left: 5px; text-align: left center }");
   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
   myObjectBrowser->setDataModel(myModule->dataModel());
-  //connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
-  //        SLOT(changeCurrentDocument(ObjectPtr)));
+  myModule->customizeObjectBrowser(myObjectBrowser);
   aObjDock->setWidget(myObjectBrowser);
 
   myContextMenuMgr->connectObjectBrowser();
@@ -1244,8 +1237,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));
+  }
 }
 
 //**************************************************************
@@ -1273,7 +1270,7 @@ void XGUI_Workshop::deleteObjects()
   aDescription += tr(" %1");
   QStringList aObjectNames;
   foreach (ObjectPtr aObj, anObjects) {
-    if (!aObj->data().get())
+    if (!aObj->data()->isValid())
       continue;
     aObjectNames << QString::fromStdString(aObj->data()->name());
   }
@@ -1499,21 +1496,29 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
 //**************************************************************
 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
 {
-  foreach (ObjectPtr aObj, theList)
-  {
+  foreach (ObjectPtr aObj, theList) {
     if (isVisible) {
-      displayObject(aObj);
+      aObj->setDisplayed(true);
+      //displayObject(aObj);
     } else {
-      myDisplayer->erase(aObj, false);
+      aObj->setDisplayed(false);
+      //myDisplayer->erase(aObj, false);
     }
   }
-  myDisplayer->updateViewer();
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  //myDisplayer->updateViewer();
 }
 
 //**************************************************************
 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));
+
 }
 
 
@@ -1550,8 +1555,10 @@ void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
 //**************************************************************
 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
 {
-  for (int i = 0; i < theDoc->size(theGroup); i++)
-    displayObject(theDoc->object(theGroup, i));
+  for (int i = 0; i < theDoc->size(theGroup); i++) 
+    theDoc->object(theGroup, i)->setDisplayed(true);
+    //displayObject(theDoc->object(theGroup, i));
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 }
 
 //**************************************************************
@@ -1578,7 +1585,6 @@ void XGUI_Workshop::closeDocument()
 
   SessionPtr aMgr = ModelAPI_Session::get();
   aMgr->closeAll();
-  objectBrowser()->clearContent();
 }
 
 //**************************************************************