1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Copyright (C) 2005 CEA/DEN, EDF R&D
27 * File : SMESHGUI_ConvToQuadOp.h
31 #include "SMESHGUI_ConvToQuadOp.h"
32 #include "SMESHGUI_ConvToQuadDlg.h"
35 #include "SMESHGUI_Utils.h"
37 #include "SMESH_TypeFilter.hxx"
39 #include "SalomeApp_Tools.h"
41 #include "SUIT_MessageBox.h"
43 #include "LightApp_UpdateFlags.h"
45 //================================================================================
49 * Initialize operation
51 //================================================================================
52 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
53 : SMESHGUI_SelectionOp(),
58 //================================================================================
62 //================================================================================
63 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
69 //================================================================================
71 * \brief Gets dialog of this operation
72 * \retval LightApp_Dialog* - pointer to dialog of this operation
74 //================================================================================
75 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
80 //================================================================================
82 * \brief Creates dialog if necessary and shows it
84 * Virtual method redefined from base class called when operation is started creates
85 * dialog if necessary and shows it, activates selection
87 //================================================================================
88 void SMESHGUI_ConvToQuadOp::startOperation()
92 myDlg = new SMESHGUI_ConvToQuadDlg( );
94 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
96 myHelpFileName = "/files/convert_to_from_quadratic.htm";
98 SMESHGUI_SelectionOp::startOperation();
100 myDlg->SetMediumNdsOnGeom( false );
101 myDlg->activateObject( 0 );
107 //================================================================================
109 * \brief Updates dialog's look and feel
111 * Virtual method redefined from the base class updates dialog's look and feel
113 //================================================================================
114 void SMESHGUI_ConvToQuadOp::selectionDone()
116 if ( !dlg()->isShown() )
119 SMESHGUI_SelectionOp::selectionDone();
122 QString anMeshEntry = myDlg->selectedObject( 0 );
123 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
124 if ( !pMesh ) return;
126 SMESH::SMESH_Mesh_var mesh =
127 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
129 if( mesh->_is_nil() )
131 myDlg->SetEnabledControls( false );
133 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic )
135 myDlg->SetEnabledRB( 0, false );
137 else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear )
139 myDlg->SetEnabledRB( 1, false );
143 myDlg->SetEnabledControls( true );
146 catch ( const SALOME::SALOME_Exception& S_ex )
148 SalomeApp_Tools::QtCatchCorbaException( S_ex );
155 //================================================================================
157 * \brief Creates selection filter
158 * \param theId - identifier of current selection widget
159 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
161 * Creates selection filter in accordance with identifier of current selection widget
163 //================================================================================
164 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
167 return new SMESH_TypeFilter( MESH );
172 //================================================================================
176 * Virtual slot redefined from the base class called when "Apply" button is clicked
178 //================================================================================
179 bool SMESHGUI_ConvToQuadOp::onApply()
184 QString anMeshEntry = myDlg->selectedObject( 0 );
185 _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() );
189 SUIT_MessageBox::warn1( myDlg,
190 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED"), tr( "SMESH_BUT_OK" ) );
195 SMESH::SMESH_Mesh_var mesh =
196 SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pMesh );
198 if( CORBA::is_nil(mesh) )
200 SUIT_MessageBox::warn1( myDlg,
201 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL"), tr( "SMESH_BUT_OK" ) );
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.latin1() );
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 );