1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_AttributeTarget.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_AttributeTarget.hxx"
28 #include "SALOMEDSImpl_AttributeReference.hxx"
29 #include "SALOMEDSImpl_Study.hxx"
31 //=======================================================================
34 //=======================================================================
36 const std::string& SALOMEDSImpl_AttributeTarget::GetID ()
38 static std::string SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
39 return SALOMEDSImpl_AttributeTargetID;
43 //=======================================================================
46 //=======================================================================
48 SALOMEDSImpl_AttributeTarget* SALOMEDSImpl_AttributeTarget::Set (const DF_Label& L)
50 SALOMEDSImpl_AttributeTarget* A = NULL;
51 if (!(A=(SALOMEDSImpl_AttributeTarget*)L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
52 A = new SALOMEDSImpl_AttributeTarget();
59 //=======================================================================
60 //function : constructor
62 //=======================================================================
63 SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
64 :SALOMEDSImpl_GenericAttribute("AttributeTarget")
68 void SALOMEDSImpl_AttributeTarget::SetRelation(const std::string& theRelation)
71 if(myRelation == theRelation) return;
74 myRelation = theRelation;
76 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
79 //=======================================================================
82 //=======================================================================
83 void SALOMEDSImpl_AttributeTarget::Add(const SALOMEDSImpl_SObject& theSO)
86 DF_Label aRefLabel = theSO.GetLabel();
87 SALOMEDSImpl_AttributeReference* aReference;
88 if ((aReference=(SALOMEDSImpl_AttributeReference*)aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
89 myVariables[aRefLabel.Entry()]=aReference;
92 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
95 //=======================================================================
98 //=======================================================================
99 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_AttributeTarget::Get()
101 std::vector<SALOMEDSImpl_SObject> aSeq;
103 for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter)
104 aSeq.push_back( SALOMEDSImpl_Study::SObject(iter->second->Label()));
109 //=======================================================================
112 //=======================================================================
113 void SALOMEDSImpl_AttributeTarget::Remove(const SALOMEDSImpl_SObject& theSO)
116 DF_Label aRefLabel = theSO.GetLabel();
118 myVariables.erase(aRefLabel.Entry());
120 SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved
123 //=======================================================================
126 //=======================================================================
127 const std::string& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
129 //=======================================================================
132 //=======================================================================
133 void SALOMEDSImpl_AttributeTarget::Restore(DF_Attribute* With)
135 SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(With);
136 myRelation = REL->GetRelation();
138 for (std::map< std::string , DF_Attribute* >::iterator iter = REL->myVariables.begin(); iter != REL->myVariables.end(); ++iter){
139 myVariables[iter->first]=iter->second;
143 //=======================================================================
144 //function : NewEmpty
146 //=======================================================================
147 DF_Attribute* SALOMEDSImpl_AttributeTarget::NewEmpty() const
149 return new SALOMEDSImpl_AttributeTarget();
152 //=======================================================================
155 //=======================================================================
156 void SALOMEDSImpl_AttributeTarget::Paste(DF_Attribute* into)
158 SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(into);
159 REL->SetRelation(myRelation);
160 REL->myVariables.clear();
161 for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter){
162 REL->myVariables[iter->first]=iter->second;