]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
authornds <natalia.donis@opencascade.com>
Tue, 2 Dec 2014 14:49:15 +0000 (17:49 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 2 Dec 2014 14:49:15 +0000 (17:49 +0300)
src/ModuleBase/ModuleBase_ViewerFilters.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ModuleConnector.cpp

index e7309ca072b2ee7fb3bdaaf82070f5bef50156ec..94625a48094797a60e63dad02d46e11366f26907 100644 (file)
@@ -39,6 +39,10 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent
         SessionPtr aMgr = ModelAPI_Session::get();
         return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
       }
+      else {
+        // This is not object controlled by the filter
+        return Standard_True;
+      }
     }
   }
   return Standard_False;
@@ -74,6 +78,10 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
           bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
           return aD1 && aD2 && aD3;
         }
+      default:
+        // This is not object controlled by the filter
+        return Standard_True;
+      break;
       }
     } else {
       // This is not object controlled by the filter
index 490ffdfd9913879e33c5cafeebc07eef161e6431..1e2a511ee1753184bca111808df0c60fb2b134c4 100644 (file)
@@ -94,6 +94,10 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
 PartSet_Module::~PartSet_Module()
 {
+  if (!myDocumentShapeFilter.IsNull())
+    myDocumentShapeFilter.Nullify();
+  if (!myPlaneFilter.IsNull())
+    myPlaneFilter.Nullify();
 }
 
 void PartSet_Module::registerValidators()
@@ -175,6 +179,9 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
       myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
     }
   }
+  if (myDocumentShapeFilter.IsNull())
+    myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(myWorkshop);
+  myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
 }
 
 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
@@ -209,6 +216,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
     myCurrentSketch = CompositeFeaturePtr();
     myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter);
   }
+  myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
 }
 
 void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
index eb8fb58217b6c900be22d30e7a413247540a44ba..085876eb23bbdf83af816698ed20782608e2db75 100644 (file)
@@ -110,6 +110,8 @@ protected slots:
    QList<AttributePtr> myEditingAttr;
 
    Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
+  /// A filter which provides selection within a current document or whole PartSet
+  Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter;
 };
 
 #endif
index 37cd834450a68835ba3a0c0d22f29c88fa037067..3f7b53b259c8bde874a25356d032b0217c410002 100644 (file)
@@ -133,13 +133,13 @@ void PartSet_WidgetSketchLabel::activate()
 
     XGUI_Displayer* aDisp = myWorkshop->displayer();
     aDisp->openLocalContext();
-    aDisp->activateObjectsOutOfContext(QIntList());
+    aDisp->activateObjects(QIntList());
     if (myPlaneFilter.IsNull())
       myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
     aDisp->addSelectionFilter(myPlaneFilter);
     QIntList aModes;
     aModes << TopAbs_FACE;
-    aDisp->setSelectionModes(aModes);
+    aDisp->activateObjects(aModes);
 
     myLabel->setText(myText);
     myLabel->setToolTip(myTooltip);
@@ -265,7 +265,7 @@ void PartSet_WidgetSketchLabel::setSketchingMode()
   XGUI_Displayer* aDisp = myWorkshop->displayer();
   QIntList aModes;
   // Clear standard selection modes if they are defined
-  aDisp->setSelectionModes(aModes);
+  aDisp->activateObjects(aModes);
   aDisp->openLocalContext();
 
   // Set filter
@@ -283,5 +283,5 @@ void PartSet_WidgetSketchLabel::setSketchingMode()
   aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
   aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
 
-  aDisp->activateObjectsOutOfContext(aModes);
+  aDisp->activateObjects(aModes);
 }
index 9ca390ecb243023847224d61da0b94d02839fea9..8347d607a8660e714ae00cb65afeb33f510378c8 100644 (file)
@@ -328,10 +328,12 @@ void XGUI_Displayer::openLocalContext()
     //for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
     //  aAisList.Append(aContext->Current());
 
+    // get the filters from the global context and append them to the local context
+    // a list of filters in the global context is not cleared and should be cleared here
     SelectMgr_ListOfFilter aFilters;
     aFilters.Assign(aContext->Filters());
 
-    aContext->ClearCurrents();
+    //aContext->ClearCurrents();
     aContext->OpenLocalContext();
     aContext->NotUseDisplayedObjects();
 
@@ -341,6 +343,7 @@ void XGUI_Displayer::openLocalContext()
     SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
     for (;aIt.More(); aIt.Next()) {
       aContext->AddFilter(aIt.Value());
+      //GetFilter()->Add(aIt.Value());
     }
     // Restore selection
     //AIS_ListIteratorOfListOfInteractive aIt(aAisList);
@@ -360,7 +363,12 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
     //for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected())
     //  aAisList.Append(ic->SelectedInteractive());
 
-    ic->ClearSelected();
+    // get the filters from the local context and append them to the global context
+    // a list of filters in the local context is cleared
+    SelectMgr_ListOfFilter aFilters;
+    aFilters.Assign(ic->Filters());
+
+    //ic->ClearSelected();
     ic->CloseAllContexts(false);
 
     // Redisplay all object if they were displayed in localContext
@@ -372,6 +380,15 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer)
         ic->SetDisplayMode(aAISIO, Shading, false);
       }
     }
+
+    // Append the filters from the local selection in the global selection context
+    SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
+    for (;aIt.More(); aIt.Next()) {
+      Handle(SelectMgr_Filter) aFilter = aIt.Value();
+      ic->AddFilter(aFilter);
+      //GetFilter()->Add(aIt.Value());
+    }
+
     if (isUpdateViewer)
       updateViewer();
     myUseExternalObjects = false;
@@ -424,6 +441,16 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
   return myWorkshop->viewer()->AISContext();
 }
 
+Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (myAndFilter.IsNull() && !aContext.IsNull()) {
+    myAndFilter = new SelectMgr_AndFilter();
+    aContext->AddFilter(myAndFilter);
+  }
+  return myAndFilter;
+}
+
 void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
@@ -453,7 +480,7 @@ void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate)
   }
 }
 
-void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
+void XGUI_Displayer::activateObjects(const QIntList& theModes)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   // Open local context if there is no one
@@ -478,9 +505,18 @@ void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
     }
   }
 
+  //Activate all displayed objects with the module modes
+  //AIS_ListOfInteractive aPrsList;
+  //aContext->DisplayedObjects(aPrsList, true);
+
+  //AIS_ListIteratorOfListOfInteractive aLIt(aPrsList);
   Handle(AIS_InteractiveObject) anAISIO;
-  foreach (AISObjectPtr aAIS, myResult2AISObjectMap) {
-  anAISIO = aAIS->impl<Handle(AIS_InteractiveObject)>();
+  for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){
+    anAISIO = aLIt.Value();
+    aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO);
+    if (!aTrihedron.IsNull())
+      continue;
+
     aContext->Load(anAISIO, -1, true);
     if (theModes.size() == 0)
       aContext->Activate(anAISIO);
@@ -493,7 +529,7 @@ void XGUI_Displayer::activateObjectsOutOfContext(const QIntList& theModes)
 }
 
 
-void XGUI_Displayer::deactivateObjectsOutOfContext()
+void XGUI_Displayer::deactivateObjects()
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
   // Open local context if there is no one
@@ -521,28 +557,6 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo
   aContext->SetDisplayMode(aAISIO, theMode, toUpdate);
 }
 
-void XGUI_Displayer::setSelectionModes(const QIntList& theModes)
-{
-  Handle(AIS_InteractiveContext) aContext = AISContext();
-  if (aContext.IsNull())
-    return;
-  if (!aContext->HasOpenedContext())
-    return;
-  // Clear previous mode
-  const TColStd_ListOfInteger& aModes = aContext->ActivatedStandardModes();
-  if (!aModes.IsEmpty()) {
-    TColStd_ListOfInteger aMModes;
-    aMModes.Assign(aModes);
-    TColStd_ListIteratorOfListOfInteger it(aMModes);
-    for(; it.More(); it.Next()) {
-      aContext->DeactivateStandardMode((TopAbs_ShapeEnum)it.Value());
-    }
-  }
-  foreach(int aMode, theModes) {
-    aContext->ActivateStandardMode((TopAbs_ShapeEnum)aMode);
-  }
-}
-
 XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
@@ -568,7 +582,8 @@ void XGUI_Displayer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilte
     if (theFilter.Access() == aIt.Value().Access())
       return;
   }
-  aContext->AddFilter(theFilter);
+  //aContext->AddFilter(theFilter);
+  GetFilter()->Add(theFilter);
 }
 
 void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
@@ -576,7 +591,8 @@ void XGUI_Displayer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFi
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (aContext.IsNull())
     return;
-  aContext->RemoveFilter(theFilter);
+  //aContext->RemoveFilter(theFilter);
+  GetFilter()->Remove(theFilter);
 }
 
 void XGUI_Displayer::removeFilters()
@@ -584,5 +600,6 @@ void XGUI_Displayer::removeFilters()
   Handle(AIS_InteractiveContext) aContext = AISContext();
   if (aContext.IsNull())
     return;
-  aContext->RemoveFilters();
+  //aContext->RemoveFilters();
+  GetFilter()->Clear();
 }
index f563223280a444faf49eeeea1918cae78bb1210f..b18eb0f8dc33baafa655ef85c202fbb606389d7d 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ViewerPrs.h>
 
+#include <SelectMgr_AndFilter.hxx>
+
 #include <QString>
 #include <QMap>
 
@@ -94,13 +96,6 @@ class XGUI_EXPORT XGUI_Displayer
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   void closeLocalContexts(const bool isUpdateViewer = true);
 
-  /*
-  * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
-  * It doesn't manages a local context
-  * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
-  */
-  void setSelectionModes(const QIntList& theModes);
-
   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
 
   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
@@ -136,10 +131,10 @@ class XGUI_EXPORT XGUI_Displayer
 
   /// Activates in local context displayed outside of the context.
   /// \param theModes - modes on which it has to be activated (can be empty)
-  void activateObjectsOutOfContext(const QIntList& theModes);
+  void activateObjects(const QIntList& theModes);
 
   /// Activates in local context displayed outside of the context.
-  void deactivateObjectsOutOfContext();
+  void deactivateObjects();
 
   /// Sets display mode for the given object if this object is displayed
   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
@@ -155,6 +150,10 @@ class XGUI_EXPORT XGUI_Displayer
   /// Returns currently installed AIS_InteractiveContext
   Handle(AIS_InteractiveContext) AISContext() const;
 
+  /// Returns the viewer context top filter. If there is no a filter, it is created and set into
+  /// The context should have only this filter inside. Other filters should be add to the filter
+  Handle(SelectMgr_AndFilter) GetFilter();
+
   /// Display the feature and a shape. This shape would be associated to the given feature
   /// \param theFeature a feature instance
   /// \param theAIS AIS presentation
@@ -181,6 +180,8 @@ class XGUI_EXPORT XGUI_Displayer
  protected:
   XGUI_Workshop* myWorkshop;
 
+  Handle(SelectMgr_AndFilter) myAndFilter;
+
   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
   ResultToAISMap myResult2AISObjectMap;
 
index cd13a987be12da53666ee1e9b286089b4e66ab3b..e45a52ccea18854b72d5bb65bd3e6ff39689fbd5 100644 (file)
@@ -73,7 +73,7 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
   foreach(int aType, theTypes) {
     aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType));
   }
-  aDisp->activateObjectsOutOfContext(aModes);
+  aDisp->activateObjects(aModes);
   //TODO: We have to open Local context because at neutral point filters don't work (bug 25340)
   //aDisp->addSelectionFilter(myDocumentShapeFilter);
 }