From b2ef195cc8a6b25a7c4098f0c75e5354a6f1cbcf Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Wed, 10 Oct 2018 16:26:17 -0400 Subject: [PATCH 1/2] Add attribute resource associate operation. --- smtk/attribute/Attribute.cxx | 2 + smtk/attribute/CMakeLists.txt | 7 +++ smtk/attribute/operators/Associate.cxx | 54 +++++++++++++++++++ smtk/attribute/operators/Associate.h | 40 ++++++++++++++ smtk/attribute/operators/Associate.sbt | 34 ++++++++++++ .../testing/cxx/unitAttributeAssociation.cxx | 25 +++++++++ 6 files changed, 162 insertions(+) create mode 100644 smtk/attribute/operators/Associate.cxx create mode 100644 smtk/attribute/operators/Associate.h create mode 100644 smtk/attribute/operators/Associate.sbt diff --git a/smtk/attribute/Attribute.cxx b/smtk/attribute/Attribute.cxx index ad8b93a690..7fc1f9a1a0 100644 --- a/smtk/attribute/Attribute.cxx +++ b/smtk/attribute/Attribute.cxx @@ -254,12 +254,14 @@ bool Attribute::isValid() const { if (!(*it)->isValid()) { + std::cout << (*it)->type() << " is invalid" << std::endl; return false; } } // also check associations if (m_associatedObjects && !m_associatedObjects->isValid()) { + std::cout << "association is invalid" << std::endl; return false; } return true; diff --git a/smtk/attribute/CMakeLists.txt b/smtk/attribute/CMakeLists.txt index 7ac02acc44..57f77bbdb0 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/operators/Associate.cxx b/smtk/attribute/operators/Associate.cxx new file mode 100644 index 0000000000..5022239270 --- /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 0000000000..39e108af3a --- /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 0000000000..70b245c292 --- /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 444a7a9f1f..6453476c84 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; } -- GitLab From 4160bbc018b6923a602d30a3bdbe3d969a8bfcd5 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Wed, 10 Oct 2018 22:18:36 -0400 Subject: [PATCH 2/2] Add associate operator to attribute Registrar --- smtk/attribute/Attribute.cxx | 2 -- smtk/attribute/Registrar.cxx | 17 +++++++++++++++++ smtk/attribute/Registrar.h | 4 ++++ smtk/attribute/operators/Associate.sbt | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/smtk/attribute/Attribute.cxx b/smtk/attribute/Attribute.cxx index 7fc1f9a1a0..ad8b93a690 100644 --- a/smtk/attribute/Attribute.cxx +++ b/smtk/attribute/Attribute.cxx @@ -254,14 +254,12 @@ bool Attribute::isValid() const { if (!(*it)->isValid()) { - std::cout << (*it)->type() << " is invalid" << std::endl; return false; } } // also check associations if (m_associatedObjects && !m_associatedObjects->isValid()) { - std::cout << "association is invalid" << std::endl; return false; } return true; diff --git a/smtk/attribute/Registrar.cxx b/smtk/attribute/Registrar.cxx index 40fffb4393..2df104f92f 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 1199c33c89..ca56a7b420 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.sbt b/smtk/attribute/operators/Associate.sbt index 70b245c292..1f047c8d61 100644 --- a/smtk/attribute/operators/Associate.sbt +++ b/smtk/attribute/operators/Associate.sbt @@ -5,7 +5,7 @@ + Label="Attribute - Associate Resource" BaseType="operation"> Associate a resource to an attribute resource. -- GitLab