sp-lpe-item.cpp revision e72ec96ad2ab870dc0af88bc559c86b32c63dd9c
#define __SP_LPE_ITEM_CPP__
/** \file
* Base class for live path effect items
*/
/*
* Authors:
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Bastien Bouclet <bgkweb@gmail.com>
*
* Copyright (C) 2008 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#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 <algorithm>
/* LPEItem base class */
static Inkscape::XML::Node *sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
static void sp_lpe_item_child_added (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * ref);
static SPItemClass *parent_class;
{
static GType lpe_item_type = 0;
if (!lpe_item_type) {
sizeof(SPLPEItemClass),
sizeof(SPLPEItem),
16,
NULL, /* value_table */
};
}
return lpe_item_type;
}
static void
{
}
static void
{
}
static void
{
}
}
/**
* Reads the Inkscape::XML::Node, and initializes SPLPEItem variables. For this to get called,
* our name must be associated with a repr via "sp_object_type_register". Best done through
* sp-object-repr.cpp's repr_name_entries array.
*/
static void
{
}
}
/**
* Drops any allocated memory.
*/
static void
{
// disconnect all modified listeners:
{
mod_it->disconnect();
}
delete lpeitem->lpe_modified_connection_list;
// unlink and delete all references in the list
delete *it;
}
// delete the list itself
delete lpeitem->path_effect_list;
}
/**
* Sets a specific value in the SPLPEItem.
*/
static void
{
switch (key) {
{
// Disable the path effects while populating the LPE list
sp_lpe_item_enable_path_effects(lpeitem, false);
// disconnect all modified listeners:
for ( std::list<sigc::connection>::iterator mod_it = lpeitem->lpe_modified_connection_list->begin();
++mod_it)
{
mod_it->disconnect();
}
// 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(object);
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), lpeitem)) );
} 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
}
}
}
}
break;
default:
}
break;
}
}
/**
* Receives update notifications.
*/
static void
{
}
// update the helperpaths of all LPEs applied to the item
// TODO: re-add for the new node tool
}
/**
* Sets modified flag for all sub-item views.
*/
static void
{
if (SP_IS_GROUP(object) && (flags & SP_OBJECT_MODIFIED_FLAG) && (flags & SP_OBJECT_USER_MODIFIED_FLAG_B)) {
}
}
}
/**
* Writes its settings to an incoming repr object, if any.
*/
sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
if (flags & SP_OBJECT_WRITE_EXT) {
if ( sp_lpe_item_has_path_effect(lpeitem) ) {
} else {
}
}
}
return repr;
}
/**
* returns true when LPE was successful.
*/
if (!lpeitem) return false;
if (!curve) return false;
for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->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("sp_lpe_item_perform_path_effect - 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("sp_lpe_item_perform_path_effect - 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(lpeitem)) {
}
try {
}
_("An exception occurred during execution of the Path Effect.") );
}
return false;
}
}
}
}
return true;
}
/**
* Calls any registered handlers for the update_patheffect action
*/
void
{
#ifdef SHAPE_VERBOSE
#endif
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) {
while (parent && SP_IS_LPE_ITEM(parent) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(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 (SP_IS_GROUP(lpeitem)) {
if (SP_IS_LPE_ITEM(subitem)) {
}
}
}
else if (SP_IS_PATH(lpeitem)) {
}
}
}
static void
{
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(lpeitem, false, true);
// Disable the path effects while preparing the new lpe
sp_lpe_item_enable_path_effects(lpeitem, false);
// Add the new reference to the list of LPE references
for (PathEffectList::const_iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it)
{
}
// 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
}
// 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
// Apply the path effect
sp_lpe_item_update_patheffect(lpeitem, true, true);
}
}
{
}
{
Inkscape::LivePathEffect::LPEObjectReference* lperef = sp_lpe_item_get_current_lpereference(lpeitem);
if (!lperef)
return;
if (!r.empty()) {
} else {
}
if (!keep_paths) {
}
}
{
if (!keep_paths) {
}
}
{
Inkscape::LivePathEffect::LPEObjectReference* lperef = sp_lpe_item_get_current_lpereference(lpeitem);
if (!lperef)
return;
down_it++;
}
}
}
{
Inkscape::LivePathEffect::LPEObjectReference* lperef = sp_lpe_item_get_current_lpereference(lpeitem);
if (!lperef)
return;
up_it--;
}
}
/** used for shapes so they can see if they should also disable shape calculation and read from d= */
{
return false;
// go through the list; if some are unknown or invalid, return true
{
return true;
}
return false;
}
{
return false;
// go through the list; if some are unknown or invalid, we are not an LPE item!
{
return false;
}
return true;
}
{
return sp_lpe_item_has_path_effect(lpeitem) || sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(parent));
}
else {
return sp_lpe_item_has_path_effect(lpeitem);
}
}
{
return lpe;
}
}
return NULL;
}
/* Return false if the item is not a path or already has a shape applied */
{
if (!SP_IS_PATH(lpeitem))
return false;
return false;
return true;
}
{
Inkscape::LivePathEffect::LPEObjectReference *lperef = sp_lpe_item_get_current_lpereference(lpeitem);
}
}
static void
{
}
}
}
static void
{
}
}
}
{
{
}
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 *lpeitem->path_effect_list;
}
Inkscape::LivePathEffect::LPEObjectReference* sp_lpe_item_get_current_lpereference(SPLPEItem *lpeitem)
{
}
return lpeitem->current_path_effect;
}
{
Inkscape::LivePathEffect::LPEObjectReference* lperef = sp_lpe_item_get_current_lpereference(lpeitem);
else
return NULL;
}
bool sp_lpe_item_set_current_path_effect(SPLPEItem *lpeitem, Inkscape::LivePathEffect::LPEObjectReference* lperef)
{
for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++) {
lpeitem->current_path_effect = (*it); // current_path_effect should always be a pointer from the path_effect_list !
return true;
}
}
return false;
}
/**
* Note that this method messes up the item's \c PathEffectList.
*/
{
for (PathEffectList::const_iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++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 sp_lpe_item_fork_path_effects_if_necessary(SPLPEItem *lpeitem, unsigned int nr_of_allowed_users)
{
bool forked = false;
if ( sp_lpe_item_has_path_effect(lpeitem) ) {
// 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.
// Forking messes up the path effect list, so after each fork,
// reload the list and recheck if more forking is required.
do {
forked = false;
{
if (lpeobj) {
if (new_lpeobj != lpeobj) {
forked = true;
break; // forked, so break the for-loop and recheck
}
}
}
} while (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 ?
{
return lpeitem->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:encoding=utf-8:textwidth=99 :