X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fknot-holder-entity.cpp;h=005ca24c71c1fbe2e1b8bbb8112c5c5401f4ed26;hb=8a2e76b7021b9b960d7c30801a1a14461d9b5939;hp=f6c82582bb412cd321c0aba63ff833e21cfa8338;hpb=e9b6af083e34e2397a8ddbe9781920733d09d151;p=inkscape.git diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index f6c82582b..005ca24c7 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -1,11 +1,10 @@ -#define __KNOT_HOLDER_ENTITY_C__ - -/** \file - * KnotHolderEntity definition. - * +/** \file + * KnotHolderEntity definition. + * * Authors: * Mitsuru Oka * Maximilian Albert + * Abhishek Sharma * * Copyright (C) 1999-2001 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. @@ -77,23 +76,45 @@ KnotHolderEntity::~KnotHolderEntity() void KnotHolderEntity::update_knot() { - Geom::Matrix const i2d(sp_item_i2d_affine(item)); + Geom::Matrix const i2d(item->i2d_affine()); Geom::Point dp(knot_get() * i2d); _moved_connection.block(); - sp_knot_set_position(knot, dp, SP_KNOT_STATE_NORMAL); + sp_knot_set_position(knot, dp, SP_KNOT_STATE_NORMAL); _moved_connection.unblock(); } Geom::Point KnotHolderEntity::snap_knot_position(Geom::Point const &p) { - Geom::Matrix const i2d (sp_item_i2d_affine(item)); + Geom::Matrix const i2d (item->i2d_affine()); + Geom::Point s = p * i2d; + + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop, true, item); + m.freeSnapReturnByRef(s, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.unSetup(); + + return s * i2d.inverse(); +} + +Geom::Point +KnotHolderEntity::snap_knot_position_constrained(Geom::Point const &p, Inkscape::Snapper::SnapConstraint const &constraint) +{ + Geom::Matrix const i2d (item->i2d_affine()); Geom::Point s = p * i2d; + SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true, item); - m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + // constrainedSnap() will first project the point p onto the constraint line and then try to snap along that line. + // This way the constraint is already enforced, no need to worry about that later on + Inkscape::Snapper::SnapConstraint transformed_constraint = Inkscape::Snapper::SnapConstraint(constraint.getPoint() * i2d, (constraint.getPoint() + constraint.getDirection()) * i2d - constraint.getPoint() * i2d); + m.constrainedSnapReturnByRef(s, Inkscape::SNAPSOURCE_NODE_HANDLE, transformed_constraint); + m.unSetup(); + return s * i2d.inverse(); } @@ -128,16 +149,16 @@ PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &ori Geom::Point p_snapped = snap_knot_position(p); if ( state & GDK_CONTROL_MASK ) { - if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) { - p_snapped[NR::Y] = origin[NR::Y]; + if (fabs((p - origin)[Geom::X]) > fabs((p - origin)[Geom::Y])) { + p_snapped[Geom::Y] = origin[Geom::Y]; } else { - p_snapped[NR::X] = origin[NR::X]; + p_snapped[Geom::X] = origin[Geom::X]; } } if (state) { Geom::Point const q = p_snapped - sp_pattern_extract_trans(pat); - sp_item_adjust_pattern(item, NR::Matrix(Geom::Translate(q))); + item->adjust_pattern(Geom::Matrix(Geom::Translate(q))); } item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -183,11 +204,11 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const & // get the scale from the current transform so we can keep it. Geom::Point scl = sp_pattern_extract_scale(pat); - NR::Matrix rot = NR::Matrix(Geom::Scale(scl)) * NR::Matrix(Geom::Rotate(theta)); + Geom::Matrix rot = Geom::Matrix(Geom::Scale(scl)) * Geom::Matrix(Geom::Rotate(theta)); Geom::Point const t = sp_pattern_extract_trans(pat); - rot[4] = t[NR::X]; - rot[5] = t[NR::Y]; - sp_item_adjust_pattern(item, rot, true); + rot[4] = t[Geom::X]; + rot[5] = t[Geom::Y]; + item->adjust_pattern(rot, true); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -213,15 +234,15 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const & scl = Geom::Scale(d.length() / pat_h); } else { d *= Geom::Rotate(-theta); - scl = Geom::Scale(d[NR::X] / pat_x, d[NR::Y] / pat_y); + scl = Geom::Scale(d[Geom::X] / pat_x, d[Geom::Y] / pat_y); } Geom::Matrix rot = (Geom::Matrix)scl * Geom::Rotate(theta); Geom::Point const t = sp_pattern_extract_trans(pat); - rot[4] = t[NR::X]; - rot[5] = t[NR::Y]; - sp_item_adjust_pattern(item, rot, true); + rot[4] = t[Geom::X]; + rot[5] = t[Geom::Y]; + item->adjust_pattern(rot, true); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } @@ -251,4 +272,4 @@ PatternKnotHolderEntityScale::knot_get() 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 :