]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix on [Bug PAL7840] It's impossible to create a copy of imported .med file in the
authorapo <apo@opencascade.com>
Thu, 27 Jan 2005 06:45:08 +0000 (06:45 +0000)
committerapo <apo@opencascade.com>
Thu, 27 Jan 2005 06:45:08 +0000 (06:45 +0000)
src/SALOMEDS/SALOMEDS_SObject_i.cxx
src/SALOMEDS/SALOMEDS_SObject_i.hxx
src/SALOMEDS/SALOMEDS_StudyManager_i.cxx

index 5f5ddded8977a4af4324f3905c2e1d3135c4516f..f8cee3794407f132fe91686d6807f22d644347ba 100644 (file)
@@ -365,12 +365,19 @@ char* SALOMEDS_SObject_i::GetID()
  *  Purpose  : 
  */
 //============================================================================
+TDF_Label SALOMEDS_SObject_i::GetFatherComponentLabel()
+{
+  TDF_Label aLabel = _lab;
+  while(!SALOMEDS_SComponent_i::IsA(aLabel) && !aLabel.IsRoot())
+    aLabel = aLabel.Father();
+
+  return aLabel;
+}
+
 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
 {
-  TDF_Label aSCompLabel = _lab;
-  while(!SALOMEDS_SComponent_i::IsA(aSCompLabel) && !aSCompLabel.IsRoot()){
-    aSCompLabel = aSCompLabel.Father();
-  }
+  TDF_Label aSCompLabel = GetFatherComponentLabel();
+
   return SALOMEDS_SComponent_i::NewRef(_study,aSCompLabel)._retn();
 }
   
index a4c73ce43c8bffcf6bef0355079e5c7e01d1ace8..45ff3e5d3ac0d95075015d2ce771c1914a9592ef 100644 (file)
@@ -110,6 +110,8 @@ public:
   SALOMEDS_Study_i* GetStudyServant(){ return _study;}
 
   TDF_Label GetLabel(){ return _lab;}
+  TDF_Label GetFatherLabel(){ return _lab.Father();}
+  TDF_Label GetFatherComponentLabel();
 
   CORBA::ORB_var GetORB() const;
 
index 614ca3611a66a59a6bd572c4fa47ac994c499b62..588019be2d76bea0b75cc2640d8264fe267d4c69 100644 (file)
@@ -1203,7 +1203,8 @@ TDF_Label SALOMEDS_StudyManager_i::PasteLabel(SALOMEDS_Study_i* theDestinationSt
                                              const TDF_Label& theSource,
                                              const TDF_Label& theDestinationStart,
                                              const int theCopiedStudyID,
-                                             const bool isFirstElement) {
+                                             const bool isFirstElement) 
+{
 
   // get corresponding source, target and auxiliary labels
   TDF_Label aTargetLabel = theDestinationStart;
@@ -1212,7 +1213,8 @@ TDF_Label SALOMEDS_StudyManager_i::PasteLabel(SALOMEDS_Study_i* theDestinationSt
   if (!isFirstElement) {
     for(a = theSource.Depth() - 1; a > 0 ; a--) {
       TDF_Label aSourceLabel = theSource;
-      for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
+      for(int aNbFather = 1; aNbFather < a; aNbFather++)
+       aSourceLabel = aSourceLabel.Father();
       aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
       aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
     }
@@ -1268,18 +1270,22 @@ TDF_Label SALOMEDS_StudyManager_i::PasteLabel(SALOMEDS_Study_i* theDestinationSt
   if (aAuxSourceLabel.FindAttribute(TDataStd_Comment::GetID(), aCommentAttribute)) {
     std::string anEntry(TCollection_AsciiString(aCommentAttribute->Get()).ToCString());
     std::size_t aNameStart = anEntry.find(' ');
+    std::string aName;
+    if(aNameStart != std::string::npos){
+      aName = anEntry.substr(aNameStart+1);
+      anEntry = anEntry.substr(0,aNameStart);
+    }
     if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
       TDF_Label aRefLabel;
-      TDF_Tool::Label(aTargetLabel.Data(),const_cast<char*>(anEntry.c_str()),aRefLabel);
+      TDF_Tool::Label(aTargetLabel.Data(),&anEntry[0],aRefLabel);
       TDF_Reference::Set(aTargetLabel, aRefLabel);
       SALOMEDS_TargetAttribute::Set(aRefLabel)->Append(aTargetLabel); // target attributes structure support
     } else {
       if(aNameStart != std::string::npos)
-       TDataStd_Name::Set(aTargetLabel, &anEntry[aNameStart+1]);
+       TDataStd_Name::Set(aTargetLabel, &aName[0]);
       else
        TDataStd_Name::Set(aTargetLabel, 
-                          TCollection_ExtendedString("Reference to:") +
-                          const_cast<char*>(anEntry.c_str()));
+                          TCollection_ExtendedString("Reference to:") + &anEntry[0]);
     }
   }
 
@@ -1334,17 +1340,9 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theOb
     return SALOMEDS::SObject::_nil();
 
   // fill root inserted SObject
-  TDF_Label aStartLabel;
   int aCStudyID = aStudyIDAttribute->Get();
-  if (aStructureOnly) {
-    TDF_Label anObjectLabel;
-    TDF_Tool::Label(aDocument->GetData(),theObject->GetID(),anObjectLabel);
-    aStartLabel = PasteLabel(aStudy,anEngine,_clipboard->Main(),anObjectLabel,aCStudyID,false);
-  } else {
-    TDF_Label aComponentLabel;
-    TDF_Tool::Label(aDocument->GetData(),aComponent->GetID(),aComponentLabel);
-    aStartLabel = PasteLabel(aStudy,anEngine,_clipboard->Main(),aComponentLabel,aCStudyID,true);
-  }
+  TDF_Label aLabel = aStructureOnly? aSObject->GetLabel(): aSObject->GetFatherComponentLabel();
+  TDF_Label aStartLabel = PasteLabel(aStudy,anEngine,_clipboard->Main(),aLabel,aCStudyID,true);
 
   // paste all sublebels
   TDF_ChildIterator anIterator(_clipboard->Main(),Standard_True);