1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeTarget.cxx
21 // Author : Sergey RUIN
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>
35 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
36 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
38 //=======================================================================
41 //=======================================================================
43 const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID ()
45 static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
46 return SALOMEDSImpl_AttributeTargetID;
50 //=======================================================================
53 //=======================================================================
55 Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L)
57 Handle(SALOMEDSImpl_AttributeTarget) A;
58 if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) {
59 A = new SALOMEDSImpl_AttributeTarget();
66 //=======================================================================
67 //function : constructor
69 //=======================================================================
70 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
71 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
75 void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation)
78 if(myRelation == theRelation) return;
81 myRelation = theRelation;
83 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
86 //=======================================================================
89 //=======================================================================
90 void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO)
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);
101 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
104 //=======================================================================
107 //=======================================================================
108 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get()
110 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
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));
120 //=======================================================================
123 //=======================================================================
124 void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO)
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);
136 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
139 //=======================================================================
142 //=======================================================================
143 const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
145 //=======================================================================
148 //=======================================================================
149 void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
151 Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With);
152 myRelation = REL->GetRelation();
153 Handle(SALOMEDSImpl_AttributeReference) V;
155 for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) {
156 V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
157 myVariables.Append(V);
161 //=======================================================================
162 //function : NewEmpty
164 //=======================================================================
165 Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
167 return new SALOMEDSImpl_AttributeTarget();
170 //=======================================================================
173 //=======================================================================
174 void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into,
175 const Handle(TDF_RelocationTable)& RT) const
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);