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_SVTKDataOwner* owner =
104 dynamic_cast<const SalomeApp_SVTKDataOwner*> ( myDataOwners[ ind ].get() );
106 return dynamic_cast<SMESH_Actor*>( owner->GetActor() );
111 //=======================================================================
112 //function : elemTypes
113 //purpose : may return {'Edge' 'Face' 'Volume'} at most
114 //=======================================================================
116 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
118 QValueList<QVariant> types;
119 SMESH_Actor* actor = getActor( ind );
121 TVisualObjPtr object = actor->GetObject();
123 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
124 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
125 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
131 //=======================================================================
132 //function : labeledTypes
133 //purpose : may return {'Point' 'Cell'} at most
134 //=======================================================================
136 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
138 QValueList<QVariant> types;
139 SMESH_Actor* actor = getActor( ind );
141 if ( actor->GetPointsLabeled()) types.append( "Point" );
142 if ( actor->GetCellsLabeled()) types.append( "Cell" );
147 //=======================================================================
148 //function : displayMode
149 //purpose : return SMESH_Actor::EReperesent
150 //=======================================================================
152 QString SMESHGUI_Selection::displayMode( int ind ) const
154 SMESH_Actor* actor = getActor( ind );
156 switch( actor->GetRepresentation() ) {
157 case SMESH_Actor::eEdge: return "eEdge";
158 case SMESH_Actor::eSurface: return "eSurface";
159 case SMESH_Actor::ePoint: return "ePoint";
166 //=======================================================================
167 //function : shrinkMode
168 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
169 //=======================================================================
171 QString SMESHGUI_Selection::shrinkMode( int ind ) const
173 SMESH_Actor* actor = getActor( ind );
174 if ( actor && actor->IsShrunkable() ) {
175 if ( actor->IsShrunk() )
177 return "IsNotShrunk";
179 return "IsNotShrinkable";
182 //=======================================================================
183 //function : entityMode
184 //purpose : may return {'Edge' 'Face' 'Volume'} at most
185 //=======================================================================
187 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
189 QValueList<QVariant> types;
190 SMESH_Actor* actor = getActor( ind );
192 unsigned int aMode = actor->GetEntityMode();
193 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
194 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
195 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
200 //=======================================================================
201 //function : controlMode
202 //purpose : return SMESH_Actor::eControl
203 //=======================================================================
205 QString SMESHGUI_Selection::controlMode( int ind ) const
207 SMESH_Actor* actor = getActor( ind );
209 switch( actor->GetControlMode() ) {
210 case SMESH_Actor::eLength: return "eLength";
211 case SMESH_Actor::eLength2D: return "eLength2D";
212 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
213 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
214 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
215 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
216 case SMESH_Actor::eArea: return "eArea";
217 case SMESH_Actor::eTaper: return "eTaper";
218 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
219 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
220 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
221 case SMESH_Actor::eWarping: return "eWarping";
222 case SMESH_Actor::eSkew: return "eSkew";
229 //=======================================================================
230 //function : numberOfNodes
232 //=======================================================================
234 int SMESHGUI_Selection::numberOfNodes( int ind ) const
236 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
238 CORBA::Object_var obj =
239 SMESH::DataOwnerToObject( static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() ));
240 if ( ! CORBA::is_nil( obj )) {
241 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
242 if ( ! mesh->_is_nil() )
243 return mesh->NbNodes();
244 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
245 if ( !aSubMeshObj->_is_nil() )
246 return aSubMeshObj->GetNumberOfNodes(true);
247 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
248 if ( !aGroupObj->_is_nil() )
249 return aGroupObj->Size();
255 //=======================================================================
256 //function : isComputable
258 //=======================================================================
260 QVariant SMESHGUI_Selection::isComputable( int ind ) const
262 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
264 Handle(SALOME_InteractiveObject) io =
265 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
266 if ( !io.IsNull() ) {
267 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
268 if ( !mesh->_is_nil() ) {
269 _PTR(SObject) so = SMESH::FindSObject( mesh );
271 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
272 return QVariant( !shape->_is_nil(), 0 );
277 return QVariant( false, 0 );
280 //=======================================================================
281 //function : hasReference
283 //=======================================================================
285 QVariant SMESHGUI_Selection::hasReference( int ind ) const
287 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
289 Handle(SALOME_InteractiveObject) io =
290 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
292 return QVariant( io->hasReference(), 0 );
294 return QVariant( false, 0 );
297 //=======================================================================
298 //function : isVisible
300 //=======================================================================
302 QVariant SMESHGUI_Selection::isVisible( int ind ) const
304 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
306 QString entry = static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->entry();
307 SMESH_Actor* actor = SMESH::FindActorByEntry( entry.latin1() );
308 if ( actor && actor->hasIO() ) {
309 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
310 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
313 return QVariant( false, 0 );
317 //=======================================================================
320 //=======================================================================
322 int SMESHGUI_Selection::type( SalomeApp_DataOwner* owner,
325 QString entry = owner->entry();
327 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
331 _PTR(SObject) objFather = obj->GetFather();
332 _PTR(SComponent) objComponent = obj->GetFatherComponent();
334 int aLevel = obj->Depth() - objComponent->Depth(),
335 aFTag = objFather->Tag(),
360 res = SUBMESH_VERTEX;
372 res = SUBMESH_COMPOUND;
384 //=======================================================================
385 //function : typeName
387 //=======================================================================
389 QString SMESHGUI_Selection::typeName( const int t )
402 return "Mesh or submesh";
404 return "Mesh vertex";
411 case SUBMESH_COMPOUND:
412 return "Mesh compound";