From 3f5a54f867784d1606ebd21a804c356cfc6ef6a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 15:00:33 +0100 Subject: Update simplify and bspline to auto size some helper paths based on current zoom (bzr r13974) --- src/live_effects/effect.cpp | 4 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-bspline.cpp | 20 ++++++-- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-simplify.cpp | 57 ++++++++++++++++------ src/live_effects/lpe-simplify.h | 3 +- .../parameter/filletchamferpointarray.cpp | 2 +- .../parameter/filletchamferpointarray.h | 4 +- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 8 +-- src/ui/dialog/lpe-fillet-chamfer-properties.h | 6 +-- 10 files changed, 76 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 827f70749..aab64fe64 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -450,7 +450,7 @@ void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; + defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); @@ -459,7 +459,7 @@ void Effect::doOnApply_impl(SPLPEItem const* lpeitem) void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - defaultUnit = &sp_lpe_item->document->getDisplayUnit()->abbr; + defaultUnit = sp_lpe_item->document->getDisplayUnit()->abbr; //printf("(SPLPEITEM*) %p\n", sp_lpe_item); sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); pathvector_before_effect = sp_curve->get_pathvector(); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 7da76b267..ac1f0b8dc 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -159,7 +159,7 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - Glib::ustring const * defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + Glib::ustring defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; std::vector selectedNodesPoints; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 045974147..02a7b3711 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -106,9 +106,23 @@ void LPEBSpline::doEffect(SPCurve *curve) // Make copy of old path as it is changed during processing Geom::PathVector const original_pathv = curve->get_pathvector(); curve->reset(); - double radiusHelperNodes = 6.0; - radiusHelperNodes /= current_zoom; - radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", *defaultUnit); + double radiusHelperNodes = 12.0; + if(current_zoom != 0){ + if(current_zoom < 0.5){ + radiusHelperNodes *= current_zoom + 0.4; + } else if(current_zoom > 1) { + radiusHelperNodes *= 1/current_zoom; + } + Geom::Affine i2doc = i2anc_affine(SP_ITEM(sp_lpe_item), SP_OBJECT(SP_ITEM(sp_lpe_item)->document->getRoot())); + double expand = (i2doc.expansionX() + i2doc.expansionY())/2; + std::cout << expand << "expand\n"; + if(expand != 0){ + radiusHelperNodes /= expand; + } + radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", defaultUnit); + } else { + radiusHelperNodes = 0; + } for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d2bdf2d8d..c8458b8cb 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -223,7 +223,7 @@ void LPEFilletChamfer::updateFillet() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit) * -1; + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit) * -1; } else { power = radius; } diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 9e4d97f51..12bd9dc60 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -20,6 +20,7 @@ #include <2geom/generic-rect.h> #include <2geom/interval.h> #include "ui/icon-names.h" +#include "util/units.h" namespace Inkscape { namespace LivePathEffect { @@ -28,8 +29,9 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) : Effect(lpeobject), steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), - helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 2.), smooth_angles(_("Smooth angles:"), _("Max degree diference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), + helper(_("Helper"), _("Show helper"), "helper", &wr, this, false, + "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false, @@ -39,10 +41,11 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")) { + radiusHelperNodes = 6.0; registerParameter(dynamic_cast(&steps)); registerParameter(dynamic_cast(&threshold)); registerParameter(dynamic_cast(&smooth_angles)); - registerParameter(dynamic_cast(&helper_size)); + registerParameter(dynamic_cast(&helper)); registerParameter(dynamic_cast(&nodes)); registerParameter(dynamic_cast(&handles)); registerParameter(dynamic_cast(&simplifyindividualpaths)); @@ -53,9 +56,6 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) steps.param_set_range(0, 100); steps.param_set_increments(1, 1); steps.param_set_digits(0); - helper_size.param_set_range(0.1, 100); - helper_size.param_set_increments(1, 1); - helper_size.param_set_digits(1); smooth_angles.param_set_range(0.0, 365.0); smooth_angles.param_set_increments(10, 10); smooth_angles.param_set_digits(2); @@ -71,9 +71,24 @@ LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem) } bbox = SP_ITEM(lpeitem)->visualBounds(); SPLPEItem * item = const_cast(lpeitem); + radiusHelperNodes = 12.0; + if(current_zoom != 0){ + if(current_zoom < 0.5){ + radiusHelperNodes *= current_zoom + 0.4; + } else if(current_zoom > 1) { + radiusHelperNodes *= 1/current_zoom; + } + Geom::Affine i2doc = i2anc_affine(SP_ITEM(lpeitem), SP_OBJECT(SP_ITEM(lpeitem)->document->getRoot())); + double expand = (i2doc.expansionX() + i2doc.expansionY())/2; + if(expand != 0){ + radiusHelperNodes /= expand; + } + radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", defaultUnit); + } else { + radiusHelperNodes = 0; + } item->apply_to_clippath(item); item->apply_to_mask(item); - } Gtk::Widget * @@ -85,18 +100,31 @@ LPESimplify::newWidget() vbox->set_homogeneous(false); vbox->set_spacing(2); std::vector::iterator it = param_vector.begin(); + Gtk::HBox * buttonTop = Gtk::manage(new Gtk::HBox(true,0)); Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::HBox * buttonsTwo = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::HBox * buttonsBottom = Gtk::manage(new Gtk::HBox(true,0)); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter * param = *it; Gtk::Widget * widg = dynamic_cast(param->param_newWidget()); - if (param->param_key == "simplifyindividualpaths" || + if (param->param_key == "helper") + { + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + buttonTop->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + } else if (param->param_key == "simplifyindividualpaths" || param->param_key == "simplifyJustCoalesce") { Glib::ustring * tip = param->param_getTooltip(); if (widg) { - buttonsTwo->pack_start(*widg, true, true, 2); + buttonsBottom->pack_start(*widg, true, true, 2); if (tip) { widg->set_tooltip_text(*tip); } else { @@ -137,8 +165,9 @@ LPESimplify::newWidget() ++it; } + vbox->pack_start(*buttonTop,true, true, 2); vbox->pack_start(*buttons,true, true, 2); - vbox->pack_start(*buttonsTwo,true, true, 2); + vbox->pack_start(*buttonsBottom,true, true, 2); return dynamic_cast(vbox); } @@ -278,7 +307,7 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) void LPESimplify::drawNode(Geom::Point p) { - double r = helper_size/0.67; + double r = radiusHelperNodes; char const * svgd; svgd = "M 0.55,0.5 A 0.05,0.05 0 0 1 0.5,0.55 0.05,0.05 0 0 1 0.45,0.5 0.05,0.05 0 0 1 0.5,0.45 0.05,0.05 0 0 1 0.55,0.5 Z M 0,0 1,0 1,1 0,1 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -291,7 +320,7 @@ LPESimplify::drawNode(Geom::Point p) void LPESimplify::drawHandle(Geom::Point p) { - double r = helper_size/0.67; + double r = radiusHelperNodes; char const * svgd; svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); @@ -306,8 +335,8 @@ LPESimplify::drawHandleLine(Geom::Point p,Geom::Point p2) { Geom::Path path; path.start( p ); - double diameter = helper_size/0.67; - if(helper_size > 0.0 && Geom::distance(p,p2) > (diameter * 0.35)){ + double diameter = radiusHelperNodes; + if(helper && Geom::distance(p,p2) > (diameter * 0.35)){ Geom::Ray ray2(p, p2); p2 = p2 - Geom::Point::polar(ray2.angle(),(diameter * 0.35)); } diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 5ee8a47e6..9721d15c4 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -40,12 +40,13 @@ protected: private: ScalarParam steps; ScalarParam threshold; - ScalarParam helper_size; ScalarParam smooth_angles; + ToggleButtonParam helper; ToggleButtonParam nodes; ToggleButtonParam handles; ToggleButtonParam simplifyindividualpaths; ToggleButtonParam simplifyJustCoalesce; + double radiusHelperNodes; Geom::PathVector hp; Geom::OptRect bbox; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index 2ebe11b4b..e9d375b93 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -354,7 +354,7 @@ void FilletChamferPointArrayParam::set_pwd2( last_pwd2_normal = pwd2_normal_in; } -void FilletChamferPointArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +void FilletChamferPointArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index 6e5cce353..7849d5afb 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -53,7 +53,7 @@ public: virtual void set_helper_size(int hs); virtual void set_use_distance(bool use_knot_distance); virtual void set_chamfer_steps(int value_chamfer_steps); - virtual void set_document_unit(Glib::ustring const * value_document_unit); + virtual void set_document_unit(Glib::ustring value_document_unit); virtual void set_unit(const gchar *abbr); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -90,7 +90,7 @@ private: int chamfer_steps; bool use_distance; const gchar *unit; - Glib::ustring const * documentUnit; + Glib::ustring documentUnit; Geom::PathVector hp; Geom::Piecewise > last_pwd2; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index b318933a7..7e5c17133 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -129,7 +129,7 @@ void FilletChamferPropertiesDialog::showDialog( const gchar *unit, bool use_distance, bool aprox_radius, - Glib::ustring const * documentUnit) + Glib::ustring documentUnit) { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); @@ -172,7 +172,7 @@ void FilletChamferPropertiesDialog::_apply() } d_pos = _index + (d_pos / 100); } else { - d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, *document_unit); + d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); d_pos = d_pos * -1; } _knotpoint->knot_set_offset(Geom::Point(d_pos, d_width)); @@ -226,7 +226,7 @@ void FilletChamferPropertiesDialog::_set_knot_point(Geom::Point knotpoint) _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); position = knotpoint[Geom::X] * -1; - position = Inkscape::Util::Quantity::convert(position, *document_unit, unit); + position = Inkscape::Util::Quantity::convert(position, document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); if (knotpoint.y() == 1) { @@ -256,7 +256,7 @@ void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) unit = abbr; } -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring const *abbr) +void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring abbr) { document_unit = abbr; } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 3807e98c8..870a1734f 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -33,7 +33,7 @@ public: const gchar *unit, bool use_distance, bool aprox_radius, - Glib::ustring const * documentUnit); + Glib::ustring documentUnit); protected: @@ -69,14 +69,14 @@ protected: void _set_pt(const Inkscape::LivePathEffect:: FilletChamferPointArrayParamKnotHolderEntity *pt); void _set_unit(const gchar *abbr); - void _set_document_unit(Glib::ustring const * abbr); + void _set_document_unit(Glib::ustring abbr); void _set_use_distance(bool use_knot_distance); void _set_aprox(bool aprox_radius); void _apply(); void _close(); bool _flexible; const gchar *unit; - Glib::ustring const * document_unit; + Glib::ustring document_unit; bool use_distance; bool aprox; void _set_knot_point(Geom::Point knotpoint); -- cgit v1.2.3