From 13223d251a0eca100512280a15dc9b2213a28809 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sun, 23 Dec 2007 22:37:31 +0000 Subject: [PATCH] Bug fix: prevent perspectives from being transformed more than once (by keeping track of selected boxes and their transformations). --- src/box3d.cpp | 149 +++++++++++++++++++++++++++------------- src/box3d.h | 5 ++ src/persp3d.cpp | 100 ++++++++++++++++++++++++++- src/persp3d.h | 11 +++ src/selection.cpp | 11 +++ src/vanishing-point.cpp | 8 +-- 6 files changed, 229 insertions(+), 55 deletions(-) diff --git a/src/box3d.cpp b/src/box3d.cpp index 0f8abd71d..b1f59253f 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -163,7 +163,7 @@ box3d_release(SPObject *object) box->modified_connection.disconnect(); box->modified_connection.~connection(); - //persp3d_remove_box (box->persp_ref->getObject(), box); + //persp3d_remove_box (box3d_get_perspective(box), box); if (((SPObjectClass *) parent_class)->release) ((SPObjectClass *) parent_class)->release(object); @@ -242,6 +242,9 @@ box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box) if (old_ref) { sp_signal_disconnect_by_data(old_ref, box); persp3d_remove_box (SP_PERSP3D(old_ref), box); + /* 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. */ + persp3d_remove_box_transform (SP_PERSP3D(old_ref), box); } if ( SP_IS_PERSP3D(ref) && ref != box ) // FIXME: Comparisons sane? { @@ -249,6 +252,9 @@ box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box) box->modified_connection = ref->connectModified(sigc::bind(sigc::ptr_fun(&box3d_ref_modified), box)); box3d_ref_modified(ref, 0, box); persp3d_add_box (SP_PERSP3D(ref), 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. */ + persp3d_add_box_transform (SP_PERSP3D(ref), box); } } @@ -343,32 +349,41 @@ box3d_position_set (SPBox3D *box) } static NR::Matrix -box3d_set_transform(SPItem */*item*/, NR::Matrix const &xform) +box3d_set_transform(SPItem *item, NR::Matrix const &xform) { + SPBox3D *box = SP_BOX3D(item); + /* check whether we need to unlink any boxes from their perspectives */ - std::set p_sel = persp3d_currently_selected_persps(inkscape_active_event_context()); - Persp3D *persp; + Persp3D *persp = box3d_get_perspective(box); Persp3D *transf_persp; - for (std::set::iterator p = p_sel.begin(); p != p_sel.end(); ++p) { - persp = (*p); - if (!persp3d_has_all_boxes_in_selection (persp)) { - std::list sel = persp3d_selected_boxes (persp); - /* create a new perspective as a copy of the current one and link the selected boxes to it */ - transf_persp = persp3d_create_xml_element (SP_OBJECT_DOCUMENT(persp), persp); + if (!persp3d_has_all_boxes_in_selection (persp)) { + std::list sel = persp3d_selected_boxes (persp); - for (std::list::iterator b = sel.begin(); b != sel.end(); ++b) { - box3d_switch_perspectives(*b, persp, transf_persp); - } - } else { - transf_persp = persp; + /* create a new perspective as a copy of the current one and link the selected boxes to it */ + transf_persp = persp3d_create_xml_element (SP_OBJECT_DOCUMENT(persp), persp); + + for (std::list::iterator b = sel.begin(); b != sel.end(); ++b) { + box3d_switch_perspectives(*b, persp, transf_persp); } + } else { + transf_persp = persp; + } + /* only transform the perspective once, even it 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 */ persp3d_apply_affine_transformation(transf_persp, xform); } + box3d_mark_transformed(box); + + if (persp3d_all_transformed(transf_persp)) { + /* all boxes were transformed; make perspective sensitive for further transformations */ + persp3d_unset_transforms(transf_persp); + } + /*** // FIXME: We somehow have to apply the transformation to strokes, patterns, and gradients. How? NR::Matrix ret(NR::transform(xform)); @@ -427,11 +442,11 @@ box3d_get_proj_corner (SPBox3D const *box, guint id) { NR::Point box3d_get_corner_screen (SPBox3D const *box, guint id) { Proj::Pt3 proj_corner (box3d_get_proj_corner (box, id)); - if (!box->persp_ref->getObject()) { + if (!box3d_get_perspective(box)) { //g_print ("No perspective present in box!! Should we simply use the currently active perspective?\n"); return NR::Point (NR_HUGE, NR_HUGE); } - return box->persp_ref->getObject()->tmat.image(proj_corner).affine(); + return box3d_get_perspective(box)->tmat.image(proj_corner).affine(); } Proj::Pt3 @@ -447,11 +462,11 @@ box3d_get_proj_center (SPBox3D *box) { NR::Point box3d_get_center_screen (SPBox3D *box) { Proj::Pt3 proj_center (box3d_get_proj_center (box)); - if (!box->persp_ref->getObject()) { + if (!box3d_get_perspective(box)) { //g_print ("No perspective present in box!! Should we simply use the currently active perspective?\n"); return NR::Point (NR_HUGE, NR_HUGE); } - return box->persp_ref->getObject()->tmat.image(proj_center).affine(); + return box3d_get_perspective(box)->tmat.image(proj_center).affine(); } /* @@ -478,12 +493,13 @@ box3d_snap (SPBox3D *box, int id, Proj::Pt3 const &pt_proj, Proj::Pt3 const &sta Proj::Pt3 D_proj (x_coord, y_coord + diff_y, z_coord, 1.0); Proj::Pt3 E_proj (x_coord - diff_x, y_coord + diff_y, z_coord, 1.0); - NR::Point A = box->persp_ref->getObject()->tmat.image(A_proj).affine(); - NR::Point B = box->persp_ref->getObject()->tmat.image(B_proj).affine(); - NR::Point C = box->persp_ref->getObject()->tmat.image(C_proj).affine(); - NR::Point D = box->persp_ref->getObject()->tmat.image(D_proj).affine(); - NR::Point E = box->persp_ref->getObject()->tmat.image(E_proj).affine(); - NR::Point pt = box->persp_ref->getObject()->tmat.image(pt_proj).affine(); + Persp3D *persp = box3d_get_perspective(box); + NR::Point A = persp->tmat.image(A_proj).affine(); + NR::Point B = persp->tmat.image(B_proj).affine(); + NR::Point C = persp->tmat.image(C_proj).affine(); + NR::Point D = persp->tmat.image(D_proj).affine(); + NR::Point E = persp->tmat.image(E_proj).affine(); + NR::Point pt = persp->tmat.image(pt_proj).affine(); // 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) @@ -539,7 +555,7 @@ box3d_snap (SPBox3D *box, int id, Proj::Pt3 const &pt_proj, Proj::Pt3 const &sta remember_snap_index_center = snap_index; result = snap_pts[snap_index]; } - return box->persp_ref->getObject()->tmat.preimage (result, z_coord, Proj::Z); + return box3d_get_perspective(box)->tmat.preimage (result, z_coord, Proj::Z); } void @@ -551,9 +567,8 @@ box3d_set_corner (SPBox3D *box, const guint id, NR::Point const &new_pos, const /* update corners 0 and 7 according to which handle was moved and to the axes of movement */ if (!(movement & Box3D::Z)) { - Proj::Pt3 pt_proj (box->persp_ref->getObject()->tmat.preimage (new_pos, (id < 4) ? box->orig_corner0[Proj::Z] : - box->orig_corner7[Proj::Z], - Proj::Z)); + Proj::Pt3 pt_proj (box3d_get_perspective(box)->tmat.preimage (new_pos, (id < 4) ? box->orig_corner0[Proj::Z] : + box->orig_corner7[Proj::Z], Proj::Z)); if (constrained) { pt_proj = box3d_snap (box, id, pt_proj, box3d_get_proj_corner (id, box->save_corner0, box->save_corner7)); } @@ -569,12 +584,12 @@ box3d_set_corner (SPBox3D *box, const guint id, NR::Point const &new_pos, const box->save_corner7[Proj::Z], 1.0); } else { - Box3D::PerspectiveLine pl(box->persp_ref->getObject()->tmat.image( + Persp3D *persp = box3d_get_perspective(box); + Box3D::PerspectiveLine pl(persp->tmat.image( box3d_get_proj_corner (id, box->save_corner0, box->save_corner7)).affine(), - Proj::Z, box->persp_ref->getObject()); + Proj::Z, persp); NR::Point new_pos_snapped(pl.closest_to(new_pos)); - Proj::Pt3 pt_proj (box->persp_ref->getObject()-> - tmat.preimage (new_pos_snapped, + Proj::Pt3 pt_proj (persp->tmat.preimage (new_pos_snapped, box3d_get_proj_corner (box, id)[(movement & Box3D::Y) ? Proj::X : Proj::Y], (movement & Box3D::Y) ? Proj::X : Proj::Y)); bool corner0_move_x = !(id & Box3D::X) && (movement & Box3D::X); @@ -598,14 +613,15 @@ box3d_set_corner (SPBox3D *box, const guint id, NR::Point const &new_pos, const void box3d_set_center (SPBox3D *box, NR::Point const &new_pos, NR::Point const &old_pos, const Box3D::Axis movement, bool constrained) { g_return_if_fail ((movement != Box3D::NONE) && (movement != Box3D::XYZ)); + Persp3D *persp = box3d_get_perspective(box); if (!(movement & Box3D::Z)) { double coord = (box->orig_corner0[Proj::Z] + box->orig_corner7[Proj::Z]) / 2; double radx = (box->orig_corner7[Proj::X] - box->orig_corner0[Proj::X]) / 2; double rady = (box->orig_corner7[Proj::Y] - box->orig_corner0[Proj::Y]) / 2; - Proj::Pt3 pt_proj (box->persp_ref->getObject()->tmat.preimage (new_pos, coord, Proj::Z)); + Proj::Pt3 pt_proj (persp->tmat.preimage (new_pos, coord, Proj::Z)); if (constrained) { - Proj::Pt3 old_pos_proj (box->persp_ref->getObject()->tmat.preimage (old_pos, coord, Proj::Z)); + Proj::Pt3 old_pos_proj (persp->tmat.preimage (old_pos, coord, Proj::Z)); pt_proj = box3d_snap (box, -1, pt_proj, old_pos_proj); } // normalizing pt_proj is essential because we want to mingle affine coordinates @@ -622,9 +638,9 @@ void box3d_set_center (SPBox3D *box, NR::Point const &new_pos, NR::Point const & double coord = (box->orig_corner0[Proj::X] + box->orig_corner7[Proj::X]) / 2; double radz = (box->orig_corner7[Proj::Z] - box->orig_corner0[Proj::Z]) / 2; - Box3D::PerspectiveLine pl(old_pos, Proj::Z, box->persp_ref->getObject()); + Box3D::PerspectiveLine pl(old_pos, Proj::Z, persp); NR::Point new_pos_snapped(pl.closest_to(new_pos)); - Proj::Pt3 pt_proj (box->persp_ref->getObject()->tmat.preimage (new_pos_snapped, coord, Proj::X)); + Proj::Pt3 pt_proj (persp->tmat.preimage (new_pos_snapped, coord, Proj::X)); /* normalizing pt_proj is essential because we want to mingle affine coordinates */ pt_proj.normalize(); @@ -646,7 +662,8 @@ void box3d_set_center (SPBox3D *box, NR::Point const &new_pos, NR::Point const & void box3d_corners_for_PLs (const SPBox3D * box, Proj::Axis axis, NR::Point &corner1, NR::Point &corner2, NR::Point &corner3, NR::Point &corner4) { - g_return_if_fail (box->persp_ref->getObject()); + Persp3D *persp = box3d_get_perspective(box); + g_return_if_fail (persp); //box->orig_corner0.normalize(); //box->orig_corner7.normalize(); double coord = (box->orig_corner0[axis] > box->orig_corner7[axis]) ? @@ -677,10 +694,10 @@ void box3d_corners_for_PLs (const SPBox3D * box, Proj::Axis axis, default: return; } - corner1 = box->persp_ref->getObject()->tmat.image(c1).affine(); - corner2 = box->persp_ref->getObject()->tmat.image(c2).affine(); - corner3 = box->persp_ref->getObject()->tmat.image(c3).affine(); - corner4 = box->persp_ref->getObject()->tmat.image(c4).affine(); + corner1 = persp->tmat.image(c1).affine(); + corner2 = persp->tmat.image(c2).affine(); + corner3 = persp->tmat.image(c3).affine(); + corner4 = persp->tmat.image(c4).affine(); } /* Auxiliary function: Checks whether the half-line from A to B crosses the line segment joining C and D */ @@ -716,7 +733,7 @@ box3d_half_line_crosses_joining_line (Geom::Point const &A, Geom::Point const &B static bool box3d_XY_axes_are_swapped (SPBox3D *box) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); g_return_val_if_fail(persp, false); Box3D::PerspectiveLine l1(box3d_get_corner_screen(box, 3), Proj::X, persp); Box3D::PerspectiveLine l2(box3d_get_corner_screen(box, 3), Proj::Y, persp); @@ -761,7 +778,7 @@ box3d_swap_z_orders (int z_orders[6]) { /* All VPs infinite */ static void box3d_set_new_z_orders_case0 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); NR::Point xdir(persp3d_get_infinite_dir(persp, Proj::X)); NR::Point ydir(persp3d_get_infinite_dir(persp, Proj::Y)); NR::Point zdir(persp3d_get_infinite_dir(persp, Proj::Z)); @@ -821,7 +838,7 @@ box3d_set_new_z_orders_case0 (SPBox3D *box, int z_orders[6], Box3D::Axis central /* 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) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); NR::Point vp(persp3d_get_VP(persp, Box3D::toProj(fin_axis)).affine()); // note: in some of the case distinctions below we rely upon the fact that oaxis1 and oaxis2 are ordered @@ -924,7 +941,7 @@ box3d_set_new_z_orders_case1 (SPBox3D *box, int z_orders[6], Box3D::Axis central /* 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*/) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); NR::Point c3(box3d_get_corner_screen(box, 3)); NR::Point xdir(persp3d_get_PL_dir_from_pt(persp, c3, Proj::X)); @@ -1074,7 +1091,7 @@ box3d_swap_sides(int z_orders[6], Box3D::Axis axis) { bool box3d_recompute_z_orders (SPBox3D *box) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); //g_return_val_if_fail(persp, false); if (!persp) @@ -1281,7 +1298,7 @@ box3d_set_z_orders (SPBox3D *box) { // 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) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); // the two corners NR::Point c1(box3d_get_corner_screen(box, id1)); @@ -1315,7 +1332,7 @@ box3d_pt_lies_in_PL_sector (SPBox3D const *box, NR::Point const &pt, int id1, in int box3d_VP_lies_in_PL_sector (SPBox3D const *box, Proj::Axis vpdir, int id1, int id2, Box3D::Axis axis) { - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); if (!persp3d_VP_is_finite(persp, vpdir)) { return 0; @@ -1345,10 +1362,44 @@ box3d_relabel_corners(SPBox3D *box) { box3d_swap_coords(box, Proj::Z, true); } +void +box3d_add_to_selection(SPBox3D *box) { + Persp3D *persp = box3d_get_perspective(box); + g_return_if_fail(persp); + persp3d_add_box_transform(persp, box); +} + +void +box3d_remove_from_selection(SPBox3D *box) { + Persp3D *persp = box3d_get_perspective(box); + 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; + } + persp3d_remove_box_transform(persp, box); +} + +void +box3d_mark_transformed(SPBox3D *box) { + Persp3D *persp = box3d_get_perspective(box); + g_return_if_fail(persp); + persp3d_set_box_transformed(persp, box, true); +} + +Persp3D * +box3d_get_perspective(SPBox3D const *box) { + return box->persp_ref->getObject(); +} + void box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp) { persp3d_remove_box (old_persp, box); persp3d_add_box (new_persp, box); + + persp3d_remove_box_transform (old_persp, box); + persp3d_add_box_transform (new_persp, box); + gchar *href = g_strdup_printf("#%s", SP_OBJECT_REPR(new_persp)->attribute("id")); SP_OBJECT_REPR(box)->setAttribute("inkscape:perspectiveID", href); g_free(href); diff --git a/src/box3d.h b/src/box3d.h index 78ee45077..d34ac1ae0 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -70,6 +70,11 @@ int box3d_VP_lies_in_PL_sector (SPBox3D const *box, Proj::Axis vpdir, int id1, i /* ensures that the coordinates of corner0 and corner7 are in the correct order (to prevent everted boxes) */ void box3d_relabel_corners(SPBox3D *box); +void box3d_add_to_selection(SPBox3D *box); +void box3d_remove_from_selection(SPBox3D *box); +void box3d_mark_transformed(SPBox3D *box); + +Persp3D *box3d_get_perspective(SPBox3D const *box); void box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp); #endif /* __SP_BOX3D_H__ */ diff --git a/src/persp3d.cpp b/src/persp3d.cpp index cb7b31803..68c27c8e2 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -94,6 +94,7 @@ persp3d_init(Persp3D *persp) persp->tmat = Proj::TransfMat3x4 (); //persp->boxes = NULL; + persp->boxes_transformed.clear(); persp->document = NULL; persp->my_counter = global_counter++; @@ -401,6 +402,75 @@ persp3d_has_box (Persp3D *persp, SPBox3D *box) { return false; } +void +persp3d_add_box_transform (Persp3D *persp, SPBox3D *box) { + std::map::iterator i = persp->boxes_transformed.find(box); + if (i != persp->boxes_transformed.end() && (*i).second == true) { + g_print ("Warning! In %s (%d): trying to add transform status for box %d twice when it's already listed as true.\n", + SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter, + box->my_counter, persp->boxes_transformed[box]); + return; + } + + persp->boxes_transformed[box] = false; +} + +void +persp3d_remove_box_transform (Persp3D *persp, SPBox3D *box) { + persp->boxes_transformed.erase(box); +} + +void +persp3d_set_box_transformed (Persp3D *persp, SPBox3D *box, bool transformed) { + if (persp->boxes_transformed.find(box) == persp->boxes_transformed.end()) { + g_print ("Warning! In %s (%d): trying to set transform status for box %d, but it is not listed in the perspective!! Aborting.\n", + SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter, + box->my_counter); + return; + } + + persp->boxes_transformed[box] = transformed; +} + +bool +persp3d_was_transformed (Persp3D *persp) { + if (persp->boxes_transformed.size() == 1) { + /* either the transform has not been applied to the single box associated to this perspective yet + or the transform was already reset; in both cases we need to return false because upcoming + transforms need to be applied */ + (*persp->boxes_transformed.begin()).second = false; // make sure the box is marked as untransformed (in case more boxes are added later) + return false; + } + + for (std::map::iterator i = persp->boxes_transformed.begin(); + i != persp->boxes_transformed.end(); ++i) { + if ((*i).second == true) { + // at least one of the boxes in the perspective has already been transformed; + return true; + } + } + return false; // all boxes in the perspective are still untransformed; a pending transformation should be applied +} + +bool +persp3d_all_transformed(Persp3D *persp) { + for (std::map::iterator i = persp->boxes_transformed.begin(); + i != persp->boxes_transformed.end(); ++i) { + if ((*i).second == false) { + return false; + } + } + return true; +} + +void +persp3d_unset_transforms(Persp3D *persp) { + for (std::map::iterator i = persp->boxes_transformed.begin(); + i != persp->boxes_transformed.end(); ++i) { + (*i).second = false; + } +} + void persp3d_update_box_displays (Persp3D *persp) { if (persp->boxes.empty()) @@ -498,7 +568,7 @@ persp3d_currently_selected_persps (SPEventContext *ec) { std::set p; for (GSList *i = (GSList *) selection->itemList(); i != NULL; i = i->next) { if (SP_IS_BOX3D (i->data)) { - p.insert(SP_BOX3D(i->data)->persp_ref->getObject()); + p.insert(box3d_get_perspective(SP_BOX3D(i->data))); } } return p; @@ -546,7 +616,7 @@ persp3d_print_debugging_info (Persp3D *persp) { g_print (" Boxes: "); for (std::vector::iterator i = persp->boxes.begin(); i != persp->boxes.end(); ++i) { - g_print ("%d (%d)", (*i)->my_counter, (*i)->persp_ref->getObject()->my_counter); + g_print ("%d (%d) ", (*i)->my_counter, box3d_get_perspective(*i)->my_counter); } g_print ("\n"); g_print ("========================\n"); @@ -562,8 +632,34 @@ persp3d_print_debugging_info_all(SPDocument *document) { persp3d_print_debugging_info(SP_PERSP3D(child)); } } + persp3d_print_all_selected(); } +void +persp3d_print_all_selected() { + /** + if (persp3d->boxes_transformed.empty()) { + g_print ("No selected perspectives in document\n"); + return; + } + **/ + g_print ("\n======================================\n"); + g_print ("Selected perspectives and their boxes:\n"); + + std::set sel_persps = persp3d_currently_selected_persps (inkscape_active_event_context()); + + for (std::set::iterator j = sel_persps.begin(); j != sel_persps.end(); ++j) { + Persp3D *persp = SP_PERSP3D(*j); + g_print (" %s (%d): ", SP_OBJECT_REPR(persp)->attribute("id"), persp->my_counter); + for (std::map::iterator i = persp->boxes_transformed.begin(); + i != persp->boxes_transformed.end(); ++i) { + g_print ("<%d,%d> ", (*i).first->my_counter, (*i).second); + } + g_print ("\n"); + } + g_print ("======================================\n\n"); + } + /* Local Variables: mode:c++ diff --git a/src/persp3d.h b/src/persp3d.h index 696c0cdad..c74af2e29 100644 --- a/src/persp3d.h +++ b/src/persp3d.h @@ -20,6 +20,7 @@ #include #include +#include #include "sp-item.h" #include "transf_mat_3x4.h" @@ -32,6 +33,7 @@ struct Persp3D : public SPObject { // TODO: Also write the list of boxes into the xml repr and vice versa link boxes to their persp3d? std::vector boxes; + std::map boxes_transformed; // TODO: eventually we should merge this with 'boxes' SPDocument *document; // FIXME: should this rather be the SPDesktop? // for debugging only @@ -64,6 +66,14 @@ gchar * persp3d_pt_to_str (Persp3D *persp, Proj::Axis const axis); void persp3d_add_box (Persp3D *persp, SPBox3D *box); void persp3d_remove_box (Persp3D *persp, SPBox3D *box); bool persp3d_has_box (Persp3D *persp, SPBox3D *box); + +void persp3d_add_box_transform (Persp3D *persp, SPBox3D *box); +void persp3d_remove_box_transform (Persp3D *persp, SPBox3D *box); +void persp3d_set_box_transformed (Persp3D *persp, SPBox3D *box, bool transformed = true); +bool persp3d_was_transformed (Persp3D *persp); +bool persp3d_all_transformed(Persp3D *persp); +void persp3d_unset_transforms(Persp3D *persp); + void persp3d_update_box_displays (Persp3D *persp); void persp3d_update_box_reprs (Persp3D *persp); void persp3d_update_z_orders (Persp3D *persp); @@ -81,6 +91,7 @@ std::list persp3d_selected_boxes (Persp3D *persp); void persp3d_print_debugging_info (Persp3D *persp); void persp3d_print_debugging_info_all(SPDocument *doc); +void persp3d_print_all_selected(); #endif /* __PERSP3D_H__ */ diff --git a/src/selection.cpp b/src/selection.cpp index 68a9a2cd9..d3b667a12 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -29,6 +29,7 @@ #include "sp-shape.h" #include "sp-path.h" #include "sp-item-group.h" +#include "box3d.h" #include @@ -166,6 +167,11 @@ void Selection::_add(SPObject *obj) { _objs = g_slist_prepend(_objs, obj); + if (SP_IS_BOX3D(obj)) { + // keep track of selected boxes for transformations + box3d_add_to_selection(SP_BOX3D(obj)); + } + _release_connections[obj] = obj->connectRelease(sigc::mem_fun(*this, (void (Selection::*)(SPObject *))&Selection::remove)); _modified_connections[obj] = obj->connectModified(sigc::mem_fun(*this, &Selection::_schedule_modified)); } @@ -200,6 +206,11 @@ void Selection::_remove(SPObject *obj) { _release_connections[obj].disconnect(); _release_connections.erase(obj); + if (SP_IS_BOX3D(obj)) { + // keep track of selected boxes for transformations + box3d_remove_from_selection(SP_BOX3D(obj)); + } + _objs = g_slist_remove(_objs, obj); } diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 403162d0e..8bedaec5d 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -611,7 +611,7 @@ VPDrag::updateDraggers () VanishingPoint vp; for (int i = 0; i < 3; ++i) { - vp.set (box->persp_ref->getObject(), Proj::axes[i]); + vp.set(box3d_get_perspective(box), Proj::axes[i]); addDragger (vp); } } @@ -709,8 +709,8 @@ VPDrag::drawLinesForFace (const SPBox3D *box, Proj::Axis axis) //, guint corner1 NR::Point corner1, corner2, corner3, corner4; box3d_corners_for_PLs (box, axis, corner1, corner2, corner3, corner4); - g_return_if_fail (box->persp_ref->getObject()); - Proj::Pt2 vp = persp3d_get_VP (box->persp_ref->getObject(), axis); + g_return_if_fail (box3d_get_perspective(box)); + Proj::Pt2 vp = persp3d_get_VP (box3d_get_perspective(box), axis); if (vp.is_finite()) { // draw perspective lines for finite VPs NR::Point pt = vp.affine(); @@ -727,7 +727,7 @@ VPDrag::drawLinesForFace (const SPBox3D *box, Proj::Axis axis) //, guint corner1 } else { // draw perspective lines for infinite VPs NR::Maybe pt1, pt2, pt3, pt4; - Persp3D *persp = box->persp_ref->getObject(); + Persp3D *persp = box3d_get_perspective(box); SPDesktop *desktop = inkscape_active_desktop (); // FIXME: Store the desktop in VPDrag Box3D::PerspectiveLine pl (corner1, axis, persp); pt1 = pl.intersection_with_viewbox(desktop); -- 2.30.2