From: apo Date: Thu, 27 Jan 2005 06:45:08 +0000 (+0000) Subject: Fix on [Bug PAL7840] It's impossible to create a copy of imported .med file in the X-Git-Tag: V2_2_0b1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d99b4a5b23b43a7d88345efa9b5b424d73741869;p=modules%2Fkernel.git Fix on [Bug PAL7840] It's impossible to create a copy of imported .med file in the --- diff --git a/src/SALOMEDS/SALOMEDS_SObject_i.cxx b/src/SALOMEDS/SALOMEDS_SObject_i.cxx index 5f5ddded8..f8cee3794 100644 --- a/src/SALOMEDS/SALOMEDS_SObject_i.cxx +++ b/src/SALOMEDS/SALOMEDS_SObject_i.cxx @@ -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(); } diff --git a/src/SALOMEDS/SALOMEDS_SObject_i.hxx b/src/SALOMEDS/SALOMEDS_SObject_i.hxx index a4c73ce43..45ff3e5d3 100644 --- a/src/SALOMEDS/SALOMEDS_SObject_i.hxx +++ b/src/SALOMEDS/SALOMEDS_SObject_i.hxx @@ -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; diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx index 614ca3611..588019be2 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx @@ -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(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(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);