// connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
// this, SLOT (onContextMenuRequested( QContextMenuEvent* )));
-
connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
}
}
+/*!
+ SLOT: called on mouse button press, stores current mouse position as start point for transformations
+*/
+void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
+{
+ myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
+ emit mousePress(theWindow, theEvent);
+}
+
/*!
SLOT: called on mouse move, processes hilighting
*/
void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
{
- XGUI_ViewPort* aViewPort = theWindow->viewPort();
- Handle(V3d_View) aView3d = aViewPort->getView();
+ if (!mySelectionEnabled) return;
+ myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
+ Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
if ( !aView3d.IsNull() ) {
myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);
- mouseMoved(theEvent->pos());
}
}
*/
void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
{
- myAISContext->Select();
+ if (!mySelectionEnabled) return;
+ if (theEvent->button() != Qt::LeftButton) return;
+
+ myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
+ bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
+
+ //if (!aHasShift)
+ // emit deselection();
+
+ if (myStartPnt == myEndPnt) {
+ if (aHasShift && myMultiSelectionEnabled)
+ myAISContext->ShiftSelect();
+ else
+ myAISContext->Select();
+ } else {
+ if (aHasShift && myMultiSelectionEnabled)
+ myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
+ myEndPnt.x(), myEndPnt.y(),
+ theWindow->viewPort()->getView(), false );
+ else
+ myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
+ myEndPnt.x(), myEndPnt.y(),
+ theWindow->viewPort()->getView(), false );
+
+ int Nb = myAISContext->NbSelected();
+ if( Nb>1 && !myMultiSelectionEnabled ) {
+ myAISContext->InitSelected();
+ Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
+ if( !anOwner.IsNull() ) {
+ myAISContext->ClearSelected( Standard_False );
+ myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
+ }
+ }
- emit mouseReleased(theEvent->pos());
+ myAISContext->UpdateCurrentViewer();
+ }
+ emit selectionChanged();
}
/// \param theList - list objects to be selected
void setObjectsSelected(const AIS_ListOfInteractive& theList);
+ /// Returns true if selection in the viewer is enabled
+ bool isSelectionEnabled() const { return mySelectionEnabled; }
+
+ /// Enable or disable selectioon in the viewer
+ // \param toEnable - true or false (enable or disable selection)
+ void setSelectionEnabled(bool toEnable) { mySelectionEnabled = toEnable; }
+
/// Select the object in 3D viewer.
/// \param theIO - list objects to be selected
void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
void activated(XGUI_ViewWindow* theWindow);
void selectionChanged();
- void mouseReleased(QPoint thePoint);
- void mouseMoved(QPoint thePoint);
+ //void mouseReleased(QPoint thePoint);
+ //void mouseMoved(QPoint thePoint);
public slots:
void onWindowMinimized(QMdiSubWindow*);
void onViewClosed(QMdiSubWindow*);
void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
+ void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
private:
void addView(QMdiSubWindow* theView);
QList<QMdiSubWindow*> myViews;
QMdiSubWindow* myActiveView;
+
+ /// Points used for selection management
+ QPoint myStartPnt, myEndPnt, myCurPnt;
};
#endif