Salome HOME
Merging from V3_2_6pre4
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeTarget.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_AttributeTarget.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25 #include "SALOMEDSImpl_AttributeTarget.hxx"
26 #include "SALOMEDSImpl_AttributeReference.hxx"
27 #include "SALOMEDSImpl_Study.hxx"
28 #include <TDF_RelocationTable.hxx>
29 #include <TDF_ListIteratorOfAttributeList.hxx>
30 #include <Standard_GUID.hxx>
31
32 using namespace std;
33
34
35 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
36 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
37
38 //=======================================================================
39 //function : GetID
40 //purpose  : 
41 //=======================================================================
42
43 const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID () 
44 {
45   static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
46   return SALOMEDSImpl_AttributeTargetID;
47 }
48
49
50 //=======================================================================
51 //function : Set
52 //purpose  : 
53 //=======================================================================
54
55 Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L) 
56 {
57   Handle(SALOMEDSImpl_AttributeTarget) A;
58   if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) {
59     A = new  SALOMEDSImpl_AttributeTarget(); 
60     L.AddAttribute(A);
61   }
62   return A;
63 }
64
65
66 //=======================================================================
67 //function : constructor
68 //purpose  : 
69 //=======================================================================
70 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
71 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
72 {
73 }
74
75 void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation)
76 {
77   CheckLocked();
78   if(myRelation == theRelation) return;
79
80   Backup();
81   myRelation = theRelation; 
82   
83   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
84 }
85
86 //=======================================================================
87 //function : Add
88 //purpose  : 
89 //=======================================================================
90 void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO) 
91 {
92   Backup();
93   TDF_Label aRefLabel = theSO->GetLabel();
94   Handle(SALOMEDSImpl_AttributeReference) aReference;
95   if (aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),aReference)) {
96     TDF_ListIteratorOfAttributeList anIter(GetVariables());
97     for(;anIter.More();anIter.Next()) if(anIter.Value()->Label() == aRefLabel) return; //BugID: PAL6192    
98     GetVariables().Append(aReference);
99   } 
100   
101   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
102 }
103
104 //=======================================================================
105 //function : Get
106 //purpose  : 
107 //=======================================================================
108 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get() 
109 {
110   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
111   
112   TDF_ListIteratorOfAttributeList anIter(GetVariables());
113   for(;anIter.More();anIter.Next()) {
114     const TDF_Label& aLabel = anIter.Value()->Label();
115    aSeq->Append( SALOMEDSImpl_Study::SObject(aLabel));
116   }
117   return aSeq;
118 }
119
120 //=======================================================================
121 //function : Remove
122 //purpose  : 
123 //=======================================================================
124 void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO) 
125 {
126   Backup();
127   TDF_Label aRefLabel = theSO->GetLabel();
128   TDF_ListIteratorOfAttributeList anIter(GetVariables());
129   for(;anIter.More();anIter.Next()) {
130     if (anIter.Value()->Label() == aRefLabel) {
131       GetVariables().Remove(anIter);
132       return;
133     }
134   }  
135   
136   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
137 }
138
139 //=======================================================================
140 //function : ID
141 //purpose  : 
142 //=======================================================================
143 const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
144
145 //=======================================================================
146 //function : Restore
147 //purpose  :
148 //=======================================================================
149 void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
150 {
151   Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With);
152   myRelation = REL->GetRelation();
153   Handle(SALOMEDSImpl_AttributeReference) V;
154   myVariables.Clear();
155   for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) {
156     V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
157     myVariables.Append(V);
158   }
159 }
160
161 //=======================================================================
162 //function : NewEmpty
163 //purpose  :
164 //=======================================================================
165 Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
166 {
167   return new SALOMEDSImpl_AttributeTarget();
168 }
169
170 //=======================================================================
171 //function : Paste
172 //purpose  :
173 //=======================================================================
174 void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into,
175                                          const Handle(TDF_RelocationTable)& RT) const
176 {
177   Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (Into);
178   REL->SetRelation(myRelation);
179   Handle(SALOMEDSImpl_AttributeReference) V1,V2;
180   for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) {
181     V1 = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
182     RT->HasRelocation (V1,V2);
183     REL->GetVariables().Append(V2);
184   }
185 }