sp-item.cpp revision 883c5b2d5104c153708fdc513209d5694b489900
/** \file
* Base class for visual SVG elements
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Abhishek Sharma
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2001-2006 authors
* Copyright (C) 2001 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
/** \class SPItem
*
* SPItem is an abstract base class for all graphic (visible) SVG nodes. It
* is a subclass of SPObject, with great deal of specific functionality.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-item.h"
#include "print.h"
#include "display/drawing-item.h"
#include "attributes.h"
#include "document.h"
#include "uri.h"
#include "inkscape.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "style.h"
#include "sp-root.h"
#include "sp-clippath.h"
#include "sp-mask.h"
#include "sp-rect.h"
#include "sp-use.h"
#include "sp-text.h"
#include "sp-item-rm-unsatisfied-cns.h"
#include "sp-pattern.h"
#include "sp-paint-server.h"
#include "sp-switch.h"
#include "sp-guide-constraint.h"
#include "gradient-chemistry.h"
#include "preferences.h"
#include "conn-avoid-ref.h"
#include "conditions.h"
#include "sp-filter-reference.h"
#include "filter-chemistry.h"
#include "sp-guide.h"
#include "sp-title.h"
#include "sp-desc.h"
#include "util/find-last-if.h"
#include "util/reverse-list.h"
#include "extract-uri.h"
#include "live_effects/lpeobject.h"
#include "live_effects/effect.h"
#include "live_effects/lpeobject-reference.h"
#define noSP_ITEM_DEBUG_IDLE
/**
* Registers SPItem class and returns its type number.
*/
{
if (!type) {
sizeof(SPItemClass),
sizeof(SPItem),
16,
NULL, /* value_table */
};
}
return type;
}
/**
* SPItem vtable initialization.
*/
void
{
//sp_object_class->build = SPItem::sp_item_build;
// sp_object_class->release = SPItem::sp_item_release;
// sp_object_class->set = SPItem::sp_item_set;
// sp_object_class->update = SPItem::sp_item_update;
// sp_object_class->write = SPItem::sp_item_write;
// klass->description = SPItem::sp_item_private_description;
// klass->snappoints = SPItem::sp_item_private_snappoints;
}
// CPPIFY: remove
}
}
/**
* Callback for SPItem object initialization.
*/
{
}
bbox_valid = FALSE;
transform_center_x = 0;
transform_center_y = 0;
_is_evaluated = true;
freeze_stroke_width = false;
clip_ref = new SPClipPathReference(this);
mask_ref = new SPMaskReference(this);
avoidRef = new SPAvoidRef(this);
}
bool SPItem::isVisibleAndUnlocked() const {
}
}
return true;
}
}
return false;
}
setAttribute("sodipodi:insensitive",
updateRepr();
}
if (!isEvaluated())
return true;
}
updateRepr();
}
if (!isEvaluated())
return true;
{
return true;
}
}
return false;
}
}
return true;
}
}
void SPItem::resetEvaluated() {
if ( StatusCalculated == _evaluated_status ) {
bool oldValue = _is_evaluated;
if ( oldValue != isEvaluated() ) {
}
} if ( StatusSet == _evaluated_status ) {
if (SP_IS_SWITCH(parent)) {
}
}
}
bool SPItem::isEvaluated() const {
if ( StatusUnknown == _evaluated_status ) {
_is_evaluated = sp_item_evaluate(this);
}
return _is_evaluated;
}
/**
* Returns something suitable for the `Hide' checkbox in the Object Properties dialog box.
* Corresponds to setExplicitlyHidden.
*/
bool SPItem::isExplicitlyHidden() const
{
}
/**
* Sets the display CSS property to `hidden' if \a val is true,
* otherwise makes it unset
*/
updateRepr();
}
/**
* Sets the transform_center_x and transform_center_y properties to retain the rotation centre
*/
// FIXME this is seriously wrong
if (bbox) {
transform_center_x = 0;
transform_center_y = 0;
}
}
void
SPItem::unsetCenter() {
transform_center_x = 0;
transform_center_y = 0;
}
bool SPItem::isCenterSet() {
return (transform_center_x != 0 || transform_center_y != 0);
}
// FIXME this is seriously wrong
if (bbox) {
} else {
}
}
namespace {
return SP_IS_ITEM(&object);
}
}
void SPItem::raiseToTop() {
);
if (topmost) {
}
}
);
if (next_higher) {
}
}
parent->firstChild(), this
),
MutableList<SPObject &>(),
);
if (next_lower) {
++next_lower;
}
}
void SPItem::lowerToBottom() {
parent->firstChild(), this
),
MutableList<SPObject &>(),
);
if (bottom) {
++bottom;
}
}
/*
* Move this SPItem into or after another SPItem in the doc
* \param target - the SPItem to move into or after
* \param intoafter - move to after the target (false), move inside (sublayer) of the target (true)
*/
if (target_ref == our_ref) {
// Move to ourself ignore
return;
}
if (!target_ref) {
// Assume move to the "first" in the top node, find the top node
}
}
if (intoafter) {
// Move this inside of the target at the end
// Change in parent, need to remove and add
} else if (!first) {
// Same parent, just move
}
// If "first" ensure it appears after the defs etc
return;
}
}
}
// CPPIFY: remove
//void SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
//{
// ((SPItem*)object)->citem->onBuild(document, repr);
//}
// Note: do this here before the clip_ref is deleted, since calling
// ensureUpToDate() for triggered routing may reference
// the deleted clip_ref.
// we do NOT disconnect from the changed signal of those before deletion.
// The destructor will call *_ref_changed with NULL as the new value,
// which will cause the hide() function to be called.
}
}
// CPPIFY: remove
{
}
switch (key) {
case SP_ATTR_TRANSFORM: {
item->set_item_transform(t);
} else {
}
break;
}
case SP_PROP_CLIP_PATH: {
if (uri) {
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
}
break;
}
case SP_PROP_MASK: {
if (uri) {
try {
} catch (Inkscape::BadURIException &e) {
}
} else {
}
break;
}
}
break;
case SP_ATTR_CONNECTOR_AVOID:
break;
break;
if (value) {
} else {
item->transform_center_x = 0;
}
break;
if (value) {
} else {
item->transform_center_y = 0;
}
break;
case SP_PROP_SYSTEM_LANGUAGE:
{
item->resetEvaluated();
// pass to default handler
}
default:
if (SP_ATTRIBUTE_IS_CSS(key)) {
} else {
}
break;
}
}
// CPPIFY: remove
{
}
{
if (old_clip) {
SPItemView *v;
/* Hide clippath */
}
}
if (SP_IS_CLIPPATH(clip)) {
}
}
}
}
{
if (old_mask) {
/* Hide mask */
}
}
if (SP_IS_MASK(mask)) {
}
}
}
}
// CPPIFY: As CItem is derived directly from CObject, this doesn't make no sense.
// CObject::onUpdate is pure. What was the idea behind these lines?
// if (((SPObjectClass *) (SPItemClass::static_parent_class))->update) {
// (* ((SPObjectClass *) (SPItemClass::static_parent_class))->update)(object, ctx, flags);
// }
// CObject::onUpdate(ctx, flags);
// any of the modifications defined in sp-object.h might change bbox,
// so we invalidate it unconditionally
if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG | SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG)) {
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
}
if (clip_path) {
}
}
if (mask) {
}
}
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
}
}
}
/* Update bounding box data used by filters */
do {
}
// Update libavoid with item geometry (for connector routing).
}
// CPPIFY: remove
{
}
Inkscape::XML::Node* CItem::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
// in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created,
// so we need to add any children from the underlying object to the new repr
if (flags & SP_OBJECT_WRITE_BUILD) {
if (crepr) {
l = g_slist_prepend (l, crepr);
}
}
}
while (l) {
l = g_slist_remove (l, l->data);
}
} else {
}
}
}
g_free(c);
if (flags & SP_OBJECT_WRITE_EXT) {
if (item->transform_center_x != 0)
else
if (item->transform_center_y != 0)
else
}
}
}
}
}
return repr;
}
// CPPIFY: remove
Inkscape::XML::Node *SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
{
}
// CPPIFY: make pure virtual
//throw;
}
/**
* Get item's geometric bounding box in this item's coordinate system.
*
* The geometric bounding box includes only the path, disregarding all style attributes.
*/
{
// call the subclass method
return bbox;
}
/**
* Get item's visual bounding box in this item's coordinate system.
*
* The visual bounding box includes the stroke and the filter region.
*/
{
using Geom::X;
using Geom::Y;
// call the subclass method
// default filer area per the SVG spec:
SVGLength x, y, w, h;
// if area is explicitly set, override:
x = filter->x;
y = filter->y;
}
} else {
// call the subclass method
}
}
return bbox;
}
{
if (type == GEOMETRIC_BBOX) {
return geometricBounds(transform);
} else {
return visualBounds(transform);
}
}
/** Get item's geometric bbox in document coordinate system.
* Document coordinates are the default coordinates of the root element:
* the origin is at the top left, X grows to the right and Y grows downwards. */
{
return geometricBounds(i2doc_affine());
}
/// Get item's visual bbox in document coordinate system.
{
if (!bbox_valid) {
bbox_valid = true;
}
return doc_bbox;
}
{
if (type == GEOMETRIC_BBOX) {
return documentGeometricBounds();
} else {
return documentVisualBounds();
}
}
/** Get item's geometric bbox in desktop coordinate system.
* Desktop coordinates should be user defined. Currently they are hardcoded:
* origin is at bottom left, X grows to the right and Y grows upwards. */
{
return geometricBounds(i2dt_affine());
}
/// Get item's visual bbox in desktop coordinate system.
{
/// @fixme hardcoded desktop transform
return ret;
}
{
} else {
}
}
{
if (type == GEOMETRIC_BBOX) {
return desktopGeometricBounds();
} else {
return desktopVisualBounds();
}
}
unsigned SPItem::pos_in_parent()
{
unsigned pos=0;
return pos;
}
if (SP_IS_ITEM(iter)) {
pos++;
}
}
return 0;
}
// CPPIFY: make pure virtual, see below!
void CItem::onSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) {
//throw;
}
// CPPIFY: remove
//void SPItem::sp_item_private_snappoints(SPItem const * /*item*/, std::vector<Inkscape::SnapCandidatePoint> &/*p*/, Inkscape::SnapPreferences const * /*snapprefs*/)
//{
/* This will only be called if the derived class doesn't override this.
* see for example sp_genericellipse_snappoints in sp-ellipse.cpp
* We don't know what shape we could be dealing with here, so we'll just
* do nothing
*/
//}
void SPItem::getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const
{
// Get the snappoints of the item
// Get the snappoints at the item's center
p.push_back(Inkscape::SnapCandidatePoint(getCenter(), Inkscape::SNAPSOURCE_ROTATION_CENTER, Inkscape::SNAPTARGET_ROTATION_CENTER));
}
// Get the snappoints of clipping paths and mask, if any
for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); ++o) {
if (*o) {
// obj is a group object, the children are the actual clippers
if (SP_IS_ITEM(child)) {
// Please note the recursive call here!
// Take into account the transformation of the item being clipped or masked
for (std::vector<Inkscape::SnapCandidatePoint>::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); ++p_orig) {
// All snappoints are in desktop coordinates, but the item's transformation is
// in document coordinates. Hence the awkward construction below
p.push_back(Inkscape::SnapCandidatePoint(pt, (*p_orig).getSourceType(), (*p_orig).getTargetType()));
}
}
}
}
}
}
// CPPIFY: make pure virtual
//throw;
}
{
if ( !isHidden() ) {
} else {
}
}
}
// CPPIFY: is it possible to combine this method with "SPItem::description()"?
return g_strdup(_("Object"));
}
// CPPIFY: remove
//gchar *SPItem::sp_item_private_description(SPItem *item)
//{
// return item->citem->onDescription();
//}
/**
* Returns a string suitable for status bar, formatted in pango markup language.
*
* Must be freed by caller.
*/
{
g_free (s);
s = snew;
}
g_free (s);
s = snew;
}
if (label) {
} else {
}
g_free (s);
s = snew;
}
return s;
}
/**
* Returns 1 if the item is filtered, 0 otherwise. Used with groups/lists to determine how many, or if any, are filtered
*
*/
{
int retval=0;
retval=1;
}
return retval;
}
/**
* Allocates unique integer keys.
* \param numkeys Number of keys required.
* \return First allocated key; hence if the returned key is n
* you can use n, n + 1, ..., n + (numkeys - 1)
*/
{
static unsigned dkey = 0;
}
// CPPIFY: make pure virtual
Inkscape::DrawingItem* CItem::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) {
//throw;
return 0;
}
Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned key, unsigned flags)
{
}
// Show and set clip
// Update bbox, in case the clip uses bbox units
}
}
// Show and set mask
// Update bbox, in case the mask uses bbox units
}
}
return ai;
}
// CPPIFY: make pure virtual
//throw;
}
{
SPItemView *v = display;
while (v != NULL) {
}
}
if (!ref) {
} else {
}
delete v->arenaitem;
g_free(v);
} else {
ref = v;
}
v = next;
}
}
// Adjusters
{
if ( SP_IS_PATTERN(server) ) {
}
}
if ( SP_IS_PATTERN(server) ) {
}
}
}
{
if ( SP_IS_GRADIENT(server) ) {
/**
* \note Bbox units for a gradient are generally a bad idea because
* with them, you cannot preserve the relative position of the
* object and its gradient after rotation or skew. So now we
* convert them to userspace units which are easy to keep in sync
* just by adding the object's transform to gradientTransform.
* \todo FIXME: convert back to bbox units after transforming with
* the item, so as to preserve the original units.
*/
}
}
if ( SP_IS_GRADIENT(server) ) {
}
}
}
{
if (freeze_stroke_width) {
return;
}
}
}
updateRepr();
}
}
/**
* Find out the inverse of previous transform of an item (from its repr)
*/
{
if (t_attr) {
if (sp_svg_transform_read(t_attr, &t)) {
t_old = t;
}
}
return t_old;
}
/**
* Recursively scale stroke width in \a item and its children by \a expansion.
*/
{
// A clone's child is the ghost of its original - we must not touch it, skip recursion
if ( !SP_IS_USE(this) ) {
if (SP_IS_ITEM(o)) {
}
}
}
}
{
// A clone's child is the ghost of its original - we must not touch it, skip recursion
if ( !SP_IS_USE(this) ) {
if (SP_IS_ITEM(o)) {
}
}
}
}
/**
* Recursively adjust rx and ry of rects.
*/
void
{
if (SP_IS_RECT (item)) {
}
if (SP_IS_ITEM(o))
}
}
/**
* Recursively compensate pattern or gradient transform.
*/
void SPItem::adjust_paint_recursive (Geom::Affine advertized_transform, Geom::Affine t_ancestors, bool is_pattern)
{
// _After_ full pattern/gradient transform: t_paint_new * t_item * t_ancestors * advertised_transform
// By equating these two expressions we get t_paint_new = t_paint * paint_delta, where:
Geom::Affine paint_delta = t_item * t_ancestors * advertized_transform * t_ancestors.inverse() * t_item.inverse();
// Within text, we do not fork gradients, and so must not recurse to avoid double compensation;
// also we do not recurse into clones, because a clone's child is the ghost of its original -
// we must not touch it
if (!(this && (SP_IS_TEXT(this) || SP_IS_USE(this)))) {
if (SP_IS_ITEM(o)) {
// At the level of the transformed item, t_ancestors is identity;
// below it, it is the accmmulated chain of transforms from this level to the top level
}
}
}
// We recursed into children first, and are now adjusting this object second;
// this is so that adjustments in a tree are done from leaves up to the root,
// and paintservers on leaves inheriting their values from ancestors could adjust themselves properly
// before ancestors themselves are adjusted, probably differently (bug 1286535)
if (is_pattern) {
} else {
}
}
{
if ( SP_IS_LPE_ITEM(this) ) {
if ( sp_lpe_item_has_path_effect(lpeitem) ) {
// now that all LPEs are forked_if_necessary, we can apply the transform
{
}
}
}
}
}
// CPPIFY:: make pure virtual?
// Not all SPItems must necessarily have a set transform method!
// throw;
return transform;
}
/**
* Set a new transform on an object.
*
* necessary. Call the object's set_transform method if transforms are
* stored optimized. Send _transformed_signal. Invoke _write method so that
* the repr is updated with the new transform.
*/
void SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Affine const &transform, Geom::Affine const *adv, bool compensate)
{
// calculate the relative transform, if not given by the adv attribute
} else {
}
if (compensate) {
// recursively compensating for stroke scaling will not always work, because it can be scaled to zero or infinite
// from which we cannot ever recover by applying an inverse scale; therefore we temporarily block any changes
// to the strokewidth in such a case instead, and unblock these after the transformation
// (as reported in https://bugs.launchpad.net/inkscape/+bug/825840/comments/4)
// This will only work if the item has a set_transform method (in this method adjust_stroke() will be called)
// We will still have to apply the inverse scaling to other items, not having a set_transform method
// such as ellipses and stars
// PS: We cannot use this freeze_stroke_width_recursive() trick in all circumstances. For example, it will
// break pasting objects within their group (because in such a case the transformation of the group will affect
// the strokewidth, and has to be compensated for. See https://bugs.launchpad.net/inkscape/+bug/959223/comments/10)
} else {
}
}
}
// recursively compensate pattern fill if it's not to be transformed
}
/// \todo FIXME: add the same else branch as for gradients below, to convert patterns to userSpaceOnUse as well
/// recursively compensate gradient fill if it's not to be transformed
} else {
// it here _before_ the new transform is set, so as to use the pre-transform bbox
}
} // endif(compensate)
// CPPIFY: check this code.
// If onSetTransform is not overridden, CItem::onSetTransform will return the transform it was given as a parameter.
// onSetTransform cannot be pure due to the fact that not all visible Items are transformable.
if ( // run the object's set_transform (i.e. embed transform) only if:
!preserve && // user did not chose to preserve all transforms
!(!transform.isTranslation() && style && style->getFilter()) // the object does not have a filter, or the transform is translation (which is supposed to not affect filters)
) {
if (freeze_stroke_width) {
freeze_stroke_width_recursive(false);
}
} else {
if (freeze_stroke_width) {
freeze_stroke_width_recursive(false);
if (compensate) {
// Recursively compensate for stroke scaling, depending on user preference
// (As to why we need to do this, see the comment a few lines above near the freeze_stroke_width_recursive(true) call)
}
}
}
}
// Note: updateRepr comes before emitting the transformed signal since
// it causes clone SPUse's copy of the original object to brought up to
// date with the original. Otherwise, sp_use_bbox returns incorrect
// values if called in code handling the transformed signal.
updateRepr();
// send the relative transform with a _transformed_signal
}
// CPPIFY: see below, do not make pure?
return FALSE;
}
{
}
/**
* Sets item private transform (not propagated to repr), without compensating stroke widths,
* gradients, patterns as sp_item_write_transform does.
*/
{
/* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a
transformation. It's apparently not used anywhere else. */
sp_item_rm_unsatisfied_cns(*this);
}
}
void CItem::onConvertToGuides() {
// CPPIFY: If not overridden, call SPItem::convert_to_guides(), see below!
this->spitem->convert_to_guides();
}
// CPPIFY: remove
void SPItem::convert_item_to_guides() {
// // Use derived method if present ...
// if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides) {
// (*((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides)(this);
// } else {
// // .. otherwise simply place the guides around the item's bounding box
//
// convert_to_guides();
// }
this->citem->onConvertToGuides();
}
/**
* \pre \a ancestor really is an ancestor (\>=) of \a object, or NULL.
* ("Ancestor (\>=)" here includes as far as \a object itself.)
*/
/* stop at first non-renderable ancestor */
if (SP_IS_ROOT(object)) {
} else {
}
}
return ret;
}
}
return i2i_affine(this, dest);
}
/**
* Returns the accumulated transformation of the item and all its ancestors, including root's viewport.
* \pre (item != NULL) and SP_IS_ITEM(item).
*/
{
return i2anc_affine(this, NULL);
}
/**
* Returns the transformation from item to desktop coords
*/
{
if ( desktop ) {
} else {
// TODO temp code to prevent crashing on command-line launch:
ret = i2doc_affine()
}
return ret;
}
{
if (parent) {
} else {
}
}
/**
* should rather be named "sp_item_d2i_affine" to match "sp_item_i2d_affine" (or vice versa)
*/
{
/* fixme: Implement the right way (Lauris) */
return i2dt_affine().inverse();
}
/* Item views */
SPItemView *SPItem::sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, Inkscape::DrawingItem *drawing_item)
{
return new_view;
}
{
} else {
}
return ret;
}
/**
* Return the arenaitem corresponding to the given item in the display
* with the given key
*/
{
}
}
return NULL;
}
{
}
{
}
{
if ( SP_IS_ITEM(iter) ) {
break;
}
}
return child;
}
void SPItem::convert_to_guides() {
if (!bbox) {
g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
return;
}
}
/*
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 :