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 CORBA::String_var cid=aComponent->GetID();
116 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(cid.in());
117 _impl->RemoveComponent(aSCO);
120 //============================================================================
121 /*! Function : NewObject
122 * Purpose : Create a new SObject
124 //============================================================================
125 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
127 SALOMEDS::Locker lock;
130 SALOMEDSImpl_SObject aFO, aSO;
131 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
132 aSO = _impl->NewObject(aFO);
133 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
134 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
139 //============================================================================
140 /*! Function : NewObjectToTag
143 //============================================================================
144 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
147 SALOMEDS::Locker lock;
149 SALOMEDSImpl_SObject aFO, aSO;
150 aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
151 aSO = _impl->NewObjectToTag(aFO, atag);
152 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
153 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
157 //============================================================================
158 /*! Function : RemoveObject
161 //============================================================================
162 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
164 SALOMEDS::Locker lock;
166 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
167 _impl->RemoveObject(aSO);
170 //============================================================================
171 /*! Function : RemoveObjectWithChildren
174 //============================================================================
175 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
177 SALOMEDS::Locker lock;
179 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
180 _impl->RemoveObjectWithChildren(aSO);
183 //============================================================================
184 /*! Function : LoadWith
187 //============================================================================
188 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
189 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
191 SALOMEDS::Locker lock;
192 Unexpect aCatch(SBSalomeException);
194 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anSCO->GetID());
195 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
196 bool isDone = _impl->LoadWith(aSCO, driver);
199 if(!isDone && _impl->IsError()) {
200 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
205 //============================================================================
209 //============================================================================
210 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
212 MESSAGE ( "This function is not yet implemented");
215 //============================================================================
216 /*! Function : FindOrCreateAttribute
217 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
220 //============================================================================
221 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
222 const char* aTypeOfAttribute)
224 SALOMEDS::Locker lock;
225 CORBA::String_var anID = anObject->GetID();
226 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
227 DF_Attribute* anAttr;
229 anAttr = _impl->FindOrCreateAttribute(aSO, string(aTypeOfAttribute));
232 throw SALOMEDS::StudyBuilder::LockProtection();
235 SALOMEDS::GenericAttribute_var anAttribute;
238 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
240 return anAttribute._retn();
243 //============================================================================
244 /*! Function : FindAttribute
245 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
247 //============================================================================
249 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
250 SALOMEDS::GenericAttribute_out anAttribute,
251 const char* aTypeOfAttribute)
253 SALOMEDS::Locker lock;
254 ASSERT(!CORBA::is_nil(anObject));
255 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
256 DF_Attribute* anAttr;
258 if(!_impl->FindAttribute(aSO, anAttr, string(aTypeOfAttribute))) return false;
260 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb));
264 //============================================================================
265 /*! Function : RemoveAttribute
266 * Purpose : Remove attribute of given type assigned SObject
268 //============================================================================
270 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
271 const char* aTypeOfAttribute)
273 SALOMEDS::Locker lock;
275 ASSERT(!CORBA::is_nil(anObject));
276 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
277 _impl->RemoveAttribute(aSO, string(aTypeOfAttribute));
280 //============================================================================
281 /*! Function : Addreference
284 //============================================================================
285 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
286 SALOMEDS::SObject_ptr theReferencedObject)
288 SALOMEDS::Locker lock;
290 ASSERT(!CORBA::is_nil(me));
291 ASSERT(!CORBA::is_nil(theReferencedObject));
293 SALOMEDSImpl_SObject aSO, aRefSO;
294 aSO = _impl->GetOwner()->GetSObject(me->GetID());
295 aRefSO = _impl->GetOwner()->GetSObject(theReferencedObject->GetID());
296 _impl->Addreference(aSO, aRefSO);
299 //============================================================================
300 /*! Function : RemoveReference
303 //============================================================================
304 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
306 SALOMEDS::Locker lock;
308 ASSERT(!CORBA::is_nil(me));
309 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(me->GetID());
310 _impl->RemoveReference(aSO);
314 //============================================================================
315 /*! Function : AddDirectory
316 * Purpose : adds a new directory with a path = thePath
318 //============================================================================
319 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
321 SALOMEDS::Locker lock;
323 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
324 if(!_impl->AddDirectory(string(thePath))) {
325 string anErrorCode = _impl->GetErrorCode();
326 if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed();
327 if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory();
328 if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();
333 //============================================================================
334 /*! Function : SetGUID
337 //============================================================================
338 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
340 SALOMEDS::Locker lock;
342 ASSERT(!CORBA::is_nil(anObject));
343 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
344 _impl->SetGUID(aSO, string(theGUID));
347 //============================================================================
348 /*! Function : IsGUID
351 //============================================================================
352 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
354 SALOMEDS::Locker lock;
355 ASSERT(!CORBA::is_nil(anObject));
356 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anObject->GetID());
357 return _impl->IsGUID(aSO, string(theGUID));
361 //============================================================================
362 /*! Function : NewCommand
365 //============================================================================
366 void SALOMEDS_StudyBuilder_i::NewCommand()
368 SALOMEDS::Locker lock;
372 //============================================================================
373 /*! Function : CommitCommand
376 //============================================================================
377 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
379 SALOMEDS::Locker lock;
380 Unexpect aCatch(SBLockProtection);
382 _impl->CommitCommand();
385 MESSAGE("Locked document modification !!!");
386 throw SALOMEDS::StudyBuilder::LockProtection();
390 //============================================================================
391 /*! Function : HasOpenCommand
394 //============================================================================
395 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
397 SALOMEDS::Locker lock;
398 return _impl->HasOpenCommand();
401 //============================================================================
402 /*! Function : AbortCommand
405 //============================================================================
406 void SALOMEDS_StudyBuilder_i::AbortCommand()
408 SALOMEDS::Locker lock;
409 _impl->AbortCommand();
412 //============================================================================
416 //============================================================================
417 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
419 SALOMEDS::Locker lock;
420 Unexpect aCatch(SBLockProtection);
425 MESSAGE("Locked document modification !!!");
426 throw SALOMEDS::StudyBuilder::LockProtection();
430 //============================================================================
434 //============================================================================
435 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
437 SALOMEDS::Locker lock;
438 Unexpect aCatch(SBLockProtection);
443 MESSAGE("Locked document modification !!!");
444 throw SALOMEDS::StudyBuilder::LockProtection();
448 //============================================================================
449 /*! Function : GetAvailableUndos
452 //============================================================================
453 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
455 SALOMEDS::Locker lock;
456 return _impl->GetAvailableUndos();
459 //============================================================================
460 /*! Function : GetAvailableRedos
463 //============================================================================
464 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
466 SALOMEDS::Locker lock;
467 return _impl->GetAvailableRedos();
470 //============================================================================
471 /*! Function : UndoLimit
474 //============================================================================
475 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
477 SALOMEDS::Locker lock;
478 return _impl->UndoLimit();
481 //============================================================================
482 /*! Function : UndoLimit
485 //============================================================================
486 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
488 SALOMEDS::Locker lock;
493 //============================================================================
494 /*! Function : CheckLocked
497 //============================================================================
498 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
500 SALOMEDS::Locker lock;
501 Unexpect aCatch(SBLockProtection);
503 _impl->CheckLocked();
506 throw SALOMEDS::StudyBuilder::LockProtection();
510 //============================================================================
511 /*! Function : SetName
514 //============================================================================
515 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
516 throw(SALOMEDS::StudyBuilder::LockProtection)
518 SALOMEDS::Locker lock;
519 Unexpect aCatch(SBLockProtection);
522 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
523 _impl->SetName(aSO, string(theValue));
526 //============================================================================
527 /*! Function : SetComment
530 //============================================================================
531 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
532 throw(SALOMEDS::StudyBuilder::LockProtection)
534 SALOMEDS::Locker lock;
535 Unexpect aCatch(SBLockProtection);
538 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
539 _impl->SetComment(aSO, string(theValue));
542 //============================================================================
543 /*! Function : SetIOR
546 //============================================================================
547 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
548 throw(SALOMEDS::StudyBuilder::LockProtection)
550 SALOMEDS::Locker lock;
551 Unexpect aCatch(SBLockProtection);
554 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(theSO->GetID());
555 _impl->SetIOR(aSO, string(theValue));