box3d.cpp revision 2b42b0a4b01b9bb69bc36783220c75407d13d940
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * SVG <box3d> implementation
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Lauris Kaplinski <lauris@kaplinski.com>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * bulia byak <buliabyak@users.sf.net>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Maximilian Albert <Anhalter42@gmx.de>
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Copyright (C) 2007 Authors
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Copyright (C) 1999-2002 Lauris Kaplinski
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Copyright (C) 2000-2001 Ximian, Inc.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Released under GNU GPL, read the file 'COPYING' for more information
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_class_init(SP3DBoxClass *klass);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_set(SPObject *object, unsigned int key, const gchar *value);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_update(SPObject *object, SPCtx *ctx, guint flags);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan//static void sp_3dbox_set_shape(SPShape *shape);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan//static void sp_3dbox_set_shape(SP3DBox *box3d);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_update_corner_with_value_from_svg (SPObject *object, guint corner_id, const gchar *value);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic void sp_3dbox_update_perspective (Box3D::Perspective3D *persp, const gchar *value);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic gchar * sp_3dbox_get_corner_coords_string (SP3DBox *box, guint id);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic std::pair<gdouble, gdouble> sp_3dbox_get_coord_pair_from_string (const gchar *);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Loganstatic gchar * sp_3dbox_get_perspective_string (SP3DBox *box);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan type = g_type_register_static(SP_TYPE_GROUP, "SP3DBox", &info, (GTypeFlags) 0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan SPObjectClass *sp_object_class = (SPObjectClass *) klass;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan parent_class = (SPGroupClass *) g_type_class_ref(SP_TYPE_GROUP);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (int i = 0; i < 8; ++i) box->corners[i] = NR::Point(0,0);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan for (int i = 0; i < 6; ++i) box->faces[i] = NULL;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logansp_3dbox_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan ((SPObjectClass *) (parent_class))->build(object, document, repr);
delete persp;
// FIXME: If the paths of the box's faces do not correspond to the svg representation of the perspective
// Maybe it would be better to simply destroy and rebuild them in sp_3dbox_link_to_existing_paths().
switch (key) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
return repr;
return repr;
static gchar *
if (!use_previous_corners) {
box3d->faces[0]->set_corners (box3d->corners[0], box3d->corners[4], box3d->corners[6], box3d->corners[2]);
box3d->faces[1]->set_corners (box3d->corners[1], box3d->corners[5], box3d->corners[7], box3d->corners[3]);
box3d->faces[2]->set_corners (box3d->corners[0], box3d->corners[1], box3d->corners[5], box3d->corners[4]);
box3d->faces[3]->set_corners (box3d->corners[2], box3d->corners[3], box3d->corners[7], box3d->corners[6]);
box3d->faces[5]->set_corners (box3d->corners[4], box3d->corners[5], box3d->corners[7], box3d->corners[6]);
box3d->faces[4]->set_corners (box3d->corners[0], box3d->corners[1], box3d->corners[3], box3d->corners[2]);
void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const A, NR::Point const B, NR::Point const C)
* In some situations (e.g., after cloning boxes, undo & redo, or reading boxes from a file) there are
* paths already present in the document which correspond to the faces of newly created boxes, but their
++face_id;
//g_warning ("SVG representation of 3D boxes should contain exactly 6 paths (degenerate boxes are not yet supported).\n");
static gchar *
static gchar *
gchar *
// FIXME: We should move this code to perspective3d.cpp, but this yields compiler errors. Why?
switch (axis) {
case Box3D::X:
case Box3D::Y:
case Box3D::Z:
sp_3dbox_get_corner_id_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos)
// clear the axis bit and switch to the appropriate corner along axis, depending on the value of front_bits
return result;
sp_3dbox_get_corner_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos)
persp->set_vanishing_point (Box3D::Z, g_ascii_strtod (vps[10], NULL), g_ascii_strtod (vps[11], NULL),