]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Filters.cpp
Salome HOME
Merge branch 'SALOME-8.2.0_porting'
[modules/shaper.git] / src / PartSet / PartSet_Filters.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_Filters.cpp
4 // Created:     08 Nov 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_Filters.h"
8
9 #include <ModuleBase_IWorkshop.h>
10 #include "ModuleBase_IModule.h"
11 #include <ModuleBase_ResultPrs.h>
12
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_ResultPart.h>
15 #include <ModelAPI_Session.h>
16
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_Shape.hxx>
19 #include <StdSelect_BRepOwner.hxx>
20
21
22 IMPLEMENT_STANDARD_RTTIEXT(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter);
23
24 Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
25 {
26   bool aValid = true;
27   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
28   // the shapes from different documents should be provided if there is no started operation
29   // in order to show/hide results
30   if (anOperation) {
31     aValid = false;
32     if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
33       std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
34       if (theOwner->HasSelectable()) {
35         Handle(AIS_InteractiveObject) aAisObj =
36           Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
37         if (!aAisObj.IsNull()) {
38           aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
39         }
40       }
41       ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
42       if (aObj) {
43         ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
44         // result of parts belongs to PartSet document and can be selected only when PartSet
45         //  is active in order to do not select the result of the active part.
46         if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group()) {
47           SessionPtr aMgr = ModelAPI_Session::get();
48           aValid = aMgr->activeDocument() == aMgr->moduleDocument();
49         }
50         else {
51           FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
52           if (aFeature) {
53             aValid = aFeature->getKind() != "Group";
54           } else
55             aValid = Standard_True;
56         }
57       } else
58         // This is not object controlled by the filter
59         aValid = Standard_True;
60     }
61   }
62 #ifdef DEBUG_FILTERS
63   qDebug(QString("PartSet_GlobalFilter::IsOk = %1").arg(aValid).toStdString().c_str());
64 #endif
65   return aValid;
66 }
67
68 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CirclePointFilter, SelectMgr_Filter);
69
70 Standard_Boolean
71   PartSet_CirclePointFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
72 {
73   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
74   if(!anOperation) {
75     return Standard_True;
76   }
77
78   if(theOwner->HasSelectable() == Standard_False) {
79     return Standard_True;
80   }
81
82   Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
83   if(aBrepOwner.IsNull()) {
84     return Standard_True;
85   }
86
87   const TopoDS_Shape& aShape = aBrepOwner->Shape();
88   if(aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
89     return Standard_True;
90   }
91
92   Handle(ModuleBase_ResultPrs) aResultPrs =
93     Handle(ModuleBase_ResultPrs)::DownCast(theOwner->Selectable());
94   if(aResultPrs.IsNull()) {
95     return Standard_True;
96   }
97
98   std::shared_ptr<GeomAPI_AISObject> aGeomAISObj(new GeomAPI_AISObject());
99   aGeomAISObj->setImpl(new Handle(AIS_InteractiveObject)(aResultPrs));
100   ObjectPtr anObj = myWorkshop->findPresentedObject(aGeomAISObj);
101   if(!anObj.get()) {
102     return Standard_True;
103   }
104
105   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
106   if(!aResult.get()) {
107     return Standard_True;
108   }
109
110   DocumentPtr aDocument = aResult->document();
111   if(!aDocument.get()) {
112     return Standard_True;
113   }
114
115   FeaturePtr aFeature = aDocument->feature(aResult);
116   if(!aFeature.get() || aFeature->getKind() != "SketchCircle") {
117     return Standard_True;
118   }
119
120   const TopoDS_Shape anOwnerShape = aResultPrs->Shape();
121   if(anOwnerShape.ShapeType() == TopAbs_EDGE) {
122     return Standard_False;
123   }
124
125 #ifdef DEBUG_FILTERS
126   qDebug(QString("PartSet_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
127 #endif
128
129   return Standard_True;
130 }