From: mpa Date: Mon, 2 Feb 2015 10:25:58 +0000 (+0300) Subject: 0022781: [CEA 1281] Preferences of colors and textures of clipping planes X-Git-Tag: V7_6_0a1~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=782de26fa93b9fb5edc9854cdda4a77b03c92175;p=modules%2Fgui.git 0022781: [CEA 1281] Preferences of colors and textures of clipping planes --- diff --git a/doc/salome/gui/images/pref_salome_occviewer.png b/doc/salome/gui/images/pref_salome_occviewer.png index 00bf8a743..35a4f21a6 100644 Binary files a/doc/salome/gui/images/pref_salome_occviewer.png and b/doc/salome/gui/images/pref_salome_occviewer.png differ diff --git a/doc/salome/gui/input/setting_preferences.doc b/doc/salome/gui/input/setting_preferences.doc index 9fabab109..4bbf36596 100644 --- a/doc/salome/gui/input/setting_preferences.doc +++ b/doc/salome/gui/input/setting_preferences.doc @@ -140,6 +140,13 @@ different locations have the same name. - XZ View - YZ View - XY View + +- Clipping parameters - specifies the default clipping plane parameters. + - Color - allows to change the color of the clipped region. + - Use default texture - if this option is switched on, the default texture + will be used for clipping texture, otherwise - the texture specified in "Texture" field. + - Texture - allows to change the texture of the clipped region + (enable if "Use default texture" is switched off). \anchor vtk_preferences

VTK 3D Viewer Preferences

diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 49d8b625b..64bb76918 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -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 <> + // ... "Clipping" group <> + 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 <> + // ... -> empty frame (for layout) <> 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 lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + QListIterator 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 lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + QListIterator 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 lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + QListIterator 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 ); diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 4497c7cce..8807cf544 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -144,6 +144,8 @@ + + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index d8aa735b3..15612a4e5 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -759,6 +759,26 @@ The changes will be applied on the next application session. PREF_PRESELECTION_DISABLED Disabled + + PREF_GROUP_CLIPPING + Clipping parameters + + + PREF_CLIPPING_COLOR + Color + + + PREF_CLIPPING_DEFAULT_TEXTURE + Use default texture + + + PREF_CLIPPING_TEXTURE + Texture + + + OCC_TEXTURE_FILES + Image files (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr) + TOT_CLOSE Close diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 5f0fb0125..fa7d33352 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -759,6 +759,26 @@ Les modifications seront appliquées à la prochaine session. PREF_PRESELECTION_DISABLED Désactivée + + PREF_GROUP_CLIPPING + Plan de coupe + + + PREF_CLIPPING_COLOR + Couleur + + + PREF_CLIPPING_DEFAULT_TEXTURE + Use default texture + + + PREF_CLIPPING_TEXTURE + Texture + + + OCC_TEXTURE_FILES + Fichiers images (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr) + TOT_CLOSE Fermer diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index b415523b9..f95bfd79e 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -759,6 +759,26 @@ session. It has to be closed before working with another study. PREF_PRESELECTION_DISABLED 無効になっています。 + + PREF_GROUP_CLIPPING + Clipping + + + PREF_CLIPPING_COLOR + Color + + + PREF_CLIPPING_DEFAULT_TEXTURE + Use default texture + + + PREF_CLIPPING_TEXTURE + Texture + + + OCC_TEXTURE_FILES + イメージファイル (*.jpeg *jpg *.jpe *.png *.bmp *.gif *.ppm *.tif *.tiff* .tga *.exr) + TOT_CLOSE 閉じる diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 83574b196..9f4e6f761 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -58,6 +58,7 @@ #include #include +#include #include #include @@ -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; } /*! diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 685e362b0..4564da1fa 100755 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -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