summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9a9619b)
raw | patch | inline | side by side (parent: 9a9619b)
author | johncoswell <johncoswell@users.sourceforge.net> | |
Sun, 30 Mar 2008 14:43:04 +0000 (14:43 +0000) | ||
committer | johncoswell <johncoswell@users.sourceforge.net> | |
Sun, 30 Mar 2008 14:43:04 +0000 (14:43 +0000) |
src/nodepath.cpp | patch | blob | history |
diff --git a/src/nodepath.cpp b/src/nodepath.cpp
index 84d1125f44e2e7fbce5dd2d612a061494fe4a799..924d57595be1993cd3452c8e60cf5d6f5fe82d7e 100644 (file)
--- a/src/nodepath.cpp
+++ b/src/nodepath.cpp
}
/**
- * Join two nodes by merging them into one.
+ * Internal function to join two nodes by merging them into one.
*/
-void sp_node_selected_join(Inkscape::NodePath::Path *nodepath)
+static void do_node_selected_join(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
{
- if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
-
- if (g_list_length(nodepath->selected) != 2) {
- nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
- return;
- }
-
- Inkscape::NodePath::Node *a = (Inkscape::NodePath::Node *) nodepath->selected->data;
- Inkscape::NodePath::Node *b = (Inkscape::NodePath::Node *) nodepath->selected->next->data;
-
- g_assert(a != b);
- if (!(a->p.other || a->n.other) || !(b->p.other || b->n.other)) {
- // 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;
- }
-
/* a and b are endpoints */
NR::Point c;
}
/* a and b are separate subpaths */
- Inkscape::NodePath::SubPath *sa = a->subpath;
- Inkscape::NodePath::SubPath *sb = b->subpath;
+ Inkscape::NodePath::SubPath *sa = a->subpath;
+ Inkscape::NodePath::SubPath *sb = b->subpath;
NR::Point p;
- Inkscape::NodePath::Node *n;
+ Inkscape::NodePath::Node *n;
NRPathcode code;
if (a == sa->first) {
p = sa->first->n.pos;
}
/**
- * Join two nodes by adding a segment between them.
+ * Internal function to join two nodes by adding a segment between them.
*/
-void sp_node_selected_join_segment(Inkscape::NodePath::Path *nodepath)
+static void do_node_selected_join_segment(Inkscape::NodePath::Path *nodepath, Inkscape::NodePath::Node *a, Inkscape::NodePath::Node *b)
{
- if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
-
- if (g_list_length(nodepath->selected) != 2) {
- nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
- return;
- }
-
- Inkscape::NodePath::Node *a = (Inkscape::NodePath::Node *) nodepath->selected->data;
- Inkscape::NodePath::Node *b = (Inkscape::NodePath::Node *) nodepath->selected->next->data;
-
- g_assert(a != b);
- if (!(a->p.other || a->n.other) || !(b->p.other || b->n.other)) {
- // 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;
- }
-
if (a->subpath == b->subpath) {
Inkscape::NodePath::SubPath *sp = a->subpath;
}
/* a and b are separate subpaths */
- Inkscape::NodePath::SubPath *sa = a->subpath;
- Inkscape::NodePath::SubPath *sb = b->subpath;
+ Inkscape::NodePath::SubPath *sa = a->subpath;
+ Inkscape::NodePath::SubPath *sb = b->subpath;
- Inkscape::NodePath::Node *n;
+ Inkscape::NodePath::Node *n;
NR::Point p;
NRPathcode code;
if (a == sa->first) {
sp_nodepath_update_repr(nodepath, _("Join nodes by segment"));
}
+enum NodeJoinType { NODE_JOIN_ENDPOINTS, NODE_JOIN_SEGMENT };
+
+/**
+ * Internal function to handle joining two nodes.
+ */
+static void node_do_selected_join(Inkscape::NodePath::Path *nodepath, NodeJoinType mode)
+{
+ if (!nodepath) return; // there's no nodepath when editing rects, stars, spirals or ellipses
+
+ if (g_list_length(nodepath->selected) != 2) {
+ nodepath->desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("To join, you must have <b>two endnodes</b> selected."));
+ return;
+ }
+
+ Inkscape::NodePath::Node *a = (Inkscape::NodePath::Node *) nodepath->selected->data;
+ Inkscape::NodePath::Node *b = (Inkscape::NodePath::Node *) nodepath->selected->next->data;
+
+ g_assert(a != b);
+ if (!(a->p.other || a->n.other) || !(b->p.other || b->n.other)) {
+ // 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:
+ do_node_selected_join_segment(nodepath, a, b);
+ break;
+ }
+}
+
+/**
+ * Join two nodes by merging them into one.
+ */
+void sp_node_selected_join(Inkscape::NodePath::Path *nodepath)
+{
+ node_do_selected_join(nodepath, NODE_JOIN_ENDPOINTS);
+}
+
+/**
+ * Join two nodes by adding a segment between them.
+ */
+void sp_node_selected_join_segment(Inkscape::NodePath::Path *nodepath)
+{
+ node_do_selected_join(nodepath, NODE_JOIN_SEGMENT);
+}
+
/**
* Delete one or more selected nodes and preserve the shape of the path as much as possible.
*/