Salome HOME
Update state of Apply and Continue button
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index d42b7e24711dbf2bff891cc65a6f0f855c80abe3..bb845edb3f7407a49bba83d7de00642fc69c5d7d 100644 (file)
@@ -91,6 +91,7 @@
 #include <ExchangePlugin_ImportPart.h>
 
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_IViewer.h>
@@ -170,6 +171,7 @@ static Handle(VInspector_CallBack) MyVCallBack;
 //#define DEBUG_WITH_MESSAGE_REPORT
 
 QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end");
+QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split");
 
 //#define DEBUG_DELETE
 //#define DEBUG_FEATURE_NAME
@@ -224,7 +226,15 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   // Load translations
   QStringList aLangs;
   aLangs << "*_en.ts"; // load by default eng translations
+
+  /// If version of OCCT is 7.4.0 or more then it means that
+  /// this is version of SALOME older then 9.4.0
+#if OCC_VERSION_HEX >= 0x070400
+  QString aCurrLang = aResMgr->language();
+#else
   QString aCurrLang = aResMgr->stringValue("language", "language", "en");
+#endif
+
   if(aCurrLang != "en") {
     aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
   }
@@ -774,9 +784,11 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation)
 #endif
 
   myErrorMgr->setPropertyPanel(myPropertyPanel);
-  theOperation->setHideFacesVisible(myFacesPanel->isVisible());
-  if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
-    myFacesPanel->show();
+  if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
+    theOperation->setHideFacesVisible(myFacesPanel->isVisible());
+    if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible())
+      myFacesPanel->show();
+  }
   showPanel(myPropertyPanel);
 }
 
@@ -860,8 +872,10 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   }
   activateObjectsSelection(anObjects);
 
-  if (!theOperation->isHideFacesVisible())
-    myFacesPanel->hide();
+  if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) {
+    if (!theOperation->isHideFacesVisible())
+      myFacesPanel->close();
+  }
 }
 
 //******************************************************
@@ -1038,6 +1052,8 @@ void XGUI_Workshop::onNew()
   QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
   aWnd->showMaximized();
   updateCommandStatus();
+  PyConsole_Console* aConsole = myMainWindow->pythonConsole();
+  connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus()));
 #endif
   myContextMenuMgr->connectViewer();
   QApplication::restoreOverrideCursor();
@@ -1211,7 +1227,8 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i
     else
       aMgr->redo();
 
-    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND)
+    if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND ||
+        QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND)
       myObjectBrowser->rebuildDataTree();
   }
   operationMgr()->updateApplyOfOperations();
@@ -1273,26 +1290,11 @@ void XGUI_Workshop::onWidgetObjectUpdated()
 //******************************************************
 void XGUI_Workshop::onImportPart()
 {
-  if (!abortAllOperations())
-    return;
-
-  //show file dialog, check if readable and open
-  qreal aRatio = ModuleBase_Tools::currentPixelRatio();
-  // If the ratio is > 1 (HD screen) then QT has a bug in
-  // displaying of system open file dialog (too small)
-  QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Import part"), QString(),
-        MyImportPartFilter, Q_NULLPTR,
-        ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options()));
-  if (!aFile.isNull()) {
+  if (abortAllOperations()) {
     ModuleBase_OperationFeature* anImportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ImportPart::ID()));
-    if (operationMgr()->startOperation(anImportPartOp)) {
-      // initialize the filename to be imported
-      FeaturePtr aFeature = anImportPartOp->feature();
-      aFeature->string(ExchangePlugin_ImportPart::FILE_PATH_ID())->setValue(aFile.toStdString());
-      ModuleBase_Tools::flushUpdated(aFeature);
-      operationMgr()->commitOperation();
-    }
+    myPropertyPanel->updateApplyPlusButton(anImportPartOp->feature());
+    operationMgr()->startOperation(anImportPartOp);
   }
 }
 
@@ -1302,6 +1304,7 @@ void XGUI_Workshop::onExportPart()
   if (abortAllOperations()) {
     ModuleBase_OperationFeature* anExportPartOp = dynamic_cast<ModuleBase_OperationFeature*>(
         module()->createOperation(ExchangePlugin_ExportPart::ID()));
+    myPropertyPanel->updateApplyPlusButton(anExportPartOp->feature());
     operationMgr()->startOperation(anExportPartOp);
   }
 }
@@ -1479,6 +1482,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
   myObjectBrowser->initialize(myModule->rootNode());
   myModule->customizeObjectBrowser(myObjectBrowser);
   aObjDock->setWidget(myObjectBrowser);
+  aObjDock->setObjectName("Object browser");
 
   connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged()));
 
@@ -1589,7 +1593,7 @@ void XGUI_Workshop::showPanel(QDockWidget* theDockWidget)
   // in order to operation manager could process key events of the panel.
   // otherwise they are ignored. It happens only if the same(activateWindow) is
   // not happened by property panel activation(e.g. resume operation of Sketch)
-  ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
+  //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()");
 }
 
 //******************************************************
@@ -1648,8 +1652,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     deleteObjects();
   else if (theId == "CLEAN_HISTORY_CMD")
     cleanHistory();
-  else if (theId == "MOVE_CMD")
-    moveObjects();
+  else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD")
+    moveObjects(theId == "MOVE_SPLIT_CMD");
   else if (theId == "COLOR_CMD")
     changeColor(aObjects);
   else if (theId == "DEFLECTION_CMD")
@@ -1866,6 +1870,9 @@ void XGUI_Workshop::deleteObjects()
   }
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+  if (anObjects.isEmpty())
+    return;
+
   if (!abortAllOperations())
     return;
 
@@ -2107,7 +2114,7 @@ bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) {
   DocumentPtr aDoc = theF1->document();
   return aDoc->index(theF1) < aDoc->index(theF2);
 }
-void XGUI_Workshop::moveObjects()
+void XGUI_Workshop::moveObjects(const bool theSplit)
 {
   if (!abortAllOperations())
     return;
@@ -2124,7 +2131,7 @@ void XGUI_Workshop::moveObjects()
   if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures))
     return;
 
-  QString anActionId = "MOVE_CMD";
+  QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD";
   QString aDescription = contextMenuMgr()->action(anActionId)->text();
   aMgr->startOperation(aDescription.toStdString());
 
@@ -2140,11 +2147,12 @@ void XGUI_Workshop::moveObjects()
     if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId))
       continue;
 
-    anActiveDocument->moveFeature(aFeature, aCurrentFeature);
+    anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit);
     aCurrentFeature = anActiveDocument->currentFeature(true);
   }
   aMgr->finishOperation();
   updateCommandStatus();
+  myViewerProxy->update();
 }
 
 //**************************************************************
@@ -2344,9 +2352,28 @@ void setColor(ResultPtr theResult, const std::vector<int>& theColor)
     aColorAttr->setValue(1, theColor[1]);
     aColorAttr->setValue(2, theColor[2]);
   }
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+}
+
+//**************************************************************
+void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid,
+  std::vector<int>& theColor)
+{
+  theColor.clear();
+  // get default color from the preferences manager for the given result
+  if (theColor.empty()) {
+    std::string aSection, aName, aDefault;
+    theObject->colorConfigInfo(aSection, aName, aDefault);
+    if (!aSection.empty() && !aName.empty()) {
+      theColor = Config_PropManager::color(aSection, aName);
+    }
+  }
+  if (!isEmptyColorValid && theColor.empty()) {
+    // all AIS objects, where the color is not set, are in black.
+    // The color should be defined in XML or set in the attribute
+    theColor = Config_PropManager::color("Visualization", "object_default_color");
+    Events_InfoMessage("XGUI_CustomPrs",
+      "A default color is not defined in the preferences for this kind of result").send();
+  }
 }
 
 //**************************************************************
@@ -2361,6 +2388,8 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       ModelAPI_Tools::getColor(aResult, aColor);
+      if (aColor.empty())
+        getDefaultColor(aResult, false, aColor);
     }
     else {
       // TODO: remove the obtaining a color from the AIS object
@@ -2412,8 +2441,10 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
       setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
+  myViewerProxy->update();
 }
 
 //**************************************************************
@@ -2423,11 +2454,9 @@ void setDeflection(ResultPtr theResult, const double theDeflection)
     return;
 
   AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
-  if (aDeflectionAttr.get() != NULL)
+  if (aDeflectionAttr.get() != NULL) {
     aDeflectionAttr->setValue(theDeflection);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  }
 }
 
 //**************************************************************
@@ -2437,11 +2466,9 @@ void setTransparency(ResultPtr theResult, double theTransparency)
     return;
 
   AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
-  if (anAttribute.get() != NULL)
+  if (anAttribute.get() != NULL) {
     anAttribute->setValue(theTransparency);
-  static const Events_ID kRedisplayEvent =
-    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent);
+  }
 }
 
 //**************************************************************
@@ -2454,7 +2481,8 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
       if (aBodyResult.get() != NULL) { // change property for all sub-solids
         std::list<ResultPtr> allRes;
         ModelAPI_Tools::allSubs(aBodyResult, allRes);
-        for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+        std::list<ResultPtr>::iterator aRes;
+        for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
           setTransparency(*aRes, theTransparency);
         }
       }
@@ -2463,6 +2491,34 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects)
   }
 }
 
+//**************************************************************
+double getDefaultDeflection(const ObjectPtr& theObject)
+{
+  double aDeflection = -1;
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aResult.get()) {
+    bool isConstruction = false;
+
+    std::string aResultGroup = aResult->groupName();
+    if (aResultGroup == ModelAPI_ResultConstruction::group())
+      isConstruction = true;
+    else if (aResultGroup == ModelAPI_ResultBody::group()) {
+      GeomShapePtr aGeomShape = aResult->shape();
+      if (aGeomShape.get()) {
+        // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+        // correction of deviation for them should not influence to the application performance
+        GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
+        isConstruction = !anExp.more();
+      }
+    }
+    if (isConstruction)
+      aDeflection = Config_PropManager::real("Visualization", "construction_deflection");
+    else
+      aDeflection = Config_PropManager::real("Visualization", "body_deflection");
+  }
+  return aDeflection;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
 {
@@ -2474,6 +2530,8 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       aDeflection = ModelAPI_Tools::getDeflection(aResult);
+      if (aDeflection < 0)
+        aDeflection = getDefaultDeflection(aResult);
     }
     else {
       // TODO: remove the obtaining a property from the AIS object
@@ -2522,10 +2580,17 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects)
       setDeflection(aResult, aDeflection);
     }
   }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aMgr->finishOperation();
   updateCommandStatus();
 }
 
+//**************************************************************
+double getDefaultTransparency(const ResultPtr& theResult)
+{
+  return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.;
+}
+
 //**************************************************************
 void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
 {
@@ -2537,6 +2602,8 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects)
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
     if (aResult.get()) {
       aCurrentValue = ModelAPI_Tools::getTransparency(aResult);
+      if (aCurrentValue < 0)
+        aCurrentValue = getDefaultTransparency(aResult);
     }
     if (aCurrentValue > 0)
       break;
@@ -2583,7 +2650,11 @@ void XGUI_Workshop::onTransparencyValueChanged()
 
   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
   setTransparency(aTransparencyWidget->getValue(), anObjects);
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+  static const Events_ID kRedisplayEvent =
+    Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  Events_Loop::loop()->flush(kRedisplayEvent);
+
+  myViewerProxy->update();
 }