1 // Copyright (C) 2007-2016 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_StudyManager_i.hxx"
30 #include "SALOMEDS_Study_i.hxx"
31 #include "SALOMEDS_SObject_i.hxx"
32 #include "SALOMEDS_SComponent_i.hxx"
33 #include "SALOMEDS_GenericAttribute_i.hxx"
34 #include "SALOMEDS_Driver_i.hxx"
35 #include "SALOMEDS.hxx"
37 #include "SALOMEDSImpl_Study.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "Utils_CorbaException.hxx"
42 #include "Utils_ExceptHandlers.hxx"
44 #include <DF_Attribute.hxx>
45 #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 //============================================================================
73 \brief Get default POA for the servant object.
75 This function is implicitly called from "_this()" function.
76 Default POA can be set via the constructor.
78 \return reference to the default POA for the servant
80 //============================================================================
81 PortableServer::POA_ptr SALOMEDS_StudyBuilder_i::_default_POA()
83 PortableServer::POA_ptr poa = SALOMEDS_StudyManager_i::GetThePOA();
84 MESSAGE("SALOMEDS_StudyBuilder_i::_default_POA: " << poa);
85 return PortableServer::POA::_duplicate(poa);
88 //============================================================================
89 /*! Function : NewComponent
90 * Purpose : Create a new component (Scomponent)
92 //============================================================================
93 SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
95 SALOMEDS::Locker lock;
97 //char* aDataType = CORBA::string_dup(DataType);
98 SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(std::string(DataType));
99 //CORBA::free_string(aDataType);
100 if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil();
102 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb);
106 //============================================================================
107 /*! Function : DefineComponentInstance
108 * Purpose : Add IOR attribute of a Scomponent
110 //============================================================================
111 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
112 CORBA::Object_ptr IOR)
114 SALOMEDS::Locker lock;
116 CORBA::String_var anID=aComponent->GetID();
117 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
119 CORBA::String_var iorstr = _orb->object_to_string(IOR);
120 _impl->DefineComponentInstance(aSCO, (char*)iorstr.in());
123 //============================================================================
124 /*! Function : RemoveComponent
125 * Purpose : Delete a Scomponent
127 //============================================================================
128 void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
130 SALOMEDS::Locker lock;
132 ASSERT(!CORBA::is_nil(aComponent));
133 CORBA::String_var cid=aComponent->GetID();
134 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(cid.in());
135 _impl->RemoveComponent(aSCO);
138 //============================================================================
139 /*! Function : NewObject
140 * Purpose : Create a new SObject
142 //============================================================================
143 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
145 SALOMEDS::Locker lock;
148 SALOMEDSImpl_SObject aFO, aSO;
149 CORBA::String_var anID=theFatherObject->GetID();
150 aFO = _impl->GetOwner()->GetSObject(anID.in());
151 aSO = _impl->NewObject(aFO);
152 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
153 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
158 //============================================================================
159 /*! Function : NewObjectToTag
162 //============================================================================
163 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
166 SALOMEDS::Locker lock;
168 SALOMEDSImpl_SObject aFO, aSO;
169 CORBA::String_var fatherEntry = theFatherObject->GetID();
170 aFO = _impl->GetOwner()->GetSObject( fatherEntry.in() );
171 aSO = _impl->NewObjectToTag(aFO, atag);
172 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
173 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
177 //============================================================================
178 /*! Function : RemoveObject
181 //============================================================================
182 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
184 SALOMEDS::Locker lock;
186 CORBA::String_var anID=anObject->GetID();
187 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
188 _impl->RemoveObject(aSO);
191 //============================================================================
192 /*! Function : RemoveObjectWithChildren
195 //============================================================================
196 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
198 SALOMEDS::Locker lock;
200 CORBA::String_var anID=anObject->GetID();
201 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
202 _impl->RemoveObjectWithChildren(aSO);
205 //============================================================================
206 /*! Function : LoadWith
209 //============================================================================
210 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
211 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
213 SALOMEDS::Locker lock;
214 Unexpect aCatch(SBSalomeException);
216 CORBA::String_var anID=anSCO->GetID();
217 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
218 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
219 bool isDone = _impl->LoadWith(aSCO, driver);
222 if(!isDone && _impl->IsError()) {
223 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
228 //============================================================================
232 //============================================================================
233 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
235 MESSAGE ( "This function is not yet implemented");
238 //============================================================================
239 /*! Function : FindOrCreateAttribute
240 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
243 //============================================================================
244 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
245 const char* aTypeOfAttribute)
247 SALOMEDS::Locker lock;
248 CORBA::String_var anID = anObject->GetID();
249 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
250 DF_Attribute* anAttr;
252 anAttr = _impl->FindOrCreateAttribute(aSO, std::string(aTypeOfAttribute));
255 throw SALOMEDS::StudyBuilder::LockProtection();
258 SALOMEDS::GenericAttribute_var anAttribute;
261 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
263 return anAttribute._retn();
266 //============================================================================
267 /*! Function : FindAttribute
268 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
270 //============================================================================
272 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
273 SALOMEDS::GenericAttribute_out anAttribute,
274 const char* aTypeOfAttribute)
276 SALOMEDS::Locker lock;
277 ASSERT(!CORBA::is_nil(anObject));
278 CORBA::String_var anID = anObject->GetID();
279 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
280 DF_Attribute* anAttr;
282 if(!_impl->FindAttribute(aSO, anAttr, std::string(aTypeOfAttribute))) return false;
284 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
288 //============================================================================
289 /*! Function : RemoveAttribute
290 * Purpose : Remove attribute of given type assigned SObject
292 //============================================================================
294 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
295 const char* aTypeOfAttribute)
297 SALOMEDS::Locker lock;
299 ASSERT(!CORBA::is_nil(anObject));
300 CORBA::String_var anID = anObject->GetID();
301 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
302 _impl->RemoveAttribute(aSO, std::string(aTypeOfAttribute));
305 //============================================================================
306 /*! Function : Addreference
309 //============================================================================
310 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
311 SALOMEDS::SObject_ptr theReferencedObject)
313 SALOMEDS::Locker lock;
315 ASSERT(!CORBA::is_nil(me));
316 ASSERT(!CORBA::is_nil(theReferencedObject));
318 SALOMEDSImpl_SObject aSO, aRefSO;
319 CORBA::String_var anID = me->GetID();
320 aSO = _impl->GetOwner()->GetSObject(anID.in());
321 anID=theReferencedObject->GetID();
322 aRefSO = _impl->GetOwner()->GetSObject(anID.in());
323 _impl->Addreference(aSO, aRefSO);
326 //============================================================================
327 /*! Function : RemoveReference
330 //============================================================================
331 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
333 SALOMEDS::Locker lock;
335 ASSERT(!CORBA::is_nil(me));
336 CORBA::String_var anID = me->GetID();
337 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
338 _impl->RemoveReference(aSO);
342 //============================================================================
343 /*! Function : AddDirectory
344 * Purpose : adds a new directory with a path = thePath
346 //============================================================================
347 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
349 SALOMEDS::Locker lock;
351 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
352 if(!_impl->AddDirectory(std::string(thePath))) {
353 std::string anErrorCode = _impl->GetErrorCode();
354 if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed();
355 if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory();
356 if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();
361 //============================================================================
362 /*! Function : SetGUID
365 //============================================================================
366 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
368 SALOMEDS::Locker lock;
370 ASSERT(!CORBA::is_nil(anObject));
371 CORBA::String_var anID=anObject->GetID();
372 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
373 _impl->SetGUID(aSO, std::string(theGUID));
376 //============================================================================
377 /*! Function : IsGUID
380 //============================================================================
381 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
383 SALOMEDS::Locker lock;
384 ASSERT(!CORBA::is_nil(anObject));
385 CORBA::String_var anID=anObject->GetID();
386 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
387 return _impl->IsGUID(aSO, std::string(theGUID));
391 //============================================================================
392 /*! Function : NewCommand
395 //============================================================================
396 void SALOMEDS_StudyBuilder_i::NewCommand()
398 SALOMEDS::Locker lock;
402 //============================================================================
403 /*! Function : CommitCommand
406 //============================================================================
407 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
409 SALOMEDS::Locker lock;
410 Unexpect aCatch(SBLockProtection);
412 _impl->CommitCommand();
415 MESSAGE("Locked document modification !!!");
416 throw SALOMEDS::StudyBuilder::LockProtection();
420 //============================================================================
421 /*! Function : HasOpenCommand
424 //============================================================================
425 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
427 SALOMEDS::Locker lock;
428 return _impl->HasOpenCommand();
431 //============================================================================
432 /*! Function : AbortCommand
435 //============================================================================
436 void SALOMEDS_StudyBuilder_i::AbortCommand()
438 SALOMEDS::Locker lock;
439 _impl->AbortCommand();
442 //============================================================================
446 //============================================================================
447 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
449 SALOMEDS::Locker lock;
450 Unexpect aCatch(SBLockProtection);
455 MESSAGE("Locked document modification !!!");
456 throw SALOMEDS::StudyBuilder::LockProtection();
460 //============================================================================
464 //============================================================================
465 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
467 SALOMEDS::Locker lock;
468 Unexpect aCatch(SBLockProtection);
473 MESSAGE("Locked document modification !!!");
474 throw SALOMEDS::StudyBuilder::LockProtection();
478 //============================================================================
479 /*! Function : GetAvailableUndos
482 //============================================================================
483 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
485 SALOMEDS::Locker lock;
486 return _impl->GetAvailableUndos();
489 //============================================================================
490 /*! Function : GetAvailableRedos
493 //============================================================================
494 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
496 SALOMEDS::Locker lock;
497 return _impl->GetAvailableRedos();
500 //============================================================================
501 /*! Function : UndoLimit
504 //============================================================================
505 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
507 SALOMEDS::Locker lock;
508 return _impl->UndoLimit();
511 //============================================================================
512 /*! Function : UndoLimit
515 //============================================================================
516 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
518 SALOMEDS::Locker lock;
523 //============================================================================
524 /*! Function : CheckLocked
527 //============================================================================
528 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
530 SALOMEDS::Locker lock;
531 Unexpect aCatch(SBLockProtection);
533 _impl->CheckLocked();
536 throw SALOMEDS::StudyBuilder::LockProtection();
540 //============================================================================
541 /*! Function : SetName
544 //============================================================================
545 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
546 throw(SALOMEDS::StudyBuilder::LockProtection)
548 SALOMEDS::Locker lock;
549 Unexpect aCatch(SBLockProtection);
552 CORBA::String_var anID=theSO->GetID();
553 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
554 _impl->SetName(aSO, std::string(theValue));
557 //============================================================================
558 /*! Function : SetComment
561 //============================================================================
562 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
563 throw(SALOMEDS::StudyBuilder::LockProtection)
565 SALOMEDS::Locker lock;
566 Unexpect aCatch(SBLockProtection);
569 CORBA::String_var anID=theSO->GetID();
570 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
571 _impl->SetComment(aSO, std::string(theValue));
574 //============================================================================
575 /*! Function : SetIOR
578 //============================================================================
579 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
580 throw(SALOMEDS::StudyBuilder::LockProtection)
582 SALOMEDS::Locker lock;
583 Unexpect aCatch(SBLockProtection);
586 CORBA::String_var anID=theSO->GetID();
587 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
588 _impl->SetIOR(aSO, std::string(theValue));