Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_node_selected_join ( Inkscape::NodePath::Path nodepath  ) 

Join two nodes by merging them into one.

Definition at line 1886 of file nodepath.cpp.

References Inkscape::NodePath::Node::code, Inkscape::NodePath::Path::desktop, Inkscape::NodePath::SubPath::first, Inkscape::MessageStack::flash(), Inkscape::NodePath::Node::knot, Inkscape::NodePath::SubPath::last, Inkscape::UI::View::View::messageStack(), Inkscape::NodePath::Node::n, Inkscape::NodePath::SubPath::nodepath, NR_END, NR_MOVETO, Inkscape::NodePath::Node::p, Inkscape::NodePath::Node::pos, Inkscape::NodePath::Path::selected, sp_node_moveto(), sp_nodepath_node_destroy(), sp_nodepath_node_new(), sp_nodepath_subpath_close(), sp_nodepath_subpath_destroy(), sp_nodepath_subpath_new(), sp_nodepath_update_handles(), sp_nodepath_update_repr(), sp_nodepath_update_statusbar(), Inkscape::NodePath::Node::subpath, and Inkscape::NodePath::Node::type.

{
    if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses

    if (g_list_length(nodepath->selected) != 2) {
        nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
        return;
    }

   Inkscape::NodePath::Node *a = (Inkscape::NodePath::Node *) nodepath->selected->data;
   Inkscape::NodePath::Node *b = (Inkscape::NodePath::Node *) nodepath->selected->next->data;

    g_assert(a != b);
    if (!(a->p.other || a->n.other) || !(b->p.other || b->n.other)) {
        // someone tried to join an orphan node (i.e. a single-node subpath).
        // this is not worth an error message, just fail silently.
        return;
    }

    if (((a->subpath->closed) || (b->subpath->closed)) || (a->p.other && a->n.other) || (b->p.other && b->n.other)) {
        nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
        return;
    }

    /* a and b are endpoints */

    NR::Point c;
    if (a->knot && SP_KNOT_IS_MOUSEOVER(a->knot)) {
        c = a->pos;
    } else if (b->knot && SP_KNOT_IS_MOUSEOVER(b->knot)) {
        c = b->pos;
    } else {
        c = (a->pos + b->pos) / 2;
    }

    if (a->subpath == b->subpath) {
       Inkscape::NodePath::SubPath *sp = a->subpath;
        sp_nodepath_subpath_close(sp);
        sp_node_moveto (sp->first, c);

        sp_nodepath_update_handles(sp->nodepath);
        sp_nodepath_update_repr(nodepath, _("Close subpath"));
        return;
    }

    /* a and b are separate subpaths */
   Inkscape::NodePath::SubPath *sa = a->subpath;
   Inkscape::NodePath::SubPath *sb = b->subpath;
    NR::Point p;
   Inkscape::NodePath::Node *n;
    NRPathcode code;
    if (a == sa->first) {
        p = sa->first->n.pos;
        code = (NRPathcode)sa->first->n.other->code;
       Inkscape::NodePath::SubPath *t = sp_nodepath_subpath_new(sa->nodepath);
        n = sa->last;
        sp_nodepath_node_new(t, NULL,Inkscape::NodePath::NODE_CUSP, NR_MOVETO, &n->n.pos, &n->pos, &n->p.pos);
        n = n->p.other;
        while (n) {
            sp_nodepath_node_new(t, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
            n = n->p.other;
            if (n == sa->first) n = NULL;
        }
        sp_nodepath_subpath_destroy(sa);
        sa = t;
    } else if (a == sa->last) {
        p = sa->last->p.pos;
        code = (NRPathcode)sa->last->code;
        sp_nodepath_node_destroy(sa->last);
    } else {
        code = NR_END;
        g_assert_not_reached();
    }

    if (b == sb->first) {
        sp_nodepath_node_new(sa, NULL,Inkscape::NodePath::NODE_CUSP, code, &p, &c, &sb->first->n.pos);
        for (n = sb->first->n.other; n != NULL; n = n->n.other) {
            sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->code, &n->p.pos, &n->pos, &n->n.pos);
        }
    } else if (b == sb->last) {
        sp_nodepath_node_new(sa, NULL,Inkscape::NodePath::NODE_CUSP, code, &p, &c, &sb->last->p.pos);
        for (n = sb->last->p.other; n != NULL; n = n->p.other) {
            sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
        }
    } else {
        g_assert_not_reached();
    }
    /* and now destroy sb */

    sp_nodepath_subpath_destroy(sb);

    sp_nodepath_update_handles(sa->nodepath);

    sp_nodepath_update_repr(nodepath, _("Join nodes"));

    sp_nodepath_update_statusbar(nodepath);
}


Generated by  Doxygen 1.6.0   Back to index