Logo Search packages:      
Sourcecode: inkscape version File versions

Inkscape::NodePath::Path* sp_nodepath_new ( SPDesktop desktop,
SPObject object,
bool  show_handles,
const char *  repr_key = NULL,
SPItem item = NULL 
)

Creates new nodepath from item.

Todo:
FIXME: remove this. We don't want to edit paths inside flowtext. Instead we will build our flowtext with cloned paths, so that the real paths are outside the flowtext and thus editable as usual.

Definition at line 154 of file nodepath.cpp.

References Inkscape::XML::Node::attribute(), NArtBpath::code, Inkscape::NodePath::Path::curve, Inkscape::NodePath::Path::d2i, Inkscape::NodePath::Path::desktop, SPCurve::end, Inkscape::NodePath::Path::helper_path, Inkscape::NodePath::Path::helperpath_rgba, Inkscape::NodePath::Path::helperpath_width, Inkscape::NodePath::Path::i2d, NR::Matrix::inverse(), Inkscape::NodePath::Path::item, Inkscape::NodePath::Path::livarot_path, Inkscape::NodePath::Path::local_change, NR_END, Inkscape::NodePath::Path::object, parse_nodetypes(), Inkscape::NodePath::Path::repr, Inkscape::NodePath::Path::repr_key, Inkscape::NodePath::Path::repr_nodetypes_key, Inkscape::NodePath::Path::selected, Inkscape::NodePath::Path::shape_editor, Inkscape::NodePath::Path::show_handles, Inkscape::NodePath::Path::show_helperpath, sp_canvas_item_show(), sp_curve_copy(), sp_curve_first_bpath(), sp_curve_transform(), sp_curve_unref(), sp_object_read_attr(), Inkscape::NodePath::Path::straight_path, subpath_from_bpath(), and Inkscape::NodePath::Path::subpaths.

{
    Inkscape::XML::Node *repr = object->repr;

    /** \todo
     * FIXME: remove this. We don't want to edit paths inside flowtext.
     * Instead we will build our flowtext with cloned paths, so that the
     * real paths are outside the flowtext and thus editable as usual.
     */
    if (SP_IS_FLOWTEXT(object)) {
        for (SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
            if SP_IS_FLOWREGION(child) {
                SPObject *grandchild = sp_object_first_child(SP_OBJECT(child));
                if (grandchild && SP_IS_PATH(grandchild)) {
                    object = SP_ITEM(grandchild);
                    break;
                }
            }
        }
    }

    SPCurve *curve = sp_nodepath_object_get_curve(object, repr_key_in);

    if (curve == NULL)
        return NULL;

    NArtBpath *bpath = sp_curve_first_bpath(curve);
    gint length = curve->end;
    if (length == 0) {
        sp_curve_unref(curve);
        return NULL; // prevent crash for one-node paths
    }

    //Create new nodepath
    Inkscape::NodePath::Path *np = g_new(Inkscape::NodePath::Path, 1);
    if (!np) {
        sp_curve_unref(curve);
        return NULL;
    }

    // Set defaults
    np->desktop     = desktop;
    np->object      = object;
    np->subpaths    = NULL;
    np->selected    = NULL;
    np->shape_editor = NULL; //Let the shapeeditor that makes this set it
    np->livarot_path = NULL;
    np->local_change = 0;
    np->show_handles = show_handles;
    np->helper_path = NULL;
    np->curve = sp_curve_copy(curve);
    np->show_helperpath = false;
    np->straight_path = false;
    if (IS_LIVEPATHEFFECT(object) && item) {
        np->item = item;
    } else {
        np->item = SP_ITEM(object);
    }

    // we need to update item's transform from the repr here,
    // because they may be out of sync when we respond
    // to a change in repr by regenerating nodepath     --bb
    sp_object_read_attr(SP_OBJECT(np->item), "transform");

    np->i2d  = sp_item_i2d_affine(np->item);
    np->d2i  = np->i2d.inverse();

    np->repr = repr;
    if (repr_key_in) { // apparantly the object is an LPEObject
        np->repr_key = g_strdup(repr_key_in);
        np->repr_nodetypes_key = g_strconcat(np->repr_key, "-nodetypes", NULL);
        Inkscape::LivePathEffect::Parameter *lpeparam = LIVEPATHEFFECT(object)->lpe->getParameter(repr_key_in);
        if (lpeparam) {
            lpeparam->param_setup_nodepath(np);
        }
    } else {
        np->repr_nodetypes_key = g_strdup("sodipodi:nodetypes");
        if ( SP_SHAPE(np->object)->path_effect_href ) {
            np->repr_key = g_strdup("inkscape:original-d");

            LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(SP_SHAPE(np->object));
            if (lpeobj && lpeobj->lpe) {
                lpeobj->lpe->setup_nodepath(np);
            }
        } else {
            np->repr_key = g_strdup("d");
        }
    }

    gchar const *nodetypes = np->repr->attribute(np->repr_nodetypes_key);
    gchar *typestr = parse_nodetypes(nodetypes, length);

    // create the subpath(s) from the bpath
    NArtBpath *b = bpath;
    while (b->code != NR_END) {
        b = subpath_from_bpath(np, b, typestr + (b - bpath));
    }

    // reverse the list, because sp_nodepath_subpath_new() used g_list_prepend instead of append (for speed)
    np->subpaths = g_list_reverse(np->subpaths);

    g_free(typestr);
    sp_curve_unref(curve);

    // create the livarot representation from the same item
    sp_nodepath_ensure_livarot_path(np);

    // Draw helper curve
    if (np->show_helperpath) {
        SPCurve *helper_curve = sp_curve_copy(np->curve);
        sp_curve_transform(helper_curve, np->i2d );
        np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(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);
        sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(np->helper_path), 0, SP_WIND_RULE_NONZERO);
        sp_canvas_item_show(np->helper_path);
        sp_curve_unref(helper_curve);
    }

    return np;
}


Generated by  Doxygen 1.6.0   Back to index