Commit e6b9e147 authored by Pierre Kraemer's avatar Pierre Kraemer

selection plugin first functional version :-)

parent 49e302e4
......@@ -128,6 +128,7 @@ file(
SET(SCHNApps_QOBJECT_FILES
${SCHNApps_ROOT_DIR}/include/camera.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/cellSelector.h
${SCHNApps_ROOT_DIR}/include/plugin.h
${SCHNApps_ROOT_DIR}/include/plugin_interaction.h
${SCHNApps_ROOT_DIR}/include/plugin_processing.h
......
......@@ -5,6 +5,7 @@
#include "surface_selection_dockTab.h"
#include "Utils/pointSprite.h"
#include "Utils/drawer.h"
namespace CGoGN
{
......@@ -36,7 +37,7 @@ public:
virtual bool enable();
virtual void disable();
virtual void draw(View *view) {}
virtual void draw(View *view);
virtual void drawMap(View* view, MapHandlerGen* map);
virtual void keyPress(View* view, QKeyEvent* event);
......@@ -66,8 +67,10 @@ protected:
Surface_Selection_DockTab* m_dockTab;
QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;
Utils::PointSprite* m_pointSprite;
Utils::Drawer* m_drawer;
Utils::VBO* m_selectionSphereVBO;
Utils::PointSprite* m_pointSprite;
bool m_selecting;
......
......@@ -25,9 +25,11 @@ bool Surface_Selection_Plugin::enable()
m_dockTab = new Surface_Selection_DockTab(m_schnapps, this);
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Selection");
m_drawer = new Utils::Drawer();
m_selectionSphereVBO = new Utils::VBO();
m_pointSprite = new CGoGN::Utils::PointSprite();
registerShader(m_drawer->getShader());
registerShader(m_pointSprite);
connect(m_schnapps, SIGNAL(selectedViewChanged(View*, View*)), this, SLOT(selectedViewChanged(View*, View*)));
......@@ -49,7 +51,7 @@ void Surface_Selection_Plugin::disable()
delete m_pointSprite;
}
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
void Surface_Selection_Plugin::draw(View *view)
{
if(m_selecting)
{
......@@ -71,6 +73,32 @@ void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
}
}
void Surface_Selection_Plugin::drawMap(View* view, MapHandlerGen* map)
{
if(map == m_schnapps->getSelectedMap())
{
const MapParameters& p = h_viewParameterSet[view][map];
if(p.positionAttribute.isValid())
{
unsigned int orbit = m_schnapps->getCurrentOrbit();
CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
if(selector)
{
const std::vector<Dart>& selectedCells = selector->getSelectedCells();
m_drawer->newList(GL_COMPILE_AND_EXECUTE);
m_drawer->pointSize(2.0f);
m_drawer->color3f(0.0f, 0.0f, 1.0f);
m_drawer->begin(GL_POINTS);
for(std::vector<Dart>::const_iterator it = selectedCells.begin(); it != selectedCells.end(); ++it)
m_drawer->vertex(p.positionAttribute[*it]);
m_drawer->end();
m_drawer->endList();
}
}
}
}
void Surface_Selection_Plugin::keyPress(View* view, QKeyEvent* event)
{
if(event->key() == Qt::Key_Shift)
......@@ -116,6 +144,20 @@ void Surface_Selection_Plugin::mousePress(View* view, QMouseEvent* event)
Algo::Surface::Selection::Collector_WithinSphere<PFP2> neigh(*map, p.positionAttribute, m_selectionRadius);
neigh.collectAll(d);
unsigned int orbit = m_schnapps->getCurrentOrbit();
CellSelectorGen* selector = m_schnapps->getSelectedSelector(orbit);
if(selector)
{
switch(orbit)
{
case DART: break;
case VERTEX: selector->select(neigh.getInsideVertices()); break;
case EDGE: selector->select(neigh.getInsideEdges()); break;
case FACE: selector->select(neigh.getInsideFaces()); break;
}
}
view->updateGL() ;
}
}
......
......@@ -7,14 +7,18 @@
#include "Topology/generic/genericmap.h"
#include "Topology/generic/cellmarker.h"
#include <QObject>
namespace CGoGN
{
namespace SCHNApps
{
class CellSelectorGen
class CellSelectorGen : public QObject
{
Q_OBJECT
public:
static unsigned int selectorCount;
......@@ -28,15 +32,18 @@ public:
virtual unsigned int getOrbit() = 0;
// virtual void select(Dart d) = 0;
// virtual void unselect(Dart d) = 0;
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;
virtual void select(const std::vector<Dart>& d) = 0;
virtual void unselect(const std::vector<Dart>& d) = 0;
// virtual bool isSelected(Dart d) = 0;
virtual bool isSelected(Dart d) = 0;
private:
signals:
void selectedCellsChanged();
protected:
QString m_name;
std::vector<Dart> m_cells;
};
......@@ -56,17 +63,19 @@ public:
inline unsigned int getOrbit() { return ORBIT; }
inline void select(Dart d)
inline void select(Dart d, bool emitSignal = true)
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
if(!m_cm.isMarked(v))
{
m_cells.push_back(d);
m_cm.mark(v);
if(emitSignal)
emit(selectedCellsChanged());
}
}
inline void unselect(Dart d)
inline void unselect(Dart d, bool emitSignal = true)
{
unsigned int v = m_map.getEmbedding<ORBIT>(d);
if(m_cm.isMarked(v))
......@@ -83,6 +92,8 @@ public:
m_cm.unmark(m_cells[i-1]);
m_cells[i-1] = m_cells.back();
m_cells.pop_back();
if(emitSignal)
emit(selectedCellsChanged());
}
}
}
......@@ -90,13 +101,13 @@ public:
inline void select(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
select(d[i]);
select(d[i], false);
}
inline void unselect(const std::vector<Dart>& d)
{
for(unsigned int i = 0; i < d.size(); ++i)
unselect(d[i]);
unselect(d[i], false);
}
inline bool isSelected(Dart d)
......
......@@ -3,6 +3,8 @@
#include "ui_controlDock_MapTabWidget.h"
#include "mapHandler.h"
namespace CGoGN
{
......@@ -15,7 +17,6 @@ namespace SCHNApps
{
class SCHNApps;
class MapHandlerGen;
class View;
class ControlDock_MapTab : public QWidget, public Ui::ControlDock_MapTabWidget
......@@ -27,20 +28,32 @@ public:
QString title() { return QString("Maps"); }
MapHandlerGen* getSelectedMap() { return m_selectedMap; }
unsigned int getCurrentOrbit();
CellSelectorGen* getSelectedSelector(unsigned int orbit) { return m_selectedSelector[orbit]; }
private slots:
// slots called from UI actions
void selectedMapChanged();
void mapCheckStateChanged(QListWidgetItem* item);
void vertexAttributeCheckStateChanged(QListWidgetItem* item);
void selectedDartSelectorChanged();
void addDartSelector();
void removeDartSelector();
void selectedVertexSelectorChanged();
void addVertexSelector();
void removeVertexSelector();
void selectedEdgeSelectorChanged();
void addEdgeSelector();
void removeEdgeSelector();
void selectedFaceSelectorChanged();
void addFaceSelector();
void removeFaceSelector();
void selectedVolumeSelectorChanged();
void addVolumeSelector();
void removeVolumeSelector();
......@@ -65,6 +78,7 @@ private:
SCHNApps* m_schnapps;
MapHandlerGen* m_selectedMap;
CellSelectorGen* m_selectedSelector[NB_ORBITS];
bool b_updatingUI;
};
......
......@@ -97,6 +97,9 @@ public slots:
void notifySelectedMapChanged(MapHandlerGen* old, MapHandlerGen* cur) { emit(selectedMapChanged(old, cur)); }
MapHandlerGen* getSelectedMap() const;
unsigned int getCurrentOrbit() const;
CellSelectorGen* getSelectedSelector(unsigned int orbit) const;
/*********************************************************
* MANAGE TEXTURES
*********************************************************/
......
......@@ -37,6 +37,7 @@ class PluginProcessing;
class View;
class Camera;
class MapHandlerGen;
class CellSelectorGen;
struct Texture;
typedef QMap<QString, Plugin*> PluginSet;
......
#include "controlDock_mapTab.h"
#include "schnapps.h"
#include "mapHandler.h"
#include "view.h"
namespace CGoGN
......@@ -15,6 +14,9 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) :
m_selectedMap(NULL),
b_updatingUI(false)
{
for(unsigned int i = 0; i < NB_ORBITS; ++i)
m_selectedSelector[i] = NULL;
setupUi(this);
connect(list_maps, SIGNAL(itemSelectionChanged()), this, SLOT(selectedMapChanged()));
......@@ -25,18 +27,41 @@ ControlDock_MapTab::ControlDock_MapTab(SCHNApps* s) :
connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));
connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*)));
connect(list_dartSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedDartSelectorChanged()));
connect(button_dartAddSelector, SIGNAL(clicked()), this, SLOT(addDartSelector()));
connect(button_dartRemoveSelector, SIGNAL(clicked()), this, SLOT(removeDartSelector()));
connect(list_vertexSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedVertexSelectorChanged()));
connect(button_vertexAddSelector, SIGNAL(clicked()), this, SLOT(addVertexSelector()));
connect(button_vertexRemoveSelector, SIGNAL(clicked()), this, SLOT(removeVertexSelector()));
connect(list_edgeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedEdgeSelectorChanged()));
connect(button_edgeAddSelector, SIGNAL(clicked()), this, SLOT(addEdgeSelector()));
connect(button_edgeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeEdgeSelector()));
connect(list_faceSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedFaceSelectorChanged()));
connect(button_faceAddSelector, SIGNAL(clicked()), this, SLOT(addFaceSelector()));
connect(button_faceRemoveSelector, SIGNAL(clicked()), this, SLOT(removeFaceSelector()));
connect(list_volumeSelectors, SIGNAL(itemSelectionChanged()), this, SLOT(selectedVolumeSelectorChanged()));
connect(button_volumeAddSelector, SIGNAL(clicked()), this, SLOT(addVolumeSelector()));
connect(button_volumeRemoveSelector, SIGNAL(clicked()), this, SLOT(removeVolumeSelector()));
}
unsigned int ControlDock_MapTab::getCurrentOrbit()
{
int current = tabWidget_mapInfo->currentIndex();
switch(current)
{
case 0 : return DART; break;
case 1 : return VERTEX; break;
case 2 : return EDGE; break;
case 3 : return FACE; break;
case 4 : return VOLUME; break;
}
return DART;
}
......@@ -110,6 +135,19 @@ void ControlDock_MapTab::vertexAttributeCheckStateChanged(QListWidgetItem *item)
}
}
void ControlDock_MapTab::selectedDartSelectorChanged()
{
if(!b_updatingUI)
{
QList<QListWidgetItem*> items = list_dartSelectors->selectedItems();
if(!items.empty())
{
QString selectedSelectorName = items[0]->text();
m_selectedSelector[DART] = m_selectedMap->getCellSelector(DART, selectedSelectorName);
}
}
}
void ControlDock_MapTab::addDartSelector()
{
if(!b_updatingUI)
......@@ -132,6 +170,19 @@ void ControlDock_MapTab::removeDartSelector()
}
}
void ControlDock_MapTab::selectedVertexSelectorChanged()
{
if(!b_updatingUI)
{
QList<QListWidgetItem*> items = list_vertexSelectors->selectedItems();
if(!items.empty())
{
QString selectedSelectorName = items[0]->text();
m_selectedSelector[VERTEX] = m_selectedMap->getCellSelector(VERTEX, selectedSelectorName);
}
}
}
void ControlDock_MapTab::addVertexSelector()
{
if(!b_updatingUI)
......@@ -154,6 +205,19 @@ void ControlDock_MapTab::removeVertexSelector()
}
}
void ControlDock_MapTab::selectedEdgeSelectorChanged()
{
if(!b_updatingUI)
{
QList<QListWidgetItem*> items = list_edgeSelectors->selectedItems();
if(!items.empty())
{
QString selectedSelectorName = items[0]->text();
m_selectedSelector[EDGE] = m_selectedMap->getCellSelector(EDGE, selectedSelectorName);
}
}
}
void ControlDock_MapTab::addEdgeSelector()
{
if(!b_updatingUI)
......@@ -176,6 +240,19 @@ void ControlDock_MapTab::removeEdgeSelector()
}
}
void ControlDock_MapTab::selectedFaceSelectorChanged()
{
if(!b_updatingUI)
{
QList<QListWidgetItem*> items = list_faceSelectors->selectedItems();
if(!items.empty())
{
QString selectedSelectorName = items[0]->text();
m_selectedSelector[FACE] = m_selectedMap->getCellSelector(FACE, selectedSelectorName);
}
}
}
void ControlDock_MapTab::addFaceSelector()
{
if(!b_updatingUI)
......@@ -198,6 +275,19 @@ void ControlDock_MapTab::removeFaceSelector()
}
}
void ControlDock_MapTab::selectedVolumeSelectorChanged()
{
if(!b_updatingUI)
{
QList<QListWidgetItem*> items = list_volumeSelectors->selectedItems();
if(!items.empty())
{
QString selectedSelectorName = items[0]->text();
m_selectedSelector[VOLUME] = m_selectedMap->getCellSelector(VOLUME, selectedSelectorName);
}
}
}
void ControlDock_MapTab::addVolumeSelector()
{
if(!b_updatingUI)
......@@ -366,6 +456,8 @@ void ControlDock_MapTab::updateSelectedMapInfo()
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_dartSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
......@@ -377,6 +469,8 @@ void ControlDock_MapTab::updateSelectedMapInfo()
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_vertexSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
......@@ -388,6 +482,8 @@ void ControlDock_MapTab::updateSelectedMapInfo()
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_edgeSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
......@@ -399,6 +495,8 @@ void ControlDock_MapTab::updateSelectedMapInfo()
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_faceSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
......@@ -410,6 +508,8 @@ void ControlDock_MapTab::updateSelectedMapInfo()
{
QListWidgetItem* item = new QListWidgetItem(cs->getName(), list_volumeSelectors);
item->setFlags(item->flags() | Qt::ItemIsEditable);
if(m_selectedSelector[orbit] == cs)
item->setSelected(true);
}
break;
}
......
......@@ -528,6 +528,16 @@ MapHandlerGen* SCHNApps::getSelectedMap() const
return m_controlMapTab->getSelectedMap();
}
unsigned int SCHNApps::getCurrentOrbit() const
{
return m_controlMapTab->getCurrentOrbit();
}
CellSelectorGen* SCHNApps::getSelectedSelector(unsigned int orbit) const
{
return m_controlMapTab->getSelectedSelector(orbit);
}
/*********************************************************
* MANAGE TEXTURES
*********************************************************/
......
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