[PATCH] Limit to 4 the number of cylinders shown in the data frame

Dirk Hohndel dirk at hohndel.org
Wed Dec 26 13:26:48 PST 2012


Were you planning to attach screenshots or pdfs?

/D

On Dec 26, 2012, at 1:25 PM, Salvador Cuñat wrote:

> Good night.
> Here are attached  a pair of printouts of the test dives.  I have modified a pair of them, adding more text, weight and dummy tank data.
> As you can see, there is room for more data, probed they are not very big.
> 
> Regards.
> 
> Salva.
> 
> 
> 2012/12/26 Salvador Cuñat <salvador.cunat at gmail.com>
> For dives with more than 4 cylinders, the frame got very crowded and we
> needed a magnifier to see the numbers.
> If we used more than four tanks, let's put the info in another frame, if not, print
> the OTUs, the maxcns and the weight sytem in the new frame.
> There is still room for two more short data.
> 
> There are issues with the size of some translations, and CNS hasn't been
> translated (and I think it isn't worth the effort).
> 
> 
> Signed-off-by: Salvador Cuñat <salvador.cunat at gmail.com>
> ---
>  print.c |  350 ++++++++++++++++++++++++++++++++++++++++++++++----------------
>  1 files changed, 259 insertions(+), 91 deletions(-)
> 
> diff --git a/print.c b/print.c
> index 368ab94..d061862 100644
> --- a/print.c
> +++ b/print.c
> @@ -168,113 +168,281 @@ static void show_dive_notes(struct dive *dive, cairo_t *cr, double w,
> 
>  /*
>   * Show the tanks used in the dive, the mix, and the gas consumed
> - * as pressures are shown in the plot
> + * as pressures are shown in the plot. And other data if we used
> + * less than four cilynders.
>   */
>  static void show_dive_tanks(struct dive *dive, cairo_t *cr, double w,
>         double h, PangoFontDescription *font)
>  {
> -       int maxwidth, maxheight, curwidth, height, decimals, n, i, z,
> -           cyl_wp, cyl_press, cyl_end;
> -       double cyl_cap, cyl_cons_gas;
> -       const char *unit_vol, *unit_press;
> -       char buffer[80], dataheader1[3][80]= { N_("Cylinder"), N_("Gasmix"), N_("Gas Used")};
> -       PangoLayout *layout;
> +       int maxwidth, maxheight, height, tank_count;
> +
> +       /* Print the tank data */
> +       void print_tanks (int maxwidth, int maxheight, int height, int tank_count, int first_tank)
> +       {
> +               int curwidth, decimals, n, i, cyl_wp, cyl_press, cyl_end;
> +               double cyl_cap, cyl_cons_gas;
> +               const char *unit_vol, *unit_press;
> +               char buffer[80], dataheader1[3][80]= { N_("Cylinder"), N_("Gasmix"), N_("Gas Used")};
> +               PangoLayout *layout;
> +
> +               /* First create a header */
> +               maxheight -= height / 6;
> +               curwidth = 0;
> +               for (i = 0; i < 3; i++) {
> +                       cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> +                       layout = pango_cairo_create_layout(cr);
> +                       pango_layout_set_height(layout,maxheight);
> +                       pango_layout_set_width(layout, maxwidth / 3);
> +                       pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
> +                       if (tank_count < 4) {
> +                               set_font(layout, font, FONT_SMALL - (0.5 * tank_count), PANGO_ALIGN_CENTER);
> +                       } else {
> +                               set_font(layout, font, FONT_SMALL - 2, PANGO_ALIGN_CENTER);
> +                       }
> +                       pango_layout_set_text(layout, _(dataheader1[i]), -1);
> +                       pango_layout_set_justify(layout, 0);
> +                       pango_cairo_show_layout(cr, layout);
> +                       curwidth = curwidth + maxwidth/ 3;
> +               }
> +               /* Then the cylinder stuff */
> +               n = first_tank;
> +               while ( n < tank_count && n < first_tank + 4){
> +                       cairo_translate (cr, 0, height / (double) PANGO_SCALE);
> +                       cairo_move_to(cr, 0, 0);
> +                       cyl_cap = get_volume_units(dive->cylinder[n].type.size.mliter, &decimals, &unit_vol);
> +                       cyl_wp = get_pressure_units(dive->cylinder[n].type.workingpressure.mbar, &unit_press);
> +                       cyl_press= get_pressure_units(dive->cylinder[n].start.mbar, &unit_press);
> +                       cyl_end= get_pressure_units(dive->cylinder[n].end.mbar, &unit_press);
> +                       cyl_cons_gas = (cyl_press - cyl_end) * cyl_cap;
> +                       curwidth = 0;
> +                       i = 0;
> +                       while ( i < 3 ) {
> +                               cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> +                               switch(i) {
> +                                       case 0 : if (prefs.output_units.volume == CUFT) {
> +                                               cyl_cap *= cyl_wp / 14.7 ;
> +                                               }
> +                                               snprintf(buffer, sizeof(buffer), _("%.*f %s"),
> +                                                       decimals,
> +                                                       cyl_cap,
> +                                                       unit_vol);
> +                                       break;
> +                                       case 1 : cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> +                                               if (dive->cylinder[n].gasmix.o2.permille == 0){
> +                                                       snprintf(buffer, sizeof(buffer), _("air"));
> +                                               } else {
> +                                                       snprintf(buffer, sizeof(buffer), _("%d/%d"),
> +                                                       dive->cylinder[n].gasmix.o2.permille /10,
> +                                                       dive->cylinder[n].gasmix.he.permille /10);
> +                                               }
> +                                       break;
> +                                       case 2 : cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> +                                               if (prefs.output_units.volume == CUFT) {
> +                                                       cyl_cons_gas /= 14.7 ;
> +                                               }
> +                                               snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
> +                                                       decimals,
> +                                                       cyl_cons_gas,
> +                                                       unit_vol);
> +                                       break;
> +                                       default : snprintf(buffer, sizeof(buffer),"Error");
> +                               }
> +                               pango_layout_set_text(layout, buffer, -1);
> +                               pango_cairo_show_layout(cr, layout);
> +                               curwidth += (maxwidth/ 3);
> +                               i++;
> +                       }
> +                       maxheight -= height;
> +                       n++;
> +               }
> +               cairo_translate(cr, -0, - ((h * PANGO_SCALE * 0.9) - maxheight) / PANGO_SCALE);
> +               g_object_unref (layout);
> +       }
> 
> -       /*Create a frame to separate tank area, note the scaling*/
> -       cairo_rectangle(cr, 0, 0 + h*0.05, w, h*0.9);
> -       cairo_set_line_width(cr, 0.01);
> -       cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
> -       cairo_stroke(cr);
> +       /* Calculate total weight
> +        * copy/paste from divelist.c
> +        */
> +       double total_weight(struct dive *dive)
> +       {
> +               int i, total_grams = 0;
> +
> +               if (dive)
> +                       for (i=0; i< MAX_WEIGHTSYSTEMS; i++)
> +                               total_grams += dive->weightsystem[i].weight.grams;
> +               return total_grams;
> +       }
> +
> +       /* Print weight system */
> +       void print_weight_data (int maxwidth, int maxheight, int height){
> +               int decimals,i;
> +               double totalweight, totalweightsystem, weightsystemcounter;
> +               const char *unit_weight;
> +               char buffer[80];
> +               PangoLayout *layout;
> 
> -       maxwidth = w * PANGO_SCALE;
> -       maxheight = h * PANGO_SCALE * 0.9;
> +               layout = pango_cairo_create_layout(cr);
> +               pango_layout_set_height(layout,maxheight);
> +               pango_layout_set_width(layout, maxwidth);
> +               pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
> +               set_font(layout, font, FONT_SMALL - 3, PANGO_ALIGN_CENTER);
> 
> -       /* We need to know how many cylinders we used*/
> -       for (z = 0; z < MAX_CYLINDERS; z++ ){
> -               if (dive->cylinder[z].start.mbar == 0) {
> -                       break;
> +               /* Header for the weight system */
> +               cairo_move_to(cr, 0, 0);
> +               snprintf (buffer, sizeof(buffer),_("Weight System"));
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +
> +               /* Detail of the weight */
> +               cairo_translate (cr, 0, height / (3 * (double) PANGO_SCALE));
> +               set_font(layout, font, FONT_SMALL - 3, PANGO_ALIGN_LEFT);
> +               weightsystemcounter = 0;
> +               for (i=0; i<  MAX_WEIGHTSYSTEMS; i++){
> +                       totalweightsystem = get_weight_units(dive->weightsystem[i].weight.grams, &decimals, &unit_weight);
> +                       if (totalweightsystem == 0){
> +                       }else{
> +                               cairo_move_to(cr, 0, 0);
> +                               snprintf(buffer, sizeof(buffer), _("%s"),dive->weightsystem[i].description);
> +                               pango_layout_set_text(layout, buffer, -1);
> +                               pango_cairo_show_layout(cr, layout);
> +                               cairo_move_to(cr,(2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
> +                               snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
> +                                               decimals,
> +                                               totalweightsystem,
> +                                               unit_weight);
> +                               pango_layout_set_text(layout, buffer, -1);
> +                               pango_cairo_show_layout(cr, layout);
> +                               weightsystemcounter++;
> +                               cairo_translate (cr, 0, height / (4 * (double) PANGO_SCALE));
> +                       }
>                 }
> +
> +               /* Total weight of the system */
> +               totalweight = get_weight_units(total_weight(dive), &decimals, &unit_weight);
> +               cairo_translate (cr, 0, height / (4 * (double) PANGO_SCALE));
> +               cairo_move_to (cr, 0, 0);
> +               snprintf(buffer, sizeof(buffer), _("Total Weight:"));
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +               cairo_move_to(cr,(2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
> +               snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
> +                               decimals,
> +                               totalweight,
> +                               unit_weight);
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +
> +               /* undo translations */
> +               cairo_translate (cr, 0, -(weightsystemcounter * height) / (4 * (double) PANGO_SCALE));
> +               cairo_translate (cr, 0, -height / (3 * (double) PANGO_SCALE));
> +               g_object_unref (layout);
>         }
> 
> -       /* to determine the distance between lines*/
> -       if (z == 0){
> -               height = maxheight / 1;
> -       } else {
> -       height = maxheight / (z + 1);
> +       /* Print the dive OTUs */
> +       void print_otus (int maxwidth, int maxheight){
> +               char buffer[20];
> +               PangoLayout *layout;
> +
> +               layout = pango_cairo_create_layout(cr);
> +               pango_layout_set_height(layout, maxheight);
> +               pango_layout_set_width(layout, maxwidth);
> +               pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
> +               set_font(layout, font, FONT_SMALL - 3, PANGO_ALIGN_LEFT);
> +
> +               cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
> +               snprintf(buffer, sizeof(buffer), _("OTU"));
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +               cairo_move_to (cr, (2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
> +               snprintf(buffer, sizeof(buffer), "%d", dive->otu);
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +               g_object_unref (layout);
>         }
> 
> -       /* Then create the layout.
> -        * First a header */
> -       cairo_translate (cr, 0, height / (6 * (double) PANGO_SCALE));
> -       maxheight -= height / 6;
> -       curwidth = 0;
> -       for (i = 0; i < 3; i++) {
> -               cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> +       /* Print the dive maxCNS */
> +       void print_cns (int maxwidth, int maxheight){
> +               char buffer[20];
> +               PangoLayout *layout;
> +
>                 layout = pango_cairo_create_layout(cr);
> -               pango_layout_set_height(layout,maxheight);
> -               pango_layout_set_width(layout, maxwidth / 3);
> +               pango_layout_set_height(layout, maxheight);
> +               pango_layout_set_width(layout, maxwidth);
>                 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
> -               set_font(layout, font, FONT_SMALL * 0.10 *(11-z), PANGO_ALIGN_CENTER);
> -               pango_layout_set_text(layout, _(dataheader1[i]), -1);
> -               pango_layout_set_justify(layout, 0);
> +               set_font(layout, font, FONT_SMALL - 3, PANGO_ALIGN_LEFT);
> +
> +               cairo_move_to (cr,(maxwidth*0.05) / ((double) PANGO_SCALE), 0);
> +               snprintf(buffer, sizeof(buffer), _("Max. CNS"));
> +               pango_layout_set_text(layout, buffer, -1);
>                 pango_cairo_show_layout(cr, layout);
> -               curwidth = curwidth + maxwidth/ 3;
> +               cairo_move_to (cr, (2 * maxwidth) / (3 * (double) PANGO_SCALE), 0);
> +               snprintf(buffer, sizeof(buffer), "%d", dive->maxcns);
> +               pango_layout_set_text(layout, buffer, -1);
> +               pango_cairo_show_layout(cr, layout);
> +               g_object_unref (layout);
>         }
> 
> -       /* Now the relevant info*/
> -       for (n = 0; n < z; n++) {
> -               cairo_translate (cr, 0, height / (double) PANGO_SCALE);
> -               cairo_move_to(cr, 0, 0);
> +       /*
> +        * The real show_dive_tanks stuff
> +        */
> +       maxwidth = w * PANGO_SCALE;
> +       maxheight = h * PANGO_SCALE * 0.9;
> 
> -               cyl_cap = get_volume_units(dive->cylinder[n].type.size.mliter, &decimals, &unit_vol);
> -               cyl_wp = get_pressure_units(dive->cylinder[n].type.workingpressure.mbar, &unit_press);
> -               cyl_press= get_pressure_units(dive->cylinder[n].start.mbar, &unit_press);
> -               cyl_end= get_pressure_units(dive->cylinder[n].end.mbar, &unit_press);
> -               cyl_cons_gas = (cyl_press - cyl_end) * cyl_cap;
> +       /* We need to know how many cylinders we used*/
> +       for ( tank_count = 0; tank_count < MAX_CYLINDERS; tank_count++ ){
> +               if (dive->cylinder[tank_count].start.mbar == 0) {
> +                       break;
> +               }
> +       }
> 
> -               curwidth = 0;
> -               i = 0;
> -               while ( i < 3 ) {
> -                       cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> -                       switch(i) {
> -                               case 0 : if (prefs.output_units.volume == CUFT) {
> -                                                cyl_cap *= cyl_wp / 14.7 ;
> -                                        }
> -                                        snprintf(buffer, sizeof(buffer), _("%.*f %s"),
> -                                                        decimals,
> -                                                        cyl_cap,
> -                                                        unit_vol);
> -                                        break;
> -                               case 1 : cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> -                                        if (dive->cylinder[n].gasmix.o2.permille == 0){
> -                                                snprintf(buffer, sizeof(buffer), _("air"));
> -
> -                                        } else {
> -                                                snprintf(buffer, sizeof(buffer), _("%d/%d"),
> -                                                        dive->cylinder[n].gasmix.o2.permille /10,
> -                                                        dive->cylinder[n].gasmix.he.permille /10);
> -                                        }
> -                                        break;
> -                               case 2 : cairo_move_to(cr, curwidth / (double) PANGO_SCALE, 0);
> -                                        if (prefs.output_units.volume == CUFT) {
> -                                                cyl_cons_gas /= 14.7 ;
> -                                        }
> -                                        snprintf(buffer, sizeof(buffer), _("%.*f %s\n"),
> -                                                        decimals,
> -                                                        cyl_cons_gas,
> -                                                        unit_vol);
> -                                        break;
> -                               default : snprintf(buffer, sizeof(buffer),"Error");
> -                       }
> -                       pango_layout_set_text(layout, buffer, -1);
> -                       pango_cairo_show_layout(cr, layout);
> -                       curwidth += (maxwidth/ 3);
> -                       i += 1;
> +       /* and determine the distance between lines*/
> +       if (tank_count == 0) {
> +               height = maxheight;
> +       } else {
> +               if ( tank_count<=4 ) {
> +                       height = maxheight / (tank_count + 1);
> +               } else {
> +                       height = maxheight / 5;
>                 }
> -               maxheight -= height;
>         }
> -       cairo_translate(cr,0, - ((h * PANGO_SCALE * 0.9) - maxheight) / PANGO_SCALE);
> -       g_object_unref(layout);
> +
> +       /*Create a frame to separate tank area, note the scaling*/
> +       cairo_set_line_width(cr, 0.01);
> +       cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
> +       cairo_rectangle(cr, 0, h*0.02, w, h*0.95);
> +       cairo_stroke(cr);
> +       cairo_translate (cr, 0, height / (6 * (double) PANGO_SCALE));
> +
> +       print_tanks (maxwidth, maxheight, height, tank_count, 0);
> +
> +       cairo_set_line_width(cr, 0.01);
> +       cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
> +       cairo_rectangle(cr, w, h*0.02, w, h*0.95);
> +       cairo_stroke(cr);
> +
> +       /* If there are more than 4 tanks use the full width, else print other data*/
> +       if (tank_count > 4){
> +               cairo_translate (cr, w, height / (6 * (double) PANGO_SCALE));
> +               print_tanks (maxwidth, maxheight, height, tank_count, 4);
> +               cairo_translate (cr, -w, -height / (6 * (double) PANGO_SCALE));
> +       } else {
> +               /* Plot a grid for the data */
> +               cairo_move_to(cr, 3*w/2, h*0.05);
> +               cairo_line_to (cr, 3*w/2, h);
> +               cairo_move_to (cr, w, ((h * 0.9)/4) + (h*0.05));
> +               cairo_line_to (cr, 3*w/2, ((h * 0.9)/4) + (h*0.05));
> +               cairo_move_to (cr, w, ((h * 0.9)*2/4) + (h*0.05));
> +               cairo_line_to (cr, 3*w/2, ((h * 0.9)*2/4) + (h*0.05));
> +               cairo_stroke (cr);
> +               /* and print OTUs, CNS and weight */
> +               cairo_translate (cr, (3.05*w/2), height / (6 * (double) PANGO_SCALE));
> +               print_weight_data (maxwidth * 0.90/2 , maxheight, maxheight / 2);
> +               cairo_translate (cr, -(3.05*w/2), -height / (6 * (double) PANGO_SCALE));
> +               cairo_translate (cr, w, 0);
> +               print_otus (maxwidth * 0.90/2, maxheight);
> +               cairo_translate (cr, 0, h/4);
> +               print_cns (maxwidth * 0.90/2, maxheight);
> +               cairo_translate (cr, -w, -h/4);
> +       }
>  }
> 
>  static void show_table_header(cairo_t *cr, double w, double h,
> @@ -453,17 +621,17 @@ static void print(int divenr, cairo_t *cr, double x, double y, double w,
>         cairo_scale(cr, 0.5, 0.5);
> 
>         /* Dive plot in the upper two thirds - note the scaling */
> -       show_dive_profile(dive, cr, w*2, h*1.33);
> +       show_dive_profile(dive, cr, w*2, h*1.30);
> 
>         /* Dive information in the lower third */
> -       cairo_translate(cr, 0, h*1.33);
> +       cairo_translate(cr, 0, h*1.30);
>         show_dive_header(dive, cr, w*2, h*0.15, font);
> 
>         cairo_translate(cr, 0, h*0.15);
> -       show_dive_tanks (dive, cr, w*1, h*0.20, font);
> +       show_dive_tanks (dive, cr, w*1, h*0.25, font);
> 
> -       cairo_translate(cr, 0, h*0.20);
> -       show_dive_notes(dive, cr, w*2, h*0.32, font);
> +       cairo_translate(cr, 0, h*0.25);
> +       show_dive_notes(dive, cr, w*2, h*0.30, font);
> 
>         cairo_restore(cr);
>  }
> --
> 1.7.2.5
> 
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface



More information about the subsurface mailing list