Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributeTarget.cxx
index b12c6537fa4e18781595085b132a0e2e31a802d1..e47d731f1c462d50410a4b193632f7a310f458cf 100644 (file)
@@ -1,29 +1,41 @@
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 //  File   : SALOMEDSImpl_AttributeTarget.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
+//
 #include "SALOMEDSImpl_AttributeTarget.hxx"
 #include "SALOMEDSImpl_AttributeReference.hxx"
 #include "SALOMEDSImpl_Study.hxx"
-#include <TDF_RelocationTable.hxx>
-#include <TDF_ListIteratorOfAttributeList.hxx>
-#include <Standard_GUID.hxx>
-
-using namespace std;
-
-
-IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
-IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute )
 
 //=======================================================================
 //function : GetID
 //purpose  : 
 //=======================================================================
 
-const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID () 
+const std::string& SALOMEDSImpl_AttributeTarget::GetID () 
 {
-  static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
+  static std::string SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F");
   return SALOMEDSImpl_AttributeTargetID;
 }
 
@@ -33,10 +45,10 @@ const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID ()
 //purpose  : 
 //=======================================================================
 
-Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L) 
+SALOMEDSImpl_AttributeTarget* SALOMEDSImpl_AttributeTarget::Set (const DF_Label& L) 
 {
-  Handle(SALOMEDSImpl_AttributeTarget) A;
-  if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) {
+  SALOMEDSImpl_AttributeTarget* A = NULL;
+  if (!(A=(SALOMEDSImpl_AttributeTarget*)L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
     A = new  SALOMEDSImpl_AttributeTarget(); 
     L.AddAttribute(A);
   }
@@ -53,7 +65,7 @@ SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget()
 {
 }
 
-void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation)
+void SALOMEDSImpl_AttributeTarget::SetRelation(const std::string& theRelation)
 {
   CheckLocked();
   if(myRelation == theRelation) return;
@@ -68,15 +80,13 @@ void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString&
 //function : Add
 //purpose  : 
 //=======================================================================
-void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO) 
+void SALOMEDSImpl_AttributeTarget::Add(const SALOMEDSImpl_SObject& theSO) 
 {
   Backup();
-  TDF_Label aRefLabel = theSO->GetLabel();
-  Handle(SALOMEDSImpl_AttributeReference) aReference;
-  if (aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),aReference)) {
-    TDF_ListIteratorOfAttributeList anIter(GetVariables());
-    for(;anIter.More();anIter.Next()) if(anIter.Value()->Label() == aRefLabel) return; //BugID: PAL6192    
-    GetVariables().Append(aReference);
+  DF_Label aRefLabel = theSO.GetLabel();
+  SALOMEDSImpl_AttributeReference* aReference;
+  if ((aReference=(SALOMEDSImpl_AttributeReference*)aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
+    myVariables[aRefLabel.Entry()]=aReference;
   } 
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
@@ -86,15 +96,13 @@ void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO
 //function : Get
 //purpose  : 
 //=======================================================================
-Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get() 
+std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_AttributeTarget::Get() 
 {
-  Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
+  std::vector<SALOMEDSImpl_SObject> aSeq;
+  
+  for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter)
+    aSeq.push_back( SALOMEDSImpl_Study::SObject(iter->second->Label()));
   
-  TDF_ListIteratorOfAttributeList anIter(GetVariables());
-  for(;anIter.More();anIter.Next()) {
-    const TDF_Label& aLabel = anIter.Value()->Label();
-   aSeq->Append( SALOMEDSImpl_Study::SObject(aLabel));
-  }
   return aSeq;
 }
 
@@ -102,17 +110,12 @@ Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get()
 //function : Remove
 //purpose  : 
 //=======================================================================
-void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO) 
+void SALOMEDSImpl_AttributeTarget::Remove(const SALOMEDSImpl_SObject& theSO) 
 {
   Backup();
-  TDF_Label aRefLabel = theSO->GetLabel();
-  TDF_ListIteratorOfAttributeList anIter(GetVariables());
-  for(;anIter.More();anIter.Next()) {
-    if (anIter.Value()->Label() == aRefLabel) {
-      GetVariables().Remove(anIter);
-      return;
-    }
-  }  
+  DF_Label aRefLabel = theSO.GetLabel();
+
+  myVariables.erase(aRefLabel.Entry());
   
   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
 }
@@ -121,21 +124,19 @@ void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& th
 //function : ID
 //purpose  : 
 //=======================================================================
-const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
+const std::string& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); }
 
 //=======================================================================
 //function : Restore
 //purpose  :
 //=======================================================================
-void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
+void SALOMEDSImpl_AttributeTarget::Restore(DF_Attribute* With)
 {
-  Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With);
+  SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(With);
   myRelation = REL->GetRelation();
-  Handle(SALOMEDSImpl_AttributeReference) V;
-  myVariables.Clear();
-  for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) {
-    V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
-    myVariables.Append(V);
+  myVariables.clear();
+  for (std::map< std::string , DF_Attribute* >::iterator iter = REL->myVariables.begin(); iter != REL->myVariables.end(); ++iter){
+    myVariables[iter->first]=iter->second;
   }
 }
 
@@ -143,7 +144,7 @@ void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With)
 //function : NewEmpty
 //purpose  :
 //=======================================================================
-Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
+DF_Attribute* SALOMEDSImpl_AttributeTarget::NewEmpty() const
 {
   return new SALOMEDSImpl_AttributeTarget();
 }
@@ -152,15 +153,12 @@ Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const
 //function : Paste
 //purpose  :
 //=======================================================================
-void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into,
-                                        const Handle(TDF_RelocationTable)& RT) const
+void SALOMEDSImpl_AttributeTarget::Paste(DF_Attribute* into)
 {
-  Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (Into);
+  SALOMEDSImpl_AttributeTarget* REL = dynamic_cast<SALOMEDSImpl_AttributeTarget*>(into);
   REL->SetRelation(myRelation);
-  Handle(SALOMEDSImpl_AttributeReference) V1,V2;
-  for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) {
-    V1 = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value());
-    RT->HasRelocation (V1,V2);
-    REL->GetVariables().Append(V2);
-  }
+  REL->myVariables.clear();
+  for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter){
+    REL->myVariables[iter->first]=iter->second;
+  }  
 }