Back to index

salome-kernel  6.5.0
SALOMEDS_UseCaseBuilder.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_UseCaseBuilder.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 
00027 #include "SALOMEDS_UseCaseBuilder.hxx"
00028 
00029 #include "SALOMEDS.hxx"
00030 #include "SALOMEDS_SObject.hxx"
00031 #include "SALOMEDS_UseCaseIterator.hxx"
00032 
00033 #include "SALOMEDSImpl_SObject.hxx"
00034 #include "SALOMEDSImpl_UseCaseIterator.hxx"
00035 
00036 #include <string>
00037 
00038 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(SALOMEDSImpl_UseCaseBuilder* theBuilder)
00039 {
00040   _isLocal = true;
00041   _local_impl = theBuilder;
00042   _corba_impl = SALOMEDS::UseCaseBuilder::_nil();
00043 }
00044 
00045 SALOMEDS_UseCaseBuilder::SALOMEDS_UseCaseBuilder(SALOMEDS::UseCaseBuilder_ptr theBuilder)
00046 {
00047   _isLocal = false;
00048   _local_impl = NULL;
00049   _corba_impl = SALOMEDS::UseCaseBuilder::_duplicate(theBuilder);
00050 }
00051 
00052 SALOMEDS_UseCaseBuilder::~SALOMEDS_UseCaseBuilder()
00053 {
00054   if(!_isLocal) _corba_impl->UnRegister(); 
00055 }  
00056 
00057 bool SALOMEDS_UseCaseBuilder::Append(const _PTR(SObject)& theObject)
00058 {
00059   bool ret;
00060   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00061   if (_isLocal) {
00062     SALOMEDS::Locker lock;
00063     ret = _local_impl->Append(*(obj->GetLocalImpl()));
00064   }
00065   else ret = _corba_impl->Append(obj->GetCORBAImpl());
00066   return ret;
00067 }
00068 
00069 bool SALOMEDS_UseCaseBuilder::Remove(const _PTR(SObject)& theObject)
00070 {
00071   bool ret;
00072   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00073   if (_isLocal) {
00074     SALOMEDS::Locker lock;
00075     ret = _local_impl->Remove(*(obj->GetLocalImpl()));
00076   }
00077   else ret = _corba_impl->Remove(obj->GetCORBAImpl());
00078   return ret;
00079 }
00080 
00081 bool SALOMEDS_UseCaseBuilder::AppendTo(const _PTR(SObject)& theFather, _PTR(SObject) theObject)
00082 {
00083   bool ret;
00084   SALOMEDS_SObject* father = dynamic_cast<SALOMEDS_SObject*>(theFather.get());
00085   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00086   if (_isLocal) {
00087     SALOMEDS::Locker lock;
00088     ret = _local_impl->AppendTo(*(father->GetLocalImpl()), *(obj->GetLocalImpl()));
00089   }
00090   else ret = _corba_impl->AppendTo(father->GetCORBAImpl(), obj->GetCORBAImpl());
00091   return ret;
00092 }
00093 
00094 bool SALOMEDS_UseCaseBuilder::InsertBefore(const _PTR(SObject)& theFirst, _PTR(SObject) theNext)
00095 {
00096   bool ret;
00097   SALOMEDS_SObject* first = dynamic_cast<SALOMEDS_SObject*>(theFirst.get());
00098   SALOMEDS_SObject* next = dynamic_cast<SALOMEDS_SObject*>(theNext.get());
00099   if (_isLocal) {
00100     SALOMEDS::Locker lock;
00101     ret = _local_impl->InsertBefore(*(first->GetLocalImpl()), *(next->GetLocalImpl()));
00102   }
00103   else ret = _corba_impl->InsertBefore(first->GetCORBAImpl(), next->GetCORBAImpl());
00104   return ret;
00105 }
00106 
00107 bool SALOMEDS_UseCaseBuilder::SetCurrentObject(const _PTR(SObject)& theObject)
00108 {
00109   bool ret;
00110   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00111   if (_isLocal) {
00112     SALOMEDS::Locker lock;
00113     ret = _local_impl->SetCurrentObject(*(obj->GetLocalImpl()));
00114   }
00115   else ret = _corba_impl->SetCurrentObject(obj->GetCORBAImpl());
00116   return ret;
00117 }
00118 
00119 bool SALOMEDS_UseCaseBuilder::SetRootCurrent()
00120 {
00121   bool ret;
00122   if (_isLocal) {
00123     SALOMEDS::Locker lock;
00124     ret = _local_impl->SetRootCurrent();
00125   }
00126   else ret = _corba_impl->SetRootCurrent();
00127   return ret;
00128 }
00129 
00130 bool SALOMEDS_UseCaseBuilder::HasChildren(const _PTR(SObject)& theObject)
00131 {
00132   bool ret;
00133   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00134   if (_isLocal) {
00135     SALOMEDS::Locker lock;
00136     ret = _local_impl->HasChildren(*(obj->GetLocalImpl()));
00137   }
00138   else ret = _corba_impl->HasChildren(obj->GetCORBAImpl());
00139   return ret;
00140 }
00141 
00142 _PTR(SObject) SALOMEDS_UseCaseBuilder::GetFather(const _PTR(SObject)& theObject)
00143 {
00144   SALOMEDS_SObject* father = NULL;
00145   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00146   if (_isLocal) {
00147     SALOMEDS::Locker lock;
00148     father = new SALOMEDS_SObject(_local_impl->GetFather(*(obj->GetLocalImpl())));
00149   }
00150   else father = new SALOMEDS_SObject(_corba_impl->GetFather(obj->GetCORBAImpl()));
00151   return _PTR(SObject)(father);
00152 }
00153 
00154 bool SALOMEDS_UseCaseBuilder::IsUseCase(const _PTR(SObject)& theObject)
00155 {
00156   bool ret;
00157   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00158   if (_isLocal) {
00159     SALOMEDS::Locker lock;
00160     ret = _local_impl->IsUseCase(*(obj->GetLocalImpl()));
00161   }
00162   else ret = _corba_impl->IsUseCase(obj->GetCORBAImpl());
00163   return ret;
00164 }
00165 
00166 bool SALOMEDS_UseCaseBuilder::IsUseCaseNode(const _PTR(SObject)& theObject)
00167 {
00168   bool ret;
00169   SALOMEDS_SObject* obj = dynamic_cast<SALOMEDS_SObject*>(theObject.get());
00170   if (_isLocal) {
00171     SALOMEDS::Locker lock;
00172     ret = _local_impl->IsUseCaseNode(*(obj->GetLocalImpl()));
00173   }
00174   else ret = _corba_impl->IsUseCaseNode(obj->GetCORBAImpl());
00175   return ret;
00176 }
00177 
00178 bool SALOMEDS_UseCaseBuilder::SetName(const std::string& theName)
00179 {
00180   bool ret;
00181   if (_isLocal) {
00182     SALOMEDS::Locker lock;
00183     ret = _local_impl->SetName(theName);
00184   }
00185   else ret = _corba_impl->SetName((char*)theName.c_str());
00186   return ret;
00187 }
00188 
00189 _PTR(SObject) SALOMEDS_UseCaseBuilder::GetCurrentObject()
00190 {
00191   SALOMEDS_SObject* obj = NULL;
00192   if (_isLocal) {
00193     SALOMEDS::Locker lock;
00194     obj = new SALOMEDS_SObject(_local_impl->GetCurrentObject());
00195   }
00196   else obj = new SALOMEDS_SObject(_corba_impl->GetCurrentObject());
00197   return _PTR(SObject)(obj);
00198 }
00199 
00200 std::string SALOMEDS_UseCaseBuilder::GetName()
00201 {
00202   std::string aName;
00203   if (_isLocal) {
00204     SALOMEDS::Locker lock;
00205     aName = _local_impl->GetName();
00206   }
00207   else aName = _corba_impl->GetName();
00208   return aName;
00209 }
00210 
00211 _PTR(SObject) SALOMEDS_UseCaseBuilder::AddUseCase(const std::string& theName)
00212 {
00213   SALOMEDS_SObject* obj = NULL;
00214   if (_isLocal) {
00215     SALOMEDS::Locker lock;
00216     obj = new SALOMEDS_SObject(_local_impl->AddUseCase(theName));
00217   }
00218   else obj = new SALOMEDS_SObject(_corba_impl->AddUseCase((char*)theName.c_str()));
00219   return _PTR(SObject)(obj);
00220 }
00221 
00222 _PTR(UseCaseIterator) SALOMEDS_UseCaseBuilder::GetUseCaseIterator(const _PTR(SObject)& theObject) 
00223 {
00224   SALOMEDS_UseCaseIterator* it = NULL;
00225   SALOMEDS_SObject* obj = (theObject)?dynamic_cast<SALOMEDS_SObject*>(theObject.get()):NULL;
00226   if (_isLocal) {
00227     SALOMEDS::Locker lock;
00228     if(obj)
00229       it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(*(obj->GetLocalImpl())));
00230     else 
00231       it = new SALOMEDS_UseCaseIterator(_local_impl->GetUseCaseIterator(SALOMEDSImpl_SObject()));
00232   }
00233   else {
00234     if(obj)
00235       it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(obj->GetCORBAImpl()));
00236     else
00237       it = new SALOMEDS_UseCaseIterator(_corba_impl->GetUseCaseIterator(SALOMEDS::SObject::_nil()));
00238   }
00239   return _PTR(UseCaseIterator)(it);
00240 }