From 7848f8444f35c690b28657d01eade355936394b3 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 3 Dec 2019 14:15:40 +0100 Subject: [PATCH] Allow to update all selected nodes with a knot. Show original path when knot move since ungrab it. Fix bugs: https://gitlab.com/inkscape/inbox/issues/1112 https://gitlab.com/inkscape/inbox/issues/884 https://gitlab.com/inkscape/inbox/issues/22 https://gitlab.com/inkscape/inbox/issues/806 (maybe previously) --- src/helper/geom-pathvectorsatellites.cpp | 5 +-- src/live_effects/lpe-fillet-chamfer.cpp | 15 +++++++- src/live_effects/lpe-fillet-chamfer.h | 2 +- .../parameter/satellitesarray.cpp | 38 ++++++++++++++++--- src/live_effects/parameter/satellitesarray.h | 1 + src/ui/tools/node-tool.cpp | 6 +++ 6 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 4197352c79..1c06dc8b02 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -129,7 +129,6 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo continue; } - Geom::Point satellite_point = _pathvector[i].pointAt(j); if (_satellites[i][j].selected || !only_selected) { if (!use_knot_distance && !flexible) { if (previous_index) { @@ -207,7 +206,7 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa bool found = false; //TODO evaluate fix on nodes at same position size_t number_nodes = count_pathvector_nodes(pathv); - size_t previous_number_nodes = count_pathvector_nodes(_pathvector); + size_t previous_number_nodes = getTotalSatellites(); for (const auto & i : pathv) { std::vector path_satellites; size_t count = i.size_closed(); @@ -226,7 +225,7 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa break; } } - if (!found && previous_number_nodes < number_nodes) { + if (!found) { path_satellites.push_back(S); } } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index c2e1a2c253..60af272e83 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,7 +55,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) false), use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), - "use_knot_distance", &wr, this, false), + "use_knot_distance", &wr, this, true), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), @@ -84,6 +84,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); _provides_knotholder_entities = true; + helperpath = false; previous_unit = Glib::ustring(""); } @@ -345,6 +346,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (pathresult.size()) { pathresult.setFinal(curve_it->initialPoint()); } + if (Geom::are_near((*curve_it).initialPoint(), (*curve_it).finalPoint())) { + return; + } pathresult.append(*curve_it); ++curve_it; } @@ -418,6 +422,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].setSelected(true); } } + if (!pathvres[i].closed()) { + satellites[i][0].amount = 0; + satellites[i][pathvres[i].size_closed() -1].amount = 0; + } } if (!_pathvector_satellites) { _pathvector_satellites = new PathVectorSatellites(); @@ -660,6 +668,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path++; path_out.push_back(tmp_path); } + if (helperpath) { + _hp = path_out; + return pathvector_after_effect; + } + _hp.clear(); return path_out; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 68ea6d57a8..71f0f5e738 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -47,7 +47,7 @@ public: void updateChamferSteps(); void updateAmount(); void refreshKnots(); - + bool helperpath; SatellitesArrayParam satellites_param; private: diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 22e195fe9c..4362a4f1ad 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -8,6 +8,7 @@ */ #include "live_effects/parameter/satellitesarray.h" +#include "live_effects/lpe-fillet-chamfer.h" #include "knotholder.h" #include "live_effects/effect.h" #include "ui/dialog/lpe-fillet-chamfer-properties.h" @@ -241,6 +242,23 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } +void SatellitesArrayParam::updateAmmount(double amount) +{ + Geom::PathVector const pathv = _last_pathvector_satellites->getPathVector(); + Satellites satellites = _last_pathvector_satellites->getSatellites(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + Geom::Curve const &curve_in = pathv[i][j]; + if (param_effect->isNodePointSelected(curve_in.initialPoint()) ){ + _vector[i][j].amount = amount; + _vector[i][j].setSelected(true); + } else { + _vector[i][j].setSelected(false); + } + } + } +} + void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { @@ -252,11 +270,6 @@ FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( SatellitesArrayParam *p, size_t index) : _pparam(p), _index(index) {} -void FilletChamferKnotHolderEntity::knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - _pparam->param_effect->refresh_widgets = true; - _pparam->write_to_SVG(); -} void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, @@ -321,10 +334,25 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } else { satellite.setPosition(s, pathv[satelite_index][subsatelite_index]); } + Inkscape::LivePathEffect::LPEFilletChamfer *filletchamfer = dynamic_cast(_pparam->param_effect); + filletchamfer->helperpath = true; + _pparam->updateAmmount(satellite.amount); _pparam->_vector[satelite_index][subsatelite_index] = satellite; sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } +void +FilletChamferKnotHolderEntity::knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) +{ + Inkscape::LivePathEffect::LPEFilletChamfer *filletchamfer = dynamic_cast(_pparam->param_effect); + if (filletchamfer) { + filletchamfer->refresh_widgets = true; + filletchamfer->helperpath = false; + filletchamfer->writeParamsToSVG(); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + } +} + Geom::Point FilletChamferKnotHolderEntity::knot_get() const { if (!_pparam->_last_pathvector_satellites || _pparam->_global_knot_hide) { diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index af98831461..c15b7107bb 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -56,6 +56,7 @@ public: void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); void reloadKnots(); + void updateAmmount(double amount); void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites, bool write = true); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 2767b605bd..631cb34f44 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -338,6 +338,12 @@ void sp_update_helperpath() { sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO); sp_canvas_item_affine_absolute(helperpath, lpeitem->i2dt_affine()); nt->_helperpath_tmpitem.emplace_back(desktop->add_temporary_canvasitem(helperpath, 0)); + SPCanvasItem *helperpath_back = sp_canvas_bpath_new(desktop->getTempGroup(), c, true); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath_back), 0xFFFFFF33, 3.0, SP_STROKE_LINEJOIN_MITER, + SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath_back), 0, SP_WIND_RULE_NONZERO); + sp_canvas_item_affine_absolute(helperpath_back, lpeitem->i2dt_affine()); + nt->_helperpath_tmpitem.emplace_back(desktop->add_temporary_canvasitem(helperpath_back, 0)); } c->unref(); cc->unref(); -- GitLab