1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISUConfig.cc
24 // Author : Alexey PETROV
27 #include "VISUConfig.hh"
29 #include "SUIT_ResourceMgr.h"
30 #include "SUIT_Session.h"
32 #include "SALOMEDSClient_GenericAttribute.hxx"
33 #include "SALOMEDSClient_AttributeIOR.hxx"
35 #include "SalomeApp_Application.h"
36 #include "SalomeApp_Study.h"
38 #include "SALOME_Event.h"
45 static int MYDEBUG = 0;
47 static int MYDEBUG = 0;
58 return SUIT_Session::session();
64 return GetSession()->resourceMgr();
67 //---------------------------------------------------------------------------
69 QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex;
70 CORBA::ORB_var Base_i::myOrb;
71 PortableServer::POA_var Base_i::myPoa;
72 SALOME_NamingService* Base_i::myNamingService;
73 SALOME_LifeCycleCORBA* Base_i::myEnginesLifeCycle;
74 VISU_Gen_i* Base_i::myVisuGenImpl;
80 char* Base_i::GetID(){
82 CORBA::Object_var anObject = _this();
83 CORBA::String_var anIOR = myOrb->object_to_string(anObject);
86 return CORBA::string_dup(myID.c_str());
89 //---------------------------------------------------------------------------
90 static int mySCnt = 0;
91 static QMutex aMutex(QMutex::Recursive);
93 Mutex::Mutex(QMutex* theMutex): myMutex(&aMutex)
95 if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<!mySCnt);
104 if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<!mySCnt);
108 //---------------------------------------------------------------------------
109 Storable::TStorableEngineMap Storable::myStorableEngineMap;
115 ostringstream anOutputStream;
116 Storable::DataToStream( anOutputStream, "myComment", GetComment() );
117 ToStream(anOutputStream);
118 anOutputStream<<ends;
119 if(MYDEBUG) MESSAGE("Storable::ToString - "<<anOutputStream.str());
120 return anOutputStream.str();
124 //---------------------------------------------------------------
127 ::CanCopy(SALOMEDS::SObject_ptr theObject)
133 //---------------------------------------------------------------
136 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
137 CORBA::Long& theObjectID,
138 const std::string& theTmpDir,
139 TFileNames& theFileNames)
141 TFileName aFileName("copy_persistent");
142 std::string aCopyPersist = theTmpDir + aFileName;
143 std::ofstream anOutputFileStream(aCopyPersist.c_str(), ios::out);
144 anOutputFileStream<<ToString()<<endl;
146 theFileNames.push_back(aFileName);
153 //---------------------------------------------------------------
156 ::RegistryStorableEngine(const std::string& theComment,
157 TStorableEngine theEngine)
159 if(!myStorableEngineMap.insert(TStorableEngineMap::value_type(theComment, theEngine)).second)
160 throw std::logic_error("Storable::Registry >> dupliacte registring !!!");
164 //---------------------------------------------------------------
167 ::Create(SALOMEDS::SObject_ptr theSObject,
168 const std::string& theLocalPersistentID,
169 const std::string& thePrefix,
170 CORBA::Boolean theIsMultiFile)
173 QString aString( CorrectPersistentString( theLocalPersistentID ).c_str() );
174 TRestoringMap aRestoringMap;
175 StringToMap(aString, aRestoringMap);
177 QString aComment = VISU::Storable::FindValue(aRestoringMap, "myComment", &anIsExists);
179 TStorableEngineMap::const_iterator anIter = myStorableEngineMap.find(aComment.toLatin1().data());
180 if(MYDEBUG) MESSAGE("Storable::Create - "<<aComment.toLatin1().data()<<" "<<(anIter != myStorableEngineMap.end()));
181 if(anIter == myStorableEngineMap.end())
183 TStorableEngine aStorableEngine = anIter->second;
184 return aStorableEngine(theSObject, aRestoringMap, thePrefix, theIsMultiFile);
186 }catch(std::exception& exc){
187 INFOS("Follow exception was occured :\n"<<exc.what());
189 INFOS("Unknown exception was occured!");
195 //---------------------------------------------------------------
198 ::Comment2Type(const std::string& theComment)
200 if ( theComment == "CURVE" )
202 if ( theComment == "TABLE" )
204 if ( theComment == "POINTMAP3D" )
205 return VISU::TPOINTMAP3D;
206 if ( theComment == "CONTAINER" )
207 return VISU::TCONTAINER;
208 if ( theComment == "MESH" )
210 if ( theComment == "SCALARMAP" )
211 return VISU::TSCALARMAP;
212 if ( theComment == "PRSMERGER" )
213 return VISU::TSCALARMAP;
214 if ( theComment == "ISOSURFACE" )
215 return VISU::TISOSURFACES;
216 if ( theComment == "DEFORMEDSHAPE" )
217 return VISU::TDEFORMEDSHAPE;
218 if ( theComment == "DEFORMEDSHAPEANDSCALARMAP" )
219 return VISU::TDEFORMEDSHAPEANDSCALARMAP;
220 if ( theComment == "GAUSSPOINTS" )
221 return VISU::TGAUSSPOINTS;
222 if ( theComment == "PLOT3D" )
223 return VISU::TPLOT3D;
224 if ( theComment == "CUTPLANES" )
225 return VISU::TCUTPLANES;
226 if ( theComment == "CUTLINES" )
227 return VISU::TCUTLINES;
228 if ( theComment == "VECTORS" )
229 return VISU::TVECTORS;
230 if ( theComment == "STREAMLINES" )
231 return VISU::TSTREAMLINES;
232 if ( theComment == "VISUGEN" )
233 return VISU::TVISUGEN;
234 if ( theComment == "VIEWMANAGER" )
235 return VISU::TVIEWMANAGER;
236 if ( theComment == "RESULT" )
237 return VISU::TRESULT;
238 if ( theComment == "XYPLOT" )
239 return VISU::TXYPLOT;
240 if ( theComment == "TABLEVIEW" )
241 return VISU::TTABLEVIEW;
242 if ( theComment == "VIEW3D" )
243 return VISU::TVIEW3D;
244 if ( theComment == "GAUSSVIEW" )
245 return VISU::TGAUSSVIEW;
246 if ( theComment == "ENTITY" )
247 return VISU::TENTITY;
248 if ( theComment == "FAMILY" )
249 return VISU::TFAMILY;
250 if ( theComment == "PART" )
251 return VISU::TPART; // MULTIPR
252 if ( theComment == "GROUP" )
254 if ( theComment == "FIELD" )
256 if ( theComment == "TIMESTAMP" )
257 return VISU::TTIMESTAMP;
258 if ( theComment == "ANIMATION" )
259 return VISU::TANIMATION;
260 if ( theComment == "ALL" )
267 //---------------------------------------------------------------
270 ::RestoringMap2Type(const TRestoringMap& theRestoringMap)
272 QString aComment = Storable::FindValue( theRestoringMap, "myComment", "" );
273 return Comment2Type(aComment.toLatin1().data());
277 //---------------------------------------------------------------
280 ::Stream2Type(const std::string& thePersistentString)
282 QString aString(thePersistentString.c_str());
283 if(aString.isEmpty())
286 VISU::Storable::TRestoringMap aRestoringMap;
287 Storable::StringToMap( aString, aRestoringMap );
288 return RestoringMap2Type( aRestoringMap );
292 //---------------------------------------------------------------
295 ::SObject2Type(const _PTR(SObject)& theSObject)
297 _PTR(GenericAttribute) anAttr;
298 if (theSObject->FindAttribute(anAttr, "AttributeString")) {
299 _PTR(AttributeString) aDataAttr(anAttr);
300 std::string aData = aDataAttr->Value();
301 return Stream2Type(aData);
308 //---------------------------------------------------------------
311 ::CorrectPersistentString(const std::string& thePersistentString)
313 QString aString(thePersistentString.c_str());
314 if(aString.isEmpty())
315 return aString.toLatin1().data();
317 VISU::Storable::TRestoringMap aRestoringMap;
318 Storable::StringToMap( aString, aRestoringMap );
320 bool anIsFound = false;
321 QString aComment = Storable::FindValue( aRestoringMap, "myComment", &anIsFound );
323 if ( aComment == "PRSMERGER" )
324 aString.replace( "myComment=PRSMERGER", "myComment=SCALARMAP" );
327 return aString.toLatin1().data();
331 //---------------------------------------------------------------
334 ::FindEntry(SALOMEDS::Study_ptr theStudyDocument,
335 const std::string& theStartEntry,
336 const TRestoringMap& theRestoringMap,
339 SALOMEDS::SObject_var aSObject = theStudyDocument->FindObjectID(theStartEntry.c_str());
340 SALOMEDS::ChildIterator_var anIter = theStudyDocument->NewChildIterator(aSObject);
341 anIter->InitEx(IsAllLevels);
342 for(; anIter->More(); anIter->Next()) {
343 aSObject = anIter->Value();
344 SALOMEDS::GenericAttribute_var anAttr;
345 if (aSObject->FindAttribute(anAttr,"AttributeString")) {
346 SALOMEDS::AttributeString_var aDataAttr = SALOMEDS::AttributeString::_narrow(anAttr);
347 CORBA::String_var aString = aDataAttr->Value();
348 VISU::Storable::TRestoringMap aRestoringMap;
349 Storable::StringToMap( aString.in(), aRestoringMap );
350 bool anIsSame = true;
351 TRestoringMap::const_iterator anIter = theRestoringMap.begin();
352 for(; anIter != theRestoringMap.end(); anIter++){
353 const TRestoringMap::key_type& aKey = anIter->first;
354 TRestoringMap::const_iterator anIter2 = aRestoringMap.find(aKey);
355 if(anIter2 != aRestoringMap.end()){
356 if (anIter->second == anIter2->second)
363 CORBA::String_var anEntry = aSObject->GetID();
372 //----------------------------------------------------------------------------
375 ::StringToMap(const QString& theString,
376 TRestoringMap& theMap)
378 if(0 && MYDEBUG) MESSAGE("Storable::StringToMap : string="<<theString.toLatin1().data());
379 QStringList strList = theString.split( ";", QString::SkipEmptyParts );
380 for ( int i = 0; i < strList.count(); i++ ) {
381 QString next = strList[ i ];
382 int pos = next.indexOf("=");
383 QString aName, aValue;
385 aName = next.trimmed();
389 aName = next.left( pos ).trimmed();
390 aValue = next.mid( pos+1 );
391 if ( aValue.isNull() )
394 if ( !aName.isEmpty() )
395 theMap.insert( TRestoringMap::value_type( (const char*)aName.toLatin1(), aValue ) );
400 //----------------------------------------------------------------------------
401 Storable::TRestoringMap
403 ::GetStorableMap(_PTR(SObject) theSObject)
405 Storable::TRestoringMap aRestoringMap;
407 _PTR(GenericAttribute) anAttr;
408 if(theSObject->FindAttribute(anAttr,"AttributeString")){
409 _PTR(AttributeString) aComment (anAttr);
410 std::string aValue = aComment->Value();
411 VISU::Storable::StringToMap(aValue.c_str(), aRestoringMap);
414 return aRestoringMap;
418 //----------------------------------------------------------------------------
421 ::DataToStream(std::ostringstream& theStr,
422 const QString& theName,
423 const QString& theVal)
425 QString output = ( !theName.isNull() ? theName : QString("") )
427 + ( !theVal.isNull() ? theVal : QString("") );
428 theStr<<(const char*)output.toLatin1()<<";";
432 //---------------------------------------------------------------
435 ::DataToStream(std::ostringstream& theStr,
436 const QString& theName,
439 QString output = ( !theName.isNull() ? theName : QString("") )
441 + QString::number( theVal );
442 theStr<<(const char*)output.toLatin1()<<";";
446 //---------------------------------------------------------------
449 ::DataToStream(std::ostringstream& theStr,
450 const QString& theName,
453 QString output = ( !theName.isNull() ? theName : QString("") )
455 + QString::number( theVal );
456 theStr<<(const char*)output.toLatin1()<<";";
460 //---------------------------------------------------------------
463 ::DataToStream(std::ostringstream& theStr,
464 const QString& theName,
467 QString output = ( !theName.isNull() ? theName : QString("") )
469 + QString::number( theVal );
470 theStr<<output.toLatin1().data()<<";";
474 //---------------------------------------------------------------
477 ::FindValue(const TRestoringMap& theMap,
478 const std::string& theArg,
481 TRestoringMap::const_iterator anIter = theMap.find(theArg);
482 if(anIter == theMap.end()) {
483 if(MYDEBUG) MESSAGE("Storable::Init >> there is no value for "<<theArg);
484 if(theIsFind != NULL)
486 //throw std::logic_error(string("Storable::Init >> there is no value for ") + theArg);
487 static QString BAD_VALUE("NULL");
490 if(theIsFind != NULL)
492 return anIter->second;
496 //---------------------------------------------------------------
499 ::FindValue(const TRestoringMap& theMap,
500 const std::string& theArg,
501 const QString& theDefaultValue)
503 bool anIsFound = false;
504 QString aValue = FindValue(theMap,theArg,&anIsFound);
507 return theDefaultValue;
511 //---------------------------------------------------------------------------
512 PortableServer::ServantBase_var
513 GetServant(CORBA::Object_ptr theObject)
515 if(CORBA::is_nil(theObject))
518 PortableServer::POA_ptr aPOA = Base_i::GetPOA();
519 PortableServer::Servant aServant = aPOA->reference_to_servant(theObject);
522 INFOS("GetServant - Unknown exception was occured!!!");
528 //---------------------------------------------------------------------------
530 SObjectToObject(SALOMEDS::SObject_ptr theSObject)
532 SALOMEDS::GenericAttribute_var anAttr;
533 CORBA::Object_var anObject;
534 if(CORBA::is_nil(theSObject))
537 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
538 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
539 CORBA::String_var aValue = anIOR->Value();
540 CORBA::ORB_ptr anORB = Base_i::GetORB();
541 if(strcmp(aValue,"") != 0)
542 anObject = anORB->string_to_object(aValue);
545 INFOS("SObjectToObject - Unknown exception was occured!!!");
550 //---------------------------------------------------------------------------
552 ClientSObjectToObject(_PTR(SObject) theSObject)
554 _PTR(GenericAttribute) anAttr;
555 CORBA::Object_var anObject;
559 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
560 _PTR(AttributeIOR) anIOR = anAttr;
561 CORBA::String_var aValue = anIOR->Value().c_str();
562 CORBA::ORB_ptr anORB = Base_i::GetORB();
563 if(strcmp(aValue,"") != 0)
564 anObject = anORB->string_to_object(aValue);
567 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
573 //---------------------------------------------------------------------------
575 CreateAttributes(SALOMEDS::Study_ptr theStudyDocument,
576 const std::string& theFatherEntry,
577 const std::string& theIconName,
578 const std::string& theIOR,
579 const std::string& theName,
580 const std::string& thePersistentRef,
581 const std::string& theComment,
582 CORBA::Boolean theCreateNew)
584 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
585 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
586 SALOMEDS::SObject_var aNewSObject;
588 aNewSObject = aStudyBuilder->NewObject(aFather);
590 aNewSObject = aFather;
591 SALOMEDS::GenericAttribute_var anAttr;
592 if(theIOR != NO_IOR){
593 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
594 SALOMEDS::AttributeIOR_var aCustomAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
595 aCustomAttr->SetValue(theIOR.c_str());
597 if(theName != NO_NAME){
598 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
599 SALOMEDS::AttributeName_var aCustomAttr = SALOMEDS::AttributeName::_narrow(anAttr);
600 aCustomAttr->SetValue(theName.c_str());
602 if(thePersistentRef != NO_PERFSITENT_REF){
603 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
604 SALOMEDS::AttributePersistentRef_var aCustomAttr = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
605 aCustomAttr->SetValue(thePersistentRef.c_str());
607 if(theComment != NO_COMMENT){
608 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
609 SALOMEDS::AttributeString_var aCustomAttr = SALOMEDS::AttributeString::_narrow(anAttr);
610 aCustomAttr->SetValue(theComment.c_str());
612 if(theIconName != NO_ICON){
613 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
614 SALOMEDS::AttributePixMap_var aCustomAttr = SALOMEDS::AttributePixMap::_narrow(anAttr);
615 aCustomAttr->SetPixMap(theIconName.c_str());
617 CORBA::String_var anEntry = aNewSObject->GetID();
618 std::string aRet(anEntry);
620 INFOS("CreateAttributes - StudyId = "<<theStudyDocument->StudyId()<<"; anEntry = "<<aRet<<"; IOR = '"<<theIOR<<"'");
625 CreateAttributes(_PTR(Study) theStudyDocument,
626 const std::string& theFatherEntry,
627 const std::string& theIconName,
628 const std::string& theIOR,
629 const std::string& theName,
630 const std::string& thePersistentRef,
631 const std::string& theComment,
632 CORBA::Boolean theCreateNew)
634 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
635 _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
636 _PTR(SObject) aNewSObject;
639 aNewSObject = aStudyBuilder->NewObject(aFather);
642 aNewSObject = aFather;
644 _PTR(GenericAttribute) anAttr;
645 if (theIOR != NO_IOR) {
646 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeIOR");
647 _PTR(AttributeIOR) aCustomAttr (anAttr);
648 aCustomAttr->SetValue(theIOR);
650 if (theName != NO_NAME) {
651 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeName");
652 _PTR(AttributeName) aCustomAttr (anAttr);
653 aCustomAttr->SetValue(theName);
655 if (thePersistentRef != NO_PERFSITENT_REF) {
656 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePersistentRef");
657 _PTR(AttributePersistentRef) aCustomAttr (anAttr);
658 aCustomAttr->SetValue(thePersistentRef);
660 if (theComment != NO_COMMENT) {
661 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributeString");
662 _PTR(AttributeString) aCustomAttr (anAttr);
663 aCustomAttr->SetValue(theComment);
665 if (theIconName != NO_ICON) {
666 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSObject, "AttributePixMap");
667 _PTR(AttributePixMap) aCustomAttr (anAttr);
668 aCustomAttr->SetPixMap(theIconName);
670 std::string aRet = aNewSObject->GetID();
672 INFOS("CreateAttributes - StudyId = " << theStudyDocument->StudyId()
673 << "; anEntry = " << aRet << "; IOR = '" << theIOR << "'");
678 //---------------------------------------------------------------
680 GenerateName(const std::string& theFmt, int /*theId*/) // theId was deprecated because of incorrect work IPAL21151
683 aName.sprintf("%s", theFmt.c_str());
686 SalomeApp_Application* anApp =
687 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
689 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
693 std::vector<_PTR(SObject)> aList = aStudy->studyDS()->FindObjectByName(aName.toLatin1().data(), "VISU");
694 if ( aList.size() > 0 ) {
696 aName.sprintf("%s:%d", theFmt.c_str(), count);
704 aName.sprintf("%s:%d", theFmt.c_str(), count);
710 //---------------------------------------------------------------
711 SALOMEDS::StudyManager_var
714 static SALOMEDS::StudyManager_var aStudyManager;
715 if(CORBA::is_nil(aStudyManager)){
716 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
717 CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
718 aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
720 return aStudyManager;
724 //---------------------------------------------------------------
726 GetDSStudy(_PTR(Study) theStudy)
728 int aStudyID = theStudy->StudyId();
729 return GetStudyManager()->GetStudyByID(aStudyID);
733 //---------------------------------------------------------------
734 struct TGetStudyEvent: public SALOME_Event
736 SALOMEDS::Study_var myStudy;
738 typedef SalomeApp_Study* TResult;
741 TGetStudyEvent(SALOMEDS::Study_ptr theStudy):
742 myStudy(SALOMEDS::Study::_duplicate(theStudy)),
750 if(CORBA::is_nil(myStudy))
753 int aStudyId = myStudy->StudyId();
754 SUIT_Session* aSession = SUIT_Session::session();
755 QList<SUIT_Application*> anApplications = aSession->applications();
756 QListIterator<SUIT_Application*> anIter (anApplications);
757 while ( anIter.hasNext() ) {
758 SUIT_Application* anApp = anIter.next();
759 if (SUIT_Study* aSStudy = anApp->activeStudy()) {
760 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
761 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
762 if (aStudyId == aCStudy->StudyId()) {
774 //---------------------------------------------------------------
776 GetGUIStudy(SALOMEDS::Study_ptr theStudy)
778 return ProcessEvent(new TGetStudyEvent(theStudy));
782 //---------------------------------------------------------------
784 GetStudy(SALOMEDS::Study_ptr theStudy)
786 if(SalomeApp_Study* aStudy = ProcessEvent(new TGetStudyEvent(theStudy)))
787 return aStudy->studyDS();
789 return _PTR(Study)();
793 //---------------------------------------------------------------
794 SALOMEDS::SObject_var
795 GetSObject( _PTR(SObject) obj )
797 _PTR(Study) aStudy = obj->GetStudy();
798 SALOMEDS::Study_var aSalomeDSStudy = GetDSStudy( aStudy );
799 std::string id = obj->GetID();
800 return aSalomeDSStudy->FindObjectID( id.c_str() );
803 //---------------------------------------------------------------
805 GetClientSObject(SALOMEDS::SObject_ptr theSObject,
806 _PTR(Study) theStudy)
808 CORBA::String_var anEntry = theSObject->GetID();
809 return theStudy->FindObjectID( anEntry.in() );
813 //---------------------------------------------------------------
815 RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
817 bool theDestroySubObjects)
819 if (theSObject->_is_nil()) return;
821 SALOMEDS::Study_var aStudyDocument = theSObject->GetStudy();
822 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
824 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
828 // Remove possible sub-objects
829 SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(theSObject);
830 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
831 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
832 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
833 if (CORBA::is_nil(aChildObj)) continue;
835 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
836 if (CORBA::is_nil(aRemovableObject)) continue;
838 aRemovableObject->RemoveFromStudy();
841 // asl, fix for PAL10455: Remove references to SObject
842 SALOMEDS::Study::ListOfSObject_var aRefs = aStudyDocument->FindDependances( theSObject );
843 for( int i=0, n=aRefs->length(); i<n; i++ )
845 SALOMEDS::SObject_var o = aRefs[i];
846 if( o->GetFatherComponent()->ComponentDataType()==theSObject->GetFatherComponent()->ComponentDataType() )
848 aStudyBuilder->RemoveReference( o );
849 aStudyBuilder->RemoveObjectWithChildren( o );
853 // Remove the SObject itself
854 aStudyBuilder->RemoveObjectWithChildren(theSObject);
858 //---------------------------------------------------------------
860 RemoveFromStudy (_PTR(SObject) theSObject,
862 bool theDestroySubObjects)
864 if (!theSObject) return;
866 _PTR(Study) aStudyDocument = theSObject->GetStudy();
867 _PTR(StudyBuilder) aStudyBuilder = aStudyDocument->NewBuilder();
869 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
873 // Remove possible sub-objects
874 _PTR(ChildIterator) aChildIter = aStudyDocument->NewChildIterator(theSObject);
875 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
876 _PTR(SObject) aChildSObject = aChildIter->Value();
877 CORBA::Object_var aChildObj = VISU::ClientSObjectToObject(aChildSObject);
878 if (CORBA::is_nil(aChildObj))
881 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
882 if (CORBA::is_nil(aRemovableObject))
885 aRemovableObject->RemoveFromStudy();
888 // Remove the SObject itself
889 aStudyBuilder->RemoveObjectWithChildren(theSObject);