Commit 12c601ff authored by Pierre Kraemer's avatar Pierre Kraemer

add CellSelectors

parent 7192da78
......@@ -166,7 +166,7 @@
<item row="5" column="0" colspan="3">
<widget class="QListWidget" name="list_dartSelectors">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
......@@ -273,7 +273,7 @@
<item row="5" column="0" colspan="3">
<widget class="QListWidget" name="list_vertexSelectors">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
......@@ -380,7 +380,7 @@
<item row="5" column="0" colspan="3">
<widget class="QListWidget" name="list_edgeSelectors">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
......@@ -487,7 +487,7 @@
<item row="5" column="0" colspan="3">
<widget class="QListWidget" name="list_faceSelectors">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
......@@ -594,7 +594,7 @@
<item row="5" column="0" colspan="3">
<widget class="QListWidget" name="list_volumeSelectors">
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</widget>
</item>
......
#ifndef _CELL_SELECTOR_H_
#define _CELL_SELECTOR_H_
#include <QString>
#include "Topology/generic/dart.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/cellmarker.h"
namespace CGoGN
{
namespace SCHNApps
{
class CellSelectorGen
{
public:
static unsigned int selectorCount;
CellSelectorGen(const QString& name);
virtual ~CellSelectorGen()
{}
inline const QString& getName() { return m_name; }
inline const std::vector<Dart>& getSelectedCells() { return m_cells; }
virtual unsigned int getOrbit() = 0;
// virtual void select(Dart d) = 0;
// virtual void unselect(Dart d) = 0;
// virtual void select(const std::vector<Dart>& d) = 0;
// virtual void unselect(const std::vector<Dart>& d) = 0;
// virtual bool isSelected(Dart d) = 0;
private:
QString m_name;
std::vector<Dart> m_cells;
};
template <unsigned int ORBIT>
class CellSelector : public CellSelectorGen
{
public:
CellSelector(GenericMap& m, const QString& name, unsigned int thread = 0) :
CellSelectorGen(name),
m_map(m),
m_cm(m, thread)
{}
~CellSelector()
{}
inline unsigned int getOrbit() { return ORBIT; }
inline void select(Dart d)
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
if(!m_cm.isMarked(v))
{
m_cells.push_back(d);
m_cm.mark(v);
}
}
inline void unselect(Dart d)
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
if(m_cm.isMarked(v))
{
bool found = false;
unsigned int i;
for(i = 0; i < m_cells.size() && !found; ++i)
{
if(m_map.getEmbedding<ORBIT>(m_cells[i]) == v)
found = true ;
}
if(found)
{
m_cm.unmark(m_cells[i-1]);
m_cells[i-1] = m_cells.back();
m_cells.pop_back();
}
}
}
inline void select(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
select(d[i]);
}
inline void unselect(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
unselect(d[i]);
}
inline bool isSelected(Dart d)
{
return m_cm.isMarked(d);
}
private:
GenericMap& m_map;
CellMarker<ORBIT> m_cm;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
......@@ -33,6 +33,16 @@ private slots:
void selectedMapChanged();
void mapCheckStateChanged(QListWidgetItem* item);
void vertexAttributeCheckStateChanged(QListWidgetItem* item);
void addDartSelector();
void removeDartSelector();
void addVertexSelector();
void removeVertexSelector();
void addEdgeSelector();
void removeEdgeSelector();
void addFaceSelector();
void removeFaceSelector();
void addVolumeSelector();
void removeVolumeSelector();
// slots called from SCHNApps signals
void mapAdded(MapHandlerGen* m);
......@@ -47,6 +57,8 @@ private slots:
void selectedMapAttributeAdded(unsigned int orbit, const QString& name);
void selectedMapVBOAdded(Utils::VBO* vbo);
void selectedMapVBORemoved(Utils::VBO* vbo);
void selectedMapCellSelectorAdded(unsigned int orbit, const QString& name);
void selectedMapCellSelectorRemoved(unsigned int orbit, const QString& name);
private:
void updateSelectedMapInfo();
......
......@@ -6,7 +6,7 @@
#include "types.h"
#include "view.h"
#include "plugin.h"
#include "primitiveSelector.h"
#include "cellSelector.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/attribmap.h"
......@@ -138,6 +138,16 @@ public slots:
void deleteVBO(const QString& name);
/*********************************************************
* MANAGE CELL SELECTORS
*********************************************************/
CellSelectorGen* addCellSelector(unsigned int orbit, const QString& name);
void removeCellSelector(unsigned int orbit, const QString& name);
CellSelectorGen* getCellSelector(unsigned int orbit, const QString& name) const;
const QMap<QString, CellSelectorGen*>& getCellSelectorSet(unsigned int orbit) const { return m_cellSelectors[orbit]; }
/*********************************************************
* MANAGE LINKED VIEWS
*********************************************************/
......@@ -159,6 +169,9 @@ signals:
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void cellSelectorAdded(unsigned int orbit, const QString& name);
void cellSelectorRemoved(unsigned int orbit, const QString& name);
protected:
QString m_name;
SCHNApps* m_schnapps;
......@@ -179,7 +192,7 @@ protected:
VBOSet m_vbo;
AttributeSet m_attribs[NB_ORBITS];
QList<PrimitiveSelectorGen*> m_selectors[NB_ORBITS];
QMap<QString, CellSelectorGen*> m_cellSelectors[NB_ORBITS];
};
......@@ -205,6 +218,8 @@ public:
void updateBB(const VertexAttribute<typename PFP::VEC3>& position);
void updateBBDrawer();
CellSelectorGen* addPrimitiveSelector(unsigned int orbit, const QString& name);
protected:
Geom::BoundingBox<typename PFP::VEC3> m_bb;
};
......
#include "cellSelector.h"
namespace CGoGN
{
namespace SCHNApps
{
unsigned int CellSelectorGen::selectorCount = 0;
CellSelectorGen::CellSelectorGen(const QString& name) :
m_name(name)
{
++selectorCount;
}
} // namespace SCHNApps
} // namespace CGoGN
......@@ -17,13 +17,24 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) :
{
setupUi(this);
connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
connect(list_maps, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(mapCheckStateChanged(QListWidgetItem*)));
connect(list_vertexAttributes, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vertexAttributeCheckStateChanged(QListWidgetItem*)));
connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*)));
connect(button_dartAddSelector, SIGNAL(clicked()), this, SLOT(addDartSelector()));
connect(button_dartRemoveSelector, SIGNAL(clicked()), this, SLOT(removeDartSelector()));
connect(button_vertexAddSelector, SIGNAL(clicked()), this, SLOT(addVertexSelector()));
connect(button_vertexRemoveSelector, SIGNAL(clicked()), this, SLOT(removeVertexSelector()));
connect(button_edgeAddSelector, SIGNAL(clicked()), this, SLOT(addEdgeSelector()));
connect(button_edgeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeEdgeSelector()));
connect(button_faceAddSelector, SIGNAL(clicked()), this, SLOT(addFaceSelector()));
connect(button_faceRemoveSelector, SIGNAL(clicked()), this, SLOT(removeFaceSelector()));
connect(button_volumeAddSelector, SIGNAL(clicked()), this, SLOT(addVolumeSelector()));
connect(button_volumeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeVolumeSelector()));
}
......@@ -34,18 +45,20 @@ void ControlDock_MapTab::selectedMapChanged()
{
if(!b_updatingUI)
{
MapHandlerGen* old = m_selectedMap;
if(m_selectedMap)
{
disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
disconnect(m_selectedMap, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(selectedMapVBOAdded(Utils::VBO*)));
disconnect(m_selectedMap, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(selectedMapVBORemoved(Utils::VBO*)));
disconnect(m_selectedMap, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorAdded(unsigned int, const QString&)));
disconnect(m_selectedMap, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorRemoved(unsigned int, const QString&)));
}
QList<QListWidgetItem*> items = list_maps->selectedItems();
if(!items.empty())
{
MapHandlerGen* old = m_selectedMap;
QString selectedMapName = items[0]->text();
m_selectedMap = m_schnapps->getMap(selectedMapName);
......@@ -56,6 +69,8 @@ void ControlDock_MapTab::selectedMapChanged()
connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&)));
connect(m_selectedMap, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(selectedMapVBOAdded(Utils::VBO*)));
connect(m_selectedMap, SIGNAL(vboRemoved(Utils::VBO*)), this, SLOT(selectedMapVBORemoved(Utils::VBO*)));
connect(m_selectedMap, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorAdded(unsigned int, const QString&)));
connect(m_selectedMap, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorRemoved(unsigned int, const QString&)));
}
}
}
......@@ -95,6 +110,116 @@ void ControlDock_MapTab::vertexAttributeCheckStateChanged(QListWidgetItem *item)
}
}
void ControlDock_MapTab::addDartSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
m_selectedMap->addCellSelector(DART, QString("selector_") + QString::number(CellSelectorGen::selectorCount));
}
}
void ControlDock_MapTab::removeDartSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
{
QList<QListWidgetItem*> items = list_dartSelectors->selectedItems();
if(!items.empty())
m_selectedMap->removeCellSelector(DART, items[0]->text());
}
}
}
void ControlDock_MapTab::addVertexSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
m_selectedMap->addCellSelector(VERTEX, QString("selector_") + QString::number(CellSelectorGen::selectorCount));
}
}
void ControlDock_MapTab::removeVertexSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
{
QList<QListWidgetItem*> items = list_vertexSelectors->selectedItems();
if(!items.empty())
m_selectedMap->removeCellSelector(VERTEX, items[0]->text());
}
}
}
void ControlDock_MapTab::addEdgeSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
m_selectedMap->addCellSelector(EDGE, QString("selector_") + QString::number(CellSelectorGen::selectorCount));
}
}
void ControlDock_MapTab::removeEdgeSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
{
QList<QListWidgetItem*> items = list_edgeSelectors->selectedItems();
if(!items.empty())
m_selectedMap->removeCellSelector(EDGE, items[0]->text());
}
}
}
void ControlDock_MapTab::addFaceSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
m_selectedMap->addCellSelector(FACE, QString("selector_") + QString::number(CellSelectorGen::selectorCount));
}
}
void ControlDock_MapTab::removeFaceSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
{
QList<QListWidgetItem*> items = list_faceSelectors->selectedItems();
if(!items.empty())
m_selectedMap->removeCellSelector(FACE, items[0]->text());
}
}
}
void ControlDock_MapTab::addVolumeSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
m_selectedMap->addCellSelector(VOLUME, QString("selector_") + QString::number(CellSelectorGen::selectorCount));
}
}
void ControlDock_MapTab::removeVolumeSelector()
{
if(!b_updatingUI)
{
if(m_selectedMap)
{
QList<QListWidgetItem*> items = list_volumeSelectors->selectedItems();
if(!items.empty())
m_selectedMap->removeCellSelector(VOLUME, items[0]->text());
}
}
}
......@@ -197,6 +322,16 @@ void ControlDock_MapTab::selectedMapVBORemoved(Utils::VBO *vbo)
updateSelectedMapInfo();
}
void ControlDock_MapTab::selectedMapCellSelectorAdded(unsigned int orbit, const QString& name)
{
updateSelectedMapInfo();
}
void ControlDock_MapTab::selectedMapCellSelectorRemoved(unsigned int orbit, const QString& name)
{
updateSelectedMapInfo();
}
......@@ -211,6 +346,12 @@ void ControlDock_MapTab::updateSelectedMapInfo()
list_faceAttributes->clear();
list_volumeAttributes->clear();
list_dartSelectors->clear();
list_vertexSelectors->clear();
list_edgeSelectors->clear();
list_faceSelectors->clear();
list_volumeSelectors->clear();
GenericMap* m = m_selectedMap->getGenericMap();
for(unsigned int orbit = DART; orbit <= VOLUME; ++orbit)
{
......@@ -221,30 +362,55 @@ void ControlDock_MapTab::updateSelectedMapInfo()
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);
}
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);
}
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);
}
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);
}
break;
}
case VOLUME : {
unsigned int nb = m->getNbOrbits<VOLUME>();
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);
}
break;
}
}
......
......@@ -103,6 +103,53 @@ void MapHandlerGen::deleteVBO(const QString& name)
}
}
/*********************************************************
* MANAGE CELL SELECTORS
*********************************************************/
CellSelectorGen* MapHandlerGen::addCellSelector(unsigned int orbit, const QString& name)
{
if(m_cellSelectors[orbit].contains(name))
return NULL;
CellSelectorGen* cs = NULL;
switch(orbit)
{
case DART: cs = new CellSelector<DART>(*m_map, name); break;
case VERTEX: cs = new CellSelector<VERTEX>(*m_map, name); break;
case EDGE: cs = new CellSelector<EDGE>(*m_map, name); break;
case FACE: cs = new CellSelector<FACE>(*m_map, name); break;
case VOLUME: cs = new CellSelector<VOLUME>(*m_map, name); break;
}
if(!cs)
return NULL;
m_cellSelectors[orbit].insert(name, cs);
emit(cellSelectorAdded(orbit, name));
return cs;
}
void MapHandlerGen::removeCellSelector(unsigned int orbit, const QString& name)
{
CellSelectorGen* cs = getCellSelector(orbit, name);
if (cs)
{
m_cellSelectors[orbit].remove(name);
emit(cellSelectorRemoved(orbit, name));
delete cs;
}
}
CellSelectorGen* MapHandlerGen::getCellSelector(unsigned int orbit, const QString& name) const
{
if (m_cellSelectors[orbit].contains(name))
return m_cellSelectors[orbit][name];
else
return NULL;
}
/*********************************************************
* MANAGE LINKED VIEWS
*********************************************************/
......
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