diff --git a/smtk/attribute/CMakeLists.txt b/smtk/attribute/CMakeLists.txt index 7ac02acc44bfe9857400b8e2b857766437e9448a..57f77bbdb03ae050ee46d24341c3beba1e9d9b3d 100644 --- a/smtk/attribute/CMakeLists.txt +++ b/smtk/attribute/CMakeLists.txt @@ -123,6 +123,8 @@ set(attributeHeaders ValueItemTemplate.h VoidItem.h VoidItemDefinition.h + + operators/Associate.h ) set(attributeSrcs @@ -168,8 +170,13 @@ set(attributeSrcs ValueItemDefinition.cxx VoidItem.cxx VoidItemDefinition.cxx + + operators/Associate.cxx ) +#construct operator inputs +smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Associate.sbt" defOpXML) + #install the headers smtk_public_headers(smtkCore ${attributeHeaders}) diff --git a/smtk/attribute/Registrar.cxx b/smtk/attribute/Registrar.cxx index 40fffb439388347e008d25cc48db2f8615115469..2df104f92f3aaa16dc3fff92e357590645e595df 100644 --- a/smtk/attribute/Registrar.cxx +++ b/smtk/attribute/Registrar.cxx @@ -13,10 +13,27 @@ #include "smtk/attribute/Resource.h" +#include "smtk/attribute/operators/Associate.h" + namespace smtk { namespace attribute { +namespace +{ +typedef std::tuple OperationList; +} + +void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager) +{ + operationManager->registerOperations(); +} + +void Registrar::unregisterFrom(const smtk::operation::Manager::Ptr& operationManager) +{ + operationManager->unregisterOperations(); +} + void Registrar::registerTo(const smtk::resource::Manager::Ptr& resourceManager) { resourceManager->registerResource(); diff --git a/smtk/attribute/Registrar.h b/smtk/attribute/Registrar.h index 1199c33c899b1673b562213554b0cd6e89e9bb6f..ca56a7b420858139013adf047ec901f6e0c0b408 100644 --- a/smtk/attribute/Registrar.h +++ b/smtk/attribute/Registrar.h @@ -12,6 +12,7 @@ #include "smtk/CoreExports.h" +#include "smtk/operation/Manager.h" #include "smtk/resource/Manager.h" namespace smtk @@ -21,6 +22,9 @@ namespace attribute class SMTKCORE_EXPORT Registrar { public: + static void registerTo(const smtk::operation::Manager::Ptr&); + static void unregisterFrom(const smtk::operation::Manager::Ptr&); + static void registerTo(const smtk::resource::Manager::Ptr&); static void unregisterFrom(const smtk::resource::Manager::Ptr&); }; diff --git a/smtk/attribute/operators/Associate.cxx b/smtk/attribute/operators/Associate.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5022239270cbcd00ce54b93e41036b60e5ca809f --- /dev/null +++ b/smtk/attribute/operators/Associate.cxx @@ -0,0 +1,54 @@ +//========================================================================= +// 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/attribute/operators/Associate.h" + +#include "smtk/attribute/Associate_xml.h" + +#include "smtk/attribute/Attribute.h" +#include "smtk/attribute/IntItem.h" +#include "smtk/attribute/Resource.h" +#include "smtk/attribute/ResourceItem.h" + +namespace smtk +{ +namespace attribute +{ + +Associate::Result Associate::operateInternal() +{ + // Access the attribute resource to associate. + smtk::attribute::Resource::Ptr resource = std::dynamic_pointer_cast( + this->parameters()->associations()->objectValue()); + + // Access the resource to which we will associate. + auto associateToItem = this->parameters()->findResource("associate to"); + + bool success = true; + + for (std::size_t i = 0; i < associateToItem->numberOfValues(); i++) + { + smtk::resource::Resource::Ptr associated = + std::dynamic_pointer_cast(associateToItem->objectValue()); + + // Associate the resource to the attribute resource. + success &= resource->associate(associated); + } + + return (success ? this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED) + : this->createResult(smtk::operation::Operation::Outcome::FAILED)); +} + +const char* Associate::xmlDescription() const +{ + return Associate_xml; +} +} +} diff --git a/smtk/attribute/operators/Associate.h b/smtk/attribute/operators/Associate.h new file mode 100644 index 0000000000000000000000000000000000000000..39e108af3a099354095477f5028345b2bb49ddf8 --- /dev/null +++ b/smtk/attribute/operators/Associate.h @@ -0,0 +1,40 @@ +//========================================================================= +// 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_attribute_operators_Associate_h +#define __smtk_attribute_operators_Associate_h + +#include "smtk/operation/XMLOperation.h" + +namespace smtk +{ +namespace attribute +{ + +/**\brief Associate a resource to an attribute resource. + + The visualized lists of attribute component items are populated from + associated resources. + */ +class SMTKCORE_EXPORT Associate : public smtk::operation::XMLOperation +{ +public: + smtkTypeMacro(smtk::attribute::Associate); + smtkCreateMacro(Associate); + smtkSharedFromThisMacro(smtk::operation::Operation); + smtkSuperclassMacro(smtk::operation::XMLOperation); + +protected: + Result operateInternal() override; + virtual const char* xmlDescription() const override; +}; +} +} + +#endif // __smtk_attribute_operators_Associate_h diff --git a/smtk/attribute/operators/Associate.sbt b/smtk/attribute/operators/Associate.sbt new file mode 100644 index 0000000000000000000000000000000000000000..1f047c8d6109c8352304edd0812c29d9c2390e8b --- /dev/null +++ b/smtk/attribute/operators/Associate.sbt @@ -0,0 +1,34 @@ + + + + + + + + + Associate a resource to an attribute resource. + + + <p>Associate a resource to an attribute resource. + <p>The visualized lists of attribute component items are + populated from associated resources. + + + + + + + + + + + + + + + + + + diff --git a/smtk/attribute/testing/cxx/unitAttributeAssociation.cxx b/smtk/attribute/testing/cxx/unitAttributeAssociation.cxx index 444a7a9f1f3f54437707daf5e9f0547608816b1b..6453476c8467fb7c7b2e7ee144c15628aa42977d 100644 --- a/smtk/attribute/testing/cxx/unitAttributeAssociation.cxx +++ b/smtk/attribute/testing/cxx/unitAttributeAssociation.cxx @@ -9,8 +9,12 @@ //========================================================================= #include "smtk/attribute/Attribute.h" #include "smtk/attribute/Definition.h" +#include "smtk/attribute/IntItem.h" #include "smtk/attribute/ModelEntityItemDefinition.h" #include "smtk/attribute/Resource.h" +#include "smtk/attribute/ResourceItem.h" + +#include "smtk/attribute/operators/Associate.h" #include "smtk/model/Edge.h" #include "smtk/model/EntityRef.h" @@ -83,5 +87,26 @@ int unitAttributeAssociation(int, char* []) smtkTest(e0.associateAttribute(att->attributeResource(), att->id()) == false, "Should not have been able to associate entity of wrong type."); + { + auto associateOperation = smtk::attribute::Associate::create(); + + attribute::ResourcePtr resptr = attribute::Resource::create(); + associateOperation->parameters()->associate(resptr); + + model::Resource::Ptr modelMgr = model::Resource::create(); + smtkTest(associateOperation->parameters()->findResource("associate to") != nullptr, + "Cannot access associate opration's input resource parameter."); + associateOperation->parameters()->findResource("associate to")->setValue(modelMgr); + + auto result = associateOperation->operate(); + + smtkTest(result->findInt("outcome")->value() == + static_cast(smtk::operation::Operation::Outcome::SUCCEEDED), + "Associate operator failed"); + + smtkTest(*(resptr->associations().begin()) == modelMgr, + "Could not set attribute resource's model-resource."); + } + return 0; }