Salome HOME
[bos #40617][CEA] Preserve color with clipping plane mbs/40617_clipping_plane 23/head
authormbs <martin.bernhard@opencascade.com>
Mon, 18 Mar 2024 16:58:53 +0000 (16:58 +0000)
committermbs <martin.bernhard@opencascade.com>
Wed, 17 Apr 2024 16:12:28 +0000 (17:12 +0100)
12 files changed:
doc/salome/gui/images/pref_salome_occviewer.png [changed mode: 0644->0755]
doc/salome/gui/input/setting_preferences.rst
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_ClippingDlg.cxx
src/OCCViewer/OCCViewer_ViewModel.cxx
src/OCCViewer/OCCViewer_ViewModel.h
src/OCCViewer/OCCViewer_ViewWindow.cxx
src/SUIT/SUIT_ViewModel.h

old mode 100644 (file)
new mode 100755 (executable)
index 7bc2de5..694836e
Binary files a/doc/salome/gui/images/pref_salome_occviewer.png and b/doc/salome/gui/images/pref_salome_occviewer.png differ
index 80f3e6318b16f7ab880f35e3c802e54c2a9c1130..4e892e81e568988de57094e369ba88a29fc09aa6 100644 (file)
@@ -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.
 
index d72e414f5a293eca0416426cc5a2a28f8b0bf946..45759e967bc9de3b9fb5e41c1c1767d2ba91d017 100644 (file)
@@ -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 <<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 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<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->setClippingUseObjColor( useObjColor );
+    }
+  }
+#endif
+
 #ifndef DISABLE_OCCVIEWER
   if ( sec == QString( "OCCViewer" ) && param == QString( "projection_mode" ) )
   {
index 0e1c4249e764cebd02385eaca650232a47048102..de4dc7130c69fb58b149c7626cbd424c23249f7d 100644 (file)
     <parameter name="enable_quad_buffer_support" value="false"/>
     <parameter name="enable_preselection" value="true"/>
     <parameter name="enable_selection"    value="true"/>
+    <parameter name="clipping_use_object_color" value="true"/>
     <parameter name="clipping_color"      value="50, 50, 50"/>
     <parameter name="clipping_use_default_texture" value="true"/>
     <parameter name="clipping_modulate"   value="true"/>
index 6cbc59b1681eeaf9825601042ced1b26e5135d5b..490bc2252d18a17f2089dbd7aa603d75f297dbf8 100644 (file)
@@ -904,6 +904,10 @@ The changes will be applied on the next application session.</translation>
         <source>PREF_GROUP_CLIPPING</source>
         <translation>Clipping parameters</translation>
     </message>
+    <message>
+        <source>PREF_CLIPPING_USE_OBJECT_COLOR</source>
+        <translation>Use color of clipped object</translation>
+    </message>
     <message>
         <source>PREF_CLIPPING_COLOR</source>
         <translation>Color</translation>
index 687bb0765dafb46bb3ffa56e68085881c5ceffa2..826114cf7eb1df2cba26daa5f428299facfb9003 100644 (file)
@@ -900,6 +900,10 @@ Les modifications seront appliquées à la prochaine session.</translation>
         <source>PREF_GROUP_CLIPPING</source>
         <translation>Plan de coupe</translation>
     </message>
+    <message>
+        <source>PREF_CLIPPING_USE_OBJECT_COLOR</source>
+        <translation>Utiliser la couleur de l&apos;objet découpé</translation>
+    </message>
     <message>
         <source>PREF_CLIPPING_COLOR</source>
         <translation>Couleur</translation>
index 58f97692272c78bfd7ef3c802ed4e2bd05ea4b40..ba8d8bb270a488f06c6119b4bd64f099bdcc6aad 100644 (file)
@@ -899,6 +899,10 @@ Pythonファイルは、文字、数字、アンダースコアが含まれて
       <source>PREF_GROUP_CLIPPING</source>
       <translation>クリッピングパラメータ</translation>
     </message>
+    <message>
+        <source>PREF_CLIPPING_USE_OBJECT_COLOR</source>
+        <translation>切り取られたオブジェクトの色を使用する</translation>
+    </message>
     <message>
       <source>PREF_CLIPPING_COLOR</source>
       <translation>色</translation>
index bee978a53d547bebcfbfd01c8cdfd3b9f0c42466..72804a4f1efb381e91aeaffd30b591804987fef3 100644 (file)
@@ -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 );
 }
index d27bba499f87086d55b5c0c4c4acef1dac6cf189..e58abb5e73020f4c1051606e76ab858da8267c3e 100644 (file)
@@ -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;
+ }
index 75f35fc51bf741920be9042ed4112f1294190be4..1477e95493c9cd24ee436c0d2ca8a1a495f19d96 100644 (file)
@@ -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;
index 1a1214cc43ae6b25aeb65553cc773be2a675de34..480c7cbe8d2700e253d5a16098a06f0e573d4c6b 100644 (file)
@@ -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 ) );
     }
index 1ab13e8d4b10ce68a80e3f5c9ca2f2cd96128395..b33a7ff25c2c8539f7717651264a0bb6a5f4cce2 100644 (file)
@@ -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 );