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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ConvToQuadOp.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "SMESHGUI_ConvToQuadOp.h"
29 #include "SMESHGUI_ConvToQuadDlg.h"
30 #include "SMESHGUI_Utils.h"
32 #include <SMESH_TypeFilter.hxx>
34 // SALOME GUI includes
35 #include <LightApp_UpdateFlags.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SalomeApp_Tools.h>
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
44 //================================================================================
48 * Initialize operation
50 //================================================================================
51 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
52 : SMESHGUI_SelectionOp(),
57 //================================================================================
61 //================================================================================
62 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
68 //================================================================================
70 * \brief Gets dialog of this operation
71 * \retval LightApp_Dialog* - pointer to dialog of this operation
73 //================================================================================
74 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
79 //================================================================================
81 * \brief Creates dialog if necessary and shows it
83 * Virtual method redefined from base class called when operation is started creates
84 * dialog if necessary and shows it, activates selection
86 //================================================================================
87 void SMESHGUI_ConvToQuadOp::startOperation()
91 myDlg = new SMESHGUI_ConvToQuadDlg( );
93 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
95 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
97 SMESHGUI_SelectionOp::startOperation();
99 myDlg->SetMediumNdsOnGeom( false );
100 myDlg->activateObject( 0 );
106 //================================================================================
108 * \brief Updates dialog's look and feel
110 * Virtual method redefined from the base class updates dialog's look and feel
112 //================================================================================
113 void SMESHGUI_ConvToQuadOp::selectionDone()
115 if ( !dlg()->isVisible() )
118 SMESHGUI_SelectionOp::selectionDone();
121 QString anMeshEntry = myDlg->selectedObject( 0 );
122 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
123 if ( !pMesh ) return;
125 SMESH::SMESH_Mesh_var mesh =
126 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
128 if( mesh->_is_nil() )
130 myDlg->SetEnabledControls( false );
132 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic )
134 myDlg->SetEnabledRB( 0, false );
136 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear )
138 myDlg->SetEnabledRB( 1, false );
142 myDlg->SetEnabledControls( true );
145 catch ( const SALOME::SALOME_Exception& S_ex )
147 SalomeApp_Tools::QtCatchCorbaException( S_ex );
154 //================================================================================
156 * \brief Creates selection filter
157 * \param theId - identifier of current selection widget
158 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
160 * Creates selection filter in accordance with identifier of current selection widget
162 //================================================================================
163 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
166 return new SMESH_TypeFilter( MESH );
171 //================================================================================
175 * Virtual slot redefined from the base class called when "Apply" button is clicked
177 //================================================================================
178 bool SMESHGUI_ConvToQuadOp::onApply()
180 SUIT_OverrideCursor aWaitCursor;
184 QString anMeshEntry = myDlg->selectedObject( 0 );
185 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
189 SUIT_MessageBox::warning( myDlg,
190 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
195 SMESH::SMESH_Mesh_var mesh =
196 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
198 if( CORBA::is_nil(mesh) )
200 SUIT_MessageBox::warning( myDlg,
201 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
206 bool aResult = false;
210 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
211 if( !myDlg->CurrentRB() )
214 if( myDlg->IsEnabledCheck() )
215 aParam = myDlg->IsMediumNdsOnGeom();
217 aEditor->ConvertToQuadratic( aParam );
222 aResult = aEditor->ConvertFromQuadratic();
225 catch ( const SALOME::SALOME_Exception& S_ex )
227 SalomeApp_Tools::QtCatchCorbaException( S_ex );
236 update( UF_ObjBrowser | UF_Model | UF_Viewer );
242 //================================================================================
244 * Determines, what elements this mesh contains.
246 //================================================================================
247 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_Mesh_var& mesh) const
249 int nbAllElem = 0, nbQEdges =0, nbQFaces =0, nbQVolum = 0;
250 int nbEdges = 0, nbFaces = 0, nbVolum = 0;
252 nbAllElem = (int)mesh->NbElements();
253 nbQEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_QUADRATIC);
254 nbQFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_QUADRATIC);
255 nbQVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_QUADRATIC);
257 nbEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR);
258 nbFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR);
259 nbVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR);
261 if( nbAllElem == (nbQEdges+nbQFaces+nbQVolum) )
262 return SMESHGUI_ConvToQuadOp::Quadratic;
263 else if ( nbAllElem == (nbEdges+nbFaces+nbVolum) )
264 return SMESHGUI_ConvToQuadOp::Linear;
266 return SMESHGUI_ConvToQuadOp::Comp;
270 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
272 QString anMeshEntry = myDlg->selectedObject( 0 );
273 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
274 if ( !pMesh ) return;
276 SMESH::SMESH_Mesh_var mesh =
277 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
279 GEOM::GEOM_Object_var mainGeom;
280 mainGeom = mesh->GetShapeToMesh();
282 if( id || mainGeom->_is_nil() )
283 myDlg->SetEnabledCheck( false );
285 myDlg->SetEnabledCheck( true );