From 444ccbe1cd8ec5d0ed1c8308609c1f17412180f9 Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Fri, 17 Apr 2015 10:33:37 -0400 Subject: [PATCH 1/5] Move vtkMaterialOperator from legacy to discrete session --- .../{legacycmb/CMBModel => operation}/vtkMaterialOperator.cxx | 0 .../{legacycmb/CMBModel => operation}/vtkMaterialOperator.h | 0 .../{legacycmb/CMBModel => operation}/vtkMaterialOperatorBase.cxx | 0 .../{legacycmb/CMBModel => operation}/vtkMaterialOperatorBase.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename smtk/bridge/discrete/{legacycmb/CMBModel => operation}/vtkMaterialOperator.cxx (100%) rename smtk/bridge/discrete/{legacycmb/CMBModel => operation}/vtkMaterialOperator.h (100%) rename smtk/bridge/discrete/{legacycmb/CMBModel => operation}/vtkMaterialOperatorBase.cxx (100%) rename smtk/bridge/discrete/{legacycmb/CMBModel => operation}/vtkMaterialOperatorBase.h (100%) diff --git a/smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperator.cxx b/smtk/bridge/discrete/operation/vtkMaterialOperator.cxx similarity index 100% rename from smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperator.cxx rename to smtk/bridge/discrete/operation/vtkMaterialOperator.cxx diff --git a/smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperator.h b/smtk/bridge/discrete/operation/vtkMaterialOperator.h similarity index 100% rename from smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperator.h rename to smtk/bridge/discrete/operation/vtkMaterialOperator.h diff --git a/smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperatorBase.cxx b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx similarity index 100% rename from smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperatorBase.cxx rename to smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx diff --git a/smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperatorBase.h b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h similarity index 100% rename from smtk/bridge/discrete/legacycmb/CMBModel/vtkMaterialOperatorBase.h rename to smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h From 7c6381ce570608b23440657127366ff700427863 Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Fri, 17 Apr 2015 10:38:47 -0400 Subject: [PATCH 2/5] Add vtkMaterialOperator to operations in discrete session --- smtk/bridge/discrete/CMakeLists.txt | 4 ++++ smtk/bridge/discrete/operation/vtkMaterialOperator.h | 5 ++--- .../discrete/operation/vtkMaterialOperatorBase.h | 10 ++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/smtk/bridge/discrete/CMakeLists.txt b/smtk/bridge/discrete/CMakeLists.txt index 87c4648ccc..03abcfa635 100644 --- a/smtk/bridge/discrete/CMakeLists.txt +++ b/smtk/bridge/discrete/CMakeLists.txt @@ -55,6 +55,8 @@ SET(DiscreteOperationFiles operation/vtkSplitOperator.cxx operation/vtkSplitOperatorBase.cxx operation/vtkMasterPolyDataNormals.cxx + operation/vtkMaterialOperator.cxx + operation/vtkMaterialOperatorBase.cxx operation/vtkMergeDuplicateCells.cxx operation/vtkModelEntityGroupOperator.cxx operation/vtkModelEntityGroupOperatorBase.cxx @@ -86,6 +88,8 @@ SET(DiscreteModelHeaders operation/vtkSplitOperator.h operation/vtkSplitOperatorBase.h operation/vtkMasterPolyDataNormals.h + operation/vtkMaterialOperator.h + operation/vtkMaterialOperatorBase.h operation/vtkMergeDuplicateCells.h operation/vtkModelEntityGroupOperator.h operation/vtkModelEntityGroupOperatorBase.h diff --git a/smtk/bridge/discrete/operation/vtkMaterialOperator.h b/smtk/bridge/discrete/operation/vtkMaterialOperator.h index b16eeff6ce..bb99929c9a 100644 --- a/smtk/bridge/discrete/operation/vtkMaterialOperator.h +++ b/smtk/bridge/discrete/operation/vtkMaterialOperator.h @@ -22,9 +22,8 @@ #ifndef __vtkMaterialOperator_h #define __vtkMaterialOperator_h -#include "vtkCmbDiscreteModelModule.h" // For export macro +#include "smtk/bridge/discrete/discreteSessionExports.h" // For export macro #include "vtkMaterialOperatorBase.h" -#include "cmbSystemConfig.h" #include @@ -34,7 +33,7 @@ class vtkDiscreteModelWrapper; class vtkIdList; class vtkModelEntity; -class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperator : public vtkMaterialOperatorBase +class SMTKDISCRETESESSION_EXPORT vtkMaterialOperator : public vtkMaterialOperatorBase { public: static vtkMaterialOperator * New(); diff --git a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h index 9177eb0ad3..bb8ef3ccb5 100644 --- a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h +++ b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h @@ -18,13 +18,11 @@ // We may eventually need to add in the ability to set a // warehouseid of a material here as well. +#ifndef __smtkdiscrete_vtkMaterialOperatorBase_h +#define __smtkdiscrete_vtkMaterialOperatorBase_h -#ifndef __vtkMaterialOperatorBase_h -#define __vtkMaterialOperatorBase_h - -#include "vtkCmbDiscreteModelModule.h" // For export macro +#include "smtk/bridge/discrete/discreteSessionExports.h" // For export macro #include "vtkModelEntityOperatorBase.h" -#include "cmbSystemConfig.h" class vtkModelMaterial; class vtkDiscreteModel; @@ -32,7 +30,7 @@ class vtkIdList; class vtkModelEntity; class vtkModelGeometricEntity; -class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperatorBase : public vtkModelEntityOperatorBase +class SMTKDISCRETESESSION_EXPORT vtkMaterialOperatorBase : public vtkModelEntityOperatorBase { public: static vtkMaterialOperatorBase * New(); From ea3f284f53bf55d95deeed9fa73bce93f24df00c Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Mon, 20 Apr 2015 12:30:34 -0400 Subject: [PATCH 3/5] Added methods to remove entity by vtkMaterialOperator in discrete --- .../bridge/discrete/kernel/vtkModelMaterial.h | 1 + .../operation/vtkMaterialOperatorBase.cxx | 57 +++++++++++++++++-- .../operation/vtkMaterialOperatorBase.h | 10 +++- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/smtk/bridge/discrete/kernel/vtkModelMaterial.h b/smtk/bridge/discrete/kernel/vtkModelMaterial.h index f78f915911..4dcbc059db 100644 --- a/smtk/bridge/discrete/kernel/vtkModelMaterial.h +++ b/smtk/bridge/discrete/kernel/vtkModelMaterial.h @@ -56,6 +56,7 @@ class VTKSMTKDISCRETEMODEL_EXPORT vtkModelMaterial : public vtkModelEntity virtual ~vtkModelMaterial(); static vtkModelMaterial* New(); + friend class vtkMaterialOperatorBase; // Description: // Remove GeometricEntity from this material. It is assumed that it // will be added to another material. diff --git a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx index 1af95f7f8c..684607e0e8 100644 --- a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx +++ b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.cxx @@ -29,6 +29,7 @@ vtkMaterialOperatorBase::vtkMaterialOperatorBase() this->ItemType = vtkModelMaterialType; this->IsItemTypeSet = 1; this->GeometricEntitiesToAdd = vtkIdList::New(); + this->GeometricEntitiesToRemove = vtkIdList::New(); this->PreviousMaterialsOfGeometricEntities = vtkIdList::New(); } @@ -39,6 +40,11 @@ vtkMaterialOperatorBase::~vtkMaterialOperatorBase() this->GeometricEntitiesToAdd->Delete(); this->GeometricEntitiesToAdd = 0; } + if(this->GeometricEntitiesToRemove) + { + this->GeometricEntitiesToRemove->Delete(); + this->GeometricEntitiesToRemove = 0; + } if(this->PreviousMaterialsOfGeometricEntities) { this->PreviousMaterialsOfGeometricEntities->Delete(); @@ -98,6 +104,24 @@ void vtkMaterialOperatorBase::ClearGeometricEntitiesToAdd() this->GeometricEntitiesToAdd->Reset(); } +void vtkMaterialOperatorBase::RemoveModelGeometricEntity( + vtkIdType GeometricEntityId) +{ + this->GeometricEntitiesToRemove->InsertUniqueId(GeometricEntityId); +} + +void vtkMaterialOperatorBase::RemoveModelGeometricEntity( + vtkModelGeometricEntity* GeometricEntity) +{ + this->RemoveModelGeometricEntity(GeometricEntity->GetUniquePersistentId()); +} + +void vtkMaterialOperatorBase::ClearGeometricEntitiesToRemove() +{ + this->GeometricEntitiesToRemove->Reset(); +} + + bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model) { if(!this->AbleToOperate(Model)) @@ -107,8 +131,6 @@ bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model) vtkModelMaterial* Material = this->GetMaterial(Model); this->PreviousMaterialsOfGeometricEntities->Reset(); - this->PreviousMaterialsOfGeometricEntities->SetNumberOfIds( - this->GeometricEntitiesToAdd->GetNumberOfIds()); for(vtkIdType i=0;iGeometricEntitiesToAdd->GetNumberOfIds();i++) { @@ -127,19 +149,42 @@ bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model) GeometricEntity = Face; } } - if(GeometricEntity) + if(GeometricEntity && GeometricEntity->GetMaterial() != Material) { vtkModelMaterial* PreviousMaterial = GeometricEntity->GetMaterial(); - this->PreviousMaterialsOfGeometricEntities->SetId( - i, PreviousMaterial->GetUniquePersistentId()); + if(PreviousMaterial) + this->PreviousMaterialsOfGeometricEntities->InsertUniqueId( + PreviousMaterial->GetUniquePersistentId()); Material->AddModelGeometricEntity(vtkModelGeometricEntity::SafeDownCast(Entity)); } + } + // remove entities + for(vtkIdType i=0;iGeometricEntitiesToRemove->GetNumberOfIds();i++) + { + vtkModelEntity* Entity = Model->GetModelEntity(this->GeometricEntitiesToRemove->GetId(i)); + vtkDiscreteModelGeometricEntity* GeometricEntity = 0; + vtkDiscreteModelRegion* Region = vtkDiscreteModelRegion::SafeDownCast(Entity); + if(Region) + { + GeometricEntity = Region; + } else { - this->PreviousMaterialsOfGeometricEntities->SetId(i, -1); + vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Entity); + if(Face && Face->GetModelRegion(0) == NULL && Face->GetModelRegion(1) == NULL) + { // Face can have a material associated with it since it is not associated with a region + GeometricEntity = Face; + } + } + if(GeometricEntity) + { + vtkModelMaterial* PreviousMaterial = GeometricEntity->GetMaterial(); + if(PreviousMaterial == Material) + Material->RemoveModelGeometricEntity(vtkModelGeometricEntity::SafeDownCast(Entity)); } } + return this->Superclass::Operate(Model); } diff --git a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h index bb8ef3ccb5..c148f62eff 100644 --- a/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h +++ b/smtk/bridge/discrete/operation/vtkMaterialOperatorBase.h @@ -68,6 +68,13 @@ class SMTKDISCRETESESSION_EXPORT vtkMaterialOperatorBase : public vtkModelEntity // Get the list of GeometricEntitiesToAdd. vtkGetObjectMacro(GeometricEntitiesToAdd, vtkIdList); + // Description: + // Remove Entities. This is not present in V3 + void ClearGeometricEntitiesToRemove(); + void RemoveModelGeometricEntity(vtkIdType GeometricEntityId); + void RemoveModelGeometricEntity(vtkModelGeometricEntity* GeometricEntity); + vtkGetObjectMacro(GeometricEntitiesToRemove, vtkIdList); + // Description: // Get the list of PreviousMaterialsOfGeometricEntities. vtkGetObjectMacro(PreviousMaterialsOfGeometricEntities, vtkIdList); @@ -101,8 +108,9 @@ class SMTKDISCRETESESSION_EXPORT vtkMaterialOperatorBase : public vtkModelEntity void operator=(const vtkMaterialOperatorBase&); // Not implemented. // Description: - // A list of vtkModelGeometricEntitys to add. + // A list of vtkModelGeometricEntitys to add/remove. vtkIdList* GeometricEntitiesToAdd; + vtkIdList* GeometricEntitiesToRemove; // Description: // A list of the old materials that each vtkModelGeometricEntity From ea23ccb2efe1639312fdc1f80c1b377e16f533e3 Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Mon, 20 Apr 2015 12:31:50 -0400 Subject: [PATCH 4/5] Refactor EntityGroupOp in discrete to also handle volome. In ModelBuilder-v3, there is a vtkModelMaterial class and its operator class, vtkMaterialOperator. Essentially this is a partitioned group, meaning entities can only belong to one group (in V3, the group is called Domain set, which is normally associated with material type of attributes). In this commit, we brought back the vtkMaterialOperator, so that users can create group of volumes (3d) or group of faces (2d), then associate (material) attribute to them. However, ideally we should have a univeral group op across all sessions to cluster entities, and then these groups can be used for attribute associations. --- smtk/bridge/discrete/Session.cxx | 32 +- .../operators/EntityGroupOperator.cxx | 277 ++++++++++++------ .../discrete/operators/EntityGroupOperator.h | 10 +- .../operators/EntityGroupOperator.sbt | 18 +- 4 files changed, 233 insertions(+), 104 deletions(-) diff --git a/smtk/bridge/discrete/Session.cxx b/smtk/bridge/discrete/Session.cxx index 007f8df543..df31056f76 100644 --- a/smtk/bridge/discrete/Session.cxx +++ b/smtk/bridge/discrete/Session.cxx @@ -827,6 +827,14 @@ smtk::model::Group Session::addMaterialToManager( { // Add material relations and arrangements translated |= smtk::model::SESSION_ENTITY_ARRANGED; + if (material->GetNumberOfAssociations(vtkModelRegionType)) + { // Add regions to material + this->addEntities(result, material->NewIterator(vtkModelRegionType), AddEntityToGroupHelper(), relDepth - 1); + } + else if(material->GetNumberOfAssociations(vtkModelFaceType)) + { // Add faces to material group + this->addEntities(result, material->NewIterator(vtkModelFaceType), AddEntityToGroupHelper(), relDepth - 1); + } } // Add material properties: @@ -1091,20 +1099,24 @@ smtk::model::Volume Session::addVolumeToManager( smtk::model::ManagerPtr mgr, int relDepth) { - if (refVolume && !mgr->findEntity(uid, false)) + if (refVolume) { - smtk::model::Volume result(mgr->insertVolume(uid)); - smtk::model::SessionInfoBits translated = smtk::model::SESSION_NOTHING; - if (relDepth >= 0) + smtk::model::Volume result; + // if there is a Volume already for refVolume, return it; otherwise, create one + if(mgr->findEntity(uid, false)) + result = smtk::model::Volume(mgr, uid); + else { - // Add refVolume relations and arrangements - this->addEntities(result, refVolume->NewAdjacentModelFaceIterator(), AddRawRelationHelper(), relDepth - 1); - this->addEntities(result, refVolume->NewIterator(vtkModelShellUseType), AddVolumeUseToVolumeHelper(), relDepth - 1); + result = mgr->insertVolume(uid); + if (relDepth >= 0) + { + // Add refVolume relations and arrangements + this->addEntities(result, refVolume->NewAdjacentModelFaceIterator(), AddRawRelationHelper(), relDepth - 1); + this->addEntities(result, refVolume->NewIterator(vtkModelShellUseType), AddVolumeUseToVolumeHelper(), relDepth - 1); + } + this->addProperties(result, refVolume); } - this->addProperties(result, refVolume); - translated |= smtk::model::SESSION_PROPERTIES; - return result; } return smtk::model::Volume(); diff --git a/smtk/bridge/discrete/operators/EntityGroupOperator.cxx b/smtk/bridge/discrete/operators/EntityGroupOperator.cxx index 087142736d..821dc34567 100644 --- a/smtk/bridge/discrete/operators/EntityGroupOperator.cxx +++ b/smtk/bridge/discrete/operators/EntityGroupOperator.cxx @@ -23,7 +23,9 @@ #include "vtkDiscreteModel.h" #include "vtkDiscreteModelEntityGroup.h" #include "vtkDiscreteModelWrapper.h" +#include "vtkIdList.h" #include "vtkModel.h" +#include "vtkModelMaterial.h" #include "EntityGroupOperator_xml.h" @@ -64,15 +66,37 @@ bool EntityGroupOperator::ableToOperate() std::string optype = optypeItem->value(); // if(optype == "Create") //only need model; if(optype == "Remove") - able2Op = this->fetchCMBCellId("remove cell group") >= 0; + able2Op = this->fetchCMBCell("remove cell group") != NULL; else if(optype == "Modify") - able2Op = this->fetchCMBCellId("modify cell group") >= 0 && ( - this->fetchCMBCellId("cell to add") >= 0 || - this->fetchCMBCellId("cell to remove") >= 0 ); + able2Op = this->fetchCMBCell("modify cell group") != NULL && ( + this->fetchCMBCell("cell to add") || + this->fetchCMBCell("cell to remove") ); return able2Op; } +int EntityGroupOperator::createBoundaryGroup(vtkDiscreteModelWrapper* modelWrapper) +{ + int entType = modelWrapper->GetModel()->GetModelDimension() == 3 ? + vtkModelFaceType : + (modelWrapper->GetModel()->GetModelDimension() == 2 ? + vtkModelEdgeType : -1); + if (entType == -1) + return -1; + + this->m_opBoundary->SetBuildEnityType(entType); + this->m_opBoundary->Build(modelWrapper); + int grpId = this->m_opBoundary->GetBuiltModelEntityGroupId(); + return grpId; +} + +int EntityGroupOperator::createDomainSet(vtkDiscreteModelWrapper* modelWrapper) +{ + this->m_opDomain->Build(modelWrapper); + int dsId = this->m_opDomain->GetBuiltMaterialId(); + return dsId; +} + OperatorResult EntityGroupOperator::operateInternal() { smtk::model::ManagerPtr pstore = this->manager(); @@ -84,6 +108,7 @@ OperatorResult EntityGroupOperator::operateInternal() opsession->findModelEntity(model.entity()); bool ok = false; smtk::model::Group bgroup; + smtk::model::EntityRefArray modGrps; smtk::model::EntityRefs grpsRemoved; // Translate SMTK inputs into CMB inputs smtk::attribute::StringItem::Ptr optypeItem = @@ -91,20 +116,30 @@ OperatorResult EntityGroupOperator::operateInternal() std::string optype = optypeItem->value(); if(optype == "Create") //only need model { - int gType = this->specification()->findInt("entity type")->value(); + int gType = this->specification()->findInt("group type")->value(); std::string gName = this->specification()->findString("group name")->value(); - int entType = gType==0 ? vtkModelFaceType : - (gType==1 ? vtkModelEdgeType : vtkModelVertexType); - this->m_op->SetBuildEnityType(entType); - this->m_op->Build(modelWrapper); - int grpId = this->m_op->GetBuiltModelEntityGroupId(); + + int grpId = -1; + if(gType == 0) // boundary group + grpId = this->createBoundaryGroup(modelWrapper); + else if(gType == 1) // domain set + grpId = this->createDomainSet(modelWrapper); ok = grpId>=0; + if(ok) { - BitFlags mask = entType==vtkModelFaceType ? smtk::model::FACE : - (entType==vtkModelEdgeType ? smtk::model::EDGE : smtk::model::VERTEX); - vtkDiscreteModelEntityGroup* grp = dynamic_cast( - modelWrapper->GetModelEntity(vtkDiscreteModelEntityGroupType, grpId)); + BitFlags mask = + // Boundary group, 3d => Face group; 2d => edge group. + (gType == 0) ? + (modelWrapper->GetModel()->GetModelDimension() == 3 ? + smtk::model::FACE : smtk::model::EDGE) : + // Domain set, 3d => volume group; 2d => face group. + (modelWrapper->GetModel()->GetModelDimension() == 3 ? + smtk::model::VOLUME : smtk::model::FACE); + int groupType = gType == 0 ? + vtkDiscreteModelEntityGroupType : vtkModelMaterialType; + vtkModelEntity* grp = + modelWrapper->GetModelEntity(groupType, grpId); smtk::common::UUID grpUUID = opsession->findOrSetEntityUUID(grp); //bgroup = opsession->addGroupToManager(grpUUID, grp, pstore, 0); // The group itself should be added too @@ -115,6 +150,7 @@ OperatorResult EntityGroupOperator::operateInternal() bgroup.setName(gName); // Add group to model's relationship model.addGroup(bgroup); + modGrps.push_back(bgroup); std::cout << "new group: " << bgroup.name() << " id: " << grpUUID.toString() << "\n"; } } @@ -124,74 +160,155 @@ OperatorResult EntityGroupOperator::operateInternal() this->specification()->findModelEntity("remove cell group"); for(std::size_t idx=0; idxnumberOfValues(); idx++) { - int grpid = this->fetchCMBCellId(remgrpItem, idx); - if(grpid >= 0) + vtkModelEntity* modEntity = this->fetchCMBCell(remgrpItem, idx); + if(!modEntity) + continue; + if(modEntity->GetType() == vtkModelMaterialType) { - this->m_op->SetId(grpid); - this->m_op->Destroy(modelWrapper); - ok = this->m_op->GetDestroySucceeded(); - if(ok) - { - // get rid of the group from manager - smtk::model::EntityRef grpRem = remgrpItem->value(idx); - model.removeGroup(grpRem.as()); - pstore->erase(grpRem); - std::cout << "Removed " << grpRem.name() << " to " << model.name() << "\n"; - grpsRemoved.insert(grpRem); - } + this->m_opDomain->SetId(modEntity->GetUniquePersistentId()); + this->m_opDomain->Destroy(modelWrapper); + ok = this->m_opDomain->GetDestroySucceeded(); + } + else if(modEntity->GetType() == vtkDiscreteModelEntityGroupType) + { + this->m_opBoundary->SetId(modEntity->GetUniquePersistentId()); + this->m_opBoundary->Destroy(modelWrapper); + ok = this->m_opBoundary->GetDestroySucceeded(); + } + if(ok) + { + // get rid of the group from manager + smtk::model::EntityRef grpRem = remgrpItem->value(idx); + model.removeGroup(grpRem.as()); + pstore->erase(grpRem); + std::cout << "Removed " << grpRem.name() << " to " << model.name() << "\n"; + grpsRemoved.insert(grpRem); } } - } else if(optype == "Modify") { - int grpId = this->fetchCMBCellId("modify cell group"); - this->m_op->SetId(grpId); - smtk::attribute::ModelEntityItemPtr entItem = - this->specification()->findModelEntity("cell to add"); - for(std::size_t idx=0; idxnumberOfValues(); idx++) + vtkModelEntity* grpEntity = this->fetchCMBCell("modify cell group"); + if(grpEntity && (vtkModelMaterial::SafeDownCast(grpEntity) || + vtkDiscreteModelEntityGroup::SafeDownCast(grpEntity))) { - int cmbid = this->fetchCMBCellId(entItem, idx); - if(cmbid >= 0) - this->m_op->AddModelEntity(cmbid); - } + vtkModelMaterial* grpDS = vtkModelMaterial::SafeDownCast(grpEntity); + vtkDiscreteModelEntityGroup* grpBC = vtkDiscreteModelEntityGroup::SafeDownCast(grpEntity); + if(grpDS) + { + this->m_opDomain->ClearGeometricEntitiesToAdd(); + this->m_opDomain->ClearGeometricEntitiesToRemove(); + this->m_opDomain->SetId(grpEntity->GetUniquePersistentId()); + } + else if(grpBC) + { + this->m_opBoundary->ClearEntitiesToAdd(); + this->m_opBoundary->ClearEntitiesToRemove(); + this->m_opBoundary->SetId(grpEntity->GetUniquePersistentId()); + } + smtk::attribute::ModelEntityItemPtr entItem = + this->specification()->findModelEntity("cell to add"); + for(std::size_t idx=0; idxnumberOfValues(); idx++) + { + vtkModelEntity* modEntity = this->fetchCMBCell(entItem, idx); + if(!modEntity) + continue; + if(grpDS) + this->m_opDomain->AddModelGeometricEntity(modEntity->GetUniquePersistentId()); + else if(grpBC) + this->m_opBoundary->AddModelEntity(modEntity->GetUniquePersistentId()); + } - entItem = this->specification()->findModelEntity("cell to remove"); - for(std::size_t idx=0; idxnumberOfValues(); idx++) - { - int cmbid = this->fetchCMBCellId(entItem, idx); - if(cmbid >= 0) - this->m_op->RemoveModelEntity(cmbid); - } - this->m_op->Operate(modelWrapper); - ok = this->m_op->GetOperateSucceeded(); - if(ok) - { - vtkDiscreteModelEntityGroup* grp = dynamic_cast( - modelWrapper->GetModelEntity(vtkDiscreteModelEntityGroupType, grpId)); - // get rid of the group from manager - smtk::model::EntityRef grpC = - this->specification()->findModelEntity("modify cell group")->value(); - smtk::model::Group tmpGrp = grpC.as(); - BitFlags mask = tmpGrp.membershipMask(); - std::string gName = tmpGrp.name(); - model.removeGroup(tmpGrp); - pstore->erase(grpC); - -// bgroup = opsession->addGroupToManager(grpC.entity(), grp, pstore, true); - smtk::common::UUID grpUUID = opsession->findOrSetEntityUUID(grp); - // The group itself should be added too - grpC = opsession->addCMBEntityToManager( - grpUUID, grp, pstore, 1); - bgroup = grpC.as(); - bgroup.setMembershipMask(mask); - bgroup.setName(gName); + entItem = this->specification()->findModelEntity("cell to remove"); + for(std::size_t idx=0; idxnumberOfValues(); idx++) + { + vtkModelEntity* modEntity = this->fetchCMBCell(entItem, idx); + if(!modEntity) + continue; + if(grpDS) + this->m_opDomain->RemoveModelGeometricEntity(modEntity->GetUniquePersistentId()); + else if(grpBC) + this->m_opBoundary->RemoveModelEntity(modEntity->GetUniquePersistentId()); + } - // Add group to model's relationship - model.addGroup(bgroup); + if(grpDS) + { + this->m_opDomain->Operate(modelWrapper); + ok = this->m_opDomain->GetOperateSucceeded(); + } + else if(grpBC) + { + this->m_opBoundary->Operate(modelWrapper); + ok = this->m_opBoundary->GetOperateSucceeded(); + } - std::cout << "Modified " << grpC.name() << " in " << model.name() << "\n"; + if(ok) + { + // get rid of the group from manager + smtk::model::EntityRef grpC = + this->specification()->findModelEntity("modify cell group")->value(); + smtk::model::Group tmpGrp = grpC.as(); + + BitFlags mask = tmpGrp.membershipMask(); + std::string gName = tmpGrp.name(); + model.removeGroup(tmpGrp); + pstore->erase(grpC); + + smtk::common::UUID grpUUID = opsession->findOrSetEntityUUID(grpEntity); + // The group itself should be added too + grpC = opsession->addCMBEntityToManager( + grpUUID, grpEntity, pstore, 1); + bgroup = grpC.as(); + bgroup.setMembershipMask(mask); + bgroup.setName(gName); + + // Add group to model's relationship + model.addGroup(bgroup); + modGrps.push_back(bgroup); + + // if we are dealing with domain set, the entities can only belong + // to one vtkModelMaterial, and the vtkMaterialOperator will remove + // the relationship to previous materials from input entities. + // Therefore, we need to put the previous materials in "modified" + // item in result. + if(grpDS) + { + vtkIdList* prevMaterials = this->m_opDomain-> + GetPreviousMaterialsOfGeometricEntities(); + for(int i=0; iGetNumberOfIds();i++) + { + vtkModelEntity* matEntity = modelWrapper->GetModelEntity( + vtkModelMaterialType, prevMaterials->GetId(i)); + smtk::common::UUID prevGrpId = opsession->findOrSetEntityUUID(matEntity); + smtk::model::EntityRef prevGrpRef(pstore, prevGrpId); + smtk::model::Group prevGrp = prevGrpRef.as(); + if(!prevGrp.isValid()) + continue; + + BitFlags prevMask = prevGrp.membershipMask(); + std::string prevName = prevGrp.name(); + model.removeGroup(prevGrp); + pstore->erase(prevGrp); + + prevGrpId = opsession->findOrSetEntityUUID(matEntity); + // The group itself should be added too + smtk::model::EntityRef grpPrev = opsession->addCMBEntityToManager( + prevGrpId, matEntity, pstore, 1); + smtk::model::Group tmpgroup = grpPrev.as(); + tmpgroup.setMembershipMask(prevMask); + tmpgroup.setName(prevName); + + // Add group to model's relationship + model.addGroup(tmpgroup); + modGrps.push_back(tmpgroup); + + } + } + + std::cout << "Modified " << grpC.name() << " in " << model.name() << "\n"; + } } + } OperatorResult result = @@ -205,8 +322,8 @@ OperatorResult EntityGroupOperator::operateInternal() // Return the created or modified group. if(optype == "Create") this->addEntityToResult(result, bgroup, CREATED); - else if(optype == "Modify") - this->addEntityToResult(result, bgroup, MODIFIED); + else if(optype == "Modify" && modGrps.size() > 0) + this->addEntitiesToResult(result, modGrps, MODIFIED); } if(optype == "Remove" && grpsRemoved.size() > 0) { @@ -231,30 +348,24 @@ Session* EntityGroupOperator::discreteSession() const return dynamic_cast(this->session()); } -int EntityGroupOperator::fetchCMBCellId(const std::string& pname) const +vtkModelEntity* EntityGroupOperator::fetchCMBCell(const std::string& pname) const { vtkModelItem* item = this->discreteSession()->entityForUUID( this->specification()->findModelEntity(pname)->value().entity()); vtkModelEntity* cell = dynamic_cast(item); - if (cell) - return cell->GetUniquePersistentId(); - - return -1; + return cell; } -int EntityGroupOperator::fetchCMBCellId( +vtkModelEntity* EntityGroupOperator::fetchCMBCell( const smtk::attribute::ModelEntityItemPtr& entItem, int idx ) const { vtkModelItem* item = this->discreteSession()->entityForUUID(entItem->value(idx).entity()); vtkModelEntity* cell = dynamic_cast(item); - if (cell) - return cell->GetUniquePersistentId(); - - return -1; + return cell; } } // namespace discrete diff --git a/smtk/bridge/discrete/operators/EntityGroupOperator.h b/smtk/bridge/discrete/operators/EntityGroupOperator.h index e61b7f1fd9..f46b064433 100644 --- a/smtk/bridge/discrete/operators/EntityGroupOperator.h +++ b/smtk/bridge/discrete/operators/EntityGroupOperator.h @@ -14,6 +14,7 @@ #include "smtk/bridge/discrete/discreteSessionExports.h" #include "smtk/model/Operator.h" #include "vtkModelEntityGroupOperator.h" +#include "vtkMaterialOperator.h" #include "vtkNew.h" namespace smtk { @@ -43,11 +44,14 @@ class SMTKDISCRETESESSION_EXPORT EntityGroupOperator : public smtk::model::Opera EntityGroupOperator(); virtual smtk::model::OperatorResult operateInternal(); Session* discreteSession() const; - int fetchCMBCellId(const std::string& parameterName) const; - int fetchCMBCellId( + vtkModelEntity* fetchCMBCell(const std::string& parameterName) const; + vtkModelEntity* fetchCMBCell( const smtk::attribute::ModelEntityItemPtr&, int idx ) const; + int createBoundaryGroup(vtkDiscreteModelWrapper* modelWrapper); + int createDomainSet(vtkDiscreteModelWrapper* modelWrapper); - vtkNew m_op; + vtkNew m_opBoundary; + vtkNew m_opDomain; }; } // namespace discrete diff --git a/smtk/bridge/discrete/operators/EntityGroupOperator.sbt b/smtk/bridge/discrete/operators/EntityGroupOperator.sbt index 7e14abd3f9..446cb5480a 100644 --- a/smtk/bridge/discrete/operators/EntityGroupOperator.sbt +++ b/smtk/bridge/discrete/operators/EntityGroupOperator.sbt @@ -22,17 +22,19 @@ group --> - face|edge|vertex + volume|face|edge - face|edge|vertex + volume|face|edge - - EnityType that new built group will contain + + Group type for the discrete model kernel: + Boundary group (face or edge) is not partitioned, meaning each entity can belong to multiple boundary groups; + Domain group (volume or face) is partitioned, meaning each entity will only belong to one domain group. + - 0 - 1 - 2 + 0 + 1 @@ -44,8 +46,8 @@ Create + group type group name - entity type From 55a6c39c2a676f0885bbc88003491f92252ea36a Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Mon, 20 Apr 2015 12:42:45 -0400 Subject: [PATCH 5/5] Added logic to make sure newly created indices are visible --- smtk/extension/qt/qtEntityItemModel.cxx | 12 +++++++++--- smtk/extension/qt/qtEntityItemModel.h | 1 + smtk/extension/qt/qtModelView.cxx | 11 +++++++++++ smtk/extension/qt/qtModelView.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/smtk/extension/qt/qtEntityItemModel.cxx b/smtk/extension/qt/qtEntityItemModel.cxx index 1ebd569ff9..7828f6cc0a 100644 --- a/smtk/extension/qt/qtEntityItemModel.cxx +++ b/smtk/extension/qt/qtEntityItemModel.cxx @@ -146,7 +146,7 @@ QModelIndex QEntityItemModel::index(int row, int column, const QModelIndex& owne DescriptivePhrasePtr ownerPhrase = this->getItem(owner); std::string entName = ownerPhrase->relatedEntity().name(); - std::cout << "Owner index for: " << entName << std::endl; +// std::cout << "Owner index for: " << entName << std::endl; DescriptivePhrases& subphrases(ownerPhrase->subphrases()); if (row >= 0 && row < static_cast(subphrases.size())) { @@ -696,7 +696,7 @@ inline void _internal_findAllExistingPhrases( if (modEnts->has((*it)->relatedEntity())) { modifiedPhrases.push_back(*it); - return; // stop searching siblings + continue; // skip Descending } // Descend @@ -779,7 +779,13 @@ void QEntityItemModel::addChildPhrases( } else */ - emit dataChanged(qidx, qidx); + emit dataChanged(qidx, qidx); + if(newDphrs.size() > 0) + { + QModelIndex lastnewChild = qidx.child(row, 0); + // give view an opportunity to scroll to the new child + emit newIndexAdded(lastnewChild); + } } void QEntityItemModel::removeChildPhrases( diff --git a/smtk/extension/qt/qtEntityItemModel.h b/smtk/extension/qt/qtEntityItemModel.h index 31230daa25..f5cc47cd45 100644 --- a/smtk/extension/qt/qtEntityItemModel.h +++ b/smtk/extension/qt/qtEntityItemModel.h @@ -114,6 +114,7 @@ class QTSMTK_EXPORT QEntityItemModel : public QAbstractItemModel signals: void phraseTitleChanged(const QModelIndex&); + void newIndexAdded(const QModelIndex & newidx); protected: smtk::model::DescriptivePhrasePtr m_root; diff --git a/smtk/extension/qt/qtModelView.cxx b/smtk/extension/qt/qtModelView.cxx index 9de2daa256..6376d575b9 100644 --- a/smtk/extension/qt/qtModelView.cxx +++ b/smtk/extension/qt/qtModelView.cxx @@ -106,6 +106,9 @@ qtModelView::qtModelView(QWidget* p) QObject::connect(qmodel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)), Qt::QueuedConnection); + QObject::connect(qmodel, + SIGNAL(newIndexAdded(const QModelIndex&)), + this, SLOT(newIndexAdded(const QModelIndex&)), Qt::QueuedConnection); } @@ -361,6 +364,14 @@ void qtModelView::selectionChanged ( emit this->entitiesSelected(selentityrefs); } +//----------------------------------------------------------------------------- +// when the dataChanged is emitted from the model, we want to scroll to +// that index so that the changes are visible in the tree view. +void qtModelView::newIndexAdded(const QModelIndex & newidx) +{ + this->scrollTo(newidx); +} + //---------------------------------------------------------------------------- void qtModelView::recursiveSelect (smtk::model::DescriptivePhrasePtr dPhrase, smtk::model::EntityRefs& selentityrefs, BitFlags entityFlags, diff --git a/smtk/extension/qt/qtModelView.h b/smtk/extension/qt/qtModelView.h index 6ef8f697cb..604bdfe588 100644 --- a/smtk/extension/qt/qtModelView.h +++ b/smtk/extension/qt/qtModelView.h @@ -101,6 +101,7 @@ protected slots: const smtk::model::SessionRef& session, const smtk::model::Group& grp, const smtk::model::EntityRefs& entities); + virtual void newIndexAdded(const QModelIndex & newidx); protected: // If 'Delete' button is pressed, invoke proper operation if possible.