1 /** \file
2 * LPE knot effect implementation, see lpe-knot.cpp.
3 */
4 /* Authors:
5 * Jean-Francois Barraud <jf.barraud@gmail.com>
6 * Johan Engelen <j.b.c.engelen@utwente.nl>
7 *
8 * Copyright (C) Johan Engelen 2007
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #ifndef INKSCAPE_LPE_KNOT_H
14 #define INKSCAPE_LPE_KNOT_H
16 #include "live_effects/effect.h"
17 #include "live_effects/parameter/parameter.h"
18 #include "live_effects/parameter/array.h"
19 //#include "live_effects/parameter/path.h"
20 #include "live_effects/parameter/bool.h"
21 #include "2geom/crossing.h"
23 namespace Inkscape {
24 namespace LivePathEffect {
26 class KnotHolderEntityCrossingSwitcher;
28 // CrossingPoint, CrossingData:
29 // "point oriented" storage of crossing data (needed to find crossing nearest to a click, etc...)
30 //TODO: evaluate how lpeknot-specific that is? Should something like this exist in 2geom?
32 namespace LPEKnotNS {//just in case...
33 struct CrossingPoint {
34 Geom::Point pt;
35 int sign; //+/-1 = positive or neg crossing, 0 = flat.
36 unsigned i, j; //paths components meeting in this point.
37 unsigned ni, nj; //this crossing is the ni-th along i, nj-th along j.
38 };
40 class CrossingPoints : public std::vector<CrossingPoint>{
41 public:
42 CrossingPoints() : std::vector<CrossingPoint>() {}
43 CrossingPoints(Geom::CrossingSet const &cs, std::vector<Geom::Path> const &path);//for self crossings only!
44 //TODO: define a constructor for intersections of 2 different paths.
45 CrossingPoints(std::vector<double> const &input);
46 std::vector<double> to_vector();
47 CrossingPoint get(unsigned const i, unsigned const ni);
48 void inherit_signs(CrossingPoints const &from_other, int default_value = 1);
49 };
51 }
54 class LPEKnot : public Effect {
55 public:
56 LPEKnot(LivePathEffectObject *lpeobject);
57 virtual ~LPEKnot();
59 virtual void doOnApply (SPLPEItem *lpeitem);
60 virtual void doBeforeEffect (SPLPEItem *lpeitem);
61 virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & input_path);
63 /* the knotholder entity classes must be declared friends */
64 friend class KnotHolderEntityCrossingSwitcher;
66 protected:
67 virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
69 private:
70 void updateSwitcher();
71 // add the parameters for your effect here:
72 ScalarParam interruption_width;
73 BoolParam prop_to_stroke_width;
74 ScalarParam switcher_size;
75 double stroke_width;
76 ArrayParam<double> crossing_points_vector;
77 LPEKnotNS::CrossingPoints crossing_points;
80 LPEKnot(const LPEKnot&);
81 LPEKnot& operator=(const LPEKnot&);
82 unsigned selectedCrossing;
83 Geom::Point switcher;
85 };
87 } //namespace LivePathEffect
88 } //namespace Inkscape
90 #endif