Salome HOME
Merge branch 'BR_internationalization'
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index cb741d4f0c169ebdfc68f0ff0ecbe534611372e3..f53edf79b0b553ce577e56f3702a4375b11d7592 100755 (executable)
@@ -41,6 +41,7 @@
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_ViewerPrs.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -67,6 +68,7 @@
 #include <XGUI_DataModel.h>
 #include <XGUI_ErrorMgr.h>
 #include <XGUI_CustomPrs.h>
+#include <XGUI_SelectionMgr.h>
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
@@ -146,9 +148,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
   mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
 
-  myHasConstraintShown[PartSet_Tools::Geometrical] = true;
-  myHasConstraintShown[PartSet_Tools::Dimensional] = true;
-  myHasConstraintShown[PartSet_Tools::Expressions] = false;
+  setDefaultConstraintShown();
 
   Config_PropManager::registerProp("Visualization", "operation_parameter_color",
                           "Reference shape wireframe color in operation", Config_Prop::Color,
@@ -392,6 +392,8 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
   if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
     mySketchMgr->stopNestedSketch(theOperation);
   }
+  else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
+    setDefaultConstraintShown();
 
   //VSV: Viewer is updated on feature update and redisplay
   if (isModified) {
@@ -403,7 +405,6 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
   QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
                                                                     aLast = myHasConstraintShown.end();
   for (; anIt != aLast; anIt++) {
-    myHasConstraintShown[anIt.key()];
     mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
   }
 }
@@ -445,8 +446,9 @@ bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& t
   if (theActionId == "MOVE_CMD") {
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aFeature) {
+      ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
       // part features can not be moved in the history.
-      if (aFeature->getKind() == PartSetPlugin_Part::ID())
+      if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
         aValid = false;
     }
   }
@@ -465,10 +467,10 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
   return mySketchMgr->canDisplayObject(theObject);
 }
 
-void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
+/*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
 {
   mySketchMgr->processHiddenObject(theObjects);
-}
+}*/
 
 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
 {
@@ -486,9 +488,11 @@ bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
   return aCanActivate;
 }
 
-bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
+bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
+                                   QWidget* theParent,
+                                   QMap<int, QAction*>& theMenuActions) const
 {
-  return myMenuMgr->addViewerMenu(theMenu, theStdActions);
+  return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
 }
 
 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
@@ -523,6 +527,14 @@ void PartSet_Module::activeSelectionModes(QIntList& theModes)
     PartSet_SketcherMgr::sketchSelectionModes(theModes);
 }
 
+void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
+{
+  if (theTypes.contains(TopAbs_FACE))
+    theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
+  if (theTypes.contains(TopAbs_WIRE))
+    theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
+}
+
 bool PartSet_Module::isMouseOverWindow()
 {
   return mySketchMgr->isMouseOverWindow();
@@ -764,6 +776,11 @@ bool PartSet_Module::deleteObjects()
 
     anOpMgr->startOperation(anOpAction);
 
+    // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
+    // the problem is in AIS Dimensions recompute if a line and the dim are removed, line is the first
+    // it causes the AIS recompute, where the base line is null, the result is empty AIS in the viewer
+    XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
+
     // 4. delete features
     // sketch feature should be skipped, only sub-features can be removed
     // when sketch operation is active
@@ -809,6 +826,8 @@ bool PartSet_Module::canCommitOperation() const
 void PartSet_Module::launchOperation(const QString& theCmdId)
 {
   storeConstraintsState(theCmdId.toStdString());
+  updateConstraintsState(theCmdId.toStdString());
+
   ModuleBase_IModule::launchOperation(theCmdId);
 }
 
@@ -820,6 +839,10 @@ void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
                                                   mySketchMgr->showConstraintStates();
     myHasConstraintShown = aShownStates;
   }
+}
+
+void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
+{
   if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str())) {
     // Show constraints if a constraint was anOperation
     mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
@@ -957,8 +980,7 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
       if (aColor.empty())
         XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
       if (!aColor.empty()) {
-        thePrs->setColor(aColor[0], aColor[1], aColor[2]);
-        aCustomized = true;
+        aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
       }
     }
 
@@ -1062,9 +1084,9 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
     bool hasResult = false;
     bool hasFeature = false;
     bool hasParameter = false;
-    bool hasSubFeature = false;
-    ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
-
+    bool hasCompositeOwner = false;
+    ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
+                                   hasCompositeOwner);
     ObjectPtr aObject = aObjects.first();
     if (aObject) {
       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
@@ -1296,7 +1318,8 @@ void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
     if (!aOperation)
       return;
     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-    aPanel->setWindowTitle(aChoiceTitle);
+    if (aPanel)
+      aPanel->setWindowTitle(aChoiceTitle);
   }
 }
 
@@ -1306,3 +1329,11 @@ XGUI_Workshop* PartSet_Module::getWorkshop() const
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   return aConnector->workshop();
 }
+
+//******************************************************
+void PartSet_Module::setDefaultConstraintShown()
+{
+  myHasConstraintShown[PartSet_Tools::Geometrical] = true;
+  myHasConstraintShown[PartSet_Tools::Dimensional] = true;
+  myHasConstraintShown[PartSet_Tools::Expressions] = false;
+}