From: mbs Date: Mon, 18 Mar 2024 16:58:53 +0000 (+0000) Subject: [bos #40617][CEA] Preserve color with clipping plane X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmbs%2F40617_clipping_plane;p=modules%2Fgui.git [bos #40617][CEA] Preserve color with clipping plane --- diff --git a/doc/salome/gui/images/pref_salome_occviewer.png b/doc/salome/gui/images/pref_salome_occviewer.png old mode 100644 new mode 100755 index 7bc2de5e8..694836e29 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.rst b/doc/salome/gui/input/setting_preferences.rst index 80f3e6318..4e892e81e 100644 --- a/doc/salome/gui/input/setting_preferences.rst +++ b/doc/salome/gui/input/setting_preferences.rst @@ -156,9 +156,18 @@ OCC 3D Viewer Preferences - **Clipping parameters** - specifies the default clipping plane parameters. - - **Color** - allows to change the color of the clipped region. + - **Use color of clipped object** - allows to use the color of the clipped object in its clipped region. + - **Color** - allows to change the color of the entire clipped region (only used, if "Use color of clipped object" is switched off). + + .. note:: + Any of the above colors is only used, if "Modulate" is switched on and either "Use default texture" is checked or any texture with "non-black" pixels is given. + - **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). + + .. note:: + If "Use default texture" is switched off and no texture is given, the clipping region will be black. If you want the clipping region to be colored, provide a small white texture image, e.g. 8x8 pixels, and check the "Modulate" option. + - **Modulate** - controls if "Texture" should be mixed with "Color" parameter or not. - **Scale factor** - sets the scale factor for default and custom textures. diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index d72e414f5..45759e967 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2058,7 +2058,7 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType resMgr->stringValue( "OCCViewer", "clipping_texture", vm->clippingTexture() ), resMgr->booleanValue( "OCCViewer", "clipping_modulate", vm->isTextureModulated() ), resMgr->doubleValue( "OCCViewer", "clipping_scale", vm->clippingTextureScale() ) ); - + vm->setClippingUseObjColor( resMgr->booleanValue( "OCCViewer", "clipping_use_object_color", vm->isClippingObjColorUsed() ) ); viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr ); @@ -3063,11 +3063,16 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) // ... "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 object color + pref->addPreference( tr( "PREF_CLIPPING_USE_OBJECT_COLOR" ), texturePref, + LightApp_Preferences::Bool, "OCCViewer", "clipping_use_object_color" ); + // .... -> clipping color + pref->addPreference( tr( "PREF_CLIPPING_COLOR" ), texturePref, + LightApp_Preferences::Color, "OCCViewer", "clipping_color" ); + // .... -> use default texture pref->addPreference( tr( "PREF_CLIPPING_DEFAULT_TEXTURE" ), texturePref, LightApp_Preferences::Bool, "OCCViewer", "clipping_use_default_texture" ); @@ -3785,6 +3790,25 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString } #endif +#ifndef DISABLE_OCCVIEWER + if ( sec == QString( "OCCViewer" ) && param == QString( "clipping_use_object_color" ) ) + { + bool useObjColor = resMgr->booleanValue( "OCCViewer", "clipping_use_object_color" ); + 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->setClippingUseObjColor( useObjColor ); + } + } +#endif + #ifndef DISABLE_OCCVIEWER if ( sec == QString( "OCCViewer" ) && param == QString( "projection_mode" ) ) { diff --git a/src/LightApp/resources/LightApp.xml b/src/LightApp/resources/LightApp.xml index 0e1c4249e..de4dc7130 100644 --- a/src/LightApp/resources/LightApp.xml +++ b/src/LightApp/resources/LightApp.xml @@ -138,6 +138,7 @@ + diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 6cbc59b16..490bc2252 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -904,6 +904,10 @@ The changes will be applied on the next application session. PREF_GROUP_CLIPPING Clipping parameters + + PREF_CLIPPING_USE_OBJECT_COLOR + Use color of clipped object + PREF_CLIPPING_COLOR Color diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 687bb0765..826114cf7 100644 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -900,6 +900,10 @@ Les modifications seront appliquées à la prochaine session. PREF_GROUP_CLIPPING Plan de coupe + + PREF_CLIPPING_USE_OBJECT_COLOR + Utiliser la couleur de l'objet découpé + PREF_CLIPPING_COLOR Couleur diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index 58f976922..ba8d8bb27 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -899,6 +899,10 @@ Pythonファイルは、文字、数字、アンダースコアが含まれて PREF_GROUP_CLIPPING クリッピングパラメータ + + PREF_CLIPPING_USE_OBJECT_COLOR + 切り取られたオブジェクトの色を使用する + PREF_CLIPPING_COLOR 色 diff --git a/src/OCCViewer/OCCViewer_ClippingDlg.cxx b/src/OCCViewer/OCCViewer_ClippingDlg.cxx index bee978a53..72804a4f1 100644 --- a/src/OCCViewer/OCCViewer_ClippingDlg.cxx +++ b/src/OCCViewer/OCCViewer_ClippingDlg.cxx @@ -281,7 +281,7 @@ void XYZToDistance ( const Handle(AIS_InteractiveContext)& theIC, double aDistance = aZmax; double aRelativeDistance = aLength > 0.01 ? aDistance / aLength : 0.0; - aRelativeDistance = qMin( aRelativeDistance, aLength ); + aRelativeDistance = qMin( aRelativeDistance, 1.0 ); aRelativeDistance = qMax( aRelativeDistance, 0.0 ); theDistance = aRelativeDistance; } @@ -978,6 +978,7 @@ void OCCViewer_ClippingDlg::erasePreview() } } myPreviewPlaneVector.clear(); + myModel->updateTrihedron(); myModel->update(); myInteractor->setEnabled( false ); } diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index d27bba499..e58abb5e7 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -207,6 +207,8 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) myClippingTexture = QString(); myTextureModulated = true; myClippingTextureScale = 1.0; + // By default, use the object color in the clipping plane + myClippingUseObjColor = true; } @@ -923,6 +925,31 @@ void OCCViewer_Viewer::enableMultiselection(bool isEnable) } } +/*! + Sets whether to use the color of the clipped object for the clipped region + \param theUseObjColor - whether to use color of clipped object +*/ +void OCCViewer_Viewer::setClippingUseObjColor( bool theUseObjColor ) +{ + myClippingUseObjColor = theUseObjColor; + + if( myInternalClipPlanes.IsEmpty() ) + return; + + for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() ) + aPlaneIt.Value()->SetUseObjectMaterial(theUseObjColor); + + update(); +} + +/*! + \return whether object color is used for clipping region +*/ +bool OCCViewer_Viewer::isClippingObjColorUsed() const +{ + return myClippingUseObjColor; +} + /*! Sets a color of the clipped region \param theColor - a new color of the clipped region @@ -948,6 +975,14 @@ QColor OCCViewer_Viewer::clippingColor() const return myClippingColor; } +/*! + Set the texture's scale factor +*/ +inline void setTextureScale(Handle(Graphic3d_TextureMap) aTexture, double theScale) +{ + aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) ); +} + // initialize a texture for clipped region Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, const QString& theTexture, const bool isModulate, const double theScale ) @@ -959,7 +994,7 @@ Handle(Graphic3d_Texture2Dmanual) initClippingTexture( const bool isDefault, con if( aTexture->IsDone() ) { aTexture->EnableRepeat(); isModulate ? aTexture->EnableModulate() : aTexture->DisableModulate(); - aTexture->GetParams()->SetScale( Graphic3d_Vec2( 1/( theScale*100 ), -1 / ( theScale*100 ) ) ); + setTextureScale( aTexture, theScale ); } return aTexture; } @@ -982,9 +1017,10 @@ void OCCViewer_Viewer::setClippingTextureParams( const bool isDefault, const QSt if( myInternalClipPlanes.IsEmpty() ) return; + double hatchScale = computeHatchScale(); Handle(Graphic3d_Texture2Dmanual) aTexture = initClippingTexture( myDefaultTextureUsed, myClippingTexture, - myTextureModulated, myClippingTextureScale ); + myTextureModulated, hatchScale); for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() ) aPlaneIt.Value()->SetCappingTexture( aTexture ); @@ -1519,6 +1555,7 @@ bool OCCViewer_Viewer::computeTrihedronSize( double& theNewSize, double& theSize return false; double aMaxSide = computeSceneSize( view3d ); + setClippingTextureParams(myDefaultTextureUsed, myClippingTexture, myTextureModulated, myClippingTextureScale); // IPAL21687 // The boundary box of the view may be initialized but nullified @@ -1566,7 +1603,8 @@ double OCCViewer_Viewer::computeSceneSize(const Handle(V3d_View)& view3d) const /*! * Update the size of the trihedron */ -void OCCViewer_Viewer::updateTrihedron() { +void OCCViewer_Viewer::updateTrihedron() +{ if ( myTrihedron.IsNull() ) return; @@ -1610,8 +1648,10 @@ Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& theP setCappingColor( aGraphic3dPlane, myClippingColor ); // set capping texture + double hatchScale = computeHatchScale(); aGraphic3dPlane->SetCappingTexture( initClippingTexture( myDefaultTextureUsed, myClippingTexture, - myTextureModulated, myClippingTextureScale ) ); + myTextureModulated, hatchScale ) ); + aGraphic3dPlane->SetUseObjectMaterial(myClippingUseObjColor); return aGraphic3dPlane; } @@ -1640,16 +1680,7 @@ void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList) myClipPlanes.push_back( aPlane ); } - // 3. Apply clipping planes - AIS_ListOfInteractive aList; - myAISContext->DisplayedObjects (aList); - for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) { - Handle(AIS_InteractiveObject) anObj = anIter.Value(); - Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj); - if (!aShape.IsNull() && aShape->IsClippable()) { - aShape->SetClipPlanes(new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); // todo: store clipping planes in a handle? - } - } + applyClippingPlanes(false); } /*! @@ -1670,6 +1701,34 @@ void OCCViewer_Viewer::applyExistingClipPlanesToObject (const Handle(AIS_Interac } } +/*! + Applies clipping planes to all visible (and clippable) objects +*/ +void OCCViewer_Viewer::applyClippingPlanes(bool theUpdateHatch) +{ + if (myInternalClipPlanes.IsEmpty()) { + return; // Nothing to do + } + + if (theUpdateHatch) { + double hatchScale = computeHatchScale(); + for ( Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt ( myInternalClipPlanes ); aPlaneIt.More(); aPlaneIt.Next() ) { + Handle(Graphic3d_TextureMap) aTexture = aPlaneIt.Value()->CappingTexture(); + setTextureScale(aTexture, hatchScale); + } + } + + AIS_ListOfInteractive aList; + myAISContext->DisplayedObjects (aList); + for ( AIS_ListIteratorOfListOfInteractive anIter (aList); anIter.More(); anIter.Next() ) { + Handle(AIS_InteractiveObject) anObj = anIter.Value(); + Handle(ViewerData_AISShape) aShape = Handle(ViewerData_AISShape)::DownCast (anObj); + if (!aShape.IsNull() && aShape->IsClippable()) { + aShape->SetClipPlanes(new Graphic3d_SequenceOfHClipPlane(myInternalClipPlanes)); + } + } +} + /*! Returns the pointer to the clipping dialog box. */ @@ -1705,3 +1764,22 @@ bool OCCViewer_Viewer::enableDrawMode( bool on ) } return prev; } + + double OCCViewer_Viewer::computeHatchScale() const + { + // bos#40617: + // Update the hatch scale of the clipping texture based on the total size of all visible objects + double hatchScale = myClippingTextureScale; + Handle(V3d_Viewer) viewer = getViewer3d(); + viewer->InitActiveViews(); + if (viewer->MoreActiveViews()) + { + Handle(V3d_View) view3d = viewer->ActiveView(); + if ( !view3d.IsNull() ) + { + double aMaxSide = computeSceneSize( view3d ); + hatchScale = aMaxSide * myClippingTextureScale * 0.01; + } + } + return hatchScale; + } diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 75f35fc51..1477e9549 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -109,7 +109,8 @@ public: virtual QString getType() const { return Type(); } virtual void contextMenuPopup(QMenu*); - + virtual void applyClippingPlanes(bool theUpdateHatch); + void getSelectedObjects(AIS_ListOfInteractive& theList); void setObjectsSelected(const AIS_ListOfInteractive& theList); void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO,Standard_True);} @@ -224,6 +225,9 @@ public: bool enableDrawMode( bool on ); + void setClippingUseObjColor( bool use ); + bool isClippingObjColorUsed() const; + void setClippingColor( const QColor& ); QColor clippingColor() const; @@ -278,6 +282,9 @@ protected slots: protected: + double computeHatchScale() const; + + Handle(V3d_Viewer) myV3dViewer; Handle(AIS_ColorScale) myColorScale; Handle(AIS_Trihedron) myTrihedron; @@ -318,6 +325,7 @@ protected: ClipPlanesList myClipPlanes; Graphic3d_SequenceOfHClipPlane myInternalClipPlanes; + bool myClippingUseObjColor; QColor myClippingColor; bool myDefaultTextureUsed; QString myClippingTexture; diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 1a1214cc4..480c7cbe8 100644 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -2492,6 +2492,7 @@ void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x, const doub Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value(); aClipPlane->SetEquation(pln); aClipPlane->SetOn(Standard_True); + aClipPlane->SetUseObjectMaterial(true); } else { view->AddClipPlane( myModel->createClipPlane( pln, Standard_True ) ); } diff --git a/src/SUIT/SUIT_ViewModel.h b/src/SUIT/SUIT_ViewModel.h index 1ab13e8d4..b33a7ff25 100644 --- a/src/SUIT/SUIT_ViewModel.h +++ b/src/SUIT/SUIT_ViewModel.h @@ -67,6 +67,7 @@ public: virtual QString getType() const { return "SUIT_ViewModel"; } virtual void contextMenuPopup( QMenu* ) {} + virtual void applyClippingPlanes( bool theUpdateHatch ) {} static void setHotButton( InteractionStyle theInteractionStyle, HotOperation theOper, Qt::KeyboardModifiers theState, Qt::MouseButtons theButton );