summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2012-04-07 14:09:58 +0000
committerJohan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl>2012-04-07 14:09:58 +0000
commit7867b2ae755a4217c14365e3b1b18484ba98712b (patch)
treeb5ee8094b54c44d0357bcada0699d06726739aa0
parentpowerstrokepointarray : add todo comment. do not derive from LPEKnotHolderEnt... (diff)
downloadinkscape-7867b2ae755a4217c14365e3b1b18484ba98712b.tar.gz
inkscape-7867b2ae755a4217c14365e3b1b18484ba98712b.zip
cleanup knotholder code for LPEs
(bzr r11170)
-rw-r--r--src/knot-holder-entity.h11
-rw-r--r--src/live_effects/effect.cpp29
-rw-r--r--src/live_effects/effect.h5
-rw-r--r--src/live_effects/lpe-angle_bisector.cpp72
-rw-r--r--src/live_effects/lpe-angle_bisector.h11
-rw-r--r--src/live_effects/lpe-copy_rotate.cpp62
-rw-r--r--src/live_effects/lpe-copy_rotate.h1
-rw-r--r--src/live_effects/lpe-knot.cpp43
-rw-r--r--src/live_effects/lpe-knot.h5
-rw-r--r--src/live_effects/lpe-parallel.cpp59
-rw-r--r--src/live_effects/lpe-parallel.h1
-rw-r--r--src/live_effects/lpe-perp_bisector.cpp47
-rw-r--r--src/live_effects/lpe-perp_bisector.h1
-rw-r--r--src/live_effects/lpe-perspective_path.cpp38
-rw-r--r--src/live_effects/lpe-perspective_path.h1
-rw-r--r--src/live_effects/lpe-skeleton.cpp25
-rw-r--r--src/live_effects/lpe-skeleton.h13
-rw-r--r--src/live_effects/lpe-tangent_to_curve.cpp66
-rw-r--r--src/live_effects/lpe-tangent_to_curve.h1
19 files changed, 266 insertions, 225 deletions
diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h
index 5422e6d1b..f1513779a 100644
--- a/src/knot-holder-entity.h
+++ b/src/knot-holder-entity.h
@@ -25,6 +25,12 @@ struct SPKnot;
class SPDesktop;
class KnotHolder;
+namespace Inkscape {
+namespace LivePathEffect {
+ class Effect;
+}
+}
+
typedef void (* SPKnotHolderSetFunc) (SPItem *item, Geom::Point const &p, Geom::Point const &origin, guint state);
typedef Geom::Point (* SPKnotHolderGetFunc) (SPItem *item);
/* fixme: Think how to make callbacks most sensitive (Lauris) */
@@ -83,6 +89,11 @@ public:
// derived KnotHolderEntity class for LPEs
class LPEKnotHolderEntity : public KnotHolderEntity {
+public:
+ LPEKnotHolderEntity(Inkscape::LivePathEffect::Effect *effect) : _effect(effect) {};
+protected:
+ Inkscape::LivePathEffect::Effect *_effect;
+private:
virtual bool isDeletable() { return false; }
};
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 0b1fe1160..44e57addf 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -282,7 +282,8 @@ Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item)
}
Effect::Effect(LivePathEffectObject *lpeobject)
- : oncanvasedit_it(0),
+ : _provides_knotholder_entities(false),
+ oncanvasedit_it(0),
is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true),
show_orig_path(false),
lpeobj(lpeobject),
@@ -468,12 +469,6 @@ Effect::registerParameter(Parameter * param)
param_vector.push_back(param);
}
-// TODO: should we provide a way to alter the handle's appearance?
-void
-Effect::registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr)
-{
- kh_entity_vector.push_back(std::make_pair(entity, descr));
-}
/**
* Add all registered LPE knotholder handles to the knotholder
@@ -491,23 +486,6 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
}
}
-void
-Effect::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
- // TODO: The entities in kh_entity_vector are already instantiated during the call
- // to registerKnotHolderHandle(), but they are recreated here. Also, we must not
- // delete them when the knotholder is destroyed, whence the clumsy function
- // isDeletable(). If we could create entities of different classes dynamically,
- // this would be much nicer. How to do this?
- std::vector<std::pair<KnotHolderEntity*, const char*> >::iterator i;
- for (i = kh_entity_vector.begin(); i != kh_entity_vector.end(); ++i) {
- KnotHolderEntity *entity = i->first;
- const char *descr = i->second;
-
- entity->create(desktop, item, knotholder, descr);
- knotholder->add(entity);
- }
-}
-
/**
* Return a vector of PathVectors which contain all helperpaths that should be drawn by the effect.
* This is the function called by external code like SPLPEItem.
@@ -688,8 +666,9 @@ bool
Effect::providesKnotholder()
{
// does the effect actively provide any knotholder entities of its own?
- if (kh_entity_vector.size() > 0)
+ if (_provides_knotholder_entities) {
return true;
+ }
// otherwise: are there any parameters that have knotholderentities?
for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) {
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 50d4c142b..008de5ea8 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -124,15 +124,14 @@ protected:
doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
void registerParameter(Parameter * param);
- void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr);
Parameter * getNextOncanvasEditableParam();
- void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
+ virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPDesktop * /*desktop*/, SPItem * /*item*/) {};
virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
std::vector<Parameter *> param_vector;
- std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
+ bool _provides_knotholder_entities;
int oncanvasedit_it;
BoolParam is_visible;
diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp
index aee4f48a1..99110c51e 100644
--- a/src/live_effects/lpe-angle_bisector.cpp
+++ b/src/live_effects/lpe-angle_bisector.cpp
@@ -1,47 +1,38 @@
#define INKSCAPE_LPE_ANGLE_BISECTOR_CPP
-/** \file
- * LPE <angle_bisector> implementation, used as an example for a base starting class
- * when implementing new LivePathEffects.
- *
- * In vi, three global search-and-replaces will let you rename everything
- * in this and the .h file:
- *
- * :%s/ANGLE_BISECTOR/YOURNAME/g
- * :%s/AngleBisector/Yourname/g
- * :%s/angle_bisector/yourname/g
- */
/*
* Authors:
- * Johan Engelen
+ * Maximilian Albert <maximilian.albert@gmail.com>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Authors 2007-2012
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/lpe-angle_bisector.h"
-// You might need to include other 2geom files. You can add them here:
#include <2geom/path.h>
#include <2geom/sbasis-to-bezier.h>
#include "sp-lpe-item.h"
+#include "knot-holder-entity.h"
+#include "knotholder.h"
namespace Inkscape {
namespace LivePathEffect {
namespace AB {
-class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityLeftEnd(LPEAngleBisector* effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityRightEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityRightEnd(LPEAngleBisector* effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -54,12 +45,10 @@ LPEAngleBisector::LPEAngleBisector(LivePathEffectObject *lpeobject) :
length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 250)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
registerParameter( dynamic_cast<Parameter *>(&length_left) );
registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(new AB::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the bisector"));
- registerKnotHolderHandle(new AB::KnotHolderEntityRightEnd(), _("Adjust the \"right\" of the bisector"));
}
LPEAngleBisector::~LPEAngleBisector()
@@ -89,25 +78,32 @@ LPEAngleBisector::doEffect_path (std::vector<Geom::Path> const & path_in)
return path_from_piecewise(output, LPE_CONVERSION_TOLERANCE);
}
-namespace AB {
-// TODO: make this more generic
-static LPEAngleBisector *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != ANGLE_BISECTOR) {
- g_print ("Warning: Effect is not of type LPEAngleBisector!\n");
- return NULL;
+void
+LPEAngleBisector::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new AB::KnotHolderEntityLeftEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"left\" end of the bisector")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
}
- return static_cast<LPEAngleBisector *>(effect);
-}
+ {
+ KnotHolderEntity *e = new AB::KnotHolderEntityRightEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"right\" of the bisector")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
+namespace AB {
void
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
- LPEAngleBisector *lpe = get_effect(item);
-
+ LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
@@ -119,8 +115,8 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori
void
KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
- LPEAngleBisector *lpe = get_effect(item);
-
+ LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir);
@@ -132,14 +128,14 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
Geom::Point
KnotHolderEntityLeftEnd::knot_get()
{
- LPEAngleBisector *lpe = get_effect(item);
+ LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect);
return lpe->ptA - lpe->dir * lpe->length_left;
}
Geom::Point
KnotHolderEntityRightEnd::knot_get()
{
- LPEAngleBisector *lpe = get_effect(item);
+ LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect);
return lpe->ptA + lpe->dir * lpe->length_right;
}
diff --git a/src/live_effects/lpe-angle_bisector.h b/src/live_effects/lpe-angle_bisector.h
index 0fd4c112f..95048751e 100644
--- a/src/live_effects/lpe-angle_bisector.h
+++ b/src/live_effects/lpe-angle_bisector.h
@@ -1,22 +1,18 @@
#ifndef INKSCAPE_LPE_ANGLE_BISECTOR_H
#define INKSCAPE_LPE_ANGLE_BISECTOR_H
-/** \file
- * LPE <angle_bisector> implementation, see lpe-angle_bisector.cpp.
- */
-
/*
* Authors:
- * Johan Engelen
+ * Maximilian Albert <maximilian.albert@gmail.com>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Authors 2007-2012
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/effect.h"
#include "live_effects/parameter/parameter.h"
-#include "live_effects/parameter/point.h"
namespace Inkscape {
namespace LivePathEffect {
@@ -36,6 +32,7 @@ public:
friend class AB::KnotHolderEntityLeftEnd;
friend class AB::KnotHolderEntityRightEnd;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
//private:
ScalarParam length_left;
diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp
index e77d80994..c61f4c3c1 100644
--- a/src/live_effects/lpe-copy_rotate.cpp
+++ b/src/live_effects/lpe-copy_rotate.cpp
@@ -4,10 +4,10 @@
*/
/*
* Authors:
- * Maximilian Albert
+ * Maximilian Albert <maximilian.albert@gmail.com>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
- * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ * Copyright (C) Authors 2007-2012
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -21,21 +21,24 @@
#include <2geom/d2-sbasis.h>
#include <2geom/angle.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
namespace CR {
-class KnotHolderEntityStartingAngle : public LPEKnotHolderEntity
-{
+class KnotHolderEntityStartingAngle : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityStartingAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity
-{
+class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -51,6 +54,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) :
dist_angle_handle(100)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
// register all your parameters here, so Inkscape knows which parameters this effect has:
registerParameter( dynamic_cast<Parameter *>(&starting_angle) );
@@ -58,12 +62,8 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) :
registerParameter( dynamic_cast<Parameter *>(&num_copies) );
registerParameter( dynamic_cast<Parameter *>(&origin) );
- registerKnotHolderHandle(new CR::KnotHolderEntityStartingAngle(), _("Adjust the starting angle"));
- registerKnotHolderHandle(new CR::KnotHolderEntityRotationAngle(), _("Adjust the rotation angle"));
-
num_copies.param_make_integer(true);
num_copies.param_set_range(0, 1000);
-
}
LPECopyRotate::~LPECopyRotate()
@@ -127,26 +127,32 @@ LPECopyRotate::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::Pat
hp_vec.push_back(pathv);
}
+void
+LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the starting angle")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+ {
+ KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the rotation angle")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
namespace CR {
using namespace Geom;
-// TODO: make this more generic
-static LPECopyRotate *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != COPY_ROTATE) {
- g_print ("Warning: Effect is not of type LPECopyRotate!\n");
- return NULL;
- }
- return static_cast<LPECopyRotate *>(effect);
-}
-
void
KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
- LPECopyRotate* lpe = get_effect(item);
+ LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -166,7 +172,7 @@ KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const
void
KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
- LPECopyRotate* lpe = get_effect(item);
+ LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -186,19 +192,21 @@ KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const
Geom::Point
KnotHolderEntityStartingAngle::knot_get()
{
- LPECopyRotate* lpe = get_effect(item);
+ LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
return snap_knot_position(lpe->start_pos);
}
Geom::Point
KnotHolderEntityRotationAngle::knot_get()
{
- LPECopyRotate* lpe = get_effect(item);
+ LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
return snap_knot_position(lpe->rot_pos);
}
} // namespace CR
+
+
/* ######################## */
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h
index 8cabdfb48..b14bc4128 100644
--- a/src/live_effects/lpe-copy_rotate.h
+++ b/src/live_effects/lpe-copy_rotate.h
@@ -38,6 +38,7 @@ public:
/* the knotholder entity classes must be declared friends */
friend class CR::KnotHolderEntityStartingAngle;
friend class CR::KnotHolderEntityRotationAngle;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
protected:
virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp
index d8c13a515..7a66b80c9 100644
--- a/src/live_effects/lpe-knot.cpp
+++ b/src/live_effects/lpe-knot.cpp
@@ -5,8 +5,9 @@
/* Authors:
* Jean-Francois Barraud <jf.barraud@gmail.com>
* Abhishek Sharma
+ * Johan Engelen
*
- * Copyright (C) 2007 Authors
+ * Copyright (C) 2007-2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -18,6 +19,7 @@
#include "svg/svg.h"
#include "style.h"
#include "knot-holder-entity.h"
+#include "knotholder.h"
#include <2geom/sbasis-to-bezier.h>
#include <2geom/sbasis.h>
@@ -38,11 +40,9 @@
namespace Inkscape {
namespace LivePathEffect {
-class KnotHolderEntityCrossingSwitcher : public LPEKnotHolderEntity
-{
+class KnotHolderEntityCrossingSwitcher : public LPEKnotHolderEntity {
public:
- virtual ~KnotHolderEntityCrossingSwitcher() {}
-
+ KnotHolderEntityCrossingSwitcher(LPEKnot *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
virtual void knot_click(guint state);
@@ -357,10 +357,11 @@ LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) :
registerParameter( dynamic_cast<Parameter *>(&switcher_size) );
registerParameter( dynamic_cast<Parameter *>(&crossing_points_vector) );
- registerKnotHolderHandle(new KnotHolderEntityCrossingSwitcher(), _("Drag to select a crossing, click to flip it"));
crossing_points = LPEKnotNS::CrossingPoints();
selectedCrossing = 0;
switcher = Geom::Point(0,0);
+
+ _provides_knotholder_entities = true;
}
LPEKnot::~LPEKnot()
@@ -582,18 +583,6 @@ LPEKnot::doBeforeEffect (SPLPEItem *lpeitem)
updateSwitcher();
}
-
-static LPEKnot *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != KNOT) {
- g_print ("Warning: Effect is not of type LPEKnot!\n");
- return NULL;
- }
- return static_cast<LPEKnot *>(effect);
-}
-
void
LPEKnot::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
{
@@ -618,9 +607,21 @@ LPEKnot::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVecto
}
void
+LPEKnot::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new KnotHolderEntityCrossingSwitcher(this);
+ e->create( desktop, item, knotholder,
+ _("Drag to select a crossing, click to flip it")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
+
+void
KnotHolderEntityCrossingSwitcher::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
- LPEKnot* lpe = get_effect(item);
+ LPEKnot* lpe = dynamic_cast<LPEKnot *>(_effect);
lpe->selectedCrossing = idx_of_nearest(lpe->crossing_points,p);
lpe->updateSwitcher();
@@ -631,14 +632,14 @@ KnotHolderEntityCrossingSwitcher::knot_set(Geom::Point const &p, Geom::Point con
Geom::Point
KnotHolderEntityCrossingSwitcher::knot_get()
{
- LPEKnot* lpe = get_effect(item);
+ LPEKnot* lpe = dynamic_cast<LPEKnot *>(_effect);
return snap_knot_position(lpe->switcher);
}
void
KnotHolderEntityCrossingSwitcher::knot_click(guint state)
{
- LPEKnot* lpe = get_effect(item);
+ LPEKnot* lpe = dynamic_cast<LPEKnot *>(_effect);
unsigned s = lpe->selectedCrossing;
if (s < lpe->crossing_points.size()){
if (state & GDK_SHIFT_MASK){
diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h
index e3dcb0b7f..14c61a4e5 100644
--- a/src/live_effects/lpe-knot.h
+++ b/src/live_effects/lpe-knot.h
@@ -3,9 +3,9 @@
*/
/* Authors:
* Jean-Francois Barraud <jf.barraud@gmail.com>
- * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) Johan Engelen 2007
+ * Copyright (C) Authors 2007-2012
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -61,6 +61,7 @@ public:
/* the knotholder entity classes must be declared friends */
friend class KnotHolderEntityCrossingSwitcher;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
protected:
virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp
index 5b373442b..4d15bf13e 100644
--- a/src/live_effects/lpe-parallel.cpp
+++ b/src/live_effects/lpe-parallel.cpp
@@ -6,7 +6,7 @@
* Authors:
* Maximilian Albert
*
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Johan Engelen 2007-2012 <j.b.c.engelen@alumnus.utwente.nl>
* Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
*
* Released under GNU GPL, read the file 'COPYING' for more information
@@ -19,21 +19,24 @@
#include <2geom/path.h>
#include <2geom/transforms.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
namespace Pl {
-class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityLeftEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityRightEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityRightEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -48,13 +51,11 @@ LPEParallel::LPEParallel(LivePathEffectObject *lpeobject) :
length_right(_("Length right"), _("Specifies the right end of the parallel"), "length-right", &wr, this, 150)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
registerParameter(dynamic_cast<Parameter *>(&offset_pt));
registerParameter( dynamic_cast<Parameter *>(&length_left) );
registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(new Pl::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the parallel"));
- registerKnotHolderHandle(new Pl::KnotHolderEntityRightEnd(), _("Adjust the \"right\" end of the parallel"));
}
LPEParallel::~LPEParallel()
@@ -93,27 +94,33 @@ LPEParallel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd
return output + dir;
}
-namespace Pl {
-
-// TODO: make this more generic
-static LPEParallel *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != PARALLEL) {
- g_print ("Warning: Effect is not of type LPEParallel!\n");
- return NULL;
+void
+LPEParallel::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new Pl::KnotHolderEntityLeftEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"left\" end of the parallel")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
}
- return static_cast<LPEParallel *>(effect);
-}
+ {
+ KnotHolderEntity *e = new Pl::KnotHolderEntityRightEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"right\" end of the parallel")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
+namespace Pl {
void
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
using namespace Geom;
- LPEParallel *lpe = get_effect(item);
-
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
@@ -127,8 +134,8 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
{
using namespace Geom;
- LPEParallel *lpe = get_effect(item);
-
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
@@ -140,14 +147,14 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
Geom::Point
KnotHolderEntityLeftEnd::knot_get()
{
- LPEParallel *lpe = get_effect(item);
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
return lpe->C;
}
Geom::Point
KnotHolderEntityRightEnd::knot_get()
{
- LPEParallel *lpe = get_effect(item);
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
return lpe->D;
}
diff --git a/src/live_effects/lpe-parallel.h b/src/live_effects/lpe-parallel.h
index 6dc426aa8..e23361675 100644
--- a/src/live_effects/lpe-parallel.h
+++ b/src/live_effects/lpe-parallel.h
@@ -39,6 +39,7 @@ public:
/* the knotholder entity classes must be declared friends */
friend class Pl::KnotHolderEntityLeftEnd;
friend class Pl::KnotHolderEntityRightEnd;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
private:
PointParam offset_pt;
diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp
index ac720b88b..ddf16cc9a 100644
--- a/src/live_effects/lpe-perp_bisector.cpp
+++ b/src/live_effects/lpe-perp_bisector.cpp
@@ -20,55 +20,48 @@
#include "sp-lpe-item.h"
#include <2geom/path.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
namespace PB {
class KnotHolderEntityEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityEnd(LPEPerpBisector *effect) : LPEKnotHolderEntity(effect) {};
void bisector_end_set(Geom::Point const &p, bool left = true);
};
class KnotHolderEntityLeftEnd : public KnotHolderEntityEnd {
public:
+ KnotHolderEntityLeftEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
class KnotHolderEntityRightEnd : public KnotHolderEntityEnd {
public:
+ KnotHolderEntityRightEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-// TODO: Make this more generic
-static LPEPerpBisector *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != PERP_BISECTOR) {
- g_print ("Warning: Effect is not of type LPEPerpBisector!\n");
- return NULL;
- }
- return static_cast<LPEPerpBisector *>(effect);
-}
-
Geom::Point
KnotHolderEntityLeftEnd::knot_get() {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe = get_effect(item);
+ LPEPerpBisector *lpe = dynamic_cast<LPEPerpBisector *>(_effect);
return Geom::Point(lpe->C);
}
Geom::Point
KnotHolderEntityRightEnd::knot_get() {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe = get_effect(item);
+ LPEPerpBisector *lpe = dynamic_cast<LPEPerpBisector *>(_effect);
return Geom::Point(lpe->D);
}
void
KnotHolderEntityEnd::bisector_end_set(Geom::Point const &p, bool left) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
+ LPEPerpBisector *lpe = dynamic_cast<LPEPerpBisector *>(_effect);
if (!lpe) return;
Geom::Point const s = snap_knot_position(p);
@@ -105,13 +98,11 @@ LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
A(0,0), B(0,0), M(0,0), C(0,0), D(0,0), perp_dir(0,0)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
// register all your parameters here, so Inkscape knows which parameters this effect has:
registerParameter( dynamic_cast<Parameter *>(&length_left) );
registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(new PB::KnotHolderEntityLeftEnd(), _("Adjust the bisector's \"left\" end"));
- registerKnotHolderHandle(new PB::KnotHolderEntityRightEnd(), _("Adjust the bisector's \"right\" end"));
}
LPEPerpBisector::~LPEPerpBisector()
@@ -159,6 +150,24 @@ LPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
return output;
}
+void
+LPEPerpBisector::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new PB::KnotHolderEntityLeftEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the bisector's \"left\" end")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+ {
+ KnotHolderEntity *e = new PB::KnotHolderEntityRightEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the bisector's \"right\" end")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
/* ######################## */
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-perp_bisector.h b/src/live_effects/lpe-perp_bisector.h
index baa440822..823717e62 100644
--- a/src/live_effects/lpe-perp_bisector.h
+++ b/src/live_effects/lpe-perp_bisector.h
@@ -47,6 +47,7 @@ public:
friend class PB::KnotHolderEntityLeftEnd;
friend class PB::KnotHolderEntityRightEnd;
friend void PB::bisector_end_set(SPItem *item, Geom::Point const &p, bool left = true);
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
private:
ScalarParam length_left;
diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp
index 9208d4aeb..d9df32076 100644
--- a/src/live_effects/lpe-perspective_path.cpp
+++ b/src/live_effects/lpe-perspective_path.cpp
@@ -4,9 +4,9 @@
*/
/* Authors:
* Maximilian Albert <maximilian.albert@gmail.com>
- * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) 2007-2008 Authors
+ * Copyright (C) 2007-2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -18,6 +18,7 @@
#include "live_effects/lpe-perspective_path.h"
#include "sp-item-group.h"
#include "knot-holder-entity.h"
+#include "knotholder.h"
#include "inkscape.h"
@@ -31,6 +32,7 @@ namespace PP {
class KnotHolderEntityOffset : public LPEKnotHolderEntity
{
public:
+ KnotHolderEntityOffset(LPEPerspectivePath *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -53,14 +55,11 @@ LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) :
registerParameter( dynamic_cast<Parameter *>(&offsety) );
registerParameter( dynamic_cast<Parameter *>(&uses_plane_xy) );
- registerKnotHolderHandle(new PP::KnotHolderEntityOffset(), _("Adjust the origin"));
-
concatenate_before_pwd2 = true; // don't split the path into its subpaths
+ _provides_knotholder_entities = true;
Persp3D *persp = persp3d_document_first_persp(inkscape_active_document());
-
Proj::TransfMat3x4 pmat = persp->perspective_impl->tmat;
-
pmat.copy_tmat(tmat);
}
@@ -138,26 +137,25 @@ LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > cons
return output;
}
-namespace PP {
-
-// TODO: make this more generic
-static LPEPerspectivePath *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != PERSPECTIVE_PATH) {
- g_print ("Warning: Effect is not of type LPEPerspectivePath!\n");
- return NULL;
+void
+LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new PP::KnotHolderEntityOffset(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the origin")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
}
- return static_cast<LPEPerspectivePath *>(effect);
-}
+};
+
+namespace PP {
void
KnotHolderEntityOffset::knot_set(Geom::Point const &p, Geom::Point const &origin, guint /*state*/)
{
using namespace Geom;
- LPEPerspectivePath* lpe = get_effect(item);
+ LPEPerspectivePath* lpe = dynamic_cast<LPEPerspectivePath *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -171,7 +169,7 @@ KnotHolderEntityOffset::knot_set(Geom::Point const &p, Geom::Point const &origin
Geom::Point
KnotHolderEntityOffset::knot_get()
{
- LPEPerspectivePath* lpe = get_effect(item);
+ LPEPerspectivePath* lpe = dynamic_cast<LPEPerspectivePath *>(_effect);
return lpe->orig + Geom::Point(lpe->offsetx, -lpe->offsety);
}
diff --git a/src/live_effects/lpe-perspective_path.h b/src/live_effects/lpe-perspective_path.h
index ad4d307c1..14321f52e 100644
--- a/src/live_effects/lpe-perspective_path.h
+++ b/src/live_effects/lpe-perspective_path.h
@@ -40,6 +40,7 @@ public:
/* the knotholder entity classes must be declared friends */
friend class PP::KnotHolderEntityOffset;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
private:
// add the parameters for your effect here:
diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp
index 08f31da7e..f3d7788d6 100644
--- a/src/live_effects/lpe-skeleton.cpp
+++ b/src/live_effects/lpe-skeleton.cpp
@@ -11,9 +11,9 @@
* :%s/skeleton/yourname/g
*/
/* Authors:
- * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) 2007 Authors
+ * Copyright (C) 2007-2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -23,6 +23,9 @@
// You might need to include other 2geom files. You can add them here:
#include <2geom/path.h>
+//#include "knot-holder-entity.h"
+//#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
@@ -33,12 +36,11 @@ LPESkeleton::LPESkeleton(LivePathEffectObject *lpeobject) :
{
/* uncomment the following line to have the original path displayed while the item is selected */
//show_orig_path = true;
+ /* uncomment the following line to enable display of the effect-specific on-canvas handles (knotholder entities) */
+ //_provides_knotholder_entities
/* register all your parameters here, so Inkscape knows which parameters this effect has: */
registerParameter( dynamic_cast<Parameter *>(&number) );
-
- /* register all your knotholder handles here: */
- //registerKnotHolderHandle(new Skeleton::KnotHolderEntityAttachMyHandle(), _("help message"));
}
LPESkeleton::~LPESkeleton()
@@ -80,7 +82,7 @@ LPESkeleton::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd
}
/* ########################
- * Define the classes for your knotholder handles here
+ * If you want to provide effect-specific on-canvas handles (knotholder entities), define them here:
*/
/*
@@ -96,6 +98,17 @@ public:
};
} // namespace Skeleton
+
+void
+LPESkeleton::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntityMyHandle *e = new KnotHolderEntityMyHandle(this);
+ e->create( desktop, item, knotholder,
+ _("Text describing what this handle does"),
+ //optional: knot_shape, knot_mode, knot_color);
+ knotholder->add(e);
+ }
+};
*/
/* ######################## */
diff --git a/src/live_effects/lpe-skeleton.h b/src/live_effects/lpe-skeleton.h
index 104ef3489..124d1a4cb 100644
--- a/src/live_effects/lpe-skeleton.h
+++ b/src/live_effects/lpe-skeleton.h
@@ -2,9 +2,9 @@
* @brief Minimal LPE effect, see lpe-skeleton.cpp.
*/
/* Authors:
- * Johan Engelen <j.b.c.engelen@utwente.nl>
+ * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
*
- * Copyright (C) 2007 Authors
+ * Copyright (C) 2007-2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -18,8 +18,10 @@
namespace Inkscape {
namespace LivePathEffect {
-// each knotholder handle for your LPE requires a separate class derived from KnotHolderEntity;
-// define it in lpe-skeleton.cpp and register it in the effect's constructor
+// each knotholder handle for your LPE requires a separate class derived from LPEKnotHolderEntity;
+// define it in lpe-skeleton.cpp and add code to create it in addKnotHolderEntities
+// note that the LPE parameter classes implement their own handles! So in most cases, you will
+// not have to do anything like this.
/**
namespace Skeleton {
// we need a separate namespace to avoid clashes with other LPEs
@@ -37,8 +39,9 @@ public:
// virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
- /* the knotholder entity classes (if any) must be declared friends */
+ /* the knotholder entity classes (if any) can be declared friends */
//friend class Skeleton::KnotHolderEntityMyHandle;
+ //virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
private:
// add the parameters for your effect here:
diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp
index a2d3cd061..04cc3335f 100644
--- a/src/live_effects/lpe-tangent_to_curve.cpp
+++ b/src/live_effects/lpe-tangent_to_curve.cpp
@@ -23,21 +23,24 @@
#include <2geom/path.h>
#include <2geom/transforms.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
namespace TtC {
-class KnotHolderEntityAttachPt : public LPEKnotHolderEntity
-{
+class KnotHolderEntityAttachPt : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityAttachPt(LPETangentToCurve *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityLeftEnd(LPETangentToCurve *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -45,6 +48,7 @@ public:
class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
{
public:
+ KnotHolderEntityRightEnd(LPETangentToCurve *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -59,15 +63,12 @@ LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) :
length_right(_("Length right"), _("Specifies the right end of the tangent"), "length-right", &wr, this, 150)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
registerParameter( dynamic_cast<Parameter *>(&angle) );
registerParameter( dynamic_cast<Parameter *>(&t_attach) );
registerParameter( dynamic_cast<Parameter *>(&length_left) );
registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(new TtC::KnotHolderEntityAttachPt(), _("Adjust the point of attachment of the tangent"));
- registerKnotHolderHandle(new TtC::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the tangent"));
- registerKnotHolderHandle(new TtC::KnotHolderEntityRightEnd(), _("Adjust the \"right\" end of the tangent"));
}
LPETangentToCurve::~LPETangentToCurve()
@@ -95,26 +96,39 @@ LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const
return output;
}
-namespace TtC {
-
-// TODO: make this more generic
-static LPETangentToCurve *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != TANGENT_TO_CURVE) {
- g_print ("Warning: Effect is not of type LPETangentToCurve!\n");
- return NULL;
+void
+LPETangentToCurve::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new TtC::KnotHolderEntityAttachPt(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the point of attachment of the tangent")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
}
- return static_cast<LPETangentToCurve *>(effect);
-}
+ {
+ KnotHolderEntity *e = new TtC::KnotHolderEntityLeftEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"left\" end of the tangent")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+ {
+ KnotHolderEntity *e = new TtC::KnotHolderEntityRightEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"right\" end of the tangent")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
+namespace TtC {
void
KnotHolderEntityAttachPt::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
using namespace Geom;
- LPETangentToCurve* lpe = get_effect(item);
+ LPETangentToCurve* lpe = dynamic_cast<LPETangentToCurve *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -136,7 +150,7 @@ KnotHolderEntityAttachPt::knot_set(Geom::Point const &p, Geom::Point const &/*or
void
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
- LPETangentToCurve *lpe = get_effect(item);
+ LPETangentToCurve *lpe = dynamic_cast<LPETangentToCurve *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -149,7 +163,7 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori
void
KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
- LPETangentToCurve *lpe = get_effect(item);
+ LPETangentToCurve *lpe = dynamic_cast<LPETangentToCurve *>(_effect);
Geom::Point const s = snap_knot_position(p);
@@ -162,21 +176,21 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
Geom::Point
KnotHolderEntityAttachPt::knot_get()
{
- LPETangentToCurve* lpe = get_effect(item);
+ LPETangentToCurve* lpe = dynamic_cast<LPETangentToCurve *>(_effect);
return lpe->ptA;
}
Geom::Point
KnotHolderEntityLeftEnd::knot_get()
{
- LPETangentToCurve *lpe = get_effect(item);
+ LPETangentToCurve *lpe = dynamic_cast<LPETangentToCurve *>(_effect);
return lpe->C;
}
Geom::Point
KnotHolderEntityRightEnd::knot_get()
{
- LPETangentToCurve *lpe = get_effect(item);
+ LPETangentToCurve *lpe = dynamic_cast<LPETangentToCurve *>(_effect);
return lpe->D;
}
diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h
index 8fe54335c..309afc14b 100644
--- a/src/live_effects/lpe-tangent_to_curve.h
+++ b/src/live_effects/lpe-tangent_to_curve.h
@@ -42,6 +42,7 @@ public:
friend class TtC::KnotHolderEntityLeftEnd;
friend class TtC::KnotHolderEntityRightEnd;
friend class TtC::KnotHolderEntityAttachPt;
+ virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item);
private:
ScalarParam angle;