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 "SMESHGUI_Selection.h"
23 #include "SMESHGUI_Utils.h"
24 #include "SMESHGUI_VTKUtils.h"
25 #include "SMESHGUI_MeshUtils.h"
26 #include "SMESHGUI_GEOMGenUtils.h"
28 #include "SMESH_Type.h"
29 #include "SMESH_Actor.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SalomeApp_Study.h"
33 #include "LightApp_VTKSelector.h"
35 #include "SUIT_Session.h"
37 #include "SVTK_RenderWindowInteractor.h"
38 #include "SVTK_ViewWindow.h"
40 #include CORBA_CLIENT_HEADER(SMESH_Gen)
41 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
42 #include CORBA_CLIENT_HEADER(SMESH_Group)
44 //=======================================================================
45 //function : SMESHGUI_Selection
47 //=======================================================================
48 SMESHGUI_Selection::SMESHGUI_Selection()
49 : LightApp_Selection()
53 //=======================================================================
54 //function : ~SMESHGUI_Selection
56 //=======================================================================
57 SMESHGUI_Selection::~SMESHGUI_Selection()
61 //=======================================================================
64 //=======================================================================
65 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
67 LightApp_Selection::init( client, mgr );
71 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
74 _PTR(Study) aStudy = aSStudy->studyDS();
76 for( int i=0, n=count(); i<n; i++ )
77 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
81 //=======================================================================
82 //function : processOwner
84 //=======================================================================
85 void SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
87 const LightApp_SVTKDataOwner* owner =
88 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
90 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
95 //=======================================================================
98 //=======================================================================
99 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
102 if ( p=="client" ) val = QtxValue( globalParam( p ) );
103 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
104 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
105 else if ( p=="isAutoColor" ) val = QtxValue( isAutoColor( ind ) );
106 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
107 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
108 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
109 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
110 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
111 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
112 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
113 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
114 else if( p=="isImported" ) val = QtxValue( isImported( ind ) );
116 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
118 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
119 //if ( val.type() == QVariant::List )
120 //cout << "size: " << val.toList().count() << endl;
125 return LightApp_Selection::param( ind, p );
128 //=======================================================================
129 //function : getVtkOwner
131 //=======================================================================
133 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
135 if( ind >= 0 && ind < count() )
136 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
141 //=======================================================================
142 //function : elemTypes
143 //purpose : may return {'Edge' 'Face' 'Volume'} at most
144 //=======================================================================
146 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
148 QValueList<QVariant> types;
149 SMESH_Actor* actor = getActor( ind );
151 TVisualObjPtr object = actor->GetObject();
153 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
154 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
155 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
161 //=======================================================================
162 //function : labeledTypes
163 //purpose : may return {'Point' 'Cell'} at most
164 //=======================================================================
166 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
168 QValueList<QVariant> types;
169 SMESH_Actor* actor = getActor( ind );
171 if ( actor->GetPointsLabeled()) types.append( "Point" );
172 if ( actor->GetCellsLabeled()) types.append( "Cell" );
177 //=======================================================================
178 //function : displayMode
179 //purpose : return SMESH_Actor::EReperesent
180 //=======================================================================
182 QString SMESHGUI_Selection::displayMode( int ind ) const
184 SMESH_Actor* actor = getActor( ind );
186 switch( actor->GetRepresentation() ) {
187 case SMESH_Actor::eEdge: return "eEdge";
188 case SMESH_Actor::eSurface: return "eSurface";
189 case SMESH_Actor::ePoint: return "ePoint";
196 //=======================================================================
197 //function : shrinkMode
198 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
199 //=======================================================================
201 QString SMESHGUI_Selection::shrinkMode( int ind ) const
203 SMESH_Actor* actor = getActor( ind );
204 if ( actor && actor->IsShrunkable() ) {
205 if ( actor->IsShrunk() )
207 return "IsNotShrunk";
209 return "IsNotShrinkable";
212 //=======================================================================
213 //function : entityMode
214 //purpose : may return {'Edge' 'Face' 'Volume'} at most
215 //=======================================================================
217 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
219 QValueList<QVariant> types;
220 SMESH_Actor* actor = getActor( ind );
222 unsigned int aMode = actor->GetEntityMode();
223 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
224 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
225 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
230 //=======================================================================
231 //function : controlMode
232 //purpose : return SMESH_Actor::eControl
233 //=======================================================================
235 QString SMESHGUI_Selection::controlMode( int ind ) const
237 SMESH_Actor* actor = getActor( ind );
239 switch( actor->GetControlMode() ) {
240 case SMESH_Actor::eLength: return "eLength";
241 case SMESH_Actor::eLength2D: return "eLength2D";
242 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
243 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
244 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
245 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
246 case SMESH_Actor::eArea: return "eArea";
247 case SMESH_Actor::eVolume3D: return "eVolume3D";
248 case SMESH_Actor::eTaper: return "eTaper";
249 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
250 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
251 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
252 case SMESH_Actor::eWarping: return "eWarping";
253 case SMESH_Actor::eSkew: return "eSkew";
260 //=======================================================================
261 //function : isAutoColor
263 //=======================================================================
265 bool SMESHGUI_Selection::isAutoColor( int ind ) const
267 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
269 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
270 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
272 if ( ! CORBA::is_nil( obj )) {
273 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
274 if ( ! mesh->_is_nil() )
275 return mesh->GetAutoColor();
281 //=======================================================================
282 //function : numberOfNodes
284 //=======================================================================
286 int SMESHGUI_Selection::numberOfNodes( int ind ) const
288 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
290 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
291 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
293 if ( ! CORBA::is_nil( obj )) {
294 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
295 if ( ! mesh->_is_nil() )
296 return mesh->NbNodes();
297 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
298 if ( !aSubMeshObj->_is_nil() )
299 return aSubMeshObj->GetNumberOfNodes(true);
300 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
301 if ( !aGroupObj->_is_nil() )
302 return aGroupObj->Size();
308 //=======================================================================
309 //function : isComputable
311 //=======================================================================
313 QVariant SMESHGUI_Selection::isComputable( int ind ) const
315 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
317 /* Handle(SALOME_InteractiveObject) io =
318 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
319 if ( !io.IsNull() ) {
320 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io); // m,sm,gr->m
321 if ( !mesh->_is_nil() ) {*/
322 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
323 //FindSObject( mesh );
325 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
326 if(!CORBA::is_nil(obj)){
327 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
328 if (!mesh->_is_nil()){
329 if(mesh->HasShapeToMesh()) {
330 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
331 return QVariant( !shape->_is_nil(), 0 );
335 return QVariant(!mesh->NbFaces()==0, 0);
340 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
341 return QVariant( !shape->_is_nil(), 0 );
348 return QVariant( false, 0 );
351 //=======================================================================
352 //function : hasReference
354 //=======================================================================
356 QVariant SMESHGUI_Selection::hasReference( int ind ) const
358 return QVariant( isReference( ind ), 0 );
361 //=======================================================================
362 //function : isVisible
364 //=======================================================================
366 QVariant SMESHGUI_Selection::isVisible( int ind ) const
368 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
370 QString ent = entry( ind );
371 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
372 if ( actor && actor->hasIO() ) {
373 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
374 return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 );
377 return QVariant( false, 0 );
380 //=======================================================================
383 //=======================================================================
385 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
387 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
392 if( obj->ReferencedObject( ref ) )
395 _PTR(SObject) objFather = obj->GetFather();
396 _PTR(SComponent) objComponent = obj->GetFatherComponent();
398 if( objComponent->ComponentDataType()!="SMESH" )
401 if( objComponent->GetIOR()==obj->GetIOR() )
404 int aLevel = obj->Depth() - objComponent->Depth(),
405 aFTag = objFather->Tag(),
412 if (anOTag >= SMESH::Tag_FirstMeshRoot)
418 case SMESH::Tag_HypothesisRoot:
421 case SMESH::Tag_AlgorithmsRoot:
429 case SMESH::Tag_SubMeshOnVertex:
430 res = SUBMESH_VERTEX;
432 case SMESH::Tag_SubMeshOnEdge:
435 case SMESH::Tag_SubMeshOnFace:
438 case SMESH::Tag_SubMeshOnSolid:
441 case SMESH::Tag_SubMeshOnCompound:
442 res = SUBMESH_COMPOUND;
445 if (aFTag >= SMESH::Tag_FirstGroup)
456 //=======================================================================
457 //function : typeName
459 //=======================================================================
461 QString SMESHGUI_Selection::typeName( const int t )
474 return "Mesh or submesh";
476 return "Mesh vertex";
483 case SUBMESH_COMPOUND:
484 return "Mesh compound";
494 bool SMESHGUI_Selection::isImported( const int ind ) const
496 QString e = entry( ind );
497 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e );
501 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) );
502 if( !aMesh->_is_nil() )
504 SALOME_MED::MedFileInfo* inf = aMesh->GetMEDFileInfo();
505 res = strlen( (char*)inf->fileName ) > 0;