diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp
index 1920baed5be3bd11dbca846afb3548d2039e51a4..559ce28667e7ba224aaf630fd69d367caa3b74ae 100644 (file)
--- a/src/eraser-context.cpp
+++ b/src/eraser-context.cpp
#include "message-context.h"
#include "prefs-utils.h"
#include "pixmaps/cursor-eraser.xpm"
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-path.h"
-#include "libnr/nr-matrix-ops.h"
-#include "libnr/nr-scale-translate-ops.h"
#include "xml/repr.h"
#include "context-fns.h"
#include "sp-item.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "livarot/Shape.h"
-#include "isnan.h"
+#include <2geom/isnan.h>
+#include <2geom/pathvector.h>
#include "eraser-context.h"
if (((SPEventContextClass *) eraser_parent_class)->setup)
((SPEventContextClass *) eraser_parent_class)->setup(ec);
- erc->accumulated = new SPCurve(32);
- erc->currentcurve = new SPCurve(4);
+ erc->accumulated = new SPCurve();
+ erc->currentcurve = new SPCurve();
- erc->cal1 = new SPCurve(32);
- erc->cal2 = new SPCurve(32);
+ erc->cal1 = new SPCurve();
+ erc->cal2 = new SPCurve();
erc->currentshape = sp_canvas_item_new(sp_desktop_sketch(ec->desktop), SP_TYPE_CANVAS_BPATH, NULL);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(erc->currentshape), ERC_RED_RGBA, SP_WIND_RULE_EVENODD);
static void
sp_eraser_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
{
- SPEraserContext *erc = SP_ERASER_CONTEXT(ec);
-
- if (!strcmp(key, "mass")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.2 );
- erc->mass = CLAMP(dval, -1000.0, 1000.0);
- } else if (!strcmp(key, "wiggle")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : (1 - DRAG_DEFAULT));
- erc->drag = CLAMP((1 - dval), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle
- } else if (!strcmp(key, "angle")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0);
- erc->angle = CLAMP (dval, -90, 90);
- } else if (!strcmp(key, "width")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 );
- erc->width = CLAMP(dval, -1000.0, 1000.0);
- } else if (!strcmp(key, "thinning")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 );
- erc->vel_thin = CLAMP(dval, -1.0, 1.0);
- } else if (!strcmp(key, "tremor")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0 );
- erc->tremor = CLAMP(dval, 0.0, 1.0);
- } else if (!strcmp(key, "flatness")) {
- double const dval = ( val ? g_ascii_strtod (val, NULL) : 1.0 );
- erc->flatness = CLAMP(dval, 0, 1.0);
- } else if (!strcmp(key, "usepressure")) {
- erc->usepressure = (val && strcmp(val, "0"));
- } else if (!strcmp(key, "usetilt")) {
- erc->usetilt = (val && strcmp(val, "0"));
- } else if (!strcmp(key, "abs_width")) {
- erc->abs_width = (val && strcmp(val, "0"));
- } else if (!strcmp(key, "cap_rounding")) {
- erc->cap_rounding = ( val ? g_ascii_strtod (val, NULL) : 0.0 );
+ //pass on up to parent class to handle common attributes.
+ if ( eraser_parent_class->set ) {
+ eraser_parent_class->set(ec, key, val);
}
-
- //g_print("ERC: %g %g %g %g\n", erc->mass, erc->drag, erc->angle, erc->width);
}
static double
if (dc->dragging && event->button.button == 1 && !event_context->space_panning) {
dc->dragging = FALSE;
- NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
+ boost::optional<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
sp_eraser_apply(dc, motion_dt);
bool workDone = false;
if (!dc->accumulated->is_empty()) {
- NArtBpath *abp;
- gchar *str;
-
if (!dc->repr) {
/* Create object */
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
item->updateRepr();
}
- abp = nr_artpath_affine(dc->accumulated->first_bpath(), sp_desktop_dt2root_affine(desktop));
- str = sp_svg_write_path(abp);
+ Geom::PathVector pathv = dc->accumulated->get_pathvector() * sp_desktop_dt2root_affine(desktop);
+ gchar *str = sp_svg_write_path(pathv);
g_assert( str != NULL );
- g_free(abp);
dc->repr->setAttribute("d", str);
g_free(str);
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(dc->repr));
- NR::Maybe<NR::Rect> eraserBbox = acid->getBounds(NR::identity());
+ boost::optional<NR::Rect> eraserBbox = acid->getBounds(NR::identity());
NR::Rect bounds = (*eraserBbox) * desktop->doc2dt();
std::vector<SPItem*> remainingItems;
GSList* toWorkOn = 0;
for (GSList *i = toWorkOn ; i ; i = i->next ) {
SPItem *item = SP_ITEM(i->data);
if ( eraserMode ) {
- NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity());
+ boost::optional<NR::Rect> bbox = item->getBounds(NR::identity());
if (bbox && bbox->intersects(*eraserBbox)) {
Inkscape::XML::Node* dup = dc->repr->duplicate(xml_doc);
dc->repr->parent()->appendChild(dup);
dc->accumulated->reset(); /* Is this required ?? */
SPCurve *rev_cal2 = dc->cal2->create_reverse();
- g_assert(dc->cal1->_end > 1);
- g_assert(rev_cal2->_end > 1);
- g_assert(SP_CURVE_SEGMENT(dc->cal1, 0)->code == NR_MOVETO_OPEN);
- g_assert(SP_CURVE_SEGMENT(rev_cal2, 0)->code == NR_MOVETO_OPEN);
- g_assert(SP_CURVE_SEGMENT(dc->cal1, 1)->code == NR_CURVETO);
- g_assert(SP_CURVE_SEGMENT(rev_cal2, 1)->code == NR_CURVETO);
- g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->code == NR_CURVETO);
- g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->code == NR_CURVETO);
+ g_assert(dc->cal1->get_segment_count() > 0);
+ g_assert(rev_cal2->get_segment_count() > 0);
+ g_assert( ! dc->cal1->first_path()->closed() );
+ g_assert( ! rev_cal2->first_path()->closed() );
+
+ Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->first_segment() );
+ Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() );
+ Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->last_segment() );
+ Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() );
+ g_assert( dc_cal1_firstseg );
+ g_assert( rev_cal2_firstseg );
+ g_assert( dc_cal1_lastseg );
+ g_assert( rev_cal2_lastseg );
dc->accumulated->append(dc->cal1, FALSE);
- add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding);
+ add_cap(dc->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[0], (*rev_cal2_firstseg)[1], dc->cap_rounding);
dc->accumulated->append(rev_cal2, TRUE);
- add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding);
+ add_cap(dc->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[0], (*dc_cal1_firstseg)[1], dc->cap_rounding);
dc->accumulated->closepath();
#endif
/* Current eraser */
- if ( dc->cal1->_end == 0 || dc->cal2->_end == 0 ) {
+ if ( dc->cal1->is_empty() || dc->cal2->is_empty() ) {
/* dc->npoints > 0 */
/* g_print("erasers(1|2) reset\n"); */
dc->cal1->reset();