nodepath.cpp revision 7e417fb969db6e58d87411bfb9d607b69ec040c9
#define __SP_NODEPATH_C__
/** \file
* Path handler in node edit mode
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Portions of this code are in public domain; node sculpting functions written by bulia byak are under GNU GPL
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gdk/gdkkeysyms.h>
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include "libnr/n-art-bpath.h"
#include "knot.h"
#include "inkscape.h"
#include "document.h"
#include "sp-namedview.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "snap.h"
#include "message-stack.h"
#include "message-context.h"
#include "node-context.h"
#include "selection-chemistry.h"
#include "selection.h"
#include "prefs-utils.h"
#include "sp-metrics.h"
#include "sp-path.h"
#include "libnr/nr-matrix-ops.h"
#include "splivarot.h"
#include "display/bezier-utils.h"
#include <vector>
#include <algorithm>
/// \todo
/// evil evil evil. FIXME: conflict of two different Path classes!
/// There is a conflict in the namespace between two classes named Path.
/// #include "sp-flowtext.h"
/// #include "sp-flowregion.h"
#define SP_TYPE_FLOWREGION (sp_flowregion_get_type ())
GType sp_flowregion_get_type (void);
#define SP_TYPE_FLOWTEXT (sp_flowtext_get_type ())
GType sp_flowtext_get_type (void);
// end evil workaround
/// \todo fixme: Implement these via preferences */
#define NODE_FILL 0xbfbfbf00
#define NODE_STROKE 0x000000ff
#define NODE_FILL_HI 0xff000000
#define NODE_STROKE_HI 0x000000ff
#define NODE_FILL_SEL 0x0000ffff
#define NODE_STROKE_SEL 0x000000ff
#define NODE_FILL_SEL_HI 0xff000000
#define NODE_STROKE_SEL_HI 0x000000ff
#define KNOT_FILL 0xffffffff
#define KNOT_STROKE 0x000000ff
#define KNOT_FILL_HI 0xff000000
#define KNOT_STROKE_HI 0x000000ff
/* Creation from object */
/* Object updating */
static void sp_nodepath_node_select(Inkscape::NodePath::Node *node, gboolean incremental, gboolean override);
/* Adjust handle placement, if the node or the other handle is moved */
/* Node event callbacks */
/* Handle event callbacks */
/* Constructors and destructors */
static Inkscape::NodePath::Node * sp_nodepath_node_new(Inkscape::NodePath::SubPath *sp,Inkscape::NodePath::Node *next,Inkscape::NodePath::NodeType type, NRPathcode code,
/* Helpers */
static Inkscape::NodePath::NodeSide *sp_node_opposite_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me);
static NRPathcode sp_node_path_code_from_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me);
// active_node indicates mouseover node
/**
* \brief Creates new nodepath from item
*/
{
/** \todo
* FIXME: remove this. We don't want to edit paths inside flowtext.
* Instead we will build our flowtext with cloned paths, so that the
* real paths are outside the flowtext and thus editable as usual.
*/
if (SP_IS_FLOWTEXT(item)) {
for (SPObject *child = sp_object_first_child(SP_OBJECT(item)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if SP_IS_FLOWREGION(child) {
break;
}
}
}
}
if (!SP_IS_PATH(item))
return NULL;
return NULL;
if (length == 0)
return NULL; // prevent crash for one-node paths
//Create new nodepath
if (!np)
return NULL;
// Set defaults
np->local_change = 0;
// we need to update item's transform from the repr here,
// because they may be out of sync when we respond
// to a change in repr by regenerating nodepath --bb
// create the subpath(s) from the bpath
}
// reverse the list, because sp_nodepath_subpath_new() used g_list_prepend instead of append (for speed)
// create the livarot representation from the same item
if (np->livarot_path)
return np;
}
/**
* Destroys nodepath's subpaths, then itself, also tell context about it.
*/
if (!np) //soft fail, like delete
return;
}
//Inform the context that made me, if any, that I am gone.
if (np->nodeContext)
if (np->livarot_path) {
delete np->livarot_path;
}
}
/**
* Return the node count of a given NodeSubPath.
*/
{
if (!subpath)
return 0;
return nodeCount;
}
/**
* Return the node count of a given NodePath.
*/
{
if (!np)
return 0;
}
return nodeCount;
}
/**
* Return the subpath count of a given NodePath.
*/
{
if (!np)
return 0;
}
/**
* Return the selected node count of a given NodePath.
*/
{
if (!np)
return 0;
}
/**
* Return the number of subpaths where nodes are selected in a given NodePath.
*/
{
if (!np)
return 0;
return 0;
return 1;
count ++;
break;
}
}
}
return count;
}
/**
* Clean up a nodepath after editing.
*
* Currently we are deleting trivial subpaths.
*/
{
//Check all closed subpaths to be >=1 nodes, all open subpaths to be >= 2 nodes
if ((sp_nodepath_subpath_get_node_count(sp)<2 && !sp->closed) || (sp_nodepath_subpath_get_node_count(sp)<1 && sp->closed))
}
//Delete them. This second step is because sp_nodepath_subpath_destroy()
//also removes the subpath from nodepath->subpaths
}
}
/**
* Create new nodepath from b, make it subpath of np.
* \param t The node type.
* \todo Fixme: t should be a proper type, rather than gchar
*/
{
} else {
}
n = sp_nodepath_node_new(sp, NULL, (Inkscape::NodePath::NodeType) *t, NR_MOVETO, &pos, &pos, &npos);
b++;
t++;
if (b->code == NR_CURVETO) {
} else {
}
} else {
}
b++;
t++;
}
return b;
}
/**
* Convert from sodipodi:nodetypes to new style type string.
*/
{
if (types) {
if (types[i] != '\0') {
switch (types[i]) {
case 's':
break;
case 'z':
break;
case 'c':
break;
default:
break;
}
}
}
}
return typestr;
}
/**
* Make curve out of nodepath, write it into that nodepath's SPShape item so that display is
* updated but repr is not (for speed). Used during curve and node drag.
*/
{
}
/**
* Update XML path node with data from path object.
*/
{
np->local_change++;
}
if (repr->attribute("sodipodi:nodetypes") == NULL || strcmp(typestr, repr->attribute("sodipodi:nodetypes"))) { // nodetypes changed
np->local_change++;
}
}
/**
* Update XML path node with data from path object, commit changes forever.
*/
{
if (np->livarot_path) {
delete np->livarot_path;
}
if (np->livarot_path)
}
}
/**
* Update XML path node with data from path object, commit changes with undo.
*/
{
if (np->livarot_path) {
delete np->livarot_path;
}
if (np->livarot_path)
}
}
/**
* Make duplicate of path, replace corresponding XML node in tree, commit.
*/
{
// remember the position of the item
// remember parent
// add the new repr to the parent
// move to the saved position
}
/**
* Create curve from path.
*/
{
while (n) {
switch (n->code) {
case NR_LINETO:
break;
case NR_CURVETO:
end_pt);
break;
default:
break;
}
n = n->n.other;
} else {
n = NULL;
}
}
}
}
return curve;
}
/**
* Convert path type string to sodipodi:nodetypes style.
*/
{
len += 32;
}
while (n) {
switch (n->type) {
code = 'c';
break;
code = 's';
break;
code = 'z';
break;
default:
code = '\0';
break;
}
len += 32;
}
n = n->n.other;
} else {
n = NULL;
}
}
}
len += 1;
}
return typestr;
}
/**
* Returns current path in context.
*/
{
if (!SP_ACTIVE_DESKTOP) {
return NULL;
}
if (!SP_IS_NODE_CONTEXT(event_context)) {
return NULL;
}
}
/**
\brief Fills node and handle positions for three nodes, splitting line
marked by end at distance t.
*/
static void sp_nodepath_line_midpoint(Inkscape::NodePath::Node *new_path,Inkscape::NodePath::Node *end, gdouble t)
{
} else {
gdouble s = 1 - t;
}
}
}
/**
* Adds new node on direct line between two nodes, activates handles of all
* three nodes.
*/
static Inkscape::NodePath::Node *sp_nodepath_line_add_node(Inkscape::NodePath::Node *end, gdouble t)
{
end,
return newnode;
}
/**
\brief Break the path at the node: duplicate the argument node, start a new subpath with the duplicate, and copy all nodes after the argument node to it
*/
{
} else {
// no break for end nodes
// create a new subpath
// duplicate the break node as start of the new subpath
Inkscape::NodePath::Node *newnode = sp_nodepath_node_new(newsubpath, NULL, (Inkscape::NodePath::NodeType)node->type, NR_MOVETO, &node->pos, &node->pos, &node->n.pos);
Inkscape::NodePath::Node *nn = sp_nodepath_node_new(newsubpath, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->code, &n->p.pos, &n->pos, &n->n.pos);
if (n->selected) {
}
sp_nodepath_node_destroy(n); // remove the point on the original subpath
}
return newnode;
}
}
/**
* Duplicate node and connect to neighbours.
*/
{
}
Inkscape::NodePath::Node *newnode = sp_nodepath_node_new(sp, node, (Inkscape::NodePath::NodeType)node->type, code, &node->p.pos, &node->pos, &node->n.pos);
return node;
else
return newnode; // otherwise select the newly created node
}
{
}
{
}
/**
* Change line type at node, with side effects on neighbours.
*/
{
return;
}
} else {
}
}
/**
* Change node type, and its handles accordingly.
*/
static Inkscape::NodePath::Node *sp_nodepath_set_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type)
{
return node;
}
}
} else {
}
// if one of handles is mouseovered, preserve its position
} else {
}
return node;
}
/**
* Same as sp_nodepath_set_node_type(), but also converts, if necessary,
* adjacent segments from lines to curves.
*/
void sp_nodepath_convert_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type)
{
// convert adjacent segment BEFORE to curve
else
}
// convert adjacent segment AFTER to curve
else
}
}
}
/**
* Move node to point, and adjust its and neighbouring handles.
*/
{
}
}
}
}
// this function is only called from batch movers that will update display at the end
// themselves, so here we just move all the knots without emitting move signals, for speed
sp_node_update_handles(node, false);
}
/**
* Call sp_node_moveto() for node selection and handle possible snapping.
*/
static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, NR::Coord dx, NR::Coord dy,
bool const snap = true)
{
if (snap) {
if (s.getDistance() < best) {
best = s.getDistance();
}
}
}
}
// do not update repr here so that node dragging is acceptably fast
}
/**
Function mapping x (in the range 0..1) to y (in the range 1..0) using a smooth half-bell-like
curve; the parameter alpha determines how blunt (alpha > 1) or sharp (alpha < 1) will be the curve
near x = 0.
*/
double
sculpt_profile (double x, double alpha)
{
if (x >= 1)
return 0;
}
double
{
// extremely primitive for now, don't have time to look for the real one
}
void
sp_nodepath_move_node_and_handles (Inkscape::NodePath::Node *n, NR::Point delta, NR::Point delta_n, NR::Point delta_p)
{
sp_node_update_handles(n, false);
}
/**
* Displace selected nodes and their handles by fractions of delta (from their origins), depending
* on how far they are from the dragged node n.
*/
static void
sp_nodepath_selected_nodes_sculpt(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, NR::Point delta)
{
g_assert (n);
if (pressure == 0)
// map pressure to alpha = 1/5 ... 5
if (pressure > 0.5)
// Only one subpath has selected nodes:
// use linear mode, where the distance from n to node being dragged is calculated along the path
double n_sel_range = 0, p_sel_range = 0;
// First pass: calculate ranges (TODO: we could cache them, as they don't change while dragging)
{
do {
// Do one step in both directions from n, until reaching the end of subpath or bumping into each other
n_going = false;
} else {
n_nodes ++;
n_range += bezier_length (n_node->p.other->origin, n_node->p.other->n.origin, n_node->p.origin, n_node->origin);
n_sel_nodes ++;
}
n_going = false;
p_going = false;
}
}
p_going = false;
} else {
p_nodes ++;
p_range += bezier_length (p_node->n.other->origin, p_node->n.other->p.origin, p_node->n.origin, p_node->origin);
p_sel_nodes ++;
}
n_going = false;
p_going = false;
}
}
}
// Second pass: actually move nodes in this subpath
{
do {
// Do one step in both directions from n, until reaching the end of subpath or bumping into each other
n_going = false;
} else {
n_range += bezier_length (n_node->p.other->origin, n_node->p.other->n.origin, n_node->p.origin, n_node->origin);
sculpt_profile ((n_range + NR::L2(n_node->n.origin - n_node->origin)) / n_sel_range, alpha) * delta,
sculpt_profile ((n_range - NR::L2(n_node->p.origin - n_node->origin)) / n_sel_range, alpha) * delta);
}
n_going = false;
p_going = false;
}
}
p_going = false;
} else {
p_range += bezier_length (p_node->n.other->origin, p_node->n.other->p.origin, p_node->n.origin, p_node->origin);
sculpt_profile ((p_range - NR::L2(p_node->n.origin - p_node->origin)) / p_sel_range, alpha) * delta,
sculpt_profile ((p_range + NR::L2(p_node->p.origin - p_node->origin)) / p_sel_range, alpha) * delta);
}
n_going = false;
p_going = false;
}
}
}
} else {
// Multiple subpaths have selected nodes:
// use spatial mode, where the distance from n to node being dragged is measured directly as NR::L2.
// TODO: correct these distances taking into account their angle relative to the bisector, so as to
// fix the pear-like shape when sculpting e.g. a ring
// First pass: calculate range
gdouble direct_range = 0;
}
}
}
// Second pass: actually move nodes
if (direct_range > 1e-6) {
} else {
}
}
}
}
}
// do not update repr here so that node dragging is acceptably fast
}
/**
* Move node selection to point, adjust its and neighbouring handles,
* handle possible snapping, and commit the change with possible undo.
*/
void
{
if (!nodepath) return;
if (dx == 0) {
} else if (dy == 0) {
} else {
}
}
/**
* Move node selection off screen and commit the change.
*/
void
{
// borrowed from sp_selection_move_screen in selection-chemistry.c
// we find out the current zoom factor and divide deltas by it
if (!nodepath) return;
if (dx == 0) {
} else if (dy == 0) {
} else {
}
}
/** If they don't yet exist, creates knot and line for the given side of the node */
static void sp_node_ensure_knot_exists (SPDesktop *desktop, Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeSide *side)
{
side->knot = sp_knot_new(desktop, _("<b>Node handle</b>: drag to shape the curve; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to lock length; with <b>Shift</b> to rotate both handles"));
}
}
}
/**
*/
static void sp_node_update_handle(Inkscape::NodePath::Node *node, gint which, gboolean show_handle, bool fire_move_signals)
{
if (show_handle) {
// Just created, so we shouldn't fire the node_moved callback - instead set the knot position directly
} else {
if (fire_move_signals) {
} else {
}
}
}
}
} else {
}
}
}
}
}
/**
* Ensure the node itself is visible, its handles and those of the neighbours of the node are
* visible if selected, update their screen positions. If fire_move_signals, move the node and its
* handles so that the corresponding signals are fired, callbacks are activated, and curve is
* updated; otherwise, just move the knots silently (used in batch moves).
*/
{
}
if (fire_move_signals)
else
}
}
}
}
/**
* Call sp_node_update_handles() for all nodes on subpath.
*/
{
}
}
/**
* Call sp_nodepath_subpath_update_handles() for all subpaths of nodepath.
*/
{
}
}
void
sp_nodepath_show_handles(bool show)
{
}
/**
* Adds all selected nodes in nodepath to list.
*/
{
/// \todo this adds a copying, rework when the selection becomes a stl list
}
/**
* Align selected nodes on the specified axis.
*/
{
return;
}
return;
}
Inkscape::NodePath::Node *pNode = reinterpret_cast<Inkscape::NodePath::Node *>(nodepath->selected->data);
if (pNode) {
}
}
}
/// Helper struct.
struct NodeSort
{
/// \todo use vectorof pointers instead of calling copy ctor
{}
};
{
}
/**
* Distribute selected nodes on the specified axis.
*/
{
return;
}
if ( ! (nodepath->selected->next && nodepath->selected->next->next) ) { // less than 3 nodes selected
return;
}
Inkscape::NodePath::Node *pNode = reinterpret_cast<Inkscape::NodePath::Node *>(nodepath->selected->data);
if (pNode) {
//dest[axis] = pNode->pos[axis];
//sp_node_moveto(pNode, dest);
}
}
//overall bboxes span
//new distance between each bbox
it ++ )
{
}
}
/**
* Call sp_nodepath_line_add_node() for all selected segments.
*/
void
{
if (!nodepath) {
return;
}
}
}
while (nl) {
}
/** \todo fixme: adjust ? */
}
/**
* Select segment nearest to point
*/
void
{
if (!nodepath) {
return;
}
//find segment to segment
}
if (e->p.other)
}
/**
* Add a node nearest to point
*/
void
{
if (!nodepath) {
return;
}
//find segment to split
//don't know why but t seems to flip for lines
}
/* fixme: adjust ? */
}
/*
* Adjusts a segment so that t moves by a certain delta for dragging
* converts lines to curves
*
* method and idea borrowed from Simon Budig <simon@gimp.org> and the GIMP
* cf. app/vectors/gimpbezierstroke.c, gimp_bezier_stroke_point_move_relative()
*/
void
{
/* feel good is an arbitrary parameter that distributes the delta between handles
* if t of the drag point is less than 1/6 distance form the endpoint only
* the corresponding hadle is adjusted. This matches the behavior in GIMP
*/
double feel_good;
if (t <= 1.0 / 6.0)
feel_good = 0;
else if (t <= 0.5)
else if (t <= 5.0 / 6.0)
else
feel_good = 1;
//if we're dragging a line convert it to a curve
}
e->p.pos += offsetcoord1;
// adjust handles of adjacent nodes where necessary
sp_node_adjust_handle(e,1);
}
/**
* Call sp_nodepath_break() for all selected segments.
*/
void sp_node_selected_break()
{
if (!nodepath) return;
}
if (temp) {
}
}
}
/**
* Duplicate the selected node(s).
*/
void sp_node_selected_duplicate()
{
if (!nodepath) {
return;
}
}
if (temp) {
}
}
}
/**
* Join two nodes by merging them into one.
*/
void sp_node_selected_join()
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
return;
}
g_assert(a != b);
if (((a->subpath->closed) || (b->subpath->closed)) || (a->p.other && a->n.other) || (b->p.other && b->n.other)) {
nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
return;
}
/* a and b are endpoints */
c = a->pos;
c = b->pos;
} else {
}
return;
}
/* a and b are separate subpaths */
sp_nodepath_node_new(t, NULL,Inkscape::NodePath::NODE_CUSP, NR_MOVETO, &n->n.pos, &n->pos, &n->p.pos);
n = n->p.other;
while (n) {
sp_nodepath_node_new(t, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
n = n->p.other;
}
sa = t;
} else {
}
sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->code, &n->p.pos, &n->pos, &n->n.pos);
}
sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
}
} else {
}
/* and now destroy sb */
}
/**
* Join two nodes by adding a segment between them.
*/
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
return;
}
g_assert(a != b);
if (((a->subpath->closed) || (b->subpath->closed)) || (a->p.other && a->n.other) || (b->p.other && b->n.other)) {
nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
return;
}
/*similar to sp_nodepath_subpath_close(sp), without the node destruction*/
return;
}
/* a and b are separate subpaths */
sp_nodepath_node_new(t, NULL,Inkscape::NodePath::NODE_CUSP, NR_MOVETO, &n->n.pos, &n->pos, &n->p.pos);
sp_nodepath_node_new(t, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
}
sa = t;
} else {
}
sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->code, &n->p.pos, &n->pos, &n->n.pos);
}
sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->n.other->code, &n->n.pos, &n->pos, &n->p.pos);
}
} else {
}
/* and now destroy sb */
}
/**
* Delete one or more selected nodes and preserve the shape of the path as much as possible.
*/
{
while (nodes_to_delete) {
bool just_delete = false;
//find the start of this contiguous selection
//move left to the first node that is not selected
//or the start of the non-closed path
for (Inkscape::NodePath::Node *curr=node->p.other; curr && curr!=node && g_list_find(nodes_to_delete, curr); curr=curr->p.other) {
}
//just delete at the beginning of an open path
if (!delete_cursor->p.other) {
just_delete = true;
} else {
}
//calculate points for each segment
int rate = 5;
if (!just_delete) {
//just delete at the end of an open path
just_delete = true;
break;
}
//sample points on the contiguous selected segment
for (int i=1; i<rate; i++) {
}
//break if we've come full circle or hit the end of the selection
break;
}
}
}
if (!just_delete) {
//calculate the best fitting single segment and adjust the endpoints
//would decreasing error create a better fitting approximation?
//adjust endpoints
}
//destroy this contiguous selection
// delete_cursor->n points to itself, which means this is the last node on a closed subpath
} else {
}
}
}
// different nodepaths will give us one undo event per nodepath
// if the entire nodepath is removed, delete the selected object.
//FIXME: a closed path CAN legally have one node, it's only an open one which must be
//at least 2
//FIXME: The following line will be wrong when we have mltiple nodepaths: we only want to
//delete this nodepath's object, not the entire selection! (though at this time, this
//does not matter)
} else {
}
}
}
/**
* Delete one or more selected nodes.
*/
void sp_node_selected_delete()
{
if (!nodepath) return;
/** \todo fixme: do it the right way */
}
//clean up the nodepath (such as for trivial subpaths)
// if the entire nodepath is removed, delete the selected object.
return;
}
}
/**
* Delete one or more segments between two selected nodes.
* This is the code for 'split'.
*/
void
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
_("Select <b>two non-endpoint nodes</b> on a path between which to delete segments."));
return;
}
//Selected nodes, not inclusive
if ( ( a==b) || //same node
{
_("Select <b>two non-endpoint nodes</b> on a path between which to delete segments."));
return;
}
//###########################################
//# BEGIN EDITS
//###########################################
//##################################
//# CLOSED PATH
//##################################
//Since we can go in a circle, we need to find the shorter distance.
// a->b or b->a
int distance = 0;
int minDistance = 0;
if (curr==b) {
//printf("a to b:%d\n", distance);
start = a;//go from a to b
end = b;
//printf("A to B :\n");
break;
}
distance++;
}
//try again, the other direction
distance = 0;
if (curr==a) {
//printf("b to a:%d\n", distance);
if (distance < minDistance) {
start = b; //we go from b to a
end = a;
//printf("B to A\n");
}
break;
}
distance++;
}
//Copy everything from 'end' to 'start' to a new subpath
break;
}
}
//##################################
//# OPEN PATH
//##################################
else {
//We need to get the direction of the list between A and B
//Can we walk from a to b?
if (curr==b) {
start = a; //did it! we go from a to b
end = b;
//printf("A to B\n");
break;
}
}
if (!start) {//didn't work? let's try the other direction
if (curr==a) {
start = b; //did it! we go from b to a
end = a;
//printf("B to A\n");
break;
}
}
}
if (!start) {
_("Cannot find path between nodes."));
return;
}
//Copy everything after 'end' to a new subpath
}
//Now let us do our deletion. Since the tail has been saved, go all the way to the end of the list
}
}
//###########################################
//# END EDITS
//###########################################
//clean up the nodepath (such as for trivial subpaths)
}
/**
* Call sp_nodepath_set_line() for all selected segments.
*/
void
{
}
}
}
/**
* Call sp_nodepath_convert_node_type() for all selected nodes.
*/
void
{
}
}
/**
* Change select status of node, update its own and neighbour handles.
*/
{
if (selected) {
} else {
}
}
/**
\brief Select a node
\param node The node to select
\param incremental If true, add to selection, otherwise deselect others
\param override If true, always select this node, otherwise toggle selected status
*/
static void sp_nodepath_node_select(Inkscape::NodePath::Node *node, gboolean incremental, gboolean override)
{
if (incremental) {
if (override) {
}
} else { // toggle
} else {
}
}
} else {
}
}
/**
\brief Deselect all nodes in the nodepath
*/
void
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
}
}
/**
\brief Select or invert selection of all nodes in the nodepath
*/
void
{
if (!nodepath) return;
}
}
}
/**
* If nothing selected, does the same as sp_nodepath_select_all();
* (i.e., similar to "select all in layer", with the "selected" subpaths
* being treated as "layers" in the path).
*/
void
{
if (!nodepath) return;
return;
}
GList *copy = g_list_copy (nodepath->selected); // copy initial selection so that selecting in the loop does not affect us
}
}
}
g_list_free (copy);
}
/**
* \brief Select the node after the last selected; if none is selected,
* select the first within path.
*/
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
} else {
}
} else {
}
} else {
} else {
} else {
}
}
}
}
}
}
}
if (last) { // there's at least one more node after selected
} else { // no more nodes, select the first one in first subpath
}
}
/**
* \brief Select the node before the first selected; if none is selected,
* select the last within path
*/
{
if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
} else {
}
} else {
}
} else {
} else {
} else {
}
}
}
}
}
}
}
if (last) { // there's at least one more node before selected
} else { // no more nodes, select the last one in last subpath
}
}
/**
* \brief Select all nodes that are within the rectangle.
*/
void sp_nodepath_select_rect(Inkscape::NodePath::Path *nodepath, NR::Rect const &b, gboolean incremental)
{
if (!incremental) {
}
}
}
}
}
/**
\brief Saves all nodes' and handles' current positions in their origin members
*/
void
{
}
}
}
/**
\brief Saves selected nodes in a nodepath into a list containing integer positions of all selected nodes
*/
{
return NULL;
}
guint i = 0;
i++;
r = g_list_append(r, GINT_TO_POINTER(i));
}
}
}
return r;
}
/**
\brief Restores selection by selecting nodes whose positions are in the list
*/
{
guint i = 0;
i++;
if (g_list_find(r, GINT_TO_POINTER(i))) {
}
}
}
}
/**
\brief Adjusts handle according to node type and line code.
*/
{
/** \todo fixme: */
/* I have line */
if (which_adjust == 1) {
} else {
}
/* I am curve */
/* Other has line */
/* other is lineto, we are either smooth or symm */
if (linelen < 1e-18)
return;
return;
}
return;
}
/* We are smooth */
if (otherlen < 1e-18) return;
}
/**
\brief Adjusts both handles according to node type and line code
*/
{
/* we are either smooth or symm */
return;
}
return;
}
/* both are curves */
return;
}
/* We are smooth */
if (plen < 1e-18) return;
if (nlen < 1e-18) return;
}
/**
* Node event callback.
*/
{
case GDK_ENTER_NOTIFY:
active_node = n;
break;
case GDK_LEAVE_NOTIFY:
active_node = NULL;
break;
case GDK_KEY_PRESS:
case GDK_space:
}
break;
default:
break;
}
break;
default:
break;
}
return ret;
}
/**
* Handle keypress on node; directly called.
*/
{
// there is no way to verify nodes so set active_node to nil when deleting!!
/// \todo FIXME: this does not seem to work, the keys are stolen by tool contexts!
case GDK_BackSpace:
active_node = NULL;
break;
case GDK_c:
break;
case GDK_s:
break;
case GDK_y:
break;
case GDK_b:
break;
}
return ret;
}
return FALSE;
}
/**
* Mouseclick on node callback.
*/
{
if (state & GDK_CONTROL_MASK) {
} else {
}
} else { //ctrl+alt+click: delete node
}
} else {
}
}
/**
* Mouse grabbed node callback.
*/
{
if (!n->selected) {
}
}
/**
* Mouse ungrabbed node callback.
*/
{
n->dragging_out = NULL;
}
/**
* The point on a line, given by its angle, closest to the given point.
* \param p A point.
* \param a Angle of the line; it is assumed to go through coordinate origin.
* \param closest Pointer to the point struct where the result is stored.
* \todo FIXME: use dot product perhaps?
*/
{
if (a == HUGE_VAL) { // vertical
} else {
}
}
/**
* Distance from the point to a line given by its angle.
* \param p A point.
* \param a Angle of the line; it is assumed to go through coordinate origin.
*/
{
point_line_closest(p, a, &c);
return sqrt(((*p)[NR::X] - c[NR::X])*((*p)[NR::X] - c[NR::X]) + ((*p)[NR::Y] - c[NR::Y])*((*p)[NR::Y] - c[NR::Y]));
}
/**
* Callback for node "request" signal.
* \todo fixme: This goes to "moved" event? (lauris)
*/
static gboolean
{
// If either (Shift and some handle retracted), or (we're already dragging out a handle)
if (((state & GDK_SHIFT_MASK) && ((n->n.other && n->n.pos == n->pos) || (n->p.other && n->p.pos == n->pos))) || n->dragging_out) {
if (!n->dragging_out) {
// This is the first drag-out event; find out which handle to drag out
double appr_n = (n->n.other ? NR::L2(n->n.other->pos - n->pos) - NR::L2(n->n.other->pos - (*p)) : -HUGE_VAL);
double appr_p = (n->p.other ? NR::L2(n->p.other->pos - n->pos) - NR::L2(n->p.other->pos - (*p)) : -HUGE_VAL);
return FALSE;
n->dragging_out = &n->p;
opposite = &n->n;
n->code = NR_CURVETO;
n->dragging_out = &n->n;
opposite = &n->p;
} else { // p and n nodes are the same
n->dragging_out = &n->p;
opposite = &n->n;
n->code = NR_CURVETO;
n->dragging_out = &n->n;
opposite = &n->p;
} else { // find out to which handle of the adjacent node we're closer; note that n->n.other == n->p.other
double appr_other_n = (n->n.other ? NR::L2(n->n.other->n.pos - n->pos) - NR::L2(n->n.other->n.pos - (*p)) : -HUGE_VAL);
double appr_other_p = (n->n.other ? NR::L2(n->n.other->p.pos - n->pos) - NR::L2(n->n.other->p.pos - (*p)) : -HUGE_VAL);
n->dragging_out = &n->n;
opposite = &n->p;
} else { // closer to other's n handle
n->dragging_out = &n->p;
opposite = &n->n;
n->code = NR_CURVETO;
}
}
}
// if there's another handle, make sure the one we drag out starts parallel to it
}
// knots might not be created yet!
}
// pass this on to the handle-moved callback
return TRUE;
}
// calculate relative distances of handles
// n handle:
// if there's no n handle (straight line), see if we can use the direction to the next point on path
if (n->n.other) { // if there is the next point
yn = n->n.other->pos[NR::Y] - n->origin[NR::Y]; // use origin because otherwise the direction will change as you drag
}
}
// p handle:
// if there's no p handle (straight line), see if we can use the direction to the prev point on path
if (n->p.other) {
}
}
// sliding on handles, only if at least one of the handles is non-vertical
// (otherwise it's the same as ctrl+drag anyway)
// calculate angles of the handles
if (xn == 0) {
if (yn == 0) { // no handle, consider it the continuation of the other one
an = 0;
}
else an = 0; // vertical; set the angle to horizontal
if (xp == 0) {
if (yp == 0) { // no handle, consider it the continuation of the other one
}
else ap = 0; // vertical; set the angle to horizontal
// angles of the perpendiculars; HUGE_VAL means vertical
// mouse point relative to the node's original pos
// distances to the four lines (two handles and two perpendiculars)
// find out which line is the closest, save its closest point in c
}
// move the node to the closest point
sp_nodepath_selected_nodes_move(n->subpath->nodepath, (*p)[NR::X] - n->pos[NR::X], n->origin[NR::Y] - n->pos[NR::Y]);
} else { // snap to vert
sp_nodepath_selected_nodes_move(n->subpath->nodepath, n->origin[NR::X] - n->pos[NR::X], (*p)[NR::Y] - n->pos[NR::Y]);
}
}
} else { // move freely
} else {
(state & GDK_SHIFT_MASK) == 0);
}
}
return TRUE;
}
/**
* Node handle clicked callback.
*/
{
}
} else { // just select or add to selection, depending in Shift
}
}
/**
* Node handle grabbed callback.
*/
{
if (!n->selected) {
}
// remember the origin point of the handle
} else {
}
}
/**
* Node handle ungrabbed callback.
*/
{
// forget origin and set knot position once more (because it can be wrong now due to restrictions)
n->p.origin_radial.a = 0;
n->n.origin_radial.a = 0;
} else {
}
}
/**
* Node handle "request" signal callback.
*/
{
me = &n->p;
opposite = &n->n;
which = -1;
me = &n->n;
opposite = &n->p;
which = 1;
} else {
which = 0;
}
/* We are smooth node adjacent with line */
}
*p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta), NULL).getPoint();
} else {
}
sp_node_adjust_handle(n, -which);
return FALSE;
}
/**
* Node handle moved callback.
*/
{
me = &n->p;
other = &n->n;
me = &n->n;
other = &n->p;
} else {
}
// calculate radial coordinates of the grabbed handle, its other handle, and the mouse point
/* 0 interpreted as "no snapping". */
// ortho doesn't exist: original handle was zero length.
} else {
/* The closest PI/2 angle, starting from original angle (i.e. snapping to original,
* its opposite and perpendiculars). */
double const a_ortho = me->origin_radial.a + floor((rnew.a - me->origin_radial.a)/(M_PI/2) + 0.5) * (M_PI/2);
// Snap to the closest.
: a_ortho );
}
}
if (state & GDK_MOD1_MASK) {
// lock handle length
}
// rotate the other handle correspondingly, if both old and new angles exist and are not the same
}
// this is what sp_knot_set_position does, but without emitting the signal:
// we cannot emit a "moved" signal because we're now processing it
/* status text */
if (!desktop) return;
if (!ec) return;
if (!mc) return;
_("<b>Node handle</b>: angle %0.2f°, length %s; with <b>Ctrl</b> to snap angle; with <b>Alt</b> to lock length; with <b>Shift</b> to rotate both handles"), degrees, length->str);
}
/**
* Node handle event callback.
*/
{
case GDK_KEY_PRESS:
case GDK_space:
}
break;
default:
break;
}
break;
default:
break;
}
return ret;
}
{
if ( both
{
}
}
{
gdouble r;
if ( both
{
} else {
r = rme.r;
}
/* Bulia says norm_angle is just the visible distance that the
* object's end must travel on the screen. Left as 'angle' for want of
* a better name.*/
rme.a += weird_angle;
if ( both
{
rother.a += weird_angle;
}
}
/**
* Rotate one node.
*/
static void node_rotate_one (Inkscape::NodePath::Node *n, gdouble angle, int which, gboolean screen)
{
bool both = false;
if (!n->n.other) { // if this is an endnode, select its single handle regardless of "which"
me = &(n->p);
other = &(n->n);
} else if (!n->p.other) {
me = &(n->n);
other = &(n->p);
} else {
if (which > 0) { // right handle
me = &(n->n);
other = &(n->p);
} else {
me = &(n->p);
other = &(n->n);
}
} else if (which < 0){ // left handle
me = &(n->n);
other = &(n->p);
} else {
me = &(n->p);
other = &(n->n);
}
} else { // both handles
me = &(n->n);
other = &(n->p);
both = true;
}
}
if (screen) {
} else {
}
if (both || n->type == Inkscape::NodePath::NODE_SMOOTH || n->type == Inkscape::NodePath::NODE_SYMM) {
}
// this function is only called from sp_nodepath_selected_nodes_rotate that will update display at the end,
// so here we just move all the knots without emitting move signals, for speed
sp_node_update_handles(n, false);
}
/**
* Rotate selected nodes.
*/
void sp_nodepath_selected_nodes_rotate(Inkscape::NodePath::Path *nodepath, gdouble angle, int which, bool screen)
{
} else {
// rotate as an object:
}
if (screen) {
} else {
}
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
}
}
}
/**
* Scale one node.
*/
{
bool both = false;
if (!n->n.other) { // if this is an endnode, select its single handle regardless of "which"
me = &(n->p);
other = &(n->n);
n->code = NR_CURVETO;
} else if (!n->p.other) {
me = &(n->n);
other = &(n->p);
if (n->n.other)
} else {
if (which > 0) { // right handle
me = &(n->n);
other = &(n->p);
if (n->n.other)
} else {
me = &(n->p);
other = &(n->n);
n->code = NR_CURVETO;
}
} else if (which < 0){ // left handle
me = &(n->n);
other = &(n->p);
if (n->n.other)
} else {
me = &(n->p);
other = &(n->n);
n->code = NR_CURVETO;
}
} else { // both handles
me = &(n->n);
other = &(n->p);
both = true;
n->code = NR_CURVETO;
if (n->n.other)
}
}
} else { // if there's no next, initialize to 0
rme.a = 0;
}
}
}
}
}
// this function is only called from sp_nodepath_selected_nodes_scale that will update display at the end,
// so here we just move all the knots without emitting move signals, for speed
sp_node_update_handles(n, false);
}
/**
* Scale selected nodes.
*/
void sp_nodepath_selected_nodes_scale(Inkscape::NodePath::Path *nodepath, gdouble const grow, int const which)
{
// scale handles of the single selected node
} else {
// scale nodes as an "object":
}
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
}
}
}
void sp_nodepath_selected_nodes_scale_screen(Inkscape::NodePath::Path *nodepath, gdouble const grow, int const which)
{
if (!nodepath) return;
}
/**
* Flip selected nodes horizontally/vertically.
*/
{
// flip handles of the single selected node
sp_node_update_handles(n, false);
} else {
// scale nodes as an "object":
}
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
}
}
}
//-----------------------------------------------
/**
* Return new subpath under given nodepath.
*/
{
// using prepend here saves up to 10% of time on paths with many subpaths, but requires that
// the caller reverses the list after it's ready (this is done in sp_nodepath_new)
return s;
}
/**
* Destroy nodes in subpath, then subpath itself.
*/
{
}
}
/**
* Link head to tail in subpath.
*/
{
//Link the head to the tail
//Remove the extra end node
}
/**
* Open closed (loopy) subpath at node.
*/
{
/* We create new startpoint, current node will become last one */
Inkscape::NodePath::Node *new_path = sp_nodepath_node_new(sp, n->n.other,Inkscape::NodePath::NODE_CUSP, NR_MOVETO,
//Unlink to make a head and tail
}
/**
* Returns area in triangle given by points; may be negative.
*/
inline double
{
return (p1[NR::X]*p2[NR::Y] + p1[NR::Y]*p3[NR::X] + p2[NR::X]*p3[NR::Y] - p2[NR::Y]*p3[NR::X] - p1[NR::Y]*p2[NR::X] - p1[NR::X]*p3[NR::Y]);
}
/**
* Return new node in subpath with given properties.
* \param pos Position of node.
* \param ppos Handle position in previous direction
* \param npos Handle position in previous direction
*/
sp_nodepath_node_new(Inkscape::NodePath::SubPath *sp, Inkscape::NodePath::Node *next, Inkscape::NodePath::NodeType type, NRPathcode code, NR::Point *ppos, NR::Point *pos, NR::Point *npos)
{
// use the type from sodipodi:nodetypes
} else {
// points are (almost) collinear
// endnode, or a node with a retracted handle
} else {
}
} else {
}
}
n->dragging_out = NULL;
if (next) {
//g_assert(g_list_find(sp->nodes, next));
} else {
}
if (prev)
else
if (next)
else
n->knot = sp_knot_new(sp->nodepath->desktop, _("<b>Node</b>: drag to edit the path; with <b>Ctrl</b> to snap to horizontal/vertical; with <b>Ctrl+Alt</b> to snap to handles' directions"));
n->knot->setShape ((n->type == Inkscape::NodePath::NODE_CUSP)? SP_KNOT_SHAPE_DIAMOND : SP_KNOT_SHAPE_SQUARE);
sp_knot_update_ctrl(n->knot);
sp_knot_show(n->knot);
// We only create handle knots and lines on demand
return n;
}
/**
* Destroy node and its knots, link neighbors in subpath.
*/
{
}
}
} else {
}
}
} else { // this was the last node on subpath
}
}
/**
* Returns one of the node's two sides.
* \param which Indicates which side.
* \return Pointer to previous node side if which==-1, next if which==1.
*/
{
switch (which) {
case -1:
return &node->p;
case 1:
return &node->n;
default:
break;
}
return NULL;
}
/**
* Return the other side of the node, given one of its sides.
*/
static Inkscape::NodePath::NodeSide *sp_node_opposite_side(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeSide *me)
{
return NULL;
}
/**
* Return NRPathcode on the given side of the node.
*/
static NRPathcode sp_node_path_code_from_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me)
{
return NR_MOVETO;
}
return NR_MOVETO;
}
return NR_END;
}
/**
* Call sp_nodepath_line_add_node() at t on the segment denoted by piece
*/
{
if (!nodepath) {
return e;
}
//find segment
n++;
}
//if the piece belongs to this subpath grab it
//otherwise move onto the next subpath
if (index < n) {
for (int i = 0; i < index; ++i) {
e = e->n.other;
}
break;
} else {
index -= (n+1);
} else {
index -= n;
}
}
}
return e;
}
/**
* Returns plain text meaning of node type.
*/
{
unsigned retracted = 0;
bool endnode = false;
retracted ++;
endnode = true;
}
if (retracted == 0) {
if (endnode) {
// TRANSLATORS: "end" is an adjective here (NOT a verb)
return _("end node");
} else {
// TRANSLATORS: "cusp" means "sharp" (cusp node); see also the Advanced Tutorial
return _("cusp");
// TRANSLATORS: "smooth" is an adjective here
return _("smooth");
return _("symmetric");
}
}
} else if (retracted == 1) {
if (endnode) {
// TRANSLATORS: "end" is an adjective here (NOT a verb)
return _("end node, handle retracted (drag with <b>Shift</b> to extend)");
} else {
return _("one handle retracted (drag with <b>Shift</b> to extend)");
}
} else {
return _("both handles retracted (drag with <b>Shift</b> to extend)");
}
return NULL;
}
/**
* Handles content of statusbar as long as node tool is active.
*/
void
{
gchar const *when_selected = _("<b>Drag</b> nodes or node handles; <b>Alt+drag</b> nodes to sculpt; <b>arrow</b> keys to move nodes, <b>< ></b> to scale, <b>[ ]</b> to rotate");
gchar const *when_selected_one = _("<b>Drag</b> the node or its handles; <b>arrow</b> keys to move the node");
if (nodepath) {
} else {
}
if (!ec) return;
if (!mc) return;
if (selected_nodes == 0) {
_("Select a single object to edit its nodes or handles."));
} else {
if (nodepath) {
ngettext("<b>0</b> out of <b>%i</b> node selected. <b>Click</b>, <b>Shift+click</b>, or <b>drag around</b> nodes to select.",
"<b>0</b> out of <b>%i</b> nodes selected. <b>Click</b>, <b>Shift+click</b>, or <b>drag around</b> nodes to select.",
} else {
} else {
}
}
}
ngettext("<b>%i</b> of <b>%i</b> node selected; %s. %s.",
"<b>%i</b> of <b>%i</b> nodes selected; %s. %s.",
selected_nodes, total_nodes, sp_node_type_description((Inkscape::NodePath::Node *) nodepath->selected->data), when_selected_one);
} else {
if (selected_subpaths > 1) {
ngettext("<b>%i</b> of <b>%i</b> node selected in <b>%i</b> of <b>%i</b> subpaths. %s.",
"<b>%i</b> of <b>%i</b> nodes selected in <b>%i</b> of <b>%i</b> subpaths. %s.",
} else {
ngettext("<b>%i</b> of <b>%i</b> node selected. %s.",
"<b>%i</b> of <b>%i</b> nodes selected. %s.",
}
}
}
/*
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 :