#else
vm = new OCCViewer_Viewer( true );
#endif
- vm->setBackgroundColor( OCCViewer_ViewFrame::TOP_LEFT,
- resMgr->colorValue( "OCCViewer", "xz_background", vm->backgroundColor() ) );
- vm->setBackgroundColor( OCCViewer_ViewFrame::TOP_RIGHT,
- resMgr->colorValue( "OCCViewer", "yz_background", vm->backgroundColor() ) );
-
- vm->setBackgroundColor( OCCViewer_ViewFrame::BOTTOM_LEFT,
- resMgr->colorValue( "OCCViewer", "xy_background", vm->backgroundColor() ) );
- vm->setBackgroundColor( OCCViewer_ViewFrame::BOTTOM_RIGHT,
- resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
+ vm->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
+ resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
+ vm->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
+ resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
+ vm->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
+ resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
+ vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
+ resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ),
resMgr->booleanValue( "OCCViewer", "relative_size", vm->trihedronRelative() ));
if( vm )
{
vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
- vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
+ vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
vm->setStaticTrihedronVisible( resMgr->booleanValue( "VTKViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
if ( vm )
- vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
+ vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
#endif
}
#endif
QStringList aValuesList;
QList<QVariant> anIndicesList;
+ QIntList idList;
// . Top-level "SALOME" preferences group <<start>>
int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
// ... "Background" group <<start>>
int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
- pref->setItemProperty( "columns", 2, bgGroup );
+ // pref->setItemProperty( "columns", 2, bgGroup );
+ aValuesList.clear();
+ anIndicesList.clear();
+ QString formats = OCCViewer_Viewer::backgroundData( aValuesList, idList );
+ foreach( int gid, idList ) anIndicesList << gid;
// .... -> 3D viewer background
- pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
- LightApp_Preferences::Color, "OCCViewer", "background" );
+ int bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
+ LightApp_Preferences::Background, "OCCViewer", "background" );
+ pref->setItemProperty( "gradient_names", aValuesList, bgId );
+ pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
+ pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "custom_enabled", false, bgId );
+ pref->setItemProperty( "image_formats", formats, bgId );
// .... -> XZ viewer background
- pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup,
- LightApp_Preferences::Color, "OCCViewer", "xz_background" );
+ bgId = pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup,
+ LightApp_Preferences::Background, "OCCViewer", "xz_background" );
+ pref->setItemProperty( "gradient_names", aValuesList, bgId );
+ pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
+ pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "custom_enabled", false, bgId );
+ pref->setItemProperty( "image_formats", formats, bgId );
// .... -> YZ viewer background
- pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup,
- LightApp_Preferences::Color, "OCCViewer", "yz_background" );
+ bgId = pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup,
+ LightApp_Preferences::Background, "OCCViewer", "yz_background" );
+ pref->setItemProperty( "gradient_names", aValuesList, bgId );
+ pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
+ pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "custom_enabled", false, bgId );
+ pref->setItemProperty( "image_formats", formats, bgId );
// .... -> XY viewer background
- pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup,
- LightApp_Preferences::Color, "OCCViewer", "xy_background" );
+ bgId = pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup,
+ LightApp_Preferences::Background, "OCCViewer", "xy_background" );
+ pref->setItemProperty( "gradient_names", aValuesList, bgId );
+ pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
+ pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "custom_enabled", false, bgId );
+ pref->setItemProperty( "image_formats", formats, bgId );
// ... "Background" group <<end>>
// ... -> empty frame (for layout) <<start>>
// ... -> empty frame (for layout) <<start>>
int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame );
- pref->setItemProperty( "columns", 2, vtkGen );
+ //pref->setItemProperty( "columns", 2, vtkGen );
// .... -> projection mode
int vtkProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), vtkGen,
LightApp_Preferences::Selector, "VTKViewer", "projection_mode" );
pref->setItemProperty( "strings", aValuesList, vtkProjMode );
pref->setItemProperty( "indexes", anIndicesList, vtkProjMode );
// .... -> background
- pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
- LightApp_Preferences::Color, "VTKViewer", "background" );
+ aValuesList.clear();
+ anIndicesList.clear();
+ formats = SVTK_Viewer::backgroundData( aValuesList, idList );
+ foreach( int gid, idList ) anIndicesList << gid;
+ bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
+ LightApp_Preferences::Background, "VTKViewer", "background" );
+ pref->setItemProperty( "gradient_names", aValuesList, bgId );
+ pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
+ pref->setItemProperty( "texture_enabled", false, bgId );
+ pref->setItemProperty( "custom_enabled", false, bgId );
+ pref->setItemProperty( "image_formats", formats, bgId );
// .... -> navigation mode
int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), vtkGen,
LightApp_Preferences::Selector, "VTKViewer", "navigation_mode" );
// ... space mouse sub-group <<start>>
int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
- pref->setItemProperty( "columns", 2, vtkSM );
+ //pref->setItemProperty( "columns", 2, vtkSM );
// .... -> decrease speed increment
int spacemousePref1 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_1" ), vtkSM,
LightApp_Preferences::Selector, "VTKViewer",
pref->setItemProperty( "strings", aValuesList, verScale );
pref->setItemProperty( "indexes", anIndicesList, verScale );
// ... -> background
- pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
+ pref->addPreference( tr( "PREF_VIEWER_BACKGROUND_COLOR" ), plot2dGroup,
LightApp_Preferences::Color, "Plot2d", "Background" );
// ... -> font color
pref->addPreference( tr( "PREF_FONT_COLOR" ), plot2dGroup, LightApp_Preferences::Color, "Plot2d", "LegendFontColor" );
</message>
<message>
<source>PREF_VIEWER_BACKGROUND</source>
+ <translation>Background</translation>
+ </message>
+ <message>
+ <source>PREF_VIEWER_BACKGROUND_COLOR</source>
<translation>Background color</translation>
</message>
<message>
</message>
<message>
<source>PREF_VIEWER_BACKGROUND</source>
+ <translation>Arrière-plan</translation>
+ </message>
+ <message>
+ <source>PREF_VIEWER_BACKGROUND_COLOR</source>
<translation>Couleur de l'arrière-plan</translation>
</message>
<message>
#include <QLayout>
#include <QApplication>
+class VisEvent : public QEvent
+{
+public:
+ VisEvent( const QMap<int,bool>& visMap ) : QEvent( QEvent::User ), myVisMap( visMap )
+ {}
+ QMap<int,bool> myVisMap;
+};
+
OCCViewer_ViewFrame::OCCViewer_ViewFrame(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel)
: OCCViewer_ViewWindow( theDesktop, theModel ), myPopupRequestedView(0)
{
//**************************************************************************************
OCCViewer_ViewWindow* OCCViewer_ViewFrame::getView( const int i ) const
{
- return ( i < myViews.count() ) ? myViews.at( i ) : 0 ;
+ return ( i >= 0 && i < myViews.count() ) ? myViews.at( i ) : 0 ;
}
//**************************************************************************************
if (myViews.count() <= 1)
return;
- myLayout->setColumnStretch(0 , 0);
+ myLayout->setColumnStretch(0, 0);
myLayout->setColumnStretch(1, 0);
int i = 0;
- OCCViewer_ViewWindow* aView = 0;
+ OCCViewer_ViewWindow* view = 0;
for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
- aView = myViews.at(i);
- if (aView != theView)
- aView->hide();
+ view = myViews.at(i);
+ view->setVisible( view == theView );
+ view->setMaximized( view == theView, false );
}
}
else {
OCCViewer_Viewer* aModel = dynamic_cast<OCCViewer_Viewer*>(myManager->getViewModel());
if (!aModel) return;
- myLayout->setColumnStretch(0 , 10);
+ myLayout->setColumnStretch(0, 10);
myLayout->setColumnStretch(1, 10);
int i = 0;
view->setMaximized(false, false);
view->setDropDownButtons( dropDownButtons() );
connectViewSignals(view);
- view->setBackgroundColor(aModel->backgroundColor(i));
+ view->setBackground(aModel->background(i));
}
myLayout->addWidget( myViews.at(BOTTOM_LEFT), 1, 0 );
myLayout->addWidget( myViews.at(TOP_LEFT), 0, 0 );
for ( i = BOTTOM_RIGHT; i <= TOP_RIGHT; i++) {
view = myViews.at(i);
view->show();
- QApplication::processEvents();
+ view->setMaximized( false, false );
+ ///////////////QApplication::processEvents(); // VSR: hangs up ?
if (view != theView)
view->onViewFitAll();
}
connect( theView, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ),
this, SIGNAL( mouseMoving(SUIT_ViewWindow*, QMouseEvent*) ) );
- // The signal is used to process get/set bacgrounf\d color from popup
+ // The signal is used to process get/set background color from popup
connect( theView, SIGNAL( contextMenuRequested(QContextMenuEvent*) ),
this, SLOT( onContextMenuRequested(QContextMenuEvent*) ) );
this, SIGNAL( contextMenuRequested(QContextMenuEvent*) ) );
}
-void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor)
+// obsolete
+void OCCViewer_ViewFrame::setBackgroundColor( const QColor& theColor )
{
if (myPopupRequestedView)
myPopupRequestedView->setBackgroundColor(theColor);
}
}
}
-
-void OCCViewer_ViewFrame::setBackgroundImage( const QString& theFilename,const Aspect_FillMethod& theFillMethod)
+void OCCViewer_ViewFrame::setBackground( const Qtx::BackgroundData& theBackground )
{
if (myPopupRequestedView)
- myPopupRequestedView->setBackgroundImage(theFilename,theFillMethod);
+ myPopupRequestedView->setBackground(theBackground);
else {
foreach (OCCViewer_ViewWindow* aView, myViews) {
if (aView->isVisible())
- aView->setBackgroundImage(theFilename,theFillMethod);
+ aView->setBackground(theBackground);
}
}
}
aView->onFitAll();
}
}
-
+
+// obsolete
QColor OCCViewer_ViewFrame::backgroundColor() const
{
if (myPopupRequestedView)
return getView(MAIN_VIEW)->backgroundColor();
}
-QString OCCViewer_ViewFrame::backgroundImageFilename() const
+Qtx::BackgroundData OCCViewer_ViewFrame::background() const
{
if (myPopupRequestedView)
- return myPopupRequestedView->backgroundImageFilename();
+ return myPopupRequestedView->background();
foreach (OCCViewer_ViewWindow* aView, myViews) {
if (aView->isVisible())
- return aView->backgroundImageFilename();
+ return aView->background();
}
- return getView(MAIN_VIEW)->backgroundImageFilename();
+ return getView(MAIN_VIEW)->background();
}
QImage OCCViewer_ViewFrame::dumpView()
}
OCCViewer_ViewWindow::setDropDownButtons( on );
}
+
+QString OCCViewer_ViewFrame::getVisualParameters()
+{
+ QStringList params;
+ int maximizedView = 999;
+ for ( int i = BOTTOM_RIGHT; i <= TOP_RIGHT && i < myViews.count(); i++) {
+ if ( getView(i)->isVisible() )
+ maximizedView = ( maximizedView != -1 ) ? ( maximizedView == 999 ? i : -1 ) : ( maximizedView );
+ params << getView(i)->getVisualParameters();
+ }
+ params.prepend( QString::number( maximizedView ) );
+ return params.join( "|" );
+}
+
+void OCCViewer_ViewFrame::setVisualParameters( const QString& parameters )
+{
+ QStringList params = parameters.split( "|" );
+ if ( params.count() > 1 ) {
+ int maximizedView = params[0].toInt();
+ QMap<int,bool> visMap;
+ if ( myViews.count() < params.count()-1 )
+ onMaximizedView( getView(MAIN_VIEW), false ); // secondary views are not created yet, but should be
+ for ( int i = 1; i < params.count(); i++ ) {
+ int idx = i-1;
+ getView( idx )->setVisualParameters( params[i] );
+ //visMap[idx] = maximizedView == -1 || maximizedView == idx;
+ }
+ onMaximizedView( getView( maximizedView ), maximizedView != -1 ); // set proper sib-window maximized
+ //VisEvent ve( visMap );
+ //QApplication::sendEvent( this, &ve );
+ }
+ else {
+ // handle obsolete versions - no parameters for xy, yz, xz views
+ getView(MAIN_VIEW)->setVisualParameters( parameters );
+ }
+}
+
+bool OCCViewer_ViewFrame::event( QEvent* e )
+{
+ if ( e->type() == QEvent::User ) {
+ VisEvent* ve = dynamic_cast<VisEvent*>( e );
+ QMap<int,bool> visMap = ve->myVisMap;
+ for ( int i = 0 ; i < myViews.count(); i++ )
+ myViews[i]->setVisible( visMap.contains( i ) && visMap[i] );
+ }
+}
virtual bool isCuttingPlane() { return getView(MAIN_VIEW)->isCuttingPlane(); }
- virtual QString getVisualParameters() { return getView(MAIN_VIEW)->getVisualParameters(); }
- virtual void setVisualParameters( const QString& parameters ) { getView(MAIN_VIEW)->setVisualParameters(parameters); }
+ virtual QString getVisualParameters();
+ virtual void setVisualParameters( const QString& parameters );
virtual void initSketchers() { getView(MAIN_VIEW)->initSketchers(); }
virtual OCCViewer_ViewSketcher* getSketcher( const int i) { return getView(MAIN_VIEW)->getSketcher(i); }
virtual bool eventFilter(QObject* watched, QEvent* e) { return SUIT_ViewWindow::eventFilter(watched, e); }
- virtual QColor backgroundColor() const;
- virtual void setBackgroundColor( const QColor& );
+ virtual QColor backgroundColor() const; // obsolete
+ virtual void setBackgroundColor( const QColor& ); // obsolete
+
+ virtual Qtx::BackgroundData background() const;
+ virtual void setBackground( const Qtx::BackgroundData& );
- virtual QString backgroundImageFilename() const;
- virtual void setBackgroundImage( const QString& theFilename , const Aspect_FillMethod& theFillMethod);
-
virtual void setDropDownButtons( bool );
+ bool event( QEvent* e );
+
public slots:
virtual void onFrontView() { getView(MAIN_VIEW)->onFrontView(); }
virtual void onViewFitAll();
#include "SUIT_ResourceMgr.h"
#include "QtxActionToolMgr.h"
+#include "QtxBackgroundTool.h"
#include <QPainter>
#include <QApplication>
#include <Visual3d_View.hxx>
+/*!
+ Get data for supported background modes: gradient types, identifiers and supported image formats
+*/
+QString OCCViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+{
+ gradList << tr("GT_HORIZONTALGRADIENT") << tr("GT_VERTICALGRADIENT") <<
+ tr("GT_FIRSTDIAGONALGRADIENT") << tr("GT_SECONDDIAGONALGRADIENT") <<
+ tr("GT_FIRSTCORNERGRADIENT") << tr("GT_SECONDCORNERGRADIENT") <<
+ tr("GT_THIRDCORNERGRADIENT") << tr("GT_FORTHCORNERGRADIENT");
+ idList << HorizontalGradient << VerticalGradient <<
+ Diagonal1Gradient << Diagonal2Gradient <<
+ Corner1Gradient << Corner2Gradient <<
+ Corner3Gradient << Corner4Gradient;
+ return QString(); // temporarily, means support of all image formars!
+}
+
/*!
Constructor
\param DisplayTrihedron - is trihedron displayed
*/
OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
: SUIT_ViewModel(),
- myColors(4, Qt::black),
+ myBackgrounds(4, Qtx::BackgroundData( Qt::black )),
myIsRelative(true),
myTrihedronSize(100)
{
}
/*!
+ [obsolete]
\return background color of viewer
*/
QColor OCCViewer_Viewer::backgroundColor() const
{
- return myColors[0];
+ return backgroundColor(0);
}
/*!
- Sets background color
+ \return background data of viewer
+*/
+Qtx::BackgroundData OCCViewer_Viewer::background() const
+{
+ return background(0);
+}
+
+/*!
+ Sets background color [obsolete]
\param c - new background color
*/
void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
setBackgroundColor( 0, c );
}
+/*!
+ Sets background data
+ \param d - new background data
+*/
+void OCCViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
+{
+ setBackground( 0, theBackground );
+}
+
/*!
Start initialization of view window
\param view - view window to be initialized
OCCViewer_ViewPort3d* vp3d = view->getViewPort();
if ( vp3d )
{
- vp3d->setBackgroundColor( myColors[0] );
vp3d->getView()->SetSurfaceDetail(V3d_TEX_ALL);
}
}
*/
SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
{
- //OCCViewer_ViewWindow* view = new OCCViewer_ViewWindow(theDesktop, this);
+ // create view frame
OCCViewer_ViewFrame* view = new OCCViewer_ViewFrame(theDesktop, this);
- initView( view->getView(OCCViewer_ViewFrame::MAIN_VIEW) );
+ // get main view window (created by view frame)
+ OCCViewer_ViewWindow* vw = view->getView(OCCViewer_ViewFrame::MAIN_VIEW);
+ // initialize main view window
+ initView( vw );
+ // set default background for view window
+ vw->setBackground( background(0) ); // 0 means MAIN_VIEW (other views are not yet created here)
return view;
}
void OCCViewer_Viewer::contextMenuPopup(QMenu* thePopup)
{
thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
- thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
- QMenu * changeImageMenu=thePopup->addMenu( tr( "MEN_CHANGE_IMAGE" ));
- changeImageMenu->addAction( tr( "CENTERED") , this, SLOT( onChangeBgImageCentered() ) );
- changeImageMenu->addAction( tr( "TILED") , this, SLOT( onChangeBgImageTiled() ) );
- changeImageMenu->addAction( tr( "STRETCHED") , this, SLOT( onChangeBgImageStretched() ) );
+ thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) );
thePopup->addSeparator();
/*!
SLOT: called if background color is to be changed changed, passes new color to view port
*/
-void OCCViewer_Viewer::onChangeBgColor()
+void OCCViewer_Viewer::onChangeBackground()
{
OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
if ( !aView )
return;
-
- QColor selColor = QColorDialog::getColor( aView->backgroundColor(), aView );
- if ( selColor.isValid() )
- aView->setBackgroundColor(selColor);
-}
-/*!
- SLOT: called if background image is to be changed changed, passes new image to view port in centered mode
-*/
-void OCCViewer_Viewer::onChangeBgImageCentered()
-{
- OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
- if ( !aView )
- return;
-
- QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES"));
- if ( ! selFile.isEmpty() ){
- aView->setBackgroundImage(selFile,Aspect_FM_CENTERED);
- }
-}
+ // get supported gradient types
+ QStringList gradList;
+ QIntList idList;
+ QString formats = backgroundData( gradList, idList );
-/*!
- SLOT: called if background image is to be changed changed, passes new image to view port in tiled mode
-*/
-void OCCViewer_Viewer::onChangeBgImageTiled()
-{
- OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
- if ( !aView )
- return;
-
- QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES"));
- if ( ! selFile.isEmpty() )
- aView->setBackgroundImage(selFile,Aspect_FM_TILED);
-}
+ // invoke dialog box
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
+ aView->background(), // initial background
+ true, // enable solid color mode
+ false, // disable texture mode
+ true, // enable gradient mode
+ false, // disable custom gradient mode
+ gradList, // gradient names
+ idList, // gradient identifiers
+ formats ); // image formats
-/*!
- SLOT: called if background image is to be changed changed, passes new image to view port in stretched mode
-*/
-void OCCViewer_Viewer::onChangeBgImageStretched()
-{
- OCCViewer_ViewWindow* aView = dynamic_cast<OCCViewer_ViewWindow*>(myViewManager->getActiveView());
- if ( !aView )
- return;
-
- QString selFile = QFileDialog::getOpenFileName(aView,tr( "SELECT_IMAGE"),aView->backgroundImageFilename(), tr("OCC_IMAGE_FILES"));
- if ( ! selFile.isEmpty() )
- aView->setBackgroundImage(selFile,Aspect_FM_STRETCH);
-// aView->setBackgroundImage(selFile,Aspect_FM_STRETCH_NODEF);
+ // set chosen background data to the viewer
+ if ( bgData.isValid() )
+ aView->setBackground( bgData );
}
+
/*!
Updates OCC 3D viewer
*/
{
return new OCCViewer_ViewWindow( 0, this);
}
-
-QColor OCCViewer_Viewer::backgroundColor(int theViewId) const
+
+// obsolete
+QColor OCCViewer_Viewer::backgroundColor( int theViewId ) const
+{
+ return background( theViewId ).color();
+}
+
+Qtx::BackgroundData OCCViewer_Viewer::background( int theViewId ) const
+{
+ return ( theViewId >= 0 && theViewId < myBackgrounds.count() ) ? myBackgrounds[theViewId] : Qtx::BackgroundData();
+}
+
+// obsolete
+void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor )
{
- return ( theViewId >= 0 && theViewId < myColors.count() ) ? myColors[theViewId] : Qt::black;
+ if ( theColor.isValid() ) {
+ Qtx::BackgroundData bg = background( theViewId );
+ bg.setColor( theColor );
+ setBackground( theViewId, bg );
+ }
}
-void OCCViewer_Viewer::setBackgroundColor( int theViewId, const QColor& theColor)
+void OCCViewer_Viewer::setBackground( int theViewId, const Qtx::BackgroundData& theBackground )
{
- if ( theColor.isValid() && theViewId >= 0 && theViewId < myColors.count() )
- myColors[theViewId] = theColor;
+ if ( theBackground.isValid() && theViewId >= 0 && theViewId < myBackgrounds.count() )
+ myBackgrounds[theViewId] = theBackground;
}
#include "OCCViewer.h"
+#include "Qtx.h"
#include "SUIT_ViewModel.h"
#include <V3d_View.hxx>
Q_OBJECT
public:
- static QString Type() { return "OCCViewer"; }
+ /*! supported gradient types */
+ enum {
+ HorizontalGradient, VerticalGradient,
+ Diagonal1Gradient, Diagonal2Gradient,
+ Corner1Gradient, Corner2Gradient,
+ Corner3Gradient, Corner4Gradient,
+ LastGradient = Corner4Gradient
+ };
+
+ static QString Type() { return "OCCViewer"; }
+ static QString backgroundData( QStringList&, QIntList& );
OCCViewer_Viewer( bool DisplayTrihedron = true);
virtual ~OCCViewer_Viewer();
void performSelectionChanged();
// emit signal selectionChanged
- QColor backgroundColor() const;
- void setBackgroundColor( const QColor& );
+ QColor backgroundColor() const; // obsolete
+ void setBackgroundColor( const QColor& ); // obsolete
+ Qtx::BackgroundData background() const;
+ void setBackground( const Qtx::BackgroundData& );
- QColor backgroundColor(int theViewId) const;
- void setBackgroundColor( int theViewId, const QColor& );
+ QColor backgroundColor(int theViewId) const; // obsolete
+ void setBackgroundColor( int theViewId, const QColor& ); // obsolete
+ Qtx::BackgroundData background(int theViewId) const;
+ void setBackground( int theViewId, const Qtx::BackgroundData& );
//! returns true if 3d Trihedron in viewer was created
bool trihedronActivated() const { return !myTrihedron.IsNull(); }
void selectionChanged();
void deselection();
-protected:
-
protected slots:
virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
void onDumpView();
- void onChangeBgColor();
- void onChangeBgImageCentered();
- void onChangeBgImageTiled();
- void onChangeBgImageStretched();
+ void onChangeBackground();
protected:
Handle(V3d_Viewer) myV3dViewer;
double myTrihedronSize;
- QVector<QColor> myColors;
+ QVector<Qtx::BackgroundData> myBackgrounds;
};
#ifdef WIN32
/*!
Sets the background color with color selection dialog. [ virtual protected slot ]
*/
-void OCCViewer_ViewPort::onChangeBgColor()
+void OCCViewer_ViewPort::onChangeBackground()
{
QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
if ( selColor.isValid() )
virtual bool synchronize( OCCViewer_ViewPort* );
protected slots:
- virtual void onChangeBgColor();
+ virtual void onChangeBackground();
signals:
void vpKeyEvent( QKeyEvent* );
bool myEnableTransform;
bool myPaintersRedrawing; /* set to draw externally */
QList<QtxAction*> myPopupActions;
-
+
private:
static int nCounter; /* objects counter */
};
#include <SUIT_ViewModel.h>
#include <QColor>
+#include <QFileInfo>
#include <QString>
#include <QRect>
#include <QPaintEvent>
myDegenerated( true ),
myAnimate( false ),
myBusy( true ),
- myIsAdvancedZoomingEnabled( false ),
- myBackgroundImageFilename( "" )
+ myIsAdvancedZoomingEnabled( false )
{
// VSR: 01/07/2010 commented to avoid SIGSEGV at SALOME exit
//selectVisualId();
}
if ( myDegenerated )
activeView()->SetDegenerateModeOn();
+ setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
}
/*!
}
/*!
- Returns the background color [ virtual public ]
+ Returns the background color [ virtual public ] [ obsolete ]
*/
QColor OCCViewer_ViewPort3d::backgroundColor() const
{
- if ( !activeView().IsNull() ) {
- Standard_Real aRed, aGreen, aBlue;
- activeView()->BackgroundColor( Quantity_TOC_RGB, aRed, aGreen, aBlue );
- int red = (int) (aRed * 255);
- int green = (int) (aGreen * 255);
- int blue = (int) (aBlue * 255);
- return QColor( red, green, blue );
- }
- return OCCViewer_ViewPort::backgroundColor();
+ return background().color();
}
/*!
- Sets the background color [ virtual public ]
+ Sets the background color [ virtual public ] [ obsolete ]
*/
void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color )
{
- if ( !activeView().IsNull() ) {
- activeView()->SetBackgroundColor( Quantity_TOC_RGB, color.red()/255.,
- color.green()/255., color.blue()/255.);
- activeView()->Update();
- emit vpChangeBGColor( color );
- }
+ Qtx::BackgroundData bg = background();
+ bg.setColor( color );
+ setBackground( bg );
}
/*!
- Returns the background image fileName[ virtual public ]
+ Returns the background data
*/
-QString OCCViewer_ViewPort3d::backgroundImageFilename() const
+Qtx::BackgroundData OCCViewer_ViewPort3d::background() const
{
- return myBackgroundImageFilename;
+ return myBackground;
}
/*!
- Sets the background image [ virtual public ]
+ Sets the background data
*/
-void OCCViewer_ViewPort3d::setBackgroundImage( const QString& fileName,const Aspect_FillMethod& theFillMethod)
-{
- myBackgroundImageFilename=fileName;
- //TEST
-// if ( !activeView().IsNull() ) {
-// activeView()->SetBackgroundImage( (Standard_CString)fileName.toLatin1().constData(),theFillMethod,true);
-// }
+void OCCViewer_ViewPort3d::setBackground( const Qtx::BackgroundData& bgData )
+{
+ if ( bgData.isValid() ) {
+ myBackground = bgData;
+ updateBackground();
+ emit vpChangeBackground( myBackground );
+ }
+}
+
+void OCCViewer_ViewPort3d::updateBackground()
+{
+ if ( activeView().IsNull() ) return;
+ if ( !myBackground.isValid() ) return;
+
+ // VSR: Important note on below code.
+ // In OCCT (at least 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).
+ // Well, all this is strange but we have to live with it.
+ switch ( myBackground.mode() ) {
+ case Qtx::ImageBackground:
+ {
+ // VSR: Do not use this code until the bug is fixed - currently it is not possible to
+ // clear the background texture image as soon as it is once set to the viewer.
+ QString fileName;
+ int textureMode = myBackground.texture( fileName );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // set texture image: file name and fill mode
+ switch ( textureMode ) {
+ case Qtx::CenterTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
+ break;
+ case Qtx::TileTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
+ break;
+ case Qtx::StretchTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ case Qtx::ColorBackground:
+ {
+ QColor c = myBackground.color();
+ if ( c.isValid() ) {
+ // Unset texture should be done here
+ // ...
+ // cancel gradient background (in OCC the only way is to set it to NONE type)
+ Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
+ activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE );
+ // then change background color
+ activeView()->SetBackgroundColor( qCol );
+ // update viewer
+ activeView()->Update();
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = myBackground.gradient( c1, c2 );
+ if ( c1.isValid() && type >= OCCViewer_Viewer::HorizontalGradient && type <= OCCViewer_Viewer::LastGradient ) {
+ // Unset texture should be done here
+ // ...
+ // Get colors and set-up gradiented background
+ if ( !c2.isValid() ) c2 = c1;
+ Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB );
+ Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB );
+ switch ( type ) {
+ case OCCViewer_Viewer::HorizontalGradient:
+ // in OCCT, 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 );
+ break;
+ case OCCViewer_Viewer::VerticalGradient:
+ // in OCCT, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
+ break;
+ case OCCViewer_Viewer::Diagonal1Gradient:
+ // in OCCT, 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 );
+ break;
+ case OCCViewer_Viewer::Diagonal2Gradient:
+ // in OCCT, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
+ break;
+ case OCCViewer_Viewer::Corner1Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
+ break;
+ case OCCViewer_Viewer::Corner2Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True );
+ break;
+ case OCCViewer_Viewer::Corner3Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True );
+ break;
+ case OCCViewer_Viewer::Corner4Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True );
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ break;
+ }
+ default:
+ break;
+ }
}
/*!
void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
const Handle(Aspect_Window)& window)
{
- if (!view.IsNull())
+ if (!view.IsNull()) {
view->SetWindow( window );
+ updateBackground();
+ }
}
/*!
#define OCCVIEWER_VIEWPORT3D_H
#include "OCCViewer_ViewPort.h"
+#include "Qtx.h"
#include <V3d_View.hxx>
void setAnimationMode(bool theDegenerated);
- virtual void setBackgroundColor( const QColor& color);
- virtual QColor backgroundColor() const;
+ virtual void setBackgroundColor( const QColor& color); // obsolete
+ virtual QColor backgroundColor() const; // obsolete
+ void setBackground( const Qtx::BackgroundData& color);
+ Qtx::BackgroundData background() const;
- virtual QString backgroundImageFilename() const;
- virtual void setBackgroundImage( const QString& fileName , const Aspect_FillMethod& theFillMethod);
-
virtual int getBgImgHeight(){return myBgImgHeight; };
virtual int getBgImgWidth() {return myBgImgWidth; };
void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
+signals:
+ void vpChangeBackground( const Qtx::BackgroundData& );
+
public slots:
virtual bool synchronize( OCCViewer_ViewPort* );
bool mapView( const Handle(V3d_View)& );
bool setWindow( const Handle(V3d_View)& );
bool mapped( const Handle(V3d_View)& ) const;
-
+ void updateBackground();
+
private:
Handle(V3d_View) myOrthoView;
Handle(V3d_View) myPerspView;
bool myBusy;
double myScale;
bool myIsAdvancedZoomingEnabled;
- QString myBackgroundImageFilename;
+ Qtx::BackgroundData myBackground;
int myBgImgHeight;
int myBgImgWidth;
};
void OCCViewer_ViewWindow::initLayout()
{
myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
- myViewPort->setBackgroundColor(Qt::black);
myViewPort->installEventFilter(this);
setCentralWidget(myViewPort);
myOperation = NOTHING;
data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
#endif
+ QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
+ data << QString( "background=%1" ).arg( bg );
return data.join("*");
}
viewAspect params;
QStringList data = parameters.split( '*' );
+ Qtx::BackgroundData bgData;
if ( parameters.contains( '=' ) ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
{
foreach( QString param, data ) {
else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
+ else if ( paramName == "background" ) {
+ QString bg = paramValue.replace( "$", "=" );
+ bgData = Qtx::stringToBackground( bg );
+ }
}
}
else // old format - "1.000e+00*0.000e+00..."
params.size = data.count() > idx ? data[idx++].toDouble() : 100.0;
}
performRestoring( params );
+ setBackground( bgData );
}
/*!
{
my2dMode = theType;
}
-
+
+// obsolete
QColor OCCViewer_ViewWindow::backgroundColor() const
{
return myViewPort ? myViewPort->backgroundColor() : Qt::black;
}
-void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor)
+// obsolete
+void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
{
if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
}
-QString OCCViewer_ViewWindow::backgroundImageFilename() const
+Qtx::BackgroundData OCCViewer_ViewWindow::background() const
{
- return myViewPort ? myViewPort->backgroundImageFilename() : "";
+ return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
}
-void OCCViewer_ViewWindow::setBackgroundImage( const QString& theFileName,const Aspect_FillMethod& theFillMethod)
+void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
{
- if ( myViewPort )
- myViewPort->setBackgroundImage( theFileName ,theFillMethod);
+ if ( myViewPort ) myViewPort->setBackground( theBackground );
}
/*!
#define OCCVIEWER_VIEWWINDOW_H
#include "OCCViewer.h"
+#include "Qtx.h"
#include "SUIT_ViewWindow.h"
#include <gp_Pnt.hxx>
#include <V3d_Plane.hxx>
void setMaximized( bool, bool = true );
bool isMaximized() const;
- virtual QColor backgroundColor() const;
- virtual void setBackgroundColor( const QColor& );
+ virtual QColor backgroundColor() const; // obsolete
+ virtual void setBackgroundColor( const QColor& ); // obsolete
+
+ virtual Qtx::BackgroundData background() const;
+ virtual void setBackground( const Qtx::BackgroundData& );
- virtual QString backgroundImageFilename() const;
- virtual void setBackgroundImage( const QString& ,const Aspect_FillMethod& theFillMethod);
-
virtual const viewAspectList& getViewAspects();
virtual void appendViewAspect( const viewAspect& );
virtual void updateViewAspects( const viewAspectList& );
<source>STRETCHED</source>
<translation>in stretched mode</translation>
</message>
+ <message>
+ <source>GT_HORIZONTALGRADIENT</source>
+ <translation>Horizontal gradient</translation>
+ </message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation>Vertical gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTDIAGONALGRADIENT</source>
+ <translation>First diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDDIAGONALGRADIENT</source>
+ <translation>Second diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTCORNERGRADIENT</source>
+ <translation>First corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDCORNERGRADIENT</source>
+ <translation>Second corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_THIRDCORNERGRADIENT</source>
+ <translation>Third corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_FORTHCORNERGRADIENT</source>
+ <translation>Fourth corner gradient</translation>
+ </message>
</context>
<context>
<name>OCCViewer_AxialScaleDlg</name>
<source>STRETCHED</source>
<translation>en mode étiré</translation>
</message>
+ <message>
+ <source>GT_HORIZONTALGRADIENT</source>
+ <translation type="unfinished">Horizontal gradient</translation>
+ </message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation type="unfinished">Vertical gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTDIAGONALGRADIENT</source>
+ <translation type="unfinished">First diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDDIAGONALGRADIENT</source>
+ <translation type="unfinished">Second diagonal gradient</translation>
+ </message>
+ <message>
+ <source>GT_FIRSTCORNERGRADIENT</source>
+ <translation type="unfinished">First corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_SECONDCORNERGRADIENT</source>
+ <translation type="unfinished">Second corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_THIRDCORNERGRADIENT</source>
+ <translation type="unfinished">Third corner gradient</translation>
+ </message>
+ <message>
+ <source>GT_FORTHCORNERGRADIENT</source>
+ <translation type="unfinished">Fourth corner gradient</translation>
+ </message>
</context>
<context>
<name>OCCViewer_AxialScaleDlg</name>
#include "SALOME_Actor.h"
-#include <QtxActionToolMgr.h>
+#include "QtxActionToolMgr.h"
+#include "QtxBackgroundTool.h"
// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
mySpaceBtn[0] = 1;
mySpaceBtn[1] = 2;
mySpaceBtn[2] = 9;
+ myDefaultBackground = Qtx::BackgroundData( Qt::black );
}
/*!
{
}
-/*!
- \return background color
-*/
+/*! Get data for supported background modes: gradient types, identifiers and supported image formats */
+QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+{
+ gradList << tr( "GT_VERTICALGRADIENT" );
+ idList << VerticalGradient;
+ return QString(); // temporarily, means support of all image formats!
+}
+
+//! Get background color of the viewer [obsolete]
QColor SVTK_Viewer::backgroundColor() const
{
- return myBgColor;
+ return background().color();
+}
+
+//! Set background color to the viewer [obsolete]
+void SVTK_Viewer::setBackgroundColor( const QColor& c )
+{
+ Qtx::BackgroundData bg = background();
+ bg.setColor( c );
+ setBackground( bg );
}
/*!
- Changes background color
- \param theColor - new background color
+ \return background data
*/
-void SVTK_Viewer::setBackgroundColor( const QColor& theColor )
+Qtx::BackgroundData SVTK_Viewer::background() const
{
- if ( !theColor.isValid() )
- return;
+ return myDefaultBackground;
+}
+/*!
+ Changes background
+ \param theBackground - new background data
+*/
+void SVTK_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
+{
+ myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black );
QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
- aView->setBackgroundColor(theColor);
+ aView->setBackground(myDefaultBackground);
}
}
- }
-
- myBgColor = theColor;
+ }
}
/*!Create new instance of view window on desktop \a theDesktop.
TViewWindow* aViewWindow = new TViewWindow(theDesktop);
aViewWindow->Initialize(this);
- aViewWindow->setBackgroundColor( backgroundColor() );
+ aViewWindow->setBackground( background() );
aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() );
aViewWindow->SetProjectionMode( projectionMode() );
void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
{
thePopup->addAction( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
- thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
+ thePopup->addAction( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) );
thePopup->addSeparator();
/*!
SLOT: called if background color is to be changed changed, passes new color to view port
*/
-void SVTK_Viewer::onChangeBgColor()
+void SVTK_Viewer::onChangeBackground()
{
- if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
- QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
- setBackgroundColor(aColor);
- }
+ SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
+ if ( !aView )
+ return;
+
+ // get supported gradient types
+ QStringList gradList;
+ QIntList idList;
+ QString formats = backgroundData( gradList, idList );
+
+ // invoke dialog box
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
+ aView->background(), // initial background
+ true, // enable solid color mode
+ false, // disable texture mode
+ true, // enable gradient mode
+ false, // disable custom gradient mode
+ gradList, // gradient names
+ idList, // gradient identifiers
+ formats ); // image formats
+
+ // set chosen background data to the viewer
+ if ( bgData.isValid() )
+ aView->setBackground( bgData );
}
/*!
#include "SVTK.h"
#include "SVTK_ViewModelBase.h"
+#include "Qtx.h"
+
#include <SALOME_Prs.h>
#include <SALOME_InteractiveObject.hxx>
#include <SALOME_ListIO.hxx>
Q_OBJECT;
public:
+ /*! supported gradient types */
+ enum {
+ VerticalGradient,
+ LastGradient = VerticalGradient,
+ };
+
typedef SVTK_ViewWindow TViewWindow;
//! Define string representation of the viewer type
- static QString Type() { return "VTKViewer"; }
+ static QString Type() { return "VTKViewer"; }
+ static QString backgroundData( QStringList&, QIntList& );
SVTK_Viewer();
virtual ~SVTK_Viewer();
//! See #SUIT_ViewModel::getType
virtual QString getType() const { return Type(); }
- //! Get background color of the viewer
+ //! Get background color of the viewer [obsolete]
QColor backgroundColor() const;
- //! Set background color to the viewer
+ //! Set background color to the viewer [obsolete]
void setBackgroundColor( const QColor& );
+ //! Get background color of the viewer
+ Qtx::BackgroundData background() const;
+
+ //! Set background color to the viewer
+ void setBackground( const Qtx::BackgroundData& );
+
//! Get size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
vtkFloatingPointType trihedronSize() const;
void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
void onDumpView();
- void onChangeBgColor();
+ void onChangeBackground();
void onActorAdded(VTKViewer_Actor*);
void onActorRemoved(VTKViewer_Actor*);
private:
void updateToolBars();
-
- QColor myBgColor;
+ Qtx::BackgroundData myDefaultBackground;
vtkFloatingPointType myTrihedronSize;
- bool myTrihedronRelative;
- bool myIsStaticTrihedronVisible;
- bool mySelectionEnabled;
- bool myMultiSelectionEnabled;
- int myIncrementSpeed;
- int myIncrementMode;
- int myProjMode;
- int myStyle;
- int myZoomingStyle;
- bool myDynamicPreSelection;
- int mySpaceBtn[3];
+ bool myTrihedronRelative;
+ bool myIsStaticTrihedronVisible;
+ bool mySelectionEnabled;
+ bool myMultiSelectionEnabled;
+ int myIncrementSpeed;
+ int myIncrementMode;
+ int myProjMode;
+ int myStyle;
+ int myZoomingStyle;
+ bool myDynamicPreSelection;
+ int mySpaceBtn[3];
};
#endif
#include "SVTK_CubeAxesDlg.h"
#include "SVTK_SetRotationPointDlg.h"
#include "SVTK_ViewParameterDlg.h"
+#include "SVTK_ViewModel.h"
#include "SALOME_Actor.h"
#include <QMenu>
#include <QToolBar>
#include <QEvent>
+#include <QFileInfo>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QXmlStreamAttributes>
#include <vtkInteractorStyle.h>
#include <vtkProperty.h>
#include <vtkCallbackCommand.h>
+#include <vtkJPEGReader.h>
+#include <vtkBMPReader.h>
+#include <vtkTIFFReader.h>
+#include <vtkPNGReader.h>
+#include <vtkMetaImageReader.h>
+#include <vtkImageMapToColors.h>
+#include <vtkTexture.h>
#include "QtxAction.h"
#include "SVTK_Event.h"
#include "SVTK_Renderer.h"
#include "SVTK_ViewWindow.h"
-#include "SVTK_ViewModelBase.h"
#include "SVTK_InteractorStyle.h"
#include "SVTK_RenderWindowInteractor.h"
#include "SVTK_GenericRenderWindowInteractor.h"
myInteractor->getRenderWindow()->Render();
+ setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
onResetView();
}
}
/*!
- Sets background color
+ Sets background color [obsolete]
\param color - new background color
*/
-void SVTK_ViewWindow::setBackgroundColor( const QColor& theColor )
+void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
{
- getRenderer()->SetBackground(theColor.red()/255.0,
- theColor.green()/255.0,
- theColor.blue()/255.0);
+ Qtx::BackgroundData bg = background();
+ bg.setColor( c );
+ setBackground( bg );
}
/*!
- \return background color of viewer
+ \return background color of viewer [obsolete]
*/
QColor SVTK_ViewWindow::backgroundColor() const
{
- vtkFloatingPointType aBackgroundColor[3];
- getRenderer()->GetBackground(aBackgroundColor);
- return QColor(int(aBackgroundColor[0]*255),
- int(aBackgroundColor[1]*255),
- int(aBackgroundColor[2]*255));
+ return background().color();
+}
+
+/*!
+ Sets background data
+ \param bgData - new background data
+*/
+void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
+{
+ bool ok = bgData.isValid();
+
+ switch ( bgData.mode() ) {
+ case Qtx::ImageBackground:
+ {
+ QString fileName;
+ int textureMode = bgData.texture( fileName );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // read texture from file
+ QString extension = fi.suffix().toLower();
+ vtkImageReader2* aReader = 0;
+ if ( extension == "jpg" || extension == "jpeg" )
+ aReader = vtkJPEGReader::New();
+ else if ( extension == "bmp" )
+ aReader = vtkBMPReader::New();
+ else if ( extension == "tif" || extension == "tiff" )
+ aReader = vtkTIFFReader::New();
+ else if ( extension == "png" )
+ aReader = vtkPNGReader::New();
+ else if ( extension == "mhd" || extension == "mha" )
+ aReader = vtkMetaImageReader::New();
+ if ( aReader ) {
+ // create texture
+ aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
+ aReader->Update();
+
+ vtkTexture* aTexture = vtkTexture::New();
+ vtkImageMapToColors* aMap = 0;
+ vtkAlgorithmOutput* anOutput;
+ /*
+ // special processing for BMP reader
+ vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
+ if ( aBMPReader ) {
+ // Special processing for BMP file
+ aBMPReader->SetAllow8BitBMP(1);
+
+ aMap = vtkImageMapToColors::New();
+ aMap->SetInputConnection( aBMPReader->GetOutputPort() );
+ aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
+ aMap->SetOutputFormatToRGB();
+
+ anOutput = aMap->GetOutputPort();
+ }
+ else {
+ }
+ */
+ anOutput = aReader->GetOutputPort( 0 );
+ aTexture->SetInputConnection( anOutput );
+ // set texture mode
+ // VSR: Currently, VTK only supports Stretch mode, so below code will give
+ // the same results for all modes
+ switch ( textureMode ) {
+ case Qtx::TileTexture:
+ aTexture->RepeatOn();
+ aTexture->EdgeClampOff();
+ aTexture->InterpolateOff();
+ break;
+ case Qtx::StretchTexture:
+ aTexture->RepeatOff();
+ aTexture->EdgeClampOff();
+ aTexture->InterpolateOn();
+ break;
+ case Qtx::CenterTexture:
+ default:
+ aTexture->RepeatOff();
+ aTexture->EdgeClampOn();
+ aTexture->InterpolateOff();
+ break;
+ }
+ // show textured background
+ getRenderer()->SetTexturedBackground( true );
+ getRenderer()->SetBackgroundTexture( aTexture );
+
+ // clean-up resources
+ if ( aMap )
+ aMap->Delete();
+ aReader->Delete();
+ aTexture->Delete();
+ ok = true;
+ }
+ }
+ break;
+ }
+ case Qtx::ColorBackground:
+ {
+ QColor c = bgData.color();
+ if ( c.isValid() ) {
+ // show solid-colored background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ getRenderer()->SetBackground( c.red()/255.0,
+ c.green()/255.0,
+ c.blue()/255.0 ); // set background color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = bgData.gradient( c1, c2 );
+ // VSR: Currently, only vertical gradient is supported by VTK.
+ // In future, switch operator might be added here to process different supported gradient types.
+ if ( c1.isValid() && type == SVTK_Viewer::VerticalGradient ) {
+ if ( !c2.isValid() ) c2 = c1;
+ // show two-color gradient background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( true ); // switch to gradient mode
+ // VSR: In VTK, gradient is colored from bottom to top:
+ // - top color is set via SetBackground2()
+ // - bottom color is set via SetBackground()
+ // So, we reverse colors, to draw gradient from top to bottom instead.
+ getRenderer()->SetBackground( c2.red()/255.0,
+ c2.green()/255.0,
+ c2.blue()/255.0 ); // set first gradient color
+ getRenderer()->SetBackground2( c1.red()/255.0,
+ c1.green()/255.0,
+ c1.blue()/255.0 ); // set second gradient color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ // .........
+ break;
+ }
+ default:
+ break;
+ }
+ if ( ok )
+ myBackground = bgData;
+}
+
+/*!
+ \return background data of viewer
+*/
+Qtx::BackgroundData SVTK_ViewWindow::background() const
+{
+ return myBackground;
}
aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
aWriter.writeEndElement();
+ aWriter.writeStartElement("Background");
+ aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
+ aWriter.writeEndElement();
+
aWriter.writeEndElement();
aWriter.writeEndDocument();
pos[1] = aAttr.value("Y").toString().toDouble();
pos[2] = aAttr.value("Z").toString().toDouble();
//printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
- } else if (aReader.name() == "FocalPoint") {
+ }
+ else if (aReader.name() == "FocalPoint") {
focalPnt[0] = aAttr.value("X").toString().toDouble();
focalPnt[1] = aAttr.value("Y").toString().toDouble();
focalPnt[2] = aAttr.value("Z").toString().toDouble();
//printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
- } else if (aReader.name() == "ViewUp") {
+ }
+ else if (aReader.name() == "ViewUp") {
viewUp[0] = aAttr.value("X").toString().toDouble();
viewUp[1] = aAttr.value("Y").toString().toDouble();
viewUp[2] = aAttr.value("Z").toString().toDouble();
//printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
- } else if (aReader.name() == "ViewScale") {
+ }
+ else if (aReader.name() == "ViewScale") {
parScale = aAttr.value("Parallel").toString().toDouble();
scale[0] = aAttr.value("X").toString().toDouble();
scale[1] = aAttr.value("Y").toString().toDouble();
SetTrihedronSize(aAttr.value("Size").toString().toDouble());
}
}
- }
+ else if (aReader.name() == "Background") {
+ if ( !baseParamsOnly ) {
+ setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
+ }
+ }
+ }
}
if (!aReader.hasError()) {
vtkCamera* camera = getRenderer()->GetActiveCamera();
#include "SVTK.h"
#include "SVTK_Selection.h"
+#include "Qtx.h"
#include "SUIT_ViewWindow.h"
#include "SALOME_InteractiveObject.hxx"
class VTKViewer_Trihedron;
class SVTK_ViewModelBase;
-//class SVTK_MainWindow;
class SVTK_Selector;
class SVTK_View;
//! Get #SVTK_View
SVTK_View* getView();
- //! Get #SVTK_MainWindow
- //SVTK_MainWindow* getMainWindow();
-
- //! Redirect the request to #SVTK_MainWindow::getRenderWindow
+ //! Get render window
vtkRenderWindow* getRenderWindow();
- //! Redirect the request to #SVTK_MainWindow::getInteractor
+ //! Get interactor
vtkRenderWindowInteractor* getInteractor() const;
- //! Redirect the request to #SVTK_MainWindow::getInteractor
+ //! Get SVTK interactor
SVTK_RenderWindowInteractor* GetInteractor() const;
+ //! Get current interactor style
vtkInteractorStyle* GetInteractorStyle() const;
- //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle
+ //! Add interactor style to the stack of styles
void PushInteractorStyle(vtkInteractorStyle* theStyle);
- //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle
+ //! Remove last interactor style from the stack of styles
void PopInteractorStyle();
- //! Redirect the request to #SVTK_MainWindow::getRenderer
+ //! Get renderer
vtkRenderer* getRenderer() const;
-
+
+ //! Get SVTK renderer
SVTK_Renderer* GetRenderer() const;
- //! Redirect the request to #SVTK_MainWindow::GetSelector
+ //! Get selector
SVTK_Selector* GetSelector() const;
- //! Redirect the request to #SVTK_Selector::SelectionMode
+ //! Set selection mode
Selection_Mode SelectionMode() const;
//! Change selection mode
virtual void SetSelectionMode(Selection_Mode theMode);
- //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor
+ //! Set background color [obsolete]
virtual void setBackgroundColor( const QColor& );
- //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor
+ //! Get background color [obsolete]
QColor backgroundColor() const;
- //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+ //! Set background
+ virtual void setBackground( const Qtx::BackgroundData& );
+
+ //! Get background
+ Qtx::BackgroundData background() const;
+
+ //! Return \c true if "display trihedron" flag is set
bool isTrihedronDisplayed();
- //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+ //! Return \c true if "show graduated axes" flag is set
bool isCubeAxesDisplayed();
/* interactive object management */
//! Redirect the request to #SVTK_Renderer::SetTrihedronSize
virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true );
- //! Redirect the request to #SVTK_MainWindow::SetIncrementalSpeed
+ //! Set incremental speed
virtual void SetIncrementalSpeed( const int, const int = 0 );
- //! Redirect the request to #SVTK_MainWindow::SetProjectionMode
+ //! Set current projection mode
virtual void SetProjectionMode( const int );
- //! Redirect the request to #SVTK_MainWindow::SetInteractionStyle
+ //! Set interactive style
virtual void SetInteractionStyle( const int );
- //! Redirect the request to #SVTK_MainWindow::SetZoomingStyle
+ //! Set zooming style
virtual void SetZoomingStyle( const int );
+ //! Set dynamic preselection on/off
virtual void SetDynamicPreSelection( bool );
- //! Redirect the request to #SVTK_MainWindow::SetSpacemouseButtons
+ //! Customize space mouse buttons
virtual void SetSpacemouseButtons( const int, const int, const int );
- //! Redirect the request to #SVTK_Renderer::SetSelectionProp
+ //! Set selection properties
virtual void SetSelectionProp(const double& theRed = 1,
const double& theGreen = 1,
const double& theBlue = 0,
StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
SVTK_View* myView;
- //SVTK_MainWindow* myMainWindow;
SVTK_ViewModelBase* myModel;
SVTK_RenderWindowInteractor* myInteractor;
int myRecordingToolBar;
vtkPVAxesWidget* myAxesWidget;
+ Qtx::BackgroundData myBackground;
private slots:
void onSynchronizeView(bool);
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Change background...</translation>
</message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation>Vertical gradient</translation>
+ </message>
</context>
</TS>
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Changer l'arrière-plan...</translation>
</message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation type="unfinished">Vertical gradient</translation>
+ </message>
</context>
</TS>
#include "VTKViewer_ViewManager.h"
#include "VTKViewer_RenderWindowInteractor.h"
+#include "QtxBackgroundTool.h"
#include "SUIT_ViewWindow.h"
#include "SUIT_Desktop.h"
#include "SUIT_Session.h"
/*!Constructor.Sets background color to black.*/
VTKViewer_Viewer::VTKViewer_Viewer()
: SUIT_ViewModel(),
-myBgColor( Qt::black )
+ myDefaultBackground( Qtx::BackgroundData( Qt::black ) )
{
}
{
}
-/*!Gets background color.*/
+/*! Get data for supported background modes: gradient types, identifiers and supported image formats */
+QString VTKViewer_Viewer::backgroundData( QStringList& gradList, QIntList& idList )
+{
+ gradList << tr( "GT_VERTICALGRADIENT" );
+ idList << VerticalGradient;
+ return QString(); // temporarily, means support of all image formats!
+}
+
+/*!Gets background color [obsolete]*/
QColor VTKViewer_Viewer::backgroundColor() const
{
- return myBgColor;
+ return background().color();
}
-/*!Sets background color.*/
+/*!Sets background color [obsolete]*/
void VTKViewer_Viewer::setBackgroundColor( const QColor& c )
{
- if ( c.isValid() )
- myBgColor = c;
+ Qtx::BackgroundData bg = background();
+ bg.setColor( c );
+ setBackground( bg );
+}
+
+/*!Gets default background data.*/
+Qtx::BackgroundData VTKViewer_Viewer::background() const
+{
+ return myDefaultBackground;
+}
+
+/*!Sets default background data.*/
+void VTKViewer_Viewer::setBackground( const Qtx::BackgroundData& theBackground )
+{
+ myDefaultBackground = theBackground.isValid() ? theBackground : Qtx::BackgroundData( Qt::black );
}
/*!Create new instance of VTKViewer_ViewWindow, sets background color and return pointer to it.*/
SUIT_ViewWindow* VTKViewer_Viewer::createView( SUIT_Desktop* theDesktop )
{
VTKViewer_ViewWindow* vw = new VTKViewer_ViewWindow( theDesktop, this );
- vw->setBackgroundColor( myBgColor );
+ vw->setBackground( myDefaultBackground );
return vw;
}
void VTKViewer_Viewer::contextMenuPopup(QMenu* thePopup)
{
thePopup->addAction( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
- thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
+ thePopup->addAction( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBackground() ) );
thePopup->addSeparator();
}
/*!On change back ground color event.*/
-void VTKViewer_Viewer::onChangeBgColor()
+void VTKViewer_Viewer::onChangeBackground()
{
VTKViewer_ViewWindow* aView = (VTKViewer_ViewWindow*)(myViewManager->getActiveView());
if ( !aView )
return;
- QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
- if ( aColor.isValid() )
- aView->setBackgroundColor(aColor);
+ // get supported gradient types
+ QStringList gradList;
+ QIntList idList;
+ QString formats = backgroundData( gradList, idList );
+
+ // invoke dialog box
+ Qtx::BackgroundData bgData = QtxBackgroundDialog::getBackground( aView, // parent for dialog box
+ aView->background(), // initial background
+ true, // enable solid color mode
+ false, // disable texture mode
+ true, // enable gradient mode
+ false, // disable custom gradient mode
+ gradList, // gradient names
+ idList, // gradient identifiers
+ formats ); // image formats
+
+ // set chosen background data to the viewer
+ if ( bgData.isValid() )
+ aView->setBackground( bgData );
}
/*!On show tool bar event.*/
#define VTKVIEWER_VIEWMODEL_H
#include "VTKViewer.h"
+#include "Qtx.h"
#include "SUIT_ViewModel.h"
#include <QColor>
Q_OBJECT
public:
+ /*! supported gradient types */
+ enum {
+ VerticalGradient,
+ LastGradient = VerticalGradient,
+ };
+
/*!Initialize type of viewer.*/
- static QString Type() { return "VTKViewer"; }
+ static QString Type() { return "VTKViewer"; }
+ static QString backgroundData( QStringList&, QIntList& );
VTKViewer_Viewer();
virtual ~VTKViewer_Viewer();
virtual QString getType() const { return Type(); }
public:
- void enableSelection(bool isEnabled);
+ void enableSelection(bool isEnabled);
/*!Checks: is selection enabled*/
- bool isSelectionEnabled() const { return mySelectionEnabled; }
+ bool isSelectionEnabled() const { return mySelectionEnabled; }
- void enableMultiselection(bool isEnable);
+ void enableMultiselection(bool isEnable);
/*!Checks: is multi selection enabled*/
- bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
+ bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
- int getSelectionCount() const;
+ int getSelectionCount() const;
- QColor backgroundColor() const;
- void setBackgroundColor( const QColor& );
+ QColor backgroundColor() const; // obsolete
+ void setBackgroundColor( const QColor& ); // obsolete
+ Qtx::BackgroundData background() const;
+ void setBackground( const Qtx::BackgroundData& );
signals:
- void selectionChanged();
+ void selectionChanged();
protected slots:
- void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
- void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
- void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
+ void onMousePress( SUIT_ViewWindow*, QMouseEvent* );
+ void onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
+ void onMouseRelease( SUIT_ViewWindow*, QMouseEvent* );
- void onDumpView();
- void onShowToolbar();
- void onChangeBgColor();
+ void onDumpView();
+ void onShowToolbar();
+ void onChangeBackground();
private:
- QColor myBgColor;
- bool mySelectionEnabled;
- bool myMultiSelectionEnabled;
+ Qtx::BackgroundData myDefaultBackground;
+ bool mySelectionEnabled;
+ bool myMultiSelectionEnabled;
};
#endif
#include <SUIT_Tools.h>
#include <SUIT_ResourceMgr.h>
+#include <QFileInfo>
#include <QImage>
#include <vtkRenderer.h>
#include <vtkCamera.h>
+#include <vtkJPEGReader.h>
+#include <vtkBMPReader.h>
+#include <vtkTIFFReader.h>
+#include <vtkPNGReader.h>
+#include <vtkMetaImageReader.h>
+#include <vtkImageMapToColors.h>
+#include <vtkTexture.h>
#include <QtxToolBar.h>
#include <QtxMultiAction.h>
myRenderer->LightFollowCameraOn();
myRenderer->TwoSidedLightingOn();
- // Set BackgroundColor
- QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
- QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
- QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
-
- if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
- myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
- else
- myRenderer->SetBackground( 0, 0, 0 );
-
// Create an interactor.
myRWInteractor = rw ? rw : VTKViewer_RenderWindowInteractor::New();
myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
+ // set default background
+ setBackground( Qtx::BackgroundData( Qt::black ) );
+ // reset view
onResetView();
}
Repaint();
}
-/*!Set background of the viewport*/
-void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color )
+/*!Set background color of the viewport [obsolete]*/
+void VTKViewer_ViewWindow::setBackgroundColor( const QColor& c )
{
- if ( myRenderer )
- myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
+ Qtx::BackgroundData bg = background();
+ bg.setColor( c );
+ setBackground( bg );
}
-/*!Returns background of the viewport*/
+/*!Returns background color of the viewport [obsolete]*/
QColor VTKViewer_ViewWindow::backgroundColor() const
{
- vtkFloatingPointType backint[3];
- if ( myRenderer ) {
- myRenderer->GetBackground( backint );
- return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
+ return background().color();
+}
+
+/*!Set background of the viewport*/
+void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
+{
+ bool ok = bgData.isValid();
+
+ switch ( bgData.mode() ) {
+ case Qtx::ImageBackground:
+ {
+ QString fileName;
+ int textureMode = bgData.texture( fileName );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // read texture from file
+ QString extension = fi.suffix().toLower();
+ vtkImageReader2* aReader = 0;
+ if ( extension == "jpg" || extension == "jpeg" )
+ aReader = vtkJPEGReader::New();
+ else if ( extension == "bmp" )
+ aReader = vtkBMPReader::New();
+ else if ( extension == "tif" || extension == "tiff" )
+ aReader = vtkTIFFReader::New();
+ else if ( extension == "png" )
+ aReader = vtkPNGReader::New();
+ else if ( extension == "mhd" || extension == "mha" )
+ aReader = vtkMetaImageReader::New();
+ if ( aReader ) {
+ // create texture
+ aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
+ aReader->Update();
+
+ vtkTexture* aTexture = vtkTexture::New();
+ vtkImageMapToColors* aMap = 0;
+ vtkAlgorithmOutput* anOutput;
+ /*
+ // special processing for BMP reader
+ vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
+ if ( aBMPReader ) {
+ // Special processing for BMP file
+ aBMPReader->SetAllow8BitBMP(1);
+
+ aMap = vtkImageMapToColors::New();
+ aMap->SetInputConnection( aBMPReader->GetOutputPort() );
+ aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
+ aMap->SetOutputFormatToRGB();
+
+ anOutput = aMap->GetOutputPort();
+ }
+ else {
+ }
+ */
+ anOutput = aReader->GetOutputPort( 0 );
+ aTexture->SetInputConnection( anOutput );
+ // set texture mode
+ // VSR: Currently, VTK only supports Stretch mode, so below code will give
+ // the same results for all modes
+ switch ( textureMode ) {
+ case Qtx::TileTexture:
+ aTexture->RepeatOn();
+ aTexture->EdgeClampOff();
+ aTexture->InterpolateOff();
+ break;
+ case Qtx::StretchTexture:
+ aTexture->RepeatOff();
+ aTexture->EdgeClampOff();
+ aTexture->InterpolateOn();
+ break;
+ case Qtx::CenterTexture:
+ default:
+ aTexture->RepeatOff();
+ aTexture->EdgeClampOn();
+ aTexture->InterpolateOff();
+ break;
+ }
+ // show textured background
+ getRenderer()->SetTexturedBackground( true ); // switch to texture mode
+ getRenderer()->SetBackgroundTexture( aTexture ); // set texture image
+
+ // clean-up resources
+ if ( aMap )
+ aMap->Delete();
+ aReader->Delete();
+ aTexture->Delete();
+ ok = true;
+ }
+ }
+ break;
+ }
+ case Qtx::ColorBackground:
+ {
+ QColor c = bgData.color();
+ if ( c.isValid() ) {
+ // show solid-colored background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ getRenderer()->SetBackground( c.red()/255.0,
+ c.green()/255.0,
+ c.blue()/255.0 ); // set background color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = bgData.gradient( c1, c2 );
+ // VSR: Currently, only vertical gradient is supported by VTK.
+ // In future, switch operator might be added here to process different supported gradient types.
+ if ( c1.isValid() && type == VTKViewer_Viewer::VerticalGradient ) {
+ if ( !c2.isValid() ) c2 = c1;
+ // show two-color gradient background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( true ); // switch to gradient mode
+ // VSR: In VTK, gradient is colored from bottom to top:
+ // - top color is set via SetBackground2()
+ // - bottom color is set via SetBackground()
+ // So, we reverse colors, to draw gradient from top to bottom instead.
+ getRenderer()->SetBackground( c2.red()/255.0,
+ c2.green()/255.0,
+ c2.blue()/255.0 ); // set first gradient color
+ getRenderer()->SetBackground2( c1.red()/255.0,
+ c1.green()/255.0,
+ c1.blue()/255.0 ); // set second gradient color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ // .........
+ break;
+ }
+ default:
+ break;
}
- return palette().color( backgroundRole() );
+ if ( ok )
+ myBackground = bgData;
+}
+
+/*!Returns background of the viewport*/
+Qtx::BackgroundData VTKViewer_ViewWindow::background() const
+{
+ return myBackground;
}
/*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/
virtual ~VTKViewer_ViewWindow();
/*!Gets tool bar.*/
- QToolBar* getToolBar() { return myToolBar; }
+ QToolBar* getToolBar() { return myToolBar; }
- void setBackgroundColor( const QColor& );
- QColor backgroundColor() const;
+ void setBackgroundColor( const QColor& ); // obsolete
+ QColor backgroundColor() const; // obsolete
+ void setBackground( const Qtx::BackgroundData& );
+ Qtx::BackgroundData background() const;
/*!Gets renderer.*/
vtkRenderer* getRenderer() { return myRenderer; }
ActionsMap myActionsMap;
double myCurScale;
+ Qtx::BackgroundData myBackground;
friend class VTKViewer_RenderWindowInteractor;
};
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Change Background...</translation>
</message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation>Vertical gradient</translation>
+ </message>
</context>
</TS>
<source>MEN_CHANGE_BACKGROUD</source>
<translation>Changer l'arrière-plan...</translation>
</message>
+ <message>
+ <source>GT_VERTICALGRADIENT</source>
+ <translation type="unfinished">Vertical gradient</translation>
+ </message>
</context>
</TS>