Commit 1803052b authored by Pierre Kraemer's avatar Pierre Kraemer

mutually exclusive cell selectors

parent cb23b33c
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<item row="5" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Free selector :</string> <string>Free vertices selector :</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -59,6 +59,22 @@ ...@@ -59,6 +59,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="button_start_stop">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QComboBox" name="combo_handleSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
<item row="11" column="0" colspan="2"> <item row="11" column="0" colspan="2">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
...@@ -72,29 +88,13 @@ ...@@ -72,29 +88,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="10" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QPushButton" name="button_start_stop">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Handle selector :</string> <string>Handle vertices selector :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2">
<widget class="QComboBox" name="combo_handleSelector">
<item>
<property name="text">
<string>- select selector -</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
......
...@@ -81,26 +81,26 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map) ...@@ -81,26 +81,26 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
m_drawer->vertex(p.positionAttribute[*it]); m_drawer->vertex(p.positionAttribute[*it]);
m_drawer->end(); m_drawer->end();
m_drawer->endList(); m_drawer->endList();
}
}
if(m_selecting) if(m_selecting)
{ {
std::vector<PFP2::VEC3> selectionPoint; std::vector<PFP2::VEC3> selectionPoint;
selectionPoint.push_back(m_selectionCenter); selectionPoint.push_back(m_selectionCenter);
m_selectionSphereVBO->updateData(selectionPoint); m_selectionSphereVBO->updateData(selectionPoint);
m_pointSprite->setAttributePosition(m_selectionSphereVBO); m_pointSprite->setAttributePosition(m_selectionSphereVBO);
m_pointSprite->setSize(m_selectionRadius); m_pointSprite->setSize(m_selectionRadius);
m_pointSprite->setColor(CGoGN::Geom::Vec4f(0.0f, 0.0f, 1.0f, 0.5f)); 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->setLightPosition(CGoGN::Geom::Vec3f(0.0f, 0.0f, 1.0f));
m_pointSprite->enableVertexAttribs(); m_pointSprite->enableVertexAttribs();
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_POINTS, 0, 1); glDrawArrays(GL_POINTS, 0, 1);
glDisable(GL_BLEND); glDisable(GL_BLEND);
m_pointSprite->disableVertexAttribs(); m_pointSprite->disableVertexAttribs();
}
}
} }
} }
} }
...@@ -111,7 +111,7 @@ void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event) ...@@ -111,7 +111,7 @@ void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event)
{ {
view->setMouseTracking(true); view->setMouseTracking(true);
m_selecting = true; m_selecting = true;
// view->updateGL(); view->updateGL();
} }
} }
...@@ -121,7 +121,7 @@ void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event) ...@@ -121,7 +121,7 @@ void Surface_Selection_Plugin::keyRelease(View* view, QKeyEvent* event)
{ {
view->setMouseTracking(false); view->setMouseTracking(false);
m_selecting = false; m_selecting = false;
// view->updateGL(); view->updateGL();
} }
} }
......
#ifndef _CELL_SELECTOR_H_ #ifndef _CELL_SELECTOR_H_
#define _CELL_SELECTOR_H_ #define _CELL_SELECTOR_H_
#include <QObject>
#include <QString> #include <QString>
#include <QList>
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/genericmap.h" #include "Topology/generic/genericmap.h"
#include "Topology/generic/cellmarker.h" #include "Topology/generic/cellmarker.h"
#include <QObject>
namespace CGoGN namespace CGoGN
{ {
...@@ -35,27 +35,69 @@ public: ...@@ -35,27 +35,69 @@ public:
virtual void select(Dart d, bool emitSignal) = 0; virtual void select(Dart d, bool emitSignal) = 0;
virtual void unselect(Dart d, bool emitSignal) = 0; virtual void unselect(Dart d, bool emitSignal) = 0;
virtual void select(const std::vector<Dart>& d) = 0; inline void select(const std::vector<Dart>& d)
virtual void unselect(const std::vector<Dart>& d) = 0; {
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<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
unselect(d[i], false);
checkChange();
}
virtual bool isSelected(Dart d) = 0; 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<CellSelectorGen*>& 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: signals:
void selectedCellsChanged(); void selectedCellsChanged();
protected: protected:
QString m_name; QString m_name;
std::vector<Dart> m_cells; std::vector<Dart> m_cells;
bool m_selectionChanged;
bool m_isMutuallyExclusive;
QList<CellSelectorGen*> m_mutuallyExclusive;
}; };
template <unsigned int ORBIT> template <unsigned int ORBIT>
class CellSelector : public CellSelectorGen class CellSelector : public CellSelectorGen
{ {
public: public:
CellSelector(GenericMap& m, const QString& name, unsigned int thread = 0) : CellSelector(GenericMap& map, const QString& name, unsigned int thread = 0) :
CellSelectorGen(name), CellSelectorGen(name),
m_map(m), m_map(map),
m_cm(m, thread) m_cm(map, thread)
{} {}
~CellSelector() ~CellSelector()
...@@ -72,8 +114,15 @@ public: ...@@ -72,8 +114,15 @@ public:
{ {
m_cells.push_back(d); m_cells.push_back(d);
m_cm.mark(v); m_cm.mark(v);
if(m_isMutuallyExclusive && !m_mutuallyExclusive.empty())
{
foreach(CellSelectorGen* cs, m_mutuallyExclusive)
cs->unselect(d, emitSignal);
}
if(emitSignal) if(emitSignal)
emit(selectedCellsChanged()); emit(selectedCellsChanged());
else
m_selectionChanged = true;
} }
} }
...@@ -96,24 +145,12 @@ public: ...@@ -96,24 +145,12 @@ public:
m_cells.pop_back(); m_cells.pop_back();
if(emitSignal) if(emitSignal)
emit(selectedCellsChanged()); emit(selectedCellsChanged());
else
m_selectionChanged = true;
} }
} }
} }
inline void select(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
select(d[i], false);
emit(selectedCellsChanged());
}
inline void unselect(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
unselect(d[i], false);
emit(selectedCellsChanged());
}
inline bool isSelected(Dart d) inline bool isSelected(Dart d)
{ {
return m_cm.isMarked(d); return m_cm.isMarked(d);
......
...@@ -38,6 +38,7 @@ private slots: ...@@ -38,6 +38,7 @@ private slots:
void vertexAttributeCheckStateChanged(QListWidgetItem* item); void vertexAttributeCheckStateChanged(QListWidgetItem* item);
void selectedSelectorChanged(); void selectedSelectorChanged();
void selectorCheckStateChanged(QListWidgetItem* item);
void addSelector(); void addSelector();
void removeSelector(); void removeSelector();
......
...@@ -152,6 +152,8 @@ public: ...@@ -152,6 +152,8 @@ public:
template <unsigned int ORBIT> template <unsigned int ORBIT>
CellSelector<ORBIT>* getCellSelector(const QString& name) const; CellSelector<ORBIT>* getCellSelector(const QString& name) const;
void updateMutuallyExclusiveSelectors(unsigned int orbit);
/********************************************************* /*********************************************************
* MANAGE LINKED VIEWS * MANAGE LINKED VIEWS
*********************************************************/ *********************************************************/
......
...@@ -9,7 +9,9 @@ namespace SCHNApps ...@@ -9,7 +9,9 @@ namespace SCHNApps
unsigned int CellSelectorGen::selectorCount = 0; unsigned int CellSelectorGen::selectorCount = 0;
CellSelectorGen::CellSelectorGen(const QString& name) : CellSelectorGen::CellSelectorGen(const QString& name) :
m_name(name) m_name(name),
m_selectionChanged(false),
m_isMutuallyExclusive(false)
{ {
++selectorCount; ++selectorCount;
} }
......
...@@ -28,22 +28,27 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) : ...@@ -28,22 +28,27 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) :
connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*))); connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*)));
connect(list_dartSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); 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_dartAddSelector, SIGNAL(clicked()), this, SLOT(addSelector()));
connect(button_dartRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(button_dartRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector()));
connect(list_vertexSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); 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_vertexAddSelector, SIGNAL(clicked()), this, SLOT(addSelector()));
connect(button_vertexRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(button_vertexRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector()));
connect(list_edgeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); 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_edgeAddSelector, SIGNAL(clicked()), this, SLOT(addSelector()));
connect(button_edgeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(button_edgeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector()));
connect(list_faceSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); 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_faceAddSelector, SIGNAL(clicked()), this, SLOT(addSelector()));
connect(button_faceRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(button_faceRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector()));
connect(list_volumeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedSelectorChanged())); 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_volumeAddSelector, SIGNAL(clicked()), this, SLOT(addSelector()));
connect(button_volumeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector())); connect(button_volumeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeSelector()));
} }
...@@ -157,6 +162,20 @@ void ControlDock_MapTab::selectedSelectorChanged() ...@@ -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() void ControlDock_MapTab::addSelector()
{ {
if(!b_updatingUI) if(!b_updatingUI)
...@@ -327,75 +346,60 @@ void ControlDock_MapTab::updateSelectedMapInfo() ...@@ -327,75 +346,60 @@ void ControlDock_MapTab::updateSelectedMapInfo()
for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit) for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit)
{ {
unsigned int nbc = m->getNbCells(orbit); unsigned int nbc = m->getNbCells(orbit);
QListWidget* selectorList = NULL;
switch(orbit) switch(orbit)
{ {
case DART : { case DART : {
unsigned int nb = m->getNbDarts(); unsigned int nb = m->getNbDarts();
label_dartNbOrbits->setText(QString::number(nb)); label_dartNbOrbits->setText(QString::number(nb));
label_dartNbCells->setText(QString::number(nbc)); label_dartNbCells->setText(QString::number(nbc));
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) selectorList = list_dartSelectors;
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_dartSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break; break;
} }
case VERTEX : { case VERTEX : {
unsigned int nb = m->getNbOrbits<VERTEX>(); unsigned int nb = m->getNbOrbits<VERTEX>();
label_vertexNbOrbits->setText(QString::number(nb)); label_vertexNbOrbits->setText(QString::number(nb));
label_vertexNbCells->setText(QString::number(nbc)); label_vertexNbCells->setText(QString::number(nbc));
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) selectorList = list_vertexSelectors;
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_vertexSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break; break;
} }
case EDGE : { case EDGE : {
unsigned int nb = m->getNbOrbits<EDGE>(); unsigned int nb = m->getNbOrbits<EDGE>();
label_edgeNbOrbits->setText(QString::number(nb)); label_edgeNbOrbits->setText(QString::number(nb));
label_edgeNbCells->setText(QString::number(nbc)); label_edgeNbCells->setText(QString::number(nbc));
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) selectorList = list_edgeSelectors;
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_edgeSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break; break;
} }
case FACE : { case FACE : {
unsigned int nb = m->getNbOrbits<FACE>(); unsigned int nb = m->getNbOrbits<FACE>();
label_faceNbOrbits->setText(QString::number(nb)); label_faceNbOrbits->setText(QString::number(nb));
label_faceNbCells->setText(QString::number(nbc)); label_faceNbCells->setText(QString::number(nbc));
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) selectorList = list_faceSelectors;
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_faceSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break; break;
} }
case VOLUME : { case VOLUME : {
unsigned int nb = m->getNbOrbits<VOLUME>(); unsigned int nb = m->getNbOrbits<VOLUME>();
label_volumeNbOrbits->setText(QString::number(nb)); label_volumeNbOrbits->setText(QString::number(nb));
label_volumeNbCells->setText(QString::number(nbc)); label_volumeNbCells->setText(QString::number(nbc));
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values()) selectorList = list_volumeSelectors;
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_volumeSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break; 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)) if(m->isOrbitEmbedded(orbit))
{ {
AttributeContainer& cont = m->getAttributeContainer(orbit); AttributeContainer& cont = m->getAttributeContainer(orbit);
......
...@@ -47,9 +47,7 @@ Utils::VBO* MapHandlerGen::createVBO(const AttributeMultiVectorGen* attr) ...@@ -47,9 +47,7 @@ Utils::VBO* MapHandlerGen::createVBO(const AttributeMultiVectorGen* attr)
emit(vboAdded(vbo)); emit(vboAdded(vbo));
} }
else else
{
vbo->updateData(attr); vbo->updateData(attr);
}
return vbo; return vbo;
} }
else else
...@@ -158,6 +156,18 @@ CellSelectorGen* MapHandlerGen::getCellSelector(unsigned int orbit, const QStrin ...@@ -158,6 +156,18 @@ CellSelectorGen* MapHandlerGen::getCellSelector(unsigned int orbit, const QStrin
return NULL; return NULL;
} }
void MapHandlerGen::updateMutuallyExclusiveSelectors(unsigned int orbit)
{
QList<CellSelectorGen*> 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 * MANAGE LINKED VIEWS
*********************************************************/ *********************************************************/
......
...@@ -139,7 +139,7 @@ void View::linkMap(MapHandlerGen* map) ...@@ -139,7 +139,7 @@ void View::linkMap(MapHandlerGen* map)
connect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL())); connect(map->getFrame(), SIGNAL(modified()), this, SLOT(updateGL()));
connect(map, SIGNAL(selectedCellsChanged()), this, SLOT(updateGL())); connect(map, SIGNAL(selectedCellsChanged()), this, SLOT(updateGL()));
if(map == m_schnapps->getSelectedMap()) if(map->isSelectedMap())
setManipulatedFrame(map->getFrame()); setManipulatedFrame(map->getFrame());
} }
} }
...