1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "SMESHGUI_Selection.h"
22 #include "SMESHGUI_Utils.h"
23 #include "SMESHGUI_VTKUtils.h"
24 #include "SMESHGUI_MeshUtils.h"
25 #include "SMESHGUI_GEOMGenUtils.h"
27 #include "SMESH_Type.h"
28 #include "SMESH_Actor.h"
30 #include "LightApp_SelectionMgr.h"
31 #include "SalomeApp_Study.h"
32 #include "LightApp_VTKSelector.h"
34 #include "SUIT_Session.h"
36 #include "SVTK_RenderWindowInteractor.h"
37 #include "SVTK_ViewWindow.h"
39 #include CORBA_CLIENT_HEADER(SMESH_Gen)
40 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
41 #include CORBA_CLIENT_HEADER(SMESH_Group)
43 //=======================================================================
44 //function : SMESHGUI_Selection
46 //=======================================================================
47 SMESHGUI_Selection::SMESHGUI_Selection()
48 : LightApp_Selection()
52 //=======================================================================
53 //function : ~SMESHGUI_Selection
55 //=======================================================================
56 SMESHGUI_Selection::~SMESHGUI_Selection()
60 //=======================================================================
63 //=======================================================================
64 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
66 LightApp_Selection::init( client, mgr );
70 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
73 _PTR(Study) aStudy = aSStudy->studyDS();
75 for( int i=0, n=count(); i<n; i++ )
76 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
80 //=======================================================================
81 //function : processOwner
83 //=======================================================================
84 void SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
86 const LightApp_SVTKDataOwner* owner =
87 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
89 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
94 //=======================================================================
97 //=======================================================================
98 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
101 if ( p=="client" ) val = QtxValue( globalParam( p ) );
102 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
103 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
104 else if ( p=="isAutoColor" ) val = QtxValue( isAutoColor( ind ) );
105 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
106 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
107 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
108 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
109 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
110 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
111 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
112 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
113 else if( p=="isImported" ) val = QtxValue( isImported( ind ) );
115 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
117 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
118 //if ( val.type() == QVariant::List )
119 //cout << "size: " << val.toList().count() << endl;
124 return LightApp_Selection::param( ind, p );
127 //=======================================================================
128 //function : getVtkOwner
130 //=======================================================================
132 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
134 if( ind >= 0 && ind < count() )
135 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
140 //=======================================================================
141 //function : elemTypes
142 //purpose : may return {'Edge' 'Face' 'Volume'} at most
143 //=======================================================================
145 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
147 QValueList<QVariant> types;
148 SMESH_Actor* actor = getActor( ind );
150 TVisualObjPtr object = actor->GetObject();
152 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
153 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
154 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
160 //=======================================================================
161 //function : labeledTypes
162 //purpose : may return {'Point' 'Cell'} at most
163 //=======================================================================
165 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
167 QValueList<QVariant> types;
168 SMESH_Actor* actor = getActor( ind );
170 if ( actor->GetPointsLabeled()) types.append( "Point" );
171 if ( actor->GetCellsLabeled()) types.append( "Cell" );
176 //=======================================================================
177 //function : displayMode
178 //purpose : return SMESH_Actor::EReperesent
179 //=======================================================================
181 QString SMESHGUI_Selection::displayMode( int ind ) const
183 SMESH_Actor* actor = getActor( ind );
185 switch( actor->GetRepresentation() ) {
186 case SMESH_Actor::eEdge: return "eEdge";
187 case SMESH_Actor::eSurface: return "eSurface";
188 case SMESH_Actor::ePoint: return "ePoint";
195 //=======================================================================
196 //function : shrinkMode
197 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
198 //=======================================================================
200 QString SMESHGUI_Selection::shrinkMode( int ind ) const
202 SMESH_Actor* actor = getActor( ind );
203 if ( actor && actor->IsShrunkable() ) {
204 if ( actor->IsShrunk() )
206 return "IsNotShrunk";
208 return "IsNotShrinkable";
211 //=======================================================================
212 //function : entityMode
213 //purpose : may return {'Edge' 'Face' 'Volume'} at most
214 //=======================================================================
216 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
218 QValueList<QVariant> types;
219 SMESH_Actor* actor = getActor( ind );
221 unsigned int aMode = actor->GetEntityMode();
222 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
223 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
224 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
229 //=======================================================================
230 //function : controlMode
231 //purpose : return SMESH_Actor::eControl
232 //=======================================================================
234 QString SMESHGUI_Selection::controlMode( int ind ) const
236 SMESH_Actor* actor = getActor( ind );
238 switch( actor->GetControlMode() ) {
239 case SMESH_Actor::eLength: return "eLength";
240 case SMESH_Actor::eLength2D: return "eLength2D";
241 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
242 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
243 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
244 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
245 case SMESH_Actor::eArea: return "eArea";
246 case SMESH_Actor::eVolume3D: return "eVolume3D";
247 case SMESH_Actor::eTaper: return "eTaper";
248 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
249 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
250 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
251 case SMESH_Actor::eWarping: return "eWarping";
252 case SMESH_Actor::eSkew: return "eSkew";
259 //=======================================================================
260 //function : isAutoColor
262 //=======================================================================
264 bool SMESHGUI_Selection::isAutoColor( int ind ) const
266 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
268 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
269 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
271 if ( ! CORBA::is_nil( obj )) {
272 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
273 if ( ! mesh->_is_nil() )
274 return mesh->GetAutoColor();
280 //=======================================================================
281 //function : numberOfNodes
283 //=======================================================================
285 int SMESHGUI_Selection::numberOfNodes( int ind ) const
287 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
289 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
290 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
292 if ( ! CORBA::is_nil( obj )) {
293 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
294 if ( ! mesh->_is_nil() )
295 return mesh->NbNodes();
296 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
297 if ( !aSubMeshObj->_is_nil() )
298 return aSubMeshObj->GetNumberOfNodes(true);
299 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
300 if ( !aGroupObj->_is_nil() )
301 return aGroupObj->Size();
307 //=======================================================================
308 //function : isComputable
310 //=======================================================================
312 QVariant SMESHGUI_Selection::isComputable( int ind ) const
314 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
316 /* Handle(SALOME_InteractiveObject) io =
317 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
318 if ( !io.IsNull() ) {
319 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io); // m,sm,gr->m
320 if ( !mesh->_is_nil() ) {*/
321 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
322 //FindSObject( mesh );
324 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
325 if(!CORBA::is_nil(obj)){
326 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
327 if (!mesh->_is_nil()){
328 if(mesh->HasShapeToMesh()) {
329 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
330 return QVariant( !shape->_is_nil(), 0 );
334 return QVariant(!mesh->NbFaces()==0, 0);
339 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
340 return QVariant( !shape->_is_nil(), 0 );
347 return QVariant( false, 0 );
350 //=======================================================================
351 //function : hasReference
353 //=======================================================================
355 QVariant SMESHGUI_Selection::hasReference( int ind ) const
357 return QVariant( isReference( ind ), 0 );
360 //=======================================================================
361 //function : isVisible
363 //=======================================================================
365 QVariant SMESHGUI_Selection::isVisible( int ind ) const
367 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
369 QString ent = entry( ind );
370 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
371 if ( actor && actor->hasIO() ) {
372 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
373 return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 );
376 return QVariant( false, 0 );
379 //=======================================================================
382 //=======================================================================
384 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
386 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
391 if( obj->ReferencedObject( ref ) )
394 _PTR(SObject) objFather = obj->GetFather();
395 _PTR(SComponent) objComponent = obj->GetFatherComponent();
397 if( objComponent->ComponentDataType()!="SMESH" )
400 if( objComponent->GetIOR()==obj->GetIOR() )
403 int aLevel = obj->Depth() - objComponent->Depth(),
404 aFTag = objFather->Tag(),
411 if (anOTag >= SMESH::Tag_FirstMeshRoot)
417 case SMESH::Tag_HypothesisRoot:
420 case SMESH::Tag_AlgorithmsRoot:
428 case SMESH::Tag_SubMeshOnVertex:
429 res = SUBMESH_VERTEX;
431 case SMESH::Tag_SubMeshOnEdge:
434 case SMESH::Tag_SubMeshOnFace:
437 case SMESH::Tag_SubMeshOnSolid:
440 case SMESH::Tag_SubMeshOnCompound:
441 res = SUBMESH_COMPOUND;
444 if (aFTag >= SMESH::Tag_FirstGroup)
455 //=======================================================================
456 //function : typeName
458 //=======================================================================
460 QString SMESHGUI_Selection::typeName( const int t )
473 return "Mesh or submesh";
475 return "Mesh vertex";
482 case SUBMESH_COMPOUND:
483 return "Mesh compound";
493 bool SMESHGUI_Selection::isImported( const int ind ) const
495 QString e = entry( ind );
496 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e );
500 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) );
501 if( !aMesh->_is_nil() )
503 SALOME_MED::MedFileInfo* inf = aMesh->GetMEDFileInfo();
504 res = strlen( (char*)inf->fileName ) > 0;