Commit e68566cb authored by Bob Obara's avatar Bob Obara

ENH: Adding observers to AssociationWidget and ModelEntityAttributeView

- Also fixed Import Issue
- Added reference to operation manager in Attribute Panel
- Resource Manager now tells observers a resource has been removed after it has been removed from the manager's set of resources and the resource's manager is cleared.
- Attribute Association operator now returns the attribute resource being modified in its result
parent 7eba4dd8
Pipeline #125456 running with stage
......@@ -55,7 +55,7 @@ Associate::Result Associate::operateInternal()
// Access the resource to which we will associate.
auto associateToItem = this->parameters()->findResource("associate to");
bool success = true;
auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
for (std::size_t i = 0; i < associateToItem->numberOfValues(); i++)
{
......@@ -63,11 +63,19 @@ Associate::Result Associate::operateInternal()
std::dynamic_pointer_cast<smtk::resource::Resource>(associateToItem->objectValue());
// Associate the resource to the attribute resource.
success &= resource->associate(associated);
bool success = resource->associate(associated);
if (success)
{
result->findResource("resource")->appendValue(resource);
}
else
{
result->findInt("outcome")->setValue(
static_cast<int>(smtk::operation::Operation::Outcome::FAILED));
}
}
return (success ? this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED)
: this->createResult(smtk::operation::Operation::Outcome::FAILED));
return result;
}
const char* Associate::xmlDescription() const
......
......@@ -29,6 +29,11 @@
</ItemDefinitions>
</AttDef>
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(associate to attribute)" BaseType="result"/>
<AttDef Type="result(associate to attribute)" BaseType="result">
<ItemDefinitions>
<Resource Name="resource" NumberOfRequiredValues="0" Extensible="true"></Resource>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeResource>
......@@ -73,10 +73,12 @@ bool pqSMTKAttributePanel::displayPipelineSource(pqPipelineSource* psrc)
// Keep hold of the selection instance for the active server connection
// so that this->displayResource() below can make use of it.
m_seln = wrapper->smtkSelection();
m_opManager = wrapper->smtkOperationManager();
}
else
{
m_seln = nullptr;
m_opManager = nullptr;
}
return this->displayResource(attrRsrc);
}
......@@ -111,8 +113,9 @@ bool pqSMTKAttributePanel::displayResource(smtk::attribute::ResourcePtr rsrc)
}
m_attrUIMgr = new smtk::extension::qtUIManager(rsrc);
m_attrUIMgr->setSelection(m_seln); // NB: m_seln may be null.
m_attrUIMgr->setSelectionBit(1); // ToDo: should be set by application
m_attrUIMgr->setOperationManager(m_opManager); // Assign the operation manager
m_attrUIMgr->setSelection(m_seln); // NB: m_seln may be null.
m_attrUIMgr->setSelectionBit(1); // ToDo: should be set by application
smtk::view::ViewPtr view = rsrc ? rsrc->findTopLevelView() : nullptr;
if (view)
......
......@@ -71,5 +71,6 @@ protected:
smtk::extension::qtUIManager* m_attrUIMgr;
smtk::resource::ResourcePtr m_rsrc;
smtk::view::SelectionPtr m_seln;
smtk::operation::ManagerPtr m_opManager;
int m_observer;
};
......@@ -19,12 +19,16 @@
#include "smtk/extension/qt/qtUIManager.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/ItemDefinition.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/ValueItem.h"
#include "smtk/attribute/ValueItemDefinition.h"
#include "smtk/operation/Manager.h"
#include "smtk/operation/SpecificationOps.h"
#include "smtk/resource/Component.h"
#include "smtk/resource/Manager.h"
......@@ -71,10 +75,52 @@ qtAssociationWidget::qtAssociationWidget(QWidget* _p, qtBaseView* bview)
std::ostringstream receiverSource;
receiverSource << "qtAssociationWidget_" << this;
m_selectionSourceName = receiverSource.str();
auto opManager = this->Internals->view->uiManager()->operationManager();
if (opManager != nullptr)
{
m_operationObserverKey = opManager->observers().insert(
[this](smtk::operation::Operation::Ptr oper, smtk::operation::EventType event,
smtk::operation::Operation::Result result) -> int {
return this->handleOperationEvent(oper, event, result);
});
}
else
{
m_operationObserverKey = -1;
std::cerr << "qtAssociationWidget: Could not find Operation Manager!\n";
}
auto resManager = this->Internals->view->uiManager()->resourceManager();
if (resManager != nullptr)
{
m_resourceObserverKey =
resManager->observers().insert([this](smtk::resource::Resource::Ptr resource,
smtk::resource::EventType event) { this->handleResourceEvent(resource, event); });
}
else
{
m_resourceObserverKey = -1;
std::cerr << "qtAssociationWidget: Could not find Resource Manager!\n";
}
}
qtAssociationWidget::~qtAssociationWidget()
{
if (m_operationObserverKey != -1)
{
auto opManager = this->Internals->view->uiManager()->operationManager();
if (opManager != nullptr)
{
opManager->observers().erase(m_operationObserverKey);
}
}
if (m_resourceObserverKey != -1)
{
auto resManager = this->Internals->view->uiManager()->resourceManager();
if (resManager != nullptr)
{
resManager->observers().erase(m_resourceObserverKey);
}
}
delete this->Internals;
}
......@@ -94,20 +140,26 @@ bool qtAssociationWidget::hasSelectedItem()
void qtAssociationWidget::showEntityAssociation(smtk::attribute::AttributePtr theAtt)
{
this->Internals->currentAtt = theAtt;
this->refreshAssociations();
}
void qtAssociationWidget::refreshAssociations()
{
this->Internals->CurrentList->blockSignals(true);
this->Internals->AvailableList->blockSignals(true);
this->Internals->CurrentList->clear();
this->Internals->AvailableList->clear();
if (!theAtt)
auto theAttribute = this->Internals->currentAtt.lock();
if (!theAttribute)
{
this->Internals->CurrentList->blockSignals(false);
this->Internals->AvailableList->blockSignals(false);
return;
}
attribute::DefinitionPtr attDef = theAtt->definition();
attribute::DefinitionPtr attDef = theAttribute->definition();
// Lets also find the base definition of the attribute that forces the unique condition
ResourcePtr attResource = attDef->resource();
......@@ -128,7 +180,7 @@ void qtAssociationWidget::showEntityAssociation(smtk::attribute::AttributePtr th
// Object doesn't have any appropriate attribute associated with it
this->addObjectAssociationListItem(this->Internals->AvailableList, obj, false);
}
else if ((*atts.begin()) == theAtt)
else if ((*atts.begin()) == theAttribute)
{
// Entity is associated with the attribute already
this->addObjectAssociationListItem(this->Internals->CurrentList, obj, false, true);
......@@ -514,3 +566,33 @@ void qtAssociationWidget::updateListItemSelectionAfterChange(
}
list->blockSignals(false);
}
int qtAssociationWidget::handleOperationEvent(smtk::operation::OperationPtr,
smtk::operation::EventType event, smtk::operation::Operation::Result result)
{
if (event != smtk::operation::EventType::DID_OPERATE)
{
return 0;
}
std::size_t count = smtk::operation::extractResources(result).size();
// If nothing has changed then just return
if (count == 0)
{
return 0;
}
// The simplest solution is just to refresh the widget
this->refreshAssociations();
return 0;
}
void qtAssociationWidget::handleResourceEvent(
smtk::resource::Resource::Ptr resource, smtk::resource::EventType event)
{
if (event == smtk::resource::EventType::REMOVED)
{
// The simplest solution is just to refresh the widget
this->refreshAssociations();
}
}
......@@ -24,6 +24,10 @@
#include "smtk/model/EntityRef.h"
#include "smtk/model/Group.h"
#include "smtk/operation/Observer.h"
#include "smtk/operation/Operation.h"
#include "smtk/resource/Observer.h"
#include <set>
class qtAssociationWidgetInternals;
......@@ -47,7 +51,10 @@ public:
virtual std::string selectionSourceName() { return m_selectionSourceName; }
public slots:
// Display the association information to a specific attribute
virtual void showEntityAssociation(smtk::attribute::AttributePtr theAtt);
// Refresh the association information for the current attribute;
virtual void refreshAssociations();
signals:
void attAssociationChanged();
......@@ -82,9 +89,20 @@ protected:
// helper function to update available/current list after selection
void updateListItemSelectionAfterChange(QList<QListWidgetItem*> selItems, QListWidget* list);
// This widget needs to handle changes made to resources as a result of an operation.
// This method is used by the observation mechanism to address these changes
int handleOperationEvent(smtk::operation::OperationPtr op, smtk::operation::EventType event,
smtk::operation::Operation::Result result);
// This widget needs to handle changes made to resources as a result of resources being removed.
// This method is used by the observation mechanism to address this via the resource manager
void handleResourceEvent(smtk::resource::Resource::Ptr resource, smtk::resource::EventType event);
private:
qtAssociationWidgetInternals* Internals;
std::string m_selectionSourceName;
smtk::operation::Observers::Key m_operationObserverKey;
smtk::resource::Observers::Key m_resourceObserverKey;
}; // class
}; // namespace attribute
......
......@@ -419,15 +419,15 @@ bool Manager::remove(const smtk::resource::ResourcePtr& resource)
{
Resource::Ptr rsrc = *resourceIt;
// Tell observers we're about to yoink it:
m_observers(rsrc, smtk::resource::EventType::REMOVED);
// Remove it from the manager's set of resources
m_resources.erase(resourceIt);
// Insert the resource's manager
// Clear the resource's manager
rsrc->m_manager = Ptr();
// Tell observers we have yoinked it:
m_observers(rsrc, smtk::resource::EventType::REMOVED);
return true;
}
......
......@@ -387,17 +387,17 @@ Import::Result Import::importExodus(const smtk::session::vtk::Resource::Ptr& res
{
smtk::attribute::ComponentItem::Ptr resultModels = result->findComponent("model");
resultModels->setValue(smtkModelOut.component());
resultModels->appendValue(smtkModelOut.component());
}
{
smtk::attribute::ResourceItem::Ptr created = result->findResource("resource");
created->setValue(resource);
created->appendValue(resource);
}
{
smtk::attribute::ComponentItem::Ptr created = result->findComponent("created");
created->setValue(smtkModelOut.component());
created->appendValue(smtkModelOut.component());
}
return result;
......
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