Salome HOME
799c09f2b36eb4763ae8c2cba2d89e94ff5971fe
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Shape.h"
24
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Tool.h"
27
28 #include <AIS_Drawer.hxx>
29 #include <AIS_TexturedShape.hxx>
30
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <BRepBuilderAPI_MakeFace.hxx>
34
35 #include <gp_Pnt.hxx>
36
37 #include <Graphic3d_AspectFillArea3d.hxx>
38 #include <Graphic3d_MaterialAspect.hxx>
39
40 #include <HYDROData_Document.h>
41 #include <HYDROData_Image.h>
42 #include <HYDROData_ImmersibleZone.h>
43 #include <HYDROData_PolylineXY.h>
44 #include <HYDROData_Region.h>
45 #include <HYDROData_Zone.h>
46 #include <HYDROData_Obstacle.h>
47
48 #include <TopoDS.hxx>
49 #include <TopoDS_Wire.hxx>
50 #include <TopoDS_Face.hxx>
51
52 #include <TopExp_Explorer.hxx>
53
54 #include <BRep_Builder.hxx>
55
56 #include <Precision.hxx>
57
58 #include <Prs3d_ShadingAspect.hxx>
59 #include <Prs3d_LineAspect.hxx>
60 #include <Prs3d_IsoAspect.hxx>
61
62 #include <SUIT_MessageBox.h>
63
64 #include <QColor>
65 #include <QFile>
66
67 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
68                                 const Handle(HYDROData_Entity)&       theObject )
69 : myContext( theContext ),
70   myObject( theObject ),
71   myIsHighlight( false ),
72   myFillingColor( Qt::transparent ),
73   myBorderColor( Qt::black ),
74   myHighlightColor( Qt::white ),
75   myIsToUpdate( false ),
76   myIsVisible( true ),
77   myDisplayMode( AIS_WireFrame )
78 {
79 }
80
81 HYDROGUI_Shape::~HYDROGUI_Shape()
82 {
83   erase();
84
85   if ( !myShape.IsNull() )
86     myShape.Nullify();
87
88   removeTextureFile();
89 }
90
91 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
92 {
93   if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
94     return;
95
96   myContext->Display( myShape, theIsUpdateViewer );
97 }
98
99 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
100 {
101   if ( myContext.IsNull() || myShape.IsNull() )
102     return;
103
104   myContext->Erase( myShape, theIsUpdateViewer );
105 }
106
107 void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
108 {
109   setIsToUpdate( false );
110
111   if ( myContext.IsNull() )
112     return;
113
114   // Try to retrieve information from object
115   if ( !myObject.IsNull() )
116   {
117     Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
118   
119     if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
120     {
121       Handle(HYDROData_ImmersibleZone) aZoneObj =
122         Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
123
124       TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
125       if ( !aZoneShape.IsNull() ) {
126         if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
127           TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
128           setFace( aZoneFace, false, false );
129         } else {
130           myTopoShape = aZoneShape;
131           myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
132
133           buildShape();
134           updateShape( false, false );
135         }
136       }
137
138       QColor aFillingColor = aZoneObj->GetFillingColor();
139       QColor aBorderColor = aZoneObj->GetBorderColor();
140
141       setFillingColor( aFillingColor, false, false );
142       setBorderColor( aBorderColor, false, false );
143     }
144     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
145     {
146       Handle(HYDROData_PolylineXY) aPolyline =
147         Handle(HYDROData_PolylineXY)::DownCast( myObject );
148
149       TopoDS_Shape aPolylineShape = aPolyline->GetShape();
150
151       if ( !aPolylineShape.IsNull() ) {
152         if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
153           TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
154           setWire( aPolylineWire, false, false );  
155         } else {
156           myTopoShape = aPolylineShape;
157           myDisplayMode = AIS_WireFrame;
158
159           buildShape();
160           updateShape( false, false );
161         }
162       }
163     }
164     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
165     {
166       Handle(HYDROData_Zone) aZone =
167         Handle(HYDROData_Zone)::DownCast( myObject );
168
169       TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
170
171       // Generate the filling color for zone
172       QStringList aGeomObjectsNames;
173
174       HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
175       HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
176       for ( ; anIter.More(); anIter.Next() )
177       {
178         Handle(HYDROData_Object) aRefbject = 
179           Handle(HYDROData_Object)::DownCast( anIter.Value() );
180         if ( aRefbject.IsNull() )
181           continue;
182
183         QString aRefObjectName = aRefbject->GetName();
184         if ( aRefObjectName.isEmpty() )
185           continue;
186
187         aGeomObjectsNames.append( aRefObjectName );
188       }
189        
190       setFace( aZoneFace, false, false );
191       if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
192       {
193         // Red color for a zone with bathymetry conflict
194         setFillingColor( Qt::red );
195       }
196       else
197       {
198         setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
199       }
200     }
201     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
202     {
203       Handle(HYDROData_Image) anImageObj =
204         Handle(HYDROData_Image)::DownCast( myObject );
205
206       removeTextureFile();
207
208       QString aTextureFileName = generateTextureFileName( anImageObj );
209
210       QImage anImage = anImageObj->Image();
211       QString aFilePath = anImageObj->GetFilePath();
212       QTransform aTrsf = anImageObj->Trsf();
213
214       int aWidth = anImage.width();
215       int aHeight = anImage.height();
216
217       QTransform anInversion = QTransform::fromScale( -1, -1 );
218       anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
219
220       // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
221       int aTrsfWidth = anImage.width();
222       int aDelta = aTrsfWidth % 4;
223       if ( aDelta > 0 )
224       {
225         aTrsfWidth += ( 4 - aDelta );
226       }
227       anImage = anImage.scaledToWidth( aTrsfWidth );
228
229       // temporary optimization, to reduce the saved image size (and the texture quality)
230       QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
231
232       bool isSaved = anImageToSave.save( aTextureFileName );
233       if ( !isSaved ) {
234         QString aTitle = QObject::tr( "FILE_ERROR" );
235         QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
236         SUIT_MessageBox::warning( 0, aTitle, aMessage );
237       }
238
239       QPointF aPoint1( 0, 0 );            // 1: top left
240       QPointF aPoint2( aWidth, 0 );       // 2: top right
241       QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
242       QPointF aPoint4( 0, aHeight );      // 4: bottom left
243
244       aPoint1 = aTrsf.map( aPoint1 );
245       aPoint2 = aTrsf.map( aPoint2 );
246       aPoint3 = aTrsf.map( aPoint3 );
247       aPoint4 = aTrsf.map( aPoint4 );
248
249       QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
250       QRectF aRect = aPolygon.boundingRect();
251
252       gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
253       gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
254       gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
255       gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
256
257       TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
258       TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
259       TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
260       TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
261
262       TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
263       aWire.Closed( true );
264
265       setTextureFileName( aTextureFileName, false, false );
266       setFace( aWire, false, false );
267     }
268     else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
269     {
270       Handle(HYDROData_Obstacle) anObstacle =
271         Handle(HYDROData_Obstacle)::DownCast( myObject );
272
273       //TODO BEGIN of the block of code to be reimplemented
274       //TODO GetTopShape() to be used in future
275       myTopoShape = anObstacle->GetShape3D();
276       myDisplayMode = AIS_Shaded;
277
278       QColor aFillingColor = anObstacle->GetFillingColor();
279       QColor aBorderColor = anObstacle->GetBorderColor();
280
281       setFillingColor( aFillingColor, false, false );
282       setBorderColor( aBorderColor, false, false );
283
284       buildShape();
285       updateShape( false, false );
286       //TODO END of the block of code to be reimplemented
287     }
288   }
289  
290   if ( myShape.IsNull() || !isVisible() )
291     return;
292
293   myContext->Display( myShape, theIsUpdateViewer );
294 }
295
296 void HYDROGUI_Shape::setVisible( const bool theState,
297                                  const bool theIsUpdateViewer )
298 {
299   if ( myIsVisible == theState )
300     return;
301
302   myIsVisible = theState;
303
304   if ( myShape.IsNull() )
305     return;
306
307   if ( myIsVisible )
308     myContext->Display( myShape, theIsUpdateViewer );
309   else
310     myContext->Erase( myShape, theIsUpdateViewer );
311 }
312
313 void HYDROGUI_Shape::highlight( bool theIsHighlight )
314 {
315   if ( myIsHighlight == theIsHighlight )
316     return;
317
318   myIsHighlight = theIsHighlight;
319
320   if ( myContext.IsNull() || myShape.IsNull() )
321     return;
322
323   colorShapeBorder( getActiveColor() );
324   myContext->Display( myShape );
325 }
326
327 bool HYDROGUI_Shape::isHighlighted() const
328 {
329   return myIsHighlight;
330 }
331
332 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
333                               const bool         theToDisplay,
334                               const bool         theIsUpdateViewer )
335 {
336   myTopoShape = theWire;
337   myDisplayMode = AIS_WireFrame;
338
339   buildShape();
340   updateShape( theToDisplay, theIsUpdateViewer );
341 }
342
343 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
344                                const bool             theToDisplay,
345                                const bool             theIsUpdateViewer )
346 {
347   TopExp_Explorer anExp( theWires, TopAbs_WIRE );
348   TopoDS_Compound aCompound;
349   BRep_Builder aBuilder;
350     aBuilder.MakeCompound( aCompound );
351
352   for ( ; anExp.More(); anExp.Next() ) {
353     TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
354     if ( aWire.IsNull() ) {
355       continue;
356     }
357
358     BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
359     aMakeFace.Build();
360     if( aMakeFace.IsDone() ) {
361       aBuilder.Add( aCompound, aMakeFace.Face() );
362     }
363   }
364
365   myTopoShape = aCompound;
366   myDisplayMode = AIS_Shaded;
367
368   buildShape();
369   updateShape( theToDisplay, theIsUpdateViewer );
370 }
371
372 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
373                               const bool         theToDisplay,
374                               const bool         theIsUpdateViewer )
375 {
376   BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
377   aFaceBuilder.Build();
378   if( aFaceBuilder.IsDone() )
379   {
380     TopoDS_Face aFace = aFaceBuilder.Face();
381     setFace( aFace, theToDisplay, theIsUpdateViewer );
382   }
383 }
384
385 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
386                               const bool         theToDisplay,
387                               const bool         theIsUpdateViewer )
388 {
389   myTopoShape = theFace;
390   myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
391   //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
392   //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
393
394   buildShape();
395   updateShape( theToDisplay, theIsUpdateViewer );
396 }
397
398 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
399                                const bool          theToDisplay,
400                                const bool          theIsUpdateViewer )
401 {
402   myTopoShape = theShape;
403   myDisplayMode = AIS_Shaded;
404
405   buildShape();
406   updateShape( theToDisplay, theIsUpdateViewer );
407 }
408
409 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
410                                       const bool    theToDisplay,
411                                       const bool    theIsUpdateViewer )
412 {
413   myFillingColor = theColor;
414   updateShape( theToDisplay, theIsUpdateViewer );
415 }
416
417 QColor HYDROGUI_Shape::getFillingColor() const
418 {
419   return myFillingColor;
420 }
421
422 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
423                                      const bool    theToDisplay,
424                                      const bool    theIsUpdateViewer )
425 {
426   myBorderColor = theColor;
427   updateShape( theToDisplay, theIsUpdateViewer );
428 }
429
430 QColor HYDROGUI_Shape::getBorderColor() const
431 {
432   return myBorderColor;
433 }
434
435 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
436 {
437   myHighlightColor = theColor;
438 }
439
440 QColor HYDROGUI_Shape::getHighlightColor() const
441 {
442   return myHighlightColor;
443 }
444
445 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
446                                          const bool     theToDisplay,
447                                          const bool     theIsUpdateViewer )
448 {
449   myTextureFileName = theFileName;
450   updateShape( theToDisplay, theIsUpdateViewer );
451 }
452
453 QString HYDROGUI_Shape::getTextureFileName() const
454 {
455   return myTextureFileName;
456 }
457
458 void HYDROGUI_Shape::buildShape()
459 {
460   // Erase previously created shape
461   erase();
462
463   if ( myTopoShape.IsNull() )
464     return;
465
466   QString aTextureFileName = getTextureFileName();
467   bool anIsTexture = !aTextureFileName.isEmpty();
468
469   if ( anIsTexture )
470   {
471     myShape = new AIS_TexturedShape( myTopoShape );
472   }
473   else
474   {
475     myShape = new AIS_Shape( myTopoShape );
476   }
477
478   if ( !myObject.IsNull() )
479     myShape->SetOwner( myObject );
480
481   myShape->SetTransparency( 0 );
482   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
483
484   if( anIsTexture )
485   {
486     Handle(AIS_TexturedShape) aTexturedShape = 
487       Handle(AIS_TexturedShape)::DownCast( myShape );
488
489     aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
490     aTexturedShape->SetTextureMapOn();
491     // Just use the texture image as is
492     aTexturedShape->DisableTextureModulate();
493     aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
494   }
495
496     // Init default params for shape
497   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
498   if ( !anAttributes.IsNull() )
499   {
500     if ( myDisplayMode == AIS_Shaded )
501     {
502       Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
503       if ( !anIsoAspect.IsNull() )
504         anIsoAspect->SetNumber( 0 );
505       
506       anIsoAspect = anAttributes->VIsoAspect();
507       if ( !anIsoAspect.IsNull() )
508         anIsoAspect->SetNumber( 0 );
509
510       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
511       if ( !aShadingAspect.IsNull() )
512       {
513         Graphic3d_MaterialAspect aMatAspect;
514         aMatAspect.SetAmbient( 1 );
515         aMatAspect.SetDiffuse( 0 );
516
517         aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
518         aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
519       }
520     }
521     else if ( myDisplayMode == AIS_WireFrame )
522     {
523       anAttributes->SetWireDraw( true );
524     }
525   }
526 }
527
528 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
529                                   const bool theIsUpdateViewer )
530 {
531   if ( myShape.IsNull() )
532     return;
533
534   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
535   if ( !anAttributes.IsNull() )
536   {
537     if ( myDisplayMode == AIS_Shaded )
538     {
539       // Coloring face filling
540       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
541       if ( !aShadingAspect.IsNull() )
542       {
543         Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), 
544                                       getQuantityColorVal( myFillingColor.green() ),
545                                       getQuantityColorVal( myFillingColor.blue() ),
546                                       Quantity_TOC_RGB );
547
548         aShadingAspect->SetColor( aFillingColor );
549         aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
550       }
551     }
552     else if ( myDisplayMode == AIS_WireFrame )
553     {
554     }
555
556     // Coloring borders
557     colorShapeBorder( getActiveColor() );
558   }
559
560   if ( !theToDisplay || !isVisible() || myContext.IsNull() )
561     return;
562   
563   myContext->Display( myShape, theIsUpdateViewer );
564 }
565
566 QColor HYDROGUI_Shape::getActiveColor() const
567 {
568   return isHighlighted() ? myHighlightColor : myBorderColor;
569 }
570
571 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
572 {
573   return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
574 }
575
576 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
577 {
578   if ( myShape.IsNull() )
579     return;
580
581   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
582   if ( anAttributes.IsNull() )
583     return;
584
585   Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), 
586                                getQuantityColorVal( theColor.green() ),
587                                getQuantityColorVal( theColor.blue() ),
588                                Quantity_TOC_RGB );
589   if ( myDisplayMode == AIS_Shaded )
590   {
591     if ( theColor.alpha() == 0 )
592     {
593       anAttributes->SetFaceBoundaryDraw( false );
594     }
595     else
596     {
597       anAttributes->SetFaceBoundaryDraw( true );
598
599       Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
600       if ( !aBoundaryAspect.IsNull() )
601         aBoundaryAspect->SetColor( aBorderColor );
602     }
603   }
604   else if ( myDisplayMode == AIS_WireFrame )
605   {
606     myShape->SetColor( aBorderColor );
607   }
608 }
609
610 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
611 {
612   QString aResult;
613   if( !theImageObj.IsNull() )
614   {
615     QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
616
617     int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
618     QString aPrefix = QString( "image_%1" ).arg( aStudyId );
619
620     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
621     anEntry.replace( ':', '_' );
622
623     QString anExtension = "bmp";
624
625     aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
626   }
627   return aResult;
628 }
629
630 void HYDROGUI_Shape::removeTextureFile() const
631 {
632   QFile aFile( getTextureFileName() );
633   if( aFile.exists() )
634     aFile.remove();
635 }
636
637 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
638 {
639   double aSizeLimit = (double)theSizeLimit;
640   double aWidth = (double)theImage.width();
641   double aHeight = (double)theImage.height();
642   if( aWidth > aSizeLimit || aHeight > aSizeLimit )
643   {
644     if( aWidth > aHeight )
645     {
646       aHeight /= ( aWidth / aSizeLimit );
647       aWidth = aSizeLimit;
648     }
649     else
650     {
651       aWidth /= ( aHeight / aSizeLimit );
652       aHeight = aSizeLimit;
653     }
654   }
655   return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
656 }