]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Provide selection of external objects in plane of sketcher
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Oct 2014 12:16:02 +0000 (16:16 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 17 Oct 2014 12:16:02 +0000 (16:16 +0400)
src/ModuleBase/ModuleBase_ViewerFilters.cpp
src/ModuleBase/ModuleBase_ViewerFilters.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h

index 6626a16683366bf0740d0ea7160a67fc18615fa5..6d2209de55682358037e820fc66a94b06e34cef0 100644 (file)
 #include <ModelAPI_Document.h>
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
@@ -33,4 +41,40 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent
     }
   }
   return Standard_False;
-}
\ No newline at end of file
+}
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  if (theOwner->HasSelectable()) {
+    Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+    if (!aShapeOwner.IsNull()) {
+      TopoDS_Shape aShape = aShapeOwner->Shape();
+      TopAbs_ShapeEnum aType = aShape.ShapeType();
+      switch (aType) {
+      case TopAbs_VERTEX:
+        {
+          gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+          return myPlane.Distance(aPnt) < Precision::Confusion();
+        }
+      case TopAbs_EDGE:
+        {
+          TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aFirst, aLast);
+          gp_Pnt aFirstPnt = aCurve->Value(aFirst);
+          gp_Pnt aMidPnt = aCurve->Value((aFirst + aLast) / 2.);
+          gp_Pnt aLastPnt = aCurve->Value(aLast);
+          bool aD1 = myPlane.Distance(aFirstPnt) < Precision::Confusion();
+          bool aD2 = myPlane.Distance(aMidPnt) < Precision::Confusion();
+          bool aD3 = myPlane.Distance(aLastPnt) < Precision::Confusion();
+          return aD1 && aD2 && aD3;
+        }
+      }
+    }
+  }
+  return Standard_False;
+}
index 55ad0b686c153118f905260bb7908ff4f17b3248..d26d3db3ed617f5db6ab13a66eb4b4b47a5e048b 100644 (file)
@@ -8,12 +8,18 @@
 
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
+#include <gp_Pln.hxx>
 
 
 class ModuleBase_IWorkshop;
 
-DEFINE_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select objects which belong to 
+* currently active document or to global document
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeDocumentFilter, SelectMgr_Filter);
 class ModuleBase_ShapeDocumentFilter: public SelectMgr_Filter
 {
 public:
@@ -28,4 +34,22 @@ private:
   ModuleBase_IWorkshop* myWorkshop;
 };
 
+/**
+* A filter which provides filtering of selection in 3d viewer.
+* Installing of this filter lets to select of Vertexes and Edges which belongs to the given plane
+*/
+DEFINE_STANDARD_HANDLE(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+class ModuleBase_ShapeInPlaneFilter: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_ShapeInPlaneFilter(const gp_Pln& thePane): 
+      SelectMgr_Filter(), myPlane(thePane) {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_ShapeInPlaneFilter)
+private:
+  gp_Pln myPlane;
+};
+
 #endif
\ No newline at end of file
index d1b54dcc16f9280e216b543e9f2cf8b86ded07ed..a44256ea79eac1c1f3629a90499eefde3b2c2fca 100644 (file)
@@ -20,6 +20,8 @@
 #include <ModelAPI_Data.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
@@ -35,6 +37,7 @@
 #include <XGUI_Tools.h>
 
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -153,7 +156,7 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
     if (aSketchOp) {
       if (aSketchOp->isEditOperation()) {
-        setSketchingMode();
+        setSketchingMode(getSketchPlane(aSketchOp->feature()));
       } else {
         aDisplayer->openLocalContext();
         aDisplayer->activateObjectsOutOfContext(QIntList());
@@ -288,7 +291,10 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
   xWorkshop()->actionsMgr()->update();
-  setSketchingMode();
+  // Set working plane
+  ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+  FeaturePtr aSketch = anOperation->feature();
+  setSketchingMode(getSketchPlane(aSketch));
 }
 
 void PartSet_Module::onFitAllView()
@@ -359,7 +365,7 @@ void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
   aDisplayer->updateViewer();
 }
 
-void PartSet_Module::setSketchingMode()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
 {
   XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
   if (!myPlaneFilter.IsNull()) {
@@ -367,13 +373,16 @@ void PartSet_Module::setSketchingMode()
     myPlaneFilter.Nullify();
   }
   QIntList aModes;
-  //aModes << TopAbs_VERTEX << TopAbs_EDGE;
-  //aModes << AIS_DSM_Text << AIS_DSM_Line;
+  // Clear standard selection modes
   aDisplayer->setSelectionModes(aModes);
   aDisplayer->openLocalContext();
   // Get default selection modes
   aModes = sketchSelectionModes(ObjectPtr());
   aDisplayer->activateObjectsOutOfContext(aModes);
+
+  // Set filter
+  mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
+  aDisplayer->addSelectionFilter(mySketchFilter);
 }
 
 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
@@ -587,3 +596,17 @@ QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
   aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
   return aModes;
 }
+
+
+gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
+{
+  DataPtr aData = theSketch->data();
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
+      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
+  gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
+  return gp_Pln(aOrig, aDir);
+}
+
index 88f745776040b4eeaa5526e2f9652615e2b8eb5a..79379ffc49403e1734ece9fa633d3c26fbba883b 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_Definitions.h>
+#include <ModuleBase_ViewerFilters.h>
 #include <XGUI_Command.h>
 #include <ModelAPI_Feature.h>
 #include <StdSelect_FaceFilter.hxx>
@@ -115,7 +116,8 @@ Q_OBJECT
   void onSetSelection(const QList<ObjectPtr>& theFeatures);
 
   /// SLOT, Defines Sketch editing mode
-  void setSketchingMode();
+  /// \param thePln - plane of current sketch
+  void setSketchingMode(const gp_Pln& thePln);
 
   /// SLOT, to visualize the feature in another local context mode
   /// \param theFeature the feature to be put in another local context mode
@@ -139,6 +141,8 @@ Q_OBJECT
   //! Edits the feature
   void editFeature(FeaturePtr theFeature);
 
+  gp_Pln getSketchPlane(FeaturePtr theSketch) const;
+
  private:
   //XGUI_Workshop* myWorkshop;
   PartSet_Listener* myListener;
@@ -146,6 +150,7 @@ Q_OBJECT
   std::map<std::string, std::string> myFeaturesInFiles;
 
   Handle(StdSelect_FaceFilter) myPlaneFilter;
+  Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter;
 };
 
 #endif