diff options
| author | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-05-17 02:00:23 +0000 |
|---|---|---|
| committer | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-05-17 02:00:23 +0000 |
| commit | c418ce3ee56b7b31832fa801996439ce8256e5e7 (patch) | |
| tree | 8972313381d2e410aedf674d66fef812a455b457 /src/live_effects | |
| parent | Commit patch for "leaned" cap. Thanks Jabiertxof! (diff) | |
| parent | Fix GTK+ 3 build (diff) | |
| download | inkscape-c418ce3ee56b7b31832fa801996439ce8256e5e7.tar.gz inkscape-c418ce3ee56b7b31832fa801996439ce8256e5e7.zip | |
Update to experimental (r13376)
(bzr r13090.1.79)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/live_effects/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/live_effects/effect-enum.h | 2 | ||||
| -rw-r--r-- | src/live_effects/effect.cpp | 21 | ||||
| -rw-r--r-- | src/live_effects/lpe-bspline.cpp | 35 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice.h | 1 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice2.cpp | 496 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice2.h | 92 | ||||
| -rw-r--r-- | src/live_effects/lpe-simplify.cpp | 287 | ||||
| -rw-r--r-- | src/live_effects/lpe-simplify.h | 59 | ||||
| -rw-r--r-- | src/live_effects/lpe-vonkoch.cpp | 3 | ||||
| -rw-r--r-- | src/live_effects/parameter/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointreseteable.cpp | 210 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointreseteable.h | 74 | ||||
| -rw-r--r-- | src/live_effects/parameter/togglebutton.cpp | 92 | ||||
| -rw-r--r-- | src/live_effects/parameter/togglebutton.h | 56 |
16 files changed, 1430 insertions, 10 deletions
diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 58bd7a7dc..c7547ded3 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -34,6 +34,7 @@ set(live_effects_SRC lpe-recursiveskeleton.cpp lpe-rough-hatches.cpp lpe-ruler.cpp + lpe-simplify.cpp # lpe-skeleton.cpp lpe-sketch.cpp lpe-spiro.cpp @@ -60,6 +61,7 @@ set(live_effects_SRC parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp + parameter/togglebutton.cpp parameter/unit.cpp parameter/vector.cpp @@ -102,6 +104,7 @@ set(live_effects_SRC lpe-recursiveskeleton.h lpe-rough-hatches.h lpe-ruler.h + lpe-simplify.h lpe-skeleton.h lpe-sketch.h lpe-spiro.h @@ -128,6 +131,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h + parameter/togglebutton.h parameter/unit.h parameter/vector.h diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 5dcd3ee28..922a4a966 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -42,6 +42,10 @@ ink_common_sources += \ live_effects/lpe-bspline.h \ live_effects/lpe-lattice.cpp \ live_effects/lpe-lattice.h \ + live_effects/lpe-lattice2.cpp \ + live_effects/lpe-lattice2.h \ + live_effects/lpe-simplify.cpp \ + live_effects/lpe-simplify.h \ live_effects/lpe-envelope.cpp \ live_effects/lpe-envelope.h \ live_effects/lpe-spiro.cpp \ diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index 8295196d5..82ce36225 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -28,6 +28,8 @@ enum EffectType { PERSPECTIVE_PATH, SPIRO, LATTICE, + LATTICE2, + SIMPLIFY, ENVELOPE, CONSTRUCT_GRID, PERP_BISECTOR, diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d94f1e242..3c13ee9a9 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -27,6 +27,8 @@ #include "live_effects/lpe-perspective_path.h" #include "live_effects/lpe-spiro.h" #include "live_effects/lpe-lattice.h" +#include "live_effects/lpe-lattice2.h" +#include "live_effects/lpe-simplify.h" #include "live_effects/lpe-envelope.h" #include "live_effects/lpe-constructgrid.h" #include "live_effects/lpe-perp_bisector.h" @@ -139,6 +141,9 @@ const Util::EnumData<EffectType> LPETypeData[] = { {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, +/* 0.91 */ + {SIMPLIFY, N_("Simplify"), "simplify"}, + {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, }; const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -285,9 +290,14 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) break; case TAPER_STROKE: neweffect = static_cast<Effect*> ( new LPETaperStroke(lpeobj) ); + case SIMPLIFY: + neweffect = static_cast<Effect*> ( new LPESimplify(lpeobj) ); + break; + case LATTICE2: + neweffect = static_cast<Effect*> ( new LPELattice2(lpeobj) ); break; default: - g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); + g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; break; } @@ -564,9 +574,12 @@ Effect::getCanvasIndicators(SPLPEItem const* lpeitem) { std::vector<Geom::PathVector> hp_vec; - if (!SP_IS_SHAPE(lpeitem)) { -// g_print ("How to handle helperpaths for non-shapes?\n"); // non-shapes are for example SPGroups. - return hp_vec; + // TODO: we can probably optimize this by using a lot more references + // rather than copying PathVectors all over the place + if (SP_IS_SHAPE(lpeitem) && show_orig_path) { + // add original path to helperpaths + SPCurve* curve = SP_SHAPE(lpeitem)->getCurve (); + hp_vec.push_back(curve->get_pathvector()); } // add indicators provided by the effect itself diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index edf19d1e5..b19b697c0 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -1,14 +1,27 @@ #define INKSCAPE_LPE_BSPLINE_C + /* * Released under GNU GPL, read the file 'COPYING' for more information */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#if WITH_GLIBMM_2_32 +# include <glibmm/threads.h> +#endif + #include <gtkmm/box.h> #include <gtkmm/entry.h> #include <gtkmm/box.h> #include <gtkmm/button.h> #include <gtkmm/checkbutton.h> + #include <glib.h> #include <glibmm/i18n.h> + + #include "display/curve.h" #include <2geom/bezier-curve.h> #include <2geom/point.h> @@ -96,7 +109,7 @@ void LPEBSpline::createAndApply(const char *name, SPDocument *doc, } void LPEBSpline::doEffect(SPCurve *curve) { - if (curve->get_segment_count() < 2) + if (curve->get_segment_count() < 1) return; // Make copy of old path as it is changed during processing Geom::PathVector const original_pathv = curve->get_pathvector(); @@ -216,10 +229,26 @@ void LPEBSpline::doEffect(SPCurve *curve) { ++curve_it1; ++curve_it2; } + SPCurve *out = new SPCurve(); + out->moveto(curve_it1->initialPoint()); + out->lineto(curve_it1->finalPoint()); + cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); + if (cubic) { + SBasisOut = out->first_segment()->toSBasis(); + nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1], *out->first_segment())); + nextPointAt2 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[2], *out->first_segment())); + nextPointAt3 = out->first_segment()->finalPoint(); + } else { + nextPointAt1 = out->first_segment()->initialPoint(); + nextPointAt2 = out->first_segment()->finalPoint(); + nextPointAt3 = out->first_segment()->finalPoint(); + } + out->reset(); + delete out; //Si está cerrada la curva, la cerramos sobre el valor guardado //previamente //Si no finalizamos en el punto final - Geom::Point startNode(0, 0); + Geom::Point startNode = path_it->begin()->initialPoint(); if (path_it->closed()) { SPCurve *start = new SPCurve(); start->moveto(path_it->begin()->initialPoint()); @@ -421,7 +450,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue) { } } //bool hasNodesSelected = LPEBspline::hasNodesSelected(); - if (curve->get_segment_count() < 2) + if (curve->get_segment_count() < 1) return; // Make copy of old path as it is changed during processing Geom::PathVector const original_pathv = curve->get_pathvector(); diff --git a/src/live_effects/lpe-lattice.h b/src/live_effects/lpe-lattice.h index a44dda3fd..5eb48909b 100644 --- a/src/live_effects/lpe-lattice.h +++ b/src/live_effects/lpe-lattice.h @@ -58,7 +58,6 @@ private: PointParam grid_point13; PointParam grid_point14; PointParam grid_point15; - LPELattice(const LPELattice&); LPELattice& operator=(const LPELattice&); }; diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp new file mode 100644 index 000000000..db609c9e1 --- /dev/null +++ b/src/live_effects/lpe-lattice2.cpp @@ -0,0 +1,496 @@ +/** \file + * LPE <lattice2> implementation + + */ +/* + * Authors: + * Johan Engelen <j.b.c.engelen@utwente.nl> + * Steren Giannini + * Noé Falzon + * Victor Navez + * ~suv + * Jabiertxo Arraiza +* +* Copyright (C) 2007-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-lattice2.h" + +#include "sp-shape.h" +#include "sp-item.h" +#include "sp-path.h" +#include "display/curve.h" +#include "svg/svg.h" + +#include <2geom/sbasis.h> +#include <2geom/sbasis-2d.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/piecewise.h> +#include <2geom/transforms.h> +#include <tools-switch.h> + +#include "desktop.h" // TODO: should be factored out (see below) + +using namespace Geom; + +namespace Inkscape { +namespace LivePathEffect { + +LPELattice2::LPELattice2(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + // initialise your parameters here: + grid_point0(_("Control handle 0:"), _("Control handle 0 - Ctrl+Alt+Click to reset"), "gridpoint0", &wr, this), + grid_point1(_("Control handle 1:"), _("Control handle 1 - Ctrl+Alt+Click to reset"), "gridpoint1", &wr, this), + grid_point2(_("Control handle 2:"), _("Control handle 2 - Ctrl+Alt+Click to reset"), "gridpoint2", &wr, this), + grid_point3(_("Control handle 3:"), _("Control handle 3 - Ctrl+Alt+Click to reset"), "gridpoint3", &wr, this), + grid_point4(_("Control handle 4:"), _("Control handle 4 - Ctrl+Alt+Click to reset"), "gridpoint4", &wr, this), + grid_point5(_("Control handle 5:"), _("Control handle 5 - Ctrl+Alt+Click to reset"), "gridpoint5", &wr, this), + grid_point6(_("Control handle 6:"), _("Control handle 6 - Ctrl+Alt+Click to reset"), "gridpoint6", &wr, this), + grid_point7(_("Control handle 7:"), _("Control handle 7 - Ctrl+Alt+Click to reset"), "gridpoint7", &wr, this), + grid_point8x9(_("Control handle 8x9:"), _("Control handle 8x9 - Ctrl+Alt+Click to reset"), "gridpoint8x9", &wr, this), + grid_point10x11(_("Control handle 10x11:"), _("Control handle 10x11 - Ctrl+Alt+Click to reset"), "gridpoint10x11", &wr, this), + grid_point12(_("Control handle 12:"), _("Control handle 12 - Ctrl+Alt+Click to reset"), "gridpoint12", &wr, this), + grid_point13(_("Control handle 13:"), _("Control handle 13 - Ctrl+Alt+Click to reset"), "gridpoint13", &wr, this), + grid_point14(_("Control handle 14:"), _("Control handle 14 - Ctrl+Alt+Click to reset"), "gridpoint14", &wr, this), + grid_point15(_("Control handle 15:"), _("Control handle 15 - Ctrl+Alt+Click to reset"), "gridpoint15", &wr, this), + grid_point16(_("Control handle 16:"), _("Control handle 16 - Ctrl+Alt+Click to reset"), "gridpoint16", &wr, this), + grid_point17(_("Control handle 17:"), _("Control handle 17 - Ctrl+Alt+Click to reset"), "gridpoint17", &wr, this), + grid_point18(_("Control handle 18:"), _("Control handle 18 - Ctrl+Alt+Click to reset"), "gridpoint18", &wr, this), + grid_point19(_("Control handle 19:"), _("Control handle 19 - Ctrl+Alt+Click to reset"), "gridpoint19", &wr, this), + grid_point20x21(_("Control handle 20x21:"), _("Control handle 20x21 - Ctrl+Alt+Click to reset"), "gridpoint20x21", &wr, this), + grid_point22x23(_("Control handle 22x23:"), _("Control handle 22x23 - Ctrl+Alt+Click to reset"), "gridpoint22x23", &wr, this), + grid_point24x26(_("Control handle 24x26:"), _("Control handle 24x26 - Ctrl+Alt+Click to reset"), "gridpoint24x26", &wr, this), + grid_point25x27(_("Control handle 25x27:"), _("Control handle 25x27 - Ctrl+Alt+Click to reset"), "gridpoint25x27", &wr, this), + grid_point28x30(_("Control handle 28x30:"), _("Control handle 28x30 - Ctrl+Alt+Click to reset"), "gridpoint28x30", &wr, this), + grid_point29x31(_("Control handle 29x31:"), _("Control handle 29x31 - Ctrl+Alt+Click to reset"), "gridpoint29x31", &wr, this), + grid_point32x33x34x35(_("Control handle 32x33x34x35:"), _("Control handle 32x33x34x35 - Ctrl+Alt+Click to reset"), "gridpoint32x33x34x35", &wr, this) + + +{ + // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast<Parameter *>(&grid_point0) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point1) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point2) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point3) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point4) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point5) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point6) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point7) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point8x9) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point10x11) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point12) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point13) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point14) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point15) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point16) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point17) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point18) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point19) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point20x21) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point22x23) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point24x26) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point25x27) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point28x30) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point29x31) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point32x33x34x35) ); +} + +LPELattice2::~LPELattice2() +{ +} + +Geom::Piecewise<Geom::D2<Geom::SBasis> > +LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) +{ + D2<SBasis2d> sb2; + + //Initialisation of the sb2 + for(unsigned dim = 0; dim < 2; dim++) { + sb2[dim].us = 3; + sb2[dim].vs = 3; + const int depth = sb2[dim].us*sb2[dim].vs; + sb2[dim].resize(depth, Linear2d(0)); + } + + //Grouping the point params in a convenient vector + std::vector<Geom::Point *> handles(36); + + handles[0] = &grid_point0; + handles[1] = &grid_point1; + handles[2] = &grid_point2; + handles[3] = &grid_point3; + handles[4] = &grid_point4; + handles[5] = &grid_point5; + handles[6] = &grid_point6; + handles[7] = &grid_point7; + handles[8] = &grid_point8x9; + handles[9] = &grid_point8x9; + handles[10] = &grid_point10x11; + handles[11] = &grid_point10x11; + handles[12] = &grid_point12; + handles[13] = &grid_point13; + handles[14] = &grid_point14; + handles[15] = &grid_point15; + handles[16] = &grid_point16; + handles[17] = &grid_point17; + handles[18] = &grid_point18; + handles[19] = &grid_point19; + handles[20] = &grid_point20x21; + handles[21] = &grid_point20x21; + handles[22] = &grid_point22x23; + handles[23] = &grid_point22x23; + handles[24] = &grid_point24x26; + handles[25] = &grid_point25x27; + handles[26] = &grid_point24x26; + handles[27] = &grid_point25x27; + handles[28] = &grid_point28x30; + handles[29] = &grid_point29x31; + handles[30] = &grid_point28x30; + handles[31] = &grid_point29x31; + handles[32] = &grid_point32x33x34x35; + handles[33] = &grid_point32x33x34x35; + handles[34] = &grid_point32x33x34x35; + handles[35] = &grid_point32x33x34x35; + + Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min()); + + double width = boundingbox_X.extent(); + double height = boundingbox_Y.extent(); + + //numbering is based on 4 rectangles.16 + for(unsigned dim = 0; dim < 2; dim++) { + Geom::Point dir(0,0); + dir[dim] = 1; + for(unsigned vi = 0; vi < sb2[dim].vs; vi++) { + for(unsigned ui = 0; ui < sb2[dim].us; ui++) { + for(unsigned iv = 0; iv < 2; iv++) { + for(unsigned iu = 0; iu < 2; iu++) { + unsigned corner = iu + 2*iv; + unsigned i = ui + vi*sb2[dim].us; + + //This is the offset from the Upperleft point + Geom::Point base( (ui + iu*(4-2*ui))*width/4., + (vi + iv*(4-2*vi))*height/4.); + + //Special action for corners + if(vi == 0 && ui == 0) { + base = Geom::Point(0,0); + } + + // i = Upperleft corner of the considerated rectangle + // corner = actual corner of the rectangle + // origin = Upperleft point + double dl = dot((*handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir); + sb2[dim][i][corner] = dl/( dim ? height : width )*pow(4.0,ui+vi); + } + } + } + } + } + + Piecewise<D2<SBasis> > output; + output.push_cut(0.); + for(unsigned i = 0; i < pwd2_in.size(); i++) { + D2<SBasis> B = pwd2_in[i]; + B[Geom::X] -= origin[Geom::X]; + B[Geom::X]*= 1/width; + B[Geom::Y] -= origin[Geom::Y]; + B[Geom::Y]*= 1/height; + //Here comes the magic + D2<SBasis> tB = compose_each(sb2,B); + tB[Geom::X] = tB[Geom::X] * width + origin[Geom::X]; + tB[Geom::Y] = tB[Geom::Y] * height + origin[Geom::Y]; + + output.push(tB,i+1); + } + return output; +} + +Gtk::Widget * +LPELattice2::newWidget() +{ + // use manage here, because after deletion of Effect object, others might still be pointing to this widget. + Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + + vbox->set_border_width(5); + Gtk::Button* resetButton = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset grid")))); + resetButton->set_alignment(0.0, 0.5); + resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPELattice2::resetGrid)); + Gtk::Widget* resetButtonWidget = dynamic_cast<Gtk::Widget *>(resetButton); + resetButtonWidget->set_tooltip_text("Reset grid"); + vbox->pack_start(*resetButtonWidget, true, true,2); + std::vector<Parameter *>::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter * param = *it; + Gtk::Widget * widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget()); + if(param->param_key == "grid"){ + widg = NULL; + } + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + } + + ++it; + } + return dynamic_cast<Gtk::Widget *>(vbox); +} + +void +LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) +{ + original_bbox(lpeitem); + setDefaults(); +} + +void +LPELattice2::setDefaults() +{ + Geom::Point gp0((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + + Geom::Point gp1((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + + Geom::Point gp2((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + + Geom::Point gp3((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + + Geom::Point gp4((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + + Geom::Point gp5((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + + Geom::Point gp6((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + + Geom::Point gp7((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + + Geom::Point gp8x9((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*0+boundingbox_Y.min()); + + Geom::Point gp10x11((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*4+boundingbox_Y.min()); + + Geom::Point gp12((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + + Geom::Point gp13((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + + Geom::Point gp14((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + + Geom::Point gp15((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + + Geom::Point gp16((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + + Geom::Point gp17((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + + Geom::Point gp18((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + + Geom::Point gp19((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + + Geom::Point gp20x21((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*1+boundingbox_Y.min()); + + Geom::Point gp22x23((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*3+boundingbox_Y.min()); + + Geom::Point gp24x26((boundingbox_X.max()-boundingbox_X.min())/4*0+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + Geom::Point gp25x27((boundingbox_X.max()-boundingbox_X.min())/4*4+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + Geom::Point gp28x30((boundingbox_X.max()-boundingbox_X.min())/4*1+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + Geom::Point gp29x31((boundingbox_X.max()-boundingbox_X.min())/4*3+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + Geom::Point gp32x33x34x35((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), + (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); + + grid_point0.param_update_default(gp0); + grid_point1.param_update_default(gp1); + grid_point2.param_update_default(gp2); + grid_point3.param_update_default(gp3); + grid_point4.param_update_default(gp4); + grid_point5.param_update_default(gp5); + grid_point6.param_update_default(gp6); + grid_point7.param_update_default(gp7); + grid_point8x9.param_update_default(gp8x9); + grid_point10x11.param_update_default(gp10x11); + grid_point12.param_update_default(gp12); + grid_point13.param_update_default(gp13); + grid_point14.param_update_default(gp14); + grid_point15.param_update_default(gp15); + grid_point16.param_update_default(gp16); + grid_point17.param_update_default(gp17); + grid_point18.param_update_default(gp18); + grid_point19.param_update_default(gp19); + grid_point20x21.param_update_default(gp20x21); + grid_point22x23.param_update_default(gp22x23); + grid_point24x26.param_update_default(gp24x26); + grid_point25x27.param_update_default(gp25x27); + grid_point28x30.param_update_default(gp28x30); + grid_point29x31.param_update_default(gp29x31); + grid_point32x33x34x35.param_update_default(gp32x33x34x35); +} + +void +LPELattice2::resetGrid() +{ + grid_point0.param_set_and_write_default(); + grid_point1.param_set_and_write_default(); + grid_point2.param_set_and_write_default(); + grid_point3.param_set_and_write_default(); + grid_point4.param_set_and_write_default(); + grid_point5.param_set_and_write_default(); + grid_point6.param_set_and_write_default(); + grid_point7.param_set_and_write_default(); + grid_point8x9.param_set_and_write_default(); + grid_point10x11.param_set_and_write_default(); + grid_point12.param_set_and_write_default(); + grid_point13.param_set_and_write_default(); + grid_point14.param_set_and_write_default(); + grid_point15.param_set_and_write_default(); + grid_point16.param_set_and_write_default(); + grid_point17.param_set_and_write_default(); + grid_point18.param_set_and_write_default(); + grid_point19.param_set_and_write_default(); + grid_point20x21.param_set_and_write_default(); + grid_point22x23.param_set_and_write_default(); + grid_point24x26.param_set_and_write_default(); + grid_point25x27.param_set_and_write_default(); + grid_point28x30.param_set_and_write_default(); + grid_point29x31.param_set_and_write_default(); + grid_point32x33x34x35.param_set_and_write_default(); + //todo:this hack is only to reposition the knots on reser grid button + //Better update path effect in LPEITEM + SPDesktop * desktop = inkscape_active_desktop(); + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); +} + +void +LPELattice2::resetDefaults(SPItem const* item) +{ + Effect::resetDefaults(item); + original_bbox(SP_LPE_ITEM(item)); + setDefaults(); + resetGrid(); +} + +void +LPELattice2::calculateCurve(Geom::Point a,Geom::Point b, SPCurve* c, bool horizontal, bool move) +{ + using Geom::X; + using Geom::Y; + if(move) c->moveto(a); + Geom::Point cubic1 = a + (1./3)* (b - a); + Geom::Point cubic2 = b + (1./3)* (a - b); + if(horizontal) c->curveto(Geom::Point(cubic1[X],a[Y]),Geom::Point(cubic2[X],b[Y]),b); + else c->curveto(Geom::Point(a[X],cubic1[Y]),Geom::Point(b[X],cubic2[Y]),b); +} + +void +LPELattice2::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) +{ + hp_vec.clear(); + + SPCurve *c = new SPCurve(); + calculateCurve(grid_point0,grid_point4, c,true, true); + calculateCurve(grid_point4,grid_point8x9, c,true, false); + calculateCurve(grid_point8x9,grid_point5, c,true, false); + calculateCurve(grid_point5,grid_point1, c,true, false); + + calculateCurve(grid_point12,grid_point16, c,true, true); + calculateCurve(grid_point16,grid_point20x21, c,true, false); + calculateCurve(grid_point20x21,grid_point17, c,true, false); + calculateCurve(grid_point17,grid_point13, c,true, false); + + calculateCurve(grid_point24x26,grid_point28x30, c,true, true); + calculateCurve(grid_point28x30,grid_point32x33x34x35, c,true, false); + calculateCurve(grid_point32x33x34x35,grid_point29x31, c,true, false); + calculateCurve(grid_point29x31,grid_point25x27, c,true, false); + + calculateCurve(grid_point14,grid_point18, c,true, true); + calculateCurve(grid_point18,grid_point22x23, c,true, false); + calculateCurve(grid_point22x23,grid_point19, c,true, false); + calculateCurve(grid_point19,grid_point15, c,true, false); + + calculateCurve(grid_point2,grid_point6, c,true, true); + calculateCurve(grid_point6,grid_point10x11, c,true, false); + calculateCurve(grid_point10x11,grid_point7, c,true, false); + calculateCurve(grid_point7,grid_point3, c,true, false); + + calculateCurve(grid_point0,grid_point12, c,false, true); + calculateCurve(grid_point12,grid_point24x26, c,false, false); + calculateCurve(grid_point24x26,grid_point14, c,false, false); + calculateCurve(grid_point14,grid_point2, c,false, false); + + calculateCurve(grid_point4,grid_point16, c,false, true); + calculateCurve(grid_point16,grid_point28x30, c,false, false); + calculateCurve(grid_point28x30,grid_point18, c,false, false); + calculateCurve(grid_point18,grid_point6, c,false, false); + + calculateCurve(grid_point8x9,grid_point20x21, c,false, true); + calculateCurve(grid_point20x21,grid_point32x33x34x35, c,false, false); + calculateCurve(grid_point32x33x34x35,grid_point22x23, c,false, false); + calculateCurve(grid_point22x23,grid_point10x11, c,false, false); + + calculateCurve(grid_point5,grid_point17, c, false, true); + calculateCurve(grid_point17,grid_point29x31, c,false, false); + calculateCurve(grid_point29x31,grid_point19, c,false, false); + calculateCurve(grid_point19,grid_point7, c,false, false); + + calculateCurve(grid_point1,grid_point13, c, false, true); + calculateCurve(grid_point13,grid_point25x27, c,false, false); + calculateCurve(grid_point25x27,grid_point15, c,false, false); + calculateCurve(grid_point15,grid_point3, c, false, false); + hp_vec.push_back(c->get_pathvector()); +} + + +/* ######################## */ + +} //namespace LivePathEffect +} /* namespace Inkscape */ + + + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h new file mode 100644 index 000000000..461f835c6 --- /dev/null +++ b/src/live_effects/lpe-lattice2.h @@ -0,0 +1,92 @@ +#ifndef INKSCAPE_LPE_LATTICE2_H +#define INKSCAPE_LPE_LATTICE2_H + +/** \file + * LPE <lattice2> implementation, see lpe-lattice2.cpp. + */ + +/* + * Authors: + * Johan Engelen + * Steren Giannini + * Noé Falzon + * Victor Navez + * ~suv + * Jabiertxo Arraiza +* +* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/enum.h" +#include "live_effects/effect.h" +#include "live_effects/parameter/pointreseteable.h" +#include "live_effects/lpegroupbbox.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPELattice2 : public Effect, GroupBBoxEffect { +public: + + LPELattice2(LivePathEffectObject *lpeobject); + virtual ~LPELattice2(); + + virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in); + + virtual void resetDefaults(SPItem const* item); + + virtual void doBeforeEffect(SPLPEItem const* lpeitem); + + virtual Gtk::Widget * newWidget(); + + virtual void calculateCurve(Geom::Point a,Geom::Point b, SPCurve *c, bool horizontal, bool move); + + virtual void setDefaults(); + + virtual void resetGrid(); + + //virtual void original_bbox(SPLPEItem const* lpeitem, bool absolute = false); + + //virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/); + + //virtual std::vector<Geom::PathVector> getHelperPaths(SPLPEItem const* lpeitem); +protected: + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); +private: + + PointReseteableParam grid_point0; + PointReseteableParam grid_point1; + PointReseteableParam grid_point2; + PointReseteableParam grid_point3; + PointReseteableParam grid_point4; + PointReseteableParam grid_point5; + PointReseteableParam grid_point6; + PointReseteableParam grid_point7; + PointReseteableParam grid_point8x9; + PointReseteableParam grid_point10x11; + PointReseteableParam grid_point12; + PointReseteableParam grid_point13; + PointReseteableParam grid_point14; + PointReseteableParam grid_point15; + PointReseteableParam grid_point16; + PointReseteableParam grid_point17; + PointReseteableParam grid_point18; + PointReseteableParam grid_point19; + PointReseteableParam grid_point20x21; + PointReseteableParam grid_point22x23; + PointReseteableParam grid_point24x26; + PointReseteableParam grid_point25x27; + PointReseteableParam grid_point28x30; + PointReseteableParam grid_point29x31; + PointReseteableParam grid_point32x33x34x35; + + LPELattice2(const LPELattice2&); + LPELattice2& operator=(const LPELattice2&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp new file mode 100644 index 000000000..d010e75a2 --- /dev/null +++ b/src/live_effects/lpe-simplify.cpp @@ -0,0 +1,287 @@ +#define INKSCAPE_LPE_SIMPLIFY_C +/* + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include <gtkmm/box.h> +#include <gtkmm/entry.h> +#include "live_effects/lpe-simplify.h" +#include "display/curve.h" +#include "live_effects/parameter/parameter.h" +#include <glibmm/i18n.h> +#include "helper/geom.h" +#include "livarot/Path.h" +#include "splivarot.h" +#include <2geom/svg-path-parser.h> +#include "desktop.h" +#include "inkscape.h" +#include "svg/svg.h" +#include "ui/tools/node-tool.h" +#include <2geom/d2.h> +#include <2geom/generic-rect.h> +#include <2geom/interval.h> + + +namespace Inkscape { +namespace LivePathEffect { + +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.), + nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false), + handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false), + simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false), + simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false) + { + registerParameter(dynamic_cast<Parameter *>(&steps)); + registerParameter(dynamic_cast<Parameter *>(&threshold)); + registerParameter(dynamic_cast<Parameter *>(&helper_size)); + registerParameter(dynamic_cast<Parameter *>(&nodes)); + registerParameter(dynamic_cast<Parameter *>(&handles)); + registerParameter(dynamic_cast<Parameter *>(&simplifyindividualpaths)); + registerParameter(dynamic_cast<Parameter *>(&simplifyJustCoalesce)); + threshold.param_set_range(0., Geom::infinity()); + threshold.param_set_increments(0.0001, 0.0001); + threshold.param_set_digits(6); + 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); +} + +LPESimplify::~LPESimplify() {} + +void +LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem) +{ + if(!hp.empty()){ + hp.clear(); + } + bbox = SP_ITEM(lpeitem)->visualBounds(); + +} + +Gtk::Widget * +LPESimplify::newWidget() +{ + // use manage here, because after deletion of Effect object, others might still be pointing to this widget. + Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox->set_border_width(5); + vbox->set_homogeneous(false); + vbox->set_spacing(2); + std::vector<Parameter *>::iterator it = param_vector.begin(); + Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::HBox * buttonsTwo = 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<Gtk::Widget *>(param->param_newWidget()); + if (param->param_key == "simplifyindividualpaths" || + param->param_key == "simplifyJustCoalesce") + { + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + buttonsTwo->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 == "nodes" || + param->param_key == "handles") + { + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + buttons->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + }else{ + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg); + std::vector< Gtk::Widget* > childList = scalarParameter->get_children(); + Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]); + entryWidg->set_width_chars(8); + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + } + } + + ++it; + } + vbox->pack_start(*buttons,true, true, 2); + vbox->pack_start(*buttonsTwo,true, true, 2); + return dynamic_cast<Gtk::Widget *>(vbox); +} + +void +LPESimplify::doEffect(SPCurve *curve) { + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); + gdouble size = Geom::L2(bbox->dimensions()); + //size /= Geom::Affine(0,0,0,0,0,0).descrim(); + Path* pathliv = Path_for_pathvector(original_pathv); + if(simplifyindividualpaths){ + size = Geom::L2(Geom::bounds_fast(original_pathv)->dimensions()); + } + for (int unsigned i = 0; i < steps; i++){ + if ( simplifyJustCoalesce ) { + pathliv->Coalesce(threshold * size); + }else{ + pathliv->ConvertEvenLines(threshold * size); + pathliv->Simplify(threshold * size); + } + } + Geom::PathVector outres = Geom::parse_svg_path(pathliv->svg_dump_path()); + generateHelperPath(outres); + curve->set_pathvector(outres); + if(SP_ACTIVE_DESKTOP && INK_IS_NODE_TOOL(SP_ACTIVE_DESKTOP->event_context)){ + SPDesktop* desktop = SP_ACTIVE_DESKTOP; + Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context); + nt->update_helperpath(); + } +} + +void +LPESimplify::generateHelperPath(Geom::PathVector result) +{ + if(!handles && !nodes){ + return; + } + + if(steps < 1){ + return; + } + + Geom::CubicBezier const *cubic = NULL; + for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { + //Si está vacÃo... + if (path_it->empty()){ + continue; + } + //Itreadores + Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve + Geom::Path::const_iterator curve_it2 = + ++(path_it->begin()); // outgoing curve + Geom::Path::const_iterator curve_endit = + path_it->end_default(); // this determines when the loop has to stop + + if (path_it->closed()) { + // if the path is closed, maybe we have to stop a bit earlier because the + // closing line segment has zerolength. + const Geom::Curve &closingline = + path_it->back_closed(); // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } + if(nodes){ + drawNode(curve_it1->initialPoint()); + } + while (curve_it2 != curve_endit) { + cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); + if (cubic) { + if(handles){ + drawHandle((*cubic)[1]); + drawHandle((*cubic)[2]); + drawHandleLine((*cubic)[0],(*cubic)[1]); + drawHandleLine((*cubic)[2],(*cubic)[3]); + } + } + if(nodes){ + drawNode(curve_it1->finalPoint()); + } + ++curve_it1; + ++curve_it2; + } + cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); + if (cubic) { + if(handles){ + drawHandle((*cubic)[1]); + drawHandle((*cubic)[2]); + drawHandleLine((*cubic)[0],(*cubic)[1]); + drawHandleLine((*cubic)[2],(*cubic)[3]); + } + } + if(nodes){ + drawNode(curve_it1->finalPoint()); + } + } +} + +void +LPESimplify::drawNode(Geom::Point p) +{ + double r = helper_size/0.67; + char const * svgd; + svgd = "M 0.999993,0.5 C 1.000065,0.7757576 0.7761859,1 0.4999926,1 0.2237994,1 -7.933901e-5,0.7757576 -7.339015e-6,0.5 -7.933901e-5,0.2242424 0.2237994,0 0.4999926,0 0.7761859,0 1.000065,0.2242424 0.999993,0.5 Z m -0.058561,0 C 0.9414949,0.74327 0.7438375,0.9416286 0.4999928,0.9416286 0.2561481,0.9416286 0.0584908,0.74327 0.0585543,0.5 0.0584908,0.25673 0.2561481,0.0583714 0.4999928,0.0583714 0.7438375,0.0583714 0.9414949,0.25673 0.9414313,0.5 Z m -0.3828447,0 c 8.5e-6,0.030303 -0.026228,0.060606 -0.058593,0.060606 -0.032366,0 -0.058603,-0.030303 -0.058593,-0.060606 -8.5e-6,-0.030303 0.026227,-0.060606 0.058593,-0.060606 0.032366,0 0.058603,0.030303 0.058593,0.060606 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Affine(r,0,0,r,0,0); + pathv += p - Geom::Point(0.5*r,0.5*r); + hp.push_back(pathv[0]); + hp.push_back(pathv[1]); + hp.push_back(pathv[2]); +} + +void +LPESimplify::drawHandle(Geom::Point p) +{ + double r = helper_size/0.67; + char const * svgd; + svgd = "M 0.6999623,0.35 C 0.7000128,0.5430303 0.5433044,0.7 0.3499775,0.7 0.1566506,0.7 -5.778776e-5,0.5430303 -7.344202e-6,0.35 -5.778776e-5,0.1569697 0.1566506,0 0.3499775,0 0.5433044,0 0.7000128,0.1569697 0.6999623,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Affine(r,0,0,r,0,0); + pathv += p - Geom::Point(0.35*r,0.35*r); + hp.push_back(pathv[0]); +} + + +void +LPESimplify::drawHandleLine(Geom::Point p,Geom::Point p2) +{ + Geom::Path path; + path.start( p ); + path.appendNew<Geom::LineSegment>( p2 ); + hp.push_back(path); +} + +void +LPESimplify::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) +{ + hp_vec.push_back(hp); +} + + +}; //namespace LivePathEffect +}; /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h new file mode 100644 index 000000000..6acf2f2d4 --- /dev/null +++ b/src/live_effects/lpe-simplify.h @@ -0,0 +1,59 @@ +#ifndef INKSCAPE_LPE_SIMPLIFY_H +#define INKSCAPE_LPE_SIMPLIFY_H + +/* + * Inkscape::LPESimplify + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/togglebutton.h" +#include "live_effects/lpegroupbbox.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPESimplify : public Effect , GroupBBoxEffect{ + +public: + LPESimplify(LivePathEffectObject *lpeobject); + virtual ~LPESimplify(); + + virtual void doEffect(SPCurve *curve); + + virtual void doBeforeEffect (SPLPEItem const* lpeitem); + + virtual void generateHelperPath(Geom::PathVector result); + + virtual Gtk::Widget * newWidget(); + + virtual void drawNode(Geom::Point p); + + virtual void drawHandle(Geom::Point p); + + virtual void drawHandleLine(Geom::Point p,Geom::Point p2); + +protected: + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); + +private: + ScalarParam steps; + ScalarParam threshold; + ScalarParam helper_size; + ToggleButtonParam nodes; + ToggleButtonParam handles; + ToggleButtonParam simplifyindividualpaths; + ToggleButtonParam simplifyJustCoalesce; + + Geom::PathVector hp; + Geom::OptRect bbox; + + LPESimplify(const LPESimplify &); + LPESimplify &operator=(const LPESimplify &); + +}; + +}; //namespace LivePathEffect +}; //namespace Inkscape +#endif diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index c0050fa60..8b0b716fe 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -4,11 +4,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <cstdio> +#include "live_effects/lpe-vonkoch.h" #include <glibmm/i18n.h> -#include "live_effects/lpe-vonkoch.h" #include <2geom/transforms.h> //using std::vector; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 37cc3dc62..330035ad6 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -11,6 +11,8 @@ ink_common_sources += \ live_effects/parameter/random.h \ live_effects/parameter/point.cpp \ live_effects/parameter/point.h \ + live_effects/parameter/pointreseteable.cpp \ + live_effects/parameter/pointreseteable.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ @@ -26,6 +28,8 @@ ink_common_sources += \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ live_effects/parameter/transformedpoint.h \ + live_effects/parameter/togglebutton.cpp \ + live_effects/parameter/togglebutton.h \ live_effects/parameter/unit.cpp \ live_effects/parameter/unit.h \ live_effects/parameter/vector.cpp \ diff --git a/src/live_effects/parameter/pointreseteable.cpp b/src/live_effects/parameter/pointreseteable.cpp new file mode 100644 index 000000000..ec36fc035 --- /dev/null +++ b/src/live_effects/parameter/pointreseteable.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/pointreseteable.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "ui/widget/point.h" +#include "widgets/icon.h" +#include "inkscape.h" +#include "verbs.h" +#include "knotholder.h" +#include <glibmm/i18n.h> +#include "tools-switch.h" +#include "ui/tools/node-tool.h" + +// needed for on-canvas editting: +#include "desktop.h" + +namespace Inkscape { + +namespace LivePathEffect { + +PointReseteableParam::PointReseteableParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const gchar *htip, Geom::Point default_value) + : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0xffffff00; + handle_tip = g_strdup(htip); +} + +PointReseteableParam::~PointReseteableParam() +{ + if (handle_tip) + g_free(handle_tip); +} + +void +PointReseteableParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +PointReseteableParam::param_set_and_write_default() +{ + param_set_and_write_new_value(defvalue); +} + +void +PointReseteableParam::param_update_default(Geom::Point newpoint) +{ + this->defvalue = newpoint; +} + +bool +PointReseteableParam::param_readSVGValue(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, ",", 2); + double newx, newy; + unsigned int success = sp_svg_number_read_d(strarray[0], &newx); + success += sp_svg_number_read_d(strarray[1], &newy); + g_strfreev (strarray); + if (success == 2) { + param_setValue( Geom::Point(newx, newy) ); + return true; + } + return false; +} + +gchar * +PointReseteableParam::param_getSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << *dynamic_cast<Geom::Point const *>( this ); + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +Gtk::Widget * +PointReseteableParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Geom::Affine transf = desktop->doc2dt(); + pointwdg->setTransform(transf); + pointwdg->setValue( *this ); + pointwdg->clearProgrammatically(); + pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + + Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); + static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true); + static_cast<Gtk::HBox*>(hbox)->show_all_children(); + + return dynamic_cast<Gtk::Widget *> (hbox); +} + +void +PointReseteableParam::param_setValue(Geom::Point newpoint) +{ + *dynamic_cast<Geom::Point *>( this ) = newpoint; + if(SP_ACTIVE_DESKTOP){ + SPDesktop* desktop = SP_ACTIVE_DESKTOP; + if (tools_isactive( desktop, TOOLS_NODES)) { + Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>( desktop->event_context); + nt->update_helperpath(); + } + } +} + +void +PointReseteableParam::param_set_and_write_new_value (Geom::Point newpoint) +{ + Inkscape::SVGOStringStream os; + os << newpoint; + gchar * str = g_strdup(os.str().c_str()); + param_write_to_repr(str); + g_free(str); +} + +void +PointReseteableParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +{ + param_set_and_write_new_value( (*this) * postmul ); +} + + +void +PointReseteableParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +class PointReseteableParamKnotHolderEntity : public KnotHolderEntity { +public: + PointReseteableParamKnotHolderEntity(PointReseteableParam *p) { this->pparam = p; } + virtual ~PointReseteableParamKnotHolderEntity() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + virtual void knot_click(guint state); + +private: + PointReseteableParam *pparam; +}; + +void +PointReseteableParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) +{ + Geom::Point const s = snap_knot_position(p, state); + pparam->param_setValue(s); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); +} + +Geom::Point +PointReseteableParamKnotHolderEntity::knot_get() const +{ + return *pparam; +} + +void +PointReseteableParamKnotHolderEntity::knot_click(guint state) +{ + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + this->pparam->param_set_default(); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + } + } +} + +void +PointReseteableParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + PointReseteableParamKnotHolderEntity *e = new PointReseteableParamKnotHolderEntity(this); + // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); + knotholder->add(e); +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/pointreseteable.h b/src/live_effects/parameter/pointreseteable.h new file mode 100644 index 000000000..5ae1fdf02 --- /dev/null +++ b/src/live_effects/parameter/pointreseteable.h @@ -0,0 +1,74 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_RESETEABLE_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_RESETEABLE_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <glib.h> +#include <2geom/point.h> + +#include "live_effects/parameter/parameter.h" + +#include "knot-holder-entity.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class PointReseteableParamKnotHolderEntity; + +class PointReseteableParam : public Geom::Point, public Parameter { +public: + PointReseteableParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const gchar *handle_tip = NULL, + Geom::Point default_value = Geom::Point(0,0) ); // tip for automatically associated on-canvas handle + virtual ~PointReseteableParam(); + + virtual Gtk::Widget * param_newWidget(); + + bool param_readSVGValue(const gchar * strvalue); + gchar * param_getSVGValue() const; + inline const gchar *handleTip() const { return handle_tip ? handle_tip : param_tooltip.c_str(); } + + void param_setValue(Geom::Point newpoint); + void param_set_default(); + void param_set_and_write_default(); + void param_update_default(Geom::Point newpoint); + + void param_set_and_write_new_value(Geom::Point newpoint); + + virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + + virtual bool providesKnotHolderEntities() const { return true; } + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + + friend class PointReseteableParamKnotHolderEntity; +private: + PointReseteableParam(const PointReseteableParam&); + PointReseteableParam& operator=(const PointReseteableParam&); + + Geom::Point defvalue; + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; + gchar *handle_tip; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp new file mode 100644 index 000000000..03238f935 --- /dev/null +++ b/src/live_effects/parameter/togglebutton.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Jabiertxo Arraiza Cenoz 2014 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/togglebutton.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "widgets/icon.h" +#include "inkscape.h" +#include "verbs.h" +#include "helper-fns.h" +#include <glibmm/i18n.h> + +namespace Inkscape { + +namespace LivePathEffect { + +ToggleButtonParam::ToggleButtonParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, bool default_value ) + : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value) +{ +} + +ToggleButtonParam::~ToggleButtonParam() +{ +} + +void +ToggleButtonParam::param_set_default() +{ + param_setValue(defvalue); +} + +bool +ToggleButtonParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(helperfns_read_bool(strvalue, defvalue)); + return true; // not correct: if value is unacceptable, should return false! +} + +gchar * +ToggleButtonParam::param_getSVGValue() const +{ + gchar * str = g_strdup(value ? "true" : "false"); + return str; +} + +Gtk::Widget * +ToggleButtonParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredToggleButton * checkwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredToggleButton( param_label, + param_tooltip, + param_key, + *param_wr, + false, + param_effect->getRepr(), + param_effect->getSPDoc()) ); + + checkwdg->setActive(value); + checkwdg->setProgrammatically = false; + checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); + + return dynamic_cast<Gtk::Widget *> (checkwdg); +} + +void +ToggleButtonParam::param_setValue(bool newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h new file mode 100644 index 000000000..9b1c71185 --- /dev/null +++ b/src/live_effects/parameter/togglebutton.h @@ -0,0 +1,56 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TOGGLEBUTTON_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TOGGLEBUTTON_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <glib.h> + +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + + +class ToggleButtonParam : public Parameter { +public: + ToggleButtonParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + bool default_value = false); + virtual ~ToggleButtonParam(); + + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(bool newvalue); + virtual void param_set_default(); + + bool get_value() const { return value; }; + + inline operator bool() const { return value; }; + +private: + ToggleButtonParam(const ToggleButtonParam&); + ToggleButtonParam& operator=(const ToggleButtonParam&); + + bool value; + bool defvalue; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif |
