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