From d1c7f79d3f67e925719eac8b06d4e0c6c3d444f6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 23 Mar 2024 11:28:26 +0100 Subject: [PATCH] [Corners LPE 3] Alert changes I --- src/live_effects/effect.cpp | 21 +++++++++++++++++++++ src/live_effects/effect.h | 23 +++++++++++++++++++++++ src/live_effects/lpe-fillet-chamfer.cpp | 13 +++++++++---- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/lpe-powerstroke.cpp | 7 ++++--- src/live_effects/lpe-powerstroke.h | 3 +-- 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 58e9250fe2..38127a421d 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -89,6 +89,7 @@ #include "ui/tools/node-tool.h" #include "ui/tools/pen-tool.h" #include "xml/sp-css-attr.h" +#include "helper/geom.h" namespace Inkscape { namespace LivePathEffect { @@ -1472,12 +1473,19 @@ void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { } + +void Effect::adjustForNewPath() +{ + _adjust_path = true; +} + //secret impl methods (shhhh!) void Effect::doAfterEffect_impl(SPLPEItem const *lpeitem, SPCurve *curve) { doAfterEffect(lpeitem, curve); is_load = false; is_applied = false; + _adjust_path = false; } void Effect::doOnRemove_impl(SPLPEItem const* lpeitem) @@ -1542,6 +1550,19 @@ void Effect::doOnApply_impl(SPLPEItem const* lpeitem) void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); + if (_provides_path_adjustment) { + LPEItemShapesNumbers lpenumbers; + // By the moment we not handle LPEItem groups. see here how to add to + // https://pastebin.com/e5AesES9 + lpenumbers.nchildshapes = 0; + lpenumbers.nsubpaths = pathvector_before_effect.size(); + lpenumbers.ncurves = count_pathvector_curves(pathvector_before_effect); + if (!is_load && lpenumbers != _lpenumbers) { + adjustForNewPath(); + } + //std::cout << _lpenumbers << std::endl; + _lpenumbers = lpenumbers; + } doBeforeEffect(lpeitem); if (is_load) { update_satellites(); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 8ceecfba70..e6501b7b99 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -15,6 +15,7 @@ #include "ui/widget/registry.h" #include <2geom/forward.h> #include +#include #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this. @@ -55,6 +56,23 @@ enum LPEAction LPE_UPDATE }; +// maybe can grow in the future with more SPItemData +struct LPEItemShapesNumbers { + size_t nchildshapes = 0; + size_t nsubpaths = 0; + size_t ncurves = 0; + inline bool operator==(LPEItemShapesNumbers const &other) const = default; + inline bool operator!=(LPEItemShapesNumbers other) const + { + return !(*this == other); + } +}; +inline std::ostream &operator<<(std::ostream &os, LPEItemShapesNumbers const &lpeitemnumbers) { + os << "Number of child shapes:" << lpeitemnumbers.nchildshapes << std::endl; + os << "Number of subpaths:" << lpeitemnumbers.nsubpaths << std::endl; + os << "Number of curves:" << lpeitemnumbers.ncurves; + return os; +} class Effect { public: static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); @@ -85,6 +103,7 @@ public: void update_satellites(); virtual void doOnException(SPLPEItem const *lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem); + virtual void adjustForNewPath(); void writeParamsToSVG(); std::vector effect_get_satellites(bool force = true); virtual void acceptParamPath (SPPath const* param_path); @@ -166,6 +185,8 @@ protected: Effect(LivePathEffectObject *lpeobject); friend class SatelliteArrayParam; friend class LPEMeasureSegments; + // adjust path study make public if grow + bool _adjust_path = false; // provide a set of doEffect functions so the developer has a choice // of what kind of input/output parameters he desires. // the order in which they appear is the order in which they are @@ -184,6 +205,7 @@ protected: virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); bool _provides_knotholder_entities; + bool _provides_path_adjustment = false; LPEAction _lpe_action = LPE_NONE; int oncanvasedit_it; bool show_orig_path; // set this to true in derived effects to automatically have the original @@ -208,6 +230,7 @@ private: void unsetDefaultParam(Glib::ustring pref_path, Parameter *param); bool provides_own_flash_paths; // if true, the standard flash path is suppressed sigc::connection _before_commit_connection; + LPEItemShapesNumbers _lpenumbers; bool is_ready; bool defaultsopen; }; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0da523c112..2d1e0d0a04 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -89,6 +89,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_make_integer(); _provides_knotholder_entities = true; + _provides_path_adjustment = true; helperpath = false; previous_unit = Glib::ustring(""); } @@ -324,7 +325,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { double size = arcLengthAt(amount, curve_in); nodesatellites[i][j].amount = size; - } + } } nodesatellites[i][j].hidden = hide_knots; if (only_selected && isNodePointSelected(curve_in.initialPoint()) ){ @@ -340,13 +341,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (!_pathvector_nodesatellites) { _pathvector_nodesatellites = new PathVectorNodeSatellites(); } - size_t number_nodes = count_pathvector_nodes(pathv); - size_t previous_number_nodes = _pathvector_nodesatellites->getTotalNodeSatellites(); - if (is_load || number_nodes != previous_number_nodes) { + if (is_load || _adjust_path) { double power = radius; if (!flexible) { power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), "px") / getSPDoc()->getDocumentScale()[Geom::X]; } + _adjust_path = false; // not wait till effect finish NodeSatelliteType nodesatellite_type = FILLET; std::map gchar_map_to_nodesatellite_type = boost::assign::map_list_of( "F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); @@ -375,6 +375,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath() { + _adjust_path = true; +} + void LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 1764334d40..957713693e 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -38,6 +38,7 @@ public: Geom::PathVector doEffect_path(Geom::PathVector const &path_in) override; void doOnApply(SPLPEItem const *lpeItem) override; Gtk::Widget *newWidget() override; + void adjustForNewPath() override; Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) override; diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index c37307700c..a41583c7f4 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -191,6 +191,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : scale_width.param_set_digits(1); recusion_limit = 0; has_recursion = false; + _provides_path_adjustment = true; } @@ -271,7 +272,7 @@ void LPEPowerStroke::doOnRemove(SPLPEItem const* lpeitem) void LPEPowerStroke::adjustForNewPath() { - adjust_path = true; + _adjust_path = true; } @@ -596,9 +597,9 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) } Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); size_t path_init = 0; - if (adjust_path) { + if (_adjust_path) { path_out_prev.clear(); - adjust_path = false; + _adjust_path = false; // not wait till effect finish Glib::ustring version = lpeversion.param_getSVGValue(); if (version < "1.3") { offset_points.recalculate_controlpoints(pathv[0]); diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h index b5e3fd2214..95c9ec79fe 100644 --- a/src/live_effects/lpe-powerstroke.h +++ b/src/live_effects/lpe-powerstroke.h @@ -48,7 +48,7 @@ public: void transform_multiply(Geom::Affine const &postmul, bool set) override; void applyStyle(SPLPEItem *lpeitem); // methods called by path-manipulator upon edits - void adjustForNewPath(); + void adjustForNewPath() override; PowerStrokePointArrayParam offset_points; BoolParam not_jump; @@ -64,7 +64,6 @@ private: EnumParam end_linecap_type; size_t recusion_limit; bool has_recursion; - bool adjust_path = false; Geom::PathVector path_out_prev; MessageParam message; }; -- GitLab