nodepath.cpp revision 41e6b2681e6a61f7e0b79f06787ad76d397bf0bd
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner * Path handler in node edit mode
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Authors:
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * Lauris Kaplinski <lauris@kaplinski.com>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * bulia byak <buliabyak@users.sf.net>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Portions of this code are in public domain; node sculpting functions written by bulia byak are under GNU GPL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/// evil evil evil. FIXME: conflict of two different Path classes!
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/// There is a conflict in the namespace between two classes named Path.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/// #include "sp-flowtext.h"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#define SP_TYPE_FLOWREGION (sp_flowregion_get_type ())
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define SP_IS_FLOWREGION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_FLOWREGION))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define SP_IS_FLOWTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_FLOWTEXT))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin// end evil workaround
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/// \todo fixme: Implement these via preferences */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Creation from object */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void subpaths_from_pathvector(Inkscape::NodePath::Path *np, Geom::PathVector const & pathv, Inkscape::NodePath::NodeType const *t);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::NodeType * parse_nodetypes(gchar const *types, guint length);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Object updating */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic SPCurve *create_curve(Inkscape::NodePath::Path *np);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic gchar *create_typestr(Inkscape::NodePath::Path *np);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_node_update_handles(Inkscape::NodePath::Node *node, bool fire_move_signals = true);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_node_select(Inkscape::NodePath::Node *node, gboolean incremental, gboolean override);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_node_set_selected(Inkscape::NodePath::Node *node, gboolean selected);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::Node *sp_nodepath_set_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Adjust handle placement, if the node or the other handle is moved */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_node_adjust_handle(Inkscape::NodePath::Node *node, gint which_adjust);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_node_adjust_handles(Inkscape::NodePath::Node *node);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_node_adjust_handles_auto(Inkscape::NodePath::Node *node);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Node event callbacks */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_clicked(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_grabbed(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_ungrabbed(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic gboolean node_request(SPKnot *knot, Geom::Point const &p, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Handle event callbacks */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_handle_clicked(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_handle_grabbed(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_handle_ungrabbed(SPKnot *knot, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic gboolean node_handle_request(SPKnot *knot, Geom::Point &p, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void node_handle_moved(SPKnot *knot, Geom::Point const &p, guint state, gpointer data);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic gboolean node_handle_event(SPKnot *knot, GdkEvent *event, Inkscape::NodePath::Node *n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Constructors and destructors */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::SubPath *sp_nodepath_subpath_new(Inkscape::NodePath::Path *nodepath);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_subpath_destroy(Inkscape::NodePath::SubPath *subpath);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_subpath_close(Inkscape::NodePath::SubPath *sp);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_subpath_open(Inkscape::NodePath::SubPath *sp,Inkscape::NodePath::Node *n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::Node * sp_nodepath_node_new(Inkscape::NodePath::SubPath *sp,Inkscape::NodePath::Node *next,Inkscape::NodePath::NodeType type, NRPathcode code,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Geom::Point *ppos, Geom::Point *pos, Geom::Point *npos);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_node_destroy(Inkscape::NodePath::Node *node);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Helpers */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::NodeSide *sp_node_get_side(Inkscape::NodePath::Node *node, gint which);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic Inkscape::NodePath::NodeSide *sp_node_opposite_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic NRPathcode sp_node_path_code_from_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic SPCurve* sp_nodepath_object_get_curve(SPObject *object, const gchar *key);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sp_nodepath_set_curve (Inkscape::NodePath::Path *np, SPCurve *curve);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin// active_node indicates mouseover node
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinInkscape::NodePath::Node * Inkscape::NodePath::Path::active_node = NULL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinsp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop, */const SPCurve *curve, bool show = false, guint32 color = 0xff0000ff) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin SPCanvasItem *helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helper_path), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helper_path), 0, SP_WIND_RULE_NONZERO);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinsp_nodepath_create_helperpaths(Inkscape::NodePath::Path *np) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin //std::map<Inkscape::LivePathEffect::Effect *, std::vector<SPCanvasItem *> > helper_path_vec;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin PathEffectList lpelist = sp_lpe_item_get_effect_list(lpeitem);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (PathEffectList::iterator i = lpelist.begin(); i != lpelist.end(); ++i) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::LivePathEffect::LPEObjectReference *lperef = (*i);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::LivePathEffect::Effect *lpe = lperef->lpeobject->get_lpe();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin // create new canvas items from the effect's helper paths
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin std::vector<Geom::PathVector> hpaths = lpe->getHelperPaths(lpeitem);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (std::vector<Geom::PathVector>::iterator j = hpaths.begin(); j != hpaths.end(); ++j) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin SPCanvasItem * canvasitem = sp_nodepath_make_helper_item(np, helper_curve, true, 0x509050dd);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinsp_nodepath_destroy_helperpaths(Inkscape::NodePath::Path *np) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (HelperPathList::iterator i = np->helper_path_vec.begin(); i != np->helper_path_vec.end(); ++i) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (std::vector<SPCanvasItem *>::iterator j = (*i).second.begin(); j != (*i).second.end(); ++j) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/** updates canvas items from the effect's helper paths */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinsp_nodepath_update_helperpaths(Inkscape::NodePath::Path *np) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin //std::map<Inkscape::LivePathEffect::Effect *, std::vector<SPCanvasItem *> > helper_path_vec;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin PathEffectList lpelist = sp_lpe_item_get_effect_list(lpeitem);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* The number or type or LPEs may have changed, so we need to clear and recreate our
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * helper_path_vec to make sure it is in sync */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (PathEffectList::iterator i = lpelist.begin(); i != lpelist.end(); ++i) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::LivePathEffect::Effect *lpe = (*i)->lpeobject->get_lpe();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin std::vector<Geom::PathVector> hpaths = lpe->getHelperPaths(lpeitem);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH((np->helper_path_vec[lpe])[j]), curve);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * \brief Creates new nodepath from item
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * If repr_key_in is not NULL, object *has* to be a LivePathEffectObject !
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * \todo create proper constructor for nodepath::path, this method returns null a constructor cannot so this cannot be simply converted to constructor.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinInkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, bool show_handles, const char * repr_key_in, SPItem *item)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * FIXME: remove this. We don't want to edit paths inside flowtext.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Instead we will build our flowtext with cloned paths, so that the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * real paths are outside the flowtext and thus editable as usual.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin SPObject *grandchild = sp_object_first_child(SP_OBJECT(child));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin SPCurve *curve = sp_nodepath_object_get_curve(object, repr_key_in);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin //Create new nodepath
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::NodePath::Path *np = new Inkscape::NodePath::Path();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::Preferences *prefs = Inkscape::Preferences::get();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin // Set defaults
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin np->shape_editor = NULL; //Let the shapeeditor that makes this set it
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin np->helperpath_rgba = prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin np->show_helperpath = prefs->getBool("/tools/nodes/show_helperpath");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(object));
if (!lpe) {
delete np;
if (lpeparam) {
if (lpe) {
/* Calculate length of the nodetype string. The closing/starting point for closed paths is counted twice.
* To get the correct count, one can count all segments in the paths, and then add the total number of (non-empty) paths. */
for (Geom::PathVector::const_iterator pit = pathv_sanitized.begin(); pit != pathv_sanitized.end(); ++pit) {
// reverse the list, because sp_nodepath_subpath_new() used g_list_prepend instead of append (for speed)
delete[] typestr;
np->helper_path = sp_nodepath_make_helper_item(np, /*desktop, */np->curve, true, np->helperpath_rgba);
return np;
while (this->subpaths) {
if (this->shape_editor)
if (this->helper_path) {
if (this->curve) {
if (this->repr_key) {
if (this->repr_nodetypes_key) {
int nodeCount = 0;
if (subpath) {
return nodeCount;
if (np) {
return nodeCount;
if (np) {
return nodeCount;
if (np) {
return nodeCount;
nodeCount++;
return nodeCount;
if ((sp_nodepath_subpath_get_node_count(sp)<2 && !sp->closed) || (sp_nodepath_subpath_get_node_count(sp)<1 && sp->closed))
static void subpaths_from_pathvector(Inkscape::NodePath::Path *np, Geom::PathVector const & pathv, Inkscape::NodePath::NodeType const *t)
/* Johan: Note that this is pretty arcane code. I am pretty sure it is working correctly, be very certain to change it! (better to just rewrite this whole method)*/
/* Remember that last closing segment is always a lineto, but its length can be zero if the path is visually closed already
// Don't use !closing_seg.isDegenerate() as it is too precise, and does not account for floating point rounding probs (LP bug #257289)
if (types) {
switch (types[i]) {
return typestr;
// now that nodepath and knotholder can be enabled simultaneously, we must update the knotholder, too
if (repr->attribute(np->repr_key) == NULL || strcmp(svgpath, repr->attribute(np->repr_key))) { // d changed
if (repr->attribute(np->repr_nodetypes_key) == NULL || strcmp(typestr, repr->attribute(np->repr_nodetypes_key))) { // nodetypes changed
static void sp_nodepath_update_repr_keyed(Inkscape::NodePath::Path *np, gchar const *key, const gchar *annotation)
switch (n->code) {
case NR_LINETO:
case NR_CURVETO:
end_pt);
n = n->n.other;
n = NULL;
return curve;
switch (n->type) {
n = n->n.other;
n = NULL;
return typestr;
return mc;
static void sp_nodepath_line_midpoint(Inkscape::NodePath::Node *new_path,Inkscape::NodePath::Node *end, gdouble t)
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
result = 0;
return result;
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;
static Inkscape::NodePath::Node *sp_nodepath_set_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type)
return node;
if (!othernode)
if (!other_to_me)
bool is_line =
return is_line;
* with that segment, procucing half-smooth node. If already half-smooth, pull out the second handle too.
void sp_nodepath_convert_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type)
#define NODE_HAS_BOTH_HANDLES(node) ((Geom::L2(node->pos - node->n.pos) > 1e-6) && (Geom::L2(node->pos - node->p.pos) > 1e-6))
node->n.pos = node->pos + (len / Geom::L2(node->p.other->pos - node->pos)) * (node->p.other->pos - node->pos);
node->p.pos = node->pos + (len / Geom::L2(node->n.other->pos - node->pos)) * (node->n.other->pos - node->pos);
if (node_n) {
if (node_p) {
static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, Geom::Coord dx, Geom::Coord dy,
if (snap) {
unselected_nodes.push_back(std::make_pair(to_2geom(node->pos), node->type == Inkscape::NodePath::NODE_SMOOTH ? Inkscape::SNAPTARGET_NODE_SMOOTH : Inkscape::SNAPTARGET_NODE_CUSP));
if (closest_only) {
closest_node = n;
if (!closest_only || n == closest_node) { //try to snap either all selected nodes or only the closest one
Inkscape::SnapSourceType source_type = (n->type == Inkscape::NodePath::NODE_SMOOTH ? Inkscape::SNAPSOURCE_NODE_SMOOTH : Inkscape::SNAPSOURCE_NODE_CUSP);
if (constrained) {
s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), source_type, dedicated_constraint, false);
if (s.getSnapped()) {
best = s;
result = 0;
switch (profile) {
case SCULPT_PROFILE_LINEAR:
case SCULPT_PROFILE_BELL:
case SCULPT_PROFILE_ELLIPTIC:
return result;
sp_nodepath_move_node_and_handles (Inkscape::NodePath::Node *n, Geom::Point delta, Geom::Point delta_n, Geom::Point delta_p)
sp_node_update_handles(n, false);
sp_nodepath_selected_nodes_sculpt(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, Geom::Point delta)
g_assert (n);
if (pressure == 0)
// Do one step in both directions from n, until reaching the end of subpath or bumping into each other
n_going = false;
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;
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;
// Do one step in both directions from n, until reaching the end of subpath or bumping into each other
n_going = false;
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 + Geom::L2(n_node->n.origin - n_node->origin)) / n_sel_range, alpha, profile) * delta,
sculpt_profile ((n_range - Geom::L2(n_node->p.origin - n_node->origin)) / n_sel_range, alpha, profile) * delta);
n_going = false;
p_going = false;
p_going = false;
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 - Geom::L2(p_node->n.origin - p_node->origin)) / p_sel_range, alpha, profile) * delta,
sculpt_profile ((p_range + Geom::L2(p_node->p.origin - p_node->origin)) / p_sel_range, alpha, profile) * delta);
n_going = false;
p_going = false;
// use spatial mode, where the distance from n to node being dragged is measured directly as Geom::L2.
if (!nodepath) return;
if (dx == 0) {
} else if (dy == 0) {
sp_node_selected_move_screen(SPDesktop *desktop, Inkscape::NodePath::Path *nodepath, gdouble dx, gdouble dy)
// borrowed from sp_selection_move_screen in selection-chemistry.c
if (!nodepath) return;
if (dx == 0) {
} else if (dy == 0) {
void sp_node_selected_move_absolute(Inkscape::NodePath::Path *nodepath, Geom::Coord val, Geom::Dim2 axis)
* If the coordinates of all selected nodes coincide, return the common coordinate; otherwise return Geom::Nothing
boost::optional<Geom::Coord> sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, Geom::Dim2 axis)
bool coincide = true;
coincide = false;
if (coincide) {
return coord;
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
if (fire_move_signals) {
if (node->knot->pos != to_2geom(node->pos)) { // visible knot is in a different position, need to update
if (fire_move_signals)
if (nodepath) {
Inkscape::NodePath::Node *pNode = reinterpret_cast<Inkscape::NodePath::Node *>(nodepath->selected->data);
if (pNode) {
struct NodeSort
if ( ! (nodepath->selected->next && nodepath->selected->next->next) ) { // less than 3 nodes selected
Inkscape::NodePath::Node *pNode = reinterpret_cast<Inkscape::NodePath::Node *>(nodepath->selected->data);
if (pNode) {
it ++ )
if (!nodepath) {
int n_added = 0;
while (nl) {
n_added ++;
} else if (n_added > 0) {
sp_nodepath_select_segment_near_point(Inkscape::NodePath::Path *nodepath, Geom::Point p, bool toggle)
if (!nodepath) {
if (!pvpos) {
if (e->p.other)
if (!nodepath) {
if (!pvpos) {
double int_part;
* cf. app/vectors/gimpbezierstroke.c, gimp_bezier_stroke_point_move_relative()
double feel_good;
feel_good = 0;
if (!nodepath) return;
if (temp) {
if (!nodepath) {
if (temp) {
static void do_node_selected_join(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
c = a->pos;
c = b->pos;
sp_nodepath_node_new(t, NULL,Inkscape::NodePath::NODE_CUSP, NR_MOVETO, &n->n.pos, &n->pos, &n->p.pos);
n = n->p.other;
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;
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);
static void do_node_selected_join_segment(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
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;
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);
nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
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."));
switch(mode) {
case NODE_JOIN_ENDPOINTS:
case NODE_JOIN_SEGMENT:
while (nodes_to_delete) {
bool just_delete = false;
for (Inkscape::NodePath::Node *curr=node->p.other; curr && curr!=node && g_list_find(nodes_to_delete, curr); curr=curr->p.other) {
just_delete = true;
if (!just_delete) {
just_delete = true;
if (!just_delete) {
if (!nodepath) return;
int distance = 0;
int minDistance = 0;
if (curr==b) {
end = b;
distance++;
distance = 0;
if (curr==a) {
end = a;
distance++;
if (curr==b) {
end = b;
if (curr==a) {
end = a;
if (!start) {
if (selected) {
node->knot->setSize ((node->type == Inkscape::NodePath::NODE_CUSP || node->type == Inkscape::NodePath::NODE_AUTO) ? 11 : 9);
node->knot->setSize ((node->type == Inkscape::NodePath::NODE_CUSP || node->type == Inkscape::NodePath::NODE_AUTO) ? 9 : 7);
static void sp_nodepath_node_select(Inkscape::NodePath::Node *node, gboolean incremental, gboolean override)
if (incremental) {
if (override) {
if (!nodepath) return;
if (!nodepath) return;
GList *copy = g_list_copy (nodepath->selected); // copy initial selection so that selecting in the loop does not affect us
void sp_nodepath_select_rect(Inkscape::NodePath::Path *nodepath, Geom::Rect const &b, gboolean incremental)
if (!incremental) {
nodepath_grow_selection_linearly (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, int grow)
g_assert (n);
if (grow > 0) {
if (grow < 0) {
// Do one step in both directions from n, until reaching the end of subpath or bumping into each other
n_going = false;
n_range += bezier_length (n_node->p.other->pos, n_node->p.other->n.pos, n_node->p.pos, n_node->pos);
n_going = false;
p_going = false;
p_going = false;
p_range += bezier_length (p_node->n.other->pos, p_node->n.other->p.pos, p_node->n.pos, p_node->pos);
n_going = false;
p_going = false;
if (grow > 0) {
if (n_sel_range < p_sel_range && farthest_n_node && farthest_n_node->n.other && !(farthest_n_node->n.other->selected)) {
nodepath_grow_selection_spatially (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, int grow)
g_assert (n);
if (grow > 0) {
if (grow < 0) {
double farthest_dist = 0;
if (node == n)
if (grow > 0) {
if (closest_unselected) {
if (farthest_selected) {
\brief Saves selected nodes in a nodepath into a list containing integer positions of all selected nodes
guint i = 0;
guint i = 0;
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
case GDK_SCROLL:
if ((event->scroll.state & GDK_CONTROL_MASK) && !(event->scroll.state & GDK_SHIFT_MASK)) { // linearly
case GDK_SCROLL_UP:
case GDK_SCROLL_DOWN:
case GDK_SCROLL_UP:
case GDK_SCROLL_DOWN:
case GDK_KEY_PRESS:
case GDK_space:
case GDK_Page_Up:
case GDK_Page_Down:
return ret;
case GDK_BackSpace:
case GDK_c:
case GDK_s:
case GDK_a:
case GDK_y:
case GDK_b:
return ret;
return FALSE;
if (!n->selected) {
n->is_dragging = true;
// Reconstruct and store the location of the mouse pointer at the time when we started dragging (needed for snapping)
n->is_dragging = false;
point_line_closest(p, a, &c);
return sqrt(((*p)[Geom::X] - c[Geom::X])*((*p)[Geom::X] - c[Geom::X]) + ((*p)[Geom::Y] - c[Geom::Y])*((*p)[Geom::Y] - c[Geom::Y]));
static gboolean
( ((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) {
double appr_n = (n->n.other ? Geom::L2(n->n.other->pos - n->pos) - Geom::L2(n->n.other->pos - p) : -HUGE_VAL);
double appr_p = (n->p.other ? Geom::L2(n->p.other->pos - n->pos) - Geom::L2(n->p.other->pos - p) : -HUGE_VAL);
return FALSE;
n->dragging_out = &n->p;
opposite = &n->n;
n->dragging_out = &n->n;
opposite = &n->p;
n->dragging_out = &n->p;
opposite = &n->n;
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 ? Geom::L2(n->n.other->n.pos - n->pos) - Geom::L2(n->n.other->n.pos - p) : -HUGE_VAL);
double appr_other_p = (n->n.other ? Geom::L2(n->n.other->p.pos - n->pos) - Geom::L2(n->n.other->p.pos - p) : -HUGE_VAL);
n->dragging_out = &n->n;
opposite = &n->p;
n->dragging_out = &n->p;
opposite = &n->n;
return TRUE;
// if there's no n handle (straight line), see if we can use the direction to the next point on path
yn = n->n.other->origin[Geom::Y] - n->origin[Geom::Y]; // use origin because otherwise the direction will change as you drag
// 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) {
if (xn == 0) {
an = 0;
if (xp == 0) {
if (n->is_dragging) {
return TRUE;
if (!n->selected) {
n->p.origin_radial.a = 0;
n->n.origin_radial.a = 0;
me = &n->p;
opposite = &n->n;
me = &n->n;
opposite = &n->p;
which = 0;
Inkscape::SnapSourceType source_type = (n->type == Inkscape::NodePath::NODE_SMOOTH ? Inkscape::SNAPSOURCE_NODE_SMOOTH : Inkscape::SNAPSOURCE_NODE_CUSP);
if (othernode) {
s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p, source_type, Inkscape::Snapper::ConstraintLine(p, ndelta), false);
s.getPoint(p);
return FALSE;
me = &n->p;
other = &n->n;
me = &n->n;
other = &n->p;
if (me->origin_radial.a != HUGE_VAL) { // otherwise ortho doesn't exist: original handle was zero length
double const a_ortho = me->origin_radial.a + floor((rnew.a - me->origin_radial.a)/(M_PI/2) + 0.5) * (M_PI/2);
: a_ortho );
if (othernode) {
double const a_oppo = rother_to_snap.a + floor((rnew.a - rother_to_snap.a)/(M_PI/2) + 0.5) * (M_PI/2);
: a_oppo );
&& (rme.a != HUGE_VAL) && (rnew.a != HUGE_VAL) && ((fabs(rme.a - rnew.a) > 0.001) || (n->type ==Inkscape::NodePath::NODE_SYMM))) {
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);
case GDK_KEY_PRESS:
case GDK_space:
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
return ret;
if ( both
gdouble r;
if ( both
r = rme.r;
if ( both
static void node_rotate_one (Inkscape::NodePath::Node *n, gdouble angle, int which, gboolean screen)
bool both = false;
me = &(n->p);
other = &(n->n);
} else if (!n->p.other) {
me = &(n->n);
other = &(n->p);
me = &(n->n);
other = &(n->p);
me = &(n->p);
other = &(n->n);
me = &(n->n);
other = &(n->p);
me = &(n->p);
other = &(n->n);
me = &(n->n);
other = &(n->p);
both = true;
if (screen) {
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,
sp_node_update_handles(n, false);
void sp_nodepath_selected_nodes_rotate(Inkscape::NodePath::Path *nodepath, gdouble angle, int which, bool screen)
if (screen) {
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
sp_nodepath_update_repr_keyed(nodepath, angle > 0 ? "nodes:rot:p" : "nodes:rot:n", _("Rotate nodes"));
bool both = false;
me = &(n->p);
other = &(n->n);
} else if (!n->p.other) {
me = &(n->n);
other = &(n->p);
if (n->n.other)
me = &(n->n);
other = &(n->p);
if (n->n.other)
me = &(n->p);
other = &(n->n);
me = &(n->n);
other = &(n->p);
if (n->n.other)
me = &(n->p);
other = &(n->n);
me = &(n->n);
other = &(n->p);
both = true;
if (n->n.other)
rme.a = 0;
// this function is only called from sp_nodepath_selected_nodes_scale that will update display at the end,
sp_node_update_handles(n, false);
void sp_nodepath_selected_nodes_scale(Inkscape::NodePath::Path *nodepath, gdouble const grow, int const which)
if (!ec) return;
if (!mc) return;
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
sp_nodepath_update_repr_keyed(nodepath, grow > 0 ? "nodes:scale:p" : "nodes:scale:n", _("Scale nodes"));
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.
void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, Geom::Dim2 axis, boost::optional<Geom::Point> center)
sp_node_update_handles(n, false);
if (!center) {
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
return box;
Inkscape::NodePath::Node *new_path = sp_nodepath_node_new(sp, n->n.other,Inkscape::NodePath::NODE_CUSP, NR_MOVETO,
sp_nodepath_node_new(Inkscape::NodePath::SubPath *sp, Inkscape::NodePath::Node *next, Inkscape::NodePath::NodeType type, NRPathcode code, Geom::Point *ppos, Geom::Point *pos, Geom::Point *npos)
if (next) {
if (prev)
if (next)
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"));
g_signal_handlers_disconnect_by_func(G_OBJECT(node->knot), (gpointer) G_CALLBACK(node_event), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->knot), (gpointer) G_CALLBACK(node_clicked), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->knot), (gpointer) G_CALLBACK(node_grabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->knot), (gpointer) G_CALLBACK(node_ungrabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->knot), (gpointer) G_CALLBACK(node_request), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_clicked), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_grabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_ungrabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_request), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_moved), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->p.knot), (gpointer) G_CALLBACK(node_handle_event), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_clicked), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_grabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_ungrabbed), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_request), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_moved), node);
g_signal_handlers_disconnect_by_func(G_OBJECT(node->n.knot), (gpointer) G_CALLBACK(node_handle_event), node);
switch (which) {
return result;
static Inkscape::NodePath::NodeSide *sp_node_opposite_side(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeSide *me)
return result;
static NRPathcode sp_node_path_code_from_side(Inkscape::NodePath::Node *node,Inkscape::NodePath::NodeSide *me)
return result;
if (!nodepath) {
if (index < n) {
for (int i = 0; i < index; ++i) {
e = e->n.other;
index -= n;
unsigned retracted = 0;
bool endnode = false;
retracted ++;
endnode = true;
if (retracted == 0) {
if (endnode) {
if (endnode) {
return NULL;
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) {
if (!ec) return;
if (!mc) return;
if (selected_nodes == 0) {
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.",
selected_nodes, total_nodes, sp_node_type_description((Inkscape::NodePath::Node *) nodepath->selected->data), when_selected_one);
if (!object)
return NULL;
if (svgd) {
if (curve_new) {
return curve;
if (lpe) {
Inkscape::LivePathEffect::PathParam *pathparam = dynamic_cast<Inkscape::LivePathEffect::PathParam *>( lpe->getParameter(np->repr_key) );
if (pathparam) {
/// \todo this code to generate a helper canvasitem from an spcurve should be moved to different file
sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const Geom::Matrix & i2d, guint32 color = 0xff0000ff) {
// would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
return canvasitem;
return NULL;
return NULL;
g_warning ("-----> sp_nodepath_generate_helperpath(SPDesktop *desktop, SPItem *item): TODO: generate the helper path for this item type!\n");
return NULL;
return helperpath;
if (show) {
//np->helper_path = sp_nodepath_make_helper_item(np, desktop, helper_curve, true); // Caution: this applies the transform np->i2d twice!!
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(np->helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);