1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI_Selection
24 // File : SMESHGUI_Selection.cxx
25 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
28 #include "SMESHGUI_Selection.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_GEOMGenUtils.h"
33 #include "SMESHGUI_ComputeDlg.h"
35 #include <SMESH_Type.h>
36 #include <SMESH_Actor.h>
37 #include <SMESH_ScalarBarActor.h>
39 // SALOME GUI includes
40 #include <SalomeApp_Study.h>
41 #include <LightApp_VTKSelector.h>
42 #include <SVTK_ViewWindow.h>
45 #include <SALOMEconfig.h>
46 #include CORBA_CLIENT_HEADER(SMESH_Gen)
47 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
48 #include CORBA_CLIENT_HEADER(SMESH_Group)
50 //=======================================================================
51 //function : SMESHGUI_Selection
53 //=======================================================================
54 SMESHGUI_Selection::SMESHGUI_Selection()
55 : LightApp_Selection()
59 //=======================================================================
60 //function : ~SMESHGUI_Selection
62 //=======================================================================
63 SMESHGUI_Selection::~SMESHGUI_Selection()
67 //=======================================================================
70 //=======================================================================
71 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
73 LightApp_Selection::init( client, mgr );
77 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
80 _PTR(Study) aStudy = aSStudy->studyDS();
82 for( int i=0, n=count(); i<n; i++ )
83 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
87 //=======================================================================
88 //function : processOwner
90 //=======================================================================
91 bool SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
93 const LightApp_SVTKDataOwner* owner =
94 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
96 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
102 //=======================================================================
103 //function : parameter
105 //=======================================================================
106 QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
109 if ( p=="client" ) val = QVariant( LightApp_Selection::parameter( p ) );
110 else if ( p=="type" ) val = QVariant( myTypes[ind] );
111 else if ( p=="elemTypes" ) val = QVariant( elemTypes( ind ) );
112 else if ( p=="isAutoColor" ) val = QVariant( isAutoColor( ind ) );
113 else if ( p=="numberOfNodes" ) val = QVariant( numberOfNodes( ind ) );
114 else if ( p=="labeledTypes" ) val = QVariant( labeledTypes( ind ) );
115 else if ( p=="shrinkMode" ) val = QVariant( shrinkMode( ind ) );
116 else if ( p=="entityMode" ) val = QVariant( entityMode( ind ) );
117 else if ( p=="controlMode" ) val = QVariant( controlMode( ind ) );
118 else if ( p=="isNumFunctor" ) val = QVariant( isNumFunctor( ind ) );
119 else if ( p=="displayMode" ) val = QVariant( displayMode( ind ) );
120 else if ( p=="isComputable" ) val = QVariant( isComputable( ind ) );
121 else if ( p=="isPreComputable" ) val = QVariant( isPreComputable( ind ) );
122 else if ( p=="hasReference" ) val = QVariant( hasReference( ind ) );
123 else if ( p=="isImported" ) val = QVariant( isImported( ind ) );
124 else if ( p=="facesOrientationMode" ) val = QVariant( facesOrientationMode( ind ) );
125 else if ( p=="groupType" ) val = QVariant( groupType( ind ) );
126 else if ( p=="quadratic2DMode") val = QVariant(quadratic2DMode(ind));
127 else if ( p=="isDistributionVisible") val = QVariant(isDistributionVisible(ind));
132 return LightApp_Selection::parameter( ind, p );
135 //=======================================================================
136 //function : getVtkOwner
138 //=======================================================================
140 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
142 if( ind >= 0 && ind < count() )
143 return myActors.isEmpty() ? 0 : myActors.at( ind );
148 //=======================================================================
149 //function : elemTypes
150 //purpose : may return {'Elem0d' 'Edge' 'Face' 'Volume'} at most
151 //=======================================================================
153 QList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
155 QList<QVariant> types;
156 SMESH_Actor* actor = getActor( ind );
158 TVisualObjPtr object = actor->GetObject();
160 if ( object->GetNbEntities( SMDSAbs_0DElement )) types.append( "Elem0d" );
161 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
162 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
163 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
169 //=======================================================================
170 //function : labeledTypes
171 //purpose : may return {'Point' 'Cell'} at most
172 //=======================================================================
174 QList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
176 QList<QVariant> types;
177 SMESH_Actor* actor = getActor( ind );
179 if ( actor->GetPointsLabeled()) types.append( "Point" );
180 if ( actor->GetCellsLabeled()) types.append( "Cell" );
185 //=======================================================================
186 //function : displayMode
187 //purpose : return SMESH_Actor::EReperesent
188 //=======================================================================
190 QString SMESHGUI_Selection::displayMode( int ind ) const
192 SMESH_Actor* actor = getActor( ind );
194 switch( actor->GetRepresentation() ) {
195 case SMESH_Actor::eEdge: return "eEdge";
196 case SMESH_Actor::eSurface: return "eSurface";
197 case SMESH_Actor::ePoint: return "ePoint";
205 //=======================================================================
206 //function : quadratic2DMode
207 //purpose : return SMESH_Actor::EQuadratic2DRepresentation
208 //=======================================================================
209 QString SMESHGUI_Selection::quadratic2DMode( int ind ) const
211 SMESH_Actor* actor = getActor( ind );
213 switch( actor->GetQuadratic2DRepresentation() ) {
214 case SMESH_Actor::eLines: return "eLines";
215 case SMESH_Actor::eArcs: return "eArcs";
222 //=======================================================================
223 //function : isDistributionVisible
224 //purpose : Visible/Invisible distribution of the ScalarBar Actor
225 //=======================================================================
227 bool SMESHGUI_Selection::isDistributionVisible(int ind) const {
228 SMESH_Actor* actor = getActor( ind );
229 return (actor && actor->GetScalarBarActor() && actor->GetScalarBarActor()->GetDistributionVisibility());
232 //=======================================================================
233 //function : shrinkMode
234 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
235 //=======================================================================
237 QString SMESHGUI_Selection::shrinkMode( int ind ) const
239 SMESH_Actor* actor = getActor( ind );
240 if ( actor && actor->IsShrunkable() ) {
241 if ( actor->IsShrunk() )
243 return "IsNotShrunk";
245 return "IsNotShrinkable";
248 //=======================================================================
249 //function : entityMode
250 //purpose : may return {'Elem0d' 'Edge' 'Face' 'Volume'} at most
251 //=======================================================================
253 QList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
255 QList<QVariant> types;
256 SMESH_Actor* actor = getActor( ind );
258 unsigned int aMode = actor->GetEntityMode();
259 if ( aMode & SMESH_Actor::eVolumes ) types.append( "Volume" );
260 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
261 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
262 if ( aMode & SMESH_Actor::e0DElements ) types.append( "Elem0d" );
267 //=======================================================================
268 //function : controlMode
269 //purpose : return SMESH_Actor::eControl
270 //=======================================================================
272 QString SMESHGUI_Selection::controlMode( int ind ) const
274 SMESH_Actor* actor = getActor( ind );
276 switch( actor->GetControlMode() ) {
277 case SMESH_Actor::eLength: return "eLength";
278 case SMESH_Actor::eLength2D: return "eLength2D";
279 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
280 case SMESH_Actor::eFreeNodes: return "eFreeNodes";
281 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
282 case SMESH_Actor::eFreeFaces: return "eFreeFaces";
283 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
284 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
285 case SMESH_Actor::eArea: return "eArea";
286 case SMESH_Actor::eVolume3D: return "eVolume3D";
287 case SMESH_Actor::eMaxElementLength2D: return "eMaxElementLength2D";
288 case SMESH_Actor::eMaxElementLength3D: return "eMaxElementLength3D";
289 case SMESH_Actor::eTaper: return "eTaper";
290 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
291 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
292 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
293 case SMESH_Actor::eWarping: return "eWarping";
294 case SMESH_Actor::eSkew: return "eSkew";
301 bool SMESHGUI_Selection::isNumFunctor( int ind ) const
304 SMESH_Actor* actor = getActor( ind );
306 switch( actor->GetControlMode() ) {
307 case SMESH_Actor::eLength:
308 case SMESH_Actor::eLength2D:
309 case SMESH_Actor::eMultiConnection:
310 case SMESH_Actor::eMultiConnection2D:
311 case SMESH_Actor::eArea:
312 case SMESH_Actor::eVolume3D:
313 case SMESH_Actor::eMaxElementLength2D:
314 case SMESH_Actor::eMaxElementLength3D:
315 case SMESH_Actor::eTaper:
316 case SMESH_Actor::eAspectRatio:
317 case SMESH_Actor::eAspectRatio3D:
318 case SMESH_Actor::eMinimumAngle:
319 case SMESH_Actor::eWarping:
320 case SMESH_Actor::eSkew:
330 //=======================================================================
331 //function : facesOrientationMode
333 //=======================================================================
335 QString SMESHGUI_Selection::facesOrientationMode( int ind ) const
337 SMESH_Actor* actor = getActor( ind );
339 if ( actor->GetFacesOriented() )
341 return "IsNotOriented";
346 //=======================================================================
347 //function : isAutoColor
349 //=======================================================================
351 bool SMESHGUI_Selection::isAutoColor( int ind ) const
353 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
355 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
356 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
358 if ( ! CORBA::is_nil( obj )) {
359 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
360 if ( ! mesh->_is_nil() )
361 return mesh->GetAutoColor();
367 //=======================================================================
368 //function : numberOfNodes
370 //=======================================================================
372 int SMESHGUI_Selection::numberOfNodes( int ind ) const
374 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
376 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
377 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
379 if ( ! CORBA::is_nil( obj )) {
380 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
381 if ( ! mesh->_is_nil() )
382 return mesh->NbNodes();
383 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
384 if ( !aSubMeshObj->_is_nil() )
385 return aSubMeshObj->GetNumberOfNodes(true);
386 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
387 if ( !aGroupObj->_is_nil() )
388 return aGroupObj->Size();
394 //=======================================================================
395 //function : isComputable
397 //=======================================================================
399 QVariant SMESHGUI_Selection::isComputable( int ind ) const
401 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
403 /* Handle(SALOME_InteractiveObject) io =
404 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
405 if ( !io.IsNull() ) {
406 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io); // m,sm,gr->m
407 if ( !mesh->_is_nil() ) {*/
408 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
409 //FindSObject( mesh );
411 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
412 if(!CORBA::is_nil(obj)){
413 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
414 if (!mesh->_is_nil()){
415 if(mesh->HasShapeToMesh()) {
416 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
417 return QVariant( !shape->_is_nil() );
421 return QVariant(!mesh->NbFaces()==0);
426 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
427 return QVariant( !shape->_is_nil() );
434 return QVariant( false );
437 //=======================================================================
438 //function : isPreComputable
440 //=======================================================================
442 QVariant SMESHGUI_Selection::isPreComputable( int ind ) const
444 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
446 QMap<int,int> modeMap;
447 _PTR(SObject) pMesh = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
448 SMESHGUI_PrecomputeOp::getAssignedAlgos( pMesh, modeMap );
449 return QVariant( modeMap.size() > 1 );
451 return QVariant( false );
454 //=======================================================================
455 //function : hasReference
457 //=======================================================================
459 QVariant SMESHGUI_Selection::hasReference( int ind ) const
461 return QVariant( isReference( ind ) );
464 //=======================================================================
465 //function : isVisible
467 //=======================================================================
469 QVariant SMESHGUI_Selection::isVisible( int ind ) const
471 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
473 QString ent = entry( ind );
474 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.toLatin1().data() );
475 if ( actor && actor->hasIO() ) {
476 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
477 return QVariant( aViewWindow->isVisible( actor->getIO() ) );
480 return QVariant( false );
483 //=======================================================================
486 //=======================================================================
488 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
490 _PTR(SObject) obj (study->FindObjectID(entry.toLatin1().data()));
495 if( obj->ReferencedObject( ref ) )
498 _PTR(SObject) objFather = obj->GetFather();
499 _PTR(SComponent) objComponent = obj->GetFatherComponent();
501 if( objComponent->ComponentDataType()!="SMESH" )
504 if( objComponent->GetIOR()==obj->GetIOR() )
507 int aLevel = obj->Depth() - objComponent->Depth(),
508 aFTag = objFather->Tag(),
515 if (anOTag >= SMESH::Tag_FirstMeshRoot)
521 case SMESH::Tag_HypothesisRoot:
524 case SMESH::Tag_AlgorithmsRoot:
532 case SMESH::Tag_SubMeshOnVertex:
533 res = SUBMESH_VERTEX;
535 case SMESH::Tag_SubMeshOnEdge:
538 case SMESH::Tag_SubMeshOnFace:
541 case SMESH::Tag_SubMeshOnSolid:
544 case SMESH::Tag_SubMeshOnCompound:
545 res = SUBMESH_COMPOUND;
548 if (aFTag >= SMESH::Tag_FirstGroup)
559 //=======================================================================
560 //function : typeName
562 //=======================================================================
564 QString SMESHGUI_Selection::typeName( const int t )
577 return "Mesh or submesh";
579 return "Mesh vertex";
586 case SUBMESH_COMPOUND:
587 return "Mesh compound";
597 bool SMESHGUI_Selection::isImported( const int ind ) const
599 QString e = entry( ind );
600 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e.toLatin1().constData() );
604 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) );
605 if( !aMesh->_is_nil() )
607 SALOME_MED::MedFileInfo* inf = aMesh->GetMEDFileInfo();
608 res = strlen( (char*)inf->fileName ) > 0;
614 //=======================================================================
615 //function : groupType
617 //=======================================================================
619 QString SMESHGUI_Selection::groupType( int ind ) const
621 QString e = entry( ind );
622 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e.toLatin1().constData() );
626 CORBA::Object_var obj = SMESH::SObjectToObject( SO );
628 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( obj );
629 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( obj );
630 if( !aGroup->_is_nil() )
631 type = QString( "Group" );
632 else if ( !aGroupOnGeom->_is_nil() )
633 type = QString( "GroupOnGeom" );