1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Shape.h"
25 #include "HYDROGUI_DataObject.h"
26 #include "HYDROGUI_Tool.h"
28 #include <AIS_Drawer.hxx>
29 #include <AIS_TexturedShape.hxx>
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <BRepBuilderAPI_MakeFace.hxx>
37 #include <Graphic3d_AspectFillArea3d.hxx>
38 #include <Graphic3d_MaterialAspect.hxx>
40 #include <HYDROData_Channel.h>
41 #include <HYDROData_Document.h>
42 #include <HYDROData_DummyObject3D.h>
43 #include <HYDROData_Image.h>
44 #include <HYDROData_ImmersibleZone.h>
45 #include <HYDROData_Obstacle.h>
46 #include <HYDROData_PolylineXY.h>
47 #include <HYDROData_Polyline3D.h>
48 #include <HYDROData_Profile.h>
49 #include <HYDROData_Region.h>
50 #include <HYDROData_ShapesGroup.h>
51 #include <HYDROData_Stream.h>
52 #include <HYDROData_Zone.h>
55 #include <TopoDS_Wire.hxx>
56 #include <TopoDS_Face.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <BRep_Builder.hxx>
62 #include <Precision.hxx>
64 #include <Prs3d_ShadingAspect.hxx>
65 #include <Prs3d_LineAspect.hxx>
66 #include <Prs3d_IsoAspect.hxx>
68 #include <SUIT_MessageBox.h>
73 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
74 const Handle(HYDROData_Entity)& theObject )
75 : myContext( theContext ),
76 myObject( theObject ),
77 myIsHighlight( false ),
78 myFillingColor( Qt::transparent ),
79 myBorderColor( Qt::black ),
80 myHighlightColor( Qt::white ),
81 myIsToUpdate( false ),
83 myDisplayMode( AIS_WireFrame )
87 HYDROGUI_Shape::~HYDROGUI_Shape()
91 if ( !myShape.IsNull() )
97 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
99 if ( myContext.IsNull() || myShape.IsNull() || !isVisible() )
102 myContext->Display( myShape, theIsUpdateViewer );
105 void HYDROGUI_Shape::erase( const bool theIsUpdateViewer )
107 if ( myContext.IsNull() || myShape.IsNull() )
110 myContext->Erase( myShape, theIsUpdateViewer );
113 void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
115 setIsToUpdate( false );
117 if ( myContext.IsNull() )
120 bool isDeactivateSelection = false;
121 // Try to retrieve information from object
122 if ( !myObject.IsNull() )
124 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myObject->Label() );
126 if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ImmersibleZone) ) )
128 Handle(HYDROData_ImmersibleZone) aZoneObj =
129 Handle(HYDROData_ImmersibleZone)::DownCast( myObject );
131 TopoDS_Shape aZoneShape = aZoneObj->GetTopShape();
132 if ( !aZoneShape.IsNull() ) {
133 if ( aZoneShape.ShapeType() == TopAbs_FACE ) {
134 TopoDS_Face aZoneFace = TopoDS::Face( aZoneShape );
135 setFace( aZoneFace, false, false );
137 myTopoShape = aZoneShape;
138 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
141 updateShape( false, false );
145 QColor aFillingColor = aZoneObj->GetFillingColor();
146 QColor aBorderColor = aZoneObj->GetBorderColor();
148 setFillingColor( aFillingColor, false, false );
149 setBorderColor( aBorderColor, false, false );
151 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_PolylineXY) ) )
153 Handle(HYDROData_PolylineXY) aPolyline =
154 Handle(HYDROData_PolylineXY)::DownCast( myObject );
156 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
158 if ( !aPolylineShape.IsNull() ) {
159 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
160 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
161 setWire( aPolylineWire, false, false );
163 myTopoShape = aPolylineShape;
164 myDisplayMode = AIS_WireFrame;
167 updateShape( false, false );
171 QColor aWireColor = aPolyline->GetWireColor();
172 setBorderColor( aWireColor, false, false );
174 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Polyline3D) ) )
176 Handle(HYDROData_Polyline3D) aPolyline =
177 Handle(HYDROData_Polyline3D)::DownCast( myObject );
179 TopoDS_Shape aPolylineShape = aPolyline->GetShape3D();
181 if ( !aPolylineShape.IsNull() ) {
182 if ( aPolylineShape.ShapeType() == TopAbs_WIRE ) {
183 TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolylineShape );
184 setWire( aPolylineWire, false, false );
186 myTopoShape = aPolylineShape;
187 myDisplayMode = AIS_WireFrame;
190 updateShape( false, false );
194 QColor aWireColor = aPolyline->GetBorderColor();
195 setBorderColor( aWireColor, false, false );
197 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Zone) ) )
199 Handle(HYDROData_Zone) aZone =
200 Handle(HYDROData_Zone)::DownCast( myObject );
202 TopoDS_Face aZoneFace = TopoDS::Face( aZone->GetShape() );
204 setFace( aZoneFace, false, false );
205 if (aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN )
207 // Red color for a zone with bathymetry conflict
208 setFillingColor( Qt::red );
212 // Generate the filling color for zone
213 QStringList aGeomObjectsNames;
215 HYDROData_SequenceOfObjects aRefObjects = aZone->GetGeometryObjects();
216 HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
217 for ( ; anIter.More(); anIter.Next() )
219 Handle(HYDROData_Object) aRefbject =
220 Handle(HYDROData_Object)::DownCast( anIter.Value() );
221 if ( aRefbject.IsNull() )
224 QString aRefObjectName = aRefbject->GetName();
225 if ( aRefObjectName.isEmpty() )
228 aGeomObjectsNames.append( aRefObjectName );
231 setFillingColor( HYDROGUI_Tool::GenerateFillingColor( aDocument, aGeomObjectsNames ) );
234 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
236 Handle(HYDROData_Image) anImageObj =
237 Handle(HYDROData_Image)::DownCast( myObject );
241 QString aTextureFileName = generateTextureFileName( anImageObj );
243 QImage anImage = anImageObj->Image();
244 QString aFilePath = anImageObj->GetFilePath();
245 QTransform aTrsf = anImageObj->Trsf();
247 int aWidth = anImage.width();
248 int aHeight = anImage.height();
250 QTransform anInversion = QTransform::fromScale( -1, -1 );
251 anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
253 // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
254 int aTrsfWidth = anImage.width();
255 int aDelta = aTrsfWidth % 4;
258 aTrsfWidth += ( 4 - aDelta );
260 anImage = anImage.scaledToWidth( aTrsfWidth );
262 // temporary optimization, to reduce the saved image size (and the texture quality)
263 QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
265 bool isSaved = anImageToSave.save( aTextureFileName );
267 QString aTitle = QObject::tr( "FILE_ERROR" );
268 QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
269 SUIT_MessageBox::warning( 0, aTitle, aMessage );
272 QPointF aPoint1( 0, 0 ); // 1: top left
273 QPointF aPoint2( aWidth, 0 ); // 2: top right
274 QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
275 QPointF aPoint4( 0, aHeight ); // 4: bottom left
277 aPoint1 = aTrsf.map( aPoint1 );
278 aPoint2 = aTrsf.map( aPoint2 );
279 aPoint3 = aTrsf.map( aPoint3 );
280 aPoint4 = aTrsf.map( aPoint4 );
282 QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
283 QRectF aRect = aPolygon.boundingRect();
285 gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
286 gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
287 gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
288 gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
290 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
291 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
292 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
293 TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
295 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
296 aWire.Closed( true );
298 setTextureFileName( aTextureFileName, false, false );
299 setFace( aWire, false, false );
300 isDeactivateSelection = true;
302 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Profile) ) )
304 Handle(HYDROData_Profile) aProfile =
305 Handle(HYDROData_Profile)::DownCast( myObject );
307 TopoDS_Wire aProfileWire;
309 if ( aProfile->IsValid() ) {
310 TopoDS_Shape aProfileShape = aProfile->GetShape3D();
312 if ( !aProfileShape.IsNull() &&
313 aProfileShape.ShapeType() == TopAbs_WIRE ) {
314 aProfileWire = TopoDS::Wire( aProfileShape );
318 setWire( aProfileWire, false, false );
320 QColor aWireColor = aProfile->GetBorderColor();
321 setBorderColor( aWireColor, false, false );
323 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Stream) ) ||
324 myObject->IsKind( STANDARD_TYPE(HYDROData_Channel) ) ||
325 myObject->IsKind( STANDARD_TYPE(HYDROData_Obstacle) ) )
327 Handle(HYDROData_Object) aGeomObject =
328 Handle(HYDROData_Object)::DownCast( myObject );
330 TopoDS_Shape anObjShape = aGeomObject->GetTopShape();
332 setShape( anObjShape, false, false );
334 QColor aFillingColor = aGeomObject->GetFillingColor();
335 QColor aBorderColor = aGeomObject->GetBorderColor();
337 setFillingColor( aFillingColor, false, false );
338 setBorderColor( aBorderColor, false, false );
340 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_DummyObject3D) ) )
342 Handle(HYDROData_DummyObject3D) anObject3D =
343 Handle(HYDROData_DummyObject3D)::DownCast( myObject );
344 TopoDS_Shape aShape3D = anObject3D->GetShape();
346 setShape( aShape3D, false, false );
348 QColor aFillingColor = anObject3D->GetFillingColor();
349 QColor aBorderColor = anObject3D->GetBorderColor();
351 setFillingColor( aFillingColor, false, false );
352 setBorderColor( aBorderColor, false, false );
354 else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_ShapesGroup) ) )
356 Handle(HYDROData_ShapesGroup) aShapesGroup =
357 Handle(HYDROData_ShapesGroup)::DownCast( myObject );
359 TopTools_SequenceOfShape aShapes;
360 aShapesGroup->GetShapes( aShapes );
362 BRepBuilderAPI_MakeWire aMakeWire;
364 for ( int i = 1, n = aShapes.Length(); i <= n; ++i )
366 TopoDS_Edge anEdge = TopoDS::Edge( aShapes.Value( i ) );
367 aMakeWire.Add( anEdge );
371 TopoDS_Wire aResWire = aMakeWire.Wire();
373 setWire( aResWire, false, false );
374 setBorderColor( Qt::red, false, false );
378 if ( myShape.IsNull() || !isVisible() )
381 myContext->Display( myShape, theIsUpdateViewer );
382 if (isDeactivateSelection)
383 myContext->Deactivate(myShape);
386 void HYDROGUI_Shape::setVisible( const bool theState,
387 const bool theIsUpdateViewer )
389 if ( myIsVisible == theState )
392 myIsVisible = theState;
394 if ( myShape.IsNull() )
398 myContext->Display( myShape, theIsUpdateViewer );
400 myContext->Erase( myShape, theIsUpdateViewer );
403 void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer )
405 if ( myIsHighlight == theIsHighlight )
408 myIsHighlight = theIsHighlight;
410 if ( myContext.IsNull() || myShape.IsNull() )
413 colorShapeBorder( getActiveColor() );
414 myContext->Display( myShape, isUpdateViewer );
417 bool HYDROGUI_Shape::isHighlighted() const
419 return myIsHighlight;
422 void HYDROGUI_Shape::setWire( const TopoDS_Wire& theWire,
423 const bool theToDisplay,
424 const bool theIsUpdateViewer )
426 myTopoShape = theWire;
427 myDisplayMode = AIS_WireFrame;
430 updateShape( theToDisplay, theIsUpdateViewer );
433 void HYDROGUI_Shape::setFaces( const TopoDS_Compound& theWires,
434 const bool theToDisplay,
435 const bool theIsUpdateViewer )
437 TopExp_Explorer anExp( theWires, TopAbs_WIRE );
438 TopoDS_Compound aCompound;
439 BRep_Builder aBuilder;
440 aBuilder.MakeCompound( aCompound );
442 for ( ; anExp.More(); anExp.Next() ) {
443 TopoDS_Wire aWire = TopoDS::Wire( anExp.Current() );
444 if ( aWire.IsNull() ) {
448 BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
450 if( aMakeFace.IsDone() ) {
451 aBuilder.Add( aCompound, aMakeFace.Face() );
455 myTopoShape = aCompound;
456 myDisplayMode = AIS_Shaded;
459 updateShape( theToDisplay, theIsUpdateViewer );
462 void HYDROGUI_Shape::setFace( const TopoDS_Wire& theWire,
463 const bool theToDisplay,
464 const bool theIsUpdateViewer )
466 BRepBuilderAPI_MakeFace aFaceBuilder( theWire, Standard_True );
467 aFaceBuilder.Build();
468 if( aFaceBuilder.IsDone() )
470 TopoDS_Face aFace = aFaceBuilder.Face();
471 setFace( aFace, theToDisplay, theIsUpdateViewer );
475 void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
476 const bool theToDisplay,
477 const bool theIsUpdateViewer )
479 myTopoShape = theFace;
480 myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_Shaded+2;
481 //Note: AIS_Shaded+2 is the same as AIS_ExactHLR
482 //TODO: it would be more suitable to use TexturedShape mode from GEOM_AISShape
485 updateShape( theToDisplay, theIsUpdateViewer );
488 void HYDROGUI_Shape::setShape( const TopoDS_Shape& theShape,
489 const bool theToDisplay,
490 const bool theIsUpdateViewer )
492 myTopoShape = theShape;
493 myDisplayMode = AIS_Shaded;
496 updateShape( theToDisplay, theIsUpdateViewer );
499 void HYDROGUI_Shape::setFillingColor( const QColor& theColor,
500 const bool theToDisplay,
501 const bool theIsUpdateViewer )
503 myFillingColor = theColor;
504 updateShape( theToDisplay, theIsUpdateViewer );
507 QColor HYDROGUI_Shape::getFillingColor() const
509 return myFillingColor;
512 void HYDROGUI_Shape::setBorderColor( const QColor& theColor,
513 const bool theToDisplay,
514 const bool theIsUpdateViewer )
516 myBorderColor = theColor;
517 updateShape( theToDisplay, theIsUpdateViewer );
520 QColor HYDROGUI_Shape::getBorderColor() const
522 return myBorderColor;
525 void HYDROGUI_Shape::setHighlightColor( const QColor& theColor )
527 myHighlightColor = theColor;
530 QColor HYDROGUI_Shape::getHighlightColor() const
532 return myHighlightColor;
535 void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
536 const bool theToDisplay,
537 const bool theIsUpdateViewer )
539 myTextureFileName = theFileName;
540 updateShape( theToDisplay, theIsUpdateViewer );
543 QString HYDROGUI_Shape::getTextureFileName() const
545 return myTextureFileName;
548 void HYDROGUI_Shape::buildShape()
550 // Erase previously created shape
553 if ( myTopoShape.IsNull() ) {
558 QString aTextureFileName = getTextureFileName();
559 bool anIsTexture = !aTextureFileName.isEmpty();
563 myShape = new AIS_TexturedShape( myTopoShape );
567 myShape = new AIS_Shape( myTopoShape );
570 if ( !myObject.IsNull() )
571 myShape->SetOwner( myObject );
573 myShape->SetTransparency( 0 );
574 myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
578 Handle(AIS_TexturedShape) aTexturedShape =
579 Handle(AIS_TexturedShape)::DownCast( myShape );
581 aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
582 aTexturedShape->SetTextureMapOn();
583 // Just use the texture image as is
584 aTexturedShape->DisableTextureModulate();
585 aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
588 // Init default params for shape
589 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
590 if ( !anAttributes.IsNull() )
592 Handle(Prs3d_IsoAspect) anIsoAspect = anAttributes->UIsoAspect();
593 if ( !anIsoAspect.IsNull() ) {
594 anIsoAspect->SetNumber( 0 );
595 anAttributes->SetUIsoAspect( anIsoAspect );
598 anIsoAspect = anAttributes->VIsoAspect();
599 if ( !anIsoAspect.IsNull() ) {
600 anIsoAspect->SetNumber( 0 );
601 anAttributes->SetVIsoAspect( anIsoAspect );
604 if ( myDisplayMode == AIS_Shaded )
606 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
607 if ( !aShadingAspect.IsNull() )
609 Graphic3d_MaterialAspect aMatAspect;
610 aMatAspect.SetAmbient( 1 );
611 aMatAspect.SetDiffuse( 0 );
613 aShadingAspect->Aspect()->SetFrontMaterial( aMatAspect );
614 aShadingAspect->Aspect()->SetBackMaterial( aMatAspect );
617 else if ( myDisplayMode == AIS_WireFrame )
619 anAttributes->SetWireDraw( true );
624 void HYDROGUI_Shape::updateShape( const bool theToDisplay,
625 const bool theIsUpdateViewer )
627 if ( myShape.IsNull() )
630 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
631 if ( !anAttributes.IsNull() )
633 if ( myDisplayMode == AIS_Shaded )
635 // Coloring face filling
636 Handle(Prs3d_ShadingAspect) aShadingAspect = anAttributes->ShadingAspect();
637 if ( !aShadingAspect.IsNull() )
639 Quantity_Color aFillingColor( getQuantityColorVal( myFillingColor.red() ),
640 getQuantityColorVal( myFillingColor.green() ),
641 getQuantityColorVal( myFillingColor.blue() ),
644 aShadingAspect->SetColor( aFillingColor );
645 aShadingAspect->SetTransparency( 1 - getQuantityColorVal( myFillingColor.alpha() ) );
648 else if ( myDisplayMode == AIS_WireFrame )
653 colorShapeBorder( getActiveColor() );
656 if ( !theToDisplay || !isVisible() || myContext.IsNull() )
659 myContext->Display( myShape, theIsUpdateViewer );
662 QColor HYDROGUI_Shape::getActiveColor() const
664 return isHighlighted() ? myHighlightColor : myBorderColor;
667 double HYDROGUI_Shape::getQuantityColorVal( const int theColorVal )
669 return theColorVal == 0 ? 0 : ( (double)theColorVal / 255 );
672 void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
674 if ( myShape.IsNull() )
677 const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
678 if ( anAttributes.IsNull() )
681 Quantity_Color aBorderColor( getQuantityColorVal( theColor.red() ),
682 getQuantityColorVal( theColor.green() ),
683 getQuantityColorVal( theColor.blue() ),
685 if ( myDisplayMode == AIS_Shaded )
687 if ( theColor.alpha() == 0 )
689 anAttributes->SetFaceBoundaryDraw( false );
693 anAttributes->SetFaceBoundaryDraw( true );
695 Handle(Prs3d_LineAspect) aBoundaryAspect = anAttributes->FaceBoundaryAspect();
696 if ( !aBoundaryAspect.IsNull() )
698 aBoundaryAspect->SetColor( aBorderColor );
699 anAttributes->SetFaceBoundaryAspect( aBoundaryAspect );
703 else if ( myDisplayMode == AIS_WireFrame )
705 myShape->SetColor( aBorderColor );
709 QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Entity)& theImageObj )
712 if( !theImageObj.IsNull() )
714 QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
716 int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
717 QString aPrefix = QString( "image_%1" ).arg( aStudyId );
719 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
720 anEntry.replace( ':', '_' );
722 QString anExtension = "bmp";
724 aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
729 void HYDROGUI_Shape::removeTextureFile() const
731 QFile aFile( getTextureFileName() );
736 QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
738 double aSizeLimit = (double)theSizeLimit;
739 double aWidth = (double)theImage.width();
740 double aHeight = (double)theImage.height();
741 if( aWidth > aSizeLimit || aHeight > aSizeLimit )
743 if( aWidth > aHeight )
745 aHeight /= ( aWidth / aSizeLimit );
750 aWidth /= ( aHeight / aSizeLimit );
751 aHeight = aSizeLimit;
754 return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );