Salome HOME
A patch from Paul RASCLE for: kernel documentation with doxygen, modification on...
[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
29 using namespace std;
30
31
32 //=======================================================================
33 //function : GetID
34 //purpose  : 
35 //=======================================================================
36
37 const std::string& SALOMEDSImpl_AttributeTarget::GetID () 
38 {
39   static std::string SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
40   return SALOMEDSImpl_AttributeTargetID;
41 }
42
43
44 //=======================================================================
45 //function : Set
46 //purpose  : 
47 //=======================================================================
48
49 SALOMEDSImpl_AttributeTarget* SALOMEDSImpl_AttributeTarget::Set (const DF_Label& L) 
50 {
51   SALOMEDSImpl_AttributeTarget* A = NULL;
52   if (!(A=(SALOMEDSImpl_AttributeTarget*)L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
53     A = new  SALOMEDSImpl_AttributeTarget(); 
54     L.AddAttribute(A);
55   }
56   return A;
57 }
58
59
60 //=======================================================================
61 //function : constructor
62 //purpose  : 
63 //=======================================================================
64 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
65 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
66 {
67 }
68
69 void SALOMEDSImpl_AttributeTarget::SetRelation(const std::string& theRelation)
70 {
71   CheckLocked();
72   if(myRelation == theRelation) return;
73
74   Backup();
75   myRelation = theRelation; 
76   
77   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
78 }
79
80 //=======================================================================
81 //function : Add
82 //purpose  : 
83 //=======================================================================
84 void SALOMEDSImpl_AttributeTarget::Add(const SALOMEDSImpl_SObject& theSO) 
85 {
86   Backup();
87   DF_Label aRefLabel = theSO.GetLabel();
88   SALOMEDSImpl_AttributeReference* aReference;
89   if ((aReference=(SALOMEDSImpl_AttributeReference*)aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
90     for(int i = 0, len = myVariables.size(); i<len; i++) if(myVariables[i]->Label() == aRefLabel) return; //BugID: PAL6192    
91     myVariables.push_back(aReference);
92   } 
93   
94   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
95 }
96
97 //=======================================================================
98 //function : Get
99 //purpose  : 
100 //=======================================================================
101 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_AttributeTarget::Get() 
102 {
103   vector<SALOMEDSImpl_SObject> aSeq;
104   
105   for(int i = 0, len = myVariables.size(); i<len; i++) 
106     aSeq.push_back( SALOMEDSImpl_Study::SObject(myVariables[i]->Label()));
107   
108   return aSeq;
109 }
110
111 //=======================================================================
112 //function : Remove
113 //purpose  : 
114 //=======================================================================
115 void SALOMEDSImpl_AttributeTarget::Remove(const SALOMEDSImpl_SObject& theSO) 
116 {
117   Backup();
118   DF_Label aRefLabel = theSO.GetLabel();
119
120   vector<DF_Attribute*> va;
121   for(int i = 0, len = myVariables.size(); i<len; i++) {
122     DF_Label L = myVariables[i]->Label();
123     if(myVariables[i]->Label() == aRefLabel) continue;
124     va.push_back(myVariables[i]);       
125   }
126
127   myVariables.clear();
128   myVariables = va;    
129   
130   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
131 }
132
133 //=======================================================================
134 //function : ID
135 //purpose  : 
136 //=======================================================================
137 const std::string& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
138
139 //=======================================================================
140 //function : Restore
141 //purpose  :
142 //=======================================================================
143 void SALOMEDSImpl_AttributeTarget::Restore(DF_Attribute* With)
144 {
145   SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(With);
146   myRelation = REL->GetRelation();
147   myVariables.clear();
148   for (int i = 0, len = REL->myVariables.size(); i<len; i++) {
149     myVariables.push_back(REL->myVariables[i]);
150   }
151 }
152
153 //=======================================================================
154 //function : NewEmpty
155 //purpose  :
156 //=======================================================================
157 DF_Attribute* SALOMEDSImpl_AttributeTarget::NewEmpty() const
158 {
159   return new SALOMEDSImpl_AttributeTarget();
160 }
161
162 //=======================================================================
163 //function : Paste
164 //purpose  :
165 //=======================================================================
166 void SALOMEDSImpl_AttributeTarget::Paste(DF_Attribute* into)
167 {
168   SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(into);
169   REL->SetRelation(myRelation);
170   REL->myVariables.clear();
171   for (int i = 0, len = myVariables.size(); i<len; i++) {
172     REL->myVariables.push_back(myVariables[i]);
173   }  
174 }