Code

5ecf2ffa29f74a74a276fe2b96cfd70b43092367
[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 bool
38 LPEPathLength::hideCanvasText() {
39     // this is only used in sp-lpe-item.cpp to hide the canvas text when the effect is invisible
40     info_text.param_setValue("");
41 }
43 Geom::Piecewise<Geom::D2<Geom::SBasis> >
44 LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
45 {
46     using namespace Geom;
48     /* convert the measured length to the correct unit ... */
49     double lengthval = Geom::length(pwd2_in);
50     gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
52     /* ... set it as the canvas text ... */
53     gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, success ? unit.get_abbreviation() : "px");
54     info_text.param_setValue(arc_length);
55     g_free(arc_length);
57     info_text.setPosAndAnchor(pwd2_in, 0.5, 10);
59     // TODO: how can we compute the area (such that cw turns don't count negative)?
60     //       should we display the area here, too, or write a new LPE for this?
61     Piecewise<D2<SBasis> > A = integral(pwd2_in);
62     Point c;
63     double area;
64     if (centroid(pwd2_in, c, area)) {
65         //g_print ("Area is zero\n");
66     }
67     //g_print ("Area: %f\n", area);
69     return pwd2_in;
70 }
72 } //namespace LivePathEffect
73 } /* namespace Inkscape */
75 /*
76   Local Variables:
77   mode:c++
78   c-file-style:"stroustrup"
79   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
80   indent-tabs-mode:nil
81   fill-column:99
82   End:
83 */
84 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :