Salome HOME
9e36f73d2307986c0eb7ae74eb90949fe407f5b1
[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       TopoDS_Wire aProfileWire;
295
296       if ( aProfile->IsValid() ) {
297         TopoDS_Shape aProfileShape = aProfile->GetShape3D();
298
299         if ( !aProfileShape.IsNull() && 
300              aProfileShape.ShapeType() == TopAbs_WIRE ) {
301           aProfileWire = TopoDS::Wire( aProfileShape );
302         }
303       }
304
305       setWire( aProfileWire, false, false );  
306     }
307   }
308  
309   if ( myShape.IsNull() || !isVisible() )
310     return;
311
312   myContext->Display( myShape, theIsUpdateViewer );
313 }
314
315 void HYDROGUI_Shape::setVisible( const bool theState,
316                                  const bool theIsUpdateViewer )
317 {
318   if ( myIsVisible == theState )
319     return;
320
321   myIsVisible = theState;
322
323   if ( myShape.IsNull() )
324     return;
325
326   if ( myIsVisible )
327     myContext->Display( myShape, theIsUpdateViewer );
328   else
329     myContext->Erase( myShape, theIsUpdateViewer );
330 }
331
332 void HYDROGUI_Shape::highlight( bool theIsHighlight )
333 {
334   if ( myIsHighlight == theIsHighlight )
335     return;
336
337   myIsHighlight = theIsHighlight;
338
339   if ( myContext.IsNull() || myShape.IsNull() )
340     return;
341
342   colorShapeBorder( getActiveColor() );
343   myContext->Display( myShape );
344 }
345
346 bool HYDROGUI_Shape::isHighlighted() const
347 {
348   return myIsHighlight;
349 }
350
351 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
352                               const bool         theToDisplay,
353                               const bool         theIsUpdateViewer )
354 {
355   myTopoShape = theWire;
356   myDisplayMode = AIS_WireFrame;
357
358   buildShape();
359   updateShape( theToDisplay, theIsUpdateViewer );
360 }
361
362 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
363                                const bool             theToDisplay,
364                                const bool             theIsUpdateViewer )
365 {
366   TopExp_Explorer anExp( theWires, TopAbs_WIRE );
367   TopoDS_Compound aCompound;
368   BRep_Builder aBuilder;
369     aBuilder.MakeCompound( aCompound );
370
371   for ( ; anExp.More(); anExp.Next() ) {
372     TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
373     if ( aWire.IsNull() ) {
374       continue;
375     }
376
377     BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
378     aMakeFace.Build();
379     if( aMakeFace.IsDone() ) {
380       aBuilder.Add( aCompound, aMakeFace.Face() );
381     }
382   }
383
384   myTopoShape = aCompound;
385   myDisplayMode = AIS_Shaded;
386
387   buildShape();
388   updateShape( theToDisplay, theIsUpdateViewer );
389 }
390
391 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
392                               const bool         theToDisplay,
393                               const bool         theIsUpdateViewer )
394 {
395   BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
396   aFaceBuilder.Build();
397   if( aFaceBuilder.IsDone() )
398   {
399     TopoDS_Face aFace = aFaceBuilder.Face();
400     setFace( aFace, theToDisplay, theIsUpdateViewer );
401   }
402 }
403
404 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
405                               const bool         theToDisplay,
406                               const bool         theIsUpdateViewer )
407 {
408   myTopoShape = theFace;
409   myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
410   //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
411   //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
412
413   buildShape();
414   updateShape( theToDisplay, theIsUpdateViewer );
415 }
416
417 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
418                                const bool          theToDisplay,
419                                const bool          theIsUpdateViewer )
420 {
421   myTopoShape = theShape;
422   myDisplayMode = AIS_Shaded;
423
424   buildShape();
425   updateShape( theToDisplay, theIsUpdateViewer );
426 }
427
428 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
429                                       const bool    theToDisplay,
430                                       const bool    theIsUpdateViewer )
431 {
432   myFillingColor = theColor;
433   updateShape( theToDisplay, theIsUpdateViewer );
434 }
435
436 QColor HYDROGUI_Shape::getFillingColor() const
437 {
438   return myFillingColor;
439 }
440
441 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
442                                      const bool    theToDisplay,
443                                      const bool    theIsUpdateViewer )
444 {
445   myBorderColor = theColor;
446   updateShape( theToDisplay, theIsUpdateViewer );
447 }
448
449 QColor HYDROGUI_Shape::getBorderColor() const
450 {
451   return myBorderColor;
452 }
453
454 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
455 {
456   myHighlightColor = theColor;
457 }
458
459 QColor HYDROGUI_Shape::getHighlightColor() const
460 {
461   return myHighlightColor;
462 }
463
464 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
465                                          const bool     theToDisplay,
466                                          const bool     theIsUpdateViewer )
467 {
468   myTextureFileName = theFileName;
469   updateShape( theToDisplay, theIsUpdateViewer );
470 }
471
472 QString HYDROGUI_Shape::getTextureFileName() const
473 {
474   return myTextureFileName;
475 }
476
477 void HYDROGUI_Shape::buildShape()
478 {
479   // Erase previously created shape
480   erase();
481
482   if ( myTopoShape.IsNull() ) {
483     myShape.Nullify();
484     return;
485   }
486
487   QString aTextureFileName = getTextureFileName();
488   bool anIsTexture = !aTextureFileName.isEmpty();
489
490   if ( anIsTexture )
491   {
492     myShape = new AIS_TexturedShape( myTopoShape );
493   }
494   else
495   {
496     myShape = new AIS_Shape( myTopoShape );
497   }
498
499   if ( !myObject.IsNull() )
500     myShape->SetOwner( myObject );
501
502   myShape->SetTransparency( 0 );
503   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
504
505   if( anIsTexture )
506   {
507     Handle(AIS_TexturedShape) aTexturedShape = 
508       Handle(AIS_TexturedShape)::DownCast( myShape );
509
510     aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
511     aTexturedShape->SetTextureMapOn();
512     // Just use the texture image as is
513     aTexturedShape->DisableTextureModulate();
514     aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
515   }
516
517     // Init default params for shape
518   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
519   if ( !anAttributes.IsNull() )
520   {
521     if ( myDisplayMode == AIS_Shaded )
522     {
523       Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
524       if ( !anIsoAspect.IsNull() )
525         anIsoAspect->SetNumber( 0 );
526       
527       anIsoAspect = anAttributes->VIsoAspect();
528       if ( !anIsoAspect.IsNull() )
529         anIsoAspect->SetNumber( 0 );
530
531       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
532       if ( !aShadingAspect.IsNull() )
533       {
534         Graphic3d_MaterialAspect aMatAspect;
535         aMatAspect.SetAmbient( 1 );
536         aMatAspect.SetDiffuse( 0 );
537
538         aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
539         aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
540       }
541     }
542     else if ( myDisplayMode == AIS_WireFrame )
543     {
544       anAttributes->SetWireDraw( true );
545     }
546   }
547 }
548
549 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
550                                   const bool theIsUpdateViewer )
551 {
552   if ( myShape.IsNull() )
553     return;
554
555   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
556   if ( !anAttributes.IsNull() )
557   {
558     if ( myDisplayMode == AIS_Shaded )
559     {
560       // Coloring face filling
561       Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
562       if ( !aShadingAspect.IsNull() )
563       {
564         Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ), 
565                                       getQuantityColorVal( myFillingColor.green() ),
566                                       getQuantityColorVal( myFillingColor.blue() ),
567                                       Quantity_TOC_RGB );
568
569         aShadingAspect->SetColor( aFillingColor );
570         aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
571       }
572     }
573     else if ( myDisplayMode == AIS_WireFrame )
574     {
575     }
576
577     // Coloring borders
578     colorShapeBorder( getActiveColor() );
579   }
580
581   if ( !theToDisplay || !isVisible() || myContext.IsNull() )
582     return;
583   
584   myContext->Display( myShape, theIsUpdateViewer );
585 }
586
587 QColor HYDROGUI_Shape::getActiveColor() const
588 {
589   return isHighlighted() ? myHighlightColor : myBorderColor;
590 }
591
592 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
593 {
594   return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
595 }
596
597 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
598 {
599   if ( myShape.IsNull() )
600     return;
601
602   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
603   if ( anAttributes.IsNull() )
604     return;
605
606   Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ), 
607                                getQuantityColorVal( theColor.green() ),
608                                getQuantityColorVal( theColor.blue() ),
609                                Quantity_TOC_RGB );
610   if ( myDisplayMode == AIS_Shaded )
611   {
612     if ( theColor.alpha() == 0 )
613     {
614       anAttributes->SetFaceBoundaryDraw( false );
615     }
616     else
617     {
618       anAttributes->SetFaceBoundaryDraw( true );
619
620       Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
621       if ( !aBoundaryAspect.IsNull() )
622         aBoundaryAspect->SetColor( aBorderColor );
623     }
624   }
625   else if ( myDisplayMode == AIS_WireFrame )
626   {
627     myShape->SetColor( aBorderColor );
628   }
629 }
630
631 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
632 {
633   QString aResult;
634   if( !theImageObj.IsNull() )
635   {
636     QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
637
638     int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
639     QString aPrefix = QString( "image_%1" ).arg( aStudyId );
640
641     QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
642     anEntry.replace( ':', '_' );
643
644     QString anExtension = "bmp";
645
646     aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
647   }
648   return aResult;
649 }
650
651 void HYDROGUI_Shape::removeTextureFile() const
652 {
653   QFile aFile( getTextureFileName() );
654   if( aFile.exists() )
655     aFile.remove();
656 }
657
658 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
659 {
660   double aSizeLimit = (double)theSizeLimit;
661   double aWidth = (double)theImage.width();
662   double aHeight = (double)theImage.height();
663   if( aWidth > aSizeLimit || aHeight > aSizeLimit )
664   {
665     if( aWidth > aHeight )
666     {
667       aHeight /= ( aWidth / aSizeLimit );
668       aWidth = aSizeLimit;
669     }
670     else
671     {
672       aWidth /= ( aHeight / aSizeLimit );
673       aHeight = aSizeLimit;
674     }
675   }
676   return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
677 }