Commit 9f27e691 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: several updates about signals management

parent 4fe72dc8
...@@ -37,6 +37,7 @@ file( ...@@ -37,6 +37,7 @@ file(
SET(SCHNApps_H_OBJECT_FILES SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h ${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h ${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h ${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h ${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
......
...@@ -37,6 +37,10 @@ public: ...@@ -37,6 +37,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {} virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots: public slots:
void openComputeNormalDialog(); void openComputeNormalDialog();
void openComputeCurvatureDialog(); void openComputeCurvatureDialog();
......
...@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged() ...@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged()
{ {
combo_positionAttribute->clear(); combo_positionAttribute->clear();
combo_normalAttribute->clear(); combo_normalAttribute->clear();
combo_KmaxAttribute->clear();
combo_KminAttribute->clear();
combo_KnormalAttribute->clear();
combo_kmaxAttribute->clear();
combo_kminAttribute->clear();
const QString& mapname = currentItems[0]->text(); const QString& mapname = currentItems[0]->text();
MapHandlerGen* mh = m_window->getMap(mapname); MapHandlerGen* mh = m_window->getMap(mapname);
GenericMap* map = mh->getGenericMap(); GenericMap* map = mh->getGenericMap();
......
...@@ -34,6 +34,10 @@ public: ...@@ -34,6 +34,10 @@ public:
virtual void mouseMove(View* view, int buttons, int x, int y) {} virtual void mouseMove(View* view, int buttons, int x, int y) {}
virtual void wheelEvent(View* view, int delta, int x, int y) {} virtual void wheelEvent(View* view, int delta, int x, int y) {}
virtual void viewLinked(View* view) {}
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
public slots: public slots:
void importFromFile(const QString& fileName); void importFromFile(const QString& fileName);
void importFromFileDialog(); void importFromFileDialog();
......
...@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable() ...@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable()
{ {
importAction = new QAction("import", this); importAction = new QAction("import", this);
addMenuAction("Volume;Import", importAction); addMenuAction("Volume;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import())); connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
return true; return true;
} }
void ImportVolumePlugin::cb_import() void ImportVolumePlugin::importFromFile(const QString& fileName)
{ {
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
QFileInfo fi(fileName); QFileInfo fi(fileName);
if(fi.exists()) if(fi.exists())
{ {
GenericMap* m = m_window->createMap(3); MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
PFP3::MAP* map = static_cast<PFP3::MAP*>(m); if(mhg)
MapHandler<PFP3>* h = new MapHandler<PFP3>(fi.baseName(), m_window, map); {
MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
PFP3::MAP* map = mh->getMap();
std::vector<std::string> attrNames ; std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames); Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute // get vertex position attribute
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, CGoGN::VERTEX>(attrNames[0]); VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute // create VBO for vertex position attribute
h->createVBO(position); mh->createVBO(position);
// compute map bounding box // compute map bounding box
h->updateBB(position); mh->updateBB(position);
// compute primitive connectivity VBOs // compute primitive connectivity VBOs
h->updatePrimitives(Algo::Render::GL2::POINTS); mh->updatePrimitives(Algo::Render::GL2::POINTS);
h->updatePrimitives(Algo::Render::GL2::LINES); mh->updatePrimitives(Algo::Render::GL2::LINES);
h->updatePrimitives(Algo::Render::GL2::TRIANGLES); mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
m_window->addMap(h);
} }
} }
void ImportVolumePlugin::importFromFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
importFromFile(fileName);
}
#ifndef DEBUG #ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin) Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else #else
......
#ifndef _IMPORTSURFACE_PLUGIN_H_ #ifndef _IMPORTVOLUME_PLUGIN_H_
#define _IMPORTSURFACE_PLUGIN_H_ #define _IMPORTVOLUME_PLUGIN_H_
#include "plugin.h" #include "plugin.h"
...@@ -38,11 +38,9 @@ public: ...@@ -38,11 +38,9 @@ public:
virtual void viewUnlinked(View* view) {} virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {} virtual void currentViewChanged(View* view) {}
virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots: public slots:
void cb_import(); void importFromFile(const QString& fileName);
void importFromFileDialog();
private: private:
QAction* importAction; QAction* importAction;
......
...@@ -60,7 +60,6 @@ bool RenderPlugin::enable() ...@@ -60,7 +60,6 @@ bool RenderPlugin::enable()
connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged())); connect(m_dockTab->mapList, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedMapChanged()));
connect(m_dockTab->combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int))); connect(m_dockTab->combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_positionVBOChanged(int)));
connect(m_dockTab->combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_normalVBOChanged(int))); connect(m_dockTab->combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_normalVBOChanged(int)));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool))); connect(m_dockTab->check_renderVertices, SIGNAL(toggled(bool)), this, SLOT(cb_renderVerticesChanged(bool)));
connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int))); connect(m_dockTab->slider_verticesScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_verticesScaleFactorChanged(int)));
connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool))); connect(m_dockTab->check_renderEdges, SIGNAL(toggled(bool)), this, SLOT(cb_renderEdgesChanged(bool)));
...@@ -142,6 +141,10 @@ void RenderPlugin::viewLinked(View* view) ...@@ -142,6 +141,10 @@ void RenderPlugin::viewLinked(View* view)
if (!maps.empty()) if (!maps.empty())
params->selectedMap = maps[0]; params->selectedMap = maps[0];
connect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
connect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
if(view->isCurrentView())
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
} }
...@@ -149,9 +152,8 @@ void RenderPlugin::viewUnlinked(View* view) ...@@ -149,9 +152,8 @@ void RenderPlugin::viewUnlinked(View* view)
{ {
h_viewParams.remove(view); h_viewParams.remove(view);
View* current = m_window->getCurrentView(); disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
if(isLinkedToView(current)) disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
m_dockTab->refreshUI(h_viewParams[current]);
} }
void RenderPlugin::currentViewChanged(View* view) void RenderPlugin::currentViewChanged(View* view)
...@@ -160,91 +162,196 @@ void RenderPlugin::currentViewChanged(View* view) ...@@ -160,91 +162,196 @@ void RenderPlugin::currentViewChanged(View* view)
m_dockTab->refreshUI(h_viewParams[view]); m_dockTab->refreshUI(h_viewParams[view]);
} }
void RenderPlugin::mapLinked(View* view, MapHandlerGen* m) void RenderPlugin::mapLinked(MapHandlerGen* m)
{ {
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m); PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p); params->perMap.insert(m->getName(), p);
if(params->perMap.count() == 1) if(params->selectedMap == NULL || params->perMap.count() == 1)
params->selectedMap = m; changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
} }
void RenderPlugin::mapUnlinked(View* view, MapHandlerGen* m) void RenderPlugin::mapUnlinked(MapHandlerGen* m)
{ {
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view)); assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName()); params->perMap.remove(m->getName());
if(params->selectedMap == m) if(params->selectedMap == m)
{ {
if(!params->perMap.empty()) if(!params->perMap.empty())
params->selectedMap = m_window->getMap(params->perMap.begin().key()); changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
else
changeSelectedMap(view, NULL);
}
else else
params->selectedMap = NULL;
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
}
void RenderPlugin::vboAdded(Utils::VBO* vbo)
{
m_dockTab->refreshUI(h_viewParams[m_window->getCurrentView()]);
}
void RenderPlugin::vboRemoved(Utils::VBO* vbo)
{
MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
if(params->perMap[map->getName()].positionVBO == vbo)
changePositionVBO(view, map, NULL);
if(params->perMap[map->getName()].normalVBO == vbo)
changeNormalVBO(view, map, NULL);
}
void RenderPlugin::changeSelectedMap(View* view, MapHandlerGen* map)
{
ParameterSet* params = h_viewParams[view];
MapHandlerGen* prev = params->selectedMap;
params->selectedMap = map;
if(view->isCurrentView())
{
if(prev)
disconnect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
if(map)
connect(map, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(vboAdded(Utils::VBO*)));
m_dockTab->refreshUI(params);
view->updateGL();
} }
} }
void RenderPlugin::cb_selectedMapChanged() void RenderPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{ {
if(!b_refreshingUI) ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].positionVBO = vbo;
if(view->isCurrentView())
{ {
View* view = m_window->getCurrentView(); m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
ParameterSet* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems(); params->perMap[map->getName()].normalVBO = vbo;
if(!currentItems.empty())
if(view->isCurrentView())
{ {
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params); m_dockTab->refreshUI(params);
view->updateGL(); view->updateGL();
} }
}
void RenderPlugin::changeRenderVertices(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderVertices = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
} }
} }
void RenderPlugin::cb_positionVBOChanged(int index) void RenderPlugin::changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].verticesScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeRenderEdges(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderEdges = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeRenderFaces(View* view, MapHandlerGen* map, bool b)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].renderFaces = b;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].faceStyle = style;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderPlugin::cb_selectedMapChanged()
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
ParameterSet* params = h_viewParams[current]; if(!currentItems.empty())
MapHandlerGen* map = params->selectedMap; changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
} }
} }
void RenderPlugin::cb_normalVBOChanged(int index) void RenderPlugin::cb_positionVBOChanged(int index)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* map = params->selectedMap; changePositionVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
params->perMap[map->getName()].normalVBO = map->getVBO(m_dockTab->combo_normalVBO->currentText());
current->updateGL();
} }
} }
void RenderPlugin::cb_refreshVBOs() void RenderPlugin::cb_normalVBOChanged(int index)
{ {
View* current = m_window->getCurrentView(); if(!b_refreshingUI)
if(isLinkedToView(current)) {
m_dockTab->refreshUI(h_viewParams[current]); View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeNormalVBO(view, map, map->getVBO(m_dockTab->combo_normalVBO->currentText()));
}
} }
void RenderPlugin::cb_renderVerticesChanged(bool b) void RenderPlugin::cb_renderVerticesChanged(bool b)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap; changeRenderVertices(view, map, b);
params->perMap[m->getName()].renderVertices = b;
current->updateGL();
} }
} }
...@@ -252,11 +359,9 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i) ...@@ -252,11 +359,9 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap; changeVerticesScaleFactor(view, map, i);
params->perMap[m->getName()].verticesScaleFactor = i / 50.0;
current->updateGL();
} }
} }
...@@ -264,11 +369,9 @@ void RenderPlugin::cb_renderEdgesChanged(bool b) ...@@ -264,11 +369,9 @@ void RenderPlugin::cb_renderEdgesChanged(bool b)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap; changeRenderEdges(view, map, b);
params->perMap[m->getName()].renderEdges = b;
current->updateGL();
} }
} }
...@@ -276,11 +379,9 @@ void RenderPlugin::cb_renderFacesChanged(bool b) ...@@ -276,11 +379,9 @@ void RenderPlugin::cb_renderFacesChanged(bool b)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap; changeRenderFaces(view, map, b);
params->perMap[m->getName()].renderFaces = b;
current->updateGL();
} }
} }
...@@ -288,14 +389,12 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b) ...@@ -288,14 +389,12 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
{ {
if(!b_refreshingUI) if(!b_refreshingUI)
{ {
View* current = m_window->getCurrentView(); View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current]; MapHandlerGen* map = h_viewParams[view]->selectedMap;
MapHandlerGen* m = params->selectedMap;
if(m_dockTab->radio_flatShading->isChecked()) if(m_dockTab->radio_flatShading->isChecked())
params->perMap[m->getName()].faceStyle = FLAT; changeFacesStyle(view, map, FLAT);
else if(m_dockTab->radio_phongShading->isChecked()) else if(m_dockTab->radio_phongShading->isChecked())
params->perMap[m->getName()].faceStyle = PHONG; changeFacesStyle(view, map, PHONG);
current->updateGL();
} }
} }
...@@ -323,7 +422,10 @@ void RenderDockTab::refreshUI(ParameterSet* params) ...@@ -323,7 +422,10 @@ void RenderDockTab::refreshUI(ParameterSet* params)
PerMapParameterSet& p = params->perMap[map->getName()]; PerMapParameterSet& p = params->perMap[map->getName()];
QList<Utils::VBO*> vbos = map->getVBOList(); QList<Utils::VBO*> vbos = map->getVBOList();
unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++i) for(int i = 0; i < vbos.count(); ++i)
{
if(vbos[i]->dataSize() == 3)
{ {
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name())); combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.positionVBO == NULL) if(p.positionVBO == NULL)
...@@ -331,11 +433,11 @@ void RenderDockTab::refreshUI(ParameterSet* params) ...@@ -331,11 +433,11 @@ void RenderDockTab::refreshUI(ParameterSet* params)
if(vbos[i]->name() == "position") // try to select a VBO named "position" if(vbos[i]->name() == "position") // try to select a VBO named "position"
{ {
p.positionVBO = vbos[i]; p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(i); combo_positionVBO->setCurrentIndex(j);
} }
} }
else if(vbos[i] == p.positionVBO) else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(i); combo_positionVBO->setCurrentIndex(j);
combo_normalVBO->addItem(QString::fromStdString(vbos[i]->name())); combo_normalVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.normalVBO == NULL) if(p.normalVBO == NULL)
...@@ -343,22 +445,45 @@ void RenderDockTab::refreshUI(ParameterSet* params) ...@@ -343,22 +445,45 @@ void RenderDockTab::refreshUI(ParameterSet* params)