/*
* Base class for shapes, including <path> element
*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
* Abhishek Sharma
*
* Copyright (C) 1999-2002 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2004 John Cliff
* Copyright (C) 2007-2008 Johan Engelen
* Copyright (C) 2010 Jon A. Cruz <jon@joncruz.org>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "helper/geom-nodetype.h"
#include "macros.h"
#include "display/drawing-shape.h"
#include "print.h"
#include "document.h"
#include "style.h"
#include "sp-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"
#include "splivarot.h" // for bounding box calculation
#define noSHAPE_VERBOSE
for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
}
this->_curve_before_lpe = NULL;
}
for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) {
this->_release_connect[i].disconnect();
this->_modified_connect[i].disconnect();
}
}
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 SPObject::release()
*/
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
if (this->_marker[i]) {
}
this->_release_connect[i].disconnect();
this->_modified_connect[i].disconnect();
}
}
if (this->_curve) {
}
if (this->_curve_before_lpe) {
}
}
}
Inkscape::XML::Node* SPShape::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
return repr;
}
// std::cout << "SPShape::update(): " << (getId()?getId():"null") << std::endl;
/* 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 (hasMarkers()) {
this->context_style = this->style;
// Done at end:
// sh->setChildrenStyle(this->context_style); //Resolve 'context-xxx' in children.
} else if (this->parent) {
}
}
}
}
/* 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 (this->hasMarkers ()) {
/* Dimension marker views */
}
for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
if (_marker[i]) {
numberOfMarkers(i));
}
}
}
/* Update marker views */
sp_shape_update_marker_view (this, v->arenaitem);
}
// Marker selector needs this here or marker previews are not rendered.
}
}
}
/**
* 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;
/* 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.
// the first vertex should get a start marker, the last an end marker, and all the others a mid marker
// see bug 456148
// START marker
{
for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
// Reverse start marker if necessary.
}
counter[i]++;
}
}
}
// MID marker
// START position
&& ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, don't draw mid marker there
{
for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
counter[i]++;
}
}
}
// MID position
{
/* 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
for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
counter[i]++;
}
}
}
}
}
// END marker
/* 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]++;
}
}
}
}
// std::cout << "SPShape::modified(): " << (getId()?getId():"null") << std::endl;
if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
if (hasMarkers()) {
this->context_style = this->style;
// Note: marker selector preview does not trigger SP_OBJECT_STYLE_MODIFIED_FLAG so
// this is not called when marker previews are generated, however there is code in
// SPShape::update() that calls this routine so we don't worry about it here.
} else if (this->parent) {
}
}
}
}
if (!this->_curve) {
return bbox;
}
if (!bbox) {
return bbox;
}
// convert the stroke to a path and calculate that path's geometric bbox
if (pathv) {
delete pathv;
}
}
// Union with bboxes of the markers, if any
/** \todo make code prettier! */
// START marker
for (unsigned i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
if ( this->_marker[i] ) {
if (marker_item) {
// Reverse start marker if necessary
}
}
// total marker transform
// get bbox of the marker with that transform
}
}
}
// MID marker
for (unsigned i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
if ( !this->_marker[i] ) {
continue;
}
if ( !marker_item ) {
continue;
}
// START position
&& ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there
{
}
}
}
// MID position
{
/* 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) {
}
}
}
++curve_it1;
++curve_it2;
}
}
// END position
}
}
}
}
}
// END marker
for (unsigned i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
if ( _marker[i] ) {
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--;
}
}
}
// total marker transform
// get bbox of the marker with that transform
}
}
}
}
}
return bbox;
}
static void
sp_shape_print_invoke_marker_printing(SPObject *obj, Geom::Affine tr, SPStyle const *style, SPPrintContext *ctx)
{
}
if (marker_item) {
}
}
if (!this->_curve) {
return;
}
return;
}
if (add_comments) {
}
/* fixme: Think (Lauris) */
pbox = this->geometricBounds();
bbox = this->desktopVisualBounds();
}
}
/** \todo make code prettier */
// START marker
for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
if ( this->_marker[i] ) {
}
}
// MID marker
for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
if (this->_marker[i]) {
// START position
&& ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there
{
}
// MID position
{
/* 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;
}
}
}
}
}
}
// END marker
/* 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
if (this->_marker[i]) {
}
}
}
if (add_comments) {
this->defaultLabel());
}
}
Inkscape::DrawingItem* SPShape::show(Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/) {
// std::cout << "SPShape::show(): " << (getId()?getId():"null") << std::endl;
/* 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 (has_markers) {
/* provide key and dimension the marker views */
if (!s->key()) {
}
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
if (_marker[i]) {
s->key() + i,
numberOfMarkers(i));
}
}
/* Update marker views */
sp_shape_update_marker_view (this, s);
this->context_style = this->style;
} else if (this->parent) {
}
return s;
}
/**
* Sets style, path, and paintbox. Updates marker views, including dimensions.
*/
for (int i = 0; i < SP_MARKER_LOC_QTY; ++i) {
if (_marker[i]) {
}
}
}
}
//SPLPEItem::onHide(key);
}
/**
* \param shape Shape.
* \return TRUE if the shape has any markers, or FALSE if not.
*/
{
/* 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. */
// Ignore markers for objects which are inside markers themselves.
return 0;
}
}
return (
this->_curve &&
(this->_marker[SP_MARKER_LOC] ||
this->_marker[SP_MARKER_LOC_START] ||
this->_marker[SP_MARKER_LOC_MID] ||
this->_marker[SP_MARKER_LOC_END])
);
}
/**
* \param shape Shape.
* \param type Marker type (e.g. SP_MARKER_LOC_START)
* \return Number of markers that the shape has of this type.
*/
return 0;
}
switch(type) {
case SP_MARKER_LOC:
{
if ( this->_marker[SP_MARKER_LOC] ) {
guint n = 0;
}
return n;
} else {
return 0;
}
}
case SP_MARKER_LOC_START:
// there is only a start marker on the first path of a pathvector
case SP_MARKER_LOC_MID:
{
if ( this->_marker[SP_MARKER_LOC_MID] ) {
guint n = 0;
}
n = (n > 1) ? (n - 2) : 0; // Minus the start and end marker, but never negative.
// A path or polyline may have only one point.
return n;
} else {
return 0;
}
}
case SP_MARKER_LOC_END:
{
// there is only an end marker on the last path of a pathvector
}
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
{
for (int i = 0; i < SP_MARKER_LOC_QTY; i++) {
SPItemView *v;
/* Hide marker */
}
/* Detach marker */
}
}
}
/**
* No-op. Exists for handling 'modified' messages
*/
static void
{
/* I think mask does update automagically */
/* g_warning ("Item %s mask %s modified", item->getId(), mask->getId()); */
}
/**
* 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 */
}
/* Unref marker */
}
if (marker) {
shape->_release_connect[key] = marker->connectRelease(sigc::bind<1>(sigc::ptr_fun(&sp_shape_marker_release), shape));
shape->_modified_connect[key] = marker->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_shape_marker_modified), shape));
}
}
}
// CPPIFY: make pure virtual
//throw;
}
/* Shape section */
/**
* Calls any registered handlers for the set_shape action
*/
/**
* 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.
*/
{
if (_curve) {
}
if (new_curve) {
if (owner) {
} else {
}
}
}
/**
* Sets _curve_before_lpe to refer to the curve.
*/
void
{
if (_curve_before_lpe) {
}
if (new_curve) {
}
}
/**
* Return duplicate of curve (if any exists) or NULL if there is no curve
*/
{
if (_curve) {
}
return NULL;
}
/**
* Return duplicate of curve *before* LPE (if any exists) or NULL if there is no curve
*/
{
if (hasPathEffect()) {
if (_curve_before_lpe) {
return this->_curve_before_lpe->copy();
}
} else {
if (_curve) {
}
}
return NULL;
}
/**
* Same as sp_shape_set_curve but without updating the display
*/
{
if (_curve) {
}
if (new_curve) {
if (owner) {
} else {
}
}
}
void SPShape::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const {
return;
}
return;
}
if (bbox) {
p.push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
}
}
// Add the first point of the path
p.push_back(Inkscape::SnapCandidatePoint(path_it->initialPoint() * i2dt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP));
}
{
// For each path: consider midpoints of line segments for snapping
if (Geom::LineSegment const* line_segment = dynamic_cast<Geom::LineSegment const*>(&(*curve_it1))) {
p.push_back(Inkscape::SnapCandidatePoint(Geom::middle_point(*line_segment) * i2dt, Inkscape::SNAPSOURCE_LINE_MIDPOINT, Inkscape::SNAPTARGET_LINE_MIDPOINT));
}
}
if (curve_it2 == path_it->end_default()) { // Test will only pass for the last iteration of the while loop
// Add the last point of the path, but only for open paths
// (for closed paths the first and last point will coincide)
p.push_back(Inkscape::SnapCandidatePoint((*curve_it1).finalPoint() * i2dt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP));
}
} else {
/* Test whether to add the node between curve_it1 and curve_it2.
* Loop to end_default (so only iterating through the stroked part); */
bool c1 = snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && (nodetype == Geom::NODE_CUSP || nodetype == Geom::NODE_NONE);
bool c2 = snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_SMOOTH) && (nodetype == Geom::NODE_SMOOTH || nodetype == Geom::NODE_SYMM);
switch (nodetype) {
break;
case Geom::NODE_SMOOTH:
break;
default:
break;
}
}
}
++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->isTargetSnappable(Inkscape::SNAPTARGET_PATH_INTERSECTION) || snapprefs->isSourceSnappable(Inkscape::SNAPSOURCE_PATH_INTERSECTION)) {
try {
p.push_back(Inkscape::SnapCandidatePoint(p_ix * i2dt, Inkscape::SNAPSOURCE_PATH_INTERSECTION, Inkscape::SNAPTARGET_PATH_INTERSECTION));
}
}
} catch (Geom::RangeError &e) {
// do nothing
// The exception could be Geom::InfiniteSolutions: then no snappoints should be added
}
}
}
}
/*
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:fileencoding=utf-8:textwidth=99 :