Commit 083a1fd4 authored by Yumin Yuan's avatar Yumin Yuan

Merge pull request #242 from yumin/discrete_merge_fix

More error checking for merge face operator in discrete
parents 834b6c0b 08278c28
......@@ -16,10 +16,11 @@
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/model/Model.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Edge.h"
#include "smtk/model/Face.h"
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/model/Volume.h"
#include "vtkDiscreteModel.h"
......@@ -45,15 +46,26 @@ MergeOperator::MergeOperator()
bool MergeOperator::ableToOperate()
{
smtk::model::Model model;
int tgtid = this->fetchCMBCellId("target cell");
int srcid = this->fetchCMBCellId("source cell");
smtk::attribute::ModelEntityItemPtr sourceItem =
this->specification()->findModelEntity("source cell");
smtk::model::Face tgtFace =
this->specification()->findModelEntity("target cell")->
value().as<smtk::model::Face>();
return
// The SMTK model must be valid
(model = this->specification()->findModelEntity("model")->value().as<smtk::model::Model>()).isValid() &&
// The CMB model must exist:
this->discreteSession()->findModelEntity(model.entity()) &&
// The source and target cells must be valid:
this->fetchCMBCellId("source cell") >= 0 &&
this->fetchCMBCellId("target cell") >= 0
// The source and target cells must be valid,
srcid >= 0 && tgtid >= 0 &&
// The source and target cells should not be the same
(sourceItem->numberOfValues() > 1 || srcid != tgtid ) &&
// Currently the discrete kernel can't merge face with edges becasue the
// operation does not update edge relationships after face-merge
(tgtFace.isValid() && tgtFace.edges().size() ==0)
;
}
......@@ -64,7 +76,8 @@ OperatorResult MergeOperator::operateInternal()
value().as<smtk::model::Model>();
vtkDiscreteModelWrapper* modelWrapper =
opsession->findModelEntity(model.entity());
this->m_op->SetTargetId(this->fetchCMBCellId("target cell"));
int tgtid = this->fetchCMBCellId("target cell");
this->m_op->SetTargetId(tgtid);
smtk::model::ManagerPtr store = this->manager();
smtk::model::EntityRefs srcsRemoved;
......@@ -75,7 +88,7 @@ OperatorResult MergeOperator::operateInternal()
for(std::size_t idx=0; idx<sourceItem->numberOfValues(); idx++)
{
int srcid = this->fetchCMBCellId(sourceItem, idx);
if(srcid >= 0)
if(srcid >= 0 && srcid != tgtid)
{
this->m_op->SetSourceId(srcid);
this->m_op->Operate(modelWrapper);
......
......@@ -9,11 +9,11 @@
<MembershipMask>model</MembershipMask>
</ModelEntity>
<ModelEntity Name="source cell" NumberOfRequiredValues="0" Extensible="1">
<MembershipMask>face|edge</MembershipMask>
<MembershipMask>face</MembershipMask>
</ModelEntity>
<ModelEntity Name="target cell" NumberOfRequiredValues="1">
<MembershipMask>face|edge</MembershipMask>
<MembershipMask>face</MembershipMask>
</ModelEntity>
</ItemDefinitions>
</AttDef>
......
......@@ -14,6 +14,7 @@
#include "smtk/attribute/ModelEntityItemDefinition.h"
#include "smtk/attribute/System.h"
#include "smtk/model/EntityRef.h"
#include "smtk/model/Group.h"
#include "smtk/model/Manager.h"
#include <QAbstractItemView>
......@@ -121,24 +122,32 @@ void qtModelEntityItemCombo::init()
QStandardItemModel* itemModel = qobject_cast<QStandardItemModel*>(this->model());
// need to update the list, since it may be changed
// We create a temporary group and use Group::meetsMembershipConstraints()
// to test whether the mask allows association.
smtk::model::Manager::Ptr tmpMgr = smtk::model::Manager::create();
smtk::model::Group tmpGrp = tmpMgr->addGroup();
tmpGrp.setMembershipMask(itemDef->membershipMask());
int row=1;
smtk::model::EntityRefs modelEnts = modelManager->entitiesMatchingFlagsAs<smtk::model::EntityRefs>(
itemDef->membershipMask(), false);
for(smtk::model::EntityRefs::iterator it = modelEnts.begin(); it != modelEnts.end(); ++it)
for (smtk::model::UUIDWithEntity it = modelManager->topology().begin();
it != modelManager->topology().end(); ++it)
{
if((*it).isUseEntity())
continue;
QStandardItem* item = new QStandardItem;
std::string entName = (*it).name();
item->setText(entName.c_str());
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
//item->setData(this->Internals->AttSelections[keyName], Qt::CheckStateRole);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
item->setCheckable(true);
item->setCheckState(ModelEntityItem->has(*it) ? Qt::Checked : Qt::Unchecked);
item->setData((*it).entity().toString().c_str(), Qt::UserRole);
itemModel->insertRow(row, item);
smtk::model::EntityRef entref(modelManager, it->first);
if (entref.isValid() && !entref.isUseEntity() &&
tmpGrp.meetsMembershipConstraints(entref))
{
QStandardItem* item = new QStandardItem;
std::string entName = entref.name();
item->setText(entName.c_str());
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
//item->setData(this->Internals->AttSelections[keyName], Qt::CheckStateRole);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
item->setCheckable(true);
item->setCheckState(ModelEntityItem->has(entref) ? Qt::Checked : Qt::Unchecked);
item->setData(entref.entity().toString().c_str(), Qt::UserRole);
itemModel->insertRow(row, item);
}
}
itemModel->sort(0);
......
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