]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Raw development for ImageViewer.
authorouv <ouv@opencascade.com>
Fri, 28 Jun 2013 12:37:12 +0000 (12:37 +0000)
committerouv <ouv@opencascade.com>
Fri, 28 Jun 2013 12:37:12 +0000 (12:37 +0000)
src/GraphicsView/GraphicsView_Object.h
src/GraphicsView/GraphicsView_PrsImage.cxx
src/GraphicsView/GraphicsView_PrsImage.h
src/GraphicsView/GraphicsView_PrsImageFrame.cxx
src/GraphicsView/GraphicsView_PrsImageFrame.h
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/Makefile.am

index 3208ba3b6a39bc4940c182ef5693e92337947dbe..40c8918670d4d92a2843d6677f53fb2e6b200705 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "GraphicsView.h"
 
+#include "GraphicsView_Defs.h"
+
 #include <QGraphicsItemGroup>
 
 class GraphicsView_ViewPort;
@@ -79,8 +81,10 @@ public:
   virtual QRectF             getPullingRect() const { return getRect(); }
   virtual bool               portContains( const QPointF& ) { return false; }
   virtual bool               startPulling( const QPointF& ) { return false; }
-  virtual void               pull( const QPointF&, GraphicsView_Object* ) {}
-  virtual void               finishPulling() {}
+  virtual void               pull( const QPointF&,
+                                   GraphicsView_Object*,
+                                   const GraphicsView_ObjectList& ) {}
+  virtual void               finishPulling( const GraphicsView_ObjectList& ) {}
   virtual bool               isPulling() { return false; }
 
   virtual bool               handleMousePress( QGraphicsSceneMouseEvent* ) { return false; }
index 75475f75ee93489b20bc1e2d09cfc63d96a628bc..f327118f43167133af8e9d190de1491f6aae9b6d 100644 (file)
 #include <QGraphicsScene>
 #include <QGraphicsView>
 #include <QPainter>
-
-#include <gp_Vec2d.hxx>
+#include <QVector2D>
 
 #include <math.h>
 
+#define EPSILON 1e-6
 #define PI 3.14159265359
 
 //=======================================================================
@@ -364,31 +364,22 @@ QPointF GraphicsView_PrsImage::centerPoint()
 // Purpose  : 
 //================================================================
 void GraphicsView_PrsImage::processResize( const int theAnchor,
-                                           const QPointF& thePoint1,
-                                           const QPointF& thePoint2 )
+                                           const double theDX,
+                                           const double theDY )
 {
-  if( thePoint1 == thePoint2 )
+  if( fabs( theDX ) < EPSILON && fabs( theDY ) < EPSILON )
     return;
 
   if( !myPreviewPixmapItem->isVisible() )
     enablePreview( true );
 
-  QPixmap aCurrentPixmap = myPixmapItem->pixmap();
-  int aWidth = aCurrentPixmap.width();
-  int aHeight = aCurrentPixmap.height();
-
-  double aDX = thePoint2.x() - thePoint1.x();
-  double aDY = thePoint2.y() - thePoint1.y();
-
   double anAngle = -1 * myRotationAngle * PI / 180.;
 
-  gp_Pnt2d aPnt1( thePoint1.x(), thePoint1.y() );
-  gp_Pnt2d aPnt2( thePoint2.x(), thePoint2.y() );
-  gp_Vec2d aVec( aPnt1, aPnt2 );
-  gp_Vec2d aVecHor( 10, 0 );
+  QVector2D aVec( theDX, theDY );
+  QVector2D aVecHor( 10, 0 );
 
-  double aDist = aPnt1.Distance( aPnt2 );
-  double anAngle1 = aVec.Angle( aVecHor );
+  double aDist = sqrt( theDX * theDX + theDY * theDY );
+  double anAngle1 = computeAngle( aVec, aVecHor );
   double anAngle2 = anAngle1 - anAngle;
 
   double aSizeDX = aDist * cos( anAngle2 );
@@ -415,7 +406,7 @@ void GraphicsView_PrsImage::processResize( const int theAnchor,
       aSizeShift = QPointF( aSizeDX, 0 );
       break;
     case GraphicsView_PrsImageFrame::TopLeft:
-      aPosShift = QPointF( aDX, aDY );
+      aPosShift = QPointF( theDX, theDY );
       aSizeShift = QPointF( -aSizeDX, -aSizeDY );
       break;
     case GraphicsView_PrsImageFrame::TopRight:
@@ -432,12 +423,16 @@ void GraphicsView_PrsImage::processResize( const int theAnchor,
       break;
   }
 
-  aWidth += (int)aSizeShift.x();
-  aHeight += (int)aSizeShift.y();
-  if( aWidth < 10 || aHeight < 10 ) // tmp
+  QPixmap aCurrentPixmap = myPixmapItem->pixmap();
+  int aWidth = aCurrentPixmap.width();
+  int aHeight = aCurrentPixmap.height();
+
+  int aNewWidth = aWidth + (int)aSizeShift.x();
+  int aNewHeight = aHeight + (int)aSizeShift.y();
+  if( aNewWidth < 10 || aNewHeight < 10 ) // tmp
     return;
 
-  QPixmap aPixmap = myPixmap.scaled( aWidth, aHeight );
+  QPixmap aPixmap = myPixmap.scaled( aNewWidth, aNewHeight );
   myPreviewPixmapItem->setPixmap( aPixmap );
 
   myPreviewPixmapItem->setPos( pos() + aPosShift );
@@ -480,32 +475,36 @@ void GraphicsView_PrsImage::finishResize()
 }
 
 //================================================================
-// Function : processRotate
+// Function : computeRotationAngle
 // Purpose  : 
 //================================================================
-void GraphicsView_PrsImage::processRotate( const QPointF& thePoint1,
-                                           const QPointF& thePoint2 )
+double GraphicsView_PrsImage::computeRotationAngle( const QPointF& thePoint1,
+                                                    const QPointF& thePoint2 ) const
 {
-  if( thePoint1 == thePoint2 )
-    return;
-
-  if( !myPreviewPixmapItem->isVisible() )
-    enablePreview( true );
-
   QRectF aRect = getRect();
   QPointF aCenter = aRect.center();
 
-  gp_Pnt2d aPnt0( aCenter.x(), aCenter.y() );
-  gp_Pnt2d aPnt1( thePoint1.x(), thePoint1.y() );
-  gp_Pnt2d aPnt2( thePoint2.x(), thePoint2.y() );
-
-  gp_Vec2d aVec1( aPnt0, aPnt1 );
-  gp_Vec2d aVec2( aPnt0, aPnt2 );
+  QVector2D aVec1( thePoint1 - aCenter );
+  QVector2D aVec2( thePoint2 - aCenter );
 
-  double anAngle = aVec1.Angle( aVec2 );
+  double anAngle = computeAngle( aVec1, aVec2 );
   double anAngleDeg = anAngle / PI * 180.;
+  return anAngleDeg;
+}
+
+//================================================================
+// Function : processRotate
+// Purpose  : 
+//================================================================
+void GraphicsView_PrsImage::processRotate( const double theAngle )
+{
+  if( fabs( theAngle ) < EPSILON )
+    return;
 
-  myPreviewRotationAngle = myRotationAngle + anAngleDeg;
+  if( !myPreviewPixmapItem->isVisible() )
+    enablePreview( true );
+
+  myPreviewRotationAngle = myRotationAngle + theAngle;
   setRotationAroundCenter( myPreviewPixmapItem, myPreviewRotationAngle );
 }
 
@@ -542,3 +541,25 @@ void GraphicsView_PrsImage::enablePreview( const bool theState )
   else
     myPreviewPixmapItem->setVisible( false );
 }
+
+//================================================================
+// Function : computeAngle
+// Purpose  : 
+//================================================================
+double GraphicsView_PrsImage::computeAngle( const QVector2D& theVector1,
+                                            const QVector2D& theVector2 )
+{
+  if( theVector1.isNull() || theVector2.isNull() )
+    return 0.0;
+
+  double aDotProduct = QVector2D::dotProduct( theVector1, theVector2 );
+  double aCos = aDotProduct / theVector1.length() / theVector2.length();
+
+  double aCrossProduct = theVector1.x() * theVector2.y() - theVector1.y() * theVector2.x();
+
+  double anAngle = acos( aCos );
+  if( aCrossProduct < 0 )
+    anAngle *= -1;
+
+  return anAngle;
+}
index 7351792667d52afe8d8157dc78ea3044d218d313..a63440c4ee43b443d3f4dd265a28a4bf122f2978 100644 (file)
@@ -80,17 +80,22 @@ public:
 
 protected:
   void                            processResize( const int theAnchor,
-                                                 const QPointF& thePoint1,
-                                                 const QPointF& thePoint2 );
+                                                 const double theDX,
+                                                 const double theDY );
   void                            finishResize();
 
-  void                            processRotate( const QPointF& thePoint1,
-                                                 const QPointF& thePoint2 );
+  double                          computeRotationAngle( const QPointF& thePoint1,
+                                                        const QPointF& thePoint2 ) const;
+
+  void                            processRotate( const double theAngle );
   void                            finishRotate();
 
 protected:
   void                            enablePreview( const bool theState );
 
+  static double                   computeAngle( const QVector2D& theVector1,
+                                                const QVector2D& theVector2 );
+
 protected:
   QPixmap                         myPixmap;
 
index b14dba132aa1e36cd5b0ebb27b200021ec473694..d3ebcdd32ae0dfa8c85ff9211a1a5337fe77ed11 100644 (file)
 #include <QCursor>
 #include <QPainter>
 
+#include <math.h>
+
+#define PI 3.14159265359
+
 #define ANCHOR_RADIUS 10
 
 //=======================================================================
@@ -208,22 +212,64 @@ bool GraphicsView_PrsImageFrame::startPulling( const QPointF& thePoint )
 // Function : pull
 // Purpose  : 
 //================================================================
-void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint, GraphicsView_Object* )
+void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint,
+                                       GraphicsView_Object* theLockedObject, // unused
+                                       const GraphicsView_ObjectList& theSyncObjects )
 {
   if( !myPrsImage )
     return;
 
+  if( thePoint == myPullingPoint )
+    return;
+
+  double aDX = thePoint.x() - myPullingPoint.x();
+  double aDY = thePoint.y() - myPullingPoint.y();
+
+  double aDAngle = myPrsImage->computeRotationAngle( myPullingPoint, thePoint );
+
   if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
-    myPrsImage->processResize( myPullingAnchor, myPullingPoint, thePoint );
+    myPrsImage->processResize( myPullingAnchor, aDX, aDY );
   else if( myPullingAnchor == TopMost )
-    myPrsImage->processRotate( myPullingPoint, thePoint );
+    myPrsImage->processRotate( aDAngle );
+
+  QRectF aRect = myPrsImage->getRect();
+  double anAngle = 0;
+  myPrsImage->getRotationAngle( anAngle );
+
+  GraphicsView_ObjectListIterator anIter( theSyncObjects );
+  while( anIter.hasNext() )
+  {
+    if( GraphicsView_PrsImage* aPrsImage = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
+    {
+      if( aPrsImage != myPrsImage )
+      {
+        if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+        {
+          QRectF aRectRef = aPrsImage->getRect();
+          double anAngleRef = 0;
+          aPrsImage->getRotationAngle( anAngleRef );
+
+          double aDXRef = aDX * aRectRef.width() / aRect.width();
+          double aDYRef = aDY * aRectRef.height() / aRect.height();
+
+          double anAngleDiff = ( anAngleRef - anAngle ) * PI / 180.;
+          double aDXRefTrans = aDXRef * cos( anAngleDiff ) - aDYRef * sin( anAngleDiff );
+          double aDYRefTrans = aDXRef * sin( anAngleDiff ) + aDYRef * cos( anAngleDiff );
+
+          aPrsImage->processResize( myPullingAnchor, aDXRefTrans, aDYRefTrans );
+        }
+        else if( myPullingAnchor == TopMost )
+          aPrsImage->processRotate( aDAngle );
+      }
+    }
+  }
 }
 
 //================================================================
 // Function : finishPulling
 // Purpose  : 
 //================================================================
-void GraphicsView_PrsImageFrame::finishPulling()
+void GraphicsView_PrsImageFrame::finishPulling( const GraphicsView_ObjectList& theSyncObjects )
 {
   if( !myPrsImage )
     return;
@@ -232,6 +278,21 @@ void GraphicsView_PrsImageFrame::finishPulling()
     myPrsImage->finishResize();
   else if( myPullingAnchor == TopMost )
     myPrsImage->finishRotate();
+
+  GraphicsView_ObjectListIterator anIter( theSyncObjects );
+  while( anIter.hasNext() )
+  {
+    if( GraphicsView_PrsImage* aPrsImage = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
+    {
+      if( aPrsImage != myPrsImage )
+      {
+        if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+          aPrsImage->finishResize();
+        else if( myPullingAnchor == TopMost )
+          aPrsImage->finishRotate();
+      }
+    }
+  }
 }
 
 //================================================================
index f71771ef00741555165ef3c91fbee75c4e4506b4..07b443a86e76c98aa85a8831a6eb1fffb993d4a2 100644 (file)
@@ -65,8 +65,10 @@ public:
   virtual QRectF                  getPullingRect() const;
   virtual bool                    portContains( const QPointF& ) { return false; } // useless
   virtual bool                    startPulling( const QPointF& );
-  virtual void                    pull( const QPointF&, GraphicsView_Object* );
-  virtual void                    finishPulling();
+  virtual void                    pull( const QPointF&,
+                                        GraphicsView_Object*,
+                                        const GraphicsView_ObjectList& );
+  virtual void                    finishPulling( const GraphicsView_ObjectList& );
   virtual bool                    isPulling() { return myIsPulling; }
 
   virtual QPointF                 centerPoint();
index e323de9b29bc90890271bbde3d3982134a707a0d..8892099ceec5219fc74380c825afcb6daf2d6996 100644 (file)
@@ -1361,7 +1361,7 @@ void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
     }
   }
 
-  myPullingObject->pull( thePoint, aLockedObject );
+  myPullingObject->pull( thePoint, aLockedObject, getSelectedObjects() );
 }
 
 //================================================================
@@ -1371,7 +1371,7 @@ void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
 void GraphicsView_ViewPort::finishPulling()
 {
   myIsPulling = false;
-  myPullingObject->finishPulling();
+  myPullingObject->finishPulling( getSelectedObjects() );
   setCursor( *getDefaultCursor() );
 }
 
index 3d9a613012675283dc92794e6dd4bef08287d6dd..688ce1fbee0f6168ece6ff7000d47998b24b7561 100644 (file)
@@ -81,6 +81,6 @@ nodist_salomeres_DATA =               \
        GraphicsView_msg_en.qm  \
        GraphicsView_msg_fr.qm
 
-libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) $(CAS_CPPFLAGS) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
-libGraphicsView_la_LDFLAGS  = $(QT_MT_LIBS) $(CAS_KERNEL)
+libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
+libGraphicsView_la_LDFLAGS  = $(QT_MT_LIBS)
 libGraphicsView_la_LIBADD   = ../SUIT/libsuit.la