diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-08-05 20:08:24 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-08-05 20:08:24 +0000 |
| commit | 7a19998853ca88c2ff03bcf7e0cbb049b693c106 (patch) | |
| tree | c13350f4dcade109de126fde87151e2978910c79 /src | |
| parent | Added point parameter (diff) | |
| download | inkscape-7a19998853ca88c2ff03bcf7e0cbb049b693c106.tar.gz inkscape-7a19998853ca88c2ff03bcf7e0cbb049b693c106.zip | |
Fix bug on apply effect from pen/pencil toolbar
(bzr r14272.1.2)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-bendpath.cpp | 45 | ||||
| -rw-r--r-- | src/live_effects/lpe-bendpath.h | 6 | ||||
| -rw-r--r-- | src/live_effects/lpe-patternalongpath.cpp | 41 | ||||
| -rw-r--r-- | src/live_effects/lpe-patternalongpath.h | 4 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 44 |
5 files changed, 72 insertions, 68 deletions
diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 364c77ccb..4d72af38c 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -52,13 +52,13 @@ namespace LivePathEffect { LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), bend_path(_("Bend path:"), _("Path along which to bend the original path"), "bendpath", &wr, this, "M0,0 L1,0"), - prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1), + prop_scale(_("_Width:"), _("Width of the path"), "prop_scale", &wr, this, 1.0), + width(_("Width distance"), _("Change the width of bend path - <b>Ctrl+Alt+Click</b>: reset"), "width", &wr, this), scale_y_rel(_("W_idth in units of length"), _("Scale the width of the path in units of its length"), "scale_y_rel", &wr, this, false), vertical_pattern(_("_Original path is vertical"), _("Rotates the original 90 degrees, before bending it along the bend path"), "vertical", &wr, this, false), - width(_("Width distance"), _("Change the width of bend path - <b>Ctrl+Alt+Click</b>: reset"), "width", &wr, this), - height(0), - original_height(0), - prop_scale_previous(1) + height(0.0), + original_height(0.0), + prop_scale_from_widget(1.0) { registerParameter( dynamic_cast<Parameter *>(&bend_path) ); registerParameter( dynamic_cast<Parameter *>(&prop_scale) ); @@ -84,8 +84,6 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); - bool prop_scale_modified = false; - Geom::Path path_in = bend_path.get_pathvector().pathAt(Geom::PathVectorTime(0, 0, 0.0)); Geom::Point ptA = path_in.pointAt(Geom::PathTime(0, 0.0)); Geom::Point B = path_in.pointAt(Geom::PathTime(1, 0.0)); @@ -95,20 +93,29 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) if (cubic) { ray.setPoints((*cubic)[1], ptA); } - if(height == 0){ + //This Hack is to fix a boring bug in the first call to the function, we have + //a wrong "ptA" + if(height == 0.0 && Geom::are_near(width, Geom::Point())){ + height = 0.1; + std::cout << ptA << "ptA0.5\n"; + } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ + Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; + prop_scale.param_set_value(1.0); height = original_height; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - } - if( prop_scale_previous != prop_scale ){ - prop_scale_modified = true; - } - if(!prop_scale_modified){ - prop_scale.param_set_value(height/original_height); + width.param_setValue(default_point); + width.param_update_default(default_point); + } else { + double distance_knot = Geom::distance(width , ptA); + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); + height = distance_knot * 2; + if(prop_scale_from_widget == prop_scale){ + prop_scale.param_set_value(height/original_height); + } else { + height = original_height * prop_scale; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); + } } - height = Geom::distance(width,ptA) * 2; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); - width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale_previous = prop_scale; + prop_scale_from_widget = prop_scale; Geom::Path hp_path(width); hp_path.appendNew<Geom::LineSegment>(ptA); hp.push_back(hp_path); diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 6394ce07e..cb9ced570 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -43,15 +43,15 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec); -private: PathParam bend_path; +private: ScalarParam prop_scale; + PointParam width; BoolParam scale_y_rel; BoolParam vertical_pattern; - PointParam width; double height; double original_height; - double prop_scale_previous; + double prop_scale_from_widget; Geom::Piecewise<Geom::D2<Geom::SBasis> > uskeleton; Geom::Piecewise<Geom::D2<Geom::SBasis> > n; diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 5215f94ec..53730d4d4 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -59,7 +59,8 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"), "copytype", PAPCopyTypeConverter, &wr, this, PAPCT_SINGLE_STRETCHED), - prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1), + prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0), + width(_("Width distance"), _("Change the width of pattern path - <b>Ctrl+Alt+Click</b>: reset"), "width", &wr, this), scale_y_rel(_("Wid_th in units of length"), _("Scale the width of the pattern in units of its length"), "scale_y_rel", &wr, this, false), @@ -76,10 +77,9 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : "vertical_pattern", &wr, this, false), fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."), "fuse_tolerance", &wr, this, 0), - width(_("Width distance"), _("Change the width of pattern path - <b>Ctrl+Alt+Click</b>: reset"), "width", &wr, this), height(0), original_height(0), - prop_scale_previous(1) + prop_scale_from_widget(1) { registerParameter( dynamic_cast<Parameter *>(&pattern) ); registerParameter( dynamic_cast<Parameter *>(©type) ); @@ -109,7 +109,6 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) Geom::OptRect bbox = pattern.get_pathvector().boundsFast(); if (bbox) { original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); - bool prop_scale_modified = false; SPShape const *sp_shape = dynamic_cast<SPShape const *>(lpeitem); if (sp_shape) { Geom::Path const *path_in = sp_shape->getCurveBeforeLPE()->first_path(); @@ -121,21 +120,29 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) if (cubic) { ray.setPoints((*cubic)[1], ptA); } - if(height == 0){ + //This Hack is to fix a boring bug in the first call to the function, we have + //a wrong "ptA" + if(height == 0.0 && Geom::are_near(width, Geom::Point())){ + height = 0.1; + std::cout << ptA << "ptA0.5\n"; + } else if(height == 0.1 && Geom::are_near(width, Geom::Point())){ + Geom::Point default_point = Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA; + prop_scale.param_set_value(1.0); height = original_height; - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale.param_set_value(1); - } - if( prop_scale_previous != prop_scale ){ - prop_scale_modified = true; - } - height = Geom::distance(width,ptA) * 2; - if(!prop_scale_modified){ - prop_scale.param_set_value(height/original_height); + width.param_setValue(default_point); + width.param_update_default(default_point); + } else { + double distance_knot = Geom::distance(width , ptA); + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), distance_knot) + ptA); + height = distance_knot * 2; + if(prop_scale_from_widget == prop_scale){ + prop_scale.param_set_value(height/original_height); + } else { + height = original_height * prop_scale; + width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), height/2.0) + ptA); + } } - width.param_setValue(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), ((original_height*prop_scale)/2.0)) + ptA); - width.param_update_default(Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), (original_height/2.0)) + ptA); - prop_scale_previous = prop_scale; + prop_scale_from_widget = prop_scale; Geom::Path hp_path(width); hp_path.appendNew<Geom::LineSegment>(ptA); hp.push_back(hp_path); diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 440c56548..df0ae9777 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -44,6 +44,7 @@ public: private: EnumParam<PAPCopyType> copytype; ScalarParam prop_scale; + PointParam width; BoolParam scale_y_rel; ScalarParam spacing; ScalarParam normal_offset; @@ -51,10 +52,9 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; - PointParam width; double height; double original_height; - double prop_scale_previous; + double prop_scale_from_widget; Geom::PathVector hp; void on_pattern_pasted(); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index bdce1cd46..6adece54f 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -215,7 +215,7 @@ static Glib::ustring const tool_name(FreehandBase *dc) : "/tools/freehand/pencil" ); } -static void spdc_paste_curve_as_freehand_shape(const SPCurve *c, FreehandBase *dc, SPItem *item) +static void spdc_paste_curve_as_freehand_shape(gchar const *svgd, FreehandBase *dc, SPItem *item) { using namespace Inkscape::LivePathEffect; @@ -223,7 +223,6 @@ static void spdc_paste_curve_as_freehand_shape(const SPCurve *c, FreehandBase *d Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item); Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); - gchar *svgd = sp_svg_write_path(c->get_pathvector()); static_cast<LPEPatternAlongPath*>(lpe)->pattern.paste_param_path(svgd); } @@ -278,10 +277,10 @@ static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *i Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); // write bend parameters: - lpe->getRepr()->setAttribute("bendpath", svgd); lpe->getRepr()->setAttribute("prop_scale", "1"); lpe->getRepr()->setAttribute("scale_y_rel", "false"); lpe->getRepr()->setAttribute("vertical", "false"); + static_cast<LPEBendPath*>(lpe)->bend_path.paste_param_path(svgd); } static void spdc_apply_simplify(std::string threshold, FreehandBase *dc, SPItem *item) @@ -386,7 +385,8 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, c->curveto(SHAPE_LENGTH, (1 + C1) * SHAPE_HEIGHT/2, (1 + C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, SHAPE_LENGTH/2, SHAPE_HEIGHT); c->curveto((1 - C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, 0, (1 + C1) * SHAPE_HEIGHT/2, 0, SHAPE_HEIGHT/2); c->closepath(); - spdc_paste_curve_as_freehand_shape(c, dc, item); + gchar const *svgd = sp_svg_write_path(c->get_pathvector()); + spdc_paste_curve_as_freehand_shape(svgd, dc, item); c->unref(); shape_applied = true; @@ -399,15 +399,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, Glib::ustring svgd = cm->getPathParameter(SP_ACTIVE_DESKTOP); if(svgd != ""){ previous_shape_pathv = sp_svg_read_pathv(svgd.data()); - Inkscape::XML::Node *nv_repr = SP_ACTIVE_DESKTOP->getNamedView()->getRepr(); - if (nv_repr->attribute("inkscape:document-units")){ - double scale_units = Inkscape::Util::Quantity::convert(1, "px", nv_repr->attribute("inkscape:document-units")); - if (!Geom::are_near(scale_units, 1.0, Geom::EPSILON)) { - previous_shape_pathv *= Geom::Scale(scale_units); - } - } - SPCurve const *c = new SPCurve(previous_shape_pathv); - spdc_paste_curve_as_freehand_shape(c, dc, item); + spdc_paste_curve_as_freehand_shape(svgd.data(), dc, item); shape_applied = true; } else { shape = NONE; @@ -419,14 +411,11 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); if(cm->paste(SP_ACTIVE_DESKTOP,true) == true){ gchar const *svgd = item->getRepr()->attribute("d"); - Geom::PathVector path = sp_svg_read_pathv(svgd); - path *= item->i2doc_affine().inverse(); - svgd = sp_svg_write_path( path ); bend_item = dc->selection->singleItem(); if(bend_item){ bend_item->moveTo(item,false); + bend_item->transform = Geom::Affine(1,0,0,1,0,0); spdc_apply_bend_shape(svgd, dc, bend_item); - bend_item->transform = Geom::Affine(1,0,0,1,0,0); dc->selection->add(SP_OBJECT(bend_item)); } else { shape = NONE; @@ -440,32 +429,33 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, { if(previous_shape_type == CLIPBOARD){ if(previous_shape_pathv.size() != 0){ - SPCurve * c = new SPCurve(); - c->set_pathvector(previous_shape_pathv); - spdc_paste_curve_as_freehand_shape(c, dc, item); - c->unref(); + gchar const *svgd = sp_svg_write_path(previous_shape_pathv); + spdc_paste_curve_as_freehand_shape(svgd, dc, item); shape_applied = true; + shape = CLIPBOARD; + } else{ + shape = NONE; } - shape = CLIPBOARD; } else { if(bend_item != NULL && bend_item->getRepr() != NULL){ gchar const *svgd = item->getRepr()->attribute("d"); - Geom::PathVector path = sp_svg_read_pathv(svgd); - path *= item->i2doc_affine().inverse(); - svgd = sp_svg_write_path( path ); dc->selection->add(SP_OBJECT(bend_item)); sp_selection_duplicate(dc->desktop); dc->selection->remove(SP_OBJECT(bend_item)); bend_item = dc->selection->singleItem(); if(bend_item){ bend_item->moveTo(item,false); - spdc_apply_bend_shape(svgd, dc, bend_item); bend_item->transform = Geom::Affine(1,0,0,1,0,0); + spdc_apply_bend_shape(svgd, dc, bend_item); dc->selection->add(SP_OBJECT(bend_item)); + shape = BEND_CLIPBOARD; + } else { + shape = NONE; } + } else { + shape = NONE; } - shape = BEND_CLIPBOARD; } break; } |
