1 // Copyright (C) 2007-2010 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 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISUConfig.cc
25 // Author : Alexey PETROV
28 #include "VISUConfig.hh"
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Session.h"
33 #include "SALOMEDSClient_GenericAttribute.hxx"
34 #include "SALOMEDSClient_AttributeIOR.hxx"
36 #include "SalomeApp_Application.h"
37 #include "SalomeApp_Study.h"
39 #include "SALOME_Event.h"
46 static int MYDEBUG = 0;
48 static int MYDEBUG = 0;
59 return SUIT_Session::session();
65 return GetSession()->resourceMgr();
68 //---------------------------------------------------------------------------
70 QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex;
71 CORBA::ORB_var Base_i::myOrb;
72 PortableServer::POA_var Base_i::myPoa;
73 SALOME_NamingService* Base_i::myNamingService;
74 SALOME_LifeCycleCORBA* Base_i::myEnginesLifeCycle;
75 VISU_Gen_i* Base_i::myVisuGenImpl;
81 char* Base_i::GetID(){
83 CORBA::Object_var anObject = _this();
84 CORBA::String_var anIOR = myOrb->object_to_string(anObject);
87 return CORBA::string_dup(myID.c_str());
90 //---------------------------------------------------------------------------
91 static int mySCnt = 0;
92 static QMutex aMutex(QMutex::Recursive);
94 Mutex::Mutex(QMutex* theMutex): myMutex(&aMutex)
96 if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<!mySCnt);
105 if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<!mySCnt);
109 //---------------------------------------------------------------------------
110 Storable::TStorableEngineMap Storable::myStorableEngineMap;
116 ostringstream anOutputStream;
117 Storable::DataToStream( anOutputStream, "myComment", GetComment() );
118 ToStream(anOutputStream);
119 anOutputStream<<ends;
120 if(MYDEBUG) MESSAGE("Storable::ToString - "<<anOutputStream.str());
121 return anOutputStream.str();
125 //---------------------------------------------------------------
128 ::CanCopy(SALOMEDS::SObject_ptr theObject)
134 //---------------------------------------------------------------
137 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
138 CORBA::Long& theObjectID,
139 const std::string& theTmpDir,
140 TFileNames& theFileNames)
142 TFileName aFileName("copy_persistent");
143 std::string aCopyPersist = theTmpDir + aFileName;
144 std::ofstream anOutputFileStream(aCopyPersist.c_str(), ios::out);
145 anOutputFileStream<<ToString()<<endl;
147 theFileNames.push_back(aFileName);
154 //---------------------------------------------------------------
157 ::RegistryStorableEngine(const std::string& theComment,
158 TStorableEngine theEngine)
160 if(!myStorableEngineMap.insert(TStorableEngineMap::value_type(theComment, theEngine)).second)
161 throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
165 //---------------------------------------------------------------
168 ::Create(SALOMEDS::SObject_ptr theSObject,
169 const std::string& theLocalPersistentID,
170 const std::string& thePrefix,
171 CORBA::Boolean theIsMultiFile)
174 QString aString( CorrectPersistentString( theLocalPersistentID ).c_str() );
175 TRestoringMap aRestoringMap;
176 StringToMap(aString, aRestoringMap);
178 QString aComment = VISU::Storable::FindValue(aRestoringMap, "myComment", &anIsExists);
180 TStorableEngineMap::const_iterator anIter = myStorableEngineMap.find(aComment.toLatin1().data());
181 if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.toLatin1().data()<<" "<<(anIter != myStorableEngineMap.end()));
182 if(anIter == myStorableEngineMap.end())
184 TStorableEngine aStorableEngine = anIter->second;
185 return aStorableEngine(theSObject, aRestoringMap, thePrefix, theIsMultiFile);
187 }catch(std::exception& exc){
188 INFOS("Follow exception was occured :\n"<<exc.what());
190 INFOS("Unknown exception was occured!");
196 //---------------------------------------------------------------
199 ::Comment2Type(const std::string& theComment)
201 if ( theComment == "CURVE" )
203 if ( theComment == "TABLE" )
205 if ( theComment == "POINTMAP3D" )
206 return VISU::TPOINTMAP3D;
207 if ( theComment == "CONTAINER" )
208 return VISU::TCONTAINER;
209 if ( theComment == "MESH" )
211 if ( theComment == "SCALARMAP" )
212 return VISU::TSCALARMAP;
213 if ( theComment == "PRSMERGER" )
214 return VISU::TSCALARMAP;
215 if ( theComment == "ISOSURFACE" )
216 return VISU::TISOSURFACES;
217 if ( theComment == "DEFORMEDSHAPE" )
218 return VISU::TDEFORMEDSHAPE;
219 if ( theComment == "DEFORMEDSHAPEANDSCALARMAP" )
220 return VISU::TDEFORMEDSHAPEANDSCALARMAP;
221 if ( theComment == "GAUSSPOINTS" )
222 return VISU::TGAUSSPOINTS;
223 if ( theComment == "PLOT3D" )
224 return VISU::TPLOT3D;
225 if ( theComment == "CUTPLANES" )
226 return VISU::TCUTPLANES;
227 if ( theComment == "CUTSEGMENT" )
228 return VISU::TCUTSEGMENT;
229 if ( theComment == "VECTORS" )
230 return VISU::TVECTORS;
231 if ( theComment == "STREAMLINES" )
232 return VISU::TSTREAMLINES;
233 if ( theComment == "VISUGEN" )
234 return VISU::TVISUGEN;
235 if ( theComment == "VIEWMANAGER" )
236 return VISU::TVIEWMANAGER;
237 if ( theComment == "RESULT" )
238 return VISU::TRESULT;
239 if ( theComment == "XYPLOT" )
240 return VISU::TXYPLOT;
241 if ( theComment == "TABLEVIEW" )
242 return VISU::TTABLEVIEW;
243 if ( theComment == "VIEW3D" )
244 return VISU::TVIEW3D;
245 if ( theComment == "GAUSSVIEW" )
246 return VISU::TGAUSSVIEW;
247 if ( theComment == "ENTITY" )
248 return VISU::TENTITY;
249 if ( theComment == "FAMILY" )
250 return VISU::TFAMILY;
251 if ( theComment == "PART" )
252 return VISU::TPART; // MULTIPR
253 if ( theComment == "GROUP" )
255 if ( theComment == "FIELD" )
257 if ( theComment == "TIMESTAMP" )
258 return VISU::TTIMESTAMP;
259 if ( theComment == "ANIMATION" )
260 return VISU::TANIMATION;
261 if ( theComment == "EVOLUTION" )
262 return VISU::TEVOLUTION;
263 if ( theComment == "ALL" )
270 //---------------------------------------------------------------
273 ::RestoringMap2Type(const TRestoringMap& theRestoringMap)
275 QString aComment = Storable::FindValue( theRestoringMap, "myComment", "" );
276 return Comment2Type(aComment.toLatin1().data());
280 //---------------------------------------------------------------
283 ::Stream2Type(const std::string& thePersistentString)
285 QString aString(thePersistentString.c_str());
286 if(aString.isEmpty())
289 VISU::Storable::TRestoringMap aRestoringMap;
290 Storable::StringToMap( aString, aRestoringMap );
291 return RestoringMap2Type( aRestoringMap );
295 //---------------------------------------------------------------
298 ::SObject2Type(const _PTR(SObject)& theSObject)
300 _PTR(GenericAttribute) anAttr;
301 if (theSObject->FindAttribute(anAttr, "AttributeString")) {
302 _PTR(AttributeString) aDataAttr(anAttr);
303 std::string aData = aDataAttr->Value();
304 return Stream2Type(aData);
311 //---------------------------------------------------------------
314 ::CorrectPersistentString(const std::string& thePersistentString)
316 QString aString(thePersistentString.c_str());
317 if(aString.isEmpty())
318 return aString.toLatin1().data();
320 VISU::Storable::TRestoringMap aRestoringMap;
321 Storable::StringToMap( aString, aRestoringMap );
323 bool anIsFound = false;
324 QString aComment = Storable::FindValue( aRestoringMap, "myComment", &anIsFound );
326 if ( aComment == "PRSMERGER" )
327 aString.replace( "myComment=PRSMERGER", "myComment=SCALARMAP" );
330 return aString.toLatin1().data();
334 //---------------------------------------------------------------
337 ::FindEntry(SALOMEDS::Study_ptr theStudyDocument,
338 const std::string& theStartEntry,
339 const TRestoringMap& theRestoringMap,
342 SALOMEDS::SObject_var aSObject = theStudyDocument->FindObjectID(theStartEntry.c_str());
343 SALOMEDS::ChildIterator_var anIter = theStudyDocument->NewChildIterator(aSObject);
344 anIter->InitEx(IsAllLevels);
345 for(; anIter->More(); anIter->Next()) {
346 aSObject = anIter->Value();
347 SALOMEDS::GenericAttribute_var anAttr;
348 if (aSObject->FindAttribute(anAttr,"AttributeString")) {
349 SALOMEDS::AttributeString_var aDataAttr = SALOMEDS::AttributeString::_narrow(anAttr);
350 CORBA::String_var aString = aDataAttr->Value();
351 VISU::Storable::TRestoringMap aRestoringMap;
352 Storable::StringToMap( aString.in(), aRestoringMap );
353 bool anIsSame = true;
354 TRestoringMap::const_iterator anIter = theRestoringMap.begin();
355 for(; anIter != theRestoringMap.end(); anIter++){
356 const TRestoringMap::key_type& aKey = anIter->first;
357 TRestoringMap::const_iterator anIter2 = aRestoringMap.find(aKey);
358 if(anIter2 != aRestoringMap.end()){
359 if (anIter->second == anIter2->second)
366 CORBA::String_var anEntry = aSObject->GetID();
375 //----------------------------------------------------------------------------
378 ::StringToMap(const QString& theString,
379 TRestoringMap& theMap)
381 if(0 && MYDEBUG) MESSAGE("Storable::StringToMap : string="<<theString.toLatin1().data());
382 QStringList strList = theString.split( ";", QString::SkipEmptyParts );
383 for ( int i = 0; i < strList.count(); i++ ) {
384 QString next = strList[ i ];
385 int pos = next.indexOf("=");
386 QString aName, aValue;
388 aName = next.trimmed();
392 aName = next.left( pos ).trimmed();
393 aValue = next.mid( pos+1 );
394 if ( aValue.isNull() )
397 if ( !aName.isEmpty() )
398 theMap.insert( TRestoringMap::value_type( (const char*)aName.toLatin1(), aValue ) );
403 //----------------------------------------------------------------------------
404 Storable::TRestoringMap
406 ::GetStorableMap(_PTR(SObject) theSObject)
408 Storable::TRestoringMap aRestoringMap;
410 _PTR(GenericAttribute) anAttr;
411 if(theSObject->FindAttribute(anAttr,"AttributeString")){
412 _PTR(AttributeString) aComment (anAttr);
413 std::string aValue = aComment->Value();
414 VISU::Storable::StringToMap(aValue.c_str(), aRestoringMap);
417 return aRestoringMap;
421 //----------------------------------------------------------------------------
424 ::DataToStream(std::ostringstream& theStr,
425 const QString& theName,
426 const QString& theVal)
428 QString output = ( !theName.isNull() ? theName : QString("") )
430 + ( !theVal.isNull() ? theVal : QString("") );
431 theStr<<(const char*)output.toLatin1()<<";";
435 //---------------------------------------------------------------
438 ::DataToStream(std::ostringstream& theStr,
439 const QString& theName,
442 QString output = ( !theName.isNull() ? theName : QString("") )
444 + QString::number( theVal );
445 theStr<<(const char*)output.toLatin1()<<";";
449 //---------------------------------------------------------------
452 ::DataToStream(std::ostringstream& theStr,
453 const QString& theName,
456 QString output = ( !theName.isNull() ? theName : QString("") )
458 + QString::number( theVal );
459 theStr<<(const char*)output.toLatin1()<<";";
463 //---------------------------------------------------------------
466 ::DataToStream(std::ostringstream& theStr,
467 const QString& theName,
470 QString output = ( !theName.isNull() ? theName : QString("") )
472 + QString::number( theVal );
473 theStr<<output.toLatin1().data()<<";";
477 //---------------------------------------------------------------
480 ::FindValue(const TRestoringMap& theMap,
481 const std::string& theArg,
484 TRestoringMap::const_iterator anIter = theMap.find(theArg);
485 if(anIter == theMap.end()) {
486 if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
487 if(theIsFind != NULL)
489 //throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
490 static QString BAD_VALUE("NULL");
493 if(theIsFind != NULL)
495 return anIter->second;
499 //---------------------------------------------------------------
502 ::FindValue(const TRestoringMap& theMap,
503 const std::string& theArg,
504 const QString& theDefaultValue)
506 bool anIsFound = false;
507 QString aValue = FindValue(theMap,theArg,&anIsFound);
510 return theDefaultValue;
514 //---------------------------------------------------------------------------
515 PortableServer::ServantBase_var
516 GetServant(CORBA::Object_ptr theObject)
518 if(CORBA::is_nil(theObject))
521 PortableServer::POA_ptr aPOA = Base_i::GetPOA();
522 PortableServer::Servant aServant = aPOA->reference_to_servant(theObject);
525 INFOS("GetServant - Unknown exception was occured!!!");
531 //---------------------------------------------------------------------------
533 SObjectToObject(SALOMEDS::SObject_ptr theSObject)
535 SALOMEDS::GenericAttribute_var anAttr;
536 CORBA::Object_var anObject;
537 if(CORBA::is_nil(theSObject))
540 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
541 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
542 CORBA::String_var aValue = anIOR->Value();
543 CORBA::ORB_ptr anORB = Base_i::GetORB();
544 if(strcmp(aValue,"") != 0)
545 anObject = anORB->string_to_object(aValue);
548 INFOS("SObjectToObject - Unknown exception was occured!!!");
553 //---------------------------------------------------------------------------
555 ClientSObjectToObject(_PTR(SObject) theSObject)
557 _PTR(GenericAttribute) anAttr;
558 CORBA::Object_var anObject;
562 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
563 _PTR(AttributeIOR) anIOR = anAttr;
564 CORBA::String_var aValue = anIOR->Value().c_str();
565 CORBA::ORB_ptr anORB = Base_i::GetORB();
566 if(strcmp(aValue,"") != 0)
567 anObject = anORB->string_to_object(aValue);
570 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
576 //---------------------------------------------------------------------------
578 CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
579 const std::string& theFatherEntry,
580 const std::string& theIconName,
581 const std::string& theIOR,
582 const std::string& theName,
583 const std::string& thePersistentRef,
584 const std::string& theComment,
585 CORBA::Boolean theCreateNew)
587 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
588 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
589 SALOMEDS::SObject_var aNewSObject;
591 aNewSObject = aStudyBuilder->NewObject(aFather);
593 aNewSObject = aFather;
594 SALOMEDS::GenericAttribute_var anAttr;
595 if(theIOR != NO_IOR){
596 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
597 SALOMEDS::AttributeIOR_var aCustomAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
598 aCustomAttr->SetValue(theIOR.c_str());
600 if(theName != NO_NAME){
601 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
602 SALOMEDS::AttributeName_var aCustomAttr = SALOMEDS::AttributeName::_narrow(anAttr);
603 aCustomAttr->SetValue(theName.c_str());
605 if(thePersistentRef != NO_PERFSITENT_REF){
606 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
607 SALOMEDS::AttributePersistentRef_var aCustomAttr = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
608 aCustomAttr->SetValue(thePersistentRef.c_str());
610 if(theComment != NO_COMMENT){
611 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
612 SALOMEDS::AttributeString_var aCustomAttr = SALOMEDS::AttributeString::_narrow(anAttr);
613 aCustomAttr->SetValue(theComment.c_str());
615 if(theIconName != NO_ICON){
616 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
617 SALOMEDS::AttributePixMap_var aCustomAttr = SALOMEDS::AttributePixMap::_narrow(anAttr);
618 aCustomAttr->SetPixMap(theIconName.c_str());
620 CORBA::String_var anEntry = aNewSObject->GetID();
621 std::string aRet(anEntry);
623 INFOS("CreateAttributes - StudyId = "<<theStudyDocument->StudyId()<<"; anEntry = "<<aRet<<"; IOR = '"<<theIOR<<"'");
628 CreateAttributes(_PTR(Study) theStudyDocument,
629 const std::string& theFatherEntry,
630 const std::string& theIconName,
631 const std::string& theIOR,
632 const std::string& theName,
633 const std::string& thePersistentRef,
634 const std::string& theComment,
635 CORBA::Boolean theCreateNew)
637 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
638 _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
639 _PTR(SObject) aNewSObject;
642 aNewSObject = aStudyBuilder->NewObject(aFather);
645 aNewSObject = aFather;
647 _PTR(GenericAttribute) anAttr;
648 if (theIOR != NO_IOR) {
649 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
650 _PTR(AttributeIOR) aCustomAttr (anAttr);
651 aCustomAttr->SetValue(theIOR);
653 if (theName != NO_NAME) {
654 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
655 _PTR(AttributeName) aCustomAttr (anAttr);
656 aCustomAttr->SetValue(theName);
658 if (thePersistentRef != NO_PERFSITENT_REF) {
659 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
660 _PTR(AttributePersistentRef) aCustomAttr (anAttr);
661 aCustomAttr->SetValue(thePersistentRef);
663 if (theComment != NO_COMMENT) {
664 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
665 _PTR(AttributeString) aCustomAttr (anAttr);
666 aCustomAttr->SetValue(theComment);
668 if (theIconName != NO_ICON) {
669 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
670 _PTR(AttributePixMap) aCustomAttr (anAttr);
671 aCustomAttr->SetPixMap(theIconName);
673 std::string aRet = aNewSObject->GetID();
675 INFOS("CreateAttributes - StudyId = " << theStudyDocument->StudyId()
676 << "; anEntry = " << aRet << "; IOR = '" << theIOR << "'");
681 //---------------------------------------------------------------
683 GenerateName(const std::string& theFmt, int /*theId*/) // theId was deprecated because of incorrect work IPAL21151
686 aName.sprintf("%s", theFmt.c_str());
689 SalomeApp_Application* anApp =
690 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
692 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
696 std::vector<_PTR(SObject)> aList = aStudy->studyDS()->FindObjectByName(aName.toLatin1().data(), "VISU");
697 if ( aList.size() > 0 ) {
699 aName.sprintf("%s:%d", theFmt.c_str(), count);
707 aName.sprintf("%s:%d", theFmt.c_str(), count);
713 //---------------------------------------------------------------
714 SALOMEDS::StudyManager_var
717 static SALOMEDS::StudyManager_var aStudyManager;
718 if(CORBA::is_nil(aStudyManager)){
719 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
720 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
721 aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
723 return aStudyManager;
727 //---------------------------------------------------------------
729 GetDSStudy(_PTR(Study) theStudy)
731 int aStudyID = theStudy->StudyId();
732 return GetStudyManager()->GetStudyByID(aStudyID);
736 //---------------------------------------------------------------
737 struct TGetStudyEvent: public SALOME_Event
739 SALOMEDS::Study_var myStudy;
741 typedef SalomeApp_Study* TResult;
744 TGetStudyEvent(SALOMEDS::Study_ptr theStudy):
745 myStudy(SALOMEDS::Study::_duplicate(theStudy)),
753 if(CORBA::is_nil(myStudy))
756 int aStudyId = myStudy->StudyId();
757 SUIT_Session* aSession = SUIT_Session::session();
758 QList<SUIT_Application*> anApplications = aSession->applications();
759 QListIterator<SUIT_Application*> anIter (anApplications);
760 while ( anIter.hasNext() ) {
761 SUIT_Application* anApp = anIter.next();
762 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
763 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
764 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
765 if (aStudyId == aCStudy->StudyId()) {
777 //---------------------------------------------------------------
779 GetGUIStudy(SALOMEDS::Study_ptr theStudy)
781 return ProcessEvent(new TGetStudyEvent(theStudy));
785 //---------------------------------------------------------------
787 GetStudy(SALOMEDS::Study_ptr theStudy)
789 if(SalomeApp_Study* aStudy = ProcessEvent(new TGetStudyEvent(theStudy)))
790 return aStudy->studyDS();
792 return _PTR(Study)();
796 //---------------------------------------------------------------
797 SALOMEDS::SObject_var
798 GetSObject( _PTR(SObject) obj )
800 _PTR(Study) aStudy = obj->GetStudy();
801 SALOMEDS::Study_var aSalomeDSStudy = GetDSStudy( aStudy );
802 std::string id = obj->GetID();
803 return aSalomeDSStudy->FindObjectID( id.c_str() );
806 //---------------------------------------------------------------
808 GetClientSObject(SALOMEDS::SObject_ptr theSObject,
809 _PTR(Study) theStudy)
811 CORBA::String_var anEntry = theSObject->GetID();
812 return theStudy->FindObjectID( anEntry.in() );
816 //---------------------------------------------------------------
818 RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
820 bool theDestroySubObjects)
822 if (theSObject->_is_nil()) return;
824 SALOMEDS::Study_var aStudyDocument = theSObject->GetStudy();
825 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
827 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
831 // Remove possible sub-objects
832 SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(theSObject);
833 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
834 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
835 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
836 if (CORBA::is_nil(aChildObj)) continue;
838 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
839 if (CORBA::is_nil(aRemovableObject)) continue;
841 aRemovableObject->RemoveFromStudy();
844 // asl, fix for PAL10455: Remove references to SObject
845 SALOMEDS::Study::ListOfSObject_var aRefs = aStudyDocument->FindDependances( theSObject );
846 for( int i=0, n=aRefs->length(); i<n; i++ )
848 SALOMEDS::SObject_var o = aRefs[i];
849 if( o->GetFatherComponent()->ComponentDataType()==theSObject->GetFatherComponent()->ComponentDataType() )
851 aStudyBuilder->RemoveReference( o );
852 aStudyBuilder->RemoveObjectWithChildren( o );
856 // Remove the SObject itself
857 aStudyBuilder->RemoveObjectWithChildren(theSObject);
861 //---------------------------------------------------------------
863 RemoveFromStudy (_PTR(SObject) theSObject,
865 bool theDestroySubObjects)
867 if (!theSObject) return;
869 _PTR(Study) aStudyDocument = theSObject->GetStudy();
870 _PTR(StudyBuilder) aStudyBuilder = aStudyDocument->NewBuilder();
872 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
876 // Remove possible sub-objects
877 _PTR(ChildIterator) aChildIter = aStudyDocument->NewChildIterator(theSObject);
878 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
879 _PTR(SObject) aChildSObject = aChildIter->Value();
880 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
881 if (CORBA::is_nil(aChildObj))
884 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
885 if (CORBA::is_nil(aRemovableObject))
888 aRemovableObject->RemoveFromStudy();
891 // Remove the SObject itself
892 aStudyBuilder->RemoveObjectWithChildren(theSObject);