Permalink
Browse files

move of indices to common class

  • Loading branch information...
1 parent fced77f commit 0e02b990ceeeccf563013a5167be106981f2c2d7 @pchilds committed Sep 14, 2012
View
@@ -50,8 +50,23 @@ void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArr
{(plot->rd)=g_array_ref(rd); (plot->gr)=g_array_ref(gr); (plot->bl)=g_array_ref(bl); (plot->al)=g_array_ref(al);}
}
+void gtk_plot_set_indices(GtkPlot *plot, GArray *nx, GArray *sz)
+{
+ if (plot->ind) g_array_free((plot->ind), FALSE);
+ if (plot->sizes) g_array_free((plot->sizes), FALSE);
+ {(plot->ind)=g_array_ref(nx); (plot->sizes)=g_array_ref(sz);}
+}
+
+void gtk_plot_set_index(GtkPlot *plot, GArray *nx)
+{
+ if (plot->ind) g_array_free((plot->ind), FALSE);
+ (plot->ind)=g_array_ref(nx);
+}
+
static void gtk_plot_finalise(GtkPlot *plot)
{
+ if (plot->ind) g_array_free((plot->ind), FALSE);
+ if (plot->sizes) g_array_free((plot->sizes), FALSE);
if (plot->afont) pango_font_description_free(plot->afont);
if (plot->lfont) pango_font_description_free(plot->lfont);
if (plot->rd) g_array_free((plot->rd), FALSE);
@@ -77,6 +92,7 @@ static void gtk_plot_init(GtkPlot *plot)
{pango_font_description_set_family((plot->afont), "sans"); pango_font_description_set_family((plot->lfont), "sans");}
{pango_font_description_set_style((plot->afont), PANGO_STYLE_NORMAL); pango_font_description_set_style((plot->lfont), PANGO_STYLE_NORMAL);}
{pango_font_description_set_size((plot->afont), 12*PANGO_SCALE); pango_font_description_set_size((plot->lfont), 12*PANGO_SCALE);}
+ {(plot->sizes)=NULL; (plot->ind)=NULL;}
(plot->rd)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
(plot->gr)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
(plot->bl)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
View
@@ -39,6 +39,7 @@
struct _GtkPlot
{
GtkDrawingArea parent;
+ GArray *ind, *sizes; /* indices of first element and number of elements for each trace */
GArray *rd, *gr, *bl, *al; /* colour and alpha of the plots */
PangoFontDescription *afont, *lfont; /* font descriptions for the tick mark and axis labels */
};
@@ -48,6 +49,8 @@
};
void gtk_plot_set_font(GtkPlot *plot, PangoFontDescription *lf, PangoFontDescription *af);
void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArray *al);
+ void gtk_plot_set_indices(GtkPlot *plot, GArray *nd, GArray *sz);
+ void gtk_plot_set_index(GtkPlot *plot, GArray *nd);
GtkWidget *gtk_plot_new(void);
G_END_DECLS
#endif
View
@@ -2933,13 +2933,13 @@ static void draw(GtkWidget *widget, cairo_t *cr)
cairo_set_line_width(cr, (plot->linew));
if (((plot->flagd)&GTK_PLOT_LINEAR_DISP_PTS)!=0) /* lines and points */
{
- for (k=0; k<(plot->ind->len); k++)
+ for (k=0; k<(plt->ind->len); k++)
{
dtt=fmod(k,(plt->rd->len));
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av);
- ft=g_array_index((plot->ind), gint, k);
- lt=g_array_index((plot->sizes), gint, k)+ft;
+ ft=g_array_index((plt->ind), gint, k);
+ lt=g_array_index((plt->sizes), gint, k)+ft;
xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if (xv<xl)
@@ -3283,13 +3283,13 @@ static void draw(GtkWidget *widget, cairo_t *cr)
}
else /* lines only */
{
- for (k=0;k<(plot->ind->len);k++)
+ for (k=0;k<(plt->ind->len);k++)
{
dtt=fmod(k,(plt->rd->len));
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av);
- ft=g_array_index((plot->ind), gint, k);
- lt=g_array_index((plot->sizes), gint, k)+ft;
+ ft=g_array_index((plt->ind), gint, k);
+ lt=g_array_index((plt->sizes), gint, k)+ft;
xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));/*segfault here when adding a plot*/
yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if (xv<xl)
@@ -3640,13 +3640,13 @@ static void draw(GtkWidget *widget, cairo_t *cr)
}
else if (((plot->flagd)&GTK_PLOT_LINEAR_DISP_PTS)!=0) /* points only */
{
- for (k=0;k<(plot->ind->len);k++)
+ for (k=0;k<(plt->ind->len);k++)
{
dtt=fmod(k,(plt->rd->len));
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av);
- ft=g_array_index((plot->ind), gint, k);
- lt=g_array_index((plot->sizes), gint, k)+ft;
+ ft=g_array_index((plt->ind), gint, k);
+ lt=g_array_index((plt->sizes), gint, k)+ft;
xv=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yv=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if ((yv<=yl)&&(yv>=yu)&&(xv>=xl)&&(xv<=xu))
@@ -4178,74 +4178,65 @@ void gtk_plot_linear_set_data(GtkPlotLinear *plot, GArray *xd, GArray *yd, GArra
{
if (plot->xdata) g_array_free((plot->xdata), FALSE);
if (plot->ydata) g_array_free((plot->ydata), FALSE);
- if (plot->ind) g_array_free((plot->ind), FALSE);
- if (plot->sizes) g_array_free((plot->sizes), FALSE);
- {(plot->xdata)=g_array_ref(xd); (plot->ydata)=g_array_ref(yd); (plot->ind)=g_array_ref(nd); (plot->sizes)=g_array_ref(sz);}
+ {(plot->xdata)=g_array_ref(xd); (plot->ydata)=g_array_ref(yd);}
+ gtk_plot_set_indices(GTK_PLOT(plot), nd, sz);
}
static void gtk_plot_linear_finalise(GtkPlotLinear *plot)
{
- GtkPlotLinearPrivate *priv;
-
- priv=GTK_PLOT_LINEAR_GET_PRIVATE(plot);
if (plot->xlab) g_free(plot->xlab);
if (plot->ylab) g_free(plot->ylab);
if (plot->xdata) g_array_free((plot->xdata), FALSE);
if (plot->ydata) g_array_free((plot->ydata), FALSE);
- if (plot->ind) g_array_free((plot->ind), FALSE);
- if (plot->sizes) g_array_free((plot->sizes), FALSE);
}
static void gtk_plot_linear_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GtkPlotLinearPrivate *priv;
-
- priv=GTK_PLOT_LINEAR_GET_PRIVATE(object);
switch (prop_id)
{
case PROP_BXN:
{
- priv->bounds.xmin=g_value_get_double(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.xmin=g_value_get_double(value);
break;
}
case PROP_BXX:
{
- priv->bounds.xmax=g_value_get_double(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.xmax=g_value_get_double(value);
break;
}
case PROP_BYN:
{
- priv->bounds.ymin=g_value_get_double(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.ymin=g_value_get_double(value);
break;
}
case PROP_BYX:
{
- priv->bounds.ymax=g_value_get_double(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.ymax=g_value_get_double(value);
break;
}
case PROP_XTJ:
{
- priv->ticks.xj=g_value_get_uint(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.xj=g_value_get_uint(value);
break;
}
case PROP_YTJ:
{
- priv->ticks.yj=g_value_get_uint(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.yj=g_value_get_uint(value);
break;
}
case PROP_XTN:
{
- priv->ticks.xn=g_value_get_uint(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.xn=g_value_get_uint(value);
break;
}
case PROP_YTN:
{
- priv->ticks.yn=g_value_get_uint(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.yn=g_value_get_uint(value);
break;
}
case PROP_FA:
{
- priv->flaga=g_value_get_uint(value);
+ GTK_PLOT_LINEAR_GET_PRIVATE(object)->flaga=g_value_get_uint(value);
break;
}
default:
@@ -4258,54 +4249,51 @@ static void gtk_plot_linear_set_property(GObject *object, guint prop_id, const G
static void gtk_plot_linear_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GtkPlotLinearPrivate *priv;
-
- priv=GTK_PLOT_LINEAR_GET_PRIVATE(object);
switch (prop_id)
{
case PROP_BXN:
{
- g_value_set_double(value, priv->bounds.xmin);
+ g_value_set_double(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.xmin);
break;
}
case PROP_BXX:
{
- g_value_set_double(value, priv->bounds.xmax);
+ g_value_set_double(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.xmax);
break;
}
case PROP_BYN:
{
- g_value_set_double(value, priv->bounds.ymin);
+ g_value_set_double(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.ymin);
break;
}
case PROP_BYX:
{
- g_value_set_double(value, priv->bounds.ymax);
+ g_value_set_double(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->bounds.ymax);
break;
}
case PROP_XTJ:
{
- g_value_set_uint(value, priv->ticks.xj);
+ g_value_set_uint(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.xj);
break;
}
case PROP_YTJ:
{
- g_value_set_uint(value, priv->ticks.yj);
+ g_value_set_uint(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.yj);
break;
}
case PROP_XTN:
{
- g_value_set_uint(value, priv->ticks.xn);
+ g_value_set_uint(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.xn);
break;
}
case PROP_YTN:
{
- g_value_set_uint(value, priv->ticks.yn);
+ g_value_set_uint(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->ticks.yn);
break;
}
case PROP_FA:
{
- g_value_set_uint(value, priv->flaga);
+ g_value_set_uint(value, GTK_PLOT_LINEAR_GET_PRIVATE(object)->flaga);
break;
}
default:
@@ -4368,7 +4356,7 @@ static void gtk_plot_linear_init(GtkPlotLinear *plot)
{(priv->range.xj)=0; (priv->range.yj)=0; (priv->range.xn)=1; (priv->range.yn)=1;}
{(plot->xdp)=2; (plot->ydp)=2;}
{(priv->flaga)=0; (priv->flagr)=0;}
- {(plot->xdata)=NULL; (plot->ydata)=NULL; (plot->ind)=NULL; (plot->sizes)=NULL;}
+ {(plot->xdata)=NULL; (plot->ydata)=NULL;}
{(plot->xlab)=g_strdup("Domain"); (plot->ylab)=g_strdup("Amplitude");}
{(plot->flagd)=GTK_PLOT_LINEAR_DISP_LIN; (plot->ptsize)=5; (plot->linew)=2;}
(plot->zmode)=(GTK_PLOT_LINEAR_ZOOM_VRT|GTK_PLOT_LINEAR_ZOOM_HZT);
View
@@ -53,7 +53,6 @@
{
GtkPlot parent;
GArray *xdata, *ydata; /* x and y data sets */
- GArray *ind, *sizes; /* indices of first element and number of elements for each trace */
gchar *xlab, *ylab; /* labels for the x and y axes */
guint ptsize, linew; /* radii of the points and line width of the plot line */
guint xdp, ydp; /* number of decimal points for axes */
Oops, something went wrong.

0 comments on commit 0e02b99

Please sign in to comment.