1 #define INKSCAPE_LPE_RULER_CPP
3 /** \file
4 * LPE <ruler> implementation, see lpe-ruler.cpp.
5 */
7 /*
8 * Authors:
9 * Maximilian Albert
10 * Johan Engelen
11 *
12 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #include "live_effects/lpe-ruler.h"
18 #include <2geom/piecewise.h>
20 namespace Inkscape {
21 namespace LivePathEffect {
23 LPERuler::LPERuler(LivePathEffectObject *lpeobject) :
24 Effect(lpeobject),
25 mark_distance(_("Mark distance"), _("Distance between ruler marks"), "mark_distance", &wr, this, 50),
26 mark_length(_("Mark length"), _("Length of ruler marks"), "mark_length", &wr, this, 10),
27 scale(_("Scale"), _("Scale factor for ruler distance"), "scale", &wr, this, 1.0)
28 {
29 registerParameter(dynamic_cast<Parameter *>(&mark_distance));
30 registerParameter(dynamic_cast<Parameter *>(&mark_length));
31 registerParameter(dynamic_cast<Parameter *>(&scale));
33 mark_distance.param_make_integer();
34 mark_length.param_make_integer();
35 }
37 LPERuler::~LPERuler()
38 {
40 }
42 Geom::Piecewise<Geom::D2<Geom::SBasis> >
43 LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
44 {
45 using namespace Geom;
47 Point A(pwd2_in.firstValue());
48 Point B(pwd2_in.lastValue());
50 Piecewise<D2<SBasis> >output(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
52 Point dir(unit_vector(B - A));
53 Point n(-rot90(dir) * mark_length);
54 double length = L2(B - A);
56 g_print ("Distance: %8.2f\n", length * scale);
58 Point C, D;
59 for (int i = 0; i < length; i += static_cast<int>(mark_distance)) {
60 C = A + dir * i;
61 D = C + n;
62 Piecewise<D2<SBasis> > seg(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
63 output.concat(seg);
64 }
66 return output;
67 }
69 /* ######################## */
71 } //namespace LivePathEffect
72 } /* namespace Inkscape */
74 /*
75 Local Variables:
76 mode:c++
77 c-file-style:"stroustrup"
78 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79 indent-tabs-mode:nil
80 fill-column:99
81 End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :