+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when the user selects a way of geometry selection
+ * \param theByMesh - true if the user wants to find geometry by mesh element
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh )
+{
+ if ( theByMesh ) {
+ if ( !myShapeByMeshOp ) {
+ myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp();
+ connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
+ SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
+ connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
+ SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
+ }
+ // set mesh object to SMESHGUI_ShapeByMeshOp and start it
+ QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+ if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() )) {
+ SMESH::SMESH_Mesh_var aMeshVar =
+ SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
+ if ( !aMeshVar->_is_nil() ) {
+ myDlg->hide(); // stop processing selection
+ myShapeByMeshOp->setModule( getSMESHGUI() );
+ myShapeByMeshOp->setStudy( 0 ); // it's really necessary
+ myShapeByMeshOp->SetMesh( aMeshVar );
+ myShapeByMeshOp->start();
+ }
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
+{
+ if ( myShapeByMeshOp == op ) {
+ SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser(); //MZN: 24.11.2006 IPAL13980 - Object Browser update added
+ myDlg->show();
+ // Select a found geometry object
+ GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
+ if ( !aGeomVar->_is_nil() )
+ {
+ QString ID = aGeomVar->GetStudyEntry();
+ if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
+ selectObject( aGeomSO );
+ selectionDone();
+ }
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onCloseShapeByMeshDlg(SUIT_Operation* op)
+{
+ if ( myShapeByMeshOp == op && myDlg ) {
+ myDlg->show();
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Selects a SObject
+ * \param theSObj - the SObject to select
+ */
+//================================================================================
+void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const
+{
+ if ( LightApp_SelectionMgr* sm = selectionMgr() ) {
+ SALOME_ListIO anIOList;
+ if ( theSObj ) {
+ Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
+ ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() );
+ anIOList.Append( anIO );
+ }
+ sm->setSelectedObjects( anIOList, false );
+ }
+}
+//================================================================================
+/*!
+ * \brief Create available list types of mesh
+ * \param theTypeMesh - Output list of available types of mesh
+ */
+//================================================================================
+void SMESHGUI_MeshOp::createMeshTypeList( QStringList& theTypeMesh)
+{
+ theTypeMesh.clear();
+ theTypeMesh.append( tr( "MT_ANY" ) );
+ if ( myMaxShapeDim >= 2 || myMaxShapeDim == -1 )
+ {
+ theTypeMesh.append( tr( "MT_TRIANGULAR" ) );
+ theTypeMesh.append( tr( "MT_QUADRILATERAL" ) );
+ }
+ if ( myMaxShapeDim == 3 || myMaxShapeDim == -1 )
+ {
+ theTypeMesh.append( tr( "MT_TETRAHEDRAL" ) );
+ theTypeMesh.append( tr( "MT_HEXAHEDRAL" ) );
+ }
+
+}
+//================================================================================
+/*!
+ * \brief Set available types of mesh
+ * \param theTypeMesh - List of available types of mesh
+ */
+//================================================================================
+void SMESHGUI_MeshOp::setAvailableMeshType( const QStringList& theTypeMesh )
+{
+ myDlg->setAvailableMeshType( theTypeMesh );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT. Is called when the user select type of mesh
+ * \param theTabIndex - Index of current active tab
+ * \param theIndex - Index of current type of mesh
+ */
+//================================================================================
+void SMESHGUI_MeshOp::onAlgoSetByMeshType( const int theTabIndex, const int theIndex)
+{
+ setFilteredAlgoData( theTabIndex, theIndex);
+}
+
+//================================================================================
+/*!
+ * \brief Set a filtered list of available algorithms by mesh type
+ * \param theTabIndex - Index of current active tab
+ * \param theIndex - Index of current type of mesh
+ */
+//================================================================================
+void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theIndex)
+{
+ int aDim;
+ THypDataList anAvailableAlgsData;
+ QStringList anAvailableAlgs;
+ QString anCompareType = "";
+ bool isAvailableChoiceAlgo = false;
+ int anCurrentAvailableAlgo = 0;
+ bool isNone = true;
+ switch ( theIndex ) {
+ case MT_ANY:
+ anCompareType = "ANY";
+ aDim = SMESH::DIM_3D;
+ break;
+ case MT_TRIANGULAR:
+ aDim = SMESH::DIM_2D;
+ anCompareType = "TRIA";
+ break;
+ case MT_QUADRILATERAL:
+ aDim = SMESH::DIM_2D;
+ anCompareType = "QUAD";
+ break;
+ case MT_TETRAHEDRAL:
+ aDim = SMESH::DIM_3D;
+ anCompareType = "TETRA";
+ break;
+ case MT_HEXAHEDRAL:
+ aDim = SMESH::DIM_3D;
+ anCompareType = "HEXA";
+ break;
+ default:;
+ }
+
+ bool toCheckIsApplicableToAll = !myIsMesh;
+ GEOM::GEOM_Object_var aGeomVar;
+ QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+ if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
+ {
+ CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
+ aGeomVar = GEOM::GEOM_Object::_narrow( obj );
+ if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
+ toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
+ }
+
+ if ( anCompareType == "ANY" )
+ {
+ for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
+ {
+ isNone = currentHyp( dim, Algo ) < 0;
+ isAvailableChoiceAlgo = false;
+ // retrieves a list of available algorithms from resources
+ availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
+ //return current algo in current tab and set new algorithm list
+ HypothesisData* algoCur;
+ if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
+ algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
+ }
+ myAvailableHypData[dim][Algo].clear();
+ anAvailableAlgs.clear();
+ if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
+ myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
+ !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
+ {
+ for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
+ {
+ HypothesisData* curAlgo = anAvailableAlgsData.at(i);
+ if ( aGeomVar->_is_nil() ||
+ SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+ {
+ anAvailableAlgs.append( curAlgo->Label );
+ myAvailableHypData[dim][Algo].append( curAlgo );
+ }
+ }
+ if ( !isNone && algoCur ) {
+ for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
+ {
+ HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
+ if ( algoAny->Label == algoCur->Label ){
+ isAvailableChoiceAlgo = true;
+ anCurrentAvailableAlgo = i;
+ break;
+ }
+ }
+ }
+ else if ( !isNone ) {
+ isAvailableChoiceAlgo = true;
+ anCurrentAvailableAlgo = currentHyp( dim, Algo );
+ }
+ }
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
+ if ( isAvailableChoiceAlgo )
+ setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
+ }
+ if ( !myIsOnGeometry )
+ for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
+ if ( i < SMESH::DIM_3D ) myDlg->disableTab( i );
+ else myDlg->enableTab( i );
+ }
+ else
+ for ( int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++ ) {
+ if ( i > myMaxShapeDim ) myDlg->disableTab( i );
+ else myDlg->enableTab( i );
+ }
+ myDlg->setCurrentTab( theTabIndex );
+ }
+ else
+ {
+ QString anCurrentAlgo;
+ bool isReqDisBound = true;
+ QString anCurrentCompareType = anCompareType;
+ isNone = currentHyp( aDim, Algo ) < 0;
+ if ( !isNone && !myAvailableHypData[aDim][Algo].empty() &&
+ myAvailableHypData[aDim][Algo].count() != anAvailableAlgsData.count() )
+ isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
+ else if ( !isNone )
+ isReqDisBound = anAvailableAlgsData.at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
+ for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
+ {
+ bool isNoneAlg = currentHyp( dim, Algo ) < 0;
+ isAvailableChoiceAlgo = false;
+ // retrieves a list of available algorithms from resources
+ availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
+ // finding algorithm which is selected
+ if ( !isNoneAlg && !myAvailableHypData[dim][Algo].empty() &&
+ myAvailableHypData[dim][Algo].count() != anAvailableAlgsData.count() )
+ anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) )->Label;
+ else if ( !isNoneAlg )
+ anCurrentAlgo = anAvailableAlgsData.at( currentHyp( dim, Algo ) )->Label;
+ anAvailableAlgs.clear();
+ myAvailableHypData[dim][Algo].clear();
+ myFilteredAlgoData[dim].clear();
+ // finding and adding algorithm depending on the type mesh
+ for ( int i = 0 ; i < anAvailableAlgsData.count(); i++ )
+ {
+ HypothesisData* algoIn = anAvailableAlgsData.at( i );
+ bool isAvailableAlgo = ( algoIn->OutputTypes.count() == 0 );
+ QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
+ for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
+ {
+ if ( *inElemType == anCurrentCompareType ) {
+ isAvailableAlgo = true;
+ break;
+ }
+ }
+ if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
+ if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
+ SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+ {
+ anAvailableAlgs.append( algoIn->Label );
+ myAvailableHypData[dim][Algo].append( algoIn );
+ myFilteredAlgoData[dim].append( algoIn );
+ }
+ }
+ //algorithm will be active, if the chosen algorithm available in the current mesh type
+ if ( !isNoneAlg && isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
+ isAvailableChoiceAlgo = true;
+ anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
+ }
+ }
+ //set new algorithm list and select the current algorithm
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
+ anCurrentCompareType = ( anCompareType == "HEXA" ) ? "QUAD" : "TRIA";
+ if ( isAvailableChoiceAlgo )
+ setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
+ else
+ setCurrentHyp( dim, Algo, -1 );
+ }
+
+ if ( isNone || isReqDisBound ) {
+ for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
+ if ( aDim != i ) {
+ myDlg->disableTab( i );
+ setCurrentHyp(i, Algo, -1);
+ }
+ }
+ }
+ else if ( !isNone ) {
+ if ( aDim == SMESH::DIM_2D){
+ myDlg->disableTab( SMESH::DIM_3D );
+ setCurrentHyp( SMESH::DIM_3D, Algo, -1);
+ }
+ for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
+ {
+ isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
+ myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
+ if ( isReqDisBound ) {
+ for (int j = i - 1; j >= SMESH::DIM_0D; j--){
+ myDlg->disableTab( j );
+ setCurrentHyp( j , Algo, -1 );
+ }
+ break;
+ }
+ }
+ }
+ myDlg->enableTab( aDim );
+ myDlg->setCurrentTab( aDim );
+ }
+ QStringList aHypothesesSetsList = SMESH::GetHypothesesSets( aDim );
+ QStringList aFilteredHypothesesSetsList;
+ aFilteredHypothesesSetsList.clear();
+ QStringList::const_iterator inHypoSetName = aHypothesesSetsList.begin();
+ for ( ; inHypoSetName != aHypothesesSetsList.end(); ++inHypoSetName )
+ {
+ HypothesesSet* currentHypoSet = SMESH::GetHypothesesSet( *inHypoSetName );
+ bool isAvailable = false;
+ currentHypoSet->init( true );
+ while ( currentHypoSet->next(), currentHypoSet->more() )
+ {
+ isAvailable = false;
+ if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
+ {
+ for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
+ {
+ if ( myAvailableHypData[i][Algo].count() == 0 ) {
+ availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
+ for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
+ {
+ HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
+ if ( aCurAlgo->Label == algoDataIn->Label ){
+ isAvailable = true;
+ break;
+ }
+ }
+ }
+ else {
+ for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
+ HypothesisData* aCurAlgo = hypData( i, Algo, j );
+ if ( aCurAlgo->Label == algoDataIn->Label ){
+ isAvailable = true;
+ break;
+ }
+ }
+ }
+ if ( isAvailable ) break;
+ }
+ if ( !isAvailable ) break;
+ }
+ }
+ if ( isAvailable )
+ aFilteredHypothesesSetsList.append( *inHypoSetName );
+ }
+ myDlg->setHypoSets( aFilteredHypothesesSetsList );
+}