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 // File : SALOMEDS_StudyBuilder_i.cxx
23 // Author : Seregy RUIN
26 #include "utilities.h"
27 #include "SALOMEDS_StudyBuilder_i.hxx"
28 #include "SALOMEDS_Study_i.hxx"
29 #include "SALOMEDS_SObject_i.hxx"
30 #include "SALOMEDS_SComponent_i.hxx"
31 #include "SALOMEDS_GenericAttribute_i.hxx"
32 #include "SALOMEDS_Driver_i.hxx"
33 #include "SALOMEDS.hxx"
35 #include "SALOMEDSImpl_Study.hxx"
36 #include "SALOMEDSImpl_SObject.hxx"
37 #include "SALOMEDSImpl_SComponent.hxx"
39 #include "Utils_CorbaException.hxx"
40 #include "Utils_ExceptHandlers.hxx"
42 #include <DF_Attribute.hxx>
43 #include <DF_Document.hxx>
48 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception);
49 UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection);
51 //============================================================================
52 /*! Function : constructor
55 //============================================================================
56 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDSImpl_StudyBuilder* theImpl,
59 _orb = CORBA::ORB::_duplicate(orb);
63 //============================================================================
64 /*! Function : destructor
67 //============================================================================
68 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
71 //============================================================================
72 /*! Function : NewComponent
73 * Purpose : Create a new component (Scomponent)
75 //============================================================================
76 SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
78 SALOMEDS::Locker lock;
80 //char* aDataType = CORBA::string_dup(DataType);
81 SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(string(DataType));
82 //CORBA::free_string(aDataType);
83 if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil();
85 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb);
89 //============================================================================
90 /*! Function : DefineComponentInstance
91 * Purpose : Add IOR attribute of a Scomponent
93 //============================================================================
94 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
95 CORBA::Object_ptr IOR)
97 SALOMEDS::Locker lock;
99 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(aComponent->GetID());
101 CORBA::String_var iorstr = _orb->object_to_string(IOR);
102 _impl->DefineComponentInstance(aSCO, (char*)iorstr.in());
105 //============================================================================
106 /*! Function : RemoveComponent
107 * Purpose : Delete a Scomponent
109 //============================================================================
110 void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
112 SALOMEDS::Locker lock;
114 ASSERT(!CORBA::is_nil(aComponent));
115 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(aComponent->GetID());
116 _impl->RemoveComponent(aSCO);
119 //============================================================================
120 /*! Function : NewObject
121 * Purpose : Create a new SObject
123 //============================================================================
124 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
126 SALOMEDS::Locker lock;
129 SALOMEDSImpl_SObject aFO, aSO;
130 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
131 aSO = _impl->NewObject(aFO);
132 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
133 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
138 //============================================================================
139 /*! Function : NewObjectToTag
142 //============================================================================
143 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
146 SALOMEDS::Locker lock;
148 SALOMEDSImpl_SObject aFO, aSO;
149 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
150 aSO = _impl->NewObjectToTag(aFO, atag);
151 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
152 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
156 //============================================================================
157 /*! Function : RemoveObject
160 //============================================================================
161 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
163 SALOMEDS::Locker lock;
165 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
166 _impl->RemoveObject(aSO);
169 //============================================================================
170 /*! Function : RemoveObjectWithChildren
173 //============================================================================
174 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
176 SALOMEDS::Locker lock;
178 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
179 _impl->RemoveObjectWithChildren(aSO);
182 //============================================================================
183 /*! Function : LoadWith
186 //============================================================================
187 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
188 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
190 SALOMEDS::Locker lock;
191 Unexpect aCatch(SBSalomeException);
193 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anSCO->GetID());
194 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
195 bool isDone = _impl->LoadWith(aSCO, driver);
198 if(!isDone && _impl->IsError()) {
199 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
204 //============================================================================
208 //============================================================================
209 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
211 MESSAGE ( "This function is not yet implemented");
214 //============================================================================
215 /*! Function : FindOrCreateAttribute
216 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
219 //============================================================================
220 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
221 const char* aTypeOfAttribute)
223 SALOMEDS::Locker lock;
224 CORBA::String_var anID = anObject->GetID();
225 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
226 DF_Attribute* anAttr;
228 anAttr = _impl->FindOrCreateAttribute(aSO, string(aTypeOfAttribute));
231 throw SALOMEDS::StudyBuilder::LockProtection();
234 SALOMEDS::GenericAttribute_var anAttribute;
237 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
239 return anAttribute._retn();
242 //============================================================================
243 /*! Function : FindAttribute
244 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
246 //============================================================================
248 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
249 SALOMEDS::GenericAttribute_out anAttribute,
250 const char* aTypeOfAttribute)
252 SALOMEDS::Locker lock;
253 ASSERT(!CORBA::is_nil(anObject));
254 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
255 DF_Attribute* anAttr;
257 if(!_impl->FindAttribute(aSO, anAttr, string(aTypeOfAttribute))) return false;
259 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
263 //============================================================================
264 /*! Function : RemoveAttribute
265 * Purpose : Remove attribute of given type assigned SObject
267 //============================================================================
269 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
270 const char* aTypeOfAttribute)
272 SALOMEDS::Locker lock;
274 ASSERT(!CORBA::is_nil(anObject));
275 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
276 _impl->RemoveAttribute(aSO, string(aTypeOfAttribute));
279 //============================================================================
280 /*! Function : Addreference
283 //============================================================================
284 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
285 SALOMEDS::SObject_ptr theReferencedObject)
287 SALOMEDS::Locker lock;
289 ASSERT(!CORBA::is_nil(me));
290 ASSERT(!CORBA::is_nil(theReferencedObject));
292 SALOMEDSImpl_SObject aSO, aRefSO;
293 aSO = _impl->GetOwner()->GetSObject(me->GetID());
294 aRefSO = _impl->GetOwner()->GetSObject(theReferencedObject->GetID());
295 _impl->Addreference(aSO, aRefSO);
298 //============================================================================
299 /*! Function : RemoveReference
302 //============================================================================
303 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
305 SALOMEDS::Locker lock;
307 ASSERT(!CORBA::is_nil(me));
308 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(me->GetID());
309 _impl->RemoveReference(aSO);
313 //============================================================================
314 /*! Function : AddDirectory
315 * Purpose : adds a new directory with a path = thePath
317 //============================================================================
318 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
320 SALOMEDS::Locker lock;
322 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
323 if(!_impl->AddDirectory(string(thePath))) {
324 string anErrorCode = _impl->GetErrorCode();
325 if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed();
326 if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory();
327 if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();
332 //============================================================================
333 /*! Function : SetGUID
336 //============================================================================
337 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
339 SALOMEDS::Locker lock;
341 ASSERT(!CORBA::is_nil(anObject));
342 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
343 _impl->SetGUID(aSO, string(theGUID));
346 //============================================================================
347 /*! Function : IsGUID
350 //============================================================================
351 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
353 SALOMEDS::Locker lock;
354 ASSERT(!CORBA::is_nil(anObject));
355 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
356 return _impl->IsGUID(aSO, string(theGUID));
360 //============================================================================
361 /*! Function : NewCommand
364 //============================================================================
365 void SALOMEDS_StudyBuilder_i::NewCommand()
367 SALOMEDS::Locker lock;
371 //============================================================================
372 /*! Function : CommitCommand
375 //============================================================================
376 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
378 SALOMEDS::Locker lock;
379 Unexpect aCatch(SBLockProtection);
381 _impl->CommitCommand();
384 MESSAGE("Locked document modification !!!");
385 throw SALOMEDS::StudyBuilder::LockProtection();
389 //============================================================================
390 /*! Function : HasOpenCommand
393 //============================================================================
394 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
396 SALOMEDS::Locker lock;
397 return _impl->HasOpenCommand();
400 //============================================================================
401 /*! Function : AbortCommand
404 //============================================================================
405 void SALOMEDS_StudyBuilder_i::AbortCommand()
407 SALOMEDS::Locker lock;
408 _impl->AbortCommand();
411 //============================================================================
415 //============================================================================
416 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
418 SALOMEDS::Locker lock;
419 Unexpect aCatch(SBLockProtection);
424 MESSAGE("Locked document modification !!!");
425 throw SALOMEDS::StudyBuilder::LockProtection();
429 //============================================================================
433 //============================================================================
434 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
436 SALOMEDS::Locker lock;
437 Unexpect aCatch(SBLockProtection);
442 MESSAGE("Locked document modification !!!");
443 throw SALOMEDS::StudyBuilder::LockProtection();
447 //============================================================================
448 /*! Function : GetAvailableUndos
451 //============================================================================
452 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
454 SALOMEDS::Locker lock;
455 return _impl->GetAvailableUndos();
458 //============================================================================
459 /*! Function : GetAvailableRedos
462 //============================================================================
463 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
465 SALOMEDS::Locker lock;
466 return _impl->GetAvailableRedos();
469 //============================================================================
470 /*! Function : UndoLimit
473 //============================================================================
474 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
476 SALOMEDS::Locker lock;
477 return _impl->UndoLimit();
480 //============================================================================
481 /*! Function : UndoLimit
484 //============================================================================
485 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
487 SALOMEDS::Locker lock;
492 //============================================================================
493 /*! Function : CheckLocked
496 //============================================================================
497 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
499 SALOMEDS::Locker lock;
500 Unexpect aCatch(SBLockProtection);
502 _impl->CheckLocked();
505 throw SALOMEDS::StudyBuilder::LockProtection();
509 //============================================================================
510 /*! Function : SetName
513 //============================================================================
514 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
515 throw(SALOMEDS::StudyBuilder::LockProtection)
517 SALOMEDS::Locker lock;
518 Unexpect aCatch(SBLockProtection);
521 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
522 _impl->SetName(aSO, string(theValue));
525 //============================================================================
526 /*! Function : SetComment
529 //============================================================================
530 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
531 throw(SALOMEDS::StudyBuilder::LockProtection)
533 SALOMEDS::Locker lock;
534 Unexpect aCatch(SBLockProtection);
537 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
538 _impl->SetComment(aSO, string(theValue));
541 //============================================================================
542 /*! Function : SetIOR
545 //============================================================================
546 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
547 throw(SALOMEDS::StudyBuilder::LockProtection)
549 SALOMEDS::Locker lock;
550 Unexpect aCatch(SBLockProtection);
553 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
554 _impl->SetIOR(aSO, string(theValue));