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