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