1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "SMESHGUI_Selection.h"
22 #include "SMESHGUI_Utils.h"
23 #include "SMESHGUI_VTKUtils.h"
24 #include "SMESHGUI_MeshUtils.h"
25 #include "SMESHGUI_GEOMGenUtils.h"
27 #include "SMESH_Type.h"
28 #include "SMESH_Actor.h"
30 #include "LightApp_SelectionMgr.h"
31 #include "SalomeApp_Study.h"
32 #include "LightApp_VTKSelector.h"
34 #include "SUIT_Session.h"
36 #include "SVTK_RenderWindowInteractor.h"
37 #include "SVTK_ViewWindow.h"
39 #include CORBA_SERVER_HEADER(SMESH_Mesh)
40 #include CORBA_SERVER_HEADER(SMESH_Group)
42 //=======================================================================
43 //function : SMESHGUI_Selection
45 //=======================================================================
46 SMESHGUI_Selection::SMESHGUI_Selection()
47 : LightApp_Selection()
51 //=======================================================================
52 //function : ~SMESHGUI_Selection
54 //=======================================================================
55 SMESHGUI_Selection::~SMESHGUI_Selection()
59 //=======================================================================
62 //=======================================================================
63 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
65 LightApp_Selection::init( client, mgr );
69 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
72 _PTR(Study) aStudy = aSStudy->studyDS();
74 for( int i=0, n=count(); i<n; i++ )
75 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
79 //=======================================================================
80 //function : processOwner
82 //=======================================================================
83 void SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
85 const LightApp_SVTKDataOwner* owner =
86 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
88 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
93 //=======================================================================
96 //=======================================================================
97 QtxValue SMESHGUI_Selection::param( const int ind, const QString& p ) const
100 if ( p=="client" ) val = QtxValue( globalParam( p ) );
101 else if ( p=="type" ) val = QtxValue( myTypes[ind] );
102 else if ( p=="elemTypes" ) val = QtxValue( elemTypes( ind ) );
103 else if ( p=="isAutoColor" ) val = QtxValue( isAutoColor( ind ) );
104 else if ( p=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
105 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
106 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
107 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
108 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
109 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
110 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
111 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
112 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
114 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
115 //if ( val.type() == QVariant::List )
116 //cout << "size: " << val.toList().count() << endl;
121 return LightApp_Selection::param( ind, p );
124 //=======================================================================
125 //function : getVtkOwner
127 //=======================================================================
129 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
131 if( ind >= 0 && ind < count() )
132 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
137 //=======================================================================
138 //function : elemTypes
139 //purpose : may return {'Edge' 'Face' 'Volume'} at most
140 //=======================================================================
142 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
144 QValueList<QVariant> types;
145 SMESH_Actor* actor = getActor( ind );
147 TVisualObjPtr object = actor->GetObject();
149 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
150 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
151 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
157 //=======================================================================
158 //function : labeledTypes
159 //purpose : may return {'Point' 'Cell'} at most
160 //=======================================================================
162 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
164 QValueList<QVariant> types;
165 SMESH_Actor* actor = getActor( ind );
167 if ( actor->GetPointsLabeled()) types.append( "Point" );
168 if ( actor->GetCellsLabeled()) types.append( "Cell" );
173 //=======================================================================
174 //function : displayMode
175 //purpose : return SMESH_Actor::EReperesent
176 //=======================================================================
178 QString SMESHGUI_Selection::displayMode( int ind ) const
180 SMESH_Actor* actor = getActor( ind );
182 switch( actor->GetRepresentation() ) {
183 case SMESH_Actor::eEdge: return "eEdge";
184 case SMESH_Actor::eSurface: return "eSurface";
185 case SMESH_Actor::ePoint: return "ePoint";
192 //=======================================================================
193 //function : shrinkMode
194 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
195 //=======================================================================
197 QString SMESHGUI_Selection::shrinkMode( int ind ) const
199 SMESH_Actor* actor = getActor( ind );
200 if ( actor && actor->IsShrunkable() ) {
201 if ( actor->IsShrunk() )
203 return "IsNotShrunk";
205 return "IsNotShrinkable";
208 //=======================================================================
209 //function : entityMode
210 //purpose : may return {'Edge' 'Face' 'Volume'} at most
211 //=======================================================================
213 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
215 QValueList<QVariant> types;
216 SMESH_Actor* actor = getActor( ind );
218 unsigned int aMode = actor->GetEntityMode();
219 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
220 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
221 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
226 //=======================================================================
227 //function : controlMode
228 //purpose : return SMESH_Actor::eControl
229 //=======================================================================
231 QString SMESHGUI_Selection::controlMode( int ind ) const
233 SMESH_Actor* actor = getActor( ind );
235 switch( actor->GetControlMode() ) {
236 case SMESH_Actor::eLength: return "eLength";
237 case SMESH_Actor::eLength2D: return "eLength2D";
238 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
239 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
240 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
241 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
242 case SMESH_Actor::eArea: return "eArea";
243 case SMESH_Actor::eVolume3D: return "eVolume3D";
244 case SMESH_Actor::eTaper: return "eTaper";
245 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
246 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
247 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
248 case SMESH_Actor::eWarping: return "eWarping";
249 case SMESH_Actor::eSkew: return "eSkew";
256 //=======================================================================
257 //function : isAutoColor
259 //=======================================================================
261 bool SMESHGUI_Selection::isAutoColor( int ind ) const
263 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
265 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
266 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
268 if ( ! CORBA::is_nil( obj )) {
269 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
270 if ( ! mesh->_is_nil() )
271 return mesh->GetAutoColor();
277 //=======================================================================
278 //function : numberOfNodes
280 //=======================================================================
282 int SMESHGUI_Selection::numberOfNodes( int ind ) const
284 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
286 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
287 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
289 if ( ! CORBA::is_nil( obj )) {
290 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
291 if ( ! mesh->_is_nil() )
292 return mesh->NbNodes();
293 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
294 if ( !aSubMeshObj->_is_nil() )
295 return aSubMeshObj->GetNumberOfNodes(true);
296 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
297 if ( !aGroupObj->_is_nil() )
298 return aGroupObj->Size();
304 //=======================================================================
305 //function : isComputable
307 //=======================================================================
309 QVariant SMESHGUI_Selection::isComputable( int ind ) const
311 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
313 /* Handle(SALOME_InteractiveObject) io =
314 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
315 if ( !io.IsNull() ) {
316 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
317 if ( !mesh->_is_nil() ) {*/
318 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
319 //FindSObject( mesh );
321 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
322 if(!CORBA::is_nil(obj)){
323 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
324 if (!mesh->_is_nil()){
325 if(mesh->HasShapeToMesh()) {
326 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
327 return QVariant( !shape->_is_nil(), 0 );
331 return QVariant(!mesh->NbFaces()==0, 0);
336 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
337 return QVariant( !shape->_is_nil(), 0 );
344 return QVariant( false, 0 );
347 //=======================================================================
348 //function : hasReference
350 //=======================================================================
352 QVariant SMESHGUI_Selection::hasReference( int ind ) const
354 return QVariant( isReference( ind ), 0 );
357 //=======================================================================
358 //function : isVisible
360 //=======================================================================
362 QVariant SMESHGUI_Selection::isVisible( int ind ) const
364 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
366 QString ent = entry( ind );
367 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
368 if ( actor && actor->hasIO() ) {
369 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
370 return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 );
373 return QVariant( false, 0 );
376 //=======================================================================
379 //=======================================================================
381 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
383 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
388 if( obj->ReferencedObject( ref ) )
391 _PTR(SObject) objFather = obj->GetFather();
392 _PTR(SComponent) objComponent = obj->GetFatherComponent();
394 if( objComponent->ComponentDataType()!="SMESH" )
397 if( objComponent->GetIOR()==obj->GetIOR() )
400 int aLevel = obj->Depth() - objComponent->Depth(),
401 aFTag = objFather->Tag(),
426 res = SUBMESH_VERTEX;
438 res = SUBMESH_COMPOUND;
452 //=======================================================================
453 //function : typeName
455 //=======================================================================
457 QString SMESHGUI_Selection::typeName( const int t )
470 return "Mesh or submesh";
472 return "Mesh vertex";
479 case SUBMESH_COMPOUND:
480 return "Mesh compound";