X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsp-spiral.cpp;h=3a37a8da278805f91880d93e5d48805f007fdf41;hb=8d358698ecbf192ba7c6dc05d4f7de7592753d9f;hp=ab65ba4ddd65484920199888d7480031784bcf86;hpb=fdc44da6a01ea7605271feed15df61005ddd0219;p=inkscape.git diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index ab65ba4dd..3a37a8da2 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -23,6 +23,7 @@ #include "display/curve.h" #include #include "xml/repr.h" +#include "document.h" #include "sp-spiral.h" @@ -30,13 +31,15 @@ static void sp_spiral_class_init (SPSpiralClass *klass); static void sp_spiral_init (SPSpiral *spiral); static void sp_spiral_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr); -static Inkscape::XML::Node *sp_spiral_write (SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_spiral_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static void sp_spiral_set (SPObject *object, unsigned int key, const gchar *value); static void sp_spiral_update (SPObject *object, SPCtx *ctx, guint flags); static gchar * sp_spiral_description (SPItem * item); static void sp_spiral_snappoints(SPItem const *item, SnapPointsIter p); + static void sp_spiral_set_shape (SPShape *shape); +static void sp_spiral_update_patheffect (SPLPEItem *lpeitem, bool write); static NR::Point sp_spiral_get_tangent (SPSpiral const *spiral, gdouble t); @@ -77,11 +80,13 @@ sp_spiral_class_init (SPSpiralClass *klass) GObjectClass * gobject_class; SPObjectClass * sp_object_class; SPItemClass * item_class; + SPLPEItemClass * lpe_item_class; SPShapeClass *shape_class; gobject_class = (GObjectClass *) klass; sp_object_class = (SPObjectClass *) klass; item_class = (SPItemClass *) klass; + lpe_item_class = (SPLPEItemClass *) klass; shape_class = (SPShapeClass *) klass; parent_class = (SPShapeClass *)g_type_class_ref (SP_TYPE_SHAPE); @@ -94,7 +99,9 @@ sp_spiral_class_init (SPSpiralClass *klass) item_class->description = sp_spiral_description; item_class->snappoints = sp_spiral_snappoints; - shape_class->set_shape = sp_spiral_set_shape; + lpe_item_class->update_patheffect = sp_spiral_update_patheffect; + + shape_class->set_shape = sp_spiral_set_shape; } /** @@ -134,12 +141,12 @@ sp_spiral_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * * Virtual write: write spiral attributes to corresponding repr. */ static Inkscape::XML::Node * -sp_spiral_write (SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { SPSpiral *spiral = SP_SPIRAL (object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = sp_repr_new ("svg:path"); + repr = xml_doc->createElement("svg:path"); } if (flags & SP_OBJECT_WRITE_EXT) { @@ -159,26 +166,21 @@ sp_spiral_write (SPObject *object, Inkscape::XML::Node *repr, guint flags) // make sure the curve is rebuilt with all up-to-date parameters sp_spiral_set_shape ((SPShape *) spiral); - //Duplicate the path - SPCurve *curve = ((SPShape *) spiral)->curve; - //Nulls might be possible if this called iteratively - if ( !curve ) { - //g_warning("sp_spiral_write(): No path to copy\n"); - return NULL; - } - NArtBpath *bpath = SP_CURVE_BPATH(curve); - if ( !bpath ) { - //g_warning("sp_spiral_write(): No path to copy\n"); - return NULL; - } - char *d = sp_svg_write_path ( bpath ); - repr->setAttribute("d", d); - g_free (d); - - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, repr, flags | SP_SHAPE_WRITE_PATH); - - return repr; + //Duplicate the path + SPCurve *curve = ((SPShape *) spiral)->curve; + //Nulls might be possible if this called iteratively + if ( !curve ) { + //g_warning("sp_spiral_write(): No path to copy\n"); + return NULL; + } + char *d = sp_svg_write_path ( curve->get_pathvector() ); + repr->setAttribute("d", d); + g_free (d); + + if (((SPObjectClass *) (parent_class))->write) + ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); + + return repr; } /** @@ -291,6 +293,26 @@ sp_spiral_update (SPObject *object, SPCtx *ctx, guint flags) ((SPObjectClass *) parent_class)->update (object, ctx, flags); } +static void +sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + SPShape *shape = (SPShape *) lpeitem; + sp_spiral_set_shape(shape); + + if (write) { + Inkscape::XML::Node *repr = SP_OBJECT_REPR(shape); + if ( shape->curve != NULL ) { + gchar *str = sp_svg_write_path(shape->curve->get_pathvector()); + repr->setAttribute("d", str); + g_free(str); + } else { + repr->setAttribute("d", NULL); + } + } + + ((SPObject *)shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); +} + /** * Return textual description of spiral. */ @@ -378,8 +400,7 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, #endif if (depth != -1) { for (i = 0; i < 4*depth; i += 4) { - sp_curve_curveto (c, - bezier[i + 1], + c->curveto(bezier[i + 1], bezier[i + 2], bezier[i + 3]); } @@ -388,7 +409,7 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, g_print ("cant_fit_cubic: t=%g\n", *t); #endif for (i = 1; i < SAMPLE_SIZE; i++) - sp_curve_lineto (c, darray[i]); + c->lineto(darray[i]); } *t = next_t; g_assert (is_unit_vector (hat2)); @@ -404,7 +425,7 @@ sp_spiral_set_shape (SPShape *shape) SP_OBJECT (spiral)->requestModified(SP_OBJECT_MODIFIED_FLAG); - SPCurve *c = sp_curve_new (); + SPCurve *c = new SPCurve (); #ifdef SPIRAL_VERBOSE g_print ("cx=%g, cy=%g, exp=%g, revo=%g, rad=%g, arg=%g, t0=%g\n", @@ -418,7 +439,7 @@ sp_spiral_set_shape (SPShape *shape) #endif /* Initial moveto. */ - sp_curve_moveto(c, sp_spiral_get_xy(spiral, spiral->t0)); + c->moveto(sp_spiral_get_xy(spiral, spiral->t0)); double const tstep = SAMPLE_STEP / spiral->revo; double const dstep = tstep / (SAMPLE_SIZE - 1); @@ -434,8 +455,9 @@ sp_spiral_set_shape (SPShape *shape) sp_spiral_fit_and_draw (spiral, c, (1.0 - t)/(SAMPLE_SIZE - 1.0), darray, hat1, hat2, &t); - sp_shape_set_curve_insync ((SPShape *) spiral, c, TRUE); - sp_curve_unref (c); + sp_lpe_item_perform_path_effect(SP_LPE_ITEM (spiral), c); + sp_shape_set_curve_insync ((SPShape *) spiral, c, TRUE); + c->unref(); } /**