mirror of https://github.com/CGAL/cgal
Merge pull request #3221 from maxGimeno/Demo-Transparency-enhancements-GF
Polyhedron Demo: minor fixes and enhancements
This commit is contained in:
commit
c40e0fe2df
|
|
@ -17,6 +17,7 @@
|
|||
#include <QMenuBar>
|
||||
#include <QChar>
|
||||
#include <QAction>
|
||||
#include <QWidgetAction>
|
||||
#include <QShortcut>
|
||||
#include <QKeySequence>
|
||||
#include <QLibrary>
|
||||
|
|
@ -1306,6 +1307,7 @@ void MainWindow::showSceneContextMenu(int selectedItemIndex,
|
|||
void MainWindow::showSceneContextMenu(const QPoint& p) {
|
||||
QWidget* sender = qobject_cast<QWidget*>(this->sender());
|
||||
if(!sender) return;
|
||||
if(scene->selectionIndices().isEmpty())return;
|
||||
int main_index = scene->selectionIndices().first();
|
||||
|
||||
if(sender == sceneView) {
|
||||
|
|
@ -1332,7 +1334,14 @@ void MainWindow::showSceneContextMenu(const QPoint& p) {
|
|||
Q_FOREACH(QAction* action, scene->item(main_index)->contextMenu()->actions())
|
||||
{
|
||||
if(action->property("is_groupable").toBool())
|
||||
{
|
||||
menu_actions[action->text()] = action;
|
||||
if(action->text() == QString("Alpha value"))
|
||||
{
|
||||
menu_actions["alpha slider"] = action->menu()->actions().last();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Q_FOREACH(Scene::Item_id index, scene->selectionIndices())
|
||||
{
|
||||
|
|
@ -1348,8 +1357,48 @@ void MainWindow::showSceneContextMenu(const QPoint& p) {
|
|||
QMenu menu;
|
||||
Q_FOREACH(QString name, menu_actions.keys())
|
||||
{
|
||||
QAction* action = menu.addAction(name);
|
||||
connect(action, &QAction::triggered, this, &MainWindow::propagate_action);
|
||||
if(name == QString("alpha slider"))
|
||||
continue;
|
||||
if(name == QString("Alpha value"))
|
||||
{
|
||||
QWidgetAction* sliderAction = new QWidgetAction(&menu);
|
||||
QSlider* slider = new QSlider(&menu);
|
||||
slider->setMinimum(0);
|
||||
slider->setMaximum(255);
|
||||
slider->setValue(
|
||||
qobject_cast<QSlider*>(
|
||||
qobject_cast<QWidgetAction*>
|
||||
(menu_actions["alpha slider"])->defaultWidget()
|
||||
)->value());
|
||||
slider->setOrientation(Qt::Horizontal);
|
||||
sliderAction->setDefaultWidget(slider);
|
||||
|
||||
connect(slider, &QSlider::valueChanged, [this, slider]()
|
||||
{
|
||||
Q_FOREACH(Scene::Item_id id, scene->selectionIndices())
|
||||
{
|
||||
Scene_item* item = scene->item(id);
|
||||
Q_FOREACH(QAction* action, item->contextMenu()->actions())
|
||||
{
|
||||
if(action->text() == "Alpha value")
|
||||
{
|
||||
QWidgetAction* sliderAction = qobject_cast<QWidgetAction*>(action->menu()->actions().last());
|
||||
QSlider* ac_slider = qobject_cast<QSlider*>(sliderAction->defaultWidget());
|
||||
ac_slider->setValue(slider->value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
QMenu* new_menu = new QMenu("Alpha value", &menu);
|
||||
new_menu->addAction(sliderAction);
|
||||
menu.addMenu(new_menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
QAction* action = menu.addAction(name);
|
||||
connect(action, &QAction::triggered, this, &MainWindow::propagate_action);
|
||||
}
|
||||
}
|
||||
if(has_stats)
|
||||
{
|
||||
|
|
@ -1834,9 +1883,9 @@ void MainWindow::on_actionLookAt_triggered()
|
|||
if( i == QDialog::Accepted &&
|
||||
dialog.has_correct_coordinates() )
|
||||
{
|
||||
viewerShow((float)dialog.get_x(),
|
||||
(float)dialog.get_y(),
|
||||
(float)dialog.get_z());
|
||||
viewerShow((float)dialog.get_x()+viewer->offset().x,
|
||||
(float)dialog.get_y()+viewer->offset().y,
|
||||
(float)dialog.get_z()+viewer->offset().z);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1849,30 +1898,57 @@ void MainWindow::viewerShowObject()
|
|||
}
|
||||
if(item) {
|
||||
const Scene::Bbox bbox = item->bbox();
|
||||
viewerShow((float)bbox.xmin()+viewer->offset().x, (float)bbox.ymin()+viewer->offset().y, (float)bbox.zmin()+viewer->offset().z,
|
||||
(float)bbox.xmax()+viewer->offset().x, (float)bbox.ymax()+viewer->offset().y, (float)bbox.zmax()+viewer->offset().z);
|
||||
CGAL::qglviewer::Vec min((float)bbox.xmin()+viewer->offset().x, (float)bbox.ymin()+viewer->offset().y, (float)bbox.zmin()+viewer->offset().z),
|
||||
max((float)bbox.xmax()+viewer->offset().x, (float)bbox.ymax()+viewer->offset().y, (float)bbox.zmax()+viewer->offset().z);
|
||||
viewer->setSceneBoundingBox(min, max);
|
||||
viewerShow(min.x, min.y, min.z,
|
||||
max.x, max.y, max.z);
|
||||
}
|
||||
}
|
||||
|
||||
QString MainWindow::cameraString() const
|
||||
{
|
||||
return viewer->dumpCameraCoordinates();
|
||||
const CGAL::qglviewer::Vec pos = viewer->camera()->position() - viewer->offset();
|
||||
const CGAL::qglviewer::Quaternion q = viewer->camera()->orientation();
|
||||
|
||||
return QString("%1 %2 %3 %4 %5 %6 %7")
|
||||
.arg(pos[0])
|
||||
.arg(pos[1])
|
||||
.arg(pos[2])
|
||||
.arg(q[0])
|
||||
.arg(q[1])
|
||||
.arg(q[2])
|
||||
.arg(q[3]);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDumpCamera_triggered()
|
||||
{
|
||||
//remove offset
|
||||
information(QString("Camera: %1")
|
||||
.arg(cameraString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCopyCamera_triggered()
|
||||
{
|
||||
//remove offset
|
||||
qApp->clipboard()->setText(this->cameraString());
|
||||
}
|
||||
|
||||
void MainWindow::on_actionPasteCamera_triggered()
|
||||
{
|
||||
//add offset
|
||||
QString s = qApp->clipboard()->text();
|
||||
QStringList list = s.split(' ');
|
||||
QString new_s[7];
|
||||
|
||||
new_s[0] = QString("%1").arg(list.at(0).toFloat() + viewer->offset().x);
|
||||
new_s[1] = QString("%1").arg(list.at(1).toFloat() + viewer->offset().y);
|
||||
new_s[2] = QString("%1").arg(list.at(2).toFloat() + viewer->offset().z);
|
||||
for(int i=3; i<7; ++i)
|
||||
new_s[i] = list.at(i);
|
||||
s = QString();
|
||||
for(int i=0; i<7; ++i)
|
||||
s.append(new_s[i]).append(" ");
|
||||
viewer->moveCameraToCoordinates(s, 0.5f);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1139,8 +1139,8 @@ QItemSelection Scene::createSelection(int i)
|
|||
|
||||
QItemSelection Scene::createSelectionAll()
|
||||
{
|
||||
return QItemSelection(index_map.keys(0).at(0),
|
||||
index_map.keys(m_entries.size() - 1).at(4));
|
||||
return QItemSelection(index(0, 0,index_map.key(0).parent()),
|
||||
index(m_entries.size()-1, 4, index_map.key(0).parent()));
|
||||
}
|
||||
|
||||
void Scene::itemChanged()
|
||||
|
|
|
|||
|
|
@ -273,6 +273,7 @@ public :
|
|||
if(!menuChanged) {
|
||||
menu->addSeparator();
|
||||
QMenu *container = new QMenu(tr("Alpha value"));
|
||||
container->menuAction()->setProperty("is_groupable", true);
|
||||
QWidgetAction *sliderAction = new QWidgetAction(0);
|
||||
sliderAction->setDefaultWidget(alphaSlider);
|
||||
connect(alphaSlider, &QSlider::valueChanged,
|
||||
|
|
@ -1344,9 +1345,24 @@ QMenu* Scene_c3t3_item::contextMenu()
|
|||
bool menuChanged = menu->property(prop_name).toBool();
|
||||
|
||||
if (!menuChanged) {
|
||||
|
||||
QMenu *container = new QMenu(tr("Tetrahedra's Shrink Factor"));
|
||||
|
||||
QMenu *container = new QMenu(tr("Alpha value"));
|
||||
container->menuAction()->setProperty("is_groupable", true);
|
||||
QWidgetAction *sliderAction = new QWidgetAction(0);
|
||||
sliderAction->setDefaultWidget(d->alphaSlider);
|
||||
connect(d->alphaSlider, &QSlider::valueChanged,
|
||||
[this]()
|
||||
{
|
||||
if(d->intersection)
|
||||
d->intersection->setAlpha(d->alphaSlider->value());
|
||||
redraw();
|
||||
}
|
||||
);
|
||||
container->addAction(sliderAction);
|
||||
menu->addMenu(container);
|
||||
|
||||
container = new QMenu(tr("Tetrahedra's Shrink Factor"));
|
||||
sliderAction = new QWidgetAction(0);
|
||||
connect(d->tet_Slider, &QSlider::valueChanged, this, &Scene_c3t3_item::itemChanged);
|
||||
sliderAction->setDefaultWidget(d->tet_Slider);
|
||||
container->addAction(sliderAction);
|
||||
|
|
@ -1388,19 +1404,7 @@ QMenu* Scene_c3t3_item::contextMenu()
|
|||
connect(actionShowGrid, SIGNAL(toggled(bool)),
|
||||
this, SLOT(show_grid(bool)));
|
||||
|
||||
container = new QMenu(tr("Alpha value"));
|
||||
sliderAction = new QWidgetAction(0);
|
||||
sliderAction->setDefaultWidget(d->alphaSlider);
|
||||
connect(d->alphaSlider, &QSlider::valueChanged,
|
||||
[this]()
|
||||
{
|
||||
if(d->intersection)
|
||||
d->intersection->setAlpha(d->alphaSlider->value());
|
||||
redraw();
|
||||
}
|
||||
);
|
||||
container->addAction(sliderAction);
|
||||
menu->addMenu(container);
|
||||
|
||||
menu->setProperty(prop_name, true);
|
||||
}
|
||||
return menu;
|
||||
|
|
|
|||
|
|
@ -1815,6 +1815,14 @@ QMenu* Scene_surface_mesh_item::contextMenu()
|
|||
bool menuChanged = menu->property(prop_name).toBool();
|
||||
|
||||
if(!menuChanged) {
|
||||
QMenu *container = new QMenu(tr("Alpha value"));
|
||||
container->menuAction()->setProperty("is_groupable", true);
|
||||
QWidgetAction *sliderAction = new QWidgetAction(0);
|
||||
sliderAction->setDefaultWidget(d->alphaSlider);
|
||||
connect(d->alphaSlider, &QSlider::valueChanged,
|
||||
[this](){redraw();});
|
||||
container->addAction(sliderAction);
|
||||
menu->addMenu(container);
|
||||
menu->addSeparator();
|
||||
QAction* actionPrintVertices=
|
||||
menu->addAction(tr("Display Vertices Ids"));
|
||||
|
|
@ -1844,13 +1852,7 @@ QMenu* Scene_surface_mesh_item::contextMenu()
|
|||
connect(actionZoomToId, &QAction::triggered,
|
||||
this, &Scene_surface_mesh_item::zoomToId);
|
||||
|
||||
QMenu *container = new QMenu(tr("Alpha value"));
|
||||
QWidgetAction *sliderAction = new QWidgetAction(0);
|
||||
sliderAction->setDefaultWidget(d->alphaSlider);
|
||||
connect(d->alphaSlider, &QSlider::valueChanged,
|
||||
[this](){redraw();});
|
||||
container->addAction(sliderAction);
|
||||
menu->addMenu(container);
|
||||
|
||||
setProperty("menu_changed", true);
|
||||
menu->setProperty(prop_name, true);
|
||||
}
|
||||
|
|
@ -1973,10 +1975,17 @@ bool Scene_surface_mesh_item::testDisplayId(double x, double y, double z, CGAL::
|
|||
EPICK::Point_3 src(x - offset.x,
|
||||
y - offset.y,
|
||||
z - offset.z);
|
||||
EPICK::Point_3 dest(viewer->camera()->position().x - offset.x,
|
||||
viewer->camera()->position().y - offset.y,
|
||||
viewer->camera()->position().z - offset.z);
|
||||
|
||||
CGAL::qglviewer::Camera* cam = viewer->camera();
|
||||
EPICK::Point_3 dest( cam->position().x - offset.x,
|
||||
cam->position().y - offset.y,
|
||||
cam->position().z - offset.z);
|
||||
EPICK::Vector_3 v(src,dest);
|
||||
EPICK::Vector_3 dir(cam->viewDirection().x,
|
||||
cam->viewDirection().y,
|
||||
cam->viewDirection().z);
|
||||
if(-CGAL::scalar_product(v, dir) < cam->zNear()) //if src is behind the near plane, don't display.
|
||||
return false;
|
||||
v = 0.01*v;
|
||||
EPICK::Point_3 point = src;
|
||||
point = point + v;
|
||||
|
|
|
|||
Loading…
Reference in New Issue