]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Define selection in Viewer 3d
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 09:04:34 +0000 (13:04 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 29 Apr 2014 09:04:34 +0000 (13:04 +0400)
src/NewGeom/CMakeLists.txt
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h

index 20404f8b172db18be4d5d2bbca43b2885ff84858..4d7a3b3e4ccd9e859dfcc62ca137b95080f0c01a 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
        NewGeom.h
        NewGeom_Module.h
        NewGeom_DataModel.h
+       NewGeom_OCCSelector.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -16,6 +17,7 @@ SET(PROJECT_AUTOMOC
 SET(PROJECT_SOURCES
        NewGeom_Module.cpp
        NewGeom_DataModel.cpp
+       NewGeom_OCCSelector.cpp
 )
 
 SET(PROJECT_RESOURCES
index efca3fde5a3ff658a2736867af5e2393a9819d18..0bba0d847e44253acc5379e70d42b3c64deef85b 100644 (file)
@@ -49,6 +49,7 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
 //**************************************************************
 void XGUI_SelectionMgr::onViewerSelection()
 {
+  // TODO: Highliht selected objects in Object Browser
   emit selectionChanged();
 }
 
index 23560ca86031d369571e2dcf5d864eb5a43d675e..20436bfbd30681390e053b80b3ec287c44d053c1 100644 (file)
@@ -455,7 +455,6 @@ void XGUI_Viewer::addView(QMdiSubWindow* theView)
 
 //    connect(aWindow, SIGNAL(contextMenuRequested( QContextMenuEvent* )),
 //            this,    SLOT  (onContextMenuRequested( QContextMenuEvent* )));
-
     connect(aWindow, SIGNAL(mouseMoving(XGUI_ViewWindow*, QMouseEvent*)),
             this, SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
 
@@ -498,17 +497,26 @@ void XGUI_Viewer::onWindowMinimized(QMdiSubWindow* theWnd)
   }
 }
 
+/*!
+  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());
   }
 }
 
@@ -517,7 +525,41 @@ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
 */
 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();
 }
index 23d66656a92bf3badab36e66d613ce5dd5630665..b422e4034432576fb6f54861c0f180a1be0c78b9 100644 (file)
@@ -74,6 +74,13 @@ public:
   /// \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); }
@@ -142,8 +149,8 @@ signals:
   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*);
@@ -153,6 +160,7 @@ private slots:
   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);
@@ -179,6 +187,9 @@ private:
   QList<QMdiSubWindow*> myViews;
 
   QMdiSubWindow* myActiveView;
+
+  /// Points used for selection management
+  QPoint myStartPnt, myEndPnt, myCurPnt;
 };
 
 #endif