mirror of https://github.com/CGAL/cgal
Fix the bug of single textItems on multiple scene_items.
This commit is contained in:
parent
56caa543f0
commit
9abe59c917
|
|
@ -137,7 +137,7 @@ MainWindow::MainWindow(QWidget* parent)
|
|||
scene = new Scene(this);
|
||||
viewer->textRenderer->setScene(scene);
|
||||
viewer->setScene(scene);
|
||||
ui->actionMax_text_items_displayed->setText(QString("Max text items displayed %1").arg(viewer->textRenderer->getMax_textItems()));
|
||||
ui->actionMax_text_items_displayed->setText(QString("Set Maximum Text Items Displayed : %1").arg(viewer->textRenderer->getMax_textItems()));
|
||||
{
|
||||
QShortcut* shortcut = new QShortcut(QKeySequence(Qt::ALT+Qt::Key_Q), this);
|
||||
connect(shortcut, SIGNAL(activated()),
|
||||
|
|
@ -1847,12 +1847,12 @@ void MainWindow::on_actionMaxItemsDisplayed_triggered()
|
|||
{
|
||||
bool ok;
|
||||
bool valid;
|
||||
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
|
||||
tr("Maximum text items diplayed:"), QLineEdit::Normal,
|
||||
"30000", &ok);
|
||||
QString text = QInputDialog::getText(this, tr("Maximum Number of Text Items"),
|
||||
tr("Maximum Text Items Diplayed:"), QLineEdit::Normal,
|
||||
QString("%1").arg(viewer->textRenderer->getMax_textItems()), &ok);
|
||||
text.toInt(&valid);
|
||||
if (ok && valid){
|
||||
viewer->textRenderer->setMax(text.toInt());
|
||||
ui->actionMax_text_items_displayed->setText(QString("Max text items displayed %1").arg(text.toInt()));
|
||||
ui->actionMax_text_items_displayed->setText(QString("Set Maximum Text Items Displayed : %1").arg(text.toInt()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>978</width>
|
||||
<height>26</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
|
@ -299,8 +299,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>534</width>
|
||||
<height>174</height>
|
||||
<width>541</width>
|
||||
<height>175</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
|
|
@ -679,7 +679,7 @@
|
|||
</action>
|
||||
<action name="actionMax_text_items_displayed">
|
||||
<property name="text">
|
||||
<string>Max text items displayed</string>
|
||||
<string>Set Maximum Text Items Displayed :</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
|
|
|||
|
|
@ -1170,9 +1170,8 @@ bool Scene::testDisplayId(double x, double y, double z, CGAL::Three::Viewer_inte
|
|||
bool res = i->testDisplayId(x,y,z, viewer);
|
||||
return res;
|
||||
}
|
||||
else return false;
|
||||
|
||||
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#include "Scene_find_items.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -591,6 +591,7 @@ Scene_polyhedron_item::Scene_polyhedron_item()
|
|||
textItems = new TextListItem(this);
|
||||
init();
|
||||
targeted_id = NULL;
|
||||
all_ids_displayed = false;
|
||||
}
|
||||
|
||||
Scene_polyhedron_item::Scene_polyhedron_item(Polyhedron* const p)
|
||||
|
|
@ -611,6 +612,7 @@ Scene_polyhedron_item::Scene_polyhedron_item(Polyhedron* const p)
|
|||
init();
|
||||
invalidateOpenGLBuffers();
|
||||
targeted_id = NULL;
|
||||
all_ids_displayed = false;
|
||||
}
|
||||
|
||||
Scene_polyhedron_item::Scene_polyhedron_item(const Polyhedron& p)
|
||||
|
|
@ -631,6 +633,7 @@ Scene_polyhedron_item::Scene_polyhedron_item(const Polyhedron& p)
|
|||
nb_f_lines = 0;
|
||||
invalidateOpenGLBuffers();
|
||||
targeted_id = NULL;
|
||||
all_ids_displayed = false;
|
||||
}
|
||||
|
||||
Scene_polyhedron_item::~Scene_polyhedron_item()
|
||||
|
|
@ -1322,6 +1325,8 @@ void Scene_polyhedron_item::printPrimitiveId(QPoint point, CGAL::Three::Viewer_i
|
|||
{
|
||||
TextRenderer *renderer = viewer->textRenderer;
|
||||
renderer->getLocalTextItems().removeAll(targeted_id);
|
||||
renderer->removeTextList(textItems);
|
||||
textItems->clear();
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
|
||||
|
|
@ -1415,7 +1420,8 @@ void Scene_polyhedron_item::printPrimitiveId(QPoint point, CGAL::Three::Viewer_i
|
|||
if (targeted_id == NULL || targeted_id->position() != text_item.position() )
|
||||
{
|
||||
targeted_id = new TextItem(text_item);
|
||||
renderer->addText(targeted_id);
|
||||
textItems->append(targeted_id);
|
||||
renderer->addTextList(textItems);
|
||||
}
|
||||
else
|
||||
targeted_id=NULL;
|
||||
|
|
@ -1427,45 +1433,60 @@ void Scene_polyhedron_item::printPrimitiveId(QPoint point, CGAL::Three::Viewer_i
|
|||
|
||||
void Scene_polyhedron_item::printPrimitiveIds(CGAL::Three::Viewer_interface *viewer) const
|
||||
{
|
||||
|
||||
TextRenderer *renderer = viewer->textRenderer;
|
||||
//clears textitems
|
||||
renderer->removeTextList(textItems);
|
||||
textItems->clear();
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
|
||||
//fills textItems
|
||||
Q_FOREACH(Polyhedron::Vertex_const_handle vh, vertices(*poly))
|
||||
|
||||
if(!all_ids_displayed)
|
||||
{
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
|
||||
//fills textItems
|
||||
Q_FOREACH(Polyhedron::Vertex_const_handle vh, vertices(*poly))
|
||||
{
|
||||
const Point& p = vh->point();
|
||||
textItems->append(new TextItem((float)p.x(), (float)p.y(), (float)p.z(), QString("%1").arg(vh->id()), true, font, Qt::red));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Q_FOREACH(boost::graph_traits<Polyhedron>::edge_descriptor e, edges(*poly))
|
||||
{
|
||||
Q_FOREACH(boost::graph_traits<Polyhedron>::edge_descriptor e, edges(*poly))
|
||||
{
|
||||
const Point& p1 = source(e, *poly)->point();
|
||||
const Point& p2 = target(e, *poly)->point();
|
||||
textItems->append(new TextItem((float)(p1.x() + p2.x()) / 2, (float)(p1.y() + p2.y()) / 2, (float)(p1.z() + p2.z()) / 2, QString("%1").arg(e.halfedge()->id() / 2), true, font, Qt::green));
|
||||
}
|
||||
}
|
||||
|
||||
Q_FOREACH(Polyhedron::Facet_handle fh, faces(*poly))
|
||||
{
|
||||
Q_FOREACH(Polyhedron::Facet_handle fh, faces(*poly))
|
||||
{
|
||||
double x(0), y(0), z(0);
|
||||
int total(0);
|
||||
Q_FOREACH(Polyhedron::Vertex_handle vh, vertices_around_face(fh->halfedge(), *poly))
|
||||
{
|
||||
x += vh->point().x();
|
||||
y += vh->point().y();
|
||||
z += vh->point().z();
|
||||
++total;
|
||||
x += vh->point().x();
|
||||
y += vh->point().y();
|
||||
z += vh->point().z();
|
||||
++total;
|
||||
}
|
||||
|
||||
textItems->append(new TextItem((float)x / total, (float)y / total, (float)z / total, QString("%1").arg(fh->id()), true, font, Qt::blue));
|
||||
}
|
||||
//add the QList to the render's pool
|
||||
renderer->addTextList(textItems);
|
||||
if(textItems->size() > renderer->getMax_textItems())
|
||||
all_ids_displayed = !all_ids_displayed;
|
||||
}
|
||||
//add the QList to the render's pool
|
||||
renderer->addTextList(textItems);
|
||||
if(all_ids_displayed)
|
||||
{
|
||||
//clears TextItems
|
||||
textItems->clear();
|
||||
renderer->removeTextList(textItems);
|
||||
if(targeted_id)
|
||||
{
|
||||
textItems->append(targeted_id);
|
||||
renderer->addTextList(textItems);
|
||||
}
|
||||
}
|
||||
all_ids_displayed = !all_ids_displayed;
|
||||
}
|
||||
|
||||
bool Scene_polyhedron_item::testDisplayId(double x, double y, double z, CGAL::Three::Viewer_interface* viewer)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ private:
|
|||
Edges,
|
||||
Feature_edges,
|
||||
Gouraud_Facets,
|
||||
NbOfVaos = Gouraud_Facets+1
|
||||
NbOfVaos
|
||||
};
|
||||
enum VBOs {
|
||||
Facets_vertices = 0,
|
||||
|
|
@ -159,9 +159,10 @@ private:
|
|||
Feature_edges_vertices,
|
||||
Edges_color,
|
||||
Facets_normals_gouraud,
|
||||
NbOfVbos = Facets_normals_gouraud+1
|
||||
NbOfVbos
|
||||
};
|
||||
|
||||
mutable bool all_ids_displayed;
|
||||
mutable std::vector<float> positions_lines;
|
||||
mutable std::vector<float> positions_feature_lines;
|
||||
mutable std::vector<float> positions_facets;
|
||||
|
|
|
|||
|
|
@ -7,32 +7,32 @@ void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer)
|
|||
painter->begin(viewer);
|
||||
QRect rect;
|
||||
qglviewer::Camera* camera = viewer->camera();
|
||||
if(viewer->textDisplayed())
|
||||
{
|
||||
Q_FOREACH(TextListItem* list, textItems)
|
||||
if(list->item() == scene->item(scene->mainSelectionIndex()))
|
||||
Q_FOREACH(TextItem* item, list->textList())
|
||||
//Display the items textItems
|
||||
Q_FOREACH(TextListItem* list, textItems)
|
||||
if(list->item() == scene->item(scene->mainSelectionIndex()))
|
||||
Q_FOREACH(TextItem* item, list->textList())
|
||||
{
|
||||
qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z());
|
||||
if(viewer->testDisplayId(src.x, src.y, src.z))
|
||||
{
|
||||
qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z());
|
||||
if(viewer->testDisplayId(src.x, src.y, src.z))
|
||||
{
|
||||
if(item->is_3D())
|
||||
rect = QRect(camera->projectedCoordinatesOf(src).x-item->width()/2,
|
||||
if(item->is_3D())
|
||||
rect = QRect(camera->projectedCoordinatesOf(src).x-item->width()/2,
|
||||
camera->projectedCoordinatesOf(src).y-item->height()/2,
|
||||
item->width(),
|
||||
item->height());
|
||||
else
|
||||
rect = QRect(src.x-item->width()/2,
|
||||
else
|
||||
rect = QRect(src.x-item->width()/2,
|
||||
src.y-item->height()/2,
|
||||
item->width(),
|
||||
item->height());
|
||||
|
||||
painter->setFont(item->font());
|
||||
painter->setPen(QPen(item->color()));
|
||||
painter->drawText(rect, item->text());
|
||||
}
|
||||
painter->setFont(item->font());
|
||||
painter->setPen(QPen(item->color()));
|
||||
painter->drawText(rect, item->text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Display the local TextItems
|
||||
Q_FOREACH(TextItem* item, local_textItems)
|
||||
{
|
||||
qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z());
|
||||
|
|
|
|||
|
|
@ -313,9 +313,7 @@ void Viewer::keyPressEvent(QKeyEvent* e)
|
|||
}
|
||||
}
|
||||
else if(e->key() == Qt::Key_I && e->modifiers() & Qt::ControlModifier){
|
||||
has_text = !has_text;
|
||||
if (has_text)
|
||||
d->scene->printPrimitiveIds(this);
|
||||
d->scene->printPrimitiveIds(this);
|
||||
update();
|
||||
}
|
||||
//forward the event to the scene (item handling of the event)
|
||||
|
|
@ -1206,11 +1204,6 @@ bool Viewer::testDisplayId(double x, double y, double z)
|
|||
return d->scene->testDisplayId(x,y,z,this);
|
||||
}
|
||||
|
||||
bool Viewer::textDisplayed() const
|
||||
{
|
||||
return has_text;
|
||||
}
|
||||
|
||||
QPainter* Viewer::getPainter(){return d->painter;}
|
||||
|
||||
void Viewer::paintEvent(QPaintEvent *)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ public:
|
|||
Viewer(QWidget * parent, bool antialiasing = false);
|
||||
~Viewer();
|
||||
bool testDisplayId(double, double, double);
|
||||
bool textDisplayed() const;
|
||||
// overload several QGLViewer virtual functions
|
||||
//! Deprecated and does nothing.
|
||||
void draw();
|
||||
|
|
@ -62,7 +61,6 @@ public:
|
|||
void setScene(CGAL::Three::Scene_draw_interface* scene);
|
||||
//! @returns the antialiasing state.
|
||||
bool antiAliasing() const;
|
||||
bool hasText() const{ return has_text; }
|
||||
//! @returns the fastDrawing state.
|
||||
bool inFastDrawing() const;
|
||||
//! Implementation of `Viewer_interface::inDrawWithNames()`
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ public:
|
|||
QList<TextItem*> textList()const {return _list;}
|
||||
void append(TextItem* ti) {_list.append(ti);}
|
||||
void clear(){_list.clear();}
|
||||
bool isEmpty()const {return _list.empty();}
|
||||
std::size_t size()const{return _list.size();}
|
||||
private:
|
||||
CGAL::Three::Scene_item* _item;
|
||||
QList<TextItem*> _list;
|
||||
|
|
|
|||
|
|
@ -102,9 +102,6 @@ public:
|
|||
virtual bool inFastDrawing() const = 0;
|
||||
//! @returns if the viewer is in `drawWithNames()`
|
||||
virtual bool inDrawWithNames() const = 0;
|
||||
//!Specifies if the Viewer prints the text or not. It is used, for example, in the items to
|
||||
//! decide if the TextItems for the primitives IDs should be computed or not.
|
||||
virtual bool textDisplayed() const =0;
|
||||
|
||||
/*! Passes all the uniform data to the shaders.
|
||||
* According to program_name, this data may change.
|
||||
|
|
|
|||
Loading…
Reference in New Issue