1 // Copyright (C) 2014-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSet_Filters.h"
22 #include <ModuleBase_IWorkshop.h>
23 #include "ModuleBase_IModule.h"
24 #include <ModuleBase_ResultPrs.h>
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>
32 #include <AIS_InteractiveObject.hxx>
33 #include <AIS_Shape.hxx>
34 #include <AIS_Trihedron.hxx>
35 #include <AIS_ViewCube.hxx>
36 #include <StdSelect_BRepOwner.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(PartSet_GlobalFilter, ModuleBase_ShapeDocumentFilter);
41 PartSet_GlobalFilter::PartSet_GlobalFilter(ModuleBase_IWorkshop* theWorkshop)
42 : ModuleBase_ShapeDocumentFilter(theWorkshop)
44 addNonSelectableType(ModelAPI_ResultField::group().c_str());
45 addNonSelectableType(ModelAPI_ResultGroup::group().c_str());
49 Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
52 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
53 Handle(AIS_InteractiveObject) aAisObj;
54 if (theOwner->HasSelectable()) {
55 aAisObj = Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
56 if (!aAisObj.IsNull()) {
57 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
60 ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
61 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
65 // Workaround to enable View Cube and Trihedron selection
66 if (!aAisObj.IsNull()) {
67 if (aAisObj->IsKind(STANDARD_TYPE(AIS_Trihedron)) ||
68 aAisObj->IsKind(STANDARD_TYPE(AIS_ViewCube))) {
73 // Issue #3161: Do not use presentations for non-SHAPER objects
79 // the shapes from different documents should be provided if there is no started operation
80 // in order to show/hide results
83 if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) {
85 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
86 // result of parts belongs to PartSet document and can be selected only when PartSet
87 // is active in order to do not select the result of the active part.
89 std::string aResultGroupName = aResult->groupName();
90 if (aResultGroupName == ModelAPI_ResultPart::group()) {
91 SessionPtr aMgr = ModelAPI_Session::get();
92 aValid = aMgr->activeDocument() == aMgr->moduleDocument();
93 } else if (myNonSelectableTypes.contains(aResultGroupName.c_str())) {
94 aValid = Standard_False;
96 aValid = Standard_True;
98 else { // possibly this code is obsolete, as a feature object can be selected in recovery
99 // only and there can not be Group feature
100 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
102 aValid = !myNonSelectableTypes.contains(aFeature->getKind().c_str());
104 aValid = Standard_True;
107 // This is not object controlled by the filter
108 aValid = Standard_True;
112 qDebug(QString("PartSet_GlobalFilter::IsOk = %1").arg(aValid).toStdString().c_str());
117 IMPLEMENT_STANDARD_RTTIEXT(PartSet_ResultGroupNameFilter, SelectMgr_Filter);
119 void PartSet_ResultGroupNameFilter::setGroupNames(const std::set<std::string>& theGroupNames)
121 myGroupNames = theGroupNames;
124 Standard_Boolean PartSet_ResultGroupNameFilter::IsOk(
125 const Handle(SelectMgr_EntityOwner)& theOwner) const
127 std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
128 if (theOwner->HasSelectable()) {
129 Handle(AIS_InteractiveObject) aAisObj =
130 Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
131 if (!aAisObj.IsNull()) {
132 aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
135 ObjectPtr anObject = myWorkshop->findPresentedObject(aAISObj);
139 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
140 // result of parts belongs to PartSet document and can be selected only when PartSet
141 // is active in order to do not select the result of the active part.
145 std::string aGroupName = aResult->groupName();// == ModelAPI_ResultPart::group()) {
146 if (myGroupNames.find(aGroupName) != myGroupNames.end())
147 return false; // the object of the filtered type is found
153 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CirclePointFilter, SelectMgr_Filter);
156 PartSet_CirclePointFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
158 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
160 return Standard_True;
163 if(theOwner->HasSelectable() == Standard_False) {
164 return Standard_True;
167 Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
168 if(aBrepOwner.IsNull()) {
169 return Standard_True;
172 const TopoDS_Shape& aShape = aBrepOwner->Shape();
173 if(aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
174 return Standard_True;
177 Handle(ModuleBase_ResultPrs) aResultPrs =
178 Handle(ModuleBase_ResultPrs)::DownCast(theOwner->Selectable());
179 if(aResultPrs.IsNull()) {
180 return Standard_True;
183 std::shared_ptr<GeomAPI_AISObject> aGeomAISObj(new GeomAPI_AISObject());
184 aGeomAISObj->setImpl(new Handle(AIS_InteractiveObject)(aResultPrs));
185 ObjectPtr anObj = myWorkshop->findPresentedObject(aGeomAISObj);
187 return Standard_True;
190 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
192 return Standard_True;
195 DocumentPtr aDocument = aResult->document();
196 if(!aDocument.get()) {
197 return Standard_True;
200 FeaturePtr aFeature = aDocument->feature(aResult);
201 if(!aFeature.get() ||
202 ((aFeature->getKind() != "SketchCircle") &&
203 (aFeature->getKind() != "SketchBSplinePeriodic"))) {
204 return Standard_True;
207 const TopoDS_Shape anOwnerShape = aResultPrs->Shape();
208 if(anOwnerShape.ShapeType() == TopAbs_EDGE) {
209 return Standard_False;
213 qDebug(QString("PartSet_ShapeDocumentFilter::IsOk = %1").arg(aValid).toStdString().c_str());
216 return Standard_True;