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"
34 #include <SMESH_TypeFilter.hxx>
36 // SALOME GUI includes
37 #include <LightApp_UpdateFlags.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SalomeApp_Tools.h>
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
46 //================================================================================
50 * Initialize operation
52 //================================================================================
53 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
54 : SMESHGUI_SelectionOp(),
59 //================================================================================
63 //================================================================================
64 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
70 //================================================================================
72 * \brief Gets dialog of this operation
73 * \retval LightApp_Dialog* - pointer to dialog of this operation
75 //================================================================================
76 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
81 //================================================================================
83 * \brief Creates dialog if necessary and shows it
85 * Virtual method redefined from base class called when operation is started creates
86 * dialog if necessary and shows it, activates selection
88 //================================================================================
89 void SMESHGUI_ConvToQuadOp::startOperation()
93 myDlg = new SMESHGUI_ConvToQuadDlg( );
95 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
97 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
99 SMESHGUI_SelectionOp::startOperation();
101 myDlg->SetMediumNdsOnGeom( false );
102 myDlg->activateObject( 0 );
108 //================================================================================
110 * \brief Updates dialog's look and feel
112 * Virtual method redefined from the base class updates dialog's look and feel
114 //================================================================================
115 void SMESHGUI_ConvToQuadOp::selectionDone()
117 if ( !dlg()->isVisible() )
120 SMESHGUI_SelectionOp::selectionDone();
123 QString anMeshEntry = myDlg->selectedObject( 0 );
124 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
125 if ( !pMesh ) return;
127 SMESH::SMESH_Mesh_var mesh =
128 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
130 if( mesh->_is_nil() )
132 myDlg->SetEnabledControls( false );
134 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic )
136 myDlg->SetEnabledRB( 0, false );
138 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear )
140 myDlg->SetEnabledRB( 1, false );
144 myDlg->SetEnabledControls( true );
147 catch ( const SALOME::SALOME_Exception& S_ex )
149 SalomeApp_Tools::QtCatchCorbaException( S_ex );
156 //================================================================================
158 * \brief Creates selection filter
159 * \param theId - identifier of current selection widget
160 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
162 * Creates selection filter in accordance with identifier of current selection widget
164 //================================================================================
165 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
168 return new SMESH_TypeFilter( MESH );
173 //================================================================================
177 * Virtual slot redefined from the base class called when "Apply" button is clicked
179 //================================================================================
180 bool SMESHGUI_ConvToQuadOp::onApply()
182 SUIT_OverrideCursor aWaitCursor;
186 QString anMeshEntry = myDlg->selectedObject( 0 );
187 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
191 SUIT_MessageBox::warning( myDlg,
192 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
197 SMESH::SMESH_Mesh_var mesh =
198 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
200 if( CORBA::is_nil(mesh) )
202 SUIT_MessageBox::warning( myDlg,
203 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
208 bool aResult = false;
212 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
213 if( !myDlg->CurrentRB() )
216 if( myDlg->IsEnabledCheck() )
217 aParam = myDlg->IsMediumNdsOnGeom();
219 aEditor->ConvertToQuadratic( aParam );
224 aResult = aEditor->ConvertFromQuadratic();
227 catch ( const SALOME::SALOME_Exception& S_ex )
229 SalomeApp_Tools::QtCatchCorbaException( S_ex );
238 SMESHGUI::Modified();
239 update( UF_ObjBrowser | UF_Model | UF_Viewer );
245 //================================================================================
247 * Determines, what elements this mesh contains.
249 //================================================================================
250 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_Mesh_var& mesh) const
252 int nbAllElem = 0, nbQEdges =0, nbQFaces =0, nbQVolum = 0;
253 int nbEdges = 0, nbFaces = 0, nbVolum = 0;
255 nbAllElem = (int)mesh->NbElements();
256 nbQEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_QUADRATIC);
257 nbQFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_QUADRATIC);
258 nbQVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_QUADRATIC);
260 nbEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR);
261 nbFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR);
262 nbVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR);
264 if( nbAllElem == (nbQEdges+nbQFaces+nbQVolum) )
265 return SMESHGUI_ConvToQuadOp::Quadratic;
266 else if ( nbAllElem == (nbEdges+nbFaces+nbVolum) )
267 return SMESHGUI_ConvToQuadOp::Linear;
269 return SMESHGUI_ConvToQuadOp::Comp;
273 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
275 QString anMeshEntry = myDlg->selectedObject( 0 );
276 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.toLatin1().data() );
277 if ( !pMesh ) return;
279 SMESH::SMESH_Mesh_var mesh =
280 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
282 GEOM::GEOM_Object_var mainGeom;
283 mainGeom = mesh->GetShapeToMesh();
285 if( id || mainGeom->_is_nil() )
286 myDlg->SetEnabledCheck( false );
288 myDlg->SetEnabledCheck( true );