1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_StudyBuilder_i.cxx
21 // Author : Seregy RUIN
25 #include "utilities.h"
26 #include "SALOMEDS_StudyBuilder_i.hxx"
27 #include "SALOMEDS_Study_i.hxx"
28 #include "SALOMEDS_SObject_i.hxx"
29 #include "SALOMEDS_SComponent_i.hxx"
30 #include "SALOMEDS_GenericAttribute_i.hxx"
31 #include "SALOMEDS_Driver_i.hxx"
32 #include "SALOMEDS.hxx"
34 #include "SALOMEDSImpl_Study.hxx"
35 #include "SALOMEDSImpl_SObject.hxx"
36 #include "SALOMEDSImpl_SComponent.hxx"
38 #include "Utils_CorbaException.hxx"
39 #include "Utils_ExceptHandlers.hxx"
41 #include <DF_Attribute.hxx>
42 #include <DF_Document.hxx>
47 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception);
48 UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection);
50 //============================================================================
51 /*! Function : constructor
54 //============================================================================
55 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDSImpl_StudyBuilder* theImpl,
58 _orb = CORBA::ORB::_duplicate(orb);
62 //============================================================================
63 /*! Function : destructor
66 //============================================================================
67 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
70 //============================================================================
71 /*! Function : NewComponent
72 * Purpose : Create a new component (Scomponent)
74 //============================================================================
75 SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
77 SALOMEDS::Locker lock;
79 //char* aDataType = CORBA::string_dup(DataType);
80 SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(string(DataType));
81 //CORBA::free_string(aDataType);
82 if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil();
84 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb);
88 //============================================================================
89 /*! Function : DefineComponentInstance
90 * Purpose : Add IOR attribute of a Scomponent
92 //============================================================================
93 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
94 CORBA::Object_ptr IOR)
96 SALOMEDS::Locker lock;
98 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(aComponent->GetID());
100 CORBA::String_var iorstr = _orb->object_to_string(IOR);
101 _impl->DefineComponentInstance(aSCO, (char*)iorstr.in());
104 //============================================================================
105 /*! Function : RemoveComponent
106 * Purpose : Delete a Scomponent
108 //============================================================================
109 void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
111 SALOMEDS::Locker lock;
113 ASSERT(!CORBA::is_nil(aComponent));
114 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(aComponent->GetID());
115 _impl->RemoveComponent(aSCO);
118 //============================================================================
119 /*! Function : NewObject
120 * Purpose : Create a new SObject
122 //============================================================================
123 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
125 SALOMEDS::Locker lock;
128 SALOMEDSImpl_SObject aFO, aSO;
129 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
130 aSO = _impl->NewObject(aFO);
131 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
132 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
137 //============================================================================
138 /*! Function : NewObjectToTag
141 //============================================================================
142 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
145 SALOMEDS::Locker lock;
147 SALOMEDSImpl_SObject aFO, aSO;
148 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
149 aSO = _impl->NewObjectToTag(aFO, atag);
150 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
151 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
155 //============================================================================
156 /*! Function : RemoveObject
159 //============================================================================
160 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
162 SALOMEDS::Locker lock;
164 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
165 _impl->RemoveObject(aSO);
168 //============================================================================
169 /*! Function : RemoveObjectWithChildren
172 //============================================================================
173 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
175 SALOMEDS::Locker lock;
177 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
178 _impl->RemoveObjectWithChildren(aSO);
181 //============================================================================
182 /*! Function : LoadWith
185 //============================================================================
186 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
187 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
189 SALOMEDS::Locker lock;
190 Unexpect aCatch(SBSalomeException);
192 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anSCO->GetID());
193 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
194 bool isDone = _impl->LoadWith(aSCO, driver);
197 if(!isDone && _impl->IsError()) {
198 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
203 //============================================================================
207 //============================================================================
208 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
210 MESSAGE ( "This function is not yet implemented");
213 //============================================================================
214 /*! Function : FindOrCreateAttribute
215 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
218 //============================================================================
219 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
220 const char* aTypeOfAttribute)
222 SALOMEDS::Locker lock;
223 CORBA::String_var anID = anObject->GetID();
224 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
225 DF_Attribute* anAttr;
227 anAttr = _impl->FindOrCreateAttribute(aSO, string(aTypeOfAttribute));
230 throw SALOMEDS::StudyBuilder::LockProtection();
233 SALOMEDS::GenericAttribute_var anAttribute;
236 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
238 return anAttribute._retn();
241 //============================================================================
242 /*! Function : FindAttribute
243 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
245 //============================================================================
247 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
248 SALOMEDS::GenericAttribute_out anAttribute,
249 const char* aTypeOfAttribute)
251 SALOMEDS::Locker lock;
252 ASSERT(!CORBA::is_nil(anObject));
253 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
254 DF_Attribute* anAttr;
256 if(!_impl->FindAttribute(aSO, anAttr, string(aTypeOfAttribute))) return false;
258 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
262 //============================================================================
263 /*! Function : RemoveAttribute
264 * Purpose : Remove attribute of given type assigned SObject
266 //============================================================================
268 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
269 const char* aTypeOfAttribute)
271 SALOMEDS::Locker lock;
273 ASSERT(!CORBA::is_nil(anObject));
274 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
275 _impl->RemoveAttribute(aSO, string(aTypeOfAttribute));
278 //============================================================================
279 /*! Function : Addreference
282 //============================================================================
283 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
284 SALOMEDS::SObject_ptr theReferencedObject)
286 SALOMEDS::Locker lock;
288 ASSERT(!CORBA::is_nil(me));
289 ASSERT(!CORBA::is_nil(theReferencedObject));
291 SALOMEDSImpl_SObject aSO, aRefSO;
292 aSO = _impl->GetOwner()->GetSObject(me->GetID());
293 aRefSO = _impl->GetOwner()->GetSObject(theReferencedObject->GetID());
294 _impl->Addreference(aSO, aRefSO);
297 //============================================================================
298 /*! Function : RemoveReference
301 //============================================================================
302 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
304 SALOMEDS::Locker lock;
306 ASSERT(!CORBA::is_nil(me));
307 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(me->GetID());
308 _impl->RemoveReference(aSO);
312 //============================================================================
313 /*! Function : AddDirectory
314 * Purpose : adds a new directory with a path = thePath
316 //============================================================================
317 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
319 SALOMEDS::Locker lock;
321 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
322 if(!_impl->AddDirectory(string(thePath))) {
323 string anErrorCode = _impl->GetErrorCode();
324 if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed();
325 if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory();
326 if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();
331 //============================================================================
332 /*! Function : SetGUID
335 //============================================================================
336 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
338 SALOMEDS::Locker lock;
340 ASSERT(!CORBA::is_nil(anObject));
341 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
342 _impl->SetGUID(aSO, string(theGUID));
345 //============================================================================
346 /*! Function : IsGUID
349 //============================================================================
350 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
352 SALOMEDS::Locker lock;
353 ASSERT(!CORBA::is_nil(anObject));
354 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
355 return _impl->IsGUID(aSO, string(theGUID));
359 //============================================================================
360 /*! Function : NewCommand
363 //============================================================================
364 void SALOMEDS_StudyBuilder_i::NewCommand()
366 SALOMEDS::Locker lock;
370 //============================================================================
371 /*! Function : CommitCommand
374 //============================================================================
375 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
377 SALOMEDS::Locker lock;
378 Unexpect aCatch(SBLockProtection);
380 _impl->CommitCommand();
383 MESSAGE("Locked document modification !!!");
384 throw SALOMEDS::StudyBuilder::LockProtection();
388 //============================================================================
389 /*! Function : HasOpenCommand
392 //============================================================================
393 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
395 SALOMEDS::Locker lock;
396 return _impl->HasOpenCommand();
399 //============================================================================
400 /*! Function : AbortCommand
403 //============================================================================
404 void SALOMEDS_StudyBuilder_i::AbortCommand()
406 SALOMEDS::Locker lock;
407 _impl->AbortCommand();
410 //============================================================================
414 //============================================================================
415 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
417 SALOMEDS::Locker lock;
418 Unexpect aCatch(SBLockProtection);
423 MESSAGE("Locked document modification !!!");
424 throw SALOMEDS::StudyBuilder::LockProtection();
428 //============================================================================
432 //============================================================================
433 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
435 SALOMEDS::Locker lock;
436 Unexpect aCatch(SBLockProtection);
441 MESSAGE("Locked document modification !!!");
442 throw SALOMEDS::StudyBuilder::LockProtection();
446 //============================================================================
447 /*! Function : GetAvailableUndos
450 //============================================================================
451 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
453 SALOMEDS::Locker lock;
454 return _impl->GetAvailableUndos();
457 //============================================================================
458 /*! Function : GetAvailableRedos
461 //============================================================================
462 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
464 SALOMEDS::Locker lock;
465 return _impl->GetAvailableRedos();
468 //============================================================================
469 /*! Function : UndoLimit
472 //============================================================================
473 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
475 SALOMEDS::Locker lock;
476 return _impl->UndoLimit();
479 //============================================================================
480 /*! Function : UndoLimit
483 //============================================================================
484 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
486 SALOMEDS::Locker lock;
491 //============================================================================
492 /*! Function : CheckLocked
495 //============================================================================
496 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
498 SALOMEDS::Locker lock;
499 Unexpect aCatch(SBLockProtection);
501 _impl->CheckLocked();
504 throw SALOMEDS::StudyBuilder::LockProtection();
508 //============================================================================
509 /*! Function : SetName
512 //============================================================================
513 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
514 throw(SALOMEDS::StudyBuilder::LockProtection)
516 SALOMEDS::Locker lock;
517 Unexpect aCatch(SBLockProtection);
520 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
521 _impl->SetName(aSO, string(theValue));
524 //============================================================================
525 /*! Function : SetComment
528 //============================================================================
529 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
530 throw(SALOMEDS::StudyBuilder::LockProtection)
532 SALOMEDS::Locker lock;
533 Unexpect aCatch(SBLockProtection);
536 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
537 _impl->SetComment(aSO, string(theValue));
540 //============================================================================
541 /*! Function : SetIOR
544 //============================================================================
545 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
546 throw(SALOMEDS::StudyBuilder::LockProtection)
548 SALOMEDS::Locker lock;
549 Unexpect aCatch(SBLockProtection);
552 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
553 _impl->SetIOR(aSO, string(theValue));