Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 51a66d026d2f96a973a92e281760ce8295834128..1b48c4e081c1d7fc1f2c17e73c3f2782cfd49d62 100644 (file)
@@ -198,11 +198,11 @@ void XGUI_Workshop::initMenu()
   aCommand->connectTo(this, SLOT(onRedo()));
 
   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
-                                QIcon(":pictures/rebuild.png"));
+    QIcon(":pictures/rebuild.png"), QKeySequence());
   aCommand->connectTo(this, SLOT(onRebuild()));
 
   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
-                                QIcon(":pictures/save.png"));
+                                QIcon(":pictures/save.png"), QKeySequence());
   aCommand->connectTo(this, SLOT(onSaveAs()));
   //aCommand->disable();
 
@@ -342,6 +342,7 @@ void XGUI_Workshop::processEvent(const boost::shared_ptr<Events_Message>& theMes
     // Find and Activate active part
     if (myPartActivating)
       return;
+    myActionsMgr->update();
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
     DocumentPtr aDoc = aMgr->moduleDocument();
@@ -494,6 +495,7 @@ void XGUI_Workshop::onOperationStarted()
     for (; anIt != aLast; anIt++) {
       aWidget = *anIt;
       aWidget->setFeature(aOperation->feature());
+      aWidget->enableFocusProcessing();
       QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
       // Init default values
       if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
@@ -503,7 +505,11 @@ void XGUI_Workshop::onOperationStarted()
 
     myPropertyPanel->setModelWidgets(aWidgets);
     myPropertyPanel->onActivateNextWidget(NULL);
-    myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
+    // Widget activation (from the previous method) may commit the current operation
+    // if pre-selection is enougth for it. So we shouldn't update prop panel's title
+    if(myOperationMgr->isCurrentOperation(aOperation)) {
+      myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
+    }
   }
   updateCommandStatus();
 }
@@ -521,12 +527,6 @@ bool XGUI_Workshop::event(QEvent * theEvent)
 {
   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
   if (aPostponedEv) {
-#ifdef _DEBUG
-    std::cout << "XGUI_Workshop::event " << "Got PostponeMessageQtEvent" << std::endl;
-    bool isMyThread = (QApplication::instance()->thread() == QThread::currentThread());
-    std::cout << "XGUI_Workshop::event " << "I am in the Qt's thread: "
-              << isMyThread << std::endl;
-#endif
     boost::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
     processEvent(aEventPtr);
     return true;
@@ -558,7 +558,8 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr<Config_FeatureMessage>& t
                                                      QString::fromStdString(theMessage->text()),
                                                      QString::fromStdString(theMessage->tooltip()),
                                                      QIcon(theMessage->icon().c_str()),
-                                                     QKeySequence(), isUsePropPanel);
+                                                     QKeySequence(),
+                                                     isUsePropPanel);
     salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
     myActionsMgr->addCommand(aAction);
     myModule->featureCreated(aAction);
@@ -575,6 +576,7 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr<Config_FeatureMessage>& t
     if (!aGroup) {
       aGroup = aPage->addGroup(aGroupName);
     }
+    QString aDocKind = QString::fromStdString(theMessage->documentKind());
     // Check if hotkey sequence is already defined:
     QKeySequence aHotKey = myActionsMgr->registerShortcut(
         QString::fromStdString(theMessage->keysequence()));
@@ -582,7 +584,9 @@ void XGUI_Workshop::addFeature(const boost::shared_ptr<Config_FeatureMessage>& t
     XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
                                                 QString::fromStdString(theMessage->text()),
                                                 QString::fromStdString(theMessage->tooltip()),
-                                                QIcon(theMessage->icon().c_str()), aHotKey,
+                                                QIcon(theMessage->icon().c_str()),
+                                                aDocKind,
+                                                aHotKey,
                                                 isUsePropPanel);
     aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
     myActionsMgr->addCommand(aCommand);
@@ -784,9 +788,17 @@ void XGUI_Workshop::onRedo()
 //******************************************************
 void XGUI_Workshop::onRebuild()
 {
+  SessionPtr aMgr = ModelAPI_Session::get();
+  bool aWasOperation = aMgr->isOperation(); // keep this value
+  if (!aWasOperation) {
+    aMgr->startOperation();
+  }
   static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
   Events_Loop::loop()->send(boost::shared_ptr<Events_Message>(
     new Events_Message(aRebuildEvent, this)));
+  if (!aWasOperation) {
+    aMgr->finishOperation();
+  }
 }
 
 //******************************************************
@@ -861,7 +873,7 @@ ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
 
   if (!err.isEmpty()) {
     if (mainWindow()) {
-      QMessageBox::warning(mainWindow(), tr("Error"), err);
+      Events_Error::send(err.toStdString());
     } else {
       qWarning(qPrintable(err));
     }
@@ -1076,6 +1088,12 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     showObjects(aObjects, false);
   else if (theId == "SHOW_ONLY_CMD")
     showOnlyObjects(aObjects);
+  else if (theId == "SHADING_CMD")
+    setDisplayMode(aObjects, XGUI_Displayer::Shading);
+  else if (theId == "WIREFRAME_CMD")
+    setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
+  else if (theId == "HIDEALL_CMD")
+    myDisplayer->eraseAll();
 }
 
 //**************************************************************
@@ -1257,3 +1275,13 @@ 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);
 }
+
+//**************************************************************
+void XGUI_Workshop::setDisplayMode(const QList<ObjectPtr>& theList, int theMode)
+{
+  foreach(ObjectPtr aObj, theList) {
+    myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
+  }
+  if (theList.size() > 0)
+    myDisplayer->updateViewer();
+}