Commit b871fa9f authored by Haocheng LIU's avatar Haocheng LIU
Browse files

Redesign qtSelectionManager with only one update Selection SLOT

This MR combines the current input selectionManger SLOTs into
one for simplification. SelectionModifier enum can be used to
specify diffferent selection mode. SkipList can be used to specify
which outputport to skip. Meanwhile qtSelectionManager would store
entityRefs instead of UUIDs. UUIDs and multiple outputport signals
would be deprecated in the future.
parent b412e00f
Pipeline #54757 passed with stage
......@@ -473,14 +473,14 @@ void qtAssociationWidget::onEntitySelected()
return;
}
smtk::common::UUIDs selents;
smtk::model::EntityRefs selents;
QList<QListWidgetItem *> selItems = listW->selectedItems();
foreach(QListWidgetItem* currentItem, selItems)
{
smtk::model::EntityRef entref = this->getModelEntityItem(currentItem);
if(entref.isValid())
{
selents.insert(entref.entity());
selents.insert(entref);
}
}
if(selents.size() > 0)
......
......@@ -133,10 +133,13 @@ qtAttributeView::createViewWidget(const ViewInfo &info)
broadcastToAttributeView(const smtk::common::UUIDs&)), view,
SIGNAL(selectionChanged(const smtk::common::UUIDs&)));
view->buildUI();
smtk::common::UUIDs selEntities;
selMgr->getSelectedEntities(selEntities);
smtk::model::EntityRefs selEntities;
selMgr->getSelectedEntitiesAsEntityRefs(selEntities);
//qt 4 signals are private. Just use the slot for update
selMgr->updateSelectedItems(selEntities, smtk::mesh::MeshSets());
selMgr->updateSelectedItems(selEntities, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases(),
smtk::extension::SelectionModifier::SELECTION_REPLACE_UNFILTERED,
smtk::model::StringList());
}
else
{
......@@ -613,10 +616,13 @@ void qtAttributeView::updateSelectionOfEntities()
selectionManager();
if (selMgr)
{
smtk::common::UUIDs selEntities;
selMgr->getSelectedEntities(selEntities);
smtk::model::EntityRefs selEntities;
selMgr->getSelectedEntitiesAsEntityRefs(selEntities);
//qt 4 signals are private. Just use the slot for update
selMgr->updateSelectedItems(selEntities, smtk::mesh::MeshSets());
selMgr->updateSelectedItems(selEntities, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases(),
smtk::extension::SelectionModifier::SELECTION_REPLACE_UNFILTERED,
smtk::model::StringList());
}
}
......
......@@ -18,6 +18,7 @@
#include "smtk/extension/qt/qtBaseView.h"
#include "smtk/extension/qt/qtCheckItemComboBox.h"
#include "smtk/extension/qt/qtUIManager.h"
#include "smtk/extension/qt/qtSelectionManager.h"
#include <QAbstractItemView>
#include <QCheckBox>
......@@ -100,7 +101,12 @@ bool qtModelEntityItem::add(const smtk::model::EntityRef& val)
if (this->modelEntityItem()->appendValue(val))
{
emit this->modified();
emit this->updateSelectionManager(val.entity(),SelectionFlags::Add);
smtk::model::EntityRefs addEntityRefs;
addEntityRefs.insert(val);
emit this->sendSelectionFromModelEntityToSelectionManager(addEntityRefs, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases(), smtk::extension
::SelectionModifier::SELECTION_ADDITION_UNFILTERED,
smtk::model::StringList());
return true;
}
return false;
......@@ -124,7 +130,12 @@ bool qtModelEntityItem::remove(const smtk::model::EntityRef& val)
item->unset(idx);
}
emit this->modified();
emit this->updateSelectionManager(val.entity(),SelectionFlags::Remove);
smtk::model::EntityRefs removeEntityRefs;
removeEntityRefs.insert(val);
emit this->sendSelectionFromModelEntityToSelectionManager(removeEntityRefs, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases(), smtk::extension
::SelectionModifier::SELECTION_SUBTRACTION_UNFILTERED,
smtk::model::StringList());
return true;
}
......@@ -398,7 +409,10 @@ void qtModelEntityItem::clearEntityAssociations()
this->Internals->EntityItemCombo->init();
}
emit this->modified();
emit this->updateSelectionManager(smtk::common::UUID(), SelectionFlags::Clear);
emit this->sendSelectionFromModelEntityToSelectionManager(smtk::model::EntityRefs(), smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases(), smtk::extension
::SelectionModifier::SELECTION_REPLACE_UNFILTERED,
smtk::model::StringList());
}
void qtModelEntityItem::onRequestEntityAssociation()
......
......@@ -18,7 +18,7 @@
#include "smtk/extension/qt/Exports.h"
#include "smtk/extension/qt/qtItem.h"
#include "smtk/model/EntityTypeBits.h" // for smtk::model::BitFlags
#include "smtk/common/UUID.h"
#include "smtk/extension/qt/qtSelectionManager.h"
class qtModelEntityItemInternals;
class QBoxLayout;
......@@ -27,17 +27,12 @@ namespace smtk
{
namespace extension
{
enum class SelectionModifier;
class SMTKQTEXT_EXPORT qtModelEntityItem : public qtItem
{
Q_OBJECT
public:
// Enumeration of SelectionManger flags
enum SelectionFlags {
Add,
Remove,
Clear
};
qtModelEntityItem(smtk::attribute::ItemPtr, QWidget* p,
qtBaseView* bview, Qt::Orientation enumOrient = Qt::Horizontal);
......@@ -59,8 +54,13 @@ namespace smtk
void requestEntityAssociation();
void entityListHighlighted(
const smtk::common::UUIDs& uuids);
void updateSelectionManager(const smtk::common::UUID uuid,
int SelectionFlag);
void sendSelectionFromModelEntityToSelectionManager(
const smtk::model::EntityRefs &selEntities,
const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &DesPhrases,
const smtk::extension::SelectionModifier modifierFlag,
const smtk::model::StringList skipList
);
protected slots:
virtual void updateItemData();
......
......@@ -380,7 +380,12 @@ void qtModelView::selectionChanged (
selproperties, false, &selmeshes);
// update selection manager
emit this->selectionChanged(selentityrefs, selmeshes, selproperties);
smtk::model::StringList skipList;
skipList.push_back(String("model tree"));
emit this->sendSelectionsFromModelViewToSelectionManager(selentityrefs,
selmeshes, selproperties,
smtk::extension::SelectionModifier::SELECTION_REPLACE_UNFILTERED,
smtk::model::StringList());
}
// when the dataChanged is emitted from the model, we want to scroll to
......
......@@ -36,6 +36,7 @@ namespace smtk{
class qtMeshSelectionItem;
class qtModelOperationWidget;
class qtOperatorDockWidget;
enum class SelectionModifier;
class SMTKQTEXT_EXPORT qtModelView : public QTreeView
{
......@@ -105,9 +106,13 @@ namespace smtk{
virtual void onOperationPanelClosing();
signals:
void selectionChanged(const smtk::model::EntityRefs& selEntityRefs,
const smtk::mesh::MeshSets& selmeshes,
const smtk::model::DescriptivePhrases& selproperties);
void sendSelectionsFromModelViewToSelectionManager(
const smtk::model::EntityRefs &selEntities,
const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &DesPhrases,
const smtk::extension::SelectionModifier modifierFlag,
const smtk::model::StringList skipList
);
void operationRequested(const smtk::model::OperatorPtr& brOp);
void operationCancelled(const smtk::model::OperatorPtr& brOp);
......
......@@ -42,7 +42,10 @@ namespace smtk
m_mask |= smtk::model::VERTEX;
this->m_filterMeshes = true;
this->m_modelMgr = nullptr;
this->m_selectionModifier = SelectionModifier::SELECTION_DEFAULT;
this->m_selectionModifier = SelectionModifier::SELECTION_REPLACE_FILTERED;
this->m_skipList.push_back(std::string("rendering window"));
this->m_skipList.push_back(std::string("model tree"));
this->m_skipList.push_back(std::string("attribute panel"));
}
void qtSelectionManager::getSelectedEntities(smtk::common::UUIDs &selEntities)
......@@ -50,117 +53,150 @@ namespace smtk
selEntities = this->m_selEntities;
}
void qtSelectionManager::getSelectedEntitiesAsEntityRefs(smtk::model::EntityRefs &selEntities)
{
selEntities = this->m_selEntityRefs;
}
void qtSelectionManager::getSelectedMeshes(smtk::mesh::MeshSets &selMeshes)
{
selMeshes = this->m_selMeshes;
}
void qtSelectionManager::updateSelectedItems(
const smtk::common::UUIDs &selEntities, const smtk::mesh::MeshSets &selMeshes)
{ // select from render view
if (this->m_selectionModifier == SelectionModifier::SELECTION_DEFAULT)
{ // clear and select
this->clearAllSelections();
this->filterEntitySelectionsByMask(const_cast<smtk::common::UUIDs &>
(selEntities), this->m_selEntities);
if (this->m_filterMeshes)
{
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
}
const smtk::model::EntityRefs &selEntities,
const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &/*DesPhrases*/,
const smtk::extension::SelectionModifier modifierFlag,
const smtk::model::StringList skipList
)
{
// \b selection from qtModelItem/operator dialog
if ( modifierFlag == smtk::extension::SelectionModifier::SELECTION_ADDITION_UNFILTERED)
{
this->m_selEntityRefs.insert(selEntities.begin(), selEntities.end());
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
// Deprecated start
for (auto selEntity: selEntities)
{
this->m_selEntities.insert(selEntity.entity());
}
// Deprecated end
}
else if (this->m_selectionModifier == SelectionModifier::SELECTION_ADDITION)
{ // add to current selection
smtk::common::UUIDs currentSelFiltered;
this->filterEntitySelectionsByMask(const_cast<smtk::common::UUIDs &>
(selEntities), currentSelFiltered);
this->m_selEntities.insert(currentSelFiltered.begin(), currentSelFiltered.end());
if (this->m_filterMeshes)
{
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
}
else if ( modifierFlag == smtk::extension::SelectionModifier::SELECTION_SUBTRACTION_UNFILTERED)
{
this->m_selEntityRefs.erase(selEntities.begin(), selEntities.end());
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
// Deprecated start
for (auto selEntity: selEntities)
{
this->m_selEntities.erase(selEntity.entity());
}
// Deprecated end
}
else
{ //subtract from current selection
smtk::common::UUIDs currentSelFiltered;
this->filterEntitySelectionsByMask(const_cast<smtk::common::UUIDs &>
(selEntities), currentSelFiltered);
for (const auto& selEnt: currentSelFiltered)
else if ( modifierFlag == smtk::extension::SelectionModifier::SELECTION_REPLACE_UNFILTERED)
{
// \b clear selection in qtModelItem/opeartor dialog
// \b selection from model tree
// \b selection from attribue panel
this->clearAllSelections();
this->m_selEntityRefs.insert(selEntities.begin(), selEntities.end());
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
// Deprecated start
for (auto selEntity: selEntities)
{
this->m_selEntities.erase(selEnt);
this->m_selEntities.insert(selEntity.entity());
}
// Deprecated end
}
if (this->m_filterMeshes)
{
for (const auto& selMesh: selMeshes)
// \b selection from render window
else if (modifierFlag == smtk::extension::SelectionModifier::SELECTION_INQUIRY)
{
if (this->m_selectionModifier == SelectionModifier::SELECTION_REPLACE_FILTERED)
{ // clear and select
this->clearAllSelections();
this->filterEntitySelectionsByMask(const_cast<smtk::model::EntityRefs &>
(selEntities), this->m_selEntityRefs);
if (this->m_filterMeshes)
{
this->m_selMeshes.erase(selMesh);
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
}
// Deprecated start
for (auto selEntity: this->m_selEntityRefs)
{
this->m_selEntities.insert(selEntity.entity());
}
}
// Deprecated end
}
else if (this->m_selectionModifier == SelectionModifier::SELECTION_ADDITION_FILTERED)
{ // add to current selection
smtk::model::EntityRefs currentSelFiltered;
this->filterEntitySelectionsByMask(const_cast<smtk::model::EntityRefs &>
(selEntities), currentSelFiltered);
this->m_selEntityRefs.insert(currentSelFiltered.begin(), currentSelFiltered.end());
this->m_selectionModifier = SelectionModifier::SELECTION_DEFAULT; // reset
if (this->m_filterMeshes)
{
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
}
// Deprecated start
for (auto selEntity: currentSelFiltered)
{
this->m_selEntities.insert(selEntity.entity());
}
// Deprecated end
}
else if (this->m_selectionModifier == SelectionModifier::SELECTION_SUBTRACTION_FILTERED)
{ //subtract from current selection
smtk::model::EntityRefs currentSelFiltered;
this->filterEntitySelectionsByMask(const_cast<smtk::model::EntityRefs &>
(selEntities), currentSelFiltered);
for (const auto& selEnt: currentSelFiltered)
{
// Deprecatred start
this->m_selEntities.erase(selEnt.entity());
// Deprecatred end
this->m_selEntityRefs.erase(selEnt);
}
emit broadcastToModelTree(this->m_selEntities,this->m_selMeshes,
true);
emit broadcastToAttributeView(this->m_selEntities);
emit broadcastToRenderView(this->m_selEntities,this->m_selMeshes,smtk::model::DescriptivePhrases());
}
if (this->m_filterMeshes)
{
for (const auto& selMesh: selMeshes)
{
this->m_selMeshes.erase(selMesh);
}
}
}
void qtSelectionManager::updateSelectedItems(const smtk::model::EntityRefs
&selEntities, const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &DesPhrases)
this->m_selectionModifier = SelectionModifier::SELECTION_REPLACE_FILTERED; // reset
{ // select from model tree
this->clearAllSelections();
for (smtk::model::EntityRefs::iterator it = selEntities.begin();
it != selEntities.end(); ++it)
{
this->m_selEntities.insert(it->entity());
}
this->m_selMeshes.insert(selMeshes.begin(),selMeshes.end());
this->m_desPhrases = DesPhrases;
emit broadcastToRenderView(selEntities, selMeshes, DesPhrases);
emit broadcastToAttributeView(this->m_selEntities);
}
void qtSelectionManager::updateSelectedItems(const smtk::common::UUIDs
&selEntities)
{ // select from attribute panel
this->clearAllSelections();
this->m_selEntities.insert(selEntities.begin(), selEntities.end());
// broadcast to model tree and render view
emit broadcastToModelTree(this->m_selEntities,smtk::mesh::MeshSets(),
true);
emit broadcastToRenderView(this->m_selEntities, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases());
}
void qtSelectionManager::updateSelectedItem(const smtk::common::UUID
&selEntity, int SelectionFlags)
{
// select from qtModelItem/operator dialog
if ( SelectionFlags == smtk::extension::qtModelEntityItem::SelectionFlags::Add)
// broadcast to rendering view, model tree and attribute panel if they are
// not in skipList
// TODO: Since we want to use surface representation for faces, we have to
// update render view again to use our settings of pqDataRepresentation
// *true* should be removed
if (true || std::find(skipList.begin(), skipList.end(), this->m_skipList[0])
== skipList.end())
{
this->m_selEntities.insert(selEntity);
emit broadcastToRenderView(this->m_selEntities, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases());
}
else if( SelectionFlags == smtk::extension::qtModelEntityItem::SelectionFlags::Remove)
if (std::find(skipList.begin(), skipList.end(), this->m_skipList[1])
== skipList.end())
{
this->m_selEntities.erase(selEntity);
emit broadcastToModelTree(this->m_selEntities,smtk::mesh::MeshSets(),
true);
}
else if( SelectionFlags == smtk::extension::qtModelEntityItem::SelectionFlags::Clear)
if (std::find(skipList.begin(), skipList.end(), this->m_skipList[2])
== skipList.end())
{
this->clearAllSelections();
emit broadcastToAttributeView(this->m_selEntities);
}
// broadcast to model tree and render view
emit broadcastToModelTree(this->m_selEntities,smtk::mesh::MeshSets(),
true);
emit broadcastToRenderView(this->m_selEntities, smtk::mesh::MeshSets(),
smtk::model::DescriptivePhrases());
emit broadcastToAttributeView(this->m_selEntities);
}
void qtSelectionManager::filterModels(bool checked)
......@@ -205,31 +241,32 @@ namespace smtk
void qtSelectionManager::clearAllSelections()
{
this->m_selEntities.clear();
this->m_selEntityRefs.clear();
this->m_selMeshes.clear();
this->m_desPhrases.clear();
}
void qtSelectionManager::filterEntitySelectionsByMask(
smtk::common::UUIDs &currentSelEnt, smtk::common::UUIDs &filteredSelEnt)
smtk::model::EntityRefs &inputEnts, smtk::model::EntityRefs &filteredSelEnts)
{
filteredSelEnt.clear();
// For now rubber band selection only support F/E/V
for(smtk::common::UUIDs::iterator uuid = currentSelEnt.begin(); uuid != currentSelEnt.end(); uuid++)
filteredSelEnts.clear();
// For now rubber band selection only support F/E/V and group
for(smtk::model::EntityRefs::iterator inputEnt = inputEnts.begin(); inputEnt != inputEnts.end(); inputEnt++)
{
smtk::model::EntityRef ent = smtk::model::EntityRef(this->m_modelMgr, *uuid);
smtk::model::EntityRef ent = *inputEnt;
if (this->m_mask & smtk::model::CELL_ENTITY)
{
// check Cell? dimension? match mask?
if ((ent.entityFlags() & smtk::model::CELL_ENTITY) &&
((ent.entityFlags() & smtk::model::ANY_DIMENSION) & this->m_mask))
{
filteredSelEnt.insert(*uuid);
filteredSelEnts.insert(ent);
}
}
if (ent.entityFlags() & smtk::model::GROUP_CONSTRAINT_MASK)
{
filteredSelEnt.insert(*uuid);
filteredSelEnts.insert(ent);
}
// Comment out for now since tessellation for volume and model is not added
......
......@@ -31,30 +31,51 @@ namespace smtk
namespace extension
{
class SMTKQTEXT_EXPORT qtSelectionManager : public QObject
{
public:
enum class SelectionModifier
{
SELECTION_DEFAULT = 0,
SELECTION_ADDITION = 1,
SELECTION_SUBTRACTION = 2
SELECTION_REPLACE_FILTERED = 0, /* !< Replace all the current selection
and filter it. Example user case: normal
selection from rendering window. */
SELECTION_REPLACE_UNFILTERED = 1, /* !< Replace all the current selection
and do not filter it. Example user case: selection
from model tree and attribute panel. */
SELECTION_ADDITION_FILTERED = 2, /* !< Filter the input selection and add it
to the current selection. Example user case:
addition from rendering window. */
SELECTION_ADDITION_UNFILTERED = 3, /* !< Do not filter the input selection
and add it to the current selection.
Example user case: addition from operator dialog. */
SELECTION_SUBTRACTION_FILTERED = 4, /* !< Filter the input selection and
subtract it from the current selection.
Example user case: substraction from rendering window. */
SELECTION_SUBTRACTION_UNFILTERED = 5, /* !< Do not filter the input
selection and sbutract it from the current selection.
Example user case: subtraction from operator dialog. */
SELECTION_INQUIRY = 6 /* !< Use the SelectionModifer defined in
qtSelectionManager. Use it when SelectionModifer is
decided by user input(Ex. different keybindings).
Example user case: rendering window selection addition and subtraction. */
};
class SMTKQTEXT_EXPORT qtSelectionManager : public QObject
{
public:
Q_OBJECT
public:
qtSelectionManager();
void setModelManager(smtk::model::ManagerPtr mgrPtr)
{this->m_modelMgr = mgrPtr;}
void getSelectedEntities(smtk::common::UUIDs &selEntities);
void getSelectedEntitiesAsEntityRefs(smtk::model::EntityRefs &selEntities);
void getSelectedMeshes(smtk::mesh::MeshSets &selMeshes);
void setSelectionModifierToAddition()
{this->m_selectionModifier = SelectionModifier::SELECTION_ADDITION;}
{this->m_selectionModifier = SelectionModifier::SELECTION_ADDITION_FILTERED;}
void setSelectionModifierToSubtraction()
{this->m_selectionModifier = SelectionModifier::SELECTION_SUBTRACTION;}
{this->m_selectionModifier = SelectionModifier::
SELECTION_SUBTRACTION_FILTERED;}
signals:
// Description
......@@ -80,28 +101,21 @@ public:
// Broadcast selection to attrite panel
void broadcastToAttributeView(const smtk::common::UUIDs &
selEntities) const;
public slots:
// Description
// update selected items from rendering window
void updateSelectedItems(const smtk::common::UUIDs &
selEntities, const smtk::mesh::MeshSets &selMeshes);
// Description
// update selected items from model tree
void updateSelectedItems(const smtk::model::EntityRefs&
selEntities, const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &DesPhrases);
// Description
// update selected items from attribute
void updateSelectedItems(const smtk::common::UUIDs & selEntities);
public slots:
// Description
// update selected items from qtModelItem/operator dialog
void updateSelectedItem(const smtk::common::UUID & selEntity, int
SelectionFlags);
// this SLOT is used to update selected items
// SelectionModifer is used to specify how to update selectionManager
// skipList is used to specify which receiver you want to skip. Ex you do
// not want the current selection to update render window since the update
// is coming from render window.
// skiplist: "rendering window", "model tree", "attribute panel"
void updateSelectedItems(const smtk::model::EntityRefs &selEntities,
const smtk::mesh::MeshSets &selMeshes,
const smtk::model::DescriptivePhrases &DesPhrases,
const smtk::extension::SelectionModifier modifierFlag,
const smtk::model::StringList skipList
);
// Description
// update mask for models
......@@ -131,22 +145,25 @@ public:
void clearAllSelections();
// Description
// filter select entitiesa from currentSelEnt and store the result in
// filter select entities from inputSelEnt and store the result in
// filteredSelEnt
void filterEntitySelectionsByMask(
smtk::common::UUIDs &currentSelEnt, smtk::common::UUIDs &filteredSelEnt);
smtk::model::EntityRefs &inputSelEnts, smtk::model::EntityRefs &filteredSelEnts);
// Description
// filter selection to handle mask other than F/E/V
void filterRubberBandSelection(smtk::model::EntityRef ent);
smtk::mesh::MeshSets m_selMeshes;
smtk::common::UUIDs m_selEntities;
smtk::common::UUIDs m_selEntities; // Deprecate it with m_selEntityRefs
smtk::model::EntityRefs m_selEntityRefs;