sp-shape.cpp revision b45b3ca12c271745b18a142d10a6ac8efd9f79cc
/*
* 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/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 "helper/geom-nodetype.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 "preferences.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, Geom::Matrix const &transform, unsigned const flags);
static NRArenaItem *sp_shape_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
static void sp_shape_snappoints (SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
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
{
}
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
}
}
/**
* 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 = 0; 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.
*/
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 */
}
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
NR_ARENA_ITEM_GET_KEY (v->arenaitem) + 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.)
*/
}
}
{
if ( !c.isDegenerate() ) {
} else {
/* FIXME: the svg spec says to search for a better alternative than zero angle directionality:
* http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes */
}
return ret;
}
{
if ( !c.isDegenerate() ) {
delete c_reverse;
} else {
/* FIXME: the svg spec says to search for a better alternative than zero angle directionality:
* http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes */
}
return ret;
}
/**
* 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 figure out what to do when both 'marker' and for instance 'marker-end' are set.
*/
static void
{
// position arguments to sp_marker_show_instance, basically counts the amount of markers.
int counter[4] = {0};
// START position
for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
counter[i]++;
}
}
// MID position
if ( (shape->marker[SP_MARKER_LOC_MID] || shape->marker[SP_MARKER_LOC]) && (path_it->size_default() > 1) ) {
{
/* 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
*/
for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
counter[i]++;
}
}
++curve_it1;
++curve_it2;
}
}
// END position
/* Get reference to last curve in the path.
* For moveto-only path, this returns the "closing line segment". */
if (index > 0) {
index--;
}
for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
counter[i]++;
}
}
}
}
}
/**
* 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, Geom::Matrix const &transform, unsigned const flags)
{
if (geombbox) {
}
}
}
// 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! */
for (unsigned i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
if (marker_item) {
if (!marker->orient_auto) {
}
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
}
}
}
for (unsigned i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
{
/* 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 */
if (marker_item) {
if (!marker->orient_auto) {
}
}
// total marker transform
// get bbox of the marker with that transform
// union it with the shape bbox
}
++curve_it1;
++curve_it2;
}
}
}
for (unsigned i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
if (marker_item) {
/* Get reference to last curve in the path.
* For moveto-only path, this returns the "closing line segment". */
if (index > 0) {
index--;
}
if (!marker->orient_auto) {
}
}
// 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
}
}
}
static void
sp_shape_print_invoke_marker_printing(SPObject* obj, Geom::Matrix tr, SPStyle* style, SPPrintContext *ctx) {
}
}
/**
* Prepares shape for printing. Handles printing of comments for printing
* comment labels.
*/
void
{
if (add_comments) {
}
/* fixme: Think (Lauris) */
}
}
/* TODO: make code prettier: lots of variables can be taken out of the loop! */
}
}
}
if ( (shape->marker[SP_MARKER_LOC_MID] || shape->marker[SP_MARKER_LOC]) && (path_it->size_default() > 1) ) {
{
/* 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;
}
}
/* Get reference to last curve in the path.
* For moveto-only path, this returns the "closing line segment". */
if (index > 0) {
index--;
}
}
}
}
}
if (add_comments) {
}
}
/**
* Sets style, path, and paintbox. Updates marker views, including dimensions.
*/
static NRArenaItem *
{
if (paintbox) {
s->setPaintBox(*paintbox);
}
/* 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.
*/
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
}
if (sp_shape_has_markers (shape)) {
/* provide key and dimension the marker views */
}
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
NR_ARENA_ITEM_GET_KEY (arenaitem) + 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:
{
}
return n;
} else {
return 0;
}
}
case SP_MARKER_LOC_START:
case SP_MARKER_LOC_MID:
{
guint n = 0;
}
return n;
} else {
return 0;
}
}
case SP_MARKER_LOC_END:
{
}
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 = 0; 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
{
if (key > SP_MARKER_LOC_END) {
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
*/
static void sp_shape_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs)
{
return;
}
// Help enforcing strict snapping, i.e. only return nodes when we're snapping nodes to nodes or a guide to nodes
return;
}
return;
int type;
if (snapprefs->getSnapObjectMidpoints()) {
if (bbox) {
type = target ? int(Inkscape::SNAPTARGET_OBJECT_MIDPOINT) : int(Inkscape::SNAPSOURCE_OBJECT_MIDPOINT);
}
}
if (snapprefs->getSnapToItemNode()) {
}
{
/* Test whether to add the node between curve_it1 and curve_it2.
* Loop to end_closed (so always including closing segment); the last node to be added
* is the node between the closing segment and the segment before that, regardless
* of the path being closed or not. If the path is closed, the final point was already added by
* adding the initial point. */
bool c1 = snapprefs->getSnapToItemNode() && (nodetype == Geom::NODE_CUSP || nodetype == Geom::NODE_NONE);
bool c2 = snapprefs->getSnapSmoothNodes() && (nodetype == Geom::NODE_SMOOTH || nodetype == Geom::NODE_SYMM);
}
// Consider midpoints of line segments for snapping
if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
if (Geom::LineSegment const* line_segment = dynamic_cast<Geom::LineSegment const*>(&(*curve_it1))) {
}
}
++curve_it1;
++curve_it2;
}
// Find the internal intersections of each path and consider these for snapping
// (using "Method 1" as described in Inkscape::ObjectSnapper::_collectNodes())
if (snapprefs->getSnapIntersectionCS()) {
type = target ? int(Inkscape::SNAPTARGET_PATH_INTERSECTION) : int(Inkscape::SNAPSOURCE_PATH_INTERSECTION);
}
}
}
}
}
/*
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 :