1 // File : SALOMEDSImpl_AttributeTarget.cxx
2 // Author : Sergey RUIN
6 #include "SALOMEDSImpl_AttributeTarget.hxx"
7 #include "SALOMEDSImpl_AttributeReference.hxx"
8 #include "SALOMEDSImpl_Study.hxx"
9 #include <TDF_RelocationTable.hxx>
10 #include <TDF_ListIteratorOfAttributeList.hxx>
11 #include <Standard_GUID.hxx>
16 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
17 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
19 //=======================================================================
22 //=======================================================================
24 const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID ()
26 static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
27 return SALOMEDSImpl_AttributeTargetID;
31 //=======================================================================
34 //=======================================================================
36 Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L)
38 Handle(SALOMEDSImpl_AttributeTarget) A;
39 if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) {
40 A = new SALOMEDSImpl_AttributeTarget();
47 //=======================================================================
48 //function : constructor
50 //=======================================================================
51 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
52 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
56 void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation)
59 if(myRelation == theRelation) return;
62 myRelation = theRelation;
64 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
67 //=======================================================================
70 //=======================================================================
71 void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO)
74 TDF_Label aRefLabel = theSO->GetLabel();
75 Handle(SALOMEDSImpl_AttributeReference) aReference;
76 if (aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),aReference)) {
77 TDF_ListIteratorOfAttributeList anIter(GetVariables());
78 for(;anIter.More();anIter.Next()) if(anIter.Value()->Label() == aRefLabel) return; //BugID: PAL6192
79 GetVariables().Append(aReference);
82 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
85 //=======================================================================
88 //=======================================================================
89 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get()
91 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
93 TDF_ListIteratorOfAttributeList anIter(GetVariables());
94 for(;anIter.More();anIter.Next()) {
95 const TDF_Label& aLabel = anIter.Value()->Label();
96 aSeq->Append( SALOMEDSImpl_Study::SObject(aLabel));
101 //=======================================================================
104 //=======================================================================
105 void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO)
108 TDF_Label aRefLabel = theSO->GetLabel();
109 TDF_ListIteratorOfAttributeList anIter(GetVariables());
110 for(;anIter.More();anIter.Next()) {
111 if (anIter.Value()->Label() == aRefLabel) {
112 GetVariables().Remove(anIter);
117 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
120 //=======================================================================
123 //=======================================================================
124 const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
126 //=======================================================================
129 //=======================================================================
130 void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
132 Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With);
133 myRelation = REL->GetRelation();
134 Handle(SALOMEDSImpl_AttributeReference) V;
136 for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) {
137 V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
138 myVariables.Append(V);
142 //=======================================================================
143 //function : NewEmpty
145 //=======================================================================
146 Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
148 return new SALOMEDSImpl_AttributeTarget();
151 //=======================================================================
154 //=======================================================================
155 void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into,
156 const Handle(TDF_RelocationTable)& RT) const
158 Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (Into);
159 REL->SetRelation(myRelation);
160 Handle(SALOMEDSImpl_AttributeReference) V1,V2;
161 for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) {
162 V1 = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
163 RT->HasRelocation (V1,V2);
164 REL->GetVariables().Append(V2);