Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daf38a9
commit d9af7f7
Showing
10 changed files
with
460 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*************************************************************************** | ||
qgsgoochmaterialsettings.cpp | ||
-------------------------------------- | ||
Date : July 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsgoochmaterialsettings.h" | ||
|
||
#include "qgssymbollayerutils.h" | ||
#include "qgslinematerial_p.h" | ||
#include <Qt3DExtras/QGoochMaterial> | ||
|
||
QString QgsGoochMaterialSettings::type() const | ||
{ | ||
return QStringLiteral( "gooch" ); | ||
} | ||
|
||
QgsAbstractMaterialSettings *QgsGoochMaterialSettings::create() | ||
{ | ||
return new QgsGoochMaterialSettings(); | ||
} | ||
|
||
QgsGoochMaterialSettings *QgsGoochMaterialSettings::clone() const | ||
{ | ||
return new QgsGoochMaterialSettings( *this ); | ||
} | ||
|
||
void QgsGoochMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & ) | ||
{ | ||
mWarm = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "warm" ), QStringLiteral( "107,0,107" ) ) ); | ||
mCool = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "cool" ), QStringLiteral( "255,130,0" ) ) ); | ||
mDiffuse = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) ); | ||
mSpecular = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "specular" ) ) ); | ||
mShininess = elem.attribute( QStringLiteral( "shininess" ) ).toFloat(); | ||
} | ||
|
||
void QgsGoochMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext & ) const | ||
{ | ||
elem.setAttribute( QStringLiteral( "warm" ), QgsSymbolLayerUtils::encodeColor( mWarm ) ); | ||
elem.setAttribute( QStringLiteral( "cool" ), QgsSymbolLayerUtils::encodeColor( mCool ) ); | ||
elem.setAttribute( QStringLiteral( "diffuse" ), QgsSymbolLayerUtils::encodeColor( mDiffuse ) ); | ||
elem.setAttribute( QStringLiteral( "specular" ), QgsSymbolLayerUtils::encodeColor( mSpecular ) ); | ||
elem.setAttribute( QStringLiteral( "shininess" ), mShininess ); | ||
} | ||
|
||
Qt3DRender::QMaterial *QgsGoochMaterialSettings::toMaterial( const QgsMaterialContext &context ) const | ||
{ | ||
Qt3DExtras::QGoochMaterial *material = new Qt3DExtras::QGoochMaterial; | ||
material->setDiffuse( mDiffuse ); | ||
material->setWarm( mWarm ); | ||
material->setCool( mCool ); | ||
|
||
material->setSpecular( mSpecular ); | ||
material->setShininess( mShininess ); | ||
|
||
if ( context.isSelected() ) | ||
{ | ||
// update the material with selection colors | ||
material->setDiffuse( context.selectionColor() ); | ||
} | ||
return material; | ||
} | ||
|
||
QgsLineMaterial *QgsGoochMaterialSettings::toLineMaterial( const QgsMaterialContext &context ) const | ||
{ | ||
QgsLineMaterial *mat = new QgsLineMaterial; | ||
mat->setLineColor( mDiffuse ); | ||
if ( context.isSelected() ) | ||
{ | ||
// update the material with selection colors | ||
mat->setLineColor( context.selectionColor() ); | ||
} | ||
return mat; | ||
} | ||
|
||
void QgsGoochMaterialSettings::addParametersToEffect( Qt3DRender::QEffect * ) const | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*************************************************************************** | ||
qgsgoochmaterialsettings.h | ||
-------------------------------------- | ||
Date : July 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSGOOCHMATERIALSETTINGS_H | ||
#define QGSGOOCHMATERIALSETTINGS_H | ||
|
||
#include "qgis_3d.h" | ||
#include "qgsabstractmaterialsettings.h" | ||
|
||
#include <QColor> | ||
|
||
class QDomElement; | ||
|
||
/** | ||
* \ingroup 3d | ||
* Basic shading material used for rendering based on the Phong shading model | ||
* with three color components: ambient, diffuse and specular. | ||
* | ||
* \warning This is not considered stable API, and may change in future QGIS releases. It is | ||
* exposed to the Python bindings as a tech preview only. | ||
* | ||
* \since QGIS 3.16 | ||
*/ | ||
class _3D_EXPORT QgsGoochMaterialSettings : public QgsAbstractMaterialSettings | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor for QgsGoochMaterialSettings. | ||
*/ | ||
QgsGoochMaterialSettings() = default; | ||
|
||
QString type() const override; | ||
|
||
/** | ||
* Returns a new instance of QgsGoochMaterialSettings. | ||
*/ | ||
static QgsAbstractMaterialSettings *create() SIP_FACTORY; | ||
|
||
QgsGoochMaterialSettings *clone() const override SIP_FACTORY; | ||
|
||
//! Returns warm color component | ||
QColor warm() const { return mWarm; } | ||
|
||
//! Returns cool color component | ||
QColor cool() const { return mCool; } | ||
|
||
//! Returns diffuse color component | ||
QColor diffuse() const { return mDiffuse; } | ||
//! Returns specular color component | ||
QColor specular() const { return mSpecular; } | ||
//! Returns shininess of the surface | ||
float shininess() const { return mShininess; } | ||
|
||
//! Sets warm color component | ||
void setWarm( const QColor &warm ) { mWarm = warm; } | ||
|
||
//! Sets cool color component | ||
void setCool( const QColor &cool ) { mCool = cool; } | ||
|
||
//! Sets diffuse color component | ||
void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; } | ||
//! Sets specular color component | ||
void setSpecular( const QColor &specular ) { mSpecular = specular; } | ||
//! Sets shininess of the surface | ||
void setShininess( float shininess ) { mShininess = shininess; } | ||
|
||
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override; | ||
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override; | ||
#ifndef SIP_RUN | ||
Qt3DRender::QMaterial *toMaterial( const QgsMaterialContext &context ) const override SIP_FACTORY; | ||
QgsLineMaterial *toLineMaterial( const QgsMaterialContext &context ) const override SIP_FACTORY; | ||
void addParametersToEffect( Qt3DRender::QEffect *effect ) const override; | ||
#endif | ||
|
||
bool operator==( const QgsGoochMaterialSettings &other ) const | ||
{ | ||
return mDiffuse == other.mDiffuse && | ||
mSpecular == other.mSpecular && | ||
mWarm == other.mWarm && | ||
mCool == other.mCool && | ||
mShininess == other.mShininess; | ||
} | ||
|
||
private: | ||
QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) }; | ||
QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) }; | ||
QColor mWarm { QColor( 107, 0, 107 )}; | ||
QColor mCool { QColor( 255, 130, 0 )}; | ||
float mShininess = 0.0f; | ||
}; | ||
|
||
|
||
#endif // QGSGOOCHMATERIALSETTINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*************************************************************************** | ||
qgsgoochmaterialwidget.cpp | ||
-------------------------------------- | ||
Date : July 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsgoochmaterialwidget.h" | ||
|
||
#include "qgsgoochmaterialsettings.h" | ||
#include "qgis.h" | ||
|
||
QgsGoochMaterialWidget::QgsGoochMaterialWidget( QWidget *parent ) | ||
: QgsMaterialSettingsWidget( parent ) | ||
{ | ||
setupUi( this ); | ||
|
||
QgsGoochMaterialSettings defaultMaterial; | ||
setSettings( &defaultMaterial, nullptr ); | ||
|
||
connect( btnDiffuse, &QgsColorButton::colorChanged, this, &QgsGoochMaterialWidget::changed ); | ||
connect( btnWarm, &QgsColorButton::colorChanged, this, &QgsGoochMaterialWidget::changed ); | ||
connect( btnCool, &QgsColorButton::colorChanged, this, &QgsGoochMaterialWidget::changed ); | ||
connect( btnSpecular, &QgsColorButton::colorChanged, this, &QgsGoochMaterialWidget::changed ); | ||
connect( spinShininess, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsGoochMaterialWidget::changed ); | ||
} | ||
|
||
QgsMaterialSettingsWidget *QgsGoochMaterialWidget::create() | ||
{ | ||
return new QgsGoochMaterialWidget(); | ||
} | ||
|
||
void QgsGoochMaterialWidget::setDiffuseVisible( bool visible ) | ||
{ | ||
lblDiffuse->setVisible( visible ); | ||
btnDiffuse->setVisible( visible ); | ||
} | ||
|
||
bool QgsGoochMaterialWidget::isDiffuseVisible() const | ||
{ | ||
return btnDiffuse->isVisible(); | ||
} | ||
|
||
void QgsGoochMaterialWidget::setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer * ) | ||
{ | ||
const QgsGoochMaterialSettings *goochMaterial = dynamic_cast< const QgsGoochMaterialSettings * >( settings ); | ||
if ( !goochMaterial ) | ||
return; | ||
btnDiffuse->setColor( goochMaterial->diffuse() ); | ||
btnWarm->setColor( goochMaterial->warm() ); | ||
btnCool->setColor( goochMaterial->cool() ); | ||
btnSpecular->setColor( goochMaterial->specular() ); | ||
spinShininess->setValue( goochMaterial->shininess() ); | ||
} | ||
|
||
QgsAbstractMaterialSettings *QgsGoochMaterialWidget::settings() | ||
{ | ||
std::unique_ptr< QgsGoochMaterialSettings > m = qgis::make_unique< QgsGoochMaterialSettings >(); | ||
m->setDiffuse( btnDiffuse->color() ); | ||
m->setWarm( btnWarm->color() ); | ||
m->setCool( btnCool->color() ); | ||
m->setSpecular( btnSpecular->color() ); | ||
m->setShininess( spinShininess->value() ); | ||
return m.release(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*************************************************************************** | ||
qgsgoochmaterialwidget.h | ||
-------------------------------------- | ||
Date : July 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSGOOCHMATERIALWIDGET_H | ||
#define QGSGOOCHMATERIALWIDGET_H | ||
|
||
#include "qgsmaterialsettingswidget.h" | ||
|
||
#include <ui_goochmaterialwidget.h> | ||
|
||
class QgsGoochMaterialSettings; | ||
|
||
|
||
//! Widget for configuration of Gooch material settings | ||
class QgsGoochMaterialWidget : public QgsMaterialSettingsWidget, private Ui::GoochMaterialWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsGoochMaterialWidget( QWidget *parent = nullptr ); | ||
|
||
static QgsMaterialSettingsWidget *create(); | ||
|
||
void setDiffuseVisible( bool visible ); | ||
bool isDiffuseVisible() const; | ||
|
||
void setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer *layer ) override; | ||
QgsAbstractMaterialSettings *settings() override; | ||
|
||
}; | ||
|
||
#endif // QGSGOOCHMATERIALWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.