Index: trunk/FACT++/gui/BasicGlCamera.cc
===================================================================
--- trunk/FACT++/gui/BasicGlCamera.cc	(revision 11779)
+++ trunk/FACT++/gui/BasicGlCamera.cc	(revision 11779)
@@ -0,0 +1,513 @@
+#include "BasicGlCamera.h"
+#include <math.h>
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include "src/tools.h"
+
+//Coordinates of an hexagon of radius 1 and center 0
+GLfloat hexcoords[6][2] = {{-0.577367206,  1},
+                           { 0.577367206,  1},
+                           { 1.154734411,  0},
+                           { 0.577367206, -1},
+                           {-0.577367206, -1},
+                           {-1.154734411,  0}};
+
+
+
+    BasicGlCamera::BasicGlCamera(QWidget* cParent) : QGLWidget(cParent)
+    {
+        setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
+        hexRadius = 0.015f;
+        hexTolerance = hexRadius/100.0f;
+        viewSize = 1.0f;
+        calculatePixelsCoords();
+
+        ifstream fin2("MasterList-v3.txt");
+        if (!fin2.is_open())
+        {
+            cout << "Error: file \"MasterList-v3\" missing. aborting." << endl;
+            exit(-1);
+        }
+        int l = 0;
+        string buf;
+        while (getline(fin2, buf, '\n'))
+        {
+            buf = Tools::Trim(buf);
+            if (buf[0]=='#')
+                continue;
+
+            unsigned int softid, hardid, dummy;
+
+            stringstream str(buf);
+
+            str >> softid;
+            str >> dummy;
+            str >> hardid;
+
+            if (softid>=1440)
+                continue;
+
+            hardwareMapping[softid] = hardid;
+            softwareMapping[hardid] = softid;
+
+            l++;
+        }
+//        GLfloat tempPixelsCoords[MAX_NUM_PIXELS][3];
+//        for (int i=0;i<1440;i++)
+//            for (int j=0;j<3;j++)
+//                tempPixelsCoords[hardwareMapping[i]][j] = pixelsCoords[i][j];
+//        for (int i=0;i<1440;i++)
+//            for (int j=0;j<3;j++)
+//                pixelsCoords[i][j] = tempPixelsCoords[i][j];
+        buildVerticesList();
+       ifstream fin1("Trigger-Patches.txt");
+       if (!fin1.is_open())
+       {
+           cout << "Error: file \"Trigger-Patches.txt\" missing. Aborting." << endl;
+           exit(-1);
+       }
+       l=0;
+        while (getline(fin1, buf, '\n'))
+        {
+            buf = Tools::Trim(buf);
+            if (buf[0]=='#')
+                continue;
+
+            stringstream str(buf);
+            for (int i=0; i<9; i++)
+            {
+                unsigned int n;
+                str >> n;
+
+                if (n>=1440)
+                    continue;
+
+                patches[l][i] = hardwareMapping[n];
+            }
+            l++;
+        }
+        buildPatchesIndices();
+
+        for (int i=0;i<1440;i++)
+            updateNeighbors(i);
+
+        ss[0] = 0;    ss[1] = 0.25f; ss[2] = 0.5f; ss[3] = 0.75f; ss[4] = 1.0f;
+        rr[0] = 0.15; rr[1] =        rr[2] = 0;    rr[3] = 1.0f;  rr[4] = 0.85f;
+        gg[0] = 0.15; gg[1] = 0;     gg[2] = 1;    gg[3] = 0;     gg[4] = 0.85f;
+        bb[0] = 0.15; bb[1] = 1;     bb[2] =       bb[3] = 0;     bb[4] = 0.85f;
+
+        fPixelStride = 1;
+        fcSlice = 0;
+        fData.resize(1440);
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+            fData[i] = (double)i/1.44;//(double)(i)/(double)(ACTUAL_NUM_PIXELS);
+    }
+    BasicGlCamera::~BasicGlCamera()
+    {
+    }
+
+    void BasicGlCamera::initializeGL()
+    {
+        qglClearColor(QColor(25,25,38));
+        glShadeModel(GL_FLAT);
+        glDisable(GL_DEPTH_TEST);
+        glDisable(GL_CULL_FACE);
+    }
+    void BasicGlCamera::resizeGL(int cWidth, int cHeight)
+    {
+        glViewport(0, 0, cWidth, cHeight);
+         glMatrixMode(GL_PROJECTION);
+         glLoadIdentity();
+         GLfloat windowRatio = (float)cWidth/(float)cHeight;
+         if (windowRatio < 1)
+         {
+             windowRatio = 1.0f/windowRatio;
+             gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
+             pixelSize = 2*viewSize/(float)cWidth;
+             shownSizex = 2*viewSize;
+             shownSizey = 2*viewSize*windowRatio;
+         }
+         else
+         {
+             gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
+             pixelSize = 2*viewSize/(float)cHeight;
+             shownSizex = 2*viewSize*windowRatio;
+             shownSizey = 2*viewSize;
+         }
+         glMatrixMode(GL_MODELVIEW);
+    }
+    void BasicGlCamera::paintGL()
+    {
+         glClear(GL_COLOR_BUFFER_BIT);
+         glLoadIdentity();
+
+         glTranslatef(0,-0.44,0);
+         glScalef(1.5, 1.5, 1.5);
+
+         drawCamera(true);
+
+         drawPatches();
+    }
+    void BasicGlCamera::mousePressEvent(QMouseEvent *cEvent)
+    {
+
+    }
+    void BasicGlCamera::mouseMoveEvent(QMouseEvent *cEvent)
+    {
+
+    }
+    void BasicGlCamera::mouseDoubleClickEvent(QMouseEvent *cEvent)
+    {
+
+    }
+    void BasicGlCamera::drawCamera(bool alsoWire)
+    {
+        cout << "Super PaintGL" << endl;
+        glColor3f(0.5,0.5,0.5);
+        glLineWidth(1.0);
+        float color;
+
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+        {
+
+            color = float(fData[i*fPixelStride+fcSlice]);// + ]eventData[nRoi*i + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+            int index = 0;
+            while (ss[index] < color)
+                index++;
+            index--;
+            float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
+            float weight1 = 1.0f-weight0;
+            pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
+            pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
+            pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
+        }
+
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+        {
+ //           if (i == 690 ||
+ //               i == 70)
+ //               continue;
+            glColor3fv(pixelsColor[i]);
+            glLoadName(i);
+
+        drawHexagon(i,true);
+
+        }
+        if (!alsoWire)
+            return;
+        glColor3f(0.0f,0.0f,0.0f);
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+        {
+//            if (i == 690 ||
+//                i == 70)
+//                continue;
+            drawHexagon(i, false);
+        }
+    }
+    void BasicGlCamera::drawPatches()
+    {
+        glLineWidth(2.0f);
+        float backupRadius = hexRadius;
+        hexRadius *= 0.95;
+        glColor3f(0.5f, 0.5f, 0.3f);
+        glBegin(GL_LINES);
+        for (int i=0;i<NTMARK;i++)
+        {
+            for (unsigned int j=0;j<patchesIndices[i].size();j++)
+            {
+                glVertex2fv(verticesList[patchesIndices[i][j].first]);
+                glVertex2fv(verticesList[patchesIndices[i][j].second]);
+            }
+        }
+        glEnd();
+        hexRadius = backupRadius;
+    }
+    int BasicGlCamera::PixelAtPosition(const QPoint &cPos)
+    {
+        const int MaxSize = 512;
+        GLuint buffer[MaxSize];
+        GLint viewport[4];
+
+        makeCurrent();
+
+        glGetIntegerv(GL_VIEWPORT, viewport);
+        glSelectBuffer(MaxSize, buffer);
+        glRenderMode(GL_SELECT);
+
+        glInitNames();
+        glPushName(0);
+
+        glMatrixMode(GL_PROJECTION);
+        glPushMatrix();
+        glLoadIdentity();
+        GLfloat windowRatio = GLfloat(width()) / GLfloat(height());
+        gluPickMatrix(GLdouble(cPos.x()), GLdouble(viewport[3] - cPos.y()),
+                1.0, 1.0, viewport);
+
+        if (windowRatio < 1)
+         {
+             windowRatio = 1.0f/windowRatio;
+             gluOrtho2D(-viewSize, viewSize, -viewSize*windowRatio, viewSize*windowRatio);
+         }
+         else
+         {
+             gluOrtho2D(-viewSize*windowRatio, viewSize*windowRatio, -viewSize, viewSize);
+         }
+
+        glMatrixMode(GL_MODELVIEW);
+        drawCamera(false);
+        glMatrixMode(GL_PROJECTION);
+        glPopMatrix();
+
+        //for some reason that I cannot understand, the push/pop matrix doesn't do the trick here... bizarre
+        //ok, so re-do the resizeGL thing.
+        resizeGL(width(), height());
+
+        if (!glRenderMode(GL_RENDER))
+            return -1;
+
+        return buffer[3];
+    }
+    void BasicGlCamera::drawHexagon(int index, bool solid)
+    {
+        if (solid)
+            glBegin(GL_POLYGON);
+        else
+            glBegin(GL_LINE_LOOP);
+
+        glVertex2fv(verticesList[verticesIndices[index][0]]);
+        glVertex2fv(verticesList[verticesIndices[index][1]]);
+        glVertex2fv(verticesList[verticesIndices[index][2]]);
+        glVertex2fv(verticesList[verticesIndices[index][3]]);
+        glVertex2fv(verticesList[verticesIndices[index][4]]);
+        glVertex2fv(verticesList[verticesIndices[index][5]]);
+        if (solid)
+            glVertex2fv(verticesList[verticesIndices[index][0]]);
+
+        glEnd();
+    }
+
+    void BasicGlCamera::updateNeighbors(int currentPixel)
+    {
+        float squaredDistance = 0;
+        for (int i=0;i<currentPixel;i++)
+        {
+            squaredDistance = (pixelsCoords[i][0] - pixelsCoords[currentPixel][0])*
+                              (pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) +
+                              (pixelsCoords[i][1] - pixelsCoords[currentPixel][1])*
+                              (pixelsCoords[i][1] - pixelsCoords[currentPixel][1]);
+            if (squaredDistance < 4*hexRadius*hexRadius*(1.0f+hexTolerance))//neighbor !
+            {//ok, but which one ?
+                if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
+                    pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//top
+                    neighbors[i][0] = currentPixel;
+                    neighbors[currentPixel][3] = i;
+                    continue;}
+                if (fabs(pixelsCoords[i][0] - pixelsCoords[currentPixel][0]) < hexTolerance &&
+                    pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//bottom
+                    neighbors[i][3] = currentPixel;
+                    neighbors[currentPixel][0] = i;
+                    continue;}
+                if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
+                    pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top right
+                    neighbors[i][4] = currentPixel;
+                    neighbors[currentPixel][1] = i;
+                    continue;}
+                if (pixelsCoords[i][0] > pixelsCoords[currentPixel][0] &&
+                    pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom right
+                    neighbors[i][5] = currentPixel;
+                    neighbors[currentPixel][2] = i;
+                    continue;}
+                if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
+                    pixelsCoords[i][1] > pixelsCoords[currentPixel][1]){//top left
+                    neighbors[i][2] = currentPixel;
+                    neighbors[currentPixel][5] = i;
+                    continue;}
+                if (pixelsCoords[i][0] < pixelsCoords[currentPixel][0] &&
+                    pixelsCoords[i][1] < pixelsCoords[currentPixel][1]){//bottom left
+                    neighbors[i][1] = currentPixel;
+                    neighbors[currentPixel][4] = i;
+                    continue;}
+            }
+        }
+    }
+    void BasicGlCamera::skipPixels(int start, int howMany)
+    {
+        for (int i=start;i<MAX_NUM_PIXELS-howMany;i++)
+        {
+            pixelsCoords[i][0] = pixelsCoords[i+howMany][0];
+            pixelsCoords[i][1] = pixelsCoords[i+howMany][1];
+        }
+    }
+    void BasicGlCamera::calculatePixelsCoords()
+    {
+        pixelsCoords[0][0] = 0;
+        pixelsCoords[0][1] = 0.3;
+        pixelsCoords[0][2] = 0;
+        pixelsCoords[1][0] = 0;
+        pixelsCoords[1][1] = 0.3+2*hexRadius;
+        pixelsCoords[1][2] = 0;
+        neighbors[0][0] = 1;
+        neighbors[1][3] = 0;
+        //from which side of the previous hexagon are we coming from ?
+        int fromSide = 3;
+        //to which side are we heading to ?
+        int toSide = 0;
+        for (int i=2;i<MAX_NUM_PIXELS;i++)
+        {
+            toSide = fromSide-1;
+            if (toSide < 0)
+                toSide =5;
+            while (neighbors[i-1][toSide] >= 0)
+            {
+                toSide--;
+                if (toSide < 0)
+                    toSide = 5;
+            }
+            fromSide = toSide + 3;
+            if (fromSide > 5)
+                fromSide -= 6;
+            //ok. now we now in which direction we're heading
+            pixelsCoords[i][0] = pixelsCoords[i-1][0];
+            pixelsCoords[i][1] = pixelsCoords[i-1][1];
+            pixelsCoords[i][2] = pixelsCoords[i-1][2];
+            switch (toSide)
+            {
+            case 0:
+                pixelsCoords[i][1] += 2*hexRadius;
+            break;
+            case 1:
+                pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
+                pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
+            break;
+            case 2:
+                pixelsCoords[i][0] += (2*hexRadius)*sin(M_PI/3.0);
+                pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
+            break;
+            case 3:
+                pixelsCoords[i][1] -= 2*hexRadius;
+            break;
+            case 4:
+                pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
+                pixelsCoords[i][1] -= (2*hexRadius)*cos(M_PI/3.0);
+            break;
+            case 5:
+                pixelsCoords[i][0] -= (2*hexRadius)*sin(M_PI/3.0);
+                pixelsCoords[i][1] += (2*hexRadius)*cos(M_PI/3.0);
+            break;
+            };
+
+            updateNeighbors(i);
+        }
+        //Ok. So now we've circled around all the way to MAX_NUM_PIXELS
+        //do the required shifts so that it matches the fact camera up to ACTUAL_NUM_PIXELS pixels
+        skipPixels(1200, 1);
+        skipPixels(1218, 3);
+        skipPixels(1236, 1);
+        skipPixels(1256, 1);
+        skipPixels(1274, 3);
+        skipPixels(1292, 3);
+        skipPixels(1309, 6);
+        skipPixels(1323, 7);
+        skipPixels(1337, 6);
+        skipPixels(1354, 6);
+        skipPixels(1368, 7);
+        skipPixels(1382, 9);
+        skipPixels(1394, 12);
+        skipPixels(1402, 15);
+        skipPixels(1410, 12);
+        skipPixels(1422, 12);
+        skipPixels(1430, 15);
+    }
+    void BasicGlCamera::buildVerticesList()
+    {
+        numVertices = 0;
+         GLfloat cVertex[2];
+         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+         {
+             for (int j=0;j<6;j++)
+             {
+                 for (int k=0;k<2;k++)
+                     cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
+                 bool found = false;
+                 for (int k=0;k<numVertices;k++)
+                 {
+                     if ((cVertex[0] - verticesList[k][0])*
+                         (cVertex[0] - verticesList[k][0]) +
+                         (cVertex[1] - verticesList[k][1])*
+                         (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
+                         {
+                             found = true;
+                             break;
+                         }
+                 }
+                 if (!found)
+                 {
+                     for (int k=0;k<2;k++)
+                         verticesList[numVertices][k] = cVertex[k];
+                     numVertices++;
+                 }
+             }
+         }
+         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+         {
+             for (int j=0;j<6;j++)
+             {
+                 for (int k=0;k<2;k++)
+                     cVertex[k] = hexcoords[j][k]*hexRadius + pixelsCoords[i][k];
+                 for (int k=0;k<numVertices;k++)
+                 {
+                     if ((cVertex[0] - verticesList[k][0])*
+                          (cVertex[0] - verticesList[k][0]) +
+                          (cVertex[1] - verticesList[k][1])*
+                          (cVertex[1] - verticesList[k][1]) < hexTolerance*hexTolerance)
+                          {
+                             verticesIndices[i][j] = k;
+                             break;
+                          }
+                 }
+             }
+         }
+    }
+    void BasicGlCamera::buildPatchesIndices()
+    {
+        vector<edge>::iterator it;
+        bool erased = false;
+        for (int i=0;i<NTMARK;i++)//for all patches
+        {
+            patchesIndices[i].clear();
+            for (int j=0;j<9;j++)//for all cells of the current patch
+            {
+                for (int k=0;k<6;k++)//for all sides of the current cell
+                {
+                    int first = k-1;
+                    int second = k;
+                    if (first < 0)
+                        first = 5;
+                    erased = false;
+                    for (it=(patchesIndices[i]).begin(); it != (patchesIndices[i]).end(); it++)//check if this side is here already or not
+                    {
+                        if (((*it).first == verticesIndices[softwareMapping[patches[i][j]]][first] &&
+                             (*it).second == verticesIndices[softwareMapping[patches[i][j]]][second]) ||
+                            ((*it).first == verticesIndices[softwareMapping[patches[i][j]]][second] &&
+                             (*it).second == verticesIndices[softwareMapping[patches[i][j]]][first]))
+                        {
+                            patchesIndices[i].erase(it);
+                            erased = true;
+                            break;
+                        }
+                    }
+                    if (!erased)
+                    {
+                        edge temp;
+                        temp.first = verticesIndices[softwareMapping[patches[i][j]]][first];
+                        temp.second = verticesIndices[softwareMapping[patches[i][j]]][second];
+                        patchesIndices[i].push_back(temp);
+                    }
+                }
+            }
+        }
+    }
+
Index: trunk/FACT++/gui/BasicGlCamera.h
===================================================================
--- trunk/FACT++/gui/BasicGlCamera.h	(revision 11779)
+++ trunk/FACT++/gui/BasicGlCamera.h	(revision 11779)
@@ -0,0 +1,93 @@
+#ifndef BASIC_GL_CAMERA_H_
+#define BASIC_GL_CAMERA_H_
+
+#define NBOARDS      40      // max. number of boards
+#define NPIX       1440      // max. number of pixels
+#define NTMARK      160      // max. number of timeMarker signals
+
+#define MAX_NUM_PIXELS 1600
+#define ACTUAL_NUM_PIXELS 1438
+
+#include <QtOpenGL/QGLWidget>
+#include <QtGui/QMouseEvent>
+#include <vector>
+
+using namespace std;
+//#include <QtGui/QMouseEvent>
+///structure for storing edges of hexagons (for blurry display)
+struct edge
+{
+    int first;
+    int second;
+};
+
+///structure for storing neighbors of pixels. For camera position calculation and blurry display
+struct PixelsNeighbors
+{
+    //neighbors. clockwise, starting from top
+    int neighbors[6];
+    PixelsNeighbors()
+    {
+        for (int i=0;i<6;i++)
+            neighbors[i] = -1;
+    }
+    int& operator[](int index){return neighbors[index];}
+};
+
+class BasicGlCamera : public QGLWidget
+{
+    Q_OBJECT
+
+public:
+    BasicGlCamera(QWidget* parent = 0);
+    ~BasicGlCamera();
+
+protected:
+    void initializeGL();
+    void resizeGL(int width, int height);
+    virtual void paintGL();
+    virtual void mousePressEvent(QMouseEvent *event);
+    virtual void mouseMoveEvent(QMouseEvent *event);
+    virtual void mouseDoubleClickEvent(QMouseEvent *event);
+    virtual void drawCamera(bool alsoWire);
+    void drawPatches();
+    int PixelAtPosition(const QPoint &pos);
+    void drawHexagon(int index, bool solid);
+
+    int fPixelStride;
+    int fcSlice;
+    vector<double>fData;
+
+    float ss[5];// = {0.00, 0.25, 0.5, 0.75, 1.00};
+    float rr[5];// = {0.15, 0.00, 0.00, 1.00, 0.85};
+    float gg[5];// = {0.15, 0.00, 1.00, 0.00, 0.85};
+    float bb[5];// = {0.15, 1.00, 0.00, 0.00, 0.85};
+ //   bool recalcColorPlease;
+    GLfloat pixelsColor[ACTUAL_NUM_PIXELS][3];
+private:
+    void updateNeighbors(int currentPixel);
+    void skipPixels(int start, int howMany);
+    void calculatePixelsCoords();
+    void buildVerticesList();
+    void buildPatchesIndices();
+    float hexRadius;
+    float hexTolerance;
+    float viewSize;
+    float pixelSize;
+    float shownSizex;
+    float shownSizey;
+    GLfloat pixelsCoords[MAX_NUM_PIXELS][3];
+    PixelsNeighbors neighbors[MAX_NUM_PIXELS];
+
+    GLfloat verticesList[ACTUAL_NUM_PIXELS*6][2];
+
+    int hardwareMapping[1440];
+    int softwareMapping[1440];
+    int patches[160][9];
+    vector<edge> patchesIndices[160];
+    int verticesIndices[ACTUAL_NUM_PIXELS][6];
+    int numVertices;
+
+};
+
+#endif
Index: trunk/FACT++/gui/FactGui.h
===================================================================
--- trunk/FACT++/gui/FactGui.h	(revision 11778)
+++ trunk/FACT++/gui/FactGui.h	(revision 11779)
@@ -32,8 +32,11 @@
 #include "TColor.h"
 
+#include "QCameraWidget.h"
+
 using namespace std;
 
 // #########################################################################
 
+/*
 class Camera : public TObject
 {
@@ -45,10 +48,5 @@
     void CreatePalette()
     {
-        /*
-         double ss[5] = {0., 0.10, 0.45, 0.75, 1.00};
-         double rr[5] = {0., 0.35, 0.85, 1.00, 1.00};
-         double gg[5] = {0., 0.10, 0.20, 0.73, 1.00};
-         double bb[5] = {0., 0.03, 0.06, 0.00, 1.00};
-         */
+
         double ss[5] = {0.00, 0.25, 0.50, 0.75, 1.00};
         double rr[5] = {0.15, 0.00, 0.00, 1.00, 0.85};
@@ -353,5 +351,5 @@
     }
 };
-
+*/
 // #########################################################################
 
@@ -1867,11 +1865,11 @@
         }
 
-        TCanvas *c = fRatesCanv->GetCanvas();
-        Camera *cam = (Camera*)c->FindObject("Camera");
-
-        cam->SetData(dat);
-
-        c->Modified();
-        c->Update();
+//        TCanvas *c = fRatesCanv->GetCanvas();
+//        Camera *cam = (Camera*)c->FindObject("Camera");
+
+        fRatesCanv->SetData(dat);
+
+//        c->Modified();
+//        c->Update();
 #endif
     }
@@ -2167,13 +2165,13 @@
 
 #ifdef HAVE_ROOT
-        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
+//        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
         for (int isw=0; isw<1440; isw++)
         {
             const int ihw = fPixelMapHW[isw];
-            cam->SetEnable(isw, sdata.IsEnabled(ihw));
-        }
-
-        fRatesCanv->GetCanvas()->Modified();
-        fRatesCanv->GetCanvas()->Update();
+            fRatesCanv->SetEnable(isw, sdata.IsEnabled(ihw));
+        }
+
+//        fRatesCanv->GetCanvas()->Modified();
+//        fRatesCanv->GetCanvas()->Update();
 #endif
 
@@ -2763,4 +2761,5 @@
         // kEnterEvent            // TCanvas processed QEvent enterEvent
         // kLeaveEvent            // TCanvas processed QEvent leaveEvent
+
         if (dynamic_cast<TCanvas*>(obj))
             return;
@@ -2774,10 +2773,10 @@
                 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
                 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
-
-                Camera *cam = static_cast<Camera*>(obj);
-                const int isw = cam->GetIdx(xx, yy);
-
-                fPixelIdx->setValue(isw);
-                ChoosePixel(*cam, isw);
+//ETIENNE MESS HERE
+ //               Camera *cam = static_cast<Camera*>(obj);
+ //               const int isw = cam->GetIdx(xx, yy);
+
+ //               fPixelIdx->setValue(isw);
+ //               ChoosePixel(*cam, isw);
             }
             return;
@@ -2790,17 +2789,16 @@
                 const float xx = canv->AbsPixeltoX(tipped->GetEventX());
                 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
-
-                Camera *cam = static_cast<Camera*>(obj);
-                const int isw = cam->GetIdx(xx, yy);
-
-                ChoosePixel(*cam, isw);
-
-                fPixelIdx->setValue(isw);
-
-                const uint16_t ihw = fPixelMapHW[isw];
-
-                Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
+//ETIENNE MESS HERE
+//                Camera *cam = static_cast<Camera*>(obj);
+//                const int isw = cam->GetIdx(xx, yy);
+
+ //               ChoosePixel(*cam, isw);
+
+ //               fPixelIdx->setValue(isw);
+
+ //               const uint16_t ihw = fPixelMapHW[isw];
+
+ //               Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
             }
-
             if (dynamic_cast<TAxis*>(obj))
                 static_cast<TAxis*>(obj)->UnZoom();
@@ -2837,25 +2835,26 @@
                 const float yy = canv->AbsPixeltoY(tipped->GetEventY());
 
-                Camera *cam = static_cast<Camera*>(obj);
-
-                const int isw = cam->GetIdx(xx, yy);
-                const int ihw = fPixelMapHW[isw];
-
-                const int idx = fPatchHW[isw];
-
-                int ii = 0;
-                for (; ii<160; ii++)
-                    if (idx==fPatchMapHW[ii])
-                        break;
-
-
-                const int patch =  ihw%4;
-                const int board = (ihw/4)%10;
-                const int crate = (ihw/4)/10;
-
-                ostringstream str;
-                str << " (hw=" << ihw << ")  Patch=" << ii << "  (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
-
-                tipText += str.str().c_str();
+//ETIENNE MESS HERE
+//                Camera *cam = static_cast<Camera*>(obj);
+
+//                const int isw = cam->GetIdx(xx, yy);
+//                const int ihw = fPixelMapHW[isw];
+
+//                const int idx = fPatchHW[isw];
+
+//                int ii = 0;
+//                for (; ii<160; ii++)
+//                    if (idx==fPatchMapHW[ii])
+//                        break;
+
+
+//                const int patch =  ihw%4;
+//                const int board = (ihw/4)%10;
+//                const int crate = (ihw/4)/10;
+
+//                ostringstream str;
+//                str << " (hw=" << ihw << ")  Patch=" << ii << "  (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
+
+//                tipText += str.str().c_str();
             }
             fStatusBar->showMessage(tipText, 3000);
@@ -2926,9 +2925,44 @@
         fPixelEnable->setChecked(on);
     }
-
+    void slot_ChoosePixel(int isw)
+    {
+        fPixelIdx->setValue(isw);
+        const uint16_t ihw = fPixelMapHW[isw];
+        const bool on = fFtmStaticData.IsEnabled(ihw);
+        fPixelEnable->setChecked(on);
+    }
+    void slot_CameraDoubleClick(int isw)
+     {
+         fPixelIdx->setValue(isw);
+         const uint16_t ihw = fPixelMapHW[isw];
+         Dim::SendCommand("FTM_CONTROL/TOGGLE_PIXEL", ihw);
+     }
+    void slot_CameraMouseMove(int isw)
+    {
+        const int ihw = fPixelMapHW[isw];
+        const int idx = fPatchHW[isw];
+        int ii = 0;
+        for (; ii<160;ii++)
+            if (idx ==fPatchMapHW[ii])
+                break;
+
+        const int patch = ihw%4;
+        const int board = (ihw/4)%10;
+        const int crate = (ihw/4)/10;
+        QString tipText;
+        tipText += fRatesCanv->GetName();
+        tipText += " [";
+        tipText += "QCameraWidget";
+        tipText += "]: ";
+        ostringstream str;
+        str << " (hw=" << ihw << ")  Patch=" << ii << "  (hw=" << fPatchMapHW[idx] << "; Crate=" << crate << " Board=" << board << " Patch=" << patch << ")";
+        tipText += str.str().c_str();
+        fStatusBar->showMessage(tipText, 3000);
+    }
     void UpdatePatch(int isw)
     {
-        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
-        ChoosePatch(*cam, isw);
+//ETIENNE MESS HERE
+//        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
+//        ChoosePatch(*cam, isw);
     }
 
@@ -2937,6 +2971,6 @@
         UpdatePatch(isw);
 
-        fRatesCanv->GetCanvas()->Modified();
-        fRatesCanv->GetCanvas()->Update();
+//        fRatesCanv->GetCanvas()->Modified();
+ //       fRatesCanv->GetCanvas()->Update();
     }
 
@@ -2975,27 +3009,33 @@
     void on_fPixelIdx_valueChanged(int isw)
     {
-        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
-        ChoosePixel(*cam, isw);
-
-        fRatesCanv->GetCanvas()->Modified();
-        fRatesCanv->GetCanvas()->Update();
+//ETIENNE MESS HERE
+//        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
+ //       ChoosePixel(*cam, isw);
+          ChoosePixel(*fRatesCanv, isw);
+
+//        fRatesCanv->GetCanvas()->Modified();
+//        fRatesCanv->GetCanvas()->Update();
     }
 
     void on_fRatesMin_valueChanged(int min)
     {
-        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
-        cam->SetMin(min);
-
-        fRatesCanv->GetCanvas()->Modified();
-        fRatesCanv->GetCanvas()->Update();
+//ETIENNE MESS HERE
+//        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
+ //       cam->SetMin(min);
+          fRatesCanv->SetMin(min);
+
+//        fRatesCanv->GetCanvas()->Modified();
+//        fRatesCanv->GetCanvas()->Update();
     }
 
     void on_fRatesMax_valueChanged(int max)
     {
-        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
-        cam->SetMax(max);
-
-        fRatesCanv->GetCanvas()->Modified();
-        fRatesCanv->GetCanvas()->Update();
+//ETIENNE MESS HERE
+//        Camera *cam = (Camera*)fRatesCanv->GetCanvas()->FindObject("Camera");
+//        cam->SetMax(max);
+            fRatesCanv->SetMax(max);
+
+//        fRatesCanv->GetCanvas()->Modified();
+//        fRatesCanv->GetCanvas()->Update();
     }
 
@@ -3286,5 +3326,5 @@
         c->cd();
         */
-        //CreateTimeFrame("Temperature / °C");
+        //CreateTimeFrame("Temperature / �C");
 
         fGraphFtmTemp[0].SetMarkerStyle(kFullDotSmall);
@@ -3326,16 +3366,18 @@
         // --------------------------------------------------------------------------
 
-        c = fRatesCanv->GetCanvas();
+//ETIENNE MESS HERE
+//        c = fRatesCanv->GetCanvas();
         //c->SetBit(TCanvas::kNoContextMenu);
-        c->SetBorderMode(0);
-        c->SetFrameBorderMode(0);
-        c->SetFillColor(kWhite);
-        c->cd();
-
-        Camera *cam = new Camera;
-        cam->SetBit(kCanDelete);
+//        c->SetBorderMode(0);
+//        c->SetFrameBorderMode(0);
+//        c->SetFillColor(kWhite);
+//        c->cd();
+
+        Camera *cam = fRatesCanv;//new Camera;
+//        cam->SetBit(kCanDelete);
         cam->SetMin(fRatesMin->value());
         cam->SetMax(fRatesMax->value());
-        cam->Draw();
+//        cam->Draw();
+        cam->updateGL();
 
         ChoosePixel(*cam, 0);
@@ -3364,28 +3406,29 @@
         gPad->SetFrameBorderMode(0);
         gPad->SetFillColor(kWhite);
-        Camera *cam1 = new Camera;
-        cam1->SetBit(kCanDelete);
-        cam1->Draw();
+        //ETIENNE MESS HERE
+//       Camera *cam1 = new Camera;
+//        cam1->SetBit(kCanDelete);
+//        cam1->Draw();
         c->cd(2);
         gPad->SetBorderMode(0);
         gPad->SetFrameBorderMode(0);
         gPad->SetFillColor(kWhite);
-        Camera *cam2 = new Camera;
-        cam2->SetBit(kCanDelete);
-        cam2->Draw();
+//        Camera *cam2 = new Camera;
+//        cam2->SetBit(kCanDelete);
+//        cam2->Draw();
         c->cd(3);
         gPad->SetBorderMode(0);
         gPad->SetFrameBorderMode(0);
         gPad->SetFillColor(kWhite);
-        Camera *cam3 = new Camera;
-        cam3->SetBit(kCanDelete);
-        cam3->Draw();
+//        Camera *cam3 = new Camera;
+//        cam3->SetBit(kCanDelete);
+//        cam3->Draw();
         c->cd(4);
         gPad->SetBorderMode(0);
         gPad->SetFrameBorderMode(0);
         gPad->SetFillColor(kWhite);
-        Camera *cam4 = new Camera;
-        cam4->SetBit(kCanDelete);
-        cam4->Draw();
+ //       Camera *cam4 = new Camera;
+//        cam4->SetBit(kCanDelete);
+//        cam4->Draw();
 
 
@@ -3407,8 +3450,14 @@
 
         fRatesCanv->setMouseTracking(true);
-        fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
-
-        connect(fRatesCanv,   SIGNAL(     RootEventProcessed(TObject*, unsigned int, TCanvas*)),
-                this,         SLOT  (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
+//ETIENNE MESS HERE
+//        fRatesCanv->EnableSignalEvents(kMouseMoveEvent|kMouseReleaseEvent|kMouseDoubleClickEvent);
+//        connect(fRatesCanv,   SIGNAL(     RootEventProcessed(TObject*, unsigned int, TCanvas*)),
+//                this,         SLOT  (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
+        connect(fRatesCanv, SIGNAL(signalPixelMoveOver(int)),
+                this, SLOT(slot_CameraMouseMove(int)));
+        connect(fRatesCanv, SIGNAL(signalPixelDoubleClick(int)),
+                this, SLOT(slot_CameraDoubleClick(int)));
+        connect(fRatesCanv, SIGNAL(signalCurrentPixel(int)),
+                this, SLOT(slot_ChoosePixel(int)));
         connect(fFtmRateCanv, SIGNAL(     RootEventProcessed(TObject*, unsigned int, TCanvas*)),
                 this,         SLOT  (slot_RootEventProcessed(TObject*, unsigned int, TCanvas*)));
Index: trunk/FACT++/gui/MainWindow.h
===================================================================
--- trunk/FACT++/gui/MainWindow.h	(revision 11778)
+++ trunk/FACT++/gui/MainWindow.h	(revision 11779)
@@ -188,4 +188,7 @@
     virtual void slot_RootEventProcessed(TObject *, unsigned int, TCanvas *) = 0;
     virtual void slot_RootUpdate() = 0;
+    virtual void slot_ChoosePixel(int) = 0;
+    virtual void slot_CameraDoubleClick(int) = 0;
+    virtual void slot_CameraMouseMove(int) = 0;
 
     void slot_TimeUpdate();
Index: trunk/FACT++/gui/QCameraWidget.cc
===================================================================
--- trunk/FACT++/gui/QCameraWidget.cc	(revision 11779)
+++ trunk/FACT++/gui/QCameraWidget.cc	(revision 11779)
@@ -0,0 +1,160 @@
+#include "QCameraWidget.h"
+#include <sstream>
+#include <iostream>
+
+    QCameraWidget::QCameraWidget(QWidget *pparent) : BasicGlCamera(pparent)
+    {
+        fWhite = 0;
+        fBold.resize(1440);
+        fEnable.resize(1440);
+        fBold.assign(1440, false);
+        fEnable.assign(1440, true);
+        fMin = -1;
+        fMax = -1;
+    }
+    void QCameraWidget::paintGL()
+    {
+        glClear(GL_COLOR_BUFFER_BIT);
+         glLoadIdentity();
+
+         glTranslatef(0,-0.44,0);
+         glScalef(1.5, 1.5, 1.5);
+         drawCamera(true);
+         drawPatches();
+
+        glLineWidth(1.0f);
+        glColor3f(1,1,1);
+        drawHexagon(fWhite, false);
+    }
+    void QCameraWidget::drawCamera(bool alsoWire)
+    {
+        glLineWidth(1.0);
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+        {
+            glColor3fv(pixelsColor[i]);
+            glLoadName(i);
+            drawHexagon(i,true);
+        }
+        if (!alsoWire)
+            return;
+        glColor3f(0.0f,0.0f,0.0f);
+        for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+        {
+            drawHexagon(i, false);
+        }
+    }
+    void QCameraWidget::Reset()
+    {
+        fBold.assign(1440, false);
+    }
+    void QCameraWidget::mousePressEvent(QMouseEvent *cEvent)
+    {
+        int face = PixelAtPosition(cEvent->pos());
+        if (face != -1) {
+            fWhite = face;
+            emit signalCurrentPixel(face);
+            updateGL();
+            }
+    }
+    void QCameraWidget::mouseMoveEvent(QMouseEvent* cEvent)
+    {
+        int face = PixelAtPosition(cEvent->pos());
+        if (face != -1) {
+            emit signalPixelMoveOver(face);
+        }
+    }
+    void QCameraWidget::mouseDoubleClickEvent(QMouseEvent* cEvent)
+    {
+        int face = PixelAtPosition(cEvent->pos());
+        if (face != -1) {
+            fWhite = face;
+            emit signalPixelDoubleClick(face);
+            updateGL();
+        }
+    }
+     void QCameraWidget::SetBold(int idx)
+     {
+         cout << "Boldness not taken into account yet" << endl;
+     }
+     void QCameraWidget::SetWhite(int idx)
+     {
+         fWhite = idx;
+     }
+     void QCameraWidget::SetEnable(int idx, bool b)
+     {
+         fEnable[idx] = b;
+     }
+     void QCameraWidget::Toggle(int idx)
+     {
+     }
+     double QCameraWidget::GetData(int idx)
+     {
+         return fData[idx];
+     }
+     void QCameraWidget::SetMin(int64_t min)
+     {
+         fMin = min;
+         CalculatePixelsColor();
+     }
+     void QCameraWidget::SetMax(int64_t max)
+     {
+         fMax = max;
+         CalculatePixelsColor();
+     }
+     const char* QCameraWidget::GetName()
+     {
+         return "QCameraWidget";
+     }
+     char *QCameraWidget::GetObjectInfo(int px, int py)
+     {
+
+         static stringstream stream;
+         static string str;
+         const int pixel = this->PixelAtPosition(QPoint(px, py));
+         if (pixel >= 0)
+         {
+             stream << "Pixel=" << pixel << "   Data=" << fData[pixel] << '\0';
+         }
+         str = stream.str();
+         return const_cast<char*>(str.c_str());
+     }
+     void QCameraWidget::CalculatePixelsColor()
+     {
+         double dmin = fData[0];
+          double dmax = fData[0];
+          for (int i=0;i<1440;i++)
+          {
+              if (!fEnable[i]) continue;
+              if (fData[i] > dmax) dmax = fData[i];
+              if (fData[i] < dmin) dmin = fData[i];
+          }
+          if (fMin >= 0) dmin = fMin;
+          if (fMax >= 0) dmax = fMax;
+          float color;
+          for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+           {
+               color = float((fData[i]-dmin)/(dmax-dmin));
+               if (!fEnable[i])
+                   color = 0;
+               int index = 0;
+               while (ss[index] < color)
+                   index++;
+               index--;
+               if (index < 0) index = 0;
+               if (index > 3) index = 3;
+               float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
+               if (weight0 > 1.0f) weight0 = 1.0f;
+               if (weight0 < 0.0f) weight0 = 0.0f;
+               float weight1 = 1.0f-weight0;
+               pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
+               pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
+               pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
+          }
+     }
+     void QCameraWidget::SetData(const valarray<double> &ddata)
+     {
+         double min, max;
+         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
+             fData[i] = ddata[i];
+         CalculatePixelsColor();
+     }
Index: trunk/FACT++/gui/QCameraWidget.h
===================================================================
--- trunk/FACT++/gui/QCameraWidget.h	(revision 11779)
+++ trunk/FACT++/gui/QCameraWidget.h	(revision 11779)
@@ -0,0 +1,58 @@
+#ifndef Q_CAMERA_WIDGET_H_
+#define Q_CAMERA_WIDGET_H_
+
+#include "BasicGlCamera.h"
+#include <valarray>
+
+using namespace std;
+
+class QCameraWidget : public BasicGlCamera
+{
+    Q_OBJECT
+
+    typedef pair<double, double> Position;
+    typedef vector<Position> Positions;
+
+    Positions fGeom;
+
+    vector<bool> fBold;
+    vector<bool> fEnable;
+
+    int fWhite;
+
+    int64_t fMin;
+    int64_t fMax;
+
+public:
+    QCameraWidget(QWidget *pparent = 0);
+    void paintGL();
+    void mousePressEvent(QMouseEvent *cEvent);
+    void mouseMoveEvent(QMouseEvent *event);
+    void mouseDoubleClickEvent(QMouseEvent *event);
+    void Reset();
+    void drawCamera(bool alsoWire);
+     void SetBold(int idx);
+     void SetWhite(int idx);
+     void SetEnable(int idx, bool b);
+     void Toggle(int idx);
+     double GetData(int idx);
+     void SetMin(int64_t min);
+     void SetMax(int64_t max);
+     const char *GetName();
+
+     int GetIdx(float px, float py);
+     char *GetObjectInfo(int px, int py);
+
+     void SetData(const valarray<double> &ddata);
+
+Q_SIGNALS:
+         void signalCurrentPixel(int pixel);
+         void signalPixelMoveOver(int pixel);
+         void signalPixelDoubleClick(int pixel);
+
+private:
+     void CalculatePixelsColor();
+};
+
+typedef QCameraWidget Camera;
+#endif
Index: trunk/FACT++/gui/design.ui
===================================================================
--- trunk/FACT++/gui/design.ui	(revision 11778)
+++ trunk/FACT++/gui/design.ui	(revision 11779)
@@ -2805,5 +2805,5 @@
                </property>
                <item row="0" column="0">
-                <widget class="RootWidget" name="fRatesCanv" native="true"/>
+                <widget class="QCameraWidget" name="fRatesCanv" native="true"/>
                </item>
               </layout>
@@ -9873,4 +9873,19 @@
    <header>RootWidget.h</header>
    <container>1</container>
+  </customwidget>
+    <customwidget>
+   <class>QGLWidget</class>
+   <extends>QWidget</extends>
+   <header>QtOpenGL/QGLWidget</header>
+  </customwidget>
+  <customwidget>
+   <class>BasicGlCamera</class>
+   <extends>QGLWidget</extends>
+   <header>BasicGlCamera.h</header>
+  </customwidget>
+  <customwidget>
+   <class>QCameraWidget</class>
+   <extends>BasicGlCamera</extends>
+   <header>QCameraWidget.h</header>
   </customwidget>
   <customwidget>
