1 // Copyright (C) 2007-2012 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_MeshEditPreview.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESH_ActorUtils.h"
35 #include "SMESH_TypeFilter.hxx"
36 #include "SMDSAbs_ElementType.hxx"
38 // SALOME GUI includes
39 #include <LightApp_UpdateFlags.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SalomeApp_Tools.h>
43 #include <SALOME_Actor.h>
46 #include <SALOMEconfig.h>
47 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
50 #include <vtkProperty.h>
52 //================================================================================
56 * Initialize operation
58 //================================================================================
59 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
60 : SMESHGUI_SelectionOp(),
66 //================================================================================
70 //================================================================================
71 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
73 if ( myDlg ) delete myDlg;
74 if ( myBadElemsPreview ) delete myBadElemsPreview;
77 //================================================================================
79 * \brief Gets dialog of this operation
80 * \retval LightApp_Dialog* - pointer to dialog of this operation
82 //================================================================================
83 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
88 //================================================================================
90 * \brief Creates dialog if necessary and shows it
92 * Virtual method redefined from base class called when operation is started creates
93 * dialog if necessary and shows it, activates selection
95 //================================================================================
96 void SMESHGUI_ConvToQuadOp::startOperation()
100 myDlg = new SMESHGUI_ConvToQuadDlg( );
102 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
104 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
106 SMESHGUI_SelectionOp::startOperation();
108 myDlg->SetMediumNdsOnGeom( false );
109 myDlg->activateObject( 0 );
110 myDlg->ShowWarning( false );
116 //================================================================================
118 * \brief Updates dialog's look and feel
120 * Virtual method redefined from the base class updates dialog's look and feel
122 //================================================================================
123 void SMESHGUI_ConvToQuadOp::selectionDone()
125 if ( !dlg()->isVisible() )
128 SMESHGUI_SelectionOp::selectionDone();
131 QString anObjEntry = myDlg->selectedObject( 0 );
132 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
135 SMESH::SMESH_IDSource_var idSource =
136 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
138 myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply );
139 if( idSource->_is_nil() )
141 myDlg->SetEnabledControls( false );
142 myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
145 MeshType meshType = ConsistMesh( idSource );
146 if( meshType == SMESHGUI_ConvToQuadOp::Quadratic )
148 myDlg->SetEnabledRB( 0, false );
150 else if( meshType == SMESHGUI_ConvToQuadOp::Linear )
152 myDlg->SetEnabledRB( 1, false );
156 myDlg->SetEnabledControls( true );
159 // show warning on non-conformal result mesh
160 if ( ! idSource->_is_nil() )
162 SMESH::SMESH_subMesh_var subMesh =
163 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
165 if ( !subMesh->_is_nil() )
167 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
168 idSource = SMESH::SMESH_IDSource::_narrow( mesh );
169 MeshType fullMeshType = ConsistMesh( idSource );
170 toShow = ( fullMeshType != Comp );
172 myDlg->ShowWarning( toShow );
175 catch ( const SALOME::SALOME_Exception& S_ex )
177 SalomeApp_Tools::QtCatchCorbaException( S_ex );
184 //================================================================================
186 * \brief Creates selection filter
187 * \param theId - identifier of current selection widget
188 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
190 * Creates selection filter in accordance with identifier of current selection widget
192 //================================================================================
193 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
196 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
201 //================================================================================
205 * Virtual slot redefined from the base class called when "Apply" button is clicked
207 //================================================================================
208 bool SMESHGUI_ConvToQuadOp::onApply()
210 SUIT_OverrideCursor aWaitCursor;
214 QString anObjEntry = myDlg->selectedObject( 0 );
215 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
219 SUIT_MessageBox::warning( myDlg,
220 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
224 SMESH::SMESH_Mesh_var mesh;
225 SMESH::SMESH_IDSource_var idSource =
226 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
227 if( !CORBA::is_nil(idSource) )
228 mesh = idSource->GetMesh();
230 if( CORBA::is_nil(mesh) )
232 SUIT_MessageBox::warning( myDlg,
233 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
237 bool aResult = false;
241 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
243 SMESH::SMESH_Mesh_var sourceMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pObj );
244 if( !myDlg->CurrentRB() )
247 if( myDlg->IsEnabledCheck() )
248 force3d = myDlg->IsMediumNdsOnGeom();
250 if ( sourceMesh->_is_nil() )
251 aEditor->ConvertToQuadraticObject( force3d, idSource );
253 aEditor->ConvertToQuadratic( force3d );
257 SMESH::ComputeError_var error = aEditor->GetLastError();
258 if ( error->hasBadMesh )
260 if ( myBadElemsPreview ) delete myBadElemsPreview; // viewWindow may change
261 myBadElemsPreview = new SMESHGUI_MeshEditPreview( viewWindow() );
263 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
264 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
265 vtkProperty* prop = vtkProperty::New();
266 prop->SetLineWidth( aLineWidth * 3 );
267 prop->SetPointSize( aPointSize * 3 );
268 prop->SetColor( 250, 0, 250 );
269 myBadElemsPreview->GetActor()->SetProperty( prop );
272 SMESH::MeshPreviewStruct_var previewData = aEditor->GetPreviewData();
273 myBadElemsPreview->SetData( & previewData.in() );
274 myBadElemsPreview->SetVisibility(true);
276 SUIT_MessageBox* mb = new SUIT_MessageBox(SUIT_MessageBox::Warning,
277 tr( "SMESH_WRN_WARNING" ),
278 tr("EDITERR_NO_MEDIUM_ON_GEOM"),
279 SUIT_MessageBox::Ok, myDlg);
280 mb->setWindowModality( Qt::NonModal );
281 mb->setAttribute( Qt::WA_DeleteOnClose );
283 connect ( mb, SIGNAL( finished(int) ), this, SLOT( onWarningWinFinished() ));
284 //connect ( mb, SIGNAL( rejected() ), this, SLOT( onWarningWinFinished() ));
290 if ( sourceMesh->_is_nil() )
291 aEditor->ConvertFromQuadraticObject( idSource );
293 aEditor->ConvertFromQuadratic();
296 catch ( const SALOME::SALOME_Exception& S_ex )
298 SalomeApp_Tools::QtCatchCorbaException( S_ex );
307 SMESHGUI::Modified();
308 update( UF_ObjBrowser | UF_Model | UF_Viewer );
314 //================================================================================
316 * \brief SLOT called when a warning window is closed
318 //================================================================================
320 void SMESHGUI_ConvToQuadOp::onWarningWinFinished()
322 if ( myBadElemsPreview )
323 myBadElemsPreview->SetVisibility(false);
326 //================================================================================
328 * Determines, what elements this mesh contains.
330 //================================================================================
331 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_IDSource_var& idSource) const
333 SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo();
334 bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge ] ||
335 nbElemOfType[SMDSEntity_Quad_Triangle ] ||
336 nbElemOfType[SMDSEntity_Quad_Quadrangle] ||
337 nbElemOfType[SMDSEntity_Quad_Tetra ] ||
338 nbElemOfType[SMDSEntity_Quad_Hexa ] ||
339 nbElemOfType[SMDSEntity_Quad_Pyramid ] ||
340 nbElemOfType[SMDSEntity_Quad_Penta ] );
342 bool hasLin = ( nbElemOfType[SMDSEntity_Edge ] ||
343 nbElemOfType[SMDSEntity_Triangle ] ||
344 nbElemOfType[SMDSEntity_Quadrangle] ||
345 nbElemOfType[SMDSEntity_Tetra ] ||
346 nbElemOfType[SMDSEntity_Hexa ] ||
347 nbElemOfType[SMDSEntity_Pyramid ] ||
348 nbElemOfType[SMDSEntity_Penta ] );
350 if ( hasQuad && hasLin )
352 return hasQuad ? Quadratic : Linear;
355 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
357 QString anObjEntry = myDlg->selectedObject( 0 );
358 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
361 SMESH::SMESH_IDSource_var idSource =
362 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
363 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
365 bool hasGeom = mesh->HasShapeToMesh();
368 myDlg->SetEnabledCheck( false );
370 myDlg->SetEnabledCheck( true );