From: eap Date: Thu, 4 May 2006 09:29:29 +0000 (+0000) Subject: Implement ConvertFromQuadratic() operation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=12375208ad9547375fad5e0371eba0716bb76edc;p=modules%2Fsmesh.git Implement ConvertFromQuadratic() operation --- diff --git a/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.cxx b/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.cxx index ab2e10111..1f5324781 100644 --- a/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.cxx @@ -34,6 +34,8 @@ #include #include #include +#include +#include SMESHGUI_ConvToQuadDlg::SMESHGUI_ConvToQuadDlg() : SMESHGUI_Dialog( 0, false, true ) @@ -50,12 +52,26 @@ SMESHGUI_ConvToQuadDlg::SMESHGUI_ConvToQuadDlg() createObject( tr( "MESH" ), aGrp, 0 ); //Create check box - myMedNdsOnGeom = new QCheckBox( tr( "MEDIUMNDS" ), mainFrame() ); + myMedNdsOnGeom = new QCheckBox( tr( "MEDIUMNDS" ), mainFrame() ); + + //Create RadioButtons + myBG = new QButtonGroup( 2, Qt::Vertical, "", mainFrame() ); + myBG->setExclusive( true ); + myRB1 = new QRadioButton( myBG ); + myRB1->setText( tr( "RADIOBTN_1" ) ); + myRB1->setChecked( true ); + + myRB2 = new QRadioButton( myBG ); + myRB2->setText( tr( "RADIOBTN_2" ) ); + // Fill layout QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 5, 5 ); aLay->addWidget( aGrp ); aLay->addWidget( myMedNdsOnGeom ); + aLay->addWidget( myBG ); + + connect(myBG, SIGNAL( clicked( int ) ), this, SIGNAL( onClicked( int ) ) ); } SMESHGUI_ConvToQuadDlg::~SMESHGUI_ConvToQuadDlg() @@ -77,7 +93,38 @@ bool SMESHGUI_ConvToQuadDlg::IsEnabledCheck() const return myMedNdsOnGeom->isEnabled(); } -void SMESHGUI_ConvToQuadDlg::SetEnabledCheck(const bool theCheck) +void SMESHGUI_ConvToQuadDlg::SetEnabledCheck( const bool theCheck ) { - myMedNdsOnGeom->setEnabled(theCheck); + myMedNdsOnGeom->setEnabled( theCheck ); } + +int SMESHGUI_ConvToQuadDlg::CurrentRB( ) +{ + return myBG->selectedId(); +} + +void SMESHGUI_ConvToQuadDlg::SetEnabledControls( const bool theCheck ) +{ + myBG->setEnabled( theCheck ); + myMedNdsOnGeom->setEnabled( theCheck ); + setButtonEnabled( theCheck, QtxDialog::OK | QtxDialog::Apply ); +} + +void SMESHGUI_ConvToQuadDlg::SetEnabledRB( const int idx, const bool theCheck ) +{ + if(idx) + { + myRB2->setEnabled( theCheck ); + myRB1->setEnabled( !theCheck ); + myRB1->setChecked( true ); + } + else + { + myRB1->setEnabled( theCheck ); + myRB2->setEnabled( !theCheck ); + myRB2->setChecked( true ); + } + emit onClicked( myBG->selectedId() ); +} + + diff --git a/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.h b/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.h index 863a96826..596b823a7 100644 --- a/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.h +++ b/src/SMESHGUI/SMESHGUI_ConvToQuadDlg.h @@ -42,6 +42,8 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) class QCheckBox; +class QRadioButton; +class QButtonGroup; class SMESHGUI_ConvToQuadDlg : public SMESHGUI_Dialog { @@ -54,11 +56,22 @@ public: bool IsMediumNdsOnGeom() const; void SetMediumNdsOnGeom(const bool theCheck); bool IsEnabledCheck() const; - void SetEnabledCheck(const bool theCheck); - + void SetEnabledCheck( const bool theCheck ); + void SetEnabledGroup( const bool theCheck ); + void SetEnabledControls( const bool theCheck ); + void SetEnabledRB( const int idx, const bool theCheck ); + int CurrentRB();//returns the ID of the selected toggle button + +signals: + void onClicked( int ); + private: QCheckBox* myMedNdsOnGeom; + QButtonGroup* myBG; + QRadioButton* myRB1; + QRadioButton* myRB2; + }; #endif diff --git a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx index f779cb2c8..a88743f2f 100644 --- a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx +++ b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.cxx @@ -91,6 +91,8 @@ void SMESHGUI_ConvToQuadOp::startOperation() { myDlg = new SMESHGUI_ConvToQuadDlg( ); } + connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) ); + SMESHGUI_SelectionOp::startOperation(); myDlg->SetMediumNdsOnGeom( false ); @@ -122,23 +124,21 @@ void SMESHGUI_ConvToQuadOp::selectionDone() SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface( pMesh ); - GEOM::GEOM_Object_var mainGeom; - mainGeom = mesh->GetShapeToMesh(); - - if( mesh->_is_nil() || - ( !mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR) && - !mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR) && - !mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR) ) ) + if( mesh->_is_nil() ) { - myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply ); - myDlg->SetEnabledCheck( false ); + myDlg->SetEnabledControls( false ); + } + else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Quadratic ) + { + myDlg->SetEnabledRB( 0, false ); + } + else if( ConsistMesh( mesh ) == SMESHGUI_ConvToQuadOp::Linear ) + { + myDlg->SetEnabledRB( 1, false ); } - else if( mainGeom->_is_nil() && myDlg->IsEnabledCheck() ) - myDlg->SetEnabledCheck( false ); else { - myDlg->setButtonEnabled( true, QtxDialog::OK | QtxDialog::Apply ); - myDlg->SetEnabledCheck( true ); + myDlg->SetEnabledControls( true ); } } catch ( const SALOME::SALOME_Exception& S_ex ) @@ -205,13 +205,20 @@ bool SMESHGUI_ConvToQuadOp::onApply() try { - bool aParam = true; - if( myDlg->IsEnabledCheck() ) - aParam = myDlg->IsMediumNdsOnGeom(); - SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor(); - aEditor->ConvertToQuadratic( aParam ); - aResult = true; + if( !myDlg->CurrentRB() ) + { + bool aParam = true; + if( myDlg->IsEnabledCheck() ) + aParam = myDlg->IsMediumNdsOnGeom(); + + aEditor->ConvertToQuadratic( aParam ); + aResult = true; + } + else + { + aResult = aEditor->ConvertFromQuadratic(); + } } catch ( const SALOME::SALOME_Exception& S_ex ) { @@ -222,11 +229,58 @@ bool SMESHGUI_ConvToQuadOp::onApply() { aResult = false; } - if(aResult) + if( aResult ) { - update( UF_ObjBrowser | UF_Model ); - myDlg->setButtonEnabled( false, QtxDialog::Apply ); + update( UF_ObjBrowser | UF_Model | UF_Viewer ); + selectionDone(); } return aResult; } +//================================================================================ +/*! ConsistMesh + * Determines, what elements this mesh contains. + */ +//================================================================================ +SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_Mesh_var& mesh) const +{ + int nbAllElem = 0, nbQEdges =0, nbQFaces =0, nbQVolum = 0; + int nbEdges = 0, nbFaces = 0, nbVolum = 0; + + nbAllElem = (int)mesh->NbElements(); + nbQEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_QUADRATIC); + nbQFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_QUADRATIC); + nbQVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_QUADRATIC); + + nbEdges = (int)mesh->NbEdgesOfOrder(SMESH::ORDER_LINEAR); + nbFaces = (int)mesh->NbFacesOfOrder(SMESH::ORDER_LINEAR); + nbVolum = (int)mesh->NbVolumesOfOrder(SMESH::ORDER_LINEAR); + + if( nbAllElem == (nbQEdges+nbQFaces+nbQVolum) ) + return SMESHGUI_ConvToQuadOp::Quadratic; + else if ( nbAllElem == (nbEdges+nbFaces+nbVolum) ) + return SMESHGUI_ConvToQuadOp::Linear; + else + return SMESHGUI_ConvToQuadOp::Comp; +} + + +void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id ) +{ + QString anMeshEntry = myDlg->selectedObject( 0 ); + _PTR(SObject) pMesh = studyDS()->FindObjectID( anMeshEntry.latin1() ); + if ( !pMesh ) return; + + SMESH::SMESH_Mesh_var mesh = + SMESH::SObjectToInterface( pMesh ); + + GEOM::GEOM_Object_var mainGeom; + mainGeom = mesh->GetShapeToMesh(); + + if( id || mainGeom->_is_nil() ) + myDlg->SetEnabledCheck( false ); + else + myDlg->SetEnabledCheck( true ); +} + + diff --git a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.h b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.h index c6b9ff5c6..bc862f97b 100644 --- a/src/SMESHGUI/SMESHGUI_ConvToQuadOp.h +++ b/src/SMESHGUI/SMESHGUI_ConvToQuadOp.h @@ -42,8 +42,9 @@ class SMESHGUI_ConvToQuadDlg; class SMESHGUI_ConvToQuadOp : public SMESHGUI_SelectionOp { Q_OBJECT - - // enum HypType{ Algo = 0, MainHyp, AddHyp }; + +public: +enum MeshType{ Comp = 0, Linear, Quadratic }; public: SMESHGUI_ConvToQuadOp(); @@ -55,12 +56,14 @@ protected: virtual void startOperation(); virtual void selectionDone(); virtual SUIT_SelectionFilter* createFilter( const int ) const; + MeshType ConsistMesh( const SMESH::SMESH_Mesh_var& ) const; protected slots: virtual bool onApply(); + void ConnectRadioButtons( int); private: - SMESHGUI_ConvToQuadDlg* myDlg; + SMESHGUI_ConvToQuadDlg* myDlg; }; #endif diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index 0bb49ce4b..44adb6e45 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -2216,7 +2216,7 @@ msgid "MEN_MAP" msgstr "Pattern mapping" msgid "MEN_CONV_TO_QUAD" -msgstr "Convert to quadratic" +msgstr "Convert to/from quadratic" msgid "MEN_EXTRUSION_ALONG" msgstr "Extrusion along a path" @@ -2569,7 +2569,7 @@ msgid "TOP_MAP" msgstr "Pattern mapping" msgid "TOP_CONV_TO_QUAD" -msgstr "Convert to quadratic" +msgstr "Convert to/from quadratic" msgid "TOP_EXTRUSION_ALONG" msgstr "Extrusion along a path" @@ -2873,7 +2873,7 @@ msgid "STB_MAP" msgstr "Pattern mapping" msgid "STB_CONV_TO_QUAD" -msgstr "Convert to quadratic" +msgstr "Convert to/from quadratic" msgid "STB_EXTRUSION_ALONG" msgstr "Extrusion along a path" @@ -3177,7 +3177,7 @@ msgstr "Mesh is not defined\nPlease specify it and try again" #----------------------------------------------------------- msgid "SMESHGUI_ConvToQuadDlg::CAPTION" -msgstr "Convert to quadratic" +msgstr "Convert to/from quadratic" msgid "SMESHGUI_ConvToQuadDlg::MESH" msgstr "Mesh" @@ -3185,6 +3185,12 @@ msgstr "Mesh" msgid "SMESHGUI_ConvToQuadDlg::MEDIUMNDS" msgstr "Medium nodes on geometry" +msgid "SMESHGUI_ConvToQuadDlg::RADIOBTN_1" +msgstr "Convert to quadratic" + +msgid "SMESHGUI_ConvToQuadDlg::RADIOBTN_2" +msgstr "Convert from quadratic" + msgid "SMESHGUI_ConvToQuadOp::MESH_IS_NOT_SELECTED" msgstr "Mesh is not selected\nPlease specify it and try again"