]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx
Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeTarget.cxx
1 //  File   : SALOMEDSImpl_AttributeTarget.cxx
2 //  Author : Sergey RUIN
3 //  Module : SALOME
4
5
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>
12
13 using namespace std;
14
15
16 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
17 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
18
19 //=======================================================================
20 //function : GetID
21 //purpose  : 
22 //=======================================================================
23
24 const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID () 
25 {
26   static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
27   return SALOMEDSImpl_AttributeTargetID;
28 }
29
30
31 //=======================================================================
32 //function : Set
33 //purpose  : 
34 //=======================================================================
35
36 Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L) 
37 {
38   Handle(SALOMEDSImpl_AttributeTarget) A;
39   if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) {
40     A = new  SALOMEDSImpl_AttributeTarget(); 
41     L.AddAttribute(A);
42   }
43   return A;
44 }
45
46
47 //=======================================================================
48 //function : constructor
49 //purpose  : 
50 //=======================================================================
51 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
52 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
53 {
54 }
55
56 void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation)
57 {
58   CheckLocked();
59   if(myRelation == theRelation) return;
60
61   Backup();
62   myRelation = theRelation; 
63   
64   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
65 }
66
67 //=======================================================================
68 //function : Add
69 //purpose  : 
70 //=======================================================================
71 void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO) 
72 {
73   Backup();
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);
80   } 
81   
82   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
83 }
84
85 //=======================================================================
86 //function : Get
87 //purpose  : 
88 //=======================================================================
89 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get() 
90 {
91   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
92   
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));
97   }
98   return aSeq;
99 }
100
101 //=======================================================================
102 //function : Remove
103 //purpose  : 
104 //=======================================================================
105 void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO) 
106 {
107   Backup();
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);
113       return;
114     }
115   }  
116   
117   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
118 }
119
120 //=======================================================================
121 //function : ID
122 //purpose  : 
123 //=======================================================================
124 const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
125
126 //=======================================================================
127 //function : Restore
128 //purpose  :
129 //=======================================================================
130 void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
131 {
132   Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With);
133   myRelation = REL->GetRelation();
134   Handle(SALOMEDSImpl_AttributeReference) V;
135   myVariables.Clear();
136   for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) {
137     V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
138     myVariables.Append(V);
139   }
140 }
141
142 //=======================================================================
143 //function : NewEmpty
144 //purpose  :
145 //=======================================================================
146 Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
147 {
148   return new SALOMEDSImpl_AttributeTarget();
149 }
150
151 //=======================================================================
152 //function : Paste
153 //purpose  :
154 //=======================================================================
155 void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into,
156                                          const Handle(TDF_RelocationTable)& RT) const
157 {
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);
165   }
166 }