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

SCHNApps: several updates about signals management

parent 4fe72dc8
......@@ -37,6 +37,7 @@ file(
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginsDialog.h
......
......@@ -37,6 +37,10 @@ public:
virtual void mouseMove(View* view, int buttons, 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:
void openComputeNormalDialog();
void openComputeCurvatureDialog();
......
......@@ -37,6 +37,11 @@ void ComputeCurvatureDialog::selectedMapChanged()
{
combo_positionAttribute->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();
MapHandlerGen* mh = m_window->getMap(mapname);
GenericMap* map = mh->getGenericMap();
......
......@@ -34,6 +34,10 @@ public:
virtual void mouseMove(View* view, int buttons, 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:
void importFromFile(const QString& fileName);
void importFromFileDialog();
......
......@@ -11,42 +11,47 @@ bool ImportVolumePlugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Volume;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
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);
if(fi.exists())
{
GenericMap* m = m_window->createMap(3);
PFP3::MAP* map = static_cast<PFP3::MAP*>(m);
MapHandler<PFP3>* h = new MapHandler<PFP3>(fi.baseName(), m_window, map);
MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
if(mhg)
{
MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
PFP3::MAP* map = mh->getMap();
std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
std::vector<std::string> attrNames ;
Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, CGoGN::VERTEX>(attrNames[0]);
// get vertex position attribute
VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, CGoGN::VERTEX>(attrNames[0]);
// create VBO for vertex position attribute
h->createVBO(position);
// create VBO for vertex position attribute
mh->createVBO(position);
// compute map bounding box
h->updateBB(position);
// compute map bounding box
mh->updateBB(position);
// compute primitive connectivity VBOs
h->updatePrimitives(Algo::Render::GL2::POINTS);
h->updatePrimitives(Algo::Render::GL2::LINES);
h->updatePrimitives(Algo::Render::GL2::TRIANGLES);
m_window->addMap(h);
// compute primitive connectivity VBOs
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
}
}
void ImportVolumePlugin::importFromFileDialog()
{
QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
importFromFile(fileName);
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else
......
#ifndef _IMPORTSURFACE_PLUGIN_H_
#define _IMPORTSURFACE_PLUGIN_H_
#ifndef _IMPORTVOLUME_PLUGIN_H_
#define _IMPORTVOLUME_PLUGIN_H_
#include "plugin.h"
......@@ -38,11 +38,9 @@ public:
virtual void viewUnlinked(View* view) {}
virtual void currentViewChanged(View* view) {}
virtual void mapLinked(View* view, MapHandlerGen* m) {}
virtual void mapUnlinked(View* view, MapHandlerGen* m) {}
public slots:
void cb_import();
void importFromFile(const QString& fileName);
void importFromFileDialog();
private:
QAction* importAction;
......
This diff is collapsed.
......@@ -100,9 +100,6 @@ public:
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m);
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
......@@ -117,10 +114,23 @@ protected:
bool b_refreshingUI;
public slots:
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeNormalVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeRenderVertices(View* view, MapHandlerGen* map, bool b);
void changeVerticesScaleFactor(View* view, MapHandlerGen* map, int i);
void changeRenderEdges(View* view, MapHandlerGen* map, bool b);
void changeRenderFaces(View* view, MapHandlerGen* map, bool b);
void changeFacesStyle(View* view, MapHandlerGen* map, FaceShadingStyle style);
void cb_selectedMapChanged();
void cb_positionVBOChanged(int index);
void cb_normalVBOChanged(int index);
void cb_refreshVBOs();
void cb_renderVerticesChanged(bool b);
void cb_verticesScaleFactorChanged(int i);
void cb_renderEdgesChanged(bool b);
......
......@@ -22,17 +22,10 @@
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Normal :</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_normalVBO">
<item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -46,29 +39,20 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="combo_positionVBO">
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Refresh</string>
<string>Normal :</string>
</property>
</widget>
</item>
......
......@@ -33,8 +33,7 @@ bool RenderVectorPlugin::enable()
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->list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedVectorVBOChanged()));
connect(m_dockTab->button_refreshVBOs, SIGNAL(clicked()), this, SLOT(cb_refreshVBOs()));
connect(m_dockTab->list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(cb_selectedVectorsVBOChanged()));
connect(m_dockTab->slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(cb_vectorsScaleFactorChanged(int)));
return true;
......@@ -80,16 +79,19 @@ void RenderVectorPlugin::viewLinked(View* view)
if (!maps.empty())
params->selectedMap = maps[0];
m_dockTab->refreshUI(params);
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);
}
void RenderVectorPlugin::viewUnlinked(View* view)
{
h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
disconnect(view, SIGNAL(mapLinked(MapHandlerGen*)), this, SLOT(mapLinked(MapHandlerGen*)));
disconnect(view, SIGNAL(mapUnlinked(MapHandlerGen*)), this, SLOT(mapUnlinked(MapHandlerGen*)));
}
void RenderVectorPlugin::currentViewChanged(View* view)
......@@ -98,31 +100,106 @@ void RenderVectorPlugin::currentViewChanged(View* view)
m_dockTab->refreshUI(h_viewParams[view]);
}
void RenderVectorPlugin::mapLinked(View* view, MapHandlerGen* m)
void RenderVectorPlugin::mapLinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
PerMapParameterSet p(m);
params->perMap.insert(m->getName(), p);
if(params->perMap.count() == 1)
params->selectedMap = m;
m_dockTab->refreshUI(params);
if(params->selectedMap == NULL || params->perMap.count() == 1)
changeSelectedMap(view, m);
else
m_dockTab->refreshUI(params);
}
void RenderVectorPlugin::mapUnlinked(View* view, MapHandlerGen* m)
void RenderVectorPlugin::mapUnlinked(MapHandlerGen* m)
{
View* view = static_cast<View*>(QObject::sender());
assert(isLinkedToView(view));
ParameterSet* params = h_viewParams[view];
params->perMap.remove(m->getName());
if(params->selectedMap == m)
{
if(!params->perMap.empty())
params->selectedMap = m_window->getMap(params->perMap.begin().key());
changeSelectedMap(view, m_window->getMap(params->perMap.begin().key()));
else
params->selectedMap = NULL;
changeSelectedMap(view, NULL);
}
else
m_dockTab->refreshUI(params);
}
void RenderVectorPlugin::vboAdded(Utils::VBO* vbo)
{
m_dockTab->refreshUI(h_viewParams[m_window->getCurrentView()]);
}
void RenderVectorPlugin::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);
}
void RenderVectorPlugin::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 RenderVectorPlugin::changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].positionVBO = vbo;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderVectorPlugin::changeSelectedVectorsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].vectorVBO = vbos;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
void RenderVectorPlugin::changeVectorsScaleFactor(View* view, MapHandlerGen* map, int i)
{
ParameterSet* params = h_viewParams[view];
params->perMap[map->getName()].vectorsScaleFactor = i / 50.0;
if(view->isCurrentView())
{
m_dockTab->refreshUI(params);
view->updateGL();
}
}
......@@ -130,16 +207,9 @@ void RenderVectorPlugin::cb_selectedMapChanged()
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
ParameterSet* params = h_viewParams[view];
QList<QListWidgetItem*> currentItems = m_dockTab->mapList->selectedItems();
if(!currentItems.empty())
{
const QString& mapname = currentItems[0]->text();
params->selectedMap = m_window->getMap(mapname);
m_dockTab->refreshUI(params);
view->updateGL();
}
changeSelectedMap(m_window->getCurrentView(), m_window->getMap(currentItems[0]->text()));
}
}
......@@ -147,48 +217,33 @@ void RenderVectorPlugin::cb_positionVBOChanged(int index)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
params->perMap[map->getName()].positionVBO = map->getVBO(m_dockTab->combo_positionVBO->currentText());
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changePositionVBO(view, map, map->getVBO(m_dockTab->combo_positionVBO->currentText()));
}
}
void RenderVectorPlugin::cb_selectedVectorVBOChanged()
void RenderVectorPlugin::cb_selectedVectorsVBOChanged()
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* map = params->selectedMap;
PerMapParameterSet& mapParam = params->perMap[map->getName()];
mapParam.vectorVBO.clear();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
QList<QListWidgetItem*> currentItems = m_dockTab->list_vectorVBO->selectedItems();
std::vector<Utils::VBO*> vbos;
foreach(QListWidgetItem* item, currentItems)
mapParam.vectorVBO.push_back(map->getVBO(item->text()));
current->updateGL();
vbos.push_back(map->getVBO(item->text()));
changeSelectedVectorsVBO(view, map, vbos);
}
}
void RenderVectorPlugin::cb_refreshVBOs()
{
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
}
void RenderVectorPlugin::cb_vectorsScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* current = m_window->getCurrentView();
ParameterSet* params = h_viewParams[current];
MapHandlerGen* m = params->selectedMap;
params->perMap[m->getName()].vectorsScaleFactor = i / 50.0;
current->updateGL();
View* view = m_window->getCurrentView();
MapHandlerGen* map = h_viewParams[view]->selectedMap;
changeVectorsScaleFactor(view, map, i);
}
}
......@@ -219,23 +274,24 @@ void RenderVectorDockTab::refreshUI(ParameterSet* params)
unsigned int j = 0;
for(int i = 0; i < vbos.count(); ++i)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.positionVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "position") // try to select a VBO named "position"
{
p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(i);
}
}
else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(i);
if(vbos[i]->dataSize() == 3)
{
combo_positionVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(p.positionVBO == NULL)
{ // if nothing is specified in the parameter set
if(vbos[i]->name() == "position") // try to select a VBO named "position"
{
p.positionVBO = vbos[i];
combo_positionVBO->setCurrentIndex(j);
}
}
else if(vbos[i] == p.positionVBO)
combo_positionVBO->setCurrentIndex(j);
list_vectorVBO->addItem(QString::fromStdString(vbos[i]->name()));
if(std::find(p.vectorVBO.begin(), p.vectorVBO.end(), vbos[i]) != p.vectorVBO.end())
list_vectorVBO->item(j)->setSelected(true);
++j;
}
}
......
......@@ -82,9 +82,6 @@ public:
virtual void viewUnlinked(View* view);
virtual void currentViewChanged(View* view);
virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m);
void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected:
......@@ -96,10 +93,19 @@ protected:
bool b_refreshingUI;
public slots:
void mapLinked(MapHandlerGen* m);
void mapUnlinked(MapHandlerGen* m);
void vboAdded(Utils::VBO* vbo);
void vboRemoved(Utils::VBO* vbo);
void changeSelectedMap(View* view, MapHandlerGen* map);
void changePositionVBO(View* view, MapHandlerGen* map, Utils::VBO* vbo);
void changeSelectedVectorsVBO(View* view, MapHandlerGen* map, const std::vector<Utils::VBO*>& vbos);
void changeVectorsScaleFactor(View* view, MapHandlerGen* map, int i);
void cb_selectedMapChanged();
void cb_positionVBOChanged(int index);
void cb_selectedVectorVBOChanged();
void cb_refreshVBOs();
void cb_selectedVectorsVBOChanged();
void cb_vectorsScaleFactorChanged(int i);
};
......
......@@ -52,22 +52,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
......
......@@ -36,6 +36,10 @@ public:
virtual void mouseMove(View* view, int buttons, 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:
void openSubdivideSurfaceDialog();
void subdivideSurface();
......
......@@ -36,6 +36,7 @@ file(
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/view.h
${SCHNApps_ROOT_DIR}/include/mapHandler.h
${SCHNApps_ROOT_DIR}/include/window.h
${SCHNApps_ROOT_DIR}/include/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/dialogs/camerasDialog.h
......
......@@ -20,8 +20,10 @@ namespace CGoGN
namespace SCHNApps
{
class MapHandlerGen
class MapHandlerGen : public QObject
{
Q_OBJECT
public:
MapHandlerGen(const QString& name, Window* window, GenericMap* map);
virtual ~MapHandlerGen();
......@@ -49,8 +51,15 @@ public:
template <typename ATTR_HANDLER>
Utils::VBO* createVBO(const ATTR_HANDLER& attr)
{
Utils::VBO* vbo = getVBO(QString::fromStdString(attr.name()));
QString name = QString::fromStdString(attr.name());
Utils::VBO* vbo = getVBO(name);
if(!vbo)
{
vbo = new Utils::VBO();
h_vbo.insert(name, vbo);
}
vbo->updateData(attr);
emit(vboAdded(vbo));
return vbo;
}
......@@ -58,7 +67,8 @@ public:
void updateVBO(const ATTR_HANDLER& attr)
{
Utils::VBO* vbo = getVBO(QString::fromStdString(attr.name()));
vbo->updateData(attr);
if(vbo)
vbo->updateData(attr);
}
Utils::VBO* getVBO(const QString& name);
......@@ -89,6 +99,10 @@ protected:
QList<View*> l_views;
VBOHash h_vbo;
signals: