]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Refs #279 - Copy for the view position coordinates
authornds <nds@opencascade.com>
Fri, 27 Dec 2013 10:07:21 +0000 (10:07 +0000)
committernds <nds@opencascade.com>
Fri, 27 Dec 2013 10:07:21 +0000 (10:07 +0000)
src/HYDROGUI/HYDROGUI_CopyPastePositionOp.cxx
src/HYDROGUI/HYDROGUI_Displayer.cxx
src/HYDROGUI/HYDROGUI_Displayer.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h

index 0139ce9ce95bcfe50be20cb1292bb3264d0bd481..55a41afc8ec84ef57713cba14100329ee4a943c9 100644 (file)
@@ -56,8 +56,7 @@ void HYDROGUI_CopyPastePositionOp::startOperation()
       SUIT_ViewManager* aViewMgr = aModule->getApp()->activeViewManager();
       SUIT_ViewWindow* aViewWindow = aViewMgr ? aViewMgr->getActiveView() : 0;
       double aX, aY, aZ;
-      if ( aDisplayer->GetCursorViewCoordinates( aViewWindow, aModule->getPopupPosition(),
-                                                 aX, aY, aZ ) )
+      if ( aDisplayer->GetCursorViewCoordinates( aViewWindow, aX, aY, aZ ) )
         aResult = tr( "%1,%2" ).arg( aX ).arg( aY );
     }
     if ( !aResult.isEmpty() ) {
index 39cb1f54f1e2758e6a3bb9d96a477c8a6e4a8c20..030ca3ed783848c2bf435998384ec16239dc5690 100644 (file)
 
 #include <CurveCreator_Utils.h>
 
+#include <LightApp_Application.h>
 #include <SVTK_ViewWindow.h>
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
+#include <SUIT_ViewManager.h>
 
 #include <vtkRenderWindowInteractor.h>
 #include <vtkRenderer.h>
@@ -47,7 +49,8 @@
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
 
 HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
-: HYDROGUI_AbstractDisplayer( theModule )
+: HYDROGUI_AbstractDisplayer( theModule ),
+  myXPosition( -1 ), myYPosition( -1 ), myIsPositionSaved( false )
 {
 }
 
@@ -236,9 +239,55 @@ QString HYDROGUI_Displayer::GetType() const
   return GraphicsView_Viewer::Type();
 }
 
-#include <iostream>
+void HYDROGUI_Displayer::SaveCursorViewPosition( SUIT_ViewWindow* theViewWindow )
+{
+  myIsPositionSaved = false;
+  myXPosition = 0;
+  myYPosition = 0;
+
+  SUIT_ViewWindow* aViewWindow = theViewWindow;
+  if ( !theViewWindow ) {
+    SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager();
+    aViewWindow = aViewMgr ? aViewMgr->getActiveView() : 0;
+    if ( !aViewWindow )
+      return;
+  }
+  
+  OCCViewer_ViewWindow* anOCCViewWindow = 
+    dynamic_cast<OCCViewer_ViewWindow*>( aViewWindow );
+  if ( anOCCViewWindow ) {
+    // Get the selected point coordinates
+    OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort();
+    if ( aViewPort ) {
+      QPoint aViewPos = aViewPort->mapFromGlobal( QCursor::pos() );
+      myXPosition = aViewPos.x();
+      myYPosition = aViewPos.y();
+      myIsPositionSaved = true;
+    }
+  }
+  else {
+    SVTK_ViewWindow* aVTKViewWindow = 
+      dynamic_cast<SVTK_ViewWindow*>(aViewWindow);
+    if ( aVTKViewWindow ) {
+      vtkRenderer* aRen = aVTKViewWindow->getRenderer();
+      if ( aRen )
+      {
+        vtkCamera* aCamera = aRen->GetActiveCamera();
+        double* aNormal = aCamera->GetViewPlaneNormal();
+        vtkRenderWindowInteractor* anInteractor = aVTKViewWindow->getInteractor();
+        if ( anInteractor )
+        {
+          anInteractor->GetLastEventPosition( myXPosition, myYPosition );
+          myIsPositionSaved = true;
+        }
+      }
+    }
+  }
+  if (!myIsPositionSaved)
+    int aValue = 0;
+}
+
 bool HYDROGUI_Displayer::GetCursorViewCoordinates( SUIT_ViewWindow* theViewWindow,
-                                                   const QPoint& theCursorPos,
                                                    double& theXCoordinate,
                                                    double& theYCoordinate,
                                                    double& theZCoordinate )
@@ -246,9 +295,8 @@ bool HYDROGUI_Displayer::GetCursorViewCoordinates( SUIT_ViewWindow* theViewWindo
   theXCoordinate = 0;
   theYCoordinate = 0;
   theZCoordinate = 0;
-  
   bool doShow = false;
-  if ( !theViewWindow )
+  if ( !theViewWindow || !myIsPositionSaved )
     return doShow;
   
   OCCViewer_ViewWindow* anOCCViewWindow = 
@@ -259,64 +307,52 @@ bool HYDROGUI_Displayer::GetCursorViewCoordinates( SUIT_ViewWindow* theViewWindo
     if ( !aViewPort ) {
       return doShow;
     }
-    QPoint aViewPos = aViewPort->mapFromGlobal( theCursorPos );
-    gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( aViewPos.x(), aViewPos.y(),
+    gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( myXPosition, myYPosition,
                                                            aViewPort->getView() );
     theXCoordinate = aPnt.X();
     theYCoordinate = aPnt.Y();
-    //std::cout << "Coordinates: " << theCursorPos.x() << ", " << theCursorPos.y() << std::endl;
     doShow = true;
   } 
   else
   {
-    SVTK_ViewWindow* aViewWindow = 
+    SVTK_ViewWindow* aVTKViewWindow = 
       dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
-    if ( aViewWindow ) {
-      vtkRenderer* aRen = aViewWindow->getRenderer();
+    if ( aVTKViewWindow ) {
+      vtkRenderer* aRen = aVTKViewWindow->getRenderer();
       if ( aRen )
       {
         vtkCamera* aCamera = aRen->GetActiveCamera();
         double* aNormal = aCamera->GetViewPlaneNormal();
-        int event_x, event_y;
-        vtkRenderWindowInteractor* anInteractor = aViewWindow->getInteractor();
-        if ( anInteractor )
-        {
-          anInteractor->GetLastEventPosition(event_x, event_y);
-          // Use a WorldPicker to get current coords
-          //std::cout << "Coordinates: " << theCursorPos.x() << ", " << theCursorPos.y() << std::endl;
-          //SVTK_RenderWindowInteractor* anInteractor = 
-          //std::cout << "VTK Coordinates: " << event_x << ", " << event_y << std::endl;
-          myPicker->Pick( event_x, event_y, 0, aRen );
-          double* aCoords = myPicker->GetPickPosition();
-          /////////////////////// Use the same algorithm as for OCC
-          double X, Y, Z;
-          double aXp, aYp, aZp;
-          double Vx, Vy, Vz;
-          X = aCoords[0];
-          Y = aCoords[1];
-          Z = aCoords[2];
-          Vx = aNormal[0];
-          Vy = aNormal[1];
-          Vz = aNormal[2];
-          Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
-          if ( fabs( Vz ) > aPrec ) {
-            double aT = -Z/Vz;
-            aXp = X + aT*Vx;
-            aYp = Y + aT*Vy;
-            aZp = Z + aT*Vz;
-          }
-          else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
-            aXp = aYp = aZp = 0;
-            if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
-              aYp = Y;
-            else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
-              aXp = X;
-          }
-          /////////////////////////
-          theXCoordinate = aXp;
-          theYCoordinate = aYp;
-          doShow = true;
+        myPicker->Pick( myXPosition, myYPosition, 0, aRen );
+        double* aCoords = myPicker->GetPickPosition();
+        /////////////////////// Use the same algorithm as for OCC
+        double X, Y, Z;
+        double aXp, aYp, aZp;
+        double Vx, Vy, Vz;
+        X = aCoords[0];
+        Y = aCoords[1];
+        Z = aCoords[2];
+        Vx = aNormal[0];
+        Vy = aNormal[1];
+        Vz = aNormal[2];
+        Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE;
+        if ( fabs( Vz ) > aPrec ) {
+          double aT = -Z/Vz;
+          aXp = X + aT*Vx;
+          aYp = Y + aT*Vy;
+          aZp = Z + aT*Vz;
+        }
+        else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ
+          aXp = aYp = aZp = 0;
+          if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane
+            aYp = Y;
+          else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane
+            aXp = X;
         }
+        /////////////////////////
+        theXCoordinate = aXp;
+        theYCoordinate = aYp;
+        doShow = true;
       }
     } 
   }
index c3dcfce3f95c365ec4e518bfc39423ade1d2f243..f99815ae0511ddeec48ac7a15e9846e3845e7a43 100644 (file)
@@ -65,17 +65,22 @@ public:
    */
   virtual QString  GetType() const;
 
+  /*
+   * Get the current cursor view position and save it in the displayer
+   * to be used in the obtaining the view coordinates of the cursor.
+   * \param theViewWindow a view window. If a view window is null, an active view is used
+   * only OCC and VTK views are processed
+   */
+  void             SaveCursorViewPosition( SUIT_ViewWindow* theViewWindow = 0 );
   /**
    * \brief Get the coodinates from the view window, projected on XOY plane
    * \param theViewWindow a view window
-   * \param theCursorPos a cursor position point
    * \param theXCoordinate a X coordinate
    * \param theXCoordinate an Y coordinate
    * \param theXCoordinate a Z coordinate, has a zero value because of the plane
    * \return true if the coordinates are got
    */
   bool             GetCursorViewCoordinates( SUIT_ViewWindow* theViewWindow,
-                                             const QPoint& theCursorPos,
                                              double& theXCoordinate,
                                              double& theYCoordinate,
                                              double& theZCoordinate );
@@ -124,6 +129,9 @@ private:
   typedef QMap< ObjectKind, HYDROGUI_PrsDriver* > PrsDriversMap;
   PrsDriversMap                   myPrsDriversMap;
   vtkNew<vtkWorldPointPicker>     myPicker;
+  int                             myXPosition;
+  int                             myYPosition;
+  bool                            myIsPositionSaved;
 };
 
 #endif
index 09cd00f85a37587359680c4b37a6453f03db52c5..ae7dad74097e96dc76ce2a207e81a399cdc7283a 100644 (file)
@@ -655,7 +655,6 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   if ( anIsOCCView || anIsVTKView ) {
     theMenu->addSeparator();
     theMenu->addAction( action( CopyViewerPositionId ) );
-    myPopupPos = QCursor::pos();
   }
 }
 
@@ -1457,7 +1456,8 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent*
   bool doShow = false;
   HYDROGUI_Displayer* aDisplayer = getDisplayer();
   if ( aDisplayer )
-    doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, QCursor::pos(), aX, aY, aZ );
+    aDisplayer->SaveCursorViewPosition( theViewWindow );
+    doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ );
 
   if ( doShow )
   {
@@ -1485,12 +1485,3 @@ int HYDROGUI_Module::getObjectDisplayOrder(
 
   return anObjectEntries.indexOf( anEntry );
 }
-
-/**
- * Get the popup menu position
- * \return the position
- */
-QPoint HYDROGUI_Module::getPopupPosition() const
-{
- return myPopupPos;
-}
index 1cfd15c837b815be5171ec8b64775ac96557cfc0..f4a87f481908b5427dc8f1ab715f6eda28f5abf4 100644 (file)
@@ -28,7 +28,6 @@
 #include <LightApp_Module.h>
 
 #include <QEvent>
-#include <QPoint>
 
 class QGraphicsSceneMouseEvent;
 
@@ -244,7 +243,6 @@ private:
 
   ViewId2ListOfShapes             myShapesMap;
   ViewId2ListOfVTKPrs             myVTKPrsMap;
-  QPoint                          myPopupPos;
   bool                            myIsUpdateEnabled;
 
   QStringList                     myGeomObjectsToImport; ///< entries of GEOM objects to be imported