summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Brock <zaibu@lunar-orbit.de>2016-11-09 00:23:41 +0000
committerAlexander Brock <zaibu@lunar-orbit.de>2016-11-09 00:23:41 +0000
commit07a86951a15301ccb7eb1446cc1e6d3ca7a68f9b (patch)
tree6aa49c38e2bf4ee709737d0b9b019587f8d6bb52 /src
parentannotate custom builds, and add correct revno into make dist tarballs (diff)
downloadinkscape-07a86951a15301ccb7eb1446cc1e6d3ca7a68f9b.tar.gz
inkscape-07a86951a15301ccb7eb1446cc1e6d3ca7a68f9b.zip
Move boolop functions from sp_selected_path_<op> to ObjectSet::path<op>
(bzr r15223.1.1)
Diffstat (limited to 'src')
-rw-r--r--src/livarot/LivarotDefs.h12
-rw-r--r--src/livarot/Shape.h1
-rw-r--r--src/livarot/int-line.h1
-rw-r--r--src/object-set.h37
-rw-r--r--src/splivarot.cpp163
-rw-r--r--src/splivarot.h21
-rw-r--r--src/ui/tools/calligraphic-tool.cpp4
-rw-r--r--src/ui/tools/eraser-tool.cpp12
-rw-r--r--src/ui/tools/flood-tool.cpp2
-rw-r--r--src/ui/tools/spray-tool.cpp4
-rw-r--r--src/verbs.cpp12
11 files changed, 113 insertions, 156 deletions
diff --git a/src/livarot/LivarotDefs.h b/src/livarot/LivarotDefs.h
index abeff3861..d020841b0 100644
--- a/src/livarot/LivarotDefs.h
+++ b/src/livarot/LivarotDefs.h
@@ -40,18 +40,6 @@ enum
found_between = 4
};
-// boolean operation
-enum bool_op
-{
- bool_op_union, // A OR B
- bool_op_inters, // A AND B
- bool_op_diff, // A \ B
- bool_op_symdiff, // A XOR B
- bool_op_cut, // coupure (pleines)
- bool_op_slice // coupure (contour)
-};
-typedef enum bool_op BooleanOp;
-
// types of cap for stroking polylines
enum butt_typ
{
diff --git a/src/livarot/Shape.h b/src/livarot/Shape.h
index 98fc2d7bf..da1edc6b3 100644
--- a/src/livarot/Shape.h
+++ b/src/livarot/Shape.h
@@ -17,6 +17,7 @@
#include <2geom/point.h>
#include "livarot/LivarotDefs.h"
+#include "object-set.h"
class Path;
class FloatLigne;
diff --git a/src/livarot/int-line.h b/src/livarot/int-line.h
index 1d3bbd9d2..ed3ccfb96 100644
--- a/src/livarot/int-line.h
+++ b/src/livarot/int-line.h
@@ -2,6 +2,7 @@
#define INKSCAPE_LIVAROT_INT_LINE_H
#include "livarot/LivarotDefs.h"
+#include "object-set.h"
/** \file
* Coverage with integer boundaries.
diff --git a/src/object-set.h b/src/object-set.h
index 12f2cb101..a89a299bd 100644
--- a/src/object-set.h
+++ b/src/object-set.h
@@ -33,6 +33,29 @@
#include "sp-item-group.h"
#include "desktop.h"
#include "document.h"
+#include "verbs.h"
+
+enum BoolOpErrors {
+ DONE,
+ DONE_NO_PATH,
+ DONE_NO_ACTION,
+ ERR_TOO_LESS_PATHS_1,
+ ERR_TOO_LESS_PATHS_2,
+ ERR_NO_PATHS,
+ ERR_Z_ORDER
+};
+
+// boolean operation
+enum bool_op
+{
+ bool_op_union, // A OR B
+ bool_op_inters, // A AND B
+ bool_op_diff, // A \ B
+ bool_op_symdiff, // A XOR B
+ bool_op_cut, // coupure (pleines)
+ bool_op_slice // coupure (contour)
+};
+typedef enum bool_op BooleanOp;
class SPBox3D;
class Persp3D;
@@ -376,7 +399,16 @@ public:
void toCurves(bool skip_undo = false);
void toLPEItems();
void pathReverse();
-
+
+ // Boolean operations
+ // in splivarot.cpp
+ bool pathUnion(const bool skip_undo = false);
+ bool pathIntersect(const bool skip_undo = false);
+ bool pathDiff(const bool skip_undo = false);
+ bool pathSymDiff(const bool skip_undo = false);
+ bool pathCut(const bool skip_undo = false);
+ bool pathSlice(const bool skip_undo = false);
+
//Other path operations
//in selection-chemistry.cpp
void toMarker(bool apply = true);
@@ -438,6 +470,9 @@ protected:
std::list<SPBox3D *> _3dboxes;
std::unordered_map<SPObject*, sigc::connection> _releaseConnections;
+private:
+ BoolOpErrors pathBoolOp(bool_op bop, const bool skip_undo, const unsigned int verb = SP_VERB_NONE, const Glib::ustring description = "");
+
};
typedef ObjectSet::SPItemRange SPItemRange;
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 6b9fd5f83..531a48e44 100644
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -47,96 +47,51 @@
#include "verbs.h"
#include "2geom/svg-path-parser.h" // to get from SVG on boolean to Geom::Path
-enum BoolOpErrors {
- DONE,
- DONE_NO_PATH,
- DONE_NO_ACTION,
- ERR_TOO_LESS_PATHS_1,
- ERR_TOO_LESS_PATHS_2,
- ERR_NO_PATHS,
- ERR_Z_ORDER
-};
-
using Inkscape::DocumentUndo;
bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who);
-void sp_selected_path_boolop_ui(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop,
- const unsigned int verb = SP_VERB_NONE, const Glib::ustring description = "");
-BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet *set, bool_op bop);
void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset);
void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating);
-void
-sp_selected_path_union(Inkscape::Selection *selection, SPDesktop *desktop)
-{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_union, SP_VERB_SELECTION_UNION, _("Union"));
-}
-
-void
-sp_selected_path_union_skip_undo(Inkscape::ObjectSet *set)
-{
- sp_selected_path_boolop(set, bool_op_union);
-}
-
-void
-sp_selected_path_intersect(Inkscape::Selection *selection, SPDesktop *desktop)
-{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_inters, SP_VERB_SELECTION_INTERSECT, _("Intersection"));
-}
-
-void
-sp_selected_path_intersect_skip_undo(Inkscape::ObjectSet *set)
-{
- sp_selected_path_boolop(set, bool_op_inters);
-}
-
-void
-sp_selected_path_diff(Inkscape::Selection *selection, SPDesktop *desktop)
-{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_diff, SP_VERB_SELECTION_DIFF, _("Difference"));
-}
-
-void
-sp_selected_path_diff_skip_undo(Inkscape::ObjectSet *set)
-{
- sp_selected_path_boolop(set, bool_op_diff);
+bool Inkscape::ObjectSet::pathUnion(const bool skip_undo) {
+ BoolOpErrors result = pathBoolOp(bool_op_union, skip_undo, SP_VERB_SELECTION_UNION, _("Union"));
+ return DONE == result;
}
-void
-sp_selected_path_symdiff(Inkscape::Selection *selection, SPDesktop *desktop)
-{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_symdiff, SP_VERB_SELECTION_SYMDIFF, _("Exclusion"));
-}
-
-void
-sp_selected_path_symdiff_skip_undo(Inkscape::ObjectSet *set)
+bool
+Inkscape::ObjectSet::pathIntersect(const bool skip_undo)
{
- sp_selected_path_boolop(set, bool_op_symdiff);
+ BoolOpErrors result = pathBoolOp(bool_op_inters, skip_undo, SP_VERB_SELECTION_INTERSECT, _("Intersection"));
+ return DONE == result;
}
-void
-sp_selected_path_cut(Inkscape::Selection *selection, SPDesktop *desktop)
+bool
+Inkscape::ObjectSet::pathDiff(const bool skip_undo)
{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_cut, SP_VERB_SELECTION_CUT, _("Division"));
+ BoolOpErrors result = pathBoolOp(bool_op_diff, skip_undo, SP_VERB_SELECTION_DIFF, _("Difference"));
+ return DONE == result;
}
-void
-sp_selected_path_cut_skip_undo(Inkscape::ObjectSet *set)
+bool
+Inkscape::ObjectSet::pathSymDiff(const bool skip_undo)
{
- sp_selected_path_boolop(set, bool_op_cut);
+ BoolOpErrors result = pathBoolOp(bool_op_symdiff, skip_undo, SP_VERB_SELECTION_SYMDIFF, _("Exclusion"));
+ return DONE == result;
}
-void
-sp_selected_path_slice(Inkscape::Selection *selection, SPDesktop *desktop)
+bool
+Inkscape::ObjectSet::pathCut(const bool skip_undo)
{
- sp_selected_path_boolop_ui(selection, desktop, bool_op_slice, SP_VERB_SELECTION_SLICE, _("Cut path"));
+ BoolOpErrors result = pathBoolOp(bool_op_cut, skip_undo, SP_VERB_SELECTION_CUT, _("Division"));
+ return DONE == result;
}
-void
-sp_selected_path_slice_skip_undo(Inkscape::ObjectSet *set)
+bool
+Inkscape::ObjectSet::pathSlice(const bool skip_undo)
{
- sp_selected_path_boolop(set, bool_op_slice);
+ BoolOpErrors result = pathBoolOp(bool_op_slice, skip_undo, SP_VERB_SELECTION_SLICE, _("Cut path"));
+ return DONE == result;
}
// helper for printing error messages, regardless of whether we have a GUI or not
@@ -352,10 +307,36 @@ Geom::PathVector pathliv_to_pathvector(Path *pathliv){
// boolean operations on the desktop
// take the source paths from the file, do the operation, delete the originals and add the results
-BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
+BoolOpErrors Inkscape::ObjectSet::pathBoolOp(bool_op bop, const bool skip_undo, const unsigned int verb, const Glib::ustring description)
{
- SPDocument *doc = set->desktop()->getDocument();
- std::vector<SPItem*> il(set->items().begin(), set->items().end());
+ if (nullptr != desktop() && !skip_undo) {
+ SPDocument *doc = desktop()->getDocument();
+ BoolOpErrors returnCode = ObjectSet::pathBoolOp(bop, true);
+ switch(returnCode) {
+ case ERR_TOO_LESS_PATHS_1:
+ boolop_display_error_message(desktop(), _("Select <b>at least 1 path</b> to perform a boolean union."));
+ break;
+ case ERR_TOO_LESS_PATHS_2:
+ boolop_display_error_message(desktop(), _("Select <b>at least 2 paths</b> to perform a boolean operation."));
+ break;
+ case ERR_NO_PATHS:
+ boolop_display_error_message(desktop(), _("One of the objects is <b>not a path</b>, cannot perform boolean operation."));
+ break;
+ case ERR_Z_ORDER:
+ boolop_display_error_message(desktop(), _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
+ break;
+ case DONE_NO_PATH:
+ DocumentUndo::done(doc, SP_VERB_NONE, description);
+ break;
+ case DONE:
+ DocumentUndo::done(doc, verb, description);
+ break;
+ }
+ return returnCode;
+ }
+
+ SPDocument *doc = document();
+ std::vector<SPItem*> il(items().begin(), items().end());
// allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334)
if (il.size() < 2 && bop != bool_op_union) {
@@ -687,7 +668,7 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
(*l)->deleteObject();
}
- set->clear();
+ clear();
delete res;
return DONE_NO_PATH;
@@ -703,7 +684,7 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
}
} else {
// find out the bottom object
- std::vector<Inkscape::XML::Node*> sorted(set->xmlNodes().begin(), set->xmlNodes().end());
+ std::vector<Inkscape::XML::Node*> sorted(xmlNodes().begin(), xmlNodes().end());
sort(sorted.begin(),sorted.end(),sp_repr_compare_position_bool);
@@ -731,7 +712,7 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
gchar *title = source->title();
gchar *desc = source->desc();
// remove source paths
- set->clear();
+ clear();
for (std::vector<SPItem*>::const_iterator l = il.begin(); l != il.end(); l++){
// if this is the bottommost object,
if (!strcmp(reinterpret_cast<SPObject *>(*l)->getRepr()->attribute("id"), id)) {
@@ -810,7 +791,7 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
// move to the saved position
repr->setPosition(pos > 0 ? pos : 0);
- set->add(doc->getObjectByRepr(repr));
+ add(doc->getObjectByRepr(repr));
Inkscape::GC::release(repr);
delete resPath[i];
@@ -845,7 +826,7 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
}
repr->setPosition(pos > 0 ? pos : 0);
- set->add(doc->getObjectByRepr(repr));
+ add(doc->getObjectByRepr(repr));
Inkscape::GC::release(repr);
}
@@ -858,36 +839,6 @@ BoolOpErrors sp_selected_path_boolop(Inkscape::ObjectSet * set, bool_op bop)
return DONE;
}
-void sp_selected_path_boolop_ui(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb,
- const Glib::ustring description)
-{
- SPDocument *doc = selection->desktop()->getDocument();
- BoolOpErrors returnCode = sp_selected_path_boolop(selection, bop);
- switch(returnCode) {
- case ERR_TOO_LESS_PATHS_1:
- boolop_display_error_message(desktop, _("Select <b>at least 1 path</b> to perform a boolean union."));
- return;
- case ERR_TOO_LESS_PATHS_2:
- boolop_display_error_message(desktop, _("Select <b>at least 2 paths</b> to perform a boolean operation."));
- return;
- case ERR_NO_PATHS:
- boolop_display_error_message(desktop, _("One of the objects is <b>not a path</b>, cannot perform boolean operation."));
- return;
- case ERR_Z_ORDER:
- boolop_display_error_message(desktop, _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
- return;
- case DONE_NO_PATH:
- DocumentUndo::done(doc, SP_VERB_NONE, description);
- return;
- case DONE:
- DocumentUndo::done(doc, verb, description);
- return;
- case DONE_NO_ACTION:
- default:
- return;
- }
-}
-
static
void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Affine marker_transform,
Geom::Scale stroke_scale, Geom::Affine transform,
diff --git a/src/splivarot.h b/src/splivarot.h
index 6adc05946..17dd4f66b 100644
--- a/src/splivarot.h
+++ b/src/splivarot.h
@@ -10,6 +10,7 @@
#include <2geom/forward.h>
#include <2geom/path.h>
#include "livarot/Path.h"
+#include "object-set.h"
class SPCurve;
class SPDesktop;
@@ -20,26 +21,6 @@ namespace Inkscape {
class ObjectSet;
}
-// boolean operations
-// work on the current selection
-// selection has 2 contain exactly 2 items
-
-// UPDATE: these signatures have been modified so they may work in
-// command-line mode, i.e. without a desktop. If a desktop is not
-// provided (desktop == NULL), error messages will be shown on stderr.
-void sp_selected_path_union (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_union_skip_undo (Inkscape::ObjectSet *set);
-void sp_selected_path_intersect (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_intersect_skip_undo (Inkscape::ObjectSet *set);
-void sp_selected_path_diff (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_diff_skip_undo (Inkscape::ObjectSet *set);
-void sp_selected_path_symdiff (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_symdiff_skip_undo (Inkscape::ObjectSet *set);
-void sp_selected_path_cut (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_cut_skip_undo (Inkscape::ObjectSet *set);
-void sp_selected_path_slice (Inkscape::Selection *selection, SPDesktop *desktop);
-void sp_selected_path_slice_skip_undo (Inkscape::ObjectSet *set);
-
// offset/inset of a curve
// takes the fill-rule in consideration
// offset amount is the stroke-width of the curve
diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp
index 9b4dbb1a2..c2b86b538 100644
--- a/src/ui/tools/calligraphic-tool.cpp
+++ b/src/ui/tools/calligraphic-tool.cpp
@@ -921,10 +921,10 @@ void CalligraphicTool::set_to_accumulated(bool unionize, bool subtract) {
if (unionize) {
desktop->getSelection()->add(this->repr);
- sp_selected_path_union_skip_undo(desktop->getSelection());
+ desktop->getSelection()->pathUnion(true);
} else if (subtract) {
desktop->getSelection()->add(this->repr);
- sp_selected_path_diff_skip_undo(desktop->getSelection());
+ desktop->getSelection()->pathDiff(true);
} else {
if (this->keep_selected) {
desktop->getSelection()->set(this->repr);
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index 4f941e534..ae312e054 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -714,7 +714,7 @@ void EraserTool::set_to_accumulated() {
Inkscape::GC::release(dup); // parent takes over
selection->set(dup);
if (!this->nowidth) {
- sp_selected_path_union_skip_undo(selection);
+ selection->pathUnion(true);
}
selection->add(item);
if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){
@@ -725,9 +725,9 @@ void EraserTool::set_to_accumulated() {
css = 0;
}
if (this->nowidth) {
- sp_selected_path_cut_skip_undo(selection);
+ selection->pathCut(true);
} else {
- sp_selected_path_diff_skip_undo(selection);
+ selection->pathDiff(true);
}
workDone = true; // TODO set this only if something was cut.
bool break_apart = prefs->getBool("/tools/eraser/break_apart", false);
@@ -762,7 +762,7 @@ void EraserTool::set_to_accumulated() {
this->repr->parent()->appendChild(dup);
Inkscape::GC::release(dup); // parent takes over
selection->set(dup);
- sp_selected_path_union_skip_undo(selection);
+ selection->pathUnion(true);
if (bbox && bbox->intersects(*eraserBbox)) {
SPClipPath *clip_path = item->clip_ref->getObject();
if (clip_path) {
@@ -786,7 +786,7 @@ void EraserTool::set_to_accumulated() {
sp_object_unref(clip_path);
selection->raiseToTop(true);
selection->add(dup_clip);
- sp_selected_path_diff_skip_undo(selection);
+ selection->pathDiff(true);
SPItem * clip = SP_ITEM(*(selection->items().begin()));
}
}
@@ -802,7 +802,7 @@ void EraserTool::set_to_accumulated() {
rect->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
selection->raiseToTop(true);
selection->add(rect);
- sp_selected_path_diff_skip_undo(selection);
+ selection->pathDiff(true);
}
selection->raiseToTop(true);
selection->add(item);
diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp
index 0b893a7ba..b01b8ad52 100644
--- a/src/ui/tools/flood-tool.cpp
+++ b/src/ui/tools/flood-tool.cpp
@@ -446,7 +446,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto
ngettext("Area filled, path with <b>%d</b> node created and unioned with selection.","Area filled, path with <b>%d</b> nodes created and unioned with selection.",
SP_PATH(reprobj)->nodesInPath()), SP_PATH(reprobj)->nodesInPath() );
selection->add(reprobj);
- sp_selected_path_union_skip_undo(desktop->getSelection());
+ selection->pathUnion(true);
} else {
desktop->messageStack()->flashF( Inkscape::WARNING_MESSAGE,
ngettext("Area filled, path with <b>%d</b> node created.","Area filled, path with <b>%d</b> nodes created.",
diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp
index 3649008ff..ad006627c 100644
--- a/src/ui/tools/spray-tool.cpp
+++ b/src/ui/tools/spray-tool.cpp
@@ -1026,7 +1026,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
if (unionResult) { // No need to add the very first item (initialized with NULL).
set->add(unionResult);
}
- sp_selected_path_union_skip_undo(set);
+ set->pathUnion(true);
set->add(parent_item);
Inkscape::GC::release(copy);
did = true;
@@ -1364,7 +1364,7 @@ bool SprayTool::root_handler(GdkEvent* event) {
SP_VERB_CONTEXT_SPRAY, _("Spray with clones"));
break;
case SPRAY_MODE_SINGLE_PATH:
- sp_selected_path_union_skip_undo(objectSet());
+ objectSet()->pathUnion(true);
desktop->getSelection()->add(object_set.objects().begin(), object_set.objects().end());
DocumentUndo::done(this->desktop->getDocument(),
SP_VERB_CONTEXT_SPRAY, _("Spray in single path"));
diff --git a/src/verbs.cpp b/src/verbs.cpp
index a5426f324..32aee4161 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -1115,22 +1115,22 @@ void SelectionVerb::perform(SPAction *action, void *data)
bool handled = true;
switch (reinterpret_cast<std::size_t>(data)) {
case SP_VERB_SELECTION_UNION:
- sp_selected_path_union(selection, dt);
+ selection->pathUnion();
break;
case SP_VERB_SELECTION_INTERSECT:
- sp_selected_path_intersect(selection, dt);
+ selection->pathIntersect();
break;
case SP_VERB_SELECTION_DIFF:
- sp_selected_path_diff(selection, dt);
+ selection->pathDiff();
break;
case SP_VERB_SELECTION_SYMDIFF:
- sp_selected_path_symdiff(selection, dt);
+ selection->pathSymDiff();
break;
case SP_VERB_SELECTION_CUT:
- sp_selected_path_cut(selection, dt);
+ selection->pathCut();
break;
case SP_VERB_SELECTION_SLICE:
- sp_selected_path_slice(selection, dt);
+ selection->pathSlice();
break;
case SP_VERB_SELECTION_GROW:
{