Salome HOME
epaisseur des polylignes = 2
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PrsImage.cxx
index 34307fda02c8afb371f07f5a74f501470c39d6cf..a146d2546623de999c861b0680b62181e5f2fd8b 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -39,6 +35,7 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Entity)& theObject
   myCaptionItem( 0 ),
   myPrsImageFrame( 0 ),
   myIsTransformationPointPreview( false ),
+  myIsByTwoPoints( true ),
   myTransformationPointType( None )
 {
   myTransformationPointCursor = new QCursor( Qt::CrossCursor );
@@ -61,9 +58,13 @@ HYDROGUI_PrsImage::~HYDROGUI_PrsImage()
 // Function : setImage
 // Purpose  : 
 //================================================================
-void HYDROGUI_PrsImage::setImage( const QImage& theImage )
+void HYDROGUI_PrsImage::setImage( const QImage& theImage, const bool theCompute )
 {
   myImage = theImage;
+  if ( theCompute ) {
+    compute();
+    computeTransformationPoints( true );
+  }
 }
 
 //================================================================
@@ -156,6 +157,16 @@ void HYDROGUI_PrsImage::updateTransformationPoint( const int thePointType,
   }
 }
 
+//================================================================
+// Function : setTransformationPointCursorShape
+// Purpose  : 
+//================================================================
+void HYDROGUI_PrsImage::setTransformationPointCursorShape(Qt::CursorShape theCursorShape)
+{
+  if ( myTransformationPointCursor )
+    myTransformationPointCursor->setShape(theCursorShape);
+}
+
 //================================================================
 // Function : boundingRect
 // Purpose  : 
@@ -292,72 +303,91 @@ void HYDROGUI_PrsImage::setSelected( bool theState )
 // Function : computeTransformationPoints
 // Purpose  : 
 //================================================================
-void HYDROGUI_PrsImage::computeTransformationPoints()
+void HYDROGUI_PrsImage::computeTransformationPoints( const bool theObligatoryInit )
 {
-  if( myTransformationPointMap.isEmpty() )
   {
-    int aWidth = myImage.width();
-    int aHeight = myImage.height();
-
-    // Create presentations for transformation points A, B and C
     for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
     {
-      TransformationPoint aTransformationPoint;
-
-      QPoint aPoint;
-      QString aCaption;
-      QColor aColor = Qt::black;
-      switch( aPointType )
-      {
-        case PointA:
-          aPoint = QPoint( 0, 0 );
-          aCaption = "A";
-          aColor = Qt::darkRed;
-          break;
-        case PointB:
-          aPoint = QPoint( aWidth, 0 );
-          aCaption = "B";
-          aColor = Qt::darkGreen;
-          break;
-        case PointC:
-          aPoint = QPoint( 0, aHeight );
-          aCaption = "C";
-          aColor = Qt::darkBlue;
-          break;
-      }
-      
-      aTransformationPoint.Point = aPoint;
-      aTransformationPoint.Caption = aCaption;
-
-      aTransformationPoint.PointItem = new QGraphicsEllipseItem( this );
-      aTransformationPoint.PointItem->setVisible( false );
-      aTransformationPoint.PointItem->setPen( QPen( aColor ) );
-      aTransformationPoint.PointItem->setBrush( QBrush( aColor ) );
-
-      double aRadius = 3;
-      QRectF aRect( -QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
-      aTransformationPoint.PointItem->setRect( aRect );
-      aTransformationPoint.PointItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
-      aTransformationPoint.PointItem->setPos( aPoint );
-
-      aTransformationPoint.CaptionItem = new QGraphicsSimpleTextItem( aCaption, this );
-      aTransformationPoint.CaptionItem->setVisible( false );
-      aTransformationPoint.CaptionItem->setPen( QPen( aColor ) );
-      aTransformationPoint.CaptionItem->setBrush( QBrush( aColor ) );
-      QFont aFont = aTransformationPoint.CaptionItem->font();
-      aFont.setPointSize( qApp->font().pointSize() );
-      aTransformationPoint.CaptionItem->setFont( aFont );
-      aTransformationPoint.CaptionItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
-
-      myTransformationPointMap[ aPointType ] = aTransformationPoint;
+      if( myTransformationPointMap.isEmpty() || theObligatoryInit )
+        initTrsfPoints( aPointType );
+      // Show/hide the point if necessary
+      updateTrsfPoint( aPointType );
+
     }
   }
+}
+
+QGraphicsItemGroup* HYDROGUI_PrsImage::createPointItem( const QString& theCaption,
+                                                        const QColor& theColor )
+{
+  QGraphicsEllipseItem* aPointItem = new QGraphicsEllipseItem( this );
+  aPointItem->setPen( QPen( theColor ) );
+  aPointItem->setBrush( QBrush( theColor ) );
 
-  for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
+  double aRadius = 3;
+  QRectF aRect( -QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
+  aPointItem->setRect( aRect );
+  aPointItem->setPos( QPointF( 0, 0 ) );
+
+  QGraphicsSimpleTextItem* aCaptionItem = aCaptionItem = new QGraphicsSimpleTextItem( theCaption, this );
+  aCaptionItem->setPen( QPen( theColor ) );
+  aCaptionItem->setBrush( QBrush( theColor ) );
+  QFont aFont = aCaptionItem->font();
+  aFont.setPointSize( qApp->font().pointSize() );
+  aCaptionItem->setFont( aFont );
+  aCaptionItem->setPos( QPointF( -aRadius * 2, aRadius * 2 ) );
+
+  QGraphicsItemGroup* aGroupItem = new QGraphicsItemGroup( this );
+  aGroupItem->addToGroup( aPointItem );
+  aGroupItem->addToGroup( aCaptionItem );
+  aGroupItem->setVisible( false );
+  aGroupItem->setFlag( QGraphicsItem::ItemIgnoresTransformations );
+
+  return aGroupItem;
+}
+
+//================================================================
+// Function : initTrsfPoints
+// Purpose  : 
+//================================================================
+void HYDROGUI_PrsImage::initTrsfPoints( const int thePointType )
+{
+  QPoint aPoint;
+  QString aCaption;
+  QColor aColor = Qt::black;
+
+  int aWidth = myImage.width();
+  int aHeight = myImage.height();
+  switch( thePointType )
   {
-    // Show/hide the point if necessary
-    updateTrsfPoint( aPointType );
+    case PointA:
+      aPoint = QPoint( 0, 0 );
+      aCaption = "A";
+      aColor = Qt::darkRed;
+      break;
+    case PointB:
+      aPoint = QPoint( aWidth, 0 );
+      aCaption = "B";
+      aColor = Qt::darkGreen;
+      break;
+    case PointC:
+      aPoint = QPoint( 0, aHeight );
+      aCaption = "C";
+      aColor = Qt::darkBlue;
+      break;
   }
+
+  TransformationPoint aTransformationPoint;
+  if ( myTransformationPointMap.contains( thePointType ) )
+    aTransformationPoint = myTransformationPointMap[thePointType];
+
+  aTransformationPoint.Point = aPoint;
+  aTransformationPoint.Caption = aCaption;
+  if ( !aTransformationPoint.GroupItem )
+    aTransformationPoint.GroupItem = createPointItem( aCaption, aColor );
+  aTransformationPoint.GroupItem->setPos( aPoint );
+
+  myTransformationPointMap[ thePointType ] = aTransformationPoint;
 }
 
 //================================================================
@@ -372,14 +402,9 @@ void HYDROGUI_PrsImage::updateTrsfPoint( const int thePointType )
 
   TransformationPoint& aTransformationPoint = myTransformationPointMap[ thePointType ];
 
-  double aRadius = 3;
   const QPointF& aPoint = aTransformationPoint.Point;
-  aTransformationPoint.PointItem->setPos( aPoint );
-  aTransformationPoint.PointItem->setVisible( anIsPointVisible );
-
-  QPointF aCaptionShift( -aRadius * 2, aRadius * 2 );
-  aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift );
-  aTransformationPoint.CaptionItem->setVisible( anIsPointVisible );
+  aTransformationPoint.GroupItem->setPos( aPoint );
+  aTransformationPoint.GroupItem->setVisible( anIsPointVisible );
 }
 
 //================================================================