Code

3b9b07c82a1ab81d820a042766917b16530c6db7
[inkscape.git] / src / live_effects / lpe-path_length.cpp
1 #define INKSCAPE_LPE_PATH_LENGTH_CPP
2 /** \file
3  * LPE <path_length> implementation.
4  */
5 /*
6  * Authors:
7  *   Maximilian Albert <maximilian.albert@gmail.com>
8  *   Johan Engelen
9  *
10  * Copyright (C) 2007-2008 Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "live_effects/lpe-path_length.h"
16 #include "sp-metrics.h"
18 #include "2geom/sbasis-geometric.h"
20 namespace Inkscape {
21 namespace LivePathEffect {
23 LPEPathLength::LPEPathLength(LivePathEffectObject *lpeobject) :
24     Effect(lpeobject),
25     info_text(this),
26     unit(_("Unit"), _("Unit"), "unit", &wr, this)
27 {
28     registerParameter(dynamic_cast<Parameter *>(&info_text));
29     registerParameter(dynamic_cast<Parameter *>(&unit));
30 }
32 LPEPathLength::~LPEPathLength()
33 {
35 }
37 Geom::Piecewise<Geom::D2<Geom::SBasis> >
38 LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
39 {
40     using namespace Geom;
42     /* convert the measured length to the correct unit ... */
43     double lengthval = Geom::length(pwd2_in);
44     gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
46     /* ... set it as the canvas text ... */
47     gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? unit.get_abbreviation() : "px");
48     info_text.param_setValue(arc_length);
49     g_free(arc_length);
51     info_text.setPosAndAnchor(pwd2_in, 0.5, 10);
53     // TODO: how can we compute the area (such that cw turns don't count negative)?
54     //       should we display the area here, too, or write a new LPE for this?
55     Piecewise<D2<SBasis> > A = integral(pwd2_in);
56     Point c;
57     double area;
58     if (centroid(pwd2_in, c, area)) {
59         //g_print ("Area is zero\n");
60     }
61     //g_print ("Area: %f\n", area);
63     return pwd2_in;
64 }
66 } //namespace LivePathEffect
67 } /* namespace Inkscape */
69 /*
70   Local Variables:
71   mode:c++
72   c-file-style:"stroustrup"
73   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74   indent-tabs-mode:nil
75   fill-column:99
76   End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :