summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorSebastian Wüst <sebi@timewaster.de>2013-10-20 15:32:08 +0000
committerSebastian Wüst <sebi@timewaster.de>2013-10-20 15:32:08 +0000
commit82908f949129e1fcbf62002799ee7b1b77986eed (patch)
treec02098dd7720cdf424f2793ecd3ddac2ea86b969 /src/live_effects
parentchanged text (diff)
parentFix build errors with clang 3.3 and c++11 enabled. (diff)
downloadinkscape-82908f949129e1fcbf62002799ee7b1b77986eed.tar.gz
inkscape-82908f949129e1fcbf62002799ee7b1b77986eed.zip
merge from trunk
(bzr r12417.1.24)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/effect.cpp2
-rw-r--r--src/live_effects/effect.h2
-rw-r--r--src/live_effects/lpe-copy_rotate.cpp2
-rw-r--r--src/live_effects/lpe-copy_rotate.h2
-rw-r--r--src/live_effects/lpe-knot.cpp2
-rw-r--r--src/live_effects/lpe-knot.h2
-rw-r--r--src/live_effects/lpe-path_length.cpp6
-rw-r--r--src/live_effects/lpe-rough-hatches.cpp6
-rw-r--r--src/live_effects/lpe-ruler.cpp8
-rw-r--r--src/live_effects/lpe-vonkoch.cpp2
-rw-r--r--src/live_effects/lpe-vonkoch.h2
-rw-r--r--src/live_effects/lpeobject.cpp157
-rw-r--r--src/live_effects/lpeobject.h33
-rw-r--r--src/live_effects/parameter/unit.cpp24
-rw-r--r--src/live_effects/parameter/unit.h15
-rw-r--r--src/live_effects/spiro.cpp242
16 files changed, 222 insertions, 285 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 105fdea32..623879ac5 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -270,7 +270,7 @@ void Effect::createAndApply(const char* name, SPDocument *doc, SPItem *item)
Inkscape::GC::release(repr);
gchar *href = g_strdup_printf("#%s", repr_id);
- sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true);
+ SP_LPE_ITEM(item)->addPathEffect(href, true);
g_free(href);
}
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index f7a7155b0..b9d86628f 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -66,7 +66,7 @@ public:
/*
* isReady() indicates whether all preparations which are necessary to apply the LPE are done,
* e.g., waiting for a parameter path either before the effect is created or when it needs a
- * path as argument. This is set in sp_lpe_item_add_path_effect().
+ * path as argument. This is set in SPLPEItem::addPathEffect().
*/
inline bool isReady() const { return is_ready; }
inline void setReady(bool ready = true) { is_ready = ready; }
diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp
index c1b72c3c7..65bbcdad1 100644
--- a/src/live_effects/lpe-copy_rotate.cpp
+++ b/src/live_effects/lpe-copy_rotate.cpp
@@ -115,7 +115,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & p
}
void
-LPECopyRotate::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
{
using namespace Geom;
diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h
index 1354b980a..ca7aa269c 100644
--- a/src/live_effects/lpe-copy_rotate.h
+++ b/src/live_effects/lpe-copy_rotate.h
@@ -41,7 +41,7 @@ public:
void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
protected:
- virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
private:
ScalarParam starting_angle;
diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp
index 27652bf0c..8fec69958 100644
--- a/src/live_effects/lpe-knot.cpp
+++ b/src/live_effects/lpe-knot.cpp
@@ -588,7 +588,7 @@ LPEKnot::doBeforeEffect (SPLPEItem const* lpeitem)
}
void
-LPEKnot::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+LPEKnot::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
{
using namespace Geom;
double r = switcher_size*.1;
diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h
index a25607981..b937f9021 100644
--- a/src/live_effects/lpe-knot.h
+++ b/src/live_effects/lpe-knot.h
@@ -64,7 +64,7 @@ public:
void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
protected:
- virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
private:
void updateSwitcher();
diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp
index d3edcda27..4ca380c15 100644
--- a/src/live_effects/lpe-path_length.cpp
+++ b/src/live_effects/lpe-path_length.cpp
@@ -14,7 +14,7 @@
#include <glibmm/i18n.h>
#include "live_effects/lpe-path_length.h"
-#include "sp-metrics.h"
+#include "util/units.h"
#include "2geom/sbasis-geometric.h"
@@ -52,11 +52,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & p
/* convert the measured length to the correct unit ... */
double lengthval = Geom::length(pwd2_in) * scale;
- gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit);
+ lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation());
/* ... set it as the canvas text ... */
gchar *arc_length = g_strdup_printf("%.2f %s", lengthval,
- display_unit ? (success ? unit.get_abbreviation() : "px") : "");
+ display_unit ? unit.get_abbreviation() : "");
info_text.param_setValue(arc_length);
g_free(arc_length);
diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp
index 0579b1016..6ffb913bd 100644
--- a/src/live_effects/lpe-rough-hatches.cpp
+++ b/src/live_effects/lpe-rough-hatches.cpp
@@ -239,10 +239,10 @@ LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) :
fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varying width"), "fat_output", &wr, this, true),
do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true),
stroke_width_top(_("Thickness: at 1st side:"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.),
- stroke_width_bot(_("at 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
+ stroke_width_bot(_("At 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.),
//
- front_thickness(_("from 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
- back_thickness(_("from 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
+ front_thickness(_("From 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.),
+ back_thickness(_("From 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25),
direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)),
//
diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp
index fefdad95a..788ab593a 100644
--- a/src/live_effects/lpe-ruler.cpp
+++ b/src/live_effects/lpe-ruler.cpp
@@ -81,9 +81,9 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const
using namespace Geom;
double real_mark_length = mark_length;
- sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px");
double real_minor_mark_length = minor_mark_length;
- sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px");
n_major = real_mark_length * n;
n_minor = real_minor_mark_length * n;
@@ -133,10 +133,10 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i
std::vector<double> s_cuts;
double real_mark_distance = mark_distance;
- sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px");
double real_offset = offset;
- sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX));
+ real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px");
for (double s = real_offset; s<totlength; s+=real_mark_distance){
s_cuts.push_back(s);
}
diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp
index f7b2beeba..c0050fa60 100644
--- a/src/live_effects/lpe-vonkoch.cpp
+++ b/src/live_effects/lpe-vonkoch.cpp
@@ -176,7 +176,7 @@ LPEVonKoch::doEffect_path (std::vector<Geom::Path> const & path_in)
//Usefull??
//void
-//LPEVonKoch::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+//LPEVonKoch::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
/*{
using namespace Geom;
if (draw_boxes.get_value()){
diff --git a/src/live_effects/lpe-vonkoch.h b/src/live_effects/lpe-vonkoch.h
index 2ea7c8169..7dff2be52 100644
--- a/src/live_effects/lpe-vonkoch.h
+++ b/src/live_effects/lpe-vonkoch.h
@@ -57,7 +57,7 @@ public:
//Usefull??
// protected:
- //virtual void addCanvasIndicators(SPLPEItem *lpeitem, std::vector<Geom::PathVector> &hp_vec);
+ //virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
private:
ScalarParam nbgenerations;
diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp
index 3e4e40198..d92c94d01 100644
--- a/src/live_effects/lpeobject.cpp
+++ b/src/live_effects/lpeobject.cpp
@@ -20,33 +20,18 @@
//#define LIVEPATHEFFECT_VERBOSE
-static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
+#include "sp-factory.h"
-static SPObjectClass *livepatheffect_parent_class;
-/**
- * Registers the LivePathEffect class with Gdk and returns its type number.
- */
-GType
-LivePathEffectObject::livepatheffect_get_type ()
-{
- static GType livepatheffect_type = 0;
-
- if (!livepatheffect_type) {
- GTypeInfo livepatheffect_info = {
- sizeof (LivePathEffectObjectClass),
- NULL, NULL,
- (GClassInitFunc) LivePathEffectObject::livepatheffect_class_init,
- NULL, NULL,
- sizeof (LivePathEffectObject),
- 16,
- (GInstanceInitFunc) LivePathEffectObject::livepatheffect_init,
- NULL,
- };
- livepatheffect_type = g_type_register_static (SP_TYPE_OBJECT, "LivePathEffectObject", &livepatheffect_info, (GTypeFlags)0);
- }
- return livepatheffect_type;
+namespace {
+ SPObject* createLivepatheffect() {
+ return new LivePathEffectObject();
+ }
+
+ bool livepatheffectRegistered = SPFactory::instance().registerObject("inkscape:path-effect", createLivepatheffect);
}
+static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
+
static Inkscape::XML::NodeEventVector const livepatheffect_repr_events = {
NULL, /* child_added */
NULL, /* child_removed */
@@ -56,57 +41,31 @@ static Inkscape::XML::NodeEventVector const livepatheffect_repr_events = {
};
-/**
- * Callback to initialize livepatheffect vtable.
- */
-void
-LivePathEffectObject::livepatheffect_class_init(LivePathEffectObjectClass *klass)
-{
- SPObjectClass *sp_object_class = (SPObjectClass *) klass;
-
- livepatheffect_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
-
- sp_object_class->build = livepatheffect_build;
- sp_object_class->release = livepatheffect_release;
-
- sp_object_class->set = livepatheffect_set;
- sp_object_class->write = livepatheffect_write;
-}
-
-/**
- * Callback to initialize livepatheffect object.
- */
-void
-LivePathEffectObject::livepatheffect_init(LivePathEffectObject *lpeobj)
+LivePathEffectObject::LivePathEffectObject()
+ : SPObject(), effecttype(Inkscape::LivePathEffect::INVALID_LPE), effecttype_set(false),
+ lpe(NULL)
{
#ifdef LIVEPATHEFFECT_VERBOSE
g_message("Init livepatheffectobject");
#endif
- lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE;
- lpeobj->lpe = NULL;
+}
- lpeobj->effecttype_set = false;
+LivePathEffectObject::~LivePathEffectObject() {
}
/**
* Virtual build: set livepatheffect attributes from its associated XML node.
*/
-void
-LivePathEffectObject::livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
-{
-#ifdef LIVEPATHEFFECT_VERBOSE
- g_message("Build livepatheffect");
-#endif
- g_assert(object != NULL);
- g_assert(SP_IS_OBJECT(object));
+void LivePathEffectObject::build(SPDocument *document, Inkscape::XML::Node *repr) {
+ g_assert(this != NULL);
+ g_assert(SP_IS_OBJECT(this));
- if (((SPObjectClass *) livepatheffect_parent_class)->build)
- (* ((SPObjectClass *) livepatheffect_parent_class)->build)(object, document, repr);
+ SPObject::build(document, repr);
- object->readAttr( "effect" );
+ this->readAttr( "effect" );
if (repr) {
- repr->addListener (&livepatheffect_repr_events, object);
+ repr->addListener (&livepatheffect_repr_events, this);
}
/* Register ourselves, is this necessary? */
@@ -116,17 +75,8 @@ LivePathEffectObject::livepatheffect_build(SPObject *object, SPDocument *documen
/**
* Virtual release of livepatheffect members before destruction.
*/
-void
-LivePathEffectObject::livepatheffect_release(SPObject *object)
-{
-#ifdef LIVEPATHEFFECT_VERBOSE
- g_print("Releasing livepatheffect");
-#endif
-
- LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object);
-
- object->getRepr()->removeListenerByData(object);
-
+void LivePathEffectObject::release() {
+ this->getRepr()->removeListenerByData(this);
/*
if (object->document) {
@@ -142,77 +92,64 @@ LivePathEffectObject::livepatheffect_release(SPObject *object)
}
gradient->modified_connection.~connection();
-
*/
- if (lpeobj->lpe) {
- delete lpeobj->lpe;
- lpeobj->lpe = NULL;
+ if (this->lpe) {
+ delete this->lpe;
+ this->lpe = NULL;
}
- lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE;
- if (((SPObjectClass *) livepatheffect_parent_class)->release)
- ((SPObjectClass *) livepatheffect_parent_class)->release(object);
+ this->effecttype = Inkscape::LivePathEffect::INVALID_LPE;
+
+ SPObject::release();
}
/**
* Virtual set: set attribute to value.
*/
-void
-LivePathEffectObject::livepatheffect_set(SPObject *object, unsigned key, gchar const *value)
-{
- LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object);
+void LivePathEffectObject::set(unsigned key, gchar const *value) {
#ifdef LIVEPATHEFFECT_VERBOSE
g_print("Set livepatheffect");
#endif
+
switch (key) {
case SP_PROP_PATH_EFFECT:
- if (lpeobj->lpe) {
- delete lpeobj->lpe;
- lpeobj->lpe = NULL;
+ if (this->lpe) {
+ delete this->lpe;
+ this->lpe = NULL;
}
if ( value && Inkscape::LivePathEffect::LPETypeConverter.is_valid_key(value) ) {
- lpeobj->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value);
- lpeobj->lpe = Inkscape::LivePathEffect::Effect::New(lpeobj->effecttype, lpeobj);
- lpeobj->effecttype_set = true;
+ this->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value);
+ this->lpe = Inkscape::LivePathEffect::Effect::New(this->effecttype, this);
+ this->effecttype_set = true;
} else {
- lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE;
- lpeobj->effecttype_set = false;
+ this->effecttype = Inkscape::LivePathEffect::INVALID_LPE;
+ this->effecttype_set = false;
}
- object->requestModified(SP_OBJECT_MODIFIED_FLAG);
+
+ this->requestModified(SP_OBJECT_MODIFIED_FLAG);
break;
}
- if (((SPObjectClass *) livepatheffect_parent_class)->set) {
- ((SPObjectClass *) livepatheffect_parent_class)->set(object, key, value);
- }
+ SPObject::set(key, value);
}
/**
* Virtual write: write object attributes to repr.
*/
-Inkscape::XML::Node *
-LivePathEffectObject::livepatheffect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
-{
-#ifdef LIVEPATHEFFECT_VERBOSE
- g_print("Write livepatheffect");
-#endif
-
- LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object);
-
+Inkscape::XML::Node* LivePathEffectObject::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
repr = xml_doc->createElement("inkscape:path-effect");
}
- if ((flags & SP_OBJECT_WRITE_ALL) || lpeobj->lpe) {
- repr->setAttribute("effect", Inkscape::LivePathEffect::LPETypeConverter.get_key(lpeobj->effecttype).c_str());
+ if ((flags & SP_OBJECT_WRITE_ALL) || this->lpe) {
+ repr->setAttribute("effect", Inkscape::LivePathEffect::LPETypeConverter.get_key(this->effecttype).c_str());
- lpeobj->lpe->writeParamsToSVG();
+ this->lpe->writeParamsToSVG();
}
- if (((SPObjectClass *) livepatheffect_parent_class)->write)
- (* ((SPObjectClass *) livepatheffect_parent_class)->write)(object, xml_doc, repr, flags);
+ SPObject::write(xml_doc, repr, flags);
return repr;
}
@@ -244,7 +181,7 @@ livepatheffect_on_repr_attr_changed ( Inkscape::XML::Node * /*repr*/,
/**
* If this has other users, create a new private duplicate and return it
* returns 'this' when no forking was necessary (and therefore no duplicate was made)
- * Check out sp_lpe_item_fork_path_effects_if_necessary !
+ * Check out SPLPEItem::forkPathEffectsIfNecessary !
*/
LivePathEffectObject *LivePathEffectObject::fork_private_if_necessary(unsigned int nr_of_allowed_users)
{
diff --git a/src/live_effects/lpeobject.h b/src/live_effects/lpeobject.h
index 2d04f8842..9700024fe 100644
--- a/src/live_effects/lpeobject.h
+++ b/src/live_effects/lpeobject.h
@@ -22,17 +22,14 @@ namespace Inkscape {
}
}
-#define TYPE_LIVEPATHEFFECT (LivePathEffectObject::livepatheffect_get_type())
-#define LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), TYPE_LIVEPATHEFFECT, LivePathEffectObject))
-#define IS_LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), TYPE_LIVEPATHEFFECT))
-
-/// The LivePathEffect vtable.
-struct LivePathEffectObjectClass {
- SPObjectClass parent_class;
-};
+#define LIVEPATHEFFECT(obj) ((LivePathEffectObject*)obj)
+#define IS_LIVEPATHEFFECT(obj) (dynamic_cast<const LivePathEffectObject*>((SPObject*)obj))
class LivePathEffectObject : public SPObject {
public:
+ LivePathEffectObject();
+ virtual ~LivePathEffectObject();
+
Inkscape::LivePathEffect::EffectType effecttype;
bool effecttype_set;
@@ -42,22 +39,18 @@ public:
/* Note that the returned pointer can be NULL in a valid LivePathEffectObject contained in a valid list of lpeobjects in an lpeitem!
* So one should always check whether the returned value is NULL or not */
Inkscape::LivePathEffect::Effect * get_lpe() { return lpe; };
+ Inkscape::LivePathEffect::Effect const * get_lpe() const { return lpe; };
-private:
Inkscape::LivePathEffect::Effect *lpe; // this can be NULL in a valid LivePathEffectObject
- /* C-style class functions: */
-public:
- static GType livepatheffect_get_type();
-private:
- static void livepatheffect_class_init(LivePathEffectObjectClass *klass);
- static void livepatheffect_init(LivePathEffectObject *stop);
- static void livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
- static void livepatheffect_release(SPObject *object);
- static void livepatheffect_set(SPObject *object, unsigned key, gchar const *value);
- static Inkscape::XML::Node *livepatheffect_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
-};
+protected:
+ virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
+ virtual void release();
+
+ virtual void set(unsigned int key, const gchar* value);
+ virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);
+};
#endif
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
index 602d806a0..0ee553e2c 100644
--- a/src/live_effects/parameter/unit.cpp
+++ b/src/live_effects/parameter/unit.cpp
@@ -10,6 +10,9 @@
#include "live_effects/parameter/unit.h"
#include "live_effects/effect.h"
#include "verbs.h"
+#include "util/units.h"
+
+using Inkscape::Util::unit_table;
namespace Inkscape {
@@ -18,10 +21,10 @@ namespace LivePathEffect {
UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, SPUnitId default_value)
+ Effect* effect, Glib::ustring default_unit)
: Parameter(label, tip, key, wr, effect)
{
- defunit = &sp_unit_get_by_id(default_value);;
+ defunit = unit_table.getUnit(default_unit);
unit = defunit;
}
@@ -32,9 +35,8 @@ UnitParam::~UnitParam()
bool
UnitParam::param_readSVGValue(const gchar * strvalue)
{
- SPUnit const *newval = sp_unit_get_by_abbreviation(strvalue);
- if (newval) {
- param_set_value(newval);
+ if (strvalue) {
+ param_set_value(*unit_table.getUnit(strvalue));
return true;
}
return false;
@@ -43,25 +45,25 @@ UnitParam::param_readSVGValue(const gchar * strvalue)
gchar *
UnitParam::param_getSVGValue() const
{
- return g_strdup(sp_unit_get_abbreviation(unit));
+ return g_strdup(unit->abbr.c_str());
}
void
UnitParam::param_set_default()
{
- param_set_value(defunit);
+ param_set_value(*defunit);
}
void
-UnitParam::param_set_value(SPUnit const *val)
+UnitParam::param_set_value(Inkscape::Util::Unit const &val)
{
- unit = val;
+ unit = new Inkscape::Util::Unit(val);
}
const gchar *
UnitParam::get_abbreviation() const
{
- return sp_unit_get_abbreviation(unit);
+ return unit->abbr.c_str();
}
Gtk::Widget *
@@ -74,7 +76,7 @@ UnitParam::param_newWidget()
param_effect->getRepr(),
param_effect->getSPDoc()));
- unit_menu->setUnit(unit);
+ unit_menu->setUnit(unit->abbr);
unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter"));
return dynamic_cast<Gtk::Widget *> (unit_menu);
diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h
index ea7a0112a..59a483018 100644
--- a/src/live_effects/parameter/unit.h
+++ b/src/live_effects/parameter/unit.h
@@ -10,10 +10,13 @@
*/
#include "live_effects/parameter/parameter.h"
-#include <helper/units.h>
namespace Inkscape {
+namespace Util {
+ class Unit;
+}
+
namespace LivePathEffect {
class UnitParam : public Parameter {
@@ -23,22 +26,22 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- SPUnitId default_value = SP_UNIT_PX);
+ Glib::ustring default_unit = "px");
virtual ~UnitParam();
virtual bool param_readSVGValue(const gchar * strvalue);
virtual gchar * param_getSVGValue() const;
virtual void param_set_default();
- void param_set_value(SPUnit const *val);
+ void param_set_value(Inkscape::Util::Unit const &val);
const gchar *get_abbreviation() const;
virtual Gtk::Widget * param_newWidget();
- operator SPUnit const *() const { return unit; }
+ operator Inkscape::Util::Unit const *() const { return unit; }
private:
- SPUnit const *unit;
- SPUnit const *defunit;
+ Inkscape::Util::Unit const *unit;
+ Inkscape::Util::Unit const *defunit;
UnitParam(const UnitParam&);
UnitParam& operator=(const UnitParam&);
diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp
index f50399a77..46e53a0da 100644
--- a/src/live_effects/spiro.cpp
+++ b/src/live_effects/spiro.cpp
@@ -677,163 +677,165 @@ add_mat_line(bandmat *m, double *v,
}
static double
-spiro_iter(spiro_seg *s, bandmat *m, int *perm, double *v, int n)
+spiro_iter(spiro_seg *s, bandmat *m, int *perm, double *v, const int n)
{
int cyclic = s[0].ty != '{' && s[0].ty != 'v';
- int i, j, jj;
int nmat = count_vec(s, n);
- double norm;
int n_invert;
- for (i = 0; i < nmat; i++) {
- v[i] = 0.;
- for (j = 0; j < 11; j++)
- m[i].a[j] = 0.;
- for (j = 0; j < 5; j++)
- m[i].al[j] = 0.;
+ for (int i = 0; i < nmat; i++) {
+ v[i] = 0.;
+ for (int j = 0; j < 11; j++) {
+ m[i].a[j] = 0.;
+ }
+ for (int j = 0; j < 5; j++) {
+ m[i].al[j] = 0.;
+ }
}
- j = 0;
- if (s[0].ty == 'o')
- jj = nmat - 2;
- else if (s[0].ty == 'c')
- jj = nmat - 1;
- else
- jj = 0;
- for (i = 0; i < n; i++) {
- char ty0 = s[i].ty;
- char ty1 = s[i + 1].ty;
- int jinc = compute_jinc(ty0, ty1);
- double th = s[i].bend_th;
- double ends[2][4];
- double derivs[4][2][4];
- int jthl = -1, jk0l = -1, jk1l = -1, jk2l = -1;
- int jthr = -1, jk0r = -1, jk1r = -1, jk2r = -1;
-
- compute_pderivs(&s[i], ends, derivs, jinc);
-
- /* constraints crossing left */
- if (ty0 == 'o' || ty0 == 'c' || ty0 == '[' || ty0 == ']') {
- jthl = jj++;
- jj %= nmat;
- jk0l = jj++;
- }
- if (ty0 == 'o') {
- jj %= nmat;
- jk1l = jj++;
- jk2l = jj++;
- }
+ int j = 0;
+ int jj;
+ if (s[0].ty == 'o') {
+ jj = nmat - 2;
+ } else if (s[0].ty == 'c') {
+ jj = nmat - 1;
+ } else {
+ jj = 0;
+ }
+ for (int i = 0; i < n; i++) {
+ char ty0 = s[i].ty;
+ char ty1 = s[i + 1].ty;
+ int jinc = compute_jinc(ty0, ty1);
+ double th = s[i].bend_th;
+ double ends[2][4];
+ double derivs[4][2][4];
+ int jthl = -1, jk0l = -1, jk1l = -1, jk2l = -1;
+ int jthr = -1, jk0r = -1, jk1r = -1, jk2r = -1;
+
+ compute_pderivs(&s[i], ends, derivs, jinc);
+
+ /* constraints crossing left */
+ if (ty0 == 'o' || ty0 == 'c' || ty0 == '[' || ty0 == ']') {
+ jthl = jj++;
+ jj %= nmat;
+ jk0l = jj++;
+ }
+ if (ty0 == 'o') {
+ jj %= nmat;
+ jk1l = jj++;
+ jk2l = jj++;
+ }
- /* constraints on left */
- if ((ty0 == '[' || ty0 == 'v' || ty0 == '{' || ty0 == 'c') &&
- jinc == 4) {
- if (ty0 != 'c')
- jk1l = jj++;
- jk2l = jj++;
- }
+ /* constraints on left */
+ if ((ty0 == '[' || ty0 == 'v' || ty0 == '{' || ty0 == 'c') &&
+ jinc == 4) {
+ if (ty0 != 'c')
+ jk1l = jj++;
+ jk2l = jj++;
+ }
- /* constraints on right */
- if ((ty1 == ']' || ty1 == 'v' || ty1 == '}' || ty1 == 'c') &&
- jinc == 4) {
- if (ty1 != 'c')
- jk1r = jj++;
- jk2r = jj++;
- }
+ /* constraints on right */
+ if ((ty1 == ']' || ty1 == 'v' || ty1 == '}' || ty1 == 'c') &&
+ jinc == 4) {
+ if (ty1 != 'c')
+ jk1r = jj++;
+ jk2r = jj++;
+ }
- /* constraints crossing right */
- if (ty1 == 'o' || ty1 == 'c' || ty1 == '[' || ty1 == ']') {
- jthr = jj;
- jk0r = (jj + 1) % nmat;
- }
- if (ty1 == 'o') {
- jk1r = (jj + 2) % nmat;
- jk2r = (jj + 3) % nmat;
- }
+ /* constraints crossing right */
+ if (ty1 == 'o' || ty1 == 'c' || ty1 == '[' || ty1 == ']') {
+ jthr = jj;
+ jk0r = (jj + 1) % nmat;
+ }
+ if (ty1 == 'o') {
+ jk1r = (jj + 2) % nmat;
+ jk2r = (jj + 3) % nmat;
+ }
- add_mat_line(m, v, derivs[0][0], th - ends[0][0], 1, j, jthl, jinc, nmat);
- add_mat_line(m, v, derivs[1][0], ends[0][1], -1, j, jk0l, jinc, nmat);
- add_mat_line(m, v, derivs[2][0], ends[0][2], -1, j, jk1l, jinc, nmat);
- add_mat_line(m, v, derivs[3][0], ends[0][3], -1, j, jk2l, jinc, nmat);
- add_mat_line(m, v, derivs[0][1], -ends[1][0], 1, j, jthr, jinc, nmat);
- add_mat_line(m, v, derivs[1][1], -ends[1][1], 1, j, jk0r, jinc, nmat);
- add_mat_line(m, v, derivs[2][1], -ends[1][2], 1, j, jk1r, jinc, nmat);
- add_mat_line(m, v, derivs[3][1], -ends[1][3], 1, j, jk2r, jinc, nmat);
- if (jthl >= 0)
- v[jthl] = mod_2pi(v[jthl]);
- if (jthr >= 0)
- v[jthr] = mod_2pi(v[jthr]);
- j += jinc;
+ add_mat_line(m, v, derivs[0][0], th - ends[0][0], 1, j, jthl, jinc, nmat);
+ add_mat_line(m, v, derivs[1][0], ends[0][1], -1, j, jk0l, jinc, nmat);
+ add_mat_line(m, v, derivs[2][0], ends[0][2], -1, j, jk1l, jinc, nmat);
+ add_mat_line(m, v, derivs[3][0], ends[0][3], -1, j, jk2l, jinc, nmat);
+ add_mat_line(m, v, derivs[0][1], -ends[1][0], 1, j, jthr, jinc, nmat);
+ add_mat_line(m, v, derivs[1][1], -ends[1][1], 1, j, jk0r, jinc, nmat);
+ add_mat_line(m, v, derivs[2][1], -ends[1][2], 1, j, jk1r, jinc, nmat);
+ add_mat_line(m, v, derivs[3][1], -ends[1][3], 1, j, jk2r, jinc, nmat);
+ if (jthl >= 0)
+ v[jthl] = mod_2pi(v[jthl]);
+ if (jthr >= 0)
+ v[jthr] = mod_2pi(v[jthr]);
+ j += jinc;
}
if (cyclic) {
- memcpy(m + nmat, m, sizeof(bandmat) * nmat);
- memcpy(m + 2 * nmat, m, sizeof(bandmat) * nmat);
- memcpy(v + nmat, v, sizeof(double) * nmat);
- memcpy(v + 2 * nmat, v, sizeof(double) * nmat);
- n_invert = 3 * nmat;
- j = nmat;
+ memcpy(m + nmat, m, sizeof(bandmat) * nmat);
+ memcpy(m + 2 * nmat, m, sizeof(bandmat) * nmat);
+ memcpy(v + nmat, v, sizeof(double) * nmat);
+ memcpy(v + 2 * nmat, v, sizeof(double) * nmat);
+ n_invert = 3 * nmat;
+ j = nmat;
} else {
- n_invert = nmat;
- j = 0;
+ n_invert = nmat;
+ j = 0;
}
#ifdef VERBOSE
- for (i = 0; i < n; i++) {
- int k;
- for (k = 0; k < 11; k++)
- printf(" %2.4f", m[i].a[k]);
- printf(": %2.4f\n", v[i]);
+ for (int i = 0; i < n; i++) {
+ for (int k = 0; k < 11; k++) {
+ printf(" %2.4f", m[i].a[k]);
+ }
+ printf(": %2.4f\n", v[i]);
}
printf("---\n");
#endif
bandec11(m, perm, n_invert);
banbks11(m, perm, v, n_invert);
- norm = 0.;
- for (i = 0; i < n; i++) {
- char ty0 = s[i].ty;
- char ty1 = s[i + 1].ty;
- int jinc = compute_jinc(ty0, ty1);
- int k;
+
+ double norm = 0.;
+ for (int i = 0; i < n; i++) {
+ char ty0 = s[i].ty;
+ char ty1 = s[i + 1].ty;
+ int jinc = compute_jinc(ty0, ty1);
+ int k;
- for (k = 0; k < jinc; k++) {
- double dk = v[j++];
+ for (k = 0; k < jinc; k++) {
+ double dk = v[j++];
#ifdef VERBOSE
- printf("s[%d].ks[%d] += %f\n", i, k, dk);
+ printf("s[%d].ks[%d] += %f\n", i, k, dk);
#endif
- s[i].ks[k] += dk;
- norm += dk * dk;
- }
+ s[i].ks[k] += dk;
+ norm += dk * dk;
+ }
s[i].ks[0] = 2.0*mod_2pi(s[i].ks[0]/2.0);
}
return norm;
}
static int
-solve_spiro(spiro_seg *s, int nseg)
+solve_spiro(spiro_seg *s, const int nseg)
{
- bandmat *m;
- double *v;
- int *perm;
int nmat = count_vec(s, nseg);
int n_alloc = nmat;
- double norm;
- int i;
- if (nmat == 0)
- return 0;
- if (s[0].ty != '{' && s[0].ty != 'v')
- n_alloc *= 3;
- if (n_alloc < 5)
- n_alloc = 5;
- m = (bandmat *)malloc(sizeof(bandmat) * n_alloc);
- v = (double *)malloc(sizeof(double) * n_alloc);
- perm = (int *)malloc(sizeof(int) * n_alloc);
-
- for (i = 0; i < 10; i++) {
- norm = spiro_iter(s, m, perm, v, nseg);
+ if (nmat == 0) {
+ return 0;
+ }
+ if (s[0].ty != '{' && s[0].ty != 'v') {
+ n_alloc *= 3;
+ }
+ if (n_alloc < 5) {
+ n_alloc = 5;
+ }
+
+ bandmat *m = (bandmat *)malloc(sizeof(bandmat) * n_alloc);
+ double *v = (double *)malloc(sizeof(double) * n_alloc);
+ int *perm = (int *)malloc(sizeof(int) * n_alloc);
+
+ for (unsigned i = 0; i < 10; i++) {
+ double norm = spiro_iter(s, m, perm, v, nseg);
#ifdef VERBOSE
- printf("%% norm = %g\n", norm);
+ printf("%% norm = %g\n", norm);
#endif
- if (norm < 1e-12) break;
+ if (norm < 1e-12) break;
}
free(m);