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