Salome HOME
Using files from package LightApp instead of files from package SalomeApp
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GEOMGenUtils.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 //  This library is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU Lesser General Public
6 //  License as published by the Free Software Foundation; either
7 //  version 2.1 of the License.
8 //
9 //  This library is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 //  Lesser General Public License for more details.
13 //
14 //  You should have received a copy of the GNU Lesser General Public
15 //  License along with this library; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19
20 #include <boost/shared_ptr.hpp>
21
22 #include "SMESHGUI_GEOMGenUtils.h"
23 #include "SMESHGUI_Utils.h"
24
25 #include <GeometryGUI.h>
26
27 #include <SALOMEDSClient_SObject.hxx>
28 #include <SALOMEDSClient_ChildIterator.hxx>
29 #include <SALOMEDS_SObject.hxx>
30
31 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
32
33
34 namespace SMESH {
35
36   GEOM::GEOM_Gen_var GetGEOMGen()
37   {
38     static GEOM::GEOM_Gen_var aGEOMGen;
39
40     if(CORBA::is_nil(aGEOMGen))
41         aGEOMGen = GeometryGUI::GetGeomGen();
42     return aGEOMGen;
43   }
44
45   GEOM::GEOM_Object_var GetShapeOnMeshOrSubMesh(_PTR(SObject) theMeshOrSubmesh)
46   {
47     SALOMEDS_SObject* aMeshOrSubmesh = _CAST(SObject,theMeshOrSubmesh);
48     if(aMeshOrSubmesh) {
49       CORBA::Object_var Obj = aMeshOrSubmesh->GetObject();
50       if ( !CORBA::is_nil( Obj ) ) {
51         SMESH::SMESH_Mesh_var aMesh =
52           SObjectToInterface<SMESH::SMESH_Mesh>( theMeshOrSubmesh );
53         if ( !aMesh->_is_nil() )
54           return aMesh->GetShapeToMesh();
55         SMESH::SMESH_subMesh_var aSubmesh =
56           SObjectToInterface<SMESH::SMESH_subMesh>( theMeshOrSubmesh );
57         if ( !aSubmesh->_is_nil() )
58           return aSubmesh->GetSubShape();
59       }
60     }
61     return GEOM::GEOM_Object::_nil();
62   }
63
64   GEOM::GEOM_Object_ptr GetGeom (_PTR(SObject) theSO)
65   {
66     if (!theSO)
67       return GEOM::GEOM_Object::_nil();
68
69     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
70     if (!aStudy)
71       return GEOM::GEOM_Object::_nil();
72
73     _PTR(ChildIterator) anIter (aStudy->NewChildIterator(theSO));
74     for (; anIter->More(); anIter->Next()) {
75       _PTR(SObject) aSObject = anIter->Value();
76       _PTR(SObject) aRefSOClient;
77       GEOM::GEOM_Object_var aMeshShape;
78
79       if (aSObject->ReferencedObject(aRefSOClient)) {
80         SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
81         aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
82       } else {
83         SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
84         aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
85       }
86
87       if (!aMeshShape->_is_nil())
88         return aMeshShape._retn();
89     }
90     return GEOM::GEOM_Object::_nil();
91   }
92 }