Here is how I found it for you, perhaps it helps you in the future :-) 1. Does Inkscape already do something similar? - Yes! It is in the menu "Path -> Object to Path" 2. Open editor, search in all .cpp files "Object to Path" 3. As always, finds a hit in verbs.cpp -> this gives you the verb enum value SP_VERB_OBJECT_TO_CURVE 4. Search for SP_VERB_OBJECT_TO_CURVE in verbs.h 5. Found "case SP_VERB_OBJECT_TO_CURVE: sp_selected_path_to_curves(sel, dt); " 6. Look at sp_selected_path_to_curves 7. etc.
I think the hardest part is step 1: knowing that, somewhere else, Inkscape already does the thing you want.
Cheers, :-) Johan
On 12-11-2013 0:37, Jabiertxo Arraiza Cenoz wrote:
Thanks very much Johan!
El lun, 11-11-2013 a las 22:45 +0100, Johan Engelen escribió:
Hi Jabiertxo,
You should use sp_item_list_to_curves (path-chemistry.h). This avoids duplicating code. Your item does not have to be selected to use sp_item_list_to_curves. You should modify path-chemistry.cpp, so that it handles the two arguments GSList **selected = nullptr and GSList **to_select = nullptr correctly.
regards, Johan
On 9-11-2013 20:23, Jabiertxo Arraiza Cenoz wrote:
Hi to all, first sorry for this big mail.
I want to convert a SP_RECT to path. This rect isnt selected and dont want to select it.
The svg is a document with only a group and inside the SP_RECT. I test it whith two object inside and the same error.
The code i use is:
if ( SP_IS_RECT(subitem) ) { SPDocument *doc = subitem->document; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); /* Transformation */ repr->setAttribute("transform", subitem->getRepr()->attribute("transform")); /* Style */ gchar *style_str = (gchar *) sp_style_write_string(subitem->style); repr->setAttribute("style", style_str); g_free(style_str); /* Mask */ gchar *mask_str = (gchar *) subitem->getRepr()->attribute("mask"); if ( mask_str ) repr->setAttribute("mask", mask_str); /* Clip path */ gchar *clip_path_str = (gchar *) subitem->getRepr()->attribute("clip-path"); if ( clip_path_str ) repr->setAttribute("clip-path", clip_path_str); /* Rotation center */ repr->setAttribute("inkscape:transform-center-x", subitem->getRepr()->attribute("inkscape:transform-center-x"), false); repr->setAttribute("inkscape:transform-center-y", subitem->getRepr()->attribute("inkscape:transform-center-y"), false); /* Definition */ gchar *def_str = sp_svg_write_path(SP_RECT(subitem)->getCurve()->get_pathvector()); repr->setAttribute("d", def_str); g_free(def_str); Inkscape::XML::Node *parent = subitem->getRepr()->parent(); gint pos = 0; char const *id = subitem->getRepr()->attribute("id"); pos = subitem->getRepr()->position(); // remember id gchar *title = subitem->title(); gchar *desc = subitem->desc(); subitem->deleteObject(false); // add the new repr to the parent parent->appendChild(repr); repr->setPosition(pos > 0 ? pos : 0); repr->setAttribute("id", id); SPObject *subitem = doc->getObjectByRepr(repr); if (title && subitem) { subitem->setTitle(title); g_free(title); } if (desc && subitem) { subitem->setDesc(desc); g_free(desc); } if (repr) { Inkscape::GC::release(repr); repr = NULL; } //item_list = g_slist_append(item_list,subitem); //continue; }
And the backtrace error is:
** Message: need to add dynamic switch ** Message: need to add dynamic switch ** Message: need to add dynamic switch
** (inkscape:3452): CRITICAL **: virtual unsigned int Inkscape::XML::SimpleNode::position() const: assertion `_parent != NULL' failed
Program received signal SIGSEGV, Segmentation fault. 0x00000000005b879d in sp_group_perform_patheffect (group=0x7e63660, topgroup=0x7e63660, write=true) at ../../jabiertxof/src/sp-item-group.cpp:846 846 parent->appendChild(repr); (gdb) bt #0 0x00000000005b879d in sp_group_perform_patheffect (group=0x7e63660, topgroup=0x7e63660, write=true) at ../../jabiertxof/src/sp-item-group.cpp:846 #1 0x00000000005c638d in sp_lpe_item_update_patheffect (lpeitem=0x7e36a50, wholetree=true, write=true) at ../../jabiertxof/src/sp-lpe-item.cpp:381 #2 0x00000000005c67b1 in SPLPEItem::remove_child (this=0x7e63660, child=0x6dd53a0) at ../../jabiertxof/src/sp-lpe-item.cpp:709 #3 0x00000000005b7149 in SPGroup::remove_child (this=0x7e63660, child=<optimized out>) at ../../jabiertxof/src/sp-item-group.cpp:142 #4 0x000000000086ca1b in Inkscape::XML::CompositeNodeObserver::notifyChildRemoved (this=0x6dd5410, node=..., child=..., prev=0x0) at ../../jabiertxof/src/xml/composite-node-observer.cpp:49 #5 0x000000000087a017 in Inkscape::XML::SimpleNode::removeChild ( this=<optimized out>, generic_child=<optimized out>) at ../../jabiertxof/src/xml/simple-node.cpp:479 #6 0x00000000005dcfae in sp_repr_unparent (repr=0x6dd53a0) at ../../jabiertxof/src/xml/repr.h:104 #7 SPObject::deleteObject (this=0x7e36a50, propagate=false, propagate_descendants=false) at ../../jabiertxof/src/sp-object.cpp:454 #8 0x00000000005b8795 in deleteObject (propagate=false, this=0x7e36a50) at ../../jabiertxof/src/sp-object.h:464 #9 sp_group_perform_patheffect (group=0x7e63660, topgroup=0x7e63660, write=true) at ../../jabiertxof/src/sp-item-group.cpp:844 ---Type <return> to continue, or q <return> to quit--- #10 0x00000000005c638d in sp_lpe_item_update_patheffect ( lpeitem=lpeitem@...3051...=0x7e63660, wholetree=wholetree@...3051...=true, write=write@...3051...=true) at ../../jabiertxof/src/sp-lpe-item.cpp:381 #11 0x00000000005c7187 in SPLPEItem::addPathEffect (this=0x7e63660, value=<optimized out>, reset=true) at ../../jabiertxof/src/sp-lpe-item.cpp:509 #12 0x00000000007669cb in Inkscape::LivePathEffect::Effect::createAndApply ( name=0x12285d8 "bend_path", doc=<optimized out>, item=0x7e63660) at ../../jabiertxof/src/live_effects/effect.cpp:294 #13 0x000000000098b4f8 in Inkscape::UI::Dialog::LivePathEffectEditor::onAdd ( this=0x72cee80) at ../../jabiertxof/src/ui/dialog/livepatheffect-editor.cpp:423 #14 0x00007ffff5212748 in Glib::SignalProxyNormal::slot0_void_callback(_GObject*, void*) () from /usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1 #15 0x00007ffff04e86e0 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #16 0x00007ffff04f9966 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #17 0x00007ffff05016bc in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #18 0x00007ffff0501852 in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 #19 0x00007ffff68e0b45 in ?? () ---Type <return> to continue, or q <return> to quit---q from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.soQuit (gdb)
Any help is welcome and thanks for read the mail. Regards, Jabier.
November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models. Explore techniques for threading, error checking, porting, and tuning. Get the most from the latest Intel processors and coprocessors. See abstracts and register http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clk... _______________________________________________ Inkscape-devel mailing list Inkscape-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/inkscape-devel