Commit 35518aca authored by Mathieu Westphal's avatar Mathieu Westphal

Full rework of the pqTextureComboBox and related classes

pqTextureComboBox and pqTextureSelectorPropertyWidget
were ald classes and needed to be reworked in order to be more generic
and robust.
parent 2779b61a
......@@ -14,7 +14,8 @@
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/CameraParallelProjection/CheckBox" command="set_boolean" arguments="true" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/BackgroundType" command="set_string" arguments="Image" />
<!-- next command was written by by hand -->
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/Image" command="set_string" arguments="Load ..." />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/Image/LoadTextureDialog" command="filesSelected" arguments="$PARAVIEW_DATA_ROOT/Testing/Data/NE2_ps_bath.png" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/Image" command="set_string" arguments="NE2_ps_bath.png" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/1pqTextureSelectorPropertyWidget0/1pqTextureComboBox0" command="activated" arguments="Load ..." />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/1pqTextureSelectorPropertyWidget0/1pqTextureComboBox0/LoadTextureDialog" command="filesSelected" arguments="$PARAVIEW_DATA_ROOT/Testing/Data/NE2_ps_bath.png" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/ViewFrame/ProxyPanel/BackgroundEditor/stackedWidget/page_3/1pqTextureSelectorPropertyWidget0/1pqTextureComboBox0" command="activated" arguments="NE2_ps_bath" />
</pqevents>
......@@ -10729,6 +10729,10 @@ Select how you want the text to be represented in the view.
<ProxyGroupDomain name="groups">
<Group name="textures" />
</ProxyGroupDomain>
<Hints>
<TextureSelectorWidget check_tcoords="1" />
<!-- enable the texture selector only when tcoords is available. -->
</Hints>
</ProxyProperty>
<ProxyProperty command="SetLookupTable"
name="LookupTable" >
......
......@@ -130,19 +130,6 @@
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="page3Layout">
<item>
<widget class="pqTextureComboBox" name="Image">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
......
......@@ -40,6 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqPropertyManager.h"
#include "pqProxy.h"
#include "pqRenderView.h"
#include "pqTextureSelectorPropertyWidget.h"
#include "pqUndoStack.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyGroup.h"
......@@ -70,6 +71,7 @@ class pqBackgroundEditorWidget::pqInternal : public Ui::BackgroundEditorWidget
{
public:
enum BackgroundType PreviousType;
pqTextureSelectorPropertyWidget* TextureSelector = nullptr;
pqInternal(pqBackgroundEditorWidget* self)
: PreviousType(SINGLE_COLOR_TYPE)
......@@ -120,6 +122,19 @@ pqBackgroundEditorWidget::pqBackgroundEditorWidget(
ui.BackgroundType->hide();
}
currentIndexChangedBackgroundType(this->Internal->PreviousType);
smProperty = smGroup->GetProperty(IMAGE_PROPERTY);
if (smProperty)
{
// Can't use property link with texture, create the widget manually and connect signals
this->Internal->TextureSelector =
new pqTextureSelectorPropertyWidget(smProxy, smProperty, this);
QObject::connect(
this->Internal->TextureSelector, SIGNAL(changeAvailable()), this, SIGNAL(changeAvailable()));
QObject::connect(
this->Internal->TextureSelector, SIGNAL(changeFinished()), this, SIGNAL(changeFinished()));
ui.page3Layout->insertWidget(0, this->Internal->TextureSelector);
}
}
pqBackgroundEditorWidget::~pqBackgroundEditorWidget()
......@@ -138,7 +153,7 @@ void pqBackgroundEditorWidget::currentIndexChangedBackgroundType(int type)
bool visibleControls[TYPE_COUNT][ROWS] = { { true, false, false }, { true, true, false },
{ false, false, true } };
QWidget* controls[ROWS][COLS] = { { ui.Color, ui.RestoreDefaultColor },
{ ui.Color2, ui.RestoreDefaultColor2 }, { ui.Image, 0 } };
{ ui.Color2, ui.RestoreDefaultColor2 }, { this->Internal->TextureSelector, 0 } };
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLS; ++j)
......@@ -202,11 +217,6 @@ void pqBackgroundEditorWidget::fireGradientAndImageChanged(int oldType, int newT
}
}
void pqBackgroundEditorWidget::setView(pqView* _view)
{
this->Internal->Image->setRenderView(qobject_cast<pqRenderView*>(_view));
}
void pqBackgroundEditorWidget::clickedRestoreDefaultColor()
{
this->changeColor(COLOR_PROPERTY);
......
......@@ -55,9 +55,6 @@ signals:
void gradientBackgroundChanged();
void imageBackgroundChanged();
public slots:
void setView(pqView* newView) override;
protected slots:
void currentIndexChangedBackgroundType(int type);
void clickedRestoreDefaultColor();
......
......@@ -135,7 +135,7 @@ pqPropertyWidget* pqStandardPropertyWidgetInterface::createWidgetForProperty(
}
else if (name == "texture_selector")
{
return new pqTextureSelectorPropertyWidget(smProxy, parentWidget);
return new pqTextureSelectorPropertyWidget(smProxy, smProperty, parentWidget);
}
else if (name == "shader_replacements_selector")
{
......
This diff is collapsed.
/*=========================================================================
Program: ParaView
Module: pqTextureComboBox.h
Module: pqTextureComboBox.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
Copyright (c) 2005,2019 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
......@@ -12,7 +12,7 @@
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
1712 Route 9, Suite 300
Clifton Park, NY 12065
USA
......@@ -33,81 +33,57 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define pqTextureComboBox_h
#include "pqComponentsModule.h"
#include <QComboBox>
class pqDataRepresentation;
class pqRenderView;
#include "vtkNew.h"
class vtkSMProxy;
#include <QComboBox>
/**
* This is a ComboBox that is used on the display tab to select available
* textures. It checks whether current representation has texture coordinates,
* if not, the widget will be disabled automatically.
* It also provides the user with an option to load new images as textures.
*/
* This is a ComboBox that is used on the display tab to select available
* textures. It can be used with Representations, Sources and Views.
* It provides the user with an option to load new images as textures.
*/
class vtkSMProxyGroupDomain;
class vtkSMProxy;
class vtkEventQtSlotConnect;
class PQCOMPONENTS_EXPORT pqTextureComboBox : public QComboBox
{
Q_OBJECT
typedef QComboBox Superclass;
public:
pqTextureComboBox(QWidget* parent = 0);
~pqTextureComboBox() override;
pqTextureComboBox(vtkSMProxyGroupDomain* domain, QWidget* parent = nullptr);
~pqTextureComboBox() override = default;
public slots:
/**
* Set the representation. We need the representation, since we need to
* update the enable state of the widget depending on whether texture
* coordinates are available.
*/
void setRepresentation(pqDataRepresentation* repr);
* Update the selected index in the combobox using the provided texture if it
* is present in the combobox
*/
void updateFromTexture(vtkSMProxy* texture);
void setRenderView(pqRenderView* rview);
static const std::string TEXTURES_GROUP;
/**
* Forces a reload of the widget. Generally one does not need to call this
* method explicity.
*/
void reload();
protected slots:
/**
* Update the enable state of the widget.
*/
virtual void updateEnableState();
signals:
/**
* Called when user activates an item.
*/
void onActivated(int);
void updateFromProperty();
void updateTextures();
void proxyRegistered(const QString& groupname);
void proxyUnRegistered(const QString& group, const QString&, vtkSMProxy* proxy);
* Emitted whenever the texture has been changed
*/
void textureChanged(vtkSMProxy* texture);
protected:
/**
* Get the texture proxy associated with the given data.
*/
vtkSMProxy* getTextureProxy(const QVariant& data) const;
/**
* Prompts the user to load a texture file.
*/
void loadTexture();
bool loadTexture(const QString& filename);
protected slots:
void onCurrentIndexChanged(int index);
void updateTextures();
void proxyRegistered(const QString& group, const QString&, vtkSMProxy* proxy);
void proxyUnRegistered(const QString& group, const QString&, vtkSMProxy* proxy);
private:
Q_DISABLE_COPY(pqTextureComboBox)
class pqInternal;
pqInternal* Internal;
bool InOnActivate;
vtkSMProxyGroupDomain* Domain;
vtkNew<vtkEventQtSlotConnect> VTKConnector;
};
#endif
......@@ -32,44 +32,110 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqTextureSelectorPropertyWidget.h"
#include <QVBoxLayout>
// ParaView Includes
#include "pqApplicationCore.h"
#include "pqPipelineRepresentation.h"
#include "pqRenderView.h"
#include "pqDataRepresentation.h"
#include "pqServerManagerModel.h"
#include "pqTextureComboBox.h"
#include "pqUndoStack.h"
#include "pqView.h"
// Server Manager Includes
#include "vtkPVDataInformation.h"
#include "vtkPVDataSetAttributesInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxyGroupDomain.h"
// Qt Includes
#include <QVBoxLayout>
pqTextureSelectorPropertyWidget::pqTextureSelectorPropertyWidget(
vtkSMProxy* smProxy, QWidget* pWidget)
vtkSMProxy* smProxy, vtkSMProperty* smProperty, QWidget* pWidget)
: pqPropertyWidget(smProxy, pWidget)
{
this->setProperty(smProperty);
this->setToolTip("Select/Load texture to apply.");
QVBoxLayout* l = new QVBoxLayout;
l->setMargin(0);
this->Selector = new pqTextureComboBox(this);
pqServerManagerModel* smm = pqApplicationCore::instance()->getServerManagerModel();
pqPipelineRepresentation* repr = smm->findItem<pqPipelineRepresentation*>(smProxy);
if (repr)
// Recover domain and sanity check
this->Domain = smProperty->FindDomain<vtkSMProxyGroupDomain>();
if (!this->Domain || this->Domain->GetNumberOfGroups() != 1 ||
strcmp(this->Domain->GetGroup(0), pqTextureComboBox::TEXTURES_GROUP.c_str()) != 0)
{
this->Selector->setRepresentation(repr);
qCritical() << "pqTextureSelectorPropertyWidget can only be used with a ProxyProperty"
" with a ProxyGroupDomain containing only the \""
<< QString(pqTextureComboBox::TEXTURES_GROUP.c_str()) << "\" group";
}
this->connect(this, SIGNAL(viewChanged(pqView*)), this, SLOT(handleViewChanged(pqView*)));
// Create the combobox selector and set its value
this->Selector = new pqTextureComboBox(this->Domain, this);
this->onPropertyChanged();
l->addWidget(this->Selector);
this->setLayout(l);
// Connect the combo box to the property
QObject::connect(
this->Selector, SIGNAL(textureChanged(vtkSMProxy*)), this, SLOT(onTextureChanged(vtkSMProxy*)));
this->VTKConnector->Connect(
smProperty, vtkCommand::ModifiedEvent, this, SLOT(onPropertyChanged()));
pqServerManagerModel* smm = pqApplicationCore::instance()->getServerManagerModel();
// If check_tcoords="1" is specified, we enabled the widget only if tcoords are available
// Valid only for a RepresentationProxy
vtkPVXMLElement* hints = smProperty->GetHints()
? smProperty->GetHints()->FindNestedElementByName("TextureSelectorWidget")
: NULL;
if (hints && strcmp(hints->GetAttributeOrDefault("check_tcoords", ""), "1") == 0)
{
this->Representation = smm->findItem<pqDataRepresentation*>(smProxy);
if (this->Representation)
{
QObject::connect(this->Representation, SIGNAL(dataUpdated()), this, SLOT(checkTCoords()));
}
this->checkTCoords();
}
}
pqTextureSelectorPropertyWidget::~pqTextureSelectorPropertyWidget()
//-----------------------------------------------------------------------------
void pqTextureSelectorPropertyWidget::onTextureChanged(vtkSMProxy* texture)
{
BEGIN_UNDO_SET("Texture Change");
vtkSMPropertyHelper(this->property()).Set(texture);
this->proxy()->UpdateVTKObjects();
END_UNDO_SET();
emit this->changeAvailable();
emit this->changeFinished();
}
void pqTextureSelectorPropertyWidget::handleViewChanged(pqView* v)
//-----------------------------------------------------------------------------
void pqTextureSelectorPropertyWidget::onPropertyChanged()
{
pqRenderView* renderView = qobject_cast<pqRenderView*>(v);
if (renderView)
bool block = this->blockSignals(true);
this->Selector->updateFromTexture(vtkSMPropertyHelper(this->property()).GetAsProxy());
this->blockSignals(block);
}
//-----------------------------------------------------------------------------
void pqTextureSelectorPropertyWidget::checkTCoords()
{
bool enable = false;
// Enable only if we have point texture coordinates.
vtkPVDataInformation* dataInfo = this->Representation->getRepresentedDataInformation();
if (dataInfo)
{
vtkPVDataSetAttributesInformation* pdInfo = dataInfo->GetPointDataInformation();
if (pdInfo && pdInfo->GetAttributeInformation(vtkDataSetAttributes::TCOORDS))
{
enable = true;
}
}
this->setEnabled(enable);
if (!enable)
{
this->Selector->setRenderView(renderView);
this->setToolTip("No texture coordinates present in the data. Cannot apply texture.");
}
}
......@@ -36,7 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqComponentsModule.h"
#include "pqPropertyWidget.h"
#include "pqTextureComboBox.h"
#include "vtkNew.h"
/**
* Property widget for selecting the texture to apply to a surface.
......@@ -44,19 +44,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* To use this widget for a property add the 'panel_widget="texture_selector"'
* to the property's XML.
*/
class vtkSMProxyGroupDomain;
class pqTextureComboBox;
class pqDataRepresentation;
class PQCOMPONENTS_EXPORT pqTextureSelectorPropertyWidget : public pqPropertyWidget
{
Q_OBJECT
public:
pqTextureSelectorPropertyWidget(vtkSMProxy* proxy, QWidget* parent = 0);
~pqTextureSelectorPropertyWidget() override;
pqTextureSelectorPropertyWidget(vtkSMProxy* proxy, vtkSMProperty* property, QWidget* parent = 0);
~pqTextureSelectorPropertyWidget() override = default;
private slots:
void handleViewChanged(pqView* view);
protected slots:
void onTextureChanged(vtkSMProxy* texture);
void onPropertyChanged();
void checkTCoords();
private:
vtkNew<vtkEventQtSlotConnect> VTKConnector;
pqTextureComboBox* Selector;
vtkSMProxyGroupDomain* Domain;
pqDataRepresentation* Representation = nullptr;
pqView* View = nullptr;
};
#endif // _pqTextureSelectorPropertyWidget_h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment