Skip to content
Browse files

gplot directory reafy for fourier analysis

  • Loading branch information...
1 parent 1c1f044 commit 20b189787374e5e134ed3184f486ebc3c664b3ba @marc-lorber committed Dec 31, 2011
View
6 src/gplot/Makefile.am
@@ -1,4 +1,7 @@
oreganodir = $(datadir)/oregano
+
+CFLAGS += -Wall -DG_DISABLE_DEPRECATED
+
INCLUDES = \
$(OREGANO_CFLAGS)
@@ -7,8 +10,7 @@ libgplot_a_SOURCES = \
gplot.c \
gplotfunction.c \
gplotfunction.h \
+ gplot-internal.h \
gplot.h \
gplotlines.c \
gplotlines.h
-
-libgplot_a_LIBADD = libgplot.a
View
67 src/gplot/gplot-internal.h
@@ -0,0 +1,67 @@
+/*
+ * gplot-internal.h
+ *
+ * Authors:
+ * Ricardo Markiewicz <rmarkie@fi.uba.ar>
+ *
+ * Copyright (C) 1999-2001 Richard Hult
+ * Copyright (C) 2003,2004 Ricardo Markiewicz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _GPLOT_INTERNAL_H_
+#define _GPLOT_INTERNAL_H_
+
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include "gplot.h"
+#include "gplotfunction.h"
+
+// Internal definitions associated to gplot.h
+
+typedef struct _GPlotClass GPlotClass;
+typedef struct _GPlotPriv GPlotPriv;
+
+
+struct _GPlot {
+ GtkLayout parent;
+
+ GPlotPriv *priv;
+};
+struct _GPlotClass {
+ GtkLayoutClass parent_class;
+};
+
+
+// Internal definitions associated to gplotfunction.h
+
+#define TYPE_GPLOT_FUNCTION (g_plot_function_get_type())
+#define GPLOT_FUNCTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT_FUNCTION, GPlotFunctionClass)
+#define GPLOT_FUNCTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TYPE_GPLOT_FUNCTION, GPlotFunctionClass))
+
+typedef struct _GPlotFunctionClass GPlotFunctionClass;
+
+struct _GPlotFunctionClass {
+ GTypeInterface parent;
+
+ void (*draw)(GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
+ void (*get_bbox)(GPlotFunction *, GPlotFunctionBBox *);
+};
+
+#endif
View
5 src/gplot/gplot.c
@@ -24,6 +24,7 @@
*/
#include <math.h>
+#include "gplot-internal.h"
#include "gplot.h"
#define BORDER_SIZE 50
@@ -594,7 +595,7 @@ g_plot_button_press_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
g_return_val_if_fail (IS_GPLOT (p), TRUE);
if (e->type == GDK_2BUTTON_PRESS) {
- /* TODO : Chekck function below cursor and open a property dialog :) */
+ /* TODO : Check function below cursor and open a property dialog :) */
} else {
switch (p->priv->zoom_mode) {
case GPLOT_ZOOM_INOUT:
@@ -623,7 +624,7 @@ g_plot_button_press_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
static gboolean
g_plot_button_release_cb (GtkWidget *w, GdkEventButton *e, GPlot *p)
{
- gdouble zoom;
+ gdouble zoom = 0.0;
g_return_val_if_fail (IS_GPLOT (p), TRUE);
View
18 src/gplot/gplot.h
@@ -30,32 +30,18 @@
#include <gtk/gtk.h>
#include <glib.h>
-#include "gplotfunction.h"
-
-#define TYPE_GPLOT (g_plot_get_type())
#define GPLOT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT, GPlot)
-#define GPLOT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT, GPlotClass)
#define IS_GPLOT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT)
+#define TYPE_GPLOT (g_plot_get_type())
typedef struct _GPlot GPlot;
-typedef struct _GPlotClass GPlotClass;
-typedef struct _GPlotPriv GPlotPriv;
+typedef struct _GPlotFunction {} GPlotFunction;
enum {
GPLOT_ZOOM_INOUT,
GPLOT_ZOOM_REGION
};
-struct _GPlot {
- GtkLayout parent;
-
- GPlotPriv *priv;
-};
-
-struct _GPlotClass {
- GtkLayoutClass parent_class;
-};
-
GType g_plot_get_type ();
GtkWidget* g_plot_new ();
void g_plot_clear (GPlot *);
View
1 src/gplot/gplotfunction.c
@@ -23,6 +23,7 @@
* Boston, MA 02111-1307, USA.
*/
+#include "gplot-internal.h"
#include "gplotfunction.h"
View
25 src/gplot/gplotfunction.h
@@ -26,19 +26,10 @@
#ifndef _GPLOT_FUNCTION_H_
#define _GPLOT_FUNCTION_H_
-#include <gdk/gdk.h>
#include <gtk/gtk.h>
-#include <glib.h>
-#define TYPE_GPLOT_FUNCTION (g_plot_function_get_type())
#define GPLOT_FUNCTION(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT_FUNCTION, GPlotFunction)
-#define GPLOT_FUNCTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT_FUNCTION, GPlotFunctionClass)
#define IS_GPLOT_FUNCTION (obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT_FUNCTION)
-#define GPLOT_FUNCTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TYPE_GPLOT_FUNCTION, GPlotFunctionClass))
-/*
-#define MAX(a,b) ((a)>(b)?(a):(b))
-#define MIN(a,b) ((a)<(b)?(a):(b))
-*/
typedef struct _GPlotFunctionBBox {
gdouble xmin;
@@ -47,23 +38,9 @@ typedef struct _GPlotFunctionBBox {
gdouble ymax;
} GPlotFunctionBBox;
-typedef struct _GPlotFunction {} GPlotFunction;
-typedef struct _GPlotFunctionClass GPlotFunctionClass;
-
-struct _GPlotFunctionClass {
- GTypeInterface parent;
-
- void (*draw)(GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
- void (*get_bbox)(GPlotFunction *, GPlotFunctionBBox *);
-};
-
-
-GType g_plot_function_get_type ();
void g_plot_function_draw (GPlotFunction *, cairo_t *, GPlotFunctionBBox *);
void g_plot_function_get_bbox (GPlotFunction *, GPlotFunctionBBox *);
void g_plot_function_set_visible (GPlotFunction *, gboolean);
gboolean g_plot_function_get_visible (GPlotFunction *);
-#endif
-
-
+#endif
View
115 src/gplot/gplotlines.c
@@ -23,8 +23,25 @@
* Boston, MA 02111-1307, USA.
*/
-#include "gplotlines.h"
#include <string.h>
+#include "gplot-internal.h"
+#include "gplotlines.h"
+
+typedef struct _GPlotLines GPlotLines;
+typedef struct _GPlotLinesPriv GPlotLinesPriv;
+typedef struct _GPlotLinesClass GPlotLinesClass;
+
+struct _GPlotLines {
+ GObject parent;
+
+ GPlotLinesPriv *priv;
+};
+
+struct _GPlotLinesClass {
+ GObjectClass parent;
+};
+
+GType g_plot_function_get_type ();
static void g_plot_lines_class_init (GPlotLinesClass* class);
static void g_plot_lines_init (GPlotLines* plot);
@@ -42,6 +59,8 @@ enum {
ARG_COLOR,
ARG_COLOR_GDKCOLOR,
ARG_VISIBLE,
+ ARG_GRAPH_TYPE,
+ ARG_SHIFT
};
struct _GPlotLinesPriv {
@@ -58,12 +77,37 @@ struct _GPlotLinesPriv {
/** Line Color */
gchar *color_string;
GdkColor color;
+
+ /** Graphic type */
+ GraphicType graphic_type;
+
+ /** Shift for pulse drawings */
+ gdouble shift;
};
+#define TYPE_GPLOT_LINES (g_plot_lines_get_type())
+#define TYPE_GPLOT_GRAPHIC_TYPE (g_plot_lines_graphic_get_type())
+#define NG_DEBUG(s) if (0) g_print ("%s\n", s)
+
G_DEFINE_TYPE_WITH_CODE (GPlotLines, g_plot_lines, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (TYPE_GPLOT_FUNCTION,
g_plot_lines_function_init));
+GType
+g_plot_lines_graphic_get_type(void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { FUNCTIONAL_CURVE, "FUNCTIONAL_CURVE", "funct-curve" },
+ { FREQUENCY_PULSE, "FREQUENCY_PULSE", "freq-pulse" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("GraphicType", values);
+ }
+ return etype;
+}
+
static void
g_plot_lines_function_init (GPlotFunctionClass *iface)
{
@@ -126,6 +170,19 @@ g_plot_lines_class_init (GPlotLinesClass* class)
ARG_COLOR_GDKCOLOR,
g_param_spec_pointer ("color-rgb", "GPlotLines::color-rgb",
"the GdkColor of the line", G_PARAM_READWRITE));
+
+ g_object_class_install_property(
+ object_class,
+ ARG_GRAPH_TYPE,
+ g_param_spec_enum ("graph-type", "GPlotLines::graph-type",
+ "the type of graphic", TYPE_GPLOT_GRAPHIC_TYPE,
+ FUNCTIONAL_CURVE, G_PARAM_READWRITE));
+
+ g_object_class_install_property(
+ object_class,
+ ARG_SHIFT,
+ g_param_spec_double ("shift", "GPlotLines::shift",
+ "the shift for multiple pulses", 0.0, 500.0, 50.0, G_PARAM_READWRITE));
}
static void
@@ -161,9 +218,11 @@ g_plot_lines_set_property(GObject *object, guint prop_id, const GValue *value,
plot->priv->color_string = g_strdup (g_value_get_string (value));
gdk_color_parse (plot->priv->color_string, &plot->priv->color);
break;
- case ARG_COLOR_GDKCOLOR:
- //s = g_value_get_string (value)
- //gdk_color_parse (s, &plot->priv->color);
+ case ARG_GRAPH_TYPE:
+ plot->priv->graphic_type = g_value_get_enum (value);
+ break;
+ case ARG_SHIFT:
+ plot->priv->shift = g_value_get_double (value);
break;
default:
break;
@@ -187,6 +246,12 @@ g_plot_lines_get_property(GObject *object, guint prop_id, GValue *value,
case ARG_COLOR:
g_value_set_string (value, plot->priv->color_string);
break;
+ case ARG_GRAPH_TYPE:
+ g_value_set_enum (value, plot->priv->graphic_type);
+ break;
+ case ARG_SHIFT:
+ g_value_set_double (value, plot->priv->shift);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (plot, prop_id, spec);
}
@@ -239,13 +304,16 @@ g_plot_lines_get_bbox (GPlotFunction *f, GPlotFunctionBBox *bbox)
(*bbox) = plot->priv->bbox;
}
+
+// This procedure is in charge to link points with ligne.
+// Modified to only draw spectral ray for Fourier analysis.
static void
g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
{
gboolean first_point = TRUE;
guint point;
- gdouble *x;
- gdouble *y;
+ gdouble *x, x1;
+ gdouble *y, y1;
guint points;
GPlotLines *plot;
@@ -259,24 +327,34 @@ g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
x = plot->priv->x;
y = plot->priv->y;
- for (point = 1; point < points; point++) {
- if ((x[point] >= bbox->xmin) && (x[point] <= bbox->xmax) &&
- (y[point] >= bbox->ymin) && (y[point] <= bbox->ymax)) {
+ if (plot->priv->graphic_type == FUNCTIONAL_CURVE) {
+ for (point = 1; point < points; point++) {
+ if ((x[point] >= bbox->xmin) && (x[point] <= bbox->xmax) &&
+ (y[point] >= bbox->ymin) && (y[point] <= bbox->ymax)) {
- if (first_point) {
- cairo_move_to (cr, x[point-1], y[point-1]);
- first_point = FALSE;
- }
+ if (first_point) {
+ cairo_move_to (cr, x[point-1], y[point-1]);
+ first_point = FALSE;
+ }
- cairo_line_to (cr, x[point], y[point]);
- } else {
- if (!first_point) {
cairo_line_to (cr, x[point], y[point]);
- first_point = TRUE;
+ } else {
+ if (!first_point) {
+ cairo_line_to (cr, x[point], y[point]);
+ first_point = TRUE;
+ }
}
}
+ } else {
+ for (point = 1; point < points; point++) {
+ x1 = x[point-1]+plot->priv->shift;
+ y1 = 0;
+ NG_DEBUG (g_strdup_printf ("gplotlines: x= %lf\ty= %lf\n", x1, y1));
+ cairo_line_to (cr, x1, y1);
+ cairo_move_to (cr, x[point]+ plot->priv->shift, y[point]);
+ }
+
}
-
if (point < points) {
cairo_line_to (cr, x[point], y[point]);
}
@@ -291,4 +369,3 @@ g_plot_lines_draw (GPlotFunction *f, cairo_t *cr, GPlotFunctionBBox *bbox)
cairo_stroke (cr);
cairo_restore (cr);
}
-
View
23 src/gplot/gplotlines.h
@@ -28,26 +28,15 @@
#include "gplotfunction.h"
-#define TYPE_GPLOT_LINES (g_plot_lines_get_type())
-#define GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT_LINES, GPlotLines)
-#define GPLOT_LINES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, TYPE_GPLOT_LINES, GPlotLinesClass)
-#define IS_GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT_LINES)
-typedef struct _GPlotLines GPlotLines;
-typedef struct _GPlotLinesPriv GPlotLinesPriv;
-typedef struct _GPlotLinesClass GPlotLinesClass;
+typedef enum {
+ FUNCTIONAL_CURVE=0,
+ FREQUENCY_PULSE
+} GraphicType;
-struct _GPlotLines {
- GObject parent;
+#define GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, TYPE_GPLOT_LINES, GPlotLines)
+#define IS_GPLOT_LINES(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, TYPE_GPLOT_LINES)
- GPlotLinesPriv *priv;
-};
-
-struct _GPlotLinesClass {
- GObjectClass parent;
-};
-
-GType g_plot_lines_get_type ();
GPlotFunction* g_plot_lines_new (gdouble *x, gdouble *y, guint points);
#endif

0 comments on commit 20b1897

Please sign in to comment.
Something went wrong with that request. Please try again.