Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_node_selected_join ( void   ) 

Join two nodes by merging them into one.

Definition at line 1127 of file nodepath.cpp.

References Path::Node::code, Path::Path::desktop, Path::SubPath::first, Path::SubPath::last, Path::Node::n, Path::SubPath::nodepath, Path::Node::p, Path::Node::pos, Path::Path::selected, Path::Node::subpath, and Path::Node::type.

{
    Path::Path *nodepath = sp_nodepath_current();
    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;
    }

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

    g_assert(a != b);
    g_assert(a->p.other || a->n.other);
    g_assert(b->p.other || b->n.other);

    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 = (a->pos + b->pos) / 2;

    if (a->subpath == b->subpath) {
        Path::SubPath *sp = a->subpath;
        sp_nodepath_subpath_close(sp);

        sp_nodepath_ensure_ctrls(sp->nodepath);

        update_repr(nodepath);

        return;
    }

    /* a and b are separate subpaths */
    Path::SubPath *sa = a->subpath;
    Path::SubPath *sb = b->subpath;
    NR::Point p;
    Path::Node *n;
    NRPathcode code;
    if (a == sa->first) {
        p = sa->first->n.pos;
        code = (NRPathcode)sa->first->n.other->code;
        Path::SubPath *t = sp_nodepath_subpath_new(sa->nodepath);
        n = sa->last;
        sp_nodepath_node_new(t, NULL, Path::NODE_CUSP, NR_MOVETO, &n->n.pos, &n->pos, &n->p.pos);
        n = n->p.other;
        while (n) {
            sp_nodepath_node_new(t, NULL, (Path::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, Path::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, (Path::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, Path::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, (Path::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_ensure_ctrls(sa->nodepath);

    update_repr(nodepath);

    sp_nodepath_update_statusbar(nodepath);
}


Generated by  Doxygen 1.6.0   Back to index