1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_ConvToQuadOp.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_ConvToQuadOp.h"
31 #include "SMESHGUI_ConvToQuadDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMDSAbs_ElementType.hxx"
35 #include "SMESH_TypeFilter.hxx"
37 // SALOME GUI includes
38 #include <LightApp_UpdateFlags.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_OverrideCursor.h>
41 #include <SalomeApp_Tools.h>
44 #include <SALOMEconfig.h>
45 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
47 //================================================================================
51 * Initialize operation
53 //================================================================================
54 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
55 : SMESHGUI_SelectionOp(),
60 //================================================================================
64 //================================================================================
65 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
71 //================================================================================
73 * \brief Gets dialog of this operation
74 * \retval LightApp_Dialog* - pointer to dialog of this operation
76 //================================================================================
77 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
82 //================================================================================
84 * \brief Creates dialog if necessary and shows it
86 * Virtual method redefined from base class called when operation is started creates
87 * dialog if necessary and shows it, activates selection
89 //================================================================================
90 void SMESHGUI_ConvToQuadOp::startOperation()
94 myDlg = new SMESHGUI_ConvToQuadDlg( );
96 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
98 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
100 SMESHGUI_SelectionOp::startOperation();
102 myDlg->SetMediumNdsOnGeom( false );
103 myDlg->activateObject( 0 );
104 myDlg->ShowWarning( false );
110 //================================================================================
112 * \brief Updates dialog's look and feel
114 * Virtual method redefined from the base class updates dialog's look and feel
116 //================================================================================
117 void SMESHGUI_ConvToQuadOp::selectionDone()
119 if ( !dlg()->isVisible() )
122 SMESHGUI_SelectionOp::selectionDone();
125 QString anObjEntry = myDlg->selectedObject( 0 );
126 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
129 SMESH::SMESH_IDSource_var idSource =
130 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
132 myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply );
133 if( idSource->_is_nil() )
135 myDlg->SetEnabledControls( false );
136 myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
139 MeshType meshType = ConsistMesh( idSource );
140 if( meshType == SMESHGUI_ConvToQuadOp::Quadratic )
142 myDlg->SetEnabledRB( 0, false );
144 else if( meshType == SMESHGUI_ConvToQuadOp::Linear )
146 myDlg->SetEnabledRB( 1, false );
150 myDlg->SetEnabledControls( true );
153 // show warning on non-conformal result mesh
154 if ( ! idSource->_is_nil() )
156 SMESH::SMESH_subMesh_var subMesh =
157 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
159 if ( !subMesh->_is_nil() )
161 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
162 idSource = SMESH::SMESH_IDSource::_narrow( mesh );
163 MeshType fullMeshType = ConsistMesh( idSource );
164 toShow = ( fullMeshType != Comp );
166 myDlg->ShowWarning( toShow );
169 catch ( const SALOME::SALOME_Exception& S_ex )
171 SalomeApp_Tools::QtCatchCorbaException( S_ex );
178 //================================================================================
180 * \brief Creates selection filter
181 * \param theId - identifier of current selection widget
182 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
184 * Creates selection filter in accordance with identifier of current selection widget
186 //================================================================================
187 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
190 return new SMESH_TypeFilter( MESHorSUBMESH );
195 //================================================================================
199 * Virtual slot redefined from the base class called when "Apply" button is clicked
201 //================================================================================
202 bool SMESHGUI_ConvToQuadOp::onApply()
204 SUIT_OverrideCursor aWaitCursor;
208 QString anObjEntry = myDlg->selectedObject( 0 );
209 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
213 SUIT_MessageBox::warning( myDlg,
214 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
218 SMESH::SMESH_Mesh_var mesh;
219 SMESH::SMESH_IDSource_var idSource =
220 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
221 if( !CORBA::is_nil(idSource) )
222 mesh = idSource->GetMesh();
224 if( CORBA::is_nil(mesh) )
226 SUIT_MessageBox::warning( myDlg,
227 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
231 bool aResult = false;
235 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
237 if( !myDlg->CurrentRB() )
240 if( myDlg->IsEnabledCheck() )
241 aParam = myDlg->IsMediumNdsOnGeom();
243 if ( myDlg->isWarningShown() )
244 aEditor->ConvertToQuadraticObject( aParam, idSource );
246 aEditor->ConvertToQuadratic( aParam );
250 if ( myDlg->isWarningShown() )
251 aEditor->ConvertFromQuadraticObject( idSource );
253 aEditor->ConvertFromQuadratic();
256 catch ( const SALOME::SALOME_Exception& S_ex )
258 SalomeApp_Tools::QtCatchCorbaException( S_ex );
267 SMESHGUI::Modified();
268 update( UF_ObjBrowser | UF_Model | UF_Viewer );
274 //================================================================================
276 * Determines, what elements this mesh contains.
278 //================================================================================
279 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_IDSource_var& idSource) const
281 SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo();
282 bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge ] ||
283 nbElemOfType[SMDSEntity_Quad_Triangle ] ||
284 nbElemOfType[SMDSEntity_Quad_Quadrangle] ||
285 nbElemOfType[SMDSEntity_Quad_Tetra ] ||
286 nbElemOfType[SMDSEntity_Quad_Hexa ] ||
287 nbElemOfType[SMDSEntity_Quad_Pyramid ] ||
288 nbElemOfType[SMDSEntity_Quad_Penta ] );
290 bool hasLin = ( nbElemOfType[SMDSEntity_Edge ] ||
291 nbElemOfType[SMDSEntity_Triangle ] ||
292 nbElemOfType[SMDSEntity_Quadrangle] ||
293 nbElemOfType[SMDSEntity_Tetra ] ||
294 nbElemOfType[SMDSEntity_Hexa ] ||
295 nbElemOfType[SMDSEntity_Pyramid ] ||
296 nbElemOfType[SMDSEntity_Penta ] );
298 if ( hasQuad && hasLin )
300 return hasQuad ? Quadratic : Linear;
303 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
305 QString anObjEntry = myDlg->selectedObject( 0 );
306 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
309 SMESH::SMESH_IDSource_var idSource =
310 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
311 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
313 bool hasGeom = mesh->HasShapeToMesh();
316 myDlg->SetEnabledCheck( false );
318 myDlg->SetEnabledCheck( true );