nodepath.cpp revision 146543b2fdf32d200a0bf114cb785a5b92054b2a
#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/canvas-bpath.h"
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include "display/sp-canvas-util.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 "shape-editor.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 "verbs.h"
#include "display/bezier-utils.h"
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
#include "live_effects/effect.h"
#include "live_effects/parameter/parameter.h"
#include "live_effects/parameter/path.h"
#include "display/snap-indicator.h"
#include "snapped-point.h"
/// \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 */
static void subpaths_from_pathvector(Inkscape::NodePath::Path *np, Geom::PathVector const & pathv, Inkscape::NodePath::NodeType const *t);
static void add_curve_to_subpath( Inkscape::NodePath::Path *np, Inkscape::NodePath::SubPath *sp, Geom::Curve const & c,
/* Object updating */
static void sp_nodepath_node_select(Inkscape::NodePath::Node *node, gboolean incremental, gboolean override);
static Inkscape::NodePath::Node *sp_nodepath_set_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type);
/* 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
static SPCanvasItem *
sp_nodepath_make_helper_item(Inkscape::NodePath::Path *np, /*SPDesktop *desktop, */const SPCurve *curve, bool show = false) {
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helper_path), np->helperpath_rgba, np->helperpath_width, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
if (show) {
}
helper_curve->unref();
return helper_path;
}
static SPCanvasItem *
}
static void
//std::map<Inkscape::LivePathEffect::Effect *, std::vector<SPCanvasItem *> >* helper_path_vec;
g_print ("Only LPEItems can have helperpaths!\n");
return;
}
// create new canvas items from the effect's helper paths
}
}
}
void
//std::map<Inkscape::LivePathEffect::Effect *, std::vector<SPCanvasItem *> >* helper_path_vec;
g_print ("Only LPEItems can have helperpaths!\n");
return;
}
/* update canvas items from the effect's helper paths; note that this code relies on the
* fact that getHelperPaths() will always return the same number of helperpaths in the same
* order as during their creation in sp_nodepath_create_helperpaths
*/
}
}
}
static void
for (HelperPathList::iterator i = np->helper_path_vec->begin(); i != np->helper_path_vec->end(); ++i) {
*j = NULL;
}
}
}
/**
* \brief Creates new nodepath from item
*/
Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, bool show_handles, const char * repr_key_in, SPItem *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(object)) {
for (SPObject *child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
if SP_IS_FLOWREGION(child) {
break;
}
}
}
}
return NULL;
return NULL; // prevent crash for one-node paths
}
//Create new nodepath
if (!np) {
return NULL;
}
// Set defaults
np->local_change = 0;
if (SP_IS_LPE_ITEM(object)) {
np->show_helperpath = true;
}
}
np->straight_path = false;
} else {
}
// 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
if (repr_key_in) { // apparantly the object is an LPEObject
Inkscape::LivePathEffect::Parameter *lpeparam = LIVEPATHEFFECT(object)->lpe->getParameter(repr_key_in);
if (lpeparam) {
}
} else {
if (lpe) {
}
} else {
}
}
/* Calculate length of the nodetype string. The closing/starting point for closed paths is counted twice.
* So for example a closed rectangle has a nodetypestring of length 5.
* To get the correct count, one can count all segments in the paths, and then add the total number of (non-empty) paths. */
}
// create the subpath(s) from the bpath
// reverse the list, because sp_nodepath_subpath_new() used g_list_prepend instead of append (for speed)
delete[] typestr;
// Draw helper curve
if (np->show_helperpath) {
}
return np;
}
/**
* Destroys nodepath's subpaths, then itself, also tell parent ShapeEditor about it.
*/
if (!np) //soft fail, like delete
return;
}
//Inform the ShapeEditor that made me, if any, that I am gone.
if (np->shape_editor)
if (np->helper_path) {
}
}
}
if (np->repr_nodetypes_key) {
}
delete np->helper_path_vec;
}
/**
* 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 nodepaths from pathvector, make it subpaths of np.
* \param t The node type array.
*/
static void subpaths_from_pathvector(Inkscape::NodePath::Path *np, Geom::PathVector const & pathv, Inkscape::NodePath::NodeType const *t)
{
guint i = 0; // index into node type array
continue; // don't add single knot paths
}
// Add last knot (because sp_nodepath_subpath_close kills the last knot)
/* Remember that last closing segment is always a lineto, but its length can be zero if the path is visually closed already
* If the length is zero, don't add it to the nodepath. */
if ( ! closing_seg.isDegenerate() ) {
}
}
}
}
// should add initial point of curve with type of previous curve:
static void add_curve_to_subpath(Inkscape::NodePath::Path *np, Inkscape::NodePath::SubPath *sp, Geom::Curve const & c, Inkscape::NodePath::NodeType const *t, guint & i,
{
if( dynamic_cast<Geom::LineSegment const*>(&c) ||
dynamic_cast<Geom::HLineSegment const*>(&c) ||
dynamic_cast<Geom::VLineSegment const*>(&c) )
{
}
pcode = NR_CURVETO;
}
else {
//this case handles sbasis as well as all other curve types
}
}
}
/**
* Convert from sodipodi:nodetypes to new style type array.
*/
static
{
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.
*/
{
if (np->show_helperpath) {
helper_curve->unref();
}
// updating helperpaths of LPEItems is now done in sp_lpe_item_update();
//sp_nodepath_update_helperpaths(np);
// now that nodepath and knotholder can be enabled simultaneously, we must update the knotholder, too
// TODO: this should be done from ShapeEditor!! nodepath should be oblivious of knotholder!
}
/**
* Update XML path node with data from path object.
*/
{
// determine if path has an effect applied and write to correct "d" attribute.
if (repr->attribute(np->repr_key) == NULL || strcmp(svgpath, repr->attribute(np->repr_key))) { // d changed
np->local_change++;
}
if (repr->attribute(np->repr_nodetypes_key) == NULL || strcmp(typestr, repr->attribute(np->repr_nodetypes_key))) { // nodetypes changed
np->local_change++;
}
if (np->show_helperpath) {
helper_curve->unref();
}
// TODO: do we need this call here? after all, update_object() should have been called just before
//sp_nodepath_update_helperpaths(np);
}
/**
* Update XML path node with data from path object, commit changes forever.
*/
{
//fixme: np can be NULL, so check before proceeding
}
/**
* Update XML path node with data from path object, commit changes with undo.
*/
static void sp_nodepath_update_repr_keyed(Inkscape::NodePath::Path *np, gchar const *key, const gchar *annotation)
{
}
/**
* 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
_("Stamp"));
}
/**
* 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. // later eliminate this function at all!
*/
{
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);
// attach rest of curve to new node
}
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)
{
}
}
} else {
}
// if one of handles is mouseovered, preserve its position
} else {
}
return node;
}
bool
{
if (!othernode)
return false;
return true;
other_to_me = &othernode->n;
other_to_me = &othernode->p;
}
if (!other_to_me)
return false;
bool is_line =
return is_line;
}
/**
* Same as sp_nodepath_set_node_type(), but also converts, if necessary, adjacent segments from
* lines to curves. If adjacent to one line segment, pulls out or rotates opposite handle to align
* with that segment, procucing half-smooth node. If already half-smooth, pull out the second handle too.
* If already cusp and set to cusp, retracts handles.
*/
void sp_nodepath_convert_node_type(Inkscape::NodePath::Node *node, Inkscape::NodePath::NodeType type)
{
/*
Here's the algorithm of converting node to smooth (Shift+S or toolbar button), in pseudocode:
if (two_handles) {
// do nothing, adjust_handles called via set_node_type will line them up
} else if (one_handle) {
if (opposite_to_handle_is_line) {
if (lined_up) {
// already half-smooth; pull opposite handle too making it fully smooth
} else {
// do nothing, adjust_handles will line the handle up, producing a half-smooth node
}
} else {
// pull opposite handle in line with the existing one
}
} else if (no_handles) {
if (both_segments_are_lines OR both_segments_are_curves) {
//pull both handles
} else {
// pull the handle opposite to line segment, making node half-smooth
}
}
*/
if (p_has_handle && n_has_handle) {
// do nothing, adjust_handles will line them up
} else if (p_has_handle || n_has_handle) {
if (p_has_handle && n_is_line) {
// already half-smooth; pull opposite handle too making it fully smooth
} else {
// do nothing, adjust_handles will line the handle up, producing a half-smooth node
}
} else if (n_has_handle && p_is_line) {
// already half-smooth; pull opposite handle too making it fully smooth
} else {
// do nothing, adjust_handles will line the handle up, producing a half-smooth node
}
// pull n handle
// pull p handle
}
} else if (!p_has_handle && !n_has_handle) {
// no handles, but both segments are either lnes or curves:
//pull both handles
// convert both to curves:
if (norm_leg_next > 0.0) {
}
} else {
// length of handle is proportional to distance to adjacent node
}
} else {
// pull the handle opposite to line segment, making it half-smooth
// pull n handle
node->n.pos = node->pos + (len / NR::L2(node->p.other->pos - node->pos)) * (node->p.other->pos - node->pos);
}
// pull p handle
node->p.pos = node->pos + (len / NR::L2(node->n.other->pos - node->pos)) * (node->n.other->pos - node->pos);
}
}
}
}
// cusping a cusp: retract nodes
}
}
/**
* 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);
if (node_n) {
sp_node_update_handles(node_n, false);
}
if (node_p) {
sp_node_update_handles(node_p, 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, bool constrained = false,
{
if (snap) {
/* When dragging a (selected) node, it should only snap to other nodes (i.e. unselected nodes), and
* not to itself. The snapper however can not tell which nodes are selected and which are not, so we
* must provide that information. */
// Build a list of the unselected nodes to which the snapper should snap
}
}
}
Inkscape::SnappedPoint s;
if (constrained) {
} else {
}
best = s.getDistance();
best_abs = s;
}
}
if (best_abs.getSnapped()) {
} else {
}
}
}
// 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
{
if (x >= 1)
return 0;
if (x <= 0)
return 1;
switch (profile) {
case SCULPT_PROFILE_LINEAR:
return 1 - x;
case SCULPT_PROFILE_BELL:
case SCULPT_PROFILE_ELLIPTIC:
return sqrt(1 - x*x);
}
return 1;
}
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, profile) * delta,
sculpt_profile ((n_range - NR::L2(n_node->p.origin - n_node->origin)) / n_sel_range, alpha, profile) * 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, profile) * delta,
sculpt_profile ((p_range + NR::L2(p_node->p.origin - p_node->origin)) / p_sel_range, alpha, profile) * 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 {
}
}
/**
* Move selected nodes to the absolute position given
*/
void sp_node_selected_move_absolute(Inkscape::NodePath::Path *nodepath, NR::Coord val, NR::Dim2 axis)
{
sp_node_moveto(n, npos);
}
}
/**
* 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)
{
// determine coordinate of first selected node
bool coincide = true;
// compare it to the coordinates of all the other selected nodes
coincide = false;
}
}
if (coincide) {
return coord;
} else {
// 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
}
}
/** 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
{
}
/**
* 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;
}
int n_added = 0;
}
}
while (nl) {
n_added ++;
}
/** \todo fixme: adjust ? */
if (n_added > 1) {
} else if (n_added > 0) {
}
}
/**
* Select segment nearest to point
*/
void
{
if (!nodepath) {
return;
}
// calculate index for nodepath's representation.
segment_index += 1;
}
}
//find segment to segment
//fixme: this can return NULL, so check before proceeding.
g_return_if_fail(e != NULL);
}
if (e->p.other)
}
/**
* Add a node nearest to point
*/
void
{
if (!nodepath) {
return;
}
// calculate index for nodepath's representation.
double int_part;
segment_index += 1;
}
}
//find segment to split
//don't know why but t seems to flip for lines
t = 1.0 - t;
}
/* 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
{
//fixme: e and e->p can be NULL, so check for those before proceeding
g_return_if_fail(e != NULL);
g_return_if_fail(&e->p != NULL);
/* 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.
*/
{
if (!nodepath) return;
}
if (temp) {
}
}
}
/**
* Duplicate the selected node(s).
*/
{
if (!nodepath) {
return;
}
}
if (temp) {
}
}
}
/**
* Internal function to join two nodes by merging them into one.
*/
static void do_node_selected_join(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
{
/* a and b are endpoints */
// if one of the two nodes is mouseovered, fix its position
c = a->pos;
c = b->pos;
} else {
// otherwise, move joined node to the midpoint
}
return;
}
/* a and b are separate subpaths */
// we will now reverse sa, so that a is its last node, not first, and drop that node
// create new subpath
// create a first moveto node on it
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) {
// copy the rest of the nodes from sa to t, going backwards
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;
}
// replace sa with t
sa = t;
// a is already last, just drop it
} else {
}
// copy all nodes from b to a, forward
sp_nodepath_node_new(sa, NULL, (Inkscape::NodePath::NodeType)n->type, (NRPathcode)n->code, &n->p.pos, &n->pos, &n->n.pos);
}
// copy all nodes from b to a, backward
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 */
}
/**
* Internal function to join two nodes by adding a segment between them.
*/
static void do_node_selected_join_segment(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
{
/*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 */
}
/**
* Internal function to handle joining two nodes.
*/
{
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);
// someone tried to join an orphan node (i.e. a single-node subpath).
// this is not worth an error message, just fail silently.
return;
}
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;
}
switch(mode) {
case NODE_JOIN_ENDPOINTS:
do_node_selected_join(nodepath, a, b);
break;
case NODE_JOIN_SEGMENT:
break;
}
}
/**
* Join two nodes by merging them into one.
*/
{
}
/**
* Join two nodes by adding a segment between them.
*/
{
}
/**
* 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?
//if these nodes are smooth or symmetrical, the endpoints will be thrown out of sync.
//make sure these nodes are changed to cusp nodes so that, once the endpoints are moved,
//the resulting nodes behave as expected.
//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)
_("Delete nodes"));
} else {
}
}
}
/**
* Delete one or more selected nodes.
*/
{
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.
_("Delete nodes"));
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) {
}
}
}
}
}
void
nodepath_grow_selection_linearly (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, int grow)
{
g_assert (n);
if (grow > 0) {
}
return;
}
if (grow < 0) {
return;
}
}
double n_sel_range = 0, p_sel_range = 0;
// Calculate ranges
{
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->pos, n_node->p.other->n.pos, n_node->p.pos, n_node->pos);
}
n_going = false;
p_going = false;
}
}
p_going = false;
} else {
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)) {
}
} else {
}
}
}
void
nodepath_grow_selection_spatially (Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *n, int grow)
{
g_assert (n);
if (grow > 0) {
}
return;
}
if (grow < 0) {
return;
}
}
double farthest_dist = 0;
double closest_dist = NR_HUGE;
if (node == n)
continue;
}
} else {
}
}
}
}
if (grow > 0) {
if (closest_unselected) {
}
} else {
if (farthest_selected) {
}
}
}
/**
\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.
*/
{
// nothing to do if we are an end node
// nothing to do if we are a cusp node
// nothing to do if it's a line from the specified side of the node (i.e. no handle to adjust)
if (which_adjust == 1) {
} else {
}
// other is a line, and we are either smooth or symm
if (linelen < 1e-18)
return;
return;
}
// symmetrize
return;
} else {
// smoothify
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:
break;
case GDK_LEAVE_NOTIFY:
break;
case GDK_SCROLL:
if ((event->scroll.state & GDK_CONTROL_MASK) && !(event->scroll.state & GDK_SHIFT_MASK)) { // linearly
case GDK_SCROLL_UP:
break;
case GDK_SCROLL_DOWN:
break;
default:
break;
}
case GDK_SCROLL_UP:
break;
case GDK_SCROLL_DOWN:
break;
default:
break;
}
}
break;
case GDK_KEY_PRESS:
case GDK_space:
}
break;
case GDK_Page_Up:
} else {
}
break;
case GDK_Page_Down:
} else {
}
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:
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) {
}
n->is_dragging = true;
}
/**
* Mouse ungrabbed node callback.
*/
{
n->dragging_out = NULL;
n->is_dragging = false;
}
/**
* 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)
( ((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->origin[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
true);
true,
} else { // snap to vert
true,
}
}
} else { // move freely
if (n->is_dragging) {
} 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;
}
Inkscape::SnappedPoint s;
if ((state & GDK_SHIFT_MASK) != 0) {
// We will not try to snap when the shift-key is pressed
// so remove the old snap indicator and don't wait for it to time-out
}
if (othernode) {
/* We are smooth node adjacent with line */
}
if ((state & GDK_SHIFT_MASK) == 0) {
s = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta));
}
} else {
if ((state & GDK_SHIFT_MASK) == 0) {
}
}
} else {
if ((state & GDK_SHIFT_MASK) == 0) {
}
}
s.getPoint(*p);
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". */
// 2. Snap to the original angle, its opposite and perpendiculars
if (me->origin_radial.a != HUGE_VAL) { // otherwise ortho doesn't exist: original handle was zero length
/* The closest PI/2 angle, starting from original angle */
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 );
}
// 3. Snap to the angle of the opposite line, if any
if (othernode) {
if (sp_node_side_is_line(n, other)) {
} else {
}
/* The closest PI/2 angle, starting from the angle of the opposite line segment */
double const a_oppo = rother_to_snap.a + floor((rnew.a - rother_to_snap.a)/(M_PI/2) + 0.5) * (M_PI/2);
// Snap to the closest.
: a_oppo );
}
}
}
if (state & GDK_MOD1_MASK) {
// lock handle length
}
&& rme.a != HUGE_VAL && rnew.a != HUGE_VAL && (fabs(rme.a - rnew.a) > 0.001 || n->type ==Inkscape::NodePath::NODE_SYMM)) {
// rotate the other handle correspondingly, if both old and new angles exist and are not the same
}
}
// move knot, 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;
case GDK_ENTER_NOTIFY:
// we use an experimentally determined threshold that seems to work fine
break;
case GDK_LEAVE_NOTIFY:
// we use an experimentally determined threshold that seems to work fine
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 {
}
else
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"));
}
/**
* 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":
}
else
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, NR::Dim2 axis, NR::Maybe<NR::Point> center)
{
// flip handles of the single selected node
sp_node_update_handles(n, false);
} else {
// scale nodes as an "object":
if (!center) {
}
n->pos *= t;
n->n.pos *= t;
n->p.pos *= t;
sp_node_update_handles(n, false);
}
}
}
{
}
return box;
}
//-----------------------------------------------
/**
* 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
}
/**
* 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.
*/
{
}
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);
}
}
} 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;
}
/**
* Return node with the given index
*/
{
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.",
}
}
}
/*
* returns a *copy* of the curve of that object.
*/
if (!object)
return NULL;
if (SP_IS_PATH(object)) {
if (svgd) {
if (curve_new) {
}
}
}
return curve;
}
return;
} else {
}
Inkscape::LivePathEffect::PathParam *pathparam = dynamic_cast<Inkscape::LivePathEffect::PathParam *>( LIVEPATHEFFECT(np->object)->lpe->getParameter(np->repr_key) );
if (pathparam) {
}
}
}
/**
SPCanvasItem *
sp_nodepath_path_to_canvasitem(Inkscape::NodePath::Path *np, SPPath *path) {
return sp_nodepath_make_helper_item(np, sp_path_get_curve_for_edit(path));
}
**/
/**
SPCanvasItem *
sp_nodepath_generate_helperpath(SPDesktop *desktop, SPCurve *curve, const SPItem *item, guint32 color = 0xff0000ff) {
SPCurve *flash_curve = curve->copy();
Geom::Matrix i2d = item ? sp_item_i2d_affine(item) : Geom::identity();
flash_curve->transform(i2d);
SPCanvasItem * canvasitem = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), flash_curve);
// would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
// unless we also flash the nodes...
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvasitem), 0, SP_WIND_RULE_NONZERO);
sp_canvas_item_show(canvasitem);
flash_curve->unref();
return canvasitem;
}
SPCanvasItem *
sp_nodepath_generate_helperpath(SPDesktop *desktop, SPPath *path) {
return sp_nodepath_generate_helperpath(desktop, sp_path_get_curve_for_edit(path), SP_ITEM(path),
prefs_get_int_attribute("tools.nodes", "highlight_color", 0xff0000ff));
}
**/
// would be nice if its color could be XORed or something, now it is invisible for red stroked objects...
// unless we also flash the nodes...
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvasitem), color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
flash_curve->unref();
return canvasitem;
}
// TODO: Merge this with sp_nodepath_make_helper_item()!
if (show) {
if (!np->helper_path) {
//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);
} else {
}
helper_curve->unref();
} else {
if (np->helper_path) {
}
}
}
/* sp_nodepath_make_straight_path:
* Prevents user from curving the path by dragging a segment or activating handles etc.
* The resulting path is a linear interpolation between nodal points, with only straight segments.
* !!! this function does not work completely yet: it does not actively straighten the path, only prevents the path from being curved
*/
np->straight_path = true;
np->show_handles = false;
g_message("add code to make the path straight.");
// do sp_nodepath_convert_node_type on all nodes?
// coding tip: search for this text : "Make selected segments lines"
}
/*
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 :