#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 <vtkActorCollection.h>
#include <vtkCallbackCommand.h>
#include <vtkObjectFactory.h>
#include <qpushbutton.h>
#include <qvbox.h>
+#include <qvalidator.h>
+
#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<VISU_GaussPtsAct>(myInteractor->getRenderer()->GetActors(),
+ SVTK::TIsSameIObject<VISU_GaussPtsAct>( 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,
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" );
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()
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
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 );
+ }
}
case vtkCommand::KeyPressEvent:
self->KeyPressed();
break;
+ case vtkCommand::EndPickEvent:
+ self->onSelectionEvent();
+ break;
}
}
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()