box3d.cpp revision a320e0fbc2a3815248a5b77eafea91c83c3c3c11
#define __SP_3DBOX_C__
/*
* SVG <box3d> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Maximilian Albert <Anhalter42@gmx.de>
*
* Copyright (C) 2007 Authors
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "attributes.h"
#include "svg/stringstream.h"
#include "box3d.h"
#include "desktop-handles.h"
static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
//static void sp_3dbox_set_shape(SPShape *shape);
//static void sp_3dbox_set_shape(SP3DBox *box3d);
static void sp_3dbox_update_corner_with_value_from_svg (SPObject *object, guint corner_id, const gchar *value);
static SPGroupClass *parent_class;
sp_3dbox_get_type(void)
{
if (!type) {
sizeof(SP3DBoxClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SP3DBox),
16, /* n_preallocs */
NULL, /* value_table */
};
}
return type;
}
static void
{
}
static void
{
}
static void
{
}
/* we initialize the z-orders to zero so that they are updated during dragging */
for (int i = 0; i < 6; ++i) {
}
// we are creating a new box; link it to the current perspective
} else {
// create a new perspective that we can compare with existing ones
Box3D::VanishingPoint (0,0),
Box3D::VanishingPoint (0,0),
document);
// perspective doesn't exist yet
} else {
// link the box to the existing perspective and delete the temporary one
delete persp;
//g_assert (Box3D::get_persp_of_box (box) == comp);
// FIXME: If the paths of the box's faces do not correspond to the svg representation of the perspective
// the box is shown with a "wrong" initial shape that is only corrected after dragging.
// Should we "repair" this by updating the paths at the end of sp_3dbox_build()?
// Maybe it would be better to simply destroy and rebuild them in sp_3dbox_link_to_existing_paths().
}
}
// TODO: We create all faces in the beginning, but only the non-degenerate ones
// should be written to the svg representation later in sp_3dbox_write.
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 2; ++j) {
// FIXME: The following code could theoretically be moved to
// the constructor of Box3DFace (but see the comment there).
}
}
// Check whether the paths of the faces of the box need to be linked to existing paths in the
// document (e.g., after a 'redo' operation or after opening a file) and do so if necessary.
// Store the center (if it already exists) and certain corners for later use during center-dragging
if (cen) {
}
}
static void
{
for (int i = 0; i < 6; ++i) {
}
}
// FIXME: We do not duplicate perspectives if they are the same for several boxes.
// Thus, don't delete the perspective when deleting a box but rather unlink the box from it.
}
}
{
switch (key) {
break;
break;
break;
{
break;
}
default:
}
break;
}
}
static void
{
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
}
/* Invoke parent method */
}
static Inkscape::XML::Node *sp_3dbox_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
{
// FIXME: How to handle other contexts???
return repr;
/* Hook paths to the faces of the box */
for (int i = 0; i < 6; ++i) {
}
}
for (int i = 0; i < 6; ++i) {
}
if (flags & SP_OBJECT_WRITE_EXT) {
/* store center and construction-corners for later use during center-dragging */
if (cen) {
}
}
}
return repr;
}
static gchar *
{
return g_strdup(_("<b>3D Box</b>"));
}
{
}
}
}
}
void
{
if (SP_OBJECT_DOCUMENT (G_OBJECT (box))->get_persp_of_box (box)->get_vanishing_point (axis)->is_finite()) {
}
}
void
{
// FIXME: Why does the following call not automatically update the children
// of box3d (which is an SPGroup, which should do this)?
//SP_OBJECT(box3d)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
/**
SP_OBJECT(box3d->path_face1)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
SP_OBJECT(box3d->path_face2)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
SP_OBJECT(box3d->path_face3)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
SP_OBJECT(box3d->path_face4)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
SP_OBJECT(box3d->path_face5)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
SP_OBJECT(box3d->path_face6)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
***/
}
static void
sp_3dbox_set_shape_from_points (SP3DBox *box, NR::Point const &cornerA, NR::Point const &cornerB, NR::Point const &cornerC)
{
// FIXME: How to handle other contexts???
return;
}
}
void
// FIXME: Note that this is _not_ the virtual set_shape() method inherited from SPShape,
// since SP3DBox is inherited from SPGroup. The following method is "artificially"
// called from sp_3dbox_update().
//sp_3dbox_set_shape(SPShape *shape)
{
return;
if (!use_previous_corners) {
} else {
}
}
void sp_3dbox_recompute_corners (SP3DBox *box, NR::Point const A, NR::Point const B, NR::Point const C)
{
}
inline static double
normalized_angle (double angle) {
}
return angle;
}
static gdouble
{
Box3D::VanishingPoint *vp = SP_OBJECT_DOCUMENT (G_OBJECT (box))->get_persp_of_box (box)->get_vanishing_point (axis);
} else {
}
}
{
//gdouble dir_0y = sp_3dbox_corner_angle_to_VP (box, Box3D::Y, front_corner ^ Box3D::X);
// Still not perfect, but only fails in some rather degenerate cases.
// I suspect that there is a more elegant model, though. :)
} else {
}
} else {
} else {
} else {
}
}
}
/* We only need to look for changes among the topmost three faces because the order
of the other ones is just inverted. */
{
for (int i = 0; i < 6; ++i) {
}
return true;
}
return false;
}
{
// For efficiency reasons, we only set the new z-orders if something really changed
if (sp_3dbox_recompute_z_orders (box)) {
}
}
void
for (int i = 0; i < 6; ++i) {
}
}
/**
* 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
* 'path' members don't link to them yet. The following function corrects this if necessary.
*/
void
// TODO: We should probably destroy the existing paths and recreate them because we don't know
// precisely which path corresponds to which face. Does this make a difference?
// In sp_3dbox_write we write the correct paths anyway, don't we? But we could get into
// trouble at a later stage when we only write single faces for degenerate boxes.
if (face_id > 5) {
g_warning ("SVG representation of 3D boxes must contain 6 paths or less.\n");
break;
}
if (!SP_IS_PATH(face_object)) {
g_warning ("SVG representation of 3D boxes should only contain paths.\n");
continue;
}
// TODO: Currently we don't check whether all paths are being linked to different faces.
// This is no problem with valid SVG files. It may lead to crashes, however,
// in case a file is corrupt (e.g., two or more faces have identical descriptions).
++face_id;
}
if (face_id < 6) {
//g_warning ("SVG representation of 3D boxes should contain exactly 6 paths (degenerate boxes are not yet supported).\n");
// TODO: Check whether it is safe to add the remaining paths to the box and do so in case it is.
// (But we also land here for newly created boxes where we shouldn't add any paths because
// This is done in sp_3dbox_write later on.
}
}
void
{
}
/* set the 'front' corners */
/* set the 'rear' corners */
}
void
{
/* set the four corners of the face containing corners[id] */
}
static void
sp_3dbox_reshape_edge_after_VP_toggling (SP3DBox *box, const guint corner, const Box3D::Axis axis, Box3D::Perspective3D *persp)
{
/* Hmm, perhaps we should simply use one of the corners as the pivot point.
But this way we minimize the amount of reshaping.
On second thought, we need to find a way to ensure that all boxes sharing the same
perspective are updated consistently _as a group_. That is, they should also retain
their relative positions towards each other. */
}
void
{
}
{
}
sp_3dbox_get_midpoint_in_axis_direction (NR::Point const &C, NR::Point const &D, Box3D::Axis axis, Box3D::Perspective3D *persp)
{
}
// TODO: The following function can probably be rewritten in a much more elegant and robust way
// by using projective coordinates for all points and using the cross ratio.
{
// Is all this sufficiently precise also for degenerate cases?
} else {
}
}
static gchar *
{
}
{
// We might as well rely on g_ascii_strtod to convert the NULL pointer to 0.0,
// but we include the following test anyway
g_warning ("Coordinate conversion failed.\n");
}
}
static gchar *
{
return sp_3dbox_get_svg_descr_of_persp (SP_OBJECT_DOCUMENT (G_OBJECT (box))->get_persp_of_box (box));
}
gchar *
{
// FIXME: We should move this code to perspective3d.cpp, but this yields compiler errors. Why?
os << "finite,";
} else {
os << "infinite,";
}
os << "finite,";
} else {
os << "infinite,";
}
os << "finite";
} else {
os << "infinite";
}
}
// auxiliary function
sp_3dbox_new_midpoints (Box3D::Perspective3D *persp, Box3D::Axis axis, NR::Point const &M0, NR::Point const &M, NR::Point const &A, NR::Point const &B)
{
// FIXME: cr == 1 is a degenerate case; how should we deal with it?
}
}
{
// TODO: Clean this function up
Box3D::Perspective3D *persp = sp_desktop_document (inkscape_active_desktop())->get_persp_of_box (box);
NR::Point A0 (sp_3dbox_get_midpoint_in_axis_direction (box->old_corner2, box->old_corner0, Box3D::Y, persp));
NR::Point B0 (sp_3dbox_get_midpoint_in_axis_direction (box->old_corner1, box->old_corner3, Box3D::Y, persp));
/* we first move the box along the X-axis ... */
std::pair<NR::Point, NR::Point> new_midpts = sp_3dbox_new_midpoints (persp, Box3D::X, M0, M1, A0, B0);
/* ... and then along the Y-axis */
std::pair<NR::Point, NR::Point> other_new_midpts = sp_3dbox_new_midpoints (persp, Box3D::Y, M1, M2, C1, D1);
}
{
if (!SP_IS_3DBOX_CONTEXT (ec))
return;
}
/*
* Manipulates corner1 through corner4 to contain the indices of the corners
* from which the perspective lines in the direction of 'axis' emerge
*/
{
// along which axis to switch when takint
} else {
}
switch (axis) {
case Box3D::X:
break;
case Box3D::Y:
break;
case Box3D::Z:
break;
default:
// do nothing
break;
}
}
/**
* Returns the id of the corner on the edge along 'axis' and passing through 'corner' that
*/
sp_3dbox_get_corner_id_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos)
{
Box3D::VanishingPoint *vp = SP_OBJECT_DOCUMENT (G_OBJECT (box))->get_persp_of_box (box)->get_vanishing_point(axis);
} else {
// clear the axis bit and switch to the appropriate corner along axis, depending on the value of front_bits
}
return result;
} else {
}
}
sp_3dbox_get_corner_along_edge (const SP3DBox *box, guint corner, Box3D::Axis axis, Box3D::FrontOrRear rel_pos)
{
}
{
guint front_corner = 1; // this could in fact be any corner, but we choose the one that is normally in front
return front_corner;
}
// auxiliary functions
static void
{
}
static void
{
// WARNING! This function changes the perspective associated to 'box'. Since there may be
// many other boxes linked to the same perspective, their perspective is also changed.
// If this behaviour is not desired in all cases, we need a different function.
for (int i = 0; i < 15; ++i) {
g_warning ("Malformed svg attribute 'perspective'\n");
return;
}
}
persp->set_vanishing_point (Box3D::Z, g_ascii_strtod (vps[10], NULL), g_ascii_strtod (vps[11], NULL),
// update the other boxes linked to the same perspective
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :