--- a/VEFViewer.cpp Mon Jun 12 14:43:47 2006 -0400
+++ b/VEFViewer.cpp Tue Jun 13 13:42:31 2006 -0400
@@ -119,6 +119,33 @@
return text;
}
+void VEFViewer::listItemDoubleClicked(QListWidgetItem* item)
+{
+ (static_cast<QDisplayListLWI*>(item))->toggleVisible();
+ updateGL();
+}
+
+void VEFViewer::customContextMenuRequested(const QPoint& pos)
+{
+ QDisplayListLWI* dl = static_cast<QDisplayListLWI*>(modelList->itemAt(pos));
+ if (dl == 0) return;
+
+ QMenu m(this);
+ dl->setupMenu(m);
+ m.exec(modelList->mapToGlobal(pos) + QPoint(10,10));
+ updateGL();
+}
+
+
+void VEFViewer::setModelList(QListWidget* l)
+{
+ modelList = l;
+ connect(modelList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
+ this, SLOT(listItemDoubleClicked(QListWidgetItem*)));
+ connect(modelList, SIGNAL(customContextMenuRequested(const QPoint&)),
+ this, SLOT(customContextMenuRequested(const QPoint&)));
+}
+
void VEFViewer::keyPressEvent(QKeyEvent* e)
{
const Qt::KeyboardModifiers modifiers = e->modifiers();
@@ -203,6 +230,8 @@
// QVertices
void QVerticesLWI::draw() const
{
+ if (!isVisible()) return;
+
glColor3f(.5, .65, .65);
glCallList(display_list);
}
@@ -234,9 +263,11 @@
}
-// QFaces
+/* QFaces */
void QFacesLWI::draw() const
{
+ if (!isVisible()) return;
+
// Draw selected
if (highlighted >= 0)
{
@@ -252,11 +283,16 @@
// Draw the object
glColor3f(0., .4, .6);
- glCallList(display_list);
+ if (!isWireframe())
+ glCallList(display_list);
+ else
+ glCallList(wireframe_display_list);
}
void QFacesLWI::drawWithNames(int offset) const
{
+ if (!isVisible()) return;
+
for (int i = 0; i < triangles.size(); i++)
{
const Triangle& t = triangles[i];
@@ -279,7 +315,7 @@
}
QFacesLWI::QFacesLWI(QString name, FILE* file, VEFViewer* v):
- QDisplayListLWI(name), highlighted(-1)
+ QDisplayListLWI(name), highlighted(-1), isWireframe_(false)
{
float nx,ny,nz; // not used
float x0,y0,z0;
@@ -304,21 +340,31 @@
std::cout << "Triangles read: " << triangles.size() << std::endl;
- // Create display list
+ // Create triangles display list
display_list = glGenLists(1);
glNewList(display_list, GL_COMPILE);
- glBegin(GL_TRIANGLES);
-
+ drawTriangles(GL_TRIANGLES);
+ glEndList();
+
+ // Create wireframe display list
+ wireframe_display_list = glGenLists(1);
+ glNewList(wireframe_display_list, GL_COMPILE);
+ drawTriangles(GL_LINE_LOOP);
+ glEndList();
+
+}
+
+void QFacesLWI::drawTriangles(GLenum mode) const
+{
for (TrianglesContainer::const_iterator cur = triangles.begin(); cur != triangles.end(); ++cur)
{
+ glBegin(mode);
glNormal3f(cur->nx,cur->ny,cur->nz);
glVertex3f(cur->x0,cur->y0,cur->z0);
glVertex3f(cur->x1,cur->y1,cur->z1);
glVertex3f(cur->x2,cur->y2,cur->z2);
+ glEnd();
}
-
- glEnd();
- glEndList();
}
qglviewer::Vec QFacesLWI::computeNormal(qglviewer::Vec v0, qglviewer::Vec v1, qglviewer::Vec v2) const
@@ -346,9 +392,12 @@
return result;
}
-// QEdges
+
+/* QEdges */
void QEdgesLWI::draw() const
{
+ if (!isVisible()) return;
+
glColor3f(.6, .2, .6);
glCallList(display_list);
}
--- a/VEFViewer.h Mon Jun 12 14:43:47 2006 -0400
+++ b/VEFViewer.h Tue Jun 13 13:42:31 2006 -0400
@@ -4,13 +4,16 @@
#include <QGLViewer/qglviewer.h>
#include <QFileDialog>
#include <QListWidgetItem>
+#include <QMenu>
class VEFViewer: public QGLViewer
{
+ Q_OBJECT
+
public:
VEFViewer(QWidget* parent);
void addFile(QString s);
- void setModelList(QListWidget* l) { modelList = l; }
+ void setModelList(QListWidget* l);
void updateMinMax(float x, float y, float z);
void init();
@@ -33,14 +36,20 @@
qglviewer::Vec min, max, center;
unsigned int vertex_count;
+
+ public slots:
+ void listItemDoubleClicked(QListWidgetItem* item);
+ void customContextMenuRequested(const QPoint& pos);
};
-class QDisplayListLWI: public QListWidgetItem
+class QDisplayListLWI: public QObject, public QListWidgetItem
{
+ Q_OBJECT
+
public:
QDisplayListLWI(QString name):
- QListWidgetItem(name)
- {}
+ QListWidgetItem(name), visible(false)
+ { toggleVisible(); }
GLuint getDisplayList() const { return display_list; }
~QDisplayListLWI() { glDeleteLists(display_list, 1); }
@@ -48,9 +57,26 @@
virtual void drawWithNames(int offset) const =0;
virtual int numElements() const =0;
virtual void highlight(int selected) =0;
+ virtual void setupMenu(QMenu& m) const
+ {
+ QAction* visible = m.addAction("Visible");
+ connect(visible, SIGNAL(triggered()), this, SLOT(toggleVisible()));
+ visible->setCheckable(true);
+ visible->setChecked(isVisible());
+ }
+
+ bool isVisible() const { return visible; }
+
+ public slots:
+ void setVisible(bool vis = true) { visible = !vis; adjustFont(); }
+ void toggleVisible() { visible = !visible; adjustFont(); }
protected:
GLuint display_list;
+ bool visible;
+
+ private:
+ void adjustFont() { QFont f; if (visible) f.setBold(true); setFont(f); }
};
@@ -67,13 +93,28 @@
class Triangle;
class QFacesLWI: public QDisplayListLWI
{
+ Q_OBJECT
+
public:
QFacesLWI(QString name, FILE* file, VEFViewer* v);
virtual void draw() const;
virtual void drawWithNames(int offset) const;
virtual int numElements() const;
virtual void highlight(int selected);
+ virtual void setupMenu(QMenu& m) const
+ {
+ QDisplayListLWI::setupMenu(m);
+
+ QAction* wireframe_action = m.addAction("Wireframe");
+ connect(wireframe_action, SIGNAL(triggered()), this, SLOT(toggleWireframe()));
+ wireframe_action->setCheckable(true);
+ wireframe_action->setChecked(isWireframe());
+ }
+ bool isWireframe() const { return isWireframe_; }
+ public slots:
+ void toggleWireframe() { isWireframe_ = !isWireframe_; }
+
private:
int readFacet(FILE* file,
float& nx, float& ny, float& nz,
@@ -81,10 +122,13 @@
float& x1, float& y1, float& z1,
float& x2, float& y2, float& z2);
qglviewer::Vec computeNormal(qglviewer::Vec v0, qglviewer::Vec v1, qglviewer::Vec v2) const;
+ void drawTriangles(GLenum mode) const;
typedef std::vector<Triangle> TrianglesContainer;
TrianglesContainer triangles;
+ bool isWireframe_;
+ GLuint wireframe_display_list;
int highlighted;
};
--- a/viewerInterface.Qt4.ui Mon Jun 12 14:43:47 2006 -0400
+++ b/viewerInterface.Qt4.ui Tue Jun 13 13:42:31 2006 -0400
@@ -23,7 +23,7 @@
<number>6</number>
</property>
<item>
- <widget class="QSplitter" name="" >
+ <widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
@@ -36,8 +36,20 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="contextMenuPolicy" >
+ <enum>Qt::CustomContextMenu</enum>
+ </property>
</widget>
- <widget class="VEFViewer" name="viewer" />
+ <widget class="VEFViewer" name="viewer" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
</widget>
</item>
</layout>