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