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