From 394989fdce570a0e947dc6795413e1acf2c8675e Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 26 Jun 2008 13:01:15 +0000 Subject: [PATCH] VISU 2008 - Evolution of the VISU selection functionality --- src/VISUGUI/Makefile.am | 2 + src/VISUGUI/VISU_msg_en.ts | 27 ++ src/VISUGUI/VisuGUI_FindPane.cxx | 364 ++++++++++++++++++ src/VISUGUI/VisuGUI_FindPane.h | 94 +++++ .../VisuGUI_GaussPointsSelectionPane.cxx | 65 +++- .../VisuGUI_GaussPointsSelectionPane.h | 18 +- src/VISUGUI/VisuGUI_SelectionPanel.cxx | 77 +++- src/VISUGUI/VisuGUI_SelectionPanel.h | 6 +- 8 files changed, 612 insertions(+), 41 deletions(-) create mode 100644 src/VISUGUI/VisuGUI_FindPane.cxx create mode 100644 src/VISUGUI/VisuGUI_FindPane.h diff --git a/src/VISUGUI/Makefile.am b/src/VISUGUI/Makefile.am index c61d27af..9132d0b2 100644 --- a/src/VISUGUI/Makefile.am +++ b/src/VISUGUI/Makefile.am @@ -45,6 +45,7 @@ dist_libVISU_la_SOURCES= \ VisuGUI_SelectionPanel.cxx \ VisuGUI_SelectionPrefDlg.cxx \ VisuGUI_GaussPointsSelectionPane.cxx \ + VisuGUI_FindPane.cxx \ VisuGUI_Tools.cxx \ VisuGUI_ViewTools.cxx \ VisuGUI_Selection.cxx \ @@ -88,6 +89,7 @@ MOC_FILES= \ VisuGUI_SelectionPanel_moc.cxx \ VisuGUI_SelectionPrefDlg_moc.cxx \ VisuGUI_GaussPointsSelectionPane_moc.cxx \ + VisuGUI_FindPane_moc.cxx \ VisuGUI_NameDlg_moc.cxx \ VisuGUI_FileDlg_moc.cxx \ VisuGUI_CursorDlg_moc.cxx \ diff --git a/src/VISUGUI/VISU_msg_en.ts b/src/VISUGUI/VISU_msg_en.ts index a8b14e80..28309a2f 100644 --- a/src/VISUGUI/VISU_msg_en.ts +++ b/src/VISUGUI/VISU_msg_en.ts @@ -1727,6 +1727,33 @@ Please, provide non-empty resulting presentation. Full loading for current file + + VisuGUI_FindPane + + BETWEEN + Between + + + CONDITION + Where scalar value is: + + + FIND_TITLE + Find + + + INCORRECT_VALUES + Input values are incorrect + + + MAXIMUM + Maximum + + + MINIMUM + Minimum + + VisuGUI_FontWg diff --git a/src/VISUGUI/VisuGUI_FindPane.cxx b/src/VISUGUI/VisuGUI_FindPane.cxx new file mode 100644 index 00000000..f9df959e --- /dev/null +++ b/src/VISUGUI/VisuGUI_FindPane.cxx @@ -0,0 +1,364 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : VisuGUI_FindPane.cxx +// Author : Oleg Uvarov +// Module : VISU + +#include "VisuGUI_FindPane.h" +#include "VisuGUI_Tools.h" + +#include "VISU_Actor.h" +#include "VISU_Event.h" +#include "VISU_GaussPtsAct.h" + +#include "VISU_IDMapper.hxx" +#include "VISU_GaussPointsPL.hxx" + +#include "SUIT_MessageBox.h" +#include "SUIT_ResourceMgr.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define PAGE_SIZE 10 + +VisuGUI_FindPane::VisuGUI_FindPane( QWidget* theParent ) : + QGroupBox( theParent ), + myCurrentPage( 0 ), + myActor( 0 ) +{ + setTitle( tr( "FIND_TITLE" ) ); + + QGridLayout* aTopLayout = new QGridLayout( this ); + + QLabel* aConditionLabel = new QLabel( tr( "CONDITION" ), this ); + + myConditionBox = new QComboBox( this ); + myConditionBox->addItems( QStringList() + << tr( "MINIMUM" ) + << tr( "MAXIMUM" ) + << "=" + << "<=" + << ">=" + << tr( "BETWEEN" ) ); + + connect( myConditionBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onConditionChanged( int ) ) ); + + QDoubleValidator* aDoubleValidator = new QDoubleValidator( this ); + + myLeftValue = new QLineEdit( this ); + myLeftValue->setValidator( aDoubleValidator ); + + myDashLabel = new QLabel( "-", this ); + + myRightValue = new QLineEdit( this ); + myRightValue->setValidator( aDoubleValidator ); + + QToolButton* anApplyBtn = new QToolButton( this ); + anApplyBtn->setIcon( VISU::GetResourceMgr()->loadPixmap( "VISU", tr( "ICON_APPLY" ) ) ); + connect( anApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) ); + + + QWidget* anIdsWidget = new QWidget( this ); + QGridLayout* anIdsLayout = new QGridLayout( anIdsWidget ); + anIdsLayout->setMargin( 0 ); + + myIdsListWidget = new QListWidget( anIdsWidget ); + myIdsListWidget->setFlow( QListView::LeftToRight ); + myIdsListWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + myIdsListWidget->setFixedHeight( 45 ); + + connect( myIdsListWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( onIdChanged() ) ); + + myPageLabel = new QLabel( anIdsWidget ); + myPageLabel->setAlignment( Qt::AlignHCenter ); + + myPrevBtn = new QToolButton( anIdsWidget ); + myPrevBtn->setIcon( VISU::GetResourceMgr()->loadPixmap( "VISU", tr( "ICON_SLIDER_PREVIOUS" ) ) ); + connect( myPrevBtn, SIGNAL( clicked() ), this, SLOT( onPrevPage() ) ); + + myNextBtn = new QToolButton( anIdsWidget ); + myNextBtn->setIcon( VISU::GetResourceMgr()->loadPixmap( "VISU", tr( "ICON_SLIDER_NEXT" ) ) ); + connect( myNextBtn, SIGNAL( clicked() ), this, SLOT( onNextPage() ) ); + + anIdsLayout->addWidget( myIdsListWidget, 0, 0, 2, 1 ); + anIdsLayout->addWidget( myPageLabel, 0, 1, 1, 2 ); + anIdsLayout->addWidget( myPrevBtn, 1, 1 ); + anIdsLayout->addWidget( myNextBtn, 1, 2 ); + + + aTopLayout->addWidget( aConditionLabel, 0, 0, 1, 5 ); + aTopLayout->addWidget( myConditionBox, 1, 0 ); + aTopLayout->addWidget( myLeftValue, 1, 1 ); + aTopLayout->addWidget( myDashLabel, 1, 2 ); + aTopLayout->addWidget( myRightValue, 1, 3 ); + aTopLayout->addWidget( anApplyBtn, 1, 4 ); + aTopLayout->addWidget( anIdsWidget, 2, 0, 1, 5 ); + + onConditionChanged( 0 ); + + setSelectionMode( ActorSelection ); +} + +VisuGUI_FindPane::~VisuGUI_FindPane() +{ +} + +void VisuGUI_FindPane::setSelectionMode( const Selection_Mode theSelectionMode ) +{ + if( mySelectionMode != theSelectionMode ) + clearIds(); + + mySelectionMode = theSelectionMode; + setEnabled( mySelectionMode != ActorSelection ); +} + + +void VisuGUI_FindPane::setActor( VISU_Actor* theActor ) +{ + if( myActor != theActor ) + clearIds(); + + myActor = theActor; +} + +void VisuGUI_FindPane::onConditionChanged( int theId ) +{ + myLeftValue->setEnabled( theId >= 2 ); + myDashLabel->setEnabled( theId == 5 ); + myRightValue->setEnabled( theId == 5 ); +} + +void VisuGUI_FindPane::onApply() +{ + if( !isValid() ) + { + SUIT_MessageBox::warning( this, tr( "WRN_VISU" ), tr( "INCORRECT_VALUES" ) ); + return; + } + + myIdsListWidget->clear(); + + if( !myActor ) + return; + + vtkDataSet* aDataSet = myActor->GetInput(); + + vtkDataArray* aScalars = 0; + if( mySelectionMode == NodeSelection ) + aScalars = aDataSet->GetPointData()->GetScalars(); + else if( mySelectionMode == CellSelection ) + aScalars = aDataSet->GetCellData()->GetScalars(); + else if( mySelectionMode == GaussPointSelection ) + { + if( VISU_GaussPtsAct* aGaussPtsAct = dynamic_cast( myActor ) ) + aScalars = aGaussPtsAct->GetInput()->GetPointData()->GetScalars(); + } + + + if( !aScalars ) + return; + + int aCondition = myConditionBox->currentIndex(); + double aLeftValue = myLeftValue->text().toDouble(); + double aRightValue = myRightValue->text().toDouble(); + + myIdsList.clear(); + + double eps = 1.0 / VTK_LARGE_FLOAT; + + double anExtremum = 0; + if( aCondition == 0 ) + anExtremum = VTK_LARGE_FLOAT; + else if( aCondition == 1 ) + anExtremum = -VTK_LARGE_FLOAT; + + for( int aVTKId = 0, aNbVal = aScalars->GetNumberOfTuples(); aVTKId < aNbVal; aVTKId++ ) + { + double aValue = *aScalars->GetTuple( aVTKId ); + + TFindId anId( -1, -1 ); + if( mySelectionMode == NodeSelection ) + anId.first = myActor->GetNodeObjId( aVTKId ); + else if( mySelectionMode == CellSelection ) + anId.first = myActor->GetElemObjId( aVTKId ); + else if( mySelectionMode == GaussPointSelection ) + { + if( VISU_GaussPtsAct* aGaussPtsAct = dynamic_cast( myActor ) ) + { + VISU::TGaussPointID aGaussPointID = aGaussPtsAct->GetGaussPointsPL()->GetObjID( aVTKId + 1 ); + anId.first = aGaussPointID.first; + anId.second = aGaussPointID.second; + } + } + + if( anId.first < 0 || + anId.second < 0 && mySelectionMode == GaussPointSelection ) + continue; + + bool ok = false; + switch( aCondition ) + { + case 0: // Minimum + ok = ( aValue - anExtremum ) < eps; + break; + case 1: // Maximum + ok = ( aValue - anExtremum ) > -eps; + break; + case 2: // = + ok = fabs( aValue - aLeftValue ) < eps; + break; + case 3: // <= + ok = ( aValue - aLeftValue ) < eps; + break; + case 4: // >= + ok = ( aValue - aLeftValue ) > -eps; + break; + case 5: // Between + ok = ( aValue - aLeftValue ) > -eps && ( aValue - aRightValue ) < eps; + break; + default: + ok = true; + break; + } + + if( ok ) + { + if( aCondition <= 1 && fabs( aValue - anExtremum ) > eps ) + { + anExtremum = aValue; + myIdsList.clear(); + } + if( !myIdsList.contains( anId ) ) + myIdsList.append( anId ); + } + } + + qSort( myIdsList ); + + myCurrentPage = 0; + displayIds(); +} + +void VisuGUI_FindPane::onIdChanged() +{ + int aFirstId = -1, aSecondId = -1; + + QList aSelectedItems = myIdsListWidget->selectedItems(); + if( aSelectedItems.size() == 1 ) + { + QString aStr = aSelectedItems.first()->text(); + + bool ok = false; + aFirstId = aStr.toInt( &ok ); + if( !ok ) // try to parse the string as a pair of ids - "[aFirstId aSecondId]" + { + aStr.remove( '[' ); + aStr.remove( ']' ); + aFirstId = aStr.section( ' ', 0, 0 ).toInt( &ok ); + if( !ok ) + aFirstId = -1; + else + { + ok = false; + aSecondId = aStr.section( ' ', 1, 1 ).toInt( &ok ); + if( !ok ) + aSecondId = -1; + } + } + } + + emit idChanged( aFirstId, aSecondId ); +} + +void VisuGUI_FindPane::onPrevPage() +{ + myCurrentPage--; + displayIds(); +} + +void VisuGUI_FindPane::onNextPage() +{ + myCurrentPage++; + displayIds(); +} + +bool VisuGUI_FindPane::isValid() const +{ + bool ok = false;; + double aLeftValue = myLeftValue->text().toDouble( &ok ); + if( myLeftValue->isEnabled() && !ok ) + return false; + + ok = false; + double aRightValue = myRightValue->text().toDouble( &ok ); + if( myRightValue->isEnabled() && ( !ok || aRightValue < aLeftValue ) ) + return false; + + return true; +} + +void VisuGUI_FindPane::clearIds() +{ + myIdsList.clear(); + myCurrentPage = 0; + + displayIds(); +} + +void VisuGUI_FindPane::displayIds() +{ + myIdsListWidget->clear(); + + int aSize = myIdsList.size(); + + myPrevBtn->setEnabled( myCurrentPage != 0 ); + myNextBtn->setEnabled( ( myCurrentPage + 1 ) * PAGE_SIZE < aSize ); + myPageLabel->setText( QString( "Page %1/%2" ) + .arg( aSize > 0 ? myCurrentPage + 1 : 0 ) + .arg( aSize > 0 ? ( aSize - 1 ) / PAGE_SIZE + 1 : 0 ) ); + + int aFirstIndex = myCurrentPage * PAGE_SIZE; + int aLastIndex = aFirstIndex + PAGE_SIZE - 1; + if( aLastIndex >= aSize ) + aLastIndex = aSize - 1; + + for( int anIndex = aFirstIndex; anIndex <= aLastIndex; anIndex++ ) + { + TFindId anId = myIdsList[ anIndex ]; + int aFirstId = anId.first, aSecondId = anId.second; + QString aStr = aSecondId < 0 ? + QString( "%1" ).arg( aFirstId ) : + QString( "[%1 %2]" ).arg( aFirstId ).arg( aSecondId ); + myIdsListWidget->addItem( aStr ); + } +} diff --git a/src/VISUGUI/VisuGUI_FindPane.h b/src/VISUGUI/VisuGUI_FindPane.h new file mode 100644 index 00000000..3e36a208 --- /dev/null +++ b/src/VISUGUI/VisuGUI_FindPane.h @@ -0,0 +1,94 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : VisuGUI_FindPane.h +// Author : Oleg Uvarov +// Module : VISU + +#ifndef VISUGUI_FINDPANE_H +#define VISUGUI_FINDPANE_H + +#include + +#include + +class QComboBox; +class QLabel; +class QLineEdit; +class QListWidget; +class QToolButton; + +class VISU_Actor; + +typedef QPair TFindId; +typedef QList TListFindId; + +//! Find pane. +/*! + * Used for filter and highlight mesh-elements by their scalar values. + */ +class VisuGUI_FindPane : public QGroupBox +{ + Q_OBJECT + +public: + VisuGUI_FindPane( QWidget* theParent ); + ~VisuGUI_FindPane(); + +public: + void setSelectionMode( const Selection_Mode ); + void setActor( VISU_Actor* ); + +protected slots: + void onConditionChanged( int ); + void onApply(); + + void onIdChanged(); + void onPrevPage(); + void onNextPage(); + +private: + bool isValid() const; + void clearIds(); + void displayIds(); + +signals: + void idChanged( int, int ); + +private: + QComboBox* myConditionBox; + QLineEdit* myLeftValue; + QLabel* myDashLabel; + QLineEdit* myRightValue; + + QListWidget* myIdsListWidget; + QLabel* myPageLabel; + QToolButton* myPrevBtn; + QToolButton* myNextBtn; + + int myCurrentPage; + TListFindId myIdsList; + + Selection_Mode mySelectionMode; + VISU_Actor* myActor; +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.cxx b/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.cxx index e62a7906..15d621e6 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.cxx +++ b/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.cxx @@ -167,6 +167,9 @@ namespace State validate ( QString & theInput, int & thePos ) const { + if( theInput.isEmpty() ) + return QValidator::Acceptable; + if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid) return QValidator::Invalid; @@ -198,6 +201,9 @@ namespace State validate ( QString & theInput, int & thePos ) const { + if( theInput.isEmpty() ) + return QValidator::Acceptable; + if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid) return QValidator::Invalid; @@ -311,16 +317,22 @@ VisuGUI_GaussPointsSelectionPane::~VisuGUI_GaussPointsSelectionPane() { } -void VisuGUI_GaussPointsSelectionPane::Update() +void VisuGUI_GaussPointsSelectionPane::update() { VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get(); - myDisplayParentMeshCheckBox->setChecked( aPickingSettings->GetDisplayParentMesh() ); } -void VisuGUI_GaussPointsSelectionPane::SetInteractor( SVTK_RenderWindowInteractor* theInteractor ) +void VisuGUI_GaussPointsSelectionPane::setIds( const int theParentId, const int theLocalId ) { - //printf( "VisuGUI_GaussPointsSelectionPane::SetInteractor( %p )\n", theInteractor ); + myParentElementLineEdit->setText( theParentId < 0 ? "" : QString::number( theParentId ) ); + myLocalPointLineEdit->setText( theLocalId < 0 ? "" : QString::number( theLocalId ) ); + onSelectionApply(); +} + +void VisuGUI_GaussPointsSelectionPane::setInteractor( SVTK_RenderWindowInteractor* theInteractor ) +{ + //printf( "VisuGUI_GaussPointsSelectionPane::setInteractor( %p )\n", theInteractor ); vtkGenericRenderWindowInteractor* aDevice = theInteractor->GetDevice(); if( aDevice->HasObserver(vtkCommand::KeyPressEvent) ) aDevice->RemoveObservers(vtkCommand::KeyPressEvent); @@ -339,7 +351,7 @@ void VisuGUI_GaussPointsSelectionPane::SetInteractor( SVTK_RenderWindowInteracto myPriority); } -SVTK_RenderWindowInteractor* VisuGUI_GaussPointsSelectionPane::GetInteractor() +SVTK_RenderWindowInteractor* VisuGUI_GaussPointsSelectionPane::getInteractor() { if( SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow( myModule ) ) { @@ -372,7 +384,7 @@ void VisuGUI_GaussPointsSelectionPane::ProcessEvents(vtkObject* vtkNotUsed(theOb void VisuGUI_GaussPointsSelectionPane::KeyPressed() { //printf( "VisuGUI_GaussPointsSelectionPane::KeyPressed()\n" ); - if( GetInteractor()->GetDevice()->GetKeyCode() == 'P' ) + if( getInteractor()->GetDevice()->GetKeyCode() == 'P' ) { VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get(); @@ -387,7 +399,7 @@ void VisuGUI_GaussPointsSelectionPane::KeyPressed() void VisuGUI_GaussPointsSelectionPane::SelectionEvent() { //printf( "VisuGUI_GaussPointsSelectionPane::SelectionEvent()\n" ); - ClearIDControls(); + clearIDControls(); SelectorHelper aHelper( myModule ); if( aHelper.get() ) @@ -419,27 +431,42 @@ void VisuGUI_GaussPointsSelectionPane::onSelectionApply() if( !aHelper.get() ) return; - VISU::TCellID aCellId = myParentElementLineEdit->text().toInt(); - VISU::TLocalPntID aLocalPntId = myLocalPointLineEdit->text().toInt(); - VISU::PGaussPtsIDMapper anIDMapper = aHelper.myPipeLine->GetGaussPtsIDMapper(); - vtkIdType anObjVtkId = anIDMapper->GetVTKID( VISU::TGaussPointID( aCellId, aLocalPntId ) ); - if( anObjVtkId < 0 ) - return; + vtkIdType anObjVtkId = -1; + VISU::TCellID aCellId; + VISU::TLocalPntID aLocalPntId; - aHelper.myMapIndex.Clear(); - aHelper.myMapIndex.Add( anObjVtkId ); - aHelper.mySelector->AddOrRemoveIndex( aHelper.myIO, aHelper.myMapIndex, false ); + bool ok = false; + aCellId = myParentElementLineEdit->text().toInt( &ok ); + if( ok ) + { + ok = false; + aLocalPntId = myLocalPointLineEdit->text().toInt( &ok ); + if( ok ) + { + VISU::PGaussPtsIDMapper anIDMapper = aHelper.myPipeLine->GetGaussPtsIDMapper(); + anObjVtkId = anIDMapper->GetVTKID( VISU::TGaussPointID( aCellId, aLocalPntId ) ); + } + } + + if( anObjVtkId < 0 ) + aHelper.mySelector->ClearIndex(); + else + { + aHelper.myMapIndex.Clear(); + aHelper.myMapIndex.Add( anObjVtkId ); + aHelper.mySelector->AddOrRemoveIndex( aHelper.myIO, aHelper.myMapIndex, false ); + } aHelper.myActor->Highlight( aHelper.myIO ); - GetInteractor()->GetDevice()->CreateTimer( VTKI_TIMER_FIRST ); + getInteractor()->GetDevice()->CreateTimer( VTKI_TIMER_FIRST ); } -void VisuGUI_GaussPointsSelectionPane::ClearIDControls() +void VisuGUI_GaussPointsSelectionPane::clearIDControls() { myParentElementLineEdit->setText( "" ); myLocalPointLineEdit->setText( "" ); } -void VisuGUI_GaussPointsSelectionPane::Apply() +void VisuGUI_GaussPointsSelectionPane::apply() { onSelectionApply(); } diff --git a/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.h b/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.h index 245c12f6..a3440636 100644 --- a/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.h +++ b/src/VISUGUI/VisuGUI_GaussPointsSelectionPane.h @@ -26,8 +26,6 @@ #ifndef VISUGUI_GAUSSPOINTSSELECTIONPANE_H #define VISUGUI_GAUSSPOINTSSELECTIONPANE_H -#include "VISU_IDMapper.hxx" - #include #include @@ -65,16 +63,18 @@ public: ~VisuGUI_GaussPointsSelectionPane(); - //! Update dialog contents. - void Update(); + //! update dialog contents. + void update(); + + void setIds( const int, const int ); - void SetInteractor( SVTK_RenderWindowInteractor* ); + void setInteractor( SVTK_RenderWindowInteractor* ); - void Apply(); - //void Help(); + void apply(); + //void help(); protected: - SVTK_RenderWindowInteractor* GetInteractor(); + SVTK_RenderWindowInteractor* getInteractor(); protected slots: void onSelectionValidate(); @@ -93,7 +93,7 @@ private: void SelectionEvent(); //void keyPressEvent( QKeyEvent* e ); - void ClearIDControls(); + void clearIDControls(); private: const SalomeApp_Module* myModule; diff --git a/src/VISUGUI/VisuGUI_SelectionPanel.cxx b/src/VISUGUI/VisuGUI_SelectionPanel.cxx index 863ba91a..dd2d672e 100644 --- a/src/VISUGUI/VisuGUI_SelectionPanel.cxx +++ b/src/VISUGUI/VisuGUI_SelectionPanel.cxx @@ -33,6 +33,7 @@ #include "VisuGUI_ViewTools.h" #include "VisuGUI_SelectionPrefDlg.h" #include "VisuGUI_GaussPointsSelectionPane.h" +#include "VisuGUI_FindPane.h" #include "VISU_Event.h" @@ -90,7 +91,6 @@ #include #include #include -#include // VTK Includes #include @@ -104,7 +104,23 @@ using namespace std; -#define MARGIN_SIZE 3 +class CustomIntValidator: public QIntValidator +{ +public: + CustomIntValidator( QObject * theParent ): + QIntValidator( 0, VTK_LARGE_ID, theParent ) + {} + + virtual + State + validate( QString& theInput, int& thePos ) const + { + if( theInput.isEmpty() ) + return QValidator::Acceptable; + + return QIntValidator::validate( theInput, thePos ); + } +}; VisuGUI_SelectionPanel::VisuGUI_SelectionPanel( const SalomeApp_Module* theModule, QWidget* theParent ) : VisuGUI_BasePanel( tr("WINDOW_TITLE" ), theParent, /*ApplyBtn | */CloseBtn | HelpBtn ), @@ -114,7 +130,6 @@ VisuGUI_SelectionPanel::VisuGUI_SelectionPanel( const SalomeApp_Module* theModul { QVBoxLayout* TopLayout = new QVBoxLayout ( mainFrame() ); //TopLayout->setSpacing(6); - //TopLayout->setMargin(MARGIN_SIZE); QWidget* aNamePane = new QWidget (mainFrame()); QGridLayout* aNameLay = new QGridLayout (aNamePane); @@ -149,7 +164,7 @@ VisuGUI_SelectionPanel::VisuGUI_SelectionPanel( const SalomeApp_Module* theModul myIDValLbl = new QLineEdit ("", aDataGrp); aGridLay->addWidget( myIDValLbl, 0, 1 ); - QIntValidator* aIntValidator = new QIntValidator (myIDValLbl); + CustomIntValidator* aIntValidator = new CustomIntValidator (myIDValLbl); aIntValidator->setBottom(0); myIDValLbl->setValidator(aIntValidator); connect(myIDValLbl, SIGNAL(returnPressed()), this, SLOT(onPointIdEdit())); @@ -306,6 +321,13 @@ VisuGUI_SelectionPanel::VisuGUI_SelectionPanel( const SalomeApp_Module* theModul TopLayout->addWidget( myTabWidget ); + // Find Pane + myFindPane = new VisuGUI_FindPane( mainFrame() ); + + connect( myFindPane, SIGNAL( idChanged( int, int ) ), this, SLOT( onIdChanged( int, int ) ) ); + + TopLayout->addWidget( myFindPane ); + // Preferences button QPushButton* aPrefBtn = new QPushButton( tr( "SELECTION_PREFERENCES" ), mainFrame() ); connect( aPrefBtn, SIGNAL( clicked() ), this, SLOT( onPreferences() ) ); @@ -377,6 +399,8 @@ void VisuGUI_SelectionPanel::onSelectionModeChanged( int theId ) break; } + myFindPane->setSelectionMode( aViewWindow->SelectionMode() ); + emit selectionModeChanged( theId ); } @@ -435,7 +459,7 @@ void VisuGUI_SelectionPanel::onSelectionEvent() { if(SVTK_MainWindow* aMainWindow = aViewWindow->getMainWindow()) { SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor(); - myGaussPointsPane->SetInteractor(anInteractor); + myGaussPointsPane->setInteractor(anInteractor); } SVTK_Selector* aSelector = aViewWindow->GetSelector(); @@ -473,6 +497,7 @@ void VisuGUI_SelectionPanel::onSelectionEvent() { VISU_Actor* anVISUActor = VISU::FindActor(VISU::GetAppStudy(myModule), aViewWindow, aSObject->GetID().c_str()); + myFindPane->setActor( anVISUActor ); if (anVISUActor) { vtkFloatingPointType aCoord[6]; anVISUActor->GetBounds(aCoord); @@ -664,19 +689,29 @@ bool onIdEdit (const QString& theText, } } if (aPrs3d) { - int anObjId = theText.toInt(); + bool ok = false; + int anObjId = theText.toInt( &ok ); + if( !ok ) + anObjId = -1; + VISU_PipeLine* aPipeLine = aPrs3d->GetPipeLine(); if( dynamic_cast( aPipeLine ) ) return false; - int aVTKId = (aPipeLine->*theMethod)(anObjId); - if(aVTKId < 0) - return false; + if( anObjId < 0 ) + aSelector->ClearIndex(); + else + { + int aVTKId = (aPipeLine->*theMethod)(anObjId); + if(aVTKId < 0) + return false; + + TColStd_MapOfInteger newIndices; + newIndices.Add(anObjId); + aSelector->AddOrRemoveIndex(anIO, newIndices, false); + } - TColStd_MapOfInteger newIndices; - newIndices.Add(anObjId); - aSelector->AddOrRemoveIndex(anIO, newIndices, false); aViewWindow->highlight(anIO, true, true); if( SVTK_MainWindow* aMainWindow = aViewWindow->getMainWindow() ) @@ -732,6 +767,24 @@ void VisuGUI_SelectionPanel::onCellIdEdit () clearFields(); } +void VisuGUI_SelectionPanel::onIdChanged( int theFirstId, int theSecondId ) +{ + //printf( "VisuGUI_SelectionPanel::onIdChanged( %d, %d )\n", theFirstId, theSecondId ); + int aType = myTabWidget->currentIndex(); + if( aType == 1 ) + { + myCellIDValLbl->setText( theFirstId < 0 ? "" : QString::number( theFirstId ) ); + onCellIdEdit(); + } + else if( aType == 2 ) + { + myIDValLbl->setText( theFirstId < 0 ? "" : QString::number( theFirstId ) ); + onPointIdEdit(); + } + else if( aType == 3 ) + myGaussPointsPane->setIds( theFirstId, theSecondId ); +} + void VisuGUI_SelectionPanel::onPreferences() { preferencesDlg()->exec(); diff --git a/src/VISUGUI/VisuGUI_SelectionPanel.h b/src/VISUGUI/VisuGUI_SelectionPanel.h index d85c7dd2..3daa392a 100644 --- a/src/VISUGUI/VisuGUI_SelectionPanel.h +++ b/src/VISUGUI/VisuGUI_SelectionPanel.h @@ -33,7 +33,6 @@ #include -class QComboBox; class QLabel; class QLineEdit; class QTableWidget; @@ -45,6 +44,7 @@ class SalomeApp_Module; class SVTK_RenderWindowInteractor; class VisuGUI_GaussPointsSelectionPane; +class VisuGUI_FindPane; class VisuGUI_SelectionPrefDlg; class VisuGUI_SelectionPanel: public VisuGUI_BasePanel @@ -77,6 +77,8 @@ private slots: void onPointIdEdit(); void onCellIdEdit(); + void onIdChanged( int theFirstId, int theSecondId ); + signals: void selectionModeChanged( int ); @@ -119,6 +121,8 @@ private: VisuGUI_GaussPointsSelectionPane* myGaussPointsPane; + VisuGUI_FindPane* myFindPane; + VisuGUI_SelectionPrefDlg* myPreferencesDlg; const SalomeApp_Module* myModule; -- 2.39.2