-// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <vtkPerspectiveTransform.h>
#include <vtkMatrix4x4.h>
+#include <QtxRubberBand.h>
+
#include <QPixmap>
#include <QWidget>
-#include <QRubberBand>
#include <QPolygon>
#include <algorithm>
}
-vtkStandardNewMacro(SVTK_InteractorStyle);
+vtkStandardNewMacro(SVTK_InteractorStyle)
/*!
Constructor
*/
SVTK_InteractorStyle::SVTK_InteractorStyle():
- mySelectionEvent(new SVTK_SelectionEvent()),
- myPointPicker(vtkPointPicker::New()),
myLastHighlitedActor(NULL),
myLastPreHighlitedActor(NULL),
myControllerIncrement(SVTK_ControllerIncrement::New()),
myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
+ mySelectionEvent(new SVTK_SelectionEvent()),
myHighlightSelectionPointActor(SVTK_Actor::New()),
+ myPointPicker(vtkPointPicker::New()),
myRectBand(0),
myPolygonBand(0),
+ myPoligonState(Disable),
myIsAdvancedZoomingEnabled(false),
- myPoligonState( Disable )
+ myInteractivePoint{0.0, 0.0, 0.0}
{
myPointPicker->Delete();
if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
{
Selection_Mode aSelectionMode = GetSelector()->SelectionMode();
- double* aCoords;
- int aVtkId;
+ double* aCoords = NULL;
+ vtkIdType aVtkId;
bool isTrueType = false;
if( myCurrFocalPointType == SVTK::StartFocalPointSelection ||
aVtkId = myPointPicker->GetPointId();
if ( aVtkId >= 0 )
{
- int anObjId = anActor->GetNodeObjId( aVtkId );
+ vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
aCoords = anActor->GetNodeCoord(anObjId);
isTrueType = true;
}
0.0,
GetCurrentRenderer() );
aVtkId = aCellPicker->GetCellId();
- int aCellId = anActor->GetElemObjId( aVtkId );
+ vtkIdType aCellId = anActor->GetElemObjId( aVtkId );
if( aSelectionMode == EdgeSelection )
isTrueType = anActor->GetObjDimension( aCellId ) == 1;
// finishing current viewer operation
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
onFinishOperation();
+ int lastOperation = State;
startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+ if (lastOperation == VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
+ InvokeEvent(SVTK::InteractiveSelectionFinished, nullptr);
+ }
}
}
startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
}
myOtherPoint = myPoint = QPoint(x, y);
- if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+ if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE &&
+ ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
startOperation(ForcedState);
}
else {
startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
}
myOtherPoint = myPoint = QPoint(x, y);
- if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
+ if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE &&
+ ForcedState != VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION) {
startOperation(ForcedState);
}
else {
ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
}
+/*!
+ Starts Interactive Selection operation
+*/
+void SVTK_InteractorStyle::startInteractiveSelection()
+{
+ if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
+ {
+ onFinishOperation();
+ startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+ }
+ ForcedState = VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION;
+}
+
+
/*!
Set rotation point selected by user
*/
case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
case VTK_INTERACTOR_STYLE_CAMERA_FIT:
case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
+ case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
State = operation;
drawRect();
break;
}
+ case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+ {
+ InteractiveSelection();
+ break;
+ }
case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
case VTK_INTERACTOR_STYLE_CAMERA_PAN:
case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
{
if (!myCursorState)
setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
- }
+ } // fall through!
case VTK_INTERACTOR_STYLE_CAMERA_FIT:
{
myOtherPoint = mousePos;
drawRect();
break;
}
+ case VTK_INTERACTOR_STYLE_CAMERA_INTERACTIVE_SELECTION:
+ this->InteractiveSelection();
}
}
Called when user moves mouse inside viewer window and there is no active viewer operation
(!put necessary processing here!)
*/
-void SVTK_InteractorStyle::onCursorMove(QPoint mousePos)
+void SVTK_InteractorStyle::onCursorMove(QPoint /*mousePos*/)
{
if ( !GetSelector()->IsPreSelectionEnabled() )
return;
{
SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
- int aVtkId = myPointPicker->GetPointId();
+ vtkIdType aVtkId = myPointPicker->GetPointId();
if ( aVtkId >= 0 ) {
- int anObjId = anActor->GetNodeObjId( aVtkId );
+ vtkIdType anObjId = anActor->GetNodeObjId( aVtkId );
- TColStd_IndexedMapOfInteger aMapIndex;
+ SVTK_TIndexedMapOfVtkId aMapIndex;
aMapIndex.Add( anObjId );
myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
this->RotateXY( incrX, -incrY );
}
+void SVTK_InteractorStyle::InteractiveSelection()
+{
+ if (vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera()) {
+ int posX, posY;
+ this->Interactor->GetEventPosition(posX, posY);
+ double viewFocus[3], z;
+ double* focalPointWorld = cam->GetFocalPoint();
+ this->ComputeWorldToDisplay(focalPointWorld[0], focalPointWorld[1],
+ focalPointWorld[2], viewFocus);
+ z = viewFocus[2];
+
+ this->ComputeDisplayToWorld(double(posX), double(posY),
+ z, this->myInteractivePoint);
+ InvokeEvent(SVTK::InteractiveSelectionChanged, (void*)this->myInteractivePoint);
+ }
+}
+
/*!
Redefined in order to add an observer (callback) for custorm event (space mouse event)
*/
theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
+ theInteractor->AddObserver( SVTK::StartInteractiveSelection, EventCallbackCommand, Priority);
+ theInteractor->AddObserver( SVTK::StopCurrentOperation, EventCallbackCommand, Priority);
}
}
// check if bounding box was changed
if ( GetCurrentRenderer() )
{
+#ifdef VGL_WORKAROUND
+ GetCurrentRenderer()->Render();
+#endif
double aCurrBBCenter[3];
if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
{
*/
void SVTK_InteractorStyle::drawRect()
{
- if ( !myRectBand ) {
- myRectBand = new QRubberBand( QRubberBand::Rectangle, GetRenderWidget() );
- QPalette palette;
- palette.setColor(myRectBand->foregroundRole(), Qt::white);
- myRectBand->setPalette(palette);
- }
- myRectBand->hide();
+ if ( !myRectBand )
+ myRectBand = new QtxRectRubberBand( GetRenderWidget() );
+ myRectBand->setUpdatesEnabled ( false );
QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
- myRectBand->setGeometry( aRect );
- myRectBand->setVisible( aRect.isValid() );
+ myRectBand->initGeometry( aRect );
+
+ if ( !myRectBand->isVisible() )
+ myRectBand->show();
+
+ myRectBand->setUpdatesEnabled ( true );
+}
+
+/*!
+ \brief Delete rubber band on the end on the dragging operation.
+*/
+void SVTK_InteractorStyle::endDrawRect()
+{
+ if ( myRectBand ) {
+ myRectBand->clearGeometry();
+ myRectBand->hide();
+ }
}
bool isIntersect( const QPoint& theStart1, const QPoint& theEnd1,
return true;
bool res = true;
- for ( uint i = 0; i < thePoints->count() - 1 && res; i++ )
+ for ( int i = 0; i < thePoints->count() - 1 && res; i++ )
{
const QPoint& aStart = thePoints->point( i );
const QPoint& anEnd = thePoints->point( i + 1 );
}
}
-/*!
- \brief Delete rubber band on the end on the dragging operation.
-*/
-void SVTK_InteractorStyle::endDrawRect()
-{
- if ( myRectBand ) myRectBand->hide();
-
- delete myRectBand;
- myRectBand = 0;
-}
-
/*!
\brief Delete rubber band on the end on the dragging operation.
*/
{
if ( myPolygonBand ) myPolygonBand->hide();
- delete myPolygonBand;
+ // RNV fix for : #19204 [CEA][Windows] VTK Viewer - Access violation while right clicking
+ //delete myPolygonBand;
+ myPolygonBand->deleteLater();
myPolygonBand = 0;
myPolygonPoints.clear();
case SVTK::StartFocalPointSelection:
self->startFocalPointSelection();
return;
-
+ case SVTK::StartInteractiveSelection:
+ self->startInteractiveSelection();
+ return;
case SVTK::SetFocalPointSelected:
if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
{
self->myPrevFocalPointType = self->myCurrFocalPointType;
self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
return;
+ case SVTK::StopCurrentOperation:
+ self->onFinishOperation();
+ self->startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
}
}
}
return myControllerIncrement.GetPointer();
}
-vtkStandardNewMacro(SVTK_ControllerIncrement);
+vtkStandardNewMacro(SVTK_ControllerIncrement)
SVTK_ControllerIncrement::SVTK_ControllerIncrement()
{
myIncrement=10;
return myIncrement;
}
-vtkStandardNewMacro(SVTK_GeomControllerIncrement);
+vtkStandardNewMacro(SVTK_GeomControllerIncrement)
SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
{
}
return myIncrement;
}
-vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
+vtkStandardNewMacro(SVTK_ControllerOnKeyDown)
/*!
Constructor
{
}
-bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
+bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* /*theIS*/)
{
return true;
}