-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <SUIT_ViewManager.h>
#include <SUIT_ViewModel.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
#include <QColor>
#include <QFileInfo>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QApplication>
+#include <QTimer>
-#include <Visual3d_View.hxx>
-#include <V3d_Viewer.hxx>
+#if OCC_VERSION_MAJOR < 7
+ #include <Visual3d_View.hxx>
+#endif
#if OCC_VERSION_LARGE > 0x06070100
#include <V3d_View.hxx>
#if defined WIN32
#include <WNT_Window.hxx>
#else
-#include <Xw_Window.hxx>
+//#include <Xw_Window.hxx>
#endif
static double rx = 0.;
}
#endif
- setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+ setDefaultParams();
+
+ myCursor = NULL;
}
/*!
*/
OCCViewer_ViewPort3d::~OCCViewer_ViewPort3d()
{
- emit vpClosed();
+ if ( myCursor )
+ {
+ delete myCursor;
+ myCursor = NULL;
+ }
+
+ emit vpClosed(this);
Handle(V3d_View) aView = activeView();
if (!aView.IsNull())
aView->Remove();
view->View()->Deactivate();
}
- /* create static trihedron (16551: EDF PAL 501) */
- OCCViewer_ViewWindow* aVW = dynamic_cast<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
- if ( aVW ) {
- OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( aVW->getViewManager()->getViewModel() );
- if ( aViewModel && aViewModel->isStaticTrihedronDisplayed() ){
- view->ZBufferTriedronSetup();
- view->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
- }
- }
-
- emit( vpMapped() );
+ emit( vpMapped(this) );
return true;
}
if ( activeView().IsNull() ) return;
if ( !myBackground.isValid() ) return;
- // VSR: Important note on below code.
- // In OCCT (in version 6.5.2), things about the background drawing
- // are not straightforward and not clearly understandable:
- // - Horizontal gradient is drawn vertically (!), well ok, from top side to bottom one.
- // - Vertical gradient is drawn horizontally (!), from right side to left one (!!!).
- // - First and second diagonal gradients are confused.
- // - Image texture, once set, can not be removed (!).
- // - Texture image fill mode Aspect_FM_NONE is not taken into account (and means the same
- // as Aspect_FM_CENTERED).
- // - The only way to cancel gradient background (and get back to single colored) is to
- // set gradient background style to Aspect_GFM_NONE while passing two colors is also needed
- // (see V3d_View::SetBgGradientColors() function).
- // - Also, it is impossible to draw texture image above the gradiented background (only above
- // single-colored).
- // In OCCT 6.5.3 all above mentioned problems are fixed; so, above comment should be removed as soon
- // as SALOME is migrated to OCCT 6.5.3. The same concerns #ifdef statements in the below code
switch ( myBackground.mode() ) {
case Qtx::ColorBackground:
{
// Unset texture should be done here
// ...
Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
-#else
- // cancel gradient background (in OCC before v6.5.3 the only way to do this is to set it to NONE type passing arbitrary colors as parameters)
- activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE );
-#endif
// then change background color
activeView()->SetBackgroundColor( qCol );
// update viewer
activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
switch ( type ) {
case OCCViewer_Viewer::HorizontalGradient:
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
-#else
- // in OCCT before v6.5.3, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type
- // and interchange the colors
- activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_VER, Standard_True );
-#endif
break;
case OCCViewer_Viewer::VerticalGradient:
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
-#else
- // in OCCT before v6.5.3, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type
- activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
-#endif
break;
case OCCViewer_Viewer::Diagonal1Gradient:
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
-#else
- // in OCCT before v6.5.3, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type
- // and interchange the colors
- activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_DIAG2, Standard_True );
-#endif
break;
case OCCViewer_Viewer::Diagonal2Gradient:
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
-#else
- // in OCCT before v6.5.3, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type
- activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
-#endif
break;
case OCCViewer_Viewer::Corner1Gradient:
activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
default:
break;
}
-#if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
- // VSR: In OCCT before v6.5.3 below code can't be used because of very ugly bug - it has been impossible to
- // clear the background texture image as soon as it was once set to the viewer.
if ( myBackground.isTextureShown() ) {
QString fileName;
int textureMode = myBackground.texture( fileName );
activeView()->Update();
}
}
-#endif
}
/*!
*/
void OCCViewer_ViewPort3d::startZoomAtPoint( int x, int y )
{
-#if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
if ( !activeView().IsNull() && isAdvancedZoomingEnabled() )
activeView()->StartZoomAtPoint( x, y );
-#endif
}
/*!
// as OCCT respects a sign of only dx,
// but we want both signes to be taken into account
//activeView()->Zoom( x0, y0, x, y );
-#if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
if ( isAdvancedZoomingEnabled() )
activeView()->ZoomAtPoint( x0, y0, x, y );
else
-#endif
activeView()->Zoom( x0 + y0, 0, x + y, 0 );
emit vpTransformed( this );
}
default:
break;
}
- activeView()->DepthFitAll();
+ // VSR: 10.06.2015: next line commented out - causes ugly blinking on starting rotation with Perspective projection mode
+ //activeView()->DepthFitAll();
}
}
mapView( activeView() );
#endif
if ( !myWindow.IsNull() ) {
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QApplication::syncX();
- QRect rc = e->rect();
- if ( !myPaintersRedrawing )
+#endif
+ if ( !myPaintersRedrawing ) {
+#if OCC_VERSION_MAJOR < 7
+ QRect rc = e->rect();
activeView()->Redraw( rc.x(), rc.y(), rc.width(), rc.height() );
+#else
+ activeView()->Redraw();
+#endif
+ }
}
OCCViewer_ViewPort::paintEvent( e );
myBusy = false;
*/
void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
{
-#ifdef WIN32
+#if defined WIN32 || QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
/* Win32 : map before first show to avoid flicker */
if ( !mapped( activeView() ) )
mapView( activeView() );
#endif
- QApplication::syncX();
- if ( !activeView().IsNull() )
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+ QApplication::syncX();
+#endif
+ QTimer::singleShot( 0, this, SLOT( repaintViewAfterMove() ) );
+}
+
+/*!
+ Moved the viewport
+*/
+void OCCViewer_ViewPort3d::repaintViewAfterMove( )
+{
+ if ( !activeView().IsNull() ){
activeView()->MustBeResized();
+ }
}
/*!
/*
* Show/Hide static triedron
*/
-void OCCViewer_ViewPort3d::updateStaticTriedronVisibility() {
- OCCViewer_ViewWindow* aVW = dynamic_cast<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
- if ( aVW ) {
- OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( aVW->getViewManager()->getViewModel() );
- Handle(V3d_View) aView = activeView();
- if ( aViewModel ){
- if(aViewModel->isStaticTrihedronDisplayed()) {
- aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
- } else {
- aView->TriedronErase();
- }
- aView->Update();
- }
+void OCCViewer_ViewPort3d::showStaticTrihedron( bool on )
+{
+ Handle(V3d_View) aView = activeView();
+ if ( !aView ) return;
+
+ if ( on ) {
+ aView->ZBufferTriedronSetup();
+ aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
+ } else {
+ aView->TriedronErase();
}
+ aView->Update();
+}
+
+/*
+ * Create default cursor with a specific shape
+ */
+void OCCViewer_ViewPort3d::setDefaultCursor( Qt::CursorShape theCursorShape )
+{
+ if ( !myCursor )
+ myCursor = new QCursor();
+
+ myCursor->setShape( theCursorShape );
+}
+
+/*
+ * Get default cursor with a specific shape
+ */
+QCursor* OCCViewer_ViewPort3d::getDefaultCursor() const
+{
+ return myCursor;
+}
+
+/*
+ * Set default parameters from preferences
+ */
+void OCCViewer_ViewPort3d::setDefaultParams()
+{
+ setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+
+ // get ray tracing parameters from preferences
+ int aDepth = SUIT_Session::session()->resourceMgr()->integerValue( "OCCViewer", "rt_depth", 3 );
+ bool aReflection = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_reflection", true );
+ bool anAntialiasing = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_antialiasing", false );
+ bool aShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_shadow", true );
+ bool aTransparentShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_trans_shadow", true );
+
+ Graphic3d_RenderingParams& aParams = myActiveView->ChangeRenderingParams();
+ aParams.RaytracingDepth = aDepth;
+ aParams.IsReflectionEnabled = aReflection;
+ aParams.IsAntialiasingEnabled = anAntialiasing;
+ aParams.IsShadowEnabled = aShadow;
+ aParams.IsTransparentShadowEnabled = aTransparentShadow;
+ myActiveView->Redraw();
}