Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into CEA_2019
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 9934267..3a8d964
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "PartSet_Module.h"
@@ -39,6 +38,7 @@
 #include "PartSet_IconFactory.h"
 #include "PartSet_OverconstraintListener.h"
 #include "PartSet_TreeNodes.h"
+#include "PartSet_FieldStepPrs.h"
 
 #include "PartSet_Filters.h"
 #include "PartSet_FilterInfinite.h"
@@ -47,6 +47,8 @@
 #include <PartSetPlugin_Part.h>
 #include <PartSetPlugin_Duplicate.h>
 
+#include <SketchPlugin_ConstraintCoincidence.h>
+
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationAction.h>
 #include <ModuleBase_IViewer.h>
@@ -61,6 +63,7 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModelAPI_ResultField.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -154,7 +157,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   myRoot(0),
   myIsOperationIsLaunched(false)
 {
-  new PartSet_IconFactory();
+  new PartSet_IconFactory(this);
 
   mySketchMgr = new PartSet_SketcherMgr(this);
   mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
@@ -176,6 +179,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 
   registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
   registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
@@ -222,20 +226,13 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
     "Dimension value size", Config_Prop::IntSpin, aStream.str());
 
   Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
-    "Sketch dimension color",
+    "Dimension color",
     Config_Prop::Color, SKETCH_DIMENSION_COLOR);
 }
 
 //******************************************************
 PartSet_Module::~PartSet_Module()
 {
-  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
-    mySelectionFilters.begin();
-  for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
-    Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
-    if (!aFilter.IsNull())
-      aFilter.Nullify();
-  }
   delete myCustomPrs;
   delete myOverconstraintListener;
   delete myRoot;
@@ -655,7 +652,7 @@ void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
 {
   bool isSketchActive = mySketchMgr->activeSketch().get();
 
-  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
+  std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
     mySelectionFilters.begin();
   for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
     int aFilterType = aFiltersIt->first;
@@ -665,7 +662,7 @@ void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
 
     // using sketch filters only if sketch operation is active
     if (!isSketchActive &&
-        mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
+        mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
       continue;
 
     // using filtering of construction results only from faces panel
@@ -676,37 +673,6 @@ void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
   }
 }
 
-//******************************************************
-QIntList PartSet_Module::selectionFilters()
-{
-  QIntList aTypes;
-
-  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
-    mySelectionFilters.begin();
-  for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
-    aTypes.append(aFiltersIt->first);
-
-  return aTypes;
-}
-
-//******************************************************
-void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
-                                             const Handle(SelectMgr_Filter)& theFilter)
-{
-  mySelectionFilters[theFilterType] = theFilter;
-}
-
-//******************************************************
-Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
-{
-  XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
-
-  if (mySelectionFilters.find(aType) != mySelectionFilters.end())
-    return mySelectionFilters[aType];
-  else
-    return Handle(SelectMgr_Filter)();
-}
-
 //******************************************************
 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
 {
@@ -890,6 +856,10 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
     connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
       mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
+    connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
+    connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
+      sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
+    aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
     aWgt = aLabelWgt;
   } else if (theType == "sketch-2dpoint_selector") {
     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
@@ -1089,7 +1059,10 @@ void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
       }
       if (aToUseZLayer) {
         Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
-        aCtx->SetZLayer(anAIS, myVisualLayerId);
+        if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+          aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
+        else
+          aCtx->SetZLayer(anAIS, myVisualLayerId);
       }
     }
   }
@@ -1150,8 +1123,14 @@ void PartSet_Module::onViewTransformed(int theTrsfType)
     SketcherPrs_Tools::setArrowSize(aLen);
     const double aCurScale = aViewer->activeView()->Camera()->Scale();
     aViewer->SetScale(aViewer->activeView(), aCurScale);
+#ifdef OPTIMIZE_PRS
     QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
     foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
+#else
+    QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
+    foreach(AISObjectPtr aAIS, aPrsList) {
+      Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
+#endif
       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
       if (!aDim.IsNull()) {
         aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
@@ -1300,9 +1279,19 @@ void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
 }
 
 //******************************************************
-Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
+Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
 {
-  return mySketchMgr->createPresentation(theResult);
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if (aResult.get())
+    return mySketchMgr->createPresentation(aResult);
+  else {
+    FieldStepPtr aStep =
+      std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
+    if (aStep.get()) {
+      return new PartSet_FieldStepPrs(aStep);
+    }
+  }
+  return Handle(AIS_InteractiveObject)();
 }
 
 //******************************************************
@@ -1431,11 +1420,15 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
-    //if (myActivePartIndex.isValid())
-    //  aTreeView->setExpanded(myActivePartIndex, false);
+
+    // Clear active part index if there is no Part documents
+    // It could be not null if document was closed and opened a new
+    // without closeDocument call
+    if (aMgr->allOpenedDocuments().size() <= 1)
+      myActivePartIndex = QModelIndex();
 
     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+    QModelIndex aOldActive = myActivePartIndex;
     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
     bool needUpdate = false;
     if (myActivePartIndex.isValid()) {
@@ -1443,6 +1436,8 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
       if (!needUpdate)
         aTreeView->setExpanded(myActivePartIndex, true);
     }
+    if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
+      aTreeView->setExpanded(aOldActive, false);
 
     aLabel->setPalette(aPalet);
     aWorkshop->updateCommandStatus();
@@ -1460,7 +1455,7 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     aDisplayer->updateViewer();
     // Update tree items if they are expanded
     if (needUpdate) {
-      aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
+      aTreeView->viewport()->update(aTreeView->viewport()->rect());
     }
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
@@ -1496,6 +1491,14 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
       }
     }
   }
+  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+    CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
+    if (aSketch.get()) {
+      ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+      if (PartSet_SketcherMgr::isSketchOperation(anOperation))
+        mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
+    }
+  }
 }
 
 //******************************************************
@@ -1672,3 +1675,13 @@ ModuleBase_ITreeNode* PartSet_Module::rootNode() const
 {
   return myRoot;
 }
+
+//******************************************************
+void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
+  myCustomPrs->disableCustomMode(theMode);
+}
+
+//******************************************************
+void PartSet_Module::enableCustomModes() {
+  myCustomPrs->enableCustomModes();
+}