Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 79491af8274f91b4b1088898f3aecbdb7e77e1fc..4022d7fc70d4e4cb0750393b73cddf4e75dbbad9 100644 (file)
@@ -187,9 +187,9 @@ void XGUI_Workshop::startApplication()
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
-  aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
+  aLoop->registerListener(this, Events_LongOp::eventID());
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
-  aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged"));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
   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));
@@ -206,6 +206,8 @@ void XGUI_Workshop::startApplication()
   }
   
   onNew();
+
+  emit applicationStarted();
 }
 
 //******************************************************
@@ -322,7 +324,6 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
       addFeature(aFeatureMsg);
     }
   }
-
   // Process creation of Part
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
@@ -337,36 +338,29 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
     myUpdatePrefs = true;
   }
-
   // Redisplay feature
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     onFeatureRedisplayMsg(aUpdMsg);
   }
-
   //Update property panel on corresponding message. If there is no current operation (no
   //property panel), or received message has different feature to the current - do nothing.
   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
     onFeatureUpdatedMsg(anUpdateMsg);
-  }
-
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
+  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDelMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
     onObjectDeletedMsg(aDelMsg);
-  }
-
-  else if (theMessage->eventID() == Events_LongOp::eventID()) {
-    if (Events_LongOp::isPerformed())
+  } else if (theMessage->eventID() == Events_LongOp::eventID()) {
+    if (Events_LongOp::isPerformed()) {
       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-    else
+    } else {
       QApplication::restoreOverrideCursor();
-  }
-
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
+    }
+  } 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();
@@ -375,9 +369,7 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
     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)) {
+  } 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();
@@ -387,7 +379,6 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
       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)) {
     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
@@ -402,8 +393,7 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
           updateCommandStatus();
       }
     }
-  }
-  else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
+  } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
     myActionsMgr->update();
     // Find and Activate active part
     if (myPartActivating)
@@ -490,6 +480,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
   std::set<ObjectPtr>::const_iterator aIt;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
     ObjectPtr aObj = (*aIt);
+
     bool aHide = !aObj->data() || !aObj->data()->isValid();
     if (!aHide) { // check that this is not hidden result
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
@@ -499,18 +490,18 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
       myDisplayer->erase(aObj, false);
     else {
       if (myDisplayer->isVisible(aObj))  {
-        myDisplayer->display(aObj, false);  // In order to update presentation
+        displayObject(aObj);  // In order to update presentation
         if (myOperationMgr->hasOperation()) {
           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-          if (aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
+          if (!aOperation->isEditOperation() &&
+              aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
             myDisplayer->deactivate(aObj);
         }
       } else {
         if (myOperationMgr->hasOperation()) {
           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-          // Display only current operation results if operation has preview
-          if (aOperation->hasObject(aObj)/* && aOperation->hasPreview()*/) {
-            myDisplayer->display(aObj, false);
+          if (myModule->canDisplayObject(aObj)) {
+            displayObject(aObj);
             // Deactivate object of current operation from selection
             if (myDisplayer->isActive(aObj))
               myDisplayer->deactivate(aObj);
@@ -531,17 +522,15 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpd
   bool aHasPart = false;
   bool isDisplayed = false;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+
     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 if (myOperationMgr->hasOperation()) {
-      ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
-      if (aOperation->hasObject(*aIt)) {  // Display only current operation results
-        myDisplayer->display(*aIt, false);
-        isDisplayed = true;
-      }
+    } else if (myModule->canDisplayObject(*aIt)) {
+      displayObject(*aIt);
+      isDisplayed = true;
     }
   }
   if (myObjectBrowser)
@@ -593,19 +582,17 @@ void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
 //******************************************************
 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
 {
+  ModuleBase_ISelection* aSel = mySelector->selection();
+  QObjectPtrList aObj = aSel->selectedPresentations();
   //!< No need for property panel
   updateCommandStatus();
   hidePropertyPanel();
   myPropertyPanel->cleanContent();
 
-  // Activate objects created by current operation
-  FeaturePtr aFeature = theOperation->feature();
-  myDisplayer->activate(aFeature);
-  const std::list<ResultPtr>& aResults = aFeature->results();
-  std::list<ResultPtr>::const_iterator aIt;
-  for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
-    myDisplayer->activate(*aIt);
-  }
+  // Activate objects created by current operation 
+  // in order to clean selection modes
+  QIntList aModes;
+  myDisplayer->activateObjects(aModes);
   myModule->operationStopped(theOperation);
 }
 
@@ -645,7 +632,7 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
     aWidget->enableFocusProcessing();
     QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
     // Init default values
-    if (!theOperation->isEditOperation() && !aWidget->isComputedDefault()) {
+    if (!theOperation->isEditOperation() && aWidget->isValueDefault() && !aWidget->isComputedDefault()) {
       aWidget->storeValue();
     }
   }
@@ -1070,6 +1057,7 @@ void XGUI_Workshop::updateCommandStatus()
     }
   }
   myActionsMgr->update();
+  emit commandStatusUpdated();
 }
 
 //******************************************************
@@ -1105,7 +1093,7 @@ void XGUI_Workshop::createDockWidgets()
   connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
 
   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
-  hidePropertyPanel();  //<! Invisible by default
+  hidePropertyPanel();  ///<! Invisible by default
   hideObjectBrowser();
   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
   myPropertyPanel->installEventFilter(myOperationMgr);
@@ -1116,7 +1104,7 @@ void XGUI_Workshop::createDockWidgets()
   connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
           SLOT(onKeyReleased(QKeyEvent*)));
-  connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
+  connect(myOperationMgr, SIGNAL(applyEnableChanged(bool)), myPropertyPanel,
           SLOT(setAcceptEnabled(bool)));
 
 }
@@ -1125,7 +1113,7 @@ void XGUI_Workshop::createDockWidgets()
 void XGUI_Workshop::showPropertyPanel()
 {
   QAction* aViewAct = myPropertyPanel->toggleViewAction();
-  //<! Restore ability to close panel from the window's menu
+  ///<! Restore ability to close panel from the window's menu
   aViewAct->setEnabled(true);
   myPropertyPanel->show();
   myPropertyPanel->raise();
@@ -1135,7 +1123,7 @@ void XGUI_Workshop::showPropertyPanel()
 void XGUI_Workshop::hidePropertyPanel()
 {
   QAction* aViewAct = myPropertyPanel->toggleViewAction();
-  //<! Do not allow to show empty property panel
+  ///<! Do not allow to show empty property panel
   aViewAct->setEnabled(false);
   myPropertyPanel->hide();
 }
@@ -1229,15 +1217,12 @@ void XGUI_Workshop::onWidgetValuesChanged()
   FeaturePtr aFeature = anOperation->feature();
 
   ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
-  //if (aCustom)
-  //  aCustom->storeValue(aFeature);
 
   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
   for (; anIt != aLast; anIt++) {
     ModuleBase_ModelWidget* aCustom = *anIt;
-    if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
-      //aCustom->storeValue(aFeature);
+    if (aCustom && (aCustom == aSenderWidget)) {
       aCustom->storeValue();
     }
   }
@@ -1254,20 +1239,21 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
     myObjectBrowser->activatePart(theFeature);
     myPartActivating = false;
   }
+  updateCommandStatus();
 }
 
 //**************************************************************
-void XGUI_Workshop::activateLastPart()
-{
-  SessionPtr aMgr = ModelAPI_Session::get();
-  DocumentPtr aDoc = aMgr->moduleDocument();
-  std::string aGrpName = ModelAPI_ResultPart::group();
-  ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
-  ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
-  if (aPart) {
-    activatePart(aPart);
-  }
-}
+//void XGUI_Workshop::activateLastPart()
+//{
+//  SessionPtr aMgr = ModelAPI_Session::get();
+//  DocumentPtr aDoc = aMgr->moduleDocument();
+//  std::string aGrpName = ModelAPI_ResultPart::group();
+//  ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
+//  ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
+//  if (aPart) {
+//    activatePart(aPart);
+//  }
+//}
 
 //**************************************************************
 void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
@@ -1306,7 +1292,7 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
   foreach (ObjectPtr aObj, theList)
   {
     if (isVisible) {
-      myDisplayer->display(aObj, false);
+      displayObject(aObj);
     } else {
       myDisplayer->erase(aObj, false);
     }
@@ -1355,7 +1341,7 @@ void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
 {
   for (int i = 0; i < theDoc->size(theGroup); i++)
-    myDisplayer->display(theDoc->object(theGroup, i), false);
+    displayObject(theDoc->object(theGroup, i));
 }
 
 //**************************************************************
@@ -1371,6 +1357,11 @@ void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
 //**************************************************************
 void XGUI_Workshop::closeDocument()
 {
+  ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
+  while (anOperation) {
+    anOperation->abort();
+    anOperation = operationMgr()->currentOperation();
+  }
   myDisplayer->closeLocalContexts();
   myDisplayer->eraseAll();
   objectBrowser()->clearContent();
@@ -1379,3 +1370,16 @@ void XGUI_Workshop::closeDocument()
   aMgr->closeAll();
   objectBrowser()->clearContent();
 }
+
+//**************************************************************
+void XGUI_Workshop::displayObject(ObjectPtr theObj)
+{
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
+  if (aBody.get() != NULL) {
+    int aNb = myDisplayer->objectsCount();
+    myDisplayer->display(theObj, false);
+    if (aNb == 0)
+      viewer()->fitAll();
+  } else 
+    myDisplayer->display(theObj, false);
+}