]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Bug #1341: selected point on circle
authordbv <dbv@opencascade.com>
Fri, 26 Feb 2016 12:09:52 +0000 (15:09 +0300)
committerdbv <dbv@opencascade.com>
Fri, 26 Feb 2016 12:10:22 +0000 (15:10 +0300)
src/PartSet/PartSet_Filters.cpp
src/PartSet/PartSet_Filters.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h

index 31f1872c778acce3053fce118629971a8dbbdcb2..f2c82f246a353219b02736eff3d7f65bf096633d 100644 (file)
@@ -8,14 +8,15 @@
 
 #include <ModuleBase_IWorkshop.h>
 #include "ModuleBase_IModule.h"
+#include <ModuleBase_ResultPrs.h>
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Session.h>
-#include <FeaturesPlugin_Group.h>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
+#include <StdSelect_BRepOwner.hxx>
 
 
 IMPLEMENT_STANDARD_HANDLE(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter);
@@ -50,7 +51,7 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
         else {
           FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
           if (aFeature) {
-            aValid = aFeature->getKind() != FeaturesPlugin_Group::ID();
+            aValid = aFeature->getKind() != "Group";
           } else 
             aValid = Standard_True;
         }
@@ -64,3 +65,66 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
 #endif
   return aValid;
 }
+
+IMPLEMENT_STANDARD_HANDLE(PartSet_CirclePointFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(PartSet_CirclePointFilter, SelectMgr_Filter);
+
+Standard_Boolean PartSet_CirclePointFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
+  if(!anOperation) {
+    return Standard_True;
+  }
+
+  if(theOwner->HasSelectable() == Standard_False) {
+    return Standard_True;
+  }
+
+  Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+  if(aBrepOwner.IsNull()) {
+    return Standard_True;
+  }
+
+  const TopoDS_Shape& aShape = aBrepOwner->Shape();
+  if(aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
+    return Standard_True;
+  }
+
+  Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(theOwner->Selectable());
+  if(aResultPrs.IsNull()) {
+    return Standard_True;
+  }
+
+  std::shared_ptr<GeomAPI_AISObject> aGeomAISObj(new GeomAPI_AISObject());
+  aGeomAISObj->setImpl(new Handle(AIS_InteractiveObject)(aResultPrs));
+  ObjectPtr anObj = myWorkshop->findPresentedObject(aGeomAISObj);
+  if(!anObj.get()) {
+    return Standard_True;
+  }
+
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+  if(!aResult.get()) {
+    return Standard_True;
+  }
+
+  DocumentPtr aDocument = aResult->document();
+  if(!aDocument.get()) {
+    return Standard_True;
+  }
+
+  FeaturePtr aFeature = aDocument->feature(aResult);
+  if(!aFeature.get() || aFeature->getKind() != "SketchCircle") {
+    return Standard_True;
+  }
+
+  const TopoDS_Shape anOwnerShape = aResultPrs->Shape();
+  if(anOwnerShape.ShapeType() == TopAbs_EDGE) {
+    return Standard_False;
+  }
+
+#ifdef DEBUG_FILTERS
+  qDebug(QString("PartSet_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
+#endif
+
+  return Standard_True;
+}
index aba48302f78784315be71582cc63fc014fd4f608..c4e727035453e9bbd1e5ec510b7a5582d45cff6f 100644 (file)
@@ -31,4 +31,32 @@ public:
   DEFINE_STANDARD_RTTI(PartSet_GlobalFilter)
 };
 
+
+/// \class PartSet_CirclePointFilter
+/// \ingroup GUI
+/// \brief A filter which provide filtering of selection in 3d viewer.
+/// Installing of this filter disables selection of point on circle in sketch
+DEFINE_STANDARD_HANDLE(PartSet_CirclePointFilter, SelectMgr_Filter);
+class PartSet_CirclePointFilter: public SelectMgr_Filter
+{
+public:
+
+  /// Constructor
+  /// \param theWorkshop instance of workshop interface
+  Standard_EXPORT PartSet_CirclePointFilter(ModuleBase_IWorkshop* theWorkshop):
+    SelectMgr_Filter(),
+    myWorkshop(theWorkshop) {};
+
+  /// Returns True if the given owner is acceptable for selection
+  /// \param theOwner the selected owner
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(PartSet_CirclePointFilter)
+
+private:
+
+  /// Reference to workshop
+  ModuleBase_IWorkshop* myWorkshop;
+};
+
 #endif
\ No newline at end of file
index b261c2ca4d1b36df03550c836e3f71680f232d7e..4c2b63a6f5f44305823c6c5518be0e9e4faaa240 100755 (executable)
@@ -864,6 +864,12 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
     aFeature->setDisplayed(true);
   }
 
+  if(myCirclePointFilter.IsNull()) {
+    myCirclePointFilter = new PartSet_CirclePointFilter(myModule->workshop());
+  }
+
+  myModule->workshop()->viewer()->addSelectionFilter(myCirclePointFilter);
+
   if (myPlaneFilter.IsNull()) 
     myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
 
@@ -898,6 +904,8 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     // The sketch was aborted
     myCurrentSketch = CompositeFeaturePtr();
+    // TODO: move this outside of if-else
+    myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
 
     // Erase all sketcher objects
@@ -940,6 +948,8 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
       myCurrentSketch->setDisplayed(true);
     
     myCurrentSketch = CompositeFeaturePtr();
+
+    myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
 
     Events_Loop::loop()->flush(aDispEvent);
index 113abadd2a852ba76c0aeb0d28396c1211e18ff1..ef5fb511a5fe41cee6c2cc93d5c27c0e0324c3d2 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "PartSet.h"
 
+#include "PartSet_Filters.h"
 #include "PartSet_Tools.h"
 
 #include <ModelAPI_Feature.h>
@@ -356,6 +357,7 @@ private:
 
   CompositeFeaturePtr myCurrentSketch;
 
+  Handle(PartSet_CirclePointFilter) myCirclePointFilter;
   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
   FeatureToSelectionMap myCurrentSelection;
   bool myPreviousUpdateViewerEnabled;