]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
1) Smooth Transformation mode
authorouv <ouv@opencascade.com>
Fri, 5 Jul 2013 07:37:15 +0000 (07:37 +0000)
committerouv <ouv@opencascade.com>
Fri, 5 Jul 2013 07:37:15 +0000 (07:37 +0000)
2) Lock Aspect Ratio mode

src/GraphicsView/GraphicsView_PrsImage.cxx
src/GraphicsView/GraphicsView_PrsImage.h
src/GraphicsView/GraphicsView_PrsImageFrame.cxx
src/GraphicsView/GraphicsView_PrsPropDlg.cxx
src/GraphicsView/GraphicsView_PrsPropDlg.h
src/GraphicsView/GraphicsView_Viewer.cxx
src/GraphicsView/resources/GraphicsView_msg_en.ts

index bdfbac2673b4cd403f08056ffd87566d3a53c5de..45cefcd63c9a68ef7bb37fa7fc37b052c66a146f 100644 (file)
@@ -204,6 +204,26 @@ bool GraphicsView_PrsImage::getIsLockAspectRatio() const
   return myIsLockAspectRatio;
 }
 
+//================================================================
+// Function : setIsSmoothTransformation
+// Purpose  : 
+//================================================================
+void GraphicsView_PrsImage::setIsSmoothTransformation( const bool theIsSmoothTransformation )
+{
+  Qt::TransformationMode aMode = theIsSmoothTransformation ?
+    Qt::SmoothTransformation : Qt::FastTransformation;
+  myPixmapItem->setTransformationMode( aMode );
+}
+
+//================================================================
+// Function : getIsSmoothTransformation
+// Purpose  : 
+//================================================================
+bool GraphicsView_PrsImage::getIsSmoothTransformation() const
+{
+  return myPixmapItem->transformationMode() == Qt::SmoothTransformation;
+}
+
 //================================================================
 // Function : boundingRect
 // Purpose  : 
@@ -227,6 +247,7 @@ void GraphicsView_PrsImage::compute()
   if( !myPreviewPixmapItem )
   {
     myPreviewPixmapItem = new QGraphicsPixmapItem();
+    myPreviewPixmapItem->setTransformationMode( Qt::FastTransformation ); // always
     //addToGroup( myPreviewPixmapItem ); // don't add
   }
   if( !myPrsImageFrame )
@@ -391,56 +412,87 @@ void GraphicsView_PrsImage::processResize( const int theAnchor,
   double aSizeDX = aDist * cos( anAngle2 );
   double aSizeDY = -aDist * sin( anAngle2 );
 
-  QPointF aPosShift;
   QPointF aSizeShift;
   switch( theAnchor )
+  {
+    case GraphicsView_PrsImageFrame::Top:         aSizeShift = QPointF( 0, -aSizeDY ); break;
+    case GraphicsView_PrsImageFrame::Bottom:      aSizeShift = QPointF( 0, aSizeDY ); break;
+    case GraphicsView_PrsImageFrame::Left:        aSizeShift = QPointF( -aSizeDX, 0 ); break;
+    case GraphicsView_PrsImageFrame::Right:       aSizeShift = QPointF( aSizeDX, 0 ); break;
+    case GraphicsView_PrsImageFrame::TopLeft:     aSizeShift = QPointF( -aSizeDX, -aSizeDY ); break;
+    case GraphicsView_PrsImageFrame::TopRight:    aSizeShift = QPointF( aSizeDX, -aSizeDY ); break;
+    case GraphicsView_PrsImageFrame::BottomLeft:  aSizeShift = QPointF( -aSizeDX, aSizeDY ); break;
+    case GraphicsView_PrsImageFrame::BottomRight: aSizeShift = QPointF( aSizeDX, aSizeDY ); break;
+  }
+
+  double aWidth = (double)myPixmap.width() * myScaleX;
+  double aHeight = (double)myPixmap.height() * myScaleY;
+
+  double aNewWidth = aWidth + aSizeShift.x();
+  double aNewHeight = aHeight + aSizeShift.y();
+
+  double aRatio = fabs( aHeight ) > EPSILON ? aWidth / aHeight : 1.0;
+  double aNewRatio = fabs( aNewHeight ) > EPSILON ? aNewWidth / aNewHeight : 1.0;
+
+  double aDiffX = 0, aDiffY = 0; // only for TopLeft anchor
+  if( myIsLockAspectRatio && fabs( aRatio ) > EPSILON &&
+      ( theAnchor == GraphicsView_PrsImageFrame::TopLeft ||
+        theAnchor == GraphicsView_PrsImageFrame::TopRight ||
+        theAnchor == GraphicsView_PrsImageFrame::BottomLeft ||
+        theAnchor == GraphicsView_PrsImageFrame::BottomRight ) )
+  {
+    double aCurrentSizeShiftX = aSizeShift.x();
+    double aCurrentSizeShiftY = aSizeShift.y();
+
+    double aSign = myScaleX * myScaleY > 0 ? 1.0 : -1.0;
+    if( aSign * aNewRatio > aSign * aRatio )
+      aSizeShift.setY( aSizeShift.x() / aRatio );
+    else
+      aSizeShift.setX( aSizeShift.y() * aRatio );
+
+    aDiffX = aSizeShift.x() - aCurrentSizeShiftX;
+    aDiffY = aSizeShift.y() - aCurrentSizeShiftY;
+
+    aNewWidth = aWidth + aSizeShift.x();
+    aNewHeight = aHeight + aSizeShift.y();
+  }
+
+  QPointF aPosShift;
+  switch( theAnchor )
   {
     case GraphicsView_PrsImageFrame::Top:
-      aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) );
-      aSizeShift = QPointF( 0, -aSizeDY );
+      aPosShift = QPointF( -aSizeShift.y() * sin( anAngle ), -aSizeShift.y() * cos( anAngle ) );
       break;
     case GraphicsView_PrsImageFrame::Bottom:
       aPosShift = QPointF( 0, 0 );
-      aSizeShift = QPointF( 0, aSizeDY );
       break;
     case GraphicsView_PrsImageFrame::Left:
-      aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) );
-      aSizeShift = QPointF( -aSizeDX, 0 );
+      aPosShift = QPointF( -aSizeShift.x() * cos( anAngle ), aSizeShift.x() * sin( anAngle ) );
       break;
     case GraphicsView_PrsImageFrame::Right:
       aPosShift = QPointF( 0, 0 );
-      aSizeShift = QPointF( aSizeDX, 0 );
       break;
     case GraphicsView_PrsImageFrame::TopLeft:
-      aPosShift = QPointF( theDX, theDY );
-      aSizeShift = QPointF( -aSizeDX, -aSizeDY );
+      aPosShift = QPointF( theDX - aDiffX * cos( anAngle ) - aDiffY * sin( anAngle ),
+                           theDY + aDiffX * sin( anAngle ) - aDiffY * cos( anAngle ) );
       break;
     case GraphicsView_PrsImageFrame::TopRight:
-      aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) );
-      aSizeShift = QPointF( aSizeDX, -aSizeDY );
+      aPosShift = QPointF( -aSizeShift.y() * sin( anAngle ), -aSizeShift.y() * cos( anAngle ) );
       break;
     case GraphicsView_PrsImageFrame::BottomLeft:
-      aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) );
-      aSizeShift = QPointF( -aSizeDX, aSizeDY );
+      aPosShift = QPointF( -aSizeShift.x() * cos( anAngle ), aSizeShift.x() * sin( anAngle ) );
       break;
     case GraphicsView_PrsImageFrame::BottomRight:
       aPosShift = QPointF( 0, 0 );
-      aSizeShift = QPointF( aSizeDX, aSizeDY );
       break;
   }
 
-  double aWidth = (double)myPixmap.width() * myScaleX;
-  double aHeight = (double)myPixmap.height() * myScaleY;
-
-  double aNewWidth = aWidth + aSizeShift.x();
-  double aNewHeight = aHeight + aSizeShift.y();
+  myPreviewPosX = myPosX + aPosShift.x();
+  myPreviewPosY = myPosY + aPosShift.y();
 
   myPreviewScaleX = myScaleX * aNewWidth / aWidth;
   myPreviewScaleY = myScaleY * aNewHeight / aHeight;
 
-  myPreviewPosX = myPosX + aPosShift.x();
-  myPreviewPosY = myPosY + aPosShift.y();
-
   updateTransform();
 }
 
index c472225cb6c73126bab9e8750bf64112a0ae2372..b30999ee7258b31a0f2067d3eced5599761b7e81 100644 (file)
@@ -59,6 +59,9 @@ public:
   void                            setIsLockAspectRatio( const bool theIsLockAspectRatio );
   bool                            getIsLockAspectRatio() const;
 
+  void                            setIsSmoothTransformation( const bool theIsSmoothTransformation );
+  bool                            getIsSmoothTransformation() const;
+
 public:
   // from QGraphicsItem
   virtual QRectF                  boundingRect() const;
index 9a6f1d632368be2f76ae872b8808c91a09761f98..14951a3b91a031d06185f595fbfe9b8ada81ad08 100644 (file)
@@ -34,6 +34,7 @@
 
 #define FRAME_Z_VALUE   1000
 #define ANCHOR_RADIUS   3
+#define EPSILON         1e-6
 #define PI              3.14159265359
 
 //=======================================================================
@@ -484,9 +485,9 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c
 
   QTransform aTransform = aParent->getViewTransform();
   double aScale = aTransform.m11(); // same as m22(), viewer specific
-  if( fabs( aScale ) < 1e-10 ||
-      fabs( myScaleX ) < 1e-10 ||
-      fabs( myScaleY ) < 1e-10 )
+  if( fabs( aScale ) < EPSILON ||
+      fabs( myScaleX ) < EPSILON ||
+      fabs( myScaleY ) < EPSILON )
     return aRect;
 
   QPointF aCenter = aRect.center();
index 3a4e654d48fb7a79d7c7067524b27796270d4f3b..dd925c7e6034e98c1a4c2c93b1a8e78814d4d264 100644 (file)
@@ -40,59 +40,80 @@ GraphicsView_PrsPropDlg::GraphicsView_PrsPropDlg( QWidget* theParent )
 
   QFrame* aMainFrame = mainFrame();
 
-  QGroupBox* aPropGroup = new QGroupBox( aMainFrame );
-
-  QLabel* aPositionXLabel = new QLabel( tr( "POSITION_X" ), aPropGroup );
-  myPositionX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
-
-  QLabel* aPositionYLabel = new QLabel( tr( "POSITION_Y" ), aPropGroup );
-  myPositionY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
-
-  QLabel* aScalingXLabel = new QLabel( tr( "SCALING_X" ), aPropGroup );
-  myScalingX = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup );
-
-  QLabel* aScalingYLabel = new QLabel( tr( "SCALING_Y" ), aPropGroup );
-  myScalingY = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup );
-
-  QLabel* aRotationAngleLabel = new QLabel( tr( "ROTATION_ANGLE" ), aPropGroup );
-  myRotationAngle = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
-
-  QLabel* anOpacityLabel = new QLabel( tr( "OPACITY" ), aPropGroup );
-  myOpacity = new QtxDoubleSpinBox( 0, 1, 0.1, aPropGroup );
-
-  QLabel* aZValueLabel = new QLabel( tr( "Z_VALUE" ), aPropGroup );
-  myZValue = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
-
-  myIsLockAspectRatio = new QCheckBox( tr( "LOCK_ASPECT_RATIO" ), aPropGroup );
-
-  QGridLayout* aPropLayout = new QGridLayout( aPropGroup );
-  aPropLayout->setMargin( 5 );
-  aPropLayout->setSpacing( 5 );
-  aPropLayout->addWidget( aPositionXLabel,     0, 0 );
-  aPropLayout->addWidget( myPositionX,         0, 1 );
-  aPropLayout->addWidget( aPositionYLabel,     1, 0 );
-  aPropLayout->addWidget( myPositionY,         1, 1 );
-  aPropLayout->addWidget( aScalingXLabel,      2, 0 );
-  aPropLayout->addWidget( myScalingX,          2, 1 );
-  aPropLayout->addWidget( aScalingYLabel,      3, 0 );
-  aPropLayout->addWidget( myScalingY,          3, 1 );
-  aPropLayout->addWidget( aRotationAngleLabel, 4, 0 );
-  aPropLayout->addWidget( myRotationAngle,     4, 1 );
-  aPropLayout->addWidget( aZValueLabel,        5, 0 );
-  aPropLayout->addWidget( myZValue,            5, 1 );
-  aPropLayout->addWidget( anOpacityLabel,      6, 0 );
-  aPropLayout->addWidget( myOpacity,           6, 1 );
-  aPropLayout->addWidget( myIsLockAspectRatio, 7, 0, 1, 2 );
-  aPropLayout->setColumnStretch( 1, 1 );
+  // Geometry
+  QGroupBox* aGeomGroup = new QGroupBox( tr( "GEOMETRY" ), aMainFrame );
+
+  QLabel* aPositionXLabel = new QLabel( tr( "POSITION_X" ), aGeomGroup );
+  myPositionX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup );
+
+  QLabel* aPositionYLabel = new QLabel( tr( "POSITION_Y" ), aGeomGroup );
+  myPositionY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup );
+
+  QLabel* aScalingXLabel = new QLabel( tr( "SCALING_X" ), aGeomGroup );
+  myScalingX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup );
+
+  QLabel* aScalingYLabel = new QLabel( tr( "SCALING_Y" ), aGeomGroup );
+  myScalingY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup );
+
+  QLabel* aRotationAngleLabel = new QLabel( tr( "ROTATION_ANGLE" ), aGeomGroup );
+  myRotationAngle = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup );
+
+  QGridLayout* aGeomLayout = new QGridLayout( aGeomGroup );
+  aGeomLayout->setMargin( 5 );
+  aGeomLayout->setSpacing( 5 );
+  aGeomLayout->addWidget( aPositionXLabel,     0, 0 );
+  aGeomLayout->addWidget( myPositionX,         0, 1 );
+  aGeomLayout->addWidget( aPositionYLabel,     1, 0 );
+  aGeomLayout->addWidget( myPositionY,         1, 1 );
+  aGeomLayout->addWidget( aScalingXLabel,      2, 0 );
+  aGeomLayout->addWidget( myScalingX,          2, 1 );
+  aGeomLayout->addWidget( aScalingYLabel,      3, 0 );
+  aGeomLayout->addWidget( myScalingY,          3, 1 );
+  aGeomLayout->addWidget( aRotationAngleLabel, 4, 0 );
+  aGeomLayout->addWidget( myRotationAngle,     4, 1 );
+  aGeomLayout->setColumnStretch( 1, 1 );
+
+  // Representation
+  QGroupBox* aReprGroup = new QGroupBox( tr( "REPRESENTATION" ), aMainFrame );
+
+  QLabel* aZValueLabel = new QLabel( tr( "Z_VALUE" ), aReprGroup );
+  myZValue = new QtxDoubleSpinBox( -1e6, 1e6, 1, aReprGroup );
+
+  QLabel* anOpacityLabel = new QLabel( tr( "OPACITY" ), aReprGroup );
+  myOpacity = new QtxDoubleSpinBox( 0, 1, 0.1, aReprGroup );
+
+  QGridLayout* aReprLayout = new QGridLayout( aReprGroup );
+  aReprLayout->setMargin( 5 );
+  aReprLayout->setSpacing( 5 );
+  aReprLayout->addWidget( aZValueLabel,   0, 0 );
+  aReprLayout->addWidget( myZValue,       0, 1 );
+  aReprLayout->addWidget( anOpacityLabel, 1, 0 );
+  aReprLayout->addWidget( myOpacity,      1, 1 );
+  aReprLayout->setColumnStretch( 1, 1 );
+
+  // Interaction
+  QGroupBox* anInterGroup = new QGroupBox( tr( "INTERACTION" ), aMainFrame );
+
+  myIsLockAspectRatio = new QCheckBox( tr( "LOCK_ASPECT_RATIO" ), anInterGroup );
+  myIsSmoothTransformation = new QCheckBox( tr( "SMOOTH_TRANSFORMATION" ), anInterGroup );
+
+  QGridLayout* anInterLayout = new QGridLayout( anInterGroup );
+  anInterLayout->setMargin( 5 );
+  anInterLayout->setSpacing( 5 );
+  anInterLayout->addWidget( myIsLockAspectRatio,      0, 0 );
+  anInterLayout->addWidget( myIsSmoothTransformation, 1, 0 );
+  anInterLayout->setColumnStretch( 1, 1 );
 
   QVBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame );
   aMainLayout->setMargin( 5 );
   aMainLayout->setSpacing( 5 );
-  aMainLayout->addWidget( aPropGroup );
+  aMainLayout->addWidget( aGeomGroup );
+  aMainLayout->addWidget( aReprGroup );
+  aMainLayout->addWidget( anInterGroup );
 
   setButtonPosition( Center, OK );
   setButtonPosition( Center, Cancel );
-  setMinimumWidth( 300 );
+  setMinimumWidth( 250 );
 }
 
 //================================================================
@@ -114,7 +135,8 @@ void GraphicsView_PrsPropDlg::setData( const double thePositionX,
                                        const double theRotationAngle,
                                        const double theZValue,
                                        const double theOpacity,
-                                       const bool theIsLockAspectRatio )
+                                       const bool theIsLockAspectRatio,
+                                       const bool theIsSmoothTransformation )
 {
   myPositionX->setValue( thePositionX );
   myPositionY->setValue( thePositionY );
@@ -124,6 +146,7 @@ void GraphicsView_PrsPropDlg::setData( const double thePositionX,
   myZValue->setValue( theZValue );
   myOpacity->setValue( theOpacity );
   myIsLockAspectRatio->setChecked( theIsLockAspectRatio );
+  myIsSmoothTransformation->setChecked( theIsSmoothTransformation );
 }
 
 //=============================================================================
@@ -137,7 +160,8 @@ void GraphicsView_PrsPropDlg::getData( double& thePositionX,
                                        double& theRotationAngle,
                                        double& theZValue,
                                        double& theOpacity,
-                                       bool& theIsLockAspectRatio ) const
+                                       bool& theIsLockAspectRatio,
+                                       bool& theIsSmoothTransformation ) const
 {
   thePositionX = myPositionX->value();
   thePositionY = myPositionY->value();
@@ -147,4 +171,5 @@ void GraphicsView_PrsPropDlg::getData( double& thePositionX,
   theZValue = myZValue->value();
   theOpacity = myOpacity->value();
   theIsLockAspectRatio = myIsLockAspectRatio->isChecked();
+  theIsSmoothTransformation = myIsSmoothTransformation->isChecked();
 }
index b870d4902a985f1969592002dfd9f07ea23a2202..f34723fbddf58355b2a76aa3243264d6b4a159aa 100644 (file)
@@ -51,7 +51,8 @@ public:
                                     const double theRotationAngle,
                                     const double theZValue,
                                     const double theOpacity,
-                                    const bool theIsLockAspectRatio );
+                                    const bool theIsLockAspectRatio,
+                                    const bool theIsSmoothTransformation );
 
   void                     getData( double& thePositionX,
                                     double& thePositionY,
@@ -60,7 +61,8 @@ public:
                                     double& theRotationAngle,
                                     double& theZValue,
                                     double& theOpacity,
-                                    bool& theIsLockAspectRatio ) const;
+                                    bool& theIsLockAspectRatio,
+                                    bool& theIsSmoothTransformation ) const;
 
 private:
   QtxDoubleSpinBox*        myPositionX;
@@ -68,9 +70,12 @@ private:
   QtxDoubleSpinBox*        myScalingX;
   QtxDoubleSpinBox*        myScalingY;
   QtxDoubleSpinBox*        myRotationAngle;
+
   QtxDoubleSpinBox*        myOpacity;
   QtxDoubleSpinBox*        myZValue;
+
   QCheckBox*               myIsLockAspectRatio;
+  QCheckBox*               myIsSmoothTransformation;
 };
 
 #endif
index 56c4bc2e6a3d1427f22bda81b181afd2715bbea5..cace48376fa72bdaf4a7811217fdb8b45e0d3227 100644 (file)
@@ -726,14 +726,17 @@ void GraphicsView_Viewer::onPrsProperties()
         double anOpacity = aPrs->opacity();
 
         bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
+        bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
 
         GraphicsView_PrsPropDlg aDlg( aViewPort );
         aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
-                      aZValue, anOpacity, anIsLockAspectRatio );
+                      aZValue, anOpacity, anIsLockAspectRatio,
+                      anIsSmoothTransformation );
         if( aDlg.exec() )
         {
           aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
-                        aZValue, anOpacity, anIsLockAspectRatio );
+                        aZValue, anOpacity, anIsLockAspectRatio,
+                        anIsSmoothTransformation );
 
           aPrs->setPosition( aPosX, aPosY );
           aPrs->setScaling( aScaleX, aScaleY );
@@ -743,6 +746,7 @@ void GraphicsView_Viewer::onPrsProperties()
           aPrs->setOpacity( anOpacity );
 
           aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
+          aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
 
           aPrs->compute();
         }
index dcb33723dc3859a00d7785af6c4e7548051a03ea..10b14bfa35d8bff1508dceb84157e345dfd3fb13 100644 (file)
       <source>PROPERTIES</source>
       <translation>Properties</translation>
     </message>
+    <message>
+      <source>GEOMETRY</source>
+      <translation>Geometry</translation>
+    </message>
     <message>
       <source>POSITION_X</source>
       <translation>Position X</translation>
       <source>ROTATION_ANGLE</source>
       <translation>Rotation angle</translation>
     </message>
+    <message>
+      <source>REPRESENTATION</source>
+      <translation>Representation</translation>
+    </message>
     <message>
       <source>Z_VALUE</source>
       <translation>Z value</translation>
       <source>OPACITY</source>
       <translation>Opacity</translation>
     </message>
+    <message>
+      <source>INTERACTION</source>
+      <translation>Interaction</translation>
+    </message>
     <message>
       <source>LOCK_ASPECT_RATIO</source>
       <translation>Lock aspect ratio</translation>
     </message>
+    <message>
+      <source>SMOOTH_TRANSFORMATION</source>
+      <translation>Smooth transformation</translation>
+    </message>
   </context>
 </TS>