diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/effect.cpp | 8 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice.cpp | 30 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice2.cpp | 172 | ||||
| -rw-r--r-- | src/live_effects/lpe-offset.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-parallel.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-perspective-envelope.cpp | 24 | ||||
| -rw-r--r-- | src/live_effects/lpe-test-doEffect-stack.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/parameter/point.cpp | 61 | ||||
| -rw-r--r-- | src/live_effects/parameter/point.h | 7 | ||||
| -rw-r--r-- | src/sp-item-group.cpp | 2 | ||||
| -rw-r--r-- | src/sp-lpe-item.cpp | 2 |
11 files changed, 172 insertions, 140 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index bddbd315a..1da364580 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -465,9 +465,11 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) sp_lpe_item = const_cast<SPLPEItem *>(lpeitem); 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(); - + SPShape * shape = dynamic_cast<SPShape *>(sp_lpe_item); + if(shape){ + sp_curve = shape->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); + } doBeforeEffect(lpeitem); } diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index ce0e4941b..c05bae7e1 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -236,21 +236,21 @@ LPELattice::resetDefaults(SPItem const* item) grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); - grid_point1.param_set_and_write_new_value(grid_point1); - grid_point2.param_set_and_write_new_value(grid_point2); - grid_point3.param_set_and_write_new_value(grid_point3); - grid_point4.param_set_and_write_new_value(grid_point4); - grid_point5.param_set_and_write_new_value(grid_point5); - grid_point6.param_set_and_write_new_value(grid_point6); - grid_point7.param_set_and_write_new_value(grid_point7); - grid_point8.param_set_and_write_new_value(grid_point8); - grid_point9.param_set_and_write_new_value(grid_point9); - grid_point10.param_set_and_write_new_value(grid_point10); - grid_point11.param_set_and_write_new_value(grid_point11); - grid_point12.param_set_and_write_new_value(grid_point12); - grid_point13.param_set_and_write_new_value(grid_point13); - grid_point14.param_set_and_write_new_value(grid_point14); - grid_point15.param_set_and_write_new_value(grid_point15); + grid_point1.param_update_default(grid_point1); + grid_point2.param_update_default(grid_point2); + grid_point3.param_update_default(grid_point3); + grid_point4.param_update_default(grid_point4); + grid_point5.param_update_default(grid_point5); + grid_point6.param_update_default(grid_point6); + grid_point7.param_update_default(grid_point7); + grid_point8.param_update_default(grid_point8); + grid_point9.param_update_default(grid_point9); + grid_point10.param_update_default(grid_point10); + grid_point11.param_update_default(grid_point11); + grid_point12.param_update_default(grid_point12); + grid_point13.param_update_default(grid_point13); + grid_point14.param_update_default(grid_point14); + grid_point15.param_update_default(grid_point15); } /** diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index f0a7aee68..53255b3d7 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -23,7 +23,8 @@ #include "sp-path.h" #include "display/curve.h" #include "svg/svg.h" - +#include "helper/geom.h" +#include <2geom/path.h> #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/sbasis-geometric.h> @@ -32,6 +33,9 @@ #include <2geom/d2.h> #include <2geom/piecewise.h> #include <2geom/transforms.h> +#include "ui/tools-switch.h" + +#include "desktop.h" // TODO: should be factored out (see below) using namespace Geom; @@ -107,6 +111,19 @@ LPELattice2::~LPELattice2() Geom::Piecewise<Geom::D2<Geom::SBasis> > LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) { + PathVector pathv = path_from_piecewise(pwd2_in,0.001); + //this is because strange problem whith sb2 and lines + PathVector cubic; + for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) { + cubic.push_back( Geom::Path() ); + cubic.back().start( pit->initialPoint() ); + cubic.back().close( pit->closed() ); + for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); ++cit) { + Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1); + cubic.back().append(cubicbezier_path); + } + } + Geom::Piecewise<Geom::D2<Geom::SBasis> > const &pwd2_in_linear_and_cubic = paths_to_pw(cubic); D2<SBasis2d> sb2; //Initialisation of the sb2 @@ -118,44 +135,45 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd } //Grouping the point params in a convenient vector - std::vector<Geom::Point *> handles(36); + + 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; + 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()); @@ -185,7 +203,7 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd // 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); + 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); } } @@ -195,8 +213,8 @@ LPELattice2::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd Piecewise<D2<SBasis> > output; output.push_cut(0.); - for(unsigned i = 0; i < pwd2_in.size(); i++) { - D2<SBasis> B = pwd2_in[i]; + for(unsigned i = 0; i < pwd2_in_linear_and_cubic.size(); i++) { + D2<SBasis> B = pwd2_in_linear_and_cubic[i]; B[Geom::X] -= origin[Geom::X]; B[Geom::X]*= 1/width; B[Geom::Y] -= origin[Geom::Y]; @@ -264,8 +282,8 @@ LPELattice2::vertical(PointParam ¶mA, PointParam ¶mB, Geom::Line vert){ double distanceMed = (distA + distB)/2; A[Geom::X] = nearest[Geom::X] - distanceMed; B[Geom::X] = nearest[Geom::X] + distanceMed; - paramA.param_set_and_write_new_value(A); - paramB.param_set_and_write_new_value(B); + paramA.param_setValue(A, true); + paramB.param_setValue(B, true); } void @@ -281,14 +299,15 @@ LPELattice2::horizontal(PointParam ¶mA, PointParam ¶mB, Geom::Line horiz double distanceMed = (distA + distB)/2; A[Geom::Y] = nearest[Geom::Y] - distanceMed; B[Geom::Y] = nearest[Geom::Y] + distanceMed; - paramA.param_set_and_write_new_value(A); - paramB.param_set_and_write_new_value(B); + paramA.param_setValue(A, true); + paramB.param_setValue(B, true); } void LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); + setDefaults(); Geom::Line vert(grid_point8x9,grid_point10x11); Geom::Line horiz(grid_point24x26,grid_point25x27); if(verticalMirror){ @@ -315,7 +334,6 @@ LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) horizontal(grid_point17, grid_point19,horiz); horizontal(grid_point20x21, grid_point22x23,horiz); } - setDefaults(); SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -429,34 +447,44 @@ LPELattice2::setDefaults() 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(); + grid_point0.param_set_default(); + grid_point1.param_set_default(); + grid_point2.param_set_default(); + grid_point3.param_set_default(); + grid_point4.param_set_default(); + grid_point5.param_set_default(); + grid_point6.param_set_default(); + grid_point7.param_set_default(); + grid_point8x9.param_set_default(); + grid_point10x11.param_set_default(); + grid_point12.param_set_default(); + grid_point13.param_set_default(); + grid_point14.param_set_default(); + grid_point15.param_set_default(); + grid_point16.param_set_default(); + grid_point17.param_set_default(); + grid_point18.param_set_default(); + grid_point19.param_set_default(); + grid_point20x21.param_set_default(); + grid_point22x23.param_set_default(); + grid_point24x26.param_set_default(); + grid_point25x27.param_set_default(); + grid_point28x30.param_set_default(); + grid_point29x31.param_set_default(); + grid_point32x33x34x35.param_set_default(); + /*todo:this hack is only to reposition the knots on reset grid button + Better update path effect in LPEITEM if(sp_lpe_item){ - sp_lpe_item_update_patheffect(sp_lpe_item, false, false); + sp_lpe_item_update_patheffect(sp_lpe_item, true, true); + SPGroup *group = dynamic_cast<SPGroup *>(sp_lpe_item); + if(group){ + group->requestModified(SP_OBJECT_MODIFIED_FLAG); + } } + */ + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); } void diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 232f1c9db..ba7179476 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -44,7 +44,7 @@ LPEOffset::doOnApply(SPLPEItem const* lpeitem) { Geom::Point offset = *(SP_SHAPE(lpeitem)->_curve->first_point()); offset_pt.param_update_default(offset); - offset_pt.param_set_and_write_new_value(offset); + offset_pt.param_setValue(offset,true); } static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index a1e713fe2..aa7405607 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -74,7 +74,7 @@ LPEParallel::doOnApply (SPLPEItem const* lpeitem) dir = unit_vector(B - A); Geom::Point offset = (A + B)/2 + dir.ccw() * 100; offset_pt.param_update_default(offset); - offset_pt.param_set_and_write_new_value(offset); + offset_pt.param_setValue(offset, true); } Geom::Piecewise<Geom::D2<Geom::SBasis> > diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index e4e75cf4d..f355fa683 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -20,7 +20,9 @@ #include "display/curve.h" #include "svg/svg.h" #include <gsl/gsl_linalg.h> +#include "ui/tools-switch.h" +#include "desktop.h" // TODO: should be factored out (see below) using namespace Geom; @@ -330,13 +332,23 @@ LPEPerspectiveEnvelope::setDefaults() void LPEPerspectiveEnvelope::resetGrid() { - Up_Left_Point.param_set_and_write_default(); - Up_Right_Point.param_set_and_write_default(); - Down_Right_Point.param_set_and_write_default(); - Down_Left_Point.param_set_and_write_default(); + Up_Left_Point.param_set_default(); + Up_Right_Point.param_set_default(); + Down_Right_Point.param_set_default(); + Down_Left_Point.param_set_default(); + /*todo:this hack is only to reposition the knots on reser grid button + Better update path effect in LPEITEM if(sp_lpe_item){ - sp_lpe_item_update_patheffect(sp_lpe_item, false, false); + sp_lpe_item_update_patheffect(sp_lpe_item, true, true); + SPGroup *group = dynamic_cast<SPGroup *>(sp_lpe_item); + if(group){ + group->requestModified(SP_OBJECT_MODIFIED_FLAG); + } } + */ + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); } void @@ -344,8 +356,8 @@ LPEPerspectiveEnvelope::resetDefaults(SPItem const* item) { Effect::resetDefaults(item); original_bbox(SP_LPE_ITEM(item)); - setDefaults(); resetGrid(); + setDefaults(); } void diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 36ab6b547..c6787aae1 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -28,7 +28,7 @@ LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast<Parameter *>(&path) ); point.set_oncanvas_looks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); - point.param_set_and_write_new_value(point); + point.param_setValue(point,true); } LPEdoEffectStackTest::~LPEdoEffectStackTest() diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 319d441b8..30e59a2bd 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -26,8 +26,7 @@ namespace LivePathEffect { PointParam::PointParam( 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), + : Parameter(label, tip, key, wr, effect), defvalue(default_value) { knot_shape = SP_KNOT_SHAPE_DIAMOND; @@ -45,19 +44,26 @@ PointParam::~PointParam() void PointParam::param_set_default() { - param_setValue(defvalue); + param_setValue(defvalue,true); } void -PointParam::param_set_and_write_default() +PointParam::param_update_default(Geom::Point newpoint) { - param_set_and_write_new_value(defvalue); + defvalue = newpoint; } void -PointParam::param_update_default(Geom::Point newpoint) +PointParam::param_setValue(Geom::Point newpoint, bool write) { - this->defvalue = newpoint; + *dynamic_cast<Geom::Point *>( this ) = newpoint; + if(write){ + Inkscape::SVGOStringStream os; + os << newpoint; + gchar * str = g_strdup(os.str().c_str()); + param_write_to_repr(str); + g_free(str); + } } bool @@ -84,6 +90,12 @@ PointParam::param_getSVGValue() const return str; } +void +PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +{ + param_setValue( (*this) * postmul, true); +} + Gtk::Widget * PointParam::param_newWidget() { @@ -110,29 +122,6 @@ PointParam::param_newWidget() } void -PointParam::param_setValue(Geom::Point newpoint) -{ - *dynamic_cast<Geom::Point *>( this ) = newpoint; -} - -void -PointParam::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 -PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) -{ - param_set_and_write_new_value( (*this) * postmul ); -} - - -void PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { knot_shape = shape; @@ -168,8 +157,11 @@ PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &or s = A; } } - pparam->param_setValue(s); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + pparam->param_setValue(s, true); + SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } } Geom::Point @@ -184,7 +176,10 @@ PointParamKnotHolderEntity::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); + SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } } } } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index c4dc096d8..346e79bdd 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -39,13 +39,9 @@ public: 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_setValue(Geom::Point newpoint, bool write = false); 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); @@ -57,7 +53,6 @@ public: private: PointParam(const PointParam&); PointParam& operator=(const PointParam&); - Geom::Point defvalue; SPKnotShapeType knot_shape; SPKnotModeType knot_mode; diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 0c65bbaed..55857dacf 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -843,7 +843,7 @@ void SPGroup::update_patheffect(bool write) { LivePathEffectObject *lpeobj = (*it)->lpeobject; if (lpeobj && lpeobj->get_lpe()) { - lpeobj->get_lpe()->doBeforeEffect(this); + lpeobj->get_lpe()->doBeforeEffect_impl(this); } } diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f059ab531..12d85b3ed 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -263,7 +263,7 @@ bool SPLPEItem::performPathEffect(SPCurve *curve) { } if (!SP_IS_GROUP(this)) { lpe->doAfterEffect(this); - } + } } } } |
