]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
0022781: [CEA 1281] Preferences of colors and textures of clipping planes
authormpa <mpa@opencascade.com>
Mon, 2 Feb 2015 10:25:58 +0000 (13:25 +0300)
committermpa <mpa@opencascade.com>
Mon, 2 Feb 2015 10:25:58 +0000 (13:25 +0300)
doc/salome/gui/images/pref_salome_occviewer.png
doc/salome/gui/input/setting_preferences.doc
src/LightApp/LightApp_Application.cxx
src/LightApp/resources/LightApp.xml
src/LightApp/resources/LightApp_msg_en.ts
src/LightApp/resources/LightApp_msg_fr.ts
src/LightApp/resources/LightApp_msg_ja.ts
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h

index 00bf8a743194bde366c40cc59d606d01511f774a..35a4f21a608841bffc371baf534905a21f973408 100644 (file)
Binary files a/doc/salome/gui/images/pref_salome_occviewer.png and b/doc/salome/gui/images/pref_salome_occviewer.png differ
index 9fabab109f09755d21e2be44eaf455327e0add51..4bbf36596a2d31c930c3b8df76aa12e1a9cbcf18 100644 (file)
@@ -140,6 +140,13 @@ different locations have the same name.
   - <b>XZ View</b>
   - <b>YZ View</b>
   - <b>XY View</b>
+  
+- <b>Clipping parameters</b> - specifies the default clipping plane parameters.
+  - <b>Color</b> - allows to change the color of the clipped region.
+  - <b>Use default texture</b> - if this option is switched on, the default texture
+    will be used for clipping texture, otherwise - the texture specified in "Texture" field.
+  - <b>Texture</b> - allows to change the texture of the clipped region 
+    (enable if "Use default texture" is switched off).
 
 \anchor vtk_preferences
 <h2>VTK 3D Viewer Preferences</h2>
index 49d8b625bcd467b10d8335be4c745fc1cf19184e..64bb76918566b5d06d011bb17b22d4d7ab685e80 100644 (file)
@@ -1492,6 +1492,10 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
     vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
     vm->enableSelection(    resMgr->booleanValue( "OCCViewer", "enable_selection",    vm->isSelectionEnabled() ) );
+    vm->setClippingColor( resMgr->colorValue( "OCCViewer", "clipping_color", vm->clippingColor() ) );
+    vm->useDefaultTexture( resMgr->booleanValue( "OCCViewer", "clipping_use_default_texture", vm->isDefaultTextureUsed() ) );
+    vm->setClippingTexture( resMgr->stringValue( "OCCViewer", "clipping_texture", vm->clippingTexture() ) );
+
 
     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
@@ -2303,6 +2307,22 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
                       LightApp_Preferences::Bool, "OCCViewer", "enable_selection" );
   // ... "Selection" group <<end>>
 
+  // ... "Clipping" group <<start>>
+  int occClippingGroup = pref->addPreference( tr( "PREF_GROUP_CLIPPING" ), occGroup );
+  // .... -> clipping color
+  pref->addPreference( tr( "PREF_CLIPPING_COLOR" ), occClippingGroup,
+               LightApp_Preferences::Color, "OCCViewer", "clipping_color" );
+  int texturePref = pref->addPreference( "", occClippingGroup, LightApp_Preferences::Frame );
+  pref->setItemProperty( "columns", 2, texturePref );
+  // .... -> use default texture
+  pref->addPreference( tr( "PREF_CLIPPING_DEFAULT_TEXTURE" ), texturePref,
+               LightApp_Preferences::Bool, "OCCViewer", "clipping_use_default_texture" );
+  // .... -> clipping texture
+  int filePref = pref->addPreference( tr( "PREF_CLIPPING_TEXTURE" ), texturePref,
+               LightApp_Preferences::File, "OCCViewer", "clipping_texture" );
+  pref->setItemProperty( "path_filter", tr( "OCC_TEXTURE_FILES" ), filePref );
+  // ... "Clipping" group <<end>>
+
   // ... -> empty frame (for layout) <<start>>
   int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame );
   pref->setItemProperty( "margin",  0, occGen );
@@ -2776,6 +2796,63 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
   }
 #endif
 
+#ifndef DISABLE_OCCVIEWER
+  if ( sec == QString( "OCCViewer" ) && param == QString( "clipping_color" ) )
+  {
+    QColor aColor = resMgr->colorValue( "OCCViewer", "clipping_color", QColor( 50, 50, 50 ) );
+    QList<SUIT_ViewManager*> lst;
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> it( lst );
+    while ( it.hasNext() )
+    {
+      SUIT_ViewModel* vm = it.next()->getViewModel();
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+        continue;
+
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      occVM->setClippingColor( aColor );
+    }
+  }
+#endif
+
+#ifndef DISABLE_OCCVIEWER
+  if ( sec == QString( "OCCViewer" ) && param == QString( "clipping_use_default_texture" ) )
+  {
+    bool isDefaultTextureUsed = resMgr->booleanValue( "OCCViewer", "clipping_use_default_texture" );
+    QList<SUIT_ViewManager*> lst;
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> it( lst );
+    while ( it.hasNext() )
+    {
+      SUIT_ViewModel* vm = it.next()->getViewModel();
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+        continue;
+
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      occVM->useDefaultTexture( isDefaultTextureUsed );
+    }
+  }
+#endif
+
+#ifndef DISABLE_OCCVIEWER
+  if ( sec == QString( "OCCViewer" ) && param == QString( "clipping_texture" ) )
+  {
+    QString aTexture = resMgr->stringValue( "OCCViewer", "clipping_texture" );
+    QList<SUIT_ViewManager*> lst;
+    viewManagers( OCCViewer_Viewer::Type(), lst );
+    QListIterator<SUIT_ViewManager*> it( lst );
+    while ( it.hasNext() )
+    {
+      SUIT_ViewModel* vm = it.next()->getViewModel();
+      if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
+        continue;
+
+      OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
+      occVM->setClippingTexture( aTexture );
+    }
+  }
+#endif
+
   if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
   {
     int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
index 4497c7ccef0c4cb0c43306f25551b11c9a42fbfe..8807cf544128e858d608c9ecd427f32223f79c9d 100644 (file)
     <!-- OCC viewer preferences -->
     <parameter name="enable_preselection" value="true"/>
     <parameter name="enable_selection"    value="true"/>
+    <parameter name="clipping_color"      value="50, 50, 50"/>
+    <parameter name="clipping_use_default_texture" value="true"/>
     <parameter name="background"      value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
     <parameter name="xz_background"   value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
     <parameter name="yz_background"   value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
index d8aa735b34daf0938512e7a63bb6a6db6af3eb7e..15612a4e57051d520124fae3a7f79250f664f6ed 100644 (file)
@@ -759,6 +759,26 @@ The changes will be applied on the next application session.</translation>
         <source>PREF_PRESELECTION_DISABLED</source>
         <translation>Disabled</translation>
     </message>
+    <message>
+        <source>PREF_GROUP_CLIPPING</source>
+        <translation>Clipping parameters</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_COLOR</source>
+        <translation>Color</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_DEFAULT_TEXTURE</source>
+        <translation>Use default texture</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_TEXTURE</source>
+        <translation>Texture</translation>
+    </message>
+    <message>
+        <source>OCC_TEXTURE_FILES</source>
+        <translation>Image files (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr)</translation>
+    </message>
     <message>
         <source>TOT_CLOSE</source>
         <translation>Close</translation>
index 5f0fb012587649b6e12e47295c46bd6a77034945..fa7d33352681fe8610ac49ad8d3eeec09526e86c 100755 (executable)
@@ -759,6 +759,26 @@ Les modifications seront appliquées à la prochaine session.</translation>
         <source>PREF_PRESELECTION_DISABLED</source>
         <translation>Désactivée</translation>
     </message>
+    <message>
+        <source>PREF_GROUP_CLIPPING</source>
+        <translation>Plan de coupe</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_COLOR</source>
+        <translation>Couleur</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_DEFAULT_TEXTURE</source>
+        <translation type="unfinished">Use default texture</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_TEXTURE</source>
+        <translation>Texture</translation>
+    </message>
+    <message>
+        <source>OCC_TEXTURE_FILES</source>
+        <translation>Fichiers images (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr)</translation>
+    </message>
     <message>
         <source>TOT_CLOSE</source>
         <translation>Fermer</translation>
index b415523b9f797a9c35837c527a9a39d949f092d5..f95bfd79e8ca262e39e32c84a9c9256db8b6e9c9 100644 (file)
@@ -759,6 +759,26 @@ session. It has to be closed before working with another study.</translation>
       <source>PREF_PRESELECTION_DISABLED</source>
       <translation>無効になっています。</translation>
     </message>
+    <message>
+        <source>PREF_GROUP_CLIPPING</source>
+        <translation type="unfinished">Clipping</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_COLOR</source>
+        <translation type="unfinished">Color</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_DEFAULT_TEXTURE</source>
+        <translation type="unfinished">Use default texture</translation>
+    </message>
+    <message>
+        <source>PREF_CLIPPING_TEXTURE</source>
+        <translation type="unfinished">Texture</translation>
+    </message>
+    <message>
+        <source>OCC_TEXTURE_FILES</source>
+        <translation>イメージファイル (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr)</translation>
+    </message>
     <message>
       <source>TOT_CLOSE</source>
       <translation>閉じる</translation>
index 83574b1969debc8e52f24929d51fc18589b6951a..9f4e6f761ab68b6dbda58443861dcd6be61daf78 100755 (executable)
@@ -58,6 +58,7 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
 #include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_MaterialAspect.hxx>
 #include <Graphic3d_TextureParams.hxx>
 
 #include <Geom_Axis2Placement.hxx>
@@ -141,6 +142,12 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   // selection
   mySelectionEnabled = true;
   myMultiSelectionEnabled = true;
+
+  //set clipping color and texture to standard
+  myClippingColor = QColor( 50, 50, 50 );
+  myDefaultTextureUsed = true;
+  myClippingTexture = QString();
+
 }
 
 /*!
@@ -572,6 +579,112 @@ void OCCViewer_Viewer::enableMultiselection(bool isEnable)
   }
 }
 
+/*!
+  Sets a color of the clipped region
+  \param theColor - a new color of the clipped region
+*/
+void OCCViewer_Viewer::setClippingColor( const QColor& theColor )
+{
+  myClippingColor = theColor;
+
+  if( myInternalClipPlanes.IsEmpty() )
+    return;
+
+  Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
+  aMaterialAspect.SetColor( Quantity_Color( theColor.redF(), theColor.greenF(),
+                                            theColor.blueF(), Quantity_TOC_RGB ) );
+
+  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
+    myInternalClipPlanes.Value(i)->SetCappingMaterial( aMaterialAspect );
+
+  update();
+}
+
+/*!
+  \return clipping color
+*/
+QColor OCCViewer_Viewer::clippingColor() const
+{
+  return myClippingColor;
+}
+
+// initialize a texture for clipped region
+Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture)
+{
+  QString aTextureFile = isDefault ? ":images/hatch.png" : theTexture;
+  QPixmap px( aTextureFile );
+  const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
+  Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
+  if( aTexture->IsDone() ) {
+    aTexture->EnableRepeat();
+    if( isDefault ) {
+      aTexture->EnableModulate();
+      aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.01, 0.01 ) );
+    }
+    else {
+      aTexture->DisableModulate();
+      aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.005, 0.005 ) );
+    }
+  }
+  return aTexture;
+}
+
+/*!
+  Sets default texture enabled status
+  \param isUsed - new status
+*/
+void OCCViewer_Viewer::useDefaultTexture( const bool isUsed )
+{
+  myDefaultTextureUsed = isUsed;
+
+  if( myInternalClipPlanes.IsEmpty() )
+    return;
+
+  Handle(Graphic3d_Texture2Dmanual) aTexture =
+    initClippingTexture( myDefaultTextureUsed, myClippingTexture );
+
+  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
+    myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
+
+  update();
+}
+
+/*!
+  \return true if default texture is used
+*/
+bool OCCViewer_Viewer::isDefaultTextureUsed() const
+{
+  return myDefaultTextureUsed;
+}
+
+/*!
+  Sets a texture of the clipped region
+  \param theTexture - a new texture of the clipped region
+*/
+void OCCViewer_Viewer::setClippingTexture( const QString& theTexture )
+{
+  myClippingTexture = theTexture;
+
+  if( myInternalClipPlanes.IsEmpty() || myDefaultTextureUsed )
+    return;
+
+  Handle(Graphic3d_Texture2Dmanual) aTexture =
+    initClippingTexture( myDefaultTextureUsed, myClippingTexture );
+
+  for( int i = 1; i <= myInternalClipPlanes.Size(); i++ )
+    myInternalClipPlanes.Value(i)->SetCappingTexture( aTexture );
+
+  update();
+}
+
+/*!
+  \return clipping texture
+*/
+QString OCCViewer_Viewer::clippingTexture() const
+{
+  return myClippingTexture;
+}
+
 /*!
   Builds popup for occ viewer
 */
@@ -1051,18 +1164,15 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP
   aGraphic3dPlane->SetOn( theIsOn );
   aGraphic3dPlane->SetCapping( Standard_True );
 
-  // load capping texture
-  QPixmap px( ":images/hatch.png" );
-  if( !px.isNull() ) {
-    const Handle(Image_PixMap) aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
-    Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual( aPixmap );
-    if( aTexture->IsDone() ) {
-      aTexture->EnableModulate();
-      aTexture->EnableRepeat();
-      aTexture->GetParams()->SetScale( Graphic3d_Vec2( 0.01, 0.01 ) );
-      aGraphic3dPlane->SetCappingTexture( aTexture );
-    }
-  }
+  // set capping color
+  Graphic3d_MaterialAspect aMaterialAspect = Graphic3d_MaterialAspect();
+  aMaterialAspect.SetColor( Quantity_Color( myClippingColor.redF(), myClippingColor.greenF(),
+                                            myClippingColor.blueF(), Quantity_TOC_RGB ) );
+  aGraphic3dPlane->SetCappingMaterial( aMaterialAspect );
+
+  // set capping texture
+  aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture) );
+
   return aGraphic3dPlane;
 }
 /*!
index 685e362b029a80e8950426bd7e7f0fa16589115f..4564da1fa47f7de5ec2d22112eb7e78a14020b5c 100755 (executable)
@@ -147,6 +147,15 @@ public:
   void                            enableMultiselection(bool isEnable);
   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
 
+  void                            setClippingColor( const QColor& );
+  QColor                          clippingColor() const;
+
+  void                            useDefaultTexture( const bool );
+  bool                            isDefaultTextureUsed() const;
+
+  void                            setClippingTexture( const QString& );
+  QString                         clippingTexture() const;
+
   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
 
   void                            setStaticTrihedronDisplayed(const bool on);
@@ -191,6 +200,7 @@ protected slots:
   void onChangeBackground();
 
 protected:
+
   Handle(V3d_Viewer)              myV3dViewer;
 
   Handle(AIS_Trihedron)           myTrihedron;
@@ -217,6 +227,11 @@ protected:
 
   ClipPlanesList                  myClipPlanes;
   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
+
+  QColor                          myClippingColor;
+  bool                            myDefaultTextureUsed;
+  QString                         myClippingTexture;
+
 };
 
 #ifdef WIN32