Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_Selection.h"
00029
00030 #include "SMESHGUI_Utils.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 #include "SMESHGUI_GEOMGenUtils.h"
00033 #include "SMESHGUI_ComputeDlg.h"
00034
00035 #include <SMESH_Type.h>
00036 #include <SMESH_Actor.h>
00037 #include <SMESH_ScalarBarActor.h>
00038
00039
00040 #include <SalomeApp_Study.h>
00041 #include <LightApp_VTKSelector.h>
00042 #include <SVTK_ViewWindow.h>
00043
00044
00045 #include <SALOMEconfig.h>
00046 #include CORBA_CLIENT_HEADER(SMESH_Gen)
00047 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
00048 #include CORBA_CLIENT_HEADER(SMESH_Group)
00049
00050
00051
00052
00053
00054 SMESHGUI_Selection::SMESHGUI_Selection()
00055 : LightApp_Selection()
00056 {
00057 }
00058
00059
00060
00061
00062
00063 SMESHGUI_Selection::~SMESHGUI_Selection()
00064 {
00065 }
00066
00067
00068
00069
00070
00071 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
00072 {
00073 LightApp_Selection::init( client, mgr );
00074
00075 if( mgr && study() )
00076 {
00077 SalomeApp_Study* aSStudy = dynamic_cast<SalomeApp_Study*>(study());
00078 if (!aSStudy)
00079 return;
00080 _PTR(Study) aStudy = aSStudy->studyDS();
00081
00082 for( int i=0, n=count(); i<n; i++ )
00083 myTypes.append( typeName( type( entry( i ), aStudy ) ) );
00084 }
00085 }
00086
00087
00088
00089
00090
00091 bool SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
00092 {
00093 const LightApp_SVTKDataOwner* owner =
00094 dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
00095 if( owner )
00096 myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
00097 else
00098 myActors.append( 0 );
00099 return true;
00100 }
00101
00102
00103
00104
00105
00106 QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
00107 {
00108 QVariant val;
00109 if ( p=="client" ) val = QVariant( LightApp_Selection::parameter( p ) );
00110 else if ( p=="type" ) val = QVariant( myTypes[ind] );
00111 else if ( p=="elemTypes" ) val = QVariant( elemTypes( ind ) );
00112 else if ( p=="isAutoColor" ) val = QVariant( isAutoColor( ind ) );
00113 else if ( p=="numberOfNodes" ) val = QVariant( numberOfNodes( ind ) );
00114 else if ( p=="dim" ) val = QVariant( dim( ind ) );
00115 else if ( p=="labeledTypes" ) val = QVariant( labeledTypes( ind ) );
00116 else if ( p=="shrinkMode" ) val = QVariant( shrinkMode( ind ) );
00117 else if ( p=="entityMode" ) val = QVariant( entityMode( ind ) );
00118 else if ( p=="controlMode" ) val = QVariant( controlMode( ind ) );
00119 else if ( p=="isNumFunctor" ) val = QVariant( isNumFunctor( ind ) );
00120 else if ( p=="displayMode" ) val = QVariant( displayMode( ind ) );
00121 else if ( p=="isComputable" ) val = QVariant( isComputable( ind ) );
00122 else if ( p=="isPreComputable" ) val = QVariant( isPreComputable( ind ) );
00123 else if ( p=="hasReference" ) val = QVariant( hasReference( ind ) );
00124 else if ( p=="isImported" ) val = QVariant( isImported( ind ) );
00125 else if ( p=="facesOrientationMode" ) val = QVariant( facesOrientationMode( ind ) );
00126 else if ( p=="groupType" ) val = QVariant( groupType( ind ) );
00127 else if ( p=="quadratic2DMode") val = QVariant(quadratic2DMode(ind));
00128 else if ( p=="isDistributionVisible") val = QVariant(isDistributionVisible(ind));
00129
00130 if( val.isValid() )
00131 return val;
00132 else
00133 return LightApp_Selection::parameter( ind, p );
00134 }
00135
00136
00137
00138
00139
00140
00141 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
00142 {
00143 if( ind >= 0 && ind < count() )
00144 return myActors.isEmpty() ? 0 : myActors.at( ind );
00145 else
00146 return 0;
00147 }
00148
00149
00150
00151
00152
00153
00154 QList<QVariant> SMESHGUI_Selection::elemTypes( int ind ) const
00155 {
00156 QList<QVariant> types;
00157 SMESH_Actor* actor = getActor( ind );
00158 if ( actor ) {
00159 TVisualObjPtr object = actor->GetObject();
00160 if ( object ) {
00161 if ( object->GetNbEntities( SMDSAbs_0DElement )) types.append( "Elem0d" );
00162 if ( object->GetNbEntities( SMDSAbs_Edge )) types.append( "Edge" );
00163 if ( object->GetNbEntities( SMDSAbs_Face )) types.append( "Face" );
00164 if ( object->GetNbEntities( SMDSAbs_Volume )) types.append( "Volume" );
00165 }
00166 }
00167 return types;
00168 }
00169
00170
00171
00172
00173
00174
00175 QList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
00176 {
00177 QList<QVariant> types;
00178 SMESH_Actor* actor = getActor( ind );
00179 if ( actor ) {
00180 if ( actor->GetPointsLabeled()) types.append( "Point" );
00181 if ( actor->GetCellsLabeled()) types.append( "Cell" );
00182 }
00183 return types;
00184 }
00185
00186
00187
00188
00189
00190
00191 QString SMESHGUI_Selection::displayMode( int ind ) const
00192 {
00193 SMESH_Actor* actor = getActor( ind );
00194 if ( actor ) {
00195 switch( actor->GetRepresentation() ) {
00196 case SMESH_Actor::eEdge: return "eEdge";
00197 case SMESH_Actor::eSurface: return "eSurface";
00198 case SMESH_Actor::ePoint: return "ePoint";
00199 default: break;
00200 }
00201 }
00202 return "Unknown";
00203 }
00204
00205
00206
00207
00208
00209
00210 QString SMESHGUI_Selection::quadratic2DMode( int ind ) const
00211 {
00212 SMESH_Actor* actor = getActor( ind );
00213 if ( actor ) {
00214 switch( actor->GetQuadratic2DRepresentation() ) {
00215 case SMESH_Actor::eLines: return "eLines";
00216 case SMESH_Actor::eArcs: return "eArcs";
00217 default: break;
00218 }
00219 }
00220 return "Unknown";
00221 }
00222
00223
00224
00225
00226
00227
00228 bool SMESHGUI_Selection::isDistributionVisible(int ind) const {
00229 SMESH_Actor* actor = getActor( ind );
00230 return (actor && actor->GetScalarBarActor() && actor->GetScalarBarActor()->GetDistributionVisibility());
00231 }
00232
00233
00234
00235
00236
00237
00238 QString SMESHGUI_Selection::shrinkMode( int ind ) const
00239 {
00240 SMESH_Actor* actor = getActor( ind );
00241 if ( actor && actor->IsShrunkable() ) {
00242 if ( actor->IsShrunk() )
00243 return "IsShrunk";
00244 return "IsNotShrunk";
00245 }
00246 return "IsNotShrinkable";
00247 }
00248
00249
00250
00251
00252
00253
00254 QList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
00255 {
00256 QList<QVariant> types;
00257 SMESH_Actor* actor = getActor( ind );
00258 if ( actor ) {
00259 unsigned int aMode = actor->GetEntityMode();
00260 if ( aMode & SMESH_Actor::eVolumes ) types.append( "Volume" );
00261 if ( aMode & SMESH_Actor::eFaces ) types.append( "Face" );
00262 if ( aMode & SMESH_Actor::eEdges ) types.append( "Edge" );
00263 if ( aMode & SMESH_Actor::e0DElements ) types.append( "Elem0d" );
00264 }
00265 return types;
00266 }
00267
00268
00269
00270
00271
00272
00273 QString SMESHGUI_Selection::controlMode( int ind ) const
00274 {
00275 SMESH_Actor* actor = getActor( ind );
00276 QString mode = "eNone";
00277 if ( actor ) {
00278 switch( actor->GetControlMode() ) {
00279 case SMESH_Actor::eLength: mode = "eLength"; break;
00280 case SMESH_Actor::eLength2D: mode = "eLength2D"; break;
00281 case SMESH_Actor::eFreeEdges: mode = "eFreeEdges"; break;
00282 case SMESH_Actor::eFreeNodes: mode = "eFreeNodes"; break;
00283 case SMESH_Actor::eFreeBorders: mode = "eFreeBorders"; break;
00284 case SMESH_Actor::eFreeFaces: mode = "eFreeFaces"; break;
00285 case SMESH_Actor::eMultiConnection: mode = "eMultiConnection"; break;
00286 case SMESH_Actor::eMultiConnection2D: mode = "eMultiConnection2D"; break;
00287 case SMESH_Actor::eArea: mode = "eArea"; break;
00288 case SMESH_Actor::eVolume3D: mode = "eVolume3D"; break;
00289 case SMESH_Actor::eMaxElementLength2D: mode = "eMaxElementLength2D"; break;
00290 case SMESH_Actor::eMaxElementLength3D: mode = "eMaxElementLength3D"; break;
00291 case SMESH_Actor::eTaper: mode = "eTaper"; break;
00292 case SMESH_Actor::eAspectRatio: mode = "eAspectRatio"; break;
00293 case SMESH_Actor::eAspectRatio3D: mode = "eAspectRatio3D"; break;
00294 case SMESH_Actor::eMinimumAngle: mode = "eMinimumAngle"; break;
00295 case SMESH_Actor::eWarping: mode = "eWarping"; break;
00296 case SMESH_Actor::eSkew: mode = "eSkew"; break;
00297 case SMESH_Actor::eBareBorderFace: mode = "eBareBorderFace"; break;
00298 case SMESH_Actor::eBareBorderVolume: mode = "eBareBorderVolume"; break;
00299 case SMESH_Actor::eOverConstrainedFace: mode = "eOverConstrainedFace"; break;
00300 case SMESH_Actor::eOverConstrainedVolume: mode = "eOverConstrainedVolume"; break;
00301 default:break;
00302 }
00303 }
00304 return mode;
00305 }
00306
00307 bool SMESHGUI_Selection::isNumFunctor( int ind ) const
00308 {
00309 bool result = false;
00310 SMESH_Actor* actor = getActor( ind );
00311 if ( actor ) {
00312 switch( actor->GetControlMode() ) {
00313 case SMESH_Actor::eLength:
00314 case SMESH_Actor::eLength2D:
00315 case SMESH_Actor::eMultiConnection:
00316 case SMESH_Actor::eMultiConnection2D:
00317 case SMESH_Actor::eArea:
00318 case SMESH_Actor::eVolume3D:
00319 case SMESH_Actor::eMaxElementLength2D:
00320 case SMESH_Actor::eMaxElementLength3D:
00321 case SMESH_Actor::eTaper:
00322 case SMESH_Actor::eAspectRatio:
00323 case SMESH_Actor::eAspectRatio3D:
00324 case SMESH_Actor::eMinimumAngle:
00325 case SMESH_Actor::eWarping:
00326 case SMESH_Actor::eSkew:
00327 result = true;
00328 break;
00329 default:
00330 break;
00331 }
00332 }
00333 return result;
00334 }
00335
00336
00337
00338
00339
00340
00341 QString SMESHGUI_Selection::facesOrientationMode( int ind ) const
00342 {
00343 SMESH_Actor* actor = getActor( ind );
00344 if ( actor ) {
00345 if ( actor->GetFacesOriented() )
00346 return "IsOriented";
00347 return "IsNotOriented";
00348 }
00349 return "Unknown";
00350 }
00351
00352
00353
00354
00355
00356
00357 bool SMESHGUI_Selection::isAutoColor( int ind ) const
00358 {
00359 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00360 {
00361 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
00362 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
00363
00364 if ( ! CORBA::is_nil( obj )) {
00365 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
00366 if ( ! mesh->_is_nil() )
00367 return mesh->GetAutoColor();
00368 }
00369 }
00370 return false;
00371 }
00372
00373
00374
00375
00376
00377
00378 int SMESHGUI_Selection::numberOfNodes( int ind ) const
00379 {
00380 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00381 {
00382 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
00383 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
00384
00385 if ( ! CORBA::is_nil( obj )) {
00386 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
00387 if ( ! mesh->_is_nil() )
00388 return mesh->NbNodes();
00389 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
00390 if ( !aSubMeshObj->_is_nil() )
00391 return aSubMeshObj->GetNumberOfNodes(true);
00392 SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
00393 if ( !aGroupObj->_is_nil() )
00394 return aGroupObj->Size();
00395 }
00396 }
00397 return 0;
00398 }
00399
00400
00406
00407
00408 int SMESHGUI_Selection::dim( int ind ) const
00409 {
00410 int dim = -1;
00411 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00412 {
00413 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
00414 CORBA::Object_var obj = SMESH::SObjectToObject( sobj, SMESH::GetActiveStudyDocument() );
00415
00416 if ( ! CORBA::is_nil( obj )) {
00417 SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
00418 if ( ! idSrc->_is_nil() )
00419 {
00420 SMESH::array_of_ElementType_var types = idSrc->GetTypes();
00421 for ( int i = 0; i < types->length(); ++ i)
00422 switch ( types[i] ) {
00423 case SMESH::EDGE : dim = std::max( dim, 1 ); break;
00424 case SMESH::FACE : dim = std::max( dim, 2 ); break;
00425 case SMESH::VOLUME: dim = std::max( dim, 3 ); break;
00426 case SMESH::ELEM0D: dim = std::max( dim, 0 ); break;
00427 default:;
00428 }
00429 }
00430 }
00431 }
00432 return dim;
00433 }
00434
00435
00436
00437
00438
00439
00440 QVariant SMESHGUI_Selection::isComputable( int ind ) const
00441 {
00442 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00443 {
00444
00445
00446
00447
00448
00449 _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
00450
00451 if ( so ) {
00452 CORBA::Object_var obj = SMESH::SObjectToObject(so, SMESH::GetActiveStudyDocument());
00453 if(!CORBA::is_nil(obj)){
00454 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
00455 if (!mesh->_is_nil()){
00456 if(mesh->HasShapeToMesh()) {
00457 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
00458 return QVariant( !shape->_is_nil() );
00459 }
00460 else
00461 {
00462 return QVariant(!mesh->NbFaces()==0);
00463 }
00464 }
00465 else
00466 {
00467 GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
00468 return QVariant( !shape->_is_nil() );
00469 }
00470 }
00471 }
00472
00473
00474 }
00475 return QVariant( false );
00476 }
00477
00478
00479
00480
00481
00482
00483 QVariant SMESHGUI_Selection::isPreComputable( int ind ) const
00484 {
00485 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00486 {
00487 QMap<int,int> modeMap;
00488 _PTR(SObject) pMesh = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
00489 SMESHGUI_PrecomputeOp::getAssignedAlgos( pMesh, modeMap );
00490 return QVariant( modeMap.size() > 1 );
00491 }
00492 return QVariant( false );
00493 }
00494
00495
00496
00497
00498
00499
00500 QVariant SMESHGUI_Selection::hasReference( int ind ) const
00501 {
00502 return QVariant( isReference( ind ) );
00503 }
00504
00505
00506
00507
00508
00509
00510 QVariant SMESHGUI_Selection::isVisible( int ind ) const
00511 {
00512 if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
00513 {
00514 QString ent = entry( ind );
00515 SMESH_Actor* actor = SMESH::FindActorByEntry( ent.toLatin1().data() );
00516 if ( actor && actor->hasIO() ) {
00517 if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView())
00518 return QVariant( aViewWindow->isVisible( actor->getIO() ) );
00519 }
00520 }
00521 return QVariant( false );
00522 }
00523
00524
00525
00526
00527
00528
00529 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
00530 {
00531 _PTR(SObject) obj (study->FindObjectID(entry.toLatin1().data()));
00532 if( !obj )
00533 return -1;
00534
00535 _PTR(SObject) ref;
00536 if( obj->ReferencedObject( ref ) )
00537 obj = ref;
00538
00539 _PTR(SObject) objFather = obj->GetFather();
00540 _PTR(SComponent) objComponent = obj->GetFatherComponent();
00541
00542 if( objComponent->ComponentDataType()!="SMESH" )
00543 return -1;
00544
00545 if( objComponent->GetIOR()==obj->GetIOR() )
00546 return COMPONENT;
00547
00548 int aLevel = obj->Depth() - objComponent->Depth(),
00549 aFTag = objFather->Tag(),
00550 anOTag = obj->Tag(),
00551 res = -1;
00552
00553 switch (aLevel)
00554 {
00555 case 1:
00556 if (anOTag >= SMESH::Tag_FirstMeshRoot)
00557 res = MESH;
00558 break;
00559 case 2:
00560 switch (aFTag)
00561 {
00562 case SMESH::Tag_HypothesisRoot:
00563 res = HYPOTHESIS;
00564 break;
00565 case SMESH::Tag_AlgorithmsRoot:
00566 res = ALGORITHM;
00567 break;
00568 }
00569 break;
00570 case 3:
00571 switch (aFTag)
00572 {
00573 case SMESH::Tag_SubMeshOnVertex:
00574 res = SUBMESH_VERTEX;
00575 break;
00576 case SMESH::Tag_SubMeshOnEdge:
00577 res = SUBMESH_EDGE;
00578 break;
00579 case SMESH::Tag_SubMeshOnFace:
00580 res = SUBMESH_FACE;
00581 break;
00582 case SMESH::Tag_SubMeshOnSolid:
00583 res = SUBMESH_SOLID;
00584 break;
00585 case SMESH::Tag_SubMeshOnCompound:
00586 res = SUBMESH_COMPOUND;
00587 break;
00588 default:
00589 if (aFTag >= SMESH::Tag_FirstGroup)
00590 res = GROUP;
00591 else
00592 res = SUBMESH;
00593 }
00594 break;
00595 }
00596
00597 return res;
00598 }
00599
00600
00601
00602
00603
00604
00605 QString SMESHGUI_Selection::typeName( const int t )
00606 {
00607 switch( t )
00608 {
00609 case HYPOTHESIS:
00610 return "Hypothesis";
00611 case ALGORITHM:
00612 return "Algorithm";
00613 case MESH:
00614 return "Mesh";
00615 case SUBMESH:
00616 return "SubMesh";
00617 case MESHorSUBMESH:
00618 return "Mesh or submesh";
00619 case SUBMESH_VERTEX:
00620 return "Mesh vertex";
00621 case SUBMESH_EDGE:
00622 return "Mesh edge";
00623 case SUBMESH_FACE:
00624 return "Mesh face";
00625 case SUBMESH_SOLID:
00626 return "Mesh solid";
00627 case SUBMESH_COMPOUND:
00628 return "Mesh compound";
00629 case GROUP:
00630 return "Group";
00631 case COMPONENT:
00632 return "Component";
00633 default:
00634 return "Unknown";
00635 }
00636 }
00637
00638 bool SMESHGUI_Selection::isImported( const int ind ) const
00639 {
00640 QString e = entry( ind );
00641 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e.toLatin1().constData() );
00642 bool res = false;
00643 if( SO )
00644 {
00645 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( SO ) );
00646 if( !aMesh->_is_nil() )
00647 {
00648 SALOME_MED::MedFileInfo* inf = aMesh->GetMEDFileInfo();
00649 res = strlen( (char*)inf->fileName ) > 0;
00650 }
00651 }
00652 return res;
00653 }
00654
00655
00656
00657
00658
00659
00660 QString SMESHGUI_Selection::groupType( int ind ) const
00661 {
00662 QString e = entry( ind );
00663 _PTR(SObject) SO = SMESH::GetActiveStudyDocument()->FindObjectID( e.toLatin1().constData() );
00664 QString type;
00665 if( SO )
00666 {
00667 CORBA::Object_var obj = SMESH::SObjectToObject( SO );
00668
00669 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( obj );
00670 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( obj );
00671 if( !aGroup->_is_nil() )
00672 type = QString( "Group" );
00673 else if ( !aGroupOnGeom->_is_nil() )
00674 type = QString( "GroupOnGeom" );
00675 }
00676 return type;
00677 }