sp-lpe-item.cpp revision a8ccce3fe7248cc5294a4f1716593c2c9c358c3c
/** \file
* Base class for live path effect items
*/
/*
* Authors:
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Bastien Bouclet <bgkweb@gmail.com>
* Abhishek Sharma
*
* Copyright (C) 2008 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "ui/tool/multi-path-manipulator.h"
#include "live_effects/effect.h"
#include "live_effects/lpe-path_length.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
#include "sp-path.h"
#include "sp-item-group.h"
#include "streq.h"
#include "macros.h"
#include "attributes.h"
#include "sp-lpe-item.h"
#include "uri.h"
#include "message-stack.h"
#include "inkscape.h"
#include "desktop.h"
#include "shape-editor.h"
#include "sp-ellipse.h"
#include "sp-clippath.h"
#include "sp-mask.h"
#include "tools-switch.h"
#include "ui/tools/node-tool.h"
#include "ui/tools/tool-base.h"
#include <algorithm>
/* LPEItem base class */
: SPItem()
, path_effects_enabled(1)
, path_effect_list(new PathEffectList())
, lpe_helperpaths()
{
}
}
this->readAttr( "inkscape:path-effect" );
}
// disconnect all modified listeners:
{
mod_it->disconnect();
}
delete this->lpe_modified_connection_list;
this->lpe_modified_connection_list = NULL;
// unlink and delete all references in the list
delete *it;
}
// delete the list itself
delete this->path_effect_list;
this->path_effect_list = NULL;
}
switch (key) {
{
this->current_path_effect = NULL;
// Disable the path effects while populating the LPE list
sp_lpe_item_enable_path_effects(this, false);
// disconnect all modified listeners:
++mod_it)
{
mod_it->disconnect();
}
this->lpe_modified_connection_list->clear();
// Clear the path effect list
{
delete *it;
}
// Parse the contents of "value" to rebuild the path effect reference list
if ( value ) {
{
Inkscape::LivePathEffect::LPEObjectReference *path_effect_ref = new Inkscape::LivePathEffect::LPEObjectReference(this);
try {
} catch (Inkscape::BadURIException &e) {
delete path_effect_ref;
}
// connect modified-listener
path_effect_ref->lpeobject->connectModified(sigc::bind(sigc::ptr_fun(&lpeobject_ref_modified), this)) );
} else {
// something has gone wrong in finding the right patheffect.
g_warning("Unknown LPE type specified, LPE stack effectively disabled");
// keep the effect in the lpestack, so the whole stack is effectively disabled but maintained
}
}
}
sp_lpe_item_enable_path_effects(this, true);
}
break;
default:
break;
}
}
// update the helperpaths of all LPEs applied to the item
// TODO: re-add for the new node tool
}
if (SP_IS_GROUP(this) && (flags & SP_OBJECT_MODIFIED_FLAG) && (flags & SP_OBJECT_USER_MODIFIED_FLAG_B)) {
sp_lpe_item_update_patheffect(this, true, true);
}
// SPItem::onModified(flags);
}
Inkscape::XML::Node* SPLPEItem::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
if (flags & SP_OBJECT_WRITE_EXT) {
if ( hasPathEffect() ) {
} else {
}
}
return repr;
}
/**
* returns true when LPE was successful.
*/
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)
{
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;
}
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 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(this);
}
try {
}
_("An exception occurred during execution of the Path Effect.") );
}
return false;
}
}
}
}
return true;
}
// CPPIFY: make pure virtual
//throw;
}
/**
* Calls any registered handlers for the update_patheffect action
*/
void
{
#ifdef SHAPE_VERBOSE
#endif
if (!lpeitem->pathEffectsEnabled())
return;
// TODO: hack! this will be removed when path length measuring is reimplemented in a better way
if ((*i)->lpeobject) {
// we manually disable text for LPEPathLength
// use static_cast, because we already checked for the right type above
}
}
}
}
if (wholetree) {
}
top = prev_parent;
}
else {
}
}
/**
* Gets called when any of the lpestack's lpeobject repr contents change: i.e. parameter change in any of the stacked LPEs
*/
static void
{
#ifdef SHAPE_VERBOSE
g_message("lpeobject_ref_modified");
#endif
sp_lpe_item_update_patheffect (lpeitem, true, true);
}
static void
{
if(mask)
{
}
if(clipPath)
{
}
if (SP_IS_GROUP(lpeitem)) {
if (SP_IS_LPE_ITEM(subitem)) {
}
}
}
else if (SP_IS_PATH(lpeitem)) {
}
}
}
static void
{
if(mask)
{
}
if(clipPath)
{
}
if (SP_IS_GROUP(lpeitem)) {
if (SP_IS_LPE_ITEM(subitem)) {
}
}
}
else if (SP_IS_PATH(lpeitem)) {
}
else {
sp_lpe_item_update_patheffect(lpeitem, true, true);
}
}
}
{
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
for (PathEffectList::const_iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); ++it)
{
}
// 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!!!
// 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
// indicate that all necessary preparations are done and the effect can be performed
}
//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 ) {
if (INK_IS_NODE_TOOL(ec)) {
}
}
}
}
{
this->addPathEffect(hrefstr, false);
}
/**
* If keep_path == true, the item should not be updated, effectively 'flattening' the LPE.
*/
{
if (!lperef)
return;
if (!r.empty()) {
} else {
}
if (!keep_paths) {
// Make sure that ellipse is stored as <svg:circle> or <svg:ellipse> if possible.
if( SP_IS_GENERICELLIPSE(this)) {
SP_GENERICELLIPSE(this)->write( this->getRepr()->document(), this->getRepr(), SP_OBJECT_WRITE_EXT );
}
}
}
/**
* If keep_path == true, the item should not be updated, effectively 'flattening' the LPE.
*/
{
if (!keep_paths) {
// Make sure that ellipse is stored as <svg:circle> or <svg:ellipse> if possible.
if (SP_IS_GENERICELLIPSE(this)) {
}
}
}
void SPLPEItem::downCurrentPathEffect()
{
if (!lperef)
return;
++down_it;
}
}
}
void SPLPEItem::upCurrentPathEffect()
{
if (!lperef)
return;
--up_it;
}
}
/** used for shapes so they can see if they should also disable shape calculation and read from d= */
bool SPLPEItem::hasBrokenPathEffect() const
{
if (path_effect_list->empty()) {
return false;
}
// go through the list; if some are unknown or invalid, return true
for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it)
{
return true;
}
}
return false;
}
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)
{
return false;
}
}
return true;
}
{
if (path_effect_list->empty()) {
return false;
}
for (PathEffectList::const_iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it)
{
if (lpeobj) {
return true;
}
}
}
return false;
}
bool SPLPEItem::hasPathEffectRecursive() const
{
}
else {
return hasPathEffect();
}
}
void
{
if(clipPath) {
if (SP_IS_PATH(clip_data)) {
} else if(SP_IS_SHAPE(clip_data)) {
} else if(SP_IS_GROUP(clip_data)) {
return;
}
if(clip_curve) {
if (success) {
} else {
// LPE was unsuccesfull. Read the old 'd'-attribute.
if (oldcurve) {
}
}
}
clip_curve->unref();
}
}
}
void
{
if(mask) {
if (SP_IS_PATH(mask_data)) {
} else if(SP_IS_SHAPE(mask_data)) {
} else if(SP_IS_GROUP(mask_data)) {
return;
}
if(mask_curve) {
if (success) {
} else {
// LPE was unsuccesfull. Read the old 'd'-attribute.
if (oldcurve) {
}
}
}
mask_curve->unref();
}
}
}
static void
{
if (SP_IS_GROUP(subitem)) {
} else if (SP_IS_SHAPE(subitem)) {
if (SP_IS_PATH(subitem)) {
} else {
}
if (c) {
if (success) {
} else {
// LPE was unsuccesfull. Read the old 'd'-attribute.
if (oldcurve) {
}
}
}
c->unref();
}
}
}
}
{
if (lpeobj) {
return lpe;
}
}
}
return NULL;
}
{
}
}
if (this->hasPathEffectRecursive()) {
}
}
}
if (this->hasPathEffectRecursive()) {
}
}
}
{
{
}
return hreflist_write_svg(hreflist);
}
/**
* THE function that should be used to generate any patheffectlist string.
* one of the methods to change the effect list:
* - create temporary href list
* - populate the templist with the effects from the old list that you want to have and their order
* - call this function with temp list as param
*/
{
bool semicolon_first = false;
{
if (semicolon_first) {
r += ';';
}
semicolon_first = true;
r += (*it);
}
return r;
}
// Return a copy of the effect list
{
return *path_effect_list;
}
// Return a copy of the effect list
{
return *path_effect_list;
}
{
}
return this->current_path_effect;
}
{
else
return NULL;
}
{
for (PathEffectList::iterator it = path_effect_list->begin(); it != path_effect_list->end(); ++it) {
this->current_path_effect = (*it); // current_path_effect should always be a pointer from the path_effect_list !
return true;
}
}
return false;
}
/**
* Writes a new "inkscape:path-effect" string to xml, where the old_lpeobjects are substituted by the new ones.
* Note that this method messes up the item's \c PathEffectList.
*/
{
for (PathEffectList::const_iterator it = this->path_effect_list->begin(); it != this->path_effect_list->end(); ++it)
{
std::vector<LivePathEffectObject const *>::const_iterator found_it(std::find(old_lpeobjs.begin(), old_lpeobjs.end(), current_lpeobj));
std::vector<LivePathEffectObject const *>::difference_type found_index = std::distance (old_lpeobjs.begin(), found_it);
}
else {
}
}
}
/**
* 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 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;
{
if (lpeobj) {
if (forked_lpeobj != lpeobj) {
forked = true;
}
}
}
if (forked) {
}
}
return forked;
}
// Enable or disable the path effects of the item.
// The counter allows nested calls
{
if (enable) {
}
else {
}
}
// Are the path effects enabled on this item ?
bool SPLPEItem::pathEffectsEnabled() const
{
return path_effects_enabled > 0;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :