2 #include "SMESHGUI_Selection.h"
3 #include "SMESHGUI_Utils.h"
4 #include "SMESHGUI_VTKUtils.h"
5 #include "SMESHGUI_MeshUtils.h"
6 #include "SMESHGUI_GEOMGenUtils.h"
8 #include "SMESH_Type.h"
9 #include "SMESH_Actor.h"
11 #include "LightApp_SelectionMgr.h"
12 #include "SalomeApp_Study.h"
13 #include "LightApp_VTKSelector.h"
15 #include "SUIT_Session.h"
17 #include "SVTK_RenderWindowInteractor.h"
18 #include "SVTK_ViewWindow.h"
20 #include CORBA_SERVER_HEADER(SMESH_Mesh)
21 #include CORBA_SERVER_HEADER(SMESH_Group)
23 //=======================================================================
24 //function : SMESHGUI_Selection
26 //=======================================================================
27 SMESHGUI_Selection::SMESHGUI_Selection()
28 : LightApp_Selection()
32 //=======================================================================
33 //function : ~SMESHGUI_Selection
35 //=======================================================================
36 SMESHGUI_Selection::~SMESHGUI_Selection()
40 //=======================================================================
43 //=======================================================================
44 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
46 LightApp_Selection::init( client, mgr );
50 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
53 _PTR(Study) aStudy = aSStudy->studyDS();
55 for( int i=0, n=count(); i<n; i++ )
56 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
60 //=======================================================================
61 //function : processOwner
63 //=======================================================================
64 void SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
66 const LightApp_SVTKDataOwner* owner =
67 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
69 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
74 //=======================================================================
77 //=======================================================================
78 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
81 if ( p=="client" ) val = QtxValue( globalParam( p ) );
82 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
83 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
84 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
85 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
86 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
87 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
88 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
89 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
90 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
91 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
92 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
94 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
95 //if ( val.type() == QVariant::List )
96 //cout << "size: " << val.toList().count() << endl;
101 return LightApp_Selection::param( ind, p );
104 //=======================================================================
105 //function : getVtkOwner
107 //=======================================================================
109 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
111 if( ind >= 0 && ind < count() )
112 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
117 //=======================================================================
118 //function : elemTypes
119 //purpose : may return {'Edge' 'Face' 'Volume'} at most
120 //=======================================================================
122 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
124 QValueList<QVariant> types;
125 SMESH_Actor* actor = getActor( ind );
127 TVisualObjPtr object = actor->GetObject();
129 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
130 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
131 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
137 //=======================================================================
138 //function : labeledTypes
139 //purpose : may return {'Point' 'Cell'} at most
140 //=======================================================================
142 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
144 QValueList<QVariant> types;
145 SMESH_Actor* actor = getActor( ind );
147 if ( actor->GetPointsLabeled()) types.append( "Point" );
148 if ( actor->GetCellsLabeled()) types.append( "Cell" );
153 //=======================================================================
154 //function : displayMode
155 //purpose : return SMESH_Actor::EReperesent
156 //=======================================================================
158 QString SMESHGUI_Selection::displayMode( int ind ) const
160 SMESH_Actor* actor = getActor( ind );
162 switch( actor->GetRepresentation() ) {
163 case SMESH_Actor::eEdge: return "eEdge";
164 case SMESH_Actor::eSurface: return "eSurface";
165 case SMESH_Actor::ePoint: return "ePoint";
172 //=======================================================================
173 //function : shrinkMode
174 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
175 //=======================================================================
177 QString SMESHGUI_Selection::shrinkMode( int ind ) const
179 SMESH_Actor* actor = getActor( ind );
180 if ( actor && actor->IsShrunkable() ) {
181 if ( actor->IsShrunk() )
183 return "IsNotShrunk";
185 return "IsNotShrinkable";
188 //=======================================================================
189 //function : entityMode
190 //purpose : may return {'Edge' 'Face' 'Volume'} at most
191 //=======================================================================
193 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
195 QValueList<QVariant> types;
196 SMESH_Actor* actor = getActor( ind );
198 unsigned int aMode = actor->GetEntityMode();
199 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
200 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
201 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
206 //=======================================================================
207 //function : controlMode
208 //purpose : return SMESH_Actor::eControl
209 //=======================================================================
211 QString SMESHGUI_Selection::controlMode( int ind ) const
213 SMESH_Actor* actor = getActor( ind );
215 switch( actor->GetControlMode() ) {
216 case SMESH_Actor::eLength: return "eLength";
217 case SMESH_Actor::eLength2D: return "eLength2D";
218 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
219 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
220 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
221 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
222 case SMESH_Actor::eArea: return "eArea";
223 case SMESH_Actor::eVolume3D: return "eVolume3D";
224 case SMESH_Actor::eTaper: return "eTaper";
225 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
226 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
227 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
228 case SMESH_Actor::eWarping: return "eWarping";
229 case SMESH_Actor::eSkew: return "eSkew";
236 //=======================================================================
237 //function : numberOfNodes
239 //=======================================================================
241 int SMESHGUI_Selection::numberOfNodes( int ind ) const
243 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
245 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
246 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
248 if ( ! CORBA::is_nil( obj )) {
249 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
250 if ( ! mesh->_is_nil() )
251 return mesh->NbNodes();
252 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
253 if ( !aSubMeshObj->_is_nil() )
254 return aSubMeshObj->GetNumberOfNodes(true);
255 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
256 if ( !aGroupObj->_is_nil() )
257 return aGroupObj->Size();
263 //=======================================================================
264 //function : isComputable
266 //=======================================================================
268 QVariant SMESHGUI_Selection::isComputable( int ind ) const
270 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
272 /* Handle(SALOME_InteractiveObject) io =
273 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
274 if ( !io.IsNull() ) {
275 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
276 if ( !mesh->_is_nil() ) {*/
277 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ) );
278 //FindSObject( mesh );
280 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
281 return QVariant( !shape->_is_nil(), 0 );
286 return QVariant( false, 0 );
289 //=======================================================================
290 //function : hasReference
292 //=======================================================================
294 QVariant SMESHGUI_Selection::hasReference( int ind ) const
296 return QVariant( isReference( ind ), 0 );
299 //=======================================================================
300 //function : isVisible
302 //=======================================================================
304 QVariant SMESHGUI_Selection::isVisible( int ind ) const
306 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
308 QString ent = entry( ind );
309 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
310 if ( actor && actor->hasIO() ) {
311 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
312 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
315 return QVariant( false, 0 );
318 //=======================================================================
321 //=======================================================================
323 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
325 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
330 if( obj->ReferencedObject( ref ) )
333 _PTR(SObject) objFather = obj->GetFather();
334 _PTR(SComponent) objComponent = obj->GetFatherComponent();
336 if( objComponent->ComponentDataType()!="SMESH" )
339 if( objComponent->GetIOR()==obj->GetIOR() )
342 int aLevel = obj->Depth() - objComponent->Depth(),
343 aFTag = objFather->Tag(),
368 res = SUBMESH_VERTEX;
380 res = SUBMESH_COMPOUND;
392 //=======================================================================
393 //function : typeName
395 //=======================================================================
397 QString SMESHGUI_Selection::typeName( const int t )
410 return "Mesh or submesh";
412 return "Mesh vertex";
419 case SUBMESH_COMPOUND:
420 return "Mesh compound";