1 // Copyright (C) 2007-2020 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 //============================================================================
72 \brief Get default POA for the servant object.
74 This function is implicitly called from "_this()" function.
75 Default POA can be set via the constructor.
77 \return reference to the default POA for the servant
79 //============================================================================
80 PortableServer::POA_ptr SALOMEDS_StudyBuilder_i::_default_POA()
82 PortableServer::POA_ptr poa = SALOMEDS_Study_i::GetThePOA();
83 MESSAGE("SALOMEDS_StudyBuilder_i::_default_POA: " << poa);
84 return PortableServer::POA::_duplicate(poa);
87 //============================================================================
88 /*! Function : NewComponent
89 * Purpose : Create a new component (Scomponent)
91 //============================================================================
92 SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
94 SALOMEDS::Locker lock;
96 //char* aDataType = CORBA::string_dup(DataType);
97 SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(std::string(DataType));
98 //CORBA::free_string(aDataType);
99 if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil();
101 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb);
105 //============================================================================
106 /*! Function : DefineComponentInstance
107 * Purpose : Add IOR attribute of a Scomponent
109 //============================================================================
110 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
111 CORBA::Object_ptr IOR)
113 SALOMEDS::Locker lock;
115 CORBA::String_var anID=aComponent->GetID();
116 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
118 CORBA::String_var iorstr = _orb->object_to_string(IOR);
119 _impl->DefineComponentInstance(aSCO, (char*)iorstr.in());
122 //============================================================================
123 /*! Function : RemoveComponent
124 * Purpose : Delete a Scomponent
126 //============================================================================
127 void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
129 SALOMEDS::Locker lock;
131 ASSERT(!CORBA::is_nil(aComponent));
132 CORBA::String_var cid=aComponent->GetID();
133 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(cid.in());
134 _impl->RemoveComponent(aSCO);
137 //============================================================================
138 /*! Function : NewObject
139 * Purpose : Create a new SObject
141 //============================================================================
142 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
144 SALOMEDS::Locker lock;
147 SALOMEDSImpl_SObject aFO, aSO;
148 CORBA::String_var anID=theFatherObject->GetID();
149 aFO = _impl->GetOwner()->GetSObject(anID.in());
150 aSO = _impl->NewObject(aFO);
151 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
152 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
157 //============================================================================
158 /*! Function : NewObjectToTag
161 //============================================================================
162 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
165 SALOMEDS::Locker lock;
167 SALOMEDSImpl_SObject aFO, aSO;
168 CORBA::String_var fatherEntry = theFatherObject->GetID();
169 aFO = _impl->GetOwner()->GetSObject( fatherEntry.in() );
170 aSO = _impl->NewObjectToTag(aFO, atag);
171 if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
172 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
176 //============================================================================
177 /*! Function : RemoveObject
180 //============================================================================
181 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
183 SALOMEDS::Locker lock;
185 CORBA::String_var anID=anObject->GetID();
186 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
187 _impl->RemoveObject(aSO);
190 //============================================================================
191 /*! Function : RemoveObjectWithChildren
194 //============================================================================
195 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
197 SALOMEDS::Locker lock;
199 CORBA::String_var anID=anObject->GetID();
200 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
201 _impl->RemoveObjectWithChildren(aSO);
204 //============================================================================
205 /*! Function : LoadWith
208 //============================================================================
209 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
210 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
212 SALOMEDS::Locker lock;
213 Unexpect aCatch(SBSalomeException);
215 CORBA::String_var anID=anSCO->GetID();
216 SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
217 SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
218 bool isDone = _impl->LoadWith(aSCO, driver);
221 if(!isDone && _impl->IsError()) {
222 THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
227 //============================================================================
231 //============================================================================
232 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
234 MESSAGE ( "This function is not yet implemented");
237 //============================================================================
238 /*! Function : FindOrCreateAttribute
239 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
242 //============================================================================
243 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
244 const char* aTypeOfAttribute)
246 SALOMEDS::Locker lock;
247 CORBA::String_var anID = anObject->GetID();
248 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
249 DF_Attribute* anAttr;
251 anAttr = _impl->FindOrCreateAttribute(aSO, std::string(aTypeOfAttribute));
254 throw SALOMEDS::StudyBuilder::LockProtection();
257 SALOMEDS::GenericAttribute_var anAttribute;
260 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
262 return anAttribute._retn();
265 //============================================================================
266 /*! Function : FindAttribute
267 * Purpose : Find attribute of given type assigned SObject, returns true if it is found
269 //============================================================================
271 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
272 SALOMEDS::GenericAttribute_out anAttribute,
273 const char* aTypeOfAttribute)
275 SALOMEDS::Locker lock;
276 ASSERT(!CORBA::is_nil(anObject));
277 CORBA::String_var anID = anObject->GetID();
278 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
279 DF_Attribute* anAttr;
281 if(!_impl->FindAttribute(aSO, anAttr, std::string(aTypeOfAttribute))) return false;
283 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
287 //============================================================================
288 /*! Function : RemoveAttribute
289 * Purpose : Remove attribute of given type assigned SObject
291 //============================================================================
293 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
294 const char* aTypeOfAttribute)
296 SALOMEDS::Locker lock;
298 ASSERT(!CORBA::is_nil(anObject));
299 CORBA::String_var anID = anObject->GetID();
300 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
301 _impl->RemoveAttribute(aSO, std::string(aTypeOfAttribute));
304 //============================================================================
305 /*! Function : Addreference
308 //============================================================================
309 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
310 SALOMEDS::SObject_ptr theReferencedObject)
312 SALOMEDS::Locker lock;
314 ASSERT(!CORBA::is_nil(me));
315 ASSERT(!CORBA::is_nil(theReferencedObject));
317 SALOMEDSImpl_SObject aSO, aRefSO;
318 CORBA::String_var anID = me->GetID();
319 aSO = _impl->GetOwner()->GetSObject(anID.in());
320 anID=theReferencedObject->GetID();
321 aRefSO = _impl->GetOwner()->GetSObject(anID.in());
322 _impl->Addreference(aSO, aRefSO);
325 //============================================================================
326 /*! Function : RemoveReference
329 //============================================================================
330 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
332 SALOMEDS::Locker lock;
334 ASSERT(!CORBA::is_nil(me));
335 CORBA::String_var anID = me->GetID();
336 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
337 _impl->RemoveReference(aSO);
340 //============================================================================
341 /*! Function : SetGUID
344 //============================================================================
345 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
347 SALOMEDS::Locker lock;
349 ASSERT(!CORBA::is_nil(anObject));
350 CORBA::String_var anID=anObject->GetID();
351 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
352 _impl->SetGUID(aSO, std::string(theGUID));
355 //============================================================================
356 /*! Function : IsGUID
359 //============================================================================
360 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
362 SALOMEDS::Locker lock;
363 ASSERT(!CORBA::is_nil(anObject));
364 CORBA::String_var anID=anObject->GetID();
365 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
366 return _impl->IsGUID(aSO, std::string(theGUID));
370 //============================================================================
371 /*! Function : NewCommand
374 //============================================================================
375 void SALOMEDS_StudyBuilder_i::NewCommand()
377 SALOMEDS::Locker lock;
381 //============================================================================
382 /*! Function : CommitCommand
385 //============================================================================
386 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
388 SALOMEDS::Locker lock;
389 Unexpect aCatch(SBLockProtection);
391 _impl->CommitCommand();
394 MESSAGE("Locked document modification !!!");
395 throw SALOMEDS::StudyBuilder::LockProtection();
399 //============================================================================
400 /*! Function : HasOpenCommand
403 //============================================================================
404 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
406 SALOMEDS::Locker lock;
407 return _impl->HasOpenCommand();
410 //============================================================================
411 /*! Function : AbortCommand
414 //============================================================================
415 void SALOMEDS_StudyBuilder_i::AbortCommand()
417 SALOMEDS::Locker lock;
418 _impl->AbortCommand();
421 //============================================================================
425 //============================================================================
426 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
428 SALOMEDS::Locker lock;
429 Unexpect aCatch(SBLockProtection);
434 MESSAGE("Locked document modification !!!");
435 throw SALOMEDS::StudyBuilder::LockProtection();
439 //============================================================================
443 //============================================================================
444 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
446 SALOMEDS::Locker lock;
447 Unexpect aCatch(SBLockProtection);
452 MESSAGE("Locked document modification !!!");
453 throw SALOMEDS::StudyBuilder::LockProtection();
457 //============================================================================
458 /*! Function : GetAvailableUndos
461 //============================================================================
462 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
464 SALOMEDS::Locker lock;
465 return _impl->GetAvailableUndos();
468 //============================================================================
469 /*! Function : GetAvailableRedos
472 //============================================================================
473 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
475 SALOMEDS::Locker lock;
476 return _impl->GetAvailableRedos();
479 //============================================================================
480 /*! Function : UndoLimit
483 //============================================================================
484 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
486 SALOMEDS::Locker lock;
487 return _impl->UndoLimit();
490 //============================================================================
491 /*! Function : UndoLimit
494 //============================================================================
495 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
497 SALOMEDS::Locker lock;
502 //============================================================================
503 /*! Function : CheckLocked
506 //============================================================================
507 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection)
509 SALOMEDS::Locker lock;
510 Unexpect aCatch(SBLockProtection);
512 _impl->CheckLocked();
515 throw SALOMEDS::StudyBuilder::LockProtection();
519 //============================================================================
520 /*! Function : SetName
523 //============================================================================
524 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
525 throw(SALOMEDS::StudyBuilder::LockProtection)
527 SALOMEDS::Locker lock;
528 Unexpect aCatch(SBLockProtection);
531 CORBA::String_var anID=theSO->GetID();
532 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
533 _impl->SetName(aSO, std::string(theValue));
536 //============================================================================
537 /*! Function : SetComment
540 //============================================================================
541 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
542 throw(SALOMEDS::StudyBuilder::LockProtection)
544 SALOMEDS::Locker lock;
545 Unexpect aCatch(SBLockProtection);
548 CORBA::String_var anID=theSO->GetID();
549 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
550 _impl->SetComment(aSO, std::string(theValue));
553 //============================================================================
554 /*! Function : SetIOR
557 //============================================================================
558 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
559 throw(SALOMEDS::StudyBuilder::LockProtection)
561 SALOMEDS::Locker lock;
562 Unexpect aCatch(SBLockProtection);
565 CORBA::String_var anID=theSO->GetID();
566 SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
567 _impl->SetIOR(aSO, std::string(theValue));