From 1803052ba948e1ade58db3d42eda9699e640231b Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Mon, 30 Sep 2013 15:07:22 +0200 Subject: [PATCH] mutually exclusive cell selectors --- .../forms/surface_deformation.ui | 38 ++++----- .../src/surface_selection.cpp | 42 +++++----- SCHNApps/include/cellSelector.h | 79 ++++++++++++++----- SCHNApps/include/controlDock_mapTab.h | 1 + SCHNApps/include/mapHandler.h | 2 + SCHNApps/src/cellSelector.cpp | 4 +- SCHNApps/src/controlDock_mapTab.cpp | 74 +++++++++-------- SCHNApps/src/mapHandler.cpp | 14 +++- SCHNApps/src/view.cpp | 2 +- 9 files changed, 156 insertions(+), 100 deletions(-) diff --git a/SCHNApps/Plugins/surface_deformation/forms/surface_deformation.ui b/SCHNApps/Plugins/surface_deformation/forms/surface_deformation.ui index 7430c240..e6be71d8 100644 --- a/SCHNApps/Plugins/surface_deformation/forms/surface_deformation.ui +++ b/SCHNApps/Plugins/surface_deformation/forms/surface_deformation.ui @@ -33,7 +33,7 @@ - Free selector : + Free vertices selector : @@ -59,6 +59,22 @@ + + + + Start + + + + + + + + - select selector - + + + + @@ -72,29 +88,13 @@ - - - - Start - - - - + - Handle selector : + Handle vertices selector : - - - - - - select selector - - - - - diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index 077f3aa4..808aecab 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -81,26 +81,26 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) m_drawer->vertex(p.positionAttribute[*it]); m_drawer->end(); m_drawer->endList(); - } - } - if(m_selecting) - { - std::vector selectionPoint; - selectionPoint.push_back(m_selectionCenter); - m_selectionSphereVBO->updateData(selectionPoint); - - m_pointSprite->setAttributePosition(m_selectionSphereVBO); - m_pointSprite->setSize(m_selectionRadius); - m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f)); - m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); - - m_pointSprite->enableVertexAttribs(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDrawArrays(GL_POINTS, 0, 1); - glDisable(GL_BLEND); - m_pointSprite->disableVertexAttribs(); + if(m_selecting) + { + std::vector selectionPoint; + selectionPoint.push_back(m_selectionCenter); + m_selectionSphereVBO->updateData(selectionPoint); + + m_pointSprite->setAttributePosition(m_selectionSphereVBO); + m_pointSprite->setSize(m_selectionRadius); + m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f)); + m_pointSprite->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f)); + + m_pointSprite->enableVertexAttribs(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDrawArrays(GL_POINTS, 0, 1); + glDisable(GL_BLEND); + m_pointSprite->disableVertexAttribs(); + } + } } } } @@ -111,7 +111,7 @@ void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event) { view->setMouseTracking(true); m_selecting = true; -// view->updateGL(); + view->updateGL(); } } @@ -121,7 +121,7 @@ void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event) { view->setMouseTracking(false); m_selecting = false; -// view->updateGL(); + view->updateGL(); } } diff --git a/SCHNApps/include/cellSelector.h b/SCHNApps/include/cellSelector.h index ff85c1d1..54556348 100644 --- a/SCHNApps/include/cellSelector.h +++ b/SCHNApps/include/cellSelector.h @@ -1,14 +1,14 @@ #ifndef _CELL_SELECTOR_H_ #define _CELL_SELECTOR_H_ +#include #include +#include #include "Topology/generic/dart.h" #include "Topology/generic/genericmap.h" #include "Topology/generic/cellmarker.h" -#include - namespace CGoGN { @@ -35,27 +35,69 @@ public: virtual void select(Dart d, bool emitSignal) = 0; virtual void unselect(Dart d, bool emitSignal) = 0; - virtual void select(const std::vector& d) = 0; - virtual void unselect(const std::vector& d) = 0; + inline void select(const std::vector& d) + { + for(unsigned int i = 0; i < d.size(); ++i) + select(d[i], false); + checkChange(); + if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty()) + { + foreach(CellSelectorGen* cs, m_mutuallyExclusive) + cs->checkChange(); + } + } + + inline void unselect(const std::vector& d) + { + for(unsigned int i = 0; i < d.size(); ++i) + unselect(d[i], false); + checkChange(); + } virtual bool isSelected(Dart d) = 0; + inline void setMutuallyExclusive(bool b) { m_isMutuallyExclusive = b; } + inline bool isMutuallyExclusive() const { return m_isMutuallyExclusive; } + inline void setMutuallyExclusiveSet(const QList& mex) + { + m_mutuallyExclusive.clear(); + foreach(CellSelectorGen* cs, mex) + { + if(cs != this) + m_mutuallyExclusive.append(cs); + } + } + + inline void checkChange() + { + if(m_selectionChanged) + { + emit(selectedCellsChanged()); + m_selectionChanged = false; + } + } + signals: void selectedCellsChanged(); protected: QString m_name; std::vector m_cells; + + bool m_selectionChanged; + + bool m_isMutuallyExclusive; + QList m_mutuallyExclusive; }; template class CellSelector : public CellSelectorGen { public: - CellSelector(GenericMap& m, const QString& name, unsigned int thread = 0) : + CellSelector(GenericMap& map, const QString& name, unsigned int thread = 0) : CellSelectorGen(name), - m_map(m), - m_cm(m, thread) + m_map(map), + m_cm(map, thread) {} ~CellSelector() @@ -72,8 +114,15 @@ public: { m_cells.push_back(d); m_cm.mark(v); + if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty()) + { + foreach(CellSelectorGen* cs, m_mutuallyExclusive) + cs->unselect(d, emitSignal); + } if(emitSignal) emit(selectedCellsChanged()); + else + m_selectionChanged = true; } } @@ -96,24 +145,12 @@ public: m_cells.pop_back(); if(emitSignal) emit(selectedCellsChanged()); + else + m_selectionChanged = true; } } } - inline void select(const std::vector& d) - { - for(unsigned int i = 0; i < d.size(); ++i) - select(d[i], false); - emit(selectedCellsChanged()); - } - - inline void unselect(const std::vector& d) - { - for(unsigned int i = 0; i < d.size(); ++i) - unselect(d[i], false); - emit(selectedCellsChanged()); - } - inline bool isSelected(Dart d) { return m_cm.isMarked(d); diff --git a/SCHNApps/include/controlDock_mapTab.h b/SCHNApps/include/controlDock_mapTab.h index 0d097f01..2ba43f3a 100644 --- a/SCHNApps/include/controlDock_mapTab.h +++ b/SCHNApps/include/controlDock_mapTab.h @@ -38,6 +38,7 @@ private slots: void vertexAttributeCheckStateChanged(QListWidgetItem* item); void selectedSelectorChanged(); + void selectorCheckStateChanged(QListWidgetItem* item); void addSelector(); void removeSelector(); diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index ac1e9e12..69cca09e 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -152,6 +152,8 @@ public: template CellSelector* getCellSelector(const QString& name) const; + void updateMutuallyExclusiveSelectors(unsigned int orbit); + /********************************************************* * MANAGE LINKED VIEWS *********************************************************/ diff --git a/SCHNApps/src/cellSelector.cpp b/SCHNApps/src/cellSelector.cpp index 58c4bc94..b74f8450 100644 --- a/SCHNApps/src/cellSelector.cpp +++ b/SCHNApps/src/cellSelector.cpp @@ -9,7 +9,9 @@ namespace SCHNApps unsigned int CellSelectorGen::selectorCount = 0; CellSelectorGen::CellSelectorGen(const QString& name) : - m_name(name) + m_name(name), + m_selectionChanged(false), + m_isMutuallyExclusive(false) { ++selectorCount; } diff --git a/SCHNApps/src/controlDock_mapTab.cpp b/SCHNApps/src/controlDock_mapTab.cpp index 2251921e..02e13e49 100644 --- a/SCHNApps/src/controlDock_mapTab.cpp +++ b/SCHNApps/src/controlDock_mapTab.cpp @@ -28,22 +28,27 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) : connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*))); connect(list_dartSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); + connect(list_dartSelectors, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(selectorCheckStateChanged(QListWidgetItem*))); connect(button_dartAddSelector, SIGNAL(clicked()), this, SLOT(addSelector())); connect(button_dartRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(list_vertexSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); + connect(list_vertexSelectors, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(selectorCheckStateChanged(QListWidgetItem*))); connect(button_vertexAddSelector, SIGNAL(clicked()), this, SLOT(addSelector())); connect(button_vertexRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(list_edgeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); + connect(list_edgeSelectors, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(selectorCheckStateChanged(QListWidgetItem*))); connect(button_edgeAddSelector, SIGNAL(clicked()), this, SLOT(addSelector())); connect(button_edgeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(list_faceSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); + connect(list_faceSelectors, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(selectorCheckStateChanged(QListWidgetItem*))); connect(button_faceAddSelector, SIGNAL(clicked()), this, SLOT(addSelector())); connect(button_faceRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(list_volumeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); + connect(list_volumeSelectors, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(selectorCheckStateChanged(QListWidgetItem*))); connect(button_volumeAddSelector, SIGNAL(clicked()), this, SLOT(addSelector())); connect(button_volumeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); } @@ -157,6 +162,20 @@ void ControlDock_MapTab::selectedSelectorChanged() } } +void ControlDock_MapTab::selectorCheckStateChanged(QListWidgetItem* item) +{ + if(!b_updatingUI) + { + if(m_selectedMap) + { + unsigned int orbit = getCurrentOrbit(); + CellSelectorGen* cs = m_selectedMap->getCellSelector(orbit, item->text()); + cs->setMutuallyExclusive(item->checkState() == Qt::Checked); + m_selectedMap->updateMutuallyExclusiveSelectors(orbit); + } + } +} + void ControlDock_MapTab::addSelector() { if(!b_updatingUI) @@ -327,75 +346,60 @@ void ControlDock_MapTab::updateSelectedMapInfo() for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit) { unsigned int nbc = m->getNbCells(orbit); + + QListWidget* selectorList = NULL; + switch(orbit) { case DART : { unsigned int nb = m->getNbDarts(); label_dartNbOrbits->setText(QString::number(nb)); label_dartNbCells->setText(QString::number(nbc)); - foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) - { - QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_dartSelectors); - item->setFlags(item->flags() | Qt::ItemIsEditable); - if(m_selectedSelector[orbit] == cs) - item->setSelected(true); - } + selectorList = list_dartSelectors; break; } case VERTEX : { unsigned int nb = m->getNbOrbits(); label_vertexNbOrbits->setText(QString::number(nb)); label_vertexNbCells->setText(QString::number(nbc)); - foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) - { - QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_vertexSelectors); - item->setFlags(item->flags() | Qt::ItemIsEditable); - if(m_selectedSelector[orbit] == cs) - item->setSelected(true); - } + selectorList = list_vertexSelectors; break; } case EDGE : { unsigned int nb = m->getNbOrbits(); label_edgeNbOrbits->setText(QString::number(nb)); label_edgeNbCells->setText(QString::number(nbc)); - foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) - { - QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_edgeSelectors); - item->setFlags(item->flags() | Qt::ItemIsEditable); - if(m_selectedSelector[orbit] == cs) - item->setSelected(true); - } + selectorList = list_edgeSelectors; break; } case FACE : { unsigned int nb = m->getNbOrbits(); label_faceNbOrbits->setText(QString::number(nb)); label_faceNbCells->setText(QString::number(nbc)); - foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) - { - QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_faceSelectors); - item->setFlags(item->flags() | Qt::ItemIsEditable); - if(m_selectedSelector[orbit] == cs) - item->setSelected(true); - } + selectorList = list_faceSelectors; break; } case VOLUME : { unsigned int nb = m->getNbOrbits(); label_volumeNbOrbits->setText(QString::number(nb)); label_volumeNbCells->setText(QString::number(nbc)); - foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) - { - QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_volumeSelectors); - item->setFlags(item->flags() | Qt::ItemIsEditable); - if(m_selectedSelector[orbit] == cs) - item->setSelected(true); - } + selectorList = list_volumeSelectors; break; } } + foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) + { + QListWidgetItem* item = new QListWidgetItem(cs->getName(), selectorList); + item->setFlags(item->flags() | Qt::ItemIsEditable); + if(m_selectedSelector[orbit] == cs) + item->setSelected(true); + if(cs->isMutuallyExclusive()) + item->setCheckState(Qt::Checked); + else + item->setCheckState(Qt::Unchecked); + } + if(m->isOrbitEmbedded(orbit)) { AttributeContainer& cont = m->getAttributeContainer(orbit); diff --git a/SCHNApps/src/mapHandler.cpp b/SCHNApps/src/mapHandler.cpp index d8c0fc79..5443bbba 100644 --- a/SCHNApps/src/mapHandler.cpp +++ b/SCHNApps/src/mapHandler.cpp @@ -47,9 +47,7 @@ Utils::VBO* MapHandlerGen::createVBO(const AttributeMultiVectorGen* attr) emit(vboAdded(vbo)); } else - { vbo->updateData(attr); - } return vbo; } else @@ -158,6 +156,18 @@ CellSelectorGen* MapHandlerGen::getCellSelector(unsigned int orbit, const QStrin return NULL; } +void MapHandlerGen::updateMutuallyExclusiveSelectors(unsigned int orbit) +{ + QList mex; + foreach(CellSelectorGen* cs, m_cellSelectors[orbit]) + { + if(cs->isMutuallyExclusive()) + mex.append(cs); + } + foreach(CellSelectorGen* cs, m_cellSelectors[orbit]) + cs->setMutuallyExclusiveSet(mex); +} + /********************************************************* * MANAGE LINKED VIEWS *********************************************************/ diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index a3103c76..c11e646c 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -139,7 +139,7 @@ void View::linkMap(MapHandlerGen* map) connect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL())); connect(map, SIGNAL(selectedCellsChanged()), this, SLOT(updateGL())); - if(map == m_schnapps->getSelectedMap()) + if(map->isSelectedMap()) setManipulatedFrame(map->getFrame()); } } -- GitLab