1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GEOMGenUtils.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_GEOMGenUtils.h"
29 #include "SMESHGUI_Utils.h"
32 // SALOME GEOM includes
33 #include <GeometryGUI.h>
34 #include <GEOM_wrap.hxx>
36 // SALOME KERNEL includes
37 #include <SALOMEDS_SObject.hxx>
40 #include <SALOMEconfig.h>
41 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
47 GEOM::GEOM_Gen_var GetGEOMGen()
49 static GEOM::GEOM_Gen_var aGEOMGen;
51 if(CORBA::is_nil(aGEOMGen)) {
52 if ( GeometryGUI::GetGeomGen()->_is_nil() )
53 GeometryGUI::InitGeomGen();
54 aGEOMGen = GeometryGUI::GetGeomGen();
59 GEOM::GEOM_Object_var GetShapeOnMeshOrSubMesh(_PTR(SObject) theMeshOrSubmesh,
62 SALOMEDS_SObject* aMeshOrSubmesh = _CAST(SObject,theMeshOrSubmesh);
64 CORBA::Object_var Obj = aMeshOrSubmesh->GetObject();
65 if ( !CORBA::is_nil( Obj ) ) {
66 SMESH::SMESH_Mesh_var aMesh =
67 SObjectToInterface<SMESH::SMESH_Mesh>( theMeshOrSubmesh );
68 if ( !aMesh->_is_nil() )
70 if ( isMesh ) *isMesh = true;
71 return aMesh->GetShapeToMesh();
73 SMESH::SMESH_subMesh_var aSubmesh =
74 SObjectToInterface<SMESH::SMESH_subMesh>( theMeshOrSubmesh );
75 if ( !aSubmesh->_is_nil() )
77 if ( isMesh ) *isMesh = false;
78 return aSubmesh->GetSubShape();
82 return GEOM::GEOM_Object::_nil();
85 GEOM::GEOM_Object_ptr GetGeom (_PTR(SObject) theSO)
88 return GEOM::GEOM_Object::_nil();
90 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
92 return GEOM::GEOM_Object::_nil();
94 _PTR(ChildIterator) anIter (aStudy->NewChildIterator(theSO));
95 for ( ; anIter->More(); anIter->Next()) {
96 _PTR(SObject) aSObject = anIter->Value();
97 _PTR(SObject) aRefSOClient;
98 GEOM::GEOM_Object_var aMeshShape;
100 if (aSObject->ReferencedObject(aRefSOClient)) {
101 SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
102 aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
104 SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
105 aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
108 if (!aMeshShape->_is_nil())
109 return aMeshShape._retn();
111 return GEOM::GEOM_Object::_nil();
114 SMESHGUI_EXPORT char* GetGeomName( _PTR(SObject) smeshSO )
119 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
123 _PTR(ChildIterator) anIter (aStudy->NewChildIterator( smeshSO ));
124 for ( ; anIter->More(); anIter->Next()) {
125 _PTR(SObject) aSObject = anIter->Value();
126 _PTR(SObject) aRefSOClient;
127 GEOM::GEOM_Object_var aMeshShape;
129 if (aSObject->ReferencedObject(aRefSOClient)) {
130 SALOMEDS_SObject* aRefSO = _CAST(SObject,aRefSOClient);
131 aMeshShape = GEOM::GEOM_Object::_narrow(aRefSO->GetObject());
132 aSObject = aRefSOClient;
135 SALOMEDS_SObject* aSO = _CAST(SObject,aSObject);
136 aMeshShape = GEOM::GEOM_Object::_narrow(aSO->GetObject());
139 if (!aMeshShape->_is_nil())
141 std::string name = aSObject->GetName();
142 return CORBA::string_dup( name.c_str() );
148 GEOM::GEOM_Object_ptr GetSubShape (GEOM::GEOM_Object_ptr theMainShape,
151 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
152 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
153 if (!aStudy || geomGen->_is_nil())
154 return GEOM::GEOM_Object::_nil();
155 GEOM::GEOM_IShapesOperations_wrap aShapesOp =
156 geomGen->GetIShapesOperations(aStudy->StudyId());
157 if (aShapesOp->_is_nil())
158 return GEOM::GEOM_Object::_nil();
159 GEOM::GEOM_Object_wrap subShape = aShapesOp->GetSubShape (theMainShape,theID);
160 return subShape._retn();
163 //================================================================================
165 * \brief Return entries of sub-mesh geometry and mesh geometry by an IO of assigned
167 * \param [in] hypIO - IO of hyp which is a reference SO to a hyp SO
168 * \param [out] subGeom - found entry of a sub-mesh if any
169 * \param [out] meshGeom - found entry of a mesh
170 * \return bool - \c true if any geometry has been found
172 //================================================================================
174 bool GetGeomEntries( Handle(SALOME_InteractiveObject)& hypIO,
180 if ( hypIO.IsNull() ) return false;
182 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
183 if ( !aStudy ) return false;
185 _PTR(SObject) hypSO = aStudy->FindObjectID( hypIO->getEntry() );
186 if ( !hypSO ) return false;
188 // Depth() is a number of fathers
189 if ( hypSO->Depth() == 4 ) // hypSO is not a reference to a hyp but a hyp it-self
191 SMESH::SMESH_Hypothesis_var hyp =
192 SMESH::SObjectToInterface< SMESH::SMESH_Hypothesis >( hypSO );
193 SMESH::SMESH_Mesh_var mesh;
194 GEOM::GEOM_Object_var geom;
195 SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGUI()->GetSMESHGen();
196 if ( !gen || !gen->GetSoleSubMeshUsingHyp( hyp, mesh.out(), geom.out() ))
199 subGeom = toQStr( geom->GetStudyEntry() );
201 geom = mesh->GetShapeToMesh();
202 if ( geom->_is_nil() )
204 meshGeom = toQStr( geom->GetStudyEntry() );
208 _PTR(SObject) appliedSO = hypSO->GetFather(); // "Applied hypotheses" folder
209 if ( !appliedSO ) return false;
211 _PTR(SObject) subOrMeshSO = appliedSO->GetFather(); // mesh or sub-mesh SO
212 if ( !subOrMeshSO ) return false;
215 GEOM::GEOM_Object_var geom = GetShapeOnMeshOrSubMesh( subOrMeshSO, &isMesh );
216 if ( geom->_is_nil() )
221 meshGeom = toQStr( geom->GetStudyEntry() );
222 return !meshGeom.isEmpty();
225 subGeom = toQStr( geom->GetStudyEntry() );
227 _PTR(SObject) subFolderSO = subOrMeshSO->GetFather(); // "SubMeshes on ..." folder
228 if ( !subFolderSO ) return false;
230 _PTR(SObject) meshSO = subFolderSO->GetFather(); // mesh SO
231 if ( !meshSO ) return false;
233 geom = GetShapeOnMeshOrSubMesh( meshSO );
234 if ( geom->_is_nil() )
237 meshGeom = toQStr( geom->GetStudyEntry() );
240 return !meshGeom.isEmpty() && !subGeom.isEmpty();
244 } // end of namespace SMESH