Commit ca1789a8 authored by Mathieu Faverge's avatar Mathieu Faverge

cleanup(plugin mv)

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