1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 //NOTE: This is an intreface to a function for the Transfer Data functionality.
27 #include "GEOMImpl_ITransferData.hxx"
29 #include <TDataStd_Comment.hxx>
30 #include <TDataStd_Name.hxx>
31 #include <TDF_ChildIDIterator.hxx>
32 #include <TNaming_Builder.hxx>
33 #include <TNaming_NamedShape.hxx>
36 //=============================================================================
40 //=============================================================================
41 void GEOMImpl_ITransferData::SetStringData
42 (const TopoDS_Shape &theSubShape,
43 const TCollection_AsciiString &theData,
44 const Standard_Boolean IsName)
47 TDF_ChildIDIterator anIt
48 (_func->GetNamingEntry(), TDataStd_Name::GetID(), Standard_True);
50 for (; anIt.More(); anIt.Next()) {
51 Handle(TDataStd_Name) aNameAttr =
52 Handle(TDataStd_Name)::DownCast(anIt.Value());
54 if (aNameAttr.IsNull()) {
58 TDF_Label aLab = aNameAttr->Label();
59 Handle(TNaming_NamedShape) aShAttr;
61 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aShAttr) &&
62 aShAttr->Get().IsEqual(theSubShape)) {
68 if (aLabel.IsNull()) {
71 aLabel = aTag.NewChild(_func->GetNamingEntry());
73 TNaming_Builder aTnBuild (aLabel);
75 aTnBuild.Generated(theSubShape);
78 // set a name or a material
79 TCollection_ExtendedString aDataExt(theData);
82 TDataStd_Name::Set(aLabel, aDataExt);
84 TDataStd_Comment::Set(aLabel, aDataExt);
88 //=============================================================================
92 //=============================================================================
93 TCollection_AsciiString GEOMImpl_ITransferData::GetStringData
94 (const TopoDS_Shape &theSubShape,
95 const Standard_Boolean IsName)
97 // check all named shapes using iterator
98 TCollection_AsciiString aResult;
99 TDF_ChildIDIterator anIt
100 (_func->GetNamingEntry(), TNaming_NamedShape::GetID(), Standard_True);
102 for (; anIt.More(); anIt.Next()) {
103 Handle(TNaming_NamedShape) aShAttr =
104 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
106 if (aShAttr.IsNull()) {
110 if (aShAttr->Get().IsEqual(theSubShape)) {
111 TDF_Label aLabel = aShAttr->Label();
112 Standard_Boolean isFound = Standard_False;
115 Handle(TDataStd_Name) aString;
117 if(aLabel.FindAttribute(TDataStd_Name::GetID(), aString)) {
118 aResult = TCollection_AsciiString(aString->Get());
119 isFound = Standard_True;
122 Handle(TDataStd_Comment) aString;
124 if(aLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) {
125 aResult = TCollection_AsciiString(aString->Get());
126 isFound = Standard_True;