]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
IPAL22901: Extending functionality of setting gradient and textured background of...
authorouv <ouv@opencascade.com>
Mon, 16 Apr 2012 09:54:58 +0000 (09:54 +0000)
committerouv <ouv@opencascade.com>
Mon, 16 Apr 2012 09:54:58 +0000 (09:54 +0000)
Part 2: gradient background.

src/SVTK/SVTK_ViewModel.cxx
src/SVTK/SVTK_ViewModel.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/resources/SVTK_msg_en.ts
src/VTKViewer/VTKViewer_OpenGLRenderer.cxx
src/VTKViewer/VTKViewer_OpenGLRenderer.h
src/VTKViewer/VTKViewer_ViewModel.cxx
src/VTKViewer/VTKViewer_ViewModel.h
src/VTKViewer/VTKViewer_ViewWindow.cxx
src/VTKViewer/resources/VTKViewer_msg_en.ts

index aaaea4eff5940da7f946a8f9dada325ee1b6499b..4ded57c092e4c087fc635746c8b8b5cc5ce7c3ec 100644 (file)
@@ -103,8 +103,22 @@ SVTK_Viewer::~SVTK_Viewer()
 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
 QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
 {
-  gradList << tr( "GT_VERTICALGRADIENT" );  // only vertical type of gradient is supported
-  idList   << VerticalGradient;             // only vertical type of gradient is supported
+  gradList << tr( "GT_HORIZONTALGRADIENT" )
+           << tr( "GT_VERTICALGRADIENT" )
+           << tr( "GT_FIRSTDIAGONALGRADIENT" )
+           << tr( "GT_SECONDDIAGONALGRADIENT" )
+           << tr( "GT_FIRSTCORNERGRADIENT" )
+           << tr( "GT_SECONDCORNERGRADIENT" )
+           << tr( "GT_THIRDCORNERGRADIENT" )
+           << tr( "GT_FOURTHCORNERGRADIENT" );
+  idList   << HorizontalGradient
+           << VerticalGradient
+           << FirstDiagonalGradient
+           << SecondDiagonalGradient
+           << FirstCornerGradient
+           << SecondCornerGradient
+           << ThirdCornerGradient
+           << FourthCornerGradient;
 #ifdef VTK_ENABLE_TEXTURED_BACKGROUND
   txtList  << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
 #endif
index 81aa013109b1b0c5846ff220c6bb4a377b1f8ec9..b0671426579f64dee52375bc5cc0ef5b73b17a49 100644 (file)
@@ -48,8 +48,15 @@ class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View
 public:
   /*! supported gradient types */
   enum { 
+    HorizontalGradient,
     VerticalGradient,
-    LastGradient = VerticalGradient,
+    FirstDiagonalGradient,
+    SecondDiagonalGradient,
+    FirstCornerGradient,
+    SecondCornerGradient,
+    ThirdCornerGradient,
+    FourthCornerGradient,
+    LastGradient = FourthCornerGradient,
   };
 
   typedef SVTK_ViewWindow TViewWindow;
index 44227e2e3a586d4510ae7dffbdd8e68ad61a32b0..3a81fc72a29871a7ed2a78224cedd9ff22767375 100755 (executable)
@@ -27,6 +27,7 @@
 #include "SVTK_ViewParameterDlg.h"
 #include "SVTK_ViewModel.h"
 #include "VTKViewer_Texture.h"
+#include "VTKViewer_OpenGLRenderer.h"
 
 #include "SALOME_Actor.h"
 
@@ -591,28 +592,28 @@ void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
       }
     case Qtx::SimpleGradientBackground:
       {
-       QColor c1, c2;
-       int type = bgData.gradient( c1, c2 );
-       // VSR: Currently, only vertical gradient is supported by VTK. 
-       // In future, switch operator might be added here to process different supported gradient types.
-       if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) {
-         if ( !c2.isValid() ) c2 = c1;
-         // show two-color gradient background
-         getRenderer()->SetTexturedBackground( false );    // cancel texture mode
-         getRenderer()->SetGradientBackground( true );     // switch to gradient mode
-         // VSR: In VTK, gradient is colored from bottom to top:
-         // - top color is set via SetBackground2()
-         // - bottom color is set via SetBackground()
-         // So, we reverse colors, to draw gradient from top to bottom instead.
-         getRenderer()->SetBackground(  c2.red()/255.0, 
-                                        c2.green()/255.0,
-                                        c2.blue()/255.0 ); // set first gradient color
-         getRenderer()->SetBackground2( c1.red()/255.0,
-                                        c1.green()/255.0,
-                                        c1.blue()/255.0 ); // set second gradient color
-         ok = true;
-       }
-       break;
+        QColor c1, c2;
+        int type = bgData.gradient( c1, c2 );
+        if ( c1.isValid() )
+        {
+          if ( !c2.isValid() )
+            c2 = c1;
+
+          // show two-color gradient background
+          getRenderer()->SetTexturedBackground( false );    // cancel texture mode
+          getRenderer()->SetGradientBackground( true );     // switch to gradient mode
+
+          VTKViewer_OpenGLRenderer* aRenderer =
+            VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
+          if( aRenderer )
+          {
+            aRenderer->SetGradientType( type );
+            aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
+            aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
+            ok = true;
+          }
+        }
+        break;
       }
     case Qtx::CustomGradientBackground:
       {
index ec3a19da14f7644cad95f8bab807eece6521743e..6e6ca4e847f5d4f4fc4a097b0dbfa45ba3e71a45 100644 (file)
@@ -595,10 +595,38 @@ Please, refer to the documentation.</translation>
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Change background...</translation>
     </message>
+    <message>
+        <source>GT_HORIZONTALGRADIENT</source>
+        <translation>Horizontal gradient</translation>
+    </message>
     <message>
         <source>GT_VERTICALGRADIENT</source>
         <translation>Vertical gradient</translation>
     </message>
+    <message>
+        <source>GT_FIRSTDIAGONALGRADIENT</source>
+        <translation>First diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDDIAGONALGRADIENT</source>
+        <translation>Second diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTCORNERGRADIENT</source>
+        <translation>First corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDCORNERGRADIENT</source>
+        <translation>Second corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_THIRDCORNERGRADIENT</source>
+        <translation>Third corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_FOURTHCORNERGRADIENT</source>
+        <translation>Fourth corner gradient</translation>
+    </message>
     <message>
         <source>BG_IMAGE_FILES</source>
         <translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>
index a9625143b510e6f09b1c015887c844296c82f653..a7250fa2efe0759313287caabcd92a307cafd3bd 100644 (file)
@@ -43,12 +43,18 @@ vtkStandardNewMacro(VTKViewer_OpenGLRenderer);
 
 VTKViewer_OpenGLRenderer::VTKViewer_OpenGLRenderer()
 {
+  this->GradientType = HorizontalGradient;
 }
 
 VTKViewer_OpenGLRenderer::~VTKViewer_OpenGLRenderer()
 {
 }
 
+void VTKViewer_OpenGLRenderer::SetGradientType( const int theGradientType )
+{
+  this->GradientType = theGradientType;
+}
+
 void VTKViewer_OpenGLRenderer::Clear(void)
 {
   GLbitfield clear_mask = 0;
@@ -97,16 +103,92 @@ void VTKViewer_OpenGLRenderer::Clear(void)
 
     if( this->GradientBackground )
     {
-      glBegin( GL_QUADS );
+      double* corner1 = 0;
+      double* corner2 = 0;
+      double* corner3 = 0;
+      double* corner4 = 0;
+      double dcorner1[3];
+      double dcorner2[3];
 
-      glColor4d( this->Background[0], this->Background[1], this->Background[2], 0.0 );
-      glVertex2f( 0.F, 0.F );
-      glVertex2f( 1.F, 0.F );
-
-      glColor4d( this->Background2[0], this->Background2[1], this->Background2[2], 0.0 );
-      glVertex2f( 1.F, 1.F );
-      glVertex2f( 0.F, 1.F );
+      switch( this->GradientType )
+      {
+        case HorizontalGradient:
+          corner1 = this->Background;
+          corner2 = this->Background2;
+          corner3 = this->Background2;
+          corner4 = this->Background;
+          break;
+        case VerticalGradient:
+          corner1 = this->Background2;
+          corner2 = this->Background2;
+          corner3 = this->Background;
+          corner4 = this->Background;
+          break;
+        case FirstDiagonalGradient:
+          corner2 = this->Background2;
+          corner4 = this->Background;
+          dcorner1[0] = dcorner2[0] = 0.5F * ( corner2[0] + corner4[0] );
+          dcorner1[1] = dcorner2[1] = 0.5F * ( corner2[1] + corner4[1] );
+          dcorner1[2] = dcorner2[2] = 0.5F * ( corner2[2] + corner4[2] );
+          corner1 = dcorner1;
+          corner3 = dcorner2;
+          break;
+        case SecondDiagonalGradient:
+          corner1 = this->Background2;  
+          corner3 = this->Background;
+          dcorner1[0] = dcorner2[0] = 0.5F * ( corner1[0] + corner3[0] );
+          dcorner1[1] = dcorner2[1] = 0.5F * ( corner1[1] + corner3[1] );
+          dcorner1[2] = dcorner2[2] = 0.5F * ( corner1[2] + corner3[2] );
+          corner2 = dcorner1;
+          corner4 = dcorner2;
+          break;
+        case FirstCornerGradient:
+          corner1 = this->Background2;
+          corner2 = this->Background2;
+          corner3 = this->Background2;
+          corner4 = this->Background;
+          break;
+        case SecondCornerGradient:
+          corner1 = this->Background2;
+          corner2 = this->Background2;
+          corner3 = this->Background;
+          corner4 = this->Background2;
+          break;
+        case ThirdCornerGradient:
+          corner1 = this->Background2;
+          corner2 = this->Background;
+          corner3 = this->Background2;
+          corner4 = this->Background2;
+          break;
+        case FourthCornerGradient:
+          corner1 = this->Background;
+          corner2 = this->Background2;
+          corner3 = this->Background2;
+          corner4 = this->Background2;
+          break;
+        default: // just in case
+          corner1 = this->Background;
+          corner2 = this->Background;
+          corner3 = this->Background;
+          corner4 = this->Background;
+          break;
+      }
 
+      glBegin( GL_TRIANGLE_FAN );
+      if( this->GradientType != FirstCornerGradient && this->GradientType != ThirdCornerGradient )
+      {
+        glColor3f( corner1[0], corner1[1], corner1[2] ); glVertex2f( 0.F, 0.F );
+        glColor3f( corner2[0], corner2[1], corner2[2] ); glVertex2f( 1.F, 0.F );
+        glColor3f( corner3[0], corner3[1], corner3[2] ); glVertex2f( 1.F, 1.F );
+        glColor3f( corner4[0], corner4[1], corner4[2] ); glVertex2f( 0.F, 1.F );
+      }
+      else //if( this->GradientType == FirstCornerGradient || this->GradientType == ThirdCornerGradient )
+      {
+        glColor3f( corner2[0], corner2[1], corner2[2] ); glVertex2f( 1.F, 0.F );
+        glColor3f( corner3[0], corner3[1], corner3[2] ); glVertex2f( 1.F, 1.F );
+        glColor3f( corner4[0], corner4[1], corner4[2] ); glVertex2f( 0.F, 1.F );
+        glColor3f( corner1[0], corner1[1], corner1[2] ); glVertex2f( 0.F, 0.F );
+      }
       glEnd();
     }
 
index 797d21221611548e52c0f717455da036e72abec8..83bcc5ecc4fbe99b33d7c174d3c280ee743c2fd1 100644 (file)
 
 class VTKVIEWER_EXPORT VTKViewer_OpenGLRenderer : public vtkOpenGLRenderer
 {
+public:
+  enum {
+    HorizontalGradient,
+    VerticalGradient,
+    FirstDiagonalGradient,
+    SecondDiagonalGradient,
+    FirstCornerGradient,
+    SecondCornerGradient,
+    ThirdCornerGradient,
+    FourthCornerGradient
+  };
+
 public:
   static VTKViewer_OpenGLRenderer *New();
   vtkTypeMacro(VTKViewer_OpenGLRenderer,vtkOpenGLRenderer);
 
-  virtual void Clear(void); 
+  virtual void SetGradientType( const int );
+
+  virtual void Clear(void);
 
 protected:
   VTKViewer_OpenGLRenderer();
   ~VTKViewer_OpenGLRenderer();
 
+private:
+  int GradientType;
+
 private:
   VTKViewer_OpenGLRenderer(const VTKViewer_OpenGLRenderer&);  // Not implemented.
   void operator=(const VTKViewer_OpenGLRenderer&);  // Not implemented.
index 44cb5fd90c107bb31ec1f1cbcdeb9ca7e520f6ab..15e4d90da0d86de864caf41315958f84e48d91cf 100755 (executable)
@@ -64,8 +64,22 @@ VTKViewer_Viewer::~VTKViewer_Viewer()
 /*! Get data for supported background modes: gradient types, identifiers and supported image formats */
 QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
 {
-  gradList << tr( "GT_VERTICALGRADIENT" );  // only vertical type of gradient is supported
-  idList   << VerticalGradient;             // only vertical type of gradient is supported
+  gradList << tr( "GT_HORIZONTALGRADIENT" )
+           << tr( "GT_VERTICALGRADIENT" )
+           << tr( "GT_FIRSTDIAGONALGRADIENT" )
+           << tr( "GT_SECONDDIAGONALGRADIENT" )
+           << tr( "GT_FIRSTCORNERGRADIENT" )
+           << tr( "GT_SECONDCORNERGRADIENT" )
+           << tr( "GT_THIRDCORNERGRADIENT" )
+           << tr( "GT_FOURTHCORNERGRADIENT" );
+  idList   << HorizontalGradient
+           << VerticalGradient
+           << FirstDiagonalGradient
+           << SecondDiagonalGradient
+           << FirstCornerGradient
+           << SecondCornerGradient
+           << ThirdCornerGradient
+           << FourthCornerGradient;
 #ifdef VTK_ENABLE_TEXTURED_BACKGROUND
   txtList  << Qtx::CenterTexture << Qtx::TileTexture << Qtx::StretchTexture;
 #endif
index a5c135e7f4a0719a32494619b3d80194b584cbb2..9976152af5f85dc83ad656e592bdf402f3bb2858 100755 (executable)
@@ -41,8 +41,15 @@ class VTKVIEWER_EXPORT VTKViewer_Viewer: public SUIT_ViewModel
 public:
   /*! supported gradient types */
   enum {
+    HorizontalGradient,
     VerticalGradient,
-    LastGradient = VerticalGradient,
+    FirstDiagonalGradient,
+    SecondDiagonalGradient,
+    FirstCornerGradient,
+    SecondCornerGradient,
+    ThirdCornerGradient,
+    FourthCornerGradient,
+    LastGradient = FourthCornerGradient,
   };
 
   /*!Initialize type of viewer.*/
index 3dfd857525cdfe9e19a75e62f7457e1be3235c39..fcafdae31c380daae699f5cc4522806680775bd4 100755 (executable)
@@ -485,25 +485,25 @@ void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
       {
        QColor c1, c2;
        int type = bgData.gradient( c1, c2 );
-       // VSR: Currently, only vertical gradient is supported by VTK. 
-       // In future, switch operator might be added here to process different supported gradient types.
-       if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) {
-         if ( !c2.isValid() ) c2 = c1;
-         // show two-color gradient background
-         getRenderer()->SetTexturedBackground( false );    // cancel texture mode
-         getRenderer()->SetGradientBackground( true );     // switch to gradient mode
-         // VSR: In VTK, gradient is colored from bottom to top:
-         // - top color is set via SetBackground2()
-         // - bottom color is set via SetBackground()
-         // So, we reverse colors, to draw gradient from top to bottom instead.
-         getRenderer()->SetBackground(  c2.red()/255.0, 
-                                        c2.green()/255.0,
-                                        c2.blue()/255.0 ); // set first gradient color
-         getRenderer()->SetBackground2( c1.red()/255.0,
-                                        c1.green()/255.0,
-                                        c1.blue()/255.0 ); // set second gradient color
-         ok = true;
-       }
+        if ( c1.isValid() )
+        {
+          if ( !c2.isValid() )
+            c2 = c1;
+
+          // show two-color gradient background
+          getRenderer()->SetTexturedBackground( false );    // cancel texture mode
+          getRenderer()->SetGradientBackground( true );     // switch to gradient mode
+
+          VTKViewer_OpenGLRenderer* aRenderer =
+            VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
+          if( aRenderer )
+          {
+            aRenderer->SetGradientType( type );
+            aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
+            aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
+            ok = true;
+          }
+        }
        break;
       }
     case Qtx::CustomGradientBackground:
index a05fe00afcf491acf2c3c065ae368505cab3c185..0f27a1597e0d6a704e873c0385f0489818c47119 100644 (file)
         <source>MEN_CHANGE_BACKGROUD</source>
         <translation>Change Background...</translation>
     </message>
+    <message>
+        <source>GT_HORIZONTALGRADIENT</source>
+        <translation>Horizontal gradient</translation>
+    </message>
     <message>
         <source>GT_VERTICALGRADIENT</source>
         <translation>Vertical gradient</translation>
     </message>
+    <message>
+        <source>GT_FIRSTDIAGONALGRADIENT</source>
+        <translation>First diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDDIAGONALGRADIENT</source>
+        <translation>Second diagonal gradient</translation>
+    </message>
+    <message>
+        <source>GT_FIRSTCORNERGRADIENT</source>
+        <translation>First corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_SECONDCORNERGRADIENT</source>
+        <translation>Second corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_THIRDCORNERGRADIENT</source>
+        <translation>Third corner gradient</translation>
+    </message>
+    <message>
+        <source>GT_FOURTHCORNERGRADIENT</source>
+        <translation>Fourth corner gradient</translation>
+    </message>
     <message>
         <source>BG_IMAGE_FILES</source>
         <translation>Image files (*.png *.jpg *.jpeg *.bmp *.tif *.tiff *.mhd *.mha)</translation>