1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOMEDS_StudyBuilder_i.cxx
25 // Author : Yves FRICAUD
29 #include "SALOMEDS_StudyBuilder_i.hxx"
30 #include "SALOMEDS_StudyManager_i.hxx"
31 #include "SALOMEDS_Study_i.hxx"
33 #include "SALOMEDS_SObject_i.hxx"
34 #include "SALOMEDS_SComponent_i.hxx"
35 #include "SALOMEDS_ChildIterator_i.hxx"
37 #include "SALOMEDS_TargetAttribute.hxx"
38 #include "SALOMEDS_IORAttribute.hxx"
39 #include "SALOMEDS_PersRefAttribute.hxx"
40 #include "SALOMEDS_LocalIDAttribute.hxx"
41 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
43 #include "SALOMEDS_Tool.hxx"
44 #include "SALOMEDS.hxx"
46 #include "Utils_CorbaException.hxx"
47 #include "Utils_ExceptHandlers.hxx"
49 #include <TDF_ChildIterator.hxx>
50 #include <TDF_Label.hxx>
51 #include <TDataStd_Name.hxx>
52 #include <TDataStd_Comment.hxx>
53 #include <TDataStd_UAttribute.hxx>
54 #include <TDataStd_Real.hxx>
55 #include <TDF_Tool.hxx>
56 #include <TDF_Reference.hxx>
57 #include <TDF_Data.hxx>
58 #include <TDataStd_ChildNodeIterator.hxx>
59 #include <TDF_ListIteratorOfAttributeList.hxx>
64 #define USE_CASE_LABEL_TAG 2
65 #define DIRECTORYID 16661
66 #define FILELOCALID 26662
68 #include "utilities.h"
72 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception);
73 UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection);
75 //============================================================================
76 /*! Function : constructor
79 //============================================================================
80 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDS_Study_i* theStudy,
81 const Handle(TDocStd_Document)& theDocument):
87 //============================================================================
88 /*! Function : destructor
91 //============================================================================
92 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
97 //============================================================================
98 CORBA::ORB_var SALOMEDS_StudyBuilder_i::GetORB() const
100 return _study->GetORB();
104 //============================================================================
105 PortableServer::POA_var SALOMEDS_StudyBuilder_i::GetPOA() const
107 return _study->GetPOA();
111 //============================================================================
112 /*! Function : NewComponent
113 * Purpose : Create a new component (Scomponent)
115 //============================================================================
116 SALOMEDS::SComponent_ptr
117 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
119 SALOMEDS::Locker lock;
122 //Always create component under main label.
123 TDF_Label L = _doc->Main();
125 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
127 Standard_Integer imax = 0;
128 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
129 if (it.Value().Tag() > imax)
130 imax = it.Value().Tag();
133 TDF_Label NL = L.FindChild(imax);
135 TDataStd_Comment::Set(NL,Standard_CString(DataType));
136 // TDataStd_Comment::Set(NL,Standard_CString(CORBA::string_dup(DataType)));
138 SALOMEDS::SComponent_var aSComponent = SALOMEDS_SComponent_i::NewRef(_study,NL);
140 OnAddSObject(aSComponent);
142 return aSComponent._retn();
145 //============================================================================
146 /*! Function : DefineComponentInstance
147 * Purpose : Add IOR attribute of a Scomponent
149 //============================================================================
150 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr theComponent,
151 CORBA::Object_ptr theObject)
153 SALOMEDS::Locker lock;
157 if(CORBA::is_nil(theComponent) || CORBA::is_nil(theObject))
162 CORBA::String_var aString = theComponent->GetID();
163 TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
165 //add theObject definition
166 aString = GetORB()->object_to_string(theObject);
167 SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),_study);
170 //============================================================================
171 /*! Function : RemoveComponent
172 * Purpose : Delete a Scomponent
174 //============================================================================
176 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr theComponent)
178 SALOMEDS::Locker lock;
181 RemoveObject(theComponent);
184 //============================================================================
185 /*! Function : NewObject
186 * Purpose : Create a new SObject
188 //============================================================================
189 SALOMEDS::SObject_ptr
190 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
192 SALOMEDS::Locker lock;
196 if(CORBA::is_nil(theFatherObject))
197 return SALOMEDS::SObject::_nil();
199 //Find label of father
201 TCollection_AsciiString anEntry;
203 CORBA::String_var aFatherID = theFatherObject->GetID();
204 TDF_Tool::Label(_doc->GetData(),aFatherID,aLabel);
207 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
208 Standard_Integer imax = 0;
209 for (TDF_ChildIterator it(aLabel); it.More(); it.Next()) {
210 if (it.Value().Tag() > imax)
211 imax = it.Value().Tag();
214 TDF_Label aNewLabel = aLabel.FindChild(imax);
216 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLabel);
218 OnAddSObject(aSObject);
220 return aSObject._retn();
223 //============================================================================
224 /*! Function : NewObjectToTag
227 //============================================================================
228 SALOMEDS::SObject_ptr
229 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
232 SALOMEDS::Locker lock;
236 if(CORBA::is_nil(theFatherObject))
237 return SALOMEDS::SObject::_nil();
239 //Find label of father
241 CORBA::String_var aFatherID = theFatherObject->GetID();
242 TDF_Tool::Label(_doc->GetData(),aFatherID,Lab);
244 //Create or find label
245 TDF_Label aNewLab = Lab.FindChild(theTag,1);
247 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLab);
249 OnAddSObject(aSObject);
251 return aSObject._retn();
254 //============================================================================
255 /*! Function : RemoveObject
258 //============================================================================
259 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr theSObject)
261 SALOMEDS::Locker lock;
263 RemoveSObject(theSObject);
267 SALOMEDS_StudyBuilder_i::RemoveSObject(SALOMEDS::SObject_ptr theSObject,
268 bool theIsForgetAllAttributes)
272 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theSObject)){
273 OnRemoveSObject(theSObject);
274 aSObject->OnRemove();
275 if(theIsForgetAllAttributes){
276 TDF_Label aLabel = aSObject->GetLabel();
277 aLabel.ForgetAllAttributes();
285 //============================================================================
286 /*! Function : RemoveObjectWithChildren
289 //============================================================================
290 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr theSObject)
292 SALOMEDS::Locker lock;
294 if(SALOMEDS_SObject_i* aSObject = RemoveSObject(theSObject,false)){
295 SALOMEDS_ChildIterator_i aChildIter(_study,aSObject->GetLabel(),true);
296 for(; aChildIter.More(); aChildIter.Next()){
297 if(SALOMEDS_SObject_i* aSObj = aChildIter.GetValue())
300 TDF_Label aLabel = aSObject->GetLabel();
301 aLabel.ForgetAllAttributes(Standard_True);
305 //============================================================================
306 /*! Function : Translate_persistentID_to_IOR
309 //============================================================================
310 static void Translate_persistentID_to_IOR(TDF_Label theLabel,
311 SALOMEDS::Driver_ptr theDriver,
312 SALOMEDS_Study_i* theStudy,
313 CORBA::Boolean theIsMultiFile,
314 CORBA::Boolean theIsASCII)
316 if(CORBA::is_nil(theDriver))
319 for (TDF_ChildIterator aChildIter (theLabel); aChildIter.More(); aChildIter.Next()){
320 TDF_Label aCurrentLabel = aChildIter.Value();
321 Handle(TDF_Attribute) anAttr;
322 if(aCurrentLabel.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),anAttr)){
323 Handle(SALOMEDS_LocalIDAttribute) anID;
324 if (aCurrentLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(),anID))
325 if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
327 TCollection_ExtendedString res = Handle(TDataStd_Comment)::DownCast(anAttr)->Get();
328 TCollection_AsciiString ch(res);
330 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(theStudy,aCurrentLabel);
332 // PAL8065: san - Translate_persistentID_to_IOR() should always be called from some CORBA method
333 // protected with a lock
335 CORBA::String_var anIOR =
336 theDriver->LocalPersistentIDToIOR(aSObject,ch.ToCString(),theIsMultiFile,theIsASCII);
339 SALOMEDS_IORAttribute::Set(aCurrentLabel,const_cast<char*>(anIOR.in()),theStudy);
342 Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theStudy,theIsMultiFile,theIsASCII);
346 //============================================================================
347 /*! Function : LoadWith
350 //============================================================================
352 //============================================================================
353 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr theSComponent,
354 SALOMEDS::Driver_ptr theDriver)
355 throw(SALOME::SALOME_Exception)
357 SALOMEDS::Locker lock;
359 Unexpect aCatch(SBSalomeException);
361 if(CORBA::is_nil(theSComponent))
365 CORBA::String_var aString = theSComponent->GetID();
366 TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
368 //Find the current Url of the study
369 Handle(TDF_Attribute) Att;
370 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
371 if(CORBA::is_nil(theDriver))
374 int aLocked = _study->GetProperties()->IsLocked();
376 _study->GetProperties()->SetLocked(false);
378 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
379 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
381 _study->GetProperties()->SetLocked(true);
384 DefineComponentInstance (theSComponent,theDriver);
386 TCollection_AsciiString aHDFPath(Handle(TDataStd_Comment)::DownCast(Att)->Get());
388 bool isASCII = false;
389 std::ostringstream anURLStream;
390 if(HDFascii::isASCII(aHDFPath.ToCString())){
392 auto_ptr<char> aResultPath(HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString()));
393 anURLStream<<aResultPath.get()<<"hdf_from_ascii.hdf";
395 anURLStream<<aHDFPath.ToCString();
397 std::string aHDFUrl = anURLStream.str();
399 //Open the Study HDF file
400 auto_ptr<HDFfile> hdf_file(new HDFfile(const_cast<char*>(aHDFUrl.c_str())));
402 char aMultifileState[2];
403 char ASCIIfileState[2];
405 CORBA::String_var scoid = theSComponent->GetID();
406 hdf_file->OpenOnDisk(HDF_RDONLY);
407 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file.get());
408 hdf_group->OpenOnDisk();
409 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
410 hdf_sco_group->OpenOnDisk();
412 SALOMEDS::TMPFile_var aStreamFile;
413 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
414 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
415 hdf_dataset->OpenOnDisk();
416 int aStreamSize = hdf_dataset->GetSize();
417 unsigned char* aBuffer = new unsigned char[aStreamSize];
419 throw HDFexception("Unable to open dataset FILE_STREAM");
420 hdf_dataset->ReadFromDisk(aBuffer);
421 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
422 hdf_dataset->CloseOnDisk();
425 aStreamFile = new SALOMEDS::TMPFile(0);
427 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
428 multifile_hdf_dataset->OpenOnDisk();
429 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
431 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
432 ascii_hdf_dataset->OpenOnDisk();
433 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
435 // set path without file name from URL
436 std::string aDir(aHDFPath.ToCString());
437 aDir = aDir.substr(0,aDir.rfind('/') + 1);
440 CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
441 theDriver->LoadASCII(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M'):
442 theDriver->Load(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M');
446 RemoveAttribute( theSComponent, "AttributeIOR" );
448 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
449 aFilesToRemove->length(1);
450 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
451 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
452 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
454 MESSAGE("Can't load component");
455 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
458 multifile_hdf_dataset->CloseOnDisk();
459 multifile_hdf_dataset = 0;
460 ascii_hdf_dataset->CloseOnDisk();
461 ascii_hdf_dataset = 0;
462 hdf_sco_group->CloseOnDisk();
464 hdf_group->CloseOnDisk();
466 hdf_file->CloseOnDisk();
469 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
470 aFilesToRemove->length(1);
471 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
472 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
473 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
476 catch (HDFexception) {
477 INFOS("No persistent file Name");
479 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
480 aFilesToRemove->length(1);
481 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
482 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
483 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
486 _study->GetProperties()->SetLocked(true);
487 THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM);
491 Translate_persistentID_to_IOR(Lab,theDriver,_study,aMultifileState[0]=='M',ASCIIfileState[0] == 'A');
492 } catch (SALOME::SALOME_Exception) {
493 INFOS("Can't translate PersRef to IOR");
495 _study->GetProperties()->SetLocked(true);
496 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
497 // throw HDFexception("Unable to load component data");
500 _study->GetProperties()->SetLocked(true);
502 MESSAGE("No persistent file Name");
506 //============================================================================
510 //============================================================================
511 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
513 MESSAGE ( "This function is not yet implemented");
516 //============================================================================
517 /*! Function : FindOrCreateAttribute
518 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
521 //============================================================================
522 SALOMEDS::GenericAttribute_ptr
523 SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr theObject,
524 const char* theTypeOfAttribute)
526 SALOMEDS::Locker lock;
528 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
529 return aSObject->FindOrCreateAttribute(theTypeOfAttribute);
531 return SALOMEDS::GenericAttribute::_nil();
534 //============================================================================
535 /*! Function : FindAttribute
536 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
538 //============================================================================
540 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr theObject,
541 SALOMEDS::GenericAttribute_out theAttr,
542 const char* theTypeOfAttribute)
544 SALOMEDS::Locker lock;
546 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
547 return aSObject->FindAttribute(theAttr,theTypeOfAttribute);
549 return Standard_False;
552 //============================================================================
553 /*! Function : RemoveAttribute
554 * Purpose : Remove attribute of given type assigned SObject
556 //============================================================================
558 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr theSObject,
559 const char* aTypeOfAttribute)
561 SALOMEDS::Locker lock;
565 if(CORBA::is_nil(theSObject))
569 CORBA::String_var anobid = theSObject->GetID();
570 TDF_Tool::Label(_doc->GetData(),anobid,Lab);
572 if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0) { // postponed removing of CORBA objects
573 Handle(SALOMEDS_IORAttribute) anAttr;
574 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
575 _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
580 Lab.ForgetAttribute(SALOMEDS::GetGUID(aTypeOfAttribute));
583 //============================================================================
584 /*! Function : Addreference
587 //============================================================================
589 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
590 SALOMEDS::SObject_ptr theReferencedObject)
592 SALOMEDS::Locker lock;
595 if(CORBA::is_nil(me) || CORBA::is_nil(theReferencedObject))
599 CORBA::String_var meid = me->GetID();
600 TDF_Tool::Label(_doc->GetData(),meid,Lab);
603 CORBA::String_var roid = theReferencedObject->GetID();
604 TDF_Tool::Label(_doc->GetData(),roid,RefLab);
606 TDF_Reference::Set(Lab,RefLab);
607 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
609 if(Lab.IsDescendant(_doc->Main()))
613 //============================================================================
614 /*! Function : RemoveReference
617 //============================================================================
618 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
620 SALOMEDS::Locker lock;
622 SALOMEDS::SObject_var theReferencedObject;
623 if(!me->ReferencedObject(theReferencedObject)) return; //No reference is found
625 if(CORBA::is_nil(me) || CORBA::is_nil(theReferencedObject))
630 CORBA::String_var meid = me->GetID();
631 TDF_Tool::Label(_doc->GetData(),meid,Lab);
633 Lab.ForgetAttribute(TDF_Reference::GetID());
636 CORBA::String_var roid = theReferencedObject->GetID();
637 TDF_Tool::Label(_doc->GetData(),roid,RefLab);
639 RemoveAttribute(theReferencedObject, "AttributeTarget");
644 //============================================================================
645 /*! Function : AddDirectory
646 * Purpose : adds a new directory with a path = thePath
648 //============================================================================
649 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
651 SALOMEDS::Locker lock;
654 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
656 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
657 Handle(TDataStd_Name) aName;
659 SALOMEDS::SObject_var anObject = SALOMEDS_SObject_i::NewRef(_study,_doc->Main());
662 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
666 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
668 if(aPath.Value(1) != '/') { //Relative path
670 aPath = TCollection_AsciiString(_study->GetContext()) + aPath;
673 TCollection_AsciiString aToken = aPath.Token("/", 1);
674 if(aToken.Length() == 0) aFatherPath = "/";
677 while(aToken.Length() != 0) {
678 if(aPath.Token("/", i+1).Length() > 0) {
680 aFatherPath += aToken;
682 aToken = aPath.Token("/", ++i);
685 anObject = SALOMEDS::SObject::_nil();
687 anObject = _study->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
690 if(anObject->_is_nil())
691 throw SALOMEDS::Study::StudyInvalidDirectory();
693 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
694 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
695 if(aLabel.IsNull()) {
696 MESSAGE("### NULL label");
697 throw SALOMEDS::Study::StudyInvalidComponent();
700 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
702 //Set LocalID attribute to identify the directory object
703 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID");
704 SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr);
705 if(aPersRef->_is_nil())
706 throw SALOMEDS::Study::StudyInvalidDirectory();
708 aPersRef->SetValue(DIRECTORYID);
712 //============================================================================
713 /*! Function : SetGUID
716 //============================================================================
717 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
719 SALOMEDS::Locker lock;
723 if(CORBA::is_nil(anObject))
727 CORBA::String_var anEntry = anObject->GetID();
728 TDF_Tool::Label(_doc->GetData(), anEntry, aLabel);
729 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
732 //============================================================================
733 /*! Function : IsGUID
736 //============================================================================
737 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
739 SALOMEDS::Locker lock;
741 if(CORBA::is_nil(anObject))
745 CORBA::String_var anEntry = anObject->GetID();
746 TDF_Tool::Label(_doc->GetData(), anEntry, aLabel);
747 return aLabel.IsAttribute((char*)theGUID);
751 //============================================================================
752 /*! Function : NewCommand
755 //============================================================================
756 void SALOMEDS_StudyBuilder_i::NewCommand()
758 SALOMEDS::Locker lock;
760 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
761 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
762 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
763 anAttr = new SALOMEDS_StudyPropertiesAttribute;
764 _doc->Main().AddAttribute(anAttr);
766 anAttr->IsLockChanged(true);
771 //============================================================================
772 /*! Function : CommitCommand
775 //============================================================================
776 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
778 SALOMEDS::Locker lock;
780 Unexpect aCatch(SBLockProtection);
781 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
782 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
783 anAttr = new SALOMEDS_StudyPropertiesAttribute;
784 _doc->Main().AddAttribute(anAttr);
786 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
787 MESSAGE("Locked document modification !!!");
789 throw SALOMEDS::StudyBuilder::LockProtection();
791 _study->RemovePostponed(_doc->GetUndoLimit());
793 int aModif = anAttr->GetModified();
794 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
795 anAttr->SetModified(aModif+1);
796 _doc->CommitCommand();
800 //============================================================================
801 /*! Function : HasOpenCommand
804 //============================================================================
805 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
807 SALOMEDS::Locker lock;
809 return _doc->HasOpenCommand();
812 //============================================================================
813 /*! Function : AbortCommand
816 //============================================================================
817 void SALOMEDS_StudyBuilder_i::AbortCommand()
819 SALOMEDS::Locker lock;
821 _study->UndoPostponed(0);
823 _doc->AbortCommand();
826 //============================================================================
830 //============================================================================
831 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
833 SALOMEDS::Locker lock;
835 Unexpect aCatch(SBLockProtection);
836 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
837 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
838 anAttr = new SALOMEDS_StudyPropertiesAttribute;
839 _doc->Main().AddAttribute(anAttr);
841 if (anAttr->IsLocked()) {
842 MESSAGE("Locked document modification !!!");
843 throw SALOMEDS::StudyBuilder::LockProtection();
845 _study->UndoPostponed(1);
847 anAttr->SetModified(anAttr->GetModified()-1);
851 //============================================================================
855 //============================================================================
856 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
858 SALOMEDS::Locker lock;
860 Unexpect aCatch(SBLockProtection);
861 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
862 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
863 anAttr = new SALOMEDS_StudyPropertiesAttribute;
864 _doc->Main().AddAttribute(anAttr);
867 if (anAttr->IsLocked()) {
868 MESSAGE("Locked document modification !!!");
869 throw SALOMEDS::StudyBuilder::LockProtection();
872 _study->UndoPostponed(-1);
873 anAttr->SetModified(anAttr->GetModified()+1);
877 //============================================================================
878 /*! Function : GetAvailableUndos
881 //============================================================================
882 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
884 SALOMEDS::Locker lock;
886 return _doc->GetAvailableUndos();
889 //============================================================================
890 /*! Function : GetAvailableRedos
893 //============================================================================
894 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
896 SALOMEDS::Locker lock;
898 return _doc->GetAvailableRedos();
901 //============================================================================
902 /*! Function : UndoLimit
905 //============================================================================
906 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
908 SALOMEDS::Locker lock;
910 return _doc->GetUndoLimit();
913 //============================================================================
914 /*! Function : UndoLimit
917 //============================================================================
918 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
920 SALOMEDS::Locker lock;
923 _doc->SetUndoLimit (n);
926 //============================================================================
927 /*! Function : SetOnAddSObject
930 //============================================================================
931 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
933 return _study->SetOnAddSObject(theCallback);
936 void SALOMEDS_StudyBuilder_i::OnAddSObject(SALOMEDS::SObject_ptr theObject)
938 _study->OnAddSObject(theObject);
941 //============================================================================
942 /*! Function : SetOnNewSObject
945 //============================================================================
946 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
948 return _study->SetOnRemoveSObject(theCallback);
951 void SALOMEDS_StudyBuilder_i::OnRemoveSObject(SALOMEDS::SObject_ptr theObject)
953 _study->OnRemoveSObject(theObject);
956 //============================================================================
957 /*! Function : CheckLocked
960 //============================================================================
961 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) {
962 _study->CheckLocked();
965 //============================================================================
966 /*! Function : SetName
969 //============================================================================
970 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
971 throw(SALOMEDS::StudyBuilder::LockProtection)
973 SALOMEDS::Locker lock;
975 Unexpect aCatch(SBLockProtection);
978 if(CORBA::is_nil(theSO))
983 CORBA::String_var aSOID = theSO->GetID();
984 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
985 TDataStd_Name::Set(aLabel, (char*)theValue);
988 //============================================================================
989 /*! Function : SetComment
992 //============================================================================
993 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
994 throw(SALOMEDS::StudyBuilder::LockProtection)
996 SALOMEDS::Locker lock;
998 Unexpect aCatch(SBLockProtection);
1001 if(CORBA::is_nil(theSO))
1006 CORBA::String_var aSOID = theSO->GetID();
1007 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
1008 TDataStd_Comment::Set(aLabel, (char*)theValue);
1011 //============================================================================
1012 /*! Function : SetIOR
1015 //============================================================================
1016 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
1017 throw(SALOMEDS::StudyBuilder::LockProtection)
1019 SALOMEDS::Locker lock;
1021 Unexpect aCatch(SBLockProtection);
1024 if(CORBA::is_nil(theSO))
1029 CORBA::String_var aSOID = theSO->GetID();
1030 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
1031 SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),_study);