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/
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=="numberOfNodes" ) val = QtxValue( numberOfNodes( ind ) );
104 else if ( p=="labeledTypes" ) val = QtxValue( labeledTypes( ind ) );
105 else if ( p=="shrinkMode" ) val = QtxValue( shrinkMode( ind ) );
106 else if ( p=="entityMode" ) val = QtxValue( entityMode( ind ) );
107 else if ( p=="controlMode" ) val = QtxValue( controlMode( ind ) );
108 else if ( p=="displayMode" ) val = QtxValue( displayMode( ind ) );
109 else if ( p=="isComputable" ) val = QtxValue( isComputable( ind ) );
110 else if ( p=="hasReference" ) val = QtxValue( hasReference( ind ) );
111 // else if ( p=="isVisible" ) val = QtxValue( isVisible( ind ) );
113 // printf( "--> param() : [%s] = %s (%s)\n", p.latin1(), val.toString().latin1(), val.typeName() );
114 //if ( val.type() == QVariant::List )
115 //cout << "size: " << val.toList().count() << endl;
120 return LightApp_Selection::param( ind, p );
123 //=======================================================================
124 //function : getVtkOwner
126 //=======================================================================
128 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
130 if( ind >= 0 && ind < count() )
131 return ((QPtrList<SMESH_Actor>&)myActors).at( ind );
136 //=======================================================================
137 //function : elemTypes
138 //purpose : may return {'Edge' 'Face' 'Volume'} at most
139 //=======================================================================
141 QValueList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
143 QValueList<QVariant> types;
144 SMESH_Actor* actor = getActor( ind );
146 TVisualObjPtr object = actor->GetObject();
148 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
149 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
150 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
156 //=======================================================================
157 //function : labeledTypes
158 //purpose : may return {'Point' 'Cell'} at most
159 //=======================================================================
161 QValueList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
163 QValueList<QVariant> types;
164 SMESH_Actor* actor = getActor( ind );
166 if ( actor->GetPointsLabeled()) types.append( "Point" );
167 if ( actor->GetCellsLabeled()) types.append( "Cell" );
172 //=======================================================================
173 //function : displayMode
174 //purpose : return SMESH_Actor::EReperesent
175 //=======================================================================
177 QString SMESHGUI_Selection::displayMode( int ind ) const
179 SMESH_Actor* actor = getActor( ind );
181 switch( actor->GetRepresentation() ) {
182 case SMESH_Actor::eEdge: return "eEdge";
183 case SMESH_Actor::eSurface: return "eSurface";
184 case SMESH_Actor::ePoint: return "ePoint";
191 //=======================================================================
192 //function : shrinkMode
193 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
194 //=======================================================================
196 QString SMESHGUI_Selection::shrinkMode( int ind ) const
198 SMESH_Actor* actor = getActor( ind );
199 if ( actor && actor->IsShrunkable() ) {
200 if ( actor->IsShrunk() )
202 return "IsNotShrunk";
204 return "IsNotShrinkable";
207 //=======================================================================
208 //function : entityMode
209 //purpose : may return {'Edge' 'Face' 'Volume'} at most
210 //=======================================================================
212 QValueList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
214 QValueList<QVariant> types;
215 SMESH_Actor* actor = getActor( ind );
217 unsigned int aMode = actor->GetEntityMode();
218 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
219 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
220 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
225 //=======================================================================
226 //function : controlMode
227 //purpose : return SMESH_Actor::eControl
228 //=======================================================================
230 QString SMESHGUI_Selection::controlMode( int ind ) const
232 SMESH_Actor* actor = getActor( ind );
234 switch( actor->GetControlMode() ) {
235 case SMESH_Actor::eLength: return "eLength";
236 case SMESH_Actor::eLength2D: return "eLength2D";
237 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
238 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
239 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
240 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
241 case SMESH_Actor::eArea: return "eArea";
242 case SMESH_Actor::eVolume3D: return "eVolume3D";
243 case SMESH_Actor::eTaper: return "eTaper";
244 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
245 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
246 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
247 case SMESH_Actor::eWarping: return "eWarping";
248 case SMESH_Actor::eSkew: return "eSkew";
255 //=======================================================================
256 //function : numberOfNodes
258 //=======================================================================
260 int SMESHGUI_Selection::numberOfNodes( int ind ) const
262 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
264 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
265 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
267 if ( ! CORBA::is_nil( obj )) {
268 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
269 if ( ! mesh->_is_nil() )
270 return mesh->NbNodes();
271 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
272 if ( !aSubMeshObj->_is_nil() )
273 return aSubMeshObj->GetNumberOfNodes(true);
274 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
275 if ( !aGroupObj->_is_nil() )
276 return aGroupObj->Size();
282 //=======================================================================
283 //function : isComputable
285 //=======================================================================
287 QVariant SMESHGUI_Selection::isComputable( int ind ) const
289 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
291 /* Handle(SALOME_InteractiveObject) io =
292 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
293 if ( !io.IsNull() ) {
294 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io) ; // m,sm,gr->m
295 if ( !mesh->_is_nil() ) {*/
296 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).latin1() );
297 //FindSObject( mesh );
299 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
300 return QVariant( !shape->_is_nil(), 0 );
305 return QVariant( false, 0 );
308 //=======================================================================
309 //function : hasReference
311 //=======================================================================
313 QVariant SMESHGUI_Selection::hasReference( int ind ) const
315 return QVariant( isReference( ind ), 0 );
318 //=======================================================================
319 //function : isVisible
321 //=======================================================================
323 QVariant SMESHGUI_Selection::isVisible( int ind ) const
325 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
327 QString ent = entry( ind );
328 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() );
329 if ( actor && actor->hasIO() ) {
330 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
331 return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 );
334 return QVariant( false, 0 );
337 //=======================================================================
340 //=======================================================================
342 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
344 _PTR(SObject) obj (study->FindObjectID(entry.latin1()));
349 if( obj->ReferencedObject( ref ) )
352 _PTR(SObject) objFather = obj->GetFather();
353 _PTR(SComponent) objComponent = obj->GetFatherComponent();
355 if( objComponent->ComponentDataType()!="SMESH" )
358 if( objComponent->GetIOR()==obj->GetIOR() )
361 int aLevel = obj->Depth() - objComponent->Depth(),
362 aFTag = objFather->Tag(),
387 res = SUBMESH_VERTEX;
399 res = SUBMESH_COMPOUND;
413 //=======================================================================
414 //function : typeName
416 //=======================================================================
418 QString SMESHGUI_Selection::typeName( const int t )
431 return "Mesh or submesh";
433 return "Mesh vertex";
440 case SUBMESH_COMPOUND:
441 return "Mesh compound";