Commit f9a48296 authored by David Thompson's avatar David Thompson Committed by Kitware Robot

Merge topic 'more-attribute-ops-master'

371288b7 Signal more changes to the attribute system...
68f45eec Add a second "dummy" operation for the attribute system.
ad5260a7 Fix updates to ComponentPhraseModel.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1443
parents 2eeebe84 371288b7
Pipeline #127546 failed with stage
in 0 seconds
......@@ -135,6 +135,7 @@ set(attributeHeaders
operators/Associate.h
operators/Dissociate.h
operators/Read.h
operators/Signal.h
operators/Write.h
)
......@@ -185,6 +186,7 @@ set(attributeSrcs
operators/Associate.cxx
operators/Dissociate.cxx
operators/Read.cxx
operators/Signal.cxx
operators/Write.cxx
)
......@@ -192,6 +194,7 @@ set(attributeSrcs
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Associate.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Dissociate.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Read.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Signal.sbt" defOpXML)
smtk_operation_xml("${CMAKE_CURRENT_SOURCE_DIR}/operators/Write.sbt" defOpXML)
#install the headers
......
......@@ -16,6 +16,7 @@
#include "smtk/attribute/operators/Associate.h"
#include "smtk/attribute/operators/Dissociate.h"
#include "smtk/attribute/operators/Read.h"
#include "smtk/attribute/operators/Signal.h"
#include "smtk/attribute/operators/Write.h"
#include "smtk/operation/groups/ReaderGroup.h"
......@@ -27,7 +28,7 @@ namespace attribute
{
namespace
{
typedef std::tuple<Associate, Dissociate, Read, Write> OperationList;
typedef std::tuple<Associate, Dissociate, Read, Signal, Write> OperationList;
}
void Registrar::registerTo(const smtk::operation::Manager::Ptr& operationManager)
......
//=========================================================================
// 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/Signal.h"
#include "smtk/attribute/Signal_xml.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Resource.h"
#include "smtk/io/Logger.h"
namespace smtk
{
namespace attribute
{
Signal::Result Signal::operateInternal()
{
auto params = this->parameters();
auto result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);
auto modIn = params->findComponent("modified");
auto creIn = params->findComponent("created");
auto expIn = params->findComponent("expunged");
auto modOut = result->findComponent("modified");
auto creOut = result->findComponent("created");
auto expOut = result->findComponent("expunged");
// Copy the inputs to the output.
creOut->setObjectValues(creIn->begin(), creIn->end());
modOut->setObjectValues(modIn->begin(), modIn->end());
expOut->setObjectValues(expIn->begin(), expIn->end());
return result;
}
const char* Signal::xmlDescription() const
{
return Signal_xml;
}
}
}
//=========================================================================
// 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_operators_Signal_h
#define smtk_operation_operators_Signal_h
#include "smtk/operation/XMLOperation.h"
namespace smtk
{
namespace attribute
{
/**\brief A "dummy" operation used to mark an attribute as created, modified, or expunged.
This operation does nothing internally except pass the components
which are associated to itself into its result's "created", "modified",
or "expunged" entries.
*/
class SMTKCORE_EXPORT Signal : public smtk::operation::XMLOperation
{
public:
smtkTypeMacro(smtk::attribute::Signal);
smtkCreateMacro(Signal);
smtkSharedFromThisMacro(smtk::operation::Operation);
smtkSuperclassMacro(smtk::operation::XMLOperation);
protected:
Result operateInternal() override;
void generateSummary(Operation::Result&) override {}
virtual const char* xmlDescription() const override;
};
}
}
#endif // smtk_operation_operators_Signal_h
<?xml version="1.0" encoding="utf-8" ?>
<!-- Description of the "associate" Operation -->
<SMTK_AttributeResource Version="3">
<Definitions>
<!-- Operation -->
<include href="smtk/operation/Operation.xml"/>
<AttDef Type="mark modified"
Label="Resource - Mark as Modified" BaseType="operation">
<BriefDescription>
Mark the specified components as created, modified, or expunged.
</BriefDescription>
<ItemDefinitions>
<Component Name="created" Extensible="true" NumberOfRequiredValues="0">
<Accepts><Resource Name="smtk::attribute::Resource" Filter="*"/></Accepts>
</Component>
<Component Name="modified" Extensible="true" NumberOfRequiredValues="0">
<Accepts><Resource Name="smtk::attribute::Resource" Filter="*"/></Accepts>
</Component>
<Component Name="expunged" Extensible="true" NumberOfRequiredValues="0">
<Accepts><Resource Name="smtk::attribute::Resource" Filter="*"/></Accepts>
</Component>
</ItemDefinitions>
</AttDef>
<!-- Result -->
<include href="smtk/operation/Result.xml"/>
<AttDef Type="result(mark modified)" BaseType="result"/>
</Definitions>
</SMTK_AttributeResource>
......@@ -453,6 +453,7 @@ void qtAttributeView::onAttributeNameChanged(QTableWidgetItem* item)
{
ResourcePtr attResource = aAttribute->definition()->resource();
attResource->rename(aAttribute, item->text().toStdString());
this->attributeChanged(aAttribute);
//aAttribute->definition()->setLabel(item->text().toAscii().constData());
}
}
......@@ -671,6 +672,7 @@ void qtAttributeView::createNewAttribute(smtk::attribute::DefinitionPtr attDef)
ResourcePtr attResource = attDef->resource();
smtk::attribute::AttributePtr newAtt = attResource->createAttribute(attDef->type());
this->attributeCreated(newAtt);
QTableWidgetItem* item = this->addAttributeListItem(newAtt);
if (item)
{
......@@ -711,6 +713,7 @@ void qtAttributeView::onDeleteSelected()
attribute::DefinitionPtr attDef = selObject->definition();
ResourcePtr attResource = attDef->resource();
attResource->removeAttribute(selObject);
this->attributeRemoved(selObject);
QTableWidgetItem* selItem = this->getSelectedItem();
this->Internals->ListTable->removeRow(selItem->row());
......
......@@ -9,8 +9,13 @@
//=========================================================================
#include "smtk/extension/qt/qtBaseView.h"
#include "smtk/attribute/ComponentItem.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/Resource.h"
#include "smtk/attribute/operators/Signal.h"
#include "smtk/operation/Manager.h"
#include "smtk/extension/qt/qtUIManager.h"
#include "smtk/view/View.h"
......@@ -128,6 +133,43 @@ void qtBaseView::valueChanged(smtk::attribute::ItemPtr item)
this->uiManager()->onViewUIModified(this, item);
}
namespace
{
static void signalAttribute(smtk::extension::qtUIManager* uiManager,
const smtk::attribute::AttributePtr& attr, const char* itemName)
{
if (attr && uiManager && itemName && itemName[0])
{
// create a "dummy" operation that will mark the attribute resource
// as modified so that applications know when a "save" is required.
auto opManager = uiManager->operationManager();
if (opManager)
{
auto markModified = opManager->create<smtk::attribute::Signal>();
auto didAppend = markModified->parameters()->findComponent(itemName)->appendObjectValue(attr);
(void)didAppend;
markModified->operate();
}
}
}
}
void qtBaseView::attributeCreated(const smtk::attribute::AttributePtr& attr)
{
signalAttribute(this->uiManager(), attr, "created");
}
void qtBaseView::attributeChanged(const smtk::attribute::AttributePtr& attr)
{
signalAttribute(this->uiManager(), attr, "modified");
}
void qtBaseView::attributeRemoved(const smtk::attribute::AttributePtr& attr)
{
signalAttribute(this->uiManager(), attr, "expunged");
}
bool qtBaseView::setFixedLabelWidth(int w)
{
w = std::min(w, this->uiManager()->maxValueLabelLength());
......
......@@ -114,6 +114,12 @@ public slots:
}
virtual void updateModelAssociation() { ; }
virtual void valueChanged(smtk::attribute::ItemPtr);
/// Invoke the Signal dummy operation to indicate an attribute has been created.
virtual void attributeCreated(const smtk::attribute::AttributePtr&);
/// Invoke the Signal dummy operation to indicate an attribute has been changed (renamed).
virtual void attributeChanged(const smtk::attribute::AttributePtr&);
/// Invoke the Signal dummy operation to indicate an attribute has been removed.
virtual void attributeRemoved(const smtk::attribute::AttributePtr&);
virtual void childrenResized() { ; }
virtual void showAdvanceLevelOverlay(bool val) { m_advOverlayVisible = val; }
virtual void showAdvanceLevel(int i);
......
......@@ -140,6 +140,7 @@ void qtInstancedView::updateAttributeData()
else
{
att = resource->createAttribute(attName, attDef);
this->attributeCreated(att);
}
}
else
......
......@@ -507,6 +507,7 @@ void qtModelEntityAttributeView::cellChanged(int row, int column)
else if (att)
{
attRes->removeAttribute(att);
this->attributeRemoved(att);
}
// Now create a new attribute for the model entity of the correct type
......@@ -517,6 +518,8 @@ void qtModelEntityAttributeView::cellChanged(int row, int column)
{
att = attRes->createAttribute(currentDefs.at(j));
att->associate(entity);
// Notify the application of the new attribute via an "operation"
this->attributeCreated(att);
break;
}
}
......
......@@ -112,6 +112,7 @@ bool qtSelectorView::createSelector()
return false;
}
this->Internals->m_selectorAttribute = resource->createAttribute(attName, attDef);
this->attributeCreated(this->Internals->m_selectorAttribute);
}
else
{
......
......@@ -449,6 +449,7 @@ void qtSimpleExpressionView::createNewFunction(smtk::attribute::DefinitionPtr at
ResourcePtr attResource = attDef->resource();
smtk::attribute::AttributePtr newFunc = attResource->createAttribute(attDef->type());
this->attributeCreated(newFunc);
QListWidgetItem* item = this->addFunctionListItem(newFunc);
if (item)
{
......
......@@ -436,9 +436,13 @@ void PhraseModel::updateChildren(
{
// Run through the entire array to see if there are different instances
// of the phrase that nonetheless behave identically.
// Note that we might have phrases that are different instances
// but identical in that they refer to the same component/resource/etc.,
// hence the second test in the conditional below:
for (auto it2 = orig.begin(); it2 != orig.end(); ++it2)
{
if (it->get() == it2->get())
if ((it->get() == it2->get()) ||
(it->get()->relatedObject() == it2->get()->relatedObject()))
{
*it = *it2;
unused.erase(lkup[*it2]);
......@@ -446,8 +450,6 @@ void PhraseModel::updateChildren(
}
}
}
// But wait, we might have phrases that are different instances
// but identical in that they refer to the same component/resource/etc.
// Now delete unused from model, starting at the back so we don't invalidate indices.
std::vector<int> removalRange(2);
......
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