From 6e55d5dca63aa7d789e237979a24027d6d91c6db Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 4 Nov 2010 12:44:53 +0000 Subject: [PATCH] PAL20885 EDF 607 SMESH: Measure tools Complete Boundary Box dialog box --- src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx | 223 +++++++++++++++++++---- src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h | 63 +++++-- src/SMESHGUI/SMESHGUI_Measurements.cxx | 51 +++++- src/SMESH_I/SMESH_Measurements_i.cxx | 28 +-- src/SMESH_I/SMESH_Measurements_i.hxx | 7 +- 5 files changed, 304 insertions(+), 68 deletions(-) diff --git a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx index ffbc3b80d..e2daa3c49 100644 --- a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx +++ b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.cxx @@ -28,9 +28,12 @@ #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_MeshUtils.h" #include "SMESHGUI_MeshInfosBox.h" +#include "SMESH_TypeFilter.hxx" +#include "SMESH_LogicalFilter.hxx" // SALOME GUI includes #include +#include #include #include @@ -53,14 +56,17 @@ #include #include #include +#include #include +#include +#include #include +#include // MESH includes #include "SMDSAbs_ElementType.hxx" #include "SMDSAbs_ElementType.hxx" - #define SPACING 6 #define MARGIN 11 @@ -148,6 +154,97 @@ void SMESHGUI_Make2DFrom3DDlg::SetMeshInfo(const SMESH::long_array& theInfo) myFullInfo->SetMeshInfo( theInfo ); } +// ========================================================================================= +/*! + * \brief Copy Mesh dialog box + */ +//======================================================================= + +SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( QWidget* parent ) + : SMESHGUI_Dialog( parent, false, true, OK | Apply | Close | Help ) +{ + setWindowTitle( tr("CAPTION") ); + + // mesh + setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) ); + createObject( tr( "MESH" ), mainFrame(), Mesh ); + + // mode + QGroupBox* aModeGrp = new QGroupBox( tr( "MODE" ), mainFrame() ); + QHBoxLayout* aModeGrpLayout = new QHBoxLayout( aModeGrp ); + aModeGrpLayout->setMargin( MARGIN ); + aModeGrpLayout->setSpacing( SPACING ); + QRadioButton* a2dFrom3dRB = new QRadioButton( tr( "2D_FROM_3D" ), aModeGrp ); + QRadioButton* a1dFrom3dRB = new QRadioButton( tr( "1D_FROM_3D" ), aModeGrp ); + QRadioButton* a1dFrom2dRB = new QRadioButton( tr( "1D_FROM_2D" ), aModeGrp ); + aModeGrpLayout->addWidget( a2dFrom3dRB ); + aModeGrpLayout->addWidget( a1dFrom3dRB ); + aModeGrpLayout->addWidget( a1dFrom2dRB ); + + // target + QGroupBox* aTargetGrp = new QGroupBox( tr( "TARGET" ), mainFrame() ); + QGridLayout* aTargetGrpLayout = new QGridLayout( aTargetGrp ); + aTargetGrpLayout->setMargin( MARGIN ); + aTargetGrpLayout->setSpacing( SPACING ); + myThisMeshRB = new QRadioButton( tr( "THIS_MESH" ), aTargetGrp ); + myNewMeshRB = new QRadioButton( tr( "NEW_MESH" ), aTargetGrp ); + myMeshName = new QLineEdit( aTargetGrp ); + myCopyCheck = new QCheckBox( tr( "COPY_SRC" ), aTargetGrp ); + myMissingCheck = new QCheckBox( tr( "MISSING_ONLY" ), aTargetGrp ); + aTargetGrpLayout->addWidget( myThisMeshRB, 0, 0 ); + aTargetGrpLayout->addWidget( myNewMeshRB, 1, 0 ); + aTargetGrpLayout->addWidget( myMeshName, 1, 1 ); + aTargetGrpLayout->addWidget( myCopyCheck, 2, 0 ); + aTargetGrpLayout->addWidget( myMissingCheck, 2, 1 ); + myGroupCheck = new QCheckBox( tr( "CREATE_GROUP" ), mainFrame() ); + myGroupName = new QLineEdit( mainFrame() ); + + // layout + QGridLayout* aDlgLay = new QGridLayout( mainFrame() ); + aDlgLay->setMargin( 0 ); + aDlgLay->setSpacing( SPACING ); + aDlgLay->addWidget( objectWg( Mesh, Label ), 0, 0 ); + aDlgLay->addWidget( objectWg( Mesh, Btn ), 0, 1 ); + aDlgLay->addWidget( objectWg( Mesh, Control ), 0, 2 ); + aDlgLay->addWidget( aModeGrp, 1, 0, 1, 3 ); + aDlgLay->addWidget( aTargetGrp, 2, 0, 1, 3 ); + aDlgLay->addWidget( myGroupCheck, 3, 0 ); + aDlgLay->addWidget( myGroupName, 3, 1, 1, 2 ); + //aDlgLay->setStretchFactor(aMainFrame, 1); + + connect( myThisMeshRB, SIGNAL( clicked() ), this, SLOT( onTargetChanged() ) ); + connect( myNewMeshRB, SIGNAL( clicked() ), this, SLOT( onTargetChanged() ) ); + connect( myGroupCheck, SIGNAL( clicked() ), this, SLOT( onGroupChecked() ) ); + + a2dFrom3dRB->setChecked( true ); + myThisMeshRB->setChecked( true ); + onTargetChanged(); + onGroupChecked(); + enableControls( false ); +} + +SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg() +{ +} + +void SMESHGUI_CopyMeshDlg::enableControls( bool on ) +{ + printf("SMESHGUI_CopyMeshDlg::enableControls:%d\n",on); + setButtonEnabled( on, QtxDialog::OK | QtxDialog::Apply ); +} + +void SMESHGUI_CopyMeshDlg::onTargetChanged() +{ + myMeshName->setEnabled( myNewMeshRB->isChecked() ); + myCopyCheck->setEnabled( myNewMeshRB->isChecked() ); + myMissingCheck->setEnabled( myNewMeshRB->isChecked() ); +} + +void SMESHGUI_CopyMeshDlg::onGroupChecked() +{ + myGroupName->setEnabled( myGroupCheck->isChecked() ); +} + //================================================================================ /*! * \brief Constructor @@ -155,9 +252,8 @@ void SMESHGUI_Make2DFrom3DDlg::SetMeshInfo(const SMESH::long_array& theInfo) //================================================================================ SMESHGUI_Make2DFrom3DOp::SMESHGUI_Make2DFrom3DOp() - : SMESHGUI_Operation() + : SMESHGUI_SelectionOp() { - myDlg = new SMESHGUI_Make2DFrom3DDlg(desktop()); } //================================================================================ @@ -168,6 +264,19 @@ SMESHGUI_Make2DFrom3DOp::SMESHGUI_Make2DFrom3DOp() SMESHGUI_Make2DFrom3DOp::~SMESHGUI_Make2DFrom3DOp() { + if ( myDlg ) + delete myDlg; +} + +//================================================================================ +/*! + * \brief Gets dialog of this operation + * \retval LightApp_Dialog* - pointer to dialog of this operation +*/ +//================================================================================ +LightApp_Dialog* SMESHGUI_Make2DFrom3DOp::dlg() const +{ + return myDlg; } //================================================================================ @@ -178,39 +287,25 @@ SMESHGUI_Make2DFrom3DOp::~SMESHGUI_Make2DFrom3DOp() void SMESHGUI_Make2DFrom3DOp::startOperation() { - myMesh = SMESH::SMESH_Mesh::_nil(); - - // check selection - LightApp_SelectionMgr *Sel = selectionMgr(); - SALOME_ListIO selected; Sel->selectedObjects( selected ); + if( !myDlg ) + myDlg = new SMESHGUI_CopyMeshDlg( desktop() ); - int nbSel = selected.Extent(); - if (nbSel != 1) { - SUIT_MessageBox::warning(desktop(), - tr("SMESH_WRN_WARNING"), - tr("SMESH_WRN_NO_AVAILABLE_DATA")); - onCancel(); - return; - } - - Handle(SALOME_InteractiveObject) anIO = selected.First(); - myMesh = SMESH::GetMeshByIO(anIO); - if (myMesh->_is_nil()) { - SUIT_MessageBox::warning(desktop(), - tr("SMESH_WRN_WARNING"), - tr("SMESH_WRN_NO_AVAILABLE_DATA")); - onCancel(); - return; - } + mySrc = SMESH::SMESH_IDSource::_nil(); + + myHelpFileName = "copy_mesh_page.html"; - SMESHGUI_Operation::startOperation(); + SMESHGUI_SelectionOp::startOperation(); + myDlg->activateObject( SMESHGUI_CopyMeshDlg::Mesh ); + myDlg->show(); + selectionDone(); + /* // backup mesh info before 2D mesh computation SMESH::long_array_var anOldInfo = myMesh->GetMeshInfo(); - if (!compute2DMesh()) { + if (0){//!compute2DMesh()) { SUIT_MessageBox::warning(desktop(), tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_COMPUTE_FAILED")); @@ -229,11 +324,62 @@ void SMESHGUI_Make2DFrom3DOp::startOperation() // show computated result _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh); if ( aMeshSObj ) - myDlg->SetMeshName( aMeshSObj->GetName().c_str() ); - myDlg->SetMeshInfo( aNewInfo ); - myDlg->show(); /*exec();*/ - commit(); - SMESHGUI::Modified(); + ;//myDlg->SetMeshName( aMeshSObj->GetName().c_str() ); + //myDlg->SetMeshInfo( aNewInfo ); + myDlg->show(); + //commit(); + //SMESHGUI::Modified(); +*/ +} + +//================================================================================ +/*! + * \brief Updates dialog's look and feel + * + * Virtual method redefined from the base class updates dialog's look and feel + */ +//================================================================================ +void SMESHGUI_Make2DFrom3DOp::selectionDone() +{ + bool on = false; + if ( dlg()->isVisible() ) { + SMESHGUI_SelectionOp::selectionDone(); + try { + QString entry = myDlg->selectedObject( SMESHGUI_CopyMeshDlg::Mesh ); + _PTR(SObject) sobj = studyDS()->FindObjectID( entry.toLatin1().constData() ); + if ( sobj ) { + SMESH::SMESH_IDSource_var obj = SMESH::SObjectToInterface( sobj ); + on = !obj->_is_nil(); + } + } + catch ( const SALOME::SALOME_Exception& S_ex ) { + SalomeApp_Tools::QtCatchCorbaException( S_ex ); + } + catch ( ... ) { + } + } + myDlg->enableControls( on ); +} + +//================================================================================ +/*! + * \brief Creates selection filter + * \param theId - identifier of current selection widget + * \retval SUIT_SelectionFilter* - pointer to the created filter or null + * + * Creates selection filter in accordance with identifier of current selection widget + */ +//================================================================================ +SUIT_SelectionFilter* SMESHGUI_Make2DFrom3DOp::createFilter( const int theId ) const +{ + SUIT_SelectionFilter* f = 0; + if ( theId == SMESHGUI_CopyMeshDlg::Mesh ) { + QList filters; + filters.append( new SMESH_TypeFilter( MESHorSUBMESH ) ); + filters.append( new SMESH_TypeFilter( GROUP ) ); + f = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR ); + } + return f; } //================================================================================ @@ -244,7 +390,12 @@ void SMESHGUI_Make2DFrom3DOp::startOperation() bool SMESHGUI_Make2DFrom3DOp::compute2DMesh() { - SUIT_OverrideCursor wc; - SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); - return aMeshEditor->Make2DMeshFrom3D(); +// SUIT_OverrideCursor wc; +// SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); +// return aMeshEditor->Make2DMeshFrom3D(); +} + +bool SMESHGUI_Make2DFrom3DOp::onApply() +{ + return false; } diff --git a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h index f2ef2d9fd..028f4d6df 100644 --- a/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h +++ b/src/SMESHGUI/SMESHGUI_Make2DFrom3DOp.h @@ -28,13 +28,16 @@ #include "SMESH_SMESHGUI.hxx" #include "SMESHGUI_Dialog.h" -#include "SMESHGUI_Operation.h" +#include "SMESHGUI_SelectionOp.h" // IDL includes #include #include CORBA_SERVER_HEADER(SMESH_Mesh) class QFrame; +class QCheckBox; +class QLineEdit; +class QRadioButton; class SMESHGUI_MeshInfosBox; /*! @@ -45,41 +48,79 @@ class SMESHGUI_Make2DFrom3DDlg : public SMESHGUI_Dialog { Q_OBJECT - public: +public: SMESHGUI_Make2DFrom3DDlg( QWidget* ); virtual ~SMESHGUI_Make2DFrom3DDlg(); void SetMeshName(const QString& theName); void SetMeshInfo(const SMESH::long_array& theInfo); - private: +private: QFrame* createMainFrame( QWidget* ); - private: +private: QLabel* myMeshName; SMESHGUI_MeshInfosBox* myFullInfo; }; +/*! + * \brief Dialog to show result mesh statistic + */ + +class SMESHGUI_CopyMeshDlg : public SMESHGUI_Dialog +{ + Q_OBJECT + +public: + enum { Mesh }; + + SMESHGUI_CopyMeshDlg( QWidget* ); + virtual ~SMESHGUI_CopyMeshDlg(); + + void enableControls( bool ); + +private slots: + void onTargetChanged(); + void onGroupChecked(); + +private: + QRadioButton* myThisMeshRB; + QRadioButton* myNewMeshRB; + QLineEdit* myMeshName; + QCheckBox* myCopyCheck; + QCheckBox* myMissingCheck; + QCheckBox* myGroupCheck; + QLineEdit* myGroupName; +}; /*! * \brief Operation to compute 2D mesh on 3D */ -class SMESHGUI_Make2DFrom3DOp : public SMESHGUI_Operation +class SMESHGUI_Make2DFrom3DOp : public SMESHGUI_SelectionOp { - public: + Q_OBJECT + +public: SMESHGUI_Make2DFrom3DOp(); virtual ~SMESHGUI_Make2DFrom3DOp(); - protected: + virtual LightApp_Dialog* dlg() const; + +protected: virtual void startOperation(); + virtual void selectionDone(); + virtual SUIT_SelectionFilter* createFilter( const int ) const; + +protected slots: + virtual bool onApply(); - private: +private: bool compute2DMesh(); - private: - SMESH::SMESH_Mesh_var myMesh; - QPointer myDlg; +private: + SMESH::SMESH_IDSource_var mySrc; + QPointer myDlg; }; #endif // SMESHGUI_Make2DFrom3DOp_H diff --git a/src/SMESHGUI/SMESHGUI_Measurements.cxx b/src/SMESHGUI/SMESHGUI_Measurements.cxx index 5aef4bf35..79d56377a 100644 --- a/src/SMESHGUI/SMESHGUI_Measurements.cxx +++ b/src/SMESHGUI/SMESHGUI_Measurements.cxx @@ -341,6 +341,7 @@ void SMESHGUI_MinDistance::selectionChanged() } } } + clear(); } /*! @@ -376,7 +377,8 @@ void SMESHGUI_MinDistance::secondChanged() void SMESHGUI_MinDistance::firstEdited() { setTarget( FirstTgt ); - clear(); + if ( sender() == myFirstTgt ) + clear(); SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector(); if ( myFirstActor && selector ) { Handle(SALOME_InteractiveObject) IO = myFirstActor->getIO(); @@ -396,7 +398,8 @@ void SMESHGUI_MinDistance::firstEdited() void SMESHGUI_MinDistance::secondEdited() { setTarget( SecondTgt ); - clear(); + if ( sender() == mySecondTgt ) + clear(); SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector(); if ( mySecondActor && selector ) { Handle(SALOME_InteractiveObject) IO = mySecondActor->getIO(); @@ -723,6 +726,7 @@ void SMESHGUI_BoundingBox::selectionChanged() mySource->clear(); } } + clear(); } /*! @@ -743,7 +747,8 @@ void SMESHGUI_BoundingBox::sourceChanged() */ void SMESHGUI_BoundingBox::sourceEdited() { - clear(); + if ( sender() == mySource ) + clear(); SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector(); if ( myActor && selector ) { Handle(SALOME_InteractiveObject) IO = myActor->getIO(); @@ -751,7 +756,7 @@ void SMESHGUI_BoundingBox::sourceEdited() TColStd_MapOfInteger ID; if ( !mySource->isReadOnly() ) myIDs = mySource->text(); - QStringList ids = mySource->text().split( " ", QString::SkipEmptyParts ); + QStringList ids = myIDs.split( " ", QString::SkipEmptyParts ); foreach ( QString id, ids ) ID.Add( id.trimmed().toLong() ); selector->AddOrRemoveIndex( IO, ID, false ); @@ -767,9 +772,45 @@ void SMESHGUI_BoundingBox::sourceEdited() void SMESHGUI_BoundingBox::compute() { SUIT_OverrideCursor wc; - if ( mySourceMode->checkedId() == NodesSrc ) { + SMESH::ListOfIDSources_var srcList = new SMESH::ListOfIDSources(); + if ( mySourceMode->checkedId() == NodesSrc || mySourceMode->checkedId() == ElementsSrc ) { + if ( mySrc.count() > 0 && !CORBA::is_nil( mySrc[0] ) ) { + SMESH::SMESH_Mesh_var m = mySrc[0]->GetMesh(); + QStringList ids = myIDs.split( " ", QString::SkipEmptyParts ); + if ( !CORBA::is_nil( m ) && ids.count() > 0 ) { + SMESH::long_array_var ids_in = new SMESH::long_array(); + ids_in->length( ids.count() ); + for( int i = 0; i < ids.count(); i++ ) + ids_in[i] = ids[i].trimmed().toLong(); + SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor(); + SMESH::SMESH_IDSource_var s = me->MakeIDSource( ids_in.in(), mySourceMode->checkedId() == NodesSrc ? SMESH::NODE : SMESH::FACE ); + srcList->length( 1 ); + srcList[0] = s; + } + } } else { + srcList->length( mySrc.count() ); + for( int i = 0; i < mySrc.count(); i++ ) + srcList[i] = mySrc[i]; + } + if ( srcList->length() > 0 ) { + int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 ); + SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements(); + SMESH::Measure result = measure->BoundingBox( srcList.in() ); + measure->Destroy(); + myXmin->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myXmax->setText( QString::number( result.maxX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myDX->setText( QString::number( result.maxX-result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myYmin->setText( QString::number( result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myYmax->setText( QString::number( result.maxY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myDY->setText( QString::number( result.maxY-result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myZmin->setText( QString::number( result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myZmax->setText( QString::number( result.maxZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + myDZ->setText( QString::number( result.maxZ-result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) ); + } + else { + clear(); } } diff --git a/src/SMESH_I/SMESH_Measurements_i.cxx b/src/SMESH_I/SMESH_Measurements_i.cxx index 87946a1da..1397a4c39 100644 --- a/src/SMESH_I/SMESH_Measurements_i.cxx +++ b/src/SMESH_I/SMESH_Measurements_i.cxx @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SMESH_Measurements_i.cxx +// Author : Pavel TELKOV, Open CASCADE S.A.S. (pavel.telkov@opencascade.com) -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses -// File : SMESH_Filter_i.cxx -// Author : Alexey Petrov, OCC -// Module : SMESH -// #include "SMESH_Measurements_i.hxx" #include "SMESH_Gen_i.hxx" @@ -196,12 +193,21 @@ static void enlargeBoundingBox(const SMDS_MeshNode* theNode, { if (!theNode) return; - theMeasure.minX = min( theMeasure.minX, theNode->X() ); - theMeasure.maxX = max( theMeasure.maxX, theNode->X() ); - theMeasure.minY = min( theMeasure.minY, theNode->Y() ); - theMeasure.maxY = max( theMeasure.maxY, theNode->Y() ); - theMeasure.minZ = min( theMeasure.minZ, theNode->Z() ); - theMeasure.maxZ = max( theMeasure.maxZ, theNode->Z() ); + if ( theMeasure.node1 == -1 ) { + // we use this attribute as a flag that it is the first node added to the bnd box + theMeasure.minX = theMeasure.maxX = theNode->X(); + theMeasure.minY = theMeasure.maxY = theNode->Y(); + theMeasure.minZ = theMeasure.maxZ = theNode->Z(); + theMeasure.node1 = theNode->GetID(); + } + else { + theMeasure.minX = min( theMeasure.minX, theNode->X() ); + theMeasure.maxX = max( theMeasure.maxX, theNode->X() ); + theMeasure.minY = min( theMeasure.minY, theNode->Y() ); + theMeasure.maxY = max( theMeasure.maxY, theNode->Y() ); + theMeasure.minZ = min( theMeasure.minZ, theNode->Z() ); + theMeasure.maxZ = max( theMeasure.maxZ, theNode->Z() ); + } } //======================================================================= diff --git a/src/SMESH_I/SMESH_Measurements_i.hxx b/src/SMESH_I/SMESH_Measurements_i.hxx index 899d5bc7e..0e1d77dcf 100644 --- a/src/SMESH_I/SMESH_Measurements_i.hxx +++ b/src/SMESH_I/SMESH_Measurements_i.hxx @@ -19,12 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses // File : SMESH_Measurements_i.hxx -// Author : Pavel Telkov, OCC -// Module : SMESH -// +// Author : Pavel TELKOV, Open CASCADE S.A.S. (pavel.telkov@opencascade.com) + #ifndef _SMESH_MEASUREMENTS_I_HXX_ #define _SMESH_MEASUREMENTS_I_HXX_ -- 2.39.2