From: cilix42 Date: Tue, 29 Jul 2008 14:53:51 +0000 (+0000) Subject: Along with nodepath also create/destroy the helperpaths of any LPEs associated to... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=26df8df7ea9a91b3a08b3c5e005fd777193d50dd;p=inkscape.git Along with nodepath also create/destroy the helperpaths of any LPEs associated to its current item --- diff --git a/src/node-context.cpp b/src/node-context.cpp index a72501af7..66e535ac3 100644 --- a/src/node-context.cpp +++ b/src/node-context.cpp @@ -183,6 +183,7 @@ sp_node_context_setup(SPEventContext *ec) static void sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint timeout) { + g_print ("-----> sp_node_context_flash_path(): TODO: generate the helper path!!\n"); SPNodeContext *nc = SP_NODE_CONTEXT(event_context); nc->remove_flash_counter = 3; // for some reason root_handler is called twice after each item_handler... @@ -196,7 +197,7 @@ sp_node_context_flash_path(SPEventContext *event_context, SPItem *item, guint ti } if (SP_IS_PATH(item)) { - SPCanvasItem *canvasitem = sp_nodepath_generate_helperpath(desktop, SP_PATH(item)); + SPCanvasItem *canvasitem = sp_nodepath_helperpath_from_path(desktop, SP_PATH(item)); nc->flash_tempitem = desktop->add_temporary_canvasitem (canvasitem, timeout); } } diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 3f3443550..7a6674d2f 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -53,6 +53,7 @@ #include #include #include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/path.h" @@ -158,20 +159,76 @@ static void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve) Inkscape::NodePath::Node * Inkscape::NodePath::Path::active_node = NULL; static SPCanvasItem * -sp_nodepath_make_helper_curve(Inkscape::NodePath::Path *np, SPDesktop *desktop, const SPCurve *curve, bool show = false) { - SPCurve *canvasitem = curve->copy(); - canvasitem->transform(to_2geom(np->i2d)); - SPCanvasItem *helper_path = sp_canvas_bpath_new(sp_desktop_controls(desktop), canvasitem); +sp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop, */const SPCurve *curve, bool show = false) { + g_print ("sp_nodepath_make_helper_item()\n"); + SPCurve *helper_curve = curve->copy(); + helper_curve->transform(to_2geom(np->i2d)); + SPCanvasItem *helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helper_path), 0, SP_WIND_RULE_NONZERO); sp_canvas_item_move_to_z(helper_path, 0); if (show) { sp_canvas_item_show(helper_path); } - canvasitem->unref(); - return canvasitem; + helper_curve->unref(); + return helper_path; +} + +static SPCanvasItem * +canvasitem_from_pathvec(Inkscape::NodePath::Path *np, Geom::PathVector const &pathv, bool show) { + g_print ("canvasitem_from_pathvec()\n"); + SPCurve *helper_curve = new SPCurve(pathv); + return sp_nodepath_make_helper_item(np, helper_curve, show); +} + +static void +sp_nodepath_create_helperpaths(Inkscape::NodePath::Path *np) { + g_print ("sp_nodepath_create_helperpaths()\n"); + //std::map >* helper_path_vec; + if (np->item) { + g_print ("np->item: %s\n", SP_OBJECT_REPR(np->item)->attribute("id")); + } else { + g_print ("np->item == NULL!\n"); + } + + if (!SP_IS_LPE_ITEM(np->item)) { + g_print ("Only LPEItems can have helperpaths!\n"); + return; + } + + SPLPEItem *lpeitem = SP_LPE_ITEM(np->item); + PathEffectList lpelist = sp_lpe_item_get_effect_list(lpeitem); + for (PathEffectList::iterator i = lpelist.begin(); i != lpelist.end(); ++i) { + Inkscape::LivePathEffect::Effect *lpe = (*i)->lpeobject->lpe; + g_print ("Processing LPE %s\n", SP_OBJECT_REPR((*i)->lpeobject)->attribute("id")); + // create new canvas items from the effect's helper paths + std::vector hpaths = lpe->getHelperPaths(lpeitem); + for (std::vector::iterator j = hpaths.begin(); j != hpaths.end(); ++j) { + g_print (" ... creating helper path\n"); + (*np->helper_path_vec)[lpe].push_back(canvasitem_from_pathvec(np, *j, true)); + } + } + g_print ("\n"); } +//typedef std::map > HelperPathList; + +static void +sp_nodepath_destroy_helperpaths(Inkscape::NodePath::Path *np) { + g_print ("sp_nodepath_destroy_helperpaths()\n"); + for (HelperPathList::iterator i = np->helper_path_vec->begin(); i != np->helper_path_vec->end(); ++i) { + g_print ("processing helper paths for LPE %s\n", SP_OBJECT_REPR((*i).first->getLPEObj())->attribute("id")); + for (std::vector::iterator j = (*i).second.begin(); j != (*i).second.end(); ++j) { + g_print (" ... destroying helper path\n"); + GtkObject *temp = *j; + *j = NULL; + gtk_object_destroy(temp); + } + } + g_print ("\n"); +} + + /** * \brief Creates new nodepath from item */ @@ -222,6 +279,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, np->local_change = 0; np->show_handles = show_handles; np->helper_path = NULL; + np->helper_path_vec = new HelperPathList; np->helperpath_rgba = prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff); np->helperpath_width = 1.0; np->curve = curve->copy(); @@ -292,9 +350,11 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, // Draw helper curve if (np->show_helperpath) { - np->helper_path = sp_nodepath_make_helper_curve(np, desktop, np->curve, true); + np->helper_path = sp_nodepath_make_helper_item(np, /*desktop, */np->curve, true); } + sp_nodepath_create_helperpaths(np); + return np; } @@ -335,6 +395,10 @@ void sp_nodepath_destroy(Inkscape::NodePath::Path *np) { np->repr_nodetypes_key = NULL; } + sp_nodepath_destroy_helperpaths(np); + delete np->helper_path_vec; + np->helper_path_vec = NULL; + np->desktop = NULL; g_free(np); @@ -4773,10 +4837,12 @@ void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve) { } } +/** SPCanvasItem * -sp_nodepath_to_canvasitem(Inkscape::NodePath::Path *np, SPDesktop *desktop, SPPath *path) { - return sp_nodepath_make_helper_curve(np, desktop, sp_path_get_curve_for_edit(path)); +sp_nodepath_path_to_canvasitem(Inkscape::NodePath::Path *np, SPPath *path) { + return sp_nodepath_make_helper_item(np, sp_path_get_curve_for_edit(path)); } +**/ /** SPCanvasItem * @@ -4801,7 +4867,23 @@ sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path) { } **/ -// TODO: Merge this with sp_nodepath_make_helper_curve()! +SPCanvasItem * +sp_nodepath_helperpath_from_path(SPDesktop *desktop, SPPath *path) { + SPCurve *flash_curve = sp_path_get_curve_for_edit(path)->copy(); + Geom::Matrix i2d = sp_item_i2d_affine(SP_ITEM(path)); + flash_curve->transform(i2d); + SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), flash_curve); + // would be nice if its color could be XORed or something, now it is invisible for red stroked objects... + // unless we also flash the nodes... + guint32 color = prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvasitem), 0, SP_WIND_RULE_NONZERO); + sp_canvas_item_show(canvasitem); + flash_curve->unref(); + return canvasitem; +} + +// TODO: Merge this with sp_nodepath_make_helper_item()! void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) { np->show_helperpath = show; @@ -4809,7 +4891,7 @@ void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) { SPCurve *helper_curve = np->curve->copy(); helper_curve->transform(to_2geom(np->i2d)); if (!np->helper_path) { - //np->helper_path = sp_nodepath_make_helper_curve(np, desktop, helper_curve, true); // Caution: this applies the transform np->i2d twice!! + //np->helper_path = sp_nodepath_make_helper_item(np, desktop, helper_curve, true); // Caution: this applies the transform np->i2d twice!! np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(np->helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); diff --git a/src/nodepath.h b/src/nodepath.h index 22cf316a4..f11d309cc 100644 --- a/src/nodepath.h +++ b/src/nodepath.h @@ -30,11 +30,16 @@ class SPKnot; class LivePathEffectObject; namespace Inkscape { -namespace XML { -class Node; -} + namespace XML { + class Node; + } + + namespace LivePathEffect { + class Effect; + } } +typedef std::map > HelperPathList; /** * Radial objects are represented by an angle and a distance from @@ -243,6 +248,9 @@ class Path { guint32 helperpath_rgba; gdouble helperpath_width; + // the helperpaths provided by all LPEs (and their paramaters) of the current item + HelperPathList* helper_path_vec; + /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop unsigned int local_change; @@ -308,8 +316,9 @@ NR::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath); NR::Maybe sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis); void sp_nodepath_show_handles(Inkscape::NodePath::Path *nodepath, bool show); -SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color); -SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path); +//SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color); +//SPCanvasItem *sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path); +SPCanvasItem *sp_nodepath_helperpath_from_path(SPDesktop *desktop, SPPath *path); void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *nodepath, bool show); void sp_nodepath_make_straight_path(Inkscape::NodePath::Path *np);