X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fvanishing-point.cpp;h=d8e27debd009161902a462a1148e3a518aa6e3de;hb=a401603e1e2635fadeec3b7a3a48de442da93472;hp=dcf8d6e71ee0f99bf95671c4f2c7d663da0f8660;hpb=41cb516a78b9e54daf81ca4a7e7fc55164c03dfa;p=inkscape.git diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index dcf8d6e71..d8e27debd 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -21,8 +21,9 @@ #include "event-context.h" #include "xml/repr.h" #include "perspective-line.h" - -#include "knotholder.h" // FIXME: can we avoid direct access to KnotHolder::update_knots? +#include "shape-editor.h" +#include "snap.h" +#include "sp-namedview.h" namespace Box3D { @@ -77,12 +78,12 @@ have_VPs_of_same_perspective (VPDragger *dr1, VPDragger *dr2) } static void -vp_knot_moved_handler (SPKnot */*knot*/, NR::Point const *ppointer, guint state, gpointer data) +vp_knot_moved_handler (SPKnot *knot, Geom::Point const *ppointer, guint state, gpointer data) { VPDragger *dragger = (VPDragger *) data; VPDrag *drag = dragger->parent; - NR::Point p = *ppointer; + Geom::Point p = *ppointer; // FIXME: take from prefs double snap_dist = SNAP_DIST / inkscape_active_desktop()->current_zoom(); @@ -104,7 +105,7 @@ vp_knot_moved_handler (SPKnot */*knot*/, NR::Point const *ppointer, guint state, sel_boxes = (*vp)->selectedBoxes(sp_desktop_selection(inkscape_active_desktop())); // we create a new perspective ... - Persp3D *new_persp = persp3d_create_xml_element (dragger->parent->document, old_persp); + Persp3D *new_persp = persp3d_create_xml_element (dragger->parent->document, old_persp->perspective_impl); /* ... unlink the boxes from the old one and FIXME: We need to unlink the _un_selected boxes of each VP so that @@ -130,7 +131,7 @@ vp_knot_moved_handler (SPKnot */*knot*/, NR::Point const *ppointer, guint state, // without Shift; see if we need to snap to another dragger for (GList *di = dragger->parent->draggers; di != NULL; di = di->next) { VPDragger *d_new = (VPDragger *) di->data; - if ((d_new != dragger) && (NR::L2 (d_new->point - p) < snap_dist)) { + if ((d_new != dragger) && (Geom::L2 (d_new->point - p) < snap_dist)) { if (have_VPs_of_same_perspective (dragger, d_new)) { // this would result in degenerate boxes, which we disallow for the time being continue; @@ -171,10 +172,20 @@ vp_knot_moved_handler (SPKnot */*knot*/, NR::Point const *ppointer, guint state, return; } } - } + // We didn't snap to another dragger, so we'll try a regular snap + SPDesktop *desktop = inkscape_active_desktop(); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); + m.unSetup(); + if (s.getSnapped()) { + p = s.getPoint(); + sp_knot_moveto(knot, p); + } + } - dragger->point = p; // FIXME: Brauchen wir dragger->point überhaupt? + dragger->point = p; // FIXME: Is dragger->point being used at all? dragger->updateVPs(p); dragger->updateBoxDisplays(); @@ -231,7 +242,7 @@ unsigned int VanishingPoint::global_counter = 0; void VanishingPoint::set_pos(Proj::Pt2 const &pt) { g_return_if_fail (_persp); - _persp->tmat.set_image_pt (_axis, pt); + _persp->perspective_impl->tmat.set_image_pt (_axis, pt); } std::list @@ -248,7 +259,7 @@ VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { return sel_boxes; } -VPDragger::VPDragger(VPDrag *parent, NR::Point p, VanishingPoint &vp) +VPDragger::VPDragger(VPDrag *parent, Geom::Point p, VanishingPoint &vp) { this->parent = parent; @@ -440,7 +451,7 @@ VPDragger::updateBoxDisplays () } void -VPDragger::updateVPs (NR::Point const &pt) +VPDragger::updateVPs (Geom::Point const &pt) { for (std::list::iterator i = this->vps.begin(); i != this->vps.end(); ++i) { (*i).set_pos (pt); @@ -457,7 +468,7 @@ VPDragger::updateZOrders () void VPDragger::printVPs() { - g_print ("VPDragger at position (%f, %f):\n", point[NR::X], point[NR::Y]); + g_print ("VPDragger at position (%f, %f):\n", point[Geom::X], point[Geom::Y]); for (std::list::iterator i = this->vps.begin(); i != this->vps.end(); ++i) { g_print (" VP %s\n", (*i).axisString()); } @@ -614,8 +625,8 @@ VPDrag::updateBoxHandles () SPEventContext *ec = inkscape_active_event_context(); g_assert (ec != NULL); - if (ec->shape_knot_holder != NULL) { - ec->shape_knot_holder->update_knots(); + if (ec->shape_editor != NULL) { + ec->shape_editor->update_knotholder(); } } @@ -657,14 +668,14 @@ VPDrag::drawLinesForFace (const SPBox3D *box, Proj::Axis axis) //, guint corner1 default: g_assert_not_reached(); } - NR::Point corner1, corner2, corner3, corner4; + Geom::Point corner1, corner2, corner3, corner4; box3d_corners_for_PLs (box, axis, corner1, corner2, corner3, corner4); 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(); + Geom::Point pt = vp.affine(); if (this->front_or_rear_lines & 0x1) { // draw 'front' perspective lines this->addLine (corner1, pt, color); @@ -677,7 +688,7 @@ VPDrag::drawLinesForFace (const SPBox3D *box, Proj::Axis axis) //, guint corner1 } } else { // draw perspective lines for infinite VPs - NR::Maybe pt1, pt2, pt3, pt4; + boost::optional pt1, pt2, pt3, pt4; Persp3D *persp = box3d_get_perspective(box); SPDesktop *desktop = inkscape_active_desktop (); // FIXME: Store the desktop in VPDrag Box3D::PerspectiveLine pl (corner1, axis, persp); @@ -721,11 +732,11 @@ VPDrag::addDragger (VanishingPoint &vp) // don't create draggers for infinite vanishing points return; } - NR::Point p = vp.get_pos(); + Geom::Point p = vp.get_pos(); for (GList *i = this->draggers; i != NULL; i = i->next) { VPDragger *dragger = (VPDragger *) i->data; - if (NR::L2 (dragger->point - p) < MERGE_DIST) { + if (Geom::L2 (dragger->point - p) < MERGE_DIST) { // distance is small, merge this draggable into dragger, no need to create new dragger dragger->addVP (vp); return; @@ -755,7 +766,7 @@ VPDrag::swap_perspectives_of_VPs(Persp3D *persp2, Persp3D *persp1) Create a line from p1 to p2 and add it to the lines list */ void -VPDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba) +VPDrag::addLine (Geom::Point p1, Geom::Point p2, guint32 rgba) { SPCanvasItem *line = sp_canvas_item_new(sp_desktop_controls(inkscape_active_desktop()), SP_TYPE_CTRLLINE, NULL); sp_ctrlline_set_coords(SP_CTRLLINE(line), p1, p2); @@ -776,4 +787,4 @@ VPDrag::addLine (NR::Point p1, NR::Point p2, guint32 rgba) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :