Salome HOME
Profile dialog backgound like it is in OCC viewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Shape.cxx
index d1de7c3c142610e103109ca306b1e0402e73a194..799c09f2b36eb4763ae8c2cba2d89e94ff5971fe 100644 (file)
@@ -59,6 +59,8 @@
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
 
+#include <SUIT_MessageBox.h>
+
 #include <QColor>
 #include <QFile>
 
@@ -215,14 +217,29 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       QTransform anInversion = QTransform::fromScale( -1, -1 );
       anImage = anImage.transformed( anInversion * aTrsf, Qt::SmoothTransformation );
 
+      // Workaround: Scale the texture image to the nearest width multiple 4 due to the CASCADE bug 23813
+      int aTrsfWidth = anImage.width();
+      int aDelta = aTrsfWidth % 4;
+      if ( aDelta > 0 )
+      {
+        aTrsfWidth += ( 4 - aDelta );
+      }
+      anImage = anImage.scaledToWidth( aTrsfWidth );
+
       // temporary optimization, to reduce the saved image size (and the texture quality)
-      QImage anImageToSave = reduceTexture( anImage, 500 );
-      anImageToSave.save( aTextureFileName );
+      QImage anImageToSave = anImage; //RKV:reduceTexture( anImage, 500 );
+
+      bool isSaved = anImageToSave.save( aTextureFileName );
+      if ( !isSaved ) {
+        QString aTitle = QObject::tr( "FILE_ERROR" );
+        QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_CREATED" ).arg( aTextureFileName );
+        SUIT_MessageBox::warning( 0, aTitle, aMessage );
+      }
 
-      QPointF aPoint1( 0, 0 );
-      QPointF aPoint2( aWidth, 0 );
-      QPointF aPoint3( aWidth, aHeight );
-      QPointF aPoint4( 0, aHeight );
+      QPointF aPoint1( 0, 0 );            // 1: top left
+      QPointF aPoint2( aWidth, 0 );       // 2: top right
+      QPointF aPoint3( aWidth, aHeight ); // 3: bottom right
+      QPointF aPoint4( 0, aHeight );      // 4: bottom left
 
       aPoint1 = aTrsf.map( aPoint1 );
       aPoint2 = aTrsf.map( aPoint2 );
@@ -243,6 +260,7 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
       TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
 
       TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
+      aWire.Closed( true );
 
       setTextureFileName( aTextureFileName, false, false );
       setFace( aWire, false, false );
@@ -470,7 +488,9 @@ void HYDROGUI_Shape::buildShape()
 
     aTexturedShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
     aTexturedShape->SetTextureMapOn();
+    // Just use the texture image as is
     aTexturedShape->DisableTextureModulate();
+    aTexturedShape->SetTextureRepeat( false ); // don't repeat the texture image on the face
   }
 
     // Init default params for shape