- if (theOwner->HasSelectable()) {
- Handle(AIS_InteractiveObject) aAisObj =
- Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
- if (!aAisObj.IsNull()) {
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
- ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
- if (aObj) {
- DocumentPtr aDoc = aObj->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- return (aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument());
+ bool aValid = true;
+
+ ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
+ // the shapes from different documents should be provided if there is no started operation
+ // in order to show/hide results
+ if (anOperation) {
+ aValid = Standard_False;
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ if (theOwner->HasSelectable()) {
+ Handle(AIS_InteractiveObject) aAisObj =
+ Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+ if (!aAisObj.IsNull()) {
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+ }
+ }
+ ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+ if (aObj) {
+ DocumentPtr aDoc = aObj->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aValid = (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument());
+ }
+ else {
+ // This object is not controlled by the filter
+ aValid = Standard_True;
+ }
+ }
+
+#ifdef DEBUG_FILTERS
+ qDebug(QString("ModuleBase_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
+#endif
+ return aValid;
+}
+
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ShapeInPlaneFilter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(
+ const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+ bool aValid = true;
+
+ if (myPlane.get()) {
+ aValid = Standard_False;
+ // selectable may be empty if the object is selected in Object Browser and is not visualized
+ // in the viewer(virtual owner is created for this case)
+ //if (theOwner->HasSelectable())
+ {
+ gp_Pln aPlane = myPlane->impl<gp_Pln>();
+ Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
+ if (!aShapeOwner.IsNull() && aShapeOwner->HasShape()) {
+ 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 aPlane.SquareDistance(aPnt) < Precision::SquareConfusion();
+ }
+ case TopAbs_EDGE:
+ {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
+ anEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
+ return anEdge->isInPlane(myPlane);
+ }
+ default:
+ // The object can be selected in Object browser and contain, for example, compound.
+ // The compound could not belong to any plane, so the result is false
+ aValid = Standard_False;
+ break;
+ }
+ } else {
+ if (theOwner->HasSelectable()) {
+ // Check Trihedron sub-objects
+ Handle(SelectMgr_SelectableObject) aSelObj = theOwner->Selectable();
+ Handle(Standard_Type) aType = aSelObj->DynamicType();
+ if (aType == STANDARD_TYPE(AIS_Trihedron)) {
+ Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aSelObj);
+ Handle(AIS_TrihedronOwner) aTrOwner = Handle(AIS_TrihedronOwner)::DownCast(theOwner);
+ if (!aTrOwner.IsNull()) {
+ const Prs3d_DatumParts& aPart = aTrOwner->DatumPart();
+ if (aPart >= Prs3d_DP_XAxis && aPart <= Prs3d_DP_ZAxis) {
+ gp_Ax2 anAxis = aTrihedron->Component()->Ax2();
+ gp_Dir aDir;
+ switch (aPart) {
+ case Prs3d_DP_XAxis:
+ aDir = anAxis.XDirection();
+ break;
+ case Prs3d_DP_YAxis:
+ aDir = anAxis.YDirection();
+ break;
+ case Prs3d_DP_ZAxis:
+ aDir = anAxis.Direction();
+ break;
+ }
+ gp_Lin aLine(aTrihedron->Component()->Location(), aDir);
+ return aPlane.Contains(aLine, Precision::Confusion(), Precision::Angular());
+ }
+ }
+ }
+ // This is not object controlled by the filter
+ aValid = Standard_True;
+ }