1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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 <Selector_Selector.h>
22 #include <Selector_NameGenerator.h>
23 #include <Selector_Algo.h>
25 #include <TopTools_MapOfShape.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <TopoDS_Builder.hxx>
28 #include <TopoDS_Compound.hxx>
29 #include <TNaming_NamedShape.hxx>
31 Selector_Selector::Selector_Selector(TDF_Label theLab, TDF_Label theBaseDocLab) :
32 myLab(theLab), myBaseDocumentLab(theBaseDocLab), myAlgo(NULL)
35 Selector_Selector::~Selector_Selector()
41 bool Selector_Selector::select(const TopoDS_Shape theContext, const TopoDS_Shape theValue,
42 const bool theGeometricalNaming)
44 if (theValue.IsNull() || theContext.IsNull())
47 myAlgo = Selector_Algo::select(theContext, theValue, myLab, myBaseDocumentLab,
48 theGeometricalNaming, true, true);
50 return myAlgo != NULL;
53 bool Selector_Selector::store(const TopoDS_Shape theContext)
56 return myAlgo->solve(theContext); // to update the selection shape on the label
59 bool Selector_Selector::restore(const TopoDS_Shape theContext)
61 myAlgo = Selector_Algo::restoreByLab(myLab, myBaseDocumentLab);
63 return myAlgo->solve(theContext); // to update the selection shape on the label
68 TopoDS_Shape Selector_Selector::value()
70 Handle(TNaming_NamedShape) aNS;
71 if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aNS))
73 return TopoDS_Shape(); // empty, error shape
76 std::wstring Selector_Selector::name(Selector_NameGenerator* theNameGenerator) {
77 return myAlgo->name(theNameGenerator);
80 TDF_Label Selector_Selector::restoreByName(
81 std::wstring theName, const TopAbs_ShapeEnum theShapeType,
82 Selector_NameGenerator* theNameGenerator, const bool theGeometricalNaming)
85 myAlgo = Selector_Algo::restoreByName(myLab, myBaseDocumentLab, theName, theShapeType,
86 theGeometricalNaming, theNameGenerator, aResult);
93 void Selector_Selector::combineGeometrical(const TopoDS_Shape theContext)
95 TopoDS_Shape aValue = value();
96 if (aValue.IsNull() || aValue.ShapeType() == TopAbs_COMPOUND)
99 Selector_Algo* aNewAlgo = Selector_Algo::relesectWithAllGeometry(myAlgo, theContext);
102 aNewAlgo->solve(theContext);
108 bool Selector_Selector::solve(const TopoDS_Shape theContext)
110 return myAlgo->solve(theContext);