diff --git a/src/nodepath.cpp b/src/nodepath.cpp
index 3b9063f33ad7ca06a4458ac3dc53151f4deedf55..e03484d7a383033b8af80f7499e5b8040ad11f62 100644 (file)
--- a/src/nodepath.cpp
+++ b/src/nodepath.cpp
#include "display/bezier-utils.h"
#include <vector>
#include <algorithm>
+#include <cstring>
+#include <string>
#include "live_effects/lpeobject.h"
#include "live_effects/parameter/parameter.h"
+#include "util/mathfns.h"
class NR::Matrix;
np->local_change = 0;
np->show_handles = show_handles;
np->helper_path = NULL;
+ np->helperpath_rgba = 0xff0000ff;
+ np->helperpath_width = 1.0;
np->curve = sp_curve_copy(curve);
np->show_helperpath = false;
np->straight_path = false;
np->repr_nodetypes_key = g_strconcat(np->repr_key, "-nodetypes", NULL);
Inkscape::LivePathEffect::Parameter *lpeparam = LIVEPATHEFFECT(object)->lpe->getParameter(repr_key_in);
if (lpeparam) {
- lpeparam->param_setup_notepath(np);
+ lpeparam->param_setup_nodepath(np);
}
} else {
np->repr_nodetypes_key = g_strdup("sodipodi:nodetypes");
LivePathEffectObject *lpeobj = sp_shape_get_livepatheffectobject(SP_SHAPE(np->object));
if (lpeobj && lpeobj->lpe) {
- lpeobj->lpe->setup_notepath(np);
+ lpeobj->lpe->setup_nodepath(np);
}
} else {
np->repr_key = g_strdup("d");
@@ -1012,18 +1017,30 @@ void sp_nodepath_convert_node_type(Inkscape::NodePath::Node *node, Inkscape::Nod
// only if both adjacent segments are lines,
// convert both to curves:
- // BEFORE:
- {
node->code = NR_CURVETO;
- NR::Point delta = node->n.other->pos - node->p.other->pos;
- node->p.pos = node->pos - delta / 4;
+ node->n.other->code = NR_CURVETO;
+
+ NR::Point leg_prev = node->pos - node->p.other->pos;
+ NR::Point leg_next = node->pos - node->n.other->pos;
+
+ double norm_leg_prev = L2(leg_prev);
+ double norm_leg_next = L2(leg_next);
+
+ // delta has length 1 and is orthogonal to bisecting line
+ NR::Point delta;
+ if (norm_leg_next > 0.0) {
+ delta = (norm_leg_prev / norm_leg_next) * leg_next - leg_prev;
+ (&delta)->normalize();
}
- // AFTER:
- {
- node->n.other->code = NR_CURVETO;
- NR::Point delta = node->p.other->pos - node->n.other->pos;
- node->n.pos = node->pos - delta / 4;
+ if (type == Inkscape::NodePath::NODE_SYMM) {
+ double norm_leg_avg = (norm_leg_prev + norm_leg_next) / 2;
+ node->p.pos = node->pos + 0.3 * norm_leg_avg * delta;
+ node->n.pos = node->pos - 0.3 * norm_leg_avg * delta;
+ } else {
+ // length of handle is proportional to distance to adjacent node
+ node->p.pos = node->pos + 0.3 * norm_leg_prev * delta;
+ node->n.pos = node->pos - 0.3 * norm_leg_next * delta;
}
sp_node_update_handles(node);
@@ -1359,6 +1376,51 @@ sp_node_selected_move_screen(Inkscape::NodePath::Path *nodepath, gdouble dx, gdo
}
}
+/**
+ * Move selected nodes to the absolute position given
+ */
+void sp_node_selected_move_absolute(Inkscape::NodePath::Path *nodepath, NR::Coord val, NR::Dim2 axis)
+{
+ for (GList *l = nodepath->selected; l != NULL; l = l->next) {
+ Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
+ NR::Point npos(axis == NR::X ? val : n->pos[NR::X], axis == NR::Y ? val : n->pos[NR::Y]);
+ sp_node_moveto(n, npos);
+ }
+
+ sp_nodepath_update_repr(nodepath, _("Move nodes"));
+}
+
+/**
+ * If the coordinates of all selected nodes coincide, return the common coordinate; otherwise return NR::Nothing
+ */
+NR::Maybe<NR::Coord> sp_node_selected_common_coord (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis)
+{
+ NR::Maybe<NR::Coord> no_coord = NR::Nothing();
+ g_return_val_if_fail(nodepath->selected, no_coord);
+
+ // determine coordinate of first selected node
+ GList *nsel = nodepath->selected;
+ Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) nsel->data;
+ NR::Coord coord = n->pos[axis];
+ bool coincide = true;
+
+ // compare it to the coordinates of all the other selected nodes
+ for (GList *l = nsel->next; l != NULL; l = l->next) {
+ n = (Inkscape::NodePath::Node *) l->data;
+ if (n->pos[axis] != coord) {
+ coincide = false;
+ }
+ }
+ if (coincide) {
+ return coord;
+ } else {
+ NR::Rect bbox = sp_node_selected_bbox(nodepath);
+ // currently we return the coordinate of the bounding box midpoint because I don't know how
+ // to erase the spin button entry field :), but maybe this can be useful behaviour anyway
+ return bbox.midpoint()[axis];
+ }
+}
+
/** 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)
{
@@ -3920,13 +3982,7 @@ void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis, NR::Ma
} else {
// scale nodes as an "object":
- Inkscape::NodePath::Node *n0 = (Inkscape::NodePath::Node *) nodepath->selected->data;
- NR::Rect box (n0->pos, n0->pos); // originally includes the first selected node
- for (GList *l = nodepath->selected; l != NULL; l = l->next) {
- Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
- box.expandTo (n->pos); // contain all selected nodes
- }
-
+ NR::Rect box = sp_node_selected_bbox (nodepath);
if (!center) {
center = box.midpoint();
}
@@ -3947,6 +4003,19 @@ void sp_nodepath_flip (Inkscape::NodePath::Path *nodepath, NR::Dim2 axis, NR::Ma
sp_nodepath_update_repr(nodepath, _("Flip nodes"));
}
+NR::Rect sp_node_selected_bbox (Inkscape::NodePath::Path *nodepath)
+{
+ g_assert (nodepath->selected);
+
+ Inkscape::NodePath::Node *n0 = (Inkscape::NodePath::Node *) nodepath->selected->data;
+ NR::Rect box (n0->pos, n0->pos); // originally includes the first selected node
+ for (GList *l = nodepath->selected; l != NULL; l = l->next) {
+ Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
+ box.expandTo (n->pos); // contain all selected nodes
+ }
+ return box;
+}
+
//-----------------------------------------------
/**
* Return new subpath under given nodepath.
@@ -4034,15 +4103,6 @@ static void sp_nodepath_subpath_open(Inkscape::NodePath::SubPath *sp,Inkscape::N
new_path->p.other = NULL;
}
-/**
- * Returns area in triangle given by points; may be negative.
- */
-inline double
-triangle_area (NR::Point p1, NR::Point p2, NR::Point p3)
-{
- 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.
@@ -4067,7 +4127,7 @@ sp_nodepath_node_new(Inkscape::NodePath::SubPath *sp, Inkscape::NodePath::Node *
// use the type from sodipodi:nodetypes
n->type = type;
} else {
- if (fabs (triangle_area (*pos, *ppos, *npos)) < 1e-2) {
+ if (fabs (Inkscape::Util::triangle_area (*pos, *ppos, *npos)) < 1e-2) {
// points are (almost) collinear
if (NR::L2(*pos - *ppos) < 1e-6 || NR::L2(*pos - *npos) < 1e-6) {
// endnode, or a node with a retracted handle
@@ -4388,6 +4448,8 @@ sp_nodepath_update_statusbar(Inkscape::NodePath::Path *nodepath)//!!!move to Sha
Inkscape::MessageContext *mc = SP_NODE_CONTEXT (ec)->_node_message_context;
if (!mc) return;
+ inkscape_active_desktop()->emitToolSubselectionChanged(NULL);
+
if (selected_nodes == 0) {
Inkscape::Selection *sel = desktop->selection;
if (!sel || sel->isEmpty()) {
void sp_nodepath_show_helperpath(Inkscape::NodePath::Path *np, bool show) {
np->show_helperpath = show;
+
+ if (show) {
+ SPCurve *helper_curve = sp_curve_copy(np->curve);
+ sp_curve_transform(helper_curve, np->i2d );
+ if (!np->helper_path) {
+ np->helper_path = sp_canvas_bpath_new(sp_desktop_controls(np->desktop), helper_curve);
+ 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);
+ sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(np->helper_path), 0, SP_WIND_RULE_NONZERO);
+ sp_canvas_item_show(np->helper_path);
+ } else {
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(np->helper_path), helper_curve);
+ }
+ sp_curve_unref(helper_curve);
+ } else {
+ if (np->helper_path) {
+ GtkObject *temp = np->helper_path;
+ np->helper_path = NULL;
+ gtk_object_destroy(temp);
+ }
+ }
}
/* this function does not work yet */