~centralelyon2010/inkscape/imagelinks2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/** \file
 * Implementation of sp_item_notify_moveto().
 */

#include <sp-item.h>
#include <2geom/transforms.h>
#include <sp-guide.h>
#include <sp-item-rm-unsatisfied-cns.h>
using std::vector;


/**
 * Called by sp_guide_moveto to indicate that the guide line corresponding to g has been moved, and
 * that consequently this item should move with it.
 *
 * \pre exist [cn in item.constraints] g eq cn.g.
 */
void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoint_ix,
                           double const position, bool const commit)
{
    g_return_if_fail(SP_IS_ITEM(&item));
    g_return_if_fail( unsigned(snappoint_ix) < 8 );
    Geom::Point const dir( mv_g.normal_to_line );
    double const dir_lensq(dot(dir, dir));
    g_return_if_fail( dir_lensq != 0 );

    std::vector<Inkscape::SnapCandidatePoint> snappoints;
    item.getSnappoints(snappoints, NULL);
    g_return_if_fail( snappoint_ix < int(snappoints.size()) );

    double const pos0 = dot(dir, snappoints[snappoint_ix].getPoint());
    /// \todo effic: skip if mv_g is already satisfied.

    /* Translate along dir to make dot(dir, snappoints(item)[snappoint_ix]) == position. */

    /* Calculation:
       dot(dir, snappoints[snappoint_ix] + s * dir) = position.
       dot(dir, snappoints[snappoint_ix]) + dot(dir, s * dir) = position.
       pos0 + s * dot(dir, dir) = position.
       s * lensq(dir) = position - pos0.
       s = (position - pos0) / dot(dir, dir). */
    Geom::Translate const tr( ( position - pos0 )
                            * ( dir / dir_lensq ) );
    item.set_i2d_affine(item.i2dt_affine() * tr);
    /// \todo Reget snappoints, check satisfied.

    if (commit) {
        /// \todo Consider maintaining a set of dirty items.

        /* Commit repr. */
        {
            item.doWriteTransform(item.getRepr(), item.transform);
        }

        sp_item_rm_unsatisfied_cns(item);
#if 0 /* nyi */
        move_cn_to_front(mv_g, snappoint_ix, item.constraints);
        /** \note If the guideline is connected to multiple snappoints of
         * this item, then keeping those cns in order requires that the
         * guide send notifications in order of increasing importance.
         */
#endif
    }
}


/*
  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:fileencoding=utf-8:textwidth=99 :