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;
95 //=======================================================================
96 //function : getVtkOwner
98 //=======================================================================
100 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
102 if ( ind >= 0 && ind < myDataOwners.count() ) {
103 const SalomeApp_DataOwner* owner =
104 dynamic_cast<const SalomeApp_DataOwner*> ( myDataOwners[ ind ].get() );
107 Handle( SALOME_InteractiveObject ) anObj = owner->IO();
108 QString entry = anObj->getEntry();
109 return dynamic_cast<SMESH_Actor*>( SMESH::FindActorByEntry( entry ) );
111 //return dynamic_cast<SMESH_Actor*>( owner->GetActor() );
116 //=======================================================================
117 //function : elemTypes
118 //purpose : may return {'Edge' 'Face' 'Volume'} at most
119 //=======================================================================
121 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
123 QValueList<QVariant> types;
124 SMESH_Actor* actor = getActor( ind );
126 TVisualObjPtr object = actor->GetObject();
128 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
129 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
130 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
136 //=======================================================================
137 //function : labeledTypes
138 //purpose : may return {'Point' 'Cell'} at most
139 //=======================================================================
141 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
143 QValueList<QVariant> types;
144 SMESH_Actor* actor = getActor( ind );
146 if ( actor->GetPointsLabeled()) types.append( "Point" );
147 if ( actor->GetCellsLabeled()) types.append( "Cell" );
152 //=======================================================================
153 //function : displayMode
154 //purpose : return SMESH_Actor::EReperesent
155 //=======================================================================
157 QString SMESHGUI_Selection::displayMode( int ind ) const
159 SMESH_Actor* actor = getActor( ind );
161 switch( actor->GetRepresentation() ) {
162 case SMESH_Actor::eEdge: return "eEdge";
163 case SMESH_Actor::eSurface: return "eSurface";
164 case SMESH_Actor::ePoint: return "ePoint";
171 //=======================================================================
172 //function : shrinkMode
173 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
174 //=======================================================================
176 QString SMESHGUI_Selection::shrinkMode( int ind ) const
178 SMESH_Actor* actor = getActor( ind );
179 if ( actor && actor->IsShrunkable() ) {
180 if ( actor->IsShrunk() )
182 return "IsNotShrunk";
184 return "IsNotShrinkable";
187 //=======================================================================
188 //function : entityMode
189 //purpose : may return {'Edge' 'Face' 'Volume'} at most
190 //=======================================================================
192 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
194 QValueList<QVariant> types;
195 SMESH_Actor* actor = getActor( ind );
197 unsigned int aMode = actor->GetEntityMode();
198 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
199 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
200 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
205 //=======================================================================
206 //function : controlMode
207 //purpose : return SMESH_Actor::eControl
208 //=======================================================================
210 QString SMESHGUI_Selection::controlMode( int ind ) const
212 SMESH_Actor* actor = getActor( ind );
214 switch( actor->GetControlMode() ) {
215 case SMESH_Actor::eLength: return "eLength";
216 case SMESH_Actor::eLength2D: return "eLength2D";
217 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
218 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
219 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
220 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
221 case SMESH_Actor::eArea: return "eArea";
222 case SMESH_Actor::eTaper: return "eTaper";
223 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
224 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
225 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
226 case SMESH_Actor::eWarping: return "eWarping";
227 case SMESH_Actor::eSkew: return "eSkew";
234 //=======================================================================
235 //function : numberOfNodes
237 //=======================================================================
239 int SMESHGUI_Selection::numberOfNodes( int ind ) const
241 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
243 CORBA::Object_var obj =
244 SMESH::DataOwnerToObject( static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() ));
245 if ( ! CORBA::is_nil( obj )) {
246 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
247 if ( ! mesh->_is_nil() )
248 return mesh->NbNodes();
249 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
250 if ( !aSubMeshObj->_is_nil() )
251 return aSubMeshObj->GetNumberOfNodes(true);
252 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
253 if ( !aGroupObj->_is_nil() )
254 return aGroupObj->Size();
260 //=======================================================================
261 //function : isComputable
263 //=======================================================================
265 QVariant SMESHGUI_Selection::isComputable( int ind ) const
267 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
269 Handle(SALOME_InteractiveObject) io =
270 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
271 if ( !io.IsNull() ) {
272 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
273 if ( !mesh->_is_nil() ) {
274 _PTR(SObject) so = SMESH::FindSObject( mesh );
276 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
277 return QVariant( !shape->_is_nil(), 0 );
282 return QVariant( false, 0 );
285 //=======================================================================
286 //function : hasReference
288 //=======================================================================
290 QVariant SMESHGUI_Selection::hasReference( int ind ) const
292 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
294 Handle(SALOME_InteractiveObject) io =
295 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
297 return QVariant( io->hasReference(), 0 );
299 return QVariant( false, 0 );
302 //=======================================================================
303 //function : isVisible
305 //=======================================================================
307 QVariant SMESHGUI_Selection::isVisible( int ind ) const
309 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
311 QString entry = static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->entry();
312 SMESH_Actor* actor = SMESH::FindActorByEntry( entry.latin1() );
313 if ( actor && actor->hasIO() ) {
314 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
315 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
318 return QVariant( false, 0 );
322 //=======================================================================
325 //=======================================================================
327 int SMESHGUI_Selection::type( SalomeApp_DataOwner* owner,
330 QString entry = owner->entry();
332 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
336 _PTR(SObject) objFather = obj->GetFather();
337 _PTR(SComponent) objComponent = obj->GetFatherComponent();
339 int aLevel = obj->Depth() - objComponent->Depth(),
340 aFTag = objFather->Tag(),
365 res = SUBMESH_VERTEX;
377 res = SUBMESH_COMPOUND;
389 //=======================================================================
390 //function : typeName
392 //=======================================================================
394 QString SMESHGUI_Selection::typeName( const int t )
407 return "Mesh or submesh";
409 return "Mesh vertex";
416 case SUBMESH_COMPOUND:
417 return "Mesh compound";