Commit 8f0aab16 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps: parameterSet management in render plugins

parent cadb8aed
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
bool ImportPlugin::enable() bool ImportPlugin::enable()
{ {
importAction = new QAction("import", this); importAction = new QAction("import", this);
addMenuAction("Import;import", importAction); addMenuAction("Import;Import Surface", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import())); connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
return true; return true;
} }
...@@ -38,8 +38,6 @@ void ImportPlugin::cb_import() ...@@ -38,8 +38,6 @@ void ImportPlugin::cb_import()
// create VBO for vertex position attribute // create VBO for vertex position attribute
h->createVBO(position); h->createVBO(position);
// Utils::VBO* positionVBO = h->getVBO(position.name());
// positionVBO->updateData(position);
// compute vertex normal attribute // compute vertex normal attribute
VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal"); VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal");
...@@ -49,8 +47,6 @@ void ImportPlugin::cb_import() ...@@ -49,8 +47,6 @@ void ImportPlugin::cb_import()
// create VBO for vertex normal attribute // create VBO for vertex normal attribute
h->createVBO(normal); h->createVBO(normal);
// CGoGN::Utils::VBO* normalVBO = h->getVBO(normal);
// normalVBO->updateData(normal);
// compute map bounding box // compute map bounding box
h->updateBB(position); h->updateBB(position);
......
...@@ -50,7 +50,7 @@ void RenderPlugin::disable() ...@@ -50,7 +50,7 @@ void RenderPlugin::disable()
void RenderPlugin::redraw(View* view) void RenderPlugin::redraw(View* view)
{ {
TabParams* params = h_viewParams[view]; ParameterSet* params = h_viewParams[view];
const QList<MapHandlerGen*>& maps = view->getLinkedMaps(); const QList<MapHandlerGen*>& maps = view->getLinkedMaps();
foreach(MapHandlerGen* m, maps) foreach(MapHandlerGen* m, maps)
...@@ -96,23 +96,22 @@ void RenderPlugin::redraw(View* view) ...@@ -96,23 +96,22 @@ void RenderPlugin::redraw(View* view)
void RenderPlugin::viewLinked(View* view) void RenderPlugin::viewLinked(View* view)
{ {
h_viewParams.insert(view, new TabParams(1.0, false, false, true, FLAT)); h_viewParams.insert(view, new ParameterSet());
m_dockTab->refreshUI(h_viewParams[view]);
} }
void RenderPlugin::viewUnlinked(View* view) void RenderPlugin::viewUnlinked(View* view)
{ {
h_viewParams.remove(view); h_viewParams.remove(view);
View* current = m_window->getCurrentView();
if(isLinkedToView(current))
m_dockTab->refreshUI(h_viewParams[current]);
} }
void RenderPlugin::currentViewChanged(View* view) void RenderPlugin::currentViewChanged(View* view)
{ {
TabParams* params = h_viewParams[view]; assert(isLinkedToView(view));
m_dockTab->check_renderVertices->setChecked(params->renderVertices); m_dockTab->refreshUI(h_viewParams[view]);
m_dockTab->slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
m_dockTab->check_renderEdges->setChecked(params->renderEdges);
m_dockTab->check_renderFaces->setChecked(params->renderFaces);
m_dockTab->radio_flatShading->setChecked(params->faceStyle == FLAT);
m_dockTab->radio_phongShading->setChecked(params->faceStyle == PHONG);
} }
void RenderPlugin::cb_renderVerticesChanged(bool b) void RenderPlugin::cb_renderVerticesChanged(bool b)
...@@ -120,7 +119,7 @@ void RenderPlugin::cb_renderVerticesChanged(bool b) ...@@ -120,7 +119,7 @@ void RenderPlugin::cb_renderVerticesChanged(bool b)
View* current = m_window->getCurrentView(); View* current = m_window->getCurrentView();
assert(isLinkedToView(current)); assert(isLinkedToView(current));
TabParams* params = h_viewParams[current]; ParameterSet* params = h_viewParams[current];
params->renderVertices = b; params->renderVertices = b;
current->updateGL(); current->updateGL();
} }
...@@ -130,7 +129,7 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i) ...@@ -130,7 +129,7 @@ void RenderPlugin::cb_verticesScaleFactorChanged(int i)
View* current = m_window->getCurrentView(); View* current = m_window->getCurrentView();
assert(isLinkedToView(current)); assert(isLinkedToView(current));
TabParams* params = h_viewParams[current]; ParameterSet* params = h_viewParams[current];
params->verticesScaleFactor = i / 50.0; params->verticesScaleFactor = i / 50.0;
current->updateGL(); current->updateGL();
} }
...@@ -140,7 +139,7 @@ void RenderPlugin::cb_renderEdgesChanged(bool b) ...@@ -140,7 +139,7 @@ void RenderPlugin::cb_renderEdgesChanged(bool b)
View* current = m_window->getCurrentView(); View* current = m_window->getCurrentView();
assert(isLinkedToView(current)); assert(isLinkedToView(current));
TabParams* params = h_viewParams[current]; ParameterSet* params = h_viewParams[current];
params->renderEdges = b; params->renderEdges = b;
current->updateGL(); current->updateGL();
} }
...@@ -150,7 +149,7 @@ void RenderPlugin::cb_renderFacesChanged(bool b) ...@@ -150,7 +149,7 @@ void RenderPlugin::cb_renderFacesChanged(bool b)
View* current = m_window->getCurrentView(); View* current = m_window->getCurrentView();
assert(isLinkedToView(current)); assert(isLinkedToView(current));
TabParams* params = h_viewParams[current]; ParameterSet* params = h_viewParams[current];
params->renderFaces = b; params->renderFaces = b;
current->updateGL(); current->updateGL();
} }
...@@ -160,7 +159,7 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b) ...@@ -160,7 +159,7 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
View* current = m_window->getCurrentView(); View* current = m_window->getCurrentView();
assert(isLinkedToView(current)); assert(isLinkedToView(current));
TabParams* params = h_viewParams[current]; ParameterSet* params = h_viewParams[current];
if(m_dockTab->radio_flatShading->isChecked()) if(m_dockTab->radio_flatShading->isChecked())
params->faceStyle = FLAT; params->faceStyle = FLAT;
else if(m_dockTab->radio_phongShading->isChecked()) else if(m_dockTab->radio_phongShading->isChecked())
...@@ -168,6 +167,21 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b) ...@@ -168,6 +167,21 @@ void RenderPlugin::cb_faceStyleChanged(QAbstractButton* b)
current->updateGL(); current->updateGL();
} }
void RenderDockTab::refreshUI(ParameterSet* params)
{
check_renderVertices->setChecked(params->renderVertices);
slider_verticesScaleFactor->setSliderPosition(params->verticesScaleFactor * 50.0);
check_renderEdges->setChecked(params->renderEdges);
check_renderFaces->setChecked(params->renderFaces);
radio_flatShading->setChecked(params->faceStyle == FLAT);
radio_phongShading->setChecked(params->faceStyle == PHONG);
}
/** /**
* If we want to compile this plugin in debug mode, * If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation * we also define a DEBUG macro at the compilation
......
...@@ -18,27 +18,20 @@ using namespace CGoGN; ...@@ -18,27 +18,20 @@ using namespace CGoGN;
using namespace SCHNApps; using namespace SCHNApps;
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
RenderDockTab() { setupUi(this); }
};
enum FaceShadingStyle enum FaceShadingStyle
{ {
FLAT = 0, FLAT = 0,
PHONG = 1 PHONG = 1
}; };
struct TabParams struct ParameterSet
{ {
TabParams(float vsf, bool rv, bool re, bool rf, FaceShadingStyle fstyle) : ParameterSet() :
verticesScaleFactor(vsf), verticesScaleFactor(1.0f),
renderVertices(rv), renderVertices(false),
renderEdges(re), renderEdges(false),
renderFaces(rf), renderFaces(true),
faceStyle(fstyle) faceStyle(FLAT)
{} {}
float verticesScaleFactor; float verticesScaleFactor;
...@@ -49,6 +42,15 @@ struct TabParams ...@@ -49,6 +42,15 @@ struct TabParams
}; };
class RenderDockTab : public QWidget, public Ui::RenderWidget
{
public:
RenderDockTab() { setupUi(this); }
void refreshUI(ParameterSet* params);
};
class RenderPlugin : public Plugin class RenderPlugin : public Plugin
{ {
Q_OBJECT Q_OBJECT
...@@ -84,7 +86,7 @@ public: ...@@ -84,7 +86,7 @@ public:
protected: protected:
RenderDockTab* m_dockTab; RenderDockTab* m_dockTab;
QHash<View*, TabParams*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
CGoGN::Utils::ShaderFlat* m_flatShader; CGoGN::Utils::ShaderFlat* m_flatShader;
CGoGN::Utils::ShaderPhong* m_phongShader; CGoGN::Utils::ShaderPhong* m_phongShader;
......
...@@ -15,17 +15,12 @@ using namespace CGoGN; ...@@ -15,17 +15,12 @@ using namespace CGoGN;
using namespace SCHNApps; using namespace SCHNApps;
class RenderVectorDockTab : public QWidget, public Ui::RenderVectorWidget struct PerMapParameterSet
{
public:
RenderVectorDockTab() { setupUi(this); }
};
struct PerMapTabParams
{ {
PerMapTabParams() {} PerMapParameterSet() : positionVBO(NULL), vectorVBO(NULL), vectorsScaleFactor(1.0f)
{}
PerMapTabParams(Utils::VBO* pos, Utils::VBO* vec, float s) : PerMapParameterSet(Utils::VBO* pos, Utils::VBO* vec, float s) :
positionVBO(pos), positionVBO(pos),
vectorVBO(vec), vectorVBO(vec),
vectorsScaleFactor(s) vectorsScaleFactor(s)
...@@ -36,20 +31,40 @@ struct PerMapTabParams ...@@ -36,20 +31,40 @@ struct PerMapTabParams
float vectorsScaleFactor; float vectorsScaleFactor;
}; };
struct TabParams struct ParameterSet
{ {
QHash<QString, PerMapTabParams> perMap; ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet> perMap;
MapHandlerGen* selectedMap; MapHandlerGen* selectedMap;
}; };
class RenderVectorPlugin;
class RenderVectorDockTab : public QWidget, public Ui::RenderVectorWidget
{
public:
RenderVectorDockTab(RenderVectorPlugin* p) : plugin(p)
{
setupUi(this);
}
void refreshUI(ParameterSet* params);
private:
RenderVectorPlugin* plugin;
};
class RenderVectorPlugin : public Plugin class RenderVectorPlugin : public Plugin
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin) Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public: public:
RenderVectorPlugin() RenderVectorPlugin() : b_refreshingUI(false)
{ {
setProvidesRendering(true); setProvidesRendering(true);
} }
...@@ -76,14 +91,16 @@ public: ...@@ -76,14 +91,16 @@ public:
virtual void mapLinked(View* view, MapHandlerGen* m); virtual void mapLinked(View* view, MapHandlerGen* m);
virtual void mapUnlinked(View* view, MapHandlerGen* m); virtual void mapUnlinked(View* view, MapHandlerGen* m);
void refreshTabInfo(); void setRefreshingUI(bool b) { b_refreshingUI = b; }
protected: protected:
RenderVectorDockTab* m_dockTab; RenderVectorDockTab* m_dockTab;
QHash<View*, TabParams*> h_viewParams; QHash<View*, ParameterSet*> h_viewParams;
CGoGN::Utils::ShaderVectorPerVertex* m_vectorShader; CGoGN::Utils::ShaderVectorPerVertex* m_vectorShader;
bool b_refreshingUI;
public slots: public slots:
void cb_selectedMapChanged(); void cb_selectedMapChanged();
void cb_positionVBOChanged(int index); void cb_positionVBOChanged(int index);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>184</width> <width>174</width>
<height>487</height> <height>487</height>
</rect> </rect>
</property> </property>
...@@ -14,22 +14,6 @@ ...@@ -14,22 +14,6 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<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> <item>
<widget class="QListWidget" name="mapList"/> <widget class="QListWidget" name="mapList"/>
</item> </item>
...@@ -45,6 +29,16 @@ ...@@ -45,6 +29,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="combo_vectorVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
...@@ -62,14 +56,20 @@ ...@@ -62,14 +56,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="2"> <item row="2" column="2" alignment="Qt::AlignRight">
<widget class="QComboBox" name="combo_vectorVBO"> <widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
......
...@@ -95,9 +95,14 @@ void Window::addTabInDock(QWidget* tabWidget, const QString& tabText) ...@@ -95,9 +95,14 @@ void Window::addTabInDock(QWidget* tabWidget, const QString& tabText)
{ {
if(tabWidget) if(tabWidget)
{ {
int currentTab = m_dockTabWidget->currentIndex();
int idx = m_dockTabWidget->addTab(tabWidget, tabText); int idx = m_dockTabWidget->addTab(tabWidget, tabText);
m_dock->setVisible(true); m_dock->setVisible(true);
m_dockTabWidget->setTabEnabled(idx, false); m_dockTabWidget->setTabEnabled(idx, false);
if(currentTab != -1)
m_dockTabWidget->setCurrentIndex(currentTab);
} }
} }
...@@ -109,22 +114,24 @@ void Window::removeTabInDock(QWidget *tabWidget) ...@@ -109,22 +114,24 @@ void Window::removeTabInDock(QWidget *tabWidget)
void Window::enablePluginTabWidgets(Plugin* plugin) void Window::enablePluginTabWidgets(Plugin* plugin)
{ {
int currentTab = m_dockTabWidget->currentIndex();
const QList<QWidget*> tabWidgets = plugin->getTabWidgets(); const QList<QWidget*> tabWidgets = plugin->getTabWidgets();
foreach(QWidget* w, tabWidgets) foreach(QWidget* w, tabWidgets)
{ m_dockTabWidget->setTabEnabled(m_dockTabWidget->indexOf(w), true);
int idx = m_dockTabWidget->indexOf(w);
m_dockTabWidget->setTabEnabled(idx, true); m_dockTabWidget->setCurrentIndex(currentTab);
}
} }
void Window::disablePluginTabWidgets(Plugin* plugin) void Window::disablePluginTabWidgets(Plugin* plugin)
{ {
int currentTab = m_dockTabWidget->currentIndex();
const QList<QWidget*> tabWidgets = plugin->getTabWidgets(); const QList<QWidget*> tabWidgets = plugin->getTabWidgets();
foreach(QWidget* w, tabWidgets) foreach(QWidget* w, tabWidgets)
{ m_dockTabWidget->setTabEnabled(m_dockTabWidget->indexOf(w), false);
int idx = m_dockTabWidget->indexOf(w);
m_dockTabWidget->setTabEnabled(idx, false); m_dockTabWidget->setCurrentIndex(currentTab);
}
} }
/********************************************************* /*********************************************************
......
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