Moved the plot from the cairo version to the Qt version

Started working on the Qt version of the Plot, initially
nothing is printed - but this is not a bad thing,
the program doesn't explodes too. :)

some work had to be done about the 'bool/gboolean' stuff
so I removed all gbooleans in the code that I'v encountered.

A new file was created ( profile.h ) so I could put the
signatures of helper methods that cairo used to call.

till now the code computes the max limits.
Next patch the first drawing will be made.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-05-04 17:24:23 -03:00
parent a58412cb31
commit c74dc11167
4 changed files with 182 additions and 133 deletions

View file

@ -1,18 +1,26 @@
#ifndef DISPLAY_H
#define DISPLAY_H
#include <cairo.h>
#ifdef __cplusplus
extern "C" {
#else
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#else
typedef int bool;
#endif
#endif
#define SCALE_SCREEN 1.0
#define SCALE_PRINT (1.0 / get_screen_dpi())
#warning "PORT THE get_screen_dpi to Qt"
#define SCALE_PRINT 1.0
//#define SCALE_PRINT (1.0 / get_screen_dpi())
extern void repaint_dive(void);
extern void do_print(void);
extern gdouble get_screen_dpi(void);
// Commented out because I don't know how to get the dpi on a paint device yet.
// extern gdouble get_screen_dpi(void);
/* Plot info with smoothing, velocity indication
* and one-, two- and three-minute minimums and maximums */
@ -24,10 +32,15 @@ struct plot_info {
int mintemp, maxtemp;
double endtempcoord;
double maxpp;
gboolean has_ndl;
bool has_ndl;
struct plot_data *entry;
};
/*
// I'm not sure if this is needed anymore - but keeping this here
// so I wont break stuff trying to redo the well.
*/
/*
* Cairo scaling really is horribly horribly mis-designed.
*
@ -38,8 +51,6 @@ struct plot_info {
*/
struct graphics_context {
int printer;
cairo_t *cr;
cairo_rectangle_t drawing_area;
double maxx, maxy;
double leftx, rightx;
double topy, bottomy;
@ -61,7 +72,7 @@ struct options {
enum { PRETTY, TABLE, TWOPERPAGE } type;
int print_selected;
int color_selected;
gboolean notes_up;
bool notes_up;
int profile_height, notes_height, tanks_height;
};

123
profile.c
View file

@ -18,9 +18,6 @@ int selected_dive = 0;
char zoomed_plot = 0;
char dc_number = 0;
#if USE_GTK_UI
static double plot_scale = SCALE_SCREEN;
#endif
static struct plot_data *last_pi_entry = NULL;
@ -1951,126 +1948,6 @@ struct divecomputer *select_dc(struct divecomputer *main)
return main;
}
#if USE_GTK_UI
void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
{
struct plot_info *pi;
struct divecomputer *dc = &dive->dc;
cairo_rectangle_t *drawing_area = &gc->drawing_area;
const char *nickname;
plot_set_scale(scale);
if (!dc->samples) {
static struct sample fake[4];
static struct divecomputer fakedc;
fakedc = dive->dc;
fakedc.sample = fake;
fakedc.samples = 4;
/* The dive has no samples, so create a few fake ones. This assumes an
ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
int duration = dive->dc.duration.seconds;
int maxdepth = dive->dc.maxdepth.mm;
int asc_desc_time = dive->dc.maxdepth.mm*60/9000;
if (asc_desc_time * 2 >= duration)
asc_desc_time = duration / 2;
fake[1].time.seconds = asc_desc_time;
fake[1].depth.mm = maxdepth;
fake[2].time.seconds = duration - asc_desc_time;
fake[2].depth.mm = maxdepth;
fake[3].time.seconds = duration * 1.00;
fakedc.events = dc->events;
dc = &fakedc;
}
/*
* Set up limits that are independent of
* the dive computer
*/
calculate_max_limits(dive, dc, gc);
/* shift the drawing area so we have a nice margin around it */
cairo_translate(gc->cr, drawing_area->x, drawing_area->y);
cairo_set_line_width_scaled(gc->cr, 1);
cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
/*
* We don't use "cairo_translate()" because that doesn't
* scale line width etc. But the actual scaling we need
* do set up ourselves..
*
* Snif. What a pity.
*/
gc->maxx = (drawing_area->width - 2*drawing_area->x);
gc->maxy = (drawing_area->height - 2*drawing_area->y);
dc = select_dc(dc);
/* This is per-dive-computer. Right now we just do the first one */
pi = create_plot_info(dive, dc, gc);
/* Depth profile */
plot_depth_profile(gc, pi);
plot_events(gc, pi, dc);
/* Temperature profile */
plot_temperature_profile(gc, pi);
/* Cylinder pressure plot */
plot_cylinder_pressure(gc, pi, dive, dc);
/* Text on top of all graphs.. */
plot_temperature_text(gc, pi);
plot_depth_text(gc, pi);
plot_cylinder_pressure_text(gc, pi);
plot_deco_text(gc, pi);
/* Bounding box last */
gc->leftx = 0; gc->rightx = 1.0;
gc->topy = 0; gc->bottomy = 1.0;
set_source_rgba(gc, BOUNDING_BOX);
cairo_set_line_width_scaled(gc->cr, 1);
move_to(gc, 0, 0);
line_to(gc, 0, 1);
line_to(gc, 1, 1);
line_to(gc, 1, 0);
cairo_close_path(gc->cr);
cairo_stroke(gc->cr);
/* Put the dive computer name in the lower left corner */
nickname = get_dc_nickname(dc->model, dc->deviceid);
if (!nickname || *nickname == '\0')
nickname = dc->model;
if (nickname) {
static const text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE};
plot_text(gc, &computer, 0, 1, "%s", nickname);
}
if (PP_GRAPHS_ENABLED) {
plot_pp_gas_profile(gc, pi);
plot_pp_text(gc, pi);
}
/* now shift the translation back by half the margin;
* this way we can draw the vertical scales on both sides */
cairo_translate(gc->cr, -drawing_area->x / 2.0, 0);
gc->maxx += drawing_area->x;
gc->leftx = -(drawing_area->x / drawing_area->width) / 2.0;
gc->rightx = 1.0 - gc->leftx;
plot_depth_scale(gc, pi);
if (gc->printer) {
free(pi->entry);
last_pi_entry = pi->entry = NULL;
pi->nr = 0;
}
}
#endif /* USE_GTK_UI */
static void plot_string(struct plot_data *entry, char *buf, size_t bufsize,
int depth, int pressure, int temp, gboolean has_ndl)
{

25
profile.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef PROFILE_H
#define PROFILE_H
#ifdef __cplusplus
extern "C" {
#else
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#else
typedef int bool;
#endif
#endif
struct dive;
struct divecomputer;
struct graphics_context;
struct plot_info;
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -6,12 +6,17 @@
#include <QDebug>
#include "../color.h"
#include "../display.h"
#include "../dive.h"
#include "../profile.h"
#define SAC_COLORS_START_IDX SAC_1
#define SAC_COLORS 9
#define VELOCITY_COLORS_START_IDX VELO_STABLE
#define VELOCITY_COLORS 5
static double plot_scale = SCALE_SCREEN;
typedef enum {
/* SAC colors. Order is important, the SAC_COLORS_START_IDX define above. */
SAC_1, SAC_2, SAC_3, SAC_4, SAC_5, SAC_6, SAC_7, SAC_8, SAC_9,
@ -92,9 +97,140 @@ ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent
fill_profile_color();
}
void ProfileGraphicsView::plot(struct dive *d)
static void plot_set_scale(scale_mode_t scale)
{
qDebug() << "Start the plotting of the dive here.";
switch (scale) {
default:
case SC_SCREEN:
plot_scale = SCALE_SCREEN;
break;
case SC_PRINT:
plot_scale = SCALE_PRINT;
break;
}
}
void ProfileGraphicsView::plot(struct dive *dive)
{
struct plot_info *pi;
struct divecomputer *dc = &dive->dc;
// This was passed around in the Cairo version / needed?
graphics_context gc;
const char *nickname;
// Fix this for printing / screen later.
// plot_set_scale( scale_mode_t);
if (!dc->samples) {
static struct sample fake[4];
static struct divecomputer fakedc;
fakedc = dive->dc;
fakedc.sample = fake;
fakedc.samples = 4;
/* The dive has no samples, so create a few fake ones. This assumes an
ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
int duration = dive->dc.duration.seconds;
int maxdepth = dive->dc.maxdepth.mm;
int asc_desc_time = dive->dc.maxdepth.mm*60/9000;
if (asc_desc_time * 2 >= duration)
asc_desc_time = duration / 2;
fake[1].time.seconds = asc_desc_time;
fake[1].depth.mm = maxdepth;
fake[2].time.seconds = duration - asc_desc_time;
fake[2].depth.mm = maxdepth;
fake[3].time.seconds = duration * 1.00;
fakedc.events = dc->events;
dc = &fakedc;
}
/*
* Set up limits that are independent of
* the dive computer
*/
calculate_max_limits(dive, dc, &gc);
#if 0
/* shift the drawing area so we have a nice margin around it */
cairo_translate(gc->cr, drawing_area->x, drawing_area->y);
cairo_set_line_width_scaled(gc->cr, 1);
cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
/*
* We don't use "cairo_translate()" because that doesn't
* scale line width etc. But the actual scaling we need
* do set up ourselves..
*
* Snif. What a pity.
*/
gc->maxx = (drawing_area->width - 2*drawing_area->x);
gc->maxy = (drawing_area->height - 2*drawing_area->y);
dc = select_dc(dc);
/* This is per-dive-computer. Right now we just do the first one */
pi = create_plot_info(dive, dc, gc);
/* Depth profile */
plot_depth_profile(gc, pi);
plot_events(gc, pi, dc);
/* Temperature profile */
plot_temperature_profile(gc, pi);
/* Cylinder pressure plot */
plot_cylinder_pressure(gc, pi, dive, dc);
/* Text on top of all graphs.. */
plot_temperature_text(gc, pi);
plot_depth_text(gc, pi);
plot_cylinder_pressure_text(gc, pi);
plot_deco_text(gc, pi);
/* Bounding box last */
gc->leftx = 0; gc->rightx = 1.0;
gc->topy = 0; gc->bottomy = 1.0;
set_source_rgba(gc, BOUNDING_BOX);
cairo_set_line_width_scaled(gc->cr, 1);
move_to(gc, 0, 0);
line_to(gc, 0, 1);
line_to(gc, 1, 1);
line_to(gc, 1, 0);
cairo_close_path(gc->cr);
cairo_stroke(gc->cr);
/* Put the dive computer name in the lower left corner */
nickname = get_dc_nickname(dc->model, dc->deviceid);
if (!nickname || *nickname == '\0')
nickname = dc->model;
if (nickname) {
static const text_render_options_t computer = {DC_TEXT_SIZE, TIME_TEXT, LEFT, MIDDLE};
plot_text(gc, &computer, 0, 1, "%s", nickname);
}
if (PP_GRAPHS_ENABLED) {
plot_pp_gas_profile(gc, pi);
plot_pp_text(gc, pi);
}
/* now shift the translation back by half the margin;
* this way we can draw the vertical scales on both sides */
cairo_translate(gc->cr, -drawing_area->x / 2.0, 0);
gc->maxx += drawing_area->x;
gc->leftx = -(drawing_area->x / drawing_area->width) / 2.0;
gc->rightx = 1.0 - gc->leftx;
plot_depth_scale(gc, pi);
if (gc->printer) {
free(pi->entry);
last_pi_entry = pi->entry = NULL;
pi->nr = 0;
}
#endif
}
void ProfileGraphicsView::resizeEvent(QResizeEvent *event)