diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-07-26 14:25:00 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-07-26 14:25:00 +0000 |
| commit | 3cc709dc31fbb335cd2cf34cae67415eb1313830 (patch) | |
| tree | 6d6dafca970804b7db2f30f752e12d12ad128be3 /src | |
| parent | Commented out tidy_operator_styled_whitespace (fixes bug 1477723). (diff) | |
| parent | update to trunk (diff) | |
| download | inkscape-3cc709dc31fbb335cd2cf34cae67415eb1313830.tar.gz inkscape-3cc709dc31fbb335cd2cf34cae67415eb1313830.zip | |
merge lp:~inkscape.dev/inkscape/simplify-lpe-pencil-toolbar into lp:inkscape
(bzr r14259)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 24 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 14 | ||||
| -rw-r--r-- | src/widgets/pencil-toolbar.cpp | 43 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 1 |
4 files changed, 78 insertions, 4 deletions
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index e8cbfcdbf..865ee760e 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -21,6 +21,7 @@ #endif #include "live_effects/lpe-patternalongpath.h" +#include "live_effects/lpe-simplify.h" #include "display/canvas-bpath.h" #include "xml/repr.h" #include "svg/svg.h" @@ -266,6 +267,21 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points lpe->getRepr()->setAttribute("offset_points", s.str().c_str()); } +static void spdc_apply_simplify(std::string threshold, FreehandBase *dc, SPItem *item) +{ + using namespace Inkscape::LivePathEffect; + + Effect::createAndApply(SIMPLIFY, dc->desktop->doc(), item); + Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); + // write powerstroke parameters: + lpe->getRepr()->setAttribute("steps", "1"); + lpe->getRepr()->setAttribute("threshold", threshold); + lpe->getRepr()->setAttribute("smooth_angles", "360"); + lpe->getRepr()->setAttribute("helper_size", "0"); + lpe->getRepr()->setAttribute("simplifyindividualpaths", "false"); + lpe->getRepr()->setAttribute("simplifyJustCoalesce", "false"); +} + static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, SPCurve *curve) { using namespace Inkscape::LivePathEffect; @@ -287,6 +303,14 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0); + bool simplify = prefs->getInt(tool_name(dc) + "/simplify", 0); + if(simplify){ + double tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0); + tol = tol/(100.0*(101.0-tol)); + std::ostringstream ss; + ss << tol; + spdc_apply_simplify(ss.str(), dc, item); + } bool shape_applied = false; SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS); const char *cstroke = sp_repr_css_property(css_item, "stroke", "none"); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 16c26546f..bfb1c67f0 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -635,8 +635,11 @@ void PencilTool::_interpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); - + double tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); + bool simplify = prefs->getInt("/tools/freehand/pencil/simplify", 0); + if(simplify){ + tolerance_sq = 0; + } g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); this->green_curve->reset(); @@ -703,8 +706,11 @@ void PencilTool::_sketchInterpolate() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; - double const tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); - + double tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); + bool simplify = prefs->getInt("/tools/freehand/pencil/simplify", 0); + if(simplify){ + tolerance_sq = 0; + } bool average_all_sketches = prefs->getBool("/tools/freehand/pencil/average_all_sketches", true); g_assert(is_zero(this->req_tangent) || is_unit_vector(this->req_tangent)); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 1214a378a..4b177d3ad 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -28,6 +28,7 @@ # include "config.h" #endif +#include <gtkmm.h> #include <glibmm/i18n.h> #include "pencil-toolbar.h" @@ -43,6 +44,12 @@ #include "ui/tools/pen-tool.h" #include "ui/uxmanager.h" #include "widgets/spinbutton-events.h" +#include <selection.h> +#include "live_effects/lpe-simplify.h" +#include "live_effects/effect-enum.h" +#include "live_effects/lpeobject.h" +#include "sp-lpe-item.h" +#include "util/glib-list-iterators.h" using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; @@ -151,6 +158,12 @@ static void freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) prefs->setInt(freehand_tool_name(dataKludge) + "/shape", shape); } +static void freehand_simplify_lpe(InkToggleAction* itact, GObject *dataKludge) { + gint simplify = gtk_toggle_action_get_active( GTK_TOGGLE_ACTION(itact) ); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(freehand_tool_name(dataKludge) + "/simplify", simplify); +} + /** * Generate the list of freehand advanced shape option entries. */ @@ -232,6 +245,24 @@ static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tb prefs->setDouble("/tools/freehand/pencil/tolerance", gtk_adjustment_get_value(adj)); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); + SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(tbl, "desktop")); + std::vector<SPItem *> selected = desktop->getSelection()->itemList(); + for (std::vector<SPItem *>::iterator it(selected.begin()); it != selected.end(); ++it){ + SPLPEItem* lpeitem = dynamic_cast<SPLPEItem*>(*it); + if (lpeitem && lpeitem->hasPathEffect()){ + Inkscape::LivePathEffect::Effect* thisEffect = lpeitem->getPathEffectOfType(Inkscape::LivePathEffect::SIMPLIFY); + if(thisEffect){ + Inkscape::LivePathEffect::LPESimplify *lpe = dynamic_cast<Inkscape::LivePathEffect::LPESimplify*>(thisEffect->getLPEObj()->get_lpe()); + if (lpe) { + double tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0); + tol = tol/(100.0*(101.0-tol)); + std::ostringstream ss; + ss << tol; + lpe->getRepr()->setAttribute("threshold", ss.str()); + } + } + } + } } /* @@ -303,6 +334,18 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_pencil_tb_defaults), holder ); gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); } + /* LPE simplify based tolerance */ + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + InkToggleAction* itact = ink_toggle_action_new( "PencilLpeSimplify", + _("LPE based interactive simplify"), + _("LPE based interactive simplify"), + INKSCAPE_ICON("interactive_simplify"), + Inkscape::ICON_SIZE_SMALL_TOOLBAR ); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(itact), prefs->getInt("/tools/freehand/pencil/simplify", 0) ); + g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(freehand_simplify_lpe), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(itact) ); + } g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index d56b91f5e..62e4bcb8b 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -398,6 +398,7 @@ static gchar const * ui_descr = " <toolitem action='FreehandModeActionPencil' />" " <separator />" " <toolitem action='PencilToleranceAction' />" + " <toolitem action='PencilLpeSimplify' />" " <separator />" " <toolitem action='PencilResetAction' />" " <separator />" |
