1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeTarget.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDSImpl_AttributeTarget.hxx"
26 #include "SALOMEDSImpl_AttributeReference.hxx"
27 #include "SALOMEDSImpl_Study.hxx"
32 //=======================================================================
35 //=======================================================================
37 const std::string& SALOMEDSImpl_AttributeTarget::GetID ()
39 static std::string SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
40 return SALOMEDSImpl_AttributeTargetID;
44 //=======================================================================
47 //=======================================================================
49 SALOMEDSImpl_AttributeTarget* SALOMEDSImpl_AttributeTarget::Set (const DF_Label& L)
51 SALOMEDSImpl_AttributeTarget* A = NULL;
52 if (!(A=(SALOMEDSImpl_AttributeTarget*)L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
53 A = new SALOMEDSImpl_AttributeTarget();
60 //=======================================================================
61 //function : constructor
63 //=======================================================================
64 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
65 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
69 void SALOMEDSImpl_AttributeTarget::SetRelation(const std::string& theRelation)
72 if(myRelation == theRelation) return;
75 myRelation = theRelation;
77 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
80 //=======================================================================
83 //=======================================================================
84 void SALOMEDSImpl_AttributeTarget::Add(const SALOMEDSImpl_SObject& theSO)
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);
94 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
97 //=======================================================================
100 //=======================================================================
101 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_AttributeTarget::Get()
103 vector<SALOMEDSImpl_SObject> aSeq;
105 for(int i = 0, len = myVariables.size(); i<len; i++)
106 aSeq.push_back( SALOMEDSImpl_Study::SObject(myVariables[i]->Label()));
111 //=======================================================================
114 //=======================================================================
115 void SALOMEDSImpl_AttributeTarget::Remove(const SALOMEDSImpl_SObject& theSO)
118 DF_Label aRefLabel = theSO.GetLabel();
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]);
130 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
133 //=======================================================================
136 //=======================================================================
137 const std::string& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
139 //=======================================================================
142 //=======================================================================
143 void SALOMEDSImpl_AttributeTarget::Restore(DF_Attribute* With)
145 SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(With);
146 myRelation = REL->GetRelation();
148 for (int i = 0, len = REL->myVariables.size(); i<len; i++) {
149 myVariables.push_back(REL->myVariables[i]);
153 //=======================================================================
154 //function : NewEmpty
156 //=======================================================================
157 DF_Attribute* SALOMEDSImpl_AttributeTarget::NewEmpty() const
159 return new SALOMEDSImpl_AttributeTarget();
162 //=======================================================================
165 //=======================================================================
166 void SALOMEDSImpl_AttributeTarget::Paste(DF_Attribute* into)
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]);