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 //=======================================================================
28 SMESHGUI_Selection::SMESHGUI_Selection( const QString& client,
29 SalomeApp_SelectionMgr* mgr )
31 myPopupClient = client;
33 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
34 (SUIT_Session::session()->activeApplication()->activeStudy());
38 _PTR(Study) study = appStudy->studyDS();
40 SUIT_DataOwnerPtrList sel;
41 mgr->selected( sel, client );
43 SUIT_DataOwnerPtrList::const_iterator anIt = sel.begin(),
45 for( ; anIt!=aLast; anIt++ )
47 SUIT_DataOwner* owner = ( SUIT_DataOwner* )( (*anIt ).get() );
48 SalomeApp_DataOwner* sowner = dynamic_cast<SalomeApp_DataOwner*>( owner );
50 myTypes.append( typeName( type( sowner, study ) ) );
52 myTypes.append( "Unknown" );
57 SMESHGUI_Selection::~SMESHGUI_Selection()
61 //=======================================================================
64 //=======================================================================
66 int SMESHGUI_Selection::count() const
68 return myTypes.count();
71 //=======================================================================
74 //=======================================================================
76 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
79 if ( p=="client" ) val = QtxValue( myPopupClient );
80 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
81 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
82 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
83 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
84 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
85 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
86 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
87 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
88 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
89 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
90 else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
92 printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
93 if ( val.type() == QVariant::List )
94 cout << "size: " << val.toList().count() << endl;
98 //=======================================================================
99 //function : getVtkOwner
101 //=======================================================================
103 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
105 if ( ind >= 0 && ind < myDataOwners.count() ) {
106 const SalomeApp_SVTKDataOwner* owner =
107 dynamic_cast<const SalomeApp_SVTKDataOwner*> ( myDataOwners[ ind ].get() );
109 return dynamic_cast<SMESH_Actor*>( owner->GetActor() );
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::eTaper: return "eTaper";
221 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
222 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
223 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
224 case SMESH_Actor::eWarping: return "eWarping";
225 case SMESH_Actor::eSkew: return "eSkew";
232 //=======================================================================
233 //function : numberOfNodes
235 //=======================================================================
237 int SMESHGUI_Selection::numberOfNodes( int ind ) const
239 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
241 CORBA::Object_var obj =
242 SMESH::DataOwnerToObject( static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() ));
243 if ( ! CORBA::is_nil( obj )) {
244 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
245 if ( ! mesh->_is_nil() )
246 return mesh->NbNodes();
247 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
248 if ( !aSubMeshObj->_is_nil() )
249 return aSubMeshObj->GetNumberOfNodes(true);
250 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
251 if ( !aGroupObj->_is_nil() )
252 return aGroupObj->Size();
258 //=======================================================================
259 //function : isComputable
261 //=======================================================================
263 QVariant SMESHGUI_Selection::isComputable( int ind ) const
265 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
267 Handle(SALOME_InteractiveObject) io =
268 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
269 if ( !io.IsNull() ) {
270 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
271 if ( !mesh->_is_nil() ) {
272 _PTR(SObject) so = SMESH::FindSObject( mesh );
274 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
275 return QVariant( !shape->_is_nil(), 0 );
280 return QVariant( false, 0 );
283 //=======================================================================
284 //function : hasReference
286 //=======================================================================
288 QVariant SMESHGUI_Selection::hasReference( int ind ) const
290 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
292 Handle(SALOME_InteractiveObject) io =
293 static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
295 return QVariant( io->hasReference(), 0 );
297 return QVariant( false, 0 );
300 //=======================================================================
301 //function : isVisible
303 //=======================================================================
305 QVariant SMESHGUI_Selection::isVisible( int ind ) const
307 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
309 QString entry = static_cast<SalomeApp_DataOwner*>( myDataOwners[ ind ].get() )->entry();
310 SMESH_Actor* actor = SMESH::FindActorByEntry( entry.latin1() );
311 if ( actor && actor->hasIO() ) {
312 SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor();
313 return QVariant( renderInter->isVisible( actor->getIO() ), 0 );
316 return QVariant( false, 0 );
320 //=======================================================================
323 //=======================================================================
325 int SMESHGUI_Selection::type( SalomeApp_DataOwner* owner,
328 QString entry = owner->entry();
330 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
334 _PTR(SObject) objFather = obj->GetFather();
335 _PTR(SComponent) objComponent = obj->GetFatherComponent();
337 int aLevel = obj->Depth() - objComponent->Depth(),
338 aFTag = objFather->Tag(),
363 res = SUBMESH_VERTEX;
375 res = SUBMESH_COMPOUND;
387 //=======================================================================
388 //function : typeName
390 //=======================================================================
392 QString SMESHGUI_Selection::typeName( const int t )
405 return "Mesh or submesh";
407 return "Mesh vertex";
414 case SUBMESH_COMPOUND:
415 return "Mesh compound";