From f7070430c2a43ad20438359f62c4313a49518152 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:52:09 +0200 Subject: Added "virtual pad" to SPSpiral. (bzr r11608.1.14) --- src/sp-spiral.cpp | 140 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 43 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index fd2672388..f5e7cdb0b 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -97,12 +97,25 @@ static void sp_spiral_class_init(SPSpiralClass *klass) shape_class->set_shape = sp_spiral_set_shape; } +CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { + this->spspiral = spiral; +} + +CSpiral::~CSpiral() { +} + /** * Callback for SPSpiral object initialization. */ static void sp_spiral_init (SPSpiral * spiral) { + spiral->cspiral = new CSpiral(spiral); + spiral->cshape = spiral->cspiral; + spiral->clpeitem = spiral->cspiral; + spiral->citem = spiral->cspiral; + spiral->cobject = spiral->cspiral; + spiral->cx = 0.0; spiral->cy = 0.0; spiral->exp = 1.0; @@ -112,14 +125,10 @@ sp_spiral_init (SPSpiral * spiral) spiral->t0 = 0.0; } -/** - * Virtual build: set spiral properties from corresponding repr. - */ -static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (reinterpret_cast(parent_class)->build) { - reinterpret_cast(parent_class)->build(object, document, repr); - } +void CSpiral::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + SPSpiral* object = this->spspiral; + + CShape::onBuild(document, repr); object->readAttr( "sodipodi:cx" ); object->readAttr( "sodipodi:cy" ); @@ -130,13 +139,17 @@ static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape:: object->readAttr( "sodipodi:t0" ); } +// CPPIFY: remove /** - * Virtual write: write spiral attributes to corresponding repr. + * Virtual build: set spiral properties from corresponding repr. */ -static Inkscape::XML::Node * -sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - SPSpiral *spiral = SP_SPIRAL (object); + ((SPSpiral*)object)->cspiral->onBuild(document, repr); +} + +Inkscape::XML::Node* CSpiral::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPSpiral *spiral = this->spspiral; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -168,19 +181,24 @@ sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X repr->setAttribute("d", d); g_free (d); - if (reinterpret_cast(parent_class)->write) { - reinterpret_cast(parent_class)->write(object, xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); - } + CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } +// CPPIFY: remove /** - * Virtual set: change spiral object attribute. + * Virtual write: write spiral attributes to corresponding repr. */ -static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value) +static Inkscape::XML::Node * +sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPSpiral *spiral = SP_SPIRAL(object); + return ((SPSpiral*)object)->cspiral->onWrite(xml_doc, repr, flags); +} + +void CSpiral::onSet(unsigned int key, gchar const* value) { + SPSpiral *spiral = this->spspiral; + SPSpiral* object = spiral; /// \todo fixme: we should really collect updates switch (key) { @@ -260,30 +278,42 @@ static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (reinterpret_cast(parent_class)->set) { - reinterpret_cast(parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * Virtual update callback. + * Virtual set: change spiral object attribute. */ -static void sp_spiral_update(SPObject *object, SPCtx *ctx, guint flags) +static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value) { + ((SPSpiral*)object)->cspiral->onSet(key, value); +} + +void CSpiral::onUpdate(SPCtx *ctx, guint flags) { + SPSpiral* object = this->spspiral; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { reinterpret_cast(object)->setShape(); } - if (reinterpret_cast(parent_class)->update) { - reinterpret_cast(parent_class)->update(object, ctx, flags); - } + CShape::onUpdate(ctx, flags); } -static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) +// CPPIFY: remove +/** + * Virtual update callback. + */ +static void sp_spiral_update(SPObject *object, SPCtx *ctx, guint flags) { - SPShape *shape = static_cast(lpeitem); + ((SPSpiral*)object)->cspiral->onUpdate(ctx, flags); +} + +void CSpiral::onUpdatePatheffect(bool write) { + SPSpiral* shape = this->spspiral; + sp_spiral_set_shape(shape); if (write) { @@ -300,14 +330,27 @@ static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } +// CPPIFY: remove +static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + ((SPSpiral*)lpeitem)->cspiral->onUpdatePatheffect(write); +} + +gchar* CSpiral::onDescription() { + SPSpiral* item = this->spspiral; + + // TRANSLATORS: since turn count isn't an integer, please adjust the + // string as needed to deal with an localized plural forms. + return g_strdup_printf (_("Spiral with %3f turns"), SP_SPIRAL(item)->revo); +} + +// CPPIFY: remove /** * Return textual description of spiral. */ static gchar *sp_spiral_description(SPItem * item) { - // TRANSLATORS: since turn count isn't an integer, please adjust the - // string as needed to deal with an localized plural forms. - return g_strdup_printf (_("Spiral with %3f turns"), SP_SPIRAL(item)->revo); + return ((SPSpiral*)item)->cspiral->onDescription(); } @@ -401,10 +444,9 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, g_assert (is_unit_vector (hat2)); } -static void -sp_spiral_set_shape (SPShape *shape) -{ - SPSpiral *spiral = SP_SPIRAL(shape); +void CSpiral::onSetShape() { + SPSpiral *spiral = this->spspiral; + SPSpiral* shape = spiral; if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE"); @@ -469,6 +511,13 @@ sp_spiral_set_shape (SPShape *shape) c->unref(); } +// CPPIFY: remove +static void +sp_spiral_set_shape (SPShape *shape) +{ + ((SPSpiral*)shape)->cspiral->onSetShape(); +} + /** * Set spiral properties and update display. */ @@ -500,19 +549,15 @@ sp_spiral_position_set (SPSpiral *spiral, (static_cast(spiral))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/** - * Virtual snappoints callback. - */ -static void sp_spiral_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CSpiral::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPSpiral* item = this->spspiral; + // We will determine the spiral's midpoint ourselves, instead of trusting on the base class // Therefore snapping to object midpoints is temporarily disabled Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - if ((reinterpret_cast(parent_class))->snappoints) { - (reinterpret_cast(parent_class))->snappoints (item, p, &local_snapprefs); - } + CShape::onSnappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (item->i2dt_affine ()); @@ -523,6 +568,15 @@ static void sp_spiral_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPSpiral*)item)->cspiral->onSnappoints(p, snapprefs); +} + /** * Return one of the points on the spiral. * -- cgit v1.2.3 From 260c7156ca920232cca2e829782373a805d59cae Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 29 Sep 2012 17:43:15 +0200 Subject: Removed old calls to set_shape and update_patheffect. (bzr r11608.1.45) --- src/sp-spiral.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index f5e7cdb0b..d549c2192 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -92,9 +92,9 @@ static void sp_spiral_class_init(SPSpiralClass *klass) item_class->description = sp_spiral_description; item_class->snappoints = sp_spiral_snappoints; - lpe_item_class->update_patheffect = sp_spiral_update_patheffect; + //lpe_item_class->update_patheffect = sp_spiral_update_patheffect; - shape_class->set_shape = sp_spiral_set_shape; + //shape_class->set_shape = sp_spiral_set_shape; } CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { -- cgit v1.2.3 From 99cb30e28d4ee193f39e23464abbd7630cac8a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 6 Oct 2012 23:56:27 +0200 Subject: Added virtual pad to SPFlowtext; removed old calls to virtual SPItem methods. (bzr r11608.1.46) --- src/sp-spiral.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index d549c2192..f6663ca12 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -89,8 +89,8 @@ static void sp_spiral_class_init(SPSpiralClass *klass) sp_object_class->set = sp_spiral_set; sp_object_class->update = sp_spiral_update; - item_class->description = sp_spiral_description; - item_class->snappoints = sp_spiral_snappoints; +// item_class->description = sp_spiral_description; +// item_class->snappoints = sp_spiral_snappoints; //lpe_item_class->update_patheffect = sp_spiral_update_patheffect; -- cgit v1.2.3 From a0a8d020201e0e38a63d9aa3dce228d7d9e6fb35 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 14 Mar 2013 12:42:39 +0100 Subject: Various changes. (bzr r11608.1.48) --- src/sp-spiral.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index f6663ca12..f31ce5f90 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -84,7 +84,7 @@ static void sp_spiral_class_init(SPSpiralClass *klass) parent_class = reinterpret_cast(g_type_class_ref(SP_TYPE_SHAPE)); - sp_object_class->build = sp_spiral_build; + //sp_object_class->build = sp_spiral_build; sp_object_class->write = sp_spiral_write; sp_object_class->set = sp_spiral_set; sp_object_class->update = sp_spiral_update; -- cgit v1.2.3 From 957c3e4b7909d42c5a13f1b1dd583f877fc32259 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:46:57 +0100 Subject: Removed function pointers from SPObject and subclasses. Added some missing virtual pads for classes that were hidden by preprocessor macros. (bzr r11608.1.55) --- src/sp-spiral.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index f31ce5f90..d802baab2 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -85,9 +85,9 @@ static void sp_spiral_class_init(SPSpiralClass *klass) parent_class = reinterpret_cast(g_type_class_ref(SP_TYPE_SHAPE)); //sp_object_class->build = sp_spiral_build; - sp_object_class->write = sp_spiral_write; - sp_object_class->set = sp_spiral_set; - sp_object_class->update = sp_spiral_update; +// sp_object_class->write = sp_spiral_write; +// sp_object_class->set = sp_spiral_set; +// sp_object_class->update = sp_spiral_update; // item_class->description = sp_spiral_description; // item_class->snappoints = sp_spiral_snappoints; -- cgit v1.2.3 From 7df6616da5ea2debb86838366ddf746841549cdb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 00:56:13 +0100 Subject: Renamed virtual function names. (bzr r11608.1.57) --- src/sp-spiral.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 8843604b9..083342640 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -69,10 +69,10 @@ sp_spiral_init (SPSpiral * spiral) spiral->t0 = 0.0; } -void CSpiral::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { +void CSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { SPSpiral* object = this->spspiral; - CShape::onBuild(document, repr); + CShape::build(document, repr); object->readAttr( "sodipodi:cx" ); object->readAttr( "sodipodi:cy" ); @@ -83,7 +83,7 @@ void CSpiral::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { object->readAttr( "sodipodi:t0" ); } -Inkscape::XML::Node* CSpiral::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +Inkscape::XML::Node* CSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPSpiral *spiral = this->spspiral; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -105,7 +105,7 @@ Inkscape::XML::Node* CSpiral::onWrite(Inkscape::XML::Document *xml_doc, Inkscape } // make sure the curve is rebuilt with all up-to-date parameters - this->onSetShape(); + this->set_shape(); //Nulls might be possible if this called iteratively if ( !spiral->_curve ) { @@ -116,12 +116,12 @@ Inkscape::XML::Node* CSpiral::onWrite(Inkscape::XML::Document *xml_doc, Inkscape repr->setAttribute("d", d); g_free (d); - CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } -void CSpiral::onSet(unsigned int key, gchar const* value) { +void CSpiral::set(unsigned int key, gchar const* value) { SPSpiral *spiral = this->spspiral; SPSpiral* object = spiral; @@ -203,26 +203,26 @@ void CSpiral::onSet(unsigned int key, gchar const* value) { object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - CShape::onSet(key, value); + CShape::set(key, value); break; } } -void CSpiral::onUpdate(SPCtx *ctx, guint flags) { +void CSpiral::update(SPCtx *ctx, guint flags) { SPSpiral* object = this->spspiral; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { reinterpret_cast(object)->setShape(); } - CShape::onUpdate(ctx, flags); + CShape::update(ctx, flags); } -void CSpiral::onUpdatePatheffect(bool write) { +void CSpiral::update_patheffect(bool write) { SPSpiral* shape = this->spspiral; - this->onSetShape(); + this->set_shape(); if (write) { Inkscape::XML::Node *repr = shape->getRepr(); @@ -238,7 +238,7 @@ void CSpiral::onUpdatePatheffect(bool write) { shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -gchar* CSpiral::onDescription() { +gchar* CSpiral::description() { SPSpiral* item = this->spspiral; // TRANSLATORS: since turn count isn't an integer, please adjust the @@ -336,7 +336,7 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, g_assert (is_unit_vector (hat2)); } -void CSpiral::onSetShape() { +void CSpiral::set_shape() { SPSpiral *spiral = this->spspiral; SPSpiral* shape = spiral; @@ -434,7 +434,7 @@ sp_spiral_position_set (SPSpiral *spiral, (static_cast(spiral))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -void CSpiral::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { +void CSpiral::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { SPSpiral* item = this->spspiral; // We will determine the spiral's midpoint ourselves, instead of trusting on the base class @@ -442,7 +442,7 @@ void CSpiral::onSnappoints(std::vector &p, Inkscap Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - CShape::onSnappoints(p, &local_snapprefs); + CShape::snappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (item->i2dt_affine ()); -- cgit v1.2.3 From 1db831354238eb8e446904fdd947aa91e0482fc6 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 30 Mar 2013 22:16:20 +0100 Subject: Turned all functions concerning SPSpiral into member functions. (bzr r11608.1.61) --- src/sp-spiral.cpp | 129 +++++++++++++++++++++--------------------------------- 1 file changed, 49 insertions(+), 80 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 083342640..348d9ca68 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -28,8 +28,6 @@ #include "sp-spiral.h" -static Geom::Point sp_spiral_get_tangent (SPSpiral const *spiral, gdouble t); - G_DEFINE_TYPE(SPSpiral, sp_spiral, SP_TYPE_SHAPE); /** @@ -253,15 +251,7 @@ gchar* CSpiral::description() { * \pre is_unit_vector(*hat1). * \post is_unit_vector(*hat2). **/ -static void -sp_spiral_fit_and_draw (SPSpiral const *spiral, - SPCurve *c, - double dstep, - Geom::Point darray[], - Geom::Point const &hat1, - Geom::Point &hat2, - double *t) -{ +void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom::Point const& hat1, Geom::Point& hat2, double* t) const { #define BEZIER_SIZE 4 #define FITTING_MAX_BEZIERS 4 #define BEZIER_LENGTH (BEZIER_SIZE * FITTING_MAX_BEZIERS) @@ -273,7 +263,7 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, int depth, i; for (d = *t, i = 0; i <= SAMPLE_SIZE; d += dstep, i++) { - darray[i] = sp_spiral_get_xy(spiral, d); + darray[i] = this->getXY(d); /* Avoid useless adjacent dups. (Otherwise we can have all of darray filled with the same value, which upsets chord_length_parameterize.) */ @@ -304,7 +294,7 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, double const next_t = d - 2 * dstep; /* == t + (SAMPLE_SIZE - 1) * dstep, in absence of dups. */ - hat2 = -sp_spiral_get_tangent (spiral, next_t); + hat2 = -this->getTangent(next_t); /** \todo * We should use better algorithm to specify maximum error. @@ -372,21 +362,20 @@ void CSpiral::set_shape() { #endif /* Initial moveto. */ - c->moveto(sp_spiral_get_xy(spiral, spiral->t0)); + c->moveto(spiral->getXY(spiral->t0)); double const tstep = SAMPLE_STEP / spiral->revo; double const dstep = tstep / (SAMPLE_SIZE - 1); - Geom::Point hat1 = sp_spiral_get_tangent (spiral, spiral->t0); + Geom::Point hat1 = spiral->getTangent(spiral->t0); Geom::Point hat2; for (t = spiral->t0; t < (1.0 - tstep);) { - sp_spiral_fit_and_draw (spiral, c, dstep, darray, hat1, hat2, &t); + spiral->fitAndDraw(c, dstep, darray, hat1, hat2, &t); hat1 = -hat2; } if ((1.0 - t) > SP_EPSILON) - sp_spiral_fit_and_draw (spiral, c, (1.0 - t)/(SAMPLE_SIZE - 1.0), - darray, hat1, hat2, &t); + spiral->fitAndDraw(c, (1.0 - t) / (SAMPLE_SIZE - 1.0), darray, hat1, hat2, &t); /* Reset the shape'scurve to the "original_curve" * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ @@ -406,32 +395,20 @@ void CSpiral::set_shape() { /** * Set spiral properties and update display. */ -void -sp_spiral_position_set (SPSpiral *spiral, - gdouble cx, - gdouble cy, - gdouble exp, - gdouble revo, - gdouble rad, - gdouble arg, - gdouble t0) -{ - g_return_if_fail (spiral != NULL); - g_return_if_fail (SP_IS_SPIRAL (spiral)); - +void SPSpiral::setPosition(gdouble cx, gdouble cy, gdouble exp, gdouble revo, gdouble rad, gdouble arg, gdouble t0) { /** \todo * Consider applying CLAMP or adding in-bounds assertions for * some of these parameters. */ - spiral->cx = cx; - spiral->cy = cy; - spiral->exp = exp; - spiral->revo = revo; - spiral->rad = MAX (rad, 0.0); - spiral->arg = arg; - spiral->t0 = CLAMP(t0, 0.0, 0.999); - - (static_cast(spiral))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + this->cx = cx; + this->cy = cy; + this->exp = exp; + this->revo = revo; + this->rad = MAX (rad, 0.0); + this->arg = arg; + this->t0 = CLAMP(t0, 0.0, 0.999); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } void CSpiral::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { @@ -461,22 +438,18 @@ void CSpiral::snappoints(std::vector &p, Inkscape: * than 1.0, though some callers go slightly beyond 1.0 for curve-fitting * purposes.) */ -Geom::Point sp_spiral_get_xy (SPSpiral const *spiral, gdouble t) -{ - g_assert (spiral != NULL); - g_assert (SP_IS_SPIRAL(spiral)); - g_assert (spiral->exp >= 0.0); +Geom::Point SPSpiral::getXY(gdouble t) const { + g_assert (this->exp >= 0.0); /* Otherwise we get NaN for t==0. */ - g_assert (spiral->exp <= 1000.0); + g_assert (this->exp <= 1000.0); /* Anything much more results in infinities. Even allowing 1000 is somewhat overkill. */ g_assert (t >= 0.0); /* Any callers passing -ve t will have a bug for non-integral values of exp. */ - double const rad = spiral->rad * pow(t, (double) spiral->exp); - double const arg = 2.0 * M_PI * spiral->revo * t + spiral->arg; + double const rad = this->rad * pow(t, (double)this->exp); + double const arg = 2.0 * M_PI * this->revo * t + this->arg; - return Geom::Point(rad * cos (arg) + spiral->cx, - rad * sin (arg) + spiral->cy); + return Geom::Point(rad * cos(arg) + this->cx, rad * sin(arg) + this->cy); } @@ -489,28 +462,24 @@ Geom::Point sp_spiral_get_xy (SPSpiral const *spiral, gdouble t) * \pre p != NULL. * \post is_unit_vector(*p). */ -static Geom::Point -sp_spiral_get_tangent (SPSpiral const *spiral, gdouble t) -{ +Geom::Point SPSpiral::getTangent(gdouble t) const { Geom::Point ret(1.0, 0.0); - g_return_val_if_fail (( ( spiral != NULL ) - && SP_IS_SPIRAL(spiral) ), - ret); + g_assert (t >= 0.0); - g_assert (spiral->exp >= 0.0); + g_assert (this->exp >= 0.0); /* See above for comments on these assertions. */ - double const t_scaled = 2.0 * M_PI * spiral->revo * t; - double const arg = t_scaled + spiral->arg; - double const s = sin (arg); - double const c = cos (arg); + double const t_scaled = 2.0 * M_PI * this->revo * t; + double const arg = t_scaled + this->arg; + double const s = sin(arg); + double const c = cos(arg); - if (spiral->exp == 0.0) { + if (this->exp == 0.0) { ret = Geom::Point(-s, c); } else if (t_scaled == 0.0) { ret = Geom::Point(c, s); } else { - Geom::Point unrotated(spiral->exp, t_scaled); + Geom::Point unrotated(this->exp, t_scaled); double const s_len = L2 (unrotated); g_assert (s_len != 0); /** \todo @@ -542,43 +511,43 @@ sp_spiral_get_tangent (SPSpiral const *spiral, gdouble t) /* Proof that ret length is non-zero: see above. (Should be near 1.) */ } - g_assert (is_unit_vector (ret)); + g_assert (is_unit_vector(ret)); return ret; } /** * Compute rad and/or arg for point on spiral. */ -void -sp_spiral_get_polar (SPSpiral const *spiral, gdouble t, gdouble *rad, gdouble *arg) -{ - g_return_if_fail (spiral != NULL); - g_return_if_fail (SP_IS_SPIRAL(spiral)); +void SPSpiral::getPolar(gdouble t, gdouble* rad, gdouble* arg) const { + if (rad) { + *rad = this->rad * pow(t, (double)this->exp); + } - if (rad) - *rad = spiral->rad * pow(t, (double) spiral->exp); - if (arg) - *arg = 2.0 * M_PI * spiral->revo * t + spiral->arg; + if (arg) { + *arg = 2.0 * M_PI * this->revo * t + this->arg; + } } /** * Return true if spiral has properties that make it invalid. */ -bool -sp_spiral_is_invalid (SPSpiral const *spiral) -{ +bool SPSpiral::isInvalid() const { gdouble rad; - sp_spiral_get_polar (spiral, 0.0, &rad, NULL); + this->getPolar(0.0, &rad, NULL); + if (rad < 0.0 || rad > SP_HUGE) { - g_print ("rad(t=0)=%g\n", rad); + g_print("rad(t=0)=%g\n", rad); return TRUE; } - sp_spiral_get_polar (spiral, 1.0, &rad, NULL); + + this->getPolar(1.0, &rad, NULL); + if (rad < 0.0 || rad > SP_HUGE) { - g_print ("rad(t=1)=%g\n", rad); + g_print("rad(t=1)=%g\n", rad); return TRUE; } + return FALSE; } -- cgit v1.2.3 From a5d6e692d661f0bf7648e64e8fcb04588bb8f3ab Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 1 Apr 2013 00:07:00 +0200 Subject: Prepared exchange of casting macros. (bzr r11608.1.63) --- src/sp-spiral.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 348d9ca68..6c1deb4d5 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -51,6 +51,7 @@ static void sp_spiral_init (SPSpiral * spiral) { spiral->cspiral = new CSpiral(spiral); + spiral->typeHierarchy.insert(typeid(SPSpiral)); delete spiral->cshape; spiral->cshape = spiral->cspiral; -- cgit v1.2.3 From 69f3b6f1abb2bb422935d43262e1e99aab359954 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 01:41:30 +0200 Subject: Added constructors to SP classes. (bzr r11608.1.67) --- src/sp-spiral.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 6c1deb4d5..eec5e953e 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -28,7 +28,7 @@ #include "sp-spiral.h" -G_DEFINE_TYPE(SPSpiral, sp_spiral, SP_TYPE_SHAPE); +G_DEFINE_TYPE(SPSpiral, sp_spiral, G_TYPE_OBJECT); /** * SPSpiral vtable initialization. @@ -44,12 +44,9 @@ CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { CSpiral::~CSpiral() { } -/** - * Callback for SPSpiral object initialization. - */ -static void -sp_spiral_init (SPSpiral * spiral) -{ +SPSpiral::SPSpiral() : SPShape() { + SPSpiral* spiral = this; + spiral->cspiral = new CSpiral(spiral); spiral->typeHierarchy.insert(typeid(SPSpiral)); @@ -68,6 +65,15 @@ sp_spiral_init (SPSpiral * spiral) spiral->t0 = 0.0; } +/** + * Callback for SPSpiral object initialization. + */ +static void +sp_spiral_init (SPSpiral * spiral) +{ + new (spiral) SPSpiral(); +} + void CSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { SPSpiral* object = this->spspiral; -- cgit v1.2.3 From d1af3566872dfff2aeec84859c87f1f8d13f79df Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 19:14:36 +0200 Subject: Registered classes with new factory. Hkern, Vkern and FeFuncX have to be rewritten, as they aren't real classes. (bzr r11608.1.69) --- src/sp-spiral.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index eec5e953e..dabd9cdd0 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -28,6 +28,18 @@ #include "sp-spiral.h" + +#include "sp-factory.h" + +namespace { + SPObject* createSpiral() { + return new SPSpiral(); + } + + bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral); +} + + G_DEFINE_TYPE(SPSpiral, sp_spiral, G_TYPE_OBJECT); /** -- cgit v1.2.3 From 8443720ce6429b9beec839e60b8a808595f4ba72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 2 Apr 2013 23:01:45 +0200 Subject: Cleaned up a bit. Uses some C++11 features. (bzr r11608.1.72) --- src/sp-spiral.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index dabd9cdd0..4c87da1b5 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -40,15 +40,6 @@ namespace { } -G_DEFINE_TYPE(SPSpiral, sp_spiral, G_TYPE_OBJECT); - -/** - * SPSpiral vtable initialization. - */ -static void sp_spiral_class_init(SPSpiralClass *klass) -{ -} - CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { this->spspiral = spiral; } @@ -77,15 +68,6 @@ SPSpiral::SPSpiral() : SPShape() { spiral->t0 = 0.0; } -/** - * Callback for SPSpiral object initialization. - */ -static void -sp_spiral_init (SPSpiral * spiral) -{ - new (spiral) SPSpiral(); -} - void CSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { SPSpiral* object = this->spspiral; @@ -235,7 +217,6 @@ void CSpiral::update(SPCtx *ctx, guint flags) { CShape::update(ctx, flags); } - void CSpiral::update_patheffect(bool write) { SPSpiral* shape = this->spspiral; -- cgit v1.2.3 From 5b651c260b3023a4d5ae2b7e68a501ee176ec1a8 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 4 Apr 2013 22:32:44 +0200 Subject: Merged SPSpiral and CSpiral. (bzr r11608.1.74) --- src/sp-spiral.cpp | 196 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 102 insertions(+), 94 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 4c87da1b5..644f32430 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -39,52 +39,38 @@ namespace { bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral); } - -CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { - this->spspiral = spiral; -} - -CSpiral::~CSpiral() { +SPSpiral::SPSpiral() : SPShape(), CShape(this) { + delete this->cshape; + this->cshape = this; + this->clpeitem = this; + this->citem = this; + this->cobject = this; + + this->cx = 0.0; + this->cy = 0.0; + this->exp = 1.0; + this->revo = 3.0; + this->rad = 1.0; + this->arg = 0.0; + this->t0 = 0.0; } -SPSpiral::SPSpiral() : SPShape() { - SPSpiral* spiral = this; - - spiral->cspiral = new CSpiral(spiral); - spiral->typeHierarchy.insert(typeid(SPSpiral)); - - delete spiral->cshape; - spiral->cshape = spiral->cspiral; - spiral->clpeitem = spiral->cspiral; - spiral->citem = spiral->cspiral; - spiral->cobject = spiral->cspiral; - - spiral->cx = 0.0; - spiral->cy = 0.0; - spiral->exp = 1.0; - spiral->revo = 3.0; - spiral->rad = 1.0; - spiral->arg = 0.0; - spiral->t0 = 0.0; +SPSpiral::~SPSpiral() { } -void CSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { - SPSpiral* object = this->spspiral; - +void SPSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { CShape::build(document, repr); - object->readAttr( "sodipodi:cx" ); - object->readAttr( "sodipodi:cy" ); - object->readAttr( "sodipodi:expansion" ); - object->readAttr( "sodipodi:revolution" ); - object->readAttr( "sodipodi:radius" ); - object->readAttr( "sodipodi:argument" ); - object->readAttr( "sodipodi:t0" ); + this->readAttr("sodipodi:cx"); + this->readAttr("sodipodi:cy"); + this->readAttr("sodipodi:expansion"); + this->readAttr("sodipodi:revolution"); + this->readAttr("sodipodi:radius"); + this->readAttr("sodipodi:argument"); + this->readAttr("sodipodi:t0"); } -Inkscape::XML::Node* CSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPSpiral *spiral = this->spspiral; - +Inkscape::XML::Node* SPSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); } @@ -94,50 +80,51 @@ Inkscape::XML::Node* CSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape:: * sodipodi:spiral="cx cy exp revo rad arg t0" */ repr->setAttribute("sodipodi:type", "spiral"); - sp_repr_set_svg_double(repr, "sodipodi:cx", spiral->cx); - sp_repr_set_svg_double(repr, "sodipodi:cy", spiral->cy); - sp_repr_set_svg_double(repr, "sodipodi:expansion", spiral->exp); - sp_repr_set_svg_double(repr, "sodipodi:revolution", spiral->revo); - sp_repr_set_svg_double(repr, "sodipodi:radius", spiral->rad); - sp_repr_set_svg_double(repr, "sodipodi:argument", spiral->arg); - sp_repr_set_svg_double(repr, "sodipodi:t0", spiral->t0); + sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx); + sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy); + sp_repr_set_svg_double(repr, "sodipodi:expansion", this->exp); + sp_repr_set_svg_double(repr, "sodipodi:revolution", this->revo); + sp_repr_set_svg_double(repr, "sodipodi:radius", this->rad); + sp_repr_set_svg_double(repr, "sodipodi:argument", this->arg); + sp_repr_set_svg_double(repr, "sodipodi:t0", this->t0); } // make sure the curve is rebuilt with all up-to-date parameters this->set_shape(); //Nulls might be possible if this called iteratively - if ( !spiral->_curve ) { + if (!this->_curve) { //g_warning("sp_spiral_write(): No path to copy\n"); return NULL; } - char *d = sp_svg_write_path ( spiral->_curve->get_pathvector() ); + char *d = sp_svg_write_path(this->_curve->get_pathvector()); repr->setAttribute("d", d); - g_free (d); + g_free(d); CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } -void CSpiral::set(unsigned int key, gchar const* value) { - SPSpiral *spiral = this->spspiral; - SPSpiral* object = spiral; - +void SPSpiral::set(unsigned int key, gchar const* value) { /// \todo fixme: we should really collect updates switch (key) { case SP_ATTR_SODIPODI_CX: - if (!sp_svg_length_read_computed_absolute (value, &spiral->cx)) { - spiral->cx = 0.0; + if (!sp_svg_length_read_computed_absolute (value, &this->cx)) { + this->cx = 0.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_CY: - if (!sp_svg_length_read_computed_absolute (value, &spiral->cy)) { - spiral->cy = 0.0; + if (!sp_svg_length_read_computed_absolute (value, &this->cy)) { + this->cy = 0.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_EXPANSION: if (value) { /** \todo @@ -147,31 +134,37 @@ void CSpiral::set(unsigned int key, gchar const* value) { * N.B. atof/sscanf/strtod consider "nan" and "inf" * to be valid numbers. */ - spiral->exp = g_ascii_strtod (value, NULL); - spiral->exp = CLAMP (spiral->exp, 0.0, 1000.0); + this->exp = g_ascii_strtod (value, NULL); + this->exp = CLAMP (this->exp, 0.0, 1000.0); } else { - spiral->exp = 1.0; + this->exp = 1.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_REVOLUTION: if (value) { - spiral->revo = g_ascii_strtod (value, NULL); - spiral->revo = CLAMP (spiral->revo, 0.05, 1024.0); + this->revo = g_ascii_strtod (value, NULL); + this->revo = CLAMP (this->revo, 0.05, 1024.0); } else { - spiral->revo = 3.0; + this->revo = 3.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_RADIUS: - if (!sp_svg_length_read_computed_absolute (value, &spiral->rad)) { - spiral->rad = MAX (spiral->rad, 0.001); + if (!sp_svg_length_read_computed_absolute (value, &this->rad)) { + this->rad = MAX (this->rad, 0.001); } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_ARGUMENT: if (value) { - spiral->arg = g_ascii_strtod (value, NULL); + this->arg = g_ascii_strtod (value, NULL); /** \todo * FIXME: We still need some bounds on arg, for * numerical reasons. E.g., we don't want inf or NaN, @@ -181,14 +174,16 @@ void CSpiral::set(unsigned int key, gchar const* value) { * results in very negative arg. */ } else { - spiral->arg = 0.0; + this->arg = 0.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_SODIPODI_T0: if (value) { - spiral->t0 = g_ascii_strtod (value, NULL); - spiral->t0 = CLAMP (spiral->t0, 0.0, 0.999); + this->t0 = g_ascii_strtod (value, NULL); + this->t0 = CLAMP (this->t0, 0.0, 0.999); /** \todo * Have shared constants for the allowable bounds for * attributes. There was a bug here where we used -1.0 @@ -197,18 +192,20 @@ void CSpiral::set(unsigned int key, gchar const* value) { * requirements. */ } else { - spiral->t0 = 0.0; + this->t0 = 0.0; } - object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; + default: CShape::set(key, value); break; } } -void CSpiral::update(SPCtx *ctx, guint flags) { - SPSpiral* object = this->spspiral; +void SPSpiral::update(SPCtx *ctx, guint flags) { + SPSpiral* object = this; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { reinterpret_cast(object)->setShape(); @@ -217,8 +214,8 @@ void CSpiral::update(SPCtx *ctx, guint flags) { CShape::update(ctx, flags); } -void CSpiral::update_patheffect(bool write) { - SPSpiral* shape = this->spspiral; +void SPSpiral::update_patheffect(bool write) { + SPSpiral* shape = this; this->set_shape(); @@ -236,8 +233,8 @@ void CSpiral::update_patheffect(bool write) { shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -gchar* CSpiral::description() { - SPSpiral* item = this->spspiral; +gchar* SPSpiral::description() { + SPSpiral* item = this; // TRANSLATORS: since turn count isn't an integer, please adjust the // string as needed to deal with an localized plural forms. @@ -255,6 +252,7 @@ void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom:: #define BEZIER_SIZE 4 #define FITTING_MAX_BEZIERS 4 #define BEZIER_LENGTH (BEZIER_SIZE * FITTING_MAX_BEZIERS) + g_assert (dstep > 0); g_assert (is_unit_vector (hat1)); @@ -267,9 +265,7 @@ void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom:: /* Avoid useless adjacent dups. (Otherwise we can have all of darray filled with the same value, which upsets chord_length_parameterize.) */ - if ((i != 0) - && (darray[i] == darray[i - 1]) - && (d < 1.0)) { + if ((i != 0) && (darray[i] == darray[i - 1]) && (d < 1.0)) { i--; d += dstep; /** We mustn't increase dstep for subsequent values of @@ -303,12 +299,15 @@ void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom:: hat1, hat2, SPIRAL_TOLERANCE*SPIRAL_TOLERANCE, FITTING_MAX_BEZIERS); + g_assert(depth * BEZIER_SIZE <= gint(G_N_ELEMENTS(bezier))); + #ifdef SPIRAL_DEBUG if (*t == spiral->t0 || *t == 1.0) g_print ("[%s] depth=%d, dstep=%g, t0=%g, t=%g, arg=%g\n", debug_state, depth, dstep, spiral->t0, *t, spiral->arg); #endif + if (depth != -1) { for (i = 0; i < 4*depth; i += 4) { c->curveto(bezier[i + 1], @@ -322,16 +321,19 @@ void SPSpiral::fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom:: for (i = 1; i < SAMPLE_SIZE; i++) c->lineto(darray[i]); } + *t = next_t; + g_assert (is_unit_vector (hat2)); } -void CSpiral::set_shape() { - SPSpiral *spiral = this->spspiral; +void SPSpiral::set_shape() { + SPSpiral *spiral = this; SPSpiral* shape = spiral; if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE"); + if (shape->getRepr()->attribute("d")) { // unconditionally read the curve from d, if any, to preserve appearance Geom::PathVector pv = sp_svg_read_pathv(shape->getRepr()->attribute("d")); @@ -340,6 +342,7 @@ void CSpiral::set_shape() { shape->setCurveBeforeLPE( cold ); cold->unref(); } + return; } @@ -369,26 +372,33 @@ void CSpiral::set_shape() { Geom::Point hat1 = spiral->getTangent(spiral->t0); Geom::Point hat2; + for (t = spiral->t0; t < (1.0 - tstep);) { spiral->fitAndDraw(c, dstep, darray, hat1, hat2, &t); hat1 = -hat2; } - if ((1.0 - t) > SP_EPSILON) + + if ((1.0 - t) > SP_EPSILON) { spiral->fitAndDraw(c, (1.0 - t) / (SAMPLE_SIZE - 1.0), darray, hat1, hat2, &t); + } /* Reset the shape'scurve to the "original_curve" * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ shape->setCurveInsync( c, TRUE); shape->setCurveBeforeLPE( c ); + if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(shape)) && sp_lpe_item_path_effects_enabled(SP_LPE_ITEM(shape))) { SPCurve *c_lpe = c->copy(); bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM (shape), c_lpe); + if (success) { shape->setCurveInsync( c_lpe, TRUE); } + c_lpe->unref(); } + c->unref(); } @@ -411,9 +421,7 @@ void SPSpiral::setPosition(gdouble cx, gdouble cy, gdouble exp, gdouble revo, gd this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -void CSpiral::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - SPSpiral* item = this->spspiral; - +void SPSpiral::snappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { // We will determine the spiral's midpoint ourselves, instead of trusting on the base class // Therefore snapping to object midpoints is temporarily disabled Inkscape::SnapPreferences local_snapprefs = *snapprefs; @@ -422,9 +430,9 @@ void CSpiral::snappoints(std::vector &p, Inkscape: CShape::snappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { - Geom::Affine const i2dt (item->i2dt_affine ()); - SPSpiral *spiral = SP_SPIRAL(item); - p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(spiral->cx, spiral->cy) * i2dt, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); + Geom::Affine const i2dt (this->i2dt_affine ()); + + p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(this->cx, this->cy) * i2dt, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); // This point is the start-point of the spiral, which is also returned when _snap_to_itemnode has been set // in the object snapper. In that case we will get a duplicate! } -- cgit v1.2.3 From cfe48de7f071e2e07a1f2f2ace3456f7b410e93b Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 15:37:33 +0200 Subject: Merged Shape and subclasses. Cleaned up a bit. (bzr r11608.1.76) --- src/sp-spiral.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 644f32430..e041e4f7d 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -39,9 +39,7 @@ namespace { bool spiralRegistered = SPFactory::instance().registerObject("spiral", createSpiral); } -SPSpiral::SPSpiral() : SPShape(), CShape(this) { - delete this->cshape; - this->cshape = this; +SPSpiral::SPSpiral() : SPShape() { this->clpeitem = this; this->citem = this; this->cobject = this; @@ -59,7 +57,7 @@ SPSpiral::~SPSpiral() { } void SPSpiral::build(SPDocument * document, Inkscape::XML::Node * repr) { - CShape::build(document, repr); + SPShape::build(document, repr); this->readAttr("sodipodi:cx"); this->readAttr("sodipodi:cy"); @@ -101,7 +99,7 @@ Inkscape::XML::Node* SPSpiral::write(Inkscape::XML::Document *xml_doc, Inkscape: repr->setAttribute("d", d); g_free(d); - CShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + SPShape::write(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } @@ -199,7 +197,7 @@ void SPSpiral::set(unsigned int key, gchar const* value) { break; default: - CShape::set(key, value); + SPShape::set(key, value); break; } } @@ -208,10 +206,10 @@ void SPSpiral::update(SPCtx *ctx, guint flags) { SPSpiral* object = this; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - reinterpret_cast(object)->setShape(); + reinterpret_cast(object)->set_shape(); } - CShape::update(ctx, flags); + SPShape::update(ctx, flags); } void SPSpiral::update_patheffect(bool write) { @@ -427,7 +425,7 @@ void SPSpiral::snappoints(std::vector &p, Inkscape Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - CShape::snappoints(p, &local_snapprefs); + SPShape::snappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (this->i2dt_affine ()); -- cgit v1.2.3 From 19d00efa85cfc42ccae9bd17ef575602f0d22c50 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 19:42:32 +0200 Subject: Merged more classes. (bzr r11608.1.78) --- src/sp-spiral.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index e041e4f7d..905a05a5f 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -40,7 +40,6 @@ namespace { } SPSpiral::SPSpiral() : SPShape() { - this->clpeitem = this; this->citem = this; this->cobject = this; -- cgit v1.2.3 From 8073924aacdda310fb7492750f78d5389b3186af Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Fri, 5 Apr 2013 22:45:01 +0200 Subject: Merged Item. (bzr r11608.1.81) --- src/sp-spiral.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index 905a05a5f..e1e175e9d 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -40,7 +40,6 @@ namespace { } SPSpiral::SPSpiral() : SPShape() { - this->citem = this; this->cobject = this; this->cx = 0.0; -- cgit v1.2.3 From 27e2102f96a5554bcd5310ec11435d155773b279 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 7 Apr 2013 18:28:22 +0200 Subject: Merge Object and subclasses. Merging of SP- and C-classes complete. (bzr r11608.1.86) --- src/sp-spiral.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/sp-spiral.cpp') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index e1e175e9d..8d2954c6e 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -40,8 +40,6 @@ namespace { } SPSpiral::SPSpiral() : SPShape() { - this->cobject = this; - this->cx = 0.0; this->cy = 0.0; this->exp = 1.0; -- cgit v1.2.3