#include <inspector/View_Widget.hxx>
+#include <AIS_ViewController.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Xw_Window.hxx>
#endif
-// the key for multi selection :
-#define MULTISELECTIONKEY Qt::ShiftModifier
-// the key for shortcut (use to activate dynamic onRotate, panning)
-#define CASCADESHORTCUTKEY Qt::ControlModifier
-// for elastic bean selection
-#define ValZWMin 1
-
// =======================================================================
// function : Constructor
// purpose :
View_Widget::View_Widget (QWidget* theParent,
const Handle(AIS_InteractiveContext)& theContext,
const bool isFitAllActive)
-: QWidget (theParent), myCurrentMode (View_CurrentAction3d_Nothing), myFirst (true), myDefaultWidth (-1),
- myDefaultHeight (-1), myViewIsEnabled (true), myXmin (0), myYmin (0), myXmax (0), myYmax (0), myDragButtonDownX (0),
- myDragButtonDownY (0), myDragMultiButtonDownX (0), myDragMultiButtonDownY (0), myIsRectVisible (false), myRectBand (0),
+: QWidget (theParent), myFirst (true), myDefaultWidth (-1),
+ myDefaultHeight (-1), myViewIsEnabled (true),
myHasInitProj (Standard_False), myInitVx (0), myInitVy (0), myInitVz (0)
{
myViewer = new View_Viewer (View_Viewer::DefaultColor());
if (!theContext.IsNull())
+ {
myViewer->InitViewer (theContext);
+ }
else
{
myViewer->InitViewer (myViewer->CreateStandardViewer());
}
+ myController = new AIS_ViewController();
setAttribute (Qt::WA_PaintOnScreen);
setAttribute (Qt::WA_NoSystemBackground);
initViewActions();
((View_ToolButton*)myFitAllAction)->SetButtonChecked (isFitAllActive);
- initCursors();
}
// =======================================================================
if (myViewer->GetView())
myViewer->GetView()->SetBackgroundColor (theIsEnabled ? View_Viewer::DefaultColor()
: View_Viewer::DisabledColor());
- for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
- ViewAction ((View_ViewActionType)anActionId)->setEnabled (theIsEnabled);
+ ViewAction (View_ViewActionType_DisplayModeId)->setEnabled (theIsEnabled);
}
// =======================================================================
emit checkedStateChanged(View_ViewActionType_FitAllId, isOn);
}
-// =======================================================================
-// function : OnUpdateToggled
-// purpose :
-// =======================================================================
-void View_Widget::OnUpdateToggled (bool isOn)
-{
- QAction* aSentByAction = (QAction*)sender();
-
- if (aSentByAction == myViewActions[View_ViewActionType_DisplayModeId])
- {
- aSentByAction->setIcon (isOn ? QIcon (":/icons/view_dm_wireframe.png")
- : QIcon (":/icons/view_dm_shading.png"));
- return;
- }
-
- if (!isOn)
- return;
-
- for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_RotationId; anActionId++)
- {
- QAction* anAction = myViewActions[(View_ViewActionType)anActionId];
- if ((anAction == myViewActions[View_ViewActionType_FitAreaId]) ||
- (anAction == myViewActions[View_ViewActionType_ZoomId]) ||
- (anAction == myViewActions[View_ViewActionType_PanId]) ||
- (anAction == myViewActions[View_ViewActionType_RotationId]))
- {
- if (anAction && (anAction != aSentByAction))
- {
- anAction->setChecked (false);
- }
- else
- {
- if (aSentByAction == myViewActions[View_ViewActionType_FitAreaId])
- setActiveCursor (View_CursorMode_HandCursor);
- else if (aSentByAction == myViewActions[View_ViewActionType_ZoomId])
- setActiveCursor (View_CursorMode_ZoomCursor);
- else if (aSentByAction == myViewActions[View_ViewActionType_PanId])
- setActiveCursor (View_CursorMode_PanCursor);
- else if (aSentByAction == myViewActions[View_ViewActionType_RotationId])
- setActiveCursor (View_CursorMode_RotationCursor);
- else
- setActiveCursor (View_CursorMode_DefaultCursor);
- }
- }
- }
-}
-
// =======================================================================
// function : initViewActions
// purpose :
createAction (View_ViewActionType_FitAllId, ":/icons/view_fitall.png", tr ("Fit All"), SLOT (OnFitAll()));
myFitAllAction->setDefaultAction (ViewAction (View_ViewActionType_FitAllId));
- createAction (View_ViewActionType_FitAreaId, ":/icons/view_fitarea.png", tr ("Fit Area"), SLOT (OnFitArea()), true);
- createAction (View_ViewActionType_ZoomId, ":/icons/view_zoom.png", tr ("Zoom"), SLOT (OnZoom()), true);
- createAction (View_ViewActionType_PanId, ":/icons/view_pan.png", tr ("Pan"), SLOT (OnPan()), true);
- createAction (View_ViewActionType_RotationId, ":/icons/view_rotate.png", tr ("Rotation"), SLOT (OnRotate()), true);
createAction (View_ViewActionType_DisplayModeId, ":/icons/view_dm_shading.png", tr ("Display Mode"),
SIGNAL (displayModeClicked()), true);
-
- for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_RotationId; anActionId++)
- connect (myViewActions[(View_ViewActionType)anActionId], SIGNAL (toggled(bool)), this, SLOT (OnUpdateToggled(bool)));
-}
-
-// =======================================================================
-// function : initCursors
-// purpose :
-// =======================================================================
-void View_Widget::initCursors()
-{
- if (!myCursors.empty())
- return;
-
- myCursors[View_CursorMode_DefaultCursor] = QCursor (Qt::ArrowCursor);
- myCursors[View_CursorMode_HandCursor] = QCursor (Qt::PointingHandCursor);
- myCursors[View_CursorMode_PanCursor] = QCursor (Qt::SizeAllCursor);
- myCursors[View_CursorMode_ZoomCursor] = QCursor(QIcon (":/icons/cursor_zoom.png").pixmap (20, 20));
- myCursors[View_CursorMode_RotationCursor] = QCursor(QIcon (":/icons/cursor_rotate.png").pixmap (20, 20));
}
// =======================================================================
// =======================================================================
void View_Widget::mousePressEvent (QMouseEvent* theEvent)
{
- if (theEvent->button() == Qt::LeftButton)
- processLeftButtonDown (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
- else if (theEvent->button() == Qt::MidButton)
- processMiddleButtonDown (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
- else if (theEvent->button() == Qt::RightButton)
- processRightButtonDown (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
-}
-
-// =======================================================================
-// function : mouseReleaseEvent
-// purpose :
-// =======================================================================
-void View_Widget::mouseReleaseEvent (QMouseEvent* theEvent)
-{
- if (theEvent->button() == Qt::LeftButton)
- processLeftButtonUp (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
- else if (theEvent->button() == Qt::MidButton)
- processMiddleButtonUp (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
- else if (theEvent->button() == Qt::RightButton)
- processRightButtonUp (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
-}
-
-// =======================================================================
-// function : mouseMoveEvent
-// purpose :
-// =======================================================================
-void View_Widget::mouseMoveEvent (QMouseEvent* theEvent)
-{
- processMouseMove (theEvent->buttons() | theEvent->modifiers(), theEvent->pos());
-}
-
-// =======================================================================
-// function : activateCursor
-// purpose :
-// =======================================================================
-void View_Widget::activateCursor (const View_CurrentAction3d theMode)
-{
- switch (theMode)
- {
- case View_CurrentAction3d_DynamicPanning:
- {
- setActiveCursor (View_CursorMode_PanCursor);
- break;
- }
- case View_CurrentAction3d_DynamicZooming:
- {
- setActiveCursor (View_CursorMode_ZoomCursor);
- break;
- }
- case View_CurrentAction3d_DynamicRotation:
- {
- setActiveCursor (View_CursorMode_RotationCursor);
- break;
- }
- case View_CurrentAction3d_WindowZooming:
- {
- setActiveCursor (View_CursorMode_HandCursor);
- break;
- }
- case View_CurrentAction3d_Nothing:
- default:
- {
- setActiveCursor (View_CursorMode_DefaultCursor);
- break;
- }
- }
-}
-
-// =======================================================================
-// function : processLeftButtonDown
-// purpose :
-// =======================================================================
-void View_Widget::processLeftButtonDown (const int theFlags, const QPoint thePoint)
-{
- // save the current mouse coordinate in min
- myXmin = thePoint.x();
- myYmin = thePoint.y();
- myXmax = thePoint.x();
- myYmax = thePoint.y();
-
- if (theFlags & CASCADESHORTCUTKEY)
- {
- myCurrentMode = View_CurrentAction3d_DynamicZooming;
- OnUpdateToggled(true);
- }
- else
- {
- switch (myCurrentMode)
- {
- case View_CurrentAction3d_Nothing:
- {
- if (theFlags & MULTISELECTIONKEY)
- processDragMultiEvent (myXmax, myYmax, View_DragMode_ButtonDown);
- else
- processDragEvent (myXmax, myYmax, View_DragMode_ButtonDown);
- break;
- }
- case View_CurrentAction3d_DynamicZooming:
- case View_CurrentAction3d_WindowZooming:
- case View_CurrentAction3d_DynamicPanning:
- break;
- case View_CurrentAction3d_DynamicRotation:
- {
- myViewer->GetView()->StartRotation (thePoint.x(), thePoint.y());
- break;
- }
- default:
- {
- throw Standard_ProgramError ("View_Widget::processLeftButtonDown : Incompatible Current Mode");
- break;
- }
- }
- }
- activateCursor (myCurrentMode);
- emit leftButtonDown(thePoint.x(), thePoint.y());
-}
-
-// =======================================================================
-// function : processMiddleButtonDown
-// purpose :
-// =======================================================================
-void View_Widget::processMiddleButtonDown (const int theFlags, const QPoint /*thePoint*/)
-{
- if (theFlags & CASCADESHORTCUTKEY) {
- myCurrentMode = View_CurrentAction3d_DynamicPanning;
- OnUpdateToggled(true);
- }
- activateCursor (myCurrentMode);
-}
-
-// =======================================================================
-// function : processRightButtonDown
-// purpose :
-// =======================================================================
-void View_Widget::processRightButtonDown (const int theFlags, const QPoint thePoint)
-{
- if (theFlags & CASCADESHORTCUTKEY)
- {
- myCurrentMode = View_CurrentAction3d_DynamicRotation;
- myViewer->GetView()->StartRotation (thePoint.x(), thePoint.y());
- OnUpdateToggled(true);
- }
- else
- {
- popup (thePoint.x(), thePoint.y());
- }
- activateCursor (myCurrentMode);
-}
-
-// =======================================================================
-// function : processLeftButtonUp
-// purpose :
-// =======================================================================
-void View_Widget::processLeftButtonUp (const int theFlags, const QPoint thePoint)
-{
- switch (myCurrentMode)
- {
- case View_CurrentAction3d_Nothing:
- {
- if (thePoint.x() == myXmin && thePoint.y() == myYmin)
- {
- // no offset between down and up --> selectEvent
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- if (theFlags & MULTISELECTIONKEY)
- processInputMultiEvent (thePoint.x(), thePoint.y());
- else
- processInputEvent (thePoint.x(), thePoint.y());
- }
- else
- {
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False);
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- if (theFlags & MULTISELECTIONKEY)
- processDragMultiEvent (thePoint.x(), thePoint.y(), View_DragMode_ButtonUp);
- else
- processDragEvent (thePoint.x(), thePoint.y(), View_DragMode_ButtonUp);
- }
- break;
- }
- case View_CurrentAction3d_DynamicZooming:
- break;
- case View_CurrentAction3d_WindowZooming:
- {
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False);
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- if ((abs(myXmin - myXmax) > ValZWMin) ||
- (abs(myYmin - myYmax) > ValZWMin))
- myViewer->GetView()->WindowFitAll (myXmin, myYmin, myXmax, myYmax);
- break;
- }
- case View_CurrentAction3d_DynamicPanning:
- break;
- case View_CurrentAction3d_DynamicRotation:
- break;
- default:
- {
- throw Standard_ProgramError("View_Widget::processLeftButtonUp : Incompatible Current Mode");
- break;
- }
- }
- myDragButtonDownX = 0;
- myDragButtonDownY = 0;
- myDragMultiButtonDownX = 0;
- myDragMultiButtonDownY = 0;
-
- emit selectionChanged();
- emit leftButtonUp(thePoint.x(), thePoint.y());
-}
-
-// =======================================================================
-// function : processMiddleButtonUp
-// purpose :
-// =======================================================================
-void View_Widget::processMiddleButtonUp (const int /*theFlags*/, const QPoint /*thePoint*/)
-{
- myCurrentMode = View_CurrentAction3d_Nothing;
- activateCursor (myCurrentMode);
-}
-
-// =======================================================================
-// function : processRightButtonUp
-// purpose :
-// =======================================================================
-void View_Widget::processRightButtonUp (const int /*theFlags*/, const QPoint thePoint)
-{
- if (myCurrentMode == View_CurrentAction3d_Nothing)
- {
- popup (thePoint.x(), thePoint.y());
- }
- else
- myCurrentMode = View_CurrentAction3d_Nothing;
- activateCursor (myCurrentMode);
-}
-
-// =======================================================================
-// function : processMouseMove
-// purpose :
-// =======================================================================
-void View_Widget::processMouseMove (const int theFlags, const QPoint thePoint)
-{
- if (theFlags & Qt::LeftButton || theFlags & Qt::RightButton || theFlags & Qt::MidButton)
+ if (myController->PressMouseButton (Graphic3d_Vec2i (theEvent->x(), theEvent->y()),
+ keyMouse (theEvent->button()),
+ keyFlag (theEvent->modifiers()),
+ Standard_False))
{
- switch (myCurrentMode)
- {
- case View_CurrentAction3d_Nothing:
- {
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False);
- if (theFlags & MULTISELECTIONKEY)
- processDragMultiEvent (myXmax, myYmax, View_DragMode_ButtonMove);
- else
- processDragEvent (myXmax, myYmax, View_DragMode_ButtonMove);
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True);
- break;
- }
- case View_CurrentAction3d_DynamicZooming:
- {
- myViewer->GetView()->Zoom (myXmax, myYmax, thePoint.x(), thePoint.y());
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- break;
- }
- case View_CurrentAction3d_WindowZooming:
- {
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False);
- drawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True);
- break;
- }
- case View_CurrentAction3d_DynamicPanning:
- {
- myViewer->GetView()->Pan (thePoint.x() - myXmax, myYmax - thePoint.y());
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- break;
- }
- case View_CurrentAction3d_DynamicRotation:
- {
- myViewer->GetView()->Rotation (thePoint.x(), thePoint.y());
- myViewer->GetView()->Redraw();
- break;
- }
- default:
- {
- throw Standard_ProgramError("View_Widget::processMouseMove : Incompatible Current Mode");
- break;
- }
- }
+ myController->FlushViewEvents (myViewer->GetContext(), myViewer->GetView(), Standard_True);
}
- else
- {
- myXmax = thePoint.x();
- myYmax = thePoint.y();
- if (theFlags & MULTISELECTIONKEY)
- processMoveMultiEvent (thePoint.x(), thePoint.y());
- else
- processMoveEvent (thePoint.x(), thePoint.y());
- }
- emit moveTo (thePoint.x(), thePoint.y());
}
// =======================================================================
-// function : processDragEvent
-// purpose :
-// =======================================================================
-void View_Widget::processDragEvent (const Standard_Integer theX, const Standard_Integer theY, const View_DragMode& theState)
-{
- //myDragButtonDownX = 0;
- //myDragButtonDownY = 0;
-
- switch (theState)
- {
- case View_DragMode_ButtonDown:
- {
- myDragButtonDownX = theX;
- myDragButtonDownY = theY;
- break;
- }
- case View_DragMode_ButtonMove:
- break;
- case View_DragMode_ButtonUp:
- {
- myViewer->GetContext()->Select (myDragButtonDownX, myDragButtonDownY, theX, theY, myViewer->GetView(), Standard_True);
- emit selectionChanged();
- break;
- }
- default:
- break;
- }
-}
-
-// =======================================================================
-// function : processInputEvent
-// purpose :
-// =======================================================================
-void View_Widget::processInputEvent (const Standard_Integer/* theX*/, const Standard_Integer/* theY*/)
-{
- myViewer->GetContext()->Select (Standard_True);
- emit selectionChanged();
-}
-
-// =======================================================================
-// function : processMoveEvent
-// purpose :
-// =======================================================================
-void View_Widget::processMoveEvent (const Standard_Integer theX, const Standard_Integer theY)
-{
- if (myViewer->GetView())
- myViewer->GetContext()->MoveTo (theX, theY, myViewer->GetView(), Standard_True);
-}
-
-// =======================================================================
-// function : processDragMultiEvent
+// function : mouseReleaseEvent
// purpose :
// =======================================================================
-void View_Widget::processDragMultiEvent (const Standard_Integer theX, const Standard_Integer theY,
- const View_DragMode& theState)
+void View_Widget::mouseReleaseEvent (QMouseEvent* theEvent)
{
- switch (theState)
+ if (myController->ReleaseMouseButton (Graphic3d_Vec2i (theEvent->x(), theEvent->y()),
+ keyMouse (theEvent->button()),
+ keyFlag (theEvent->modifiers()),
+ Standard_False))
{
- case View_DragMode_ButtonDown:
- {
- myDragMultiButtonDownX = theX;
- myDragMultiButtonDownY = theY;
- break;
- }
- case View_DragMode_ButtonMove:
- {
- myViewer->GetContext()->ShiftSelect (myDragMultiButtonDownX, myDragMultiButtonDownY, theX, theY,
- myViewer->GetView(), Standard_True);
- emit selectionChanged();
- break;
- }
- case View_DragMode_ButtonUp:
- default:
- break;
+ myController->FlushViewEvents (myViewer->GetContext(), myViewer->GetView(), Standard_True);
}
}
// =======================================================================
-// function : processInputMultiEvent
-// purpose :
-// =======================================================================
-void View_Widget::processInputMultiEvent (const Standard_Integer /*theX*/, const Standard_Integer /*theY*/)
-{
- myViewer->GetContext()->ShiftSelect (Standard_True);
- emit selectionChanged();
-}
-
-// =======================================================================
-// function : drawRectangle
+// function : mouseMoveEvent
// purpose :
// =======================================================================
-void View_Widget::drawRectangle (const Standard_Integer theMinX, const Standard_Integer MinY,
- const Standard_Integer MaxX, const Standard_Integer MaxY,
- const Standard_Boolean theToDraw)
+void View_Widget::mouseMoveEvent (QMouseEvent* theEvent)
{
- Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
+ myController->UpdateMousePosition (Graphic3d_Vec2i (theEvent->x(), theEvent->y()),
+ keyMouse (theEvent->button()),
+ keyFlag (theEvent->modifiers()), Standard_False);
- StoredMinX = (theMinX < MaxX) ? theMinX : MaxX;
- StoredMinY = (MinY < MaxY) ? MinY : MaxY;
- StoredMaxX = (theMinX > MaxX) ? theMinX : MaxX;
- StoredMaxY = (MinY > MaxY) ? MinY : MaxY;
-
- QRect aRect;
- aRect.setRect(StoredMinX, StoredMinY, abs (StoredMaxX-StoredMinX), abs (StoredMaxY-StoredMinY));
-
- if (!myRectBand)
- {
- myRectBand = new QRubberBand (QRubberBand::Rectangle, this);
- myRectBand->setStyle (QStyleFactory::create ("windows"));
- myRectBand->setGeometry (aRect);
- myRectBand->show();
- }
-
- if (myIsRectVisible && !theToDraw) // move or up : erase at the old position
- {
- myRectBand->hide();
- delete myRectBand;
- myRectBand = 0;
- myIsRectVisible = false;
- }
-
- if (theToDraw) // move : draw
- {
- myIsRectVisible = true;
- myRectBand->setGeometry (aRect);
- }
+ myController->FlushViewEvents (myViewer->GetContext(), myViewer->GetView(), Standard_True);
}
// =======================================================================
}
// =======================================================================
-// function : setActiveCursor
+// function : keyFlag
// purpose :
// =======================================================================
-void View_Widget::setActiveCursor (const View_CursorMode& theMode)
+Aspect_VKeyFlags View_Widget::keyFlag (const int theModifierId)
{
- QCursor aCursor = myCursors[theMode];
- setCursor (myCursors[theMode]);
+ switch (theModifierId)
+ {
+ case Qt::NoModifier: return Aspect_VKeyFlags_NONE;
+ case Qt::ShiftModifier: return Aspect_VKeyFlags_SHIFT;
+ case Qt::ControlModifier: return Aspect_VKeyFlags_CTRL;
+ default: break;
+ }
+ return Aspect_VKeyFlags_NONE;
+}
+
+// =======================================================================
+// function : keyMouse
+// purpose :
+// =======================================================================
+Aspect_VKeyMouse View_Widget::keyMouse (const int theButtonId)
+{
+ switch (theButtonId)
+ {
+ case Qt::NoButton: return Aspect_VKeyMouse_NONE;
+ case Qt::LeftButton: return Aspect_VKeyMouse_LeftButton;
+ case Qt::RightButton: return Aspect_VKeyMouse_RightButton;
+ case Qt::MidButton: return Aspect_VKeyMouse_MiddleButton;
+ default: break;
+ }
+ return Aspect_VKeyMouse_NONE;
}
#define View_View_H
#include <AIS_InteractiveContext.hxx>
+#include <AIS_ViewController.hxx>
+#include <Aspect_VKeyFlags.hxx>
#include <V3d_View.hxx>
#include <inspector/View_ViewActionType.hxx>
#include <inspector/View_Viewer.hxx>
class View_Viewer;
-class QRubberBand;
-
//! \class View_Widget
//! \brief It is a Qt control that visualizes content of OCCT 3D view
//! It creates control and actions of manipulating of this view,
class View_Widget : public QWidget
{
Q_OBJECT
-protected:
-
- //! Enumeration defines manipulating actions of the widget
- enum View_CurrentAction3d
- {
- View_CurrentAction3d_Nothing, //!< Empty action
- View_CurrentAction3d_DynamicZooming, //!< Zoom action
- View_CurrentAction3d_WindowZooming, //!< Zoom action using rectangle
- View_CurrentAction3d_DynamicPanning, //!< Panning action
- View_CurrentAction3d_DynamicRotation //!< Rotation action
- };
-
- //! Enumeration defines cursor kind
- enum View_CursorMode
- {
- View_CursorMode_DefaultCursor, //!< default Qt cursor
- View_CursorMode_HandCursor, //!< hand cursor
- View_CursorMode_PanCursor, //!< panning cursor
- View_CursorMode_ZoomCursor, //!< zoom cursor
- View_CursorMode_RotationCursor //!< onRotate cursor
- };
-
- //! Enumeration defines drag mode
- enum View_DragMode
- {
- View_DragMode_ButtonDown, //!< theState == -1 button down
- View_DragMode_ButtonMove, //!< theState == 0 move
- View_DragMode_ButtonUp //< theState == 1 button up
- };
public:
-
//! Constructor
Standard_EXPORT View_Widget (QWidget* theParent,
const Handle(AIS_InteractiveContext)& theContext,
//! Sends a signal about selection change if the left mouse button is pressed and current action does not process it
void selectionChanged();
- //! Sends a signal about moving to the point in the view
- //! \param theX X mouse position in pixels
- //! \param theY Y mouse position in pixels
- void moveTo (const int theX, const int theY);
-
- //! Sends a signal about up the left mouse button down
- //! \param theX X mouse position in pixels
- //! \param theY Y mouse position in pixels
- void leftButtonDown (const int theX, const int theY);
-
- //! Sends a signal about up the left mouse button up
- //! \param theX X mouse position in pixels
- //! \param theY Y mouse position in pixels
- void leftButtonUp (const int theX, const int theY);
-
//! Sends a signal about display mode change
void displayModeClicked();
//! Fits all the V3d view and redraw view
void OnFitAll() { myViewer->GetView()->FitAll(); }
- //! Stores state about fitting all to use it by the mouse move
- void OnFitArea() { myCurrentMode = View_CurrentAction3d_WindowZooming; }
-
- //! Stores state about zoom to use it by the mouse move
- void OnZoom() { myCurrentMode = View_CurrentAction3d_DynamicZooming; }
-
- //! Stores state about pan to use it by the mouse move
- void OnPan() { myCurrentMode = View_CurrentAction3d_DynamicPanning; }
-
- //! Stores state about onRotate to use it by the mouse move
- void OnRotate() { myCurrentMode = View_CurrentAction3d_DynamicRotation; }
-
//! Updates states of widget actions
//!
//! - if the state is checked, uncheck all other actions
Standard_EXPORT void onCheckedStateChanged (bool isOn);
- //! Updates states of tool actions:
- //! - if the action is display mode, it changes an icon for action(wireframe or shading)
- //! - if the state is checked, uncheck all other actions
- //! \param isOn boolean value about check
- Standard_EXPORT void OnUpdateToggled (bool isOn);
-
protected:
//! Avoids Qt standard execution of this method, redraw V3d view
//! Creates view actions and fills an internal map
void initViewActions();
- //! Creates cursors and fills an internal map
- void initCursors();
-
- //! Sets widget cursor by the action type
- //! \param theMode an active action mode
- void activateCursor (const View_CurrentAction3d theMode);
-
- //! Activates cursor of the active operation, perform drag, onRotate depending on mode,
- //! stores the point position in xmin/xmax and ymin/ymax
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processLeftButtonDown (const int theFlags, const QPoint thePoint);
-
- //! Activates cursor of the active operation and performs dynamic pan if it is active
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processMiddleButtonDown (const int theFlags, const QPoint thePoint);
-
- //! Activates cursor of the active operation, build popup menu
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processRightButtonDown (const int theFlags, const QPoint thePoint);
-
- //! Performs the active operation or performs Input/Drag event processing, emits selection changed signal
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processLeftButtonUp (const int theFlags, const QPoint thePoint);
-
- //! Changes the active operation to None
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processMiddleButtonUp (const int theFlags, const QPoint thePoint);
-
- //! Calls popup menu build and changes the active operation to None
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processRightButtonUp (const int theFlags, const QPoint thePoint);
-
- //! Performs active operation or draws rectangle of zoom
- //! \param theFlags an event buttons and modifiers
- //! \param thePoint a clicked point
- void processMouseMove (const int theFlags, const QPoint thePoint);
-
- //! Performs selection: store clicked point by botton down, call Select by button up
- //! Emits signal about selection changed
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- //! \param theState a mouse button state: down, move or up
- void processDragEvent (const Standard_Integer theX, const Standard_Integer theY, const View_DragMode& theState);
-
- //! Performs selection in context without parameter, it means the selection of picked object
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- void processInputEvent (const Standard_Integer theX, const Standard_Integer theY);
-
- //! Calls MoveTo of the context for the parameter coordinates
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- void processMoveEvent (const Standard_Integer theX, const Standard_Integer theY);
-
- //! Empty: template to process mouse move with multi selection key pressed
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- void processMoveMultiEvent (const Standard_Integer theX, const Standard_Integer theY)
- { (void)theX; (void)theY; }
-
- //! Performs selection: store clicked point by botton down, call ShiftSelect by button move
- //! Emits signal about selection changed
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- //! \param theState a mouse button state: down, move or up
- void processDragMultiEvent (const Standard_Integer theX, const Standard_Integer theY, const View_DragMode& theState);
-
- //! Performs shift selection in context without parameter, it means the selection of picked object
- //! \param theX a horizontal position of mouse event
- //! \param theX a vertical position of mouse event
- void processInputMultiEvent (const Standard_Integer theX, const Standard_Integer theY);
-
//! Empty: template to create popup menu
//! \param theX a horizontal position of mouse event
//! \param theX a vertical position of mouse event
void popup (const Standard_Integer theX, const Standard_Integer theY) { (void)theX; (void)theY; }
- //! Draws Qt rectangle for the given area (e.g. for panning operation)
- //! \param theMinX a minimal X coordinate
- //! \param theMinY a minimal Y coordinate
- //! \param theMinZ a minimal Z coordinate
- //! \param theMaxX a maximum X coordinate
- //! \param theMaxY a maximum Y coordinate
- //! \param theMaxZ a maximum Z coordinate
- //! \param theToDraw state whether the rectangle should be visualized or hidden
- void drawRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY, const Standard_Integer theMaxX,
- const Standard_Integer theMaxY, const Standard_Boolean theToDraw);
private:
//! Creates action and stores it in a map of actions
//! \param theActionId an identifier of action in internal map
const char* theSlot, const bool isCheckable = false,
const QString& theToolBar = QString(), const QString& theStatusBar = QString());
- //! Sets active action cursor for application
- //! \param theMode a cursor mode
- void setActiveCursor (const View_CursorMode& theMode);
+private:
+ //! Converts Qt modifier key to Aspect key flag
+ //! \param theModifierId the event modifier
+ static Aspect_VKeyFlags keyFlag (const int theModifierId);
+
+ //! Converts Qt button key to Aspect key mouse
+ //! \param theButtonId the event button
+ static Aspect_VKeyMouse keyMouse (const int theButtonId);
private:
View_Viewer* myViewer; //!< connector to context, V3d viewer and V3d View
+ AIS_ViewController* myController; //!< controller to process view actions
+
QToolButton* myFitAllAction; //!< widget for fit all, processed double click to perform action automatically
QMap<View_ViewActionType, QAction*> myViewActions; //!< tool bar view actions
- QMap<View_CursorMode, QCursor> myCursors; //!< possible cursors for view actions
- View_CurrentAction3d myCurrentMode; //!< an active action mode for viewer
Standard_Boolean myFirst; //!< flag to Init view by the first resize/paint call
Standard_Integer myDefaultWidth; //!< default width for the first sizeHint
Standard_Integer myDefaultHeight; //!< default height for the first sizeHint
Standard_Boolean myViewIsEnabled; //!< flag if the view and tool bar view actions are enabled/disabled
- Standard_Integer myXmin; //!< cached X minimal position by mouse press event
- Standard_Integer myYmin; //!< cached Y minimal position by mouse press event
- Standard_Integer myXmax; //!< cached X maximum position by mouse press event
- Standard_Integer myYmax; //!< cached Y maximum position by mouse press event
- Standard_Integer myDragButtonDownX; //!< cached X button down by drag event
- Standard_Integer myDragButtonDownY; //!< cached Y button down by drag event
- Standard_Integer myDragMultiButtonDownX; //!< cached X button down by multi drag event
- Standard_Integer myDragMultiButtonDownY; //!< cached Y button down by multi drag event
- Standard_Boolean myIsRectVisible; //!< true if rectangle is visible now
- QRubberBand* myRectBand; //!< selection rectangle rubber band
Standard_Boolean myHasInitProj; //!< is initial camera position defined
Standard_Real myInitVx; //!< initial camera position on X
Standard_Real myInitVy; //!< initial camera position on Y
Standard_Real myInitVz; //!< initial camera position on Z
-
};
#endif