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