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