1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // File : SALOMEDS_StudyBuilder_i.cxx
24 // Author : Seregy RUIN
27 #include "utilities.h"
28 #include "SALOMEDS_StudyBuilder_i.hxx"
29 #include "SALOMEDS_Study_i.hxx"
30 #include "SALOMEDS_SObject_i.hxx"
31 #include "SALOMEDS_SComponent_i.hxx"
32 #include "SALOMEDS_GenericAttribute_i.hxx"
33 #include "SALOMEDS_Driver_i.hxx"
34 #include "SALOMEDS.hxx"
36 #include "SALOMEDSImpl_Study.hxx"
37 #include "SALOMEDSImpl_SObject.hxx"
38 #include "SALOMEDSImpl_SComponent.hxx"
40 #include "Utils_CorbaException.hxx"
41 #include "Utils_ExceptHandlers.hxx"
43 #include <DF_Attribute.hxx>
44 #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(std::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 CORBA::String_var anID=aComponent->GetID();
99 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
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 CORBA::String_var anID=theFatherObject->GetID();
132 aFO = _impl->GetOwner()->GetSObject(anID.in());
133 aSO = _impl->NewObject(aFO);
134 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
135 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
140 //============================================================================
141 /*! Function : NewObjectToTag
144 //============================================================================
145 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
148 SALOMEDS::Locker lock;
150 SALOMEDSImpl_SObject aFO, aSO;
151 CORBA::String_var fatherEntry = theFatherObject->GetID();
152 aFO = _impl->GetOwner()->GetSObject( fatherEntry.in() );
153 aSO = _impl->NewObjectToTag(aFO, atag);
154 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
155 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
159 //============================================================================
160 /*! Function : RemoveObject
163 //============================================================================
164 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
166 SALOMEDS::Locker lock;
168 CORBA::String_var anID=anObject->GetID();
169 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
170 _impl->RemoveObject(aSO);
173 //============================================================================
174 /*! Function : RemoveObjectWithChildren
177 //============================================================================
178 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
180 SALOMEDS::Locker lock;
182 CORBA::String_var anID=anObject->GetID();
183 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
184 _impl->RemoveObjectWithChildren(aSO);
187 //============================================================================
188 /*! Function : LoadWith
191 //============================================================================
192 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
193 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
195 SALOMEDS::Locker lock;
196 Unexpect aCatch(SBSalomeException);
198 CORBA::String_var anID=anSCO->GetID();
199 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
200 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
201 bool isDone = _impl->LoadWith(aSCO, driver);
204 if(!isDone && _impl->IsError()) {
205 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
210 //============================================================================
214 //============================================================================
215 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
217 MESSAGE ( "This function is not yet implemented");
220 //============================================================================
221 /*! Function : FindOrCreateAttribute
222 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
225 //============================================================================
226 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
227 const char* aTypeOfAttribute)
229 SALOMEDS::Locker lock;
230 CORBA::String_var anID = anObject->GetID();
231 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
232 DF_Attribute* anAttr;
234 anAttr = _impl->FindOrCreateAttribute(aSO, std::string(aTypeOfAttribute));
237 throw SALOMEDS::StudyBuilder::LockProtection();
240 SALOMEDS::GenericAttribute_var anAttribute;
243 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
245 return anAttribute._retn();
248 //============================================================================
249 /*! Function : FindAttribute
250 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
252 //============================================================================
254 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
255 SALOMEDS::GenericAttribute_out anAttribute,
256 const char* aTypeOfAttribute)
258 SALOMEDS::Locker lock;
259 ASSERT(!CORBA::is_nil(anObject));
260 CORBA::String_var anID = anObject->GetID();
261 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
262 DF_Attribute* anAttr;
264 if(!_impl->FindAttribute(aSO, anAttr, std::string(aTypeOfAttribute))) return false;
266 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
270 //============================================================================
271 /*! Function : RemoveAttribute
272 * Purpose : Remove attribute of given type assigned SObject
274 //============================================================================
276 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
277 const char* aTypeOfAttribute)
279 SALOMEDS::Locker lock;
281 ASSERT(!CORBA::is_nil(anObject));
282 CORBA::String_var anID = anObject->GetID();
283 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
284 _impl->RemoveAttribute(aSO, std::string(aTypeOfAttribute));
287 //============================================================================
288 /*! Function : Addreference
291 //============================================================================
292 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
293 SALOMEDS::SObject_ptr theReferencedObject)
295 SALOMEDS::Locker lock;
297 ASSERT(!CORBA::is_nil(me));
298 ASSERT(!CORBA::is_nil(theReferencedObject));
300 SALOMEDSImpl_SObject aSO, aRefSO;
301 CORBA::String_var anID = me->GetID();
302 aSO = _impl->GetOwner()->GetSObject(anID.in());
303 anID=theReferencedObject->GetID();
304 aRefSO = _impl->GetOwner()->GetSObject(anID.in());
305 _impl->Addreference(aSO, aRefSO);
308 //============================================================================
309 /*! Function : RemoveReference
312 //============================================================================
313 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
315 SALOMEDS::Locker lock;
317 ASSERT(!CORBA::is_nil(me));
318 CORBA::String_var anID = me->GetID();
319 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
320 _impl->RemoveReference(aSO);
324 //============================================================================
325 /*! Function : AddDirectory
326 * Purpose : adds a new directory with a path = thePath
328 //============================================================================
329 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
331 SALOMEDS::Locker lock;
333 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
334 if(!_impl->AddDirectory(std::string(thePath))) {
335 std::string anErrorCode = _impl->GetErrorCode();
336 if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed();
337 if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory();
338 if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();
343 //============================================================================
344 /*! Function : SetGUID
347 //============================================================================
348 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
350 SALOMEDS::Locker lock;
352 ASSERT(!CORBA::is_nil(anObject));
353 CORBA::String_var anID=anObject->GetID();
354 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
355 _impl->SetGUID(aSO, std::string(theGUID));
358 //============================================================================
359 /*! Function : IsGUID
362 //============================================================================
363 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
365 SALOMEDS::Locker lock;
366 ASSERT(!CORBA::is_nil(anObject));
367 CORBA::String_var anID=anObject->GetID();
368 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
369 return _impl->IsGUID(aSO, std::string(theGUID));
373 //============================================================================
374 /*! Function : NewCommand
377 //============================================================================
378 void SALOMEDS_StudyBuilder_i::NewCommand()
380 SALOMEDS::Locker lock;
384 //============================================================================
385 /*! Function : CommitCommand
388 //============================================================================
389 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
391 SALOMEDS::Locker lock;
392 Unexpect aCatch(SBLockProtection);
394 _impl->CommitCommand();
397 MESSAGE("Locked document modification !!!");
398 throw SALOMEDS::StudyBuilder::LockProtection();
402 //============================================================================
403 /*! Function : HasOpenCommand
406 //============================================================================
407 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
409 SALOMEDS::Locker lock;
410 return _impl->HasOpenCommand();
413 //============================================================================
414 /*! Function : AbortCommand
417 //============================================================================
418 void SALOMEDS_StudyBuilder_i::AbortCommand()
420 SALOMEDS::Locker lock;
421 _impl->AbortCommand();
424 //============================================================================
428 //============================================================================
429 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
431 SALOMEDS::Locker lock;
432 Unexpect aCatch(SBLockProtection);
437 MESSAGE("Locked document modification !!!");
438 throw SALOMEDS::StudyBuilder::LockProtection();
442 //============================================================================
446 //============================================================================
447 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
449 SALOMEDS::Locker lock;
450 Unexpect aCatch(SBLockProtection);
455 MESSAGE("Locked document modification !!!");
456 throw SALOMEDS::StudyBuilder::LockProtection();
460 //============================================================================
461 /*! Function : GetAvailableUndos
464 //============================================================================
465 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
467 SALOMEDS::Locker lock;
468 return _impl->GetAvailableUndos();
471 //============================================================================
472 /*! Function : GetAvailableRedos
475 //============================================================================
476 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
478 SALOMEDS::Locker lock;
479 return _impl->GetAvailableRedos();
482 //============================================================================
483 /*! Function : UndoLimit
486 //============================================================================
487 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
489 SALOMEDS::Locker lock;
490 return _impl->UndoLimit();
493 //============================================================================
494 /*! Function : UndoLimit
497 //============================================================================
498 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
500 SALOMEDS::Locker lock;
505 //============================================================================
506 /*! Function : CheckLocked
509 //============================================================================
510 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
512 SALOMEDS::Locker lock;
513 Unexpect aCatch(SBLockProtection);
515 _impl->CheckLocked();
518 throw SALOMEDS::StudyBuilder::LockProtection();
522 //============================================================================
523 /*! Function : SetName
526 //============================================================================
527 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
528 throw(SALOMEDS::StudyBuilder::LockProtection)
530 SALOMEDS::Locker lock;
531 Unexpect aCatch(SBLockProtection);
534 CORBA::String_var anID=theSO->GetID();
535 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
536 _impl->SetName(aSO, std::string(theValue));
539 //============================================================================
540 /*! Function : SetComment
543 //============================================================================
544 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
545 throw(SALOMEDS::StudyBuilder::LockProtection)
547 SALOMEDS::Locker lock;
548 Unexpect aCatch(SBLockProtection);
551 CORBA::String_var anID=theSO->GetID();
552 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
553 _impl->SetComment(aSO, std::string(theValue));
556 //============================================================================
557 /*! Function : SetIOR
560 //============================================================================
561 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
562 throw(SALOMEDS::StudyBuilder::LockProtection)
564 SALOMEDS::Locker lock;
565 Unexpect aCatch(SBLockProtection);
568 CORBA::String_var anID=theSO->GetID();
569 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
570 _impl->SetIOR(aSO, std::string(theValue));