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

mutually exclusive cell selectors

parent cb23b33c
......@@ -33,7 +33,7 @@
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Free selector :</string>
<string>Free vertices selector :</string>
</property>
</widget>
</item>
......@@ -59,6 +59,22 @@
</property>
</widget>
</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">
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -72,27 +88,11 @@
</property>
</spacer>
</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="3" column="0">
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Handle selector :</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>
<string>Handle vertices selector :</string>
</property>
</item>
</widget>
</item>
</layout>
......
......@@ -81,8 +81,6 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
m_drawer->vertex(p.positionAttribute[*it]);
m_drawer->end();
m_drawer->endList();
}
}
if(m_selecting)
{
......@@ -103,6 +101,8 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
m_pointSprite->disableVertexAttribs();
}
}
}
}
}
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);
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();
}
}
......
#ifndef _CELL_SELECTOR_H_
#define _CELL_SELECTOR_H_
#include <QObject>
#include <QString>
#include <QList>
#include "Topology/generic/dart.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/cellmarker.h"
#include <QObject>
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<Dart>& d) = 0;
virtual void unselect(const std::vector<Dart>& d) = 0;
inline void select(const std::vector<Dart>& 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<Dart>& 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<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:
void selectedCellsChanged();
protected:
QString m_name;
std::vector<Dart> m_cells;
bool m_selectionChanged;
bool m_isMutuallyExclusive;
QList<CellSelectorGen*> m_mutuallyExclusive;
};
template <unsigned int ORBIT>
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<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)
{
return m_cm.isMarked(d);
......
......@@ -38,6 +38,7 @@ private slots:
void vertexAttributeCheckStateChanged(QListWidgetItem* item);
void selectedSelectorChanged();
void selectorCheckStateChanged(QListWidgetItem* item);
void addSelector();
void removeSelector();
......
......@@ -152,6 +152,8 @@ public:
template <unsigned int ORBIT>
CellSelector<ORBIT>* getCellSelector(const QString& name) const;
void updateMutuallyExclusiveSelectors(unsigned int orbit);
/*********************************************************
* MANAGE LINKED VIEWS
*********************************************************/
......
......@@ -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;
}
......
......@@ -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,73 +346,58 @@ 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<VERTEX>();
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<EDGE>();
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<FACE>();
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<VOLUME>();
label_volumeNbOrbits->setText(QString::number(nb));
label_volumeNbCells->setText(QString::number(nbc));
selectorList = list_volumeSelectors;
break;
}
}
foreach(CellSelectorGen* cs, m_selectedMap->getCellSelectorSet(orbit).values())
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_volumeSelectors);
QListWidgetItem* item = new QListWidgetItem(cs->getName(), selectorList);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
if(cs->isMutuallyExclusive())
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}
if(m->isOrbitEmbedded(orbit))
......
......@@ -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<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
*********************************************************/
......
......@@ -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());
}
}
......
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