Commit dbe4add0 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' into 'develop'

Develop

See merge request !60
parents 36744b8a f6a1f2bf
......@@ -14,6 +14,16 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0" colspan="2">
<widget class="QLineEdit" name="selectedName">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="ColorComboBox" name="combo_color"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
......@@ -50,14 +60,20 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
<item row="11" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QSlider" name="slider_vectorsScaleFactor">
<property name="value">
<number>50</number>
......@@ -67,21 +83,42 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Vectors Size :</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>156</width>
<height>161</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorComboBox</class>
<extends>QComboBox</extends>
<header>colorComboBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -12,16 +12,34 @@ namespace CGoGN
namespace SCHNApps
{
//struct SVectorInfo
//{
// Utils::VBO* vbo;
// QColor color;
// float scaleFactor;
// SVectorInfo() :
// vbo(NULL), color(QColor("red")), scaleFactor(1.0f)
// {}
// SVectorInfo(Utils::VBO* ptr) :
// vbo(ptr), color(QColor("red")), scaleFactor(1.0f)
// {}
//};
struct MapParameters
{
MapParameters() :
positionVBO(NULL),
vectorsScaleFactor(1.0f)
positionVBO(NULL)
{}
Utils::VBO* positionVBO;
QList<Utils::VBO*> vectorVBOs;
float vectorsScaleFactor;
QList<QColor> colors;
QList<float> scaleFactors;
//float vectorsScaleFactor;
};
class Surface_RenderVector_Plugin : public PluginInteraction
......@@ -72,7 +90,8 @@ public slots:
void changePositionVBO(const QString& view, const QString& map, const QString& vbo);
void addVectorVBO(const QString& view, const QString& map, const QString& vbo);
void removeVectorVBO(const QString& view, const QString& map, const QString& vbo);
void changeVectorsScaleFactor(const QString& view, const QString& map, float f);
void changeVectorScaleFactor(const QString& view, const QString& map, const QString& vbo, float f);
void changeVectorColor(const QString& view, const QString& map, const QString& vbo, const QString& col);
protected:
Surface_RenderVector_DockTab* m_dockTab;
......
......@@ -26,11 +26,15 @@ private:
SCHNApps* m_schnapps;
Surface_RenderVector_Plugin* m_plugin;
bool b_updatingUI;
int m_current_vbo;
QString m_currentVBOName;
private slots:
void positionVBOChanged(int index);
void selectedVectorsVBOChanged();
void selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old);
void vectorsVBOChecked(QListWidgetItem* item);
void vectorsScaleFactorChanged(int i);
void colorChanged(int i);
private:
void addPositionVBO(QString name);
......
......@@ -51,13 +51,29 @@ void Surface_RenderVector_Plugin::drawMap(View* view, MapHandlerGen* map)
{
const MapParameters& p = h_viewParameterSet[view][map];
m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
if(p.positionVBO)
//m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.vectorsScaleFactor) ;
//if(p.positionVBO)
//{
// m_vectorShader->setAttributePosition(p.positionVBO);
// for(QList<Utils::VBO*>::const_iterator it = p.vectorVBOs.begin(); it != p.vectorVBOs.end(); ++it)
// {
// m_vectorShader->setAttributeVector(*it);
// glLineWidth(1.0f);
// map->draw(m_vectorShader, Algo::Render::GL2::POINTS);
// }
//}
if (p.positionVBO)
{
m_vectorShader->setAttributePosition(p.positionVBO);
for(QList<Utils::VBO*>::const_iterator it = p.vectorVBOs.begin(); it != p.vectorVBOs.end(); ++it)
int nb = p.vectorVBOs.size();
for (int i = 0; i < nb; ++i)
{
m_vectorShader->setAttributeVector(*it);
m_vectorShader->setAttributeVector(p.vectorVBOs[i]);
m_vectorShader->setScale(map->getBBdiagSize() / 100.0f * p.scaleFactors[i]);
const QColor& col = p.colors[i];
m_vectorShader->setColor(Geom::Vec4f(col.redF(), col.greenF(), col.blueF(), 0.0f));
glLineWidth(1.0f);
map->draw(m_vectorShader, Algo::Render::GL2::POINTS);
}
......@@ -177,6 +193,8 @@ void Surface_RenderVector_Plugin::addVectorVBO(const QString& view, const QStrin
{
Utils::VBO* vbuf = m->getVBO(vbo);
h_viewParameterSet[v][m].vectorVBOs.append(vbuf);
h_viewParameterSet[v][m].colors.append(QColor("red"));
h_viewParameterSet[v][m].scaleFactors.append(1.0f);
if(v->isSelectedView())
{
if(v->isLinkedToMap(m)) v->updateGL();
......@@ -192,7 +210,10 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt
if(v && m)
{
Utils::VBO* vbuf = m->getVBO(vbo);
h_viewParameterSet[v][m].vectorVBOs.removeOne(vbuf);
int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vbuf);
h_viewParameterSet[v][m].vectorVBOs.removeAt(idx);
h_viewParameterSet[v][m].colors.removeAt(idx);
h_viewParameterSet[v][m].scaleFactors.removeAt(idx);
if(v->isSelectedView())
{
if(v->isLinkedToMap(m)) v->updateGL();
......@@ -201,17 +222,38 @@ void Surface_RenderVector_Plugin::removeVectorVBO(const QString& view, const QSt
}
}
void Surface_RenderVector_Plugin::changeVectorsScaleFactor(const QString& view, const QString& map, float f)
void Surface_RenderVector_Plugin::changeVectorScaleFactor(const QString& view, const QString& map, const QString& vbo, float f)
{
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map);
if(v && m)
{
h_viewParameterSet[v][m].vectorsScaleFactor = f;
Utils::VBO* vboPtr = m->getVBO(vbo);
int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vboPtr);
h_viewParameterSet[v][m].scaleFactors[idx] = f;
if(v->isSelectedView())
{
if(v->isLinkedToMap(m)) v->updateGL();
if(m->isSelectedMap()) m_dockTab->updateMapParameters();
if (m->isSelectedMap()) m_dockTab->updateMapParameters();
}
}
}
void Surface_RenderVector_Plugin::changeVectorColor(const QString& view, const QString& map, const QString& vbo, const QString& col)
{
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map);
if (v && m)
{
Utils::VBO* vboPtr = m->getVBO(vbo);
int idx = h_viewParameterSet[v][m].vectorVBOs.indexOf(vboPtr);
h_viewParameterSet[v][m].colors[idx] = QColor(col);
if (v->isSelectedView())
{
if (v->isLinkedToMap(m)) v->updateGL();
if (m->isSelectedMap()) m_dockTab->updateMapParameters();
}
}
}
......
......@@ -15,17 +15,27 @@ namespace SCHNApps
Surface_RenderVector_DockTab::Surface_RenderVector_DockTab(SCHNApps* s, Surface_RenderVector_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
b_updatingUI(false),
m_current_vbo(-1)
{
setupUi(this);
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(list_vectorVBO, SIGNAL(itemSelectionChanged()), this, SLOT(selectedVectorsVBOChanged()));
connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
}
list_vectorVBO->setSelectionMode(QAbstractItemView::SingleSelection);
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
QFont font = selectedName->font();
font.setBold(true);
selectedName->setFont(font);
selectedName->setText("not selected");
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(slider_vectorsScaleFactor, SIGNAL(valueChanged(int)), this, SLOT(vectorsScaleFactorChanged(int)));
connect(list_vectorVBO, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(vectorsVBOChecked(QListWidgetItem*)));
connect(list_vectorVBO, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(selectedVectorVBOChanged(QListWidgetItem*, QListWidgetItem*)));
connect(combo_color, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
}
void Surface_RenderVector_DockTab::positionVBOChanged(int index)
......@@ -43,53 +53,123 @@ void Surface_RenderVector_DockTab::positionVBOChanged(int index)
}
}
void Surface_RenderVector_DockTab::selectedVectorsVBOChanged()
void Surface_RenderVector_DockTab::selectedVectorVBOChanged(QListWidgetItem* item, QListWidgetItem* old)
{
if(!b_updatingUI)
{
if ((item->checkState() == Qt::Checked))
{
selectedName->setText(item->text());
slider_vectorsScaleFactor->setEnabled(true);
combo_color->setEnabled(true);
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map)
{
const MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* v = map->getVBO(item->text());
m_current_vbo = p.vectorVBOs.indexOf(v);
if (m_current_vbo >= 0)
{
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0f);
std::cout << item->text().toStdString() << " : " << p.scaleFactors[m_current_vbo] << " / " << slider_vectorsScaleFactor->value() << std::endl;
combo_color->setColor(p.colors[m_current_vbo]);
}
}
}
else
{
selectedName->setText("not selected");
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
}
}
}
void Surface_RenderVector_DockTab::vectorsVBOChecked(QListWidgetItem* item)
{
if (!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
if (view && map)
{
QList<QListWidgetItem*> currentItems = list_vectorVBO->selectedItems();
QList<Utils::VBO*> vbos;
const QList<Utils::VBO*>& vboList = m_plugin->h_viewParameterSet[view][map].vectorVBOs;
foreach(QListWidgetItem* item, currentItems)
MapParameters& p = m_plugin->h_viewParameterSet[view][map];
Utils::VBO* vbo = map->getVBO(item->text());
if (item->checkState() == Qt::Checked)
{
Utils::VBO* vbo = map->getVBO(item->text());
vbos.append(vbo);
if (!vboList.contains(vbo))
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
p.vectorVBOs.append(vbo);
p.scaleFactors.append(1.0f);
p.colors.append(QColor("red"));
if (list_vectorVBO->currentItem() == item)
selectedVectorVBOChanged(item, NULL);
else
list_vectorVBO->setCurrentItem(item);
m_plugin->pythonRecording("addVectorVBO", "", view->getName(), map->getName(), item->text());
}
foreach(Utils::VBO* vbo, vboList)
else
{
if (!vbos.contains(vbo))
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(vbo->name().c_str()));
int idx = p.vectorVBOs.indexOf(vbo);
p.vectorVBOs.removeAt(idx);
p.scaleFactors.removeAt(idx);
p.colors.removeAt(idx);
list_vectorVBO->setCurrentItem(item);
list_vectorVBO->clearSelection();
slider_vectorsScaleFactor->setDisabled(true);
combo_color->setDisabled(true);
m_current_vbo = -1;
m_plugin->pythonRecording("removeVectorVBO", "", view->getName(), map->getName(), QString(item->text()));
}
m_plugin->h_viewParameterSet[view][map].vectorVBOs = vbos;
view->updateGL();
}
}
}
void Surface_RenderVector_DockTab::vectorsScaleFactorChanged(int i)
{
if(!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
if (view && map && (m_current_vbo>=0))
{
m_plugin->h_viewParameterSet[view][map].vectorsScaleFactor = i / 50.0;
view->updateGL();
float& scale = m_plugin->h_viewParameterSet[view][map].scaleFactors[m_current_vbo];
float newScale = float(i) / 50.0f;
std::cout << "vectorsScaleFactorChanged " << i << " -> " << newScale << " / old:" << scale << std::endl;
if (fabs(scale - newScale) > 0.01f)
{
scale = newScale;
m_plugin->pythonRecording("changeVectorScaleFactor", "", view->getName(), map->getName(),
selectedName->text(), newScale);
view->updateGL();
}
}
}
}
void Surface_RenderVector_DockTab::colorChanged(int i)
{
if (!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map && (m_current_vbo >= 0))
{
QColor& col = m_plugin->h_viewParameterSet[view][map].colors[m_current_vbo];
if (col != combo_color->color())
{
col = combo_color->color();
m_plugin->pythonRecording("changeVectorColor", "", view->getName(), map->getName(),
selectedName->text(), combo_color->color().name());
view->updateGL();
}
}
}
}
void Surface_RenderVector_DockTab::addPositionVBO(QString name)
......@@ -114,6 +194,9 @@ void Surface_RenderVector_DockTab::addVectorVBO(QString name)
{
b_updatingUI = true;
list_vectorVBO->addItem(name);
QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setCheckState(Qt::Unchecked);
b_updatingUI = false;
}
......@@ -128,6 +211,8 @@ void Surface_RenderVector_DockTab::removeVectorVBO(QString name)
void Surface_RenderVector_DockTab::updateMapParameters()
{
std::cout << "Surface_RenderVector_DockTab::updateMapParameters" << std::endl;
b_updatingUI = true;
combo_positionVBO->clear();
......@@ -148,17 +233,23 @@ void Surface_RenderVector_DockTab::updateMapParameters()
{
combo_positionVBO->addItem(QString::fromStdString(vbo->name()));
if(vbo == p.positionVBO)
combo_positionVBO->setCurrentIndex(i);
combo_positionVBO->setCurrentIndex(i+1); // +1 for "- select VBO -"
list_vectorVBO->addItem(QString::fromStdString(vbo->name()));
QListWidgetItem* item = list_vectorVBO->item(list_vectorVBO->count() - 1);
item->setFlags(item->flags() | Qt::ItemIsEditable);
item->setCheckState(Qt::Unchecked);
if(p.vectorVBOs.contains(vbo))
list_vectorVBO->item(i)->setSelected(true);
list_vectorVBO->item(i)->setCheckState(Qt::Checked);
++i;
}
}
slider_vectorsScaleFactor->setSliderPosition(p.vectorsScaleFactor * 50.0);
if (m_current_vbo >= 0)
{
slider_vectorsScaleFactor->setSliderPosition(p.scaleFactors[m_current_vbo] * 50.0f);
combo_color->setColor(p.colors[m_current_vbo]);
}
// set color
}
b_updatingUI = false;
......
......@@ -26,6 +26,8 @@ public:
virtual ~ListPopUp();
virtual void show();
QListWidget* list();
QListWidgetItem* addItem(const QString& str, Qt::CheckState checked = Qt::Unchecked);
......
......@@ -129,6 +129,8 @@ public:
void addMenuAction(Plugin* plugin, const QString& menuPath, QAction* action);
void removeMenuAction(Plugin* plugin, QAction* action);
void statusBarMessage(const QString& msg, int msec);
public slots:
void aboutSCHNApps();
void aboutCGoGN();
......
......@@ -67,7 +67,7 @@ void ControlDock_CameraTab::selectedCameraChanged()
void ControlDock_CameraTab::cameraProjectionChanged(QAbstractButton* b)
{
if (!b_updatingUI)
if (!b_updatingUI && m_selectedCamera)
{
if(radio_orthographicProjection->isChecked())
m_selectedCamera->setProjectionType(qglviewer::Camera::ORTHOGRAPHIC);
......
......@@ -8,13 +8,14 @@ namespace CGoGN
namespace SCHNApps
{
ListPopUp::ListPopUp(const QString& name, QWidget* parent):
ListPopUp::ListPopUp(const QString& name, QWidget* parent) :
QDialog(parent)
{
setWindowTitle(name);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
setWindowFlags(windowFlags()/* | Qt::FramelessWindowHint*/ | Qt::SplashScreen | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
m_layout = new QVBoxLayout(this);
setLayout(m_layout);
m_layout->setContentsMargins(1, 1, 1, 1);
m_list_items = new QListWidget();
m_list_items->setSelectionMode(QAbstractItemView::NoSelection);
m_layout->addWidget(m_list_items);
......@@ -29,11 +30,33 @@ QListWidget* ListPopUp::list()
return m_list_items;
}
void ListPopUp::show()
{
int rows = m_list_items->model()->rowCount();
int rowSize = m_list_items->sizeHintForRow(0);
int height = rows * rowSize + 6;
if (height < 96) // 96??
height = 96;
m_list_items->setFixedHeight(height);
QDialog::show();
}
QListWidgetItem* ListPopUp::addItem(const QString& str, Qt::CheckState checked)
{
QListWidgetItem* item = new QListWidgetItem(str, m_list_items);
item->setCheckState(checked);
int rows = m_list_items->model()->rowCount();
int rowSize = m_list_items->sizeHintForRow(0);
int height = rows * rowSize;
if (height >= m_list_items->size().height())
m_list_items->setFixedHeight(height + 6);
//QFontMetrics fm(m_list_items->font());
//int maxTextWidth = fm.width(item->text());
//if (maxTextWidth < 140)
// maxTextWidth = 140;
//m_list_items->setFixedWidth(maxTextWidth + 40);
return item;
}
......@@ -61,6 +84,7 @@ bool ListPopUp::removeItem(const QString& str)
if(items.empty())
return false;
m_list_items->takeItem(m_list_items->row(items[0]));
return true;
}
......
......@@ -923,6 +923,10 @@ void SCHNApps::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}
void SCHNApps::statusBarMessage(const QString& msg, int msec)
{
statusbar->showMessage(msg, msec);
}
} // namespace SCHNApps
......
......@@ -13,6 +13,7 @@
#include <QKeyEvent>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QMessageBox>
namespace CGoGN
{
......@@ -501,16 +502,47 @@ void View::keyPressEvent(QKeyEvent* event)
if (event->key() == Qt::Key_S)
{
b_saveSnapshots = !b_saveSnapshots;
if (b_saveSnapshots)
connect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
{
QMessageBox msgBox;
msgBox.setText("Snapshot every frame?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if (msgBox.exec() == QMessageBox::Ok)
{
m_schnapps->statusBarMessage("frame snapshot !!", 2000);
connect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
}
else
{
m_schnapps->statusBarMessage("cancel frame snapshot", 2000);
b_saveSnapshots = false;
}
}
else
{
disconnect(this, SIGNAL(drawFinished(bool)), this, SLOT(saveSnapshot(bool)));
m_schnapps->statusBarMessage("Stop frame snapshot", 2000);
}
}
else
{
foreach(PluginInteraction* plugin, l_plugins)
plugin->keyPress(this, event);
QGLViewer::keyPressEvent(event);
if (event->key() == Qt::Key_Escape)
{
QMessageBox msgBox;
msgBox.setText("Really quit SCHNApps ?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
if (msgBox.exec() == QMessageBox::Ok)
exit(0);
}
else
QGLViewer::keyPressEvent(event);
}
}
......
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