1 // Copyright (C) 2007-2008 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
25 * Copyright (C) 2005 CEA/DEN, EDF R&D
29 * File : SMESHGUI_ConvToQuadOp.h
33 #include "SMESHGUI_ConvToQuadOp.h"
34 #include "SMESHGUI_ConvToQuadDlg.h"
37 #include "SMESHGUI_Utils.h"
39 #include "SMESH_TypeFilter.hxx"
41 #include "SalomeApp_Tools.h"
43 #include "SUIT_MessageBox.h"
45 #include "LightApp_UpdateFlags.h"
47 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
49 //================================================================================
53 * Initialize operation
55 //================================================================================
56 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
57 : SMESHGUI_SelectionOp(),
62 //================================================================================
66 //================================================================================
67 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
73 //================================================================================
75 * \brief Gets dialog of this operation
76 * \retval LightApp_Dialog* - pointer to dialog of this operation
78 //================================================================================
79 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
84 //================================================================================
86 * \brief Creates dialog if necessary and shows it
88 * Virtual method redefined from base class called when operation is started creates
89 * dialog if necessary and shows it, activates selection
91 //================================================================================
92 void SMESHGUI_ConvToQuadOp::startOperation()
96 myDlg = new SMESHGUI_ConvToQuadDlg( );
98 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
100 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
102 SMESHGUI_SelectionOp::startOperation();
104 myDlg->SetMediumNdsOnGeom( false );
105 myDlg->activateObject( 0 );
111 //================================================================================
113 * \brief Updates dialog's look and feel
115 * Virtual method redefined from the base class updates dialog's look and feel
117 //================================================================================
118 void SMESHGUI_ConvToQuadOp::selectionDone()
120 if ( !dlg()->isShown() )
123 SMESHGUI_SelectionOp::selectionDone();
126 QString anMeshEntry = myDlg->selectedObject( 0 );
127 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
128 if ( !pMesh ) return;
130 SMESH::SMESH_Mesh_var mesh =
131 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
133 if( mesh->_is_nil() )
135 myDlg->SetEnabledControls( false );
137 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic )
139 myDlg->SetEnabledRB( 0, false );
141 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear )
143 myDlg->SetEnabledRB( 1, false );
147 myDlg->SetEnabledControls( true );
150 catch ( const SALOME::SALOME_Exception& S_ex )
152 SalomeApp_Tools::QtCatchCorbaException( S_ex );
159 //================================================================================
161 * \brief Creates selection filter
162 * \param theId - identifier of current selection widget
163 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
165 * Creates selection filter in accordance with identifier of current selection widget
167 //================================================================================
168 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
171 return new SMESH_TypeFilter( MESH );
176 //================================================================================
180 * Virtual slot redefined from the base class called when "Apply" button is clicked
182 //================================================================================
183 bool SMESHGUI_ConvToQuadOp::onApply()
188 QString anMeshEntry = myDlg->selectedObject( 0 );
189 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
193 SUIT_MessageBox::warn1( myDlg,
194 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED"), tr( "SMESH_BUT_OK" ) );
199 SMESH::SMESH_Mesh_var mesh =
200 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
202 if( CORBA::is_nil(mesh) )
204 SUIT_MessageBox::warn1( myDlg,
205 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL"), tr( "SMESH_BUT_OK" ) );
210 bool aResult = false;
214 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
215 if( !myDlg->CurrentRB() )
218 if( myDlg->IsEnabledCheck() )
219 aParam = myDlg->IsMediumNdsOnGeom();
221 aEditor->ConvertToQuadratic( aParam );
226 aResult = aEditor->ConvertFromQuadratic();
229 catch ( const SALOME::SALOME_Exception& S_ex )
231 SalomeApp_Tools::QtCatchCorbaException( S_ex );
240 update( UF_ObjBrowser | UF_Model | UF_Viewer );
246 //================================================================================
248 * Determines, what elements this mesh contains.
250 //================================================================================
251 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_Mesh_var& mesh) const
253 int nbAllElem = 0, nbQEdges =0, nbQFaces =0, nbQVolum = 0;
254 int nbEdges = 0, nbFaces = 0, nbVolum = 0;
256 nbAllElem = (int)mesh->NbElements();
257 nbQEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_QUADRATIC);
258 nbQFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_QUADRATIC);
259 nbQVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_QUADRATIC);
261 nbEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR);
262 nbFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR);
263 nbVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR);
265 if( nbAllElem == (nbQEdges+nbQFaces+nbQVolum) )
266 return SMESHGUI_ConvToQuadOp::Quadratic;
267 else if ( nbAllElem == (nbEdges+nbFaces+nbVolum) )
268 return SMESHGUI_ConvToQuadOp::Linear;
270 return SMESHGUI_ConvToQuadOp::Comp;
274 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
276 QString anMeshEntry = myDlg->selectedObject( 0 );
277 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
278 if ( !pMesh ) return;
280 SMESH::SMESH_Mesh_var mesh =
281 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
283 GEOM::GEOM_Object_var mainGeom;
284 mainGeom = mesh->GetShapeToMesh();
286 if( id || mainGeom->_is_nil() )
287 myDlg->SetEnabledCheck( false );
289 myDlg->SetEnabledCheck( true );