[goffice] Add a view class to Gog3DBox to support data that are view dependent.
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Add a view class to Gog3DBox to support data that are view dependent.
- Date: Wed, 7 May 2014 18:20:56 +0000 (UTC)
commit aa7fa520339336cc739a7e93f14f71f0108cdd5b
Author: Jean Brefort <jean brefort normalesup org>
Date: Wed May 7 20:20:35 2014 +0200
Add a view class to Gog3DBox to support data that are view dependent.
ChangeLog | 15 ++++++++++
NEWS | 1 +
goffice/graph/gog-3d-box.c | 9 ++++++
goffice/graph/gog-3d-box.h | 20 ++++++++++--
goffice/graph/gog-axis-line.c | 6 ++--
goffice/graph/gog-chart-map-3d.c | 37 ++++++++++++++----------
goffice/graph/gog-chart-map-3d.h | 2 +-
goffice/graph/gog-chart.c | 54 ++++++++++++++++++-----------------
goffice/graph/gog-grid-line.c | 6 ++--
goffice/graph/gog-grid.c | 2 +-
plugins/plot_surface/gog-surface.c | 2 +-
11 files changed, 100 insertions(+), 54 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7322390..cb4157c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2014-05-07 Jean Brefort <jean brefort normalesup org>
+ * goffice/graph/gog-3d-box.c (gog_3d_box_class_init): add a view class for
+ the 3d box to support data that are view dependent.
+ * goffice/graph/gog-3d-box.h: ditto.
+ * goffice/graph/gog-axis-line.c (xyz_process): change gog_chart_map_3d_new()
+ signature to suppor the new view class.
+ * goffice/graph/gog-chart-map-3d.c (xyz_map_3D_to_view),
+ (gog_chart_map_3d_new), (gog_chart_map_3d_free): ditto.
+ * goffice/graph/gog-chart-map-3d.h: ditto.
+ * goffice/graph/gog-chart.c (gog_chart_view_3d_process): ditto.
+ * goffice/graph/gog-grid-line.c (gog_grid_line_xyz_render): ditto.
+ * goffice/graph/gog-grid.c (gog_grid_view_xyz_render): ditto.
+ * plugins/plot_surface/gog-surface.c (gog_surface_view_render): ditto.
+
+2014-05-07 Jean Brefort <jean brefort normalesup org>
+
* goffice/graph/gog-3d-box.c (cb_g3d_update),
(gog_3d_box_populate_editor): fixed criticals.
diff --git a/NEWS b/NEWS
index 579d805..a629cfe 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ goffice 0.10.16:
Jean
* Don't use GDK_THREADS_*. [728793]
* Fixed Gog3DBox properties editor.
+ * Add a view class to Gog3DBox to support data that are view dependent.
Morten:
* Clean out old #ifdef mess.
diff --git a/goffice/graph/gog-3d-box.c b/goffice/graph/gog-3d-box.c
index 8620c0a..73940fe 100644
--- a/goffice/graph/gog-3d-box.c
+++ b/goffice/graph/gog-3d-box.c
@@ -312,6 +312,7 @@ gog_3d_box_class_init (Gog3DBoxClass *klass)
#ifdef GOFFICE_WITH_GTK
gog_klass->populate_editor = gog_3d_box_populate_editor;
#endif
+ gog_klass->view_type = gog_3d_box_view_get_type ();
}
static void
@@ -324,6 +325,14 @@ gog_3d_box_init (Gog3DBox *box)
go_matrix3x3_from_euler (&box->mat, box->psi, box->theta, box->phi);
}
+typedef GogViewClass Gog3DBoxViewClass;
+
GSF_CLASS (Gog3DBox, gog_3d_box,
gog_3d_box_class_init, gog_3d_box_init,
GOG_TYPE_OBJECT)
+
+/* Gog3DViewClass*/
+
+GSF_CLASS (Gog3DBoxView, gog_3d_box_view,
+ NULL, NULL,
+ GOG_TYPE_VIEW)
diff --git a/goffice/graph/gog-3d-box.h b/goffice/graph/gog-3d-box.h
index 994d5c7..34f965e 100644
--- a/goffice/graph/gog-3d-box.h
+++ b/goffice/graph/gog-3d-box.h
@@ -30,10 +30,6 @@ struct _Gog3DBox {
GogObject base;
double fov, psi, theta, phi; /* field of view and orientation */
- double dx, dy, dz; /* box size */
- double r; /* distance from view point to the center of the box */
- double ratio; /* ratio to use to be certain that everything fits
- in the view */
GOMatrix3x3 mat; /* the matrix based on psi, theta, and phi */
};
@@ -43,6 +39,22 @@ struct _Gog3DBox {
GType gog_3d_box_get_type (void);
+struct _Gog3DBoxView {
+ GogView base;
+
+ double dx, dy, dz; /* box size */
+ double r; /* distance from view point to the center of the box */
+ double ratio; /* ratio to use to be certain that everything fits
+ in the view */
+};
+typedef struct _Gog3DBoxView Gog3DBoxView;
+
+#define GOG_3D_BOX_VIEW_TYPE (gog_3d_box_view_get_type ())
+#define GOG_3D_BOX_VIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_3D_BOX_VIEW_TYPE, Gog3DBoxView))
+#define GOG_IS_3D_BOX_VIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_3D_BOX_VIEW_TYPE))
+
+GType gog_3d_box_view_get_type (void);
+
G_END_DECLS
#endif /* GOG_3D_BOX_H */
diff --git a/goffice/graph/gog-axis-line.c b/goffice/graph/gog-axis-line.c
index 1a92269..e211738 100644
--- a/goffice/graph/gog-axis-line.c
+++ b/goffice/graph/gog-axis-line.c
@@ -1838,7 +1838,7 @@ xyz_process (GogAxisBaseAction action, GogView *view, GogViewPadding *padding,
axes = gog_chart_get_axes (axis_base->chart, GOG_AXIS_Z);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (axis_base->chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis_base->axis, axis1, axis2);
} else if (axis_type == GOG_AXIS_Y) {
axes = gog_chart_get_axes (axis_base->chart, GOG_AXIS_Z);
@@ -1847,7 +1847,7 @@ xyz_process (GogAxisBaseAction action, GogView *view, GogViewPadding *padding,
axes = gog_chart_get_axes (axis_base->chart, GOG_AXIS_X);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (axis_base->chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis2, axis_base->axis, axis1);
} else {
axes = gog_chart_get_axes (axis_base->chart, GOG_AXIS_X);
@@ -1856,7 +1856,7 @@ xyz_process (GogAxisBaseAction action, GogView *view, GogViewPadding *padding,
axes = gog_chart_get_axes (axis_base->chart, GOG_AXIS_Y);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (axis_base->chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis1, axis2, axis_base->axis);
}
diff --git a/goffice/graph/gog-chart-map-3d.c b/goffice/graph/gog-chart-map-3d.c
index c5ae36b..eb90645 100644
--- a/goffice/graph/gog-chart-map-3d.c
+++ b/goffice/graph/gog-chart-map-3d.c
@@ -23,7 +23,7 @@
#include <goffice/goffice.h>
struct _GogChartMap3D {
- GogChart *chart;
+ Gog3DBoxView *view;
GogViewAllocation area;
gpointer data;
GogAxisMap *axis_map[3];
@@ -43,17 +43,17 @@ null_map_3D (GogChartMap3D *map, double x, double y, double z, double *u, double
static void
xyz_map_3D_to_view (GogChartMap3D *map, double x, double y, double z, double *u, double *v, double *w)
{
- Gog3DBox *box = GOG_3D_BOX (gog_object_get_child_by_name (GOG_OBJECT (map->chart), "3D-Box"));
+ Gog3DBox *box = GOG_3D_BOX (gog_view_get_model (GOG_VIEW (map->view)));
x = gog_axis_map_to_view (map->axis_map[0], x);
y = gog_axis_map_to_view (map->axis_map[1], y);
z = gog_axis_map_to_view (map->axis_map[2], z);
go_matrix3x3_transform (&box->mat, x, y, z, &x, &y, &z);
if (box->fov > 0.) {
- x /= (1. - y / box->r) * box->ratio;
- z /= (1. - y / box->r) * box->ratio;
+ x /= (1. - y / map->view->r) * map->view->ratio;
+ z /= (1. - y / map->view->r) * map->view->ratio;
} else {
- x /= box->ratio;
- z /= box->ratio;
+ x /= map->view->ratio;
+ z /= map->view->ratio;
}
if (u)
*u = map->area.x + map->area.w / 2. * (1. + x / map->area.w);
@@ -65,7 +65,7 @@ xyz_map_3D_to_view (GogChartMap3D *map, double x, double y, double z, double *u,
/**
* gog_chart_map_3d_new:
- * @chart: a #GogChart with 3D support
+ * @view: a #GogView for a chart with 3D support or one of its children
* @area: area allocated to chart
* @axis0: 1st dimension axis
* @axis1: 2nd dimension axis
@@ -78,31 +78,38 @@ xyz_map_3D_to_view (GogChartMap3D *map, double x, double y, double z, double *u,
**/
GogChartMap3D*
-gog_chart_map_3d_new (GogChart *chart, GogViewAllocation const *area,
+gog_chart_map_3d_new (GogView *view, GogViewAllocation const *area,
GogAxis *axis0, GogAxis *axis1, GogAxis *axis2)
{
GogChartMap3D *map;
GogAxisSet axis_set;
Gog3DBox *box;
+ GogChart *chart;
- g_return_val_if_fail (GOG_IS_CHART (chart), NULL);
+ g_return_val_if_fail (GOG_IS_VIEW (view), NULL);
+
+ while (view && !GOG_IS_CHART (view->model))
+ view = view->parent;
+
+ g_return_val_if_fail (view, NULL);
+
+ chart = GOG_CHART (view->model);
map = g_new (GogChartMap3D, 1);
- g_object_ref (chart);
- map->chart = chart;
map->area = *area;
map->data = NULL;
map->is_valid = FALSE;
map->ref_count = 1;
box = GOG_3D_BOX (gog_object_get_child_by_name (GOG_OBJECT (chart), "3D-Box"));
+ map->view = GOG_3D_BOX_VIEW (g_object_ref (gog_view_find_child_view (view, (GogObject *) box)));
axis_set = gog_chart_get_axis_set (chart);
switch (axis_set & GOG_AXIS_SET_FUNDAMENTAL) {
case GOG_AXIS_SET_XYZ: {
- map->axis_map[0] = gog_axis_map_new (axis0, -box->dx, 2 * box->dx);
- map->axis_map[1] = gog_axis_map_new (axis1, -box->dy, 2 * box->dy);
- map->axis_map[2] = gog_axis_map_new (axis2, -box->dz, 2 * box->dz);
+ map->axis_map[0] = gog_axis_map_new (axis0, -map->view->dx, 2 * map->view->dx);
+ map->axis_map[1] = gog_axis_map_new (axis1, -map->view->dy, 2 * map->view->dy);
+ map->axis_map[2] = gog_axis_map_new (axis2, -map->view->dz, 2 * map->view->dz);
map->data = NULL;
map->map_3D_to_view = xyz_map_3D_to_view;
@@ -199,7 +206,7 @@ gog_chart_map_3d_free (GogChartMap3D *map)
gog_axis_map_free (map->axis_map[i]);
g_free (map->data);
- g_object_unref (map->chart);
+ g_object_unref (map->view);
g_free (map);
}
diff --git a/goffice/graph/gog-chart-map-3d.h b/goffice/graph/gog-chart-map-3d.h
index 78c13c7..055984b 100644
--- a/goffice/graph/gog-chart-map-3d.h
+++ b/goffice/graph/gog-chart-map-3d.h
@@ -29,7 +29,7 @@ G_BEGIN_DECLS
typedef struct _GogChartMap3D GogChartMap3D;
GType gog_chart_map_3d_get_type (void);
-GogChartMap3D *gog_chart_map_3d_new (GogChart *chart, GogViewAllocation const *area,
+GogChartMap3D *gog_chart_map_3d_new (GogView *view, GogViewAllocation const *area,
GogAxis *axis0, GogAxis *axis1, GogAxis *axis2);
void gog_chart_map_3d_to_view (GogChartMap3D *map, double x, double y, double z, double *u,
double *v, double *w);
GogAxisMap *gog_chart_map_3d_get_axis_map (GogChartMap3D *map, unsigned int index);
diff --git a/goffice/graph/gog-chart.c b/goffice/graph/gog-chart.c
index 3abb5f0..6d69c37 100644
--- a/goffice/graph/gog-chart.c
+++ b/goffice/graph/gog-chart.c
@@ -1146,6 +1146,7 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
double xmin, xmax, ymin, ymax, zmin, zmax;
double o[3], x[3], y[3], z[3], tg, d;
Gog3DBox *box;
+ Gog3DBoxView *box_view;
GogChart *chart = GOG_CHART (gog_view_get_model (view));
GogObject *obj = gog_object_get_child_by_name (GOG_OBJECT (chart), "3D-Box");
GSList *ptr;
@@ -1157,6 +1158,7 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
gog_object_add_by_name (GOG_OBJECT (chart), "3D-Box", obj);
}
box = GOG_3D_BOX (obj);
+ box_view = GOG_3D_BOX_VIEW (gog_view_find_child_view (view, obj));
/* Only use the first of the axes. */
axes = gog_chart_get_axes (chart, GOG_AXIS_X);
@@ -1173,20 +1175,20 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
gog_axis_get_bounds (axisZ, &zmin, &zmax);
/* define the 3d box */
/* FIXME: take axes into account */
- box->dz = tmp.h;
+ box_view->dz = tmp.h;
if (ymax - ymin > xmax - xmin) {
- box->dy = tmp.w;
- box->dx = (xmax - xmin) / (ymax - ymin) * tmp.w;
+ box_view->dy = tmp.w;
+ box_view->dx = (xmax - xmin) / (ymax - ymin) * tmp.w;
} else {
- box->dx = tmp.w;
- box->dy = (ymax - ymin) / (xmax - xmin) * tmp.w;
+ box_view->dx = tmp.w;
+ box_view->dy = (ymax - ymin) / (xmax - xmin) * tmp.w;
}
/* now compute the position of each vertex, ignoring the fov */
- go_matrix3x3_transform (&box->mat, -box->dx, -box->dy, -box->dz, o, o + 1, o + 2);
- go_matrix3x3_transform (&box->mat, box->dx, -box->dy, -box->dz, x, x + 1, x + 2);
- go_matrix3x3_transform (&box->mat, -box->dx, box->dy, -box->dz, y, y + 1, y + 2);
- go_matrix3x3_transform (&box->mat, -box->dx, -box->dy, box->dz, z, z + 1, z + 2);
+ go_matrix3x3_transform (&box->mat, -box_view->dx, -box_view->dy, -box_view->dz, o, o + 1, o + 2);
+ go_matrix3x3_transform (&box->mat, box_view->dx, -box_view->dy, -box_view->dz, x, x + 1, x + 2);
+ go_matrix3x3_transform (&box->mat, -box_view->dx, box_view->dy, -box_view->dz, y, y + 1, y + 2);
+ go_matrix3x3_transform (&box->mat, -box_view->dx, -box_view->dy, box_view->dz, z, z + 1, z + 2);
/* for each diagonal, we need to take the vertex closer to the view point */
if (o[1] > 0) {
o[0] = -o[0];
@@ -1211,35 +1213,35 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
/* if the fov is positive, calculate the position of the viewpoint */
if (box->fov > 0.) {
tg = tan (box->fov / 2.);
- box->r = -sqrt (o[0] * o[0] + o[2] * o[2]) / tg + o[1];
+ box_view->r = -sqrt (o[0] * o[0] + o[2] * o[2]) / tg + o[1];
d = -sqrt (x[0] * x[0] + x[2] * x[2]) / tg + x[1];
- if (d < box->r)
- box->r = d;
+ if (d < box_view->r)
+ box_view->r = d;
d = -sqrt (y[0] * y[0] + y[2] * y[2]) / tg + y[1];
- if (d < box->r)
- box->r = d;
+ if (d < box_view->r)
+ box_view->r = d;
d = -sqrt (z[0] *z[0] + z[2] * z[2]) / tg + z[1];
- if (d < box->r)
- box->r = d;
+ if (d < box_view->r)
+ box_view->r = d;
/* also calculate the reduction factor we need to make things fit in the bbox */
- xmax = fabs (o[0]) / (1. - o[1] / box->r);
- zmax = fabs (o[2]) / (1. - o[1] / box->r);
- d = fabs (x[0]) / (1. - x[1] / box->r);
+ xmax = fabs (o[0]) / (1. - o[1] / box_view->r);
+ zmax = fabs (o[2]) / (1. - o[1] / box_view->r);
+ d = fabs (x[0]) / (1. - x[1] / box_view->r);
if (d > xmax)
xmax = d;
- d = fabs (x[2]) / (1. - x[1] / box->r);
+ d = fabs (x[2]) / (1. - x[1] / box_view->r);
if (d > zmax)
zmax = d;
- d = fabs (y[0]) / (1. - y[1] / box->r);
+ d = fabs (y[0]) / (1. - y[1] / box_view->r);
if (d > xmax)
xmax = d;
- d = fabs (y[2]) / (1. - y[1] / box->r);
+ d = fabs (y[2]) / (1. - y[1] / box_view->r);
if (d > zmax)
zmax = d;
- d = fabs (z[0]) / (1. - z[1] / box->r);
+ d = fabs (z[0]) / (1. - z[1] / box_view->r);
if (d > xmax)
xmax = d;
- d = fabs (z[2]) / (1. - z[1] / box->r);
+ d = fabs (z[2]) / (1. - z[1] / box_view->r);
if (d > zmax)
zmax = d;
} else {
@@ -1268,7 +1270,7 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
/* use d and tg as x and z ratios, respectively */
d = xmax / tmp.w;
tg = zmax / tmp.h;
- box->ratio = (d > tg)? d: tg;
+ box_view->ratio = (d > tg)? d: tg;
gog_view_padding_request (view, bbox, &padding);
@@ -1287,7 +1289,7 @@ gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox)
/* Recalculating ratio */
d = xmax / bbox->w;
tg = zmax / bbox->h;
- box->ratio = (d > tg)? d: tg;
+ box_view->ratio = (d > tg)? d: tg;
for (ptr = view->children; ptr != NULL ; ptr = ptr->next) {
child = ptr->data;
diff --git a/goffice/graph/gog-grid-line.c b/goffice/graph/gog-grid-line.c
index 0ae3c58..578a9c4 100644
--- a/goffice/graph/gog-grid-line.c
+++ b/goffice/graph/gog-grid-line.c
@@ -273,7 +273,7 @@ gog_grid_line_xyz_render (GogGridLine *grid_line, GogView *view,
axes = gog_chart_get_axes (chart, GOG_AXIS_Z);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis, axis1, axis2);
} else if (axis_type == GOG_AXIS_Y) {
axes = gog_chart_get_axes (chart, GOG_AXIS_Z);
@@ -282,7 +282,7 @@ gog_grid_line_xyz_render (GogGridLine *grid_line, GogView *view,
axes = gog_chart_get_axes (chart, GOG_AXIS_X);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis2, axis, axis1);
} else {
axes = gog_chart_get_axes (chart, GOG_AXIS_X);
@@ -291,7 +291,7 @@ gog_grid_line_xyz_render (GogGridLine *grid_line, GogView *view,
axes = gog_chart_get_axes (chart, GOG_AXIS_Y);
axis2 = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
axis1, axis2, axis);
}
diff --git a/goffice/graph/gog-grid.c b/goffice/graph/gog-grid.c
index fa3a9df..f855cb7 100644
--- a/goffice/graph/gog-grid.c
+++ b/goffice/graph/gog-grid.c
@@ -192,7 +192,7 @@ gog_grid_view_xyz_render (GogGrid *grid, GogView *view,
axes = gog_chart_get_axes (chart, GOG_AXIS_Z);
zaxis = GOG_AXIS (axes->data);
g_slist_free (axes);
- c_map = gog_chart_map_3d_new (chart, plot_area,
+ c_map = gog_chart_map_3d_new (view, plot_area,
xaxis, yaxis, zaxis);
a_map = gog_chart_map_3d_get_axis_map (c_map, 0);
diff --git a/plugins/plot_surface/gog-surface.c b/plugins/plot_surface/gog-surface.c
index 7b6629c..b047e7a 100644
--- a/plugins/plot_surface/gog-surface.c
+++ b/plugins/plot_surface/gog-surface.c
@@ -155,7 +155,7 @@ gog_surface_view_render (GogView *view, GogViewAllocation const *bbox)
else
return;
- chart_map = gog_chart_map_3d_new (chart, area,
+ chart_map = gog_chart_map_3d_new (view, area,
GOG_PLOT (plot)->axis[GOG_AXIS_X],
GOG_PLOT (plot)->axis[GOG_AXIS_Y],
GOG_PLOT (plot)->axis[GOG_AXIS_Z]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]