X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_ConvToQuadOp.cxx;h=77b0a8fe67c5ff3363075ec18a53c1f2c5c973ba;hp=962b11abdf95ddca42b1ac344acaa8c4961664b3;hb=2077baef82667760cb5fdc79454203a10d457d38;hpb=0635c9fc80f67d1e5dc0e94ec85f487286a92070 diff --git a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx index 962b11abd..77b0a8fe6 100644 --- a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx +++ b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx @@ -1,24 +1,25 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SMESH SMESHGUI : GUI for SMESH component // File : SMESHGUI_ConvToQuadOp.cxx // Author : Open CASCADE S.A.S. @@ -26,20 +27,28 @@ // #include "SMESHGUI_ConvToQuadOp.h" +#include "SMESHGUI.h" #include "SMESHGUI_ConvToQuadDlg.h" +#include "SMESHGUI_MeshEditPreview.h" #include "SMESHGUI_Utils.h" - -#include +#include "SMESH_ActorUtils.h" +#include "SMESH_TypeFilter.hxx" +#include "SMDSAbs_ElementType.hxx" // SALOME GUI includes -#include -#include #include +#include +#include +#include +#include // IDL includes #include #include CORBA_SERVER_HEADER(SMESH_MeshEditor) +// VTK includes +#include + //================================================================================ /*! * \brief Constructor @@ -49,7 +58,8 @@ //================================================================================ SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp() : SMESHGUI_SelectionOp(), - myDlg( 0 ) + myDlg( 0 ), + myBadElemsPreview(0) { } @@ -60,8 +70,8 @@ SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp() //================================================================================ SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp() { - if ( myDlg ) - delete myDlg; + if ( myDlg ) delete myDlg; + if ( myBadElemsPreview ) delete myBadElemsPreview; } //================================================================================ @@ -95,8 +105,9 @@ void SMESHGUI_ConvToQuadOp::startOperation() SMESHGUI_SelectionOp::startOperation(); - myDlg->SetMediumNdsOnGeom( false ); + myDlg->SetMediumNdsOnGeom( true ); myDlg->activateObject( 0 ); + myDlg->ShowWarning( false ); myDlg->show(); selectionDone(); @@ -117,28 +128,40 @@ void SMESHGUI_ConvToQuadOp::selectionDone() SMESHGUI_SelectionOp::selectionDone(); try { - QString anMeshEntry = myDlg->selectedObject( 0 ); - _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() ); - if ( !pMesh ) return; + QString anObjEntry = myDlg->selectedObject( 0 ); + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); + if ( !pObj ) return; - SMESH::SMESH_Mesh_var mesh = - SMESH::SObjectToInterface( pMesh ); + SMESH::SMESH_IDSource_var idSource = + SMESH::SObjectToInterface( pObj ); - if( mesh->_is_nil() ) + myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply ); + if( idSource->_is_nil() ) { myDlg->SetEnabledControls( false ); + myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply ); + return; } - else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic ) - { - myDlg->SetEnabledRB( 0, false ); - } - else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear ) - { - myDlg->SetEnabledRB( 1, false ); - } - else + SMESH::SMESH_Mesh_var mesh = idSource->GetMesh(); + bool hasGeom = mesh->HasShapeToMesh(); + MeshDestinationType meshTgtType = DestinationMesh( idSource ); + myDlg->SetEnabledRB( meshTgtType, hasGeom && ( meshTgtType & ( BiQuadratic | Quadratic ))); + + // show warning on non-conformal result mesh + if ( ! idSource->_is_nil() ) { - myDlg->SetEnabledControls( true ); + SMESH::SMESH_subMesh_var subMesh = + SMESH::SObjectToInterface( pObj ); + bool toShow = false; + if ( !subMesh->_is_nil() ) + { + SMESH::SMESH_Mesh_var mesh = idSource->GetMesh(); + idSource = SMESH::SMESH_IDSource::_narrow( mesh ); + bool isMixOrder; + DestinationMesh( idSource, &isMixOrder ); + toShow = !isMixOrder; + } + myDlg->ShowWarning( toShow ); } } catch ( const SALOME::SALOME_Exception& S_ex ) @@ -162,7 +185,7 @@ void SMESHGUI_ConvToQuadOp::selectionDone() SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const { if ( theId == 0 ) - return new SMESH_TypeFilter( MESH ); + return new SMESH_TypeFilter( SMESH::MESHorSUBMESH ); else return 0; } @@ -176,48 +199,93 @@ SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) con //================================================================================ bool SMESHGUI_ConvToQuadOp::onApply() { + SUIT_OverrideCursor aWaitCursor; QString aMess; - QString anMeshEntry = myDlg->selectedObject( 0 ); - _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() ); - if ( !pMesh ) + QString anObjEntry = myDlg->selectedObject( 0 ); + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); + if ( !pObj ) { dlg()->show(); SUIT_MessageBox::warning( myDlg, - tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") ); - + tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") ); return false; } - SMESH::SMESH_Mesh_var mesh = - SMESH::SObjectToInterface( pMesh ); + SMESH::SMESH_Mesh_var mesh; + SMESH::SMESH_IDSource_var idSource = + SMESH::SObjectToInterface( pObj ); + if( !CORBA::is_nil(idSource) ) + mesh = idSource->GetMesh(); if( CORBA::is_nil(mesh) ) { SUIT_MessageBox::warning( myDlg, - tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") ); - + tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") ); return false; - } + } bool aResult = false; try { SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor(); - if( !myDlg->CurrentRB() ) + aResult = true; + SMESH::SMESH_Mesh_var sourceMesh = SMESH::SObjectToInterface( pObj ); + if( myDlg->CurrentRB()==1 || myDlg->CurrentRB()==2) { - bool aParam = true; + bool force3d = true; if( myDlg->IsEnabledCheck() ) - aParam = myDlg->IsMediumNdsOnGeom(); - - aEditor->ConvertToQuadratic( aParam ); - aResult = true; + force3d = myDlg->IsMediumNdsOnGeom(); + bool theToBiQuad = myDlg->IsBiQuadratic(); + if ( sourceMesh->_is_nil() ) { + if ( theToBiQuad ) aEditor->ConvertToBiQuadratic ( force3d, idSource ); + else aEditor->ConvertToQuadraticObject( force3d, idSource ); + } + else { + if ( theToBiQuad ) aEditor->ConvertToBiQuadratic( force3d, sourceMesh ); + else aEditor->ConvertToQuadratic ( force3d ); + } + if ( !force3d ) + { + SMESH::ComputeError_var error = aEditor->GetLastError(); + if ( error->hasBadMesh ) + { + if ( myBadElemsPreview ) delete myBadElemsPreview; // viewWindow may change + myBadElemsPreview = new SMESHGUI_MeshEditPreview( viewWindow() ); + + double aPointSize = SMESH::GetFloat("SMESH:node_size",3); + double aLineWidth = SMESH::GetFloat("SMESH:element_width",1); + vtkProperty* prop = vtkProperty::New(); + prop->SetLineWidth( aLineWidth * 3 ); + prop->SetPointSize( aPointSize * 3 ); + prop->SetColor( 250, 0, 250 ); + myBadElemsPreview->GetActor()->SetProperty( prop ); + prop->Delete(); + + SMESH::MeshPreviewStruct_var previewData = aEditor->GetPreviewData(); + myBadElemsPreview->SetData( & previewData.in() ); + myBadElemsPreview->SetVisibility(true); + + SUIT_MessageBox* mb = new SUIT_MessageBox(SUIT_MessageBox::Warning, + tr( "SMESH_WRN_WARNING" ), + tr("EDITERR_NO_MEDIUM_ON_GEOM"), + SUIT_MessageBox::Ok, myDlg); + mb->setWindowModality( Qt::NonModal ); + mb->setAttribute( Qt::WA_DeleteOnClose ); + mb->show(); + connect ( mb, SIGNAL( finished(int) ), this, SLOT( onWarningWinFinished() )); + //connect ( mb, SIGNAL( rejected() ), this, SLOT( onWarningWinFinished() )); + } + } } else { - aResult = aEditor->ConvertFromQuadratic(); + if ( sourceMesh->_is_nil() ) + aEditor->ConvertFromQuadraticObject( idSource ); + else + aEditor->ConvertFromQuadratic(); } } catch ( const SALOME::SALOME_Exception& S_ex ) @@ -231,6 +299,7 @@ bool SMESHGUI_ConvToQuadOp::onApply() } if( aResult ) { + SMESHGUI::Modified(); update( UF_ObjBrowser | UF_Model | UF_Viewer ); selectionDone(); } @@ -238,46 +307,92 @@ bool SMESHGUI_ConvToQuadOp::onApply() } //================================================================================ -/*! ConsistMesh - * Determines, what elements this mesh contains. +/*! + * \brief SLOT called when a warning window is closed */ //================================================================================ -SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_Mesh_var& mesh) const + +void SMESHGUI_ConvToQuadOp::onWarningWinFinished() { - int nbAllElem = 0, nbQEdges =0, nbQFaces =0, nbQVolum = 0; - int nbEdges = 0, nbFaces = 0, nbVolum = 0; - - nbAllElem = (int)mesh->NbElements(); - nbQEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_QUADRATIC); - nbQFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_QUADRATIC); - nbQVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_QUADRATIC); - - nbEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR); - nbFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR); - nbVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR); - - if( nbAllElem == (nbQEdges+nbQFaces+nbQVolum) ) - return SMESHGUI_ConvToQuadOp::Quadratic; - else if ( nbAllElem == (nbEdges+nbFaces+nbVolum) ) - return SMESHGUI_ConvToQuadOp::Linear; - else - return SMESHGUI_ConvToQuadOp::Comp; + if ( myBadElemsPreview ) + myBadElemsPreview->SetVisibility(false); } +//================================================================================ +/*! ConsistMesh + * Determines, what elements this mesh does not contain. + */ +//================================================================================ + +SMESHGUI_ConvToQuadOp::MeshDestinationType +SMESHGUI_ConvToQuadOp::DestinationMesh( const SMESH::SMESH_IDSource_var& idSource, + bool* isMixOrder) +{ + SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo(); + + bool hasBiQuad = ( nbElemOfType[SMDSEntity_BiQuad_Triangle ] || + nbElemOfType[SMDSEntity_BiQuad_Quadrangle ] || + nbElemOfType[SMDSEntity_BiQuad_Penta ] || + nbElemOfType[SMDSEntity_TriQuad_Hexa ] ); + bool hasLinBiQuad = ( nbElemOfType[SMDSEntity_Triangle ] || + nbElemOfType[SMDSEntity_Quadrangle ] || + nbElemOfType[SMDSEntity_Hexa ] ); + bool hasQuadBiQuad = ( nbElemOfType[SMDSEntity_Quad_Triangle ] || + nbElemOfType[SMDSEntity_Quad_Quadrangle ] || + nbElemOfType[SMDSEntity_Quad_Hexa ] ); + + bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge ] || + nbElemOfType[SMDSEntity_Quad_Triangle ] || + nbElemOfType[SMDSEntity_Quad_Quadrangle] || + nbElemOfType[SMDSEntity_Quad_Tetra ] || + nbElemOfType[SMDSEntity_Quad_Hexa ] || + nbElemOfType[SMDSEntity_Quad_Pyramid ] || + nbElemOfType[SMDSEntity_Quad_Polygon ] || + nbElemOfType[SMDSEntity_Quad_Penta ] ); + + bool hasLin = ( nbElemOfType[SMDSEntity_Edge ] || + nbElemOfType[SMDSEntity_Triangle ] || + nbElemOfType[SMDSEntity_Quadrangle] || + nbElemOfType[SMDSEntity_Tetra ] || + nbElemOfType[SMDSEntity_Hexa ] || + nbElemOfType[SMDSEntity_Pyramid ] || + nbElemOfType[SMDSEntity_Polygon ] || + nbElemOfType[SMDSEntity_Penta ] ); + + int tgtType = 0; + if ( hasBiQuad ) + tgtType |= ( Quadratic | Linear ); + if ( hasLinBiQuad ) + tgtType |= ( BiQuadratic | Quadratic ); + if ( hasQuadBiQuad ) + tgtType |= ( BiQuadratic | Linear ); + if ( hasQuad ) + tgtType |= Linear; + if ( hasLin ) + tgtType |= Quadratic; + + if ( tgtType == 0 ) + tgtType = Quadratic; + + if ( isMixOrder ) + *isMixOrder = ( hasLin && ( hasQuad || hasBiQuad )); + + return MeshDestinationType( tgtType ); +} void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id ) { - QString anMeshEntry = myDlg->selectedObject( 0 ); - _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() ); - if ( !pMesh ) return; + QString anObjEntry = myDlg->selectedObject( 0 ); + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() ); + if ( !pObj ) return; - SMESH::SMESH_Mesh_var mesh = - SMESH::SObjectToInterface( pMesh ); + SMESH::SMESH_IDSource_var idSource = + SMESH::SObjectToInterface( pObj ); + SMESH::SMESH_Mesh_var mesh = idSource->GetMesh(); - GEOM::GEOM_Object_var mainGeom; - mainGeom = mesh->GetShapeToMesh(); + bool hasGeom = mesh->HasShapeToMesh(); - if( id || mainGeom->_is_nil() ) + if( id==0 || !hasGeom ) myDlg->SetEnabledCheck( false ); else myDlg->SetEnabledCheck( true );