Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ca1789a8 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

cleanup(plugin mv)

parent 36951eec
No related branches found
No related tags found
1 merge request!5Plugins/matrix visualizer
...@@ -92,7 +92,7 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd) ...@@ -92,7 +92,7 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
{ {
for (j = 0; j < DEFAULT_LEVEL_POWER_2; ++j) for (j = 0; j < DEFAULT_LEVEL_POWER_2; ++j)
{ {
m_colors[i][j] = 0.f; m_colors[i][j] = 1.f;
} }
} }
...@@ -130,7 +130,7 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd) ...@@ -130,7 +130,7 @@ void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
n = y; n = y;
do do
{ {
m_colors[m][n] = 1.0f; m_colors[m][n] = 0.0f;
n++; n++;
} while (n < yEnd); } while (n < yEnd);
......
...@@ -16,8 +16,8 @@ Matrix_visualizer::Matrix_visualizer() { ...@@ -16,8 +16,8 @@ Matrix_visualizer::Matrix_visualizer() {
this->connect_widgets(); this->connect_widgets();
// For windows dev (pc: orange) // For windows dev (pc: orange)
this->line_edit_symbol->setText("C:\\Data\\Lessons\\2017-2018\\PFA\\Matrix\\symb_lap40.txt"); this->line_edit_symbol->setText("/home/mathieu/svn/pastix/pastix/build/symbol_rank");
} }
Matrix_visualizer* Matrix_visualizer::Get() Matrix_visualizer* Matrix_visualizer::Get()
...@@ -60,7 +60,7 @@ void Matrix_visualizer::execute(){ ...@@ -60,7 +60,7 @@ void Matrix_visualizer::execute(){
if (symbol_filepath.size() == 0) if (symbol_filepath.size() == 0)
{ {
Helper::log(LogStatus::FATAL, "Empty filepath for symbol matrix file..."); Helper::log(LogStatus::FATAL, "Empty filepath for symbol matrix file...");
return; return;
} }
...@@ -138,17 +138,17 @@ void Matrix_visualizer::on_tool_button_symbol_clicked() ...@@ -138,17 +138,17 @@ void Matrix_visualizer::on_tool_button_symbol_clicked()
void Matrix_visualizer::on_tool_button_values_clicked() void Matrix_visualizer::on_tool_button_values_clicked()
{ {
QString values_filepath = QFileDialog::getOpenFileName(s_plugin, tr("Open file"), "C://"); QString values_filepath = QFileDialog::getOpenFileName(s_plugin, tr("Open file"), "C://");
s_plugin->line_edit_values->setText(values_filepath); s_plugin->line_edit_values->setText(values_filepath);
} }
void Matrix_visualizer::on_tool_button_infos_clicked() void Matrix_visualizer::on_tool_button_infos_clicked()
{ {
s_plugin->text_edit_infos->setText(""); s_plugin->text_edit_infos->setText("");
} }
void Matrix_visualizer::on_tool_button_logs_clicked() void Matrix_visualizer::on_tool_button_logs_clicked()
{ {
s_plugin->text_edit_logs->setText(""); s_plugin->text_edit_logs->setText("");
} }
...@@ -2,70 +2,74 @@ ...@@ -2,70 +2,74 @@
#include "MatrixWindow.hpp" #include "MatrixWindow.hpp"
#define BACKGROUND_COLOR_R 0.f #define BACKGROUND_COLOR_R 0.2f
#define BACKGROUND_COLOR_G 0.f #define BACKGROUND_COLOR_G 0.2f
#define BACKGROUND_COLOR_B 0.f #define BACKGROUND_COLOR_B 0.2f
/* Helpers */ /* Helpers */
static void drawSquare(GLfloat x, GLfloat y, GLfloat dx, GLfloat dy, GLfloat r, GLfloat g, GLfloat b) static void drawSquare(GLfloat x, GLfloat y, GLfloat dx, GLfloat dy, GLfloat r, GLfloat g, GLfloat b)
{ {
glBegin(GL_QUADS); glBegin(GL_QUADS);
// Setup color
glColor3f(r, g, b); // Setup color
glColor3f(r, g, b);
// Setup square corners
glVertex2f(x, y); // Setup square corners
glVertex2f(x + dx, y); glVertex2f(x, y);
glVertex2f(x + dx, y + dy); glVertex2f(x + dx, y);
glVertex2f(x, y + dy); glVertex2f(x + dx, y + dy);
glVertex2f(x, y + dy);
glEnd(); glEnd();
} }
static void drawTemporarySelection(int x, int y, int dx, int dy) static void drawTemporarySelection(int x, int y, int dx, int dy)
{ {
glBegin(GL_QUADS); glBegin(GL_QUADS);
// Setup color
glColor4f(1.f, 1.f, 1.f, .25f); // Setup color
glColor4f(1.f, 1.f, 1.f, .25f);
// Setup vertex
glVertex2f(x, y); // Setup vertex
glVertex2f(x + dx, y); glVertex2f(x, y);
glVertex2f(x + dx, y + dy); glVertex2f(x + dx, y);
glVertex2f(x, y + dy); glVertex2f(x + dx, y + dy);
glEnd(); glVertex2f(x, y + dy);
glEnd();
} }
MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* label) MatrixGLWidget::MatrixGLWidget(QWidget* parent, symbol_matrix_t* matrix, QLabel* label)
#ifdef USE_QT5 #ifdef USE_QT5
: QOpenGLWidget(parent) : QOpenGLWidget(parent)
#else #else
: QGLWidget(parent) : QGLWidget(parent)
#endif #endif
, m_label(label) , m_label(label)
, m_frameCount(0) , m_frameCount(0)
{ {
this->setFixedSize(MATRIX_WINDOW_LENGTH, MATRIX_WINDOW_HEIGHT); this->setFixedSize(MATRIX_WINDOW_LENGTH, MATRIX_WINDOW_HEIGHT);
m_zooming = new Zooming(matrix); m_zooming = new Zooming(matrix);
#ifdef USE_QT5 #ifdef USE_QT5
connect(&m_updateTimer, &QTimer::timeout, this, &MatrixGLWidget::updateTimer); connect(&m_updateTimer, &QTimer::timeout, this, &MatrixGLWidget::updateTimer);
#else #else
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimer())); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
#endif #endif
m_updateTimer.start(1000 / 60); m_updateTimer.start(1000 / 60);
m_qtToGLWidthCoeff = 1.f; m_qtToGLWidthCoeff = 1.f;
m_qtToGLHeightCoeff = 1.f; m_qtToGLHeightCoeff = 1.f;
m_camera.m_cameraX = 0.f; m_camera.m_cameraX = 0.f;
m_camera.m_cameraY = 0.f; m_camera.m_cameraY = 0.f;
m_camera.m_cameraDx = 1.f; m_camera.m_cameraDx = 1.f;
m_camera.m_cameraDy = 1.f; m_camera.m_cameraDy = 1.f;
m_mouseXClicked = -1; m_mouseXClicked = -1;
m_mouseYClicked = -1; m_mouseYClicked = -1;
} }
MatrixGLWidget::~MatrixGLWidget() MatrixGLWidget::~MatrixGLWidget()
...@@ -78,10 +82,10 @@ void MatrixGLWidget::initializeGL() ...@@ -78,10 +82,10 @@ void MatrixGLWidget::initializeGL()
#ifdef USE_QT5 #ifdef USE_QT5
initializeOpenGLFunctions(); initializeOpenGLFunctions();
#endif #endif
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glClearColor(BACKGROUND_COLOR_R, BACKGROUND_COLOR_G, BACKGROUND_COLOR_B, 1.f); glClearColor(BACKGROUND_COLOR_R, BACKGROUND_COLOR_G, BACKGROUND_COLOR_B, 1.f);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
...@@ -100,10 +104,10 @@ void MatrixGLWidget::resizeGL(int w, int h) ...@@ -100,10 +104,10 @@ void MatrixGLWidget::resizeGL(int w, int h)
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glTranslatef(0, 2, 0); glTranslatef(0, 2, 0);
m_qtToGLWidthCoeff = (double)Zooming::DEFAULT_LEVEL_POWER_2 / (double)w; m_qtToGLWidthCoeff = (double)Zooming::DEFAULT_LEVEL_POWER_2 / (double)w;
m_qtToGLHeightCoeff = (double)Zooming::DEFAULT_LEVEL_POWER_2 / (double)h; m_qtToGLHeightCoeff = (double)Zooming::DEFAULT_LEVEL_POWER_2 / (double)h;
} }
void MatrixGLWidget::paintGL() void MatrixGLWidget::paintGL()
...@@ -114,145 +118,145 @@ void MatrixGLWidget::paintGL() ...@@ -114,145 +118,145 @@ void MatrixGLWidget::paintGL()
initializeOpenGLFunctions(); initializeOpenGLFunctions();
#endif #endif
if (m_frameCount == 0) if (m_frameCount == 0)
m_time.start(); m_time.start();
else else
{ {
sprintf(m_fpsString, "FPS: %f ms", m_time.elapsed() / float(m_frameCount)); sprintf(m_fpsString, "FPS: %f ms", m_time.elapsed() / float(m_frameCount));
m_label->setText(m_fpsString); m_label->setText(m_fpsString);
} }
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f); glClearColor(0.f, 0.f, 0.f, 0.f);
for (i = 0; i < Zooming::DEFAULT_LEVEL_POWER_2; ++i) for (i = 0; i < Zooming::DEFAULT_LEVEL_POWER_2; ++i)
{ {
for (j = 0; j < Zooming::DEFAULT_LEVEL_POWER_2; ++j) for (j = 0; j < Zooming::DEFAULT_LEVEL_POWER_2; ++j)
{ {
GLfloat grey = m_zooming->getColor(i, j); GLfloat grey = m_zooming->getColor(i, j);
if (grey != 0.f) if (grey != 0.f)
drawSquare(i, j, 1, 1, grey, grey, grey); drawSquare(i, j, 1, 1, grey, grey, grey);
} }
} }
if (m_drawTempSelection == 1) if (m_drawTempSelection == 1)
drawTemporarySelection(m_tempSelectionX, m_tempSelectionY, m_tempSelectionDx, m_tempSelectionDy); drawTemporarySelection(m_tempSelectionX, m_tempSelectionY, m_tempSelectionDx, m_tempSelectionDy);
m_frameCount++; m_frameCount++;
} }
void MatrixGLWidget::updateTimer() void MatrixGLWidget::updateTimer()
{ {
// Need to do this because the connect function cannot // Need to do this because the connect function cannot
// differenciate overloaded cases of update // differenciate overloaded cases of update
update(); update();
} }
void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent) void MatrixGLWidget::keyPressEvent(QKeyEvent *keyEvent)
{ {
switch (keyEvent->key()) switch (keyEvent->key())
{ {
default: default:
break; break;
} }
} }
void MatrixGLWidget::mousePressEvent(QMouseEvent* mouseEvent) void MatrixGLWidget::mousePressEvent(QMouseEvent* mouseEvent)
{ {
if (mouseEvent->button() == Qt::RightButton) if (mouseEvent->button() == Qt::RightButton)
{ {
if (m_savedPositions.size() > 0) if (m_savedPositions.size() > 0)
{ {
CameraPosition newCamera = m_savedPositions.top(); CameraPosition newCamera = m_savedPositions.top();
m_savedPositions.pop(); m_savedPositions.pop();
m_camera = newCamera; m_camera = newCamera;
refreshCamera(); refreshCamera();
} }
} }
else if (mouseEvent->button() == Qt::LeftButton) else if (mouseEvent->button() == Qt::LeftButton)
{ {
m_mouseXClicked = mouseEvent->x() * m_qtToGLWidthCoeff; m_mouseXClicked = mouseEvent->x() * m_qtToGLWidthCoeff;
m_mouseYClicked = mouseEvent->y() * m_qtToGLHeightCoeff; m_mouseYClicked = mouseEvent->y() * m_qtToGLHeightCoeff;
} }
} }
void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent) void MatrixGLWidget::mouseMoveEvent(QMouseEvent* mouseEvent)
{ {
if (m_mouseXClicked != -1 && m_mouseYClicked != -1) if (m_mouseXClicked != -1 && m_mouseYClicked != -1)
{ {
int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff; int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff;
int glPosY = mouseEvent->y() * m_qtToGLHeightCoeff; int glPosY = mouseEvent->y() * m_qtToGLHeightCoeff;
int firstPosX = m_mouseXClicked; int firstPosX = m_mouseXClicked;
int firstPosY = m_mouseYClicked; int firstPosY = m_mouseYClicked;
if (firstPosX > glPosX) if (firstPosX > glPosX)
{ {
int tmp = firstPosX; int tmp = firstPosX;
firstPosX = glPosX; firstPosX = glPosX;
glPosX = tmp; glPosX = tmp;
} }
if (firstPosY > glPosY) if (firstPosY > glPosY)
{ {
int tmp = firstPosY; int tmp = firstPosY;
firstPosY = glPosY; firstPosY = glPosY;
glPosY = tmp; glPosY = tmp;
} }
m_drawTempSelection = 1; m_drawTempSelection = 1;
m_tempSelectionX = firstPosX; m_tempSelectionX = firstPosX;
m_tempSelectionY = firstPosY; m_tempSelectionY = firstPosY;
m_tempSelectionDx = glPosX - firstPosX; m_tempSelectionDx = glPosX - firstPosX;
m_tempSelectionDy = glPosY - firstPosY; m_tempSelectionDy = glPosY - firstPosY;
} }
} }
void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent) void MatrixGLWidget::mouseReleaseEvent(QMouseEvent* mouseEvent)
{ {
if (m_mouseXClicked != -1 && m_mouseYClicked != -1) if (m_mouseXClicked != -1 && m_mouseYClicked != -1)
{ {
int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff; int glPosX = mouseEvent->x() * m_qtToGLWidthCoeff;
int glPosY = mouseEvent->y() * m_qtToGLHeightCoeff; int glPosY = mouseEvent->y() * m_qtToGLHeightCoeff;
m_savedPositions.push(m_camera); m_savedPositions.push(m_camera);
m_drawTempSelection = 0; m_drawTempSelection = 0;
// Switch min max // Switch min max
if (m_mouseXClicked > glPosX) if (m_mouseXClicked > glPosX)
{ {
int tmp = m_mouseXClicked; int tmp = m_mouseXClicked;
m_mouseXClicked = glPosX; m_mouseXClicked = glPosX;
glPosX = tmp; glPosX = tmp;
} }
if (m_mouseYClicked > glPosY) if (m_mouseYClicked > glPosY)
{ {
int tmp = m_mouseXClicked; int tmp = m_mouseXClicked;
m_mouseYClicked = glPosY; m_mouseYClicked = glPosY;
glPosY = tmp; glPosY = tmp;
} }
int diffX = glPosX - m_mouseXClicked; int diffX = glPosX - m_mouseXClicked;
int diffY = glPosY - m_mouseYClicked; int diffY = glPosY - m_mouseYClicked;
m_camera.m_cameraX += ((double)m_mouseXClicked * m_camera.m_cameraDx) / (double)Zooming::DEFAULT_LEVEL_POWER_2; m_camera.m_cameraX += ((double)m_mouseXClicked * m_camera.m_cameraDx) / (double)Zooming::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraY += ((double)m_mouseYClicked * m_camera.m_cameraDy) / (double)Zooming::DEFAULT_LEVEL_POWER_2; m_camera.m_cameraY += ((double)m_mouseYClicked * m_camera.m_cameraDy) / (double)Zooming::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraDx = ((double)diffX * m_camera.m_cameraDx) / (double)Zooming::DEFAULT_LEVEL_POWER_2; m_camera.m_cameraDx = ((double)diffX * m_camera.m_cameraDx) / (double)Zooming::DEFAULT_LEVEL_POWER_2;
m_camera.m_cameraDy = ((double)diffY * m_camera.m_cameraDy) / (double)Zooming::DEFAULT_LEVEL_POWER_2; m_camera.m_cameraDy = ((double)diffY * m_camera.m_cameraDy) / (double)Zooming::DEFAULT_LEVEL_POWER_2;
refreshCamera(); refreshCamera();
m_mouseXClicked = -1; m_mouseXClicked = -1;
m_mouseYClicked = -1; m_mouseYClicked = -1;
} }
} }
void MatrixGLWidget::refreshCamera() void MatrixGLWidget::refreshCamera()
{ {
m_zooming->move(m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx, m_zooming->move(m_camera.m_cameraX, m_camera.m_cameraX + m_camera.m_cameraDx,
m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy); m_camera.m_cameraY, m_camera.m_cameraY + m_camera.m_cameraDy);
} }
\ No newline at end of file
...@@ -7,8 +7,8 @@ Matrix_window::Matrix_window(symbol_matrix_t* matrix) ...@@ -7,8 +7,8 @@ Matrix_window::Matrix_window(symbol_matrix_t* matrix)
QWidget* widget = new QWidget(); QWidget* widget = new QWidget();
QVBoxLayout* layout = new QVBoxLayout(widget); QVBoxLayout* layout = new QVBoxLayout(widget);
m_label = new QLabel(nullptr); m_label = new QLabel(nullptr);
m_label->setText("Infos: "); m_label->setText("Infos: ");
m_gl = new MatrixGLWidget(nullptr, matrix, m_label); m_gl = new MatrixGLWidget(nullptr, matrix, m_label);
m_gl->setObjectName(QString("matrix_gl_visualizer")); m_gl->setObjectName(QString("matrix_gl_visualizer"));
...@@ -26,7 +26,6 @@ Matrix_window::~Matrix_window() ...@@ -26,7 +26,6 @@ Matrix_window::~Matrix_window()
void Matrix_window::closeEvent(QCloseEvent* event) void Matrix_window::closeEvent(QCloseEvent* event)
{ {
// Dégueu
delete this; delete this;
} }
...@@ -35,7 +34,7 @@ void Matrix_window::keyPressEvent(QKeyEvent* event) ...@@ -35,7 +34,7 @@ void Matrix_window::keyPressEvent(QKeyEvent* event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Escape: case Qt::Key_Escape:
close(); close();
break; break;
} }
} }
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QLabel> #include <QLabel>
#define MATRIX_WINDOW_LENGTH 512 #define MATRIX_WINDOW_LENGTH 512
#define MATRIX_WINDOW_HEIGHT 512 #define MATRIX_WINDOW_HEIGHT 512
class Matrix_window : public QMainWindow class Matrix_window : public QMainWindow
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment