select.cpp
Go to the documentation of this file.00001
00007 #include <vve.h>
00008 #include <util/vector.h>
00009
00010 typedef util::Vector<3, double> Point3d;
00011
00012 struct VertexContent
00013 {
00014 VertexContent()
00015 : selected(false)
00016 {}
00017
00018 Point3d pos;
00019 bool selected;
00020 };
00021
00022 typedef graph::VVGraph<VertexContent> vvgraph;
00023 typedef vvgraph::vertex_t vertex;
00024
00025 class SelectModel : public Model
00026 {
00027 public:
00028 vvgraph S;
00029
00030 SelectModel(QObject *parent)
00031 : Model(parent)
00032 {
00033 for(double i = 0 ; i < 10 ; i++)
00034 {
00035 for(double j = 0 ; j < 10 ; j++)
00036 {
00037 vertex v;
00038 v->pos.x() = i;
00039 v->pos.y() = j;
00040 S.insert(v);
00041 }
00042 }
00043 }
00044
00045 void step() { }
00046
00047 void preDraw( Viewer* viewer )
00048 {
00049 glClearColor(0,0,0,0);
00050 viewer->setSceneBoundingBox(qglviewer::Vec(0,0,0), qglviewer::Vec(10, 10, 0));
00051 }
00052
00053 void drawCell(const vertex& v)
00054 {
00055 Point3d c1 = v->pos;
00056 Point3d c2 = v->pos + Point3d(1, 0, 0);
00057 Point3d c3 = v->pos + Point3d(1, 1, 0);
00058 Point3d c4 = v->pos + Point3d(0, 1, 0);
00059 glBegin(GL_QUADS);
00060 glVertex3dv(c1.c_data());
00061 glVertex3dv(c2.c_data());
00062 glVertex3dv(c3.c_data());
00063 glVertex3dv(c4.c_data());
00064 glEnd();
00065 }
00066
00067 void draw()
00068 {
00069 forall(const vertex& v, S)
00070 {
00071 if(v->selected)
00072 {
00073 glColor3f(1, 0, 0);
00074 }
00075 else
00076 {
00077 glColor3f(0.5, 0.5, 0.5);
00078 }
00079 drawCell(v);
00080 }
00081 }
00082
00083 void drawWithNames()
00084 {
00085 forall(const vertex& v, S)
00086 {
00087 glPushName((int)v.label());
00088 drawCell(v);
00089 glPopName();
00090 }
00091 }
00092 };
00093
00094 class SelectViewer : public Viewer
00095 {
00096 public:
00097 SelectViewer(QWidget *parent)
00098 : Viewer(parent)
00099 { }
00100
00101 protected:
00102 void postSelection(const QPoint& p)
00103 {
00104 int s = selectedName();
00105 if(s != -1)
00106 {
00107
00108
00109 vertex v((vertex::identity_t)s);
00110 v->selected ^= true;
00111 }
00112 }
00113 };
00114
00115 DEFINE_MODEL(SelectModel);
00116 DEFINE_VIEWER(SelectViewer);
00117