Back to index

salome-kernel  6.5.0
SALOMEDS_AttributeTreeNode.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_AttributeTreeNode.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include "SALOMEDS_AttributeTreeNode.hxx"
00028 #include "SALOMEDS.hxx"
00029 
00030 #include <string>
00031 #include <stdexcept>
00032 
00033 #include "SALOMEDSImpl_AttributeTreeNode.hxx"
00034 #include "SALOMEDS_AttributeTreeNode.hxx"
00035 
00036 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDSImpl_AttributeTreeNode* theAttr)
00037 :SALOMEDS_GenericAttribute(theAttr)
00038 {}
00039 
00040 SALOMEDS_AttributeTreeNode::SALOMEDS_AttributeTreeNode(SALOMEDS::AttributeTreeNode_ptr theAttr)
00041 :SALOMEDS_GenericAttribute(theAttr)
00042 {}
00043 
00044 SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode()
00045 {}
00046 
00047 void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value)
00048 {
00049   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00050   if (_isLocal) {
00051     CheckLocked();
00052     SALOMEDS::Locker lock;
00053     SALOMEDSImpl_AttributeTreeNode *aNode, *aFather;
00054     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00055     aFather = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00056     aNode->SetFather(aFather);
00057   }
00058   else {
00059     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00060     SALOMEDS::AttributeTreeNode_var aFather = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00061     aNode->SetFather(aFather);
00062   }
00063 }
00064 
00065 bool SALOMEDS_AttributeTreeNode::HasFather()
00066 {
00067   bool ret;
00068   if (_isLocal) {
00069     SALOMEDS::Locker lock;
00070     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00071     ret = aNode->HasFather();
00072   }
00073   else {
00074     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00075     ret = aNode->HasFather();
00076   }
00077   return ret;
00078 }
00079 
00080 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather()
00081 {
00082   SALOMEDSClient_AttributeTreeNode* aTN  = NULL;
00083   if (_isLocal) {
00084     SALOMEDS::Locker lock;
00085     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00086     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
00087   }
00088   else {
00089     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00090     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFather());
00091   }
00092   return _PTR(AttributeTreeNode)(aTN);
00093 }
00094 
00095 void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value)
00096 {
00097   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00098   if (_isLocal) {
00099     CheckLocked();
00100     SALOMEDS::Locker lock;
00101     SALOMEDSImpl_AttributeTreeNode *aNode, *aPrev;
00102     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00103     aPrev = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00104     aNode->SetPrevious(aPrev);
00105   }
00106   else {
00107     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00108     SALOMEDS::AttributeTreeNode_var aPrev = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00109     aNode->SetPrevious(aPrev);
00110   }
00111 }
00112 
00113 bool SALOMEDS_AttributeTreeNode::HasPrevious()
00114 {
00115   bool ret;
00116   if (_isLocal) {
00117     SALOMEDS::Locker lock;
00118     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00119     ret = aNode->HasPrevious();
00120   }
00121   else {
00122     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00123     ret = aNode->HasPrevious();
00124   }
00125   return ret;
00126 }
00127 
00128 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious()
00129 {
00130   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
00131   if (_isLocal) {
00132     SALOMEDS::Locker lock;
00133     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00134     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
00135   }
00136   else {
00137     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00138     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetPrevious());
00139   }
00140   return _PTR(AttributeTreeNode)(aTN);
00141 }
00142 
00143 void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value)
00144 {
00145   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00146   if (_isLocal) {
00147     CheckLocked();
00148     SALOMEDS::Locker lock;
00149     SALOMEDSImpl_AttributeTreeNode  *aNode, *aNext;
00150     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00151     aNext = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00152     aNode->SetNext(aNext);
00153   }
00154   else {
00155     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00156     SALOMEDS::AttributeTreeNode_var aNext = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00157     aNode->SetNext(aNext);
00158   }
00159 }
00160 
00161 bool SALOMEDS_AttributeTreeNode::HasNext()
00162 {
00163   bool ret;
00164   if (_isLocal) {
00165     SALOMEDS::Locker lock;
00166     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00167     ret = aNode->HasNext();
00168   }
00169   else {
00170     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00171     ret = aNode->HasNext();
00172   }
00173   return ret;
00174 }
00175 
00176 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext()
00177 {
00178   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
00179   if (_isLocal) {
00180     SALOMEDS::Locker lock;
00181     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00182     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
00183   }
00184   else {
00185     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00186     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetNext());
00187   }
00188   return _PTR(AttributeTreeNode)(aTN);
00189 }
00190 
00191 void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value)
00192 {
00193   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00194   if (_isLocal) {
00195     CheckLocked();
00196     SALOMEDS::Locker lock;
00197     SALOMEDSImpl_AttributeTreeNode *aNode, *aFirst;
00198     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00199     aFirst = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00200     aNode->SetFirst(aFirst);
00201   }
00202   else {
00203     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00204     SALOMEDS::AttributeTreeNode_var aFirst = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00205     aNode->SetFirst(aFirst);
00206   }
00207 }
00208 
00209 bool SALOMEDS_AttributeTreeNode::HasFirst()
00210 {
00211   bool ret;
00212   if (_isLocal) {
00213     SALOMEDS::Locker lock;
00214     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00215     ret = aNode->HasFirst();
00216   }
00217   else {
00218     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00219     ret = aNode->HasFirst();
00220   }
00221   return ret;
00222 }
00223 
00224 _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFirst()
00225 {
00226   SALOMEDSClient_AttributeTreeNode* aTN = NULL;
00227   if (_isLocal) {
00228     SALOMEDS::Locker lock;
00229     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00230     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
00231   }
00232   else {
00233     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00234     aTN = new SALOMEDS_AttributeTreeNode(aNode->GetFirst());
00235   }
00236   return _PTR(AttributeTreeNode)(aTN);
00237 }
00238 
00239 void SALOMEDS_AttributeTreeNode::SetTreeID(const std::string& value)
00240 {
00241   if (_isLocal) {
00242     CheckLocked();
00243     SALOMEDS::Locker lock;
00244     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00245     aNode->SetTreeID(value);
00246   }
00247   else {
00248     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00249     aNode->SetTreeID(value.c_str());
00250   }
00251 }
00252 
00253 std::string SALOMEDS_AttributeTreeNode::GetTreeID()
00254 {
00255   std::string aGUID;
00256   if (_isLocal) {
00257     SALOMEDS::Locker lock;
00258     SALOMEDSImpl_AttributeTreeNode* aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00259     aGUID = aNode->GetTreeID();
00260   }
00261   else {
00262     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00263     aGUID = aNode->GetTreeID();
00264   }
00265 
00266   return aGUID;
00267 }
00268 
00269 void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value)
00270 {
00271   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00272   if (_isLocal) {
00273     CheckLocked();
00274     SALOMEDS::Locker lock;
00275     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00276     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00277     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00278     aNode->Append(anOther);
00279   }
00280   else {
00281     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00282     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00283     aNode->Append(anOther);
00284   }
00285 }
00286 
00287 void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value)
00288 {
00289   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00290   if (_isLocal) {
00291     CheckLocked();
00292     SALOMEDS::Locker lock;
00293     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00294     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00295     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00296     aNode->Prepend(anOther);
00297   }
00298   else {
00299     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00300     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00301     aNode->Prepend(anOther);
00302   }
00303 }
00304 
00305 void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value)
00306 {
00307   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00308   if (_isLocal) {
00309     CheckLocked();
00310     SALOMEDS::Locker lock;
00311     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00312     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00313     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00314     aNode->InsertBefore(anOther);
00315   }
00316   else {
00317     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00318     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00319     aNode->InsertBefore(anOther);
00320   }
00321 }
00322 
00323 void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value)
00324 {
00325   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00326   if (_isLocal) {
00327     CheckLocked();
00328     SALOMEDS::Locker lock;
00329     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00330     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00331     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00332     aNode->InsertAfter(anOther);
00333   }
00334   else {
00335     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00336     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00337     aNode->InsertAfter(anOther);
00338   }
00339 }
00340 
00341 void SALOMEDS_AttributeTreeNode::Remove()
00342 {
00343   if (_isLocal) {
00344     CheckLocked();
00345     SALOMEDS::Locker lock;
00346     dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->Remove();
00347   }
00348   else SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Remove();
00349 }
00350 
00351 int SALOMEDS_AttributeTreeNode::Depth()
00352 {
00353   int aDepth;
00354   if (_isLocal) {
00355     SALOMEDS::Locker lock;
00356     aDepth = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->Depth();
00357   }
00358   else aDepth =  SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Depth();
00359   return aDepth;
00360 }
00361 
00362 bool SALOMEDS_AttributeTreeNode::IsRoot()
00363 {
00364   bool ret;
00365   if (_isLocal) {
00366     SALOMEDS::Locker lock;
00367     ret = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl)->IsRoot();
00368   }
00369   else ret =  SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->IsRoot();
00370   return ret;
00371 }
00372 
00373 bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value)
00374 {
00375   bool ret;
00376   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00377   if (_isLocal) {
00378     SALOMEDS::Locker lock;
00379     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00380     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00381     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00382     ret = aNode->IsDescendant(anOther);
00383   }
00384   else {
00385     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00386     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00387     ret = aNode->IsDescendant(anOther);
00388   }  
00389   return ret;
00390 }
00391 
00392 bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value)
00393 {
00394   bool ret;
00395   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00396   if (_isLocal) {
00397     SALOMEDS::Locker lock;
00398     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00399     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00400     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00401     ret = aNode->IsFather(anOther);
00402   }
00403   else {
00404     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00405     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00406     ret = aNode->IsFather(anOther);
00407   }  
00408   return ret;  
00409 }
00410 
00411 bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value)
00412 {
00413   bool ret;
00414   SALOMEDS_AttributeTreeNode* aTN = dynamic_cast<SALOMEDS_AttributeTreeNode*>(value.get());
00415   if (_isLocal) {
00416     SALOMEDS::Locker lock;
00417     SALOMEDSImpl_AttributeTreeNode *aNode, *anOther;
00418     aNode = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(_local_impl);
00419     anOther = dynamic_cast<SALOMEDSImpl_AttributeTreeNode*>(aTN->_local_impl);
00420     ret = aNode->IsChild(anOther);
00421   }
00422   else {
00423     SALOMEDS::AttributeTreeNode_var aNode = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl);
00424     SALOMEDS::AttributeTreeNode_var anOther = SALOMEDS::AttributeTreeNode::_narrow(aTN->_corba_impl);
00425     ret = aNode->IsChild(anOther);
00426   }  
00427   return ret;  
00428 }
00429 
00430 std::string SALOMEDS_AttributeTreeNode::Label()
00431 {
00432   std::string aLabel;
00433   if (_isLocal) {
00434     SALOMEDS::Locker lock;
00435     aLabel = _local_impl->Label().Entry();
00436   }
00437   else aLabel = SALOMEDS::AttributeTreeNode::_narrow(_corba_impl)->Label();
00438   return aLabel;
00439 }