sp-shape.cpp revision a950d99f377922f93d802d8ad56fa93290581660
/*
* 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::Document *doc, 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
{
}
}
sp_shape_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
{
}
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 */
}
}
}
/**
* Calculate the transform required to get a marker's path object in the
* right place for particular path segment on a shape.
*
* \see sp_shape_marker_update_marker_view.
*
* From SVG spec:
* The axes of the temporary new user coordinate system are aligned according to the orient attribute on the 'marker'
* element and the slope of the curve at the given vertex. (Note: if there is a discontinuity at a vertex, the slope
* is the average of the slopes of the two segments of the curve that join at the given vertex. If a slope cannot be
* determined, the slope is assumed to be zero.)
*
* 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
*/
{
delete c1_reverse;
double ret_angle;
/* 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.)
*/
}
}
{
}
{
delete c_reverse;
}
/**
* 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.
*
* TODO: correctly handle the 'marker' attribute.
* "Using the marker property from a style sheet is equivalent to using all three (start, mid, end)."
* See painting-marker-03-f.svg in SVG 1.1 Full test suite.
*/
static void
{
// position arguments to sp_marker_show_instance, basically counts the amount of markers.
int start_pos = 0;
int mid_pos = 0;
int end_pos = 0;
start_pos++;
}
{
/* Put marker between curve_it1 and curve_it2.
* Loop to end_default (so including closing segment), because when a path is closed,
* there should be a midpoint marker between last segment and closing straight line segment
*/
mid_pos++;
++curve_it1;
++curve_it2;
}
}
end_pos++;
}
}
}
/**
* 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)
{
Geom::Rect geombbox = bounds_exact_transformed(shape->curve->get_pathvector(), to_2geom(transform));
}
}
}
// Union with bboxes of the markers, if any
if (sp_shape_has_markers (shape)) {
/* TODO: make code prettier: lots of variables can be taken out of the loop! */
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
}
{
/* Put marker between curve_it1 and curve_it2.
* Loop to end_default (so including closing segment), because when a path is closed,
* there should be a midpoint marker between last segment and closing straight line segment */
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
++curve_it1;
++curve_it2;
}
}
}
// 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) */
}
}
/* TODO: make code prettier: lots of variables can be taken out of the loop! */
}
}
{
/* Put marker between curve_it1 and curve_it2.
* Loop to end_default (so including closing segment), because when a path is closed,
* there should be a midpoint marker between last segment and closing straight line segment */
}
++curve_it1;
++curve_it2;
}
}
}
}
}
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
{
switch(type) {
case SP_MARKER_LOC_START:
case SP_MARKER_LOC_MID:
{
guint n = 0;
}
return n;
} else {
return 0;
}
}
case SP_MARKER_LOC_END:
{
guint n = 0;
n++;
}
}
return n;
} else {
return 0;
}
}
default:
return 0;
}
}
/**
* 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 :