Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_ConvToQuadOp.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_ConvToQuadDlg.h"
00032 #include "SMESHGUI_Utils.h"
00033 #include "SMDSAbs_ElementType.hxx"
00034
00035 #include "SMESH_TypeFilter.hxx"
00036
00037
00038 #include <LightApp_UpdateFlags.h>
00039 #include <SUIT_MessageBox.h>
00040 #include <SUIT_OverrideCursor.h>
00041 #include <SalomeApp_Tools.h>
00042
00043
00044 #include <SALOMEconfig.h>
00045 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00046
00047
00053
00054 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
00055 : SMESHGUI_SelectionOp(),
00056 myDlg( 0 )
00057 {
00058 }
00059
00060
00064
00065 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
00066 {
00067 if ( myDlg )
00068 delete myDlg;
00069 }
00070
00071
00076
00077 LightApp_Dialog* SMESHGUI_ConvToQuadOp::dlg() const
00078 {
00079 return myDlg;
00080 }
00081
00082
00089
00090 void SMESHGUI_ConvToQuadOp::startOperation()
00091 {
00092 if( !myDlg )
00093 {
00094 myDlg = new SMESHGUI_ConvToQuadDlg( );
00095 }
00096 connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
00097
00098 myHelpFileName = "convert_to_from_quadratic_mesh_page.html";
00099
00100 SMESHGUI_SelectionOp::startOperation();
00101
00102 myDlg->SetMediumNdsOnGeom( false );
00103 myDlg->activateObject( 0 );
00104 myDlg->ShowWarning( false );
00105 myDlg->show();
00106
00107 selectionDone();
00108 }
00109
00110
00116
00117 void SMESHGUI_ConvToQuadOp::selectionDone()
00118 {
00119 if ( !dlg()->isVisible() )
00120 return;
00121
00122 SMESHGUI_SelectionOp::selectionDone();
00123 try
00124 {
00125 QString anObjEntry = myDlg->selectedObject( 0 );
00126 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
00127 if ( !pObj ) return;
00128
00129 SMESH::SMESH_IDSource_var idSource =
00130 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
00131
00132 myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply );
00133 if( idSource->_is_nil() )
00134 {
00135 myDlg->SetEnabledControls( false );
00136 myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
00137 return;
00138 }
00139 MeshType meshType = ConsistMesh( idSource );
00140 if( meshType == SMESHGUI_ConvToQuadOp::Quadratic )
00141 {
00142 myDlg->SetEnabledRB( 0, false );
00143 }
00144 else if( meshType == SMESHGUI_ConvToQuadOp::Linear )
00145 {
00146 myDlg->SetEnabledRB( 1, false );
00147 }
00148 else
00149 {
00150 myDlg->SetEnabledControls( true );
00151 }
00152
00153
00154 if ( ! idSource->_is_nil() )
00155 {
00156 SMESH::SMESH_subMesh_var subMesh =
00157 SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( pObj );
00158 bool toShow = false;
00159 if ( !subMesh->_is_nil() )
00160 {
00161 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
00162 idSource = SMESH::SMESH_IDSource::_narrow( mesh );
00163 MeshType fullMeshType = ConsistMesh( idSource );
00164 toShow = ( fullMeshType != Comp );
00165 }
00166 myDlg->ShowWarning( toShow );
00167 }
00168 }
00169 catch ( const SALOME::SALOME_Exception& S_ex )
00170 {
00171 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00172 }
00173 catch ( ... )
00174 {
00175 }
00176 }
00177
00178
00186
00187 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
00188 {
00189 if ( theId == 0 )
00190 return new SMESH_TypeFilter( MESHorSUBMESH );
00191 else
00192 return 0;
00193 }
00194
00195
00201
00202 bool SMESHGUI_ConvToQuadOp::onApply()
00203 {
00204 SUIT_OverrideCursor aWaitCursor;
00205
00206 QString aMess;
00207
00208 QString anObjEntry = myDlg->selectedObject( 0 );
00209 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
00210 if ( !pObj )
00211 {
00212 dlg()->show();
00213 SUIT_MessageBox::warning( myDlg,
00214 tr( "SMESH_WRN_WARNING" ), tr("MESH_IS_NOT_SELECTED") );
00215 return false;
00216 }
00217
00218 SMESH::SMESH_Mesh_var mesh;
00219 SMESH::SMESH_IDSource_var idSource =
00220 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
00221 if( !CORBA::is_nil(idSource) )
00222 mesh = idSource->GetMesh();
00223
00224 if( CORBA::is_nil(mesh) )
00225 {
00226 SUIT_MessageBox::warning( myDlg,
00227 tr( "SMESH_WRN_WARNING" ), tr("REF_IS_NULL") );
00228 return false;
00229 }
00230
00231 bool aResult = false;
00232
00233 try
00234 {
00235 SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
00236 aResult = true;
00237 SMESH::SMESH_Mesh_var sourceMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pObj );
00238 if( !myDlg->CurrentRB() )
00239 {
00240 bool aParam = true;
00241 if( myDlg->IsEnabledCheck() )
00242 aParam = myDlg->IsMediumNdsOnGeom();
00243
00244 if ( sourceMesh->_is_nil() )
00245 aEditor->ConvertToQuadraticObject( aParam, idSource );
00246 else
00247 aEditor->ConvertToQuadratic( aParam );
00248 }
00249 else
00250 {
00251 if ( sourceMesh->_is_nil() )
00252 aEditor->ConvertFromQuadraticObject( idSource );
00253 else
00254 aEditor->ConvertFromQuadratic();
00255 }
00256 }
00257 catch ( const SALOME::SALOME_Exception& S_ex )
00258 {
00259 SalomeApp_Tools::QtCatchCorbaException( S_ex );
00260 aResult = false;
00261 }
00262 catch ( ... )
00263 {
00264 aResult = false;
00265 }
00266 if( aResult )
00267 {
00268 SMESHGUI::Modified();
00269 update( UF_ObjBrowser | UF_Model | UF_Viewer );
00270 selectionDone();
00271 }
00272 return aResult;
00273 }
00274
00275
00279
00280 SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_IDSource_var& idSource) const
00281 {
00282 SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo();
00283 bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge ] ||
00284 nbElemOfType[SMDSEntity_Quad_Triangle ] ||
00285 nbElemOfType[SMDSEntity_Quad_Quadrangle] ||
00286 nbElemOfType[SMDSEntity_Quad_Tetra ] ||
00287 nbElemOfType[SMDSEntity_Quad_Hexa ] ||
00288 nbElemOfType[SMDSEntity_Quad_Pyramid ] ||
00289 nbElemOfType[SMDSEntity_Quad_Penta ] );
00290
00291 bool hasLin = ( nbElemOfType[SMDSEntity_Edge ] ||
00292 nbElemOfType[SMDSEntity_Triangle ] ||
00293 nbElemOfType[SMDSEntity_Quadrangle] ||
00294 nbElemOfType[SMDSEntity_Tetra ] ||
00295 nbElemOfType[SMDSEntity_Hexa ] ||
00296 nbElemOfType[SMDSEntity_Pyramid ] ||
00297 nbElemOfType[SMDSEntity_Penta ] );
00298
00299 if ( hasQuad && hasLin )
00300 return Comp;
00301 return hasQuad ? Quadratic : Linear;
00302 }
00303
00304 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
00305 {
00306 QString anObjEntry = myDlg->selectedObject( 0 );
00307 _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
00308 if ( !pObj ) return;
00309
00310 SMESH::SMESH_IDSource_var idSource =
00311 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( pObj );
00312 SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
00313
00314 bool hasGeom = mesh->HasShapeToMesh();
00315
00316 if( id || !hasGeom )
00317 myDlg->SetEnabledCheck( false );
00318 else
00319 myDlg->SetEnabledCheck( true );
00320 }