Fwd: Cannot move duplicated object

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Cannot move duplicated object

Bhupen Aole

Hi Inkscape devs!

I am trying to create a duplicate of the selected object and move the new copy to a different location.
Following is what I have come up with (browsing around other code), but I am sure I am doing something wrong. There is no compilation or run time error but the new object does not move although duplicate is created correctly.
Appreciate your help.

void Array::applyPageGrid(Inkscape::Selection *selection)
{
    int xq = _scalar_grid_horizontal_qty.get_value_as_int();
    double x = _scalar_grid_horizontal_amt.getValue("px");
    double y = _scalar_grid_vertical.getValue("px");
//selection->moveRelative(x, y);
// Duplicate (taken from selection-chemistry.cpp)
    SPDocument *doc = selection->document();
    if(!doc)
        return;
    Inkscape::XML::Document* xml_doc = doc->getReprDoc();
    std::vector<Inkscape::XML::Node*> reprs(selection->xmlNodes().begin(), selection->xmlNodes().end());
//selection->clear();
sort(reprs.begin(),reprs.end(),sp_repr_compare_position_bool);
std::vector<Inkscape::XML::Node*> newsel;
    std::vector<const gchar *> old_ids;
    std::vector<const gchar *> new_ids;
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value");
    const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true);
    for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();++i){
        Inkscape::XML::Node *old_repr = *i;
        Inkscape::XML::Node *parent = old_repr->parent();
        Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc);
        parent->appendChild(copy);
        if (relink_clones) {
            SPObject *old_obj = doc->getObjectByRepr(old_repr);
            SPObject *new_obj = doc->getObjectByRepr(copy);
            add_ids_recursive(old_ids, old_obj);
            add_ids_recursive(new_ids, new_obj);
        }
        if (fork_livepatheffects) {
            SPObject *new_obj = doc->getObjectByRepr(copy);
            SPLPEItem *newLPEObj = dynamic_cast<SPLPEItem *>(new_obj);
            if (newLPEObj) {
                newLPEObj->forkPathEffectsIfNecessary(1);
            }
        }
((ObjectSet*)copy)->moveRelative(x, y);
        newsel.push_back(copy);
        Inkscape::GC::release(copy);
    }

    DocumentUndo::done( selection->desktop()->getDocument() , SP_VERB_DIALOG_ARRAY,
                        _("Grid"));
}

Thanks!



_______________________________________________
Inkscape-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/inkscape-devel