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 for( int i=0, n=count(); i<n; i++ )
53 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
57 //=======================================================================
58 //function : processOwner
60 //=======================================================================
61 void SMESHGUI_Selection::processOwner( const SalomeApp_DataOwner* ow )
63 const SalomeApp_SVTKDataOwner* owner =
64 dynamic_cast<const SalomeApp_SVTKDataOwner*> ( ow );
66 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
71 //=======================================================================
74 //=======================================================================
75 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
78 if ( p=="client" ) val = QtxValue( globalParam( p ) );
79 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
80 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
81 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
82 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
83 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
84 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
85 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
86 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
87 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
88 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
89 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
91 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
92 //if ( val.type() == QVariant::List )
93 //cout << "size: " << val.toList().count() << endl;
98 return SalomeApp_Selection::param( ind, p );
101 //=======================================================================
102 //function : getVtkOwner
104 //=======================================================================
106 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
108 if( ind >= 0 && ind < count() )
109 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
114 //=======================================================================
115 //function : elemTypes
116 //purpose : may return {'Edge' 'Face' 'Volume'} at most
117 //=======================================================================
119 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
121 QValueList<QVariant> types;
122 SMESH_Actor* actor = getActor( ind );
124 TVisualObjPtr object = actor->GetObject();
126 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
127 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
128 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
134 //=======================================================================
135 //function : labeledTypes
136 //purpose : may return {'Point' 'Cell'} at most
137 //=======================================================================
139 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
141 QValueList<QVariant> types;
142 SMESH_Actor* actor = getActor( ind );
144 if ( actor->GetPointsLabeled()) types.append( "Point" );
145 if ( actor->GetCellsLabeled()) types.append( "Cell" );
150 //=======================================================================
151 //function : displayMode
152 //purpose : return SMESH_Actor::EReperesent
153 //=======================================================================
155 QString SMESHGUI_Selection::displayMode( int ind ) const
157 SMESH_Actor* actor = getActor( ind );
159 switch( actor->GetRepresentation() ) {
160 case SMESH_Actor::eEdge: return "eEdge";
161 case SMESH_Actor::eSurface: return "eSurface";
162 case SMESH_Actor::ePoint: return "ePoint";
169 //=======================================================================
170 //function : shrinkMode
171 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
172 //=======================================================================
174 QString SMESHGUI_Selection::shrinkMode( int ind ) const
176 SMESH_Actor* actor = getActor( ind );
177 if ( actor && actor->IsShrunkable() ) {
178 if ( actor->IsShrunk() )
180 return "IsNotShrunk";
182 return "IsNotShrinkable";
185 //=======================================================================
186 //function : entityMode
187 //purpose : may return {'Edge' 'Face' 'Volume'} at most
188 //=======================================================================
190 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
192 QValueList<QVariant> types;
193 SMESH_Actor* actor = getActor( ind );
195 unsigned int aMode = actor->GetEntityMode();
196 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
197 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
198 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
203 //=======================================================================
204 //function : controlMode
205 //purpose : return SMESH_Actor::eControl
206 //=======================================================================
208 QString SMESHGUI_Selection::controlMode( int ind ) const
210 SMESH_Actor* actor = getActor( ind );
212 switch( actor->GetControlMode() ) {
213 case SMESH_Actor::eLength: return "eLength";
214 case SMESH_Actor::eLength2D: return "eLength2D";
215 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
216 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
217 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
218 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
219 case SMESH_Actor::eArea: return "eArea";
220 case SMESH_Actor::eVolume3D: return "eVolume3D";
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 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
243 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
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::GetActiveStudyDocument()->FindObjectID( entry( ind ) );
275 //FindSObject( mesh );
277 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
278 return QVariant( !shape->_is_nil(), 0 );
283 return QVariant( false, 0 );
286 //=======================================================================
287 //function : hasReference
289 //=======================================================================
291 QVariant SMESHGUI_Selection::hasReference( int ind ) const
293 return QVariant( isReference( ind ), 0 );
296 //=======================================================================
297 //function : isVisible
299 //=======================================================================
301 QVariant SMESHGUI_Selection::isVisible( int ind ) const
303 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
305 QString ent = entry( ind );
306 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
307 if ( actor && actor->hasIO() ) {
308 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
309 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
312 return QVariant( false, 0 );
315 //=======================================================================
318 //=======================================================================
320 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
322 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
327 if( obj->ReferencedObject( ref ) )
330 _PTR(SObject) objFather = obj->GetFather();
331 _PTR(SComponent) objComponent = obj->GetFatherComponent();
333 if( objComponent->ComponentDataType()!="SMESH" )
336 if( objComponent->GetIOR()==obj->GetIOR() )
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";