+
+//================================================================================
+/*!
+ * \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 = SMESH::toQStr( 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)
+{
+ QStringList anAvailableAlgs;
+ QString anCompareType = currentMeshTypeName( theIndex );
+ int anCurrentAvailableAlgo = -1;
+ bool isNone = true;
+ int aDim = SMESH::DIM_3D;
+ if ( theIndex == MT_TRIANGULAR || theIndex == MT_QUADRILATERAL)
+ aDim = SMESH::DIM_2D;
+ if ( anCompareType == "ANY" )
+ {
+ bool isReqDisBound = false;
+ int aReqDim = SMESH::DIM_3D;
+ for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
+ {
+ anCurrentAvailableAlgo = -1;
+ isNone = currentHyp( dim, Algo ) < 0;
+ //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 ) );
+ }
+ HypothesisData* prevAlgo = 0;
+ HypothesisData* nextAlgo = 0;
+ if ( dim == SMESH::DIM_2D ) {
+ prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
+ if ( aDim == SMESH::DIM_3D )
+ nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
+ }
+ // retrieves a list of available algorithms from resources
+ availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCompareType);
+ anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( algoCur );
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
+ setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
+ if ( anCurrentAvailableAlgo > -1 )
+ isReqDisBound = algoCur->InputTypes.isEmpty();
+ else if ( dim != SMESH::DIM_3D && currentHyp( SMESH::DIM_3D, Algo ) >= 0 )
+ isReqDisBound = true;
+ if ( isReqDisBound ) {
+ aReqDim = dim;
+ break;
+ }
+ }
+ 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 || ( isReqDisBound && i < aReqDim ) ) myDlg->disableTab( i );
+ else myDlg->enableTab( i );
+ }
+ myDlg->setCurrentTab( theTabIndex );
+ }
+ else
+ {
+ HypothesisData* anCurrentAlgo;
+ bool isReqDisBound = true;
+ QString anCurrentCompareType = anCompareType;
+ isNone = currentHyp( aDim, Algo ) < 0;
+ if ( !isNone && !myAvailableHypData[aDim][Algo].empty() )
+ isReqDisBound = myAvailableHypData[aDim][Algo].at( currentHyp( aDim, Algo ) )->InputTypes.isEmpty();
+ for ( int dim = aDim; dim >= SMESH::DIM_2D; dim-- )
+ {
+ bool isNoneAlg = currentHyp( dim, Algo ) < 0;
+ anCurrentAvailableAlgo = -1;
+ HypothesisData* prevAlgo = 0;
+ HypothesisData* nextAlgo = 0;
+ if ( dim == SMESH::DIM_2D ) {
+ prevAlgo = hypData( SMESH::DIM_1D, Algo, currentHyp( SMESH::DIM_1D, Algo ) );
+ if ( aDim == SMESH::DIM_3D )
+ nextAlgo = hypData( SMESH::DIM_3D, Algo, currentHyp( SMESH::DIM_3D, Algo ) );
+ }
+ // finding algorithm which is selected
+ if ( !isNoneAlg ) {
+ anCurrentAlgo = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
+ }
+ // retrieves a list of available algorithms from resources
+ availableHyps( dim, Algo, anAvailableAlgs, myAvailableHypData[dim][Algo], prevAlgo, nextAlgo, anCurrentCompareType );
+ // finding and adding algorithm depending on the type mesh
+ anCurrentAvailableAlgo = myAvailableHypData[dim][Algo].indexOf( anCurrentAlgo );
+ //set new algorithm list and select the current algorithm
+ myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
+ anCurrentCompareType = ( anCompareType == "HEXA" || anCompareType == "QUAD" ) ? "QUAD" : "TRIA";
+ setCurrentHyp( dim, Algo, anCurrentAvailableAlgo );
+ }
+
+ if ( isNone || isReqDisBound ) {
+ for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
+ if ( aDim != i ) {
+ myDlg->disableTab( i );
+ }
+ }
+ }
+ 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-- ) {
+ bool isNoneAlg = currentHyp( i, Algo ) < 0;
+ if ( !isNoneAlg )
+ isReqDisBound = myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
+ else
+ isReqDisBound = true;
+ if ( isReqDisBound && isNoneAlg ) {
+ for (int j = i - 1; j >= SMESH::DIM_0D; j--) {
+ if ( j < aDim && currentHyp( j+1, Algo ) < 0 ) {
+ myDlg->disableTab( j );
+ setCurrentHyp( j , Algo, -1 );
+ }
+ }
+ break;
+ }
+ else if ( isNoneAlg ) {
+ myDlg->disableTab( i );
+ }
+ }
+ }
+ myDlg->enableTab( aDim );
+ myDlg->setCurrentTab( aDim );
+ }
+ THypDataList anAvailableAlgsData;
+ 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++) {
+ int anCurrentAvailableAlgo = myAvailableHypData[i][Algo].indexOf( algoDataIn );
+ if ( anCurrentAvailableAlgo > -1 ) {
+ isAvailable = true;
+ break;
+ }
+ }
+ if ( !isAvailable )
+ break;
+ }
+ }
+ if ( isAvailable )
+ aFilteredHypothesesSetsList.append( *inHypoSetName );
+ }
+ myDlg->setHypoSets( aFilteredHypothesesSetsList );
+}
+
+//================================================================================
+/*!
+ * \brief Get current name types of mesh
+ * \param theIndex - current index types of mesh
+ * \retval QString - result
+ */
+//================================================================================
+QString SMESHGUI_MeshOp::currentMeshTypeName( const int theIndex ) const
+{
+ QString aMeshType = "";
+ switch ( theIndex ) {
+ case MT_ANY:
+ aMeshType = "ANY";
+ break;
+ case MT_TRIANGULAR:
+ aMeshType = "TRIA";
+ break;
+ case MT_QUADRILATERAL:
+ aMeshType = "QUAD";
+ break;
+ case MT_TETRAHEDRAL:
+ aMeshType = "TETRA";
+ break;
+ case MT_HEXAHEDRAL:
+ aMeshType = "HEXA";
+ break;
+ default:;
+ }
+ return aMeshType;
+}
+