Back to index

salome-smesh  6.5.0
SMESHGUI_GEOMGenUtils.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 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_GEOMGenUtils.cxx
00025 // Author : Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_GEOMGenUtils.h"
00029 #include "SMESHGUI_Utils.h"
00030 
00031 // SALOME GEOM includes
00032 #include <GeometryGUI.h>
00033 
00034 // SALOME KERNEL includes
00035 #include <SALOMEDS_SObject.hxx>
00036 
00037 // IDL includes
00038 #include <SALOMEconfig.h>
00039 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
00040 
00041 namespace SMESH
00042 {
00043   GEOM::GEOM_Gen_var GetGEOMGen()
00044   {
00045     static GEOM::GEOM_Gen_var aGEOMGen;
00046 
00047     if(CORBA::is_nil(aGEOMGen)) {
00048       if ( GeometryGUI::GetGeomGen()->_is_nil() )
00049         GeometryGUI::InitGeomGen();
00050       aGEOMGen = GeometryGUI::GetGeomGen();
00051     }
00052     return aGEOMGen;
00053   }
00054 
00055   GEOM::GEOM_Object_var GetShapeOnMeshOrSubMesh(_PTR(SObject) theMeshOrSubmesh,
00056                                                 bool*         isMesh)
00057   {
00058     SALOMEDS_SObject* aMeshOrSubmesh = _CAST(SObject,theMeshOrSubmesh);
00059     if(aMeshOrSubmesh) {
00060       CORBA::Object_var Obj = aMeshOrSubmesh->GetObject();
00061       if ( !CORBA::is_nil( Obj ) ) {
00062         SMESH::SMESH_Mesh_var aMesh =
00063           SObjectToInterface<SMESH::SMESH_Mesh>( theMeshOrSubmesh );
00064         if ( !aMesh->_is_nil() )
00065         {
00066           if ( isMesh ) *isMesh = true;
00067           return aMesh->GetShapeToMesh();
00068         }
00069         SMESH::SMESH_subMesh_var aSubmesh =
00070           SObjectToInterface<SMESH::SMESH_subMesh>( theMeshOrSubmesh );
00071         if ( !aSubmesh->_is_nil() )
00072         {
00073           if ( isMesh ) *isMesh = false;
00074           return aSubmesh->GetSubShape();
00075         }
00076       }
00077     }
00078     return GEOM::GEOM_Object::_nil();
00079   }
00080 
00081   GEOM::GEOM_Object_ptr GetGeom (_PTR(SObject) theSO)
00082   {
00083     if (!theSO)
00084       return GEOM::GEOM_Object::_nil();
00085 
00086     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00087     if (!aStudy)
00088       return GEOM::GEOM_Object::_nil();
00089 
00090     _PTR(ChildIterator) anIter (aStudy->NewChildIterator(theSO));
00091     for ( ; anIter->More(); anIter->Next()) {
00092       _PTR(SObject) aSObject = anIter->Value();
00093       _PTR(SObject) aRefSOClient;
00094       GEOM::GEOM_Object_var aMeshShape;
00095 
00096       if (aSObject->ReferencedObject(aRefSOClient)) {
00097         SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
00098         aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
00099       } else {
00100         SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
00101         aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
00102       }
00103 
00104       if (!aMeshShape->_is_nil())
00105         return aMeshShape._retn();
00106     }
00107     return GEOM::GEOM_Object::_nil();
00108   }
00109 
00110   GEOM::GEOM_Object_ptr GetSubShape (GEOM::GEOM_Object_ptr theMainShape,
00111                                      long                  theID)
00112   {
00113     GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
00114     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
00115     if (!aStudy || geomGen->_is_nil())
00116       return GEOM::GEOM_Object::_nil();
00117     GEOM::GEOM_IShapesOperations_var aShapesOp = geomGen->GetIShapesOperations(aStudy->StudyId());
00118     if (aShapesOp->_is_nil())
00119       return GEOM::GEOM_Object::_nil();
00120     GEOM::GEOM_Object_var subShape = aShapesOp->GetSubShape (theMainShape,theID);
00121     return subShape._retn();
00122   }
00123 } // end of namespace SMESH