~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/live_effects/lpe-angle_bisector.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define INKSCAPE_LPE_ANGLE_BISECTOR_CPP
 
2
/** \file
 
3
 * LPE <angle_bisector> implementation, used as an example for a base starting class
 
4
 * when implementing new LivePathEffects.
 
5
 *
 
6
 * In vi, three global search-and-replaces will let you rename everything
 
7
 * in this and the .h file:
 
8
 *
 
9
 *   :%s/ANGLE_BISECTOR/YOURNAME/g
 
10
 *   :%s/AngleBisector/Yourname/g
 
11
 *   :%s/angle_bisector/yourname/g
 
12
 */
 
13
/*
 
14
 * Authors:
 
15
 *   Johan Engelen
 
16
 *
 
17
 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
 
18
 *
 
19
 * Released under GNU GPL, read the file 'COPYING' for more information
 
20
 */
 
21
 
 
22
#include "live_effects/lpe-angle_bisector.h"
 
23
 
 
24
// You might need to include other 2geom files. You can add them here:
 
25
#include <2geom/path.h>
 
26
#include <2geom/sbasis-to-bezier.h>
 
27
 
 
28
namespace Inkscape {
 
29
namespace LivePathEffect {
 
30
 
 
31
namespace AB {
 
32
 
 
33
class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
 
34
{
 
35
public:
 
36
    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 
37
    virtual Geom::Point knot_get();
 
38
};
 
39
 
 
40
class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
 
41
{
 
42
public:
 
43
    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 
44
    virtual Geom::Point knot_get();
 
45
};
 
46
 
 
47
} // namespace TtC
 
48
 
 
49
LPEAngleBisector::LPEAngleBisector(LivePathEffectObject *lpeobject) :
 
50
    Effect(lpeobject),
 
51
    length_left(_("Length left"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 0),
 
52
    length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 250)
 
53
{
 
54
    show_orig_path = true;
 
55
 
 
56
    registerParameter( dynamic_cast<Parameter *>(&length_left) );
 
57
    registerParameter( dynamic_cast<Parameter *>(&length_right) );
 
58
 
 
59
    registerKnotHolderHandle(new AB::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the bisector"));
 
60
    registerKnotHolderHandle(new AB::KnotHolderEntityRightEnd(), _("Adjust the \"right\" of the bisector"));
 
61
}
 
62
 
 
63
LPEAngleBisector::~LPEAngleBisector()
 
64
{
 
65
}
 
66
 
 
67
std::vector<Geom::Path>
 
68
LPEAngleBisector::doEffect_path (std::vector<Geom::Path> const & path_in)
 
69
{
 
70
    using namespace Geom;
 
71
 
 
72
    std::vector<Geom::Path> path_out;
 
73
 
 
74
    // we assume that the path has >= 3 nodes
 
75
    ptA = path_in[0].pointAt(1);
 
76
    Point B = path_in[0].initialPoint();
 
77
    Point C = path_in[0].pointAt(2);
 
78
 
 
79
    double angle = angle_between(B - ptA, C - ptA);
 
80
 
 
81
    dir = unit_vector(B - ptA) * Rotate(angle/2);
 
82
 
 
83
    Geom::Point D = ptA - dir * length_left;
 
84
    Geom::Point E = ptA + dir * length_right;
 
85
 
 
86
    Piecewise<D2<SBasis> > output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(D[X], E[X]), Linear(D[Y], E[Y])));
 
87
 
 
88
    return path_from_piecewise(output, LPE_CONVERSION_TOLERANCE);
 
89
}
 
90
namespace AB {
 
91
 
 
92
// TODO: make this more generic
 
93
static LPEAngleBisector *
 
94
get_effect(SPItem *item)
 
95
{
 
96
    Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
 
97
    if (effect->effectType() != ANGLE_BISECTOR) {
 
98
        g_print ("Warning: Effect is not of type LPEAngleBisector!\n");
 
99
        return NULL;
 
100
    }
 
101
    return static_cast<LPEAngleBisector *>(effect);
 
102
}
 
103
 
 
104
void
 
105
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
 
106
{
 
107
    LPEAngleBisector *lpe = get_effect(item);
 
108
    
 
109
    Geom::Point const s = snap_knot_position(p);
 
110
 
 
111
    double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
 
112
    lpe->length_left.param_set_value(-lambda);
 
113
 
 
114
    sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
 
115
}
 
116
 
 
117
void
 
118
KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
 
119
{
 
120
    LPEAngleBisector *lpe = get_effect(item);
 
121
    
 
122
    Geom::Point const s = snap_knot_position(p);
 
123
 
 
124
    double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
 
125
    lpe->length_right.param_set_value(lambda);
 
126
 
 
127
    sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
 
128
}
 
129
 
 
130
Geom::Point
 
131
KnotHolderEntityLeftEnd::knot_get()
 
132
{
 
133
    LPEAngleBisector *lpe = get_effect(item);
 
134
    return lpe->ptA - lpe->dir * lpe->length_left;
 
135
}
 
136
 
 
137
Geom::Point
 
138
KnotHolderEntityRightEnd::knot_get()
 
139
{
 
140
    LPEAngleBisector *lpe = get_effect(item);
 
141
    return lpe->ptA + lpe->dir * lpe->length_right;
 
142
}
 
143
 
 
144
} // namespace AB
 
145
 
 
146
/* ######################## */
 
147
 
 
148
} //namespace LivePathEffect
 
149
} /* namespace Inkscape */
 
150
 
 
151
/*
 
152
  Local Variables:
 
153
  mode:c++
 
154
  c-file-style:"stroustrup"
 
155
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
156
  indent-tabs-mode:nil
 
157
  fill-column:99
 
158
  End:
 
159
*/
 
160
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :