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"
45 #include "Utils_CorbaException.hxx"
46 #include "Utils_ExceptHandlers.hxx"
48 #include <TDF_ChildIterator.hxx>
49 #include <TDF_Label.hxx>
50 #include <TDataStd_Name.hxx>
51 #include <TDataStd_Comment.hxx>
52 #include <TDataStd_UAttribute.hxx>
53 #include <TDataStd_Real.hxx>
54 #include <TDF_Tool.hxx>
55 #include <TDF_Reference.hxx>
56 #include <TDF_Data.hxx>
57 #include <TDataStd_ChildNodeIterator.hxx>
58 #include <TDF_ListIteratorOfAttributeList.hxx>
63 #define USE_CASE_LABEL_TAG 2
64 #define DIRECTORYID 16661
65 #define FILELOCALID 26662
67 #include "utilities.h"
71 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception);
72 UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection);
74 //============================================================================
75 /*! Function : constructor
78 //============================================================================
79 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDS_Study_i* theStudy,
80 const Handle(TDocStd_Document)& theDocument):
86 //============================================================================
87 /*! Function : destructor
90 //============================================================================
91 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
96 //============================================================================
97 CORBA::ORB_var SALOMEDS_StudyBuilder_i::GetORB() const
99 return _study->GetORB();
103 //============================================================================
104 PortableServer::POA_var SALOMEDS_StudyBuilder_i::GetPOA() const
106 return _study->GetPOA();
110 //============================================================================
111 /*! Function : NewComponent
112 * Purpose : Create a new component (Scomponent)
114 //============================================================================
115 SALOMEDS::SComponent_ptr
116 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
119 //Always create component under main label.
120 TDF_Label L = _doc->Main();
122 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
124 Standard_Integer imax = 0;
125 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
126 if (it.Value().Tag() > imax)
127 imax = it.Value().Tag();
130 TDF_Label NL = L.FindChild(imax);
132 TDataStd_Comment::Set(NL,Standard_CString(DataType));
133 // TDataStd_Comment::Set(NL,Standard_CString(CORBA::string_dup(DataType)));
135 SALOMEDS::SComponent_var aSComponent = SALOMEDS_SComponent_i::NewRef(_study,NL);
137 OnAddSObject(aSComponent);
139 return aSComponent._retn();
142 //============================================================================
143 /*! Function : DefineComponentInstance
144 * Purpose : Add IOR attribute of a Scomponent
146 //============================================================================
147 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr theComponent,
148 CORBA::Object_ptr theObject)
152 if(CORBA::is_nil(theComponent) || CORBA::is_nil(theObject))
157 CORBA::String_var aString = theComponent->GetID();
158 TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
160 //add theObject definition
161 aString = GetORB()->object_to_string(theObject);
162 SALOMEDS_IORAttribute::Set(Lab,const_cast<char*>(aString.in()),_study);
165 //============================================================================
166 /*! Function : RemoveComponent
167 * Purpose : Delete a Scomponent
169 //============================================================================
171 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr theComponent)
174 RemoveObject(theComponent);
177 //============================================================================
178 /*! Function : NewObject
179 * Purpose : Create a new SObject
181 //============================================================================
182 SALOMEDS::SObject_ptr
183 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
187 if(CORBA::is_nil(theFatherObject))
188 return SALOMEDS::SObject::_nil();
190 //Find label of father
192 TCollection_AsciiString anEntry;
194 CORBA::String_var aFatherID = theFatherObject->GetID();
195 TDF_Tool::Label(_doc->GetData(),aFatherID,aLabel);
198 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
199 Standard_Integer imax = 0;
200 for (TDF_ChildIterator it(aLabel); it.More(); it.Next()) {
201 if (it.Value().Tag() > imax)
202 imax = it.Value().Tag();
205 TDF_Label aNewLabel = aLabel.FindChild(imax);
207 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLabel);
209 OnAddSObject(aSObject);
211 return aSObject._retn();
214 //============================================================================
215 /*! Function : NewObjectToTag
218 //============================================================================
219 SALOMEDS::SObject_ptr
220 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
225 if(CORBA::is_nil(theFatherObject))
226 return SALOMEDS::SObject::_nil();
228 //Find label of father
230 CORBA::String_var aFatherID = theFatherObject->GetID();
231 TDF_Tool::Label(_doc->GetData(),aFatherID,Lab);
233 //Create or find label
234 TDF_Label aNewLab = Lab.FindChild(theTag,1);
236 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(_study,aNewLab);
238 OnAddSObject(aSObject);
240 return aSObject._retn();
243 //============================================================================
244 /*! Function : RemoveObject
247 //============================================================================
248 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr theSObject)
250 RemoveSObject(theSObject);
254 SALOMEDS_StudyBuilder_i::RemoveSObject(SALOMEDS::SObject_ptr theSObject,
255 bool theIsForgetAllAttributes)
259 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theSObject)){
260 OnRemoveSObject(theSObject);
261 aSObject->OnRemove();
262 if(theIsForgetAllAttributes){
263 TDF_Label aLabel = aSObject->GetLabel();
264 aLabel.ForgetAllAttributes();
272 //============================================================================
273 /*! Function : RemoveObjectWithChildren
276 //============================================================================
277 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr theSObject)
279 if(SALOMEDS_SObject_i* aSObject = RemoveSObject(theSObject,false)){
280 SALOMEDS_ChildIterator_i aChildIter(_study,aSObject->GetLabel(),true);
281 for(; aChildIter.More(); aChildIter.Next()){
282 if(SALOMEDS_SObject_i* aSObj = aChildIter.GetValue())
285 TDF_Label aLabel = aSObject->GetLabel();
286 aLabel.ForgetAllAttributes(Standard_True);
290 //============================================================================
291 /*! Function : Translate_persistentID_to_IOR
294 //============================================================================
295 static void Translate_persistentID_to_IOR(TDF_Label theLabel,
296 SALOMEDS::Driver_ptr theDriver,
297 SALOMEDS_Study_i* theStudy,
298 CORBA::Boolean theIsMultiFile,
299 CORBA::Boolean theIsASCII)
301 if(CORBA::is_nil(theDriver))
304 for (TDF_ChildIterator aChildIter (theLabel); aChildIter.More(); aChildIter.Next()){
305 TDF_Label aCurrentLabel = aChildIter.Value();
306 Handle(TDF_Attribute) anAttr;
307 if(aCurrentLabel.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),anAttr)){
308 Handle(SALOMEDS_LocalIDAttribute) anID;
309 if (aCurrentLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(),anID))
310 if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
312 TCollection_ExtendedString res = Handle(TDataStd_Comment)::DownCast(anAttr)->Get();
313 TCollection_AsciiString ch(res);
315 SALOMEDS::SObject_var aSObject = SALOMEDS_SObject_i::NewRef(theStudy,aCurrentLabel);
317 CORBA::String_var anIOR =
318 theDriver->LocalPersistentIDToIOR(aSObject,ch.ToCString(),theIsMultiFile,theIsASCII);
319 SALOMEDS_IORAttribute::Set(aCurrentLabel,const_cast<char*>(anIOR.in()),theStudy);
322 Translate_persistentID_to_IOR(aCurrentLabel,theDriver,theStudy,theIsMultiFile,theIsASCII);
326 //============================================================================
327 /*! Function : LoadWith
330 //============================================================================
332 //============================================================================
333 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr theSComponent,
334 SALOMEDS::Driver_ptr theDriver)
335 throw(SALOME::SALOME_Exception)
337 Unexpect aCatch(SBSalomeException);
339 if(CORBA::is_nil(theSComponent))
343 CORBA::String_var aString = theSComponent->GetID();
344 TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
346 //Find the current Url of the study
347 Handle(TDF_Attribute) Att;
348 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
349 if(CORBA::is_nil(theDriver))
352 int aLocked = _study->GetProperties()->IsLocked();
354 _study->GetProperties()->SetLocked(false);
356 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
357 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
359 _study->GetProperties()->SetLocked(true);
362 DefineComponentInstance (theSComponent,theDriver);
364 TCollection_AsciiString aHDFPath(Handle(TDataStd_Comment)::DownCast(Att)->Get());
366 bool isASCII = false;
367 std::ostringstream anURLStream;
368 if(HDFascii::isASCII(aHDFPath.ToCString())){
370 auto_ptr<char> aResultPath(HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString()));
371 anURLStream<<aResultPath.get()<<"hdf_from_ascii.hdf";
373 anURLStream<<aHDFPath.ToCString();
375 std::string aHDFUrl = anURLStream.str();
377 //Open the Study HDF file
378 auto_ptr<HDFfile> hdf_file(new HDFfile(const_cast<char*>(aHDFUrl.c_str())));
380 char aMultifileState[2];
381 char ASCIIfileState[2];
383 CORBA::String_var scoid = theSComponent->GetID();
384 hdf_file->OpenOnDisk(HDF_RDONLY);
385 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file.get());
386 hdf_group->OpenOnDisk();
387 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
388 hdf_sco_group->OpenOnDisk();
390 SALOMEDS::TMPFile_var aStreamFile;
391 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
392 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
393 hdf_dataset->OpenOnDisk();
394 int aStreamSize = hdf_dataset->GetSize();
395 unsigned char* aBuffer = new unsigned char[aStreamSize];
397 throw HDFexception("Unable to open dataset FILE_STREAM");
398 hdf_dataset->ReadFromDisk(aBuffer);
399 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
400 hdf_dataset->CloseOnDisk();
403 aStreamFile = new SALOMEDS::TMPFile(0);
405 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
406 multifile_hdf_dataset->OpenOnDisk();
407 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
409 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
410 ascii_hdf_dataset->OpenOnDisk();
411 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
413 // set path without file name from URL
414 std::string aDir(aHDFPath.ToCString());
415 aDir.substr(0,aDir.find('/'));
417 CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
418 theDriver->LoadASCII(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M'):
419 theDriver->Load(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M');
421 RemoveAttribute( theSComponent, "AttributeIOR" );
423 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
424 aFilesToRemove->length(1);
425 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
426 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
427 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
429 MESSAGE("Can't load component");
430 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
433 multifile_hdf_dataset->CloseOnDisk();
434 multifile_hdf_dataset = 0;
435 ascii_hdf_dataset->CloseOnDisk();
436 ascii_hdf_dataset = 0;
437 hdf_sco_group->CloseOnDisk();
439 hdf_group->CloseOnDisk();
441 hdf_file->CloseOnDisk();
444 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
445 aFilesToRemove->length(1);
446 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
447 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
448 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
451 catch (HDFexception) {
452 INFOS("No persistent file Name");
454 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
455 aFilesToRemove->length(1);
456 std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
457 aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
458 SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
461 _study->GetProperties()->SetLocked(true);
462 THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM);
466 Translate_persistentID_to_IOR(Lab,theDriver,_study,aMultifileState[0]=='M',ASCIIfileState[0] == 'A');
467 } catch (SALOME::SALOME_Exception) {
468 INFOS("Can't translate PersRef to IOR");
470 _study->GetProperties()->SetLocked(true);
471 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
472 // throw HDFexception("Unable to load component data");
475 _study->GetProperties()->SetLocked(true);
477 MESSAGE("No persistent file Name");
481 //============================================================================
485 //============================================================================
486 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
488 MESSAGE ( "This function is not yet implemented");
491 //============================================================================
492 /*! Function : FindOrCreateAttribute
493 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
496 //============================================================================
497 SALOMEDS::GenericAttribute_ptr
498 SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr theObject,
499 const char* theTypeOfAttribute)
501 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
502 return aSObject->FindOrCreateAttribute(theTypeOfAttribute);
504 return SALOMEDS::GenericAttribute::_nil();
507 //============================================================================
508 /*! Function : FindAttribute
509 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
511 //============================================================================
513 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr theObject,
514 SALOMEDS::GenericAttribute_out theAttr,
515 const char* theTypeOfAttribute)
517 if(SALOMEDS_SObject_i* aSObject = _study->DownCast(theObject))
518 return aSObject->FindAttribute(theAttr,theTypeOfAttribute);
520 return Standard_False;
523 //============================================================================
524 /*! Function : RemoveAttribute
525 * Purpose : Remove attribute of given type assigned SObject
527 //============================================================================
529 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr theSObject,
530 const char* aTypeOfAttribute)
534 if(CORBA::is_nil(theSObject))
538 CORBA::String_var anobid = theSObject->GetID();
539 TDF_Tool::Label(_doc->GetData(),anobid,Lab);
541 if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0) { // postponed removing of CORBA objects
542 Handle(SALOMEDS_IORAttribute) anAttr;
543 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
544 _study->AddPostponed(TCollection_AsciiString(anAttr->Get()).ToCString());
549 Lab.ForgetAttribute(SALOMEDS::GetGUID(aTypeOfAttribute));
552 //============================================================================
553 /*! Function : Addreference
556 //============================================================================
558 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
559 SALOMEDS::SObject_ptr theReferencedObject)
562 if(CORBA::is_nil(me) || CORBA::is_nil(theReferencedObject))
566 CORBA::String_var meid = me->GetID();
567 TDF_Tool::Label(_doc->GetData(),meid,Lab);
570 CORBA::String_var roid = theReferencedObject->GetID();
571 TDF_Tool::Label(_doc->GetData(),roid,RefLab);
573 TDF_Reference::Set(Lab,RefLab);
574 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
576 if(Lab.IsDescendant(_doc->Main()))
580 //============================================================================
581 /*! Function : RemoveReference
584 //============================================================================
585 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
587 SALOMEDS::SObject_var theReferencedObject;
588 if(!me->ReferencedObject(theReferencedObject)) return; //No reference is found
590 if(CORBA::is_nil(me) || CORBA::is_nil(theReferencedObject))
595 CORBA::String_var meid = me->GetID();
596 TDF_Tool::Label(_doc->GetData(),meid,Lab);
598 Lab.ForgetAttribute(TDF_Reference::GetID());
601 CORBA::String_var roid = theReferencedObject->GetID();
602 TDF_Tool::Label(_doc->GetData(),roid,RefLab);
604 RemoveAttribute(theReferencedObject, "AttributeTarget");
609 //============================================================================
610 /*! Function : AddDirectory
611 * Purpose : adds a new directory with a path = thePath
613 //============================================================================
614 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
617 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
619 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
620 Handle(TDataStd_Name) aName;
622 SALOMEDS::SObject_var anObject = SALOMEDS_SObject_i::NewRef(_study,_doc->Main());
625 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
629 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
631 if(aPath.Value(1) != '/') { //Relative path
633 aPath = TCollection_AsciiString(_study->GetContext()) + aPath;
636 TCollection_AsciiString aToken = aPath.Token("/", 1);
637 if(aToken.Length() == 0) aFatherPath = "/";
640 while(aToken.Length() != 0) {
641 if(aPath.Token("/", i+1).Length() > 0) {
643 aFatherPath += aToken;
645 aToken = aPath.Token("/", ++i);
648 anObject = SALOMEDS::SObject::_nil();
650 anObject = _study->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
653 if(anObject->_is_nil())
654 throw SALOMEDS::Study::StudyInvalidDirectory();
656 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
657 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
658 if(aLabel.IsNull()) {
659 MESSAGE("### NULL label");
660 throw SALOMEDS::Study::StudyInvalidComponent();
663 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
665 //Set LocalID attribute to identify the directory object
666 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID");
667 SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr);
668 if(aPersRef->_is_nil())
669 throw SALOMEDS::Study::StudyInvalidDirectory();
671 aPersRef->SetValue(DIRECTORYID);
675 //============================================================================
676 /*! Function : SetGUID
679 //============================================================================
680 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
684 if(CORBA::is_nil(anObject))
688 CORBA::String_var anEntry = anObject->GetID();
689 TDF_Tool::Label(_doc->GetData(), anEntry, aLabel);
690 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
693 //============================================================================
694 /*! Function : IsGUID
697 //============================================================================
698 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
700 if(CORBA::is_nil(anObject))
704 CORBA::String_var anEntry = anObject->GetID();
705 TDF_Tool::Label(_doc->GetData(), anEntry, aLabel);
706 return aLabel.IsAttribute((char*)theGUID);
710 //============================================================================
711 /*! Function : NewCommand
714 //============================================================================
715 void SALOMEDS_StudyBuilder_i::NewCommand()
717 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
718 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
719 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
720 anAttr = new SALOMEDS_StudyPropertiesAttribute;
721 _doc->Main().AddAttribute(anAttr);
723 anAttr->IsLockChanged(true);
728 //============================================================================
729 /*! Function : CommitCommand
732 //============================================================================
733 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
735 Unexpect aCatch(SBLockProtection);
736 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
737 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
738 anAttr = new SALOMEDS_StudyPropertiesAttribute;
739 _doc->Main().AddAttribute(anAttr);
741 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
742 MESSAGE("Locked document modification !!!");
744 throw SALOMEDS::StudyBuilder::LockProtection();
746 _study->RemovePostponed(_doc->GetUndoLimit());
748 int aModif = anAttr->GetModified();
749 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
750 anAttr->SetModified(aModif+1);
751 _doc->CommitCommand();
755 //============================================================================
756 /*! Function : HasOpenCommand
759 //============================================================================
760 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
762 return _doc->HasOpenCommand();
765 //============================================================================
766 /*! Function : AbortCommand
769 //============================================================================
770 void SALOMEDS_StudyBuilder_i::AbortCommand()
772 _study->UndoPostponed(0);
774 _doc->AbortCommand();
777 //============================================================================
781 //============================================================================
782 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
784 Unexpect aCatch(SBLockProtection);
785 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
786 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
787 anAttr = new SALOMEDS_StudyPropertiesAttribute;
788 _doc->Main().AddAttribute(anAttr);
790 if (anAttr->IsLocked()) {
791 MESSAGE("Locked document modification !!!");
792 throw SALOMEDS::StudyBuilder::LockProtection();
794 _study->UndoPostponed(1);
796 anAttr->SetModified(anAttr->GetModified()-1);
800 //============================================================================
804 //============================================================================
805 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
807 Unexpect aCatch(SBLockProtection);
808 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
809 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
810 anAttr = new SALOMEDS_StudyPropertiesAttribute;
811 _doc->Main().AddAttribute(anAttr);
814 if (anAttr->IsLocked()) {
815 MESSAGE("Locked document modification !!!");
816 throw SALOMEDS::StudyBuilder::LockProtection();
819 _study->UndoPostponed(-1);
820 anAttr->SetModified(anAttr->GetModified()+1);
824 //============================================================================
825 /*! Function : GetAvailableUndos
828 //============================================================================
829 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
831 return _doc->GetAvailableUndos();
834 //============================================================================
835 /*! Function : GetAvailableRedos
838 //============================================================================
839 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
841 return _doc->GetAvailableRedos();
844 //============================================================================
845 /*! Function : UndoLimit
848 //============================================================================
849 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
851 return _doc->GetUndoLimit();
854 //============================================================================
855 /*! Function : UndoLimit
858 //============================================================================
859 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
862 _doc->SetUndoLimit (n);
865 //============================================================================
866 /*! Function : SetOnAddSObject
869 //============================================================================
870 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
872 return _study->SetOnAddSObject(theCallback);
875 void SALOMEDS_StudyBuilder_i::OnAddSObject(SALOMEDS::SObject_ptr theObject)
877 _study->OnAddSObject(theObject);
880 //============================================================================
881 /*! Function : SetOnNewSObject
884 //============================================================================
885 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
887 return _study->SetOnRemoveSObject(theCallback);
890 void SALOMEDS_StudyBuilder_i::OnRemoveSObject(SALOMEDS::SObject_ptr theObject)
892 _study->OnRemoveSObject(theObject);
895 //============================================================================
896 /*! Function : CheckLocked
899 //============================================================================
900 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) {
901 _study->CheckLocked();
904 //============================================================================
905 /*! Function : SetName
908 //============================================================================
909 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
910 throw(SALOMEDS::StudyBuilder::LockProtection)
912 Unexpect aCatch(SBLockProtection);
915 if(CORBA::is_nil(theSO))
920 CORBA::String_var aSOID = theSO->GetID();
921 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
922 TDataStd_Name::Set(aLabel, (char*)theValue);
925 //============================================================================
926 /*! Function : SetComment
929 //============================================================================
930 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
931 throw(SALOMEDS::StudyBuilder::LockProtection)
933 Unexpect aCatch(SBLockProtection);
936 if(CORBA::is_nil(theSO))
941 CORBA::String_var aSOID = theSO->GetID();
942 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
943 TDataStd_Comment::Set(aLabel, (char*)theValue);
946 //============================================================================
947 /*! Function : SetIOR
950 //============================================================================
951 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
952 throw(SALOMEDS::StudyBuilder::LockProtection)
954 Unexpect aCatch(SBLockProtection);
957 if(CORBA::is_nil(theSO))
962 CORBA::String_var aSOID = theSO->GetID();
963 TDF_Tool::Label(_doc->GetData(), aSOID, aLabel);
964 SALOMEDS_IORAttribute::Set(aLabel, TCollection_ExtendedString((char*)theValue),_study);