Commit e8bbc351 authored by Shawn Waldon's avatar Shawn Waldon Committed by Kitware Robot
Browse files

Merge topic 'pick-block-fixes'

ad5d784e Fix Wsign-compare warning
d9665e7c Get current value of opacity to populate set block opacity dialog
15a500f2 Add HasElement to vtkSMDoubleMapProperty
9ccb5fd0 Make multiblock inspector panel update when block color/opacity are set
b5e3aa09 Get block name for context menu no longer uses inspector panel
ab8f8491

 Make pqPipelineContextMenuBehavior not use multiblock inspector panel
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Utkarsh Ayachit's avatarUtkarsh Ayachit <utkarsh.ayachit@kitware.com>
Merge-request: !1421
parents 07a1ff2f ad5d784e
Pipeline #54149 failed with stage
in 0 seconds
......@@ -158,6 +158,12 @@ vtkIdType vtkSMDoubleMapProperty::GetNumberOfElements()
return this->Private->Map.size();
}
//---------------------------------------------------------------------------
bool vtkSMDoubleMapProperty::HasElement(vtkIdType index)
{
return this->Private->Map.find(index) != this->Private->Map.end();
}
//---------------------------------------------------------------------------
void vtkSMDoubleMapProperty::ClearElements()
{
......
......@@ -90,6 +90,11 @@ public:
*/
virtual vtkIdType GetNumberOfElements() VTK_OVERRIDE;
/**
* Returns true if the property has an element with the given index
*/
bool HasElement(vtkIdType index);
/**
* Clears all of the elements from the property.
*/
......
......@@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqActiveObjects.h"
#include "pqApplicationCore.h"
#include "pqDoubleRangeDialog.h"
#include "pqEditColorMapReaction.h"
#include "pqMultiBlockInspectorPanel.h"
#include "pqPVApplicationCore.h"
......@@ -50,6 +51,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkPVDataInformation.h"
#include "vtkPVGeneralSettings.h"
#include "vtkSMArrayListDomain.h"
#include "vtkSMDoubleMapProperty.h"
#include "vtkSMDoubleMapPropertyIterator.h"
#include "vtkSMIntVectorProperty.h"
#include "vtkSMPVRepresentationProxy.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
......@@ -434,6 +438,39 @@ void pqPipelineContextMenuBehavior::hide()
}
}
namespace
{
void readVisibilityMap(vtkSMIntVectorProperty* ivp, QMap<unsigned int, int>& visibilities)
{
for (unsigned i = 0; i + 1 < ivp->GetNumberOfElements(); i += 2)
{
visibilities[ivp->GetElement(i)] = ivp->GetElement(i + 1);
}
}
void setVisibilitiesFromMap(
vtkSMIntVectorProperty* ivp, QMap<unsigned int, int>& visibilities, vtkSMProxy* proxy)
{
std::vector<int> vector;
for (QMap<unsigned int, int>::const_iterator i = visibilities.begin(); i != visibilities.end();
i++)
{
vector.push_back(static_cast<int>(i.key()));
vector.push_back(static_cast<int>(i.value()));
}
BEGIN_UNDO_SET("Change Block Visibilities");
if (!vector.empty())
{
// if property changes, ModifiedEvent will be fired and
// this->UpdateUITimer will be started.
ivp->SetElements(&vector[0], static_cast<unsigned int>(vector.size()));
}
proxy->UpdateVTKObjects();
END_UNDO_SET();
}
}
//-----------------------------------------------------------------------------
void pqPipelineContextMenuBehavior::hideBlock()
{
......@@ -443,11 +480,20 @@ void pqPipelineContextMenuBehavior::hideBlock()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockVisibility");
if (property)
{
panel->setBlockVisibility(this->PickedBlocks, false);
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(property);
QMap<unsigned int, int> visibilities;
readVisibilityMap(ivp, visibilities);
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
visibilities[this->PickedBlocks[i]] = 0;
}
setVisibilitiesFromMap(ivp, visibilities, proxy);
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -459,21 +505,35 @@ void pqPipelineContextMenuBehavior::showOnlyBlock()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockVisibility");
if (property)
{
panel->showOnlyBlocks(this->PickedBlocks);
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(property);
QMap<unsigned int, int> visibilities;
visibilities[0] = 0;
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
visibilities[this->PickedBlocks[i]] = 1;
}
setVisibilitiesFromMap(ivp, visibilities, proxy);
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
void pqPipelineContextMenuBehavior::showAllBlocks()
{
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockVisibility");
if (property)
{
panel->showAllBlocks();
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(property);
QMap<unsigned int, int> visibilities;
visibilities[0] = 1;
setVisibilitiesFromMap(ivp, visibilities, proxy);
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -485,11 +545,20 @@ void pqPipelineContextMenuBehavior::unsetBlockVisibility()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockVisibility");
if (property)
{
panel->clearBlockVisibility(this->PickedBlocks);
vtkSMIntVectorProperty* ivp = vtkSMIntVectorProperty::SafeDownCast(property);
QMap<unsigned int, int> visibilities;
readVisibilityMap(ivp, visibilities);
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
visibilities.remove(this->PickedBlocks[i]);
}
setVisibilitiesFromMap(ivp, visibilities, proxy);
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -502,15 +571,24 @@ void pqPipelineContextMenuBehavior::setBlockColor()
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
QColor qcolor = QColorDialog::getColor(
QColor(), panel, "Choose Block Color", QColorDialog::DontUseNativeDialog);
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockColor");
if (property)
{
QColor color = QColorDialog::getColor(
QColor(), panel, "Choose Block Color", QColorDialog::DontUseNativeDialog);
if (color.isValid())
BEGIN_UNDO_SET("Change Block Colors");
vtkSMDoubleMapProperty* dmp = vtkSMDoubleMapProperty::SafeDownCast(property);
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
panel->setBlockColor(this->PickedBlocks, color);
double color[] = { qcolor.redF(), qcolor.greenF(), qcolor.blueF() };
dmp->SetElements(this->PickedBlocks[i], color);
}
proxy->UpdateVTKObjects();
END_UNDO_SET();
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -522,11 +600,38 @@ void pqPipelineContextMenuBehavior::unsetBlockColor()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockColor");
if (property)
{
panel->clearBlockColor(this->PickedBlocks);
BEGIN_UNDO_SET("Change Block Colors");
vtkSMDoubleMapProperty* dmp = vtkSMDoubleMapProperty::SafeDownCast(property);
QMap<unsigned int, QColor> blockColors;
vtkSmartPointer<vtkSMDoubleMapPropertyIterator> iter;
iter.TakeReference(dmp->NewIterator());
for (iter->Begin(); !iter->IsAtEnd(); iter->Next())
{
QColor color = QColor::fromRgbF(
iter->GetElementComponent(0), iter->GetElementComponent(1), iter->GetElementComponent(2));
blockColors.insert(iter->GetKey(), color);
}
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
blockColors.remove(this->PickedBlocks[i]);
}
dmp->ClearElements();
QMap<unsigned int, QColor>::const_iterator iter2;
for (iter2 = blockColors.begin(); iter2 != blockColors.end(); iter2++)
{
QColor qcolor = iter2.value();
double color[] = { qcolor.redF(), qcolor.greenF(), qcolor.blueF() };
dmp->SetElements(iter2.key(), color);
}
proxy->UpdateVTKObjects();
END_UNDO_SET();
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -538,11 +643,36 @@ void pqPipelineContextMenuBehavior::setBlockOpacity()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockOpacity");
if (property)
{
panel->promptAndSetBlockOpacity(this->PickedBlocks);
vtkSMDoubleMapProperty* dmp = vtkSMDoubleMapProperty::SafeDownCast(property);
// Hope this works?
double current_opacity = 1;
if (dmp->HasElement(this->PickedBlocks[0]))
{
current_opacity = dmp->GetElement(this->PickedBlocks[0]);
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
pqDoubleRangeDialog dialog("Opacity:", 0.0, 1.0, panel);
dialog.setValue(current_opacity);
bool ok = dialog.exec();
if (!ok)
{
return;
}
BEGIN_UNDO_SET("Change Block Opacities");
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
dmp->SetElement(this->PickedBlocks[i], dialog.value());
}
proxy->UpdateVTKObjects();
END_UNDO_SET();
}
this->PickedRepresentation->renderViewEventually();
}
//-----------------------------------------------------------------------------
......@@ -554,20 +684,84 @@ void pqPipelineContextMenuBehavior::unsetBlockOpacity()
return;
}
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkSMProxy* proxy = this->PickedRepresentation->getProxy();
vtkSMProperty* property = proxy->GetProperty("BlockOpacity");
if (property)
{
BEGIN_UNDO_SET("Change Block Opacities");
vtkSMDoubleMapProperty* dmp = vtkSMDoubleMapProperty::SafeDownCast(property);
for (int i = 0; i < this->PickedBlocks.size(); ++i)
{
dmp->RemoveElement(this->PickedBlocks[i]);
}
proxy->UpdateVTKObjects();
END_UNDO_SET();
}
this->PickedRepresentation->renderViewEventually();
}
namespace
{
const char* findBlockName(
int flatIndexTarget, int& flatIndexCurrent, vtkPVCompositeDataInformation* currentInfo)
{
// An interior block shouldn't be selected, only blocks with geometry can be
if (flatIndexCurrent == flatIndexTarget)
{
return nullptr;
}
for (unsigned int i = 0; i < currentInfo->GetNumberOfChildren(); i++)
{
panel->clearBlockOpacity(this->PickedBlocks);
++flatIndexCurrent;
if (flatIndexCurrent == flatIndexTarget)
{
return currentInfo->GetName(i);
}
else if (flatIndexCurrent > flatIndexTarget)
{
return nullptr;
}
vtkPVDataInformation* childInfo = currentInfo->GetDataInformation(i);
if (childInfo)
{
vtkPVCompositeDataInformation* compositeChildInfo = childInfo->GetCompositeDataInformation();
// recurse down through child blocks only if the child block
// is composite and is not a multi-piece data set
if (compositeChildInfo->GetDataIsComposite() && !compositeChildInfo->GetDataIsMultiPiece())
{
const char* result = findBlockName(flatIndexTarget, flatIndexCurrent, compositeChildInfo);
if (result)
{
return result;
}
}
else if (compositeChildInfo && compositeChildInfo->GetDataIsMultiPiece())
{
flatIndexCurrent += compositeChildInfo->GetNumberOfChildren();
}
}
}
return nullptr;
}
}
//-----------------------------------------------------------------------------
QString pqPipelineContextMenuBehavior::lookupBlockName(unsigned int flatIndex) const
{
pqMultiBlockInspectorPanel* panel = getMultiBlockInspectorPanel();
if (panel)
vtkPVDataInformation* info = this->PickedRepresentation->getRepresentedDataInformation();
if (!info)
{
return QString();
}
vtkPVCompositeDataInformation* compositeInfo = info->GetCompositeDataInformation();
int myIdx = 0;
const char* name = findBlockName(flatIndex, myIdx, compositeInfo);
if (name)
{
return panel->lookupBlockName(flatIndex);
return QString(name);
}
else
{
......
......@@ -237,12 +237,18 @@ void pqMultiBlockInspectorPanel::onRepresentationChanged(pqRepresentation* repre
visibilityProperty, vtkCommand::ModifiedEvent, &this->UpdateUITimer, SLOT(start()));
}
vtkSMProperty* colorProperty = proxy->GetProperty("BlockColors");
vtkSMProperty* colorProperty = proxy->GetProperty("BlockColor");
if (colorProperty)
{
this->PropertyListener->Connect(
colorProperty, vtkCommand::ModifiedEvent, &this->UpdateUITimer, SLOT(start()));
}
vtkSMProperty* opacityProperty = proxy->GetProperty("BlockOpacity");
if (opacityProperty)
{
this->PropertyListener->Connect(
opacityProperty, vtkCommand::ModifiedEvent, &this->UpdateUITimer, SLOT(start()));
}
vtkSMProperty* colorArrayNameProperty = proxy->GetProperty("ColorArrayName");
if (colorArrayNameProperty)
{
......
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