Back to index

salome-kernel  6.5.0
SALOMEDS_StudyBuilder_i.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOMEDS_StudyBuilder_i.cxx
00024 //  Author : Seregy RUIN
00025 //  Module : SALOME
00026 //
00027 #include "utilities.h"
00028 #include "SALOMEDS_StudyBuilder_i.hxx"
00029 #include "SALOMEDS_Study_i.hxx"
00030 #include "SALOMEDS_SObject_i.hxx"
00031 #include "SALOMEDS_SComponent_i.hxx"
00032 #include "SALOMEDS_GenericAttribute_i.hxx"
00033 #include "SALOMEDS_Driver_i.hxx"
00034 #include "SALOMEDS.hxx"
00035 
00036 #include "SALOMEDSImpl_Study.hxx"
00037 #include "SALOMEDSImpl_SObject.hxx"
00038 #include "SALOMEDSImpl_SComponent.hxx"
00039 
00040 #include "Utils_CorbaException.hxx"
00041 #include "Utils_ExceptHandlers.hxx"
00042 
00043 #include <DF_Attribute.hxx>
00044 #include <DF_Document.hxx>
00045 #include <stdlib.h> 
00046 
00047 UNEXPECT_CATCH(SBSalomeException, SALOME::SALOME_Exception);
00048 UNEXPECT_CATCH(SBLockProtection, SALOMEDS::StudyBuilder::LockProtection);
00049 
00050 //============================================================================
00054 //============================================================================
00055 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(SALOMEDSImpl_StudyBuilder* theImpl, 
00056                                                  CORBA::ORB_ptr orb) 
00057 {
00058   _orb = CORBA::ORB::_duplicate(orb);
00059   _impl = theImpl;
00060 }
00061 
00062 //============================================================================
00066 //============================================================================
00067 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
00068 {}
00069 
00070 //============================================================================
00074 //============================================================================
00075 SALOMEDS::SComponent_ptr SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
00076 {
00077   SALOMEDS::Locker lock;
00078   CheckLocked();
00079   //char* aDataType = CORBA::string_dup(DataType);
00080   SALOMEDSImpl_SComponent aSCO = _impl->NewComponent(std::string(DataType));
00081   //CORBA::free_string(aDataType);
00082   if(aSCO.IsNull()) return SALOMEDS::SComponent::_nil();
00083 
00084   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO,_orb);
00085   return sco._retn();
00086 }
00087 
00088 //============================================================================
00092 //============================================================================
00093 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
00094                                                       CORBA::Object_ptr IOR)
00095 {
00096   SALOMEDS::Locker lock;
00097   CheckLocked();
00098   CORBA::String_var anID=aComponent->GetID();
00099   SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
00100 
00101   CORBA::String_var iorstr = _orb->object_to_string(IOR);
00102   _impl->DefineComponentInstance(aSCO, (char*)iorstr.in());
00103 }
00104 
00105 //============================================================================
00109 //============================================================================
00110 void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
00111 {
00112   SALOMEDS::Locker lock;
00113   CheckLocked();
00114   ASSERT(!CORBA::is_nil(aComponent));
00115   CORBA::String_var cid=aComponent->GetID();
00116   SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(cid.in());
00117   _impl->RemoveComponent(aSCO);
00118 }
00119 
00120 //============================================================================
00124 //============================================================================
00125 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
00126 {
00127   SALOMEDS::Locker lock;
00128   CheckLocked();
00129   
00130   SALOMEDSImpl_SObject aFO, aSO;
00131   CORBA::String_var anID=theFatherObject->GetID();
00132   aFO = _impl->GetOwner()->GetSObject(anID.in());
00133   aSO = _impl->NewObject(aFO);
00134   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
00135   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO,_orb);
00136 
00137   return so._retn();
00138 }
00139 
00140 //============================================================================
00144 //============================================================================
00145 SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
00146                                                               CORBA::Long atag)
00147 {
00148   SALOMEDS::Locker lock;
00149   CheckLocked();
00150   SALOMEDSImpl_SObject aFO, aSO;
00151   aFO = _impl->GetOwner()->GetSObject(theFatherObject->GetID());
00152   aSO = _impl->NewObjectToTag(aFO, atag);
00153   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
00154   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
00155   return so._retn();
00156 }
00157 
00158 //============================================================================
00162 //============================================================================
00163 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
00164 {
00165   SALOMEDS::Locker lock;
00166   CheckLocked();
00167   CORBA::String_var anID=anObject->GetID();
00168   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00169   _impl->RemoveObject(aSO);
00170 }
00171 
00172 //============================================================================
00176 //============================================================================
00177 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
00178 {
00179   SALOMEDS::Locker lock;
00180   CheckLocked();
00181   CORBA::String_var anID=anObject->GetID();
00182   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00183   _impl->RemoveObjectWithChildren(aSO);
00184 }
00185 
00186 //============================================================================
00190 //============================================================================
00191 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO, 
00192                                        SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
00193 {
00194   SALOMEDS::Locker lock;
00195   Unexpect aCatch(SBSalomeException);
00196 
00197   CORBA::String_var anID=anSCO->GetID();
00198   SALOMEDSImpl_SComponent aSCO = _impl->GetOwner()->GetSComponent(anID.in());
00199   SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb);
00200   bool isDone = _impl->LoadWith(aSCO, driver); 
00201   delete driver;
00202 
00203   if(!isDone && _impl->IsError()) {
00204     THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM);
00205   }
00206 }
00207 
00208 
00209 //============================================================================
00213 //============================================================================
00214 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
00215 {
00216   MESSAGE ( "This function is not yet implemented");
00217 }
00218 
00219 //============================================================================
00224 //============================================================================
00225 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject, 
00226                                                                               const char* aTypeOfAttribute)
00227 {
00228   SALOMEDS::Locker lock;
00229   CORBA::String_var anID = anObject->GetID();
00230   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.inout());
00231   DF_Attribute* anAttr;
00232   try {
00233      anAttr = _impl->FindOrCreateAttribute(aSO, std::string(aTypeOfAttribute));
00234   }
00235   catch (...) {
00236     throw SALOMEDS::StudyBuilder::LockProtection();
00237   }
00238 
00239   SALOMEDS::GenericAttribute_var anAttribute;
00240   
00241   if(anAttr)     
00242      anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
00243 
00244   return anAttribute._retn();
00245 }
00246 
00247 //============================================================================
00251 //============================================================================
00252 
00253 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject, 
00254                                                       SALOMEDS::GenericAttribute_out anAttribute, 
00255                                                       const char* aTypeOfAttribute)
00256 {
00257   SALOMEDS::Locker lock;
00258   ASSERT(!CORBA::is_nil(anObject));
00259   CORBA::String_var anID = anObject->GetID();
00260   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00261   DF_Attribute* anAttr;
00262 
00263   if(!_impl->FindAttribute(aSO, anAttr, std::string(aTypeOfAttribute))) return false;
00264     
00265   anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
00266   return true;  
00267 }
00268 
00269 //============================================================================
00273 //============================================================================
00274 
00275 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject, 
00276                                               const char* aTypeOfAttribute)
00277 {
00278   SALOMEDS::Locker lock;
00279   CheckLocked();
00280   ASSERT(!CORBA::is_nil(anObject));
00281   CORBA::String_var anID = anObject->GetID();
00282   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00283   _impl->RemoveAttribute(aSO, std::string(aTypeOfAttribute));
00284 }
00285 
00286 //============================================================================
00290 //============================================================================
00291 void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me, 
00292                                            SALOMEDS::SObject_ptr theReferencedObject)
00293 {
00294   SALOMEDS::Locker lock;
00295   CheckLocked();
00296   ASSERT(!CORBA::is_nil(me));
00297   ASSERT(!CORBA::is_nil(theReferencedObject));
00298  
00299   SALOMEDSImpl_SObject aSO, aRefSO;
00300   CORBA::String_var anID = me->GetID();
00301   aSO = _impl->GetOwner()->GetSObject(anID.in());
00302   anID=theReferencedObject->GetID();
00303   aRefSO = _impl->GetOwner()->GetSObject(anID.in());
00304   _impl->Addreference(aSO, aRefSO);
00305 }
00306 
00307 //============================================================================
00311 //============================================================================
00312 void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me)
00313 {
00314   SALOMEDS::Locker lock;
00315   CheckLocked();
00316   ASSERT(!CORBA::is_nil(me));
00317   CORBA::String_var anID = me->GetID();
00318   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00319   _impl->RemoveReference(aSO);
00320 }
00321 
00322 
00323 //============================================================================
00327 //============================================================================
00328 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath) 
00329 {
00330   SALOMEDS::Locker lock;
00331   CheckLocked();
00332   if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
00333   if(!_impl->AddDirectory(std::string(thePath))) {
00334     std::string anErrorCode = _impl->GetErrorCode();
00335     if(anErrorCode == "StudyNameAlreadyUsed") throw SALOMEDS::Study::StudyNameAlreadyUsed(); 
00336     if(anErrorCode == "StudyInvalidDirectory") throw SALOMEDS::Study::StudyInvalidDirectory(); 
00337     if(anErrorCode == "StudyInvalidComponent") throw SALOMEDS::Study::StudyInvalidComponent();  
00338   }
00339 }
00340 
00341 
00342 //============================================================================
00346 //============================================================================
00347 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
00348 {
00349   SALOMEDS::Locker lock;
00350   CheckLocked();
00351   ASSERT(!CORBA::is_nil(anObject));
00352   CORBA::String_var anID=anObject->GetID();
00353   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00354   _impl->SetGUID(aSO, std::string(theGUID));
00355 }
00356 
00357 //============================================================================
00361 //============================================================================
00362 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
00363 {
00364   SALOMEDS::Locker lock;
00365   ASSERT(!CORBA::is_nil(anObject));
00366   CORBA::String_var anID=anObject->GetID();
00367   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());
00368   return _impl->IsGUID(aSO, std::string(theGUID));
00369 }
00370 
00371 
00372 //============================================================================
00376 //============================================================================
00377 void SALOMEDS_StudyBuilder_i::NewCommand()
00378 {
00379   SALOMEDS::Locker lock;
00380   _impl->NewCommand();
00381 }
00382 
00383 //============================================================================
00387 //============================================================================
00388 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
00389 {
00390   SALOMEDS::Locker lock;
00391   Unexpect aCatch(SBLockProtection);
00392   try {
00393     _impl->CommitCommand();
00394   }
00395   catch(...) {
00396     MESSAGE("Locked document modification !!!");
00397     throw SALOMEDS::StudyBuilder::LockProtection();
00398   }
00399 }
00400 
00401 //============================================================================
00405 //============================================================================
00406 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
00407 {
00408   SALOMEDS::Locker lock;
00409   return _impl->HasOpenCommand();
00410 }
00411 
00412 //============================================================================
00416 //============================================================================
00417 void SALOMEDS_StudyBuilder_i::AbortCommand()
00418 {
00419   SALOMEDS::Locker lock;
00420   _impl->AbortCommand();
00421 }
00422 
00423 //============================================================================
00427 //============================================================================
00428 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
00429 {
00430   SALOMEDS::Locker lock;
00431   Unexpect aCatch(SBLockProtection);
00432   try {
00433     _impl->Undo();
00434   }
00435   catch(...) {
00436     MESSAGE("Locked document modification !!!");
00437     throw SALOMEDS::StudyBuilder::LockProtection();
00438   }
00439 }
00440 
00441 //============================================================================
00445 //============================================================================
00446 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
00447 {
00448   SALOMEDS::Locker lock;
00449   Unexpect aCatch(SBLockProtection);
00450   try {
00451     _impl->Redo();
00452   }
00453   catch(...) {
00454     MESSAGE("Locked document modification !!!");
00455     throw SALOMEDS::StudyBuilder::LockProtection();
00456   }
00457 }
00458 
00459 //============================================================================
00463 //============================================================================
00464 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
00465 {
00466   SALOMEDS::Locker lock;
00467   return _impl->GetAvailableUndos();
00468 }
00469 
00470 //============================================================================
00474 //============================================================================
00475 CORBA::Boolean  SALOMEDS_StudyBuilder_i::GetAvailableRedos()
00476 {
00477   SALOMEDS::Locker lock;
00478   return _impl->GetAvailableRedos();
00479 }
00480 
00481 //============================================================================
00485 //============================================================================
00486 CORBA::Long  SALOMEDS_StudyBuilder_i::UndoLimit()
00487 {
00488   SALOMEDS::Locker lock;
00489   return _impl->UndoLimit();
00490 }
00491 
00492 //============================================================================
00496 //============================================================================
00497 void  SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
00498 {
00499   SALOMEDS::Locker lock;
00500   CheckLocked();
00501   _impl->UndoLimit(n);
00502 }
00503 
00504 //============================================================================
00508 //============================================================================
00509 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) 
00510 {
00511   SALOMEDS::Locker lock;
00512   Unexpect aCatch(SBLockProtection);
00513   try {
00514     _impl->CheckLocked();
00515   }
00516   catch(...) {
00517     throw SALOMEDS::StudyBuilder::LockProtection();
00518   }
00519 }
00520 
00521 //============================================================================
00525 //============================================================================
00526 void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* theValue)
00527      throw(SALOMEDS::StudyBuilder::LockProtection)
00528 {
00529   SALOMEDS::Locker lock;
00530   Unexpect aCatch(SBLockProtection);
00531   CheckLocked();
00532  
00533   CORBA::String_var anID=theSO->GetID();
00534   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());  
00535   _impl->SetName(aSO, std::string(theValue));
00536 }
00537 
00538 //============================================================================
00542 //============================================================================
00543 void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char* theValue)
00544      throw(SALOMEDS::StudyBuilder::LockProtection)
00545 {
00546   SALOMEDS::Locker lock;
00547   Unexpect aCatch(SBLockProtection);
00548   CheckLocked();
00549 
00550   CORBA::String_var anID=theSO->GetID();
00551   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());  
00552   _impl->SetComment(aSO, std::string(theValue));
00553 }
00554 
00555 //============================================================================
00559 //============================================================================
00560 void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* theValue)
00561  throw(SALOMEDS::StudyBuilder::LockProtection)
00562 {
00563   SALOMEDS::Locker lock;
00564   Unexpect aCatch(SBLockProtection);
00565   CheckLocked();
00566 
00567   CORBA::String_var anID=theSO->GetID();
00568   SALOMEDSImpl_SObject aSO = _impl->GetOwner()->GetSObject(anID.in());  
00569   _impl->SetIOR(aSO, std::string(theValue));
00570 }