...
 
Commits (2)
......@@ -39,6 +39,12 @@
#include "smtk/resource/Resource.h"
#include "pqActiveObjects.h"
#include "pqServer.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMPropertyIterator.h"
#include "vtkSMProxy.h"
#include "vtkSMSessionProxyManager.h"
#include "vtkCompositeRepresentation.h"
#include "smtk/extension/qt/qtResourceBrowserP.h"
......@@ -122,13 +128,38 @@ pqSMTKResourceBrowser::pqSMTKResourceBrowser(const smtk::view::PhraseModelPtr& p
// The superclass has initialized m_p;
// now we must add ParaView-specific configuration:
// I. Decorate phrases with visibility related to representations in the active view.
// I. Decorate phrases with visibility/color related to representations in the active view.
m_p->m_phraseModel->setDecorator([this](smtk::view::DescriptivePhrasePtr phr) {
smtk::view::VisibilityContent::decoratePhrase(
phr, [this](smtk::view::VisibilityContent::Query qq, int val,
smtk::view::ConstPhraseContentPtr data) {
return pqSMTKResourceBrowser::panelPhraseDecorator(qq, val, data, m_p->m_visibleThings);
if (phr->phraseType() == smtk::view::DescriptivePhraseType::COMPONENT_LIST)
{
// List phrases generated by the TwoLevelSubphraseGenerator should
// be decorated with an editor for SMTK's default color settings.
smtk::view::ColorContent::decoratePhrase(
phr, [this](smtk::view::ColorContent::Query qq, smtk::resource::FloatList& val,
smtk::view::ConstPhraseContentPtr data) {
return pqSMTKResourceBrowser::defaultComponentColorDecorator(qq, val, data);
});
// TODO: We should also listen for changes to the ColorPalette proxy object
// and mark any COMPONENT_LIST phrases that match as modified when
// their associated color changes.
// They should also have a special visibility editor:
/*
smtk::view::VisibilityContent::decoratePhrase(
phr, [this](smtk::view::VisibilityContent::Query qq, int val,
smtk::view::ConstPhraseContentPtr data) {
return pqSMTKResourceBrowser::activeViewVisibilityDecorator(qq, val, data, m_p->m_visibleThings);
});
*/
}
else
{
smtk::view::VisibilityContent::decoratePhrase(
phr, [this](smtk::view::VisibilityContent::Query qq, int val,
smtk::view::ConstPhraseContentPtr data) {
return pqSMTKResourceBrowser::activeViewVisibilityDecorator(qq, val, data, m_p->m_visibleThings);
});
}
});
// II. Prepare the subphrase generator.
......@@ -160,8 +191,8 @@ pqSMTKResourceBrowser::~pqSMTKResourceBrowser()
{
}
int pqSMTKResourceBrowser::panelPhraseDecorator(smtk::view::VisibilityContent::Query qq, int val,
smtk::view::ConstPhraseContentPtr data, std::map<smtk::common::UUID, int>& visibleThings)
int pqSMTKResourceBrowser::activeViewVisibilityDecorator(smtk::view::VisibilityContent::Query qq,
int val, smtk::view::ConstPhraseContentPtr data, std::map<smtk::common::UUID, int>& visibleThings)
{
auto comp = data->relatedComponent();
auto rsrc = data->relatedResource();
......@@ -245,6 +276,50 @@ int pqSMTKResourceBrowser::panelPhraseDecorator(smtk::view::VisibilityContent::Q
return 0;
}
int pqSMTKResourceBrowser::defaultComponentColorDecorator(smtk::view::ColorContent::Query qq,
smtk::view::ColorContent::FloatList& val, smtk::view::ConstPhraseContentPtr data)
{
std::string colorPropertyName;
std::string title = data->stringValue(smtk::view::PhraseContent::ContentType::TITLE);
if (title == "faces") colorPropertyName = "DefaultFaceColor";
else if (title == "edges") colorPropertyName = "EdgeColor";
// else if (title == "vertices") colorPropertyName = "DefaultVertexColor";
if (!colorPropertyName.empty())
{
pqServer* server = pqActiveObjects::instance().activeServer();
vtkSMProxy* proxy = server->proxyManager()->GetProxy("global_properties", "ColorPalette");
if (!proxy->GetProperty(colorPropertyName.c_str())) { return 0; }
vtkSMPropertyHelper colorProperty(proxy, colorPropertyName.c_str());
int ncc = colorProperty.GetNumberOfElements();
switch (qq)
{
case smtk::view::ColorContent::DISPLAYABLE:
return 1;
case smtk::view::ColorContent::EDITABLE:
return 1;
case smtk::view::ColorContent::GET_VALUE:
val = colorProperty.GetDoubleArray();
while (val.size() < 4)
{
val.push_back(1.0);
}
return 1;
case smtk::view::ColorContent::SET_VALUE:
// TODO: For now (to match ParaView's color palette, colors are
// only stored as RGB, not RGBA. So, even if val is longer
// we truncate to ncc (usu. 3):
if (static_cast<int>(val.size()) >= ncc)
{
colorProperty.Set(&val[0], ncc);
return 1;
}
}
}
return 0;
}
void pqSMTKResourceBrowser::searchTextChanged(const QString& searchText)
{ // For now, just rebuild.
(void)searchText;
......
......@@ -14,6 +14,7 @@
#include "smtk/extension/qt/qtResourceBrowser.h"
#include "smtk/view/ColorContent.h"
#include "smtk/view/VisibilityContent.h"
#include "smtk/PublicPointerDefs.h"
......@@ -54,9 +55,14 @@ public:
/// This method may be used by other ParaView plugins that wish to expose
/// per-active-view visibility decorations on qtResourceBrowser widgets.
static int panelPhraseDecorator(smtk::view::VisibilityContent::Query qq, int val,
static int activeViewVisibilityDecorator(smtk::view::VisibilityContent::Query qq, int val,
smtk::view::ConstPhraseContentPtr data, std::map<smtk::common::UUID, int>& visibleThings);
/// This method displays and edits a default color related to what each
/// list-phrase contains while ignoring the color of other phrases.
static int defaultComponentColorDecorator(smtk::view::ColorContent::Query qq,
smtk::view::ColorContent::FloatList& val, smtk::view::ConstPhraseContentPtr data);
protected slots:
virtual void searchTextChanged(const QString& searchText);
......
# set up sources to build
set(viewSrcs
AvailableOperations.cxx
ColorContent.cxx
ComponentPhraseContent.cxx
ComponentPhraseModel.cxx
#ComponentsByTypeGenerator.cxx
......@@ -24,6 +25,7 @@ set (jsonViewHeaders
)
set(viewHeaders
AvailableOperations.h
ColorContent.h
ComponentPhraseContent.h
ComponentPhraseModel.h
#ComponentsByTypeGenerator.h
......
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/view/ColorContent.h"
#include "smtk/view/DescriptivePhrase.h"
#include "smtk/view/PhraseModel.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/model/Entity.h"
#include "smtk/model/EntityRef.h"
#include "smtk/resource/Resource.h"
namespace smtk
{
namespace view
{
ColorContent::ColorContent()
{
}
ColorContent::~ColorContent()
{
}
ColorContent::Ptr ColorContent::setup(Delegate delegate)
{
m_delegate = delegate;
return shared_from_this();
}
DescriptivePhrasePtr ColorContent::decoratePhrase(DescriptivePhrasePtr src, Delegate delegate)
{
auto decorator = ColorContent::create()->setup(delegate);
decorator->appendDecorator(src->content());
src->setContent(decorator);
return src;
}
bool ColorContent::displayable(ContentType attr) const
{
FloatList dummy;
return attr == COLOR ? !!m_delegate(DISPLAYABLE, dummy, shared_from_this())
: this->Superclass::displayable(attr);
}
bool ColorContent::editable(ContentType attr) const
{
FloatList dummy;
return attr == COLOR ? !!m_delegate(EDITABLE, dummy, shared_from_this())
: this->Superclass::editable(attr);
}
resource::FloatList ColorContent::colorValue(ContentType attr) const
{
FloatList result;
bool didGet = false;
if (attr == COLOR && m_delegate)
{
didGet = !!m_delegate(GET_VALUE, result, shared_from_this());
}
if (!didGet)
{
result = this->Superclass::colorValue(attr);
}
return result;
}
bool ColorContent::editColorValue(ContentType attr, const FloatList& val)
{
bool didChange;
if (attr == COLOR && m_delegate)
{
FloatList edit(val);
didChange = !!m_delegate(SET_VALUE, edit, shared_from_this());
}
else
{
didChange = this->Superclass::editColorValue(attr, val);
}
if (didChange)
{
auto phr = this->location();
if (phr)
{
auto model = phr->phraseModel();
if (model)
{
auto idx = phr->index();
const std::vector<int> refs;
model->trigger(phr, PhraseModelEvent::PHRASE_MODIFIED, idx, idx, refs);
}
}
}
return didChange;
}
} // view namespace
} // smtk namespace
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef smtk_view_ColorContent_h
#define smtk_view_ColorContent_h
#include "smtk/view/PhraseContent.h"
#include <functional>
namespace smtk
{
namespace view
{
/**\brief Describe a resource component for user presentation.
*
*/
class SMTKCORE_EXPORT ColorContent : public PhraseContent
{
public:
/// Types of queries for visibility.
enum Query
{
DISPLAYABLE,
EDITABLE,
GET_VALUE,
SET_VALUE
};
/// Signature of a function to inspect or set the subject's visibility.
using FloatList = resource::FloatList;
using Delegate = std::function<int(Query q, FloatList& v, ConstPhraseContentPtr data)>;
smtkTypeMacro(ColorContent);
smtkSuperclassMacro(PhraseContent);
smtkSharedPtrCreateMacro(PhraseContent);
virtual ~ColorContent();
Ptr setup(Delegate delegate);
static DescriptivePhrasePtr decoratePhrase(DescriptivePhrasePtr phr, Delegate delegate);
bool displayable(ContentType attr) const override;
bool editable(ContentType attr) const override;
FloatList colorValue(ContentType attr) const override;
bool editColorValue(ContentType attr, const FloatList& val) override;
bool operator==(const PhraseContent& other) const override
{
return this->equalTo(other); // no way to compare m_delegate members.
}
protected:
ColorContent();
Delegate m_delegate;
};
} // view namespace
} // smtk namespace
#endif
......@@ -164,6 +164,7 @@ public:
int mutableAspects() const { return m_mutableAspects; }
protected:
friend class ColorContent;
friend class VisibilityContent;
PhraseModel();
......