Commit 85ddb3c1 authored by T.J. Corona's avatar T.J. Corona

Operation: add observers for group actions (add/remove from group)

parent 5ad110ec
......@@ -26,6 +26,7 @@ set(operationSrcs
set(operationHeaders
Launcher.h
Group.h
GroupObserver.h
Manager.h
Metadata.h
MetadataContainer.h
......
......@@ -64,7 +64,16 @@ bool Group::registerOperation(const std::string& typeName, std::set<std::string>
Operation::Specification spec = getSpecification<std::string>(typeName, m_manager);
// Add the group name to the operator specification's list of groups.
return spec ? addTag(spec, name(), values) : false;
bool added = spec ? addTag(spec, name(), values) : false;
if (added)
{
auto manager = m_manager.lock();
auto metadata = manager->metadata().get<NameTag>().find(typeName);
manager->groupObservers()(metadata->index(), m_name, true);
}
return added;
}
bool Group::registerOperation(const Operation::Index& index, std::set<std::string> values)
......@@ -73,7 +82,15 @@ bool Group::registerOperation(const Operation::Index& index, std::set<std::strin
Operation::Specification spec = getSpecification<Operation::Index>(index, m_manager);
// Add the group name to the operator specification's list of groups.
return spec ? addTag(spec, name(), values) : false;
bool added = spec ? addTag(spec, name(), values) : false;
if (added)
{
auto manager = m_manager.lock();
manager->groupObservers()(index, m_name, true);
}
return added;
}
bool Group::unregisterOperation(const std::string& typeName)
......@@ -82,7 +99,16 @@ bool Group::unregisterOperation(const std::string& typeName)
Operation::Specification spec = getSpecification<std::string>(typeName, m_manager);
// Remove the group name from the operator specification's list of groups.
return spec ? removeTag(spec, name()) : false;
bool removed = spec ? removeTag(spec, name()) : false;
if (removed)
{
auto manager = m_manager.lock();
auto metadata = manager->metadata().get<NameTag>().find(typeName);
manager->groupObservers()(metadata->index(), m_name, false);
}
return removed;
}
bool Group::unregisterOperation(const Operation::Index& index)
......@@ -91,7 +117,15 @@ bool Group::unregisterOperation(const Operation::Index& index)
Operation::Specification spec = getSpecification<Operation::Index>(index, m_manager);
// Remove the group name from the operator specification's list of groups.
return spec ? removeTag(spec, name()) : false;
bool removed = spec ? removeTag(spec, name()) : false;
if (removed)
{
auto manager = m_manager.lock();
manager->groupObservers()(index, m_name, false);
}
return removed;
}
Operation::Specification Group::specification(const std::string& typeName) const
......
......@@ -13,6 +13,7 @@
#include "smtk/CoreExports.h"
#include "smtk/operation/GroupObserver.h"
#include "smtk/operation/Operation.h"
#include <set>
......@@ -48,6 +49,9 @@ class Manager;
class SMTKCORE_EXPORT Group
{
public:
typedef GroupObserver Observer;
typedef GroupObservers Observers;
Group(const std::string& name, std::shared_ptr<smtk::operation::Manager> manager)
: m_manager(manager)
, m_name(name)
......
//=========================================================================
// 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_operation_GroupObserver_h
#define __smtk_operation_GroupObserver_h
#include "smtk/CoreExports.h"
#include "smtk/common/Observers.h"
#include "smtk/operation/Operation.h"
namespace smtk
{
namespace operation
{
class Group;
typedef std::function<void(const Operation::Index&, const std::string&, bool)> GroupObserver;
typedef smtk::common::Observers<GroupObserver> GroupObservers;
}
}
#endif // __smtk_operation_GroupObserver_h
......@@ -113,6 +113,10 @@ public:
Observers& observers() { return m_observers; }
const Observers& observers() const { return m_observers; }
/// Return the group observers associated with this manager.
Group::Observers& groupObservers() { return m_groupObservers; }
const Group::Observers& groupObservers() const { return m_groupObservers; }
/// Return the metadata observers associated with this manager.
Metadata::Observers& metadataObservers() { return m_metadataObservers; }
const Metadata::Observers& metadataObservers() const { return m_metadataObservers; }
......@@ -190,6 +194,9 @@ private:
/// A container for all operation observers.
Observers m_observers;
/// A container for all operation group observers.
Group::Observers m_groupObservers;
/// A container for all operation metadata observers.
Metadata::Observers m_metadataObservers;
......
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