Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
eraser-tool.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_UI_TOOLS_ERASER_TOOL_H
3#define INKSCAPE_UI_TOOLS_ERASER_TOOL_H
4
5/*
6 * Handwriting-like drawing mode
7 *
8 * Authors:
9 * Mitsuru Oka <oka326@parkcity.ne.jp>
10 * Lauris Kaplinski <lauris@kaplinski.com>
11 *
12 * The original dynadraw code:
13 * Paul Haeberli <paul@sgi.com>
14 *
15 * Copyright (C) 1998 The Free Software Foundation
16 * Copyright (C) 1999-2002 authors
17 * Copyright (C) 2001-2002 Ximian, Inc.
18 * Copyright (C) 2008 Jon A. Cruz
19 *
20 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
21 */
22
23#include "message.h"
24#include "style-enums.h"
26#include "object/sp-use.h"
27
28namespace Inkscape {
29struct KeyPressEvent;
30struct ExtendedInput;
31} // namespace Inkscape
32
33namespace Inkscape::UI::Tools {
34
36{
37 DELETE,
38 CUT,
39 CLIP
40};
41static inline constexpr auto DEFAULT_ERASER_MODE = EraserToolMode::CUT;
42
45{
46 SPItem *item = nullptr;
47 bool was_selected = false;
48
49 EraseTarget(SPItem *ptr, bool sel)
50 : item{ptr}
51 , was_selected{sel}
52 {}
53 inline bool operator==(EraseTarget const &other) const noexcept { return item == other.item; }
54};
55
56class EraserTool : public DynamicBase
57{
58private:
59 // non-static data:
61 bool nowidth = false;
62 std::vector<MessageId> _our_messages;
63 SPItem *_acid = nullptr;
64 std::vector<SPItem *> _survivers;
67
68 // static data:
69 static constexpr uint32_t trace_color_rgba = 0xff0000ff; // RGBA red
71
72 static constexpr double tolerance = 0.1;
73
74 static constexpr double epsilon = 0.5e-6;
75 static constexpr double epsilon_start = 0.5e-2;
76 static constexpr double vel_start = 1e-5;
77
78 static constexpr double drag_default = 1.0;
79 static constexpr double drag_min = 0.0;
80 static constexpr double drag_max = 1.0;
81
82 static constexpr double min_pressure = 0.0;
83 static constexpr double max_pressure = 1.0;
84 static constexpr double default_pressure = 1.0;
85
86 static constexpr double min_tilt = -1.0;
87 static constexpr double max_tilt = 1.0;
88 static constexpr double default_tilt = 0.0;
89
90public:
91 // public member functions
93 ~EraserTool() override;
94 bool root_handler(CanvasEvent const &event) final;
95
96 using Error = std::uint64_t;
97 static constexpr Error ALL_GOOD = 0x0;
98 static constexpr Error NON_EXISTENT = 0x1 << 1;
99 static constexpr Error NO_AREA_PATH = 0x1 << 2;
100 static constexpr Error RASTER_IMAGE = 0x1 << 3;
101 static constexpr Error ERROR_GROUP = 0x1 << 4;
102
103private:
104 // private member functions
105 void _accumulate();
106 bool _apply(Geom::Point const &p);
107 bool _booleanErase(EraseTarget target, bool store_survivers);
108 void _brush();
109 void _cancel();
110 void _clearCurrent();
111 void _clearStatusBar();
112 void _clipErase(SPItem *item) const;
113 void _completeBezier(double tolerance_sq, bool releasing);
114 bool _cutErase(EraseTarget target, bool store_survivers);
115 bool _doWork();
116 void _drawTemporaryBox();
117 void _extinput(ExtendedInput const &ext);
119 std::vector<EraseTarget> _filterByCollision(std::vector<EraseTarget> const &items, SPItem *with) const;
120 std::vector<EraseTarget> _filterCutEraseables(std::vector<EraseTarget> const &items, bool silent = false);
121 std::vector<EraseTarget> _findItemsToErase();
122 void _fitAndSplit(bool releasing);
123 void _fitDrawLastPoint();
124 bool _handleKeypress(KeyPressEvent const &key);
125 void _handleStrokeStyle(SPItem *item) const;
127 bool _performEraseOperation(std::vector<EraseTarget> const &items_to_erase, bool store_survivers);
128 void _reset(Geom::Point p);
129 void _setStatusBarMessage(char *message);
130 void _updateMode();
131
132 static void _generateNormalDist2(double &r1, double &r2);
133 static void _addCap(Geom::Path &curve, Geom::Point const &pre, Geom::Point const &from, Geom::Point const &to,
134 Geom::Point const &post, double rounding);
135 static bool _isStraightSegment(SPItem *path);
137 bool _probeUnlinkCutClonedGroup(EraseTarget &original_target, SPUse* clone, SPGroup* cloned_group,
138 bool store_survivers = true);
139};
140
141} // namespace Inkscape::UI::Tools
142
143#endif // INKSCAPE_UI_TOOLS_ERASER_TOOL_H
144
145/*
146 Local Variables:
147 mode:c++
148 c-file-style:"stroustrup"
149 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150 indent-tabs-mode:nil
151 fill-column:99
152 End:
153*/
154// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Sequence of contiguous curves, aka spline.
Definition path.h:353
Two-dimensional point that doubles as a vector.
Definition point.h:66
static constexpr double epsilon
Definition eraser-tool.h:74
bool _doWork()
Performs the actual erase operation against the current document.
void _clipErase(SPItem *item) const
Clips through an item.
bool root_handler(CanvasEvent const &event) final
static Error _uncuttableItemType(SPItem *item)
Returns error flags for items that cannot be meaningfully erased in CUT mode.
bool _handleKeypress(KeyPressEvent const &key)
Analyses and handles a key press event, returns true if processed, false if not.
void _handleStrokeStyle(SPItem *item) const
Handles the "evenodd" stroke style.
SPItem * _insertAcidIntoDocument(SPDocument *document)
Inserts the temporary red shape of the eraser stroke (the "acid") into the document.
static constexpr double default_pressure
Definition eraser-tool.h:84
static constexpr double tolerance
Definition eraser-tool.h:72
static constexpr double max_tilt
Definition eraser-tool.h:87
bool _apply(Geom::Point const &p)
static constexpr double max_pressure
Definition eraser-tool.h:83
static constexpr double drag_max
Definition eraser-tool.h:80
static constexpr Error NO_AREA_PATH
Definition eraser-tool.h:99
static bool _isStraightSegment(SPItem *path)
Detects whether the given path is a straight line segment which encloses no area or consists of sever...
static constexpr Error ERROR_GROUP
void _fitAndSplit(bool releasing)
static constexpr Error NON_EXISTENT
Definition eraser-tool.h:98
static constexpr double default_tilt
Definition eraser-tool.h:88
static constexpr double drag_min
Definition eraser-tool.h:79
static constexpr uint32_t trace_color_rgba
Definition eraser-tool.h:69
std::vector< EraseTarget > _filterByCollision(std::vector< EraseTarget > const &items, SPItem *with) const
Filters a list of potential erase targets by collision with a given item.
bool _cutErase(EraseTarget target, bool store_survivers)
Erases from a shape by cutting (boolean difference or cut operation).
static constexpr SPWindRule trace_wind_rule
Definition eraser-tool.h:70
static constexpr double min_pressure
Definition eraser-tool.h:82
static void _generateNormalDist2(double &r1, double &r2)
static constexpr double min_tilt
Definition eraser-tool.h:86
std::vector< MessageId > _our_messages
Definition eraser-tool.h:62
void _updateMode()
Reads the current Eraser mode from Preferences and sets mode accordingly.
std::vector< SPItem * > _survivers
Definition eraser-tool.h:64
static constexpr double drag_default
Definition eraser-tool.h:78
void _extinput(ExtendedInput const &ext)
void _clearStatusBar()
Clears all of messages sent by us to the status bar.
static constexpr Error RASTER_IMAGE
static constexpr double epsilon_start
Definition eraser-tool.h:75
bool _performEraseOperation(std::vector< EraseTarget > const &items_to_erase, bool store_survivers)
Performs the actual erasing on a collection of erase targets.
static constexpr Error ALL_GOOD
Definition eraser-tool.h:97
std::vector< EraseTarget > _findItemsToErase()
Prepares a list of items in the current document containing the items which qualify for the erase ope...
static void _addCap(Geom::Path &curve, Geom::Point const &pre, Geom::Point const &from, Geom::Point const &to, Geom::Point const &post, double rounding)
bool _probeUnlinkCutClonedGroup(EraseTarget &original_target, SPUse *clone, SPGroup *cloned_group, bool store_survivers=true)
Analyses a cloned group and decides if the CUT mode should unlink the clone.
static constexpr double vel_start
Definition eraser-tool.h:76
void _completeBezier(double tolerance_sq, bool releasing)
std::vector< EraseTarget > _filterCutEraseables(std::vector< EraseTarget > const &items, bool silent=false)
Filters out elements that can be erased in CUT mode (by boolean operations) from the given vector of ...
bool _booleanErase(EraseTarget target, bool store_survivers)
Performs a boolean difference or cut operation which implements the CUT mode erasure.
void _setStatusBarMessage(char *message)
Sets an error message in the status bar.
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
Base class for visual SVG elements.
Definition sp-item.h:109
Definition sp-use.h:25
SPItem * item
static constexpr auto DEFAULT_ERASER_MODE
Definition eraser-tool.h:41
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
GList * items
Abstract base class for events.
Extended input data associated to events generated by graphics tablets.
A key has been pressed.
Proxy object providing a "live value" interface.
Represents an item to erase.
Definition eraser-tool.h:45
bool operator==(EraseTarget const &other) const noexcept
Definition eraser-tool.h:53
bool was_selected
Whether the item was part of selection.
Definition eraser-tool.h:47
EraseTarget(SPItem *ptr, bool sel)
Definition eraser-tool.h:49
SPItem * item
Pointer to the item to be erased.
Definition eraser-tool.h:46
Definition curve.h:24
SPStyle enums: named public enums that correspond to SVG property values.
SPWindRule
Definition style-enums.h:23
@ SP_WIND_RULE_EVENODD
Definition style-enums.h:26
SPDesktop * desktop