Code

GSoC C++-ificiation merge and cleanup.
[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     scale(_("Scale"), _("Scaling factor"), "scale", &wr, this, 1.0),
26     info_text(this),
27     unit(_("Unit"), _("Unit"), "unit", &wr, this),
28     display_unit(_("Display unit"), _("Print unit after path length"), "display_unit", &wr, this, true)
29 {
30     registerParameter(dynamic_cast<Parameter *>(&scale));
31     registerParameter(dynamic_cast<Parameter *>(&info_text));
32     registerParameter(dynamic_cast<Parameter *>(&unit));
33     registerParameter(dynamic_cast<Parameter *>(&display_unit));
34 }
36 LPEPathLength::~LPEPathLength()
37 {
39 }
41 void
42 LPEPathLength::hideCanvasText() {
43     // this is only used in sp-lpe-item.cpp to hide the canvas text when the effect is invisible
44     info_text.param_setValue("");
45 }
47 Geom::Piecewise<Geom::D2<Geom::SBasis> >
48 LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
49 {
50     using namespace Geom;
52     /* convert the measured length to the correct unit ... */
53     double lengthval = Geom::length(pwd2_in) * scale;
54     gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
56     /* ... set it as the canvas text ... */
57     gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,
58                                         display_unit ? (success ? unit.get_abbreviation() : "px") : "");
59     info_text.param_setValue(arc_length);
60     g_free(arc_length);
62     info_text.setPosAndAnchor(pwd2_in, 0.5, 10);
64     // TODO: how can we compute the area (such that cw turns don't count negative)?
65     //       should we display the area here, too, or write a new LPE for this?
66     Piecewise<D2<SBasis> > A = integral(pwd2_in);
67     Point c;
68     double area;
69     if (centroid(pwd2_in, c, area)) {
70         //g_print ("Area is zero\n");
71     }
72     //g_print ("Area: %f\n", area);
74     return pwd2_in;
75 }
77 } //namespace LivePathEffect
78 } /* namespace Inkscape */
80 /*
81   Local Variables:
82   mode:c++
83   c-file-style:"stroustrup"
84   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
85   indent-tabs-mode:nil
86   fill-column:99
87   End:
88 */
89 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :