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=="isVisible" ) val = QtxValue( isVisible( ind ) );
115 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
116 //if ( val.type() == QVariant::List )
117 //cout << "size: " << val.toList().count() << endl;
122 return LightApp_Selection::param( ind, p );
125 //=======================================================================
126 //function : getVtkOwner
128 //=======================================================================
130 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
132 if( ind >= 0 && ind < count() )
133 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
138 //=======================================================================
139 //function : elemTypes
140 //purpose : may return {'Edge' 'Face' 'Volume'} at most
141 //=======================================================================
143 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
145 QValueList<QVariant> types;
146 SMESH_Actor* actor = getActor( ind );
148 TVisualObjPtr object = actor->GetObject();
150 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
151 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
152 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
158 //=======================================================================
159 //function : labeledTypes
160 //purpose : may return {'Point' 'Cell'} at most
161 //=======================================================================
163 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
165 QValueList<QVariant> types;
166 SMESH_Actor* actor = getActor( ind );
168 if ( actor->GetPointsLabeled()) types.append( "Point" );
169 if ( actor->GetCellsLabeled()) types.append( "Cell" );
174 //=======================================================================
175 //function : displayMode
176 //purpose : return SMESH_Actor::EReperesent
177 //=======================================================================
179 QString SMESHGUI_Selection::displayMode( int ind ) const
181 SMESH_Actor* actor = getActor( ind );
183 switch( actor->GetRepresentation() ) {
184 case SMESH_Actor::eEdge: return "eEdge";
185 case SMESH_Actor::eSurface: return "eSurface";
186 case SMESH_Actor::ePoint: return "ePoint";
193 //=======================================================================
194 //function : shrinkMode
195 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
196 //=======================================================================
198 QString SMESHGUI_Selection::shrinkMode( int ind ) const
200 SMESH_Actor* actor = getActor( ind );
201 if ( actor && actor->IsShrunkable() ) {
202 if ( actor->IsShrunk() )
204 return "IsNotShrunk";
206 return "IsNotShrinkable";
209 //=======================================================================
210 //function : entityMode
211 //purpose : may return {'Edge' 'Face' 'Volume'} at most
212 //=======================================================================
214 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
216 QValueList<QVariant> types;
217 SMESH_Actor* actor = getActor( ind );
219 unsigned int aMode = actor->GetEntityMode();
220 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
221 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
222 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
227 //=======================================================================
228 //function : controlMode
229 //purpose : return SMESH_Actor::eControl
230 //=======================================================================
232 QString SMESHGUI_Selection::controlMode( int ind ) const
234 SMESH_Actor* actor = getActor( ind );
236 switch( actor->GetControlMode() ) {
237 case SMESH_Actor::eLength: return "eLength";
238 case SMESH_Actor::eLength2D: return "eLength2D";
239 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
240 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
241 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
242 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
243 case SMESH_Actor::eArea: return "eArea";
244 case SMESH_Actor::eVolume3D: return "eVolume3D";
245 case SMESH_Actor::eTaper: return "eTaper";
246 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
247 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
248 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
249 case SMESH_Actor::eWarping: return "eWarping";
250 case SMESH_Actor::eSkew: return "eSkew";
257 //=======================================================================
258 //function : isAutoColor
260 //=======================================================================
262 bool SMESHGUI_Selection::isAutoColor( int ind ) const
264 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
266 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
267 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
269 if ( ! CORBA::is_nil( obj )) {
270 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
271 if ( ! mesh->_is_nil() )
272 return mesh->GetAutoColor();
278 //=======================================================================
279 //function : numberOfNodes
281 //=======================================================================
283 int SMESHGUI_Selection::numberOfNodes( int ind ) const
285 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
287 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
288 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
290 if ( ! CORBA::is_nil( obj )) {
291 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
292 if ( ! mesh->_is_nil() )
293 return mesh->NbNodes();
294 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
295 if ( !aSubMeshObj->_is_nil() )
296 return aSubMeshObj->GetNumberOfNodes(true);
297 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
298 if ( !aGroupObj->_is_nil() )
299 return aGroupObj->Size();
305 //=======================================================================
306 //function : isComputable
308 //=======================================================================
310 QVariant SMESHGUI_Selection::isComputable( int ind ) const
312 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
314 /* Handle(SALOME_InteractiveObject) io =
315 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
316 if ( !io.IsNull() ) {
317 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io); // m,sm,gr->m
318 if ( !mesh->_is_nil() ) {*/
319 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
320 //FindSObject( mesh );
322 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
323 if(!CORBA::is_nil(obj)){
324 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
325 if (!mesh->_is_nil()){
326 if(mesh->HasShapeToMesh()) {
327 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
328 return QVariant( !shape->_is_nil(), 0 );
332 return QVariant(!mesh->NbFaces()==0, 0);
337 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
338 return QVariant( !shape->_is_nil(), 0 );
345 return QVariant( false, 0 );
348 //=======================================================================
349 //function : hasReference
351 //=======================================================================
353 QVariant SMESHGUI_Selection::hasReference( int ind ) const
355 return QVariant( isReference( ind ), 0 );
358 //=======================================================================
359 //function : isVisible
361 //=======================================================================
363 QVariant SMESHGUI_Selection::isVisible( int ind ) const
365 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
367 QString ent = entry( ind );
368 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
369 if ( actor && actor->hasIO() ) {
370 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
371 return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 );
374 return QVariant( false, 0 );
377 //=======================================================================
380 //=======================================================================
382 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
384 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
389 if( obj->ReferencedObject( ref ) )
392 _PTR(SObject) objFather = obj->GetFather();
393 _PTR(SComponent) objComponent = obj->GetFatherComponent();
395 if( objComponent->ComponentDataType()!="SMESH" )
398 if( objComponent->GetIOR()==obj->GetIOR() )
401 int aLevel = obj->Depth() - objComponent->Depth(),
402 aFTag = objFather->Tag(),
409 if (anOTag >= SMESH::Tag_FirstMeshRoot)
415 case SMESH::Tag_HypothesisRoot:
418 case SMESH::Tag_AlgorithmsRoot:
426 case SMESH::Tag_SubMeshOnVertex:
427 res = SUBMESH_VERTEX;
429 case SMESH::Tag_SubMeshOnEdge:
432 case SMESH::Tag_SubMeshOnFace:
435 case SMESH::Tag_SubMeshOnSolid:
438 case SMESH::Tag_SubMeshOnCompound:
439 res = SUBMESH_COMPOUND;
442 if (aFTag >= SMESH::Tag_FirstGroup)
453 //=======================================================================
454 //function : typeName
456 //=======================================================================
458 QString SMESHGUI_Selection::typeName( const int t )
471 return "Mesh or submesh";
473 return "Mesh vertex";
480 case SUBMESH_COMPOUND:
481 return "Mesh compound";