1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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.html";
106 SMESHGUI_SelectionOp::startOperation();
108 myDlg->SetMediumNdsOnGeom( true );
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 = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().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 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
146 bool hasGeom = mesh->HasShapeToMesh();
147 MeshDestinationType meshTgtType = DestinationMesh( idSource );
148 myDlg->SetEnabledRB( meshTgtType, hasGeom && ( meshTgtType & ( BiQuadratic | Quadratic )));
150 // show warning on non-conformal result mesh
151 if ( ! idSource->_is_nil() )
153 SMESH::SMESH_subMesh_var subMesh =
154 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
156 if ( !subMesh->_is_nil() )
158 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
159 idSource = SMESH::SMESH_IDSource::_narrow( mesh );
161 DestinationMesh( idSource, &isMixOrder );
162 toShow = !isMixOrder;
164 myDlg->ShowWarning( toShow );
167 catch ( const SALOME::SALOME_Exception& S_ex )
169 SalomeApp_Tools::QtCatchCorbaException( S_ex );
176 //================================================================================
178 * \brief Creates selection filter
179 * \param theId - identifier of current selection widget
180 * \retval SUIT_SelectionFilter* - pointer to the created filter or null
182 * Creates selection filter in accordance with identifier of current selection widget
184 //================================================================================
185 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
188 return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
193 //================================================================================
197 * Virtual slot redefined from the base class called when "Apply" button is clicked
199 //================================================================================
200 bool SMESHGUI_ConvToQuadOp::onApply()
202 SUIT_OverrideCursor aWaitCursor;
206 QString anObjEntry = myDlg->selectedObject( 0 );
207 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
211 SUIT_MessageBox::warning( myDlg,
212 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
216 SMESH::SMESH_Mesh_var mesh;
217 SMESH::SMESH_IDSource_var idSource =
218 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
219 if( !CORBA::is_nil(idSource) )
220 mesh = idSource->GetMesh();
222 if( CORBA::is_nil(mesh) )
224 SUIT_MessageBox::warning( myDlg,
225 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
229 bool aResult = false;
233 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
235 SMESH::SMESH_Mesh_var sourceMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pObj );
236 if( myDlg->CurrentRB()==1 || myDlg->CurrentRB()==2)
239 if( myDlg->IsEnabledCheck() )
240 force3d = myDlg->IsMediumNdsOnGeom();
241 bool theToBiQuad = myDlg->IsBiQuadratic();
242 if ( sourceMesh->_is_nil() ) {
243 if ( theToBiQuad ) aEditor->ConvertToBiQuadratic ( force3d, idSource );
244 else aEditor->ConvertToQuadraticObject( force3d, idSource );
247 if ( theToBiQuad ) aEditor->ConvertToBiQuadratic( force3d, sourceMesh );
248 else aEditor->ConvertToQuadratic ( force3d );
252 SMESH::ComputeError_var error = aEditor->GetLastError();
253 if ( error->hasBadMesh )
255 if ( myBadElemsPreview ) delete myBadElemsPreview; // viewWindow may change
256 myBadElemsPreview = new SMESHGUI_MeshEditPreview( viewWindow() );
258 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
259 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
260 vtkProperty* prop = vtkProperty::New();
261 prop->SetLineWidth( aLineWidth * 3 );
262 prop->SetPointSize( aPointSize * 3 );
263 prop->SetColor( 250, 0, 250 );
264 myBadElemsPreview->GetActor()->SetProperty( prop );
267 SMESH::MeshPreviewStruct_var previewData = aEditor->GetPreviewData();
268 myBadElemsPreview->SetData( previewData.in() );
269 myBadElemsPreview->SetVisibility(true);
271 SUIT_MessageBox* mb = new SUIT_MessageBox(SUIT_MessageBox::Warning,
272 tr( "SMESH_WRN_WARNING" ),
273 tr("EDITERR_NO_MEDIUM_ON_GEOM"),
274 SUIT_MessageBox::Ok, myDlg);
275 mb->setWindowModality( Qt::NonModal );
276 mb->setAttribute( Qt::WA_DeleteOnClose );
278 connect ( mb, SIGNAL( finished(int) ), this, SLOT( onWarningWinFinished() ));
279 //connect ( mb, SIGNAL( rejected() ), this, SLOT( onWarningWinFinished() ));
285 if ( sourceMesh->_is_nil() )
286 aEditor->ConvertFromQuadraticObject( idSource );
288 aEditor->ConvertFromQuadratic();
291 catch ( const SALOME::SALOME_Exception& S_ex )
293 SalomeApp_Tools::QtCatchCorbaException( S_ex );
302 SMESHGUI::Modified();
303 update( UF_ObjBrowser | UF_Model | UF_Viewer );
309 //================================================================================
311 * \brief SLOT called when a warning window is closed
313 //================================================================================
315 void SMESHGUI_ConvToQuadOp::onWarningWinFinished()
317 if ( myBadElemsPreview )
318 myBadElemsPreview->SetVisibility(false);
321 //================================================================================
323 * Determines, what elements this mesh does not contain.
325 //================================================================================
327 SMESHGUI_ConvToQuadOp::MeshDestinationType
328 SMESHGUI_ConvToQuadOp::DestinationMesh( const SMESH::SMESH_IDSource_var& idSource,
331 SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo();
333 bool hasBiQuad = ( nbElemOfType[SMDSEntity_BiQuad_Triangle ] ||
334 nbElemOfType[SMDSEntity_BiQuad_Quadrangle ] ||
335 nbElemOfType[SMDSEntity_BiQuad_Penta ] ||
336 nbElemOfType[SMDSEntity_TriQuad_Hexa ] );
337 bool hasLinBiQuad = ( nbElemOfType[SMDSEntity_Triangle ] ||
338 nbElemOfType[SMDSEntity_Quadrangle ] ||
339 nbElemOfType[SMDSEntity_Hexa ] );
340 bool hasQuadBiQuad = ( nbElemOfType[SMDSEntity_Quad_Triangle ] ||
341 nbElemOfType[SMDSEntity_Quad_Quadrangle ] ||
342 nbElemOfType[SMDSEntity_Quad_Hexa ] );
344 bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge ] ||
345 nbElemOfType[SMDSEntity_Quad_Triangle ] ||
346 nbElemOfType[SMDSEntity_Quad_Quadrangle] ||
347 nbElemOfType[SMDSEntity_Quad_Tetra ] ||
348 nbElemOfType[SMDSEntity_Quad_Hexa ] ||
349 nbElemOfType[SMDSEntity_Quad_Pyramid ] ||
350 nbElemOfType[SMDSEntity_Quad_Polygon ] ||
351 nbElemOfType[SMDSEntity_Quad_Penta ] );
353 bool hasLin = ( nbElemOfType[SMDSEntity_Edge ] ||
354 nbElemOfType[SMDSEntity_Triangle ] ||
355 nbElemOfType[SMDSEntity_Quadrangle] ||
356 nbElemOfType[SMDSEntity_Tetra ] ||
357 nbElemOfType[SMDSEntity_Hexa ] ||
358 nbElemOfType[SMDSEntity_Pyramid ] ||
359 nbElemOfType[SMDSEntity_Polygon ] ||
360 nbElemOfType[SMDSEntity_Penta ] );
364 tgtType |= ( Quadratic | Linear );
366 tgtType |= ( BiQuadratic | Quadratic );
368 tgtType |= ( BiQuadratic | Linear );
372 tgtType |= Quadratic;
378 *isMixOrder = ( hasLin && ( hasQuad || hasBiQuad ));
380 return MeshDestinationType( tgtType );
383 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
385 QString anObjEntry = myDlg->selectedObject( 0 );
386 _PTR(SObject) pObj = SMESH::getStudy()->FindObjectID( anObjEntry.toUtf8().data() );
389 SMESH::SMESH_IDSource_var idSource =
390 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
391 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
393 bool hasGeom = mesh->HasShapeToMesh();
395 if( id==0 || !hasGeom )
396 myDlg->SetEnabledCheck( false );
398 myDlg->SetEnabledCheck( true );