Salome HOME
0021791: [CEA 623] Clipping : no difference between a closed shell and a solid.
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.cxx
index f34b888e5e520ba294f279e9708e30d97cc7eedc..5aff3c60d3670f3b23dda84fc6ed71c5e09f0b49 100755 (executable)
@@ -26,6 +26,7 @@
 #include "OCCViewer_VService.h"
 #include "OCCViewer_ViewPort3d.h"
 #include "OCCViewer_ClippingDlg.h"
+#include "OCCViewer_Utilities.h"
 
 #include "SUIT_ViewWindow.h"
 #include "SUIT_ViewManager.h"
@@ -54,6 +55,9 @@
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Graphic3d_TextureParams.hxx>
+
 #include <Geom_Axis2Placement.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_DatumAspect.hxx>
@@ -153,11 +157,6 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
   // selection
   mySelectionEnabled = true;
   myMultiSelectionEnabled = true;
-  
-  
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  if(resMgr)
-    myShowStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
 }
 
 /*!
@@ -225,6 +224,9 @@ void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
     if ( vp3d )
     {
       vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
+      // connect signal from viewport
+      connect(vp3d, SIGNAL(vpClosed(OCCViewer_ViewPort3d*)), this, SLOT(onViewClosed(OCCViewer_ViewPort3d*)));
+      connect(vp3d, SIGNAL(vpMapped(OCCViewer_ViewPort3d*)), this, SLOT(onViewMapped(OCCViewer_ViewPort3d*)));
     }
   }
 }
@@ -243,9 +245,7 @@ SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
   initView( vw );
   // set default background for view window
   vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
-  // connect signal from viewport
-  connect(view->getViewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
-  connect(view->getViewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
+
   return view;
 }
 
@@ -393,7 +393,7 @@ void OCCViewer_Viewer::onKeyPress(SUIT_ViewWindow* theWindow, QKeyEvent* theEven
   emit selectionChanged();
 }
 
-void OCCViewer_Viewer::onViewClosed()
+void OCCViewer_Viewer::onViewClosed(OCCViewer_ViewPort3d*)
 {
   Standard_Integer aViewsNb = 0;
   for ( myV3dViewer->InitActiveViews(); myV3dViewer->MoreActiveViews(); myV3dViewer->NextActiveViews())
@@ -404,9 +404,13 @@ void OCCViewer_Viewer::onViewClosed()
   }
 }
 
-void OCCViewer_Viewer::onViewMapped()
+void OCCViewer_Viewer::onViewMapped(OCCViewer_ViewPort3d* viewPort)
 {
   setTrihedronShown( true );
+  bool showStaticTrihedron = true;
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+  if ( resMgr ) showStaticTrihedron = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
+  viewPort->showStaticTrihedron( showStaticTrihedron );
 }
 
 int OCCViewer_Viewer::getTopLayerId()
@@ -899,7 +903,7 @@ void OCCViewer_Viewer::isos( int& u, int& v ) const
  */
 OCCViewer_ViewWindow* OCCViewer_Viewer::createSubWindow()
 {
-  return new OCCViewer_ViewWindow( 0,  this);
+  return new OCCViewer_ViewWindow(0,  this);
 }
 
 // obsolete  
@@ -933,18 +937,10 @@ void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData&
 /*!
   Set the show static trihedron flag
 */
-void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on) {
-  if(myShowStaticTrihedron != on) {
-    OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
-    if(!aView)
-      return;
-
-    OCCViewer_ViewPort3d* vp3d = aView->getViewPort();
-    if(vp3d) {
-      myShowStaticTrihedron = on;
-      vp3d->updateStaticTriedronVisibility();
-    }
-  }
+void OCCViewer_Viewer::setStaticTrihedronDisplayed(const bool on)
+{
+  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
+  if ( aView ) aView->showStaticTrihedron( on );
 }
 
 /*!
@@ -1039,7 +1035,29 @@ void OCCViewer_Viewer::setSelectionOptions( bool isPreselectionEnabled, bool isS
   }
 }
 
-
+/*!
+  Creates clipping plane based on the incoming plane
+*/
+Handle(Graphic3d_ClipPlane) OCCViewer_Viewer::createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn)
+{
+  Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( thePlane );
+  aGraphic3dPlane->SetOn( theIsOn );
+  aGraphic3dPlane->SetCapping( Standard_True );
+
+  // load capping texture
+  QPixmap px( ":images/hatch.png" );
+  if( !px.isNull() ) {
+    const Handle(Image_PixMap) aPixmap = 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 );
+    }
+  }
+  return aGraphic3dPlane;
+}
 /*!
   Applies clipping planes to clippable objects
 */
@@ -1061,10 +1079,7 @@ void OCCViewer_Viewer::setClipPlanes(ClipPlanesList theList)
     gp_Pnt anOrigin( aPlane.X, aPlane.Y, aPlane.Z );
     gp_Dir aDirection( aDx, aDy, aDz );
 
-    Handle(Graphic3d_ClipPlane) aGraphic3dPlane = new Graphic3d_ClipPlane( gp_Pln( anOrigin, aDirection ) );
-    aGraphic3dPlane->SetOn( aPlane.IsOn );
-
-    myInternalClipPlanes.Append( aGraphic3dPlane );
+    myInternalClipPlanes.Append( createClipPlane( gp_Pln( anOrigin, aDirection ), aPlane.IsOn ) );
     myClipPlanes.push_back( aPlane );
   }