box3d.cpp revision e5fd2dcbf9f67fe796bc0a48f1fcedb5ba829af5
/*
* SVG <box3d> implementation
*
* Authors:
* Maximilian Albert <Anhalter42@gmx.de>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Abhishek Sharma
* Jon A. Cruz <jon@joncruz.org>
*
* 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 "ui/tools/box3d-tool.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"
#include "sp-factory.h"
namespace {
SPObject* createBox3D() {
return new SPBox3D();
}
}
this->my_counter = 0;
this->persp_href = NULL;
this->persp_ref = new Persp3DReference(this);
}
}
/* we initialize the z-orders to zero so that they are updated during dragging */
for (int i = 0; i < 6; ++i) {
}
if ( doc ) {
}
}
if (box->persp_href) {
}
// We have to store this here because the Persp3DReference gets destroyed below, but we need to
// access it to call persp3d_remove_box(), which cannot be called earlier because the reference
// needs to be destroyed first.
}
if (persp) {
/*
// TODO: This deletes a perspective when the last box referring to it is gone. Eventually,
// Reason: When redoing a box deletion, the associated perspective is deleted twice, first
// by the following code and then again by the redo mechanism! Perhaps we should perform
if (persp->perspective_impl->boxes.empty()) {
SPDocument *doc = box->document;
persp->deleteObject();
doc->setCurrentPersp3D(persp3d_document_first_persp(doc));
}
*/
}
}
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) {
}
{
}
}
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
}
Inkscape::XML::Node* SPBox3D::write(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;
}
const char* SPBox3D::display_name() {
return _("3D Box");
}
{
/* 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) */
if (side) {
}
}
}
// We don't apply the transform to the box directly but instead to its perspective (which is
// done in sp_selection_apply_affine). Here we only adjust strokes, patterns, etc.
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) {
return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_corner).affine() * i2d.inverse();
} else {
}
}
1.0);
}
if (!box3d_get_perspective(box)) {
}
return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_center).affine() * i2d.inverse();
}
/*
* 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;
// constant for sizing the array of points to be considered:
static const int MAX_POINT_COUNT = 4;
// 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[MAX_POINT_COUNT];
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 {
}
}
{
return box3d;
}
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 */
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
try
{
}
catch (Geom::InfiniteSolutions& e)
{
// We're probably dealing with parallel lines, so they don't really cross
return false;
}
if (!inters) {
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;
}
/*
* 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;
}
// FIXME: At present, this is not used. Why is it calculated?
/*
unsigned int central_corner = 3 ^ central_axis;
if (central_axis == Box3D::Z) {
central_corner = central_corner ^ Box3D::XYZ;
}
if (box3d_XY_axes_are_swapped(box)) {
central_corner = central_corner ^ Box3D::XYZ;
}
*/
// 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 (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
}
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 */
{
// remember position of the box
// remember important attributes
// create a new group and add the sides (converted to ordinary paths) as its children
if (side) {
} 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)
box->deleteObject(true);
}
const char *SPBox3D::displayName() const {
return _("3D Box");
}
// We could put more details about the 3d box here
return g_strdup("");
}
static inline void
box3d_push_back_corner_pair(SPBox3D const *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) {
}
void SPBox3D::convert_to_guides() const {
this->convert_to_guides();
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 :