Salome HOME
Update mail address
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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       if ( GeometryGUI::GetGeomGen()->_is_nil() )
42         GeometryGUI::InitGeomGen();
43       aGEOMGen = GeometryGUI::GetGeomGen();
44     }
45     return aGEOMGen;
46   }
47
48   GEOM::GEOM_Object_var GetShapeOnMeshOrSubMesh(_PTR(SObject) theMeshOrSubmesh)
49   {
50     SALOMEDS_SObject* aMeshOrSubmesh = _CAST(SObject,theMeshOrSubmesh);
51     if(aMeshOrSubmesh) {
52       CORBA::Object_var Obj = aMeshOrSubmesh->GetObject();
53       if ( !CORBA::is_nil( Obj ) ) {
54         SMESH::SMESH_Mesh_var aMesh =
55           SObjectToInterface<SMESH::SMESH_Mesh>( theMeshOrSubmesh );
56         if ( !aMesh->_is_nil() )
57           return aMesh->GetShapeToMesh();
58         SMESH::SMESH_subMesh_var aSubmesh =
59           SObjectToInterface<SMESH::SMESH_subMesh>( theMeshOrSubmesh );
60         if ( !aSubmesh->_is_nil() )
61           return aSubmesh->GetSubShape();
62       }
63     }
64     return GEOM::GEOM_Object::_nil();
65   }
66
67   GEOM::GEOM_Object_ptr GetGeom (_PTR(SObject) theSO)
68   {
69     if (!theSO)
70       return GEOM::GEOM_Object::_nil();
71
72     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
73     if (!aStudy)
74       return GEOM::GEOM_Object::_nil();
75
76     _PTR(ChildIterator) anIter (aStudy->NewChildIterator(theSO));
77     for (; anIter->More(); anIter->Next()) {
78       _PTR(SObject) aSObject = anIter->Value();
79       _PTR(SObject) aRefSOClient;
80       GEOM::GEOM_Object_var aMeshShape;
81
82       if (aSObject->ReferencedObject(aRefSOClient)) {
83         SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
84         aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
85       } else {
86         SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
87         aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
88       }
89
90       if (!aMeshShape->_is_nil())
91         return aMeshShape._retn();
92     }
93     return GEOM::GEOM_Object::_nil();
94   }
95 }