sp-item.cpp revision 61da78fae8529d195d3e8557c4867ca18c43ba98
/*
* 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
*/
#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 "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-textpath.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
SPItemView *view);
bbox_valid = FALSE;
transform_center_x = 0;
transform_center_y = 0;
freeze_stroke_width = false;
_is_evaluated = true;
// doc_bbox = Geom::OptRect();
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;
}
bool SPItem::isHighlightSet() const {
return _highlightColor != NULL;
}
if (_highlightColor)
{
}
else {
{
return item->highlight_color();
}
else
{
}
}
}
}
void SPItem::resetEvaluated() {
if ( StatusCalculated == _evaluated_status ) {
bool oldValue = _is_evaluated;
if ( oldValue != isEvaluated() ) {
}
} if ( StatusSet == _evaluated_status ) {
if (switchItem) {
}
}
}
bool SPItem::isEvaluated() const {
if ( StatusUnknown == _evaluated_status ) {
_is_evaluated = sp_item_evaluate(this);
}
return _is_evaluated;
}
bool SPItem::isExplicitlyHidden() const
{
}
updateRepr();
}
// Copied from DocumentProperties::onDocUnitChange()
if ( !vb.hasZeroArea() ) {
}
// FIXME this is seriously wrong
if (bbox) {
// object centre is document coordinates (i.e. in pixels), so we need to consider the viewbox
// to translate to user units; transform_center_x/y is in user units
transform_center_x = 0;
transform_center_y = 0;
}
}
void
SPItem::unsetCenter() {
transform_center_x = 0;
transform_center_y = 0;
}
bool SPItem::isCenterSet() const {
return (transform_center_x != 0 || transform_center_y != 0);
}
// Get the item's transformation center in document coordinates (i.e. in pixels)
// Copied from DocumentProperties::onDocUnitChange()
if ( !vb.hasZeroArea() ) {
}
// FIXME this is seriously wrong
if (bbox) {
// transform_center_x/y are stored in user units, so we have to take the viewbox into account to translate to document coordinates
} else {
}
}
void
}
namespace {
}
}
void SPItem::raiseToTop() {
);
if (topmost) {
}
}
);
if (next_higher) {
}
}
parent->firstChild(), this
),
MutableList<SPObject &>(),
);
if (next_lower) {
++next_lower;
}
}
void SPItem::lowerToBottom() {
while(dynamic_cast<SPObject*>(bottom) && dynamic_cast<SPObject*>(bottom->next) && bottom!=this && !is_item(*(bottom->next))) bottom=bottom->next;
}
}
if (!target_ref) {
// Assume move to the "first" in the top node, find the top node
intoafter = false;
}
}
if (target_ref == our_ref) {
// Move to ourself ignore
return;
}
if (intoafter) {
// Move this inside of the target at the end
// Change in parent, need to remove and add
} else {
// Same parent, just move
}
}
}
// 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.
if (fill_ps) {
}
if (stroke_ps) {
}
}
//item->_transformed_signal.~signal();
}
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;
}
{
if (value) {
} else {
}
break;
}
case SP_ATTR_CONNECTOR_AVOID:
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)) {
style->readFromObject( this );
} else {
}
break;
}
}
{
if (old_clip) {
SPItemView *v;
/* Hide clippath */
}
}
if (clipPath) {
}
}
}
}
{
if (old_mask) {
/* Hide mask */
}
}
if (maskItem) {
}
}
}
}
if (old_fill_ps) {
}
}
if (new_fill_ps) {
}
if (pi) {
}
}
}
}
if (old_stroke_ps) {
}
}
if (new_stroke_ps) {
}
if (pi) {
}
}
}
}
// Any of the modifications defined in sp-object.h might change bbox,
// so we invalidate it unconditionally
bbox_valid = FALSE;
if (flags & (SP_OBJECT_CHILD_MODIFIED_FLAG |
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
}
if (clip_path) {
}
}
if (mask) {
}
}
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
v->arenaitem->setAntialiasing(style->shape_rendering.computed != SP_CSS_SHAPE_RENDERING_CRISPEDGES);
}
}
}
/* Update bounding box in user space, used for filter and objectBoundingBox units */
do {
}
// Update libavoid with item geometry (for connector routing).
if (avoidRef)
}
{
}
Inkscape::XML::Node* SPItem::write(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
}
}
}
}
}
if (item->_highlightColor){
} else {
}
return repr;
}
// CPPIFY: make pure virtual
//throw;
}
{
// call the subclass method
// CPPIFY
//bbox = this->bbox(transform, SPItem::GEOMETRIC_BBOX);
return bbox;
}
{
using Geom::X;
using Geom::Y;
SPFilter *filter = (style && style->filter.href) ? dynamic_cast<SPFilter *>(style->getFilter()) : NULL;
if ( filter ) {
// call the subclass method
// CPPIFY
//bbox = this->bbox(Geom::identity(), SPItem::VISUAL_BBOX);
bbox = const_cast<SPItem*>(this)->bbox(Geom::identity(), SPItem::GEOMETRIC_BBOX); // see LP Bug 1229971
// 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
// CPPIFY
//bbox = this->bbox(transform, SPItem::VISUAL_BBOX);
}
}
return bbox;
}
{
if (type == GEOMETRIC_BBOX) {
return geometricBounds(transform);
} else {
return visualBounds(transform);
}
}
{
return geometricBounds(i2doc_affine());
}
{
if (!bbox_valid) {
bbox_valid = true;
}
return doc_bbox;
}
{
if (type == GEOMETRIC_BBOX) {
return documentGeometricBounds();
} else {
return documentVisualBounds();
}
}
{
return geometricBounds(i2dt_affine());
}
{
/// @fixme hardcoded desktop transform
return ret;
}
{
} else {
}
}
{
if (type == GEOMETRIC_BBOX) {
return desktopGeometricBounds();
} else {
return desktopVisualBounds();
}
}
unsigned int SPItem::pos_in_parent() const {
unsigned int pos = 0;
if (iter == this) {
return pos;
}
pos++;
}
}
return 0;
}
// CPPIFY: make pure virtual, see below!
void SPItem::snappoints(std::vector<Inkscape::SnapCandidatePoint> & /*p*/, Inkscape::SnapPreferences const */*snapprefs*/) const {
//throw;
}
/* 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
// CPPIFY
//this->snappoints(p, snapprefs);
// 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 (item) {
// 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 {
}
}
}
const char* SPItem::displayName() const {
return _("Object");
}
return g_strdup("");
}
this->displayName(), this->description());
g_free (s);
s = snew;
}
g_free (s);
s = snew;
}
if (label) {
} else {
}
g_free (s);
s = snew;
}
return s;
}
bool SPItem::isFiltered() const {
}
{
static unsigned dkey = 0;
}
// CPPIFY: make pure virtual
Inkscape::DrawingItem* SPItem::show(Inkscape::Drawing& /*drawing*/, unsigned int /*key*/, unsigned int /*flags*/) {
//throw;
return 0;
}
Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned key, unsigned flags)
{
//ai->setCompositeOperator( style->composite_op.value );
}
// 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
}
if (fill_ps) {
}
if (ap) {
}
}
if (stroke_ps) {
}
if (ap) {
}
}
}
return ai;
}
// CPPIFY: make pure virtual
//throw;
}
{
SPItemView *v = display;
while (v != NULL) {
}
}
if (fill_ps) {
}
if (stroke_ps) {
}
if (!ref) {
} else {
}
delete v->arenaitem;
g_free(v);
} else {
ref = v;
}
v = next;
}
}
// Adjusters
{
if ( serverPatt ) {
}
}
if ( serverPatt ) {
}
}
}
{
if ( serverGrad ) {
/**
* \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 ( serverGrad ) {
}
}
}
{
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;
}
{
// A clone's child is the ghost of its original - we must not touch it, skip recursion
if ( !dynamic_cast<SPUse *>(this) ) {
if (item) {
}
}
}
}
{
// A clone's child is the ghost of its original - we must not touch it, skip recursion
if ( !dynamic_cast<SPUse *>(this) ) {
if (item) {
}
}
}
}
/**
* Recursively adjust rx and ry of rects.
*/
static void
{
if (rect) {
}
if (item) {
}
}
}
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 (item) {
// 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 {
}
}
{
// 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;
}
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;
}
{
}
{
/* 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 SPItem::convert_to_guides() const {
// // CPPIFY: If not overridden, call SPItem::convert_to_guides() const, see below!
// this->convert_to_guides();
//}
/* stop at first non-renderable ancestor */
if (root) {
} else {
}
}
return ret;
}
}
return i2i_affine(this, dest);
}
{
return i2anc_affine(this, NULL);
}
{
if ( desktop ) {
} else {
// TODO temp code to prevent crashing on command-line launch:
ret = i2doc_affine()
}
return ret;
}
{
if (parent) {
} else {
}
}
{
/* 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;
}
static SPItemView*
{
} else {
}
return ret;
}
{
}
}
return NULL;
}
{
}
{
}
{
if ( tmp ) {
break;
}
}
return child;
}
void SPItem::convert_to_guides() const {
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 :