From e6d2a8bbec2605e15fc179e8c96fe200b106a7f5 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 14 Nov 2007 08:20:10 +0000 Subject: [PATCH] Fix for Bug NPAL16809 EDF 562 VISU Gauss Picking, having an alphanumeric selection (New GUI controls is introduced) --- src/VVTK/VVTK_PickingDlg.cxx | 271 +++++++++++++++++++++++++++++++++-- src/VVTK/VVTK_PickingDlg.h | 24 ++++ 2 files changed, 283 insertions(+), 12 deletions(-) diff --git a/src/VVTK/VVTK_PickingDlg.cxx b/src/VVTK/VVTK_PickingDlg.cxx index 3d0a5f4d..085816a4 100644 --- a/src/VVTK/VVTK_PickingDlg.cxx +++ b/src/VVTK/VVTK_PickingDlg.cxx @@ -24,15 +24,20 @@ #include "VVTK_PickingDlg.h" #include "VISU_GaussPtsAct.h" +#include "VISU_GaussPointsPL.hxx" #include "VISU_GaussPtsSettings.h" #include "SUIT_MessageBox.h" #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" +#include "SVTK_Selector.h" #include "SVTK_MainWindow.h" #include "SVTK_RenderWindowInteractor.h" +#include "VTKViewer_Algorithm.h" +#include "SVTK_Functor.h" + #include #include #include @@ -51,13 +56,182 @@ #include #include +#include + #include "QtxAction.h" #include "QtxDblSpinBox.h" #include "QtxIntSpinBox.h" #include "LightApp_Application.h" -using namespace std; +namespace +{ + struct SelectorHelper + { + public: + SelectorHelper( SVTK_RenderWindowInteractor* theInteractor ): + myInteractor( theInteractor ) + {} + + bool + get() + { + bool aResult = false; + myMapIndex.Clear(); + mySelector = NULL; + myPipeLine = NULL; + myActor = NULL; + + if ( !myInteractor ) + return aResult; + + mySelector = myInteractor->GetSelector(); + if ( !mySelector ) + return aResult; + + const SALOME_ListIO& aListIO = mySelector->StoredIObjects(); + if ( aListIO.Extent() != 1 ) + return aResult; + + myIO = aListIO.First(); + if ( mySelector->HasIndex( myIO ) ) + mySelector->GetIndex(myIO, myMapIndex); + + myActor = SVTK::Find(myInteractor->getRenderer()->GetActors(), + SVTK::TIsSameIObject( myIO )); + if ( !myActor ) + return aResult; + + myPipeLine = myActor->GetGaussPointsPL(); + + return true; + } + + SVTK_RenderWindowInteractor* myInteractor; + TColStd_IndexedMapOfInteger myMapIndex; + Handle(SALOME_InteractiveObject) myIO; + SVTK_Selector* mySelector; + + VISU_GaussPointsPL* myPipeLine; + VISU_GaussPtsAct* myActor; + }; + + + + class GaussPtsIDValidator: public QIntValidator + { + public: + GaussPtsIDValidator( SVTK_RenderWindowInteractor* theInteractor, + QObject * theParent ): + QIntValidator( 0, VTK_LARGE_ID, theParent ), + myHelper(theInteractor) + {} + + virtual + State + validate ( QString & theInput, int & thePos ) const + { + if ( QIntValidator::validate( theInput, thePos ) == QValidator::Invalid) + return QValidator::Invalid; + + if ( !myHelper.get() ) + return QValidator::Invalid; + + return QValidator::Acceptable; + } + + protected: + mutable SelectorHelper myHelper; + }; + + + class GaussCellIDValidator: public GaussPtsIDValidator + { + public: + GaussCellIDValidator( QLineEdit* theLocalPointLabel, + SVTK_RenderWindowInteractor* theInteractor, + QObject * theParent ): + GaussPtsIDValidator( theInteractor, theParent ), + myLocalPointLineEdit( theLocalPointLabel ) + {} + + virtual + State + validate ( QString & theInput, int & thePos ) const + { + if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid) + return QValidator::Invalid; + + VISU::TCellID aCellID = theInput.toInt(); + VISU::TLocalPntID aLocalPntID = myLocalPointLineEdit->text().toInt(); + VISU::PGaussPtsIDMapper anIDMapper = myHelper.myPipeLine->GetGaussPtsIDMapper(); + if ( anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) ) < 0 ) + return QValidator::Intermediate; + + return QValidator::Acceptable; + } + + private: + QLineEdit* myLocalPointLineEdit; + }; + + + class GaussLocalPointIDValidator: public GaussPtsIDValidator + { + public: + GaussLocalPointIDValidator( QLineEdit* theParentElementLineEdit, + SVTK_RenderWindowInteractor* theInteractor, + QObject * theParent ): + GaussPtsIDValidator( theInteractor, theParent ), + myParentElementLineEdit( theParentElementLineEdit ) + {} + + virtual + State + validate ( QString & theInput, int & thePos ) const + { + if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid) + return QValidator::Invalid; + + VISU::TLocalPntID aLocalPntID = theInput.toInt(); + VISU::TCellID aCellID = myParentElementLineEdit->text().toInt(); + VISU::PGaussPtsIDMapper anIDMapper = myHelper.myPipeLine->GetGaussPtsIDMapper(); + if ( anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) ) < 0 ) + return QValidator::Intermediate; + + return QValidator::Acceptable; + } + + private: + QLineEdit* myParentElementLineEdit; + }; +} + + +VVTK_ValidatedLineEdit::VVTK_ValidatedLineEdit( QWidget * parent, const char * name ): + QLineEdit( parent, name ) +{ + connect( this, SIGNAL( textChanged( const QString& ) ), this, SLOT( MarkValidated( const QString& ) ) ); +} + +void VVTK_ValidatedLineEdit::MarkValidated( const QString& theText ) +{ + if ( !validator() ) + return; + + int aPos; + QString aText( theText ); + switch ( validator()->validate( aText, aPos ) ) { + case QValidator::Invalid: + case QValidator::Intermediate: + setPaletteForegroundColor( QColor( 255, 0, 0 ) ); + break; + case QValidator::Acceptable: + setPaletteForegroundColor( QColor( 0, 0, 0 ) ); + break; + } +} + VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction, SVTK_MainWindow* theParent, @@ -192,18 +366,30 @@ VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction, CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 ); // Display parent mesh element - QGroupBox* ParentMeshGroup = new QGroupBox( tr( "PARENT_MESH_TITLE" ), aBox, "ParentMeshGroup" ); - ParentMeshGroup->setColumnLayout(0, Qt::Vertical ); - ParentMeshGroup->layout()->setSpacing( 0 ); - ParentMeshGroup->layout()->setMargin( 0 ); + QGroupBox* PositionGroup = new QGroupBox( tr( "DATA_POSITION" ), aBox, "Position" ); + PositionGroup->setColumnLayout(0, Qt::Vertical ); + PositionGroup->layout()->setSpacing( 0 ); + PositionGroup->layout()->setMargin( 0 ); + + QGridLayout* PositionGroupLayout = new QGridLayout (PositionGroup->layout()); + PositionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); + PositionGroupLayout->setSpacing(6); + PositionGroupLayout->setMargin(11); + + QLabel* ParentElementLabel = new QLabel( tr( "PARENT_ELEMENT" ), PositionGroup ); + PositionGroupLayout->addMultiCellWidget( ParentElementLabel, 0, 0, 0, 2 ); - QGridLayout* ParentMeshGroupLayout = new QGridLayout (ParentMeshGroup->layout()); - ParentMeshGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); - ParentMeshGroupLayout->setSpacing(6); - ParentMeshGroupLayout->setMargin(11); + myParentElementLineEdit = new VVTK_ValidatedLineEdit( PositionGroup ); + PositionGroupLayout->addMultiCellWidget( myParentElementLineEdit, 0, 0, 3, 3 ); - myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), ParentMeshGroup ); - ParentMeshGroupLayout->addWidget( myDisplayParentMeshCheckBox, 0, 0 ); + QLabel* LocalPointLabel = new QLabel( tr( "LOCAL_POINT" ), PositionGroup ); + PositionGroupLayout->addMultiCellWidget( LocalPointLabel, 1, 1, 0, 2 ); + + myLocalPointLineEdit = new VVTK_ValidatedLineEdit( PositionGroup ); + PositionGroupLayout->addMultiCellWidget( myLocalPointLineEdit, 1, 1, 3, 3 ); + + myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), PositionGroup ); + PositionGroupLayout->addMultiCellWidget( myDisplayParentMeshCheckBox, 2, 2, 0, 3 ); // Common buttons =========================================================== QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); @@ -235,6 +421,9 @@ VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction, connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) ); connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) ); connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onClickHelp() ) ); + + connect( myParentElementLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onSelectionValidate() ) ); + connect( myLocalPointLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onSelectionValidate() ) ); } VVTK_PickingDlg::~VVTK_PickingDlg() @@ -314,6 +503,32 @@ void VVTK_PickingDlg::Update() onClickApply(); } +void VVTK_PickingDlg::onSelectionValidate() +{ + myParentElementLineEdit->MarkValidated( myParentElementLineEdit->text() ); + myLocalPointLineEdit->MarkValidated( myLocalPointLineEdit->text() ); +} + +void VVTK_PickingDlg::onSelectionEvent() +{ + SelectorHelper aHelper( myInteractor ); + if ( !aHelper.get() ) + return; + + const TColStd_IndexedMapOfInteger& aMapIndex = aHelper.myMapIndex; + if ( aMapIndex.Extent() != 1 ) + return; + + int anObjId = aHelper.myMapIndex(1); + + VISU::TGaussPointID aGaussPointID = aHelper.myPipeLine->GetObjID( anObjId ); + + VISU::TCellID aCellID = aGaussPointID.first; + myParentElementLineEdit->setText( QString::number( aCellID ) ); + + VISU::TLocalPntID aLocalPntID = aGaussPointID.second; + myLocalPointLineEdit->setText( QString::number( aLocalPntID ) ); +} VISU_PickingSettings* VVTK_PickingDlg @@ -329,6 +544,18 @@ void VVTK_PickingDlg::SetInteractor( SVTK_RenderWindowInteractor* theInteractor theInteractor->GetDevice()->AddObserver(vtkCommand::KeyPressEvent, myEventCallbackCommand.GetPointer(), myPriority); + + theInteractor->GetDevice()->AddObserver(vtkCommand::EndPickEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + { + QValidator* aValidator = new GaussCellIDValidator( myLocalPointLineEdit, theInteractor, myParentElementLineEdit ); + myParentElementLineEdit->setValidator( aValidator ); + } + { + QValidator* aValidator = new GaussLocalPointIDValidator( myParentElementLineEdit, theInteractor, myLocalPointLineEdit ); + myLocalPointLineEdit->setValidator( aValidator ); + } } @@ -343,6 +570,9 @@ void VVTK_PickingDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), case vtkCommand::KeyPressEvent: self->KeyPressed(); break; + case vtkCommand::EndPickEvent: + self->onSelectionEvent(); + break; } } @@ -379,7 +609,24 @@ void VVTK_PickingDlg::onClickApply() aColor[2] = aButtonColor.blue() / 255.0; myPickingSettings->SetColor( aColor ); - myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL); + myPickingSettings->InvokeEvent( VISU::UpdatePickingSettingsEvent, NULL ); + + SelectorHelper aHelper( myInteractor ); + if ( !aHelper.get() ) + return; + + VISU::TCellID aCellID = myParentElementLineEdit->text().toInt(); + VISU::TLocalPntID aLocalPntID = myLocalPointLineEdit->text().toInt(); + VISU::PGaussPtsIDMapper anIDMapper = aHelper.myPipeLine->GetGaussPtsIDMapper(); + vtkIdType anObjId = anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) ); + if ( anObjId < 0 ) + return; + + aHelper.myMapIndex.Clear(); + aHelper.myMapIndex.Add( anObjId ); + aHelper.mySelector->AddOrRemoveIndex( aHelper.myIO, aHelper.myMapIndex, false ); + aHelper.myActor->Highlight( aHelper.myIO ); + myInteractor->GetDevice()->CreateTimer( VTKI_TIMER_FIRST ); } void VVTK_PickingDlg::onClickClose() diff --git a/src/VVTK/VVTK_PickingDlg.h b/src/VVTK/VVTK_PickingDlg.h index 81b2576c..671b651c 100644 --- a/src/VVTK/VVTK_PickingDlg.h +++ b/src/VVTK/VVTK_PickingDlg.h @@ -26,6 +26,8 @@ #include "SVTK_DialogBase.h" +#include + #include #include @@ -34,6 +36,7 @@ class vtkCallbackCommand; class vtkImageData; class QLabel; +class QLineEdit; class QComboBox; class QCheckBox; class QPushButton; @@ -48,6 +51,9 @@ class VISU_PickingSettings; class SVTK_MainWindow; class SVTK_RenderWindowInteractor; +class VVTK_ValidatedLineEdit; + + //! Picking Dialog. /*! * Uses for set up picking preferenses and apply @@ -76,11 +82,13 @@ public: void SetInteractor( SVTK_RenderWindowInteractor* ); protected slots: + void onSelectionEvent(); void onClickApply(); void onClickClose(); void onClickHelp(); void onColorButtonPressed(); + void onSelectionValidate(); private: static void ProcessEvents(vtkObject* theObject, @@ -105,10 +113,26 @@ private: QtxAction* myAction; vtkSmartPointer myPickingSettings; + VVTK_ValidatedLineEdit* myParentElementLineEdit; + VVTK_ValidatedLineEdit* myLocalPointLineEdit; + SVTK_RenderWindowInteractor* myInteractor; float myPriority; vtkSmartPointer myEventCallbackCommand; }; + +class VVTK_ValidatedLineEdit : public QLineEdit +{ + Q_OBJECT; +public: + VVTK_ValidatedLineEdit( QWidget * parent, const char * name = 0 ); + +public slots: + void + MarkValidated( const QString& theText ); +}; + + #endif -- 2.39.2