Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_TargetAttribute.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS_TargetAttribute.cxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SALOMEDS_TargetAttribute.ixx"
30 #include <TDF_Reference.hxx>
31 #include <TDF_ListIteratorOfAttributeList.hxx>
32 #include "utilities.h"
33 using namespace std;
34
35 //=======================================================================
36 //function : GetID
37 //purpose  : 
38 //=======================================================================
39
40 const Standard_GUID& SALOMEDS_TargetAttribute::GetID () 
41 {
42   static Standard_GUID SALOMEDS_TargetAttributeID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
43   return SALOMEDS_TargetAttributeID;
44 }
45
46
47
48 //=======================================================================
49 //function : Set
50 //purpose  : 
51 //=======================================================================
52
53 Handle(SALOMEDS_TargetAttribute) SALOMEDS_TargetAttribute::Set (const TDF_Label& L) 
54 {
55   Handle(SALOMEDS_TargetAttribute) A;
56   if (!L.FindAttribute(SALOMEDS_TargetAttribute::GetID(),A)) {
57     A = new  SALOMEDS_TargetAttribute(); 
58     L.AddAttribute(A);
59   }
60   return A;
61 }
62
63
64 //=======================================================================
65 //function : constructor
66 //purpose  : 
67 //=======================================================================
68 SALOMEDS_TargetAttribute::SALOMEDS_TargetAttribute()
69 {}
70
71 //=======================================================================
72 //function : Append
73 //purpose  : 
74 //=======================================================================
75
76 void SALOMEDS_TargetAttribute::Append(TDF_Label& theReferencedObject) {
77   Backup();
78   Handle(TDF_Reference) aReference;
79   if (theReferencedObject.FindAttribute(TDF_Reference::GetID(),aReference)) {
80     TDF_ListIteratorOfAttributeList anIter(GetVariables());
81     for(;anIter.More();anIter.Next()) if(anIter.Value()->Label() == theReferencedObject) return; //BugID: PAL6192    
82     GetVariables().Append(aReference);
83   } else {
84     MESSAGE("SALOMEDS_TargetAttribute::Append: can't append referenced object");
85   }
86 }
87
88 //=======================================================================
89 //function : Get
90 //purpose  : 
91 //=======================================================================
92 void SALOMEDS_TargetAttribute::Get(TDF_LabelList& theReferencedObjects) {
93   theReferencedObjects.Clear();
94   TDF_ListIteratorOfAttributeList anIter(GetVariables());
95   for(;anIter.More();anIter.Next()) {
96     theReferencedObjects.Append(anIter.Value()->Label());
97   }
98 }
99
100 //=======================================================================
101 //function : Remove
102 //purpose  : 
103 //=======================================================================
104 void SALOMEDS_TargetAttribute::Remove(TDF_Label& theReferencedObject) {
105   Backup();
106   TDF_ListIteratorOfAttributeList anIter(GetVariables());
107   for(;anIter.More();anIter.Next()) {
108     if (anIter.Value()->Label() == theReferencedObject) {
109       GetVariables().Remove(anIter);
110       return;
111     }
112   }  
113   MESSAGE("SALOMEDS_TargetAttribute::Remove: nothing to remove");
114 }
115
116 //=======================================================================
117 //function : ID
118 //purpose  : 
119 //=======================================================================
120
121 const Standard_GUID& SALOMEDS_TargetAttribute::ID () const { return GetID(); }
122