1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <boost/shared_ptr.hpp>
24 #include "SMESHGUI_GEOMGenUtils.h"
25 #include "SMESHGUI_Utils.h"
27 #include <GeometryGUI.h>
29 #include <SALOMEDSClient_SObject.hxx>
30 #include <SALOMEDSClient_ChildIterator.hxx>
31 #include <SALOMEDS_SObject.hxx>
33 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
38 GEOM::GEOM_Gen_var GetGEOMGen()
40 static GEOM::GEOM_Gen_var aGEOMGen;
42 if(CORBA::is_nil(aGEOMGen)) {
43 if ( GeometryGUI::GetGeomGen()->_is_nil() )
44 GeometryGUI::InitGeomGen();
45 aGEOMGen = GeometryGUI::GetGeomGen();
50 GEOM::GEOM_Object_var GetShapeOnMeshOrSubMesh(_PTR(SObject) theMeshOrSubmesh)
52 SALOMEDS_SObject* aMeshOrSubmesh = _CAST(SObject,theMeshOrSubmesh);
54 CORBA::Object_var Obj = aMeshOrSubmesh->GetObject();
55 if ( !CORBA::is_nil( Obj ) ) {
56 SMESH::SMESH_Mesh_var aMesh =
57 SObjectToInterface<SMESH::SMESH_Mesh>( theMeshOrSubmesh );
58 if ( !aMesh->_is_nil() )
59 return aMesh->GetShapeToMesh();
60 SMESH::SMESH_subMesh_var aSubmesh =
61 SObjectToInterface<SMESH::SMESH_subMesh>( theMeshOrSubmesh );
62 if ( !aSubmesh->_is_nil() )
63 return aSubmesh->GetSubShape();
66 return GEOM::GEOM_Object::_nil();
69 GEOM::GEOM_Object_ptr GetGeom (_PTR(SObject) theSO)
72 return GEOM::GEOM_Object::_nil();
74 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
76 return GEOM::GEOM_Object::_nil();
78 _PTR(ChildIterator) anIter (aStudy->NewChildIterator(theSO));
79 for (; anIter->More(); anIter->Next()) {
80 _PTR(SObject) aSObject = anIter->Value();
81 _PTR(SObject) aRefSOClient;
82 GEOM::GEOM_Object_var aMeshShape;
84 if (aSObject->ReferencedObject(aRefSOClient)) {
85 SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
86 aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
88 SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
89 aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
92 if (!aMeshShape->_is_nil())
93 return aMeshShape._retn();
95 return GEOM::GEOM_Object::_nil();
98 GEOM::GEOM_Object_ptr GetSubShape (GEOM::GEOM_Object_ptr theMainShape,
101 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
102 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
103 if (!aStudy || geomGen->_is_nil())
104 return GEOM::GEOM_Object::_nil();
105 GEOM::GEOM_IShapesOperations_var aShapesOp = geomGen->GetIShapesOperations(aStudy->StudyId());
106 if (aShapesOp->_is_nil())
107 return GEOM::GEOM_Object::_nil();
108 GEOM::GEOM_Object_var subShape = aShapesOp->GetSubShape (theMainShape,theID);
109 return subShape._retn();