]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Filters.cpp
Salome HOME
Merge remote-tracking branch 'remotes/origin/Operations_on_Groups'
[modules/shaper.git] / src / PartSet / PartSet_Filters.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PartSet_Filters.h"
21
22 #include <ModuleBase_IWorkshop.h>
23 #include "ModuleBase_IModule.h"
24 #include <ModuleBase_ResultPrs.h>
25
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_ResultPart.h>
28 #include <ModelAPI_ResultGroup.h>
29 #include <ModelAPI_ResultField.h>
30 #include <ModelAPI_Session.h>
31
32 #include <AIS_InteractiveObject.hxx>
33 #include <AIS_Shape.hxx>
34 #include <StdSelect_BRepOwner.hxx>
35
36
37 IMPLEMENT_STANDARD_RTTIEXT(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter);
38
39 Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
40 {
41   bool aValid = true;
42   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
43   // the shapes from different documents should be provided if there is no started operation
44   // in order to show/hide results
45   if (anOperation) {
46     aValid = false;
47     if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
48       std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
49       if (theOwner->HasSelectable()) {
50         Handle(AIS_InteractiveObject) aAisObj =
51           Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
52         if (!aAisObj.IsNull()) {
53           aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
54         }
55       }
56       ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
57       if (aObj) {
58         ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
59         // result of parts belongs to PartSet document and can be selected only when PartSet
60         //  is active in order to do not select the result of the active part.
61         if (aResult.get()) {
62           std::string aResultGroupName = aResult->groupName();
63           if (aResultGroupName == ModelAPI_ResultPart::group()) {
64             SessionPtr aMgr = ModelAPI_Session::get();
65             aValid = aMgr->activeDocument() == aMgr->moduleDocument();
66           } else if (aResultGroupName == ModelAPI_ResultField::group()) {
67             aValid = Standard_False;
68           } else
69             aValid = Standard_True;
70         }
71         else { // possibly this code is obsolete, as a feature object can be selected in recovery
72           // only and there can not be Group feature
73           FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
74           if (aFeature) {
75             aValid = aFeature->getKind() != "Group";
76           } else
77             aValid = Standard_True;
78         }
79       } else
80         // This is not object controlled by the filter
81         aValid = Standard_True;
82     }
83   }
84 #ifdef DEBUG_FILTERS
85   qDebug(QString("PartSet_GlobalFilter::IsOk = %1").arg(aValid).toStdString().c_str());
86 #endif
87   return aValid;
88 }
89
90 IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultGroupNameFilter, SelectMgr_Filter);
91
92 void PartSet_ResultGroupNameFilter::setGroupNames(const std::set<std::string>& theGroupNames)
93 {
94   myGroupNames = theGroupNames;
95 }
96
97 Standard_Boolean PartSet_ResultGroupNameFilter::IsOk(
98   const Handle(SelectMgr_EntityOwner)& theOwner) const
99 {
100   std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
101   if (theOwner->HasSelectable()) {
102     Handle(AIS_InteractiveObject) aAisObj =
103       Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
104     if (!aAisObj.IsNull()) {
105       aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
106     }
107   }
108   ObjectPtr anObject = myWorkshop->findPresentedObject(aAISObj);
109   if (!anObject.get())
110     return true;
111
112   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
113   // result of parts belongs to PartSet document and can be selected only when PartSet
114   //  is active in order to do not select the result of the active part.
115   if (!aResult.get())
116     return true;
117
118   std::string aGroupName = aResult->groupName();// == ModelAPI_ResultPart::group()) {
119   if (myGroupNames.find(aGroupName) != myGroupNames.end())
120     return false; // the object of the filtered type is found
121
122   return true;
123 }
124
125
126 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CirclePointFilter, SelectMgr_Filter);
127
128 Standard_Boolean
129   PartSet_CirclePointFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
130 {
131   ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
132   if(!anOperation) {
133     return Standard_True;
134   }
135
136   if(theOwner->HasSelectable() == Standard_False) {
137     return Standard_True;
138   }
139
140   Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
141   if(aBrepOwner.IsNull()) {
142     return Standard_True;
143   }
144
145   const TopoDS_Shape& aShape = aBrepOwner->Shape();
146   if(aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
147     return Standard_True;
148   }
149
150   Handle(ModuleBase_ResultPrs) aResultPrs =
151     Handle(ModuleBase_ResultPrs)::DownCast(theOwner->Selectable());
152   if(aResultPrs.IsNull()) {
153     return Standard_True;
154   }
155
156   std::shared_ptr<GeomAPI_AISObject> aGeomAISObj(new GeomAPI_AISObject());
157   aGeomAISObj->setImpl(new Handle(AIS_InteractiveObject)(aResultPrs));
158   ObjectPtr anObj = myWorkshop->findPresentedObject(aGeomAISObj);
159   if(!anObj.get()) {
160     return Standard_True;
161   }
162
163   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
164   if(!aResult.get()) {
165     return Standard_True;
166   }
167
168   DocumentPtr aDocument = aResult->document();
169   if(!aDocument.get()) {
170     return Standard_True;
171   }
172
173   FeaturePtr aFeature = aDocument->feature(aResult);
174   if(!aFeature.get() || aFeature->getKind() != "SketchCircle") {
175     return Standard_True;
176   }
177
178   const TopoDS_Shape anOwnerShape = aResultPrs->Shape();
179   if(anOwnerShape.ShapeType() == TopAbs_EDGE) {
180     return Standard_False;
181   }
182
183 #ifdef DEBUG_FILTERS
184   qDebug(QString("PartSet_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
185 #endif
186
187   return Standard_True;
188 }