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 "SalomeApp_SelectionMgr.h"
12 #include "SalomeApp_Study.h"
13 #include "SalomeApp_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 : SalomeApp_Selection()
32 //=======================================================================
33 //function : ~SMESHGUI_Selection
35 //=======================================================================
36 SMESHGUI_Selection::~SMESHGUI_Selection()
40 //=======================================================================
43 //=======================================================================
44 void SMESHGUI_Selection::init( const QString& client, SalomeApp_SelectionMgr* mgr )
46 SalomeApp_Selection::init( client, mgr );
50 _PTR(Study) aStudy = study()->studyDS();
52 SUIT_DataOwnerPtrList sel;
53 mgr->selected( sel, client );
55 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(),
57 for( ; anIt!=aLast; anIt++ )
59 SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
60 SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
62 myTypes.append( typeName( type( sowner, aStudy ) ) );
64 myTypes.append( "Unknown" );
69 //=======================================================================
72 //=======================================================================
73 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
76 if ( p=="client" ) val = QtxValue( globalParam( p ) );
77 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
78 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
79 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
80 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
81 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
82 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
83 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
84 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
85 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
86 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
87 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
89 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
90 //if ( val.type() == QVariant::List )
91 //cout << "size: " << val.toList().count() << endl;
96 return SalomeApp_Selection::param( ind, p );
99 //=======================================================================
100 //function : getVtkOwner
102 //=======================================================================
104 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
106 if ( ind >= 0 && ind < myDataOwners.count() ) {
107 const SalomeApp_SVTKDataOwner* owner =
108 dynamic_cast<const SalomeApp_SVTKDataOwner*> ( myDataOwners[ ind ].get() );
110 return dynamic_cast<SMESH_Actor*>( owner->GetActor() );
115 //=======================================================================
116 //function : elemTypes
117 //purpose : may return {'Edge' 'Face' 'Volume'} at most
118 //=======================================================================
120 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
122 QValueList<QVariant> types;
123 SMESH_Actor* actor = getActor( ind );
125 TVisualObjPtr object = actor->GetObject();
127 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
128 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
129 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
135 //=======================================================================
136 //function : labeledTypes
137 //purpose : may return {'Point' 'Cell'} at most
138 //=======================================================================
140 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
142 QValueList<QVariant> types;
143 SMESH_Actor* actor = getActor( ind );
145 if ( actor->GetPointsLabeled()) types.append( "Point" );
146 if ( actor->GetCellsLabeled()) types.append( "Cell" );
151 //=======================================================================
152 //function : displayMode
153 //purpose : return SMESH_Actor::EReperesent
154 //=======================================================================
156 QString SMESHGUI_Selection::displayMode( int ind ) const
158 SMESH_Actor* actor = getActor( ind );
160 switch( actor->GetRepresentation() ) {
161 case SMESH_Actor::eEdge: return "eEdge";
162 case SMESH_Actor::eSurface: return "eSurface";
163 case SMESH_Actor::ePoint: return "ePoint";
170 //=======================================================================
171 //function : shrinkMode
172 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
173 //=======================================================================
175 QString SMESHGUI_Selection::shrinkMode( int ind ) const
177 SMESH_Actor* actor = getActor( ind );
178 if ( actor && actor->IsShrunkable() ) {
179 if ( actor->IsShrunk() )
181 return "IsNotShrunk";
183 return "IsNotShrinkable";
186 //=======================================================================
187 //function : entityMode
188 //purpose : may return {'Edge' 'Face' 'Volume'} at most
189 //=======================================================================
191 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
193 QValueList<QVariant> types;
194 SMESH_Actor* actor = getActor( ind );
196 unsigned int aMode = actor->GetEntityMode();
197 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
198 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
199 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
204 //=======================================================================
205 //function : controlMode
206 //purpose : return SMESH_Actor::eControl
207 //=======================================================================
209 QString SMESHGUI_Selection::controlMode( int ind ) const
211 SMESH_Actor* actor = getActor( ind );
213 switch( actor->GetControlMode() ) {
214 case SMESH_Actor::eLength: return "eLength";
215 case SMESH_Actor::eLength2D: return "eLength2D";
216 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
217 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
218 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
219 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
220 case SMESH_Actor::eArea: return "eArea";
221 case SMESH_Actor::eTaper: return "eTaper";
222 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
223 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
224 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
225 case SMESH_Actor::eWarping: return "eWarping";
226 case SMESH_Actor::eSkew: return "eSkew";
233 //=======================================================================
234 //function : numberOfNodes
236 //=======================================================================
238 int SMESHGUI_Selection::numberOfNodes( int ind ) const
240 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
242 CORBA::Object_var obj =
243 SMESH::DataOwnerToObject( static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() ));
244 if ( ! CORBA::is_nil( obj )) {
245 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
246 if ( ! mesh->_is_nil() )
247 return mesh->NbNodes();
248 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
249 if ( !aSubMeshObj->_is_nil() )
250 return aSubMeshObj->GetNumberOfNodes(true);
251 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
252 if ( !aGroupObj->_is_nil() )
253 return aGroupObj->Size();
259 //=======================================================================
260 //function : isComputable
262 //=======================================================================
264 QVariant SMESHGUI_Selection::isComputable( int ind ) const
266 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
268 Handle(SALOME_InteractiveObject) io =
269 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
270 if ( !io.IsNull() ) {
271 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
272 if ( !mesh->_is_nil() ) {
273 _PTR(SObject) so = SMESH::FindSObject( mesh );
275 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
276 return QVariant( !shape->_is_nil(), 0 );
281 return QVariant( false, 0 );
284 //=======================================================================
285 //function : hasReference
287 //=======================================================================
289 QVariant SMESHGUI_Selection::hasReference( int ind ) const
291 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
293 SalomeApp_DataOwner* owner = dynamic_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].operator->() );
296 _PTR(SObject) obj ( study()->studyDS()->FindObjectID( owner->entry().latin1() ) ), ref;
297 return QVariant( obj->ReferencedObject( ref ), 0 );
300 return QVariant( false, 0 );
303 //=======================================================================
304 //function : isVisible
306 //=======================================================================
308 QVariant SMESHGUI_Selection::isVisible( int ind ) const
310 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
312 QString entry = static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->entry();
313 SMESH_Actor* actor = SMESH::FindActorByEntry( entry.latin1() );
314 if ( actor && actor->hasIO() ) {
315 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
316 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
319 return QVariant( false, 0 );
323 //=======================================================================
326 //=======================================================================
327 int SMESHGUI_Selection::type( SalomeApp_DataOwner* owner, _PTR(Study) study )
329 return type( owner->entry(), study );
332 //=======================================================================
335 //=======================================================================
337 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
339 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
344 if( obj->ReferencedObject( ref ) )
347 _PTR(SObject) objFather = obj->GetFather();
348 _PTR(SComponent) objComponent = obj->GetFatherComponent();
350 if( objComponent->ComponentDataType()!="SMESH" )
353 if( objComponent->GetIOR()==obj->GetIOR() )
356 int aLevel = obj->Depth() - objComponent->Depth(),
357 aFTag = objFather->Tag(),
382 res = SUBMESH_VERTEX;
394 res = SUBMESH_COMPOUND;
406 //=======================================================================
407 //function : typeName
409 //=======================================================================
411 QString SMESHGUI_Selection::typeName( const int t )
424 return "Mesh or submesh";
426 return "Mesh vertex";
433 case SUBMESH_COMPOUND:
434 return "Mesh compound";