コード例 #1
0
static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj)
{
    SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(obj, "desktop"));
    std::vector<SPItem *> selected = desktop->getSelection()->itemList();
    for (std::vector<SPItem *>::iterator it(selected.begin()); it != selected.end(); ++it){
        SPLPEItem* lpeitem = dynamic_cast<SPLPEItem*>(*it);
        if (lpeitem && lpeitem->hasPathEffect()){
            PathEffectList lpelist = lpeitem->getEffectList();
            std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i;
            for (i = lpelist.begin(); i != lpelist.end(); ++i) {
                LivePathEffectObject *lpeobj = (*i)->lpeobject;
                if (lpeobj) {
                    Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
                    if (dynamic_cast<Inkscape::LivePathEffect::LPESimplify *>(lpe)) {
                        SPShape * shape = dynamic_cast<SPShape *>(lpeitem);
                        if(shape){
                            SPCurve * c = shape->getCurveBeforeLPE();
                            lpe->doEffect(c);
                            lpeitem->setCurrentPathEffect(*i);
                            if (lpelist.size() > 1){
                                lpeitem->removeCurrentPathEffect(true);
                                shape->setCurveBeforeLPE(c);
                            } else {
                                lpeitem->removeCurrentPathEffect(false);
                                shape->setCurve(c,0);
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
}
コード例 #2
0
ファイル: sp-lpe-item.cpp プロジェクト: asitti/inkscape
void SPLPEItem::addPathEffect(gchar *value, bool reset)
{
    if (value) {
        // Apply the path effects here because in the casse of a group, lpe->resetDefaults
        // needs that all the subitems have their effects applied
        sp_lpe_item_update_patheffect(this, false, true);

        // Disable the path effects while preparing the new lpe
        sp_lpe_item_enable_path_effects(this, false);

        // Add the new reference to the list of LPE references
        HRefList hreflist;
        for (PathEffectList::const_iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); ++it)
        {
            hreflist.push_back( std::string((*it)->lpeobject_href) );
        }
        hreflist.push_back( std::string(value) );
        std::string hrefs = hreflist_write_svg(hreflist);

        this->getRepr()->setAttribute("inkscape:path-effect", hrefs.c_str());

        // Make sure that ellipse is stored as <svg:path>
        if( SP_IS_GENERICELLIPSE(this)) {
            SP_GENERICELLIPSE(this)->write( this->getRepr()->document(), this->getRepr(), SP_OBJECT_WRITE_EXT );
        }
        // make sure there is an original-d for paths!!!
        sp_lpe_item_create_original_path_recursive(this);

        LivePathEffectObject *lpeobj = this->path_effect_list->back()->lpeobject;
        if (lpeobj && lpeobj->get_lpe()) {
            Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
            // Ask the path effect to reset itself if it doesn't have parameters yet
            if (reset) {
                // has to be called when all the subitems have their lpes applied
                lpe->resetDefaults(this);
            }

            // perform this once when the effect is applied
            lpe->doOnApply(this);

            // indicate that all necessary preparations are done and the effect can be performed
            lpe->setReady();
        }

        //Enable the path effects now that everything is ready to apply the new path effect
        sp_lpe_item_enable_path_effects(this, true);

        // Apply the path effect
        sp_lpe_item_update_patheffect(this, true, true);
        
        //fix bug 1219324
        if (SP_ACTIVE_DESKTOP ) {
        Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context;
            if (INK_IS_NODE_TOOL(ec)) {
                tools_switch(SP_ACTIVE_DESKTOP, TOOLS_LPETOOL); //mhh
                tools_switch(SP_ACTIVE_DESKTOP, TOOLS_NODES);
            }
        }
    }
}
コード例 #3
0
ファイル: sp-lpe-item.cpp プロジェクト: asitti/inkscape
/**
 *  Check all effects in the stack if they are used by other items, and fork them if so.
 *  It is not recommended to fork the effects by yourself calling LivePathEffectObject::fork_private_if_necessary,
 *  use this method instead.
 *  Returns true if one or more effects were forked; returns false if nothing was done.
 */
bool SPLPEItem::forkPathEffectsIfNecessary(unsigned int nr_of_allowed_users)
{
    bool forked = false;

    if ( this->hasPathEffect() ) {
        // If one of the path effects is used by 2 or more items, fork it
        // so that each object has its own independent copy of the effect.
        // Note: replacing path effects messes up the path effect list

        // Clones of the LPEItem will increase the refcount of the lpeobjects.
        // Therefore, nr_of_allowed_users should be increased with the number of clones (i.e. refs to the lpeitem)
        nr_of_allowed_users += this->hrefcount;

        std::vector<LivePathEffectObject const *> old_lpeobjs, new_lpeobjs;
        PathEffectList effect_list = this->getEffectList();
        for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); ++it)
        {
            LivePathEffectObject *lpeobj = (*it)->lpeobject;
            if (lpeobj) {
                LivePathEffectObject *forked_lpeobj = lpeobj->fork_private_if_necessary(nr_of_allowed_users);
                if (forked_lpeobj != lpeobj) {
                    forked = true;
                    old_lpeobjs.push_back(lpeobj);
                    new_lpeobjs.push_back(forked_lpeobj);
                }
            }
        }

        if (forked) {
            this->replacePathEffects(old_lpeobjs, new_lpeobjs);
        }
    }

    return forked;
}
コード例 #4
0
ファイル: sp-item-group.cpp プロジェクト: Spin0za/inkscape
static void
sp_group_update_patheffect (SPLPEItem *lpeitem, bool write)
{
#ifdef GROUP_VERBOSE
    g_message("sp_group_update_patheffect: %p\n", lpeitem);
#endif
    g_return_if_fail (lpeitem != NULL);
    g_return_if_fail (SP_IS_GROUP (lpeitem));

    GSList const *item_list = sp_item_group_item_list(SP_GROUP(lpeitem));
    for ( GSList const *iter = item_list; iter; iter = iter->next ) {
        SPObject *subitem = static_cast<SPObject *>(iter->data);
        if (SP_IS_LPE_ITEM(subitem)) {
            if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect) {
                SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect (SP_LPE_ITEM(subitem), write);
            }
        }
    }

    if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) {
        for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++)
        {
            LivePathEffectObject *lpeobj = (*it)->lpeobject;
            if (lpeobj && lpeobj->get_lpe()) {
                lpeobj->get_lpe()->doBeforeEffect(lpeitem);
            }
        }

        sp_group_perform_patheffect(SP_GROUP(lpeitem), SP_GROUP(lpeitem), write);
    }
}
コード例 #5
0
ファイル: sp-path.cpp プロジェクト: Spin0za/inkscape
static gchar *
sp_path_description(SPItem * item)
{
    int count = SP_PATH(item)->nodesInPath();
    if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) {

        Glib::ustring s;

        PathEffectList effect_list =  sp_lpe_item_get_effect_list(SP_LPE_ITEM(item));
        for (PathEffectList::iterator it = effect_list.begin(); it != effect_list.end(); ++it)
        {
            LivePathEffectObject *lpeobj = (*it)->lpeobject;
            if (!lpeobj || !lpeobj->get_lpe())
                break;
            if (s.empty())
                s = lpeobj->get_lpe()->getName();
            else
                s = s + ", " + lpeobj->get_lpe()->getName();
        }

        return g_strdup_printf(ngettext("<b>Path</b> (%i node, path effect: %s)",
                                        "<b>Path</b> (%i nodes, path effect: %s)",count), count, s.c_str());
    } else {
        return g_strdup_printf(ngettext("<b>Path</b> (%i node)",
                                        "<b>Path</b> (%i nodes)",count), count);
    }
}
コード例 #6
0
ファイル: sp-lpe-item.cpp プロジェクト: asitti/inkscape
Inkscape::LivePathEffect::Effect*
SPLPEItem::getPathEffectOfType(int type)
{
    std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i;
    for (i = path_effect_list->begin(); i != path_effect_list->end(); ++i) {
        LivePathEffectObject *lpeobj = (*i)->lpeobject;
        if (lpeobj) {
            Inkscape::LivePathEffect::Effect* lpe = lpeobj->get_lpe();
            if (lpe && (lpe->effectType() == type)) {
                return lpe;
            }
        }
    }
    return NULL;
}
コード例 #7
0
ファイル: sp-lpe-item.cpp プロジェクト: asitti/inkscape
bool SPLPEItem::hasPathEffect() const
{
    if (path_effect_list->empty()) {
        return false;
    }

    // go through the list; if some are unknown or invalid, we are not an LPE item!
    for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it)
    {
        LivePathEffectObject *lpeobj = (*it)->lpeobject;
        if (!lpeobj || !lpeobj->get_lpe()) {
            return false;
        }
    }

    return true;
}
コード例 #8
0
ファイル: sp-lpe-item.cpp プロジェクト: asitti/inkscape
/**
 * returns true when LPE was successful.
 */
bool SPLPEItem::performPathEffect(SPCurve *curve) {
    if (!this) {
        return false;
    }

    if (!curve) {
        return false;
    }

    if (this->hasPathEffect() && this->pathEffectsEnabled()) {
        for (PathEffectList::iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); ++it)
        {
            LivePathEffectObject *lpeobj = (*it)->lpeobject;
            if (!lpeobj) {
                /** \todo Investigate the cause of this.
                 * For example, this happens when copy pasting an object with LPE applied. Probably because the object is pasted while the effect is not yet pasted to defs, and cannot be found.
                 */
                g_warning("SPLPEItem::performPathEffect - NULL lpeobj in list!");
                return false;
            }
            Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
            if (!lpe) {
                /** \todo Investigate the cause of this.
                 * Not sure, but I think this can happen when an unknown effect type is specified...
                 */
                g_warning("SPLPEItem::performPathEffect - lpeobj with invalid lpe in the stack!");
                return false;
            }

            if (lpe->isVisible()) {
                if (lpe->acceptsNumClicks() > 0 && !lpe->isReady()) {
                    // if the effect expects mouse input before being applied and the input is not finished
                    // yet, we don't alter the path
                    return false;
                }

                // Groups have their doBeforeEffect called elsewhere
                if (!SP_IS_GROUP(this)) {
                    lpe->doBeforeEffect_impl(this);
                }

                try {
                    lpe->doEffect(curve);
                }
                catch (std::exception & e) {
                    g_warning("Exception during LPE %s execution. \n %s", lpe->getName().c_str(), e.what());
                    if (SP_ACTIVE_DESKTOP && SP_ACTIVE_DESKTOP->messageStack()) {
                        SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE,
                                        _("An exception occurred during execution of the Path Effect.") );
                    }
                    return false;
                }
                if (!SP_IS_GROUP(this)) {
                    lpe->doAfterEffect(this);
		}
            }
        }
    }

    return true;
}