#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);
}
}
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;
+}
#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:
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
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
#include <XGUI_MainWindow.h>
#include <XGUI_Displayer.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
if (aSketchOp->isEditOperation()) {
- setSketchingMode();
+ setSketchingMode(getSketchPlane(aSketchOp->feature()));
} else {
aDisplayer->openLocalContext();
aDisplayer->activateObjectsOutOfContext(QIntList());
{
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()
aDisplayer->updateViewer();
}
-void PartSet_Module::setSketchingMode()
+void PartSet_Module::setSketchingMode(const gp_Pln& thePln)
{
XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
if (!myPlaneFilter.IsNull()) {
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)
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);
+}
+
#include <ModuleBase_IModule.h>
#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ViewerFilters.h>
#include <XGUI_Command.h>
#include <ModelAPI_Feature.h>
#include <StdSelect_FaceFilter.hxx>
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
//! Edits the feature
void editFeature(FeaturePtr theFeature);
+ gp_Pln getSketchPlane(FeaturePtr theSketch) const;
+
private:
//XGUI_Workshop* myWorkshop;
PartSet_Listener* myListener;
std::map<std::string, std::string> myFeaturesInFiles;
Handle(StdSelect_FaceFilter) myPlaneFilter;
+ Handle(ModuleBase_ShapeInPlaneFilter) mySketchFilter;
};
#endif