box3d.cpp revision 72ea4c0c8c73f2159bd19761dd1fb0fcf8ceb4f9
#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 "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 "prefs-utils.h"
#include "desktop.h"
#include "macros.h"
//static void box3d_ref_changed(SPObject *old_ref, SPObject *ref, Persp3D *persp);
//static void box3d_ref_modified(SPObject *href, guint flags, Persp3D *persp);
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;
}
/**
if (!box->persp3d) {
g_print ("Box seems to be newly created since no perspective is referenced yet. We reference the current perspective.\n");
box->persp3d = doc->current_persp3d;
}
**/
}
/**
* 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.
// TODO: Clean this up (also w.r.t the surrounding if construct)
/***
g_print ("No perspective given. Attaching to current perspective instead.\n");
g_free(box->persp_href);
Inkscape::XML::Node *repr = SP_OBJECT_REPR(inkscape_active_document()->current_persp3d);
box->persp_href = g_strdup(repr->attribute("id"));
box->persp_ref->attach(Inkscape::URI(box->persp_href));
***/
}
}
// FIXME: Is the following update doubled by some call in either persp3d.cpp or vanishing_point_new.cpp?
break;
}
break;
}
break;
default:
}
break;
}
//object->updateRepr(); // This ensures correct update of the box after undo/redo. FIXME: Why is this not present in sp-rect.cpp and similar files?
}
/**
* 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. */
}
{
box->modified_connection = ref->connectModified(sigc::bind(sigc::ptr_fun(&box3d_ref_modified), box));
/* 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
}
{
// 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 if (doc) {
//persp3d_add_box (doc->current_persp3d, box);
} else {
g_print ("No active document while creating perspective!!!\n");
}
}
}
}
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) ) {
}
}
{
/* 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 */
}
// Adjust stroke width
// Adjust pattern fill
// Adjust gradient fill
// Adjust LPE
}
}
/**
* Gets called when persp(?) repr contents change: i.e. parameter change.
*/
static void
{
/***
g_print ("FIXME: box3d_ref_modified was called. What should we do?\n");
g_print ("Here is at least the the href's id: %s\n", SP_OBJECT_REPR(href)->attribute("id"));
g_print (" ... and the box's, too: %s\n", SP_OBJECT_REPR(box)->attribute("id"));
***/
}
1.0);
}
1.0);
}
if (!box3d_get_perspective(box)) {
//g_print ("No perspective present in box!! Should we simply use the currently active perspective?\n");
}
}
1.0);
}
if (!box3d_get_perspective(box)) {
//g_print ("No perspective present in box!! Should we simply use the currently active perspective?\n");
}
}
/*
* 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;
static guint remember_snap_index_center = 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, NR::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, NR::Point const &new_pos, NR::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
//g_print ("3 infinite VPs; ");
switch(central_axis) {
case Box3D::X:
if (!swapped) {
//g_print ("central axis X (case a)");
} else {
//g_print ("central axis X (case b)");
}
break;
case Box3D::Y:
if (!swapped) {
//g_print ("central axis Y (case a)");
} else {
//g_print ("central axis Y (case b)");
}
break;
case Box3D::Z:
if (!swapped) {
//g_print ("central axis Z (case a)");
} else {
//g_print ("central axis Z (case b)");
}
break;
if (!swapped) {
//g_print ("central axis NONE (case a)");
} else {
//g_print ("central axis NONE (case b)");
}
break;
default:
break;
}
/**
if (swapped) {
g_print ("; swapped");
}
g_print ("\n");
**/
}
/* 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
//g_print ("oaxis1 = %s, oaxis2 = %s\n", Box3D::string_from_axes(oaxis1), Box3D::string_from_axes(oaxis2));
int inside1 = 0;
int inside2 = 0;
//g_print ("inside1 = %d, inside2 = %d\n", inside1, inside2);
//g_print ("2 infinite VPs; ");
//g_print ("finite axis: %s; ", Box3D::string_from_axes(fin_axis));
switch(central_axis) {
case Box3D::X:
if (!swapped) {
//g_print ("central axis X (case a)");
} else {
//if (inside2) {
//g_print ("central axis X (case b)");
//} else {
//g_print ("central axis X (case c)");
//box3d_aux_set_z_orders (z_orders, 5, 3, 1, 2, 0, 4);
//}
}
break;
case Box3D::Y:
if (inside2 > 0) {
//g_print ("central axis Y (case a)");
} else if (inside2 < 0) {
//g_print ("central axis Y (case b)");
} else {
if (!swapped) {
//g_print ("central axis Y (case c1)");
} else {
//g_print ("central axis Y (case c2)");
}
}
break;
case Box3D::Z:
if (inside2) {
if (!swapped) {
//g_print ("central axis Z (case a1)");
} else {
//g_print ("central axis Z (case a2)");
}
} else if (inside1) {
if (!swapped) {
//g_print ("central axis Z (case b1)");
} else {
//g_print ("central axis Z (case b2)");
//box3d_aux_set_z_orders (z_orders, 5, 3, 0, 1, 2, 4);
}
} else {
// "regular" case
if (!swapped) {
//g_print ("central axis Z (case c1)");
} else {
//g_print ("central axis Z (case c2)");
//box3d_aux_set_z_orders (z_orders, 5, 3, 4, 0, 2, 1);
}
}
break;
if (!swapped) {
//g_print ("central axis NONE (case a)");
} else {
//g_print ("central axis NONE (case b)");
//box3d_aux_set_z_orders (z_orders, 2, 3, 4, 1, 0, 5);
}
break;
default:
}
/**
if (swapped) {
g_print ("; swapped");
}
g_print ("\n");
**/
}
/* 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*/) {
//g_print ("Insides: xy = %d, xz = %d, yx = %d, yz = %d, zx = %d, zy = %d\n",
// insidexy, insidexz, insideyx, insideyz, insidezx, insidezy);
(void)insidexz;
(void)insideyx;
(void)insidezx;
//g_print ("1 infinite VP; ");
switch(central_axis) {
case Box3D::X:
if (!swapped) {
if (insidezy == -1) {
//g_print ("central axis X (case a1)");
} else if (insidexy == 1) {
//g_print ("central axis X (case a2)");
} else {
//g_print ("central axis X (case a3)");
}
} else {
if (insideyz == -1) {
//g_print ("central axis X (case b1)");
} else {
if (!swapped) {
//g_print ("central axis X (case b2)");
} else {
//g_print ("central axis X (case b3)");
}
}
}
break;
case Box3D::Y:
if (!swapped) {
if (insideyz == 1) {
//g_print ("central axis Y (case a1)");
} else {
//g_print ("central axis Y (case a2)");
}
} else {
//g_print ("central axis Y (case b)");
}
break;
case Box3D::Z:
if (!swapped) {
if (insidezy == 1) {
//g_print ("central axis Z (case a1)");
} else if (insidexy == -1) {
//g_print ("central axis Z (case a2)");
} else {
//g_print ("central axis Z (case a3)");
}
} else {
//g_print ("central axis Z (case b)");
}
break;
if (!swapped) {
//g_print ("central axis NONE (case a)");
} else {
//g_print ("central axis NONE (case b)");
}
break;
default:
break;
}
/**
if (swapped) {
g_print ("; swapped");
}
g_print ("\n");
**/
}
/*
* 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
//g_return_val_if_fail(persp, false);
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 NR::Point altogether
central_axis = Box3D::X;
central_axis = Box3D::Y;
central_axis = Box3D::Z;
}
//g_print ("Crossing: %s\n", Box3D::string_from_axes(central_axis));
if (central_axis == Box3D::Z) {
}
if (box3d_XY_axes_are_swapped(box)) {
//g_print ("Axes X and Y are swapped\n");
}
// FIXME: At present we don't use the information about central_corner computed above.
switch (central_axis) {
case Box3D::Y:
} else {
// degenerate case
//g_print ("Degenerate case #1\n");
}
break;
case Box3D::Z:
// degenerate case
//g_print ("Degenerate case #2\n");
// degenerate case
//g_print ("Degenerate case #3\n");
} else {
}
break;
case Box3D::X:
// degenerate case
//g_print ("Degenerate case #4\n");
} 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;
}
}
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) {
}
}
/**
g_print ("Resetting z-orders: ");
for (int i = 0; i < 6; ++i) {
g_print ("%d ", box->z_orders[i]);
}
g_print ("\n");
**/
}
}
/*
* 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, NR::Point const &pt, int id1, int id2, Box3D::Axis axis) {
// the two corners
int ret = 0;
//g_print ("Case 0 - returning %d\n", ret);
} else {
// test whether pt lies "towards" or "away from" the VP
ret = 1;
} else {
ret = -1;
}
}
//g_print ("Case 1 - returning %d\n", ret);
}
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
}
// FIXME: 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
}
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 */
// TODO: Copy over all important attributes (see sp_selected_item_to_curved_repr() for an example)
SPGroup *
// remember position of the box
// 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 object encountered as child of a 3D box.\n");
}
}
// add the new group to the box's parent and set remembered position
}
static void
box3d_push_back_corner_pair(SPBox3D *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) {
}
void
return;
}
//SPDesktop *desktop = inkscape_active_desktop();
//Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
/* perspective lines in X direction */
/* perspective lines in Y direction */
/* perspective lines in Z direction */
if (write_undo) {
}
}
/*
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 :