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