Esempio n. 1
0
void
lpetool_update_measuring_items(LpeTool *lc)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    for ( std::map<SPPath *, SPCanvasItem*>::iterator i = lc->measuring_items->begin();
          i != lc->measuring_items->end();
          ++i )
    {
        SPPath *path = i->first;
        SPCurve *curve = path->getCurve();
        Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
        Inkscape::Util::Unit const * unit = NULL;
        if (prefs->getString("/tools/lpetool/unit").compare("")) {
            unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
        } else {
            unit = unit_table.getUnit("px");
        }
        double lengthval = Geom::length(pwd2);
        lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
        gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
        sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
        set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
        // TODO: must we free arc_length?
    }
}
Esempio n. 2
0
void
lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection)
{
    if (!selection) {
        selection = lc->desktop->getSelection();
    }
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    bool show = prefs->getBool("/tools/lpetool/show_measuring_info",  true);

    SPPath *path;
    SPCurve *curve;
    SPCanvasText *canvas_text;
    SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup();
    gchar *arc_length;
    double lengthval;
    std::vector<SPItem*> items=selection->itemList();
    for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
        if (SP_IS_PATH(*i)) {
            path = SP_PATH(*i);
            curve = path->getCurve();
            Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = paths_to_pw(curve->get_pathvector());
            canvas_text = (SPCanvasText *) sp_canvastext_new(tmpgrp, lc->desktop, Geom::Point(0,0), "");
            if (!show)
                sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));

            Inkscape::Util::Unit const * unit = NULL;
            if (prefs->getString("/tools/lpetool/unit").compare("")) {
                unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit"));
            } else {
                unit = unit_table.getUnit("px");
            }

            lengthval = Geom::length(pwd2);
            lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
            arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
            sp_canvastext_set_text (canvas_text, arc_length);
            set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
            // TODO: must we free arc_length?
            (*lc->measuring_items)[path] = SP_CANVAS_ITEM(canvas_text);
        }
    }
}