Salome HOME
Get rid of compilation warnings. Part II. MSVC warnings.
[modules/shaper.git] / src / Selector / Selector_Primitive.cpp
1 // Copyright (C) 2014-2020  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 <Selector_Primitive.h>
21
22 #include <Selector_NameGenerator.h>
23
24 #include <TNaming_NamedShape.hxx>
25 #include <TDataStd_Name.hxx>
26
27
28 Selector_Primitive::Selector_Primitive() : Selector_Algo()
29 {
30 }
31
32 void Selector_Primitive::select(const TDF_Label theFinalLabel)
33 {
34   myFinal = theFinalLabel;
35 }
36
37 void Selector_Primitive::store()
38 {
39   storeType(Selector_Algo::SELTYPE_PRIMITIVE);
40   static const TDF_LabelList anEmptyRefList;
41   storeBaseArray(anEmptyRefList, myFinal);
42 }
43
44 bool Selector_Primitive::restore()
45 {
46   static TDF_LabelList anEmptyRefList;
47   return restoreBaseArray(anEmptyRefList, myFinal);
48 }
49
50 TDF_Label Selector_Primitive::restoreByName(std::string theName,
51   const TopAbs_ShapeEnum /*theShapeType*/, Selector_NameGenerator* theNameGenerator)
52 {
53   TDF_Label aContext;
54   if (theNameGenerator->restoreContext(theName, aContext, myFinal)) {
55     if (myFinal.IsNull())
56       aContext.Nullify();
57   }
58   return aContext;
59 }
60
61 bool Selector_Primitive::solve(const TopoDS_Shape& theContext)
62 {
63   Handle(TNaming_NamedShape) aNS;
64   if (myFinal.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
65     TopoDS_Shape aResult = aNS->Get();
66     // if shape was modified and not exists in the context anymore, check evolution of this shape
67     // issue 2254 and similar (document CEA parametric first issue description)
68     findNewVersion(theContext, aResult);
69     Selector_Algo::store(aResult);
70     return true;
71   }
72   return false;
73 }
74
75 std::string Selector_Primitive::name(Selector_NameGenerator* theNameGenerator)
76 {
77   Handle(TDataStd_Name) aName;
78   if (!myFinal.FindAttribute(TDataStd_Name::GetID(), aName))
79     return "";
80   std::string aResult = theNameGenerator->contextName(myFinal);
81   if (!aResult.empty())
82     aResult += "/" + std::string(TCollection_AsciiString(aName->Get()).ToCString());
83   return aResult;
84 }