Salome HOME
Support of the newer version of OCCT 7.2.0 with patches
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 3bbb2d79c531b1dfa029d9c960f543267e15d3bd..70f6736b51f0c3c955c7b406c42ba577904ef242 100755 (executable)
@@ -173,8 +173,13 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
 
-  mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
-  mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
+  registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
+  registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
+  Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
+  std::set<std::string> aCRGroupNames;
+  aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
+  aCRFilter->setGroupNames(aCRGroupNames);
+  registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
 
   setDefaultConstraintShown();
 
@@ -203,9 +208,10 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 //******************************************************
 PartSet_Module::~PartSet_Module()
 {
-  SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
-  for (; aIt.More(); aIt.Next()) {
-    Handle(SelectMgr_Filter) aFilter = aIt.Value();
+  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();
   }
@@ -548,17 +554,6 @@ bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
   return aCanActivate;
 }
 
-//******************************************************
-void PartSet_Module::selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters) const
-{
-  for (SelectMgr_ListOfFilter::Iterator aFiltersIt(mySelectionFilters); aFiltersIt.More();
-       aFiltersIt.Next())
-    theSelectionFilters.Append(aFiltersIt.Value());
-
-  if (mySketchMgr->activeSketch())
-    mySketchMgr->selectionFilters(theSelectionFilters);
-}
-
 //******************************************************
 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
                                    QWidget* theParent,
@@ -614,6 +609,72 @@ void PartSet_Module::activeSelectionModes(QIntList& theModes)
     theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
 }
 
+//******************************************************
+void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
+{
+  customSubShapesSelectionModes(theModes);
+  //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
+  //myWorkshop->module()->activeSelectionModes(theModes);
+}
+
+//******************************************************
+void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
+                                            SelectMgr_ListOfFilter& theSelectionFilters)
+{
+  bool isSketchActive = mySketchMgr->activeSketch().get();
+
+  std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
+    mySelectionFilters.begin();
+  for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
+    int aFilterType = aFiltersIt->first;
+    // do not add not participating filters in given parameters
+    if (!theFilterTypes.contains(aFilterType))
+      continue;
+
+    // using sketch filters only if sketch operation is active
+    if (!isSketchActive &&
+        mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
+      continue;
+
+    // using filtering of construction results only from faces panel
+    if (aFilterType == SF_ResultGroupNameFilter)
+      continue;
+
+    theSelectionFilters.Append(aFiltersIt->second);
+  }
+}
+
+//******************************************************
+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)
 {
@@ -1339,8 +1400,9 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    if (myActivePartIndex.isValid())
-      aTreeView->setExpanded(myActivePartIndex, false);
+    // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
+    //if (myActivePartIndex.isValid())
+    //  aTreeView->setExpanded(myActivePartIndex, false);
 
     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
     myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);