Edit_box_plugin

This commit is contained in:
Maxime Gimeno 2018-09-27 10:16:41 +02:00
parent 97fcf113a6
commit 56e58b8f99
6 changed files with 45 additions and 16 deletions

View File

@ -116,7 +116,7 @@ public:
FT x = -diag/fd + FT(i)/FT(grid_size) * dx;
{
FT y = -diag/fd + FT(j)/FT(grid_size) * dy;
const CGAL::qglviewer::Vec v_offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec v_offset = Three::mainViewer()->offset();
Simple_kernel::Vector_3 offset(v_offset.x, v_offset.y, v_offset.z);
Point query = transfo( Point(x,y,z))-offset;
FT min = DBL_MAX;

View File

@ -229,6 +229,8 @@ public:
pxr_.setViewer(v);
connect(v, SIGNAL(pointSelected(const QMouseEvent *)), &pxr_, SLOT(update(const QMouseEvent *)));
createOrGetDockLayout();
connect(mw, SIGNAL(newViewerCreated(QObject*)),
this, SLOT(connectNewViewer(QObject*)));
QMenu* menuFile = mw->findChild<QMenu*>("menuFile");
if ( NULL != menuFile )
@ -697,8 +699,6 @@ private:
viewer->installEventFilter(y_item);
viewer->installEventFilter(z_item);
}
connect(mw, SIGNAL(newViewerCreated(QObject*)),
this, SLOT(connectNewViewer(QObject*)));
connect(x_item, SIGNAL(selected(CGAL::Three::Scene_item*)), this, SLOT(select_plane(CGAL::Three::Scene_item*)));
connect(y_item, SIGNAL(selected(CGAL::Three::Scene_item*)), this, SLOT(select_plane(CGAL::Three::Scene_item*)));

View File

@ -198,7 +198,7 @@ public Q_SLOTS:
else
{
QApplication::setOverrideCursor(Qt::WaitCursor);
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
CGAL::QGLViewer* viewer = Three::mainViewer();
QList<Scene_item*> polyhedra;
//Fills the list of target polyhedra and the cutting plane

View File

@ -312,14 +312,14 @@ public Q_SLOTS:
if(!is_point_set)
{
const CGAL::qglviewer::Vec offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec offset = Three::mainViewer()->offset();
transform_item->manipulatedFrame()->setFromMatrix(matrix);
transform_item->manipulatedFrame()->translate(offset);
transform_item->itemChanged();
}
else
{
const CGAL::qglviewer::Vec offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec offset = Three::mainViewer()->offset();
transform_points_item->manipulatedFrame()->setFromMatrix(matrix);
transform_points_item->manipulatedFrame()->translate(offset);
transform_points_item->itemChanged();
@ -458,7 +458,7 @@ void Polyhedron_demo_affine_transform_plugin::end(){
QApplication::restoreOverrideCursor();
double matrix[16];
transformMatrix(&matrix[0]);
const CGAL::qglviewer::Vec offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec offset = Three::mainViewer()->offset();
matrix[12]-=offset.x;
matrix[13]-=offset.y;
matrix[14]-=offset.z;
@ -548,7 +548,7 @@ void Polyhedron_demo_affine_transform_plugin::updateUiMatrix()
matrix(1,3) -= transform_points_item->center().y;
matrix(2,3) -= transform_points_item->center().z;
}
const CGAL::qglviewer::Vec offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec offset = Three::mainViewer()->offset();
matrix.data()[12]-=offset.x;
matrix.data()[13]-=offset.y;
matrix.data()[14]-=offset.z;

View File

@ -5,6 +5,7 @@
#include "Scene_edit_box_item.h"
#include "Scene_surface_mesh_item.h"
#include <CGAL/Three/Viewer_interface.h>
#include <CGAL/Three/Three.h>
#include <CGAL/boost/graph/helpers.h>
#include <QAction>
#include <QMainWindow>
@ -49,6 +50,16 @@ public Q_SLOTS:
void bbox();
void enableAction();
void exportToPoly();
void connectNewViewer(QObject* o)
{
for(int i=0; i<scene->numberOfEntries(); ++i)
{
Scene_edit_box_item* item = qobject_cast<Scene_edit_box_item*>(
scene->item(i));
if(item)
o->installEventFilter(item);
}
}
private:
CGAL::Three::Scene_interface* scene;
@ -69,6 +80,8 @@ void Edit_box_plugin::init(QMainWindow* mainWindow, CGAL::Three::Scene_interface
actionExport = new QAction(tr("Export to Face_graph item"), mainWindow);
connect(actionExport, SIGNAL(triggered()),
this, SLOT(exportToPoly()));
connect(mw, SIGNAL(newViewerCreated(QObject*)),
this, SLOT(connectNewViewer(QObject*)));
}
void Edit_box_plugin::bbox()
@ -85,8 +98,9 @@ void Edit_box_plugin::bbox()
this, SLOT(enableAction()));
item->setName("Edit box");
item->setRenderingMode(FlatPlusEdges);
CGAL::QGLViewer* viewer = *CGAL::QGLViewer::QGLViewerPool().begin();
viewer->installEventFilter(item);
Q_FOREACH(CGAL::QGLViewer* viewer, CGAL::QGLViewer::QGLViewerPool())
viewer->installEventFilter(item);
scene->addItem(item);
actionBbox->setEnabled(false);
@ -100,7 +114,7 @@ void Edit_box_plugin::enableAction() {
void Edit_box_plugin::exportToPoly()
{
int id =0;
const CGAL::qglviewer::Vec v_offset = static_cast<CGAL::Three::Viewer_interface*>(CGAL::QGLViewer::QGLViewerPool().first())->offset();
const CGAL::qglviewer::Vec v_offset = Three::mainViewer()->offset();
EPICK::Vector_3 offset(v_offset.x, v_offset.y, v_offset.z);
Scene_edit_box_item* item = NULL;
for(int i = 0, end = scene->numberOfEntries();

View File

@ -619,11 +619,16 @@ void Scene_edit_box_item::highlight(Viewer_interface *viewer)
d->hl_vertex.data(),
static_cast<int>(d->hl_vertex.size()*sizeof(float)));
tc->initializeBuffers(viewer);
tc->setFlatDataSize(d->vertex_spheres.size());
tc->setCenterSize(d->hl_vertex.size());
//draw
d->hl_type = Scene_edit_box_item_priv::VERTEX;
Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool())
{
CGAL::Three::Viewer_interface* viewer =
static_cast<CGAL::Three::Viewer_interface*>(v);
tc->initializeBuffers(viewer);
}
break;
}
case 1:
@ -644,10 +649,15 @@ void Scene_edit_box_item::highlight(Viewer_interface *viewer)
Ec::Vertices,
d->hl_vertex.data(),
static_cast<GLsizei>(d->hl_vertex.size()*sizeof(float)));
ec->initializeBuffers(viewer);
ec->setFlatDataSize(d->hl_vertex.size());
//draw
d->hl_type = Scene_edit_box_item_priv::EDGE;
Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool())
{
CGAL::Three::Viewer_interface* viewer =
static_cast<CGAL::Three::Viewer_interface*>(v);
ec->initializeBuffers(viewer);
}
break;
}
case 2:
@ -677,10 +687,15 @@ void Scene_edit_box_item::highlight(Viewer_interface *viewer)
Tc::Flat_normals,
d->hl_normal.data(),
static_cast<int>(d->hl_normal.size()*sizeof(float)));
tc->initializeBuffers(viewer);
tc->setFlatDataSize(d->hl_vertex.size());
//draw
d->hl_type = Scene_edit_box_item_priv::FACE;
Q_FOREACH(CGAL::QGLViewer* v, CGAL::QGLViewer::QGLViewerPool())
{
CGAL::Three::Viewer_interface* viewer =
static_cast<CGAL::Three::Viewer_interface*>(v);
tc->initializeBuffers(viewer);
}
break;
}
default:
@ -748,8 +763,8 @@ bool Scene_edit_box_item::eventFilter(QObject *obj, QEvent *event)
{
if(!visible())
return false;
Viewer_interface* test_viewer = qobject_cast<Vi*>(obj);
if(!test_viewer)
Viewer_interface* viewer = qobject_cast<Vi*>(obj);
if(!viewer)
return false;
if(event->type() == QEvent::MouseButtonPress)
{