box3d.cpp revision 13fb8f69456a16aa361d3c7db68b9551f3f3ae53
#define __SP_BOX3D_C__
/*
* SVG <box3d> implementation
*
* Authors:
* Maximilian Albert <Anhalter42@gmx.de>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* 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 "xml/document.h"
#include "libnr/nr-matrix-fns.h"
#include "box3d.h"
#include "box3d-side.h"
#include "box3d-context.h"
#include "proj_pt.h"
#include "transf_mat_3x4.h"
#include "perspective-line.h"
#include "inkscape.h"
#include "persp3d.h"
#include "line-geometry.h"
#include "persp3d-reference.h"
#include "uri.h"
#include "sp-guide.h"
#include "sp-namedview.h"
#include "preferences.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "macros.h"
static Inkscape::XML::Node *box3d_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
static SPGroupClass *parent_class;
box3d_get_type(void)
{
if (!type) {
sizeof(SPBox3DClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(SPBox3D),
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) {
}
if (!doc) {
g_print ("No document for the box!!!!\n");
return;
}
}
/**
* Virtual release of SPBox3D members before destruction.
*/
static void
{
if (box->persp_href) {
}
}
//persp3d_remove_box (box3d_get_perspective(box), box);
}
static void
{
switch (key) {
/* No change, do nothing. */
} else {
if (box->persp_href) {
}
if (value) {
// Now do the attaching, which emits the changed signal.
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
// Detach, which emits the changed signal.
}
}
// FIXME: Is the following update doubled by some call in either persp3d.cpp or vanishing_point_new.cpp?
break;
}
break;
}
break;
default:
}
break;
}
}
/**
* Gets called when (re)attached to another perspective.
*/
static void
{
if (old_ref) {
/* Note: This sometimes leads to attempts to remove boxes twice from the list of selected/transformed
boxes in a perspectives, but this should be uncritical. */
}
{
/* Note: This sometimes leads to attempts to add boxes twice to the list of selected/transformed
boxes in a perspectives, but this should be uncritical. */
}
}
static void
{
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
/* FIXME?: Perhaps the display updates of box sides should be instantiated from here, but this
causes evil update loops so it's all done from box3d_position_set, which is called from
various other places (like the handlers in object-edit.cpp, vanishing-point.cpp, etc. */
}
// Invoke parent method
}
static Inkscape::XML::Node *box3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
// this is where we end up when saving as plain SVG (also in other circumstances?)
// thus we don' set "sodipodi:type" so that the box is only saved as an ordinary svg:g
}
if (flags & SP_OBJECT_WRITE_EXT) {
if (box->persp_href) {
} else {
/* box is not yet linked to a perspective; use the document's current perspective */
} else {
}
}
}
}
return repr;
}
static gchar *
{
return g_strdup(_("<b>3D Box</b>"));
}
void
{
/* This draws the curve and calls requestDisplayUpdate() for each side (the latter is done in
box3d_side_position_set() to avoid update conflicts with the parent box) */
for (SPObject *child = sp_object_first_child(SP_OBJECT (box)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_BOX3D_SIDE(child))
}
}
{
/* check whether we need to unlink any boxes from their perspectives */
if (!persp3d_has_all_boxes_in_selection (persp)) {
/* create a new perspective as a copy of the current one and link the selected boxes to it */
}
} else {
}
/* only transform the perspective once, even if it has several selected boxes */
if(!persp3d_was_transformed (transf_persp)) {
/* concatenate the affine transformation with the perspective mapping; this
function also triggers repr updates of boxes and the perspective itself */
}
if (persp3d_all_transformed(transf_persp)) {
/* all boxes were transformed; make perspective sensitive for further transformations */
}
if (SP_IS_ITEM(child)) {
// Adjust stroke width
// Adjust pattern fill
// Adjust gradient fill
// Adjust LPE
}
}
}
1.0);
}
1.0);
}
if (!box3d_get_perspective(box)) {
}
if (item_coords) {
} else {
}
}
1.0);
}
if (!box3d_get_perspective(box)) {
}
}
/*
* To keep the snappoint from jumping randomly between the two lines when the mouse pointer is close to
* their intersection, we remember the last snapped line and keep snapping to this specific line as long
* as the distance from the intersection to the mouse pointer is less than remember_snap_threshold.
*/
// Should we make the threshold settable in the preferences?
static double remember_snap_threshold = 30;
static guint remember_snap_index = 0;
// TODO: Replace these lines between corners with lines from a corner to a vanishing point
// (this might help to prevent rounding errors if the box is small)
Box3D::Line diag2(A, E); // diag2 is only taken into account if id equals -1, i.e., if we are snapping the center
if (id == -1) {
}
// determine the distances to all potential snapping points
double snap_dists[num_snap_lines];
for (int i = 0; i < num_snap_lines; ++i) {
}
// while we are within a given tolerance of the starting point,
// keep snapping to the same point to avoid jumping
bool within_tolerance = true;
for (int i = 0; i < num_snap_lines; ++i) {
if (snap_dists[i] > remember_snap_threshold) {
within_tolerance = false;
break;
}
}
// find the closest snapping point
int snap_index = -1;
for (int i = 0; i < num_snap_lines; ++i) {
if (snap_dists[i] < snap_dist) {
snap_index = i;
snap_dist = snap_dists[i];
}
}
// snap to the closest point (or the previously remembered one
// if we are within tolerance of the starting point)
if (within_tolerance) {
} else {
}
}
void
box3d_set_corner (SPBox3D *box, const guint id, Geom::Point const &new_pos, const Box3D::Axis movement, bool constrained) {
/* update corners 0 and 7 according to which handle was moved and to the axes of movement */
Proj::Pt3 pt_proj (box3d_get_perspective(box)->tmat.preimage (new_pos, (id < 4) ? box->orig_corner0[Proj::Z] :
if (constrained) {
pt_proj = box3d_snap (box, id, pt_proj, box3d_get_proj_corner (id, box->save_corner0, box->save_corner7));
}
// normalizing pt_proj is essential because we want to mingle affine coordinates
1.0);
1.0);
} else {
// normalizing pt_proj is essential because we want to mingle affine coordinates
1.0);
1.0);
}
// FIXME: Should we update the box here? If so, how?
}
void box3d_set_center (SPBox3D *box, Geom::Point const &new_pos, Geom::Point const &old_pos, const Box3D::Axis movement, bool constrained) {
if (constrained) {
}
// normalizing pt_proj is essential because we want to mingle affine coordinates
box->orig_corner0 = Proj::Pt3 ((movement & Box3D::X) ? pt_proj[Proj::X] - radx : box->orig_corner0[Proj::X],
1.0);
box->orig_corner7 = Proj::Pt3 ((movement & Box3D::X) ? pt_proj[Proj::X] + radx : box->orig_corner7[Proj::X],
1.0);
} else {
/* normalizing pt_proj is essential because we want to mingle affine coordinates */
1.0);
1.0);
}
}
/*
* Manipulates corner1 through corner4 to contain the indices of the corners
* from which the perspective lines in the direction of 'axis' emerge
*/
{
//box->orig_corner0.normalize();
//box->orig_corner7.normalize();
// FIXME: This can certainly be done more elegantly/efficiently than by a case-by-case analysis.
switch (axis) {
case Proj::X:
break;
case Proj::Y:
break;
case Proj::Z:
break;
default:
return;
}
}
/* Auxiliary function: Checks whether the half-line from A to B crosses the line segment joining C and D */
static bool
return false;
}
// C and D lie on the same side of the line AB
return false;
}
// A and B lie on different sides of the line CD
return true;
// The line CD passes on the "wrong" side of A
return false;
}
// The line CD passes on the "correct" side of A
return true;
}
static bool
g_return_val_if_fail(persp, false);
}
static inline void
z_orders[0] = a;
z_orders[1] = b;
z_orders[2] = c;
z_orders[3] = d;
z_orders[4] = e;
z_orders[5] = f;
}
static inline void
int tmp;
for (int i = 0; i < 3; ++i) {
}
}
/*
* In standard perspective we have:
* 2 = front face
* 1 = top face
* 0 = left face
* 3 = right face
* 4 = bottom face
* 5 = rear face
*/
/* All VPs infinite */
static void
switch(central_axis) {
case Box3D::X:
if (!swapped) {
} else {
}
break;
case Box3D::Y:
if (!swapped) {
} else {
}
break;
case Box3D::Z:
if (!swapped) {
} else {
}
break;
if (!swapped) {
} else {
}
break;
default:
break;
}
}
/* Precisely one finite VP */
static void
box3d_set_new_z_orders_case1 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis, Box3D::Axis fin_axis) {
// note: in some of the case distinctions below we rely upon the fact that oaxis1 and oaxis2 are ordered
int inside1 = 0;
int inside2 = 0;
switch(central_axis) {
case Box3D::X:
if (!swapped) {
} else {
}
break;
case Box3D::Y:
if (inside2 > 0) {
} else if (inside2 < 0) {
} else {
if (!swapped) {
} else {
}
}
break;
case Box3D::Z:
if (inside2) {
if (!swapped) {
} else {
}
} else if (inside1) {
if (!swapped) {
} else {
}
} else {
// "regular" case
if (!swapped) {
} else {
}
}
break;
if (!swapped) {
} else {
}
break;
default:
}
}
/* Precisely 2 finite VPs */
static void
box3d_set_new_z_orders_case2 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis, Box3D::Axis /*infinite_axis*/) {
//int insidexz = box3d_VP_lies_in_PL_sector (box, Proj::X, 3, 3 ^ Box3D::Y, Box3D::Z);
//int insidezx = box3d_VP_lies_in_PL_sector (box, Proj::Z, 3, 3 ^ Box3D::Y, Box3D::X);
switch(central_axis) {
case Box3D::X:
if (!swapped) {
if (insidezy == -1) {
} else if (insidexy == 1) {
} else {
}
} else {
if (insideyz == -1) {
} else {
if (!swapped) {
} else {
if (insidexy == 0) {
} else {
}
}
}
}
break;
case Box3D::Y:
if (!swapped) {
if (insideyz == 1) {
} else {
}
} else {
if (insideyx == 1) {
} else {
}
}
break;
case Box3D::Z:
if (!swapped) {
if (insidezy == 1) {
} else if (insidexy == -1) {
} else {
}
} else {
}
break;
if (!swapped) {
} else {
}
break;
default:
break;
}
}
/*
* It can happen that during dragging the box is everted.
* In this case the opposite sides in this direction need to be swapped
*/
if (box->orig_corner0[Proj::Z] > box->orig_corner7[Proj::Z]) // FIXME: Remove the need to distinguish signs among the cases
return ev;
}
static void
int pos1 = -1;
int pos2 = -1;
for (int i = 0; i < 6; ++i) {
if (pos1 == -1) {
pos1 = i;
} else {
pos2 = i;
break;
}
}
}
}
bool
if (!persp)
return false;
int z_orders[6];
// determine directions from corner3 to the VPs
int num_finite = 0;
for (int i = 0; i < 3; ++i) {
num_finite++;
} else {
}
}
// determine the "central" axis (if there is one)
central_axis = Box3D::Z;
central_axis = Box3D::X;
central_axis = Box3D::Y;
}
switch (num_finite) {
case 0:
// TODO: Remark: In this case (and maybe one of the others, too) the z-orders for all boxes
// coincide, hence only need to be computed once in a more central location.
break;
case 1:
break;
case 2:
case 3:
break;
default:
/*
* For each VP F, check wether the half-line from the corner3 to F crosses the line segment
* joining the other two VPs. If this is the case, it determines the "central" corner from
* which the visible sides can be deduced. Otherwise, corner3 is the central corner.
*/
// FIXME: We should eliminate the use of Geom::Point altogether
central_axis = Box3D::X;
central_axis = Box3D::Y;
central_axis = Box3D::Z;
}
if (central_axis == Box3D::Z) {
}
if (box3d_XY_axes_are_swapped(box)) {
}
// FIXME: At present we don't use the information about central_corner computed above.
switch (central_axis) {
case Box3D::Y:
} else {
// degenerate case
}
break;
case Box3D::Z:
// degenerate case
// degenerate case
} else {
}
break;
case Box3D::X:
// degenerate case
} else {
}
break;
break;
default:
break;
} // end default case
}
// TODO: If there are still errors in z-orders of everted boxes, we need to choose a variable corner
// instead of the hard-coded corner #3 in the computations above
for (int i = 0; i < 3; ++i) {
}
}
// Check whether anything actually changed
for (int i = 0; i < 6; ++i) {
for (int j = i; j < 6; ++j) {
}
return true;
}
}
return false;
}
if (SP_IS_BOX3D_SIDE(side))
}
return sides;
}
// TODO: Check whether the box is everted in any direction and swap the sides opposite to this direction
void
// For efficiency reasons, we only set the new z-orders if something really changed
if (box3d_recompute_z_orders (box)) {
for (unsigned int i = 0; i < 6; ++i) {
}
}
}
}
/*
* Auxiliary function for z-order recomputing:
* Determines whether \a pt lies in the sector formed by the two PLs from the corners with IDs
* \a i21 and \a id2 to the VP in direction \a axis. If the VP is infinite, we say that \a pt
* lies in the sector if it lies between the two (parallel) PLs.
* \ret * 0 if \a pt doesn't lie in the sector
* * 1 if \a pt lies in the sector and either VP is finite of VP is infinite and the direction
* from the edge between the two corners to \a pt points towards the VP
* * -1 otherwise
*/
// TODO: Maybe it would be useful to have a similar method for projective points pt because then we
// can use it for VPs and perhaps merge the case distinctions during z-order recomputation.
int
box3d_pt_lies_in_PL_sector (SPBox3D const *box, Geom::Point const &pt, int id1, int id2, Box3D::Axis axis) {
// the two corners
int ret = 0;
} else {
// test whether pt lies "towards" or "away from" the VP
ret = 1;
} else {
ret = -1;
}
}
}
return ret;
}
int
box3d_VP_lies_in_PL_sector (SPBox3D const *box, Proj::Axis vpdir, int id1, int id2, Box3D::Axis axis) {
return 0;
} else {
}
}
/* swap the coordinates of corner0 and corner7 along the specified axis */
static void
}
// Should we also swap the coordinates of save_corner0 and save_corner7?
}
/* ensure that the coordinates of corner0 and corner7 are in the correct order (to prevent everted boxes) */
void
}
static void
} else {
}
}
static void
for (int i = 0; i < 3; ++i) {
}
}
}
void
}
void
}
void
if (!persp) {
/* this can happen if a box is deleted through undo and the persp_ref is already detached;
should we rebuild the boxes of each perspective in this case or is it safe to leave it alone? */
return;
}
}
void
}
static void
if (SP_IS_BOX3D(obj)) {
} else if (SP_IS_GROUP(obj)) {
}
}
}
return boxes;
}
Persp3D *
}
void
box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp, bool recompute_corners) {
if (recompute_corners) {
}
}
/* Converts the 3D box to an ordinary SPGroup, adds it to the XML tree at the same position as
the original box and deletes the latter */
SPGroup *
// remember position of the box
// remember important attributes
// create a new group and add the sides (converted to ordinary paths) as its children
for (SPObject *child = sp_object_first_child(SP_OBJECT(box)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (SP_IS_BOX3D_SIDE(child)) {
} else {
g_warning("Non-side item encountered as child of a 3D box.");
}
}
// add the new group to the box's parent and set remembered position
if (mask)
if (clip_path)
}
static inline void
box3d_push_back_corner_pair(SPBox3D *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) {
}
void
return;
}
/* perspective lines in X direction */
/* perspective lines in Y direction */
/* perspective lines in Z direction */
}
/*
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 :