Salome HOME
size of image is limited by 7000 pixels
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeImage.cxx
index 3d5199656b4476fdd4db7a80643ff37f836e7209..765e75d615d7f9e3751439d8b9386f1b7b672c8f 100644 (file)
 #include <HYDROData_Document.h>
 
 #include <gp_Pnt.hxx>
+#include <QMessageBox>
+#include <QApplication>
+#include <QDesktopWidget>
 
 HYDROGUI_ShapeImage::HYDROGUI_ShapeImage( const Handle(AIS_InteractiveContext)& theContext,
-                                          const Handle_HYDROData_Image&         theImage,
+                                          const Handle(HYDROData_Image)&         theImage,
                                           const int                             theZLayer )
 : HYDROGUI_Shape( theContext, theImage, theZLayer )
 {
@@ -46,17 +49,26 @@ void HYDROGUI_ShapeImage::update( bool theIsUpdateViewer, bool isDeactivateSelec
   HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
 }
 
-Handle(AIS_InteractiveObject) HYDROGUI_ShapeImage::createShape() const
+QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeImage::createShape() const
 {
-    Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
-    if ( anImageObj.IsNull() )
-        return Handle_AIS_InteractiveObject();
+  QList<Handle(AIS_InteractiveObject)> shapes;
 
-    Handle(HYDROGUI_ImagePrs) aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj ), imageContour( anImageObj ) );
-    return aPrs;
+  Handle(HYDROGUI_ImagePrs) aPrs;
+
+  Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( getObject() );
+  if ( !anImageObj.IsNull() )
+  {
+       QString aMsg;
+    aPrs = new HYDROGUI_ImagePrs( imagePixMap( anImageObj, aMsg ), imageContour( anImageObj ) );
+       if( !aMsg.isEmpty() )
+               QMessageBox::warning( qApp->desktop(), "Warning", aMsg ); 
+    shapes.append( aPrs );
+  }
+
+  return shapes;
 }
 
-Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj ) const
+Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Image)& theImageObj, QString& theMessage ) const
 {
     Handle(Image_PixMap) aPix;
     if ( !theImageObj.IsNull() )
@@ -73,7 +85,14 @@ Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Im
             if ( aDelta > 0 )
                 aTrsfWidth += ( 4 - aDelta );
       
+                       const int maxWidth = 7000;
+                       if( aTrsfWidth>maxWidth )
+                       {
+                               aTrsfWidth = maxWidth;
+                               theMessage = QString( "The size of image is scaled to %0" ).arg( aTrsfWidth );
+                       }
             anImage = anImage.scaledToWidth( aTrsfWidth );
+                       int pix = anImage.width() * anImage.height();
 
             aPix = HYDROGUI_Tool::Pixmap( anImage );
         }
@@ -81,7 +100,7 @@ Handle(Image_PixMap) HYDROGUI_ShapeImage::imagePixMap( const Handle(HYDROData_Im
     return aPix;
 }
 
-QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle_HYDROData_Image& theImageObj ) const
+QPolygonF HYDROGUI_ShapeImage::imageContour( const Handle(HYDROData_Image)& theImageObj ) const
 {
     QPolygonF aContour;
     if ( !theImageObj.IsNull() )