XGUI_Viewer.h
XGUI_RubberBand.h
XGUI_Constants.h
+ XGUI_ViewBackground.h
)
SET(PROJECT_AUTOMOC
XGUI_ViewPort.cpp
XGUI_Viewer.cpp
XGUI_RubberBand.cpp
+ XGUI_ViewBackground.cpp
)
SET(PROJECT_RESOURCES
#ifndef XGUI_Constants_H
#define XGUI_Constants_H
+#include <QList>
+
+typedef QList<int> QIntList; //!< list of int values
+typedef QList<short> QShortList; //!< list of short int values
+typedef QList<double> QDoubleList; //!< list of double values
+
+
namespace XGUI
{
enum GradientType {
+ NoGradient = -1,
HorizontalGradient, VerticalGradient,
Diagonal1Gradient, Diagonal2Gradient,
Corner1Gradient, Corner2Gradient,
enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane};
+enum BackgroundMode {
+ NoBackground, // no (invalid) background data
+ ColorBackground, // single color
+ SimpleGradientBackground, // simple two-color gradient
+ CustomGradientBackground // custom (complex) gradient
+};
+
+ //! Texture mode
+enum TextureMode {
+ CenterTexture, // center texture
+ TileTexture, // tile texture
+ StretchTexture, // stretch texture
+};
+
+
};
#endif
\ No newline at end of file
--- /dev/null
+#include "XGUI_ViewBackground.h"
+
+
+/*!
+ \brief Default constructor.
+ Creates invalid background data.
+*/
+XGUI_ViewBackground::XGUI_ViewBackground()
+ : myTextureMode( XGUI::CenterTexture ),
+ myGradientType( XGUI::NoGradient ),
+ myTextureShown( false )
+{
+ setMode( XGUI::NoBackground );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the specified color
+ \param c color
+*/
+XGUI_ViewBackground::XGUI_ViewBackground( const QColor& theColor )
+ : myTextureMode( XGUI::CenterTexture ),
+ myGradientType( XGUI::NoGradient ),
+ myTextureShown( false )
+{
+ setColor( theColor );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the specified two-color gradient
+ \param type gradient type identifier
+ \param c1 first gradient color
+ \param c2 second gradient color
+ \note the interpretation of the gradient identifier should be done in the calling code
+*/
+XGUI_ViewBackground::XGUI_ViewBackground( XGUI::GradientType type, const QColor& c1, const QColor& c2 )
+ : myTextureMode( XGUI::CenterTexture ),
+ myGradientType( XGUI::NoGradient ),
+ myTextureShown( false )
+{
+ setGradient( type, c1, c2 );
+}
+
+/*!
+ \brief Constructor.
+ Creates background data initialized with the arbirtary gradient data
+ \param grad gradient data
+*/
+XGUI_ViewBackground::XGUI_ViewBackground( const QGradient& grad )
+ : myTextureMode( XGUI::CenterTexture ),
+ myGradientType( XGUI::NoGradient ),
+ myTextureShown( false )
+{
+ setGradient( grad );
+}
+
+/*!
+ \brief Destructor.
+*/
+XGUI_ViewBackground::~XGUI_ViewBackground()
+{
+}
+
+/*!
+ \brief Compares two background data objects
+*/
+bool XGUI_ViewBackground::operator==( const XGUI_ViewBackground& other ) const
+{
+ return
+ ( myMode == other.myMode ) &&
+ ( myTextureMode == other.myTextureMode ) &&
+ ( myFileName == other.myFileName ) &&
+ ( myColors == other.myColors ) &&
+ ( myGradientType == other.myGradientType ) &&
+ ( myGradient == other.myGradient ) &&
+ ( myTextureShown == other.myTextureShown );
+}
+
+/*!
+ \brief Returns \c false if background data is not set (invalid)
+ \return \c true if background data is valid or \c false otherwise
+ \sa mode()
+*/
+bool XGUI_ViewBackground::isValid() const
+{
+ return myMode != XGUI::NoBackground;
+}
+
+
+/*!
+ \brief Get file name used as a texture image
+ \return path to the texture image file
+ \sa setTexture(), setTextureShown()
+*/
+XGUI::TextureMode XGUI_ViewBackground::texture( QString& fileName ) const
+{
+ fileName = myFileName;
+ return myTextureMode;
+}
+
+/*!
+ \brief Set file name to be used as a texture image.
+
+ \note To show texture image on the background it is necessary to call additionally
+ setTextureShown() method.
+
+ \param fileName path to the texture image file name
+ \param m texture mode (CenterTexture by default)
+ \sa texture(), setTextureShown()
+*/
+void XGUI_ViewBackground::setTexture( const QString& fileName, const XGUI::TextureMode m )
+{
+ myFileName = fileName;
+ myTextureMode = m;
+}
+
+/*!
+ \brief Check if "show texture" flag is switched on
+ \return \c true if "show texture" flag is set or \c false otherwise
+ \sa setTextureShown(), texture()
+*/
+bool XGUI_ViewBackground::isTextureShown() const
+{
+ return myTextureShown;
+}
+
+/*!
+ \brief Specify if texture should be shown on the background or no.
+ \param on \c true if texture should be shown or \c false otherwise
+ \sa isTextureShown(), texture()
+*/
+void XGUI_ViewBackground::setTextureShown( bool on )
+{
+ myTextureShown = on;
+}
+
+/*!
+ \brief Get background color. Returns null QColor if color is not set
+ \return solid background color
+ \sa setColor(), mode()
+*/
+QColor XGUI_ViewBackground::color() const
+{
+ return myColors.count() > 0 ? myColors[0] : QColor();
+}
+
+/*!
+ \brief Set background color and switch to the ColorBackground mode
+ \param c color
+ \sa color(), mode()
+*/
+void XGUI_ViewBackground::setColor( const QColor& c )
+{
+ myColors.clear();
+ myColors << c;
+ setMode( XGUI::ColorBackground );
+}
+
+/*!
+ \brief Get simple gradient data.
+ Returns -1 and null QColor for \a c1 and \a c2 if gradient data is not set
+ \param c1 first gradient color is returned via this parameter
+ \param c2 second gradient color is returned via this parameter
+ \return current two-colored gradient mode type identifier
+ \note the interpretation of the gradient identifier should be done in the calling code
+ \sa setGradient(int, const QColor&, const QColor&), mode()
+*/
+int XGUI_ViewBackground::gradient( QColor& c1, QColor& c2 ) const
+{
+ c1 = myColors.count() > 0 ? myColors[0] : QColor();
+ c2 = myColors.count() > 1 ? myColors[1] : ( myColors.count() > 0 ? myColors[0] : QColor() );
+ return myGradientType;
+}
+
+/*!
+ \brief Set simple background gradient data and switch to the SimpleGradientBackground mode
+ \param type two-colored gradient mode type identifier
+ \param c1 first gradient color is returned via this parameter
+ \param c2 second gradient color is returned via this parameter
+ \note the interpretation of the gradient identifier should be done in the calling code
+ \sa gradient(QColor&, QColor&), mode()
+*/
+void XGUI_ViewBackground::setGradient( XGUI::GradientType type, const QColor& c1, const QColor& c2 )
+{
+ myColors.clear();
+ myColors << c1 << c2;
+ myGradientType = type;
+ setMode( XGUI::SimpleGradientBackground );
+}
+
+/*!
+ \brief Get complex gradient data.
+ Returns QGradient of QGradient::NoGradient if gradient data is not set
+ \note This function does not transform simple gradient data set with
+ setGradient( const QString&, const QColor&, const QColor& ) to QGradient class
+ \return gradient data
+ \sa setGradient(const QGradient&), mode()
+*/
+const QGradient* XGUI_ViewBackground::gradient() const
+{
+ return &myGradient;
+}
+
+/*!
+ \brief Set complex background gradient data and switch to the CustomGradientBackground mode
+ \param grad gradient data (QLinearGradient, QRadialGradient or QConicalGradient)
+ \sa gradient(), mode()
+*/
+void XGUI_ViewBackground::setGradient( const QGradient& grad )
+{
+ myGradient = grad;
+ setMode( XGUI::CustomGradientBackground );
+}
--- /dev/null
+
+#ifndef XGUI_ViewBackground_H
+#define XGUI_ViewBackground_H
+
+#include "XGUI_Constants.h"
+
+#include <QColor>
+#include <QGradient>
+#include <QString>
+#include <QCompleter>
+
+typedef QList<QColor> QColorList; //!< list of colors
+
+/*!
+ \class XGUI_ViewBackground
+ \brief Stores background data
+
+ This class is used to store background data. Depending on the mode,
+ the background can be specified by:
+ - image (by assigning the file name to be used as background texture), see setTexture(), setTextureShown()
+ - single color (by assigning any color), see setColor()
+ - simple two-color gradient (with the gradient type id and two colors), see setGradient( int, const QColor&, const QColor& )
+ - complex gradient (by assigning arbitrary gradient data), see setGradient( const QGradient& )
+
+ The class stores all the data passed to it, so switching between different modes can be done
+ just by calling setMode() function.
+
+ \note Texture is used with combination of the background mode.
+
+ \note Two-color gradient is specified by two colors and integer identifier. The interpretation of
+ this identifier should be done in the calling code.
+
+ \code
+ XGUI_ViewBackground bg;
+ bg.setColor( QColor(100, 100, 100) ); // bg is switched to ColorBackground mode
+ bg.setGradient( Qt::Horizontal, Qt::gray, Qt::white ); // bg is switched to ColorBackground mode
+ QLinearGradient grad( 0,0,1,1 );
+ grad.setColorAt( 0.0, Qt::gray );
+ grad.setColorAt( 0.5, Qt::white );
+ grad.setColorAt( 1.0, Qt::green );
+ grad.setSpread( QGradient::PadSpread );
+ bg.setGradient( grad ); // bg is switched to CustomGradientBackground mode
+ bg.setMode( ColorBackground ); // bg is switched back to ColorBackground mode
+ bg.setTexture( "/data/images/background.png" ); // specify texture (in the centered mode by default)
+ bg.setTextureShown( true ); // draw texture on the solid color background
+ \endcode
+*/
+class XGUI_ViewBackground
+{
+public:
+ XGUI_ViewBackground();
+ XGUI_ViewBackground( const QColor& theColor );
+ XGUI_ViewBackground( XGUI::GradientType type, const QColor& theColor1, const QColor& theColor2);
+ XGUI_ViewBackground( const QGradient& );
+ virtual ~XGUI_ViewBackground();
+
+ bool operator==( const XGUI_ViewBackground&) const;
+ inline bool operator!=( const XGUI_ViewBackground& other ) const
+ { return !operator==( other ); }
+
+ bool isValid() const;
+
+ /*!
+ \brief Get background mode
+ \return current background mode
+ \sa setMode()
+ */
+ XGUI::BackgroundMode mode() const { return myMode; }
+
+ /*!
+ \brief Set background mode
+ \param m background mode being set
+ \sa mode()
+ */
+ void setMode( const XGUI::BackgroundMode m ) { myMode = m; }
+
+ XGUI::TextureMode texture( QString& ) const;
+ void setTexture( const QString&, XGUI::TextureMode = XGUI::CenterTexture );
+ bool isTextureShown() const;
+ void setTextureShown( bool );
+
+ QColor color() const;
+ void setColor( const QColor& );
+
+ int gradient( QColor&, QColor& ) const;
+ void setGradient( XGUI::GradientType, const QColor&, const QColor& );
+
+ const QGradient* gradient() const;
+ void setGradient( const QGradient& );
+
+private:
+ XGUI::BackgroundMode myMode;
+ XGUI::TextureMode myTextureMode;
+ QString myFileName;
+ QColorList myColors;
+ XGUI::GradientType myGradientType;
+ QGradient myGradient;
+ bool myTextureShown;
+};
+
+#endif
\ No newline at end of file
#include <QGuiApplication>
#include <QPaintEvent>
#include <QPainter>
+#include <QFileInfo>
#include <V3d_OrthographicView.hxx>
#include <V3d_PerspectiveView.hxx>
//***********************************************
void XGUI_ViewPort::updateBackground()
{
+ 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 XGUI::ColorBackground:
+ {
+ QColor c = myBackground.color();
+ if ( c.isValid() ) {
+ // Unset texture should be done here
+ // ...
+ Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
+ activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
+ // then change background color
+ activeView()->SetBackgroundColor( qCol );
+ // update viewer
+ activeView()->Update();
+ }
+ break;
+ }
+ case XGUI::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = myBackground.gradient( c1, c2 );
+ if ( c1.isValid() && type >= XGUI::HorizontalGradient && type <= XGUI::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 );
+ activeView()->SetBgImageStyle( Aspect_FM_NONE ); // cancel texture background
+ switch ( type ) {
+ case XGUI::HorizontalGradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
+ break;
+ case XGUI::VerticalGradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
+ break;
+ case XGUI::Diagonal1Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
+ break;
+ case XGUI::Diagonal2Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
+ break;
+ case XGUI::Corner1Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
+ break;
+ case XGUI::Corner2Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True );
+ break;
+ case XGUI::Corner3Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True );
+ break;
+ case XGUI::Corner4Gradient:
+ activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True );
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+ case XGUI::CustomGradientBackground:
+ // NOT IMPLEMENTED YET
+ break;
+ default:
+ break;
+ }
+ // 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 );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // set texture image: file name and fill mode
+ switch ( textureMode ) {
+ case XGUI::CenterTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
+ break;
+ case XGUI::TileTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
+ break;
+ case XGUI::StretchTexture:
+ activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
+ break;
+ default:
+ break;
+ }
+ activeView()->Update();
+ }
+ }
}
//***********************************************
emit vpTransformed( );
}
}
+
+/*!
+ Sets the background data
+*/
+void XGUI_ViewPort::setBackground( const XGUI_ViewBackground& bgData )
+{
+ if ( bgData.isValid() ) {
+ myBackground = bgData;
+ updateBackground();
+ emit vpChangeBackground( myBackground );
+ }
+}
#ifndef XGUI_ViewPort_H
#define XGUI_ViewPort_H
+#include "XGUI_ViewBackground.h"
+
#include <QWidget>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
void setAdvancedZoomingEnabled( const bool theState ) { myIsAdvancedZoomingEnabled = theState; }
bool isAdvancedZoomingEnabled() const { return myIsAdvancedZoomingEnabled; }
+ XGUI_ViewBackground background() const { return myBackground; }
+ void setBackground( const XGUI_ViewBackground& bgData );
+
signals:
- //void vpChangeBackground( const Qtx::BackgroundData& );
+ void vpChangeBackground( const XGUI_ViewBackground& );
void vpClosed();
void vpMapped();
void vpTransformed( );
bool myIsAdvancedZoomingEnabled;
double myScale;
+
+ XGUI_ViewBackground myBackground;
+ int myBgImgHeight;
+ int myBgImgWidth;
};
setTransformInProcess( false );
setTransformRequested( NOTHING );
}
+
+XGUI_ViewBackground XGUI_ViewWindow::background() const
+{
+ return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
+}
+
+void XGUI_ViewWindow::setBackground( const XGUI_ViewBackground& theBackground )
+{
+ if ( myViewPort ) myViewPort->setBackground( theBackground );
+}
#define XGUI_ViewWindow_H
#include "XGUI_Constants.h"
+#include "XGUI_ViewBackground.h"
#include <QFrame>
#include <QIcon>
void setTransformEnabled( const OperationType, const bool );
bool transformEnabled( const OperationType ) const;
+ XGUI_ViewBackground background() const;
+ void setBackground( const XGUI_ViewBackground& theBackground );
+
signals:
void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
}
+// VSR: Uncomment below line to allow texture background support in OCC viewer
+#define OCC_ENABLE_TEXTURED_BACKGROUND
+
+/*!
+ Get data for supported background modes: gradient types, identifiers and supported image formats
+*/
+QString XGUI_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QIntList& txtList )
+{
+ 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 << XGUI::HorizontalGradient << XGUI::VerticalGradient <<
+ XGUI::Diagonal1Gradient << XGUI::Diagonal2Gradient <<
+ XGUI::Corner1Gradient << XGUI::Corner2Gradient <<
+ XGUI::Corner3Gradient << XGUI::Corner4Gradient;
+#ifdef OCC_ENABLE_TEXTURED_BACKGROUND
+ txtList << XGUI::CenterTexture << XGUI::TileTexture << XGUI::StretchTexture;
+#endif
+ return tr("BG_IMAGE_FILES");
+}
+
+
XGUI_Viewer::XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron) :
QObject(theParent),
// init CasCade viewers
myV3dViewer = CreateViewer(TCollection_ExtendedString("Viewer3d").ToExtString(),
"", "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True );
- //myV3dViewer->Init(); // to avoid creation of the useless perspective view (see OCCT issue 0024267)
myV3dViewer->SetDefaultLights();
// init selector
myTrihedron->SetInfiniteState( Standard_True );
Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
- //myTrihedron->SetColor( Col );
myTrihedron->SetArrowColor( Col.Name() );
myTrihedron->SetSize(myTrihedronSize);
Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
XGUI_Viewer::~XGUI_Viewer(void)
{
+ myAISContext.Nullify();
+ myV3dViewer.Nullify();
}
connect(view->viewPort(), SIGNAL(vpClosed()), this, SLOT(onViewClosed()));
connect(view->viewPort(), SIGNAL(vpMapped()), this, SLOT(onViewMapped()));
+ view->setBackground(XGUI_ViewBackground(XGUI::VerticalGradient, Qt::green, Qt::blue));
+
QMdiArea* aMDI = myMainWindow->mdiArea();
QMdiSubWindow* aWnd = aMDI->addSubWindow(view, Qt::FramelessWindowHint);
aWnd->setGeometry(0,0, aMDI->width() / 2, aMDI->height() / 2);
{
Q_OBJECT
public:
+ static QString backgroundData( QStringList&, QIntList&, QIntList& );
+
XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
~XGUI_Viewer();
<translation>Menu</translation>
</message>
</context>
+<context>
+ <name>XGUI_Viewer</name>
+ <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>
+ <message>
+ <source>BG_IMAGE_FILES</source>
+ <translation>Image files (*.bmp *.gif *.pix *.xwd *.rgb *.rs)</translation>
+ </message>
+</context>
</TS>