From 0976c402e0e09c4fe9d7d7d6990535e693b16a58 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 30 Oct 2014 20:11:17 +0100 Subject: Fix a bug whith units pointed by suv (bzr r13645.1.2) --- src/live_effects/lpe-fillet-chamfer.cpp | 12 +++++++----- src/live_effects/parameter/filletchamferpointarray.cpp | 9 ++------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f15bf9215..8a8f68d80 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -34,6 +34,7 @@ #include "ui/tool/selectable-control-point.h" #include "ui/tool/node.h" #include "ui/tools/node-tool.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -172,9 +173,9 @@ void LPEFilletChamfer::toggleHide() for (std::vector::const_iterator point_it = filletChamferData.begin(); point_it != filletChamferData.end(); ++point_it) { if (hide_knots) { - result.push_back(Point((*point_it)[X], abs((*point_it)[Y]) * -1)); + result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); } else { - result.push_back(Point((*point_it)[X], abs((*point_it)[Y]))); + result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); } } fillet_chamfer_values.param_set_and_write_new_value(result); @@ -211,7 +212,8 @@ void LPEFilletChamfer::updateFillet() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), "px") * -1; + Inkscape::Util::Unit const *doc_units = inkscape_active_desktop()->namedview->doc_units; + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), doc_units->abbr) * -1; } else { power = radius; } @@ -589,11 +591,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } int type = 0; if(path_it->closed() && last){ - type = abs(filletChamferData[counter - counterCurves][Y]); + type = std::abs(filletChamferData[counter - counterCurves][Y]); } else if (!path_it->closed() && last){ //0 } else { - type = abs(filletChamferData[counter + 1][Y]); + type = std::abs(filletChamferData[counter + 1][Y]); } if (type == 3 || type == 4) { if (type == 4) { diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index e2b1aba61..db24a9735 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -175,13 +175,8 @@ void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( last_pathv[counterPaths][counter - offset].initialPoint(), 0.1))) { if ( curve_it2 == curve_endit) { - if (last_pathv[counterPaths].size() < pathv[counterPaths].size()) { - offset = abs(last_pathv[counterPaths].size() - - pathv[counterPaths].size()); - } else if (last_pathv[counterPaths].size() > - pathv[counterPaths].size()) { - offset = (abs(last_pathv[counterPaths].size() - - pathv[counterPaths].size())) * -1; + if (last_pathv[counterPaths].size() != pathv[counterPaths].size()) { + offset = (last_pathv[counterPaths].size() - pathv[counterPaths].size()) * -1; } else { offset = 0; } -- cgit v1.2.3 From 86891a9e442c81435c6d197cb09b3dc210643bc0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Feb 2015 16:40:25 +0100 Subject: starting whith pointwise (bzr r13645.1.7) --- src/live_effects/CMakeLists.txt | 2 + src/live_effects/lpe-fillet-chamfer.cpp | 585 +---------------------------- src/live_effects/lpe-fillet-chamfer.h | 41 +- src/live_effects/parameter/Makefile_insert | 2 + src/live_effects/parameter/array.cpp | 32 ++ src/live_effects/parameter/array.h | 9 +- src/live_effects/parameter/pointwise.cpp | 104 +++++ src/live_effects/parameter/pointwise.h | 88 +++++ 8 files changed, 253 insertions(+), 610 deletions(-) create mode 100644 src/live_effects/parameter/pointwise.cpp create mode 100644 src/live_effects/parameter/pointwise.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c8a02c810..e171e99e3 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -63,6 +63,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp + parameter/pointwise.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -139,6 +140,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h + parameter/pointwise.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d2bdf2d8d..f4eb4f46e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -13,23 +13,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/lpe-fillet-chamfer.h" - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/line.h> -#include "desktop.h" -#include "display/curve.h" -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" -#include "helper/geom.h" - -#include "live_effects/parameter/filletchamferpointarray.h" - -// for programmatically updating knots -#include "ui/tools-switch.h" -#include +#include "live_effects/parameter/pointwise.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -38,348 +23,23 @@ using namespace Geom; namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, - { FM_ARC, N_("Force arc"), "arc" }, - { FM_BEZIER, N_("Force bezier"), "bezier" } -}; -static const Util::EnumDataConverter -FMConverter(FilletMethodData, FM_END); - -const double tolerance = 0.001; -const double gapHelper = 0.00001; - LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fillet_chamfer_values(_("Fillet point"), _("Fillet point"), "fillet_chamfer_values", &wr, this), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 0), - - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0) + pointwise_values(_("Fillet point"), _("Fillet point"), "pointwise_values", &wr, this) { - registerParameter(&fillet_chamfer_values); - registerParameter(&unit); - registerParameter(&method); - registerParameter(&radius); - registerParameter(&chamfer_steps); - registerParameter(&helper_size); - registerParameter(&flexible); - registerParameter(&use_knot_distance); - registerParameter(&ignore_radius_0); - registerParameter(&only_selected); - registerParameter(&hide_knots); - - radius.param_set_range(0., infinity()); - radius.param_set_increments(1, 1); - radius.param_set_digits(4); - chamfer_steps.param_set_range(1, 999); - chamfer_steps.param_set_increments(1, 1); - chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, infinity()); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); - fillet_chamfer_values.set_chamfer_steps(3); + registerParameter(&pointwise_values); } LPEFilletChamfer::~LPEFilletChamfer() {} -Gtk::Widget *LPEFilletChamfer::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "radius") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(6); - } - } else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); - } - } else if (param->param_key == "flexible") { - Gtk::CheckButton *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::toggleFlexFixed)); - } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "hide_knots") { - Gtk::CheckButton *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::toggleHide)); - } else if (param->param_key == "only_selected") { - Gtk::manage(widg); - } else if (param->param_key == "ignore_radius_0") { - Gtk::manage(widg); - } - - 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; - } - Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); - fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); - - filletContainer->pack_start(*fillet, true, true, 2); - Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); - inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); - filletContainer->pack_start(*inverseFillet, true, true, 2); - - Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); - chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); - - chamferContainer->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); - inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); - chamferContainer->pack_start(*inverseChamfer, true, true, 2); - - vbox->pack_start(*filletContainer, true, true, 2); - vbox->pack_start(*chamferContainer, true, true, 2); - - return vbox; -} - -void LPEFilletChamfer::toggleHide() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (hide_knots) { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); - } else { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); - refreshKnots(); -} - -void LPEFilletChamfer::toggleFlexFixed() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - unsigned int i = 0; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (flexible) { - result.push_back(Point(fillet_chamfer_values.to_time(i, (*point_it)[X]), - (*point_it)[Y])); - } else { - result.push_back(Point(fillet_chamfer_values.to_len(i, (*point_it)[X]), - (*point_it)[Y])); - } - i++; - } - if (flexible) { - radius.param_set_range(0., 100); - radius.param_set_value(0); - } else { - radius.param_set_range(0., infinity()); - radius.param_set_value(0); - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::updateFillet() -{ - double power = 0; - if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit) * -1; - } else { - power = radius; - } - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doUpdateFillet(path_from_piecewise(pwd2, tolerance), power); -} - -void LPEFilletChamfer::fillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 1); -} - -void LPEFilletChamfer::inverseFillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 2); -} - -void LPEFilletChamfer::chamferSubdivisions() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 5000); -} - -void LPEFilletChamfer::chamfer() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 3000); -} - -void LPEFilletChamfer::inverseChamfer() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 4000); -} - -void LPEFilletChamfer::refreshKnots() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - fillet_chamfer_values.recalculate_knots(pwd2); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); - } -} - -void LPEFilletChamfer::doUpdateFillet(std::vector const& original_pathv, double power) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - std::vector original_pathv_processed = pathv_to_linear_and_cubic_beziers(original_pathv); - int counter = 0; - for (PathVector::const_iterator path_it = original_pathv_processed.begin(); - path_it != original_pathv_processed.end(); ++path_it) { - if (path_it->empty()) - continue; - - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - double powerend = 0; - while (curve_it1 != curve_endit) { - powerend = power; - if (power < 0 && !use_knot_distance) { - powerend = fillet_chamfer_values.rad_to_len(counter,powerend); - } - if (power > 0) { - powerend = counter + (power / 100); - } - if (ignore_radius_0 && (filletChamferData[counter][X] == 0 || - filletChamferData[counter][X] == counter)) { - powerend = filletChamferData[counter][X]; - } - if (filletChamferData[counter][Y] == 0) { - powerend = filletChamferData[counter][X]; - } - if (only_selected && !isNodePointSelected(curve_it1->initialPoint())) { - powerend = filletChamferData[counter][X]; - } - result.push_back(Point(powerend, filletChamferData[counter][Y])); - ++curve_it1; - ++curve_it2; - counter++; - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::doChangeType(std::vector const& original_pathv, int type) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - std::vector original_pathv_processed = pathv_to_linear_and_cubic_beziers(original_pathv); - int counter = 0; - for (PathVector::const_iterator path_it = original_pathv_processed.begin(); path_it != original_pathv_processed.end(); ++path_it) { - int pathCounter = 0; - if (path_it->empty()) - continue; - - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - bool toggle = true; - if (filletChamferData[counter][Y] == 0 || - (ignore_radius_0 && (filletChamferData[counter][X] == 0 || - filletChamferData[counter][X] == counter)) || - (only_selected && !isNodePointSelected(curve_it1->initialPoint()))) { - toggle = false; - } - if (toggle) { - if(type >= 5000){ - if(filletChamferData[counter][Y] >= 3000 && filletChamferData[counter][Y] < 4000){ - type = type - 2000; - } else if (filletChamferData[counter][Y] >= 4000 && filletChamferData[counter][Y] < 5000){ - type = type - 1000; - } - } - result.push_back(Point(filletChamferData[counter][X], type)); - } else { - result.push_back(filletChamferData[counter]); - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - pathCounter++; - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - if (SP_IS_SHAPE(lpeItem)) { - std::vector point; - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeItem)->_curve->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + SPShape * shape = dynamic_cast(lpeItem); + if (shape) { + std::vector pointwise; + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->gerCurve->get_pathvector()); + //Piecewise > pwd2_in = paths_to_pw(original_pathv); for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) continue; @@ -401,25 +61,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } int counter = 0; while (curve_it1 != curve_endit) { - std::pair positions = fillet_chamfer_values.get_positions(counter, original_pathv); + Geom::Saltellite sat(FILLET, true, true, false, false, false, 0, 0.2); + std::pair positions = pointwise_values.get_positions(counter, original_pathv); Geom::NodeType nodetype; if (positions.second == 0) { - if (path_it->closed()) { - Piecewise > u; - u.push_cut(0); - u.push(pwd2_in[fillet_chamfer_values.last_index(counter, original_pathv)], 1); - Geom::Curve const * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); - nodetype = get_nodetype(*A, *curve_it1); - } else { - nodetype = NODE_NONE; - } + nodetype = NODE_NONE; } else { nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == NODE_CUSP) { - point.push_back(Point(0, 1)); - } else { - point.push_back(Point(0, 0)); + pointwise.push_back(std::pair); } ++curve_it1; if (curve_it2 != curve_endit) { @@ -428,222 +79,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counter++; } } - fillet_chamfer_values.param_set_and_write_new_value(point); + pointwise_values.param_set_and_write_new_value(pointwise); } else { - g_warning("LPE Fillet can only be applied to shapes (not groups)."); + g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); item->removeCurrentPathEffect(false); } } -void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) -{ - if (SP_IS_SHAPE(lpeItem)) { - if(hide_knots){ - fillet_chamfer_values.set_helper_size(0); - } else { - fillet_chamfer_values.set_helper_size(helper_size); - } - fillet_chamfer_values.set_document_unit(defaultUnit); - fillet_chamfer_values.set_use_distance(use_knot_distance); - fillet_chamfer_values.set_unit(unit.get_abbreviation()); - SPCurve *c = SP_IS_PATH(lpeItem) ? static_cast(lpeItem) - ->get_original_curve() - : SP_SHAPE(lpeItem)->getCurve(); - std::vector filletChamferData = fillet_chamfer_values.data(); - if (!filletChamferData.empty() && getKnotsNumber(c) != (int) - filletChamferData.size()) { - PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); - fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pwd2_in); - } - } else { - g_warning("LPE Fillet can only be applied to shapes (not groups)."); - } -} - -int LPEFilletChamfer::getKnotsNumber(SPCurve const *c) -{ - int nKnots = c->nodes_in_path(); - PathVector const pv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - for (std::vector::const_iterator path_it = pv.begin(); - path_it != pv.end(); ++path_it) { - if (!(*path_it).closed()) { - nKnots--; - } - } - return nKnots; -} - -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty()) { - fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - } -} - -std::vector -LPEFilletChamfer::doEffect_path(std::vector const &path_in) -{ - std::vector pathvector_out; - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); - pwd2_in = remove_short_cuts(pwd2_in, .01); - Piecewise > der = derivative(pwd2_in); - Piecewise > n = rot90(unitVector(der)); - fillet_chamfer_values.set_pwd2(pwd2_in, n); - std::vector filletChamferData = fillet_chamfer_values.data(); - unsigned int counter = 0; - const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); - path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path path_out; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - 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(); - } - } - unsigned int counterCurves = 0; - while (curve_it1 != curve_endit) { - Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); - if(!path_it->closed() || curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - } - bool last = curve_it2 == curve_endit; - std::vector times = fillet_chamfer_values.get_times(counter, path_in, last); - Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); - if (counterCurves > 0) { - knotCurve1->setInitial(path_out.finalPoint()); - } else { - path_out.start((*curve_it1).pointAt(times[0])); - } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); - Point startArcPoint = knotCurve1->finalPoint(); - Point endArcPoint = curve_it2Fixed->pointAt(times[2]); - double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, curve_it1->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(curve_it1->finalPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); - bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double angle = angle_between(ray1, ray2, ccwToggle); - double handleAngle = ray1.angle() - angle; - if (ccwToggle) { - handleAngle = ray1.angle() + angle; - } - Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; - handleAngle = ray2.angle() + angle; - if (ccwToggle) { - handleAngle = ray2.angle() - angle; - } - Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - //straigth lines arc based - Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); - Line const angled_line(startArcPoint,endArcPoint); - double angleArc = Geom::angle_between( x_line,angled_line); - double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); - Coord rx = radius; - Coord ry = rx; - - if (times[1] != 1) { - if (times[1] != gapHelper && times[1] != times[0] + gapHelper) { - path_out.append(*knotCurve1); - } - int type = 0; - if(path_it->closed() && last){ - type = std::abs(filletChamferData[counter - counterCurves][Y]); - } else if (!path_it->closed() && last){ - //0 - } else { - type = std::abs(filletChamferData[counter + 1][Y]); - } - if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - path_out.appendNew(endArcPoint); - } else if (type >= 3000 && type < 4000) { - unsigned int chamferSubs = type-3000; - Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); - } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); - } - path_out.appendNew(endArcPoint); - } else if (type >= 4000 && type < 5000) { - unsigned int chamferSubs = type-4000; - Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); - } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); - } - path_out.appendNew(endArcPoint); - } else if (type == 2) { - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); - } - } else if (type == 1){ - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - } else { - path_out.appendNew(handle1, handle2, endArcPoint); - } - } - } else { - path_out.append(*knotCurve1); - } - if (path_it->closed() && last) { - path_out.close(); - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - counterCurves++; - } - pathvector_out.push_back(path_out); - } - return pathvector_out; -} }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 0d6a1ff17..f4462d154 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -27,58 +27,23 @@ #include "live_effects/parameter/bool.h" #include "live_effects/parameter/unit.h" -#include "live_effects/parameter/filletchamferpointarray.h" +#include "live_effects/parameter/pointwise.h" #include "live_effects/effect.h" namespace Inkscape { namespace LivePathEffect { -enum FilletMethod { - FM_AUTO, - FM_ARC, - FM_BEZIER, - FM_END -}; class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); - virtual std::vector doEffect_path(std::vector const &path_in); - virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget* newWidget(); - - int getKnotsNumber(SPCurve const *c); - void toggleHide(); - void toggleFlexFixed(); - void chamfer(); - void chamferSubdivisions(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - void updateFillet(); - void doUpdateFillet(std::vector const& original_pathv, double power); - void doChangeType(std::vector const& original_pathv, int type); - void refreshKnots(); - - FilletChamferPointArrayParam fillet_chamfer_values; -private: + PointwiseArrayParam pointwise_values; - BoolParam hide_knots; - BoolParam ignore_radius_0; - BoolParam only_selected; - BoolParam flexible; - BoolParam use_knot_distance; - UnitParam unit; - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - ScalarParam helper_size; +private: LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index f990f41c7..d78b1e22f 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -26,6 +26,8 @@ ink_common_sources += \ live_effects/parameter/powerstrokepointarray.h \ live_effects/parameter/filletchamferpointarray.cpp \ live_effects/parameter/filletchamferpointarray.h \ + live_effects/parameter/pointwise.cpp \ + live_effects/parameter/pointwise.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 1b8f742da..bd2bf1870 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -48,6 +48,38 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } +void +sp_svg_satellite_read_d(gchar const *str, satellite *sat){ + gchar ** strarray = g_strsplit(str, "*", 0); + if(strarray.size() != 6){ + g_strfreev (strarray); + return NULL; + } + sat->setSatelliteType(SatelliteTypeMap[strarray[0]]); + sat->setActive(helperfns_read_bool(strarray[1], true)); + sat->sethasMirror(helperfns_read_bool(strarray[2], false)); + sat->setHidden(helperfns_read_bool(strarray[3], false)); + sat->setHidden(helperfns_read_bool(strarray[3], false)); + sat->setTime(sp_svg_number_read_d(strarray[4], 0.0)); + sat->setSize(sp_svg_number_read_d(strarray[5], 0.0)); + g_strfreev (strarray); +} + +template <> +std::pair +ArrayParam::readsvg(const gchar * str) +{ + gchar ** strarray = g_strsplit(str, ",", 2); + int index; + Geom::satellite sat = NULL; + unsigned int success = sp_svg_number_read_d(strarray[0], &index); + success += sp_svg_satellite_read_d(strarray[1], &sat); + g_strfreev (strarray); + if (success == 2) { + return std::pair; + } + return std::pair; +} } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a600f0257..b93c7a617 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -93,7 +93,14 @@ protected: // separate items with pipe symbol str << " | "; } - str << vector[i]; + std::pair pointwiseElement = dynamic_cast ><(_vector[i]); + if(pointwiseElement){ + str << vector[i].first; + str << " , "; + str << vector[i].second; + } else { + str << vector[i]; + } } } diff --git a/src/live_effects/parameter/pointwise.cpp b/src/live_effects/parameter/pointwise.cpp new file mode 100644 index 000000000..ec83eb6c7 --- /dev/null +++ b/src/live_effects/parameter/pointwise.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" + +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +PointwiseParam::PointwiseParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; +} + +PointwiseParam::~PointwiseParam() {} + +Gtk::Widget *PointwiseParam::param_newWidget() +{ + return NULL; +} + +void PointwiseParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +PointwiseParamKnotHolderEntity:: +PointwiseParamKnotHolderEntity( + PointwiseParam *p) + : _pparam(p) {} + +void PointwiseParamKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point const s = snap_knot_position(p, state); + _pparam->_vector.at(_index).second.setPosition(s,_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); +} + +Point PointwiseParamKnotHolderEntity::knot_get() const +{ + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); + _pparam->updateCanvasIndicators(); + return canvas_point; +} + + +void PointwiseParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + for (unsigned int i = 0; i < _pointwise.satellites.size(); ++i) { + const gchar *tip; + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + PointwiseParamKnotHolderEntity *e = + new PointwiseParamKnotHolderEntity(this, i); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } + updateCanvasIndicators(); +} + +} /* 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/pointwise.h b/src/live_effects/parameter/pointwise.h new file mode 100644 index 000000000..59f1b4ff4 --- /dev/null +++ b/src/live_effects/parameter/pointwise.h @@ -0,0 +1,88 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_POINTWISE_H +#define INKSCAPE_LIVEPATHEFFECT_POINTWISE_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include "knot-holder-entity.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class PointwiseParamKnotHolderEntity; + +class PointwiseParam : public ArrayParam { +public: + PointwiseParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~PointwiseParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + virtual bool providesKnotHolderEntities() const { + return true; + } + friend class PointwiseParamKnotHolderEntity; + +protected: + + StorageType readsvg(const gchar * str); + +private: + PointwiseParam(const PointwiseParam &); + PointwiseParam &operator=(const PointwiseParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; +}; + +class PointwiseParamKnotHolderEntity : public KnotHolderEntity { +public: + PointwiseParamKnotHolderEntity(PointwiseParam *p, + unsigned int index); + virtual ~PointwiseParamKnotHolderEntity() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, + guint state); + virtual Geom::Point knot_get() const; + + /*Checks whether the index falls within the size of the parameter's vector*/ + bool valid_index(unsigned int index) const { + return (_pparam->_vector.size() > index); + } + ; + +private: + PointwiseParam *_pparam; + unsigned int _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 99fb2239028e72f8773bff39e43f7af33b4252d4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:29:48 +0100 Subject: first steps (bzr r13645.1.9) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 54 ++++++++++----- src/live_effects/lpe-fillet-chamfer.h | 18 ++--- src/live_effects/parameter/Makefile_insert | 4 +- src/live_effects/parameter/array.cpp | 51 ++++++++------ src/live_effects/parameter/array.h | 43 +++++++++--- src/live_effects/parameter/pointwise.cpp | 104 ----------------------------- src/live_effects/parameter/pointwise.h | 88 ------------------------ 8 files changed, 110 insertions(+), 256 deletions(-) delete mode 100644 src/live_effects/parameter/pointwise.cpp delete mode 100644 src/live_effects/parameter/pointwise.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index e171e99e3..6b004e1df 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -63,7 +63,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/pointwise.cpp + parameter/satellitepairarray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -140,7 +140,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/pointwise.h + parameter/satellitepairarray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f4eb4f46e..884e51ffd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -14,20 +14,28 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/pointwise.h" +#include "live_effects/lpe-fillet-chamfer.h" +#include +#include <2geom/pointwise.h> +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include "helper/geom-nodetype.h" +#include "helper/geom.h" +#include "display/curve.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; + namespace Inkscape { namespace LivePathEffect { LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pointwise_values(_("Fillet point"), _("Fillet point"), "pointwise_values", &wr, this) + satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this) { - registerParameter(&pointwise_values); + registerParameter(&satellitepairarrayparam_values); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -35,12 +43,17 @@ LPEFilletChamfer::~LPEFilletChamfer() {} void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - SPShape * shape = dynamic_cast(lpeItem); + SPLPEItem * splpeitem = const_cast(lpeItem); + SPShape * shape = dynamic_cast(splpeitem); if (shape) { - std::vector pointwise; - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->gerCurve->get_pathvector()); - //Piecewise > pwd2_in = paths_to_pw(original_pathv); - for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + Geom::PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + std::vector > satellites; + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); + pwd2_in = remove_short_cuts(pwd2_in, .01); + Geom::Piecewise > der = derivative(pwd2_in); + Geom::Piecewise > n = rot90(unitVector(der)); + satellitepairarrayparam_values.set_pwd2(pwd2_in, n); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) continue; @@ -61,16 +74,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } int counter = 0; while (curve_it1 != curve_endit) { - Geom::Saltellite sat(FILLET, true, true, false, false, false, 0, 0.2); - std::pair positions = pointwise_values.get_positions(counter, original_pathv); + Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); Geom::NodeType nodetype; - if (positions.second == 0) { - nodetype = NODE_NONE; - } else { + if(counter!=0){ nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); + } else { + nodetype = Geom::NODE_NONE; } - if (nodetype == NODE_CUSP) { - pointwise.push_back(std::pair); + if (nodetype == Geom::NODE_CUSP) { + satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; if (curve_it2 != curve_endit) { @@ -79,7 +91,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counter++; } } - pointwise_values.param_set_and_write_new_value(pointwise); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -87,6 +99,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +{ + if (!path_in.empty()) { + //fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + } +} + }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f4462d154..08000c0a5 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,19 +15,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(GLIBMM_DISABLE_DEPRECATED) && defined(HAVE_GLIBMM_THREADS_H) -# include -#endif - -#include "live_effects/parameter/enum.h" -#include "live_effects/parameter/bool.h" -#include "live_effects/parameter/unit.h" - -#include "live_effects/parameter/pointwise.h" +#include "2geom/pointwise.h" +#include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" namespace Inkscape { @@ -40,8 +29,9 @@ public: virtual ~LPEFilletChamfer(); virtual void doOnApply(SPLPEItem const *lpeItem); + virtual void adjustForNewPath(std::vector const &path_in); - PointwiseArrayParam pointwise_values; + SatellitePairArrayParam satellitepairarrayparam_values; private: diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index d78b1e22f..33c6b0673 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -26,8 +26,8 @@ ink_common_sources += \ live_effects/parameter/powerstrokepointarray.h \ live_effects/parameter/filletchamferpointarray.cpp \ live_effects/parameter/filletchamferpointarray.h \ - live_effects/parameter/pointwise.cpp \ - live_effects/parameter/pointwise.h \ + live_effects/parameter/satellitepairarray.cpp \ + live_effects/parameter/satellitepairarray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index bd2bf1870..d17f28c4f 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -6,8 +6,7 @@ #include "live_effects/parameter/array.h" -#include "svg/svg.h" -#include "svg/stringstream.h" +#include "helper-fns.h" #include <2geom/coord.h> #include <2geom/point.h> @@ -48,37 +47,47 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -void -sp_svg_satellite_read_d(gchar const *str, satellite *sat){ - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray.size() != 6){ +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, " * ", 0); + if(strarray[6] && !strarray[7]){ + std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; + sat->setSatelliteType(gts[strarray[0]]); + sat->setIsTime(helperfns_read_bool(strarray[1], true)); + sat->setActive(helperfns_read_bool(strarray[2], true)); + sat->setHasMirror(helperfns_read_bool(strarray[3], false)); + sat->setHidden(helperfns_read_bool(strarray[4], false)); + double time,size; + sp_svg_number_read_d(strarray[5], &time); + sp_svg_number_read_d(strarray[6], &size); + sat->setTime(time); + sat->setSize(size); g_strfreev (strarray); - return NULL; + return 1; } - sat->setSatelliteType(SatelliteTypeMap[strarray[0]]); - sat->setActive(helperfns_read_bool(strarray[1], true)); - sat->sethasMirror(helperfns_read_bool(strarray[2], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setTime(sp_svg_number_read_d(strarray[4], 0.0)); - sat->setSize(sp_svg_number_read_d(strarray[5], 0.0)); g_strfreev (strarray); + return 0; } template <> -std::pair -ArrayParam::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); - int index; - Geom::satellite sat = NULL; - unsigned int success = sp_svg_number_read_d(strarray[0], &index); + double index; + std::pair result; + unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); + Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); g_strfreev (strarray); if (success == 2) { - return std::pair; + return std::make_pair(index, sat); } - return std::pair; + return std::make_pair((int)Geom::infinity(),sat); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index b93c7a617..9f26ed3e6 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,6 +15,9 @@ #include "live_effects/parameter/parameter.h" +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include <2geom/pointwise.h> #include "svg/svg.h" #include "svg/stringstream.h" @@ -93,16 +96,40 @@ protected: // separate items with pipe symbol str << " | "; } - std::pair pointwiseElement = dynamic_cast ><(_vector[i]); - if(pointwiseElement){ - str << vector[i].first; - str << " , "; - str << vector[i].second; - } else { - str << vector[i]; - } + writesvgData(str,vector[i]); } } + + void writesvgData(SVGOStringStream &str, float const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, double const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, Geom::Point const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + str << nVector.first; + str << " , "; + std::map stg = nVector.second.SatelliteTypeToGcharMap; + str << stg[nVector.second.satellitetype()]; + str << " * "; + str << nVector.second.isTime(); + str << " * "; + str << nVector.second.active(); + str << " * "; + str << nVector.second.hasMirror(); + str << " * "; + str << nVector.second.hidden(); + str << " * "; + str << nVector.second.size(); + str << " * "; + str < - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" - -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -PointwiseParam::PointwiseParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; -} - -PointwiseParam::~PointwiseParam() {} - -Gtk::Widget *PointwiseParam::param_newWidget() -{ - return NULL; -} - -void PointwiseParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -PointwiseParamKnotHolderEntity:: -PointwiseParamKnotHolderEntity( - PointwiseParam *p) - : _pparam(p) {} - -void PointwiseParamKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Point PointwiseParamKnotHolderEntity::knot_get() const -{ - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - _pparam->updateCanvasIndicators(); - return canvas_point; -} - - -void PointwiseParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - for (unsigned int i = 0; i < _pointwise.satellites.size(); ++i) { - const gchar *tip; - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - PointwiseParamKnotHolderEntity *e = - new PointwiseParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - updateCanvasIndicators(); -} - -} /* 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/pointwise.h b/src/live_effects/parameter/pointwise.h deleted file mode 100644 index 59f1b4ff4..000000000 --- a/src/live_effects/parameter/pointwise.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_POINTWISE_H -#define INKSCAPE_LIVEPATHEFFECT_POINTWISE_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class PointwiseParamKnotHolderEntity; - -class PointwiseParam : public ArrayParam { -public: - PointwiseParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~PointwiseParam(); - - virtual Gtk::Widget * param_newWidget() { - return NULL; - } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual bool providesKnotHolderEntities() const { - return true; - } - friend class PointwiseParamKnotHolderEntity; - -protected: - - StorageType readsvg(const gchar * str); - -private: - PointwiseParam(const PointwiseParam &); - PointwiseParam &operator=(const PointwiseParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; -}; - -class PointwiseParamKnotHolderEntity : public KnotHolderEntity { -public: - PointwiseParamKnotHolderEntity(PointwiseParam *p, - unsigned int index); - virtual ~PointwiseParamKnotHolderEntity() {} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, - guint state); - virtual Geom::Point knot_get() const; - - /*Checks whether the index falls within the size of the parameter's vector*/ - bool valid_index(unsigned int index) const { - return (_pparam->_vector.size() > index); - } - ; - -private: - PointwiseParam *_pparam; - unsigned int _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif -- cgit v1.2.3 From 3ff9b36f48101c62c460622dd683a582e5dc17ca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:31:04 +0100 Subject: first steps (bzr r13645.1.10) --- src/live_effects/parameter/satellitepairarray.cpp | 114 ++++++++++++++++++++++ src/live_effects/parameter/satellitepairarray.h | 95 ++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 src/live_effects/parameter/satellitepairarray.cpp create mode 100644 src/live_effects/parameter/satellitepairarray.h (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp new file mode 100644 index 000000000..f4f79b485 --- /dev/null +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "live_effects/parameter/satellitepairarray.h" +#include "sp-lpe-item.h" +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +SatellitePairArrayParam::SatellitePairArrayParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam >(label, tip, key, wr, effect, 0) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; +} + +SatellitePairArrayParam::~SatellitePairArrayParam() {} + +void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +void SatellitePairArrayParam::set_pwd2( + Piecewise > const &pwd2_in, + Piecewise > const &pwd2_normal_in) +{ + last_pwd2 = pwd2_in; + last_pwd2_normal = pwd2_normal_in; +} + +void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + for (unsigned int i = 0; i < _vector.size(); ++i) { + const gchar *tip; + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + SatellitePairArrayParamKnotHolderEntity *e = + new SatellitePairArrayParamKnotHolderEntity(this, i); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } +} + + +SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) + : _pparam(p), + _index(index) +{ +} + + + +void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point const s = snap_knot_position(p, state); + _pparam->_vector.at(_index).second.setPosition(s,_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +Geom::Point +SatellitePairArrayParamKnotHolderEntity::knot_get() const +{ + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).second]); + return canvas_point; +} + + +} /* 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/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h new file mode 100644 index 000000000..82d04c790 --- /dev/null +++ b/src/live_effects/parameter/satellitepairarray.h @@ -0,0 +1,95 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include "live_effects/parameter/array.h" +#include "knot-holder-entity.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class SatellitePairArrayParamKnotHolderEntity; + +class SatellitePairArrayParam : public ArrayParam > { +public: + SatellitePairArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~SatellitePairArrayParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + 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); + void set_pwd2(Geom::Piecewise > const &pwd2_in, + Geom::Piecewise > const &pwd2_normal_in); + Geom::Piecewise > const &get_pwd2() const { + return last_pwd2; + } + Geom::Piecewise > const &get_pwd2_normal() const { + return last_pwd2_normal; + } + friend class SatellitePairArrayParamKnotHolderEntity; + +private: + SatellitePairArrayParam(const SatellitePairArrayParam &); + SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; + + Geom::Piecewise > last_pwd2; + Geom::Piecewise > last_pwd2_normal; + +}; + +class SatellitePairArrayParamKnotHolderEntity : public KnotHolderEntity { +public: + SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + virtual ~SatellitePairArrayParamKnotHolderEntity() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + + /** Checks whether the index falls within the size of the parameter's vector */ + bool valid_index(unsigned int index) const { + return (_pparam->_vector.size() > index); + }; + +private: + SatellitePairArrayParam *_pparam; + unsigned int _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 5c3350ef1281298f25c1cbcb60a66d238a417030 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 00:12:00 +0100 Subject: added knots (bzr r13645.1.12) --- src/live_effects/lpe-fillet-chamfer.cpp | 20 +++++++++++--------- src/live_effects/parameter/array.cpp | 2 +- src/live_effects/parameter/array.h | 14 +++++++------- src/live_effects/parameter/satellitepairarray.cpp | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 884e51ffd..5d6358bb2 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -54,11 +54,10 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Piecewise > n = rot90(unitVector(der)); satellitepairarrayparam_values.set_pwd2(pwd2_in, n); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) + if (path_it->empty()){ continue; - + } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); @@ -72,22 +71,25 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) curve_endit = path_it->end_open(); } } + Geom::Path::const_iterator curve_end = curve_endit; + --curve_end; int counter = 0; while (curve_it1 != curve_endit) { Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); Geom::NodeType nodetype; - if(counter!=0){ - nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); + if (counter==0) { + if (path_it->closed()) { + nodetype = Geom::get_nodetype(*curve_end, *curve_it1); + } else { + nodetype = Geom::NODE_NONE; + } } else { - nodetype = Geom::NODE_NONE; + nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == Geom::NODE_CUSP) { satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } counter++; } } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d17f28c4f..d1d718b08 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -53,7 +53,7 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, " * ", 0); + gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; sat->setSatelliteType(gts[strarray[0]]); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 9f26ed3e6..ba1ed3d4e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -114,20 +114,20 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; - str << " , "; + str << ","; std::map stg = nVector.second.SatelliteTypeToGcharMap; str << stg[nVector.second.satellitetype()]; - str << " * "; + str << "*"; str << nVector.second.isTime(); - str << " * "; + str << "*"; str << nVector.second.active(); - str << " * "; + str << "*"; str << nVector.second.hasMirror(); - str << " * "; + str << "*"; str << nVector.second.hidden(); - str << " * "; + str << "*"; str << nVector.second.size(); - str << " * "; + str << "*"; str <_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).second]); + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).first]); return canvas_point; } -- cgit v1.2.3 From 9593c78703845bfca18a3a135cbbc47cc03b54f6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 21:49:53 +0100 Subject: continuing fillet/chamfer (bzr r13645.1.13) --- src/live_effects/lpe-fillet-chamfer.cpp | 228 ++++++++++++++++++++-- src/live_effects/lpe-fillet-chamfer.h | 14 +- src/live_effects/parameter/array.cpp | 9 +- src/live_effects/parameter/array.h | 14 +- src/live_effects/parameter/satellitepairarray.cpp | 4 +- src/live_effects/parameter/satellitepairarray.h | 7 +- 6 files changed, 236 insertions(+), 40 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 5d6358bb2..df9de81b7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -17,25 +17,38 @@ #include "live_effects/lpe-fillet-chamfer.h" #include +#include #include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> +#include <2geom/svg-elliptical-arc.h> #include "helper/geom-nodetype.h" +#include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include - +using namespace Geom; namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData FilletMethodData[FM_END] = { + { FM_AUTO, N_("Auto"), "auto" }, + { FM_ARC, N_("Force arc"), "arc" }, + { FM_BEZIER, N_("Force bezier"), "bezier" } +}; +static const Util::EnumDataConverter +FMConverter(FilletMethodData, FM_END); + LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this) + satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), + method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO) { registerParameter(&satellitepairarrayparam_values); + registerParameter(&method); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -46,23 +59,21 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { - Geom::PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - std::vector > satellites; - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + std::vector > satellites; + Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); - Geom::Piecewise > der = derivative(pwd2_in); - Geom::Piecewise > n = rot90(unitVector(der)); - satellitepairarrayparam_values.set_pwd2(pwd2_in, n); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + satellitepairarrayparam_values.set_pwd2(pwd2_in); + for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + const Curve &closingline = path_it->back_closed(); // the closing line segment is always of type - // Geom::LineSegment. + // 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 @@ -75,18 +86,18 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); + Satellite satellite(FILLET, true, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { - nodetype = Geom::get_nodetype(*curve_end, *curve_it1); + nodetype = get_nodetype(*curve_end, *curve_it1); } else { - nodetype = Geom::NODE_NONE; + nodetype = NODE_NONE; } } else { nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } - if (nodetype == Geom::NODE_CUSP) { + if (nodetype == NODE_CUSP) { satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; @@ -101,11 +112,196 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } + +void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) +{ + SPLPEItem * splpeitem = const_cast(lpeItem); + SPShape * shape = dynamic_cast(splpeitem); + if (shape) { + SPCurve *c = shape->getCurve(); + SPPath * path = dynamic_cast(shape); + if(path){ + c = path->get_original_curve(); + } + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + Piecewise > pwd2_in = paths_to_pw(original_pathv); + pwd2_in = remove_short_cuts(pwd2_in, .01); + satellitepairarrayparam_values.set_pwd2(pwd2_in); + } else { + g_warning("LPE Fillet can only be applied to shapes (not groups)."); + } +} + +std::vector +LPEFilletChamfer::doEffect_path(std::vector const &path_in) +{ + std::vector pathvector_out; + Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); + pwd2_in = remove_short_cuts(pwd2_in, .01); + satellitepairarrayparam_values.set_pwd2(pwd2_in); + std::vector > filletChamferData = satellitepairarrayparam_values.data(); + unsigned int counter = 0; + const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + for (PathVector::const_iterator path_it = path_in_processed.begin(); + path_it != path_in_processed.end(); ++path_it) { + if (path_it->empty()) + continue; + Geom::Path path_out; + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + const Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // 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(); + } + } + unsigned int counterCurves = 0; + while (curve_it1 != curve_endit) { + Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); + int indexFix = 0; + if(!path_it->closed() || curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + indexFix = counter; + } + bool last = curve_it2 == curve_endit; + std::vector times; + times.push_back(filletChamferData[counter].second.getTime()); + times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis(),filletChamferData[indexFix].second.getTime())); + times.push_back(filletChamferData[indexFix].second.getTime()); + Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); + if (counterCurves > 0) { + knotCurve1->setInitial(path_out.finalPoint()); + } else { + path_out.start((*curve_it1).pointAt(times[0])); + } + Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Point startArcPoint = knotCurve1->finalPoint(); + Point endArcPoint = curve_it2Fixed->pointAt(times[2]); + double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; + double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; + CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, curve_it1->finalPoint()); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; + CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); + Ray ray2(curve_it1->finalPoint(), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); + bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; + double angle = angle_between(ray1, ray2, ccwToggle); + double handleAngle = ray1.angle() - angle; + if (ccwToggle) { + handleAngle = ray1.angle() + angle; + } + Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; + handleAngle = ray2.angle() + angle; + if (ccwToggle) { + handleAngle = ray2.angle() - angle; + } + Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); + //straigth lines arc based + Line const x_line(Point(0,0),Point(1,0)); + Line const angled_line(startArcPoint,endArcPoint); + double angleArc = angle_between( x_line,angled_line); + double radius = distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + Coord rx = radius; + Coord ry = rx; + + if (times[1] != 1) { + if (times[1] != times[0]) { + path_out.append(*knotCurve1); + } + SatelliteType satType = FILLET; + if(path_it->closed() && last){ + satType = filletChamferData[counter - counterCurves].second.getSatelliteType(); + } else if (!path_it->closed() && last){ + //0 + } else { + satType = filletChamferData[counter + 1].second.getSatelliteType(); + } + if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ + path_out.appendNew(endArcPoint); + } else if (satType == CHAMFER) { + unsigned int chamferSubs = 0; + Geom::Path path_chamfer; + path_chamfer.start(path_out.finalPoint()); + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else { + path_chamfer.appendNew(handle1, handle2, endArcPoint); + } + double chamfer_stepsTime = 1.0/chamferSubs; + for(unsigned int i = 1; i < chamferSubs; i++){ + Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); + } + path_out.appendNew(endArcPoint); + } else if (satType == INVERSE_CHAMFER) { + unsigned int chamferSubs = 2; + Geom::Path path_chamfer; + path_chamfer.start(path_out.finalPoint()); + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + ccwToggle = ccwToggle?0:1; + path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + }else{ + path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + } + double chamfer_stepsTime = 1.0/chamferSubs; + for(unsigned int i = 1; i < chamferSubs; i++){ + Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); + } + path_out.appendNew(endArcPoint); + } else if (satType == INVERSE_FILLET) { + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + ccwToggle = ccwToggle?0:1; + path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + }else{ + path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + } + } else if (satType == FILLET){ + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else { + path_out.appendNew(handle1, handle2, endArcPoint); + } + } + } else { + path_out.append(*knotCurve1); + } + if (path_it->closed() && last) { + path_out.close(); + } + ++curve_it1; + if (curve_it2 != curve_endit) { + ++curve_it2; + } + counter++; + counterCurves++; + } + pathvector_out.push_back(path_out); + } + return pathvector_out; +} + void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty()) { - //fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); } } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 08000c0a5..94a2bd2b3 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -14,27 +14,35 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include "live_effects/parameter/enum.h" #include "2geom/pointwise.h" #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" +using namespace Geom; namespace Inkscape { namespace LivePathEffect { +enum FilletMethod { + FM_AUTO, + FM_ARC, + FM_BEZIER, + FM_END +}; class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); - + virtual void doBeforeEffect(SPLPEItem const *lpeItem); + virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); SatellitePairArrayParam satellitepairarrayparam_values; private: - + EnumParam method; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d1d718b08..473b561d2 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -55,17 +55,16 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ - std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; - sat->setSatelliteType(gts[strarray[0]]); + sat->setSatelliteType(strarray[0]); sat->setIsTime(helperfns_read_bool(strarray[1], true)); sat->setActive(helperfns_read_bool(strarray[2], true)); sat->setHasMirror(helperfns_read_bool(strarray[3], false)); sat->setHidden(helperfns_read_bool(strarray[4], false)); double time,size; - sp_svg_number_read_d(strarray[5], &time); - sp_svg_number_read_d(strarray[6], &size); - sat->setTime(time); + sp_svg_number_read_d(strarray[5], &size); + sp_svg_number_read_d(strarray[6], &time); sat->setSize(size); + sat->setTime(time); g_strfreev (strarray); return 1; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index ba1ed3d4e..c99777b08 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -116,19 +116,19 @@ protected: str << nVector.first; str << ","; std::map stg = nVector.second.SatelliteTypeToGcharMap; - str << stg[nVector.second.satellitetype()]; + str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << nVector.second.isTime(); + str << nVector.second.getIsTime(); str << "*"; - str << nVector.second.active(); + str << nVector.second.getActive(); str << "*"; - str << nVector.second.hasMirror(); + str << nVector.second.getHasMirror(); str << "*"; - str << nVector.second.hidden(); + str << nVector.second.getHidden(); str << "*"; - str << nVector.second.size(); + str << nVector.second.getSize(); str << "*"; - str < > const &pwd2_in, - Piecewise > const &pwd2_normal_in) + Piecewise > const &pwd2_in) { last_pwd2 = pwd2_in; - last_pwd2_normal = pwd2_normal_in; } void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 82d04c790..ff1924829 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -47,14 +47,10 @@ public: return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void set_pwd2(Geom::Piecewise > const &pwd2_in, - Geom::Piecewise > const &pwd2_normal_in); + void set_pwd2(Geom::Piecewise > const &pwd2_in); Geom::Piecewise > const &get_pwd2() const { return last_pwd2; } - Geom::Piecewise > const &get_pwd2_normal() const { - return last_pwd2_normal; - } friend class SatellitePairArrayParamKnotHolderEntity; private: @@ -66,7 +62,6 @@ private: guint32 knot_color; Geom::Piecewise > last_pwd2; - Geom::Piecewise > last_pwd2_normal; }; -- cgit v1.2.3 From e6e262b34c193502d1f9be44324515bf8c861d47 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 17 Feb 2015 00:23:51 +0100 Subject: starting fillet/chamfer (bzr r13645.1.15) --- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.h | 1 - src/live_effects/parameter/array.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index df9de81b7..b34cd87a1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -174,7 +174,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) bool last = curve_it2 == curve_endit; std::vector times; times.push_back(filletChamferData[counter].second.getTime()); - times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis(),filletChamferData[indexFix].second.getTime())); + times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis())); times.push_back(filletChamferData[indexFix].second.getTime()); Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 94a2bd2b3..2c0dfcaab 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -19,7 +19,6 @@ #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" -using namespace Geom; namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index c99777b08..8145d62a3 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -115,7 +115,6 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; - std::map stg = nVector.second.SatelliteTypeToGcharMap; str << nVector.second.getSatelliteTypeGchar(); str << "*"; str << nVector.second.getIsTime(); -- cgit v1.2.3 From a230b9d6684f01ded46fd530ba0cc74ce9696e2d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:53:20 +0100 Subject: Basic filleting using pointwise (bzr r13645.1.16) --- src/live_effects/CMakeLists.txt | 2 - src/live_effects/lpe-fillet-chamfer.cpp | 123 ++- src/live_effects/parameter/Makefile_insert | 2 - .../parameter/filletchamferpointarray.cpp | 881 --------------------- .../parameter/filletchamferpointarray.h | 127 --- 5 files changed, 80 insertions(+), 1055 deletions(-) delete mode 100644 src/live_effects/parameter/filletchamferpointarray.cpp delete mode 100644 src/live_effects/parameter/filletchamferpointarray.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 6b004e1df..3af27a220 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -55,7 +55,6 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp - parameter/filletchamferpointarray.cpp parameter/parameter.cpp parameter/path.cpp parameter/originalpath.cpp @@ -131,7 +130,6 @@ set(live_effects_SRC parameter/array.h parameter/bool.h - parameter/filletchamferpointarray.h parameter/enum.h parameter/parameter.h parameter/path-reference.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b34cd87a1..3b1b1697c 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -64,6 +64,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); + int counterTotal = 0; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -98,10 +99,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == NODE_CUSP) { - satellites.push_back(std::make_pair(counter, satellite)); + satellites.push_back(std::make_pair(counterTotal, satellite)); } ++curve_it1; counter++; + counterTotal++; } } satellitepairarrayparam_values.param_set_and_write_new_value(satellites); @@ -132,14 +134,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } + std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { + const double gapHelper = 0.00001; std::vector pathvector_out; Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); std::vector > filletChamferData = satellitepairarrayparam_values.data(); + Pointwise *pointwise = new Pointwise( pwd2_in, filletChamferData); unsigned int counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); @@ -152,9 +157,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type - // LineSegment. + // 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 @@ -164,18 +169,46 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } unsigned int counterCurves = 0; + unsigned int first = counter; + double time0 = 0; while (curve_it1 != curve_endit) { + std::vector satVector; + Satellite sat(FILLET, true, true, false, false, 0.0, 0.0); Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); - int indexFix = 0; if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - indexFix = counter; + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + sat = satVector[0]; + } + } else { + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + sat = satVector[0]; + } + } + if(first == counter){ + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + time0 = satVector[0].getTime(); + } } bool last = curve_it2 == curve_endit; + double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); + double time2 = sat.getTime(); + if(time1 <= time0){ + time1 = time0 + gapHelper; + } + if(time0 == 1){ + time0 = time0 - gapHelper; + } + if(time2 == 1){ + time2 = time2 - gapHelper; + } std::vector times; - times.push_back(filletChamferData[counter].second.getTime()); - times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis())); - times.push_back(filletChamferData[indexFix].second.getTime()); + times.push_back(time0); + times.push_back(time1); + times.push_back(time2); Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); @@ -187,14 +220,17 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Point endArcPoint = curve_it2Fixed->pointAt(times[2]); double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; - CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, curve_it1->finalPoint()); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); + if(time0 == 1){ + handle1 = startArcPoint; + } + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); Ray ray2(curve_it1->finalPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); @@ -207,76 +243,76 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) handleAngle = ray1.angle() + angle; } Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; + if(time0 == 1){ + inverseHandle1 = startArcPoint; + } handleAngle = ray2.angle() + angle; if (ccwToggle) { handleAngle = ray2.angle() - angle; } Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - //straigth lines arc based - Line const x_line(Point(0,0),Point(1,0)); + Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); - double angleArc = angle_between( x_line,angled_line); - double radius = distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + double angleArc = Geom::angle_between( x_line,angled_line); + double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); Coord rx = radius; Coord ry = rx; - if (times[1] != 1) { - if (times[1] != times[0]) { + if (times[1] != 1 || (times[1] == 1 && times[0] == times[1] - gapHelper )) { + if (times[1] != times[0] + gapHelper) { path_out.append(*knotCurve1); } - SatelliteType satType = FILLET; - if(path_it->closed() && last){ - satType = filletChamferData[counter - counterCurves].second.getSatelliteType(); - } else if (!path_it->closed() && last){ - //0 - } else { - satType = filletChamferData[counter + 1].second.getSatelliteType(); - } + SatelliteType type = FILLET; + type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - path_out.appendNew(endArcPoint); - } else if (satType == CHAMFER) { - unsigned int chamferSubs = 0; + //path_out.appendNew(endArcPoint); + } else if (type == CHAMFER) { + /* + unsigned int chamferSubs = type-3000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); + path_chamfer.appendNew(handle1, handle2, endArcPoint); } double chamfer_stepsTime = 1.0/chamferSubs; for(unsigned int i = 1; i < chamferSubs; i++){ - Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); } - path_out.appendNew(endArcPoint); - } else if (satType == INVERSE_CHAMFER) { - unsigned int chamferSubs = 2; + path_out.appendNew(endArcPoint); + /*/ + } else if (type == INVERSE_CHAMFER) { + /* + unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } double chamfer_stepsTime = 1.0/chamferSubs; for(unsigned int i = 1; i < chamferSubs; i++){ - Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); } - path_out.appendNew(endArcPoint); - } else if (satType == INVERSE_FILLET) { + path_out.appendNew(endArcPoint); + */ + } else if (type == INVERSE_FILLET) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - } else if (satType == FILLET){ + } else if (type == FILLET){ if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { - path_out.appendNew(handle1, handle2, endArcPoint); + path_out.appendNew(handle1, handle2, endArcPoint); } } } else { @@ -291,6 +327,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } counter++; counterCurves++; + time0 = times[2]; } pathvector_out.push_back(path_out); } @@ -299,7 +336,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ +{ if (!path_in.empty()) { //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); } diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 33c6b0673..c9f40f7d1 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -24,8 +24,6 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/filletchamferpointarray.cpp \ - live_effects/parameter/filletchamferpointarray.h \ live_effects/parameter/satellitepairarray.cpp \ live_effects/parameter/satellitepairarray.h \ live_effects/parameter/text.cpp \ diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp deleted file mode 100644 index 2ebe11b4b..000000000 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ /dev/null @@ -1,881 +0,0 @@ -/* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <2geom/piecewise.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/sbasis-geometric.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/line.h> -#include <2geom/path-intersection.h> - -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/filletchamferpointarray.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "knotholder.h" -#include "sp-lpe-item.h" -#include "selection.h" - -// needed for on-canvas editting: -#include "desktop.h" -#include "live_effects/lpeobject.h" -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" -#include "ui/tools/node-tool.h" - -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -FilletChamferPointArrayParam::FilletChamferPointArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; -} - -FilletChamferPointArrayParam::~FilletChamferPointArrayParam() {} - -Gtk::Widget *FilletChamferPointArrayParam::param_newWidget() -{ - return NULL; - /* - 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; - 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(hbox)->pack_start(*pointwdg, true, true); - static_cast(hbox)->show_all_children(); - - return dynamic_cast (hbox); - */ -} - -void -FilletChamferPointArrayParam::param_transform_multiply(Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true) && - _vector[1][X] <= 0) { - std::vector result; - for (std::vector::const_iterator point_it = _vector.begin(); - point_it != _vector.end(); ++point_it) { - Coord A = - (*point_it)[X] * ((postmul.expansionX() + postmul.expansionY()) / 2); - result.push_back(Point(A, (*point_it)[Y])); - } - param_set_and_write_new_value(result); - } - - // param_set_and_write_new_value( (*this) * postmul ); -} - -/** call this method to recalculate the controlpoints such that they stay at the - * same location relative to the new path. Useful after adding/deleting nodes to - * the path.*/ -void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( - Piecewise > const &pwd2_in) -{ - if (!last_pwd2.empty()) { - PathVector const pathv = - path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); - PathVector last_pathv = - path_from_piecewise(remove_short_cuts(last_pwd2, 0.1), 0.001); - std::vector result; - unsigned long counter = 0; - unsigned long counterPaths = 0; - unsigned long counterCurves = 0; - long offset = 0; - long offsetPaths = 0; - Geom::NodeType nodetype; - for (PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { - if (path_it->empty()) { - counterPaths++; - counter++; - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - counterCurves = 0; - while (curve_it1 != curve_endit) { - //if start a path get node type - if (counterCurves == 0) { - if (path_it->closed()) { - if (path_it->back_closed().isDegenerate()) { - nodetype = get_nodetype(path_it->back_open(), *curve_it1); - } else { - nodetype = get_nodetype(path_it->back_closed(), *curve_it1); - } - } else { - nodetype = NODE_NONE; - } - } else { - //check node type also whith straight lines because get_nodetype - //return non cusp node in a node inserted inside a straight line - //todo: if the path remove some nodes whith the result of a straight - //line but with handles, the node inserted into dont fire the knot - // because is not handle as cusp node by get_nodetype function - bool this_is_line = true; - bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); - nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); - if (this_is_line || next_is_line) { - nodetype = NODE_CUSP; - } - } - if (last_pathv.size() > pathv.size() || - (last_pathv.size() > counterPaths && - last_pathv[counterPaths].size() > counter - offset && - !are_near(curve_it1->initialPoint(), - last_pathv[counterPaths][counter - offset].initialPoint(), - 0.1))) { - if ( curve_it2 == curve_endit) { - if (last_pathv[counterPaths].size() != pathv[counterPaths].size()) { - offset = (last_pathv[counterPaths].size() - pathv[counterPaths].size()) * -1; - } else { - offset = 0; - } - offsetPaths += offset; - offset = offsetPaths; - } else if (counterCurves == 0 && last_pathv.size() <= pathv.size() && - counter - offset <= last_pathv[counterPaths].size() && - are_near(curve_it1->initialPoint(), - last_pathv[counterPaths].finalPoint(), 0.1) && - !last_pathv[counterPaths].closed()) { - long e = counter - offset + 1; - std::vector tmp = _vector; - for (unsigned long i = - last_pathv[counterPaths].size() + counter - offset; - i > counterCurves - offset + 1; i--) { - - if (tmp[i - 1][X] > 0) { - double fractpart, intpart; - fractpart = modf(tmp[i - 1][X], &intpart); - _vector[e] = Point(e + fractpart, tmp[i - 1][Y]); - } else { - _vector[e] = Point(tmp[i - 1][X], tmp[i - 1][Y]); - } - e++; - } - //delete temp vector - std::vector().swap(tmp); - if (last_pathv.size() > counterPaths) { - last_pathv[counterPaths] = last_pathv[counterPaths].reverse(); - } - } else { - if (last_pathv.size() > counterPaths) { - if (last_pathv[counterPaths].size() < - pathv[counterPaths].size()) { - offset++; - } else if (last_pathv[counterPaths].size() > - pathv[counterPaths].size()) { - offset--; - continue; - } - } else { - offset++; - } - } - double xPos = 0; - if (_vector[1][X] > 0) { - xPos = nearest_point(curve_it1->initialPoint(), pwd2_in); - } - if (nodetype == NODE_CUSP) { - result.push_back(Point(xPos, 1)); - } else { - result.push_back(Point(xPos, 0)); - } - } else { - double xPos = _vector[counter - offset][X]; - if (_vector.size() <= (unsigned)(counter - offset)) { - if (_vector[1][X] > 0) { - xPos = nearest_point(curve_it1->initialPoint(), pwd2_in); - } else { - xPos = 0; - } - } - if (nodetype == NODE_CUSP) { - double vectorY = _vector[counter - offset][Y]; - if (_vector.size() <= (unsigned)(counter - offset) || vectorY == 0) { - vectorY = 1; - } - result.push_back(Point(xPos, vectorY)); - } else { - if (_vector[1][X] < 0) { - xPos = 0; - } - result.push_back(Point(floor(xPos), 0)); - } - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - counterCurves++; - } - counterPaths++; - } - _vector = result; - write_to_SVG(); - } -} - -void FilletChamferPointArrayParam::recalculate_knots( - Piecewise > const &pwd2_in) -{ - bool change = false; - PathVector pathv = path_from_piecewise(pwd2_in, 0.001); - if (!pathv.empty()) { - std::vector result; - int counter = 0; - int counterCurves = 0; - Geom::NodeType nodetype; - for (PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { - if (path_it->empty()) { - counter++; - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - counterCurves = 0; - while (curve_it1 != curve_endit) { - //if start a path get node type - if (counterCurves == 0) { - if (path_it->closed()) { - if (path_it->back_closed().isDegenerate()) { - nodetype = get_nodetype(path_it->back_open(), *curve_it1); - } else { - nodetype = get_nodetype(path_it->back_closed(), *curve_it1); - } - } else { - nodetype = NODE_NONE; - } - } else { - bool this_is_line = true; - bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); - nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); - if (this_is_line || next_is_line) { - nodetype = NODE_CUSP; - } - } - if (nodetype == NODE_CUSP) { - double vectorY = _vector[counter][Y]; - if (vectorY == 0) { - vectorY = 1; - change = true; - } - result.push_back(Point(_vector[counter][X], vectorY)); - } else { - double xPos = floor(_vector[counter][X]); - if (_vector[1][X] < 0) { - xPos = 0; - } - double vectorY = _vector[counter][Y]; - if (vectorY != 0) { - change = true; - } - result.push_back(Point(xPos, 0)); - } - ++curve_it1; - counter++; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counterCurves++; - } - } - if (change) { - _vector = result; - write_to_SVG(); - } - } -} - -void FilletChamferPointArrayParam::set_pwd2( - Piecewise > const &pwd2_in, - Piecewise > const &pwd2_normal_in) -{ - last_pwd2 = pwd2_in; - last_pwd2_normal = pwd2_normal_in; -} - -void FilletChamferPointArrayParam::set_document_unit(Glib::ustring const * value_document_unit) -{ - documentUnit = value_document_unit; -} - -void FilletChamferPointArrayParam::set_helper_size(int hs) -{ - helper_size = hs; -} - -void FilletChamferPointArrayParam::set_chamfer_steps(int value_chamfer_steps) -{ - chamfer_steps = value_chamfer_steps; -} - -void FilletChamferPointArrayParam::set_use_distance(bool use_knot_distance ) -{ - use_distance = use_knot_distance; -} - -void FilletChamferPointArrayParam::set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void FilletChamferPointArrayParam::updateCanvasIndicators() -{ - std::vector ts = data(); - hp.clear(); - unsigned int i = 0; - for (std::vector::const_iterator point_it = ts.begin(); - point_it != ts.end(); ++point_it) { - double Xvalue = to_time(i, (*point_it)[X]) -i; - if (Xvalue == 0) { - i++; - continue; - } - Geom::Point ptA = last_pwd2[i].valueAt(Xvalue); - Geom::Point derivA = unit_vector(derivative(last_pwd2[i]).valueAt(Xvalue)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - pathv *= aff; - pathv += last_pwd2[i].valueAt(Xvalue); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - i++; - } -} - -void FilletChamferPointArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(hp); -} - -double FilletChamferPointArrayParam::rad_to_len(int index, double rad) -{ - double len = 0; - std::vector subpaths = path_from_piecewise(last_pwd2, 0.1); - std::pair positions = get_positions(index, subpaths); - D2 A = last_pwd2[last_index(index, subpaths)]; - if(positions.second != 0){ - A = last_pwd2[index-1]; - }else{ - if(!subpaths[positions.first].closed()){ - return len; - } - } - D2 B = last_pwd2[index]; - Piecewise > offset_curve0 = Piecewise >(A)+rot90(unitVector(derivative(A)))*(rad); - Piecewise > offset_curve1 = Piecewise >(B)+rot90(unitVector(derivative(B)))*(rad); - Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; - Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; - Geom::Crossings cs = Geom::crossings(p0, p1); - if(cs.size() > 0){ - Point cp =p0(cs[0].ta); - double p0pt = nearest_point(cp, B); - len = time_to_len(index,p0pt); - } else { - if(rad < 0){ - len = rad_to_len(index, rad * -1); - } - } - return len; -} - -double FilletChamferPointArrayParam::len_to_rad(int index, double len) -{ - double rad = 0; - double tmp_len = _vector[index][X]; - _vector[index] = Geom::Point(len,_vector[index][Y]); - std::vector subpaths = path_from_piecewise(last_pwd2, 0.1); - std::pair positions = get_positions(index, subpaths); - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[last_index(index, subpaths)], 1); - Geom::Curve * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Geom::Curve * B = subpaths[positions.first][positions.second].duplicate(); - std::vector times; - if(positions.second != 0){ - A = subpaths[positions.first][positions.second-1].duplicate(); - times = get_times(index-1, subpaths, false); - }else{ - if(!subpaths[positions.first].closed()){ - return rad; - } - times = get_times(last_index(index, subpaths), subpaths, true); - } - _vector[index] = Geom::Point(tmp_len,_vector[index][Y]); - Geom::Point startArcPoint = A->toSBasis().valueAt(times[1]); - Geom::Point endArcPoint = B->toSBasis().valueAt(times[2]); - Curve *knotCurve1 = A->portion(times[0], times[1]); - Curve *knotCurve2 = B->portion(times[2], 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, A->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(B->initialPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - bool ccwToggle = cross(A->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - rad = distanceArc/sin(angleBetween/2.0); - return rad * -1; -} - -std::vector FilletChamferPointArrayParam::get_times(int index, std::vector subpaths, bool last) -{ - const double tolerance = 0.001; - const double gapHelper = 0.00001; - std::pair positions = get_positions(index, subpaths); - Curve *curve_it1; - curve_it1 = subpaths[positions.first][positions.second].duplicate(); - Coord it1_length = (*curve_it1).length(tolerance); - double time_it1, time_it2, time_it1_B, intpart; - time_it1 = modf(to_time(index, _vector[index][X]), &intpart); - if (_vector[index][Y] == 0) { - time_it1 = 0; - } - double resultLenght = 0; - time_it1_B = 1; - if (subpaths[positions.first].closed() && last) { - time_it2 = modf(to_time(index - positions.second , _vector[index - positions.second ][X]), &intpart); - resultLenght = it1_length + to_len(index - positions.second, _vector[index - positions.second ][X]); - } else if (!subpaths[positions.first].closed() && last){ - time_it2 = 0; - resultLenght = 0; - } else { - time_it2 = modf(to_time(index + 1, _vector[index + 1][X]), &intpart); - resultLenght = it1_length + to_len( index + 1, _vector[index + 1][X]); - } - if (resultLenght > 0 && time_it2 != 0) { - time_it1_B = modf(to_time(index, -resultLenght), &intpart); - } else { - if (time_it2 == 0) { - time_it1_B = 1; - } else { - time_it1_B = gapHelper; - } - } - - if ((subpaths[positions.first].closed() && last && _vector[index - positions.second][Y] == 0) || (subpaths[positions.first].size() > positions.second + 1 && _vector[index + 1][Y] == 0)) { - time_it1_B = 1; - time_it2 = 0; - } - if (time_it1_B < time_it1) { - time_it1_B = time_it1 + gapHelper; - } - std::vector out; - out.push_back(time_it1); - out.push_back(time_it1_B); - out.push_back(time_it2); - return out; -} - -std::pair FilletChamferPointArrayParam::get_positions(int index, std::vector subpaths) -{ - int counter = -1; - std::size_t first = 0; - std::size_t second = 0; - for (PathVector::const_iterator path_it = subpaths.begin(); path_it != subpaths.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - 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(); - } - } - first++; - second = 0; - while (curve_it1 != curve_endit) { - counter++; - second++; - if(counter == index){ - break; - } - ++curve_it1; - } - if(counter == index){ - break; - } - } - first--; - second--; - std::pair out(first, second); - return out; -} - -int FilletChamferPointArrayParam::last_index(int index, std::vector subpaths) -{ - int counter = -1; - bool inSubpath = false; - for (PathVector::const_iterator path_it = subpaths.begin(); path_it != subpaths.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - counter++; - if(counter == index){ - inSubpath = true; - } - ++curve_it1; - } - if(inSubpath){ - break; - } - } - if(!inSubpath){ - counter = -1; - } - return counter; -} - - -double FilletChamferPointArrayParam::len_to_time(int index, double len) -{ - double t = 0; - if (last_pwd2.size() > (unsigned) index) { - if (len != 0) { - if (last_pwd2[index][0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[index], 1); - std::vector t_roots = roots(arcLengthSb(u) - std::abs(len)); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } else { - double lenghtPart = 0; - if (last_pwd2.size() > (unsigned) index) { - lenghtPart = length(last_pwd2[index], EPSILON); - } - if (std::abs(len) < lenghtPart && lenghtPart != 0) { - t = std::abs(len) / lenghtPart; - } - } - } - t = double(index) + t; - } else { - t = double(last_pwd2.size() - 1); - } - - return t; -} - -double FilletChamferPointArrayParam::time_to_len(int index, double time) -{ - double intpart; - double len = 0; - time = modf(time, &intpart); - double lenghtPart = 0; - if (last_pwd2.size() <= (unsigned) index || time == 0) { - return len; - } - if (last_pwd2[index][0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[index], 1); - u = portion(u, 0, time); - return length(u, 0.001) * -1; - } - lenghtPart = length(last_pwd2[index], EPSILON); - return (time * lenghtPart) * -1; -} - -double FilletChamferPointArrayParam::to_time(int index, double A) -{ - if (A > 0) { - return A; - } else { - return len_to_time(index, A); - } -} - -double FilletChamferPointArrayParam::to_len(int index, double A) -{ - if (A > 0) { - return time_to_len(index, A); - } else { - return A; - } -} - -void FilletChamferPointArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -FilletChamferPointArrayParamKnotHolderEntity:: -FilletChamferPointArrayParamKnotHolderEntity( - FilletChamferPointArrayParam *p, unsigned int index) - : _pparam(p), _index(index) {} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - using namespace Geom; - - if (!valid_index(_index)) { - return; - } - Piecewise > const &pwd2 = _pparam->get_pwd2(); - double t = nearest_point(p, pwd2[_index]); - Geom::Point const s = snap_knot_position(pwd2[_index].valueAt(t), state); - t = nearest_point(s, pwd2[_index]); - if (t == 1) { - t = 0.9999; - } - t += _index; - - if (_pparam->_vector.at(_index)[X] <= 0) { - _pparam->_vector.at(_index) = - Point(_pparam->time_to_len(_index, t), _pparam->_vector.at(_index)[Y]); - } else { - _pparam->_vector.at(_index) = Point(t, _pparam->_vector.at(_index)[Y]); - } - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Point FilletChamferPointArrayParamKnotHolderEntity::knot_get() const -{ - using namespace Geom; - - if (!valid_index(_index)) { - return Point(infinity(), infinity()); - } - - Piecewise > const &pwd2 = _pparam->get_pwd2(); - - double time_it = _pparam->to_time(_index, _pparam->_vector.at(_index)[X]); - Point canvas_point = pwd2.valueAt(time_it); - - _pparam->updateCanvasIndicators(); - return canvas_point; - -} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_click(guint state) -{ - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(_index) = Point(_index, _pparam->_vector.at(_index)[Y]); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ - using namespace Geom; - int type = (int)_pparam->_vector.at(_index)[Y]; - if (type >=3000 && type < 4000){ - type = 3; - } - if (type >=4000 && type < 5000){ - type = 4; - } - switch(type){ - case 1: - type = 2; - break; - case 2: - type = _pparam->chamfer_steps + 3000; - break; - case 3: - type = _pparam->chamfer_steps + 4000; - break; - default: - type = 1; - break; - } - _pparam->_vector.at(_index) = Point(_pparam->_vector.at(_index)[X], (double)type); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type >=3000 && type < 4000){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type >=4000 && type < 5000) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == 2) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - double xModified = _pparam->_vector.at(_index).x(); - if(xModified < 0 && !_pparam->use_distance){ - xModified = _pparam->len_to_rad(_index, _pparam->_vector.at(_index).x()); - } - std::vector subpaths = path_from_piecewise(_pparam->last_pwd2, 0.1); - std::pair positions = _pparam->get_positions(_index, subpaths); - D2 A = _pparam->last_pwd2[_pparam->last_index(_index, subpaths)]; - if(positions.second != 0){ - A = _pparam->last_pwd2[_index-1]; - } - D2 B = _pparam->last_pwd2[_index]; - bool aprox = (A[0].degreesOfFreedom() != 2 || B[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; - Geom::Point offset = Geom::Point(xModified, _pparam->_vector.at(_index).y()); - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, offset, this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit); - } - -} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_set_offset( - Geom::Point offset) -{ - double xModified = offset.x(); - if(xModified < 0 && !_pparam->use_distance){ - xModified = _pparam->rad_to_len(_index, offset.x()); - } - _pparam->_vector.at(_index) = Geom::Point(xModified, offset.y()); - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); -} - -void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - recalculate_knots(get_pwd2()); - for (unsigned int i = 0; i < _vector.size(); ++i) { - if (_vector[i][Y] <= 0) { - continue; - } - const gchar *tip; - if (_vector[i][Y] >=3000 && _vector[i][Y] < 4000){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (_vector[i][Y] >=4000 && _vector[i][Y] < 5000) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (_vector[i][Y] == 2) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferPointArrayParamKnotHolderEntity *e = - new FilletChamferPointArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - updateCanvasIndicators(); -} - -} /* 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/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h deleted file mode 100644 index 6e5cce353..000000000 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_FILLET_CHAMFER_POINT_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_FILLET_CHAMFER_POINT_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/point.h> - -#include "live_effects/parameter/array.h" - -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferPointArrayParamKnotHolderEntity; - -class FilletChamferPointArrayParam : public ArrayParam { -public: - FilletChamferPointArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~FilletChamferPointArrayParam(); - - virtual Gtk::Widget *param_newWidget(); - - virtual void param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/); - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual double to_time(int index, double A); - virtual double to_len(int index, double A); - virtual double rad_to_len(int index, double rad); - virtual double len_to_rad(int index, double len); - virtual double len_to_time(int index, double len); - virtual double time_to_len(int index, double time); - virtual std::pair get_positions(int index, std::vector subpaths); - virtual int last_index(int index, std::vector subpaths); - std::vector get_times(int index, std::vector subpaths, bool last); - virtual void set_helper_size(int hs); - virtual void set_use_distance(bool use_knot_distance); - virtual void set_chamfer_steps(int value_chamfer_steps); - virtual void set_document_unit(Glib::ustring const * value_document_unit); - virtual void set_unit(const gchar *abbr); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { - return true; - } - virtual void updateCanvasIndicators(); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - - void set_pwd2(Geom::Piecewise > const &pwd2_in, - Geom::Piecewise > const &pwd2_normal_in); - Geom::Piecewise > const &get_pwd2() const { - return last_pwd2; - } - Geom::Piecewise > const &get_pwd2_normal() const { - return last_pwd2_normal; - } - - void recalculate_controlpoints_for_new_pwd2( - Geom::Piecewise > const &pwd2_in); - void recalculate_knots( - Geom::Piecewise > const &pwd2_in); - friend class FilletChamferPointArrayParamKnotHolderEntity; - -private: - FilletChamferPointArrayParam(const FilletChamferPointArrayParam &); - FilletChamferPointArrayParam &operator=(const FilletChamferPointArrayParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - int helper_size; - int chamfer_steps; - bool use_distance; - const gchar *unit; - Glib::ustring const * documentUnit; - Geom::PathVector hp; - - Geom::Piecewise > last_pwd2; - Geom::Piecewise > last_pwd2_normal; -}; - -class FilletChamferPointArrayParamKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferPointArrayParamKnotHolderEntity(FilletChamferPointArrayParam *p, - unsigned int index); - virtual ~FilletChamferPointArrayParamKnotHolderEntity() {} - - 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); - virtual void knot_set_offset(Geom::Point offset); - - /*Checks whether the index falls within the size of the parameter's vector*/ - bool valid_index(unsigned int index) const { - return (_pparam->_vector.size() > index); - } - ; - -private: - FilletChamferPointArrayParam *_pparam; - unsigned int _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif -- cgit v1.2.3 From eae224916a20ea75f80471af2df057e7e74b0c9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:59:45 +0100 Subject: reducing size in pointwise LPE data (bzr r13645.1.18) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3b1b1697c..e9d9a21b1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -262,11 +262,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (times[1] != times[0] + gapHelper) { path_out.append(*knotCurve1); } - SatelliteType type = FILLET; + SatelliteType type = F; type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ //path_out.appendNew(endArcPoint); - } else if (type == CHAMFER) { + } else if (type == C) { /* unsigned int chamferSubs = type-3000; Geom::Path path_chamfer; @@ -283,7 +283,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } path_out.appendNew(endArcPoint); /*/ - } else if (type == INVERSE_CHAMFER) { + } else if (type == IC) { /* unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; @@ -301,14 +301,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } path_out.appendNew(endArcPoint); */ - } else if (type == INVERSE_FILLET) { + } else if (type == IF) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - } else if (type == FILLET){ + } else if (type == F){ if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { -- cgit v1.2.3 From aa9e36cd93c4f71ff8eb0a6fc24d46933fdf7d14 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 22:06:37 +0100 Subject: fixed some bugs (bzr r13645.1.19) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index e9d9a21b1..0ef8b5a0e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -87,7 +87,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(FILLET, true, true, false, false, 0.0, 0.0); + Satellite satellite(F, true, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { @@ -173,7 +173,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; while (curve_it1 != curve_endit) { std::vector satVector; - Satellite sat(FILLET, true, true, false, false, 0.0, 0.0); + Satellite sat(F, true, true, false, false, 0.0, 0.0); Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); -- cgit v1.2.3 From 83e726c8fb391f0cbbccc9b286bfecefc730dbc7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 Feb 2015 23:16:39 +0100 Subject: Added flexible/fixed to fillet chamfer and fix bugs (bzr r13645.1.20) --- src/live_effects/lpe-fillet-chamfer.cpp | 100 ++++++++++++++++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 3 + src/live_effects/parameter/array.h | 10 ++-- 3 files changed, 77 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0ef8b5a0e..73c504deb 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -45,10 +45,13 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO) + method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), + pointwise() { registerParameter(&satellitepairarrayparam_values); registerParameter(&method); + registerParameter(&flexible); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -60,11 +63,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPShape * shape = dynamic_cast(splpeitem); if (shape) { PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - std::vector > satellites; Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); int counterTotal = 0; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -87,7 +90,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(F, true, true, false, false, 0.0, 0.0); + Satellite satellite(F, flexible, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { @@ -114,7 +117,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } - void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); @@ -126,9 +128,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, .01); + //wating to recalculate + //recalculate_controlpoints_for_new_pwd2(pwd2_in); satellitepairarrayparam_values.set_pwd2(pwd2_in); + std::vector > satellites = satellitepairarrayparam_values.data(); + pointwise = new Pointwise( pwd2_in,satellites); + bool changed = false; + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(it->second.getIsTime() != flexible){ + it->second.setIsTime(flexible); + changed = true; + } + } + if(changed){ + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -140,18 +156,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) { const double gapHelper = 0.00001; std::vector pathvector_out; - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); - pwd2_in = remove_short_cuts(pwd2_in, .01); - satellitepairarrayparam_values.set_pwd2(pwd2_in); - std::vector > filletChamferData = satellitepairarrayparam_values.data(); - Pointwise *pointwise = new Pointwise( pwd2_in, filletChamferData); unsigned int counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()) + if (path_it->empty()){ continue; + } Geom::Path path_out; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -172,9 +184,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) unsigned int first = counter; double time0 = 0; while (curve_it1 != curve_endit) { + if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + g_warning("LPE Fillet not handle degenerate curves."); + return path_in; + } std::vector satVector; - Satellite sat(F, true, true, false, false, 0.0, 0.0); - Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); + Satellite sat; + Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); satVector = pointwise->findSatellites(counter+1,1); @@ -193,33 +209,38 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) time0 = satVector[0].getTime(); } } + bool last = curve_it2 == curve_endit; double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); double time2 = sat.getTime(); if(time1 <= time0){ - time1 = time0 + gapHelper; - } - if(time0 == 1){ - time0 = time0 - gapHelper; - } - if(time2 == 1){ - time2 = time2 - gapHelper; + time1 = time0; } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); + std::cout << ":::" << counter << ":::::::::::::::\n"; + std::cout << time0 << "::Time 0\n"; + std::cout << time1 << "::Time 1\n"; + std::cout << time2 << "::Time 2\n"; Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); } else { path_out.start((*curve_it1).pointAt(times[0])); } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Point startArcPoint = knotCurve1->finalPoint(); Point endArcPoint = curve_it2Fixed->pointAt(times[2]); + if(times[2] == 1){ + endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); + } + if(times[1] == times[0]){ + startArcPoint = knotCurve1->pointAt(1-gapHelper); + } double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; + double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, curve_it1->finalPoint()); if (cubic1) { @@ -229,13 +250,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time0 == 1){ handle1 = startArcPoint; } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(curve_it1->finalPoint(), endArcPoint); + Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Ray ray2(curve_it2Fixed->initialPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); + bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; double angle = angle_between(ray1, ray2, ccwToggle); double handleAngle = ray1.angle() - angle; @@ -251,21 +273,28 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) handleAngle = ray2.angle() - angle; } Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); + if(times[2] == 1){ + endArcPoint = curve_it2Fixed->pointAt(times[2]); + } + if(times[1] == times[0]){ + startArcPoint = knotCurve1->pointAt(1); + } Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); double angleArc = Geom::angle_between( x_line,angled_line); double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); Coord rx = radius; Coord ry = rx; - - if (times[1] != 1 || (times[1] == 1 && times[0] == times[1] - gapHelper )) { - if (times[1] != times[0] + gapHelper) { - path_out.append(*knotCurve1); + if (times[1] != 1) { + if (times[1] != times[0] || times[1] == times[0] == 1) { + if(!knotCurve1->isDegenerate()){ + path_out.append(*knotCurve1); + } } SatelliteType type = F; type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - //path_out.appendNew(endArcPoint); + // path_out.appendNew(endArcPoint); } else if (type == C) { /* unsigned int chamferSubs = type-3000; @@ -316,11 +345,20 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } } else { - path_out.append(*knotCurve1); + if(!knotCurve1->isDegenerate()){ + path_out.append(*knotCurve1); + } } if (path_it->closed() && last) { path_out.close(); } + /* + if(!path_it->closed() || curve_it2 != curve_endit){ + satellites[counter + 1] = std::make_pair(counter + 1, sat); + } else { + satellites[first] = std::make_pair(first, sat); + } + */ ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 2c0dfcaab..f5c4f14ea 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,6 +42,9 @@ public: private: EnumParam method; + BoolParam flexible; + Geom::Pointwise *pointwise; + LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 8145d62a3..e9775da24 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -115,15 +115,15 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; - str << nVector.second.getSatelliteTypeGchar(); + str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << nVector.second.getIsTime(); + str << g_strdup(nVector.second.getIsTime() ? "true" : "false"); str << "*"; - str << nVector.second.getActive(); + str << g_strdup(nVector.second.getActive() ? "true" : "false"); str << "*"; - str << nVector.second.getHasMirror(); + str << g_strdup(nVector.second.getHasMirror() ? "true" : "false"); str << "*"; - str << nVector.second.getHidden(); + str << g_strdup(nVector.second.getHidden() ? "true" : "false"); str << "*"; str << nVector.second.getSize(); str << "*"; -- cgit v1.2.3 From 7086c79862b2d9bcd9f12f078854ad7e117d2cde Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Feb 2015 22:52:58 +0100 Subject: fixing write knot (bzr r13645.1.22) --- src/live_effects/lpe-fillet-chamfer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 73c504deb..2354aa5ed 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -120,6 +120,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); + if (splpeitem) { + // This writes all parameters to SVG. Is this sufficiently efficient or should we only + // write the ones that were changed? + Inkscape::LivePathEffect::Effect *lpe = splpeitem->getCurrentLPE(); + if (lpe) { + LivePathEffectObject *lpeobj = lpe->getLPEObj(); + lpeobj->updateRepr(); + } + } SPShape * shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); -- cgit v1.2.3 From 43c5af94d24cd408f7b369545e96cf9192f6ba90 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Feb 2015 13:13:49 +0100 Subject: improving code (bzr r13645.1.24) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +--------- src/live_effects/parameter/array.cpp | 8 ++++---- src/live_effects/parameter/array.h | 8 ++++---- 3 files changed, 9 insertions(+), 17 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2354aa5ed..39acdca80 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,6 +16,7 @@ #include "live_effects/lpe-fillet-chamfer.h" +#include "live_effects/lpeobject.h" #include #include #include <2geom/pointwise.h> @@ -120,15 +121,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); - if (splpeitem) { - // This writes all parameters to SVG. Is this sufficiently efficient or should we only - // write the ones that were changed? - Inkscape::LivePathEffect::Effect *lpe = splpeitem->getCurrentLPE(); - if (lpe) { - LivePathEffectObject *lpeobj = lpe->getLPEObj(); - lpeobj->updateRepr(); - } - } SPShape * shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 473b561d2..6dad9fcc8 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -56,10 +56,10 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ sat->setSatelliteType(strarray[0]); - sat->setIsTime(helperfns_read_bool(strarray[1], true)); - sat->setActive(helperfns_read_bool(strarray[2], true)); - sat->setHasMirror(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[4], false)); + sat->setIsTime(strncmp(strarray[1],"1",1) == 0); + sat->setActive(strncmp(strarray[2],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); + sat->setHidden(strncmp(strarray[4],"1",1) == 0); double time,size; sp_svg_number_read_d(strarray[5], &size); sp_svg_number_read_d(strarray[6], &time); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index e9775da24..ff406d792 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -117,13 +117,13 @@ protected: str << ","; str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << g_strdup(nVector.second.getIsTime() ? "true" : "false"); + str << nVector.second.getIsTime(); str << "*"; - str << g_strdup(nVector.second.getActive() ? "true" : "false"); + str << nVector.second.getActive(); str << "*"; - str << g_strdup(nVector.second.getHasMirror() ? "true" : "false"); + str << nVector.second.getHasMirror(); str << "*"; - str << g_strdup(nVector.second.getHidden() ? "true" : "false"); + str << nVector.second.getHidden(); str << "*"; str << nVector.second.getSize(); str << "*"; -- cgit v1.2.3 From 00d08a0f4bca11e775bbacf3d512676a0493c1a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 01:18:02 +0100 Subject: adding mirror knot (bzr r13645.1.25) --- src/live_effects/lpe-fillet-chamfer.cpp | 25 ++++++--- src/live_effects/parameter/array.cpp | 10 ++-- src/live_effects/parameter/array.h | 4 +- src/live_effects/parameter/satellitepairarray.cpp | 62 ++++++++++++++++++++--- src/live_effects/parameter/satellitepairarray.h | 11 ++-- 5 files changed, 86 insertions(+), 26 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 39acdca80..41c6a7090 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -65,8 +65,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (shape) { PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, .01); - satellitepairarrayparam_values.set_pwd2(pwd2_in); + pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -110,6 +109,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counterTotal++; } } + pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -130,20 +130,31 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); - pwd2_in = remove_short_cuts(pwd2_in, .01); + pwd2_in = remove_short_cuts(pwd2_in, 0.01); //wating to recalculate //recalculate_controlpoints_for_new_pwd2(pwd2_in); - satellitepairarrayparam_values.set_pwd2(pwd2_in); std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise = new Pointwise( pwd2_in,satellites); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); bool changed = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); + double ammount = it->second.getAmmount(); + D2 d2_in = pwd2_in[it->first]; + if(it->second.getIsTime()){ + double time = it->second.toTime(ammount,d2_in); + it->second.setAmmount(time); + } else { + double size = it->second.toSize(ammount,d2_in); + it->second.setAmmount(size); + } changed = true; } } if(changed){ + pointwise->setSatellites(satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } } else { @@ -207,13 +218,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(first == counter){ satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - time0 = satVector[0].getTime(); + time0 = satVector[0].getTime(curve_it2Fixed->toSBasis()); } } bool last = curve_it2 == curve_endit; double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); - double time2 = sat.getTime(); + double time2 = sat.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 6dad9fcc8..2c3d823a5 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -60,11 +60,11 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setActive(strncmp(strarray[2],"1",1) == 0); sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); sat->setHidden(strncmp(strarray[4],"1",1) == 0); - double time,size; - sp_svg_number_read_d(strarray[5], &size); - sp_svg_number_read_d(strarray[6], &time); - sat->setSize(size); - sat->setTime(time); + double ammount,angle; + sp_svg_number_read_d(strarray[5], &ammount); + sp_svg_number_read_d(strarray[6], &angle); + sat->setAmmount(ammount); + sat->setAngle(angle); g_strfreev (strarray); return 1; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index ff406d792..1a5823199 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -125,9 +125,9 @@ protected: str << "*"; str << nVector.second.getHidden(); str << "*"; - str << nVector.second.getSize(); + str << nVector.second.getAmmount(); str << "*"; - str < > const &pwd2_in) +void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { - last_pwd2 = pwd2_in; + last_pointwise = pointwise; } void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, @@ -55,6 +54,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); const gchar *tip; tip = _("Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " @@ -67,6 +67,19 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } +void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, int i) +{ + const gchar *tip; + tip = _("Mirror ppp"); + SatellitePairArrayParamKnotHolderEntity *e = + new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); +} + SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) : _pparam(p), @@ -80,8 +93,28 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) { - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point s = snap_knot_position(p, state); + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if(_pparam->_vector.size() <= _index){ + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + double mirrorTime = Geom::nearest_point(s, *d2_in); + double size = satellite.second.toSize(mirrorTime, *d2_in); + double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; + double time = satellite.second.toTime(lenght,pwd2[satellite.first]); + s = pwd2[satellite.first].valueAt(time); + satellite.second.setPosition(s,pwd2[satellite.first]); + } + } else { + satellite.second.setPosition(s,pwd2[satellite.first]); + } + _pparam->_vector.at(index) = satellite; SPLPEItem * splpeitem = dynamic_cast(item); if(splpeitem){ sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -91,7 +124,24 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Geom::Point SatellitePairArrayParamKnotHolderEntity::knot_get() const { - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point tmpPoint; + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if( _index >= _pparam->_vector.size()){ + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + } + } else { + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + } + Geom::Point const canvas_point = tmpPoint; return canvas_point; } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index ff1924829..dde844fd1 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -21,6 +21,7 @@ #include #include "live_effects/parameter/array.h" #include "knot-holder-entity.h" +#include <2geom/pointwise.h> namespace Inkscape { @@ -47,10 +48,8 @@ public: return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void set_pwd2(Geom::Piecewise > const &pwd2_in); - Geom::Piecewise > const &get_pwd2() const { - return last_pwd2; - } + virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; private: @@ -60,8 +59,8 @@ private: SPKnotShapeType knot_shape; SPKnotModeType knot_mode; guint32 knot_color; - - Geom::Piecewise > last_pwd2; + + Geom::Pointwise *last_pointwise; }; -- cgit v1.2.3 From f77b5496f69a5391bc548be95c85659539a92fe9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 23:23:56 +0100 Subject: added mirror knots (bzr r13645.1.26) --- src/live_effects/lpe-fillet-chamfer.cpp | 48 +++++++++++++++++------ src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/array.cpp | 14 ++++--- src/live_effects/parameter/array.h | 4 ++ src/live_effects/parameter/satellitepairarray.cpp | 35 ++++++++++++++++- 5 files changed, 81 insertions(+), 21 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 41c6a7090..d46d0f4ff 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -48,11 +48,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), + mirrorKnots(_("Mirror Knots"), _("Mirror Knots"), "mirrorKnots", &wr, this, true), pointwise() { registerParameter(&satellitepairarrayparam_values); registerParameter(&method); registerParameter(&flexible); + registerParameter(&mirrorKnots); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -90,24 +92,36 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(F, flexible, true, false, false, 0.0, 0.0); - Geom::NodeType nodetype; + bool isStart = false; + if(counter == 0){ + isStart = true; + } + bool isClosing = false; + if(path_it->closed() && curve_it1 == curve_end){ + isClosing = true; + } + bool active = true; + bool hidden = false; if (counter==0) { if (path_it->closed()) { - nodetype = get_nodetype(*curve_end, *curve_it1); } else { - nodetype = NODE_NONE; + active = false; } - } else { - nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); - } - if (nodetype == NODE_CUSP) { - satellites.push_back(std::make_pair(counterTotal, satellite)); } + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; counterTotal++; } + if (!path_it->closed()){ + bool active = false; + bool isClosing = false; + bool isStart = false; + bool hidden = false; + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); + } } pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); @@ -152,6 +166,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } changed = true; } + if(it->second.getHasMirror() != mirrorKnots){ + it->second.setHasMirror(mirrorKnots); + changed = true; + } } if(changed){ pointwise->setSatellites(satellites); @@ -218,12 +236,16 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(first == counter){ satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - time0 = satVector[0].getTime(curve_it2Fixed->toSBasis()); + time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); } } bool last = curve_it2 == curve_endit; - double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); + double s = sat.getAmmount(); + if(sat.getIsTime()){ + s = sat.toSize(s, curve_it2Fixed->toSBasis()); + } + double time1 = sat.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = sat.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; @@ -249,7 +271,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1-gapHelper); + startArcPoint = curve_it1->pointAt(times[0]+gapHelper); } double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; @@ -289,7 +311,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1); + startArcPoint = curve_it1->pointAt(times[0]); } Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f5c4f14ea..149a2d743 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -43,6 +43,7 @@ public: private: EnumParam method; BoolParam flexible; + BoolParam mirrorKnots; Geom::Pointwise *pointwise; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 2c3d823a5..c00cdd8da 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,15 +54,17 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[6] && !strarray[7]){ + if(strarray[8] && !strarray[9]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setActive(strncmp(strarray[2],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); - sat->setHidden(strncmp(strarray[4],"1",1) == 0); + sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); + sat->setIsStart(strncmp(strarray[3],"1",1) == 0); + sat->setActive(strncmp(strarray[4],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); + sat->setHidden(strncmp(strarray[6],"1",1) == 0); double ammount,angle; - sp_svg_number_read_d(strarray[5], &ammount); - sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_d(strarray[7], &ammount); + sp_svg_number_read_d(strarray[8], &angle); sat->setAmmount(ammount); sat->setAngle(angle); g_strfreev (strarray); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 1a5823199..0be155f50 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -119,6 +119,10 @@ protected: str << "*"; str << nVector.second.getIsTime(); str << "*"; + str << nVector.second.getIsClosing(); + str << "*"; + str << nVector.second.getIsStart(); + str << "*"; str << nVector.second.getActive(); str << "*"; str << nVector.second.getHasMirror(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index e6f0c03f9..7a35df28f 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,7 +54,9 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { - addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + if(_vector[i].second.getHasMirror()){ + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + } const gchar *tip; tip = _("Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " @@ -105,10 +107,20 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ double mirrorTime = Geom::nearest_point(s, *d2_in); + double timeStart = 0; + std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); + if(satVector.size()>0){ + timeStart = satVector[0].getTime(*d2_in); + } + if(timeStart > mirrorTime){ + mirrorTime = timeStart; + } double size = satellite.second.toSize(mirrorTime, *d2_in); double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; double time = satellite.second.toTime(lenght,pwd2[satellite.first]); + std::cout << time << "time\n"; s = pwd2[satellite.first].valueAt(time); + std::cout << s << "s\n"; satellite.second.setPosition(s,pwd2[satellite.first]); } } else { @@ -136,7 +148,26 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ - tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + double s = satellite.second.getAmmount(); + if(satellite.second.getIsTime()){ + s = satellite.second.toSize(s, pwd2[satellite.first]); + } + double t = satellite.second.getOpositeTime(s,*d2_in); + if(t > 1){ + t = 1; + } + if(t < 0){ + t = 0; + } + double timeStart = 0; + std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); + if(satVector.size()>0){ + timeStart = satVector[0].getTime(*d2_in); + } + if(timeStart > t){ + t = timeStart; + } + tmpPoint = (*d2_in).valueAt(t); } } else { tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); -- cgit v1.2.3 From ef1da924221c3ab94e0c7bedf580f4a930459aa4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 00:11:38 +0100 Subject: added more fillet/chamfer properties (bzr r13645.1.28) --- src/live_effects/lpe-fillet-chamfer.cpp | 312 +++++++++++++++++++--- src/live_effects/lpe-fillet-chamfer.h | 23 +- src/live_effects/parameter/satellitepairarray.cpp | 5 +- 3 files changed, 295 insertions(+), 45 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d46d0f4ff..802340698 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -27,6 +27,8 @@ #include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" +#include "ui/tools-switch.h" +#include <2geom/path-intersection.h> #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -45,16 +47,37 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), + satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 3), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - mirrorKnots(_("Mirror Knots"), _("Mirror Knots"), "mirrorKnots", &wr, this, true), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), + only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), + use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), + ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), pointwise() { registerParameter(&satellitepairarrayparam_values); + registerParameter(&unit); registerParameter(&method); + registerParameter(&radius); + registerParameter(&chamfer_steps); registerParameter(&flexible); - registerParameter(&mirrorKnots); + registerParameter(&use_knot_distance); + registerParameter(&mirror_knots); + registerParameter(&ignore_radius_0); + registerParameter(&only_selected); + registerParameter(&hide_knots); + + radius.param_set_range(0., infinity()); + radius.param_set_increments(1, 1); + radius.param_set_digits(4); + chamfer_steps.param_set_range(1, 999); + chamfer_steps.param_set_increments(1, 1); + chamfer_steps.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -108,7 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -119,7 +142,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool isClosing = false; bool isStart = false; bool hidden = false; - Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); } } @@ -132,6 +155,222 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } +Gtk::Widget *LPEFilletChamfer::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = param->param_newWidget(); + if (param->param_key == "radius") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(6); + } + /*} else if (param->param_key == "chamfer_steps") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(3); + } + + } else if (param->param_key == "helper_size") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + */ + } else if (param->param_key == "only_selected") { + Gtk::manage(widg); + }/* else if (param->param_key == "ignore_radius_0") { + Gtk::manage(widg); + } + */ + 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; + } + + Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + + filletContainer->pack_start(*fillet, true, true, 2); + Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + filletContainer->pack_start(*inverseFillet, true, true, 2); + + Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + + chamferContainer->pack_start(*chamfer, true, true, 2); + Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + chamferContainer->pack_start(*inverseChamfer, true, true, 2); + + vbox->pack_start(*filletContainer, true, true, 2); + vbox->pack_start(*chamferContainer, true, true, 2); + + return vbox; +} + + +void LPEFilletChamfer::fillet() +{ + updateSatelliteType(F); +} + +void LPEFilletChamfer::inverseFillet() +{ + updateSatelliteType(IF); +} + +void LPEFilletChamfer::chamfer() +{ + updateSatelliteType(C); +} + +void LPEFilletChamfer::inverseChamfer() +{ + updateSatelliteType(IC); +} + +/* +double LPEFilletChamfer::len_to_rad(double A, std::pair satellite) +{ + Piecewise > pwd2 = pointwise->getPwd2(); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + Geom::D2 d2_out = pwd2[satellite.first]; + double time_in = satellite.second.getOpositeTime(A, *d2_in); + double time_out = satellite.second.toTime(A,d2_out); + Geom::Point startArcPoint = (*d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + Ray ray2(d2_out.valueAt(0), endArcPoint); + bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; + double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); + double angleBetween = angle_between(ray1, ray2, ccwToggle); + return distanceArc/sin(angleBetween/2.0); + } + return 0; +} +*/ + +double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) +{ + double len = 0; + Piecewise > pwd2 = pointwise->getPwd2(); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + Geom::D2 d2_out = pwd2[satellite.first]; + Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative((*d2_in))))*(A); + Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; + Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; + Geom::Crossings cs = Geom::crossings(p0, p1); + if(cs.size() > 0){ + Point cp =p0(cs[0].ta); + double p0pt = nearest_point(cp, d2_out); + len = satellite.second.toSize(p0pt,d2_out); + } else { + if(A < 0){ + len = rad_to_len(A * -1, satellite); + } + } + } + return len; +} + + +void LPEFilletChamfer::refreshKnots() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (tools_isactive(desktop, TOOLS_NODES)) { + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); + } +} + +void LPEFilletChamfer::updateFillet() +{ + double power = 0; + if (!flexible) { + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit); + } else { + power = radius/100; + } + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setAmmount(power); + } + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } + } else { + it->second.setAmmount(power); + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + +void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +{ + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setSatelliteType(satellitetype); + } + } else { + it->second.setSatelliteType(satellitetype); + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); @@ -152,6 +391,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setSatellites(satellites); satellitepairarrayparam_values.set_pointwise(pointwise); bool changed = false; + bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); @@ -166,15 +406,25 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } changed = true; } - if(it->second.getHasMirror() != mirrorKnots){ - it->second.setHasMirror(mirrorKnots); + if(it->second.getHasMirror() != mirror_knots){ + it->second.setHasMirror(mirror_knots); changed = true; + refresh = true; + } + bool hide = !hide_knots; + if(it->second.getHidden() != hide){ + it->second.setHidden(hide); + changed = true; + refresh = true; } } if(changed){ pointwise->setSatellites(satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } + if(refresh){ + refreshKnots(); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -219,18 +469,18 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) return path_in; } std::vector satVector; - Satellite sat; + Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); satVector = pointwise->findSatellites(counter+1,1); if(satVector.size()>0){ - sat = satVector[0]; + satellite = satVector[0]; } } else { satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - sat = satVector[0]; + satellite = satVector[0]; } } if(first == counter){ @@ -241,12 +491,12 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = sat.getAmmount(); - if(sat.getIsTime()){ - s = sat.toSize(s, curve_it2Fixed->toSBasis()); + double s = satellite.getAmmount(); + if(satellite.getIsTime()){ + s = satellite.toSize(s, curve_it2Fixed->toSBasis()); } - double time1 = sat.getOpositeTime(s,(*curve_it1).toSBasis()); - double time2 = sat.getTime(curve_it2Fixed->toSBasis()); + double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); + double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; } @@ -254,10 +504,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) times.push_back(time0); times.push_back(time1); times.push_back(time2); - std::cout << ":::" << counter << ":::::::::::::::\n"; - std::cout << time0 << "::Time 0\n"; - std::cout << time1 << "::Time 1\n"; - std::cout << time2 << "::Time 2\n"; Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); @@ -325,13 +571,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_out.append(*knotCurve1); } } - SatelliteType type = F; - type = sat.getSatelliteType(); - if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - // path_out.appendNew(endArcPoint); - } else if (type == C) { - /* - unsigned int chamferSubs = type-3000; + SatelliteType type = satellite.getSatelliteType(); + if (type == C) { Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ @@ -339,16 +580,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { path_chamfer.appendNew(handle1, handle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ + double chamfer_stepsTime = 1.0/chamfer_steps; + for(unsigned int i = 1; i < chamfer_steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } path_out.appendNew(endArcPoint); - /*/ } else if (type == IC) { - /* - unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ @@ -357,13 +595,12 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) }else{ path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ + double chamfer_stepsTime = 1.0/chamfer_steps; + for(unsigned int i = 1; i < chamfer_steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } path_out.appendNew(endArcPoint); - */ } else if (type == IF) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; @@ -386,13 +623,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (path_it->closed() && last) { path_out.close(); } - /* - if(!path_it->closed() || curve_it2 != curve_endit){ - satellites[counter + 1] = std::make_pair(counter + 1, sat); - } else { - satellites[first] = std::make_pair(first, sat); - } - */ ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 149a2d743..44c8b113f 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,6 +15,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/parameter/enum.h" +#include "live_effects/parameter/unit.h" #include "2geom/pointwise.h" #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" @@ -37,13 +38,31 @@ public: virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); - + virtual Gtk::Widget* newWidget(); + /*double len_to_rad(double A, std::pair sat);*/ + double rad_to_len(double A, std::pair satellite); + void updateSatelliteType(Geom::SatelliteType satellitetype); + void updateFillet(); + void refreshKnots(); + void chamfer(); + void inverseChamfer(); + void fillet(); + void inverseFillet(); + SatellitePairArrayParam satellitepairarrayparam_values; private: + UnitParam unit; EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; BoolParam flexible; - BoolParam mirrorKnots; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam ignore_radius_0; + Geom::Pointwise *pointwise; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 7a35df28f..beda9ecbf 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,6 +54,9 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + continue; + } if(_vector[i].second.getHasMirror()){ addKnotHolderEntitieMirrored(knotholder, desktop, item, i); } @@ -118,9 +121,7 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, double size = satellite.second.toSize(mirrorTime, *d2_in); double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; double time = satellite.second.toTime(lenght,pwd2[satellite.first]); - std::cout << time << "time\n"; s = pwd2[satellite.first].valueAt(time); - std::cout << s << "s\n"; satellite.second.setPosition(s,pwd2[satellite.first]); } } else { -- cgit v1.2.3 From 60327dd47f6bbbb0d30c13c905117bd8b3be5e5d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 23:54:42 +0100 Subject: added helper paths and fixed some bugs (bzr r13645.1.30) --- src/live_effects/lpe-fillet-chamfer.cpp | 66 ++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/satellitepairarray.cpp | 87 +++++++++++++++++++++-- src/live_effects/parameter/satellitepairarray.h | 9 ++- 4 files changed, 121 insertions(+), 42 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 802340698..a8e2ea6b8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -58,6 +58,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), + helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,6 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); + registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); @@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, infinity()); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -126,8 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool active = true; bool hidden = false; if (counter==0) { - if (path_it->closed()) { - } else { + if (!path_it->closed()) { active = false; } } @@ -179,27 +183,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(6); } - /*} else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); - } - } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - */ } else if (param->param_key == "only_selected") { Gtk::manage(widg); - }/* else if (param->param_key == "ignore_radius_0") { - Gtk::manage(widg); } - */ Glib::ustring *tip = param->param_getTooltip(); if (widg) { vbox->pack_start(*widg, true, true, 2); @@ -211,7 +200,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } } } - ++it; } @@ -285,24 +273,25 @@ double LPEFilletChamfer::len_to_rad(double A, std::pair sa double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) { double len = 0; + std::cout << A << "A\n"; Piecewise > pwd2 = pointwise->getPwd2(); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ + std::cout << satellite.first << "satellite.first\n"; + std::cout << "d2in\n"; Geom::D2 d2_out = pwd2[satellite.first]; - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative((*d2_in))))*(A); + Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; Geom::Crossings cs = Geom::crossings(p0, p1); if(cs.size() > 0){ Point cp =p0(cs[0].ta); + std::cout << cp << "cp\n"; double p0pt = nearest_point(cp, d2_out); len = satellite.second.toSize(p0pt,d2_out); - } else { - if(A < 0){ - len = rad_to_len(A * -1, satellite); - } } + std::cout << len << "len\n"; } return len; } @@ -328,21 +317,27 @@ void LPEFilletChamfer::updateFillet() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ + it->second.setAmmount(0); + continue; + } if(ignore_radius_0 && it->second.getAmmount() == 0){ continue; } if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ - it->second.setAmmount(power); - } - if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } else { + it->second.setAmmount(power); + } } } else { - it->second.setAmmount(power); if(!use_knot_distance && !flexible){ it->second.setAmmount(rad_to_len(power,*it)); + } else { + it->second.setAmmount(power); } } } @@ -384,12 +379,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - //wating to recalculate - //recalculate_controlpoints_for_new_pwd2(pwd2_in); std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise->setPwd2(pwd2_in); - pointwise->setSatellites(satellites); + pointwise = new Pointwise(pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); + if(hide_knots){ + satellitepairarrayparam_values.set_helper_size(0); + } else { + satellitepairarrayparam_values.set_helper_size(helper_size); + } bool changed = false; bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { @@ -491,10 +488,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.getAmmount(); - if(satellite.getIsTime()){ - s = satellite.toSize(s, curve_it2Fixed->toSBasis()); - } + double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 44c8b113f..c194d2edd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,6 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; + ScalarParam helper_size; Geom::Pointwise *pointwise; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index beda9ecbf..72a666dc2 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -31,6 +31,14 @@ SatellitePairArrayParam::SatellitePairArrayParam( knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; knot_color = 0x00ff0000; + /* + std::vector > satellites; + Geom::Path path; + path.start(Geom::Point(0,0)); + path.appendNew(Geom::Point(0,1)); + last_pointwise = new Pointwise(path.toPwSb(),satellites); + */ + last_pointwise = NULL; } SatellitePairArrayParam::~SatellitePairArrayParam() {} @@ -49,6 +57,74 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } +void SatellitePairArrayParam::set_helper_size(int hs) +{ + helper_size = hs; + updateCanvasIndicators(); +} + +void SatellitePairArrayParam::updateCanvasIndicators() +{ + Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); + hp.clear(); + bool mirrorPass = false; + for (unsigned int i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + continue; + } + double pos = 0; + if(pwd2.size() <= _vector[i].first){ + break; + } + Geom::D2 d2 = pwd2[_vector[i].first]; + if(mirrorPass == true){ + double size = _vector[i].second.getSize(pwd2[_vector[i].first]); + boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + if(curve_in){ + d2 = *curve_in; + pos = _vector[i].second.getOpositeTime(size,*curve_in); + } + } else { + pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + } + if (pos == 0) { + continue; + } + Geom::Point ptA = d2.valueAt(pos); + Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + derivA = derivA * rot; + Geom::Point C = ptA - derivA * helper_size; + Geom::Point D = ptA + derivA * helper_size; + Geom::Ray ray1(C, D); + char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(helper_size); + if(mirrorPass == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + hp.push_back(pathv[1]); + if(_vector[i].second.getHasMirror() && mirrorPass == false){ + mirrorPass = true; + i--; + } else { + mirrorPass = false; + } + } +} + +void SatellitePairArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) @@ -103,6 +179,9 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } + if( _pparam->last_pointwise == NULL){ + return; + } std::pair satellite = _pparam->_vector.at(index); Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); @@ -143,16 +222,16 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const index = _index-_pparam->_vector.size(); } std::pair satellite = _pparam->_vector.at(index); + if( _pparam->last_pointwise == NULL){ + return Geom::Point(0,0); + } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ - double s = satellite.second.getAmmount(); - if(satellite.second.getIsTime()){ - s = satellite.second.toSize(s, pwd2[satellite.first]); - } + double s = satellite.second.getSize(pwd2[satellite.first]); double t = satellite.second.getOpositeTime(s,*d2_in); if(t > 1){ t = 1; diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index dde844fd1..1ecc1fee6 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -44,11 +44,14 @@ public: void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + virtual void set_helper_size(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void updateCanvasIndicators(); void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; @@ -59,6 +62,8 @@ private: SPKnotShapeType knot_shape; SPKnotModeType knot_mode; guint32 knot_color; + Geom::PathVector hp; + int helper_size; Geom::Pointwise *last_pointwise; -- cgit v1.2.3 From 885ed9addb9a67398e74176fd541c3415c5f44d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 18:04:02 +0100 Subject: Fix radian to lenght conversion and minior bugs (bzr r13645.1.31) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a8e2ea6b8..786945cd0 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -145,7 +145,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool active = false; bool isClosing = false; bool isStart = false; - bool hidden = false; + bool hidden = true; Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); } @@ -290,6 +290,10 @@ double LPEFilletChamfer::rad_to_len(double A, std::pair sa std::cout << cp << "cp\n"; double p0pt = nearest_point(cp, d2_out); len = satellite.second.toSize(p0pt,d2_out); + } else { + if(A > 0){ + len = rad_to_len(A * -1, satellite); + } } std::cout << len << "len\n"; } @@ -491,6 +495,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); + if(!satellite.getActive()){ + time1 = 1; + time0 = 0; + } if(time1 <= time0){ time1 = time0; } -- cgit v1.2.3 From 1db09cce6114c1b2d95ac77b00672caad0447b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 23:42:59 +0100 Subject: All features done, only need piecewise update function (bzr r13645.1.33) --- src/live_effects/lpe-fillet-chamfer.cpp | 127 ++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 4 +- src/live_effects/parameter/array.cpp | 12 +- src/live_effects/parameter/array.h | 4 +- src/live_effects/parameter/satellitepairarray.cpp | 161 ++++++++++++++++++++-- src/live_effects/parameter/satellitepairarray.h | 12 +- 6 files changed, 226 insertions(+), 94 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 786945cd0..118a89ead 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -28,7 +28,6 @@ #include "helper/geom.h" #include "display/curve.h" #include "ui/tools-switch.h" -#include <2geom/path-intersection.h> #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -97,7 +96,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -119,6 +118,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; + unsigned int steps = 0; while (curve_it1 != curve_endit) { bool isStart = false; if(counter == 0){ @@ -135,7 +135,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -146,7 +146,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool isClosing = false; bool isStart = false; bool hidden = true; - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); } } @@ -175,7 +175,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmmount)); widg = widgRegistered; if (widg) { Gtk::HBox *scalarParameter = dynamic_cast(widg); @@ -183,6 +183,16 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(6); } + } else if (param->param_key == "chamfer_steps") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(3); + } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); @@ -248,59 +258,6 @@ void LPEFilletChamfer::inverseChamfer() updateSatelliteType(IC); } -/* -double LPEFilletChamfer::len_to_rad(double A, std::pair satellite) -{ - Piecewise > pwd2 = pointwise->getPwd2(); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - Geom::D2 d2_out = pwd2[satellite.first]; - double time_in = satellite.second.getOpositeTime(A, *d2_in); - double time_out = satellite.second.toTime(A,d2_out); - Geom::Point startArcPoint = (*d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Ray ray1(startArcPoint, (*d2_in).valueAt(1)); - Ray ray2(d2_out.valueAt(0), endArcPoint); - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - return distanceArc/sin(angleBetween/2.0); - } - return 0; -} -*/ - -double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) -{ - double len = 0; - std::cout << A << "A\n"; - Piecewise > pwd2 = pointwise->getPwd2(); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - std::cout << satellite.first << "satellite.first\n"; - std::cout << "d2in\n"; - Geom::D2 d2_out = pwd2[satellite.first]; - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); - Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); - Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; - Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; - Geom::Crossings cs = Geom::crossings(p0, p1); - if(cs.size() > 0){ - Point cp =p0(cs[0].ta); - std::cout << cp << "cp\n"; - double p0pt = nearest_point(cp, d2_out); - len = satellite.second.toSize(p0pt,d2_out); - } else { - if(A > 0){ - len = rad_to_len(A * -1, satellite); - } - } - std::cout << len << "len\n"; - } - return len; -} - - void LPEFilletChamfer::refreshKnots() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -310,7 +267,7 @@ void LPEFilletChamfer::refreshKnots() } } -void LPEFilletChamfer::updateFillet() +void LPEFilletChamfer::updateAmmount() { double power = 0; if (!flexible) { @@ -318,9 +275,9 @@ void LPEFilletChamfer::updateFillet() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ it->second.setAmmount(0); continue; @@ -332,14 +289,14 @@ void LPEFilletChamfer::updateFillet() Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + it->second.setAmmount(pointwise->rad_to_len(power,*it)); } else { it->second.setAmmount(power); } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + it->second.setAmmount(pointwise->rad_to_len(power,*it)); } else { it->second.setAmmount(power); } @@ -349,11 +306,32 @@ void LPEFilletChamfer::updateFillet() satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } +void LPEFilletChamfer::updateChamferSteps() +{ + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setSteps(chamfer_steps); + } + } else { + it->second.setSteps(chamfer_steps); + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmmount() == 0){ continue; } @@ -383,7 +361,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > satellites = satellitepairarrayparam_values.data(); + std::vector > satellites = satellitepairarrayparam_values.data(); pointwise = new Pointwise(pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); if(hide_knots){ @@ -391,9 +369,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellitepairarrayparam_values.set_helper_size(helper_size); } + satellitepairarrayparam_values.set_document_unit(defaultUnit); + satellitepairarrayparam_values.set_use_distance(use_knot_distance); + satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); bool changed = false; bool refresh = false; - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); double ammount = it->second.getAmmount(); @@ -574,6 +555,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } SatelliteType type = satellite.getSatelliteType(); + unsigned int steps = satellite.getSteps(); + if(steps < 1){ + steps = 1; + } if (type == C) { Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); @@ -582,8 +567,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { path_chamfer.appendNew(handle1, handle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamfer_steps; - for(unsigned int i = 1; i < chamfer_steps; i++){ + double chamfer_stepsTime = 1.0/steps; + for(unsigned int i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } @@ -597,8 +582,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) }else{ path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamfer_steps; - for(unsigned int i = 1; i < chamfer_steps; i++){ + double chamfer_stepsTime = 1.0/steps; + for(unsigned int i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index c194d2edd..56db6305e 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,9 +40,9 @@ public: virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); /*double len_to_rad(double A, std::pair sat);*/ - double rad_to_len(double A, std::pair satellite); void updateSatelliteType(Geom::SatelliteType satellitetype); - void updateFillet(); + void updateChamferSteps(); + void updateAmmount(); void refreshKnots(); void chamfer(); void inverseChamfer(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c00cdd8da..e4c480d93 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,7 +54,7 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[8] && !strarray[9]){ + if(strarray[9] && !strarray[10]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); @@ -63,10 +63,14 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); sat->setHidden(strncmp(strarray[6],"1",1) == 0); double ammount,angle; + float stepsTmp; sp_svg_number_read_d(strarray[7], &ammount); sp_svg_number_read_d(strarray[8], &angle); + sp_svg_number_read_f(strarray[9], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; sat->setAmmount(ammount); sat->setAngle(angle); + sat->setSteps(steps); g_strfreev (strarray); return 1; } @@ -75,12 +79,12 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); double index; - std::pair result; + std::pair result; unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 0be155f50..d28576fce 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -112,7 +112,7 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; str << nVector.second.getSatelliteTypeGchar(); @@ -132,6 +132,8 @@ protected: str << nVector.second.getAmmount(); str << "*"; str << nVector.second.getAngle(); + str << "*"; + str << nVector.second.getSteps(); } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 72a666dc2..ffd04e14c 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -9,6 +9,7 @@ */ #include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" #include "live_effects/parameter/satellitepairarray.h" #include "sp-lpe-item.h" // TODO due to internal breakage in glibmm headers, @@ -26,18 +27,14 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; knot_color = 0x00ff0000; - /* - std::vector > satellites; - Geom::Path path; - path.start(Geom::Point(0,0)); - path.appendNew(Geom::Point(0,1)); - last_pointwise = new Pointwise(path.toPwSb(),satellites); - */ + helper_size = 0; + use_distance = false; + last_pointwise = NULL; } @@ -57,6 +54,21 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } +void SatellitePairArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +{ + documentUnit = value_document_unit; +} + +void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) +{ + use_distance = use_knot_distance; +} + +void SatellitePairArrayParam::set_unit(const gchar *abbr) +{ + unit = abbr; +} + void SatellitePairArrayParam::set_helper_size(int hs) { helper_size = hs; @@ -73,7 +85,7 @@ void SatellitePairArrayParam::updateCanvasIndicators() continue; } double pos = 0; - if(pwd2.size() <= _vector[i].first){ + if(pwd2.size() <= (unsigned)_vector[i].first){ break; } Geom::D2 d2 = pwd2[_vector[i].first]; @@ -136,10 +148,26 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if(_vector[i].second.getHasMirror()){ addKnotHolderEntitieMirrored(knotholder, desktop, item, i); } + using namespace Geom; + SatelliteType type = _vector[i].second.getSatelliteType(); const gchar *tip; - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } SatellitePairArrayParamKnotHolderEntity *e = new SatellitePairArrayParamKnotHolderEntity(this, i); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), @@ -152,8 +180,26 @@ void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholde SPDesktop *desktop, SPItem *item, int i) { + using namespace Geom; + SatelliteType type = _vector[i].second.getSatelliteType(); const gchar *tip; - tip = _("Mirror ppp"); + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } SatellitePairArrayParamKnotHolderEntity *e = new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), @@ -257,6 +303,95 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const } +void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) +{ + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector.at(index).second.setAmmount(0.0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }else{ + using namespace Geom; + SatelliteType type = _pparam->_vector.at(index).second.getSatelliteType(); + switch(type){ + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; + } + _pparam->_vector.at(index).second.setSatelliteType(type); + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + double ammount = _pparam->_vector.at(index).second.getAmmount(); + if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ + ammount = _pparam->last_pointwise->len_to_rad(ammount, _pparam->_vector.at(index)); + } + boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); + bool aprox = false; + D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; + if(d2_in){ + aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, ammount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); + + } +} + +void SatellitePairArrayParamKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +{ + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + double ammount = satellite.getAmmount(); + if(!_pparam->use_distance && !satellite.getIsTime()){ + ammount = _pparam->last_pointwise->rad_to_len(ammount, _pparam->_vector.at(index)); + } + satellite.setAmmount(ammount); + _pparam->_vector.at(index).second = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 1ecc1fee6..21fb0fbd8 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -29,7 +29,7 @@ namespace LivePathEffect { class SatellitePairArrayParamKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam > { +class SatellitePairArrayParam : public ArrayParam > { public: SatellitePairArrayParam(const Glib::ustring &label, const Glib::ustring &tip, @@ -51,6 +51,9 @@ public: virtual bool providesKnotHolderEntities() const { return true; } + void set_document_unit(Glib::ustring const * value_document_unit); + void set_use_distance(bool use_knot_distance ); + void set_unit(const gchar *abbr); virtual void updateCanvasIndicators(); void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; @@ -64,7 +67,9 @@ private: guint32 knot_color; Geom::PathVector hp; int helper_size; - + bool use_distance; + const gchar *unit; + Glib::ustring const * documentUnit; Geom::Pointwise *last_pointwise; }; @@ -76,7 +81,8 @@ public: 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); + void knot_set_offset(Geom::Satellite); /** Checks whether the index falls within the size of the parameter's vector */ bool valid_index(unsigned int index) const { return (_pparam->_vector.size() > index); -- cgit v1.2.3 From 62ebac099d8fa013e34a773c0fe3aee56b5a5758 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Mar 2015 13:55:16 +0100 Subject: finish helper paths and beter handle of fillet/chamfer overflow. Also make the satellitepairarray LPE parameter usable for other pointwise effects, not only to fillet chamfer (bzr r13645.1.35) --- src/live_effects/lpe-fillet-chamfer.cpp | 53 +++--- src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/array.cpp | 6 +- src/live_effects/parameter/array.h | 2 +- src/live_effects/parameter/satellitepairarray.cpp | 217 +++++++++++++--------- src/live_effects/parameter/satellitepairarray.h | 16 +- 6 files changed, 180 insertions(+), 116 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 118a89ead..d979171be 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -79,7 +79,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, infinity()); + helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); } @@ -175,7 +175,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmmount)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widgRegistered; if (widg) { Gtk::HBox *scalarParameter = dynamic_cast(widg); @@ -267,7 +267,7 @@ void LPEFilletChamfer::refreshKnots() } } -void LPEFilletChamfer::updateAmmount() +void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { @@ -279,26 +279,26 @@ void LPEFilletChamfer::updateAmmount() Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ - it->second.setAmmount(0); + it->second.setAmount(0); continue; } - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmmount(pointwise->rad_to_len(power,*it)); + it->second.setAmount(pointwise->rad_to_len(power,*it)); } else { - it->second.setAmmount(power); + it->second.setAmount(power); } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmmount(pointwise->rad_to_len(power,*it)); + it->second.setAmount(pointwise->rad_to_len(power,*it)); } else { - it->second.setAmmount(power); + it->second.setAmount(power); } } } @@ -311,7 +311,7 @@ void LPEFilletChamfer::updateChamferSteps() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ @@ -332,7 +332,7 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ @@ -358,33 +358,40 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(path){ c = path->get_original_curve(); } + //fillet chamfer specific calls + satellitepairarrayparam_values.set_document_unit(defaultUnit); + satellitepairarrayparam_values.set_use_distance(use_knot_distance); + satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); + //mandatory call + satellitepairarrayparam_values.set_effect_type(this->effectType()); + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); + Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > satellites = satellitepairarrayparam_values.data(); pointwise = new Pointwise(pwd2_in,satellites); + + //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { satellitepairarrayparam_values.set_helper_size(helper_size); } - satellitepairarrayparam_values.set_document_unit(defaultUnit); - satellitepairarrayparam_values.set_use_distance(use_knot_distance); - satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); bool changed = false; bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); - double ammount = it->second.getAmmount(); + double amount = it->second.getAmount(); D2 d2_in = pwd2_in[it->first]; if(it->second.getIsTime()){ - double time = it->second.toTime(ammount,d2_in); - it->second.setAmmount(time); + double time = it->second.toTime(amount,d2_in); + it->second.setAmount(time); } else { - double size = it->second.toSize(ammount,d2_in); - it->second.setAmmount(size); + double size = it->second.toSize(amount,d2_in); + it->second.setAmount(size); } changed = true; } @@ -483,6 +490,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time1 <= time0){ time1 = time0; } + std::cout << counter << ":::::::::::::::::::::::::::::\n"; + std::cout << time0 << "time0\n"; + std::cout << time1 << "time1\n"; + std::cout << time2 << "time2\n"; std::vector times; times.push_back(time0); times.push_back(time1); @@ -549,7 +560,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Coord rx = radius; Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1) { + if (times[1] != times[0] || times[1] == times[0] == 1 ) { if(!knotCurve1->isDegenerate()){ path_out.append(*knotCurve1); } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 56db6305e..3d22216d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,7 +42,7 @@ public: /*double len_to_rad(double A, std::pair sat);*/ void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); - void updateAmmount(); + void updateAmount(); void refreshKnots(); void chamfer(); void inverseChamfer(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index e4c480d93..e8a1b9532 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -62,13 +62,13 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setActive(strncmp(strarray[4],"1",1) == 0); sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); sat->setHidden(strncmp(strarray[6],"1",1) == 0); - double ammount,angle; + double amount,angle; float stepsTmp; - sp_svg_number_read_d(strarray[7], &ammount); + sp_svg_number_read_d(strarray[7], &amount); sp_svg_number_read_d(strarray[8], &angle); sp_svg_number_read_f(strarray[9], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - sat->setAmmount(ammount); + sat->setAmount(amount); sat->setAngle(angle); sat->setSteps(steps); g_strfreev (strarray); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index d28576fce..a6e797d4e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -129,7 +129,7 @@ protected: str << "*"; str << nVector.second.getHidden(); str << "*"; - str << nVector.second.getAmmount(); + str << nVector.second.getAmount(); str << "*"; str << nVector.second.getAngle(); str << "*"; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index ffd04e14c..9c2c1f93b 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -34,7 +34,7 @@ SatellitePairArrayParam::SatellitePairArrayParam( knot_color = 0x00ff0000; helper_size = 0; use_distance = false; - + _effectType = FILLET_CHAMFER; last_pointwise = NULL; } @@ -69,37 +69,61 @@ void SatellitePairArrayParam::set_unit(const gchar *abbr) unit = abbr; } +void SatellitePairArrayParam::set_effect_type(EffectType et) +{ + _effectType = et; +} + void SatellitePairArrayParam::set_helper_size(int hs) { helper_size = hs; updateCanvasIndicators(); } -void SatellitePairArrayParam::updateCanvasIndicators() +void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) { + if( last_pointwise == NULL){ + return; + } Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - hp.clear(); - bool mirrorPass = false; + if( mirror == true){ + hp.clear(); + } for (unsigned int i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ continue; } + if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ + continue; + } double pos = 0; if(pwd2.size() <= (unsigned)_vector[i].first){ break; } Geom::D2 d2 = pwd2[_vector[i].first]; - if(mirrorPass == true){ - double size = _vector[i].second.getSize(pwd2[_vector[i].first]); - boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + bool overflow = false; + double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); + double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); + double lenght_in = 0; + boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + if(curve_in){ + lenght_in = Geom::length(*curve_in, Geom::EPSILON); + } + if(mirror == true){ if(curve_in){ d2 = *curve_in; - pos = _vector[i].second.getOpositeTime(size,*curve_in); + pos = _vector[i].second.getOpositeTime(size_out,*curve_in); + if(lenght_out < size_out){ + overflow = true; + } } } else { pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + if(lenght_in < size_out){ + overflow = true; + } } - if (pos == 0) { + if (pos <= 0 || pos >= 1) { continue; } Geom::Point ptA = d2.valueAt(pos); @@ -113,7 +137,7 @@ void SatellitePairArrayParam::updateCanvasIndicators() Geom::PathVector pathv = sp_svg_read_pathv(svgd); Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(helper_size); - if(mirrorPass == true){ + if(mirror == true){ aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); } else { aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); @@ -122,13 +146,40 @@ void SatellitePairArrayParam::updateCanvasIndicators() pathv += d2.valueAt(pos); hp.push_back(pathv[0]); hp.push_back(pathv[1]); - if(_vector[i].second.getHasMirror() && mirrorPass == false){ - mirrorPass = true; - i--; - } else { - mirrorPass = false; + if(overflow){ + double diameter = helper_size; + if(helper_size == 0){ + diameter = 15; + char const * svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Scale (diameter); + pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); + hp.push_back(pathv[0]); + } else { + char const * svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(helper_size/2.0); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + } } } + if( mirror == true){ + updateCanvasIndicators(false); + } +} +void SatellitePairArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); } void SatellitePairArrayParam::addCanvasIndicators( @@ -139,76 +190,62 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item) + SPItem *item, + bool mirror) { for (unsigned int i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ continue; } - if(_vector[i].second.getHasMirror()){ - addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + if(!_vector[i].second.getHasMirror() && mirror == true){ + continue; + } + int iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); } using namespace Geom; SatelliteType type = _vector[i].second.getSatelliteType(); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + //IF is for filletChamfer effect... + if(_effectType == FILLET_CHAMFER){ + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); } - SatellitePairArrayParamKnotHolderEntity *e = - new SatellitePairArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); + } + if( mirror == true){ + addKnotHolderEntities(knotholder, desktop, item, false); } } -void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholder, +void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, int i) + SPItem *item) { - using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - SatellitePairArrayParamKnotHolderEntity *e = - new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); + addKnotHolderEntities(knotholder, desktop, item, true); } - -SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) : _pparam(p), _index(index) { @@ -216,7 +253,7 @@ SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity -void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, +void FilletChamferKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) { @@ -244,10 +281,11 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, mirrorTime = timeStart; } double size = satellite.second.toSize(mirrorTime, *d2_in); - double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; - double time = satellite.second.toTime(lenght,pwd2[satellite.first]); - s = pwd2[satellite.first].valueAt(time); - satellite.second.setPosition(s,pwd2[satellite.first]); + double amount = Geom::length(*d2_in, Geom::EPSILON) - size; + if(satellite.second.getIsTime()){ + amount = satellite.second.toTime(amount,pwd2[satellite.first]); + } + satellite.second.setAmount(amount); } } else { satellite.second.setPosition(s,pwd2[satellite.first]); @@ -260,7 +298,7 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, } Geom::Point -SatellitePairArrayParamKnotHolderEntity::knot_get() const +FilletChamferKnotHolderEntity::knot_get() const { Geom::Point tmpPoint; int index = _index; @@ -303,15 +341,19 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const } -void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) +void FilletChamferKnotHolderEntity::knot_click(guint state) { + if( _pparam->last_pointwise == NULL){ + return; + } + int index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmmount(0.0); + _pparam->_vector.at(index).second.setAmount(0.0); _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); }else{ @@ -356,9 +398,9 @@ void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - double ammount = _pparam->_vector.at(index).second.getAmmount(); + double amount = _pparam->_vector.at(index).second.getAmount(); if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ - ammount = _pparam->last_pointwise->len_to_rad(ammount, _pparam->_vector.at(index)); + amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); } boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); bool aprox = false; @@ -367,22 +409,29 @@ void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, ammount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); } } -void SatellitePairArrayParamKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { + if( _pparam->last_pointwise == NULL){ + return; + } int index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - double ammount = satellite.getAmmount(); + double amount = satellite.getAmount(); + double maxAmount = amount; if(!_pparam->use_distance && !satellite.getIsTime()){ - ammount = _pparam->last_pointwise->rad_to_len(ammount, _pparam->_vector.at(index)); + amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); + if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index).second.getAmount(); + } } - satellite.setAmmount(ammount); + satellite.setAmount(amount); _pparam->_vector.at(index).second = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 21fb0fbd8..79a015c6d 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -20,6 +20,7 @@ #include #include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" #include "knot-holder-entity.h" #include <2geom/pointwise.h> @@ -27,7 +28,7 @@ namespace Inkscape { namespace LivePathEffect { -class SatellitePairArrayParamKnotHolderEntity; +class FilletChamferKnotHolderEntity; class SatellitePairArrayParam : public ArrayParam > { public: @@ -46,7 +47,7 @@ public: guint32 color); virtual void set_helper_size(int hs); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); virtual bool providesKnotHolderEntities() const { return true; @@ -54,9 +55,11 @@ public: void set_document_unit(Glib::ustring const * value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); + void set_effect_type(EffectType et); virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); - friend class SatellitePairArrayParamKnotHolderEntity; + friend class FilletChamferKnotHolderEntity; private: SatellitePairArrayParam(const SatellitePairArrayParam &); @@ -70,14 +73,15 @@ private: bool use_distance; const gchar *unit; Glib::ustring const * documentUnit; + EffectType _effectType; Geom::Pointwise *last_pointwise; }; -class SatellitePairArrayParamKnotHolderEntity : public KnotHolderEntity { +class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); - virtual ~SatellitePairArrayParamKnotHolderEntity() {} + FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + virtual ~FilletChamferKnotHolderEntity() {} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; -- cgit v1.2.3 From 580ee6538b069ca74d4159d6b6b8ad6a33bcab4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 15:14:26 +0100 Subject: minor changes to helper paths (bzr r13645.1.37) --- src/live_effects/lpe-fillet-chamfer.cpp | 19 +++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d979171be..ca53bec63 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -57,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), + helper(_("Show helper lines"), _("Show helper lines"), "helper", &wr, this, false), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,13 +65,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); - registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); + registerParameter(&helper); radius.param_set_range(0., infinity()); radius.param_set_increments(1, 1); @@ -79,9 +79,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, 999); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -193,9 +190,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(3); } - } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -374,10 +368,15 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call - if(hide_knots){ + if(hide_knots || !helper){ satellitepairarrayparam_values.set_helper_size(0); } else { - satellitepairarrayparam_values.set_helper_size(helper_size); + double radiusHelperNodes = 6.0; + if(current_zoom != 0){ + radiusHelperNodes *= 1/current_zoom; + radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", *defaultUnit); + } + satellitepairarrayparam_values.set_helper_size(radiusHelperNodes); } bool changed = false; bool refresh = false; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 3d22216d4..d099d0475 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,7 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; - ScalarParam helper_size; + BoolParam helper; Geom::Pointwise *pointwise; -- cgit v1.2.3 From 4c1951cc43deafcc0131ba6a0878b4f371651f68 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 16:30:33 +0100 Subject: merged anf fixed from trunk (bzr r13645.1.39) --- src/live_effects/lpe-fillet-chamfer.cpp | 84 +++-------------------- src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/satellitepairarray.cpp | 2 +- src/live_effects/parameter/satellitepairarray.h | 4 +- 4 files changed, 14 insertions(+), 78 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0140f9be9..36dd599d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -57,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper(_("Show helper lines"), _("Show helper lines"), "helper", &wr, this, false), + helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,13 +65,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); + registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); - registerParameter(&helper); radius.param_set_range(0., infinity()); radius.param_set_increments(1, 1); @@ -79,6 +79,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, 999); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -190,6 +193,9 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(3); } + } else if (param->param_key == "helper_size") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -231,60 +237,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() return vbox; } -void LPEFilletChamfer::toggleHide() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (hide_knots) { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); - } else { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); - refreshKnots(); -} - -void LPEFilletChamfer::toggleFlexFixed() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - unsigned int i = 0; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (flexible) { - result.push_back(Point(fillet_chamfer_values.to_time(i, (*point_it)[X]), - (*point_it)[Y])); - } else { - result.push_back(Point(fillet_chamfer_values.to_len(i, (*point_it)[X]), - (*point_it)[Y])); - } - i++; - } - if (flexible) { - radius.param_set_range(0., 100); - radius.param_set_value(0); - } else { - radius.param_set_range(0., infinity()); - radius.param_set_value(0); - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::updateFillet() -{ - double power = 0; - if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit) * -1; - } else { - power = radius; - } - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doUpdateFillet(path_from_piecewise(pwd2, tolerance), power); -} ->>>>>>> MERGE-SOURCE void LPEFilletChamfer::fillet() { @@ -422,26 +374,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call - if(hide_knots || !helper){ + if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { - double radiusHelperNodes = 12.0; - if(current_zoom != 0){ - if(current_zoom < 0.5){ - radiusHelperNodes *= current_zoom + 0.4; - } else if(current_zoom > 1) { - radiusHelperNodes *= 1/current_zoom; - } - Geom::Affine i2doc = i2anc_affine(SP_ITEM(lpeItem), SP_OBJECT(SP_ITEM(lpeItem)->document->getRoot())); - double expand = (i2doc.expansionX() + i2doc.expansionY())/2; - if(expand != 0){ - radiusHelperNodes /= expand; - } - radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", defaultUnit); - } else { - radiusHelperNodes = 0; - } - satellitepairarrayparam_values.set_helper_size(radiusHelperNodes); + satellitepairarrayparam_values.set_helper_size(helper_size); } bool changed = false; bool refresh = false; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d099d0475..3d22216d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,7 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; - BoolParam helper; + ScalarParam helper_size; Geom::Pointwise *pointwise; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 9c2c1f93b..0fc27153f 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,7 +54,7 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } -void SatellitePairArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 79a015c6d..d20339ccb 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -52,7 +52,7 @@ public: virtual bool providesKnotHolderEntities() const { return true; } - void set_document_unit(Glib::ustring const * value_document_unit); + void set_document_unit(Glib::ustring value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); void set_effect_type(EffectType et); @@ -72,7 +72,7 @@ private: int helper_size; bool use_distance; const gchar *unit; - Glib::ustring const * documentUnit; + Glib::ustring documentUnit; EffectType _effectType; Geom::Pointwise *last_pointwise; -- cgit v1.2.3 From 14b24b5d5cc3a8c72d496bea35e16e8ca47ae458 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Mar 2015 22:06:08 +0100 Subject: commit for refactoring (bzr r13645.1.42) --- src/live_effects/lpe-fillet-chamfer.cpp | 27 ++++++------- src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/satellitepairarray.cpp | 46 ++++++++++++++++++----- src/live_effects/parameter/satellitepairarray.h | 1 + 4 files changed, 53 insertions(+), 23 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 36dd599d4..b94e3c429 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -58,7 +58,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise() + pointwise(NULL) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -400,9 +400,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) changed = true; refresh = true; } - bool hide = !hide_knots; - if(it->second.getHidden() != hide){ - it->second.setHidden(hide); + if(it->second.getHidden() != hide_knots){ + it->second.setHidden(hide_knots); changed = true; refresh = true; } @@ -419,6 +418,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +{ + if (!path_in.empty() && pointwise) { + std::cout << pointwise->getSatellites().size() << "sizefirst\n"; + pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + std::cout << pointwise->getSatellites().size() << "sizesecond\n"; + satellitepairarrayparam_values.set_pointwise(pointwise); + satellitepairarrayparam_values.param_set_and_write_new_value(pointwise->getSatellites()); + } +} std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) @@ -634,15 +644,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) return pathvector_out; } -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty()) { - //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - } -} - - }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 3d22216d4..1bedbefa4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -39,7 +39,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); - /*double len_to_rad(double A, std::pair sat);*/ + /*double len_to_rad(double A, std::pair sat);*/ void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0fc27153f..45f522693 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -52,6 +52,7 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { last_pointwise = pointwise; + std::cout << pointwise->getSatellites().size() << "setted\n"; } void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) @@ -82,7 +83,7 @@ void SatellitePairArrayParam::set_helper_size(int hs) void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) { - if( last_pointwise == NULL){ + if(!last_pointwise){ return; } Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); @@ -90,7 +91,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) hp.clear(); } for (unsigned int i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ @@ -188,13 +189,24 @@ void SatellitePairArrayParam::addCanvasIndicators( hp_vec.push_back(hp); } +void SatellitePairArrayParam::recalculate_knots() +{ + if(last_pointwise){ + _vector = last_pointwise->getSatellites(); + write_to_SVG(); + } +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { + std::cout << _vector.size() << "recalculated\n"; + recalculate_knots(); + std::cout << _vector.size() << "recalculated\n"; for (unsigned int i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ @@ -262,10 +274,18 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - if( _pparam->last_pointwise == NULL){ + if (!valid_index(index)) { + return; + } + + if( !_pparam->last_pointwise ){ return; } + std::pair satellite = _pparam->_vector.at(index); + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return; + } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ @@ -305,12 +325,21 @@ FilletChamferKnotHolderEntity::knot_get() const if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } + if (!valid_index(index)) { + return Point(infinity(), infinity()); + } std::pair satellite = _pparam->_vector.at(index); - if( _pparam->last_pointwise == NULL){ - return Geom::Point(0,0); + if(!_pparam->last_pointwise){ + return Point(infinity(), infinity()); + } + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return Point(infinity(), infinity()); } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); + std::cout << pointwise->getSatellites().size() << "knotGet\n"; + std::cout << satellite.first << "sindex\n"; + std::cout << _index << "index\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); @@ -340,10 +369,9 @@ FilletChamferKnotHolderEntity::knot_get() const return canvas_point; } - void FilletChamferKnotHolderEntity::knot_click(guint state) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } @@ -416,7 +444,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } int index = _index; diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index d20339ccb..9b22a386b 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -56,6 +56,7 @@ public: void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); void set_effect_type(EffectType et); + void recalculate_knots(); virtual void updateCanvasIndicators(); virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); -- cgit v1.2.3 From aeffc3f474c1ce460b2c9f8340de283d5853a164 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Mar 2015 19:26:22 +0100 Subject: fixing a boring bug in path manipulator (bzr r13645.1.43) --- src/live_effects/lpe-fillet-chamfer.cpp | 113 ++++++++++++++-------- src/live_effects/parameter/array.cpp | 17 ++-- src/live_effects/parameter/array.h | 5 +- src/live_effects/parameter/satellitepairarray.cpp | 59 ++++++----- 4 files changed, 113 insertions(+), 81 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b94e3c429..0a5d3a224 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -23,6 +23,7 @@ #include <2geom/satellite.h> #include <2geom/satellite-enum.h> #include <2geom/svg-elliptical-arc.h> +#include <2geom/sbasis-to-bezier.h> #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" #include "helper/geom.h" @@ -120,14 +121,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; unsigned int steps = 0; while (curve_it1 != curve_endit) { - bool isStart = false; - if(counter == 0){ - isStart = true; - } - bool isClosing = false; - if(path_it->closed() && curve_it1 == curve_end){ - isClosing = true; + if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + g_warning("LPE Fillet not handle degenerate curves."); + SPLPEItem * item = const_cast(lpeItem); + item->removeCurrentPathEffect(false); + return; } + bool isEndOpen = false; bool active = true; bool hidden = false; if (counter==0) { @@ -135,7 +135,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); + Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -143,15 +143,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } if (!path_it->closed()){ bool active = false; - bool isClosing = false; - bool isStart = false; + bool isEndOpen = true; bool hidden = true; - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal, satellite)); + Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); + satellites.push_back(std::make_pair(counterTotal-1, satellite)); } } - pointwise = new Pointwise( pwd2_in,satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + pointwise = new Pointwise( pwd2_in); + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -278,13 +278,14 @@ void LPEFilletChamfer::updateAmount() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ + if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ it->second.setAmount(0); continue; } if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } + if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ @@ -301,9 +302,12 @@ void LPEFilletChamfer::updateAmount() it->second.setAmount(power); } } + if(it->second.getIsEndOpen()){ + it->second.setAmount(0); + } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() @@ -324,7 +328,7 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) @@ -345,11 +349,12 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + std::cout << "dobeforestart\n"; SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { @@ -368,9 +373,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise = new Pointwise(pwd2_in,satellites); - + std::vector > sats; + sats = satellitepairarrayparam_values.data(); + pointwise = new Pointwise(pwd2_in); + pointwise->setSatellites(sats); //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call @@ -381,7 +387,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } bool changed = false; bool refresh = false; - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); double amount = it->second.getAmount(); @@ -407,8 +413,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } if(changed){ - pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + pointwise->setSatellites(sats); + satellitepairarrayparam_values.set_pointwise(pointwise); } if(refresh){ refreshKnots(); @@ -416,23 +422,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } + std::cout << "dobeforeend\n"; } void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - std::cout << pointwise->getSatellites().size() << "sizefirst\n"; - pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - std::cout << pointwise->getSatellites().size() << "sizesecond\n"; + pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); + pointwise->set_extremes(false,true,0.0,0.0); satellitepairarrayparam_values.set_pointwise(pointwise); - satellitepairarrayparam_values.param_set_and_write_new_value(pointwise->getSatellites()); } } std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { + std::cout << "doEffect_pathstart\n"; const double gapHelper = 0.00001; std::vector pathvector_out; unsigned int counter = 0; @@ -447,6 +453,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); + if(path_it->size() == 1){ + counter++; + path_out.start((*curve_it1).pointAt(0)); + path_out.append(*curve_it1); + pathvector_out.push_back(path_out); + continue; + } if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type @@ -470,22 +483,44 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) std::vector satVector; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); - if(!path_it->closed() || curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + if(!path_it->closed()){ + if(curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } + } else { + if(time0 != 1){ + Curve *lastCurve = curve_it1->portion(time0, 1); + lastCurve->setInitial(path_out.finalPoint()); + path_out.append(*lastCurve); + } + ++curve_it1; + counter++; + counterCurves++; + continue; } } else { - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ - satellite = satVector[0]; + if(curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } + } else { + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } } } if(first == counter){ satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ + if(satVector.size()>0 && satVector[0].getActive()){ time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); + } else { + time0 = 0; } } @@ -495,8 +530,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(!satellite.getActive()){ time1 = 1; - time0 = 0; + time2 = 0; } + if(time1 <= time0){ time1 = time0; } @@ -641,6 +677,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } pathvector_out.push_back(path_out); } + std::cout << "doEffect_pathendt\n"; return pathvector_out; } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index e8a1b9532..d8b2388da 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,19 +54,18 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[9] && !strarray[10]){ + if(strarray[8] && !strarray[9]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); - sat->setIsStart(strncmp(strarray[3],"1",1) == 0); - sat->setActive(strncmp(strarray[4],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); - sat->setHidden(strncmp(strarray[6],"1",1) == 0); + sat->setIsEndOpen(strncmp(strarray[2],"1",1) == 0); + sat->setActive(strncmp(strarray[3],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[4],"1",1) == 0); + sat->setHidden(strncmp(strarray[5],"1",1) == 0); double amount,angle; float stepsTmp; - sp_svg_number_read_d(strarray[7], &amount); - sp_svg_number_read_d(strarray[8], &angle); - sp_svg_number_read_f(strarray[9], &stepsTmp); + sp_svg_number_read_d(strarray[6], &amount); + sp_svg_number_read_d(strarray[7], &angle); + sp_svg_number_read_f(strarray[8], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; sat->setAmount(amount); sat->setAngle(angle); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a6e797d4e..5443cc3c4 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -119,9 +119,7 @@ protected: str << "*"; str << nVector.second.getIsTime(); str << "*"; - str << nVector.second.getIsClosing(); - str << "*"; - str << nVector.second.getIsStart(); + str << nVector.second.getIsEndOpen(); str << "*"; str << nVector.second.getActive(); str << "*"; @@ -134,6 +132,7 @@ protected: str << nVector.second.getAngle(); str << "*"; str << nVector.second.getSteps(); + std::cout << str.str() << "SATEEELIITE\n"; } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 45f522693..045ef2060 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -52,7 +52,7 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { last_pointwise = pointwise; - std::cout << pointwise->getSatellites().size() << "setted\n"; + param_set_and_write_new_value(last_pointwise->getSatellites()); } void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) @@ -106,20 +106,19 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); double lenght_in = 0; - boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); - if(curve_in){ - lenght_in = Geom::length(*curve_in, Geom::EPSILON); + boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); + if(d2_prev_index){ + lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } if(mirror == true){ - if(curve_in){ - d2 = *curve_in; - pos = _vector[i].second.getOpositeTime(size_out,*curve_in); + if(d2_prev_index){ + pos = _vector[i].second.getOpositeTime(size_out,pwd2[*d2_prev_index]); if(lenght_out < size_out){ overflow = true; } } } else { - pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + pos = _vector[i].second.getTime(d2); if(lenght_in < size_out){ overflow = true; } @@ -202,20 +201,18 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { - std::cout << _vector.size() << "recalculated\n"; recalculate_knots(); - std::cout << _vector.size() << "recalculated\n"; for (unsigned int i = 0; i < _vector.size(); ++i) { + int iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); + } if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ continue; } - int iPlus = i; - if( mirror == true){ - iPlus = i + _vector.size(); - } using namespace Geom; SatelliteType type = _vector[i].second.getSatelliteType(); //IF is for filletChamfer effect... @@ -289,19 +286,20 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - double mirrorTime = Geom::nearest_point(s, *d2_in); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); if(satVector.size()>0){ - timeStart = satVector[0].getTime(*d2_in); + timeStart = satVector[0].getTime(d2_in); } if(timeStart > mirrorTime){ mirrorTime = timeStart; } - double size = satellite.second.toSize(mirrorTime, *d2_in); - double amount = Geom::length(*d2_in, Geom::EPSILON) - size; + double size = satellite.second.toSize(mirrorTime, d2_in); + double amount = Geom::length(d2_in, Geom::EPSILON) - size; if(satellite.second.getIsTime()){ amount = satellite.second.toTime(amount,pwd2[satellite.first]); } @@ -337,15 +335,13 @@ FilletChamferKnotHolderEntity::knot_get() const } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - std::cout << pointwise->getSatellites().size() << "knotGet\n"; - std::cout << satellite.first << "sindex\n"; - std::cout << _index << "index\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.second.getSize(pwd2[satellite.first]); - double t = satellite.second.getOpositeTime(s,*d2_in); + double t = satellite.second.getOpositeTime(s,d2_in); if(t > 1){ t = 1; } @@ -355,12 +351,12 @@ FilletChamferKnotHolderEntity::knot_get() const double timeStart = 0; std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); if(satVector.size()>0){ - timeStart = satVector[0].getTime(*d2_in); + timeStart = satVector[0].getTime(d2_in); } if(timeStart > t){ t = timeStart; } - tmpPoint = (*d2_in).valueAt(t); + tmpPoint = (d2_in).valueAt(t); } } else { tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); @@ -430,11 +426,12 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); } - boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); bool aprox = false; D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - if(d2_in){ - aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + if(d2_prev_index){ + Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); -- cgit v1.2.3 From f3e7b51b1d2497cda7a66e13f4f50da145ece19c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 20 Mar 2015 00:14:47 +0100 Subject: Added delete nodes/satellites (bzr r13645.1.45) --- src/live_effects/lpe-fillet-chamfer.cpp | 7 +------ src/live_effects/parameter/array.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0a5d3a224..38645a943 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -119,7 +119,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; - unsigned int steps = 0; + unsigned int steps = chamfer_steps; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); @@ -354,7 +354,6 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - std::cout << "dobeforestart\n"; SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { @@ -422,7 +421,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } - std::cout << "dobeforeend\n"; } void @@ -430,7 +428,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - pointwise->set_extremes(false,true,0.0,0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -438,7 +435,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { - std::cout << "doEffect_pathstart\n"; const double gapHelper = 0.00001; std::vector pathvector_out; unsigned int counter = 0; @@ -677,7 +673,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } pathvector_out.push_back(path_out); } - std::cout << "doEffect_pathendt\n"; return pathvector_out; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 5443cc3c4..7ff477ffb 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -17,7 +17,6 @@ #include <2geom/satellite.h> #include <2geom/satellite-enum.h> -#include <2geom/pointwise.h> #include "svg/svg.h" #include "svg/stringstream.h" @@ -132,7 +131,6 @@ protected: str << nVector.second.getAngle(); str << "*"; str << nVector.second.getSteps(); - std::cout << str.str() << "SATEEELIITE\n"; } StorageType readsvg(const gchar * str); -- cgit v1.2.3 From cfe5bd077cc29fd43385792435f687d468aca13f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 10:55:27 +0100 Subject: fix bspline calls and atemp to fic a bug whith map (bzr r13645.1.46) --- src/live_effects/lpe-fillet-chamfer.cpp | 46 +++++++++++------------ src/live_effects/parameter/satellitepairarray.cpp | 12 +++--- 2 files changed, 27 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 38645a943..09436676c 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -374,17 +374,13 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats; sats = satellitepairarrayparam_values.data(); - pointwise = new Pointwise(pwd2_in); - pointwise->setSatellites(sats); - //mandatory call - satellitepairarrayparam_values.set_pointwise(pointwise); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { satellitepairarrayparam_values.set_helper_size(helper_size); } - bool changed = false; bool refresh = false; for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { if(it->second.getIsTime() != flexible){ @@ -398,23 +394,20 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) double size = it->second.toSize(amount,d2_in); it->second.setAmount(size); } - changed = true; } if(it->second.getHasMirror() != mirror_knots){ it->second.setHasMirror(mirror_knots); - changed = true; refresh = true; } if(it->second.getHidden() != hide_knots){ it->second.setHidden(hide_knots); - changed = true; refresh = true; } } - if(changed){ - pointwise->setSatellites(sats); - satellitepairarrayparam_values.set_pointwise(pointwise); - } + pointwise = new Pointwise(pwd2_in); + pointwise->setSatellites(sats); + //mandatory call + satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } @@ -428,6 +421,9 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); + std::vector > sats = pointwise->getSatellites(); + pointwise->set_extremes(sats,false,true,0.0,0.0); + pointwise->setSatellites(sats); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -476,15 +472,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satVector; + std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(counter+1,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } else { if(time0 != 1){ @@ -500,21 +496,21 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(counter+1,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } else { - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(first,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } } if(first == counter){ - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0 && satVector[0].getActive()){ - time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); + satIndexes = pointwise->findSatellites(first,1); + if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){ + time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 045ef2060..47f023c29 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -291,9 +291,9 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; - std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); - if(satVector.size()>0){ - timeStart = satVector[0].getTime(d2_in); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + if(satIndexes.size()>0){ + timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } if(timeStart > mirrorTime){ mirrorTime = timeStart; @@ -349,9 +349,9 @@ FilletChamferKnotHolderEntity::knot_get() const t = 0; } double timeStart = 0; - std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); - if(satVector.size()>0){ - timeStart = satVector[0].getTime(d2_in); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + if(satIndexes.size()>0){ + timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } if(timeStart > t){ t = timeStart; -- cgit v1.2.3 From c1487f9dc277520b8734b7e80387b35c78d979ae Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 22:24:37 +0100 Subject: Fixed bug whith maps (bzr r13645.1.49) --- src/live_effects/lpe-bspline.cpp | 44 +++++-------------------------- src/live_effects/lpe-bspline.h | 3 +-- src/live_effects/lpe-fillet-chamfer.cpp | 46 ++++++++++++++++----------------- 3 files changed, 29 insertions(+), 64 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index b924d8a23..dba501f42 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -1,48 +1,16 @@ /* * Released under GNU GPL, read the file 'COPYING' for more information */ - -#ifdef HAVE_CONFIG_H -# include -#endif - #include - -#if WITH_GLIBMM_2_32 -# include -#endif - -#include -#include - - -#include "display/curve.h" -#include <2geom/bezier-curve.h> -#include <2geom/point.h> -#include "helper/geom-curves.h" #include "live_effects/lpe-bspline.h" -#include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" #include "ui/widget/scalar.h" -#include "xml/repr.h" -#include "svg/svg.h" +#include "display/curve.h" +#include "helper/geom-curves.h" #include "sp-path.h" -#include "style.h" -#include "document-private.h" -#include "document.h" -#include "document-undo.h" -#include "verbs.h" -#include "sp-lpe-item.h" -#include "sp-namedview.h" -#include "display/sp-canvas.h" -#include -#include -#include "util/units.h" -// For handling un-continuous paths: -#include "message-stack.h" -#include "inkscape.h" - -using Inkscape::DocumentUndo; +#include "svg/svg.h" +#include "xml/repr.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 642562b24..8017e39ef 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,9 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/effect.h" -#include "live_effects/parameter/bool.h" + #include namespace Inkscape { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 09436676c..93c21469a 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -149,8 +149,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellites.push_back(std::make_pair(counterTotal-1, satellite)); } } - pointwise = new Pointwise( pwd2_in); - pointwise->setSatellites(satellites); + pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -373,8 +372,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats; - sats = satellitepairarrayparam_values.data(); - + if(!pointwise){ + sats = satellitepairarrayparam_values.data(); + } else { + sats = pointwise->getSatellites(); + } //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -382,30 +384,29 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellitepairarrayparam_values.set_helper_size(helper_size); } bool refresh = false; - for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { - if(it->second.getIsTime() != flexible){ - it->second.setIsTime(flexible); - double amount = it->second.getAmount(); - D2 d2_in = pwd2_in[it->first]; - if(it->second.getIsTime()){ - double time = it->second.toTime(amount,d2_in); - it->second.setAmount(time); + for(unsigned i = 0; i < sats.size(); i++){ + if(sats[i].second.getIsTime() != flexible){ + sats[i].second.setIsTime(flexible); + double amount = sats[i].second.getAmount(); + D2 d2_in = pwd2_in[sats[i].first]; + if(sats[i].second.getIsTime()){ + double time = sats[i].second.toTime(amount,d2_in); + sats[i].second.setAmount(time); } else { - double size = it->second.toSize(amount,d2_in); - it->second.setAmount(size); + double size = sats[i].second.toSize(amount,d2_in); + sats[i].second.setAmount(size); } } - if(it->second.getHasMirror() != mirror_knots){ - it->second.setHasMirror(mirror_knots); + if(sats[i].second.getHasMirror() != mirror_knots){ + sats[i].second.setHasMirror(mirror_knots); refresh = true; } - if(it->second.getHidden() != hide_knots){ - it->second.setHidden(hide_knots); + if(sats[i].second.getHidden() != hide_knots){ + sats[i].second.setHidden(hide_knots); refresh = true; } } - pointwise = new Pointwise(pwd2_in); - pointwise->setSatellites(sats); + pointwise = new Pointwise(pwd2_in, sats); //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ @@ -421,10 +422,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - std::vector > sats = pointwise->getSatellites(); - pointwise->set_extremes(sats,false,true,0.0,0.0); - pointwise->setSatellites(sats); - satellitepairarrayparam_values.set_pointwise(pointwise); + pointwise->set_extremes(false,true,0.0,0.0); } } -- cgit v1.2.3 From 8bd246d8b59749e15de4d5d0d78e9b82fa8a601a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 Mar 2015 18:27:17 +0100 Subject: Fixed bug when deleting nodes (bzr r13645.1.51) --- src/live_effects/lpe-fillet-chamfer.cpp | 56 ++++++++++++----------- src/live_effects/parameter/array.cpp | 10 ++-- src/live_effects/parameter/array.h | 4 +- src/live_effects/parameter/satellitepairarray.cpp | 37 ++++++++------- src/live_effects/parameter/satellitepairarray.h | 8 ++-- 5 files changed, 60 insertions(+), 55 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 93c21469a..6b388b0f6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -51,7 +51,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 3), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), @@ -97,7 +97,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -119,7 +119,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; - unsigned int steps = chamfer_steps; + size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); @@ -274,9 +274,9 @@ void LPEFilletChamfer::updateAmount() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ it->second.setAmount(0); continue; @@ -311,9 +311,9 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } @@ -332,9 +332,9 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } @@ -371,12 +371,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > sats; - if(!pointwise){ - sats = satellitepairarrayparam_values.data(); - } else { - sats = pointwise->getSatellites(); - } + std::vector > sats = satellitepairarrayparam_values.data(); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -384,6 +380,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellitepairarrayparam_values.set_helper_size(helper_size); } bool refresh = false; + bool hide = true; for(unsigned i = 0; i < sats.size(); i++){ if(sats[i].second.getIsTime() != flexible){ sats[i].second.setIsTime(flexible); @@ -401,13 +398,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sats[i].second.setHasMirror(mirror_knots); refresh = true; } - if(sats[i].second.getHidden() != hide_knots){ - sats[i].second.setHidden(hide_knots); - refresh = true; + if(sats[i].second.getHidden() == false){ + hide = false; } + sats[i].second.setHidden(hide_knots); + } + if(hide != hide_knots){ + refresh = true; } pointwise = new Pointwise(pwd2_in, sats); //mandatory call + pointwise->set_extremes(false, false, true); satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); @@ -421,8 +422,9 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - pointwise->set_extremes(false,true,0.0,0.0); + pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + pointwise->set_extremes(true, false, true, 0.0, 0.0); + satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -431,7 +433,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) { const double gapHelper = 0.00001; std::vector pathvector_out; - unsigned int counter = 0; + size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); @@ -462,15 +464,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) curve_endit = path_it->end_open(); } } - unsigned int counterCurves = 0; - unsigned int first = counter; + size_t counterCurves = 0; + size_t first = counter; double time0 = 0; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satIndexes; + std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ @@ -602,7 +604,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } SatelliteType type = satellite.getSatelliteType(); - unsigned int steps = satellite.getSteps(); + size_t steps = satellite.getSteps(); if(steps < 1){ steps = 1; } @@ -615,7 +617,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_chamfer.appendNew(handle1, handle2, endArcPoint); } double chamfer_stepsTime = 1.0/steps; - for(unsigned int i = 1; i < steps; i++){ + for(size_t i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } @@ -630,7 +632,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } double chamfer_stepsTime = 1.0/steps; - for(unsigned int i = 1; i < steps; i++){ + for(size_t i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d8b2388da..33cb53f4e 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -78,20 +78,20 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); double index; - std::pair result; + std::pair result; unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); g_strfreev (strarray); if (success == 2) { - return std::make_pair(index, sat); + return std::make_pair((size_t)index, sat); } - return std::make_pair((int)Geom::infinity(),sat); + return std::make_pair((size_t)0,sat); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 7ff477ffb..4fb053dbb 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -90,7 +90,7 @@ protected: size_t _default_size; void writesvg(SVGOStringStream &str, std::vector const &vector) const { - for (unsigned int i = 0; i < vector.size(); ++i) { + for (size_t i = 0; i < vector.size(); ++i) { if (i != 0) { // separate items with pipe symbol str << " | "; @@ -111,7 +111,7 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; str << nVector.second.getSatelliteTypeGchar(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 47f023c29..8102edf9b 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -11,6 +11,7 @@ #include "knotholder.h" #include "ui/dialog/lpe-fillet-chamfer-properties.h" #include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/effect.h" #include "sp-lpe-item.h" // TODO due to internal breakage in glibmm headers, // this has to be included last. @@ -27,7 +28,7 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -90,7 +91,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) if( mirror == true){ hp.clear(); } - for (unsigned int i = 0; i < _vector.size(); ++i) { + for (size_t i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } @@ -106,7 +107,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); + boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); if(d2_prev_index){ lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -191,8 +192,7 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::recalculate_knots() { if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - write_to_SVG(); + //_vector = last_pointwise->getSatellites(); } } @@ -202,8 +202,8 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, bool mirror) { recalculate_knots(); - for (unsigned int i = 0; i < _vector.size(); ++i) { - int iPlus = i; + for (size_t i = 0; i < _vector.size(); ++i) { + size_t iPlus = i; if( mirror == true){ iPlus = i + _vector.size(); } @@ -254,7 +254,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) : _pparam(p), _index(index) { @@ -267,7 +267,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, guint state) { Geom::Point s = snap_knot_position(p, state); - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -286,12 +286,12 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); if(d2_prev_index){ Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); if(satIndexes.size()>0){ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } @@ -319,7 +319,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const { Geom::Point tmpPoint; - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -335,9 +335,12 @@ FilletChamferKnotHolderEntity::knot_get() const } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if(pwd2.size() <= (unsigned)satellite.first){ + return Point(infinity(), infinity()); + } if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); if(d2_prev_index){ Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.second.getSize(pwd2[satellite.first]); @@ -349,7 +352,7 @@ FilletChamferKnotHolderEntity::knot_get() const t = 0; } double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); if(satIndexes.size()>0){ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } @@ -371,7 +374,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) return; } - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -428,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } bool aprox = false; D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); if(d2_prev_index){ Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; @@ -444,7 +447,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) if( !_pparam->last_pointwise){ return; } - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 9b22a386b..a85e3f83f 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam > { +class SatellitePairArrayParam : public ArrayParam > { public: SatellitePairArrayParam(const Glib::ustring &label, const Glib::ustring &tip, @@ -81,7 +81,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() {} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); @@ -89,13 +89,13 @@ public: virtual void knot_click(guint state); void knot_set_offset(Geom::Satellite); /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(unsigned int index) const { + bool valid_index(size_t index) const { return (_pparam->_vector.size() > index); }; private: SatellitePairArrayParam *_pparam; - unsigned int _index; + size_t _index; }; } //namespace LivePathEffect -- cgit v1.2.3 From edc48d93d2b528c20b9adb0f7d074c73c46f03eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Mar 2015 00:01:44 +0100 Subject: adding append mode (bzr r13645.1.54) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6b388b0f6..55e1f93aa 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -421,8 +421,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { + std::cout << "1111111111111111111111111111111111111111\n"; if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + std::cout << "222222222222222222222222222222222222222222222\n"; + pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); pointwise->set_extremes(true, false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } -- cgit v1.2.3 From 13df14f4cf6b48cf01ac54ba0322f50a143c007e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Mar 2015 13:49:37 +0100 Subject: adding append mode (bzr r13645.1.55) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 55e1f93aa..2fc2027ab 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -372,7 +372,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats = satellitepairarrayparam_values.data(); - //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -413,6 +412,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(refresh){ refreshKnots(); } + if(c->nodes_in_path() != sats.size()){ + pointwise->recalculate_for_new_pwd2(pwd2_in); + pointwise->set_extremes(true, false, true, 0.0, 0.0); + satellitepairarrayparam_values.set_pointwise(pointwise); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -421,9 +425,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { - std::cout << "1111111111111111111111111111111111111111\n"; if (!path_in.empty() && pointwise) { - std::cout << "222222222222222222222222222222222222222222222\n"; pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); pointwise->set_extremes(true, false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); -- cgit v1.2.3 From a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 12:56:46 +0200 Subject: end append path (bzr r13645.1.57) --- src/live_effects/lpe-fillet-chamfer.cpp | 64 +++++++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/satellitepairarray.cpp | 23 +++++++- src/live_effects/parameter/satellitepairarray.h | 1 + 4 files changed, 59 insertions(+), 30 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2fc2027ab..0502a4192 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -59,7 +59,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL) + pointwise(NULL), + segCount(0) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -380,43 +381,52 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } bool refresh = false; bool hide = true; - for(unsigned i = 0; i < sats.size(); i++){ - if(sats[i].second.getIsTime() != flexible){ - sats[i].second.setIsTime(flexible); - double amount = sats[i].second.getAmount(); - D2 d2_in = pwd2_in[sats[i].first]; - if(sats[i].second.getIsTime()){ - double time = sats[i].second.toTime(amount,d2_in); - sats[i].second.setAmount(time); + for (std::vector >::iterator it = sats.begin(); it != sats.end();) + { + if(it->second.getIsTime() != flexible){ + it->second.setIsTime(flexible); + double amount = it->second.getAmount(); + D2 d2_in = pwd2_in[it->first]; + if(it->second.getIsTime()){ + double time = it->second.toTime(amount,d2_in); + it->second.setAmount(time); } else { - double size = sats[i].second.toSize(amount,d2_in); - sats[i].second.setAmount(size); + double size = it->second.toSize(amount,d2_in); + it->second.setAmount(size); } } - if(sats[i].second.getHasMirror() != mirror_knots){ - sats[i].second.setHasMirror(mirror_knots); + if(it->second.getHasMirror() != mirror_knots){ + it->second.setHasMirror(mirror_knots); refresh = true; } - if(sats[i].second.getHidden() == false){ + if(it->second.getHidden() == false){ hide = false; } - sats[i].second.setHidden(hide_knots); + it->second.setHidden(hide_knots); + if(it->second.getIsEndOpen()){ + it = sats.erase(it); + } else { + ++it; + } } if(hide != hide_knots){ refresh = true; } - pointwise = new Pointwise(pwd2_in, sats); - //mandatory call - pointwise->set_extremes(false, false, true); + + if(pointwise && c->get_segment_count() != segCount && segCount != 0){ + pointwise->recalculate_for_new_pwd2(pwd2_in); + pointwise->set_extremes(false, true, 0.0, 0.0); + segCount = c->get_segment_count(); + } else { + pointwise = new Pointwise(pwd2_in, sats); + //mandatory call + pointwise->set_extremes(false, true); + segCount = c->get_segment_count(); + } satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } - if(c->nodes_in_path() != sats.size()){ - pointwise->recalculate_for_new_pwd2(pwd2_in); - pointwise->set_extremes(true, false, true, 0.0, 0.0); - satellitepairarrayparam_values.set_pointwise(pointwise); - } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -426,8 +436,8 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - pointwise->set_extremes(true, false, true, 0.0, 0.0); + pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + pointwise->set_extremes(false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -532,10 +542,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time1 <= time0){ time1 = time0; } - std::cout << counter << ":::::::::::::::::::::::::::::\n"; - std::cout << time0 << "time0\n"; - std::cout << time1 << "time1\n"; - std::cout << time2 << "time2\n"; std::vector times; times.push_back(time0); times.push_back(time1); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 1bedbefa4..89d91265a 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -65,6 +65,7 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; + double segCount; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 8102edf9b..3876dc8df 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -13,6 +13,7 @@ #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" +#include // TODO due to internal breakage in glibmm headers, // this has to be included last. #include @@ -113,7 +114,8 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) } if(mirror == true){ if(d2_prev_index){ - pos = _vector[i].second.getOpositeTime(size_out,pwd2[*d2_prev_index]); + d2 = pwd2[*d2_prev_index]; + pos = _vector[i].second.getOpositeTime(size_out,d2); if(lenght_out < size_out){ overflow = true; } @@ -196,6 +198,24 @@ void SatellitePairArrayParam::recalculate_knots() } } +void +SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getIsTime() && _vector[i].second.getAmount() > 0){ + _vector[i].second.setAmount(_vector[i].second.getAmount() * ((postmul.expansionX() + postmul.expansionY()) / 2)); + } + } + param_set_and_write_new_value(_vector); + } + + // param_set_and_write_new_value( (*this) * postmul ); +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, @@ -315,6 +335,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, } } + Geom::Point FilletChamferKnotHolderEntity::knot_get() const { diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index a85e3f83f..462f1017c 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -52,6 +52,7 @@ public: virtual bool providesKnotHolderEntities() const { return true; } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void set_document_unit(Glib::ustring value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); -- cgit v1.2.3 From 842a3a6415e837f502671ff098525bba9d8a0362 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 13:50:29 +0200 Subject: Remove active desktop calls from LPE (bzr r13645.1.60) --- src/live_effects/lpe-fillet-chamfer.cpp | 11 +++-------- src/live_effects/parameter/satellitepairarray.cpp | 4 +++- src/live_effects/parameter/satellitepairarray.h | 6 ++++-- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0502a4192..0f767435f 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,6 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include "live_effects/lpeobject.h" -#include -#include #include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> @@ -28,7 +25,7 @@ #include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" -#include "ui/tools-switch.h" +#include "knotholder.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -260,10 +257,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + if(satellitepairarrayparam_values.knoth){ + satellitepairarrayparam_values.knoth->update_knots(); } } diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 3876dc8df..dd67be6a1 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -29,7 +29,8 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0), + knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -271,6 +272,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + knoth = knotholder; addKnotHolderEntities(knotholder, desktop, item, true); } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 462f1017c..fcd3bd736 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -62,7 +62,9 @@ public: virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); friend class FilletChamferKnotHolderEntity; - + friend class LPEFilletChamfer; +protected: + KnotHolder *knoth; private: SatellitePairArrayParam(const SatellitePairArrayParam &); SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); @@ -83,7 +85,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {} + virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; -- cgit v1.2.3 From a309dd74bad06a293cae9f70f575024eed0b652a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:50:35 +0200 Subject: fixed hide knots and removed unused headers (bzr r13645.1.61) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++------- src/live_effects/parameter/satellitepairarray.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0f767435f..6775fa000 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,17 +16,13 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/sbasis-to-bezier.h> -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" +#include "helper/geom-curves.h" +#include <2geom/svg-elliptical-arc.h> #include "knotholder.h" -#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -46,7 +42,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index dd67be6a1..0748269f4 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -195,7 +195,7 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::recalculate_knots() { if(last_pointwise){ - //_vector = last_pointwise->getSatellites(); + _vector = last_pointwise->getSatellites(); } } @@ -222,13 +222,13 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { - recalculate_knots(); + //recalculate_knots(); for (size_t i = 0; i < _vector.size(); ++i) { size_t iPlus = i; if( mirror == true){ iPlus = i + _vector.size(); } - if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ + if(!_vector[i].second.getActive()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ @@ -282,8 +282,6 @@ FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayP { } - - void FilletChamferKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) @@ -353,6 +351,7 @@ FilletChamferKnotHolderEntity::knot_get() const if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } + std::cout << satellite.second.getHidden() << "hiddden\n"; if(!satellite.second.getActive() || satellite.second.getHidden()){ return Point(infinity(), infinity()); } @@ -361,6 +360,8 @@ FilletChamferKnotHolderEntity::knot_get() const if(pwd2.size() <= (unsigned)satellite.first){ return Point(infinity(), infinity()); } + this->knot->show(); + std::cout << satellite.second.getHidden() << "show\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); -- cgit v1.2.3 From cb6f3fcd6fc271c32e1a1afcf946b7ca75a161d7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:51:21 +0200 Subject: removed code comments (bzr r13645.1.62) --- src/live_effects/parameter/satellitepairarray.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0748269f4..461a6b54e 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -351,7 +351,6 @@ FilletChamferKnotHolderEntity::knot_get() const if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } - std::cout << satellite.second.getHidden() << "hiddden\n"; if(!satellite.second.getActive() || satellite.second.getHidden()){ return Point(infinity(), infinity()); } @@ -361,7 +360,6 @@ FilletChamferKnotHolderEntity::knot_get() const return Point(infinity(), infinity()); } this->knot->show(); - std::cout << satellite.second.getHidden() << "show\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); -- cgit v1.2.3 From dff3aa428ff050c2cce501f646977ddad921feca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 04:13:16 +0200 Subject: Move 2Geom work to a intermediate positon -helper- Removed dependency to helper/geom.h Now use a simple vector, not a vector of pairs of size_t and Satellite Getters and setters on Satellite removed Update store parameter to a more friendly string, like powerstroke Todo: Documentation and Fix coding style. (bzr r13645.1.63) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 173 ++++--- src/live_effects/lpe-fillet-chamfer.h | 9 +- src/live_effects/parameter/Makefile_insert | 4 +- src/live_effects/parameter/array.cpp | 77 ++-- src/live_effects/parameter/array.h | 38 +- src/live_effects/parameter/satellitearray.cpp | 524 ++++++++++++++++++++++ src/live_effects/parameter/satellitearray.h | 108 +++++ src/live_effects/parameter/satellitepairarray.cpp | 507 --------------------- src/live_effects/parameter/satellitepairarray.h | 108 ----- 10 files changed, 775 insertions(+), 777 deletions(-) create mode 100644 src/live_effects/parameter/satellitearray.cpp create mode 100644 src/live_effects/parameter/satellitearray.h delete mode 100644 src/live_effects/parameter/satellitepairarray.cpp delete mode 100644 src/live_effects/parameter/satellitepairarray.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 3af27a220..7bafb356d 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -62,7 +62,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/satellitepairarray.cpp + parameter/satellitearray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -138,7 +138,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/satellitepairarray.h + parameter/satellitearray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6775fa000..54b2fb52f 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,13 +16,15 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> #include "helper/geom.h" #include "display/curve.h" #include "helper/geom-curves.h" +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" +#include "helper/geom-pathinfo.h" #include <2geom/svg-elliptical-arc.h> #include "knotholder.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -40,7 +42,7 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), + satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitearrayparam_values", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), @@ -55,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : pointwise(NULL), segCount(0) { - registerParameter(&satellitepairarrayparam_values); + registerParameter(&satellitearrayparam_values); registerParameter(&unit); registerParameter(&method); registerParameter(&radius); @@ -91,7 +93,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -121,7 +123,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) item->removeCurrentPathEffect(false); return; } - bool isEndOpen = false; bool active = true; bool hidden = false; if (counter==0) { @@ -129,22 +130,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal, satellite)); + Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, steps); + satellites.push_back(satellite); ++curve_it1; counter++; counterTotal++; } - if (!path_it->closed()){ - bool active = false; - bool isEndOpen = true; - bool hidden = true; - Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal-1, satellite)); - } } pointwise = new Pointwise( pwd2_in,satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -253,8 +247,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if(satellitepairarrayparam_values.knoth){ - satellitepairarrayparam_values.knoth->update_knots(); + if(satellitearrayparam_values.knoth){ + satellitearrayparam_values.knoth->update_knots(); } } @@ -266,81 +260,85 @@ void LPEFilletChamfer::updateAmount() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ - it->second.setAmount(0); + Pathinfo pathInfo(pwd2); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(!pathInfo.getIsClosed(it - satellites.begin()) && pathInfo.getFirst(it - satellites.begin()) == (unsigned)(it - satellites.begin())){ + it->amount = 0; continue; } - if(ignore_radius_0 && it->second.getAmount() == 0){ + if(ignore_radius_0 && it->amount == 0){ continue; } - + boost::optional prev = pathInfo.getPrevious(it - satellites.begin()); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = satellites[*prev]; + } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } - if(it->second.getIsEndOpen()){ - it->second.setAmount(0); - } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } else { - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } else { - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -354,51 +352,47 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitepairarrayparam_values.set_document_unit(defaultUnit); - satellitepairarrayparam_values.set_use_distance(use_knot_distance); - satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); + satellitearrayparam_values.set_document_unit(defaultUnit); + satellitearrayparam_values.set_use_distance(use_knot_distance); + satellitearrayparam_values.set_unit(unit.get_abbreviation()); //mandatory call - satellitepairarrayparam_values.set_effect_type(this->effectType()); + satellitearrayparam_values.set_effect_type(this->effectType()); PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > sats = satellitepairarrayparam_values.data(); + std::vector sats = satellitearrayparam_values.data(); //optional call if(hide_knots){ - satellitepairarrayparam_values.set_helper_size(0); + satellitearrayparam_values.set_helper_size(0); } else { - satellitepairarrayparam_values.set_helper_size(helper_size); + satellitearrayparam_values.set_helper_size(helper_size); } bool refresh = false; bool hide = true; - for (std::vector >::iterator it = sats.begin(); it != sats.end();) + for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if(it->second.getIsTime() != flexible){ - it->second.setIsTime(flexible); - double amount = it->second.getAmount(); - D2 d2_in = pwd2_in[it->first]; - if(it->second.getIsTime()){ - double time = it->second.toTime(amount,d2_in); - it->second.setAmount(time); + if(it->isTime != flexible){ + it->isTime = flexible; + double amount = it->amount; + D2 d2_in = pwd2_in[it - sats.begin()]; + if(it->isTime){ + double time = it->toTime(amount,d2_in); + it->amount = time; } else { - double size = it->second.toSize(amount,d2_in); - it->second.setAmount(size); + double size = it->toSize(amount,d2_in); + it->amount = size; } } - if(it->second.getHasMirror() != mirror_knots){ - it->second.setHasMirror(mirror_knots); + if(it->hasMirror != mirror_knots){ + it->hasMirror = mirror_knots; refresh = true; } - if(it->second.getHidden() == false){ + if(it->hidden == false){ hide = false; } - it->second.setHidden(hide_knots); - if(it->second.getIsEndOpen()){ - it = sats.erase(it); - } else { - ++it; - } + it->hidden = hide_knots; + ++it; } if(hide != hide_knots){ refresh = true; @@ -414,7 +408,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->set_extremes(false, true); segCount = c->get_segment_count(); } - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } @@ -429,7 +423,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); pointwise->set_extremes(false, true, 0.0, 0.0); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } } @@ -472,20 +466,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counterCurves = 0; size_t first = counter; double time0 = 0; + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } } else { if(time0 != 1){ @@ -501,21 +494,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } + } else { - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> first ){ + satellite = sats[first]; } } } if(first == counter){ - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){ - time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis()); + if(sats.size() > first && sats[first].active){ + time0 = sats[first].getTime(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } @@ -525,7 +516,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); - if(!satellite.getActive()){ + if(!satellite.active){ time1 = 1; time2 = 0; } @@ -604,8 +595,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_out.append(*knotCurve1); } } - SatelliteType type = satellite.getSatelliteType(); - size_t steps = satellite.getSteps(); + SatelliteType type = satellite.satelliteType; + size_t steps = satellite.steps; if(steps < 1){ steps = 1; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 89d91265a..e56200a17 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -14,11 +14,12 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + #include "live_effects/parameter/enum.h" #include "live_effects/parameter/unit.h" -#include "2geom/pointwise.h" -#include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" +#include "helper/geom-pointwise.h" namespace Inkscape { namespace LivePathEffect { @@ -39,7 +40,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); - /*double len_to_rad(double A, std::pair sat);*/ + void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); @@ -49,7 +50,7 @@ public: void fillet(); void inverseFillet(); - SatellitePairArrayParam satellitepairarrayparam_values; + SatelliteArrayParam satellitearrayparam_values; private: UnitParam unit; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 74b499fa2..9a0ebe235 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -22,8 +22,8 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/satellitepairarray.cpp \ - live_effects/parameter/satellitepairarray.h \ + live_effects/parameter/satellitearray.cpp \ + live_effects/parameter/satellitearray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 33cb53f4e..c8ee63fec 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -5,9 +5,7 @@ */ #include "live_effects/parameter/array.h" - #include "helper-fns.h" - #include <2geom/coord.h> #include <2geom/point.h> @@ -15,6 +13,35 @@ namespace Inkscape { namespace LivePathEffect { +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, ",", 8); + if(strarray[7] && !strarray[8]){ + sat->setSatelliteType(g_strstrip(strarray[0])); + sat->isTime = strncmp(strarray[1],"1",1) == 0; + sat->active = strncmp(strarray[2],"1",1) == 0; + sat->hasMirror = strncmp(strarray[3],"1",1) == 0; + sat->hidden = strncmp(strarray[4],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strarray[5], &amount); + sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_f(strarray[7], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + sat->amount = amount; + sat->angle = angle; + sat->steps = steps; + g_strfreev (strarray); + return 1; + } + g_strfreev (strarray); + return 0; +} + template <> double ArrayParam::readsvg(const gchar * str) @@ -47,51 +74,17 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -//TODO: move maybe to svg-lenght.cpp -unsigned int -sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ - if (!str) { - return 0; - } - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[8] && !strarray[9]){ - sat->setSatelliteType(strarray[0]); - sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setIsEndOpen(strncmp(strarray[2],"1",1) == 0); - sat->setActive(strncmp(strarray[3],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[4],"1",1) == 0); - sat->setHidden(strncmp(strarray[5],"1",1) == 0); - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strarray[6], &amount); - sp_svg_number_read_d(strarray[7], &angle); - sp_svg_number_read_f(strarray[8], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - sat->setAmount(amount); - sat->setAngle(angle); - sat->setSteps(steps); - g_strfreev (strarray); - return 1; - } - g_strfreev (strarray); - return 0; -} template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +Geom::Satellite +ArrayParam::readsvg(const gchar * str) { - gchar ** strarray = g_strsplit(str, ",", 2); - double index; - std::pair result; - unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; - success += sp_svg_satellite_read_d(strarray[1], &sat); - g_strfreev (strarray); - if (success == 2) { - return std::make_pair((size_t)index, sat); + if (sp_svg_satellite_read_d(str, &sat)) { + return sat; } - return std::make_pair((size_t)0,sat); + Geom::Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + return satellite; } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 4fb053dbb..25e479304 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,8 +15,8 @@ #include "live_effects/parameter/parameter.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -111,26 +111,22 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { - str << nVector.first; + void writesvgData(SVGOStringStream &str, Geom::Satellite const &nVector) const { + str << nVector.getSatelliteTypeGchar(); str << ","; - str << nVector.second.getSatelliteTypeGchar(); - str << "*"; - str << nVector.second.getIsTime(); - str << "*"; - str << nVector.second.getIsEndOpen(); - str << "*"; - str << nVector.second.getActive(); - str << "*"; - str << nVector.second.getHasMirror(); - str << "*"; - str << nVector.second.getHidden(); - str << "*"; - str << nVector.second.getAmount(); - str << "*"; - str << nVector.second.getAngle(); - str << "*"; - str << nVector.second.getSteps(); + str << nVector.isTime; + str << ","; + str << nVector.active; + str << ","; + str << nVector.hasMirror; + str << ","; + str << nVector.hidden; + str << ","; + str << nVector.amount; + str << ","; + str << nVector.angle; + str << ","; + str << nVector.steps; } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp new file mode 100644 index 000000000..24a491b4b --- /dev/null +++ b/src/live_effects/parameter/satellitearray.cpp @@ -0,0 +1,524 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" +#include "live_effects/parameter/satellitearray.h" +#include "live_effects/effect.h" +#include "sp-lpe-item.h" +#include +#include +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +SatelliteArrayParam::SatelliteArrayParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0), + knoth(NULL) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; + helper_size = 0; + use_distance = false; + _effectType = FILLET_CHAMFER; + last_pointwise = NULL; +} + +SatelliteArrayParam::~SatelliteArrayParam() {} + +void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +void SatelliteArrayParam::set_pointwise(Geom::Pointwise *pointwise) +{ + last_pointwise = pointwise; + param_set_and_write_new_value(last_pointwise->getSatellites()); +} + +void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) +{ + documentUnit = value_document_unit; +} + +void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) +{ + use_distance = use_knot_distance; +} + +void SatelliteArrayParam::set_unit(const gchar *abbr) +{ + unit = abbr; +} + +void SatelliteArrayParam::set_effect_type(EffectType et) +{ + _effectType = et; +} + +void SatelliteArrayParam::set_helper_size(int hs) +{ + helper_size = hs; + updateCanvasIndicators(); +} + +void SatelliteArrayParam::updateCanvasIndicators(bool mirror) +{ + if(!last_pointwise){ + return; + } + Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if( mirror == true){ + hp.clear(); + } + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].active || _vector[i].hidden){ + continue; + } + if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ + continue; + } + double pos = 0; + if(pwd2.size() <= i){ + break; + } + Geom::D2 d2 = pwd2[i]; + bool overflow = false; + double size_out = _vector[i].getSize(pwd2[i]); + double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); + double lenght_in = 0; + boost::optional d2_prev_index = pathInfo.getPrevious(i); + if(d2_prev_index){ + lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); + } + if(mirror == true){ + if(d2_prev_index){ + d2 = pwd2[*d2_prev_index]; + pos = _vector[i].getOpositeTime(size_out,d2); + if(lenght_out < size_out){ + overflow = true; + } + } + } else { + pos = _vector[i].getTime(d2); + if(lenght_in < size_out){ + overflow = true; + } + } + if (pos <= 0 || pos >= 1) { + continue; + } + Geom::Point ptA = d2.valueAt(pos); + Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + derivA = derivA * rot; + Geom::Point C = ptA - derivA * helper_size; + Geom::Point D = ptA + derivA * helper_size; + Geom::Ray ray1(C, D); + char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(helper_size); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + hp.push_back(pathv[1]); + if(overflow){ + double diameter = helper_size; + if(helper_size == 0){ + diameter = 15; + char const * svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Scale (diameter); + pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); + hp.push_back(pathv[0]); + } else { + char const * svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(helper_size/2.0); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + } + } + } + if( mirror == true){ + updateCanvasIndicators(false); + } +} +void SatelliteArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); +} + +void SatelliteArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} + +void SatelliteArrayParam::recalculate_knots() +{ + if(last_pointwise){ + _vector = last_pointwise->getSatellites(); + } +} + +void +SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].isTime && _vector[i].amount > 0){ + _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); + } + } + param_set_and_write_new_value(_vector); + } + + // param_set_and_write_new_value( (*this) * postmul ); +} + +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, + bool mirror) +{ + //recalculate_knots(); + for (size_t i = 0; i < _vector.size(); ++i) { + size_t iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); + } + if(!_vector[i].active){ + continue; + } + if(!_vector[i].hasMirror && mirror == true){ + continue; + } + using namespace Geom; + SatelliteType type = _vector[i].satelliteType; + //IF is for filletChamfer effect... + if(_effectType == FILLET_CHAMFER){ + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } + } + if( mirror == true){ + addKnotHolderEntities(knotholder, desktop, item, false); + } +} + +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); +} + +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) + : _pparam(p), + _index(index) +{ +} + +void FilletChamferKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point s = snap_knot_position(p, state); + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (!valid_index(index)) { + return; + } + + if( !_pparam->last_pointwise ){ + return; + } + + Geom::Satellite satellite = _pparam->_vector.at(index); + if(!satellite.active || satellite.hidden){ + return; + } + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if(_pparam->_vector.size() <= _index){ + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double mirrorTime = Geom::nearest_point(s, d2_in); + double timeStart = 0; + std::vector sats = pointwise->getSatellites(); + timeStart = sats[*d2_prev_index].getTime(d2_in); + if(timeStart > mirrorTime){ + mirrorTime = timeStart; + } + double size = satellite.toSize(mirrorTime, d2_in); + double amount = Geom::length(d2_in, Geom::EPSILON) - size; + if(satellite.isTime){ + amount = satellite.toTime(amount,pwd2[index]); + } + satellite.amount = amount; + } + } else { + satellite.setPosition(s,pwd2[index]); + } + _pparam->_vector.at(index) = satellite; + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + + +Geom::Point +FilletChamferKnotHolderEntity::knot_get() const +{ + Geom::Point tmpPoint; + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (!valid_index(index)) { + return Point(infinity(), infinity()); + } + Geom::Satellite satellite = _pparam->_vector.at(index); + if(!_pparam->last_pointwise){ + return Point(infinity(), infinity()); + } + if(!satellite.active || satellite.hidden){ + return Point(infinity(), infinity()); + } + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if(pwd2.size() <= index){ + return Point(infinity(), infinity()); + } + this->knot->show(); + if( _index >= _pparam->_vector.size()){ + tmpPoint = satellite.getPosition(pwd2[index]); + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double s = satellite.getSize(pwd2[index]); + double t = satellite.getOpositeTime(s,d2_in); + if(t > 1){ + t = 1; + } + if(t < 0){ + t = 0; + } + double timeStart = 0; + timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); + if(timeStart > t){ + t = timeStart; + } + tmpPoint = (d2_in).valueAt(t); + } + } else { + tmpPoint = satellite.getPosition(pwd2[index]); + } + Geom::Point const canvas_point = tmpPoint; + return canvas_point; +} + +void FilletChamferKnotHolderEntity::knot_click(guint state) +{ + if( !_pparam->last_pointwise){ + return; + } + + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector.at(index).amount = 0.0; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }else{ + using namespace Geom; + SatelliteType type = _pparam->_vector.at(index).satelliteType; + switch(type){ + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; + } + _pparam->_vector.at(index).satelliteType = type; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + double amount = _pparam->_vector.at(index).amount; + if(!_pparam->use_distance && !_pparam->_vector.at(index).isTime){ + boost::optional prev = pathInfo.getPrevious(index); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).len_to_rad(amount, prevPwd2, pwd2[index], prevSat); + } + bool aprox = false; + D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); + + } +} + +void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +{ + if( !_pparam->last_pointwise){ + return; + } + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + double amount = satellite.amount; + double maxAmount = amount; + if(!_pparam->use_distance && !satellite.isTime){ + Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + boost::optional prev = pathInfo.getPrevious(index); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).rad_to_len(amount, prevPwd2, pwd2[index], prevSat); + if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index).amount; + } + } + satellite.amount = amount; + _pparam->_vector.at(index) = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +} /* 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/satellitearray.h b/src/live_effects/parameter/satellitearray.h new file mode 100644 index 000000000..ee0cfbad3 --- /dev/null +++ b/src/live_effects/parameter/satellitearray.h @@ -0,0 +1,108 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" +#include "helper/geom-pointwise.h" +#include "knot-holder-entity.h" +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class FilletChamferKnotHolderEntity; + +class SatelliteArrayParam : public ArrayParam { +public: + SatelliteArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~SatelliteArrayParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + virtual void set_helper_size(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); + virtual bool providesKnotHolderEntities() const { + return true; + } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); + void set_document_unit(Glib::ustring value_document_unit); + void set_use_distance(bool use_knot_distance ); + void set_unit(const gchar *abbr); + void set_effect_type(EffectType et); + void recalculate_knots(); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + void set_pointwise(Geom::Pointwise *pointwise); + friend class FilletChamferKnotHolderEntity; + friend class LPEFilletChamfer; +protected: + KnotHolder *knoth; +private: + SatelliteArrayParam(const SatelliteArrayParam &); + SatelliteArrayParam &operator=(const SatelliteArrayParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; + Geom::PathVector hp; + int helper_size; + bool use_distance; + const gchar *unit; + Glib::ustring documentUnit; + EffectType _effectType; + Geom::Pointwise *last_pointwise; + +}; + +class FilletChamferKnotHolderEntity : public KnotHolderEntity { +public: + FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); + virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} + + 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); + void knot_set_offset(Geom::Satellite); + /** Checks whether the index falls within the size of the parameter's vector */ + bool valid_index(size_t index) const { + return (_pparam->_vector.size() > index); + }; + +private: + SatelliteArrayParam *_pparam; + size_t _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp deleted file mode 100644 index 461a6b54e..000000000 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitepairarray.h" -#include "live_effects/effect.h" -#include "sp-lpe-item.h" -#include -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -SatellitePairArrayParam::SatellitePairArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0), - knoth(NULL) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; - helper_size = 0; - use_distance = false; - _effectType = FILLET_CHAMFER; - last_pointwise = NULL; -} - -SatellitePairArrayParam::~SatellitePairArrayParam() {} - -void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) -{ - last_pointwise = pointwise; - param_set_and_write_new_value(last_pointwise->getSatellites()); -} - -void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) -{ - documentUnit = value_document_unit; -} - -void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) -{ - use_distance = use_knot_distance; -} - -void SatellitePairArrayParam::set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void SatellitePairArrayParam::set_effect_type(EffectType et) -{ - _effectType = et; -} - -void SatellitePairArrayParam::set_helper_size(int hs) -{ - helper_size = hs; - updateCanvasIndicators(); -} - -void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) -{ - if(!last_pointwise){ - return; - } - Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - if( mirror == true){ - hp.clear(); - } - for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ - continue; - } - if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ - continue; - } - double pos = 0; - if(pwd2.size() <= (unsigned)_vector[i].first){ - break; - } - Geom::D2 d2 = pwd2[_vector[i].first]; - bool overflow = false; - double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); - double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); - double lenght_in = 0; - boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); - if(d2_prev_index){ - lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); - } - if(mirror == true){ - if(d2_prev_index){ - d2 = pwd2[*d2_prev_index]; - pos = _vector[i].second.getOpositeTime(size_out,d2); - if(lenght_out < size_out){ - overflow = true; - } - } - } else { - pos = _vector[i].second.getTime(d2); - if(lenght_in < size_out){ - overflow = true; - } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point ptA = d2.valueAt(pos); - Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); - } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - } - pathv *= aff; - pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - if(overflow){ - double diameter = helper_size; - if(helper_size == 0){ - diameter = 15; - char const * svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale (diameter); - pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); - hp.push_back(pathv[0]); - } else { - char const * svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(helper_size/2.0); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); - } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - } - pathv *= aff; - pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - } - } - } - if( mirror == true){ - updateCanvasIndicators(false); - } -} -void SatellitePairArrayParam::updateCanvasIndicators() -{ - updateCanvasIndicators(true); -} - -void SatellitePairArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(hp); -} - -void SatellitePairArrayParam::recalculate_knots() -{ - if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - } -} - -void -SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true)) { - for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getIsTime() && _vector[i].second.getAmount() > 0){ - _vector[i].second.setAmount(_vector[i].second.getAmount() * ((postmul.expansionX() + postmul.expansionY()) / 2)); - } - } - param_set_and_write_new_value(_vector); - } - - // param_set_and_write_new_value( (*this) * postmul ); -} - -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, - bool mirror) -{ - //recalculate_knots(); - for (size_t i = 0; i < _vector.size(); ++i) { - size_t iPlus = i; - if( mirror == true){ - iPlus = i + _vector.size(); - } - if(!_vector[i].second.getActive()){ - continue; - } - if(!_vector[i].second.getHasMirror() && mirror == true){ - continue; - } - using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); - //IF is for filletChamfer effect... - if(_effectType == FILLET_CHAMFER){ - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - } - if( mirror == true){ - addKnotHolderEntities(knotholder, desktop, item, false); - } -} - -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); -} - -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) - : _pparam(p), - _index(index) -{ -} - -void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - Geom::Point s = snap_knot_position(p, state); - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (!valid_index(index)) { - return; - } - - if( !_pparam->last_pointwise ){ - return; - } - - std::pair satellite = _pparam->_vector.at(index); - if(!satellite.second.getActive() || satellite.second.getHidden()){ - return; - } - Geom::Pointwise* pointwise = _pparam->last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirrorTime = Geom::nearest_point(s, d2_in); - double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } - if(timeStart > mirrorTime){ - mirrorTime = timeStart; - } - double size = satellite.second.toSize(mirrorTime, d2_in); - double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if(satellite.second.getIsTime()){ - amount = satellite.second.toTime(amount,pwd2[satellite.first]); - } - satellite.second.setAmount(amount); - } - } else { - satellite.second.setPosition(s,pwd2[satellite.first]); - } - _pparam->_vector.at(index) = satellite; - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - - -Geom::Point -FilletChamferKnotHolderEntity::knot_get() const -{ - Geom::Point tmpPoint; - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (!valid_index(index)) { - return Point(infinity(), infinity()); - } - std::pair satellite = _pparam->_vector.at(index); - if(!_pparam->last_pointwise){ - return Point(infinity(), infinity()); - } - if(!satellite.second.getActive() || satellite.second.getHidden()){ - return Point(infinity(), infinity()); - } - Geom::Pointwise* pointwise = _pparam->last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - if(pwd2.size() <= (unsigned)satellite.first){ - return Point(infinity(), infinity()); - } - this->knot->show(); - if( _index >= _pparam->_vector.size()){ - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.second.getSize(pwd2[satellite.first]); - double t = satellite.second.getOpositeTime(s,d2_in); - if(t > 1){ - t = 1; - } - if(t < 0){ - t = 0; - } - double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } - if(timeStart > t){ - t = timeStart; - } - tmpPoint = (d2_in).valueAt(t); - } - } else { - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - } - Geom::Point const canvas_point = tmpPoint; - return canvas_point; -} - -void FilletChamferKnotHolderEntity::knot_click(guint state) -{ - if( !_pparam->last_pointwise){ - return; - } - - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmount(0.0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ - using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).second.getSatelliteType(); - switch(type){ - case F: - type = IF; - break; - case IF: - type = C; - break; - case C: - type = IC; - break; - default: - type = F; - break; - } - _pparam->_vector.at(index).second.setSatelliteType(type); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - double amount = _pparam->_vector.at(index).second.getAmount(); - if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ - amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); - } - bool aprox = false; - D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); - if(d2_prev_index){ - Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; - } - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); - - } -} - -void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) -{ - if( !_pparam->last_pointwise){ - return; - } - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - double amount = satellite.getAmount(); - double maxAmount = amount; - if(!_pparam->use_distance && !satellite.getIsTime()){ - amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); - if(maxAmount > 0 && amount == 0){ - amount = _pparam->_vector.at(index).second.getAmount(); - } - } - satellite.setAmount(amount); - _pparam->_vector.at(index).second = satellite; - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -} /* 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/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h deleted file mode 100644 index fcd3bd736..000000000 --- a/src/live_effects/parameter/satellitepairarray.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include "live_effects/parameter/array.h" -#include "live_effects/effect-enum.h" -#include "knot-holder-entity.h" -#include <2geom/pointwise.h> - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferKnotHolderEntity; - -class SatellitePairArrayParam : public ArrayParam > { -public: - SatellitePairArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~SatellitePairArrayParam(); - - virtual Gtk::Widget * param_newWidget() { - return NULL; - } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual void set_helper_size(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { - return true; - } - void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void set_document_unit(Glib::ustring value_document_unit); - void set_use_distance(bool use_knot_distance ); - void set_unit(const gchar *abbr); - void set_effect_type(EffectType et); - void recalculate_knots(); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - void set_pointwise(Geom::Pointwise *pointwise); - friend class FilletChamferKnotHolderEntity; - friend class LPEFilletChamfer; -protected: - KnotHolder *knoth; -private: - SatellitePairArrayParam(const SatellitePairArrayParam &); - SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - Geom::PathVector hp; - int helper_size; - bool use_distance; - const gchar *unit; - Glib::ustring documentUnit; - EffectType _effectType; - Geom::Pointwise *last_pointwise; - -}; - -class FilletChamferKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} - - 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); - void knot_set_offset(Geom::Satellite); - /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const { - return (_pparam->_vector.size() > index); - }; - -private: - SatellitePairArrayParam *_pparam; - size_t _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif -- cgit v1.2.3 From ce42be89c9b32edeba6eda6522199ec749e014f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 12:08:06 +0200 Subject: More cleanup of code structure. TODO: Documentation TODO: Fit code guidelines of Inkscape (bzr r13645.1.64) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 54b2fb52f..e873bebf9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -400,12 +400,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(pointwise && c->get_segment_count() != segCount && segCount != 0){ pointwise->recalculate_for_new_pwd2(pwd2_in); - pointwise->set_extremes(false, true, 0.0, 0.0); segCount = c->get_segment_count(); } else { pointwise = new Pointwise(pwd2_in, sats); - //mandatory call - pointwise->set_extremes(false, true); segCount = c->get_segment_count(); } satellitearrayparam_values.set_pointwise(pointwise); @@ -422,7 +419,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); - pointwise->set_extremes(false, true, 0.0, 0.0); satellitearrayparam_values.set_pointwise(pointwise); } } -- cgit v1.2.3 From f3965759e52107c1cdcd8b7e248e5538fdaa11b6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 17:54:35 +0200 Subject: Added documentation and fix to coding style. (bzr r13645.1.66) --- src/live_effects/lpe-fillet-chamfer.cpp | 656 ++++++++++++++------------ src/live_effects/lpe-fillet-chamfer.h | 12 +- src/live_effects/parameter/satellitearray.cpp | 403 ++++++++-------- src/live_effects/parameter/satellitearray.h | 89 ++-- 4 files changed, 616 insertions(+), 544 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index e873bebf9..6e026550a 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -9,12 +9,12 @@ * Also su_v for his construvtive feedback and time * Also to Mc- (IRC nick) for his important contribution to find real time * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of hours + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/lpe-fillet-chamfer.h" #include "helper/geom.h" #include "display/curve.h" @@ -33,29 +33,40 @@ namespace Inkscape { namespace LivePathEffect { static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, - { FM_ARC, N_("Force arc"), "arc" }, + { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter -FMConverter(FilletMethodData, FM_END); - -LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitearrayparam_values", &wr, this), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), - only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), - segCount(0) +static const Util::EnumDataConverter FMConverter(FilletMethodData, + FM_END); + +LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) + : Effect(lpeobject), + satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), + "satellitearrayparam_values", &wr, this), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), + "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, + this, 0.), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", + &wr, this, 1), + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), + "flexible", &wr, this, false), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, + this, true), + only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "only_selected", &wr, this, + false), + use_knot_distance(_("Use knots distance instead radius"), + _("Use knots distance instead radius"), + "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, + false), + ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), + "ignore_radius_0", &wr, this, false), + helper_size(_("Helper size with direction:"), + _("Helper size with direction"), "helper_size", &wr, this, 0), + pointwise(NULL), segment_size(0) { registerParameter(&satellitearrayparam_values); registerParameter(&unit); @@ -83,65 +94,67 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : LPEFilletChamfer::~LPEFilletChamfer() {} - void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - SPLPEItem * splpeitem = const_cast(lpeItem); - SPShape * shape = dynamic_cast(splpeitem); + SPLPEItem *splpeitem = const_cast(lpeItem); + SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + PathVector const &original_pathv = + pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - int counterTotal = 0; - std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ + int global_counter = 0; + std::vector satellites; + for (PathVector::const_iterator path_it = original_pathv.begin(); + path_it != original_pathv.end(); ++path_it) { + if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // 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(); - } + const Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // 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(); + } } Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem * item = const_cast(lpeItem); + SPLPEItem *item = const_cast(lpeItem); item->removeCurrentPathEffect(false); return; } bool active = true; bool hidden = false; - if (counter==0) { + if (counter == 0) { if (!path_it->closed()) { active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, steps); + Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, + steps); satellites.push_back(satellite); ++curve_it1; counter++; - counterTotal++; + global_counter++; } } - pointwise = new Pointwise( pwd2_in,satellites); - satellitearrayparam_values.set_pointwise(pointwise); + pointwise = new Pointwise(pwd2_in, satellites); + satellitearrayparam_values.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); - SPLPEItem * item = const_cast(lpeItem); + SPLPEItem *item = const_cast(lpeItem); item->removeCurrentPathEffect(false); } } @@ -161,28 +174,36 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); - widg = widgRegistered; + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg = widg_registered; if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(6); + Gtk::HBox *scalar_parameter = dynamic_cast(widg); + std::vector childList = + scalar_parameter->get_children(); + Gtk::Entry *entry_widget = dynamic_cast(childList[1]); + entry_widget->set_width_chars(6); } } else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); - widg = widgRegistered; + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); + widg = widg_registered; if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); + Gtk::HBox *scalar_parameter = dynamic_cast(widg); + std::vector childList = + scalar_parameter->get_children(); + Gtk::Entry *entry_widget = dynamic_cast(childList[1]); + entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -199,32 +220,39 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } ++it; } - - Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); - fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); - - filletContainer->pack_start(*fillet, true, true, 2); - Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); - inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); - filletContainer->pack_start(*inverseFillet, true, true, 2); - - Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); - chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); - - chamferContainer->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); - inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); - chamferContainer->pack_start(*inverseChamfer, true, true, 2); - - vbox->pack_start(*filletContainer, true, true, 2); - vbox->pack_start(*chamferContainer, true, true, 2); + + Gtk::HBox *fillet_container = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *fillet = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + fillet->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + + fillet_container->pack_start(*fillet, true, true, 2); + Gtk::Button *inverse_fillet = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + inverse_fillet->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + fillet_container->pack_start(*inverse_fillet, true, true, 2); + + Gtk::HBox *chamfer_container = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *chamfer = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + chamfer->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + + chamfer_container->pack_start(*chamfer, true, true, 2); + Gtk::Button *inverse_chamfer = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + inverse_chamfer->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + chamfer_container->pack_start(*inverse_chamfer, true, true, 2); + + vbox->pack_start(*fillet_container, true, true, 2); + vbox->pack_start(*chamfer_container, true, true, 2); return vbox; } - void LPEFilletChamfer::fillet() { updateSatelliteType(F); @@ -247,7 +275,7 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if(satellitearrayparam_values.knoth){ + if (satellitearrayparam_values.knoth) { satellitearrayparam_values.knoth->update_knots(); } } @@ -256,81 +284,90 @@ void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit); + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), + defaultUnit); } else { - power = radius/100; + power = radius / 100; } std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(!pathInfo.getIsClosed(it - satellites.begin()) && pathInfo.getFirst(it - satellites.begin()) == (unsigned)(it - satellites.begin())){ + Pathinfo path_info(pwd2); + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (!path_info.isClosed(it - satellites.begin()) && + path_info.first(it - satellites.begin()) == + (unsigned)(it - satellites.begin())) { it->amount = 0; continue; } - if(ignore_radius_0 && it->amount == 0){ + if (ignore_radius_0 && it->amount == 0) { continue; } - boost::optional prev = pathInfo.getPrevious(it - satellites.begin()); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ - prevPwd2 = pwd2[*prev]; - prevSat = satellites[*prev]; + boost::optional previous = + path_info.previous(it - satellites.begin()); + boost::optional > previous_d2 = boost::none; + boost::optional previous_satellite = boost::none; + if (previous) { + previous_d2 = pwd2[*previous]; + previous_satellite = satellites[*previous]; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ - if(!use_knot_distance && !flexible){ - it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { + if (!use_knot_distance && !flexible) { + it->amount = it->radToLen(power, previous_d2, + pwd2[it - satellites.begin()], previous_satellite); } else { it->amount = power; } } } else { - if(!use_knot_distance && !flexible){ - it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); + if (!use_knot_distance && !flexible) { + it->amount = it->radToLen(power, previous_d2, + pwd2[it - satellites.begin()], previous_satellite); } else { it->amount = power; } } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->amount == 0){ + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (ignore_radius_0 && it->amount == 0) { continue; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ - it->steps = chamfer_steps; + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { + it->steps = chamfer_steps; } } else { it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->amount == 0){ + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (ignore_radius_0 && it->amount == 0) { continue; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { it->satelliteType = satellitetype; } } else { @@ -338,75 +375,76 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - SPLPEItem * splpeitem = const_cast(lpeItem); - SPShape * shape = dynamic_cast(splpeitem); + SPLPEItem *splpeitem = const_cast(lpeItem); + SPShape *shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); - SPPath * path = dynamic_cast(shape); - if(path){ + SPPath *path = dynamic_cast(shape); + if (path) { c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.set_document_unit(defaultUnit); - satellitearrayparam_values.set_use_distance(use_knot_distance); - satellitearrayparam_values.set_unit(unit.get_abbreviation()); + satellitearrayparam_values.setDocumentUnit(defaultUnit); + satellitearrayparam_values.setUseDistance(use_knot_distance); + satellitearrayparam_values.setUnit(unit.get_abbreviation()); //mandatory call - satellitearrayparam_values.set_effect_type(this->effectType()); - - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + satellitearrayparam_values.setEffectType(effectType()); + + PathVector const &original_pathv = + pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); + std::vector sats = satellitearrayparam_values.data(); //optional call - if(hide_knots){ - satellitearrayparam_values.set_helper_size(0); + if (hide_knots) { + satellitearrayparam_values.setHelperSize(0); } else { - satellitearrayparam_values.set_helper_size(helper_size); + satellitearrayparam_values.setHelperSize(helper_size); } bool refresh = false; bool hide = true; - for (std::vector::iterator it = sats.begin(); it != sats.end();) - { - if(it->isTime != flexible){ + for (std::vector::iterator it = sats.begin(); + it != sats.end();) { + if (it->isTime != flexible) { it->isTime = flexible; double amount = it->amount; D2 d2_in = pwd2_in[it - sats.begin()]; - if(it->isTime){ - double time = it->toTime(amount,d2_in); + if (it->isTime) { + double time = it->toTime(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount,d2_in); + double size = it->toSize(amount, d2_in); it->amount = size; } } - if(it->hasMirror != mirror_knots){ + if (it->hasMirror != mirror_knots) { it->hasMirror = mirror_knots; refresh = true; } - if(it->hidden == false){ + if (it->hidden == false) { hide = false; } it->hidden = hide_knots; ++it; } - if(hide != hide_knots){ + if (hide != hide_knots) { refresh = true; } - - if(pointwise && c->get_segment_count() != segCount && segCount != 0){ - pointwise->recalculate_for_new_pwd2(pwd2_in); - segCount = c->get_segment_count(); + + if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { + pointwise->recalculateForNewPwd2(pwd2_in); + segment_size = c->get_segment_count(); } else { pointwise = new Pointwise(pwd2_in, sats); - segCount = c->get_segment_count(); + segment_size = c->get_segment_count(); } - satellitearrayparam_values.set_pointwise(pointwise); - if(refresh){ + satellitearrayparam_values.setPointwise(pointwise); + if (refresh) { refreshKnots(); } } else { @@ -418,246 +456,272 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); - satellitearrayparam_values.set_pointwise(pointwise); + pointwise->recalculateForNewPwd2(remove_short_cuts( + paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); + satellitearrayparam_values.setPointwise(pointwise); } } std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { - const double gapHelper = 0.00001; - std::vector pathvector_out; + const double GAP_HELPER = 0.00001; + std::vector path_out; size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + std::vector path_in_processed = + pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()){ + if (path_it->empty()) { continue; } - Geom::Path path_out; + Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); - if(path_it->size() == 1){ + if (path_it->size() == 1) { counter++; - path_out.start((*curve_it1).pointAt(0)); - path_out.append(*curve_it1); - pathvector_out.push_back(path_out); + tmp_path.start((*curve_it1).pointAt(0)); + tmp_path.append(*curve_it1); + path_out.push_back(tmp_path); continue; } if (path_it->closed()) { - 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(); - } + 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(); + } } - size_t counterCurves = 0; + size_t counter_curves = 0; size_t first = counter; double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { g_warning("LPE Fillet not handle degenerate curves."); return path_in; } Satellite satellite; - Curve *curve_it2Fixed = path_it->begin()->duplicate(); - if(!path_it->closed()){ - if(curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - if(sats.size()> counter+1 ){ - satellite = sats[counter+1]; + Curve *curve_it2_fixed = path_it->begin()->duplicate(); + if (!path_it->closed()) { + if (curve_it2 != curve_endit) { + curve_it2_fixed = (*curve_it2).duplicate(); + if (sats.size() > counter + 1) { + satellite = sats[counter + 1]; } } else { - if(time0 != 1){ - Curve *lastCurve = curve_it1->portion(time0, 1); - lastCurve->setInitial(path_out.finalPoint()); - path_out.append(*lastCurve); + if (time0 != 1) { + Curve *last_curve = curve_it1->portion(time0, 1); + last_curve->setInitial(tmp_path.finalPoint()); + tmp_path.append(*last_curve); } ++curve_it1; counter++; - counterCurves++; + counter_curves++; continue; } } else { - if(curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - if(sats.size()> counter+1 ){ - satellite = sats[counter+1]; + if (curve_it2 != curve_endit) { + curve_it2_fixed = (*curve_it2).duplicate(); + if (sats.size() > counter + 1) { + satellite = sats[counter + 1]; } } else { - if(sats.size()> first ){ + if (sats.size() > first) { satellite = sats[first]; } } } - if(first == counter){ - if(sats.size() > first && sats[first].active){ - time0 = sats[first].getTime(path_it->begin()->duplicate()->toSBasis()); + if (first == counter) { + if (sats.size() > first && sats[first].active) { + time0 = + sats[first].time(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } } bool last = curve_it2 == curve_endit; - double s = satellite.getSize(curve_it2Fixed->toSBasis()); - double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); - double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); - if(!satellite.active){ + double s = satellite.size(curve_it2_fixed->toSBasis()); + double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); + double time2 = satellite.time(curve_it2_fixed->toSBasis()); + if (!satellite.active) { time1 = 1; time2 = 0; } - - if(time1 <= time0){ + + if (time1 <= time0) { time1 = time0; } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); - if (counterCurves > 0) { - knotCurve1->setInitial(path_out.finalPoint()); + Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + if (counter_curves > 0) { + knot_curve_1->setInitial(tmp_path.finalPoint()); } else { - path_out.start((*curve_it1).pointAt(times[0])); - } - - Point startArcPoint = knotCurve1->finalPoint(); - Point endArcPoint = curve_it2Fixed->pointAt(times[2]); - if(times[2] == 1){ - endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); - } - if(times[1] == times[0]){ - startArcPoint = curve_it1->pointAt(times[0]+gapHelper); - } - double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, curve_it1->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - if(time0 == 1){ - handle1 = startArcPoint; - } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(curve_it2Fixed->initialPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); - - bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double angle = angle_between(ray1, ray2, ccwToggle); - double handleAngle = ray1.angle() - angle; - if (ccwToggle) { - handleAngle = ray1.angle() + angle; - } - Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; - if(time0 == 1){ - inverseHandle1 = startArcPoint; - } - handleAngle = ray2.angle() + angle; - if (ccwToggle) { - handleAngle = ray2.angle() - angle; - } - Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - if(times[2] == 1){ - endArcPoint = curve_it2Fixed->pointAt(times[2]); - } - if(times[1] == times[0]){ - startArcPoint = curve_it1->pointAt(times[0]); - } - Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); - Line const angled_line(startArcPoint,endArcPoint); - double angleArc = Geom::angle_between( x_line,angled_line); - double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + tmp_path.start((*curve_it1).pointAt(times[0])); + } + + Point start_arc_point = knot_curve_1->finalPoint(); + Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + if (times[2] == 1) { + end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); + } + if (times[1] == times[0]) { + start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); + } + double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; + double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; + Geom::CubicBezier const *cubic_1 = + dynamic_cast(&*knot_curve_1); + Ray ray_1(start_arc_point, curve_it1->finalPoint()); + if (cubic_1) { + ray_1.setPoints((*cubic_1)[2], start_arc_point); + } + Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + if (time0 == 1) { + handle_1 = start_arc_point; + } + Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::CubicBezier const *cubic_2 = + dynamic_cast(&*knot_curve_2); + Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + if (cubic_2) { + ray_2.setPoints(end_arc_point, (*cubic_2)[1]); + } + Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + + bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, + end_arc_point - start_arc_point) < 0; + double angle = angle_between(ray_1, ray_2, ccw_toggle); + double handleAngle = ray_1.angle() - angle; + if (ccw_toggle) { + handleAngle = ray_1.angle() + angle; + } + Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + if (time0 == 1) { + inverse_handle_1 = start_arc_point; + } + handleAngle = ray_2.angle() + angle; + if (ccw_toggle) { + handleAngle = ray_2.angle() - angle; + } + Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + if (times[2] == 1) { + end_arc_point = curve_it2_fixed->pointAt(times[2]); + } + if (times[1] == times[0]) { + start_arc_point = curve_it1->pointAt(times[0]); + } + Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Line const angled_line(start_arc_point, end_arc_point); + double arc_angle = Geom::angle_between(x_line, angled_line); + double radius = Geom::distance(start_arc_point, + middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); Coord rx = radius; Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1 ) { - if(!knotCurve1->isDegenerate()){ - path_out.append(*knotCurve1); + if (times[1] != times[0] || times[1] == times[0] == 1) { + if (!knot_curve_1->isDegenerate()) { + tmp_path.append(*knot_curve_1); } } SatelliteType type = satellite.satelliteType; size_t steps = satellite.steps; - if(steps < 1){ + if (steps < 1) { steps = 1; } if (type == C) { Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + path_chamfer.start(tmp_path.finalPoint()); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + path_chamfer.appendNew(rx, ry, arc_angle, 0, + ccw_toggle, end_arc_point); } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); + path_chamfer.appendNew(handle_1, handle_2, + end_arc_point); } - double chamfer_stepsTime = 1.0/steps; - for(size_t i = 1; i < steps; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + double chamfer_stepsTime = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = + path_chamfer.pointAt(chamfer_stepsTime * i); + tmp_path.appendNew(chamfer_step); } - path_out.appendNew(endArcPoint); + tmp_path.appendNew(end_arc_point); } else if (type == IC) { Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_chamfer.start(tmp_path.finalPoint()); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; + path_chamfer.appendNew(rx, ry, arc_angle, 0, + ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew( + inverse_handle_1, inverse_handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0/steps; - for(size_t i = 1; i < steps; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + double chamfer_stepsTime = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = + path_chamfer.pointAt(chamfer_stepsTime * i); + tmp_path.appendNew(chamfer_step); } - path_out.appendNew(endArcPoint); + tmp_path.appendNew(end_arc_point); } else if (type == IF) { - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + end_arc_point); + } else { + tmp_path.appendNew(inverse_handle_1, + inverse_handle_2, end_arc_point); } - } else if (type == F){ - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else if (type == F) { + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + end_arc_point); } else { - path_out.appendNew(handle1, handle2, endArcPoint); + tmp_path.appendNew(handle_1, handle_2, + end_arc_point); } } } else { - if(!knotCurve1->isDegenerate()){ - path_out.append(*knotCurve1); + if (!knot_curve_1->isDegenerate()) { + tmp_path.append(*knot_curve_1); } } if (path_it->closed() && last) { - path_out.close(); + tmp_path.close(); } ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; } counter++; - counterCurves++; + counter_curves++; time0 = times[2]; } - pathvector_out.push_back(path_out); + path_out.push_back(tmp_path); } - return pathvector_out; + return path_out; } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index e56200a17..c519679f8 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -10,7 +10,8 @@ * Special thanks to Johan Engelen for the base of the effect -powerstroke- * Also to ScislaC for point me to the idea * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of hours + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -36,10 +37,11 @@ public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual std::vector doEffect_path(std::vector const &path_in); + virtual std::vector + doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget* newWidget(); + virtual Gtk::Widget *newWidget(); void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); @@ -49,7 +51,7 @@ public: void inverseChamfer(); void fillet(); void inverseFillet(); - + SatelliteArrayParam satellitearrayparam_values; private: @@ -66,7 +68,7 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; - double segCount; + double segment_size; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 24a491b4b..bac907343 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -19,27 +19,26 @@ // this has to be included last. #include - using namespace Geom; namespace Inkscape { namespace LivePathEffect { -SatelliteArrayParam::SatelliteArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), - knoth(NULL) +SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) { - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; - helper_size = 0; - use_distance = false; + _knot_shape = SP_KNOT_SHAPE_DIAMOND; + _knot_mode = SP_KNOT_MODE_XOR; + _knot_color = 0x00ff0000; + _helper_size = 0; + _use_distance = false; _effectType = FILLET_CHAMFER; - last_pointwise = NULL; + _last_pointwise = NULL; } SatelliteArrayParam::~SatelliteArrayParam() {} @@ -48,138 +47,141 @@ void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { - knot_shape = shape; - knot_mode = mode; - knot_color = color; + _knot_shape = shape; + _knot_mode = mode; + _knot_color = color; } -void SatelliteArrayParam::set_pointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::setPointwise(Geom::Pointwise *pointwise) { - last_pointwise = pointwise; - param_set_and_write_new_value(last_pointwise->getSatellites()); + _last_pointwise = pointwise; + param_set_and_write_new_value(_last_pointwise->getSatellites()); } -void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) +void SatelliteArrayParam::setDocumentUnit(Glib::ustring value_document_unit) { - documentUnit = value_document_unit; + _documentUnit = value_document_unit; } -void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) +void SatelliteArrayParam::setUseDistance(bool use_knot_distance) { - use_distance = use_knot_distance; + _use_distance = use_knot_distance; } -void SatelliteArrayParam::set_unit(const gchar *abbr) +void SatelliteArrayParam::setUnit(const gchar *abbr) { - unit = abbr; + _unit = abbr; } -void SatelliteArrayParam::set_effect_type(EffectType et) +void SatelliteArrayParam::setEffectType(EffectType et) { _effectType = et; } -void SatelliteArrayParam::set_helper_size(int hs) +void SatelliteArrayParam::setHelperSize(int hs) { - helper_size = hs; + _helper_size = hs; updateCanvasIndicators(); } void SatelliteArrayParam::updateCanvasIndicators(bool mirror) { - if(!last_pointwise){ + if (!_last_pointwise) { return; } - Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if( mirror == true){ - hp.clear(); + Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + if (mirror == true) { + _hp.clear(); } for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].active || _vector[i].hidden){ + if (!_vector[i].active || _vector[i].hidden) { continue; } - if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ + if ((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0) { continue; } double pos = 0; - if(pwd2.size() <= i){ + if (pwd2.size() <= i) { break; } Geom::D2 d2 = pwd2[i]; bool overflow = false; - double size_out = _vector[i].getSize(pwd2[i]); + double size_out = _vector[i].size(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = pathInfo.getPrevious(i); - if(d2_prev_index){ + boost::optional d2_prev_index = path_info.previous(i); + if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } - if(mirror == true){ - if(d2_prev_index){ + if (mirror == true) { + if (d2_prev_index) { d2 = pwd2[*d2_prev_index]; - pos = _vector[i].getOpositeTime(size_out,d2); - if(lenght_out < size_out){ + pos = _vector[i].time(size_out, true, d2); + if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].getTime(d2); - if(lenght_in < size_out){ + pos = _vector[i].time(d2); + if (lenght_in < size_out) { overflow = true; } } if (pos <= 0 || pos >= 1) { continue; } - Geom::Point ptA = d2.valueAt(pos); - Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Point point_a = d2.valueAt(pos); + Geom::Point deriv_a = unit_vector(derivative(d2).valueAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + aff *= Geom::Scale(_helper_size); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - if(overflow){ - double diameter = helper_size; - if(helper_size == 0){ + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { diameter = 15; - char const * svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale (diameter); - pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); - hp.push_back(pathv[0]); + pathv *= Geom::Scale(diameter); + pathv += point_a - Geom::Point(diameter * 0.35, diameter * 0.35); + _hp.push_back(pathv[0]); } else { - char const * svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); aff = Geom::Affine(); - aff *= Geom::Scale(helper_size/2.0); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); + _hp.push_back(pathv[0]); } } } - if( mirror == true){ + if (mirror == true) { updateCanvasIndicators(false); } } @@ -191,58 +193,47 @@ void SatelliteArrayParam::updateCanvasIndicators() void SatelliteArrayParam::addCanvasIndicators( SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - hp_vec.push_back(hp); -} - -void SatelliteArrayParam::recalculate_knots() -{ - if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - } + hp_vec.push_back(_hp); } -void -SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, +void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, bool /*set*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/transform/rectcorners", true)) { for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].isTime && _vector[i].amount > 0){ - _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); + if (!_vector[i].isTime && _vector[i].amount > 0) { + _vector[i].amount = _vector[i].amount * + ((postmul.expansionX() + postmul.expansionY()) / 2); } } param_set_and_write_new_value(_vector); } - - // param_set_and_write_new_value( (*this) * postmul ); } void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, - bool mirror) + SPItem *item, bool mirror) { - //recalculate_knots(); for (size_t i = 0; i < _vector.size(); ++i) { size_t iPlus = i; - if( mirror == true){ + if (mirror == true) { iPlus = i + _vector.size(); } - if(!_vector[i].active){ + if (!_vector[i].active) { continue; } - if(!_vector[i].hasMirror && mirror == true){ + if (!_vector[i].hasMirror && mirror == true) { continue; } using namespace Geom; SatelliteType type = _vector[i].satelliteType; //IF is for filletChamfer effect... - if(_effectType == FILLET_CHAMFER){ + if (_effectType == FILLET_CHAMFER) { const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " + if (type == C) { + tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == IC) { @@ -261,11 +252,11 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, iPlus); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); + _knot_shape, _knot_mode, _knot_color); knotholder->add(e); } } - if( mirror == true){ + if (mirror == true) { addKnotHolderEntities(knotholder, desktop, item, false); } } @@ -274,159 +265,155 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) - : _pparam(p), - _index(index) -{ -} +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( + SatelliteArrayParam *p, size_t index) + : _pparam(p), _index(index) {} void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) + Point const &/*origin*/, + guint state) { Geom::Point s = snap_knot_position(p, state); size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { return; } - if( !_pparam->last_pointwise ){ + if (!_pparam->_last_pointwise) { return; } Geom::Satellite satellite = _pparam->_vector.at(index); - if(!satellite.active || satellite.hidden){ + if (!satellite.active || satellite.hidden) { return; } - Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ + Pathinfo path_info(pwd2); + if (_pparam->_vector.size() <= _index) { + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirrorTime = Geom::nearest_point(s, d2_in); - double timeStart = 0; + double mirror_time = Geom::nearest_point(s, d2_in); + double time_start = 0; std::vector sats = pointwise->getSatellites(); - timeStart = sats[*d2_prev_index].getTime(d2_in); - if(timeStart > mirrorTime){ - mirrorTime = timeStart; + time_start = sats[*d2_prev_index].time(d2_in); + if (time_start > mirror_time) { + mirror_time = time_start; } - double size = satellite.toSize(mirrorTime, d2_in); + double size = satellite.toSize(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if(satellite.isTime){ - amount = satellite.toTime(amount,pwd2[index]); + if (satellite.isTime) { + amount = satellite.toTime(amount, pwd2[index]); } satellite.amount = amount; } } else { - satellite.setPosition(s,pwd2[index]); + satellite.setPosition(s, pwd2[index]); } - _pparam->_vector.at(index) = satellite; - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ + _pparam->_vector.at(index) = satellite; + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); } } - -Geom::Point -FilletChamferKnotHolderEntity::knot_get() const +Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - Geom::Point tmpPoint; + Geom::Point tmp_point; size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { return Point(infinity(), infinity()); } Geom::Satellite satellite = _pparam->_vector.at(index); - if(!_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return Point(infinity(), infinity()); } - if(!satellite.active || satellite.hidden){ + if (!satellite.active || satellite.hidden) { return Point(infinity(), infinity()); } - Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if(pwd2.size() <= index){ + Pathinfo path_info(pwd2); + if (pwd2.size() <= index) { return Point(infinity(), infinity()); } this->knot->show(); - if( _index >= _pparam->_vector.size()){ - tmpPoint = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.getSize(pwd2[index]); - double t = satellite.getOpositeTime(s,d2_in); - if(t > 1){ + if (_index >= _pparam->_vector.size()) { + tmp_point = satellite.getPosition(pwd2[index]); + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double s = satellite.size(pwd2[index]); + double t = satellite.time(s, true, d2_in); + if (t > 1) { t = 1; } - if(t < 0){ + if (t < 0) { t = 0; } - double timeStart = 0; - timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); - if(timeStart > t){ - t = timeStart; + double time_start = 0; + time_start = pointwise->getSatellites()[*d2_prev_index].time(d2_in); + if (time_start > t) { + t = time_start; } - tmpPoint = (d2_in).valueAt(t); + tmp_point = (d2_in).valueAt(t); } } else { - tmpPoint = satellite.getPosition(pwd2[index]); + tmp_point = satellite.getPosition(pwd2[index]); } - Geom::Point const canvas_point = tmpPoint; + Geom::Point const canvas_point = tmp_point; return canvas_point; } void FilletChamferKnotHolderEntity::knot_click(guint state) { - if( !_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return; } size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector.at(index).amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ + } else { using namespace Geom; SatelliteType type = _pparam->_vector.at(index).satelliteType; - switch(type){ - case F: - type = IF; - break; - case IF: - type = C; - break; - case C: - type = IC; - break; - default: - type = F; - break; + switch (type) { + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; } _pparam->_vector.at(index).satelliteType = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " + if (type == C) { + tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == IC) { @@ -446,55 +433,63 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - double amount = _pparam->_vector.at(index).amount; - if(!_pparam->use_distance && !_pparam->_vector.at(index).isTime){ - boost::optional prev = pathInfo.getPrevious(index); + Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + double amount = _pparam->_vector.at(index).amount; + if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { + boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ + boost::optional prevSat = boost::none; + if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); } - amount = _pparam->_vector.at(index).len_to_rad(amount, prevPwd2, pwd2[index], prevSat); + amount = _pparam->_vector.at(index) + .lenToRad(amount, prevPwd2, pwd2[index], prevSat); } bool aprox = false; - D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ - Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); - + this->desktop, amount, this, _pparam->_unit, _pparam->_use_distance, + aprox, _pparam->_documentUnit, _pparam->_vector.at(index)); + } } void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { - if( !_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return; } size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } double amount = satellite.amount; - double maxAmount = amount; - if(!_pparam->use_distance && !satellite.isTime){ - Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - boost::optional prev = pathInfo.getPrevious(index); + double max_amount = amount; + if (!_pparam->_use_distance && !satellite.isTime) { + Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ + boost::optional prevSat = boost::none; + if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); } - amount = _pparam->_vector.at(index).rad_to_len(amount, prevPwd2, pwd2[index], prevSat); - if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index) + .radToLen(amount, prevPwd2, pwd2[index], prevSat); + if (max_amount > 0 && amount == 0) { amount = _pparam->_vector.at(index).amount; } } @@ -502,8 +497,8 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) _pparam->_vector.at(index) = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); } } diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index ee0cfbad3..bb53af12b 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -10,11 +10,11 @@ * To Nathan Hurst for his review and help on refactor * and finaly to Liam P. White for his big help on coding, that save me a lot of * hours - * - * + * + * * This parameter act as bridge from pointwise class to serialize it as a LPE * parameter - * + * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -32,69 +32,80 @@ class FilletChamferKnotHolderEntity; class SatelliteArrayParam : public ArrayParam { public: - SatelliteArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); + SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect); virtual ~SatelliteArrayParam(); - virtual Gtk::Widget * param_newWidget() { + virtual Gtk::Widget *param_newWidget() + { return NULL; } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual void set_helper_size(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { + virtual void setHelperSize(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, + std::vector &hp_vec); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + virtual bool providesKnotHolderEntities() const + { return true; } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void set_document_unit(Glib::ustring value_document_unit); - void set_use_distance(bool use_knot_distance ); - void set_unit(const gchar *abbr); - void set_effect_type(EffectType et); - void recalculate_knots(); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - void set_pointwise(Geom::Pointwise *pointwise); + void setDocumentUnit(Glib::ustring value_document__unit); + void setUseDistance(bool use_knot_distance); + void setUnit(const gchar *abbr); + void setEffectType(EffectType et); + void setPointwise(Geom::Pointwise *pointwise); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + friend class FilletChamferKnotHolderEntity; friend class LPEFilletChamfer; + protected: KnotHolder *knoth; + private: SatelliteArrayParam(const SatelliteArrayParam &); SatelliteArrayParam &operator=(const SatelliteArrayParam &); - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - Geom::PathVector hp; - int helper_size; - bool use_distance; - const gchar *unit; - Glib::ustring documentUnit; + SPKnotShapeType _knot_shape; + SPKnotModeType _knot_mode; + guint32 _knot_color; + Geom::PathVector _hp; + int _helper_size; + bool _use_distance; + const gchar *_unit; + Glib::ustring _documentUnit; EffectType _effectType; - Geom::Pointwise *last_pointwise; + Geom::Pointwise *_last_pointwise; }; class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} + virtual ~FilletChamferKnotHolderEntity() + { + _pparam->knoth = NULL; + } - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + 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); void knot_set_offset(Geom::Satellite); - /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const { + /** Checks whether the index falls within the size of the parameter's vector + */ + bool valid_index(size_t index) const + { return (_pparam->_vector.size() > index); - }; + } + ; private: SatelliteArrayParam *_pparam; -- cgit v1.2.3 From de70b4b2d0611dbf45ec6adc3f29a36137ce7c42 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 19:26:07 +0200 Subject: Now open -without conversion- old fillet chamfer objects (bzr r13645.1.68) --- src/live_effects/lpe-fillet-chamfer.cpp | 40 ++++++++++++++++++--------------- src/live_effects/lpe-fillet-chamfer.h | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6e026550a..6ff098894 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -41,8 +41,8 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), - "satellitearrayparam_values", &wr, this), + satellites_param(_("pair_array_param"), _("pair_array_param"), + "satellites_param", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), @@ -68,7 +68,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise(NULL), segment_size(0) { - registerParameter(&satellitearrayparam_values); + registerParameter(&satellites_param); registerParameter(&unit); registerParameter(&method); registerParameter(&radius); @@ -151,7 +151,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(pwd2_in, satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -275,8 +275,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if (satellitearrayparam_values.knoth) { - satellitearrayparam_values.knoth->update_knots(); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -331,7 +331,7 @@ void LPEFilletChamfer::updateAmount() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() @@ -353,7 +353,7 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) @@ -375,7 +375,7 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -389,22 +389,26 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.setDocumentUnit(defaultUnit); - satellitearrayparam_values.setUseDistance(use_knot_distance); - satellitearrayparam_values.setUnit(unit.get_abbreviation()); + satellites_param.setDocumentUnit(defaultUnit); + satellites_param.setUseDistance(use_knot_distance); + satellites_param.setUnit(unit.get_abbreviation()); //mandatory call - satellitearrayparam_values.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); + std::vector sats = satellites_param.data(); + if(sats.empty()){ + doOnApply(lpeItem); + sats = satellites_param.data(); + } //optional call if (hide_knots) { - satellitearrayparam_values.setHelperSize(0); + satellites_param.setHelperSize(0); } else { - satellitearrayparam_values.setHelperSize(helper_size); + satellites_param.setHelperSize(helper_size); } bool refresh = false; bool hide = true; @@ -443,7 +447,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise = new Pointwise(pwd2_in, sats); segment_size = c->get_segment_count(); } - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); if (refresh) { refreshKnots(); } @@ -458,7 +462,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) if (!path_in.empty() && pointwise) { pointwise->recalculateForNewPwd2(remove_short_cuts( paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index c519679f8..dc2199609 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -52,7 +52,7 @@ public: void fillet(); void inverseFillet(); - SatelliteArrayParam satellitearrayparam_values; + SatelliteArrayParam satellites_param; private: UnitParam unit; -- cgit v1.2.3 From e7fc8e1fde0b795b34ab0db85575bbf7c9c11791 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 2 Apr 2015 21:47:51 +0200 Subject: add move knots when move nodes pointed by su_v (bzr r13645.1.69) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +++ src/live_effects/parameter/satellitearray.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ff098894..ac412e120 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -405,6 +405,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sats = satellites_param.data(); } //optional call + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); + } if (hide_knots) { satellites_param.setHelperSize(0); } else { diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index bac907343..0e42c23c5 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -34,7 +34,7 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; - _knot_color = 0x00ff0000; + _knot_color = 0xAAFF8800; _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; -- cgit v1.2.3 From 323fc5ae45fd8374de4561d0771f6b9d5cd3e87a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 01:46:44 +0200 Subject: Adding suport for duplicate nodes Allow degenrate curves Show helper path whith original path (bzr r13645.1.70) --- src/live_effects/lpe-fillet-chamfer.cpp | 28 +++++++++++++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 3 ++- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ac412e120..f7fd6f64b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -129,12 +129,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem *item = const_cast(lpeItem); - item->removeCurrentPathEffect(false); - return; - } bool active = true; bool hidden = false; if (counter == 0) { @@ -380,6 +374,9 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + if(!_hp.empty()){ + _hp.clear(); + } SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -469,6 +466,12 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) } } +void +LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(_hp); +} + std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { @@ -483,6 +486,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (path_it->empty()) { continue; } + _hp.push_back(*path_it); Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -511,9 +515,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - return path_in; + if ((*curve_it1).isDegenerate() || (curve_it2 != curve_endit && (*curve_it2).isDegenerate())) { + ++curve_it1; + if (curve_it2 != curve_endit) { + ++curve_it2; + } + counter++; + counter_curves++; + time0 = 0.0; + continue; } Satellite satellite; Curve *curve_it2_fixed = path_it->begin()->duplicate(); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index dc2199609..e3ea41ba8 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,7 +42,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget *newWidget(); - + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); @@ -69,6 +69,7 @@ private: Geom::Pointwise *pointwise; double segment_size; + Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); -- cgit v1.2.3 From 04218b26ae0a10bf9e64721fb0dd789f024afca5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 16:10:46 +0200 Subject: Update pathinfo class to allow piecewise and pathvector as input. Add a method on pointwise to allow update if degenerated curves in new path, not noticed by piecewises (bzr r13645.1.72) --- src/live_effects/lpe-fillet-chamfer.cpp | 38 +++++---------------------------- src/live_effects/lpe-fillet-chamfer.h | 2 -- 2 files changed, 5 insertions(+), 35 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f7fd6f64b..fdf2469e0 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -66,7 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), segment_size(0) + pointwise(NULL) { registerParameter(&satellites_param); registerParameter(&unit); @@ -288,7 +288,7 @@ void LPEFilletChamfer::updateAmount() Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info.isClosed(it - satellites.begin()) && + if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == (unsigned)(it - satellites.begin())) { it->amount = 0; @@ -401,17 +401,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) doOnApply(lpeItem); sats = satellites_param.data(); } - //optional call - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); - } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } - bool refresh = false; - bool hide = true; for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->isTime != flexible) { @@ -428,44 +422,22 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } if (it->hasMirror != mirror_knots) { it->hasMirror = mirror_knots; - refresh = true; - } - if (it->hidden == false) { - hide = false; } it->hidden = hide_knots; ++it; } - if (hide != hide_knots) { - refresh = true; - } - - if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { - pointwise->recalculateForNewPwd2(pwd2_in); - segment_size = c->get_segment_count(); + if (pointwise && c->get_segment_count() != sats.size()) { + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); - segment_size = c->get_segment_count(); } satellites_param.setPointwise(pointwise); - if (refresh) { - refreshKnots(); - } + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } } -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty() && pointwise) { - pointwise->recalculateForNewPwd2(remove_short_cuts( - paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellites_param.setPointwise(pointwise); - } -} - void LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index e3ea41ba8..6acc9fb40 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,7 +40,6 @@ public: virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget *newWidget(); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(Geom::SatelliteType satellitetype); @@ -68,7 +67,6 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; - double segment_size; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); -- cgit v1.2.3 From 49ec02c315e6e5068b1ad395c01db2b536dd9b9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 21:20:55 +0200 Subject: Updated Pathinfo to discrimine degenerate curves optionaly. Fixed redundant data in are_near from pointwise Fixed Fillet-Chamfer lpe to allow duplicate nodes (bzr r13645.1.73) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index fdf2469e0..6cc9062d9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -487,11 +487,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (curve_it2 != curve_endit && (*curve_it2).isDegenerate())) { + if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { + ++curve_it2; + } + if ((*curve_it1).isDegenerate()) { ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } counter++; counter_curves++; time0 = 0.0; -- cgit v1.2.3 From c6457829dc2711fca07f5f27ecc597dc4f932929 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:59:57 +0200 Subject: fixing bug on closed paths (bzr r13645.1.76) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6cc9062d9..ac877c792 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -427,6 +427,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) ++it; } if (pointwise && c->get_segment_count() != sats.size()) { + std::cout << "recalculta\n"; pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); -- cgit v1.2.3 From 22ded87a8ca58e0ff4400b2d4e76787f4ac22bd6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 19:39:38 +0200 Subject: Fixed bug on closed paths, Clenup of pathinfo (bzr r13645.1.77) --- src/live_effects/lpe-fillet-chamfer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ac877c792..935e97ec9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -426,8 +426,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - if (pointwise && c->get_segment_count() != sats.size()) { - std::cout << "recalculta\n"; + Pathinfo path_info(original_pathv); + size_t number_curves = path_info.numberCurves() + 1; + if (pointwise && number_curves != sats.size()) { pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); -- cgit v1.2.3 From 74649824e41b26bcf560ba485364a6ffe7b80fca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 20:12:48 +0200 Subject: rename pathinfo function (bzr r13645.1.78) --- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 935e97ec9..cad67cea9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -427,7 +427,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) ++it; } Pathinfo path_info(original_pathv); - size_t number_curves = path_info.numberCurves() + 1; + size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { -- cgit v1.2.3 From 1a4fb1c5b0c91ed84f3a98bc78cfc725d043e629 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:22:14 +0200 Subject: Adding and renaming methofs to pathinfo (bzr r13645.1.79) --- src/live_effects/lpe-fillet-chamfer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index cad67cea9..a846e4bad 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -429,7 +429,16 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Pathinfo path_info(original_pathv); size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { - pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); + bool active = true; + bool hidden = false; + bool is_time = sats[0].isTime; + bool mirror_knots = sats[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(sats[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { pointwise = new Pointwise(pwd2_in, sats); } -- cgit v1.2.3 From 3ce6cb91e8259ec064956c79c2cc4f9050dccbce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 9 May 2015 22:48:48 +0200 Subject: fixing review (bzr r13645.1.86) --- src/live_effects/lpe-fillet-chamfer.cpp | 40 +++++++++++++-------------- src/live_effects/lpe-fillet-chamfer.h | 4 +-- src/live_effects/parameter/array.cpp | 14 +++++----- src/live_effects/parameter/array.h | 7 ++--- src/live_effects/parameter/satellitearray.cpp | 20 +++++++------- src/live_effects/parameter/satellitearray.h | 8 +++--- 6 files changed, 45 insertions(+), 48 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1b7f232ed..d26f47541 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -97,12 +97,12 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = + PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; - std::vector satellites; + std::vector satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { @@ -111,7 +111,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -168,13 +168,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } @@ -186,16 +185,15 @@ Gtk::Widget *LPEFilletChamfer::newWidget() widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -280,10 +278,10 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == @@ -297,7 +295,7 @@ void LPEFilletChamfer::updateAmount() boost::optional previous = path_info.previous(it - satellites.begin()); boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; + boost::optional previous_satellite = boost::none; if (previous) { previous_d2 = pwd2[*previous]; previous_satellite = satellites[*previous]; @@ -327,9 +325,9 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -347,11 +345,11 @@ void LPEFilletChamfer::updateChamferSteps() satellites_param.setPointwise(pointwise); } -void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -391,7 +389,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellites_param.data(); + std::vector sats = satellites_param.data(); if(sats.empty()){ doOnApply(lpeItem); sats = satellites_param.data(); @@ -491,7 +489,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 9ec5b5e04..48056924a 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -41,7 +41,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); - void updateSatelliteType(Geom::SatelliteType satellitetype); + void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); void refreshKnots(); @@ -64,7 +64,7 @@ private: BoolParam ignore_radius_0; ScalarParam helper_size; - Geom::Pointwise *pointwise; + Pointwise *pointwise; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c8ee63fec..c71b8ed55 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -15,16 +15,16 @@ namespace LivePathEffect { //TODO: move maybe to svg-lenght.cpp unsigned int -sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ +sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ if (!str) { return 0; } gchar ** strarray = g_strsplit(str, ",", 8); if(strarray[7] && !strarray[8]){ sat->setSatelliteType(g_strstrip(strarray[0])); - sat->isTime = strncmp(strarray[1],"1",1) == 0; + sat->is_time = strncmp(strarray[1],"1",1) == 0; sat->active = strncmp(strarray[2],"1",1) == 0; - sat->hasMirror = strncmp(strarray[3],"1",1) == 0; + sat->has_mirror = strncmp(strarray[3],"1",1) == 0; sat->hidden = strncmp(strarray[4],"1",1) == 0; double amount,angle; float stepsTmp; @@ -76,14 +76,14 @@ ArrayParam::readsvg(const gchar * str) } template <> -Geom::Satellite -ArrayParam::readsvg(const gchar * str) +Satellite +ArrayParam::readsvg(const gchar * str) { - Geom::Satellite sat; + Satellite sat; if (sp_svg_satellite_read_d(str, &sat)) { return sat; } - Geom::Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); return satellite; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 25e479304..66ed6344b 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -16,7 +16,6 @@ #include "live_effects/parameter/parameter.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -111,14 +110,14 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, Geom::Satellite const &nVector) const { + void writesvgData(SVGOStringStream &str, Satellite const &nVector) const { str << nVector.getSatelliteTypeGchar(); str << ","; - str << nVector.isTime; + str << nVector.is_time; str << ","; str << nVector.active; str << ","; - str << nVector.hasMirror; + str << nVector.has_mirror; str << ","; str << nVector.hidden; str << ","; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index b0b036962..5a3b64dd3 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -30,7 +30,7 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -52,7 +52,7 @@ void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatelliteArrayParam::setPointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::setPointwise(Pointwise *pointwise) { _last_pointwise = pointwise; param_set_and_write_new_value(_last_pointwise->getSatellites()); @@ -280,11 +280,11 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, return; } - Geom::Satellite satellite = _pparam->_vector.at(index); + Satellite satellite = _pparam->_vector.at(index); if (!satellite.active || satellite.hidden) { return; } - Geom::Pointwise *pointwise = _pparam->_last_pointwise; + Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (_pparam->_vector.size() <= _index) { @@ -293,7 +293,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_point(s, d2_in); double time_start = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); time_start = sats[*d2_prev_index].time(d2_in); if (time_start > mirror_time) { mirror_time = time_start; @@ -325,14 +325,14 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const if (!valid_index(index)) { return Point(infinity(), infinity()); } - Geom::Satellite satellite = _pparam->_vector.at(index); + Satellite satellite = _pparam->_vector.at(index); if (!_pparam->_last_pointwise) { return Point(infinity(), infinity()); } if (!satellite.active || satellite.hidden) { return Point(infinity(), infinity()); } - Geom::Pointwise *pointwise = _pparam->_last_pointwise; + Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (pwd2.size() <= index) { @@ -429,7 +429,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; + boost::optional prevSat = boost::none; if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); @@ -456,7 +456,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } -void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { if (!_pparam->_last_pointwise) { return; @@ -472,7 +472,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; + boost::optional prevSat = boost::none; if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index 2845e3969..cc09e7589 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatelliteArrayParam : public ArrayParam { +class SatelliteArrayParam : public ArrayParam { public: SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, @@ -57,7 +57,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Geom::Pointwise *pointwise); + void setPointwise(Pointwise *pointwise); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -78,7 +78,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Geom::Pointwise *_last_pointwise; + Pointwise *_last_pointwise; }; @@ -94,7 +94,7 @@ public: guint state); virtual Geom::Point knot_get() const; virtual void knot_click(guint state); - void knot_set_offset(Geom::Satellite); + void knot_set_offset(Satellite); /** Checks whether the index falls within the size of the parameter's vector */ bool valid_index(size_t index) const -- cgit v1.2.3 From 6195a5fd157ff2681534aa90a279627e0048d4e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 00:37:31 +0200 Subject: fixing review (bzr r13645.1.87) --- src/live_effects/lpe-fillet-chamfer.cpp | 43 ++++++++++++++++----------- src/live_effects/parameter/satellitearray.cpp | 22 +++++--------- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d26f47541..8d457c90b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -20,7 +20,6 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "helper/geom-pathinfo.h" #include <2geom/svg-elliptical-arc.h> #include "knotholder.h" @@ -134,8 +133,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, - steps); + Satellite satellite(F); + satellite.setIsTime(flexible); + satellite.setActive(active) + satellite.setMirror(mirror_knots) + satellite.setHidden(hidden) + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(steps); satellites.push_back(satellite); ++curve_it1; counter++; @@ -282,10 +287,12 @@ void LPEFilletChamfer::updateAmount() Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { + it != satellites.end(); ++it) + { if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) { + (unsigned)(it - satellites.begin())) + { it->amount = 0; continue; } @@ -294,26 +301,28 @@ void LPEFilletChamfer::updateAmount() } boost::optional previous = path_info.previous(it - satellites.begin()); - boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; - if (previous) { - previous_d2 = pwd2[*previous]; - previous_satellite = satellites[*previous]; - } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()], satellites[*previous]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } else { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()], satellites[*previous]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } @@ -406,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) double amount = it->amount; D2 d2_in = pwd2_in[it - sats.begin()]; if (it->isTime) { - double time = it->toTime(amount, d2_in); + double time = it->timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount, d2_in); + double size = it->arcLengthAt(amount, d2_in); it->amount = size; } } diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5a3b64dd3..5a90d1930 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -298,10 +298,10 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if (time_start > mirror_time) { mirror_time = time_start; } - double size = satellite.toSize(mirror_time, d2_in); + double size = satellite.arcLengthAt(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; if (satellite.isTime) { - amount = satellite.toTime(amount, pwd2[index]); + amount = satellite.timeAtArcLength(amount, pwd2[index]); } satellite.amount = amount; } @@ -428,14 +428,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) double amount = _pparam->_vector.at(index).amount; if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { boost::optional prev = path_info.previous(index); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; if (prev) { - prevPwd2 = pwd2[*prev]; - prevSat = _pparam->_vector.at(*prev); + amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); + } else { + amount = 0.0; } - amount = _pparam->_vector.at(index) - .lenToRad(amount, prevPwd2, pwd2[index], prevSat); } bool aprox = false; D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; @@ -471,14 +468,11 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; if (prev) { - prevPwd2 = pwd2[*prev]; - prevSat = _pparam->_vector.at(*prev); + amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); + } else { + amount = 0.0; } - amount = _pparam->_vector.at(index) - .radToLen(amount, prevPwd2, pwd2[index], prevSat); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector.at(index).amount; } -- cgit v1.2.3 From 870dbb0348163f55263eb9dca601d525d53a8d79 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 13:40:31 +0200 Subject: Working on Krzysztof review. Seems to be all fixed. TODO: double check review and comment (bzr r13645.1.89) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 154 +++++++++++++------------- src/live_effects/lpe-fillet-chamfer.h | 6 +- src/live_effects/parameter/array.cpp | 9 +- src/live_effects/parameter/satellitearray.cpp | 90 +++++++-------- 5 files changed, 129 insertions(+), 134 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index e06afef2f..a5bb1741c 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -58,11 +58,11 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp - parameter/parameter.cpp - parameter/path.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp + parameter/parameter.cpp parameter/path-reference.cpp + parameter/path.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp parameter/satellitearray.cpp diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 8d457c90b..16bef6a99 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -4,13 +4,6 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * Also to Mc- (IRC nick) for his important contribution to find real time - * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -27,7 +20,6 @@ // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; namespace Inkscape { namespace LivePathEffect { @@ -45,7 +37,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, - this, 0.), + this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), @@ -78,7 +70,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&only_selected); registerParameter(&hide_knots); - radius.param_set_range(0., infinity()); + radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); chamfer_steps.param_set_range(1, 999); @@ -96,13 +88,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -110,7 +102,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - Curve const &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -133,11 +125,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F); + Satellite satellite(FILLET); satellite.setIsTime(flexible); - satellite.setActive(active) - satellite.setMirror(mirror_knots) - satellite.setHidden(hidden) + satellite.setActive(active); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hidden); satellite.setAmount(0.0); satellite.setAngle(0.0); satellite.setSteps(steps); @@ -148,6 +140,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(pwd2_in, satellites); + pointwise->setPathInfo(original_pathv); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -250,22 +243,22 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::fillet() { - updateSatelliteType(F); + updateSatelliteType(FILLET); } void LPEFilletChamfer::inverseFillet() { - updateSatelliteType(IF); + updateSatelliteType(INVERSE_FILLET); } void LPEFilletChamfer::chamfer() { - updateSatelliteType(C); + updateSatelliteType(CHAMFER); } void LPEFilletChamfer::inverseChamfer() { - updateSatelliteType(IC); + updateSatelliteType(INVERSE_CHAMFER); } void LPEFilletChamfer::refreshKnots() @@ -284,7 +277,7 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) @@ -335,7 +328,7 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { @@ -357,7 +350,7 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { @@ -366,10 +359,10 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } else { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); @@ -394,9 +387,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector sats = satellites_param.data(); if(sats.empty()){ @@ -410,20 +403,20 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if (it->isTime != flexible) { - it->isTime = flexible; + if (it->is_time != flexible) { + it->is_time = flexible; double amount = it->amount; - D2 d2_in = pwd2_in[it - sats.begin()]; - if (it->isTime) { - double time = it->timeAtArcLength(amount, d2_in); + Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + if (it->is_time) { + double time = timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->arcLengthAt(amount, d2_in); + double size = arcLengthAt(amount, d2_in); it->amount = size; } } - if (it->hasMirror != mirror_knots) { - it->hasMirror = mirror_knots; + if (it->has_mirror != mirror_knots) { + it->has_mirror = mirror_knots; } it->hidden = hide_knots; ++it; @@ -431,19 +424,19 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Pathinfo path_info(original_pathv); size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { - bool active = true; - bool hidden = false; - bool is_time = sats[0].isTime; - bool mirror_knots = sats[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(sats[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); + Satellite sat(sats[0].satellite_type); + sat.setIsTime(sats[0].is_time); + sat.setActive(true); + sat.setHasMirror( sats[0].has_mirror); + sat.setHidden(false); + sat.setAmount(0.0); + sat.setAngle(0.0); + sat.setSteps(0); pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { pointwise = new Pointwise(pwd2_in, sats); } + pointwise->setPathInfo(original_pathv); satellites_param.setPointwise(pointwise); refreshKnots(); } else { @@ -466,7 +459,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; @@ -511,7 +504,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) continue; } Satellite satellite; - Curve *curve_it2_fixed = path_it->begin()->duplicate(); + Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); @@ -520,7 +513,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } else { if (time0 != 1) { - Curve *last_curve = curve_it1->portion(time0, 1); + Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); } @@ -552,7 +545,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.size(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); double time2 = satellite.time(curve_it2_fixed->toSBasis()); if (!satellite.active) { @@ -567,15 +560,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); if (counter_curves > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } - Point start_arc_point = knot_curve_1->finalPoint(); - Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point start_arc_point = knot_curve_1->finalPoint(); + Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); } @@ -586,22 +579,22 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); - Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; if (time0 == 1) { handle_1 = start_arc_point; } - Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, end_arc_point - start_arc_point) < 0; @@ -610,7 +603,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_1.angle() + angle; } - Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; if (time0 == 1) { inverse_handle_1 = start_arc_point; } @@ -618,39 +611,40 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_2.angle() - angle; } - Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Line const angled_line(start_arc_point, end_arc_point); + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / sin(angle / 2.0); - Coord rx = radius; - Coord ry = rx; + Geom::Coord rx = radius; + Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || times[1] == times[0] == 1) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } } - SatelliteType type = satellite.satelliteType; + SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; if (steps < 1) { steps = 1; } - if (type == C) { + if (type == CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, + method == FM_ARC) + { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew(handle_1, handle_2, @@ -658,19 +652,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } double chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( @@ -683,22 +677,24 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - } else if (type == F) { + } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + method == FM_ARC) + { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 48056924a..bab278cf5 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -7,11 +7,7 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Jabiertxof:Thanks to all people help me * * Released under GNU GPL, read the file 'COPYING' for more information */ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c71b8ed55..9b326fe32 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -83,7 +83,14 @@ ArrayParam::readsvg(const gchar * str) if (sp_svg_satellite_read_d(str, &sat)) { return sat; } - Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + Satellite satellite(FILLET); + satellite.setIsTime(true); + satellite.setActive(false); + satellite.setHasMirror(false); + satellite.setHidden(true); + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(0); return satellite; } diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5a90d1930..7df849c24 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -1,10 +1,8 @@ /* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,8 +17,6 @@ // this has to be included last. #include -using namespace Geom; - namespace Inkscape { namespace LivePathEffect { @@ -88,7 +84,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (!_vector[i].active || _vector[i].hidden) { continue; } - if ((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0) { + if ((!_vector[i].has_mirror && mirror == true) || _vector[i].amount == 0) { continue; } double pos = 0; @@ -97,7 +93,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } Geom::D2 d2 = pwd2[i]; bool overflow = false; - double size_out = _vector[i].size(pwd2[i]); + double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; boost::optional d2_prev_index = path_info.previous(i); @@ -133,9 +129,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(_helper_size); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); @@ -161,9 +157,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) aff = Geom::Affine(); aff *= Geom::Scale(_helper_size / 2.0); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); @@ -193,7 +189,7 @@ void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, if (prefs->getBool("/options/transform/rectcorners", true)) { for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].isTime && _vector[i].amount > 0) { + if (!_vector[i].is_time && _vector[i].amount > 0) { _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } @@ -214,23 +210,23 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if (!_vector[i].active) { continue; } - if (!_vector[i].hasMirror && mirror == true) { + if (!_vector[i].has_mirror && mirror == true) { continue; } using namespace Geom; - SatelliteType type = _vector[i].satelliteType; + SatelliteType type = _vector[i].satellite_type; //IF is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { const gchar *tip; - if (type == C) { + if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { tip = _("Inverse Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { tip = _("Inverse Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); @@ -263,8 +259,8 @@ FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( SatelliteArrayParam *p, size_t index) : _pparam(p), _index(index) {} -void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, +void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, + Geom::Point const &/*origin*/, guint state) { Geom::Point s = snap_knot_position(p, state); @@ -298,10 +294,10 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if (time_start > mirror_time) { mirror_time = time_start; } - double size = satellite.arcLengthAt(mirror_time, d2_in); + double size = arcLengthAt(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if (satellite.isTime) { - amount = satellite.timeAtArcLength(amount, pwd2[index]); + if (satellite.is_time) { + amount = timeAtArcLength(amount, pwd2[index]); } satellite.amount = amount; } @@ -323,20 +319,20 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } Satellite satellite = _pparam->_vector.at(index); if (!_pparam->_last_pointwise) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } if (!satellite.active || satellite.hidden) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (pwd2.size() <= index) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { @@ -344,7 +340,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const boost::optional d2_prev_index = path_info.previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.size(pwd2[index]); + double s = satellite.arcDistance(pwd2[index]); double t = satellite.time(s, true, d2_in); if (t > 1) { t = 1; @@ -383,34 +379,34 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).satelliteType; + SatelliteType type = _pparam->_vector.at(index).satellite_type; switch (type) { - case F: - type = IF; + case FILLET: + type = INVERSE_FILLET; break; - case IF: - type = C; + case INVERSE_FILLET: + type = CHAMFER; break; - case C: - type = IC; + case CHAMFER: + type = INVERSE_CHAMFER; break; default: - type = F; + type = FILLET; break; } - _pparam->_vector.at(index).satelliteType = type; + _pparam->_vector.at(index).satellite_type = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; - if (type == C) { + if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { tip = _("Inverse Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { tip = _("Inverse Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); @@ -423,10 +419,10 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); double amount = _pparam->_vector.at(index).amount; - if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { boost::optional prev = path_info.previous(index); if (prev) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); @@ -435,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } bool aprox = false; - D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; boost::optional d2_prev_index = path_info.previous(index); if (d2_prev_index) { Geom::D2 d2_in = @@ -464,8 +460,8 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) } double amount = satellite.amount; double max_amount = amount; - if (!_pparam->_use_distance && !satellite.isTime) { - Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + if (!_pparam->_use_distance && !satellite.is_time) { + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); if (prev) { -- cgit v1.2.3 From c7925bda67f038dd5054329c43936658ca2cae76 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 22:36:27 +0200 Subject: some comments and pointwise related refactor (bzr r13645.1.91) --- src/live_effects/lpe-fillet-chamfer.cpp | 25 +++++++++++++++++-------- src/live_effects/parameter/satellitearray.cpp | 27 ++++++++++++++++----------- 2 files changed, 33 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 16bef6a99..3e7c1d0e1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -139,8 +139,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) global_counter++; } } - pointwise = new Pointwise(pwd2_in, satellites); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); pointwise->setPathInfo(original_pathv); + pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -278,12 +281,13 @@ void LPEFilletChamfer::updateAmount() } std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info.closed(it - satellites.begin()) && - path_info.first(it - satellites.begin()) == + if (!path_info->closed(it - satellites.begin()) && + path_info->first(it - satellites.begin()) == (unsigned)(it - satellites.begin())) { it->amount = 0; @@ -293,7 +297,7 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = - path_info.previous(it - satellites.begin()); + path_info->previous(it - satellites.begin()); if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { @@ -421,8 +425,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - Pathinfo path_info(original_pathv); - size_t number_curves = path_info.size(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(original_pathv); + size_t number_curves = path_info->size(); + //if are diferent sizes call to poinwise recalculate if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); @@ -434,9 +440,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sat.setSteps(0); pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { - pointwise = new Pointwise(pwd2_in, sats); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(sats); } pointwise->setPathInfo(original_pathv); + pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); } else { diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 7df849c24..4eefea0b0 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -76,7 +76,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) return; } Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (mirror == true) { _hp.clear(); } @@ -96,7 +97,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = path_info.previous(i); + boost::optional d2_prev_index = path_info->previous(i); if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -282,9 +283,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (_pparam->_vector.size() <= _index) { - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_point(s, d2_in); @@ -330,14 +332,15 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { tmp_point = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.arcDistance(pwd2[index]); @@ -420,10 +423,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); double amount = _pparam->_vector.at(index).amount; if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - boost::optional prev = path_info.previous(index); + boost::optional prev = path_info->previous(index); if (prev) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); } else { @@ -432,7 +436,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } bool aprox = false; Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; @@ -462,8 +466,9 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); - boost::optional prev = path_info.previous(index); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); + boost::optional prev = path_info->previous(index); if (prev) { amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); } else { -- cgit v1.2.3 From d11134922137f029c42919ed3298924135bec386 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 11 May 2015 00:24:25 +0200 Subject: fix a minor bug calculating max time (bzr r13645.1.92) --- src/live_effects/lpe-fillet-chamfer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3e7c1d0e1..cc21d99cc 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -565,6 +565,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (time1 <= time0) { time1 = time0; } + if (time2 > 1) { + time2 = 1; + } std::vector times; times.push_back(time0); times.push_back(time1); @@ -632,7 +635,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { -- cgit v1.2.3 From a5d2901e1f17879bc65e23b3ff26f8c304658ce4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 Jun 2015 17:58:32 +0200 Subject: removed reverse path, commented why (bzr r13645.1.97) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index cc21d99cc..eaf1c6a08 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -429,6 +429,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) path_info->set(original_pathv); size_t number_curves = path_info->size(); //if are diferent sizes call to poinwise recalculate + //TODO: fire a reverse satellites on reverse path. Maybe a new method + //like "are_similar" to avoid precission issues on reverse a pointwise + // and after convert to Pathvector if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); -- cgit v1.2.3 From 57b065b5ffb5a871b5efac52f03cb95355bfa119 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 02:57:00 +0200 Subject: fix to compile on Krzysztof merge previous to fix the improvements in the merge request (bzr r13645.1.100) --- src/live_effects/lpe-fillet-chamfer.cpp | 347 +++++++++++++------------- src/live_effects/lpe-fillet-chamfer.h | 79 +++--- src/live_effects/parameter/satellitearray.cpp | 14 +- 3 files changed, 224 insertions(+), 216 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a0aada090..b617c929e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -4,13 +4,6 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * Also to Mc- (IRC nick) for his important contribution to find real time - * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -20,15 +13,13 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "helper/geom-pathinfo.h" -#include <2geom/svg-elliptical-arc.h> +#include <2geom/elliptical-arc.h> #include "knotholder.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; namespace Inkscape { namespace LivePathEffect { @@ -41,13 +32,12 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), - "satellitearrayparam_values", &wr, this), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), + satellites_param(_("pair_array_param"), _("pair_array_param"), + "satellites_param", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, - this, 0.), + this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), @@ -66,10 +56,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), segment_size(0) + pointwise(NULL) { - registerParameter(&satellitearrayparam_values); - registerParameter(&unit); + registerParameter(&satellites_param); registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); @@ -81,7 +70,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&only_selected); registerParameter(&hide_knots); - radius.param_set_range(0., infinity()); + radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); chamfer_steps.param_set_range(1, 999); @@ -99,13 +88,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; - std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); + std::vector satellites; + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -113,7 +102,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -129,12 +118,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem *item = const_cast(lpeItem); - item->removeCurrentPathEffect(false); - return; - } bool active = true; bool hidden = false; if (counter == 0) { @@ -142,16 +125,26 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, - steps); + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setActive(active); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hidden); + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(steps); satellites.push_back(satellite); ++curve_it1; counter++; global_counter++; } } - pointwise = new Pointwise(pwd2_in, satellites); - satellitearrayparam_values.setPointwise(pointwise); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); + pointwise->setPathInfo(original_pathv); + pointwise->setStart(); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -176,13 +169,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } @@ -194,16 +186,15 @@ Gtk::Widget *LPEFilletChamfer::newWidget() widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -255,28 +246,28 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::fillet() { - updateSatelliteType(F); + updateSatelliteType(FILLET); } void LPEFilletChamfer::inverseFillet() { - updateSatelliteType(IF); + updateSatelliteType(INVERSE_FILLET); } void LPEFilletChamfer::chamfer() { - updateSatelliteType(C); + updateSatelliteType(CHAMFER); } void LPEFilletChamfer::inverseChamfer() { - updateSatelliteType(IC); + updateSatelliteType(INVERSE_CHAMFER); } void LPEFilletChamfer::refreshKnots() { - if (satellitearrayparam_values.knoth) { - satellitearrayparam_values.knoth->update_knots(); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -284,19 +275,21 @@ void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), - defaultUnit); + power = radius; } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if (!path_info.isClosed(it - satellites.begin()) && - path_info.first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) { + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) + { + if (!path_info->closed(it - satellites.begin()) && + path_info->first(it - satellites.begin()) == + (unsigned)(it - satellites.begin())) + { it->amount = 0; continue; } @@ -304,41 +297,43 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = - path_info.previous(it - satellites.begin()); - boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; - if (previous) { - previous_d2 = pwd2[*previous]; - previous_satellite = satellites[*previous]; - } + path_info->previous(it - satellites.begin()); if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } else { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -353,14 +348,14 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } -void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -368,18 +363,21 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } else { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + if(!_hp.empty()){ + _hp.clear(); + } SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -389,93 +387,96 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.setDocumentUnit(defaultUnit); - satellitearrayparam_values.setUseDistance(use_knot_distance); - satellitearrayparam_values.setUnit(unit.get_abbreviation()); + satellites_param.setUseDistance(use_knot_distance); //mandatory call - satellitearrayparam_values.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); - //optional call + std::vector sats = satellites_param.data(); + if(sats.empty()){ + doOnApply(lpeItem); + sats = satellites_param.data(); + } if (hide_knots) { - satellitearrayparam_values.setHelperSize(0); + satellites_param.setHelperSize(0); } else { - satellitearrayparam_values.setHelperSize(helper_size); + satellites_param.setHelperSize(helper_size); } - bool refresh = false; - bool hide = true; for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if (it->isTime != flexible) { - it->isTime = flexible; + if (it->is_time != flexible) { + it->is_time = flexible; double amount = it->amount; - D2 d2_in = pwd2_in[it - sats.begin()]; - if (it->isTime) { - double time = it->toTime(amount, d2_in); + Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + if (it->is_time) { + double time = timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount, d2_in); + double size = arcLengthAt(amount, d2_in); it->amount = size; } } - if (it->hasMirror != mirror_knots) { - it->hasMirror = mirror_knots; - refresh = true; - } - if (it->hidden == false) { - hide = false; + if (it->has_mirror != mirror_knots) { + it->has_mirror = mirror_knots; } it->hidden = hide_knots; ++it; } - if (hide != hide_knots) { - refresh = true; - } - - if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { - pointwise->recalculateForNewPwd2(pwd2_in); - segment_size = c->get_segment_count(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(original_pathv); + size_t number_curves = path_info->size(); + //if are diferent sizes call to poinwise recalculate + //TODO: fire a reverse satellites on reverse path. Maybe a new method + //like "are_similar" to avoid precission issues on reverse a pointwise + // and after convert to Pathvector + if (pointwise && number_curves != sats.size()) { + Satellite sat(sats[0].satellite_type); + sat.setIsTime(sats[0].is_time); + sat.setActive(true); + sat.setHasMirror( sats[0].has_mirror); + sat.setHidden(false); + sat.setAmount(0.0); + sat.setAngle(0.0); + sat.setSteps(0); + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { - pointwise = new Pointwise(pwd2_in, sats); - segment_size = c->get_segment_count(); - } - satellitearrayparam_values.setPointwise(pointwise); - if (refresh) { - refreshKnots(); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(sats); } + pointwise->setPathInfo(original_pathv); + pointwise->setStart(); + satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } } void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - if (!path_in.empty() && pointwise) { - pointwise->recalculateForNewPwd2(remove_short_cuts( - paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellitearrayparam_values.setPointwise(pointwise); - } + hp_vec.push_back(_hp); } -std::vector -LPEFilletChamfer::doEffect_path(std::vector const &path_in) +Geom::PathVector +LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; - std::vector path_out; + Geom::PathVector path_out; size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = + Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; } + _hp.push_back(*path_it); Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -502,14 +503,20 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - return path_in; + if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { + ++curve_it2; + } + if ((*curve_it1).isDegenerate()) { + ++curve_it1; + counter++; + counter_curves++; + time0 = 0.0; + continue; } Satellite satellite; - Curve *curve_it2_fixed = path_it->begin()->duplicate(); + Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); @@ -518,7 +525,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } else { if (time0 != 1) { - Curve *last_curve = curve_it1->portion(time0, 1); + Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); } @@ -550,7 +557,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.size(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); double time2 = satellite.time(curve_it2_fixed->toSBasis()); if (!satellite.active) { @@ -561,19 +568,22 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (time1 <= time0) { time1 = time0; } + if (time2 > 1) { + time2 = 1; + } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); if (counter_curves > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } - Point start_arc_point = knot_curve_1->finalPoint(); - Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point start_arc_point = knot_curve_1->finalPoint(); + Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); } @@ -584,31 +594,31 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); - Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; if (time0 == 1) { handle_1 = start_arc_point; } - Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, - end_arc_point - start_arc_point) < 0; + end_arc_point - start_arc_point) < 0; double angle = angle_between(ray_1, ray_2, ccw_toggle); double handleAngle = ray_1.angle() - angle; if (ccw_toggle) { handleAngle = ray_1.angle() + angle; } - Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; if (time0 == 1) { inverse_handle_1 = start_arc_point; } @@ -616,39 +626,40 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_2.angle() - angle; } - Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Line const angled_line(start_arc_point, end_arc_point); + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, - middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); - Coord rx = radius; - Coord ry = rx; + middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); + Geom::Coord rx = radius; + Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || times[1] == times[0] == 1) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } } - SatelliteType type = satellite.satelliteType; + SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; if (steps < 1) { steps = 1; } - if (type == C) { + if (type == CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, + method == FM_ARC) + { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew(handle_1, handle_2, @@ -656,19 +667,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } double chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( @@ -681,22 +692,24 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - } else if (type == F) { + } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + method == FM_ARC) + { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index ed76eb0e6..d7549d070 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -7,17 +7,12 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Jabiertxof:Thanks to all people help me * * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/unit.h" #include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" #include "helper/geom-pointwise.h" @@ -26,52 +21,50 @@ namespace Inkscape { namespace LivePathEffect { enum FilletMethod { - FM_AUTO, - FM_ARC, - FM_BEZIER, - FM_END + FM_AUTO, + FM_ARC, + FM_BEZIER, + FM_END }; class LPEFilletChamfer : public Effect { public: - LPEFilletChamfer(LivePathEffectObject *lpeobject); - virtual ~LPEFilletChamfer(); - virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual std::vector - doEffect_path(std::vector const &path_in); - virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget *newWidget(); + LPEFilletChamfer(LivePathEffectObject *lpeobject); + virtual ~LPEFilletChamfer(); + virtual void doBeforeEffect(SPLPEItem const *lpeItem); + virtual Geom::PathVector + doEffect_path(Geom::PathVector const &path_in); + virtual void doOnApply(SPLPEItem const *lpeItem); + virtual Gtk::Widget *newWidget(); + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); + void updateSatelliteType(SatelliteType satellitetype); + void updateChamferSteps(); + void updateAmount(); + void refreshKnots(); + void chamfer(); + void inverseChamfer(); + void fillet(); + void inverseFillet(); - void updateSatelliteType(Geom::SatelliteType satellitetype); - void updateChamferSteps(); - void updateAmount(); - void refreshKnots(); - void chamfer(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - - SatelliteArrayParam satellitearrayparam_values; + SatelliteArrayParam satellites_param; private: - UnitParam unit; - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - BoolParam flexible; - BoolParam mirror_knots; - BoolParam only_selected; - BoolParam use_knot_distance; - BoolParam hide_knots; - BoolParam ignore_radius_0; - ScalarParam helper_size; + EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; + BoolParam flexible; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam ignore_radius_0; + ScalarParam helper_size; - Geom::Pointwise *pointwise; - double segCount; + Pointwise *pointwise; + Geom::PathVector _hp; - LPEFilletChamfer(const LPEFilletChamfer &); - LPEFilletChamfer &operator=(const LPEFilletChamfer &); + LPEFilletChamfer(const LPEFilletChamfer &); + LPEFilletChamfer &operator=(const LPEFilletChamfer &); }; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 4eefea0b0..46c7396d0 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -134,8 +134,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } + aff *= Geom::Translate(d2.valueAt(pos)); pathv *= aff; - pathv += d2.valueAt(pos); _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); if (overflow) { @@ -146,8 +146,10 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale(diameter); - pathv += point_a - Geom::Point(diameter * 0.35, diameter * 0.35); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; _hp.push_back(pathv[0]); } else { char const *svgd; @@ -162,8 +164,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } + aff *= Geom::Translate(d2.valueAt(pos)); pathv *= aff; - pathv += d2.valueAt(pos); _hp.push_back(pathv[0]); } } @@ -289,7 +291,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirror_time = Geom::nearest_point(s, d2_in); + double mirror_time = Geom::nearest_time(s, d2_in); double time_start = 0; std::vector sats = pointwise->getSatellites(); time_start = sats[*d2_prev_index].time(d2_in); @@ -470,7 +472,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) path_info->set(pwd2); boost::optional prev = path_info->previous(index); if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); + amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); } else { amount = 0.0; } -- cgit v1.2.3 From ebcbadbe16fe20e54a5daf9c5e6954521113d9cc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 03:14:24 +0200 Subject: Fix a bug displaying arcs (bzr r13645.1.101) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b617c929e..eb9f82918 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -659,6 +659,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -678,7 +679,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -697,7 +697,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -709,6 +708,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { -- cgit v1.2.3 From 936f6512b26120b882a1c68e50968a15002f3af4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:01:17 +0200 Subject: Fixes from branch review (bzr r13645.1.102) --- src/live_effects/lpe-fillet-chamfer.cpp | 57 +++++-------------- src/live_effects/lpe-fillet-chamfer.h | 1 - src/live_effects/parameter/array.cpp | 2 +- src/live_effects/parameter/satellitearray.cpp | 81 ++++++++++++++++++++------- src/live_effects/parameter/satellitearray.h | 1 - 5 files changed, 75 insertions(+), 67 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index eb9f82918..7871ccc1e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -13,7 +13,6 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-pathinfo.h" #include <2geom/elliptical-arc.h> #include "knotholder.h" #include @@ -81,8 +80,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_digits(0); } -LPEFilletChamfer::~LPEFilletChamfer() {} - void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { SPLPEItem *splpeitem = const_cast(lpeItem); @@ -101,20 +98,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - Geom::Curve const &closingline = path_it->back_closed(); - // the closing line segment is always of type - // 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(); - } - } - Geom::Path::const_iterator curve_end = curve_endit; - --curve_end; int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -142,7 +125,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) pointwise = new Pointwise(); pointwise->setPwd2(pwd2_in); pointwise->setSatellites(satellites); - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { @@ -281,14 +263,13 @@ void LPEFilletChamfer::updateAmount() } std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info->closed(it - satellites.begin()) && - path_info->first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) + Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); + size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; continue; @@ -296,8 +277,13 @@ void LPEFilletChamfer::updateAmount() if (ignore_radius_0 && it->amount == 0) { continue; } - boost::optional previous = - path_info->previous(it - satellites.begin()); + boost::optional previous = boost::none; + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + previous = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + previous = sat_curve_time - 1; + } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { @@ -425,13 +411,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - Pathinfo* path_info = new Pathinfo(); - path_info->set(original_pathv); - size_t number_curves = path_info->size(); + size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate - //TODO: fire a reverse satellites on reverse path. Maybe a new method + //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise - // and after convert to Pathvector + //and after convert to Pathvector if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); @@ -447,7 +431,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setPwd2(pwd2_in); pointwise->setSatellites(sats); } - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); @@ -488,18 +471,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_out.push_back(tmp_path); continue; } - if (path_it->closed()) { - 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(); - } - } size_t counter_curves = 0; size_t first = counter; double time0 = 0; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d7549d070..804709342 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -30,7 +30,6 @@ enum FilletMethod { class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); - virtual ~LPEFilletChamfer(); virtual void doBeforeEffect(SPLPEItem const *lpeItem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 9b326fe32..0abcd4b9b 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -20,7 +20,7 @@ sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, ",", 8); - if(strarray[7] && !strarray[8]){ + if(strlen(str) > 0 && strarray[7] && !strarray[8]){ sat->setSatelliteType(g_strstrip(strarray[0])); sat->is_time = strncmp(strarray[1],"1",1) == 0; sat->active = strncmp(strarray[2],"1",1) == 0; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 46c7396d0..b7d403a91 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -37,8 +37,6 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, _last_pointwise = NULL; } -SatelliteArrayParam::~SatelliteArrayParam() {} - void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) @@ -76,8 +74,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) return; } Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (mirror == true) { _hp.clear(); } @@ -97,7 +94,17 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = path_info->previous(i); + + Geom::Path sat_path = pointwise_pv.pathAt(i); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -285,10 +292,18 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - if (_pparam->_vector.size() <= _index) { - boost::optional d2_prev_index = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + if (_index >= _pparam->_vector.size() ) { + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_time(s, d2_in); @@ -334,15 +349,23 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { tmp_point = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = path_info->previous(index); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.arcDistance(pwd2[index]); @@ -425,20 +448,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - boost::optional prev = path_info->previous(index); - if (prev) { - amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); + if (d2_prev_index) { + amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); } else { amount = 0.0; } } bool aprox = false; Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; @@ -468,9 +499,17 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - boost::optional prev = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional prev = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + prev = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + prev = sat_curve_time - 1; + } if (prev) { amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); } else { diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index cc09e7589..bb8bf27c8 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -35,7 +35,6 @@ public: SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); - virtual ~SatelliteArrayParam(); virtual Gtk::Widget *param_newWidget() { -- cgit v1.2.3 From 2207d9110e54540a7408642099c9217d8037a6b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:22:52 +0200 Subject: astyle (bzr r13645.1.105) --- src/live_effects/lpe-fillet-chamfer.cpp | 50 ++++++++++++--------------- src/live_effects/parameter/satellitearray.cpp | 24 ++++++------- 2 files changed, 34 insertions(+), 40 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7871ccc1e..8998279a6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -32,7 +32,7 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellites_param(_("pair_array_param"), _("pair_array_param"), - "satellites_param", &wr, this), + "satellites_param", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, @@ -264,13 +264,11 @@ void LPEFilletChamfer::updateAmount() std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) - { + it != satellites.end(); ++it) { Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (!sat_path.closed() && sat_curve_time == first) - { + if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; continue; } @@ -278,19 +276,19 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = boost::none; - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); previous = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - if(previous){ + if(previous) { it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); + pwd2[it - satellites.begin()]); } else { it->amount = 0.0; } @@ -300,12 +298,12 @@ void LPEFilletChamfer::updateAmount() } } else { if (!use_knot_distance && !flexible) { - if(previous){ + if(previous) { it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); - } else { - it->amount = 0.0; - } + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } @@ -361,7 +359,7 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - if(!_hp.empty()){ + if(!_hp.empty()) { _hp.clear(); } SPLPEItem *splpeitem = const_cast(lpeItem); @@ -382,7 +380,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector sats = satellites_param.data(); - if(sats.empty()){ + if(sats.empty()) { doOnApply(lpeItem); sats = satellites_param.data(); } @@ -413,7 +411,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate - //todo: fire a reverse satellites on reverse path. Maybe a new method + //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector if (pointwise && number_curves != sats.size()) { @@ -609,7 +607,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { @@ -628,8 +626,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -648,8 +645,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -666,10 +662,9 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); + end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); @@ -677,11 +672,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); + end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, end_arc_point); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index b7d403a91..5e45ddf0d 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -94,15 +94,15 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - + Geom::Path sat_path = pointwise_pv.pathAt(i); boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -298,10 +298,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -360,10 +360,10 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -454,13 +454,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } - + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { if (d2_prev_index) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); @@ -504,10 +504,10 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) boost::optional prev = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; } if (prev) { -- cgit v1.2.3 From 6962e3344dea73a3bc7d5599cc223ed8cc7cdbe7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 21 Aug 2015 23:53:14 +0200 Subject: Not sure about this changes :( (bzr r13645.1.107) --- src/live_effects/parameter/satellitearray.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5e45ddf0d..9c22741ff 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -361,8 +361,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + d2_prev_index = first + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } -- cgit v1.2.3 From 4f78e3e4289b52ba4b7a3fbe24fd0d6fcb6f2250 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 23 Aug 2015 23:03:12 +0200 Subject: satellites in curves (bzr r13645.1.110) --- src/live_effects/lpe-fillet-chamfer.cpp | 102 ++++++++++----------- src/live_effects/parameter/satellitearray.cpp | 127 +++++++++----------------- 2 files changed, 90 insertions(+), 139 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 8998279a6..385e9ce28 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -85,19 +85,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - Geom::PathVector const original_pathv = - pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, 0.01); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); int global_counter = 0; std::vector satellites; - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { + for (Geom::PathVector::const_iterator path_it = pathv.begin(); + path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_endit = path_it->end_closed(); int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -106,6 +103,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (counter == 0) { if (!path_it->closed()) { active = false; + hidden = true; } } Satellite satellite(FILLET); @@ -123,9 +121,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(); - pointwise->setPwd2(pwd2_in); - pointwise->setSatellites(satellites); - pointwise->setStart(); + pointwise->setPathVector(pathv); + pointwise->setSatellites(satellites, false); + //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -262,11 +260,14 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); + Geom::PathVector const pathv = pointwise->getPathVector(); + //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector + //but is very dificult know the index of a curve inside a pathvector with current API Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); - size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); + Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(it - satellites.begin()).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; @@ -282,25 +283,12 @@ void LPEFilletChamfer::updateAmount() } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - if (!use_knot_distance && !flexible) { - if(previous) { - it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); - } else { - it->amount = 0.0; - } - } else { - it->amount = power; - } - } - } else { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { if(previous) { - it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); + it->amount = it->radToLen(power, pathv.curveAt(*previous), + pathv.curveAt(it - satellites.begin())); } else { it->amount = 0.0; } @@ -375,31 +363,36 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const original_pathv = + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellites_param.data(); + Geom::Piecewise > pwd2 = paths_to_pw(pathv); + pwd2 = remove_short_cuts(pwd2, 0.01); + std::vector sats = normalizeSatellites(pathv, satellites_param.data()); if(sats.empty()) { doOnApply(lpeItem); - sats = satellites_param.data(); + sats = normalizeSatellites(pathv, satellites_param.data()); } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } + Geom::Curve const &first_curve = pathv.curveAt(0); + size_t number_curves = pathv.curveCount(); + //Activete cache + timeAtArcLength(1, first_curve, number_curves * 3); + arcLengthAt(1, first_curve, number_curves * 3); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { it->is_time = flexible; double amount = it->amount; - Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + Geom::Curve const &curve_in = pathv.curveAt(it - sats.begin()); if (it->is_time) { - double time = timeAtArcLength(amount, d2_in); + double time = timeAtArcLength(amount, curve_in); it->amount = time; } else { - double size = arcLengthAt(amount, d2_in); + double size = arcLengthAt(amount, curve_in); it->amount = size; } } @@ -409,7 +402,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise @@ -423,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sat.setAmount(0.0); sat.setAngle(0.0); sat.setSteps(0); - pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); + pointwise->recalculateForNewPwd2(pwd2, pathv, sat); } else { pointwise = new Pointwise(); - pointwise->setPwd2(pwd2_in); + pointwise->setPwd2(pwd2); pointwise->setSatellites(sats); } pointwise->setStart(); @@ -519,16 +511,16 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (first == counter) { if (sats.size() > first && sats[first].active) { time0 = - sats[first].time(path_it->begin()->duplicate()->toSBasis()); + sats[first].time(*path_it->begin()); } else { time0 = 0; } } - + Geom::Curve const &curve_it2_fixed_ref = *curve_it2_fixed; bool last = curve_it2 == curve_endit; - double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); - double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); - double time2 = satellite.time(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed_ref); + double time1 = satellite.time(s, true, (*curve_it1)); + double time2 = satellite.time(curve_it2_fixed_ref); if (!satellite.active) { time1 = 1; time2 = 0; @@ -552,15 +544,15 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); if (times[2] == 1) { - end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); + end_arc_point = curve_it2_fixed_ref.pointAt(times[2] - GAP_HELPER); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); } double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; + double k2 = distance(end_arc_point, curve_it2_fixed_ref.initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); @@ -571,10 +563,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed_ref.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed_ref.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } @@ -597,7 +589,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { - end_arc_point = curve_it2_fixed->pointAt(times[2]); + end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); @@ -625,7 +617,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, @@ -644,7 +636,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -661,7 +653,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -671,7 +663,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 9c22741ff..ba1338daa 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -73,8 +73,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (!_last_pointwise) { return; } + Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (mirror == true) { _hp.clear(); } @@ -86,21 +87,21 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) continue; } double pos = 0; - if (pwd2.size() <= i) { + if (pathv.size() <= i) { break; } - Geom::D2 d2 = pwd2[i]; + Geom::Curve &curve = const_cast(pathv.curveAt(i)); bool overflow = false; - double size_out = _vector[i].arcDistance(pwd2[i]); - double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); + double size_out = _vector[i].arcDistance(pathv.curveAt(i)); + double lenght_out = pathv.curveAt(i).length( Geom::EPSILON); double lenght_in = 0; - Geom::Path sat_path = pointwise_pv.pathAt(i); + Geom::Path sat_path = pathv.pathAt(i); boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; @@ -110,14 +111,14 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } if (mirror == true) { if (d2_prev_index) { - d2 = pwd2[*d2_prev_index]; - pos = _vector[i].time(size_out, true, d2); + curve = pathv.curveAt(*d2_prev_index); + pos = _vector[i].time(size_out, true, curve); if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].time(d2); + pos = _vector[i].time(curve); if (lenght_in < size_out) { overflow = true; } @@ -125,8 +126,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (pos <= 0 || pos >= 1) { continue; } - Geom::Point point_a = d2.valueAt(pos); - Geom::Point deriv_a = unit_vector(derivative(d2).valueAt(pos)); + Geom::Point point_a = curve.pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve.toSBasis()).valueAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); deriv_a = deriv_a * rot; Geom::Point point_c = point_a - deriv_a * _helper_size; @@ -141,7 +142,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(d2.valueAt(pos)); + aff *= Geom::Translate(curve.pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); @@ -171,7 +172,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(d2.valueAt(pos)); + aff *= Geom::Translate(curve.pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); } @@ -292,36 +293,16 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { - Geom::Path sat_path = pointwise_pv.pathAt(index); - boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; - } - if (d2_prev_index) { - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirror_time = Geom::nearest_time(s, d2_in); - double time_start = 0; - std::vector sats = pointwise->getSatellites(); - time_start = sats[*d2_prev_index].time(d2_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, d2_in); - double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pwd2[index]); - } - satellite.amount = amount; + Geom::Path sat_path = pathv.pathAt(index); + if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { + satellite.setPosition(s, sat_path.back(), true); + } else { + satellite.setPosition(s, pathv.curveAt(index-1), true); } } else { - satellite.setPosition(s, pwd2[index]); + satellite.setPosition(s, pathv.curveAt(index)); } _pparam->_vector.at(index) = satellite; SPLPEItem *splpeitem = dynamic_cast(item); @@ -349,41 +330,20 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { - tmp_point = satellite.getPosition(pwd2[index]); - Geom::Path sat_path = pointwise_pv.pathAt(index); - boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - d2_prev_index = first + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; - } - if (d2_prev_index) { - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.arcDistance(pwd2[index]); - double t = satellite.time(s, true, d2_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[*d2_prev_index].time(d2_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (d2_in).valueAt(t); + Geom::Path sat_path = pathv.pathAt(index); + if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { + tmp_point = satellite.getPosition(sat_path.back(), true); + } else { + tmp_point = satellite.getPosition(pathv.curveAt(index - 1), true); } } else { - tmp_point = satellite.getPosition(pwd2[index]); + tmp_point = satellite.getPosition(pathv.curveAt(index)); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -447,11 +407,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; - Geom::Path sat_path = pointwise_pv.pathAt(index); + Geom::Path sat_path = pathv.pathAt(index); boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); @@ -462,18 +422,17 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { if (d2_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); + amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*d2_prev_index), pathv.curveAt(index),_pparam->_vector.at(*d2_prev_index)); } else { amount = 0.0; } } bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + Geom::Curve const &curve_out = pathv.curveAt(index); if (d2_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && + Geom::Curve const &curve_in = pathv.curveAt(*d2_prev_index); + aprox = (curve_in.degreesOfFreedom() != 2 || + curve_out.degreesOfFreedom() != 2) && !_pparam->_use_distance ? true : false; @@ -498,19 +457,19 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pointwise_pv.pathAt(index); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(index); boost::optional prev = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; } if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); + amount = _pparam->_vector.at(index).radToLen(amount, pathv.curveAt(*prev), pathv.curveAt(index)); } else { amount = 0.0; } -- cgit v1.2.3 From 89b565d68326ada49d11d0735ffb6b602c26a54f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 24 Aug 2015 00:58:37 +0200 Subject: Cached some functions (bzr r13645.1.111) --- src/live_effects/lpe-fillet-chamfer.cpp | 12 +-- src/live_effects/parameter/satellitearray.cpp | 115 +++++++++++++++++--------- 2 files changed, 82 insertions(+), 45 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 385e9ce28..3fa011b38 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -94,7 +94,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_closed(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -121,8 +121,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(); - pointwise->setPathVector(pathv); - pointwise->setSatellites(satellites, false); + pointwise->setPwd2(paths_to_pw(pathv)); + pointwise->setSatellites(satellites); //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { @@ -260,10 +260,10 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); - Geom::PathVector const pathv = pointwise->getPathVector(); //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector //but is very dificult know the index of a curve inside a pathvector with current API Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); @@ -367,10 +367,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Geom::Piecewise > pwd2 = paths_to_pw(pathv); pwd2 = remove_short_cuts(pwd2, 0.01); - std::vector sats = normalizeSatellites(pathv, satellites_param.data()); + std::vector sats = satellites_param.data(); if(sats.empty()) { doOnApply(lpeItem); - sats = normalizeSatellites(pathv, satellites_param.data()); + sats = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index ba1338daa..6c3123f12 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -87,38 +87,37 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) continue; } double pos = 0; - if (pathv.size() <= i) { + if (pwd2.size() <= i) { break; } - Geom::Curve &curve = const_cast(pathv.curveAt(i)); + Geom::Curve *curve_in = pathv.curveAt(i).duplicate(); bool overflow = false; - double size_out = _vector[i].arcDistance(pathv.curveAt(i)); - double lenght_out = pathv.curveAt(i).length( Geom::EPSILON); + double size_out = _vector[i].arcDistance(*curve_in); + double lenght_out = curve_in->length(); double lenght_in = 0; Geom::Path sat_path = pathv.pathAt(i); - boost::optional d2_prev_index = boost::none; + boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + curve_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; + curve_prev_index = sat_curve_time - 1; } - if (d2_prev_index) { - lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); + if (curve_prev_index) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); } if (mirror == true) { - if (d2_prev_index) { - curve = pathv.curveAt(*d2_prev_index); - pos = _vector[i].time(size_out, true, curve); + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i].time(size_out, true, *curve_in); if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].time(curve); + pos = _vector[i].time(*curve_in); if (lenght_in < size_out) { overflow = true; } @@ -126,8 +125,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (pos <= 0 || pos >= 1) { continue; } - Geom::Point point_a = curve.pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve.toSBasis()).valueAt(pos)); + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); deriv_a = deriv_a * rot; Geom::Point point_c = point_a - deriv_a * _helper_size; @@ -142,7 +141,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(curve.pointAt(pos)); + aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); @@ -172,7 +171,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(curve.pointAt(pos)); + aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); } @@ -296,10 +295,29 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { Geom::Path sat_path = pathv.pathAt(index); - if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { - satellite.setPosition(s, sat_path.back(), true); - } else { - satellite.setPosition(s, pathv.curveAt(index-1), true); + boost::optional curve_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first) { + curve_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first) { + curve_prev_index = sat_curve_time - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + std::vector sats = pointwise->getSatellites(); + time_start = sats[*curve_prev_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; + } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv.curveAt(index)); + } + satellite.amount = amount; } } else { satellite.setPosition(s, pathv.curveAt(index)); @@ -336,11 +354,32 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } this->knot->show(); if (_index >= _pparam->_vector.size()) { + tmp_point = satellite.getPosition(pathv.curveAt(index)); Geom::Path sat_path = pathv.pathAt(index); - if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { - tmp_point = satellite.getPosition(sat_path.back(), true); - } else { - tmp_point = satellite.getPosition(pathv.curveAt(index - 1), true); + boost::optional curve_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint(), pwd2); + if (sat_path.closed() && sat_curve_time == first) { + curve_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first) { + curve_prev_index = sat_curve_time - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); + double s = satellite.arcDistance(pathv.curveAt(index)); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; + } + double time_start = 0; + time_start = pointwise->getSatellites()[*curve_prev_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); } } else { tmp_point = satellite.getPosition(pathv.curveAt(index)); @@ -410,29 +449,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; Geom::Path sat_path = pathv.pathAt(index); - boost::optional d2_prev_index = boost::none; + boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + curve_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; + curve_prev_index = sat_curve_time - 1; } - if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - if (d2_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*d2_prev_index), pathv.curveAt(index),_pparam->_vector.at(*d2_prev_index)); + if (curve_prev_index) { + amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*curve_prev_index), pathv.curveAt(index), _pparam->_vector.at(*curve_prev_index)); } else { amount = 0.0; } } bool aprox = false; - Geom::Curve const &curve_out = pathv.curveAt(index); - if (d2_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*d2_prev_index); - aprox = (curve_in.degreesOfFreedom() != 2 || - curve_out.degreesOfFreedom() != 2) && + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + if (curve_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[*curve_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance ? true : false; @@ -463,7 +501,6 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; -- cgit v1.2.3 From d34b8dca901083e5b68fd22899cb2c014238f8a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:39:35 +0200 Subject: addes cache and log to a function, result of the test, no diference so remove cache on next commit (bzr r13645.1.112) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 ++++++-- src/live_effects/lpe-fillet-chamfer.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3fa011b38..a83c7bbd5 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,6 +55,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), + cache(_("Cache size:"),_("Cache size"), "cache_size", &wr, this, 3), pointwise(NULL) { registerParameter(&satellites_param); @@ -68,6 +69,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); + registerParameter(&cache); radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); @@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); + cache.param_set_range(0, 999); + cache.param_set_increments(1, 1); + cache.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -380,8 +385,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::Curve const &first_curve = pathv.curveAt(0); size_t number_curves = pathv.curveCount(); //Activete cache - timeAtArcLength(1, first_curve, number_curves * 3); - arcLengthAt(1, first_curve, number_curves * 3); + timeAtArcLength(1, first_curve, number_curves * cache); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 804709342..9c58ab66c 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -58,6 +58,7 @@ private: BoolParam hide_knots; BoolParam ignore_radius_0; ScalarParam helper_size; + ScalarParam cache; Pointwise *pointwise; Geom::PathVector _hp; -- cgit v1.2.3 From 6d0ce49991a442e7e3f26c3922c26e54d927dd93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:48:02 +0200 Subject: Removed cache work :( (bzr r13645.1.113) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 -------- src/live_effects/lpe-fillet-chamfer.h | 1 - 2 files changed, 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a83c7bbd5..4c325b7fa 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,7 +55,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - cache(_("Cache size:"),_("Cache size"), "cache_size", &wr, this, 3), pointwise(NULL) { registerParameter(&satellites_param); @@ -69,7 +68,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); - registerParameter(&cache); radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); @@ -80,9 +78,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); - cache.param_set_range(0, 999); - cache.param_set_increments(1, 1); - cache.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -382,10 +377,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - Geom::Curve const &first_curve = pathv.curveAt(0); size_t number_curves = pathv.curveCount(); - //Activete cache - timeAtArcLength(1, first_curve, number_curves * cache); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 9c58ab66c..804709342 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -58,7 +58,6 @@ private: BoolParam hide_knots; BoolParam ignore_radius_0; ScalarParam helper_size; - ScalarParam cache; Pointwise *pointwise; Geom::PathVector _hp; -- cgit v1.2.3 From 4b21c95466fd2e108caccafb3feb1d17e5055431 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 21:34:58 +0200 Subject: add 'little' comment (bzr r13645.1.114) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 - src/live_effects/parameter/satellitearray.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 4c325b7fa..24ed983fd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -278,7 +278,6 @@ void LPEFilletChamfer::updateAmount() } boost::optional previous = boost::none; if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); previous = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 6c3123f12..ab2b9fe2e 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -294,6 +294,16 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Piecewise > pwd2 = pointwise->getPwd2(); Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { + //I want to remplace this whith patvectorTime but need a way to know the index of a curve in a pathvector + //Geom::Path sat_path = pathv.pathAt(index); + //PathTime sat_time = sat_path.nearestTime(pathv.curveAt(index).initialPoint()); + //boost::optional previous_index = boost::none; + //if (sat_path.closed() && sat_time.curve_index == 0) { + // previous_index = sat_path.size(); + //} else if(!sat_path.closed() || sat_time.curve_index != 0) { + // previous_index = sat_time.curve_index - 1; + //} + //if (previous_index) { Geom::Path sat_path = pathv.pathAt(index); boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); -- cgit v1.2.3 From 67753b095a9a4c3ce0f22a3c63b5adb863c087ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 1 Sep 2015 21:54:18 +0200 Subject: Update to limit options to radius = 0, radious > 0 or both (bzr r13645.1.118) --- src/live_effects/lpe-fillet-chamfer.cpp | 19 +++++++++++++------ src/live_effects/lpe-fillet-chamfer.h | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ed983fd..8c3b6e2f1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -51,8 +51,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), - "ignore_radius_0", &wr, this, false), + apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), + apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise(NULL) @@ -65,7 +65,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); - registerParameter(&ignore_radius_0); + registerParameter(&apply_no_radius); + registerParameter(&apply_with_radius); registerParameter(&only_selected); registerParameter(&hide_knots); @@ -273,7 +274,9 @@ void LPEFilletChamfer::updateAmount() it->amount = 0; continue; } - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } boost::optional previous = boost::none; @@ -306,7 +309,9 @@ void LPEFilletChamfer::updateChamferSteps() Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } if (only_selected) { @@ -328,7 +333,9 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } if (only_selected) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 804709342..638e8c6af 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -56,7 +56,8 @@ private: BoolParam only_selected; BoolParam use_knot_distance; BoolParam hide_knots; - BoolParam ignore_radius_0; + BoolParam apply_no_radius; + BoolParam apply_with_radius; ScalarParam helper_size; Pointwise *pointwise; -- cgit v1.2.3 From 7fee08f7ade15cbba3932dd745492779e7e01987 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 00:17:44 +0100 Subject: Fixed bugs post merge (bzr r13645.1.120) --- src/live_effects/parameter/satellitearray.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index ab2b9fe2e..1615f33e2 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -137,9 +137,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(_helper_size); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); } aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; @@ -167,9 +167,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) aff = Geom::Affine(); aff *= Geom::Scale(_helper_size / 2.0); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); } aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; -- cgit v1.2.3 From 01836c90d5d768fe4f189bf066cb4ed800196d8d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 07:59:18 +0100 Subject: Remove advertaising buttons of old version (bzr r13645.1.123) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d91225cb7..896cf2e69 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -146,14 +146,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); vbox->set_spacing(2); - Gtk::HBox *advertaising = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *advert = Gtk::manage(new Gtk::Button(Glib::ustring(_("IMPORTANT! New version soon...")))); - advertaising->pack_start(*advert, true, true, 2); - vbox->pack_start(*advertaising, true, true, 2); - Gtk::HBox *advertaising2 = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *advert2 = Gtk::manage(new Gtk::Button(Glib::ustring(_("Not compatible. Convert to path after.")))); - advertaising2->pack_start(*advert2, true, true, 2); - vbox->pack_start(*advertaising2, true, true, 2); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { -- cgit v1.2.3 From 90fa52d140c68277789d5c87b86bd7a73969458d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 8 Apr 2016 18:03:17 +0200 Subject: remove a waring on compile (bzr r13645.1.126) --- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 896cf2e69..956395623 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -609,7 +609,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1) { + if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } -- cgit v1.2.3 From 97bd182d6a2113eab1dd5faf51402ebd5382791c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 22:57:37 +0200 Subject: First attempt to make fixed tweenk review (bzr r13645.1.128) --- src/live_effects/lpe-fillet-chamfer.cpp | 240 +++++------ src/live_effects/lpe-fillet-chamfer.h | 4 +- src/live_effects/parameter/Makefile_insert | 4 +- src/live_effects/parameter/array.cpp | 71 ++-- src/live_effects/parameter/array.h | 35 +- src/live_effects/parameter/satellitearray.cpp | 550 ------------------------- src/live_effects/parameter/satellitearray.h | 114 ----- src/live_effects/parameter/satellitesarray.cpp | 527 +++++++++++++++++++++++ src/live_effects/parameter/satellitesarray.h | 115 ++++++ 9 files changed, 810 insertions(+), 850 deletions(-) delete mode 100644 src/live_effects/parameter/satellitearray.cpp delete mode 100644 src/live_effects/parameter/satellitearray.h create mode 100644 src/live_effects/parameter/satellitesarray.cpp create mode 100644 src/live_effects/parameter/satellitesarray.h (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 956395623..bcab1c055 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -91,39 +91,30 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPShape *shape = dynamic_cast(splpeitem); if (shape) { Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - int global_counter = 0; - std::vector satellites; - for (Geom::PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { + Satellites satellites; + for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } + std::vector subpath_satellites; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - int counter = 0; - size_t steps = chamfer_steps; + bool start = true; while (curve_it1 != curve_endit) { - bool active = true; bool hidden = false; - if (counter == 0) { + if (start) { if (!path_it->closed()) { - active = false; hidden = true; } + start = false; } Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setActive(active); - satellite.setHasMirror(mirror_knots); satellite.setHidden(hidden); - satellite.setAmount(0.0); - satellite.setAngle(0.0); - satellite.setSteps(steps); - satellites.push_back(satellite); + satellite.setSteps(chamfer_steps); + subpath_satellites.push_back(satellite); ++curve_it1; - counter++; - global_counter++; } + satellites.push_back(subpath_satellites); } pointwise = new Pointwise(); pointwise->setPwd2(paths_to_pw(pathv)); @@ -264,42 +255,36 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); - //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector - //but is very dificult know the index of a curve inside a pathvector with current API - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(it - satellites.begin()).initialPoint() , pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (!sat_path.closed() && sat_curve_time == first) { - it->amount = 0; - continue; - } - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - boost::optional previous = boost::none; - if (sat_path.closed() && sat_curve_time == first) { - previous = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - previous = sat_curve_time - 1; - } - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point) || !only_selected) { - if (!use_knot_distance && !flexible) { - if(previous) { - it->amount = it->radToLen(power, pathv.curveAt(*previous), - pathv.curveAt(it - satellites.begin())); + Satellites satellites = pointwise->getSatellites(); + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[pathv[i].size() - 1]; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } + if (!pathv[i].closed() && sat_curve_time == 0) { + it->amount = 0; + continue; + } + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { + continue; + } + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point) || !only_selected) { + if (!use_knot_distance && !flexible) { + if(curve_prev_index) { + it->amount = it->radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + } else { + it->amount = 0.0; + } } else { - it->amount = 0.0; + it->amount = power; } - } else { - it->amount = power; } } } @@ -310,21 +295,22 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - it->steps = chamfer_steps; + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if ((!apply_no_radius && satellites[i][j]->amount == 0) || + (!apply_with_radius && satellites[i][j]->amount != 0)) + { + continue; + } + if (only_selected) { + Geom::Point satellite_point = pathv[i].pointAt(j); + if (isNodePointSelected(satellite_point)) { + satellites[i][j]->steps = chamfer_steps; + } + } else { + satellites[i][j]->steps = chamfer_steps; } - } else { - it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); @@ -334,21 +320,22 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - it->satellite_type = satellitetype; + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if ((!apply_no_radius && satellites[i][j]->amount == 0) || + (!apply_with_radius && satellites[i][j]->amount != 0)) + { + continue; + } + if (only_selected) { + Geom::Point satellite_point = pathv[i].pointAt(j); + if (isNodePointSelected(satellite_point)) { + satellites[i][j]->satellite_type = satellitetype; + } + } else { + satellites[i][j]->satellite_type = satellitetype; } - } else { - it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); @@ -373,14 +360,13 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const pathv = - pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Geom::Piecewise > pwd2 = paths_to_pw(pathv); pwd2 = remove_short_cuts(pwd2, 0.01); - std::vector sats = satellites_param.data(); - if(sats.empty()) { + Satellites satelites = satellites_param.data(); + if(satelites.empty()) { doOnApply(lpeItem); - sats = satellites_param.data(); + satelites = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); @@ -388,44 +374,39 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setHelperSize(helper_size); } size_t number_curves = pathv.curveCount(); - for (std::vector::iterator it = sats.begin(); - it != sats.end();) { - if (it->is_time != flexible) { - it->is_time = flexible; - double amount = it->amount; - Geom::Curve const &curve_in = pathv.curveAt(it - sats.begin()); - if (it->is_time) { - double time = timeAtArcLength(amount, curve_in); - it->amount = time; - } else { - double size = arcLengthAt(amount, curve_in); - it->amount = size; + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if (satellites[i][j]->is_time != flexible) { + satellites[i][j]->is_time = flexible; + double amount = satellites[i][j]->amount; + Geom::Curve const &curve_in = pathv[i][j]; + if (satellites[i][j]->is_time) { + double time = timeAtArcLength(amount, curve_in); + satellites[i][j]->amount = time; + } else { + double size = arcLengthAt(amount, curve_in); + satellites[i][j]->amount = size; + } } + if (satellites[i][j]->has_mirror != mirror_knots) { + satellites[i][j]->has_mirror = mirror_knots; + } + satellites[i][j]->hidden = hide_knots; } - if (it->has_mirror != mirror_knots) { - it->has_mirror = mirror_knots; - } - it->hidden = hide_knots; - ++it; } //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector - if (pointwise && number_curves != sats.size()) { - Satellite sat(sats[0].satellite_type); - sat.setIsTime(sats[0].is_time); - sat.setActive(true); - sat.setHasMirror( sats[0].has_mirror); - sat.setHidden(false); - sat.setAmount(0.0); - sat.setAngle(0.0); - sat.setSteps(0); - pointwise->recalculateForNewPwd2(pwd2, pathv, sat); + if (pointwise && number_curves != pointwise->getTotalSatellites()) { + Satellite satellite(satellites[0][0].satellite_type); + satellite.setIsTime(satellites[0][0].is_time); + satellite.setHasMirror(satellites[0][0].has_mirror); + pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); } else { pointwise = new Pointwise(); pointwise->setPwd2(pwd2); - pointwise->setSatellites(sats); + pointwise->setSatellites(satellites); } pointwise->setStart(); satellites_param.setPointwise(pointwise); @@ -446,12 +427,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; Geom::PathVector path_out; - size_t counter = 0; + size_t counter_paths = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - Geom::PathVector path_in_processed = - pathv_to_linear_and_cubic_beziers(path_in); - for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); - path_it != path_in_processed.end(); ++path_it) { + Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -470,14 +449,13 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + Satellites satelites = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { ++curve_it2; } if ((*curve_it1).isDegenerate()) { ++curve_it1; - counter++; counter_curves++; time0 = 0.0; continue; @@ -487,8 +465,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); - if (sats.size() > counter + 1) { - satellite = sats[counter + 1]; + if (satellites[counter_paths].size() > counter_curves + 1) { + satellite = satellites[counter_paths][counter_curves + 1]; } } else { if (time0 != 1) { @@ -497,27 +475,25 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.append(*last_curve); } ++curve_it1; - counter++; counter_curves++; continue; } } else { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); - if (sats.size() > counter + 1) { - satellite = sats[counter + 1]; + if (satellites[counter_paths].size() > counter_curves + 1) { + satellite = satellites[counter_paths][counter_curves + 1];; } } else { - if (sats.size() > first) { - satellite = sats[first]; + if (satellites[counter_paths].size() > 0) { + satellite = satellites[counter_paths][0]; } } } - if (first == counter) { - if (sats.size() > first && sats[first].active) { - time0 = - sats[first].time(*path_it->begin()); + if (counter_curves == 0) { + if (satellites[counter_paths].size() > 0 && satellites[counter_paths][0].active) { + time0 = satellites[counter_paths][0].time(*path_it->begin()); } else { time0 = 0; } @@ -691,10 +667,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve_it2 != curve_endit) { ++curve_it2; } - counter++; counter_curves++; time0 = times[2]; } + counter_paths++; path_out.push_back(tmp_path); } return path_out; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 638e8c6af..a209971dd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -13,7 +13,7 @@ */ #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/satellitearray.h" +#include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "helper/geom-pointwise.h" @@ -45,7 +45,7 @@ public: void fillet(); void inverseFillet(); - SatelliteArrayParam satellites_param; + SatellitesArrayParam satellites_param; private: EnumParam method; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 9a0ebe235..ab4a8eb4e 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -22,8 +22,8 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/satellitearray.cpp \ - live_effects/parameter/satellitearray.h \ + live_effects/parameter/satellitesarray.cpp \ + live_effects/parameter/satellitesarray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 0abcd4b9b..0bbe39293 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -13,35 +13,43 @@ namespace Inkscape { namespace LivePathEffect { -//TODO: move maybe to svg-lenght.cpp +//TODO: move maybe unsigned int -sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ +sp_svg_satellite_vector_read_d(gchar const *str, std::vector *satellites){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, ",", 8); - if(strlen(str) > 0 && strarray[7] && !strarray[8]){ - sat->setSatelliteType(g_strstrip(strarray[0])); - sat->is_time = strncmp(strarray[1],"1",1) == 0; - sat->active = strncmp(strarray[2],"1",1) == 0; - sat->has_mirror = strncmp(strarray[3],"1",1) == 0; - sat->hidden = strncmp(strarray[4],"1",1) == 0; - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strarray[5], &amount); - sp_svg_number_read_d(strarray[6], &angle); - sp_svg_number_read_f(strarray[7], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - sat->amount = amount; - sat->angle = angle; - sat->steps = steps; - g_strfreev (strarray); - return 1; + gchar ** strarray = g_strsplit(str, "@", 0); + for (size_t i = 0; i < strarray.size(); ++i) { + gchar ** strsubarray = g_strsplit(strarray[i], ",", 7); + if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ + Satellite sat; + sat->setSatelliteType(g_strstrip(strsubarray[0])); + sat->is_time = strncmp(strsubarray[1],"1",1) == 0; + sat->has_mirror = strncmp(strsubarray[2],"1",1) == 0; + sat->hidden = strncmp(strsubarray[3],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strsubarray[4], &amount); + sp_svg_number_read_d(strsubarray[5], &angle); + sp_svg_number_read_f(strsubarray[6], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + sat->amount = amount; + sat->angle = angle; + sat->steps = steps; + g_strfreev (strsubarray); + satellites.push_back(sat); + } + g_strfreev (strsubarray); } g_strfreev (strarray); + if (!sat.empty()){ + return 1; + } return 0; } + template <> double ArrayParam::readsvg(const gchar * str) @@ -75,25 +83,20 @@ ArrayParam::readsvg(const gchar * str) return Geom::Point(Geom::infinity(),Geom::infinity()); } + template <> -Satellite -ArrayParam::readsvg(const gchar * str) +std::vector +ArrayParam >::readsvg(const gchar * str) { - Satellite sat; - if (sp_svg_satellite_read_d(str, &sat)) { - return sat; + std::vector satellites; + if (sp_svg_satellite_vector_read_d(str, &satellites)) { + return satellites; } - Satellite satellite(FILLET); - satellite.setIsTime(true); - satellite.setActive(false); - satellite.setHasMirror(false); - satellite.setHidden(true); - satellite.setAmount(0.0); - satellite.setAngle(0.0); - satellite.setSteps(0); - return satellite; + satellites.push_back(Satellite satellite(FILLET)); + return satellites; } + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 66ed6344b..7076a465f 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -110,22 +110,25 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, Satellite const &nVector) const { - str << nVector.getSatelliteTypeGchar(); - str << ","; - str << nVector.is_time; - str << ","; - str << nVector.active; - str << ","; - str << nVector.has_mirror; - str << ","; - str << nVector.hidden; - str << ","; - str << nVector.amount; - str << ","; - str << nVector.angle; - str << ","; - str << nVector.steps; + void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { + for (size_t i = 0; i < nVector.size(); ++i) { + str << nVector[i].getSatelliteTypeGchar(); + str << ","; + str << nVector[i].is_time; + str << ","; + str << nVector[i].has_mirror; + str << ","; + str << nVector[i].hidden; + str << ","; + str << nVector[i].amount; + str << ","; + str << nVector[i].angle; + str << ","; + str << nVector[i].steps; + if (i != nVector.size()-1) { + str << "@"; + } + } } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp deleted file mode 100644 index 1615f33e2..000000000 --- a/src/live_effects/parameter/satellitearray.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Author(s): - * Jabiertxo Arraiza Cenoz - * - * Copyright (C) 2014 Author(s) - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitearray.h" -#include "live_effects/effect.h" -#include "sp-lpe-item.h" -#include -#include -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - -namespace Inkscape { - -namespace LivePathEffect { - -SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) -{ - _knot_shape = SP_KNOT_SHAPE_DIAMOND; - _knot_mode = SP_KNOT_MODE_XOR; - _knot_color = 0xAAFF8800; - _helper_size = 0; - _use_distance = false; - _effectType = FILLET_CHAMFER; - _last_pointwise = NULL; -} - -void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - _knot_shape = shape; - _knot_mode = mode; - _knot_color = color; -} - -void SatelliteArrayParam::setPointwise(Pointwise *pointwise) -{ - _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise->getSatellites()); -} - -void SatelliteArrayParam::setUseDistance(bool use_knot_distance) -{ - _use_distance = use_knot_distance; -} - -void SatelliteArrayParam::setEffectType(EffectType et) -{ - _effectType = et; -} - -void SatelliteArrayParam::setHelperSize(int hs) -{ - _helper_size = hs; - updateCanvasIndicators(); -} - -void SatelliteArrayParam::updateCanvasIndicators(bool mirror) -{ - if (!_last_pointwise) { - return; - } - - Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (mirror == true) { - _hp.clear(); - } - for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].active || _vector[i].hidden) { - continue; - } - if ((!_vector[i].has_mirror && mirror == true) || _vector[i].amount == 0) { - continue; - } - double pos = 0; - if (pwd2.size() <= i) { - break; - } - Geom::Curve *curve_in = pathv.curveAt(i).duplicate(); - bool overflow = false; - double size_out = _vector[i].arcDistance(*curve_in); - double lenght_out = curve_in->length(); - double lenght_in = 0; - - Geom::Path sat_path = pathv.pathAt(i); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); - } - if (mirror == true) { - if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i].time(size_out, true, *curve_in); - if (lenght_out < size_out) { - overflow = true; - } - } - } else { - pos = _vector[i].time(*curve_in); - if (lenght_in < size_out) { - overflow = true; - } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point point_a = curve_in->pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - deriv_a = deriv_a * rot; - Geom::Point point_c = point_a - deriv_a * _helper_size; - Geom::Point point_d = point_a + deriv_a * _helper_size; - Geom::Ray ray_1(point_c, point_d); - char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - _hp.push_back(pathv[1]); - if (overflow) { - double diameter = _helper_size; - if (_helper_size == 0) { - diameter = 15; - char const *svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " - "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(diameter); - aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); - pathv *= aff; - _hp.push_back(pathv[0]); - } else { - char const *svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " - "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " - "0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size / 2.0); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - } - } - } - if (mirror == true) { - updateCanvasIndicators(false); - } -} -void SatelliteArrayParam::updateCanvasIndicators() -{ - updateCanvasIndicators(true); -} - -void SatelliteArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(_hp); -} - -void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true)) { - for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].is_time && _vector[i].amount > 0) { - _vector[i].amount = _vector[i].amount * - ((postmul.expansionX() + postmul.expansionY()) / 2); - } - } - param_set_and_write_new_value(_vector); - } -} - -void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, bool mirror) -{ - for (size_t i = 0; i < _vector.size(); ++i) { - size_t iPlus = i; - if (mirror == true) { - iPlus = i + _vector.size(); - } - if (!_vector[i].active) { - continue; - } - if (!_vector[i].has_mirror && mirror == true) { - continue; - } - using namespace Geom; - SatelliteType type = _vector[i].satellite_type; - //IF is for filletChamfer effect... - if (_effectType == FILLET_CHAMFER) { - const gchar *tip; - if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - _knot_shape, _knot_mode, _knot_color); - knotholder->add(e); - } - } - if (mirror == true) { - addKnotHolderEntities(knotholder, desktop, item, false); - } -} - -void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); -} - -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( - SatelliteArrayParam *p, size_t index) - : _pparam(p), _index(index) {} - -void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, - Geom::Point const &/*origin*/, - guint state) -{ - Geom::Point s = snap_knot_position(p, state); - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (!valid_index(index)) { - return; - } - - if (!_pparam->_last_pointwise) { - return; - } - - Satellite satellite = _pparam->_vector.at(index); - if (!satellite.active || satellite.hidden) { - return; - } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (_index >= _pparam->_vector.size() ) { - //I want to remplace this whith patvectorTime but need a way to know the index of a curve in a pathvector - //Geom::Path sat_path = pathv.pathAt(index); - //PathTime sat_time = sat_path.nearestTime(pathv.curveAt(index).initialPoint()); - //boost::optional previous_index = boost::none; - //if (sat_path.closed() && sat_time.curve_index == 0) { - // previous_index = sat_path.size(); - //} else if(!sat_path.closed() || sat_time.curve_index != 0) { - // previous_index = sat_time.curve_index - 1; - //} - //if (previous_index) { - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); - double mirror_time = Geom::nearest_time(s, curve_in); - double time_start = 0; - std::vector sats = pointwise->getSatellites(); - time_start = sats[*curve_prev_index].time(curve_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, curve_in); - double amount = curve_in.length() - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv.curveAt(index)); - } - satellite.amount = amount; - } - } else { - satellite.setPosition(s, pathv.curveAt(index)); - } - _pparam->_vector.at(index) = satellite; - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -Geom::Point FilletChamferKnotHolderEntity::knot_get() const -{ - Geom::Point tmp_point; - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (!valid_index(index)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Satellite satellite = _pparam->_vector.at(index); - if (!_pparam->_last_pointwise) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (!satellite.active || satellite.hidden) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (pwd2.size() <= index) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - this->knot->show(); - if (_index >= _pparam->_vector.size()) { - tmp_point = satellite.getPosition(pathv.curveAt(index)); - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint(), pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); - double s = satellite.arcDistance(pathv.curveAt(index)); - double t = satellite.time(s, true, curve_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[*curve_prev_index].time(curve_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (curve_in).pointAt(t); - } - } else { - tmp_point = satellite.getPosition(pathv.curveAt(index)); - } - Geom::Point const canvas_point = tmp_point; - return canvas_point; -} - -void FilletChamferKnotHolderEntity::knot_click(guint state) -{ - if (!_pparam->_last_pointwise) { - return; - } - - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).amount = 0.0; - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - } else { - using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).satellite_type; - switch (type) { - case FILLET: - type = INVERSE_FILLET; - break; - case INVERSE_FILLET: - type = CHAMFER; - break; - case CHAMFER: - type = INVERSE_CHAMFER; - break; - default: - type = FILLET; - break; - } - _pparam->_vector.at(index).satellite_type = type; - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - double amount = _pparam->_vector.at(index).amount; - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - if (curve_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*curve_prev_index), pathv.curveAt(index), _pparam->_vector.at(*curve_prev_index)); - } else { - amount = 0.0; - } - } - bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - if (curve_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[*curve_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && - !_pparam->_use_distance - ? true - : false; - } - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount, this, _pparam->_use_distance, - aprox, _pparam->_vector.at(index)); - - } -} - -void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) -{ - if (!_pparam->_last_pointwise) { - return; - } - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - double amount = satellite.amount; - double max_amount = amount; - if (!_pparam->_use_distance && !satellite.is_time) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(index); - boost::optional prev = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - prev = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - prev = sat_curve_time - 1; - } - if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pathv.curveAt(*prev), pathv.curveAt(index)); - } else { - amount = 0.0; - } - if (max_amount > 0 && amount == 0) { - amount = _pparam->_vector.at(index).amount; - } - } - satellite.amount = amount; - _pparam->_vector.at(index) = satellite; - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -} /* 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/satellitearray.h b/src/live_effects/parameter/satellitearray.h deleted file mode 100644 index bb8bf27c8..000000000 --- a/src/live_effects/parameter/satellitearray.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/array.h" -#include "live_effects/effect-enum.h" -#include "helper/geom-pointwise.h" -#include "knot-holder-entity.h" -#include - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferKnotHolderEntity; - -class SatelliteArrayParam : public ArrayParam { -public: - SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, Effect *effect); - - virtual Gtk::Widget *param_newWidget() - { - return NULL; - } - virtual void setHelperSize(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - virtual bool providesKnotHolderEntities() const - { - return true; - } - void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void setUseDistance(bool use_knot_distance); - void setEffectType(EffectType et); - void setPointwise(Pointwise *pointwise); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - - friend class FilletChamferKnotHolderEntity; - friend class LPEFilletChamfer; - -protected: - KnotHolder *knoth; - -private: - SatelliteArrayParam(const SatelliteArrayParam &); - SatelliteArrayParam &operator=(const SatelliteArrayParam &); - - SPKnotShapeType _knot_shape; - SPKnotModeType _knot_mode; - guint32 _knot_color; - Geom::PathVector _hp; - int _helper_size; - bool _use_distance; - EffectType _effectType; - Pointwise *_last_pointwise; - -}; - -class FilletChamferKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() - { - _pparam->knoth = NULL; - } - - 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); - void knot_set_offset(Satellite); - /** Checks whether the index falls within the size of the parameter's vector - */ - bool valid_index(size_t index) const - { - return (_pparam->_vector.size() > index); - } - ; - -private: - SatelliteArrayParam *_pparam; - size_t _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp new file mode 100644 index 000000000..9274a4aff --- /dev/null +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -0,0 +1,527 @@ +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" +#include "live_effects/parameter/satellitesarray.h" +#include "live_effects/effect.h" +#include "sp-lpe-item.h" +#include +#include +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + +namespace Inkscape { + +namespace LivePathEffect { + +SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) +{ + _knot_shape = SP_KNOT_SHAPE_DIAMOND; + _knot_mode = SP_KNOT_MODE_XOR; + _knot_color = 0xAAFF8800; + _helper_size = 0; + _use_distance = false; + _effectType = FILLET_CHAMFER; + _last_pointwise = NULL; +} + +void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + _knot_shape = shape; + _knot_mode = mode; + _knot_color = color; +} + +void SatellitesArrayParam::setPointwise(Pointwise *pointwise) +{ + _last_pointwise = pointwise; + param_set_and_write_new_value(_last_pointwise->getSatellites()); +} + +void SatellitesArrayParam::setUseDistance(bool use_knot_distance) +{ + _use_distance = use_knot_distance; +} + +void SatellitesArrayParam::setEffectType(EffectType et) +{ + _effectType = et; +} + +void SatellitesArrayParam::setHelperSize(int hs) +{ + _helper_size = hs; + updateCanvasIndicators(); +} + +void SatellitesArrayParam::updateCanvasIndicators(bool mirror) +{ + if (!_last_pointwise) { + return; + } + Geom::PathVector pathv = _last_pointwise->getPV(); + if (mirror == true) { + _hp.clear(); + } + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!_vector[i][j].active || _vector[i][j].hidden) { + continue; + } + if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { + continue; + } + double pos = 0; + if (pathv.size() <= i || pathv[i].size() <= j) { + break; + } + Geom::Curve *curve_in = pathv[i][j].duplicate(); + bool overflow = false; + double size_out = _vector[i][j].arcDistance(*curve_in); + double lenght_out = curve_in->length(); + double lenght_in = 0; + + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[pathv[i].size() - 1]; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } + if (curve_prev_index) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); + } + if (mirror == true) { + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; + } + } + } else { + pos = _vector[i][j].time(*curve_in); + if (lenght_in < size_out) { + overflow = true; + } + } + if (pos <= 0 || pos >= 1) { + continue; + } + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { + diameter = 15; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; + _hp.push_back(pathv[0]); + } else { + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + } + } + } + } + if (mirror == true) { + updateCanvasIndicators(false); + } +} +void SatellitesArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); +} + +void SatellitesArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(_hp); +} + +void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!_vector[i][j].is_time && _vector[i][j].amount > 0) { + _vector[i][j].amount = _vector[i][j].amount * + ((postmul.expansionX() + postmul.expansionY()) / 2); + } + } + } + param_set_and_write_new_value(_vector); + } +} + +void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, bool mirror) +{ + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + size_t iPlus = j; + if (mirror == true) { + iPlus = j + _vector[i].size(); + } + if (!_vector[i][j].active) { + continue; + } + if (!_vector[i][j].has_mirror && mirror == true) { + continue; + } + using namespace Geom; + SatelliteType type = _vector[i][j].satellite_type; + //IF is for filletChamfer effect... + if (_effectType == FILLET_CHAMFER) { + const gchar *tip; + if (type == CHAMFER) { + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_CHAMFER) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_FILLET) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, i, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + _knot_shape, _knot_mode, _knot_color); + knotholder->add(e); + } + } + } + if (mirror == true) { + addKnotHolderEntities(knotholder, desktop, item, false); + } +} + +void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); +} + +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( + SatellitesArrayParam *p, size_t index, size_t subindex) + : _pparam(p), _index(index), _subindex(subindex) {} + +void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, + Geom::Point const &/*origin*/, + guint state) +{ + Geom::Point s = snap_knot_position(p, state); + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (!valid_index(subindex)) { + return; + } + + if (!_pparam->_last_pointwise) { + return; + } + + Satellite satellite = _pparam->_vector[_index].at(subindex); + if (!satellite.active || satellite.hidden) { + return; + } + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + if (_subindex >= _pparam->_vector[_index].size() ) { + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + Satellites sats = pointwise->getSatellites(); + time_start = sats[_index][*curve_prev_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; + } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv[_index][); + } + satellite.amount = amount; + } + } else { + satellite.setPosition(s, pathv[_index]); + } + _pparam->_vector[_index][_subindex] = satellite; + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +Geom::Point FilletChamferKnotHolderEntity::knot_get() const +{ + Geom::Point tmp_point; + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (!valid_index(_subindex)) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + Satellite satellite = _pparam->_vector[_index][_subindex]; + if (!_pparam->_last_pointwise) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (!satellite.active || satellite.hidden) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + if (pathv[_index].size() <= subindex) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + this->knot->show(); + if (_subindex >= _pparam->_vector[index].size()) { + tmp_point = satellite.getPosition(pathv[_index][_subindex]); + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; + double s = satellite.arcDistance(pathv[_index][_subindex]); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; + } + double time_start = 0; + time_start = pointwise->getSatellites()[_index][*curve_prev_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); + } + } else { + tmp_point = satellite.getPosition(pathv[_index][_subindex]); + } + Geom::Point const canvas_point = tmp_point; + return canvas_point; +} + +void FilletChamferKnotHolderEntity::knot_click(guint state) +{ + if (!_pparam->_last_pointwise) { + return; + } + + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector[_index][_subindex].amount = 0.0; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + } else { + using namespace Geom; + SatelliteType type = _pparam->_vector[_index][_subindex].satellite_type; + switch (type) { + case FILLET: + type = INVERSE_FILLET; + break; + case INVERSE_FILLET: + type = CHAMFER; + break; + case CHAMFER: + type = INVERSE_CHAMFER; + break; + default: + type = FILLET; + break; + } + _pparam->_vector[_index][subindex].satellite_type = type; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == CHAMFER) { + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_CHAMFER) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_FILLET) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + double amount = _pparam->_vector[_index][_subindex].amount; + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { + if (curve_prev_index) { + amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex], _pparam->_vector[_index][*curve_prev_index]); + } else { + amount = 0.0; + } + } + bool aprox = false; + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[_index][subindex]; + if (curve_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[_index][*curve_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, amount, this, _pparam->_use_distance, + aprox, _pparam->_vector[_index][subindex]); + + } +} + +void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) +{ + if (!_pparam->_last_pointwise) { + return; + } + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + double amount = satellite.amount; + double max_amount = amount; + if (!_pparam->_use_distance && !satellite.is_time) { + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(index); + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*prev], pathv[_index][subindex]); + } else { + amount = 0.0; + } + if (max_amount > 0 && amount == 0) { + amount = _pparam->_vector[_index][subindex].amount; + } + } + satellite.amount = amount; + _pparam->_vector[_index][subindex] = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +} /* 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/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h new file mode 100644 index 000000000..db3776ba3 --- /dev/null +++ b/src/live_effects/parameter/satellitesarray.h @@ -0,0 +1,115 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" +#include "helper/geom-pointwise.h" +#include "knot-holder-entity.h" +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class FilletChamferKnotHolderEntity; + +class SatellitesArrayParam : public ArrayArrayParam { +public: + SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect); + + virtual Gtk::Widget *param_newWidget() + { + return NULL; + } + virtual void setHelperSize(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, + std::vector &hp_vec); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + virtual bool providesKnotHolderEntities() const + { + return true; + } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); + void setUseDistance(bool use_knot_distance); + void setEffectType(EffectType et); + void setPointwise(Pointwise *pointwise); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + + friend class FilletChamferKnotHolderEntity; + friend class LPEFilletChamfer; + +protected: + KnotHolder *knoth; + +private: + SatellitesArrayParam(const SatellitesArrayParam &); + SatellitesArrayParam &operator=(const SatellitesArrayParam &); + + SPKnotShapeType _knot_shape; + SPKnotModeType _knot_mode; + guint32 _knot_color; + Geom::PathVector _hp; + int _helper_size; + bool _use_distance; + EffectType _effectType; + Pointwise *_last_pointwise; + +}; + +class FilletChamferKnotHolderEntity : public KnotHolderEntity { +public: + FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index, size_t subindex); + virtual ~FilletChamferKnotHolderEntity() + { + _pparam->knoth = NULL; + } + + 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); + void knot_set_offset(Satellite); + /** Checks whether the index falls within the size of the parameter's vector + */ + bool valid_index(size_t index) const + { + return (_pparam->_vector.size() > index); + } + ; + +private: + SatellitesArrayParam *_pparam; + size_t _index; + size_t _subindex; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 07717a370b8efe6ddbb0c69d115bb063a2e7686a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 10 May 2016 23:16:49 +0200 Subject: Working with path updates (bzr r13645.1.130) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 248 ++++++++++---------- src/live_effects/parameter/array.cpp | 41 ++-- src/live_effects/parameter/array.h | 9 +- src/live_effects/parameter/satellitesarray.cpp | 310 +++++++++++++------------ src/live_effects/parameter/satellitesarray.h | 2 +- 6 files changed, 303 insertions(+), 311 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index a1aa811a9..64364c88c 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -65,7 +65,7 @@ set(live_effects_SRC parameter/path.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/satellitearray.cpp + parameter/satellitesarray.cpp parameter/random.cpp parameter/text.cpp parameter/togglebutton.cpp @@ -145,7 +145,7 @@ set(live_effects_SRC parameter/path.h parameter/point.h parameter/powerstrokepointarray.h - parameter/satellitearray.h + parameter/satellitesarray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index bcab1c055..ab1cf41e3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -97,29 +97,32 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) continue; } std::vector subpath_satellites; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - bool start = true; - while (curve_it1 != curve_endit) { - bool hidden = false; - if (start) { - if (!path_it->closed()) { - hidden = true; - } - start = false; - } + for (Geom::Path::const_iterator curve_it = path_it->begin(); curve_it != path_it->end(); ++curve_it) { + //Maybe we want this satellites... + //if (curve_it->isDegenerate()) { + // continue + //} + Satellite satellite(FILLET); + satellite.setSteps(chamfer_steps); + subpath_satellites.push_back(satellite); + } + //we add the last satellite on open path because pointwise is related to nodes, not curves + //so maybe in the future we can need this last satellite in other effects + //dont remove for this effect because pointwise class has methods when the path is modiffied + //and we want one method for all uses + if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setHidden(hidden); satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); - ++curve_it1; } satellites.push_back(subpath_satellites); } pointwise = new Pointwise(); + //Why Pwd2? Could we switch all to pathvector instead? + //I usualy use a pathvector, except some curve operations with D2 + //if yes maybe "poinwise" need a rename pointwise->setPwd2(paths_to_pw(pathv)); pointwise->setSatellites(satellites); - //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -261,29 +264,33 @@ void LPEFilletChamfer::updateAmount() for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional curve_prev_index = boost::none; if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[pathv[i].size() - 1]; + curve_prev_index = pathv[i].size() - 1; } else if(!pathv[i].closed() || j != 0) { curve_prev_index = j - 1; } - if (!pathv[i].closed() && sat_curve_time == 0) { - it->amount = 0; + if (!pathv[i].closed() && j == 0) { + satellites[i][j].amount = 0; + continue; + } + if (pathv[i].size() == j) { continue; } - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + + Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { if(curve_prev_index) { - it->amount = it->radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); } else { - it->amount = 0.0; + satellites[i][j].amount = 0.0; } } else { - it->amount = power; + satellites[i][j].amount = power; } } } @@ -294,22 +301,22 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); + Satellites satellites = pointwise->getSatellites(); Geom::PathVector pathv = pointwise->getPV(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j]->amount == 0) || - (!apply_with_radius && satellites[i][j]->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } if (only_selected) { Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point)) { - satellites[i][j]->steps = chamfer_steps; + satellites[i][j].steps = chamfer_steps; } } else { - satellites[i][j]->steps = chamfer_steps; + satellites[i][j].steps = chamfer_steps; } } } @@ -319,22 +326,28 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); + Satellites satellites = pointwise->getSatellites(); Geom::PathVector pathv = pointwise->getPV(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j]->amount == 0) || - (!apply_with_radius && satellites[i][j]->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } + if (pathv[i].size() == j) { + if (!only_selected) { + satellites[i][j].satellite_type = satellitetype; + } + continue; + } if (only_selected) { Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point)) { - satellites[i][j]->satellite_type = satellitetype; + satellites[i][j].satellite_type = satellitetype; } } else { - satellites[i][j]->satellite_type = satellitetype; + satellites[i][j].satellite_type = satellitetype; } } } @@ -361,44 +374,47 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2 = paths_to_pw(pathv); - pwd2 = remove_short_cuts(pwd2, 0.01); - Satellites satelites = satellites_param.data(); - if(satelites.empty()) { + Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(pathv), 0.01);; + Satellites satellites = satellites_param.data(); + if(satellites.empty()) { doOnApply(lpeItem); - satelites = satellites_param.data(); + satellites = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } - size_t number_curves = pathv.curveCount(); + size_t number_nodes = pathv.nodes().size(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j]->is_time != flexible) { - satellites[i][j]->is_time = flexible; - double amount = satellites[i][j]->amount; + if (satellites[i][j].is_time != flexible) { + satellites[i][j].is_time = flexible; + double amount = satellites[i][j].amount; + if (pathv[i].size() == j){ + continue; + } Geom::Curve const &curve_in = pathv[i][j]; - if (satellites[i][j]->is_time) { + if (satellites[i][j].is_time) { double time = timeAtArcLength(amount, curve_in); - satellites[i][j]->amount = time; + satellites[i][j].amount = time; } else { double size = arcLengthAt(amount, curve_in); - satellites[i][j]->amount = size; + satellites[i][j].amount = size; } } - if (satellites[i][j]->has_mirror != mirror_knots) { - satellites[i][j]->has_mirror = mirror_knots; + if (satellites[i][j].has_mirror != mirror_knots) { + satellites[i][j].has_mirror = mirror_knots; } - satellites[i][j]->hidden = hide_knots; + satellites[i][j].hidden = hide_knots; } } //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector - if (pointwise && number_curves != pointwise->getTotalSatellites()) { + if (pointwise && number_nodes != pointwise->getTotalSatellites()) { + std::cout << "gasdfgffffffffffffffffffffffffffffffffffffffffffffffffff\n"; Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(satellites[0][0].has_mirror); @@ -408,7 +424,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); } - pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); } else { @@ -427,86 +442,63 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; Geom::PathVector path_out; - size_t counter_paths = 0; + size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { + Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } _hp.push_back(*path_it); Geom::Path tmp_path; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->size() == 1) { - counter++; - tmp_path.start((*curve_it1).pointAt(0)); - tmp_path.append(*curve_it1); + path++; + tmp_path.start(path_it[0].pointAt(0)); + tmp_path.append(path_it[0]); path_out.push_back(tmp_path); continue; } - size_t counter_curves = 0; - size_t first = counter; double time0 = 0; - Satellites satelites = pointwise->getSatellites(); - while (curve_it1 != curve_endit) { - if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { - ++curve_it2; - } - if ((*curve_it1).isDegenerate()) { - ++curve_it1; - counter_curves++; - time0 = 0.0; - continue; - } - Satellite satellite; - Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); - if (!path_it->closed()) { - if (curve_it2 != curve_endit) { - curve_it2_fixed = (*curve_it2).duplicate(); - if (satellites[counter_paths].size() > counter_curves + 1) { - satellite = satellites[counter_paths][counter_curves + 1]; - } - } else { - if (time0 != 1) { - Geom::Curve *last_curve = curve_it1->portion(time0, 1); - last_curve->setInitial(tmp_path.finalPoint()); - tmp_path.append(*last_curve); - } - ++curve_it1; - counter_curves++; - continue; - } - } else { - if (curve_it2 != curve_endit) { - curve_it2_fixed = (*curve_it2).duplicate(); - if (satellites[counter_paths].size() > counter_curves + 1) { - satellite = satellites[counter_paths][counter_curves + 1];; - } - - } else { - if (satellites[counter_paths].size() > 0) { - satellite = satellites[counter_paths][0]; - } + size_t curve = 0; + Satellites satellites = pointwise->getSatellites(); + for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { + boost::optional curve_next_index = boost::none; + if (curve == pathv[path].size() - 1 && pathv[path].closed()) { + curve_next_index = 0; + } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { + curve_next_index = curve + 1; + } + if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path + if (time0 != 1) { //Previous satellite not at 100% amount + Geom::Curve *last_curve = curve_it1->portion(time0, 1); + last_curve->setInitial(tmp_path.finalPoint()); + tmp_path.append(*last_curve); + delete last_curve; } + continue; } - if (counter_curves == 0) { - if (satellites[counter_paths].size() > 0 && satellites[counter_paths][0].active) { - time0 = satellites[counter_paths][0].time(*path_it->begin()); - } else { + Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; +// if (curve != pathv[path].size() && (*curve_it2).isDegenerate()) { +// ++curve_it2; +// } +// if ((*curve_it1).isDegenerate()) { +// ++curve_it1; +// counter_curves++; +// time0 = 0.0; +// continue; +// } + Satellite satellite = satellites[path][*curve_next_index]; + if (!curve) { //curve == 0 + if (!path_it->closed()) { time0 = 0; + } else { + time0 = satellites[path][0].time(*curve_it1); } } - Geom::Curve const &curve_it2_fixed_ref = *curve_it2_fixed; - bool last = curve_it2 == curve_endit; - double s = satellite.arcDistance(curve_it2_fixed_ref); + bool last = pathv[path].size() - 1 == curve; + double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); - double time2 = satellite.time(curve_it2_fixed_ref); - if (!satellite.active) { - time1 = 1; - time2 = 0; - } + double time2 = satellite.time(curve_it2); if (time1 <= time0) { time1 = time0; @@ -519,22 +511,22 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) times.push_back(time1); times.push_back(time2); Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); - if (counter_curves > 0) { + if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); + Geom::Point end_arc_point = curve_it2.pointAt(times[2]); if (times[2] == 1) { - end_arc_point = curve_it2_fixed_ref.pointAt(times[2] - GAP_HELPER); + end_arc_point = curve_it2.pointAt(times[2] - GAP_HELPER); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); } double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2_fixed_ref.initialPoint()) * K; + double k2 = distance(end_arc_point, curve_it2.initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); @@ -545,10 +537,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2_fixed_ref.portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2_fixed_ref.initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } @@ -571,7 +563,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { - end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); + end_arc_point = curve_it2.pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); @@ -599,7 +591,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, @@ -618,7 +610,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -635,7 +627,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -645,7 +637,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, @@ -663,14 +655,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (path_it->closed() && last) { tmp_path.close(); } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter_curves++; + curve++; time0 = times[2]; } - counter_paths++; + path++; path_out.push_back(tmp_path); } return path_out; diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 0bbe39293..c9e2d6563 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -15,35 +15,36 @@ namespace LivePathEffect { //TODO: move maybe unsigned int -sp_svg_satellite_vector_read_d(gchar const *str, std::vector *satellites){ +sp_svg_satellite_vector_read_d(gchar const *str, std::vector *subpath_satellites){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, "@", 0); - for (size_t i = 0; i < strarray.size(); ++i) { - gchar ** strsubarray = g_strsplit(strarray[i], ",", 7); + gchar ** strarray = g_strsplit(str, " @ ", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + gchar ** strsubarray = g_strsplit(*iter, ",", 7); if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ - Satellite sat; - sat->setSatelliteType(g_strstrip(strsubarray[0])); - sat->is_time = strncmp(strsubarray[1],"1",1) == 0; - sat->has_mirror = strncmp(strsubarray[2],"1",1) == 0; - sat->hidden = strncmp(strsubarray[3],"1",1) == 0; + Satellite satellite; + satellite.setSatelliteType(g_strstrip(strsubarray[0])); + satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; double amount,angle; float stepsTmp; sp_svg_number_read_d(strsubarray[4], &amount); sp_svg_number_read_d(strsubarray[5], &angle); sp_svg_number_read_f(strsubarray[6], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - sat->amount = amount; - sat->angle = angle; - sat->steps = steps; + satellite.amount = amount; + satellite.angle = angle; + satellite.steps = steps; + subpath_satellites->push_back(satellite); g_strfreev (strsubarray); - satellites.push_back(sat); } - g_strfreev (strsubarray); + iter++; } g_strfreev (strarray); - if (!sat.empty()){ + if (!subpath_satellites->empty()){ return 1; } return 0; @@ -88,12 +89,12 @@ template <> std::vector ArrayParam >::readsvg(const gchar * str) { - std::vector satellites; - if (sp_svg_satellite_vector_read_d(str, &satellites)) { - return satellites; + std::vector subpath_satellites; + if (sp_svg_satellite_vector_read_d(str, &subpath_satellites)) { + return subpath_satellites; } - satellites.push_back(Satellite satellite(FILLET)); - return satellites; + subpath_satellites.push_back(Satellite(FILLET)); + return subpath_satellites; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 7076a465f..64d01650c 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -51,7 +51,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) { _vector.clear(); - gchar ** strarray = g_strsplit(strvalue, "|", 0); + gchar ** strarray = g_strsplit(strvalue, " | ", 0); gchar ** iter = strarray; while (*iter != NULL) { _vector.push_back( readsvg(*iter) ); @@ -112,6 +112,10 @@ protected: void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { for (size_t i = 0; i < nVector.size(); ++i) { + if (i != 0) { + // separate items with @ symbol ¿Any other? + str << " @ "; + } str << nVector[i].getSatelliteTypeGchar(); str << ","; str << nVector[i].is_time; @@ -125,9 +129,6 @@ protected: str << nVector[i].angle; str << ","; str << nVector[i].steps; - if (i != nVector.size()-1) { - str << "@"; - } } } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 9274a4aff..9f14a1d5b 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -26,7 +26,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -77,104 +77,106 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (mirror == true) { _hp.clear(); } - for (size_t i = 0; i < _vector.size(); ++i) { - for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!_vector[i][j].active || _vector[i][j].hidden) { - continue; - } - if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { - continue; - } - double pos = 0; - if (pathv.size() <= i || pathv[i].size() <= j) { - break; - } - Geom::Curve *curve_in = pathv[i][j].duplicate(); - bool overflow = false; - double size_out = _vector[i][j].arcDistance(*curve_in); - double lenght_out = curve_in->length(); - double lenght_in = 0; - - boost::optional curve_prev_index = boost::none; - if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[pathv[i].size() - 1]; - } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); - } - if (mirror == true) { + if (_effectType == FILLET_CHAMFER) { + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if ( _vector[i][j].hidden) { + continue; + } + if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { + continue; + } + double pos = 0; + if (pathv[i].size() == j) { //ignore last satellite in open paths with fillet chamfer effect + continue; + } + Geom::Curve *curve_in = pathv[i][j].duplicate(); + bool overflow = false; + double size_out = _vector[i][j].arcDistance(*curve_in); + double lenght_out = curve_in->length(); + double lenght_in = 0; + + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[i].size() - 1; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i][j].time(size_out, true, *curve_in); - if (lenght_out < size_out) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); + } + if (mirror) { + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; + } + } + } else { + pos = _vector[i][j].time(*curve_in); + if (lenght_in < size_out) { overflow = true; } } - } else { - pos = _vector[i][j].time(*curve_in); - if (lenght_in < size_out) { - overflow = true; + if (pos <= 0 || pos >= 1) { + continue; } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point point_a = curve_in->pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - deriv_a = deriv_a * rot; - Geom::Point point_c = point_a - deriv_a * _helper_size; - Geom::Point point_d = point_a + deriv_a * _helper_size; - Geom::Ray ray_1(point_c, point_d); - char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - _hp.push_back(pathv[1]); - if (overflow) { - double diameter = _helper_size; - if (_helper_size == 0) { - diameter = 15; - char const *svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " - "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(diameter); - aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); - pathv *= aff; - _hp.push_back(pathv[0]); + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size); + if (mirror) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - char const *svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " - "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " - "0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size / 2.0); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { + diameter = 15; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; + _hp.push_back(pathv[0]); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); } } } } - if (mirror == true) { + if (mirror) { updateCanvasIndicators(false); } } @@ -198,8 +200,7 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!_vector[i][j].is_time && _vector[i][j].amount > 0) { - _vector[i][j].amount = _vector[i][j].amount * - ((postmul.expansionX() + postmul.expansionY()) / 2); + _vector[i][j].amount = _vector[i][j].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } } } @@ -208,24 +209,22 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, bool mirror) + SPDesktop *desktop, + SPItem *item, bool mirror) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - size_t iPlus = j; - if (mirror == true) { - iPlus = j + _vector[i].size(); - } - if (!_vector[i][j].active) { + if (!_vector[i][j].has_mirror && mirror) { continue; } - if (!_vector[i][j].has_mirror && mirror == true) { - continue; + SatelliteType type = _vector[i][j].satellite_type; + size_t index = i; + size_t subindex = j; + if (mirror) { + subindex = subindex + _vector[i].size(); } using namespace Geom; - SatelliteType type = _vector[i][j].satellite_type; - //IF is for filletChamfer effect... + //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { const gchar *tip; if (type == CHAMFER) { @@ -245,15 +244,13 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, i, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - _knot_shape, _knot_mode, _knot_color); + FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index, subindex); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } } } - if (mirror == true) { + if (mirror) { addKnotHolderEntities(knotholder, desktop, item, false); } } @@ -279,7 +276,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(subindex)) { + if (!valid_index(_index)) { return; } @@ -287,39 +284,39 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } - Satellite satellite = _pparam->_vector[_index].at(subindex); - if (!satellite.active || satellite.hidden) { + Satellite satellite = _pparam->_vector[_index][subindex]; + if (satellite.hidden) { return; } Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - if (_subindex >= _pparam->_vector[_index].size() ) { + Geom::PathVector pathv = pointwise->getPV(); + if (subindex != _subindex) { boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites sats = pointwise->getSatellites(); - time_start = sats[_index][*curve_prev_index].time(curve_in); + Satellites satellites = pointwise->getSatellites(); + time_start = satellites[_index][*curve_prev_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; } double size = arcLengthAt(mirror_time, curve_in); double amount = curve_in.length() - size; if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][); + amount = timeAtArcLength(amount, pathv[_index][subindex]); } satellite.amount = amount; } } else { - satellite.setPosition(s, pathv[_index]); + satellite.setPosition(s, pathv[_index][subindex]); } - _pparam->_vector[_index][_subindex] = satellite; + _pparam->_vector[_index][subindex] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -333,33 +330,41 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_subindex)) { + if (!valid_index(_index)) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - Satellite satellite = _pparam->_vector[_index][_subindex]; - if (!_pparam->_last_pointwise) { + Satellite satellite = _pparam->_vector[_index][subindex]; + Pointwise *pointwise = _pparam->_last_pointwise; + if (!pointwise) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - if (!satellite.active || satellite.hidden) { + Geom::PathVector pathv = pointwise->getPV(); + if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it + _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - if (pathv[_index].size() <= subindex) { + if (!pathv[_index].closed() && subindex == 0){ //Path is open hide first satellite + _pparam->_vector[_index][subindex].hidden = true; + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (satellite.hidden) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (subindex != _subindex && !_pparam->_vector[_index][subindex].has_mirror) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); - if (_subindex >= _pparam->_vector[index].size()) { - tmp_point = satellite.getPosition(pathv[_index][_subindex]); + if (subindex != _subindex) { + tmp_point = satellite.getPosition(pathv[_index][subindex]); boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double s = satellite.arcDistance(pathv[_index][_subindex]); + double s = satellite.arcDistance(pathv[_index][subindex]); double t = satellite.time(s, true, curve_in); if (t > 1) { t = 1; @@ -375,7 +380,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const tmp_point = (curve_in).pointAt(t); } } else { - tmp_point = satellite.getPosition(pathv[_index][_subindex]); + tmp_point = satellite.getPosition(pathv[_index][subindex]); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -386,19 +391,18 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_last_pointwise) { return; } - size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector[_index][_subindex].amount = 0.0; + _pparam->_vector[_index][subindex].amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector[_index][_subindex].satellite_type; + SatelliteType type = _pparam->_vector[_index][subindex].satellite_type; switch (type) { case FILLET: type = INVERSE_FILLET; @@ -438,13 +442,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - double amount = _pparam->_vector[_index][_subindex].amount; + Geom::PathVector pathv = _pparam->_last_pointwise->getPV(); + double amount = _pparam->_vector[_index][subindex].amount; boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { if (curve_prev_index) { @@ -454,10 +458,9 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[_index][subindex]; + Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); if (curve_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[_index][*curve_prev_index]; + Geom::D2 d2_in = pathv[_index][*curve_prev_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -483,17 +486,16 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(index); + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pointwise->getPV(); boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*prev], pathv[_index][subindex]); + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex]); } else { amount = 0.0; } diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index db3776ba3..9a9ec4a88 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitesArrayParam : public ArrayArrayParam { +class SatellitesArrayParam : public ArrayParam > { public: SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, -- cgit v1.2.3 From b03cc6d03c9cfa57ebee8c70412e96c5d92f4f83 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 May 2016 22:27:45 +0200 Subject: pre-remove of subpath update satellites (bzr r13645.1.132) --- src/live_effects/lpe-fillet-chamfer.cpp | 28 ++++++++++++-------------- src/live_effects/parameter/satellitesarray.cpp | 1 + 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ab1cf41e3..7379efcf6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -410,22 +410,21 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } //if are diferent sizes call to poinwise recalculate - //todo: fire a reverse satellites on reverse path. Maybe a new method - //like "are_similar" to avoid precission issues on reverse a pointwise - //and after convert to Pathvector + //TODO: Update the satellite data in paths modified, Goal 0.93 if (pointwise && number_nodes != pointwise->getTotalSatellites()) { - std::cout << "gasdfgffffffffffffffffffffffffffffffffffffffffffffffffff\n"; + pointwise->setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(satellites[0][0].has_mirror); pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); + satellites_param.setPointwise(pointwise); } else { pointwise = new Pointwise(); pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); + satellites_param.setPointwise(pointwise); + refreshKnots(); } - satellites_param.setPointwise(pointwise); - refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -477,16 +476,15 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } continue; } + if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { + curve_next_index = *curve_next_index + 1; + } Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; -// if (curve != pathv[path].size() && (*curve_it2).isDegenerate()) { -// ++curve_it2; -// } -// if ((*curve_it1).isDegenerate()) { -// ++curve_it1; -// counter_curves++; -// time0 = 0.0; -// continue; -// } + if ((*curve_it1).isDegenerate()) { + curve++; + time0 = 0.0; + continue; + } Satellite satellite = satellites[path][*curve_next_index]; if (!curve) { //curve == 0 if (!path_it->closed()) { diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 9f14a1d5b..8e6ba0b41 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -339,6 +339,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::PathVector pathv = pointwise->getPV(); + if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); -- cgit v1.2.3 From c103f187da67d1e2a9d31f45248a415945b1e5c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 May 2016 22:09:34 +0200 Subject: Fiximg pointwise (bzr r13645.1.133) --- src/live_effects/lpe-fillet-chamfer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7379efcf6..6ecffb388 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -360,6 +360,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(!_hp.empty()) { _hp.clear(); } + std::cout << "1\n"; SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -368,6 +369,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (path) { c = path->get_original_curve(); } + std::cout << "2\n"; //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); //mandatory call @@ -409,9 +411,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } + std::cout << "3\n"; //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 if (pointwise && number_nodes != pointwise->getTotalSatellites()) { + std::cout << "4\n"; pointwise->setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); @@ -419,12 +423,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); satellites_param.setPointwise(pointwise); } else { + std::cout << "5\n"; pointwise = new Pointwise(); pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); satellites_param.setPointwise(pointwise); refreshKnots(); } + std::cout << "6\n"; } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -443,8 +449,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + std::cout << "7\n"; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { + std::cout << "8\n"; if (path_it->empty()) { continue; } @@ -467,6 +475,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { curve_next_index = curve + 1; } + std::cout << *curve_next_index << "\n"; if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); @@ -479,6 +488,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { curve_next_index = *curve_next_index + 1; } + std::cout << *curve_next_index << "\n"; + std::cout << pathv[path].size() << "pathv[path].size()\n"; + std::cout << path << "\n"; + std::cout << satellites.size() << "\n"; + std::cout << satellites[path].size() << "\n"; Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; if ((*curve_it1).isDegenerate()) { curve++; -- cgit v1.2.3 From 4c145e43f8ab8d8040fb2fa42309f7bd400f6349 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 May 2016 23:52:45 +0200 Subject: Fixing pointwise (bzr r13645.1.135) --- src/live_effects/lpe-fillet-chamfer.cpp | 95 ++++------ src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/array.cpp | 68 +++----- src/live_effects/parameter/array.h | 2 +- src/live_effects/parameter/satellitesarray.cpp | 231 ++++++++++++------------- src/live_effects/parameter/satellitesarray.h | 8 +- 6 files changed, 170 insertions(+), 236 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ecffb388..f8f17fccf 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -54,8 +54,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL) + _("Helper size with direction"), "helper_size", &wr, this, 0) { registerParameter(&satellites_param); registerParameter(&method); @@ -82,7 +81,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); //helper_size.param_overwrite_widget(true); - } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -117,12 +115,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pointwise = new Pointwise(); - //Why Pwd2? Could we switch all to pathvector instead? - //I usualy use a pathvector, except some curve operations with D2 - //if yes maybe "poinwise" need a rename - pointwise->setPwd2(paths_to_pw(pathv)); - pointwise->setSatellites(satellites); + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -258,15 +252,15 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - boost::optional curve_prev_index = boost::none; + boost::optional previous_index = boost::none; if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[i].size() - 1; + previous_index = pathv[i].size() - 1; } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; + previous_index = j - 1; } if (!pathv[i].closed() && j == 0) { satellites[i][j].amount = 0; @@ -284,8 +278,8 @@ void LPEFilletChamfer::updateAmount() Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { - if(curve_prev_index) { - satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + if(previous_index) { + satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*previous_index], pathv[i][j]); } else { satellites[i][j].amount = 0.0; } @@ -295,14 +289,14 @@ void LPEFilletChamfer::updateAmount() } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -320,14 +314,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -351,16 +345,12 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - if(!_hp.empty()) { - _hp.clear(); - } - std::cout << "1\n"; SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -369,14 +359,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (path) { c = path->get_original_curve(); } - std::cout << "2\n"; //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(pathv), 0.01);; Satellites satellites = satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); @@ -411,26 +399,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - std::cout << "3\n"; //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - if (pointwise && number_nodes != pointwise->getTotalSatellites()) { - std::cout << "4\n"; - pointwise->setSatellites(satellites); + size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 && number_nodes != satellites_counter) { + pointwise.setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); - satellite.setHasMirror(satellites[0][0].has_mirror); - pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pointwise.recalculateForNewPathVector(pathv, satellite); satellites_param.setPointwise(pointwise); } else { - std::cout << "5\n"; - pointwise = new Pointwise(); - pointwise->setPwd2(pwd2); - pointwise->setSatellites(satellites); + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); refreshKnots(); } - std::cout << "6\n"; } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -449,10 +434,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::cout << "7\n"; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { - std::cout << "8\n"; if (path_it->empty()) { continue; } @@ -467,39 +450,21 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pointwise->getSatellites(); + Satellites satellites = pointwise.getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { - boost::optional curve_next_index = boost::none; + size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { - curve_next_index = 0; - } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { - curve_next_index = curve + 1; + next_index = 0; } - std::cout << *curve_next_index << "\n"; if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); - delete last_curve; } continue; } - if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { - curve_next_index = *curve_next_index + 1; - } - std::cout << *curve_next_index << "\n"; - std::cout << pathv[path].size() << "pathv[path].size()\n"; - std::cout << path << "\n"; - std::cout << satellites.size() << "\n"; - std::cout << satellites[path].size() << "\n"; - Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; - if ((*curve_it1).isDegenerate()) { - curve++; - time0 = 0.0; - continue; - } - Satellite satellite = satellites[path][*curve_next_index]; + Satellite satellite = satellites[path][next_index]; if (!curve) { //curve == 0 if (!path_it->closed()) { time0 = 0; @@ -508,10 +473,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } bool last = pathv[path].size() - 1 == curve; + Geom::Curve const &curve_it2 = pathv[path][next_index]; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); - if (time1 <= time0) { time1 = time0; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index a209971dd..7603c7de4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - Pointwise *pointwise; + Pointwise pointwise; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c9e2d6563..3d2e7773d 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -13,44 +13,6 @@ namespace Inkscape { namespace LivePathEffect { -//TODO: move maybe -unsigned int -sp_svg_satellite_vector_read_d(gchar const *str, std::vector *subpath_satellites){ - if (!str) { - return 0; - } - gchar ** strarray = g_strsplit(str, " @ ", 0); - gchar ** iter = strarray; - while (*iter != NULL) { - gchar ** strsubarray = g_strsplit(*iter, ",", 7); - if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ - Satellite satellite; - satellite.setSatelliteType(g_strstrip(strsubarray[0])); - satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strsubarray[4], &amount); - sp_svg_number_read_d(strsubarray[5], &angle); - sp_svg_number_read_f(strsubarray[6], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - satellite.amount = amount; - satellite.angle = angle; - satellite.steps = steps; - subpath_satellites->push_back(satellite); - g_strfreev (strsubarray); - } - iter++; - } - g_strfreev (strarray); - if (!subpath_satellites->empty()){ - return 1; - } - return 0; -} - - template <> double ArrayParam::readsvg(const gchar * str) @@ -89,11 +51,35 @@ template <> std::vector ArrayParam >::readsvg(const gchar * str) { - std::vector subpath_satellites; - if (sp_svg_satellite_vector_read_d(str, &subpath_satellites)) { + std::vector subpath_satellites; + if (!str) { return subpath_satellites; } - subpath_satellites.push_back(Satellite(FILLET)); + gchar ** strarray = g_strsplit(str, "@", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + gchar ** strsubarray = g_strsplit(*iter, ",", 7); + if(*strsubarray[6]){ + Satellite satellite; + satellite.setSatelliteType(g_strstrip(strsubarray[0])); + satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strsubarray[4], &amount); + sp_svg_number_read_d(strsubarray[5], &angle); + sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + satellite.amount = amount; + satellite.angle = angle; + satellite.steps = steps; + subpath_satellites.push_back(satellite); + } + g_strfreev (strsubarray); + iter++; + } + g_strfreev (strarray); return subpath_satellites; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 64d01650c..8a9d72fe3 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -51,7 +51,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) { _vector.clear(); - gchar ** strarray = g_strsplit(strvalue, " | ", 0); + gchar ** strarray = g_strsplit(strvalue, "|", 0); gchar ** iter = strarray; while (*iter != NULL) { _vector.push_back( readsvg(*iter) ); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8e6ba0b41..be4eb6732 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -12,7 +12,6 @@ #include "live_effects/effect.h" #include "sp-lpe-item.h" #include -#include // TODO due to internal breakage in glibmm headers, // this has to be included last. #include @@ -34,7 +33,6 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; - _last_pointwise = NULL; } void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, @@ -46,10 +44,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPointwise(Pointwise *pointwise) +void SatellitesArrayParam::setPointwise(Pointwise pointwise) { _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise->getSatellites()); + param_set_and_write_new_value(_last_pointwise.getSatellites()); } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -67,51 +65,51 @@ void SatellitesArrayParam::setHelperSize(int hs) _helper_size = hs; updateCanvasIndicators(); } - +bool SatellitesArrayParam::validData() +{ + return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); +} void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!_last_pointwise) { + if (!validData()) { + return; + } + if(!_hp.empty()) { + _hp.clear(); + } + Geom::PathVector pathv = _last_pointwise.getPathVector(); + if (pathv.empty()) { return; } - Geom::PathVector pathv = _last_pointwise->getPV(); if (mirror == true) { _hp.clear(); } if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if ( _vector[i][j].hidden) { - continue; - } - if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { - continue; - } - double pos = 0; - if (pathv[i].size() == j) { //ignore last satellite in open paths with fillet chamfer effect + if (_vector[i][j].hidden || //Ignore if hidden + (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop + _vector[i][j].amount == 0 || //no helper in 0 value + pathv[i].size() == j || //ignore last satellite in open paths with fillet chamfer effect + !pathv[i].closed() && j == 0) //ignore first satellites on open paths + { continue; } Geom::Curve *curve_in = pathv[i][j].duplicate(); + double pos = 0; bool overflow = false; double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); - double lenght_in = 0; - - boost::optional curve_prev_index = boost::none; + size_t previous_index = j - 1; //Always are previous index because we skip first satellite on open paths if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[i].size() - 1; - } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); + previous_index = pathv[i].size() - 1; } + double lenght_in = pathv.curveAt(previous_index).length(); if (mirror) { - if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i][j].time(size_out, true, *curve_in); - if (lenght_out < size_out) { - overflow = true; - } + curve_in = const_cast(&pathv.curveAt(previous_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; } } else { pos = _vector[i][j].time(*curve_in); @@ -191,8 +189,7 @@ void SatellitesArrayParam::addCanvasIndicators( hp_vec.push_back(_hp); } -void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) +void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, bool /*set*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -212,6 +209,10 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { + if (!validData()) { + return; + } + Geom::PathVector pathv = _last_pointwise.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!_vector[i][j].has_mirror && mirror) { @@ -226,6 +227,9 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { + if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { + continue; + } const gchar *tip; if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " @@ -271,48 +275,41 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { + if (! _pparam->validData() || !valid_index(_index)) { + return; + } Geom::Point s = snap_knot_position(p, state); size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_index)) { - return; - } - - if (!_pparam->_last_pointwise) { - return; - } - Satellite satellite = _pparam->_vector[_index][subindex]; - if (satellite.hidden) { + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { return; } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pointwise->getPV(); if (subindex != _subindex) { - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double mirror_time = Geom::nearest_time(s, curve_in); - double time_start = 0; - Satellites satellites = pointwise->getSatellites(); - time_start = satellites[_index][*curve_prev_index].time(curve_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, curve_in); - double amount = curve_in.length() - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][subindex]); - } - satellite.amount = amount; + Geom::Curve const &curve_in = pathv[_index][previous_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + Satellites satellites = _pparam->_last_pointwise.getSatellites(); + time_start = satellites[_index][previous_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv[_index][subindex]); + } + satellite.amount = amount; } else { satellite.setPosition(s, pathv[_index][subindex]); } @@ -325,61 +322,45 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { + if (! _pparam->validData() || !valid_index(_index)) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Point tmp_point; size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_index)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } Satellite satellite = _pparam->_vector[_index][subindex]; - Pointwise *pointwise = _pparam->_last_pointwise; - if (!pointwise) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Geom::PathVector pathv = pointwise->getPV(); - - if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } - if (!pathv[_index].closed() && subindex == 0){ //Path is open hide first satellite - _pparam->_vector[_index][subindex].hidden = true; - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (satellite.hidden) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (subindex != _subindex && !_pparam->_vector[_index][subindex].has_mirror) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } this->knot->show(); if (subindex != _subindex) { tmp_point = satellite.getPosition(pathv[_index][subindex]); - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double s = satellite.arcDistance(pathv[_index][subindex]); - double t = satellite.time(s, true, curve_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[_index][*curve_prev_index].time(curve_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (curve_in).pointAt(t); + Geom::Curve const &curve_in = pathv[_index][previous_index]; + double s = satellite.arcDistance(pathv[_index][subindex]); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; } + double time_start = 0; + time_start = _pparam->_last_pointwise.getSatellites()[_index][previous_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); } else { tmp_point = satellite.getPosition(pathv[_index][subindex]); } @@ -389,13 +370,19 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - if (!_pparam->_last_pointwise) { + if (! _pparam->validData() || !valid_index(_index)) { return; } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { + return; + } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector[_index][subindex].amount = 0.0; @@ -443,25 +430,22 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Geom::PathVector pathv = _pparam->_last_pointwise->getPV(); double amount = _pparam->_vector[_index][subindex].amount; - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { - if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex], _pparam->_vector[_index][*curve_prev_index]); + if (previous_index) { + amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][previous_index], pathv[_index][subindex], _pparam->_vector[_index][previous_index]); } else { amount = 0.0; } } bool aprox = false; Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); - if (curve_prev_index) { - Geom::D2 d2_in = pathv[_index][*curve_prev_index].toSBasis(); + if (previous_index) { + Geom::D2 d2_in = pathv[_index][previous_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -477,29 +461,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - if (!_pparam->_last_pointwise) { + if (! _pparam->validData() || !valid_index(_index)) { return; } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { + return; + } double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pointwise->getPV(); - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; - } - if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex]); - } else { - amount = 0.0; + previous_index = pathv[_index].size() - 1; } + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][previous_index], pathv[_index][subindex]); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector[_index][subindex].amount; } diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 9a9ec4a88..dcd82ada5 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -56,9 +56,9 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Pointwise *pointwise); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); + void setPointwise(Pointwise pointwise); + bool validData(); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; friend class LPEFilletChamfer; @@ -77,7 +77,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Pointwise *_last_pointwise; + Pointwise _last_pointwise; }; -- cgit v1.2.3 From 159439c26042b7c69aa9c33ce9484e4dfd00372a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 May 2016 11:48:51 +0200 Subject: Fixing pointwise (bzr r13645.1.137) --- src/live_effects/lpe-fillet-chamfer.cpp | 6 ++++- src/live_effects/parameter/array.h | 32 +++++++++++++------------- src/live_effects/parameter/satellitesarray.cpp | 10 ++++++++ src/live_effects/parameter/satellitesarray.h | 5 ++-- 4 files changed, 34 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f8f17fccf..9c633ea57 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -363,6 +363,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); + satellites_param.setPathUpdate(false); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Satellites satellites = satellites_param.data(); @@ -402,8 +403,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 ){ + std::cout << number_nodes << "aaaaa" << pointwise.getTotalSatellites() << "\n"; + } if (satellites_counter != 0 && number_nodes != satellites_counter) { - pointwise.setSatellites(satellites); + satellites_param.setPathUpdate(true); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(mirror_knots); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 8a9d72fe3..9802abc2e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -89,7 +89,7 @@ protected: size_t _default_size; void writesvg(SVGOStringStream &str, std::vector const &vector) const { - for (size_t i = 0; i < vector.size(); ++i) { + for (unsigned int i = 0; i < vector.size(); ++i) { if (i != 0) { // separate items with pipe symbol str << " | "; @@ -98,37 +98,37 @@ protected: } } - void writesvgData(SVGOStringStream &str, float const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, float const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, double const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, double const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, Geom::Point const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, Geom::Point const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { - for (size_t i = 0; i < nVector.size(); ++i) { + void writesvgData(SVGOStringStream &str, std::vector const &vector_data) const { + for (size_t i = 0; i < vector_data.size(); ++i) { if (i != 0) { // separate items with @ symbol ¿Any other? str << " @ "; } - str << nVector[i].getSatelliteTypeGchar(); + str << vector_data[i].getSatelliteTypeGchar(); str << ","; - str << nVector[i].is_time; + str << vector_data[i].is_time; str << ","; - str << nVector[i].has_mirror; + str << vector_data[i].has_mirror; str << ","; - str << nVector[i].hidden; + str << vector_data[i].hidden; str << ","; - str << nVector[i].amount; + str << vector_data[i].amount; str << ","; - str << nVector[i].angle; + str << vector_data[i].angle; str << ","; - str << nVector[i].steps; + str << vector_data[i].steps; } } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index be4eb6732..14660acc4 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -48,6 +48,7 @@ void SatellitesArrayParam::setPointwise(Pointwise pointwise) { _last_pointwise = pointwise; param_set_and_write_new_value(_last_pointwise.getSatellites()); + } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -60,6 +61,11 @@ void SatellitesArrayParam::setEffectType(EffectType et) _effectType = et; } +void SatellitesArrayParam::setPathUpdate(bool path_update) +{ + _path_update = path_update; +} + void SatellitesArrayParam::setHelperSize(int hs) { _helper_size = hs; @@ -67,6 +73,7 @@ void SatellitesArrayParam::setHelperSize(int hs) } bool SatellitesArrayParam::validData() { + if (_path_update) { return false;} return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); } void SatellitesArrayParam::updateCanvasIndicators(bool mirror) @@ -323,6 +330,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { if (! _pparam->validData() || !valid_index(_index)) { + this->knot->hide(); return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Point tmp_point; @@ -336,10 +344,12 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect { + this->knot->hide(); _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); + std::cout << subindex << pathv[_index].size() << "----" << _pparam->_vector[_index].size() << "fgdgsdgsdgsdsdsgd\n"; if (subindex != _subindex) { tmp_point = satellite.getPosition(pathv[_index][subindex]); size_t previous_index = subindex - 1; diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index dcd82ada5..0cebb9cb4 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setPathUpdate(bool path_update); void setEffectType(EffectType et); void setPointwise(Pointwise pointwise); bool validData(); @@ -76,6 +77,7 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; + bool _path_update; EffectType _effectType; Pointwise _last_pointwise; @@ -99,8 +101,7 @@ public: bool valid_index(size_t index) const { return (_pparam->_vector.size() > index); - } - ; + }; private: SatellitesArrayParam *_pparam; -- cgit v1.2.3 From c511141b70995ca7295df4ae244d7cc626f6ab73 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 May 2016 23:06:15 +0200 Subject: Update to refresh knots (bzr r13645.1.139) --- src/live_effects/lpe-fillet-chamfer.cpp | 12 +++++++----- src/live_effects/parameter/array.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 9c633ea57..fc31aa447 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -239,8 +239,11 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); + //Find another way to update knots satellites_param.knoth->update_knots(); do the thing + //but not updat the knot index on node delete + if (tools_isactive(desktop, TOOLS_NODES)) { + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); } } @@ -413,13 +416,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); pointwise.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPointwise(pointwise); } else { pointwise.setPathVector(pathv); pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); - refreshKnots(); } + satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 3d2e7773d..4e3037904 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -60,21 +60,21 @@ ArrayParam >::readsvg(const gchar * str) while (*iter != NULL) { gchar ** strsubarray = g_strsplit(*iter, ",", 7); if(*strsubarray[6]){ - Satellite satellite; - satellite.setSatelliteType(g_strstrip(strsubarray[0])); - satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; + Satellite *satellite = new Satellite(); + satellite->setSatelliteType(g_strstrip(strsubarray[0])); + satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite->has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite->hidden = strncmp(strsubarray[3],"1",1) == 0; double amount,angle; float stepsTmp; sp_svg_number_read_d(strsubarray[4], &amount); sp_svg_number_read_d(strsubarray[5], &angle); sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - satellite.amount = amount; - satellite.angle = angle; - satellite.steps = steps; - subpath_satellites.push_back(satellite); + satellite->amount = amount; + satellite->angle = angle; + satellite->steps = steps; + subpath_satellites.push_back(*satellite); } g_strfreev (strsubarray); iter++; -- cgit v1.2.3 From ff9ec25d3afc0453ead52d3da10b754637c8207f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 May 2016 20:25:20 +0200 Subject: Fixing pointwise (bzr r13645.1.141) --- src/live_effects/lpe-fillet-chamfer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index fc31aa447..a291776b7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,9 @@ #include <2geom/elliptical-arc.h> #include "knotholder.h" #include +#include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: #include - namespace Inkscape { namespace LivePathEffect { @@ -241,6 +241,7 @@ void LPEFilletChamfer::refreshKnots() { //Find another way to update knots satellites_param.knoth->update_knots(); do the thing //but not updat the knot index on node delete + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (tools_isactive(desktop, TOOLS_NODES)) { tools_switch(desktop, TOOLS_SELECT); tools_switch(desktop, TOOLS_NODES); @@ -420,8 +421,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise.setPathVector(pathv); pointwise.setSatellites(satellites); } - satellites_param.setPointwise(pointwise); refreshKnots(); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } -- cgit v1.2.3 From 8d35486a82d04a28dc9f297147ad4666b34cde4a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 19:37:15 +0200 Subject: Fixing pointwise (bzr r13645.1.143) --- src/live_effects/lpe-fillet-chamfer.cpp | 39 +++++++++--------- src/live_effects/parameter/satellitesarray.cpp | 56 +++++++++++++------------- src/live_effects/parameter/satellitesarray.h | 4 +- 3 files changed, 48 insertions(+), 51 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a291776b7..6ec711de7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -367,9 +367,21 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); - satellites_param.setPathUpdate(false); - Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + //if are diferent sizes call to poinwise recalculate + //TODO: Update the satellite data in paths modified, Goal 0.93 + size_t number_nodes = pathv.nodes().size(); + size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 && number_nodes != satellites_counter) { + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pointwise.recalculateForNewPathVector(pathv, satellite); + satellites_param.setPointwise(pointwise); + refreshKnots(); + return; + } Satellites satellites = satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); @@ -380,7 +392,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - size_t number_nodes = pathv.nodes().size(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if (satellites[i][j].is_time != flexible) { @@ -404,25 +415,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - //if are diferent sizes call to poinwise recalculate - //TODO: Update the satellite data in paths modified, Goal 0.93 - size_t satellites_counter = pointwise.getTotalSatellites(); - if (satellites_counter != 0 ){ - std::cout << number_nodes << "aaaaa" << pointwise.getTotalSatellites() << "\n"; - } - if (satellites_counter != 0 && number_nodes != satellites_counter) { - satellites_param.setPathUpdate(true); - Satellite satellite(satellites[0][0].satellite_type); - satellite.setIsTime(satellites[0][0].is_time); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pointwise.recalculateForNewPathVector(pathv, satellite); - } else { - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - } - refreshKnots(); + + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 14660acc4..78f1a945f 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -61,26 +61,25 @@ void SatellitesArrayParam::setEffectType(EffectType et) _effectType = et; } -void SatellitesArrayParam::setPathUpdate(bool path_update) -{ - _path_update = path_update; -} - void SatellitesArrayParam::setHelperSize(int hs) { _helper_size = hs; updateCanvasIndicators(); } -bool SatellitesArrayParam::validData() +bool SatellitesArrayParam::validData(size_t index,size_t subindex) { - if (_path_update) { return false;} - return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); + if(!_last_pointwise.getPathVector().size() > index){ + return false; + } + if(!_last_pointwise.getPathVector()[index].size_closed() > subindex){ + return false; + } + return true; //_last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); } + void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!validData()) { - return; - } + if(!_hp.empty()) { _hp.clear(); } @@ -94,6 +93,9 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!validData(i, j)) { + return; + } if (_vector[i][j].hidden || //Ignore if hidden (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value @@ -216,12 +218,12 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { - if (!validData()) { - return; - } Geom::PathVector pathv = _last_pointwise.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!validData(i, j)) { + return; + } if (!_vector[i][j].has_mirror && mirror) { continue; } @@ -282,14 +284,14 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } Geom::Point s = snap_knot_position(p, state); size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Satellite satellite = _pparam->_vector[_index][subindex]; Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || @@ -329,15 +331,15 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - if (! _pparam->validData() || !valid_index(_index)) { - this->knot->hide(); - return Geom::Point(Geom::infinity(), Geom::infinity()); - } Geom::Point tmp_point; size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + this->knot->hide(); + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Satellite satellite = _pparam->_vector[_index][subindex]; Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || @@ -380,13 +382,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -471,13 +473,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 0cebb9cb4..c6893f595 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,10 +55,9 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); - void setPathUpdate(bool path_update); void setEffectType(EffectType et); void setPointwise(Pointwise pointwise); - bool validData(); + bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; @@ -77,7 +76,6 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; - bool _path_update; EffectType _effectType; Pointwise _last_pointwise; -- cgit v1.2.3 From 634be67d2fa8aa07d25d96e10a3ad24fdfdcc80e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 20:44:19 +0200 Subject: Rename branch (bzr r13645.1.145) --- src/live_effects/lpe-fillet-chamfer.cpp | 48 +++++++++++++------------- src/live_effects/lpe-fillet-chamfer.h | 4 +-- src/live_effects/parameter/satellitesarray.cpp | 28 +++++++-------- src/live_effects/parameter/satellitesarray.h | 8 ++--- 4 files changed, 44 insertions(+), 44 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ec711de7..56f7557ba 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -104,9 +104,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pointwise is related to nodes, not curves + //we add the last satellite on open path because pathVectorSatellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pointwise class has methods when the path is modiffied + //dont remove for this effect because pathVectorSatellites class has methods when the path is modiffied //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); @@ -115,9 +115,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setPathVector(pathv); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -256,8 +256,8 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional previous_index = boost::none; @@ -293,14 +293,14 @@ void LPEFilletChamfer::updateAmount() } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -318,14 +318,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -349,8 +349,8 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -371,14 +371,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pointwise.getTotalSatellites(); + size_t satellites_counter = pathVectorSatellites.getTotalSatellites(); if (satellites_counter != 0 && number_nodes != satellites_counter) { Satellite satellite(FILLET); satellite.setIsTime(flexible); satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); - pointwise.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); + satellites_param.setPathVectorSatellites(pathVectorSatellites); refreshKnots(); return; } @@ -416,9 +416,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setPathVector(pathv); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -454,7 +454,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pointwise.getSatellites(); + Satellites satellites = pathVectorSatellites.getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 7603c7de4..62b894660 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,7 +15,7 @@ #include "live_effects/parameter/enum.h" #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" -#include "helper/geom-pointwise.h" +#include "helper/geom-pathvectorsatellites.h" namespace Inkscape { namespace LivePathEffect { @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - Pointwise pointwise; + PathVectorSatellites pathVectorSatellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 78f1a945f..45a6282e0 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -44,10 +44,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPointwise(Pointwise pointwise) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites) { - _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise.getSatellites()); + _last_pathVectorSatellites = pathVectorSatellites; + param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); } @@ -68,13 +68,13 @@ void SatellitesArrayParam::setHelperSize(int hs) } bool SatellitesArrayParam::validData(size_t index,size_t subindex) { - if(!_last_pointwise.getPathVector().size() > index){ + if(!_last_pathVectorSatellites.getPathVector().size() > index){ return false; } - if(!_last_pointwise.getPathVector()[index].size_closed() > subindex){ + if(!_last_pathVectorSatellites.getPathVector()[index].size_closed() > subindex){ return false; } - return true; //_last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); + return true; //_last_pathVectorSatellites.getPathVector().nodes().size() == _last_pathVectorSatellites.getTotalSatellites(); } void SatellitesArrayParam::updateCanvasIndicators(bool mirror) @@ -83,7 +83,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if(!_hp.empty()) { _hp.clear(); } - Geom::PathVector pathv = _last_pointwise.getPathVector(); + Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); if (pathv.empty()) { return; } @@ -218,7 +218,7 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { - Geom::PathVector pathv = _last_pointwise.getPathVector(); + Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!validData(i, j)) { @@ -293,7 +293,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -308,7 +308,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Curve const &curve_in = pathv[_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites satellites = _pparam->_last_pointwise.getSatellites(); + Satellites satellites = _pparam->_last_pathVectorSatellites.getSatellites(); time_start = satellites[_index][previous_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; @@ -341,7 +341,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const return Geom::Point(Geom::infinity(), Geom::infinity()); } Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -368,7 +368,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const t = 0; } double time_start = 0; - time_start = _pparam->_last_pointwise.getSatellites()[_index][previous_index].time(curve_in); + time_start = _pparam->_last_pathVectorSatellites.getSatellites()[_index][previous_index].time(curve_in); if (time_start > t) { t = time_start; } @@ -389,7 +389,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->validData(_index, subindex)) { return; } - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect { @@ -480,7 +480,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) if (!_pparam->validData(_index, subindex)) { return; } - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index c6893f595..27e9dea6f 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -12,7 +12,7 @@ * hours * * - * This parameter act as bridge from pointwise class to serialize it as a LPE + * This parameter act as bridge from pathVectorSatellites class to serialize it as a LPE * parameter * * Released under GNU GPL, read the file 'COPYING' for more information @@ -20,7 +20,7 @@ #include "live_effects/parameter/array.h" #include "live_effects/effect-enum.h" -#include "helper/geom-pointwise.h" +#include "helper/geom-pathvectorsatellites.h" #include "knot-holder-entity.h" #include @@ -56,7 +56,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Pointwise pointwise); + void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites); bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -77,7 +77,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Pointwise _last_pointwise; + PathVectorSatellites _last_pathVectorSatellites; }; -- cgit v1.2.3 From 5ad260d5810f6f8bb2cdea7186d0766091ad9b54 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 11 Jun 2016 17:32:56 +0200 Subject: Fixing satellites bug on erase (bzr r13645.1.146) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +-- src/live_effects/parameter/satellitesarray.cpp | 19 +++++++++++++++++-- src/live_effects/parameter/satellitesarray.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 56f7557ba..b4eca6909 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -378,8 +378,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathVectorSatellites); - refreshKnots(); + satellites_param.setPathVectorSatellites(pathVectorSatellites, true); return; } Satellites satellites = satellites_param.data(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 45a6282e0..cb7d0df8f 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -44,11 +44,16 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots) { + if (refresh_knots) { + clearKnotHolder(knoth); + } _last_pathVectorSatellites = pathVectorSatellites; param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); - + if (refresh_knots) { + addKnotHolderEntities(knoth, SP_ACTIVE_DESKTOP, knoth.getItem()); + } } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -214,6 +219,16 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } } +void SatellitesArrayParam::clearKnotHolder(KnotHolder *knotholder) +{ + for (std::list::iterator i = knotholder.entity.begin(); i != knotholder.entity.end(); ++i) + { + delete (*i); + (*i) = NULL; + } + entity.clear(); // is this necessary? +} + void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 27e9dea6f..c52d28541 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -45,6 +45,7 @@ public: SPItem *item); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); + virtual void clearKnotHolder(KnotHolder *knotholder); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); @@ -56,7 +57,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites); + void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots = false); bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); -- cgit v1.2.3 From d84bbca17771ed1a2f680328adf14b30a4c66b77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 01:05:25 +0200 Subject: Fix the bug deleting satellites (bzr r13645.1.148) --- src/live_effects/lpe-fillet-chamfer.cpp | 82 ++++---- src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/satellitesarray.cpp | 248 +++++++++++++------------ src/live_effects/parameter/satellitesarray.h | 13 +- 4 files changed, 175 insertions(+), 170 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b4eca6909..1d5c036ba 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,9 @@ #include <2geom/elliptical-arc.h> #include "knotholder.h" #include -#include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: #include + namespace Inkscape { namespace LivePathEffect { @@ -54,7 +54,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0) + _("Helper size with direction"), "helper_size", &wr, this, 0), + pathvector_satellites(NULL) { registerParameter(&satellites_param); registerParameter(&method); @@ -104,9 +105,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pathVectorSatellites is related to nodes, not curves + //we add the last satellite on open path because pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pathVectorSatellites class has methods when the path is modiffied + //dont remove for this effect because pathvector_satellites class has methods when the path is modiffied //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); @@ -115,9 +116,10 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pathVectorSatellites.setPathVector(pathv); - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites = new PathVectorSatellites(); + pathvector_satellites->setPathVector(pathv); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -239,12 +241,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - //Find another way to update knots satellites_param.knoth->update_knots(); do the thing - //but not updat the knot index on node delete - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -256,8 +254,8 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional previous_index = boost::none; @@ -293,14 +291,14 @@ void LPEFilletChamfer::updateAmount() } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -318,14 +316,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -349,8 +347,8 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -370,16 +368,19 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pathVectorSatellites.getTotalSatellites(); - if (satellites_counter != 0 && number_nodes != satellites_counter) { - Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathVectorSatellites, true); - return; + if (pathvector_satellites) { + size_t number_nodes = pathv.nodes().size(); + size_t satellites_counter = pathvector_satellites->getTotalSatellites(); + if (number_nodes != satellites_counter) { + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pathvector_satellites->recalculateForNewPathVector(pathv, satellite); + satellites_param.setPathVectorSatellites(pathvector_satellites); + refreshKnots(); + return; + } } Satellites satellites = satellites_param.data(); if(satellites.empty()) { @@ -414,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - - pathVectorSatellites.setPathVector(pathv); - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites = new PathVectorSatellites(); + pathvector_satellites->setPathVector(pathv); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -442,7 +443,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (path_it->empty()) { continue; } - _hp.push_back(*path_it); Geom::Path tmp_path; if (path_it->size() == 1) { path++; @@ -453,7 +453,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pathVectorSatellites.getSatellites(); + Satellites satellites = pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 62b894660..363a35d43 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - PathVectorSatellites pathVectorSatellites; + PathVectorSatellites *pathvector_satellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index cb7d0df8f..e61aaf38d 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -11,6 +11,7 @@ #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" +#include "inkscape.h" #include // TODO due to internal breakage in glibmm headers, // this has to be included last. @@ -33,6 +34,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; + _last_pathvector_satellites = NULL; } void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, @@ -44,16 +46,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites) { - if (refresh_knots) { - clearKnotHolder(knoth); - } - _last_pathVectorSatellites = pathVectorSatellites; - param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); - if (refresh_knots) { - addKnotHolderEntities(knoth, SP_ACTIVE_DESKTOP, knoth.getItem()); - } + _last_pathvector_satellites = pathVectorSatellites; + param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -71,24 +67,18 @@ void SatellitesArrayParam::setHelperSize(int hs) _helper_size = hs; updateCanvasIndicators(); } -bool SatellitesArrayParam::validData(size_t index,size_t subindex) -{ - if(!_last_pathVectorSatellites.getPathVector().size() > index){ - return false; - } - if(!_last_pathVectorSatellites.getPathVector()[index].size_closed() > subindex){ - return false; - } - return true; //_last_pathVectorSatellites.getPathVector().nodes().size() == _last_pathVectorSatellites.getTotalSatellites(); -} void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { + if (!_last_pathvector_satellites) { + return; + } + if(!_hp.empty()) { _hp.clear(); } - Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); if (pathv.empty()) { return; } @@ -98,9 +88,6 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!validData(i, j)) { - return; - } if (_vector[i][j].hidden || //Ignore if hidden (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value @@ -219,41 +206,28 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } } -void SatellitesArrayParam::clearKnotHolder(KnotHolder *knotholder) -{ - for (std::list::iterator i = knotholder.entity.begin(); i != knotholder.entity.end(); ++i) - { - delete (*i); - (*i) = NULL; - } - entity.clear(); // is this necessary? -} - void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror) + SPItem *item, + bool mirror) { - Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); + size_t index = 0; for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!validData(i, j)) { - return; - } if (!_vector[i][j].has_mirror && mirror) { continue; } SatelliteType type = _vector[i][j].satellite_type; - size_t index = i; - size_t subindex = j; - if (mirror) { - subindex = subindex + _vector[i].size(); + if (mirror && i == 0 && j == 0) { + index = index + _last_pathvector_satellites->getTotalSatellites(); } using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { - if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { - continue; - } +// if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { +// continue; +// } const gchar *tip; if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " @@ -272,10 +246,11 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } - FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index, subindex); + FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } + index++; } } if (mirror) { @@ -292,52 +267,62 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( - SatellitesArrayParam *p, size_t index, size_t subindex) - : _pparam(p), _index(index), _subindex(subindex) {} + SatellitesArrayParam *p, size_t index) + : _pparam(p), _index(index) {} void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { - Geom::Point s = snap_knot_position(p, state); - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; + } + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + + Geom::Point s = snap_knot_position(p, state); + if (!valid_index(path_index, curve_index)) { return; } - Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Satellite satellite = _pparam->_vector[path_index][curve_index]; + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } - if (subindex != _subindex) { - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + if (is_mirror) { + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - Geom::Curve const &curve_in = pathv[_index][previous_index]; + Geom::Curve const &curve_in = pathv[path_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites satellites = _pparam->_last_pathVectorSatellites.getSatellites(); - time_start = satellites[_index][previous_index].time(curve_in); + Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); + time_start = satellites[path_index][previous_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; } double size = arcLengthAt(mirror_time, curve_in); double amount = curve_in.length() - size; if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][subindex]); + amount = timeAtArcLength(amount, pathv[path_index][curve_index]); } satellite.amount = amount; } else { - satellite.setPosition(s, pathv[_index][subindex]); + satellite.setPosition(s, pathv[path_index][curve_index]); } - _pparam->_vector[_index][subindex] = satellite; + _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -346,35 +331,40 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { + if (!_pparam->_last_pathvector_satellites) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Point tmp_point; - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { - this->knot->hide(); + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Satellite satellite = _pparam->_vector[path_index][curve_index]; + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { - this->knot->hide(); - _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); - std::cout << subindex << pathv[_index].size() << "----" << _pparam->_vector[_index].size() << "fgdgsdgsdgsdsdsgd\n"; - if (subindex != _subindex) { - tmp_point = satellite.getPosition(pathv[_index][subindex]); - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + if (is_mirror) { + tmp_point = satellite.getPosition(pathv[path_index][curve_index]); + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - Geom::Curve const &curve_in = pathv[_index][previous_index]; - double s = satellite.arcDistance(pathv[_index][subindex]); + Geom::Curve const &curve_in = pathv[path_index][previous_index]; + double s = satellite.arcDistance(pathv[path_index][curve_index]); double t = satellite.time(s, true, curve_in); if (t > 1) { t = 1; @@ -383,13 +373,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const t = 0; } double time_start = 0; - time_start = _pparam->_last_pathVectorSatellites.getSatellites()[_index][previous_index].time(curve_in); + time_start = _pparam->_last_pathvector_satellites->getSatellites()[path_index][previous_index].time(curve_in); if (time_start > t) { t = time_start; } tmp_point = (curve_in).pointAt(t); } else { - tmp_point = satellite.getPosition(pathv[_index][subindex]); + tmp_point = satellite.getPosition(pathv[path_index][curve_index]); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -397,27 +387,36 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; } - if (!_pparam->validData(_index, subindex)) { + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; + } + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return; } - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); - if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); + if (!pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector[_index][subindex].amount = 0.0; + _pparam->_vector[path_index][curve_index].amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector[_index][subindex].satellite_type; + SatelliteType type = _pparam->_vector[path_index][curve_index].satellite_type; switch (type) { case FILLET: type = INVERSE_FILLET; @@ -432,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) type = FILLET; break; } - _pparam->_vector[_index][subindex].satellite_type = type; + _pparam->_vector[path_index][curve_index].satellite_type = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; @@ -457,22 +456,22 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - double amount = _pparam->_vector[_index][subindex].amount; - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + double amount = _pparam->_vector[path_index][curve_index].amount; + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { + if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { if (previous_index) { - amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][previous_index], pathv[_index][subindex], _pparam->_vector[_index][previous_index]); + amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); } else { amount = 0.0; } } bool aprox = false; - Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); + Geom::D2 d2_out = pathv[path_index][curve_index].toSBasis(); if (previous_index) { - Geom::D2 d2_in = pathv[_index][previous_index].toSBasis(); + Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -481,41 +480,50 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount, this, _pparam->_use_distance, - aprox, _pparam->_vector[_index][subindex]); + aprox, _pparam->_vector[path_index][curve_index]); } } void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; + } + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return; } - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][previous_index], pathv[_index][subindex]); + amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); if (max_amount > 0 && amount == 0) { - amount = _pparam->_vector[_index][subindex].amount; + amount = _pparam->_vector[path_index][curve_index].amount; } } satellite.amount = amount; - _pparam->_vector[_index][subindex] = satellite; + _pparam->_vector[path_index][curve_index] = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); SPLPEItem *splpeitem = dynamic_cast(item); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index c52d28541..a52bcef53 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -45,7 +45,6 @@ public: SPItem *item); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void clearKnotHolder(KnotHolder *knotholder); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); @@ -57,8 +56,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots = false); - bool validData(size_t index, size_t subindex); + void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; @@ -78,13 +76,13 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - PathVectorSatellites _last_pathVectorSatellites; + PathVectorSatellites *_last_pathvector_satellites; }; class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index, size_t subindex); + FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() { _pparam->knoth = NULL; @@ -97,15 +95,14 @@ public: void knot_set_offset(Satellite); /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const + bool valid_index(size_t index,size_t subindex) const { - return (_pparam->_vector.size() > index); + return (_pparam->_vector.size() > index && _pparam->_vector[index].size() > subindex); }; private: SatellitesArrayParam *_pparam; size_t _index; - size_t _subindex; }; } //namespace LivePathEffect -- cgit v1.2.3 From 7e1183de6ed51ff730915fe936e2bb607dd72f33 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 16:33:27 +0200 Subject: Fix bug consecutive nodes at same position (bzr r13645.1.152) --- src/live_effects/lpe-fillet-chamfer.cpp | 14 +++++++++++++- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/satellitesarray.cpp | 7 ++++++- src/live_effects/parameter/satellitesarray.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1d5c036ba..48e68d366 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,7 +55,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pathvector_satellites(NULL) + pathvector_satellites(NULL), + degenerate_hide(false) { registerParameter(&satellites_param); registerParameter(&method); @@ -387,6 +388,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) doOnApply(lpeItem); satellites = satellites_param.data(); } + if (degenerate_hide) { + satellites_param.setGlobalKnotHide(true); + } else { + satellites_param.setGlobalKnotHide(false); + } if (hide_knots) { satellites_param.setHelperSize(0); } else { @@ -438,6 +444,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + degenerate_hide = false; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { @@ -468,6 +475,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) continue; } Satellite satellite = satellites[path][next_index]; + if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { + degenerate_hide = true; + g_warning("Knots hidded if consecutive nodes has the same position."); + return path_in; + } if (!curve) { //curve == 0 if (!path_it->closed()) { time0 = 0; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 363a35d43..420403b70 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,6 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; + bool degenerate_hide; PathVectorSatellites *pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index e61aaf38d..db7cf80c0 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -33,6 +33,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _knot_color = 0xAAFF8800; _helper_size = 0; _use_distance = false; + _global_knot_hide = false; _effectType = FILLET_CHAMFER; _last_pathvector_satellites = NULL; } @@ -57,6 +58,10 @@ void SatellitesArrayParam::setUseDistance(bool use_knot_distance) _use_distance = use_knot_distance; } +void SatellitesArrayParam::setGlobalKnotHide(bool global_knot_hide) +{ + _global_knot_hide = global_knot_hide; +} void SatellitesArrayParam::setEffectType(EffectType et) { _effectType = et; @@ -331,7 +336,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - if (!_pparam->_last_pathvector_satellites) { + if (!_pparam->_last_pathvector_satellites || _pparam->_global_knot_hide) { return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Point tmp_point; diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index a52bcef53..30b1db6c1 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -75,6 +76,7 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; + bool _global_knot_hide; EffectType _effectType; PathVectorSatellites *_last_pathvector_satellites; -- cgit v1.2.3 From e40990e3b9c391cdded31f28bb8f8d448fd1d361 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 17:27:07 +0200 Subject: Handle both directions on knot reposition (bzr r13645.1.154) --- src/live_effects/parameter/satellitesarray.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index db7cf80c0..18e1bd4de 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -305,13 +305,18 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, { return; } - if (is_mirror) { - size_t previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ - previous_index = pathv[path_index].size() - 1; - } - Geom::Curve const &curve_in = pathv[path_index][previous_index]; - double mirror_time = Geom::nearest_time(s, curve_in); + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; + } + Geom::Curve const &curve_in = pathv[path_index][previous_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + Geom::Point mirror = curve_in.pointAt(mirror_time); + double normal_time = Geom::nearest_time(s, pathv[path_index][curve_index]); + Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); + double distance_mirror = Geom::distance(mirror,s); + double distance_normal = Geom::distance(normal,s); + if (distance_mirror <= distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); time_start = satellites[path_index][previous_index].time(curve_in); -- cgit v1.2.3 From 35fc5dc7a7667ad3e79b409fb588c1cc56e2ab57 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:10:49 +0200 Subject: Fix a helper path data (bzr r14984) --- src/live_effects/lpe-transform_2pts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 1cd59b7fa..3c4ce0708 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -434,7 +434,7 @@ LPETransform2Pts::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } if(!lock_angle && lock_lenght) { char const * svgd; - svgd = "m 7.07,7.07 c -3.9,3.91 -10.24,3.91 -14.14,0 -3.91,-3.9 -3.91,-10.24 0,-14.14 3.9,-3.91 10.24,-3.91 14.14,0 l -2.83,-4.24 -0.7,2.12"; + svgd = "M 0,9.94 C -2.56,9.91 -5.17,8.98 -7.07,7.07 c -3.91,-3.9 -3.91,-10.24 0,-14.14 1.97,-1.97 4.51,-3.02 7.07,-3.04 2.56,0.02 5.1,1.07 7.07,3.04 3.91,3.9 3.91,10.24 0,14.14 C 5.17,8.98 2.56,9.91 0,9.94 Z"; PathVector pathv_turn = sp_svg_read_pathv(svgd); pathv_turn *= Geom::Rotate(previous_angle); pathv_turn *= Affine(r,0,0,r,0,0) * Translate(Geom::Point(end)); -- cgit v1.2.3 From 73f078b27b669c941651ecf14a3119ae491ccabf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:58:55 +0200 Subject: Fix 90% of tweenk review (bzr r13645.1.155) --- src/live_effects/effect.cpp | 32 ++- src/live_effects/effect.h | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 354 +++++++++---------------- src/live_effects/lpe-fillet-chamfer.h | 34 ++- src/live_effects/lpe-transform_2pts.cpp | 2 +- src/live_effects/parameter/array.cpp | 15 +- src/live_effects/parameter/array.h | 2 + src/live_effects/parameter/satellitesarray.cpp | 51 ++-- src/live_effects/parameter/satellitesarray.h | 5 +- 9 files changed, 214 insertions(+), 286 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 0a78b199e..f60d628f6 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -400,19 +400,39 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector sNP) +Effect::setCurrentZoom(double cZ) { - selectedNodesPoints = sNP; + current_zoom = cZ; } void -Effect::setCurrentZoom(double cZ) +Effect::setSelectedNodePoints(std::vector selected_node_points) { - current_zoom = cZ; + selectedNodesPoints = selected_node_points; } +std::vector +Effect::getSelectedNodes() +{ + size_t counter = 0; + std::vector result; + for (size_t i = 0; i < pathvector_before_effect.size(); i++) { + for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { + if ((pathvector_before_effect[i].size_closed() == j-1 && + isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || + isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) + { + result.push_back(counter); + } + counter++; + } + } + return result; +} + + bool -Effect::isNodePointSelected(Geom::Point const &nodePoint) const +Effect::isNodePointSelected(Geom::Point const &node_point) const { if (selectedNodesPoints.size() > 0) { using Geom::X; @@ -421,7 +441,7 @@ Effect::isNodePointSelected(Geom::Point const &nodePoint) const i != selectedNodesPoints.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(nodePoint[X],nodePoint[Y]); + Geom::Point p2(node_point[X],node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..1f08a2bae 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -59,8 +59,9 @@ public: void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector sNP); - bool isNodePointSelected(Geom::Point const &nodePoint) const; + void setSelectedNodePoints(std::vector selected_node_points); + std::vector getSelectedNodes(); + bool isNodePointSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 48e68d366..83baab1d1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -22,67 +22,65 @@ namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, +static const Util::EnumData Fillet_methodData[] = { + { FM_AUTO, N_("Auto"), "auto" }, + { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter FMConverter(FilletMethodData, - FM_END); +static const Util::EnumDataConverter FMConverter(Fillet_methodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellites_param(_("pair_array_param"), _("pair_array_param"), - "satellites_param", &wr, this), - method(_("Method:"), _("Methods to calculate the fillet or chamfer"), - "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, + _satellites_param("satellites_param", "satellites_param", + "_satellites_param", &wr, this), + _method(_("_method:"), _("_methods to calculate the fillet or chamfer"), + "_method", FMConverter, &wr, this, FM_AUTO), + _radius(_("_radius (unit or %):"), _("_radius, in unit or %"), "_radius", &wr, this, 0.0), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", + _chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "_chamfer_steps", &wr, this, 1), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), - "flexible", &wr, this, false), - mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, + _flexible(_("_flexible _radius size (%)"), _("_flexible _radius size (%)"), + "_flexible", &wr, this, false), + _mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "_mirror_knots", &wr, this, true), - only_selected(_("Change only selected nodes"), - _("Change only selected nodes"), "only_selected", &wr, this, + _only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "_only_selected", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), - _("Use knots distance instead radius"), - "use_knot_distance", &wr, this, false), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, + _use_knot_distance(_("Use knots distance instead _radius"), + _("Use knots distance instead _radius"), + "_use_knot_distance", &wr, this, false), + _hide_knots(_("Hide knots"), _("Hide knots"), "_hide_knots", &wr, this, false), - apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), - apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), - helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0), - pathvector_satellites(NULL), - degenerate_hide(false) + _apply_no_radius(_("Apply changes if _radius = 0"), _("Apply changes if _radius = 0"), "_apply_no_radius", &wr, this, true), + _apply_with_radius(_("Apply changes if _radius > 0"), _("Apply changes if _radius > 0"), "_apply_with_radius", &wr, this, true), + _helper_size(_("Helper path size with direction to node:"), + _("Helper path size with direction to node"), "_helper_size", &wr, this, 0), + _pathvector_satellites(NULL), + _degenerate_hide(false) { - registerParameter(&satellites_param); - registerParameter(&method); - registerParameter(&radius); - registerParameter(&chamfer_steps); - registerParameter(&helper_size); - registerParameter(&flexible); - registerParameter(&use_knot_distance); - registerParameter(&mirror_knots); - registerParameter(&apply_no_radius); - registerParameter(&apply_with_radius); - registerParameter(&only_selected); - registerParameter(&hide_knots); + registerParameter(&_satellites_param); + registerParameter(&_method); + registerParameter(&_radius); + registerParameter(&_chamfer_steps); + registerParameter(&_helper_size); + registerParameter(&_flexible); + registerParameter(&_use_knot_distance); + registerParameter(&_mirror_knots); + registerParameter(&_apply_no_radius); + registerParameter(&_apply_with_radius); + registerParameter(&_only_selected); + registerParameter(&_hide_knots); - radius.param_set_range(0.0, Geom::infinity()); - radius.param_set_increments(1, 1); - radius.param_set_digits(4); - radius.param_overwrite_widget(true); - chamfer_steps.param_set_range(1, 999); - chamfer_steps.param_set_increments(1, 1); - chamfer_steps.param_set_digits(0); - //chamfer_steps.param_overwrite_widget(true); - helper_size.param_set_range(0, 999); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); - //helper_size.param_overwrite_widget(true); + _radius.param_set_range(0.0, Geom::infinity()); + _radius.param_set_increments(1, 1); + _radius.param_set_digits(4); + _radius.param_overwrite_widget(true); + _chamfer_steps.param_set_range(1, 999); + _chamfer_steps.param_set_increments(1, 1); + _chamfer_steps.param_set_digits(0); + _helper_size.param_set_range(0, 999); + _helper_size.param_set_increments(5, 5); + _helper_size.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -103,24 +101,24 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) // continue //} Satellite satellite(FILLET); - satellite.setSteps(chamfer_steps); + satellite.setSteps(_chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pathvector_satellites is related to nodes, not curves + //we add the last satellite on open path because _pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pathvector_satellites class has methods when the path is modiffied - //and we want one method for all uses + //dont remove for this effect because _pathvector_satellites class has _methods when the path is modiffied + //and we want one _method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setSteps(chamfer_steps); + satellite.setSteps(_chamfer_steps); subpath_satellites.push_back(satellite); } satellites.push_back(subpath_satellites); } - pathvector_satellites = new PathVectorSatellites(); - pathvector_satellites->setPathVector(pathv); - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites = new PathVectorSatellites(); + _pathvector_satellites->setPathVector(pathv); + _pathvector_satellites->setSatellites(satellites); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -142,7 +140,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "radius") { + if (param->param_key == "_radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -154,7 +152,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } - } else if (param->param_key == "chamfer_steps") { + } else if (param->param_key == "_chamfer_steps") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -166,12 +164,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } - } else if (param->param_key == "helper_size") { + } else if (param->param_key == "_helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "only_selected") { + } else if (param->param_key == "_only_selected") { Gtk::manage(widg); } Glib::ustring *tip = param->param_getTooltip(); @@ -189,29 +187,25 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } Gtk::HBox *fillet_container = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); fillet->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),FILLET)); fillet_container->pack_start(*fillet, true, true, 2); - Gtk::Button *inverse_fillet = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + Gtk::Button *inverse_fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); inverse_fillet->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),INVERSE_FILLET)); fillet_container->pack_start(*inverse_fillet, true, true, 2); Gtk::HBox *chamfer_container = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); chamfer->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),CHAMFER)); chamfer_container->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverse_chamfer = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + Gtk::Button *inverse_chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); inverse_chamfer->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),INVERSE_CHAMFER)); chamfer_container->pack_start(*inverse_chamfer, true, true, 2); vbox->pack_start(*fillet_container, true, true, 2); @@ -220,136 +214,30 @@ Gtk::Widget *LPEFilletChamfer::newWidget() return vbox; } -void LPEFilletChamfer::fillet() -{ - updateSatelliteType(FILLET); -} - -void LPEFilletChamfer::inverseFillet() -{ - updateSatelliteType(INVERSE_FILLET); -} - -void LPEFilletChamfer::chamfer() -{ - updateSatelliteType(CHAMFER); -} - -void LPEFilletChamfer::inverseChamfer() -{ - updateSatelliteType(INVERSE_CHAMFER); -} - void LPEFilletChamfer::refreshKnots() { - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); + if (_satellites_param._knoth) { + _satellites_param._knoth->update_knots(); } } void LPEFilletChamfer::updateAmount() { - double power = 0; - if (!flexible) { - power = radius; - } else { - power = radius / 100; - } - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - boost::optional previous_index = boost::none; - if(j == 0 && pathv[i].closed()){ - previous_index = pathv[i].size() - 1; - } else if(!pathv[i].closed() || j != 0) { - previous_index = j - 1; - } - if (!pathv[i].closed() && j == 0) { - satellites[i][j].amount = 0; - continue; - } - if (pathv[i].size() == j) { - continue; - } - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point) || !only_selected) { - if (!use_knot_distance && !flexible) { - if(previous_index) { - satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*previous_index], pathv[i][j]); - } else { - satellites[i][j].amount = 0.0; - } - } else { - satellites[i][j].amount = power; - } - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateAmount(_radius, _apply_no_radius, _apply_with_radius, _only_selected, + _use_knot_distance, _flexible); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point)) { - satellites[i][j].steps = chamfer_steps; - } - } else { - satellites[i][j].steps = chamfer_steps; - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateSteps(_chamfer_steps, _apply_no_radius, _apply_with_radius, _only_selected); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - if (pathv[i].size() == j) { - if (!only_selected) { - satellites[i][j].satellite_type = satellitetype; - } - continue; - } - if (only_selected) { - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point)) { - satellites[i][j].satellite_type = satellitetype; - } - } else { - satellites[i][j].satellite_type = satellitetype; - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateSatelliteType(satellitetype, _apply_no_radius, _apply_with_radius, _only_selected); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -363,45 +251,46 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellites_param.setUseDistance(use_knot_distance); + _satellites_param.setUseDistance(_use_knot_distance); //mandatory call - satellites_param.setEffectType(effectType()); + _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - if (pathvector_satellites) { + if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pathvector_satellites->getTotalSatellites(); + size_t satellites_counter = _pathvector_satellites->getTotalSatellites(); if (number_nodes != satellites_counter) { Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pathvector_satellites->recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathvector_satellites); + satellite.setIsTime(_flexible); + satellite.setHasMirror(_mirror_knots); + satellite.setHidden(_hide_knots); + _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); + _pathvector_satellites->setSelected(getSelectedNodes()); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); return; } } - Satellites satellites = satellites_param.data(); + Satellites satellites = _satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); - satellites = satellites_param.data(); + satellites = _satellites_param.data(); } - if (degenerate_hide) { - satellites_param.setGlobalKnotHide(true); + if (_degenerate_hide) { + _satellites_param.setGlobalKnotHide(true); } else { - satellites_param.setGlobalKnotHide(false); + _satellites_param.setGlobalKnotHide(false); } - if (hide_knots) { - satellites_param.setHelperSize(0); + if (_hide_knots) { + _satellites_param.setHelperSize(0); } else { - satellites_param.setHelperSize(helper_size); + _satellites_param.setHelperSize(_helper_size); } for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j].is_time != flexible) { - satellites[i][j].is_time = flexible; + if (satellites[i][j].is_time != _flexible) { + satellites[i][j].is_time = _flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j){ continue; @@ -415,16 +304,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].amount = size; } } - if (satellites[i][j].has_mirror != mirror_knots) { - satellites[i][j].has_mirror = mirror_knots; + if (satellites[i][j].has_mirror != _mirror_knots) { + satellites[i][j].has_mirror = _mirror_knots; } - satellites[i][j].hidden = hide_knots; + satellites[i][j].hidden = _hide_knots; } } - pathvector_satellites = new PathVectorSatellites(); - pathvector_satellites->setPathVector(pathv); - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites = new PathVectorSatellites(); + _pathvector_satellites->setPathVector(pathv); + _pathvector_satellites->setSatellites(satellites); + _pathvector_satellites->setSelected(getSelectedNodes()); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -444,7 +334,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - degenerate_hide = false; + _degenerate_hide = false; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { @@ -460,7 +350,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pathvector_satellites->getSatellites(); + Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { @@ -476,7 +366,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Satellite satellite = satellites[path][next_index]; if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { - degenerate_hide = true; + _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; } @@ -563,10 +453,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); - double radius = Geom::distance(start_arc_point, + double _radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / sin(angle / 2.0); - Geom::Coord rx = radius; + Geom::Coord rx = _radius; Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { @@ -583,8 +473,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -592,9 +482,9 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.appendNew(handle_1, handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0 / steps; + double _chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(_chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); @@ -602,25 +492,25 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( inverse_handle_1, inverse_handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0 / steps; + double _chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + path_chamfer.pointAt(_chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -629,8 +519,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 420403b70..bd0b74b51 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -20,7 +20,7 @@ namespace Inkscape { namespace LivePathEffect { -enum FilletMethod { +enum Fillet_method { FM_AUTO, FM_ARC, FM_BEZIER, @@ -40,28 +40,24 @@ public: void updateChamferSteps(); void updateAmount(); void refreshKnots(); - void chamfer(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - SatellitesArrayParam satellites_param; + SatellitesArrayParam _satellites_param; private: - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - BoolParam flexible; - BoolParam mirror_knots; - BoolParam only_selected; - BoolParam use_knot_distance; - BoolParam hide_knots; - BoolParam apply_no_radius; - BoolParam apply_with_radius; - ScalarParam helper_size; + EnumParam _method; + ScalarParam _radius; + ScalarParam _chamfer_steps; + BoolParam _flexible; + BoolParam _mirror_knots; + BoolParam _only_selected; + BoolParam _use_knot_distance; + BoolParam _hide_knots; + BoolParam _apply_no_radius; + BoolParam _apply_with_radius; + ScalarParam _helper_size; - bool degenerate_hide; - PathVectorSatellites *pathvector_satellites; + bool _degenerate_hide; + PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 1cd59b7fa..3c4ce0708 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -434,7 +434,7 @@ LPETransform2Pts::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } if(!lock_angle && lock_lenght) { char const * svgd; - svgd = "m 7.07,7.07 c -3.9,3.91 -10.24,3.91 -14.14,0 -3.91,-3.9 -3.91,-10.24 0,-14.14 3.9,-3.91 10.24,-3.91 14.14,0 l -2.83,-4.24 -0.7,2.12"; + svgd = "M 0,9.94 C -2.56,9.91 -5.17,8.98 -7.07,7.07 c -3.91,-3.9 -3.91,-10.24 0,-14.14 1.97,-1.97 4.51,-3.02 7.07,-3.04 2.56,0.02 5.1,1.07 7.07,3.04 3.91,3.9 3.91,10.24 0,14.14 C 5.17,8.98 2.56,9.91 0,9.94 Z"; PathVector pathv_turn = sp_svg_read_pathv(svgd); pathv_turn *= Geom::Rotate(previous_angle); pathv_turn *= Affine(r,0,0,r,0,0) * Translate(Geom::Point(end)); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 4e3037904..28867def2 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -58,18 +58,19 @@ ArrayParam >::readsvg(const gchar * str) gchar ** strarray = g_strsplit(str, "@", 0); gchar ** iter = strarray; while (*iter != NULL) { - gchar ** strsubarray = g_strsplit(*iter, ",", 7); - if(*strsubarray[6]){ + gchar ** strsubarray = g_strsplit(*iter, ",", 8); + if(*strsubarray[7]){//steps always > 0 Satellite *satellite = new Satellite(); satellite->setSatelliteType(g_strstrip(strsubarray[0])); satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite->has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite->hidden = strncmp(strsubarray[3],"1",1) == 0; + satellite->selected = strncmp(strsubarray[2],"1",1) == 0; + satellite->has_mirror = strncmp(strsubarray[3],"1",1) == 0; + satellite->hidden = strncmp(strsubarray[4],"1",1) == 0; double amount,angle; float stepsTmp; - sp_svg_number_read_d(strsubarray[4], &amount); - sp_svg_number_read_d(strsubarray[5], &angle); - sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); + sp_svg_number_read_d(strsubarray[5], &amount); + sp_svg_number_read_d(strsubarray[6], &angle); + sp_svg_number_read_f(g_strstrip(strsubarray[7]), &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; satellite->amount = amount; satellite->angle = angle; diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 9802abc2e..9204ede1f 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -120,6 +120,8 @@ protected: str << ","; str << vector_data[i].is_time; str << ","; + str << vector_data[i].selected; + str << ","; str << vector_data[i].has_mirror; str << ","; str << vector_data[i].hidden; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 18e1bd4de..2f5cea7b5 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -26,7 +26,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam >(label, tip, key, wr, effect, 0), _knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -180,6 +180,9 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) } } } + if(!_knot_reset_helper.empty()){ + _hp.insert(_hp.end(), _knot_reset_helper.begin(), _knot_reset_helper.end() ); + } if (mirror) { updateCanvasIndicators(false); } @@ -230,24 +233,21 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { -// if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { -// continue; -// } const gchar *tip; if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " + tip = _("Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + tip = _("Inverse Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " + tip = _("Inverse Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else { - tip = _("Fillet: Ctrl+Click toggle type, " + tip = _("Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } @@ -267,7 +267,7 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - knoth = knotholder; + _knoth = knotholder; addKnotHolderEntities(knotholder, desktop, item, true); } @@ -316,6 +316,14 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); double distance_mirror = Geom::distance(mirror,s); double distance_normal = Geom::distance(normal,s); + //this avoid toggle when fillet are near node +// if (is_mirror && Geom::are_near(mirror, pathv[path_index][curve_index].initialPoint())) { +// distance_mirror = 0.0; +// distance_normal = 1.0; +// } else if (!is_mirror && Geom::are_near(normal, pathv[path_index][curve_index].initialPoint())){ +// distance_mirror = 1.0; +// distance_normal = 0.0; +// } if (distance_mirror <= distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); @@ -332,6 +340,15 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } else { satellite.setPosition(s, pathv[path_index][curve_index]); } + _pparam->_knot_reset_helper.clear(); + if (satellite.amount == 0){ + char const *svgd; + svgd = "M -5.39,8.78 -9.13,5.29 -10.38,10.28 Z M -7.22,7.07 -3.43,3.37 m -1.95,-12.16 -3.74,3.5 -1.26,-5 z " + "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " + "M 7.07,7.07 3.29,3.37 M 5.24,-8.78 l 3.74,3.5 1.26,-5 z M 7.07,-7.07 3.29,-3.37"; + _pparam->_knot_reset_helper = sp_svg_read_pathv(svgd); + _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(Geom::Point(normal)); + } _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { @@ -446,21 +463,21 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " + tip = _("Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + tip = _("Inverse Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " + tip = _("Inverse Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else { - tip = _("Fillet: Ctrl+Click toggle type, " + tip = _("Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } this->knot->tip = g_strdup(tip); this->knot->show(); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 30b1db6c1..64bc934c8 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -64,7 +64,7 @@ public: friend class LPEFilletChamfer; protected: - KnotHolder *knoth; + KnotHolder *_knoth; private: SatellitesArrayParam(const SatellitesArrayParam &); @@ -74,6 +74,7 @@ private: SPKnotModeType _knot_mode; guint32 _knot_color; Geom::PathVector _hp; + Geom::PathVector _knot_reset_helper; int _helper_size; bool _use_distance; bool _global_knot_hide; @@ -87,7 +88,7 @@ public: FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() { - _pparam->knoth = NULL; + _pparam->_knoth = NULL; } virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, -- cgit v1.2.3 From 2c544b51a588c8874b5b5f9a5e1e33d591972b15 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 14 Jun 2016 23:44:32 +0200 Subject: Add snap to origin in double direction knots (bzr r13645.1.157) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 + src/live_effects/lpe-fillet-chamfer.h | 4 ++-- src/live_effects/parameter/satellitesarray.cpp | 20 ++++++++++---------- src/live_effects/parameter/satellitesarray.h | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 83baab1d1..ef5f8f0a5 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -252,6 +252,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } //fillet chamfer specific calls _satellites_param.setUseDistance(_use_knot_distance); + _satellites_param.setCurrentZoom(current_zoom); //mandatory call _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index bd0b74b51..8a3701f7d 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -31,10 +31,10 @@ class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual Geom::PathVector - doEffect_path(Geom::PathVector const &path_in); + virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); + Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 2f5cea7b5..c0141ddfa 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -34,6 +34,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _global_knot_hide = false; + _current_zoom = 0; _effectType = FILLET_CHAMFER; _last_pathvector_satellites = NULL; } @@ -58,6 +59,11 @@ void SatellitesArrayParam::setUseDistance(bool use_knot_distance) _use_distance = use_knot_distance; } +void SatellitesArrayParam::setCurrentZoom(double current_zoom) +{ + _current_zoom = current_zoom; +} + void SatellitesArrayParam::setGlobalKnotHide(bool global_knot_hide) { _global_knot_hide = global_knot_hide; @@ -316,15 +322,9 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); double distance_mirror = Geom::distance(mirror,s); double distance_normal = Geom::distance(normal,s); - //this avoid toggle when fillet are near node -// if (is_mirror && Geom::are_near(mirror, pathv[path_index][curve_index].initialPoint())) { -// distance_mirror = 0.0; -// distance_normal = 1.0; -// } else if (!is_mirror && Geom::are_near(normal, pathv[path_index][curve_index].initialPoint())){ -// distance_mirror = 1.0; -// distance_normal = 0.0; -// } - if (distance_mirror <= distance_normal) { + if (Geom::are_near(s, pathv[path_index][curve_index].initialPoint(), 1.5 / _pparam->_current_zoom)) { + satellite.amount = 0; + } else if (distance_mirror < distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); time_start = satellites[path_index][previous_index].time(curve_in); @@ -347,7 +347,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " "M 7.07,7.07 3.29,3.37 M 5.24,-8.78 l 3.74,3.5 1.26,-5 z M 7.07,-7.07 3.29,-3.37"; _pparam->_knot_reset_helper = sp_svg_read_pathv(svgd); - _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(Geom::Point(normal)); + _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(pathv[path_index][curve_index].initialPoint()); } _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 64bc934c8..5b2d8a799 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setCurrentZoom(double current_zoom); void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); @@ -78,6 +79,7 @@ private: int _helper_size; bool _use_distance; bool _global_knot_hide; + double _current_zoom; EffectType _effectType; PathVectorSatellites *_last_pathvector_satellites; -- cgit v1.2.3 From 5d388f13644b59e355e0980c74695247b2191562 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 16 Jun 2016 22:29:40 +0200 Subject: Fixes some bugs related to powerstroke 'Powerstroke infinite loop' Fixed bugs: - https://launchpad.net/bugs/1535444 - https://launchpad.net/bugs/1236320 - https://launchpad.net/bugs/1586973 (bzr r14991) --- src/live_effects/lpe-powerstroke.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 03102a84a..66c8776b5 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -35,6 +35,7 @@ #include <2geom/ellipse.h> #include <2geom/circle.h> #include <2geom/math-utils.h> +#include "helper/geom.h" #include #include "spiro.h" @@ -205,14 +206,13 @@ LPEPowerStroke::~LPEPowerStroke() } - void LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem) { - if (SP_IS_SHAPE(lpeitem)) { + if (SP_IS_SHAPE(lpeitem) && offset_points.data().empty()) { SPLPEItem* item = const_cast(lpeitem); std::vector points; - Geom::PathVector const &pathv = SP_SHAPE(lpeitem)->_curve->get_pathvector(); + Geom::PathVector const &pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeitem)->_curve->get_pathvector()); double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed / 2 : 1.; SPCSSAttr *css = sp_repr_css_attr_new (); @@ -565,12 +565,11 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) if (path_in.empty()) { return path_out; } - - // for now, only regard first subpath and ignore the rest - Geom::Piecewise > pwd2_in = path_in[0].toPwSb(); - + Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::Piecewise > pwd2_in = pathv[0].toPwSb(); Piecewise > der = derivative(pwd2_in); - Piecewise > n = rot90(unitVector(der)); + Piecewise > n = unitVector(der,0.0001); + n = rot90(n); offset_points.set_pwd2(pwd2_in, n); LineCapType end_linecap = static_cast(end_linecap_type.get_value()); @@ -583,7 +582,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) if (sort_points) { sort(ts.begin(), ts.end(), compare_offsets); } - if (path_in[0].closed()) { + if (pathv[0].closed()) { // add extra points for interpolation between first and last point Point first_point = ts.front(); Point last_point = ts.back(); @@ -605,7 +604,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) for (std::size_t i = 0, e = ts.size(); i < e; ++i) { ts[i][Geom::X] *= xcoord_scaling; } - // create stroke path where points (x,y) := (t, offset) Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast(interpolator_type.get_value())); if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast(interpolator)) { @@ -631,7 +629,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) x = portion(x, rtsmin.at(0), rtsmax.at(0)); y = portion(y, rtsmin.at(0), rtsmax.at(0)); } - LineJoinType jointype = static_cast(linejoin_type.get_value()); Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); @@ -639,8 +636,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE); Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE); - - if (path_in[0].closed()) { + if (pathv[0].closed()) { fixed_path.close(true); path_out.push_back(fixed_path); fixed_mirrorpath.close(true); @@ -684,7 +680,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) } fixed_path.append(fixed_mirrorpath); - switch (start_linecap) { case LINECAP_ZERO_WIDTH: // do nothing @@ -720,11 +715,9 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) break; } } - fixed_path.close(true); path_out.push_back(fixed_path); } - return path_out; } -- cgit v1.2.3 From c631289820725ebd027571ec34ae2a1540cc3713 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 10:33:51 +0200 Subject: attemp to simplify doeffect code on fillet chamfer (bzr r13645.1.159) --- src/live_effects/lpe-fillet-chamfer.cpp | 109 +++++++++++++++----------------- src/live_effects/lpe-fillet-chamfer.h | 1 + 2 files changed, 51 insertions(+), 59 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ef5f8f0a5..f2ed8d4d8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -328,6 +328,17 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< hp_vec.push_back(_hp); } +void +LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point) +{ + double path_subdivision = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = path_chamfer.pointAt(path_subdivision * i); + tmp_path.appendNew(chamfer_step); + } + tmp_path.appendNew(end_arc_point); +} + Geom::PathVector LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { @@ -470,65 +481,45 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (steps < 1) { steps = 1; } - if (type == CHAMFER) { - Geom::Path path_chamfer; - path_chamfer.start(tmp_path.finalPoint()); - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, - ccw_toggle, end_arc_point); - } else { - path_chamfer.appendNew(handle_1, handle_2, - end_arc_point); - } - double _chamfer_stepsTime = 1.0 / steps; - for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = path_chamfer.pointAt(_chamfer_stepsTime * i); - tmp_path.appendNew(chamfer_step); - } - tmp_path.appendNew(end_arc_point); - } else if (type == INVERSE_CHAMFER) { - Geom::Path path_chamfer; - path_chamfer.start(tmp_path.finalPoint()); - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, - ccw_toggle, end_arc_point); - } else { - path_chamfer.appendNew( - inverse_handle_1, inverse_handle_2, end_arc_point); - } - double _chamfer_stepsTime = 1.0 / steps; - for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(_chamfer_stepsTime * i); - tmp_path.appendNew(chamfer_step); - } - tmp_path.appendNew(end_arc_point); - } else if (type == INVERSE_FILLET) { - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); - } else { - tmp_path.appendNew(inverse_handle_1, - inverse_handle_2, end_arc_point); - } - } else if (type == FILLET) { - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); - } else { - tmp_path.appendNew(handle_1, handle_2, - end_arc_point); - } + bool eliptical = (is_straight_curve(*curve_it1) && + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC; + switch (type) { + case CHAMFER: + Geom::Path path_chamfer; + path_chamfer.start(tmp_path.finalPoint()); + if (eliptical) { + ccw_toggle = ccw_toggle ? 0 : 1; + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew(handle_1, handle_2, end_arc_point); + } + addChamferSteps(tmp_path, path_chamfer, end_arc_point); + break; + case INVERSE_CHAMFER: + Geom::Path path_chamfer; + path_chamfer.start(tmp_path.finalPoint()); + if (eliptical) { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); + } + addChamferSteps(tmp_path, path_chamfer, end_arc_point); + break; + case INVERSE_FILLET: + if (eliptical) { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); + } + break; + default: //fillet + if (eliptical) { + ccw_toggle = ccw_toggle ? 0 : 1; + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + tmp_path.appendNew(handle_1, handle_2, end_arc_point); + } } } else { if (!knot_curve_1->isDegenerate()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 8a3701f7d..35e9028f3 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -35,6 +35,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); + void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); -- cgit v1.2.3 From c5f642fbd66ccb150d361d2861d0b1baa744dcba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 15:07:51 +0200 Subject: Pre fixing selected points (bzr r13645.1.161) --- src/live_effects/effect.cpp | 13 ++++--- src/live_effects/effect.h | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 53 +++++++++++++++----------- src/live_effects/lpe-fillet-chamfer.h | 3 +- src/live_effects/parameter/satellitesarray.cpp | 45 +++++++++++++--------- 5 files changed, 67 insertions(+), 51 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index f60d628f6..515aa26fc 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -406,9 +406,9 @@ Effect::setCurrentZoom(double cZ) } void -Effect::setSelectedNodePoints(std::vector selected_node_points) +Effect::setSelectedNodePoints(std::vector selected_nodes_pos) { - selectedNodesPoints = selected_node_points; + _selected_nodes_pos = selected_nodes_pos; } std::vector @@ -418,7 +418,8 @@ Effect::getSelectedNodes() std::vector result; for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { - if ((pathvector_before_effect[i].size_closed() == j-1 && + if ((!pathvector_before_effect[i].closed() && + pathvector_before_effect[i].size_closed() == j-1 && isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) { @@ -434,11 +435,11 @@ Effect::getSelectedNodes() bool Effect::isNodePointSelected(Geom::Point const &node_point) const { - if (selectedNodesPoints.size() > 0) { + if (_selected_nodes_pos.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { + for (std::vector::const_iterator i = _selected_nodes_pos.begin(); + i != _selected_nodes_pos.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); Geom::Point p2(node_point[X],node_point[Y]); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1f08a2bae..3b02b14d4 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -59,7 +59,7 @@ public: void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector selected_node_points); + void setSelectedNodePoints(std::vector selected_nodes_pos); std::vector getSelectedNodes(); bool isNodePointSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); @@ -163,7 +163,7 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; - std::vector selectedNodesPoints; + std::vector _selected_nodes_pos; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f2ed8d4d8..7a663614b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -260,8 +260,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //TODO: Update the satellite data in paths modified, Goal 0.93 if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = _pathvector_satellites->getTotalSatellites(); - if (number_nodes != satellites_counter) { + size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); + if (number_nodes != previous_number_nodes) { + std::cout << "sfsfaasfasfasfasffasdf\n"; Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); @@ -329,7 +330,7 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } void -LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point) +LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps) { double path_subdivision = 1.0 / steps; for (size_t i = 1; i < steps; i++) { @@ -462,14 +463,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Geom::Line const angled_line(start_arc_point, end_arc_point); - double arc_angle = Geom::angle_between(x_line, angled_line); - double _radius = Geom::distance(start_arc_point, - middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); - Geom::Coord rx = _radius; - Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { if (!knot_curve_1->isDegenerate()) { @@ -478,14 +471,20 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; - if (steps < 1) { - steps = 1; - } + if (!steps) steps = 1; + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); + double arc_angle = Geom::angle_between(x_line, angled_line); + double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); + Geom::Coord rx = radius; + Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && is_straight_curve(curve_it2) && _method != FM_BEZIER) || _method == FM_ARC; switch (type) { - case CHAMFER: + case CHAMFER: + { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if (eliptical) { @@ -494,9 +493,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else { path_chamfer.appendNew(handle_1, handle_2, end_arc_point); } - addChamferSteps(tmp_path, path_chamfer, end_arc_point); - break; - case INVERSE_CHAMFER: + addChamferSteps(tmp_path, path_chamfer, end_arc_point, steps); + } + break; + case INVERSE_CHAMFER: + { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if (eliptical) { @@ -504,22 +505,28 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else { path_chamfer.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - addChamferSteps(tmp_path, path_chamfer, end_arc_point); - break; - case INVERSE_FILLET: + addChamferSteps(tmp_path, path_chamfer, end_arc_point, steps); + } + break; + case INVERSE_FILLET: + { if (eliptical) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - break; - default: //fillet + } + break; + default: //fillet + { if (eliptical) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, end_arc_point); } + } + break; } } else { if (!knot_curve_1->isDegenerate()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 35e9028f3..134886950 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -35,7 +35,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); - void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point); + void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); @@ -56,7 +56,6 @@ private: BoolParam _apply_no_radius; BoolParam _apply_with_radius; ScalarParam _helper_size; - bool _degenerate_hide; PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index c0141ddfa..71c69c6c5 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -112,10 +112,13 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) bool overflow = false; double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); - size_t previous_index = j - 1; //Always are previous index because we skip first satellite on open paths + gint previous_index = j - 1; //Always are previous index because we skip first satellite on open paths if(j == 0 && pathv[i].closed()){ previous_index = pathv[i].size() - 1; } + if( previous_index < 0 ) { + return; + } double lenght_in = pathv.curveAt(previous_index).length(); if (mirror) { curve_in = const_cast(&pathv.curveAt(previous_index)); @@ -311,10 +314,13 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, { return; } - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } Geom::Curve const &curve_in = pathv[path_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); Geom::Point mirror = curve_in.pointAt(mirror_time); @@ -386,10 +392,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const this->knot->show(); if (is_mirror) { tmp_point = satellite.getPosition(pathv[path_index][curve_index]); - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Curve const &curve_in = pathv[path_index][previous_index]; double s = satellite.arcDistance(pathv[path_index][curve_index]); double t = satellite.time(s, true, curve_in); @@ -484,27 +493,24 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { double amount = _pparam->_vector[path_index][curve_index].amount; - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { - if (previous_index) { - amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); - } else { - amount = 0.0; - } + amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); } bool aprox = false; Geom::D2 d2_out = pathv[path_index][curve_index].toSBasis(); - if (previous_index) { - Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && - !_pparam->_use_distance - ? true - : false; - } + Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount, this, _pparam->_use_distance, aprox, _pparam->_vector[path_index][curve_index]); @@ -540,10 +546,13 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector[path_index][curve_index].amount; -- cgit v1.2.3 From 38a1a4d45114a681408e763c3afec79f0bc21940 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 18:53:51 +0200 Subject: fixing bug moving nodes (bzr r13645.1.162) --- src/live_effects/effect.cpp | 27 +++++++++++++++----------- src/live_effects/effect.h | 10 +++++----- src/live_effects/lpe-bspline.cpp | 8 ++++---- src/live_effects/lpe-fillet-chamfer.cpp | 14 ++++++------- src/live_effects/parameter/satellitesarray.cpp | 7 ++----- 5 files changed, 34 insertions(+), 32 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 515aa26fc..7b36e30f9 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -363,14 +363,13 @@ Effect::Effect(LivePathEffectObject *lpeobject) lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), - current_zoom(1), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden - is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden + is_ready(false), // is automatically set to false if providesOwnFlashPaths() is not overridden + _current_zoom(1.0) { registerParameter( dynamic_cast(&is_visible) ); is_visible.widget_is_visible = false; - current_zoom = 0.0; } Effect::~Effect() @@ -400,13 +399,19 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setCurrentZoom(double cZ) +Effect::setCurrentZoom(double zoom) { - current_zoom = cZ; + _current_zoom = zoom; +} + +double +Effect::getCurrentZoom() +{ + return _current_zoom; } void -Effect::setSelectedNodePoints(std::vector selected_nodes_pos) +Effect::setSelectedNodes(std::vector selected_nodes_pos) { _selected_nodes_pos = selected_nodes_pos; } @@ -419,9 +424,9 @@ Effect::getSelectedNodes() for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { if ((!pathvector_before_effect[i].closed() && - pathvector_before_effect[i].size_closed() == j-1 && - isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || - isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) + pathvector_before_effect[i].size_closed() == j+1 && + isNodeSelected( pathvector_before_effect[i][j].finalPoint())) || + isNodeSelected( pathvector_before_effect[i][j].initialPoint())) { result.push_back(counter); } @@ -433,15 +438,15 @@ Effect::getSelectedNodes() bool -Effect::isNodePointSelected(Geom::Point const &node_point) const +Effect::isNodeSelected(Geom::Point const &node_point) const { if (_selected_nodes_pos.size() > 0) { using Geom::X; using Geom::Y; + Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); for (std::vector::const_iterator i = _selected_nodes_pos.begin(); i != _selected_nodes_pos.end(); ++i) { Geom::Point p = *i; - Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); Geom::Point p2(node_point[X],node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 3b02b14d4..ac83d9b75 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -58,10 +58,11 @@ public: //of indirection is needed. We first call these methods, then the below. void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); - void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector selected_nodes_pos); + void setCurrentZoom(double zoom); + double getCurrentZoom(); + void setSelectedNodes(std::vector selected_nodes_pos); std::vector getSelectedNodes(); - bool isNodePointSelected(Geom::Point const &node_point) const; + bool isNodeSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); @@ -162,7 +163,6 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - double current_zoom; std::vector _selected_nodes_pos; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; @@ -170,7 +170,7 @@ private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed bool is_ready; - + double _current_zoom; Effect(const Effect&); Effect& operator=(const Effect&); }; diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 1423e670a..3fed11d5a 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -398,7 +398,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && Geom::are_near((*cubic)[1], point_at0)) || (apply_with_weight && !Geom::are_near((*cubic)[1], point_at0))) { - if (isNodePointSelected(point_at0) || !only_selected) { + if (isNodeSelected(point_at0) || !only_selected) { point_at1 = sbasis_in.valueAt(weight_ammount); if (weight_ammount != NO_POWER) { point_at1 = @@ -414,7 +414,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && Geom::are_near((*cubic)[2], point_at3)) || (apply_with_weight && !Geom::are_near((*cubic)[2], point_at3))) { - if (isNodePointSelected(point_at3) || !only_selected) { + if (isNodeSelected(point_at3) || !only_selected) { point_at2 = sbasis_in.valueAt(1 - weight_ammount); if (weight_ammount != NO_POWER) { point_at2 = @@ -431,14 +431,14 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && weight_ammount == NO_POWER) || (apply_with_weight && weight_ammount != NO_POWER)) { - if (isNodePointSelected(point_at0) || !only_selected) { + if (isNodeSelected(point_at0) || !only_selected) { point_at1 = sbasis_in.valueAt(weight_ammount); point_at1 = Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } else { point_at1 = in->first_segment()->initialPoint(); } - if (isNodePointSelected(point_at3) || !only_selected) { + if (isNodeSelected(point_at3) || !only_selected) { point_at2 = sbasis_in.valueAt(1 - weight_ammount); point_at2 = Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7a663614b..c9d3d4afd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -252,7 +252,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } //fillet chamfer specific calls _satellites_param.setUseDistance(_use_knot_distance); - _satellites_param.setCurrentZoom(current_zoom); + _satellites_param.setCurrentZoom(getCurrentZoom()); //mandatory call _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); @@ -262,7 +262,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); if (number_nodes != previous_number_nodes) { - std::cout << "sfsfaasfasfasfasffasdf\n"; Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); @@ -348,7 +347,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); _degenerate_hide = false; - Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(path_in); + Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -363,7 +363,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { @@ -377,8 +376,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } continue; } + Geom::Curve const &curve_it2 = pathv[path][next_index]; Satellite satellite = satellites[path][next_index]; - if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { + if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint()) || + Geom::are_near(curve_it2.initialPoint(), curve_it2.finalPoint())) { _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; @@ -391,7 +392,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } bool last = pathv[path].size() - 1 == curve; - Geom::Curve const &curve_it2 = pathv[path][next_index]; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); @@ -406,6 +406,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) times.push_back(time1); times.push_back(time2); Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { @@ -432,7 +433,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 71c69c6c5..8c86f64ca 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -356,10 +356,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(pathv[path_index][curve_index].initialPoint()); } _pparam->_vector[path_index][curve_index] = satellite; - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } Geom::Point FilletChamferKnotHolderEntity::knot_get() const @@ -391,7 +388,6 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } this->knot->show(); if (is_mirror) { - tmp_point = satellite.getPosition(pathv[path_index][curve_index]); gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; @@ -418,6 +414,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const tmp_point = satellite.getPosition(pathv[path_index][curve_index]); } Geom::Point const canvas_point = tmp_point; + _pparam->updateCanvasIndicators(); return canvas_point; } -- cgit v1.2.3 From 6820ee49d69cd419c5e8d3c9de74b0552758c842 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 00:58:42 +0200 Subject: Fixes when moves a path (bzr r13645.1.163) --- src/live_effects/effect.cpp | 13 ++++++------- src/live_effects/lpe-fillet-chamfer.cpp | 24 +++++++++++------------- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/satellitesarray.cpp | 1 - 4 files changed, 18 insertions(+), 21 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 7b36e30f9..5ac5e2407 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -421,6 +421,9 @@ Effect::getSelectedNodes() { size_t counter = 0; std::vector result; + if (pathvector_before_effect.empty()){ + return result; + } for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { if ((!pathvector_before_effect[i].closed() && @@ -440,15 +443,11 @@ Effect::getSelectedNodes() bool Effect::isNodeSelected(Geom::Point const &node_point) const { - if (_selected_nodes_pos.size() > 0) { - using Geom::X; - using Geom::Y; - Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); + if (!_selected_nodes_pos.empty()) { for (std::vector::const_iterator i = _selected_nodes_pos.begin(); i != _selected_nodes_pos.end(); ++i) { - Geom::Point p = *i; - Geom::Point p2(node_point[X],node_point[Y]); - p2 *= transformCoordinate; + Geom::Point p = (*i); + Geom::Point p2(node_point[Geom::X],node_point[Geom::Y]); if (Geom::are_near(p, p2, 0.01)) { return true; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index c9d3d4afd..47b91bf03 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -258,26 +258,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 + Satellites satellites = _satellites_param.data(); + if(satellites.empty()) { + doOnApply(lpeItem); + satellites = _satellites_param.data(); + } if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); + size_t previous_number_nodes = _pathvector_satellites->getTotalSatellites(); if (number_nodes != previous_number_nodes) { Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); satellite.setHidden(_hide_knots); _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); - _pathvector_satellites->setSelected(getSelectedNodes()); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); - refreshKnots(); - return; + satellites = _pathvector_satellites->getSatellites(); } } - Satellites satellites = _satellites_param.data(); - if(satellites.empty()) { - doOnApply(lpeItem); - satellites = _satellites_param.data(); - } if (_degenerate_hide) { _satellites_param.setGlobalKnotHide(true); } else { @@ -311,7 +308,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = _hide_knots; } } - _pathvector_satellites = new PathVectorSatellites(); + if (!_pathvector_satellites) { + _pathvector_satellites = new PathVectorSatellites(); + } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); _pathvector_satellites->setSelected(getSelectedNodes()); @@ -378,8 +377,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Curve const &curve_it2 = pathv[path][next_index]; Satellite satellite = satellites[path][next_index]; - if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint()) || - Geom::are_near(curve_it2.initialPoint(), curve_it2.finalPoint())) { + if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint())) { _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 134886950..d3f437afd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -16,6 +16,7 @@ #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "helper/geom-pathvectorsatellites.h" +#include "helper/geom-satellite.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8c86f64ca..d4182d459 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -81,7 +81,6 @@ void SatellitesArrayParam::setHelperSize(int hs) void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!_last_pathvector_satellites) { return; } -- cgit v1.2.3 From 417ba16c9f42a5476045ca4f1825fff2fed518ba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 03:30:10 +0200 Subject: Organize doeffect function (bzr r13645.1.164) --- src/live_effects/lpe-fillet-chamfer.cpp | 87 ++++++++++++-------------- src/live_effects/parameter/array.cpp | 2 +- src/live_effects/parameter/satellitesarray.cpp | 26 ++++---- 3 files changed, 53 insertions(+), 62 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 47b91bf03..268e08921 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -259,7 +259,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 Satellites satellites = _satellites_param.data(); - if(satellites.empty()) { + if (satellites.empty()) { doOnApply(lpeItem); satellites = _satellites_param.data(); } @@ -290,7 +290,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (satellites[i][j].is_time != _flexible) { satellites[i][j].is_time = _flexible; double amount = satellites[i][j].amount; - if (pathv[i].size() == j){ + if (pathv[i].size() == j) { continue; } Geom::Curve const &curve_in = pathv[i][j]; @@ -367,6 +367,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve == pathv[path].size() - 1 && pathv[path].closed()) { next_index = 0; } + //append last extreme of paths on open paths if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); @@ -389,7 +390,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) time0 = satellites[path][0].time(*curve_it1); } } - bool last = pathv[path].size() - 1 == curve; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); @@ -399,70 +399,61 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time2 > 1) { time2 = 1; } - std::vector times; - times.push_back(time0); - times.push_back(time1); - times.push_back(time2); - Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); - Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); + Geom::Curve *knot_curve_1 = curve_it1->portion(time0, time1); + Geom::Curve *knot_curve_2 = curve_it2.portion(time2, 1); if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { - tmp_path.start((*curve_it1).pointAt(times[0])); + tmp_path.start((*curve_it1).pointAt(time0)); } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2.pointAt(times[2]); - if (times[2] == 1) { - end_arc_point = curve_it2.pointAt(times[2] - GAP_HELPER); + Geom::Point end_arc_point = curve_it2.pointAt(time2); + //add a gap helper + if (time2 == 1) { + end_arc_point = curve_it2.pointAt(time2 - GAP_HELPER); } - if (times[1] == times[0]) { - start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); + if (time1 == time0) { + start_arc_point = curve_it1->pointAt(time1 + GAP_HELPER); } + double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2.initialPoint()) * K; - Geom::CubicBezier const *cubic_1 = - dynamic_cast(&*knot_curve_1); + double k2 = distance(curve_it2.initialPoint(), end_arc_point) * K; + Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); + Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; - if (time0 == 1) { - handle_1 = start_arc_point; - } - Geom::CubicBezier const *cubic_2 = - dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); - - bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, - end_arc_point - start_arc_point) < 0; + bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, end_arc_point - start_arc_point) < 0; double angle = angle_between(ray_1, ray_2, ccw_toggle); - double handleAngle = ray_1.angle() - angle; + double handle_angle_1 = ray_1.angle() - angle; + double handle_angle_2 = ray_2.angle() + angle; if (ccw_toggle) { - handleAngle = ray_1.angle() + angle; + handle_angle_1 = ray_1.angle() + angle; + handle_angle_2 = ray_2.angle() - angle; } - Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); + Geom::Point inverse_handle_1 = Geom::Point::polar(handle_angle_1, k1) + start_arc_point; + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handle_angle_2, k2); if (time0 == 1) { + handle_1 = start_arc_point; inverse_handle_1 = start_arc_point; } - handleAngle = ray_2.angle() + angle; - if (ccw_toggle) { - handleAngle = ray_2.angle() - angle; - } - Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); - if (times[2] == 1) { - end_arc_point = curve_it2.pointAt(times[2]); + //remove gap helper + if (time2 == 1) { + end_arc_point = curve_it2.pointAt(time2); } - if (times[1] == times[0]) { - start_arc_point = curve_it1->pointAt(times[0]); + if (time1 == time0) { + start_arc_point = curve_it1->pointAt(time0); } - if (times[1] != 1) { - if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { + if (time1 != 1) { + if (time1 != time0 || (time1 == 1 && time0 == 1)) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } @@ -474,7 +465,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && @@ -531,11 +522,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.append(*knot_curve_1); } } - if (path_it->closed() && last) { - tmp_path.close(); - } curve++; - time0 = times[2]; + time0 = time2; + } + if (path_it->closed()) { + tmp_path.close(); } path++; path_out.push_back(tmp_path); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 28867def2..7470f54cd 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -59,7 +59,7 @@ ArrayParam >::readsvg(const gchar * str) gchar ** iter = strarray; while (*iter != NULL) { gchar ** strsubarray = g_strsplit(*iter, ",", 8); - if(*strsubarray[7]){//steps always > 0 + if (*strsubarray[7]) {//steps always > 0 Satellite *satellite = new Satellite(); satellite->setSatelliteType(g_strstrip(strsubarray[0])); satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index d4182d459..4705fd821 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -85,7 +85,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) return; } - if(!_hp.empty()) { + if (!_hp.empty()) { _hp.clear(); } Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); @@ -112,10 +112,10 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); gint previous_index = j - 1; //Always are previous index because we skip first satellite on open paths - if(j == 0 && pathv[i].closed()){ + if (j == 0 && pathv[i].closed()) { previous_index = pathv[i].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } double lenght_in = pathv.curveAt(previous_index).length(); @@ -188,7 +188,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) } } } - if(!_knot_reset_helper.empty()){ + if (!_knot_reset_helper.empty()) { _hp.insert(_hp.end(), _knot_reset_helper.begin(), _knot_reset_helper.end() ); } if (mirror) { @@ -314,10 +314,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } Geom::Curve const &curve_in = pathv[path_index][previous_index]; @@ -346,7 +346,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, satellite.setPosition(s, pathv[path_index][curve_index]); } _pparam->_knot_reset_helper.clear(); - if (satellite.amount == 0){ + if (satellite.amount == 0) { char const *svgd; svgd = "M -5.39,8.78 -9.13,5.29 -10.38,10.28 Z M -7.22,7.07 -3.43,3.37 m -1.95,-12.16 -3.74,3.5 -1.26,-5 z " "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " @@ -388,10 +388,10 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const this->knot->show(); if (is_mirror) { gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Curve const &curve_in = pathv[path_index][previous_index]; @@ -490,10 +490,10 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } else if (state & GDK_SHIFT_MASK) { double amount = _pparam->_vector[path_index][curve_index].amount; gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { @@ -543,10 +543,10 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); -- cgit v1.2.3 From 30e74d438ef362634967a47053ecf27fb950e340 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 2 Jul 2016 02:27:56 +0200 Subject: Fix bug #1598009 regression on path parameter Fixed bugs: - https://launchpad.net/bugs/1598009 (bzr r15004) --- src/live_effects/parameter/path.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index bed191e83..f0c494267 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -237,7 +237,6 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) r.role = SHAPE_ROLE_LPE_PARAM; r.edit_transform = item->i2dt_affine(); // TODO is it right? - r.edit_transform *= item->transform.inverse(); if (!href) { r.item = reinterpret_cast(param_effect->getLPEObj()); r.lpe_key = param_key; @@ -458,8 +457,7 @@ PathParam::paste_param_path(const char *svgd) SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); if (item != NULL) { Geom::PathVector path_clipboard = sp_svg_read_pathv(svgd); - path_clipboard *= item->i2doc_affine().inverse() * item->transform; - path_clipboard *= Geom::Translate(path_clipboard.initialPoint() - _pathvector.initialPoint()).inverse(); + path_clipboard *= item->i2doc_affine().inverse(); svgd = sp_svg_write_path( path_clipboard ); } -- cgit v1.2.3 From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/live_effects/lpe-perspective_path.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index c8cdd7912..c62ead2b3 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -107,12 +107,12 @@ void LPEPerspectivePath::refresh(Gtk::Entry* perspective) { perspectiveID = perspective->get_text(); Persp3D *first = 0; Persp3D *persp = 0; - for ( SPObject *child = this->lpeobj->document->getDefs()->firstChild(); child && !persp; child = child->getNext() ) { - if (SP_IS_PERSP3D(child) && first == 0) { - first = SP_PERSP3D(child); + for (auto& child: lpeobj->document->getDefs()->_children) { + if (SP_IS_PERSP3D(&child) && first == 0) { + first = SP_PERSP3D(&child); } - if (SP_IS_PERSP3D(child) && strcmp(child->getId(), const_cast(perspectiveID.c_str())) == 0) { - persp = SP_PERSP3D(child); + if (SP_IS_PERSP3D(&child) && strcmp(child.getId(), const_cast(perspectiveID.c_str())) == 0) { + persp = SP_PERSP3D(&child); break; } } -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/live_effects/lpe-perspective_path.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index c62ead2b3..049e10f0f 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -107,7 +107,7 @@ void LPEPerspectivePath::refresh(Gtk::Entry* perspective) { perspectiveID = perspective->get_text(); Persp3D *first = 0; Persp3D *persp = 0; - for (auto& child: lpeobj->document->getDefs()->_children) { + for (auto& child: lpeobj->document->getDefs()->children) { if (SP_IS_PERSP3D(&child) && first == 0) { first = SP_PERSP3D(&child); } -- cgit v1.2.3 From e7afb49bd67284227bf5df1df22f9993b1bfa581 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 21 Jul 2016 21:05:55 +0200 Subject: =?UTF-8?q?This=20for=20you=20CR=20=C2=B7=20Measure=20line,=20show?= =?UTF-8?q?=20the=20distance=20on=20rect=20lines=20CAD=20like=20with=20aut?= =?UTF-8?q?o=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (bzr r15017.1.1) --- src/live_effects/CMakeLists.txt | 4 + src/live_effects/Makefile_insert | 2 + src/live_effects/effect-enum.h | 1 + src/live_effects/effect.cpp | 6 ++ src/live_effects/lpe-measure-line.cpp | 45 +++++++++++ src/live_effects/lpe-measure-line.h | 48 ++++++++++++ src/live_effects/parameter/texttopath.cpp | 125 ++++++++++++++++++++++++++++++ src/live_effects/parameter/texttopath.h | 87 +++++++++++++++++++++ 8 files changed, 318 insertions(+) create mode 100644 src/live_effects/lpe-measure-line.cpp create mode 100644 src/live_effects/lpe-measure-line.h create mode 100644 src/live_effects/parameter/texttopath.cpp create mode 100644 src/live_effects/parameter/texttopath.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 9a2f06a76..ed66dd2d9 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -27,6 +27,7 @@ set(live_effects_SRC lpe-lattice.cpp lpe-lattice2.cpp lpe-line_segment.cpp + lpe-measure-line.cpp lpe-mirror_symmetry.cpp lpe-offset.cpp lpe-parallel.cpp @@ -68,6 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp + parameter/texttopath.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -105,6 +107,7 @@ set(live_effects_SRC lpe-lattice.h lpe-lattice2.h lpe-line_segment.h + lpe-measure-line.h lpe-mirror_symmetry.h lpe-offset.h lpe-parallel.h @@ -148,6 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h + parameter/texttopath.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index b5bee55c8..d227d379d 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -70,6 +70,8 @@ ink_common_sources += \ live_effects/lpe-perspective_path.h \ live_effects/lpe-perspective-envelope.cpp \ live_effects/lpe-perspective-envelope.h \ + live_effects/lpe-measure-line.cpp \ + live_effects/lpe-measure-line.h \ live_effects/lpe-mirror_symmetry.cpp \ live_effects/lpe-mirror_symmetry.h \ live_effects/lpe-circle_3pts.cpp \ diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index eea26184c..3682aa1bd 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -36,6 +36,7 @@ enum EffectType { CONSTRUCT_GRID, PERP_BISECTOR, TANGENT_TO_CURVE, + MEASURE_LINE, MIRROR_SYMMETRY, CIRCLE_3PTS, TRANSFORM_2PTS, diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1868ca43b..d01312ca7 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -40,6 +40,7 @@ #include "live_effects/lpe-lattice2.h" #include "live_effects/lpe-lattice.h" #include "live_effects/lpe-line_segment.h" +#include "live_effects/lpe-measure-line.h" #include "live_effects/lpe-mirror_symmetry.h" #include "live_effects/lpe-offset.h" #include "live_effects/lpe-parallel.h" @@ -151,6 +152,8 @@ const Util::EnumData 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"}, +/* 9.93 */ + {MEASURE_LINE, N_("Measure Line"), "measure-line"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -319,6 +322,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case TRANSFORM_2PTS: neweffect = static_cast ( new LPETransform2Pts(lpeobj) ); break; + case MEASURE_LINE: + neweffect = static_cast ( new LPEMeasureLine(lpeobj) ); + break; default: g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp new file mode 100644 index 000000000..d6fe02afd --- /dev/null +++ b/src/live_effects/lpe-measure-line.cpp @@ -0,0 +1,45 @@ +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/lpe-measure-line.h" + +// TODO due to internal breakage in glibmm headers, this must be last: +#include + +using namespace Geom; +namespace Inkscape { +namespace LivePathEffect { + +LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") +{ + registerParameter(&text); +} + +LPEMeasureLine::~LPEMeasureLine() {} + +Geom::PathVector +LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) +{ + return path_in; +} + +}; //namespace LivePathEffect +}; /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offset:((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-measure-line.h b/src/live_effects/lpe-measure-line.h new file mode 100644 index 000000000..5ba1ff8c6 --- /dev/null +++ b/src/live_effects/lpe-measure-line.h @@ -0,0 +1,48 @@ +#ifndef INKSCAPE_LPE_MEASURE_LINE_H +#define INKSCAPE_LPE_MEASURE_LINE_H + +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include "live_effects/parameter/texttopath.h" +#include "live_effects/effect.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEMeasureLine : public Effect { +public: + LPEMeasureLine(LivePathEffectObject *lpeobject); + virtual ~LPEMeasureLine(); + + virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + +private: + + TextToPathParam text; + + LPEMeasureLine(const LPEMeasureLine &); + LPEMeasureLine &operator=(const LPEMeasureLine &); + +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif + +/* + 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/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp new file mode 100644 index 000000000..8625e4d71 --- /dev/null +++ b/src/live_effects/parameter/texttopath.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) Maximilian Albert 2008 + * + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/registered-widget.h" +#include + +#include "live_effects/parameter/texttopath.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 "display/canvas-text.h" + +#include <2geom/sbasis-geometric.h> + +namespace Inkscape { + +namespace LivePathEffect { + +TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); +} + +void +TextToPathParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +TextToPathParam::setPos(Geom::Point pos) +{ + sp_canvastext_set_coords (canvas_text, pos); +} + +void +TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool /*use_curvature*/) +{ + using namespace Geom; + + Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); + double t_reparam = pwd2_reparam.cuts.back() * t; + Point pos = pwd2_reparam.valueAt(t_reparam); + Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); + Point n = -rot90(dir); + double angle = Geom::angle_between(dir, Point(1,0)); + + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); +} + +void +TextToPathParam::setAnchor(double x_value, double y_value) +{ + anchor_x = x_value; + anchor_y = y_value; + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); +} + +bool +TextToPathParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +TextToPathParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +TextToPathParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + + rsu->setText(value.c_str()); + rsu->setProgrammatically = false; + + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); + + return dynamic_cast (rsu); +} + +void +TextToPathParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; + + sp_canvastext_set_text (canvas_text, newvalue.c_str()); +} + +} /* 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/texttopath.h b/src/live_effects/parameter/texttopath.h new file mode 100644 index 000000000..9a0ee38e2 --- /dev/null +++ b/src/live_effects/parameter/texttopath.h @@ -0,0 +1,87 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "display/canvas-bpath.h" +#include "live_effects/parameter/parameter.h" + +struct SPCanvasText; + +namespace Inkscape { + +namespace LivePathEffect { + +class TextToPathParam : public Parameter { +public: + TextToPathParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~TextToPathParam() {} + + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + virtual void param_set_default(); + void setPos(Geom::Point pos); + void setPosAndAnchor(const Geom::Piecewise > &pwd2, + const double t, const double length, bool use_curvature = false); + void setAnchor(double x_value, double y_value); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + TextToPathParam(const TextToPathParam&); + TextToPathParam& operator=(const TextToPathParam&); + double anchor_x; + double anchor_y; + + Glib::ustring value; + Glib::ustring defvalue; + + SPCanvasText *canvas_text; +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class TextToPathParamInternal : public TextToPathParam { +public: + TextToPathParamInternal(Effect* effect) : + TextToPathParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + 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 : -- cgit v1.2.3 From 98d87665f4230cbd85df6b6c7d61be770ac6524a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 23 Jul 2016 20:53:24 +0200 Subject: Order and cleanup of some LPE (bzr r15020) --- src/live_effects/lpe-copy_rotate.cpp | 3 ++- src/live_effects/lpe-lattice2.cpp | 7 +++---- src/live_effects/lpe-lattice2.h | 2 +- src/live_effects/lpe-mirror_symmetry.cpp | 5 ++--- src/live_effects/lpe-mirror_symmetry.h | 2 +- src/live_effects/lpe-roughen.cpp | 6 +++--- src/live_effects/lpe-roughen.h | 1 + src/live_effects/lpe-show_handles.cpp | 4 ++-- src/live_effects/lpe-show_handles.h | 2 +- src/live_effects/lpe-simplify.cpp | 5 ++--- src/live_effects/lpe-simplify.h | 2 +- 11 files changed, 19 insertions(+), 20 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index efea76039..80f5bdafd 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -11,7 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> @@ -22,6 +21,8 @@ #include "knot-holder-entity.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 0c403daec..bacbe5fa7 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -17,9 +17,6 @@ */ #include "live_effects/lpe-lattice2.h" - -#include - #include "sp-shape.h" #include "sp-item.h" #include "sp-path.h" @@ -36,6 +33,8 @@ #include <2geom/d2.h> #include <2geom/piecewise.h> #include <2geom/transforms.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; @@ -280,7 +279,7 @@ void LPELattice2::onExpanderChanged() { expanded = expander->get_expanded(); - if(expander->get_expanded()) { + if(expanded) { expander->set_label (Glib::ustring(_("Hide Points"))); } else { expander->set_label (Glib::ustring(_("Show Points"))); diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 8d0c18a3a..07bc4af86 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,8 +18,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/parameter/enum.h" -#include #include "live_effects/effect.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 9f3070ff4..cf866ad6a 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -13,9 +13,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include - #include "live_effects/lpe-mirror_symmetry.h" #include #include @@ -28,6 +25,8 @@ #include "knot-holder-entity.h" #include "knotholder.h" #include "inkscape.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 3a244cb7e..9e5b4d628 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -15,7 +15,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/point.h" diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 105fe2fc4..14137b043 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -13,16 +13,16 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include "desktop.h" #include "live_effects/lpe-roughen.h" +#include "desktop.h" #include "display/curve.h" #include "live_effects/parameter/parameter.h" #include #include "helper/geom.h" #include "sp-item-group.h" -#include #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index 44a723c89..c4be8fed7 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -12,6 +12,7 @@ #ifndef INKSCAPE_LPE_ROUGHEN_H #define INKSCAPE_LPE_ROUGHEN_H +#include #include "live_effects/parameter/enum.h" #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 0bc1c4f17..2d4666fe4 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -6,8 +6,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include -#include #include "live_effects/lpe-show_handles.h" #include "live_effects/parameter/parameter.h" #include <2geom/sbasis-to-bezier.h> @@ -16,6 +14,8 @@ #include "desktop-style.h" #include "style.h" #include "svg/svg.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 34390dd32..8bff3c1a8 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -8,7 +8,7 @@ * Copyright (C) Jabier Arraiza Cenoz 2014 * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" #include "live_effects/parameter/bool.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index f807bdc8d..b0c1fbc23 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -2,12 +2,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-simplify.h" #include "display/curve.h" #include "live_effects/parameter/parameter.h" -#include #include "helper/geom.h" #include "livarot/Path.h" #include "splivarot.h" @@ -21,6 +18,8 @@ #include <2geom/interval.h> #include "ui/icon-names.h" #include "util/units.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 294d77b35..8135561af 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -6,7 +6,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/parameter/togglebutton.h" #include "live_effects/lpegroupbbox.h" -- cgit v1.2.3 From 06caba8f2caeb07011e492d7218f0b8f6b28e801 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 17:05:29 +0200 Subject: Fises to toggle button and coding style (bzr r15021) --- src/live_effects/parameter/togglebutton.cpp | 70 +++++++++++++++-------------- src/live_effects/parameter/togglebutton.h | 8 ++-- 2 files changed, 41 insertions(+), 37 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 47a8b5615..c761731b7 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -24,10 +24,10 @@ 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, const Glib::ustring& inactive_label, - char const * icon_active, char const * icon_inactive, - Inkscape::IconSize icon_size) + char const * _icon_active, char const * _icon_inactive, + Inkscape::IconSize _icon_size) : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), - inactiveLabel(inactive_label), iconActive(icon_active), iconInactive(icon_inactive), iconSize(icon_size) + inactive_label(inactive_label), _icon_active(_icon_active), _icon_inactive(_icon_inactive), _icon_size(_icon_size) { checkwdg = NULL; } @@ -75,38 +75,40 @@ ToggleButtonParam::param_newWidget() param_effect->getRepr(), param_effect->getSPDoc()) ); #if GTK_CHECK_VERSION(3,0,0) - GtkWidget * boxButton = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous(GTK_BOX(boxButton), false); + GtkWidget * box_button = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_set_homogeneous(GTK_BOX(box_button), false); #else - GtkWidget * boxButton = gtk_hbox_new (false, 0); + GtkWidget * box_button = gtk_hbox_new (false, 0); #endif - GtkWidget * labelButton = gtk_label_new (""); + GtkWidget * label_button = gtk_label_new (""); if (!param_label.empty()) { - if(value || inactiveLabel.empty()){ - gtk_label_set_text(GTK_LABEL(labelButton), param_label.c_str()); + if(value || inactive_label.empty()){ + gtk_label_set_text(GTK_LABEL(label_button), param_label.c_str()); }else{ - gtk_label_set_text(GTK_LABEL(labelButton), inactiveLabel.c_str()); + gtk_label_set_text(GTK_LABEL(label_button), inactive_label.c_str()); } } - gtk_widget_show(labelButton); - if ( iconActive ) { - if(!iconInactive){ - iconInactive = iconActive; + gtk_widget_show(label_button); + if ( _icon_active ) { + if(!_icon_inactive){ + _icon_inactive = _icon_active; } - gtk_widget_show(boxButton); - GtkWidget *iconButton = sp_icon_new(iconSize, iconActive); + gtk_widget_show(box_button); + GtkWidget *icon_button = NULL; if(!value){ - iconButton = sp_icon_new(iconSize, iconInactive); + icon_button = sp_icon_new(_icon_size, _icon_inactive); + } else { + icon_button = sp_icon_new(_icon_size, _icon_active); } - gtk_widget_show(iconButton); - gtk_box_pack_start (GTK_BOX(boxButton), iconButton, false, false, 1); + gtk_widget_show(icon_button); + gtk_box_pack_start (GTK_BOX(box_button), icon_button, false, false, 1); if (!param_label.empty()) { - gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); + gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1); } }else{ - gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); + gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1); } - checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); + checkwdg->add(*Gtk::manage(Glib::wrap(box_button))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); @@ -126,25 +128,27 @@ ToggleButtonParam::refresh_button() if(!checkwdg){ return; } - Gtk::Widget * boxButton = checkwdg->get_child(); - if(!boxButton){ + Gtk::Widget * box_button = checkwdg->get_child(); + if(!box_button){ return; } - GList * childs = gtk_container_get_children(GTK_CONTAINER(boxButton->gobj())); - guint totalWidgets = g_list_length (childs); + GList * childs = gtk_container_get_children(GTK_CONTAINER(box_button->gobj())); + guint total_widgets = g_list_length (childs); if (!param_label.empty()) { - if(value || inactiveLabel.empty()){ - gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, totalWidgets-1)), param_label.c_str()); + if(value || inactive_label.empty()){ + gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, total_widgets-1)), param_label.c_str()); }else{ - gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, totalWidgets-1)), inactiveLabel.c_str()); + gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, total_widgets-1)), inactive_label.c_str()); } } - if ( iconActive ) { - GdkPixbuf * iconPixbuf = sp_pixbuf_new( iconSize, iconActive ); + if ( _icon_active ) { + GdkPixbuf * icon_pixbuf = NULL; if(!value){ - iconPixbuf = sp_pixbuf_new( iconSize, iconInactive); + icon_pixbuf = sp_pixbuf_new( _icon_size, _icon_inactive ); + } else { + icon_pixbuf = sp_pixbuf_new( _icon_size, _icon_active ); } - gtk_image_set_from_pixbuf (GTK_IMAGE(g_list_nth_data(childs, 0)), iconPixbuf); + gtk_image_set_from_pixbuf (GTK_IMAGE(g_list_nth_data(childs, 0)), icon_pixbuf); } } diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 4e545bcfd..8390fec86 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -59,10 +59,10 @@ private: void refresh_button(); bool value; bool defvalue; - const Glib::ustring inactiveLabel; - const char * iconActive; - const char * iconInactive; - Inkscape::IconSize iconSize; + const Glib::ustring inactive_label; + const char * _icon_active; + const char * _icon_inactive; + Inkscape::IconSize _icon_size; Inkscape::UI::Widget::RegisteredToggleButton * checkwdg; sigc::signal _signal_toggled; -- cgit v1.2.3 From 325f658295ffa45c23c681a6a96a76acf232ef29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 17:58:34 +0200 Subject: Fixed a bug on roughen LPE on open paths (bzr r15022) --- src/live_effects/lpe-roughen.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 14137b043..13f2b7b51 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -229,7 +229,7 @@ void LPERoughen::doEffect(SPCurve *curve) nCurve->lineto(curve_it1->finalPoint()); } last_move = Geom::Point(0, 0); - double length = curve_it1->length(0.001); + double length = curve_it1->length(0.01); std::size_t splits = 0; if (method == DM_SEGMENTS) { splits = segments; @@ -354,9 +354,6 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point point_a3 = seg1[3] + point_a3; ray.setPoints(prev,A->initialPoint()); point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); - if(prev == Geom::Point(0,0)){ - point_a1 = randomize(max_lenght); - } if(last){ Geom::Path b2(point_b3); b2.appendNew(point_a3); -- cgit v1.2.3 From a5d6c9a27683820be3d84eea73c2d6f161ce0e8e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 18:49:11 +0200 Subject: Add Text tag and update widgets code (bzr r15017.1.2) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/effect.cpp | 3 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-measure-line.cpp | 91 +++++++++++++++++++- src/live_effects/lpe-measure-line.h | 15 ++-- src/live_effects/lpe-transform_2pts.cpp | 1 - src/live_effects/parameter/font.cpp | 126 ++++++++++++++++++++++++++++ src/live_effects/parameter/font.h | 77 +++++++++++++++++ src/live_effects/parameter/point.cpp | 2 +- src/live_effects/parameter/point.h | 1 - src/live_effects/parameter/texttopath.cpp | 125 --------------------------- src/live_effects/parameter/texttopath.h | 87 ------------------- src/live_effects/parameter/togglebutton.cpp | 8 ++ 13 files changed, 315 insertions(+), 226 deletions(-) create mode 100644 src/live_effects/parameter/font.cpp create mode 100644 src/live_effects/parameter/font.h delete mode 100644 src/live_effects/parameter/texttopath.cpp delete mode 100644 src/live_effects/parameter/texttopath.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index ed66dd2d9..c3d740862 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/texttopath.cpp + parameter/font.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/texttopath.h + parameter/font.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d01312ca7..a62e8b62b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -370,6 +370,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), + upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -697,7 +698,7 @@ Effect::newWidget() ++it; } - + upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..e0a7cbe6b 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -122,6 +122,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; + bool upd_params; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d6fe02afd..7b823b072 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include "inkscape.h" +#include "uri.h" +#include "uri-references.h" +#include "desktop.h" +#include "document.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -17,16 +22,98 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") { - registerParameter(&text); + registerParameter(&fontselector); + rtext = NULL; + fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) +{ + if (SP_ACTIVE_DESKTOP) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + std::stringstream lenghtstr; + lenghtstr.imbue(std::locale::classic()); + lenghtstr << lenght; + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lenghtstr.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + text_obj->updateRepr(); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { + lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); return path_in; } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 5ba1ff8c6..7e576ffe6 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,8 +9,11 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/texttopath.h" +#include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include +#include "xml/node.h" + namespace Inkscape { namespace LivePathEffect { @@ -19,13 +22,13 @@ class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); - + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - private: - - TextToPathParam text; - + double lenght; + FontParam fontselector; + Inkscape::FontLister *fontlister; + Inkscape::XML::Node *rtext; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..d32cf42fc 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -90,7 +90,6 @@ LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - point_a = Point(boundingbox_X.min(), boundingbox_Y.middle()); point_b = Point(boundingbox_X.max(), boundingbox_Y.middle()); SPLPEItem * splpeitem = const_cast(lpeitem); diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp new file mode 100644 index 000000000..174b66152 --- /dev/null +++ b/src/live_effects/parameter/font.cpp @@ -0,0 +1,126 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/font.h" +#include "live_effects/effect.h" +#include "ui/widget/font-selector.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontParam::param_set_default() +{ + param_setValue(defvalue); +} + + +Glib::ustring +FontParam::param_readFontSpec(const gchar * strvalue) +{ + Glib::ustring result; + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + result = (Glib::ustring)strarray[0]; + g_strfreev (strarray); + return result; + } + } + g_strfreev (strarray); + return result; +} + +double +FontParam::param_readFontSize(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize = 0; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + g_strfreev (strarray); + return fontsize; + } + } + g_strfreev (strarray); + return fontsize; +} + +bool +FontParam::param_readSVGValue(const gchar * strvalue) +{ + double fontsize = param_readFontSize(strvalue); + Glib::ustring fontspec = param_readFontSpec(strvalue); + Inkscape::SVGOStringStream os; + os << fontspec << " @ " << fontsize; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontSelector( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + double fontsize = param_readFontSize(param_getSVGValue()); + Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); + fontselectorwdg->setValue( fontspec, fontsize ); + fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); + + return dynamic_cast (fontselectorwdg); +} + +void +FontParam::param_setValue(const Glib::ustring 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/font.h b/src/live_effects/parameter/font.h new file mode 100644 index 000000000..e7bcc59d2 --- /dev/null +++ b/src/live_effects/parameter/font.h @@ -0,0 +1,77 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontParam : public Parameter { +public: + FontParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + double param_readFontSize(const gchar * strvalue); + Glib::ustring param_readFontSpec(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontParam(const FontParam&); + FontParam& operator=(const FontParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +/* + * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas + * text that should not be settable by the user. Note that since no widget is provided, the + * parameter must be initialized differently than usual (only with a pointer to the parent effect; + * no label, no tooltip, etc.). + */ +class FontParamInternal : public FontParam { +public: + FontParamInternal(Effect* effect) : + FontParam("", "", "", NULL, effect) {} + + virtual Gtk::Widget * param_newWidget() { return NULL; } +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + 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/point.cpp b/src/live_effects/parameter/point.cpp index ca3471b29..b4f2c7758 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -134,7 +134,7 @@ PointParam::param_newWidget() Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); - + param_effect->upd_params = false; return dynamic_cast (hbox); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 4329e0bcd..06773c80e 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,7 +11,6 @@ #include #include <2geom/point.h> - #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp deleted file mode 100644 index 8625e4d71..000000000 --- a/src/live_effects/parameter/texttopath.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) Maximilian Albert 2008 - * - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/registered-widget.h" -#include - -#include "live_effects/parameter/texttopath.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 "display/canvas-text.h" - -#include <2geom/sbasis-geometric.h> - -namespace Inkscape { - -namespace LivePathEffect { - -TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); -} - -void -TextToPathParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -TextToPathParam::setPos(Geom::Point pos) -{ - sp_canvastext_set_coords (canvas_text, pos); -} - -void -TextToPathParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool /*use_curvature*/) -{ - using namespace Geom; - - Piecewise > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); - double t_reparam = pwd2_reparam.cuts.back() * t; - Point pos = pwd2_reparam.valueAt(t_reparam); - Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); - Point n = -rot90(dir); - double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); -} - -void -TextToPathParam::setAnchor(double x_value, double y_value) -{ - anchor_x = x_value; - anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); -} - -bool -TextToPathParam::param_readSVGValue(const gchar * strvalue) -{ - param_setValue(strvalue); - return true; -} - -gchar * -TextToPathParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -TextToPathParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( - param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); - rsu->setProgrammatically = false; - - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - - return dynamic_cast (rsu); -} - -void -TextToPathParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); -} - -} /* 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/texttopath.h b/src/live_effects/parameter/texttopath.h deleted file mode 100644 index 9a0ee38e2..000000000 --- a/src/live_effects/parameter/texttopath.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "display/canvas-bpath.h" -#include "live_effects/parameter/parameter.h" - -struct SPCanvasText; - -namespace Inkscape { - -namespace LivePathEffect { - -class TextToPathParam : public Parameter { -public: - TextToPathParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~TextToPathParam() {} - - virtual Gtk::Widget * param_newWidget(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - virtual void param_set_default(); - void setPos(Geom::Point pos); - void setPosAndAnchor(const Geom::Piecewise > &pwd2, - const double t, const double length, bool use_curvature = false); - void setAnchor(double x_value, double y_value); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - TextToPathParam(const TextToPathParam&); - TextToPathParam& operator=(const TextToPathParam&); - double anchor_x; - double anchor_y; - - Glib::ustring value; - Glib::ustring defvalue; - - SPCanvasText *canvas_text; -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class TextToPathParamInternal : public TextToPathParam { -public: - TextToPathParamInternal(Effect* effect) : - TextToPathParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - 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.cpp b/src/live_effects/parameter/togglebutton.cpp index 47a8b5615..5977a5114 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -12,6 +12,7 @@ #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" +#include "selection.h" #include "widgets/icon.h" #include "inkscape.h" #include "verbs.h" @@ -106,6 +107,7 @@ ToggleButtonParam::param_newWidget() }else{ gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); } + param_effect->upd_params = false; checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; @@ -157,6 +159,12 @@ ToggleButtonParam::param_setValue(bool newvalue) void ToggleButtonParam::toggled() { + //Force redraw for update widgets + param_effect->upd_params = true; + if (SP_ACTIVE_DESKTOP) { + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection ->emitModified(); + } _signal_toggled.emit(); } -- cgit v1.2.3 From 066d5189a44b52d9bb4f75633e6748b73bfc2a8a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 19:00:29 +0200 Subject: Fix a var name bug (bzr r15017.1.4) --- src/live_effects/parameter/togglebutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index b30a5a3d2..dd1717b40 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -110,7 +110,7 @@ ToggleButtonParam::param_newWidget() gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1); } - checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); + checkwdg->add(*Gtk::manage(Glib::wrap(box_button))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); -- cgit v1.2.3 From c6c1a5740f4778826030b6b724063d757a7cc603 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 24 Jul 2016 19:27:32 +0200 Subject: Order some headers (bzr r15023) --- src/live_effects/lpe-lattice2.h | 2 +- src/live_effects/lpe-roughen.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 07bc4af86..4a025d182 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -19,8 +19,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include -#include "live_effects/parameter/enum.h" #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index c4be8fed7..dbdb91e62 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -13,8 +13,8 @@ #define INKSCAPE_LPE_ROUGHEN_H #include -#include "live_effects/parameter/enum.h" #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/bool.h" -- cgit v1.2.3 From 10790202dbd81463005cc3ae7cdb6f2068003adb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 25 Jul 2016 01:43:33 +0200 Subject: Add strore parameters (bzr r15017.1.5) --- src/live_effects/lpe-measure-line.cpp | 265 ++++++++++++++++++++++--------- src/live_effects/lpe-measure-line.h | 18 ++- src/live_effects/parameter/bool.cpp | 6 + src/live_effects/parameter/bool.h | 2 +- src/live_effects/parameter/font.cpp | 7 +- src/live_effects/parameter/font.h | 1 + src/live_effects/parameter/parameter.cpp | 7 + src/live_effects/parameter/parameter.h | 1 + src/live_effects/parameter/point.cpp | 4 +- src/live_effects/parameter/point.h | 2 +- src/live_effects/parameter/unit.cpp | 6 + src/live_effects/parameter/unit.h | 1 + 12 files changed, 239 insertions(+), 81 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 7b823b072..dc5d856cf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,13 @@ #include "inkscape.h" #include "uri.h" #include "uri-references.h" +#include "preferences.h" +#include "util/units.h" +#include "svg/svg-length.h" +#include "display/curve.h" +#include "sp-root.h" +#include "sp-shape.h" +#include "sp-path.h" #include "desktop.h" #include "document.h" @@ -22,99 +29,209 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + pos(0,0), + angle(0) { registerParameter(&fontselector); + registerParameter(&scale); + registerParameter(&precision); + registerParameter(&unit); + registerParameter(&reverse); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); + precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); + reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); rtext = NULL; + precision.param_set_range(0, 100); + precision.param_set_increments(1, 1); + precision.param_set_digits(0); + precision.param_make_integer(true); fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) +{ + if (!SP_IS_SHAPE(lpeitem)) { + g_warning("LPE measure line can only be applied to shapes (not groups)."); + SPLPEItem * item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { - if (SP_ACTIVE_DESKTOP) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", 0); - sp_repr_set_svg_double(rtext, "y", 0); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + SPLPEItem * splpeitem = const_cast(lpeitem); + SPPath *sp_path = dynamic_cast(splpeitem); + if (sp_path) { + Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (SP_ACTIVE_DESKTOP) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + angle = ray.angle(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + Geom::Point newpos = pos - Point::polar(angle_cross, 10); + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.imbue(std::locale::classic()); + length_str << "%." << precision << "f %s"; + gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lengthchar); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lengthchar); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine; + text_obj->updateRepr(); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - std::stringstream lenghtstr; - lenghtstr.imbue(std::locale::classic()); - lenghtstr << lenght; - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(lenghtstr.str().c_str()); - } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } +} + +Gtk::Widget *LPEMeasureLine::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(6); + + std::vector::iterator it = param_vector.begin(); + Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + 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); + } + } } - text_obj->updateRepr(); + + ++it; } + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); + button1->pack_start(*save_default, true, true, 2); + vbox->pack_start(*button1, true, true, 2); + return dynamic_cast(vbox); } Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); - return path_in; + + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + Geom::Path path; + Geom::Point s = path_in.initialPoint(); + Geom::Point e = path_in.finalPoint(); + path.start( s ); + path.appendNew( e ); + Geom::PathVector output; + output.push_back(path); + return output; +} + +void +LPEMeasureLine::saveDefault() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setDouble("/live_effects/measure-line/scale", scale); + prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); + prefs->setInt("/live_effects/measure-line/reverse", reverse); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e576ffe6..3b05cb18c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,7 +11,13 @@ */ #include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include "live_effects/parameter/text.h" +#include "live_effects/parameter/unit.h" +#include "live_effects/parameter/bool.h" #include +#include <2geom/angle.h> +#include <2geom/ray.h> +#include <2geom/point.h> #include "xml/node.h" @@ -23,12 +29,22 @@ public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void saveDefault(); + virtual Gtk::Widget *newWidget(); private: - double lenght; + double length; FontParam fontselector; Inkscape::FontLister *fontlister; Inkscape::XML::Node *rtext; + Geom::Point pos; + Geom::Coord angle; + ScalarParam scale; + ScalarParam precision; + UnitParam unit; + BoolParam reverse; + Glib::ustring doc_unit; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 9ecadbdeb..af99ef362 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -36,6 +36,12 @@ BoolParam::param_set_default() param_setValue(defvalue); } +void +BoolParam::param_update_default(bool const default_value) +{ + defvalue = default_value; +} + bool BoolParam::param_readSVGValue(const gchar * strvalue) { diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 403dd0b87..7ad8a9368 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -36,7 +36,7 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); - + void param_update_default(bool const default_value); bool get_value() const { return value; }; inline operator bool() const { return value; }; diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp index 174b66152..8f89ee5c4 100644 --- a/src/live_effects/parameter/font.cpp +++ b/src/live_effects/parameter/font.cpp @@ -33,7 +33,10 @@ FontParam::param_set_default() { param_setValue(defvalue); } - +void +FontParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} Glib::ustring FontParam::param_readFontSpec(const gchar * strvalue) @@ -100,7 +103,7 @@ FontParam::param_newWidget() Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); fontselectorwdg->setValue( fontspec, fontsize ); fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - + param_effect->upd_params = false; return dynamic_cast (fontselectorwdg); } diff --git a/src/live_effects/parameter/font.h b/src/live_effects/parameter/font.h index e7bcc59d2..3909ea424 100644 --- a/src/live_effects/parameter/font.h +++ b/src/live_effects/parameter/font.h @@ -28,6 +28,7 @@ public: virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); double param_readFontSize(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); Glib::ustring param_readFontSpec(const gchar * strvalue); virtual gchar * param_getSVGValue() const; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index d4e213948..ae55c84e9 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -101,6 +101,12 @@ ScalarParam::param_set_default() param_set_value(defvalue); } +void +ScalarParam::param_update_default(gdouble default_value) +{ + defvalue = default_value; +} + void ScalarParam::param_set_value(gdouble val) { @@ -169,6 +175,7 @@ ScalarParam::param_newWidget() if(!overwrite_widget){ rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } + param_effect->upd_params = false; return dynamic_cast (rsu); } else { return NULL; diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 0ef28650a..8556b0d9a 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -110,6 +110,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); + void param_update_default(gdouble default_value); void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index b4f2c7758..90a5b252b 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -62,9 +62,9 @@ PointParam::param_get_default() const{ } void -PointParam::param_update_default(Geom::Point newpoint) +PointParam::param_update_default(const Geom::Point default_point) { - defvalue = newpoint; + defvalue = default_point; } void diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 06773c80e..d41e8a710 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -42,7 +42,7 @@ public: void param_set_default(); Geom::Point param_get_default() const; void param_set_liveupdate(bool live_update); - void param_update_default(Geom::Point newpoint); + void param_update_default(const Geom::Point default_point); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 0ee553e2c..b6ea99bfe 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -54,6 +54,12 @@ UnitParam::param_set_default() param_set_value(*defunit); } +void +UnitParam::param_update_default(const Glib::ustring default_unit) +{ + defunit = unit_table.getUnit(default_unit); +} + void UnitParam::param_set_value(Inkscape::Util::Unit const &val) { diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index 59a483018..ae58cf956 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -33,6 +33,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); + void param_update_default(const Glib::ustring default_unit); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); -- cgit v1.2.3 From d7bdf3ed2d198c0027babed217dfec32f5f4f389 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 26 Jul 2016 00:10:01 +0200 Subject: Add gap,offset,insensitive transforms, and delete on lpe remove (bzr r15017.1.6) --- src/live_effects/lpe-measure-line.cpp | 101 +++++++++++++++++++++++++++++++--- src/live_effects/lpe-measure-line.h | 8 +++ 2 files changed, 102 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index dc5d856cf..3d5cd8591 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -13,8 +13,12 @@ #include "preferences.h" #include "util/units.h" #include "svg/svg-length.h" +#include "svg/svg-color.h" #include "display/curve.h" +#include <2geom/affine.h> +#include "style.h" #include "sp-root.h" +#include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" #include "desktop.h" @@ -32,27 +36,57 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), + gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&scale); registerParameter(&precision); + registerParameter(&offset_right_left); + registerParameter(&offset_top_bottom); + registerParameter(&gap_start); + registerParameter(&gap_end); registerParameter(&unit); registerParameter(&reverse); + registerParameter(&color_as_line); + registerParameter(&scale_insensitive); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); + offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); + gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); + gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); + color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + offset_right_left.param_set_range(-999999.0, 999999.0); + offset_right_left.param_set_increments(1, 1); + offset_right_left.param_set_digits(2); + offset_top_bottom.param_set_range(-999999.0, 999999.0); + offset_top_bottom.param_set_increments(1, 1); + offset_top_bottom.param_set_digits(2); + gap_start.param_set_range(-999999.0, 999999.0); + gap_start.param_set_increments(1, 1); + gap_start.param_set_digits(2); + gap_end.param_set_range(-999999.0, 999999.0); + gap_end.param_set_increments(1, 1); + gap_end.param_set_digits(2); fontlister = Inkscape::FontLister::get_instance(); } @@ -75,21 +109,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); - if (SP_ACTIVE_DESKTOP) { + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); + length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - Geom::Point newpos = pos - Point::polar(angle_cross, 10); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -103,6 +138,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); /* Set style */ sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); @@ -126,7 +162,30 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } + } else { + sp_repr_css_unset_property (css, "#000000"); + } + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); Glib::ustring css_str; @@ -141,6 +200,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Inkscape::GC::release(rtspan); } /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.imbue(std::locale::classic()); @@ -165,12 +228,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); affine *= Geom::Rotate(angle); affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine; + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); text_obj->updateRepr(); } } } +void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -211,11 +286,17 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + s = s - Point::polar(angle, gap_start); + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + e = e - Point::polar(angle, gap_end); path.start( s ); path.appendNew( e ); Geom::PathVector output; @@ -230,8 +311,14 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); + prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); + prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); + prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); + prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 3b05cb18c..ba24aa404 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -30,6 +30,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -42,9 +43,16 @@ private: Geom::Coord angle; ScalarParam scale; ScalarParam precision; + ScalarParam offset_right_left; + ScalarParam offset_top_bottom; + ScalarParam gap_start; + ScalarParam gap_end; UnitParam unit; BoolParam reverse; + BoolParam color_as_line; + BoolParam scale_insensitive; Glib::ustring doc_unit; +/* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From bc46160cc69e4597d94ae6dd0c70428341a4d4f2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 00:55:05 +0200 Subject: Add optional linked path (bzr r15017.1.8) --- src/live_effects/lpe-measure-line.cpp | 58 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 8 ++++- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 3d5cd8591..638d60464 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -14,6 +14,7 @@ #include "util/units.h" #include "svg/svg-length.h" #include "svg/svg-color.h" +#include "svg/svg.h" #include "display/curve.h" #include <2geom/affine.h> #include "style.h" @@ -34,10 +35,13 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 10), + offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), unit(_("Unit:"), _("Unit"), "unit", &wr, this), @@ -48,6 +52,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : angle(0) { registerParameter(&fontselector); + registerParameter(&origin); + registerParameter(&curve_linked); + registerParameter(&line_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -63,9 +70,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 10.0)); - gap_start.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_start", 0.0)); - gap_end.param_update_default(prefs->getDouble("/live_effects/measure-line/gap_end", 0.0)); + offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -75,12 +81,20 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); + curve_linked.param_set_range(1, 999); + curve_linked.param_set_increments(1, 1); + curve_linked.param_set_digits(0); + curve_linked.param_make_integer(true); + precision.param_make_integer(true); offset_right_left.param_set_range(-999999.0, 999999.0); offset_right_left.param_set_increments(1, 1); offset_right_left.param_set_digits(2); offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); + line_offset.param_set_range(-999999.0, 999999.0); + line_offset.param_set_increments(1, 1); + line_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -110,9 +124,39 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Geom::Point s = pathvector.initialPoint(); Geom::Point e = pathvector.finalPoint(); - length = Geom::distance(path_in.initialPoint(), path_in.finalPoint()) * scale; + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + Geom::Ray ray(s,e); + angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, line_offset); + e = e - Point::polar(angle_cross, line_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } + length = Geom::distance(s, e) * scale; pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); angle = ray.angle(); @@ -125,7 +169,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -313,8 +356,7 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/gap_start", gap_start); - prefs->setDouble("/live_effects/measure-line/gap_end", gap_end); + prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setInt("/live_effects/measure-line/reverse", reverse); prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index ba24aa404..b03a44705 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,11 +9,13 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/font.h" + #include "live_effects/effect.h" +#include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/originalpath.h" #include #include <2geom/angle.h> #include <2geom/ray.h> @@ -41,12 +43,16 @@ private: Inkscape::XML::Node *rtext; Geom::Point pos; Geom::Coord angle; + OriginalPathParam origin; + ScalarParam curve_linked; + ScalarParam line_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; + size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; -- cgit v1.2.3 From f35bb1f74a0ffeb5c6477a25e3c4cde87a97bcf1 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 12:06:06 +0200 Subject: Removed unused includes, decrease compilation time (bzr r15025) --- src/live_effects/effect.cpp | 19 +------------------ src/live_effects/lpe-angle_bisector.cpp | 1 - src/live_effects/lpe-attach-path.cpp | 7 ------- src/live_effects/lpe-bendpath.cpp | 16 ---------------- src/live_effects/lpe-bounding-box.cpp | 4 ---- src/live_effects/lpe-circle_3pts.cpp | 1 - src/live_effects/lpe-circle_with_radius.cpp | 1 - src/live_effects/lpe-constructgrid.cpp | 3 --- src/live_effects/lpe-copy_rotate.cpp | 4 ---- src/live_effects/lpe-curvestitch.cpp | 8 -------- src/live_effects/lpe-dynastroke.cpp | 6 ------ src/live_effects/lpe-ellipse_5pts.cpp | 1 - src/live_effects/lpe-envelope.cpp | 14 -------------- src/live_effects/lpe-extrude.cpp | 5 ----- src/live_effects/lpe-fill-between-many.cpp | 3 --- src/live_effects/lpe-fill-between-strokes.cpp | 3 --- src/live_effects/lpe-fillet-chamfer.cpp | 5 ----- src/live_effects/lpe-gears.cpp | 5 ----- src/live_effects/lpe-interpolate.cpp | 3 --- src/live_effects/lpe-interpolate_points.cpp | 2 -- src/live_effects/lpe-jointype.cpp | 4 ---- src/live_effects/lpe-knot.cpp | 7 ------- src/live_effects/lpe-lattice.cpp | 14 +------------- src/live_effects/lpe-lattice2.cpp | 15 +-------------- src/live_effects/lpe-line_segment.cpp | 4 ---- src/live_effects/lpe-mirror_symmetry.cpp | 7 ------- src/live_effects/lpe-offset.cpp | 4 ---- src/live_effects/lpe-parallel.cpp | 4 ---- src/live_effects/lpe-path_length.cpp | 2 -- src/live_effects/lpe-patternalongpath.cpp | 10 ---------- src/live_effects/lpe-perp_bisector.cpp | 3 --- src/live_effects/lpe-perspective-envelope.cpp | 1 - src/live_effects/lpe-perspective_path.cpp | 5 ----- src/live_effects/lpe-powerstroke.cpp | 15 --------------- src/live_effects/lpe-recursiveskeleton.cpp | 6 ------ src/live_effects/lpe-rough-hatches.cpp | 8 -------- src/live_effects/lpe-roughen.cpp | 5 ----- src/live_effects/lpe-ruler.cpp | 4 ---- src/live_effects/lpe-show_handles.cpp | 1 - src/live_effects/lpe-simplify.cpp | 9 --------- src/live_effects/lpe-skeleton.cpp | 4 ---- src/live_effects/lpe-sketch.cpp | 8 -------- src/live_effects/lpe-spiro.cpp | 3 --- src/live_effects/lpe-tangent_to_curve.cpp | 4 ---- src/live_effects/lpe-taperstroke.cpp | 8 -------- src/live_effects/lpe-test-doEffect-stack.cpp | 3 --- src/live_effects/lpe-transform_2pts.cpp | 3 --- src/live_effects/lpe-vonkoch.cpp | 2 -- src/live_effects/lpegroupbbox.cpp | 2 -- src/live_effects/lpeobject-reference.cpp | 1 - src/live_effects/lpeobject.cpp | 3 --- src/live_effects/spiro.cpp | 1 - 52 files changed, 3 insertions(+), 278 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1868ca43b..ef807d586 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -8,12 +8,11 @@ //#define LPE_ENABLE_TEST_EFFECTS //uncomment for toy effects #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif // include effects: #include "live_effects/lpe-patternalongpath.h" -#include "live_effects/effect.h" #include "live_effects/lpe-angle_bisector.h" #include "live_effects/lpe-attach-path.h" #include "live_effects/lpe-bendpath.h" @@ -64,30 +63,14 @@ #include "live_effects/lpe-vonkoch.h" #include "xml/node-event-vector.h" -#include "sp-object.h" -#include "attributes.h" #include "message-stack.h" -#include "desktop.h" -#include "inkscape.h" -#include "document.h" #include "document-private.h" -#include "xml/document.h" -#include #include "ui/tools/pen-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" -#include "sp-lpe-item.h" #include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" -#include #include "display/curve.h" -#include - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/affine.h> -#include <2geom/pathvector.h> - namespace Inkscape { diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 900d29e3a..9bfbf4ca8 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -12,7 +12,6 @@ #include "live_effects/lpe-angle_bisector.h" -#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> #include "sp-lpe-item.h" diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index 21459f322..d2b44dd4e 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -10,16 +10,9 @@ #include "live_effects/lpe-attach-path.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" #include "2geom/path-sink.h" -#include "parameter/parameter.h" -#include "live_effects/parameter/point.h" -#include "parameter/originalpath.h" -#include "2geom/affine.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index bc112285f..c24d38d7b 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -6,27 +6,11 @@ */ #include "live_effects/lpe-bendpath.h" -#include "sp-shape.h" -#include "sp-item.h" -#include "sp-path.h" #include "sp-item-group.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" - -#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" -#include - -#include - using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 43a60d482..cfe1f5165 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -9,12 +9,8 @@ #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" -#include "lpe-bounding-box.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index dbb1f4b6b..18252f6a0 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -15,7 +15,6 @@ #include "live_effects/lpe-circle_3pts.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index 8f2156044..6e03cb1ce 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -15,7 +15,6 @@ #include "display/curve.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/pathvector.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index b1e0edaac..4af8891e8 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -14,9 +14,6 @@ #include "live_effects/lpe-constructgrid.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 80f5bdafd..f28ab4b31 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -15,11 +15,7 @@ #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" -#include <2geom/path.h> -#include <2geom/transforms.h> -#include <2geom/angle.h> -#include "knot-holder-entity.h" #include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 609447f26..3beedaf57 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -17,19 +17,11 @@ #include "live_effects/lpe-curvestitch.h" -#include "sp-item.h" #include "sp-path.h" #include "svg/svg.h" #include "xml/repr.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/affine.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index aeecd5d5c..7e22f6e51 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -14,14 +14,8 @@ #include "display/curve.h" //# include -#include <2geom/path.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> #include <2geom/sbasis-math.h> -#include <2geom/piecewise.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 4c953bcda..8f0f8e18a 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -15,7 +15,6 @@ // You might need to include other 2geom files. You can add them here: #include -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index e873c0b15..0ce784877 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -5,22 +5,8 @@ */ #include "live_effects/lpe-envelope.h" -#include "sp-shape.h" -#include "sp-item.h" -#include "sp-path.h" -#include "sp-item-group.h" #include "display/curve.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" -#include <2geom/sbasis.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 using std::vector; namespace Inkscape { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8b3f4714a..22cdf3c3e 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -15,11 +15,6 @@ #include -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/transforms.h> -#include - #include "sp-item.h" namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 574ec3580..ccb9cf56d 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -9,11 +9,8 @@ #include "live_effects/lpe-fill-between-many.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" #include diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 89ea80545..b1e328d18 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -9,11 +9,8 @@ #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 07760b172..24ee2ccc3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -17,21 +17,16 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/elliptical-arc.h> -#include <2geom/line.h> -#include "desktop.h" #include "display/curve.h" #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" #include "helper/geom.h" -#include "live_effects/parameter/filletchamferpointarray.h" - // for programmatically updating knots #include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index d4d695542..307fab6fd 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -8,14 +8,9 @@ #include "live_effects/lpe-gears.h" -#include - #include -#include <2geom/d2.h> -#include <2geom/sbasis.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/path.h> using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index 74c7efd90..43da4d105 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -14,10 +14,7 @@ #include "live_effects/lpe-interpolate.h" -#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> #include "sp-path.h" #include "display/curve.h" diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index cf70832ee..ab0576174 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -13,8 +13,6 @@ #include "live_effects/lpe-interpolate_points.h" -#include <2geom/path.h> - #include "live_effects/lpe-powerstroke-interpolators.h" namespace Inkscape { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index fe42932be..3bfbd6288 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -10,16 +10,12 @@ #include "live_effects/parameter/enum.h" #include "helper/geom-pathstroke.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" -#include <2geom/path.h> #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index a033a6c4a..221d03ebf 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -16,7 +16,6 @@ #include "sp-path.h" #include "display/curve.h" #include "live_effects/lpe-knot.h" -#include "svg/svg.h" #include "style.h" #include "knot-holder-entity.h" #include "knotholder.h" @@ -25,20 +24,14 @@ #include #include <2geom/sbasis-to-bezier.h> -#include <2geom/sbasis.h> -#include <2geom/d2.h> -#include <2geom/path.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/basic-intersection.h> -#include <2geom/exception.h> // for change crossing undo #include "verbs.h" #include "document.h" #include "document-undo.h" -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 3c23e349e..091b6ddca 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * No� Falzon * Victor Navez * * Copyright (C) 2007-2008 Authors @@ -16,22 +16,10 @@ #include "live_effects/lpe-lattice.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 "desktop.h" // TODO: should be factored out (see below) using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index bacbe5fa7..9e9fc153a 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * No� Falzon * Victor Navez * ~suv * Jabiertxo Arraiza @@ -17,24 +17,11 @@ */ #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 "helper/geom.h" -#include <2geom/path.h> -#include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> -#include "helper/geom-curves.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> // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index dfd8aea8f..4c9edabd4 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -14,10 +14,6 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" -#include <2geom/pathvector.h> -#include <2geom/geom.h> -#include <2geom/bezier-curve.h> - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index cf866ad6a..a7459faed 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -14,19 +14,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-mirror_symmetry.h" -#include #include #include #include "helper/geom.h" -#include <2geom/path.h> #include <2geom/path-intersection.h> -#include <2geom/transforms.h> -#include <2geom/affine.h> -#include "knot-holder-entity.h" #include "knotholder.h" -#include "inkscape.h" // TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index d611b88a1..a0fa46c3f 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -17,11 +17,7 @@ #include "sp-shape.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> #include <2geom/elliptical-arc.h> -#include <2geom/transforms.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 23cd5e2e7..9cd8ecf46 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -17,10 +17,6 @@ #include "sp-shape.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 4ca380c15..8fbf9d420 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -16,8 +16,6 @@ #include "live_effects/lpe-path_length.h" #include "util/units.h" -#include "2geom/sbasis-geometric.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 911c410f9..7d6ac10ac 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -6,22 +6,12 @@ #include "live_effects/lpe-patternalongpath.h" #include "live_effects/lpeobject.h" -#include "sp-shape.h" #include "display/curve.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" -#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" -#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index 660318c57..f69dae6a1 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -18,10 +18,7 @@ #include "display/curve.h" #include "sp-path.h" #include "line-geometry.h" -#include "sp-lpe-item.h" -#include <2geom/path.h> -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index ae951dfc9..8a6a95f2e 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -18,7 +18,6 @@ #include "live_effects/lpe-perspective-envelope.h" #include "helper/geom.h" #include "display/curve.h" -#include "svg/svg.h" #include using namespace Geom; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index c8cdd7912..6857d4363 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -15,18 +15,13 @@ #include "persp3d.h" //#include "transf_mat_3x4.h" -#include "document.h" #include "document-private.h" #include "live_effects/lpe-perspective_path.h" #include "live_effects/lpeobject.h" -#include "sp-item-group.h" #include "knot-holder-entity.h" #include "knotholder.h" #include "desktop.h" #include -#include "inkscape.h" - -#include <2geom/path.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 66c8776b5..0de668847 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -13,32 +13,17 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpe-powerstroke-interpolators.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> -#include <2geom/transforms.h> -#include <2geom/bezier-utils.h> #include <2geom/elliptical-arc.h> -#include <2geom/sbasis-to-bezier.h> #include <2geom/path-sink.h> #include <2geom/path-intersection.h> -#include <2geom/crossing.h> -#include <2geom/ellipse.h> #include <2geom/circle.h> -#include <2geom/math-utils.h> #include "helper/geom.h" -#include - -#include "spiro.h" namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index ac571d963..ed0c915ce 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -14,13 +14,7 @@ #include "live_effects/lpe-recursiveskeleton.h" -#include <2geom/path.h> -#include <2geom/sbasis.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> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 76421e0f0..2fb65b349 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -18,18 +18,10 @@ #include "sp-item.h" #include "sp-path.h" -#include "svg/svg.h" #include "xml/repr.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis.h> #include <2geom/sbasis-math.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/affine.h> namespace Inkscape { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 13f2b7b51..3a486ff10 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -14,15 +14,10 @@ */ #include "live_effects/lpe-roughen.h" -#include "desktop.h" #include "display/curve.h" -#include "live_effects/parameter/parameter.h" #include #include "helper/geom.h" -#include "sp-item-group.h" -#include // TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 49b5faa2e..3a2d78b2c 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,10 +12,6 @@ */ #include "live_effects/lpe-ruler.h" -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> -#include "inkscape.h" -#include "desktop.h" namespace Inkscape { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 2d4666fe4..388ea176f 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -7,7 +7,6 @@ */ #include "live_effects/lpe-show_handles.h" -#include "live_effects/parameter/parameter.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> #include "helper/geom.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index b0c1fbc23..ec21e10d2 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -4,20 +4,11 @@ #include "live_effects/lpe-simplify.h" #include "display/curve.h" -#include "live_effects/parameter/parameter.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> #include "ui/icon-names.h" -#include "util/units.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 6e4afbe9b..7d34db699 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -21,13 +21,9 @@ #include "live_effects/lpe-skeleton.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> #include -//#include "knot-holder-entity.h" -//#include "knotholder.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 82d343f6e..95e2f6f0d 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -16,16 +16,8 @@ #include // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/sbasis-math.h> -#include <2geom/piecewise.h> -#include <2geom/crossing.h> #include <2geom/path-intersection.h> namespace Inkscape { diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 0d42596b2..4a41dc5a0 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -7,9 +7,6 @@ #include "live_effects/lpe-spiro.h" #include "display/curve.h" -#include -#include <2geom/pathvector.h> -#include <2geom/affine.h> #include <2geom/curves.h> #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 978ab57fb..b308ef8d7 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -19,10 +19,6 @@ #include "sp-path.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f2ddd4929..f6f6b33dc 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -13,28 +13,20 @@ #include "live_effects/lpe-taperstroke.h" -#include <2geom/path.h> -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/sbasis-to-bezier.h> #include "helper/geom-nodetype.h" #include "helper/geom-pathstroke.h" #include "display/curve.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "svg/svg.h" -#include "knot-holder-entity.h" #include "knotholder.h" -#include - template inline bool withinRange(T value, T low, T high) { return (value > low && value < high); diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 2bcd4c136..c7ecf6481 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -8,9 +8,6 @@ #include "live_effects/lpe-test-doEffect-stack.h" -#include <2geom/piecewise.h> -#include -#include using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..2b03a4bb2 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -14,9 +14,6 @@ #include "live_effects/lpe-transform_2pts.h" #include "display/curve.h" -#include <2geom/transforms.h> -#include <2geom/pathvector.h> -#include "sp-path.h" #include "ui/icon-names.h" #include "svg/svg.h" #include "verbs.h" diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 7eda7446e..2486f3366 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -8,8 +8,6 @@ #include -#include <2geom/transforms.h> - //using std::vector; namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 2a1b70a6a..3862ebcc8 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -7,8 +7,6 @@ #include "live_effects/lpegroupbbox.h" -#include "sp-item.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index d9de6e77f..1940806bd 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -8,7 +8,6 @@ #include -#include "enums.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/lpeobject.h" #include "uri.h" diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index 8e5ae568f..b5b27c984 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -11,13 +11,10 @@ #include "xml/repr.h" #include "xml/node-event-vector.h" -#include "sp-object.h" #include "attributes.h" #include "document.h" #include "document-private.h" -#include - //#define LIVEPATHEFFECT_VERBOSE static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index 0ac2815bf..a2ff4813e 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include "display/curve.h" -#include <2geom/math-utils.h> #define SPIRO_SHOW_INFINITE_COORDINATE_CALLS -- cgit v1.2.3 From 5c04358b2fd79db36b8064ad5e7a9fd8bbe314bb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 12:30:52 +0200 Subject: Finish linked path and add local number format (bzr r15017.1.9) --- src/live_effects/lpe-measure-line.cpp | 96 ++++++++++++++++++++++------------- src/live_effects/lpe-measure-line.h | 4 +- 2 files changed, 64 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 638d60464..31b1db7c2 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -24,6 +24,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -34,27 +35,28 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " "), - origin(_("Optional Origin:"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin:"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - line_offset(_("Optional origin offset"), _("Optional origin offset"), "line_offset", &wr, this, 5), - scale(_("Scale:"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision"), _("Number precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), + fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), + curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), + precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), + offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - reverse(_("To other side"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line"), _("Measure color as line"), "color_as_line", &wr, this, false), - scale_insensitive(_("Scale insensitive"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + unit(_("Unit*"), _("Unit"), "unit", &wr, this), + reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), + color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), pos(0,0), angle(0) { registerParameter(&fontselector); registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&line_offset); + registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -65,17 +67,19 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&reverse); registerParameter(&color_as_line); registerParameter(&scale_insensitive); + registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - line_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/line_offset", 5.0)); + origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); + local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); @@ -92,9 +96,9 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - line_offset.param_set_range(-999999.0, 999999.0); - line_offset.param_set_increments(1, 1); - line_offset.param_set_digits(2); + origin_offset.param_set_range(-999999.0, 999999.0); + origin_offset.param_set_increments(1, 1); + origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -104,6 +108,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : fontlister = Inkscape::FontLister::get_instance(); } +bool LPEMeasureLine::alerts_off = false; + LPEMeasureLine::~LPEMeasureLine() {} void @@ -113,6 +119,18 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); + } else { + if(!alerts_off) { + char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); + gint response = dialog.run(); + alerts_off = true; + if(response == GTK_RESPONSE_CANCEL) { + SPLPEItem* item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); + return; + } + } } } @@ -145,8 +163,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, line_offset); - e = e - Point::polar(angle_cross, line_offset); + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); Geom::Path path; path.start( s ); path.appendNew( e ); @@ -249,17 +267,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.imbue(std::locale::classic()); - length_str << "%." << precision << "f %s"; - gchar *lengthchar = g_strdup_printf(length_str.str().c_str(), length, unit.get_abbreviation()); + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(lengthchar); + rstring = xml_doc->createTextNode(length_str.str().c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(lengthchar); + rstring->setContent(length_str.str().c_str()); } SPObject * text_obj = NULL; if (!elemref) { @@ -280,11 +303,13 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); + if (rtext) { + rtext->setAttribute("sodipodi:insensitive", NULL); + SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + if (text_obj) { + text_obj->updateRepr(); + text_obj->deleteObject(); + } } } } @@ -297,7 +322,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); - vbox->set_spacing(6); + vbox->set_spacing(2); std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); @@ -319,7 +344,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() ++it; } - Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save as default")))); + Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); vbox->pack_start(*button1, true, true, 2); @@ -356,11 +381,12 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/line_offset", line_offset); + prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setInt("/live_effects/measure-line/reverse", reverse); - prefs->setInt("/live_effects/measure-line/color_as_line", color_as_line); - prefs->setInt("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/reverse", reverse); + prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/local_locale", local_locale); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index b03a44705..75faee45d 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -45,7 +45,7 @@ private: Geom::Coord angle; OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam line_offset; + ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; @@ -57,7 +57,9 @@ private: BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; + BoolParam local_locale; Glib::ustring doc_unit; + static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 4450066e940f3751d1a69fdfc0efc8428dedfab2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 28 Jul 2016 13:16:04 +0200 Subject: Fix little typo (bzr r15017.1.10) --- src/live_effects/lpe-measure-line.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 31b1db7c2..69d1619d8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -37,7 +37,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin*"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), + curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), -- cgit v1.2.3 From 43b49e325db73cc19b1731db6c69545664ee8fbe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 13:26:17 +0200 Subject: Reverted changes to r15024 after many building problems (bzr r15027) --- src/live_effects/effect.cpp | 19 ++++++++++++++++++- src/live_effects/lpe-angle_bisector.cpp | 1 + src/live_effects/lpe-attach-path.cpp | 7 +++++++ src/live_effects/lpe-bendpath.cpp | 16 ++++++++++++++++ src/live_effects/lpe-bounding-box.cpp | 4 ++++ src/live_effects/lpe-circle_3pts.cpp | 1 + src/live_effects/lpe-circle_with_radius.cpp | 1 + src/live_effects/lpe-constructgrid.cpp | 3 +++ src/live_effects/lpe-copy_rotate.cpp | 4 ++++ src/live_effects/lpe-curvestitch.cpp | 8 ++++++++ src/live_effects/lpe-dynastroke.cpp | 6 ++++++ src/live_effects/lpe-ellipse_5pts.cpp | 1 + src/live_effects/lpe-envelope.cpp | 14 ++++++++++++++ src/live_effects/lpe-extrude.cpp | 5 +++++ src/live_effects/lpe-fill-between-many.cpp | 3 +++ src/live_effects/lpe-fill-between-strokes.cpp | 3 +++ src/live_effects/lpe-fillet-chamfer.cpp | 5 +++++ src/live_effects/lpe-gears.cpp | 5 +++++ src/live_effects/lpe-interpolate.cpp | 3 +++ src/live_effects/lpe-interpolate_points.cpp | 2 ++ src/live_effects/lpe-jointype.cpp | 4 ++++ src/live_effects/lpe-knot.cpp | 7 +++++++ src/live_effects/lpe-lattice.cpp | 14 +++++++++++++- src/live_effects/lpe-lattice2.cpp | 15 ++++++++++++++- src/live_effects/lpe-line_segment.cpp | 4 ++++ src/live_effects/lpe-mirror_symmetry.cpp | 7 +++++++ src/live_effects/lpe-offset.cpp | 4 ++++ src/live_effects/lpe-parallel.cpp | 4 ++++ src/live_effects/lpe-path_length.cpp | 2 ++ src/live_effects/lpe-patternalongpath.cpp | 10 ++++++++++ src/live_effects/lpe-perp_bisector.cpp | 3 +++ src/live_effects/lpe-perspective-envelope.cpp | 1 + src/live_effects/lpe-perspective_path.cpp | 5 +++++ src/live_effects/lpe-powerstroke.cpp | 15 +++++++++++++++ src/live_effects/lpe-recursiveskeleton.cpp | 6 ++++++ src/live_effects/lpe-rough-hatches.cpp | 8 ++++++++ src/live_effects/lpe-roughen.cpp | 5 +++++ src/live_effects/lpe-ruler.cpp | 4 ++++ src/live_effects/lpe-show_handles.cpp | 1 + src/live_effects/lpe-simplify.cpp | 9 +++++++++ src/live_effects/lpe-skeleton.cpp | 4 ++++ src/live_effects/lpe-sketch.cpp | 8 ++++++++ src/live_effects/lpe-spiro.cpp | 3 +++ src/live_effects/lpe-tangent_to_curve.cpp | 4 ++++ src/live_effects/lpe-taperstroke.cpp | 8 ++++++++ src/live_effects/lpe-test-doEffect-stack.cpp | 3 +++ src/live_effects/lpe-transform_2pts.cpp | 3 +++ src/live_effects/lpe-vonkoch.cpp | 2 ++ src/live_effects/lpegroupbbox.cpp | 2 ++ src/live_effects/lpeobject-reference.cpp | 1 + src/live_effects/lpeobject.cpp | 3 +++ src/live_effects/spiro.cpp | 1 + 52 files changed, 278 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index ef807d586..1868ca43b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -8,11 +8,12 @@ //#define LPE_ENABLE_TEST_EFFECTS //uncomment for toy effects #ifdef HAVE_CONFIG_H -#include +# include "config.h" #endif // include effects: #include "live_effects/lpe-patternalongpath.h" +#include "live_effects/effect.h" #include "live_effects/lpe-angle_bisector.h" #include "live_effects/lpe-attach-path.h" #include "live_effects/lpe-bendpath.h" @@ -63,14 +64,30 @@ #include "live_effects/lpe-vonkoch.h" #include "xml/node-event-vector.h" +#include "sp-object.h" +#include "attributes.h" #include "message-stack.h" +#include "desktop.h" +#include "inkscape.h" +#include "document.h" #include "document-private.h" +#include "xml/document.h" +#include #include "ui/tools/pen-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" +#include "sp-lpe-item.h" #include "live_effects/lpeobject.h" +#include "live_effects/parameter/parameter.h" +#include #include "display/curve.h" +#include + +#include <2geom/sbasis-to-bezier.h> +#include <2geom/affine.h> +#include <2geom/pathvector.h> + namespace Inkscape { diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 9bfbf4ca8..900d29e3a 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -12,6 +12,7 @@ #include "live_effects/lpe-angle_bisector.h" +#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> #include "sp-lpe-item.h" diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index d2b44dd4e..21459f322 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -10,9 +10,16 @@ #include "live_effects/lpe-attach-path.h" #include "display/curve.h" +#include "sp-item.h" +#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" +#include "2geom/bezier-curve.h" #include "2geom/path-sink.h" +#include "parameter/parameter.h" +#include "live_effects/parameter/point.h" +#include "parameter/originalpath.h" +#include "2geom/affine.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index c24d38d7b..bc112285f 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -6,11 +6,27 @@ */ #include "live_effects/lpe-bendpath.h" +#include "sp-shape.h" +#include "sp-item.h" +#include "sp-path.h" #include "sp-item-group.h" +#include "svg/svg.h" +#include "ui/widget/scalar.h" + +#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" +#include + +#include + using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index cfe1f5165..43a60d482 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -9,8 +9,12 @@ #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" +#include "sp-item.h" +#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" +#include "2geom/bezier-curve.h" +#include "lpe-bounding-box.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index 18252f6a0..dbb1f4b6b 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -15,6 +15,7 @@ #include "live_effects/lpe-circle_3pts.h" // You might need to include other 2geom files. You can add them here: +#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index 6e03cb1ce..8f2156044 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -15,6 +15,7 @@ #include "display/curve.h" // You might need to include other 2geom files. You can add them here: +#include <2geom/pathvector.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 4af8891e8..b1e0edaac 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -14,6 +14,9 @@ #include "live_effects/lpe-constructgrid.h" +#include <2geom/path.h> +#include <2geom/transforms.h> + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f28ab4b31..80f5bdafd 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -15,7 +15,11 @@ #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" +#include <2geom/path.h> +#include <2geom/transforms.h> +#include <2geom/angle.h> +#include "knot-holder-entity.h" #include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 3beedaf57..609447f26 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -17,11 +17,19 @@ #include "live_effects/lpe-curvestitch.h" +#include "sp-item.h" #include "sp-path.h" #include "svg/svg.h" #include "xml/repr.h" +#include <2geom/path.h> +#include <2geom/piecewise.h> +#include <2geom/sbasis.h> +#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/affine.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 7e22f6e51..aeecd5d5c 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -14,8 +14,14 @@ #include "display/curve.h" //# include +#include <2geom/path.h> +#include <2geom/sbasis.h> +#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> #include <2geom/sbasis-math.h> +#include <2geom/piecewise.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 8f0f8e18a..4c953bcda 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -15,6 +15,7 @@ // You might need to include other 2geom files. You can add them here: #include +#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 0ce784877..e873c0b15 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -5,8 +5,22 @@ */ #include "live_effects/lpe-envelope.h" +#include "sp-shape.h" +#include "sp-item.h" +#include "sp-path.h" +#include "sp-item-group.h" #include "display/curve.h" +#include "svg/svg.h" +#include "ui/widget/scalar.h" +#include <2geom/sbasis.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 using std::vector; namespace Inkscape { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 22cdf3c3e..8b3f4714a 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -15,6 +15,11 @@ #include +#include <2geom/path.h> +#include <2geom/piecewise.h> +#include <2geom/transforms.h> +#include + #include "sp-item.h" namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index ccb9cf56d..574ec3580 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -9,8 +9,11 @@ #include "live_effects/lpe-fill-between-many.h" #include "display/curve.h" +#include "sp-item.h" +#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" +#include "2geom/bezier-curve.h" #include diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index b1e328d18..89ea80545 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -9,8 +9,11 @@ #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" +#include "sp-item.h" +#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" +#include "2geom/bezier-curve.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ee2ccc3..07760b172 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -17,16 +17,21 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/elliptical-arc.h> +#include <2geom/line.h> +#include "desktop.h" #include "display/curve.h" #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" #include "helper/geom.h" +#include "live_effects/parameter/filletchamferpointarray.h" + // for programmatically updating knots #include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 307fab6fd..d4d695542 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -8,9 +8,14 @@ #include "live_effects/lpe-gears.h" +#include + #include +#include <2geom/d2.h> +#include <2geom/sbasis.h> #include <2geom/bezier-to-sbasis.h> +#include <2geom/path.h> using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index 43da4d105..74c7efd90 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -14,7 +14,10 @@ #include "live_effects/lpe-interpolate.h" +#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> +#include <2geom/piecewise.h> +#include <2geom/sbasis-geometric.h> #include "sp-path.h" #include "display/curve.h" diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index ab0576174..cf70832ee 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -13,6 +13,8 @@ #include "live_effects/lpe-interpolate_points.h" +#include <2geom/path.h> + #include "live_effects/lpe-powerstroke-interpolators.h" namespace Inkscape { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index 3bfbd6288..fe42932be 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -10,12 +10,16 @@ #include "live_effects/parameter/enum.h" #include "helper/geom-pathstroke.h" +#include "sp-shape.h" #include "style.h" +#include "xml/repr.h" +#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" +#include <2geom/path.h> #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 221d03ebf..a033a6c4a 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -16,6 +16,7 @@ #include "sp-path.h" #include "display/curve.h" #include "live_effects/lpe-knot.h" +#include "svg/svg.h" #include "style.h" #include "knot-holder-entity.h" #include "knotholder.h" @@ -24,14 +25,20 @@ #include #include <2geom/sbasis-to-bezier.h> +#include <2geom/sbasis.h> +#include <2geom/d2.h> +#include <2geom/path.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/basic-intersection.h> +#include <2geom/exception.h> // for change crossing undo #include "verbs.h" #include "document.h" #include "document-undo.h" +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 091b6ddca..3c23e349e 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * No� Falzon + * Noé Falzon * Victor Navez * * Copyright (C) 2007-2008 Authors @@ -16,10 +16,22 @@ #include "live_effects/lpe-lattice.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 "desktop.h" // TODO: should be factored out (see below) using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 9e9fc153a..bacbe5fa7 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * No� Falzon + * Noé Falzon * Victor Navez * ~suv * Jabiertxo Arraiza @@ -17,11 +17,24 @@ */ #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 "helper/geom.h" +#include <2geom/path.h> +#include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> +#include "helper/geom-curves.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> // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index 4c9edabd4..dfd8aea8f 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -14,6 +14,10 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" +#include <2geom/pathvector.h> +#include <2geom/geom.h> +#include <2geom/bezier-curve.h> + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a7459faed..cf866ad6a 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -14,12 +14,19 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-mirror_symmetry.h" +#include #include #include #include "helper/geom.h" +#include <2geom/path.h> #include <2geom/path-intersection.h> +#include <2geom/transforms.h> +#include <2geom/affine.h> +#include "knot-holder-entity.h" #include "knotholder.h" +#include "inkscape.h" // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index a0fa46c3f..d611b88a1 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -17,7 +17,11 @@ #include "sp-shape.h" #include "display/curve.h" +#include <2geom/path.h> +#include <2geom/piecewise.h> +#include <2geom/sbasis-geometric.h> #include <2geom/elliptical-arc.h> +#include <2geom/transforms.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 9cd8ecf46..23cd5e2e7 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -17,6 +17,10 @@ #include "sp-shape.h" #include "display/curve.h" +#include <2geom/path.h> +#include <2geom/transforms.h> + +#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 8fbf9d420..4ca380c15 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -16,6 +16,8 @@ #include "live_effects/lpe-path_length.h" #include "util/units.h" +#include "2geom/sbasis-geometric.h" + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 7d6ac10ac..911c410f9 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -6,12 +6,22 @@ #include "live_effects/lpe-patternalongpath.h" #include "live_effects/lpeobject.h" +#include "sp-shape.h" #include "display/curve.h" +#include "svg/svg.h" +#include "ui/widget/scalar.h" +#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" +#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index f69dae6a1..660318c57 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -18,7 +18,10 @@ #include "display/curve.h" #include "sp-path.h" #include "line-geometry.h" +#include "sp-lpe-item.h" +#include <2geom/path.h> +#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 8a6a95f2e..ae951dfc9 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -18,6 +18,7 @@ #include "live_effects/lpe-perspective-envelope.h" #include "helper/geom.h" #include "display/curve.h" +#include "svg/svg.h" #include using namespace Geom; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 6857d4363..c8cdd7912 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -15,13 +15,18 @@ #include "persp3d.h" //#include "transf_mat_3x4.h" +#include "document.h" #include "document-private.h" #include "live_effects/lpe-perspective_path.h" #include "live_effects/lpeobject.h" +#include "sp-item-group.h" #include "knot-holder-entity.h" #include "knotholder.h" #include "desktop.h" #include +#include "inkscape.h" + +#include <2geom/path.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 0de668847..66c8776b5 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -13,17 +13,32 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpe-powerstroke-interpolators.h" +#include "sp-shape.h" #include "style.h" +#include "xml/repr.h" +#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" +#include <2geom/path.h> +#include <2geom/piecewise.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/transforms.h> +#include <2geom/bezier-utils.h> #include <2geom/elliptical-arc.h> +#include <2geom/sbasis-to-bezier.h> #include <2geom/path-sink.h> #include <2geom/path-intersection.h> +#include <2geom/crossing.h> +#include <2geom/ellipse.h> #include <2geom/circle.h> +#include <2geom/math-utils.h> #include "helper/geom.h" +#include + +#include "spiro.h" namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index ed0c915ce..ac571d963 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -14,7 +14,13 @@ #include "live_effects/lpe-recursiveskeleton.h" +#include <2geom/path.h> +#include <2geom/sbasis.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> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 2fb65b349..76421e0f0 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -18,10 +18,18 @@ #include "sp-item.h" #include "sp-path.h" +#include "svg/svg.h" #include "xml/repr.h" +#include <2geom/path.h> +#include <2geom/piecewise.h> +#include <2geom/sbasis.h> #include <2geom/sbasis-math.h> +#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/affine.h> namespace Inkscape { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 3a486ff10..13f2b7b51 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -14,10 +14,15 @@ */ #include "live_effects/lpe-roughen.h" +#include "desktop.h" #include "display/curve.h" +#include "live_effects/parameter/parameter.h" #include #include "helper/geom.h" +#include "sp-item-group.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 3a2d78b2c..49b5faa2e 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,6 +12,10 @@ */ #include "live_effects/lpe-ruler.h" +#include <2geom/piecewise.h> +#include <2geom/sbasis-geometric.h> +#include "inkscape.h" +#include "desktop.h" namespace Inkscape { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 388ea176f..2d4666fe4 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -7,6 +7,7 @@ */ #include "live_effects/lpe-show_handles.h" +#include "live_effects/parameter/parameter.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> #include "helper/geom.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index ec21e10d2..b0c1fbc23 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -4,11 +4,20 @@ #include "live_effects/lpe-simplify.h" #include "display/curve.h" +#include "live_effects/parameter/parameter.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> #include "ui/icon-names.h" +#include "util/units.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 7d34db699..6e4afbe9b 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -21,9 +21,13 @@ #include "live_effects/lpe-skeleton.h" // You might need to include other 2geom files. You can add them here: +#include <2geom/path.h> #include +//#include "knot-holder-entity.h" +//#include "knotholder.h" + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 95e2f6f0d..82d343f6e 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -16,8 +16,16 @@ #include // You might need to include other 2geom files. You can add them here: +#include <2geom/path.h> +#include <2geom/sbasis.h> +#include <2geom/sbasis-geometric.h> #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/sbasis-math.h> +#include <2geom/piecewise.h> +#include <2geom/crossing.h> #include <2geom/path-intersection.h> namespace Inkscape { diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 4a41dc5a0..0d42596b2 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -7,6 +7,9 @@ #include "live_effects/lpe-spiro.h" #include "display/curve.h" +#include +#include <2geom/pathvector.h> +#include <2geom/affine.h> #include <2geom/curves.h> #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index b308ef8d7..978ab57fb 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -19,6 +19,10 @@ #include "sp-path.h" #include "display/curve.h" +#include <2geom/path.h> +#include <2geom/transforms.h> + +#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f6f6b33dc..f2ddd4929 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -13,20 +13,28 @@ #include "live_effects/lpe-taperstroke.h" +#include <2geom/path.h> +#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/sbasis-to-bezier.h> #include "helper/geom-nodetype.h" #include "helper/geom-pathstroke.h" #include "display/curve.h" +#include "sp-shape.h" #include "style.h" +#include "xml/repr.h" +#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "svg/svg.h" +#include "knot-holder-entity.h" #include "knotholder.h" +#include + template inline bool withinRange(T value, T low, T high) { return (value > low && value < high); diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index c7ecf6481..2bcd4c136 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -8,6 +8,9 @@ #include "live_effects/lpe-test-doEffect-stack.h" +#include <2geom/piecewise.h> +#include +#include using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 2b03a4bb2..3c4ce0708 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -14,6 +14,9 @@ #include "live_effects/lpe-transform_2pts.h" #include "display/curve.h" +#include <2geom/transforms.h> +#include <2geom/pathvector.h> +#include "sp-path.h" #include "ui/icon-names.h" #include "svg/svg.h" #include "verbs.h" diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 2486f3366..7eda7446e 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -8,6 +8,8 @@ #include +#include <2geom/transforms.h> + //using std::vector; namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 3862ebcc8..2a1b70a6a 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -7,6 +7,8 @@ #include "live_effects/lpegroupbbox.h" +#include "sp-item.h" + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index 1940806bd..d9de6e77f 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -8,6 +8,7 @@ #include +#include "enums.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/lpeobject.h" #include "uri.h" diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index b5b27c984..8e5ae568f 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -11,10 +11,13 @@ #include "xml/repr.h" #include "xml/node-event-vector.h" +#include "sp-object.h" #include "attributes.h" #include "document.h" #include "document-private.h" +#include + //#define LIVEPATHEFFECT_VERBOSE static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index a2ff4813e..0ac2815bf 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include "display/curve.h" +#include <2geom/math-utils.h> #define SPIRO_SHOW_INFINITE_COORDINATE_CALLS -- cgit v1.2.3 From 49a7927ecf31ace696e9e5770e8d6543c356db7a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 28 Jul 2016 19:15:34 +0100 Subject: Finish removing GTK+ 2 fallbacks (bzr r15023.2.8) --- src/live_effects/parameter/togglebutton.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index c761731b7..023bebc03 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -74,12 +74,8 @@ ToggleButtonParam::param_newWidget() false, param_effect->getRepr(), param_effect->getSPDoc()) ); -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget * box_button = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + auto box_button = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(box_button), false); -#else - GtkWidget * box_button = gtk_hbox_new (false, 0); -#endif GtkWidget * label_button = gtk_label_new (""); if (!param_label.empty()) { if(value || inactive_label.empty()){ -- cgit v1.2.3 From 881b103a91e5668c1f7333ac989e4a968aa92aed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 12:06:16 +0200 Subject: Improvements to widget redraw (bzr r15017.1.11) --- src/live_effects/lpe-ellipse_5pts.cpp | 2 +- src/live_effects/lpe-extrude.cpp | 2 +- src/live_effects/lpe-knot.cpp | 4 ++-- src/live_effects/parameter/parameter.cpp | 38 +++++++++++++++++++++----------- src/live_effects/parameter/parameter.h | 2 ++ src/live_effects/parameter/point.cpp | 31 ++++++++++++++------------ src/live_effects/parameter/point.h | 2 ++ 7 files changed, 50 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 4c953bcda..088d24b9c 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -171,7 +171,7 @@ LPEEllipse5Pts::doEffect_path (Geom::PathVector const & path_in) // figure out if we have a slice, guarding against rounding errors - Path p(Geom::Point(cos(0), sin(0))); + Geom::Path p(Geom::Point(cos(0), sin(0))); double end = 2 * M_PI; for (s = 0; s < end; s += M_PI_2) { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8b3f4714a..dd1a8c824 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -66,7 +66,7 @@ LPEExtrude::doEffect_pwd2 (Geom::Piecewise > const & pwd2 using namespace Geom; // generate connecting lines (the 'sides' of the extrusion) - Path path(Point(0.,0.)); + Geom::Path path(Point(0.,0.)); path.appendNew( extrude_vector.getVector() ); Piecewise > connector = path.toPwSb(); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index a033a6c4a..09f35f05e 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -101,7 +101,7 @@ findShadowedTime(Geom::Path const &patha, std::vector const &pt_and Affine mat = from_basis( T, N, pt_and_dir[0] ); mat = mat.inverse(); - Path p = patha * mat; + Geom::Path p = patha * mat; std::vector times; @@ -484,7 +484,7 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) // std::cout<<"fusing first and last component\n"; ++beg_comp; --end_comp; - Path first = gpaths[i0].portion(dom.back()); + Geom::Path first = gpaths[i0].portion(dom.back()); //FIXME: stitching should not be necessary (?!?) first.setStitching(true); first.append(gpaths[i0].portion(dom.front())); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index ae55c84e9..3f8fced4b 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -4,8 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" -#include #include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" @@ -16,6 +14,8 @@ #include "verbs.h" +#include + #define noLPEREALPARAM_DEBUG namespace Inkscape { @@ -66,7 +66,8 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget) + hide_widget(no_widget), + _rsu(NULL) { } @@ -117,6 +118,9 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; + if (_rsu) { + _rsu->setValue(val); + } } void @@ -138,7 +142,9 @@ ScalarParam::param_set_range(gdouble min, gdouble max) } else { this->max = SCALARPARAM_G_MAXDOUBLE; } - + if (_rsu) { + _rsu->setRange(this->min, this->max); + } param_set_value(value); // reset value to see whether it is in ranges } @@ -161,22 +167,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - rsu->setValue(value); - rsu->setDigits(digits); - rsu->setIncrements(inc_step, inc_page); - rsu->setRange(min, max); - rsu->setProgrammatically = false; + _rsu->setValue(value); + _rsu->setDigits(digits); + _rsu->setIncrements(inc_step, inc_page); + _rsu->setRange(min, max); + _rsu->setProgrammatically = false; if (add_slider) { - rsu->addSlider(); + _rsu->addSlider(); } if(!overwrite_widget){ - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (rsu); + return dynamic_cast (_rsu); } else { return NULL; } @@ -186,6 +192,9 @@ void ScalarParam::param_set_digits(unsigned digits) { this->digits = digits; + if (_rsu) { + _rsu->setDigits(this->digits); + } } void @@ -193,6 +202,9 @@ ScalarParam::param_set_increments(double step, double page) { inc_step = step; inc_page = page; + if (_rsu) { + _rsu->setIncrements(inc_step, inc_page); + } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 8556b0d9a..63c55203e 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -12,6 +12,7 @@ #include #include <2geom/forward.h> #include <2geom/pathvector.h> +#include "ui/widget/registered-widget.h" // In gtk2, this wasn't an issue; we could toss around // G_MAXDOUBLE and not worry about size allocations. But @@ -140,6 +141,7 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); + Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 90a5b252b..3442fd851 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -4,7 +4,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/registered-widget.h" #include "live_effects/parameter/point.h" #include "live_effects/effect.h" #include "svg/svg.h" @@ -30,7 +29,8 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, : Parameter(label, tip, key, wr, effect), defvalue(default_value), liveupdate(live_update), - knoth(NULL) + knoth(NULL), + _pointwdg(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -81,6 +81,9 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) if(knoth && liveupdate){ knoth->update_knots(); } + if (_pointwdg) { + _pointwdg->setValue( newpoint ); + } } bool @@ -116,7 +119,7 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( + _pointwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, param_tooltip, param_key, @@ -126,13 +129,13 @@ PointParam::param_newWidget() // 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")); + _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(hbox)->pack_start(*pointwdg, true, true); + static_cast(hbox)->pack_start(*_pointwdg, true, true); static_cast(hbox)->show_all_children(); param_effect->upd_params = false; return dynamic_cast (hbox); @@ -191,13 +194,13 @@ void PointParamKnotHolderEntity::knot_click(guint state) { if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - this->pparam->param_set_default(); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } + if (state & GDK_MOD1_MASK) { + this->pparam->param_set_default(); + SPLPEItem * splpeitem = dynamic_cast(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 d41e8a710..62c6fb83d 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,6 +11,7 @@ #include #include <2geom/point.h> +#include "ui/widget/registered-widget.h" #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" @@ -61,6 +62,7 @@ private: SPKnotModeType knot_mode; guint32 knot_color; gchar *handle_tip; + Inkscape::UI::Widget::RegisteredTransformedPoint * _pointwdg; }; -- cgit v1.2.3 From 53500549df51879d6a7aaec5a0c8c37ca7087817 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 29 Jul 2016 20:28:00 +0200 Subject: Add orientation and alow unsort combobox enum widget (bzr r15017.1.12) --- src/live_effects/lpe-measure-line.cpp | 437 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 19 +- src/live_effects/parameter/enum.h | 8 +- 3 files changed, 303 insertions(+), 161 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 69d1619d8..6145f7592 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -8,6 +8,7 @@ */ #include "live_effects/lpe-measure-line.h" #include "inkscape.h" +#include "xml/node.h" #include "uri.h" #include "uri-references.h" #include "preferences.h" @@ -33,9 +34,21 @@ using namespace Geom; namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData OrientationMethodData[] = { + { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, + { OM_VERTICAL, N_("Vertical"), "vertical" }, + { OM_PARALLEL, N_("Parallel"), "parallel" }, + { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, + { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, + { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, + { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } +}; +static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); + LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), @@ -49,11 +62,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), - pos(0,0), - angle(0) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { registerParameter(&fontselector); + registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); registerParameter(&origin_offset); @@ -80,7 +92,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); - rtext = NULL; precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -143,175 +154,279 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } else { + orientations_remove.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } else { + orientations_remove.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } else { + orientations_remove.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { + pathvector = origin.get_pathvector(); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(1, ncurves); + if(previous_ncurves != ncurves) { + this->upd_params = true; + previous_ncurves = ncurves; + } + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + s = s - Point::polar(angle_cross, origin_offset); + e = e - Point::polar(angle_cross, origin_offset); + Geom::Path path; + path.start( s ); + path.appendNew( e ); + Geom::PathVector line_upd; + line_upd.push_back(path); + Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); + gchar *str = sp_svg_write_path(line_upd); + line->setAttribute("inkscape:original-d", str); + } else { + if(*om_it == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(*om_it == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); Geom::Ray ray(s,e); - angle = ray.angle(); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } - length = Geom::distance(s, e) * scale; - pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_unset_property (css, "#000000"); } } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); - length_str.precision(precision); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << length << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.setf(std::ios::fixed, std::ios::floatfield); + length_str.precision(precision); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << length << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { + Glib::ustring orientation_str; + if (*omdel_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*omdel_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*omdel_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); } } } void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if (rtext) { - rtext->setAttribute("sodipodi:insensitive", NULL); - SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - if (text_obj) { - text_obj->updateRepr(); - text_obj->deleteObject(); - } - } - } +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// if (horizontal_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (vertical_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// if (parallel_text) { +// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); +// if (text_obj) { +// text_obj->deleteObject(); +// } +// } +// } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -357,6 +472,8 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) Geom::Path path; Geom::Point s = path_in.initialPoint(); Geom::Point e = path_in.finalPoint(); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); if (reverse) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; @@ -365,6 +482,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); + if(orientation == OM_VERTICAL) { + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); + } + s[Geom::X] = xpos; + e[Geom::X] = xpos; + } + if(orientation == OM_HORIZONTAL) { + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); + if (reverse) { + ypos = std::min(s[Geom::Y],e[Geom::Y]); + } + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 75faee45d..67d27408a 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,6 +11,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/font.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" @@ -20,12 +21,21 @@ #include <2geom/angle.h> #include <2geom/ray.h> #include <2geom/point.h> -#include "xml/node.h" - namespace Inkscape { namespace LivePathEffect { +enum OrientationMethod { + OM_HORIZONTAL, + OM_VERTICAL, + OM_PARALLEL, + OM_PARALLEL_VERTICAL, + OM_PARALLEL_HORIZONTAL, + OM_VERTICAL_HORIZONTAL, + OM_PARALLEL_VERTICAL_HORIZONTAL, + OM_END +}; + class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); @@ -37,12 +47,9 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - double length; FontParam fontselector; Inkscape::FontLister *fontlister; - Inkscape::XML::Node *rtext; - Geom::Point pos; - Geom::Coord angle; + EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; ScalarParam origin_offset; diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 2340663c3..dbfc68623 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -27,12 +27,14 @@ public: const Util::EnumDataConverter& c, Inkscape::UI::Widget::Registry* wr, Effect* effect, - E default_value) + E default_value, + bool sort = true) : Parameter(label, tip, key, wr, effect) { enumdataconv = &c; defvalue = default_value; value = defvalue; + sorted = sort; }; virtual ~EnumParam() { }; @@ -40,12 +42,11 @@ public: virtual Gtk::Widget * param_newWidget() { Inkscape::UI::Widget::RegisteredEnum *regenum = Gtk::manage ( new Inkscape::UI::Widget::RegisteredEnum( param_label, param_tooltip, - param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); + param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc(), sorted ) ); regenum->set_active_by_id(value); regenum->combobox()->setProgrammatically = false; regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter")); - return dynamic_cast (regenum); }; @@ -86,6 +87,7 @@ private: E value; E defvalue; + bool sorted; const Util::EnumDataConverter * enumdataconv; }; -- cgit v1.2.3 From d60fb000cfc3717ef51b716d9ccb9b63ecb38aa8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 01:44:17 +0200 Subject: Remove font-Dialog and useGtk::FontSelector instead (bzr r15017.1.13) --- src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-measure-line.cpp | 27 +++--- src/live_effects/lpe-measure-line.h | 5 +- src/live_effects/parameter/Makefile_insert | 2 + src/live_effects/parameter/font.cpp | 129 ----------------------------- src/live_effects/parameter/font.h | 78 ----------------- src/live_effects/parameter/fontbutton.cpp | 92 ++++++++++++++++++++ src/live_effects/parameter/fontbutton.h | 62 ++++++++++++++ 8 files changed, 174 insertions(+), 225 deletions(-) delete mode 100644 src/live_effects/parameter/font.cpp delete mode 100644 src/live_effects/parameter/font.h create mode 100644 src/live_effects/parameter/fontbutton.cpp create mode 100644 src/live_effects/parameter/fontbutton.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c3d740862..784317090 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/font.cpp + parameter/fontbutton.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/font.h + parameter/fontbutton.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6145f7592..5df3d499e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include +#include #include "inkscape.h" #include "xml/node.h" #include "uri.h" @@ -47,13 +49,13 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fontselector(_("Font Selector*"), _("Font Selector"), "fontselector", &wr, this, " "), + fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), - precision(_("Number precision*"), _("Number precision"), "precision", &wr, this, 2), + precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), @@ -64,7 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) { - registerParameter(&fontselector); + registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&origin); registerParameter(&curve_linked); @@ -81,7 +83,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&scale_insensitive); registerParameter(&local_locale); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontselector.param_update_default(prefs->getString("/live_effects/measure-line/fontselector")); + fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); @@ -116,7 +118,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_range(-999999.0, 999999.0); gap_end.param_set_increments(1, 1); gap_end.param_set_digits(2); - fontlister = Inkscape::FontLister::get_instance(); } bool LPEMeasureLine::alerts_off = false; @@ -294,15 +295,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) rtspan->setAttribute("sodipodi:role", "line"); } SPCSSAttr *css = sp_repr_css_attr_new(); - Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); - double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); - fontlister->fill_css( css, fontspec ); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "font-style", "normal"); - sp_repr_css_set_property (css, "font-weight", "normal"); sp_repr_css_set_property (css, "line-height", "125%"); sp_repr_css_set_property (css, "letter-spacing", "0"); sp_repr_css_set_property (css, "word-spacing", "0"); @@ -352,14 +352,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; - length_str.setf(std::ios::fixed, std::ios::floatfield); length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); if (local_locale) { length_str.imbue(std::locale("")); } else { length_str.imbue(std::locale::classic()); } - length_str << length << unit.get_abbreviation(); + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); Inkscape::XML::Node *rstring = NULL; if (!elemref) { rstring = xml_doc->createTextNode(length_str.str().c_str()); @@ -509,7 +510,7 @@ void LPEMeasureLine::saveDefault() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/live_effects/measure-line/fontselector", (Glib::ustring)fontselector.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 67d27408a..15831e231 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -12,7 +12,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/font.h" +#include "live_effects/parameter/fontbutton.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/unit.h" #include "live_effects/parameter/bool.h" @@ -47,8 +47,7 @@ public: void saveDefault(); virtual Gtk::Widget *newWidget(); private: - FontParam fontselector; - Inkscape::FontLister *fontlister; + FontButtonParam fontbutton; EnumParam orientation; OriginalPathParam origin; ScalarParam curve_linked; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index bd1c5b600..d9cd5b3c1 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/fontbutton.cpp \ + live_effects/parameter/fontbutton.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp deleted file mode 100644 index 8f89ee5c4..000000000 --- a/src/live_effects/parameter/font.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include "ui/widget/registered-widget.h" -#include "live_effects/parameter/font.h" -#include "live_effects/effect.h" -#include "ui/widget/font-selector.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "verbs.h" - -#include - -namespace Inkscape { - -namespace LivePathEffect { - -FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ -} - -void -FontParam::param_set_default() -{ - param_setValue(defvalue); -} -void -FontParam::param_update_default(const Glib::ustring default_value){ - defvalue = default_value; -} - -Glib::ustring -FontParam::param_readFontSpec(const gchar * strvalue) -{ - Glib::ustring result; - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - result = (Glib::ustring)strarray[0]; - g_strfreev (strarray); - return result; - } - } - g_strfreev (strarray); - return result; -} - -double -FontParam::param_readFontSize(const gchar * strvalue) -{ - gchar ** strarray = g_strsplit(strvalue, " @ ", 2); - double fontsize = 0; - if (strarray[1]) { - unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); - if (success == 1) { - g_strfreev (strarray); - return fontsize; - } - } - g_strfreev (strarray); - return fontsize; -} - -bool -FontParam::param_readSVGValue(const gchar * strvalue) -{ - double fontsize = param_readFontSize(strvalue); - Glib::ustring fontspec = param_readFontSpec(strvalue); - Inkscape::SVGOStringStream os; - os << fontspec << " @ " << fontsize; - param_setValue((Glib::ustring)os.str()); - return true; -} - -gchar * -FontParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -FontParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredFontSelector( param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() ) ); - double fontsize = param_readFontSize(param_getSVGValue()); - Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); - fontselectorwdg->setValue( fontspec, fontsize ); - fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); - param_effect->upd_params = false; - return dynamic_cast (fontselectorwdg); -} - -void -FontParam::param_setValue(const Glib::ustring 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/font.h b/src/live_effects/parameter/font.h deleted file mode 100644 index 3909ea424..000000000 --- a/src/live_effects/parameter/font.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H - -/* - * Inkscape::LivePathEffectParameters - * - * Authors: - * Released under GNU GPL, read the file 'COPYING' for more information - */ -#include -#include -#include "live_effects/parameter/parameter.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class FontParam : public Parameter { -public: - FontParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const Glib::ustring default_value = ""); - virtual ~FontParam() {} - - virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); - double param_readFontSize(const gchar * strvalue); - void param_update_default(const Glib::ustring defvalue); - Glib::ustring param_readFontSpec(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(const Glib::ustring newvalue); - - virtual void param_set_default(); - - const Glib::ustring get_value() const { return defvalue; }; - -private: - FontParam(const FontParam&); - FontParam& operator=(const FontParam&); - Glib::ustring value; - Glib::ustring defvalue; - -}; - -/* - * This parameter does not display a widget in the LPE dialog; LPEs can use it to display on-canvas - * text that should not be settable by the user. Note that since no widget is provided, the - * parameter must be initialized differently than usual (only with a pointer to the parent effect; - * no label, no tooltip, etc.). - */ -class FontParamInternal : public FontParam { -public: - FontParamInternal(Effect* effect) : - FontParam("", "", "", NULL, effect) {} - - virtual Gtk::Widget * param_newWidget() { return NULL; } -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif - -/* - 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/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp new file mode 100644 index 000000000..ff8ab76a0 --- /dev/null +++ b/src/live_effects/parameter/fontbutton.cpp @@ -0,0 +1,92 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/fontbutton.h" +#include "live_effects/effect.h" +#include "ui/widget/font-button.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +FontButtonParam::FontButtonParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontButtonParam::param_set_default() +{ + param_setValue(defvalue); +} +void +FontButtonParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; +} + +bool +FontButtonParam::param_readSVGValue(const gchar * strvalue) +{ + Inkscape::SVGOStringStream os; + os << strvalue; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontButtonParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontButtonParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontButton * fontbuttonwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontButton( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + Glib::ustring fontspec = param_getSVGValue(); + fontbuttonwdg->setValue( fontspec); + fontbuttonwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font button parameter")); + param_effect->upd_params = false; + return dynamic_cast (fontbuttonwdg); +} + +void +FontButtonParam::param_setValue(const Glib::ustring 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/fontbutton.h b/src/live_effects/parameter/fontbutton.h new file mode 100644 index 000000000..387ad130b --- /dev/null +++ b/src/live_effects/parameter/fontbutton.h @@ -0,0 +1,62 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class FontButtonParam : public Parameter { +public: + FontButtonParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~FontButtonParam() {} + + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + void param_update_default(const Glib::ustring defvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + + virtual void param_set_default(); + + const Glib::ustring get_value() const { return defvalue; }; + +private: + FontButtonParam(const FontButtonParam&); + FontButtonParam& operator=(const FontButtonParam&); + Glib::ustring value; + Glib::ustring defvalue; + +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + 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 : -- cgit v1.2.3 From f391d1cb5c644cd325f64a88d6d3a9da73fdb9de Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 02:50:36 +0200 Subject: Fixes positions of labels (bzr r15017.1.14) --- src/live_effects/lpe-measure-line.cpp | 113 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 77 insertions(+), 38 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5df3d499e..d0252aea9 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -215,6 +215,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -223,6 +226,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } Geom::Ray ray(s,e); Geom::Coord angle = ray.angle(); @@ -250,6 +256,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::X] = xpos; e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); + } } if(*om_it == OM_HORIZONTAL) { Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); @@ -258,6 +267,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } s[Geom::Y] = ypos; e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); + } } } double length = Geom::distance(s, e) * scale; @@ -406,28 +418,55 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } -void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) +void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { -// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { -// if (horizontal_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(horizontal_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (vertical_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(vertical_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// if (parallel_text) { -// SPObject * text_obj = desktop->currentLayer()->get_child_by_repr(parallel_text); -// if (text_obj) { -// text_obj->deleteObject(); -// } -// } -// } + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + SPLPEItem * splpeitem = const_cast(lpeitem); + std::vector orientations; + std::vector orientations_remove; + if ( orientation == OM_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_HORIZONTAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_HORIZONTAL); + } + if ( orientation == OM_VERTICAL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_VERTICAL_HORIZONTAL) + { + orientations.push_back(OM_VERTICAL); + } + if ( orientation == OM_PARALLEL || + orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || + orientation == OM_PARALLEL_VERTICAL || + orientation == OM_PARALLEL_HORIZONTAL) + { + orientations.push_back(OM_PARALLEL); + } + for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (*om_it == OM_VERTICAL) { + orientation_str = "vertical"; + } + if (*om_it == OM_HORIZONTAL) { + orientation_str = "horizontal"; + } + if (*om_it == OM_PARALLEL) { + orientation_str = "parallel"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + } + } } Gtk::Widget *LPEMeasureLine::newWidget() @@ -483,22 +522,22 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; e = e - Point::polar(angle, gap_end); - if(orientation == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - } - if(orientation == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - } +// if(orientation == OM_VERTICAL) { +// Coord xpos = std::max(s[Geom::X],e[Geom::X]); +// if (reverse) { +// xpos = std::min(s[Geom::X],e[Geom::X]); +// } +// s[Geom::X] = xpos; +// e[Geom::X] = xpos; +// } +// if(orientation == OM_HORIZONTAL) { +// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); +// if (reverse) { +// ypos = std::min(s[Geom::Y],e[Geom::Y]); +// } +// s[Geom::Y] = ypos; +// e[Geom::Y] = ypos; +// } path.start( s ); path.appendNew( e ); Geom::PathVector output; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 15831e231..05f9b2f73 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); - virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnRemove (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); -- cgit v1.2.3 From 7f16afbb515eceed9c63afacec73cd528a662327 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 30 Jul 2016 19:04:34 +0200 Subject: Full rewrite on working mode now no linked paths necesary (bzr r15017.1.15) --- src/live_effects/effect.cpp | 4 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-measure-line.cpp | 528 +++++++++++-------------------- src/live_effects/lpe-measure-line.h | 9 +- src/live_effects/parameter/parameter.cpp | 43 +-- src/live_effects/parameter/parameter.h | 2 - 6 files changed, 198 insertions(+), 390 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a62e8b62b..7efc1a711 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -454,7 +454,9 @@ void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/) void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) { } - +void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ +} //secret impl methods (shhhh!) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e0a7cbe6b..f54624302 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -66,7 +66,7 @@ public: virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); - + virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem); void writeParamsToSVG(); virtual void acceptParamPath (SPPath const* param_path); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d0252aea9..6d58e2b7d 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -39,11 +39,7 @@ namespace LivePathEffect { static const Util::EnumData OrientationMethodData[] = { { OM_HORIZONTAL, N_("Horizontal"), "horizontal" }, { OM_VERTICAL, N_("Vertical"), "vertical" }, - { OM_PARALLEL, N_("Parallel"), "parallel" }, - { OM_PARALLEL_VERTICAL, N_("Parallel and vertical,"), "parallel_vertical" }, - { OM_PARALLEL_HORIZONTAL, N_("Parallel and horizontal"), "parallel_horizontal" }, - { OM_VERTICAL_HORIZONTAL, N_("Vertical and horizontal"), "vertical_horizontal" }, - { OM_PARALLEL_VERTICAL_HORIZONTAL, N_("Parallel, vertical and horizontal"), "parallel_vertical_horizontal" } + { OM_PARALLEL, N_("Parallel"), "parallel" } }; static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); @@ -51,9 +47,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), - origin(_("Optional Origin"), _("Optional origin"), "origin", &wr, this), - curve_linked(_("Curve on optional origin"), _("Curve on optional origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - origin_offset(_("Optional origin offset*"), _("Optional origin offset"), "origin_offset", &wr, this, 5), + curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), @@ -68,9 +62,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : { registerParameter(&fontbutton); registerParameter(&orientation); - registerParameter(&origin); registerParameter(&curve_linked); - registerParameter(&origin_offset); registerParameter(&scale); registerParameter(&precision); registerParameter(&offset_right_left); @@ -88,7 +80,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); - origin_offset.param_update_default(prefs->getDouble("/live_effects/measure-line/origin_offset", 5.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); @@ -98,7 +89,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : precision.param_set_increments(1, 1); precision.param_set_digits(0); precision.param_make_integer(true); - curve_linked.param_set_range(1, 999); + curve_linked.param_set_range(0, 999); curve_linked.param_set_increments(1, 1); curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); @@ -109,9 +100,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : offset_top_bottom.param_set_range(-999999.0, 999999.0); offset_top_bottom.param_set_increments(1, 1); offset_top_bottom.param_set_digits(2); - origin_offset.param_set_range(-999999.0, 999999.0); - origin_offset.param_set_increments(1, 1); - origin_offset.param_set_digits(2); gap_start.param_set_range(-999999.0, 999999.0); gap_start.param_set_increments(1, 1); gap_start.param_set_digits(2); @@ -120,8 +108,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : gap_end.param_set_digits(2); } -bool LPEMeasureLine::alerts_off = false; - LPEMeasureLine::~LPEMeasureLine() {} void @@ -131,16 +117,24 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) g_warning("LPE measure line can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); - } else { - if(!alerts_off) { - char *msg = _("The \"measure line\" path effect could update original path on the object you are applying it to if link it to other path. If this is not what you want, click Cancel."); - Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_OK_CANCEL, true); - gint response = dialog.run(); - alerts_off = true; - if(response == GTK_RESPONSE_CANCEL) { - SPLPEItem* item = const_cast(lpeitem); - item->removeCurrentPathEffect(false); - return; + } +} + +void +LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); } } } @@ -154,266 +148,166 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } else { - orientations_remove.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } else { - orientations_remove.push_back(OM_VERTICAL); + size_t ncurves = pathvector.curveCount(); + curve_linked.param_set_range(0, ncurves); + Geom::Point s = pathvector.initialPoint(); + Geom::Point e = pathvector.finalPoint(); + if (curve_linked) { //0 start-end nodes + s = pathvector.pointAt(curve_linked -1); + e = pathvector.pointAt(curve_linked); } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } else { - orientations_remove.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Glib::ustring orientation_str; + Inkscape::XML::Node *rtext = NULL; + if (orientation == OM_VERTICAL) { + orientation_str = "vertical"; + Coord xpos = std::max(s[Geom::X],e[Geom::X]); + if (reverse) { + xpos = std::min(s[Geom::X],e[Geom::X]); } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; + s[Geom::X] = xpos; + e[Geom::X] = xpos; + if (s[Geom::Y] > e[Geom::Y]) { + swap(s,e); } - if (origin.linksToPath() && origin.getObject() && !origin.get_pathvector().empty()) { - pathvector = origin.get_pathvector(); - size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(1, ncurves); - if(previous_ncurves != ncurves) { - this->upd_params = true; - previous_ncurves = ncurves; - } - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - s = s - Point::polar(angle_cross, origin_offset); - e = e - Point::polar(angle_cross, origin_offset); - Geom::Path path; - path.start( s ); - path.appendNew( e ); - Geom::PathVector line_upd; - line_upd.push_back(path); - Inkscape::XML::Node *line = SP_OBJECT(sp_path)->getRepr(); - gchar *str = sp_svg_write_path(line_upd); - line->setAttribute("inkscape:original-d", str); - } else { - if(*om_it == OM_VERTICAL) { - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); - } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); - } - } - if(*om_it == OM_HORIZONTAL) { - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); - } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); - } - } - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + } + if (orientation == OM_HORIZONTAL) { + orientation_str = "horizontal"; + Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; + ypos = std::min(s[Geom::Y],e[Geom::Y]); } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); + s[Geom::Y] = ypos; + e[Geom::Y] = ypos; + if (s[Geom::X] < e[Geom::X]) { + swap(s,e); } - SPCSSAttr *css = sp_repr_css_attr_new(); - Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); + } + if (orientation == OM_PARALLEL) { + orientation_str = "parallel"; + } + double length = Geom::distance(s, e) * scale; + Geom::Point pos = Geom::middle_point(s,e); + Geom::Ray ray(s,e); + Geom::Coord angle = ray.angle(); + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (reverse) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + Geom::Point newpos = pos - Point::polar(angle, offset_right_left); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + newpos = newpos - Point::polar(angle_cross, offset_top_bottom); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); + /* Create */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + double fontsize = fontdesc.get_size()/Pango::SCALE; + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if (color_as_line) { + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_unset_property (css, "#000000"); + sp_repr_css_set_property (css, "fill", "#000000"); } } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + sp_repr_css_unset_property (css, "#000000"); } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); - } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); } - for (std::vector::const_iterator omdel_it = orientations_remove.begin(); omdel_it != orientations_remove.end(); ++omdel_it) { - Glib::ustring orientation_str; - if (*omdel_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*omdel_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*omdel_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + if (!scale_insensitive) { + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(newpos); + SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); + text_obj->updateRepr(); } } } @@ -422,49 +316,13 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - std::vector orientations; - std::vector orientations_remove; - if ( orientation == OM_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_HORIZONTAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_HORIZONTAL); - } - if ( orientation == OM_VERTICAL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_VERTICAL_HORIZONTAL) - { - orientations.push_back(OM_VERTICAL); - } - if ( orientation == OM_PARALLEL || - orientation == OM_PARALLEL_VERTICAL_HORIZONTAL || - orientation == OM_PARALLEL_VERTICAL || - orientation == OM_PARALLEL_HORIZONTAL) - { - orientations.push_back(OM_PARALLEL); - } - for (std::vector::const_iterator om_it = orientations.begin(); om_it != orientations.end(); ++om_it) { - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; - if (*om_it == OM_VERTICAL) { - orientation_str = "vertical"; - } - if (*om_it == OM_HORIZONTAL) { - orientation_str = "horizontal"; - } - if (*om_it == OM_PARALLEL) { - orientation_str = "parallel"; - } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_DINnumber_" + orientation_str).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); } } } @@ -509,40 +367,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { - Geom::Path path; - Geom::Point s = path_in.initialPoint(); - Geom::Point e = path_in.finalPoint(); - Geom::Ray ray(s,e); - Geom::Coord angle = ray.angle(); - if (reverse) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - s = s - Point::polar(angle, gap_start); - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - e = e - Point::polar(angle, gap_end); -// if(orientation == OM_VERTICAL) { -// Coord xpos = std::max(s[Geom::X],e[Geom::X]); -// if (reverse) { -// xpos = std::min(s[Geom::X],e[Geom::X]); -// } -// s[Geom::X] = xpos; -// e[Geom::X] = xpos; -// } -// if(orientation == OM_HORIZONTAL) { -// Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); -// if (reverse) { -// ypos = std::min(s[Geom::Y],e[Geom::Y]); -// } -// s[Geom::Y] = ypos; -// e[Geom::Y] = ypos; -// } - path.start( s ); - path.appendNew( e ); - Geom::PathVector output; - output.push_back(path); - return output; + return path_in; } void @@ -554,7 +379,6 @@ LPEMeasureLine::saveDefault() prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); - prefs->setDouble("/live_effects/measure-line/origin_offset", origin_offset); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setBool("/live_effects/measure-line/reverse", reverse); prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 05f9b2f73..834194841 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -29,10 +29,6 @@ enum OrientationMethod { OM_HORIZONTAL, OM_VERTICAL, OM_PARALLEL, - OM_PARALLEL_VERTICAL, - OM_PARALLEL_HORIZONTAL, - OM_VERTICAL_HORIZONTAL, - OM_PARALLEL_VERTICAL_HORIZONTAL, OM_END }; @@ -43,29 +39,26 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void saveDefault(); virtual Gtk::Widget *newWidget(); private: FontButtonParam fontbutton; EnumParam orientation; - OriginalPathParam origin; ScalarParam curve_linked; - ScalarParam origin_offset; ScalarParam scale; ScalarParam precision; ScalarParam offset_right_left; ScalarParam offset_top_bottom; ScalarParam gap_start; ScalarParam gap_end; - size_t previous_ncurves; UnitParam unit; BoolParam reverse; BoolParam color_as_line; BoolParam scale_insensitive; BoolParam local_locale; Glib::ustring doc_unit; - static bool alerts_off; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 3f8fced4b..befac4df1 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -5,8 +5,8 @@ */ -#include "live_effects/parameter/parameter.h" #include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" #include "svg/svg.h" #include "xml/repr.h" @@ -66,8 +66,7 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget), - _rsu(NULL) + hide_widget(no_widget) { } @@ -111,6 +110,7 @@ ScalarParam::param_update_default(gdouble default_value) void ScalarParam::param_set_value(gdouble val) { + param_effect->upd_params = true; value = val; if (integer) value = round(value); @@ -118,9 +118,6 @@ ScalarParam::param_set_value(gdouble val) value = max; if (value < min) value = min; - if (_rsu) { - _rsu->setValue(val); - } } void @@ -131,7 +128,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) // Once again, in gtk2, this is not a problem. But in gtk3, // widgets get allocated the amount of size they ask for, // leading to excessively long widgets. - + param_effect->upd_params = true; if (min >= -SCALARPARAM_G_MAXDOUBLE) { this->min = min; } else { @@ -140,10 +137,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) if (max <= SCALARPARAM_G_MAXDOUBLE) { this->max = max; } else { - this->max = SCALARPARAM_G_MAXDOUBLE; - } - if (_rsu) { - _rsu->setRange(this->min, this->max); + this->max = SCALARPARAM_G_MAXDOUBLE; } param_set_value(value); // reset value to see whether it is in ranges } @@ -151,6 +145,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) void ScalarParam::param_make_integer(bool yes) { + param_effect->upd_params = true; integer = yes; digits = 0; inc_step = 1; @@ -167,22 +162,22 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - _rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( + Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - _rsu->setValue(value); - _rsu->setDigits(digits); - _rsu->setIncrements(inc_step, inc_page); - _rsu->setRange(min, max); - _rsu->setProgrammatically = false; + rsu->setValue(value); + rsu->setDigits(digits); + rsu->setIncrements(inc_step, inc_page); + rsu->setRange(min, max); + rsu->setProgrammatically = false; if (add_slider) { - _rsu->addSlider(); + rsu->addSlider(); } if(!overwrite_widget){ - _rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } param_effect->upd_params = false; - return dynamic_cast (_rsu); + return dynamic_cast (rsu); } else { return NULL; } @@ -191,20 +186,16 @@ ScalarParam::param_newWidget() void ScalarParam::param_set_digits(unsigned digits) { + param_effect->upd_params = true; this->digits = digits; - if (_rsu) { - _rsu->setDigits(this->digits); - } } void ScalarParam::param_set_increments(double step, double page) { + param_effect->upd_params = true; inc_step = step; inc_page = page; - if (_rsu) { - _rsu->setIncrements(inc_step, inc_page); - } } diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 63c55203e..3658bded8 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -117,7 +117,6 @@ public: void param_set_range(gdouble min, gdouble max); void param_set_digits(unsigned digits); void param_set_increments(double step, double page); - void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; void param_overwrite_widget(bool overwrite_widget); @@ -141,7 +140,6 @@ protected: private: ScalarParam(const ScalarParam&); ScalarParam& operator=(const ScalarParam&); - Inkscape::UI::Widget::RegisteredScalar *_rsu; }; } //namespace LivePathEffect -- cgit v1.2.3 From 6ac79a669ea08356806bd130d1426871473b0b71 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 16:02:08 +0200 Subject: Add options to fit on DIN (bzr r15017.1.16) --- src/live_effects/lpe-measure-line.cpp | 515 +++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 18 +- src/live_effects/parameter/text.cpp | 36 ++- src/live_effects/parameter/text.h | 4 +- 4 files changed, 387 insertions(+), 186 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6d58e2b7d..c2a502e00 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -1,7 +1,8 @@ /* * Author(s): * Jabiertxo Arraiza Cenoz - * + * Some code and ideas migrated from dimensioning.py by + * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information @@ -22,6 +23,7 @@ #include <2geom/affine.h> #include "style.h" #include "sp-root.h" +#include "sp-defs.h" #include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" @@ -50,41 +52,52 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), - offset_right_left(_("Offset right left*"), _("Offset right left"), "offset_right_left", &wr, this, 0), - offset_top_bottom(_("Offset top bottom*"), _("Offset top bottom"), "offset_top_bottom", &wr, this, 5), - gap_start(_("Gap to line from origin"), _("Gap to line from origin, without affecting measure"), "gap_start", &wr, this, 0), - gap_end(_("Gap to line from end"), _("Gap to line from end, without affecting measure"), "gap_end", &wr, this, 0), + position(_("Positon*"), _("Positon"), "position", &wr, this, 5), + text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), + helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this), - reverse(_("To other side*"), _("To other side"), "reverse", &wr, this, false), - color_as_line(_("Measure color as line*"), _("Measure color as line"), "color_as_line", &wr, this, false), + format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), + flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true) + local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), + line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) { registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); registerParameter(&scale); registerParameter(&precision); - registerParameter(&offset_right_left); - registerParameter(&offset_top_bottom); - registerParameter(&gap_start); - registerParameter(&gap_end); + registerParameter(&position); + registerParameter(&text_distance); + registerParameter(&helpline_distance); + registerParameter(&helpline_overlap); registerParameter(&unit); - registerParameter(&reverse); - registerParameter(&color_as_line); + registerParameter(&format); + registerParameter(&arrows_outside); + registerParameter(&flip_side); registerParameter(&scale_insensitive); registerParameter(&local_locale); + registerParameter(&line_group_05); + registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); - offset_right_left.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_right_left", 0.0)); - offset_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/offset_top_bottom", 5.0)); + position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); + text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); + helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - reverse.param_update_default(prefs->getBool("/live_effects/measure-line/reverse")); - color_as_line.param_update_default(prefs->getBool("/live_effects/measure-line/color_as_line")); + format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); + line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); + rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); @@ -94,18 +107,18 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked.param_set_digits(0); curve_linked.param_make_integer(true); precision.param_make_integer(true); - offset_right_left.param_set_range(-999999.0, 999999.0); - offset_right_left.param_set_increments(1, 1); - offset_right_left.param_set_digits(2); - offset_top_bottom.param_set_range(-999999.0, 999999.0); - offset_top_bottom.param_set_increments(1, 1); - offset_top_bottom.param_set_digits(2); - gap_start.param_set_range(-999999.0, 999999.0); - gap_start.param_set_increments(1, 1); - gap_start.param_set_digits(2); - gap_end.param_set_range(-999999.0, 999999.0); - gap_end.param_set_increments(1, 1); - gap_end.param_set_digits(2); + position.param_set_range(-999999.0, 999999.0); + position.param_set_increments(1, 1); + position.param_set_digits(2); + text_distance.param_set_range(-999999.0, 999999.0); + text_distance.param_set_increments(1, 1); + text_distance.param_set_digits(2); + helpline_distance.param_set_range(-999999.0, 999999.0); + helpline_distance.param_set_increments(1, 1); + helpline_distance.param_set_digits(2); + helpline_overlap.param_set_range(-999999.0, 999999.0); + helpline_overlap.param_set_increments(1, 1); + helpline_overlap.param_set_digits(2); } LPEMeasureLine::~LPEMeasureLine() {} @@ -124,7 +137,7 @@ void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -140,6 +153,213 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } } +void +LPEMeasureLine::createArrowMarker(Glib::ustring mode) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + mode).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *arrow = NULL; + if (!(elemref = SVGElemRef->getObject())) { + arrow = xml_doc->createElement("svg:marker"); + arrow->setAttribute("id", mode.c_str()); + arrow->setAttribute("inkscape:stockid", mode.c_str()); + arrow->setAttribute("orient", "auto"); + arrow->setAttribute("refX", "0.0"); + arrow->setAttribute("refY", "0.0"); + arrow->setAttribute("style", "overflow:visible"); + /* Create */ + Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); + if (mode == (Glib::ustring)"ArrowDIN-start") { + arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDIN-end") { + arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); + } else if (mode == (Glib::ustring)"ArrowDINout-start") { + arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); + } else { + arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); + } + arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); + arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + arrow->addChild(arrow_path, NULL); + Inkscape::GC::release(arrow_path); + SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + Inkscape::GC::release(arrow); + } + } +} + +void +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rtext = NULL; + doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; + if (doc_unit.empty()) { + doc_unit = "px"; + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + } else { + if (remove) { + return; + } + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + gchar * transform; + if (rotate_anotation) { + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + transform = sp_svg_transform_write(affine); + } else { + transform = NULL; + } + rtext->setAttribute("transform", transform); + SPCSSAttr *css = sp_repr_css_attr_new(); + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << std::fixed << length; + length_str << unit.get_abbreviation(); + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(length_str.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(length_str.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } + } +} + +void +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *line = NULL; + if (!main) { + Geom::Ray ray(start, end); + Geom::Coord angle = ray.angle(); + start = start + Point::polar(angle, helpline_distance ); + end = end + Point::polar(angle, helpline_overlap ); + } + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + Geom::PathVector line_pathv; + line_pathv.push_back(line_path); + gchar * line_str = sp_svg_write_path( line_pathv ); + line_pathv.clear(); + if (elemref = SVGElemRef->getObject()) { + if (remove) { + elemref->deleteObject(); + return; + } + line = elemref->getRepr(); + line->setAttribute("d" , line_str); + } else { + if (remove) { + return; + } + line = xml_doc->createElement("svg:path"); + line->setAttribute("id", id.c_str()); + line->setAttribute("d" , line_str); + } + Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; + if (main) { + line->setAttribute("inkscape:label", "dinline"); + if (arrows_outside) { + style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; + } else { + style = style + (Glib::ustring)"marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"; + } + } else { + line->setAttribute("inkscape:label", "dinhelpline"); + } + std::stringstream stroke_w; + stroke_w.imbue(std::locale::classic()); + if (line_group_05) { + double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } else { + double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + stroke_w << stroke_width; + style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + } + line->setAttribute("style", style.c_str()); + SPObject * line_obj = NULL; + if (!elemref) { + line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + Inkscape::GC::release(line); + } + } +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { @@ -147,167 +367,99 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + if (arrows_outside) { + createArrowMarker((Glib::ustring)"ArrowDINout-start"); + createArrowMarker((Glib::ustring)"ArrowDINout-end"); + } else { + createArrowMarker((Glib::ustring)"ArrowDIN-start"); + createArrowMarker((Glib::ustring)"ArrowDIN-end"); + } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); - Geom::Point s = pathvector.initialPoint(); - Geom::Point e = pathvector.finalPoint(); - if (curve_linked) { //0 start-end nodes - s = pathvector.pointAt(curve_linked -1); - e = pathvector.pointAt(curve_linked); + Geom::Point start = pathvector.initialPoint(); + Geom::Point end = pathvector.finalPoint(); + if (curve_linked) { //!0 + start = pathvector.pointAt(curve_linked -1); + end = pathvector.pointAt(curve_linked); + } + Geom::Point hstart = start; + Geom::Point hend = end; + bool remove = false; + if (Geom::are_near(hstart, hend)) { + remove = true; } - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Glib::ustring orientation_str; - Inkscape::XML::Node *rtext = NULL; if (orientation == OM_VERTICAL) { - orientation_str = "vertical"; - Coord xpos = std::max(s[Geom::X],e[Geom::X]); - if (reverse) { - xpos = std::min(s[Geom::X],e[Geom::X]); + Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); + if (flip_side) { + xpos = std::min(hstart[Geom::X],hend[Geom::X]); } - s[Geom::X] = xpos; - e[Geom::X] = xpos; - if (s[Geom::Y] > e[Geom::Y]) { - swap(s,e); + hstart[Geom::X] = xpos; + hend[Geom::X] = xpos; + if (hstart[Geom::Y] > hend[Geom::Y]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { + remove = true; } } if (orientation == OM_HORIZONTAL) { - orientation_str = "horizontal"; - Coord ypos = std::max(s[Geom::Y],e[Geom::Y]); - if (reverse) { - ypos = std::min(s[Geom::Y],e[Geom::Y]); + Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); + if (flip_side) { + ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); } - s[Geom::Y] = ypos; - e[Geom::Y] = ypos; - if (s[Geom::X] < e[Geom::X]) { - swap(s,e); + hstart[Geom::Y] = ypos; + hend[Geom::Y] = ypos; + if (hstart[Geom::X] < hend[Geom::X]) { + swap(hstart,hend); + swap(start,end); + } + if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { + remove = true; } } - if (orientation == OM_PARALLEL) { - orientation_str = "parallel"; - } - double length = Geom::distance(s, e) * scale; - Geom::Point pos = Geom::middle_point(s,e); - Geom::Ray ray(s,e); + double length = Geom::distance(start,end) * scale; + Geom::Point pos = Geom::middle_point(hstart,hend); + Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (reverse) { + if (flip_side) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Point newpos = pos - Point::polar(angle, offset_right_left); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - newpos = newpos - Point::polar(angle_cross, offset_top_bottom); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - } else { - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("id", ((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); - /* Set style */ - sp_repr_set_svg_double(rtext, "x", newpos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", newpos[Geom::Y]); - /* Create */ - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - SPCSSAttr *css = sp_repr_css_attr_new(); + //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - if (color_as_line) { - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); - } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - } else { - sp_repr_css_unset_property (css, "#000000"); - } - } else { - sp_repr_css_set_property (css, "fill", "#000000"); - } - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtspan->setAttribute("style", css_str.c_str()); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - /* Create TEXT */ + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); + createTextLabel(pos, length, angle, fontsize, remove); + //LINE + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + if (line_group_05) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); } - length_str << std::fixed << length; - length_str << unit.get_abbreviation(); - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + if (flip_side) { + arrow_gap *= -1; } - SPObject * text_obj = NULL; - if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); - Inkscape::GC::release(rtext); - } else { - text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + hstart = hstart - Point::polar(angle_cross, position); + Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(start, hstart, id, false, remove); + hend = hend - Point::polar(angle_cross, position); + id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(end, hend, id, false, remove); + if (!arrows_outside) { + hstart = hstart + Point::polar(angle, arrow_gap); + hend = hend - Point::polar(angle, arrow_gap ); } - Geom::Affine affine = Geom::Affine(Geom::Translate(newpos).inverse()); - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(newpos); - SP_ITEM(text_obj)->transform = affine * i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - text_obj->updateRepr(); + id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); + createLine(hstart, hend, id, true, remove); } } } @@ -316,11 +468,28 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(((Glib::ustring)this->getRepr()->attribute("id") + (Glib::ustring)"_text").c_str()); + Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -377,13 +546,17 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); - prefs->setDouble("/live_effects/measure-line/offset_right_left", offset_right_left); - prefs->setDouble("/live_effects/measure-line/offset_top_bottom", offset_top_bottom); + prefs->setDouble("/live_effects/measure-line/position", position); + prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); + prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setBool("/live_effects/measure-line/reverse", reverse); - prefs->setBool("/live_effects/measure-line/color_as_line", color_as_line); + prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); + prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); + prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 834194841..d54859f8c 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,6 +41,9 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: @@ -49,15 +52,18 @@ private: ScalarParam curve_linked; ScalarParam scale; ScalarParam precision; - ScalarParam offset_right_left; - ScalarParam offset_top_bottom; - ScalarParam gap_start; - ScalarParam gap_end; + ScalarParam position; + ScalarParam text_distance; + ScalarParam helpline_distance; + ScalarParam helpline_overlap; UnitParam unit; - BoolParam reverse; - BoolParam color_as_line; + TextParam format; + BoolParam arrows_outside; + BoolParam flip_side; BoolParam scale_insensitive; BoolParam local_locale; + BoolParam line_group_05; + BoolParam rotate_anotation; Glib::ustring doc_unit; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 234a6174d..e51cf93ab 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -31,7 +31,8 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, const Glib::ustring default_value ) : Parameter(label, tip, key, wr, effect), value(default_value), - defvalue(default_value) + defvalue(default_value), + _hide_canvas_text(false) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); @@ -45,10 +46,25 @@ TextParam::param_set_default() param_setValue(defvalue); } +void +TextParam::param_update_default(Glib::ustring default_value) +{ + defvalue = default_value; +} + +void +TextParam::param_hide_canvas_text() +{ + _hide_canvas_text = true; + sp_canvastext_set_text (canvas_text,""); +} + void TextParam::setPos(Geom::Point pos) { - sp_canvastext_set_coords (canvas_text, pos); + if (!_hide_canvas_text) { + sp_canvastext_set_coords (canvas_text, pos); + } } void @@ -63,9 +79,10 @@ TextParam::setPosAndAnchor(const Geom::Piecewise > &pwd2, Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); Point n = -rot90(dir); double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + if (!_hide_canvas_text) { + sp_canvastext_set_coords(canvas_text, pos + n * length); + sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); + } } void @@ -73,7 +90,9 @@ TextParam::setAnchor(double x_value, double y_value) { anchor_x = x_value; anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + if (!_hide_canvas_text) { + sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); + } } bool @@ -107,8 +126,9 @@ void TextParam::param_setValue(const Glib::ustring newvalue) { value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); + if (!_hide_canvas_text) { + sp_canvastext_set_text (canvas_text, newvalue.c_str()); + } } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 62de70eec..553c84c0a 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -40,7 +40,9 @@ public: virtual gchar * param_getSVGValue() const; void param_setValue(const Glib::ustring newvalue); + void param_hide_canvas_text(); virtual void param_set_default(); + void param_update_default(Glib::ustring default_value); void setPos(Geom::Point pos); void setPosAndAnchor(const Geom::Piecewise > &pwd2, const double t, const double length, bool use_curvature = false); @@ -53,7 +55,7 @@ private: TextParam& operator=(const TextParam&); double anchor_x; double anchor_y; - + bool _hide_canvas_text; Glib::ustring value; Glib::ustring defvalue; -- cgit v1.2.3 From cbbb526d842570fb993598537204ba7b6394d68e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 17:34:33 +0200 Subject: Font and lenght problems in diferent display units solved, also handle uniform scale viewbox (bzr r15017.1.18) --- src/live_effects/lpe-measure-line.cpp | 40 +++++++++++++++++++++++++++-------- src/live_effects/lpe-measure-line.h | 3 ++- 2 files changed, 33 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c2a502e00..716f15a5e 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -198,9 +198,30 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; - doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; - if (doc_unit.empty()) { - doc_unit = "px"; + double doc_w = desktop->getDocument()->getRoot()->width.value; +// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; +// if (doc_unit == "") { +// doc_unit = "px"; +// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { +// doc_w_unit = "px"; +// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); +// } +// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; +// if (doc_unit.empty()) { +// doc_unit = "px"; +// } + Geom::Scale scale = desktop->getDocument()->getDocumentScale(); + SPNamedView *nv = desktop->getNamedView(); + Glib::ustring display_unit = nv->display_units->abbr; + if (display_unit.empty()) { + display_unit = "px"; + } + //only check constrain viewbox on X + doc_scale = Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( doc_scale > 0 ) { + doc_scale= 1.0/doc_scale; + } else { + doc_scale = 1.0; } Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -263,7 +284,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext->addChild(rtspan, NULL); Inkscape::GC::release(rtspan); } - length = Inkscape::Util::Quantity::convert(length, doc_unit.c_str(), unit.get_abbreviation()); + length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); std::stringstream length_str; length_str.precision(precision); length_str.setf(std::ios::fixed, std::ios::floatfield); @@ -343,11 +364,11 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, std::stringstream stroke_w; stroke_w.imbue(std::locale::classic()); if (line_group_05) { - double stroke_width = Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } else { - double stroke_width = Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } @@ -419,7 +440,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) remove = true; } } - double length = Geom::distance(start,end) * scale; + double length = Geom::distance(hstart,hend) * scale; Geom::Point pos = Geom::middle_point(hstart,hend); Geom::Ray ray(hstart,hend); Geom::Coord angle = ray.angle(); @@ -432,6 +453,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; + fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); @@ -439,9 +461,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } createTextLabel(pos, length, angle, fontsize, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35, "mm", doc_unit.c_str()); + double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { - arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25, "mm", doc_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d54859f8c..581bbb7e4 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -64,7 +64,8 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; - Glib::ustring doc_unit; + Glib::ustring display_unit; + double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 5697c9788ff67d3382d9df31107daa9b7d2aacd2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 18:57:35 +0200 Subject: Rotate the text label on down position 180 degree (bzr r15017.1.19) --- src/live_effects/lpe-measure-line.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 716f15a5e..b4ad45092 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -56,7 +56,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), @@ -251,7 +251,11 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - affine *= Geom::Rotate(angle); + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + affine *= Geom::Rotate(std::abs(angle)); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -448,13 +452,17 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); double fontsize = fontdesc.get_size()/Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + } else { + pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; -- cgit v1.2.3 From 372309acc2c71ec2153f58f8ee6917ecf4d5d341 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 31 Jul 2016 19:34:59 +0200 Subject: Fix label positioning (bzr r15017.1.20) --- src/live_effects/lpe-measure-line.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b4ad45092..97da89fd1 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -199,17 +199,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; double doc_w = desktop->getDocument()->getRoot()->width.value; -// Glib::ustring doc_unit = unit_table.getUnit(desktop->getDocument()->getRoot()->width.unit)->abbr; -// if (doc_unit == "") { -// doc_unit = "px"; -// } else if (doc_unit == "%" && desktop->getDocument()->getRoot()->viewBox_set) { -// doc_w_unit = "px"; -// doc_w = desktop->getDocument()->getRoot()->viewBox.width(); -// } -// doc_unit = Inkscape::Util::unit_table.getUnit(desktop->doc()->getRoot()->height.unit)->abbr; -// if (doc_unit.empty()) { -// doc_unit = "px"; -// } Geom::Scale scale = desktop->getDocument()->getDocumentScale(); SPNamedView *nv = desktop->getNamedView(); Glib::ustring display_unit = nv->display_units->abbr; @@ -251,11 +240,13 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl gchar * transform; if (rotate_anotation) { Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } - affine *= Geom::Rotate(std::abs(angle)); + affine *= Geom::Rotate(angle); affine *= Geom::Translate(pos); transform = sp_svg_transform_write(affine); } else { @@ -458,7 +449,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; - if (std::abs(angle) > rad_from_deg(90) && std::abs(angle) < rad_from_deg(270)) { + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); } else { pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); -- cgit v1.2.3 From 28d25258de5d2274382dbb592f62e21ca8f91729 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 00:47:38 +0200 Subject: Fix text param and alow run from commandline (bzr r15017.1.21) --- src/live_effects/lpe-measure-line.cpp | 32 ++++++++++++++++++++++++-------- src/live_effects/parameter/text.cpp | 20 ++++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 97da89fd1..fc2ff0f8b 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -57,7 +57,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), - format(_("Format*"), _("Format the number ex:measure+ +unit"), "format", &wr, this, "measure+unit"), + format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), @@ -83,15 +83,27 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - fontbutton.param_update_default(prefs->getString("/live_effects/measure-line/fontbutton")); + Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); + if(fontbutton_value.empty()){ + fontbutton_value = "Sans 10"; + } + fontbutton.param_update_default(fontbutton_value); scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); - unit.param_update_default(prefs->getString("/live_effects/measure-line/unit")); - format.param_update_default(prefs->getString("/live_effects/measure-line/format")); + Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); + if(unit_value.empty()){ + unit_value = "px"; + } + unit.param_update_default(unit_value); + Glib::ustring format_value = prefs->getString("/live_effects/measure-line/format"); + if(format_value.empty()){ + format_value = "{measure}{unit}"; + } + format.param_update_default(format_value); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -391,6 +403,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createArrowMarker((Glib::ustring)"ArrowDIN-end"); } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + if (((Glib::ustring)format.param_getSVGValue()).empty()) { + format.param_setValue((Glib::ustring)"{measure}{unit}"); + this->upd_params = true; + } size_t ncurves = pathvector.curveCount(); curve_linked.param_set_range(0, ncurves); Geom::Point start = pathvector.initialPoint(); @@ -491,26 +507,26 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { SPLPEItem * splpeitem = const_cast(lpeitem); - Inkscape::URI SVGElem_uri(( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri2(( (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri3(( (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } - Inkscape::URI SVGElem_uri4(( (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); elemref = NULL; if (elemref = SVGElemRef->getObject()) { diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index e51cf93ab..0650b7e66 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -34,10 +34,13 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, defvalue(default_value), _hide_canvas_text(false) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); + } else { + _hide_canvas_text = true; + } } void @@ -55,8 +58,10 @@ TextParam::param_update_default(Glib::ustring default_value) void TextParam::param_hide_canvas_text() { - _hide_canvas_text = true; - sp_canvastext_set_text (canvas_text,""); + if (!_hide_canvas_text) { + sp_canvastext_set_text(canvas_text, " "); + _hide_canvas_text = true; + } } void @@ -113,8 +118,7 @@ TextParam::param_newWidget() { Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); + rsu->setText(value); rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); -- cgit v1.2.3 From c10966d3ebdac9c920d6329aa4eaca4d450c84da Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 10:50:36 +0200 Subject: Finish format text label (bzr r15017.1.22) --- src/live_effects/lpe-measure-line.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fc2ff0f8b..ad8a050ea 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -301,15 +301,23 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl length_str.imbue(std::locale::classic()); } length_str << std::fixed << length; - length_str << unit.get_abbreviation(); + Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); + size_t s = label_value.find((Glib::ustring)"{measure}",0); + if(s < label_value.length()) { + label_value.replace(s,s+9,length_str.str()); + } + s = label_value.find((Glib::ustring)"{unit}",0); + if(s < label_value.length()) { + label_value.replace(s,s+6,unit.get_abbreviation()); + } Inkscape::XML::Node *rstring = NULL; if (!elemref) { - rstring = xml_doc->createTextNode(length_str.str().c_str()); + rstring = xml_doc->createTextNode(label_value.c_str()); rtspan->addChild(rstring, NULL); Inkscape::GC::release(rstring); } else { rstring = rtspan->firstChild(); - rstring->setContent(length_str.str().c_str()); + rstring->setContent(label_value.c_str()); } SPObject * text_obj = NULL; if (!elemref) { -- cgit v1.2.3 From a456c94f4b7e0e385c8a5e89247065804f0abf93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:25:45 +0200 Subject: Add css override style and order widgets (bzr r15017.1.23) --- src/live_effects/lpe-measure-line.cpp | 105 ++++++++++++++++++++++++++++++---- src/live_effects/lpe-measure-line.h | 11 +++- 2 files changed, 102 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ad8a050ea..1755f0232 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -47,34 +47,39 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), + unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), + scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), - rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true) + rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), + helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), + anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), + arrows_format(_("CSS arrows*"), _("Override CSS to arrows, return to save, empty to reset DIM"), "arrows_format", &wr, this,""), + expanded(false) { + registerParameter(&unit); registerParameter(&fontbutton); registerParameter(&orientation); registerParameter(&curve_linked); - registerParameter(&scale); registerParameter(&precision); registerParameter(&position); registerParameter(&text_distance); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); - registerParameter(&unit); + registerParameter(&scale); registerParameter(&format); registerParameter(&arrows_outside); registerParameter(&flip_side); @@ -82,6 +87,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&dimline_format); + registerParameter(&helperlines_format); + registerParameter(&anotation_format); + registerParameter(&arrows_format); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); if(fontbutton_value.empty()){ @@ -104,6 +113,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : format_value = "{measure}{unit}"; } format.param_update_default(format_value); + dimline_format.param_update_default(prefs->getString("/live_effects/measure-line/dimline_format")); + helperlines_format.param_update_default(prefs->getString("/live_effects/measure-line/helperlines_format")); + anotation_format.param_update_default(prefs->getString("/live_effects/measure-line/anotation_format")); + arrows_format.param_update_default(prefs->getString("/live_effects/measure-line/arrows_format")); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); @@ -195,11 +208,31 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); } arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); - arrow_path->setAttribute("style", "fill:#000000;stroke:none"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); + } else { + Inkscape::XML::Node *arrow= elemref->getRepr(); + if (arrow) { + Inkscape::XML::Node *arrow_data = arrow->firstChild(); + if (arrow_data) { + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_data->setAttribute("style", css_str.c_str()); + } + } } } } @@ -266,26 +299,29 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } rtext->setAttribute("transform", transform); SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height", "125%"); - sp_repr_css_set_property (css, "letter-spacing", "0"); + + sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height","125%"); + sp_repr_css_set_property (css, "letter-spacing","0"); sp_repr_css_set_property (css, "word-spacing", "0"); sp_repr_css_set_property (css, "text-align", "center"); sp_repr_css_set_property (css, "text-anchor", "middle"); sp_repr_css_set_property (css, "fill", "#000000"); sp_repr_css_set_property (css, "fill-opacity", "1"); sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Glib::ustring css_str; sp_repr_css_write_string(css,css_str); if (!rtspan) { rtspan = rtext->firstChild(); } - rtspan->setAttribute("style", css_str.c_str()); + rtext->setAttribute("style", css_str.c_str()); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -387,7 +423,16 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, stroke_w << stroke_width; style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); } - line->setAttribute("style", style.c_str()); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, style.c_str()); + if (main) { + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + } else { + sp_repr_css_attr_add_from_string(css, helperlines_format.param_getSVGValue()); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + line->setAttribute("style", css_str.c_str()); SPObject * line_obj = NULL; if (!elemref) { line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); @@ -490,6 +535,12 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); + if (width_line != "-1") { + arrow_gap = 8 * atof(width_line); + } if (flip_side) { arrow_gap *= -1; } @@ -555,13 +606,23 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - vbox->pack_start(*widg, true, true, 2); + if (param->param_key != "dimline_format" && + param->param_key != "helperlines_format" && + param->param_key != "arrows_format" && + param->param_key != "anotation_format") { + vbox->pack_start(*widg, true, true, 2); + } else { + vbox_expander->pack_start(*widg, true, true, 2); + } if (tip) { widg->set_tooltip_text(*tip); } else { @@ -576,10 +637,26 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); + expander->add(*vbox_expander); + expander->set_expanded(expanded); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); + vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); return dynamic_cast(vbox); } +void +LPEMeasureLine::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Hide DIM CSS style override"))); + } else { + expander->set_label (Glib::ustring(_("Show DIM CSS style override"))); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { @@ -599,6 +676,10 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/dimline_format", (Glib::ustring)dimline_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/helperlines_format", (Glib::ustring)helperlines_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/anotation_format", (Glib::ustring)anotation_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/arrows_format", (Glib::ustring)arrows_format.param_getSVGValue()); prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 581bbb7e4..7e9bfabc7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -43,20 +43,21 @@ public: virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: + UnitParam unit; FontButtonParam fontbutton; EnumParam orientation; ScalarParam curve_linked; - ScalarParam scale; ScalarParam precision; ScalarParam position; ScalarParam text_distance; ScalarParam helpline_distance; ScalarParam helpline_overlap; - UnitParam unit; + ScalarParam scale; TextParam format; BoolParam arrows_outside; BoolParam flip_side; @@ -64,7 +65,13 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + TextParam dimline_format; + TextParam helperlines_format; + TextParam anotation_format; + TextParam arrows_format; Glib::ustring display_unit; + bool expanded; + Gtk::Expander * expander; double doc_scale; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); -- cgit v1.2.3 From fcfd11a606e3951121e2ff1cee46c60ce8d02c9b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 16:50:33 +0200 Subject: Hide canvas text from some text input (bzr r15017.1.24) --- src/live_effects/lpe-measure-line.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 1755f0232..b84169480 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -123,6 +123,10 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); format.param_hide_canvas_text(); + dimline_format.param_hide_canvas_text(); + helperlines_format.param_hide_canvas_text(); + anotation_format.param_hide_canvas_text(); + arrows_format.param_hide_canvas_text(); precision.param_set_range(0, 100); precision.param_set_increments(1, 1); precision.param_set_digits(0); -- cgit v1.2.3 From b7556c8456244e9cc884f721d8a728c1377d565e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:11:45 +0200 Subject: Noumerous bug fixes, font size, stroke with arroow position, and text input response (bzr r15017.1.25) --- src/live_effects/lpe-measure-line.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index b84169480..80d8cb645 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -518,7 +518,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/Pango::SCALE; + double fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; @@ -541,13 +541,16 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - gchar const * width_line = sp_repr_css_property(css,"stroke-width","-1"); - if (width_line != "-1") { - arrow_gap = 8 * atof(width_line); + std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); + std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + if (width_line > -0.0001) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } if (flip_side) { arrow_gap *= -1; } + std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); -- cgit v1.2.3 From 149d77a628b55077399365b420c27e7edc36d6ec Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:17:30 +0200 Subject: Remove a helper cout (bzr r15017.1.26) --- src/live_effects/lpe-measure-line.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 80d8cb645..c78475fe8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -550,7 +550,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - std::cout << arrow_gap << "arrow_gap\n"; angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); -- cgit v1.2.3 From 2bf9d069f2861ed7dce253a04c2df21a7e387b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:27:21 +0200 Subject: Fix to hidde all elements when hide the effect (bzr r15017.1.27) --- src/live_effects/lpe-measure-line.cpp | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index c78475fe8..792b0a512 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -179,6 +179,45 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) rtext->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtext = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + if (!this->isVisible()) { + rtext->setAttribute("style", "display:none"); + } else { + rtext->setAttribute("style", NULL); + } + } } } -- cgit v1.2.3 From e4f398171b8da1b990125dfc44277c886212702c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:34:14 +0200 Subject: Fixed compiling bug (bzr r15017.1.28) --- src/live_effects/lpe-measure-line.cpp | 53 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 792b0a512..5e638c4e4 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -170,52 +170,49 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::XML::Node *node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtext = NULL; + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + elemref = NULL; + node = NULL; if (elemref = SVGElemRef->getObject()) { - rtext = elemref->getRepr(); + node = elemref->getRepr(); if (!this->isVisible()) { - rtext->setAttribute("style", "display:none"); + node->setAttribute("style", "display:none"); } else { - rtext->setAttribute("style", NULL); + node->setAttribute("style", NULL); } } } -- cgit v1.2.3 From dd30b0318f3f943bab0613d8284cf8c8ad2a089a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 18:58:17 +0200 Subject: Attem to fix the locale error (bzr r15017.1.29) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 5e638c4e4..fb4530abd 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,6 +29,7 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" +#include #include // TODO due to internal breakage in glibmm headers, this must be last: -- cgit v1.2.3 From 390ac12b6a0e6bbc89e34125692d60c44546e94a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:15:46 +0200 Subject: Fix set locale to some compilers folowing su_v help (bzr r15017.1.30) --- src/live_effects/lpe-measure-line.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index fb4530abd..e9e2183e7 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -29,7 +29,6 @@ #include "sp-path.h" #include "desktop.h" #include "document.h" -#include #include // TODO due to internal breakage in glibmm headers, this must be last: @@ -578,9 +577,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - std::setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - std::setlocale(LC_NUMERIC, std::locale("").name().c_str()); + setlocale(LC_NUMERIC, std::locale("").name().c_str()); if (width_line > -0.0001) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } -- cgit v1.2.3 From 3b643ec9eff097b88dc4658a9652e67734f3d803 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Aug 2016 19:36:57 +0200 Subject: Credits improvements (bzr r15017.1.31) --- src/live_effects/lpe-measure-line.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index e9e2183e7..ddce17cdf 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -3,6 +3,7 @@ * Jabiertxo Arraiza Cenoz * Some code and ideas migrated from dimensioning.py by * Johannes B. Rutzmoser, johannes.rutzmoser (at) googlemail (dot) com + * https://github.com/Rutzmoser/inkscape_dimensioning * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information -- cgit v1.2.3 From 7275e687fcaee5608b7e53481b73cb0b3d254dbe Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 11:19:13 +0200 Subject: Add split DIN line if anottation over (bzr r15017.1.32) --- src/live_effects/lpe-measure-line.cpp | 112 ++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 9 ++- 2 files changed, 79 insertions(+), 42 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ddce17cdf..393961a13 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -54,7 +54,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), position(_("Positon*"), _("Positon"), "position", &wr, this, 5), - text_distance(_("Text distance*"), _("Text distance"), "text_distance", &wr, this, 12), + text_top_bottom(_("Text top/bottom*"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), + text_right_left(_("Text right/left*"), _("Text right/left"), "text_right_left", &wr, this, 0), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), @@ -65,6 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -77,7 +79,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&curve_linked); registerParameter(&precision); registerParameter(&position); - registerParameter(&text_distance); + registerParameter(&text_top_bottom); + registerParameter(&text_right_left); registerParameter(&helpline_distance); registerParameter(&helpline_overlap); registerParameter(&scale); @@ -88,6 +91,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); + registerParameter(&hide_back); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -101,7 +105,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); - text_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/text_distance", 5.0)); + text_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/text_top_bottom", 5.0)); helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); @@ -123,6 +127,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + hide_back.param_update_default(prefs->getBool("/live_effects/measure-line/hide_back")); format.param_hide_canvas_text(); dimline_format.param_hide_canvas_text(); helperlines_format.param_hide_canvas_text(); @@ -140,9 +145,12 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : position.param_set_range(-999999.0, 999999.0); position.param_set_increments(1, 1); position.param_set_digits(2); - text_distance.param_set_range(-999999.0, 999999.0); - text_distance.param_set_increments(1, 1); - text_distance.param_set_digits(2); + text_top_bottom.param_set_range(-999999.0, 999999.0); + text_top_bottom.param_set_increments(1, 1); + text_top_bottom.param_set_digits(2); + text_right_left.param_set_range(-999999.0, 999999.0); + text_right_left.param_set_increments(1, 1); + text_right_left.param_set_digits(2); helpline_distance.param_set_range(-999999.0, 999999.0); helpline_distance.param_set_increments(1, 1); helpline_distance.param_set_digits(2); @@ -182,8 +190,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -194,8 +200,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -206,8 +210,6 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; - node = NULL; if (elemref = SVGElemRef->getObject()) { node = elemref->getRepr(); if (!this->isVisible()) { @@ -258,7 +260,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow_path->setAttribute("style", css_str.c_str()); arrow->addChild(arrow_path, NULL); Inkscape::GC::release(arrow_path); - SPObject * arrow_obj = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); + elemref = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); } else { Inkscape::XML::Node *arrow= elemref->getRepr(); @@ -279,7 +281,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } void -LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove) +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -324,16 +326,16 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan->setAttribute("sodipodi:role", "line"); } gchar * transform; - if (rotate_anotation) { - Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - angle = std::fmod(angle, 2*M_PI); + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; - if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(pos); + } + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + if (rotate_anotation) { transform = sp_svg_transform_write(affine); } else { transform = NULL; @@ -363,6 +365,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan = rtext->firstChild(); } rtext->setAttribute("style", css_str.c_str()); + rtspan->setAttribute("style", NULL); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -396,11 +399,21 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring = rtspan->firstChild(); rstring->setContent(label_value.c_str()); } - SPObject * text_obj = NULL; if (!elemref) { - text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); Inkscape::GC::release(rtext); } + Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); + affine = Geom::Affine(Geom::Scale(1.1)); + tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); + SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); + Inkscape::GC::release(tmp_node); + tmp_obj->updateRepr(); + Geom::OptRect bounds = SP_ITEM(tmp_obj)->bounds(SPItem::GEOMETRIC_BBOX); + if (bounds) { + anotation_width = bounds->width(); + } + tmp_obj->deleteObject(); } } @@ -420,11 +433,33 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, start = start + Point::polar(angle, helpline_distance ); end = end + Point::polar(angle, helpline_overlap ); } - Geom::Path line_path; - line_path.start(start); - line_path.appendNew(end); Geom::PathVector line_pathv; - line_pathv.push_back(line_path); + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + Geom::Path line_path; + double k = 0; + if (flip_side) { + k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); + } else { + k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); + } + if (Geom::distance(start,end) < anotation_width){ + return; + } + Geom::Ray ray(end, start); + Geom::Coord angle = ray.angle(); + line_path.start(start); + line_path.appendNew(start - Point::polar(angle, k)); + line_pathv.push_back(line_path); + line_path.clear(); + line_path.start(end + Point::polar(angle, k)); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } else { + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } gchar * line_str = sp_svg_write_path( line_pathv ); line_pathv.clear(); if (elemref = SVGElemRef->getObject()) { @@ -474,9 +509,8 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, Glib::ustring css_str; sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); - SPObject * line_obj = NULL; if (!elemref) { - line_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); Inkscape::GC::release(line); } } @@ -555,24 +589,24 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } //We get the font size to offset the text to the middle Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); - double fontsize = fontdesc.get_size()/(double)Pango::SCALE; + fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); if (angle_cross < 0) angle_cross += 2*M_PI; angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (position - text_distance) + fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (position + text_distance) - fontsize/2.0); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (!scale_insensitive) { Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } - createTextLabel(pos, length, angle, fontsize, remove); + createTextLabel(pos, length, angle, remove); //LINE - double arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); } @@ -618,19 +652,16 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri2); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri3); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); SVGElemRef->attach(SVGElem_uri4); - elemref = NULL; if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } @@ -714,7 +745,7 @@ LPEMeasureLine::saveDefault() prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/position", position); - prefs->setDouble("/live_effects/measure-line/text_distance", text_distance); + prefs->setDouble("/live_effects/measure-line/text_top_bottom", text_top_bottom); prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); @@ -728,6 +759,7 @@ LPEMeasureLine::saveDefault() prefs->setBool("/live_effects/measure-line/local_locale", local_locale); prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); + prefs->setBool("/live_effects/measure-line/hide_back", hide_back); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7e9bfabc7..7819a94d7 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -42,7 +42,7 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); - void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, double fontsize, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); void saveDefault(); @@ -54,7 +54,8 @@ private: ScalarParam curve_linked; ScalarParam precision; ScalarParam position; - ScalarParam text_distance; + ScalarParam text_top_bottom; + ScalarParam text_right_left; ScalarParam helpline_distance; ScalarParam helpline_overlap; ScalarParam scale; @@ -65,6 +66,7 @@ private: BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; + BoolParam hide_back; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -73,6 +75,9 @@ private: bool expanded; Gtk::Expander * expander; double doc_scale; + double fontsize; + double anotation_width; + double arrow_gap; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From af36c60d5f160f314640b6402769779e18d9b2ef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Aug 2016 13:41:58 +0200 Subject: Add houz improvement text right/left with line out (bzr r15017.1.33) --- src/live_effects/lpe-measure-line.cpp | 62 ++++++++++++++++++++++++++++++----- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 393961a13..04085015c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -218,6 +218,16 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) node->setAttribute("style", NULL); } } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + node = elemref->getRepr(); + if (!this->isVisible()) { + node->setAttribute("style", "display:none"); + } else { + node->setAttribute("style", NULL); + } + } } } @@ -305,6 +315,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *rtspan = NULL; + pos = pos - Point::polar(angle, text_right_left); if (elemref = SVGElemRef->getObject()) { if (remove) { elemref->deleteObject(); @@ -404,7 +415,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::GC::release(rtext); } Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); - affine = Geom::Affine(Geom::Scale(1.1)); + affine = Geom::Affine(Geom::Scale(1.4)); tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); Inkscape::GC::release(tmp_node); @@ -418,7 +429,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } void -LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool remove) +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); @@ -434,7 +445,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -478,7 +489,9 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, line->setAttribute("d" , line_str); } Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; - if (main) { + if (overflow && !arrows) { + line->setAttribute("inkscape:label", "downline"); + } else if (main) { line->setAttribute("inkscape:label", "dinline"); if (arrows_outside) { style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; @@ -605,6 +618,34 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); + bool overflow = false; + if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); + if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); + } + Geom::Point prog_end = Geom::Point(); + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); + } + } else { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } + } + overflow = true; + createLine(sstart, prog_end, (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, false, false); + } else { + //erase it + createLine(Geom::Point(),Geom::Point(), (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, true, false); + } //LINE arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); if (line_group_05) { @@ -621,20 +662,18 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(start, hstart, id, false, remove); + createLine(start, hstart, id, false, false, remove); hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(end, hend, id, false, remove); + createLine(end, hend, id, false, false, remove); if (!arrows_outside) { hstart = hstart + Point::polar(angle, arrow_gap); hend = hend - Point::polar(angle, arrow_gap ); } id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(hstart, hend, id, true, remove); + createLine(hstart, hend, id, true, overflow, remove, true); } } } @@ -665,6 +704,11 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) if (elemref = SVGElemRef->getObject()) { elemref->deleteObject(); } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 7819a94d7..f9c925ef3 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -41,7 +41,7 @@ public: virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool remove); + void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); void createArrowMarker(Glib::ustring mode); -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/live_effects/effect.cpp | 19 +------------------ src/live_effects/lpe-angle_bisector.cpp | 1 - src/live_effects/lpe-attach-path.cpp | 7 ------- src/live_effects/lpe-bendpath.cpp | 16 ---------------- src/live_effects/lpe-bounding-box.cpp | 4 ---- src/live_effects/lpe-circle_3pts.cpp | 1 - src/live_effects/lpe-circle_with_radius.cpp | 1 - src/live_effects/lpe-constructgrid.cpp | 3 --- src/live_effects/lpe-copy_rotate.cpp | 4 ---- src/live_effects/lpe-curvestitch.cpp | 8 -------- src/live_effects/lpe-dynastroke.cpp | 6 ------ src/live_effects/lpe-ellipse_5pts.cpp | 1 - src/live_effects/lpe-envelope.cpp | 14 -------------- src/live_effects/lpe-extrude.cpp | 5 ----- src/live_effects/lpe-fill-between-many.cpp | 3 --- src/live_effects/lpe-fill-between-strokes.cpp | 3 --- src/live_effects/lpe-fillet-chamfer.cpp | 5 ----- src/live_effects/lpe-gears.cpp | 5 ----- src/live_effects/lpe-interpolate.cpp | 3 --- src/live_effects/lpe-interpolate_points.cpp | 2 -- src/live_effects/lpe-jointype.cpp | 4 ---- src/live_effects/lpe-knot.cpp | 7 ------- src/live_effects/lpe-lattice.cpp | 14 +------------- src/live_effects/lpe-lattice2.cpp | 15 +-------------- src/live_effects/lpe-line_segment.cpp | 4 ---- src/live_effects/lpe-mirror_symmetry.cpp | 7 ------- src/live_effects/lpe-offset.cpp | 4 ---- src/live_effects/lpe-parallel.cpp | 4 ---- src/live_effects/lpe-path_length.cpp | 2 -- src/live_effects/lpe-patternalongpath.cpp | 10 ---------- src/live_effects/lpe-perp_bisector.cpp | 3 --- src/live_effects/lpe-perspective-envelope.cpp | 1 - src/live_effects/lpe-perspective_path.cpp | 5 ----- src/live_effects/lpe-powerstroke.cpp | 15 --------------- src/live_effects/lpe-recursiveskeleton.cpp | 6 ------ src/live_effects/lpe-rough-hatches.cpp | 8 -------- src/live_effects/lpe-roughen.cpp | 5 ----- src/live_effects/lpe-ruler.cpp | 4 ---- src/live_effects/lpe-show_handles.cpp | 1 - src/live_effects/lpe-simplify.cpp | 9 --------- src/live_effects/lpe-skeleton.cpp | 4 ---- src/live_effects/lpe-sketch.cpp | 8 -------- src/live_effects/lpe-spiro.cpp | 3 --- src/live_effects/lpe-tangent_to_curve.cpp | 4 ---- src/live_effects/lpe-taperstroke.cpp | 8 -------- src/live_effects/lpe-test-doEffect-stack.cpp | 3 --- src/live_effects/lpe-transform_2pts.cpp | 3 --- src/live_effects/lpe-vonkoch.cpp | 2 -- src/live_effects/lpegroupbbox.cpp | 2 -- src/live_effects/lpeobject-reference.cpp | 1 - src/live_effects/lpeobject.cpp | 3 --- src/live_effects/spiro.cpp | 1 - 52 files changed, 3 insertions(+), 278 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 1868ca43b..ef807d586 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -8,12 +8,11 @@ //#define LPE_ENABLE_TEST_EFFECTS //uncomment for toy effects #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif // include effects: #include "live_effects/lpe-patternalongpath.h" -#include "live_effects/effect.h" #include "live_effects/lpe-angle_bisector.h" #include "live_effects/lpe-attach-path.h" #include "live_effects/lpe-bendpath.h" @@ -64,30 +63,14 @@ #include "live_effects/lpe-vonkoch.h" #include "xml/node-event-vector.h" -#include "sp-object.h" -#include "attributes.h" #include "message-stack.h" -#include "desktop.h" -#include "inkscape.h" -#include "document.h" #include "document-private.h" -#include "xml/document.h" -#include #include "ui/tools/pen-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" -#include "sp-lpe-item.h" #include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" -#include #include "display/curve.h" -#include - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/affine.h> -#include <2geom/pathvector.h> - namespace Inkscape { diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 900d29e3a..9bfbf4ca8 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -12,7 +12,6 @@ #include "live_effects/lpe-angle_bisector.h" -#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> #include "sp-lpe-item.h" diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index 21459f322..d2b44dd4e 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -10,16 +10,9 @@ #include "live_effects/lpe-attach-path.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" #include "2geom/path-sink.h" -#include "parameter/parameter.h" -#include "live_effects/parameter/point.h" -#include "parameter/originalpath.h" -#include "2geom/affine.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index bc112285f..c24d38d7b 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -6,27 +6,11 @@ */ #include "live_effects/lpe-bendpath.h" -#include "sp-shape.h" -#include "sp-item.h" -#include "sp-path.h" #include "sp-item-group.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" - -#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" -#include - -#include - using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 43a60d482..cfe1f5165 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -9,12 +9,8 @@ #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" -#include "lpe-bounding-box.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index dbb1f4b6b..18252f6a0 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -15,7 +15,6 @@ #include "live_effects/lpe-circle_3pts.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index 8f2156044..6e03cb1ce 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -15,7 +15,6 @@ #include "display/curve.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/pathvector.h> #include <2geom/circle.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index b1e0edaac..4af8891e8 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -14,9 +14,6 @@ #include "live_effects/lpe-constructgrid.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 80f5bdafd..f28ab4b31 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -15,11 +15,7 @@ #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" -#include <2geom/path.h> -#include <2geom/transforms.h> -#include <2geom/angle.h> -#include "knot-holder-entity.h" #include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 609447f26..3beedaf57 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -17,19 +17,11 @@ #include "live_effects/lpe-curvestitch.h" -#include "sp-item.h" #include "sp-path.h" #include "svg/svg.h" #include "xml/repr.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/affine.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index aeecd5d5c..7e22f6e51 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -14,14 +14,8 @@ #include "display/curve.h" //# include -#include <2geom/path.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> #include <2geom/sbasis-math.h> -#include <2geom/piecewise.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 4c953bcda..8f0f8e18a 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -15,7 +15,6 @@ // You might need to include other 2geom files. You can add them here: #include -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index e873c0b15..0ce784877 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -5,22 +5,8 @@ */ #include "live_effects/lpe-envelope.h" -#include "sp-shape.h" -#include "sp-item.h" -#include "sp-path.h" -#include "sp-item-group.h" #include "display/curve.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" -#include <2geom/sbasis.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 using std::vector; namespace Inkscape { diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8b3f4714a..22cdf3c3e 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -15,11 +15,6 @@ #include -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/transforms.h> -#include - #include "sp-item.h" namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 574ec3580..ccb9cf56d 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -9,11 +9,8 @@ #include "live_effects/lpe-fill-between-many.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" #include diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 89ea80545..b1e328d18 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -9,11 +9,8 @@ #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" -#include "sp-item.h" -#include "2geom/path.h" #include "sp-shape.h" #include "sp-text.h" -#include "2geom/bezier-curve.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 07760b172..24ee2ccc3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -17,21 +17,16 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/elliptical-arc.h> -#include <2geom/line.h> -#include "desktop.h" #include "display/curve.h" #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" #include "helper/geom.h" -#include "live_effects/parameter/filletchamferpointarray.h" - // for programmatically updating knots #include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index d4d695542..307fab6fd 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -8,14 +8,9 @@ #include "live_effects/lpe-gears.h" -#include - #include -#include <2geom/d2.h> -#include <2geom/sbasis.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/path.h> using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index 74c7efd90..43da4d105 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -14,10 +14,7 @@ #include "live_effects/lpe-interpolate.h" -#include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> #include "sp-path.h" #include "display/curve.h" diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index cf70832ee..ab0576174 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -13,8 +13,6 @@ #include "live_effects/lpe-interpolate_points.h" -#include <2geom/path.h> - #include "live_effects/lpe-powerstroke-interpolators.h" namespace Inkscape { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index fe42932be..3bfbd6288 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -10,16 +10,12 @@ #include "live_effects/parameter/enum.h" #include "helper/geom-pathstroke.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" -#include <2geom/path.h> #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index a033a6c4a..221d03ebf 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -16,7 +16,6 @@ #include "sp-path.h" #include "display/curve.h" #include "live_effects/lpe-knot.h" -#include "svg/svg.h" #include "style.h" #include "knot-holder-entity.h" #include "knotholder.h" @@ -25,20 +24,14 @@ #include #include <2geom/sbasis-to-bezier.h> -#include <2geom/sbasis.h> -#include <2geom/d2.h> -#include <2geom/path.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/basic-intersection.h> -#include <2geom/exception.h> // for change crossing undo #include "verbs.h" #include "document.h" #include "document-undo.h" -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 3c23e349e..091b6ddca 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * No� Falzon * Victor Navez * * Copyright (C) 2007-2008 Authors @@ -16,22 +16,10 @@ #include "live_effects/lpe-lattice.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 "desktop.h" // TODO: should be factored out (see below) using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index bacbe5fa7..9e9fc153a 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -6,7 +6,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * No� Falzon * Victor Navez * ~suv * Jabiertxo Arraiza @@ -17,24 +17,11 @@ */ #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 "helper/geom.h" -#include <2geom/path.h> -#include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> -#include "helper/geom-curves.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> // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index dfd8aea8f..4c9edabd4 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -14,10 +14,6 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" -#include <2geom/pathvector.h> -#include <2geom/geom.h> -#include <2geom/bezier-curve.h> - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index cf866ad6a..a7459faed 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -14,19 +14,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-mirror_symmetry.h" -#include #include #include #include "helper/geom.h" -#include <2geom/path.h> #include <2geom/path-intersection.h> -#include <2geom/transforms.h> -#include <2geom/affine.h> -#include "knot-holder-entity.h" #include "knotholder.h" -#include "inkscape.h" // TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index d611b88a1..a0fa46c3f 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -17,11 +17,7 @@ #include "sp-shape.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> #include <2geom/elliptical-arc.h> -#include <2geom/transforms.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 23cd5e2e7..9cd8ecf46 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -17,10 +17,6 @@ #include "sp-shape.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 4ca380c15..8fbf9d420 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -16,8 +16,6 @@ #include "live_effects/lpe-path_length.h" #include "util/units.h" -#include "2geom/sbasis-geometric.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 911c410f9..7d6ac10ac 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -6,22 +6,12 @@ #include "live_effects/lpe-patternalongpath.h" #include "live_effects/lpeobject.h" -#include "sp-shape.h" #include "display/curve.h" -#include "svg/svg.h" -#include "ui/widget/scalar.h" -#include <2geom/sbasis.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 "knot-holder-entity.h" #include "knotholder.h" -#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index 660318c57..f69dae6a1 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -18,10 +18,7 @@ #include "display/curve.h" #include "sp-path.h" #include "line-geometry.h" -#include "sp-lpe-item.h" -#include <2geom/path.h> -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index ae951dfc9..8a6a95f2e 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -18,7 +18,6 @@ #include "live_effects/lpe-perspective-envelope.h" #include "helper/geom.h" #include "display/curve.h" -#include "svg/svg.h" #include using namespace Geom; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index c8cdd7912..6857d4363 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -15,18 +15,13 @@ #include "persp3d.h" //#include "transf_mat_3x4.h" -#include "document.h" #include "document-private.h" #include "live_effects/lpe-perspective_path.h" #include "live_effects/lpeobject.h" -#include "sp-item-group.h" #include "knot-holder-entity.h" #include "knotholder.h" #include "desktop.h" #include -#include "inkscape.h" - -#include <2geom/path.h> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 66c8776b5..0de668847 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -13,32 +13,17 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpe-powerstroke-interpolators.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> -#include <2geom/transforms.h> -#include <2geom/bezier-utils.h> #include <2geom/elliptical-arc.h> -#include <2geom/sbasis-to-bezier.h> #include <2geom/path-sink.h> #include <2geom/path-intersection.h> -#include <2geom/crossing.h> -#include <2geom/ellipse.h> #include <2geom/circle.h> -#include <2geom/math-utils.h> #include "helper/geom.h" -#include - -#include "spiro.h" namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index ac571d963..ed0c915ce 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -14,13 +14,7 @@ #include "live_effects/lpe-recursiveskeleton.h" -#include <2geom/path.h> -#include <2geom/sbasis.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> namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 76421e0f0..2fb65b349 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -18,18 +18,10 @@ #include "sp-item.h" #include "sp-path.h" -#include "svg/svg.h" #include "xml/repr.h" -#include <2geom/path.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis.h> #include <2geom/sbasis-math.h> -#include <2geom/sbasis-geometric.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/affine.h> namespace Inkscape { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 13f2b7b51..3a486ff10 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -14,15 +14,10 @@ */ #include "live_effects/lpe-roughen.h" -#include "desktop.h" #include "display/curve.h" -#include "live_effects/parameter/parameter.h" #include #include "helper/geom.h" -#include "sp-item-group.h" -#include // TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 49b5faa2e..3a2d78b2c 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,10 +12,6 @@ */ #include "live_effects/lpe-ruler.h" -#include <2geom/piecewise.h> -#include <2geom/sbasis-geometric.h> -#include "inkscape.h" -#include "desktop.h" namespace Inkscape { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 2d4666fe4..388ea176f 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -7,7 +7,6 @@ */ #include "live_effects/lpe-show_handles.h" -#include "live_effects/parameter/parameter.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> #include "helper/geom.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index b0c1fbc23..ec21e10d2 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -4,20 +4,11 @@ #include "live_effects/lpe-simplify.h" #include "display/curve.h" -#include "live_effects/parameter/parameter.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> #include "ui/icon-names.h" -#include "util/units.h" // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 6e4afbe9b..7d34db699 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -21,13 +21,9 @@ #include "live_effects/lpe-skeleton.h" // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> #include -//#include "knot-holder-entity.h" -//#include "knotholder.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 82d343f6e..95e2f6f0d 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -16,16 +16,8 @@ #include // You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> -#include <2geom/sbasis.h> -#include <2geom/sbasis-geometric.h> #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> -#include <2geom/sbasis-math.h> -#include <2geom/piecewise.h> -#include <2geom/crossing.h> #include <2geom/path-intersection.h> namespace Inkscape { diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 0d42596b2..4a41dc5a0 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -7,9 +7,6 @@ #include "live_effects/lpe-spiro.h" #include "display/curve.h" -#include -#include <2geom/pathvector.h> -#include <2geom/affine.h> #include <2geom/curves.h> #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 978ab57fb..b308ef8d7 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -19,10 +19,6 @@ #include "sp-path.h" #include "display/curve.h" -#include <2geom/path.h> -#include <2geom/transforms.h> - -#include "knot-holder-entity.h" #include "knotholder.h" namespace Inkscape { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f2ddd4929..f6f6b33dc 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -13,28 +13,20 @@ #include "live_effects/lpe-taperstroke.h" -#include <2geom/path.h> -#include <2geom/path.h> #include <2geom/circle.h> #include <2geom/sbasis-to-bezier.h> #include "helper/geom-nodetype.h" #include "helper/geom-pathstroke.h" #include "display/curve.h" -#include "sp-shape.h" #include "style.h" -#include "xml/repr.h" -#include "sp-paint-server.h" #include "svg/svg-color.h" #include "desktop-style.h" #include "svg/css-ostringstream.h" #include "svg/svg.h" -#include "knot-holder-entity.h" #include "knotholder.h" -#include - template inline bool withinRange(T value, T low, T high) { return (value > low && value < high); diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 2bcd4c136..c7ecf6481 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -8,9 +8,6 @@ #include "live_effects/lpe-test-doEffect-stack.h" -#include <2geom/piecewise.h> -#include -#include using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..2b03a4bb2 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -14,9 +14,6 @@ #include "live_effects/lpe-transform_2pts.h" #include "display/curve.h" -#include <2geom/transforms.h> -#include <2geom/pathvector.h> -#include "sp-path.h" #include "ui/icon-names.h" #include "svg/svg.h" #include "verbs.h" diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 7eda7446e..2486f3366 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -8,8 +8,6 @@ #include -#include <2geom/transforms.h> - //using std::vector; namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 2a1b70a6a..3862ebcc8 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -7,8 +7,6 @@ #include "live_effects/lpegroupbbox.h" -#include "sp-item.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index d9de6e77f..1940806bd 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -8,7 +8,6 @@ #include -#include "enums.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/lpeobject.h" #include "uri.h" diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index 8e5ae568f..b5b27c984 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -11,13 +11,10 @@ #include "xml/repr.h" #include "xml/node-event-vector.h" -#include "sp-object.h" #include "attributes.h" #include "document.h" #include "document-private.h" -#include - //#define LIVEPATHEFFECT_VERBOSE static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index 0ac2815bf..a2ff4813e 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include "display/curve.h" -#include <2geom/math-utils.h> #define SPIRO_SHOW_INFINITE_COORDINATE_CALLS -- cgit v1.2.3 From e471a664f923f517b68071f2e33fbb6ce070f8b7 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 8 Aug 2016 13:56:40 +0100 Subject: Remove deprecated Autotools and btool files. Please use CMake instead (bzr r15046) --- src/live_effects/Makefile_insert | 115 ----------------------------- src/live_effects/parameter/Makefile_insert | 36 --------- 2 files changed, 151 deletions(-) delete mode 100644 src/live_effects/Makefile_insert delete mode 100644 src/live_effects/parameter/Makefile_insert (limited to 'src/live_effects') diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert deleted file mode 100644 index b5bee55c8..000000000 --- a/src/live_effects/Makefile_insert +++ /dev/null @@ -1,115 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -ink_common_sources += \ - live_effects/effect.cpp \ - live_effects/effect.h \ - live_effects/effect-enum.h \ - live_effects/lpeobject.cpp \ - live_effects/lpeobject.h \ - live_effects/lpegroupbbox.cpp \ - live_effects/lpegroupbbox.h \ - live_effects/lpeobject-reference.cpp \ - live_effects/lpeobject-reference.h \ - live_effects/lpe-patternalongpath.cpp \ - live_effects/lpe-patternalongpath.h \ - live_effects/lpe-bendpath.cpp \ - live_effects/lpe-bendpath.h \ - live_effects/lpe-dynastroke.cpp \ - live_effects/lpe-dynastroke.h \ - live_effects/lpe-extrude.cpp \ - live_effects/lpe-extrude.h \ - live_effects/lpe-sketch.cpp \ - live_effects/lpe-sketch.h \ - live_effects/lpe-knot.cpp \ - live_effects/lpe-knot.h \ - live_effects/lpe-vonkoch.cpp \ - live_effects/lpe-vonkoch.h \ - live_effects/lpe-rough-hatches.cpp \ - live_effects/lpe-rough-hatches.h \ - live_effects/lpe-curvestitch.cpp \ - live_effects/lpe-curvestitch.h \ - live_effects/lpe-constructgrid.cpp \ - live_effects/lpe-constructgrid.h \ - live_effects/lpe-fillet-chamfer.cpp \ - live_effects/lpe-fillet-chamfer.h \ - live_effects/lpe-gears.cpp \ - live_effects/lpe-gears.h \ - live_effects/lpe-interpolate.cpp \ - live_effects/lpe-interpolate.h \ - live_effects/lpe-interpolate_points.cpp \ - live_effects/lpe-interpolate_points.h \ - live_effects/lpe-test-doEffect-stack.cpp \ - live_effects/lpe-test-doEffect-stack.h \ - live_effects/lpe-bspline.cpp \ - 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-roughen.cpp \ - live_effects/lpe-roughen.h \ - live_effects/lpe-show_handles.cpp \ - live_effects/lpe-show_handles.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 \ - live_effects/lpe-spiro.h \ - live_effects/lpe-tangent_to_curve.cpp \ - live_effects/lpe-tangent_to_curve.h \ - live_effects/lpe-perp_bisector.cpp \ - live_effects/lpe-perp_bisector.h \ - live_effects/spiro.h \ - live_effects/spiro.cpp \ - live_effects/spiro-converters.h \ - live_effects/spiro-converters.cpp \ - live_effects/lpe-circle_with_radius.cpp \ - live_effects/lpe-circle_with_radius.h \ - live_effects/lpe-perspective_path.cpp \ - live_effects/lpe-perspective_path.h \ - live_effects/lpe-perspective-envelope.cpp \ - live_effects/lpe-perspective-envelope.h \ - live_effects/lpe-mirror_symmetry.cpp \ - live_effects/lpe-mirror_symmetry.h \ - live_effects/lpe-circle_3pts.cpp \ - live_effects/lpe-circle_3pts.h \ - live_effects/lpe-transform_2pts.cpp \ - live_effects/lpe-transform_2pts.h \ - live_effects/lpe-angle_bisector.cpp \ - live_effects/lpe-angle_bisector.h \ - live_effects/lpe-parallel.cpp \ - live_effects/lpe-parallel.h \ - live_effects/lpe-copy_rotate.cpp \ - live_effects/lpe-copy_rotate.h \ - live_effects/lpe-powerstroke.cpp \ - live_effects/lpe-powerstroke.h \ - live_effects/lpe-powerstroke-interpolators.h \ - live_effects/lpe-offset.cpp \ - live_effects/lpe-offset.h \ - live_effects/lpe-clone-original.cpp \ - live_effects/lpe-clone-original.h \ - live_effects/lpe-ruler.cpp \ - live_effects/lpe-ruler.h \ - live_effects/lpe-recursiveskeleton.cpp \ - live_effects/lpe-recursiveskeleton.h \ - live_effects/lpe-text_label.cpp \ - live_effects/lpe-text_label.h \ - live_effects/lpe-path_length.cpp \ - live_effects/lpe-path_length.h \ - live_effects/lpe-line_segment.cpp \ - live_effects/lpe-line_segment.h \ - live_effects/lpe-bounding-box.cpp \ - live_effects/lpe-bounding-box.h \ - live_effects/lpe-attach-path.cpp \ - live_effects/lpe-attach-path.h \ - live_effects/lpe-fill-between-strokes.cpp \ - live_effects/lpe-fill-between-strokes.h \ - live_effects/lpe-fill-between-many.cpp \ - live_effects/lpe-fill-between-many.h \ - live_effects/lpe-ellipse_5pts.cpp \ - live_effects/lpe-ellipse_5pts.h \ - live_effects/lpe-jointype.cpp \ - live_effects/lpe-jointype.h \ - live_effects/lpe-taperstroke.cpp \ - live_effects/lpe-taperstroke.h diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert deleted file mode 100644 index bd1c5b600..000000000 --- a/src/live_effects/parameter/Makefile_insert +++ /dev/null @@ -1,36 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -ink_common_sources += \ - live_effects/parameter/parameter.cpp \ - live_effects/parameter/parameter.h \ - live_effects/parameter/array.cpp \ - live_effects/parameter/array.h \ - live_effects/parameter/bool.cpp \ - live_effects/parameter/bool.h \ - live_effects/parameter/random.cpp \ - live_effects/parameter/random.h \ - live_effects/parameter/point.cpp \ - live_effects/parameter/point.h \ - live_effects/parameter/enum.h \ - live_effects/parameter/path-reference.cpp \ - live_effects/parameter/path-reference.h \ - live_effects/parameter/path.cpp \ - live_effects/parameter/path.h \ - live_effects/parameter/originalpath.cpp \ - live_effects/parameter/originalpath.h \ - live_effects/parameter/originalpatharray.cpp \ - live_effects/parameter/originalpatharray.h \ - live_effects/parameter/powerstrokepointarray.cpp \ - live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/filletchamferpointarray.cpp \ - live_effects/parameter/filletchamferpointarray.h \ - live_effects/parameter/text.cpp \ - 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 \ - live_effects/parameter/vector.h -- cgit v1.2.3 From e1a84ff6c44588f7847258b5eb5266365e0738e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 29 Aug 2016 15:27:55 +0200 Subject: Fixes to helper paths. evaluate backport to 0.92.x (bzr r15086) --- src/live_effects/effect.cpp | 13 +++++++++++++ src/live_effects/effect.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index ef807d586..033eb8955 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -66,6 +66,7 @@ #include "message-stack.h" #include "document-private.h" #include "ui/tools/pen-tool.h" +#include "ui/tools/node-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" #include "live_effects/lpeobject.h" @@ -454,6 +455,7 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); } + update_helperpath(); } /** @@ -643,6 +645,17 @@ Effect::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector(desktop->event_context); + nt->update_helperpath(); + } + } +} /** * This *creates* a new widget, management of deletion should be done by the caller diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..840f723fa 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -102,6 +102,7 @@ public: virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); std::vector getCanvasIndicators(SPLPEItem const* lpeitem); + void update_helperpath(); inline bool providesOwnFlashPaths() const { return provides_own_flash_paths || show_orig_path; -- cgit v1.2.3 From 3a70c702b97414c4508c6871462d1fa4f1433ad7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 29 Aug 2016 18:15:30 +0200 Subject: Add comment and fix in helper paths (bzr r15087) --- src/live_effects/effect.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 033eb8955..fd1b8e3ec 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -645,6 +645,9 @@ Effect::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector Date: Mon, 29 Aug 2016 18:26:57 +0200 Subject: Fix some comment typos (bzr r15088) --- src/live_effects/effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index fd1b8e3ec..007a8ca38 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -646,7 +646,7 @@ Effect::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector Date: Mon, 29 Aug 2016 19:35:32 +0200 Subject: Fix a bug in pattern along path at first edit node after applied. Backport it to 0.92 (bzr r15089) --- src/live_effects/lpe-bendpath.cpp | 14 +++++++++----- src/live_effects/lpe-bendpath.h | 2 +- src/live_effects/lpe-patternalongpath.cpp | 17 ++++++++++------- src/live_effects/lpe-patternalongpath.h | 1 + 4 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index c24d38d7b..2ba1e32b4 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -67,6 +67,7 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : _provides_knotholder_entities = true; apply_to_clippath_and_mask = true; concatenate_before_pwd2 = true; + _prop_scale_store = prop_scale; } LPEBendPath::~LPEBendPath() @@ -80,6 +81,9 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); + if(_prop_scale_store != prop_scale) { + prop_scale.param_set_value(_prop_scale_store); + } } Geom::Piecewise > @@ -120,9 +124,9 @@ LPEBendPath::doEffect_pwd2 (Geom::Piecewise > const & pwd } if ( scale_y_rel.get_value() ) { - y*=(scaling*prop_scale); + y*=(scaling*_prop_scale_store); } else { - if (prop_scale != 1.0) y *= prop_scale; + if (_prop_scale_store != 1.0) y *= _prop_scale_store; } Piecewise > output = compose(uskeleton,x) + y*compose(n,x); @@ -184,9 +188,9 @@ KnotHolderEntityWidthBendPath::knot_set(Geom::Point const &p, Geom::Point const& Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); if(nearest_to_ray == 0){ - lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); + lpe->_prop_scale_store = -Geom::distance(s , ptA)/(lpe->original_height/2.0); } else { - lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + lpe->_prop_scale_store = Geom::distance(s , ptA)/(lpe->original_height/2.0); } sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); @@ -207,7 +211,7 @@ KnotHolderEntityWidthBendPath::knot_get() const ray.setPoints(ptA,(*cubic)[1]); } ray.setAngle(ray.angle() + Geom::rad_from_deg(90)); - Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->_prop_scale_store) + ptA; bp_helper_path.clear(); Geom::Path hp(result_point); diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index eeda86a5e..36789bb15 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -58,7 +58,7 @@ private: BoolParam vertical_pattern; Geom::Piecewise > uskeleton; Geom::Piecewise > n; - + double _prop_scale_store; void on_pattern_pasted(); LPEBendPath(const LPEBendPath&); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 7d6ac10ac..0814ce0da 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -95,7 +95,7 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : prop_scale.param_set_increments(0.01, 0.10); _provides_knotholder_entities = true; - + _prop_scale_store = prop_scale; } LPEPatternAlongPath::~LPEPatternAlongPath() @@ -111,6 +111,9 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) if (bbox) { original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); } + if(_prop_scale_store != prop_scale) { + prop_scale.param_set_value(_prop_scale_store); + } } Geom::Piecewise > @@ -213,9 +216,9 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con x*=scaling; } if ( scale_y_rel.get_value() ) { - y*=(scaling*prop_scale); + y*=(scaling*_prop_scale_store); } else { - if (prop_scale != 1.0) y *= prop_scale; + if (_prop_scale_store != 1.0) y *= _prop_scale_store; } x += toffset; @@ -253,7 +256,7 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool transform_stroke = prefs ? prefs->getBool("/options/transform/stroke", true) : true; if (transform_stroke && !scale_y_rel) { - prop_scale.param_set_value(prop_scale * ((postmul.expansionX() + postmul.expansionY()) / 2)); + prop_scale.param_set_value(_prop_scale_store * ((postmul.expansionX() + postmul.expansionY()) / 2)); } if (postmul.isTranslation()) { pattern.param_transform_multiply(postmul, set); @@ -299,9 +302,9 @@ KnotHolderEntityWidthPatternAlongPath::knot_set(Geom::Point const &p, Geom::Poin Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); if(nearest_to_ray == 0){ - lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); + lpe->_prop_scale_store = -Geom::distance(s , ptA)/(lpe->original_height/2.0); } else { - lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); + lpe->_prop_scale_store = Geom::distance(s , ptA)/(lpe->original_height/2.0); } } @@ -325,7 +328,7 @@ KnotHolderEntityWidthPatternAlongPath::knot_get() const ray.setPoints(ptA, (*cubic)[1]); } ray.setAngle(ray.angle() + Geom::rad_from_deg(90)); - Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->_prop_scale_store) + ptA; pap_helper_path.clear(); Geom::Path hp(result_point); diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 3d7fc02bc..eedf4c172 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -61,6 +61,7 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; + double _prop_scale_store; void on_pattern_pasted(); LPEPatternAlongPath(const LPEPatternAlongPath&); -- cgit v1.2.3 From d5fc5796665d580a13a2048049108dc7cb1ee01e Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 3 Sep 2016 01:56:26 +0300 Subject: Remove extraneous checks for truth/false. Convert to a plain var-access or the "!" operator. (bzr r15100.1.5) --- src/live_effects/lpe-envelope.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 0ce784877..c3b0a7c10 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -47,7 +47,7 @@ Geom::Piecewise > LPEEnvelope::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { - if(xx.get_value() == false && yy.get_value() == false) + if(!xx.get_value() && !yy.get_value()) { return pwd2_in; } @@ -158,7 +158,7 @@ LPEEnvelope::doEffect_pwd2 (Geom::Piecewise > const & pwd output_y = ybis*(compose((uskeleton1),x1) + y1*compose(n1,x1) ) + y*(compose((uskeleton3),x3) + y3*compose(n3,x3) ); output_y /= (boundingbox_Y.extent()); - if(xx.get_value() == false && yy.get_value() == true) + if(!xx.get_value() && yy.get_value()) { return output_y; } @@ -167,13 +167,13 @@ LPEEnvelope::doEffect_pwd2 (Geom::Piecewise > const & pwd output_x = x*(compose((uskeleton2),y2) + -x2*compose(n2,y2) ) + xbis*(compose((uskeleton4),y4) + -x4*compose(n4,y4) ); output_x /= (boundingbox_X.extent()); - if(xx.get_value() == true && yy.get_value() == false) + if(xx.get_value() && !yy.get_value()) { return output_x; } /*output : Deformation by Up, Left, Right and Down Bend Paths*/ - if(xx.get_value() == true && yy.get_value() == true) + if(xx.get_value() && yy.get_value()) { Piecewise xsqr = x*xbis; /* xsqr = x * (BBox_X - x) */ Piecewise ysqr = y*ybis; /* xsqr = y * (BBox_Y - y) */ -- cgit v1.2.3 From 0711d958cefd7acfa36b8d2f7e556afd95c04941 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 4 Sep 2016 17:28:07 +0200 Subject: Fix bug#744612 Fixed bugs: - https://launchpad.net/bugs/744612 (bzr r15104) --- src/live_effects/lpe-gears.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 307fab6fd..fc5327257 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -248,6 +248,9 @@ LPEGears::doEffect_path (Geom::PathVector const &path_in) path_out.push_back( gear->path()); for (++it; it != gearpath.end() ; ++it) { + if (are_near((*it).initialPoint(), (*it).finalPoint())) { + continue; + } // iterate through Geom::Curve in path_in Gear* gearnew = new Gear(gear->spawn( (*it).finalPoint() )); path_out.push_back( gearnew->path() ); -- cgit v1.2.3 From 707c97e59e42f890e1f70ed8c92614db105cf7e0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 5 Sep 2016 08:11:03 +0200 Subject: Bug#744612. Add minimun radius value to minimize hangs Fixed bugs: - https://launchpad.net/bugs/744612 (bzr r15105) --- src/live_effects/lpe-gears.cpp | 17 +++++++++++------ src/live_effects/lpe-gears.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index fc5327257..1d5398aa5 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -207,7 +207,8 @@ namespace LivePathEffect { LPEGears::LPEGears(LivePathEffectObject *lpeobject) : Effect(lpeobject), teeth(_("_Teeth:"), _("The number of teeth"), "teeth", &wr, this, 10), - phi(_("_Phi:"), _("Tooth pressure angle (typically 20-25 deg). The ratio of teeth not in contact."), "phi", &wr, this, 5) + phi(_("_Phi:"), _("Tooth pressure angle (typically 20-25 deg). The ratio of teeth not in contact."), "phi", &wr, this, 5), + min_radius(_("Min Radius:"), _("Minimun radius, low balues can slow"), "min_radius", &wr, this, 5.0) { /* Tooth pressure angle: The angle between the tooth profile and a perpendicular to the pitch * circle, usually at the point where the pitch circle meets the tooth profile. Standard angles @@ -218,8 +219,10 @@ LPEGears::LPEGears(LivePathEffectObject *lpeobject) : teeth.param_make_integer(); teeth.param_set_range(3, 1e10); - registerParameter( dynamic_cast(&teeth) ); - registerParameter( dynamic_cast(&phi) ); + min_radius.param_set_range(0.01, 9999.0); + registerParameter(&teeth); + registerParameter(&phi); + registerParameter(&min_radius); } LPEGears::~LPEGears() @@ -242,11 +245,13 @@ LPEGears::doEffect_path (Geom::PathVector const &path_in) gear->angle(atan2((*it).initialPoint() - gear_centre)); ++it; - if ( it == gearpath.end() ) return path_out; - gear->pitch_radius(Geom::distance(gear_centre, (*it).finalPoint())); + if ( it == gearpath.end() ) return path_out; + double radius = Geom::distance(gear_centre, (*it).finalPoint()); + radius = radius < min_radius?min_radius:radius; + gear->pitch_radius(radius); path_out.push_back( gear->path()); - + for (++it; it != gearpath.end() ; ++it) { if (are_near((*it).initialPoint(), (*it).finalPoint())) { continue; diff --git a/src/live_effects/lpe-gears.h b/src/live_effects/lpe-gears.h index 5dd6dd239..57b49d2b5 100644 --- a/src/live_effects/lpe-gears.h +++ b/src/live_effects/lpe-gears.h @@ -27,6 +27,7 @@ public: private: ScalarParam teeth; ScalarParam phi; + ScalarParam min_radius; LPEGears(const LPEGears&); LPEGears& operator=(const LPEGears&); -- cgit v1.2.3 From 1c5f5f06cff3fd162208e4e59c3b937cc7790f04 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 9 Sep 2016 14:09:07 +0200 Subject: Fix bug: #1621213 in Pattern Along Path LPE Fixed bugs: - https://launchpad.net/bugs/1621213 (bzr r15110) --- src/live_effects/lpe-patternalongpath.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 0814ce0da..f90ac2b70 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -11,6 +11,7 @@ #include <2geom/bezier-to-sbasis.h> #include "knotholder.h" +#include using std::vector; @@ -195,12 +196,12 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con case PAPCT_REPEATED_STRETCHED: // if uskeleton is closed: if(path_i.segs.front().at0() == path_i.segs.back().at1()){ - nbCopies = static_cast(std::floor((uskeleton.domain().extent() - toffset)/(pattBndsX->extent()+xspace))); + nbCopies = std::max(1, static_cast(std::floor((uskeleton.domain().extent() - toffset)/(pattBndsX->extent()+xspace)))); pattBndsX = Interval(pattBndsX->min(),pattBndsX->max()+xspace); scaling = (uskeleton.domain().extent() - toffset)/(((double)nbCopies)*pattBndsX->extent()); // if not closed: no space at the end }else{ - nbCopies = static_cast(std::floor((uskeleton.domain().extent() - toffset + xspace)/(pattBndsX->extent()+xspace))); + nbCopies = std::max(1, static_cast(std::floor((uskeleton.domain().extent() - toffset + xspace)/(pattBndsX->extent()+xspace)))); pattBndsX = Interval(pattBndsX->min(),pattBndsX->max()+xspace); scaling = (uskeleton.domain().extent() - toffset)/(((double)nbCopies)*pattBndsX->extent() - xspace); } -- cgit v1.2.3 From d16ce258120800e84bfca5c3c687c25177a3137c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 11 Sep 2016 12:10:44 +0200 Subject: Fix bugs: #1621234 and #172137 Fixed bugs: - https://launchpad.net/bugs/172137 - https://launchpad.net/bugs/1621234 (bzr r15111) --- src/live_effects/lpe-bendpath.cpp | 14 +++++--------- src/live_effects/lpe-bendpath.h | 2 +- src/live_effects/lpe-patternalongpath.cpp | 21 ++++++++++----------- src/live_effects/lpe-patternalongpath.h | 1 - 4 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 2ba1e32b4..c24d38d7b 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -67,7 +67,6 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : _provides_knotholder_entities = true; apply_to_clippath_and_mask = true; concatenate_before_pwd2 = true; - _prop_scale_store = prop_scale; } LPEBendPath::~LPEBendPath() @@ -81,9 +80,6 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); - if(_prop_scale_store != prop_scale) { - prop_scale.param_set_value(_prop_scale_store); - } } Geom::Piecewise > @@ -124,9 +120,9 @@ LPEBendPath::doEffect_pwd2 (Geom::Piecewise > const & pwd } if ( scale_y_rel.get_value() ) { - y*=(scaling*_prop_scale_store); + y*=(scaling*prop_scale); } else { - if (_prop_scale_store != 1.0) y *= _prop_scale_store; + if (prop_scale != 1.0) y *= prop_scale; } Piecewise > output = compose(uskeleton,x) + y*compose(n,x); @@ -188,9 +184,9 @@ KnotHolderEntityWidthBendPath::knot_set(Geom::Point const &p, Geom::Point const& Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); if(nearest_to_ray == 0){ - lpe->_prop_scale_store = -Geom::distance(s , ptA)/(lpe->original_height/2.0); + lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); } else { - lpe->_prop_scale_store = Geom::distance(s , ptA)/(lpe->original_height/2.0); + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); } sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); @@ -211,7 +207,7 @@ KnotHolderEntityWidthBendPath::knot_get() const ray.setPoints(ptA,(*cubic)[1]); } ray.setAngle(ray.angle() + Geom::rad_from_deg(90)); - Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->_prop_scale_store) + ptA; + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; bp_helper_path.clear(); Geom::Path hp(result_point); diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 36789bb15..eeda86a5e 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -58,7 +58,7 @@ private: BoolParam vertical_pattern; Geom::Piecewise > uskeleton; Geom::Piecewise > n; - double _prop_scale_store; + void on_pattern_pasted(); LPEBendPath(const LPEBendPath&); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index f90ac2b70..0785da235 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -96,7 +96,7 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : prop_scale.param_set_increments(0.01, 0.10); _provides_knotholder_entities = true; - _prop_scale_store = prop_scale; + } LPEPatternAlongPath::~LPEPatternAlongPath() @@ -112,9 +112,6 @@ LPEPatternAlongPath::doBeforeEffect (SPLPEItem const* lpeitem) if (bbox) { original_height = (*bbox)[Geom::Y].max() - (*bbox)[Geom::Y].min(); } - if(_prop_scale_store != prop_scale) { - prop_scale.param_set_value(_prop_scale_store); - } } Geom::Piecewise > @@ -217,9 +214,9 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con x*=scaling; } if ( scale_y_rel.get_value() ) { - y*=(scaling*_prop_scale_store); + y*=(scaling*prop_scale); } else { - if (_prop_scale_store != 1.0) y *= _prop_scale_store; + if (prop_scale != 1.0) y *= prop_scale; } x += toffset; @@ -257,10 +254,12 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool transform_stroke = prefs ? prefs->getBool("/options/transform/stroke", true) : true; if (transform_stroke && !scale_y_rel) { - prop_scale.param_set_value(_prop_scale_store * ((postmul.expansionX() + postmul.expansionY()) / 2)); - } + prop_scale.param_set_value(prop_scale * ((postmul.expansionX() + postmul.expansionY()) / 2)); + prop_scale.write_to_SVG(); + } if (postmul.isTranslation()) { pattern.param_transform_multiply(postmul, set); + pattern.write_to_SVG(); } sp_lpe_item_update_patheffect (sp_lpe_item, false, true); } @@ -303,9 +302,9 @@ KnotHolderEntityWidthPatternAlongPath::knot_set(Geom::Point const &p, Geom::Poin Geom::Point knot_pos = this->knot->pos * item->i2dt_affine().inverse(); Geom::Coord nearest_to_ray = ray.nearestTime(knot_pos); if(nearest_to_ray == 0){ - lpe->_prop_scale_store = -Geom::distance(s , ptA)/(lpe->original_height/2.0); + lpe->prop_scale.param_set_value(-Geom::distance(s , ptA)/(lpe->original_height/2.0)); } else { - lpe->_prop_scale_store = Geom::distance(s , ptA)/(lpe->original_height/2.0); + lpe->prop_scale.param_set_value(Geom::distance(s , ptA)/(lpe->original_height/2.0)); } } @@ -329,7 +328,7 @@ KnotHolderEntityWidthPatternAlongPath::knot_get() const ray.setPoints(ptA, (*cubic)[1]); } ray.setAngle(ray.angle() + Geom::rad_from_deg(90)); - Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->_prop_scale_store) + ptA; + Geom::Point result_point = Geom::Point::polar(ray.angle(), (lpe->original_height/2.0) * lpe->prop_scale) + ptA; pap_helper_path.clear(); Geom::Path hp(result_point); diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index eedf4c172..3d7fc02bc 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -61,7 +61,6 @@ private: BoolParam prop_units; BoolParam vertical_pattern; ScalarParam fuse_tolerance; - double _prop_scale_store; void on_pattern_pasted(); LPEPatternAlongPath(const LPEPatternAlongPath&); -- cgit v1.2.3 From efef5e86d229e8fe2022d6178f3da02b17ab7896 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 23 Sep 2016 23:47:26 +0200 Subject: Fix bug pointed in inkscape devel by Miguel Lopez and CR. Caution now rotate copies and perspective envelope store in a better way the dropdown widgets -enums- (bzr r15124) --- src/live_effects/lpe-mirror_symmetry.cpp | 17 ++++++++++------- src/live_effects/lpe-perspective-envelope.cpp | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a7459faed..69bfaab9a 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -25,11 +25,11 @@ namespace Inkscape { namespace LivePathEffect { static const Util::EnumData ModeTypeData[MT_END] = { - { MT_V, N_("Vertical Page Center"), "Vertical Page Center, use select tool to move item instead line" }, - { MT_H, N_("Horizontal Page Center"), "Horizontal Page Center, use select tool to move item instead line" }, - { MT_FREE, N_("Free from reflection line"), "Free from path" }, - { MT_X, N_("X from middle knot"), "X from middle knot" }, - { MT_Y, N_("Y from middle knot"), "Y from middle knot" } + { MT_V, N_("Vertical Page Center"), "vertical" }, + { MT_H, N_("Horizontal Page Center"), "horizontale" }, + { MT_FREE, N_("Free from reflection line"), "free" }, + { MT_X, N_("X from middle knot"), "X" }, + { MT_Y, N_("Y from middle knot"), "Y" } }; static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); @@ -178,6 +178,9 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); + if (hyp == 0) { + hyp = 0.000001; + } double c = (point_b[0] - point_a[0]) / hyp; // cos(alpha) double s = (point_b[1] - point_a[1]) / hyp; // sin(alpha) @@ -292,8 +295,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (!fuse_paths || discard_orig_path) { - for (int i = 0; i < static_cast(path_in.size()); ++i) { - path_out.push_back(path_in[i] * m); + for (size_t i = 0; i < original_pathv.size(); ++i) { + path_out.push_back(original_pathv[i] * m); } } diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 8a6a95f2e..6a6b59519 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -31,8 +31,8 @@ enum DeformationType { }; static const Util::EnumData DeformationTypeData[] = { - {DEFORMATION_PERSPECTIVE , N_("Perspective"), "Perspective"}, - {DEFORMATION_ENVELOPE , N_("Envelope deformation"), "Envelope deformation"} + {DEFORMATION_PERSPECTIVE , N_("Perspective"), "perspective"}, + {DEFORMATION_ENVELOPE , N_("Envelope deformation"), "envelope_deformation"} }; static const Util::EnumDataConverter DeformationTypeConverter(DeformationTypeData, sizeof(DeformationTypeData)/sizeof(*DeformationTypeData)); -- cgit v1.2.3 From c1a2006fd8f82aace5415027f6d94e137d990875 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Sep 2016 09:51:04 +0200 Subject: Code improvements on mirror symmetry (bzr r15125) --- src/live_effects/lpe-mirror_symmetry.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 69bfaab9a..a9fb36626 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -178,13 +178,13 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); - if (hyp == 0) { - hyp = 0.000001; + double cos = 0; + double sen = 0; + if (hyp > 0) { + cos = (point_b[0] - point_a[0]) / hyp; + sen = (point_b[1] - point_a[1]) / hyp; } - double c = (point_b[0] - point_a[0]) / hyp; // cos(alpha) - double s = (point_b[1] - point_a[1]) / hyp; // sin(alpha) - - Geom::Affine m2(c, -s, s, c, 0.0, 0.0); + Geom::Affine m2(cos, -sen, sen, cos, 0.0, 0.0); Geom::Scale sca(1.0, -1.0); Geom::Affine m = m1.inverse() * m2; -- cgit v1.2.3 From 77adf166cf949efcd02d1b19225fc788a3479186 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Sep 2016 10:00:43 +0200 Subject: Typo fix for name var (bzr r15126) --- src/live_effects/lpe-mirror_symmetry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a9fb36626..afb7e2230 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -179,12 +179,12 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); double cos = 0; - double sen = 0; + double sin = 0; if (hyp > 0) { cos = (point_b[0] - point_a[0]) / hyp; - sen = (point_b[1] - point_a[1]) / hyp; + sin = (point_b[1] - point_a[1]) / hyp; } - Geom::Affine m2(cos, -sen, sen, cos, 0.0, 0.0); + Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); Geom::Scale sca(1.0, -1.0); Geom::Affine m = m1.inverse() * m2; -- cgit v1.2.3 From 47dfdcc650d9faaec121088fac69aa69d54299c3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Sep 2016 12:21:14 +0200 Subject: Fix bug 1627202 on mirror symmetry wrong results on transforms Fixed bugs: - https://launchpad.net/bugs/1627202 (bzr r15127) --- src/live_effects/lpe-mirror_symmetry.cpp | 14 +++++++++++++- src/live_effects/lpe-mirror_symmetry.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index afb7e2230..fc13415fd 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -87,7 +87,7 @@ void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; - + original_bbox(lpeitem); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); @@ -144,6 +144,18 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) previous_center = center_point; } +void +LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) +{ + center_point *= postmul; + previous_center = center_point; + // cycle through all parameters. Most parameters will not need transformation, but path and point params do. + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); + } +} + void LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 9e5b4d628..7ec4029e0 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -46,6 +46,7 @@ public: virtual ~LPEMirrorSymmetry(); virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; -- cgit v1.2.3 From 8cf7cf4a53027f31865afec8e6c4233bf8487ccb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Sep 2016 21:19:24 +0200 Subject: Fix a typo bug (bzr r15129) --- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index fc13415fd..4deb29d8f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -26,7 +26,7 @@ namespace LivePathEffect { static const Util::EnumData ModeTypeData[MT_END] = { { MT_V, N_("Vertical Page Center"), "vertical" }, - { MT_H, N_("Horizontal Page Center"), "horizontale" }, + { MT_H, N_("Horizontal Page Center"), "horizontal" }, { MT_FREE, N_("Free from reflection line"), "free" }, { MT_X, N_("X from middle knot"), "X" }, { MT_Y, N_("Y from middle knot"), "Y" } -- cgit v1.2.3 From 67fa2b7c2a26e909b1adb5fb188285367dfba7e4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 3 Oct 2016 23:35:23 +0200 Subject: Fix merge bugs (bzr r15017.1.36) --- src/live_effects/lpe-measure-line.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 04085015c..6e77931b0 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -161,6 +161,11 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} +void swap(Geom::Point &A, Geom::Point &B){ + Geom::Point tmp = A; + A = B; + B = tmp; +} void LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) { -- cgit v1.2.3 From 5a0f38c94489c344e66b0a4441668ea02e3361d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 4 Oct 2016 17:32:38 +0200 Subject: Fix scaling bug (bzr r15017.1.37) --- src/live_effects/lpe-measure-line.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 6e77931b0..57e67ab3a 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -541,6 +541,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); + pathvector *= affinetransform; if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); createArrowMarker((Glib::ustring)"ArrowDINout-end"); @@ -618,9 +621,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } - if (!scale_insensitive) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(desktop->doc()->getRoot())); - length *= (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_insensitive) { + length *= (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; } createTextLabel(pos, length, angle, remove); bool overflow = false; -- cgit v1.2.3 From 98f6a39975eef4b0d711e13b6743e494347d8ae0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 00:08:23 +0200 Subject: add lock (bzr r15017.1.39) --- src/live_effects/lpe-measure-line.cpp | 62 +++++++++++++++-------------------- src/live_effects/lpe-measure-line.h | 2 +- 2 files changed, 28 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 4780fb817..434dc484c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -67,7 +67,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - lock_measure(_("Lock measure data"), _("Lock measure data to avoid problems on transforms"), "lock_measure", &wr, this, true), + unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&lock_measure); + registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -256,10 +256,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); @@ -288,10 +288,10 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (lock_measure) { - arrow->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { arrow->setAttribute("sodipodi:insensitive", NULL); + } else { + arrow->setAttribute("sodipodi:insensitive", "true"); } Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { @@ -339,16 +339,14 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl elemref->deleteObject(); return; } -// Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(elemref)->parent, SP_OBJECT(desktop->doc()->getRoot())); -// pos *= affinetransform; pos = pos - Point::polar(angle, text_right_left); rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } } else { if (remove) { @@ -357,10 +355,10 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (lock_measure) { - rtext->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { rtext->setAttribute("sodipodi:insensitive", NULL); + } else { + rtext->setAttribute("sodipodi:insensitive", "true"); } pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); @@ -477,11 +475,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, end = end + Point::polar(angle, helpline_overlap ); } Geom::PathVector line_pathv; - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(sp_lpe_item)->parent, SP_OBJECT(doc->getRoot())); - double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - if (main && std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ Geom::Path line_path; double k = 0; if (flip_side) { @@ -526,10 +520,10 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (lock_measure) { - line->setAttribute("sodipodi:insensitive", "true"); - } else { + if (unlock_measure) { line->setAttribute("sodipodi:insensitive", NULL); + } else { + line->setAttribute("sodipodi:insensitive", "true"); } line_pathv.clear(); @@ -583,8 +577,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DOCUMENT; Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem)->parent, SP_OBJECT(doc->getRoot())); double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - double current_text_top_bottom = text_top_bottom / parents_scale; - double current_position = position / parents_scale; Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); pathvector *= affinetransform; @@ -661,9 +653,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (current_position - current_text_top_bottom) + fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); } else { - pos = pos - Point::polar(angle_cross, (current_position + current_text_top_bottom) - fontsize/2.5); + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } if (scale_insensitive) { length *= parents_scale; @@ -671,14 +663,14 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createTextLabel(pos, length, angle, remove); bool overflow = false; if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { - Geom::Point sstart = end - Point::polar(angle_cross, current_position); - Geom::Point send = end - Point::polar(angle_cross, current_position); + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { - sstart = start - Point::polar(angle_cross, current_position); - send = start - Point::polar(angle_cross, current_position); + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); } Geom::Point prog_end = Geom::Point(); - if (std::abs(current_text_top_bottom) < fontsize/1.5 && hide_back) { + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { if (text_right_left > 0 ) { prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } else { @@ -713,10 +705,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (flip_side) { arrow_gap *= -1; } - hstart = hstart - Point::polar(angle_cross, current_position); + hstart = hstart - Point::polar(angle_cross, position); Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(start, hstart, id, false, false, remove); - hend = hend - Point::polar(angle_cross, current_position); + hend = hend - Point::polar(angle_cross, position); id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); createLine(end, hend, id, false, false, remove); if (!arrows_outside) { diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 83fef26b8..999d53af0 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -67,7 +67,7 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam lock_measure; + BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; -- cgit v1.2.3 From 124c2b96d76984dd9fe7a4db0f9b8738ea3ba657 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 5 Oct 2016 18:51:40 +0200 Subject: add button to release measures (bzr r15017.1.40) --- src/live_effects/lpe-measure-line.cpp | 85 +++++++++++++++++++++++------------ src/live_effects/lpe-measure-line.h | 3 +- src/live_effects/lpeobject.h | 10 ++++- 3 files changed, 67 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 434dc484c..e8ceb7e51 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -10,6 +10,7 @@ */ #include "live_effects/lpe-measure-line.h" #include +#include "ui/dialog/livepatheffect-editor.h" #include #include "inkscape.h" #include "xml/node.h" @@ -21,7 +22,7 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" -#include <2geom/affine.h> +#include "2geom/affine.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -67,7 +68,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - unlock_measure(_("Unlock measure data"), _("Unlock measure data maybe give problems on transforms"), "unlock_measure", &wr, this, false), dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), @@ -93,7 +93,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&line_group_05); registerParameter(&rotate_anotation); registerParameter(&hide_back); - registerParameter(&unlock_measure); registerParameter(&dimline_format); registerParameter(&helperlines_format); registerParameter(&anotation_format); @@ -159,6 +158,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_range(-999999.0, 999999.0); helpline_overlap.param_set_increments(1, 1); helpline_overlap.param_set_digits(2); + erase = true; } LPEMeasureLine::~LPEMeasureLine() {} @@ -256,11 +256,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); arrow->setAttribute("style", "overflow:visible"); - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); if (mode == (Glib::ustring)"ArrowDIN-start") { @@ -288,11 +284,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } else { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { - if (unlock_measure) { - arrow->setAttribute("sodipodi:insensitive", NULL); - } else { - arrow->setAttribute("sodipodi:insensitive", "true"); - } + arrow->setAttribute("sodipodi:insensitive", "true"); Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { SPCSSAttr *css = sp_repr_css_attr_new(); @@ -343,11 +335,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = elemref->getRepr(); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); } else { if (remove) { return; @@ -355,11 +343,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - if (unlock_measure) { - rtext->setAttribute("sodipodi:insensitive", NULL); - } else { - rtext->setAttribute("sodipodi:insensitive", "true"); - } + rtext->setAttribute("sodipodi:insensitive", "true"); pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); @@ -520,11 +504,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } - if (unlock_measure) { - line->setAttribute("sodipodi:insensitive", NULL); - } else { - line->setAttribute("sodipodi:insensitive", "true"); - } + line->setAttribute("sodipodi:insensitive", "true"); line_pathv.clear(); Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; @@ -723,6 +703,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { + if (!erase) return; + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -754,6 +736,48 @@ void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) } } +void LPEMeasureLine::toObjects() +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri3); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri4); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri5); + if (elemref = SVGElemRef->getObject()) { + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + } + erase = false; + sp_lpe_item->removeCurrentPathEffect(true); + //TODO: find better way to refresh effect list + if (SP_IS_OBJECT(sp_lpe_item)){ + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection->remove(SP_OBJECT(sp_lpe_item)); + selection->add(SP_OBJECT(sp_lpe_item)); + } + } +} + Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -766,6 +790,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::HBox * button2 = Gtk::manage(new Gtk::HBox(true,0)); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox_expander->set_border_width(0); vbox_expander->set_spacing(2); @@ -797,12 +822,16 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); + Gtk::Button *remove = Gtk::manage(new Gtk::Button(Glib::ustring(_("Convert to objects")))); + remove->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::toObjects)); + button2->pack_start(*remove, true, true, 2); expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); + vbox->pack_start(*button2, true, true, 2); return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 999d53af0..2fab9dbb9 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -44,6 +44,7 @@ public: void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); void onExpanderChanged(); + void toObjects(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -67,7 +68,6 @@ private: BoolParam line_group_05; BoolParam rotate_anotation; BoolParam hide_back; - BoolParam unlock_measure; TextParam dimline_format; TextParam helperlines_format; TextParam anotation_format; @@ -79,6 +79,7 @@ private: double fontsize; double anotation_width; double arrow_gap; + bool erase; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpeobject.h b/src/live_effects/lpeobject.h index 2e62707e3..087223947 100644 --- a/src/live_effects/lpeobject.h +++ b/src/live_effects/lpeobject.h @@ -38,8 +38,14 @@ public: /* Note that the returned pointer can be NULL in a valid LivePathEffectObject contained in a valid list of lpeobjects in an lpeitem! * So one should always check whether the returned value is NULL or not */ - Inkscape::LivePathEffect::Effect * get_lpe() { return lpe; }; - Inkscape::LivePathEffect::Effect const * get_lpe() const { return lpe; }; + Inkscape::LivePathEffect::Effect * get_lpe() { + if(this) return lpe; + else return NULL; + } + Inkscape::LivePathEffect::Effect const * get_lpe() const { + if(this) return lpe; + else return NULL; + }; Inkscape::LivePathEffect::Effect *lpe; // this can be NULL in a valid LivePathEffectObject -- cgit v1.2.3 From e64d416e42f8361036d9a31dff5b646810f69e97 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 8 Oct 2016 02:03:08 +0200 Subject: Fix bug:1622321 on powerstroke Fixed bugs: - https://launchpad.net/bugs/1622321 (bzr r15154) --- src/live_effects/lpe-powerstroke.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 0de668847..329a00756 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -609,11 +609,12 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) // find time values for which x lies outside path domain // and only take portion of x and y that lies within those time values std::vector< double > rtsmin = roots (x - pwd2_in.domain().min()); - std::vector< double > rtsmax = roots (x - pwd2_in.domain().max()); + std::vector< double > rtsmax = roots (x + pwd2_in.domain().max()); if ( !rtsmin.empty() && !rtsmax.empty() ) { x = portion(x, rtsmin.at(0), rtsmax.at(0)); y = portion(y, rtsmin.at(0), rtsmax.at(0)); } + LineJoinType jointype = static_cast(linejoin_type.get_value()); Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); -- cgit v1.2.3 From 9a88fdf01355bf46200c68dfed53078aaf5e58ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 22 Oct 2016 21:27:22 +0200 Subject: Fix bug#1635442 Fixed bugs: - https://launchpad.net/bugs/1635442 (bzr r15186) --- src/live_effects/lpe-copy_rotate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f28ab4b31..1133e083a 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -58,7 +58,7 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), - origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), + origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), -- cgit v1.2.3 From 6813c18d7497f999fdf326e2746f8ba7c0c9da99 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 2 Nov 2016 15:49:37 +0100 Subject: Close the bounding box path LPE (bzr r15197) --- src/live_effects/lpe-bounding-box.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index cfe1f5165..2de768c3a 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -41,6 +41,7 @@ void LPEBoundingBox::doEffect (SPCurve * curve) p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->top())); + p.close(); Geom::PathVector out; out.push_back(p); curve->set_pathvector(out); -- cgit v1.2.3 From b49cad5aefd16b340307056a5e959a62548a8fe1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 2 Nov 2016 16:02:59 +0100 Subject: Fix fill between many LPE to start up with current path (bzr r15198) --- src/live_effects/lpe-fill-between-many.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index ccb9cf56d..2087925fa 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -57,6 +57,9 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) if (!res_pathv.empty()) { res_pathv.front().close(); } + if (res_pathv.empty()) { + res_pathv = curve->get_pathvector(); + } curve->set_pathvector(res_pathv); } -- cgit v1.2.3 From 88b914c8f65f78e31ae591bc00f09cf3192f502d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 18 Nov 2016 18:59:18 +0100 Subject: Fix #1627817. Bug in knot LPE Fixed bugs: - https://launchpad.net/bugs/1627817 (bzr r15259) --- src/live_effects/lpe-knot.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index fbc32cf3e..474523aa3 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -26,6 +26,7 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/basic-intersection.h> +#include "helper/geom.h" // for change crossing undo #include "verbs.h" @@ -392,14 +393,14 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) if (gpaths.size()==0){ return path_in; } - - for (unsigned comp=0; compgetCurve(); } if (c) { - Geom::PathVector subpaths = c->get_pathvector(); + Geom::PathVector subpaths = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); for (unsigned i=0; i Date: Mon, 21 Nov 2016 12:06:29 +0100 Subject: Fix #1643408. Bug in pap LPE Fixed bugs: - https://launchpad.net/bugs/1643408 (bzr r15263) --- src/live_effects/lpe-patternalongpath.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 0785da235..f9bad0610 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -142,7 +142,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con double xspace = spacing; double noffset = normal_offset; double toffset = tang_offset; - if (prop_units.get_value() && pattBndsY){ + if (prop_units.get_value()){ xspace *= pattBndsX->extent(); noffset *= pattBndsY->extent(); toffset *= pattBndsX->extent(); @@ -171,7 +171,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con Piecewise > uskeleton = arc_length_parametrization(path_i,2,.1); uskeleton = remove_short_cuts(uskeleton,.01); Piecewise > n = rot90(derivative(uskeleton)); - n = force_continuity(remove_short_cuts(n,.1)); + n = force_continuity(remove_short_cuts(n,.1),.01); int nbCopies = 0; double scaling = 1; @@ -210,16 +210,14 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con double pattWidth = pattBndsX->extent() * scaling; - if (scaling != 1.0) { - x*=scaling; - } + x*=scaling; if ( scale_y_rel.get_value() ) { - y*=(scaling*prop_scale); + y*=(scaling * prop_scale); } else { - if (prop_scale != 1.0) y *= prop_scale; + y *= prop_scale; } x += toffset; - + double offs = 0; for (int i=0; i 0){ -- cgit v1.2.3 From f3bb5718c8e82b984a5a9894d6c12a4919912412 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 29 Nov 2016 10:17:38 +0100 Subject: Fixes transforms bug in meassure line LPE pointed in IRC by CR and suv (bzr r15284) --- src/live_effects/lpe-measure-line.cpp | 51 ++++++++++++++++++++++------------- src/live_effects/lpe-measure-line.h | 3 ++- 2 files changed, 34 insertions(+), 20 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index e8ceb7e51..ed655ff38 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -63,7 +63,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), - scale_insensitive(_("Scale insensitive*"), _("Scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + scale_insensitive(_("Scale insensitive*"), _("Costrained scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), @@ -285,11 +285,13 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { arrow->setAttribute("sodipodi:insensitive", "true"); + arrow->setAttribute("transform", NULL); Inkscape::XML::Node *arrow_data = arrow->firstChild(); if (arrow_data) { SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property (css, "fill","#000000"); sp_repr_css_set_property (css, "stroke","none" ); + arrow_data->setAttribute("transform", NULL); sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); Glib::ustring css_str; sp_repr_css_write_string(css,css_str); @@ -301,11 +303,12 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } void -LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove) +LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; + SPRoot * root = desktop->getDocument()->getRoot(); double doc_w = desktop->getDocument()->getRoot()->width.value; Geom::Scale scale = desktop->getDocument()->getDocumentScale(); SPNamedView *nv = desktop->getNamedView(); @@ -325,7 +328,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { if (remove) { elemref->deleteObject(); @@ -336,6 +338,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("transform", NULL); } else { if (remove) { return; @@ -373,7 +376,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); sp_repr_css_set_property (css, "line-height","125%"); sp_repr_css_set_property (css, "letter-spacing","0"); @@ -391,6 +393,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } rtext->setAttribute("style", css_str.c_str()); rtspan->setAttribute("style", NULL); + rtspan->setAttribute("transform", NULL); sp_repr_css_attr_unref (css); if (!elemref) { rtext->addChild(rtspan, NULL); @@ -415,6 +418,9 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl if(s < label_value.length()) { label_value.replace(s,s+6,unit.get_abbreviation()); } + if ( !valid ) { + label_value = Glib::ustring(_("Non Uniform Scale")); + } Inkscape::XML::Node *rstring = NULL; if (!elemref) { rstring = xml_doc->createTextNode(label_value.c_str()); @@ -425,20 +431,13 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring->setContent(label_value.c_str()); } if (!elemref) { - elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + elemref = root->appendChildRepr(rtext); Inkscape::GC::release(rtext); } - Inkscape::XML::Node *tmp_node = rtext->duplicate(xml_doc); - affine = Geom::Affine(Geom::Scale(1.4)); - tmp_node->setAttribute("transform", sp_svg_transform_write(affine)); - SPObject * tmp_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(tmp_node)); - Inkscape::GC::release(tmp_node); - tmp_obj->updateRepr(); - Geom::OptRect bounds = SP_ITEM(tmp_obj)->bounds(SPItem::GEOMETRIC_BBOX); + Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { - anotation_width = bounds->width(); + anotation_width = bounds->width() * 1.4; } - tmp_obj->deleteObject(); } } @@ -449,6 +448,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SPRoot * root = desktop->getDocument()->getRoot(); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *line = NULL; @@ -495,6 +495,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); + line->setAttribute("transform", NULL); } else { if (remove) { return; @@ -542,12 +543,18 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); if (!elemref) { - elemref = SP_OBJECT(desktop->currentLayer()->appendChildRepr(line)); + elemref = root->appendChildRepr(line); Inkscape::GC::release(line); } } } +void +LPEMeasureLine::transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) +{ + sp_lpe_item_update_patheffect (sp_lpe_item, false, true); +} + void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { @@ -555,10 +562,11 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { SPDocument * doc = SP_ACTIVE_DOCUMENT; - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem)->parent, SP_OBJECT(doc->getRoot())); - double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); + Geom::Affine writed_transform = Geom::identity(); + sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); + pathvector *= writed_transform.inverse(); pathvector *= affinetransform; if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); @@ -637,10 +645,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } + double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; if (scale_insensitive) { length *= parents_scale; } - createTextLabel(pos, length, angle, remove); + if (scale_insensitive && !affinetransform.preservesAngles()) { + createTextLabel(pos, length, angle, remove, false); + } else { + createTextLabel(pos, length, angle, remove, true); + } bool overflow = false; if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { Geom::Point sstart = end - Point::polar(angle_cross, position); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 2fab9dbb9..d5e98b5b3 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -40,9 +40,10 @@ public: virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); + void transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); - void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove); + void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); void toObjects(); void createArrowMarker(Glib::ustring mode); -- cgit v1.2.3 From 94086e16b6daf9d363569271022e97fb5dac07ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 29 Nov 2016 11:47:17 +0100 Subject: Reorganize SVG Structure have clean meassure line structure (bzr r15285) --- src/live_effects/lpe-measure-line.cpp | 140 ++++++++++++---------------------- src/live_effects/lpe-measure-line.h | 3 +- 2 files changed, 49 insertions(+), 94 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ed655ff38..17ebeef84 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -181,59 +181,12 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *node = NULL; - if (elemref = SVGElemRef->getObject()) { - node = elemref->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } - } - Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri2); - if (elemref = SVGElemRef->getObject()) { - node = elemref->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } - } - Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri3); - if (elemref = SVGElemRef->getObject()) { - node = elemref->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } - } - Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri4); - if (elemref = SVGElemRef->getObject()) { - node = elemref->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } - } - Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri5); - if (elemref = SVGElemRef->getObject()) { - node = elemref->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } + if (meassure_data) { + Inkscape::XML::Node *node = meassure_data->getRepr(); + if (!this->isVisible()) { + node->setAttribute("style", "display:none"); + } else { + node->setAttribute("style", NULL); } } } @@ -308,7 +261,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *rtext = NULL; - SPRoot * root = desktop->getDocument()->getRoot(); double doc_w = desktop->getDocument()->getRoot()->width.value; Geom::Scale scale = desktop->getDocument()->getDocumentScale(); SPNamedView *nv = desktop->getNamedView(); @@ -431,7 +383,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring->setContent(label_value.c_str()); } if (!elemref) { - elemref = root->appendChildRepr(rtext); + elemref = meassure_data->appendChildRepr(rtext); Inkscape::GC::release(rtext); } Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); @@ -441,6 +393,41 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } } +void +LPEMeasureLine::createMeasureStructure() +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#LPE_helper_layer").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (!(elemref = SVGElemRef->getObject())) { + SPRoot * root = desktop->doc()->getRoot(); + Inkscape::XML::Node *container_layer = NULL; + container_layer = xml_doc->createElement("svg:g"); + container_layer->setAttribute("inkscape:groupmode", "layer"); + container_layer->setAttribute("inkscape:label", _("LPE Helper Layer")); + container_layer->setAttribute("id", _("LPE_helper_layer")); + elemref = root->appendChildRepr(container_layer); + Inkscape::GC::release(container_layer); + } + elemref->setAttribute("transform", NULL); + Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"meassure-line-data-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + SVGElemRef->attach(SVGElem_uri2); + meassure_data = NULL; + if (!(meassure_data = SVGElemRef->getObject())) { + Inkscape::XML::Node *meassure_data_node = NULL; + meassure_data_node = xml_doc->createElement("svg:g"); + meassure_data_node->setAttribute("id", ((Glib::ustring)"meassure-line-data-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + meassure_data = elemref->appendChildRepr(meassure_data_node); + Inkscape::GC::release(meassure_data_node); + } + meassure_data->setAttribute("sodipodi:insensitive", "true"); + meassure_data->setAttribute("transform", NULL); + } +} + void LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) { @@ -448,7 +435,6 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SPRoot * root = desktop->getDocument()->getRoot(); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *line = NULL; @@ -543,18 +529,12 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); if (!elemref) { - elemref = root->appendChildRepr(line); + elemref = meassure_data->appendChildRepr(line); Inkscape::GC::release(line); } } } -void -LPEMeasureLine::transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) -{ - sp_lpe_item_update_patheffect (sp_lpe_item, false, true); -} - void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { @@ -568,6 +548,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); pathvector *= writed_transform.inverse(); pathvector *= affinetransform; + createMeasureStructure(); if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); createArrowMarker((Glib::ustring)"ArrowDINout-end"); @@ -717,42 +698,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) { if (!erase) return; - - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } - Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri2); - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } - Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri3); - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } - Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri4); - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } - Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri5); - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } + if (meassure_data) { + meassure_data->deleteObject(); } } void LPEMeasureLine::toObjects() { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - + meassure_data->setAttribute("sodipodi:insensitive", NULL); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d5e98b5b3..0909b03be 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -40,10 +40,10 @@ public: virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* lpeitem); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); - void transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); + void createMeasureStructure(); void onExpanderChanged(); void toObjects(); void createArrowMarker(Glib::ustring mode); @@ -81,6 +81,7 @@ private: double anotation_width; double arrow_gap; bool erase; + SPObject * meassure_data; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From 69ba226147751a529c9561925b2737fa3071ecd2 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 3 Dec 2016 20:05:32 +0100 Subject: Improvements and fixes for buds pointed by suv on measure line LPE (bzr r15294) --- src/live_effects/effect.cpp | 1 + src/live_effects/effect.h | 1 + src/live_effects/lpe-measure-line.cpp | 213 +++++++++++++++------------------- src/live_effects/lpe-measure-line.h | 16 ++- 4 files changed, 107 insertions(+), 124 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 792bb5d7a..41b7d8c2c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -350,6 +350,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) oncanvasedit_it(0), is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), show_orig_path(false), + erase_extra_objects(true), lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 5ca53486c..06aa075eb 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -123,6 +123,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; + bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; protected: diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 17ebeef84..9238f2571 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -47,6 +47,9 @@ static const Util::EnumData OrientationMethodData[] = { }; static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); +std::vector ml_elements; +SPObject * container; + LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), @@ -63,7 +66,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), - scale_insensitive(_("Scale insensitive*"), _("Costrained scale insensitive to transforms in element, parents..."), "scale_insensitive", &wr, this, true), + scale_sensitive(_("Scale sensitive*"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), @@ -88,7 +91,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&format); registerParameter(&arrows_outside); registerParameter(&flip_side); - registerParameter(&scale_insensitive); + registerParameter(&scale_sensitive); registerParameter(&local_locale); registerParameter(&line_group_05); registerParameter(&rotate_anotation); @@ -124,7 +127,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : anotation_format.param_update_default(prefs->getString("/live_effects/measure-line/anotation_format")); arrows_format.param_update_default(prefs->getString("/live_effects/measure-line/arrows_format")); flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); - scale_insensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_insensitive")); + scale_sensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_sensitive")); local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); @@ -158,7 +161,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_range(-999999.0, 999999.0); helpline_overlap.param_set_increments(1, 1); helpline_overlap.param_set_digits(2); - erase = true; } LPEMeasureLine::~LPEMeasureLine() {} @@ -168,28 +170,6 @@ void swap(Geom::Point &A, Geom::Point &B){ A = B; B = tmp; } -void -LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) -{ - if (!SP_IS_SHAPE(lpeitem)) { - g_warning("LPE measure line can only be applied to shapes (not groups)."); - SPLPEItem * item = const_cast(lpeitem); - item->removeCurrentPathEffect(false); - } -} - -void -LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) -{ - if (meassure_data) { - Inkscape::XML::Node *node = meassure_data->getRepr(); - if (!this->isVisible()) { - node->setAttribute("style", "display:none"); - } else { - node->setAttribute("style", NULL); - } - } -} void LPEMeasureLine::createArrowMarker(Glib::ustring mode) @@ -252,6 +232,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } } } + ml_elements.push_back(mode); } } @@ -275,7 +256,8 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } else { doc_scale = 1.0; } - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + Glib::ustring id = (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id"); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -383,9 +365,18 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring->setContent(label_value.c_str()); } if (!elemref) { - elemref = meassure_data->appendChildRepr(rtext); + elemref = container->appendChildRepr(rtext); Inkscape::GC::release(rtext); - } + } else if (elemref->parent != container) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id.c_str()); + elemref = elemref_copy; + } + ml_elements.push_back(id); Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { anotation_width = bounds->width() * 1.4; @@ -393,41 +384,6 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } } -void -LPEMeasureLine::createMeasureStructure() -{ - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#LPE_helper_layer").c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (!(elemref = SVGElemRef->getObject())) { - SPRoot * root = desktop->doc()->getRoot(); - Inkscape::XML::Node *container_layer = NULL; - container_layer = xml_doc->createElement("svg:g"); - container_layer->setAttribute("inkscape:groupmode", "layer"); - container_layer->setAttribute("inkscape:label", _("LPE Helper Layer")); - container_layer->setAttribute("id", _("LPE_helper_layer")); - elemref = root->appendChildRepr(container_layer); - Inkscape::GC::release(container_layer); - } - elemref->setAttribute("transform", NULL); - Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"meassure-line-data-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri2); - meassure_data = NULL; - if (!(meassure_data = SVGElemRef->getObject())) { - Inkscape::XML::Node *meassure_data_node = NULL; - meassure_data_node = xml_doc->createElement("svg:g"); - meassure_data_node->setAttribute("id", ((Glib::ustring)"meassure-line-data-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - meassure_data = elemref->appendChildRepr(meassure_data_node); - Inkscape::GC::release(meassure_data_node); - } - meassure_data->setAttribute("sodipodi:insensitive", "true"); - meassure_data->setAttribute("transform", NULL); - } -} - void LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) { @@ -529,9 +485,27 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); if (!elemref) { - elemref = meassure_data->appendChildRepr(line); + elemref = container->appendChildRepr(line); Inkscape::GC::release(line); - } + } else if (elemref->parent != container) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id.c_str()); + } + ml_elements.push_back(id); + } +} + +void +LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) +{ + if (!SP_IS_SHAPE(lpeitem)) { + g_warning("LPE measure line can only be applied to shapes (not groups)."); + SPLPEItem * item = const_cast(lpeitem); + item->removeCurrentPathEffect(false); } } @@ -539,16 +513,20 @@ void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { SPLPEItem * splpeitem = const_cast(lpeitem); + container = dynamic_cast(splpeitem->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; + } SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { - SPDocument * doc = SP_ACTIVE_DOCUMENT; Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); Geom::Affine writed_transform = Geom::identity(); sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); - pathvector *= writed_transform.inverse(); - pathvector *= affinetransform; - createMeasureStructure(); + pathvector *= writed_transform; if (arrows_outside) { createArrowMarker((Glib::ustring)"ArrowDINout-start"); createArrowMarker((Glib::ustring)"ArrowDINout-end"); @@ -626,11 +604,11 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } else { pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); } - double parents_scale = (affinetransform.inverse().expansionX() + affinetransform.inverse().expansionY()) / 2.0; - if (scale_insensitive) { + double parents_scale = (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_sensitive) { length *= parents_scale; } - if (scale_insensitive && !affinetransform.preservesAngles()) { + if (scale_sensitive && !affinetransform.preservesAngles()) { createTextLabel(pos, length, angle, remove, false); } else { createTextLabel(pos, length, angle, remove, true); @@ -695,52 +673,56 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } -void LPEMeasureLine::doOnRemove (SPLPEItem const* lpeitem) + +void +LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + processObjects(MA_VISIBILITY); +} + +void +LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - if (!erase) return; - if (meassure_data) { - meassure_data->deleteObject(); + if (!erase_extra_objects) { + processObjects(MA_TO_OBJECTS); + ml_elements.clear(); + return; } + processObjects(MA_ERASE); } -void LPEMeasureLine::toObjects() +void +LPEMeasureLine::processObjects(MeasureAction measure_action) { + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - meassure_data->setAttribute("sodipodi:insensitive", NULL); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - } - Inkscape::URI SVGElem_uri2(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri2); - if (elemref = SVGElemRef->getObject()) { - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - } - Inkscape::URI SVGElem_uri3(((Glib::ustring)"#" + (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri3); - if (elemref = SVGElemRef->getObject()) { - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - } - Inkscape::URI SVGElem_uri4(((Glib::ustring)"#" + (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri4); - if (elemref = SVGElemRef->getObject()) { - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - } - Inkscape::URI SVGElem_uri5(((Glib::ustring)"#" + (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); - SVGElemRef->attach(SVGElem_uri5); - if (elemref = SVGElemRef->getObject()) { - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + for (std::vector::iterator el_it = ml_elements.begin(); + el_it != ml_elements.end();++el_it) { + Glib::ustring id = *el_it; + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + switch (measure_action){ + case MA_TO_OBJECTS: + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + break; + case MA_ERASE: + elemref->deleteObject(); + break; + default: //MA_VISIBILITY + if (!this->isVisible()) { + elemref->getRepr()->setAttribute("style", "display:none"); + } else { + elemref->getRepr()->setAttribute("style", NULL); + } + break; + } + } } - erase = false; - sp_lpe_item->removeCurrentPathEffect(true); - //TODO: find better way to refresh effect list - if (SP_IS_OBJECT(sp_lpe_item)){ - Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); - selection->remove(SP_OBJECT(sp_lpe_item)); - selection->add(SP_OBJECT(sp_lpe_item)); + if (measure_action == MA_ERASE) { + ml_elements.clear(); } } } @@ -757,7 +739,6 @@ Gtk::Widget *LPEMeasureLine::newWidget() std::vector::iterator it = param_vector.begin(); Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::HBox * button2 = Gtk::manage(new Gtk::HBox(true,0)); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox_expander->set_border_width(0); vbox_expander->set_spacing(2); @@ -789,16 +770,12 @@ Gtk::Widget *LPEMeasureLine::newWidget() Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); button1->pack_start(*save_default, true, true, 2); - Gtk::Button *remove = Gtk::manage(new Gtk::Button(Glib::ustring(_("Convert to objects")))); - remove->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::toObjects)); - button2->pack_start(*remove, true, true, 2); expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); vbox->pack_start(*button1, true, true, 2); - vbox->pack_start(*button2, true, true, 2); return dynamic_cast(vbox); } @@ -837,7 +814,7 @@ LPEMeasureLine::saveDefault() prefs->setString("/live_effects/measure-line/anotation_format", (Glib::ustring)anotation_format.param_getSVGValue()); prefs->setString("/live_effects/measure-line/arrows_format", (Glib::ustring)arrows_format.param_getSVGValue()); prefs->setBool("/live_effects/measure-line/flip_side", flip_side); - prefs->setBool("/live_effects/measure-line/scale_insensitive", scale_insensitive); + prefs->setBool("/live_effects/measure-line/scale_sensitive", scale_sensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 0909b03be..fe327c89b 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -32,20 +32,25 @@ enum OrientationMethod { OM_END }; +enum MeasureAction { + MA_ERASE = 0, + MA_TO_OBJECTS. + MA_VISIBILITY +}; + class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); - virtual void doOnRemove (SPLPEItem const* lpeitem); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); + void processObjects(MeasureAction measure_action); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); - void createMeasureStructure(); void onExpanderChanged(); - void toObjects(); void createArrowMarker(Glib::ustring mode); void saveDefault(); virtual Gtk::Widget *newWidget(); @@ -64,7 +69,7 @@ private: TextParam format; BoolParam arrows_outside; BoolParam flip_side; - BoolParam scale_insensitive; + BoolParam scale_sensitive; BoolParam local_locale; BoolParam line_group_05; BoolParam rotate_anotation; @@ -80,8 +85,7 @@ private: double fontsize; double anotation_width; double arrow_gap; - bool erase; - SPObject * meassure_data; + /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From e3556efba77bf72acba893418f7b51caab84360b Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 3 Dec 2016 20:10:10 +0100 Subject: Fix a typo (bzr r15295) --- src/live_effects/lpe-measure-line.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index fe327c89b..ed8224ab6 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -34,7 +34,7 @@ enum OrientationMethod { enum MeasureAction { MA_ERASE = 0, - MA_TO_OBJECTS. + MA_TO_OBJECTS, MA_VISIBILITY }; -- cgit v1.2.3 From c3c178b48abf5f6b24a5d227e0e3c07c79fd4644 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 3 Dec 2016 23:48:30 +0100 Subject: Fix names in measure line LPE (bzr r15297) --- src/live_effects/lpe-measure-line.cpp | 18 +++++++++--------- src/live_effects/lpe-measure-line.h | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 9238f2571..ef270d849 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -677,22 +677,22 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { - processObjects(MA_VISIBILITY); + processObjects(LPE_VISIBILITY); } void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (!erase_extra_objects) { - processObjects(MA_TO_OBJECTS); + processObjects(LPE_TO_OBJECTS); ml_elements.clear(); return; } - processObjects(MA_ERASE); + processObjects(LPE_ERASE); } void -LPEMeasureLine::processObjects(MeasureAction measure_action) +LPEMeasureLine::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { @@ -704,14 +704,14 @@ LPEMeasureLine::processObjects(MeasureAction measure_action) SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { - switch (measure_action){ - case MA_TO_OBJECTS: + switch (lpe_action){ + case LPE_TO_OBJECTS: elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); break; - case MA_ERASE: + case LPE_ERASE: elemref->deleteObject(); break; - default: //MA_VISIBILITY + default: //LPE_VISIBILITY if (!this->isVisible()) { elemref->getRepr()->setAttribute("style", "display:none"); } else { @@ -721,7 +721,7 @@ LPEMeasureLine::processObjects(MeasureAction measure_action) } } } - if (measure_action == MA_ERASE) { + if (lpe_action == LPE_ERASE) { ml_elements.clear(); } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index ed8224ab6..a05189039 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -32,10 +32,10 @@ enum OrientationMethod { OM_END }; -enum MeasureAction { - MA_ERASE = 0, - MA_TO_OBJECTS, - MA_VISIBILITY +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY }; class LPEMeasureLine : public Effect { @@ -47,7 +47,7 @@ public: virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void processObjects(MeasureAction measure_action); + void processObjects(LpeAction lpe_action); void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); -- cgit v1.2.3 From 4d33b96eb8c47f5aef22f795dd199ba04b734784 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 3 Dec 2016 23:49:17 +0100 Subject: Start coding (bzr r15295.1.1) --- src/live_effects/lpe-mirror_symmetry.cpp | 201 ++++++++++++++++++++++++++++--- src/live_effects/lpe-mirror_symmetry.h | 14 +++ 2 files changed, 200 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 4deb29d8f..e62dbbca9 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -14,12 +14,18 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-mirror_symmetry.h" -#include -#include +#include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include "sp-defs.h" #include "helper/geom.h" -#include <2geom/path-intersection.h> +#include "2geom/path-intersection.h" +#include "2geom/affine.h" +#include "uri.h" +#include "uri-references.h" #include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { @@ -34,6 +40,9 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); +std::vector ms_elements; +SPObject * ms_container; + namespace MS { class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { @@ -65,6 +74,9 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), + split(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split", &wr, this, false), + split_sensitive(_("Make split selectable"), _("Allow select splited elements"), "split", &wr, this, false), + split_style(_("Make splits with style"), _("Allow Change colors to split"), "split", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring") { @@ -73,6 +85,9 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &discard_orig_path); registerParameter( &fuse_paths); registerParameter( &oposite_fuse); + registerParameter( &split); + registerParameter( &split_sensitive); + registerParameter( &split_style); registerParameter( &start_point); registerParameter( &end_point); apply_to_clippath_and_mask = true; @@ -142,8 +157,155 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } } previous_center = center_point; + if (split) { + SPLPEItem * splpeitem = const_cast(lpeitem); + ms_container = dynamic_cast(splpeitem->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; + } + Geom::Point point_a(line_separation.initialPoint()); + Geom::Point point_b(line_separation.finalPoint()); + + Geom::Translate m1(point_a[0], point_a[1]); + double hyp = Geom::distance(point_a, point_b); + double cos = 0; + double sin = 0; + if (hyp > 0) { + cos = (point_b[0] - point_a[0]) / hyp; + sin = (point_b[1] - point_a[1]) / hyp; + } + Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); + Geom::Scale sca(1.0, -1.0); + + Geom::Affine m = m1.inverse() * m2; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + createPhantom(splpeitem , (Glib::ustring) "origin-clon-", split_style); + createClone(splpeitem , m, (Glib::ustring) "clon-"); + } +} + +void +LPEMirrorSymmetry::createPhantom(SPLPEItem *origin, Glib::ustring id, bool styling) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + id = id + (Glib::ustring)this->getRepr()->attribute("id"); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *phantom = origin->getRepr()->duplicate(xml_doc); + if (elemref = SVGElemRef->getObject()) { + elemref->deleteObject(); + } + if (styling) { + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill", NULL); + sp_repr_css_set_property (css, "stroke",NULL); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + sp_repr_css_change_recursive (phantom, css, css_str.c_str()); + } + phantom->setAttribute("id", id); + phantom->setAttribute("inkscape:path-effect", NULL); + SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(phantom)); + Inkscape::GC::release(phantom); + ms_elements.push_back(id); + } +} + +void +LPEMirrorSymmetry::createClone(SPLPEItem *origin, Geom::Affine transform, Glib::ustring id) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + id = id + (Glib::ustring)this->getRepr()->attribute("id"); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *use = NULL; + use = xml_doc->createElement("svg:use"); + use->setAttribute("transform" , sp_svg_transform_write(transform)); + use->setAttribute("xlink:href", ((Glib::ustring)"#origin-" + id).c_str()); + use->setAttribute("width", "100%"); + use->setAttribute("height", "100%"); + use->setAttribute("id", id); + use->setAttribute("x", "0"); + use->setAttribute("y", "0"); + if (split_sensitive) { + use->setAttribute("sodipodi:insensitive" , "false"); + } else { + use->setAttribute("sodipodi:insensitive" , "true"); + } + if (elemref) { + elemref->deleteObject(); + } + elemref = ms_container->appendChildRepr(use); + Inkscape::GC::release(use); + ms_elements.push_back(id); + } +} + + +void +LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + processObjects(LPE_VISIBILITY); +} + +void +LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + if (!erase_extra_objects) { + processObjects(LPE_TO_OBJECTS); + ms_elements.clear(); + return; + } + processObjects(LPE_ERASE); } +void +LPEMirrorSymmetry::processObjects(LpeAction lpe_action) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + for (std::vector::iterator el_it = ms_elements.begin(); + el_it != ms_elements.end();++el_it) { + Glib::ustring id = *el_it; + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + if (elemref = SVGElemRef->getObject()) { + switch (lpe_action){ + case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + break; + case LPE_ERASE: + elemref->deleteObject(); + break; + default: //LPE_VISIBILITY + if (!this->isVisible()) { + elemref->getRepr()->setAttribute("style", "display:none"); + } else { + elemref->getRepr()->setAttribute("style", NULL); + } + break; + } + } + } + if (lpe_action == LPE_ERASE) { + ms_elements.clear(); + } + } +} + + void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { @@ -178,6 +340,9 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { + if (split && !fuse_paths) { + return path_in; + } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector path_out; @@ -204,7 +369,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) m = m * m2.inverse(); m = m * m1; - if (fuse_paths && !discard_orig_path) { + if (fuse_paths && (!discard_orig_path || split )) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -255,11 +420,15 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (position == 1) { Geom::Path mirror = portion.reversed() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - if(i!=0) { - portion.setFinal(portion.initialPoint()); + if (split) { portion.close(); + } else { + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + if(i!=0) { + portion.setFinal(portion.initialPoint()); + portion.close(); + } } tmp_path.push_back(portion); } @@ -277,10 +446,14 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Path portion = original.portion(time_start, original.size()); if (!portion.empty()) { portion = portion.reversed(); - Geom::Path mirror = portion.reversed() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - portion = portion.reversed(); + if (split) { + + } else { + Geom::Path mirror = portion.reversed() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + portion = portion.reversed(); + } if (!original.closed()) { tmp_path.push_back(portion); } else { @@ -304,9 +477,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } - } - - if (!fuse_paths || discard_orig_path) { + } else if (!fuse_paths || discard_orig_path) { for (size_t i = 0; i < original_pathv.size(); ++i) { path_out.push_back(original_pathv[i] * m); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7ec4029e0..70c82e330 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -31,6 +31,12 @@ namespace MS { class KnotHolderEntityCenterMirrorSymmetry; } +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY +}; + enum ModeType { MT_V, MT_H, @@ -48,8 +54,13 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); + void processObjects(LpeAction lpe_action); /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; + void createPhantom(SPLPEItem *origin, Glib::ustring id, bool styling); + void createClone(SPLPEItem *origin, Geom::Affine transform, Glib::ustring id); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: @@ -60,6 +71,9 @@ private: BoolParam discard_orig_path; BoolParam fuse_paths; BoolParam oposite_fuse; + BoolParam split; + BoolParam split_sensitive; + BoolParam split_style; PointParam start_point; PointParam end_point; Geom::Line line_separation; -- cgit v1.2.3 From 4839ba469180e32f7bff635c3f0a4b436511bf3b Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 5 Dec 2016 15:04:19 +0100 Subject: Added rough mirror improvements, things to fix (bzr r15295.1.3) --- src/live_effects/effect.h | 8 +- src/live_effects/lpe-measure-line.h | 6 - src/live_effects/lpe-mirror_symmetry.cpp | 230 +++++++++++++++++++------------ src/live_effects/lpe-mirror_symmetry.h | 18 ++- 4 files changed, 158 insertions(+), 104 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 06aa075eb..28a1a4e8e 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -44,6 +44,12 @@ enum LPEPathFlashType { DEFAULT }; +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY +}; + class Effect { public: static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); @@ -125,6 +131,7 @@ public: bool apply_to_clippath_and_mask; bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; + BoolParam is_visible; protected: Effect(LivePathEffectObject *lpeobject); @@ -150,7 +157,6 @@ protected: bool _provides_knotholder_entities; int oncanvasedit_it; - BoolParam is_visible; bool show_orig_path; // set this to true in derived effects to automatically have the original // path displayed as helperpath diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index a05189039..d668fbd30 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -32,12 +32,6 @@ enum OrientationMethod { OM_END }; -enum LpeAction { - LPE_ERASE = 0, - LPE_TO_OBJECTS, - LPE_VISIBILITY -}; - class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e62dbbca9..f420c7e69 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -40,7 +40,7 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); -std::vector ms_elements; +std::vector ms_elements; SPObject * ms_container; namespace MS { @@ -52,45 +52,38 @@ public: virtual Geom::Point knot_get() const; }; -class KnotHolderEntityStartMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityStartMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -class KnotHolderEntityEndMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityEndMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - } // namespace MS LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), + split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, 0), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split", &wr, this, false), - split_sensitive(_("Make split selectable"), _("Allow select splited elements"), "split", &wr, this, false), - split_style(_("Make splits with style"), _("Allow Change colors to split"), "split", &wr, this, false), + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), + split_sensitive(_("Make split selectable"), _("Allow select splited elements"), "split_sensitive", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring") + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), + id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") { show_orig_path = true; registerParameter(&mode); + registerParameter( &split_gap); registerParameter( &discard_orig_path); registerParameter( &fuse_paths); registerParameter( &oposite_fuse); - registerParameter( &split); - registerParameter( &split_sensitive); - registerParameter( &split_style); + registerParameter( &split_elements); + //registerParameter( &split_sensitive); registerParameter( &start_point); registerParameter( &end_point); + registerParameter( &id_origin); + id_origin.param_hide_canvas_text(); + split_gap.param_set_range(-999999.0, 999999.0); + split_gap.param_set_increments(0.1, 0.1); + split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; + actual = true; } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -98,14 +91,30 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() } void - LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { + SPLPEItem * splpeitem = const_cast(lpeitem); + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::Selection *sel = desktop->getSelection(); + if ( sel && !sel->isEmpty() ) { + SPItem *item = sel->singleItem(); + if (item) { + if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { + actual = false; + return; + } + } else { + + } + } + } + using namespace Geom; original_bbox(lpeitem); + Geom::Affine m = Geom::identity();//lpeitem->transform; Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); - Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); + gchar * id = g_strdup(((Glib::ustring)"mirror-" + (Glib::ustring)id_origin.param_getSVGValue() + (Glib::ustring)"-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); if (mode == MT_Y) { point_a = Geom::Point(boundingbox_X.min(),center_point[Y]); point_b = Geom::Point(boundingbox_X.max(),center_point[Y]); @@ -157,8 +166,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } } previous_center = center_point; - if (split) { - SPLPEItem * splpeitem = const_cast(lpeitem); + if (split_elements) { ms_container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); @@ -166,9 +174,16 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } +// if (std::strcmp(splpeitem->getId(), id) == 0) { +// Geom::Affine affine = Geom::identity(); +// affine *= Geom::Translate(center_point).inverse(); +// affine *= Geom::Rotate(Geom::rad_from_deg(180)); +// affine *= Geom::Translate(center_point); +// line_separation *= affine; +// } Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); - + Geom::Point gap = Geom::Point(split_gap,0); Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); double cos = 0; @@ -178,76 +193,80 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) sin = (point_b[1] - point_a[1]) / hyp; } Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); + gap *= m2; Geom::Scale sca(1.0, -1.0); - - Geom::Affine m = m1.inverse() * m2; + if (std::strcmp(splpeitem->getId(), id) == 0) { + id = id_origin.param_getSVGValue(); + } + m = m1.inverse() * m2; m = m * sca; m = m * m2.inverse(); m = m * m1; - createPhantom(splpeitem , (Glib::ustring) "origin-clon-", split_style); - createClone(splpeitem , m, (Glib::ustring) "clon-"); + m = m * gap; + m = m * lpeitem->transform; + ms_elements.clear(); + createMirror(splpeitem, m, id); + } else { + processObjects(LPE_ERASE); } } void -LPEMirrorSymmetry::createPhantom(SPLPEItem *origin, Glib::ustring id, bool styling) +LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - id = id + (Glib::ustring)this->getRepr()->attribute("id"); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *phantom = origin->getRepr()->duplicate(xml_doc); - if (elemref = SVGElemRef->getObject()) { - elemref->deleteObject(); - } - if (styling) { - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property (css, "fill", NULL); - sp_repr_css_set_property (css, "stroke",NULL); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - sp_repr_css_change_recursive (phantom, css, css_str.c_str()); + va_list args; + va_start(args, first_attribute); + + if ( origin->name() == "svg:g" && origin->childCount() == dest->childCount() ) { + Inkscape::XML::Node * node_it = origin->firstChild(); + size_t index = 0; + while (node_it != origin->lastChild()) { + cloneAttrbutes(node_it, dest->nthChild(index), first_attribute, args); + node_it = node_it->next(); + index++; } - phantom->setAttribute("id", id); - phantom->setAttribute("inkscape:path-effect", NULL); - SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(phantom)); - Inkscape::GC::release(phantom); - ms_elements.push_back(id); } + while(char const * att = va_arg(args, char const *)) { + dest->setAttribute(att,origin->attribute(att)); + } + va_end(args); } void -LPEMirrorSymmetry::createClone(SPLPEItem *origin, Geom::Affine transform, Glib::ustring id) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, gchar * id) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - id = id + (Glib::ustring)this->getRepr()->attribute("id"); Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *use = NULL; - use = xml_doc->createElement("svg:use"); - use->setAttribute("transform" , sp_svg_transform_write(transform)); - use->setAttribute("xlink:href", ((Glib::ustring)"#origin-" + id).c_str()); - use->setAttribute("width", "100%"); - use->setAttribute("height", "100%"); - use->setAttribute("id", id); - use->setAttribute("x", "0"); - use->setAttribute("y", "0"); - if (split_sensitive) { - use->setAttribute("sodipodi:insensitive" , "false"); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = SVGElemRef->getObject()) { + phantom = elemref->getRepr(); } else { - use->setAttribute("sodipodi:insensitive" , "true"); + phantom = origin->getRepr()->duplicate(xml_doc); } - if (elemref) { + cloneAttrbutes(origin->getRepr(), phantom, "inkscape:original-d"); + phantom->setAttribute("id", id); + // if (std::strcmp(id, id_origin.param_getSVGValue()) != 0) { + phantom->setAttribute("transform" , sp_svg_transform_write(transform)); + +// if (split_sensitive) { +// phantom->setAttribute("sodipodi:insensitive" , NULL); +// } else { +// phantom->setAttribute("sodipodi:insensitive" , "true"); +// } + if (!elemref) { + elemref = ms_container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } else if (elemref->parent != ms_container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + ms_container->appendChildRepr(copy); + Inkscape::GC::release(copy); elemref->deleteObject(); + copy->setAttribute("id", id); } - elemref = ms_container->appendChildRepr(use); - Inkscape::GC::release(use); ms_elements.push_back(id); } } @@ -274,9 +293,9 @@ void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::iterator el_it = ms_elements.begin(); + for (std::vector::iterator el_it = ms_elements.begin(); el_it != ms_elements.end();++el_it) { - Glib::ustring id = *el_it; + gchar * id = *el_it; Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -285,6 +304,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) switch (lpe_action){ case LPE_TO_OBJECTS: elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + SP_LPE_ITEM(elemref)->removeAllPathEffects(true); break; case LPE_ERASE: elemref->deleteObject(); @@ -309,12 +329,14 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { - center_point *= postmul; - previous_center = center_point; - // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { - Parameter * param = *it; - param->param_transform_multiply(postmul, set); + if( !split_elements) { + center_point *= postmul; + previous_center = center_point; + // cycle through all parameters. Most parameters will not need transformation, but path and point params do. + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); + } } } @@ -334,13 +356,14 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point = point_c; previous_center = center_point; + id_origin.param_setValue((Glib::ustring)lpeitem->getId()); } Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { - if (split && !fuse_paths) { + if (split_elements && !fuse_paths) { return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); @@ -369,7 +392,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) m = m * m2.inverse(); m = m * m1; - if (fuse_paths && (!discard_orig_path || split )) { + if (fuse_paths && (!discard_orig_path || split_elements )) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -420,7 +443,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (position == 1) { Geom::Path mirror = portion.reversed() * m; - if (split) { + if (split_elements) { portion.close(); } else { mirror.setInitial(portion.finalPoint()); @@ -446,9 +469,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Path portion = original.portion(time_start, original.size()); if (!portion.empty()) { portion = portion.reversed(); - if (split) { - - } else { + if (!split_elements) { Geom::Path mirror = portion.reversed() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); @@ -486,6 +507,41 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) return path_out; } + +Gtk::Widget *LPEMirrorSymmetry::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "id_origin") { + 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(vbox); +} + void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 70c82e330..00bc45488 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -17,6 +17,7 @@ */ #include #include "live_effects/effect.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" @@ -31,12 +32,6 @@ namespace MS { class KnotHolderEntityCenterMirrorSymmetry; } -enum LpeAction { - LPE_ERASE = 0, - LPE_TO_OBJECTS, - LPE_VISIBILITY -}; - enum ModeType { MT_V, MT_H, @@ -56,11 +51,12 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); + virtual Gtk::Widget *newWidget(); void processObjects(LpeAction lpe_action); /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; - void createPhantom(SPLPEItem *origin, Glib::ustring id, bool styling); - void createClone(SPLPEItem *origin, Geom::Affine transform, Glib::ustring id); + void createMirror(SPLPEItem *origin, Geom::Affine transform, gchar * id); + void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: @@ -68,17 +64,19 @@ protected: private: EnumParam mode; + ScalarParam split_gap; BoolParam discard_orig_path; BoolParam fuse_paths; BoolParam oposite_fuse; - BoolParam split; + BoolParam split_elements; BoolParam split_sensitive; - BoolParam split_style; PointParam start_point; PointParam end_point; + TextParam id_origin; Geom::Line line_separation; Geom::Point previous_center; Geom::Point center_point; + bool actual; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 64e8f0b5a189cffa91b182c24043b73eaa5e0b4c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 5 Dec 2016 15:07:45 +0100 Subject: Rollback a unwanted modified file (bzr r15295.1.5) --- src/live_effects/lpe-measure-line.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d668fbd30..a05189039 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -32,6 +32,12 @@ enum OrientationMethod { OM_END }; +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY +}; + class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); -- cgit v1.2.3 From 1361cbe77c067e59ccbd25ed5eb1c50e177f8b34 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 5 Dec 2016 21:55:14 +0100 Subject: Working on mirror LPE (bzr r15295.1.6) --- src/live_effects/lpe-measure-line.h | 6 -- src/live_effects/lpe-mirror_symmetry.cpp | 107 +++++++++++++++++++++---------- src/live_effects/lpe-mirror_symmetry.h | 7 +- 3 files changed, 76 insertions(+), 44 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index a05189039..d668fbd30 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -32,12 +32,6 @@ enum OrientationMethod { OM_END }; -enum LpeAction { - LPE_ERASE = 0, - LPE_TO_OBJECTS, - LPE_VISIBILITY -}; - class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f420c7e69..d6989fa41 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -40,9 +40,6 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); -std::vector ms_elements; -SPObject * ms_container; - namespace MS { class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { @@ -62,7 +59,6 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), - split_sensitive(_("Make split selectable"), _("Allow select splited elements"), "split_sensitive", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") @@ -74,7 +70,6 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &fuse_paths); registerParameter( &oposite_fuse); registerParameter( &split_elements); - //registerParameter( &split_sensitive); registerParameter( &start_point); registerParameter( &end_point); registerParameter( &id_origin); @@ -167,6 +162,9 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } previous_center = center_point; if (split_elements) { + ms_elements.clear(); + ms_elements.push_back(id); + ms_elements.push_back(id_origin.param_getSVGValue()); ms_container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); @@ -174,13 +172,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } -// if (std::strcmp(splpeitem->getId(), id) == 0) { -// Geom::Affine affine = Geom::identity(); -// affine *= Geom::Translate(center_point).inverse(); -// affine *= Geom::Rotate(Geom::rad_from_deg(180)); -// affine *= Geom::Translate(center_point); -// line_separation *= affine; -// } Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); Geom::Point gap = Geom::Point(split_gap,0); @@ -204,30 +195,75 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) m = m * m1; m = m * gap; m = m * lpeitem->transform; - ms_elements.clear(); createMirror(splpeitem, m, id); } else { + ms_elements.clear(); processObjects(LPE_ERASE); } } +//void +//LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...) +//{ +// va_list args; +// va_start(args, first_attribute); + +// if ( origin->name() == "svg:g" && origin->childCount() == dest->childCount() ) { +// Inkscape::XML::Node * node_it = origin->firstChild(); +// size_t index = 0; +// while (node_it != origin->lastChild()) { +// cloneAttrbutes(node_it, dest->nthChild(index), first_attribute, live, args); +// node_it = node_it->next(); +// index++; +// } +// } +// while(char const * att = va_arg(args, char const *)) { +// dest->setAttribute(att,origin->attribute(att)); +// } +// va_end(args); +//} + void -LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...) +LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, char const * first_attribute, ...) { va_list args; va_start(args, first_attribute); - - if ( origin->name() == "svg:g" && origin->childCount() == dest->childCount() ) { - Inkscape::XML::Node * node_it = origin->firstChild(); + + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); size_t index = 0; - while (node_it != origin->lastChild()) { - cloneAttrbutes(node_it, dest->nthChild(index), first_attribute, args); - node_it = node_it->next(); + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneAttrbutes(*obj_it, dest_child, live, first_attribute, args); index++; } } + unsigned counter = 0; while(char const * att = va_arg(args, char const *)) { - dest->setAttribute(att,origin->attribute(att)); + if (counter % 2 != 0){ + SPShape * shape = SP_SHAPE(origin); + if (shape) { + if ( live && (att == "d" || att == "inkscape:original-d")) { + SPCurve *c = NULL; + if (att == "d") { + c = shape->getCurve(); + } else { + c = shape->getCurveBeforeLPE(); + } + if (c) { + dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); + c->reset(); + g_free(c); + } else { + dest->getRepr()->setAttribute(att,NULL); + } + } else { + dest->getRepr()->setAttribute(att,origin->getRepr()->attribute(att)); + } + } + } + counter++; } va_end(args); } @@ -247,27 +283,21 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, gchar } else { phantom = origin->getRepr()->duplicate(xml_doc); } - cloneAttrbutes(origin->getRepr(), phantom, "inkscape:original-d"); + phantom->setAttribute("id", id); - // if (std::strcmp(id, id_origin.param_getSVGValue()) != 0) { - phantom->setAttribute("transform" , sp_svg_transform_write(transform)); - -// if (split_sensitive) { -// phantom->setAttribute("sodipodi:insensitive" , NULL); -// } else { -// phantom->setAttribute("sodipodi:insensitive" , "true"); -// } if (!elemref) { elemref = ms_container->appendChildRepr(phantom); Inkscape::GC::release(phantom); - } else if (elemref->parent != ms_container) { + } + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d"); + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + if (elemref->parent != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", id); ms_container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); - copy->setAttribute("id", id); } - ms_elements.push_back(id); } } @@ -283,6 +313,7 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); + std::cout << ms_elements.size() << "ms_elements.size() ms_elements.size() ms_elements.size() ms_elements.size() ms_elements.size() \n"; ms_elements.clear(); return; } @@ -294,17 +325,22 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { for (std::vector::iterator el_it = ms_elements.begin(); - el_it != ms_elements.end();++el_it) { + el_it != ms_elements.end(); ++el_it) { gchar * id = *el_it; + std::cout << id << "idididididididididi\n"; Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { + SPLPEItem *lpe_element = dynamic_cast(elemref); + std::cout << elemref->getId() << "elemref->getId()elemref->getId()elemref->getId()elemref->getId()\n"; switch (lpe_action){ case LPE_TO_OBJECTS: elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - SP_LPE_ITEM(elemref)->removeAllPathEffects(true); + if (lpe_element && lpe_element->hasPathEffect()) { + lpe_element->removeAllPathEffects(true); + } break; case LPE_ERASE: elemref->deleteObject(); @@ -357,6 +393,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) center_point = point_c; previous_center = center_point; id_origin.param_setValue((Glib::ustring)lpeitem->getId()); + id_origin.write_to_SVG(); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 00bc45488..cdbfe67e2 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -56,7 +56,8 @@ public: /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; void createMirror(SPLPEItem *origin, Geom::Affine transform, gchar * id); - void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...); +// void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, char const * first_attribute, ...); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: @@ -69,7 +70,6 @@ private: BoolParam fuse_paths; BoolParam oposite_fuse; BoolParam split_elements; - BoolParam split_sensitive; PointParam start_point; PointParam end_point; TextParam id_origin; @@ -77,7 +77,8 @@ private: Geom::Point previous_center; Geom::Point center_point; bool actual; - + std::vector ms_elements; + SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; -- cgit v1.2.3 From f799b5d6e8278c76326a6fec8da0e017eac342ec Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 6 Dec 2016 21:41:55 +0100 Subject: Fixes for measure LPE and speed path based LPE operations (bzr r15302) --- src/live_effects/lpe-measure-line.cpp | 160 +++++++++++++++++---------------- src/live_effects/lpe-measure-line.h | 9 +- src/live_effects/lpe-path_length.cpp | 10 +-- src/live_effects/lpe-path_length.h | 2 - src/live_effects/parameter/parameter.h | 2 + src/live_effects/parameter/text.cpp | 5 +- 6 files changed, 99 insertions(+), 89 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ef270d849..a1de035fb 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -47,9 +47,6 @@ static const Util::EnumData OrientationMethodData[] = { }; static const Util::EnumDataConverter OMConverter(OrientationMethodData, OM_END); -std::vector ml_elements; -SPObject * container; - LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), @@ -63,7 +60,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), - format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"measure unit"), + format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"{measure}{unit}"), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_sensitive(_("Scale sensitive*"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), @@ -161,6 +158,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_range(-999999.0, 999999.0); helpline_overlap.param_set_increments(1, 1); helpline_overlap.param_set_digits(2); + start_stored = Geom::Point(0,0); + end_stored = Geom::Point(0,0); } LPEMeasureLine::~LPEMeasureLine() {} @@ -172,19 +171,19 @@ void swap(Geom::Point &A, Geom::Point &B){ } void -LPEMeasureLine::createArrowMarker(Glib::ustring mode) +LPEMeasureLine::createArrowMarker(const char * mode) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + mode).c_str()); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(mode).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; Inkscape::XML::Node *arrow = NULL; if (!(elemref = SVGElemRef->getObject())) { arrow = xml_doc->createElement("svg:marker"); - arrow->setAttribute("id", mode.c_str()); - arrow->setAttribute("inkscape:stockid", mode.c_str()); + arrow->setAttribute("id", mode); + arrow->setAttribute("inkscape:stockid", mode); arrow->setAttribute("orient", "auto"); arrow->setAttribute("refX", "0.0"); arrow->setAttribute("refY", "0.0"); @@ -192,20 +191,20 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) arrow->setAttribute("sodipodi:insensitive", "true"); /* Create */ Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); - if (mode == (Glib::ustring)"ArrowDIN-start") { + if (std::strcmp(mode, "ArrowDIN-start") == 0) { arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); - } else if (mode == (Glib::ustring)"ArrowDIN-end") { + } else if (std::strcmp(mode, "ArrowDIN-end") == 0) { arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); - } else if (mode == (Glib::ustring)"ArrowDINout-start") { + } else if (std::strcmp(mode, "ArrowDINout-start") == 0) { arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); } else { arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); } - arrow_path->setAttribute("id", (mode + (Glib::ustring)"_path").c_str()); + arrow_path->setAttribute("id", Glib::ustring(mode).append("_path").c_str()); SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property (css, "fill","#000000"); - sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_set_property (css, "stroke","none"); sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); Glib::ustring css_str; sp_repr_css_write_string(css,css_str); @@ -223,7 +222,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) if (arrow_data) { SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property (css, "fill","#000000"); - sp_repr_css_set_property (css, "stroke","none" ); + sp_repr_css_set_property (css, "stroke","none"); arrow_data->setAttribute("transform", NULL); sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); Glib::ustring css_str; @@ -232,7 +231,7 @@ LPEMeasureLine::createArrowMarker(Glib::ustring mode) } } } - ml_elements.push_back(mode); + elements.push_back(mode); } } @@ -256,8 +255,8 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } else { doc_scale = 1.0; } - Glib::ustring id = (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id"); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -279,7 +278,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } rtext = xml_doc->createElement("svg:text"); rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", ( (Glib::ustring)"text-on-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); + rtext->setAttribute("id", id); rtext->setAttribute("sodipodi:insensitive", "true"); pos = pos - Point::polar(angle, text_right_left); sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); @@ -287,7 +286,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan = xml_doc->createElement("svg:tspan"); rtspan->setAttribute("sodipodi:role", "line"); } - gchar * transform; + const char * transform; Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; @@ -306,7 +305,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css( css, (Glib::ustring)fontbutton.param_getSVGValue() ); + fontlister->fill_css(css, Glib::ustring(fontbutton.param_getSVGValue())); std::stringstream font_size; font_size.imbue(std::locale::classic()); font_size << fontsize << "pt"; @@ -344,11 +343,11 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } length_str << std::fixed << length; Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); - size_t s = label_value.find((Glib::ustring)"{measure}",0); + size_t s = label_value.find(Glib::ustring("{measure}"),0); if(s < label_value.length()) { label_value.replace(s,s+9,length_str.str()); } - s = label_value.find((Glib::ustring)"{unit}",0); + s = label_value.find(Glib::ustring("{unit}"),0); if(s < label_value.length()) { label_value.replace(s,s+6,unit.get_abbreviation()); } @@ -365,18 +364,18 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rstring->setContent(label_value.c_str()); } if (!elemref) { - elemref = container->appendChildRepr(rtext); + elemref = sp_lpe_item->parent->appendChildRepr(rtext); Inkscape::GC::release(rtext); - } else if (elemref->parent != container) { + } else if (elemref->parent != sp_lpe_item->parent) { Inkscape::XML::Node *old_repr = elemref->getRepr(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = container->appendChildRepr(copy); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); - copy->setAttribute("id", id.c_str()); + copy->setAttribute("id", id); elemref = elemref_copy; } - ml_elements.push_back(id); + elements.push_back(id); Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { anotation_width = bounds->width() * 1.4; @@ -385,11 +384,11 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl } void -LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, bool main, bool overflow, bool remove, bool arrows) +LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -427,7 +426,6 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, line_path.appendNew(end); line_pathv.push_back(line_path); } - if (elemref = SVGElemRef->getObject()) { if (remove) { elemref->deleteObject(); @@ -435,7 +433,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, } line = elemref->getRepr(); - gchar * line_str = sp_svg_write_path( line_pathv ); + const char * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); line->setAttribute("transform", NULL); } else { @@ -443,22 +441,22 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, return; } line = xml_doc->createElement("svg:path"); - line->setAttribute("id", id.c_str()); - gchar * line_str = sp_svg_write_path( line_pathv ); + line->setAttribute("id", id); + const char * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); } line->setAttribute("sodipodi:insensitive", "true"); line_pathv.clear(); - Glib::ustring style = (Glib::ustring)"stroke:#000000;fill:none;"; + Glib::ustring style = Glib::ustring("stroke:#000000;fill:none;"); if (overflow && !arrows) { line->setAttribute("inkscape:label", "downline"); } else if (main) { line->setAttribute("inkscape:label", "dinline"); if (arrows_outside) { - style = style + (Glib::ustring)"marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"; + style = style + Glib::ustring("marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"); } else { - style = style + (Glib::ustring)"marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"; + style = style + Glib::ustring("marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"); } } else { line->setAttribute("inkscape:label", "dinhelpline"); @@ -468,11 +466,11 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, if (line_group_05) { double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; - style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + style = style + Glib::ustring("stroke-width:" + stroke_w.str()); } else { double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); stroke_w << stroke_width; - style = style + (Glib::ustring)"stroke-width:" + (Glib::ustring)stroke_w.str(); + style = style + Glib::ustring("stroke-width:" + stroke_w.str()); } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, style.c_str()); @@ -485,17 +483,17 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, Glib::ustring id, sp_repr_css_write_string(css,css_str); line->setAttribute("style", css_str.c_str()); if (!elemref) { - elemref = container->appendChildRepr(line); + elemref = sp_lpe_item->parent->appendChildRepr(line); Inkscape::GC::release(line); - } else if (elemref->parent != container) { + } else if (elemref->parent != sp_lpe_item->parent) { Inkscape::XML::Node *old_repr = elemref->getRepr(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = container->appendChildRepr(copy); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); - copy->setAttribute("id", id.c_str()); + copy->setAttribute("id", id); } - ml_elements.push_back(id); + elements.push_back(id); } } @@ -513,7 +511,7 @@ void LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { SPLPEItem * splpeitem = const_cast(lpeitem); - container = dynamic_cast(splpeitem->parent); + sp_lpe_item->parent = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); Inkscape::XML::Node *root_origin = doc->getReprRoot(); @@ -527,26 +525,29 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine writed_transform = Geom::identity(); sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); pathvector *= writed_transform; - if (arrows_outside) { - createArrowMarker((Glib::ustring)"ArrowDINout-start"); - createArrowMarker((Glib::ustring)"ArrowDINout-end"); - } else { - createArrowMarker((Glib::ustring)"ArrowDIN-start"); - createArrowMarker((Glib::ustring)"ArrowDIN-end"); - } if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if (((Glib::ustring)format.param_getSVGValue()).empty()) { - format.param_setValue((Glib::ustring)"{measure}{unit}"); + if ((Glib::ustring(format.param_getSVGValue()).empty())) { + format.param_setValue(Glib::ustring("{measure}{unit}")); this->upd_params = true; } size_t ncurves = pathvector.curveCount(); - curve_linked.param_set_range(0, ncurves); + if (ncurves != (size_t)curve_linked.param_get_max()) { + curve_linked.param_set_range(0, ncurves); + } Geom::Point start = pathvector.initialPoint(); Geom::Point end = pathvector.finalPoint(); if (curve_linked) { //!0 start = pathvector.pointAt(curve_linked -1); end = pathvector.pointAt(curve_linked); } + if (Geom::are_near(start, start_stored, 0.01) && + Geom::are_near(end, end_stored, 0.01) && + sp_lpe_item->getCurrentLPE() != this){ + return; + } + elements.clear(); + start_stored = start; + end_stored = end; Geom::Point hstart = start; Geom::Point hend = end; bool remove = false; @@ -591,8 +592,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); if (angle < 0) angle += 2*M_PI; } + if (arrows_outside) { + createArrowMarker("ArrowDINout-start"); + createArrowMarker("ArrowDINout-end"); + } else { + createArrowMarker("ArrowDIN-start"); + createArrowMarker("ArrowDIN-end"); + } //We get the font size to offset the text to the middle - Pango::FontDescription fontdesc((Glib::ustring)fontbutton.param_getSVGValue()); + Pango::FontDescription fontdesc(Glib::ustring(fontbutton.param_getSVGValue())); fontsize = fontdesc.get_size()/(double)Pango::SCALE; fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); @@ -614,6 +622,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) createTextLabel(pos, length, angle, remove, true); } bool overflow = false; + const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { Geom::Point sstart = end - Point::polar(angle_cross, position); Geom::Point send = end - Point::polar(angle_cross, position); @@ -636,10 +645,10 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } overflow = true; - createLine(sstart, prog_end, (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, false, false); + createLine(sstart, prog_end, downline, true, overflow, false, false); } else { //erase it - createLine(Geom::Point(),Geom::Point(), (Glib::ustring)"downline-" + (Glib::ustring)this->getRepr()->attribute("id"), true, overflow, true, false); + createLine(Geom::Point(),Geom::Point(), downline, true, overflow, true, false); } //LINE arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); @@ -658,17 +667,15 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) arrow_gap *= -1; } hstart = hstart - Point::polar(angle_cross, position); - Glib::ustring id = (Glib::ustring)"infoline-on-start-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(start, hstart, id, false, false, remove); + createLine(start, hstart, g_strdup(Glib::ustring("infoline-on-start-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); hend = hend - Point::polar(angle_cross, position); - id = (Glib::ustring)"infoline-on-end-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(end, hend, id, false, false, remove); + createLine(end, hend, g_strdup(Glib::ustring("infoline-on-end-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); if (!arrows_outside) { hstart = hstart + Point::polar(angle, arrow_gap); hend = hend - Point::polar(angle, arrow_gap ); } - id = (Glib::ustring)"infoline-" + (Glib::ustring)this->getRepr()->attribute("id"); - createLine(hstart, hend, id, true, overflow, remove, true); + createLine(hstart, hend, g_strdup(Glib::ustring("infoline-").append(this->getRepr()->attribute("id")).c_str()), true, overflow, remove, true); + } } } @@ -685,7 +692,7 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - ml_elements.clear(); + elements.clear(); return; } processObjects(LPE_ERASE); @@ -696,10 +703,11 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::iterator el_it = ml_elements.begin(); - el_it != ml_elements.end();++el_it) { - Glib::ustring id = *el_it; - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + for (std::vector::const_iterator el_it = elements.begin(); + el_it != elements.end();++el_it) { + const char * id = (const char *)(*el_it); + std::cout << id << "asdfffgasdfasdsdgf\n"; + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; @@ -722,7 +730,7 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) } } if (lpe_action == LPE_ERASE) { - ml_elements.clear(); + elements.clear(); } } } @@ -800,19 +808,19 @@ void LPEMeasureLine::saveDefault() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/live_effects/measure-line/fontbutton", (Glib::ustring)fontbutton.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/fontbutton", Glib::ustring(fontbutton.param_getSVGValue())); prefs->setDouble("/live_effects/measure-line/scale", scale); prefs->setInt("/live_effects/measure-line/precision", precision); prefs->setDouble("/live_effects/measure-line/position", position); prefs->setDouble("/live_effects/measure-line/text_top_bottom", text_top_bottom); prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); - prefs->setString("/live_effects/measure-line/unit", (Glib::ustring)unit.get_abbreviation()); - prefs->setString("/live_effects/measure-line/format", (Glib::ustring)format.param_getSVGValue()); - prefs->setString("/live_effects/measure-line/dimline_format", (Glib::ustring)dimline_format.param_getSVGValue()); - prefs->setString("/live_effects/measure-line/helperlines_format", (Glib::ustring)helperlines_format.param_getSVGValue()); - prefs->setString("/live_effects/measure-line/anotation_format", (Glib::ustring)anotation_format.param_getSVGValue()); - prefs->setString("/live_effects/measure-line/arrows_format", (Glib::ustring)arrows_format.param_getSVGValue()); + prefs->setString("/live_effects/measure-line/unit", Glib::ustring(unit.get_abbreviation())); + prefs->setString("/live_effects/measure-line/format", Glib::ustring(format.param_getSVGValue())); + prefs->setString("/live_effects/measure-line/dimline_format", Glib::ustring(dimline_format.param_getSVGValue())); + prefs->setString("/live_effects/measure-line/helperlines_format", Glib::ustring(helperlines_format.param_getSVGValue())); + prefs->setString("/live_effects/measure-line/anotation_format", Glib::ustring(anotation_format.param_getSVGValue())); + prefs->setString("/live_effects/measure-line/arrows_format", Glib::ustring(arrows_format.param_getSVGValue())); prefs->setBool("/live_effects/measure-line/flip_side", flip_side); prefs->setBool("/live_effects/measure-line/scale_sensitive", scale_sensitive); prefs->setBool("/live_effects/measure-line/local_locale", local_locale); diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index a05189039..cb902e74f 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -45,13 +45,14 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doEffect (SPCurve * curve){}; //stop the chain virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); void processObjects(LpeAction lpe_action); - void createLine(Geom::Point start,Geom::Point end,Glib::ustring id, bool main, bool overflow, bool remove, bool arrows = false); + void createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); - void createArrowMarker(Glib::ustring mode); + void createArrowMarker(const char * mode); void saveDefault(); virtual Gtk::Widget *newWidget(); private: @@ -85,7 +86,9 @@ private: double fontsize; double anotation_width; double arrow_gap; - + Geom::Point start_stored; + Geom::Point end_stored; + std::vector elements; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 8fbf9d420..6ec1e0ede 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -37,12 +37,6 @@ LPEPathLength::~LPEPathLength() } -void -LPEPathLength::hideCanvasText() { - // this is only used in sp-lpe-item.cpp to hide the canvas text when the effect is invisible - info_text.param_setValue(""); -} - Geom::Piecewise > LPEPathLength::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { @@ -69,7 +63,9 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise > const & p //g_print ("Area is zero\n"); } //g_print ("Area: %f\n", area); - + if (!this->isVisible()) { + info_text.param_setValue(""); + } return pwd2_in; } diff --git a/src/live_effects/lpe-path_length.h b/src/live_effects/lpe-path_length.h index e108e770a..14d093c09 100644 --- a/src/live_effects/lpe-path_length.h +++ b/src/live_effects/lpe-path_length.h @@ -29,8 +29,6 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); - void hideCanvasText(); - private: LPEPathLength(const LPEPathLength&); LPEPathLength& operator=(const LPEPathLength&); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 3658bded8..5dbcb7868 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -118,6 +118,8 @@ public: void param_set_digits(unsigned digits); void param_set_increments(double step, double page); void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; + double param_get_max() { return max; }; + double param_get_min() { return min; }; void param_overwrite_widget(bool overwrite_widget); virtual Gtk::Widget * param_newWidget(); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 0650b7e66..8cab68ad0 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -110,7 +110,10 @@ TextParam::param_readSVGValue(const gchar * strvalue) gchar * TextParam::param_getSVGValue() const { - return g_strdup(value.c_str()); + Inkscape::SVGOStringStream os; + os << value; + gchar * str = g_strdup(os.str().c_str()); + return str; } Gtk::Widget * -- cgit v1.2.3 From 03098d9de7fbca944663da45b1a662be8a69c485 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 6 Dec 2016 22:16:46 +0100 Subject: Fix to const char (bzr r15295.1.9) --- src/live_effects/lpe-mirror_symmetry.cpp | 32 ++++++++++++++++---------------- src/live_effects/lpe-mirror_symmetry.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index d6989fa41..e44d57a0e 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -109,7 +109,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine m = Geom::identity();//lpeitem->transform; Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); - gchar * id = g_strdup(((Glib::ustring)"mirror-" + (Glib::ustring)id_origin.param_getSVGValue() + (Glib::ustring)"-" + (Glib::ustring)this->getRepr()->attribute("id")).c_str()); if (mode == MT_Y) { point_a = Geom::Point(boundingbox_X.min(),center_point[Y]); point_b = Geom::Point(boundingbox_X.max(),center_point[Y]); @@ -162,9 +161,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } previous_center = center_point; if (split_elements) { - ms_elements.clear(); - ms_elements.push_back(id); - ms_elements.push_back(id_origin.param_getSVGValue()); ms_container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); @@ -186,16 +182,22 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); gap *= m2; Geom::Scale sca(1.0, -1.0); - if (std::strcmp(splpeitem->getId(), id) == 0) { - id = id_origin.param_getSVGValue(); - } + const char * id_original = id_origin.param_getSVGValue(); + const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); m = m1.inverse() * m2; m = m * sca; m = m * m2.inverse(); m = m * m1; m = m * gap; m = m * lpeitem->transform; - createMirror(splpeitem, m, id); + if (std::strcmp(splpeitem->getId(), id) == 0) { + createMirror(splpeitem, m, id_original); + } else { + createMirror(splpeitem, m, id); + } + ms_elements.clear(); + ms_elements.push_back(id); + ms_elements.push_back(id_original); } else { ms_elements.clear(); processObjects(LPE_ERASE); @@ -269,11 +271,11 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, gchar * id) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref= NULL; @@ -324,17 +326,15 @@ void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::iterator el_it = ms_elements.begin(); + for (std::vector::iterator el_it = ms_elements.begin(); el_it != ms_elements.end(); ++el_it) { - gchar * id = *el_it; - std::cout << id << "idididididididididi\n"; - Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + id).c_str()); + const char * id = *el_it; + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { SPLPEItem *lpe_element = dynamic_cast(elemref); - std::cout << elemref->getId() << "elemref->getId()elemref->getId()elemref->getId()elemref->getId()\n"; switch (lpe_action){ case LPE_TO_OBJECTS: elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); @@ -392,7 +392,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point = point_c; previous_center = center_point; - id_origin.param_setValue((Glib::ustring)lpeitem->getId()); + id_origin.param_setValue(Glib::ustring(lpeitem->getId())); id_origin.write_to_SVG(); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index cdbfe67e2..9ca86872f 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -55,7 +55,7 @@ public: void processObjects(LpeAction lpe_action); /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; - void createMirror(SPLPEItem *origin, Geom::Affine transform, gchar * id); + void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, char const * first_attribute, ...); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); @@ -77,7 +77,7 @@ private: Geom::Point previous_center; Geom::Point center_point; bool actual; - std::vector ms_elements; + std::vector ms_elements; SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 4faef66de872ba1abd4e652ead9b66fc3394eda0 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 7 Dec 2016 02:00:05 +0100 Subject: Fix measure LPE to fit future extra objects based LPE (bzr r15304) --- src/live_effects/lpe-measure-line.cpp | 44 ++++++++++++++++++++++++----------- src/live_effects/lpe-measure-line.h | 1 + 2 files changed, 32 insertions(+), 13 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index a1de035fb..8b73781b5 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -14,6 +14,7 @@ #include #include "inkscape.h" #include "xml/node.h" +#include "xml/sp-css-attr.h" #include "uri.h" #include "uri-references.h" #include "preferences.h" @@ -61,6 +62,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"{measure}{unit}"), + id_origin("id_origin", "id_origin", "id_origin", &wr, this,""), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_sensitive(_("Scale sensitive*"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), @@ -97,6 +99,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&helperlines_format); registerParameter(&anotation_format); registerParameter(&arrows_format); + registerParameter(&id_origin); + id_origin.param_hide_canvas_text(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); if(fontbutton_value.empty()){ @@ -505,6 +509,8 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); } + id_origin.param_setValue(Glib::ustring(lpeitem->getId())); + id_origin.write_to_SVG(); } void @@ -701,31 +707,43 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::processObjects(LpeAction lpe_action) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::const_iterator el_it = elements.begin(); - el_it != elements.end();++el_it) { - const char * id = (const char *)(*el_it); - std::cout << id << "asdfffgasdfasdsdgf\n"; + for (std::vector::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { + SPCSSAttr *css; + Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - break; + break; + case LPE_ERASE: - elemref->deleteObject(); - break; - default: //LPE_VISIBILITY - if (!this->isVisible()) { - elemref->getRepr()->setAttribute("style", "display:none"); + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + elemref->deleteObject(); + } + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + css->setAttribute("display", "none"); } else { - elemref->getRepr()->setAttribute("style", NULL); + css->setAttribute("display", NULL); } - break; + sp_repr_css_write_string(css,css_str); + elemref->getRepr()->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index cb902e74f..565644c07 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -68,6 +68,7 @@ private: ScalarParam helpline_overlap; ScalarParam scale; TextParam format; + TextParam id_origin; BoolParam arrows_outside; BoolParam flip_side; BoolParam scale_sensitive; -- cgit v1.2.3 From 34215a3e1d3b00357b4741ec397cf7d257770556 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 7 Dec 2016 02:24:26 +0100 Subject: Fixing and commiting (bzr r15295.1.10) --- src/live_effects/lpe-measure-line.cpp | 44 +++++++++---- src/live_effects/lpe-measure-line.h | 1 + src/live_effects/lpe-mirror_symmetry.cpp | 110 ++++++++++++++++--------------- src/live_effects/lpe-mirror_symmetry.h | 6 +- 4 files changed, 93 insertions(+), 68 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index a1de035fb..8b73781b5 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -14,6 +14,7 @@ #include #include "inkscape.h" #include "xml/node.h" +#include "xml/sp-css-attr.h" #include "uri.h" #include "uri-references.h" #include "preferences.h" @@ -61,6 +62,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"{measure}{unit}"), + id_origin("id_origin", "id_origin", "id_origin", &wr, this,""), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), scale_sensitive(_("Scale sensitive*"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), @@ -97,6 +99,8 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&helperlines_format); registerParameter(&anotation_format); registerParameter(&arrows_format); + registerParameter(&id_origin); + id_origin.param_hide_canvas_text(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); if(fontbutton_value.empty()){ @@ -505,6 +509,8 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) SPLPEItem * item = const_cast(lpeitem); item->removeCurrentPathEffect(false); } + id_origin.param_setValue(Glib::ustring(lpeitem->getId())); + id_origin.write_to_SVG(); } void @@ -701,31 +707,43 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::processObjects(LpeAction lpe_action) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::const_iterator el_it = elements.begin(); - el_it != elements.end();++el_it) { - const char * id = (const char *)(*el_it); - std::cout << id << "asdfffgasdfasdsdgf\n"; + for (std::vector::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { + SPCSSAttr *css; + Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - break; + break; + case LPE_ERASE: - elemref->deleteObject(); - break; - default: //LPE_VISIBILITY - if (!this->isVisible()) { - elemref->getRepr()->setAttribute("style", "display:none"); + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + elemref->deleteObject(); + } + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + css->setAttribute("display", "none"); } else { - elemref->getRepr()->setAttribute("style", NULL); + css->setAttribute("display", NULL); } - break; + sp_repr_css_write_string(css,css_str); + elemref->getRepr()->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index d680282a5..dea5ca47a 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -62,6 +62,7 @@ private: ScalarParam helpline_overlap; ScalarParam scale; TextParam format; + TextParam id_origin; BoolParam arrows_outside; BoolParam flip_side; BoolParam scale_sensitive; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e44d57a0e..bb38acbf1 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -24,6 +24,8 @@ #include "uri.h" #include "uri-references.h" #include "knotholder.h" +#include "style.h" +#include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -98,12 +100,9 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) actual = false; return; } - } else { - } } } - using namespace Geom; original_bbox(lpeitem); Geom::Affine m = Geom::identity();//lpeitem->transform; @@ -170,7 +169,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); - Geom::Point gap = Geom::Point(split_gap,0); + Geom::Point gap(split_gap,0); Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); double cos = 0; @@ -180,7 +179,9 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) sin = (point_b[1] - point_a[1]) / hyp; } Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - gap *= m2; + Geom::Point dir = unit_vector(point_b - point_a); + Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; + line_separation *= Geom::Translate(offset); Geom::Scale sca(1.0, -1.0); const char * id_original = id_origin.param_getSVGValue(); const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); @@ -188,24 +189,23 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) m = m * sca; m = m * m2.inverse(); m = m * m1; - m = m * gap; m = m * lpeitem->transform; if (std::strcmp(splpeitem->getId(), id) == 0) { createMirror(splpeitem, m, id_original); } else { createMirror(splpeitem, m, id); } - ms_elements.clear(); - ms_elements.push_back(id); - ms_elements.push_back(id_original); + elements.clear(); + elements.push_back(id); + elements.push_back(id_original); } else { - ms_elements.clear(); + elements.clear(); processObjects(LPE_ERASE); } } //void -//LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...) +//LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...) //{ // va_list args; // va_start(args, first_attribute); @@ -219,14 +219,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) // index++; // } // } -// while(char const * att = va_arg(args, char const *)) { +// while(const char * att = va_arg(args, const char *)) { // dest->setAttribute(att,origin->attribute(att)); // } // va_end(args); //} void -LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, char const * first_attribute, ...) +LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...) { va_list args; va_start(args, first_attribute); @@ -241,31 +241,27 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c index++; } } - unsigned counter = 0; - while(char const * att = va_arg(args, char const *)) { - if (counter % 2 != 0){ - SPShape * shape = SP_SHAPE(origin); - if (shape) { - if ( live && (att == "d" || att == "inkscape:original-d")) { - SPCurve *c = NULL; - if (att == "d") { - c = shape->getCurve(); - } else { - c = shape->getCurveBeforeLPE(); - } - if (c) { - dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); - c->reset(); - g_free(c); - } else { - dest->getRepr()->setAttribute(att,NULL); - } + for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + SPShape * shape = SP_SHAPE(origin); + if (shape) { + if ( live && (att == "d" || att == "inkscape:original-d")) { + SPCurve *c = NULL; + if (att == "d") { + c = shape->getCurve(); + } else { + c = shape->getCurveBeforeLPE(); + } + if (c) { + dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); + c->reset(); + g_free(c); } else { - dest->getRepr()->setAttribute(att,origin->getRepr()->attribute(att)); + dest->getRepr()->setAttribute(att,NULL); } + } else { + dest->getRepr()->setAttribute(att,origin->getRepr()->attribute(att)); } } - counter++; } va_end(args); } @@ -291,7 +287,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = ms_container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d"); + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -315,8 +311,8 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) { if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - std::cout << ms_elements.size() << "ms_elements.size() ms_elements.size() ms_elements.size() ms_elements.size() ms_elements.size() \n"; - ms_elements.clear(); + std::cout << elements.size() << "elements.size() elements.size() elements.size() elements.size() elements.size() \n"; + elements.clear(); return; } processObjects(LPE_ERASE); @@ -326,37 +322,47 @@ void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::iterator el_it = ms_elements.begin(); - el_it != ms_elements.end(); ++el_it) { + for (std::vector::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { const char * id = *el_it; Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { - SPLPEItem *lpe_element = dynamic_cast(elemref); + SPCSSAttr *css; + Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - if (lpe_element && lpe_element->hasPathEffect()) { - lpe_element->removeAllPathEffects(true); - } - break; + break; + case LPE_ERASE: - elemref->deleteObject(); - break; - default: //LPE_VISIBILITY - if (!this->isVisible()) { - elemref->getRepr()->setAttribute("style", "display:none"); + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + elemref->deleteObject(); + } + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + css->setAttribute("display", "none"); } else { - elemref->getRepr()->setAttribute("style", NULL); + css->setAttribute("display", NULL); } - break; + sp_repr_css_write_string(css,css_str); + elemref->getRepr()->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } } if (lpe_action == LPE_ERASE) { - ms_elements.clear(); + elements.clear(); } } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 9ca86872f..7b090ed82 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -56,8 +56,8 @@ public: /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); -// void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, char const * first_attribute, ...); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, char const * first_attribute, ...); +// void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: @@ -77,7 +77,7 @@ private: Geom::Point previous_center; Geom::Point center_point; bool actual; - std::vector ms_elements; + std::vector elements; SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 67c59fe00892c5e22704515e627c938be2c7e422 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 13:29:18 +0100 Subject: fix bug #1644621 on show handles Fixed bugs: - https://launchpad.net/bugs/1644621 (bzr r15305) --- src/live_effects/lpe-show_handles.cpp | 38 +++++++++++++++++++++++------------ src/live_effects/lpe-show_handles.h | 5 +++-- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 388ea176f..2cbaa2707 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -24,20 +24,17 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) nodes(_("Show nodes"), _("Show nodes"), "nodes", &wr, this, true), handles(_("Show handles"), _("Show handles"), "handles", &wr, this, true), original_path(_("Show path"), _("Show path"), "original_path", &wr, this, true), - scale_nodes_and_handles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scale_nodes_and_handles", &wr, this, 10), - rotate_nodes(_("Rotate nodes"), _("Rotate nodes"), "rotate_nodes", &wr, this, 0) + show_center_node(_("Show center of node"), _("Show center of node"), "show_center_node", &wr, this, false), + scale_nodes_and_handles(_("Scale nodes and handles"), _("Scale nodes and handles"), "scale_nodes_and_handles", &wr, this, 10) { registerParameter(&nodes); registerParameter(&handles); registerParameter(&original_path); + registerParameter(&show_center_node); registerParameter(&scale_nodes_and_handles); - registerParameter(&rotate_nodes); scale_nodes_and_handles.param_set_range(0, 500.); scale_nodes_and_handles.param_set_increments(1, 1); scale_nodes_and_handles.param_set_digits(2); - rotate_nodes.param_set_range(0, 365); - rotate_nodes.param_set_increments(1, 1); - rotate_nodes.param_set_digits(0); stroke_width = 1.0; } @@ -129,7 +126,11 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) } } if(nodes) { - drawNode(curve_it1->initialPoint()); + Geom::NodeType nodetype = Geom::NODE_CUSP; + if(path_it->closed()) { + nodetype = Geom::get_nodetype(*curve_it1, path_it->back()); + } + drawNode(curve_it1->initialPoint(), nodetype); } while (curve_it1 != curve_endit) { cubic = dynamic_cast(&*curve_it1); @@ -145,8 +146,9 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) } } } - if(nodes) { - drawNode(curve_it1->finalPoint()); + if(nodes && (curve_it2 != curve_endit || !path_it->closed())) { + Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, *curve_it2); + drawNode(curve_it1->finalPoint(), nodetype); } ++curve_it1; if(curve_it2 != curve_endit) { @@ -157,16 +159,26 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) } void -LPEShowHandles::drawNode(Geom::Point p) +LPEShowHandles::drawNode(Geom::Point p, Geom::NodeType nodetype) { if(stroke_width * scale_nodes_and_handles > 0.0) { + Geom::Rotate rotate = Geom::Rotate(0); + if ( nodetype == Geom::NODE_CUSP) { + rotate = Geom::Rotate::from_degrees(45); + } double diameter = stroke_width * scale_nodes_and_handles; char const * svgd; - svgd = "M 0.05,0 A 0.05,0.05 0 0 1 0,0.05 0.05,0.05 0 0 1 -0.05,0 0.05,0.05 0 0 1 0,-0.05 0.05,0.05 0 0 1 0.05,0 Z M -0.5,-0.5 0.5,-0.5 0.5,0.5 -0.5,0.5 Z"; + if (show_center_node) { + svgd = "M 0.05,0 A 0.05,0.05 0 0 1 0,0.05 0.05,0.05 0 0 1 -0.05,0 0.05,0.05 0 0 1 0,-0.05 0.05,0.05 0 0 1 0.05,0 Z M -0.5,-0.5 0.5,-0.5 0.5,0.5 -0.5,0.5 Z"; + } else { + svgd = "M -0.5,-0.5 0.5,-0.5 0.5,0.5 -0.5,0.5 Z"; + } Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Rotate::from_degrees(rotate_nodes) * Geom::Scale(diameter) * Geom::Translate(p); + pathv *= rotate * Geom::Scale(diameter) * Geom::Translate(p); outline_path.push_back(pathv[0]); - outline_path.push_back(pathv[1]); + if (show_center_node) { + outline_path.push_back(pathv[1]); + } } } diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 8bff3c1a8..3eda04649 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -9,6 +9,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include +#include "helper/geom-nodetype.h" #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" #include "live_effects/parameter/bool.h" @@ -28,7 +29,7 @@ public: virtual void generateHelperPath(Geom::PathVector result); - virtual void drawNode(Geom::Point p); + virtual void drawNode(Geom::Point p, Geom::NodeType nodetype); virtual void drawHandle(Geom::Point p); @@ -43,8 +44,8 @@ private: BoolParam nodes; BoolParam handles; BoolParam original_path; + BoolParam show_center_node; ScalarParam scale_nodes_and_handles; - ScalarParam rotate_nodes; double stroke_width; static bool alerts_off; -- cgit v1.2.3 From c178aad1e6eb84bf507b0da8bdda95677711f3cb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 13:44:59 +0100 Subject: fix bug #1644621 on show handles. Fix start knot on closed paths Fixed bugs: - https://launchpad.net/bugs/1644621 (bzr r15306) --- src/live_effects/lpe-show_handles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 2cbaa2707..170b6dccb 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -128,7 +128,7 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) if(nodes) { Geom::NodeType nodetype = Geom::NODE_CUSP; if(path_it->closed()) { - nodetype = Geom::get_nodetype(*curve_it1, path_it->back()); + nodetype = Geom::get_nodetype(path_it->finalCurve(), *curve_it1); } drawNode(curve_it1->initialPoint(), nodetype); } -- cgit v1.2.3 From 5556bd47f01333db15eae21a0db110e5944a65d7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 18:34:44 +0100 Subject: Fix for reopened bug #1643408 (bzr r15308) --- src/live_effects/lpe-patternalongpath.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index f9bad0610..0a5965b86 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -171,8 +171,11 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con Piecewise > uskeleton = arc_length_parametrization(path_i,2,.1); uskeleton = remove_short_cuts(uskeleton,.01); Piecewise > n = rot90(derivative(uskeleton)); - n = force_continuity(remove_short_cuts(n,.1),.01); - + if (Geom::are_near(pwd2_in[0].at0(),pwd2_in[pwd2_in.size()-1].at1(),0.01)) { + n = force_continuity(remove_short_cuts(n,0.1),0.01); + } else { + n = force_continuity(remove_short_cuts(n,0.1)); + } int nbCopies = 0; double scaling = 1; switch(type) { -- cgit v1.2.3 From ca8a79c512fed1699932ad1d2785ade64032338c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 18:41:57 +0100 Subject: Fix for reopened bug #1643408- minor typyng (bzr r15309) --- src/live_effects/lpe-patternalongpath.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 0a5965b86..15c2817c4 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -149,8 +149,8 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con } //Prevent more than 90% overlap... - if (xspace < -pattBndsX->extent()*.9) { - xspace = -pattBndsX->extent()*.9; + if (xspace < -pattBndsX->extent() * 0.9) { + xspace = -pattBndsX->extent() * 0.9; } //TODO: dynamical update of parameter ranges? //if (prop_units.get_value()){ @@ -168,13 +168,13 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con Geom::Piecewise > path_i = paths_in[idx]; Piecewise x = x0; Piecewise y = y0; - Piecewise > uskeleton = arc_length_parametrization(path_i,2,.1); - uskeleton = remove_short_cuts(uskeleton,.01); + Piecewise > uskeleton = arc_length_parametrization(path_i,2, 0.1); + uskeleton = remove_short_cuts(uskeleton, 0.01); Piecewise > n = rot90(derivative(uskeleton)); - if (Geom::are_near(pwd2_in[0].at0(),pwd2_in[pwd2_in.size()-1].at1(),0.01)) { - n = force_continuity(remove_short_cuts(n,0.1),0.01); + if (Geom::are_near(pwd2_in[0].at0(),pwd2_in[pwd2_in.size()-1].at1(), 0.01)) { + n = force_continuity(remove_short_cuts(n, 0.1), 0.01); } else { - n = force_continuity(remove_short_cuts(n,0.1)); + n = force_continuity(remove_short_cuts(n, 0.1)); } int nbCopies = 0; double scaling = 1; -- cgit v1.2.3 From 832e5be17eb44f74710b680b493e8ad7ed957128 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 18:47:41 +0100 Subject: Fixing retaining LPE on extra elements (bzr r15295.1.13) --- src/live_effects/lpe-mirror_symmetry.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index bb38acbf1..abf578078 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -287,7 +287,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = ms_container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -334,7 +334,9 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + if (sp_lpe_item->getId() != id) { + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + } elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); break; -- cgit v1.2.3 From 9b078f84a03865319b411bf537c256744d46e8e3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 7 Dec 2016 20:07:41 +0100 Subject: fixing extra LPE on copies on release (bzr r15295.1.15) --- src/live_effects/lpe-measure-line.cpp | 9 ++++++++- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 8b73781b5..3d0583f55 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -696,7 +696,9 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { + std::cout << "111111111111111111111111\n"; if (!erase_extra_objects) { + std::cout << "2222222222222222222222222\n"; processObjects(LPE_TO_OBJECTS); elements.clear(); return; @@ -720,7 +722,12 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + std::cout << sp_lpe_item->getId() << "sp_lpe_item->getId()\n"; + std::cout << id << "Id()\n"; + if (std::strcmp(sp_lpe_item->getId(), id) != 0) { + std::cout << id << "loborro\n"; + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + } elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); break; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index abf578078..fd7c7824d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -334,7 +334,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - if (sp_lpe_item->getId() != id) { + if (std::strcmp(sp_lpe_item->getId(), id) != 0) { elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); } elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); -- cgit v1.2.3 From 6586a50de3ad7f47a895f904ff66cc6613d62124 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 7 Dec 2016 23:17:49 +0100 Subject: Improve measure line to allow similar LPE (bzr r15310) --- src/live_effects/lpe-measure-line.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 8b73781b5..45076d625 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -686,7 +686,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } - void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { @@ -696,6 +695,7 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { + //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); elements.clear(); @@ -711,6 +711,9 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) for (std::vector::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it) { const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); -- cgit v1.2.3 From 043cb3136f9118e411aff77e8105b3ac0b05b6b8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 7 Dec 2016 23:19:44 +0100 Subject: Fix the duplicated LPE on erase bug (bzr r15295.1.16) --- src/live_effects/lpe-measure-line.cpp | 15 ++++++--------- src/live_effects/lpe-mirror_symmetry.cpp | 11 ++++++----- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 3d0583f55..ef63888d9 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -686,7 +686,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } - +//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { @@ -696,9 +696,8 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - std::cout << "111111111111111111111111\n"; + //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { - std::cout << "2222222222222222222222222\n"; processObjects(LPE_TO_OBJECTS); elements.clear(); return; @@ -713,6 +712,9 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) for (std::vector::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it) { const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -722,12 +724,7 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - std::cout << sp_lpe_item->getId() << "sp_lpe_item->getId()\n"; - std::cout << id << "Id()\n"; - if (std::strcmp(sp_lpe_item->getId(), id) != 0) { - std::cout << id << "loborro\n"; - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - } + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); break; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index fd7c7824d..a338f60f4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -299,7 +299,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const } } - +//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { @@ -309,9 +309,9 @@ LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) { + //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - std::cout << elements.size() << "elements.size() elements.size() elements.size() elements.size() elements.size() \n"; elements.clear(); return; } @@ -325,6 +325,9 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) for (std::vector::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it) { const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); @@ -334,9 +337,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - if (std::strcmp(sp_lpe_item->getId(), id) != 0) { - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - } + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); break; -- cgit v1.2.3 From 29ce4ffa9e5e7ba3baf08a43e5848c0bc8038149 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 8 Dec 2016 03:08:15 +0100 Subject: Noumerous bugfixes (bzr r15295.1.18) --- src/live_effects/lpe-measure-line.cpp | 16 ++++++++++++---- src/live_effects/lpe-mirror_symmetry.cpp | 20 +++++++++++++------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ef63888d9..8847b78aa 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -24,6 +24,7 @@ #include "svg/svg.h" #include "display/curve.h" #include "2geom/affine.h" +#include "path-chemistry.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -720,12 +721,19 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { + Inkscape::XML::Node * elemnode = elemref->getRepr(); + std::vector item_list; + item_list.push_back(SP_ITEM(elemref)); + std::vector item_to_select; + std::vector item_selected; SPCSSAttr *css; Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); break; case LPE_ERASE: @@ -743,7 +751,7 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) css->setAttribute("display", NULL); } sp_repr_css_write_string(css,css_str); - elemref->getRepr()->setAttribute("style", css_str.c_str()); + elemnode->setAttribute("style", css_str.c_str()); break; default: @@ -751,7 +759,7 @@ LPEMeasureLine::processObjects(LpeAction lpe_action) } } } - if (lpe_action == LPE_ERASE) { + if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { elements.clear(); } } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a338f60f4..11620b23f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -23,6 +23,7 @@ #include "2geom/affine.h" #include "uri.h" #include "uri-references.h" +#include "path-chemistry.h" #include "knotholder.h" #include "style.h" #include "xml/sp-css-attr.h" @@ -93,7 +94,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty() ) { + if ( sel && !sel->isEmpty() && actual) { SPItem *item = sel->singleItem(); if (item) { if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { @@ -312,7 +313,6 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - elements.clear(); return; } processObjects(LPE_ERASE); @@ -333,12 +333,19 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) SVGElemRef->attach(SVGElem_uri); SPObject *elemref = NULL; if (elemref = SVGElemRef->getObject()) { + Inkscape::XML::Node * elemnode = elemref->getRepr(); + std::vector item_list; + item_list.push_back(SP_ITEM(elemref)); + std::vector item_to_select; + std::vector item_selected; SPCSSAttr *css; Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); break; case LPE_ERASE: @@ -356,7 +363,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) css->setAttribute("display", NULL); } sp_repr_css_write_string(css,css_str); - elemref->getRepr()->setAttribute("style", css_str.c_str()); + elemnode->setAttribute("style", css_str.c_str()); break; default: @@ -364,7 +371,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) } } } - if (lpe_action == LPE_ERASE) { + if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { elements.clear(); } } @@ -627,7 +634,6 @@ KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point LPEMirrorSymmetry* lpe = dynamic_cast(_effect); Geom::Point const s = snap_knot_position(p, state); lpe->center_point = s; - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } -- cgit v1.2.3 From 5c9722f0f1e8133300a9146439b1de4b60274488 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 8 Dec 2016 23:21:24 +0100 Subject: 'upport' changes to LPE's rotate copies and mirrot symmetry (bzr r15313) --- src/live_effects/lpe-copy_rotate.cpp | 155 ++++++++++--------------------- src/live_effects/lpe-copy_rotate.h | 16 +--- src/live_effects/lpe-mirror_symmetry.cpp | 144 ++++++++++++---------------- src/live_effects/lpe-mirror_symmetry.h | 11 +-- 4 files changed, 117 insertions(+), 209 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 1133e083a..a21d67078 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -15,32 +15,12 @@ #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" - -#include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { namespace LivePathEffect { -namespace CR { - -class KnotHolderEntityStartingAngle : public LPEKnotHolderEntity { -public: - KnotHolderEntityStartingAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity { -public: - KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace CR - bool pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) { @@ -59,6 +39,7 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this), + starting_point("hidden", "hidden", "starting_point", &wr, this), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), @@ -74,6 +55,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&copies_to_360); registerParameter(&fuse_paths); registerParameter(&starting_angle); + registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&origin); @@ -87,6 +69,41 @@ LPECopyRotate::~LPECopyRotate() } +Gtk::Widget * LPECopyRotate::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "starting_point") { + 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(vbox); +} + + void LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) { @@ -104,11 +121,6 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(fuse_paths) { - Geom::Coord angle = Geom::deg_from_rad(atan(-postmul[1]/postmul[0])); - angle += starting_angle; - starting_angle.param_set_value(angle); - } // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { @@ -146,11 +158,25 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) dir = unit_vector(B - A); // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) + bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); + if (!near) { + starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); + if (GDK_SHIFT_MASK) { + dist_angle_handle = L2(B - A); + } else { + dist_angle_handle = L2(starting_point - origin); + } + } start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; + if (near) { + starting_point.param_setValue(start_pos); + } + previous_start_point = (Geom::Point)starting_point; if ( fuse_paths || copies_to_360 ) { rot_pos = origin; } + SPLPEItem * item = const_cast(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -418,85 +444,6 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } -void -LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - { - KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the starting angle")); - knotholder->add(e); - } - { - KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the rotation angle")); - knotholder->add(e); - } -}; - -namespace CR { - -using namespace Geom; - -void -KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - LPECopyRotate* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - lpe->starting_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin))); - if (state & GDK_SHIFT_MASK) { - lpe->dist_angle_handle = L2(lpe->B - lpe->A); - } else { - lpe->dist_angle_handle = L2(p - lpe->origin); - } - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -void -KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - LPECopyRotate* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - lpe->rotation_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle); - if (state & GDK_SHIFT_MASK) { - lpe->dist_angle_handle = L2(lpe->B - lpe->A); - } else { - lpe->dist_angle_handle = L2(p - lpe->origin); - } - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityStartingAngle::knot_get() const -{ - LPECopyRotate const *lpe = dynamic_cast(_effect); - return lpe->start_pos; -} - -Geom::Point -KnotHolderEntityRotationAngle::knot_get() const -{ - LPECopyRotate const *lpe = dynamic_cast(_effect); - return lpe->rot_pos; -} - -} // namespace CR - -/* ######################## */ - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 87af867df..f189ffa04 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -13,7 +13,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" @@ -21,12 +21,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace CR { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityStartingAngle; -class KnotHolderEntityRotationAngle; -} - class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); @@ -38,16 +32,13 @@ public: virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); - /* the knotholder entity classes must be declared friends */ - friend class CR::KnotHolderEntityStartingAngle; - friend class CR::KnotHolderEntityRotationAngle; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - + virtual Gtk::Widget * newWidget(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: PointParam origin; + PointParam starting_point; ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; @@ -58,6 +49,7 @@ private: Geom::Point dir; Geom::Point start_pos; Geom::Point rot_pos; + Geom::Point previous_start_point; double dist_angle_handle; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 4deb29d8f..c5c9b7260 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -18,8 +18,8 @@ #include #include "helper/geom.h" #include <2geom/path-intersection.h> -#include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { @@ -34,39 +34,16 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); -namespace MS { - -class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -class KnotHolderEntityStartMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityStartMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -class KnotHolderEntityEndMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityEndMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace MS - LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), + //TODO: Fix htip for multilang start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring") + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), + center_point("hidden","hidden", "center_point", &wr, this, "hidden") { show_orig_path = true; registerParameter(&mode); @@ -75,15 +52,51 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &oposite_fuse); registerParameter( &start_point); registerParameter( &end_point); + registerParameter( ¢er_point); apply_to_clippath_and_mask = true; + previous_center = Geom::Point(0,0); } LPEMirrorSymmetry::~LPEMirrorSymmetry() { } -void +Gtk::Widget * LPEMirrorSymmetry::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "center_point") { + 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(vbox); +} + +void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; @@ -99,19 +112,21 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } - line_separation.setPoints(point_a, point_b); - if ( mode == MT_X || mode == MT_Y ) { + if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); - center_point = Geom::middle_point(point_a, point_b); + } + line_separation.setPoints(point_a, point_b); + if ( mode == MT_X || mode == MT_Y ) { + start_point.param_setValue(point_a, true); + end_point.param_setValue(point_b, true); } else if ( mode == MT_FREE) { if(!are_near(previous_center,center_point, 0.01)) { Geom::Point trans = center_point - previous_center; - start_point.param_setValue(start_point * trans); - end_point.param_setValue(end_point * trans); + start_point.param_setValue(start_point * trans, true); + end_point.param_setValue(end_point * trans, true); line_separation.setPoints(start_point, end_point); } else { - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ @@ -120,11 +135,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - start_point.param_setValue(sp); + start_point.param_setValue(sp, true); Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + end_point.param_setValue(ep, true); line_separation.setPoints(start_point, end_point); } } else { //horizontal page @@ -133,22 +147,22 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - start_point.param_setValue(sp); + start_point.param_setValue(sp, true); Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + end_point.param_setValue(ep, true); line_separation.setPoints(start_point, end_point); } } - previous_center = center_point; + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + if (!are_near(previous_center, center_point,0.01)) { + center_point.param_setValue(previous_center); + } } void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { - center_point *= postmul; - previous_center = center_point; // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; @@ -166,11 +180,11 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); - start_point.param_setValue(point_a); + start_point.param_setValue(point_a, true); start_point.param_update_default(point_a); - end_point.param_setValue(point_b); + end_point.param_setValue(point_b, true); end_point.param_update_default(point_b); - center_point = point_c; + center_point.param_setValue(point_c); previous_center = center_point; } @@ -330,44 +344,6 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector hp_vec.push_back(helper); } -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; - SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; - guint32 knot_color = 0x0000ff00; - { - KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center"), knot_shape, knot_mode, knot_color ); - knotholder->add(c); - } -}; - -namespace MS { - -using namespace Geom; - -void -KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - LPEMirrorSymmetry* lpe = dynamic_cast(_effect); - Geom::Point const s = snap_knot_position(p, state); - lpe->center_point = s; - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityCenterMirrorSymmetry::knot_get() const -{ - LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); - return lpe->center_point; -} - -} // namespace CR - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7ec4029e0..cabd00546 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -26,11 +26,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace MS { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityCenterMirrorSymmetry; -} - enum ModeType { MT_V, MT_H, @@ -48,9 +43,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); - /* the knotholder entity classes must be declared friends */ - friend class MS::KnotHolderEntityCenterMirrorSymmetry; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual Gtk::Widget * newWidget(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -62,9 +55,9 @@ private: BoolParam oposite_fuse; PointParam start_point; PointParam end_point; + PointParam center_point; Geom::Line line_separation; Geom::Point previous_center; - Geom::Point center_point; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 76dc7d78c1f595659cb32d34bf046e13fe08721e Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 8 Dec 2016 23:22:16 +0100 Subject: Working on nested LPE (bzr r15295.1.19) --- src/live_effects/lpe-mirror_symmetry.cpp | 146 +++++++------------------------ src/live_effects/lpe-mirror_symmetry.h | 13 +-- 2 files changed, 35 insertions(+), 124 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 11620b23f..8225c152f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -43,17 +43,6 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); -namespace MS { - -class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace MS - LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), @@ -62,9 +51,9 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), - id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { show_orig_path = true; registerParameter(&mode); @@ -75,13 +64,12 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &split_elements); registerParameter( &start_point); registerParameter( &end_point); - registerParameter( &id_origin); - id_origin.param_hide_canvas_text(); + registerParameter( ¢er_point); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; - actual = true; + previous_center = Geom::Point(0,0); } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -94,11 +82,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty() && actual) { + if ( sel && !sel->isEmpty()) { SPItem *item = sel->singleItem(); if (item) { if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { - actual = false; return; } } @@ -117,11 +104,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } + if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { + start_point.param_setValue(point_a); + end_point.param_setValue(point_b); + } line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); - center_point = Geom::middle_point(point_a, point_b); } else if ( mode == MT_FREE) { if(!are_near(previous_center,center_point, 0.01)) { Geom::Point trans = center_point - previous_center; @@ -129,7 +119,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans); line_separation.setPoints(start_point, end_point); } else { - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ @@ -142,7 +131,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else { //horizontal page @@ -155,11 +143,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } - previous_center = center_point; + + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + if (!are_near(previous_center, center_point,0.01)) { + center_point.param_setValue(previous_center); + } if (split_elements) { ms_container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; @@ -168,6 +159,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } + Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); Geom::Point gap(split_gap,0); @@ -184,21 +176,22 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; line_separation *= Geom::Translate(offset); Geom::Scale sca(1.0, -1.0); - const char * id_original = id_origin.param_getSVGValue(); - const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); + const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); + const char * mirror_b = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); m = m1.inverse() * m2; m = m * sca; m = m * m2.inverse(); m = m * m1; m = m * lpeitem->transform; - if (std::strcmp(splpeitem->getId(), id) == 0) { - createMirror(splpeitem, m, id_original); - } else { - createMirror(splpeitem, m, id); + if (std::strcmp(splpeitem->getId(), mirror_a) != 0) { + createMirror(splpeitem, m, mirror_a); + } + if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { + createMirror(splpeitem, m, mirror_b); } elements.clear(); - elements.push_back(id); - elements.push_back(id_original); + elements.push_back(mirror_a); + elements.push_back(mirror_b); } else { elements.clear(); processObjects(LPE_ERASE); @@ -288,7 +281,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = ms_container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -349,7 +342,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { elemref->deleteObject(); } break; @@ -357,7 +350,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) case LPE_VISIBILITY: css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + if (!this->isVisible() && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { css->setAttribute("display", "none"); } else { css->setAttribute("display", NULL); @@ -382,8 +375,6 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { if( !split_elements) { - center_point *= postmul; - previous_center = center_point; // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; @@ -406,10 +397,13 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b); end_point.param_update_default(point_b); - center_point = point_c; + center_point.param_setValue(point_c); previous_center = center_point; - id_origin.param_setValue(Glib::ustring(lpeitem->getId())); - id_origin.write_to_SVG(); + SPLPEItem * splpeitem = const_cast(lpeitem); + Glib::ustring mirror_a = Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")); + if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet + splpeitem->getRepr()->setAttribute("id", mirror_a.c_str()); + } } @@ -560,41 +554,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) return path_out; } - -Gtk::Widget *LPEMirrorSymmetry::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "id_origin") { - 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(vbox); -} - void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { @@ -610,43 +569,6 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector hp_vec.push_back(helper); } -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; - SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; - guint32 knot_color = 0x0000ff00; - { - KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center"), knot_shape, knot_mode, knot_color ); - knotholder->add(c); - } -}; - -namespace MS { - -using namespace Geom; - -void -KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - LPEMirrorSymmetry* lpe = dynamic_cast(_effect); - Geom::Point const s = snap_knot_position(p, state); - lpe->center_point = s; - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityCenterMirrorSymmetry::knot_get() const -{ - LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); - return lpe->center_point; -} - -} // namespace CR - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7b090ed82..fba16c750 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -27,11 +27,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace MS { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityCenterMirrorSymmetry; -} - enum ModeType { MT_V, MT_H, @@ -51,14 +46,10 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); - virtual Gtk::Widget *newWidget(); void processObjects(LpeAction lpe_action); - /* the knotholder entity classes must be declared friends */ - friend class MS::KnotHolderEntityCenterMirrorSymmetry; void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -72,11 +63,9 @@ private: BoolParam split_elements; PointParam start_point; PointParam end_point; - TextParam id_origin; + PointParam center_point; Geom::Line line_separation; Geom::Point previous_center; - Geom::Point center_point; - bool actual; std::vector elements; SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); -- cgit v1.2.3 From e973e1fc03c1b10c52a21af5f354f63b0f6624bd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 10 Dec 2016 17:15:17 +0100 Subject: Fix headers on LPE's (bzr r15318) --- src/live_effects/lpe-angle_bisector.cpp | 8 +++----- src/live_effects/lpe-attach-path.cpp | 5 ++--- src/live_effects/lpe-bendpath.cpp | 3 ++- src/live_effects/lpe-bounding-box.cpp | 6 +++--- src/live_effects/lpe-bspline.h | 2 +- src/live_effects/lpe-circle_3pts.cpp | 2 ++ src/live_effects/lpe-circle_with_radius.cpp | 2 ++ src/live_effects/lpe-clone-original.cpp | 5 ++--- src/live_effects/lpe-constructgrid.cpp | 4 ++-- src/live_effects/lpe-copy_rotate.cpp | 1 + src/live_effects/lpe-copy_rotate.h | 2 +- src/live_effects/lpe-curvestitch.cpp | 5 +++-- src/live_effects/lpe-dynastroke.cpp | 2 ++ src/live_effects/lpe-ellipse_5pts.cpp | 5 ++--- src/live_effects/lpe-envelope.cpp | 2 ++ src/live_effects/lpe-extrude.cpp | 4 ++-- src/live_effects/lpe-fill-between-many.cpp | 2 +- src/live_effects/lpe-fill-between-strokes.cpp | 5 ++--- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-gears.cpp | 5 ++--- src/live_effects/lpe-interpolate.cpp | 6 +++--- src/live_effects/lpe-interpolate_points.cpp | 3 ++- src/live_effects/lpe-jointype.cpp | 2 ++ src/live_effects/lpe-knot.cpp | 3 +++ src/live_effects/lpe-lattice.cpp | 3 ++- src/live_effects/lpe-lattice2.cpp | 3 +++ src/live_effects/lpe-lattice2.h | 2 +- src/live_effects/lpe-line_segment.cpp | 2 ++ src/live_effects/lpe-mirror_symmetry.cpp | 3 +++ src/live_effects/lpe-mirror_symmetry.h | 2 +- src/live_effects/lpe-offset.cpp | 5 ++--- src/live_effects/lpe-parallel.cpp | 5 +++-- src/live_effects/lpe-path_length.cpp | 4 ++-- src/live_effects/lpe-patternalongpath.cpp | 2 ++ src/live_effects/lpe-perp_bisector.cpp | 6 +++--- src/live_effects/lpe-perspective-envelope.cpp | 3 +++ src/live_effects/lpe-perspective_path.cpp | 5 +++-- src/live_effects/lpe-powerstroke.cpp | 3 +++ src/live_effects/lpe-recursiveskeleton.cpp | 5 +++-- src/live_effects/lpe-rough-hatches.cpp | 3 ++- src/live_effects/lpe-roughen.cpp | 3 +++ src/live_effects/lpe-roughen.h | 1 - src/live_effects/lpe-ruler.cpp | 3 ++- src/live_effects/lpe-show_handles.cpp | 2 ++ src/live_effects/lpe-show_handles.h | 1 - src/live_effects/lpe-simplify.cpp | 2 ++ src/live_effects/lpe-simplify.h | 1 - src/live_effects/lpe-skeleton.cpp | 3 +-- src/live_effects/lpe-sketch.cpp | 5 +++-- src/live_effects/lpe-tangent_to_curve.cpp | 4 ++-- src/live_effects/lpe-taperstroke.cpp | 2 ++ src/live_effects/lpe-test-doEffect-stack.cpp | 5 +++-- src/live_effects/lpe-text_label.cpp | 5 +++-- src/live_effects/lpe-transform_2pts.cpp | 1 + src/live_effects/lpe-vonkoch.cpp | 2 +- src/live_effects/parameter/fontbutton.cpp | 2 +- src/live_effects/parameter/fontbutton.h | 1 - 57 files changed, 112 insertions(+), 73 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 9bfbf4ca8..56d33eb4b 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -8,15 +8,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-angle_bisector.h" - -#include <2geom/sbasis-to-bezier.h> - +#include "2geom/sbasis-to-bezier.h" #include "sp-lpe-item.h" #include "knot-holder-entity.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index d2b44dd4e..302165719 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -4,15 +4,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include - #include "live_effects/lpe-attach-path.h" - #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" #include "2geom/path-sink.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index c24d38d7b..b1e133292 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -7,9 +7,10 @@ #include "live_effects/lpe-bendpath.h" #include "sp-item-group.h" - #include "knot-holder-entity.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 2de768c3a..11fb34e04 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -3,14 +3,14 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 7823f00f0..90cf82c19 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,8 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/effect.h" +#include "live_effects/effect.h" #include namespace Inkscape { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index 18252f6a0..3410b13f2 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -17,6 +17,8 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index 6e03cb1ce..fcefc4ec6 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -17,6 +17,8 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 7541c0be2..10418a02d 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -4,11 +4,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-clone-original.h" - #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 4af8891e8..8d24f9f47 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -10,9 +10,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-constructgrid.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index a21d67078..5b94e9083 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -11,6 +11,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index f189ffa04..8f9fc12ac 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -13,7 +13,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "live_effects/effect.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 3beedaf57..38cbeaac0 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -13,8 +13,6 @@ */ #include "ui/widget/scalar.h" -#include - #include "live_effects/lpe-curvestitch.h" #include "sp-path.h" @@ -22,6 +20,9 @@ #include "xml/repr.h" #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 7e22f6e51..50bbe6451 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -16,6 +16,8 @@ #include <2geom/bezier-to-sbasis.h> #include <2geom/sbasis-math.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 0371fc313..28e7058d7 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -12,15 +12,14 @@ */ #include "live_effects/lpe-ellipse_5pts.h" - -// You might need to include other 2geom files. You can add them here: -#include #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> #include "inkscape.h" #include "desktop.h" #include "message-stack.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index c3b0a7c10..61a696435 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -6,6 +6,8 @@ #include "live_effects/lpe-envelope.h" #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index d22007f76..daa30d45a 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -12,10 +12,10 @@ */ #include "live_effects/lpe-extrude.h" - +#include "sp-item.h" +// TODO due to internal breakage in glibmm headers, this must be last: #include -#include "sp-item.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 2087925fa..1e2eadfdb 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -11,7 +11,7 @@ #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" - +// TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index b1e328d18..0dbebdf26 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -3,14 +3,13 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ee2ccc3..1e2df7dc8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -25,8 +25,8 @@ // for programmatically updating knots #include "ui/tools-switch.h" - // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 1d5398aa5..17579c64e 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -7,10 +7,9 @@ */ #include "live_effects/lpe-gears.h" - -#include - #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index 43da4d105..e95dc5f38 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -9,15 +9,15 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-interpolate.h" #include <2geom/sbasis-to-bezier.h> #include "sp-path.h" #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index ab0576174..0a0bcea14 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -12,8 +12,9 @@ */ #include "live_effects/lpe-interpolate_points.h" - #include "live_effects/lpe-powerstroke-interpolators.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index 3bfbd6288..dacb87dd9 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -19,6 +19,8 @@ #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 474523aa3..c35da0601 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -33,6 +33,9 @@ #include "document.h" #include "document-undo.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 091b6ddca..acffed000 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -20,7 +20,8 @@ #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> - +// TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 9e9fc153a..e827491c0 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -16,12 +16,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-lattice2.h" #include "display/curve.h" #include "helper/geom.h" #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> + // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 4a025d182..59a0350d3 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,7 +18,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/point.h" diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index 4c9edabd4..cc024fb92 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -13,6 +13,8 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index c5c9b7260..482b8bfa4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -13,11 +13,14 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include #include "live_effects/lpe-mirror_symmetry.h" #include #include #include "helper/geom.h" #include <2geom/path-intersection.h> + // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index cabd00546..a7d271453 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -15,7 +15,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/point.h" diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index a0fa46c3f..057f404e0 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -11,13 +11,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-offset.h" #include "sp-shape.h" #include "display/curve.h" - #include <2geom/elliptical-arc.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 9cd8ecf46..276749c43 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -11,14 +11,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-parallel.h" #include "sp-shape.h" #include "display/curve.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 6ec1e0ede..a06dbde98 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -11,10 +11,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-path_length.h" #include "util/units.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 15c2817c4..9cfeffee7 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -12,6 +12,8 @@ #include "knotholder.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index f69dae6a1..bce22250a 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -11,9 +11,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-perp_bisector.h" #include "display/curve.h" #include "sp-path.h" @@ -21,6 +18,9 @@ #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { namespace PB { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 6a6b59519..e834c0e86 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -20,6 +20,9 @@ #include "display/curve.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include + using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index cb4e43d87..2c6d66cee 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -11,8 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include -#include - #include "persp3d.h" //#include "transf_mat_3x4.h" #include "document-private.h" @@ -23,6 +21,9 @@ #include "desktop.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 329a00756..e9f3975c7 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -25,6 +25,9 @@ #include <2geom/circle.h> #include "helper/geom.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index ed0c915ce..aa0db920b 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -10,12 +10,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-recursiveskeleton.h" #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 2fb65b349..3cc8658ea 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -13,7 +13,6 @@ */ #include "ui/widget/scalar.h" -#include #include "live_effects/lpe-rough-hatches.h" #include "sp-item.h" @@ -23,6 +22,8 @@ #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 3a486ff10..c6edffd9b 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -13,11 +13,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-roughen.h" #include "display/curve.h" #include #include "helper/geom.h" + // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index dbdb91e62..bab06022f 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -12,7 +12,6 @@ #ifndef INKSCAPE_LPE_ROUGHEN_H #define INKSCAPE_LPE_ROUGHEN_H -#include #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/parameter.h" diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 3a2d78b2c..60c2a3e1c 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,7 +12,8 @@ */ #include "live_effects/lpe-ruler.h" - +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 170b6dccb..7c298d0e7 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -6,6 +6,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-show_handles.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> @@ -13,6 +14,7 @@ #include "desktop-style.h" #include "style.h" #include "svg/svg.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 3eda04649..c46abd2c2 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -8,7 +8,6 @@ * Copyright (C) Jabier Arraiza Cenoz 2014 * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "helper/geom-nodetype.h" #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index ec21e10d2..8bdb19b4f 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -2,6 +2,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-simplify.h" #include "display/curve.h" #include "helper/geom.h" @@ -9,6 +10,7 @@ #include "svg/svg.h" #include "ui/tools/node-tool.h" #include "ui/icon-names.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 8135561af..6c407f572 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -6,7 +6,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/effect.h" #include "live_effects/parameter/togglebutton.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 7d34db699..adc4a3493 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -20,8 +20,7 @@ #include "live_effects/lpe-skeleton.h" -// You might need to include other 2geom files. You can add them here: - +// TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 95e2f6f0d..e01516f2e 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -13,13 +13,14 @@ #include "live_effects/lpe-sketch.h" -#include - // You might need to include other 2geom files. You can add them here: #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/path-intersection.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index b308ef8d7..76d4ea71b 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -13,13 +13,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-tangent_to_curve.h" #include "sp-path.h" #include "display/curve.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f6f6b33dc..4ffc41691 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -26,6 +26,8 @@ #include "svg/svg.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include template inline bool withinRange(T value, T low, T high) { diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index c7ecf6481..324893706 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -4,10 +4,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-test-doEffect-stack.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp index 602a6897c..709d05e18 100644 --- a/src/live_effects/lpe-text_label.cpp +++ b/src/live_effects/lpe-text_label.cpp @@ -11,10 +11,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-text_label.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 78db622f2..e1f36eee7 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -20,6 +20,7 @@ // TODO due to internal breakage in glibmm headers, this must be last: #include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 2486f3366..47e2a1cec 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -5,7 +5,7 @@ */ #include "live_effects/lpe-vonkoch.h" - +// TODO due to internal breakage in glibmm headers, this must be last: #include //using std::vector; diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index ff8ab76a0..64c203093 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -4,7 +4,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "ui/widget/registered-widget.h" #include "live_effects/parameter/fontbutton.h" #include "live_effects/effect.h" diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index 387ad130b..df47251a2 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -8,7 +8,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include -#include #include "live_effects/parameter/parameter.h" namespace Inkscape { -- cgit v1.2.3 From 2569672abb50eb7a6eacd5e094ed8119e83de8e7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 16 Dec 2016 12:59:18 +0100 Subject: Fixing nested mirrors (bzr r15295.1.22) --- src/live_effects/lpe-mirror_symmetry.cpp | 125 ++++++++++++++++++------------- src/live_effects/lpe-mirror_symmetry.h | 4 +- 2 files changed, 75 insertions(+), 54 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index fa054a283..e4ae0bbdb 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -56,18 +56,21 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), + original("hidden", "hidden", "original", &wr, this,"") { show_orig_path = true; registerParameter(&mode); - registerParameter( &split_gap); - registerParameter( &discard_orig_path); - registerParameter( &fuse_paths); - registerParameter( &oposite_fuse); - registerParameter( &split_elements); - registerParameter( &start_point); - registerParameter( &end_point); - registerParameter( ¢er_point); + registerParameter(&split_gap); + registerParameter(&discard_orig_path); + registerParameter(&fuse_paths); + registerParameter(&oposite_fuse); + registerParameter(&split_elements); + registerParameter(&start_point); + registerParameter(&end_point); + registerParameter(¢er_point); + registerParameter(&original); + original.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); @@ -155,45 +158,43 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) center_point.param_setValue(previous_center); } if (split_elements) { - ms_container = dynamic_cast(splpeitem->parent); + container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); Inkscape::XML::Node *root_origin = doc->getReprRoot(); if (root_origin != root) { return; } - - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - Geom::Point gap(split_gap,0); - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Point dir = unit_vector(point_b - point_a); - Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; - line_separation *= Geom::Translate(offset); - Geom::Scale sca(1.0, -1.0); - const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); - const char * mirror_b = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); - m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - m = m * lpeitem->transform; - if (std::strcmp(splpeitem->getId(), mirror_a) != 0) { - createMirror(splpeitem, m, mirror_a); - } - if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { + const char * mirror_a = g_strdup(Glib::ustring(original.param_getSVGValue()).c_str()); + const char * mirror_b = g_strdup(Glib::ustring("mirror-").append(this->getRepr()->attribute("id")).c_str()); + if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { + syncMirror(splpeitem, mirror_a); + } else { + Geom::Point point_a(line_separation.initialPoint()); + Geom::Point point_b(line_separation.finalPoint()); + Geom::Point gap(split_gap,0); + Geom::Translate m1(point_a[0], point_a[1]); + double hyp = Geom::distance(point_a, point_b); + double cos = 0; + double sin = 0; + if (hyp > 0) { + cos = (point_b[0] - point_a[0]) / hyp; + sin = (point_b[1] - point_a[1]) / hyp; + } + Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); + Geom::Point dir = unit_vector(point_b - point_a); + Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; + line_separation *= Geom::Translate(offset); + Geom::Scale sca(1.0, -1.0); + m = m1.inverse() * m2; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + m = m * splpeitem->transform; + //if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { createMirror(splpeitem, m, mirror_b); } elements.clear(); - elements.push_back(mirror_a); elements.push_back(mirror_b); } else { elements.clear(); @@ -251,7 +252,7 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c if (c) { dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); c->reset(); - g_free(c); + g_free(c); } else { dest->getRepr()->setAttribute(att,NULL); } @@ -278,24 +279,40 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const } else { phantom = origin->getRepr()->duplicate(xml_doc); } - phantom->setAttribute("id", id); if (!elemref) { - elemref = ms_container->appendChildRepr(phantom); + elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - if (elemref->parent != ms_container) { + if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", id); - ms_container->appendChildRepr(copy); + container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); } } } +void +LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) +{ + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = SVGElemRef->getObject()) { + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required + } + } +} + + //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) @@ -345,15 +362,15 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { + //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { elemref->deleteObject(); - } + //} break; case LPE_VISIBILITY: css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { + if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { css->setAttribute("display", "none"); } else { css->setAttribute("display", NULL); @@ -402,11 +419,13 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point.param_setValue(point_c); previous_center = center_point; - SPLPEItem * splpeitem = const_cast(lpeitem); - Glib::ustring mirror_a = Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")); - if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet - splpeitem->getRepr()->setAttribute("id", mirror_a.c_str()); - } + original.param_setValue(lpeitem->getId()); + original.write_to_SVG(); +// SPLPEItem * splpeitem = const_cast(lpeitem); +// Glib::ustring mirror_a = Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")); +// if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet +// splpeitem->getRepr()->setAttribute("id", mirror_a.c_str()); +// } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 03396fdf3..3a78db169 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -49,6 +49,7 @@ public: void processObjects(LpeAction lpe_action); void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); + void syncMirror(SPLPEItem *origin, const char * id); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); protected: @@ -64,10 +65,11 @@ private: PointParam start_point; PointParam end_point; PointParam center_point; + TextParam original; Geom::Line line_separation; Geom::Point previous_center; std::vector elements; - SPObject * ms_container; + SPObject * container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; -- cgit v1.2.3 From 8ce90cc9aeecfd5133926156f23ac3cbe318c49d Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 16 Dec 2016 23:44:26 +0100 Subject: working with mirrors (bzr r15295.1.24) --- src/live_effects/lpe-mirror_symmetry.cpp | 134 +++++++++++++++++++++++-------- src/live_effects/lpe-mirror_symmetry.h | 9 ++- 2 files changed, 104 insertions(+), 39 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e4ae0bbdb..f34421df2 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -15,6 +15,8 @@ */ #include +#include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include "live_effects/lpe-mirror_symmetry.h" #include "display/curve.h" #include "svg/path-string.h" @@ -53,11 +55,10 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), - original("hidden", "hidden", "original", &wr, this,"") + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { show_orig_path = true; registerParameter(&mode); @@ -69,8 +70,6 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter(&start_point); registerParameter(&end_point); registerParameter(¢er_point); - registerParameter(&original); - original.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); @@ -157,7 +156,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (!are_near(previous_center, center_point,0.01)) { center_point.param_setValue(previous_center); } - if (split_elements) { + if (split_elements && allow_split()) { container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); @@ -165,11 +164,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (root_origin != root) { return; } - const char * mirror_a = g_strdup(Glib::ustring(original.param_getSVGValue()).c_str()); - const char * mirror_b = g_strdup(Glib::ustring("mirror-").append(this->getRepr()->attribute("id")).c_str()); - if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { - syncMirror(splpeitem, mirror_a); - } else { + const char * mirror = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); +// if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { +// syncMirror(splpeitem, mirror_a); +// } else { Geom::Point point_a(line_separation.initialPoint()); Geom::Point point_b(line_separation.finalPoint()); Geom::Point gap(split_gap,0); @@ -191,14 +189,15 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) m = m * m2.inverse(); m = m * m1; m = m * splpeitem->transform; - //if (std::strcmp(splpeitem->getId(), mirror_b) != 0) { - createMirror(splpeitem, m, mirror_b); - } - elements.clear(); - elements.push_back(mirror_b); + createMirror(splpeitem, m); + //} } else { - elements.clear(); + if (!allow_split()) { + std::cout << "Only one operation of split allowed. Group results to nested effects.\n"; + split_elements.param_setValue(false); + } processObjects(LPE_ERASE); + elements.clear(); } } @@ -265,9 +264,19 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + const char * id; + Glib::ustring idbase = Glib::ustring(sp_lpe_item->getId()); + size_t pos = idbase.find("-mirror"); + if (pos <= idbase.size()) { + id = g_strdup(idbase.substr(pos).c_str()); + } else { + id = g_strdup(idbase.append("-mirror").c_str()); + elements.clear(); + elements.push_back(id); + } Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -284,7 +293,7 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -296,22 +305,77 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const } } -void -LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) -{ - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref= NULL; - Inkscape::XML::Node *phantom = NULL; - if (elemref = SVGElemRef->getObject()) { - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required +//void +//LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) +//{ +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); +// Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); +// Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); +// SVGElemRef->attach(SVGElem_uri); +// SPObject *elemref= NULL; +// Inkscape::XML::Node *phantom = NULL; +// if (elemref = SVGElemRef->getObject()) { +// cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required +// } +// } +//} + +bool +LPEMirrorSymmetry::allow_split(){ + if (sp_lpe_item->path_effect_list->empty()) { + return false; + } + size_t count = 0; + for (PathEffectList::const_iterator it = sp_lpe_item->path_effect_list->begin(); it != sp_lpe_item->path_effect_list->end(); ++it) + { + LivePathEffectObject *lpeobj = (*it)->lpeobject; + if (lpeobj) { + Inkscape::LivePathEffect::LPEMirrorSymmetry * ms = dynamic_cast(lpeobj->get_lpe()); + if (ms && ms->split_elements) { + count++; + } } } + return count <= 1; } +//Gtk::Widget * +//LPEMirrorSymmetry::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); +// std::vector::iterator it = param_vector.begin(); +// while (it != param_vector.end()) { +// if ((*it)->widget_is_visible) { +// Parameter *param = *it; +// Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); +// if (widg) { +// if (param->param_key == "split_elements") { +// Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast(widg)); +// if (!allow_split()) { +// widg_registered->set_sensitive("false"); +// } +// widg = dynamic_cast(widg_registered); +// } +// Glib::ustring *tip = param->param_getTooltip(); +// 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(vbox); +//} //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void @@ -419,12 +483,12 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point.param_setValue(point_c); previous_center = center_point; - original.param_setValue(lpeitem->getId()); - original.write_to_SVG(); // SPLPEItem * splpeitem = const_cast(lpeitem); -// Glib::ustring mirror_a = Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")); // if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet -// splpeitem->getRepr()->setAttribute("id", mirror_a.c_str()); +// const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); +// splpeitem->setAttribute("id", mirror_a); +// first_lpe.param_setValue(this->getRepr()->attribute("id")); +// first_lpe.write_to_SVG(); // } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 3a78db169..12ceebaf8 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -17,8 +17,8 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/text.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" @@ -46,11 +46,13 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); +// virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); + void createMirror(SPLPEItem *origin, Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); - void syncMirror(SPLPEItem *origin, const char * id); +// void syncMirror(SPLPEItem *origin, const char * id); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); + bool allow_split(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -65,7 +67,6 @@ private: PointParam start_point; PointParam end_point; PointParam center_point; - TextParam original; Geom::Line line_separation; Geom::Point previous_center; std::vector elements; -- cgit v1.2.3 From 5927b3bf5d9d8dcc9f519b4b9060669bd2599a28 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 16 Dec 2016 23:49:53 +0100 Subject: Rollback 15315 (bzr r15295.1.25) --- src/live_effects/lpe-angle_bisector.cpp | 8 +- src/live_effects/lpe-attach-path.cpp | 5 +- src/live_effects/lpe-bendpath.cpp | 3 +- src/live_effects/lpe-bounding-box.cpp | 6 +- src/live_effects/lpe-bspline.h | 2 +- src/live_effects/lpe-circle_3pts.cpp | 2 - src/live_effects/lpe-circle_with_radius.cpp | 2 - src/live_effects/lpe-clone-original.cpp | 5 +- src/live_effects/lpe-constructgrid.cpp | 4 +- src/live_effects/lpe-copy_rotate.cpp | 156 ++++++++----- src/live_effects/lpe-copy_rotate.h | 14 +- src/live_effects/lpe-curvestitch.cpp | 5 +- src/live_effects/lpe-dynastroke.cpp | 2 - src/live_effects/lpe-ellipse_5pts.cpp | 5 +- src/live_effects/lpe-envelope.cpp | 2 - src/live_effects/lpe-extrude.cpp | 4 +- src/live_effects/lpe-fill-between-many.cpp | 2 +- src/live_effects/lpe-fill-between-strokes.cpp | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-gears.cpp | 5 +- src/live_effects/lpe-interpolate.cpp | 6 +- src/live_effects/lpe-interpolate_points.cpp | 3 +- src/live_effects/lpe-jointype.cpp | 2 - src/live_effects/lpe-knot.cpp | 3 - src/live_effects/lpe-lattice.cpp | 3 +- src/live_effects/lpe-lattice2.cpp | 3 - src/live_effects/lpe-lattice2.h | 2 +- src/live_effects/lpe-line_segment.cpp | 2 - src/live_effects/lpe-mirror_symmetry.cpp | 314 +++++++++++++------------- src/live_effects/lpe-mirror_symmetry.h | 24 +- src/live_effects/lpe-offset.cpp | 5 +- src/live_effects/lpe-parallel.cpp | 5 +- src/live_effects/lpe-path_length.cpp | 4 +- src/live_effects/lpe-patternalongpath.cpp | 2 - src/live_effects/lpe-perp_bisector.cpp | 6 +- src/live_effects/lpe-perspective-envelope.cpp | 3 - src/live_effects/lpe-perspective_path.cpp | 5 +- src/live_effects/lpe-powerstroke.cpp | 3 - src/live_effects/lpe-recursiveskeleton.cpp | 5 +- src/live_effects/lpe-rough-hatches.cpp | 3 +- src/live_effects/lpe-roughen.cpp | 3 - src/live_effects/lpe-roughen.h | 1 + src/live_effects/lpe-ruler.cpp | 3 +- src/live_effects/lpe-show_handles.cpp | 2 - src/live_effects/lpe-show_handles.h | 1 + src/live_effects/lpe-simplify.cpp | 2 - src/live_effects/lpe-simplify.h | 1 + src/live_effects/lpe-skeleton.cpp | 3 +- src/live_effects/lpe-sketch.cpp | 5 +- src/live_effects/lpe-tangent_to_curve.cpp | 4 +- src/live_effects/lpe-taperstroke.cpp | 2 - src/live_effects/lpe-test-doEffect-stack.cpp | 5 +- src/live_effects/lpe-text_label.cpp | 5 +- src/live_effects/lpe-transform_2pts.cpp | 1 - src/live_effects/lpe-vonkoch.cpp | 2 +- src/live_effects/parameter/fontbutton.cpp | 2 +- src/live_effects/parameter/fontbutton.h | 1 + 57 files changed, 355 insertions(+), 330 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 56d33eb4b..9bfbf4ca8 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -8,13 +8,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-angle_bisector.h" -#include "2geom/sbasis-to-bezier.h" + +#include <2geom/sbasis-to-bezier.h> + #include "sp-lpe-item.h" #include "knot-holder-entity.h" #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index 302165719..d2b44dd4e 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -4,14 +4,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include + #include "live_effects/lpe-attach-path.h" + #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" #include "2geom/path-sink.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index b1e133292..c24d38d7b 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -7,10 +7,9 @@ #include "live_effects/lpe-bendpath.h" #include "sp-item-group.h" + #include "knot-holder-entity.h" #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 11fb34e04..2de768c3a 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -3,14 +3,14 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include + #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 90cf82c19..7823f00f0 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,8 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/effect.h" + #include namespace Inkscape { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index 3410b13f2..18252f6a0 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -17,8 +17,6 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index fcefc4ec6..6e03cb1ce 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -17,8 +17,6 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 10418a02d..7541c0be2 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -4,10 +4,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-clone-original.h" + #include "display/curve.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 8d24f9f47..4af8891e8 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -10,10 +10,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/lpe-constructgrid.h" -// TODO due to internal breakage in glibmm headers, this must be last: #include +#include "live_effects/lpe-constructgrid.h" + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 5b94e9083..1133e083a 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -11,17 +11,36 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" + +#include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { namespace LivePathEffect { +namespace CR { + +class KnotHolderEntityStartingAngle : public LPEKnotHolderEntity { +public: + KnotHolderEntityStartingAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + +class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity { +public: + KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + +} // namespace CR + bool pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) { @@ -40,7 +59,6 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this), - starting_point("hidden", "hidden", "starting_point", &wr, this), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), @@ -56,7 +74,6 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&copies_to_360); registerParameter(&fuse_paths); registerParameter(&starting_angle); - registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&origin); @@ -70,41 +87,6 @@ LPECopyRotate::~LPECopyRotate() } -Gtk::Widget * LPECopyRotate::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "starting_point") { - 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(vbox); -} - - void LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) { @@ -122,6 +104,11 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { + if(fuse_paths) { + Geom::Coord angle = Geom::deg_from_rad(atan(-postmul[1]/postmul[0])); + angle += starting_angle; + starting_angle.param_set_value(angle); + } // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { @@ -159,25 +146,11 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) dir = unit_vector(B - A); // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) - bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); - if (!near) { - starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); - if (GDK_SHIFT_MASK) { - dist_angle_handle = L2(B - A); - } else { - dist_angle_handle = L2(starting_point - origin); - } - } start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; - if (near) { - starting_point.param_setValue(start_pos); - } - previous_start_point = (Geom::Point)starting_point; if ( fuse_paths || copies_to_360 ) { rot_pos = origin; } - SPLPEItem * item = const_cast(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -445,6 +418,85 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } +void +LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + { + KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); + e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the starting angle")); + knotholder->add(e); + } + { + KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this); + e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the rotation angle")); + knotholder->add(e); + } +}; + +namespace CR { + +using namespace Geom; + +void +KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) +{ + LPECopyRotate* lpe = dynamic_cast(_effect); + + Geom::Point const s = snap_knot_position(p, state); + + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + lpe->starting_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin))); + if (state & GDK_SHIFT_MASK) { + lpe->dist_angle_handle = L2(lpe->B - lpe->A); + } else { + lpe->dist_angle_handle = L2(p - lpe->origin); + } + + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +void +KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) +{ + LPECopyRotate* lpe = dynamic_cast(_effect); + + Geom::Point const s = snap_knot_position(p, state); + + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + lpe->rotation_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle); + if (state & GDK_SHIFT_MASK) { + lpe->dist_angle_handle = L2(lpe->B - lpe->A); + } else { + lpe->dist_angle_handle = L2(p - lpe->origin); + } + + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +Geom::Point +KnotHolderEntityStartingAngle::knot_get() const +{ + LPECopyRotate const *lpe = dynamic_cast(_effect); + return lpe->start_pos; +} + +Geom::Point +KnotHolderEntityRotationAngle::knot_get() const +{ + LPECopyRotate const *lpe = dynamic_cast(_effect); + return lpe->rot_pos; +} + +} // namespace CR + +/* ######################## */ + } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 8f9fc12ac..87af867df 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -21,6 +21,12 @@ namespace Inkscape { namespace LivePathEffect { +namespace CR { +// we need a separate namespace to avoid clashes with LPEPerpBisector +class KnotHolderEntityStartingAngle; +class KnotHolderEntityRotationAngle; +} + class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); @@ -32,13 +38,16 @@ public: virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); - virtual Gtk::Widget * newWidget(); + /* the knotholder entity classes must be declared friends */ + friend class CR::KnotHolderEntityStartingAngle; + friend class CR::KnotHolderEntityRotationAngle; + void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: PointParam origin; - PointParam starting_point; ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; @@ -49,7 +58,6 @@ private: Geom::Point dir; Geom::Point start_pos; Geom::Point rot_pos; - Geom::Point previous_start_point; double dist_angle_handle; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 38cbeaac0..3beedaf57 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -13,6 +13,8 @@ */ #include "ui/widget/scalar.h" +#include + #include "live_effects/lpe-curvestitch.h" #include "sp-path.h" @@ -20,9 +22,6 @@ #include "xml/repr.h" #include <2geom/bezier-to-sbasis.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 50bbe6451..7e22f6e51 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -16,8 +16,6 @@ #include <2geom/bezier-to-sbasis.h> #include <2geom/sbasis-math.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 28e7058d7..0371fc313 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -12,14 +12,15 @@ */ #include "live_effects/lpe-ellipse_5pts.h" + +// You might need to include other 2geom files. You can add them here: +#include #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> #include "inkscape.h" #include "desktop.h" #include "message-stack.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 61a696435..c3b0a7c10 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -6,8 +6,6 @@ #include "live_effects/lpe-envelope.h" #include "display/curve.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include using std::vector; diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index daa30d45a..d22007f76 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -12,10 +12,10 @@ */ #include "live_effects/lpe-extrude.h" -#include "sp-item.h" -// TODO due to internal breakage in glibmm headers, this must be last: + #include +#include "sp-item.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 1e2eadfdb..2087925fa 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -11,7 +11,7 @@ #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" -// TODO due to internal breakage in glibmm headers, this must be last: + #include namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 0dbebdf26..b1e328d18 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -3,13 +3,14 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include + #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1e2df7dc8..24ee2ccc3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -25,8 +25,8 @@ // for programmatically updating knots #include "ui/tools-switch.h" + // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 17579c64e..1d5398aa5 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -7,10 +7,11 @@ */ #include "live_effects/lpe-gears.h" -#include <2geom/bezier-to-sbasis.h> -// TODO due to internal breakage in glibmm headers, this must be last: + #include +#include <2geom/bezier-to-sbasis.h> + using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index e95dc5f38..43da4d105 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -9,15 +9,15 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include + #include "live_effects/lpe-interpolate.h" #include <2geom/sbasis-to-bezier.h> #include "sp-path.h" #include "display/curve.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index 0a0bcea14..ab0576174 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -12,9 +12,8 @@ */ #include "live_effects/lpe-interpolate_points.h" + #include "live_effects/lpe-powerstroke-interpolators.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index dacb87dd9..3bfbd6288 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -19,8 +19,6 @@ #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index c35da0601..474523aa3 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -33,9 +33,6 @@ #include "document.h" #include "document-undo.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index acffed000..091b6ddca 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -20,8 +20,7 @@ #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include + using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index e827491c0..9e9fc153a 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -16,15 +16,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/lpe-lattice2.h" #include "display/curve.h" #include "helper/geom.h" #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> - // TODO due to internal breakage in glibmm headers, this must be last: -#include using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 59a0350d3..4a025d182 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,7 +18,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/point.h" diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index cc024fb92..4c9edabd4 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -13,8 +13,6 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f34421df2..11620b23f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -13,10 +13,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include -#include "live_effects/lpeobject.h" -#include "live_effects/lpeobject-reference.h" #include "live_effects/lpe-mirror_symmetry.h" #include "display/curve.h" #include "svg/path-string.h" @@ -31,7 +27,6 @@ #include "knotholder.h" #include "style.h" #include "xml/sp-css-attr.h" - // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -48,6 +43,17 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); +namespace MS { + +class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { +public: + KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + +} // namespace MS + LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), @@ -55,26 +61,27 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), + id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") { show_orig_path = true; registerParameter(&mode); - registerParameter(&split_gap); - registerParameter(&discard_orig_path); - registerParameter(&fuse_paths); - registerParameter(&oposite_fuse); - registerParameter(&split_elements); - registerParameter(&start_point); - registerParameter(&end_point); - registerParameter(¢er_point); + registerParameter( &split_gap); + registerParameter( &discard_orig_path); + registerParameter( &fuse_paths); + registerParameter( &oposite_fuse); + registerParameter( &split_elements); + registerParameter( &start_point); + registerParameter( &end_point); + registerParameter( &id_origin); + id_origin.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; - previous_center = Geom::Point(0,0); + actual = true; } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -87,10 +94,11 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty()) { + if ( sel && !sel->isEmpty() && actual) { SPItem *item = sel->singleItem(); if (item) { if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { + actual = false; return; } } @@ -109,14 +117,11 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } - if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { - start_point.param_setValue(point_a); - end_point.param_setValue(point_b); - } line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); + center_point = Geom::middle_point(point_a, point_b); } else if ( mode == MT_FREE) { if(!are_near(previous_center,center_point, 0.01)) { Geom::Point trans = center_point - previous_center; @@ -124,6 +129,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans); line_separation.setPoints(start_point, end_point); } else { + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ @@ -136,6 +142,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else { //horizontal page @@ -148,56 +155,53 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } - - previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - if (!are_near(previous_center, center_point,0.01)) { - center_point.param_setValue(previous_center); - } - if (split_elements && allow_split()) { - container = dynamic_cast(splpeitem->parent); + previous_center = center_point; + if (split_elements) { + ms_container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); Inkscape::XML::Node *root_origin = doc->getReprRoot(); if (root_origin != root) { return; } - const char * mirror = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); -// if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { -// syncMirror(splpeitem, mirror_a); -// } else { - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - Geom::Point gap(split_gap,0); - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Point dir = unit_vector(point_b - point_a); - Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; - line_separation *= Geom::Translate(offset); - Geom::Scale sca(1.0, -1.0); - m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - m = m * splpeitem->transform; - createMirror(splpeitem, m); - //} - } else { - if (!allow_split()) { - std::cout << "Only one operation of split allowed. Group results to nested effects.\n"; - split_elements.param_setValue(false); + Geom::Point point_a(line_separation.initialPoint()); + Geom::Point point_b(line_separation.finalPoint()); + Geom::Point gap(split_gap,0); + Geom::Translate m1(point_a[0], point_a[1]); + double hyp = Geom::distance(point_a, point_b); + double cos = 0; + double sin = 0; + if (hyp > 0) { + cos = (point_b[0] - point_a[0]) / hyp; + sin = (point_b[1] - point_a[1]) / hyp; } - processObjects(LPE_ERASE); + Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); + Geom::Point dir = unit_vector(point_b - point_a); + Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; + line_separation *= Geom::Translate(offset); + Geom::Scale sca(1.0, -1.0); + const char * id_original = id_origin.param_getSVGValue(); + const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); + m = m1.inverse() * m2; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + m = m * lpeitem->transform; + if (std::strcmp(splpeitem->getId(), id) == 0) { + createMirror(splpeitem, m, id_original); + } else { + createMirror(splpeitem, m, id); + } + elements.clear(); + elements.push_back(id); + elements.push_back(id_original); + } else { elements.clear(); + processObjects(LPE_ERASE); } } @@ -251,7 +255,7 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c if (c) { dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); c->reset(); - g_free(c); + g_free(c); } else { dest->getRepr()->setAttribute(att,NULL); } @@ -264,19 +268,9 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - const char * id; - Glib::ustring idbase = Glib::ustring(sp_lpe_item->getId()); - size_t pos = idbase.find("-mirror"); - if (pos <= idbase.size()) { - id = g_strdup(idbase.substr(pos).c_str()); - } else { - id = g_strdup(idbase.append("-mirror").c_str()); - elements.clear(); - elements.push_back(id); - } Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -288,95 +282,24 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) } else { phantom = origin->getRepr()->duplicate(xml_doc); } + phantom->setAttribute("id", id); if (!elemref) { - elemref = container->appendChildRepr(phantom); + elemref = ms_container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - if (elemref->parent != container) { + if (elemref->parent != ms_container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", id); - container->appendChildRepr(copy); + ms_container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); } } } -//void -//LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) -//{ -// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { -// Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); -// Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); -// Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); -// SVGElemRef->attach(SVGElem_uri); -// SPObject *elemref= NULL; -// Inkscape::XML::Node *phantom = NULL; -// if (elemref = SVGElemRef->getObject()) { -// cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required -// } -// } -//} - -bool -LPEMirrorSymmetry::allow_split(){ - if (sp_lpe_item->path_effect_list->empty()) { - return false; - } - size_t count = 0; - for (PathEffectList::const_iterator it = sp_lpe_item->path_effect_list->begin(); it != sp_lpe_item->path_effect_list->end(); ++it) - { - LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (lpeobj) { - Inkscape::LivePathEffect::LPEMirrorSymmetry * ms = dynamic_cast(lpeobj->get_lpe()); - if (ms && ms->split_elements) { - count++; - } - } - } - return count <= 1; -} - -//Gtk::Widget * -//LPEMirrorSymmetry::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); -// std::vector::iterator it = param_vector.begin(); -// while (it != param_vector.end()) { -// if ((*it)->widget_is_visible) { -// Parameter *param = *it; -// Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); -// if (widg) { -// if (param->param_key == "split_elements") { -// Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast(widg)); -// if (!allow_split()) { -// widg_registered->set_sensitive("false"); -// } -// widg = dynamic_cast(widg_registered); -// } -// Glib::ustring *tip = param->param_getTooltip(); -// 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(vbox); -//} - //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) @@ -426,15 +349,15 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { elemref->deleteObject(); - //} + } break; case LPE_VISIBILITY: css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { css->setAttribute("display", "none"); } else { css->setAttribute("display", NULL); @@ -459,6 +382,8 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { if( !split_elements) { + center_point *= postmul; + previous_center = center_point; // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; @@ -481,15 +406,10 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b); end_point.param_update_default(point_b); - center_point.param_setValue(point_c); + center_point = point_c; previous_center = center_point; -// SPLPEItem * splpeitem = const_cast(lpeitem); -// if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet -// const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); -// splpeitem->setAttribute("id", mirror_a); -// first_lpe.param_setValue(this->getRepr()->attribute("id")); -// first_lpe.write_to_SVG(); -// } + id_origin.param_setValue(Glib::ustring(lpeitem->getId())); + id_origin.write_to_SVG(); } @@ -640,6 +560,41 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) return path_out; } + +Gtk::Widget *LPEMirrorSymmetry::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "id_origin") { + 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(vbox); +} + void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { @@ -655,6 +610,43 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector hp_vec.push_back(helper); } +void +LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; + SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; + guint32 knot_color = 0x0000ff00; + { + KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); + c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the center"), knot_shape, knot_mode, knot_color ); + knotholder->add(c); + } +}; + +namespace MS { + +using namespace Geom; + +void +KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) +{ + LPEMirrorSymmetry* lpe = dynamic_cast(_effect); + Geom::Point const s = snap_knot_position(p, state); + lpe->center_point = s; + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +Geom::Point +KnotHolderEntityCenterMirrorSymmetry::knot_get() const +{ + LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); + return lpe->center_point; +} + +} // namespace CR + } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 12ceebaf8..7b090ed82 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -15,10 +15,10 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" -#include "live_effects/parameter/parameter.h" #include "live_effects/parameter/text.h" +#include "live_effects/parameter/parameter.h" #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" @@ -27,6 +27,11 @@ namespace Inkscape { namespace LivePathEffect { +namespace MS { +// we need a separate namespace to avoid clashes with LPEPerpBisector +class KnotHolderEntityCenterMirrorSymmetry; +} + enum ModeType { MT_V, MT_H, @@ -46,13 +51,14 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); -// virtual Gtk::Widget * newWidget(); + virtual Gtk::Widget *newWidget(); void processObjects(LpeAction lpe_action); - void createMirror(SPLPEItem *origin, Geom::Affine transform); + /* the knotholder entity classes must be declared friends */ + friend class MS::KnotHolderEntityCenterMirrorSymmetry; + void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); -// void syncMirror(SPLPEItem *origin, const char * id); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); - bool allow_split(); + void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -66,11 +72,13 @@ private: BoolParam split_elements; PointParam start_point; PointParam end_point; - PointParam center_point; + TextParam id_origin; Geom::Line line_separation; Geom::Point previous_center; + Geom::Point center_point; + bool actual; std::vector elements; - SPObject * container; + SPObject * ms_container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 057f404e0..a0fa46c3f 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -11,12 +11,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-offset.h" #include "sp-shape.h" #include "display/curve.h" + #include <2geom/elliptical-arc.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 276749c43..9cd8ecf46 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -11,15 +11,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-parallel.h" #include "sp-shape.h" #include "display/curve.h" #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index a06dbde98..6ec1e0ede 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -11,10 +11,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-path_length.h" #include "util/units.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 9cfeffee7..15c2817c4 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -12,8 +12,6 @@ #include "knotholder.h" #include -// TODO due to internal breakage in glibmm headers, this must be last: -#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index bce22250a..f69dae6a1 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -11,6 +11,9 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include + #include "live_effects/lpe-perp_bisector.h" #include "display/curve.h" #include "sp-path.h" @@ -18,9 +21,6 @@ #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { namespace PB { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index e834c0e86..6a6b59519 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -20,9 +20,6 @@ #include "display/curve.h" #include -// TODO due to internal breakage in glibmm headers, this must be last: -#include - using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 2c6d66cee..cb4e43d87 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -11,6 +11,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include +#include + #include "persp3d.h" //#include "transf_mat_3x4.h" #include "document-private.h" @@ -21,9 +23,6 @@ #include "desktop.h" #include -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index e9f3975c7..329a00756 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -25,9 +25,6 @@ #include <2geom/circle.h> #include "helper/geom.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index aa0db920b..ed0c915ce 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -10,13 +10,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-recursiveskeleton.h" #include <2geom/bezier-to-sbasis.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 3cc8658ea..2fb65b349 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -13,6 +13,7 @@ */ #include "ui/widget/scalar.h" +#include #include "live_effects/lpe-rough-hatches.h" #include "sp-item.h" @@ -22,8 +23,6 @@ #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index c6edffd9b..3a486ff10 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -13,14 +13,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/lpe-roughen.h" #include "display/curve.h" #include #include "helper/geom.h" - // TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index bab06022f..dbdb91e62 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -12,6 +12,7 @@ #ifndef INKSCAPE_LPE_ROUGHEN_H #define INKSCAPE_LPE_ROUGHEN_H +#include #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/parameter.h" diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 60c2a3e1c..3a2d78b2c 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,8 +12,7 @@ */ #include "live_effects/lpe-ruler.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 7c298d0e7..170b6dccb 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -6,7 +6,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/lpe-show_handles.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> @@ -14,7 +13,6 @@ #include "desktop-style.h" #include "style.h" #include "svg/svg.h" - // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index c46abd2c2..3eda04649 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -8,6 +8,7 @@ * Copyright (C) Jabier Arraiza Cenoz 2014 * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "helper/geom-nodetype.h" #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 8bdb19b4f..ec21e10d2 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -2,7 +2,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/lpe-simplify.h" #include "display/curve.h" #include "helper/geom.h" @@ -10,7 +9,6 @@ #include "svg/svg.h" #include "ui/tools/node-tool.h" #include "ui/icon-names.h" - // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 6c407f572..8135561af 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -6,6 +6,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/effect.h" #include "live_effects/parameter/togglebutton.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index adc4a3493..7d34db699 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -20,7 +20,8 @@ #include "live_effects/lpe-skeleton.h" -// TODO due to internal breakage in glibmm headers, this must be last: +// You might need to include other 2geom files. You can add them here: + #include namespace Inkscape { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index e01516f2e..95e2f6f0d 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -13,14 +13,13 @@ #include "live_effects/lpe-sketch.h" +#include + // You might need to include other 2geom files. You can add them here: #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/path-intersection.h> -// TODO due to internal breakage in glibmm headers, this must be last: -#include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 76d4ea71b..b308ef8d7 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -13,13 +13,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include + #include "live_effects/lpe-tangent_to_curve.h" #include "sp-path.h" #include "display/curve.h" #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 4ffc41691..f6f6b33dc 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -26,8 +26,6 @@ #include "svg/svg.h" #include "knotholder.h" -// TODO due to internal breakage in glibmm headers, this must be last: -#include template inline bool withinRange(T value, T low, T high) { diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 324893706..c7ecf6481 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -4,11 +4,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/lpe-test-doEffect-stack.h" - -// TODO due to internal breakage in glibmm headers, this must be last: #include +#include "live_effects/lpe-test-doEffect-stack.h" + using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp index 709d05e18..602a6897c 100644 --- a/src/live_effects/lpe-text_label.cpp +++ b/src/live_effects/lpe-text_label.cpp @@ -11,11 +11,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/lpe-text_label.h" - -// TODO due to internal breakage in glibmm headers, this must be last: #include +#include "live_effects/lpe-text_label.h" + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index e1f36eee7..78db622f2 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -20,7 +20,6 @@ // TODO due to internal breakage in glibmm headers, this must be last: #include - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 47e2a1cec..2486f3366 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -5,7 +5,7 @@ */ #include "live_effects/lpe-vonkoch.h" -// TODO due to internal breakage in glibmm headers, this must be last: + #include //using std::vector; diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 64c203093..ff8ab76a0 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -4,7 +4,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "ui/widget/registered-widget.h" #include "live_effects/parameter/fontbutton.h" #include "live_effects/effect.h" diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index df47251a2..387ad130b 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -8,6 +8,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include +#include #include "live_effects/parameter/parameter.h" namespace Inkscape { -- cgit v1.2.3 From 57175b32ef6539d7249a0d28d302c174ba453275 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 16 Dec 2016 23:53:43 +0100 Subject: remove rollback to 15315 (bzr r15295.1.26) --- src/live_effects/lpe-angle_bisector.cpp | 8 +- src/live_effects/lpe-attach-path.cpp | 5 +- src/live_effects/lpe-bendpath.cpp | 3 +- src/live_effects/lpe-bounding-box.cpp | 6 +- src/live_effects/lpe-bspline.h | 2 +- src/live_effects/lpe-circle_3pts.cpp | 2 + src/live_effects/lpe-circle_with_radius.cpp | 2 + src/live_effects/lpe-clone-original.cpp | 5 +- src/live_effects/lpe-constructgrid.cpp | 4 +- src/live_effects/lpe-copy_rotate.cpp | 156 +++++-------- src/live_effects/lpe-copy_rotate.h | 14 +- src/live_effects/lpe-curvestitch.cpp | 5 +- src/live_effects/lpe-dynastroke.cpp | 2 + src/live_effects/lpe-ellipse_5pts.cpp | 5 +- src/live_effects/lpe-envelope.cpp | 2 + src/live_effects/lpe-extrude.cpp | 4 +- src/live_effects/lpe-fill-between-many.cpp | 2 +- src/live_effects/lpe-fill-between-strokes.cpp | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-gears.cpp | 5 +- src/live_effects/lpe-interpolate.cpp | 6 +- src/live_effects/lpe-interpolate_points.cpp | 3 +- src/live_effects/lpe-jointype.cpp | 2 + src/live_effects/lpe-knot.cpp | 3 + src/live_effects/lpe-lattice.cpp | 3 +- src/live_effects/lpe-lattice2.cpp | 3 + src/live_effects/lpe-lattice2.h | 2 +- src/live_effects/lpe-line_segment.cpp | 2 + src/live_effects/lpe-mirror_symmetry.cpp | 314 +++++++++++++------------- src/live_effects/lpe-mirror_symmetry.h | 24 +- src/live_effects/lpe-offset.cpp | 5 +- src/live_effects/lpe-parallel.cpp | 5 +- src/live_effects/lpe-path_length.cpp | 4 +- src/live_effects/lpe-patternalongpath.cpp | 2 + src/live_effects/lpe-perp_bisector.cpp | 6 +- src/live_effects/lpe-perspective-envelope.cpp | 3 + src/live_effects/lpe-perspective_path.cpp | 5 +- src/live_effects/lpe-powerstroke.cpp | 3 + src/live_effects/lpe-recursiveskeleton.cpp | 5 +- src/live_effects/lpe-rough-hatches.cpp | 3 +- src/live_effects/lpe-roughen.cpp | 3 + src/live_effects/lpe-roughen.h | 1 - src/live_effects/lpe-ruler.cpp | 3 +- src/live_effects/lpe-show_handles.cpp | 2 + src/live_effects/lpe-show_handles.h | 1 - src/live_effects/lpe-simplify.cpp | 2 + src/live_effects/lpe-simplify.h | 1 - src/live_effects/lpe-skeleton.cpp | 3 +- src/live_effects/lpe-sketch.cpp | 5 +- src/live_effects/lpe-tangent_to_curve.cpp | 4 +- src/live_effects/lpe-taperstroke.cpp | 2 + src/live_effects/lpe-test-doEffect-stack.cpp | 5 +- src/live_effects/lpe-text_label.cpp | 5 +- src/live_effects/lpe-transform_2pts.cpp | 1 + src/live_effects/lpe-vonkoch.cpp | 2 +- src/live_effects/parameter/fontbutton.cpp | 2 +- src/live_effects/parameter/fontbutton.h | 1 - 57 files changed, 330 insertions(+), 355 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 9bfbf4ca8..56d33eb4b 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -8,15 +8,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-angle_bisector.h" - -#include <2geom/sbasis-to-bezier.h> - +#include "2geom/sbasis-to-bezier.h" #include "sp-lpe-item.h" #include "knot-holder-entity.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index d2b44dd4e..302165719 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -4,15 +4,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include - #include "live_effects/lpe-attach-path.h" - #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" #include "2geom/path-sink.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index c24d38d7b..b1e133292 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -7,9 +7,10 @@ #include "live_effects/lpe-bendpath.h" #include "sp-item-group.h" - #include "knot-holder-entity.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 2de768c3a..11fb34e04 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -3,14 +3,14 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-bounding-box.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 7823f00f0..90cf82c19 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,8 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/effect.h" +#include "live_effects/effect.h" #include namespace Inkscape { diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp index 18252f6a0..3410b13f2 100644 --- a/src/live_effects/lpe-circle_3pts.cpp +++ b/src/live_effects/lpe-circle_3pts.cpp @@ -17,6 +17,8 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp index 6e03cb1ce..fcefc4ec6 100644 --- a/src/live_effects/lpe-circle_with_radius.cpp +++ b/src/live_effects/lpe-circle_with_radius.cpp @@ -17,6 +17,8 @@ // You might need to include other 2geom files. You can add them here: #include <2geom/circle.h> #include <2geom/path-sink.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 7541c0be2..10418a02d 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -4,11 +4,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-clone-original.h" - #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 4af8891e8..8d24f9f47 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -10,9 +10,9 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-constructgrid.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 1133e083a..5b94e9083 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -11,36 +11,17 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" - -#include "knotholder.h" // TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { namespace LivePathEffect { -namespace CR { - -class KnotHolderEntityStartingAngle : public LPEKnotHolderEntity { -public: - KnotHolderEntityStartingAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity { -public: - KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace CR - bool pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) { @@ -59,6 +40,7 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this), + starting_point("hidden", "hidden", "starting_point", &wr, this), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), @@ -74,6 +56,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&copies_to_360); registerParameter(&fuse_paths); registerParameter(&starting_angle); + registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&origin); @@ -87,6 +70,41 @@ LPECopyRotate::~LPECopyRotate() } +Gtk::Widget * LPECopyRotate::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "starting_point") { + 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(vbox); +} + + void LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) { @@ -104,11 +122,6 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(fuse_paths) { - Geom::Coord angle = Geom::deg_from_rad(atan(-postmul[1]/postmul[0])); - angle += starting_angle; - starting_angle.param_set_value(angle); - } // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { @@ -146,11 +159,25 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) dir = unit_vector(B - A); // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) + bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); + if (!near) { + starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); + if (GDK_SHIFT_MASK) { + dist_angle_handle = L2(B - A); + } else { + dist_angle_handle = L2(starting_point - origin); + } + } start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; + if (near) { + starting_point.param_setValue(start_pos); + } + previous_start_point = (Geom::Point)starting_point; if ( fuse_paths || copies_to_360 ) { rot_pos = origin; } + SPLPEItem * item = const_cast(lpeitem); item->apply_to_clippath(item); item->apply_to_mask(item); @@ -418,85 +445,6 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } -void -LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - { - KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the starting angle")); - knotholder->add(e); - } - { - KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the rotation angle")); - knotholder->add(e); - } -}; - -namespace CR { - -using namespace Geom; - -void -KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - LPECopyRotate* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - lpe->starting_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin))); - if (state & GDK_SHIFT_MASK) { - lpe->dist_angle_handle = L2(lpe->B - lpe->A); - } else { - lpe->dist_angle_handle = L2(p - lpe->origin); - } - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -void -KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - LPECopyRotate* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - lpe->rotation_angle.param_set_value(deg_from_rad(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle); - if (state & GDK_SHIFT_MASK) { - lpe->dist_angle_handle = L2(lpe->B - lpe->A); - } else { - lpe->dist_angle_handle = L2(p - lpe->origin); - } - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityStartingAngle::knot_get() const -{ - LPECopyRotate const *lpe = dynamic_cast(_effect); - return lpe->start_pos; -} - -Geom::Point -KnotHolderEntityRotationAngle::knot_get() const -{ - LPECopyRotate const *lpe = dynamic_cast(_effect); - return lpe->rot_pos; -} - -} // namespace CR - -/* ######################## */ - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 87af867df..8f9fc12ac 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -21,12 +21,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace CR { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityStartingAngle; -class KnotHolderEntityRotationAngle; -} - class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); @@ -38,16 +32,13 @@ public: virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); - /* the knotholder entity classes must be declared friends */ - friend class CR::KnotHolderEntityStartingAngle; - friend class CR::KnotHolderEntityRotationAngle; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - + virtual Gtk::Widget * newWidget(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: PointParam origin; + PointParam starting_point; ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; @@ -58,6 +49,7 @@ private: Geom::Point dir; Geom::Point start_pos; Geom::Point rot_pos; + Geom::Point previous_start_point; double dist_angle_handle; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 3beedaf57..38cbeaac0 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -13,8 +13,6 @@ */ #include "ui/widget/scalar.h" -#include - #include "live_effects/lpe-curvestitch.h" #include "sp-path.h" @@ -22,6 +20,9 @@ #include "xml/repr.h" #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 7e22f6e51..50bbe6451 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -16,6 +16,8 @@ #include <2geom/bezier-to-sbasis.h> #include <2geom/sbasis-math.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-ellipse_5pts.cpp b/src/live_effects/lpe-ellipse_5pts.cpp index 0371fc313..28e7058d7 100644 --- a/src/live_effects/lpe-ellipse_5pts.cpp +++ b/src/live_effects/lpe-ellipse_5pts.cpp @@ -12,15 +12,14 @@ */ #include "live_effects/lpe-ellipse_5pts.h" - -// You might need to include other 2geom files. You can add them here: -#include #include <2geom/circle.h> #include <2geom/ellipse.h> #include <2geom/path-sink.h> #include "inkscape.h" #include "desktop.h" #include "message-stack.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index c3b0a7c10..61a696435 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -6,6 +6,8 @@ #include "live_effects/lpe-envelope.h" #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index d22007f76..daa30d45a 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -12,10 +12,10 @@ */ #include "live_effects/lpe-extrude.h" - +#include "sp-item.h" +// TODO due to internal breakage in glibmm headers, this must be last: #include -#include "sp-item.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 2087925fa..1e2eadfdb 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -11,7 +11,7 @@ #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" - +// TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index b1e328d18..0dbebdf26 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -3,14 +3,13 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-fill-between-strokes.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ee2ccc3..1e2df7dc8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -25,8 +25,8 @@ // for programmatically updating knots #include "ui/tools-switch.h" - // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 1d5398aa5..17579c64e 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -7,10 +7,9 @@ */ #include "live_effects/lpe-gears.h" - -#include - #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; using namespace Geom; diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index 43da4d105..e95dc5f38 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -9,15 +9,15 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-interpolate.h" #include <2geom/sbasis-to-bezier.h> #include "sp-path.h" #include "display/curve.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index ab0576174..0a0bcea14 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -12,8 +12,9 @@ */ #include "live_effects/lpe-interpolate_points.h" - #include "live_effects/lpe-powerstroke-interpolators.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index 3bfbd6288..dacb87dd9 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -19,6 +19,8 @@ #include <2geom/elliptical-arc.h> #include "lpe-jointype.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 474523aa3..c35da0601 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -33,6 +33,9 @@ #include "document.h" #include "document-undo.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 091b6ddca..acffed000 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -20,7 +20,8 @@ #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> - +// TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 9e9fc153a..e827491c0 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -16,12 +16,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-lattice2.h" #include "display/curve.h" #include "helper/geom.h" #include <2geom/sbasis-2d.h> #include <2geom/bezier-to-sbasis.h> + // TODO due to internal breakage in glibmm headers, this must be last: +#include using namespace Geom; diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 4a025d182..59a0350d3 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -18,7 +18,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/point.h" diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index 4c9edabd4..cc024fb92 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -13,6 +13,8 @@ #include "live_effects/lpe-line_segment.h" #include "ui/tools/lpe-tool.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 11620b23f..f34421df2 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -13,6 +13,10 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + +#include +#include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include "live_effects/lpe-mirror_symmetry.h" #include "display/curve.h" #include "svg/path-string.h" @@ -27,6 +31,7 @@ #include "knotholder.h" #include "style.h" #include "xml/sp-css-attr.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -43,17 +48,6 @@ static const Util::EnumData ModeTypeData[MT_END] = { static const Util::EnumDataConverter MTConverter(ModeTypeData, MT_END); -namespace MS { - -class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace MS - LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), @@ -61,27 +55,26 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints"), "split_elements", &wr, this, false), - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), - id_origin("id_origin", "id_origin", "id_origin", &wr, this,"") + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { show_orig_path = true; registerParameter(&mode); - registerParameter( &split_gap); - registerParameter( &discard_orig_path); - registerParameter( &fuse_paths); - registerParameter( &oposite_fuse); - registerParameter( &split_elements); - registerParameter( &start_point); - registerParameter( &end_point); - registerParameter( &id_origin); - id_origin.param_hide_canvas_text(); + registerParameter(&split_gap); + registerParameter(&discard_orig_path); + registerParameter(&fuse_paths); + registerParameter(&oposite_fuse); + registerParameter(&split_elements); + registerParameter(&start_point); + registerParameter(&end_point); + registerParameter(¢er_point); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; - actual = true; + previous_center = Geom::Point(0,0); } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -94,11 +87,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty() && actual) { + if ( sel && !sel->isEmpty()) { SPItem *item = sel->singleItem(); if (item) { if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { - actual = false; return; } } @@ -117,11 +109,14 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } + if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { + start_point.param_setValue(point_a); + end_point.param_setValue(point_b); + } line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); - center_point = Geom::middle_point(point_a, point_b); } else if ( mode == MT_FREE) { if(!are_near(previous_center,center_point, 0.01)) { Geom::Point trans = center_point - previous_center; @@ -129,7 +124,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans); line_separation.setPoints(start_point, end_point); } else { - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ @@ -142,7 +136,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } else { //horizontal page @@ -155,53 +148,56 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); } } - previous_center = center_point; - if (split_elements) { - ms_container = dynamic_cast(splpeitem->parent); + + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + if (!are_near(previous_center, center_point,0.01)) { + center_point.param_setValue(previous_center); + } + if (split_elements && allow_split()) { + container = dynamic_cast(splpeitem->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); Inkscape::XML::Node *root_origin = doc->getReprRoot(); if (root_origin != root) { return; } - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - Geom::Point gap(split_gap,0); - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Point dir = unit_vector(point_b - point_a); - Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; - line_separation *= Geom::Translate(offset); - Geom::Scale sca(1.0, -1.0); - const char * id_original = id_origin.param_getSVGValue(); - const char * id = g_strdup(Glib::ustring("mirror-").append(id_original).append("-").append(this->getRepr()->attribute("id")).c_str()); - m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - m = m * lpeitem->transform; - if (std::strcmp(splpeitem->getId(), id) == 0) { - createMirror(splpeitem, m, id_original); - } else { - createMirror(splpeitem, m, id); - } - elements.clear(); - elements.push_back(id); - elements.push_back(id_original); + const char * mirror = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); +// if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { +// syncMirror(splpeitem, mirror_a); +// } else { + Geom::Point point_a(line_separation.initialPoint()); + Geom::Point point_b(line_separation.finalPoint()); + Geom::Point gap(split_gap,0); + Geom::Translate m1(point_a[0], point_a[1]); + double hyp = Geom::distance(point_a, point_b); + double cos = 0; + double sin = 0; + if (hyp > 0) { + cos = (point_b[0] - point_a[0]) / hyp; + sin = (point_b[1] - point_a[1]) / hyp; + } + Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); + Geom::Point dir = unit_vector(point_b - point_a); + Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; + line_separation *= Geom::Translate(offset); + Geom::Scale sca(1.0, -1.0); + m = m1.inverse() * m2; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + m = m * splpeitem->transform; + createMirror(splpeitem, m); + //} } else { - elements.clear(); + if (!allow_split()) { + std::cout << "Only one operation of split allowed. Group results to nested effects.\n"; + split_elements.param_setValue(false); + } processObjects(LPE_ERASE); + elements.clear(); } } @@ -255,7 +251,7 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c if (c) { dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); c->reset(); - g_free(c); + g_free(c); } else { dest->getRepr()->setAttribute(att,NULL); } @@ -268,9 +264,19 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id) +LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + const char * id; + Glib::ustring idbase = Glib::ustring(sp_lpe_item->getId()); + size_t pos = idbase.find("-mirror"); + if (pos <= idbase.size()) { + id = g_strdup(idbase.substr(pos).c_str()); + } else { + id = g_strdup(idbase.append("-mirror").c_str()); + elements.clear(); + elements.push_back(id); + } Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); @@ -282,24 +288,95 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform, const } else { phantom = origin->getRepr()->duplicate(xml_doc); } - phantom->setAttribute("id", id); if (!elemref) { - elemref = ms_container->appendChildRepr(phantom); + elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - if (elemref->parent != ms_container) { + if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", id); - ms_container->appendChildRepr(copy); + container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); } } } +//void +//LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) +//{ +// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { +// Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); +// Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); +// Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); +// SVGElemRef->attach(SVGElem_uri); +// SPObject *elemref= NULL; +// Inkscape::XML::Node *phantom = NULL; +// if (elemref = SVGElemRef->getObject()) { +// cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required +// } +// } +//} + +bool +LPEMirrorSymmetry::allow_split(){ + if (sp_lpe_item->path_effect_list->empty()) { + return false; + } + size_t count = 0; + for (PathEffectList::const_iterator it = sp_lpe_item->path_effect_list->begin(); it != sp_lpe_item->path_effect_list->end(); ++it) + { + LivePathEffectObject *lpeobj = (*it)->lpeobject; + if (lpeobj) { + Inkscape::LivePathEffect::LPEMirrorSymmetry * ms = dynamic_cast(lpeobj->get_lpe()); + if (ms && ms->split_elements) { + count++; + } + } + } + return count <= 1; +} + +//Gtk::Widget * +//LPEMirrorSymmetry::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); +// std::vector::iterator it = param_vector.begin(); +// while (it != param_vector.end()) { +// if ((*it)->widget_is_visible) { +// Parameter *param = *it; +// Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); +// if (widg) { +// if (param->param_key == "split_elements") { +// Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast(widg)); +// if (!allow_split()) { +// widg_registered->set_sensitive("false"); +// } +// widg = dynamic_cast(widg_registered); +// } +// Glib::ustring *tip = param->param_getTooltip(); +// 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(vbox); +//} + //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) @@ -349,15 +426,15 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { elemref->deleteObject(); - } + //} break; case LPE_VISIBILITY: css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { css->setAttribute("display", "none"); } else { css->setAttribute("display", NULL); @@ -382,8 +459,6 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { if( !split_elements) { - center_point *= postmul; - previous_center = center_point; // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; @@ -406,10 +481,15 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b); end_point.param_update_default(point_b); - center_point = point_c; + center_point.param_setValue(point_c); previous_center = center_point; - id_origin.param_setValue(Glib::ustring(lpeitem->getId())); - id_origin.write_to_SVG(); +// SPLPEItem * splpeitem = const_cast(lpeitem); +// if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet +// const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); +// splpeitem->setAttribute("id", mirror_a); +// first_lpe.param_setValue(this->getRepr()->attribute("id")); +// first_lpe.write_to_SVG(); +// } } @@ -560,41 +640,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) return path_out; } - -Gtk::Widget *LPEMirrorSymmetry::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "id_origin") { - 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(vbox); -} - void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { @@ -610,43 +655,6 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector hp_vec.push_back(helper); } -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; - SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; - guint32 knot_color = 0x0000ff00; - { - KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center"), knot_shape, knot_mode, knot_color ); - knotholder->add(c); - } -}; - -namespace MS { - -using namespace Geom; - -void -KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - LPEMirrorSymmetry* lpe = dynamic_cast(_effect); - Geom::Point const s = snap_knot_position(p, state); - lpe->center_point = s; - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityCenterMirrorSymmetry::knot_get() const -{ - LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); - return lpe->center_point; -} - -} // namespace CR - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7b090ed82..12ceebaf8 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -15,10 +15,10 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include + #include "live_effects/effect.h" -#include "live_effects/parameter/text.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" @@ -27,11 +27,6 @@ namespace Inkscape { namespace LivePathEffect { -namespace MS { -// we need a separate namespace to avoid clashes with LPEPerpBisector -class KnotHolderEntityCenterMirrorSymmetry; -} - enum ModeType { MT_V, MT_H, @@ -51,14 +46,13 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); - virtual Gtk::Widget *newWidget(); +// virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - /* the knotholder entity classes must be declared friends */ - friend class MS::KnotHolderEntityCenterMirrorSymmetry; - void createMirror(SPLPEItem *origin, Geom::Affine transform, const char * id); + void createMirror(SPLPEItem *origin, Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); +// void syncMirror(SPLPEItem *origin, const char * id); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + bool allow_split(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -72,13 +66,11 @@ private: BoolParam split_elements; PointParam start_point; PointParam end_point; - TextParam id_origin; + PointParam center_point; Geom::Line line_separation; Geom::Point previous_center; - Geom::Point center_point; - bool actual; std::vector elements; - SPObject * ms_container; + SPObject * container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index a0fa46c3f..057f404e0 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -11,13 +11,12 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-offset.h" #include "sp-shape.h" #include "display/curve.h" - #include <2geom/elliptical-arc.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 9cd8ecf46..276749c43 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -11,14 +11,15 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-parallel.h" #include "sp-shape.h" #include "display/curve.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 6ec1e0ede..a06dbde98 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -11,10 +11,10 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-path_length.h" #include "util/units.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 15c2817c4..9cfeffee7 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -12,6 +12,8 @@ #include "knotholder.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include using std::vector; diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index f69dae6a1..bce22250a 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -11,9 +11,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - -#include - #include "live_effects/lpe-perp_bisector.h" #include "display/curve.h" #include "sp-path.h" @@ -21,6 +18,9 @@ #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { namespace PB { diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 6a6b59519..e834c0e86 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -20,6 +20,9 @@ #include "display/curve.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include + using namespace Geom; namespace Inkscape { diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index cb4e43d87..2c6d66cee 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -11,8 +11,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include -#include - #include "persp3d.h" //#include "transf_mat_3x4.h" #include "document-private.h" @@ -23,6 +21,9 @@ #include "desktop.h" #include +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 329a00756..e9f3975c7 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -25,6 +25,9 @@ #include <2geom/circle.h> #include "helper/geom.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Geom { // should all be moved to 2geom at some point diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index ed0c915ce..aa0db920b 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -10,12 +10,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-recursiveskeleton.h" #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 2fb65b349..3cc8658ea 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -13,7 +13,6 @@ */ #include "ui/widget/scalar.h" -#include #include "live_effects/lpe-rough-hatches.h" #include "sp-item.h" @@ -23,6 +22,8 @@ #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 3a486ff10..c6edffd9b 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -13,11 +13,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-roughen.h" #include "display/curve.h" #include #include "helper/geom.h" + // TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index dbdb91e62..bab06022f 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -12,7 +12,6 @@ #ifndef INKSCAPE_LPE_ROUGHEN_H #define INKSCAPE_LPE_ROUGHEN_H -#include #include "live_effects/effect.h" #include "live_effects/parameter/enum.h" #include "live_effects/parameter/parameter.h" diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 3a2d78b2c..60c2a3e1c 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -12,7 +12,8 @@ */ #include "live_effects/lpe-ruler.h" - +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 170b6dccb..7c298d0e7 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -6,6 +6,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-show_handles.h" #include <2geom/sbasis-to-bezier.h> #include <2geom/svg-path-parser.h> @@ -13,6 +14,7 @@ #include "desktop-style.h" #include "style.h" #include "svg/svg.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-show_handles.h b/src/live_effects/lpe-show_handles.h index 3eda04649..c46abd2c2 100644 --- a/src/live_effects/lpe-show_handles.h +++ b/src/live_effects/lpe-show_handles.h @@ -8,7 +8,6 @@ * Copyright (C) Jabier Arraiza Cenoz 2014 * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "helper/geom-nodetype.h" #include "live_effects/effect.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index ec21e10d2..8bdb19b4f 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -2,6 +2,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include #include "live_effects/lpe-simplify.h" #include "display/curve.h" #include "helper/geom.h" @@ -9,6 +10,7 @@ #include "svg/svg.h" #include "ui/tools/node-tool.h" #include "ui/icon-names.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h index 8135561af..6c407f572 100644 --- a/src/live_effects/lpe-simplify.h +++ b/src/live_effects/lpe-simplify.h @@ -6,7 +6,6 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/effect.h" #include "live_effects/parameter/togglebutton.h" #include "live_effects/lpegroupbbox.h" diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 7d34db699..adc4a3493 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -20,8 +20,7 @@ #include "live_effects/lpe-skeleton.h" -// You might need to include other 2geom files. You can add them here: - +// TODO due to internal breakage in glibmm headers, this must be last: #include namespace Inkscape { diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 95e2f6f0d..e01516f2e 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -13,13 +13,14 @@ #include "live_effects/lpe-sketch.h" -#include - // You might need to include other 2geom files. You can add them here: #include <2geom/sbasis-math.h> #include <2geom/bezier-to-sbasis.h> #include <2geom/path-intersection.h> +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index b308ef8d7..76d4ea71b 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -13,13 +13,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-tangent_to_curve.h" #include "sp-path.h" #include "display/curve.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f6f6b33dc..4ffc41691 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -26,6 +26,8 @@ #include "svg/svg.h" #include "knotholder.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include template inline bool withinRange(T value, T low, T high) { diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index c7ecf6481..324893706 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -4,10 +4,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-test-doEffect-stack.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + using std::memcpy; namespace Inkscape { diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp index 602a6897c..709d05e18 100644 --- a/src/live_effects/lpe-text_label.cpp +++ b/src/live_effects/lpe-text_label.cpp @@ -11,10 +11,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include - #include "live_effects/lpe-text_label.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 78db622f2..e1f36eee7 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -20,6 +20,7 @@ // TODO due to internal breakage in glibmm headers, this must be last: #include + namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 2486f3366..47e2a1cec 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -5,7 +5,7 @@ */ #include "live_effects/lpe-vonkoch.h" - +// TODO due to internal breakage in glibmm headers, this must be last: #include //using std::vector; diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index ff8ab76a0..64c203093 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -4,7 +4,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "ui/widget/registered-widget.h" #include "live_effects/parameter/fontbutton.h" #include "live_effects/effect.h" diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index 387ad130b..df47251a2 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -8,7 +8,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include -#include #include "live_effects/parameter/parameter.h" namespace Inkscape { -- cgit v1.2.3 From fa0cdcb4b2d8e2290860f3457be613387d57b8b9 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 17 Dec 2016 18:28:36 +0100 Subject: Fix a bug on transforms in mirror symmetry (bzr r15330) --- src/live_effects/lpe-mirror_symmetry.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 482b8bfa4..1c888b8d1 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -171,6 +171,7 @@ LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) Parameter * param = *it; param->param_transform_multiply(postmul, set); } + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); } void -- cgit v1.2.3 From cb31a827d3db6bc45cdd806fdf1581f608ccc180 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 19 Dec 2016 00:19:40 +0100 Subject: Use Geom::Reflection instead custom method an copy rotate and mirror LPE (bzr r15331) --- src/live_effects/lpe-copy_rotate.cpp | 15 ++------------- src/live_effects/lpe-mirror_symmetry.cpp | 28 +++------------------------- src/live_effects/lpe-mirror_symmetry.h | 1 - 3 files changed, 5 insertions(+), 39 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 5b94e9083..0492b12d6 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -262,19 +262,8 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s if (i%2 != 0) { Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; - Geom::Translate m1(A[0], A[1]); - double hyp = Geom::distance(A, B); - double c = (B[0] - A[0]) / hyp; // cos(alpha) - double s = (B[1] - A[1]) / hyp; // sin(alpha) - - Geom::Affine m2(c, -s, s, c, 0.0, 0.0); - Geom::Scale sca(1.0, -1.0); - - Geom::Affine tmp_m = m1.inverse() * m2; - m = tmp_m; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; + Geom::Line ls(A,B); + Geom::Affine m = Geom::reflection (ls.vector(), A); } else { append_path = original; } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 1c888b8d1..67d932e84 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -119,7 +119,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) start_point.param_setValue(point_a); end_point.param_setValue(point_b); } - line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a, true); end_point.param_setValue(point_b, true); @@ -128,9 +127,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point trans = center_point - previous_center; start_point.param_setValue(start_point * trans, true); end_point.param_setValue(end_point * trans, true); - line_separation.setPoints(start_point, end_point); - } else { - line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ if(SP_ACTIVE_DESKTOP){ @@ -142,7 +138,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep, true); - line_separation.setPoints(start_point, end_point); } } else { //horizontal page if(SP_ACTIVE_DESKTOP){ @@ -154,7 +149,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep, true); - line_separation.setPoints(start_point, end_point); } } previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); @@ -203,24 +197,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out = pathv_to_linear_and_cubic_beziers(path_in); } - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Scale sca(1.0, -1.0); - - Geom::Affine m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; + Geom::Line ls((Geom::Point)start_point,(Geom::Point)end_point); + Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); @@ -247,7 +225,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } Geom::Point s = start_point; Geom::Point e = end_point; - double dir = line_separation.angle(); + double dir = ls.angle(); double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(center_point, bbox) + diagonal; diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index a7d271453..b4967173a 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -56,7 +56,6 @@ private: PointParam start_point; PointParam end_point; PointParam center_point; - Geom::Line line_separation; Geom::Point previous_center; LPEMirrorSymmetry(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 8b8a183534d1bd9bfec78239294b0959b97defdd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 19 Dec 2016 00:35:19 +0100 Subject: Some coding style fixes (bzr r15332) --- src/live_effects/lpe-mirror_symmetry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 67d932e84..07c9f6f99 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -197,8 +197,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out = pathv_to_linear_and_cubic_beziers(path_in); } - Geom::Line ls((Geom::Point)start_point,(Geom::Point)end_point); - Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); + Geom::Line line_separation((Geom::Point)start_point, (Geom::Point)end_point); + Geom::Affine m = Geom::reflection (line_separation.vector(), (Geom::Point)start_point); if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); @@ -225,7 +225,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } Geom::Point s = start_point; Geom::Point e = end_point; - double dir = ls.angle(); + double dir = line_separation.angle(); double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(center_point, bbox) + diagonal; -- cgit v1.2.3 From 323abf91b94beccd3dd2a3d617344dbc81523840 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 19 Dec 2016 00:37:46 +0100 Subject: working on reflections (bzr r15295.1.27) --- src/live_effects/lpe-measure-line.cpp | 9 +- src/live_effects/lpe-mirror_symmetry.cpp | 317 ++++++++++++++----------------- src/live_effects/lpe-mirror_symmetry.h | 13 +- src/live_effects/parameter/bool.cpp | 3 +- src/live_effects/parameter/text.cpp | 3 +- 5 files changed, 159 insertions(+), 186 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 8847b78aa..3feb6ff08 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -23,6 +23,7 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" +#include "helper/geom.h" #include "2geom/affine.h" #include "path-chemistry.h" #include "style.h" @@ -169,12 +170,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} -void swap(Geom::Point &A, Geom::Point &B){ - Geom::Point tmp = A; - A = B; - B = tmp; -} - void LPEMeasureLine::createArrowMarker(const char * mode) { @@ -535,7 +530,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { if ((Glib::ustring(format.param_getSVGValue()).empty())) { format.param_setValue(Glib::ustring("{measure}{unit}")); - this->upd_params = true; + format.write_to_SVG(); } size_t ncurves = pathvector.curveCount(); if (ncurves != (size_t)curve_linked.param_get_max()) { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f34421df2..3676013e0 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -25,6 +25,7 @@ #include "helper/geom.h" #include "2geom/path-intersection.h" #include "2geom/affine.h" +#include "helper/geom.h" #include "uri.h" #include "uri-references.h" #include "path-chemistry.h" @@ -58,7 +59,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), + id_origin("hidden", "hidden store the id of the first LPEItem", "id_origin", &wr, this,"") { show_orig_path = true; registerParameter(&mode); @@ -70,27 +72,80 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter(&start_point); registerParameter(&end_point); registerParameter(¢er_point); + registerParameter(&id_origin); + id_origin.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); + other = NULL; + last_transform = Geom::identity(); } LPEMirrorSymmetry::~LPEMirrorSymmetry() { } +void +LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) +{ + last_transform = Geom::identity(); + if (split_elements) { + if (discard_orig_path) { + discard_orig_path.param_setValue(false); + discard_orig_path.write_to_SVG(); + std::cout << _("You can't discard original paths on split elements"); + } + container = dynamic_cast(sp_lpe_item->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; + } + Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); + Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); + // Geom::Point gap(split_gap,0); +// Geom::Translate m1(point_a[0], point_a[1]); +// double hyp = Geom::distance(point_a, point_b); +// double cos = 0; +// double sin = 0; +// if (hyp > 0) { +// cos = (point_b[0] - point_a[0]) / hyp; +// sin = (point_b[1] - point_a[1]) / hyp; +// } +// Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); +// Geom::Point dir = unit_vector(point_b - point_a); +// Geom::Point offset = (point_a + point_b)/2 + Geom::rot90(dir.ccw()) * split_gap; +// line_separation *= Geom::Translate(offset); +// Geom::Scale sca(1.0, -1.0); +// m = m1.inverse() * m2; +// m = m * sca; +// m = m * m2.inverse(); +// m = m * m1; + m = m * sp_lpe_item->transform; +// if (std::strcmp(sp_lpe_item->getId(), origin) != 0) { + createMirror(m); +// } else { +// createMirror(sp_lpe_item, m, mirror); +// } + } else { + processObjects(LPE_ERASE); + elements.clear(); + other = NULL; + } +} + void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { - SPLPEItem * splpeitem = const_cast(lpeitem); if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { Inkscape::Selection *sel = desktop->getSelection(); if ( sel && !sel->isEmpty()) { SPItem *item = sel->singleItem(); if (item) { - if(std::strcmp(splpeitem->getId(),item->getId()) != 0) { + if(std::strcmp(sp_lpe_item->getId(),item->getId()) != 0) { return; } } @@ -98,7 +153,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } using namespace Geom; original_bbox(lpeitem); - Geom::Affine m = Geom::identity();//lpeitem->transform; Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); if (mode == MT_Y) { @@ -113,7 +167,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) start_point.param_setValue(point_a); end_point.param_setValue(point_b); } - line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a); end_point.param_setValue(point_b); @@ -122,9 +175,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point trans = center_point - previous_center; start_point.param_setValue(start_point * trans); end_point.param_setValue(end_point * trans); - line_separation.setPoints(start_point, end_point); - } else { - line_separation.setPoints(start_point, end_point); } } else if ( mode == MT_V){ if(SP_ACTIVE_DESKTOP){ @@ -136,7 +186,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - line_separation.setPoints(start_point, end_point); } } else { //horizontal page if(SP_ACTIVE_DESKTOP){ @@ -148,7 +197,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); - line_separation.setPoints(start_point, end_point); } } @@ -156,49 +204,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if (!are_near(previous_center, center_point,0.01)) { center_point.param_setValue(previous_center); } - if (split_elements && allow_split()) { - container = dynamic_cast(splpeitem->parent); - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); - Inkscape::XML::Node *root_origin = doc->getReprRoot(); - if (root_origin != root) { - return; - } - const char * mirror = g_strdup(Glib::ustring("mirror-b-").append(this->getRepr()->attribute("id")).c_str()); -// if (std::strcmp(splpeitem->getId(), mirror_b) == 0) { -// syncMirror(splpeitem, mirror_a); -// } else { - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - Geom::Point gap(split_gap,0); - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Point dir = unit_vector(point_b - point_a); - Geom::Point offset = (point_a + point_b)/2 + dir.ccw() * split_gap; - line_separation *= Geom::Translate(offset); - Geom::Scale sca(1.0, -1.0); - m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - m = m * splpeitem->transform; - createMirror(splpeitem, m); - //} - } else { - if (!allow_split()) { - std::cout << "Only one operation of split allowed. Group results to nested effects.\n"; - split_elements.param_setValue(false); - } - processObjects(LPE_ERASE); - elements.clear(); - } } //void @@ -264,21 +269,22 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c } void -LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) +LPEMirrorSymmetry::createMirror(Geom::Affine transform) { if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - const char * id; - Glib::ustring idbase = Glib::ustring(sp_lpe_item->getId()); - size_t pos = idbase.find("-mirror"); - if (pos <= idbase.size()) { - id = g_strdup(idbase.substr(pos).c_str()); + const char * id_origin_char = id_origin.param_getSVGValue(); + const char * mirror = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); + const char * elemref_id; + if (std::strcmp(sp_lpe_item->getId(), mirror) == 0) { + elemref_id = id_origin_char; } else { - id = g_strdup(idbase.append("-mirror").c_str()); - elements.clear(); - elements.push_back(id); + elemref_id = mirror; } + elements.clear(); + elements.push_back(id_origin_char); + elements.push_back(mirror); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); + Inkscape::URI SVGElem_uri(Glib::ustring("#").append(elemref_id).c_str()); Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); SVGElemRef->attach(SVGElem_uri); SPObject *elemref= NULL; @@ -286,97 +292,72 @@ LPEMirrorSymmetry::createMirror(SPLPEItem *origin, Geom::Affine transform) if (elemref = SVGElemRef->getObject()) { phantom = elemref->getRepr(); } else { - phantom = origin->getRepr()->duplicate(xml_doc); + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); } - phantom->setAttribute("id", id); + phantom->setAttribute("id", elemref_id); if (!elemref) { elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "inkscape:original-d", "d", "inkscape:path-effect", NULL); //NULL required + //transform *= last_transform; + //if (transform != Geom::identity()) { + if (elemref_id == mirror) { + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + } else { + sp_lpe_item->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + } + //} if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); - copy->setAttribute("id", id); - container->appendChildRepr(copy); + copy->setAttribute("id", elemref_id); + other = container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); + } else { + other = elemref; } + } } -//void -//LPEMirrorSymmetry::syncMirror(SPLPEItem *origin, const char * id) -//{ -// if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { -// Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); -// Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); -// Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); -// SVGElemRef->attach(SVGElem_uri); -// SPObject *elemref= NULL; -// Inkscape::XML::Node *phantom = NULL; -// if (elemref = SVGElemRef->getObject()) { -// cloneAttrbutes(SP_OBJECT(origin), elemref, true, "inkscape:original-d", "inkscape:path-effect", NULL); //NULL required -// } -// } -//} - -bool -LPEMirrorSymmetry::allow_split(){ - if (sp_lpe_item->path_effect_list->empty()) { - return false; - } - size_t count = 0; - for (PathEffectList::const_iterator it = sp_lpe_item->path_effect_list->begin(); it != sp_lpe_item->path_effect_list->end(); ++it) - { - LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (lpeobj) { - Inkscape::LivePathEffect::LPEMirrorSymmetry * ms = dynamic_cast(lpeobj->get_lpe()); - if (ms && ms->split_elements) { - count++; +Gtk::Widget * +LPEMirrorSymmetry::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter * param = *it; + if (param->param_key == "id_origin") { + ++it; + continue; + } + Gtk::Widget * widg = param->param_newWidget(); + 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 count <= 1; + this->upd_params = false; + return dynamic_cast(vbox); } -//Gtk::Widget * -//LPEMirrorSymmetry::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); -// std::vector::iterator it = param_vector.begin(); -// while (it != param_vector.end()) { -// if ((*it)->widget_is_visible) { -// Parameter *param = *it; -// Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); -// if (widg) { -// if (param->param_key == "split_elements") { -// Gtk::CheckButton *widg_registered = Gtk::manage(dynamic_cast(widg)); -// if (!allow_split()) { -// widg_registered->set_sensitive("false"); -// } -// widg = dynamic_cast(widg_registered); -// } -// Glib::ustring *tip = param->param_getTooltip(); -// 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(vbox); -//} - //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) @@ -458,13 +439,21 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { - if( !split_elements) { - // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { - Parameter * param = *it; - param->param_transform_multiply(postmul, set); - } + // cycle through all parameters. Most parameters will not need transformation, but path and point params do. + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); } + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); +// Geom::Affine m = Geom::identity(); +// m *= sp_lpe_item->transform; +// m *= postmul; +// sp_lpe_item->transform = m; + last_transform *= postmul; + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); +// if (other) { +// sp_lpe_item_update_patheffect(SP_LPE_ITEM(other), false, false); +// } } void @@ -483,13 +472,11 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) end_point.param_update_default(point_b); center_point.param_setValue(point_c); previous_center = center_point; -// SPLPEItem * splpeitem = const_cast(lpeitem); -// if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet -// const char * mirror_a = g_strdup(Glib::ustring("mirror-a-").append(this->getRepr()->attribute("id")).c_str()); -// splpeitem->setAttribute("id", mirror_a); -// first_lpe.param_setValue(this->getRepr()->attribute("id")); -// first_lpe.write_to_SVG(); -// } + SPLPEItem * splpeitem = const_cast(lpeitem); + if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet + id_origin.param_setValue(lpeitem->getRepr()->attribute("id")); + id_origin.write_to_SVG(); + } } @@ -506,26 +493,10 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out = pathv_to_linear_and_cubic_beziers(path_in); } - Geom::Point point_a(line_separation.initialPoint()); - Geom::Point point_b(line_separation.finalPoint()); - - Geom::Translate m1(point_a[0], point_a[1]); - double hyp = Geom::distance(point_a, point_b); - double cos = 0; - double sin = 0; - if (hyp > 0) { - cos = (point_b[0] - point_a[0]) / hyp; - sin = (point_b[1] - point_a[1]) / hyp; - } - Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); - Geom::Scale sca(1.0, -1.0); + Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); + Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); - Geom::Affine m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - - if (fuse_paths && (!discard_orig_path || split_elements )) { + if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -550,7 +521,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } Geom::Point s = start_point; Geom::Point e = end_point; - double dir = line_separation.angle(); + double dir = ls.angle(); double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(center_point, bbox) + diagonal; @@ -577,7 +548,9 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (position == 1) { Geom::Path mirror = portion.reversed() * m; if (split_elements) { - portion.close(); + if(i!=0 || original.closed()) { + portion.close(); + } } else { mirror.setInitial(portion.finalPoint()); portion.append(mirror); @@ -626,7 +599,9 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (cs.size() == 0 && position == 1) { tmp_path.push_back(original); - tmp_path.push_back(original * m); + if ( !split_elements) { + tmp_path.push_back(original * m); + } } path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 12ceebaf8..b05871cd0 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -42,17 +42,16 @@ public: virtual ~LPEMirrorSymmetry(); virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); -// virtual Gtk::Widget * newWidget(); + virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - void createMirror(SPLPEItem *origin, Geom::Affine transform); -// void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); -// void syncMirror(SPLPEItem *origin, const char * id); + void createMirror(Geom::Affine transform); + // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); - bool allow_split(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -67,10 +66,12 @@ private: PointParam start_point; PointParam end_point; PointParam center_point; - Geom::Line line_separation; + TextParam id_origin; Geom::Point previous_center; std::vector elements; SPObject * container; + SPObject * other; + Geom::Affine last_transform; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index af99ef362..813c06b4e 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -72,7 +72,7 @@ BoolParam::param_newWidget() checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - + param_effect->upd_params = false; return dynamic_cast (checkwdg); } else { return NULL; @@ -82,6 +82,7 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { + param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 8cab68ad0..5c4cdf4c6 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -125,13 +125,14 @@ TextParam::param_newWidget() rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - + param_effect->upd_params = false; return dynamic_cast (rsu); } void TextParam::param_setValue(const Glib::ustring newvalue) { + param_effect->upd_params = true; value = newvalue; if (!_hide_canvas_text) { sp_canvastext_set_text (canvas_text, newvalue.c_str()); -- cgit v1.2.3 From 635736904fd73e31d6e74ec65761e48f888b0f50 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 19 Dec 2016 16:17:23 +0100 Subject: Remove 'desktop' usage on measure line LPE (bzr r15333) --- src/live_effects/lpe-measure-line.cpp | 938 +++++++++++++++++----------------- 1 file changed, 458 insertions(+), 480 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 45076d625..a317a8aa1 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -15,8 +15,6 @@ #include "inkscape.h" #include "xml/node.h" #include "xml/sp-css-attr.h" -#include "uri.h" -#include "uri-references.h" #include "preferences.h" #include "util/units.h" #include "svg/svg-length.h" @@ -30,7 +28,6 @@ #include "sp-item.h" #include "sp-shape.h" #include "sp-path.h" -#include "desktop.h" #include "document.h" #include @@ -177,328 +174,316 @@ void swap(Geom::Point &A, Geom::Point &B){ void LPEMeasureLine::createArrowMarker(const char * mode) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(mode).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *arrow = NULL; - if (!(elemref = SVGElemRef->getObject())) { - arrow = xml_doc->createElement("svg:marker"); - arrow->setAttribute("id", mode); - arrow->setAttribute("inkscape:stockid", mode); - arrow->setAttribute("orient", "auto"); - arrow->setAttribute("refX", "0.0"); - arrow->setAttribute("refY", "0.0"); - arrow->setAttribute("style", "overflow:visible"); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + SPObject *elemref = NULL; + Inkscape::XML::Node *arrow = NULL; + if (elemref = document->getObjectById(mode)) { + Inkscape::XML::Node *arrow= elemref->getRepr(); + if (arrow) { arrow->setAttribute("sodipodi:insensitive", "true"); - /* Create */ - Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); - if (std::strcmp(mode, "ArrowDIN-start") == 0) { - arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); - } else if (std::strcmp(mode, "ArrowDIN-end") == 0) { - arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); - } else if (std::strcmp(mode, "ArrowDINout-start") == 0) { - arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); - } else { - arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); + arrow->setAttribute("transform", NULL); + Inkscape::XML::Node *arrow_data = arrow->firstChild(); + if (arrow_data) { + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none"); + arrow_data->setAttribute("transform", NULL); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_data->setAttribute("style", css_str.c_str()); } - - arrow_path->setAttribute("id", Glib::ustring(mode).append("_path").c_str()); - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property (css, "fill","#000000"); - sp_repr_css_set_property (css, "stroke","none"); - sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - arrow_path->setAttribute("style", css_str.c_str()); - arrow->addChild(arrow_path, NULL); - Inkscape::GC::release(arrow_path); - elemref = SP_OBJECT(desktop->getDocument()->getDefs()->appendChildRepr(arrow)); - Inkscape::GC::release(arrow); + } + } else { + arrow = xml_doc->createElement("svg:marker"); + arrow->setAttribute("id", mode); + arrow->setAttribute("inkscape:stockid", mode); + arrow->setAttribute("orient", "auto"); + arrow->setAttribute("refX", "0.0"); + arrow->setAttribute("refY", "0.0"); + arrow->setAttribute("style", "overflow:visible"); + arrow->setAttribute("sodipodi:insensitive", "true"); + /* Create */ + Inkscape::XML::Node *arrow_path = xml_doc->createElement("svg:path"); + if (std::strcmp(mode, "ArrowDIN-start") == 0) { + arrow_path->setAttribute("d", "M -8,0 8,-2.11 8,2.11 z"); + } else if (std::strcmp(mode, "ArrowDIN-end") == 0) { + arrow_path->setAttribute("d", "M 8,0 -8,2.11 -8,-2.11 z"); + } else if (std::strcmp(mode, "ArrowDINout-start") == 0) { + arrow_path->setAttribute("d", "M 0,0 -16,2.11 -16,0.5 -26,0.5 -26,-0.5 -16,-0.5 -16,-2.11 z"); } else { - Inkscape::XML::Node *arrow= elemref->getRepr(); - if (arrow) { - arrow->setAttribute("sodipodi:insensitive", "true"); - arrow->setAttribute("transform", NULL); - Inkscape::XML::Node *arrow_data = arrow->firstChild(); - if (arrow_data) { - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property (css, "fill","#000000"); - sp_repr_css_set_property (css, "stroke","none"); - arrow_data->setAttribute("transform", NULL); - sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - arrow_data->setAttribute("style", css_str.c_str()); - } - } + arrow_path->setAttribute("d", "M 0,0 16,2.11 16,0.5 26,0.5 26,-0.5 16,-0.5 16,-2.11 z"); } - elements.push_back(mode); + + arrow_path->setAttribute("id", Glib::ustring(mode).append("_path").c_str()); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "fill","#000000"); + sp_repr_css_set_property (css, "stroke","none"); + sp_repr_css_attr_add_from_string(css, arrows_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + arrow_path->setAttribute("style", css_str.c_str()); + arrow->addChild(arrow_path, NULL); + Inkscape::GC::release(arrow_path); + elemref = SP_OBJECT(document->getDefs()->appendChildRepr(arrow)); + Inkscape::GC::release(arrow); } + elements.push_back(mode); } void LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::XML::Node *rtext = NULL; - double doc_w = desktop->getDocument()->getRoot()->width.value; - Geom::Scale scale = desktop->getDocument()->getDocumentScale(); - SPNamedView *nv = desktop->getNamedView(); - Glib::ustring display_unit = nv->display_units->abbr; - if (display_unit.empty()) { - display_unit = "px"; - } - //only check constrain viewbox on X - doc_scale = Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); - if( doc_scale > 0 ) { - doc_scale= 1.0/doc_scale; - } else { - doc_scale = 1.0; - } - const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *rtspan = NULL; - if (elemref = SVGElemRef->getObject()) { - if (remove) { - elemref->deleteObject(); - return; - } - pos = pos - Point::polar(angle, text_right_left); - rtext = elemref->getRepr(); - sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - rtext->setAttribute("sodipodi:insensitive", "true"); - rtext->setAttribute("transform", NULL); - } else { - if (remove) { - return; - } - rtext = xml_doc->createElement("svg:text"); - rtext->setAttribute("xml:space", "preserve"); - rtext->setAttribute("id", id); - rtext->setAttribute("sodipodi:insensitive", "true"); - pos = pos - Point::polar(angle, text_right_left); - sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); - sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); - rtspan = xml_doc->createElement("svg:tspan"); - rtspan->setAttribute("sodipodi:role", "line"); - } - const char * transform; - Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); - angle = std::fmod(angle, 2*M_PI); - if (angle < 0) angle += 2*M_PI; - if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - affine *= Geom::Rotate(angle); - affine *= Geom::Translate(pos); - if (rotate_anotation) { - transform = sp_svg_transform_write(affine); - } else { - transform = NULL; - } - rtext->setAttribute("transform", transform); - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); - Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); - fontlister->fill_css(css, Glib::ustring(fontbutton.param_getSVGValue())); - std::stringstream font_size; - font_size.imbue(std::locale::classic()); - font_size << fontsize << "pt"; - sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); - sp_repr_css_set_property (css, "line-height","125%"); - sp_repr_css_set_property (css, "letter-spacing","0"); - sp_repr_css_set_property (css, "word-spacing", "0"); - sp_repr_css_set_property (css, "text-align", "center"); - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "fill", "#000000"); - sp_repr_css_set_property (css, "fill-opacity", "1"); - sp_repr_css_set_property (css, "stroke", "none"); - sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - if (!rtspan) { - rtspan = rtext->firstChild(); - } - rtext->setAttribute("style", css_str.c_str()); - rtspan->setAttribute("style", NULL); - rtspan->setAttribute("transform", NULL); - sp_repr_css_attr_unref (css); - if (!elemref) { - rtext->addChild(rtspan, NULL); - Inkscape::GC::release(rtspan); - } - length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); - if (local_locale) { - length_str.imbue(std::locale("")); - } else { - length_str.imbue(std::locale::classic()); - } - length_str << std::fixed << length; - Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); - size_t s = label_value.find(Glib::ustring("{measure}"),0); - if(s < label_value.length()) { - label_value.replace(s,s+9,length_str.str()); - } - s = label_value.find(Glib::ustring("{unit}"),0); - if(s < label_value.length()) { - label_value.replace(s,s+6,unit.get_abbreviation()); - } - if ( !valid ) { - label_value = Glib::ustring(_("Non Uniform Scale")); - } - Inkscape::XML::Node *rstring = NULL; - if (!elemref) { - rstring = xml_doc->createTextNode(label_value.c_str()); - rtspan->addChild(rstring, NULL); - Inkscape::GC::release(rstring); - } else { - rstring = rtspan->firstChild(); - rstring->setContent(label_value.c_str()); - } - if (!elemref) { - elemref = sp_lpe_item->parent->appendChildRepr(rtext); - Inkscape::GC::release(rtext); - } else if (elemref->parent != sp_lpe_item->parent) { - Inkscape::XML::Node *old_repr = elemref->getRepr(); - Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); - Inkscape::GC::release(copy); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + Inkscape::XML::Node *rtext = NULL; + double doc_w = document->getRoot()->width.value; + Geom::Scale scale = document->getDocumentScale(); + SPNamedView *nv = sp_document_namedview(document, NULL); + Glib::ustring display_unit = nv->display_units->abbr; + if (display_unit.empty()) { + display_unit = "px"; + } + //only check constrain viewbox on X + doc_scale = Inkscape::Util::Quantity::convert( scale[Geom::X], "px", nv->display_units ); + if( doc_scale > 0 ) { + doc_scale= 1.0/doc_scale; + } else { + doc_scale = 1.0; + } + const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = document->getObjectById(id)) { + if (remove) { elemref->deleteObject(); - copy->setAttribute("id", id); - elemref = elemref_copy; + return; } - elements.push_back(id); - Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); - if (bounds) { - anotation_width = bounds->width() * 1.4; + pos = pos - Point::polar(angle, text_right_left); + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + rtext->setAttribute("sodipodi:insensitive", "true"); + rtext->setAttribute("transform", NULL); + } else { + if (remove) { + return; } + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", id); + rtext->setAttribute("sodipodi:insensitive", "true"); + pos = pos - Point::polar(angle, text_right_left); + sp_repr_set_svg_double(rtext, "x", pos[Geom::X]); + sp_repr_set_svg_double(rtext, "y", pos[Geom::Y]); + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + const char * transform; + Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + affine *= Geom::Rotate(angle); + affine *= Geom::Translate(pos); + if (rotate_anotation) { + transform = sp_svg_transform_write(affine); + } else { + transform = NULL; + } + rtext->setAttribute("transform", transform); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); + Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); + fontlister->fill_css(css, Glib::ustring(fontbutton.param_getSVGValue())); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size",font_size.str().c_str()); + sp_repr_css_set_property (css, "line-height","125%"); + sp_repr_css_set_property (css, "letter-spacing","0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtext->setAttribute("style", css_str.c_str()); + rtspan->setAttribute("style", NULL); + rtspan->setAttribute("transform", NULL); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); + std::stringstream length_str; + length_str.precision(precision); + length_str.setf(std::ios::fixed, std::ios::floatfield); + if (local_locale) { + length_str.imbue(std::locale("")); + } else { + length_str.imbue(std::locale::classic()); + } + length_str << std::fixed << length; + Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); + size_t s = label_value.find(Glib::ustring("{measure}"),0); + if(s < label_value.length()) { + label_value.replace(s,s+9,length_str.str()); + } + s = label_value.find(Glib::ustring("{unit}"),0); + if(s < label_value.length()) { + label_value.replace(s,s+6,unit.get_abbreviation()); + } + if ( !valid ) { + label_value = Glib::ustring(_("Non Uniform Scale")); + } + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(label_value.c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(label_value.c_str()); + } + if (!elemref) { + elemref = sp_lpe_item->parent->appendChildRepr(rtext); + Inkscape::GC::release(rtext); + } else if (elemref->parent != sp_lpe_item->parent) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id); + elemref = elemref_copy; + } + elements.push_back(id); + Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); + if (bounds) { + anotation_width = bounds->width() * 1.4; } } void LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - Inkscape::XML::Node *line = NULL; - if (!main) { - Geom::Ray ray(start, end); - Geom::Coord angle = ray.angle(); - start = start + Point::polar(angle, helpline_distance ); - end = end + Point::polar(angle, helpline_overlap ); - } - Geom::PathVector line_pathv; - if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ - Geom::Path line_path; - double k = 0; - if (flip_side) { - k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); - } else { - k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); - } - if (Geom::distance(start,end) < anotation_width){ - return; - } - Geom::Ray ray(end, start); - Geom::Coord angle = ray.angle(); - line_path.start(start); - line_path.appendNew(start - Point::polar(angle, k)); - line_pathv.push_back(line_path); - line_path.clear(); - line_path.start(end + Point::polar(angle, k)); - line_path.appendNew(end); - line_pathv.push_back(line_path); + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + SPObject *elemref = NULL; + Inkscape::XML::Node *line = NULL; + if (!main) { + Geom::Ray ray(start, end); + Geom::Coord angle = ray.angle(); + start = start + Point::polar(angle, helpline_distance ); + end = end + Point::polar(angle, helpline_overlap ); + } + Geom::PathVector line_pathv; + if (main && std::abs(text_top_bottom) < fontsize/1.5 && hide_back && !overflow){ + Geom::Path line_path; + double k = 0; + if (flip_side) { + k = (Geom::distance(start,end)/2.0) + arrow_gap - (anotation_width/2.0); } else { - Geom::Path line_path; - line_path.start(start); - line_path.appendNew(end); - line_pathv.push_back(line_path); + k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); } - if (elemref = SVGElemRef->getObject()) { - if (remove) { - elemref->deleteObject(); - return; - } - line = elemref->getRepr(); - - const char * line_str = sp_svg_write_path( line_pathv ); - line->setAttribute("d" , line_str); - line->setAttribute("transform", NULL); - } else { - if (remove) { - return; - } - line = xml_doc->createElement("svg:path"); - line->setAttribute("id", id); - const char * line_str = sp_svg_write_path( line_pathv ); - line->setAttribute("d" , line_str); + if (Geom::distance(start,end) < anotation_width){ + return; } - line->setAttribute("sodipodi:insensitive", "true"); - line_pathv.clear(); - - Glib::ustring style = Glib::ustring("stroke:#000000;fill:none;"); - if (overflow && !arrows) { - line->setAttribute("inkscape:label", "downline"); - } else if (main) { - line->setAttribute("inkscape:label", "dinline"); - if (arrows_outside) { - style = style + Glib::ustring("marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"); - } else { - style = style + Glib::ustring("marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"); - } - } else { - line->setAttribute("inkscape:label", "dinhelpline"); + Geom::Ray ray(end, start); + Geom::Coord angle = ray.angle(); + line_path.start(start); + line_path.appendNew(start - Point::polar(angle, k)); + line_pathv.push_back(line_path); + line_path.clear(); + line_path.start(end + Point::polar(angle, k)); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } else { + Geom::Path line_path; + line_path.start(start); + line_path.appendNew(end); + line_pathv.push_back(line_path); + } + if (elemref = document->getObjectById(id)) { + if (remove) { + elemref->deleteObject(); + return; } - std::stringstream stroke_w; - stroke_w.imbue(std::locale::classic()); - if (line_group_05) { - double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); - stroke_w << stroke_width; - style = style + Glib::ustring("stroke-width:" + stroke_w.str()); - } else { - double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); - stroke_w << stroke_width; - style = style + Glib::ustring("stroke-width:" + stroke_w.str()); + line = elemref->getRepr(); + + const char * line_str = sp_svg_write_path( line_pathv ); + line->setAttribute("d" , line_str); + line->setAttribute("transform", NULL); + } else { + if (remove) { + return; } - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, style.c_str()); - if (main) { - sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + line = xml_doc->createElement("svg:path"); + line->setAttribute("id", id); + const char * line_str = sp_svg_write_path( line_pathv ); + line->setAttribute("d" , line_str); + } + line->setAttribute("sodipodi:insensitive", "true"); + line_pathv.clear(); + + Glib::ustring style = Glib::ustring("stroke:#000000;fill:none;"); + if (overflow && !arrows) { + line->setAttribute("inkscape:label", "downline"); + } else if (main) { + line->setAttribute("inkscape:label", "dinline"); + if (arrows_outside) { + style = style + Glib::ustring("marker-start:url(#ArrowDINout-start);marker-end:url(#ArrowDINout-end);"); } else { - sp_repr_css_attr_add_from_string(css, helperlines_format.param_getSVGValue()); - } - Glib::ustring css_str; - sp_repr_css_write_string(css,css_str); - line->setAttribute("style", css_str.c_str()); - if (!elemref) { - elemref = sp_lpe_item->parent->appendChildRepr(line); - Inkscape::GC::release(line); - } else if (elemref->parent != sp_lpe_item->parent) { - Inkscape::XML::Node *old_repr = elemref->getRepr(); - Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); - SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); - Inkscape::GC::release(copy); - elemref->deleteObject(); - copy->setAttribute("id", id); + style = style + Glib::ustring("marker-start:url(#ArrowDIN-start);marker-end:url(#ArrowDIN-end);"); } - elements.push_back(id); + } else { + line->setAttribute("inkscape:label", "dinhelpline"); + } + std::stringstream stroke_w; + stroke_w.imbue(std::locale::classic()); + if (line_group_05) { + double stroke_width = Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); + stroke_w << stroke_width; + style = style + Glib::ustring("stroke-width:" + stroke_w.str()); + } else { + double stroke_width = Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); + stroke_w << stroke_width; + style = style + Glib::ustring("stroke-width:" + stroke_w.str()); } + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, style.c_str()); + if (main) { + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + } else { + sp_repr_css_attr_add_from_string(css, helperlines_format.param_getSVGValue()); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + line->setAttribute("style", css_str.c_str()); + if (!elemref) { + elemref = sp_lpe_item->parent->appendChildRepr(line); + Inkscape::GC::release(line); + } else if (elemref->parent != sp_lpe_item->parent) { + Inkscape::XML::Node *old_repr = elemref->getRepr(); + Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + SPObject * elemref_copy = sp_lpe_item->parent->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + copy->setAttribute("id", id); + } + elements.push_back(id); } void @@ -518,171 +503,168 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) { SPLPEItem * splpeitem = const_cast(lpeitem); sp_lpe_item->parent = dynamic_cast(splpeitem->parent); - SPDocument * doc = SP_ACTIVE_DOCUMENT; + SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); - Inkscape::XML::Node *root_origin = doc->getReprRoot(); + Inkscape::XML::Node *root_origin = document->getReprRoot(); if (root_origin != root) { return; } SPPath *sp_path = dynamic_cast(splpeitem); if (sp_path) { - Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(doc->getRoot())); + Geom::Affine affinetransform = i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(document->getRoot())); Geom::PathVector pathvector = sp_path->get_original_curve()->get_pathvector(); Geom::Affine writed_transform = Geom::identity(); sp_svg_transform_read(splpeitem->getAttribute("transform"), &writed_transform ); pathvector *= writed_transform; - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - if ((Glib::ustring(format.param_getSVGValue()).empty())) { - format.param_setValue(Glib::ustring("{measure}{unit}")); - this->upd_params = true; - } - size_t ncurves = pathvector.curveCount(); - if (ncurves != (size_t)curve_linked.param_get_max()) { - curve_linked.param_set_range(0, ncurves); - } - Geom::Point start = pathvector.initialPoint(); - Geom::Point end = pathvector.finalPoint(); - if (curve_linked) { //!0 - start = pathvector.pointAt(curve_linked -1); - end = pathvector.pointAt(curve_linked); + if ((Glib::ustring(format.param_getSVGValue()).empty())) { + format.param_setValue(Glib::ustring("{measure}{unit}")); + this->upd_params = true; + } + size_t ncurves = pathvector.curveCount(); + if (ncurves != (size_t)curve_linked.param_get_max()) { + curve_linked.param_set_range(0, ncurves); + } + Geom::Point start = pathvector.initialPoint(); + Geom::Point end = pathvector.finalPoint(); + if (curve_linked) { //!0 + start = pathvector.pointAt(curve_linked -1); + end = pathvector.pointAt(curve_linked); + } + if (Geom::are_near(start, start_stored, 0.01) && + Geom::are_near(end, end_stored, 0.01) && + sp_lpe_item->getCurrentLPE() != this){ + return; + } + elements.clear(); + start_stored = start; + end_stored = end; + Geom::Point hstart = start; + Geom::Point hend = end; + bool remove = false; + if (Geom::are_near(hstart, hend)) { + remove = true; + } + if (orientation == OM_VERTICAL) { + Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); + if (flip_side) { + xpos = std::min(hstart[Geom::X],hend[Geom::X]); } - if (Geom::are_near(start, start_stored, 0.01) && - Geom::are_near(end, end_stored, 0.01) && - sp_lpe_item->getCurrentLPE() != this){ - return; + hstart[Geom::X] = xpos; + hend[Geom::X] = xpos; + if (hstart[Geom::Y] > hend[Geom::Y]) { + swap(hstart,hend); + swap(start,end); } - elements.clear(); - start_stored = start; - end_stored = end; - Geom::Point hstart = start; - Geom::Point hend = end; - bool remove = false; - if (Geom::are_near(hstart, hend)) { + if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { remove = true; } - if (orientation == OM_VERTICAL) { - Coord xpos = std::max(hstart[Geom::X],hend[Geom::X]); - if (flip_side) { - xpos = std::min(hstart[Geom::X],hend[Geom::X]); - } - hstart[Geom::X] = xpos; - hend[Geom::X] = xpos; - if (hstart[Geom::Y] > hend[Geom::Y]) { - swap(hstart,hend); - swap(start,end); - } - if (Geom::are_near(hstart[Geom::Y], hend[Geom::Y])) { - remove = true; - } - } - if (orientation == OM_HORIZONTAL) { - Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); - if (flip_side) { - ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); - } - hstart[Geom::Y] = ypos; - hend[Geom::Y] = ypos; - if (hstart[Geom::X] < hend[Geom::X]) { - swap(hstart,hend); - swap(start,end); - } - if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { - remove = true; - } - } - double length = Geom::distance(hstart,hend) * scale; - Geom::Point pos = Geom::middle_point(hstart,hend); - Geom::Ray ray(hstart,hend); - Geom::Coord angle = ray.angle(); + } + if (orientation == OM_HORIZONTAL) { + Coord ypos = std::max(hstart[Geom::Y],hend[Geom::Y]); if (flip_side) { - angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); - if (angle < 0) angle += 2*M_PI; - } - if (arrows_outside) { - createArrowMarker("ArrowDINout-start"); - createArrowMarker("ArrowDINout-end"); - } else { - createArrowMarker("ArrowDIN-start"); - createArrowMarker("ArrowDIN-end"); + ypos = std::min(hstart[Geom::Y],hend[Geom::Y]); } - //We get the font size to offset the text to the middle - Pango::FontDescription fontdesc(Glib::ustring(fontbutton.param_getSVGValue())); - fontsize = fontdesc.get_size()/(double)Pango::SCALE; - fontsize *= desktop->doc()->getRoot()->c2p.inverse().expansionX(); - Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); - if (angle_cross < 0) angle_cross += 2*M_PI; - angle = std::fmod(angle, 2*M_PI); - if (angle < 0) angle += 2*M_PI; - if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { - pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); - } else { - pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); + hstart[Geom::Y] = ypos; + hend[Geom::Y] = ypos; + if (hstart[Geom::X] < hend[Geom::X]) { + swap(hstart,hend); + swap(start,end); } - double parents_scale = (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; - if (scale_sensitive) { - length *= parents_scale; + if (Geom::are_near(hstart[Geom::X], hend[Geom::X])) { + remove = true; } - if (scale_sensitive && !affinetransform.preservesAngles()) { - createTextLabel(pos, length, angle, remove, false); - } else { - createTextLabel(pos, length, angle, remove, true); + } + double length = Geom::distance(hstart,hend) * scale; + Geom::Point pos = Geom::middle_point(hstart,hend); + Geom::Ray ray(hstart,hend); + Geom::Coord angle = ray.angle(); + if (flip_side) { + angle = std::fmod(angle + rad_from_deg(180), 2*M_PI); + if (angle < 0) angle += 2*M_PI; + } + if (arrows_outside) { + createArrowMarker("ArrowDINout-start"); + createArrowMarker("ArrowDINout-end"); + } else { + createArrowMarker("ArrowDIN-start"); + createArrowMarker("ArrowDIN-end"); + } + //We get the font size to offset the text to the middle + Pango::FontDescription fontdesc(Glib::ustring(fontbutton.param_getSVGValue())); + fontsize = fontdesc.get_size()/(double)Pango::SCALE; + fontsize *= document->getRoot()->c2p.inverse().expansionX(); + Geom::Coord angle_cross = std::fmod(angle + rad_from_deg(90), 2*M_PI); + if (angle_cross < 0) angle_cross += 2*M_PI; + angle = std::fmod(angle, 2*M_PI); + if (angle < 0) angle += 2*M_PI; + if (angle >= rad_from_deg(90) && angle < rad_from_deg(270)) { + pos = pos - Point::polar(angle_cross, (position - text_top_bottom) + fontsize/2.5); + } else { + pos = pos - Point::polar(angle_cross, (position + text_top_bottom) - fontsize/2.5); + } + double parents_scale = (affinetransform.expansionX() + affinetransform.expansionY()) / 2.0; + if (scale_sensitive) { + length *= parents_scale; + } + if (scale_sensitive && !affinetransform.preservesAngles()) { + createTextLabel(pos, length, angle, remove, false); + } else { + createTextLabel(pos, length, angle, remove, true); + } + bool overflow = false; + const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); + if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { + Geom::Point sstart = end - Point::polar(angle_cross, position); + Geom::Point send = end - Point::polar(angle_cross, position); + if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { + sstart = start - Point::polar(angle_cross, position); + send = start - Point::polar(angle_cross, position); } - bool overflow = false; - const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); - if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { - Geom::Point sstart = end - Point::polar(angle_cross, position); - Geom::Point send = end - Point::polar(angle_cross, position); - if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { - sstart = start - Point::polar(angle_cross, position); - send = start - Point::polar(angle_cross, position); - } - Geom::Point prog_end = Geom::Point(); - if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { - if (text_right_left > 0 ) { - prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); - } else { - prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); - } + Geom::Point prog_end = Geom::Point(); + if (std::abs(text_top_bottom) < fontsize/1.5 && hide_back) { + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } else { - if (text_right_left > 0 ) { - prog_end = sstart - Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); - } else { - prog_end = sstart + Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); - } + prog_end = sstart + Point::polar(angle, std::abs(text_right_left) - (anotation_width/1.9) - (Geom::distance(start,end)/2.0)); } - overflow = true; - createLine(sstart, prog_end, downline, true, overflow, false, false); } else { - //erase it - createLine(Geom::Point(),Geom::Point(), downline, true, overflow, true, false); - } - //LINE - arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); - if (line_group_05) { - arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); - } - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); - double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - setlocale(LC_NUMERIC, std::locale("").name().c_str()); - if (width_line > -0.0001) { - arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); - } - if (flip_side) { - arrow_gap *= -1; - } - hstart = hstart - Point::polar(angle_cross, position); - createLine(start, hstart, g_strdup(Glib::ustring("infoline-on-start-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); - hend = hend - Point::polar(angle_cross, position); - createLine(end, hend, g_strdup(Glib::ustring("infoline-on-end-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); - if (!arrows_outside) { - hstart = hstart + Point::polar(angle, arrow_gap); - hend = hend - Point::polar(angle, arrow_gap ); + if (text_right_left > 0 ) { + prog_end = sstart - Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } else { + prog_end = sstart + Point::polar(angle,(anotation_width/2) + std::abs(text_right_left) - (Geom::distance(start,end)/2.0)); + } } - createLine(hstart, hend, g_strdup(Glib::ustring("infoline-").append(this->getRepr()->attribute("id")).c_str()), true, overflow, remove, true); - + overflow = true; + createLine(sstart, prog_end, downline, true, overflow, false, false); + } else { + //erase it + createLine(Geom::Point(),Geom::Point(), downline, true, overflow, true, false); + } + //LINE + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); + if (line_group_05) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.25 / doc_scale, "mm", display_unit.c_str()); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); + setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); + setlocale(LC_NUMERIC, std::locale("").name().c_str()); + if (width_line > -0.0001) { + arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } + if (flip_side) { + arrow_gap *= -1; + } + hstart = hstart - Point::polar(angle_cross, position); + createLine(start, hstart, g_strdup(Glib::ustring("infoline-on-start-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); + hend = hend - Point::polar(angle_cross, position); + createLine(end, hend, g_strdup(Glib::ustring("infoline-on-end-").append(this->getRepr()->attribute("id")).c_str()), false, false, remove); + if (!arrows_outside) { + hstart = hstart + Point::polar(angle, arrow_gap); + hend = hend - Point::polar(angle, arrow_gap ); + } + createLine(hstart, hend, g_strdup(Glib::ustring("infoline-").append(this->getRepr()->attribute("id")).c_str()), true, overflow, remove, true); } } @@ -707,52 +689,48 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::processObjects(LpeAction lpe_action) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - for (std::vector::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - Inkscape::URI SVGElem_uri(Glib::ustring("#").append(id).c_str()); - Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); - SVGElemRef->attach(SVGElem_uri); - SPObject *elemref = NULL; - if (elemref = SVGElemRef->getObject()) { - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - elemref->deleteObject(); - } - break; + SPDocument * document = SP_ACTIVE_DOCUMENT; + for (std::vector::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + SPCSSAttr *css; + Glib::ustring css_str; + switch (lpe_action){ + case LPE_TO_OBJECTS: + elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); + elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); + break; - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemref->getRepr()->setAttribute("style", css_str.c_str()); - break; + case LPE_ERASE: + if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + elemref->deleteObject(); + } + break; - default: - break; + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { + css->setAttribute("display", "none"); + } else { + css->setAttribute("display", NULL); } + sp_repr_css_write_string(css,css_str); + elemref->getRepr()->setAttribute("style", css_str.c_str()); + break; + + default: + break; } } - if (lpe_action == LPE_ERASE) { - elements.clear(); - } + } + if (lpe_action == LPE_ERASE) { + elements.clear(); } } -- cgit v1.2.3 From 3be69f178a31b0880167282cecbe83c2beccbdd2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 19 Dec 2016 17:08:46 +0100 Subject: Add translatable strings to trunk (bzr r15334) --- src/live_effects/lpe-mirror_symmetry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 07c9f6f99..dcb4f4c99 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -44,8 +44,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), //TODO: Fix htip for multilang - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), - end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring"), + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), center_point("hidden","hidden", "center_point", &wr, this, "hidden") { show_orig_path = true; -- cgit v1.2.3 From 5ba49eaa5621b2e232f8df179798a1b2b282890c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 19 Dec 2016 19:00:54 +0100 Subject: Add update_helperpaths not member of nodetool class to easy call from outside (bzr r15335) --- src/live_effects/effect.cpp | 9 +-------- src/live_effects/lpe-knot.cpp | 1 - src/live_effects/lpe-simplify.cpp | 6 +----- 3 files changed, 2 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 41b7d8c2c..4458c3a20 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -660,14 +660,7 @@ Effect::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector(desktop->event_context); - nt->update_helperpath(); - } - } + Inkscape::UI::Tools::sp_update_helperpath(); } /** diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index c35da0601..7c6882f30 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -20,7 +20,6 @@ #include "knot-holder-entity.h" #include "knotholder.h" -#include #include #include <2geom/sbasis-to-bezier.h> diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 8bdb19b4f..5de9816bb 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -140,11 +140,7 @@ LPESimplify::doEffect(SPCurve *curve) Geom::PathVector result = Geom::parse_svg_path(pathliv->svg_dump_path()); generateHelperPathAndSmooth(result); curve->set_pathvector(result); - SPDesktop* desktop = SP_ACTIVE_DESKTOP; - if(desktop && INK_IS_NODE_TOOL(desktop->event_context)) { - Inkscape::UI::Tools::NodeTool *nt = static_cast(desktop->event_context); - nt->update_helperpath(); - } + Inkscape::UI::Tools::sp_update_helperpath(); } void -- cgit v1.2.3 From 952eb10b1e00f0e4abfbf8dd23fcb3935019f098 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 19 Dec 2016 21:54:42 +0100 Subject: Remove some ocurrences of desktop in knot functions (bzr r15337) --- src/live_effects/effect.cpp | 6 +++--- src/live_effects/effect.h | 4 ++-- src/live_effects/lpe-knot.cpp | 4 ++-- src/live_effects/lpe-knot.h | 2 +- src/live_effects/lpe-patternalongpath.cpp | 4 ++-- src/live_effects/lpe-patternalongpath.h | 2 +- src/live_effects/lpe-perspective_path.cpp | 5 ++--- src/live_effects/lpe-perspective_path.h | 2 +- src/live_effects/lpe-skeleton.cpp | 4 ++-- src/live_effects/lpe-skeleton.h | 2 +- src/live_effects/lpe-spiro.cpp | 2 -- src/live_effects/lpe-tangent_to_curve.cpp | 8 ++++---- src/live_effects/lpe-tangent_to_curve.h | 2 +- src/live_effects/lpe-taperstroke.cpp | 6 +++--- src/live_effects/lpe-taperstroke.h | 2 +- src/live_effects/parameter/filletchamferpointarray.cpp | 8 ++------ src/live_effects/parameter/filletchamferpointarray.h | 3 +-- src/live_effects/parameter/parameter.h | 2 +- src/live_effects/parameter/point.cpp | 12 ++++-------- src/live_effects/parameter/point.h | 2 +- src/live_effects/parameter/powerstrokepointarray.cpp | 4 ++-- src/live_effects/parameter/powerstrokepointarray.h | 2 +- src/live_effects/parameter/vector.cpp | 7 +++---- src/live_effects/parameter/vector.h | 2 +- 24 files changed, 42 insertions(+), 55 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 4458c3a20..5cc0d6f20 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -612,15 +612,15 @@ Effect::registerParameter(Parameter * param) * Add all registered LPE knotholder handles to the knotholder */ void -Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +Effect::addHandles(KnotHolder *knotholder, SPItem *item) { using namespace Inkscape::LivePathEffect; // add handles provided by the effect itself - addKnotHolderEntities(knotholder, desktop, item); + addKnotHolderEntities(knotholder, item); // add handles provided by the effect's parameters (if any) for (std::vector::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->addKnotHolderEntities(knotholder, desktop, item); + (*p)->addKnotHolderEntities(knotholder, item); } } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 06aa075eb..1997ff0ca 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -100,7 +100,7 @@ public: // /TODO: in view of providesOwnFlashPaths() below, this is somewhat redundant // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } - void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addHandles(KnotHolder *knotholder, SPItem *item); std::vector getCanvasIndicators(SPLPEItem const* lpeitem); void update_helperpath(); @@ -142,7 +142,7 @@ protected: void registerParameter(Parameter * param); Parameter * getNextOncanvasEditableParam(); - virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPDesktop * /*desktop*/, SPItem * /*item*/) {}; + virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 7c6882f30..2defecb77 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -615,10 +615,10 @@ LPEKnot::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vectorcreate( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Drag to select a crossing, click to flip it") ); knotholder->add(e); }; diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h index 95bfaf6e1..ac518b97c 100644 --- a/src/live_effects/lpe-knot.h +++ b/src/live_effects/lpe-knot.h @@ -61,7 +61,7 @@ public: /* the knotholder entity classes must be declared friends */ friend class KnotHolderEntityCrossingSwitcher; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 9cfeffee7..e5c9f1be1 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -275,10 +275,10 @@ LPEPatternAlongPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vect void -LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new WPAP::KnotHolderEntityWidthPatternAlongPath(this); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(e); } diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 3d7fc02bc..c34a9a15d 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -43,7 +43,7 @@ public: void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); PathParam pattern; diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 2c6d66cee..979b6dea5 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -18,7 +18,6 @@ #include "live_effects/lpeobject.h" #include "knot-holder-entity.h" #include "knotholder.h" -#include "desktop.h" #include // TODO due to internal breakage in glibmm headers, this must be last: @@ -243,9 +242,9 @@ LPEPerspectivePath::newWidget() return dynamic_cast(vbox); } -void LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +void LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new PP::KnotHolderEntityOffset(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the origin") ); knotholder->add(e); }; diff --git a/src/live_effects/lpe-perspective_path.h b/src/live_effects/lpe-perspective_path.h index c4ddf1853..87ee453ff 100644 --- a/src/live_effects/lpe-perspective_path.h +++ b/src/live_effects/lpe-perspective_path.h @@ -41,7 +41,7 @@ public: virtual Gtk::Widget * newWidget(); /* the knotholder entity classes must be declared friends */ friend class PP::KnotHolderEntityOffset; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: // add the parameters for your effect here: diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index adc4a3493..4fc18cee2 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -97,10 +97,10 @@ public: } // namespace Skeleton void -LPESkeleton::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +LPESkeleton::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { { KnotHolderEntityMyHandle *e = new KnotHolderEntityMyHandle(this); - e->create( desktop, item, knotholder, + e->create( NULL, item, knotholder, _("Text describing what this handle does"), //optional: knot_shape, knot_mode, knot_color); knotholder->add(e); diff --git a/src/live_effects/lpe-skeleton.h b/src/live_effects/lpe-skeleton.h index 3b45b6978..e633ba5ab 100644 --- a/src/live_effects/lpe-skeleton.h +++ b/src/live_effects/lpe-skeleton.h @@ -41,7 +41,7 @@ public: /* the knotholder entity classes (if any) can be declared friends */ //friend class Skeleton::KnotHolderEntityMyHandle; - //virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + //virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: // add the parameters for your effect here: diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 4a41dc5a0..8ea57bee4 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -16,8 +16,6 @@ // For handling un-continuous paths: #include "message-stack.h" #include "inkscape.h" -#include "desktop.h" - namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 76d4ea71b..5f63e1ee9 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -92,22 +92,22 @@ LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise > const } void -LPETangentToCurve::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +LPETangentToCurve::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { { KnotHolderEntity *e = new TtC::KnotHolderEntityAttachPt(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the point of attachment of the tangent") ); knotholder->add(e); } { KnotHolderEntity *e = new TtC::KnotHolderEntityLeftEnd(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the left end of the tangent") ); knotholder->add(e); } { KnotHolderEntity *e = new TtC::KnotHolderEntityRightEnd(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create( NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the right end of the tangent") ); knotholder->add(e); } diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h index 8e44c01d1..a6a3c17ca 100644 --- a/src/live_effects/lpe-tangent_to_curve.h +++ b/src/live_effects/lpe-tangent_to_curve.h @@ -41,7 +41,7 @@ public: friend class TtC::KnotHolderEntityLeftEnd; friend class TtC::KnotHolderEntityRightEnd; friend class TtC::KnotHolderEntityAttachPt; - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); private: ScalarParam angle; diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index 4ffc41691..f4a81aa90 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -435,14 +435,14 @@ Piecewise > stretch_along(Piecewise > pwd2_in, Geom::Path } } -void LPETaperStroke::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +void LPETaperStroke::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { KnotHolderEntity *e = new TpS::KnotHolderEntityAttachBegin(this); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Start point of the taper"), SP_KNOT_SHAPE_CIRCLE); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Start point of the taper"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(e); KnotHolderEntity *f = new TpS::KnotHolderEntityAttachEnd(this); - f->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("End point of the taper"), SP_KNOT_SHAPE_CIRCLE); + f->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("End point of the taper"), SP_KNOT_SHAPE_CIRCLE); knotholder->add(f); } diff --git a/src/live_effects/lpe-taperstroke.h b/src/live_effects/lpe-taperstroke.h index 88604486e..e3ecbb56c 100644 --- a/src/live_effects/lpe-taperstroke.h +++ b/src/live_effects/lpe-taperstroke.h @@ -36,7 +36,7 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const& path_in); Geom::PathVector doEffect_simplePath(Geom::PathVector const& path_in); - virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item); friend class TpS::KnotHolderEntityAttachBegin; friend class TpS::KnotHolderEntityAttachEnd; diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index b321a5831..7696288b0 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -24,7 +24,6 @@ #include "selection.h" // needed for on-canvas editting: -#include "desktop.h" #include "live_effects/lpeobject.h" #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" @@ -825,10 +824,7 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_set_offset( this->parent_holder->knot_ungrabbed_handler(this->knot, 0); } -void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ +void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { recalculate_knots(get_pwd2()); for (unsigned int i = 0; i < _vector.size(); ++i) { if (_vector[i][Y] <= 0) { @@ -854,7 +850,7 @@ void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } FilletChamferPointArrayParamKnotHolderEntity *e = new FilletChamferPointArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), knot_shape, knot_mode, knot_color); knotholder->add(e); } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index 48cd26d2d..b81339a69 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -59,8 +59,7 @@ public: return true; } virtual void updateCanvasIndicators(); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); void set_pwd2(Geom::Piecewise > const &pwd2_in, Geom::Piecewise > const &pwd2_normal_in); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 5dbcb7868..6cf10710c 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -68,7 +68,7 @@ public: // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths virtual bool providesKnotHolderEntities() const { return false; } - virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPDesktop */*desktop*/, SPItem */*item*/) {}; + virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPItem */*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector &/*hp_vec*/) {}; virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 3442fd851..c87b1e299 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -15,9 +15,6 @@ #include "knotholder.h" #include -// needed for on-canvas editting: -#include "desktop.h" - namespace Inkscape { namespace LivePathEffect { @@ -126,9 +123,8 @@ PointParam::param_newWidget() *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(); + Geom::Affine transf = Geom::Scale(1, -1); + transf[5] = SP_ACTIVE_DOCUMENT->getHeight().value("px"); _pointwdg->setTransform(transf); _pointwdg->setValue( *this ); _pointwdg->clearProgrammatically(); @@ -205,12 +201,12 @@ PointParamKnotHolderEntity::knot_click(guint state) } void -PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { knoth = knotholder; PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(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); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color); knotholder->add(e); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 62c6fb83d..e8cb66225 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -49,7 +49,7 @@ public: 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); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); friend class PointParamKnotHolderEntity; private: diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index c61e8f9cb..7753d819d 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -248,11 +248,11 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) } } -void PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +void PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { PowerStrokePointArrayParamKnotHolderEntity *e = new PowerStrokePointArrayParamKnotHolderEntity(this, i); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Stroke width control point: drag to alter the stroke width. Ctrl+click adds a control point, Ctrl+Alt+click deletes it, Shift+click launches width dialog."), knot_shape, knot_mode, knot_color); knotholder->add(e); diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 70b22e27e..56a609fa8 100644 --- a/src/live_effects/parameter/powerstrokepointarray.h +++ b/src/live_effects/parameter/powerstrokepointarray.h @@ -38,7 +38,7 @@ public: float median_width(); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); void set_pwd2(Geom::Piecewise > const & pwd2_in, Geom::Piecewise > const & pwd2_normal_in); Geom::Piecewise > const & get_pwd2() const { return last_pwd2; } diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index cfaa9e7e7..aa16a2b98 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -14,7 +14,6 @@ #include "svg/stringstream.h" #include "live_effects/effect.h" -#include "desktop.h" #include "verbs.h" namespace Inkscape { @@ -188,14 +187,14 @@ private: }; void -VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { VectorParamKnotHolderEntity_Origin *origin_e = new VectorParamKnotHolderEntity_Origin(this); - origin_e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color); + origin_e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color); knotholder->add(origin_e); VectorParamKnotHolderEntity_Vector *vector_e = new VectorParamKnotHolderEntity_Vector(this); - vector_e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color); + vector_e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color); knotholder->add(vector_e); } diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index 35ca04437..edee4ff4d 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -53,7 +53,7 @@ public: void set_oncanvas_color(guint32 color); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); private: VectorParam(const VectorParam&); -- cgit v1.2.3 From 69c944a3622fe17cddb8caa4a515b7535807d1bd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 19 Dec 2016 22:59:28 +0100 Subject: Fix minor bug (bzr r15295.1.30) --- src/live_effects/lpe-mirror_symmetry.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 65177579d..f2238eab6 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -375,6 +375,7 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { + SPDocument * document = SP_ACTIVE_DOCUMENT; for (std::vector::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it) { const char * id = *el_it; -- cgit v1.2.3 From c730bf957bfaee8246577dda57378dd65e40a342 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 20 Dec 2016 01:12:41 +0100 Subject: Fix strings in mirror symetry and copy rotate LPE (bzr r15338) --- src/live_effects/lpe-copy_rotate.cpp | 10 +++++----- src/live_effects/lpe-mirror_symmetry.cpp | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 0492b12d6..72896c1ae 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -39,11 +39,11 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), - origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this), - starting_point("hidden", "hidden", "starting_point", &wr, this), - starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), - rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), - num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), + origin(_("Origin"), _("Adjust origin of the rotation"), "origin", &wr, this, _("Adjust origin of the rotation")), + starting_point(_("Start point"), _("Starting point to define start angle"), "starting_point", &wr, this, _("Adjust starting point to define start angle")), + starting_angle(_("Starting angle"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), + rotation_angle(_("Rotation angle"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), + num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), fuse_paths(_("Fuse paths"), _("Fuse paths by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), dist_angle_handle(100.0) diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index dcb4f4c99..303539ee4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -40,13 +40,12 @@ MTConverter(ModeTypeData, MT_END); LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), - discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), + discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - //TODO: Fix htip for multilang start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point("hidden","hidden", "center_point", &wr, this, "hidden") + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { show_orig_path = true; registerParameter(&mode); -- cgit v1.2.3 From 858a09bfb1b8541ecd0b91584b65e351015318bd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 20 Dec 2016 01:19:03 +0100 Subject: Remove string from tip (bzr r15339) --- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 303539ee4..624bdaf12 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -43,7 +43,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) { -- cgit v1.2.3 From 440735f0a9b66cf638e3932c456a8fbfe214e2cd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 20 Dec 2016 01:29:00 +0100 Subject: Fix strings in mirror symetry and copy rotate LPE (bzr r15295.1.31) --- src/live_effects/lpe-mirror_symmetry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f2238eab6..744ab58e5 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -57,10 +57,10 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), - start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust the start of mirroring")), + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), - id_origin("hidden", "hidden store the id of the first LPEItem", "id_origin", &wr, this,"") + id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,"") { show_orig_path = true; registerParameter(&mode); -- cgit v1.2.3 From 3d61abda24d5b63539ef4c73470e7099fb5597af Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 20 Dec 2016 13:03:44 +0100 Subject: Fix undo incosistences in mirror LPE and in copy rotate LPE (bzr r15340) --- src/live_effects/lpe-copy_rotate.cpp | 4 ++-- src/live_effects/lpe-mirror_symmetry.cpp | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 72896c1ae..153be031e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -113,7 +113,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); - origin.param_setValue(A); + origin.param_setValue(A, true); origin.param_update_default(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); @@ -171,7 +171,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; if (near) { - starting_point.param_setValue(start_pos); + starting_point.param_setValue(start_pos, true); } previous_start_point = (Geom::Point)starting_point; if ( fuse_paths || copies_to_360 ) { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 624bdaf12..9a6fb05dd 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -103,6 +103,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); + //center_point->param_set_liveupdate(false); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); @@ -114,16 +115,20 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } - if (Geom::are_near((Geom::Point)start_point, (Geom::Point)end_point, 0.01)) { - start_point.param_setValue(point_a); - end_point.param_setValue(point_b); + if ((Geom::Point)start_point == (Geom::Point)end_point && (Geom::Point)start_point == Geom::Point(0,0)) { + start_point.param_setValue(point_a, true); + end_point.param_setValue(point_b, true); + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + center_point.param_setValue(previous_center, true); } if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a, true); end_point.param_setValue(point_b, true); } else if ( mode == MT_FREE) { - if(!are_near(previous_center,center_point, 0.01)) { - Geom::Point trans = center_point - previous_center; + if (are_near(previous_center, (Geom::Point)center_point, 0.01)) { + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + } else { + Geom::Point trans = center_point - Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); start_point.param_setValue(start_point * trans, true); end_point.param_setValue(end_point * trans, true); } @@ -150,10 +155,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(ep, true); } } - previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - if (!are_near(previous_center, center_point,0.01)) { - center_point.param_setValue(previous_center); + if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); } + previous_center = center_point; } void @@ -181,7 +186,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b, true); end_point.param_update_default(point_b); - center_point.param_setValue(point_c); + center_point.param_setValue(point_c, true); previous_center = center_point; } -- cgit v1.2.3 From 96595dc7172f8ed98247ce94bd5a596927bae59c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 20 Dec 2016 21:51:48 +0100 Subject: Remove more SPDesktop from LPE's (bzr r15344) --- src/live_effects/lpe-mirror_symmetry.cpp | 37 +++++++++++++++----------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 9a6fb05dd..5b405e3ac 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -124,6 +124,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) if ( mode == MT_X || mode == MT_Y ) { start_point.param_setValue(point_a, true); end_point.param_setValue(point_b, true); + center_point.param_setValue(Geom::middle_point(point_a, point_b), true); } else if ( mode == MT_FREE) { if (are_near(previous_center, (Geom::Point)center_point, 0.01)) { center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); @@ -133,27 +134,23 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) end_point.param_setValue(end_point * trans, true); } } else if ( mode == MT_V){ - if(SP_ACTIVE_DESKTOP){ - SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); - Geom::Rect view_box_rect = doc->getViewBox(); - Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); - sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - start_point.param_setValue(sp, true); - Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); - ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - end_point.param_setValue(ep, true); - } + SPDocument * document = SP_ACTIVE_DOCUMENT; + Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); + Geom::Point sp = Geom::Point(document->getWidth().value("px")/2.0, 0) * transform; + start_point.param_setValue(sp, true); + Geom::Point ep = Geom::Point(document->getWidth().value("px")/2.0, document->getHeight().value("px")) * transform; + end_point.param_setValue(ep, true); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + previous_center = center_point; } else { //horizontal page - if(SP_ACTIVE_DESKTOP){ - SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); - Geom::Rect view_box_rect = doc->getViewBox(); - Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); - sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - start_point.param_setValue(sp, true); - Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); - ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); - end_point.param_setValue(ep, true); - } + SPDocument * document = SP_ACTIVE_DOCUMENT; + Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); + Geom::Point sp = Geom::Point(0, document->getHeight().value("px")/2.0) * transform; + start_point.param_setValue(sp, true); + Geom::Point ep = Geom::Point(document->getWidth().value("px"), document->getHeight().value("px")/2.0) * transform; + end_point.param_setValue(ep, true); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + previous_center = center_point; } if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); -- cgit v1.2.3 From ec04b9e4c0e94f38b56321ef073f9a8671a1a9a8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 26 Dec 2016 10:14:15 +0100 Subject: Fixes bug #1652465 on mirror and copy rotate LPE. Fixed bugs: - https://launchpad.net/bugs/1652465 (bzr r15356) --- src/live_effects/lpe-copy_rotate.cpp | 10 +++------- src/live_effects/lpe-mirror_symmetry.cpp | 18 ++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 153be031e..3dd35696a 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -50,8 +50,6 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : { show_orig_path = true; _provides_knotholder_entities = true; - apply_to_clippath_and_mask = true; - // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); registerParameter(&fuse_paths); @@ -63,6 +61,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies.param_make_integer(true); num_copies.param_set_range(0, 1000); + apply_to_clippath_and_mask = true; } LPECopyRotate::~LPECopyRotate() @@ -170,17 +169,14 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) } start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; - if (near) { + near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); + if (!near) { starting_point.param_setValue(start_pos, true); } previous_start_point = (Geom::Point)starting_point; if ( fuse_paths || copies_to_360 ) { rot_pos = origin; } - - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } void diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 5b405e3ac..f7881fb2e 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -55,8 +55,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &start_point); registerParameter( &end_point); registerParameter( ¢er_point); - apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); + apply_to_clippath_and_mask = true; } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -115,16 +115,19 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } - if ((Geom::Point)start_point == (Geom::Point)end_point && (Geom::Point)start_point == Geom::Point(0,0)) { + if ((Geom::Point)start_point == (Geom::Point)end_point) { start_point.param_setValue(point_a, true); end_point.param_setValue(point_b, true); previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); center_point.param_setValue(previous_center, true); + return; } if ( mode == MT_X || mode == MT_Y ) { - start_point.param_setValue(point_a, true); - end_point.param_setValue(point_b, true); - center_point.param_setValue(Geom::middle_point(point_a, point_b), true); + if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { + start_point.param_setValue(point_a, true); + end_point.param_setValue(point_b, true); + center_point.param_setValue(Geom::middle_point(point_a, point_b), true); + } } else if ( mode == MT_FREE) { if (are_near(previous_center, (Geom::Point)center_point, 0.01)) { center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); @@ -141,7 +144,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(document->getWidth().value("px")/2.0, document->getHeight().value("px")) * transform; end_point.param_setValue(ep, true); center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); - previous_center = center_point; } else { //horizontal page SPDocument * document = SP_ACTIVE_DOCUMENT; Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); @@ -150,10 +152,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point ep = Geom::Point(document->getWidth().value("px"), document->getHeight().value("px")/2.0) * transform; end_point.param_setValue(ep, true); center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); - previous_center = center_point; - } - if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); } previous_center = center_point; } -- cgit v1.2.3 From 0f1a4f260fe919cc77033cf62b9d15a330f32ab5 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 26 Dec 2016 10:24:58 +0100 Subject: fixing things (bzr r15295.1.38) --- src/live_effects/lpe-mirror_symmetry.cpp | 100 ++++++++++++++++++------------- src/live_effects/lpe-mirror_symmetry.h | 1 + 2 files changed, 58 insertions(+), 43 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index aedb4e11f..5464c2bad 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -26,6 +26,7 @@ #include "2geom/path-intersection.h" #include "2geom/affine.h" #include "helper/geom.h" +#include "sp-lpe-item.h" #include "uri.h" #include "uri-references.h" #include "path-chemistry.h" @@ -87,9 +88,31 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() { } +bool +LPEMirrorSymmetry::isCurrentLPEItem() { + if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { + Inkscape::Selection *sel = desktop->getSelection(); + if ( sel && !sel->isEmpty()) { + SPItem *item = sel->singleItem(); + if (item) { + if(sp_lpe_item && std::strcmp(sp_lpe_item->getId(),item->getId()) == 0) { + return true; + } + } + } + } + return false; +} + void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { + std::cout << sp_lpe_item->getId() << "111111111111111111111111111111\n"; + std::cout << lpeitem->getId() << "22222222222222222222222222222222222222222\n"; + if (!isCurrentLPEItem()) { + return; + } + std::cout << "dgagsdgsdgsdgsdgsdgsdgsdgsd\n"; last_transform = Geom::identity(); if (split_elements) { if (discard_orig_path) { @@ -126,6 +149,7 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) // m = m * m1; m = m * sp_lpe_item->transform; // if (std::strcmp(sp_lpe_item->getId(), origin) != 0) { +std::cout << m << "m\n"; createMirror(m); // } else { // createMirror(sp_lpe_item, m, mirror); @@ -140,19 +164,12 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty()) { - SPItem *item = sel->singleItem(); - if (item) { - if(std::strcmp(sp_lpe_item->getId(),item->getId()) != 0) { - return; - } - } - } - } + using namespace Geom; original_bbox(lpeitem); + if (!isCurrentLPEItem()) { + return; + } //center_point->param_set_liveupdate(false); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); @@ -164,7 +181,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_a = Geom::Point(center_point[X],boundingbox_Y.min()); point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } - if ((Geom::Point)start_point == (Geom::Point)end_point && (Geom::Point)start_point == Geom::Point(0,0)) { + if ((Geom::Point)start_point == (Geom::Point)end_point) { start_point.param_setValue(point_a, true); end_point.param_setValue(point_b, true); previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); @@ -274,16 +291,9 @@ LPEMirrorSymmetry::createMirror(Geom::Affine transform) { SPDocument * document = SP_ACTIVE_DOCUMENT; const char * id_origin_char = id_origin.param_getSVGValue(); - const char * mirror = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); - const char * elemref_id; - if (std::strcmp(sp_lpe_item->getId(), mirror) == 0) { - elemref_id = id_origin_char; - } else { - elemref_id = mirror; - } + const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); elements.clear(); - elements.push_back(id_origin_char); - elements.push_back(mirror); + elements.push_back(elemref_id); Inkscape::XML::Document *xml_doc = document->getReprDoc(); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; @@ -297,14 +307,16 @@ LPEMirrorSymmetry::createMirror(Geom::Affine transform) elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "inkscape:original-d", "d", "inkscape:path-effect", NULL); //NULL required + cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d", NULL); //NULL required //transform *= last_transform; //if (transform != Geom::identity()) { - if (elemref_id == mirror) { - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - } else { - sp_lpe_item->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - } + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + Inkscape::LivePathEffect::LPEObjectReference* lperef = SP_LPE_ITEM(elemref)->getCurrentLPEReference(); + if (lperef) { + PathEffectList * new_list = SP_LPE_ITEM(elemref)->path_effect_list; + new_list->remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list + elemref->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); + } //} if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -331,7 +343,7 @@ LPEMirrorSymmetry::newWidget() while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter * param = *it; - if (param->param_key == "id_origin") { + if (param->param_key == "id_origin" || param->param_key == "center_point") { ++it; continue; } @@ -432,21 +444,23 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { - Parameter * param = *it; - param->param_transform_multiply(postmul, set); + if (isCurrentLPEItem()) { + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); + } + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + + // Geom::Affine m = Geom::identity(); + // m *= sp_lpe_item->transform; + // m *= postmul; + // sp_lpe_item->transform = m; + //last_transform *= postmul; + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); + // if (other) { + // sp_lpe_item_update_patheffect(SP_LPE_ITEM(other), false, false); + // } } - previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - -// Geom::Affine m = Geom::identity(); -// m *= sp_lpe_item->transform; -// m *= postmul; -// sp_lpe_item->transform = m; - last_transform *= postmul; - sp_lpe_item_update_patheffect(sp_lpe_item, false, false); -// if (other) { -// sp_lpe_item_update_patheffect(SP_LPE_ITEM(other), false, false); -// } } @@ -477,7 +491,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { - if (split_elements && !fuse_paths) { + if (split_elements && !fuse_paths || !isCurrentLPEItem()) { return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index b05871cd0..765f2740f 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -50,6 +50,7 @@ public: virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); void createMirror(Geom::Affine transform); + bool isCurrentLPEItem(); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); -- cgit v1.2.3 From 98d830e63a7900ff0a47151ba25c3d0bd10eba1a Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 26 Dec 2016 13:54:09 +0100 Subject: Fixes problem on mirror symmetry last commit. (bzr r15358) --- src/live_effects/lpe-mirror_symmetry.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f7881fb2e..61b2b8b5c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -124,9 +124,25 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } if ( mode == MT_X || mode == MT_Y ) { if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { - start_point.param_setValue(point_a, true); - end_point.param_setValue(point_b, true); center_point.param_setValue(Geom::middle_point(point_a, point_b), true); + end_point.param_setValue(point_b, true); + start_point.param_setValue(point_a, true); + } else { + if ( mode == MT_X ) { + if (!are_near(start_point[X], point_a[X], 0.01)) { + start_point.param_setValue(point_a, true); + } + if (!are_near(end_point[X], point_b[X], 0.01)) { + end_point.param_setValue(point_b, true); + } + } else { //MT_Y + if (!are_near(start_point[Y], point_a[Y], 0.01)) { + start_point.param_setValue(point_a, true); + } + if (!are_near(end_point[Y], point_b[Y], 0.01)) { + end_point.param_setValue(point_b, true); + } + } } } else if ( mode == MT_FREE) { if (are_near(previous_center, (Geom::Point)center_point, 0.01)) { -- cgit v1.2.3 From 223ba2e5e0060a4fef243fb3249c946168698e59 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 26 Dec 2016 23:00:38 +0000 Subject: Fix header inclusion ordering (bzr r15365) --- src/live_effects/lpe-measure-line.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 565644c07..c69921a4d 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -11,6 +11,9 @@ */ #include "live_effects/effect.h" + +#include + #include "live_effects/parameter/enum.h" #include "live_effects/parameter/fontbutton.h" #include "live_effects/parameter/text.h" -- cgit v1.2.3 From 9144e83f27ca6ad76ec6d72a8426ebd76c63a6a5 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Tue, 27 Dec 2016 01:27:19 +0000 Subject: Rm some deprecated Gtk::Stock usage (bzr r15366) --- src/live_effects/lpe-perspective-envelope.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index e834c0e86..e0dac0687 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -408,7 +408,8 @@ LPEPerspectiveEnvelope::newWidget() vbox->pack_start(*hbox_middle, false, true, 2); vbox->pack_start(*hbox_down_handles, true, true, 2); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); - Gtk::Button* reset_button = Gtk::manage(new Gtk::Button(Gtk::Stock::CLEAR)); + Gtk::Button* reset_button = Gtk::manage(new Gtk::Button(_("_Clear"), true)); + reset_button->set_image_from_icon_name("edit-clear"); reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPEPerspectiveEnvelope::resetGrid)); reset_button->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); @@ -540,4 +541,4 @@ LPEPerspectiveEnvelope::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::v fill-column:99 End: */ -// vim: file_type=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3 From 50714133d92da517b5185385ea4c553408c80e54 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 28 Dec 2016 09:42:19 +0100 Subject: First attemp working (bzr r15356.1.1) --- src/live_effects/CMakeLists.txt | 6 ++ src/live_effects/effect.cpp | 10 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-clone-original.cpp | 169 ++++++++++++++++++++++++++++++-- src/live_effects/lpe-clone-original.h | 20 +++- 5 files changed, 190 insertions(+), 16 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 784317090..5ffccc7c0 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -60,6 +60,9 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp parameter/filletchamferpointarray.cpp + parameter/item-reference.cpp + parameter/item.cpp + parameter/originalitem.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp parameter/parameter.cpp @@ -142,6 +145,9 @@ set(live_effects_SRC parameter/bool.h parameter/enum.h parameter/filletchamferpointarray.h + parameter/item.h + parameter/item-reference.h + parameter/originalitem.h parameter/originalpath.h parameter/originalpatharray.h parameter/parameter.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 5cc0d6f20..cfd393b87 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -116,7 +116,7 @@ const Util::EnumData LPETypeData[] = { {RULER, N_("Ruler"), "ruler"}, /* 0.91 */ {POWERSTROKE, N_("Power stroke"), "powerstroke"}, - {CLONE_ORIGINAL, N_("Clone original path"), "clone_original"}, + {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, /* 0.92 */ {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, @@ -457,8 +457,7 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - sp_curve = shape->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector(); + setSPCurve(shape->getCurve()); } doBeforeEffect(lpeitem); if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { @@ -468,6 +467,11 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } +void Effect::setSPCurve(SPCurve *curve) +{ + sp_curve = curve; + pathvector_before_effect = curve->get_pathvector(); +} /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of * mouse clicks. This method activates the pen context, which waits for the specified number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1997ff0ca..e975deb05 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,6 +73,7 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); + void setSPCurve(SPCurve *curve); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 10418a02d..be8bc9e0d 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -6,6 +6,11 @@ #include "live_effects/lpe-clone-original.h" #include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include +#include "xml/sp-css-attr.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -14,9 +19,148 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), - linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this) + linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), + preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), + attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), + style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { - registerParameter( dynamic_cast(&linked_path) ); + registerParameter(&linked_item); + registerParameter(&attributes); + registerParameter(&style_attributes); + registerParameter(&preserve_position); + attributes.param_hide_canvas_text(); + style_attributes.param_hide_canvas_text(); + apply_to_clippath_and_mask = true; +} + +void +LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...) +{ + va_list args; + va_start(args, first_attribute); + SPDocument * document = SP_ACTIVE_DOCUMENT; + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneAttrbutes(*obj_it, dest_child, live, first_attribute, args); + index++; + } + } + SPShape * shape_origin = SP_SHAPE(origin); + SPShape * shape_dest = SP_SHAPE(dest); + for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + std::vector elems; + boost::split(elems, att, boost::is_any_of(",")); + for (std::vector::const_iterator atts = elems.begin(); + atts != elems.end(); ++atts) { + const char* attribute = (*atts).c_str(); + if ( std::strcmp(attribute, "transform") == 0 ) { + Geom::Affine affine_dest = Geom::identity(); + sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + if (preserve_position) { + Geom::Affine affine_origin = Geom::identity(); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); + SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin; + } + } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { + SPCurve *c = NULL; + if (std::strcmp(attribute, "d") == 0) { + c = shape_origin->getCurve(); + } else { + c = shape_origin->getCurveBeforeLPE(); + } + if (c) { + Geom::PathVector c_pv = c->get_pathvector(); + if (preserve_position) { + Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); + if (orig_bbox) { + c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); + } + } + c->set_pathvector(c_pv); + shape_dest->setCurveInsync(c, TRUE); + dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + c->unref(); + } else { + dest->getRepr()->setAttribute(attribute, NULL); + } + } else { + dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + } + } + } + va_end(args); +} + +void +LPECloneOriginal::cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...) +{ + va_list args; + va_start(args, first_attribute); + + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneStyleAttrbutes(*obj_it, dest_child, first_attribute, args); + index++; + } + } + SPCSSAttr *css_origin = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style")); + SPCSSAttr *css_dest = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css_dest, dest->getRepr()->attribute("style")); + for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + std::vector elems; + boost::split(elems, att, boost::is_any_of(",")); + for (std::vector::const_iterator atts = elems.begin(); + atts != elems.end(); ++atts) { + const char* attribute = (*atts).c_str(); + const char* origin_attribute = sp_repr_css_property(css_origin, attribute, ""); + if (origin_attribute == "") { + sp_repr_css_set_property (css_dest, attribute, NULL); + } else { + sp_repr_css_set_property (css_dest, attribute, origin_attribute); + } + } + Glib::ustring css_str; + sp_repr_css_write_string(css_dest,css_str); + dest->getRepr()->setAttribute("style", css_str.c_str()); + } + va_end(args); +} + +void +LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ + original_bbox(lpeitem); + if (linked_item.linksToItem() && sp_lpe_item) { + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), NULL); //NULL required + cloneStyleAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), style_attributes.param_getSVGValue(), NULL); //NULL required + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + this->setSPCurve(shape->getCurve()); + } + } +} + +void +LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){ + Glib::ustring attributes_value("d,transform"); + attributes.param_setValue(attributes_value); + attributes.write_to_SVG(); + Glib::ustring style_attributes_value("opacity,border-width"); + style_attributes.param_setValue(style_attributes_value); + style_attributes.write_to_SVG(); +} + +void +LPECloneOriginal::doAfterEffect (SPLPEItem const* lpeitem){ } LPECloneOriginal::~LPECloneOriginal() @@ -26,12 +170,21 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::doEffect (SPCurve * curve) { - if ( linked_path.linksToPath() ) { - Geom::PathVector linked_pathv = linked_path.get_pathvector(); - if ( !linked_pathv.empty() ) { - curve->set_pathvector(linked_pathv); - } - } +// std::vector elems; +// const char * attrs = attributes.param_getSVGValue(); +// boost::split(elems, attrs, boost::is_any_of(",")); +// bool has_d = false; +// for (std::vector::const_iterator atts = elems.begin(); +// atts != elems.end(); ++atts) { +// const char* attribute = (*atts).c_str(); +// if (std::strcmp(attribute, "d") == 0) { +// has_d = true; +// } +// } +// if (linked_item.linksToItem() && has_d) { +// curve->reset(); +// } + curve->set_pathvector(pathvector_before_effect); } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index abf65ded8..148590695 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -10,22 +10,32 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/originalpath.h" +#include "live_effects/parameter/originalitem.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" +#include "live_effects/parameter/text.h" +#include "live_effects/lpegroupbbox.h" namespace Inkscape { namespace LivePathEffect { -class LPECloneOriginal : public Effect { +class LPECloneOriginal : public Effect, GroupBBoxEffect { public: LPECloneOriginal(LivePathEffectObject *lpeobject); virtual ~LPECloneOriginal(); virtual void doEffect (SPCurve * curve); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); + void cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...); private: - OriginalPathParam linked_path; - -private: + OriginalItemParam linked_item; + BoolParam preserve_position; + TextParam attributes; + TextParam style_attributes; LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; -- cgit v1.2.3 From dade3a4aa7da7579145341ee8e63149de053d99a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:39:41 +0100 Subject: Fixing transforms and adding scale (bzr r15356.2.1) --- src/live_effects/lpe-clone-original.cpp | 25 +++++++++++++++++-------- src/live_effects/lpe-clone-original.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index be8bc9e0d..d702e98d5 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -20,14 +20,19 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), + scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { registerParameter(&linked_item); + registerParameter(&scale); registerParameter(&attributes); registerParameter(&style_attributes); registerParameter(&preserve_position); + scale.param_set_range(0.01, 999999.0); + scale.param_set_increments(1, 1); + scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); apply_to_clippath_and_mask = true; @@ -58,13 +63,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co atts != elems.end(); ++atts) { const char* attribute = (*atts).c_str(); if ( std::strcmp(attribute, "transform") == 0 ) { - Geom::Affine affine_dest = Geom::identity(); - sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + Geom::Affine affine_dest = SP_ITEM(dest)->transform; dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + Geom::Affine affine_origin = Geom::identity(); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); if (preserve_position) { - Geom::Affine affine_origin = Geom::identity(); - sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); - SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin; + SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ; } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { SPCurve *c = NULL; @@ -75,11 +79,16 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co } if (c) { Geom::PathVector c_pv = c->get_pathvector(); - if (preserve_position) { - Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox) { + Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); + if (orig_bbox) { + if (preserve_position) { c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); } + if (scale != 100.0) { + double scale_affine = scale/100.0; + Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); + c_pv *= Geom::Translate((*orig_bbox).corner(0)) * scale * Geom::Translate((*orig_bbox).corner(0)).inverse(); + } } c->set_pathvector(c_pv); shape_dest->setCurveInsync(c, TRUE); diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index 148590695..bec835ae1 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -33,6 +33,7 @@ public: private: OriginalItemParam linked_item; + ScalarParam scale; BoolParam preserve_position; TextParam attributes; TextParam style_attributes; -- cgit v1.2.3 From fd45bf5cbe22dddb7b016a3025f3553dbb0f1e27 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:42:27 +0100 Subject: Fixing scale (bzr r15356.2.2) --- src/live_effects/lpe-clone-original.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index d702e98d5..04afe00e2 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -87,7 +87,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); - c_pv *= Geom::Translate((*orig_bbox).corner(0)) * scale * Geom::Translate((*orig_bbox).corner(0)).inverse(); + c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); } } c->set_pathvector(c_pv); -- cgit v1.2.3 From 50fca17129701b09a9049e4469ca39d0c06c15a7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:46:37 +0100 Subject: Fixing scale (bzr r15356.2.3) --- src/live_effects/lpe-clone-original.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 04afe00e2..4ba752b85 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -87,7 +87,11 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); - c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); + if (preserve_position) { + c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)).inverse() * scale * Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); + } else { + c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); + } } } c->set_pathvector(c_pv); -- cgit v1.2.3 From f69e17d45c7311cb8430caa03f4f41be63ac9279 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 29 Dec 2016 21:32:45 +0100 Subject: Add sp_shape to LPE chain and fixing transforms (bzr r15356.1.4) --- src/live_effects/effect.cpp | 41 ++++++++++++++++++++------------- src/live_effects/effect.h | 9 ++++---- src/live_effects/lpe-clone-original.cpp | 33 ++++++++++++++++++-------- src/live_effects/lpe-clone-original.h | 4 +++- 4 files changed, 57 insertions(+), 30 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cfd393b87..81a512d23 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,7 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), - sp_curve(NULL), + sp_shape(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -392,9 +392,9 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector sNP) +Effect::setSelectedNodePoints(std::vector selected_np) { - selectedNodesPoints = sNP; + selected_nodes_points = selected_np; } void @@ -404,16 +404,16 @@ Effect::setCurrentZoom(double cZ) } bool -Effect::isNodePointSelected(Geom::Point const &nodePoint) const +Effect::isNodePointSelected(Geom::Point const &node_point) const { - if (selectedNodesPoints.size() > 0) { + if (selected_nodes_points.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { + for (std::vector::const_iterator i = selected_nodes_points.begin(); + i != selected_nodes_points.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(nodePoint[X],nodePoint[Y]); + Geom::Point p2(node_point[X], node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; @@ -446,20 +446,24 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector();*/ + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + setCurrentShape(shape); + } doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); + //Groups set shape in performPathEffect before each call to doEffect SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - setSPCurve(shape->getCurve()); + setCurrentShape(shape); } + //printf("(SPLPEITEM*) %p\n", sp_lpe_item); doBeforeEffect(lpeitem); + if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); @@ -467,10 +471,15 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } -void Effect::setSPCurve(SPCurve *curve) -{ - sp_curve = curve; - pathvector_before_effect = curve->get_pathvector(); +void Effect::setCurrentShape(SPShape * shape){ + if(shape){ + sp_shape = shape; + if (!(sp_curve = sp_shape->getCurve())) { + // oops + return; + } + pathvector_before_effect = sp_curve->get_pathvector(); + } } /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e975deb05..5dfa3de29 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,8 +73,8 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); - void setSPCurve(SPCurve *curve); - + SPShape * getCurrentShape(){ return sp_shape; }; + void setCurrentShape(SPShape * shape); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, * e.g., waiting for a parameter path either before the effect is created or when it needs a @@ -164,9 +164,10 @@ protected: // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.z + SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. double current_zoom; - std::vector selectedNodesPoints; + std::vector selected_nodes_points; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 7072ad161..8176f3811 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -37,10 +37,12 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); apply_to_clippath_and_mask = true; + preserve_position_changed = !preserve_position; + preserve_affine = Geom::identity(); } void -LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes) +LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { @@ -49,7 +51,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes); + cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes, false); index++; } } @@ -65,7 +67,15 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co Geom::Affine affine_origin = SP_ITEM(origin)->transform; //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); if (preserve_position) { - SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ; + Geom::Affine dest_affine = Geom::identity(); + if (root) { + dest_affine *= Geom::Translate(preserve_affine.translation()); + preserve_affine = Geom::identity(); + } + dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); + dest_affine *= affine_origin; + SP_ITEM(dest)->transform = dest_affine; } else { SP_ITEM(dest)->transform = affine_origin ; } @@ -131,6 +141,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ original_bbox(lpeitem); + if ( preserve_position_changed != preserve_position ) { + if (!preserve_position) { + preserve_affine = SP_ITEM(sp_lpe_item)->transform; + } + preserve_position_changed = preserve_position; + } if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -142,11 +158,7 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_path.param_readSVGValue(""); } if (linked_item.linksToItem()) { - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue()); - SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - this->setSPCurve(shape->getCurve()); - } + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -205,7 +217,10 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::doEffect (SPCurve * curve) { - curve->set_pathvector(pathvector_before_effect); + SPShape * shape = getCurrentShape(); + if(shape){ + curve->set_pathvector(shape->getCurve()->get_pathvector()); + } } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e232135eb..e8a9a7419 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -29,7 +29,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual Gtk::Widget * newWidget(); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: OriginalPathParam linked_path; @@ -38,6 +38,8 @@ private: BoolParam preserve_position; TextParam attributes; TextParam style_attributes; + bool preserve_position_changed; + Geom::Affine preserve_affine; LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; -- cgit v1.2.3 From 1718bfb10a12c22b9f4a9d502e715634c2cc153c Mon Sep 17 00:00:00 2001 From: Ivan Mas??r Date: Fri, 30 Dec 2016 17:11:45 +0100 Subject: fix typos, add translator comment (bzr r15373) --- src/live_effects/lpe-gears.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 17579c64e..dad520041 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -207,7 +207,7 @@ LPEGears::LPEGears(LivePathEffectObject *lpeobject) : Effect(lpeobject), teeth(_("_Teeth:"), _("The number of teeth"), "teeth", &wr, this, 10), phi(_("_Phi:"), _("Tooth pressure angle (typically 20-25 deg). The ratio of teeth not in contact."), "phi", &wr, this, 5), - min_radius(_("Min Radius:"), _("Minimun radius, low balues can slow"), "min_radius", &wr, this, 5.0) + min_radius(_("Min Radius:"), _("Minimum radius, low values can be slow"), "min_radius", &wr, this, 5.0) { /* Tooth pressure angle: The angle between the tooth profile and a perpendicular to the pitch * circle, usually at the point where the pitch circle meets the tooth profile. Standard angles diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index a317a8aa1..af2a8e919 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -52,7 +52,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), - position(_("Positon*"), _("Positon"), "position", &wr, this, 5), + position(_("Position*"), _("Position"), "position", &wr, this, 5), text_top_bottom(_("Text top/bottom*"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), text_right_left(_("Text right/left*"), _("Text right/left"), "text_right_left", &wr, this, 0), helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), -- cgit v1.2.3 From 3c16d15761bac73cba9b81b49efe8e71306a5766 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Dec 2016 19:14:55 +0100 Subject: Fixing clips and masks (bzr r15356.1.6) --- src/live_effects/lpe-clone-original.cpp | 36 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 8176f3811..81e6809f1 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -8,6 +8,8 @@ #include "display/curve.h" #include "svg/path-string.h" #include "svg/svg.h" +#include "sp-clippath.h" +#include "sp-mask.h" #include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: @@ -36,9 +38,9 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); - apply_to_clippath_and_mask = true; preserve_position_changed = !preserve_position; preserve_affine = Geom::identity(); + apply_to_clippath_and_mask = true; } void @@ -60,6 +62,13 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co SPShape * shape_dest = SP_SHAPE(dest); gchar ** attarray = g_strsplit(attributes, ",", 0); gchar ** iter = attarray; +// if (SP_IS_CLIPPATH(SP_ITEM(origin)->parent) || SP_IS_MASK(SP_ITEM(origin)->parent)) { +// Geom::Affine dest_affine = Geom::identity(); +// if (root && preserve_position) { +// dest_affine *= Geom::Translate(preserve_affine.translation()); +// } +// SP_ITEM(SP_ITEM(dest)->parent)->transform = dest_affine; +// } while (*iter != NULL) { const char* attribute = (*iter); if ( std::strcmp(attribute, "transform") == 0 ) { @@ -69,11 +78,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (preserve_position) { Geom::Affine dest_affine = Geom::identity(); if (root) { + std::cout << "root" << preserve_affine.translation() << "\n"; dest_affine *= Geom::Translate(preserve_affine.translation()); - preserve_affine = Geom::identity(); + //preserve_affine = Geom::identity(); + dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); } - dest_affine *= Geom::Translate(affine_dest.translation()); - dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); dest_affine *= affine_origin; SP_ITEM(dest)->transform = dest_affine; } else { @@ -89,7 +99,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox) { + if (orig_bbox && root) { if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Scale scale = Geom::Scale(scale_affine); @@ -141,12 +151,6 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ original_bbox(lpeitem); - if ( preserve_position_changed != preserve_position ) { - if (!preserve_position) { - preserve_affine = SP_ITEM(sp_lpe_item)->transform; - } - preserve_position_changed = preserve_position; - } if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -158,6 +162,16 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_path.param_readSVGValue(""); } if (linked_item.linksToItem()) { + if (preserve_position) { + preserve_affine = SP_ITEM(sp_lpe_item)->transform; + } +// if ( preserve_position_changed != preserve_position ) { +// if (!preserve_position) { +// preserve_affine = SP_ITEM(sp_lpe_item)->transform; +// preserve_affine *= Geom::Translate(SP_ITEM(linked_item.getObject())->transform.translation()).inverse(); +// } +// preserve_position_changed = preserve_position; +// } cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } -- cgit v1.2.3 From 631a285a36f65a5ab6eb0626c0e65ad4c85f1c21 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 31 Dec 2016 02:26:39 +0100 Subject: Not target bug. Fixes a typo in last minute refactor that ignore mirroring in fuse options of rotate copies LPE. The mirror affine is redeclared and not overwited as we need. Also inicializa a value as double in pattern along path (Not Backported) (bzr r15378) --- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-patternalongpath.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3dd35696a..c8f1b9e75 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -259,7 +259,7 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; Geom::Line ls(A,B); - Geom::Affine m = Geom::reflection (ls.vector(), A); + m = Geom::reflection (ls.vector(), A); } else { append_path = original; } diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index e5c9f1be1..c1853ef22 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -63,7 +63,7 @@ static const Util::EnumDataConverter PAPCopyTypeConverter(PAPCopyTy LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : Effect(lpeobject), pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), - original_height(0), + original_height(0.0), prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0), copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"), "copytype", PAPCopyTypeConverter, &wr, this, PAPCT_SINGLE_STRETCHED), -- cgit v1.2.3 From 088070b65c83f9a6a7d1d268e8a794776cc648a8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 1 Jan 2017 03:21:07 +0100 Subject: Fixing transforms,clips... (bzr r15356.1.8) --- src/live_effects/lpe-clone-original.cpp | 150 ++++++++++++++++++++++---------- src/live_effects/lpe-clone-original.h | 5 +- src/live_effects/lpe-copy_rotate.cpp | 1 - 3 files changed, 109 insertions(+), 47 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 81e6809f1..76cc56b8f 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -24,6 +24,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), + use_center(_("Relative center of element"), _("Relative center of element"), "use_center", &wr, this, true), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { @@ -33,14 +34,28 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : registerParameter(&attributes); registerParameter(&style_attributes); registerParameter(&preserve_position); + registerParameter(&use_center); scale.param_set_range(0.01, 999999.0); scale.param_set_increments(1, 1); scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); - preserve_position_changed = !preserve_position; + preserve_position_changed = preserve_position; preserve_affine = Geom::identity(); - apply_to_clippath_and_mask = true; +} + +bool hasLinkedTransform( const char * attributes) { + gchar ** attarray = g_strsplit(attributes, ",", 0); + gchar ** iter = attarray; + bool has_linked_transform = false; + while (*iter != NULL) { + const char* attribute = (*iter); + if ( std::strcmp(attribute, "transform") == 0 ) { + has_linked_transform = true; + } + iter++; + } + return has_linked_transform; } void @@ -53,41 +68,69 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes, false); + cloneAttrbutes((*obj_it), dest_child, live, attributes, style_attributes, false); index++; } } //Attributes SPShape * shape_origin = SP_SHAPE(origin); + SPPath * path_origin = SP_PATH(origin); SPShape * shape_dest = SP_SHAPE(dest); + SPMask *mask_origin = SP_ITEM(origin)->mask_ref->getObject(); + SPMask *mask_dest = SP_ITEM(dest)->mask_ref->getObject(); + if(mask_origin && mask_dest) { + std::vector mask_list = mask_origin->childList(true); + std::vector mask_list_dest = mask_dest->childList(true); + if (mask_list.size() == mask_list_dest.size()) { + size_t i = 0; + for ( std::vector::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) { + SPObject * mask_data = *iter; + SPObject * mask_dest_data = mask_list_dest[i]; + cloneAttrbutes(mask_data, mask_dest_data, live, attributes, style_attributes, false); + i++; + } + } + } + SPClipPath *clippath_origin = SP_ITEM(origin)->clip_ref->getObject(); + SPClipPath *clippath_dest = SP_ITEM(dest)->clip_ref->getObject(); + if(clippath_origin && clippath_dest) { + std::vector clippath_list = clippath_origin->childList(true); + std::vector clippath_list_dest = clippath_dest->childList(true); + if (clippath_list.size() == clippath_list_dest.size()) { + size_t i = 0; + for ( std::vector::const_iterator iter=clippath_list.begin();iter!=clippath_list.end();++iter) { + SPObject * clippath_data = *iter; + SPObject * clippath_dest_data = clippath_list_dest[i]; + cloneAttrbutes(clippath_data, clippath_dest_data, live, attributes, style_attributes, false); + i++; + } + } + } gchar ** attarray = g_strsplit(attributes, ",", 0); gchar ** iter = attarray; -// if (SP_IS_CLIPPATH(SP_ITEM(origin)->parent) || SP_IS_MASK(SP_ITEM(origin)->parent)) { -// Geom::Affine dest_affine = Geom::identity(); -// if (root && preserve_position) { -// dest_affine *= Geom::Translate(preserve_affine.translation()); -// } -// SP_ITEM(SP_ITEM(dest)->parent)->transform = dest_affine; -// } + Geom::Affine affine_dest = Geom::identity(); + Geom::Affine affine_origin = Geom::identity(); + Geom::Affine affine_previous = Geom::identity(); + sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); while (*iter != NULL) { const char* attribute = (*iter); if ( std::strcmp(attribute, "transform") == 0 ) { - Geom::Affine affine_dest = SP_ITEM(dest)->transform; - Geom::Affine affine_origin = SP_ITEM(origin)->transform; - //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); if (preserve_position) { Geom::Affine dest_affine = Geom::identity(); if (root) { - std::cout << "root" << preserve_affine.translation() << "\n"; - dest_affine *= Geom::Translate(preserve_affine.translation()); - //preserve_affine = Geom::identity(); - dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= affine_origin; + if (preserve_affine == Geom::identity()) { + dest_affine *= Geom::Translate(affine_dest.translation()); + } dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); - } - dest_affine *= affine_origin; - SP_ITEM(dest)->transform = dest_affine; + dest_affine *= Geom::Translate(preserve_affine.translation()); + affine_previous = preserve_affine; + preserve_affine = Geom::identity(); + SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(dest_affine)); + } } else { - SP_ITEM(dest)->transform = affine_origin ; + SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(affine_origin)); } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { SPCurve *c = NULL; @@ -99,21 +142,33 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox && root) { + Geom::OptRect dest_bbox = SP_ITEM(dest)->geometricBounds(); + if (dest_bbox && orig_bbox && root) { + Geom::Point orig_point = (*orig_bbox).corner(0); + Geom::Point dest_point = (*dest_bbox).corner(0); + if (use_center) { + orig_point = (*orig_bbox).midpoint(); + dest_point = (*dest_bbox).midpoint(); + } if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Scale scale = Geom::Scale(scale_affine); - c_pv *= Geom::Translate((*orig_bbox).midpoint()).inverse(); + c_pv *= Geom::Translate(orig_point).inverse(); c_pv *= scale; - c_pv *= Geom::Translate((*orig_bbox).midpoint()); + c_pv *= Geom::Translate(orig_point); } - if (preserve_position) { - c_pv *= Geom::Translate(Geom::Point(boundingbox_X.middle(), boundingbox_Y.middle()) - (*orig_bbox).midpoint()); + if (preserve_position && hasLinkedTransform(attributes)) { + c_pv *= Geom::Translate(dest_point - orig_point); } } + c_pv *= i2anc_affine(dest, sp_lpe_item); c->set_pathvector(c_pv); - shape_dest->setCurveInsync(c, TRUE); - dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + if (!path_origin) { + shape_dest->setCurveInsync(c, TRUE); + dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + } else { + shape_dest->setCurve(c, TRUE); + } c->unref(); } else { dest->getRepr()->setAttribute(attribute, NULL); @@ -124,8 +179,6 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co iter++; } g_strfreev (attarray); - - //Style Attributes SPCSSAttr *css_origin = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style")); SPCSSAttr *css_dest = sp_repr_css_attr_new(); @@ -161,17 +214,14 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_item.param_readSVGValue(linked_path.param_getSVGValue()); linked_path.param_readSVGValue(""); } + if (linked_item.linksToItem()) { - if (preserve_position) { - preserve_affine = SP_ITEM(sp_lpe_item)->transform; + if ( preserve_position_changed != preserve_position ) { + if (!preserve_position) { + sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &preserve_affine); + } + preserve_position_changed = preserve_position; } -// if ( preserve_position_changed != preserve_position ) { -// if (!preserve_position) { -// preserve_affine = SP_ITEM(sp_lpe_item)->transform; -// preserve_affine *= Geom::Translate(SP_ITEM(linked_item.getObject())->transform.translation()).inverse(); -// } -// preserve_position_changed = preserve_position; -// } cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -219,7 +269,7 @@ LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){ Glib::ustring attributes_value("d,transform"); attributes.param_setValue(attributes_value); attributes.write_to_SVG(); - Glib::ustring style_attributes_value("opacity,border-width"); + Glib::ustring style_attributes_value("opacity,stroke-width"); style_attributes.param_setValue(style_attributes_value); style_attributes.write_to_SVG(); } @@ -229,11 +279,23 @@ LPECloneOriginal::~LPECloneOriginal() } -void LPECloneOriginal::doEffect (SPCurve * curve) +void +LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) +{ + if (linked_item.linksToItem()) { + bool changed = false; + linked_item.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); + } +} + +void +LPECloneOriginal::doEffect (SPCurve * curve) { - SPShape * shape = getCurrentShape(); - if(shape){ - curve->set_pathvector(shape->getCurve()->get_pathvector()); + if (linked_item.linksToItem()) { + SPShape * shape = getCurrentShape(); + if(shape){ + curve->set_pathvector(shape->getCurve()->get_pathvector()); + } } } diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e8a9a7419..064fe84b2 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -24,10 +24,10 @@ class LPECloneOriginal : public Effect, GroupBBoxEffect { public: LPECloneOriginal(LivePathEffectObject *lpeobject); virtual ~LPECloneOriginal(); - + virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doEffect (SPCurve * curve); virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Gtk::Widget * newWidget(); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); @@ -36,6 +36,7 @@ private: OriginalItemParam linked_item; ScalarParam scale; BoolParam preserve_position; + BoolParam use_center; TextParam attributes; TextParam style_attributes; bool preserve_position_changed; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3dd35696a..aafd2c094 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -122,7 +122,6 @@ void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); -- cgit v1.2.3 From d7651a90c6b180f2587db786ad3d6715dba010bf Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 1 Jan 2017 04:08:02 +0100 Subject: Fix bug/add feature on #1653380 on rotate copies Fixed bugs: - https://launchpad.net/bugs/1653380 (bzr r15382) --- src/live_effects/lpe-copy_rotate.cpp | 23 +++++++++++++++++++++-- src/live_effects/lpe-copy_rotate.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index c8f1b9e75..813f25d3d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -15,6 +15,7 @@ #include #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> +#include <2geom/intersection-graph.h> #include "live_effects/lpe-copy_rotate.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -45,7 +46,8 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fuse_paths(_("Fuse paths"), _("Fuse paths by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), + fuse_paths(_("Kaleidoskope"), _("Kaleidoskope by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), + join_paths(_("Join paths"), _("Join paths, use fill-rule: evenodd for best result"), "join_paths", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -53,6 +55,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); registerParameter(&fuse_paths); + registerParameter(&join_paths); registerParameter(&starting_angle); registerParameter(&starting_point); registerParameter(&rotation_angle); @@ -400,10 +403,26 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p output = paths_to_pw(path_out); } } else { + Geom::PathVector output_pv = path_from_piecewise(output , 0.01); for (int i = 0; i < num_copies; ++i) { Rotate rot(-rad_from_deg(rotation_angle * i)); Affine t = pre * rot * Translate(origin); - output.concat(pwd2_in * t); + if (join_paths) { + Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); + if (pig) { + if (!output_pv.empty()) { + output_pv = pig->getUnion(); + } else { + output_pv = join_pv; + } + } + } else { + output.concat(pwd2_in * t); + } + } + if (join_paths) { + output = paths_to_pw(output_pv); } } return output; diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 8f9fc12ac..c2ae2daf1 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -44,6 +44,7 @@ private: ScalarParam num_copies; BoolParam copies_to_360; BoolParam fuse_paths; + BoolParam join_paths; Geom::Point A; Geom::Point B; Geom::Point dir; -- cgit v1.2.3 From ba0a43458620f76e235fc9d61539582d7887311f Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 2 Jan 2017 00:30:14 +0100 Subject: attemt to mirror (bzr r15356.1.11) --- src/live_effects/lpe-clone-original.cpp | 26 +++++++++++++++++--------- src/live_effects/lpe-clone-original.h | 1 + src/live_effects/parameter/item.cpp | 26 ++++++++++++++++---------- src/live_effects/parameter/originalitem.cpp | 15 +++++++++++++++ src/live_effects/parameter/originalitem.h | 2 ++ 5 files changed, 51 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 76cc56b8f..4fc74b275 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -24,6 +24,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), + inverse(_("Inverse clone"), _("Use LPE item as origin. Destructive"), "inverse", &wr, this, false), use_center(_("Relative center of element"), _("Relative center of element"), "use_center", &wr, this, true), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") @@ -34,6 +35,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : registerParameter(&attributes); registerParameter(&style_attributes); registerParameter(&preserve_position); + registerParameter(&inverse); registerParameter(&use_center); scale.param_set_range(0.01, 999999.0); scale.param_set_increments(1, 1); @@ -132,13 +134,9 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co } else { SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(affine_origin)); } - } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { + } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0)) { SPCurve *c = NULL; - if (std::strcmp(attribute, "d") == 0) { - c = shape_origin->getCurve(); - } else { - c = shape_origin->getCurveBeforeLPE(); - } + c = shape_origin->getCurve(); if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); @@ -161,7 +159,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co c_pv *= Geom::Translate(dest_point - orig_point); } } - c_pv *= i2anc_affine(dest, sp_lpe_item); + if (inverse) { + c_pv *= i2anc_affine(origin, sp_lpe_item); + origin->getRepr()->setAttribute("inkscape:original-d", sp_svg_write_path(c_pv)); + } else { + c_pv *= i2anc_affine(dest, sp_lpe_item); + } c->set_pathvector(c_pv); if (!path_origin) { shape_dest->setCurveInsync(c, TRUE); @@ -203,7 +206,6 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ - original_bbox(lpeitem); if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -222,7 +224,13 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ } preserve_position_changed = preserve_position; } - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); + if (inverse) { + linked_item.param_quit_listening(); + cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); + } else { + linked_item.param_start_listening(linked_item.getObject()); + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); + } } } diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index 064fe84b2..aad6e9fa9 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -36,6 +36,7 @@ private: OriginalItemParam linked_item; ScalarParam scale; BoolParam preserve_position; + BoolParam inverse; BoolParam use_center; TextParam attributes; TextParam style_attributes; diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 8caea4e26..0a46ec7ce 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -135,25 +135,31 @@ ItemParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vectorconnectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); - linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); - if (SP_IS_ITEM(to)) { - linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); + if (!linked_delete_connection.connected() || force) { + std::cout << "111111111111111111\n"; + linked_delete_connection = to->connectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); + linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); + if (SP_IS_ITEM(to)) { + linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); + } + linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated } - linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated } void ItemParam::quit_listening(void) { - linked_modified_connection.disconnect(); - linked_delete_connection.disconnect(); - linked_transformed_connection.disconnect(); + if (linked_delete_connection.connected()) { + std::cout << "2222222222222222222222\n"; + linked_modified_connection.disconnect(); + linked_delete_connection.disconnect(); + linked_transformed_connection.disconnect(); + } } void @@ -161,7 +167,7 @@ ItemParam::ref_changed(SPObject */*old_ref*/, SPObject *new_ref) { quit_listening(); if ( new_ref ) { - start_listening(new_ref); + start_listening(new_ref, true); } } diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index 015fa0bd4..dc7f2d634 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -83,6 +83,21 @@ OriginalItemParam::param_newWidget() return dynamic_cast (_widget); } +void +OriginalItemParam::param_start_listening(SPObject * to) +{ + if ( to == NULL ) { + return; + } + start_listening(to, false); +} + +void +OriginalItemParam::param_quit_listening(void) +{ + quit_listening(); +} + void OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { diff --git a/src/live_effects/parameter/originalitem.h b/src/live_effects/parameter/originalitem.h index 9c67571e8..5478a1e4b 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -26,6 +26,8 @@ public: bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } + void param_start_listening(SPObject * to); + void param_quit_listening(void); virtual Gtk::Widget * param_newWidget(); -- cgit v1.2.3 From de63ebfb86a6908b5aaad019ae1358cdf483ce17 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 2 Jan 2017 01:14:22 +0100 Subject: attemt to mirror (bzr r15295.1.42) --- src/live_effects/lpe-mirror_symmetry.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f83025afc..ba3891529 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -325,12 +325,12 @@ LPEMirrorSymmetry::createMirror(Geom::Affine transform) //transform *= last_transform; //if (transform != Geom::identity()) { elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - Inkscape::LivePathEffect::LPEObjectReference* lperef = SP_LPE_ITEM(elemref)->getCurrentLPEReference(); - if (lperef) { - PathEffectList * new_list = SP_LPE_ITEM(elemref)->path_effect_list; - new_list->remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list - elemref->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); - } +// Inkscape::LivePathEffect::LPEObjectReference* lperef = SP_LPE_ITEM(elemref)->getCurrentLPEReference(); +// if (lperef) { +// PathEffectList * new_list = SP_LPE_ITEM(elemref)->path_effect_list; +// new_list->remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list +// elemref->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); +// } //} if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); -- cgit v1.2.3 From 0a19b6fbad1ada089488541e60f195a0943c01a8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 2 Jan 2017 13:14:36 +0100 Subject: Fix inverse clone (bzr r15356.1.12) --- src/live_effects/lpe-clone-original.cpp | 18 ++++++++++-------- src/live_effects/parameter/item.cpp | 26 ++++++++++---------------- src/live_effects/parameter/originalitem.cpp | 21 ++++----------------- src/live_effects/parameter/originalitem.h | 5 ++--- 4 files changed, 26 insertions(+), 44 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 4fc74b275..33abd685a 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -24,7 +24,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), - inverse(_("Inverse clone"), _("Use LPE item as origin. Destructive"), "inverse", &wr, this, false), + inverse(_("Inverse clone"), _("Use LPE item as origin"), "inverse", &wr, this, false), use_center(_("Relative center of element"), _("Relative center of element"), "use_center", &wr, this, true), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") @@ -136,7 +136,11 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0)) { SPCurve *c = NULL; - c = shape_origin->getCurve(); + if (inverse) { + c = shape_origin->getCurveBeforeLPE(); + } else { + c = shape_origin->getCurve(); + } if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); @@ -155,13 +159,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co c_pv *= scale; c_pv *= Geom::Translate(orig_point); } - if (preserve_position && hasLinkedTransform(attributes)) { + if (preserve_position) { c_pv *= Geom::Translate(dest_point - orig_point); } } if (inverse) { c_pv *= i2anc_affine(origin, sp_lpe_item); - origin->getRepr()->setAttribute("inkscape:original-d", sp_svg_write_path(c_pv)); } else { c_pv *= i2anc_affine(dest, sp_lpe_item); } @@ -218,17 +221,16 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ } if (linked_item.linksToItem()) { - if ( preserve_position_changed != preserve_position ) { + linked_item.setInverse(inverse); + if ( preserve_position_changed != preserve_position ) { if (!preserve_position) { sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &preserve_affine); } preserve_position_changed = preserve_position; } if (inverse) { - linked_item.param_quit_listening(); cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } else { - linked_item.param_start_listening(linked_item.getObject()); cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -299,7 +301,7 @@ LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) void LPECloneOriginal::doEffect (SPCurve * curve) { - if (linked_item.linksToItem()) { + if (linked_item.linksToItem() && !inverse) { SPShape * shape = getCurrentShape(); if(shape){ curve->set_pathvector(shape->getCurve()->get_pathvector()); diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 0a46ec7ce..8caea4e26 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -135,31 +135,25 @@ ItemParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vectorconnectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); - linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); - if (SP_IS_ITEM(to)) { - linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); - } - linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated + linked_delete_connection = to->connectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); + linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); + if (SP_IS_ITEM(to)) { + linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); } + linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated } void ItemParam::quit_listening(void) { - if (linked_delete_connection.connected()) { - std::cout << "2222222222222222222222\n"; - linked_modified_connection.disconnect(); - linked_delete_connection.disconnect(); - linked_transformed_connection.disconnect(); - } + linked_modified_connection.disconnect(); + linked_delete_connection.disconnect(); + linked_transformed_connection.disconnect(); } void @@ -167,7 +161,7 @@ ItemParam::ref_changed(SPObject */*old_ref*/, SPObject *new_ref) { quit_listening(); if ( new_ref ) { - start_listening(new_ref, true); + start_listening(new_ref); } } diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index dc7f2d634..053062128 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -83,26 +83,13 @@ OriginalItemParam::param_newWidget() return dynamic_cast (_widget); } -void -OriginalItemParam::param_start_listening(SPObject * to) -{ - if ( to == NULL ) { - return; - } - start_listening(to, false); -} - -void -OriginalItemParam::param_quit_listening(void) -{ - quit_listening(); -} - void OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { - emit_changed(); - SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + if (!inverse) { + emit_changed(); + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + } } void diff --git a/src/live_effects/parameter/originalitem.h b/src/live_effects/parameter/originalitem.h index 5478a1e4b..58d04e05a 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -23,11 +23,9 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect); virtual ~OriginalItemParam(); - + void setInverse(bool inversed) { inverse = inversed; } bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } - void param_start_listening(SPObject * to); - void param_quit_listening(void); virtual Gtk::Widget * param_newWidget(); @@ -38,6 +36,7 @@ protected: void on_select_original_button_click(); private: + bool inverse; OriginalItemParam(const OriginalItemParam&); OriginalItemParam& operator=(const OriginalItemParam&); }; -- cgit v1.2.3 From f61f13c62dd0c8e87f89492508acfebad6b32f83 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 2 Jan 2017 16:03:00 +0100 Subject: End defining, bug fixing.... (bzr r15295.1.44) --- src/live_effects/lpe-mirror_symmetry.cpp | 85 ++++++----------------------- src/live_effects/lpe-mirror_symmetry.h | 6 +- src/live_effects/parameter/originalitem.cpp | 21 ++++++- src/live_effects/parameter/originalitem.h | 2 +- 4 files changed, 43 insertions(+), 71 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index ba3891529..bd77db53c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -52,18 +52,20 @@ MTConverter(ModeTypeData, MT_END); LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), + mirror_item(_("Mirror item:"), _("Mirror item"), "mirror_item", &wr, this), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, 0), discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Group result to apply nested"), "split_elements", &wr, this, false), + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Whith fuse don't work on shapes"), "split_elements", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,"") { show_orig_path = true; + registerParameter(&mirror_item); registerParameter(&mode); registerParameter(&split_gap); registerParameter(&discard_orig_path); @@ -107,12 +109,9 @@ LPEMirrorSymmetry::isCurrentLPEItem() { void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { - std::cout << sp_lpe_item->getId() << "111111111111111111111111111111\n"; - std::cout << lpeitem->getId() << "22222222222222222222222222222222222222222\n"; if (!isCurrentLPEItem()) { return; } - std::cout << "dgagsdgsdgsdgsdgsdgsdgsdgsd\n"; last_transform = Geom::identity(); if (split_elements) { if (discard_orig_path) { @@ -129,31 +128,11 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) } Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); - // Geom::Point gap(split_gap,0); -// Geom::Translate m1(point_a[0], point_a[1]); -// double hyp = Geom::distance(point_a, point_b); -// double cos = 0; -// double sin = 0; -// if (hyp > 0) { -// cos = (point_b[0] - point_a[0]) / hyp; -// sin = (point_b[1] - point_a[1]) / hyp; -// } -// Geom::Affine m2(cos, -sin, sin, cos, 0.0, 0.0); -// Geom::Point dir = unit_vector(point_b - point_a); -// Geom::Point offset = (point_a + point_b)/2 + Geom::rot90(dir.ccw()) * split_gap; -// line_separation *= Geom::Translate(offset); -// Geom::Scale sca(1.0, -1.0); -// m = m1.inverse() * m2; -// m = m * sca; -// m = m * m2.inverse(); -// m = m * m1; + Geom::Point dir = rot90(unit_vector((Geom::Point)start_point - (Geom::Point)end_point)); + Geom::Point gap = dir * split_gap; + m *= Geom::Translate(gap); m = m * sp_lpe_item->transform; -// if (std::strcmp(sp_lpe_item->getId(), origin) != 0) { -std::cout << m << "m\n"; - createMirror(m); -// } else { -// createMirror(sp_lpe_item, m, mirror); -// } + toMirror(m); } else { processObjects(LPE_ERASE); elements.clear(); @@ -238,44 +217,23 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) previous_center = center_point; } -//void -//LPEMirrorSymmetry::cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...) -//{ -// va_list args; -// va_start(args, first_attribute); - -// if ( origin->name() == "svg:g" && origin->childCount() == dest->childCount() ) { -// Inkscape::XML::Node * node_it = origin->firstChild(); -// size_t index = 0; -// while (node_it != origin->lastChild()) { -// cloneAttrbutes(node_it, dest->nthChild(index), first_attribute, live, args); -// node_it = node_it->next(); -// index++; -// } -// } -// while(const char * att = va_arg(args, const char *)) { -// dest->setAttribute(att,origin->attribute(att)); -// } -// va_end(args); -//} - void -LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...) +LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes) { - va_list args; - va_start(args, first_attribute); - if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); size_t index = 0; for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, first_attribute, args); + cloneAttrbutes(*obj_it, dest_child, live, attributes); index++; } } - for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + gchar ** attarray = g_strsplit(attributes, ",", 0); + gchar ** iter = attarray; + while (*iter != NULL) { + const char* att = (*iter); SPShape * shape = SP_SHAPE(origin); if (shape) { if ( live && (att == "d" || att == "inkscape:original-d")) { @@ -296,12 +254,12 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c dest->getRepr()->setAttribute(att,origin->getRepr()->attribute(att)); } } + iter++; } - va_end(args); } void -LPEMirrorSymmetry::createMirror(Geom::Affine transform) +LPEMirrorSymmetry::toMirror(Geom::Affine transform) { SPDocument * document = SP_ACTIVE_DOCUMENT; const char * id_origin_char = id_origin.param_getSVGValue(); @@ -320,18 +278,11 @@ LPEMirrorSymmetry::createMirror(Geom::Affine transform) if (!elemref) { elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); + mirror_item.param_write(elemref_id); } - cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d", NULL); //NULL required - //transform *= last_transform; - //if (transform != Geom::identity()) { + elemref->getRepr()->setAttribute("inkscape:path-effect", ""); + cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d"); elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); -// Inkscape::LivePathEffect::LPEObjectReference* lperef = SP_LPE_ITEM(elemref)->getCurrentLPEReference(); -// if (lperef) { -// PathEffectList * new_list = SP_LPE_ITEM(elemref)->path_effect_list; -// new_list->remove(lperef); //current lpe ref is always our 'own' pointer from the path_effect_list -// elemref->getRepr()->setAttribute("inkscape:path-effect", patheffectlist_svg_string(new_list)); -// } - //} if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", elemref_id); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 765f2740f..03ff56842 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -17,6 +17,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/originalitem.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" @@ -49,15 +50,16 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - void createMirror(Geom::Affine transform); + void toMirror(Geom::Affine transform); bool isCurrentLPEItem(); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: + OriginalItemParam mirror_item; EnumParam mode; ScalarParam split_gap; BoolParam discard_orig_path; diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index 053062128..07c8bd27c 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -83,12 +83,31 @@ OriginalItemParam::param_newWidget() return dynamic_cast (_widget); } +void +OriginalItemParam::param_write(const gchar * iid) +{ + Glib::ustring itemid(iid); + + if (itemid.empty()) { + return; + } + // add '#' at start to make it an uri. + itemid.insert(itemid.begin(), '#'); + if ( href && strcmp(itemid.c_str(), href) == 0 ) { + // no change, do nothing + return; + } else { + param_write_to_repr(itemid.c_str()); + } +} + void OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) { if (!inverse) { emit_changed(); - SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + LivePathEffectObject* lpeobj = param_effect->getLPEObj(); + SP_OBJECT(lpeobj)->requestModified(SP_OBJECT_MODIFIED_FLAG); } } diff --git a/src/live_effects/parameter/originalitem.h b/src/live_effects/parameter/originalitem.h index 58d04e05a..86e223cea 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -26,7 +26,7 @@ public: void setInverse(bool inversed) { inverse = inversed; } bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } - + void param_write(const gchar * iid); virtual Gtk::Widget * param_newWidget(); protected: -- cgit v1.2.3 From 661acc453184bfe673a759794049c494a1477de5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 2 Jan 2017 20:10:32 +0100 Subject: Fixing paths (bzr r15295.1.46) --- src/live_effects/lpe-mirror_symmetry.cpp | 56 +++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index bd77db53c..0436ed877 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -220,6 +220,8 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) void LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); size_t index = 0; @@ -235,6 +237,11 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c while (*iter != NULL) { const char* att = (*iter); SPShape * shape = SP_SHAPE(origin); + SPPath * path = SP_PATH(dest); + if (!path && !SP_IS_GROUP(dest)) { + Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + } if (shape) { if ( live && (att == "d" || att == "inkscape:original-d")) { SPCurve *c = NULL; @@ -262,11 +269,11 @@ void LPEMirrorSymmetry::toMirror(Geom::Affine transform) { SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); const char * id_origin_char = id_origin.param_getSVGValue(); const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); elements.clear(); elements.push_back(elemref_id); - Inkscape::XML::Document *xml_doc = document->getReprDoc(); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; if (elemref = document->getObjectById(elemref_id)) { @@ -275,12 +282,44 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); } phantom->setAttribute("id", elemref_id); + phantom->setAttribute("inkscape:path-effect", NULL); + phantom->setAttribute("sodipodi:type", NULL); + phantom->setAttribute("sodipodi:rx", NULL); + phantom->setAttribute("sodipodi:ry", NULL); + phantom->setAttribute("sodipodi:cx", NULL); + phantom->setAttribute("sodipodi:cy", NULL); + phantom->setAttribute("sodipodi:end", NULL); + phantom->setAttribute("sodipodi:start", NULL); + phantom->setAttribute("inkscape:flatsided", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:rounded", NULL); + phantom->setAttribute("sodipodi:arg1", NULL); + phantom->setAttribute("sodipodi:arg2", NULL); + phantom->setAttribute("sodipodi:r1", NULL); + phantom->setAttribute("sodipodi:r2", NULL); + phantom->setAttribute("sodipodi:sides", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("sodipodi:argument", NULL); + phantom->setAttribute("sodipodi:expansion", NULL); + phantom->setAttribute("sodipodi:radius", NULL); + phantom->setAttribute("sodipodi:revolution", NULL); + phantom->setAttribute("sodipodi:t0", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("x", NULL); + phantom->setAttribute("y", NULL); + phantom->setAttribute("rx", NULL); + phantom->setAttribute("ry", NULL); + phantom->setAttribute("width", NULL); + phantom->setAttribute("height", NULL); if (!elemref) { elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); mirror_item.param_write(elemref_id); + } else { + elemref->updateRepr(xml_doc, phantom, SP_OBJECT_WRITE_ALL); } - elemref->getRepr()->setAttribute("inkscape:path-effect", ""); cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d"); elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != container) { @@ -513,6 +552,10 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) double time_end = crossed[i]; if (time_start != time_end && time_end - time_start > Geom::EPSILON) { Geom::Path portion = original.portion(time_start, time_end); + Geom::Path next_portion = portion; + if (crossed.size() > i+1) { + next_portion = original.portion(time_end, crossed[i+1]); + } if (!portion.empty()) { Geom::Point middle = portion.pointAt((double)portion.size()/2.0); position = Geom::sgn(Geom::cross(e - s, middle - s)); @@ -522,8 +565,9 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (position == 1) { Geom::Path mirror = portion.reversed() * m; if (split_elements) { - if(i!=0 || original.closed()) { - portion.close(); + if (crossed.size() > i+1) { + portion.appendNew( next_portion.finalPoint() ); + i++; } } else { mirror.setInitial(portion.finalPoint()); @@ -533,7 +577,9 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) portion.close(); } } - tmp_path.push_back(portion); + if (split_elements) { + tmp_path.push_back(portion); + } } portion.clear(); } -- cgit v1.2.3 From ea0de461574893c3b21e4653d0185cec501e0efe Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 2 Jan 2017 21:18:59 +0100 Subject: Remove clone original code (bzr r15295.1.47) --- src/live_effects/CMakeLists.txt | 6 - src/live_effects/effect.cpp | 41 ++-- src/live_effects/effect.h | 8 +- src/live_effects/lpe-clone-original.cpp | 289 +------------------------- src/live_effects/lpe-clone-original.h | 24 +-- src/live_effects/parameter/item-reference.cpp | 44 ---- src/live_effects/parameter/item-reference.h | 56 ----- src/live_effects/parameter/item.cpp | 246 ---------------------- src/live_effects/parameter/item.h | 79 ------- src/live_effects/parameter/originalitem.cpp | 148 ------------- src/live_effects/parameter/originalitem.h | 49 ----- 11 files changed, 28 insertions(+), 962 deletions(-) delete mode 100644 src/live_effects/parameter/item-reference.cpp delete mode 100644 src/live_effects/parameter/item-reference.h delete mode 100644 src/live_effects/parameter/item.cpp delete mode 100644 src/live_effects/parameter/item.h delete mode 100644 src/live_effects/parameter/originalitem.cpp delete mode 100644 src/live_effects/parameter/originalitem.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 5ffccc7c0..784317090 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -60,9 +60,6 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp parameter/filletchamferpointarray.cpp - parameter/item-reference.cpp - parameter/item.cpp - parameter/originalitem.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp parameter/parameter.cpp @@ -145,9 +142,6 @@ set(live_effects_SRC parameter/bool.h parameter/enum.h parameter/filletchamferpointarray.h - parameter/item.h - parameter/item-reference.h - parameter/originalitem.h parameter/originalpath.h parameter/originalpatharray.h parameter/parameter.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 81a512d23..5cc0d6f20 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -116,7 +116,7 @@ const Util::EnumData LPETypeData[] = { {RULER, N_("Ruler"), "ruler"}, /* 0.91 */ {POWERSTROKE, N_("Power stroke"), "powerstroke"}, - {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, + {CLONE_ORIGINAL, N_("Clone original path"), "clone_original"}, /* 0.92 */ {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, @@ -356,7 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), - sp_shape(NULL), + sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -392,9 +392,9 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector selected_np) +Effect::setSelectedNodePoints(std::vector sNP) { - selected_nodes_points = selected_np; + selectedNodesPoints = sNP; } void @@ -404,16 +404,16 @@ Effect::setCurrentZoom(double cZ) } bool -Effect::isNodePointSelected(Geom::Point const &node_point) const +Effect::isNodePointSelected(Geom::Point const &nodePoint) const { - if (selected_nodes_points.size() > 0) { + if (selectedNodesPoints.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selected_nodes_points.begin(); - i != selected_nodes_points.end(); ++i) { + for (std::vector::const_iterator i = selectedNodesPoints.begin(); + i != selectedNodesPoints.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(node_point[X], node_point[Y]); + Geom::Point p2(nodePoint[X],nodePoint[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; @@ -446,24 +446,21 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - setCurrentShape(shape); - } + /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - //Groups set shape in performPathEffect before each call to doEffect + //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - setCurrentShape(shape); + sp_curve = shape->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); } - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); doBeforeEffect(lpeitem); - if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); @@ -471,16 +468,6 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } -void Effect::setCurrentShape(SPShape * shape){ - if(shape){ - sp_shape = shape; - if (!(sp_curve = sp_shape->getCurve())) { - // oops - return; - } - pathvector_before_effect = sp_curve->get_pathvector(); - } -} /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of * mouse clicks. This method activates the pen context, which waits for the specified number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index b1dc0eabb..bc56c2390 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -79,8 +79,7 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); - SPShape * getCurrentShape(){ return sp_shape; }; - void setCurrentShape(SPShape * shape); + /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, * e.g., waiting for a parameter path either before the effect is created or when it needs a @@ -170,10 +169,9 @@ protected: // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.z - SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. + SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; - std::vector selected_nodes_points; + std::vector selectedNodesPoints; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 33abd685a..10418a02d 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -6,12 +6,6 @@ #include "live_effects/lpe-clone-original.h" #include "display/curve.h" -#include "svg/path-string.h" -#include "svg/svg.h" -#include "sp-clippath.h" -#include "sp-mask.h" -#include "xml/sp-css-attr.h" - // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -20,268 +14,9 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), - linked_path("LEGACY FALLBACK", "LEGACY FALLBACK", "linkedpath", &wr, this), - linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), - scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), - preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), - inverse(_("Inverse clone"), _("Use LPE item as origin"), "inverse", &wr, this, false), - use_center(_("Relative center of element"), _("Relative center of element"), "use_center", &wr, this, true), - attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), - style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") -{ - registerParameter(&linked_path); - registerParameter(&linked_item); - registerParameter(&scale); - registerParameter(&attributes); - registerParameter(&style_attributes); - registerParameter(&preserve_position); - registerParameter(&inverse); - registerParameter(&use_center); - scale.param_set_range(0.01, 999999.0); - scale.param_set_increments(1, 1); - scale.param_set_digits(2); - attributes.param_hide_canvas_text(); - style_attributes.param_hide_canvas_text(); - preserve_position_changed = preserve_position; - preserve_affine = Geom::identity(); -} - -bool hasLinkedTransform( const char * attributes) { - gchar ** attarray = g_strsplit(attributes, ",", 0); - gchar ** iter = attarray; - bool has_linked_transform = false; - while (*iter != NULL) { - const char* attribute = (*iter); - if ( std::strcmp(attribute, "transform") == 0 ) { - has_linked_transform = true; - } - iter++; - } - return has_linked_transform; -} - -void -LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) + linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this) { - SPDocument * document = SP_ACTIVE_DOCUMENT; - if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { - std::vector< SPObject * > childs = origin->childList(true); - size_t index = 0; - for (std::vector::iterator obj_it = childs.begin(); - obj_it != childs.end(); ++obj_it) { - SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes((*obj_it), dest_child, live, attributes, style_attributes, false); - index++; - } - } - //Attributes - SPShape * shape_origin = SP_SHAPE(origin); - SPPath * path_origin = SP_PATH(origin); - SPShape * shape_dest = SP_SHAPE(dest); - SPMask *mask_origin = SP_ITEM(origin)->mask_ref->getObject(); - SPMask *mask_dest = SP_ITEM(dest)->mask_ref->getObject(); - if(mask_origin && mask_dest) { - std::vector mask_list = mask_origin->childList(true); - std::vector mask_list_dest = mask_dest->childList(true); - if (mask_list.size() == mask_list_dest.size()) { - size_t i = 0; - for ( std::vector::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) { - SPObject * mask_data = *iter; - SPObject * mask_dest_data = mask_list_dest[i]; - cloneAttrbutes(mask_data, mask_dest_data, live, attributes, style_attributes, false); - i++; - } - } - } - SPClipPath *clippath_origin = SP_ITEM(origin)->clip_ref->getObject(); - SPClipPath *clippath_dest = SP_ITEM(dest)->clip_ref->getObject(); - if(clippath_origin && clippath_dest) { - std::vector clippath_list = clippath_origin->childList(true); - std::vector clippath_list_dest = clippath_dest->childList(true); - if (clippath_list.size() == clippath_list_dest.size()) { - size_t i = 0; - for ( std::vector::const_iterator iter=clippath_list.begin();iter!=clippath_list.end();++iter) { - SPObject * clippath_data = *iter; - SPObject * clippath_dest_data = clippath_list_dest[i]; - cloneAttrbutes(clippath_data, clippath_dest_data, live, attributes, style_attributes, false); - i++; - } - } - } - gchar ** attarray = g_strsplit(attributes, ",", 0); - gchar ** iter = attarray; - Geom::Affine affine_dest = Geom::identity(); - Geom::Affine affine_origin = Geom::identity(); - Geom::Affine affine_previous = Geom::identity(); - sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); - sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); - while (*iter != NULL) { - const char* attribute = (*iter); - if ( std::strcmp(attribute, "transform") == 0 ) { - if (preserve_position) { - Geom::Affine dest_affine = Geom::identity(); - if (root) { - dest_affine *= affine_origin; - if (preserve_affine == Geom::identity()) { - dest_affine *= Geom::Translate(affine_dest.translation()); - } - dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); - dest_affine *= Geom::Translate(preserve_affine.translation()); - affine_previous = preserve_affine; - preserve_affine = Geom::identity(); - SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(dest_affine)); - } - } else { - SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(affine_origin)); - } - } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0)) { - SPCurve *c = NULL; - if (inverse) { - c = shape_origin->getCurveBeforeLPE(); - } else { - c = shape_origin->getCurve(); - } - if (c) { - Geom::PathVector c_pv = c->get_pathvector(); - Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - Geom::OptRect dest_bbox = SP_ITEM(dest)->geometricBounds(); - if (dest_bbox && orig_bbox && root) { - Geom::Point orig_point = (*orig_bbox).corner(0); - Geom::Point dest_point = (*dest_bbox).corner(0); - if (use_center) { - orig_point = (*orig_bbox).midpoint(); - dest_point = (*dest_bbox).midpoint(); - } - if (scale != 100.0) { - double scale_affine = scale/100.0; - Geom::Scale scale = Geom::Scale(scale_affine); - c_pv *= Geom::Translate(orig_point).inverse(); - c_pv *= scale; - c_pv *= Geom::Translate(orig_point); - } - if (preserve_position) { - c_pv *= Geom::Translate(dest_point - orig_point); - } - } - if (inverse) { - c_pv *= i2anc_affine(origin, sp_lpe_item); - } else { - c_pv *= i2anc_affine(dest, sp_lpe_item); - } - c->set_pathvector(c_pv); - if (!path_origin) { - shape_dest->setCurveInsync(c, TRUE); - dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); - } else { - shape_dest->setCurve(c, TRUE); - } - c->unref(); - } else { - dest->getRepr()->setAttribute(attribute, NULL); - } - } else { - dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); - } - iter++; - } - g_strfreev (attarray); - SPCSSAttr *css_origin = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style")); - SPCSSAttr *css_dest = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css_dest, dest->getRepr()->attribute("style")); - gchar ** styleattarray = g_strsplit(style_attributes, ",", 0); - gchar ** styleiter = styleattarray; - while (*styleiter != NULL) { - const char* attribute = (*styleiter); - const char* origin_attribute = sp_repr_css_property(css_origin, attribute, ""); - if (origin_attribute == "") { - sp_repr_css_set_property (css_dest, attribute, NULL); - } else { - sp_repr_css_set_property (css_dest, attribute, origin_attribute); - } - styleiter++; - } - g_strfreev (styleattarray); - Glib::ustring css_str; - sp_repr_css_write_string(css_dest,css_str); - dest->getRepr()->setAttribute("style", css_str.c_str()); -} - -void -LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ - if (linked_path.linksToPath()) { //Legacy staff - Glib::ustring attributes_value("d"); - attributes.param_setValue(attributes_value); - attributes.write_to_SVG(); - Glib::ustring style_attributes_value(""); - style_attributes.param_setValue(style_attributes_value); - style_attributes.write_to_SVG(); - linked_item.param_readSVGValue(linked_path.param_getSVGValue()); - linked_path.param_readSVGValue(""); - } - - if (linked_item.linksToItem()) { - linked_item.setInverse(inverse); - if ( preserve_position_changed != preserve_position ) { - if (!preserve_position) { - sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &preserve_affine); - } - preserve_position_changed = preserve_position; - } - if (inverse) { - cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); - } else { - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); - } - } -} - - -Gtk::Widget * -LPECloneOriginal::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter * param = *it; - if (param->param_key == "linkedpath") { - ++it; - continue; - } - Gtk::Widget * widg = param->param_newWidget(); - 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; - } - this->upd_params = false; - return dynamic_cast(vbox); -} - -void -LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){ - Glib::ustring attributes_value("d,transform"); - attributes.param_setValue(attributes_value); - attributes.write_to_SVG(); - Glib::ustring style_attributes_value("opacity,stroke-width"); - style_attributes.param_setValue(style_attributes_value); - style_attributes.write_to_SVG(); + registerParameter( dynamic_cast(&linked_path) ); } LPECloneOriginal::~LPECloneOriginal() @@ -289,22 +24,12 @@ LPECloneOriginal::~LPECloneOriginal() } -void -LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) -{ - if (linked_item.linksToItem()) { - bool changed = false; - linked_item.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); - } -} - -void -LPECloneOriginal::doEffect (SPCurve * curve) +void LPECloneOriginal::doEffect (SPCurve * curve) { - if (linked_item.linksToItem() && !inverse) { - SPShape * shape = getCurrentShape(); - if(shape){ - curve->set_pathvector(shape->getCurve()->get_pathvector()); + if ( linked_path.linksToPath() ) { + Geom::PathVector linked_pathv = linked_path.get_pathvector(); + if ( !linked_pathv.empty() ) { + curve->set_pathvector(linked_pathv); } } } diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index aad6e9fa9..abf65ded8 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -10,38 +10,22 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/originalitem.h" #include "live_effects/parameter/originalpath.h" -#include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/point.h" -#include "live_effects/parameter/text.h" -#include "live_effects/lpegroupbbox.h" namespace Inkscape { namespace LivePathEffect { -class LPECloneOriginal : public Effect, GroupBBoxEffect { +class LPECloneOriginal : public Effect { public: LPECloneOriginal(LivePathEffectObject *lpeobject); virtual ~LPECloneOriginal(); - virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void doEffect (SPCurve * curve); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void transform_multiply(Geom::Affine const& postmul, bool set); - virtual Gtk::Widget * newWidget(); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: OriginalPathParam linked_path; - OriginalItemParam linked_item; - ScalarParam scale; - BoolParam preserve_position; - BoolParam inverse; - BoolParam use_center; - TextParam attributes; - TextParam style_attributes; - bool preserve_position_changed; - Geom::Affine preserve_affine; + +private: LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; diff --git a/src/live_effects/parameter/item-reference.cpp b/src/live_effects/parameter/item-reference.cpp deleted file mode 100644 index a775d93b7..000000000 --- a/src/live_effects/parameter/item-reference.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The reference corresponding to href of LPE Item parameter. - * - * Copyright (C) 2008 Johan Engelen - * - * Released under GNU GPL, read the file 'COPYING' for more information. - */ - -#include "live_effects/parameter/item-reference.h" - -#include "sp-shape.h" -#include "sp-text.h" -#include "sp-item-group.h" - -namespace Inkscape { -namespace LivePathEffect { - -bool ItemReference::_acceptObject(SPObject * const obj) const -{ - if (SP_IS_SHAPE(obj) || SP_IS_TEXT(obj) || SP_IS_GROUP(obj)) { - /* Refuse references to lpeobject */ - if (obj == getOwner()) { - return false; - } - // TODO: check whether the referred item has this LPE applied, if so: deny deny deny! - return URIReference::_acceptObject(obj); - } else { - return false; - } -} - -} // 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/item-reference.h b/src/live_effects/parameter/item-reference.h deleted file mode 100644 index 91231455a..000000000 --- a/src/live_effects/parameter/item-reference.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SEEN_LPE_ITEM_REFERENCE_H -#define SEEN_LPE_ITEM_REFERENCE_H - -/* - * Copyright (C) 2008-2012 Authors - * Authors: Johan Engelen - * Abhishek Sharma - * - * Released under GNU GPL, read the file 'COPYING' for more information. - */ - -#include - -class SPItem; -namespace Inkscape { -namespace XML { class Node; } - -namespace LivePathEffect { - -/** - * The reference corresponding to href of LPE ItemParam. - */ -class ItemReference : public Inkscape::URIReference { -public: - ItemReference(SPObject *owner) : URIReference(owner) {} - - SPItem *getObject() const { - return (SPItem *)URIReference::getObject(); - } - -protected: - virtual bool _acceptObject(SPObject * const obj) const; - -private: - ItemReference(const ItemReference&); - ItemReference& operator=(const ItemReference&); -}; - -} // namespace LivePathEffect - -} // namespace Inkscape - - - -#endif /* !SEEN_LPE_PATH_REFERENCE_H */ - -/* - 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/item.cpp b/src/live_effects/parameter/item.cpp deleted file mode 100644 index 8caea4e26..000000000 --- a/src/live_effects/parameter/item.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) Johan Engelen 2007 - * Abhishek Sharma - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/point.h" -#include - -#include "live_effects/parameter/item.h" -#include "live_effects/effect.h" -#include "svg/svg.h" - -#include "widgets/icon.h" -#include -#include "selection-chemistry.h" -#include "xml/repr.h" -#include "desktop.h" -#include "inkscape.h" -#include "message-stack.h" - -// clipboard support -#include "ui/clipboard.h" -// required for linking to other paths -#include "uri.h" - -#include -#include -#include "ui/icon-names.h" - -namespace Inkscape { - -namespace LivePathEffect { - -ItemParam::ItemParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const gchar * default_value) - : Parameter(label, tip, key, wr, effect), - changed(true), - href(NULL), - ref( (SPObject*)effect->getLPEObj() ) -{ - defvalue = g_strdup(default_value); - ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &ItemParam::ref_changed)); -} - -ItemParam::~ItemParam() -{ - remove_link(); - g_free(defvalue); -} - -void -ItemParam::param_set_default() -{ - param_readSVGValue(defvalue); -} - - -void -ItemParam::param_set_and_write_default() -{ - param_write_to_repr(defvalue); -} - -bool -ItemParam::param_readSVGValue(const gchar * strvalue) -{ - if (strvalue) { - remove_link(); - if (strvalue[0] == '#') { - if (href) - g_free(href); - href = g_strdup(strvalue); - try { - ref.attach(Inkscape::URI(href)); - //lp:1299948 - SPItem* i = ref.getObject(); - if (i) { - linked_modified_callback(i, SP_OBJECT_MODIFIED_FLAG); - } // else: document still processing new events. Repr of the linked object not created yet. - } catch (Inkscape::BadURIException &e) { - g_warning("%s", e.what()); - ref.detach(); - } - } - emit_changed(); - return true; - } - - return false; -} - -gchar * -ItemParam::param_getSVGValue() const -{ - return g_strdup(href); -} - -Gtk::Widget * -ItemParam::param_newWidget() -{ - Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox()); - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-clone"), Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); - static_cast(_widget)->pack_start(*pLabel, true, true); - pLabel->set_tooltip_text(param_tooltip); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &ItemParam::on_link_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Link to item on clipboard")); - - static_cast(_widget)->show_all_children(); - - return dynamic_cast (_widget); -} - -void -ItemParam::emit_changed() -{ - changed = true; - signal_item_changed.emit(); -} - - -void -ItemParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector &hp_vec) -{ -} - - -void -ItemParam::start_listening(SPObject * to) -{ - if ( to == NULL ) { - return; - } - linked_delete_connection = to->connectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); - linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); - if (SP_IS_ITEM(to)) { - linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); - } - linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated -} - -void -ItemParam::quit_listening(void) -{ - linked_modified_connection.disconnect(); - linked_delete_connection.disconnect(); - linked_transformed_connection.disconnect(); -} - -void -ItemParam::ref_changed(SPObject */*old_ref*/, SPObject *new_ref) -{ - quit_listening(); - if ( new_ref ) { - start_listening(new_ref); - } -} - -void -ItemParam::remove_link() -{ - if (href) { - ref.detach(); - g_free(href); - href = NULL; - } -} - -void -ItemParam::linked_delete(SPObject */*deleted*/) -{ - quit_listening(); - remove_link(); -} - -void ItemParam::linked_modified(SPObject *linked_obj, guint flags) -{ - linked_modified_callback(linked_obj, flags); -} - -void ItemParam::linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item) -{ - linked_transformed_callback(rel_transf, moved_item); -} - -void -ItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) -{ - emit_changed(); - SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); -} - -void -ItemParam::on_link_button_click() -{ - Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); - const gchar * iid = cm->getFirstObjectID(); - if (!iid) { - return; - } - - Glib::ustring itemid(iid); - - if (itemid.empty()) { - return; - } - - // add '#' at start to make it an uri. - itemid.insert(itemid.begin(), '#'); - if ( href && strcmp(itemid.c_str(), href) == 0 ) { - // no change, do nothing - return; - } else { - // TODO: - // check if id really exists in document, or only in clipboard document: if only in clipboard then invalid - // check if linking to object to which LPE is applied (maybe delegated to PathReference - - param_write_to_repr(itemid.c_str()); - DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Link item parameter to path")); - } -} - -} /* 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/item.h b/src/live_effects/parameter/item.h deleted file mode 100644 index 6c719d451..000000000 --- a/src/live_effects/parameter/item.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ITEM_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ITEM_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - - -#include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/item-reference.h" -#include -#include - -namespace Inkscape { - -namespace LivePathEffect { - -class ItemParam : public Parameter { -public: - ItemParam ( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const gchar * default_value = ""); - virtual ~ItemParam(); - virtual Gtk::Widget * param_newWidget(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - virtual void param_set_default(); - void param_set_and_write_default(); - virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); - - sigc::signal signal_item_pasted; - sigc::signal signal_item_changed; - bool changed; /* this gets set whenever the path is changed (this is set to true, and then the signal_item_changed signal is emitted). - * the user must set it back to false if she wants to use it sensibly */ -protected: - - gchar * href; // contains link to other object, e.g. "#path2428", NULL if ItemParam contains pathdata itself - ItemReference ref; - sigc::connection ref_changed_connection; - sigc::connection linked_delete_connection; - sigc::connection linked_modified_connection; - sigc::connection linked_transformed_connection; - void ref_changed(SPObject *old_ref, SPObject *new_ref); - void remove_link(); - void start_listening(SPObject * to); - void quit_listening(void); - void linked_delete(SPObject *deleted); - void linked_modified(SPObject *linked_obj, guint flags); - void linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item); - virtual void linked_modified_callback(SPObject *linked_obj, guint flags); - virtual void linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) {}; - void on_link_button_click(); - - void emit_changed(); - - gchar * defvalue; - -private: - ItemParam(const ItemParam&); - ItemParam& operator=(const ItemParam&); -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp deleted file mode 100644 index 07c8bd27c..000000000 --- a/src/live_effects/parameter/originalitem.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) Johan Engelen 2012 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include "live_effects/parameter/originalitem.h" - -#include "widgets/icon.h" -#include -#include -#include - -#include "uri.h" -#include "sp-shape.h" -#include "sp-text.h" -#include "display/curve.h" -#include "live_effects/effect.h" - -#include "inkscape.h" -#include "desktop.h" -#include "selection.h" -#include "ui/icon-names.h" - -namespace Inkscape { - -namespace LivePathEffect { - -OriginalItemParam::OriginalItemParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect) - : ItemParam(label, tip, key, wr, effect, "") -{ -} - -OriginalItemParam::~OriginalItemParam() -{ - -} - -Gtk::Widget * -OriginalItemParam::param_newWidget() -{ - Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); - - { // Label - Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(param_label)); - static_cast(_widget)->pack_start(*pLabel, true, true); - pLabel->set_tooltip_text(param_tooltip); - } - - { // Paste item to link button - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-paste"), Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemParam::on_link_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Link to item")); - } - - { // Select original button - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("edit-select-original", Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemParam::on_select_original_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Select original")); - } - - static_cast(_widget)->show_all_children(); - - return dynamic_cast (_widget); -} - -void -OriginalItemParam::param_write(const gchar * iid) -{ - Glib::ustring itemid(iid); - - if (itemid.empty()) { - return; - } - // add '#' at start to make it an uri. - itemid.insert(itemid.begin(), '#'); - if ( href && strcmp(itemid.c_str(), href) == 0 ) { - // no change, do nothing - return; - } else { - param_write_to_repr(itemid.c_str()); - } -} - -void -OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) -{ - if (!inverse) { - emit_changed(); - LivePathEffectObject* lpeobj = param_effect->getLPEObj(); - SP_OBJECT(lpeobj)->requestModified(SP_OBJECT_MODIFIED_FLAG); - } -} - -void -OriginalItemParam::linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) -{ -/** \todo find good way to compensate for referenced item transform, like done for normal clones. - * See sp-use.cpp: sp_use_move_compensate */ -} - - -void -OriginalItemParam::on_select_original_button_click() -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPItem *original = ref.getObject(); - if (desktop == NULL || original == NULL) { - return; - } - Inkscape::Selection *selection = desktop->getSelection(); - selection->clear(); - selection->set(original); -} - -} /* 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/originalitem.h b/src/live_effects/parameter/originalitem.h deleted file mode 100644 index 86e223cea..000000000 --- a/src/live_effects/parameter/originalitem.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINAL_ITEM_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINAL_ITEM_H - -/* - * Inkscape::LiveItemEffectParameters - * -* Copyright (C) Johan Engelen 2012 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/item.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class OriginalItemParam: public ItemParam { -public: - OriginalItemParam ( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect); - virtual ~OriginalItemParam(); - void setInverse(bool inversed) { inverse = inversed; } - bool linksToItem() const { return (href != NULL); } - SPItem * getObject() const { return ref.getObject(); } - void param_write(const gchar * iid); - virtual Gtk::Widget * param_newWidget(); - -protected: - virtual void linked_modified_callback(SPObject *linked_obj, guint flags); - virtual void linked_transformed_callback(Geom::Affine const *rel_transf, SPItem *moved_item); - - void on_select_original_button_click(); - -private: - bool inverse; - OriginalItemParam(const OriginalItemParam&); - OriginalItemParam& operator=(const OriginalItemParam&); -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif -- cgit v1.2.3 From 1154b598331b962b3ea6b5f0daabf632b538fe12 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 3 Jan 2017 15:58:20 +0100 Subject: Fixing some bugs (bzr r15295.1.48) --- src/live_effects/lpe-mirror_symmetry.cpp | 246 +++++++++++++++---------------- src/live_effects/lpe-mirror_symmetry.h | 5 - 2 files changed, 122 insertions(+), 129 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 0436ed877..05380c568 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -52,7 +52,6 @@ MTConverter(ModeTypeData, MT_END); LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), - mirror_item(_("Mirror item:"), _("Mirror item"), "mirror_item", &wr, this), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, 0), discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), @@ -65,7 +64,6 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,"") { show_orig_path = true; - registerParameter(&mirror_item); registerParameter(&mode); registerParameter(&split_gap); registerParameter(&discard_orig_path); @@ -82,43 +80,22 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : split_gap.param_set_digits(2); apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); - other = NULL; - last_transform = Geom::identity(); } LPEMirrorSymmetry::~LPEMirrorSymmetry() { } -bool -LPEMirrorSymmetry::isCurrentLPEItem() { - if (SPDesktop *desktop = SP_ACTIVE_DESKTOP) { - Inkscape::Selection *sel = desktop->getSelection(); - if ( sel && !sel->isEmpty()) { - SPItem *item = sel->singleItem(); - if (item) { - if(sp_lpe_item && std::strcmp(sp_lpe_item->getId(),item->getId()) == 0) { - return true; - } - } - } - } - return false; -} - void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { - if (!isCurrentLPEItem()) { - return; - } - last_transform = Geom::identity(); if (split_elements) { - if (discard_orig_path) { - discard_orig_path.param_setValue(false); - discard_orig_path.write_to_SVG(); - std::cout << _("You can't discard original paths on split elements"); - } +// if (discard_orig_path) { +// discard_orig_path.param_setValue(false); +// discard_orig_path.write_to_SVG(); +// std::cout << _("You can't discard original paths on split elements"); +// return; +// } container = dynamic_cast(sp_lpe_item->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); @@ -136,7 +113,6 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) } else { processObjects(LPE_ERASE); elements.clear(); - other = NULL; } } @@ -146,9 +122,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; original_bbox(lpeitem); - if (!isCurrentLPEItem()) { - return; - } //center_point->param_set_liveupdate(false); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); @@ -240,20 +213,17 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c SPPath * path = SP_PATH(dest); if (!path && !SP_IS_GROUP(dest)) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); - dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); } - if (shape) { - if ( live && (att == "d" || att == "inkscape:original-d")) { + path = SP_PATH(dest); + if (path && shape) { + if ( live && att == "d") { SPCurve *c = NULL; - if (att == "d") { - c = shape->getCurve(); - } else { - c = shape->getCurveBeforeLPE(); - } + c = shape->getCurve(); if (c) { + path->setCurve(c, TRUE); dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); - c->reset(); - g_free(c); + c->unref(); } else { dest->getRepr()->setAttribute(att,NULL); } @@ -280,56 +250,52 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) phantom = elemref->getRepr(); } else { phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + phantom->setAttribute("inkscape:path-effect", NULL); + phantom->setAttribute("inkscape:original-d", NULL); + phantom->setAttribute("sodipodi:type", NULL); + phantom->setAttribute("sodipodi:rx", NULL); + phantom->setAttribute("sodipodi:ry", NULL); + phantom->setAttribute("sodipodi:cx", NULL); + phantom->setAttribute("sodipodi:cy", NULL); + phantom->setAttribute("sodipodi:end", NULL); + phantom->setAttribute("sodipodi:start", NULL); + phantom->setAttribute("inkscape:flatsided", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:rounded", NULL); + phantom->setAttribute("sodipodi:arg1", NULL); + phantom->setAttribute("sodipodi:arg2", NULL); + phantom->setAttribute("sodipodi:r1", NULL); + phantom->setAttribute("sodipodi:r2", NULL); + phantom->setAttribute("sodipodi:sides", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("sodipodi:argument", NULL); + phantom->setAttribute("sodipodi:expansion", NULL); + phantom->setAttribute("sodipodi:radius", NULL); + phantom->setAttribute("sodipodi:revolution", NULL); + phantom->setAttribute("sodipodi:t0", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("x", NULL); + phantom->setAttribute("y", NULL); + phantom->setAttribute("rx", NULL); + phantom->setAttribute("ry", NULL); + phantom->setAttribute("width", NULL); + phantom->setAttribute("height", NULL); } phantom->setAttribute("id", elemref_id); - phantom->setAttribute("inkscape:path-effect", NULL); - phantom->setAttribute("sodipodi:type", NULL); - phantom->setAttribute("sodipodi:rx", NULL); - phantom->setAttribute("sodipodi:ry", NULL); - phantom->setAttribute("sodipodi:cx", NULL); - phantom->setAttribute("sodipodi:cy", NULL); - phantom->setAttribute("sodipodi:end", NULL); - phantom->setAttribute("sodipodi:start", NULL); - phantom->setAttribute("inkscape:flatsided", NULL); - phantom->setAttribute("inkscape:randomized", NULL); - phantom->setAttribute("inkscape:rounded", NULL); - phantom->setAttribute("sodipodi:arg1", NULL); - phantom->setAttribute("sodipodi:arg2", NULL); - phantom->setAttribute("sodipodi:r1", NULL); - phantom->setAttribute("sodipodi:r2", NULL); - phantom->setAttribute("sodipodi:sides", NULL); - phantom->setAttribute("inkscape:randomized", NULL); - phantom->setAttribute("sodipodi:argument", NULL); - phantom->setAttribute("sodipodi:expansion", NULL); - phantom->setAttribute("sodipodi:radius", NULL); - phantom->setAttribute("sodipodi:revolution", NULL); - phantom->setAttribute("sodipodi:t0", NULL); - phantom->setAttribute("inkscape:randomized", NULL); - phantom->setAttribute("inkscape:randomized", NULL); - phantom->setAttribute("inkscape:randomized", NULL); - phantom->setAttribute("x", NULL); - phantom->setAttribute("y", NULL); - phantom->setAttribute("rx", NULL); - phantom->setAttribute("ry", NULL); - phantom->setAttribute("width", NULL); - phantom->setAttribute("height", NULL); if (!elemref) { elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); - mirror_item.param_write(elemref_id); - } else { - elemref->updateRepr(xml_doc, phantom, SP_OBJECT_WRITE_ALL); } cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d"); elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", elemref_id); - other = container->appendChildRepr(copy); + container->appendChildRepr(copy); Inkscape::GC::release(copy); elemref->deleteObject(); - } else { - other = elemref; } } @@ -416,9 +382,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - //if (std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0) { - elemref->deleteObject(); - //} + elemref->deleteObject(); break; case LPE_VISIBILITY: @@ -448,24 +412,12 @@ void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - if (isCurrentLPEItem()) { - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { - Parameter * param = *it; - param->param_transform_multiply(postmul, set); - } - previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - - // Geom::Affine m = Geom::identity(); - // m *= sp_lpe_item->transform; - // m *= postmul; - // sp_lpe_item->transform = m; - //last_transform *= postmul; - sp_lpe_item_update_patheffect(sp_lpe_item, false, false); - // if (other) { - // sp_lpe_item_update_patheffect(SP_LPE_ITEM(other), false, false); - // } + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); } - + previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); } void @@ -495,7 +447,17 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { - if (split_elements && !fuse_paths || !isCurrentLPEItem()) { + if (split_elements && !fuse_paths) { + if (SP_IS_SHAPE(sp_lpe_item)) { + SPCurve *c = NULL; + if (!path_in.empty()) { + c->set_pathvector(path_in); + if (c) { + SP_SHAPE(sp_lpe_item)->setCurveInsync(c, TRUE); + c->unref(); + } + } + } return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); @@ -516,7 +478,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (path_it->empty()) { continue; } - Geom::PathVector tmp_path; + Geom::PathVector tmp_pathvector; + Geom::Path tmp_path; double time_start = 0.0; int position = 0; bool end_open = false; @@ -552,10 +515,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) double time_end = crossed[i]; if (time_start != time_end && time_end - time_start > Geom::EPSILON) { Geom::Path portion = original.portion(time_start, time_end); - Geom::Path next_portion = portion; - if (crossed.size() > i+1) { - next_portion = original.portion(time_end, crossed[i+1]); - } if (!portion.empty()) { Geom::Point middle = portion.pointAt((double)portion.size()/2.0); position = Geom::sgn(Geom::cross(e - s, middle - s)); @@ -565,20 +524,24 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (position == 1) { Geom::Path mirror = portion.reversed() * m; if (split_elements) { - if (crossed.size() > i+1) { - portion.appendNew( next_portion.finalPoint() ); - i++; + if (!tmp_path.empty()) { + tmp_path.appendNew( portion.initialPoint() ); } } else { mirror.setInitial(portion.finalPoint()); portion.append(mirror); - if(i!=0) { + if(i != 0) { portion.setFinal(portion.initialPoint()); portion.close(); } } - if (split_elements) { - tmp_path.push_back(portion); + if (!split_elements) { + tmp_pathvector.push_back(portion); + } else { + if (!tmp_path.empty()) { + portion.setInitial(tmp_path.finalPoint()); + } + tmp_path.append(portion); } } portion.clear(); @@ -602,36 +565,71 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) portion = portion.reversed(); } if (!original.closed()) { - tmp_path.push_back(portion); + if (!split_elements) { + tmp_pathvector.push_back(portion); + } else { + portion.setInitial(tmp_path.finalPoint()); + tmp_path.append(portion); + tmp_pathvector.push_back(tmp_path); + } } else { - if (cs.size() > 1 && tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { - portion.setFinal(tmp_path[0].initialPoint()); - portion.setInitial(tmp_path[0].finalPoint()); - tmp_path[0].append(portion); + if (!split_elements) { + if (cs.size() > 1 && tmp_pathvector.size() > 0 && tmp_pathvector[0].size() > 0 ) { + portion.setFinal(tmp_pathvector[0].initialPoint()); + portion.setInitial(tmp_pathvector[0].finalPoint()); + tmp_pathvector[0].append(portion); + } else { + tmp_pathvector.push_back(portion); + } + tmp_pathvector[0].close(); } else { - tmp_path.push_back(portion); + portion.setInitial(tmp_path.finalPoint()); + tmp_path.append(portion); + tmp_path.close(); } - tmp_path[0].close(); } portion.clear(); } } } +// if (cs.size()!=0 && position == 0) { +// if (split_elements && original.closed()) { +// tmp_path.appendNew( tmp_path.initialPoint() ); +// tmp_path.close(); +// } +// } if (cs.size() == 0 && position == 1) { - tmp_path.push_back(original); + tmp_pathvector.push_back(original); if ( !split_elements) { - tmp_path.push_back(original * m); + tmp_pathvector.push_back(original * m); + } + } + if (split_elements) { + if (split_elements && original.closed()) { + tmp_path.appendNew( tmp_path.initialPoint() ); + tmp_path.close(); } + tmp_pathvector.push_back(tmp_path); + tmp_path.clear(); } - path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); - tmp_path.clear(); + path_out.insert(path_out.end(), tmp_pathvector.begin(), tmp_pathvector.end()); + tmp_pathvector.clear(); } } else if (!fuse_paths || discard_orig_path) { for (size_t i = 0; i < original_pathv.size(); ++i) { path_out.push_back(original_pathv[i] * m); } } - +// if (SP_IS_SHAPE(sp_lpe_item)) { +// SPCurve *c = NULL; +// if (!path_out.empty()) { +// c->set_pathvector(path_out); +// if (c) { +// SP_SHAPE(sp_lpe_item)->setCurve(c, TRUE); +// c->unref(); +// } +// } +// } return path_out; } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 03ff56842..0680e5be8 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -17,7 +17,6 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/originalitem.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" @@ -51,7 +50,6 @@ public: virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); void toMirror(Geom::Affine transform); - bool isCurrentLPEItem(); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes); @@ -59,7 +57,6 @@ protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: - OriginalItemParam mirror_item; EnumParam mode; ScalarParam split_gap; BoolParam discard_orig_path; @@ -73,8 +70,6 @@ private: Geom::Point previous_center; std::vector elements; SPObject * container; - SPObject * other; - Geom::Affine last_transform; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; -- cgit v1.2.3 From 4943de681c1bdd831b828beab9ceb1f31f58b60a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Jan 2017 17:43:32 +0100 Subject: Fixing broken things (bzr r15295.1.49) --- src/live_effects/lpe-mirror_symmetry.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 05380c568..576c7df5e 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -448,16 +448,6 @@ Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { if (split_elements && !fuse_paths) { - if (SP_IS_SHAPE(sp_lpe_item)) { - SPCurve *c = NULL; - if (!path_in.empty()) { - c->set_pathvector(path_in); - if (c) { - SP_SHAPE(sp_lpe_item)->setCurveInsync(c, TRUE); - c->unref(); - } - } - } return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); @@ -592,12 +582,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } } } -// if (cs.size()!=0 && position == 0) { -// if (split_elements && original.closed()) { -// tmp_path.appendNew( tmp_path.initialPoint() ); -// tmp_path.close(); -// } -// } if (cs.size() == 0 && position == 1) { tmp_pathvector.push_back(original); if ( !split_elements) { @@ -620,16 +604,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out.push_back(original_pathv[i] * m); } } -// if (SP_IS_SHAPE(sp_lpe_item)) { -// SPCurve *c = NULL; -// if (!path_out.empty()) { -// c->set_pathvector(path_out); -// if (c) { -// SP_SHAPE(sp_lpe_item)->setCurve(c, TRUE); -// c->unref(); -// } -// } -// } return path_out; } -- cgit v1.2.3 From a8b0fd382f8ad594f2d086c347c4dfc65eb4b00d Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 4 Jan 2017 03:29:11 +0200 Subject: Convert source files from latin1 to utf-8. It is the path of least surprise and doesn't break my scripts. (bzr r15369.1.6) --- src/live_effects/lpe-lattice.h | 2 +- src/live_effects/lpe-lattice2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-lattice.h b/src/live_effects/lpe-lattice.h index 5eb48909b..8720af138 100644 --- a/src/live_effects/lpe-lattice.h +++ b/src/live_effects/lpe-lattice.h @@ -9,7 +9,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * Noé Falzon * Victor Navez * * Copyright (C) Johan Engelen 2007 diff --git a/src/live_effects/lpe-lattice2.h b/src/live_effects/lpe-lattice2.h index 59a0350d3..95c5285fb 100644 --- a/src/live_effects/lpe-lattice2.h +++ b/src/live_effects/lpe-lattice2.h @@ -9,7 +9,7 @@ * Authors: * Johan Engelen * Steren Giannini - * Noé Falzon + * Noé Falzon * Victor Navez * ~suv * Jabiertxo Arraiza -- cgit v1.2.3 From 72a83bc13438724d098533b7d54da814cc7ef4ff Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 4 Jan 2017 21:38:05 +0100 Subject: Fixing some bugs (bzr r15295.1.50) --- src/live_effects/effect.h | 7 ++--- src/live_effects/lpe-mirror_symmetry.cpp | 54 +++++++++++++++++--------------- src/live_effects/lpe-mirror_symmetry.h | 2 +- 3 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index bc56c2390..9a2d4c67d 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -19,7 +19,7 @@ class SPDocument; class SPDesktop; class SPItem; -class LivePathEffectObject; +class LivePathEffectObject; class SPLPEItem; class KnotHolder; class KnotHolderEntity; @@ -132,7 +132,8 @@ public: bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; BoolParam is_visible; - + SPCurve * sp_curve; + Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); @@ -172,8 +173,6 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; std::vector selectedNodesPoints; - SPCurve * sp_curve; - Geom::PathVector pathvector_before_effect; private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 576c7df5e..07a0d8b0c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -89,7 +89,7 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { - if (split_elements) { + if (split_elements && !discard_orig_path) { // if (discard_orig_path) { // discard_orig_path.param_setValue(false); // discard_orig_path.write_to_SVG(); @@ -191,7 +191,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } void -LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes) +LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = document->getReprDoc(); @@ -201,37 +201,35 @@ LPEMirrorSymmetry::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, c for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes); + cloneD(*obj_it, dest_child, live, false); index++; } } - gchar ** attarray = g_strsplit(attributes, ",", 0); - gchar ** iter = attarray; - while (*iter != NULL) { - const char* att = (*iter); - SPShape * shape = SP_SHAPE(origin); - SPPath * path = SP_PATH(dest); - if (!path && !SP_IS_GROUP(dest)) { - Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); - dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); - } + SPShape * shape = SP_SHAPE(origin); + SPPath * path = SP_PATH(dest); + if (!path && !SP_IS_GROUP(dest)) { + Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); path = SP_PATH(dest); - if (path && shape) { - if ( live && att == "d") { - SPCurve *c = NULL; + } + if (path && shape) { + if ( live) { + SPCurve *c = NULL; + if (root) { + c = new SPCurve(); + c->set_pathvector(pathvector_before_effect); + } else { c = shape->getCurve(); - if (c) { - path->setCurve(c, TRUE); - dest->getRepr()->setAttribute(att,sp_svg_write_path(c->get_pathvector())); - c->unref(); - } else { - dest->getRepr()->setAttribute(att,NULL); - } + } + if (c) { + path->setCurve(c, TRUE); + c->unref(); } else { - dest->getRepr()->setAttribute(att,origin->getRepr()->attribute(att)); + dest->getRepr()->setAttribute("d", NULL); } + } else { + dest->getRepr()->setAttribute("d", origin->getRepr()->attribute("d")); } - iter++; } } @@ -288,7 +286,7 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneAttrbutes(SP_OBJECT(sp_lpe_item), elemref, true, "d"); + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); @@ -553,6 +551,10 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) mirror.setInitial(portion.finalPoint()); portion.append(mirror); portion = portion.reversed(); + } else { + if (!tmp_path.empty()) { + tmp_path.appendNew( portion.initialPoint() ); + } } if (!original.closed()) { if (!split_elements) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 0680e5be8..c39cf3e04 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -51,7 +51,7 @@ public: void processObjects(LpeAction lpe_action); void toMirror(Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes); + void cloneD(SPObject *origin, SPObject *dest, bool live, bool root); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); -- cgit v1.2.3 From 9d0a8be3ea0673e7a453c16ddb77fdcf1ee47f4d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 5 Jan 2017 12:46:24 +0100 Subject: Fixing mirror on split (bzr r15295.1.51) --- src/live_effects/lpe-mirror_symmetry.cpp | 113 ++++++++++++++----------------- 1 file changed, 50 insertions(+), 63 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 07a0d8b0c..987444ed4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -455,11 +455,40 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) path_out = pathv_to_linear_and_cubic_beziers(path_in); } - Geom::Line line_separation((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (line_separation.vector(), (Geom::Point)start_point); - - if (fuse_paths && !discard_orig_path) { + if (split_elements && fuse_paths) { + Geom::OptRect bbox = path_in->boundsFast(); + bbox *= scale(1.2); + Geom::Path p(Geom::Point(bbox->left(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->top())); + p.close(); + p *= Geom::translate(bbox->middle_point()).inverse(); + p *= Geom::rotate(line_separation.angle()); + p *= Geom::translate(bbox->middle_point()); + bbox = p->boundsFast(); + p.clear(); + p(Geom::Point(bbox->left(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->top())); + p.close(); + Geom::Point base(bbox->right(), bbox->top()); + if (oposite_fuse) { + base = Geom::Point(bbox->left(), bbox->top()); + } + p *= Geom::translate(base - line_separation.pointAt(nearest_time(base, line_separation))); + Geom::PathVector pv_bbox; + pv_bbox.push_back(p); + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(pv_bbox, path_in); + if (pig && !path_in.empty() && !pv_bbox.empty()) { + path_out = pig->getBminusA(); + } + } else if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -467,7 +496,6 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) continue; } Geom::PathVector tmp_pathvector; - Geom::Path tmp_path; double time_start = 0.0; int position = 0; bool end_open = false; @@ -511,26 +539,13 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (position == 1) { Geom::Path mirror = portion.reversed() * m; - if (split_elements) { - if (!tmp_path.empty()) { - tmp_path.appendNew( portion.initialPoint() ); - } - } else { - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - if(i != 0) { - portion.setFinal(portion.initialPoint()); - portion.close(); - } - } - if (!split_elements) { - tmp_pathvector.push_back(portion); - } else { - if (!tmp_path.empty()) { - portion.setInitial(tmp_path.finalPoint()); - } - tmp_path.append(portion); + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + if(i != 0) { + portion.setFinal(portion.initialPoint()); + portion.close(); } + tmp_pathvector.push_back(portion); } portion.clear(); } @@ -546,39 +561,21 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Path portion = original.portion(time_start, original.size()); if (!portion.empty()) { portion = portion.reversed(); - if (!split_elements) { - Geom::Path mirror = portion.reversed() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - portion = portion.reversed(); - } else { - if (!tmp_path.empty()) { - tmp_path.appendNew( portion.initialPoint() ); - } - } + Geom::Path mirror = portion.reversed() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + portion = portion.reversed(); if (!original.closed()) { - if (!split_elements) { - tmp_pathvector.push_back(portion); - } else { - portion.setInitial(tmp_path.finalPoint()); - tmp_path.append(portion); - tmp_pathvector.push_back(tmp_path); - } + tmp_pathvector.push_back(portion); } else { - if (!split_elements) { - if (cs.size() > 1 && tmp_pathvector.size() > 0 && tmp_pathvector[0].size() > 0 ) { - portion.setFinal(tmp_pathvector[0].initialPoint()); - portion.setInitial(tmp_pathvector[0].finalPoint()); - tmp_pathvector[0].append(portion); - } else { - tmp_pathvector.push_back(portion); - } - tmp_pathvector[0].close(); + if (cs.size() > 1 && tmp_pathvector.size() > 0 && tmp_pathvector[0].size() > 0 ) { + portion.setFinal(tmp_pathvector[0].initialPoint()); + portion.setInitial(tmp_pathvector[0].finalPoint()); + tmp_pathvector[0].append(portion); } else { - portion.setInitial(tmp_path.finalPoint()); - tmp_path.append(portion); - tmp_path.close(); + tmp_pathvector.push_back(portion); } + tmp_pathvector[0].close(); } portion.clear(); } @@ -586,17 +583,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if (cs.size() == 0 && position == 1) { tmp_pathvector.push_back(original); - if ( !split_elements) { - tmp_pathvector.push_back(original * m); - } - } - if (split_elements) { - if (split_elements && original.closed()) { - tmp_path.appendNew( tmp_path.initialPoint() ); - tmp_path.close(); - } - tmp_pathvector.push_back(tmp_path); - tmp_path.clear(); + tmp_pathvector.push_back(original * m); } path_out.insert(path_out.end(), tmp_pathvector.begin(), tmp_pathvector.end()); tmp_pathvector.clear(); -- cgit v1.2.3 From a8857b9bea3e09e8d22c454a0773d14111936426 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 5 Jan 2017 13:24:27 +0100 Subject: Workingcd ../mirror_improvements! (bzr r15295.1.53) --- src/live_effects/lpe-mirror_symmetry.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 987444ed4..e4a3c7657 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -23,6 +23,7 @@ #include "svg/svg.h" #include "sp-defs.h" #include "helper/geom.h" +#include "2geom/intersection-graph.h" #include "2geom/path-intersection.h" #include "2geom/affine.h" #include "helper/geom.h" @@ -458,30 +459,33 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Line line_separation((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (line_separation.vector(), (Geom::Point)start_point); if (split_elements && fuse_paths) { - Geom::OptRect bbox = path_in->boundsFast(); - bbox *= scale(1.2); + Geom::OptRect bbox = sp_lpe_item->geometricBounds(); Geom::Path p(Geom::Point(bbox->left(), bbox->top())); p.appendNew(Geom::Point(bbox->right(), bbox->top())); p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->top())); p.close(); - p *= Geom::translate(bbox->middle_point()).inverse(); - p *= Geom::rotate(line_separation.angle()); - p *= Geom::translate(bbox->middle_point()); - bbox = p->boundsFast(); + p *= Geom::Translate(bbox->midpoint()).inverse(); + p *= Geom::Scale(1.2); + p *= Geom::Rotate(line_separation.angle()); + p *= Geom::Translate(bbox->midpoint()); + bbox = p.boundsFast(); p.clear(); - p(Geom::Point(bbox->left(), bbox->top())); + p.start(Geom::Point(bbox->left(), bbox->top())); p.appendNew(Geom::Point(bbox->right(), bbox->top())); p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); p.appendNew(Geom::Point(bbox->left(), bbox->top())); p.close(); - Geom::Point base(bbox->right(), bbox->top()); + p *= Geom::Translate(bbox->midpoint()).inverse(); + p *= Geom::Rotate(line_separation.angle()); + p *= Geom::Translate(bbox->midpoint()); + Geom::Point base(p.pointAt(3)); if (oposite_fuse) { - base = Geom::Point(bbox->left(), bbox->top()); + base = p.pointAt(0); } - p *= Geom::translate(base - line_separation.pointAt(nearest_time(base, line_separation))); + p *= Geom::Translate(line_separation.pointAt(line_separation.nearestTime(base)) - base); Geom::PathVector pv_bbox; pv_bbox.push_back(p); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(pv_bbox, path_in); -- cgit v1.2.3 From 52fe6e55a494d146bc2b1ad3b7a46e43a57bf311 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 5 Jan 2017 17:49:13 +0100 Subject: Bug fixes and add a slight gap to no line in middle (bzr r15295.1.55) --- src/live_effects/lpe-mirror_symmetry.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e4a3c7657..1fd007de3 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -54,7 +54,7 @@ MTConverter(ModeTypeData, MT_END); LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), - split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, 0), + split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), @@ -78,7 +78,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : id_origin.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); - split_gap.param_set_digits(2); + split_gap.param_set_digits(5); apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); } @@ -91,12 +91,6 @@ void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { if (split_elements && !discard_orig_path) { -// if (discard_orig_path) { -// discard_orig_path.param_setValue(false); -// discard_orig_path.write_to_SVG(); -// std::cout << _("You can't discard original paths on split elements"); -// return; -// } container = dynamic_cast(sp_lpe_item->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); @@ -488,8 +482,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) p *= Geom::Translate(line_separation.pointAt(line_separation.nearestTime(base)) - base); Geom::PathVector pv_bbox; pv_bbox.push_back(p); - Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(pv_bbox, path_in); - if (pig && !path_in.empty() && !pv_bbox.empty()) { + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(pv_bbox, original_pathv); + if (pig && !original_pathv.empty() && !pv_bbox.empty()) { path_out = pig->getBminusA(); } } else if (fuse_paths && !discard_orig_path) { -- cgit v1.2.3 From 7bedd224ace433cf4c1a829ba38f6a3c388227e6 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 5 Jan 2017 20:03:50 +0100 Subject: Adding base (bzr r15392.1.1) --- src/live_effects/effect.h | 15 ++++++++++----- src/live_effects/lpe-measure-line.cpp | 9 +++------ src/live_effects/lpe-measure-line.h | 6 ------ src/live_effects/parameter/bool.cpp | 3 ++- src/live_effects/parameter/text.cpp | 3 ++- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1997ff0ca..9a2d4c67d 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -19,7 +19,7 @@ class SPDocument; class SPDesktop; class SPItem; -class LivePathEffectObject; +class LivePathEffectObject; class SPLPEItem; class KnotHolder; class KnotHolderEntity; @@ -44,6 +44,12 @@ enum LPEPathFlashType { DEFAULT }; +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY +}; + class Effect { public: static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); @@ -125,7 +131,9 @@ public: bool apply_to_clippath_and_mask; bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; - + BoolParam is_visible; + SPCurve * sp_curve; + Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); @@ -150,7 +158,6 @@ protected: bool _provides_knotholder_entities; int oncanvasedit_it; - BoolParam is_visible; bool show_orig_path; // set this to true in derived effects to automatically have the original // path displayed as helperpath @@ -166,8 +173,6 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; std::vector selectedNodesPoints; - SPCurve * sp_curve; - Geom::PathVector pathvector_before_effect; private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index af2a8e919..e07335e1c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -21,7 +21,9 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" +#include "helper/geom.h" #include "2geom/affine.h" +#include "path-chemistry.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -165,12 +167,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} -void swap(Geom::Point &A, Geom::Point &B){ - Geom::Point tmp = A; - A = B; - B = tmp; -} - void LPEMeasureLine::createArrowMarker(const char * mode) { @@ -668,6 +664,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } +//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index c69921a4d..cb531affe 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -35,12 +35,6 @@ enum OrientationMethod { OM_END }; -enum LpeAction { - LPE_ERASE = 0, - LPE_TO_OBJECTS, - LPE_VISIBILITY -}; - class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index af99ef362..813c06b4e 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -72,7 +72,7 @@ BoolParam::param_newWidget() checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - + param_effect->upd_params = false; return dynamic_cast (checkwdg); } else { return NULL; @@ -82,6 +82,7 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { + param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 8cab68ad0..5c4cdf4c6 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -125,13 +125,14 @@ TextParam::param_newWidget() rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - + param_effect->upd_params = false; return dynamic_cast (rsu); } void TextParam::param_setValue(const Glib::ustring newvalue) { + param_effect->upd_params = true; value = newvalue; if (!_hide_canvas_text) { sp_canvastext_set_text (canvas_text, newvalue.c_str()); -- cgit v1.2.3 From 8b32064865a8da5aaf043e603148a2402f9b7602 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 6 Jan 2017 23:57:27 +0100 Subject: base of effect (bzr r15392.1.2) --- src/live_effects/lpe-copy_rotate.cpp | 229 ++++++++++++++++++++++++++++++++++- src/live_effects/lpe-copy_rotate.h | 12 ++ 2 files changed, 238 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 813f25d3d..963b31807 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -17,6 +17,12 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/intersection-graph.h> #include "live_effects/lpe-copy_rotate.h" +#include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include "path-chemistry.h" +#include "style.h" +#include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -45,9 +51,12 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : starting_angle(_("Starting angle"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), + split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), fuse_paths(_("Kaleidoskope"), _("Kaleidoskope by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), join_paths(_("Join paths"), _("Join paths, use fill-rule: evenodd for best result"), "join_paths", &wr, this, false), + split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Whith fuse don't work on shapes"), "split_elements", &wr, this, false), + id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,""), dist_angle_handle(100.0) { show_orig_path = true; @@ -60,8 +69,14 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); + registerParameter(&split_gap); + registerParameter(&split_elements); + registerParameter(&id_origin); registerParameter(&origin); - + id_origin.param_hide_canvas_text(); + split_gap.param_set_range(-999999.0, 999999.0); + split_gap.param_set_increments(0.1, 0.1); + split_gap.param_set_digits(5); num_copies.param_make_integer(true); num_copies.param_set_range(0, 1000); apply_to_clippath_and_mask = true; @@ -72,6 +87,137 @@ LPECopyRotate::~LPECopyRotate() } +void +LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) +{ + if (split_elements) { + container = dynamic_cast(sp_lpe_item->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; + } +// Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); +// Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); +// Geom::Point dir = rot90(unit_vector((Geom::Point)start_point - (Geom::Point)end_point)); +// Geom::Point gap = dir * split_gap; +// m *= Geom::Translate(gap); +// m = m * sp_lpe_item->transform; +// toMirror(m); + } else { + processObjects(LPE_ERASE); + elements.clear(); + } +} + +void +LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool live, bool root) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneD(*obj_it, dest_child, live, false); + index++; + } + } + SPShape * shape = SP_SHAPE(origin); + SPPath * path = SP_PATH(dest); + if (!path && !SP_IS_GROUP(dest)) { + Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + path = SP_PATH(dest); + } + if (path && shape) { + if ( live) { + SPCurve *c = NULL; + if (root) { + c = new SPCurve(); + c->set_pathvector(pathvector_before_effect); + } else { + c = shape->getCurve(); + } + if (c) { + path->setCurve(c, TRUE); + c->unref(); + } else { + dest->getRepr()->setAttribute("d", NULL); + } + } else { + dest->getRepr()->setAttribute("d", origin->getRepr()->attribute("d")); + } + } +} + +void +LPECopyRotate::toMirror(Geom::Affine transform) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + const char * id_origin_char = id_origin.param_getSVGValue(); + const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); + elements.clear(); + elements.push_back(elemref_id); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = document->getObjectById(elemref_id)) { + phantom = elemref->getRepr(); + } else { + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + phantom->setAttribute("inkscape:path-effect", NULL); + phantom->setAttribute("inkscape:original-d", NULL); + phantom->setAttribute("sodipodi:type", NULL); + phantom->setAttribute("sodipodi:rx", NULL); + phantom->setAttribute("sodipodi:ry", NULL); + phantom->setAttribute("sodipodi:cx", NULL); + phantom->setAttribute("sodipodi:cy", NULL); + phantom->setAttribute("sodipodi:end", NULL); + phantom->setAttribute("sodipodi:start", NULL); + phantom->setAttribute("inkscape:flatsided", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:rounded", NULL); + phantom->setAttribute("sodipodi:arg1", NULL); + phantom->setAttribute("sodipodi:arg2", NULL); + phantom->setAttribute("sodipodi:r1", NULL); + phantom->setAttribute("sodipodi:r2", NULL); + phantom->setAttribute("sodipodi:sides", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("sodipodi:argument", NULL); + phantom->setAttribute("sodipodi:expansion", NULL); + phantom->setAttribute("sodipodi:radius", NULL); + phantom->setAttribute("sodipodi:revolution", NULL); + phantom->setAttribute("sodipodi:t0", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("inkscape:randomized", NULL); + phantom->setAttribute("x", NULL); + phantom->setAttribute("y", NULL); + phantom->setAttribute("rx", NULL); + phantom->setAttribute("ry", NULL); + phantom->setAttribute("width", NULL); + phantom->setAttribute("height", NULL); + } + phantom->setAttribute("id", elemref_id); + if (!elemref) { + elemref = container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + if (elemref->parent != container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", elemref_id); + container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + } +} + Gtk::Widget * LPECopyRotate::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -89,7 +235,7 @@ Gtk::Widget * LPECopyRotate::newWidget() Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - if (param->param_key != "starting_point") { + if (param->param_key == "id_origin" || param->param_key != "starting_point") { vbox->pack_start(*widg, true, true, 2); if (tip) { widg->set_tooltip_text(*tip); @@ -119,17 +265,22 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) origin.param_update_default(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); + SPLPEItem * splpeitem = const_cast(lpeitem); + if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet + id_origin.param_setValue(lpeitem->getRepr()->attribute("id")); + id_origin.write_to_SVG(); + } } void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); } + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); } void @@ -449,6 +600,78 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } + +//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication +void +LPECopyRotate::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + processObjects(LPE_VISIBILITY); +} + +void +LPECopyRotate::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + //unset "erase_extra_objects" hook on sp-lpe-item.cpp + if (!erase_extra_objects) { + processObjects(LPE_TO_OBJECTS); + return; + } + processObjects(LPE_ERASE); +} + +void +LPECopyRotate::processObjects(LpeAction lpe_action) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + for (std::vector::iterator el_it = elements.begin(); + el_it != elements.end(); ++el_it) { + const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + Inkscape::XML::Node * elemnode = elemref->getRepr(); + std::vector item_list; + item_list.push_back(SP_ITEM(elemref)); + std::vector item_to_select; + std::vector item_selected; + SPCSSAttr *css; + Glib::ustring css_str; + switch (lpe_action){ + case LPE_TO_OBJECTS: + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); + break; + + case LPE_ERASE: + elemref->deleteObject(); + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { + css->setAttribute("display", "none"); + } else { + css->setAttribute("display", NULL); + } + sp_repr_css_write_string(css,css_str); + elemnode->setAttribute("style", css_str.c_str()); + break; + + default: + break; + } + } + } + if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { + elements.clear(); + } +} + } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index c2ae2daf1..d398700ee 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -15,6 +15,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" @@ -28,11 +29,17 @@ public: virtual void doOnApply (SPLPEItem const* lpeitem); virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); + void processObjects(LpeAction lpe_action); + void toMirror(Geom::Affine transform); + void cloneD(SPObject *origin, SPObject *dest, bool live, bool root); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -42,9 +49,12 @@ private: ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; + ScalarParam split_gap; BoolParam copies_to_360; BoolParam fuse_paths; BoolParam join_paths; + BoolParam split_elements; + TextParam id_origin; Geom::Point A; Geom::Point B; Geom::Point dir; @@ -52,6 +62,8 @@ private: Geom::Point rot_pos; Geom::Point previous_start_point; double dist_angle_handle; + std::vector elements; + SPObject * container; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); }; -- cgit v1.2.3 From 949e58535cd5189f1b140a1b3968d40c17d5515f Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 7 Jan 2017 19:08:18 +0100 Subject: Some naming fix and headers (bzr r15295.1.57) --- src/live_effects/lpe-mirror_symmetry.cpp | 13 +++++-------- src/live_effects/lpe-mirror_symmetry.h | 3 +-- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 1fd007de3..e51812a38 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -28,10 +28,7 @@ #include "2geom/affine.h" #include "helper/geom.h" #include "sp-lpe-item.h" -#include "uri.h" -#include "uri-references.h" #include "path-chemistry.h" -#include "knotholder.h" #include "style.h" #include "xml/sp-css-attr.h" @@ -58,7 +55,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - split_elements(_("Split elements"), _("Split elements, this allow gradients and other paints. Whith fuse don't work on shapes"), "split_elements", &wr, this, false), + split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), @@ -70,7 +67,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter(&discard_orig_path); registerParameter(&fuse_paths); registerParameter(&oposite_fuse); - registerParameter(&split_elements); + registerParameter(&split_items); registerParameter(&start_point); registerParameter(&end_point); registerParameter(¢er_point); @@ -90,7 +87,7 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { - if (split_elements && !discard_orig_path) { + if (split_items && !discard_orig_path) { container = dynamic_cast(sp_lpe_item->parent); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); @@ -440,7 +437,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { - if (split_elements && !fuse_paths) { + if (split_items && !fuse_paths) { return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); @@ -452,7 +449,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Line line_separation((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (line_separation.vector(), (Geom::Point)start_point); - if (split_elements && fuse_paths) { + if (split_items && fuse_paths) { Geom::OptRect bbox = sp_lpe_item->geometricBounds(); Geom::Path p(Geom::Point(bbox->left(), bbox->top())); p.appendNew(Geom::Point(bbox->right(), bbox->top())); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index c39cf3e04..2122a41e4 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -20,7 +20,6 @@ #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" -#include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" #include "live_effects/lpegroupbbox.h" @@ -62,7 +61,7 @@ private: BoolParam discard_orig_path; BoolParam fuse_paths; BoolParam oposite_fuse; - BoolParam split_elements; + BoolParam split_items; PointParam start_point; PointParam end_point; PointParam center_point; -- cgit v1.2.3 From 2a434d30cbf94a89598f6a2ae7e0c5943a245dae Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 7 Jan 2017 19:59:44 +0100 Subject: Some naming fix and headers (bzr r15295.1.59) --- src/live_effects/lpe-mirror_symmetry.cpp | 12 ++++++------ src/live_effects/lpe-mirror_symmetry.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e51812a38..a8b1e321d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -104,7 +104,7 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) toMirror(m); } else { processObjects(LPE_ERASE); - elements.clear(); + items.clear(); } } @@ -232,8 +232,8 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) Inkscape::XML::Document *xml_doc = document->getReprDoc(); const char * id_origin_char = id_origin.param_getSVGValue(); const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); - elements.clear(); - elements.push_back(elemref_id); + items.clear(); + items.push_back(elemref_id); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; if (elemref = document->getObjectById(elemref_id)) { @@ -348,8 +348,8 @@ void LPEMirrorSymmetry::processObjects(LpeAction lpe_action) { SPDocument * document = SP_ACTIVE_DOCUMENT; - for (std::vector::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { + for (std::vector::iterator el_it = items.begin(); + el_it != items.end(); ++el_it) { const char * id = *el_it; if (!id || strlen(id) == 0) { return; @@ -393,7 +393,7 @@ LPEMirrorSymmetry::processObjects(LpeAction lpe_action) } } if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { - elements.clear(); + items.clear(); } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 2122a41e4..5a6db5062 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -67,7 +67,7 @@ private: PointParam center_point; TextParam id_origin; Geom::Point previous_center; - std::vector elements; + std::vector items; SPObject * container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From b92f23dfe2ae9c7887489a890da735b1771a7969 Mon Sep 17 00:00:00 2001 From: "mattia@debian.org" <> Date: Sat, 7 Jan 2017 23:00:59 +0100 Subject: Fix typo in variable name s/strech/stretch/ Fixed bugs: - https://launchpad.net/bugs/1653371 (bzr r15400.1.1) --- src/live_effects/lpe-transform_2pts.cpp | 14 +++++++------- src/live_effects/lpe-transform_2pts.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index e1f36eee7..ef2900775 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -34,7 +34,7 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : flip_vertical(_("Flip vertical"), _("Flip vertical"), "flip_vertical", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), start(_("Start"), _("Start point"), "start", &wr, this, "Start point"), end(_("End"), _("End point"), "end", &wr, this, "End point"), - strech(_("Stretch"), _("Stretch the result"), "strech", &wr, this, 1), + stretch(_("Stretch"), _("Stretch the result"), "stretch", &wr, this, 1), offset(_("Offset"), _("Offset from knots"), "offset", &wr, this, 0), first_knot(_("First Knot"), _("First Knot"), "first_knot", &wr, this, 1), last_knot(_("Last Knot"), _("Last Knot"), "last_knot", &wr, this, 1), @@ -52,7 +52,7 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : registerParameter(&first_knot); registerParameter(&last_knot); registerParameter(&helper_size); - registerParameter(&strech); + registerParameter(&stretch); registerParameter(&offset); registerParameter(&start); registerParameter(&end); @@ -73,9 +73,9 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : offset.param_set_range(-999999.0, 999999.0); offset.param_set_increments(1, 1); offset.param_set_digits(2); - strech.param_set_range(0, 999.0); - strech.param_set_increments(0.01, 0.01); - strech.param_set_digits(4); + stretch.param_set_range(0, 999.0); + stretch.param_set_increments(0.01, 0.01); + stretch.param_set_digits(4); apply_to_clippath_and_mask = true; } @@ -379,9 +379,9 @@ LPETransform2Pts::doEffect_pwd2 (Geom::Piecewise > const m *= Geom::Scale(-1,1); m *= Geom::Rotate(original_angle); } - if(strech != 1){ + if(stretch != 1){ m *= Geom::Rotate(-original_angle); - m *= Geom::Scale(1,strech); + m *= Geom::Scale(1,stretch); m *= Geom::Rotate(original_angle); } if(elastic) { diff --git a/src/live_effects/lpe-transform_2pts.h b/src/live_effects/lpe-transform_2pts.h index c20d56206..0f88e6b00 100644 --- a/src/live_effects/lpe-transform_2pts.h +++ b/src/live_effects/lpe-transform_2pts.h @@ -57,7 +57,7 @@ private: ToggleButtonParam flip_vertical; PointParam start; PointParam end; - ScalarParam strech; + ScalarParam stretch; ScalarParam offset; ScalarParam first_knot; ScalarParam last_knot; -- cgit v1.2.3 From c71315ca4dd98551ee180f97fe6e303f131fbbea Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 8 Jan 2017 02:57:46 +0100 Subject: Fix offset gap (bzr r15295.1.60) --- src/live_effects/lpe-mirror_symmetry.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a8b1e321d..3e46422a0 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -97,9 +97,6 @@ LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) } Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); - Geom::Point dir = rot90(unit_vector((Geom::Point)start_point - (Geom::Point)end_point)); - Geom::Point gap = dir * split_gap; - m *= Geom::Translate(gap); m = m * sp_lpe_item->transform; toMirror(m); } else { @@ -483,6 +480,10 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (pig && !original_pathv.empty() && !pv_bbox.empty()) { path_out = pig->getBminusA(); } + Geom::Point dir = rot90(unit_vector((Geom::Point)start_point - (Geom::Point)end_point)); + Geom::Point gap = dir * split_gap; + m *= Geom::Translate(gap); + path_out *= m; } else if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) -- cgit v1.2.3 From 5f0a1801ee8423cbdb4d0e86aa8502049f4e0c0f Mon Sep 17 00:00:00 2001 From: suv-lp <> Date: Mon, 9 Jan 2017 20:32:29 +0100 Subject: [Bug #1654798] Broken icon in LPE 'Fill between many' Fixed bugs: - https://launchpad.net/bugs/1654798 (bzr r15404) --- src/live_effects/parameter/originalpath.cpp | 2 +- src/live_effects/parameter/originalpatharray.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 2741461be..f7eb48b7a 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -56,7 +56,7 @@ OriginalPathParam::param_newWidget() } { // Paste path to link button - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-paste"), Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-clone"), Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 4ee068ebf..083abc94c 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -144,7 +144,7 @@ Gtk::Widget* OriginalPathArrayParam::param_newWidget() { // Paste path to link button - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("gtk-stock", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("edit-clone", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); -- cgit v1.2.3 From 48f06b976cdce2e2ba847ab5e2da5dc3f3883075 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 14 Jan 2017 23:31:01 +0100 Subject: Fixed wroken. now working (bzr r15392.1.5) --- src/live_effects/lpe-copy_rotate.cpp | 45 +++++++++++++++++++++++++++--------- src/live_effects/lpe-copy_rotate.h | 6 +++-- 2 files changed, 38 insertions(+), 13 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 438cb1c49..42ca531b4 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -82,6 +82,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies.param_make_integer(true); apply_to_clippath_and_mask = true; previous_num_copies = num_copies; + reset = false; } LPECopyRotate::~LPECopyRotate() @@ -144,7 +145,7 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); } t *= sp_lpe_item->transform; - toItem(t, i-1); + toItem(t, i-1, reset); rest ++; } } else { @@ -152,9 +153,10 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); Geom::Affine t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); t *= sp_lpe_item->transform; - toItem(t, i - 1); + toItem(t, i - 1, reset); } } + reset = false; } else { processObjects(LPE_ERASE); items.clear(); @@ -165,7 +167,7 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) } void -LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root) +LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = document->getReprDoc(); @@ -175,7 +177,7 @@ LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root) for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneD(*obj_it, dest_child, false); + cloneD(*obj_it, dest_child, false, reset); index++; } } @@ -200,11 +202,14 @@ LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root) } else { dest->getRepr()->setAttribute("d", NULL); } + if (reset) { + dest->getRepr()->setAttribute("style", shape->getRepr()->attribute("style")); + } } } void -LPECopyRotate::toItem(Geom::Affine transform, size_t i) +LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = document->getReprDoc(); @@ -255,9 +260,9 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i) elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - SP_ITEM(elemref)->setHidden(false); - cloneD(SP_OBJECT(sp_lpe_item), elemref, true); + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, reset); elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + SP_ITEM(elemref)->setHidden(false); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", elemref_id); @@ -267,6 +272,12 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i) } } +void +LPECopyRotate::resetStyles(){ + reset = true; + doAfterEffect(sp_lpe_item); +} + Gtk::Widget * LPECopyRotate::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -276,7 +287,15 @@ Gtk::Widget * LPECopyRotate::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); vbox->set_spacing(2); - + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); + Gtk::Button * reset_button = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset styles")))); + reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPECopyRotate::resetStyles)); + reset_button->set_size_request(140,30); + vbox->pack_start(*hbox, true,true,2); + hbox->pack_start(*reset_button, false, false,2); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { @@ -733,10 +752,14 @@ LPECopyRotate::processObjects(LpeAction lpe_action) Glib::ustring css_str; switch (lpe_action){ case LPE_TO_OBJECTS: - if (elemnode->attribute("inkscape:path-effect")) { - sp_item_list_to_curves(item_list, item_selected, item_to_select); + if (SP_ITEM(elemref)->isHidden()) { + elemref->deleteObject(); + } else { + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); } - elemnode->setAttribute("sodipodi:insensitive", NULL); break; case LPE_ERASE: diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 62cceacf4..3dba83fee 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -40,8 +40,9 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); void processObjects(LpeAction lpe_action); - void toItem(Geom::Affine transform, size_t i); - void cloneD(SPObject *origin, SPObject *dest, bool root); + void toItem(Geom::Affine transform, size_t i, bool reset); + void cloneD(SPObject *origin, SPObject *dest, bool root, bool reset); + void resetStyles(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -66,6 +67,7 @@ private: double dist_angle_handle; double previous_num_copies; std::vector items; + bool reset; SPObject * container; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); -- cgit v1.2.3 From 6e57767d7d58f47b2f921cd45a7675eab1bca02c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 15 Jan 2017 13:51:37 +0100 Subject: Remove unnecesatry text parameter (bzr r15392.1.6) --- src/live_effects/lpe-copy_rotate.cpp | 15 +++------------ src/live_effects/lpe-copy_rotate.h | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 42ca531b4..a074665b5 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -57,7 +57,6 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : fuse_paths(_("Kaleidoskope"), _("Kaleidoskope by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), join_paths(_("Join paths"), _("Join paths, use fill-rule: evenodd for best result"), "join_paths", &wr, this, false), split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), - id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,""), dist_angle_handle(100.0) { show_orig_path = true; @@ -72,9 +71,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&split_gap); - registerParameter(&id_origin); registerParameter(&origin); - id_origin.param_hide_canvas_text(); split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(5); @@ -108,7 +105,7 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) if (numcopies_gap > 0 && num_copies != 0) { guint counter = num_copies - 1; while (numcopies_gap > 0) { - const char * id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(id_origin.param_getSVGValue()).c_str()); + const char * id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); if (!id || strlen(id) == 0) { return; } @@ -213,8 +210,7 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = document->getReprDoc(); - const char * id_origin_char = id_origin.param_getSVGValue(); - const char * elemref_id = g_strdup(Glib::ustring("rotated-").append(std::to_string(i)).append("-").append(id_origin_char).c_str()); + const char * elemref_id = g_strdup(Glib::ustring("rotated-").append(std::to_string(i)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); items.push_back(elemref_id); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; @@ -303,7 +299,7 @@ Gtk::Widget * LPECopyRotate::newWidget() Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - if (param->param_key == "id_origin" || param->param_key != "starting_point") { + if (param->param_key != "starting_point") { vbox->pack_start(*widg, true, true, 2); if (tip) { widg->set_tooltip_text(*tip); @@ -333,11 +329,6 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) origin.param_update_default(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); - SPLPEItem * splpeitem = const_cast(lpeitem); - if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet - id_origin.param_setValue(lpeitem->getRepr()->attribute("id")); - id_origin.write_to_SVG(); - } } void diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 3dba83fee..6d6d06c4d 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -57,7 +57,6 @@ private: BoolParam fuse_paths; BoolParam join_paths; BoolParam split_items; - TextParam id_origin; Geom::Point A; Geom::Point B; Geom::Point dir; -- cgit v1.2.3 From 7201350d40601daaa99930be2554c5811eba23b0 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 20 Jan 2017 18:52:27 +0100 Subject: Fix bug 1657591. Crash on ungrouping in v0.92. A unnecesary call to update path effect hook the crash, not sure why but this call is unnecesary so I remove it Fixed bugs: - https://launchpad.net/bugs/1657591 (bzr r15424) --- src/live_effects/lpe-patternalongpath.cpp | 1 - src/live_effects/parameter/vector.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index c1853ef22..f404afe17 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -264,7 +264,6 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) pattern.param_transform_multiply(postmul, set); pattern.write_to_SVG(); } - sp_lpe_item_update_patheffect (sp_lpe_item, false, true); } void diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index aa16a2b98..55b4d4b32 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -116,7 +116,7 @@ VectorParam::set_and_write_new_values(Geom::Point const &new_origin, Geom::Point void VectorParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) { - set_and_write_new_values( origin * postmul, vector * postmul.withoutTranslation() ); + set_and_write_new_values( origin * postmul, vector * postmul.withoutTranslation() ); } -- cgit v1.2.3 From 8884e1097b5b5c11d9653ff1c9e4d9148fa579dd Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 20 Jan 2017 19:07:28 +0100 Subject: Fix bug 1622388. Insane memory leak and crash with pattern along path Fixed bugs: - https://launchpad.net/bugs/1622388 (bzr r15425) --- src/live_effects/lpe-patternalongpath.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index f404afe17..966e9020e 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -11,6 +11,7 @@ #include <2geom/bezier-to-sbasis.h> #include "knotholder.h" +#include #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -161,7 +162,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con // spacing.param_set_range(-pattBndsX.extent()*.9, Geom::infinity()); // } - y0+=noffset; + y0 += noffset; std::vector > > paths_in; paths_in = split_at_discontinuities(pwd2_in); @@ -197,7 +198,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con case PAPCT_REPEATED_STRETCHED: // if uskeleton is closed: - if(path_i.segs.front().at0() == path_i.segs.back().at1()){ + if (are_near(path_i.segs.front().at0(), path_i.segs.back().at1())){ nbCopies = std::max(1, static_cast(std::floor((uskeleton.domain().extent() - toffset)/(pattBndsX->extent()+xspace)))); pattBndsX = Interval(pattBndsX->min(),pattBndsX->max()+xspace); scaling = (uskeleton.domain().extent() - toffset)/(((double)nbCopies)*pattBndsX->extent()); @@ -213,11 +214,13 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con return pwd2_in; }; + //Ceil to 6 decimals + scaling = ceil(scaling * 1000000) / 1000000; double pattWidth = pattBndsX->extent() * scaling; - x*=scaling; + x *= scaling; if ( scale_y_rel.get_value() ) { - y*=(scaling * prop_scale); + y *= prop_scale * scaling; } else { y *= prop_scale; } @@ -235,7 +238,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con offs+=pattWidth; } } - if (fuse_tolerance > 0){ + if (fuse_tolerance > 0){ pre_output = fuse_nearby_ends(pre_output, fuse_tolerance); for (unsigned i=0; i Date: Sat, 21 Jan 2017 17:02:50 +0100 Subject: Fixes typos in strings. Some typos in Inkscape 0.92 LPE UI Fixed bugs: - https://launchpad.net/bugs/1622731 (bzr r15427) --- src/live_effects/lpe-perspective-envelope.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index e0dac0687..18b5b724d 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -379,7 +379,7 @@ LPEPerspectiveEnvelope::newWidget() hbox_down_handles->pack_start(*widg, true, true, 2); } if (tip) { - widg->set_tooltip_text(*tip); + widg->set_tooltip_markup(*tip); } else { widg->set_tooltip_text(""); widg->set_has_tooltip(false); -- cgit v1.2.3 From 2a398a6073bf3fb0497a774760a4cebb54bb7e2c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 22 Jan 2017 03:06:22 +0100 Subject: Add multiwidget fixes (bzr r15356.1.15) --- src/live_effects/lpe-clone-original.cpp | 21 ++++++++++++++++----- src/live_effects/lpe-clone-original.h | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index da93a5093..db697552a 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -32,8 +32,8 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : paintorder(_("Clone paint order"), _("Clone paint order"), "paintorder", &wr, this, false), opacity(_("Clone opacity"), _("Clone opacity"), "opacity", &wr, this, false), filter(_("Clone filter"), _("Clone filter"), "filter", &wr, this, false), - attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), - style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,""), + attributes("Attributes linked", "Attributes linked, comma separated atributes", "attributes", &wr, this,""), + style_attributes("Style attributes linked", "Style attributes linked, comma separated atributes", "style_attributes", &wr, this,""), expanded(false) { registerParameter(&linked_path); @@ -237,14 +237,14 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ } preserve_position_changed = preserve_position; } - Glib::ustring attr = Glib::ustring(attributes.param_getSVGValue()); + Glib::ustring attr = Glib::ustring(attributes.param_getSVGValue()).append(","); if (d) { attr.append("d,"); } if (transform) { attr.append("transform,"); } - Glib::ustring style_attr = Glib::ustring(style_attributes.param_getSVGValue()); + Glib::ustring style_attr = Glib::ustring(style_attributes.param_getSVGValue()).append(","); if (fill) { style_attr.append("fill,").append("fill-rule,"); } @@ -315,12 +315,23 @@ LPECloneOriginal::newWidget() expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show attributes override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); - expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPECloneOriginal::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); this->upd_params = false; return dynamic_cast(vbox); } +void +LPECloneOriginal::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Hide attributes override"))); + } else { + expander->set_label (Glib::ustring(_("Show attributes override"))); + } +} + LPECloneOriginal::~LPECloneOriginal() { diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index c5080ad0e..0ff5eb01d 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -8,7 +8,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include #include "live_effects/effect.h" #include "live_effects/parameter/originalitem.h" #include "live_effects/parameter/originalpath.h" @@ -28,6 +28,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Gtk::Widget * newWidget(); + void onExpanderChanged(); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: -- cgit v1.2.3 From d431044fc72f9b668dcfa5771f361f4d6088bdd7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 22 Jan 2017 18:53:31 +0100 Subject: Update to new code in trunk (bzr r13645.1.166) --- src/live_effects/effect.cpp | 94 +++++++------ src/live_effects/effect.h | 15 +- src/live_effects/lpe-fillet-chamfer.cpp | 188 ++++++++++++++----------- src/live_effects/lpe-fillet-chamfer.h | 29 ++-- src/live_effects/parameter/satellitesarray.cpp | 8 +- src/live_effects/parameter/satellitesarray.h | 9 +- 6 files changed, 188 insertions(+), 155 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 6899a3161..19e80c611 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -119,7 +119,7 @@ const Util::EnumData LPETypeData[] = { /* 0.92 */ {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, - {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, + {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective_envelope"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, {SHOW_HANDLES, N_("Show handles"), "show_handles"}, @@ -129,7 +129,6 @@ const Util::EnumData LPETypeData[] = { {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, /* Ponyscape -> Inkscape 0.92*/ {ATTACH_PATH, N_("Attach path"), "attach_path"}, {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, @@ -137,7 +136,8 @@ const Util::EnumData LPETypeData[] = { {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, /* 9.93 */ - {MEASURE_LINE, N_("Measure Line"), "measure-line"}, + {MEASURE_LINE, N_("Measure Line"), "measure_line"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -358,11 +358,11 @@ Effect::Effect(LivePathEffectObject *lpeobject) upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden - is_ready(false), // is automatically set to false if providesOwnFlashPaths() is not overridden - _current_zoom(1.0) + is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { registerParameter( dynamic_cast(&is_visible) ); is_visible.widget_is_visible = false; + current_zoom = 0.0; } Effect::~Effect() @@ -392,55 +392,67 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setCurrentZoom(double zoom) +Effect::setSelectedNodePos(std::vector selected_nodes_pos_data) { - _current_zoom = zoom; -} - -double -Effect::getCurrentZoom() -{ - return _current_zoom; + selected_nodes_pos = selected_nodes_pos_data; } void -Effect::setSelectedNodes(std::vector selected_nodes_pos) +Effect::setSelectedNodeIndex(Geom::PathVector pv) { - _selected_nodes_pos = selected_nodes_pos; -} + selected_nodes_index.clear(); + for (Geom::PathVector::const_iterator path_it = pv.begin(); + path_it != pv.end(); ++path_it) { -std::vector -Effect::getSelectedNodes() -{ - size_t counter = 0; - std::vector result; - if (pathvector_before_effect.empty()){ - return result; - } - for (size_t i = 0; i < pathvector_before_effect.size(); i++) { - for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { - if ((!pathvector_before_effect[i].closed() && - pathvector_before_effect[i].size_closed() == j+1 && - isNodeSelected( pathvector_before_effect[i][j].finalPoint())) || - isNodeSelected( pathvector_before_effect[i][j].initialPoint())) - { - result.push_back(counter); + if (path_it->empty()) { + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + 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(); + } + } + size_t i = 0; + while (curve_it1 != curve_endit) { + if (isNodeSelected(curve_it1->initialPoint())) { + selected_nodes_index.push_back(i); } - counter++; + ++i; + ++curve_it1; + } + if (isNodeSelected(path_it->finalPoint())) { + selected_nodes_index.push_back(i); } } - return result; } +void +Effect::setCurrentZoom(double cZ) +{ + current_zoom = cZ; +} bool -Effect::isNodeSelected(Geom::Point const &node_point) const -{ - if (!_selected_nodes_pos.empty()) { - for (std::vector::const_iterator i = _selected_nodes_pos.begin(); - i != _selected_nodes_pos.end(); ++i) { - Geom::Point p = (*i); - Geom::Point p2(node_point[Geom::X],node_point[Geom::Y]); +Effect::isNodeSelected(Geom::Point const &nodePoint) const +{ + if (selected_nodes_pos.size() > 0) { + using Geom::X; + using Geom::Y; + for (std::vector::const_iterator i = selected_nodes_pos.begin(); + i != selected_nodes_pos.end(); ++i) { + Geom::Point p = *i; + Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); + Geom::Point p2(nodePoint[X],nodePoint[Y]); + p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 61de60db8..0190325c0 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -58,11 +58,10 @@ public: //of indirection is needed. We first call these methods, then the below. void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); - void setCurrentZoom(double zoom); - double getCurrentZoom(); - void setSelectedNodes(std::vector selected_nodes_pos); - std::vector getSelectedNodes(); - bool isNodeSelected(Geom::Point const &node_point) const; + void setCurrentZoom(double cZ); + void setSelectedNodePos(std::vector selected_nodes_pos_data); + void setSelectedNodeIndex(Geom::PathVector pv); + bool isNodeSelected(Geom::Point const &nodePoint) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); @@ -166,14 +165,16 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - std::vector _selected_nodes_pos; + double current_zoom; + std::vector selected_nodes_pos; + std::vector selected_nodes_index; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed bool is_ready; - double _current_zoom; + Effect(const Effect&); Effect& operator=(const Effect&); }; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2bbd3dbab..410d6f0fc 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -23,65 +23,68 @@ namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData Fillet_methodData[] = { +static const Util::EnumData FilletmethodData[] = { { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter FMConverter(Fillet_methodData, FM_END); +static const Util::EnumDataConverter FMConverter(FilletmethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - _satellites_param("satellites_param", "satellites_param", - "_satellites_param", &wr, this), - _method(_("_method:"), _("_methods to calculate the fillet or chamfer"), - "_method", FMConverter, &wr, this, FM_AUTO), - _radius(_("_radius (unit or %):"), _("_radius, in unit or %"), "_radius", &wr, + unit(_("Unit"), _("Unit"), "unit", &wr, this, "px"), + satellites_param("Satellites_param", "Satellites_param", + "satellites_param", &wr, this), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), + "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.0), - _chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "_chamfer_steps", + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), - _flexible(_("_flexible _radius size (%)"), _("_flexible _radius size (%)"), - "_flexible", &wr, this, false), - _mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "_mirror_knots", &wr, + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), + "flexible", &wr, this, false), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), - _only_selected(_("Change only selected nodes"), - _("Change only selected nodes"), "_only_selected", &wr, this, + only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "only_selected", &wr, this, false), - _use_knot_distance(_("Use knots distance instead _radius"), - _("Use knots distance instead _radius"), - "_use_knot_distance", &wr, this, false), - _hide_knots(_("Hide knots"), _("Hide knots"), "_hide_knots", &wr, this, + use_knot_distance(_("Use knots distance instead radius"), + _("Use knots distance instead radius"), + "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - _apply_no_radius(_("Apply changes if _radius = 0"), _("Apply changes if _radius = 0"), "_apply_no_radius", &wr, this, true), - _apply_with_radius(_("Apply changes if _radius > 0"), _("Apply changes if _radius > 0"), "_apply_with_radius", &wr, this, true), - _helper_size(_("Helper path size with direction to node:"), - _("Helper path size with direction to node"), "_helper_size", &wr, this, 0), + apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), + apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), + helper_size(_("Helper path size with direction to node:"), + _("Helper path size with direction to node"), "helper_size", &wr, this, 0), _pathvector_satellites(NULL), _degenerate_hide(false) { - registerParameter(&_satellites_param); - registerParameter(&_method); - registerParameter(&_radius); - registerParameter(&_chamfer_steps); - registerParameter(&_helper_size); - registerParameter(&_flexible); - registerParameter(&_use_knot_distance); - registerParameter(&_mirror_knots); - registerParameter(&_apply_no_radius); - registerParameter(&_apply_with_radius); - registerParameter(&_only_selected); - registerParameter(&_hide_knots); + registerParameter(&satellites_param); + registerParameter(&unit); + registerParameter(&method); + registerParameter(&radius); + registerParameter(&chamfer_steps); + registerParameter(&helper_size); + registerParameter(&flexible); + registerParameter(&use_knot_distance); + registerParameter(&mirror_knots); + registerParameter(&apply_no_radius); + registerParameter(&apply_with_radius); + registerParameter(&only_selected); + registerParameter(&hide_knots); - _radius.param_set_range(0.0, Geom::infinity()); - _radius.param_set_increments(1, 1); - _radius.param_set_digits(4); - _radius.param_overwrite_widget(true); - _chamfer_steps.param_set_range(1, 999); - _chamfer_steps.param_set_increments(1, 1); - _chamfer_steps.param_set_digits(0); - _helper_size.param_set_range(0, 999); - _helper_size.param_set_increments(5, 5); - _helper_size.param_set_digits(0); + radius.param_set_range(0.0, Geom::infinity()); + radius.param_set_increments(1, 1); + radius.param_set_digits(4); + radius.param_overwrite_widget(true); + chamfer_steps.param_set_range(1, 999); + chamfer_steps.param_set_increments(1, 1); + chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, 999); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); + _provides_knotholder_entities = true; } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -102,16 +105,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) // continue //} Satellite satellite(FILLET); - satellite.setSteps(_chamfer_steps); + satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } //we add the last satellite on open path because _pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because _pathvector_satellites class has _methods when the path is modiffied - //and we want one _method for all uses + //dont remove for this effect because _pathvector_satellites class has methods when the path is modiffied + //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setSteps(_chamfer_steps); + satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } satellites.push_back(subpath_satellites); @@ -119,7 +122,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) _pathvector_satellites = new PathVectorSatellites(); _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -141,7 +144,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "_radius") { + if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -153,7 +156,14 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } - } else if (param->param_key == "_chamfer_steps") { +// } else if (param->param_key == "unit") { +// Inkscape::UI::Widget::RegisteredUnitMenu* widg_registered = +// Gtk::manage(dynamic_cast< Inkscape::UI::Widget::RegisteredUnitMenu *>(widg)); +// widg_registered->setUnit(unit.get_abbreviation()); +// widg_registered->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter")); +// widg_registered->getUnitMenu()->signal_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::convertUnit)); +// widg = widg_registered; + } else if (param->param_key == "chamfer_steps") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -165,12 +175,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } - } else if (param->param_key == "_helper_size") { + } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "_only_selected") { + } else if (param->param_key == "only_selected") { Gtk::manage(widg); } Glib::ustring *tip = param->param_getTooltip(); @@ -217,28 +227,37 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::refreshKnots() { - if (_satellites_param._knoth) { - _satellites_param._knoth->update_knots(); + if (satellites_param._knoth) { + satellites_param._knoth->update_knots(); } } void LPEFilletChamfer::updateAmount() { - _pathvector_satellites->updateAmount(_radius, _apply_no_radius, _apply_with_radius, _only_selected, - _use_knot_distance, _flexible); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateAmount(radius, apply_no_radius, apply_with_radius, only_selected, + use_knot_distance, flexible); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } +//void LPEFilletChamfer::convertUnit() +//{ +// SPDocument * document = SP_ACTIVE_DOCUMENT; +// SPNamedView *nv = sp_document_namedview(document, NULL); +// Glib::ustring display_unit = nv->display_units->abbr; +// _pathvector_satellites->convertUnit(unit.get_abbreviation(), display_unit, apply_no_radius, apply_with_radius); +// satellites_param.setPathVectorSatellites(_pathvector_satellites); +//} + void LPEFilletChamfer::updateChamferSteps() { - _pathvector_satellites->updateSteps(_chamfer_steps, _apply_no_radius, _apply_with_radius, _only_selected); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateSteps(chamfer_steps, apply_no_radius, apply_with_radius, only_selected); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - _pathvector_satellites->updateSatelliteType(satellitetype, _apply_no_radius, _apply_with_radius, _only_selected); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateSatelliteType(satellitetype, apply_no_radius, apply_with_radius, only_selected); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -252,44 +271,44 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - _satellites_param.setUseDistance(_use_knot_distance); - _satellites_param.setCurrentZoom(getCurrentZoom()); + satellites_param.setUseDistance(use_knot_distance); + satellites_param.setCurrentZoom(current_zoom); //mandatory call - _satellites_param.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - Satellites satellites = _satellites_param.data(); + Satellites satellites = satellites_param.data(); if (satellites.empty()) { doOnApply(lpeItem); - satellites = _satellites_param.data(); + satellites = satellites_param.data(); } if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector_satellites->getTotalSatellites(); if (number_nodes != previous_number_nodes) { Satellite satellite(FILLET); - satellite.setIsTime(_flexible); - satellite.setHasMirror(_mirror_knots); - satellite.setHidden(_hide_knots); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); satellites = _pathvector_satellites->getSatellites(); } } if (_degenerate_hide) { - _satellites_param.setGlobalKnotHide(true); + satellites_param.setGlobalKnotHide(true); } else { - _satellites_param.setGlobalKnotHide(false); + satellites_param.setGlobalKnotHide(false); } - if (_hide_knots) { - _satellites_param.setHelperSize(0); + if (hide_knots) { + satellites_param.setHelperSize(0); } else { - _satellites_param.setHelperSize(_helper_size); + satellites_param.setHelperSize(helper_size); } for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j].is_time != _flexible) { - satellites[i][j].is_time = _flexible; + if (satellites[i][j].is_time != flexible) { + satellites[i][j].is_time = flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j) { continue; @@ -303,10 +322,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].amount = size; } } - if (satellites[i][j].has_mirror != _mirror_knots) { - satellites[i][j].has_mirror = _mirror_knots; + if (satellites[i][j].has_mirror != mirror_knots) { + satellites[i][j].has_mirror = mirror_knots; } - satellites[i][j].hidden = _hide_knots; + satellites[i][j].hidden = hide_knots; } } if (!_pathvector_satellites) { @@ -314,8 +333,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - _pathvector_satellites->setSelected(getSelectedNodes()); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + if (only_selected) { + setSelectedNodeIndex(pathv); + _pathvector_satellites->setSelected(selected_nodes_index); + } + satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -470,8 +492,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Coord rx = radius; Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC; + is_straight_curve(curve_it2) && method != FM_BEZIER) || + method == FM_ARC; switch (type) { case CHAMFER: { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d3f437afd..2cee04a1e 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,13 +15,14 @@ #include "live_effects/parameter/enum.h" #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" +#include "live_effects/parameter/unit.h" #include "helper/geom-pathvectorsatellites.h" #include "helper/geom-satellite.h" namespace Inkscape { namespace LivePathEffect { -enum Fillet_method { +enum Filletmethod { FM_AUTO, FM_ARC, FM_BEZIER, @@ -39,24 +40,26 @@ public: void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); + //void convertUnit(); void updateChamferSteps(); void updateAmount(); void refreshKnots(); - SatellitesArrayParam _satellites_param; + SatellitesArrayParam satellites_param; private: - EnumParam _method; - ScalarParam _radius; - ScalarParam _chamfer_steps; - BoolParam _flexible; - BoolParam _mirror_knots; - BoolParam _only_selected; - BoolParam _use_knot_distance; - BoolParam _hide_knots; - BoolParam _apply_no_radius; - BoolParam _apply_with_radius; - ScalarParam _helper_size; + UnitParam unit; + EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; + BoolParam flexible; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam apply_no_radius; + BoolParam apply_with_radius; + ScalarParam helper_size; bool _degenerate_hide; PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 4705fd821..7efe5dd98 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -223,7 +223,6 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, SPItem *item, bool mirror) { @@ -260,23 +259,22 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Ctrl+Alt+Click reset"); } FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } index++; } } if (mirror) { - addKnotHolderEntities(knotholder, desktop, item, false); + addKnotHolderEntities(knotholder, item, false); } } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, SPItem *item) { _knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); + addKnotHolderEntities(knotholder, item, true); } FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 5b2d8a799..edaf2f08d 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -41,12 +41,9 @@ public: return NULL; } virtual void setHelperSize(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); virtual void updateCanvasIndicators(bool mirror); virtual bool providesKnotHolderEntities() const -- cgit v1.2.3 From e06fb0c25cc352df40b77a1988b5045426e7ef2d Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 01:02:46 +0100 Subject: Fixing to merge (bzr r15392.1.8) --- src/live_effects/effect.cpp | 21 +++++++++++-- src/live_effects/effect.h | 3 ++ src/live_effects/lpe-copy_rotate.cpp | 1 + src/live_effects/lpe-measure-line.cpp | 58 +++-------------------------------- src/live_effects/lpe-measure-line.h | 2 -- 5 files changed, 28 insertions(+), 57 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 227f91594..3cfeface8 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,6 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), + sp_shape(NULL), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -480,6 +481,17 @@ Effect::processObjects(LpeAction lpe_action) } } +void Effect::setCurrentShape(SPShape * shape){ + if(shape){ + sp_shape = shape; + if (!(sp_curve = sp_shape->getCurve())) { + // oops + return; + } + pathvector_before_effect = sp_curve->get_pathvector(); + } +} + /** * Is performed each time before the effect is updated. */ @@ -503,8 +515,12 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector();*/ + sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + setCurrentShape(shape); + } doOnApply(lpeitem); } @@ -514,6 +530,7 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ + setCurrentShape(shape); sp_curve = shape->getCurve(); pathvector_before_effect = sp_curve->get_pathvector(); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 2f42ab3f6..f5e41d50e 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -79,6 +79,8 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); + SPShape * getCurrentShape(){ return sp_shape; }; + void setCurrentShape(SPShape * shape); void processObjects(LpeAction lpe_action); /* @@ -172,6 +174,7 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. std::vector items; double current_zoom; std::vector selectedNodesPoints; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index a4d844fdd..33c4d6e5b 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -588,6 +588,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) triangle.push_back(divider); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(triangle, path_out); if (pig && ! path_out.empty() && !triangle.empty()) { + //TODO: Here can produce a crash because some knows problems in new boolops code path_out = pig->getIntersection(); } Geom::Affine r = Geom::identity(); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index e07335e1c..38f93ebb4 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -225,7 +225,7 @@ LPEMeasureLine::createArrowMarker(const char * mode) elemref = SP_OBJECT(document->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); } - elements.push_back(mode); + items.push_back(mode); } void @@ -365,7 +365,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl copy->setAttribute("id", id); elemref = elemref_copy; } - elements.push_back(id); + items.push_back(id); Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { anotation_width = bounds->width() * 1.4; @@ -479,7 +479,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, b elemref->deleteObject(); copy->setAttribute("id", id); } - elements.push_back(id); + items.push_back(id); } void @@ -531,7 +531,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_lpe_item->getCurrentLPE() != this){ return; } - elements.clear(); + items.clear(); start_stored = start; end_stored = end; Geom::Point hstart = start; @@ -677,60 +677,12 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - elements.clear(); + items.clear(); return; } processObjects(LPE_ERASE); } -void -LPEMeasureLine::processObjects(LpeAction lpe_action) -{ - SPDocument * document = SP_ACTIVE_DOCUMENT; - for (std::vector::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - SPObject *elemref = NULL; - if (elemref = document->getObjectById(id)) { - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - elemref->deleteObject(); - } - break; - - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemref->getRepr()->setAttribute("style", css_str.c_str()); - break; - - default: - break; - } - } - } - if (lpe_action == LPE_ERASE) { - elements.clear(); - } -} - Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index cb531affe..724c0d924 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -45,7 +45,6 @@ public: virtual void doEffect (SPCurve * curve){}; //stop the chain virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void processObjects(LpeAction lpe_action); void createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); @@ -86,7 +85,6 @@ private: double arrow_gap; Geom::Point start_stored; Geom::Point end_stored; - std::vector elements; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); -- cgit v1.2.3 From ba053c48cdcd8b4995f188d80887d46c41f97b3d Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 01:37:00 +0100 Subject: Remove some code and make dependant of rotate copies (bzr r15356.1.17) --- src/live_effects/effect.cpp | 39 ++++++++++++------------------------ src/live_effects/effect.h | 8 +++----- src/live_effects/lpe-copy_rotate.cpp | 1 + 3 files changed, 17 insertions(+), 31 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 81a512d23..9d9381294 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,7 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), - sp_shape(NULL), + sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -392,9 +392,9 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector selected_np) +Effect::setSelectedNodePoints(std::vector sNP) { - selected_nodes_points = selected_np; + selectedNodesPoints = sNP; } void @@ -404,16 +404,16 @@ Effect::setCurrentZoom(double cZ) } bool -Effect::isNodePointSelected(Geom::Point const &node_point) const +Effect::isNodePointSelected(Geom::Point const &nodePoint) const { - if (selected_nodes_points.size() > 0) { + if (selectedNodesPoints.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selected_nodes_points.begin(); - i != selected_nodes_points.end(); ++i) { + for (std::vector::const_iterator i = selectedNodesPoints.begin(); + i != selectedNodesPoints.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(node_point[X], node_point[Y]); + Geom::Point p2(nodePoint[X],nodePoint[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; @@ -446,24 +446,21 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - setCurrentShape(shape); - } + /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector();*/ doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - //Groups set shape in performPathEffect before each call to doEffect + //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - setCurrentShape(shape); + sp_curve = shape->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); } - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); doBeforeEffect(lpeitem); - if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); @@ -471,16 +468,6 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } -void Effect::setCurrentShape(SPShape * shape){ - if(shape){ - sp_shape = shape; - if (!(sp_curve = sp_shape->getCurve())) { - // oops - return; - } - pathvector_before_effect = sp_curve->get_pathvector(); - } -} /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of * mouse clicks. This method activates the pen context, which waits for the specified number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 5dfa3de29..1997ff0ca 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,8 +73,7 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); - SPShape * getCurrentShape(){ return sp_shape; }; - void setCurrentShape(SPShape * shape); + /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, * e.g., waiting for a parameter path either before the effect is created or when it needs a @@ -164,10 +163,9 @@ protected: // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.z - SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. + SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; - std::vector selected_nodes_points; + std::vector selectedNodesPoints; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 250f6aa29..813f25d3d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -125,6 +125,7 @@ void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); -- cgit v1.2.3 From e282eca29c2cd9b97247db78f2375c8a64071d9c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 01:44:29 +0100 Subject: Some bug fix to prepare merge (bzr r15392.1.9) --- src/live_effects/effect.cpp | 2 ++ src/live_effects/lpe-copy_rotate.cpp | 1 - src/live_effects/lpe-measure-line.cpp | 1 - src/live_effects/parameter/parameter.cpp | 3 +++ 4 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 3cfeface8..a0ab0d41c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -70,6 +70,8 @@ #include "ui/tools/node-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" +#include "path-chemistry.h" +#include "xml/sp-css-attr.h" #include "live_effects/lpeobject.h" #include "display/curve.h" diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 33c4d6e5b..b81451487 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -20,7 +20,6 @@ #include "display/curve.h" #include "svg/path-string.h" #include "svg/svg.h" -#include "path-chemistry.h" #include "style.h" #include "helper/geom.h" #include "xml/sp-css-attr.h" diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 38f93ebb4..ef87be81c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -664,7 +664,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } } -//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) { diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 76aa05bae..befac4df1 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -198,6 +198,9 @@ ScalarParam::param_set_increments(double step, double page) inc_page = page; } + + + } /* namespace LivePathEffect */ } /* namespace Inkscape */ -- cgit v1.2.3 From 6d832f1da88ad485979c2c480dbd7576db486807 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 01:57:50 +0100 Subject: Fixes some compiling bug (bzr r15392.1.10) --- src/live_effects/lpe-copy_rotate.cpp | 65 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index b81451487..61ea7e171 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -23,6 +23,7 @@ #include "style.h" #include "helper/geom.h" #include "xml/sp-css-attr.h" +#include "path-chemistry.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -218,38 +219,38 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) } else { phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); std::vector attrs; - attrs->push_back("inkscape:path-effect"); - attrs->push_back("inkscape:original-d"); - attrs->push_back("sodipodi:type"); - attrs->push_back("sodipodi:rx"); - attrs->push_back("sodipodi:ry"); - attrs->push_back("sodipodi:cx"); - attrs->push_back("sodipodi:cy"); - attrs->push_back("sodipodi:end"); - attrs->push_back("sodipodi:start"); - attrs->push_back("inkscape:flatsided"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:rounded"); - attrs->push_back("sodipodi:arg1"); - attrs->push_back("sodipodi:arg2"); - attrs->push_back("sodipodi:r1"); - attrs->push_back("sodipodi:r2"); - attrs->push_back("sodipodi:sides"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("sodipodi:argument"); - attrs->push_back("sodipodi:expansion"); - attrs->push_back("sodipodi:radius"); - attrs->push_back("sodipodi:revolution"); - attrs->push_back("sodipodi:t0"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("x"); - attrs->push_back("y"); - attrs->push_back("rx"); - attrs->push_back("ry"); - attrs->push_back("width"); - attrs->push_back("height"); + attrs.push_back("inkscape:path-effect"); + attrs.push_back("inkscape:original-d"); + attrs.push_back("sodipodi:type"); + attrs.push_back("sodipodi:rx"); + attrs.push_back("sodipodi:ry"); + attrs.push_back("sodipodi:cx"); + attrs.push_back("sodipodi:cy"); + attrs.push_back("sodipodi:end"); + attrs.push_back("sodipodi:start"); + attrs.push_back("inkscape:flatsided"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:rounded"); + attrs.push_back("sodipodi:arg1"); + attrs.push_back("sodipodi:arg2"); + attrs.push_back("sodipodi:r1"); + attrs.push_back("sodipodi:r2"); + attrs.push_back("sodipodi:sides"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("sodipodi:argument"); + attrs.push_back("sodipodi:expansion"); + attrs.push_back("sodipodi:radius"); + attrs.push_back("sodipodi:revolution"); + attrs.push_back("sodipodi:t0"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("x"); + attrs.push_back("y"); + attrs.push_back("rx"); + attrs.push_back("ry"); + attrs.push_back("width"); + attrs.push_back("height"); phantom->setAttribute("id", elemref_id); for(const char * attr : attrs) { phantom->setAttribute(attr, NULL); -- cgit v1.2.3 From 05e33ba9f32f76d8cdb1feeeec5dd62f6d6d6811 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 01:58:33 +0100 Subject: Fixes some compiling bug (bzr r15295.1.64) --- src/live_effects/lpe-mirror_symmetry.cpp | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e94ad496e..0defeb900 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -238,38 +238,38 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) } else { phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); std::vector attrs; - attrs->push_back("inkscape:path-effect"); - attrs->push_back("inkscape:original-d"); - attrs->push_back("sodipodi:type"); - attrs->push_back("sodipodi:rx"); - attrs->push_back("sodipodi:ry"); - attrs->push_back("sodipodi:cx"); - attrs->push_back("sodipodi:cy"); - attrs->push_back("sodipodi:end"); - attrs->push_back("sodipodi:start"); - attrs->push_back("inkscape:flatsided"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:rounded"); - attrs->push_back("sodipodi:arg1"); - attrs->push_back("sodipodi:arg2"); - attrs->push_back("sodipodi:r1"); - attrs->push_back("sodipodi:r2"); - attrs->push_back("sodipodi:sides"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("sodipodi:argument"); - attrs->push_back("sodipodi:expansion"); - attrs->push_back("sodipodi:radius"); - attrs->push_back("sodipodi:revolution"); - attrs->push_back("sodipodi:t0"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("inkscape:randomized"); - attrs->push_back("x"); - attrs->push_back("y"); - attrs->push_back("rx"); - attrs->push_back("ry"); - attrs->push_back("width"); - attrs->push_back("height"); + attrs.push_back("inkscape:path-effect"); + attrs.push_back("inkscape:original-d"); + attrs.push_back("sodipodi:type"); + attrs.push_back("sodipodi:rx"); + attrs.push_back("sodipodi:ry"); + attrs.push_back("sodipodi:cx"); + attrs.push_back("sodipodi:cy"); + attrs.push_back("sodipodi:end"); + attrs.push_back("sodipodi:start"); + attrs.push_back("inkscape:flatsided"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:rounded"); + attrs.push_back("sodipodi:arg1"); + attrs.push_back("sodipodi:arg2"); + attrs.push_back("sodipodi:r1"); + attrs.push_back("sodipodi:r2"); + attrs.push_back("sodipodi:sides"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("sodipodi:argument"); + attrs.push_back("sodipodi:expansion"); + attrs.push_back("sodipodi:radius"); + attrs.push_back("sodipodi:revolution"); + attrs.push_back("sodipodi:t0"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("x"); + attrs.push_back("y"); + attrs.push_back("rx"); + attrs.push_back("ry"); + attrs.push_back("width"); + attrs.push_back("height"); for(const char * attr : attrs) { phantom->setAttribute(attr, NULL); } -- cgit v1.2.3 From 6569c9330cb3f5378d01c4fe43c13f69d537561e Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 08:17:30 +0100 Subject: Bug fixes (bzr r15392.1.11) --- src/live_effects/lpe-copy_rotate.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 61ea7e171..fbc7933e7 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -119,7 +119,17 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) } previous_num_copies = num_copies; } - + SPObject *elemref = NULL; + char * id = g_strdup(Glib::ustring("rotated-").append("1").append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + guint counter = 0; + while(elemref = document->getObjectById(id)) { + if (SP_ITEM(elemref)->isHidden()) { + items.push_back(id); + } + id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + counter++; + } + g_free(id); double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); @@ -354,7 +364,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if (copies_to_360) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if (fuse_paths && rotation_angle * num_copies > 360 && rotation_angle > 0) { + if (fuse_paths && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { num_copies.param_set_value(floor(360/rotation_angle)); } if (fuse_paths && copies_to_360) { @@ -616,7 +626,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if (num_copies == 1 && !fuse_paths) { + if ((num_copies == 1 && !fuse_paths) || split_items) { return pwd2_in; } -- cgit v1.2.3 From 2630f312c74dd106a6f911045dbaed401bd12bbc Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 24 Jan 2017 08:18:21 +0100 Subject: Bug fixes (bzr r15295.1.65) --- src/live_effects/lpe-mirror_symmetry.cpp | 54 -------------------------------- src/live_effects/lpe-mirror_symmetry.h | 2 -- 2 files changed, 56 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 0defeb900..f35f3096f 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -345,60 +345,6 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) processObjects(LPE_ERASE); } -void -LPEMirrorSymmetry::processObjects(LpeAction lpe_action) -{ - SPDocument * document = SP_ACTIVE_DOCUMENT; - for (std::vector::iterator el_it = items.begin(); - el_it != items.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - SPObject *elemref = NULL; - if (elemref = document->getObjectById(id)) { - Inkscape::XML::Node * elemnode = elemref->getRepr(); - std::vector item_list; - item_list.push_back(SP_ITEM(elemref)); - std::vector item_to_select; - std::vector item_selected; - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - if (elemnode->attribute("inkscape:path-effect")) { - sp_item_list_to_curves(item_list, item_selected, item_to_select); - } - elemnode->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - elemref->deleteObject(); - break; - - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemnode->setAttribute("style", css_str.c_str()); - break; - - default: - break; - } - } - } - if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { - items.clear(); - } -} - - void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 5a6db5062..592a11894 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -47,7 +47,6 @@ public: virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); - void processObjects(LpeAction lpe_action); void toMirror(Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneD(SPObject *origin, SPObject *dest, bool live, bool root); @@ -67,7 +66,6 @@ private: PointParam center_point; TextParam id_origin; Geom::Point previous_center; - std::vector items; SPObject * container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 7fecbddd1fb8b57f9c6efd3204645e33d9b38d09 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 24 Jan 2017 10:32:24 +0100 Subject: update to trunk (bzr r15356.1.18) --- src/live_effects/effect.cpp | 88 +++++++- src/live_effects/effect.h | 20 +- src/live_effects/lpe-copy_rotate.cpp | 306 ++++++++++++++++++++++++++- src/live_effects/lpe-copy_rotate.h | 14 ++ src/live_effects/lpe-measure-line.cpp | 66 +----- src/live_effects/lpe-measure-line.h | 8 - src/live_effects/lpe-mirror_symmetry.cpp | 342 +++++++++++++++++++++++++------ src/live_effects/lpe-mirror_symmetry.h | 13 +- src/live_effects/parameter/bool.cpp | 3 +- src/live_effects/parameter/text.cpp | 3 +- 10 files changed, 707 insertions(+), 156 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 9d9381294..50e2aa353 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -70,6 +70,8 @@ #include "ui/tools/node-tool.h" #include "ui/tools-switch.h" #include "knotholder.h" +#include "path-chemistry.h" +#include "xml/sp-css-attr.h" #include "live_effects/lpeobject.h" #include "display/curve.h" @@ -356,6 +358,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), + sp_shape(NULL), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -392,15 +395,15 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector sNP) +Effect::setCurrentZoom(double cZ) { - selectedNodesPoints = sNP; + current_zoom = cZ; } void -Effect::setCurrentZoom(double cZ) +Effect::setSelectedNodePoints(std::vector sNP) { - current_zoom = cZ; + selectedNodesPoints = sNP; } bool @@ -423,6 +426,74 @@ Effect::isNodePointSelected(Geom::Point const &nodePoint) const return false; } +void +Effect::processObjects(LpeAction lpe_action) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + for (std::vector::iterator el_it = items.begin(); + el_it != items.end(); ++el_it) { + const char * id = *el_it; + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + Inkscape::XML::Node * elemnode = elemref->getRepr(); + std::vector item_list; + item_list.push_back(SP_ITEM(elemref)); + std::vector item_to_select; + std::vector item_selected; + SPCSSAttr *css; + Glib::ustring css_str; + switch (lpe_action){ + case LPE_TO_OBJECTS: + if (SP_ITEM(elemref)->isHidden()) { + elemref->deleteObject(); + } else { + if (elemnode->attribute("inkscape:path-effect")) { + sp_item_list_to_curves(item_list, item_selected, item_to_select); + } + elemnode->setAttribute("sodipodi:insensitive", NULL); + } + break; + + case LPE_ERASE: + elemref->deleteObject(); + break; + + case LPE_VISIBILITY: + css = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); + if (!this->isVisible()/* && std::strcmp(elemref->getId(),sp_lpe_item->getId()) != 0*/) { + css->setAttribute("display", "none"); + } else { + css->setAttribute("display", NULL); + } + sp_repr_css_write_string(css,css_str); + elemnode->setAttribute("style", css_str.c_str()); + break; + + default: + break; + } + } + } + if (lpe_action == LPE_ERASE || lpe_action == LPE_TO_OBJECTS) { + items.clear(); + } +} + +void Effect::setCurrentShape(SPShape * shape){ + if(shape){ + sp_shape = shape; + if (!(sp_curve = sp_shape->getCurve())) { + // oops + return; + } + pathvector_before_effect = sp_curve->get_pathvector(); + } +} + /** * Is performed each time before the effect is updated. */ @@ -446,8 +517,12 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector();*/ + sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); + pathvector_before_effect = sp_curve->get_pathvector(); + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + setCurrentShape(shape); + } doOnApply(lpeitem); } @@ -457,6 +532,7 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ + setCurrentShape(shape); sp_curve = shape->getCurve(); pathvector_before_effect = sp_curve->get_pathvector(); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1997ff0ca..f5e41d50e 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -19,7 +19,7 @@ class SPDocument; class SPDesktop; class SPItem; -class LivePathEffectObject; +class LivePathEffectObject; class SPLPEItem; class KnotHolder; class KnotHolderEntity; @@ -44,6 +44,12 @@ enum LPEPathFlashType { DEFAULT }; +enum LpeAction { + LPE_ERASE = 0, + LPE_TO_OBJECTS, + LPE_VISIBILITY +}; + class Effect { public: static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); @@ -73,6 +79,9 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); + SPShape * getCurrentShape(){ return sp_shape; }; + void setCurrentShape(SPShape * shape); + void processObjects(LpeAction lpe_action); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, @@ -125,7 +134,9 @@ public: bool apply_to_clippath_and_mask; bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; - + BoolParam is_visible; + SPCurve * sp_curve; + Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); @@ -150,7 +161,6 @@ protected: bool _provides_knotholder_entities; int oncanvasedit_it; - BoolParam is_visible; bool show_orig_path; // set this to true in derived effects to automatically have the original // path displayed as helperpath @@ -164,10 +174,10 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. + std::vector items; double current_zoom; std::vector selectedNodesPoints; - SPCurve * sp_curve; - Geom::PathVector pathvector_before_effect; private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 813f25d3d..fbc7933e7 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -17,6 +17,13 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/intersection-graph.h> #include "live_effects/lpe-copy_rotate.h" +#include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include "style.h" +#include "helper/geom.h" +#include "xml/sp-css-attr.h" +#include "path-chemistry.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -45,9 +52,11 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : starting_angle(_("Starting angle"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), + split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), fuse_paths(_("Kaleidoskope"), _("Kaleidoskope by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), join_paths(_("Join paths"), _("Join paths, use fill-rule: evenodd for best result"), "join_paths", &wr, this, false), + split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -56,15 +65,21 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&copies_to_360); registerParameter(&fuse_paths); registerParameter(&join_paths); + registerParameter(&split_items); registerParameter(&starting_angle); registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); + registerParameter(&split_gap); registerParameter(&origin); - + split_gap.param_set_range(-999999.0, 999999.0); + split_gap.param_set_increments(0.1, 0.1); + split_gap.param_set_digits(5); + num_copies.param_set_range(0, 999999); num_copies.param_make_integer(true); - num_copies.param_set_range(0, 1000); apply_to_clippath_and_mask = true; + previous_num_copies = num_copies; + reset = false; } LPECopyRotate::~LPECopyRotate() @@ -72,6 +87,207 @@ LPECopyRotate::~LPECopyRotate() } +void +LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) +{ + if (split_items) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + items.clear(); + container = dynamic_cast(sp_lpe_item->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; + } + if (previous_num_copies != num_copies) { + gint numcopies_gap = previous_num_copies - num_copies; + if (numcopies_gap > 0 && num_copies != 0) { + guint counter = num_copies - 1; + while (numcopies_gap > 0) { + const char * id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + if (!id || strlen(id) == 0) { + return; + } + SPObject *elemref = NULL; + if (elemref = document->getObjectById(id)) { + SP_ITEM(elemref)->setHidden(true); + } + counter++; + numcopies_gap--; + } + } + previous_num_copies = num_copies; + } + SPObject *elemref = NULL; + char * id = g_strdup(Glib::ustring("rotated-").append("1").append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + guint counter = 0; + while(elemref = document->getObjectById(id)) { + if (SP_ITEM(elemref)->isHidden()) { + items.push_back(id); + } + id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + counter++; + } + g_free(id); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; + Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; + Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); + if (fuse_paths) { + size_t rest = 0; + for (size_t i = 1; i < num_copies; ++i) { + Geom::Affine r = Geom::identity(); + Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); + if( rest%2 == 0) { + r *= Geom::Rotate(Geom::Angle(dir)).inverse(); + r *= Geom::Scale(1, -1); + r *= Geom::Rotate(Geom::Angle(dir)); + } + Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); + Geom::Affine t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + if( rest%2 == 0) { + t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); + } + t *= sp_lpe_item->transform; + toItem(t, i-1, reset); + rest ++; + } + } else { + for (size_t i = 1; i < num_copies; ++i) { + Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); + Geom::Affine t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + t *= sp_lpe_item->transform; + toItem(t, i - 1, reset); + } + } + reset = false; + } else { + processObjects(LPE_ERASE); + items.clear(); + } + + std::cout << previous_num_copies << "previous_num_copies\n"; + std::cout << num_copies << "num_copies\n"; +} + +void +LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneD(*obj_it, dest_child, false, reset); + index++; + } + } + SPShape * shape = SP_SHAPE(origin); + SPPath * path = SP_PATH(dest); + if (!path && !SP_IS_GROUP(dest)) { + Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + path = SP_PATH(dest); + } + if (path && shape) { + SPCurve *c = NULL; + if (root) { + c = new SPCurve(); + c->set_pathvector(pathvector_before_effect); + } else { + c = shape->getCurve(); + } + if (c) { + path->setCurve(c, TRUE); + c->unref(); + } else { + dest->getRepr()->setAttribute("d", NULL); + } + if (reset) { + dest->getRepr()->setAttribute("style", shape->getRepr()->attribute("style")); + } + } +} + +void +LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + const char * elemref_id = g_strdup(Glib::ustring("rotated-").append(std::to_string(i)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + items.push_back(elemref_id); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = document->getObjectById(elemref_id)) { + phantom = elemref->getRepr(); + } else { + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + std::vector attrs; + attrs.push_back("inkscape:path-effect"); + attrs.push_back("inkscape:original-d"); + attrs.push_back("sodipodi:type"); + attrs.push_back("sodipodi:rx"); + attrs.push_back("sodipodi:ry"); + attrs.push_back("sodipodi:cx"); + attrs.push_back("sodipodi:cy"); + attrs.push_back("sodipodi:end"); + attrs.push_back("sodipodi:start"); + attrs.push_back("inkscape:flatsided"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:rounded"); + attrs.push_back("sodipodi:arg1"); + attrs.push_back("sodipodi:arg2"); + attrs.push_back("sodipodi:r1"); + attrs.push_back("sodipodi:r2"); + attrs.push_back("sodipodi:sides"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("sodipodi:argument"); + attrs.push_back("sodipodi:expansion"); + attrs.push_back("sodipodi:radius"); + attrs.push_back("sodipodi:revolution"); + attrs.push_back("sodipodi:t0"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("x"); + attrs.push_back("y"); + attrs.push_back("rx"); + attrs.push_back("ry"); + attrs.push_back("width"); + attrs.push_back("height"); + phantom->setAttribute("id", elemref_id); + for(const char * attr : attrs) { + phantom->setAttribute(attr, NULL); + } + } + if (!elemref) { + elemref = container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, reset); + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + SP_ITEM(elemref)->setHidden(false); + if (elemref->parent != container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", elemref_id); + container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + } +} + +void +LPECopyRotate::resetStyles(){ + reset = true; + doAfterEffect(sp_lpe_item); +} + Gtk::Widget * LPECopyRotate::newWidget() { // use manage here, because after deletion of Effect object, others might @@ -81,7 +297,15 @@ Gtk::Widget * LPECopyRotate::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); vbox->set_spacing(2); - + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); + vbox_expander->set_border_width(0); + vbox_expander->set_spacing(2); + Gtk::Button * reset_button = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset styles")))); + reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPECopyRotate::resetStyles)); + reset_button->set_size_request(140,30); + vbox->pack_start(*hbox, true,true,2); + hbox->pack_start(*reset_button, false, false,2); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { @@ -125,11 +349,11 @@ void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); } + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); } void @@ -140,17 +364,17 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if (copies_to_360) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if (fuse_paths && rotation_angle * num_copies > 360 && rotation_angle > 0) { + if (fuse_paths && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { num_copies.param_set_value(floor(360/rotation_angle)); } if (fuse_paths && copies_to_360) { - num_copies.param_set_increments(2,2); + num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); rotation_angle.param_set_value(360.0/(double)num_copies); } } else { - num_copies.param_set_increments(1,1); + num_copies.param_set_increments(1.0, 10.0); } if (dist_angle_handle < 1.0) { @@ -352,12 +576,57 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s tmp_path.clear(); } +Geom::PathVector +LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) +{ + Geom::PathVector path_out; + if (split_items && (fuse_paths || join_paths)) { + if (num_copies == 0) { + return path_out; + } + path_out = pathv_to_linear_and_cubic_beziers(path_in); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::OptRect bbox = sp_lpe_item->geometricBounds(); + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; + Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; + Geom::Path divider = Geom::Path(line_start); + divider.appendNew((Geom::Point)origin); + divider.appendNew(line_end); + divider.close(); + Geom::PathVector triangle; + triangle.push_back(divider); + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(triangle, path_out); + if (pig && ! path_out.empty() && !triangle.empty()) { + //TODO: Here can produce a crash because some knows problems in new boolops code + path_out = pig->getIntersection(); + } + Geom::Affine r = Geom::identity(); + Geom::Point dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); + Geom::Point gap = dir * split_gap; + r *= Geom::Translate(gap); + path_out *= r; + } else { + // default behavior + for (unsigned int i=0; i < path_in.size(); i++) { + Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); + Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); + Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); + // add the output path vector to the already accumulated vector: + for (unsigned int j=0; j < path.size(); j++) { + path_out.push_back(path[j]); + } + } + } + return pathv_to_linear_and_cubic_beziers(path_out); +} + Geom::Piecewise > LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { using namespace Geom; - if (num_copies == 1 && !fuse_paths) { + if ((num_copies == 1 && !fuse_paths) || split_items) { return pwd2_in; } @@ -373,10 +642,10 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p divider.appendNew(line_end); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); + PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001)); if (fuse_paths) { Geom::PathVector path_out; Geom::PathVector tmp_path; - PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -403,7 +672,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p output = paths_to_pw(path_out); } } else { - Geom::PathVector output_pv = path_from_piecewise(output , 0.01); + Geom::PathVector output_pv; for (int i = 0; i < num_copies; ++i) { Rotate rot(-rad_from_deg(rotation_angle * i)); Affine t = pre * rot * Translate(origin); @@ -449,6 +718,23 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } +void +LPECopyRotate::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + processObjects(LPE_VISIBILITY); +} + +void +LPECopyRotate::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + //unset "erase_extra_objects" hook on sp-lpe-item.cpp + if (!erase_extra_objects) { + processObjects(LPE_TO_OBJECTS); + return; + } + processObjects(LPE_ERASE); +} + } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index c2ae2daf1..dbec2e1c3 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -15,6 +15,8 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" #include "live_effects/lpegroupbbox.h" @@ -26,13 +28,20 @@ public: LPECopyRotate(LivePathEffectObject *lpeobject); virtual ~LPECopyRotate(); virtual void doOnApply (SPLPEItem const* lpeitem); + virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); + void toItem(Geom::Affine transform, size_t i, bool reset); + void cloneD(SPObject *origin, SPObject *dest, bool root, bool reset); + void resetStyles(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -42,9 +51,11 @@ private: ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; + ScalarParam split_gap; BoolParam copies_to_360; BoolParam fuse_paths; BoolParam join_paths; + BoolParam split_items; Geom::Point A; Geom::Point B; Geom::Point dir; @@ -52,6 +63,9 @@ private: Geom::Point rot_pos; Geom::Point previous_start_point; double dist_angle_handle; + double previous_num_copies; + bool reset; + SPObject * container; LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); }; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index af2a8e919..ef87be81c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -21,7 +21,9 @@ #include "svg/svg-color.h" #include "svg/svg.h" #include "display/curve.h" +#include "helper/geom.h" #include "2geom/affine.h" +#include "path-chemistry.h" #include "style.h" #include "sp-root.h" #include "sp-defs.h" @@ -165,12 +167,6 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : LPEMeasureLine::~LPEMeasureLine() {} -void swap(Geom::Point &A, Geom::Point &B){ - Geom::Point tmp = A; - A = B; - B = tmp; -} - void LPEMeasureLine::createArrowMarker(const char * mode) { @@ -229,7 +225,7 @@ LPEMeasureLine::createArrowMarker(const char * mode) elemref = SP_OBJECT(document->getDefs()->appendChildRepr(arrow)); Inkscape::GC::release(arrow); } - elements.push_back(mode); + items.push_back(mode); } void @@ -369,7 +365,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl copy->setAttribute("id", id); elemref = elemref_copy; } - elements.push_back(id); + items.push_back(id); Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { anotation_width = bounds->width() * 1.4; @@ -483,7 +479,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, b elemref->deleteObject(); copy->setAttribute("id", id); } - elements.push_back(id); + items.push_back(id); } void @@ -535,7 +531,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) sp_lpe_item->getCurrentLPE() != this){ return; } - elements.clear(); + items.clear(); start_stored = start; end_stored = end; Geom::Point hstart = start; @@ -680,60 +676,12 @@ LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) //unset "erase_extra_objects" hook on sp-lpe-item.cpp if (!erase_extra_objects) { processObjects(LPE_TO_OBJECTS); - elements.clear(); + items.clear(); return; } processObjects(LPE_ERASE); } -void -LPEMeasureLine::processObjects(LpeAction lpe_action) -{ - SPDocument * document = SP_ACTIVE_DOCUMENT; - for (std::vector::iterator el_it = elements.begin(); - el_it != elements.end(); ++el_it) { - const char * id = *el_it; - if (!id || strlen(id) == 0) { - return; - } - SPObject *elemref = NULL; - if (elemref = document->getObjectById(id)) { - SPCSSAttr *css; - Glib::ustring css_str; - switch (lpe_action){ - case LPE_TO_OBJECTS: - elemref->getRepr()->setAttribute("inkscape:path-effect", NULL); - elemref->getRepr()->setAttribute("sodipodi:insensitive", NULL); - break; - - case LPE_ERASE: - if (std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - elemref->deleteObject(); - } - break; - - case LPE_VISIBILITY: - css = sp_repr_css_attr_new(); - sp_repr_css_attr_add_from_string(css, elemref->getRepr()->attribute("style")); - if (!this->isVisible() && std::strcmp(elemref->getId(),id_origin.param_getSVGValue()) != 0) { - css->setAttribute("display", "none"); - } else { - css->setAttribute("display", NULL); - } - sp_repr_css_write_string(css,css_str); - elemref->getRepr()->setAttribute("style", css_str.c_str()); - break; - - default: - break; - } - } - } - if (lpe_action == LPE_ERASE) { - elements.clear(); - } -} - Gtk::Widget *LPEMeasureLine::newWidget() { // use manage here, because after deletion of Effect object, others might diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index c69921a4d..724c0d924 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -35,12 +35,6 @@ enum OrientationMethod { OM_END }; -enum LpeAction { - LPE_ERASE = 0, - LPE_TO_OBJECTS, - LPE_VISIBILITY -}; - class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); @@ -51,7 +45,6 @@ public: virtual void doEffect (SPCurve * curve){}; //stop the chain virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - void processObjects(LpeAction lpe_action); void createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows = false); void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); @@ -92,7 +85,6 @@ private: double arrow_gap; Geom::Point start_stored; Geom::Point end_stored; - std::vector elements; /* Geom::Affine affine_over;*/ LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 61b2b8b5c..7f0a93c52 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -15,11 +15,22 @@ */ #include +#include "live_effects/lpeobject.h" +#include "live_effects/lpeobject-reference.h" #include "live_effects/lpe-mirror_symmetry.h" -#include -#include +#include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include "sp-defs.h" #include "helper/geom.h" -#include <2geom/path-intersection.h> +#include "2geom/intersection-graph.h" +#include "2geom/path-intersection.h" +#include "2geom/affine.h" +#include "helper/geom.h" +#include "sp-lpe-item.h" +#include "path-chemistry.h" +#include "style.h" +#include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -40,73 +51,69 @@ MTConverter(ModeTypeData, MT_END); LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), + split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), discard_orig_path(_("Discard original path"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), + split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, _("Adjust start of mirroring")), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, _("Adjust end of mirroring")), - center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")) + center_point(_("Center mirror line"), _("Center mirror line"), "center_point", &wr, this, _("Adjust center of mirroring")), + id_origin("id origin", "store the id of the first LPEItem", "id_origin", &wr, this,"") { show_orig_path = true; registerParameter(&mode); - registerParameter( &discard_orig_path); - registerParameter( &fuse_paths); - registerParameter( &oposite_fuse); - registerParameter( &start_point); - registerParameter( &end_point); - registerParameter( ¢er_point); - previous_center = Geom::Point(0,0); + registerParameter(&split_gap); + registerParameter(&discard_orig_path); + registerParameter(&fuse_paths); + registerParameter(&oposite_fuse); + registerParameter(&split_items); + registerParameter(&start_point); + registerParameter(&end_point); + registerParameter(¢er_point); + registerParameter(&id_origin); + id_origin.param_hide_canvas_text(); + split_gap.param_set_range(-999999.0, 999999.0); + split_gap.param_set_increments(0.1, 0.1); + split_gap.param_set_digits(5); apply_to_clippath_and_mask = true; + previous_center = Geom::Point(0,0); } LPEMirrorSymmetry::~LPEMirrorSymmetry() { } -Gtk::Widget * LPEMirrorSymmetry::newWidget() +void +LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { - // 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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "center_point") { - vbox->pack_start(*widg, true, true, 2); - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); - } - } - } + if (split_items && !discard_orig_path) { + container = dynamic_cast(sp_lpe_item->parent); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); + Inkscape::XML::Node *root_origin = doc->getReprRoot(); + if (root_origin != root) { + return; } - - ++it; + Geom::Line ls((Geom::Point)start_point, (Geom::Point)end_point); + Geom::Affine m = Geom::reflection (ls.vector(), (Geom::Point)start_point); + m = m * sp_lpe_item->transform; + toMirror(m); + } else { + processObjects(LPE_ERASE); + items.clear(); } - return dynamic_cast(vbox); } - void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { + using namespace Geom; original_bbox(lpeitem); //center_point->param_set_liveupdate(false); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); - Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); if (mode == MT_Y) { point_a = Geom::Point(boundingbox_X.min(),center_point[Y]); point_b = Geom::Point(boundingbox_X.max(),center_point[Y]); @@ -172,6 +179,172 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) previous_center = center_point; } +void +LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneD(*obj_it, dest_child, live, false); + index++; + } + } + SPShape * shape = SP_SHAPE(origin); + SPPath * path = SP_PATH(dest); + if (!path && !SP_IS_GROUP(dest)) { + Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); + dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + path = SP_PATH(dest); + } + if (path && shape) { + if ( live) { + SPCurve *c = NULL; + if (root) { + c = new SPCurve(); + c->set_pathvector(pathvector_before_effect); + } else { + c = shape->getCurve(); + } + if (c) { + path->setCurve(c, TRUE); + c->unref(); + } else { + dest->getRepr()->setAttribute("d", NULL); + } + } else { + dest->getRepr()->setAttribute("d", origin->getRepr()->attribute("d")); + } + } +} + +void +LPEMirrorSymmetry::toMirror(Geom::Affine transform) +{ + SPDocument * document = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + const char * id_origin_char = id_origin.param_getSVGValue(); + const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); + items.clear(); + items.push_back(elemref_id); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = document->getObjectById(elemref_id)) { + phantom = elemref->getRepr(); + } else { + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + std::vector attrs; + attrs.push_back("inkscape:path-effect"); + attrs.push_back("inkscape:original-d"); + attrs.push_back("sodipodi:type"); + attrs.push_back("sodipodi:rx"); + attrs.push_back("sodipodi:ry"); + attrs.push_back("sodipodi:cx"); + attrs.push_back("sodipodi:cy"); + attrs.push_back("sodipodi:end"); + attrs.push_back("sodipodi:start"); + attrs.push_back("inkscape:flatsided"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:rounded"); + attrs.push_back("sodipodi:arg1"); + attrs.push_back("sodipodi:arg2"); + attrs.push_back("sodipodi:r1"); + attrs.push_back("sodipodi:r2"); + attrs.push_back("sodipodi:sides"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("sodipodi:argument"); + attrs.push_back("sodipodi:expansion"); + attrs.push_back("sodipodi:radius"); + attrs.push_back("sodipodi:revolution"); + attrs.push_back("sodipodi:t0"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("x"); + attrs.push_back("y"); + attrs.push_back("rx"); + attrs.push_back("ry"); + attrs.push_back("width"); + attrs.push_back("height"); + for(const char * attr : attrs) { + phantom->setAttribute(attr, NULL); + } + } + phantom->setAttribute("id", elemref_id); + if (!elemref) { + elemref = container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + if (elemref->parent != container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", elemref_id); + container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); + } +} + +Gtk::Widget * +LPEMirrorSymmetry::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::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter * param = *it; + if (param->param_key == "id_origin" || param->param_key == "center_point") { + ++it; + continue; + } + Gtk::Widget * widg = param->param_newWidget(); + 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; + } + this->upd_params = false; + return dynamic_cast(vbox); +} + +//TODO: Migrate the tree next function to effect.cpp/h to avoid duplication +void +LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) +{ + processObjects(LPE_VISIBILITY); +} + +void +LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) +{ + //unset "erase_extra_objects" hook on sp-lpe-item.cpp + if (!erase_extra_objects) { + processObjects(LPE_TO_OBJECTS); + return; + } + processObjects(LPE_ERASE); +} + void LPEMirrorSymmetry::transform_multiply(Geom::Affine const& postmul, bool set) { @@ -193,18 +366,26 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); - start_point.param_setValue(point_a, true); + start_point.param_setValue(point_a); start_point.param_update_default(point_a); - end_point.param_setValue(point_b, true); + end_point.param_setValue(point_b); end_point.param_update_default(point_b); center_point.param_setValue(point_c, true); previous_center = center_point; + SPLPEItem * splpeitem = const_cast(lpeitem); + if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet + id_origin.param_setValue(lpeitem->getRepr()->attribute("id")); + id_origin.write_to_SVG(); + } } Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { + if (split_items && !fuse_paths) { + return path_in; + } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector path_out; @@ -214,15 +395,51 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Line line_separation((Geom::Point)start_point, (Geom::Point)end_point); Geom::Affine m = Geom::reflection (line_separation.vector(), (Geom::Point)start_point); - - if (fuse_paths && !discard_orig_path) { + if (split_items && fuse_paths) { + Geom::OptRect bbox = sp_lpe_item->geometricBounds(); + Geom::Path p(Geom::Point(bbox->left(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->top())); + p.close(); + p *= Geom::Translate(bbox->midpoint()).inverse(); + p *= Geom::Scale(1.2); + p *= Geom::Rotate(line_separation.angle()); + p *= Geom::Translate(bbox->midpoint()); + bbox = p.boundsFast(); + p.clear(); + p.start(Geom::Point(bbox->left(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->top())); + p.appendNew(Geom::Point(bbox->right(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->bottom())); + p.appendNew(Geom::Point(bbox->left(), bbox->top())); + p.close(); + p *= Geom::Translate(bbox->midpoint()).inverse(); + p *= Geom::Rotate(line_separation.angle()); + p *= Geom::Translate(bbox->midpoint()); + Geom::Point base(p.pointAt(3)); + if (oposite_fuse) { + base = p.pointAt(0); + } + p *= Geom::Translate(line_separation.pointAt(line_separation.nearestTime(base)) - base); + Geom::PathVector pv_bbox; + pv_bbox.push_back(p); + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(pv_bbox, original_pathv); + if (pig && !original_pathv.empty() && !pv_bbox.empty()) { + path_out = pig->getBminusA(); + } + Geom::Point dir = rot90(unit_vector((Geom::Point)end_point - (Geom::Point)start_point)); + Geom::Point gap = dir * split_gap; + path_out *= Geom::Translate(gap); + } else if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; } - Geom::PathVector tmp_path; + Geom::PathVector tmp_pathvector; double time_start = 0.0; int position = 0; bool end_open = false; @@ -268,11 +485,11 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Path mirror = portion.reversed() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); - if(i!=0) { + if(i != 0) { portion.setFinal(portion.initialPoint()); portion.close(); } - tmp_path.push_back(portion); + tmp_pathvector.push_back(portion); } portion.clear(); } @@ -293,36 +510,33 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) portion.append(mirror); portion = portion.reversed(); if (!original.closed()) { - tmp_path.push_back(portion); + tmp_pathvector.push_back(portion); } else { - if (cs.size() > 1 && tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { - portion.setFinal(tmp_path[0].initialPoint()); - portion.setInitial(tmp_path[0].finalPoint()); - tmp_path[0].append(portion); + if (cs.size() > 1 && tmp_pathvector.size() > 0 && tmp_pathvector[0].size() > 0 ) { + portion.setFinal(tmp_pathvector[0].initialPoint()); + portion.setInitial(tmp_pathvector[0].finalPoint()); + tmp_pathvector[0].append(portion); } else { - tmp_path.push_back(portion); + tmp_pathvector.push_back(portion); } - tmp_path[0].close(); + tmp_pathvector[0].close(); } portion.clear(); } } } if (cs.size() == 0 && position == 1) { - tmp_path.push_back(original); - tmp_path.push_back(original * m); + tmp_pathvector.push_back(original); + tmp_pathvector.push_back(original * m); } - path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); - tmp_path.clear(); + path_out.insert(path_out.end(), tmp_pathvector.begin(), tmp_pathvector.end()); + tmp_pathvector.clear(); } - } - - if (!fuse_paths || discard_orig_path) { + } else if (!fuse_paths || discard_orig_path) { for (size_t i = 0; i < original_pathv.size(); ++i) { path_out.push_back(original_pathv[i] * m); } } - return path_out; } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index b4967173a..592a11894 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -18,8 +18,8 @@ #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" -#include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" #include "live_effects/lpegroupbbox.h" @@ -41,23 +41,32 @@ public: virtual ~LPEMirrorSymmetry(); virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); + virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); + virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); + void toMirror(Geom::Affine transform); + // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); + void cloneD(SPObject *origin, SPObject *dest, bool live, bool root); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: EnumParam mode; + ScalarParam split_gap; BoolParam discard_orig_path; BoolParam fuse_paths; BoolParam oposite_fuse; + BoolParam split_items; PointParam start_point; PointParam end_point; PointParam center_point; + TextParam id_origin; Geom::Point previous_center; - + SPObject * container; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); }; diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index af99ef362..813c06b4e 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -72,7 +72,7 @@ BoolParam::param_newWidget() checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - + param_effect->upd_params = false; return dynamic_cast (checkwdg); } else { return NULL; @@ -82,6 +82,7 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { + param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 8cab68ad0..5c4cdf4c6 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -125,13 +125,14 @@ TextParam::param_newWidget() rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - + param_effect->upd_params = false; return dynamic_cast (rsu); } void TextParam::param_setValue(const Glib::ustring newvalue) { + param_effect->upd_params = true; value = newvalue; if (!_hide_canvas_text) { sp_canvastext_set_text (canvas_text, newvalue.c_str()); -- cgit v1.2.3 From 3867766478056535d7d22e5afd432ca670d9a73f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 24 Jan 2017 10:44:10 +0100 Subject: Fixing update to trunk (bzr r15356.1.20) --- src/live_effects/CMakeLists.txt | 6 + src/live_effects/parameter/item-reference.cpp | 44 +++++ src/live_effects/parameter/item-reference.h | 56 ++++++ src/live_effects/parameter/item.cpp | 246 ++++++++++++++++++++++++++ src/live_effects/parameter/item.h | 79 +++++++++ src/live_effects/parameter/originalitem.cpp | 129 ++++++++++++++ src/live_effects/parameter/originalitem.h | 49 +++++ 7 files changed, 609 insertions(+) create mode 100644 src/live_effects/parameter/item-reference.cpp create mode 100644 src/live_effects/parameter/item-reference.h create mode 100644 src/live_effects/parameter/item.cpp create mode 100644 src/live_effects/parameter/item.h create mode 100644 src/live_effects/parameter/originalitem.cpp create mode 100644 src/live_effects/parameter/originalitem.h (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 784317090..5ffccc7c0 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -60,6 +60,9 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp parameter/filletchamferpointarray.cpp + parameter/item-reference.cpp + parameter/item.cpp + parameter/originalitem.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp parameter/parameter.cpp @@ -142,6 +145,9 @@ set(live_effects_SRC parameter/bool.h parameter/enum.h parameter/filletchamferpointarray.h + parameter/item.h + parameter/item-reference.h + parameter/originalitem.h parameter/originalpath.h parameter/originalpatharray.h parameter/parameter.h diff --git a/src/live_effects/parameter/item-reference.cpp b/src/live_effects/parameter/item-reference.cpp new file mode 100644 index 000000000..a775d93b7 --- /dev/null +++ b/src/live_effects/parameter/item-reference.cpp @@ -0,0 +1,44 @@ +/* + * The reference corresponding to href of LPE Item parameter. + * + * Copyright (C) 2008 Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include "live_effects/parameter/item-reference.h" + +#include "sp-shape.h" +#include "sp-text.h" +#include "sp-item-group.h" + +namespace Inkscape { +namespace LivePathEffect { + +bool ItemReference::_acceptObject(SPObject * const obj) const +{ + if (SP_IS_SHAPE(obj) || SP_IS_TEXT(obj) || SP_IS_GROUP(obj)) { + /* Refuse references to lpeobject */ + if (obj == getOwner()) { + return false; + } + // TODO: check whether the referred item has this LPE applied, if so: deny deny deny! + return URIReference::_acceptObject(obj); + } else { + return false; + } +} + +} // 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/item-reference.h b/src/live_effects/parameter/item-reference.h new file mode 100644 index 000000000..91231455a --- /dev/null +++ b/src/live_effects/parameter/item-reference.h @@ -0,0 +1,56 @@ +#ifndef SEEN_LPE_ITEM_REFERENCE_H +#define SEEN_LPE_ITEM_REFERENCE_H + +/* + * Copyright (C) 2008-2012 Authors + * Authors: Johan Engelen + * Abhishek Sharma + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include + +class SPItem; +namespace Inkscape { +namespace XML { class Node; } + +namespace LivePathEffect { + +/** + * The reference corresponding to href of LPE ItemParam. + */ +class ItemReference : public Inkscape::URIReference { +public: + ItemReference(SPObject *owner) : URIReference(owner) {} + + SPItem *getObject() const { + return (SPItem *)URIReference::getObject(); + } + +protected: + virtual bool _acceptObject(SPObject * const obj) const; + +private: + ItemReference(const ItemReference&); + ItemReference& operator=(const ItemReference&); +}; + +} // namespace LivePathEffect + +} // namespace Inkscape + + + +#endif /* !SEEN_LPE_PATH_REFERENCE_H */ + +/* + 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/item.cpp b/src/live_effects/parameter/item.cpp new file mode 100644 index 000000000..8caea4e26 --- /dev/null +++ b/src/live_effects/parameter/item.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (C) Johan Engelen 2007 + * Abhishek Sharma + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "ui/widget/point.h" +#include + +#include "live_effects/parameter/item.h" +#include "live_effects/effect.h" +#include "svg/svg.h" + +#include "widgets/icon.h" +#include +#include "selection-chemistry.h" +#include "xml/repr.h" +#include "desktop.h" +#include "inkscape.h" +#include "message-stack.h" + +// clipboard support +#include "ui/clipboard.h" +// required for linking to other paths +#include "uri.h" + +#include +#include +#include "ui/icon-names.h" + +namespace Inkscape { + +namespace LivePathEffect { + +ItemParam::ItemParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const gchar * default_value) + : Parameter(label, tip, key, wr, effect), + changed(true), + href(NULL), + ref( (SPObject*)effect->getLPEObj() ) +{ + defvalue = g_strdup(default_value); + ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &ItemParam::ref_changed)); +} + +ItemParam::~ItemParam() +{ + remove_link(); + g_free(defvalue); +} + +void +ItemParam::param_set_default() +{ + param_readSVGValue(defvalue); +} + + +void +ItemParam::param_set_and_write_default() +{ + param_write_to_repr(defvalue); +} + +bool +ItemParam::param_readSVGValue(const gchar * strvalue) +{ + if (strvalue) { + remove_link(); + if (strvalue[0] == '#') { + if (href) + g_free(href); + href = g_strdup(strvalue); + try { + ref.attach(Inkscape::URI(href)); + //lp:1299948 + SPItem* i = ref.getObject(); + if (i) { + linked_modified_callback(i, SP_OBJECT_MODIFIED_FLAG); + } // else: document still processing new events. Repr of the linked object not created yet. + } catch (Inkscape::BadURIException &e) { + g_warning("%s", e.what()); + ref.detach(); + } + } + emit_changed(); + return true; + } + + return false; +} + +gchar * +ItemParam::param_getSVGValue() const +{ + return g_strdup(href); +} + +Gtk::Widget * +ItemParam::param_newWidget() +{ + Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox()); + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-clone"), Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); + static_cast(_widget)->pack_start(*pLabel, true, true); + pLabel->set_tooltip_text(param_tooltip); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &ItemParam::on_link_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Link to item on clipboard")); + + static_cast(_widget)->show_all_children(); + + return dynamic_cast (_widget); +} + +void +ItemParam::emit_changed() +{ + changed = true; + signal_item_changed.emit(); +} + + +void +ItemParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector &hp_vec) +{ +} + + +void +ItemParam::start_listening(SPObject * to) +{ + if ( to == NULL ) { + return; + } + linked_delete_connection = to->connectDelete(sigc::mem_fun(*this, &ItemParam::linked_delete)); + linked_modified_connection = to->connectModified(sigc::mem_fun(*this, &ItemParam::linked_modified)); + if (SP_IS_ITEM(to)) { + linked_transformed_connection = SP_ITEM(to)->connectTransformed(sigc::mem_fun(*this, &ItemParam::linked_transformed)); + } + linked_modified(to, SP_OBJECT_MODIFIED_FLAG); // simulate linked_modified signal, so that path data is updated +} + +void +ItemParam::quit_listening(void) +{ + linked_modified_connection.disconnect(); + linked_delete_connection.disconnect(); + linked_transformed_connection.disconnect(); +} + +void +ItemParam::ref_changed(SPObject */*old_ref*/, SPObject *new_ref) +{ + quit_listening(); + if ( new_ref ) { + start_listening(new_ref); + } +} + +void +ItemParam::remove_link() +{ + if (href) { + ref.detach(); + g_free(href); + href = NULL; + } +} + +void +ItemParam::linked_delete(SPObject */*deleted*/) +{ + quit_listening(); + remove_link(); +} + +void ItemParam::linked_modified(SPObject *linked_obj, guint flags) +{ + linked_modified_callback(linked_obj, flags); +} + +void ItemParam::linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item) +{ + linked_transformed_callback(rel_transf, moved_item); +} + +void +ItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) +{ + emit_changed(); + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + +void +ItemParam::on_link_button_click() +{ + Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + const gchar * iid = cm->getFirstObjectID(); + if (!iid) { + return; + } + + Glib::ustring itemid(iid); + + if (itemid.empty()) { + return; + } + + // add '#' at start to make it an uri. + itemid.insert(itemid.begin(), '#'); + if ( href && strcmp(itemid.c_str(), href) == 0 ) { + // no change, do nothing + return; + } else { + // TODO: + // check if id really exists in document, or only in clipboard document: if only in clipboard then invalid + // check if linking to object to which LPE is applied (maybe delegated to PathReference + + param_write_to_repr(itemid.c_str()); + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Link item parameter to path")); + } +} + +} /* 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/item.h b/src/live_effects/parameter/item.h new file mode 100644 index 000000000..6c719d451 --- /dev/null +++ b/src/live_effects/parameter/item.h @@ -0,0 +1,79 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ITEM_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ITEM_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + + +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/item-reference.h" +#include +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class ItemParam : public Parameter { +public: + ItemParam ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const gchar * default_value = ""); + virtual ~ItemParam(); + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + virtual void param_set_default(); + void param_set_and_write_default(); + virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); + + sigc::signal signal_item_pasted; + sigc::signal signal_item_changed; + bool changed; /* this gets set whenever the path is changed (this is set to true, and then the signal_item_changed signal is emitted). + * the user must set it back to false if she wants to use it sensibly */ +protected: + + gchar * href; // contains link to other object, e.g. "#path2428", NULL if ItemParam contains pathdata itself + ItemReference ref; + sigc::connection ref_changed_connection; + sigc::connection linked_delete_connection; + sigc::connection linked_modified_connection; + sigc::connection linked_transformed_connection; + void ref_changed(SPObject *old_ref, SPObject *new_ref); + void remove_link(); + void start_listening(SPObject * to); + void quit_listening(void); + void linked_delete(SPObject *deleted); + void linked_modified(SPObject *linked_obj, guint flags); + void linked_transformed(Geom::Affine const *rel_transf, SPItem *moved_item); + virtual void linked_modified_callback(SPObject *linked_obj, guint flags); + virtual void linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) {}; + void on_link_button_click(); + + void emit_changed(); + + gchar * defvalue; + +private: + ItemParam(const ItemParam&); + ItemParam& operator=(const ItemParam&); +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp new file mode 100644 index 000000000..053062128 --- /dev/null +++ b/src/live_effects/parameter/originalitem.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) Johan Engelen 2012 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include "live_effects/parameter/originalitem.h" + +#include "widgets/icon.h" +#include +#include +#include + +#include "uri.h" +#include "sp-shape.h" +#include "sp-text.h" +#include "display/curve.h" +#include "live_effects/effect.h" + +#include "inkscape.h" +#include "desktop.h" +#include "selection.h" +#include "ui/icon-names.h" + +namespace Inkscape { + +namespace LivePathEffect { + +OriginalItemParam::OriginalItemParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect) + : ItemParam(label, tip, key, wr, effect, "") +{ +} + +OriginalItemParam::~OriginalItemParam() +{ + +} + +Gtk::Widget * +OriginalItemParam::param_newWidget() +{ + Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); + + { // Label + Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(param_label)); + static_cast(_widget)->pack_start(*pLabel, true, true); + pLabel->set_tooltip_text(param_tooltip); + } + + { // Paste item to link button + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-paste"), Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemParam::on_link_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Link to item")); + } + + { // Select original button + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("edit-select-original", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &OriginalItemParam::on_select_original_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Select original")); + } + + static_cast(_widget)->show_all_children(); + + return dynamic_cast (_widget); +} + +void +OriginalItemParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) +{ + if (!inverse) { + emit_changed(); + SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); + } +} + +void +OriginalItemParam::linked_transformed_callback(Geom::Affine const * /*rel_transf*/, SPItem * /*moved_item*/) +{ +/** \todo find good way to compensate for referenced item transform, like done for normal clones. + * See sp-use.cpp: sp_use_move_compensate */ +} + + +void +OriginalItemParam::on_select_original_button_click() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPItem *original = ref.getObject(); + if (desktop == NULL || original == NULL) { + return; + } + Inkscape::Selection *selection = desktop->getSelection(); + selection->clear(); + selection->set(original); +} + +} /* 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/originalitem.h b/src/live_effects/parameter/originalitem.h new file mode 100644 index 000000000..58d04e05a --- /dev/null +++ b/src/live_effects/parameter/originalitem.h @@ -0,0 +1,49 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINAL_ITEM_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ORIGINAL_ITEM_H + +/* + * Inkscape::LiveItemEffectParameters + * +* Copyright (C) Johan Engelen 2012 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/item.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class OriginalItemParam: public ItemParam { +public: + OriginalItemParam ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect); + virtual ~OriginalItemParam(); + void setInverse(bool inversed) { inverse = inversed; } + bool linksToItem() const { return (href != NULL); } + SPItem * getObject() const { return ref.getObject(); } + + virtual Gtk::Widget * param_newWidget(); + +protected: + virtual void linked_modified_callback(SPObject *linked_obj, guint flags); + virtual void linked_transformed_callback(Geom::Affine const *rel_transf, SPItem *moved_item); + + void on_select_original_button_click(); + +private: + bool inverse; + OriginalItemParam(const OriginalItemParam&); + OriginalItemParam& operator=(const OriginalItemParam&); +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 7b1f640dd11a7580f04ae50d2c0d7d62e301d9d7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 24 Jan 2017 12:00:13 +0100 Subject: Fix for bug on clone original LPE (bzr r15442) --- src/live_effects/lpe-clone-original.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index db697552a..31d5bab65 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -26,7 +26,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), inverse(_("Inverse clone"), _("Use LPE item as origin"), "inverse", &wr, this, false), d(_("Clone shape -d-"), _("Clone shape -d-"), "d", &wr, this, true), - transform(_("Clone transforms"), _("Clone transforms"), "d", &wr, this, true), + transform(_("Clone transforms"), _("Clone transforms"), "transform", &wr, this, true), fill(_("Clone fill"), _("Clone fill"), "fill", &wr, this, false), stroke(_("Clone stroke"), _("Clone stroke"), "stroke", &wr, this, false), paintorder(_("Clone paint order"), _("Clone paint order"), "paintorder", &wr, this, false), @@ -59,20 +59,6 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : preserve_affine = Geom::identity(); } -bool hasLinkedTransform( const char * attributes) { - gchar ** attarray = g_strsplit(attributes, ",", 0); - gchar ** iter = attarray; - bool has_linked_transform = false; - while (*iter != NULL) { - const char* attribute = (*iter); - if ( std::strcmp(attribute, "transform") == 0 ) { - has_linked_transform = true; - } - iter++; - } - return has_linked_transform; -} - void LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) { @@ -237,14 +223,18 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ } preserve_position_changed = preserve_position; } - Glib::ustring attr = Glib::ustring(attributes.param_getSVGValue()).append(","); + Glib::ustring attr = ""; if (d) { attr.append("d,"); } if (transform) { attr.append("transform,"); } - Glib::ustring style_attr = Glib::ustring(style_attributes.param_getSVGValue()).append(","); + attr.append(Glib::ustring(attributes.param_getSVGValue()).append(",")); + if (attr.size() && !Glib::ustring(attributes.param_getSVGValue()).size()) { + attr.erase (attr.size()-1, 1); + } + Glib::ustring style_attr = ""; if (fill) { style_attr.append("fill,").append("fill-rule,"); } @@ -263,6 +253,10 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ if (opacity) { style_attr.append("opacity,"); } + if (style_attr.size() && !Glib::ustring(style_attributes.param_getSVGValue()).size()) { + style_attr.erase (style_attr.size()-1, 1); + } + style_attr.append(Glib::ustring(style_attributes.param_getSVGValue()).append(",")); if (inverse) { cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); } else { -- cgit v1.2.3 From 0b1d6a94ad7b8caf7bc9bf7ef7c87ef7bad9ac43 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 24 Jan 2017 12:28:51 +0100 Subject: Fix a translation bug in rotate copies LPE (bzr r15443) --- src/live_effects/lpe-copy_rotate.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index fbc7933e7..42e055062 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -604,8 +604,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) Geom::Affine r = Geom::identity(); Geom::Point dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); Geom::Point gap = dir * split_gap; - r *= Geom::Translate(gap); - path_out *= r; + path_out *= Geom::Translate(gap); } else { // default behavior for (unsigned int i=0; i < path_in.size(); i++) { -- cgit v1.2.3 From 66d65a21fddda6f20cc992e1edb4b4a8a5eb6368 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 25 Jan 2017 12:32:06 +0100 Subject: Retain clone position in clone Original LPE (bzr r15447) --- src/live_effects/lpe-clone-original.cpp | 21 ++++++++++++++++++++- src/live_effects/lpe-clone-original.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 31d5bab65..e70575986 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -34,7 +34,8 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : filter(_("Clone filter"), _("Clone filter"), "filter", &wr, this, false), attributes("Attributes linked", "Attributes linked, comma separated atributes", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked, comma separated atributes", "style_attributes", &wr, this,""), - expanded(false) + expanded(false), + origin(Geom::Point(0,0)) { registerParameter(&linked_path); registerParameter(&linked_item); @@ -259,8 +260,26 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ style_attr.append(Glib::ustring(style_attributes.param_getSVGValue()).append(",")); if (inverse) { cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); + Geom::OptRect bbox = SP_ITEM(sp_lpe_item)->geometricBounds(); + if (bbox && preserve_position && origin != Geom::Point(0,0)) { + origin = (*bbox).corner(0) - origin; + SP_ITEM(linked_item.getObject())->transform *= Geom::Translate(origin); + } + bbox = SP_ITEM(sp_lpe_item)->geometricBounds(); + if (bbox && preserve_position) { + origin = (*bbox).corner(0); + } } else { cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); + Geom::OptRect bbox = SP_ITEM(linked_item.getObject())->geometricBounds(); + if (bbox && preserve_position && origin != Geom::Point(0,0)) { + origin = (*bbox).corner(0) - origin; + SP_ITEM(sp_lpe_item)->transform *= Geom::Translate(origin); + } + bbox = SP_ITEM(linked_item.getObject())->geometricBounds(); + if (bbox && preserve_position) { + origin = (*bbox).corner(0); + } } } } diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index 0ff5eb01d..e4328c169 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -46,6 +46,7 @@ private: BoolParam filter; TextParam attributes; TextParam style_attributes; + Geom::Point origin; bool preserve_position_changed; bool expanded; Gtk::Expander * expander; -- cgit v1.2.3 From 3400a57bdeae2cdbfaa47acc19978507f18574ae Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 25 Jan 2017 15:36:46 +0100 Subject: A bit refactor of clone object LPE (bzr r15448) --- src/live_effects/lpe-clone-original.cpp | 34 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index e70575986..04db6171e 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -258,28 +258,18 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ style_attr.erase (style_attr.size()-1, 1); } style_attr.append(Glib::ustring(style_attributes.param_getSVGValue()).append(",")); - if (inverse) { - cloneAttrbutes(SP_OBJECT(sp_lpe_item), linked_item.getObject(), true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); - Geom::OptRect bbox = SP_ITEM(sp_lpe_item)->geometricBounds(); - if (bbox && preserve_position && origin != Geom::Point(0,0)) { - origin = (*bbox).corner(0) - origin; - SP_ITEM(linked_item.getObject())->transform *= Geom::Translate(origin); - } - bbox = SP_ITEM(sp_lpe_item)->geometricBounds(); - if (bbox && preserve_position) { - origin = (*bbox).corner(0); - } - } else { - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); - Geom::OptRect bbox = SP_ITEM(linked_item.getObject())->geometricBounds(); - if (bbox && preserve_position && origin != Geom::Point(0,0)) { - origin = (*bbox).corner(0) - origin; - SP_ITEM(sp_lpe_item)->transform *= Geom::Translate(origin); - } - bbox = SP_ITEM(linked_item.getObject())->geometricBounds(); - if (bbox && preserve_position) { - origin = (*bbox).corner(0); - } + + SPItem * from = inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linked_item.getObject()); + SPItem * to = !inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linked_item.getObject()); + cloneAttrbutes(from, to, true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); + Geom::OptRect bbox = from->geometricBounds(); + if (bbox && preserve_position && origin != Geom::Point(0,0)) { + origin = (*bbox).corner(0) - origin; + to->transform *= Geom::Translate(origin); + } + bbox = from->geometricBounds(); + if (bbox && preserve_position) { + origin = (*bbox).corner(0); } } } -- cgit v1.2.3 From e542da53d6e359cda5d1426533131ee341539412 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 4 Feb 2017 12:21:15 +0100 Subject: Fixes bug 1655160 in stich subpaths Fixed bugs: - https://launchpad.net/bugs/1655160 (bzr r15472) --- src/live_effects/lpe-curvestitch.cpp | 12 +++++------- src/live_effects/lpe-curvestitch.h | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 38cbeaac0..f2fc00aeb 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -54,6 +54,7 @@ LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) : prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); + transformed = false; } LPECurveStitch::~LPECurveStitch() @@ -106,8 +107,9 @@ LPECurveStitch::doEffect_path (Geom::PathVector const & path_in) if (!Geom::are_near(start,end)) { gdouble scaling_y = 1.0; - if (scale_y_rel.get_value()) { + if (scale_y_rel.get_value() || transformed) { scaling_y = (L2(end-start)/scaling)*prop_scale; + transformed = false; } else { scaling_y = prop_scale; } @@ -193,12 +195,8 @@ LPECurveStitch::transform_multiply(Geom::Affine const& postmul, bool set) if (postmul.isTranslation()) { strokepath.param_transform_multiply(postmul, set); } else if (!scale_y_rel.get_value()) { - // this basically means that for this transformation, the result should be the same as normal scaling the result path - // don't know how to do this yet. -// Geom::Affine new_postmul; - //new_postmul.setIdentity(); -// new_postmul.setTranslation(postmul.translation()); -// Effect::transform_multiply(new_postmul, set); + transformed = true; + strokepath.param_transform_multiply(postmul, set); } } diff --git a/src/live_effects/lpe-curvestitch.h b/src/live_effects/lpe-curvestitch.h index c6ea66f6c..0a48046e0 100644 --- a/src/live_effects/lpe-curvestitch.h +++ b/src/live_effects/lpe-curvestitch.h @@ -43,6 +43,7 @@ private: RandomParam endpoint_spacing_variation; ScalarParam prop_scale; BoolParam scale_y_rel; + bool transformed; LPECurveStitch(const LPECurveStitch&); LPECurveStitch& operator=(const LPECurveStitch&); -- cgit v1.2.3 From 4914ec755a1f9ccb1159e7e62a538af79334aac2 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 4 Feb 2017 23:37:20 +0100 Subject: Fixes bug:1654808 along a option to fuse when paths points are coincidant Fixed bugs: - https://launchpad.net/bugs/1654808 (bzr r15474) --- src/live_effects/lpe-fill-between-many.cpp | 10 ++++++++-- src/live_effects/lpe-fill-between-many.h | 1 + src/live_effects/lpe-fill-between-strokes.cpp | 28 +++++++++++++++------------ src/live_effects/lpe-fill-between-strokes.h | 2 ++ 4 files changed, 27 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 1e2eadfdb..2690ce160 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -19,9 +19,11 @@ namespace LivePathEffect { LPEFillBetweenMany::LPEFillBetweenMany(LivePathEffectObject *lpeobject) : Effect(lpeobject), - linked_paths(_("Linked path:"), _("Paths from which to take the original path data"), "linkedpaths", &wr, this) + linked_paths(_("Linked path:"), _("Paths from which to take the original path data"), "linkedpaths", &wr, this), + fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this) { registerParameter( dynamic_cast(&linked_paths) ); + registerParameter( dynamic_cast(&fuse) ); //perceived_path = true; } @@ -46,7 +48,11 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) if (!res_pathv.empty()) { linked_path = linked_path * SP_ITEM(obj)->getRelativeTransform(firstObj); - res_pathv.front().appendNew(linked_path.initialPoint()); + if (!are_near(res_pathv.front().finalPoint(), linked_path.initialPoint(), 0.01) || !fuse) { + res_pathv.front().appendNew(linked_path.initialPoint()); + } else { + linked_path.setInitial(res_pathv.front().finalPoint()); + } res_pathv.front().append(linked_path); } else { firstObj = SP_ITEM(obj); diff --git a/src/live_effects/lpe-fill-between-many.h b/src/live_effects/lpe-fill-between-many.h index 99ee8b15f..552c8037d 100644 --- a/src/live_effects/lpe-fill-between-many.h +++ b/src/live_effects/lpe-fill-between-many.h @@ -24,6 +24,7 @@ public: private: OriginalPathArrayParam linked_paths; + BoolParam fuse; private: LPEFillBetweenMany(const LPEFillBetweenMany&); diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 0dbebdf26..8dc55357f 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -18,11 +18,15 @@ LPEFillBetweenStrokes::LPEFillBetweenStrokes(LivePathEffectObject *lpeobject) : Effect(lpeobject), linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this), second_path(_("Second path:"), _("Second path from which to take the original path data"), "secondpath", &wr, this), - reverse_second(_("Reverse Second"), _("Reverses the second path order"), "reversesecond", &wr, this) + reverse_second(_("Reverse Second"), _("Reverses the second path order"), "reversesecond", &wr, this), + close(_("Close path"), _("Close path"), "close", &wr, this), + fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this) { registerParameter( dynamic_cast(&linked_path) ); registerParameter( dynamic_cast(&second_path) ); registerParameter( dynamic_cast(&reverse_second) ); + registerParameter( dynamic_cast(&close) ); + registerParameter( dynamic_cast(&fuse) ); //perceived_path = true; } @@ -51,22 +55,22 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) } if ( !result_linked_pathv.empty() && !result_second_pathv.empty() && !result_linked_pathv.front().closed() ) { - if (reverse_second.get_value()) - { - result_linked_pathv.front().appendNew(result_second_pathv.front().finalPoint()); - result_linked_pathv.front().append(result_second_pathv.front().reversed()); + if (reverse_second.get_value()) { + result_second_pathv.front() = result_second_pathv.front().reversed(); } - else - { + if (!are_near(result_linked_pathv.front().finalPoint(), result_second_pathv.front().initialPoint(),0.01) || !fuse) { result_linked_pathv.front().appendNew(result_second_pathv.front().initialPoint()); - result_linked_pathv.front().append(result_second_pathv.front()); + } else { + result_second_pathv.front().setInitial(result_linked_pathv.front().finalPoint()); + } + result_linked_pathv.front().append(result_second_pathv.front()); + if (close) { + result_linked_pathv.front().close(); } curve->set_pathvector(result_linked_pathv); - } - else if ( !result_linked_pathv.empty() ) { + } else if ( !result_linked_pathv.empty() ) { curve->set_pathvector(result_linked_pathv); - } - else if ( !result_second_pathv.empty() ) { + } else if ( !result_second_pathv.empty() ) { curve->set_pathvector(result_second_pathv); } } diff --git a/src/live_effects/lpe-fill-between-strokes.h b/src/live_effects/lpe-fill-between-strokes.h index ec57b1852..14eb9167c 100644 --- a/src/live_effects/lpe-fill-between-strokes.h +++ b/src/live_effects/lpe-fill-between-strokes.h @@ -26,6 +26,8 @@ private: OriginalPathParam linked_path; OriginalPathParam second_path; BoolParam reverse_second; + BoolParam close; + BoolParam fuse; private: LPEFillBetweenStrokes(const LPEFillBetweenStrokes&); -- cgit v1.2.3 From 349536d49558ec5841e799eb33a4cbbb3fa9722d Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 5 Feb 2017 16:04:35 +0000 Subject: Fix C++11 errors and warnings with g++-7 Fixed bugs: - https://launchpad.net/bugs/1660992 (bzr r15477) --- src/live_effects/lpeobject-reference.cpp | 4 +++- src/live_effects/parameter/item.cpp | 13 ++++++++----- src/live_effects/parameter/path.cpp | 13 ++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index 1940806bd..83cd6623c 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -6,9 +6,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information. */ +#include "live_effects/lpeobject-reference.h" + #include -#include "live_effects/lpeobject-reference.h" +#include "bad-uri-exception.h" #include "live_effects/lpeobject.h" #include "uri.h" diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 8caea4e26..93cf2b15f 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -5,15 +5,20 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/point.h" +#include "live_effects/parameter/item.h" + #include -#include "live_effects/parameter/item.h" +#include +#include + +#include "bad-uri-exception.h" +#include "ui/widget/point.h" + #include "live_effects/effect.h" #include "svg/svg.h" #include "widgets/icon.h" -#include #include "selection-chemistry.h" #include "xml/repr.h" #include "desktop.h" @@ -25,8 +30,6 @@ // required for linking to other paths #include "uri.h" -#include -#include #include "ui/icon-names.h" namespace Inkscape { diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index f0c494267..dafc6d406 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -5,10 +5,16 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "ui/widget/point.h" +#include "live_effects/parameter/path.h" + #include -#include "live_effects/parameter/path.h" +#include +#include + +#include "bad-uri-exception.h" +#include "ui/widget/point.h" + #include "live_effects/effect.h" #include "svg/svg.h" #include <2geom/svg-path-parser.h> @@ -17,7 +23,6 @@ #include <2geom/d2.h> #include "widgets/icon.h" -#include #include "selection-chemistry.h" #include "xml/repr.h" #include "desktop.h" @@ -44,8 +49,6 @@ #include "ui/tool/multi-path-manipulator.h" #include "ui/tool/shape-record.h" -#include -#include #include "ui/icon-names.h" namespace Inkscape { -- cgit v1.2.3 From a710b1017f72e57de6f48e2597f8a624a2beed46 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Feb 2017 21:29:19 +0100 Subject: Fix crashes when element is not shape in rotate copies and mirror symmetry. remove std::cout uneeded (bzr r15523) --- src/live_effects/lpe-copy_rotate.cpp | 5 +---- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 42e055062..329005878 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -168,9 +168,6 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) processObjects(LPE_ERASE); items.clear(); } - - std::cout << previous_num_copies << "previous_num_copies\n"; - std::cout << num_copies << "num_copies\n"; } void @@ -190,7 +187,7 @@ LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) } SPShape * shape = SP_SHAPE(origin); SPPath * path = SP_PATH(dest); - if (!path && !SP_IS_GROUP(dest)) { + if (!path && !SP_IS_GROUP(dest) && shape) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); path = SP_PATH(dest); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 7f0a93c52..c4101fe79 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -196,7 +196,7 @@ LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root } SPShape * shape = SP_SHAPE(origin); SPPath * path = SP_PATH(dest); - if (!path && !SP_IS_GROUP(dest)) { + if (!path && !SP_IS_GROUP(dest) && shape) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); path = SP_PATH(dest); -- cgit v1.2.3 From b5746c69a30ebacc0e18df50b864e19309a654a1 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Feb 2017 21:39:20 +0100 Subject: Remmove unneded conditional from rotate copies and mirror symmetry (bzr r15524) --- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 329005878..15ee5eb24 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -187,7 +187,7 @@ LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) } SPShape * shape = SP_SHAPE(origin); SPPath * path = SP_PATH(dest); - if (!path && !SP_IS_GROUP(dest) && shape) { + if (shape && !path) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); path = SP_PATH(dest); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index c4101fe79..ad374c5f8 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -196,7 +196,7 @@ LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root } SPShape * shape = SP_SHAPE(origin); SPPath * path = SP_PATH(dest); - if (!path && !SP_IS_GROUP(dest) && shape) { + if (shape && !path) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); path = SP_PATH(dest); -- cgit v1.2.3 From b2f88d76af6a23dea81547f35d9fc8060df255d1 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 18 Feb 2017 12:31:11 +0100 Subject: Fix bug on rotate copies with one line vertical input Fixed bugs: - https://launchpad.net/bugs/1665463 (bzr r15529) --- src/live_effects/lpe-copy_rotate.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 15ee5eb24..26912115e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -374,11 +374,11 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) num_copies.param_set_increments(1.0, 10.0); } - if (dist_angle_handle < 1.0) { - dist_angle_handle = 1.0; - } A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); + if (Geom::are_near(A, B, 0.01)) { + B += Geom::Point(1.0, 0.0); + } dir = unit_vector(B - A); // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) @@ -391,6 +391,9 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) dist_angle_handle = L2(starting_point - origin); } } + if (dist_angle_handle < 1.0) { + dist_angle_handle = 1.0; + } start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); -- cgit v1.2.3 From 50cff32bb7ab2fb2ab618ee5b3f4e31852e5802c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 18 Feb 2017 13:10:14 +0100 Subject: Fix bug 1665595 and prevent other LPE the same bug when using ACTIVE_DOCUMENT Fixed bugs: - https://launchpad.net/bugs/1665595 (bzr r15530) --- src/live_effects/effect.cpp | 3 + src/live_effects/lpe-clone-original.cpp | 3 + src/live_effects/lpe-copy_rotate.cpp | 12 ++- src/live_effects/lpe-measure-line.cpp | 12 +++ src/live_effects/lpe-mirror_symmetry.cpp | 160 +++++++++++++++++-------------- 5 files changed, 114 insertions(+), 76 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 50e2aa353..f664870ec 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -430,6 +430,9 @@ void Effect::processObjects(LpeAction lpe_action) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } for (std::vector::iterator el_it = items.begin(); el_it != items.end(); ++el_it) { const char * id = *el_it; diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 04db6171e..b1cd6b0e5 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -64,6 +64,9 @@ void LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); size_t index = 0; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 26912115e..9ba680cd4 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -92,11 +92,13 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) { if (split_items) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } items.clear(); container = dynamic_cast(sp_lpe_item->parent); - SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); - Inkscape::XML::Node *root_origin = doc->getReprRoot(); + Inkscape::XML::Node *root_origin = document->getReprRoot(); if (root_origin != root) { return; } @@ -174,6 +176,9 @@ void LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); @@ -216,6 +221,9 @@ void LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); const char * elemref_id = g_strdup(Glib::ustring("rotated-").append(std::to_string(i)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); items.push_back(elemref_id); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index ef87be81c..625db150b 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -171,6 +171,9 @@ void LPEMeasureLine::createArrowMarker(const char * mode) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); SPObject *elemref = NULL; Inkscape::XML::Node *arrow = NULL; @@ -232,6 +235,9 @@ void LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); Inkscape::XML::Node *rtext = NULL; double doc_w = document->getRoot()->width.value; @@ -376,6 +382,9 @@ void LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, bool main, bool overflow, bool remove, bool arrows) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); SPObject *elemref = NULL; Inkscape::XML::Node *line = NULL; @@ -500,6 +509,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * splpeitem = const_cast(lpeitem); sp_lpe_item->parent = dynamic_cast(splpeitem->parent); SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Node *root = splpeitem->document->getReprRoot(); Inkscape::XML::Node *root_origin = document->getReprRoot(); if (root_origin != root) { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index ad374c5f8..c31ce7c01 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -87,11 +87,14 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } if (split_items && !discard_orig_path) { container = dynamic_cast(sp_lpe_item->parent); - SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *root = sp_lpe_item->document->getReprRoot(); - Inkscape::XML::Node *root_origin = doc->getReprRoot(); + Inkscape::XML::Node *root_origin = document->getReprRoot(); if (root_origin != root) { return; } @@ -161,20 +164,24 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } } else if ( mode == MT_V){ SPDocument * document = SP_ACTIVE_DOCUMENT; - Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); - Geom::Point sp = Geom::Point(document->getWidth().value("px")/2.0, 0) * transform; - start_point.param_setValue(sp, true); - Geom::Point ep = Geom::Point(document->getWidth().value("px")/2.0, document->getHeight().value("px")) * transform; - end_point.param_setValue(ep, true); - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + if (document) { + Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); + Geom::Point sp = Geom::Point(document->getWidth().value("px")/2.0, 0) * transform; + start_point.param_setValue(sp, true); + Geom::Point ep = Geom::Point(document->getWidth().value("px")/2.0, document->getHeight().value("px")) * transform; + end_point.param_setValue(ep, true); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + } } else { //horizontal page SPDocument * document = SP_ACTIVE_DOCUMENT; - Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); - Geom::Point sp = Geom::Point(0, document->getHeight().value("px")/2.0) * transform; - start_point.param_setValue(sp, true); - Geom::Point ep = Geom::Point(document->getWidth().value("px"), document->getHeight().value("px")/2.0) * transform; - end_point.param_setValue(ep, true); - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + if (document) { + Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); + Geom::Point sp = Geom::Point(0, document->getHeight().value("px")/2.0) * transform; + start_point.param_setValue(sp, true); + Geom::Point ep = Geom::Point(document->getWidth().value("px"), document->getHeight().value("px")/2.0) * transform; + end_point.param_setValue(ep, true); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + } } previous_center = center_point; } @@ -183,6 +190,9 @@ void LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; + if (!document) { + return; + } Inkscape::XML::Document *xml_doc = document->getReprDoc(); if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); @@ -226,67 +236,69 @@ void LPEMirrorSymmetry::toMirror(Geom::Affine transform) { SPDocument * document = SP_ACTIVE_DOCUMENT; - Inkscape::XML::Document *xml_doc = document->getReprDoc(); - const char * id_origin_char = id_origin.param_getSVGValue(); - const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); - items.clear(); - items.push_back(elemref_id); - SPObject *elemref= NULL; - Inkscape::XML::Node *phantom = NULL; - if (elemref = document->getObjectById(elemref_id)) { - phantom = elemref->getRepr(); - } else { - phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); - std::vector attrs; - attrs.push_back("inkscape:path-effect"); - attrs.push_back("inkscape:original-d"); - attrs.push_back("sodipodi:type"); - attrs.push_back("sodipodi:rx"); - attrs.push_back("sodipodi:ry"); - attrs.push_back("sodipodi:cx"); - attrs.push_back("sodipodi:cy"); - attrs.push_back("sodipodi:end"); - attrs.push_back("sodipodi:start"); - attrs.push_back("inkscape:flatsided"); - attrs.push_back("inkscape:randomized"); - attrs.push_back("inkscape:rounded"); - attrs.push_back("sodipodi:arg1"); - attrs.push_back("sodipodi:arg2"); - attrs.push_back("sodipodi:r1"); - attrs.push_back("sodipodi:r2"); - attrs.push_back("sodipodi:sides"); - attrs.push_back("inkscape:randomized"); - attrs.push_back("sodipodi:argument"); - attrs.push_back("sodipodi:expansion"); - attrs.push_back("sodipodi:radius"); - attrs.push_back("sodipodi:revolution"); - attrs.push_back("sodipodi:t0"); - attrs.push_back("inkscape:randomized"); - attrs.push_back("inkscape:randomized"); - attrs.push_back("inkscape:randomized"); - attrs.push_back("x"); - attrs.push_back("y"); - attrs.push_back("rx"); - attrs.push_back("ry"); - attrs.push_back("width"); - attrs.push_back("height"); - for(const char * attr : attrs) { - phantom->setAttribute(attr, NULL); + if (document) { + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + const char * id_origin_char = id_origin.param_getSVGValue(); + const char * elemref_id = g_strdup(Glib::ustring("mirror-").append(id_origin_char).c_str()); + items.clear(); + items.push_back(elemref_id); + SPObject *elemref= NULL; + Inkscape::XML::Node *phantom = NULL; + if (elemref = document->getObjectById(elemref_id)) { + phantom = elemref->getRepr(); + } else { + phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); + std::vector attrs; + attrs.push_back("inkscape:path-effect"); + attrs.push_back("inkscape:original-d"); + attrs.push_back("sodipodi:type"); + attrs.push_back("sodipodi:rx"); + attrs.push_back("sodipodi:ry"); + attrs.push_back("sodipodi:cx"); + attrs.push_back("sodipodi:cy"); + attrs.push_back("sodipodi:end"); + attrs.push_back("sodipodi:start"); + attrs.push_back("inkscape:flatsided"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:rounded"); + attrs.push_back("sodipodi:arg1"); + attrs.push_back("sodipodi:arg2"); + attrs.push_back("sodipodi:r1"); + attrs.push_back("sodipodi:r2"); + attrs.push_back("sodipodi:sides"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("sodipodi:argument"); + attrs.push_back("sodipodi:expansion"); + attrs.push_back("sodipodi:radius"); + attrs.push_back("sodipodi:revolution"); + attrs.push_back("sodipodi:t0"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("inkscape:randomized"); + attrs.push_back("x"); + attrs.push_back("y"); + attrs.push_back("rx"); + attrs.push_back("ry"); + attrs.push_back("width"); + attrs.push_back("height"); + for(const char * attr : attrs) { + phantom->setAttribute(attr, NULL); + } + } + phantom->setAttribute("id", elemref_id); + if (!elemref) { + elemref = container->appendChildRepr(phantom); + Inkscape::GC::release(phantom); + } + cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); + elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + if (elemref->parent != container) { + Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); + copy->setAttribute("id", elemref_id); + container->appendChildRepr(copy); + Inkscape::GC::release(copy); + elemref->deleteObject(); } - } - phantom->setAttribute("id", elemref_id); - if (!elemref) { - elemref = container->appendChildRepr(phantom); - Inkscape::GC::release(phantom); - } - cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); - if (elemref->parent != container) { - Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); - copy->setAttribute("id", elemref_id); - container->appendChildRepr(copy); - Inkscape::GC::release(copy); - elemref->deleteObject(); } } -- cgit v1.2.3 From 43d7f36a9bc533b98ebaf38d24fb2331844a049a Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 20 Feb 2017 22:27:51 +0100 Subject: This patch fixes the bug #1664632. Realy fixes two path parameters what are using "original-d" path data instead "d" on link paths. This parameters are used in a few LPE and all of them get better/wanted result than previous beabiour. With this fixed, we can use the fill between many LPE to archive the wanted effect of a path mixed of Bezier,BSpline and Spiro. Here are a pic with the archived result fixing the bug:https://inkscape.org/en/~jabiertxof/%E2%98%85fix-bug-1664632 Today in IRC logs about 21:30 I do a full inform about this. Fixed bugs: - https://launchpad.net/bugs/1664632 (bzr r15536) --- src/live_effects/parameter/originalpath.cpp | 2 +- src/live_effects/parameter/originalpatharray.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index f7eb48b7a..1e78f7fe1 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -89,7 +89,7 @@ OriginalPathParam::linked_modified_callback(SPObject *linked_obj, guint /*flags* { SPCurve *curve = NULL; if (SP_IS_SHAPE(linked_obj)) { - curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + curve = SP_SHAPE(linked_obj)->getCurve(); } if (SP_IS_TEXT(linked_obj)) { curve = SP_TEXT(linked_obj)->getNormalizedBpath(); diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 083abc94c..693821ed2 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -386,7 +386,7 @@ void OriginalPathArrayParam::setPathVector(SPObject *linked_obj, guint /*flags*/ } SPCurve *curve = NULL; if (SP_IS_SHAPE(linked_obj)) { - curve = SP_SHAPE(linked_obj)->getCurveBeforeLPE(); + curve = SP_SHAPE(linked_obj)->getCurve(); } if (SP_IS_TEXT(linked_obj)) { curve = SP_TEXT(linked_obj)->getNormalizedBpath(); -- cgit v1.2.3 From 960d9ec3486bc6c7a106ce78a25de4b3cac823bf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 21 Feb 2017 15:16:20 +0100 Subject: Improvements to fill between strokes and fill between many LPE's (bzr r15537) --- src/live_effects/lpe-clone-original.cpp | 1 - src/live_effects/lpe-fill-between-many.cpp | 37 +++++++++++++--- src/live_effects/lpe-fill-between-many.h | 7 ++- src/live_effects/lpe-fill-between-strokes.cpp | 63 ++++++++++++++++++++++----- src/live_effects/lpe-fill-between-strokes.h | 7 ++- 5 files changed, 94 insertions(+), 21 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index b1cd6b0e5..440af6f9c 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -347,7 +347,6 @@ void LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) { if (linked_item.linksToItem()) { - bool changed = false; linked_item.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); } } diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 2690ce160..2e1fe0dc1 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -4,13 +4,13 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include #include "live_effects/lpe-fill-between-many.h" #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +#include "svg/svg.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -20,11 +20,17 @@ namespace LivePathEffect { LPEFillBetweenMany::LPEFillBetweenMany(LivePathEffectObject *lpeobject) : Effect(lpeobject), linked_paths(_("Linked path:"), _("Paths from which to take the original path data"), "linkedpaths", &wr, this), - fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this) + fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this, false), + allow_transforms(_("Allow transforms"), _("Allow transforms"), "allow_transforms", &wr, this, false), + join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true), + close(_("Close"), _("Close path"), "close", &wr, this, true) { registerParameter( dynamic_cast(&linked_paths) ); registerParameter( dynamic_cast(&fuse) ); - //perceived_path = true; + registerParameter( dynamic_cast(&allow_transforms) ); + registerParameter( dynamic_cast(&join) ); + registerParameter( dynamic_cast(&close) ); + transformmultiply = false; } LPEFillBetweenMany::~LPEFillBetweenMany() @@ -46,7 +52,7 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) linked_path = (*iter)->_pathvector.front(); } - if (!res_pathv.empty()) { + if (!res_pathv.empty() && join) { linked_path = linked_path * SP_ITEM(obj)->getRelativeTransform(firstObj); if (!are_near(res_pathv.front().finalPoint(), linked_path.initialPoint(), 0.01) || !fuse) { res_pathv.front().appendNew(linked_path.initialPoint()); @@ -56,19 +62,40 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) res_pathv.front().append(linked_path); } else { firstObj = SP_ITEM(obj); + if (close && !join) { + linked_path.close(); + } res_pathv.push_back(linked_path); } } } - if (!res_pathv.empty()) { + if (!res_pathv.empty() && close) { res_pathv.front().close(); } if (res_pathv.empty()) { res_pathv = curve->get_pathvector(); } + if(!allow_transforms && !transformmultiply) { + Geom::Affine affine = Geom::identity(); + sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &affine); + res_pathv *= affine.inverse(); + } + if(transformmultiply) { + transformmultiply = false; + } curve->set_pathvector(res_pathv); } +void +LPEFillBetweenMany::transform_multiply(Geom::Affine const& postmul, bool set) +{ + if(!allow_transforms && sp_lpe_item) { + SP_ITEM(sp_lpe_item)->transform *= postmul.inverse(); + transformmultiply = true; + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); + } +} + } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fill-between-many.h b/src/live_effects/lpe-fill-between-many.h index 552c8037d..fe824e936 100644 --- a/src/live_effects/lpe-fill-between-many.h +++ b/src/live_effects/lpe-fill-between-many.h @@ -19,13 +19,16 @@ class LPEFillBetweenMany : public Effect { public: LPEFillBetweenMany(LivePathEffectObject *lpeobject); virtual ~LPEFillBetweenMany(); - + virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual void doEffect (SPCurve * curve); private: OriginalPathArrayParam linked_paths; BoolParam fuse; - + BoolParam allow_transforms; + BoolParam join; + BoolParam close; + bool transformmultiply; private: LPEFillBetweenMany(const LPEFillBetweenMany&); LPEFillBetweenMany& operator=(const LPEFillBetweenMany&); diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 8dc55357f..43fef4288 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -8,6 +8,7 @@ #include "display/curve.h" #include "sp-shape.h" #include "sp-text.h" +#include "svg/svg.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -19,15 +20,19 @@ LPEFillBetweenStrokes::LPEFillBetweenStrokes(LivePathEffectObject *lpeobject) : linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this), second_path(_("Second path:"), _("Second path from which to take the original path data"), "secondpath", &wr, this), reverse_second(_("Reverse Second"), _("Reverses the second path order"), "reversesecond", &wr, this), - close(_("Close path"), _("Close path"), "close", &wr, this), - fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this) + fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this, false), + allow_transforms(_("Allow transforms"), _("Allow transforms"), "allow_transforms", &wr, this, false), + join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true), + close(_("Close"), _("Close path"), "close", &wr, this, true) { registerParameter( dynamic_cast(&linked_path) ); registerParameter( dynamic_cast(&second_path) ); registerParameter( dynamic_cast(&reverse_second) ); - registerParameter( dynamic_cast(&close) ); registerParameter( dynamic_cast(&fuse) ); - //perceived_path = true; + registerParameter( dynamic_cast(&allow_transforms) ); + registerParameter( dynamic_cast(&join) ); + registerParameter( dynamic_cast(&close) ); + transformmultiply = false; } LPEFillBetweenStrokes::~LPEFillBetweenStrokes() @@ -38,6 +43,13 @@ LPEFillBetweenStrokes::~LPEFillBetweenStrokes() void LPEFillBetweenStrokes::doEffect (SPCurve * curve) { if (curve) { + Geom::Affine affine = Geom::identity(); + if(!allow_transforms && !transformmultiply) { + sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &affine); + } + if(transformmultiply) { + transformmultiply = false; + } if ( linked_path.linksToPath() && second_path.linksToPath() && linked_path.getObject() && second_path.getObject() ) { Geom::PathVector linked_pathv = linked_path.get_pathvector(); Geom::PathVector second_pathv = second_path.get_pathvector(); @@ -58,19 +70,30 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) if (reverse_second.get_value()) { result_second_pathv.front() = result_second_pathv.front().reversed(); } - if (!are_near(result_linked_pathv.front().finalPoint(), result_second_pathv.front().initialPoint(),0.01) || !fuse) { - result_linked_pathv.front().appendNew(result_second_pathv.front().initialPoint()); + if (join) { + if (!are_near(result_linked_pathv.front().finalPoint(), result_second_pathv.front().initialPoint(),0.01) || !fuse) { + result_linked_pathv.front().appendNew(result_second_pathv.front().initialPoint()); + } else { + result_second_pathv.front().setInitial(result_linked_pathv.front().finalPoint()); + } + result_linked_pathv.front().append(result_second_pathv.front()); + if (close) { + result_linked_pathv.front().close(); + } } else { - result_second_pathv.front().setInitial(result_linked_pathv.front().finalPoint()); - } - result_linked_pathv.front().append(result_second_pathv.front()); - if (close) { - result_linked_pathv.front().close(); + if (close) { + result_linked_pathv.front().close(); + result_second_pathv.front().close(); + } + result_linked_pathv.push_back(result_second_pathv.front()); } + result_linked_pathv *= affine.inverse(); curve->set_pathvector(result_linked_pathv); } else if ( !result_linked_pathv.empty() ) { + result_linked_pathv *= affine.inverse(); curve->set_pathvector(result_linked_pathv); } else if ( !result_second_pathv.empty() ) { + result_second_pathv *= affine.inverse(); curve->set_pathvector(result_second_pathv); } } @@ -83,6 +106,10 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) result_pathv.push_back((*iter)); } if ( !result_pathv.empty() ) { + result_pathv *= affine.inverse(); + if (close) { + result_pathv.front().close(); + } curve->set_pathvector(result_pathv); } } @@ -95,12 +122,26 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) result_pathv.push_back((*iter)); } if ( !result_pathv.empty() ) { + result_pathv *= affine.inverse(); + if (close) { + result_pathv.front().close(); + } curve->set_pathvector(result_pathv); } } } } +void +LPEFillBetweenStrokes::transform_multiply(Geom::Affine const& postmul, bool set) +{ + if(!allow_transforms && sp_lpe_item) { + SP_ITEM(sp_lpe_item)->transform *= postmul.inverse(); + transformmultiply = true; + sp_lpe_item_update_patheffect(sp_lpe_item, false, false); + } +} + } // namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fill-between-strokes.h b/src/live_effects/lpe-fill-between-strokes.h index 14eb9167c..5bbd6e7da 100644 --- a/src/live_effects/lpe-fill-between-strokes.h +++ b/src/live_effects/lpe-fill-between-strokes.h @@ -19,15 +19,18 @@ class LPEFillBetweenStrokes : public Effect { public: LPEFillBetweenStrokes(LivePathEffectObject *lpeobject); virtual ~LPEFillBetweenStrokes(); - + virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual void doEffect (SPCurve * curve); private: OriginalPathParam linked_path; OriginalPathParam second_path; BoolParam reverse_second; - BoolParam close; BoolParam fuse; + BoolParam allow_transforms; + BoolParam join; + BoolParam close; + bool transformmultiply; private: LPEFillBetweenStrokes(const LPEFillBetweenStrokes&); -- cgit v1.2.3 From 9fc2dec29dbebeccf3a4f4bcde043d4dbcd8e52b Mon Sep 17 00:00:00 2001 From: Eduard Braun <> Date: Tue, 7 Mar 2017 21:53:57 +0100 Subject: Apply the fix done by Eduard Brown from bug 1666314 to measure-line LPE. (Thanks Eduard) (bzr r15576) --- src/live_effects/lpe-measure-line.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 625db150b..83ae60fc4 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -329,19 +329,20 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl Inkscape::GC::release(rtspan); } length = Inkscape::Util::Quantity::convert(length / doc_scale, display_unit.c_str(), unit.get_abbreviation()); - std::stringstream length_str; - length_str.precision(precision); - length_str.setf(std::ios::fixed, std::ios::floatfield); + char *oldlocale = g_strdup (setlocale(LC_NUMERIC, NULL)); if (local_locale) { - length_str.imbue(std::locale("")); + setlocale (LC_NUMERIC, ""); } else { - length_str.imbue(std::locale::classic()); + setlocale (LC_NUMERIC, "C"); } - length_str << std::fixed << length; + gchar length_str[64]; + g_snprintf(length_str, 64, "%.*f", (int)precision, length); + setlocale (LC_NUMERIC, oldlocale); + g_free (oldlocale); Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); size_t s = label_value.find(Glib::ustring("{measure}"),0); if(s < label_value.length()) { - label_value.replace(s,s+9,length_str.str()); + label_value.replace(s,s+9,length_str); } s = label_value.find(Glib::ustring("{unit}"),0); if(s < label_value.length()) { @@ -655,9 +656,11 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, dimline_format.param_getSVGValue()); - setlocale(LC_NUMERIC, std::locale::classic().name().c_str()); + char *oldlocale = g_strdup (setlocale(LC_NUMERIC, NULL)); + setlocale (LC_NUMERIC, "C"); double width_line = atof(sp_repr_css_property(css,"stroke-width","-1")); - setlocale(LC_NUMERIC, std::locale("").name().c_str()); + setlocale (LC_NUMERIC, oldlocale); + g_free (oldlocale); if (width_line > -0.0001) { arrow_gap = 8 * Inkscape::Util::Quantity::convert(width_line/ doc_scale, "mm", display_unit.c_str()); } -- cgit v1.2.3 From 6587e0fd91e337ac0bcf650e7ba95e0b9001cfab Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 12 Mar 2017 09:47:27 +0000 Subject: LPE Gtk3 deprecation fixes (bzr r15587) --- src/live_effects/lpe-perspective-envelope.cpp | 8 ++++---- src/live_effects/lpe-perspective_path.cpp | 17 +++++++++++++++-- src/live_effects/lpe-roughen.cpp | 8 ++++---- 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 18b5b724d..365ff5389 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -369,12 +369,12 @@ LPEPerspectiveEnvelope::newWidget() Gtk::Label* handles = Gtk::manage(new Gtk::Label(Glib::ustring(_("Handles:")),Gtk::ALIGN_START)); vbox->pack_start(*handles, false, false, 2); hbox_up_handles->pack_start(*widg, true, true, 2); - hbox_up_handles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); + hbox_up_handles->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_VERTICAL)), Gtk::PACK_EXPAND_WIDGET); } else if(param->param_key == "up_right_point") { hbox_up_handles->pack_start(*widg, true, true, 2); } else if(param->param_key == "down_left_point") { hbox_down_handles->pack_start(*widg, true, true, 2); - hbox_down_handles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET); + hbox_down_handles->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_VERTICAL)), Gtk::PACK_EXPAND_WIDGET); } else { hbox_down_handles->pack_start(*widg, true, true, 2); } @@ -403,8 +403,8 @@ LPEPerspectiveEnvelope::newWidget() } vbox->pack_start(*hbox_up_handles,true, true, 2); Gtk::HBox * hbox_middle = Gtk::manage(new Gtk::HBox(true,2)); - hbox_middle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); - hbox_middle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET); + hbox_middle->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); + hbox_middle->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); vbox->pack_start(*hbox_middle, false, true, 2); vbox->pack_start(*hbox_down_handles, true, true, 2); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 979b6dea5..b83fb67d7 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -226,15 +226,28 @@ LPEPerspectivePath::newWidget() ++it; } Gtk::HBox * perspectiveId = Gtk::manage(new Gtk::HBox(true,0)); + +#if WITH_GTKMM_3_10 + Gtk::Label* labelPerspective = Gtk::manage(new Gtk::Label("Perspective ID:", Gtk::ALIGN_START, Gtk::ALIGN_START)); +#else Gtk::Label* labelPerspective = Gtk::manage(new Gtk::Label("Perspective ID:", 0., 0.)); +#endif + Gtk::Entry* perspective = Gtk::manage(new Gtk::Entry()); perspective->set_text(perspectiveID); perspective->set_tooltip_text("Set the perspective ID to apply"); perspectiveId->pack_start(*labelPerspective, true, true, 2); perspectiveId->pack_start(*perspective, true, true, 2); vbox->pack_start(*perspectiveId, true, true, 2); - Gtk::Button* apply3D = Gtk::manage(new Gtk::Button(Glib::ustring(_("Refresh perspective")))); - apply3D->set_alignment(0.0, 0.5); + Gtk::Button* apply3D = Gtk::manage(new Gtk::Button()); + +#if WITH_GTKMM_3_10 + Gtk::Label *apply3DLabel = Gtk::manage(new Gtk::Label(_("Refresh perspective"), Gtk::ALIGN_START, Gtk::ALIGN_CENTER)); +#else + Gtk::Label *apply3DLabel = Gtk::manage(new Gtk::Label(_("Refresh perspective"), 0.0, 0.5)); +#endif + + apply3D->add(*apply3DLabel); apply3D->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,&LPEPerspectivePath::refresh),perspective)); Gtk::Widget* apply3DWidget = dynamic_cast(apply3D); apply3DWidget->set_tooltip_text("Refresh perspective"); diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index c6edffd9b..e847494a2 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -120,7 +120,7 @@ Gtk::Widget *LPERoughen::newWidget() Gtk::ALIGN_START)); method_label->set_use_markup(true); vbox->pack_start(*method_label, false, false, 2); - vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), + vbox->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); } if (param->param_key == "displace_x") { @@ -129,7 +129,7 @@ Gtk::Widget *LPERoughen::newWidget() Gtk::ALIGN_START)); displace_x_label->set_use_markup(true); vbox->pack_start(*displace_x_label, false, false, 2); - vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), + vbox->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); } if (param->param_key == "global_randomize") { @@ -138,7 +138,7 @@ Gtk::Widget *LPERoughen::newWidget() Gtk::ALIGN_START)); global_rand->set_use_markup(true); vbox->pack_start(*global_rand, false, false, 2); - vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), + vbox->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); } if (param->param_key == "handles") { @@ -147,7 +147,7 @@ Gtk::Widget *LPERoughen::newWidget() Gtk::ALIGN_START)); options->set_use_markup(true); vbox->pack_start(*options, false, false, 2); - vbox->pack_start(*Gtk::manage(new Gtk::HSeparator()), + vbox->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_HORIZONTAL)), Gtk::PACK_EXPAND_WIDGET); } Glib::ustring *tip = param->param_getTooltip(); -- cgit v1.2.3 From 98c50c48230463cb059434ad781ccef2ce998cb7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 20:58:19 +0100 Subject: Remove some warnings (bzr r13645.1.171) --- src/live_effects/parameter/satellitesarray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 7efe5dd98..8cf517852 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -102,7 +102,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value pathv[i].size() == j || //ignore last satellite in open paths with fillet chamfer effect - !pathv[i].closed() && j == 0) //ignore first satellites on open paths + (!pathv[i].closed() && j == 0)) //ignore first satellites on open paths { continue; } @@ -306,7 +306,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Satellite satellite = _pparam->_vector[path_index][curve_index]; Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; -- cgit v1.2.3 From 5997087db8a3bc2ec3b3bb0623f3f66cb81a4521 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 21:03:59 +0100 Subject: Remove some warnings (bzr r13645.1.172) --- src/live_effects/parameter/satellitesarray.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8cf517852..c7bc7f026 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -378,7 +378,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const Satellite satellite = _pparam->_vector[path_index][curve_index]; Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return Geom::Point(Geom::infinity(), Geom::infinity()); @@ -434,7 +434,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) return; } Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); - if (!pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + if ((!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; @@ -532,7 +532,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) } Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; -- cgit v1.2.3 From fdd8ce77fa742072a1cea8136acaeed1dae079b5 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 23:29:49 +0100 Subject: Remove some compiling warns (bzr r15599) --- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-clone-original.cpp | 2 +- src/live_effects/lpe-copy_rotate.cpp | 6 +++--- src/live_effects/lpe-measure-line.cpp | 8 ++++---- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- src/live_effects/lpeobject.h | 6 ++---- 6 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index f664870ec..017947cda 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -440,7 +440,7 @@ Effect::processObjects(LpeAction lpe_action) return; } SPObject *elemref = NULL; - if (elemref = document->getObjectById(id)) { + if ((elemref = document->getObjectById(id))) { Inkscape::XML::Node * elemnode = elemref->getRepr(); std::vector item_list; item_list.push_back(SP_ITEM(elemref)); diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 440af6f9c..c41b1ef95 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -193,7 +193,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co while (*styleiter != NULL) { const char* attribute = (*styleiter); const char* origin_attribute = sp_repr_css_property(css_origin, attribute, ""); - if (origin_attribute == "") { + if (!strlen(origin_attribute)) { //==0 sp_repr_css_set_property (css_dest, attribute, NULL); } else { sp_repr_css_set_property (css_dest, attribute, origin_attribute); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 9ba680cd4..bf82b5deb 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -112,7 +112,7 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) return; } SPObject *elemref = NULL; - if (elemref = document->getObjectById(id)) { + if ((elemref = document->getObjectById(id))) { SP_ITEM(elemref)->setHidden(true); } counter++; @@ -124,7 +124,7 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) SPObject *elemref = NULL; char * id = g_strdup(Glib::ustring("rotated-").append("1").append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); guint counter = 0; - while(elemref = document->getObjectById(id)) { + while((elemref = document->getObjectById(id))) { if (SP_ITEM(elemref)->isHidden()) { items.push_back(id); } @@ -229,7 +229,7 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) items.push_back(elemref_id); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; - if (elemref = document->getObjectById(elemref_id)) { + if ((elemref = document->getObjectById(elemref_id))) { phantom = elemref->getRepr(); } else { phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 83ae60fc4..86d72615c 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -177,7 +177,7 @@ LPEMeasureLine::createArrowMarker(const char * mode) Inkscape::XML::Document *xml_doc = document->getReprDoc(); SPObject *elemref = NULL; Inkscape::XML::Node *arrow = NULL; - if (elemref = document->getObjectById(mode)) { + if ((elemref = document->getObjectById(mode))) { Inkscape::XML::Node *arrow= elemref->getRepr(); if (arrow) { arrow->setAttribute("sodipodi:insensitive", "true"); @@ -257,7 +257,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl const char * id = g_strdup(Glib::ustring("text-on-").append(this->getRepr()->attribute("id")).c_str()); SPObject *elemref = NULL; Inkscape::XML::Node *rtspan = NULL; - if (elemref = document->getObjectById(id)) { + if ((elemref = document->getObjectById(id))) { if (remove) { elemref->deleteObject(); return; @@ -422,7 +422,7 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, b line_path.appendNew(end); line_pathv.push_back(line_path); } - if (elemref = document->getObjectById(id)) { + if ((elemref = document->getObjectById(id))) { if (remove) { elemref->deleteObject(); return; @@ -625,7 +625,7 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { Geom::Point sstart = end - Point::polar(angle_cross, position); Geom::Point send = end - Point::polar(angle_cross, position); - if (text_right_left < 0 && flip_side || text_right_left > 0 && !flip_side) { + if ((text_right_left < 0 && flip_side) || (text_right_left > 0 && !flip_side)) { sstart = start - Point::polar(angle_cross, position); send = start - Point::polar(angle_cross, position); } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index c31ce7c01..97015c34d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -244,7 +244,7 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) items.push_back(elemref_id); SPObject *elemref= NULL; Inkscape::XML::Node *phantom = NULL; - if (elemref = document->getObjectById(elemref_id)) { + if ((elemref = document->getObjectById(elemref_id))) { phantom = elemref->getRepr(); } else { phantom = sp_lpe_item->getRepr()->duplicate(xml_doc); diff --git a/src/live_effects/lpeobject.h b/src/live_effects/lpeobject.h index 087223947..e468b4080 100644 --- a/src/live_effects/lpeobject.h +++ b/src/live_effects/lpeobject.h @@ -39,12 +39,10 @@ public: /* Note that the returned pointer can be NULL in a valid LivePathEffectObject contained in a valid list of lpeobjects in an lpeitem! * So one should always check whether the returned value is NULL or not */ Inkscape::LivePathEffect::Effect * get_lpe() { - if(this) return lpe; - else return NULL; + return lpe; } Inkscape::LivePathEffect::Effect const * get_lpe() const { - if(this) return lpe; - else return NULL; + return lpe; }; Inkscape::LivePathEffect::Effect *lpe; // this can be NULL in a valid LivePathEffectObject -- cgit v1.2.3 From 62036c3e30d6188ee9372b36b25f7ef9bdfea5c0 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 15 Apr 2017 15:28:29 +0200 Subject: Fixes crashes with LPE point parameter (bzr r15623) --- src/live_effects/parameter/point.cpp | 21 +++++++++------------ src/live_effects/parameter/point.h | 4 +--- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index c87b1e299..db768090a 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -26,8 +26,7 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, : Parameter(label, tip, key, wr, effect), defvalue(default_value), liveupdate(live_update), - knoth(NULL), - _pointwdg(NULL) + knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -59,7 +58,7 @@ PointParam::param_get_default() const{ } void -PointParam::param_update_default(const Geom::Point default_point) +PointParam::param_update_default(Geom::Point default_point) { defvalue = default_point; } @@ -78,9 +77,7 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) if(knoth && liveupdate){ knoth->update_knots(); } - if (_pointwdg) { - _pointwdg->setValue( newpoint ); - } + param_effect->upd_params = true; } bool @@ -116,7 +113,7 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { - _pointwdg = Gtk::manage( + Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, param_tooltip, param_key, @@ -125,13 +122,13 @@ PointParam::param_newWidget() param_effect->getSPDoc() ) ); Geom::Affine transf = Geom::Scale(1, -1); transf[5] = SP_ACTIVE_DOCUMENT->getHeight().value("px"); - _pointwdg->setTransform(transf); - _pointwdg->setValue( *this ); - _pointwdg->clearProgrammatically(); - _pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + 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(hbox)->pack_start(*_pointwdg, true, true); + static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); param_effect->upd_params = false; return dynamic_cast (hbox); diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index e8cb66225..5d145a81a 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -43,14 +43,13 @@ public: void param_set_default(); Geom::Point param_get_default() const; void param_set_liveupdate(bool live_update); - void param_update_default(const Geom::Point default_point); + void param_update_default(Geom::Point default_point); 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, SPItem *item); - friend class PointParamKnotHolderEntity; private: PointParam(const PointParam&); @@ -62,7 +61,6 @@ private: SPKnotModeType knot_mode; guint32 knot_color; gchar *handle_tip; - Inkscape::UI::Widget::RegisteredTransformedPoint * _pointwdg; }; -- cgit v1.2.3 From 0a5ba68c8b932263983aa9b8d442afdd6012624e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 24 Apr 2017 23:46:22 +0200 Subject: Improve rotate copies LPE to allow mirror copy with and without fuse (bzr r15639) --- src/live_effects/lpe-copy_rotate.cpp | 60 ++++++++++++++++++++++++------------ src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 42 insertions(+), 20 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index bf82b5deb..3fda0576b 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -54,8 +54,8 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fuse_paths(_("Kaleidoskope"), _("Kaleidoskope by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), - join_paths(_("Join paths"), _("Join paths, use fill-rule: evenodd for best result"), "join_paths", &wr, this, false), + fuse_paths(_("Fuse Paths"), _("Fuse by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), + mirror_copies(_("Mirror copies"), _("Mirror between copies"), "mirror_copies", &wr, this, false), split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), dist_angle_handle(100.0) { @@ -64,7 +64,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); registerParameter(&fuse_paths); - registerParameter(&join_paths); + registerParameter(&mirror_copies); registerParameter(&split_items); registerParameter(&starting_angle); registerParameter(&starting_point); @@ -138,31 +138,40 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); + Geom::Affine r = Geom::identity(); + Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); + if (mirror_copies) { + r *= Geom::Rotate(Geom::Angle(dir)).inverse(); + r *= Geom::Scale(1, -1); + r *= Geom::Rotate(Geom::Angle(dir)); + } if (fuse_paths) { size_t rest = 0; for (size_t i = 1; i < num_copies; ++i) { - Geom::Affine r = Geom::identity(); - Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); - if( rest%2 == 0) { - r *= Geom::Rotate(Geom::Angle(dir)).inverse(); - r *= Geom::Scale(1, -1); - r *= Geom::Rotate(Geom::Angle(dir)); - } Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); - Geom::Affine t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + Geom::Affine t; if( rest%2 == 0) { - t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); + t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } else { + t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); } t *= sp_lpe_item->transform; toItem(t, i-1, reset); rest ++; } } else { + size_t rest = 0; for (size_t i = 1; i < num_copies; ++i) { Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); - Geom::Affine t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + Geom::Affine t; + if( rest%2 == 0) { + t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } else { + t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } t *= sp_lpe_item->transform; toItem(t, i - 1, reset); + rest ++; } } reset = false; @@ -490,7 +499,7 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s for (int i = 0; i < num_copies; ++i) { Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); - if (i%2 != 0) { + if (i%2 != 0 && mirror_copies) { Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; Geom::Line ls(A,B); @@ -588,7 +597,7 @@ Geom::PathVector LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) { Geom::PathVector path_out; - if (split_items && (fuse_paths || join_paths)) { + if (split_items && fuse_paths) { if (num_copies == 0) { return path_out; } @@ -650,7 +659,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Piecewise > output; Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001)); - if (fuse_paths) { + if (fuse_paths && mirror_copies) { Geom::PathVector path_out; Geom::PathVector tmp_path; for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -682,8 +691,21 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Geom::PathVector output_pv; for (int i = 0; i < num_copies; ++i) { Rotate rot(-rad_from_deg(rotation_angle * i)); - Affine t = pre * rot * Translate(origin); - if (join_paths) { + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; + Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; + Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); + Geom::Affine r = Geom::identity(); + Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); + if (mirror_copies && i%2 != 0) { + r *= Geom::Rotate(Geom::Angle(dir)).inverse(); + r *= Geom::Scale(1, -1); + r *= Geom::Rotate(Geom::Angle(dir)); + } + Affine t = pre * r * rot * Translate(origin); + if (fuse_paths && !mirror_copies) { Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); if (pig) { @@ -697,7 +719,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p output.concat(pwd2_in * t); } } - if (join_paths) { + if (fuse_paths && !mirror_copies) { output = paths_to_pw(output_pv); } } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index dbec2e1c3..497f2cf5d 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -54,7 +54,7 @@ private: ScalarParam split_gap; BoolParam copies_to_360; BoolParam fuse_paths; - BoolParam join_paths; + BoolParam mirror_copies; BoolParam split_items; Geom::Point A; Geom::Point B; -- cgit v1.2.3 From 5ca97b274722c104c20be06095ae353e79bf7dbb Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 25 Apr 2017 00:49:21 +0200 Subject: Fix last commit bug on split LPE objects in rotate copies LPE (bzr r15640) --- src/live_effects/lpe-copy_rotate.cpp | 46 +++++++++++------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3fda0576b..40dbb798e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -138,41 +138,23 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); - Geom::Affine r = Geom::identity(); Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); - if (mirror_copies) { - r *= Geom::Rotate(Geom::Angle(dir)).inverse(); - r *= Geom::Scale(1, -1); - r *= Geom::Rotate(Geom::Angle(dir)); - } - if (fuse_paths) { - size_t rest = 0; - for (size_t i = 1; i < num_copies; ++i) { - Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); - Geom::Affine t; - if( rest%2 == 0) { - t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - } else { - t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - } - t *= sp_lpe_item->transform; - toItem(t, i-1, reset); - rest ++; + size_t rest = 0; + for (size_t i = 1; i < num_copies; ++i) { + Geom::Affine r = Geom::identity(); + if( rest%2 == 0 && mirror_copies) { + r *= Geom::Rotate(Geom::Angle(dir)).inverse(); + r *= Geom::Scale(1, -1); + r *= Geom::Rotate(Geom::Angle(dir)); } - } else { - size_t rest = 0; - for (size_t i = 1; i < num_copies; ++i) { - Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); - Geom::Affine t; - if( rest%2 == 0) { - t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - } else { - t = m * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - } - t *= sp_lpe_item->transform; - toItem(t, i - 1, reset); - rest ++; + Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); + Geom::Affine t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + if( rest%2 == 0 && mirror_copies) { + t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); } + t *= sp_lpe_item->transform; + toItem(t, i-1, reset); + rest ++; } reset = false; } else { -- cgit v1.2.3 From 1ec3dcea424afadc16e6e95090e0ef78b0aa38bb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Apr 2017 13:50:40 +0200 Subject: Rotate copies LPE refactor. Add double option, fuse and kaleidoscope both with mirror copies and split items (bzr r15641) --- src/live_effects/lpe-copy_rotate.cpp | 179 +++++++++++++++++------------------ src/live_effects/lpe-copy_rotate.h | 4 + 2 files changed, 90 insertions(+), 93 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 40dbb798e..f0c304f1f 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -57,6 +57,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : fuse_paths(_("Fuse Paths"), _("Fuse by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), mirror_copies(_("Mirror copies"), _("Mirror between copies"), "mirror_copies", &wr, this, false), split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), + kaleidoscope(_("Kaleidoscope"), _("Kaleidoscope, use fill-rule: evenodd for best result"), "kaleidoscope", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -64,6 +65,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); registerParameter(&fuse_paths); + registerParameter(&kaleidoscope); registerParameter(&mirror_copies); registerParameter(&split_items); registerParameter(&starting_angle); @@ -358,18 +360,23 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; original_bbox(lpeitem); if (copies_to_360) { + this->upd_params = true; rotation_angle.param_set_value(360.0/(double)num_copies); } - if (fuse_paths && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { + + if (kaleidoscope && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { + this->upd_params = true; num_copies.param_set_value(floor(360/rotation_angle)); } - if (fuse_paths && copies_to_360) { + if (kaleidoscope && copies_to_360) { + this->upd_params = true; num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); rotation_angle.param_set_value(360.0/(double)num_copies); } } else { + this->upd_params = true; num_copies.param_set_increments(1.0, 10.0); } @@ -382,7 +389,8 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); - if (!near) { + if (!near) { + this->upd_params = true; starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); if (GDK_SHIFT_MASK) { dist_angle_handle = L2(B - A); @@ -396,7 +404,8 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); - if (!near) { + if (!near) { + this->upd_params = true; starting_point.param_setValue(start_pos, true); } previous_start_point = (Geom::Point)starting_point; @@ -477,19 +486,21 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s } Geom::PathVector tmp_path_helper; Geom::Path append_path = original; - + Geom::Point previous = original.finalPoint(); for (int i = 0; i < num_copies; ++i) { Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); if (i%2 != 0 && mirror_copies) { - Geom::Point A = (Geom::Point)origin; - Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; - Geom::Line ls(A,B); - m = Geom::reflection (ls.vector(), A); + Geom::Point point_a = (Geom::Point)origin; + Geom::Point point_b = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; + Geom::Line ls(point_a, point_b); + m = Geom::reflection (ls.vector(), point_a); + append_path *= m; } else { append_path = original; + append_path *= m; } - append_path *= m; + previous = append_path.finalPoint(); if (tmp_path_helper.size() > 0) { if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(), append_path.finalPoint())) { Geom::Path tmp_append = append_path.reversed(); @@ -579,20 +590,33 @@ Geom::PathVector LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) { Geom::PathVector path_out; - if (split_items && fuse_paths) { + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::OptRect bbox = sp_lpe_item->geometricBounds(); + size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; + Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; + divider = Geom::Path(line_start); + divider.appendNew((Geom::Point)origin); + divider.appendNew(line_end); + divider.close(); + dir_gap = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); + if (split_items && (fuse_paths || kaleidoscope)) { + if (!kaleidoscope && fuse_paths) { + for (unsigned int i=0; i < path_in.size(); i++) { + Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); + Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); + Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); + // add the output path vector to the already accumulated vector: + for (unsigned int j=0; j < path.size(); j++) { + path_out.push_back(path[j]); + } + } + } else { + path_out = pathv_to_linear_and_cubic_beziers(path_in); + } if (num_copies == 0) { return path_out; } - path_out = pathv_to_linear_and_cubic_beziers(path_in); - double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::OptRect bbox = sp_lpe_item->geometricBounds(); - double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; - Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; - Geom::Path divider = Geom::Path(line_start); - divider.appendNew((Geom::Point)origin); - divider.appendNew(line_end); - divider.close(); Geom::PathVector triangle; triangle.push_back(divider); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(triangle, path_out); @@ -601,11 +625,23 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) path_out = pig->getIntersection(); } Geom::Affine r = Geom::identity(); - Geom::Point dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); - Geom::Point gap = dir * split_gap; + Geom::Point gap = dir_gap * split_gap; path_out *= Geom::Translate(gap); + if ( kaleidoscope && !split_items ) { + path_out *= Geom::Translate(gap).inverse(); + Geom::PathVector path_out_c; + for (unsigned int i=0; i < path_out.size(); i++) { + Geom::Piecewise > pwd2_in = path_out[i].toPwSb(); + Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); + Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); + // add the output path vector to the already accumulated vector: + for (unsigned int j=0; j < path.size(); j++) { + path_out_c.push_back(path[j]); + } + } + path_out = path_out_c; + } } else { - // default behavior for (unsigned int i=0; i < path_in.size(); i++) { Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); @@ -624,86 +660,43 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if ((num_copies == 1 && !fuse_paths) || split_items) { + if ((num_copies == 1 && !fuse_paths) || (split_items && !fuse_paths && !kaleidoscope)) { return pwd2_in; } - double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point line_start = origin + dir * Rotate(-rad_from_deg(starting_angle)) * size_divider; - Geom::Point line_end = origin + dir * Rotate(-rad_from_deg(rotation_angle + starting_angle)) * size_divider; - //Note:: beter way to do this - //Whith AppendNew have problems whith the crossing order - Geom::Path divider = Geom::Path(line_start); - divider.appendNew((Geom::Point)origin); - divider.appendNew(line_end); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001)); - if (fuse_paths && mirror_copies) { - Geom::PathVector path_out; - Geom::PathVector tmp_path; - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - bool end_open = false; - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { - end_open = true; - } - } - Geom::Path original = (Geom::Path)(*path_it); - if (end_open && path_it->closed()) { - original.close(false); - original.appendNew( original.initialPoint() ); - original.close(true); - } - tmp_path.push_back(original); - setFusion(tmp_path, divider, size_divider); - path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); - tmp_path.clear(); - } - if (path_out.size()>0) { - output = paths_to_pw(path_out); + Geom::PathVector output_pv; + for (int i = 0; i < num_copies; ++i) { + Rotate rot(-rad_from_deg(rotation_angle * i)); + Geom::Affine r = Geom::identity(); + if (mirror_copies && i%2 != 0) { + r *= Geom::Rotate(Geom::Angle(dir_gap)).inverse(); + r *= Geom::Scale(1, -1); + r *= Geom::Rotate(Geom::Angle(dir_gap)); } - } else { - Geom::PathVector output_pv; - for (int i = 0; i < num_copies; ++i) { - Rotate rot(-rad_from_deg(rotation_angle * i)); - double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; - Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; - Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); - Geom::Affine r = Geom::identity(); - Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); - if (mirror_copies && i%2 != 0) { - r *= Geom::Rotate(Geom::Angle(dir)).inverse(); - r *= Geom::Scale(1, -1); - r *= Geom::Rotate(Geom::Angle(dir)); + Affine t = pre * r * rot * Translate(origin); + if (fuse_paths || kaleidoscope) { + Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); + if (kaleidoscope) { + Geom::Point gap = dir_gap * rot * -0.01; + join_pv *= Geom::Translate(gap); } - Affine t = pre * r * rot * Translate(origin); - if (fuse_paths && !mirror_copies) { - Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); - Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); - if (pig) { - if (!output_pv.empty()) { - output_pv = pig->getUnion(); - } else { - output_pv = join_pv; - } + Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); + if (pig) { + if (!output_pv.empty()) { + output_pv = pig->getUnion(); + } else { + output_pv = join_pv; } - } else { - output.concat(pwd2_in * t); } + } else { + output.concat(pwd2_in * t); } - if (fuse_paths && !mirror_copies) { - output = paths_to_pw(output_pv); - } + } + if (fuse_paths || kaleidoscope) { + output = paths_to_pw(output_pv); } return output; } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 497f2cf5d..8e508a52d 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -54,15 +54,19 @@ private: ScalarParam split_gap; BoolParam copies_to_360; BoolParam fuse_paths; + BoolParam kaleidoscope; BoolParam mirror_copies; BoolParam split_items; Geom::Point A; Geom::Point B; Geom::Point dir; + Geom::Point dir_gap; Geom::Point start_pos; Geom::Point rot_pos; Geom::Point previous_start_point; double dist_angle_handle; + double size_divider; + Geom::Path divider; double previous_num_copies; bool reset; SPObject * container; -- cgit v1.2.3 From 5750002046442d348cb568e30e6605d6653595f3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Apr 2017 17:32:43 +0200 Subject: Fixed some bugs in Rotate Copies LPE. Added a EnumParam to handle explusive bool params Make compatible with 0.92 code (bzr r15642) --- src/live_effects/lpe-copy_rotate.cpp | 97 +++++++++++++++++++----------------- src/live_effects/lpe-copy_rotate.h | 13 +++-- 2 files changed, 60 insertions(+), 50 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f0c304f1f..8304acaa7 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -30,6 +30,14 @@ namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData RotateMethodData[RM_END] = { + { RM_NORMAL, N_("Normal"), "normal" }, + { RM_KALEIDOSCOPE, N_("Kaleidoscope"), "kaleidoskope" }, + { RM_FUSE, N_("Fuse paths"), "fuse_paths" } +}; +static const Util::EnumDataConverter +RMConverter(RotateMethodData, RM_END); + bool pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) { @@ -54,26 +62,31 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fuse_paths(_("Fuse Paths"), _("Fuse by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), + method(_("Method:"), _("Rotate methods"), "method", RMConverter, &wr, this, RM_NORMAL), mirror_copies(_("Mirror copies"), _("Mirror between copies"), "mirror_copies", &wr, this, false), split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), - kaleidoscope(_("Kaleidoscope"), _("Kaleidoscope, use fill-rule: evenodd for best result"), "kaleidoscope", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; _provides_knotholder_entities = true; + //0.92 compatibility + if (strcmp(this->getRepr()->attribute("fuse_paths"), "true") == 0){ + this->getRepr()->setAttribute("fuse_paths", NULL); + this->getRepr()->setAttribute("method", "kaleidoskope"); + this->getRepr()->setAttribute("mirror_copies", "true"); + }; // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter(&copies_to_360); - registerParameter(&fuse_paths); - registerParameter(&kaleidoscope); - registerParameter(&mirror_copies); - registerParameter(&split_items); + registerParameter(&method); registerParameter(&starting_angle); registerParameter(&starting_point); registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&split_gap); registerParameter(&origin); + registerParameter(&copies_to_360); + registerParameter(&mirror_copies); + registerParameter(&split_items); + split_gap.param_set_range(-999999.0, 999999.0); split_gap.param_set_increments(0.1, 0.1); split_gap.param_set_digits(5); @@ -134,29 +147,21 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) counter++; } g_free(id); - double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; - Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); - Geom::Point dir = unit_vector((Geom::Point)origin - Geom::middle_point(line_start,line_end)); - size_t rest = 0; for (size_t i = 1; i < num_copies; ++i) { Geom::Affine r = Geom::identity(); - if( rest%2 == 0 && mirror_copies) { - r *= Geom::Rotate(Geom::Angle(dir)).inverse(); + if( i%2 != 0 && mirror_copies) { + r *= Geom::Rotate(Geom::Angle(half_dir)).inverse(); r *= Geom::Scale(1, -1); - r *= Geom::Rotate(Geom::Angle(dir)); + r *= Geom::Rotate(Geom::Angle(half_dir)); } Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); Geom::Affine t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - if( rest%2 == 0 && mirror_copies) { + if( i%2 != 0 && mirror_copies) { t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); } t *= sp_lpe_item->transform; toItem(t, i-1, reset); - rest ++; } reset = false; } else { @@ -295,15 +300,6 @@ Gtk::Widget * LPECopyRotate::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); vbox->set_spacing(2); - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); - Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); - vbox_expander->set_border_width(0); - vbox_expander->set_spacing(2); - Gtk::Button * reset_button = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset styles")))); - reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPECopyRotate::resetStyles)); - reset_button->set_size_request(140,30); - vbox->pack_start(*hbox, true,true,2); - hbox->pack_start(*reset_button, false, false,2); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { @@ -325,6 +321,12 @@ Gtk::Widget * LPECopyRotate::newWidget() ++it; } + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0)); + Gtk::Button * reset_button = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset styles")))); + reset_button->signal_clicked().connect(sigc::mem_fun (*this,&LPECopyRotate::resetStyles)); + reset_button->set_size_request(110,20); + vbox->pack_start(*hbox, true,true,2); + hbox->pack_start(*reset_button, false, false,2); return dynamic_cast(vbox); } @@ -364,11 +366,11 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) rotation_angle.param_set_value(360.0/(double)num_copies); } - if (kaleidoscope && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { + if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { this->upd_params = true; num_copies.param_set_value(floor(360/rotation_angle)); } - if (kaleidoscope && copies_to_360) { + if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && copies_to_360) { this->upd_params = true; num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { @@ -409,7 +411,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) starting_point.param_setValue(start_pos, true); } previous_start_point = (Geom::Point)starting_point; - if ( fuse_paths || copies_to_360 ) { + if ( method == RM_FUSE || copies_to_360 ) { rot_pos = origin; } } @@ -599,9 +601,9 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) divider.appendNew((Geom::Point)origin); divider.appendNew(line_end); divider.close(); - dir_gap = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); - if (split_items && (fuse_paths || kaleidoscope)) { - if (!kaleidoscope && fuse_paths) { + half_dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); + if (method == RM_KALEIDOSCOPE || method == RM_FUSE) { + if (method != RM_KALEIDOSCOPE) { for (unsigned int i=0; i < path_in.size(); i++) { Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); @@ -625,9 +627,9 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) path_out = pig->getIntersection(); } Geom::Affine r = Geom::identity(); - Geom::Point gap = dir_gap * split_gap; + Geom::Point gap = half_dir * split_gap; path_out *= Geom::Translate(gap); - if ( kaleidoscope && !split_items ) { + if ( !split_items ) { path_out *= Geom::Translate(gap).inverse(); Geom::PathVector path_out_c; for (unsigned int i=0; i < path_out.size(); i++) { @@ -660,7 +662,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if ((num_copies == 1 && !fuse_paths) || (split_items && !fuse_paths && !kaleidoscope)) { + if ((num_copies == 1 && method != RM_FUSE) || (split_items && method != RM_FUSE && method != RM_KALEIDOSCOPE)) { return pwd2_in; } @@ -671,18 +673,19 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p for (int i = 0; i < num_copies; ++i) { Rotate rot(-rad_from_deg(rotation_angle * i)); Geom::Affine r = Geom::identity(); - if (mirror_copies && i%2 != 0) { - r *= Geom::Rotate(Geom::Angle(dir_gap)).inverse(); + if( i%2 != 0 && mirror_copies) { + r *= Geom::Rotate(Geom::Angle(half_dir)).inverse(); r *= Geom::Scale(1, -1); - r *= Geom::Rotate(Geom::Angle(dir_gap)); + r *= Geom::Rotate(Geom::Angle(half_dir)); } - Affine t = pre * r * rot * Translate(origin); - if (fuse_paths || kaleidoscope) { + Geom::Affine t = pre * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + if(mirror_copies && i%2 != 0) { + t = pre * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); + } + if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); - if (kaleidoscope) { - Geom::Point gap = dir_gap * rot * -0.01; - join_pv *= Geom::Translate(gap); - } + Geom::Point gap = half_dir * rot * -0.01; + join_pv *= Geom::Translate(gap); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); if (pig) { if (!output_pv.empty()) { @@ -695,7 +698,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p output.concat(pwd2_in * t); } } - if (fuse_paths || kaleidoscope) { + if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { output = paths_to_pw(output_pv); } return output; diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 8e508a52d..2e6b35b65 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -15,6 +15,7 @@ */ #include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/text.h" #include "live_effects/parameter/point.h" @@ -23,6 +24,13 @@ namespace Inkscape { namespace LivePathEffect { +enum RotateMethod { + RM_NORMAL, + RM_KALEIDOSCOPE, + RM_FUSE, + RM_END +}; + class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); @@ -53,14 +61,13 @@ private: ScalarParam num_copies; ScalarParam split_gap; BoolParam copies_to_360; - BoolParam fuse_paths; - BoolParam kaleidoscope; + EnumParam method; BoolParam mirror_copies; BoolParam split_items; Geom::Point A; Geom::Point B; Geom::Point dir; - Geom::Point dir_gap; + Geom::Point half_dir; Geom::Point start_pos; Geom::Point rot_pos; Geom::Point previous_start_point; -- cgit v1.2.3 From 5c5b667c64a349e88744c9d67a5ce95ca16e6f03 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 25 Apr 2017 23:33:21 +0200 Subject: Rotate copies improvements: Bug fixes. Better widgets positions (bzr r15643) --- src/live_effects/lpe-copy_rotate.cpp | 91 ++++++++++++------------------------ src/live_effects/lpe-copy_rotate.h | 4 +- 2 files changed, 32 insertions(+), 63 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 8304acaa7..ef481381d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -60,7 +60,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : starting_angle(_("Starting angle"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), - split_gap(_("Gap on split"), _("Gap on split"), "split_gap", &wr, this, -0.001), + gap(_("Gap"), _("Gap"), "gap", &wr, this, -0.0001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), method(_("Method:"), _("Rotate methods"), "method", RMConverter, &wr, this, RM_NORMAL), mirror_copies(_("Mirror copies"), _("Mirror between copies"), "mirror_copies", &wr, this, false), @@ -70,27 +70,27 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : show_orig_path = true; _provides_knotholder_entities = true; //0.92 compatibility - if (strcmp(this->getRepr()->attribute("fuse_paths"), "true") == 0){ + if (this->getRepr()->attribute("fuse_paths") && strcmp(this->getRepr()->attribute("fuse_paths"), "true") == 0){ this->getRepr()->setAttribute("fuse_paths", NULL); this->getRepr()->setAttribute("method", "kaleidoskope"); this->getRepr()->setAttribute("mirror_copies", "true"); }; // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&method); + registerParameter(&num_copies); registerParameter(&starting_angle); registerParameter(&starting_point); registerParameter(&rotation_angle); - registerParameter(&num_copies); - registerParameter(&split_gap); registerParameter(&origin); + registerParameter(&gap); registerParameter(&copies_to_360); registerParameter(&mirror_copies); registerParameter(&split_items); - split_gap.param_set_range(-999999.0, 999999.0); - split_gap.param_set_increments(0.1, 0.1); - split_gap.param_set_digits(5); - num_copies.param_set_range(0, 999999); + gap.param_set_range(-999999.0, 999999.0); + gap.param_set_increments(0.1, 0.1); + gap.param_set_digits(5); + num_copies.param_set_range(1, 999999); num_copies.param_make_integer(true); apply_to_clippath_and_mask = true; previous_num_copies = num_copies; @@ -361,7 +361,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if (copies_to_360) { + if (copies_to_360 && num_copies > 2) { this->upd_params = true; rotation_angle.param_set_value(360.0/(double)num_copies); } @@ -370,7 +370,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) this->upd_params = true; num_copies.param_set_value(floor(360/rotation_angle)); } - if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && copies_to_360) { + if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && mirror_copies && copies_to_360) { this->upd_params = true; num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { @@ -594,7 +594,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) Geom::PathVector path_out; double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::OptRect bbox = sp_lpe_item->geometricBounds(); - size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + size_divider = Geom::distance(origin,bbox) + (diagonal * 6); Geom::Point line_start = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))) * size_divider; Geom::Point line_end = origin + dir * Geom::Rotate(-(Geom::rad_from_deg(rotation_angle + starting_angle))) * size_divider; divider = Geom::Path(line_start); @@ -604,15 +604,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) half_dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); if (method == RM_KALEIDOSCOPE || method == RM_FUSE) { if (method != RM_KALEIDOSCOPE) { - for (unsigned int i=0; i < path_in.size(); i++) { - Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); - Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); - Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); - // add the output path vector to the already accumulated vector: - for (unsigned int j=0; j < path.size(); j++) { - path_out.push_back(path[j]); - } - } + path_out = doEffect_path_post(path_in); } else { path_out = pathv_to_linear_and_cubic_beziers(path_in); } @@ -622,56 +614,33 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) Geom::PathVector triangle; triangle.push_back(divider); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(triangle, path_out); - if (pig && ! path_out.empty() && !triangle.empty()) { - //TODO: Here can produce a crash because some knows problems in new boolops code + if (pig && !path_out.empty() && !triangle.empty()) { path_out = pig->getIntersection(); } - Geom::Affine r = Geom::identity(); - Geom::Point gap = half_dir * split_gap; - path_out *= Geom::Translate(gap); + path_out *= Geom::Translate(half_dir * gap); if ( !split_items ) { - path_out *= Geom::Translate(gap).inverse(); - Geom::PathVector path_out_c; - for (unsigned int i=0; i < path_out.size(); i++) { - Geom::Piecewise > pwd2_in = path_out[i].toPwSb(); - Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); - Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); - // add the output path vector to the already accumulated vector: - for (unsigned int j=0; j < path.size(); j++) { - path_out_c.push_back(path[j]); - } - } - path_out = path_out_c; + path_out *= Geom::Translate(half_dir * gap).inverse(); + path_out = doEffect_path_post(path_out); } } else { - for (unsigned int i=0; i < path_in.size(); i++) { - Geom::Piecewise > pwd2_in = path_in[i].toPwSb(); - Geom::Piecewise > pwd2_out = doEffect_pwd2(pwd2_in); - Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); - // add the output path vector to the already accumulated vector: - for (unsigned int j=0; j < path.size(); j++) { - path_out.push_back(path[j]); - } - } + path_out = doEffect_path_post(path_in); } return pathv_to_linear_and_cubic_beziers(path_out); } -Geom::Piecewise > -LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +Geom::PathVector +LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) { - using namespace Geom; - - if ((num_copies == 1 && method != RM_FUSE) || (split_items && method != RM_FUSE && method != RM_KALEIDOSCOPE)) { - return pwd2_in; + if ((split_items || num_copies == 1) && method != RM_FUSE && method != RM_KALEIDOSCOPE) { + return path_in; } - Piecewise > output; - Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); - PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001)); + Geom::Affine pre = Geom::Translate(-origin) * Geom::Rotate(-Geom::rad_from_deg(starting_angle)); + Geom::PathVector original_pathv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector output_pv; + Geom::PathVector output; for (int i = 0; i < num_copies; ++i) { - Rotate rot(-rad_from_deg(rotation_angle * i)); + Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * i)); Geom::Affine r = Geom::identity(); if( i%2 != 0 && mirror_copies) { r *= Geom::Rotate(Geom::Angle(half_dir)).inverse(); @@ -683,9 +652,8 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p t = pre * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); } if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { - Geom::PathVector join_pv = path_from_piecewise(pwd2_in * t , 0.01); - Geom::Point gap = half_dir * rot * -0.01; - join_pv *= Geom::Translate(gap); + Geom::PathVector join_pv = original_pathv * t; + join_pv *= Geom::Translate(half_dir * rot * gap); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); if (pig) { if (!output_pv.empty()) { @@ -695,11 +663,12 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } } } else { - output.concat(pwd2_in * t); + output_pv = path_in * t; + output.insert(output.end(), output_pv.begin(), output_pv.end()); } } if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { - output = paths_to_pw(output_pv); + output = output_pv; } return output; } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 2e6b35b65..542a4e36e 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -37,7 +37,7 @@ public: virtual ~LPECopyRotate(); virtual void doOnApply (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); - virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + Geom::PathVector doEffect_path_post (Geom::PathVector const & path_in); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doAfterEffect (SPLPEItem const* lpeitem); virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); @@ -59,7 +59,7 @@ private: ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; - ScalarParam split_gap; + ScalarParam gap; BoolParam copies_to_360; EnumParam method; BoolParam mirror_copies; -- cgit v1.2.3 From 3d97b5de6d6a8d585411b364559c067df6d91a9b Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Tue, 25 Apr 2017 23:49:06 +0200 Subject: Little UX tweak (bzr r15644) --- src/live_effects/lpe-copy_rotate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index ef481381d..4869e8279 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -81,13 +81,13 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&starting_angle); registerParameter(&starting_point); registerParameter(&rotation_angle); - registerParameter(&origin); registerParameter(&gap); + registerParameter(&origin); registerParameter(&copies_to_360); registerParameter(&mirror_copies); registerParameter(&split_items); - gap.param_set_range(-999999.0, 999999.0); + gap.param_set_range(-99999.0, 99999.0); gap.param_set_increments(0.1, 0.1); gap.param_set_digits(5); num_copies.param_set_range(1, 999999); -- cgit v1.2.3 From 4420145b9b14f7f752f704b450b9a162dc8a640a Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 26 Apr 2017 00:52:24 +0200 Subject: Improve 0.92 support for Clone Original LPE (bzr r15645) --- src/live_effects/lpe-clone-original.cpp | 39 ++++++++++++++------------------- src/live_effects/lpe-clone-original.h | 3 +-- 2 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index c41b1ef95..47fb6a04e 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -20,8 +20,7 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), - linked_path("LEGACY FALLBACK", "LEGACY FALLBACK", "linkedpath", &wr, this), - linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), + linkeditem(_("Linked Item:"), _("Item from which to take the original data"), "linkeditem", &wr, this), scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), inverse(_("Inverse clone"), _("Use LPE item as origin"), "inverse", &wr, this, false), @@ -37,8 +36,15 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : expanded(false), origin(Geom::Point(0,0)) { - registerParameter(&linked_path); - registerParameter(&linked_item); + //0.92 compatibility + const gchar * linkedpath = this->getRepr()->attribute("linkedpath"); + if (linkedpath && strcmp(linkedpath, "") != 0){ + this->getRepr()->setAttribute("linkeditem", linkedpath); + this->getRepr()->setAttribute("linkedpath", NULL); + this->getRepr()->setAttribute("transform", "false"); + }; + + registerParameter(&linkeditem); registerParameter(&scale); registerParameter(&attributes); registerParameter(&style_attributes); @@ -208,19 +214,8 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ - if (linked_path.linksToPath()) { //Legacy staff - Glib::ustring attributes_value("d"); - attributes.param_setValue(attributes_value); - attributes.write_to_SVG(); - Glib::ustring style_attributes_value(""); - style_attributes.param_setValue(style_attributes_value); - style_attributes.write_to_SVG(); - linked_item.param_readSVGValue(linked_path.param_getSVGValue()); - linked_path.param_readSVGValue(""); - } - - if (linked_item.linksToItem()) { - linked_item.setInverse(inverse); + if (linkeditem.linksToItem()) { + linkeditem.setInverse(inverse); if ( preserve_position_changed != preserve_position ) { if (!preserve_position) { sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &preserve_affine); @@ -262,8 +257,8 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ } style_attr.append(Glib::ustring(style_attributes.param_getSVGValue()).append(",")); - SPItem * from = inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linked_item.getObject()); - SPItem * to = !inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linked_item.getObject()); + SPItem * from = inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linkeditem.getObject()); + SPItem * to = !inverse ? SP_ITEM(sp_lpe_item) : SP_ITEM(linkeditem.getObject()); cloneAttrbutes(from, to, true, g_strdup(attr.c_str()), g_strdup(style_attr.c_str()), true); Geom::OptRect bbox = from->geometricBounds(); if (bbox && preserve_position && origin != Geom::Point(0,0)) { @@ -346,15 +341,15 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) { - if (linked_item.linksToItem()) { - linked_item.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); + if (linkeditem.linksToItem()) { + linkeditem.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); } } void LPECloneOriginal::doEffect (SPCurve * curve) { - if (linked_item.linksToItem() && !inverse) { + if (linkeditem.linksToItem() && !inverse) { SPShape * shape = getCurrentShape(); if(shape){ curve->set_pathvector(shape->getCurve()->get_pathvector()); diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e4328c169..9bab8553f 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -32,8 +32,7 @@ public: void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: - OriginalPathParam linked_path; - OriginalItemParam linked_item; + OriginalItemParam linkeditem; ScalarParam scale; BoolParam preserve_position; BoolParam inverse; -- cgit v1.2.3 From 87e82106ab1ce4eb6c961c9332287594b1be8af3 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 28 Apr 2017 21:41:42 +0200 Subject: Formating code (bzr r15648) --- src/live_effects/effect.cpp | 103 ++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 51 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 017947cda..bfcca422e 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -74,72 +74,73 @@ #include "xml/sp-css-attr.h" #include "live_effects/lpeobject.h" #include "display/curve.h" - +#include +#include namespace Inkscape { namespace LivePathEffect { - +const Glib::ustring DEFAULT_PREF_VALUE = "--default"; const Util::EnumData LPETypeData[] = { // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} #ifdef LPE_ENABLE_TEST_EFFECTS - {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, - {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, + {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, + {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, {CIRCLE_WITH_RADIUS, N_("Circle (by center and radius)"), "circle_with_radius"}, - {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, - {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, - {EXTRUDE, N_("Extrude"), "extrude"}, - {LATTICE, N_("Lattice Deformation"), "lattice"}, - {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, - {OFFSET, N_("Offset"), "offset"}, - {PARALLEL, N_("Parallel"), "parallel"}, - {PATH_LENGTH, N_("Path length"), "path_length"}, - {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, - {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, - {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, - {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, - {TEXT_LABEL, N_("Text label"), "text_label"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, + {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, + {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, + {EXTRUDE, N_("Extrude"), "extrude"}, + {LATTICE, N_("Lattice Deformation"), "lattice"}, + {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, + {OFFSET, N_("Offset"), "offset"}, + {PARALLEL, N_("Parallel"), "parallel"}, + {PATH_LENGTH, N_("Path length"), "path_length"}, + {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, + {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, + {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, + {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, + {TEXT_LABEL, N_("Text label"), "text_label"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, #endif /* 0.46 */ - {BEND_PATH, N_("Bend"), "bend_path"}, - {GEARS, N_("Gears"), "gears"}, - {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG - {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"}, + {BEND_PATH, N_("Bend"), "bend_path"}, + {GEARS, N_("Gears"), "gears"}, + {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG + {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"}, /* 0.47 */ - {VONKOCH, N_("VonKoch"), "vonkoch"}, - {KNOT, N_("Knot"), "knot"}, - {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, - {SPIRO, N_("Spiro spline"), "spiro"}, - {ENVELOPE, N_("Envelope Deformation"), "envelope"}, - {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, - {ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"}, - {SKETCH, N_("Sketch"), "sketch"}, - {RULER, N_("Ruler"), "ruler"}, + {VONKOCH, N_("VonKoch"), "vonkoch"}, + {KNOT, N_("Knot"), "knot"}, + {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, + {SPIRO, N_("Spiro spline"), "spiro"}, + {ENVELOPE, N_("Envelope Deformation"), "envelope"}, + {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, + {ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"}, + {SKETCH, N_("Sketch"), "sketch"}, + {RULER, N_("Ruler"), "ruler"}, /* 0.91 */ - {POWERSTROKE, N_("Power stroke"), "powerstroke"}, - {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, + {POWERSTROKE, N_("Power stroke"), "powerstroke"}, + {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, /* 0.92 */ - {SIMPLIFY, N_("Simplify"), "simplify"}, - {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, - {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, - {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, - {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, - {SHOW_HANDLES, N_("Show handles"), "show_handles"}, - {ROUGHEN, N_("Roughen"), "roughen"}, - {BSPLINE, N_("BSpline"), "bspline"}, - {JOIN_TYPE, N_("Join type"), "join_type"}, - {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, - {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, - {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, + {SIMPLIFY, N_("Simplify"), "simplify"}, + {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, + {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, //TODO:Wrong name with "-" + {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, + {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, + {SHOW_HANDLES, N_("Show handles"), "show_handles"}, + {ROUGHEN, N_("Roughen"), "roughen"}, + {BSPLINE, N_("BSpline"), "bspline"}, + {JOIN_TYPE, N_("Join type"), "join_type"}, + {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, + {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, + {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, /* Ponyscape -> Inkscape 0.92*/ - {ATTACH_PATH, N_("Attach path"), "attach_path"}, - {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, - {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"}, + {ATTACH_PATH, N_("Attach path"), "attach_path"}, + {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, + {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"}, /* 9.93 */ - {MEASURE_LINE, N_("Measure Line"), "measure-line"}, + {MEASURE_LINE, N_("Measure Line"), "measure_line"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); -- cgit v1.2.3 From 8f46a5b0b98499b98623370b3fa4d15e22d5cbef Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 28 Apr 2017 22:04:47 +0200 Subject: Code formating (bzr r15649) --- src/live_effects/lpe-bendpath.cpp | 8 +++--- src/live_effects/lpe-bounding-box.cpp | 4 +-- src/live_effects/lpe-constructgrid.cpp | 4 +-- src/live_effects/lpe-curvestitch.cpp | 16 +++++------ src/live_effects/lpe-dynastroke.cpp | 22 +++++++-------- src/live_effects/lpe-envelope.cpp | 12 ++++---- src/live_effects/lpe-extrude.cpp | 2 +- src/live_effects/lpe-fill-between-many.cpp | 10 +++---- src/live_effects/lpe-fill-between-strokes.cpp | 14 +++++----- src/live_effects/lpe-interpolate.cpp | 6 ++-- src/live_effects/lpe-knot.cpp | 12 ++++---- src/live_effects/lpe-lattice.cpp | 32 ++++++++++----------- src/live_effects/lpe-line_segment.cpp | 2 +- src/live_effects/lpe-offset.cpp | 2 +- src/live_effects/lpe-parallel.cpp | 6 ++-- src/live_effects/lpe-path_length.cpp | 8 +++--- src/live_effects/lpe-patternalongpath.cpp | 20 +++++++------- src/live_effects/lpe-perp_bisector.cpp | 4 +-- src/live_effects/lpe-perspective_path.cpp | 10 +++---- src/live_effects/lpe-powerstroke.cpp | 16 +++++------ src/live_effects/lpe-recursiveskeleton.cpp | 2 +- src/live_effects/lpe-rough-hatches.cpp | 40 +++++++++++++-------------- src/live_effects/lpe-ruler.cpp | 18 ++++++------ src/live_effects/lpe-skeleton.cpp | 2 +- src/live_effects/lpe-sketch.cpp | 34 +++++++++++------------ src/live_effects/lpe-tangent_to_curve.cpp | 8 +++--- src/live_effects/lpe-test-doEffect-stack.cpp | 8 +++--- src/live_effects/lpe-text_label.cpp | 2 +- src/live_effects/lpe-vonkoch.cpp | 18 ++++++------ 29 files changed, 171 insertions(+), 171 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index b1e133292..363356cac 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -57,10 +57,10 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : 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) { - registerParameter( dynamic_cast(&bend_path) ); - registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y_rel) ); - registerParameter( dynamic_cast(&vertical_pattern) ); + registerParameter( &bend_path ); + registerParameter( &prop_scale); + registerParameter( &scale_y_rel); + registerParameter( &vertical_pattern); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); diff --git a/src/live_effects/lpe-bounding-box.cpp b/src/live_effects/lpe-bounding-box.cpp index 11fb34e04..c83d7e3bc 100644 --- a/src/live_effects/lpe-bounding-box.cpp +++ b/src/live_effects/lpe-bounding-box.cpp @@ -20,8 +20,8 @@ LPEBoundingBox::LPEBoundingBox(LivePathEffectObject *lpeobject) : linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this), visual_bounds(_("Visual Bounds"), _("Uses the visual bounding box"), "visualbounds", &wr, this) { - registerParameter( dynamic_cast(&linked_path) ); - registerParameter( dynamic_cast(&visual_bounds) ); + registerParameter(&linked_path); + registerParameter(&visual_bounds); //perceived_path = true; } diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 8d24f9f47..db620fa95 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -24,8 +24,8 @@ LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) : nr_x(_("Size _X:"), _("The size of the grid in X direction."), "nr_x", &wr, this, 5), nr_y(_("Size _Y:"), _("The size of the grid in Y direction."), "nr_y", &wr, this, 5) { - registerParameter( dynamic_cast(&nr_x) ); - registerParameter( dynamic_cast(&nr_y) ); + registerParameter(&nr_x); + registerParameter(&nr_y); nr_x.param_make_integer(); nr_y.param_make_integer(); diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index f2fc00aeb..f8d2e56ca 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -40,14 +40,14 @@ LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) : prop_scale(_("Scale _width:"), _("Scale the width of the stitch path"), "prop_scale", &wr, this, 1), scale_y_rel(_("Scale _width relative to length"), _("Scale the width of the stitch path relative to its length"), "scale_y_rel", &wr, this, false) { - registerParameter( dynamic_cast(&nrofpaths) ); - registerParameter( dynamic_cast(&startpoint_edge_variation) ); - registerParameter( dynamic_cast(&startpoint_spacing_variation) ); - registerParameter( dynamic_cast(&endpoint_edge_variation) ); - registerParameter( dynamic_cast(&endpoint_spacing_variation) ); - registerParameter( dynamic_cast(&strokepath) ); - registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y_rel) ); + registerParameter(&nrofpaths); + registerParameter(&startpoint_edge_variation); + registerParameter(&startpoint_spacing_variation); + registerParameter(&endpoint_edge_variation); + registerParameter(&endpoint_spacing_variation); + registerParameter(&strokepath ); + registerParameter(&prop_scale); + registerParameter(&scale_y_rel); nrofpaths.param_make_integer(); nrofpaths.param_set_range(2, Geom::infinity()); diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 50bbe6451..33e754a8a 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -55,17 +55,17 @@ LPEDynastroke::LPEDynastroke(LivePathEffectObject *lpeobject) : capping(_("Capping:"), _("left capping"), "capping", &wr, this, "M 100,5 C 50,5 0,0 0,0 0,0 50,-5 100,-5") { - registerParameter( dynamic_cast(& method) ); - registerParameter( dynamic_cast(& width) ); - registerParameter( dynamic_cast(& roundness) ); - registerParameter( dynamic_cast(& angle) ); - //registerParameter( dynamic_cast(& modulo_pi) ); - registerParameter( dynamic_cast(& start_cap) ); - registerParameter( dynamic_cast(& growfor) ); - registerParameter( dynamic_cast(& end_cap) ); - registerParameter( dynamic_cast(& fadefor) ); - registerParameter( dynamic_cast(& round_ends) ); - registerParameter( dynamic_cast(& capping) ); + registerParameter(&method); + registerParameter(&width); + registerParameter(&roundness); + registerParameter(&angle); + //registerParameter(&modulo_pi) ); + registerParameter(&start_cap); + registerParameter(&growfor); + registerParameter(&end_cap); + registerParameter(&fadefor); + registerParameter(&round_ends); + registerParameter(&capping); width.param_set_range(0, Geom::infinity()); roundness.param_set_range(0.01, 1); diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 61a696435..8528ab14d 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -23,12 +23,12 @@ LPEEnvelope::LPEEnvelope(LivePathEffectObject *lpeobject) : xx(_("_Enable left & right paths"), _("Enable the left and right deformation paths"), "xx", &wr, this, true), yy(_("_Enable top & bottom paths"), _("Enable the top and bottom deformation paths"), "yy", &wr, this, true) { - registerParameter( dynamic_cast(&yy) ); - registerParameter( dynamic_cast(&xx) ); - registerParameter( dynamic_cast(&bend_path1) ); - registerParameter( dynamic_cast(&bend_path2) ); - registerParameter( dynamic_cast(&bend_path3) ); - registerParameter( dynamic_cast(&bend_path4) ); + registerParameter(&yy); + registerParameter(&xx); + registerParameter(&bend_path1); + registerParameter(&bend_path2); + registerParameter(&bend_path3); + registerParameter(&bend_path4); concatenate_before_pwd2 = true; apply_to_clippath_and_mask = true; } diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index daa30d45a..4a3ad7508 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -27,7 +27,7 @@ LPEExtrude::LPEExtrude(LivePathEffectObject *lpeobject) : show_orig_path = true; concatenate_before_pwd2 = false; - registerParameter( dynamic_cast(&extrude_vector) ); + registerParameter(&extrude_vector); } LPEExtrude::~LPEExtrude() diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 2e1fe0dc1..40fa91c68 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -25,11 +25,11 @@ LPEFillBetweenMany::LPEFillBetweenMany(LivePathEffectObject *lpeobject) : join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true), close(_("Close"), _("Close path"), "close", &wr, this, true) { - registerParameter( dynamic_cast(&linked_paths) ); - registerParameter( dynamic_cast(&fuse) ); - registerParameter( dynamic_cast(&allow_transforms) ); - registerParameter( dynamic_cast(&join) ); - registerParameter( dynamic_cast(&close) ); + registerParameter(&linked_paths); + registerParameter(&fuse); + registerParameter(&allow_transforms); + registerParameter(&join); + registerParameter(&close); transformmultiply = false; } diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 43fef4288..f8d86ae99 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -25,13 +25,13 @@ LPEFillBetweenStrokes::LPEFillBetweenStrokes(LivePathEffectObject *lpeobject) : join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true), close(_("Close"), _("Close path"), "close", &wr, this, true) { - registerParameter( dynamic_cast(&linked_path) ); - registerParameter( dynamic_cast(&second_path) ); - registerParameter( dynamic_cast(&reverse_second) ); - registerParameter( dynamic_cast(&fuse) ); - registerParameter( dynamic_cast(&allow_transforms) ); - registerParameter( dynamic_cast(&join) ); - registerParameter( dynamic_cast(&close) ); + registerParameter(&linked_path); + registerParameter(&second_path); + registerParameter(&reverse_second); + registerParameter(&fuse); + registerParameter(&allow_transforms); + registerParameter(&join); + registerParameter(&close); transformmultiply = false; } diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index e95dc5f38..db3faa307 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -30,9 +30,9 @@ LPEInterpolate::LPEInterpolate(LivePathEffectObject *lpeobject) : { show_orig_path = true; - registerParameter( dynamic_cast(&trajectory_path) ); - registerParameter( dynamic_cast(&equidistant_spacing) ); - registerParameter( dynamic_cast(&number_of_steps) ); + registerParameter(&trajectory_path); + registerParameter(&equidistant_spacing); + registerParameter(&number_of_steps); number_of_steps.param_make_integer(); number_of_steps.param_set_range(2, Geom::infinity()); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 2defecb77..261612fdb 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -356,12 +356,12 @@ LPEKnot::LPEKnot(LivePathEffectObject *lpeobject) : switcher(0.,0.) { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&interruption_width) ); - registerParameter( dynamic_cast(&prop_to_stroke_width) ); - registerParameter( dynamic_cast(&add_stroke_width) ); - registerParameter( dynamic_cast(&add_other_stroke_width) ); - registerParameter( dynamic_cast(&switcher_size) ); - registerParameter( dynamic_cast(&crossing_points_vector) ); + registerParameter(&interruption_width); + registerParameter(&prop_to_stroke_width); + registerParameter(&add_stroke_width); + registerParameter(&add_other_stroke_width); + registerParameter(&switcher_size); + registerParameter(&crossing_points_vector); _provides_knotholder_entities = true; } diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index acffed000..124a7a9c6 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -50,22 +50,22 @@ LPELattice::LPELattice(LivePathEffectObject *lpeobject) : { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&grid_point0) ); - registerParameter( dynamic_cast(&grid_point1) ); - registerParameter( dynamic_cast(&grid_point2) ); - registerParameter( dynamic_cast(&grid_point3) ); - registerParameter( dynamic_cast(&grid_point4) ); - registerParameter( dynamic_cast(&grid_point5) ); - registerParameter( dynamic_cast(&grid_point6) ); - registerParameter( dynamic_cast(&grid_point7) ); - registerParameter( dynamic_cast(&grid_point8) ); - registerParameter( dynamic_cast(&grid_point9) ); - registerParameter( dynamic_cast(&grid_point10) ); - registerParameter( dynamic_cast(&grid_point11) ); - registerParameter( dynamic_cast(&grid_point12) ); - registerParameter( dynamic_cast(&grid_point13) ); - registerParameter( dynamic_cast(&grid_point14) ); - registerParameter( dynamic_cast(&grid_point15) ); + registerParameter(&grid_point0); + registerParameter(&grid_point1); + registerParameter(&grid_point2); + registerParameter(&grid_point3); + registerParameter(&grid_point4); + registerParameter(&grid_point5); + registerParameter(&grid_point6); + registerParameter(&grid_point7); + registerParameter(&grid_point8); + registerParameter(&grid_point9); + registerParameter(&grid_point10); + registerParameter(&grid_point11); + registerParameter(&grid_point12); + registerParameter(&grid_point13); + registerParameter(&grid_point14); + registerParameter(&grid_point15); apply_to_clippath_and_mask = true; } diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index cc024fb92..fd23da804 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -32,7 +32,7 @@ LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) : end_type(_("End type:"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH) { /* register all your parameters here, so Inkscape knows which parameters this effect has: */ - registerParameter( dynamic_cast(&end_type) ); + registerParameter(&end_type); } LPELineSegment::~LPELineSegment() diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 057f404e0..c853e4afa 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -27,7 +27,7 @@ LPEOffset::LPEOffset(LivePathEffectObject *lpeobject) : { show_orig_path = true; apply_to_clippath_and_mask = true; - registerParameter(dynamic_cast(&offset_pt)); + registerParameter(&offset_pt); } LPEOffset::~LPEOffset() diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 276749c43..271442c7d 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -51,9 +51,9 @@ LPEParallel::LPEParallel(LivePathEffectObject *lpeobject) : show_orig_path = true; _provides_knotholder_entities = true; - registerParameter(dynamic_cast(&offset_pt)); - registerParameter( dynamic_cast(&length_left) ); - registerParameter( dynamic_cast(&length_right) ); + registerParameter(&offset_pt); + registerParameter(&length_left); + registerParameter(&length_right); } LPEParallel::~LPEParallel() diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index a06dbde98..61818a73b 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -26,10 +26,10 @@ LPEPathLength::LPEPathLength(LivePathEffectObject *lpeobject) : unit(_("Unit:"), _("Unit"), "unit", &wr, this), display_unit(_("Display unit"), _("Print unit after path length"), "display_unit", &wr, this, true) { - registerParameter(dynamic_cast(&scale)); - registerParameter(dynamic_cast(&info_text)); - registerParameter(dynamic_cast(&unit)); - registerParameter(dynamic_cast(&display_unit)); + registerParameter(&scale); + registerParameter(&info_text); + registerParameter(&unit); + registerParameter(&display_unit); } LPEPathLength::~LPEPathLength() diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 966e9020e..b026bbc22 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -85,16 +85,16 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."), "fuse_tolerance", &wr, this, 0) { - registerParameter( dynamic_cast(&pattern) ); - registerParameter( dynamic_cast(©type) ); - registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y_rel) ); - registerParameter( dynamic_cast(&spacing) ); - registerParameter( dynamic_cast(&normal_offset) ); - registerParameter( dynamic_cast(&tang_offset) ); - registerParameter( dynamic_cast(&prop_units) ); - registerParameter( dynamic_cast(&vertical_pattern) ); - registerParameter( dynamic_cast(&fuse_tolerance) ); + registerParameter(&pattern); + registerParameter(©type); + registerParameter(&prop_scale); + registerParameter(&scale_y_rel); + registerParameter(&spacing); + registerParameter(&normal_offset); + registerParameter(&tang_offset); + registerParameter(&prop_units); + registerParameter(&vertical_pattern); + registerParameter(&fuse_tolerance); prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index bce22250a..dab169cfe 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -99,8 +99,8 @@ LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) : _provides_knotholder_entities = true; // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&length_left) ); - registerParameter( dynamic_cast(&length_right) ); + registerParameter(&length_left); + registerParameter(&length_right); } LPEPerpBisector::~LPEPerpBisector() diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index b83fb67d7..435c91c2d 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -51,11 +51,11 @@ LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : uses_plane_xy(_("Uses XY plane?"), _("If true, put the path on the left side of an imaginary box, otherwise on the right side"), "uses_plane_xy", &wr, this, true) { // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&scalex) ); - registerParameter( dynamic_cast(&scaley) ); - registerParameter( dynamic_cast(&offsetx) ); - registerParameter( dynamic_cast(&offsety) ); - registerParameter( dynamic_cast(&uses_plane_xy) ); + registerParameter( &scalex); + registerParameter( &scaley); + registerParameter( &offsetx); + registerParameter( &offsety); + registerParameter( &uses_plane_xy); concatenate_before_pwd2 = true; // don't split the path into its subpaths _provides_knotholder_entities = true; diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index e9f3975c7..d87f92fcc 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -179,14 +179,14 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : interpolator_beta.addSlider(true); interpolator_beta.param_set_range(0.,1.); - registerParameter( dynamic_cast(&offset_points) ); - registerParameter( dynamic_cast(&sort_points) ); - registerParameter( dynamic_cast(&interpolator_type) ); - registerParameter( dynamic_cast(&interpolator_beta) ); - registerParameter( dynamic_cast(&start_linecap_type) ); - registerParameter( dynamic_cast(&linejoin_type) ); - registerParameter( dynamic_cast(&miter_limit) ); - registerParameter( dynamic_cast(&end_linecap_type) ); + registerParameter(&offset_points); + registerParameter(&sort_points); + registerParameter(&interpolator_type); + registerParameter(&interpolator_beta); + registerParameter(&start_linecap_type); + registerParameter(&linejoin_type); + registerParameter(&miter_limit); + registerParameter(&end_linecap_type); } LPEPowerStroke::~LPEPowerStroke() diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index aa0db920b..47613f58e 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -28,7 +28,7 @@ LPERecursiveSkeleton::LPERecursiveSkeleton(LivePathEffectObject *lpeobject) : concatenate_before_pwd2 = true; iterations.param_make_integer(true); iterations.param_set_range(1, 15); - registerParameter( dynamic_cast(&iterations) ); + registerParameter(&iterations); } diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 3cc8658ea..d832b3615 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -241,26 +241,26 @@ LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) : // bender(_("Global bending"), _("Relative position to a reference point defines global bending direction and amount"), "bender", &wr, this, Geom::Point(-5,0)) { - registerParameter( dynamic_cast(&direction) ); - registerParameter( dynamic_cast(&dist_rdm) ); - registerParameter( dynamic_cast(&growth) ); - registerParameter( dynamic_cast(&do_bend) ); - registerParameter( dynamic_cast(&bender) ); - registerParameter( dynamic_cast(&top_edge_variation) ); - registerParameter( dynamic_cast(&bot_edge_variation) ); - registerParameter( dynamic_cast(&top_tgt_variation) ); - registerParameter( dynamic_cast(&bot_tgt_variation) ); - registerParameter( dynamic_cast(&scale_tf) ); - registerParameter( dynamic_cast(&scale_tb) ); - registerParameter( dynamic_cast(&scale_bf) ); - registerParameter( dynamic_cast(&scale_bb) ); - registerParameter( dynamic_cast(&top_smth_variation) ); - registerParameter( dynamic_cast(&bot_smth_variation) ); - registerParameter( dynamic_cast(&fat_output) ); - registerParameter( dynamic_cast(&stroke_width_top) ); - registerParameter( dynamic_cast(&stroke_width_bot) ); - registerParameter( dynamic_cast(&front_thickness) ); - registerParameter( dynamic_cast(&back_thickness) ); + registerParameter(&direction); + registerParameter(&dist_rdm); + registerParameter(&growth); + registerParameter(&do_bend); + registerParameter(&bender); + registerParameter(&top_edge_variation); + registerParameter(&bot_edge_variation); + registerParameter(&top_tgt_variation); + registerParameter(&bot_tgt_variation); + registerParameter(&scale_tf); + registerParameter(&scale_tb); + registerParameter(&scale_bf); + registerParameter(&scale_bb); + registerParameter(&top_smth_variation); + registerParameter(&bot_smth_variation); + registerParameter(&fat_output); + registerParameter(&stroke_width_top); + registerParameter(&stroke_width_bot); + registerParameter(&front_thickness); + registerParameter(&back_thickness); //hatch_dist.param_set_range(0.1, Geom::infinity()); growth.param_set_range(0, Geom::infinity()); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 60c2a3e1c..852592219 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -45,15 +45,15 @@ LPERuler::LPERuler(LivePathEffectObject *lpeobject) : offset(_("_Offset:"), _("Offset of first mark"), "offset", &wr, this, 0.0), border_marks(_("Border marks:"), _("Choose whether to draw marks at the beginning and end of the path"), "border_marks", BorderMarkTypeConverter, &wr, this, BORDERMARK_BOTH) { - registerParameter(dynamic_cast(&unit)); - registerParameter(dynamic_cast(&mark_distance)); - registerParameter(dynamic_cast(&mark_length)); - registerParameter(dynamic_cast(&minor_mark_length)); - registerParameter(dynamic_cast(&major_mark_steps)); - registerParameter(dynamic_cast(&shift)); - registerParameter(dynamic_cast(&offset)); - registerParameter(dynamic_cast(&mark_dir)); - registerParameter(dynamic_cast(&border_marks)); + registerParameter(&unit); + registerParameter(&mark_distance); + registerParameter(&mark_length); + registerParameter(&minor_mark_length); + registerParameter(&major_mark_steps); + registerParameter(&shift); + registerParameter(&offset); + registerParameter(&mark_dir); + registerParameter(&border_marks); major_mark_steps.param_make_integer(); major_mark_steps.param_set_range(1, 1000); diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 4fc18cee2..d3c94269a 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -37,7 +37,7 @@ LPESkeleton::LPESkeleton(LivePathEffectObject *lpeobject) : //_provides_knotholder_entities /* register all your parameters here, so Inkscape knows which parameters this effect has: */ - registerParameter( dynamic_cast(&number) ); + registerParameter(&number); } LPESkeleton::~LPESkeleton() diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index e01516f2e..e3376b7e5 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -62,25 +62,25 @@ LPESketch::LPESketch(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: //Add some comment in the UI: *warning* the precise output of this effect might change in future releases! //convert to path if you want to keep exact output unchanged in future releases... - //registerParameter( dynamic_cast(&testpointA) ); - registerParameter( dynamic_cast(&nbiter_approxstrokes) ); - registerParameter( dynamic_cast(&strokelength) ); - registerParameter( dynamic_cast(&strokelength_rdm) ); - registerParameter( dynamic_cast(&strokeoverlap) ); - registerParameter( dynamic_cast(&strokeoverlap_rdm) ); - registerParameter( dynamic_cast(&ends_tolerance) ); - registerParameter( dynamic_cast(¶llel_offset) ); - registerParameter( dynamic_cast(&tremble_size) ); - registerParameter( dynamic_cast(&tremble_frequency) ); + //registerParameter(&testpointA) ); + registerParameter(&nbiter_approxstrokes); + registerParameter(&strokelength); + registerParameter(&strokelength_rdm); + registerParameter(&strokeoverlap); + registerParameter(&strokeoverlap_rdm); + registerParameter(&ends_tolerance); + registerParameter(¶llel_offset); + registerParameter(&tremble_size); + registerParameter(&tremble_frequency); #ifdef LPE_SKETCH_USE_CONSTRUCTION_LINES - registerParameter( dynamic_cast(&nbtangents) ); - registerParameter( dynamic_cast(&tgt_places_rdmness) ); - registerParameter( dynamic_cast(&tgtscale) ); - registerParameter( dynamic_cast(&tgtlength) ); - registerParameter( dynamic_cast(&tgtlength_rdm) ); + registerParameter(&nbtangents); + registerParameter(&tgt_places_rdmness); + registerParameter(&tgtscale); + registerParameter(&tgtlength); + registerParameter(&tgtlength_rdm); #ifdef LPE_SKETCH_USE_CURVATURE - registerParameter( dynamic_cast(&min_curvature) ); - registerParameter( dynamic_cast(&max_curvature) ); + registerParameter(&min_curvature); + registerParameter(&max_curvature); #endif #endif diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 5f63e1ee9..69a4dfad9 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -60,10 +60,10 @@ LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) : show_orig_path = true; _provides_knotholder_entities = true; - registerParameter( dynamic_cast(&angle) ); - registerParameter( dynamic_cast(&t_attach) ); - registerParameter( dynamic_cast(&length_left) ); - registerParameter( dynamic_cast(&length_right) ); + registerParameter(&angle); + registerParameter(&t_attach); + registerParameter(&length_left); + registerParameter(&length_right); } LPETangentToCurve::~LPETangentToCurve() diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 324893706..c484c88a2 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -21,12 +21,12 @@ LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : point(_("Point param:"), "tooltip of point parameter", "point_param", &wr, this), path(_("Path param:"), "tooltip of path parameter", "path_param", &wr, this,"M 0,100 100,0") { - registerParameter( dynamic_cast(&step) ); - registerParameter( dynamic_cast(&point) ); - registerParameter( dynamic_cast(&path) ); + registerParameter(&step); + registerParameter(&point); + registerParameter(&path); point.set_oncanvas_looks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); - point.param_setValue(point,true); + point.param_setValue(point); } LPEdoEffectStackTest::~LPEdoEffectStackTest() diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp index 709d05e18..0c1db2f04 100644 --- a/src/live_effects/lpe-text_label.cpp +++ b/src/live_effects/lpe-text_label.cpp @@ -23,7 +23,7 @@ LPETextLabel::LPETextLabel(LivePathEffectObject *lpeobject) : Effect(lpeobject), label(_("Label:"), _("Text label attached to the path"), "label", &wr, this, "This is a label") { - registerParameter( dynamic_cast(&label) ); + registerParameter(&label); } LPETextLabel::~LPETextLabel() diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 47e2a1cec..b9fd8908a 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -53,15 +53,15 @@ LPEVonKoch::LPEVonKoch(LivePathEffectObject *lpeobject) : maxComplexity(_("_Max complexity:"), _("Disable effect if the output is too complex"), "maxComplexity", &wr, this, 1000) { //FIXME: a path is used here instead of 2 points to work around path/point param incompatibility bug. - registerParameter( dynamic_cast(&ref_path) ); - //registerParameter( dynamic_cast(&refA) ); - //registerParameter( dynamic_cast(&refB) ); - registerParameter( dynamic_cast(&generator) ); - registerParameter( dynamic_cast(&similar_only) ); - registerParameter( dynamic_cast(&nbgenerations) ); - registerParameter( dynamic_cast(&drawall) ); - registerParameter( dynamic_cast(&maxComplexity) ); - //registerParameter( dynamic_cast(&draw_boxes) ); + registerParameter(&ref_path); + //registerParameter(&refA) ); + //registerParameter(&refB) ); + registerParameter(&generator); + registerParameter(&similar_only); + registerParameter(&nbgenerations); + registerParameter(&drawall); + registerParameter(&maxComplexity); + //registerParameter(&draw_boxes) ); apply_to_clippath_and_mask = true; nbgenerations.param_make_integer(); nbgenerations.param_set_range(0, Geom::infinity()); -- cgit v1.2.3 From e5601e5e84df30c40d93271fd69cecd31391e309 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 29 Apr 2017 02:01:22 +0200 Subject: Rewrite UX (bzr r15620.1.12) --- src/live_effects/effect.cpp | 102 +++++++++++++- src/live_effects/effect.h | 6 +- src/live_effects/lpe-measure-line.cpp | 152 ++++++++------------- src/live_effects/lpe-measure-line.h | 1 - src/live_effects/parameter/array.h | 2 +- src/live_effects/parameter/bool.cpp | 6 + src/live_effects/parameter/bool.h | 2 +- src/live_effects/parameter/enum.h | 10 +- .../parameter/filletchamferpointarray.h | 1 + src/live_effects/parameter/fontbutton.cpp | 7 +- src/live_effects/parameter/fontbutton.h | 6 +- src/live_effects/parameter/item.cpp | 4 + src/live_effects/parameter/item.h | 1 + src/live_effects/parameter/originalpatharray.h | 3 +- src/live_effects/parameter/parameter.cpp | 10 ++ src/live_effects/parameter/parameter.h | 6 +- src/live_effects/parameter/path.cpp | 4 + src/live_effects/parameter/path.h | 1 + src/live_effects/parameter/point.cpp | 13 ++ src/live_effects/parameter/point.h | 2 + src/live_effects/parameter/powerstrokepointarray.h | 2 +- src/live_effects/parameter/random.cpp | 14 ++ src/live_effects/parameter/random.h | 4 +- src/live_effects/parameter/text.cpp | 4 +- src/live_effects/parameter/text.h | 6 +- src/live_effects/parameter/togglebutton.cpp | 14 +- src/live_effects/parameter/togglebutton.h | 2 + src/live_effects/parameter/transformedpoint.cpp | 19 +++ src/live_effects/parameter/transformedpoint.h | 4 +- src/live_effects/parameter/unit.cpp | 4 +- src/live_effects/parameter/unit.h | 5 +- src/live_effects/parameter/vector.cpp | 19 +++ src/live_effects/parameter/vector.h | 3 +- 33 files changed, 305 insertions(+), 134 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index bfcca422e..37694f32f 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -73,6 +73,7 @@ #include "path-chemistry.h" #include "xml/sp-css-attr.h" #include "live_effects/lpeobject.h" +#include #include "display/curve.h" #include #include @@ -80,7 +81,7 @@ namespace Inkscape { namespace LivePathEffect { -const Glib::ustring DEFAULT_PREF_VALUE = "--default"; + const Util::EnumData LPETypeData[] = { // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} #ifdef LPE_ENABLE_TEST_EFFECTS @@ -645,6 +646,7 @@ void Effect::readallParameters(Inkscape::XML::Node const* repr) { std::vector::iterator it = param_vector.begin(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); while (it != param_vector.end()) { Parameter * param = *it; const gchar * key = param->param_key.c_str(); @@ -655,10 +657,17 @@ Effect::readallParameters(Inkscape::XML::Node const* repr) g_warning("Effect::readallParameters - '%s' not accepted for %s", value, key); } } else { - // set default value - param->param_set_default(); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(pref_path).isValid(); + if(valid){ + param->param_update_default(prefs->getString(pref_path).c_str()); + } else { + param->param_set_default(); + } } - ++it; } } @@ -777,6 +786,91 @@ Effect::newWidget() return dynamic_cast(vbox); } +/** + * This *creates* a new widget, with default values setter + */ +Gtk::Widget * +Effect::defaultParamSet() +{ + // use manage here, because after deletion of Effect object, others might still be pointing to this widget. + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox() ); + + vbox->set_border_width(5); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); + vbox_expander->set_border_width(10); + vbox_expander->set_spacing(2); + Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(effectType()); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(effectType()); + std::vector::iterator it = param_vector.begin(); + Inkscape::UI::Widget::Registry * wr; + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter * param = *it; + Glib::ustring * tip = param->param_getTooltip(); + const gchar * key = param->param_key.c_str(); + const gchar * value = param->param_label.c_str(); + const gchar * tooltip_extra = _(". Change custom values for this parameter"); + Glib::ustring tooltip = param->param_tooltip + (Glib::ustring)tooltip_extra; + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(pref_path).isValid(); + const gchar * set_or_upd; + if (valid) { + set_or_upd = _("Update"); + } else { + set_or_upd = _("Set"); + } + Gtk::HBox * vbox_param = Gtk::manage( new Gtk::HBox(true) ); + Gtk::Label *parameter_label = Gtk::manage(new Gtk::Label(value, Gtk::ALIGN_START)); + parameter_label->set_use_markup(true); + parameter_label->set_use_underline (true); + parameter_label->set_ellipsize(Pango::ELLIPSIZE_END); + vbox_param->pack_start(*parameter_label, true, true, 2); + Gtk::Button *set = Gtk::manage(new Gtk::Button((Glib::ustring)set_or_upd)); + Gtk::Button *unset = Gtk::manage(new Gtk::Button(Glib::ustring(_("Unset")))); + unset->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Effect::unsetDefaultParam), pref_path, set, unset)); + set->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Effect::setDefaultParam), pref_path, param->param_getSVGValue(), set, unset)); + if (!valid) { + unset->set_sensitive(false); + } + vbox_param->pack_start(*set, true, true, 2); + vbox_param->pack_start(*unset, true, true, 2); + + vbox_expander->pack_start(*vbox_param, true, true, 2); + } + ++it; + } + Glib::ustring tip = "" + effectname + (Glib::ustring)_(": Set default parameters to current values"); + Gtk::Expander * expander = Gtk::manage(new Gtk::Expander(tip)); + expander->set_use_markup(true); + expander->add(*vbox_expander); + expander->set_expanded(false); + vbox->pack_start(*dynamic_cast (expander), true, true, 2); + return dynamic_cast(vbox); +} + +void +Effect::setDefaultParam(Glib::ustring pref_path, gchar * value, Gtk::Button *set , Gtk::Button *unset) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(pref_path, (Glib::ustring)value); + gchar * label = _("Update"); + set->set_label((Glib::ustring)label); + unset->set_sensitive(true); +} + +void +Effect::unsetDefaultParam(Glib::ustring pref_path, Gtk::Button *set, Gtk::Button *unset) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->remove(pref_path); + gchar * label = _("Set"); + set->set_label((Glib::ustring)label); + unset->set_sensitive(false); +} Inkscape::XML::Node *Effect::getRepr() { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index f5e41d50e..c34c391c0 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -94,7 +94,7 @@ public: virtual void doEffect (SPCurve * curve); virtual Gtk::Widget * newWidget(); - + virtual Gtk::Widget * defaultParamSet(); /** * Sets all parameters to their default values and writes them to SVG. */ @@ -172,13 +172,15 @@ protected: // this boolean defaults to false, it concatenates the input path to one pwd2, // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. std::vector items; double current_zoom; std::vector selectedNodesPoints; + private: + void setDefaultParam(Glib::ustring pref_path, gchar * value, Gtk::Button *set , Gtk::Button *unset); + void unsetDefaultParam(Glib::ustring pref_path, Gtk::Button *set , Gtk::Button *unset); bool provides_own_flash_paths; // if true, the standard flash path is suppressed bool is_ready; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 86d72615c..52aa56fa0 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -49,32 +49,33 @@ static const Util::EnumDataConverter OMConverter(OrientationM LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - unit(_("Unit*"), _("Unit"), "unit", &wr, this, "px"), - fontbutton(_("Font*"), _("Font Selector"), "fontbutton", &wr, this), + unit(_("Unit"), _("Unit"), "unit", &wr, this, "px"), + fontbutton(_("Font"), _("Font Selector"), "fontbutton", &wr, this), orientation(_("Orientation"), _("Orientation method"), "orientation", OMConverter, &wr, this, OM_PARALLEL, false), curve_linked(_("Curve on origin"), _("Curve on origin, set 0 to start/end"), "curve_linked", &wr, this, 1), - precision(_("Precision*"), _("Precision"), "precision", &wr, this, 2), - position(_("Position*"), _("Position"), "position", &wr, this, 5), - text_top_bottom(_("Text top/bottom*"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), - text_right_left(_("Text right/left*"), _("Text right/left"), "text_right_left", &wr, this, 0), - helpline_distance(_("Helpline distance*"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), - helpline_overlap(_("Helpline overlap*"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), - scale(_("Scale*"), _("Scaling factor"), "scale", &wr, this, 1.0), - format(_("Format*"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"{measure}{unit}"), + precision(_("Precision"), _("Precision"), "precision", &wr, this, 2), + position(_("Position"), _("Position"), "position", &wr, this, 5), + text_top_bottom(_("Text top/bottom"), _("Text top/bottom"), "text_top_bottom", &wr, this, 0), + text_right_left(_("Text right/left"), _("Text right/left"), "text_right_left", &wr, this, 0), + helpline_distance(_("Helpline distance"), _("Helpline distance"), "helpline_distance", &wr, this, 0.0), + helpline_overlap(_("Helpline overlap"), _("Helpline overlap"), "helpline_overlap", &wr, this, 2.0), + scale(_("Scale"), _("Scaling factor"), "scale", &wr, this, 1.0), + format(_("Format"), _("Format the number ex:{measure} {unit}, return to save"), "format", &wr, this,"{measure}{unit}"), id_origin("id_origin", "id_origin", "id_origin", &wr, this,""), arrows_outside(_("Arrows outside"), _("Arrows outside"), "arrows_outside", &wr, this, false), - flip_side(_("Flip side*"), _("Flip side"), "flip_side", &wr, this, false), - scale_sensitive(_("Scale sensitive*"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), - local_locale(_("Local Number Format*"), _("Local number format"), "local_locale", &wr, this, true), - line_group_05(_("Line Group 0.5*"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), - rotate_anotation(_("Rotate Anotation*"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), - hide_back(_("Hide if label over*"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), - dimline_format(_("CSS DIN line*"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), - helperlines_format(_("CSS helpers*"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), - anotation_format(_("CSS anotation*"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), - arrows_format(_("CSS arrows*"), _("Override CSS to arrows, return to save, empty to reset DIM"), "arrows_format", &wr, this,""), + flip_side(_("Flip side"), _("Flip side"), "flip_side", &wr, this, false), + scale_sensitive(_("Scale sensitive"), _("Costrained scale sensitive to transformed containers"), "scale_sensitive", &wr, this, true), + local_locale(_("Local Number Format"), _("Local number format"), "local_locale", &wr, this, true), + line_group_05(_("Line Group 0.5"), _("Line Group 0.5, from 0.7"), "line_group_05", &wr, this, true), + rotate_anotation(_("Rotate Anotation"), _("Rotate Anotation"), "rotate_anotation", &wr, this, true), + hide_back(_("Hide if label over"), _("Hide DIN line if label over"), "hide_back", &wr, this, true), + dimline_format(_("CSS DIN line"), _("Override CSS to DIN line, return to save, empty to reset to DIM"), "dimline_format", &wr, this,""), + helperlines_format(_("CSS helpers"), _("Override CSS to helper lines, return to save, empty to reset to DIM"), "helperlines_format", &wr, this,""), + anotation_format(_("CSS anotation"), _("Override CSS to anotation text, return to save, empty to reset to DIM"), "anotation_format", &wr, this,""), + arrows_format(_("CSS arrows"), _("Override CSS to arrows, return to save, empty to reset DIM"), "arrows_format", &wr, this,""), expanded(false) { + //set to true the parameters you want to be changed his default values registerParameter(&unit); registerParameter(&fontbutton); registerParameter(&orientation); @@ -99,39 +100,16 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : registerParameter(&anotation_format); registerParameter(&arrows_format); registerParameter(&id_origin); + id_origin.param_hide_canvas_text(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring fontbutton_value = prefs->getString("/live_effects/measure-line/fontbutton"); - if(fontbutton_value.empty()){ - fontbutton_value = "Sans 10"; - } - fontbutton.param_update_default(fontbutton_value); - scale.param_update_default(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); - precision.param_update_default(prefs->getInt("/live_effects/measure-line/precision", 2)); - position.param_update_default(prefs->getDouble("/live_effects/measure-line/position", 10.0)); - text_top_bottom.param_update_default(prefs->getDouble("/live_effects/measure-line/text_top_bottom", 5.0)); - helpline_distance.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); - helpline_overlap.param_update_default(prefs->getDouble("/live_effects/measure-line/helpline_overlap", 0.0)); - Glib::ustring unit_value = prefs->getString("/live_effects/measure-line/unit"); - if(unit_value.empty()){ - unit_value = "px"; - } - unit.param_update_default(unit_value); + Glib::ustring format_value = prefs->getString("/live_effects/measure-line/format"); if(format_value.empty()){ format_value = "{measure}{unit}"; } - format.param_update_default(format_value); - dimline_format.param_update_default(prefs->getString("/live_effects/measure-line/dimline_format")); - helperlines_format.param_update_default(prefs->getString("/live_effects/measure-line/helperlines_format")); - anotation_format.param_update_default(prefs->getString("/live_effects/measure-line/anotation_format")); - arrows_format.param_update_default(prefs->getString("/live_effects/measure-line/arrows_format")); - flip_side.param_update_default(prefs->getBool("/live_effects/measure-line/flip_side")); - scale_sensitive.param_update_default(prefs->getBool("/live_effects/measure-line/scale_sensitive")); - local_locale.param_update_default(prefs->getBool("/live_effects/measure-line/local_locale")); - line_group_05.param_update_default(prefs->getBool("/live_effects/measure-line/line_group_05")); - rotate_anotation.param_update_default(prefs->getBool("/live_effects/measure-line/rotate_anotation")); - hide_back.param_update_default(prefs->getBool("/live_effects/measure-line/hide_back")); + format.param_update_default(format_value.c_str()); + format.param_hide_canvas_text(); dimline_format.param_hide_canvas_text(); helperlines_format.param_hide_canvas_text(); @@ -375,7 +353,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl items.push_back(id); Geom::OptRect bounds = SP_ITEM(elemref)->bounds(SPItem::GEOMETRIC_BBOX); if (bounds) { - anotation_width = bounds->width() * 1.4; + anotation_width = bounds->width() * 1.15; } } @@ -405,8 +383,14 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, b k = (Geom::distance(start,end)/2.0) - arrow_gap - (anotation_width/2.0); } if (Geom::distance(start,end) < anotation_width){ - return; + if ((elemref = document->getObjectById(id))) { + if (remove) { + elemref->deleteObject(); + } + return; + } } + //k = std::max(k , arrow_gap -1); Geom::Ray ray(end, start); Geom::Coord angle = ray.angle(); line_path.start(start); @@ -622,6 +606,9 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } bool overflow = false; const char * downline = g_strdup(Glib::ustring("downline-").append(this->getRepr()->attribute("id")).c_str()); + //delete residual lines if exist + createLine(Geom::Point(),Geom::Point(), downline, true, overflow, true, false); + //Create it if ((anotation_width/2) + std::abs(text_right_left) > Geom::distance(start,end)/2.0) { Geom::Point sstart = end - Point::polar(angle_cross, position); Geom::Point send = end - Point::polar(angle_cross, position); @@ -645,9 +632,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) } overflow = true; createLine(sstart, prog_end, downline, true, overflow, false, false); - } else { - //erase it - createLine(Geom::Point(),Geom::Point(), downline, true, overflow, true, false); } //LINE arrow_gap = 8 * Inkscape::Util::Quantity::convert(0.35 / doc_scale, "mm", display_unit.c_str()); @@ -708,44 +692,41 @@ Gtk::Widget *LPEMeasureLine::newWidget() vbox->set_spacing(2); std::vector::iterator it = param_vector.begin(); - Gtk::HBox * button1 = Gtk::manage(new Gtk::HBox(true,0)); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox(Effect::newWidget()) ); vbox_expander->set_border_width(0); vbox_expander->set_spacing(2); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter *param = *it; - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "dimline_format" && - param->param_key != "helperlines_format" && - param->param_key != "arrows_format" && - param->param_key != "anotation_format") { - vbox->pack_start(*widg, true, true, 2); - } else { - vbox_expander->pack_start(*widg, true, true, 2); - } - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); + if (param->param_key != "id_origin") { + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "dimline_format" && + param->param_key != "helperlines_format" && + param->param_key != "arrows_format" && + param->param_key != "anotation_format") { + vbox->pack_start(*widg, true, true, 2); + } else { + vbox_expander->pack_start(*widg, true, true, 2); + } + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } } } } ++it; } - Gtk::Button *save_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Save '*' as default")))); - save_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::saveDefault)); - button1->pack_start(*save_default, true, true, 2); expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show DIM CSS style override")))); expander->add(*vbox_expander); expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPEMeasureLine::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); - vbox->pack_start(*button1, true, true, 2); return dynamic_cast(vbox); } @@ -766,31 +747,6 @@ LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) return path_in; } -void -LPEMeasureLine::saveDefault() -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/live_effects/measure-line/fontbutton", Glib::ustring(fontbutton.param_getSVGValue())); - prefs->setDouble("/live_effects/measure-line/scale", scale); - prefs->setInt("/live_effects/measure-line/precision", precision); - prefs->setDouble("/live_effects/measure-line/position", position); - prefs->setDouble("/live_effects/measure-line/text_top_bottom", text_top_bottom); - prefs->setDouble("/live_effects/measure-line/helpline_distance", helpline_distance); - prefs->setDouble("/live_effects/measure-line/helpline_overlap", helpline_overlap); - prefs->setString("/live_effects/measure-line/unit", Glib::ustring(unit.get_abbreviation())); - prefs->setString("/live_effects/measure-line/format", Glib::ustring(format.param_getSVGValue())); - prefs->setString("/live_effects/measure-line/dimline_format", Glib::ustring(dimline_format.param_getSVGValue())); - prefs->setString("/live_effects/measure-line/helperlines_format", Glib::ustring(helperlines_format.param_getSVGValue())); - prefs->setString("/live_effects/measure-line/anotation_format", Glib::ustring(anotation_format.param_getSVGValue())); - prefs->setString("/live_effects/measure-line/arrows_format", Glib::ustring(arrows_format.param_getSVGValue())); - prefs->setBool("/live_effects/measure-line/flip_side", flip_side); - prefs->setBool("/live_effects/measure-line/scale_sensitive", scale_sensitive); - prefs->setBool("/live_effects/measure-line/local_locale", local_locale); - prefs->setBool("/live_effects/measure-line/line_group_05", line_group_05); - prefs->setBool("/live_effects/measure-line/rotate_anotation", rotate_anotation); - prefs->setBool("/live_effects/measure-line/hide_back", hide_back); -} - }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 724c0d924..b42f7cfd5 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -49,7 +49,6 @@ public: void createTextLabel(Geom::Point pos, double length, Geom::Coord angle, bool remove, bool valid); void onExpanderChanged(); void createArrowMarker(const char * mode); - void saveDefault(); virtual Gtk::Widget *newWidget(); private: UnitParam unit; diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a600f0257..fa08e1f91 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -59,7 +59,7 @@ public: g_strfreev (strarray); return true; } - + virtual void param_update_default(const gchar * default_value){}; virtual gchar * param_getSVGValue() const { Inkscape::SVGOStringStream os; writesvg(os, _vector); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 813c06b4e..fafa71368 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -42,6 +42,12 @@ BoolParam::param_update_default(bool const default_value) defvalue = default_value; } +void +BoolParam::param_update_default(const gchar * default_value) +{ + param_update_default(helperfns_read_bool(default_value, defvalue)); +} + bool BoolParam::param_readSVGValue(const gchar * strvalue) { diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 7ad8a9368..39f328eaa 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -37,8 +37,8 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); void param_update_default(bool const default_value); + virtual void param_update_default(const gchar * default_value); bool get_value() const { return value; }; - inline operator bool() const { return value; }; private: diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index dbfc68623..0bb2d89b2 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -76,7 +76,15 @@ public: void param_set_default() { param_set_value(defvalue); } - + + void param_update_default(E default_value) { + defvalue = default_value; + } + + virtual void param_update_default(const gchar * default_value) { + param_update_default(enumdataconv->get_id_from_key(Glib::ustring(default_value))); + } + void param_set_value(E val) { value = val; } diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h index b81339a69..4e4268703 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -55,6 +55,7 @@ public: virtual void set_chamfer_steps(int value_chamfer_steps); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); + virtual void param_update_default(const gchar * default_value){}; virtual bool providesKnotHolderEntities() const { return true; } diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 64c203093..5ec98df8c 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -33,9 +33,11 @@ FontButtonParam::param_set_default() { param_setValue(defvalue); } + void -FontButtonParam::param_update_default(const Glib::ustring default_value){ - defvalue = default_value; +FontButtonParam::param_update_default(const gchar * default_value) +{ + defvalue = (Glib::ustring)strdup(default_value); } bool @@ -76,6 +78,7 @@ FontButtonParam::param_setValue(const Glib::ustring newvalue) value = newvalue; } + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index df47251a2..60e1aa46e 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -21,15 +21,15 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const Glib::ustring default_value = ""); + const Glib::ustring default_value = "Sans 10"); virtual ~FontButtonParam() {} virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); - void param_update_default(const Glib::ustring defvalue); + void param_update_default(const gchar * default_value); virtual gchar * param_getSVGValue() const; - void param_setValue(const Glib::ustring newvalue); + void param_setValue(Glib::ustring newvalue); virtual void param_set_default(); diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 93cf2b15f..7b40f4540 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -60,6 +60,10 @@ ItemParam::param_set_default() param_readSVGValue(defvalue); } +void +ItemParam::param_update_default(const gchar * default_value){ + defvalue = strdup(default_value); +} void ItemParam::param_set_and_write_default() diff --git a/src/live_effects/parameter/item.h b/src/live_effects/parameter/item.h index 6c719d451..89c32f9bd 100644 --- a/src/live_effects/parameter/item.h +++ b/src/live_effects/parameter/item.h @@ -36,6 +36,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); + virtual void param_update_default(const gchar * default_value); void param_set_and_write_default(); virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); diff --git a/src/live_effects/parameter/originalpatharray.h b/src/live_effects/parameter/originalpatharray.h index 296c0f7f7..fe9371644 100644 --- a/src/live_effects/parameter/originalpatharray.h +++ b/src/live_effects/parameter/originalpatharray.h @@ -65,12 +65,11 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; virtual void param_set_default(); - + virtual void param_update_default(const gchar * default_value){}; /** Disable the canvas indicators of parent class by overriding this method */ virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; /** Disable the canvas indicators of parent class by overriding this method */ virtual void addCanvasIndicators(SPLPEItem const* /*lpeitem*/, std::vector & /*hp_vec*/) {}; - std::vector _vector; protected: diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index befac4df1..15c81d543 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -107,6 +107,16 @@ ScalarParam::param_update_default(gdouble default_value) defvalue = default_value; } +void +ScalarParam::param_update_default(const gchar * default_value) +{ + double newval; + unsigned int success = sp_svg_number_read_d(default_value, &newval); + if (success == 1) { + param_update_default(newval); + } +} + void ScalarParam::param_set_value(gdouble val) { diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 6cf10710c..ee1d2d547 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -60,7 +60,7 @@ public: void write_to_SVG(); virtual void param_set_default() = 0; - + virtual void param_update_default(const gchar * default_value) = 0; // This creates a new widget (newed with Gtk::manage(new ...);) virtual Gtk::Widget * param_newWidget() = 0; @@ -77,6 +77,7 @@ public: virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) {}; Glib::ustring param_key; + Glib::ustring param_tooltip; Inkscape::UI::Widget::Registry * param_wr; Glib::ustring param_label; @@ -84,7 +85,6 @@ public: bool widget_is_visible; protected: - Glib::ustring param_tooltip; Effect* param_effect; @@ -112,6 +112,7 @@ public: virtual void param_set_default(); void param_update_default(gdouble default_value); + virtual void param_update_default(const gchar * default_value); void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); @@ -120,7 +121,6 @@ public: void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; double param_get_max() { return max; }; double param_get_min() { return min; }; - void param_overwrite_widget(bool overwrite_widget); virtual Gtk::Widget * param_newWidget(); diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index dafc6d406..aa87508ab 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -439,6 +439,10 @@ PathParam::linked_modified_callback(SPObject *linked_obj, guint /*flags*/) SP_OBJECT(param_effect->getLPEObj())->requestModified(SP_OBJECT_MODIFIED_FLAG); } +void +PathParam::param_update_default(const gchar * default_value){ + defvalue = strdup(default_value); +} /* CALLBACK FUNCTIONS FOR THE BUTTONS */ void diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index d2dddbe97..5381a6b36 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -40,6 +40,7 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); + virtual void param_update_default(const gchar * default_value); void param_set_and_write_default(); void set_new_value (Geom::PathVector const &newpath, bool write_to_svg); void set_new_value (Geom::Piecewise > const &newpath, bool write_to_svg); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index db768090a..561f1b34c 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -63,6 +63,19 @@ PointParam::param_update_default(Geom::Point default_point) defvalue = default_point; } +void +PointParam::param_update_default(const gchar * default_point) +{ + gchar ** strarray = g_strsplit(default_point, ",", 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_update_default( Geom::Point(newx, newy) ); + } +} + void PointParam::param_setValue(Geom::Point newpoint, bool write) { diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 5d145a81a..a5153ad80 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -44,6 +44,8 @@ public: Geom::Point param_get_default() const; void param_set_liveupdate(bool live_update); void param_update_default(Geom::Point default_point); + + virtual void param_update_default(const gchar * default_point); virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 56a609fa8..a34163ca1 100644 --- a/src/live_effects/parameter/powerstrokepointarray.h +++ b/src/live_effects/parameter/powerstrokepointarray.h @@ -39,13 +39,13 @@ public: virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); + virtual void param_update_default(const gchar * default_value){}; void set_pwd2(Geom::Piecewise > const & pwd2_in, Geom::Piecewise > const & pwd2_normal_in); Geom::Piecewise > const & get_pwd2() const { return last_pwd2; } Geom::Piecewise > const & get_pwd2_normal() const { return last_pwd2_normal; } void recalculate_controlpoints_for_new_pwd2(Geom::Piecewise > const & pwd2_in); - friend class PowerStrokePointArrayParamKnotHolderEntity; private: diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 075e85ee1..90e53ca0e 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -77,6 +77,20 @@ RandomParam::param_set_default() param_set_value(defvalue, defseed); } +void +RandomParam::param_update_default(gdouble default_value){ + defvalue = default_value; +} + +void +RandomParam::param_update_default(const gchar * default_value){ + double newval; + unsigned int success = sp_svg_number_read_d(default_value, &newval); + if (success == 1) { + param_update_default(newval); + } +} + void RandomParam::param_set_value(gdouble val, long newseed) { diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index ca4440336..5fb6027ac 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -38,9 +38,9 @@ public: void param_set_value(gdouble val, long newseed); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); - + void param_update_default(gdouble default_value); + virtual void param_update_default(const gchar * default_value); void resetRandomizer(); - operator gdouble(); inline gdouble get_value() { return value; } ; diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 5c4cdf4c6..84603149e 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -50,9 +50,9 @@ TextParam::param_set_default() } void -TextParam::param_update_default(Glib::ustring default_value) +TextParam::param_update_default(const gchar * default_value) { - defvalue = default_value; + defvalue = (Glib::ustring)default_value; } void diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 553c84c0a..137f3ee02 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -39,16 +39,16 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; - void param_setValue(const Glib::ustring newvalue); + void param_setValue(Glib::ustring newvalue); void param_hide_canvas_text(); virtual void param_set_default(); - void param_update_default(Glib::ustring default_value); + virtual void param_update_default(const gchar * default_value); void setPos(Geom::Point pos); void setPosAndAnchor(const Geom::Piecewise > &pwd2, const double t, const double length, bool use_curvature = false); void setAnchor(double x_value, double y_value); - const Glib::ustring get_value() const { return defvalue; }; + const Glib::ustring get_value() const { return value; }; private: TextParam(const TextParam&); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index b3f6442bb..b8058e9c8 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -60,6 +60,18 @@ ToggleButtonParam::param_getSVGValue() const return str; } +void +ToggleButtonParam::param_update_default(bool default_value) +{ + defvalue = default_value; +} + +void +ToggleButtonParam::param_update_default(const gchar * default_value) +{ + param_update_default(helperfns_read_bool(default_value, defvalue)); +} + Gtk::Widget * ToggleButtonParam::param_newWidget() { @@ -68,7 +80,7 @@ ToggleButtonParam::param_newWidget() } checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredToggleButton( param_label, + new Inkscape::UI::Widget::RegisteredToggleButton(param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 8390fec86..d6ca15e75 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -51,6 +51,8 @@ public: sigc::signal& signal_toggled() { return _signal_toggled; } virtual void toggled(); + void param_update_default(bool default_value); + virtual void param_update_default(const gchar * default_value); private: ToggleButtonParam(const ToggleButtonParam&); diff --git a/src/live_effects/parameter/transformedpoint.cpp b/src/live_effects/parameter/transformedpoint.cpp index 0d03432c3..22d5ba3a4 100644 --- a/src/live_effects/parameter/transformedpoint.cpp +++ b/src/live_effects/parameter/transformedpoint.cpp @@ -82,6 +82,25 @@ TransformedPointParam::param_getSVGValue() const return str; } +void +TransformedPointParam::param_update_default(Geom::Point default_point) +{ + defvalue = default_point; +} + +void +TransformedPointParam::param_update_default(const gchar * default_point) +{ + gchar ** strarray = g_strsplit(default_point, ",", 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_update_default( Geom::Point(newx, newy) ); + } +} + Gtk::Widget * TransformedPointParam::param_newWidget() { diff --git a/src/live_effects/parameter/transformedpoint.h b/src/live_effects/parameter/transformedpoint.h index c96bedb53..269cc508e 100644 --- a/src/live_effects/parameter/transformedpoint.h +++ b/src/live_effects/parameter/transformedpoint.h @@ -51,7 +51,9 @@ public: void set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); void set_oncanvas_color(guint32 color); - + Geom::Point param_get_default() { return defvalue; } + void param_update_default(Geom::Point default_point); + virtual void param_update_default(const gchar * default_point); virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index b6ea99bfe..b78b75dbf 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -55,9 +55,9 @@ UnitParam::param_set_default() } void -UnitParam::param_update_default(const Glib::ustring default_unit) +UnitParam::param_update_default(const gchar * default_unit) { - defunit = unit_table.getUnit(default_unit); + defunit = unit_table.getUnit((Glib::ustring)default_unit); } void diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index ae58cf956..c662b6edc 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -33,11 +33,10 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); - void param_update_default(const Glib::ustring default_unit); + virtual void param_update_default(const gchar * default_unit); const gchar *get_abbreviation() const; - virtual Gtk::Widget * param_newWidget(); - + operator Inkscape::Util::Unit const *() const { return unit; } private: diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 55b4d4b32..470fa9c2d 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -48,6 +48,25 @@ VectorParam::param_set_default() setVector(defvalue); } +void +VectorParam::param_update_default(Geom::Point default_point) +{ + defvalue = default_point; +} + +void +VectorParam::param_update_default(const gchar * default_point) +{ + gchar ** strarray = g_strsplit(default_point, ",", 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_update_default( Geom::Point(newx, newy) ); + } +} + bool VectorParam::param_readSVGValue(const gchar * strvalue) { diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index edee4ff4d..d270e9f43 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -51,7 +51,8 @@ public: void set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); void set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); void set_oncanvas_color(guint32 color); - + void param_update_default(Geom::Point default_point); + virtual void param_update_default(const gchar * default_point); virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); -- cgit v1.2.3 From a54924aece45764357c36d22d0475ef640b75ba1 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 29 Apr 2017 16:40:51 +0200 Subject: minor bugfixing (bzr r15620.1.13) --- src/live_effects/effect.cpp | 14 ++++++++------ src/live_effects/lpe-bspline.cpp | 2 +- src/live_effects/parameter/parameter.cpp | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 37694f32f..22cc5567b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -795,17 +795,15 @@ Effect::defaultParamSet() // use manage here, because after deletion of Effect object, others might still be pointing to this widget. Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox() ); - - vbox->set_border_width(5); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); - vbox_expander->set_border_width(10); - vbox_expander->set_spacing(2); Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(effectType()); Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(effectType()); std::vector::iterator it = param_vector.begin(); Inkscape::UI::Widget::Registry * wr; + bool has_params = false; while (it != param_vector.end()) { if ((*it)->widget_is_visible) { + has_params = true; Parameter * param = *it; Glib::ustring * tip = param->param_getTooltip(); const gchar * key = param->param_key.c_str(); @@ -843,13 +841,17 @@ Effect::defaultParamSet() } ++it; } - Glib::ustring tip = "" + effectname + (Glib::ustring)_(": Set default parameters to current values"); + Glib::ustring tip = "" + effectname + (Glib::ustring)_(": Set default parameters"); Gtk::Expander * expander = Gtk::manage(new Gtk::Expander(tip)); expander->set_use_markup(true); expander->add(*vbox_expander); expander->set_expanded(false); vbox->pack_start(*dynamic_cast (expander), true, true, 2); - return dynamic_cast(vbox); + if (has_params) { + return dynamic_cast(vbox); + } else { + return NULL; + } } void diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 1423e670a..5c227e68a 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -86,7 +86,7 @@ Gtk::Widget *LPEBSpline::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_homogeneous(false); vbox->set_border_width(5); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 15c81d543..e35c89c09 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -91,6 +91,7 @@ ScalarParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; os << value; + std::cout << value << "value\n"; gchar * str = g_strdup(os.str().c_str()); return str; } -- cgit v1.2.3 From a3d1689c18ebf132acb7ae0501ec419a71e48a85 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 1 May 2017 03:15:26 +0200 Subject: Fix erase lpe in multi LPE mode Improve rendering widgets, simplify the code, redraw widgets each time not only on odd iterations (bzr r15655) --- src/live_effects/effect.cpp | 2 -- src/live_effects/effect.h | 1 - src/live_effects/lpe-clone-original.cpp | 1 - src/live_effects/lpe-copy_rotate.cpp | 6 ------ src/live_effects/lpe-measure-line.cpp | 1 - src/live_effects/lpe-mirror_symmetry.cpp | 1 - src/live_effects/parameter/bool.cpp | 2 -- src/live_effects/parameter/fontbutton.cpp | 1 - src/live_effects/parameter/parameter.cpp | 6 ------ src/live_effects/parameter/point.cpp | 2 -- src/live_effects/parameter/text.cpp | 2 -- src/live_effects/parameter/togglebutton.cpp | 3 --- 12 files changed, 28 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index bfcca422e..326225e0c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -358,7 +358,6 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), - upd_params(true), sp_shape(NULL), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -773,7 +772,6 @@ Effect::newWidget() ++it; } - upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index f5e41d50e..973516133 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -133,7 +133,6 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE - bool upd_params; BoolParam is_visible; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 47fb6a04e..d97a990af 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -318,7 +318,6 @@ LPECloneOriginal::newWidget() expander->set_expanded(expanded); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPECloneOriginal::onExpanderChanged) ); vbox->pack_start(*expander, true, true, 2); - this->upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 4869e8279..900fc8b67 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -362,23 +362,19 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; original_bbox(lpeitem); if (copies_to_360 && num_copies > 2) { - this->upd_params = true; rotation_angle.param_set_value(360.0/(double)num_copies); } if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { - this->upd_params = true; num_copies.param_set_value(floor(360/rotation_angle)); } if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && mirror_copies && copies_to_360) { - this->upd_params = true; num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); rotation_angle.param_set_value(360.0/(double)num_copies); } } else { - this->upd_params = true; num_copies.param_set_increments(1.0, 10.0); } @@ -392,7 +388,6 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); if (!near) { - this->upd_params = true; starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); if (GDK_SHIFT_MASK) { dist_angle_handle = L2(B - A); @@ -407,7 +402,6 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); if (!near) { - this->upd_params = true; starting_point.param_setValue(start_pos, true); } previous_start_point = (Geom::Point)starting_point; diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 86d72615c..63d60da3f 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -527,7 +527,6 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) pathvector *= writed_transform; if ((Glib::ustring(format.param_getSVGValue()).empty())) { format.param_setValue(Glib::ustring("{measure}{unit}")); - this->upd_params = true; } size_t ncurves = pathvector.curveCount(); if (ncurves != (size_t)curve_linked.param_get_max()) { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 97015c34d..b411bd699 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -335,7 +335,6 @@ LPEMirrorSymmetry::newWidget() ++it; } - this->upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 813c06b4e..1bd5f96ad 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -72,7 +72,6 @@ BoolParam::param_newWidget() checkwdg->setActive(value); checkwdg->setProgrammatically = false; checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - param_effect->upd_params = false; return dynamic_cast (checkwdg); } else { return NULL; @@ -82,7 +81,6 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { - param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 64c203093..baf24d77c 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -66,7 +66,6 @@ FontButtonParam::param_newWidget() Glib::ustring fontspec = param_getSVGValue(); fontbuttonwdg->setValue( fontspec); fontbuttonwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font button parameter")); - param_effect->upd_params = false; return dynamic_cast (fontbuttonwdg); } diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index befac4df1..26a563909 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -110,7 +110,6 @@ ScalarParam::param_update_default(gdouble default_value) void ScalarParam::param_set_value(gdouble val) { - param_effect->upd_params = true; value = val; if (integer) value = round(value); @@ -128,7 +127,6 @@ ScalarParam::param_set_range(gdouble min, gdouble max) // Once again, in gtk2, this is not a problem. But in gtk3, // widgets get allocated the amount of size they ask for, // leading to excessively long widgets. - param_effect->upd_params = true; if (min >= -SCALARPARAM_G_MAXDOUBLE) { this->min = min; } else { @@ -145,7 +143,6 @@ ScalarParam::param_set_range(gdouble min, gdouble max) void ScalarParam::param_make_integer(bool yes) { - param_effect->upd_params = true; integer = yes; digits = 0; inc_step = 1; @@ -176,7 +173,6 @@ ScalarParam::param_newWidget() if(!overwrite_widget){ rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } - param_effect->upd_params = false; return dynamic_cast (rsu); } else { return NULL; @@ -186,14 +182,12 @@ ScalarParam::param_newWidget() void ScalarParam::param_set_digits(unsigned digits) { - param_effect->upd_params = true; this->digits = digits; } void ScalarParam::param_set_increments(double step, double page) { - param_effect->upd_params = true; inc_step = step; inc_page = page; } diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index db768090a..55dc79fe8 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -77,7 +77,6 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) if(knoth && liveupdate){ knoth->update_knots(); } - param_effect->upd_params = true; } bool @@ -130,7 +129,6 @@ PointParam::param_newWidget() Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); - param_effect->upd_params = false; return dynamic_cast (hbox); } diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 5c4cdf4c6..47fbd39af 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -125,14 +125,12 @@ TextParam::param_newWidget() rsu->setProgrammatically = false; rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - param_effect->upd_params = false; return dynamic_cast (rsu); } void TextParam::param_setValue(const Glib::ustring newvalue) { - param_effect->upd_params = true; value = newvalue; if (!_hide_canvas_text) { sp_canvastext_set_text (canvas_text, newvalue.c_str()); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index b3f6442bb..f7042b6d1 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -112,7 +112,6 @@ ToggleButtonParam::param_newWidget() checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); _toggled_connection = checkwdg->signal_toggled().connect(sigc::mem_fun(*this, &ToggleButtonParam::toggled)); - param_effect->upd_params = false; return checkwdg; } @@ -159,8 +158,6 @@ ToggleButtonParam::param_setValue(bool newvalue) void ToggleButtonParam::toggled() { - //Force redraw for update widgets - param_effect->upd_params = true; if (SP_ACTIVE_DESKTOP) { Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); selection->emitModified(); -- cgit v1.2.3 From 36dbe5ea8d5bcaba57339df7b0344ca91dce3dd9 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 1 May 2017 04:04:06 +0200 Subject: Remove couts (bzr r15620.1.16) --- src/live_effects/parameter/parameter.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 569736735..ccf8f37e7 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -91,7 +91,6 @@ ScalarParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; os << value; - std::cout << value << "value\n"; gchar * str = g_strdup(os.str().c_str()); return str; } -- cgit v1.2.3 From 561ec7df77bc2e499dc525d987a8be4552e9ea41 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 5 May 2017 16:41:34 +0200 Subject: Improve responsive from LPE Fixed bugs: - https://launchpad.net/bugs/1688168 (bzr r15662) --- src/live_effects/effect.cpp | 1 + src/live_effects/effect.h | 1 + src/live_effects/lpe-copy_rotate.cpp | 4 +-- src/live_effects/lpe-mirror_symmetry.cpp | 38 +++++++++++++-------------- src/live_effects/lpe-offset.cpp | 2 +- src/live_effects/lpe-perspective-envelope.cpp | 32 +++++++++++----------- src/live_effects/lpe-transform_2pts.cpp | 18 ++++++++++--- src/live_effects/parameter/bool.cpp | 1 + src/live_effects/parameter/enum.h | 1 + src/live_effects/parameter/fontbutton.cpp | 1 + src/live_effects/parameter/parameter.cpp | 2 ++ src/live_effects/parameter/point.cpp | 2 +- src/live_effects/parameter/togglebutton.cpp | 1 + src/live_effects/parameter/unit.cpp | 1 + 14 files changed, 62 insertions(+), 43 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 326225e0c..8df1aa927 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -358,6 +358,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), + upd_params(true), sp_shape(NULL), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 973516133..f5e41d50e 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -133,6 +133,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE + bool upd_params; BoolParam is_visible; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 900fc8b67..ffd2ef4cf 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -339,7 +339,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); - origin.param_setValue(A, true); + origin.param_setValue(A); origin.param_update_default(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); @@ -402,7 +402,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); if (!near) { - starting_point.param_setValue(start_pos, true); + starting_point.param_setValue(start_pos); } previous_start_point = (Geom::Point)starting_point; if ( method == RM_FUSE || copies_to_360 ) { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index b411bd699..4e93a2572 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -126,61 +126,61 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } if ((Geom::Point)start_point == (Geom::Point)end_point) { - start_point.param_setValue(point_a, true); - end_point.param_setValue(point_b, true); + start_point.param_setValue(point_a); + end_point.param_setValue(point_b); previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - center_point.param_setValue(previous_center, true); + center_point.param_setValue(previous_center); return; } if ( mode == MT_X || mode == MT_Y ) { if (!are_near(previous_center, (Geom::Point)center_point, 0.01)) { center_point.param_setValue(Geom::middle_point(point_a, point_b), true); - end_point.param_setValue(point_b, true); - start_point.param_setValue(point_a, true); + end_point.param_setValue(point_b); + start_point.param_setValue(point_a); } else { if ( mode == MT_X ) { if (!are_near(start_point[X], point_a[X], 0.01)) { - start_point.param_setValue(point_a, true); + start_point.param_setValue(point_a); } if (!are_near(end_point[X], point_b[X], 0.01)) { - end_point.param_setValue(point_b, true); + end_point.param_setValue(point_b); } } else { //MT_Y if (!are_near(start_point[Y], point_a[Y], 0.01)) { - start_point.param_setValue(point_a, true); + start_point.param_setValue(point_a); } if (!are_near(end_point[Y], point_b[Y], 0.01)) { - end_point.param_setValue(point_b, true); + end_point.param_setValue(point_b); } } } } else if ( mode == MT_FREE) { if (are_near(previous_center, (Geom::Point)center_point, 0.01)) { - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point)); } else { Geom::Point trans = center_point - Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); - start_point.param_setValue(start_point * trans, true); - end_point.param_setValue(end_point * trans, true); + start_point.param_setValue(start_point * trans); + end_point.param_setValue(end_point * trans); } } else if ( mode == MT_V){ SPDocument * document = SP_ACTIVE_DOCUMENT; if (document) { Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); Geom::Point sp = Geom::Point(document->getWidth().value("px")/2.0, 0) * transform; - start_point.param_setValue(sp, true); + start_point.param_setValue(sp); Geom::Point ep = Geom::Point(document->getWidth().value("px")/2.0, document->getHeight().value("px")) * transform; - end_point.param_setValue(ep, true); - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + end_point.param_setValue(ep); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point)); } } else { //horizontal page SPDocument * document = SP_ACTIVE_DOCUMENT; if (document) { Geom::Affine transform = i2anc_affine(SP_OBJECT(lpeitem), NULL).inverse(); Geom::Point sp = Geom::Point(0, document->getHeight().value("px")/2.0) * transform; - start_point.param_setValue(sp, true); + start_point.param_setValue(sp); Geom::Point ep = Geom::Point(document->getWidth().value("px"), document->getHeight().value("px")/2.0) * transform; - end_point.param_setValue(ep, true); - center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point), true); + end_point.param_setValue(ep); + center_point.param_setValue(Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point)); } } previous_center = center_point; @@ -381,7 +381,7 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) start_point.param_update_default(point_a); end_point.param_setValue(point_b); end_point.param_update_default(point_b); - center_point.param_setValue(point_c, true); + center_point.param_setValue(point_c); previous_center = center_point; SPLPEItem * splpeitem = const_cast(lpeitem); if (!lpeitem->hasPathEffectOfType(this->effectType(), false) ){ //first applied not ready yet diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index c853e4afa..a5d1d23c8 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -39,7 +39,7 @@ LPEOffset::doOnApply(SPLPEItem const* lpeitem) { Geom::Point offset = *(SP_SHAPE(lpeitem)->_curve->first_point()); offset_pt.param_update_default(offset); - offset_pt.param_setValue(offset,true); + offset_pt.param_setValue(offset); } static void append_half_circle(Geom::Piecewise > &pwd2, diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 365ff5389..3cff83fed 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -110,15 +110,15 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) int position_c = Geom::sgn(Geom::cross(handles[2] - handles[3], handles[0] - handles[3])); if (position_a != 1 && move0) { Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[0])); - down_left_point.param_setValue(point_a, true); + down_left_point.param_setValue(point_a); } if (position_b == 1 && move0) { Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[0])); - down_left_point.param_setValue(point_b, true); + down_left_point.param_setValue(point_b); } if (position_c == 1 && move0) { Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[0])); - down_left_point.param_setValue(point_c, true); + down_left_point.param_setValue(point_c); } line_a.setPoints(handles[0],handles[2]); line_b.setPoints(handles[2],handles[3]); @@ -128,15 +128,15 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) position_c = Geom::sgn(Geom::cross(handles[3] - handles[0], handles[1] - handles[0])); if (position_a != 1 && move1) { Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[1])); - up_left_point.param_setValue(point_a, true); + up_left_point.param_setValue(point_a); } if (position_b == 1 && move1) { Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[1])); - up_left_point.param_setValue(point_b, true); + up_left_point.param_setValue(point_b); } if (position_c == 1 && move1) { Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[1])); - up_left_point.param_setValue(point_c, true); + up_left_point.param_setValue(point_c); } line_a.setPoints(handles[1],handles[3]); line_b.setPoints(handles[3],handles[0]); @@ -146,15 +146,15 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) position_c = Geom::sgn(Geom::cross(handles[0] - handles[1], handles[2] - handles[1])); if (position_a != 1 && move2) { Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[2])); - up_right_point.param_setValue(point_a, true); + up_right_point.param_setValue(point_a); } if (position_b == 1 && move2) { Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[2])); - up_right_point.param_setValue(point_b, true); + up_right_point.param_setValue(point_b); } if (position_c == 1 && move2) { Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[2])); - up_right_point.param_setValue(point_c, true); + up_right_point.param_setValue(point_c); } line_a.setPoints(handles[2],handles[0]); line_b.setPoints(handles[0],handles[1]); @@ -164,15 +164,15 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) position_c = Geom::sgn(Geom::cross(handles[1] - handles[2], handles[3] - handles[2])); if (position_a != 1 && move3) { Geom::Point point_a = line_a.pointAt(line_a.nearestTime(handles[3])); - down_right_point.param_setValue(point_a, true); + down_right_point.param_setValue(point_a); } if (position_b == 1 && move3) { Geom::Point point_b = line_b.pointAt(line_b.nearestTime(handles[3])); - down_right_point.param_setValue(point_b, true); + down_right_point.param_setValue(point_b); } if (position_c == 1 && move3) { Geom::Point point_c = line_c.pointAt(line_c.nearestTime(handles[3])); - down_right_point.param_setValue(point_c, true); + down_right_point.param_setValue(point_c); } } else { handles.resize(4); @@ -434,8 +434,8 @@ LPEPerspectiveEnvelope::vertical(PointParam ¶m_one, PointParam ¶m_two, G } A[Geom::X] = nearest[Geom::X] - distance_middle; B[Geom::X] = nearest[Geom::X] + distance_middle; - param_one.param_setValue(A, true); - param_two.param_setValue(B, true); + param_one.param_setValue(A); + param_two.param_setValue(B); } void @@ -455,8 +455,8 @@ LPEPerspectiveEnvelope::horizontal(PointParam ¶m_one, PointParam ¶m_two, } A[Geom::Y] = nearest[Geom::Y] - distance_middle; B[Geom::Y] = nearest[Geom::Y] + distance_middle; - param_one.param_setValue(A, true); - param_two.param_setValue(B, true); + param_one.param_setValue(A); + param_two.param_setValue(B); } void diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index ef2900775..f4d233d56 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -138,14 +138,22 @@ LPETransform2Pts::doBeforeEffect (SPLPEItem const* lpeitem) size_t nnodes = nodeCount(pathvector); first_knot.param_set_range(1, last_knot-1); last_knot.param_set_range(first_knot+1, nnodes); - from_original_width.param_setValue(false); + if (from_original_width){ + from_original_width.param_setValue(false); + } } else { - first_knot.param_set_value(1); - last_knot.param_set_value(2); + if (first_knot != 1){ + first_knot.param_set_value(1); + } + if (last_knot != 2){ + last_knot.param_set_value(2); + } first_knot.param_set_range(1,1); last_knot.param_set_range(2,2); - from_original_width.param_setValue(true); append_path = false; + if (!from_original_width){ + from_original_width.param_setValue(true); + } } if(lock_lenght && !lock_angle && previous_lenght != -1) { Geom::Ray transformed((Geom::Point)start,(Geom::Point)end); @@ -251,6 +259,8 @@ LPETransform2Pts::reset() first_knot.param_set_value(1); last_knot.param_set_value(2); } + offset.param_set_value(0.0); + stretch.param_set_value(1.0); Geom::Ray transformed(point_a, point_b); previous_angle = transformed.angle(); previous_lenght = Geom::distance(point_a, point_b); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 1bd5f96ad..0a1647623 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -81,6 +81,7 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { + param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index dbfc68623..05ac393c1 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -78,6 +78,7 @@ public: } void param_set_value(E val) { + param_effect->upd_params = true; value = val; } diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index baf24d77c..31534fba0 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -72,6 +72,7 @@ FontButtonParam::param_newWidget() void FontButtonParam::param_setValue(const Glib::ustring newvalue) { + param_effect->upd_params = true; value = newvalue; } diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 26a563909..256ebf322 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -39,6 +39,7 @@ Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, void Parameter::param_write_to_repr(const char * svgd) { + param_effect->upd_params = true; param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); } @@ -110,6 +111,7 @@ ScalarParam::param_update_default(gdouble default_value) void ScalarParam::param_set_value(gdouble val) { + param_effect->upd_params = true; value = val; if (integer) value = round(value); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 55dc79fe8..e5216bf2d 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -168,7 +168,7 @@ PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &or s = A; } } - pparam->param_setValue(s, this->pparam->liveupdate); + pparam->param_setValue(s); SPLPEItem * splpeitem = dynamic_cast(item); if(splpeitem && this->pparam->liveupdate){ sp_lpe_item_update_patheffect(splpeitem, false, false); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index f7042b6d1..dd9ea6fb2 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -152,6 +152,7 @@ ToggleButtonParam::refresh_button() void ToggleButtonParam::param_setValue(bool newvalue) { + param_effect->upd_params = true; value = newvalue; refresh_button(); } diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index b6ea99bfe..df0307f97 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -63,6 +63,7 @@ UnitParam::param_update_default(const Glib::ustring default_unit) void UnitParam::param_set_value(Inkscape::Util::Unit const &val) { + param_effect->upd_params = true; unit = new Inkscape::Util::Unit(val); } -- cgit v1.2.3 From 79778c1b0a01926c1f43065525ef55a55e11587c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 01:11:06 +0200 Subject: LPE widget refactor. Improvement to not update on same value (bzr r15665) --- src/live_effects/parameter/bool.cpp | 4 +++- src/live_effects/parameter/enum.h | 4 +++- src/live_effects/parameter/fontbutton.cpp | 4 +++- src/live_effects/parameter/parameter.cpp | 4 +++- src/live_effects/parameter/random.cpp | 1 + src/live_effects/parameter/text.cpp | 3 +++ src/live_effects/parameter/togglebutton.cpp | 4 +++- 7 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 9cb91bdd6..3184bfa80 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -87,7 +87,9 @@ BoolParam::param_newWidget() void BoolParam::param_setValue(bool newvalue) { - param_effect->upd_params = true; + if (value != newvalue) { + param_effect->upd_params = true; + } value = newvalue; } diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 6cadd6953..78fa87a4f 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -86,7 +86,9 @@ public: } void param_set_value(E val) { - param_effect->upd_params = true; + if (value != val) { + param_effect->upd_params = true; + } value = val; } diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 5add69c1d..ca8908f0e 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -74,7 +74,9 @@ FontButtonParam::param_newWidget() void FontButtonParam::param_setValue(const Glib::ustring newvalue) { - param_effect->upd_params = true; + if (value != newvalue) { + param_effect->upd_params = true; + } value = newvalue; } diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 1c1063960..45f46a0a7 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -121,7 +121,9 @@ ScalarParam::param_update_default(const gchar * default_value) void ScalarParam::param_set_value(gdouble val) { - param_effect->upd_params = true; + if (value != val) { + param_effect->upd_params = true; + } value = val; if (integer) value = round(value); diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 90e53ca0e..b1375adda 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -94,6 +94,7 @@ RandomParam::param_update_default(const gchar * default_value){ void RandomParam::param_set_value(gdouble val, long newseed) { + param_effect->upd_params = true; value = val; if (integer) value = round(value); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 4062a4dc7..d633666aa 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -131,6 +131,9 @@ TextParam::param_newWidget() void TextParam::param_setValue(const Glib::ustring newvalue) { + if (value != newvalue) { + param_effect->upd_params = true; + } value = newvalue; if (!_hide_canvas_text) { sp_canvastext_set_text (canvas_text, newvalue.c_str()); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 9eb89fea5..eb40a7e41 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -164,7 +164,9 @@ ToggleButtonParam::refresh_button() void ToggleButtonParam::param_setValue(bool newvalue) { - param_effect->upd_params = true; + if (value != newvalue) { + param_effect->upd_params = true; + } value = newvalue; refresh_button(); } -- cgit v1.2.3 From 575d7a8f668987ea8395643a2c89a848ba527483 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 02:27:58 +0200 Subject: Updating code to trunk (bzr r13645.1.176) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b9e96cb72..abb6fa9d2 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -305,7 +305,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - std::vector selected_nodes_index; size_t index = 0; for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { -- cgit v1.2.3 From 5004996c798cdbad5ff7abbaf2e7272411631cee Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 19:45:16 +0200 Subject: Pre merge fixing (bzr r13645.1.177) --- src/live_effects/lpe-fillet-chamfer.cpp | 56 ++++++++++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 3 +- src/live_effects/parameter/satellitesarray.cpp | 15 ++++--- src/live_effects/parameter/satellitesarray.h | 2 +- 4 files changed, 48 insertions(+), 28 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index abb6fa9d2..e968a7822 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -234,7 +234,15 @@ void LPEFilletChamfer::refreshKnots() void LPEFilletChamfer::updateAmount() { - _pathvector_satellites->updateAmount(radius, apply_no_radius, apply_with_radius, only_selected, + setSelected(_pathvector_satellites); + double power = radius; + if (!flexible) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + SPNamedView *nv = sp_document_namedview(document, NULL); + Glib::ustring display_unit = nv->display_units->abbr; + power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), display_unit.c_str()); + } + _pathvector_satellites->updateAmount(power, apply_no_radius, apply_with_radius, only_selected, use_knot_distance, flexible); satellites_param.setPathVectorSatellites(_pathvector_satellites); } @@ -250,34 +258,45 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { + setSelected(_pathvector_satellites); _pathvector_satellites->updateSteps(chamfer_steps, apply_no_radius, apply_with_radius, only_selected); satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { + setSelected(_pathvector_satellites); _pathvector_satellites->updateSatelliteType(satellitetype, apply_no_radius, apply_with_radius, only_selected); satellites_param.setPathVectorSatellites(_pathvector_satellites); } +void LPEFilletChamfer::setSelected(PathVectorSatellites *_pathvector_satellites){ + Geom::PathVector const pathv = _pathvector_satellites->getPathVector(); + Satellites satellites = _pathvector_satellites->getSatellites(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + Geom::Curve const &curve_in = pathv[i][j]; + if (only_selected && isNodePointSelected(curve_in.initialPoint()) ){ + satellites[i][j].setSelected(true); + } else { + satellites[i][j].setSelected(false); + } + } + } + _pathvector_satellites->setSatellites(satellites); +} + void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - SPLPEItem *splpeitem = const_cast(lpeItem); - SPShape *shape = dynamic_cast(splpeitem); - if (shape) { - SPCurve *c = shape->getCurve(); - SPPath *path = dynamic_cast(shape); - if (path) { - c = path->get_original_curve(); - } + if (sp_curve) { //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); satellites_param.setCurrentZoom(current_zoom); //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - //if are diferent sizes call to poinwise recalculate - //TODO: Update the satellite data in paths modified, Goal 0.93 + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(sp_curve->get_pathvector()); + //if are diferent sizes call to recalculate + //TODO: Update the satellite data in paths modified, Satellites satellites = satellites_param.data(); if (satellites.empty()) { doOnApply(lpeItem); @@ -305,16 +324,15 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - size_t index = 0; for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { + Geom::Curve const &curve_in = pathv[i][j]; if (satellites[i][j].is_time != flexible) { satellites[i][j].is_time = flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j) { continue; } - Geom::Curve const &curve_in = pathv[i][j]; if (satellites[i][j].is_time) { double time = timeAtArcLength(amount, curve_in); satellites[i][j].amount = time; @@ -327,11 +345,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].has_mirror = mirror_knots; } satellites[i][j].hidden = hide_knots; - Geom::Curve const &curve_in = pathv[i][j]; if (only_selected && isNodePointSelected(curve_in.initialPoint()) ){ - selected_nodes_index.push_back(index); + satellites[i][j].setSelected(true); } - index ++; } } if (!_pathvector_satellites) { @@ -339,10 +355,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - if (only_selected) { - _pathvector_satellites->setSelected(selected_nodes_index); - } - satellites_param.setPathVectorSatellites(_pathvector_satellites); + satellites_param.setPathVectorSatellites(_pathvector_satellites, false); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -358,6 +371,7 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< void LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps) { + setSelected(_pathvector_satellites); double path_subdivision = 1.0 / steps; for (size_t i = 1; i < steps; i++) { Geom::Point chamfer_step = path_chamfer.pointAt(path_subdivision * i); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 2cee04a1e..7f5dd7d4c 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,7 +40,8 @@ public: void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); - //void convertUnit(); + void setSelected(PathVectorSatellites *_pathvector_satellites); + //void convertUnit(); void updateChamferSteps(); void updateAmount(); void refreshKnots(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index c7bc7f026..7626317a1 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -39,6 +39,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _last_pathvector_satellites = NULL; } + void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) @@ -48,10 +49,14 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites, bool write) { _last_pathvector_satellites = pathVectorSatellites; - param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); + if (write) { + param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); + } else { + param_setValue(_last_pathvector_satellites->getSatellites()); + } } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -226,6 +231,9 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { + if (!_last_pathvector_satellites) { + return; + } Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); size_t index = 0; for (size_t i = 0; i < _vector.size(); ++i) { @@ -442,7 +450,6 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector[path_index][curve_index].amount = 0.0; - _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; @@ -462,7 +469,6 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) break; } _pparam->_vector[path_index][curve_index].satellite_type = type; - _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; if (type == CHAMFER) { @@ -555,7 +561,6 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) satellite.amount = amount; _pparam->_vector[path_index][curve_index] = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index edaf2f08d..5ae372ac2 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,7 +55,7 @@ public: void setCurrentZoom(double current_zoom); void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); + void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites, bool write = true); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; -- cgit v1.2.3 From 557ec6397498df157e0fd08561bede35606c7baf Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 21:00:24 +0200 Subject: Fix a compiling bug found by Ede_123 on IRC (bzr r15667) --- src/live_effects/parameter/array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 10a3ea018..e65d3b55c 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -130,7 +130,7 @@ protected: str << ","; str << vector_data[i].angle; str << ","; - str << vector_data[i].steps; + str << static_cast(vector_data[i].steps); } } -- cgit v1.2.3 From 5b4c7fc7fbd532673473fd47b781bfc740cc5a07 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 23:00:45 +0200 Subject: Add improvement pointed in IRC by Ede_123 to allow defaultables parametes on fillet chamfer (bzr r15668) --- src/live_effects/CMakeLists.txt | 2 ++ src/live_effects/lpe-fillet-chamfer.cpp | 54 +++++++++++++++++++++++++++++++-- src/live_effects/lpe-fillet-chamfer.h | 2 ++ 3 files changed, 55 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index f67c43db0..c2f434f50 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -59,6 +59,7 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp + parameter/hidden.cpp parameter/item-reference.cpp parameter/item.cpp parameter/originalitem.cpp @@ -143,6 +144,7 @@ set(live_effects_SRC parameter/array.h parameter/bool.h + parameter/hidden.h parameter/enum.h parameter/item.h parameter/item-reference.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index e968a7822..08ceab3c3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -37,6 +37,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "satellites_param", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), + mode(_("Mode:"), _("Mode, fillet or chamfer"), + "mode", &wr, this, "F"), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", @@ -63,6 +65,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&satellites_param); registerParameter(&unit); registerParameter(&method); + registerParameter(&mode); registerParameter(&radius); registerParameter(&chamfer_steps); registerParameter(&helper_size); @@ -94,6 +97,22 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (shape) { Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Satellites satellites; + double power = radius; + std::cout << power << "power\n"; + if (!flexible) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + SPNamedView *nv = sp_document_namedview(document, NULL); + Glib::ustring display_unit = nv->display_units->abbr; + power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), display_unit.c_str()); + } + std::cout << power << "power22222222\n"; + SatelliteType satellite_type = FILLET; + std::map gchar_map_to_satellite_type = + boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); + std::map::iterator it = gchar_map_to_satellite_type.find(std::string(mode.param_getSVGValue())); + if (it != gchar_map_to_satellite_type.end()) { + satellite_type = it->second; + } for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -104,8 +123,12 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) //if (curve_it->isDegenerate()) { // continue //} - Satellite satellite(FILLET); + Satellite satellite(satellite_type); satellite.setSteps(chamfer_steps); + satellite.setAmount(power); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); subpath_satellites.push_back(satellite); } //we add the last satellite on open path because _pathvector_satellites is related to nodes, not curves @@ -113,8 +136,12 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) //dont remove for this effect because _pathvector_satellites class has methods when the path is modiffied //and we want one method for all uses if (!path_it->closed()) { - Satellite satellite(FILLET); + Satellite satellite(satellite_type); satellite.setSteps(chamfer_steps); + satellite.setAmount(power); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); subpath_satellites.push_back(satellite); } satellites.push_back(subpath_satellites); @@ -265,6 +292,9 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { + std::map satellite_type_to_gchar_map = + boost::assign::map_list_of(FILLET, "F")(INVERSE_FILLET, "IF")(CHAMFER, "C")(INVERSE_CHAMFER, "IC")(INVALID_SATELLITE, "KO"); + mode.param_setValue((Glib::ustring)satellite_type_to_gchar_map.at(satellitetype)); setSelected(_pathvector_satellites); _pathvector_satellites->updateSatelliteType(satellitetype, apply_no_radius, apply_with_radius, only_selected); satellites_param.setPathVectorSatellites(_pathvector_satellites); @@ -306,7 +336,25 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector_satellites->getTotalSatellites(); if (number_nodes != previous_number_nodes) { - Satellite satellite(FILLET); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(sp_curve->get_pathvector()); + Satellites satellites; + double power = radius; + if (!flexible) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + SPNamedView *nv = sp_document_namedview(document, NULL); + Glib::ustring display_unit = nv->display_units->abbr; + power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), display_unit.c_str()); + } + SatelliteType satellite_type = FILLET; + std::map gchar_map_to_satellite_type = + boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); + std::map::iterator it = gchar_map_to_satellite_type.find(std::string(mode.param_getSVGValue())); + if (it != gchar_map_to_satellite_type.end()) { + satellite_type = it->second; + } + Satellite satellite(satellite_type); + satellite.setSteps(chamfer_steps); + satellite.setAmount(power); satellite.setIsTime(flexible); satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 7f5dd7d4c..c628added 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -16,6 +16,7 @@ #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "live_effects/parameter/unit.h" +#include "live_effects/parameter/hidden.h" #include "helper/geom-pathvectorsatellites.h" #include "helper/geom-satellite.h" @@ -54,6 +55,7 @@ private: ScalarParam radius; ScalarParam chamfer_steps; BoolParam flexible; + HiddenParam mode; BoolParam mirror_knots; BoolParam only_selected; BoolParam use_knot_distance; -- cgit v1.2.3 From 8c9030f8eb348b09b0111247522a0c5e2aed6ce8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 23:01:40 +0200 Subject: Add missing files (bzr r15669) --- src/live_effects/parameter/hidden.cpp | 86 +++++++++++++++++++++++++++++++++++ src/live_effects/parameter/hidden.h | 68 +++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/live_effects/parameter/hidden.cpp create mode 100644 src/live_effects/parameter/hidden.h (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/hidden.cpp b/src/live_effects/parameter/hidden.cpp new file mode 100644 index 000000000..2f218847a --- /dev/null +++ b/src/live_effects/parameter/hidden.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) jabiertxof 2017 + * Copyright (C) Maximilian Albert 2008 + * + * Authors: + * Jabiertxof + * Maximilian Albert + * Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "live_effects/parameter/hidden.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" + +namespace Inkscape { + +namespace LivePathEffect { + +HiddenParam::HiddenParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +HiddenParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +HiddenParam::param_update_default(const gchar * default_value) +{ + defvalue = (Glib::ustring)default_value; +} + + +bool +HiddenParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +HiddenParam::param_getSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << value; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +Gtk::Widget * +HiddenParam::param_newWidget() +{ + return NULL; +} + +void +HiddenParam::param_setValue(const Glib::ustring 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/hidden.h b/src/live_effects/parameter/hidden.h new file mode 100644 index 000000000..d565272b6 --- /dev/null +++ b/src/live_effects/parameter/hidden.h @@ -0,0 +1,68 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_HIDDEN_H +#define INKSCAPE_LIVEPATHEFFECT_HIDDEN_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Jabiertxof + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) jabiertxof 2017 + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/parameter.h" + + +namespace Inkscape { + +namespace LivePathEffect { + +class HiddenParam : public Parameter { +public: + HiddenParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~HiddenParam() {} + + virtual Gtk::Widget * param_newWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(Glib::ustring newvalue); + virtual void param_set_default(); + virtual void param_update_default(const gchar * default_value); + + const Glib::ustring get_value() const { return value; }; + +private: + HiddenParam(const HiddenParam&); + HiddenParam& operator=(const HiddenParam&); + Glib::ustring value; + Glib::ustring defvalue; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + 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 : -- cgit v1.2.3 From ae91bcdbb542c5e7233b0d33f8aba42439408587 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 7 May 2017 02:23:42 +0200 Subject: Reorder LPE enum to match definition in effect.cpp. also fix a bug pointed by Ede_123 in IRC, LPE dialog show bad default selected LPE (bzr r15670) --- src/live_effects/effect-enum.h | 72 ++++++++++++++++++++---------------------- src/live_effects/effect.cpp | 37 +++++++++++----------- 2 files changed, 54 insertions(+), 55 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index 3682aa1bd..a6920c1fb 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -16,57 +16,55 @@ namespace LivePathEffect { enum EffectType { BEND_PATH = 0, + GEARS, PATTERN_ALONG_PATH, - FREEHAND_SHAPE, - SKETCH, - ROUGH_HATCHES, + CURVE_STITCH, VONKOCH, KNOT, - GEARS, - CURVE_STITCH, - CIRCLE_WITH_RADIUS, - PERSPECTIVE_PATH, + CONSTRUCT_GRID, SPIRO, - LATTICE, - LATTICE2, - ROUGHEN, - SHOW_HANDLES, - SIMPLIFY, ENVELOPE, - CONSTRUCT_GRID, - PERP_BISECTOR, - TANGENT_TO_CURVE, - MEASURE_LINE, - MIRROR_SYMMETRY, - CIRCLE_3PTS, - TRANSFORM_2PTS, - ANGLE_BISECTOR, - PARALLEL, - COPY_ROTATE, - OFFSET, - RULER, - BOOLOPS, INTERPOLATE, - INTERPOLATE_POINTS, - TEXT_LABEL, - PATH_LENGTH, - LINE_SEGMENT, - DOEFFECTSTACK_TEST, - BSPLINE, - DYNASTROKE, - RECURSIVE_SKELETON, - EXTRUDE, + ROUGH_HATCHES, + SKETCH, + RULER, POWERSTROKE, CLONE_ORIGINAL, + SIMPLIFY, + LATTICE2, + PERSPECTIVE_ENVELOPE, + INTERPOLATE_POINTS, + TRANSFORM_2PTS, + SHOW_HANDLES, + ROUGHEN, + BSPLINE, + JOIN_TYPE, + TAPER_STROKE, + MIRROR_SYMMETRY, + COPY_ROTATE, ATTACH_PATH, FILL_BETWEEN_STROKES, FILL_BETWEEN_MANY, ELLIPSE_5PTS, BOUNDING_BOX, - JOIN_TYPE, - TAPER_STROKE, - PERSPECTIVE_ENVELOPE, + MEASURE_LINE, FILLET_CHAMFER, + DOEFFECTSTACK_TEST, + ANGLE_BISECTOR, + CIRCLE_WITH_RADIUS, + CIRCLE_3PTS, + DYNASTROKE, + EXTRUDE, + LATTICE, + LINE_SEGMENT, + OFFSET, + PARALLEL, + PATH_LENGTH, + PERP_BISECTOR, + PERSPECTIVE_PATH, + RECURSIVE_SKELETON, + TANGENT_TO_CURVE, + TEXT_LABEL, INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) }; diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 467a65c7c..6ab50b1c0 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -84,24 +84,6 @@ namespace LivePathEffect { const Util::EnumData LPETypeData[] = { // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} -#ifdef LPE_ENABLE_TEST_EFFECTS - {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, - {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, - {CIRCLE_WITH_RADIUS, N_("Circle (by center and radius)"), "circle_with_radius"}, - {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, - {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, - {EXTRUDE, N_("Extrude"), "extrude"}, - {LATTICE, N_("Lattice Deformation"), "lattice"}, - {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, - {OFFSET, N_("Offset"), "offset"}, - {PARALLEL, N_("Parallel"), "parallel"}, - {PATH_LENGTH, N_("Path length"), "path_length"}, - {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, - {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, - {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, - {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, - {TEXT_LABEL, N_("Text label"), "text_label"}, -#endif /* 0.46 */ {BEND_PATH, N_("Bend"), "bend_path"}, {GEARS, N_("Gears"), "gears"}, @@ -142,6 +124,25 @@ const Util::EnumData LPETypeData[] = { /* 9.93 */ {MEASURE_LINE, N_("Measure Line"), "measure_line"}, {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, +#ifdef LPE_ENABLE_TEST_EFFECTS + {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, + {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, + {CIRCLE_WITH_RADIUS, N_("Circle (by center and radius)"), "circle_with_radius"}, + {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, + {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, + {EXTRUDE, N_("Extrude"), "extrude"}, + {LATTICE, N_("Lattice Deformation"), "lattice"}, + {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, + {OFFSET, N_("Offset"), "offset"}, + {PARALLEL, N_("Parallel"), "parallel"}, + {PATH_LENGTH, N_("Path length"), "path_length"}, + {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, + {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, + {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, + {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, + {TEXT_LABEL, N_("Text label"), "text_label"}, +#endif + }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); -- cgit v1.2.3 From 48a1d89571b6da9fe574bcc49f8692b693d6fbf8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 7 May 2017 02:37:49 +0200 Subject: Improvement to store default line width on join type and tapper stroke pointed by Ede_123 on IRC (bzr r15671) --- src/live_effects/lpe-jointype.cpp | 11 +++++++++-- src/live_effects/lpe-taperstroke.cpp | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index dacb87dd9..0e1e46a94 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -83,6 +83,7 @@ LPEJoinType::~LPEJoinType() void LPEJoinType::doOnApply(SPLPEItem const* lpeitem) { if (SP_IS_SHAPE(lpeitem)) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPLPEItem* item = const_cast(lpeitem); double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed : 1.; @@ -109,8 +110,14 @@ void LPEJoinType::doOnApply(SPLPEItem const* lpeitem) sp_desktop_apply_css_recursive(item, css, true); sp_repr_css_attr_unref (css); - - line_width.param_set_value(width); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)"line_width"; + bool valid = prefs->getEntry(pref_path).isValid(); + if(!valid){ + line_width.param_set_value(width); + } line_width.write_to_SVG(); } } diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f4a81aa90..a40a40146 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -91,6 +91,7 @@ LPETaperStroke::LPETaperStroke(LivePathEffectObject *lpeobject) : void LPETaperStroke::doOnApply(SPLPEItem const* lpeitem) { if (SP_IS_SHAPE(lpeitem)) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPLPEItem* item = const_cast(lpeitem); double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed : 1.; @@ -117,8 +118,14 @@ void LPETaperStroke::doOnApply(SPLPEItem const* lpeitem) sp_desktop_apply_css_recursive(item, css, true); sp_repr_css_attr_unref (css); - - line_width.param_set_value(width); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)"stroke_width"; + bool valid = prefs->getEntry(pref_path).isValid(); + if(!valid){ + line_width.param_set_value(width); + } line_width.write_to_SVG(); } else { printf("WARNING: It only makes sense to apply Taper stroke to paths (not groups).\n"); -- cgit v1.2.3 From d3deb9184f7044f930133f37654e52bc24272616 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 7 May 2017 19:16:47 +0200 Subject: Fix a bug on tapper stroke detected with Ede_123 on IRC (bzr r15673) --- src/live_effects/effect.cpp | 15 +++------------ src/live_effects/effect.h | 1 + src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- src/live_effects/lpe-taperstroke.cpp | 1 - 5 files changed, 6 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 6ab50b1c0..aa8987185 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -492,7 +492,7 @@ Effect::processObjects(LpeAction lpe_action) void Effect::setCurrentShape(SPShape * shape){ if(shape){ sp_shape = shape; - if (!(sp_curve = sp_shape->getCurve())) { + if (!(sp_curve = sp_shape->getCurveBeforeLPE())) { // oops return; } @@ -523,25 +523,16 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector(); SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - setCurrentShape(shape); - } + setCurrentShape(shape); doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - setCurrentShape(shape); - sp_curve = shape->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector(); - } + setCurrentShape(shape); doBeforeEffect(lpeitem); if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index c34c391c0..60ee8d98f 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -137,6 +137,7 @@ public: BoolParam is_visible; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; + Geom::PathVector pathvector_after_effect; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index ffd2ef4cf..b54368b4e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -199,7 +199,7 @@ LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) SPCurve *c = NULL; if (root) { c = new SPCurve(); - c->set_pathvector(pathvector_before_effect); + c->set_pathvector(pathvector_after_effect); } else { c = shape->getCurve(); } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 4e93a2572..186b97fe3 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -216,7 +216,7 @@ LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root SPCurve *c = NULL; if (root) { c = new SPCurve(); - c->set_pathvector(pathvector_before_effect); + c->set_pathvector(pathvector_after_effect); } else { c = shape->getCurve(); } diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index a40a40146..45394ae91 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -477,7 +477,6 @@ void KnotHolderEntityAttachBegin::knot_set(Geom::Point const &p, Geom::Point con // use that object. Geom::PathVector pathv = lpe->pathvector_before_effect; - Piecewise > pwd2; Geom::Path p_in = return_at_first_cusp(pathv[0]); pwd2.concat(p_in.toPwSb()); -- cgit v1.2.3 From f9d2f22497a59cc551a43f3c669ef02263d99a3b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 12 May 2017 19:09:47 +0200 Subject: Fix a bug pointed by suv in IRC about simple mode of rotate copies with origin position (bzr r15689) --- src/live_effects/lpe-copy_rotate.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index b54368b4e..f8be0f2a5 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -365,7 +365,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) rotation_angle.param_set_value(360.0/(double)num_copies); } - if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { + if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0 && copies_to_360) { num_copies.param_set_value(floor(360/rotation_angle)); } if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && mirror_copies && copies_to_360) { @@ -657,6 +657,10 @@ LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) } } } else { + t = pre * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + if(mirror_copies && i%2 != 0) { + t = pre * Geom::Rotate(Geom::rad_from_deg(-starting_angle-rotation_angle)) * r * rot * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } output_pv = path_in * t; output.insert(output.end(), output_pv.begin(), output_pv.end()); } -- cgit v1.2.3 From 6c05c1c14cb8d29fb06d6779ec9817615c518ab5 Mon Sep 17 00:00:00 2001 From: chr Date: Thu, 18 May 2017 19:58:59 +0200 Subject: fix a brunch of memory leaks (bzr r15698.1.2) --- src/live_effects/lpe-bspline.cpp | 1 + src/live_effects/parameter/path.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 5c227e68a..dbd67beda 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -168,6 +168,7 @@ void LPEBSpline::changeWeight(double weight_ammount) doBSplineFromWidget(curve, weight_ammount/100.0); gchar *str = sp_svg_write_path(curve->get_pathvector()); path->getRepr()->setAttribute("inkscape:original-d", str); + g_free(str); } } diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index aa87508ab..6e90c9279 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -245,8 +245,9 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) r.lpe_key = param_key; Geom::PathVector stored_pv = _pathvector; param_write_to_repr("M0,0 L1,0"); - const char *svgd = sp_svg_write_path(stored_pv); + gchar *svgd = sp_svg_write_path(stored_pv); param_write_to_repr(svgd); + g_free(svgd); } else { r.item = ref.getObject(); } -- cgit v1.2.3 From 71f7e26f4a6714fe1d3b6a72f61c481c3e1f52a0 Mon Sep 17 00:00:00 2001 From: chr Date: Tue, 23 May 2017 21:48:27 +0200 Subject: fix a brunch of memory leaks pt.2 I'd like to see the crappy API fixed, to avoid this stupid mistakes. (bzr r15698.1.12) --- src/live_effects/lpe-clone-original.cpp | 12 +++++++++--- src/live_effects/lpe-copy_rotate.cpp | 4 +++- src/live_effects/lpe-measure-line.cpp | 11 +++++++---- src/live_effects/lpe-mirror_symmetry.cpp | 4 +++- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index d97a990af..31bf0e270 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -138,10 +138,14 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co dest_affine *= Geom::Translate(preserve_affine.translation()); affine_previous = preserve_affine; preserve_affine = Geom::identity(); - SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(dest_affine)); + gchar * str = sp_svg_transform_write(dest_affine); + SP_ITEM(dest)->getRepr()->setAttribute("transform", str); + g_free(str); } } else { - SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(affine_origin)); + gchar * str = sp_svg_transform_write(affine_origin); + SP_ITEM(dest)->getRepr()->setAttribute("transform", str); + g_free(str); } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0)) { SPCurve *c = NULL; @@ -176,7 +180,9 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co c->set_pathvector(c_pv); if (!path_origin) { shape_dest->setCurveInsync(c, TRUE); - dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + gchar *str = sp_svg_write_path(c_pv); + dest->getRepr()->setAttribute(attribute, str); + g_free(str); } else { shape_dest->setCurve(c, TRUE); } diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f8be0f2a5..e80ad80cb 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -274,7 +274,9 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) Inkscape::GC::release(phantom); } cloneD(SP_OBJECT(sp_lpe_item), elemref, true, reset); - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + gchar *str = sp_svg_transform_write(transform); + elemref->getRepr()->setAttribute("transform" , str); + g_free(str); SP_ITEM(elemref)->setHidden(false); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 892744462..f7892cbe7 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -260,7 +260,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl rtspan = xml_doc->createElement("svg:tspan"); rtspan->setAttribute("sodipodi:role", "line"); } - const char * transform; + gchar * transform; Geom::Affine affine = Geom::Affine(Geom::Translate(pos).inverse()); angle = std::fmod(angle, 2*M_PI); if (angle < 0) angle += 2*M_PI; @@ -276,6 +276,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl transform = NULL; } rtext->setAttribute("transform", transform); + g_free(transform); SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css, anotation_format.param_getSVGValue()); Inkscape::FontLister *fontlister = Inkscape::FontLister::get_instance(); @@ -317,7 +318,7 @@ LPEMeasureLine::createTextLabel(Geom::Point pos, double length, Geom::Coord angl g_snprintf(length_str, 64, "%.*f", (int)precision, length); setlocale (LC_NUMERIC, oldlocale); g_free (oldlocale); - Glib::ustring label_value = Glib::ustring(format.param_getSVGValue()); + Glib::ustring label_value(format.param_getSVGValue()); size_t s = label_value.find(Glib::ustring("{measure}"),0); if(s < label_value.length()) { label_value.replace(s,s+9,length_str); @@ -413,17 +414,19 @@ LPEMeasureLine::createLine(Geom::Point start,Geom::Point end, const char * id, b } line = elemref->getRepr(); - const char * line_str = sp_svg_write_path( line_pathv ); + gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); line->setAttribute("transform", NULL); + g_free(line_str); } else { if (remove) { return; } line = xml_doc->createElement("svg:path"); line->setAttribute("id", id); - const char * line_str = sp_svg_write_path( line_pathv ); + gchar * line_str = sp_svg_write_path( line_pathv ); line->setAttribute("d" , line_str); + g_free(line_str); } line->setAttribute("sodipodi:insensitive", "true"); line_pathv.clear(); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 186b97fe3..b1f10c242 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -291,7 +291,9 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) Inkscape::GC::release(phantom); } cloneD(SP_OBJECT(sp_lpe_item), elemref, true, true); - elemref->getRepr()->setAttribute("transform" , sp_svg_transform_write(transform)); + gchar *str = sp_svg_transform_write(transform); + elemref->getRepr()->setAttribute("transform" , str); + g_free(str); if (elemref->parent != container) { Inkscape::XML::Node *copy = phantom->duplicate(xml_doc); copy->setAttribute("id", elemref_id); -- cgit v1.2.3 From b6a1443bedffbebe6defa48837a19fe47daa13ca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 25 May 2017 13:07:38 +0200 Subject: Allow rotate on split items over Rotate copies LPE (bzr r15701) --- src/live_effects/lpe-copy_rotate.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index e80ad80cb..45734168e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -628,6 +628,13 @@ Geom::PathVector LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) { if ((split_items || num_copies == 1) && method != RM_FUSE && method != RM_KALEIDOSCOPE) { + if (split_items) { + Geom::PathVector path_out = pathv_to_linear_and_cubic_beziers(path_in); + Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); + Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle))); + Geom::Affine t = m * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + return path_out * t; + } return path_in; } -- cgit v1.2.3 From 392fb78921ab50255888bc09e6b4252e71440370 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 May 2017 12:45:27 +0200 Subject: Improve methods on rotate copies LPE (bzr r15702) --- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-copy_rotate.cpp | 86 ++++++++++++++++++-------------- src/live_effects/lpe-copy_rotate.h | 4 +- src/live_effects/lpe-mirror_symmetry.cpp | 10 ++-- src/live_effects/lpe-mirror_symmetry.h | 2 +- 5 files changed, 58 insertions(+), 46 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index aa8987185..a4b44b1a9 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -439,7 +439,7 @@ Effect::processObjects(LpeAction lpe_action) for (std::vector::iterator el_it = items.begin(); el_it != items.end(); ++el_it) { const char * id = *el_it; - if (!id || strlen(id) == 0) { + if (!id) { return; } SPObject *elemref = NULL; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 45734168e..f3bc1eeb3 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -94,6 +94,8 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies.param_make_integer(true); apply_to_clippath_and_mask = true; previous_num_copies = num_copies; + previous_origin = Geom::Point(0,0); + previous_start_point = Geom::Point(0,0); reset = false; } @@ -137,28 +139,34 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) previous_num_copies = num_copies; } SPObject *elemref = NULL; - char * id = g_strdup(Glib::ustring("rotated-").append("1").append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); + const char * id = g_strdup(Glib::ustring("rotated-").append("0").append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); guint counter = 0; while((elemref = document->getObjectById(id))) { + id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); if (SP_ITEM(elemref)->isHidden()) { items.push_back(id); } - id = g_strdup(Glib::ustring("rotated-").append(std::to_string(counter)).append("-").append(sp_lpe_item->getRepr()->attribute("id")).c_str()); counter++; } - g_free(id); Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); for (size_t i = 1; i < num_copies; ++i) { Geom::Affine r = Geom::identity(); - if( i%2 != 0 && mirror_copies) { + if(mirror_copies && i%2 != 0) { r *= Geom::Rotate(Geom::Angle(half_dir)).inverse(); r *= Geom::Scale(1, -1); r *= Geom::Rotate(Geom::Angle(half_dir)); } + Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle * i))); Geom::Affine t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - if( i%2 != 0 && mirror_copies) { - t = m * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); + if (method != RM_NORMAL) { + if(mirror_copies && i%2 != 0) { + t = m * r * rot * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } + } else { + if(mirror_copies && i%2 != 0) { + t = m * Geom::Rotate(Geom::rad_from_deg(-rotation_angle)) * r * rot * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + } } t *= sp_lpe_item->transform; toItem(t, i-1, reset); @@ -171,28 +179,30 @@ LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) } void -LPECopyRotate::cloneD(SPObject *origin, SPObject *dest, bool root, bool reset) +LPECopyRotate::cloneD(SPObject *orig, SPObject *dest, Geom::Affine transform, bool root, bool reset) { SPDocument * document = SP_ACTIVE_DOCUMENT; if (!document) { return; } Inkscape::XML::Document *xml_doc = document->getReprDoc(); - if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { - std::vector< SPObject * > childs = origin->childList(true); + if ( SP_IS_GROUP(orig) && SP_IS_GROUP(dest) && SP_GROUP(orig)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = orig->childList(true); size_t index = 0; for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneD(*obj_it, dest_child, false, reset); + cloneD(*obj_it, dest_child, transform, false, reset); index++; } } - SPShape * shape = SP_SHAPE(origin); + SPShape * shape = SP_SHAPE(orig); SPPath * path = SP_PATH(dest); if (shape && !path) { + const char * id = dest->getId(); Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); + dest->getRepr()->setAttribute("d", id); path = SP_PATH(dest); } if (path && shape) { @@ -273,7 +283,7 @@ LPECopyRotate::toItem(Geom::Affine transform, size_t i, bool reset) elemref = container->appendChildRepr(phantom); Inkscape::GC::release(phantom); } - cloneD(SP_OBJECT(sp_lpe_item), elemref, true, reset); + cloneD(SP_OBJECT(sp_lpe_item), elemref, transform, true, reset); gchar *str = sp_svg_transform_write(transform); elemref->getRepr()->setAttribute("transform" , str); g_free(str); @@ -353,7 +363,9 @@ LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) // cycle through all parameters. Most parameters will not need transformation, but path and point params do. for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; - param->param_transform_multiply(postmul, set); + if(param->param_key != "starting_point" || postmul.isRotation()) { + param->param_transform_multiply(postmul, set); + } } sp_lpe_item_update_patheffect(sp_lpe_item, false, false); } @@ -366,11 +378,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if (copies_to_360 && num_copies > 2) { rotation_angle.param_set_value(360.0/(double)num_copies); } - - if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0 && copies_to_360) { + if (method != RM_NORMAL && rotation_angle * num_copies > 360.1 && rotation_angle > 0 && copies_to_360) { num_copies.param_set_value(floor(360/rotation_angle)); } - if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && mirror_copies && copies_to_360) { + if (method != RM_NORMAL && mirror_copies && copies_to_360) { num_copies.param_set_increments(2.0,10.0); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -388,8 +399,9 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) dir = unit_vector(B - A); // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) - bool near = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); - if (!near) { + bool near_start_point = Geom::are_near(previous_start_point, (Geom::Point)starting_point, 0.01); + bool near_origin = Geom::are_near(previous_origin, (Geom::Point)origin, 0.01); + if (!near_start_point) { starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); if (GDK_SHIFT_MASK) { dist_angle_handle = L2(B - A); @@ -400,16 +412,17 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if (dist_angle_handle < 1.0) { dist_angle_handle = 1.0; } - start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; - rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; - near = Geom::are_near(start_pos, (Geom::Point)starting_point, 0.01); - if (!near) { + double distance = dist_angle_handle; + if (previous_start_point != Geom::Point(0,0) || previous_origin != Geom::Point(0,0)) { + distance = Geom::distance(previous_origin, starting_point); + } + start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * distance; + if (!near_start_point || !near_origin || split_items) { starting_point.param_setValue(start_pos); } + + previous_origin = (Geom::Point)origin; previous_start_point = (Geom::Point)starting_point; - if ( method == RM_FUSE || copies_to_360 ) { - rot_pos = origin; - } } void @@ -598,7 +611,7 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) divider.appendNew(line_end); divider.close(); half_dir = unit_vector(Geom::middle_point(line_start,line_end) - (Geom::Point)origin); - if (method == RM_KALEIDOSCOPE || method == RM_FUSE) { + if (method != RM_NORMAL) { if (method != RM_KALEIDOSCOPE) { path_out = doEffect_path_post(path_in); } else { @@ -627,14 +640,13 @@ LPECopyRotate::doEffect_path (Geom::PathVector const & path_in) Geom::PathVector LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) { - if ((split_items || num_copies == 1) && method != RM_FUSE && method != RM_KALEIDOSCOPE) { - if (split_items) { - Geom::PathVector path_out = pathv_to_linear_and_cubic_beziers(path_in); - Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); - Geom::Rotate rot(-(Geom::rad_from_deg(rotation_angle))); - Geom::Affine t = m * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); - return path_out * t; - } + if ((split_items || num_copies == 1) && method == RM_NORMAL) { + if (split_items) { + Geom::PathVector path_out = pathv_to_linear_and_cubic_beziers(path_in); + Geom::Affine m = Geom::Translate(-origin) * Geom::Rotate(-(Geom::rad_from_deg(starting_angle))); + Geom::Affine t = m * Geom::Rotate(-Geom::rad_from_deg(starting_angle)) * Geom::Rotate(Geom::rad_from_deg(starting_angle)) * Geom::Translate(origin); + return path_out * t; + } return path_in; } @@ -654,7 +666,7 @@ LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) if(mirror_copies && i%2 != 0) { t = pre * r * rot * Geom::Rotate(Geom::rad_from_deg(starting_angle)).inverse() * Geom::Translate(origin); } - if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { + if (method != RM_NORMAL) { Geom::PathVector join_pv = original_pathv * t; join_pv *= Geom::Translate(half_dir * rot * gap); Geom::PathIntersectionGraph *pig = new Geom::PathIntersectionGraph(output_pv, join_pv); @@ -674,7 +686,7 @@ LPECopyRotate::doEffect_path_post (Geom::PathVector const & path_in) output.insert(output.end(), output_pv.begin(), output_pv.end()); } } - if (method == RM_FUSE || method == RM_KALEIDOSCOPE) { + if (method != RM_NORMAL) { output = output_pv; } return output; @@ -688,7 +700,7 @@ LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector((Geom::Point)origin); - hp.appendNew(origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle); + hp.appendNew(origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * Geom::distance(origin,starting_point)); Geom::PathVector pathv; pathv.push_back(hp); hp_vec.push_back(pathv); diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 542a4e36e..bc89878e5 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -48,7 +48,7 @@ public: virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); virtual Gtk::Widget * newWidget(); void toItem(Geom::Affine transform, size_t i, bool reset); - void cloneD(SPObject *origin, SPObject *dest, bool root, bool reset); + void cloneD(SPObject *orig, SPObject *dest, Geom::Affine transform, bool root, bool reset); void resetStyles(); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); @@ -69,7 +69,7 @@ private: Geom::Point dir; Geom::Point half_dir; Geom::Point start_pos; - Geom::Point rot_pos; + Geom::Point previous_origin; Geom::Point previous_start_point; double dist_angle_handle; double size_divider; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index b1f10c242..bd3dedc86 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -187,15 +187,15 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) } void -LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root) +LPEMirrorSymmetry::cloneD(SPObject *orig, SPObject *dest, bool live, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; if (!document) { return; } Inkscape::XML::Document *xml_doc = document->getReprDoc(); - if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { - std::vector< SPObject * > childs = origin->childList(true); + if ( SP_IS_GROUP(orig) && SP_IS_GROUP(dest) && SP_GROUP(orig)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = orig->childList(true); size_t index = 0; for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { @@ -204,7 +204,7 @@ LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root index++; } } - SPShape * shape = SP_SHAPE(origin); + SPShape * shape = SP_SHAPE(orig); SPPath * path = SP_PATH(dest); if (shape && !path) { Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); @@ -227,7 +227,7 @@ LPEMirrorSymmetry::cloneD(SPObject *origin, SPObject *dest, bool live, bool root dest->getRepr()->setAttribute("d", NULL); } } else { - dest->getRepr()->setAttribute("d", origin->getRepr()->attribute("d")); + dest->getRepr()->setAttribute("d", orig->getRepr()->attribute("d")); } } } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 592a11894..07bb3d4fc 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -49,7 +49,7 @@ public: virtual Gtk::Widget * newWidget(); void toMirror(Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); - void cloneD(SPObject *origin, SPObject *dest, bool live, bool root); + void cloneD(SPObject *orig, SPObject *dest, bool live, bool root); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); -- cgit v1.2.3 From 10ea7415fe8527dc57874a8aa67e5b904daf6d4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 May 2017 13:07:01 +0200 Subject: Order LPE parameters (bzr r15703) --- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f3bc1eeb3..ff24b46da 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -55,6 +55,7 @@ pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const & LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), + method(_("Method:"), _("Rotate methods"), "method", RMConverter, &wr, this, RM_NORMAL), origin(_("Origin"), _("Adjust origin of the rotation"), "origin", &wr, this, _("Adjust origin of the rotation")), starting_point(_("Start point"), _("Starting point to define start angle"), "starting_point", &wr, this, _("Adjust starting point to define start angle")), starting_angle(_("Starting angle"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), @@ -62,7 +63,6 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), gap(_("Gap"), _("Gap"), "gap", &wr, this, -0.0001), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - method(_("Method:"), _("Rotate methods"), "method", RMConverter, &wr, this, RM_NORMAL), mirror_copies(_("Mirror copies"), _("Mirror between copies"), "mirror_copies", &wr, this, false), split_items(_("Split elements"), _("Split elements, this allow gradients and other paints."), "split_items", &wr, this, false), dist_angle_handle(100.0) diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index bc89878e5..a0a3d4dc1 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -54,6 +54,7 @@ protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: + EnumParam method; PointParam origin; PointParam starting_point; ScalarParam starting_angle; @@ -61,7 +62,6 @@ private: ScalarParam num_copies; ScalarParam gap; BoolParam copies_to_360; - EnumParam method; BoolParam mirror_copies; BoolParam split_items; Geom::Point A; -- cgit v1.2.3 From c98c541481381a04f5e04da046d457b05c3ed711 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 27 May 2017 12:23:25 +0200 Subject: Change bad named vars (bzr r15704) --- src/live_effects/effect.cpp | 2 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-copy_rotate.cpp | 4 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 4 ++-- src/live_effects/lpe-mirror_symmetry.cpp | 4 ++-- src/live_effects/parameter/bool.cpp | 6 +++--- src/live_effects/parameter/bool.h | 4 ++-- src/live_effects/parameter/hidden.cpp | 6 ++++-- src/live_effects/parameter/hidden.h | 5 +++-- src/live_effects/parameter/parameter.cpp | 6 +++--- src/live_effects/parameter/parameter.h | 4 ++-- 12 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a4b44b1a9..23a4c9f3d 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -355,7 +355,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) oncanvasedit_it(0), is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), show_orig_path(false), - erase_extra_objects(true), + keep_paths(false), lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 60ee8d98f..cc0d53f12 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -132,7 +132,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; - bool erase_extra_objects; // set this to false allow retain extra generated objects, see measure line LPE + bool keep_paths; // set this to false allow retain extra generated objects, see measure line LPE bool upd_params; BoolParam is_visible; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index ff24b46da..2364f4f66 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -722,8 +722,8 @@ LPECopyRotate::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPECopyRotate::doOnRemove (SPLPEItem const* /*lpeitem*/) { - //unset "erase_extra_objects" hook on sp-lpe-item.cpp - if (!erase_extra_objects) { + //set "keep paths" hook on sp-lpe-item.cpp + if (keep_paths) { processObjects(LPE_TO_OBJECTS); return; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 08ceab3c3..a2f0b829d 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -38,7 +38,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), mode(_("Mode:"), _("Mode, fillet or chamfer"), - "mode", &wr, this, "F"), + "mode", &wr, this, "F", true), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index f7892cbe7..f18ba2dcd 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -674,8 +674,8 @@ LPEMeasureLine::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMeasureLine::doOnRemove (SPLPEItem const* /*lpeitem*/) { - //unset "erase_extra_objects" hook on sp-lpe-item.cpp - if (!erase_extra_objects) { + //set "keep paths" hook on sp-lpe-item.cpp + if (keep_paths) { processObjects(LPE_TO_OBJECTS); items.clear(); return; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index bd3dedc86..9c2b876db 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -350,8 +350,8 @@ LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) { - //unset "erase_extra_objects" hook on sp-lpe-item.cpp - if (!erase_extra_objects) { + //set "keep paths" hook on sp-lpe-item.cpp + if (keep_paths) { processObjects(LPE_TO_OBJECTS); return; } diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 3184bfa80..d9e8ecc90 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -21,8 +21,8 @@ namespace LivePathEffect { BoolParam::BoolParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, bool default_value , bool no_widget) - : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), hide_widget(no_widget) + Effect* effect, bool default_value , bool is_visible) + : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), widget_is_visible(is_visible) { } @@ -65,7 +65,7 @@ BoolParam::param_getSVGValue() const Gtk::Widget * BoolParam::param_newWidget() { - if(!hide_widget){ + if(widget_is_visible){ Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredCheckButton( param_label, param_tooltip, diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 39f328eaa..86681e764 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -26,7 +26,7 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect, bool default_value = false, - bool no_widget = false); + bool widget_is_visible = true); virtual ~BoolParam(); virtual Gtk::Widget * param_newWidget(); @@ -40,6 +40,7 @@ public: virtual void param_update_default(const gchar * default_value); bool get_value() const { return value; }; inline operator bool() const { return value; }; + bool widget_is_visible; private: BoolParam(const BoolParam&); @@ -47,7 +48,6 @@ private: bool value; bool defvalue; - bool hide_widget; }; diff --git a/src/live_effects/parameter/hidden.cpp b/src/live_effects/parameter/hidden.cpp index 2f218847a..95735d50f 100644 --- a/src/live_effects/parameter/hidden.cpp +++ b/src/live_effects/parameter/hidden.cpp @@ -22,10 +22,12 @@ namespace LivePathEffect { HiddenParam::HiddenParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) + Effect* effect, const Glib::ustring default_value, bool is_visible) : Parameter(label, tip, key, wr, effect), value(default_value), - defvalue(default_value) + defvalue(default_value), + //This last is to allow set or unset default parameters on hidden ones + widget_is_visible(is_visible) { } diff --git a/src/live_effects/parameter/hidden.h b/src/live_effects/parameter/hidden.h index d565272b6..f07dd9edc 100644 --- a/src/live_effects/parameter/hidden.h +++ b/src/live_effects/parameter/hidden.h @@ -29,7 +29,8 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const Glib::ustring default_value = ""); + const Glib::ustring default_value = "", + bool widget_is_visible = false); virtual ~HiddenParam() {} virtual Gtk::Widget * param_newWidget(); @@ -42,7 +43,7 @@ public: virtual void param_update_default(const gchar * default_value); const Glib::ustring get_value() const { return value; }; - + bool widget_is_visible; private: HiddenParam(const HiddenParam&); HiddenParam& operator=(const HiddenParam&); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 45f46a0a7..cc7b476d7 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -55,7 +55,7 @@ void Parameter::write_to_SVG(void) */ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, gdouble default_value, bool no_widget) + Effect* effect, gdouble default_value, bool is_visible) : Parameter(label, tip, key, wr, effect), value(default_value), min(-SCALARPARAM_G_MAXDOUBLE), @@ -67,7 +67,7 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_page(1), add_slider(false), overwrite_widget(false), - hide_widget(no_widget) + widget_is_visible(is_visible) { } @@ -172,7 +172,7 @@ ScalarParam::param_overwrite_widget(bool overwrite_widget) Gtk::Widget * ScalarParam::param_newWidget() { - if(!hide_widget){ + if(widget_is_visible){ Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index ee1d2d547..bdba9f860 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -104,7 +104,7 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect, gdouble default_value = 1.0, - bool no_widget = false); + bool widget_is_visible = true); virtual ~ScalarParam(); virtual bool param_readSVGValue(const gchar * strvalue); @@ -125,6 +125,7 @@ public: virtual Gtk::Widget * param_newWidget(); inline operator gdouble() const { return value; }; + bool widget_is_visible; protected: gdouble value; @@ -137,7 +138,6 @@ protected: double inc_page; bool add_slider; bool overwrite_widget; - bool hide_widget; private: ScalarParam(const ScalarParam&); -- cgit v1.2.3 From d77efb0c2c4b6925e87055f2921d35677d1625d5 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 27 May 2017 14:00:01 +0200 Subject: More fixes to LPE (bzr r15705) --- src/live_effects/lpe-bspline.cpp | 4 +-- src/live_effects/lpe-copy_rotate.cpp | 15 +++++----- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 35 ++++++++++++------------ src/live_effects/lpe-mirror_symmetry.cpp | 38 ++------------------------ src/live_effects/lpe-mirror_symmetry.h | 1 - src/live_effects/lpe-transform_2pts.cpp | 4 +-- src/live_effects/parameter/bool.cpp | 4 +-- src/live_effects/parameter/bool.h | 4 +-- src/live_effects/parameter/hidden.cpp | 5 ++-- src/live_effects/parameter/hidden.h | 2 +- src/live_effects/parameter/parameter.cpp | 11 ++++---- src/live_effects/parameter/parameter.h | 9 +++--- src/live_effects/parameter/satellitesarray.cpp | 1 + 14 files changed, 47 insertions(+), 88 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index dbd67beda..721a4ecab 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -44,12 +44,12 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) weight.param_set_range(NO_POWER, 100.0); weight.param_set_increments(0.1, 0.1); weight.param_set_digits(4); - weight.param_overwrite_widget(true); + weight.param_set_undo(false); steps.param_set_range(1, 10); steps.param_set_increments(1, 1); steps.param_set_digits(0); - steps.param_overwrite_widget(true); + steps.param_set_undo(false); helper_size.param_set_range(0.0, 999.0); helper_size.param_set_increments(1, 1); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 2364f4f66..551cf1bf9 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -96,6 +96,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : previous_num_copies = num_copies; previous_origin = Geom::Point(0,0); previous_start_point = Geom::Point(0,0); + starting_point.param_widget_is_visible(false); reset = false; } @@ -319,14 +320,12 @@ Gtk::Widget * LPECopyRotate::newWidget() Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); Glib::ustring *tip = param->param_getTooltip(); if (widg) { - if (param->param_key != "starting_point") { - vbox->pack_start(*widg, true, true, 2); - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); - } + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); } } } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a2f0b829d..11298bcbe 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -80,7 +80,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); - radius.param_overwrite_widget(true); + radius.param_set_undo(false); chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index f18ba2dcd..99828aef8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -141,6 +141,7 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : helpline_overlap.param_set_digits(2); start_stored = Geom::Point(0,0); end_stored = Geom::Point(0,0); + id_origin.param_widget_is_visible(false); } LPEMeasureLine::~LPEMeasureLine() {} @@ -700,24 +701,22 @@ Gtk::Widget *LPEMeasureLine::newWidget() while (it != param_vector.end()) { if ((*it)->widget_is_visible) { Parameter *param = *it; - if (param->param_key != "id_origin") { - Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - if (param->param_key != "dimline_format" && - param->param_key != "helperlines_format" && - param->param_key != "arrows_format" && - param->param_key != "anotation_format") { - vbox->pack_start(*widg, true, true, 2); - } else { - vbox_expander->pack_start(*widg, true, true, 2); - } - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); - } + Gtk::Widget *widg = dynamic_cast(param->param_newWidget()); + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + if (param->param_key != "dimline_format" && + param->param_key != "helperlines_format" && + param->param_key != "arrows_format" && + param->param_key != "anotation_format") { + vbox->pack_start(*widg, true, true, 2); + } else { + vbox_expander->pack_start(*widg, true, true, 2); + } + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); } } } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 9c2b876db..8e68c483c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -78,6 +78,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : split_gap.param_set_digits(5); apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); + id_origin.param_widget_is_visible(false); + center_point.param_widget_is_visible(false); } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -304,42 +306,6 @@ LPEMirrorSymmetry::toMirror(Geom::Affine transform) } } -Gtk::Widget * -LPEMirrorSymmetry::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::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter * param = *it; - if (param->param_key == "id_origin" || param->param_key == "center_point") { - ++it; - continue; - } - Gtk::Widget * widg = param->param_newWidget(); - 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(vbox); -} - //TODO: Migrate the tree next function to effect.cpp/h to avoid duplication void LPEMirrorSymmetry::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 07bb3d4fc..e98c83f2b 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -46,7 +46,6 @@ public: virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); virtual void doOnRemove (SPLPEItem const* /*lpeitem*/); virtual void doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/); - virtual Gtk::Widget * newWidget(); void toMirror(Geom::Affine transform); // void cloneAttrbutes(Inkscape::XML::Node * origin, Inkscape::XML::Node * dest, const char * first_attribute, ...); void cloneD(SPObject *orig, SPObject *dest, bool live, bool root); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index f4d233d56..ab05b880c 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -64,9 +64,9 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : registerParameter(&lock_angle); first_knot.param_make_integer(true); - first_knot.param_overwrite_widget(true); + first_knot.param_set_undo(false); last_knot.param_make_integer(true); - last_knot.param_overwrite_widget(true); + last_knot.param_set_undo(false); helper_size.param_set_range(0, 999); helper_size.param_set_increments(1, 1); helper_size.param_set_digits(0); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index d9e8ecc90..954947cf4 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -21,8 +21,8 @@ namespace LivePathEffect { BoolParam::BoolParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, bool default_value , bool is_visible) - : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), widget_is_visible(is_visible) + Effect* effect, bool default_value) + : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value) { } diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 86681e764..417752050 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -25,8 +25,7 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - bool default_value = false, - bool widget_is_visible = true); + bool default_value = false); virtual ~BoolParam(); virtual Gtk::Widget * param_newWidget(); @@ -40,7 +39,6 @@ public: virtual void param_update_default(const gchar * default_value); bool get_value() const { return value; }; inline operator bool() const { return value; }; - bool widget_is_visible; private: BoolParam(const BoolParam&); diff --git a/src/live_effects/parameter/hidden.cpp b/src/live_effects/parameter/hidden.cpp index 95735d50f..6d0e7f58f 100644 --- a/src/live_effects/parameter/hidden.cpp +++ b/src/live_effects/parameter/hidden.cpp @@ -25,10 +25,9 @@ HiddenParam::HiddenParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, const Glib::ustring default_value, bool is_visible) : Parameter(label, tip, key, wr, effect), value(default_value), - defvalue(default_value), - //This last is to allow set or unset default parameters on hidden ones - widget_is_visible(is_visible) + defvalue(default_value) { + param_widget_is_visible(is_visible); } void diff --git a/src/live_effects/parameter/hidden.h b/src/live_effects/parameter/hidden.h index f07dd9edc..387071e53 100644 --- a/src/live_effects/parameter/hidden.h +++ b/src/live_effects/parameter/hidden.h @@ -43,7 +43,7 @@ public: virtual void param_update_default(const gchar * default_value); const Glib::ustring get_value() const { return value; }; - bool widget_is_visible; + private: HiddenParam(const HiddenParam&); HiddenParam& operator=(const HiddenParam&); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index cc7b476d7..2f73488aa 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -55,7 +55,7 @@ void Parameter::write_to_SVG(void) */ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, gdouble default_value, bool is_visible) + Effect* effect, gdouble default_value) : Parameter(label, tip, key, wr, effect), value(default_value), min(-SCALARPARAM_G_MAXDOUBLE), @@ -66,8 +66,7 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, inc_step(0.1), inc_page(1), add_slider(false), - overwrite_widget(false), - widget_is_visible(is_visible) + _set_undo(true) { } @@ -164,9 +163,9 @@ ScalarParam::param_make_integer(bool yes) } void -ScalarParam::param_overwrite_widget(bool overwrite_widget) +ScalarParam::param_set_undo(bool set_undo) { - this->overwrite_widget = overwrite_widget; + _set_undo = set_undo; } Gtk::Widget * @@ -184,7 +183,7 @@ ScalarParam::param_newWidget() if (add_slider) { rsu->addSlider(); } - if(!overwrite_widget){ + if(_set_undo){ rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } return dynamic_cast (rsu); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index bdba9f860..7ab7e30dd 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -57,6 +57,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. virtual gchar * param_getSVGValue() const = 0; + virtual void param_widget_is_visible(bool is_visible) {widget_is_visible = is_visible;} void write_to_SVG(); virtual void param_set_default() = 0; @@ -103,8 +104,7 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - gdouble default_value = 1.0, - bool widget_is_visible = true); + gdouble default_value = 1.0); virtual ~ScalarParam(); virtual bool param_readSVGValue(const gchar * strvalue); @@ -121,11 +121,10 @@ public: void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; }; double param_get_max() { return max; }; double param_get_min() { return min; }; - void param_overwrite_widget(bool overwrite_widget); + void param_set_undo(bool set_undo); virtual Gtk::Widget * param_newWidget(); inline operator gdouble() const { return value; }; - bool widget_is_visible; protected: gdouble value; @@ -137,7 +136,7 @@ protected: double inc_step; double inc_page; bool add_slider; - bool overwrite_widget; + bool _set_undo; private: ScalarParam(const ScalarParam&); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 7626317a1..ce4da243e 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -37,6 +37,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _current_zoom = 0; _effectType = FILLET_CHAMFER; _last_pathvector_satellites = NULL; + param_widget_is_visible(false); } -- cgit v1.2.3 From 5f75967b19b3cc95f249194fa13a2e04ef582c36 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 28 May 2017 07:40:43 +0200 Subject: Force not original-d if the clip-path or mask has not a LPE allowed to change it (bzr r15707) --- src/live_effects/parameter/path.cpp | 104 +++++++++++++++++++++--------------- src/live_effects/parameter/path.h | 6 ++- 2 files changed, 67 insertions(+), 43 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 6e90c9279..54f5d93e8 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -69,7 +69,10 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, defvalue = g_strdup(default_value); param_readSVGValue(defvalue); oncanvas_editable = true; - + _edit_button = true; + _copy_button = true; + _paste_button = true; + _link_button = true; ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &PathParam::ref_changed)); } @@ -167,6 +170,15 @@ PathParam::param_getSVGValue() const } } +void +PathParam::set_buttons(bool edit_button, bool copy_button, bool paste_button, bool link_button) +{ + _edit_button = edit_button; + _copy_button = copy_button; + _paste_button = paste_button; + _link_button = link_button; +} + Gtk::Widget * PathParam::param_newWidget() { @@ -175,47 +187,55 @@ PathParam::param_newWidget() Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); static_cast(_widget)->pack_start(*pLabel, true, true); pLabel->set_tooltip_text(param_tooltip); - - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("tool-node-editor"), Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Edit on-canvas")); - - pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-copy"), Inkscape::ICON_SIZE_BUTTON) ); - pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_copy_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Copy path")); - - pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-paste"), Inkscape::ICON_SIZE_BUTTON) ); - pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Paste path")); - - pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-clone"), Inkscape::ICON_SIZE_BUTTON) ); - pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_link_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - pButton->set_tooltip_text(_("Link to path on clipboard")); - + Gtk::Widget * pIcon = NULL; + Gtk::Button * pButton = NULL; + if (_edit_button) { + pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("tool-node-editor"), Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Edit on-canvas")); + } + + if (_copy_button) { + pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-copy"), Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_copy_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Copy path")); + } + + if (_paste_button) { + pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-paste"), Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Paste path")); + } + if (_link_button) { + pIcon = Gtk::manage( sp_icon_get_icon( INKSCAPE_ICON("edit-clone"), Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_link_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + pButton->set_tooltip_text(_("Link to path on clipboard")); + } + static_cast(_widget)->show_all_children(); return dynamic_cast (_widget); diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 5381a6b36..ff5e4f1b8 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -44,7 +44,7 @@ public: void param_set_and_write_default(); void set_new_value (Geom::PathVector const &newpath, bool write_to_svg); void set_new_value (Geom::Piecewise > const &newpath, bool write_to_svg); - + void set_buttons(bool edit_button, bool copy_button, bool paste_button, bool link_button); virtual void param_editOncanvas(SPItem * item, SPDesktop * dt); virtual void param_setup_nodepath(Inkscape::NodePath::Path *np); virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); @@ -91,6 +91,10 @@ protected: gchar * defvalue; private: + bool _edit_button; + bool _copy_button; + bool _paste_button; + bool _link_button; PathParam(const PathParam&); PathParam& operator=(const PathParam&); }; -- cgit v1.2.3 From 59143c117378ec4a866f34b1ba2e2930bfb17593 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 28 May 2017 12:46:10 +0200 Subject: Add a new value to LPE 'is_load' to know the lpe is just load, no previous values set yet to not LPE stored values when loading a previous file (bzr r15711) --- src/live_effects/effect.cpp | 2 ++ src/live_effects/effect.h | 1 + src/live_effects/lpe-copy_rotate.cpp | 1 + src/live_effects/lpe-mirror_symmetry.cpp | 1 + 4 files changed, 5 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 23a4c9f3d..3a628b243 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,6 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), show_orig_path(false), keep_paths(false), + is_load(true), lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), @@ -511,6 +512,7 @@ Effect::doBeforeEffect (SPLPEItem const*/*lpeitem*/) void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/) { + is_load = false; } void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/) diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index cc0d53f12..e353eba23 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -133,6 +133,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; bool keep_paths; // set this to false allow retain extra generated objects, see measure line LPE + bool is_load; bool upd_params; BoolParam is_visible; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 551cf1bf9..b29b5e493 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -109,6 +109,7 @@ void LPECopyRotate::doAfterEffect (SPLPEItem const* lpeitem) { if (split_items) { + is_load = false; SPDocument * document = SP_ACTIVE_DOCUMENT; if (!document) { return; diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 8e68c483c..3fcc4ae3d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -89,6 +89,7 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doAfterEffect (SPLPEItem const* lpeitem) { + is_load = false; SPDocument * document = SP_ACTIVE_DOCUMENT; if (!document) { return; -- cgit v1.2.3 From 5151c0569bb266461c3b6a6325c0d4be60b41a67 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 29 May 2017 02:09:29 +0200 Subject: Fix bug #1694111 also fixes noumerous bugfixes on LPE undo. And shapes are improved to only perform path effet one time each Fixed bugs: - https://launchpad.net/bugs/1694111 (bzr r15713) --- src/live_effects/effect.cpp | 11 ++++++++--- src/live_effects/lpe-copy_rotate.cpp | 9 ++++----- src/live_effects/lpe-mirror_symmetry.cpp | 1 + src/live_effects/lpeobject.cpp | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 3a628b243..21136353c 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -452,10 +452,13 @@ Effect::processObjects(LpeAction lpe_action) std::vector item_selected; SPCSSAttr *css; Glib::ustring css_str; + SPItem *item = SP_ITEM(elemref); switch (lpe_action){ case LPE_TO_OBJECTS: - if (SP_ITEM(elemref)->isHidden()) { - elemref->deleteObject(); + if (item->isHidden()) { + sp_object_ref(item, 0 ); + item->deleteObject(true); + sp_object_unref(item); } else { if (elemnode->attribute("inkscape:path-effect")) { sp_item_list_to_curves(item_list, item_selected, item_to_select); @@ -465,7 +468,9 @@ Effect::processObjects(LpeAction lpe_action) break; case LPE_ERASE: - elemref->deleteObject(); + sp_object_ref(item, 0 ); + item->deleteObject(true); + sp_object_unref(item); break; case LPE_VISIBILITY: diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index b29b5e493..3abcbf217 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -199,15 +199,13 @@ LPECopyRotate::cloneD(SPObject *orig, SPObject *dest, Geom::Affine transform, bo } } SPShape * shape = SP_SHAPE(orig); - SPPath * path = SP_PATH(dest); - if (shape && !path) { + if (shape && !SP_IS_PATH(dest)) { const char * id = dest->getId(); Inkscape::XML::Node *dest_node = sp_selected_item_to_curved_repr(SP_ITEM(dest), 0); dest->updateRepr(xml_doc, dest_node, SP_OBJECT_WRITE_ALL); dest->getRepr()->setAttribute("d", id); - path = SP_PATH(dest); } - if (path && shape) { + if (SP_IS_PATH(dest) && shape) { SPCurve *c = NULL; if (root) { c = new SPCurve(); @@ -216,7 +214,7 @@ LPECopyRotate::cloneD(SPObject *orig, SPObject *dest, Geom::Affine transform, bo c = shape->getCurve(); } if (c) { - path->setCurve(c, TRUE); + SP_PATH(dest)->setCurve(c, TRUE); c->unref(); } else { dest->getRepr()->setAttribute("d", NULL); @@ -725,6 +723,7 @@ LPECopyRotate::doOnRemove (SPLPEItem const* /*lpeitem*/) //set "keep paths" hook on sp-lpe-item.cpp if (keep_paths) { processObjects(LPE_TO_OBJECTS); + items.clear(); return; } processObjects(LPE_ERASE); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 3fcc4ae3d..5d80d65fe 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -320,6 +320,7 @@ LPEMirrorSymmetry::doOnRemove (SPLPEItem const* /*lpeitem*/) //set "keep paths" hook on sp-lpe-item.cpp if (keep_paths) { processObjects(LPE_TO_OBJECTS); + items.clear(); return; } processObjects(LPE_ERASE); diff --git a/src/live_effects/lpeobject.cpp b/src/live_effects/lpeobject.cpp index b5b27c984..ca3ae46e0 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -112,6 +112,7 @@ void LivePathEffectObject::set(unsigned key, gchar const *value) { this->effecttype_set = true; } else { this->effecttype = Inkscape::LivePathEffect::INVALID_LPE; + this->lpe = NULL; this->effecttype_set = false; } -- cgit v1.2.3 From fbb39e2ef01040c3c359bf05eb3094e5c7430565 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 29 May 2017 17:41:44 +0200 Subject: Alow write to repr on hidden LPE parameters (bzr r15716) --- src/live_effects/parameter/hidden.cpp | 5 ++++- src/live_effects/parameter/hidden.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/hidden.cpp b/src/live_effects/parameter/hidden.cpp index 6d0e7f58f..e8c55ebd3 100644 --- a/src/live_effects/parameter/hidden.cpp +++ b/src/live_effects/parameter/hidden.cpp @@ -66,9 +66,12 @@ HiddenParam::param_newWidget() } void -HiddenParam::param_setValue(const Glib::ustring newvalue) +HiddenParam::param_setValue(const Glib::ustring newvalue, bool write) { value = newvalue; + if (write) { + param_write_to_repr(value.c_str()); + } } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/hidden.h b/src/live_effects/parameter/hidden.h index 387071e53..c3fba5575 100644 --- a/src/live_effects/parameter/hidden.h +++ b/src/live_effects/parameter/hidden.h @@ -38,7 +38,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; - void param_setValue(Glib::ustring newvalue); + void param_setValue(Glib::ustring newvalue, bool write = false); virtual void param_set_default(); virtual void param_update_default(const gchar * default_value); -- cgit v1.2.3