sp-shape.cpp revision 5209a05743e62584a7ec6afe050ffb0223f899f8
/*
* Base class for shapes, including <path> element
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2004 John Cliff
* Copyright (C) 2007-2008 Johan Engelen
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-translate-ops.h>
#include <libnr/nr-scale-matrix-ops.h>
#include "macros.h"
#include "display/nr-arena-shape.h"
#include "print.h"
#include "document.h"
#include "style.h"
#include "marker.h"
#include "sp-path.h"
#include "prefs-utils.h"
#include "attributes.h"
#include "live_effects/lpeobject.h"
#include "uri.h"
#include "extract-uri.h"
#include "uri-references.h"
#include "bad-uri-exception.h"
#define noSHAPE_VERBOSE
static Inkscape::XML::Node *sp_shape_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
static void sp_shape_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
static NRArenaItem *sp_shape_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
static SPLPEItemClass *parent_class;
/**
* Registers the SPShape class with Gdk and returns its type number.
*/
sp_shape_get_type (void)
{
if (!type) {
sizeof (SPShapeClass),
sizeof (SPShape),
16,
NULL, /* value_table */
};
}
return type;
}
/**
* Initializes a SPShapeClass object. Establishes the function pointers to the class'
* member routines in the class vtable, and sets pointers to parent classes.
*/
static void
{
}
/**
* Initializes an SPShape object.
*/
static void
{
for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
}
}
static void
{
for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
}
}
}
/**
* Virtual build callback for SPMarker.
*
* This is to be invoked immediately after creation of an SPShape.
*
* \see sp_object_build()
*/
static void
{
}
}
/**
* Removes, releases and unrefs all children of object
*
* This is the inverse of sp_shape_build(). It must be invoked as soon
* as the shape is removed from the tree, even if it is still referenced
* by other objects. This routine also disconnects/unrefs markers and
* curves attached to it.
*
* \see sp_object_release()
*/
static void
{
SPItemView *v;
int i;
for (i=SP_MARKER_LOC_START; i<SP_MARKER_LOC_QTY; i++) {
}
}
}
}
}
}
static void
{
}
}
{
}
return repr;
}
/**
* Updates the shape when its attributes have changed. Also establishes
* marker objects to match the style settings.
*/
static void
{
}
/* This stanza checks that an object's marker style agrees with
* the marker objects it has allocated. sp_shape_set_marker ensures
* that the appropriate marker objects are present (or absent) to
* match the style.
*/
/* TODO: It would be nice if this could be done at an earlier level */
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
}
}
}
}
/* This is suboptimal, because changing parent style schedules recalculation */
/* But on the other hand - how can we know that parent does not tie style and transform */
if (flags & SP_OBJECT_MODIFIED_FLAG) {
}
if (paintbox) {
s->setPaintBox(*paintbox);
}
}
}
if (sp_shape_has_markers (shape)) {
/* Dimension marker views */
/* Get enough keys for all, start, mid and end marker types,
** and set this view's arenaitem key to the first of these keys.
*/
v->arenaitem,
);
}
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
sp_shape_number_of_markers (shape, i));
}
}
}
/* Update marker views */
}
}
}
/**
* Works out whether a marker of a given type is required at a particular
* point on a shape.
*
* \param shape Shape of interest.
* \param m Marker type (e.g. SP_MARKER_LOC_START)
* \param bp Path segment.
* \return 1 if a marker is required here, otherwise 0.
*/
bool
{
return false;
}
return m == SP_MARKER_LOC_START;
return m == SP_MARKER_LOC_END;
else
return m == SP_MARKER_LOC_MID;
}
static bool
is_moveto(NRPathcode const c)
{
return c == NR_MOVETO || c == NR_MOVETO_OPEN;
}
/**
* Helper function that advances a subpath's bpath to the first subpath
* by checking for moveto segments.
*
* \pre The bpath[] containing bp begins with a moveto.
*/
static NArtBpath const *
{
--bp;
}
return bp;
}
/**
* Advances the bpath to the last segment in the subpath.
*/
static NArtBpath const *
{
for(;;) {
++bp;
case NR_MOVETO:
case NR_MOVETO_OPEN:
case NR_END:
--bp;
return bp;
default: continue;
}
}
}
/* A subpath begins with a moveto and ends immediately before the next moveto or NR_END.
* (`moveto' here means either NR_MOVETO or NR_MOVETO_OPEN.) I'm assuming that non-empty
* paths always begin with a moveto.
*
* The control points of the subpath are the control points of the path elements of the subpath.
*
* As usual, the control points of a moveto or NR_LINETO are {c(3)}, and
* the control points of a NR_CURVETO are {c(1), c(2), c(3)}.
* (It follows from the definition that NR_END isn't part of a subpath.)
*
* The initial control point is bpath[bi0].c(3).
*
* Reference: http://www.w3.org/TR/SVG11/painting.html#MarkerElement, the `orient' attribute.
* Reference for behaviour of zero-length segments:
* http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
*/
* i.e. outside of [-pi, pi]. This value is incremented by
* 1 and checked using > to be safe from floating-point
* equality comparison madness.*/
/**
* Helper function to calculate the outgoing tangent of a path
* ( atan2(other - p0) )
* \pre The bpath[] containing bp0 begins with a moveto.
*/
static double
{
/* See notes in comment block above. */
++bp;
case NR_LINETO:
goto found;
}
break;
case NR_CURVETO:
goto found;
}
}
break;
case NR_MOVETO_OPEN:
case NR_END:
case NR_MOVETO:
/* Gone right around the subpath without finding any different point since the
* initial moveto. */
return no_tangent + 1;
}
/* Open subpath. */
return no_tangent + 1;
}
goto found;
}
break;
}
/* Back where we started, so zero-length subpath. */
return no_tangent + 1;
/* Note: this test must come after we've looked at element bp, in case bp0 is a curve:
* we must look at c(1) and c(2). (E.g. single-curve subpath.)
*/
}
}
}
/**
* Helper function to calculate the incoming tangent of a path
* ( atan2(p0 - other) )
*
* \pre The bpath[] containing bp0 begins with a moveto.
*/
static double
{
/* See notes in comment block before outgoing_tangent. */
case NR_LINETO:
goto found;
}
--bp;
break;
case NR_CURVETO:
goto found;
}
}
--bp;
break;
case NR_MOVETO:
case NR_MOVETO_OPEN:
goto found;
}
/* Open subpath. */
return no_tangent + 1;
}
break;
default: /* includes NR_END */
return no_tangent + 1;
}
/* Back where we started from: zero-length subpath. */
return no_tangent + 1;
}
}
}
/**
* Calculate the transform required to get a marker's path object in the
* right place for particular path segment on a shape. You should
* call sp_shape_marker_required first to see if a marker is required
* at this point.
*
* \see sp_shape_marker_required.
*
* \param shape Shape which the marker is for.
* \param m Marker type (e.g. SP_MARKER_LOC_START)
* \param bp Path segment which the arrow is for.
* \return Transform matrix.
*/
{
double ret_angle;
if (angle1 > no_tangent) {
/* First vertex of an open subpath. */
? 0.
: angle2 );
} else if (angle2 > no_tangent) {
/* Last vertex of an open subpath. */
} else {
/* ret_angle is in the middle of the larger of the two sectors between angle1 and
* angle2, so flip it by 180degrees to force it to the middle of the smaller sector.
*
* (Imagine a circle with rays drawn at angle1 and angle2 from the centre of the
* circle. Those two rays divide the circle into two sectors.)
*/
}
}
}
/**
* Updates the instances (views) of a given marker in a shape.
* Marker views have to be scaled already. The transformation
* is retrieved and then shown by calling sp_marker_show_instance.
*/
static void
{
for (int i = SP_MARKER_LOC_START; i < SP_MARKER_LOC_QTY; i++) {
continue;
}
int n = 0;
NR_ARENA_ITEM_GET_KEY(ai) + i, n, m,
n++;
}
}
}
}
/**
* Sets modified flag for all sub-item views.
*/
static void
{
}
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
}
}
}
/**
* Calculates the bounding box for item, storing it into bbox.
* This also includes the bounding boxes of any markers included in the shape.
*/
static void sp_shape_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
{
}
}
}
// Union with bboxes of the markers, if any
if (sp_shape_has_markers (shape)) {
for (int m = SP_MARKER_LOC_START; m < SP_MARKER_LOC_QTY; m++) {
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
}
}
}
}
}
// copy our bbox to the variable we're given
}
}
/**
* Prepares shape for printing. Handles printing of comments for printing
* comment labels.
*/
void
{
gint add_comments = prefs_get_int_attribute_limited ("printing.debug", "add-label-comments", 0, 0, 1);
if (add_comments) {
}
/* fixme: Think (Lauris) */
}
}
for (int m = SP_MARKER_LOC_START; m < SP_MARKER_LOC_QTY; m++) {
}
}
}
}
if (add_comments) {
}
}
/**
* Sets style, path, and paintbox. Updates marker views, including dimensions.
*/
static NRArenaItem *
{
if (paintbox) {
s->setPaintBox(*paintbox);
}
if (sp_shape_has_markers (shape)) {
/* Dimension the marker views */
}
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
sp_shape_number_of_markers (shape, i));
}
}
/* Update marker views */
}
return arenaitem;
}
/**
*/
static void
{
SPItemView *v;
int i;
for (i=0; i<SP_MARKER_LOC_QTY; i++) {
NR_ARENA_ITEM_GET_KEY (v->arenaitem) + i);
}
}
}
}
}
}
/**
* \param shape Shape.
* \return TRUE if the shape has any markers, or FALSE if not.
*/
int
{
/* Note, we're ignoring 'marker' settings, which technically should apply for
all three settings. This should be fixed later such that if 'marker' is
specified, then all three should appear. */
return (
);
}
/**
* \param shape Shape.
* \param type Marker type (e.g. SP_MARKER_LOC_START)
* \return Number of markers that the shape has of this type.
*/
int
{
int n = 0;
n++;
}
}
return n;
}
/**
* Checks if the given marker is used in the shape, and if so, it
* releases it by calling sp_marker_hide. Also detaches signals
* and unrefs the marker from the shape.
*/
static void
{
int i;
for (i = SP_MARKER_LOC_START; i < SP_MARKER_LOC_QTY; i++) {
SPItemView *v;
/* Hide marker */
/* fixme: Do we need explicit remove here? (Lauris) */
/* nr_arena_item_set_mask (v->arenaitem, NULL); */
}
/* Detach marker */
}
}
}
/**
* No-op. Exists for handling 'modified' messages
*/
static void
{
/* I think mask does update automagically */
/* g_warning ("Item %s mask %s modified", SP_OBJECT_ID (item), SP_OBJECT_ID (mask)); */
}
/**
* Adds a new marker to shape object at the location indicated by key. value
* must be a valid URI reference resolvable from the shape object (i.e., present
* in the document <defs>). If the shape object already has a marker
* registered at the given position, it is removed first. Then the
* new marker is hrefed and its signals connected.
*/
void
{
return;
}
SPItemView *v;
/* Detach marker */
/* Hide marker */
/* fixme: Do we need explicit remove here? (Lauris) */
/* nr_arena_item_set_mask (v->arenaitem, NULL); */
}
/* Unref marker */
}
if (SP_IS_MARKER (mrk)) {
shape->release_connect[key] = mrk->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_shape_marker_release), shape));
shape->modified_connect[key] = mrk->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_shape_marker_modified), shape));
}
}
}
/* Shape section */
/**
* Calls any registered handlers for the set_shape action
*/
void
{
}
}
/**
* Adds a curve to the shape. If owner is specified, a reference
* will be made, otherwise the curve will be copied into the shape.
* Any existing curve in the shape will be unreferenced first.
* This routine also triggers a request to update the display.
*/
void
{
}
if (curve) {
if (owner) {
} else {
}
}
}
/**
* Return duplicate of curve (if any exists) or NULL if there is no curve
*/
SPCurve *
{
}
return NULL;
}
/**
* Same as sp_shape_set_curve but without updating the display
*/
void
{
}
if (curve) {
if (owner) {
} else {
}
}
}
/**
* Return all nodes in a path that are to be considered for snapping
*/
{
return;
}
// Cycle through the nodes in the concatenated subpaths
// NR_MOVETO Indicates the start of a closed subpath, see nr-path-code.h
// If we're looking at a closed subpath, then we can skip this first
// point of the subpath because it's coincident with the last point.
if (b->code == NR_MOVETO_OPEN || b->code == NR_LINETO || b[1].code == NR_LINETO || b[1].code == NR_END) {
// end points of a line segment are always considered for snapping
*p = pos;
} else {
// g_assert(b->code == NR_CURVETO);
// Determine whether a node is at a smooth part of the path, by
// calculating a measure for the collinearity of the handles
bool c1 = fabs (Inkscape::Util::triangle_area (pos, ppos, npos)) < 1; // points are (almost) collinear
bool c2 = NR::L2(pos - ppos) < 1e-6 || NR::L2(pos - npos) < 1e-6; // endnode, or a node with a retracted handle
*p = pos; // only return non-smooth nodes ("cusps")
}
}
}
b++;
}
}
/*
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 :