Code

Mnemonics in "Input devices", and LPE dialogs (Bug 170765)
[inkscape.git] / src / live_effects / lpe-constructgrid.cpp
1 #define INKSCAPE_LPE_CONSTRUCTGRID_CPP
2 /** \file
3  * LPE Construct Grid implementation
4  */
5 /*
6  * Authors:
7  *   Johan Engelen
8 *
9 * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "live_effects/lpe-constructgrid.h"
16 #include <2geom/path.h>
17 #include <2geom/transforms.h>
19 namespace Inkscape {
20 namespace LivePathEffect {
22 using namespace Geom;
24 LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) :
25     Effect(lpeobject),
26     nr_x(_("Size _X:"), _("The size of the grid in X direction."), "nr_x", &wr, this, 5),
27     nr_y(_("Size _Y:"), _("The size of the grid in Y direction."), "nr_y", &wr, this, 5)
28 {
29     registerParameter( dynamic_cast<Parameter *>(&nr_x) );
30     registerParameter( dynamic_cast<Parameter *>(&nr_y) );
32     nr_x.param_make_integer();
33     nr_y.param_make_integer();
34     nr_x.param_set_range(1, 1e10);
35     nr_y.param_set_range(1, 1e10);
36 }
38 LPEConstructGrid::~LPEConstructGrid()
39 {
41 }
43 std::vector<Geom::Path>
44 LPEConstructGrid::doEffect_path (std::vector<Geom::Path> const & path_in)
45 {
46   // Check that the path has at least 3 nodes (i.e. 2 segments), more nodes are ignored
47     if (path_in[0].size() >= 2) {
48         // read the first 3 nodes:
49         Geom::Path::const_iterator it ( path_in[0].begin() );
50         Geom::Point first_p  = (*it++).initialPoint();
51         Geom::Point origin   = (*it++).initialPoint();
52         Geom::Point second_p = (*it++).initialPoint();
53         // make first_p and second_p be the construction *vectors* of the grid:
54         first_p  -= origin;
55         second_p -= origin;
56         Geom::Translate first_translation( first_p );
57         Geom::Translate second_translation( second_p );
59         // create the gridpaths of the two directions
60         Geom::Path first_path( origin );
61         first_path.appendNew<LineSegment>( origin + first_p*nr_y );
62         Geom::Path second_path( origin );
63         second_path.appendNew<LineSegment>( origin + second_p*nr_x );
65         // use the gridpaths and set them in the correct grid
66         std::vector<Geom::Path> path_out;
67         path_out.push_back(first_path);
68         for (int ix = 0; ix < nr_x; ix++) {
69             path_out.push_back(path_out.back() * second_translation );
70         }
71         path_out.push_back(second_path);
72         for (int iy = 0; iy < nr_y; iy++) {
73             path_out.push_back(path_out.back() * first_translation );
74         }
76         return path_out;
77     } else {
78         return path_in;
79     }
80 }
82 } //namespace LivePathEffect
83 } /* namespace Inkscape */
85 /*
86   Local Variables:
87   mode:c++
88   c-file-style:"stroustrup"
89   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
90   indent-tabs-mode:nil
91   fill-column:99
92   End:
93 */
94 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :