1 // SMESH SMESHGUI_Selection
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_Selection.cxx
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
27 #include "SMESHGUI_Selection.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
33 #include <SMESH_Type.h>
34 #include <SMESH_Actor.h>
36 // SALOME GUI includes
37 #include <SalomeApp_Study.h>
38 #include <LightApp_VTKSelector.h>
39 #include <SVTK_ViewWindow.h>
42 #include <SALOMEconfig.h>
43 #include CORBA_CLIENT_HEADER(SMESH_Gen)
44 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
45 #include CORBA_CLIENT_HEADER(SMESH_Group)
47 //=======================================================================
48 //function : SMESHGUI_Selection
50 //=======================================================================
51 SMESHGUI_Selection::SMESHGUI_Selection( const QString& client, LightApp_SelectionMgr* mgr )
52 : LightApp_Selection( client, mgr )
56 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
59 _PTR(Study) aStudy = aSStudy->studyDS();
61 for( int i=0, n=count(); i<n; i++ )
62 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
66 //=======================================================================
67 //function : ~SMESHGUI_Selection
69 //=======================================================================
70 SMESHGUI_Selection::~SMESHGUI_Selection()
74 //=======================================================================
75 //function : processOwner
77 //=======================================================================
78 void SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
80 const LightApp_SVTKDataOwner* owner =
81 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
83 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
88 //=======================================================================
89 //function : parameter
91 //=======================================================================
92 QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
95 if ( p=="client" ) val = QVariant( LightApp_Selection::parameter( p ) );
96 else if ( p=="type" ) val = QVariant( myTypes[ind] );
97 else if ( p=="elemTypes" ) val = QVariant( elemTypes( ind ) );
98 else if ( p=="isAutoColor" ) val = QVariant( isAutoColor( ind ) );
99 else if ( p=="numberOfNodes" ) val = QVariant( numberOfNodes( ind ) );
100 else if ( p=="labeledTypes" ) val = QVariant( labeledTypes( ind ) );
101 else if ( p=="shrinkMode" ) val = QVariant( shrinkMode( ind ) );
102 else if ( p=="entityMode" ) val = QVariant( entityMode( ind ) );
103 else if ( p=="controlMode" ) val = QVariant( controlMode( ind ) );
104 else if ( p=="displayMode" ) val = QVariant( displayMode( ind ) );
105 else if ( p=="isComputable" ) val = QVariant( isComputable( ind ) );
106 else if ( p=="hasReference" ) val = QVariant( hasReference( ind ) );
111 return LightApp_Selection::parameter( ind, p );
114 //=======================================================================
115 //function : getVtkOwner
117 //=======================================================================
119 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
121 if( ind >= 0 && ind < count() )
122 return myActors.at( ind );
127 //=======================================================================
128 //function : elemTypes
129 //purpose : may return {'Edge' 'Face' 'Volume'} at most
130 //=======================================================================
132 QList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
134 QList<QVariant> types;
135 SMESH_Actor* actor = getActor( ind );
137 TVisualObjPtr object = actor->GetObject();
139 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
140 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
141 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
147 //=======================================================================
148 //function : labeledTypes
149 //purpose : may return {'Point' 'Cell'} at most
150 //=======================================================================
152 QList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
154 QList<QVariant> types;
155 SMESH_Actor* actor = getActor( ind );
157 if ( actor->GetPointsLabeled()) types.append( "Point" );
158 if ( actor->GetCellsLabeled()) types.append( "Cell" );
163 //=======================================================================
164 //function : displayMode
165 //purpose : return SMESH_Actor::EReperesent
166 //=======================================================================
168 QString SMESHGUI_Selection::displayMode( int ind ) const
170 SMESH_Actor* actor = getActor( ind );
172 switch( actor->GetRepresentation() ) {
173 case SMESH_Actor::eEdge: return "eEdge";
174 case SMESH_Actor::eSurface: return "eSurface";
175 case SMESH_Actor::ePoint: return "ePoint";
182 //=======================================================================
183 //function : shrinkMode
184 //purpose : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
185 //=======================================================================
187 QString SMESHGUI_Selection::shrinkMode( int ind ) const
189 SMESH_Actor* actor = getActor( ind );
190 if ( actor && actor->IsShrunkable() ) {
191 if ( actor->IsShrunk() )
193 return "IsNotShrunk";
195 return "IsNotShrinkable";
198 //=======================================================================
199 //function : entityMode
200 //purpose : may return {'Edge' 'Face' 'Volume'} at most
201 //=======================================================================
203 QList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
205 QList<QVariant> types;
206 SMESH_Actor* actor = getActor( ind );
208 unsigned int aMode = actor->GetEntityMode();
209 if ( aMode & SMESH_Actor::eVolumes) types.append( "Volume");
210 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
211 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
216 //=======================================================================
217 //function : controlMode
218 //purpose : return SMESH_Actor::eControl
219 //=======================================================================
221 QString SMESHGUI_Selection::controlMode( int ind ) const
223 SMESH_Actor* actor = getActor( ind );
225 switch( actor->GetControlMode() ) {
226 case SMESH_Actor::eLength: return "eLength";
227 case SMESH_Actor::eLength2D: return "eLength2D";
228 case SMESH_Actor::eFreeEdges: return "eFreeEdges";
229 case SMESH_Actor::eFreeBorders: return "eFreeBorders";
230 case SMESH_Actor::eMultiConnection: return "eMultiConnection";
231 case SMESH_Actor::eMultiConnection2D: return "eMultiConnection2D";
232 case SMESH_Actor::eArea: return "eArea";
233 case SMESH_Actor::eVolume3D: return "eVolume3D";
234 case SMESH_Actor::eTaper: return "eTaper";
235 case SMESH_Actor::eAspectRatio: return "eAspectRatio";
236 case SMESH_Actor::eAspectRatio3D: return "eAspectRatio3D";
237 case SMESH_Actor::eMinimumAngle: return "eMinimumAngle";
238 case SMESH_Actor::eWarping: return "eWarping";
239 case SMESH_Actor::eSkew: return "eSkew";
246 //=======================================================================
247 //function : isAutoColor
249 //=======================================================================
251 bool SMESHGUI_Selection::isAutoColor( int ind ) const
253 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
255 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
256 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
258 if ( ! CORBA::is_nil( obj )) {
259 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
260 if ( ! mesh->_is_nil() )
261 return mesh->GetAutoColor();
267 //=======================================================================
268 //function : numberOfNodes
270 //=======================================================================
272 int SMESHGUI_Selection::numberOfNodes( int ind ) const
274 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
276 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
277 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
279 if ( ! CORBA::is_nil( obj )) {
280 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
281 if ( ! mesh->_is_nil() )
282 return mesh->NbNodes();
283 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
284 if ( !aSubMeshObj->_is_nil() )
285 return aSubMeshObj->GetNumberOfNodes(true);
286 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
287 if ( !aGroupObj->_is_nil() )
288 return aGroupObj->Size();
294 //=======================================================================
295 //function : isComputable
297 //=======================================================================
299 QVariant SMESHGUI_Selection::isComputable( int ind ) const
301 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
303 /* Handle(SALOME_InteractiveObject) io =
304 static_cast<LightApp_DataOwner*>( myDataOwners[ ind ].get() )->IO();
305 if ( !io.IsNull() ) {
306 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io); // m,sm,gr->m
307 if ( !mesh->_is_nil() ) {*/
308 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
309 //FindSObject( mesh );
311 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
312 if(!CORBA::is_nil(obj)){
313 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
314 if (!mesh->_is_nil()){
315 if(mesh->HasShapeToMesh()) {
316 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
317 return QVariant( !shape->_is_nil() );
321 return QVariant(!mesh->NbFaces()==0);
326 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
327 return QVariant( !shape->_is_nil() );
334 return QVariant( false );
337 //=======================================================================
338 //function : hasReference
340 //=======================================================================
342 QVariant SMESHGUI_Selection::hasReference( int ind ) const
344 return QVariant( isReference( ind ) );
347 //=======================================================================
348 //function : isVisible
350 //=======================================================================
352 QVariant SMESHGUI_Selection::isVisible( int ind ) const
354 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
356 QString ent = entry( ind );
357 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.toLatin1().data() );
358 if ( actor && actor->hasIO() ) {
359 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
360 return QVariant( aViewWindow->isVisible( actor->getIO() ) );
363 return QVariant( false );
366 //=======================================================================
369 //=======================================================================
371 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
373 _PTR(SObject) obj (study->FindObjectID(entry.toLatin1().data()));
378 if( obj->ReferencedObject( ref ) )
381 _PTR(SObject) objFather = obj->GetFather();
382 _PTR(SComponent) objComponent = obj->GetFatherComponent();
384 if( objComponent->ComponentDataType()!="SMESH" )
387 if( objComponent->GetIOR()==obj->GetIOR() )
390 int aLevel = obj->Depth() - objComponent->Depth(),
391 aFTag = objFather->Tag(),
398 if (anOTag >= SMESH::Tag_FirstMeshRoot)
404 case SMESH::Tag_HypothesisRoot:
407 case SMESH::Tag_AlgorithmsRoot:
415 case SMESH::Tag_SubMeshOnVertex:
416 res = SUBMESH_VERTEX;
418 case SMESH::Tag_SubMeshOnEdge:
421 case SMESH::Tag_SubMeshOnFace:
424 case SMESH::Tag_SubMeshOnSolid:
427 case SMESH::Tag_SubMeshOnCompound:
428 res = SUBMESH_COMPOUND;
431 if (aFTag >= SMESH::Tag_FirstGroup)
442 //=======================================================================
443 //function : typeName
445 //=======================================================================
447 QString SMESHGUI_Selection::typeName( const int t )
460 return "Mesh or submesh";
462 return "Mesh vertex";
469 case SUBMESH_COMPOUND:
470 return "Mesh compound";