From 58ce696e0a1f622c94c23fed7671ad4c0e32e31d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 30 Oct 2014 15:22:17 +0100 Subject: [PATCH 001/121] Starting poinwise code for 0.92. Add base files (bzr r13645.1.1) --- src/2geom/pointwise.cpp | 62 +++++++++++++++++ src/2geom/pointwise.h | 90 +++++++++++++++++++++++++ src/2geom/satellite.h | 146 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 src/2geom/pointwise.cpp create mode 100644 src/2geom/pointwise.h create mode 100644 src/2geom/satellite.h diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp new file mode 100644 index 0000000000..7a84593ba4 --- /dev/null +++ b/src/2geom/pointwise.cpp @@ -0,0 +1,62 @@ +/* + * pointwise.cpp - Pointwise function class + * + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#include <2geom/pointwise.h> + +namespace Geom { + +std::pair +pointwise::findSatellites(int A) const + { + std::pair ret; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(_satellites[i].first() == A){ + ret.push_back(std::pair) + } + } + return ret; + } +double toTime(std::pair A, double B){ + +} +double toSize(std::pair A, double B) +Pointwise recalculate(Piecewise > A) + + +} +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h new file mode 100644 index 0000000000..7573a0bdcf --- /dev/null +++ b/src/2geom/pointwise.h @@ -0,0 +1,90 @@ +/** + * \file + * \brief Pointwise + *//* + * Authors: + * + * Copyright 2014 authors + * + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#ifndef SEEN_GEOM_POINTWISE_H +#define SEEN_GEOM_POINTWISE_H + +#include +#include <2geom/sbasis.h> +#include <2geom/sbasis-2d.h> +#include <2geom/piecewise.h> +#include <2geom/satellite.h> +#include <2geom/affine.h> + +namespace Geom { +/** + * %Pointwise function class. + */ + +class Pointwise +{ + public: + Pointwise(){} + + Pointwise(Piecewise > pwd2, std::vector > satellites) + : _pwd2(pwd2), _satellites(satellites) + { + } + + virtual ~Pointwise(); + + std::pair findSatellites(int A) const; + + double toTime(std::pair A, double B); + double toSize(std::pair A, double B); + double len_to_rad(int index, double len); + double rad_to_len(int index, double rad); + std::vector get_times(int index, bool last); + std::pair get_positions(int index) + int last_index(int index); + double time_to_len(int index, double time); + double len_to_time(int index, double len); + Pointwise recalculate_for_new_pwd2(Piecewise > A); + + private: + std::vector > _satellites; + Piecewise > _pwd2; +}; + +#endif //SEEN_GEOM_PW_SB_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h new file mode 100644 index 0000000000..6be745de00 --- /dev/null +++ b/src/2geom/satellite.h @@ -0,0 +1,146 @@ +/** + * \file + * \brief Satellite + *//* + * Authors: + * + * Copyright 2014 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + */ + +#ifndef LIB2GEOM_SEEN_SATELLITE_H +#define LIB2GEOM_SEEN_SATELLITE_H + +namespace Geom { + +class Satellite +{ + public: + Satellite() + {} + + virtual ~Sattelite(); + + Satellite(typeSatellite ts, bool isTime, bool active, bool after, bool hidden, double size, double time) + : _ts(ts), _time(time), _active(active), _after(after), _hidden(hidden), _size(size), _time(time) + { + } + + void setTypeSatellite(typeSatellite A) + { + _ts = A; + } + + void setActive(bool A) + { + _active = A; + } + + void setAfter(bool A) + { + _after = A; + } + + void setHidden(bool A) + { + _hidden = A; + } + + void setTime(double A) + { + _isTime = true; + _time = A; + } + + void setSize(double A) + { + _isTime = false; + _size = A; + } + + typeSatellite ts() const + { + return _ts; + } + + bool isTime() const + { + return _isTime; + } + + bool active() const + { + return _active; + } + + bool after() const + { + return _after; + } + + bool hidden() const + { + return _hidden; + } + + double size() const + { + return _size; + } + + double time() const + { + return _time; + } + + bool isDegenerate() const + { + return _size = 0 && _time = 0; + } + + private: + typeSatellite _ts; + bool _isTime; + bool _active; + bool _after; + bool _hidden; + double _size; + double _time; +}; + +} // end namespace Geom + +#endif // LIB2GEOM_SEEN_SATELLITE_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:fileencoding=utf-8:textwidth=99 : -- GitLab From 0976c402e0e09c4fe9d7d7d6990535e693b16a58 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 30 Oct 2014 20:11:17 +0100 Subject: [PATCH 002/121] Fix a bug whith units pointed by suv (bzr r13645.1.2) --- src/live_effects/lpe-fillet-chamfer.cpp | 12 +++++++----- .../parameter/filletchamferpointarray.cpp | 9 ++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f15bf9215d..8a8f68d80a 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 e2b1aba614..db24a97355 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; } -- GitLab From ab9fe994f320dfd929888e2f5d821b6968385694 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Feb 2015 18:05:01 +0100 Subject: [PATCH 003/121] refactor of pointwise base (bzr r13645.1.6) --- src/2geom/pointwise.cpp | 22 +++++++---------- src/2geom/pointwise.h | 19 +++++++-------- src/2geom/satellite-enum.h | 40 +++++++++++++++++++++++++++++++ src/2geom/satellite.h | 48 +++++++++++++++++++++++++++++--------- 4 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 src/2geom/satellite-enum.h diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 7a84593ba4..ce3aa86f6f 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -31,23 +31,17 @@ namespace Geom { -std::pair +std::vector pointwise::findSatellites(int A) const - { - std::pair ret; - for(unsigned i = 0; i < _satellites.size(); i++){ - if(_satellites[i].first() == A){ - ret.push_back(std::pair) - } - } - return ret; +{ + std::vector ret; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(_satellites[i].first() == A){ + ret.push_back(_satellites[i].second); } -double toTime(std::pair A, double B){ - + } + return ret; } -double toSize(std::pair A, double B) -Pointwise recalculate(Piecewise > A) - } /* diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 7573a0bdcf..33289f4f07 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -59,18 +59,15 @@ class Pointwise virtual ~Pointwise(); - std::pair findSatellites(int A) const; - - double toTime(std::pair A, double B); - double toSize(std::pair A, double B); - double len_to_rad(int index, double len); - double rad_to_len(int index, double rad); - std::vector get_times(int index, bool last); - std::pair get_positions(int index) - int last_index(int index); - double time_to_len(int index, double time); - double len_to_time(int index, double len); + std::vector findSatellites(int A) const; Pointwise recalculate_for_new_pwd2(Piecewise > A); + Pointwise pwd2_reverse(int index); + Pointwise pwd2_append(int index); + Pointwise pwd2_prepend(int index); + Pointwise pwd2_add(int index); + Pointwise pwd2_del(int index); + Pointwise satellite_add(int index,satelite sat); + Pointwise satellite_del(int index,satelite sat); private: std::vector > _satellites; diff --git a/src/2geom/satellite-enum.h b/src/2geom/satellite-enum.h new file mode 100644 index 0000000000..3872cf7180 --- /dev/null +++ b/src/2geom/satellite-enum.h @@ -0,0 +1,40 @@ +#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H +#define LIB2GEOM_SEEN_SATELLITE_ENUM_H + +/* + * + * +* Copyright (C) Jabier Arraiza Cenoz + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "util/enums.h" + +namespace Geom { + +enum SatelliteType { + FILLET=0, + INVERSE_FILLET, + CHAMFER, + INVERSE_CHAMFER, + INVALID_SATELLITE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) +}; + +extern const Util::EnumData SATELLITETypeData[]; /// defined in satelite.cpp +extern const Util::EnumDataConverter SATELLITETypeConverter; /// defined in sattelite.cpp + +} //namespace Geom + +#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/2geom/satellite.h b/src/2geom/satellite.h index 6be745de00..8e570db4cf 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -33,8 +33,22 @@ #ifndef LIB2GEOM_SEEN_SATELLITE_H #define LIB2GEOM_SEEN_SATELLITE_H +#include <2geom/satellite-enum.h> + namespace Geom { +const Util::EnumData SATELLITETypeData[] = { + // {constant defined in satellite-enum.h, N_("name of satellite_type"), "name of your satellite type on SVG"} +/* 0.92 */ + {FILLET, N_("Fillet"), "fillet"}, + {INVERSE_FILLET, N_("Inverse Fillet"), "inverse_fillet"}, + {CHAMFER, N_("Chamfer"), "chamfer"}, + {INVERSE_CHAMFER, N_("Inverse Chamfer"), "inverse_chamfer"}, + {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, +}; +const Util::EnumDataConverter SATELLITETypeConverter(SATELLITETypeData, sizeof(SATELLITETypeData)/sizeof(*SATELLITETypeData)); + + class Satellite { public: @@ -43,14 +57,14 @@ class Satellite virtual ~Sattelite(); - Satellite(typeSatellite ts, bool isTime, bool active, bool after, bool hidden, double size, double time) - : _ts(ts), _time(time), _active(active), _after(after), _hidden(hidden), _size(size), _time(time) + Satellite(SatelliteType satellitetype, bool isTime, bool active, bool mirror, bool after, bool hidden, double size, double time) + : _satellitetype(satellitetype), _time(time), _active(active), _mirror(mirror), _after(after), _hidden(hidden), _size(size), _time(time) { } - void setTypeSatellite(typeSatellite A) + void setSatelliteType(SatelliteType A) { - _ts = A; + _satellitetype = A; } void setActive(bool A) @@ -58,9 +72,9 @@ class Satellite _active = A; } - void setAfter(bool A) + void setHasMirror(bool A) { - _after = A; + _mirror = A; } void setHidden(bool A) @@ -80,7 +94,7 @@ class Satellite _size = A; } - typeSatellite ts() const + SatelliteType satellitetype() const { return _ts; } @@ -95,9 +109,9 @@ class Satellite return _active; } - bool after() const + bool hasMirror() const { - return _after; + return _mirror; } bool hidden() const @@ -115,16 +129,28 @@ class Satellite return _time; } + double toTime(double A,D2 curve) const + { + //todo make the process + return _time; + } + + double toSize(double A,D2 curve) const + { + //todo make the process + return _size; + } + bool isDegenerate() const { return _size = 0 && _time = 0; } private: - typeSatellite _ts; + SatelliteType _satellitetype; bool _isTime; bool _active; - bool _after; + bool _hasMirror; bool _hidden; double _size; double _time; -- GitLab From 86891a9e442c81435c6d197cb09b3dc210643bc0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Feb 2015 16:40:25 +0100 Subject: [PATCH 004/121] starting whith pointwise (bzr r13645.1.7) --- src/2geom/Makefile_insert | 3 + src/2geom/pointwise.cpp | 6 +- src/2geom/pointwise.h | 16 +- src/2geom/satellite-enum.h | 2 +- src/2geom/satellite.h | 28 +- 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 ++++ 13 files changed, 295 insertions(+), 623 deletions(-) create mode 100644 src/live_effects/parameter/pointwise.cpp create mode 100644 src/live_effects/parameter/pointwise.h diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index e77f413cb2..2f23bc4423 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -80,6 +80,8 @@ 2geom/point.cpp \ 2geom/point.h \ 2geom/point-ops.h \ + 2geom/pointwise.cpp \ + 2geom/pointwise.h \ 2geom/poly.cpp \ 2geom/poly.h \ 2geom/quadtree.cpp \ @@ -90,6 +92,7 @@ 2geom/recursive-bezier-intersection.cpp \ 2geom/region.cpp \ 2geom/region.h \ + 2geom/satellite.h \ 2geom/sbasis-2d.cpp \ 2geom/sbasis-2d.h \ 2geom/sbasis.cpp \ diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index ce3aa86f6f..cd7f7914fc 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -1,6 +1,8 @@ /* - * pointwise.cpp - Pointwise function class - * + * pointwise.cpp + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 33289f4f07..c0974f54c2 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -3,10 +3,20 @@ * \brief Pointwise *//* * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors * - * Copyright 2014 authors - * - * + * Pointwise maintains a set of "Satellite" positions along a curve/pathvector. + * The positions are specified as arc length distances along the curve or by + * time in the curve. Splicing operations automatically update the satellite + * positions to preserve the intent. + * The data is serialised to SVG using a specialiced pointwise LPE parameter to + * handle it in th future can be a inkscape based property to paths + * //all operations are O(1) per satellite, with the exception of .., .., and .., which + * //need to use binary search to find the locations. + * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing + * existing algorithms to correctly update satellite positions. + * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation diff --git a/src/2geom/satellite-enum.h b/src/2geom/satellite-enum.h index 3872cf7180..a71306bc95 100644 --- a/src/2geom/satellite-enum.h +++ b/src/2geom/satellite-enum.h @@ -20,7 +20,7 @@ enum SatelliteType { INVERSE_CHAMFER, INVALID_SATELLITE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) }; - +std::map SatelliteTypeMap = boost::map_list_of("FILLET", FILLET)("INVERSE_FILLET", INVERSE_FILLET)("CHAMFER",CHAMFER)("INVERSE_CHAMFER",INVERSE_CHAMFER)("INVALID_SATELLITE",INVALID_SATELLITE); extern const Util::EnumData SATELLITETypeData[]; /// defined in satelite.cpp extern const Util::EnumDataConverter SATELLITETypeConverter; /// defined in sattelite.cpp diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 8e570db4cf..a18b08f27a 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -3,8 +3,8 @@ * \brief Satellite *//* * Authors: - * - * Copyright 2014 authors + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors * * This library is free software; you can redistribute it and/or * modify it either under the terms of the GNU Lesser General Public @@ -129,16 +129,30 @@ class Satellite return _time; } - double toTime(double A,D2 curve) const + double time(D2 curve) const { //todo make the process return _time; } - double toSize(double A,D2 curve) const - { - //todo make the process - return _size; + void setPosition(Geom::Point p, D2 curve){ + _time = Geom::nearestPoint(p, curve); + if(!_isTime){ + if (curve.degreesOfFreedom() != 2) { + Piecewise > u; + u.push_cut(0); + u.push(curve, 1); + u = portion(u, 0, _time); + _size = length(u, 0.001) * -1; + } else { + lenghtPart = length(last_pwd2[index], EPSILON); + _size = (time * lenghtPart) * -1; + } + } + } + + Geom::Point getPosition(D2 curve){ + return curve.pointAt(_time); } bool isDegenerate() const diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index c8a02c8100..e171e99e3c 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 d2bdf2d8de..f4eb4f46e3 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 0d6a1ff178..f4462d1540 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 f990f41c77..d78b1e22f3 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 1b8f742da0..bd2bf1870d 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 a600f02573..b93c7a617c 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 0000000000..ec83eb6c70 --- /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 0000000000..59f1b4ff46 --- /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 -- GitLab From 99fb2239028e72f8773bff39e43f7af33b4252d4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:29:48 +0100 Subject: [PATCH 005/121] first steps (bzr r13645.1.9) --- src/2geom/2geom.h | 2 + src/2geom/CMakeLists.txt | 4 + src/2geom/Makefile_insert | 1 + src/2geom/pointwise.cpp | 15 ++- src/2geom/pointwise.h | 24 ++--- src/2geom/satellite-enum.h | 19 +++- src/2geom/satellite.h | 67 ++++--------- 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 ----------------- 15 files changed, 173 insertions(+), 325 deletions(-) delete mode 100644 src/live_effects/parameter/pointwise.cpp delete mode 100644 src/live_effects/parameter/pointwise.h diff --git a/src/2geom/2geom.h b/src/2geom/2geom.h index 000f3423d5..1deef9e8c6 100644 --- a/src/2geom/2geom.h +++ b/src/2geom/2geom.h @@ -59,6 +59,8 @@ #include <2geom/sbasis.h> // others +#include <2geom/pointwise.h> +#include <2geom/satellite.h> #include <2geom/math-utils.h> #include <2geom/utils.h> diff --git a/src/2geom/CMakeLists.txt b/src/2geom/CMakeLists.txt index eeaecaa394..b49b78e7e2 100644 --- a/src/2geom/CMakeLists.txt +++ b/src/2geom/CMakeLists.txt @@ -26,11 +26,13 @@ set(2geom_SRC pathvector.cpp piecewise.cpp point.cpp + pointwise.cpp poly.cpp quadtree.cpp rect.cpp # recursive-bezier-intersection.cpp region.cpp + satellite.cpp sbasis-2d.cpp sbasis-geometric.cpp sbasis-math.cpp @@ -100,11 +102,13 @@ set(2geom_SRC piecewise.h point-ops.h point.h + pointwise.h poly.h quadtree.h ray.h rect.h region.h + satellite.h sbasis-2d.h sbasis-curve.h sbasis-geometric.h diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index 2f23bc4423..8872065fb7 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -92,6 +92,7 @@ 2geom/recursive-bezier-intersection.cpp \ 2geom/region.cpp \ 2geom/region.h \ + 2geom/satellite.cpp \ 2geom/satellite.h \ 2geom/sbasis-2d.cpp \ 2geom/sbasis-2d.h \ diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index cd7f7914fc..5cbccbca99 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -33,12 +33,19 @@ namespace Geom { -std::vector -pointwise::findSatellites(int A) const +Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) + : _pwd2(pwd2), _satellites(satellites) { - std::vector ret; +}; + +Pointwise::~Pointwise(){}; + +std::vector +Pointwise::findSatellites(int A) const +{ + std::vector ret; for(unsigned i = 0; i < _satellites.size(); i++){ - if(_satellites[i].first() == A){ + if(_satellites[i].first == A){ ret.push_back(_satellites[i].second); } } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index c0974f54c2..6e9c8840ba 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -50,7 +50,6 @@ #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> #include <2geom/satellite.h> -#include <2geom/affine.h> namespace Geom { /** @@ -60,31 +59,28 @@ namespace Geom { class Pointwise { public: - Pointwise(){} - - Pointwise(Piecewise > pwd2, std::vector > satellites) - : _pwd2(pwd2), _satellites(satellites) - { - } - + Pointwise(){}; + Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); - - std::vector findSatellites(int A) const; + std::vector findSatellites(int A) const; Pointwise recalculate_for_new_pwd2(Piecewise > A); Pointwise pwd2_reverse(int index); Pointwise pwd2_append(int index); Pointwise pwd2_prepend(int index); Pointwise pwd2_add(int index); Pointwise pwd2_del(int index); - Pointwise satellite_add(int index,satelite sat); - Pointwise satellite_del(int index,satelite sat); + Pointwise satellite_add(int index,Satellite sat); + Pointwise satellite_del(int index,Satellite sat); private: - std::vector > _satellites; Piecewise > _pwd2; + std::vector > _satellites; + }; -#endif //SEEN_GEOM_PW_SB_H +} // end namespace Geom + +#endif //SEEN_GEOM_POINTWISE_H /* Local Variables: mode:c++ diff --git a/src/2geom/satellite-enum.h b/src/2geom/satellite-enum.h index a71306bc95..474e985479 100644 --- a/src/2geom/satellite-enum.h +++ b/src/2geom/satellite-enum.h @@ -10,6 +10,8 @@ */ #include "util/enums.h" +/*#include +*/ namespace Geom { @@ -18,11 +20,20 @@ enum SatelliteType { INVERSE_FILLET, CHAMFER, INVERSE_CHAMFER, - INVALID_SATELLITE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) + INVALID_SATELLITE // This must be last) }; -std::map SatelliteTypeMap = boost::map_list_of("FILLET", FILLET)("INVERSE_FILLET", INVERSE_FILLET)("CHAMFER",CHAMFER)("INVERSE_CHAMFER",INVERSE_CHAMFER)("INVALID_SATELLITE",INVALID_SATELLITE); -extern const Util::EnumData SATELLITETypeData[]; /// defined in satelite.cpp -extern const Util::EnumDataConverter SATELLITETypeConverter; /// defined in sattelite.cpp + +/* TODO maybe is best do next by bimap + typedef boost::bimap< Geom::SatelliteType,gchar const *> map_type ; + + map_type SatelliteTypeBimap; + + SatelliteTypeBimap.insert( map_type::value_type(FILLET, "FILLET")); + SatelliteTypeBimap.insert( map_type::value_type(INVERSE_FILLET, "INVERSE_FILLET")); + SatelliteTypeBimap.insert( map_type::value_type(CHAMFER, "CHAMFER")) ); + SatelliteTypeBimap.insert( map_type::value_type(INVERSE_CHAMFER, "INVERSE_CHAMFER")); + SatelliteTypeBimap.insert( map_type::value_type(INVALID_SATELLITE, "INVALID_SATELLITE")); +*/ } //namespace Geom diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index a18b08f27a..8623ff1b08 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -34,39 +34,31 @@ #define LIB2GEOM_SEEN_SATELLITE_H #include <2geom/satellite-enum.h> +#include <2geom/d2.h> +#include +#include namespace Geom { -const Util::EnumData SATELLITETypeData[] = { - // {constant defined in satellite-enum.h, N_("name of satellite_type"), "name of your satellite type on SVG"} -/* 0.92 */ - {FILLET, N_("Fillet"), "fillet"}, - {INVERSE_FILLET, N_("Inverse Fillet"), "inverse_fillet"}, - {CHAMFER, N_("Chamfer"), "chamfer"}, - {INVERSE_CHAMFER, N_("Inverse Chamfer"), "inverse_chamfer"}, - {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, -}; -const Util::EnumDataConverter SATELLITETypeConverter(SATELLITETypeData, sizeof(SATELLITETypeData)/sizeof(*SATELLITETypeData)); - - class Satellite { public: - Satellite() - {} - virtual ~Sattelite(); + Satellite(); + Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double size, double time); - Satellite(SatelliteType satellitetype, bool isTime, bool active, bool mirror, bool after, bool hidden, double size, double time) - : _satellitetype(satellitetype), _time(time), _active(active), _mirror(mirror), _after(after), _hidden(hidden), _size(size), _time(time) - { - } + virtual ~Satellite(); void setSatelliteType(SatelliteType A) { _satellitetype = A; } + void setIsTime(bool A) + { + _isTime = A; + } + void setActive(bool A) { _active = A; @@ -74,7 +66,7 @@ class Satellite void setHasMirror(bool A) { - _mirror = A; + _hasMirror = A; } void setHidden(bool A) @@ -84,19 +76,17 @@ class Satellite void setTime(double A) { - _isTime = true; _time = A; } void setSize(double A) { - _isTime = false; _size = A; } SatelliteType satellitetype() const { - return _ts; + return _satellitetype; } bool isTime() const @@ -111,7 +101,7 @@ class Satellite bool hasMirror() const { - return _mirror; + return _hasMirror; } bool hidden() const @@ -129,36 +119,19 @@ class Satellite return _time; } - double time(D2 curve) const + double time(Geom::D2 curve) const { //todo make the process return _time; } - void setPosition(Geom::Point p, D2 curve){ - _time = Geom::nearestPoint(p, curve); - if(!_isTime){ - if (curve.degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(curve, 1); - u = portion(u, 0, _time); - _size = length(u, 0.001) * -1; - } else { - lenghtPart = length(last_pwd2[index], EPSILON); - _size = (time * lenghtPart) * -1; - } - } - } + void setPosition(Geom::Point p, Geom::D2 curve); - Geom::Point getPosition(D2 curve){ - return curve.pointAt(_time); - } + Geom::Point getPosition(Geom::D2 curve); - bool isDegenerate() const - { - return _size = 0 && _time = 0; - } + static const std::map SatelliteTypeToGcharMap; + + static const std::map GcharMapToSatelliteType; private: SatelliteType _satellitetype; diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index e171e99e3c..6b004e1dfa 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 f4eb4f46e3..884e51ffd3 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 f4462d1540..08000c0a59 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 d78b1e22f3..33c6b06737 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 bd2bf1870d..d17f28c4fe 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 b93c7a617c..9f26ed3e6d 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 59f1b4ff46..0000000000 --- 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 -- GitLab From 3ff9b36f48101c62c460622dd683a582e5dc17ca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:31:04 +0100 Subject: [PATCH 006/121] first steps (bzr r13645.1.10) --- .../parameter/satellitepairarray.cpp | 114 ++++++++++++++++++ .../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 diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp new file mode 100644 index 0000000000..f4f79b4858 --- /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 0000000000..82d04c790b --- /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 -- GitLab From 5c3350ef1281298f25c1cbcb60a66d238a417030 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 00:12:00 +0100 Subject: [PATCH 007/121] 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 ++++++------- .../parameter/satellitepairarray.cpp | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 884e51ffd3..5d6358bb20 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 d17f28c4fe..d1d718b081 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 9f26ed3e6d..ba1ed3d4e4 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; } -- GitLab From 9593c78703845bfca18a3a135cbbc47cc03b54f6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 21:49:53 +0100 Subject: [PATCH 008/121] continuing fillet/chamfer (bzr r13645.1.13) --- src/2geom/satellite.h | 31 ++- 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 +- .../parameter/satellitepairarray.cpp | 4 +- .../parameter/satellitepairarray.h | 7 +- 7 files changed, 259 insertions(+), 48 deletions(-) diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 8623ff1b08..06b4a1dd69 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -54,6 +54,12 @@ class Satellite _satellitetype = A; } + void setSatelliteType(gchar const * A) + { + std::map GcharMapToSatelliteType = boost::assign::map_list_of("FILLET", FILLET)("INVERSE_FILLET", INVERSE_FILLET)("CHAMFER",CHAMFER)("INVERSE_CHAMFER",INVERSE_CHAMFER)("INVALID_SATELLITE",INVALID_SATELLITE); + _satellitetype = GcharMapToSatelliteType[A]; + } + void setIsTime(bool A) { _isTime = A; @@ -84,42 +90,48 @@ class Satellite _size = A; } - SatelliteType satellitetype() const + SatelliteType getSatelliteType() const { return _satellitetype; } - bool isTime() const + gchar const * getSatelliteTypeGchar() const + { + std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(FILLET, "FILLET")(INVERSE_FILLET, "INVERSE_FILLET")(CHAMFER,"CHAMFER")(INVERSE_CHAMFER,"INVERSE_CHAMFER")(INVALID_SATELLITE,"INVALID_SATELLITE"); + return SatelliteTypeToGcharMap[_satellitetype]; + } + + bool getIsTime() const { return _isTime; } - bool active() const + bool getActive() const { return _active; } - bool hasMirror() const + bool getHasMirror() const { return _hasMirror; } - bool hidden() const + bool getHidden() const { return _hidden; } - double size() const + double getSize() const { return _size; } - double time() const + double getTime() const { return _time; } - double time(Geom::D2 curve) const + double getTime(Geom::D2 curve) const { //todo make the process return _time; @@ -133,7 +145,10 @@ class Satellite static const std::map GcharMapToSatelliteType; + static double getOpositeTime(Geom::D2 SBasisCurve, double time); + private: + SatelliteType _satellitetype; bool _isTime; bool _active; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 5d6358bb20..df9de81b75 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 08000c0a59..94a2bd2b3b 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 d1d718b081..473b561d26 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 ba1ed3d4e4..c99777b08b 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 82d04c790b..ff1924829c 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; }; -- GitLab From e6e262b34c193502d1f9be44324515bf8c861d47 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 17 Feb 2015 00:23:51 +0100 Subject: [PATCH 009/121] starting fillet/chamfer (bzr r13645.1.15) --- src/2geom/satellite.h | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.h | 1 - src/live_effects/parameter/array.h | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 06b4a1dd69..a83de5af25 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -145,7 +145,7 @@ class Satellite static const std::map GcharMapToSatelliteType; - static double getOpositeTime(Geom::D2 SBasisCurve, double time); + double getOpositeTime(Geom::D2 SBasisCurve); private: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index df9de81b75..b34cd87a1a 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 94a2bd2b3b..2c0dfcaab8 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 c99777b08b..8145d62a38 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(); -- GitLab From a230b9d6684f01ded46fd530ba0cc74ce9696e2d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:53:20 +0100 Subject: [PATCH 010/121] Basic filleting using pointwise (bzr r13645.1.16) --- src/2geom/pointwise.cpp | 7 +- src/2geom/pointwise.h | 2 +- src/2geom/satellite.cpp | 103 ++ 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 --- .../dialog/lpe-fillet-chamfer-properties.cpp | 300 ------ src/ui/dialog/lpe-fillet-chamfer-properties.h | 115 --- 10 files changed, 190 insertions(+), 1472 deletions(-) create mode 100644 src/2geom/satellite.cpp delete mode 100644 src/live_effects/parameter/filletchamferpointarray.cpp delete mode 100644 src/live_effects/parameter/filletchamferpointarray.h diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 5cbccbca99..d7d5afc631 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -41,12 +41,17 @@ Pointwise::Pointwise(Piecewise > pwd2, std::vector -Pointwise::findSatellites(int A) const +Pointwise::findSatellites(int A, int B) const { std::vector ret; + int counter = 0; for(unsigned i = 0; i < _satellites.size(); i++){ if(_satellites[i].first == A){ + if(counter >= B && B != -1){ + return ret; + } ret.push_back(_satellites[i].second); + counter++; } } return ret; diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 6e9c8840ba..d48321832d 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -62,7 +62,7 @@ class Pointwise Pointwise(){}; Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); - std::vector findSatellites(int A) const; + std::vector findSatellites(int A, int B = -1) const; Pointwise recalculate_for_new_pwd2(Piecewise > A); Pointwise pwd2_reverse(int index); Pointwise pwd2_append(int index); diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp new file mode 100644 index 0000000000..b8ddd040b2 --- /dev/null +++ b/src/2geom/satellite.cpp @@ -0,0 +1,103 @@ +/** + * \file + * \brief Satellite + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + */ + +#include <2geom/satellite.h> +#include <2geom/curve.h> +#include <2geom/nearest-point.h> +#include <2geom/sbasis-geometric.h> + + +namespace Geom { + +Satellite::Satellite(){}; + +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double size, double time) + : _satellitetype(satellitetype), _isTime(isTime), _active(active), _hasMirror(hasMirror), _hidden(hidden), _size(size), _time(time){}; + +Satellite::~Satellite() {}; + +void +Satellite::setPosition(Geom::Point p, Geom::D2 d2_in){ + _time = Geom::nearest_point(p, d2_in); + if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, _time); + _size = Geom::length(u, 0.001); + } else { + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + _size = (_time * lenghtPart); + } +} + +Geom::Point +Satellite::getPosition(Geom::D2 d2_in){ + return d2_in.valueAt(_time); +} + +double +Satellite::getOpositeTime(Geom::D2 d2_in){ + double t = 0; + if(_size == 0){ + return 1; + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + double size = lenghtPart - _size; + if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - size); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } else { + if (size < lenghtPart && lenghtPart != 0) { + t = size / lenghtPart; + } + } + return t; +} + +} // end namespace Geom + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 6b004e1dfa..3af27a2201 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 b34cd87a1a..3b1b1697c7 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 33c6b06737..c9f40f7d11 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 2ebe11b4b0..0000000000 --- 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 6e5cce3536..0000000000 --- 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 diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index b318933a75..e69de29bb2 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -1,300 +0,0 @@ -/** - * From the code of Liam P.White from his Power Stroke Knot dialog - * - * Released under GNU GPL. Read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#if GLIBMM_DISABLE_DEPRECATED &&HAVE_GLIBMM_THREADS_H -#include -#endif - -#include -#include "lpe-fillet-chamfer-properties.h" -#include -#include -#include -#include "inkscape.h" -#include "desktop.h" -#include "document.h" -#include "document-undo.h" -#include "layer-manager.h" -#include "message-stack.h" - -#include "sp-object.h" -#include "sp-item.h" -#include "verbs.h" -#include "selection.h" -#include "selection-chemistry.h" -#include "ui/icon-names.h" -#include "ui/widget/imagetoggler.h" -#include "util/units.h" -#include - -//#include "event-context.h" - -namespace Inkscape { -namespace UI { -namespace Dialogs { - -FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() - : _desktop(NULL), _knotpoint(NULL), _position_visible(false) -{ - Gtk::Box *mainVBox = get_vbox(); - mainVBox->set_homogeneous(false); - _layout_table.set_spacings(4); - _layout_table.resize(3, 3); - - // Layer name widgets - _fillet_chamfer_position_numeric.set_digits(4); - _fillet_chamfer_position_numeric.set_increments(1,1); - //todo: get tha max aloable infinity freeze the widget - _fillet_chamfer_position_numeric.set_range(0., 999999999999999999.); - - _fillet_chamfer_position_label.set_label(_("Radius (pixels):")); - _fillet_chamfer_position_label.set_alignment(1.0, 0.5); - - _layout_table.attach(_fillet_chamfer_position_label, 0, 1, 0, 1, Gtk::FILL, - Gtk::FILL); - _layout_table.attach(_fillet_chamfer_position_numeric, 1, 2, 0, 1, - Gtk::FILL | Gtk::EXPAND, Gtk::FILL); - _fillet_chamfer_chamfer_subdivisions.set_digits(0); - _fillet_chamfer_chamfer_subdivisions.set_increments(1,1); - //todo: get tha max aloable infinity freeze the widget - _fillet_chamfer_chamfer_subdivisions.set_range(0, 999999999999999999.0); - - _fillet_chamfer_chamfer_subdivisions_label.set_label(_("Chamfer subdivisions:")); - _fillet_chamfer_chamfer_subdivisions_label.set_alignment(1.0, 0.5); - - _layout_table.attach(_fillet_chamfer_chamfer_subdivisions_label, 0, 1, 1, 2, Gtk::FILL, - Gtk::FILL); - _layout_table.attach(_fillet_chamfer_chamfer_subdivisions, 1, 2, 1, 2, - Gtk::FILL | Gtk::EXPAND, Gtk::FILL); - _fillet_chamfer_type_fillet.set_label(_("Fillet")); - _fillet_chamfer_type_fillet.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_inverse_fillet.set_label(_("Inverse fillet")); - _fillet_chamfer_type_inverse_fillet.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_chamfer.set_label(_("Chamfer")); - _fillet_chamfer_type_chamfer.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_inverse_chamfer.set_label(_("Inverse chamfer")); - _fillet_chamfer_type_inverse_chamfer.set_group(_fillet_chamfer_type_group); - - - mainVBox->pack_start(_layout_table, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_fillet, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_inverse_fillet, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_chamfer, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_inverse_chamfer, true, true, 4); - - // Buttons - _close_button.set_use_stock(true); - _close_button.set_label(Gtk::Stock::CANCEL.id); - _close_button.set_can_default(); - - _apply_button.set_use_underline(true); - _apply_button.set_can_default(); - - _close_button.signal_clicked() - .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)); - _apply_button.signal_clicked() - .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_apply)); - - signal_delete_event().connect(sigc::bind_return( - sigc::hide(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)), - true)); - - add_action_widget(_close_button, Gtk::RESPONSE_CLOSE); - add_action_widget(_apply_button, Gtk::RESPONSE_APPLY); - - _apply_button.grab_default(); - - show_all_children(); - - set_focus(_fillet_chamfer_position_numeric); -} - -FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() -{ - - _set_desktop(NULL); -} - -void FilletChamferPropertiesDialog::showDialog( - SPDesktop *desktop, Geom::Point knotpoint, - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt, - const gchar *unit, - bool use_distance, - bool aprox_radius, - Glib::ustring const * documentUnit) -{ - FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); - - dialog->_set_desktop(desktop); - dialog->_set_unit(unit); - dialog->_set_use_distance(use_distance); - dialog->_set_aprox(aprox_radius); - dialog->_set_document_unit(documentUnit); - dialog->_set_knot_point(knotpoint); - dialog->_set_pt(pt); - - dialog->set_title(_("Modify Fillet-Chamfer")); - dialog->_apply_button.set_label(_("_Modify")); - - dialog->set_modal(true); - desktop->setWindowTransient(dialog->gobj()); - dialog->property_destroy_with_parent() = true; - - dialog->show(); - dialog->present(); -} - -void FilletChamferPropertiesDialog::_apply() -{ - double d_width; - double d_pos = _fillet_chamfer_position_numeric.get_value(); - if (d_pos) { - if (_fillet_chamfer_type_fillet.get_active() == true) { - d_width = 1; - } else if (_fillet_chamfer_type_inverse_fillet.get_active() == true) { - d_width = 2; - } else if (_fillet_chamfer_type_inverse_chamfer.get_active() == true) { - d_width = _fillet_chamfer_chamfer_subdivisions.get_value() + 4000; - } else { - d_width = _fillet_chamfer_chamfer_subdivisions.get_value() + 3000; - } - if (_flexible) { - if (d_pos > 99.99999 || d_pos < 0) { - d_pos = 0; - } - d_pos = _index + (d_pos / 100); - } else { - d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, *document_unit); - d_pos = d_pos * -1; - } - _knotpoint->knot_set_offset(Geom::Point(d_pos, d_width)); - } - _close(); -} - -void FilletChamferPropertiesDialog::_close() -{ - _set_desktop(NULL); - destroy_(); - Glib::signal_idle().connect( - sigc::bind_return( - sigc::bind(sigc::ptr_fun(&::operator delete), this), - false - ) - ); -} - -bool FilletChamferPropertiesDialog::_handleKeyEvent(GdkEventKey * /*event*/) -{ - return false; -} - -void FilletChamferPropertiesDialog::_handleButtonEvent(GdkEventButton *event) -{ - if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { - _apply(); - } -} - -void FilletChamferPropertiesDialog::_set_knot_point(Geom::Point knotpoint) -{ - double position; - std::string distance_or_radius = std::string(_("Radius")); - if(aprox){ - distance_or_radius = std::string(_("Radius approximated")); - } - if(use_distance){ - distance_or_radius = std::string(_("Knot distance")); - } - if (knotpoint.x() > 0) { - double intpart; - position = modf(knotpoint[Geom::X], &intpart) * 100; - _flexible = true; - _index = intpart; - _fillet_chamfer_position_label.set_label(_("Position (%):")); - } else { - _flexible = false; - std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, unit); - _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); - position = knotpoint[Geom::X] * -1; - - position = Inkscape::Util::Quantity::convert(position, *document_unit, unit); - } - _fillet_chamfer_position_numeric.set_value(position); - if (knotpoint.y() == 1) { - _fillet_chamfer_type_fillet.set_active(true); - } else if (knotpoint.y() == 2) { - _fillet_chamfer_type_inverse_fillet.set_active(true); - } else if (knotpoint.y() >= 3000 && knotpoint.y() < 4000) { - _fillet_chamfer_chamfer_subdivisions.set_value(knotpoint.y() - 3000); - _fillet_chamfer_type_chamfer.set_active(true); - } else if (knotpoint.y() >= 4000 && knotpoint.y() < 5000) { - _fillet_chamfer_chamfer_subdivisions.set_value(knotpoint.y() - 4000); - _fillet_chamfer_type_inverse_chamfer.set_active(true); - } -} - -void FilletChamferPropertiesDialog::_set_pt( - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt) -{ - _knotpoint = const_cast< - Inkscape::LivePathEffect::FilletChamferPointArrayParamKnotHolderEntity *>( - pt); -} - -void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring const *abbr) -{ - document_unit = abbr; -} - -void FilletChamferPropertiesDialog::_set_use_distance(bool use_knot_distance) -{ - use_distance = use_knot_distance; -} - -void FilletChamferPropertiesDialog::_set_aprox(bool aprox_radius) -{ - aprox = aprox_radius; -} - -void FilletChamferPropertiesDialog::_set_desktop(SPDesktop *desktop) -{ - if (desktop) { - Inkscape::GC::anchor(desktop); - } - if (_desktop) { - Inkscape::GC::release(_desktop); - } - _desktop = desktop; -} - -} // namespace -} // namespace -} // namespace - -/* - 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:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 3807e98c8c..e69de29bb2 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -1,115 +0,0 @@ -/** - * - * From the code of Liam P.White from his Power Stroke Knot dialog - * - * Released under GNU GPL. Read the file 'COPYING' for more information - */ - -#ifndef INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H -#define INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H - -#include <2geom/point.h> -#include -#include "live_effects/parameter/filletchamferpointarray.h" - -class SPDesktop; - -namespace Inkscape { -namespace UI { -namespace Dialogs { - -class FilletChamferPropertiesDialog : public Gtk::Dialog { -public: - FilletChamferPropertiesDialog(); - virtual ~FilletChamferPropertiesDialog(); - - Glib::ustring getName() const { - return "LayerPropertiesDialog"; - } - - static void showDialog(SPDesktop *desktop, Geom::Point knotpoint, - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt, - const gchar *unit, - bool use_distance, - bool aprox_radius, - Glib::ustring const * documentUnit); - -protected: - - SPDesktop *_desktop; - Inkscape::LivePathEffect::FilletChamferPointArrayParamKnotHolderEntity * - _knotpoint; - - Gtk::Label _fillet_chamfer_position_label; - Gtk::SpinButton _fillet_chamfer_position_numeric; - Gtk::RadioButton::Group _fillet_chamfer_type_group; - Gtk::RadioButton _fillet_chamfer_type_fillet; - Gtk::RadioButton _fillet_chamfer_type_inverse_fillet; - Gtk::RadioButton _fillet_chamfer_type_chamfer; - Gtk::RadioButton _fillet_chamfer_type_inverse_chamfer; - Gtk::Label _fillet_chamfer_chamfer_subdivisions_label; - Gtk::SpinButton _fillet_chamfer_chamfer_subdivisions; - - Gtk::Table _layout_table; - bool _position_visible; - double _index; - - Gtk::Button _close_button; - Gtk::Button _apply_button; - - sigc::connection _destroy_connection; - - static FilletChamferPropertiesDialog &_instance() { - static FilletChamferPropertiesDialog instance; - return instance; - } - - void _set_desktop(SPDesktop *desktop); - void _set_pt(const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt); - void _set_unit(const gchar *abbr); - void _set_document_unit(Glib::ustring const * abbr); - void _set_use_distance(bool use_knot_distance); - void _set_aprox(bool aprox_radius); - void _apply(); - void _close(); - bool _flexible; - const gchar *unit; - Glib::ustring const * document_unit; - bool use_distance; - bool aprox; - void _set_knot_point(Geom::Point knotpoint); - void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); - - bool _handleKeyEvent(GdkEventKey *event); - void _handleButtonEvent(GdkEventButton *event); - - friend class Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity; - -private: - FilletChamferPropertiesDialog( - FilletChamferPropertiesDialog const &); // no copy - FilletChamferPropertiesDialog &operator=( - FilletChamferPropertiesDialog const &); // no assign -}; - -} // namespace -} // namespace -} // namespace - -#endif //INKSCAPE_DIALOG_LAYER_PROPERTIES_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:fileencoding=utf-8:textwidth=99 -// : -- GitLab From eae224916a20ea75f80471af2df057e7e74b0c9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:59:45 +0100 Subject: [PATCH 011/121] reducing size in pointwise LPE data (bzr r13645.1.18) --- src/2geom/satellite-enum.h | 10 +++++----- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/2geom/satellite-enum.h b/src/2geom/satellite-enum.h index 474e985479..bcd8d1bb33 100644 --- a/src/2geom/satellite-enum.h +++ b/src/2geom/satellite-enum.h @@ -16,11 +16,11 @@ namespace Geom { enum SatelliteType { - FILLET=0, - INVERSE_FILLET, - CHAMFER, - INVERSE_CHAMFER, - INVALID_SATELLITE // This must be last) + F=0, //Fillet + IF, //Inverse Fillet + C, //Chamfer + IC, //Inverse Chamfer + KO // Invalid Satellite) }; /* TODO maybe is best do next by bimap diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3b1b1697c7..e9d9a21b17 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 { -- GitLab From aa9e36cd93c4f71ff8eb0a6fc24d46933fdf7d14 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 22:06:37 +0100 Subject: [PATCH 012/121] fixed some bugs (bzr r13645.1.19) --- src/2geom/satellite.h | 4 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index a83de5af25..7b524f9127 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -56,7 +56,7 @@ class Satellite void setSatelliteType(gchar const * A) { - std::map GcharMapToSatelliteType = boost::assign::map_list_of("FILLET", FILLET)("INVERSE_FILLET", INVERSE_FILLET)("CHAMFER",CHAMFER)("INVERSE_CHAMFER",INVERSE_CHAMFER)("INVALID_SATELLITE",INVALID_SATELLITE); + std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); _satellitetype = GcharMapToSatelliteType[A]; } @@ -97,7 +97,7 @@ class Satellite gchar const * getSatelliteTypeGchar() const { - std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(FILLET, "FILLET")(INVERSE_FILLET, "INVERSE_FILLET")(CHAMFER,"CHAMFER")(INVERSE_CHAMFER,"INVERSE_CHAMFER")(INVALID_SATELLITE,"INVALID_SATELLITE"); + std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); return SatelliteTypeToGcharMap[_satellitetype]; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index e9d9a21b17..0ef8b5a0e4 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(); -- GitLab From 83e726c8fb391f0cbbccc9b286bfecefc730dbc7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 Feb 2015 23:16:39 +0100 Subject: [PATCH 013/121] Added flexible/fixed to fillet chamfer and fix bugs (bzr r13645.1.20) --- src/2geom/pointwise.cpp | 5 ++ src/2geom/pointwise.h | 3 + src/2geom/satellite.cpp | 89 ++++++++++++++++++--- src/2geom/satellite.h | 6 +- src/live_effects/lpe-fillet-chamfer.cpp | 100 ++++++++++++++++-------- src/live_effects/lpe-fillet-chamfer.h | 3 + src/live_effects/parameter/array.h | 10 +-- 7 files changed, 166 insertions(+), 50 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index d7d5afc631..aa1620e8ad 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -40,6 +40,11 @@ Pointwise::Pointwise(Piecewise > pwd2, std::vector > +Pointwise::getSatellites(){ + return _satellites; +} + std::vector Pointwise::findSatellites(int A, int B) const { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index d48321832d..e7646d96c2 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -63,6 +63,8 @@ class Pointwise Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); std::vector findSatellites(int A, int B = -1) const; + std::vector > getSatellites(); + Pointwise recalculate_for_new_pwd2(Piecewise > A); Pointwise pwd2_reverse(int index); Pointwise pwd2_append(int index); @@ -71,6 +73,7 @@ class Pointwise Pointwise pwd2_del(int index); Pointwise satellite_add(int index,Satellite sat); Pointwise satellite_del(int index,Satellite sat); + private: Piecewise > _pwd2; diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index b8ddd040b2..9a2fa0a10a 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -46,7 +46,14 @@ Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool Satellite::~Satellite() {}; void -Satellite::setPosition(Geom::Point p, Geom::D2 d2_in){ +Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +{ + if(!d2_in.isFinite() || d2_in.isZero()){ + _time = 0; + _size = 0; + return; + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); _time = Geom::nearest_point(p, d2_in); if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; @@ -55,23 +62,24 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in){ u = Geom::portion(u, 0.0, _time); _size = Geom::length(u, 0.001); } else { - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); _size = (_time * lenghtPart); } + if(_time > 0.998){ + _time = 1; + } } -Geom::Point -Satellite::getPosition(Geom::D2 d2_in){ - return d2_in.valueAt(_time); -} - double -Satellite::getOpositeTime(Geom::D2 d2_in){ +Satellite::getOpositeTime(Geom::D2 d2_in) +{ + if(!d2_in.isFinite() || d2_in.isZero()){ + return 1; + } double t = 0; + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); if(_size == 0){ return 1; } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); double size = lenghtPart - _size; if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; @@ -86,9 +94,72 @@ Satellite::getOpositeTime(Geom::D2 d2_in){ t = size / lenghtPart; } } + if(_time > 0.999){ + _time = 1; + } return t; } +void +Satellite::updateSizeTime(Geom::D2 d2_in) +{ + if(!d2_in.isFinite() || d2_in.isZero()){ + _time = 0; + _size = 0; + return; + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + if(!_isTime){ + if (_size != 0) { + if(lenghtPart <= _size){ + _time = 1; + _size = lenghtPart; + } else if (d2_in[0].degreesOfFreedom() != 2) { + Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - _size); + if (t_roots.size() > 0) { + _time = t_roots[0]; + } + } else { + if (_size < lenghtPart && lenghtPart != 0) { + _time = _size / lenghtPart; + } + } + } else { + _time = 0; + } + } else { + if (_time != 0) { + if (d2_in[0].degreesOfFreedom() != 2) { + Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = portion(u, 0, _time); + _size = length(u, 0.001); + } else { + lenghtPart = length(d2_in, EPSILON); + _size = _time * lenghtPart; + } + } else { + _size = 0; + } + } + if(_time > 0.999){ + _time = 1; + } +} + +Geom::Point +Satellite::getPosition(Geom::D2 d2_in){ + if(!d2_in.isFinite() || d2_in.isZero()){ + return Geom::Point(9999999999.0,9999999999.0); + } + updateSizeTime(d2_in); + return d2_in.valueAt(_time); +} + } // end namespace Geom /* diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 7b524f9127..105297f489 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -131,11 +131,7 @@ class Satellite return _time; } - double getTime(Geom::D2 curve) const - { - //todo make the process - return _time; - } + void updateSizeTime(Geom::D2 d2_in); void setPosition(Geom::Point p, Geom::D2 curve); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0ef8b5a0e4..73c504deb2 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 2c0dfcaab8..f5c4f14ead 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 8145d62a38..e9775da24b 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 << "*"; -- GitLab From 7086c79862b2d9bcd9f12f078854ad7e117d2cde Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Feb 2015 22:52:58 +0100 Subject: [PATCH 014/121] fixing write knot (bzr r13645.1.22) --- src/live_effects/lpe-fillet-chamfer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 73c504deb2..2354aa5ed1 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(); -- GitLab From 43c5af94d24cd408f7b369545e96cf9192f6ba90 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Feb 2015 13:13:49 +0100 Subject: [PATCH 015/121] improving code (bzr r13645.1.24) --- src/2geom/satellite.cpp | 123 +++++++++--------------- src/2geom/satellite.h | 10 +- src/live_effects/lpe-fillet-chamfer.cpp | 10 +- src/live_effects/parameter/array.cpp | 8 +- src/live_effects/parameter/array.h | 8 +- 5 files changed, 56 insertions(+), 103 deletions(-) diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 9a2fa0a10a..5b362d87fc 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -45,119 +45,86 @@ Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool Satellite::~Satellite() {}; -void -Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +double +Satellite::toTime(double A,Geom::D2 d2_in) { if(!d2_in.isFinite() || d2_in.isZero()){ _time = 0; _size = 0; - return; + return 0; } + double t = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - _time = Geom::nearest_point(p, d2_in); - if (d2_in[0].degreesOfFreedom() != 2) { + if (A > lenghtPart) { + t = 1; + } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); u.push(d2_in, 1); - u = Geom::portion(u, 0.0, _time); - _size = Geom::length(u, 0.001); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } } else { - _size = (_time * lenghtPart); + //to be sure + if (lenghtPart != 0) { + t = A / lenghtPart; + } } - if(_time > 0.998){ - _time = 1; + if(t > 0.998){ + t = 1; } + return t; } double -Satellite::getOpositeTime(Geom::D2 d2_in) +Satellite::toSize(double A,Geom::D2 d2_in) { if(!d2_in.isFinite() || d2_in.isZero()){ - return 1; + _time = 0; + _size = 0; + return 0; } - double t = 0; + double s = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if(_size == 0){ - return 1; - } - double size = lenghtPart - _size; if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - size); - if (t_roots.size() > 0) { - t = t_roots[0]; - } + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); } else { - if (size < lenghtPart && lenghtPart != 0) { - t = size / lenghtPart; - } + s = (A * lenghtPart); } - if(_time > 0.999){ - _time = 1; - } - return t; + return s; } -void -Satellite::updateSizeTime(Geom::D2 d2_in) +double +Satellite::getOpositeTime(Geom::D2 d2_in) { - if(!d2_in.isFinite() || d2_in.isZero()){ - _time = 0; - _size = 0; - return; + double s = getSize(); + if(s == 0){ + return 1; } double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if(!_isTime){ - if (_size != 0) { - if(lenghtPart <= _size){ - _time = 1; - _size = lenghtPart; - } else if (d2_in[0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - _size); - if (t_roots.size() > 0) { - _time = t_roots[0]; - } - } else { - if (_size < lenghtPart && lenghtPart != 0) { - _time = _size / lenghtPart; - } - } - } else { - _time = 0; - } - } else { - if (_time != 0) { - if (d2_in[0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = portion(u, 0, _time); - _size = length(u, 0.001); - } else { - lenghtPart = length(d2_in, EPSILON); - _size = _time * lenghtPart; - } - } else { - _size = 0; - } - } - if(_time > 0.999){ - _time = 1; - } + double size = lenghtPart - s; + return toTime(size, d2_in); } Geom::Point Satellite::getPosition(Geom::D2 d2_in){ - if(!d2_in.isFinite() || d2_in.isZero()){ - return Geom::Point(9999999999.0,9999999999.0); + double t = getTime(); + if(!_isTime){ + t = toTime(getSize(), d2_in); } - updateSizeTime(d2_in); - return d2_in.valueAt(_time); + return d2_in.valueAt(t); +} + +void +Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +{ + setTime(Geom::nearest_point(p, d2_in)); + setSize(toSize(getTime(),d2_in)); } } // end namespace Geom diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 105297f489..dd8e4d9d0a 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -79,7 +79,6 @@ class Satellite { _hidden = A; } - void setTime(double A) { _time = A; @@ -131,18 +130,13 @@ class Satellite return _time; } - void updateSizeTime(Geom::D2 d2_in); - void setPosition(Geom::Point p, Geom::D2 curve); Geom::Point getPosition(Geom::D2 curve); - static const std::map SatelliteTypeToGcharMap; - - static const std::map GcharMapToSatelliteType; - double getOpositeTime(Geom::D2 SBasisCurve); - + double toSize(double A,Geom::D2 d2_in); + double toTime(double A,Geom::D2 d2_in); private: SatelliteType _satellitetype; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2354aa5ed1..39acdca808 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 473b561d26..6dad9fcc80 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 e9775da24b..ff406d7922 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 << "*"; -- GitLab From 00d08a0f4bca11e775bbacf3d512676a0493c1a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 01:18:02 +0100 Subject: [PATCH 016/121] adding mirror knot (bzr r13645.1.25) --- src/2geom/pointwise.cpp | 61 ++++++++++++++++++ src/2geom/pointwise.h | 9 ++- src/2geom/satellite.cpp | 42 ++++++++----- src/2geom/satellite.h | 28 ++++----- src/live_effects/lpe-fillet-chamfer.cpp | 25 +++++--- src/live_effects/parameter/array.cpp | 10 +-- src/live_effects/parameter/array.h | 4 +- .../parameter/satellitepairarray.cpp | 62 +++++++++++++++++-- .../parameter/satellitepairarray.h | 11 ++-- 9 files changed, 195 insertions(+), 57 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index aa1620e8ad..bc468343cc 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -45,6 +45,67 @@ Pointwise::getSatellites(){ return _satellites; } +void +Pointwise::setSatellites(std::vector > sat){ + _satellites = sat; +} + +Piecewise > +Pointwise::getPwd2(){ + return _pwd2; +} + +void +Pointwise::setPwd2(Piecewise > pwd2_in){ + _pwd2 = pwd2_in; +} + +boost::optional > +Pointwise::getCurveIn(std::pair sat){ + //curve out = sat.first; + std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_from_piecewise(_pwd2, 0.001)); + int counterTotal = 0; + 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::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(); + } + } + Geom::Path::const_iterator curve_end = curve_endit; + --curve_end; + int counter = 0; + while (curve_it1 != curve_endit) { + if(counterTotal == sat.first){ + if (counter==0) { + if (path_it->closed()) { + return (*curve_end).toSBasis(); + } else { + return boost::none; + } + } else { + return (*path_it)[counter - 1].toSBasis(); + } + } + ++curve_it1; + counter++; + counterTotal++; + } + } + return boost::none; +} + std::vector Pointwise::findSatellites(int A, int B) const { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index e7646d96c2..5937264ad9 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -50,6 +50,10 @@ #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> #include <2geom/satellite.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/path.h> +#include "helper/geom.h" +#include namespace Geom { /** @@ -64,7 +68,10 @@ class Pointwise virtual ~Pointwise(); std::vector findSatellites(int A, int B = -1) const; std::vector > getSatellites(); - + void setSatellites(std::vector > sat); + Piecewise > getPwd2(); + void setPwd2(Piecewise > pwd2_in); + boost::optional > getCurveIn(std::pair sat); Pointwise recalculate_for_new_pwd2(Piecewise > A); Pointwise pwd2_reverse(int index); Pointwise pwd2_append(int index); diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 5b362d87fc..21361147cf 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,17 +40,16 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double size, double time) - : _satellitetype(satellitetype), _isTime(isTime), _active(active), _hasMirror(hasMirror), _hidden(hidden), _size(size), _time(time){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double ammount, double angle) + : _satellitetype(satellitetype), _isTime(isTime), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; Satellite::~Satellite() {}; double Satellite::toTime(double A,Geom::D2 d2_in) { - if(!d2_in.isFinite() || d2_in.isZero()){ - _time = 0; - _size = 0; + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + _ammount = 0; return 0; } double t = 0; @@ -80,9 +79,8 @@ Satellite::toTime(double A,Geom::D2 d2_in) double Satellite::toSize(double A,Geom::D2 d2_in) { - if(!d2_in.isFinite() || d2_in.isZero()){ - _time = 0; - _size = 0; + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + _ammount = 0; return 0; } double s = 0; @@ -102,7 +100,10 @@ Satellite::toSize(double A,Geom::D2 d2_in) double Satellite::getOpositeTime(Geom::D2 d2_in) { - double s = getSize(); + double s = getAmmount(); + if(getIsTime()){ + s = toSize(s, d2_in); + } if(s == 0){ return 1; } @@ -111,20 +112,29 @@ Satellite::getOpositeTime(Geom::D2 d2_in) return toTime(size, d2_in); } +double +Satellite::getTime(Geom::D2 d2_in){ + double t = getAmmount(); + if(!getIsTime()){ + t = toTime(t, d2_in); + } + return t; +} + + Geom::Point Satellite::getPosition(Geom::D2 d2_in){ - double t = getTime(); - if(!_isTime){ - t = toTime(getSize(), d2_in); - } - return d2_in.valueAt(t); + return d2_in.valueAt(getTime(d2_in)); } void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { - setTime(Geom::nearest_point(p, d2_in)); - setSize(toSize(getTime(),d2_in)); + double A = Geom::nearest_point(p, d2_in); + if(!getIsTime()){ + A = toSize(A, d2_in); + } + setAmmount(A); } } // end namespace Geom diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index dd8e4d9d0a..c66770bb69 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double size, double time); + Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double ammount, double angle); virtual ~Satellite(); @@ -79,14 +79,14 @@ class Satellite { _hidden = A; } - void setTime(double A) + void setAmmount(double A) { - _time = A; + _ammount = A; } - void setSize(double A) + void setAngle(double A) { - _size = A; + _angle = A; } SatelliteType getSatelliteType() const @@ -120,23 +120,23 @@ class Satellite return _hidden; } - double getSize() const + double getAmmount() const { - return _size; + return _ammount; } - double getTime() const + double getAngle() const { - return _time; + return _angle; } - void setPosition(Geom::Point p, Geom::D2 curve); - + void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 curve); - + double getTime(Geom::D2 d2_in); double getOpositeTime(Geom::D2 SBasisCurve); double toSize(double A,Geom::D2 d2_in); double toTime(double A,Geom::D2 d2_in); + private: SatelliteType _satellitetype; @@ -144,8 +144,8 @@ class Satellite bool _active; bool _hasMirror; bool _hidden; - double _size; - double _time; + double _ammount; + double _angle; }; } // end namespace Geom diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 39acdca808..41c6a7090a 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 6dad9fcc80..2c3d823a53 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 ff406d7922..1a58231997 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 ff1924829c..dde844fd15 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; }; -- GitLab From f77b5496f69a5391bc548be95c85659539a92fe9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 23:23:56 +0100 Subject: [PATCH 017/121] added mirror knots (bzr r13645.1.26) --- src/2geom/pointwise.cpp | 35 ++++++++++++++ src/2geom/pointwise.h | 2 + src/2geom/satellite.cpp | 10 ++-- src/2geom/satellite.h | 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 ++ .../parameter/satellitepairarray.cpp | 35 +++++++++++++- 9 files changed, 145 insertions(+), 30 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index bc468343cc..3c359eddcd 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -123,6 +123,41 @@ Pointwise::findSatellites(int A, int B) const return ret; } +std::vector +Pointwise::findClosingSatellites(int A, int B) const +{ + std::vector ret; + bool finded = false; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(finded && _satellites[i].second.getIsStart()){ + return ret; + } + if(finded && _satellites[i].second.getIsClosing()){ + ret.push_back(_satellites[i].second); + } + if(_satellites[i].first == A){ + finded = true; + } + } + return ret; +} + +std::vector +Pointwise::findPeviousSatellites(int A, int B) const +{ + std::vector ret; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(_satellites[i].first == A){ + if(!_satellites[i].second.getIsStart()){ + ret = findSatellites(_satellites[i-1].first, B); + } else { + ret = findClosingSatellites(_satellites[i].first, B); + } + } + } + return ret; +} + } /* Local Variables: diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 5937264ad9..c7426dc9d4 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -67,6 +67,8 @@ class Pointwise Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); std::vector findSatellites(int A, int B = -1) const; + std::vector findPeviousSatellites(int A, int B) const; + std::vector findClosingSatellites(int A, int B) const; std::vector > getSatellites(); void setSatellites(std::vector > sat); Piecewise > getPwd2(); diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 21361147cf..9c253523e4 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,8 +40,8 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double ammount, double angle) - : _satellitetype(satellitetype), _isTime(isTime), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle) + : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; Satellite::~Satellite() {}; @@ -98,12 +98,8 @@ Satellite::toSize(double A,Geom::D2 d2_in) } double -Satellite::getOpositeTime(Geom::D2 d2_in) +Satellite::getOpositeTime(double s, Geom::D2 d2_in) { - double s = getAmmount(); - if(getIsTime()){ - s = toSize(s, d2_in); - } if(s == 0){ return 1; } diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index c66770bb69..7581e6e345 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double ammount, double angle); + Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle); virtual ~Satellite(); @@ -65,6 +65,16 @@ class Satellite _isTime = A; } + void setIsClosing(bool A) + { + _isClosing = A; + } + + void setIsStart(bool A) + { + _isStart = A; + } + void setActive(bool A) { _active = A; @@ -105,6 +115,16 @@ class Satellite return _isTime; } + bool getIsClosing() const + { + return _isClosing; + } + + bool getIsStart() const + { + return _isStart; + } + bool getActive() const { return _active; @@ -133,7 +153,7 @@ class Satellite void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 curve); double getTime(Geom::D2 d2_in); - double getOpositeTime(Geom::D2 SBasisCurve); + double getOpositeTime(double A,Geom::D2 SBasisCurve); double toSize(double A,Geom::D2 d2_in); double toTime(double A,Geom::D2 d2_in); @@ -141,6 +161,8 @@ class Satellite SatelliteType _satellitetype; bool _isTime; + bool _isClosing; + bool _isStart; bool _active; bool _hasMirror; bool _hidden; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 41c6a7090a..d46d0f4ff5 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 f5c4f14ead..149a2d743d 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 2c3d823a53..c00cdd8dac 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 1a58231997..0be155f50f 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 e6f0c03f99..7a35df28f5 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]); -- GitLab From ef1da924221c3ab94e0c7bedf580f4a930459aa4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 00:11:38 +0100 Subject: [PATCH 018/121] added more fillet/chamfer properties (bzr r13645.1.28) --- src/2geom/satellite.h | 6 +- src/live_effects/lpe-fillet-chamfer.cpp | 312 +++++++++++++++--- src/live_effects/lpe-fillet-chamfer.h | 23 +- .../parameter/satellitepairarray.cpp | 5 +- 4 files changed, 298 insertions(+), 48 deletions(-) diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 7581e6e345..aa949a97cb 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -56,8 +56,8 @@ class Satellite void setSatelliteType(gchar const * A) { - std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); - _satellitetype = GcharMapToSatelliteType[A]; + std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + _satellitetype = GcharMapToSatelliteType.find(std::string(A))->second; } void setIsTime(bool A) @@ -107,7 +107,7 @@ class Satellite gchar const * getSatelliteTypeGchar() const { std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); - return SatelliteTypeToGcharMap[_satellitetype]; + return SatelliteTypeToGcharMap.at(_satellitetype); } bool getIsTime() const diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d46d0f4ff5..8023406980 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 149a2d743d..44c8b113f9 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 7a35df28f5..beda9ecbf6 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 { -- GitLab From 60327dd47f6bbbb0d30c13c905117bd8b3be5e5d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 23:54:42 +0100 Subject: [PATCH 019/121] added helper paths and fixed some bugs (bzr r13645.1.30) --- src/2geom/pointwise.cpp | 4 +- src/2geom/pointwise.h | 2 +- src/2geom/satellite.cpp | 9 ++ src/2geom/satellite.h | 1 + src/live_effects/lpe-fillet-chamfer.cpp | 66 +++++++------- src/live_effects/lpe-fillet-chamfer.h | 1 + .../parameter/satellitepairarray.cpp | 87 ++++++++++++++++++- .../parameter/satellitepairarray.h | 9 +- 8 files changed, 134 insertions(+), 45 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 3c359eddcd..0115ea1037 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -124,7 +124,7 @@ Pointwise::findSatellites(int A, int B) const } std::vector -Pointwise::findClosingSatellites(int A, int B) const +Pointwise::findClosingSatellites(int A) const { std::vector ret; bool finded = false; @@ -151,7 +151,7 @@ Pointwise::findPeviousSatellites(int A, int B) const if(!_satellites[i].second.getIsStart()){ ret = findSatellites(_satellites[i-1].first, B); } else { - ret = findClosingSatellites(_satellites[i].first, B); + ret = findClosingSatellites(_satellites[i].first); } } } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index c7426dc9d4..aa907d4984 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -68,7 +68,7 @@ class Pointwise virtual ~Pointwise(); std::vector findSatellites(int A, int B = -1) const; std::vector findPeviousSatellites(int A, int B) const; - std::vector findClosingSatellites(int A, int B) const; + std::vector findClosingSatellites(int A) const; std::vector > getSatellites(); void setSatellites(std::vector > sat); Piecewise > getPwd2(); diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 9c253523e4..c216595dc7 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -117,6 +117,15 @@ Satellite::getTime(Geom::D2 d2_in){ return t; } +double +Satellite::getSize(Geom::D2 d2_in){ + double s = getAmmount(); + if(getIsTime()){ + s = toSize(s, d2_in); + } + return s; +} + Geom::Point Satellite::getPosition(Geom::D2 d2_in){ diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index aa949a97cb..48be13cc49 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -152,6 +152,7 @@ class Satellite void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 curve); + double getSize(Geom::D2 d2_in); double getTime(Geom::D2 d2_in); double getOpositeTime(double A,Geom::D2 SBasisCurve); double toSize(double A,Geom::D2 d2_in); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 8023406980..a8e2ea6b89 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 44c8b113f9..c194d2eddb 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 beda9ecbf6..72a666dc22 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 dde844fd15..1ecc1fee6b 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; -- GitLab From 885ed9addb9a67398e74176fd541c3415c5f44d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 18:04:02 +0100 Subject: [PATCH 020/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a8e2ea6b89..786945cd02 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; } -- GitLab From 1db09cce6114c1b2d95ac77b00672caad0447b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 23:42:59 +0100 Subject: [PATCH 021/121] All features done, only need piecewise update function (bzr r13645.1.33) --- src/2geom/pointwise.cpp | 87 ++++- src/2geom/pointwise.h | 25 +- src/2geom/satellite.cpp | 4 +- src/2geom/satellite.h | 13 +- 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 +- .../parameter/satellitepairarray.cpp | 161 ++++++++- .../parameter/satellitepairarray.h | 12 +- .../dialog/lpe-fillet-chamfer-properties.cpp | 313 ++++++++++++++++++ src/ui/dialog/lpe-fillet-chamfer-properties.h | 118 +++++++ 12 files changed, 763 insertions(+), 117 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 0115ea1037..1d1c69ceec 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -30,23 +30,26 @@ */ #include <2geom/pointwise.h> +#include <2geom/ray.h> +#include <2geom/path-intersection.h> +#include namespace Geom { -Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) +Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) : _pwd2(pwd2), _satellites(satellites) { }; Pointwise::~Pointwise(){}; -std::vector > +std::vector > Pointwise::getSatellites(){ return _satellites; } void -Pointwise::setSatellites(std::vector > sat){ +Pointwise::setSatellites(std::vector > sat){ _satellites = sat; } @@ -60,11 +63,77 @@ Pointwise::setPwd2(Piecewise > pwd2_in){ _pwd2 = pwd2_in; } +double +Pointwise::rad_to_len(double A, std::pair satellite) +{ + double len = 0; + boost::optional > d2_in = 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; +} + +double +Pointwise::len_to_rad(double A, std::pair satellite) +{ + boost::optional > d2_in = 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); + Piecewise > u; + u.push_cut(0); + u.push((*d2_in), 1); + Geom::Curve * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Piecewise > u2; + u2.push_cut(0); + u2.push((d2_out), 1); + Geom::Curve * B = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Curve *knotCurve1 = A->portion(0, time_in); + Curve *knotCurve2 = B->portion(time_out, 1); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Ray ray2(d2_out.valueAt(0), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + 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); + double divisor = std::sin(angleBetween/2.0); + if(divisor > 0){ + return distanceArc/divisor; + } + } + return 0; +} + boost::optional > -Pointwise::getCurveIn(std::pair sat){ +Pointwise::getCurveIn(std::pair sat){ //curve out = sat.first; std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_from_piecewise(_pwd2, 0.001)); - int counterTotal = 0; + unsigned int counterTotal = 0; for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()){ continue; @@ -85,7 +154,7 @@ Pointwise::getCurveIn(std::pair sat){ } Geom::Path::const_iterator curve_end = curve_endit; --curve_end; - int counter = 0; + unsigned int counter = 0; while (curve_it1 != curve_endit) { if(counterTotal == sat.first){ if (counter==0) { @@ -107,7 +176,7 @@ Pointwise::getCurveIn(std::pair sat){ } std::vector -Pointwise::findSatellites(int A, int B) const +Pointwise::findSatellites(unsigned int A, int B) const { std::vector ret; int counter = 0; @@ -124,7 +193,7 @@ Pointwise::findSatellites(int A, int B) const } std::vector -Pointwise::findClosingSatellites(int A) const +Pointwise::findClosingSatellites(unsigned int A) const { std::vector ret; bool finded = false; @@ -143,7 +212,7 @@ Pointwise::findClosingSatellites(int A) const } std::vector -Pointwise::findPeviousSatellites(int A, int B) const +Pointwise::findPeviousSatellites(unsigned int A, int B) const { std::vector ret; for(unsigned i = 0; i < _satellites.size(); i++){ diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index aa907d4984..b6bd4c4fda 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -64,29 +64,32 @@ class Pointwise { public: Pointwise(){}; - Pointwise(Piecewise > pwd2, std::vector > satellites); + Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); - std::vector findSatellites(int A, int B = -1) const; - std::vector findPeviousSatellites(int A, int B) const; - std::vector findClosingSatellites(int A) const; - std::vector > getSatellites(); - void setSatellites(std::vector > sat); + std::vector findSatellites(unsigned int A, int B = -1) const; + std::vector findPeviousSatellites(unsigned int A, int B) const; + std::vector findClosingSatellites(unsigned int A) const; + double rad_to_len(double A, std::pair satellite); + double len_to_rad(double A, std::pair satellite); + std::vector > getSatellites(); + void setSatellites(std::vector > sat); Piecewise > getPwd2(); void setPwd2(Piecewise > pwd2_in); - boost::optional > getCurveIn(std::pair sat); + boost::optional > getCurveIn(std::pair sat); Pointwise recalculate_for_new_pwd2(Piecewise > A); + /* Pointwise pwd2_reverse(int index); Pointwise pwd2_append(int index); Pointwise pwd2_prepend(int index); Pointwise pwd2_add(int index); Pointwise pwd2_del(int index); - Pointwise satellite_add(int index,Satellite sat); - Pointwise satellite_del(int index,Satellite sat); - + Pointwise satellite_add(unsigned int index,Satellite sat); + Pointwise satellite_del(unsigned int index,Satellite sat); + */ private: Piecewise > _pwd2; - std::vector > _satellites; + std::vector > _satellites; }; diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index c216595dc7..22c3c8bed1 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,8 +40,8 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle) - : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle, unsigned int steps) + : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle), _steps(steps){}; Satellite::~Satellite() {}; diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 48be13cc49..4b07976201 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle); + Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle, unsigned int steps); virtual ~Satellite(); @@ -99,6 +99,11 @@ class Satellite _angle = A; } + void setSteps(int A) + { + _steps = A; + } + SatelliteType getSatelliteType() const { return _satellitetype; @@ -150,6 +155,11 @@ class Satellite return _angle; } + int getSteps() const + { + return _steps; + } + void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 curve); double getSize(Geom::D2 d2_in); @@ -169,6 +179,7 @@ class Satellite bool _hidden; double _ammount; double _angle; + unsigned int _steps; }; } // end namespace Geom diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 786945cd02..118a89eade 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 c194d2eddb..56db6305e7 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 c00cdd8dac..e4c480d934 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 0be155f50f..d28576fce9 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 72a666dc22..ffd04e14c8 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 1ecc1fee6b..21fb0fbd8f 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); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index e69de29bb2..fe0deba577 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -0,0 +1,313 @@ +/** + * From the code of Liam P.White from his Power Stroke Knot dialog + * + * Released under GNU GPL. Read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if GLIBMM_DISABLE_DEPRECATED &&HAVE_GLIBMM_THREADS_H +#include +#endif + +#include +#include "lpe-fillet-chamfer-properties.h" +#include +#include +#include +#include "inkscape.h" +#include "desktop.h" +#include "document.h" +#include "document-undo.h" +#include "layer-manager.h" +#include "message-stack.h" + +#include "sp-object.h" +#include "sp-item.h" +#include "verbs.h" +#include "selection.h" +#include "selection-chemistry.h" +#include "ui/icon-names.h" +#include "ui/widget/imagetoggler.h" +#include "util/units.h" +#include + +//#include "event-context.h" + +namespace Inkscape { +namespace UI { +namespace Dialogs { + +FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() + : _desktop(NULL), _knotpoint(NULL), _position_visible(false) +{ + Gtk::Box *mainVBox = get_vbox(); + mainVBox->set_homogeneous(false); + _layout_table.set_spacings(4); + _layout_table.resize(3, 3); + + // Layer name widgets + _fillet_chamfer_position_numeric.set_digits(4); + _fillet_chamfer_position_numeric.set_increments(1,1); + //todo: get tha max aloable infinity freeze the widget + _fillet_chamfer_position_numeric.set_range(0., 999999999999999999.); + + _fillet_chamfer_position_label.set_label(_("Radius (pixels):")); + _fillet_chamfer_position_label.set_alignment(1.0, 0.5); + + _layout_table.attach(_fillet_chamfer_position_label, 0, 1, 0, 1, Gtk::FILL, + Gtk::FILL); + _layout_table.attach(_fillet_chamfer_position_numeric, 1, 2, 0, 1, + Gtk::FILL | Gtk::EXPAND, Gtk::FILL); + _fillet_chamfer_chamfer_subdivisions.set_digits(0); + _fillet_chamfer_chamfer_subdivisions.set_increments(1,1); + //todo: get tha max aloable infinity freeze the widget + _fillet_chamfer_chamfer_subdivisions.set_range(1, 4294967295); + + _fillet_chamfer_chamfer_subdivisions_label.set_label(_("Chamfer subdivisions:")); + _fillet_chamfer_chamfer_subdivisions_label.set_alignment(1.0, 0.5); + + _layout_table.attach(_fillet_chamfer_chamfer_subdivisions_label, 0, 1, 1, 2, Gtk::FILL, + Gtk::FILL); + _layout_table.attach(_fillet_chamfer_chamfer_subdivisions, 1, 2, 1, 2, + Gtk::FILL | Gtk::EXPAND, Gtk::FILL); + _fillet_chamfer_type_fillet.set_label(_("Fillet")); + _fillet_chamfer_type_fillet.set_group(_fillet_chamfer_type_group); + _fillet_chamfer_type_inverse_fillet.set_label(_("Inverse fillet")); + _fillet_chamfer_type_inverse_fillet.set_group(_fillet_chamfer_type_group); + _fillet_chamfer_type_chamfer.set_label(_("Chamfer")); + _fillet_chamfer_type_chamfer.set_group(_fillet_chamfer_type_group); + _fillet_chamfer_type_inverse_chamfer.set_label(_("Inverse chamfer")); + _fillet_chamfer_type_inverse_chamfer.set_group(_fillet_chamfer_type_group); + + + mainVBox->pack_start(_layout_table, true, true, 4); + mainVBox->pack_start(_fillet_chamfer_type_fillet, true, true, 4); + mainVBox->pack_start(_fillet_chamfer_type_inverse_fillet, true, true, 4); + mainVBox->pack_start(_fillet_chamfer_type_chamfer, true, true, 4); + mainVBox->pack_start(_fillet_chamfer_type_inverse_chamfer, true, true, 4); + + // Buttons + _close_button.set_use_stock(true); + _close_button.set_label(Gtk::Stock::CANCEL.id); + _close_button.set_can_default(); + + _apply_button.set_use_underline(true); + _apply_button.set_can_default(); + + _close_button.signal_clicked() + .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)); + _apply_button.signal_clicked() + .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_apply)); + + signal_delete_event().connect(sigc::bind_return( + sigc::hide(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)), + true)); + + add_action_widget(_close_button, Gtk::RESPONSE_CLOSE); + add_action_widget(_apply_button, Gtk::RESPONSE_APPLY); + + _apply_button.grab_default(); + + show_all_children(); + + set_focus(_fillet_chamfer_position_numeric); +} + +FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() +{ + + _set_desktop(NULL); +} + +void FilletChamferPropertiesDialog::showDialog( + SPDesktop *desktop, double ammount, + const Inkscape::LivePathEffect:: + SatellitePairArrayParamKnotHolderEntity *pt, + const gchar *unit, + bool use_distance, + bool aprox_radius, + Glib::ustring const * documentUnit, + Geom::Satellite satellite) +{ + FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); + + dialog->_set_desktop(desktop); + dialog->_set_unit(unit); + dialog->_set_use_distance(use_distance); + dialog->_set_aprox(aprox_radius); + dialog->_set_document_unit(documentUnit); + dialog->_set_ammount(ammount); + dialog->_set_satellite(satellite); + dialog->_set_pt(pt); + + dialog->set_title(_("Modify Fillet-Chamfer")); + dialog->_apply_button.set_label(_("_Modify")); + + dialog->set_modal(true); + desktop->setWindowTransient(dialog->gobj()); + dialog->property_destroy_with_parent() = true; + + dialog->show(); + dialog->present(); +} + +void FilletChamferPropertiesDialog::_apply() +{ + + double d_pos = _fillet_chamfer_position_numeric.get_value(); + if (d_pos >= 0) { + if (_fillet_chamfer_type_fillet.get_active() == true) { + _satellite.setSatelliteType(Geom::F); + } else if (_fillet_chamfer_type_inverse_fillet.get_active() == true) { + _satellite.setSatelliteType(Geom::IF); + } else if (_fillet_chamfer_type_inverse_chamfer.get_active() == true) { + _satellite.setSatelliteType(Geom::IC); + } else { + _satellite.setSatelliteType(Geom::C); + } + if (_flexible) { + if (d_pos > 99.99999 || d_pos < 0) { + d_pos = 0; + } + d_pos = d_pos / 100; + } else { + d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, *document_unit); + } + _satellite.setAmmount( d_pos); + unsigned int steps = (unsigned int)_fillet_chamfer_chamfer_subdivisions.get_value(); + if(steps < 1){ + steps = 1; + } + _satellite.setSteps(steps); + _knotpoint->knot_set_offset(_satellite); + } + _close(); +} + +void FilletChamferPropertiesDialog::_close() +{ + _set_desktop(NULL); + destroy_(); + Glib::signal_idle().connect( + sigc::bind_return( + sigc::bind(sigc::ptr_fun(&::operator delete), this), + false + ) + ); +} + +bool FilletChamferPropertiesDialog::_handleKeyEvent(GdkEventKey * /*event*/) +{ + return false; +} + +void FilletChamferPropertiesDialog::_handleButtonEvent(GdkEventButton *event) +{ + if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { + _apply(); + } +} + +void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) +{ + double position; + std::string distance_or_radius = std::string(_("Radius")); + if(aprox){ + distance_or_radius = std::string(_("Radius approximated")); + } + if(use_distance){ + distance_or_radius = std::string(_("Knot distance")); + } + if (satellite.getIsTime()) { + position = ammount * 100; + _flexible = true; + _fillet_chamfer_position_label.set_label(_("Position (%):")); + } else { + _flexible = false; + std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, unit); + _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); + position = ammount; + position = Inkscape::Util::Quantity::convert(position, *document_unit, unit); + } + _fillet_chamfer_position_numeric.set_value(position); + if (satellite.getSatelliteType() == Geom::F) { + _fillet_chamfer_type_fillet.set_active(true); + } else if (satellite.getSatelliteType() == Geom::IF) { + _fillet_chamfer_type_inverse_fillet.set_active(true); + } else if (satellite.getSatelliteType() == Geom::C) { + _fillet_chamfer_type_chamfer.set_active(true); + _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); + } else if (satellite.getSatelliteType() == Geom::IC) { + _fillet_chamfer_type_inverse_chamfer.set_active(true); + _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); + } + _satellite = satellite; +} + +void FilletChamferPropertiesDialog::_set_pt( + const Inkscape::LivePathEffect:: + SatellitePairArrayParamKnotHolderEntity *pt) +{ + _knotpoint = const_cast< + Inkscape::LivePathEffect::SatellitePairArrayParamKnotHolderEntity *>( + pt); +} + +void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) +{ + unit = abbr; +} + +void FilletChamferPropertiesDialog::_set_ammount(double amm) +{ + ammount = amm; +} + + + + +void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring const *abbr) +{ + document_unit = abbr; +} + +void FilletChamferPropertiesDialog::_set_use_distance(bool use_knot_distance) +{ + use_distance = use_knot_distance; +} + +void FilletChamferPropertiesDialog::_set_aprox(bool aprox_radius) +{ + aprox = aprox_radius; +} + +void FilletChamferPropertiesDialog::_set_desktop(SPDesktop *desktop) +{ + if (desktop) { + Inkscape::GC::anchor(desktop); + } + if (_desktop) { + Inkscape::GC::release(_desktop); + } + _desktop = desktop; +} + +} // namespace +} // namespace +} // namespace + +/* + 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:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index e69de29bb2..63215d17c8 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -0,0 +1,118 @@ +/** + * + * From the code of Liam P.White from his Power Stroke Knot dialog + * + * Released under GNU GPL. Read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H +#define INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H + +#include <2geom/point.h> +#include +#include "live_effects/parameter/satellitepairarray.h" + +class SPDesktop; + +namespace Inkscape { +namespace UI { +namespace Dialogs { + +class FilletChamferPropertiesDialog : public Gtk::Dialog { +public: + FilletChamferPropertiesDialog(); + virtual ~FilletChamferPropertiesDialog(); + + Glib::ustring getName() const { + return "LayerPropertiesDialog"; + } + + static void showDialog(SPDesktop *desktop, double ammount, + const Inkscape::LivePathEffect:: + SatellitePairArrayParamKnotHolderEntity *pt, + const gchar *unit, + bool use_distance, + bool aprox_radius, + Glib::ustring const * documentUnit, + Geom::Satellite satellite); + +protected: + + SPDesktop *_desktop; + Inkscape::LivePathEffect::SatellitePairArrayParamKnotHolderEntity * + _knotpoint; + + Gtk::Label _fillet_chamfer_position_label; + Gtk::SpinButton _fillet_chamfer_position_numeric; + Gtk::RadioButton::Group _fillet_chamfer_type_group; + Gtk::RadioButton _fillet_chamfer_type_fillet; + Gtk::RadioButton _fillet_chamfer_type_inverse_fillet; + Gtk::RadioButton _fillet_chamfer_type_chamfer; + Gtk::RadioButton _fillet_chamfer_type_inverse_chamfer; + Gtk::Label _fillet_chamfer_chamfer_subdivisions_label; + Gtk::SpinButton _fillet_chamfer_chamfer_subdivisions; + + Gtk::Table _layout_table; + bool _position_visible; + + Gtk::Button _close_button; + Gtk::Button _apply_button; + + sigc::connection _destroy_connection; + + static FilletChamferPropertiesDialog &_instance() { + static FilletChamferPropertiesDialog instance; + return instance; + } + + void _set_desktop(SPDesktop *desktop); + void _set_pt(const Inkscape::LivePathEffect:: + SatellitePairArrayParamKnotHolderEntity *pt); + void _set_unit(const gchar *abbr); + void _set_document_unit(Glib::ustring const * abbr); + void _set_use_distance(bool use_knot_distance); + void _set_aprox(bool aprox_radius); + void _apply(); + void _close(); + bool _flexible; + Geom::Satellite _satellite; + const gchar *unit; + Glib::ustring const * document_unit; + bool use_distance; + double ammount; + bool aprox; + void _set_ammount(double ammount); + void _set_satellite(Geom::Satellite satellite); + void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); + + bool _handleKeyEvent(GdkEventKey *event); + void _handleButtonEvent(GdkEventButton *event); + + friend class Inkscape::LivePathEffect:: + SatellitePairArrayParamKnotHolderEntity; + +private: + FilletChamferPropertiesDialog( + FilletChamferPropertiesDialog const &); // no copy + FilletChamferPropertiesDialog &operator=( + FilletChamferPropertiesDialog const &); // no assign +}; + +} // namespace +} // namespace +} // namespace + +#endif //INKSCAPE_DIALOG_LAYER_PROPERTIES_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:fileencoding=utf-8:textwidth=99 +// : -- GitLab From a0d7339156a79b435423b11dbbbe3eb6558b9d32 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 5 Mar 2015 00:15:27 +0100 Subject: [PATCH 022/121] Add to po files (bzr r13645.1.34) --- po/POTFILES.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 9f301ac228..d1aef8eadc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -160,7 +160,7 @@ src/live_effects/lpe-taperstroke.cpp src/live_effects/lpe-vonkoch.cpp src/live_effects/parameter/bool.cpp src/live_effects/parameter/enum.h -src/live_effects/parameter/filletchamferpointarray.cpp +src/live_effects/parameter/satellitepairarray.cpp src/live_effects/parameter/originalpath.cpp src/live_effects/parameter/originalpatharray.cpp src/live_effects/parameter/parameter.cpp -- GitLab From 62ebac099d8fa013e34a773c0fe3aee56b5a5758 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Mar 2015 13:55:16 +0100 Subject: [PATCH 023/121] 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/2geom/pointwise.cpp | 2 +- src/2geom/satellite.cpp | 39 ++-- src/2geom/satellite.h | 12 +- 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 +- .../parameter/satellitepairarray.cpp | 217 +++++++++++------- .../parameter/satellitepairarray.h | 16 +- .../dialog/lpe-fillet-chamfer-properties.cpp | 20 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 14 +- 11 files changed, 222 insertions(+), 161 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 1d1c69ceec..3b182916ae 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -132,7 +132,7 @@ Pointwise::len_to_rad(double A, std::pair satelli boost::optional > Pointwise::getCurveIn(std::pair sat){ //curve out = sat.first; - std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_from_piecewise(_pwd2, 0.001)); + std::vector path_in_processed = path_from_piecewise(_pwd2, 0.001); unsigned int counterTotal = 0; for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()){ diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 22c3c8bed1..3420db7f60 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,8 +40,8 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle, unsigned int steps) - : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle), _steps(steps){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps) + : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _amount(amount), _angle(angle), _steps(steps){}; Satellite::~Satellite() {}; @@ -49,13 +49,14 @@ double Satellite::toTime(double A,Geom::D2 d2_in) { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ - _ammount = 0; return 0; } double t = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart) { - t = 1; + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + if (lenghtPart != 0) { + t = A / lenghtPart; + } } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); @@ -64,15 +65,8 @@ Satellite::toTime(double A,Geom::D2 d2_in) if (t_roots.size() > 0) { t = t_roots[0]; } - } else { - //to be sure - if (lenghtPart != 0) { - t = A / lenghtPart; - } - } - if(t > 0.998){ - t = 1; } + return t; } @@ -80,19 +74,18 @@ double Satellite::toSize(double A,Geom::D2 d2_in) { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ - _ammount = 0; return 0; } double s = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (d2_in[0].degreesOfFreedom() != 2) { + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + s = (A * lenghtPart); + } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); u.push(d2_in, 1); u = Geom::portion(u, 0.0, A); s = Geom::length(u, 0.001); - } else { - s = (A * lenghtPart); } return s; } @@ -110,16 +103,19 @@ Satellite::getOpositeTime(double s, Geom::D2 d2_in) double Satellite::getTime(Geom::D2 d2_in){ - double t = getAmmount(); + double t = getAmount(); if(!getIsTime()){ t = toTime(t, d2_in); } + if(t > 1){ + t = 1; + } return t; } double Satellite::getSize(Geom::D2 d2_in){ - double s = getAmmount(); + double s = getAmount(); if(getIsTime()){ s = toSize(s, d2_in); } @@ -129,7 +125,8 @@ Satellite::getSize(Geom::D2 d2_in){ Geom::Point Satellite::getPosition(Geom::D2 d2_in){ - return d2_in.valueAt(getTime(d2_in)); + double t = getTime(d2_in); + return d2_in.valueAt(t); } void @@ -139,7 +136,7 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) if(!getIsTime()){ A = toSize(A, d2_in); } - setAmmount(A); + setAmount(A); } } // end namespace Geom diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 4b07976201..d14a98a7f4 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle, unsigned int steps); + Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps); virtual ~Satellite(); @@ -89,9 +89,9 @@ class Satellite { _hidden = A; } - void setAmmount(double A) + void setAmount(double A) { - _ammount = A; + _amount = A; } void setAngle(double A) @@ -145,9 +145,9 @@ class Satellite return _hidden; } - double getAmmount() const + double getAmount() const { - return _ammount; + return _amount; } double getAngle() const @@ -177,7 +177,7 @@ class Satellite bool _active; bool _hasMirror; bool _hidden; - double _ammount; + double _amount; double _angle; unsigned int _steps; }; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 118a89eade..d979171be9 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 56db6305e7..3d22216d4e 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 e4c480d934..e8a1b95322 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 d28576fce9..a6e797d4e6 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 ffd04e14c8..9c2c1f93bf 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 21fb0fbd8f..79a015c6d9 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; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index fe0deba577..8a6cbadadf 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -123,9 +123,9 @@ FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() } void FilletChamferPropertiesDialog::showDialog( - SPDesktop *desktop, double ammount, + SPDesktop *desktop, double amount, const Inkscape::LivePathEffect:: - SatellitePairArrayParamKnotHolderEntity *pt, + FilletChamferKnotHolderEntity *pt, const gchar *unit, bool use_distance, bool aprox_radius, @@ -139,7 +139,7 @@ void FilletChamferPropertiesDialog::showDialog( dialog->_set_use_distance(use_distance); dialog->_set_aprox(aprox_radius); dialog->_set_document_unit(documentUnit); - dialog->_set_ammount(ammount); + dialog->_set_amount(amount); dialog->_set_satellite(satellite); dialog->_set_pt(pt); @@ -176,7 +176,7 @@ void FilletChamferPropertiesDialog::_apply() } else { d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, *document_unit); } - _satellite.setAmmount( d_pos); + _satellite.setAmount( d_pos); unsigned int steps = (unsigned int)_fillet_chamfer_chamfer_subdivisions.get_value(); if(steps < 1){ steps = 1; @@ -222,14 +222,14 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) distance_or_radius = std::string(_("Knot distance")); } if (satellite.getIsTime()) { - position = ammount * 100; + position = amount * 100; _flexible = true; _fillet_chamfer_position_label.set_label(_("Position (%):")); } else { _flexible = false; std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, unit); _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); - position = ammount; + position = amount; position = Inkscape::Util::Quantity::convert(position, *document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); @@ -249,10 +249,10 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) void FilletChamferPropertiesDialog::_set_pt( const Inkscape::LivePathEffect:: - SatellitePairArrayParamKnotHolderEntity *pt) + FilletChamferKnotHolderEntity *pt) { _knotpoint = const_cast< - Inkscape::LivePathEffect::SatellitePairArrayParamKnotHolderEntity *>( + Inkscape::LivePathEffect::FilletChamferKnotHolderEntity *>( pt); } @@ -261,9 +261,9 @@ void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) unit = abbr; } -void FilletChamferPropertiesDialog::_set_ammount(double amm) +void FilletChamferPropertiesDialog::_set_amount(double amm) { - ammount = amm; + amount = amm; } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 63215d17c8..6051b49d35 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -27,9 +27,9 @@ public: return "LayerPropertiesDialog"; } - static void showDialog(SPDesktop *desktop, double ammount, + static void showDialog(SPDesktop *desktop, double amount, const Inkscape::LivePathEffect:: - SatellitePairArrayParamKnotHolderEntity *pt, + FilletChamferKnotHolderEntity *pt, const gchar *unit, bool use_distance, bool aprox_radius, @@ -39,7 +39,7 @@ public: protected: SPDesktop *_desktop; - Inkscape::LivePathEffect::SatellitePairArrayParamKnotHolderEntity * + Inkscape::LivePathEffect::FilletChamferKnotHolderEntity * _knotpoint; Gtk::Label _fillet_chamfer_position_label; @@ -67,7 +67,7 @@ protected: void _set_desktop(SPDesktop *desktop); void _set_pt(const Inkscape::LivePathEffect:: - SatellitePairArrayParamKnotHolderEntity *pt); + FilletChamferKnotHolderEntity *pt); void _set_unit(const gchar *abbr); void _set_document_unit(Glib::ustring const * abbr); void _set_use_distance(bool use_knot_distance); @@ -79,9 +79,9 @@ protected: const gchar *unit; Glib::ustring const * document_unit; bool use_distance; - double ammount; + double amount; bool aprox; - void _set_ammount(double ammount); + void _set_amount(double amount); void _set_satellite(Geom::Satellite satellite); void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); @@ -89,7 +89,7 @@ protected: void _handleButtonEvent(GdkEventButton *event); friend class Inkscape::LivePathEffect:: - SatellitePairArrayParamKnotHolderEntity; + FilletChamferKnotHolderEntity; private: FilletChamferPropertiesDialog( -- GitLab From 580ee6538b069ca74d4159d6b6b8ad6a33bcab4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 15:14:26 +0100 Subject: [PATCH 024/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d979171be9..ca53bec635 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 3d22216d4e..d099d04759 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; -- GitLab From 4c1951cc43deafcc0131ba6a0878b4f371651f68 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 16:30:33 +0100 Subject: [PATCH 025/121] 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 +- .../parameter/satellitepairarray.cpp | 2 +- .../parameter/satellitepairarray.h | 4 +- .../dialog/lpe-fillet-chamfer-properties.cpp | 10 +-- 5 files changed, 15 insertions(+), 87 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0140f9be99..36dd599d45 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 d099d04759..3d22216d4e 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 9c2c1f93bf..0fc27153f1 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 79a015c6d9..d20339ccbd 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; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index d0f52775a4..c6959b7189 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -129,12 +129,8 @@ void FilletChamferPropertiesDialog::showDialog( const gchar *unit, bool use_distance, bool aprox_radius, -<<<<<<< TREE - Glib::ustring const * documentUnit, + Glib::ustring documentUnit, Geom::Satellite satellite) -======= - Glib::ustring documentUnit) ->>>>>>> MERGE-SOURCE { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); @@ -265,7 +261,6 @@ void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) unit = abbr; } -<<<<<<< TREE void FilletChamferPropertiesDialog::_set_amount(double amm) { amount = amm; @@ -274,10 +269,7 @@ void FilletChamferPropertiesDialog::_set_amount(double amm) -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring const *abbr) -======= void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring abbr) ->>>>>>> MERGE-SOURCE { document_unit = abbr; } -- GitLab From 14b24b5d5cc3a8c72d496bea35e16e8ca47ae458 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Mar 2015 22:06:08 +0100 Subject: [PATCH 026/121] commit for refactoring (bzr r13645.1.42) --- src/2geom/pointwise.cpp | 148 ++++++++++++++++++ src/2geom/pointwise.h | 18 +-- src/live_effects/lpe-fillet-chamfer.cpp | 27 ++-- src/live_effects/lpe-fillet-chamfer.h | 2 +- .../parameter/satellitepairarray.cpp | 46 ++++-- .../parameter/satellitepairarray.h | 1 + 6 files changed, 209 insertions(+), 33 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 3b182916ae..96a7e86447 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -63,6 +63,95 @@ Pointwise::setPwd2(Piecewise > pwd2_in){ _pwd2 = pwd2_in; } +void +Pointwise::recalculate_for_new_pwd2(Piecewise > A) +{ + if( _pwd2.size() > A.size()){ + new_pwd_sustract(A); + } else if ( _pwd2.size() < A.size()){ + new_pwd_append(A); + } +} + +void +Pointwise::new_pwd_append(Piecewise > A) +{ + int counter = 0; + double last = -1; + std::vector > satellites; + std::cout << _pwd2.size() << "pwsize\n"; + std::cout << A.size() << "Asize\n"; + for(unsigned i = 0; i < _satellites.size(); i++){ + std::cout << _satellites[i].first << "firat\n"; + std::cout << _satellites[i].first-counter << "firat\n"; + + if(_satellites.size() > i+1 && !_satellites[i+1].second.getIsStart() && !are_near(_pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ + std::cout << "removed\n"; + if(last != _satellites[i].first){ + std::cout << "removedtrue\n"; + counter++; + last = _satellites[i].first; + } + } else{ + std::cout << "added\n"; + satellites.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + } + } + _pwd2 = A; + _satellites = satellites; +} +void +Pointwise::new_pwd_sustract(Piecewise > A) +{ + int counter = 0; + double last = -1; + double start = false; + double hideLast = false; + std::vector > satellites; + std::cout << _pwd2.size() << "pwsize\n"; + std::cout << A.size() << "Asize\n"; + for(unsigned i = 0; i < _satellites.size(); i++){ + std::cout << _satellites[i].first << "firat\n"; + std::cout << _satellites[i].first-counter << "firat\n"; + if((_satellites[i].first != findLastIndex(i) && !_satellites[findLastIndex(i)].second.getIsClosing()) && !are_near(_pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ + std::cout << "removed\n"; + if(last != _satellites[i].first){ + std::cout << "removedtrue\n"; + counter++; + last = _satellites[i].first; + if(_satellites[i].second.getIsClosing()){ + satellites = setBackClosing(satellites); + } + if(_satellites[i].second.getIsStart()){ + start = true; + } + if(_satellites[i].second.getHidden()){ + hideLast = true; + } else { + hideLast = false; + } + } + } else{ + std::cout << "added\n"; + if(start){ + setStarting(_satellites[i].first); + start = false; + } + if(_satellites[i].second.getIsStart() && hideLast){ + satellites = setBackHidden(satellites); + hideLast = false; + } + if(last != _satellites[i].first && _satellites[i].first == findLastIndex(i) && !_satellites[findLastIndex(i)].second.getIsClosing()){ + last = _satellites[i].first; + counter++; + } + satellites.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + } + } + _pwd2 = A; + _satellites = satellites; +} + double Pointwise::rad_to_len(double A, std::pair satellite) { @@ -192,6 +281,49 @@ Pointwise::findSatellites(unsigned int A, int B) const return ret; } +std::vector > +Pointwise::setBackHidden(std::vector > sat) +{ + for(unsigned i = 0; i < sat.size(); i++){ + if(sat[i].first == sat.back().first ){ + sat[i].second.setHidden(true); + } + } + return sat; +} + +std::vector > +Pointwise::setBackInactive(std::vector > sat) +{ + for(unsigned i = 0; i < sat.size(); i++){ + if(sat[i].first == sat.back().first ){ + sat[i].second.setHidden(true); + } + } + return sat; +} + +std::vector > +Pointwise::setBackClosing(std::vector > sat) +{ + for(unsigned i = 0; i < sat.size(); i++){ + if(sat[i].first == sat.back().first ){ + sat[i].second.setIsClosing(true); + } + } + return sat; +} + +void +Pointwise::setStarting(unsigned int A) +{ + for(unsigned i = 0; i < _satellites.size(); i++){ + if(_satellites[i].first == A){ + _satellites[i].second.setIsStart(true); + } + } +} + std::vector Pointwise::findClosingSatellites(unsigned int A) const { @@ -211,6 +343,22 @@ Pointwise::findClosingSatellites(unsigned int A) const return ret; } +double +Pointwise::findLastIndex(unsigned int A) const +{ + double ret = -1; + bool finded = false; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(finded && _satellites[i].second.getIsStart()){ + return _satellites[i].first; + } + if(_satellites[i].first == A){ + finded = true; + } + } + return ret; +} + std::vector Pointwise::findPeviousSatellites(unsigned int A, int B) const { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index b6bd4c4fda..54f272a13e 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -76,16 +76,14 @@ class Pointwise Piecewise > getPwd2(); void setPwd2(Piecewise > pwd2_in); boost::optional > getCurveIn(std::pair sat); - Pointwise recalculate_for_new_pwd2(Piecewise > A); - /* - Pointwise pwd2_reverse(int index); - Pointwise pwd2_append(int index); - Pointwise pwd2_prepend(int index); - Pointwise pwd2_add(int index); - Pointwise pwd2_del(int index); - Pointwise satellite_add(unsigned int index,Satellite sat); - Pointwise satellite_del(unsigned int index,Satellite sat); - */ + void recalculate_for_new_pwd2(Piecewise > A); + void new_pwd_append(Piecewise > A); + void new_pwd_sustract(Piecewise > A); + std::vector > setBackClosing(std::vector > sat); + std::vector > setBackHidden(std::vector > sat); + void setStarting(unsigned int A); + double findLastIndex(unsigned int A) const; + private: Piecewise > _pwd2; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 36dd599d45..b94e3c4291 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 3d22216d4e..1bedbefa49 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 0fc27153f1..45f5226934 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 d20339ccbd..9b22a386b8 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); -- GitLab From aeffc3f474c1ce460b2c9f8340de283d5853a164 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Mar 2015 19:26:22 +0100 Subject: [PATCH 027/121] fixing a boring bug in path manipulator (bzr r13645.1.43) --- src/2geom/pointwise.cpp | 472 ++++++++++-------- src/2geom/pointwise.h | 31 +- src/2geom/satellite.cpp | 19 +- src/2geom/satellite.h | 34 +- src/live_effects/lpe-fillet-chamfer.cpp | 113 +++-- src/live_effects/parameter/array.cpp | 17 +- src/live_effects/parameter/array.h | 5 +- .../parameter/satellitepairarray.cpp | 59 ++- src/ui/tool/path-manipulator.cpp | 38 +- 9 files changed, 425 insertions(+), 363 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 96a7e86447..584e78523c 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -36,33 +36,149 @@ namespace Geom { -Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) - : _pwd2(pwd2), _satellites(satellites) +Pointwise::Pointwise(Piecewise > pwd2) + : _pwd2(pwd2),_pathInfo(NULL), _satellites(NULL) { + setPathInfo(); }; Pointwise::~Pointwise(){}; -std::vector > -Pointwise::getSatellites(){ +Piecewise > +Pointwise::getPwd2() const +{ + return _pwd2; +} + +void +Pointwise::setPwd2(Piecewise > pwd2_in) +{ + _pwd2 = pwd2_in; + setPathInfo(); +} + +std::vector > +Pointwise::getSatellites() const +{ return _satellites; } void -Pointwise::setSatellites(std::vector > sat){ - _satellites = sat; +Pointwise::setSatellites(std::vector > sats) +{ + _satellites = sats; } -Piecewise > -Pointwise::getPwd2(){ - return _pwd2; +//START QUESTION Next functions maybe is beter land outside the class? +void +Pointwise::setPathInfo() +{ + setPathInfo(_pwd2); } void -Pointwise::setPwd2(Piecewise > pwd2_in){ - _pwd2 = pwd2_in; +Pointwise::setPathInfo(Piecewise > pwd2) +{ + _pathInfo.clear(); + std::vector path_in = path_from_piecewise(remove_short_cuts(pwd2,0.1), 0.001); + unsigned int counter = 0; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + } + while (curve_it1 != curve_endit) { + ++curve_it1; + counter++; + } + if(path_it->closed()){ + _pathInfo.push_back(std::make_pair(counter-1,true)); + } else { + _pathInfo.push_back(std::make_pair(counter-1,false)); + } + } +} + +unsigned int +Pointwise::getSubPathIndex(unsigned int index) const +{ + for(unsigned int i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return i; + } + } + return 0; +} + +unsigned int +Pointwise::getLast(unsigned int index) const +{ + for(unsigned int i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].first; + } + } + return 0; +} + +unsigned int +Pointwise::getFirst(unsigned int index) const +{ + for(unsigned int i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + if(i==0){ + return 0; + } else { + return _pathInfo[i-1].first + 1; + } + } + } + return 0; } +boost::optional +Pointwise::getPrevious(unsigned int index) const +{ + if(getFirst(index) == index && getIsClosed(index)){ + return getLast(index); + } + if(getFirst(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index - 1; +} + +boost::optional +Pointwise::getNext(unsigned int index) const +{ + if(getLast(index) == index && getIsClosed(index)){ + return getFirst(index); + } + if(getLast(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index + 1; +} + +bool +Pointwise::getIsClosed(unsigned int index) const +{ + for(unsigned int i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].second; + } + } + return false; +} +//END QUESTION + void Pointwise::recalculate_for_new_pwd2(Piecewise > A) { @@ -76,90 +192,132 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) void Pointwise::new_pwd_append(Piecewise > A) { - int counter = 0; - double last = -1; - std::vector > satellites; - std::cout << _pwd2.size() << "pwsize\n"; - std::cout << A.size() << "Asize\n"; - for(unsigned i = 0; i < _satellites.size(); i++){ - std::cout << _satellites[i].first << "firat\n"; - std::cout << _satellites[i].first-counter << "firat\n"; - - if(_satellites.size() > i+1 && !_satellites[i+1].second.getIsStart() && !are_near(_pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ - std::cout << "removed\n"; - if(last != _satellites[i].first){ - std::cout << "removedtrue\n"; - counter++; - last = _satellites[i].first; + //not working + PathVector pathv = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + PathVector pathv_new = path_from_piecewise(remove_short_cuts(A, 0.1), 0.001); + unsigned int counter = 0; + unsigned int counterPaths = 0; + unsigned int counterCurves = 0; + 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(); } - } else{ - std::cout << "added\n"; - satellites.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); } + counterCurves = 0; + while (curve_it2 != curve_endit) { + counter++; + counterCurves++; + ++curve_it1; + ++curve_it2; + } + if(!are_near(curve_it2->pointAt(1),pathv_new[counterPaths].finalPoint(),0.001)){ + pathv_new[counterPaths] = pathv_new[counterPaths].reverse(); + } + counterPaths++; } - _pwd2 = A; - _satellites = satellites; + A = paths_to_pw(pathv_new); + + counter = 0; + std::vector > sats; + unsigned int start = 0; + for(unsigned i = 0; i < A.size(); i++){ + if(/*getIsStart(i, A) &&/*/ i!=0 ){ + if(!are_near(A[i-1].at0(),A[start].at0(),0.001)){ + sats.back().second.setIsEndOpen(true); + } + start = i; + } + if(!are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + counter++; + bool isEndOpen = false; + bool active = true; + bool hidden = false; + bool flexible = true; + bool mirror_knots = true; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(F, flexible, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); + sats.push_back(std::make_pair(i,sat)); + } else { + sats[i-counter].second.setIsEndOpen(false); + sats.push_back(std::make_pair(i,_satellites[i-counter].second)); + } + } + setPwd2(A); + setSatellites(sats); } + void Pointwise::new_pwd_sustract(Piecewise > A) { int counter = 0; - double last = -1; - double start = false; - double hideLast = false; - std::vector > satellites; - std::cout << _pwd2.size() << "pwsize\n"; - std::cout << A.size() << "Asize\n"; + std::vector > sats; + Piecewise > pwd2 = _pwd2; + setPwd2(A); for(unsigned i = 0; i < _satellites.size(); i++){ - std::cout << _satellites[i].first << "firat\n"; - std::cout << _satellites[i].first-counter << "firat\n"; - if((_satellites[i].first != findLastIndex(i) && !_satellites[findLastIndex(i)].second.getIsClosing()) && !are_near(_pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ - std::cout << "removed\n"; - if(last != _satellites[i].first){ - std::cout << "removedtrue\n"; - counter++; - last = _satellites[i].first; - if(_satellites[i].second.getIsClosing()){ - satellites = setBackClosing(satellites); - } - if(_satellites[i].second.getIsStart()){ - start = true; - } - if(_satellites[i].second.getHidden()){ - hideLast = true; - } else { - hideLast = false; + if(!_satellites[i].second.getIsEndOpen() && (getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001))){ + counter++; + } else { + sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + } + } + setSatellites(sats); +} + +void +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) +{ + for(unsigned int i = 0; i < _pathInfo.size(); i++){ + unsigned int firstNode = getFirst(_pathInfo[i].first); + unsigned int lastNode = getLast(_pathInfo[i].first); + std::cout << firstNode << "FIRSTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; + std::cout << lastNode << "LASTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; + if(!getIsClosed(lastNode)){ + std::cout << "CLOSSEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n"; + bool endOpen = false; + for(unsigned i = 0; i < _satellites.size(); i++){ + _satellites[i].second.setIsEndOpen(false); + if(_satellites[i].first == firstNode || _satellites[i].first == lastNode){ + _satellites[i].second.setActive(active); + _satellites[i].second.setHidden(hidden); + if(_satellites[i].first == lastNode){ + if(!endOpen){ + endOpen = true; + } else { + endOpen = false; + std::cout << "ENNNNNNNNNNNDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDOPEN\n"; + _satellites[i].second.setIsEndOpen(true); + _satellites[i].second.setAmount(amount); + _satellites[i].second.setAngle(angle); + } + } } } - } else{ - std::cout << "added\n"; - if(start){ - setStarting(_satellites[i].first); - start = false; - } - if(_satellites[i].second.getIsStart() && hideLast){ - satellites = setBackHidden(satellites); - hideLast = false; - } - if(last != _satellites[i].first && _satellites[i].first == findLastIndex(i) && !_satellites[findLastIndex(i)].second.getIsClosing()){ - last = _satellites[i].first; - counter++; - } - satellites.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); } } - _pwd2 = A; - _satellites = satellites; } double -Pointwise::rad_to_len(double A, std::pair satellite) +Pointwise::rad_to_len(double A, std::pair sat) const { double len = 0; - boost::optional > d2_in = getCurveIn(satellite); - if(d2_in){ - Geom::D2 d2_out = _pwd2[satellite.first]; - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); + boost::optional d2_prev_index = getPrevious(sat.first); + if(d2_prev_index){ + Geom::D2 d2_in = _pwd2[*d2_prev_index]; + Geom::D2 d2_out = _pwd2[sat.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]; @@ -167,10 +325,10 @@ Pointwise::rad_to_len(double A, std::pair satelli if(cs.size() > 0){ Point cp =p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); - len = satellite.second.toSize(p0pt,d2_out); + len = sat.second.toSize(p0pt,d2_out); } else { if(A > 0){ - len = rad_to_len(A * -1, satellite); + len = rad_to_len(A * -1, sat); } } } @@ -178,18 +336,19 @@ Pointwise::rad_to_len(double A, std::pair satelli } double -Pointwise::len_to_rad(double A, std::pair satellite) +Pointwise::len_to_rad(double A, std::pair sat) const { - boost::optional > d2_in = 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); + boost::optional d2_prev_index = getPrevious(sat.first); + if(d2_prev_index){ + Geom::D2 d2_in = _pwd2[*d2_prev_index]; + Geom::D2 d2_out = _pwd2[sat.first]; + double time_in = sat.second.getOpositeTime(A, d2_in); + double time_out = sat.second.toTime(A,d2_out); + Geom::Point startArcPoint = (d2_in).valueAt(time_in); Geom::Point endArcPoint = d2_out.valueAt(time_out); Piecewise > u; u.push_cut(0); - u.push((*d2_in), 1); + u.push((d2_in), 1); Geom::Curve * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); Piecewise > u2; u2.push_cut(0); @@ -198,7 +357,7 @@ Pointwise::len_to_rad(double A, std::pair satelli Curve *knotCurve1 = A->portion(0, time_in); Curve *knotCurve2 = B->portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + Ray ray1(startArcPoint, (d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } @@ -207,7 +366,7 @@ Pointwise::len_to_rad(double A, std::pair satelli if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; + 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); double divisor = std::sin(angleBetween/2.0); @@ -218,52 +377,6 @@ Pointwise::len_to_rad(double A, std::pair satelli return 0; } -boost::optional > -Pointwise::getCurveIn(std::pair sat){ - //curve out = sat.first; - std::vector path_in_processed = path_from_piecewise(_pwd2, 0.001); - unsigned int counterTotal = 0; - 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::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(); - } - } - Geom::Path::const_iterator curve_end = curve_endit; - --curve_end; - unsigned int counter = 0; - while (curve_it1 != curve_endit) { - if(counterTotal == sat.first){ - if (counter==0) { - if (path_it->closed()) { - return (*curve_end).toSBasis(); - } else { - return boost::none; - } - } else { - return (*path_it)[counter - 1].toSBasis(); - } - } - ++curve_it1; - counter++; - counterTotal++; - } - } - return boost::none; -} - std::vector Pointwise::findSatellites(unsigned int A, int B) const { @@ -281,96 +394,13 @@ Pointwise::findSatellites(unsigned int A, int B) const return ret; } -std::vector > -Pointwise::setBackHidden(std::vector > sat) -{ - for(unsigned i = 0; i < sat.size(); i++){ - if(sat[i].first == sat.back().first ){ - sat[i].second.setHidden(true); - } - } - return sat; -} - -std::vector > -Pointwise::setBackInactive(std::vector > sat) -{ - for(unsigned i = 0; i < sat.size(); i++){ - if(sat[i].first == sat.back().first ){ - sat[i].second.setHidden(true); - } - } - return sat; -} - -std::vector > -Pointwise::setBackClosing(std::vector > sat) -{ - for(unsigned i = 0; i < sat.size(); i++){ - if(sat[i].first == sat.back().first ){ - sat[i].second.setIsClosing(true); - } - } - return sat; -} - -void -Pointwise::setStarting(unsigned int A) -{ - for(unsigned i = 0; i < _satellites.size(); i++){ - if(_satellites[i].first == A){ - _satellites[i].second.setIsStart(true); - } - } -} - -std::vector -Pointwise::findClosingSatellites(unsigned int A) const -{ - std::vector ret; - bool finded = false; - for(unsigned i = 0; i < _satellites.size(); i++){ - if(finded && _satellites[i].second.getIsStart()){ - return ret; - } - if(finded && _satellites[i].second.getIsClosing()){ - ret.push_back(_satellites[i].second); - } - if(_satellites[i].first == A){ - finded = true; - } - } - return ret; -} - -double -Pointwise::findLastIndex(unsigned int A) const -{ - double ret = -1; - bool finded = false; - for(unsigned i = 0; i < _satellites.size(); i++){ - if(finded && _satellites[i].second.getIsStart()){ - return _satellites[i].first; - } - if(_satellites[i].first == A){ - finded = true; - } - } - return ret; -} - std::vector Pointwise::findPeviousSatellites(unsigned int A, int B) const { + boost::optional previous = getPrevious(A); std::vector ret; - for(unsigned i = 0; i < _satellites.size(); i++){ - if(_satellites[i].first == A){ - if(!_satellites[i].second.getIsStart()){ - ret = findSatellites(_satellites[i-1].first, B); - } else { - ret = findClosingSatellites(_satellites[i].first); - } - } + if(previous){ + ret = findSatellites(*previous,B); } return ret; } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 54f272a13e..eb34008779 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -63,32 +63,33 @@ namespace Geom { class Pointwise { public: - Pointwise(){}; - Pointwise(Piecewise > pwd2, std::vector > satellites); + Pointwise(Piecewise > pwd2); virtual ~Pointwise(); std::vector findSatellites(unsigned int A, int B = -1) const; std::vector findPeviousSatellites(unsigned int A, int B) const; - std::vector findClosingSatellites(unsigned int A) const; - double rad_to_len(double A, std::pair satellite); - double len_to_rad(double A, std::pair satellite); - std::vector > getSatellites(); - void setSatellites(std::vector > sat); - Piecewise > getPwd2(); + double rad_to_len(double A, std::pair sat) const; + double len_to_rad(double A, std::pair sat) const; + std::vector > getSatellites() const; + void setSatellites(std::vector > sats); + Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); - boost::optional > getCurveIn(std::pair sat); void recalculate_for_new_pwd2(Piecewise > A); void new_pwd_append(Piecewise > A); void new_pwd_sustract(Piecewise > A); - std::vector > setBackClosing(std::vector > sat); - std::vector > setBackHidden(std::vector > sat); - void setStarting(unsigned int A); - double findLastIndex(unsigned int A) const; - + void set_extremes(bool active, bool hidden, double amount, double angle); + void setPathInfo(); + void setPathInfo(Piecewise >); + unsigned int getSubPathIndex(unsigned int index) const; + unsigned int getLast(unsigned int index) const; + unsigned int getFirst(unsigned int index) const; + boost::optional getPrevious(unsigned int index) const; + boost::optional getNext(unsigned int index) const; + bool getIsClosed(unsigned int index) const; private: Piecewise > _pwd2; std::vector > _satellites; - + std::vector > _pathInfo; }; } // end namespace Geom diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 3420db7f60..509c0e0747 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,13 +40,13 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps) - : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _amount(amount), _angle(angle), _steps(steps){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps) + : _satellitetype(satellitetype), _isTime(isTime), _isEndOpen(isEndOpen), _active(active), _hasMirror(hasMirror), _hidden(hidden), _amount(amount), _angle(angle), _steps(steps){}; Satellite::~Satellite() {}; double -Satellite::toTime(double A,Geom::D2 d2_in) +Satellite::toTime(double A,Geom::D2 d2_in) const { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ return 0; @@ -71,7 +71,7 @@ Satellite::toTime(double A,Geom::D2 d2_in) } double -Satellite::toSize(double A,Geom::D2 d2_in) +Satellite::toSize(double A,Geom::D2 d2_in) const { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ return 0; @@ -91,7 +91,7 @@ Satellite::toSize(double A,Geom::D2 d2_in) } double -Satellite::getOpositeTime(double s, Geom::D2 d2_in) +Satellite::getOpositeTime(double s, Geom::D2 d2_in) const { if(s == 0){ return 1; @@ -102,7 +102,8 @@ Satellite::getOpositeTime(double s, Geom::D2 d2_in) } double -Satellite::getTime(Geom::D2 d2_in){ +Satellite::getTime(Geom::D2 d2_in) const +{ double t = getAmount(); if(!getIsTime()){ t = toTime(t, d2_in); @@ -114,7 +115,8 @@ Satellite::getTime(Geom::D2 d2_in){ } double -Satellite::getSize(Geom::D2 d2_in){ +Satellite::getSize(Geom::D2 d2_in) const +{ double s = getAmount(); if(getIsTime()){ s = toSize(s, d2_in); @@ -124,7 +126,8 @@ Satellite::getSize(Geom::D2 d2_in){ Geom::Point -Satellite::getPosition(Geom::D2 d2_in){ +Satellite::getPosition(Geom::D2 d2_in) const +{ double t = getTime(d2_in); return d2_in.valueAt(t); } diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index d14a98a7f4..43863d71fc 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps); + Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps); virtual ~Satellite(); @@ -65,15 +65,11 @@ class Satellite _isTime = A; } - void setIsClosing(bool A) + void setIsEndOpen(bool A) { - _isClosing = A; + _isEndOpen = A; } - void setIsStart(bool A) - { - _isStart = A; - } void setActive(bool A) { @@ -120,14 +116,9 @@ class Satellite return _isTime; } - bool getIsClosing() const - { - return _isClosing; - } - - bool getIsStart() const + bool getIsEndOpen() const { - return _isStart; + return _isEndOpen; } bool getActive() const @@ -161,19 +152,18 @@ class Satellite } void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 curve); - double getSize(Geom::D2 d2_in); - double getTime(Geom::D2 d2_in); - double getOpositeTime(double A,Geom::D2 SBasisCurve); - double toSize(double A,Geom::D2 d2_in); - double toTime(double A,Geom::D2 d2_in); + Geom::Point getPosition(Geom::D2 curve) const; + double getSize(Geom::D2 d2_in) const; + double getTime(Geom::D2 d2_in) const; + double getOpositeTime(double A,Geom::D2 SBasisCurve) const; + double toSize(double A,Geom::D2 d2_in) const; + double toTime(double A,Geom::D2 d2_in) const; private: SatelliteType _satellitetype; bool _isTime; - bool _isClosing; - bool _isStart; + bool _isEndOpen; bool _active; bool _hasMirror; bool _hidden; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b94e3c4291..0a5d3a224c 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 e8a1b95322..d8b2388da8 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 a6e797d4e6..5443cc3c45 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 45f5226934..045ef2060e 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); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index c8b986824c..dbcde240a1 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1221,10 +1221,13 @@ int PathManipulator::BSplineGetSteps() const { LivePathEffect::LPEBSpline const *lpe_bsp = NULL; - if (SP_IS_LPE_ITEM(_path) && _path->hasPathEffect()){ - Inkscape::LivePathEffect::Effect const *thisEffect = SP_LPE_ITEM(_path)->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); - if(thisEffect){ - lpe_bsp = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); + SPLPEItem * path = dynamic_cast(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect const *thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); + if(thisEffect){ + lpe_bsp = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); + } } } int steps = 0; @@ -1338,19 +1341,22 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) _spcurve->set_pathvector(pathv); if (alert_LPE) { /// \todo note that _path can be an Inkscape::LivePathEffect::Effect* too, kind of confusing, rework member naming? - if (SP_IS_LPE_ITEM(_path) && _path->hasPathEffect()){ - Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(_path)->getPathEffectOfType(Inkscape::LivePathEffect::POWERSTROKE); - if(thisEffect){ - LivePathEffect::LPEPowerStroke *lpe_pwr = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); - if (lpe_pwr) { - lpe_pwr->adjustForNewPath(pathv); + SPLPEItem * path = dynamic_cast(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect* thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::POWERSTROKE); + if(thisEffect){ + LivePathEffect::LPEPowerStroke *lpe_pwr = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); + if (lpe_pwr) { + lpe_pwr->adjustForNewPath(pathv); + } } - } - thisEffect = SP_LPE_ITEM(_path)->getPathEffectOfType(Inkscape::LivePathEffect::FILLET_CHAMFER); - if(thisEffect){ - LivePathEffect::LPEFilletChamfer *lpe_fll = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); - if (lpe_fll) { - lpe_fll->adjustForNewPath(pathv); + thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::FILLET_CHAMFER); + if(thisEffect){ + LivePathEffect::LPEFilletChamfer *lpe_fll = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); + if (lpe_fll) { + lpe_fll->adjustForNewPath(pathv); + } } } } -- GitLab From f3e7b51b1d2497cda7a66e13f4f50da145ece19c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 20 Mar 2015 00:14:47 +0100 Subject: [PATCH 028/121] Added delete nodes/satellites (bzr r13645.1.45) --- src/2geom/pointwise.cpp | 34 +++++++++++-------- src/2geom/pointwise.h | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 7 +--- src/live_effects/parameter/array.h | 2 -- .../dialog/lpe-fillet-chamfer-properties.cpp | 3 +- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 584e78523c..8f7a0b4020 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -37,7 +37,7 @@ namespace Geom { Pointwise::Pointwise(Piecewise > pwd2) - : _pwd2(pwd2),_pathInfo(NULL), _satellites(NULL) + : _pwd2(pwd2) { setPathInfo(); }; @@ -273,36 +273,40 @@ Pointwise::new_pwd_sustract(Piecewise > A) sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); } } + set_extremes(sats,false,true,0.0,0.0); setSatellites(sats); } void -Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(std::vector > sats, bool active, bool hidden, double amount, double angle) { for(unsigned int i = 0; i < _pathInfo.size(); i++){ unsigned int firstNode = getFirst(_pathInfo[i].first); unsigned int lastNode = getLast(_pathInfo[i].first); - std::cout << firstNode << "FIRSTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; - std::cout << lastNode << "LASTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; if(!getIsClosed(lastNode)){ - std::cout << "CLOSSEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n"; bool endOpen = false; - for(unsigned i = 0; i < _satellites.size(); i++){ - _satellites[i].second.setIsEndOpen(false); - if(_satellites[i].first == firstNode || _satellites[i].first == lastNode){ - _satellites[i].second.setActive(active); - _satellites[i].second.setHidden(hidden); - if(_satellites[i].first == lastNode){ + for(unsigned i = 0; i < sats.size(); i++){ + sats[i].second.setIsEndOpen(false); + if(sats[i].first > lastNode){ + break; + } + if(sats[i].first == firstNode || sats[i].first == lastNode){ + sats[i].second.setActive(active); + sats[i].second.setHidden(hidden); + if(sats[i].first == lastNode){ if(!endOpen){ endOpen = true; } else { endOpen = false; - std::cout << "ENNNNNNNNNNNDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDOPEN\n"; - _satellites[i].second.setIsEndOpen(true); - _satellites[i].second.setAmount(amount); - _satellites[i].second.setAngle(angle); + sats[i].second.setIsEndOpen(true); + sats[i].second.setAmount(amount); + sats[i].second.setAngle(angle); } } + if(sats[i].first == firstNode){ + sats[i].second.setAmount(amount); + sats[i].second.setAngle(angle); + } } } } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index eb34008779..e313722a1a 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -76,7 +76,7 @@ class Pointwise void recalculate_for_new_pwd2(Piecewise > A); void new_pwd_append(Piecewise > A); void new_pwd_sustract(Piecewise > A); - void set_extremes(bool active, bool hidden, double amount, double angle); + void set_extremes(std::vector > sats, bool active, bool hidden, double amount, double angle); void setPathInfo(); void setPathInfo(Piecewise >); unsigned int getSubPathIndex(unsigned int index) const; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0a5d3a224c..38645a9436 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 5443cc3c45..7ff477ffb4 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); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index c6959b7189..aa27a1414a 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -233,16 +233,15 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) position = Inkscape::Util::Quantity::convert(position, document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); + _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); if (satellite.getSatelliteType() == Geom::F) { _fillet_chamfer_type_fillet.set_active(true); } else if (satellite.getSatelliteType() == Geom::IF) { _fillet_chamfer_type_inverse_fillet.set_active(true); } else if (satellite.getSatelliteType() == Geom::C) { _fillet_chamfer_type_chamfer.set_active(true); - _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); } else if (satellite.getSatelliteType() == Geom::IC) { _fillet_chamfer_type_inverse_chamfer.set_active(true); - _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); } _satellite = satellite; } -- GitLab From cfe5bd077cc29fd43385792435f687d468aca13f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 10:55:27 +0100 Subject: [PATCH 029/121] fix bspline calls and atemp to fic a bug whith map (bzr r13645.1.46) --- src/2geom/pointwise.cpp | 109 +++++++----------- src/2geom/pointwise.h | 7 +- src/live_effects/lpe-fillet-chamfer.cpp | 46 ++++---- .../parameter/satellitepairarray.cpp | 12 +- src/ui/tool/node.cpp | 20 ++-- src/ui/tool/path-manipulator.cpp | 6 +- src/ui/tool/path-manipulator.h | 2 +- 7 files changed, 84 insertions(+), 118 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 8f7a0b4020..f476821ff5 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -192,66 +192,27 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) void Pointwise::new_pwd_append(Piecewise > A) { - //not working - PathVector pathv = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - PathVector pathv_new = path_from_piecewise(remove_short_cuts(A, 0.1), 0.001); unsigned int counter = 0; - unsigned int counterPaths = 0; - unsigned int counterCurves = 0; - 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_it2 != curve_endit) { - counter++; - counterCurves++; - ++curve_it1; - ++curve_it2; - } - if(!are_near(curve_it2->pointAt(1),pathv_new[counterPaths].finalPoint(),0.001)){ - pathv_new[counterPaths] = pathv_new[counterPaths].reverse(); + std::vector > sats; + for(unsigned i = 0; i < _satellites.size(); i++){ + if(_satellites[i].second.getIsEndOpen()){ + _satellites.erase(_satellites.begin() + i); } - counterPaths++; } - A = paths_to_pw(pathv_new); - - counter = 0; - std::vector > sats; - unsigned int start = 0; for(unsigned i = 0; i < A.size(); i++){ - if(/*getIsStart(i, A) &&/*/ i!=0 ){ - if(!are_near(A[i-1].at0(),A[start].at0(),0.001)){ - sats.back().second.setIsEndOpen(true); - } - start = i; - } if(!are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ counter++; bool isEndOpen = false; bool active = true; bool hidden = false; - bool flexible = true; - bool mirror_knots = true; + bool isTime = sats[0].second.getIsTime(); + bool mirror_knots = sats[0].second.getHasMirror(); double amount = 0.0; double degrees = 0.0; int steps = 0; - Satellite sat(F, flexible, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); + Satellite sat(sats[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); sats.push_back(std::make_pair(i,sat)); } else { - sats[i-counter].second.setIsEndOpen(false); sats.push_back(std::make_pair(i,_satellites[i-counter].second)); } } @@ -267,52 +228,60 @@ Pointwise::new_pwd_sustract(Piecewise > A) Piecewise > pwd2 = _pwd2; setPwd2(A); for(unsigned i = 0; i < _satellites.size(); i++){ - if(!_satellites[i].second.getIsEndOpen() && (getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001))){ + if(_satellites[i].second.getIsEndOpen()){ + _satellites.erase(_satellites.begin() + i); + } + } + for(unsigned i = 0; i < _satellites.size(); i++){ + if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ counter++; } else { sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); } } - set_extremes(sats,false,true,0.0,0.0); + std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n"; + std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n"; setSatellites(sats); } void -Pointwise::set_extremes(std::vector > sats, bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(std::vector > &sats, bool active, bool hidden, double amount, double angle) { for(unsigned int i = 0; i < _pathInfo.size(); i++){ unsigned int firstNode = getFirst(_pathInfo[i].first); unsigned int lastNode = getLast(_pathInfo[i].first); if(!getIsClosed(lastNode)){ - bool endOpen = false; + unsigned int lastIndex = 0; for(unsigned i = 0; i < sats.size(); i++){ sats[i].second.setIsEndOpen(false); if(sats[i].first > lastNode){ break; } - if(sats[i].first == firstNode || sats[i].first == lastNode){ + if(sats[i].first == firstNode){ sats[i].second.setActive(active); sats[i].second.setHidden(hidden); - if(sats[i].first == lastNode){ - if(!endOpen){ - endOpen = true; - } else { - endOpen = false; - sats[i].second.setIsEndOpen(true); - sats[i].second.setAmount(amount); - sats[i].second.setAngle(angle); - } - } - if(sats[i].first == firstNode){ - sats[i].second.setAmount(amount); - sats[i].second.setAngle(angle); - } + sats[i].second.setAmount(amount); + sats[i].second.setAngle(angle); + } + if(sats[i].first == lastNode){ + lastIndex = i; } } + Satellite sat(sats[0].second.getSatelliteType(), sats[0].second.getIsTime(), true, active, sats[0].second.getHasMirror(), hidden, amount, angle, sats[0].second.getSteps()); + sats.insert(sats.begin() + lastIndex,std::make_pair(lastNode,sat)); } } } +void +Pointwise::reverse(unsigned int start,unsigned int end){ + for(unsigned int i = start; i < end / 2; i++){ + std::pair tmp = _satellites[i]; + _satellites[i] = _satellites[end - start - i - 1]; + _satellites[end - start - i - 1] = tmp; + } +} + double Pointwise::rad_to_len(double A, std::pair sat) const { @@ -381,28 +350,28 @@ Pointwise::len_to_rad(double A, std::pair sat) co return 0; } -std::vector +std::vector Pointwise::findSatellites(unsigned int A, int B) const { - std::vector ret; + std::vector ret; int counter = 0; for(unsigned i = 0; i < _satellites.size(); i++){ if(_satellites[i].first == A){ if(counter >= B && B != -1){ return ret; } - ret.push_back(_satellites[i].second); + ret.push_back(i); counter++; } } return ret; } -std::vector +std::vector Pointwise::findPeviousSatellites(unsigned int A, int B) const { boost::optional previous = getPrevious(A); - std::vector ret; + std::vector ret; if(previous){ ret = findSatellites(*previous,B); } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index e313722a1a..72ff852d09 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -65,8 +65,8 @@ class Pointwise public: Pointwise(Piecewise > pwd2); virtual ~Pointwise(); - std::vector findSatellites(unsigned int A, int B = -1) const; - std::vector findPeviousSatellites(unsigned int A, int B) const; + std::vector findSatellites(unsigned int A, int B = -1) const; + std::vector findPeviousSatellites(unsigned int A, int B) const; double rad_to_len(double A, std::pair sat) const; double len_to_rad(double A, std::pair sat) const; std::vector > getSatellites() const; @@ -76,7 +76,8 @@ class Pointwise void recalculate_for_new_pwd2(Piecewise > A); void new_pwd_append(Piecewise > A); void new_pwd_sustract(Piecewise > A); - void set_extremes(std::vector > sats, bool active, bool hidden, double amount, double angle); + void set_extremes(std::vector > &sats, bool active, bool hidden, double amount, double angle); + void reverse(unsigned int start,unsigned int end); void setPathInfo(); void setPathInfo(Piecewise >); unsigned int getSubPathIndex(unsigned int index) const; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 38645a9436..09436676ca 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 045ef2060e..47f023c292 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; diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index eeea47e4d2..5cfc2a0caf 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -175,7 +175,7 @@ void Handle::move(Geom::Point const &new_pos) setPosition(new_pos); //move the handler and its oposite the same proportion - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ setPosition(_pm().BSplineHandleReposition(this,this)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } @@ -192,7 +192,7 @@ void Handle::move(Geom::Point const &new_pos) setRelativePos(new_delta); //move the handler and its oposite the same proportion - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ setPosition(_pm().BSplineHandleReposition(this,this)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } @@ -218,7 +218,7 @@ void Handle::move(Geom::Point const &new_pos) setPosition(new_pos); // moves the handler and its oposite the same proportion - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ setPosition(_pm().BSplineHandleReposition(this,this)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } @@ -313,7 +313,7 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven //this function moves the handler and its oposite to the default proportion of defaultStartPower void Handle::handle_2button_press(){ - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ setPosition(_pm().BSplineHandleReposition(this,defaultStartPower)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),defaultStartPower)); _pm().update(); @@ -373,7 +373,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) new_pos = result; // moves the handler and its oposite in X fixed positions depending on parameter "steps with control" // by default in live BSpline - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ setPosition(new_pos); int steps = _pm().BSplineGetSteps(); new_pos=_pm().BSplineHandleReposition(this,ceilf(_pm().BSplineHandlePosition(this,this)*steps)/steps); @@ -423,7 +423,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) } } //if it is bspline but SHIFT or CONTROL are not pressed it fixes it in the original position - if(_pm().isBSpline() && !held_shift(*event) && !held_control(*event)){ + if(_pm().isBSpline(false) && !held_shift(*event) && !held_control(*event)){ new_pos=_last_drag_origin(); } move(new_pos); // needed for correct update, even though it's redundant @@ -656,7 +656,7 @@ void Node::move(Geom::Point const &new_pos) _fixNeighbors(old_pos, new_pos); // move the affected handlers. First the node ones, later the adjoining ones. - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight)); if(prevNode){ @@ -709,7 +709,7 @@ void Node::transform(Geom::Affine const &m) _fixNeighbors(old_pos, position()); // move the involved handlers, first the node ones, later the adjoining ones - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ _front.setPosition(_pm().BSplineHandleReposition(this->front(),nodeWeight)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),nodeWeight)); if(prevNode){ @@ -916,7 +916,7 @@ void Node::setType(NodeType type, bool update_handles) } /* in node type changes, about bspline traces, we can mantain them with noPower power in border mode, or we give them the default power in curve mode */ - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ double weight = noPower; if(_pm().BSplineHandlePosition(this->front()) != noPower ){ weight = defaultStartPower; @@ -1172,7 +1172,7 @@ void Node::_setState(State state) mgr.setActive(_canvas_item, true); mgr.setPrelight(_canvas_item, false); //this shows the handlers when selecting the nodes - if(_pm().isBSpline()){ + if(_pm().isBSpline(false)){ this->front()->setPosition(_pm().BSplineHandleReposition(this->front())); this->back()->setPosition(_pm().BSplineHandleReposition(this->back())); } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index dbcde240a1..64eba39212 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -670,7 +670,7 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite start = next; } // if we are removing, we readjust the handlers - if(isBSpline()){ + if(isBSpline(false)){ if(start.prev()){ start.prev()->front()->setPosition(BSplineHandleReposition(start.prev()->front(),start.prev()->back())); } @@ -999,7 +999,7 @@ NodeList::iterator PathManipulator::subdivideSegment(NodeList::iterator first, d // set new handle positions Node *n = new Node(_multi_path_manipulator._path_data.node_data, seg2[0]); - if(!isBSpline()){ + if(!isBSpline(false)){ n->back()->setPosition(seg1[2]); n->front()->setPosition(seg2[1]); n->setType(NODE_SMOOTH, false); @@ -1245,7 +1245,7 @@ bool PathManipulator::isBSpline(bool recalculate){ return _is_bspline; } -bool PathManipulator::isBSpline() const { +bool PathManipulator::isBSpline(false) const { return BSplineGetSteps() > 0; } diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 4d2bf4300a..4badec5697 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -107,7 +107,7 @@ private: void _createControlPointsFromGeometry(); - bool isBSpline(bool recalculate = false); + bool isBSpline(bool recalculate); bool isBSpline() const; double BSplineHandlePosition(Handle *h, Handle *h2 = NULL); Geom::Point BSplineHandleReposition(Handle *h, Handle *h2 = NULL); -- GitLab From c1487f9dc277520b8734b7e80387b35c78d979ae Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 22:24:37 +0100 Subject: [PATCH 030/121] Fixed bug whith maps (bzr r13645.1.49) --- src/2geom/pointwise.cpp | 32 ++++++++--------- src/2geom/pointwise.h | 4 +-- src/live_effects/lpe-bspline.cpp | 44 ++++------------------- src/live_effects/lpe-bspline.h | 3 +- src/live_effects/lpe-fillet-chamfer.cpp | 46 ++++++++++++------------- src/ui/tool/multi-path-manipulator.h | 2 +- src/ui/tool/path-manipulator.cpp | 30 ++++++++-------- src/ui/tool/path-manipulator.h | 2 +- 8 files changed, 62 insertions(+), 101 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index f476821ff5..733bd64963 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -36,8 +36,8 @@ namespace Geom { -Pointwise::Pointwise(Piecewise > pwd2) - : _pwd2(pwd2) +Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) + : _pwd2(pwd2),_satellites(satellites),_pathInfo() { setPathInfo(); }; @@ -239,36 +239,34 @@ Pointwise::new_pwd_sustract(Piecewise > A) sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); } } - std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n"; - std::cout << sats.size() << "SAAAAAAAAAAAAAAAAAAAAAAAATTSSIZE\n"; setSatellites(sats); } void -Pointwise::set_extremes(std::vector > &sats, bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) { for(unsigned int i = 0; i < _pathInfo.size(); i++){ unsigned int firstNode = getFirst(_pathInfo[i].first); unsigned int lastNode = getLast(_pathInfo[i].first); if(!getIsClosed(lastNode)){ unsigned int lastIndex = 0; - for(unsigned i = 0; i < sats.size(); i++){ - sats[i].second.setIsEndOpen(false); - if(sats[i].first > lastNode){ + for(unsigned j = 0; j < _satellites.size();j++){ + _satellites[j].second.setIsEndOpen(false); + if(_satellites[j].first > lastNode){ break; } - if(sats[i].first == firstNode){ - sats[i].second.setActive(active); - sats[i].second.setHidden(hidden); - sats[i].second.setAmount(amount); - sats[i].second.setAngle(angle); + if(_satellites[j].first == firstNode){ + _satellites[j].second.setActive(active); + _satellites[j].second.setHidden(hidden); + _satellites[j].second.setAmount(amount); + _satellites[j].second.setAngle(angle); } - if(sats[i].first == lastNode){ - lastIndex = i; + if(_satellites[j].first == lastNode){ + lastIndex = j; } } - Satellite sat(sats[0].second.getSatelliteType(), sats[0].second.getIsTime(), true, active, sats[0].second.getHasMirror(), hidden, amount, angle, sats[0].second.getSteps()); - sats.insert(sats.begin() + lastIndex,std::make_pair(lastNode,sat)); + Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, amount, angle, _satellites[0].second.getSteps()); + _satellites.insert(_satellites.begin() + lastIndex,std::make_pair(lastNode,sat)); } } } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 72ff852d09..f9dc2e47aa 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -63,7 +63,7 @@ namespace Geom { class Pointwise { public: - Pointwise(Piecewise > pwd2); + Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); std::vector findSatellites(unsigned int A, int B = -1) const; std::vector findPeviousSatellites(unsigned int A, int B) const; @@ -76,7 +76,7 @@ class Pointwise void recalculate_for_new_pwd2(Piecewise > A); void new_pwd_append(Piecewise > A); void new_pwd_sustract(Piecewise > A); - void set_extremes(std::vector > &sats, bool active, bool hidden, double amount, double angle); + void set_extremes(bool active, bool hidden, double amount, double angle); void reverse(unsigned int start,unsigned int end); void setPathInfo(); void setPathInfo(Piecewise >); diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index b924d8a236..dba501f42b 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 642562b24e..8017e39efd 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 09436676ca..93c21469ad 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); } } diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index cdbf34e9d4..1bbcdd7ec9 100644 --- a/src/ui/tool/multi-path-manipulator.h +++ b/src/ui/tool/multi-path-manipulator.h @@ -39,7 +39,7 @@ public: virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *event); bool empty() { return _mmap.empty(); } - unsigned size() { return _mmap.empty(); } + unsigned size() { return _mmap.size(); } void setItems(std::set const &); void clear() { _mmap.clear(); } void cleanup(); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 8b735f3e6c..00e18dd3f6 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -11,6 +11,7 @@ */ #include "live_effects/lpe-powerstroke.h" +#include "live_effects/lpe-bspline.h" #include "live_effects/lpe-fillet-chamfer.h" #include #include @@ -20,7 +21,7 @@ #include <2geom/bezier-curve.h> #include <2geom/bezier-utils.h> #include <2geom/path-sink.h> -#include + #include "ui/tool/path-manipulator.h" #include "desktop.h" @@ -33,6 +34,7 @@ #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" + #include "sp-path.h" #include "helper/geom.h" #include "preferences.h" @@ -43,7 +45,7 @@ #include "ui/tool/multi-path-manipulator.h" #include "xml/node.h" #include "xml/node-observer.h" -#include "live_effects/lpe-bspline.h" +#include namespace Inkscape { namespace UI { @@ -151,7 +153,7 @@ PathManipulator::PathManipulator(MultiPathManipulator &mpm, SPPath *path, _createControlPointsFromGeometry(); //Define if the path is BSpline on construction - isBSpline(true); + recalculateIsBSpline(); } PathManipulator::~PathManipulator() @@ -1238,22 +1240,18 @@ int PathManipulator::BSplineGetSteps() const { } // determines if the trace has bspline effect -bool PathManipulator::isBSpline(bool recalculate){ - if(recalculate){ - SPLPEItem * path = dynamic_cast(_path); - if (path){ - if(path->hasPathEffect()){ - Inkscape::LivePathEffect::Effect const *thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); - if(thisEffect){ - _is_bspline = true; - return _is_bspline; - } +void PathManipulator::recalculateIsBSpline(){ + SPLPEItem * path = dynamic_cast(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect const *thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); + if(thisEffect){ + _is_bspline = true; + return; } } - } _is_bspline = false; - return _is_bspline; } bool PathManipulator::isBSpline() const { @@ -1325,7 +1323,7 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) { Geom::PathBuilder builder; //Refresh if is bspline some times -think on path change selection, this value get lost - isBSpline(true); + recalculateIsBSpline(); for (std::list::iterator spi = _subpaths.begin(); spi != _subpaths.end(); ) { SubpathPtr subpath = *spi; if (subpath->empty()) { diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 4badec5697..6dc1c9d09d 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -107,7 +107,7 @@ private: void _createControlPointsFromGeometry(); - bool isBSpline(bool recalculate); + void recalculateIsBSpline(); bool isBSpline() const; double BSplineHandlePosition(Handle *h, Handle *h2 = NULL); Geom::Point BSplineHandleReposition(Handle *h, Handle *h2 = NULL); -- GitLab From 8bd246d8b59749e15de4d5d0d78e9b82fa8a601a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 Mar 2015 18:27:17 +0100 Subject: [PATCH 031/121] Fixed bug when deleting nodes (bzr r13645.1.51) --- src/2geom/pointwise.cpp | 131 ++++++++++-------- src/2geom/pointwise.h | 34 ++--- src/2geom/satellite.cpp | 2 +- src/2geom/satellite.h | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 56 ++++---- src/live_effects/parameter/array.cpp | 10 +- src/live_effects/parameter/array.h | 4 +- .../parameter/satellitepairarray.cpp | 37 ++--- .../parameter/satellitepairarray.h | 8 +- .../dialog/lpe-fillet-chamfer-properties.cpp | 2 +- 10 files changed, 152 insertions(+), 136 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 733bd64963..9669c20b86 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -36,7 +36,7 @@ namespace Geom { -Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) +Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) : _pwd2(pwd2),_satellites(satellites),_pathInfo() { setPathInfo(); @@ -57,14 +57,14 @@ Pointwise::setPwd2(Piecewise > pwd2_in) setPathInfo(); } -std::vector > +std::vector > Pointwise::getSatellites() const { return _satellites; } void -Pointwise::setSatellites(std::vector > sats) +Pointwise::setSatellites(std::vector > sats) { _satellites = sats; } @@ -81,7 +81,7 @@ Pointwise::setPathInfo(Piecewise > pwd2) { _pathInfo.clear(); std::vector path_in = path_from_piecewise(remove_short_cuts(pwd2,0.1), 0.001); - unsigned int counter = 0; + size_t counter = 0; for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()){ continue; @@ -106,10 +106,10 @@ Pointwise::setPathInfo(Piecewise > pwd2) } } -unsigned int -Pointwise::getSubPathIndex(unsigned int index) const +size_t +Pointwise::getSubPathIndex(size_t index) const { - for(unsigned int i = 0; i < _pathInfo.size(); i++){ + for(size_t i = 0; i < _pathInfo.size(); i++){ if(index <= _pathInfo[i].first){ return i; } @@ -117,10 +117,10 @@ Pointwise::getSubPathIndex(unsigned int index) const return 0; } -unsigned int -Pointwise::getLast(unsigned int index) const +size_t +Pointwise::getLast(size_t index) const { - for(unsigned int i = 0; i < _pathInfo.size(); i++){ + for(size_t i = 0; i < _pathInfo.size(); i++){ if(index <= _pathInfo[i].first){ return _pathInfo[i].first; } @@ -128,10 +128,10 @@ Pointwise::getLast(unsigned int index) const return 0; } -unsigned int -Pointwise::getFirst(unsigned int index) const +size_t +Pointwise::getFirst(size_t index) const { - for(unsigned int i = 0; i < _pathInfo.size(); i++){ + for(size_t i = 0; i < _pathInfo.size(); i++){ if(index <= _pathInfo[i].first){ if(i==0){ return 0; @@ -143,8 +143,8 @@ Pointwise::getFirst(unsigned int index) const return 0; } -boost::optional -Pointwise::getPrevious(unsigned int index) const +boost::optional +Pointwise::getPrevious(size_t index) const { if(getFirst(index) == index && getIsClosed(index)){ return getLast(index); @@ -155,8 +155,8 @@ Pointwise::getPrevious(unsigned int index) const return index - 1; } -boost::optional -Pointwise::getNext(unsigned int index) const +boost::optional +Pointwise::getNext(size_t index) const { if(getLast(index) == index && getIsClosed(index)){ return getFirst(index); @@ -168,9 +168,9 @@ Pointwise::getNext(unsigned int index) const } bool -Pointwise::getIsClosed(unsigned int index) const +Pointwise::getIsClosed(size_t index) const { - for(unsigned int i = 0; i < _pathInfo.size(); i++){ + for(size_t i = 0; i < _pathInfo.size(); i++){ if(index <= _pathInfo[i].first){ return _pathInfo[i].second; } @@ -192,14 +192,14 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) void Pointwise::new_pwd_append(Piecewise > A) { - unsigned int counter = 0; - std::vector > sats; - for(unsigned i = 0; i < _satellites.size(); i++){ + size_t counter = 0; + std::vector > sats; + for(size_t i = 0; i < _satellites.size(); i++){ if(_satellites[i].second.getIsEndOpen()){ _satellites.erase(_satellites.begin() + i); } } - for(unsigned i = 0; i < A.size(); i++){ + for(size_t i = 0; i < A.size(); i++){ if(!are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ counter++; bool isEndOpen = false; @@ -223,16 +223,16 @@ Pointwise::new_pwd_append(Piecewise > A) void Pointwise::new_pwd_sustract(Piecewise > A) { - int counter = 0; - std::vector > sats; - Piecewise > pwd2 = _pwd2; - setPwd2(A); - for(unsigned i = 0; i < _satellites.size(); i++){ + size_t counter = 0; + std::vector > sats; + for(size_t i = 0; i < _satellites.size(); i++){ if(_satellites[i].second.getIsEndOpen()){ _satellites.erase(_satellites.begin() + i); } } - for(unsigned i = 0; i < _satellites.size(); i++){ + Piecewise > pwd2 = _pwd2; + setPwd2(A); + for(size_t i = 0; i < _satellites.size(); i++){ if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ counter++; } else { @@ -243,48 +243,59 @@ Pointwise::new_pwd_sustract(Piecewise > A) } void -Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(bool endOpenSat,bool active, bool hidden, double amount, double angle) { - for(unsigned int i = 0; i < _pathInfo.size(); i++){ - unsigned int firstNode = getFirst(_pathInfo[i].first); - unsigned int lastNode = getLast(_pathInfo[i].first); + for(size_t i = 0; i < _pathInfo.size(); i++){ + size_t firstNode = getFirst(_pathInfo[i].first); + size_t lastNode = getLast(_pathInfo[i].first); if(!getIsClosed(lastNode)){ - unsigned int lastIndex = 0; - for(unsigned j = 0; j < _satellites.size();j++){ - _satellites[j].second.setIsEndOpen(false); - if(_satellites[j].first > lastNode){ - break; + long lastIndex = -1; + for(size_t j = 0; j < _satellites.size(); j++){ + if(_satellites[j].first < firstNode || _satellites[j].first > lastNode){ + continue; } + _satellites[j].second.setIsEndOpen(false); if(_satellites[j].first == firstNode){ _satellites[j].second.setActive(active); _satellites[j].second.setHidden(hidden); - _satellites[j].second.setAmount(amount); - _satellites[j].second.setAngle(angle); + if(amount >= 0){ + _satellites[j].second.setAmount(amount); + } + if(angle >= 0){ + _satellites[j].second.setAngle(angle); + } + } + + if(_satellites[j].first == lastNode && lastIndex != -1){ + _satellites[j].second.setIsEndOpen(true); } - if(_satellites[j].first == lastNode){ + + if(_satellites[j].first == lastNode && lastIndex == -1){ lastIndex = j; } } - Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, amount, angle, _satellites[0].second.getSteps()); - _satellites.insert(_satellites.begin() + lastIndex,std::make_pair(lastNode,sat)); + if(endOpenSat){ + Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); + _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); + } } } } void -Pointwise::reverse(unsigned int start,unsigned int end){ - for(unsigned int i = start; i < end / 2; i++){ - std::pair tmp = _satellites[i]; +Pointwise::reverse(size_t start,size_t end){ + for(size_t i = start; i < end / 2; i++){ + std::pair tmp = _satellites[i]; _satellites[i] = _satellites[end - start - i - 1]; _satellites[end - start - i - 1] = tmp; } } double -Pointwise::rad_to_len(double A, std::pair sat) const +Pointwise::rad_to_len(double A, std::pair sat) const { double len = 0; - boost::optional d2_prev_index = getPrevious(sat.first); + boost::optional d2_prev_index = getPrevious(sat.first); if(d2_prev_index){ Geom::D2 d2_in = _pwd2[*d2_prev_index]; Geom::D2 d2_out = _pwd2[sat.first]; @@ -307,9 +318,9 @@ Pointwise::rad_to_len(double A, std::pair sat) co } double -Pointwise::len_to_rad(double A, std::pair sat) const +Pointwise::len_to_rad(double A, std::pair sat) const { - boost::optional d2_prev_index = getPrevious(sat.first); + boost::optional d2_prev_index = getPrevious(sat.first); if(d2_prev_index){ Geom::D2 d2_in = _pwd2[*d2_prev_index]; Geom::D2 d2_out = _pwd2[sat.first]; @@ -348,14 +359,14 @@ Pointwise::len_to_rad(double A, std::pair sat) co return 0; } -std::vector -Pointwise::findSatellites(unsigned int A, int B) const +std::vector +Pointwise::findSatellites(size_t A, long B) const { - std::vector ret; - int counter = 0; - for(unsigned i = 0; i < _satellites.size(); i++){ + std::vector ret; + long counter = 0; + for(size_t i = 0; i < _satellites.size(); i++){ if(_satellites[i].first == A){ - if(counter >= B && B != -1){ + if(counter >= B && B != (long)-1){ return ret; } ret.push_back(i); @@ -365,11 +376,11 @@ Pointwise::findSatellites(unsigned int A, int B) const return ret; } -std::vector -Pointwise::findPeviousSatellites(unsigned int A, int B) const +std::vector +Pointwise::findPeviousSatellites(size_t A, long B) const { - boost::optional previous = getPrevious(A); - std::vector ret; + boost::optional previous = getPrevious(A); + std::vector ret; if(previous){ ret = findSatellites(*previous,B); } diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index f9dc2e47aa..a7cbcfec4d 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -63,34 +63,34 @@ namespace Geom { class Pointwise { public: - Pointwise(Piecewise > pwd2, std::vector > satellites); + Pointwise(Piecewise > pwd2, std::vector > satellites); virtual ~Pointwise(); - std::vector findSatellites(unsigned int A, int B = -1) const; - std::vector findPeviousSatellites(unsigned int A, int B) const; - double rad_to_len(double A, std::pair sat) const; - double len_to_rad(double A, std::pair sat) const; - std::vector > getSatellites() const; - void setSatellites(std::vector > sats); + std::vector findSatellites(size_t A, long B = -1) const; + std::vector findPeviousSatellites(size_t A, long B) const; + double rad_to_len(double A, std::pair sat) const; + double len_to_rad(double A, std::pair sat) const; + std::vector > getSatellites() const; + void setSatellites(std::vector > sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); void recalculate_for_new_pwd2(Piecewise > A); void new_pwd_append(Piecewise > A); void new_pwd_sustract(Piecewise > A); - void set_extremes(bool active, bool hidden, double amount, double angle); - void reverse(unsigned int start,unsigned int end); + void set_extremes(bool endOpenSat, bool active, bool hidden, double amount = -1, double angle = -1); + void reverse(size_t start,size_t end); void setPathInfo(); void setPathInfo(Piecewise >); - unsigned int getSubPathIndex(unsigned int index) const; - unsigned int getLast(unsigned int index) const; - unsigned int getFirst(unsigned int index) const; - boost::optional getPrevious(unsigned int index) const; - boost::optional getNext(unsigned int index) const; - bool getIsClosed(unsigned int index) const; + size_t getSubPathIndex(size_t index) const; + size_t getLast(size_t index) const; + size_t getFirst(size_t index) const; + boost::optional getPrevious(size_t index) const; + boost::optional getNext(size_t index) const; + bool getIsClosed(size_t index) const; private: Piecewise > _pwd2; - std::vector > _satellites; - std::vector > _pathInfo; + std::vector > _satellites; + std::vector > _pathInfo; }; } // end namespace Geom diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 509c0e0747..d1420b20ca 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,7 +40,7 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps) +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) : _satellitetype(satellitetype), _isTime(isTime), _isEndOpen(isEndOpen), _active(active), _hasMirror(hasMirror), _hidden(hidden), _amount(amount), _angle(angle), _steps(steps){}; Satellite::~Satellite() {}; diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 43863d71fc..42ed9c2913 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -45,7 +45,7 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, unsigned int steps); + Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); virtual ~Satellite(); @@ -169,7 +169,7 @@ class Satellite bool _hidden; double _amount; double _angle; - unsigned int _steps; + size_t _steps; }; } // end namespace Geom diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 93c21469ad..6b388b0f6b 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 d8b2388da8..33cb53f4eb 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 7ff477ffb4..4fb053dbb9 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 47f023c292..8102edf9b0 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 9b22a386b8..a85e3f83f5 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 diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index aa27a1414a..6875799f8e 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -177,7 +177,7 @@ void FilletChamferPropertiesDialog::_apply() d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); } _satellite.setAmount( d_pos); - unsigned int steps = (unsigned int)_fillet_chamfer_chamfer_subdivisions.get_value(); + size_t steps = (size_t)_fillet_chamfer_chamfer_subdivisions.get_value(); if(steps < 1){ steps = 1; } -- GitLab From edc48d93d2b528c20b9adb0f7d074c73c46f03eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Mar 2015 00:01:44 +0100 Subject: [PATCH 032/121] adding append mode (bzr r13645.1.54) --- src/2geom/pointwise.cpp | 31 ++++++++++++++----------- src/2geom/pointwise.h | 4 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 4 +++- src/ui/tool/path-manipulator.cpp | 1 - 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 9669c20b86..b97f8749f8 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -183,45 +183,48 @@ void Pointwise::recalculate_for_new_pwd2(Piecewise > A) { if( _pwd2.size() > A.size()){ - new_pwd_sustract(A); + std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbb\n"; + pwd2_sustract(A); } else if ( _pwd2.size() < A.size()){ - new_pwd_append(A); + pwd2_append(A); + std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"; } + std::cout << "cccccccccccccccccccccccccccccccccc\n"; } void -Pointwise::new_pwd_append(Piecewise > A) +Pointwise::pwd2_append(Piecewise > A) { size_t counter = 0; std::vector > sats; - for(size_t i = 0; i < _satellites.size(); i++){ - if(_satellites[i].second.getIsEndOpen()){ - _satellites.erase(_satellites.begin() + i); - } - } + Piecewise > pwd2 = _pwd2; + setPwd2(A); + std::cout << A.size() << "ASIZE\n"; + std::cout << pwd2.size() << "PWD2SIZE\n"; for(size_t i = 0; i < A.size(); i++){ - if(!are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + std::cout << i << "indes\n"; + std::cout << counter << "counter\n"; + if(pwd2.size() <= i-counter || !are_near(pwd2[i-counter].at0(),A[i].at0(),0.001)){ counter++; bool isEndOpen = false; bool active = true; bool hidden = false; - bool isTime = sats[0].second.getIsTime(); - bool mirror_knots = sats[0].second.getHasMirror(); + bool isTime = _satellites[0].second.getIsTime(); + bool mirror_knots = _satellites[0].second.getHasMirror(); double amount = 0.0; double degrees = 0.0; int steps = 0; - Satellite sat(sats[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); + Satellite sat(_satellites[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); sats.push_back(std::make_pair(i,sat)); } else { sats.push_back(std::make_pair(i,_satellites[i-counter].second)); } } - setPwd2(A); setSatellites(sats); } void -Pointwise::new_pwd_sustract(Piecewise > A) +Pointwise::pwd2_sustract(Piecewise > A) { size_t counter = 0; std::vector > sats; diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index a7cbcfec4d..296eb6ca65 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -74,8 +74,8 @@ class Pointwise Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); void recalculate_for_new_pwd2(Piecewise > A); - void new_pwd_append(Piecewise > A); - void new_pwd_sustract(Piecewise > A); + void pwd2_append(Piecewise > A); + void pwd2_sustract(Piecewise > A); void set_extremes(bool endOpenSat, bool active, bool hidden, double amount = -1, double angle = -1); void reverse(size_t start,size_t end); void setPathInfo(); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6b388b0f6b..55e1f93aa6 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); } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index d2bdd93845..ccf75dcded 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -34,7 +34,6 @@ #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" - #include "sp-path.h" #include "helper/geom.h" #include "preferences.h" -- GitLab From 13df14f4cf6b48cf01ac54ba0322f50a143c007e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Mar 2015 13:49:37 +0100 Subject: [PATCH 033/121] adding append mode (bzr r13645.1.55) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 55e1f93aa6..2fc2027ab8 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); -- GitLab From a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 12:56:46 +0200 Subject: [PATCH 034/121] end append path (bzr r13645.1.57) --- src/2geom/pointwise.cpp | 174 +++++++++++++++--- src/2geom/pointwise.h | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 64 ++++--- src/live_effects/lpe-fillet-chamfer.h | 1 + .../parameter/satellitepairarray.cpp | 23 ++- .../parameter/satellitepairarray.h | 1 + 6 files changed, 207 insertions(+), 60 deletions(-) diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index b97f8749f8..bc82780d76 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -183,13 +183,10 @@ void Pointwise::recalculate_for_new_pwd2(Piecewise > A) { if( _pwd2.size() > A.size()){ - std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbb\n"; pwd2_sustract(A); - } else if ( _pwd2.size() < A.size()){ + } else if (_pwd2.size() < A.size()){ pwd2_append(A); - std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"; } - std::cout << "cccccccccccccccccccccccccccccccccc\n"; } void @@ -197,14 +194,39 @@ Pointwise::pwd2_append(Piecewise > A) { size_t counter = 0; std::vector > sats; - Piecewise > pwd2 = _pwd2; - setPwd2(A); - std::cout << A.size() << "ASIZE\n"; - std::cout << pwd2.size() << "PWD2SIZE\n"; + for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->second.getIsEndOpen()){ + it = _satellites.erase(it); + } else { + ++it; + } + } + bool reversed = false; + bool reorder = false; for(size_t i = 0; i < A.size(); i++){ - std::cout << i << "indes\n"; - std::cout << counter << "counter\n"; - if(pwd2.size() <= i-counter || !are_near(pwd2[i-counter].at0(),A[i].at0(),0.001)){ + size_t first = getFirst(i-counter); + size_t last = getLast(i-counter); + setPathInfo(A); + size_t subpathAIndex = getSubPathIndex(i); + setPathInfo(_pwd2); + bool changedSubpath = false; + if(_pwd2.size() <= i-counter){ + changedSubpath = false; + } else { + changedSubpath = subpathAIndex != getSubPathIndex(i-counter); + } + if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + subpath_append_reorder(getSubPathIndex(first)); + reorder = true; + i--; + continue; + } + if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + reverse(first, last); + reversed = true; + } + if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ counter++; bool isEndOpen = false; bool active = true; @@ -217,9 +239,13 @@ Pointwise::pwd2_append(Piecewise > A) Satellite sat(_satellites[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); sats.push_back(std::make_pair(i,sat)); } else { - sats.push_back(std::make_pair(i,_satellites[i-counter].second)); + std::vector satsFind = findSatellites(i-counter,999); + for(size_t j = 0; j< satsFind.size(); j++){ + sats.push_back(std::make_pair(i,_satellites[satsFind[j]].second)); + } } } + setPwd2(A); setSatellites(sats); } @@ -228,9 +254,12 @@ Pointwise::pwd2_sustract(Piecewise > A) { size_t counter = 0; std::vector > sats; - for(size_t i = 0; i < _satellites.size(); i++){ - if(_satellites[i].second.getIsEndOpen()){ - _satellites.erase(_satellites.begin() + i); + for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->second.getIsEndOpen()){ + it = _satellites.erase(it); + } else { + ++it; } } Piecewise > pwd2 = _pwd2; @@ -239,14 +268,17 @@ Pointwise::pwd2_sustract(Piecewise > A) if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ counter++; } else { - sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + std::vector satsFind = findSatellites(_satellites[i].first-counter,999); + for(size_t j = 0; j< satsFind.size(); j++){ + sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[satsFind[j]].second)); + } } } setSatellites(sats); } void -Pointwise::set_extremes(bool endOpenSat,bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) { for(size_t i = 0; i < _pathInfo.size(); i++){ size_t firstNode = getFirst(_pathInfo[i].first); @@ -268,30 +300,96 @@ Pointwise::set_extremes(bool endOpenSat,bool active, bool hidden, double amount, _satellites[j].second.setAngle(angle); } } - - if(_satellites[j].first == lastNode && lastIndex != -1){ - _satellites[j].second.setIsEndOpen(true); - } - if(_satellites[j].first == lastNode && lastIndex == -1){ lastIndex = j; } } - if(endOpenSat){ - Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); - _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); + Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); + _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); + } else { + for(size_t j = 0; j < _satellites.size(); j++){ + if(_satellites[j].first < firstNode){ + continue; + } + if(_satellites[j].first == firstNode && !_satellites[j].second.getActive()){ + _satellites[j].second.setActive(true); + _satellites[j].second.setHidden(_satellites[j+1].second.getHidden()); + } + + } + } + } +} + +void +Pointwise::subpath_append_reorder(size_t subpath){ + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t nSubpath = 0; + size_t counter = 0; + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); + 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) { + if(nSubpath == subpath){ + std::vector sats = findSatellites(counter,999); + for(size_t i = 0; i< sats.size(); i++){ + _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[i]].second)); + } + deleteSatellites(counter); + } else { + counter++; } + ++curve_it1; } + if(nSubpath == subpath){ + rev = *path_it; + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; } + tmp_path.push_back(rev); + setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); } void Pointwise::reverse(size_t start,size_t end){ - for(size_t i = start; i < end / 2; i++){ - std::pair tmp = _satellites[i]; - _satellites[i] = _satellites[end - start - i - 1]; - _satellites[end - start - i - 1] = tmp; + start ++; + for(size_t i = end; i >= start; i--){ + std::vector sats = findSatellites(i,999); + for(size_t j = 0; j< sats.size(); j++){ + _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[j]].second)); + } + deleteSatellites(i); } + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + size_t nSubpath = 0; + size_t subpath = getSubPathIndex(start); + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + counter ++; + if(nSubpath == subpath){ + tmp_path.push_back(path_it->reverse()); + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); } double @@ -362,6 +460,24 @@ Pointwise::len_to_rad(double A, std::pair sat) const return 0; } +void +Pointwise::deleteSatellites(size_t A) +{ + bool erased = false; + for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->first == A){ + it = _satellites.erase(it); + erased = true; + } else { + if(erased){ + it->first = it->first-1; + } + ++it; + } + } +} + std::vector Pointwise::findSatellites(size_t A, long B) const { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 296eb6ca65..df39974928 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -76,7 +76,9 @@ class Pointwise void recalculate_for_new_pwd2(Piecewise > A); void pwd2_append(Piecewise > A); void pwd2_sustract(Piecewise > A); - void set_extremes(bool endOpenSat, bool active, bool hidden, double amount = -1, double angle = -1); + void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); + void deleteSatellites(size_t A); + void subpath_append_reorder(size_t subpath); void reverse(size_t start,size_t end); void setPathInfo(); void setPathInfo(Piecewise >); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2fc2027ab8..0502a41924 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 1bedbefa49..89d91265aa 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 8102edf9b0..3876dc8dfe 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 a85e3f83f5..462f1017c5 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); -- GitLab From 7acc0ec6f6a0756b73baa2bc815113984f6f3ea6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 13:23:02 +0200 Subject: [PATCH 035/121] change pointwise comment (bzr r13645.1.59) --- src/2geom/pointwise.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index df39974928..0eb7c70733 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -12,8 +12,6 @@ * positions to preserve the intent. * The data is serialised to SVG using a specialiced pointwise LPE parameter to * handle it in th future can be a inkscape based property to paths - * //all operations are O(1) per satellite, with the exception of .., .., and .., which - * //need to use binary search to find the locations. * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing * existing algorithms to correctly update satellite positions. -- GitLab From 842a3a6415e837f502671ff098525bba9d8a0362 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 13:50:29 +0200 Subject: [PATCH 036/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0502a41924..0f767435f6 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 3876dc8dfe..dd67be6a10 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 462f1017c5..fcd3bd7366 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; -- GitLab From a309dd74bad06a293cae9f70f575024eed0b652a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:50:35 +0200 Subject: [PATCH 037/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0f767435f6..6775fa0006 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 dd67be6a10..0748269f44 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); -- GitLab From cb6f3fcd6fc271c32e1a1afcf946b7ca75a161d7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:51:21 +0200 Subject: [PATCH 038/121] removed code comments (bzr r13645.1.62) --- src/live_effects/parameter/satellitepairarray.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0748269f44..461a6b54e1 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); -- GitLab From dff3aa428ff050c2cce501f646977ddad921feca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 04:13:16 +0200 Subject: [PATCH 039/121] 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) --- po/POTFILES.in | 2 +- src/2geom/Makefile_insert | 4 - src/2geom/pointwise.cpp | 519 ------------------ src/2geom/satellite.cpp | 156 ------ src/helper/Makefile_insert | 7 + src/helper/geom-pathinfo.cpp | 178 ++++++ src/helper/geom-pathinfo.h | 81 +++ src/helper/geom-pointwise.cpp | 268 +++++++++ .../pointwise.h => helper/geom-pointwise.h} | 28 +- .../geom-satellite-enum.h} | 0 src/helper/geom-satellite.cpp | 237 ++++++++ .../satellite.h => helper/geom-satellite.h} | 133 +---- 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 +- ...ellitepairarray.cpp => satellitearray.cpp} | 159 +++--- ...{satellitepairarray.h => satellitearray.h} | 18 +- .../dialog/lpe-fillet-chamfer-properties.cpp | 24 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 2 +- 22 files changed, 1049 insertions(+), 1072 deletions(-) delete mode 100644 src/2geom/pointwise.cpp delete mode 100644 src/2geom/satellite.cpp create mode 100644 src/helper/geom-pathinfo.cpp create mode 100644 src/helper/geom-pathinfo.h create mode 100644 src/helper/geom-pointwise.cpp rename src/{2geom/pointwise.h => helper/geom-pointwise.h} (72%) rename src/{2geom/satellite-enum.h => helper/geom-satellite-enum.h} (100%) create mode 100644 src/helper/geom-satellite.cpp rename src/{2geom/satellite.h => helper/geom-satellite.h} (51%) rename src/live_effects/parameter/{satellitepairarray.cpp => satellitearray.cpp} (73%) rename src/live_effects/parameter/{satellitepairarray.h => satellitearray.h} (87%) diff --git a/po/POTFILES.in b/po/POTFILES.in index d1aef8eadc..96be5baf77 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -160,7 +160,7 @@ src/live_effects/lpe-taperstroke.cpp src/live_effects/lpe-vonkoch.cpp src/live_effects/parameter/bool.cpp src/live_effects/parameter/enum.h -src/live_effects/parameter/satellitepairarray.cpp +src/live_effects/parameter/satellitearray.cpp src/live_effects/parameter/originalpath.cpp src/live_effects/parameter/originalpatharray.cpp src/live_effects/parameter/parameter.cpp diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index 8872065fb7..e77f413cb2 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -80,8 +80,6 @@ 2geom/point.cpp \ 2geom/point.h \ 2geom/point-ops.h \ - 2geom/pointwise.cpp \ - 2geom/pointwise.h \ 2geom/poly.cpp \ 2geom/poly.h \ 2geom/quadtree.cpp \ @@ -92,8 +90,6 @@ 2geom/recursive-bezier-intersection.cpp \ 2geom/region.cpp \ 2geom/region.h \ - 2geom/satellite.cpp \ - 2geom/satellite.h \ 2geom/sbasis-2d.cpp \ 2geom/sbasis-2d.h \ 2geom/sbasis.cpp \ diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp deleted file mode 100644 index bc82780d76..0000000000 --- a/src/2geom/pointwise.cpp +++ /dev/null @@ -1,519 +0,0 @@ -/* - * pointwise.cpp - * Authors: - * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - * - */ - -#include <2geom/pointwise.h> -#include <2geom/ray.h> -#include <2geom/path-intersection.h> -#include - -namespace Geom { - -Pointwise::Pointwise(Piecewise > pwd2, std::vector > satellites) - : _pwd2(pwd2),_satellites(satellites),_pathInfo() -{ - setPathInfo(); -}; - -Pointwise::~Pointwise(){}; - -Piecewise > -Pointwise::getPwd2() const -{ - return _pwd2; -} - -void -Pointwise::setPwd2(Piecewise > pwd2_in) -{ - _pwd2 = pwd2_in; - setPathInfo(); -} - -std::vector > -Pointwise::getSatellites() const -{ - return _satellites; -} - -void -Pointwise::setSatellites(std::vector > sats) -{ - _satellites = sats; -} - -//START QUESTION Next functions maybe is beter land outside the class? -void -Pointwise::setPathInfo() -{ - setPathInfo(_pwd2); -} - -void -Pointwise::setPathInfo(Piecewise > pwd2) -{ - _pathInfo.clear(); - std::vector path_in = path_from_piecewise(remove_short_cuts(pwd2,0.1), 0.001); - size_t counter = 0; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - ++curve_it1; - counter++; - } - if(path_it->closed()){ - _pathInfo.push_back(std::make_pair(counter-1,true)); - } else { - _pathInfo.push_back(std::make_pair(counter-1,false)); - } - } -} - -size_t -Pointwise::getSubPathIndex(size_t index) const -{ - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return i; - } - } - return 0; -} - -size_t -Pointwise::getLast(size_t index) const -{ - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].first; - } - } - return 0; -} - -size_t -Pointwise::getFirst(size_t index) const -{ - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - if(i==0){ - return 0; - } else { - return _pathInfo[i-1].first + 1; - } - } - } - return 0; -} - -boost::optional -Pointwise::getPrevious(size_t index) const -{ - if(getFirst(index) == index && getIsClosed(index)){ - return getLast(index); - } - if(getFirst(index) == index && !getIsClosed(index)){ - return boost::none; - } - return index - 1; -} - -boost::optional -Pointwise::getNext(size_t index) const -{ - if(getLast(index) == index && getIsClosed(index)){ - return getFirst(index); - } - if(getLast(index) == index && !getIsClosed(index)){ - return boost::none; - } - return index + 1; -} - -bool -Pointwise::getIsClosed(size_t index) const -{ - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].second; - } - } - return false; -} -//END QUESTION - -void -Pointwise::recalculate_for_new_pwd2(Piecewise > A) -{ - if( _pwd2.size() > A.size()){ - pwd2_sustract(A); - } else if (_pwd2.size() < A.size()){ - pwd2_append(A); - } -} - -void -Pointwise::pwd2_append(Piecewise > A) -{ - size_t counter = 0; - std::vector > sats; - for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) - { - if(it->second.getIsEndOpen()){ - it = _satellites.erase(it); - } else { - ++it; - } - } - bool reversed = false; - bool reorder = false; - for(size_t i = 0; i < A.size(); i++){ - size_t first = getFirst(i-counter); - size_t last = getLast(i-counter); - setPathInfo(A); - size_t subpathAIndex = getSubPathIndex(i); - setPathInfo(_pwd2); - bool changedSubpath = false; - if(_pwd2.size() <= i-counter){ - changedSubpath = false; - } else { - changedSubpath = subpathAIndex != getSubPathIndex(i-counter); - } - if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_append_reorder(getSubPathIndex(first)); - reorder = true; - i--; - continue; - } - if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - reverse(first, last); - reversed = true; - } - if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ - counter++; - bool isEndOpen = false; - bool active = true; - bool hidden = false; - bool isTime = _satellites[0].second.getIsTime(); - bool mirror_knots = _satellites[0].second.getHasMirror(); - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(_satellites[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); - sats.push_back(std::make_pair(i,sat)); - } else { - std::vector satsFind = findSatellites(i-counter,999); - for(size_t j = 0; j< satsFind.size(); j++){ - sats.push_back(std::make_pair(i,_satellites[satsFind[j]].second)); - } - } - } - setPwd2(A); - setSatellites(sats); -} - -void -Pointwise::pwd2_sustract(Piecewise > A) -{ - size_t counter = 0; - std::vector > sats; - for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) - { - if(it->second.getIsEndOpen()){ - it = _satellites.erase(it); - } else { - ++it; - } - } - Piecewise > pwd2 = _pwd2; - setPwd2(A); - for(size_t i = 0; i < _satellites.size(); i++){ - if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ - counter++; - } else { - std::vector satsFind = findSatellites(_satellites[i].first-counter,999); - for(size_t j = 0; j< satsFind.size(); j++){ - sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[satsFind[j]].second)); - } - } - } - setSatellites(sats); -} - -void -Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) -{ - for(size_t i = 0; i < _pathInfo.size(); i++){ - size_t firstNode = getFirst(_pathInfo[i].first); - size_t lastNode = getLast(_pathInfo[i].first); - if(!getIsClosed(lastNode)){ - long lastIndex = -1; - for(size_t j = 0; j < _satellites.size(); j++){ - if(_satellites[j].first < firstNode || _satellites[j].first > lastNode){ - continue; - } - _satellites[j].second.setIsEndOpen(false); - if(_satellites[j].first == firstNode){ - _satellites[j].second.setActive(active); - _satellites[j].second.setHidden(hidden); - if(amount >= 0){ - _satellites[j].second.setAmount(amount); - } - if(angle >= 0){ - _satellites[j].second.setAngle(angle); - } - } - if(_satellites[j].first == lastNode && lastIndex == -1){ - lastIndex = j; - } - } - Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); - _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); - } else { - for(size_t j = 0; j < _satellites.size(); j++){ - if(_satellites[j].first < firstNode){ - continue; - } - if(_satellites[j].first == firstNode && !_satellites[j].second.getActive()){ - _satellites[j].second.setActive(true); - _satellites[j].second.setHidden(_satellites[j+1].second.getHidden()); - } - - } - } - } -} - -void -Pointwise::subpath_append_reorder(size_t subpath){ - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); - size_t nSubpath = 0; - size_t counter = 0; - std::vector tmp_path; - Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); - 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) { - if(nSubpath == subpath){ - std::vector sats = findSatellites(counter,999); - for(size_t i = 0; i< sats.size(); i++){ - _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[i]].second)); - } - deleteSatellites(counter); - } else { - counter++; - } - ++curve_it1; - } - if(nSubpath == subpath){ - rev = *path_it; - } else { - tmp_path.push_back(*path_it); - } - nSubpath++; - } - tmp_path.push_back(rev); - setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); -} - -void -Pointwise::reverse(size_t start,size_t end){ - start ++; - for(size_t i = end; i >= start; i--){ - std::vector sats = findSatellites(i,999); - for(size_t j = 0; j< sats.size(); j++){ - _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[j]].second)); - } - deleteSatellites(i); - } - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); - size_t counter = 0; - size_t nSubpath = 0; - size_t subpath = getSubPathIndex(start); - std::vector tmp_path; - Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ - continue; - } - counter ++; - if(nSubpath == subpath){ - tmp_path.push_back(path_it->reverse()); - } else { - tmp_path.push_back(*path_it); - } - nSubpath++; - } - setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); -} - -double -Pointwise::rad_to_len(double A, std::pair sat) const -{ - double len = 0; - boost::optional d2_prev_index = getPrevious(sat.first); - if(d2_prev_index){ - Geom::D2 d2_in = _pwd2[*d2_prev_index]; - Geom::D2 d2_out = _pwd2[sat.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 = sat.second.toSize(p0pt,d2_out); - } else { - if(A > 0){ - len = rad_to_len(A * -1, sat); - } - } - } - return len; -} - -double -Pointwise::len_to_rad(double A, std::pair sat) const -{ - boost::optional d2_prev_index = getPrevious(sat.first); - if(d2_prev_index){ - Geom::D2 d2_in = _pwd2[*d2_prev_index]; - Geom::D2 d2_out = _pwd2[sat.first]; - double time_in = sat.second.getOpositeTime(A, d2_in); - double time_out = sat.second.toTime(A,d2_out); - Geom::Point startArcPoint = (d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Piecewise > u; - u.push_cut(0); - u.push((d2_in), 1); - Geom::Curve * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Piecewise > u2; - u2.push_cut(0); - u2.push((d2_out), 1); - Geom::Curve * B = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Curve *knotCurve1 = A->portion(0, time_in); - Curve *knotCurve2 = B->portion(time_out, 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (d2_in).valueAt(1)); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(d2_out.valueAt(0), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - 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); - double divisor = std::sin(angleBetween/2.0); - if(divisor > 0){ - return distanceArc/divisor; - } - } - return 0; -} - -void -Pointwise::deleteSatellites(size_t A) -{ - bool erased = false; - for (std::vector >::iterator it=_satellites.begin(); it!=_satellites.end();) - { - if(it->first == A){ - it = _satellites.erase(it); - erased = true; - } else { - if(erased){ - it->first = it->first-1; - } - ++it; - } - } -} - -std::vector -Pointwise::findSatellites(size_t A, long B) const -{ - std::vector ret; - long counter = 0; - for(size_t i = 0; i < _satellites.size(); i++){ - if(_satellites[i].first == A){ - if(counter >= B && B != (long)-1){ - return ret; - } - ret.push_back(i); - counter++; - } - } - return ret; -} - -std::vector -Pointwise::findPeviousSatellites(size_t A, long B) const -{ - boost::optional previous = getPrevious(A); - std::vector ret; - if(previous){ - ret = findSatellites(*previous,B); - } - return ret; -} - -} -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp deleted file mode 100644 index d1420b20ca..0000000000 --- a/src/2geom/satellite.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * \file - * \brief Satellite - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. - */ - -#include <2geom/satellite.h> -#include <2geom/curve.h> -#include <2geom/nearest-point.h> -#include <2geom/sbasis-geometric.h> - - -namespace Geom { - -Satellite::Satellite(){}; - -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) - : _satellitetype(satellitetype), _isTime(isTime), _isEndOpen(isEndOpen), _active(active), _hasMirror(hasMirror), _hidden(hidden), _amount(amount), _angle(angle), _steps(steps){}; - -Satellite::~Satellite() {}; - -double -Satellite::toTime(double A,Geom::D2 d2_in) const -{ - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ - return 0; - } - double t = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - if (lenghtPart != 0) { - t = A / lenghtPart; - } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } - - return t; -} - -double -Satellite::toSize(double A,Geom::D2 d2_in) const -{ - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ - return 0; - } - double s = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - s = (A * lenghtPart); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); - } - return s; -} - -double -Satellite::getOpositeTime(double s, Geom::D2 d2_in) const -{ - if(s == 0){ - return 1; - } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - double size = lenghtPart - s; - return toTime(size, d2_in); -} - -double -Satellite::getTime(Geom::D2 d2_in) const -{ - double t = getAmount(); - if(!getIsTime()){ - t = toTime(t, d2_in); - } - if(t > 1){ - t = 1; - } - return t; -} - -double -Satellite::getSize(Geom::D2 d2_in) const -{ - double s = getAmount(); - if(getIsTime()){ - s = toSize(s, d2_in); - } - return s; -} - - -Geom::Point -Satellite::getPosition(Geom::D2 d2_in) const -{ - double t = getTime(d2_in); - return d2_in.valueAt(t); -} - -void -Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) -{ - double A = Geom::nearest_point(p, d2_in); - if(!getIsTime()){ - A = toSize(A, d2_in); - } - setAmount(A); -} - -} // end namespace Geom - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index e59fcfb701..1d051734e1 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -12,8 +12,15 @@ ink_common_sources += \ helper/geom-curves.h \ helper/geom-nodetype.cpp \ helper/geom-nodetype.h \ + helper/geom-pathinfo.cpp \ + helper/geom-pathinfo.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ + helper/geom-pointwise.cpp \ + helper/geom-pointwise.h \ + helper/geom-satellite.cpp \ + helper/geom-satellite.h \ + helper/geom-satellite-enum.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ helper/mathfns.h \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp new file mode 100644 index 0000000000..c8ba01bd07 --- /dev/null +++ b/src/helper/geom-pathinfo.cpp @@ -0,0 +1,178 @@ +/* + * pathinfo.cpp + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#include +#include <2geom/sbasis-to-bezier.h> + +namespace Geom { + +Pathinfo::Pathinfo(Piecewise > pwd2) + : _pwd2(pwd2) +{ + setPathInfo(); +}; + +Pathinfo::~Pathinfo(){}; + +Piecewise > +Pathinfo::getPwd2() const +{ + return _pwd2; +} + +void +Pathinfo::setPwd2(Piecewise > pwd2_in) +{ + _pwd2 = pwd2_in; + setPathInfo(); +} + + +void +Pathinfo::setPathInfo() +{ + _pathInfo.clear(); + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + } + while (curve_it1 != curve_endit) { + ++curve_it1; + counter++; + } + if(path_it->closed()){ + _pathInfo.push_back(std::make_pair(counter-1,true)); + } else { + _pathInfo.push_back(std::make_pair(counter-1,false)); + } + } +} + +size_t +Pathinfo::getSubPathIndex(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return i; + } + } + return 0; +} + +size_t +Pathinfo::getLast(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].first; + } + } + return 0; +} + +size_t +Pathinfo::getFirst(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + if(i==0){ + return 0; + } else { + return _pathInfo[i-1].first + 1; + } + } + } + return 0; +} + +boost::optional +Pathinfo::getPrevious(size_t index) const +{ + if(getFirst(index) == index && getIsClosed(index)){ + return getLast(index); + } + if(getFirst(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index - 1; +} + +boost::optional +Pathinfo::getNext(size_t index) const +{ + if(getLast(index) == index && getIsClosed(index)){ + return getFirst(index); + } + if(getLast(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index + 1; +} + +bool +Pathinfo::getIsClosed(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].second; + } + } + return false; +} + +std::vector > +Pathinfo::getPathInfo() const +{ + return _pathInfo; +} + +}; // namespace Geom + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h new file mode 100644 index 0000000000..1696fd3663 --- /dev/null +++ b/src/helper/geom-pathinfo.h @@ -0,0 +1,81 @@ +/** + * \file + * \brief Pathinfo + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * Pathinfo maintains .... + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#ifndef SEEN_GEOM_PATHINFO_H +#define SEEN_GEOM_PATHINFO_H + +#include <2geom/path.h> +#include + +namespace Geom { + +/** + * %Pathinfo function class. + */ + +class Pathinfo +{ + public: + Pathinfo(Piecewise > pwd2); + virtual ~Pathinfo(); + Piecewise > getPwd2() const; + void setPwd2(Piecewise > pwd2_in); + size_t getSubPathIndex(size_t index) const; + size_t getLast(size_t index) const; + size_t getFirst(size_t index) const; + boost::optional getPrevious(size_t index) const; + boost::optional getNext(size_t index) const; + bool getIsClosed(size_t index) const; + std::vector > getPathInfo() const; + + private: + void setPathInfo(); + Piecewise > _pwd2; + std::vector > _pathInfo; +}; + +} //namespace Geom + + +#endif //SEEN_GEOM_PATHINFO_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp new file mode 100644 index 0000000000..4926bcc477 --- /dev/null +++ b/src/helper/geom-pointwise.cpp @@ -0,0 +1,268 @@ +/* + * pointwise.cpp + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#include +#include + +namespace Geom { + +Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) + : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) +{ +}; + +Pointwise::~Pointwise(){}; + +Piecewise > +Pointwise::getPwd2() const +{ + return _pwd2; +} + +void +Pointwise::setPwd2(Piecewise > pwd2_in) +{ + _pwd2 = pwd2_in; + _pathInfo.setPwd2(_pwd2); +} + +std::vector +Pointwise::getSatellites() const +{ + return _satellites; +} + +void +Pointwise::setSatellites(std::vector sats) +{ + _satellites = sats; +} + +void +Pointwise::recalculate_for_new_pwd2(Piecewise > A) +{ + if( _pwd2.size() > A.size()){ + pwd2_sustract(A); + } else if (_pwd2.size() < A.size()){ + pwd2_append(A); + } +} + +void +Pointwise::pwd2_append(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + bool reversed = false; + bool reorder = false; + for(size_t i = 0; i < A.size(); i++){ + size_t first = _pathInfo.getFirst(i-counter); + size_t last = _pathInfo.getLast(i-counter); + _pathInfo.setPwd2(A); + size_t subpathAIndex = _pathInfo.getSubPathIndex(i); + _pathInfo.setPwd2(_pwd2); + bool changedSubpath = false; + if(_pwd2.size() <= i-counter){ + changedSubpath = false; + } else { + changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); + } + if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + subpath_append_reorder(_pathInfo.getSubPathIndex(first)); + reorder = true; + i--; + continue; + } + if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + reverse(first, last); + reversed = true; + } + if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + counter++; + bool active = true; + bool hidden = false; + bool isTime = _satellites[0].isTime; + bool mirror_knots = _satellites[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(_satellites[0].satelliteType, isTime, active, mirror_knots, hidden, amount, degrees, steps); + sats.push_back(sat); + } else { + sats.push_back(_satellites[i-counter]); + } + } + setPwd2(A); + setSatellites(sats); +} + +void +Pointwise::pwd2_sustract(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + Piecewise > pwd2 = _pwd2; + setPwd2(A); + for(size_t i = 0; i < _satellites.size(); i++){ + if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + counter++; + } else { + sats.push_back(_satellites[i-counter]); + } + } + setSatellites(sats); +} + +void +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) +{ + std::vector > pathInfo = _pathInfo.getPathInfo(); + for(size_t i = 0; i < pathInfo.size(); i++){ + size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); + size_t lastNode = _pathInfo.getLast(pathInfo[i].first); + if(!_pathInfo.getIsClosed(lastNode)){ + for(size_t j = 0; j < _satellites.size(); j++){ + if(j < firstNode || j > lastNode){ + continue; + } + if(j == firstNode){ + _satellites[j].active = active; + _satellites[j].hidden = hidden; + if(amount >= 0){ + _satellites[j].amount = amount; + } + if(angle >= 0){ + _satellites[j].angle = angle; + } + } + } + } else { + for(size_t j = 0; j < _satellites.size(); j++){ + if(j < firstNode){ + continue; + } + if(j == firstNode && !_satellites[j].active){ + _satellites[j].active = true; + _satellites[j].hidden = _satellites[j+1].hidden; + } + + } + } + } +} + +void +Pointwise::subpath_append_reorder(size_t subpath){ + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t nSubpath = 0; + size_t counter = 0; + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.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(); + 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) { + if(nSubpath == subpath){ + _satellites.push_back(_satellites[counter]); + deleteSatellite(counter); + } else { + counter++; + } + ++curve_it1; + } + if(nSubpath == subpath){ + rev = *path_it; + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + tmp_path.push_back(rev); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); +} + +void +Pointwise::reverse(size_t start,size_t end){ + start ++; + for(size_t i = end; i >= start; i--){ + _satellites.push_back(_satellites[i]); + deleteSatellite(i); + } + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + size_t nSubpath = 0; + size_t subpath = _pathInfo.getSubPathIndex(start); + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + counter ++; + if(nSubpath == subpath){ + tmp_path.push_back(path_it->reverse()); + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); +} + +void +Pointwise::deleteSatellite(size_t A) +{ + for (std::vector::iterator it = _satellites.begin(); it != _satellites.end();) + { + if((unsigned)(it - _satellites.begin()) == A){ + it = _satellites.erase(it); + } + } +} + +} // namespace Geom +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/2geom/pointwise.h b/src/helper/geom-pointwise.h similarity index 72% rename from src/2geom/pointwise.h rename to src/helper/geom-pointwise.h index 0eb7c70733..8b5c275b9c 100644 --- a/src/2geom/pointwise.h +++ b/src/helper/geom-pointwise.h @@ -47,10 +47,10 @@ #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> -#include <2geom/satellite.h> +#include +#include #include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> -#include "helper/geom.h" #include namespace Geom { @@ -61,36 +61,24 @@ namespace Geom { class Pointwise { public: - Pointwise(Piecewise > pwd2, std::vector > satellites); + Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); - std::vector findSatellites(size_t A, long B = -1) const; - std::vector findPeviousSatellites(size_t A, long B) const; - double rad_to_len(double A, std::pair sat) const; - double len_to_rad(double A, std::pair sat) const; - std::vector > getSatellites() const; - void setSatellites(std::vector > sats); + std::vector getSatellites() const; + void setSatellites(std::vector sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); void recalculate_for_new_pwd2(Piecewise > A); void pwd2_append(Piecewise > A); void pwd2_sustract(Piecewise > A); void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); - void deleteSatellites(size_t A); + void deleteSatellite(size_t A); void subpath_append_reorder(size_t subpath); void reverse(size_t start,size_t end); - void setPathInfo(); - void setPathInfo(Piecewise >); - size_t getSubPathIndex(size_t index) const; - size_t getLast(size_t index) const; - size_t getFirst(size_t index) const; - boost::optional getPrevious(size_t index) const; - boost::optional getNext(size_t index) const; - bool getIsClosed(size_t index) const; private: Piecewise > _pwd2; - std::vector > _satellites; - std::vector > _pathInfo; + std::vector _satellites; + Pathinfo _pathInfo; }; } // end namespace Geom diff --git a/src/2geom/satellite-enum.h b/src/helper/geom-satellite-enum.h similarity index 100% rename from src/2geom/satellite-enum.h rename to src/helper/geom-satellite-enum.h diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp new file mode 100644 index 0000000000..73201445a1 --- /dev/null +++ b/src/helper/geom-satellite.cpp @@ -0,0 +1,237 @@ +/** + * \file + * \brief Satellite + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + */ + +#include +#include <2geom/curve.h> +#include <2geom/nearest-point.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/path-intersection.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/ray.h> +#include + + +namespace Geom { + +Satellite::Satellite(){}; + +Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) + : satelliteType(satelliteType), isTime(isTime), active(active), hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), steps(steps){}; + +Satellite::~Satellite() {}; + +double +Satellite::toTime(double A,Geom::D2 d2_in) const +{ + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + return 0; + } + double t = 0; + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + if (lenghtPart != 0) { + t = A / lenghtPart; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + + return t; +} + +double +Satellite::toSize(double A,Geom::D2 d2_in) const +{ + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + return 0; + } + double s = 0; + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + s = (A * lenghtPart); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} + + +double +Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +{ + double len = 0; + if(d2_in && previousSatellite){ + 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 = (*previousSatellite).toSize(p0pt,d2_out); + } else { + if(A > 0){ + len = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite); + } + } + } + return len; +} + +double +Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +{ + if(d2_in && previousSatellite){ + double time_in = (*previousSatellite).getOpositeTime(A, *d2_in); + double time_out = (*previousSatellite).toTime(A,d2_out); + Geom::Point startArcPoint = (*d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Piecewise > u; + u.push_cut(0); + u.push(*d2_in, 1); + Geom::Curve * C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Piecewise > u2; + u2.push_cut(0); + u2.push(d2_out, 1); + Geom::Curve * D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Curve *knotCurve1 = C->portion(0, time_in); + Curve *knotCurve2 = D->portion(time_out, 1); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Ray ray2(d2_out.valueAt(0), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + 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); + double divisor = std::sin(angleBetween/2.0); + if(divisor > 0){ + return distanceArc/divisor; + } + } + return 0; +} + +double +Satellite::getOpositeTime(double s, Geom::D2 d2_in) const +{ + if(s == 0){ + return 1; + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + double size = lenghtPart - s; + return toTime(size, d2_in); +} + +double +Satellite::getTime(Geom::D2 d2_in) const +{ + double t = amount; + if(!isTime){ + t = toTime(t, d2_in); + } + if(t > 1){ + t = 1; + } + return t; +} + +double +Satellite::getSize(Geom::D2 d2_in) const +{ + double s = amount; + if(isTime){ + s = toSize(s, d2_in); + } + return s; +} + + +Geom::Point +Satellite::getPosition(Geom::D2 d2_in) const +{ + double t = getTime(d2_in); + return d2_in.valueAt(t); +} + +void +Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +{ + double A = Geom::nearest_point(p, d2_in); + if(!isTime){ + A = toSize(A, d2_in); + } + amount = A; +} + +void +Satellite::setSatelliteType(gchar const * A) +{ + std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; +} + +gchar const * +Satellite::getSatelliteTypeGchar() const +{ + std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); + return SatelliteTypeToGcharMap.at(satelliteType); +} + +} //namespace Geom + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/2geom/satellite.h b/src/helper/geom-satellite.h similarity index 51% rename from src/2geom/satellite.h rename to src/helper/geom-satellite.h index 42ed9c2913..f367bb7f38 100644 --- a/src/2geom/satellite.h +++ b/src/helper/geom-satellite.h @@ -33,7 +33,7 @@ #ifndef LIB2GEOM_SEEN_SATELLITE_H #define LIB2GEOM_SEEN_SATELLITE_H -#include <2geom/satellite-enum.h> +#include #include <2geom/d2.h> #include #include @@ -45,131 +45,30 @@ class Satellite public: Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); + Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); virtual ~Satellite(); - void setSatelliteType(SatelliteType A) - { - _satellitetype = A; - } - - void setSatelliteType(gchar const * A) - { - std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); - _satellitetype = GcharMapToSatelliteType.find(std::string(A))->second; - } - - void setIsTime(bool A) - { - _isTime = A; - } - - void setIsEndOpen(bool A) - { - _isEndOpen = A; - } - - - void setActive(bool A) - { - _active = A; - } - - void setHasMirror(bool A) - { - _hasMirror = A; - } - - void setHidden(bool A) - { - _hidden = A; - } - void setAmount(double A) - { - _amount = A; - } - - void setAngle(double A) - { - _angle = A; - } - - void setSteps(int A) - { - _steps = A; - } - - SatelliteType getSatelliteType() const - { - return _satellitetype; - } - - gchar const * getSatelliteTypeGchar() const - { - std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); - return SatelliteTypeToGcharMap.at(_satellitetype); - } - - bool getIsTime() const - { - return _isTime; - } - - bool getIsEndOpen() const - { - return _isEndOpen; - } - - bool getActive() const - { - return _active; - } - - bool getHasMirror() const - { - return _hasMirror; - } - - bool getHidden() const - { - return _hidden; - } - - double getAmount() const - { - return _amount; - } - - double getAngle() const - { - return _angle; - } - - int getSteps() const - { - return _steps; - } - void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 curve) const; + Geom::Point getPosition(Geom::D2 d2_in) const; double getSize(Geom::D2 d2_in) const; double getTime(Geom::D2 d2_in) const; double getOpositeTime(double A,Geom::D2 SBasisCurve) const; double toSize(double A,Geom::D2 d2_in) const; double toTime(double A,Geom::D2 d2_in) const; - - private: - - SatelliteType _satellitetype; - bool _isTime; - bool _isEndOpen; - bool _active; - bool _hasMirror; - bool _hidden; - double _amount; - double _angle; - size_t _steps; + double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + void setSatelliteType(gchar const * A); + gchar const * getSatelliteTypeGchar() const; + + SatelliteType satelliteType; + bool isTime; + bool active; + bool hasMirror; + bool hidden; + double amount; + double angle; + size_t steps; }; } // end namespace Geom diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 3af27a2201..7bafb356df 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 6775fa0006..54b2fb52f2 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 89d91265aa..e56200a170 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 74b499fa29..9a0ebe2352 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 33cb53f4eb..c8ee63fec3 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 4fb053dbb9..25e4793041 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/satellitepairarray.cpp b/src/live_effects/parameter/satellitearray.cpp similarity index 73% rename from src/live_effects/parameter/satellitepairarray.cpp rename to src/live_effects/parameter/satellitearray.cpp index 461a6b54e1..24a491b4b8 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -10,10 +10,11 @@ #include "knotholder.h" #include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitepairarray.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 @@ -25,11 +26,11 @@ namespace Inkscape { namespace LivePathEffect { -SatellitePairArrayParam::SatellitePairArrayParam( +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), + : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; @@ -41,9 +42,9 @@ SatellitePairArrayParam::SatellitePairArrayParam( last_pointwise = NULL; } -SatellitePairArrayParam::~SatellitePairArrayParam() {} +SatelliteArrayParam::~SatelliteArrayParam() {} -void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, +void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { @@ -52,77 +53,78 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, knot_color = color; } -void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::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) +void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } -void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) +void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) { use_distance = use_knot_distance; } -void SatellitePairArrayParam::set_unit(const gchar *abbr) +void SatelliteArrayParam::set_unit(const gchar *abbr) { unit = abbr; } -void SatellitePairArrayParam::set_effect_type(EffectType et) +void SatelliteArrayParam::set_effect_type(EffectType et) { _effectType = et; } -void SatellitePairArrayParam::set_helper_size(int hs) +void SatelliteArrayParam::set_helper_size(int hs) { helper_size = hs; updateCanvasIndicators(); } -void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) +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].second.getActive() || _vector[i].second.getHidden()){ + if(!_vector[i].active || _vector[i].hidden){ continue; } - if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ + if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ continue; } double pos = 0; - if(pwd2.size() <= (unsigned)_vector[i].first){ + if(pwd2.size() <= i){ break; } - Geom::D2 d2 = pwd2[_vector[i].first]; + Geom::D2 d2 = pwd2[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 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 = last_pointwise->getPrevious(_vector[i].first); + 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].second.getOpositeTime(size_out,d2); + pos = _vector[i].getOpositeTime(size_out,d2); if(lenght_out < size_out){ overflow = true; } } } else { - pos = _vector[i].second.getTime(d2); + pos = _vector[i].getTime(d2); if(lenght_in < size_out){ overflow = true; } @@ -181,18 +183,18 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) updateCanvasIndicators(false); } } -void SatellitePairArrayParam::updateCanvasIndicators() +void SatelliteArrayParam::updateCanvasIndicators() { updateCanvasIndicators(true); } -void SatellitePairArrayParam::addCanvasIndicators( +void SatelliteArrayParam::addCanvasIndicators( SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { hp_vec.push_back(hp); } -void SatellitePairArrayParam::recalculate_knots() +void SatelliteArrayParam::recalculate_knots() { if(last_pointwise){ _vector = last_pointwise->getSatellites(); @@ -200,15 +202,15 @@ void SatellitePairArrayParam::recalculate_knots() } void -SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, +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].second.getIsTime() && _vector[i].second.getAmount() > 0){ - _vector[i].second.setAmount(_vector[i].second.getAmount() * ((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); @@ -217,7 +219,7 @@ SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, // param_set_and_write_new_value( (*this) * postmul ); } -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) @@ -228,14 +230,14 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if( mirror == true){ iPlus = i + _vector.size(); } - if(!_vector[i].second.getActive()){ + if(!_vector[i].active){ continue; } - if(!_vector[i].second.getHasMirror() && mirror == true){ + if(!_vector[i].hasMirror && mirror == true){ continue; } using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); + SatelliteType type = _vector[i].satelliteType; //IF is for filletChamfer effect... if(_effectType == FILLET_CHAMFER){ const gchar *tip; @@ -268,7 +270,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { @@ -276,7 +278,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) : _pparam(p), _index(index) { @@ -299,34 +301,33 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, return; } - std::pair satellite = _pparam->_vector.at(index); - if(!satellite.second.getActive() || satellite.second.getHidden()){ + 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 = pointwise->getPrevious(satellite.first); + 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 satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } + std::vector sats = pointwise->getSatellites(); + timeStart = sats[*d2_prev_index].getTime(d2_in); if(timeStart > mirrorTime){ mirrorTime = timeStart; } - double size = satellite.second.toSize(mirrorTime, d2_in); + double size = satellite.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]); + if(satellite.isTime){ + amount = satellite.toTime(amount,pwd2[index]); } - satellite.second.setAmount(amount); + satellite.amount = amount; } } else { - satellite.second.setPosition(s,pwd2[satellite.first]); + satellite.setPosition(s,pwd2[index]); } _pparam->_vector.at(index) = satellite; SPLPEItem * splpeitem = dynamic_cast(item); @@ -347,26 +348,27 @@ FilletChamferKnotHolderEntity::knot_get() const if (!valid_index(index)) { return Point(infinity(), infinity()); } - std::pair satellite = _pparam->_vector.at(index); + Geom::Satellite satellite = _pparam->_vector.at(index); if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } - if(!satellite.second.getActive() || satellite.second.getHidden()){ + if(!satellite.active || satellite.hidden){ return Point(infinity(), infinity()); } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - if(pwd2.size() <= (unsigned)satellite.first){ + Pathinfo pathInfo(pwd2); + if(pwd2.size() <= index){ 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); + 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.second.getSize(pwd2[satellite.first]); - double t = satellite.second.getOpositeTime(s,d2_in); + double s = satellite.getSize(pwd2[index]); + double t = satellite.getOpositeTime(s,d2_in); if(t > 1){ t = 1; } @@ -374,17 +376,14 @@ FilletChamferKnotHolderEntity::knot_get() const 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); - } + timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); if(timeStart > t){ t = timeStart; } tmpPoint = (d2_in).valueAt(t); } } else { - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + tmpPoint = satellite.getPosition(pwd2[index]); } Geom::Point const canvas_point = tmpPoint; return canvas_point; @@ -402,12 +401,12 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmount(0.0); + _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).second.getSatelliteType(); + SatelliteType type = _pparam->_vector.at(index).satelliteType; switch(type){ case F: type = IF; @@ -422,7 +421,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) type = F; break; } - _pparam->_vector.at(index).second.setSatelliteType(type); + _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; @@ -447,19 +446,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) 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)); + 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 = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + 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).second); + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); } } @@ -473,16 +481,25 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - double amount = satellite.getAmount(); + double amount = satellite.amount; double maxAmount = amount; - if(!_pparam->use_distance && !satellite.getIsTime()){ - amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); + 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).second.getAmount(); + amount = _pparam->_vector.at(index).amount; } } - satellite.setAmount(amount); - _pparam->_vector.at(index).second = satellite; + 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); diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitearray.h similarity index 87% rename from src/live_effects/parameter/satellitepairarray.h rename to src/live_effects/parameter/satellitearray.h index fcd3bd7366..ee0cfbad35 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -18,11 +18,11 @@ * 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 "helper/geom-pointwise.h" #include "knot-holder-entity.h" -#include <2geom/pointwise.h> +#include namespace Inkscape { @@ -30,14 +30,14 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam > { +class SatelliteArrayParam : public ArrayParam { public: - SatellitePairArrayParam(const Glib::ustring &label, + SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); - virtual ~SatellitePairArrayParam(); + virtual ~SatelliteArrayParam(); virtual Gtk::Widget * param_newWidget() { return NULL; @@ -66,8 +66,8 @@ public: protected: KnotHolder *knoth; private: - SatellitePairArrayParam(const SatellitePairArrayParam &); - SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); + SatelliteArrayParam(const SatelliteArrayParam &); + SatelliteArrayParam &operator=(const SatelliteArrayParam &); SPKnotShapeType knot_shape; SPKnotModeType knot_mode; @@ -84,7 +84,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); + 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); @@ -97,7 +97,7 @@ public: }; private: - SatellitePairArrayParam *_pparam; + SatelliteArrayParam *_pparam; size_t _index; }; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 6875799f8e..443a48c13e 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -160,13 +160,13 @@ void FilletChamferPropertiesDialog::_apply() double d_pos = _fillet_chamfer_position_numeric.get_value(); if (d_pos >= 0) { if (_fillet_chamfer_type_fillet.get_active() == true) { - _satellite.setSatelliteType(Geom::F); + _satellite.satelliteType = Geom::F; } else if (_fillet_chamfer_type_inverse_fillet.get_active() == true) { - _satellite.setSatelliteType(Geom::IF); + _satellite.satelliteType = Geom::IF; } else if (_fillet_chamfer_type_inverse_chamfer.get_active() == true) { - _satellite.setSatelliteType(Geom::IC); + _satellite.satelliteType = Geom::IC; } else { - _satellite.setSatelliteType(Geom::C); + _satellite.satelliteType = Geom::C; } if (_flexible) { if (d_pos > 99.99999 || d_pos < 0) { @@ -176,12 +176,12 @@ void FilletChamferPropertiesDialog::_apply() } else { d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); } - _satellite.setAmount( d_pos); + _satellite.amount = d_pos; size_t steps = (size_t)_fillet_chamfer_chamfer_subdivisions.get_value(); if(steps < 1){ steps = 1; } - _satellite.setSteps(steps); + _satellite.steps = steps; _knotpoint->knot_set_offset(_satellite); } _close(); @@ -221,7 +221,7 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) if(use_distance){ distance_or_radius = std::string(_("Knot distance")); } - if (satellite.getIsTime()) { + if (satellite.isTime) { position = amount * 100; _flexible = true; _fillet_chamfer_position_label.set_label(_("Position (%):")); @@ -233,14 +233,14 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) position = Inkscape::Util::Quantity::convert(position, document_unit, unit); } _fillet_chamfer_position_numeric.set_value(position); - _fillet_chamfer_chamfer_subdivisions.set_value(satellite.getSteps()); - if (satellite.getSatelliteType() == Geom::F) { + _fillet_chamfer_chamfer_subdivisions.set_value(satellite.steps); + if (satellite.satelliteType == Geom::F) { _fillet_chamfer_type_fillet.set_active(true); - } else if (satellite.getSatelliteType() == Geom::IF) { + } else if (satellite.satelliteType == Geom::IF) { _fillet_chamfer_type_inverse_fillet.set_active(true); - } else if (satellite.getSatelliteType() == Geom::C) { + } else if (satellite.satelliteType == Geom::C) { _fillet_chamfer_type_chamfer.set_active(true); - } else if (satellite.getSatelliteType() == Geom::IC) { + } else if (satellite.satelliteType == Geom::IC) { _fillet_chamfer_type_inverse_chamfer.set_active(true); } _satellite = satellite; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 533f7af2a6..1a40eea9b4 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -10,7 +10,7 @@ #include <2geom/point.h> #include -#include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/parameter/satellitearray.h" class SPDesktop; -- GitLab From ce42be89c9b32edeba6eda6522199ec749e014f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 12:08:06 +0200 Subject: [PATCH 040/121] More cleanup of code structure. TODO: Documentation TODO: Fit code guidelines of Inkscape (bzr r13645.1.64) --- src/helper/geom-pathinfo.cpp | 6 -- src/helper/geom-pathinfo.h | 1 - src/helper/geom-pointwise.cpp | 117 +++++++++--------------- src/helper/geom-pointwise.h | 17 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 4 - 5 files changed, 53 insertions(+), 92 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index c8ba01bd07..4bacad7ea0 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -42,12 +42,6 @@ Pathinfo::Pathinfo(Piecewise > pwd2) Pathinfo::~Pathinfo(){}; -Piecewise > -Pathinfo::getPwd2() const -{ - return _pwd2; -} - void Pathinfo::setPwd2(Piecewise > pwd2_in) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 1696fd3663..9018e44f22 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -49,7 +49,6 @@ class Pathinfo public: Pathinfo(Piecewise > pwd2); virtual ~Pathinfo(); - Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); size_t getSubPathIndex(size_t index) const; size_t getLast(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 4926bcc477..9096dff282 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -30,13 +30,14 @@ */ #include -#include + namespace Geom { Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) { + setStart(); }; Pointwise::~Pointwise(){}; @@ -64,6 +65,24 @@ void Pointwise::setSatellites(std::vector sats) { _satellites = sats; + setStart(); +} + +void +Pointwise::setStart() +{ + std::vector > pathInfo = _pathInfo.getPathInfo(); + for(size_t i = 0; i < pathInfo.size(); i++){ + size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); + size_t lastNode = _pathInfo.getLast(pathInfo[i].first); + if(!_pathInfo.getIsClosed(lastNode)){ + _satellites[firstNode].hidden = true; + _satellites[firstNode].active = false; + } else { + _satellites[firstNode].active = true; + _satellites[firstNode].hidden = _satellites[firstNode + 1].hidden; + } + } } void @@ -76,6 +95,24 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) } } +void +Pointwise::pwd2_sustract(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + Piecewise > pwd2 = _pwd2; + setPwd2(A); + for(size_t i = 0; i < _satellites.size(); i++){ + if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + counter++; + } else { + sats.push_back(_satellites[i-counter]); + } + } + setSatellites(sats); +} + + void Pointwise::pwd2_append(Piecewise > A) { @@ -96,13 +133,13 @@ Pointwise::pwd2_append(Piecewise > A) changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); } if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_append_reorder(_pathInfo.getSubPathIndex(first)); + subpath_to_top(_pathInfo.getSubPathIndex(first)); reorder = true; i--; continue; } if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - reverse(first, last); + subpath_reverse(first, last); reversed = true; } if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ @@ -125,62 +162,7 @@ Pointwise::pwd2_append(Piecewise > A) } void -Pointwise::pwd2_sustract(Piecewise > A) -{ - size_t counter = 0; - std::vector sats; - Piecewise > pwd2 = _pwd2; - setPwd2(A); - for(size_t i = 0; i < _satellites.size(); i++){ - if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ - counter++; - } else { - sats.push_back(_satellites[i-counter]); - } - } - setSatellites(sats); -} - -void -Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) -{ - std::vector > pathInfo = _pathInfo.getPathInfo(); - for(size_t i = 0; i < pathInfo.size(); i++){ - size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); - size_t lastNode = _pathInfo.getLast(pathInfo[i].first); - if(!_pathInfo.getIsClosed(lastNode)){ - for(size_t j = 0; j < _satellites.size(); j++){ - if(j < firstNode || j > lastNode){ - continue; - } - if(j == firstNode){ - _satellites[j].active = active; - _satellites[j].hidden = hidden; - if(amount >= 0){ - _satellites[j].amount = amount; - } - if(angle >= 0){ - _satellites[j].angle = angle; - } - } - } - } else { - for(size_t j = 0; j < _satellites.size(); j++){ - if(j < firstNode){ - continue; - } - if(j == firstNode && !_satellites[j].active){ - _satellites[j].active = true; - _satellites[j].hidden = _satellites[j+1].hidden; - } - - } - } - } -} - -void -Pointwise::subpath_append_reorder(size_t subpath){ +Pointwise::subpath_to_top(size_t subpath){ std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t nSubpath = 0; size_t counter = 0; @@ -199,7 +181,7 @@ Pointwise::subpath_append_reorder(size_t subpath){ while (curve_it1 != curve_endit) { if(nSubpath == subpath){ _satellites.push_back(_satellites[counter]); - deleteSatellite(counter); + _satellites.erase(_satellites.begin() + counter); } else { counter++; } @@ -217,11 +199,11 @@ Pointwise::subpath_append_reorder(size_t subpath){ } void -Pointwise::reverse(size_t start,size_t end){ +Pointwise::subpath_reverse(size_t start,size_t end){ start ++; for(size_t i = end; i >= start; i--){ _satellites.push_back(_satellites[i]); - deleteSatellite(i); + _satellites.erase(_satellites.begin() + i); } std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t counter = 0; @@ -244,17 +226,6 @@ Pointwise::reverse(size_t start,size_t end){ setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); } -void -Pointwise::deleteSatellite(size_t A) -{ - for (std::vector::iterator it = _satellites.begin(); it != _satellites.end();) - { - if((unsigned)(it - _satellites.begin()) == A){ - it = _satellites.erase(it); - } - } -} - } // namespace Geom /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 8b5c275b9c..8297143c9a 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -43,12 +43,11 @@ #ifndef SEEN_GEOM_POINTWISE_H #define SEEN_GEOM_POINTWISE_H -#include +#include +#include #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> -#include -#include #include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> #include @@ -63,17 +62,19 @@ class Pointwise public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); + std::vector getSatellites() const; void setSatellites(std::vector sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); + void setStart(); + void recalculate_for_new_pwd2(Piecewise > A); - void pwd2_append(Piecewise > A); void pwd2_sustract(Piecewise > A); - void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); - void deleteSatellite(size_t A); - void subpath_append_reorder(size_t subpath); - void reverse(size_t start,size_t end); + void pwd2_append(Piecewise > A); + void subpath_to_top(size_t subpath); + void subpath_reverse(size_t start,size_t end); + private: Piecewise > _pwd2; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 54b2fb52f2..e873bebf9f 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); } } -- GitLab From aea84844cf40c4c1b1977548421ec50ad164590e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 14:18:34 +0200 Subject: [PATCH 041/121] add documentation (bzr r13645.1.65) --- src/helper/geom-pathinfo.cpp | 38 ++++--------- src/helper/geom-pathinfo.h | 32 ++--------- src/helper/geom-pointwise.cpp | 60 +++++++++++---------- src/helper/geom-pointwise.h | 59 +++++++------------- src/helper/geom-satellite-enum.h | 26 +++------ src/helper/geom-satellite.cpp | 93 +++++++++++++++++++------------- src/helper/geom-satellite.h | 44 +++++---------- 7 files changed, 142 insertions(+), 210 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 4bacad7ea0..19991e879a 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,32 +1,11 @@ -/* - * pathinfo.cpp +/** + * \file + * \brief Pathinfo store the data of a pathvector and allow get info about it + *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #include @@ -34,6 +13,10 @@ namespace Geom { +/** + * @brief Pathinfo store the data of a pathvector and allow get info about it + * + */ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { @@ -49,7 +32,8 @@ Pathinfo::setPwd2(Piecewise > pwd2_in) setPathInfo(); } - +/** Store the base path data + */ void Pathinfo::setPathInfo() { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 9018e44f22..9a40a4f20c 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,35 +1,11 @@ /** * \file - * \brief Pathinfo + * \brief Pathinfo store the data of a pathvector and allow get info about it *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * Pathinfo maintains .... - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #ifndef SEEN_GEOM_PATHINFO_H @@ -41,9 +17,9 @@ namespace Geom { /** - * %Pathinfo function class. + * @brief Pathinfo store the data of a pathvector and allow get info about it + * */ - class Pathinfo { public: diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9096dff282..9e65685ae5 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,32 +1,11 @@ -/* - * pointwise.cpp +/** + * \file + * \brief Pointwise a class to manage a vector of satellites per piecewise curve + *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #include @@ -34,6 +13,19 @@ namespace Geom { +/** + * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * + * For the moment is a per curve satellite holder not per node. This is ok for + * much cases but not a real node satellite on open paths + * To implement this we can: + * add extra satellite in open paths, and take notice of current open paths + * or put extra satellites on back for each open subpath + * + * Also maybe the vector of satellites become a vector of + * optional satellites, and remove the active variable in satellites. + * + */ Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) { @@ -68,6 +60,8 @@ Pointwise::setSatellites(std::vector sats) setStart(); } +/** Update the start satellite on ope/closed paths. + */ void Pointwise::setStart() { @@ -85,6 +79,8 @@ Pointwise::setStart() } } +/** Fired when a path is modified. + */ void Pointwise::recalculate_for_new_pwd2(Piecewise > A) { @@ -95,6 +91,8 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) } } +/** Some nodes/subpaths are removed. + */ void Pointwise::pwd2_sustract(Piecewise > A) { @@ -112,7 +110,8 @@ Pointwise::pwd2_sustract(Piecewise > A) setSatellites(sats); } - +/** Append nodes/subpaths to current pointwise + */ void Pointwise::pwd2_append(Piecewise > A) { @@ -123,6 +122,7 @@ Pointwise::pwd2_append(Piecewise > A) for(size_t i = 0; i < A.size(); i++){ size_t first = _pathInfo.getFirst(i-counter); size_t last = _pathInfo.getLast(i-counter); + //Check for subpath closed. If a subpath is closed, is not reversed or moved to back _pathInfo.setPwd2(A); size_t subpathAIndex = _pathInfo.getSubPathIndex(i); _pathInfo.setPwd2(_pwd2); @@ -133,7 +133,8 @@ Pointwise::pwd2_append(Piecewise > A) changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); } if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_to_top(_pathInfo.getSubPathIndex(first)); + //Send the modified subpath to back + subpath_to_back(_pathInfo.getSubPathIndex(first)); reorder = true; i--; continue; @@ -161,8 +162,9 @@ Pointwise::pwd2_append(Piecewise > A) setSatellites(sats); } + void -Pointwise::subpath_to_top(size_t subpath){ +Pointwise::subpath_to_back(size_t subpath){ std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t nSubpath = 0; size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 8297143c9a..59ed4d1aa2 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,43 +1,11 @@ /** * \file - * \brief Pointwise + * \brief Pointwise a class to manage a vector of satellites per piecewise curve *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * Pointwise maintains a set of "Satellite" positions along a curve/pathvector. - * The positions are specified as arc length distances along the curve or by - * time in the curve. Splicing operations automatically update the satellite - * positions to preserve the intent. - * The data is serialised to SVG using a specialiced pointwise LPE parameter to - * handle it in th future can be a inkscape based property to paths - * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing - * existing algorithms to correctly update satellite positions. - - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #ifndef SEEN_GEOM_POINTWISE_H @@ -53,29 +21,40 @@ #include namespace Geom { + /** - * %Pointwise function class. + * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * + * For the moment is a per curve satellite holder not per node. This is ok for + * much cases but not a real node satellite on open paths + * To implement this we can: + * add extra satellite in open paths, and take notice of current open paths + * or put extra satellites on back for each open subpath + * + * Also maybe the vector of satellites become a vector of + * optional satellites, and remove the active variable in satellites. + * */ - class Pointwise { public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); - std::vector getSatellites() const; - void setSatellites(std::vector sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); + + std::vector getSatellites() const; + void setSatellites(std::vector sats); + void setStart(); void recalculate_for_new_pwd2(Piecewise > A); void pwd2_sustract(Piecewise > A); void pwd2_append(Piecewise > A); - void subpath_to_top(size_t subpath); + void subpath_to_back(size_t subpath); void subpath_reverse(size_t start,size_t end); - private: Piecewise > _pwd2; std::vector _satellites; diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h index bcd8d1bb33..4680ce2f61 100644 --- a/src/helper/geom-satellite-enum.h +++ b/src/helper/geom-satellite-enum.h @@ -1,17 +1,17 @@ #ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H #define LIB2GEOM_SEEN_SATELLITE_ENUM_H -/* - * +/** + * \file + * \brief Satellite types enum + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz * -* Copyright (C) Jabier Arraiza Cenoz - * - * Released under GNU GPL, read the file 'COPYING' for more information + * This code is in public domain */ #include "util/enums.h" -/*#include -*/ namespace Geom { @@ -23,18 +23,6 @@ enum SatelliteType { KO // Invalid Satellite) }; -/* TODO maybe is best do next by bimap - typedef boost::bimap< Geom::SatelliteType,gchar const *> map_type ; - - map_type SatelliteTypeBimap; - - SatelliteTypeBimap.insert( map_type::value_type(FILLET, "FILLET")); - SatelliteTypeBimap.insert( map_type::value_type(INVERSE_FILLET, "INVERSE_FILLET")); - SatelliteTypeBimap.insert( map_type::value_type(CHAMFER, "CHAMFER")) ); - SatelliteTypeBimap.insert( map_type::value_type(INVERSE_CHAMFER, "INVERSE_CHAMFER")); - SatelliteTypeBimap.insert( map_type::value_type(INVALID_SATELLITE, "INVALID_SATELLITE")); -*/ - } //namespace Geom #endif diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 73201445a1..6304b41481 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,33 +1,11 @@ /** * \file - * \brief Satellite + * \brief Satellite a per ?node/curve holder of data. *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. + * This code is in public domain */ #include @@ -42,6 +20,9 @@ namespace Geom { +/** + * @brief Satellite a per ?node/curve holder of data. + */ Satellite::Satellite(){}; Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) @@ -49,6 +30,9 @@ Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool Satellite::~Satellite() {}; +/** + * Calculate the time in d2_in with a size of A + */ double Satellite::toTime(double A,Geom::D2 d2_in) const { @@ -74,6 +58,9 @@ Satellite::toTime(double A,Geom::D2 d2_in) const return t; } +/** + * Calculate the size in d2_in with a point at A + */ double Satellite::toSize(double A,Geom::D2 d2_in) const { @@ -94,7 +81,9 @@ Satellite::toSize(double A,Geom::D2 d2_in) const return s; } - +/** + * Calculate the lenght of a satellite from a radious A input. + */ double Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const { @@ -118,6 +107,9 @@ Satellite::rad_to_len(double A, boost::optional > d2_in, return len; } + /** + * Calculate the radious of a satellite from a lenght A input. + */ double Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const { @@ -157,17 +149,9 @@ Satellite::len_to_rad(double A, boost::optional > d2_in, return 0; } -double -Satellite::getOpositeTime(double s, Geom::D2 d2_in) const -{ - if(s == 0){ - return 1; - } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - double size = lenghtPart - s; - return toTime(size, d2_in); -} - +/** + * Get the time position of the satellite in d2_in + */ double Satellite::getTime(Geom::D2 d2_in) const { @@ -181,6 +165,29 @@ Satellite::getTime(Geom::D2 d2_in) const return t; } +/**. + * Get the time from a lenght A in other curve, a bolean I gived to reverse time + */ +double +Satellite::getTime(double A, bool I, Geom::D2 d2_in) const +{ + if(A == 0 && I){ + return 1; + } + if(A == 0 && !I){ + return 0; + } + if(!I){ + return toTime(A, d2_in); + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + A = lenghtPart - A; + return toTime(A, d2_in); +} + +/** + * Get the lenght of the satellite in d2_in + */ double Satellite::getSize(Geom::D2 d2_in) const { @@ -191,7 +198,9 @@ Satellite::getSize(Geom::D2 d2_in) const return s; } - +/** + * Get the point position of the satellite + */ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const { @@ -199,6 +208,9 @@ Satellite::getPosition(Geom::D2 d2_in) const return d2_in.valueAt(t); } +/** + * Set the position of the satellite from a gived point P + */ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { @@ -209,6 +221,9 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) amount = A; } +/** + * Map a satellite type with gchar + */ void Satellite::setSatelliteType(gchar const * A) { @@ -216,6 +231,10 @@ Satellite::setSatelliteType(gchar const * A) satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; } + +/** + * Map a gchar with satelliteType + */ gchar const * Satellite::getSatelliteTypeGchar() const { diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index f367bb7f38..d4550b9220 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,33 +1,11 @@ /** * \file - * \brief Satellite + * \brief Satellite a per ?node/curve holder of data. *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. + * This code is in public domain */ #ifndef LIB2GEOM_SEEN_SATELLITE_H @@ -40,6 +18,9 @@ namespace Geom { +/** + * @brief Satellite a per ?node/curve holder of data. + */ class Satellite { public: @@ -49,18 +30,21 @@ class Satellite virtual ~Satellite(); - void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 d2_in) const; - double getSize(Geom::D2 d2_in) const; - double getTime(Geom::D2 d2_in) const; - double getOpositeTime(double A,Geom::D2 SBasisCurve) const; double toSize(double A,Geom::D2 d2_in) const; double toTime(double A,Geom::D2 d2_in) const; double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + + double getTime(Geom::D2 d2_in) const; + double getTime(double A, bool I, Geom::D2 d2_in) const; + double getSize(Geom::D2 d2_in) const; + + void setPosition(Geom::Point p, Geom::D2 d2_in); + Geom::Point getPosition(Geom::D2 d2_in) const; + void setSatelliteType(gchar const * A); gchar const * getSatelliteTypeGchar() const; - + //TODO: maybe make after variables protected? SatelliteType satelliteType; bool isTime; bool active; -- GitLab From f3965759e52107c1cdcd8b7e248e5538fdaa11b6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 17:54:35 +0200 Subject: [PATCH 042/121] Added documentation and fix to coding style. (bzr r13645.1.66) --- src/helper/geom-pathinfo.cpp | 119 ++-- src/helper/geom-pathinfo.h | 52 +- src/helper/geom-pointwise.cpp | 185 ++--- src/helper/geom-pointwise.h | 55 +- src/helper/geom-satellite-enum.h | 22 +- src/helper/geom-satellite.cpp | 153 ++-- src/helper/geom-satellite.h | 47 +- 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 +-- .../dialog/lpe-fillet-chamfer-properties.cpp | 80 +-- src/ui/dialog/lpe-fillet-chamfer-properties.h | 54 +- 13 files changed, 1011 insertions(+), 916 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 19991e879a..f120045351 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,12 +1,12 @@ /** * \file * \brief Pathinfo store the data of a pathvector and allow get info about it - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include #include <2geom/sbasis-to-bezier.h> @@ -17,131 +17,120 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) - : _pwd2(pwd2) +Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { - setPathInfo(); -}; + _setPathInfo(); +} +; -Pathinfo::~Pathinfo(){}; +Pathinfo::~Pathinfo() {} +; -void -Pathinfo::setPwd2(Piecewise > pwd2_in) +void Pathinfo::setPwd2(Piecewise > pwd2_in) { _pwd2 = pwd2_in; - setPathInfo(); + _setPathInfo(); } /** Store the base path data */ -void -Pathinfo::setPathInfo() +void Pathinfo::_setPathInfo() { - _pathInfo.clear(); - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + data.clear(); + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.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(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } + 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) { ++curve_it1; counter++; } - if(path_it->closed()){ - _pathInfo.push_back(std::make_pair(counter-1,true)); + if (path_it->closed()) { + data.push_back(std::make_pair(counter - 1, true)); } else { - _pathInfo.push_back(std::make_pair(counter-1,false)); + data.push_back(std::make_pair(counter - 1, false)); } } } -size_t -Pathinfo::getSubPathIndex(size_t index) const +size_t Pathinfo::subPathIndex(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { return i; } } return 0; } -size_t -Pathinfo::getLast(size_t index) const +size_t Pathinfo::last(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].first; + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + return data[i].first; } } return 0; } -size_t -Pathinfo::getFirst(size_t index) const +size_t Pathinfo::first(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - if(i==0){ + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + if (i == 0) { return 0; } else { - return _pathInfo[i-1].first + 1; + return data[i - 1].first + 1; } } } return 0; } -boost::optional -Pathinfo::getPrevious(size_t index) const +boost::optional Pathinfo::previous(size_t index) const { - if(getFirst(index) == index && getIsClosed(index)){ - return getLast(index); + if (first(index) == index && isClosed(index)) { + return last(index); } - if(getFirst(index) == index && !getIsClosed(index)){ + if (first(index) == index && !isClosed(index)) { return boost::none; } return index - 1; } -boost::optional -Pathinfo::getNext(size_t index) const +boost::optional Pathinfo::next(size_t index) const { - if(getLast(index) == index && getIsClosed(index)){ - return getFirst(index); + if (last(index) == index && isClosed(index)) { + return first(index); } - if(getLast(index) == index && !getIsClosed(index)){ + if (last(index) == index && !isClosed(index)) { return boost::none; } return index + 1; } -bool -Pathinfo::getIsClosed(size_t index) const +bool Pathinfo::isClosed(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].second; + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + return data[i].second; } } return false; } -std::vector > -Pathinfo::getPathInfo() const -{ - return _pathInfo; -} - }; // namespace Geom /* @@ -153,4 +142,6 @@ Pathinfo::getPathInfo() const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 9a40a4f20c..c9d8e28628 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,12 +1,12 @@ /** * \file * \brief Pathinfo store the data of a pathvector and allow get info about it - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef SEEN_GEOM_PATHINFO_H #define SEEN_GEOM_PATHINFO_H @@ -20,29 +20,27 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -class Pathinfo -{ - public: - Pathinfo(Piecewise > pwd2); - virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2_in); - size_t getSubPathIndex(size_t index) const; - size_t getLast(size_t index) const; - size_t getFirst(size_t index) const; - boost::optional getPrevious(size_t index) const; - boost::optional getNext(size_t index) const; - bool getIsClosed(size_t index) const; - std::vector > getPathInfo() const; - - private: - void setPathInfo(); - Piecewise > _pwd2; - std::vector > _pathInfo; +class Pathinfo { +public: + Pathinfo(Piecewise > pwd2); + virtual ~Pathinfo(); + void setPwd2(Piecewise > pwd2_in); + size_t subPathIndex(size_t index) const; + size_t last(size_t index) const; + size_t first(size_t index) const; + boost::optional previous(size_t index) const; + boost::optional next(size_t index) const; + bool isClosed(size_t index) const; + std::vector > pathInfo() const; + std::vector > data; + +private: + void _setPathInfo(); + Piecewise > _pwd2; }; } //namespace Geom - #endif //SEEN_GEOM_PATHINFO_H /* Local Variables: @@ -53,4 +51,6 @@ class Pathinfo fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9e65685ae5..cfe93311cb 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,23 +1,22 @@ /** * \file * \brief Pointwise a class to manage a vector of satellites per piecewise curve - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include - namespace Geom { /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths + * much cases but not a real node satellite on open paths * To implement this we can: * add extra satellite in open paths, and take notice of current open paths * or put extra satellites on back for each open subpath @@ -26,35 +25,34 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) - : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) +Pointwise::Pointwise(Piecewise > pwd2, + std::vector satellites) + : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) { setStart(); -}; +} +; -Pointwise::~Pointwise(){}; +Pointwise::~Pointwise() {} +; -Piecewise > -Pointwise::getPwd2() const +Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void -Pointwise::setPwd2(Piecewise > pwd2_in) +void Pointwise::setPwd2(Piecewise > pwd2_in) { _pwd2 = pwd2_in; - _pathInfo.setPwd2(_pwd2); + _path_info.setPwd2(_pwd2); } -std::vector -Pointwise::getSatellites() const +std::vector Pointwise::getSatellites() const { return _satellites; } -void -Pointwise::setSatellites(std::vector sats) +void Pointwise::setSatellites(std::vector sats) { _satellites = sats; setStart(); @@ -62,14 +60,13 @@ Pointwise::setSatellites(std::vector sats) /** Update the start satellite on ope/closed paths. */ -void -Pointwise::setStart() +void Pointwise::setStart() { - std::vector > pathInfo = _pathInfo.getPathInfo(); - for(size_t i = 0; i < pathInfo.size(); i++){ - size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); - size_t lastNode = _pathInfo.getLast(pathInfo[i].first); - if(!_pathInfo.getIsClosed(lastNode)){ + std::vector > path_info = _path_info.data; + for (size_t i = 0; i < path_info.size(); i++) { + size_t firstNode = _path_info.first(path_info[i].first); + size_t lastNode = _path_info.last(path_info[i].first); + if (!_path_info.isClosed(lastNode)) { _satellites[firstNode].hidden = true; _satellites[firstNode].active = false; } else { @@ -81,30 +78,29 @@ Pointwise::setStart() /** Fired when a path is modified. */ -void -Pointwise::recalculate_for_new_pwd2(Piecewise > A) +void Pointwise::recalculateForNewPwd2(Piecewise > A) { - if( _pwd2.size() > A.size()){ - pwd2_sustract(A); - } else if (_pwd2.size() < A.size()){ - pwd2_append(A); + if (_pwd2.size() > A.size()) { + pwd2Sustract(A); + } else if (_pwd2.size() < A.size()) { + pwd2Append(A); } } /** Some nodes/subpaths are removed. */ -void -Pointwise::pwd2_sustract(Piecewise > A) +void Pointwise::pwd2Sustract(Piecewise > A) { size_t counter = 0; std::vector sats; Piecewise > pwd2 = _pwd2; setPwd2(A); - for(size_t i = 0; i < _satellites.size(); i++){ - if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + for (size_t i = 0; i < _satellites.size(); i++) { + if (_path_info.last(i - counter) < i - counter || + !are_near(pwd2[i].at0(), A[i - counter].at0(), 0.001)) { counter++; } else { - sats.push_back(_satellites[i-counter]); + sats.push_back(_satellites[i - counter]); } } setSatellites(sats); @@ -112,76 +108,83 @@ Pointwise::pwd2_sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void -Pointwise::pwd2_append(Piecewise > A) +void Pointwise::pwd2Append(Piecewise > A) { size_t counter = 0; std::vector sats; bool reversed = false; bool reorder = false; - for(size_t i = 0; i < A.size(); i++){ - size_t first = _pathInfo.getFirst(i-counter); - size_t last = _pathInfo.getLast(i-counter); - //Check for subpath closed. If a subpath is closed, is not reversed or moved to back - _pathInfo.setPwd2(A); - size_t subpathAIndex = _pathInfo.getSubPathIndex(i); - _pathInfo.setPwd2(_pwd2); - bool changedSubpath = false; - if(_pwd2.size() <= i-counter){ - changedSubpath = false; + for (size_t i = 0; i < A.size(); i++) { + size_t first = _path_info.first(i - counter); + size_t last = _path_info.last(i - counter); + //Check for subpath closed. If a subpath is closed, is not reversed or moved + //to back + _path_info.setPwd2(A); + size_t new_subpath_index = _path_info.subPathIndex(i); + _path_info.setPwd2(_pwd2); + bool subpath_is_changed = false; + if (_pwd2.size() <= i - counter) { + subpath_is_changed = false; } else { - changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); + subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + if (!reorder && first == i - counter && + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && + !subpath_is_changed) { //Send the modified subpath to back - subpath_to_back(_pathInfo.getSubPathIndex(first)); + subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_reverse(first, last); + if (!reversed && first == i - counter && + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && + !subpath_is_changed) { + subpathReverse(first, last); reversed = true; } - if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + if (_pwd2.size() <= i - counter || + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)) { counter++; bool active = true; bool hidden = false; - bool isTime = _satellites[0].isTime; + bool is_time = _satellites[0].isTime; bool mirror_knots = _satellites[0].hasMirror; double amount = 0.0; double degrees = 0.0; int steps = 0; - Satellite sat(_satellites[0].satelliteType, isTime, active, mirror_knots, hidden, amount, degrees, steps); + Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); sats.push_back(sat); } else { - sats.push_back(_satellites[i-counter]); + sats.push_back(_satellites[i - counter]); } } setPwd2(A); setSatellites(sats); } - -void -Pointwise::subpath_to_back(size_t subpath){ - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); - size_t nSubpath = 0; +void Pointwise::subpathToBack(size_t subpath) +{ + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + size_t subpath_counter = 0; size_t counter = 0; std::vector tmp_path; - Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + Geom::Path to_back; + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.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(); - const Curve &closingline = path_it->back_closed(); + 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) { - if(nSubpath == subpath){ + if (subpath_counter == subpath) { _satellites.push_back(_satellites[counter]); _satellites.erase(_satellites.begin() + counter); } else { @@ -189,43 +192,45 @@ Pointwise::subpath_to_back(size_t subpath){ } ++curve_it1; } - if(nSubpath == subpath){ - rev = *path_it; + if (subpath_counter == subpath) { + to_back = *path_it; } else { tmp_path.push_back(*path_it); } - nSubpath++; + subpath_counter++; } - tmp_path.push_back(rev); - setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); + tmp_path.push_back(to_back); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -void -Pointwise::subpath_reverse(size_t start,size_t end){ - start ++; - for(size_t i = end; i >= start; i--){ +void Pointwise::subpathReverse(size_t start, size_t end) +{ + start++; + for (size_t i = end; i >= start; i--) { _satellites.push_back(_satellites[i]); _satellites.erase(_satellites.begin() + i); } - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - size_t nSubpath = 0; - size_t subpath = _pathInfo.getSubPathIndex(start); + size_t subpath_counter = 0; + size_t subpath = _path_info.subPathIndex(start); std::vector tmp_path; Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { continue; } - counter ++; - if(nSubpath == subpath){ + counter++; + if (subpath_counter == subpath) { tmp_path.push_back(path_it->reverse()); } else { tmp_path.push_back(*path_it); } - nSubpath++; + subpath_counter++; } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } } // namespace Geom @@ -238,4 +243,6 @@ Pointwise::subpath_reverse(size_t start,size_t end){ fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 59ed4d1aa2..3ce1ca75a9 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,12 +1,12 @@ /** * \file * \brief Pointwise a class to manage a vector of satellites per piecewise curve - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef SEEN_GEOM_POINTWISE_H #define SEEN_GEOM_POINTWISE_H @@ -26,7 +26,7 @@ namespace Geom { * @brief Pointwise a class to manage a vector of satellites per piecewise curve * * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths + * much cases but not a real node satellite on open paths * To implement this we can: * add extra satellite in open paths, and take notice of current open paths * or put extra satellites on back for each open subpath @@ -35,30 +35,29 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ -class Pointwise -{ - public: - Pointwise(Piecewise > pwd2, std::vector satellites); - virtual ~Pointwise(); +class Pointwise { +public: + Pointwise(Piecewise > pwd2, std::vector satellites); + virtual ~Pointwise(); - Piecewise > getPwd2() const; - void setPwd2(Piecewise > pwd2_in); + Piecewise > getPwd2() const; + void setPwd2(Piecewise > pwd2_in); - std::vector getSatellites() const; - void setSatellites(std::vector sats); + std::vector getSatellites() const; + void setSatellites(std::vector sats); - void setStart(); + void setStart(); - void recalculate_for_new_pwd2(Piecewise > A); - void pwd2_sustract(Piecewise > A); - void pwd2_append(Piecewise > A); - void subpath_to_back(size_t subpath); - void subpath_reverse(size_t start,size_t end); + void recalculateForNewPwd2(Piecewise > A); + void pwd2Sustract(Piecewise > A); + void pwd2Append(Piecewise > A); + void subpathToBack(size_t subpath); + void subpathReverse(size_t start, size_t end); - private: - Piecewise > _pwd2; - std::vector _satellites; - Pathinfo _pathInfo; +private: + Piecewise > _pwd2; + std::vector _satellites; + Pathinfo _path_info; }; } // end namespace Geom @@ -73,4 +72,6 @@ class Pointwise fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h index 4680ce2f61..d82cdabe02 100644 --- a/src/helper/geom-satellite-enum.h +++ b/src/helper/geom-satellite-enum.h @@ -4,23 +4,23 @@ /** * \file * \brief Satellite types enum - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include "util/enums.h" namespace Geom { enum SatelliteType { - F=0, //Fillet - IF, //Inverse Fillet - C, //Chamfer - IC, //Inverse Chamfer - KO // Invalid Satellite) + F = 0, //Fillet + IF, //Inverse Fillet + C, //Chamfer + IC, //Inverse Chamfer + KO // Invalid Satellite) }; } //namespace Geom diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 6304b41481..efe6bb37ad 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,12 +1,12 @@ /** * \file * \brief Satellite a per ?node/curve holder of data. - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include #include <2geom/curve.h> @@ -17,26 +17,31 @@ #include <2geom/ray.h> #include - namespace Geom { /** * @brief Satellite a per ?node/curve holder of data. */ -Satellite::Satellite(){}; +Satellite::Satellite() {} +; -Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) - : satelliteType(satelliteType), isTime(isTime), active(active), hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), steps(steps){}; +Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, + bool hasMirror, bool hidden, double amount, double angle, + size_t steps) + : satelliteType(satelliteType), isTime(isTime), active(active), + hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), + steps(steps) {} +; -Satellite::~Satellite() {}; +Satellite::~Satellite() {} +; /** * Calculate the time in d2_in with a size of A */ -double -Satellite::toTime(double A,Geom::D2 d2_in) const +double Satellite::toTime(double A, Geom::D2 d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double t = 0; @@ -61,10 +66,9 @@ Satellite::toTime(double A,Geom::D2 d2_in) const /** * Calculate the size in d2_in with a point at A */ -double -Satellite::toSize(double A,Geom::D2 d2_in) const +double Satellite::toSize(double A, Geom::D2 d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double s = 0; @@ -84,66 +88,78 @@ Satellite::toSize(double A,Geom::D2 d2_in) const /** * Calculate the lenght of a satellite from a radious A input. */ -double -Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +double Satellite::radToLen( + double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const { double len = 0; - if(d2_in && previousSatellite){ - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); - Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + if (d2_in && previousSatellite) { + 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); + if (cs.size() > 0) { + Point cp = p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); - len = (*previousSatellite).toSize(p0pt,d2_out); + len = (*previousSatellite).toSize(p0pt, d2_out); } else { - if(A > 0){ - len = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite); + if (A > 0) { + len = radToLen(A * -1, *d2_in, d2_out, previousSatellite); } } } return len; } - /** - * Calculate the radious of a satellite from a lenght A input. - */ -double -Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +/** +* Calculate the radious of a satellite from a lenght A input. +*/ +double Satellite::lenToRad( + double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const { - if(d2_in && previousSatellite){ - double time_in = (*previousSatellite).getOpositeTime(A, *d2_in); - double time_out = (*previousSatellite).toTime(A,d2_out); + if (d2_in && previousSatellite) { + double time_in = (*previousSatellite).time(A, true, *d2_in); + double time_out = (*previousSatellite).toTime(A, d2_out); Geom::Point startArcPoint = (*d2_in).valueAt(time_in); Geom::Point endArcPoint = d2_out.valueAt(time_out); Piecewise > u; u.push_cut(0); u.push(*d2_in, 1); - Geom::Curve * C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); Piecewise > u2; u2.push_cut(0); u2.push(d2_out, 1); - Geom::Curve * D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); Curve *knotCurve1 = C->portion(0, time_in); Curve *knotCurve2 = D->portion(time_out, 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Geom::CubicBezier const *cubic1 = + dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, (*d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); Ray ray2(d2_out.valueAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,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); - double divisor = std::sin(angleBetween/2.0); - if(divisor > 0){ - return distanceArc/divisor; + double divisor = std::sin(angleBetween / 2.0); + if (divisor > 0) { + return distanceArc / divisor; } } return 0; @@ -152,14 +168,13 @@ Satellite::len_to_rad(double A, boost::optional > d2_in, /** * Get the time position of the satellite in d2_in */ -double -Satellite::getTime(Geom::D2 d2_in) const +double Satellite::time(Geom::D2 d2_in) const { double t = amount; - if(!isTime){ + if (!isTime) { t = toTime(t, d2_in); } - if(t > 1){ + if (t > 1) { t = 1; } return t; @@ -168,16 +183,16 @@ Satellite::getTime(Geom::D2 d2_in) const /**. * Get the time from a lenght A in other curve, a bolean I gived to reverse time */ -double -Satellite::getTime(double A, bool I, Geom::D2 d2_in) const +double Satellite::time(double A, bool I, + Geom::D2 d2_in) const { - if(A == 0 && I){ + if (A == 0 && I) { return 1; } - if(A == 0 && !I){ + if (A == 0 && !I) { return 0; } - if(!I){ + if (!I) { return toTime(A, d2_in); } double lenghtPart = Geom::length(d2_in, Geom::EPSILON); @@ -188,11 +203,10 @@ Satellite::getTime(double A, bool I, Geom::D2 d2_in) const /** * Get the lenght of the satellite in d2_in */ -double -Satellite::getSize(Geom::D2 d2_in) const +double Satellite::size(Geom::D2 d2_in) const { double s = amount; - if(isTime){ + if (isTime) { s = toSize(s, d2_in); } return s; @@ -201,21 +215,19 @@ Satellite::getSize(Geom::D2 d2_in) const /** * Get the point position of the satellite */ -Geom::Point -Satellite::getPosition(Geom::D2 d2_in) const +Geom::Point Satellite::getPosition(Geom::D2 d2_in) const { - double t = getTime(d2_in); + double t = time(d2_in); return d2_in.valueAt(t); } /** * Set the position of the satellite from a gived point P */ -void -Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { double A = Geom::nearest_point(p, d2_in); - if(!isTime){ + if (!isTime) { A = toSize(A, d2_in); } amount = A; @@ -224,21 +236,20 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) /** * Map a satellite type with gchar */ -void -Satellite::setSatelliteType(gchar const * A) +void Satellite::setSatelliteType(gchar const *A) { - std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + std::map GcharMapToSatelliteType = + boost::assign::map_list_of("F", F)("IF", IF)("C", C)("IC", IC)("KO", KO); satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; } - /** * Map a gchar with satelliteType */ -gchar const * -Satellite::getSatelliteTypeGchar() const +gchar const *Satellite::getSatelliteTypeGchar() const { - std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); + std::map SatelliteTypeToGcharMap = + boost::assign::map_list_of(F, "F")(IF, "IF")(C, "C")(IC, "IC")(KO, "KO"); return SatelliteTypeToGcharMap.at(satelliteType); } @@ -253,4 +264,6 @@ Satellite::getSatelliteTypeGchar() const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index d4550b9220..df54819fdc 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,12 +1,12 @@ /** * \file * \brief Satellite a per ?node/curve holder of data. - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef LIB2GEOM_SEEN_SATELLITE_H #define LIB2GEOM_SEEN_SATELLITE_H @@ -21,29 +21,34 @@ namespace Geom { /** * @brief Satellite a per ?node/curve holder of data. */ -class Satellite -{ - public: +class Satellite { +public: Satellite(); - Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); + Satellite(SatelliteType satelliteType, bool isTime, bool active, + bool hasMirror, bool hidden, double amount, double angle, + size_t steps); virtual ~Satellite(); - double toSize(double A,Geom::D2 d2_in) const; - double toTime(double A,Geom::D2 d2_in) const; - double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; - double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + double toSize(double A, Geom::D2 d2_in) const; + double toTime(double A, Geom::D2 d2_in) const; + double lenToRad(double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const; + double radToLen(double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const; - double getTime(Geom::D2 d2_in) const; - double getTime(double A, bool I, Geom::D2 d2_in) const; - double getSize(Geom::D2 d2_in) const; + double time(Geom::D2 d2_in) const; + double time(double A, bool I, Geom::D2 d2_in) const; + double size(Geom::D2 d2_in) const; void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 d2_in) const; - void setSatelliteType(gchar const * A); - gchar const * getSatelliteTypeGchar() const; + void setSatelliteType(gchar const *A); + gchar const *getSatelliteTypeGchar() const; //TODO: maybe make after variables protected? SatelliteType satelliteType; bool isTime; @@ -68,4 +73,6 @@ class Satellite fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index e873bebf9f..6e026550a7 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 e56200a170..c519679f8c 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 24a491b4b8..bac9073430 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 ee0cfbad35..bb53af12bd 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; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 443a48c13e..2960f0d344 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -53,7 +53,7 @@ FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() _fillet_chamfer_position_numeric.set_increments(1,1); //todo: get tha max aloable infinity freeze the widget _fillet_chamfer_position_numeric.set_range(0., 999999999999999999.); - + _fillet_chamfer_position_label.set_label(_("Radius (pixels):")); _fillet_chamfer_position_label.set_alignment(1.0, 0.5); @@ -65,7 +65,7 @@ FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() _fillet_chamfer_chamfer_subdivisions.set_increments(1,1); //todo: get tha max aloable infinity freeze the widget _fillet_chamfer_chamfer_subdivisions.set_range(1, 4294967295); - + _fillet_chamfer_chamfer_subdivisions_label.set_label(_("Chamfer subdivisions:")); _fillet_chamfer_chamfer_subdivisions_label.set_alignment(1.0, 0.5); @@ -119,29 +119,29 @@ FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() { - _set_desktop(NULL); + _setDesktop(NULL); } void FilletChamferPropertiesDialog::showDialog( - SPDesktop *desktop, double amount, + SPDesktop *desktop, double _amount, const Inkscape::LivePathEffect:: FilletChamferKnotHolderEntity *pt, - const gchar *unit, - bool use_distance, - bool aprox_radius, - Glib::ustring documentUnit, - Geom::Satellite satellite) + const gchar *_unit, + bool _use_distance, + bool _aprox_radius, + Glib::ustring _documentUnit, + Geom::Satellite _satellite) { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); - dialog->_set_desktop(desktop); - dialog->_set_unit(unit); - dialog->_set_use_distance(use_distance); - dialog->_set_aprox(aprox_radius); - dialog->_set_document_unit(documentUnit); - dialog->_set_amount(amount); - dialog->_set_satellite(satellite); - dialog->_set_pt(pt); + dialog->_setDesktop(desktop); + dialog->_setUnit(_unit); + dialog->_setUseDistance(_use_distance); + dialog->_setAprox(_aprox_radius); + dialog->_setDocumentUnit(_documentUnit); + dialog->_setAmount(_amount); + dialog->_setSatellite(_satellite); + dialog->_setPt(pt); dialog->set_title(_("Modify Fillet-Chamfer")); dialog->_apply_button.set_label(_("_Modify")); @@ -156,7 +156,7 @@ void FilletChamferPropertiesDialog::showDialog( void FilletChamferPropertiesDialog::_apply() { - + double d_pos = _fillet_chamfer_position_numeric.get_value(); if (d_pos >= 0) { if (_fillet_chamfer_type_fillet.get_active() == true) { @@ -174,11 +174,11 @@ void FilletChamferPropertiesDialog::_apply() } d_pos = d_pos / 100; } else { - d_pos = Inkscape::Util::Quantity::convert(d_pos, unit, document_unit); + d_pos = Inkscape::Util::Quantity::convert(d_pos, _unit, _document_unit); } _satellite.amount = d_pos; size_t steps = (size_t)_fillet_chamfer_chamfer_subdivisions.get_value(); - if(steps < 1){ + if(steps < 1) { steps = 1; } _satellite.steps = steps; @@ -189,7 +189,7 @@ void FilletChamferPropertiesDialog::_apply() void FilletChamferPropertiesDialog::_close() { - _set_desktop(NULL); + _setDesktop(NULL); destroy_(); Glib::signal_idle().connect( sigc::bind_return( @@ -211,26 +211,26 @@ void FilletChamferPropertiesDialog::_handleButtonEvent(GdkEventButton *event) } } -void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) +void FilletChamferPropertiesDialog::_setSatellite(Geom::Satellite satellite) { double position; std::string distance_or_radius = std::string(_("Radius")); - if(aprox){ + if(_aprox) { distance_or_radius = std::string(_("Radius approximated")); } - if(use_distance){ + if(_use_distance) { distance_or_radius = std::string(_("Knot distance")); } if (satellite.isTime) { - position = amount * 100; + position = _amount * 100; _flexible = true; _fillet_chamfer_position_label.set_label(_("Position (%):")); } else { _flexible = false; - std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, unit); + std::string posConcat = Glib::ustring::compose (_("%1 (%2):"), distance_or_radius, _unit); _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); - position = amount; - position = Inkscape::Util::Quantity::convert(position, document_unit, unit); + position = _amount; + position = Inkscape::Util::Quantity::convert(position, _document_unit, _unit); } _fillet_chamfer_position_numeric.set_value(position); _fillet_chamfer_chamfer_subdivisions.set_value(satellite.steps); @@ -246,7 +246,7 @@ void FilletChamferPropertiesDialog::_set_satellite(Geom::Satellite satellite) _satellite = satellite; } -void FilletChamferPropertiesDialog::_set_pt( +void FilletChamferPropertiesDialog::_setPt( const Inkscape::LivePathEffect:: FilletChamferKnotHolderEntity *pt) { @@ -255,35 +255,35 @@ void FilletChamferPropertiesDialog::_set_pt( pt); } -void FilletChamferPropertiesDialog::_set_unit(const gchar *abbr) +void FilletChamferPropertiesDialog::_setUnit(const gchar *abbr) { - unit = abbr; + _unit = abbr; } -void FilletChamferPropertiesDialog::_set_amount(double amm) +void FilletChamferPropertiesDialog::_setAmount(double amm) { - amount = amm; + _amount = amm; } -void FilletChamferPropertiesDialog::_set_document_unit(Glib::ustring abbr) +void FilletChamferPropertiesDialog::_setDocumentUnit(Glib::ustring abbr) { - document_unit = abbr; + _document_unit = abbr; } -void FilletChamferPropertiesDialog::_set_use_distance(bool use_knot_distance) +void FilletChamferPropertiesDialog::_setUseDistance(bool use_knot_distance) { - use_distance = use_knot_distance; + _use_distance = use_knot_distance; } -void FilletChamferPropertiesDialog::_set_aprox(bool aprox_radius) +void FilletChamferPropertiesDialog::_setAprox(bool _aprox_radius) { - aprox = aprox_radius; + _aprox = _aprox_radius; } -void FilletChamferPropertiesDialog::_set_desktop(SPDesktop *desktop) +void FilletChamferPropertiesDialog::_setDesktop(SPDesktop *desktop) { if (desktop) { Inkscape::GC::anchor(desktop); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 1a40eea9b4..51fc847c3f 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -23,18 +23,19 @@ public: FilletChamferPropertiesDialog(); virtual ~FilletChamferPropertiesDialog(); - Glib::ustring getName() const { + Glib::ustring getName() const + { return "LayerPropertiesDialog"; } - static void showDialog(SPDesktop *desktop, double amount, + static void showDialog(SPDesktop *desktop, double _amount, const Inkscape::LivePathEffect:: FilletChamferKnotHolderEntity *pt, - const gchar *unit, - bool use_distance, - bool aprox_radius, - Glib::ustring documentUnit, - Geom::Satellite satellite); + const gchar *_unit, + bool _use_distance, + bool _aprox_radius, + Glib::ustring _documentUnit, + Geom::Satellite _satellite); protected: @@ -60,36 +61,39 @@ protected: sigc::connection _destroy_connection; - static FilletChamferPropertiesDialog &_instance() { + static FilletChamferPropertiesDialog &_instance() + { static FilletChamferPropertiesDialog instance; return instance; } - void _set_desktop(SPDesktop *desktop); - void _set_pt(const Inkscape::LivePathEffect:: + void _setDesktop(SPDesktop *desktop); + void _setPt(const Inkscape::LivePathEffect:: FilletChamferKnotHolderEntity *pt); - void _set_unit(const gchar *abbr); - void _set_document_unit(Glib::ustring abbr); - void _set_use_distance(bool use_knot_distance); - void _set_aprox(bool aprox_radius); + void _setUnit(const gchar *abbr); + void _setDocumentUnit(Glib::ustring abbr); + void _setUseDistance(bool use_knot_distance); + void _setAprox(bool aprox_radius); + void _setAmount(double amount); + void _setSatellite(Geom::Satellite satellite); + void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); + + bool _handleKeyEvent(GdkEventKey *event); + void _handleButtonEvent(GdkEventButton *event); + void _apply(); void _close(); bool _flexible; Geom::Satellite _satellite; - const gchar *unit; - Glib::ustring document_unit; - bool use_distance; - double amount; - bool aprox; - void _set_amount(double amount); - void _set_satellite(Geom::Satellite satellite); - void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); + const gchar *_unit; + Glib::ustring _document_unit; + bool _use_distance; + double _amount; + bool _aprox; - bool _handleKeyEvent(GdkEventKey *event); - void _handleButtonEvent(GdkEventButton *event); friend class Inkscape::LivePathEffect:: - FilletChamferKnotHolderEntity; + FilletChamferKnotHolderEntity; private: FilletChamferPropertiesDialog( -- GitLab From de70b4b2d0611dbf45ec6adc3f29a36137ce7c42 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 19:26:07 +0200 Subject: [PATCH 043/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6e026550a7..6ff0988946 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 c519679f8c..dc21996090 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; -- GitLab From e7fc8e1fde0b795b34ab0db85575bbf7c9c11791 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 2 Apr 2015 21:47:51 +0200 Subject: [PATCH 044/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ff0988946..ac412e120d 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 bac9073430..0e42c23c58 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; -- GitLab From 323fc5ae45fd8374de4561d0771f6b9d5cd3e87a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 01:46:44 +0200 Subject: [PATCH 045/121] Adding suport for duplicate nodes Allow degenrate curves Show helper path whith original path (bzr r13645.1.70) --- src/helper/geom-pointwise.cpp | 14 ++++++------- src/live_effects/lpe-fillet-chamfer.cpp | 28 +++++++++++++++++-------- src/live_effects/lpe-fillet-chamfer.h | 3 ++- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index cfe93311cb..261d2bff47 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -123,28 +123,26 @@ void Pointwise::pwd2Append(Piecewise > A) size_t new_subpath_index = _path_info.subPathIndex(i); _path_info.setPwd2(_pwd2); bool subpath_is_changed = false; + bool not_exist = ; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if (!reorder && first == i - counter && - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && - !subpath_is_changed) { + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if (!reversed && first == i - counter && - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && - !subpath_is_changed) { + if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)) { + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) || + /*this condition for duplicate node Shift+d*/(i > 0 && are_near(A[i - 1].at0(), A[i].at0(), 0.001) && + !are_near(_pwd2[i - counter].at0(), _pwd2[i - counter - 1].at0(), 0.001))){ counter++; bool active = true; bool hidden = false; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ac412e120d..f7fd6f64bd 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 dc21996090..e3ea41ba83 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 &); -- GitLab From 04218b26ae0a10bf9e64721fb0dd789f024afca5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 16:10:46 +0200 Subject: [PATCH 046/121] 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/helper/geom-pathinfo.cpp | 42 ++++++++++++----- src/helper/geom-pathinfo.h | 12 +++-- src/helper/geom-pointwise.cpp | 62 ++++++++++++++++++++++--- src/helper/geom-pointwise.h | 3 +- src/live_effects/lpe-fillet-chamfer.cpp | 38 ++------------- src/live_effects/lpe-fillet-chamfer.h | 2 - src/ui/tool/multi-path-manipulator.cpp | 10 ++-- src/ui/tool/path-manipulator.cpp | 7 --- 8 files changed, 107 insertions(+), 69 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f120045351..f9d4e5dbba 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -19,25 +19,40 @@ namespace Geom { */ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { - _setPathInfo(); + _setPathInfo(pwd2); +} +; +Pathinfo::Pathinfo(Geom::PathVector path_vector) : _path_vector(path_vector) +{ + _setPathInfo(path_vector); } ; Pathinfo::~Pathinfo() {} ; -void Pathinfo::setPwd2(Piecewise > pwd2_in) +void Pathinfo::setPwd2(Piecewise > pwd2) +{ + _pwd2 = pwd2; + _setPathInfo(pwd2); +} + +void Pathinfo::setPathVector(Geom::PathVector path_vector) { - _pwd2 = pwd2_in; - _setPathInfo(); + _path_vector = path_vector; + _setPathInfo(path_vector); } +void Pathinfo::_setPathInfo(Piecewise > pwd2) +{ + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); +} /** Store the base path data */ -void Pathinfo::_setPathInfo() +void Pathinfo::_setPathInfo(Geom::PathVector path_vector) { data.clear(); - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; for (PathVector::const_iterator path_it = path_in.begin(); @@ -65,6 +80,11 @@ void Pathinfo::_setPathInfo() } } +size_t Pathinfo::numberCurves() const +{ + return data.back().first; +} + size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < data.size(); i++) { @@ -101,10 +121,10 @@ size_t Pathinfo::first(size_t index) const boost::optional Pathinfo::previous(size_t index) const { - if (first(index) == index && isClosed(index)) { + if (first(index) == index && closed(index)) { return last(index); } - if (first(index) == index && !isClosed(index)) { + if (first(index) == index && !closed(index)) { return boost::none; } return index - 1; @@ -112,16 +132,16 @@ boost::optional Pathinfo::previous(size_t index) const boost::optional Pathinfo::next(size_t index) const { - if (last(index) == index && isClosed(index)) { + if (last(index) == index && closed(index)) { return first(index); } - if (last(index) == index && !isClosed(index)) { + if (last(index) == index && !closed(index)) { return boost::none; } return index + 1; } -bool Pathinfo::isClosed(size_t index) const +bool Pathinfo::closed(size_t index) const { for (size_t i = 0; i < data.size(); i++) { if (index <= data[i].first) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index c9d8e28628..c41d92e7aa 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -23,20 +23,24 @@ namespace Geom { class Pathinfo { public: Pathinfo(Piecewise > pwd2); + Pathinfo(Geom::PathVector path_vector); virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2_in); + void setPwd2(Piecewise > pwd2); + void setPathVector(Geom::PathVector path_vector); + size_t numberCurves() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; boost::optional previous(size_t index) const; boost::optional next(size_t index) const; - bool isClosed(size_t index) const; - std::vector > pathInfo() const; + bool closed(size_t index) const; std::vector > data; private: - void _setPathInfo(); + void _setPathInfo(Geom::PathVector path_vector); + void _setPathInfo(Piecewise > pwd2); Piecewise > _pwd2; + Geom::PathVector _path_vector; }; } //namespace Geom diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 261d2bff47..714573ad51 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -66,7 +66,7 @@ void Pointwise::setStart() for (size_t i = 0; i < path_info.size(); i++) { size_t firstNode = _path_info.first(path_info[i].first); size_t lastNode = _path_info.last(path_info[i].first); - if (!_path_info.isClosed(lastNode)) { + if (!_path_info.closed(lastNode)) { _satellites[firstNode].hidden = true; _satellites[firstNode].active = false; } else { @@ -78,12 +78,14 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A) +void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A); + } else { + insertDegenerateSatellites(A,B); } } @@ -123,7 +125,6 @@ void Pointwise::pwd2Append(Piecewise > A) size_t new_subpath_index = _path_info.subPathIndex(i); _path_info.setPwd2(_pwd2); bool subpath_is_changed = false; - bool not_exist = ; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; } else { @@ -140,9 +141,8 @@ void Pointwise::pwd2Append(Piecewise > A) subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) || - /*this condition for duplicate node Shift+d*/(i > 0 && are_near(A[i - 1].at0(), A[i].at0(), 0.001) && - !are_near(_pwd2[i - counter].at0(), _pwd2[i - counter - 1].at0(), 0.001))){ + + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)){ counter++; bool active = true; bool hidden = false; @@ -231,6 +231,56 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } + +/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. + */ +void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B) +{ + size_t size_A = A.size(); + _path_info.setPathVector(B); + size_t size_B = _path_info.numberCurves(); + size_t satellite_gap = size_B - size_A; + if (satellite_gap == 0){ + return; + } + size_t counter = 0; + size_t counter_added = 0; + for (PathVector::const_iterator path_it = B.begin(); + path_it != B.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(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + } + while (curve_it1 != curve_endit) { + if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ + counter_added++; + bool active = true; + bool hidden = false; + bool is_time = _satellites[0].isTime; + bool mirror_knots = _satellites[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); + _satellites.insert(_satellites.begin() + counter ,sat); + } + ++curve_it1; + counter++; + } + } + + _path_info.setPwd2(A); + setPwd2(A); +} + } // namespace Geom /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 3ce1ca75a9..48ee36255a 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -48,11 +48,12 @@ public: void setStart(); - void recalculateForNewPwd2(Piecewise > A); + void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B); void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); + void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B); private: Piecewise > _pwd2; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f7fd6f64bd..fdf2469e0d 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 e3ea41ba83..6acc9fb400 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 &); diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index f53cef5f46..8a8e4cb8a6 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -330,20 +330,20 @@ void MultiPathManipulator::insertNodes() { if (_selection.empty()) return; invokeForAll(&PathManipulator::insertNodes); - _done(_("Add nodes")); + _done(_("Add nodes"), true); } void MultiPathManipulator::insertNodesAtExtrema(ExtremumType extremum) { if (_selection.empty()) return; invokeForAll(&PathManipulator::insertNodeAtExtremum, extremum); - _done(_("Add extremum nodes")); + _done(_("Add extremum nodes"), true); } void MultiPathManipulator::duplicateNodes() { if (_selection.empty()) return; invokeForAll(&PathManipulator::duplicateNodes); - _done(_("Duplicate nodes")); + _done(_("Duplicate nodes"), true); } void MultiPathManipulator::joinNodes() @@ -483,10 +483,10 @@ void MultiPathManipulator::reverseSubpaths() { if (_selection.empty()) { invokeForAll(&PathManipulator::reverseSubpaths, false); - _done("Reverse subpaths"); + _done("Reverse subpaths", true); } else { invokeForAll(&PathManipulator::reverseSubpaths, true); - _done("Reverse selected subpaths"); + _done("Reverse selected subpaths", true); } } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index dbae69f2ca..d50c3057bc 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1356,13 +1356,6 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) lpe_pwr->adjustForNewPath(pathv); } } - thisEffect = _path->getPathEffectOfType(Inkscape::LivePathEffect::FILLET_CHAMFER); - if(thisEffect){ - LivePathEffect::LPEFilletChamfer *lpe_fll = dynamic_cast(thisEffect->getLPEObj()->get_lpe()); - if (lpe_fll) { - lpe_fll->adjustForNewPath(pathv); - } - } } } -- GitLab From 49ec02c315e6e5068b1ad395c01db2b536dd9b9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 21:20:55 +0200 Subject: [PATCH 047/121] 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/helper/geom-pathinfo.cpp | 14 +++++++++----- src/helper/geom-pathinfo.h | 6 +++--- src/helper/geom-pointwise.cpp | 10 +++++----- src/live_effects/lpe-fillet-chamfer.cpp | 8 ++++---- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f9d4e5dbba..a37c0e475f 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -22,9 +22,9 @@ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) _setPathInfo(pwd2); } ; -Pathinfo::Pathinfo(Geom::PathVector path_vector) : _path_vector(path_vector) +Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) : _path_vector(path_vector) { - _setPathInfo(path_vector); + _setPathInfo(path_vector, skip_degenerate); } ; @@ -37,10 +37,10 @@ void Pathinfo::setPwd2(Piecewise > pwd2) _setPathInfo(pwd2); } -void Pathinfo::setPathVector(Geom::PathVector path_vector) +void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) { _path_vector = path_vector; - _setPathInfo(path_vector); + _setPathInfo(path_vector, skip_degenerate); } void Pathinfo::_setPathInfo(Piecewise > pwd2) @@ -49,7 +49,7 @@ void Pathinfo::_setPathInfo(Piecewise > pwd2) } /** Store the base path data */ -void Pathinfo::_setPathInfo(Geom::PathVector path_vector) +void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) { data.clear(); Geom::PathVector path_in = @@ -69,6 +69,10 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector) } } while (curve_it1 != curve_endit) { + if(curve_it1->isDegenerate() && skip_degenerate ){ + ++curve_it1; + continue; + } ++curve_it1; counter++; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index c41d92e7aa..021fcca2b7 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -23,10 +23,10 @@ namespace Geom { class Pathinfo { public: Pathinfo(Piecewise > pwd2); - Pathinfo(Geom::PathVector path_vector); + Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); void setPwd2(Piecewise > pwd2); - void setPathVector(Geom::PathVector path_vector); + void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); size_t numberCurves() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; @@ -37,8 +37,8 @@ public: std::vector > data; private: - void _setPathInfo(Geom::PathVector path_vector); void _setPathInfo(Piecewise > pwd2); + void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); Piecewise > _pwd2; Geom::PathVector _path_vector; }; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 714573ad51..f68c9b13f0 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -99,7 +99,7 @@ void Pointwise::pwd2Sustract(Piecewise > A) setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || - !are_near(pwd2[i].at0(), A[i - counter].at0(), 0.001)) { + !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -130,19 +130,19 @@ void Pointwise::pwd2Append(Piecewise > A) } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { + if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)){ + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ counter++; bool active = true; bool hidden = false; @@ -270,7 +270,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV int steps = 0; Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, hidden, amount, degrees, steps); - _satellites.insert(_satellites.begin() + counter ,sat); + _satellites.insert(_satellites.begin() + counter + 1 ,sat); } ++curve_it1; counter++; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index fdf2469e0d..6cc9062d93 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; -- GitLab From f4864a7048b05cfe032027470c58e5ef2b69bd59 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:21:27 +0200 Subject: [PATCH 048/121] Fix a bug in pathinfo (bzr r13645.1.74) --- src/helper/geom-pathinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475f..99ca3c8aae 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -45,7 +45,7 @@ void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) void Pathinfo::_setPathInfo(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001), true); } /** Store the base path data */ -- GitLab From c6457829dc2711fca07f5f27ecc597dc4f932929 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:59:57 +0200 Subject: [PATCH 049/121] fixing bug on closed paths (bzr r13645.1.76) --- src/helper/geom-pathinfo.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 99ca3c8aae..a37c0e475f 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -45,7 +45,7 @@ void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) void Pathinfo::_setPathInfo(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001), true); + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } /** Store the base path data */ diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6cc9062d93..ac877c7929 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); -- GitLab From 22ded87a8ca58e0ff4400b2d4e76787f4ac22bd6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 19:39:38 +0200 Subject: [PATCH 050/121] Fixed bug on closed paths, Clenup of pathinfo (bzr r13645.1.77) --- src/helper/geom-pathinfo.cpp | 12 ++++-------- src/helper/geom-pathinfo.h | 2 -- src/live_effects/lpe-fillet-chamfer.cpp | 5 +++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475f..ac94c02816 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -17,12 +17,12 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) +Pathinfo::Pathinfo(Piecewise > pwd2) { _setPathInfo(pwd2); } ; -Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) : _path_vector(path_vector) +Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) { _setPathInfo(path_vector, skip_degenerate); } @@ -33,13 +33,11 @@ Pathinfo::~Pathinfo() {} void Pathinfo::setPwd2(Piecewise > pwd2) { - _pwd2 = pwd2; _setPathInfo(pwd2); } void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) { - _path_vector = path_vector; _setPathInfo(path_vector, skip_degenerate); } @@ -52,11 +50,9 @@ void Pathinfo::_setPathInfo(Piecewise > pwd2) void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) { data.clear(); - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + for (PathVector::const_iterator path_it = path_vector.begin(); + path_it != path_vector.end(); ++path_it) { if (path_it->empty()) { continue; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 021fcca2b7..7a597202f2 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -39,8 +39,6 @@ public: private: void _setPathInfo(Piecewise > pwd2); void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); - Piecewise > _pwd2; - Geom::PathVector _path_vector; }; } //namespace Geom diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ac877c7929..935e97ec9f 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); -- GitLab From 74649824e41b26bcf560ba485364a6ffe7b80fca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 20:12:48 +0200 Subject: [PATCH 051/121] rename pathinfo function (bzr r13645.1.78) --- src/helper/geom-pathinfo.cpp | 4 ++-- src/helper/geom-pathinfo.h | 2 +- src/helper/geom-pointwise.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index ac94c02816..0cb7c64dd3 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -80,9 +80,9 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) } } -size_t Pathinfo::numberCurves() const +size_t Pathinfo::size() const { - return data.back().first; + return data.back().first + 1; } size_t Pathinfo::subPathIndex(size_t index) const diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 7a597202f2..73220b9590 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -27,7 +27,7 @@ public: virtual ~Pathinfo(); void setPwd2(Piecewise > pwd2); void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); - size_t numberCurves() const; + size_t size() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index f68c9b13f0..54cfbb45de 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -238,7 +238,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV { size_t size_A = A.size(); _path_info.setPathVector(B); - size_t size_B = _path_info.numberCurves(); + size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 935e97ec9f..cad67cea95 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 { -- GitLab From 1a4fb1c5b0c91ed84f3a98bc78cfc725d043e629 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:22:14 +0200 Subject: [PATCH 052/121] Adding and renaming methofs to pathinfo (bzr r13645.1.79) --- src/helper/geom-pathinfo.cpp | 5 ++++ src/helper/geom-pathinfo.h | 1 + src/helper/geom-pointwise.cpp | 40 +++++++------------------ src/helper/geom-pointwise.h | 6 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 11 ++++++- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 0cb7c64dd3..8144564cb9 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -85,6 +85,11 @@ size_t Pathinfo::size() const return data.back().first + 1; } +size_t Pathinfo::subPathSize(size_t index) const +{ + return data[index].first + 1; +} + size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < data.size(); i++) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 73220b9590..85c4ca6fa8 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -28,6 +28,7 @@ public: void setPwd2(Piecewise > pwd2); void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); size_t size() const; + size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 54cfbb45de..5b153841b3 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -78,14 +78,14 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B) +void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { - pwd2Append(A); + pwd2Append(A, S); } else { - insertDegenerateSatellites(A,B); + insertDegenerateSatellites(A, B, S); } } @@ -110,11 +110,10 @@ void Pointwise::pwd2Sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > A) +void Pointwise::pwd2Append(Piecewise > A, Satellite S) { size_t counter = 0; std::vector sats; - bool reversed = false; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { size_t first = _path_info.first(i - counter); @@ -130,6 +129,7 @@ void Pointwise::pwd2Append(Piecewise > A) } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); @@ -137,23 +137,14 @@ void Pointwise::pwd2Append(Piecewise > A) i--; continue; } - if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + + if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { subpathReverse(first, last); - reversed = true; } if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ counter++; - bool active = true; - bool hidden = false; - bool is_time = _satellites[0].isTime; - bool mirror_knots = _satellites[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); - sats.push_back(sat); + sats.push_back(S); } else { sats.push_back(_satellites[i - counter]); } @@ -205,7 +196,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) { start++; for (size_t i = end; i >= start; i--) { - _satellites.push_back(_satellites[i]); + _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); _satellites.erase(_satellites.begin() + i); } std::vector path_in = @@ -234,7 +225,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B) +void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) { size_t size_A = A.size(); _path_info.setPathVector(B); @@ -261,16 +252,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV while (curve_it1 != curve_endit) { if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ counter_added++; - bool active = true; - bool hidden = false; - bool is_time = _satellites[0].isTime; - bool mirror_knots = _satellites[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); - _satellites.insert(_satellites.begin() + counter + 1 ,sat); + _satellites.insert(_satellites.begin() + counter + 1 ,S); } ++curve_it1; counter++; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 48ee36255a..e4b9f2b05e 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -48,12 +48,12 @@ public: void setStart(); - void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B); + void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S); void pwd2Sustract(Piecewise > A); - void pwd2Append(Piecewise > A); + void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B); + void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); private: Piecewise > _pwd2; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index cad67cea95..a846e4bad4 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); } -- GitLab From b0de25aa4da8128cb2c3b8b92b67db5070c5ef72 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:25:02 +0200 Subject: [PATCH 053/121] added comment (bzr r13645.1.80) --- src/helper/geom-pointwise.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5b153841b3..6521e10b27 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -132,6 +132,7 @@ void Pointwise::pwd2Append(Piecewise > A, Satellite S) if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back + //TODO: change subpathToBack to subpath move for the case of multiple subpath reverse subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; -- GitLab From f3f25749ce81d3664a53e723c611645f78bdefa2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 18:47:54 +0200 Subject: [PATCH 054/121] adding suport to full path reverse (bzr r13645.1.82) --- src/helper/geom-pathinfo.cpp | 6 +++++- src/helper/geom-pointwise.cpp | 24 ++++++++++++++++++++++++ src/helper/geom-pointwise.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 8144564cb9..38d58d417a 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -87,7 +87,11 @@ size_t Pathinfo::size() const size_t Pathinfo::subPathSize(size_t index) const { - return data[index].first + 1; + size_t size = 0; + if( data.size() > index){ + size = data[index].first + 1; + } + return size; } size_t Pathinfo::subPathIndex(size_t index) const diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6521e10b27..74c594d68a 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -223,6 +223,26 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } +void Pointwise::pathReverse() +{ + start++; + for (size_t i = _satellites.size()-1; i >= 0; i--) { + _satellites.insert(_satellites.begin() + _satellites.size(), _satellites[i]); + _satellites.erase(_satellites.begin() + i); + } + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + std::vector tmp_path; + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + tmp_path.push_back(path_it->reverse()); + } + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); +} + /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ @@ -233,6 +253,10 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ + if(_path_info.subPathSize(1) > 0 && !are_near(_pwd2[0].initialPoint(), A[0].initialPoint()) && + !are_near(_pwd2[size_A-1].finalPoint(), A[size_A-1].finalPoint())){ + pathReverse(); + } return; } size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index e4b9f2b05e..590f25f6f5 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -52,6 +52,7 @@ public: void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); + void pathReverse(); void subpathReverse(size_t start, size_t end); void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); -- GitLab From 81dd40474313f2adbb1f59fb4ad9a38342f03752 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 20:51:06 +0200 Subject: [PATCH 055/121] prevent overflow index on a pathinfo function (bzr r13645.1.84) --- src/helper/geom-pointwise.cpp | 25 ------------------------- src/helper/geom-pointwise.h | 1 - 2 files changed, 26 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 74c594d68a..89bde41307 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -223,27 +223,6 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -void Pointwise::pathReverse() -{ - start++; - for (size_t i = _satellites.size()-1; i >= 0; i--) { - _satellites.insert(_satellites.begin() + _satellites.size(), _satellites[i]); - _satellites.erase(_satellites.begin() + i); - } - std::vector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - std::vector tmp_path; - for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - tmp_path.push_back(path_it->reverse()); - } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); -} - - /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) @@ -253,10 +232,6 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ - if(_path_info.subPathSize(1) > 0 && !are_near(_pwd2[0].initialPoint(), A[0].initialPoint()) && - !are_near(_pwd2[size_A-1].finalPoint(), A[size_A-1].finalPoint())){ - pathReverse(); - } return; } size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 590f25f6f5..e4b9f2b05e 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -52,7 +52,6 @@ public: void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); - void pathReverse(); void subpathReverse(size_t start, size_t end); void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); -- GitLab From 3ce6cb91e8259ec064956c79c2cc4f9050dccbce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 9 May 2015 22:48:48 +0200 Subject: [PATCH 056/121] fixing review (bzr r13645.1.86) --- src/helper/geom-pathinfo.cpp | 73 +++---- src/helper/geom-pathinfo.h | 25 +-- src/helper/geom-pointwise.cpp | 45 ++-- src/helper/geom-pointwise.h | 23 +- src/helper/geom-satellite-enum.h | 39 ---- src/helper/geom-satellite.cpp | 201 +++++++++--------- src/helper/geom-satellite.h | 50 +++-- 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 +- 13 files changed, 245 insertions(+), 304 deletions(-) delete mode 100644 src/helper/geom-satellite-enum.h diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 38d58d417a..9e5e409c32 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store the data of a pathvector and allow get info about it + * \brief Pathinfo store the _data of a pathvector and allow get info about it */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -11,48 +11,37 @@ #include #include <2geom/sbasis-to-bezier.h> -namespace Geom { - /** - * @brief Pathinfo store the data of a pathvector and allow get info about it + * @brief Pathinfo store the _data of a pathvector and allow get info about it * */ Pathinfo::Pathinfo(Piecewise > pwd2) { - _setPathInfo(pwd2); + set(pwd2); } -; + Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) { - _setPathInfo(path_vector, skip_degenerate); + set(path_vector, skip_degenerate); } -; -Pathinfo::~Pathinfo() {} -; -void Pathinfo::setPwd2(Piecewise > pwd2) -{ - _setPathInfo(pwd2); -} +Pathinfo::~Pathinfo() {} -void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) -{ - _setPathInfo(path_vector, skip_degenerate); -} -void Pathinfo::_setPathInfo(Piecewise > pwd2) +void Pathinfo::set(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); + set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } -/** Store the base path data +/** Store the base path _data */ -void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) +void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) { - data.clear(); + _data.clear(); size_t counter = 0; for (PathVector::const_iterator path_it = path_vector.begin(); - path_it != path_vector.end(); ++path_it) { + path_it != path_vector.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -73,31 +62,31 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) counter++; } if (path_it->closed()) { - data.push_back(std::make_pair(counter - 1, true)); + _data.push_back(std::make_pair(counter - 1, true)); } else { - data.push_back(std::make_pair(counter - 1, false)); + _data.push_back(std::make_pair(counter - 1, false)); } } } -size_t Pathinfo::size() const +size_t Pathinfo::subPathCounter() const { - return data.back().first + 1; + return _data.back().first + 1; } size_t Pathinfo::subPathSize(size_t index) const { size_t size = 0; - if( data.size() > index){ - size = data[index].first + 1; + if( _data.size() > index){ + size = _data[index].first + 1; } return size; } size_t Pathinfo::subPathIndex(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { return i; } } @@ -106,9 +95,9 @@ size_t Pathinfo::subPathIndex(size_t index) const size_t Pathinfo::last(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { - return data[i].first; + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { + return _data[i].first; } } return 0; @@ -116,12 +105,12 @@ size_t Pathinfo::last(size_t index) const size_t Pathinfo::first(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { if (i == 0) { return 0; } else { - return data[i - 1].first + 1; + return _data[i - 1].first + 1; } } } @@ -152,16 +141,14 @@ boost::optional Pathinfo::next(size_t index) const bool Pathinfo::closed(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { - return data[i].second; + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { + return _data[i].second; } } return false; } -}; // namespace Geom - /* Local Variables: mode:c++ diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 85c4ca6fa8..ae05f5b89e 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,7 @@ /** * \file - * \brief Pathinfo store the data of a pathvector and allow get info about it + * \brief Pathinfo store data of a pathvector and allow get info about it + * \ */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -8,26 +9,26 @@ * This code is in public domain */ -#ifndef SEEN_GEOM_PATHINFO_H -#define SEEN_GEOM_PATHINFO_H +#ifndef SEEN_PATHINFO_H +#define SEEN_PATHINFO_H #include <2geom/path.h> #include -namespace Geom { - /** * @brief Pathinfo store the data of a pathvector and allow get info about it * */ +using namespace Geom; class Pathinfo { public: Pathinfo(Piecewise > pwd2); Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2); - void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); - size_t size() const; + void set(Piecewise > pwd2); + void set(Geom::PathVector path_vector, bool skip_degenerate = false); + std::vector > get(){return _data;}; + size_t subPathCounter() const; size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; @@ -35,16 +36,12 @@ public: boost::optional previous(size_t index) const; boost::optional next(size_t index) const; bool closed(size_t index) const; - std::vector > data; private: - void _setPathInfo(Piecewise > pwd2); - void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); + std::vector > _data; }; -} //namespace Geom - -#endif //SEEN_GEOM_PATHINFO_H +#endif //SEEN_PATHINFO_H /* Local Variables: mode:c++ diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 89bde41307..bd03f1d895 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -10,8 +10,6 @@ #include -namespace Geom { - /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * @@ -31,20 +29,20 @@ Pointwise::Pointwise(Piecewise > pwd2, { setStart(); } -; + Pointwise::~Pointwise() {} -; + Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Piecewise > pwd2_in) +void Pointwise::setPwd2(Piecewise > const pwd2_in) { _pwd2 = pwd2_in; - _path_info.setPwd2(_pwd2); + _path_info.set(_pwd2); } std::vector Pointwise::getSatellites() const @@ -52,7 +50,7 @@ std::vector Pointwise::getSatellites() const return _satellites; } -void Pointwise::setSatellites(std::vector sats) +void Pointwise::setSatellites(std::vector const sats) { _satellites = sats; setStart(); @@ -62,7 +60,7 @@ void Pointwise::setSatellites(std::vector sats) */ void Pointwise::setStart() { - std::vector > path_info = _path_info.data; + std::vector > path_info = _path_info.get(); for (size_t i = 0; i < path_info.size(); i++) { size_t firstNode = _path_info.first(path_info[i].first); size_t lastNode = _path_info.last(path_info[i].first); @@ -78,7 +76,7 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S) +void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); @@ -91,7 +89,7 @@ void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Piecewise > A) +void Pointwise::pwd2Sustract(Piecewise > const A) { size_t counter = 0; std::vector sats; @@ -99,7 +97,8 @@ void Pointwise::pwd2Sustract(Piecewise > A) setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || - !are_near(pwd2[i].at0(), A[i - counter].at0())) { + !are_near(pwd2[i].at0(), A[i - counter].at0())) + { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -110,7 +109,7 @@ void Pointwise::pwd2Sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > A, Satellite S) +void Pointwise::pwd2Append(Piecewise > const A, Satellite const S) { size_t counter = 0; std::vector sats; @@ -120,9 +119,9 @@ void Pointwise::pwd2Append(Piecewise > A, Satellite S) size_t last = _path_info.last(i - counter); //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back - _path_info.setPwd2(A); + _path_info.set(A); size_t new_subpath_index = _path_info.subPathIndex(i); - _path_info.setPwd2(_pwd2); + _path_info.set(_pwd2); bool subpath_is_changed = false; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; @@ -163,7 +162,8 @@ void Pointwise::subpathToBack(size_t subpath) std::vector tmp_path; Geom::Path to_back; for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + path_it != path_in.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -208,7 +208,8 @@ void Pointwise::subpathReverse(size_t start, size_t end) std::vector tmp_path; Geom::Path rev; for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + path_it != path_in.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -225,11 +226,11 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) +void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S) { size_t size_A = A.size(); - _path_info.setPathVector(B); - size_t size_B = _path_info.size(); + _path_info.set(B); + size_t size_B = _path_info.subPathCounter(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; @@ -237,7 +238,8 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t counter = 0; size_t counter_added = 0; for (PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) { + path_it != B.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -259,11 +261,10 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV } } - _path_info.setPwd2(A); + _path_info.set(A); setPwd2(A); } -} // namespace Geom /* Local Variables: mode:c++ diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index e4b9f2b05e..787cdbfff3 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -8,8 +8,8 @@ * This code is in public domain */ -#ifndef SEEN_GEOM_POINTWISE_H -#define SEEN_GEOM_POINTWISE_H +#ifndef SEEN_POINTWISE_H +#define SEEN_POINTWISE_H #include #include @@ -20,8 +20,6 @@ #include <2geom/path.h> #include -namespace Geom { - /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * @@ -35,25 +33,26 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ +using namespace Geom; class Pointwise { public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); Piecewise > getPwd2() const; - void setPwd2(Piecewise > pwd2_in); + void setPwd2(Piecewise > const pwd2_in); std::vector getSatellites() const; - void setSatellites(std::vector sats); + void setSatellites(std::vector const sats); void setStart(); - void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S); - void pwd2Sustract(Piecewise > A); - void pwd2Append(Piecewise > A, Satellite S); + void recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Sustract(Piecewise > const A); + void pwd2Append(Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); + void insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S); private: Piecewise > _pwd2; @@ -61,9 +60,7 @@ private: Pathinfo _path_info; }; -} // end namespace Geom - -#endif //SEEN_GEOM_POINTWISE_H +#endif //SEEN_POINTWISE_H /* Local Variables: mode:c++ diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h deleted file mode 100644 index d82cdabe02..0000000000 --- a/src/helper/geom-satellite-enum.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H -#define LIB2GEOM_SEEN_SATELLITE_ENUM_H - -/** - * \file - * \brief Satellite types enum - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#include "util/enums.h" - -namespace Geom { - -enum SatelliteType { - F = 0, //Fillet - IF, //Inverse Fillet - C, //Chamfer - IC, //Inverse Chamfer - KO // Invalid Satellite) -}; - -} //namespace Geom - -#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/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index efe6bb37ad..397a556a99 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -17,38 +17,32 @@ #include <2geom/ray.h> #include -namespace Geom { - /** * @brief Satellite a per ?node/curve holder of data. */ Satellite::Satellite() {} -; -Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, - bool hasMirror, bool hidden, double amount, double angle, - size_t steps) - : satelliteType(satelliteType), isTime(isTime), active(active), - hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), - steps(steps) {} -; + +Satellite::Satellite(SatelliteType satellite_type) + : satellite_type(satellite_type) +{} Satellite::~Satellite() {} -; /** * Calculate the time in d2_in with a size of A + * TODO: find a better place to it */ -double Satellite::toTime(double A, Geom::D2 d2_in) const +double timeAtArcLength(double A, Geom::D2 const d2_in) { if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double t = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - if (lenghtPart != 0) { - t = A / lenghtPart; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; } } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; @@ -65,16 +59,17 @@ double Satellite::toTime(double A, Geom::D2 d2_in) const /** * Calculate the size in d2_in with a point at A + * TODO: find a better place to it */ -double Satellite::toSize(double A, Geom::D2 d2_in) const +double arcLengthAt(double A, Geom::D2 const d2_in) { if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double s = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - s = (A * lenghtPart); + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); @@ -86,81 +81,79 @@ double Satellite::toSize(double A, Geom::D2 d2_in) const } /** - * Calculate the lenght of a satellite from a radious A input. + * Calculate the length of a satellite from a radious A input. + * convert a arc radius to a satellite length */ double Satellite::radToLen( - double A, boost::optional > d2_in, - Geom::D2 d2_out, - boost::optional previousSatellite) const + double A, Geom::D2 const d2_in, + Geom::D2 const d2_out, + Satellite const previousSatellite) const { double len = 0; - if (d2_in && previousSatellite) { - 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 = (*previousSatellite).toSize(p0pt, d2_out); - } else { - if (A > 0) { - len = radToLen(A * -1, *d2_in, d2_out, previousSatellite); - } + 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 = arcLengthAt(p0pt, d2_out); + } else { + if (A > 0) { + len = radToLen(A * -1, d2_in, d2_out, previousSatellite); } } return len; } /** -* Calculate the radious of a satellite from a lenght A input. +* Calculate the radious of a satellite from a length A input. +* convert a satellite length to a arc radius */ double Satellite::lenToRad( - double A, boost::optional > d2_in, - Geom::D2 d2_out, - boost::optional previousSatellite) const + double A, Geom::D2 const d2_in, + Geom::D2 const d2_out, + Satellite const previousSatellite) const { - if (d2_in && previousSatellite) { - double time_in = (*previousSatellite).time(A, true, *d2_in); - double time_out = (*previousSatellite).toTime(A, d2_out); - Geom::Point startArcPoint = (*d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Piecewise > u; - u.push_cut(0); - u.push(*d2_in, 1); - Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Piecewise > u2; - u2.push_cut(0); - u2.push(d2_out, 1); - Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Curve *knotCurve1 = C->portion(0, time_in); - Curve *knotCurve2 = D->portion(time_out, 1); - Geom::CubicBezier const *cubic1 = - dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (*d2_in).valueAt(1)); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(d2_out.valueAt(0), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - 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); - double divisor = std::sin(angleBetween / 2.0); - if (divisor > 0) { - return distanceArc / divisor; - } + double time_in = (previousSatellite).time(A, true, d2_in); + double time_out = timeAtArcLength(A, d2_out); + Geom::Point startArcPoint = (d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Piecewise > u2; + u2.push_cut(0); + u2.push(d2_out, 1); + Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Curve *knotCurve1 = C->portion(0, time_in); + Curve *knotCurve2 = D->portion(time_out, 1); + Geom::CubicBezier const *cubic1 = + dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, (d2_in).valueAt(1)); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); + Ray ray2(d2_out.valueAt(0), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + 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); + double divisor = std::sin(angleBetween / 2.0); + if (divisor > 0) { + return distanceArc / divisor; } return 0; } @@ -171,8 +164,8 @@ double Satellite::lenToRad( double Satellite::time(Geom::D2 d2_in) const { double t = amount; - if (!isTime) { - t = toTime(t, d2_in); + if (!is_time) { + t = timeAtArcLength(t, d2_in); } if (t > 1) { t = 1; @@ -181,7 +174,7 @@ double Satellite::time(Geom::D2 d2_in) const } /**. - * Get the time from a lenght A in other curve, a bolean I gived to reverse time + * Get the time from a length A in other curve, a bolean I gived to reverse time */ double Satellite::time(double A, bool I, Geom::D2 d2_in) const @@ -193,21 +186,21 @@ double Satellite::time(double A, bool I, return 0; } if (!I) { - return toTime(A, d2_in); + return timeAtArcLength(A, d2_in); } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - A = lenghtPart - A; - return toTime(A, d2_in); + double length_part = Geom::length(d2_in, Geom::EPSILON); + A = length_part - A; + return timeAtArcLength(A, d2_in); } /** - * Get the lenght of the satellite in d2_in + * Get the length of the satellite in d2_in */ -double Satellite::size(Geom::D2 d2_in) const +double Satellite::arcDistance(Geom::D2 d2_in) const { double s = amount; - if (isTime) { - s = toSize(s, d2_in); + if (is_time) { + s = arcLengthAt(s, d2_in); } return s; } @@ -227,8 +220,8 @@ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { double A = Geom::nearest_point(p, d2_in); - if (!isTime) { - A = toSize(A, d2_in); + if (!is_time) { + A = arcLengthAt(A, d2_in); } amount = A; } @@ -238,9 +231,13 @@ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) */ void Satellite::setSatelliteType(gchar const *A) { - std::map GcharMapToSatelliteType = - boost::assign::map_list_of("F", F)("IF", IF)("C", C)("IC", IC)("KO", KO); - satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; + 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(A)); + if(it != gchar_map_to_satellite_type.end()) + { + satellite_type = it->second; + } } /** @@ -248,13 +245,11 @@ void Satellite::setSatelliteType(gchar const *A) */ gchar const *Satellite::getSatelliteTypeGchar() const { - std::map SatelliteTypeToGcharMap = - boost::assign::map_list_of(F, "F")(IF, "IF")(C, "C")(IC, "IC")(KO, "KO"); - return SatelliteTypeToGcharMap.at(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"); + return satellite_type_to_gchar_map.at(satellite_type); } -} //namespace Geom - /* Local Variables: mode:c++ diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index df54819fdc..263cefa682 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -8,61 +8,67 @@ * This code is in public domain */ -#ifndef LIB2GEOM_SEEN_SATELLITE_H -#define LIB2GEOM_SEEN_SATELLITE_H +#ifndef SEEN_SATELLITE_H +#define SEEN_SATELLITE_H -#include #include <2geom/d2.h> #include #include +#include "util/enums.h" -namespace Geom { +enum SatelliteType { + FILLET = 0, //Fillet + INVERSE_FILLET, //Inverse Fillet + CHAMFER, //Chamfer + INVERSE_CHAMFER, //Inverse Chamfer + INVALID_SATELLITE // Invalid Satellite) +}; /** * @brief Satellite a per ?node/curve holder of data. */ +using namespace Geom; class Satellite { public: Satellite(); - Satellite(SatelliteType satelliteType, bool isTime, bool active, - bool hasMirror, bool hidden, double amount, double angle, - size_t steps); + Satellite(SatelliteType satellite_type); virtual ~Satellite(); - - double toSize(double A, Geom::D2 d2_in) const; - double toTime(double A, Geom::D2 d2_in) const; - double lenToRad(double A, boost::optional > d2_in, + void setIsTime(bool set_is_time){is_time = set_is_time;} + void setActive(bool set_active){active = set_active;} + void setHasMirror(bool set_has_mirror){has_mirror = set_has_mirror;} + void setHidden(bool set_hidden){hidden = set_hidden;} + void setAmount(bool set_amount){amount = set_amount;} + void setAngle(bool set_angle){angle = set_angle;} + void setSteps(bool set_steps){steps = set_steps;} + double lenToRad(double A, Geom::D2 d2_in, Geom::D2 d2_out, - boost::optional previousSatellite) const; - double radToLen(double A, boost::optional > d2_in, + Satellite previousSatellite) const; + double radToLen(double A, Geom::D2 d2_in, Geom::D2 d2_out, - boost::optional previousSatellite) const; + Satellite previousSatellite) const; double time(Geom::D2 d2_in) const; double time(double A, bool I, Geom::D2 d2_in) const; - double size(Geom::D2 d2_in) const; + double arcDistance(Geom::D2 d2_in) const; void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 d2_in) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; - //TODO: maybe make after variables protected? - SatelliteType satelliteType; - bool isTime; + SatelliteType satellite_type; + bool is_time; bool active; - bool hasMirror; + bool has_mirror; bool hidden; double amount; double angle; size_t steps; }; -} // end namespace Geom - -#endif // LIB2GEOM_SEEN_SATELLITE_H +#endif // SEEN_SATELLITE_H /* Local Variables: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1b7f232ed9..d26f475416 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 9ec5b5e04a..48056924a0 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 c8ee63fec3..c71b8ed55f 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 25e4793041..66ed6344b8 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 b0b0369624..5a3b64dd3d 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 2845e39692..cc09e7589a 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 -- GitLab From 6195a5fd157ff2681534aa90a279627e0048d4e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 00:37:31 +0200 Subject: [PATCH 057/121] fixing review (bzr r13645.1.87) --- src/helper/geom-satellite.cpp | 50 ----------------- src/helper/geom-satellite.h | 54 ++++++++++++++++++- src/live_effects/lpe-fillet-chamfer.cpp | 43 +++++++++------ src/live_effects/parameter/satellitearray.cpp | 22 +++----- .../dialog/lpe-fillet-chamfer-properties.cpp | 4 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 6 +-- 6 files changed, 92 insertions(+), 87 deletions(-) diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 397a556a99..51cff7d79c 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -11,7 +11,6 @@ #include #include <2geom/curve.h> #include <2geom/nearest-point.h> -#include <2geom/sbasis-geometric.h> #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> @@ -29,56 +28,7 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} -/** - * Calculate the time in d2_in with a size of A - * TODO: find a better place to it - */ -double timeAtArcLength(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - if (length_part != 0) { - t = A / length_part; - } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } - return t; -} - -/** - * Calculate the size in d2_in with a point at A - * TODO: find a better place to it - */ -double arcLengthAt(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); - } - return s; -} /** * Calculate the length of a satellite from a radious A input. diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 263cefa682..a4b1b23b92 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -14,6 +14,7 @@ #include <2geom/d2.h> #include #include +#include <2geom/sbasis-geometric.h> #include "util/enums.h" @@ -22,7 +23,7 @@ enum SatelliteType { INVERSE_FILLET, //Inverse Fillet CHAMFER, //Chamfer INVERSE_CHAMFER, //Inverse Chamfer - INVALID_SATELLITE // Invalid Satellite) + INVALID_SATELLITE // Invalid Satellite }; /** * @brief Satellite a per ?node/curve holder of data. @@ -68,6 +69,57 @@ public: size_t steps; }; +/** + * Calculate the time in d2_in with a size of A + * TODO: find a better place to it + */ +double timeAtArcLength(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double t = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + + return t; +} + +/** + * Calculate the size in d2_in with a point at A + * TODO: find a better place to it + */ +double arcLengthAt(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double s = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} + #endif // SEEN_SATELLITE_H /* diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d26f475416..8d457c90b3 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 5a3b64dd3d..5a90d19303 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; } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index bc6557b197..2b49d19528 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -123,7 +123,7 @@ void FilletChamferPropertiesDialog::showDialog( FilletChamferKnotHolderEntity *pt, bool _use_distance, bool _aprox_radius, - Geom::Satellite _satellite) + Satellite _satellite) { FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); @@ -200,7 +200,7 @@ void FilletChamferPropertiesDialog::_handleButtonEvent(GdkEventButton *event) } } -void FilletChamferPropertiesDialog::_setSatellite(Geom::Satellite satellite) +void FilletChamferPropertiesDialog::_setSatellite(Satellite satellite) { double position; std::string distance_or_radius = std::string(_("Radius")); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index 53bb90b80d..f982db2861 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -33,7 +33,7 @@ public: FilletChamferKnotHolderEntity *pt, bool _use_distance, bool _aprox_radius, - Geom::Satellite _satellite); + Satellite _satellite); protected: @@ -71,7 +71,7 @@ protected: void _setUseDistance(bool use_knot_distance); void _setAprox(bool aprox_radius); void _setAmount(double amount); - void _setSatellite(Geom::Satellite satellite); + void _setSatellite(Satellite satellite); void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); bool _handleKeyEvent(GdkEventKey *event); @@ -80,7 +80,7 @@ protected: void _apply(); void _close(); bool _flexible; - Geom::Satellite _satellite; + Satellite _satellite; bool _use_distance; double _amount; bool _aprox; -- GitLab From 870dbb0348163f55263eb9dca601d525d53a8d79 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 13:40:31 +0200 Subject: [PATCH 058/121] Working on Krzysztof review. Seems to be all fixed. TODO: double check review and comment (bzr r13645.1.89) --- src/helper/Makefile_insert | 1 - src/helper/geom-pathinfo.cpp | 20 ++- src/helper/geom-pathinfo.h | 12 +- src/helper/geom-pointwise.cpp | 34 ++-- src/helper/geom-pointwise.h | 20 +-- src/helper/geom-satellite.cpp | 71 ++++++-- src/helper/geom-satellite.h | 55 +------ 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 +++++----- .../dialog/lpe-fillet-chamfer-properties.cpp | 18 +- 13 files changed, 249 insertions(+), 245 deletions(-) diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 1d051734e1..919234b470 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -20,7 +20,6 @@ ink_common_sources += \ helper/geom-pointwise.h \ helper/geom-satellite.cpp \ helper/geom-satellite.h \ - helper/geom-satellite-enum.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ helper/mathfns.h \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 9e5e409c32..5ffd1d31ed 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store the _data of a pathvector and allow get info about it + * \brief Pathinfo store the _data of a Geom::PathVector and allow get info about it */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -12,10 +12,10 @@ #include <2geom/sbasis-to-bezier.h> /** - * @brief Pathinfo store the _data of a pathvector and allow get info about it + * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) +Pathinfo::Pathinfo(Geom::Piecewise > pwd2) { set(pwd2); } @@ -29,7 +29,7 @@ Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) Pathinfo::~Pathinfo() {} -void Pathinfo::set(Piecewise > pwd2) +void Pathinfo::set(Geom::Piecewise > pwd2) { set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } @@ -39,7 +39,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) { _data.clear(); size_t counter = 0; - for (PathVector::const_iterator path_it = path_vector.begin(); + for (Geom::PathVector::const_iterator path_it = path_vector.begin(); path_it != path_vector.end(); ++path_it) { if (path_it->empty()) { @@ -48,7 +48,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) 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(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } @@ -69,7 +69,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) } } -size_t Pathinfo::subPathCounter() const +size_t Pathinfo::size() const { return _data.back().first + 1; } @@ -78,7 +78,11 @@ size_t Pathinfo::subPathSize(size_t index) const { size_t size = 0; if( _data.size() > index){ - size = _data[index].first + 1; + double prev = 0; + if(index != 0){ + prev = _data[index - 1].first; + } + size = prev - _data[index].first + 1; } return size; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index ae05f5b89e..8a6c51e51e 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store data of a pathvector and allow get info about it + * \brief Pathinfo store data of a Geom::PathVector and allow get info about it * \ */ /* * Authors: @@ -16,19 +16,19 @@ #include /** - * @brief Pathinfo store the data of a pathvector and allow get info about it + * @brief Pathinfo store the data of a Geom::PathVector and allow get info about it * */ -using namespace Geom; + class Pathinfo { public: - Pathinfo(Piecewise > pwd2); + Pathinfo(Geom::Piecewise > pwd2); Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); - void set(Piecewise > pwd2); + void set(Geom::Piecewise > pwd2); void set(Geom::PathVector path_vector, bool skip_degenerate = false); std::vector > get(){return _data;}; - size_t subPathCounter() const; + size_t size() const; size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index bd03f1d895..3041c60ea6 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -23,7 +23,7 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Piecewise > pwd2, +Pointwise::Pointwise(Geom::Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) { @@ -34,17 +34,23 @@ Pointwise::Pointwise(Piecewise > pwd2, Pointwise::~Pointwise() {} -Piecewise > Pointwise::getPwd2() const +Geom::Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Piecewise > const pwd2_in) +void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) { _pwd2 = pwd2_in; _path_info.set(_pwd2); } +void Pointwise::setPathInfo(Geom::PathVector const pv) +{ + _path_info.set(pv); + setStart(); +} + std::vector Pointwise::getSatellites() const { return _satellites; @@ -76,7 +82,7 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); @@ -89,11 +95,11 @@ void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::Path /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Piecewise > const A) +void Pointwise::pwd2Sustract(Geom::Piecewise > const A) { size_t counter = 0; std::vector sats; - Piecewise > pwd2 = _pwd2; + Geom::Piecewise > pwd2 = _pwd2; setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || @@ -109,7 +115,7 @@ void Pointwise::pwd2Sustract(Piecewise > const A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > const A, Satellite const S) +void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) { size_t counter = 0; std::vector sats; @@ -161,7 +167,7 @@ void Pointwise::subpathToBack(size_t subpath) size_t counter = 0; std::vector tmp_path; Geom::Path to_back; - for (PathVector::const_iterator path_it = path_in.begin(); + for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()) { @@ -169,7 +175,7 @@ void Pointwise::subpathToBack(size_t subpath) } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } @@ -207,7 +213,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) size_t subpath = _path_info.subPathIndex(start); std::vector tmp_path; Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); + for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()) { @@ -226,18 +232,18 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { size_t size_A = A.size(); _path_info.set(B); - size_t size_B = _path_info.subPathCounter(); + size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; } size_t counter = 0; size_t counter_added = 0; - for (PathVector::const_iterator path_it = B.begin(); + for (Geom::PathVector::const_iterator path_it = B.begin(); path_it != B.end(); ++path_it) { if (path_it->empty()) { @@ -246,7 +252,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom: 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(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 787cdbfff3..b1f2235c64 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,29 +33,29 @@ * optional satellites, and remove the active variable in satellites. * */ -using namespace Geom; + class Pointwise { public: - Pointwise(Piecewise > pwd2, std::vector satellites); + Pointwise(Geom::Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); - Piecewise > getPwd2() const; - void setPwd2(Piecewise > const pwd2_in); + Geom::Piecewise > getPwd2() const; + void setPwd2(Geom::Piecewise > const pwd2_in); std::vector getSatellites() const; void setSatellites(std::vector const sats); - + void setPathInfo(Geom::PathVector const pv); void setStart(); - void recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Sustract(Piecewise > const A); - void pwd2Append(Piecewise > const A, Satellite const S); + void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Sustract(Geom::Piecewise > const A); + void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S); + void insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); private: - Piecewise > _pwd2; + Geom::Piecewise > _pwd2; std::vector _satellites; Pathinfo _path_info; }; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 51cff7d79c..c2d4ef7156 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -28,7 +28,56 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} +/** + * Calculate the time in d2_in with a size of A + * TODO: find a better place to it + */ +double timeAtArcLength(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double t = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + return t; +} + +/** + * Calculate the size in d2_in with a point at A + * TODO: find a better place to it + */ +double arcLengthAt(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double s = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} /** * Calculate the length of a satellite from a radious A input. @@ -40,17 +89,17 @@ double Satellite::radToLen( Satellite const previousSatellite) const { double len = 0; - Piecewise > offset_curve0 = - Piecewise >(d2_in) + + Geom::Piecewise > offset_curve0 = + Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); - Piecewise > offset_curve1 = - Piecewise >(d2_out) + + Geom::Piecewise > offset_curve1 = + Geom::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); + Geom::Point cp = p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); len = arcLengthAt(p0pt, d2_out); } else { @@ -74,25 +123,25 @@ double Satellite::lenToRad( double time_out = timeAtArcLength(A, d2_out); Geom::Point startArcPoint = (d2_in).valueAt(time_in); Geom::Point endArcPoint = d2_out.valueAt(time_out); - Piecewise > u; + Geom::Piecewise > u; u.push_cut(0); u.push(d2_in, 1); Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Piecewise > u2; + Geom::Piecewise > u2; u2.push_cut(0); u2.push(d2_out, 1); Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Curve *knotCurve1 = C->portion(0, time_in); - Curve *knotCurve2 = D->portion(time_out, 1); + Geom::Curve *knotCurve1 = C->portion(0, time_in); + Geom::Curve *knotCurve2 = D->portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (d2_in).valueAt(1)); + Geom::Ray ray1(startArcPoint, (d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(d2_out.valueAt(0), endArcPoint); + Geom::Ray ray2(d2_out.valueAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index a4b1b23b92..722adbef4f 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -28,7 +28,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ -using namespace Geom; + class Satellite { public: @@ -68,57 +68,8 @@ public: double angle; size_t steps; }; - -/** - * Calculate the time in d2_in with a size of A - * TODO: find a better place to it - */ -double timeAtArcLength(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - if (length_part != 0) { - t = A / length_part; - } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } - - return t; -} - -/** - * Calculate the size in d2_in with a point at A - * TODO: find a better place to it - */ -double arcLengthAt(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); - } - return s; -} +double timeAtArcLength(double A, Geom::D2 const d2_in); +double arcLengthAt(double A, Geom::D2 const d2_in); #endif // SEEN_SATELLITE_H diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index e06afef2f7..a5bb1741ca 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 8d457c90b3..16bef6a998 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 48056924a0..bab278cf52 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 c71b8ed55f..9b326fe32a 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 5a90d19303..7df849c240 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) { diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 2b49d19528..f89668a4c1 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -151,13 +151,13 @@ void FilletChamferPropertiesDialog::_apply() double d_pos = _fillet_chamfer_position_numeric.get_value(); if (d_pos >= 0) { if (_fillet_chamfer_type_fillet.get_active() == true) { - _satellite.satelliteType = Geom::F; + _satellite.satellite_type = FILLET; } else if (_fillet_chamfer_type_inverse_fillet.get_active() == true) { - _satellite.satelliteType = Geom::IF; + _satellite.satellite_type = INVERSE_FILLET; } else if (_fillet_chamfer_type_inverse_chamfer.get_active() == true) { - _satellite.satelliteType = Geom::IC; + _satellite.satellite_type = INVERSE_CHAMFER; } else { - _satellite.satelliteType = Geom::C; + _satellite.satellite_type = CHAMFER; } if (_flexible) { if (d_pos > 99.99999 || d_pos < 0) { @@ -210,7 +210,7 @@ void FilletChamferPropertiesDialog::_setSatellite(Satellite satellite) if(_use_distance) { distance_or_radius = std::string(_("Knot distance")); } - if (satellite.isTime) { + if (satellite.is_time) { position = _amount * 100; _flexible = true; _fillet_chamfer_position_label.set_label(_("Position (%):")); @@ -222,13 +222,13 @@ void FilletChamferPropertiesDialog::_setSatellite(Satellite satellite) } _fillet_chamfer_position_numeric.set_value(position); _fillet_chamfer_chamfer_subdivisions.set_value(satellite.steps); - if (satellite.satelliteType == Geom::F) { + if (satellite.satellite_type == FILLET) { _fillet_chamfer_type_fillet.set_active(true); - } else if (satellite.satelliteType == Geom::IF) { + } else if (satellite.satellite_type == INVERSE_FILLET) { _fillet_chamfer_type_inverse_fillet.set_active(true); - } else if (satellite.satelliteType == Geom::C) { + } else if (satellite.satellite_type == CHAMFER) { _fillet_chamfer_type_chamfer.set_active(true); - } else if (satellite.satelliteType == Geom::IC) { + } else if (satellite.satellite_type == INVERSE_CHAMFER) { _fillet_chamfer_type_inverse_chamfer.set_active(true); } _satellite = satellite; -- GitLab From 63b289b4a3341f435e49dde40503636ba7b01b6a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 21:27:46 +0200 Subject: [PATCH 059/121] Added some comments (bzr r13645.1.90) --- src/helper/geom-pathinfo.cpp | 30 ++++++++++++++++++++++++------ src/helper/geom-pathinfo.h | 4 ++-- src/helper/geom-pointwise.h | 2 +- src/helper/geom-satellite.cpp | 6 ++---- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 5ffd1d31ed..d37b8b6da7 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,8 @@ /** * \file - * \brief Pathinfo store the _data of a Geom::PathVector and allow get info about it + * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. + * \Usualy need a curve index to get the results + * \TODO: migrate more Inkscape loops to use it. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -69,24 +71,30 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) } } +/** Size of pathvector + */ size_t Pathinfo::size() const { return _data.back().first + 1; } -size_t Pathinfo::subPathSize(size_t index) const +/** Size of subpath + */ +size_t Pathinfo::subPathSize(size_t subpath_index) const { size_t size = 0; - if( _data.size() > index){ + if( _data.size() > subpath_index){ double prev = 0; - if(index != 0){ - prev = _data[index - 1].first; + if(subpath_index != 0){ + prev = _data[subpath_index - 1].first; } - size = prev - _data[index].first + 1; + size = prev - _data[subpath_index].first + 1; } return size; } +/** Get subpath index from a curve index + */ size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -97,6 +105,8 @@ size_t Pathinfo::subPathIndex(size_t index) const return 0; } +/** Get subpath last index given a curve index + */ size_t Pathinfo::last(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -107,6 +117,8 @@ size_t Pathinfo::last(size_t index) const return 0; } +/** Get subpath first index given a curve index + */ size_t Pathinfo::first(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -121,6 +133,8 @@ size_t Pathinfo::first(size_t index) const return 0; } +/** Get previous index given a curve index + */ boost::optional Pathinfo::previous(size_t index) const { if (first(index) == index && closed(index)) { @@ -132,6 +146,8 @@ boost::optional Pathinfo::previous(size_t index) const return index - 1; } +/** Get next index given a curve index + */ boost::optional Pathinfo::next(size_t index) const { if (last(index) == index && closed(index)) { @@ -143,6 +159,8 @@ boost::optional Pathinfo::next(size_t index) const return index + 1; } +/** Get if subpath is closed given a curve index + */ bool Pathinfo::closed(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 8a6c51e51e..cd3a3b2b87 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store data of a Geom::PathVector and allow get info about it + * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. * \ */ /* * Authors: @@ -29,7 +29,7 @@ public: void set(Geom::PathVector path_vector, bool skip_degenerate = false); std::vector > get(){return _data;}; size_t size() const; - size_t subPathSize(size_t index) const; + size_t subPathSize(size_t subpath_index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index b1f2235c64..3cb4ff1366 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites, once per piecewise curve */ /* * Authors: * 2015 Jabier Arraiza Cenoz diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index c2d4ef7156..d038398759 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -80,8 +80,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) } /** - * Calculate the length of a satellite from a radious A input. - * convert a arc radius to a satellite length + * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamferknot be on original curve */ double Satellite::radToLen( double A, Geom::D2 const d2_in, @@ -111,8 +110,7 @@ double Satellite::radToLen( } /** -* Calculate the radious of a satellite from a length A input. -* convert a satellite length to a arc radius +* Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer */ double Satellite::lenToRad( double A, Geom::D2 const d2_in, -- GitLab From c7925bda67f038dd5054329c43936658ca2cae76 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 22:36:27 +0200 Subject: [PATCH 060/121] some comments and pointwise related refactor (bzr r13645.1.91) --- src/helper/geom-pathinfo.cpp | 11 +------- src/helper/geom-pathinfo.h | 3 +-- src/helper/geom-pointwise.cpp | 23 ++++++++-------- src/helper/geom-pointwise.h | 14 +++++++--- src/helper/geom-satellite.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 25 +++++++++++------ src/live_effects/parameter/satellitearray.cpp | 27 +++++++++++-------- 7 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index d37b8b6da7..d73f8f707f 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -17,16 +17,7 @@ * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it * */ -Pathinfo::Pathinfo(Geom::Piecewise > pwd2) -{ - set(pwd2); -} - -Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) -{ - set(path_vector, skip_degenerate); -} - +Pathinfo::Pathinfo() {} Pathinfo::~Pathinfo() {} diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index cd3a3b2b87..41753c68ff 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -22,8 +22,7 @@ class Pathinfo { public: - Pathinfo(Geom::Piecewise > pwd2); - Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); + Pathinfo(); virtual ~Pathinfo(); void set(Geom::Piecewise > pwd2); void set(Geom::PathVector path_vector, bool skip_degenerate = false); diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 3041c60ea6..5f6c0d29e4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -3,8 +3,14 @@ * \brief Pointwise a class to manage a vector of satellites per piecewise curve */ /* * Authors: - * 2015 Jabier Arraiza Cenoz - * + * Jabiertxof + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Nathan Hurst + * Krzysztof Kosiński * This code is in public domain */ @@ -23,12 +29,7 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Geom::Piecewise > pwd2, - std::vector satellites) - : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) -{ - setStart(); -} +Pointwise::Pointwise() {} Pointwise::~Pointwise() {} @@ -48,7 +49,6 @@ void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) void Pointwise::setPathInfo(Geom::PathVector const pv) { _path_info.set(pv); - setStart(); } std::vector Pointwise::getSatellites() const @@ -59,10 +59,9 @@ std::vector Pointwise::getSatellites() const void Pointwise::setSatellites(std::vector const sats) { _satellites = sats; - setStart(); } -/** Update the start satellite on ope/closed paths. +/** Update the start satellite on open/closed paths. */ void Pointwise::setStart() { @@ -137,7 +136,6 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back - //TODO: change subpathToBack to subpath move for the case of multiple subpath reverse subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; @@ -145,6 +143,7 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat } if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + //reverse subpath subpathReverse(first, last); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 3cb4ff1366..d83b54b79f 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,10 +1,16 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites, once per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise curve */ /* * Authors: - * 2015 Jabier Arraiza Cenoz - * + * Jabiertxof + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Nathan Hurst + * Krzysztof Kosiński * This code is in public domain */ @@ -36,7 +42,7 @@ class Pointwise { public: - Pointwise(Geom::Piecewise > pwd2, std::vector satellites); + Pointwise(); virtual ~Pointwise(); Geom::Piecewise > getPwd2() const; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index d038398759..cd3f65f68e 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -80,7 +80,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) } /** - * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamferknot be on original curve + * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve */ double Satellite::radToLen( double A, Geom::D2 const d2_in, diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 16bef6a998..3e7c1d0e1f 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 7df849c240..4eefea0b06 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 { -- GitLab From d11134922137f029c42919ed3298924135bec386 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 11 May 2015 00:24:25 +0200 Subject: [PATCH 061/121] fix a minor bug calculating max time (bzr r13645.1.92) --- src/helper/geom-satellite.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index cd3f65f68e..eed9706cf1 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -39,7 +39,7 @@ double timeAtArcLength(double A, Geom::D2 const d2_in) } double t = 0; double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (A >= length_part || d2_in[0].degreesOfFreedom() == 2) { if (length_part != 0) { t = A / length_part; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3e7c1d0e1f..cc21d99ccf 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) { -- GitLab From d6710f8318ba6f95e9dd5ad96d341acc41b14a4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 25 Jun 2015 19:54:53 +0200 Subject: [PATCH 062/121] attemp to handle reverse path (bzr r13645.1.95) --- src/helper/geom-pointwise.cpp | 14 +++++++++++++- src/helper/geom-pointwise.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e4..dc95ffda4b 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -83,7 +83,11 @@ void Pointwise::setStart() */ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { - if (_pwd2.size() > A.size()) { + Geom::PathVector const reversed = path_from_piecewise(remove_short_cuts(reverse(_pwd2), 0.1), 0.001); + Geom::PathVector const original = path_from_piecewise(remove_short_cuts(reverse(A), 0.1), 0.001); + if (reversed == original) { + pwd2Reverse(A); + } else if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); @@ -112,6 +116,14 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) setSatellites(sats); } +/** Reverse a path + */ +void Pointwise::pwd2Reverse(Geom::Piecewise > const A){ + std::reverse(_satellites.begin(), _satellites.end()); + setPwd2(A); + setSatellites(_satellites); +} + /** Append nodes/subpaths to current pointwise */ void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index d83b54b79f..79504ecffd 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -54,6 +54,7 @@ public: void setStart(); void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Reverse(Geom::Piecewise > const A); void pwd2Sustract(Geom::Piecewise > const A); void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); -- GitLab From a5d2901e1f17879bc65e23b3ff26f8c304658ce4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 Jun 2015 17:58:32 +0200 Subject: [PATCH 063/121] removed reverse path, commented why (bzr r13645.1.97) --- src/helper/geom-pointwise.cpp | 14 +------------- src/helper/geom-pointwise.h | 1 - src/live_effects/lpe-fillet-chamfer.cpp | 3 +++ 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index dc95ffda4b..5f6c0d29e4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -83,11 +83,7 @@ void Pointwise::setStart() */ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { - Geom::PathVector const reversed = path_from_piecewise(remove_short_cuts(reverse(_pwd2), 0.1), 0.001); - Geom::PathVector const original = path_from_piecewise(remove_short_cuts(reverse(A), 0.1), 0.001); - if (reversed == original) { - pwd2Reverse(A); - } else if (_pwd2.size() > A.size()) { + if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); @@ -116,14 +112,6 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) setSatellites(sats); } -/** Reverse a path - */ -void Pointwise::pwd2Reverse(Geom::Piecewise > const A){ - std::reverse(_satellites.begin(), _satellites.end()); - setPwd2(A); - setSatellites(_satellites); -} - /** Append nodes/subpaths to current pointwise */ void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 79504ecffd..d83b54b79f 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -54,7 +54,6 @@ public: void setStart(); void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Reverse(Geom::Piecewise > const A); void pwd2Sustract(Geom::Piecewise > const A); void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index cc21d99ccf..eaf1c6a08f 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); -- GitLab From 57b065b5ffb5a871b5efac52f03cb95355bfa119 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 02:57:00 +0200 Subject: [PATCH 064/121] fix to compile on Krzysztof merge previous to fix the improvements in the merge request (bzr r13645.1.100) --- src/helper/geom-pointwise.cpp | 10 +- src/helper/geom-satellite.cpp | 11 +- src/helper/geom-satellite.h | 3 +- src/live_effects/lpe-fillet-chamfer.cpp | 347 +++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 79 ++-- src/live_effects/parameter/satellitearray.cpp | 14 +- 6 files changed, 235 insertions(+), 229 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e4..6910207bff 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -160,11 +160,11 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat void Pointwise::subpathToBack(size_t subpath) { - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t subpath_counter = 0; size_t counter = 0; - std::vector tmp_path; + Geom::PathVector tmp_path; Geom::Path to_back; for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) @@ -205,12 +205,12 @@ void Pointwise::subpathReverse(size_t start, size_t end) _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); _satellites.erase(_satellites.begin() + i); } - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; size_t subpath_counter = 0; size_t subpath = _path_info.subPathIndex(start); - std::vector tmp_path; + Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) @@ -220,7 +220,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) } counter++; if (subpath_counter == subpath) { - tmp_path.push_back(path_it->reverse()); + tmp_path.push_back(path_it->reversed()); } else { tmp_path.push_back(*path_it); } diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index eed9706cf1..f5f28544d9 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -10,7 +10,7 @@ #include #include <2geom/curve.h> -#include <2geom/nearest-point.h> +#include <2geom/nearest-time.h> #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> @@ -84,8 +84,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) */ double Satellite::radToLen( double A, Geom::D2 const d2_in, - Geom::D2 const d2_out, - Satellite const previousSatellite) const + Geom::D2 const d2_out) const { double len = 0; Geom::Piecewise > offset_curve0 = @@ -99,11 +98,11 @@ double Satellite::radToLen( Geom::Crossings cs = Geom::crossings(p0, p1); if (cs.size() > 0) { Geom::Point cp = p0(cs[0].ta); - double p0pt = nearest_point(cp, d2_out); + double p0pt = nearest_time(cp, d2_out); len = arcLengthAt(p0pt, d2_out); } else { if (A > 0) { - len = radToLen(A * -1, d2_in, d2_out, previousSatellite); + len = radToLen(A * -1, d2_in, d2_out); } } return len; @@ -216,7 +215,7 @@ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const */ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { - double A = Geom::nearest_point(p, d2_in); + double A = Geom::nearest_time(p, d2_in); if (!is_time) { A = arcLengthAt(A, d2_in); } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 722adbef4f..42c5687bdc 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -47,8 +47,7 @@ public: Geom::D2 d2_out, Satellite previousSatellite) const; double radToLen(double A, Geom::D2 d2_in, - Geom::D2 d2_out, - Satellite previousSatellite) const; + Geom::D2 d2_out) const; double time(Geom::D2 d2_in) const; double time(double A, bool I, Geom::D2 d2_in) const; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a0aada0907..b617c929ea 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 ed76eb0e64..d7549d0708 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 4eefea0b06..46c7396d00 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; } -- GitLab From ebcbadbe16fe20e54a5daf9c5e6954521113d9cc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 03:14:24 +0200 Subject: [PATCH 065/121] Fix a bug displaying arcs (bzr r13645.1.101) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b617c929ea..eb9f829186 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 { -- GitLab From 936f6512b26120b882a1c68e50968a15002f3af4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:01:17 +0200 Subject: [PATCH 066/121] Fixes from branch review (bzr r13645.1.102) --- src/helper/CMakeLists.txt | 4 + src/helper/Makefile_insert | 2 - src/helper/geom-pathinfo.cpp | 176 ------------------ src/helper/geom-pathinfo.h | 55 ------ src/helper/geom-pointwise.cpp | 124 +++++++----- src/helper/geom-pointwise.h | 24 +-- 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 - 11 files changed, 164 insertions(+), 363 deletions(-) delete mode 100644 src/helper/geom-pathinfo.cpp delete mode 100644 src/helper/geom-pathinfo.h diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index ff4760c247..aa99934b63 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -14,6 +14,8 @@ set(helper_SRC geom.cpp geom-nodetype.cpp geom-pathstroke.cpp + geom-pointwise.cpp + geom-satellite.cpp gnome-utils.cpp pixbuf-ops.cpp png-write.cpp @@ -32,6 +34,8 @@ set(helper_SRC geom-curves.h geom-nodetype.h geom-pathstroke.h + geom-pointwise.h + geom-satellite.h geom.h gnome-utils.h mathfns.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 919234b470..54588d0ce6 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -12,8 +12,6 @@ ink_common_sources += \ helper/geom-curves.h \ helper/geom-nodetype.cpp \ helper/geom-nodetype.h \ - helper/geom-pathinfo.cpp \ - helper/geom-pathinfo.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ helper/geom-pointwise.cpp \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp deleted file mode 100644 index d73f8f707f..0000000000 --- a/src/helper/geom-pathinfo.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * \file - * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. - * \Usualy need a curve index to get the results - * \TODO: migrate more Inkscape loops to use it. - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#include -#include <2geom/sbasis-to-bezier.h> - -/** - * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it - * - */ -Pathinfo::Pathinfo() {} - -Pathinfo::~Pathinfo() {} - - -void Pathinfo::set(Geom::Piecewise > pwd2) -{ - set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); -} -/** Store the base path _data - */ -void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) -{ - _data.clear(); - size_t counter = 0; - for (Geom::PathVector::const_iterator path_it = path_vector.begin(); - path_it != path_vector.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()) { - Geom::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - if(curve_it1->isDegenerate() && skip_degenerate ){ - ++curve_it1; - continue; - } - ++curve_it1; - counter++; - } - if (path_it->closed()) { - _data.push_back(std::make_pair(counter - 1, true)); - } else { - _data.push_back(std::make_pair(counter - 1, false)); - } - } -} - -/** Size of pathvector - */ -size_t Pathinfo::size() const -{ - return _data.back().first + 1; -} - -/** Size of subpath - */ -size_t Pathinfo::subPathSize(size_t subpath_index) const -{ - size_t size = 0; - if( _data.size() > subpath_index){ - double prev = 0; - if(subpath_index != 0){ - prev = _data[subpath_index - 1].first; - } - size = prev - _data[subpath_index].first + 1; - } - return size; -} - -/** Get subpath index from a curve index - */ -size_t Pathinfo::subPathIndex(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return i; - } - } - return 0; -} - -/** Get subpath last index given a curve index - */ -size_t Pathinfo::last(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return _data[i].first; - } - } - return 0; -} - -/** Get subpath first index given a curve index - */ -size_t Pathinfo::first(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - if (i == 0) { - return 0; - } else { - return _data[i - 1].first + 1; - } - } - } - return 0; -} - -/** Get previous index given a curve index - */ -boost::optional Pathinfo::previous(size_t index) const -{ - if (first(index) == index && closed(index)) { - return last(index); - } - if (first(index) == index && !closed(index)) { - return boost::none; - } - return index - 1; -} - -/** Get next index given a curve index - */ -boost::optional Pathinfo::next(size_t index) const -{ - if (last(index) == index && closed(index)) { - return first(index); - } - if (last(index) == index && !closed(index)) { - return boost::none; - } - return index + 1; -} - -/** Get if subpath is closed given a curve index - */ -bool Pathinfo::closed(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return _data[i].second; - } - } - return false; -} - -/* - 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:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h deleted file mode 100644 index 41753c68ff..0000000000 --- a/src/helper/geom-pathinfo.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. - * \ - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#ifndef SEEN_PATHINFO_H -#define SEEN_PATHINFO_H - -#include <2geom/path.h> -#include - -/** - * @brief Pathinfo store the data of a Geom::PathVector and allow get info about it - * - */ - -class Pathinfo { -public: - Pathinfo(); - virtual ~Pathinfo(); - void set(Geom::Piecewise > pwd2); - void set(Geom::PathVector path_vector, bool skip_degenerate = false); - std::vector > get(){return _data;}; - size_t size() const; - size_t subPathSize(size_t subpath_index) const; - size_t subPathIndex(size_t index) const; - size_t last(size_t index) const; - size_t first(size_t index) const; - boost::optional previous(size_t index) const; - boost::optional next(size_t index) const; - bool closed(size_t index) const; - -private: - std::vector > _data; -}; - -#endif //SEEN_PATHINFO_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:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6910207bff..7627b5dc33 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -29,26 +29,15 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise() {} - -Pointwise::~Pointwise() {} - - -Geom::Piecewise > Pointwise::getPwd2() const +pwd2sb Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) +void Pointwise::setPwd2(pwd2sb const &pwd2_in) { _pwd2 = pwd2_in; - _path_info.set(_pwd2); -} - -void Pointwise::setPathInfo(Geom::PathVector const pv) -{ - _path_info.set(pv); } std::vector Pointwise::getSatellites() const @@ -56,7 +45,7 @@ std::vector Pointwise::getSatellites() const return _satellites; } -void Pointwise::setSatellites(std::vector const sats) +void Pointwise::setSatellites(std::vector const &sats) { _satellites = sats; } @@ -65,26 +54,39 @@ void Pointwise::setSatellites(std::vector const sats) */ void Pointwise::setStart() { - std::vector > path_info = _path_info.get(); - for (size_t i = 0; i < path_info.size(); i++) { - size_t firstNode = _path_info.first(path_info[i].first); - size_t lastNode = _path_info.last(path_info[i].first); - if (!_path_info.closed(lastNode)) { - _satellites[firstNode].hidden = true; - _satellites[firstNode].active = false; - } else { - _satellites[firstNode].active = true; - _satellites[firstNode].hidden = _satellites[firstNode + 1].hidden; + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + int counter = 0; + for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); + path_it != pointwise_pv.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + Geom::Path::const_iterator curve_it = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + int index = 0; + while (curve_it != curve_endit) { + if(index == 0){ + if (!path_it->closed()) { + _satellites[counter].hidden = true; + _satellites[counter].active = false; + } else { + _satellites[counter].active = true; + _satellites[counter].hidden = _satellites[counter].hidden; + } + } + ++index; + ++counter; + ++curve_it; } } } /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { if (_pwd2.size() > A.size()) { - pwd2Sustract(A); + pwd2Subtract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); } else { @@ -94,14 +96,18 @@ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > c /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Geom::Piecewise > const A) +void Pointwise::pwd2Subtract(pwd2sb const &A) { size_t counter = 0; std::vector sats; - Geom::Piecewise > pwd2 = _pwd2; + pwd2sb pwd2 = _pwd2; setPwd2(A); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); for (size_t i = 0; i < _satellites.size(); i++) { - if (_path_info.last(i - counter) < i - counter || + Geom::Path sat_path = pointwise_pv.pathAt(i - counter); + Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); + Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); + if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; @@ -114,36 +120,53 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) +void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) { size_t counter = 0; std::vector sats; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { - size_t first = _path_info.first(i - counter); - size_t last = _path_info.last(i - counter); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + Geom::Path sat_path = pointwise_pv.pathAt(i - counter); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); + Geom::PathVectorTime sat_curve_time; + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); + size_t last = first + sat_path.size() - 1; + bool is_start = false; + if(sat_curve_time.curve_index == 0){ + is_start = true; + } //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back - _path_info.set(A); - size_t new_subpath_index = _path_info.subPathIndex(i); - _path_info.set(_pwd2); + size_t old_subpath_index = sat_curve_time.path_index; + pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + sat_path = pointwise_pv.pathAt(i); + sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t new_subpath_index = sat_curve_time.path_index; bool subpath_is_changed = false; - if (_pwd2.size() <= i - counter) { - subpath_is_changed = false; - } else { - subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); + if (_pwd2.size() > i - counter) { + subpath_is_changed = old_subpath_index != new_subpath_index; } - if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + if (!reorder && is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back - subpathToBack(_path_info.subPathIndex(first)); + subpathToBack(old_subpath_index); reorder = true; i--; continue; } - if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //reverse subpath + if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + //Krzysztof this code is hiden because i need a clean way to acced to the first and last index of a subpath based in + //his position on pathvector. Maybe the result Geom::PathVectorTime of nearestTime method can also return the time in the pathvector without calling two times to nearestTime subpathReverse(first, last); } @@ -209,7 +232,14 @@ void Pointwise::subpathReverse(size_t start, size_t end) path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; size_t subpath_counter = 0; - size_t subpath = _path_info.subPathIndex(start); + Geom::Path sat_path = path_in.pathAt(start); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); + Geom::PathVectorTime sat_curve_time; + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t subpath = sat_curve_time.path_index; Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); @@ -231,11 +261,10 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); - _path_info.set(B); - size_t size_B = _path_info.size(); + size_t size_B = B.curveCount(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; @@ -266,7 +295,6 @@ void Pointwise::insertDegenerateSatellites(Geom::Piecewise -#include #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> @@ -39,31 +38,26 @@ * optional satellites, and remove the active variable in satellites. * */ - +typedef Geom::Piecewise > pwd2sb; class Pointwise { public: - Pointwise(); - virtual ~Pointwise(); - - Geom::Piecewise > getPwd2() const; - void setPwd2(Geom::Piecewise > const pwd2_in); + pwd2sb getPwd2() const; + void setPwd2(pwd2sb const &pwd2_in); std::vector getSatellites() const; - void setSatellites(std::vector const sats); - void setPathInfo(Geom::PathVector const pv); + void setSatellites(std::vector const &sats); void setStart(); - void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Sustract(Geom::Piecewise > const A); - void pwd2Append(Geom::Piecewise > const A, Satellite const S); + void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + void pwd2Subtract(pwd2sb const &A); + void pwd2Append(pwd2sb const &A, Satellite const &S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); private: - Geom::Piecewise > _pwd2; + pwd2sb _pwd2; std::vector _satellites; - Pathinfo _path_info; }; #endif //SEEN_POINTWISE_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index eb9f829186..7871ccc1ec 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 d7549d0708..8047093425 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 9b326fe32a..0abcd4b9b4 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 46c7396d00..b7d403a910 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 cc09e7589a..bb8bf27c87 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() { -- GitLab From ada767e2ad124b9dad0f80b7979a156513976aaa Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:20:05 +0200 Subject: [PATCH 067/121] pointwise tweak (bzr r13645.1.104) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 7627b5dc33..db66162ca1 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -165,8 +165,6 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) } if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //Krzysztof this code is hiden because i need a clean way to acced to the first and last index of a subpath based in - //his position on pathvector. Maybe the result Geom::PathVectorTime of nearestTime method can also return the time in the pathvector without calling two times to nearestTime subpathReverse(first, last); } -- GitLab From 2207d9110e54540a7408642099c9217d8037a6b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:22:52 +0200 Subject: [PATCH 068/121] astyle (bzr r13645.1.105) --- src/helper/geom-pointwise.cpp | 30 +++++------ src/helper/geom-satellite.cpp | 5 +- src/helper/geom-satellite.h | 35 ++++++++++--- src/live_effects/lpe-fillet-chamfer.cpp | 50 ++++++++----------- src/live_effects/parameter/satellitearray.cpp | 24 ++++----- 5 files changed, 77 insertions(+), 67 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index db66162ca1..91281ed7db 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -57,7 +57,7 @@ void Pointwise::setStart() Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); int counter = 0; for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); - path_it != pointwise_pv.end(); ++path_it) { + path_it != pointwise_pv.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -65,7 +65,7 @@ void Pointwise::setStart() Geom::Path::const_iterator curve_endit = path_it->end_default(); int index = 0; while (curve_it != curve_endit) { - if(index == 0){ + if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; _satellites[counter].active = false; @@ -108,8 +108,7 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| - !are_near(pwd2[i].at0(), A[i - counter].at0())) - { + !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -130,14 +129,14 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) Geom::Path sat_path = pointwise_pv.pathAt(i - counter); boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); size_t last = first + sat_path.size() - 1; bool is_start = false; - if(sat_curve_time.curve_index == 0){ + if(sat_curve_time.curve_index == 0) { is_start = true; } //Check for subpath closed. If a subpath is closed, is not reversed or moved @@ -146,7 +145,7 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); sat_path = pointwise_pv.pathAt(i); sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); @@ -168,7 +167,7 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) subpathReverse(first, last); } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())) { counter++; sats.push_back(S); } else { @@ -188,8 +187,7 @@ void Pointwise::subpathToBack(size_t subpath) Geom::PathVector tmp_path; Geom::Path to_back; for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) - { + path_it != path_in.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -233,7 +231,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) Geom::Path sat_path = path_in.pathAt(start); boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); @@ -241,8 +239,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) - { + path_it != path_in.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -264,14 +261,13 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con size_t size_A = A.size(); size_t size_B = B.curveCount(); size_t satellite_gap = size_B - size_A; - if (satellite_gap == 0){ + if (satellite_gap == 0) { return; } size_t counter = 0; size_t counter_added = 0; for (Geom::PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) - { + path_it != B.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -284,7 +280,7 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con } } while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ + if ((*curve_it1).isDegenerate() && counter_added < satellite_gap) { counter_added++; _satellites.insert(_satellites.begin() + counter + 1 ,S); } diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index f5f28544d9..ddef7685a0 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -230,9 +230,8 @@ void Satellite::setSatelliteType(gchar const *A) 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(A)); - if(it != gchar_map_to_satellite_type.end()) - { - satellite_type = it->second; + if(it != gchar_map_to_satellite_type.end()) { + satellite_type = it->second; } } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 42c5687bdc..ef76060c4e 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -36,13 +36,34 @@ public: Satellite(SatelliteType satellite_type); virtual ~Satellite(); - void setIsTime(bool set_is_time){is_time = set_is_time;} - void setActive(bool set_active){active = set_active;} - void setHasMirror(bool set_has_mirror){has_mirror = set_has_mirror;} - void setHidden(bool set_hidden){hidden = set_hidden;} - void setAmount(bool set_amount){amount = set_amount;} - void setAngle(bool set_angle){angle = set_angle;} - void setSteps(bool set_steps){steps = set_steps;} + void setIsTime(bool set_is_time) + { + is_time = set_is_time; + } + void setActive(bool set_active) + { + active = set_active; + } + void setHasMirror(bool set_has_mirror) + { + has_mirror = set_has_mirror; + } + void setHidden(bool set_hidden) + { + hidden = set_hidden; + } + void setAmount(bool set_amount) + { + amount = set_amount; + } + void setAngle(bool set_angle) + { + angle = set_angle; + } + void setSteps(bool set_steps) + { + steps = set_steps; + } double lenToRad(double A, Geom::D2 d2_in, Geom::D2 d2_out, Satellite previousSatellite) const; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7871ccc1ec..8998279a65 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 b7d403a910..5e45ddf0dd 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) { -- GitLab From 6962e3344dea73a3bc7d5599cc223ed8cc7cdbe7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 21 Aug 2015 23:53:14 +0200 Subject: [PATCH 069/121] Not sure about this changes :( (bzr r13645.1.107) --- src/helper/geom-pointwise.cpp | 93 ++++++++++++------- src/helper/geom-pointwise.h | 37 +++++--- src/helper/geom-satellite.cpp | 9 +- src/live_effects/parameter/satellitearray.cpp | 3 +- 4 files changed, 91 insertions(+), 51 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 91281ed7db..526df7957f 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,35 +1,21 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof + * Nathan Hurst * Johan Engelen * Josh Andler * suv * Mc- * Liam P. White - * Nathan Hurst * Krzysztof Kosiński * This code is in public domain */ #include -/** - * @brief Pointwise a class to manage a vector of satellites per piecewise curve - * - * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths - * To implement this we can: - * add extra satellite in open paths, and take notice of current open paths - * or put extra satellites on back for each open subpath - * - * Also maybe the vector of satellites become a vector of - * optional satellites, and remove the active variable in satellites. - * - */ - pwd2sb Pointwise::getPwd2() const { return _pwd2; @@ -40,18 +26,69 @@ void Pointwise::setPwd2(pwd2sb const &pwd2_in) _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites() const +std::vector Pointwise::getSatellites(bool curve_based) { + if(curve_based){ + size_t global_counter = 0; + size_t satellite_gap = 0; + Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + for (Geom::PathVector::const_iterator path_it = pathvector.begin(); + path_it != pathvector.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + size_t counter = 0; + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end_closed(); ++curve_it) { + if(!path_it->closed()){ + if(path_it->size_closed()-1 == counter){ + _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); + satellite_gap++; + std::cout << counter << "get satellites" << "\n"; + } + } + counter++; + global_counter++; + } + } + } return _satellites; } -void Pointwise::setSatellites(std::vector const &sats) +void Pointwise::setSatellites(std::vector const &sats, bool curve_based) { _satellites = sats; + if(curve_based){ + size_t global_counter = 0; + Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + for (Geom::PathVector::const_iterator path_it = pathvector.begin(); + path_it != pathvector.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + size_t counter = 0; + size_t start = global_counter; + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end_closed(); ++curve_it) { + if(!path_it->closed()){ + if(path_it->size_closed()-1 == counter){ + if(global_counter == _satellites.size()){ + _satellites.push_back(_satellites[start]); + } else { + _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); + } + std::cout << counter << "set satellites" << "\n"; + } + } + counter++; + global_counter++; + } + } + } } -/** Update the start satellite on open/closed paths. - */ + + void Pointwise::setStart() { Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); @@ -61,28 +98,24 @@ void Pointwise::setStart() if (path_it->empty()) { continue; } - Geom::Path::const_iterator curve_it = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); int index = 0; - while (curve_it != curve_endit) { + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end(); ++curve_it) { if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; _satellites[counter].active = false; } else { _satellites[counter].active = true; - _satellites[counter].hidden = _satellites[counter].hidden; + _satellites[counter].hidden = _satellites[counter+1].hidden; } } ++index; ++counter; - ++curve_it; } } } -/** Fired when a path is modified. - */ void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { if (_pwd2.size() > A.size()) { @@ -94,8 +127,6 @@ void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B } } -/** Some nodes/subpaths are removed. - */ void Pointwise::pwd2Subtract(pwd2sb const &A) { size_t counter = 0; @@ -117,8 +148,6 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) setSatellites(sats); } -/** Append nodes/subpaths to current pointwise - */ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) { size_t counter = 0; @@ -254,8 +283,6 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - */ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 6a8ea88816..fe8f6f1576 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,15 +1,15 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof + * Nathan Hurst * Johan Engelen * Josh Andler * suv * Mc- * Liam P. White - * Nathan Hurst * Krzysztof Kosiński * This code is in public domain */ @@ -27,16 +27,6 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve - * - * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths - * To implement this we can: - * add extra satellite in open paths, and take notice of current open paths - * or put extra satellites on back for each open subpath - * - * Also maybe the vector of satellites become a vector of - * optional satellites, and remove the active variable in satellites. - * */ typedef Geom::Piecewise > pwd2sb; class Pointwise { @@ -44,15 +34,32 @@ public: pwd2sb getPwd2() const; void setPwd2(pwd2sb const &pwd2_in); - std::vector getSatellites() const; - void setSatellites(std::vector const &sats); + /** + * @parameter curve_based allow the use of a satellite on last node of open paths + * if not curve based + */ + std::vector getSatellites(bool curve_based = true); + void setSatellites(std::vector const &sats, bool curve_based = true); + /** Update the start satellite on open/closed paths. + */ void setStart(); - + /** Fired when a path is modified. + */ void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + /** Some nodes/subpaths are removed. + */ void pwd2Subtract(pwd2sb const &A); + /** Append nodes/subpaths to current pointwise + */ void pwd2Append(pwd2sb const &A, Satellite const &S); + /** Send a subpath to end and update satellites + */ void subpathToBack(size_t subpath); + /** Reverse a subpath and update satellites + */ void subpathReverse(size_t start, size_t end); + /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. + */ void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); private: diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index ddef7685a0..9b2691a336 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -23,7 +23,14 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) - : satellite_type(satellite_type) + : satellite_type(satellite_type), + is_time(false), + active(false), + has_mirror(false), + hidden(true), + amount(0.0), + angle(0.0), + steps(0) {} Satellite::~Satellite() {} diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5e45ddf0dd..9c22741fff 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; } -- GitLab From 9e8b8be725180905f537a0c20183c209abc5476f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 22 Aug 2015 00:05:38 +0200 Subject: [PATCH 070/121] remove couts (bzr r13645.1.109) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 526df7957f..8a0db62584 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -44,7 +44,6 @@ std::vector Pointwise::getSatellites(bool curve_based) if(path_it->size_closed()-1 == counter){ _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); satellite_gap++; - std::cout << counter << "get satellites" << "\n"; } } counter++; @@ -77,7 +76,6 @@ void Pointwise::setSatellites(std::vector const &sats, bool curve_bas } else { _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); } - std::cout << counter << "set satellites" << "\n"; } } counter++; -- GitLab From 4f78e3e4289b52ba4b7a3fbe24fd0d6fcb6f2250 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 23 Aug 2015 23:03:12 +0200 Subject: [PATCH 071/121] satellites in curves (bzr r13645.1.110) --- src/helper/geom-pointwise.cpp | 61 +------ src/helper/geom-pointwise.h | 6 +- src/helper/geom-satellite.cpp | 163 +++++++++++------- src/helper/geom-satellite.h | 25 ++- src/live_effects/lpe-fillet-chamfer.cpp | 102 +++++------ src/live_effects/parameter/satellitearray.cpp | 127 +++++--------- 6 files changed, 209 insertions(+), 275 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8a0db62584..8ae2125a43 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -23,76 +23,25 @@ pwd2sb Pointwise::getPwd2() const void Pointwise::setPwd2(pwd2sb const &pwd2_in) { + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites(bool curve_based) +std::vector Pointwise::getSatellites(e) { - if(curve_based){ - size_t global_counter = 0; - size_t satellite_gap = 0; - Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (Geom::PathVector::const_iterator path_it = pathvector.begin(); - path_it != pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - size_t counter = 0; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end_closed(); ++curve_it) { - if(!path_it->closed()){ - if(path_it->size_closed()-1 == counter){ - _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); - satellite_gap++; - } - } - counter++; - global_counter++; - } - } - } return _satellites; } -void Pointwise::setSatellites(std::vector const &sats, bool curve_based) +void Pointwise::setSatellites(std::vector const &sats) { _satellites = sats; - if(curve_based){ - size_t global_counter = 0; - Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (Geom::PathVector::const_iterator path_it = pathvector.begin(); - path_it != pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - size_t counter = 0; - size_t start = global_counter; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end_closed(); ++curve_it) { - if(!path_it->closed()){ - if(path_it->size_closed()-1 == counter){ - if(global_counter == _satellites.size()){ - _satellites.push_back(_satellites[start]); - } else { - _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); - } - } - } - counter++; - global_counter++; - } - } - } } - - void Pointwise::setStart() { - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); int counter = 0; - for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); - path_it != pointwise_pv.end(); ++path_it) { + for (Geom::PathVector::const_iterator path_it = _pathvector.begin(); + path_it != _pathvector.end(); ++path_it) { if (path_it->empty()) { continue; } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index fe8f6f1576..9d2993a23f 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,13 +33,13 @@ class Pointwise { public: pwd2sb getPwd2() const; void setPwd2(pwd2sb const &pwd2_in); - /** * @parameter curve_based allow the use of a satellite on last node of open paths * if not curve based */ - std::vector getSatellites(bool curve_based = true); - void setSatellites(std::vector const &sats, bool curve_based = true); + std::vector getSatellites(); + void setSatellites(std::vector const &sats); + /** Update the start satellite on open/closed paths. */ void setStart(); diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 9b2691a336..10afca725d 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -36,53 +36,88 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} /** - * Calculate the time in d2_in with a size of A + * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ -double timeAtArcLength(double A, Geom::D2 const d2_in) +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) { - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + if ( A == 0 || curve_in.isDegenerate()) { return 0; } + + //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- + Geom::D2 d2_in = curve_in.toSBasis(); + static std::deque > > > deque_cache; + if(cache_limit > 0 && deque_cache.size() > cache_limit){ + std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); + deque_cache = deque_cache_split; + } + if(cache_limit > 0){ + return 1; + } + std::deque > > >::iterator it; + for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ + if(it->second.first == A){ + if(it->second.second == d2_in){ + return it->first; + } + } + } + double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A >= length_part || d2_in[0].degreesOfFreedom() == 2) { + double length_part = curve_in.length(); + if (A >= length_part || curve_in.isLineSegment()) { if (length_part != 0) { t = A / length_part; } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); + } else if (!curve_in.isLineSegment()) { + + std::vector t_roots = roots(Geom::arcLengthSb(d2_in) - A); if (t_roots.size() > 0) { t = t_roots[0]; } } - + deque_cache.push_front(std::make_pair(t, std::make_pair(A, d2_in))); return t; } /** - * Calculate the size in d2_in with a point at A + * Calculate the size in curve_in with a point at A * TODO: find a better place to it */ -double arcLengthAt(double A, Geom::D2 const d2_in) +double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit) { - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + if ( A == 0 || curve_in.isDegenerate()) { return 0; } + + //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- + Geom::D2 d2_in = curve_in.toSBasis(); + static std::deque > > > deque_cache; + if(cache_limit > 0 && deque_cache.size() > cache_limit){ + std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); + deque_cache = deque_cache_split; + } + if(cache_limit > 0){ + return 1; + } + std::deque > > >::iterator it; + for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ + if(it->second.first == A){ + if(it->second.second == d2_in){ + return it->first; + } + } + } double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + double length_part = curve_in.length(); + if (A > length_part || curve_in.isLineSegment()) { s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); + } else if (!curve_in.isLineSegment()) { + Geom::Curve *curve = curve_in.portion(0.0, A); + s = curve->length(0.001); } + deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; } @@ -90,10 +125,12 @@ double arcLengthAt(double A, Geom::D2 const d2_in) * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve */ double Satellite::radToLen( - double A, Geom::D2 const d2_in, - Geom::D2 const d2_out) const + double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out) const { double len = 0; + Geom::D2 d2_in = curve_in.toSBasis(); + Geom::D2 d2_out = curve_out.toSBasis(); Geom::Piecewise > offset_curve0 = Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); @@ -105,11 +142,11 @@ double Satellite::radToLen( Geom::Crossings cs = Geom::crossings(p0, p1); if (cs.size() > 0) { Geom::Point cp = p0(cs[0].ta); - double p0pt = nearest_time(cp, d2_out); - len = arcLengthAt(p0pt, d2_out); + double p0pt = nearest_time(cp, curve_out); + len = arcLengthAt(p0pt, curve_out); } else { if (A > 0) { - len = radToLen(A * -1, d2_in, d2_out); + len = radToLen(A * -1, curve_in, curve_out); } } return len; @@ -119,37 +156,29 @@ double Satellite::radToLen( * Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer */ double Satellite::lenToRad( - double A, Geom::D2 const d2_in, - Geom::D2 const d2_out, + double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out, Satellite const previousSatellite) const { - double time_in = (previousSatellite).time(A, true, d2_in); - double time_out = timeAtArcLength(A, d2_out); - Geom::Point startArcPoint = (d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Geom::Piecewise > u2; - u2.push_cut(0); - u2.push(d2_out, 1); - Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Geom::Curve *knotCurve1 = C->portion(0, time_in); - Geom::Curve *knotCurve2 = D->portion(time_out, 1); + double time_in = (previousSatellite).time(A, true, curve_in); + double time_out = timeAtArcLength(A, curve_out); + Geom::Point startArcPoint = curve_in.pointAt(time_in); + Geom::Point endArcPoint = curve_out.pointAt(time_out); + Geom::Curve *knotCurve1 = curve_in.portion(0, time_in); + Geom::Curve *knotCurve2 = curve_out.portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Geom::Ray ray1(startArcPoint, (d2_in).valueAt(1)); + Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Geom::Ray ray2(d2_out.valueAt(0), endArcPoint); + Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross((d2_in).valueAt(1) - startArcPoint, + bool ccwToggle = cross(curve_in.pointAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; double distanceArc = Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); @@ -162,13 +191,15 @@ double Satellite::lenToRad( } /** - * Get the time position of the satellite in d2_in + * Get the time position of the satellite in curve_in */ -double Satellite::time(Geom::D2 d2_in) const +double Satellite::time(Geom::Curve const &curve_in, bool const I) const { double t = amount; if (!is_time) { - t = timeAtArcLength(t, d2_in); + t = time(t, I, curve_in); + } else if (I) { + t = 1-t; } if (t > 1) { t = 1; @@ -179,8 +210,8 @@ double Satellite::time(Geom::D2 d2_in) const /**. * Get the time from a length A in other curve, a bolean I gived to reverse time */ -double Satellite::time(double A, bool I, - Geom::D2 d2_in) const +double Satellite::time(double A, bool const I, + Geom::Curve const &curve_in) const { if (A == 0 && I) { return 1; @@ -189,21 +220,21 @@ double Satellite::time(double A, bool I, return 0; } if (!I) { - return timeAtArcLength(A, d2_in); + return timeAtArcLength(A, curve_in); } - double length_part = Geom::length(d2_in, Geom::EPSILON); + double length_part = curve_in.length(); A = length_part - A; - return timeAtArcLength(A, d2_in); + return timeAtArcLength(A, curve_in); } /** - * Get the length of the satellite in d2_in + * Get the length of the satellite in curve_in */ -double Satellite::arcDistance(Geom::D2 d2_in) const +double Satellite::arcDistance(Geom::Curve const &curve_in) const { double s = amount; if (is_time) { - s = arcLengthAt(s, d2_in); + s = arcLengthAt(s, curve_in); } return s; } @@ -211,22 +242,26 @@ double Satellite::arcDistance(Geom::D2 d2_in) const /** * Get the point position of the satellite */ -Geom::Point Satellite::getPosition(Geom::D2 d2_in) const +Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool const I) const { - double t = time(d2_in); - return d2_in.valueAt(t); + double t = time(curve_in, I); + return curve_in.pointAt(t); } /** * Set the position of the satellite from a gived point P */ -void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I) { - double A = Geom::nearest_time(p, d2_in); + Geom::Curve * curve = const_cast(&curve_in); + if (I) { + curve = curve->reverse(); + } + double A = Geom::nearest_time(p, *curve); if (!is_time) { - A = arcLengthAt(A, d2_in); + A = arcLengthAt(A, *curve); } - amount = A; + this->setAmount(A); } /** diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index ef76060c4e..ed1ec221bb 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -11,7 +11,6 @@ #ifndef SEEN_SATELLITE_H #define SEEN_SATELLITE_H -#include <2geom/d2.h> #include #include #include <2geom/sbasis-geometric.h> @@ -64,18 +63,18 @@ public: { steps = set_steps; } - double lenToRad(double A, Geom::D2 d2_in, - Geom::D2 d2_out, - Satellite previousSatellite) const; - double radToLen(double A, Geom::D2 d2_in, - Geom::D2 d2_out) const; + double lenToRad(double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out, + Satellite const previousSatellite) const; + double radToLen(double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out) const; - double time(Geom::D2 d2_in) const; - double time(double A, bool I, Geom::D2 d2_in) const; - double arcDistance(Geom::D2 d2_in) const; + double time(Geom::Curve const &curve_in, bool const I = false) const; + double time(double A, bool const I, Geom::Curve const &curve_in) const; + double arcDistance(Geom::Curve const &curve_in) const; - void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 d2_in) const; + void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I = false); + Geom::Point getPosition(Geom::Curve const &curve_in, bool const I = false) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; @@ -88,8 +87,8 @@ public: double angle; size_t steps; }; -double timeAtArcLength(double A, Geom::D2 const d2_in); -double arcLengthAt(double A, Geom::D2 const d2_in); +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); +double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); #endif // SEEN_SATELLITE_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 8998279a65..385e9ce284 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 9c22741fff..ba1338daa0 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; } -- GitLab From 89b565d68326ada49d11d0735ffb6b602c26a54f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 24 Aug 2015 00:58:37 +0200 Subject: [PATCH 072/121] Cached some functions (bzr r13645.1.111) --- src/helper/geom-pointwise.cpp | 20 +-- src/helper/geom-pointwise.h | 1 + src/helper/geom-satellite.cpp | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 12 +- src/live_effects/parameter/satellitearray.cpp | 115 ++++++++++++------ 5 files changed, 95 insertions(+), 57 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8ae2125a43..9aa90df011 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -27,7 +27,7 @@ void Pointwise::setPwd2(pwd2sb const &pwd2_in) _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites(e) +std::vector Pointwise::getSatellites() { return _satellites; } @@ -80,10 +80,10 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) std::vector sats; pwd2sb pwd2 = _pwd2; setPwd2(A); - 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); for (size_t i = 0; i < _satellites.size(); i++) { - Geom::Path sat_path = pointwise_pv.pathAt(i - counter); - Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); + Geom::Path sat_path = pathv.pathAt(i - counter); + Geom::PathTime sat_curve_time = sat_path.nearestTime(pathv.curveAt(i - counter).initialPoint()); Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| !are_near(pwd2[i].at0(), A[i - counter].at0())) { @@ -101,9 +101,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) std::vector sats; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - Geom::Path sat_path = pointwise_pv.pathAt(i - counter); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(i - counter); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i-counter).initialPoint()); Geom::PathVectorTime sat_curve_time; if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; @@ -118,9 +118,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back size_t old_subpath_index = sat_curve_time.path_index; - pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - sat_path = pointwise_pv.pathAt(i); - sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); + pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + sat_path = pathv.pathAt(i); + sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i).initialPoint()); if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 9d2993a23f..a2324accd2 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -64,6 +64,7 @@ public: private: pwd2sb _pwd2; + Geom::PathVector _pathvector; std::vector _satellites; }; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 10afca725d..35d21ef320 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -115,7 +115,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim s = (A * length_part); } else if (!curve_in.isLineSegment()) { Geom::Curve *curve = curve_in.portion(0.0, A); - s = curve->length(0.001); + s = curve->length(); } deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; @@ -261,7 +261,7 @@ void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bo if (!is_time) { A = arcLengthAt(A, *curve); } - this->setAmount(A); + amount = A; } /** diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 385e9ce284..3fa011b387 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 ba1338daa0..6c3123f129 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; -- GitLab From d34b8dca901083e5b68fd22899cb2c014238f8a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:39:35 +0200 Subject: [PATCH 073/121] addes cache and log to a function, result of the test, no diference so remove cache on next commit (bzr r13645.1.112) --- src/helper/geom-satellite.cpp | 108 +++++++++++++++++------- src/helper/geom-satellite.h | 7 +- src/live_effects/lpe-fillet-chamfer.cpp | 8 +- src/live_effects/lpe-fillet-chamfer.h | 1 + 4 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 35d21ef320..fac314b7f7 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -15,6 +15,13 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> #include +//log cache +#ifdef _WIN32 +#include +#else +#include +#include +#endif /** * @brief Satellite a per ?node/curve holder of data. @@ -39,6 +46,49 @@ Satellite::~Satellite() {} * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ + +//http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c +/* Remove if already defined */ +typedef long long int64; typedef unsigned long long uint64; + +/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both + * windows and linux. */ + +uint64 GetTimeMs64() +{ +#ifdef _WIN32 + /* Windows */ + FILETIME ft; + LARGE_INTEGER li; + + /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it + * to a LARGE_INTEGER structure. */ + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + + uint64 ret = li.QuadPart; + ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */ + ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ + + return ret; +#else + /* Linux */ + struct timeval tv; + + gettimeofday(&tv, NULL); + + uint64 ret = tv.tv_usec; + /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */ + ret /= 1000; + + /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */ + ret += (tv.tv_sec * 1000); + + return ret; +#endif +} + double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) { if ( A == 0 || curve_in.isDegenerate()) { @@ -47,19 +97,34 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - static std::deque > > > deque_cache; - if(cache_limit > 0 && deque_cache.size() > cache_limit){ - std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); - deque_cache = deque_cache_split; + + static bool cached = false; + if(cache_limit == 0){ + cached = false; + } else if(cache_limit > 1){ + cached = true; } - if(cache_limit > 0){ + static size_t count = 0; + static uint64 start = GetTimeMs64(); + static uint64 time_diff = GetTimeMs64(); + static cache_item cache_value = std::make_pair(0.0, std::make_pair(A, d2_in)); + if(cache_limit > 1 || cache_limit == 0){ + uint64 end = GetTimeMs64(); + uint64 elapsed_ms = end-start; + if(count == 0){ + time_diff = 0; + } else if(elapsed_ms < 1000){ + time_diff += elapsed_ms; + } + std::cout << "counter:" << count << ", cached:" << cached << ", function:timeAtArcLength" << ", miliseconds:" << elapsed_ms << ", acumulated ms:" << time_diff << "\n"; + start = end; + count++; return 1; } - std::deque > > >::iterator it; - for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ - if(it->second.first == A){ - if(it->second.second == d2_in){ - return it->first; + if(cached){ + if(cache_value.second.first == A){ + if(cache_value.second.second == d2_in ){ + return cache_value.first; } } } @@ -77,7 +142,9 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache t = t_roots[0]; } } - deque_cache.push_front(std::make_pair(t, std::make_pair(A, d2_in))); + if(cached){ + cache_value = std::make_pair(t, std::make_pair(A, d2_in)); + } return t; } @@ -85,7 +152,7 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache * Calculate the size in curve_in with a point at A * TODO: find a better place to it */ -double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit) +double arcLengthAt(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { return 0; @@ -93,22 +160,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - static std::deque > > > deque_cache; - if(cache_limit > 0 && deque_cache.size() > cache_limit){ - std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); - deque_cache = deque_cache_split; - } - if(cache_limit > 0){ - return 1; - } - std::deque > > >::iterator it; - for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ - if(it->second.first == A){ - if(it->second.second == d2_in){ - return it->first; - } - } - } double s = 0; double length_part = curve_in.length(); if (A > length_part || curve_in.isLineSegment()) { @@ -117,7 +168,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim Geom::Curve *curve = curve_in.portion(0.0, A); s = curve->length(); } - deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index ed1ec221bb..61ac6be751 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -27,7 +27,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ - +typedef std::pair > > cache_item; class Satellite { public: @@ -87,8 +87,9 @@ public: double angle; size_t steps; }; -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); -double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); +//cache_limit never called as 1 +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 1); +double arcLengthAt(double const A, Geom::Curve const &curve_in); #endif // SEEN_SATELLITE_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 3fa011b387..a83c7bbd5e 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 8047093425..9c58ab66c2 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; -- GitLab From 6d0ce49991a442e7e3f26c3922c26e54d927dd93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:48:02 +0200 Subject: [PATCH 074/121] Removed cache work :( (bzr r13645.1.113) --- src/helper/geom-satellite.cpp | 78 +------------------------ src/helper/geom-satellite.h | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 8 --- src/live_effects/lpe-fillet-chamfer.h | 1 - 4 files changed, 3 insertions(+), 88 deletions(-) diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index fac314b7f7..547caf539a 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -47,49 +47,8 @@ Satellite::~Satellite() {} * TODO: find a better place to it */ -//http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c -/* Remove if already defined */ -typedef long long int64; typedef unsigned long long uint64; -/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both - * windows and linux. */ - -uint64 GetTimeMs64() -{ -#ifdef _WIN32 - /* Windows */ - FILETIME ft; - LARGE_INTEGER li; - - /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it - * to a LARGE_INTEGER structure. */ - GetSystemTimeAsFileTime(&ft); - li.LowPart = ft.dwLowDateTime; - li.HighPart = ft.dwHighDateTime; - - uint64 ret = li.QuadPart; - ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */ - ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ - - return ret; -#else - /* Linux */ - struct timeval tv; - - gettimeofday(&tv, NULL); - - uint64 ret = tv.tv_usec; - /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */ - ret /= 1000; - - /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */ - ret += (tv.tv_sec * 1000); - - return ret; -#endif -} - -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) +double timeAtArcLength(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { return 0; @@ -97,38 +56,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - - static bool cached = false; - if(cache_limit == 0){ - cached = false; - } else if(cache_limit > 1){ - cached = true; - } - static size_t count = 0; - static uint64 start = GetTimeMs64(); - static uint64 time_diff = GetTimeMs64(); - static cache_item cache_value = std::make_pair(0.0, std::make_pair(A, d2_in)); - if(cache_limit > 1 || cache_limit == 0){ - uint64 end = GetTimeMs64(); - uint64 elapsed_ms = end-start; - if(count == 0){ - time_diff = 0; - } else if(elapsed_ms < 1000){ - time_diff += elapsed_ms; - } - std::cout << "counter:" << count << ", cached:" << cached << ", function:timeAtArcLength" << ", miliseconds:" << elapsed_ms << ", acumulated ms:" << time_diff << "\n"; - start = end; - count++; - return 1; - } - if(cached){ - if(cache_value.second.first == A){ - if(cache_value.second.second == d2_in ){ - return cache_value.first; - } - } - } - double t = 0; double length_part = curve_in.length(); if (A >= length_part || curve_in.isLineSegment()) { @@ -142,9 +69,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache t = t_roots[0]; } } - if(cached){ - cache_value = std::make_pair(t, std::make_pair(A, d2_in)); - } return t; } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 61ac6be751..2369dddbd5 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -27,7 +27,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ -typedef std::pair > > cache_item; + class Satellite { public: @@ -88,7 +88,7 @@ public: size_t steps; }; //cache_limit never called as 1 -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 1); +double timeAtArcLength(double const A, Geom::Curve const &curve_in); double arcLengthAt(double const A, Geom::Curve const &curve_in); #endif // SEEN_SATELLITE_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a83c7bbd5e..4c325b7fa0 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 9c58ab66c2..8047093425 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; -- GitLab From 4b21c95466fd2e108caccafb3feb1d17e5055431 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 21:34:58 +0200 Subject: [PATCH 075/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 4c325b7fa0..24ed983fdc 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 6c3123f129..ab2b9fe2e4 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); -- GitLab From be65fc811e309e3a126f272601c3cb7997ef465e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 22:09:46 +0200 Subject: [PATCH 076/121] astyle code (bzr r13645.1.116) --- src/helper/geom-pointwise.cpp | 2 +- src/helper/geom-satellite.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9aa90df011..7074761da6 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -47,7 +47,7 @@ void Pointwise::setStart() } int index = 0; for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end(); ++curve_it) { + curve_it != path_it->end(); ++curve_it) { if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 547caf539a..615106dd93 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -31,13 +31,13 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), - is_time(false), - active(false), - has_mirror(false), - hidden(true), - amount(0.0), - angle(0.0), - steps(0) + is_time(false), + active(false), + has_mirror(false), + hidden(true), + amount(0.0), + angle(0.0), + steps(0) {} Satellite::~Satellite() {} @@ -46,7 +46,7 @@ Satellite::~Satellite() {} * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ - + double timeAtArcLength(double const A, Geom::Curve const &curve_in) { -- GitLab From 67753b095a9a4c3ce0f22a3c63b5adb863c087ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 1 Sep 2015 21:54:18 +0200 Subject: [PATCH 077/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ed983fdc..8c3b6e2f1b 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 8047093425..638e8c6af3 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; -- GitLab From 7fee08f7ade15cbba3932dd745492779e7e01987 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 00:17:44 +0100 Subject: [PATCH 078/121] Fixed bugs post merge (bzr r13645.1.120) --- src/live_effects/parameter/satellitearray.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index ab2b9fe2e4..1615f33e2c 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; -- GitLab From 01836c90d5d768fe4f189bf066cb4ed800196d8d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 07:59:18 +0100 Subject: [PATCH 079/121] Remove advertaising buttons of old version (bzr r13645.1.123) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d91225cb7d..896cf2e695 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) { -- GitLab From 90fa52d140c68277789d5c87b86bd7a73969458d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 8 Apr 2016 18:03:17 +0200 Subject: [PATCH 080/121] remove a waring on compile (bzr r13645.1.126) --- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 896cf2e695..9563956239 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); } -- GitLab From 97bd182d6a2113eab1dd5faf51402ebd5382791c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 22:57:37 +0200 Subject: [PATCH 081/121] First attempt to make fixed tweenk review (bzr r13645.1.128) --- src/2geom/2geom.h | 2 - src/2geom/CMakeLists.txt | 3 - src/helper/geom-pointwise.cpp | 277 +++------ src/helper/geom-pointwise.h | 49 +- src/helper/geom-satellite.cpp | 60 +- src/helper/geom-satellite.h | 16 +- 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 ------------------ .../parameter/satellitesarray.cpp | 527 +++++++++++++++++ .../{satellitearray.h => satellitesarray.h} | 17 +- 14 files changed, 835 insertions(+), 1020 deletions(-) delete mode 100644 src/live_effects/parameter/satellitearray.cpp create mode 100644 src/live_effects/parameter/satellitesarray.cpp rename src/live_effects/parameter/{satellitearray.h => satellitesarray.h} (85%) diff --git a/src/2geom/2geom.h b/src/2geom/2geom.h index e9222ba846..813e243b34 100644 --- a/src/2geom/2geom.h +++ b/src/2geom/2geom.h @@ -59,8 +59,6 @@ #include <2geom/sbasis.h> // others -#include <2geom/pointwise.h> -#include <2geom/satellite.h> #include <2geom/math-utils.h> #include <2geom/utils.h> diff --git a/src/2geom/CMakeLists.txt b/src/2geom/CMakeLists.txt index e38594547f..97b47b630f 100644 --- a/src/2geom/CMakeLists.txt +++ b/src/2geom/CMakeLists.txt @@ -29,11 +29,9 @@ set(2geom_SRC pathvector.cpp piecewise.cpp point.cpp - pointwise.cpp polynomial.cpp rect.cpp # recursive-bezier-intersection.cpp - satellite.cpp sbasis-2d.cpp sbasis-geometric.cpp sbasis-math.cpp @@ -95,7 +93,6 @@ set(2geom_SRC pathvector.h piecewise.h point.h - pointwise.h polynomial.h ray.h rect.h diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 7074761da6..a96b7cbda7 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -16,221 +16,116 @@ #include -pwd2sb Pointwise::getPwd2() const +PwD2SBasis Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(pwd2sb const &pwd2_in) +Geom::Pathvector Pointwise::getPV() const { - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - _pwd2 = pwd2_in; + return _pathvector; } -std::vector Pointwise::getSatellites() +void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) { - return _satellites; + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + _pwd2 = pwd2_in; } -void Pointwise::setSatellites(std::vector const &sats) +Satelites Pointwise::getSatellites() { - _satellites = sats; + return _satellites; } -void Pointwise::setStart() +size_t Pointwise::getTotalSatellites() { - int counter = 0; - for (Geom::PathVector::const_iterator path_it = _pathvector.begin(); - path_it != _pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - int index = 0; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end(); ++curve_it) { - if(index == 0) { - if (!path_it->closed()) { - _satellites[counter].hidden = true; - _satellites[counter].active = false; - } else { - _satellites[counter].active = true; - _satellites[counter].hidden = _satellites[counter+1].hidden; - } - } - ++index; - ++counter; + size_t counter = 0 + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + counter++; } } + return counter; } -void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) +void Pointwise::setSatellites(Satelites const &sats) { - if (_pwd2.size() > A.size()) { - pwd2Subtract(A); - } else if (_pwd2.size() < A.size()) { - pwd2Append(A, S); - } else { - insertDegenerateSatellites(A, B, S); - } + _satellites = sats; } -void Pointwise::pwd2Subtract(pwd2sb const &A) +void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { - size_t counter = 0; - std::vector sats; - pwd2sb pwd2 = _pwd2; - setPwd2(A); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (size_t i = 0; i < _satellites.size(); i++) { - Geom::Path sat_path = pathv.pathAt(i - counter); - Geom::PathTime sat_curve_time = sat_path.nearestTime(pathv.curveAt(i - counter).initialPoint()); - Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); - if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| - !are_near(pwd2[i].at0(), A[i - counter].at0())) { - counter++; - } else { - sats.push_back(_satellites[i - counter]); - } + if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { + recalculatePwD2(A, S); + } else { + insertDegenerateSatellites(A, B, S); } - setSatellites(sats); } -void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) +void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) { - size_t counter = 0; - std::vector sats; - bool reorder = false; - for (size_t i = 0; i < A.size(); i++) { - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(i - counter); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i-counter).initialPoint()); - Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; - } - sat_curve_time.normalizeForward(sat_path.size()); - size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); - size_t last = first + sat_path.size() - 1; - bool is_start = false; - if(sat_curve_time.curve_index == 0) { - is_start = true; - } - //Check for subpath closed. If a subpath is closed, is not reversed or moved - //to back - size_t old_subpath_index = sat_curve_time.path_index; - pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - sat_path = pathv.pathAt(i); - sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i).initialPoint()); - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; - } - sat_curve_time.normalizeForward(sat_path.size()); - size_t new_subpath_index = sat_curve_time.path_index; - bool subpath_is_changed = false; - if (_pwd2.size() > i - counter) { - subpath_is_changed = old_subpath_index != new_subpath_index; - } - - if (!reorder && is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //Send the modified subpath to back - subpathToBack(old_subpath_index); - reorder = true; - i--; - continue; - } - - if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - subpathReverse(first, last); + Satelites sats; + Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + Geom::PathVector old_pathv = _pathvector; + _pathvector.clear(); + size_t new_size = new_pathv.size(); + size_t old_size = old_pathv.size(); + size_t old_increments = old_size; + for (size_t i = 0; i < new_pathv.size(); i++) { + bool match = false; + for (size_t j = 0; j < old_pathv.size(); j++) { + std::vector subpath_satellites; + if ( new_pathv[i] == old_pathv[j]){ + _pathvector.push_back(old_pathv[j]; + sats.push_back(_satellites[j]); + _satellites.erase(_satellites.begin() + j); + old_pathv.erase(old_pathv.begin() + j); + new_pathv.erase(new_pathv.begin() + i); + match = true; + break; + } } - - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())) { - counter++; - sats.push_back(S); - } else { - sats.push_back(_satellites[i - counter]); + if (!match && new_size > old_increments){ + _pathvector.push_back(new_pathv[i]); + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size(); k++) { + subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); + } + sats.push_back(subpath_satellites); + old_increments ++; } } - setPwd2(A); - setSatellites(sats); -} - -void Pointwise::subpathToBack(size_t subpath) -{ - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - size_t subpath_counter = 0; - size_t counter = 0; - Geom::PathVector tmp_path; - Geom::Path to_back; - for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.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::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - while (curve_it1 != curve_endit) { - if (subpath_counter == subpath) { - _satellites.push_back(_satellites[counter]); - _satellites.erase(_satellites.begin() + counter); + if (new_size == old_size) { + //we asume not change the order of subpaths when remove or add nodes to existing subpaths + for (size_t l = 0; l < old_pathv.size(); l++) { + //we assume we only can delete or add nodes not a mix of both + if (old_pathv[l].size() > new_pathv[l].size()){ + //erase nodes + for (size_t m = 0; m < old_pathv[l].size(); m++) { + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { + _satellites[l].erase(_satellites.begin() + m); + } + } + } else if (old_pathv[l].size() > new_pathv[l].size()) { + //add nodes + for (size_t m = 0; m < old_pathv[l].size(); m++) { + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { + _satellites[l].insert(_satellites.begin() + m, S); + } + } } else { - counter++; + //never happends } - ++curve_it1; + sats.push_back(_satellites[l]); + _pathvector.push_back(new_pathv[l]); + } - if (subpath_counter == subpath) { - to_back = *path_it; - } else { - tmp_path.push_back(*path_it); - } - subpath_counter++; - } - tmp_path.push_back(to_back); - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); -} - -void Pointwise::subpathReverse(size_t start, size_t end) -{ - start++; - for (size_t i = end; i >= start; i--) { - _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); - _satellites.erase(_satellites.begin() + i); - } - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - size_t counter = 0; - size_t subpath_counter = 0; - Geom::Path sat_path = path_in.pathAt(start); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); - Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; } - sat_curve_time.normalizeForward(sat_path.size()); - size_t subpath = sat_curve_time.path_index; - Geom::PathVector tmp_path; - Geom::Path rev; - for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - counter++; - if (subpath_counter == subpath) { - tmp_path.push_back(path_it->reversed()); - } else { - tmp_path.push_back(*path_it); - } - subpath_counter++; - } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); + setPwd2(A); + setSatellites(sats); } -void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) +void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); size_t size_B = B.curveCount(); @@ -238,31 +133,21 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con if (satellite_gap == 0) { return; } - size_t counter = 0; size_t counter_added = 0; - for (Geom::PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) { - if (path_it->empty()) { + for (size_t i = 0; i < B.size(); i++) { + size_t counter = 0; + if (B[i]->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()) { - Geom::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() && counter_added < satellite_gap) { + for (size_t j = 0; j < B[i].size(); j++) { + if ((B[i][j].isDegenerate() && counter_added < satellite_gap) { counter_added++; - _satellites.insert(_satellites.begin() + counter + 1 ,S); + _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); } ++curve_it1; counter++; } } - setPwd2(A); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index a2324accd2..4c2ec79570 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -28,44 +28,27 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve */ -typedef Geom::Piecewise > pwd2sb; +typedef Geom::Piecewise > PwD2SBasisasis; +typedef std::vector< Satelites > Satelites; class Pointwise { public: - pwd2sb getPwd2() const; - void setPwd2(pwd2sb const &pwd2_in); - /** - * @parameter curve_based allow the use of a satellite on last node of open paths - * if not curve based - */ - std::vector getSatellites(); - void setSatellites(std::vector const &sats); - - /** Update the start satellite on open/closed paths. - */ - void setStart(); - /** Fired when a path is modified. - */ - void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); - /** Some nodes/subpaths are removed. - */ - void pwd2Subtract(pwd2sb const &A); - /** Append nodes/subpaths to current pointwise - */ - void pwd2Append(pwd2sb const &A, Satellite const &S); - /** Send a subpath to end and update satellites - */ - void subpathToBack(size_t subpath); - /** Reverse a subpath and update satellites - */ - void subpathReverse(size_t start, size_t end); - /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - */ - void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + PwD2SBasis getPwd2() const; + Geom::Pathvector getPV() const; + void setPwd2(PwD2SBasis const &pwd2_in); + Satelites getSatellites(); + size_t getTotalSatellites(); + void setSatellites(Satelites const &sats); + void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); + //Fired when a path is modified. + void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); + //Recalculate satellites + void insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); + //Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. private: - pwd2sb _pwd2; + PwD2SBasis _pwd2; Geom::PathVector _pathvector; - std::vector _satellites; + Satelites _satellites; }; #endif //SEEN_POINTWISE_H diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 615106dd93..027497d78d 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -32,7 +32,6 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), is_time(false), - active(false), has_mirror(false), hidden(true), amount(0.0), @@ -54,7 +53,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) return 0; } - //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); double t = 0; double length_part = curve_in.length(); @@ -63,9 +61,8 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) t = A / length_part; } } else if (!curve_in.isLineSegment()) { - std::vector t_roots = roots(Geom::arcLengthSb(d2_in) - A); - if (t_roots.size() > 0) { + if (!t_roots.empty()) { t = t_roots[0]; } } @@ -82,8 +79,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) return 0; } - //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- - Geom::D2 d2_in = curve_in.toSBasis(); double s = 0; double length_part = curve_in.length(); if (A > length_part || curve_in.isLineSegment()) { @@ -91,6 +86,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) } else if (!curve_in.isLineSegment()) { Geom::Curve *curve = curve_in.portion(0.0, A); s = curve->length(); + delete curve; } return s; } @@ -105,7 +101,7 @@ double Satellite::radToLen( double len = 0; Geom::D2 d2_in = curve_in.toSBasis(); Geom::D2 d2_out = curve_out.toSBasis(); - Geom::Piecewise > offset_curve0 = + Geom::Piecewise > offset_curve0 = Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); Geom::Piecewise > offset_curve1 = @@ -136,30 +132,28 @@ double Satellite::lenToRad( { double time_in = (previousSatellite).time(A, true, curve_in); double time_out = timeAtArcLength(A, curve_out); - Geom::Point startArcPoint = curve_in.pointAt(time_in); - Geom::Point endArcPoint = curve_out.pointAt(time_out); - Geom::Curve *knotCurve1 = curve_in.portion(0, time_in); - Geom::Curve *knotCurve2 = curve_out.portion(time_out, 1); - Geom::CubicBezier const *cubic1 = - dynamic_cast(&*knotCurve1); + Geom::Point start_arc_point = curve_in.pointAt(time_in); + Geom::Point end_arc_point = curve_out.pointAt(time_out); + Geom::Curve *knot_curve1 = curve_in.portion(0, time_in); + Geom::Curve *knot_curve2 = curve_out.portion(time_out, 1); + Geom::cubic_bezier const *cubic1 = dynamic_cast(&*knot_curve1); Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); + Geom::cubic_bezier const *cubic2 = dynamic_cast(&*knot_curve2); Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross(curve_in.pointAt(1) - startArcPoint, - endArcPoint - startArcPoint) < 0; - double distanceArc = + bool ccw_toggle = cross(curve_in.pointAt(1) - startArcPoint, + end_arc_point - startArcPoint) < 0; + double distance_arc = Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - double divisor = std::sin(angleBetween / 2.0); + double angle_between = angle_between(ray1, ray2, ccw_toggle); + double divisor = std::sin(angle_between / 2.0); if (divisor > 0) { - return distanceArc / divisor; + return distance_arc / divisor; } return 0; } @@ -167,12 +161,12 @@ double Satellite::lenToRad( /** * Get the time position of the satellite in curve_in */ -double Satellite::time(Geom::Curve const &curve_in, bool const I) const +double Satellite::time(Geom::Curve const &curve_in, bool inverse) const { double t = amount; if (!is_time) { - t = time(t, I, curve_in); - } else if (I) { + t = time(t, inverse, curve_in); + } else if (inverse) { t = 1-t; } if (t > 1) { @@ -182,18 +176,18 @@ double Satellite::time(Geom::Curve const &curve_in, bool const I) const } /**. - * Get the time from a length A in other curve, a bolean I gived to reverse time + * Get the time from a length A in other curve, a bolean inverse gived to reverse time */ -double Satellite::time(double A, bool const I, +double Satellite::time(double A, bool inverse, Geom::Curve const &curve_in) const { - if (A == 0 && I) { + if (A == 0 && inverse) { return 1; } - if (A == 0 && !I) { + if (A == 0 && !inverse) { return 0; } - if (!I) { + if (!inverse) { return timeAtArcLength(A, curve_in); } double length_part = curve_in.length(); @@ -216,19 +210,19 @@ double Satellite::arcDistance(Geom::Curve const &curve_in) const /** * Get the point position of the satellite */ -Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool const I) const +Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool inverse) const { - double t = time(curve_in, I); + double t = time(curve_in, inverse); return curve_in.pointAt(t); } /** * Set the position of the satellite from a gived point P */ -void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I) +void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse) { Geom::Curve * curve = const_cast(&curve_in); - if (I) { + if (inverse) { curve = curve->reverse(); } double A = Geom::nearest_time(p, *curve); diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 2369dddbd5..6cf891ec5b 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -39,10 +39,6 @@ public: { is_time = set_is_time; } - void setActive(bool set_active) - { - active = set_active; - } void setHasMirror(bool set_has_mirror) { has_mirror = set_has_mirror; @@ -69,20 +65,22 @@ public: double radToLen(double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out) const; - double time(Geom::Curve const &curve_in, bool const I = false) const; - double time(double A, bool const I, Geom::Curve const &curve_in) const; + double time(Geom::Curve const &curve_in, bool inverse = false) const; + double time(double A, bool inverse, Geom::Curve const &curve_in) const; double arcDistance(Geom::Curve const &curve_in) const; - void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I = false); - Geom::Point getPosition(Geom::Curve const &curve_in, bool const I = false) const; + void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse = false); + Geom::Point getPosition(Geom::Curve const &curve_in, bool inverse = false) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; SatelliteType satellite_type; + //The value stored could be a time value of the satellite in the curve ot a distance on the curve + //"is_time" tell is if is a time or lenght value bool is_time; - bool active; bool has_mirror; bool hidden; + //in "amount" we store the time or distance used in the satellite double amount; double angle; size_t steps; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 9563956239..bcab1c055a 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 638e8c6af3..a209971dde 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 9a0ebe2352..ab4a8eb4ee 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 0abcd4b9b4..0bbe39293b 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 66ed6344b8..7076a465fc 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 1615f33e2c..0000000000 --- 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/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp new file mode 100644 index 0000000000..9274a4aff9 --- /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/satellitearray.h b/src/live_effects/parameter/satellitesarray.h similarity index 85% rename from src/live_effects/parameter/satellitearray.h rename to src/live_effects/parameter/satellitesarray.h index bb8bf27c87..db3776ba38 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -1,5 +1,5 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H /* * Inkscape::LivePathEffectParameters @@ -30,9 +30,9 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatelliteArrayParam : public ArrayParam { +class SatellitesArrayParam : public ArrayArrayParam { public: - SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, + SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); @@ -67,8 +67,8 @@ protected: KnotHolder *knoth; private: - SatelliteArrayParam(const SatelliteArrayParam &); - SatelliteArrayParam &operator=(const SatelliteArrayParam &); + SatellitesArrayParam(const SatellitesArrayParam &); + SatellitesArrayParam &operator=(const SatellitesArrayParam &); SPKnotShapeType _knot_shape; SPKnotModeType _knot_mode; @@ -83,7 +83,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); + FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index, size_t subindex); virtual ~FilletChamferKnotHolderEntity() { _pparam->knoth = NULL; @@ -103,8 +103,9 @@ public: ; private: - SatelliteArrayParam *_pparam; + SatellitesArrayParam *_pparam; size_t _index; + size_t _subindex; }; } //namespace LivePathEffect -- GitLab From 07717a370b8efe6ddbb0c69d115bb063a2e7686a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 10 May 2016 23:16:49 +0200 Subject: [PATCH 082/121] Working with path updates (bzr r13645.1.130) --- src/helper/geom-pointwise.cpp | 63 ++-- src/helper/geom-pointwise.h | 12 +- src/helper/geom-satellite.cpp | 22 +- 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 +- .../parameter/satellitesarray.cpp | 310 +++++++++--------- src/live_effects/parameter/satellitesarray.h | 2 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 2 +- 10 files changed, 353 insertions(+), 360 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a96b7cbda7..a7082ec241 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -15,42 +15,41 @@ */ #include - PwD2SBasis Pointwise::getPwd2() const { return _pwd2; } -Geom::Pathvector Pointwise::getPV() const +Geom::PathVector Pointwise::getPV() const { return _pathvector; } void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) { - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); _pwd2 = pwd2_in; + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); } -Satelites Pointwise::getSatellites() +Satellites Pointwise::getSatellites() { return _satellites; } size_t Pointwise::getTotalSatellites() { - size_t counter = 0 - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { counter++; } } return counter; } -void Pointwise::setSatellites(Satelites const &sats) +void Pointwise::setSatellites(Satellites const &satellites) { - _satellites = sats; + _satellites = satellites; } void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) @@ -64,7 +63,7 @@ void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector cons void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) { - Satelites sats; + Satellites satellites; Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); Geom::PathVector old_pathv = _pathvector; _pathvector.clear(); @@ -74,11 +73,8 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) for (size_t i = 0; i < new_pathv.size(); i++) { bool match = false; for (size_t j = 0; j < old_pathv.size(); j++) { - std::vector subpath_satellites; if ( new_pathv[i] == old_pathv[j]){ - _pathvector.push_back(old_pathv[j]; - sats.push_back(_satellites[j]); - _satellites.erase(_satellites.begin() + j); + satellites.push_back(_satellites[j]); old_pathv.erase(old_pathv.begin() + j); new_pathv.erase(new_pathv.begin() + i); match = true; @@ -86,12 +82,11 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) } } if (!match && new_size > old_increments){ - _pathvector.push_back(new_pathv[i]); - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size(); k++) { + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); } - sats.push_back(subpath_satellites); + satellites.push_back(subpath_satellites); old_increments ++; } } @@ -99,30 +94,37 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) //we asume not change the order of subpaths when remove or add nodes to existing subpaths for (size_t l = 0; l < old_pathv.size(); l++) { //we assume we only can delete or add nodes not a mix of both + std::vector subpath_satellites; if (old_pathv[l].size() > new_pathv[l].size()){ //erase nodes for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { - _satellites[l].erase(_satellites.begin() + m); + if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { + subpath_satellites.push_back(_satellites[l][m]); } } - } else if (old_pathv[l].size() > new_pathv[l].size()) { + if (!old_pathv[l].closed() && + are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) + { + subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); + } + } else if (old_pathv[l].size() < new_pathv[l].size()) { //add nodes for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { - _satellites[l].insert(_satellites.begin() + m, S); + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { + _satellites[l].insert(_satellites[l].begin() + m, S); } } + if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { + _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); + } } else { //never happends } - sats.push_back(_satellites[l]); - _pathvector.push_back(new_pathv[l]); - + satellites.push_back(subpath_satellites); } } setPwd2(A); - setSatellites(sats); + setSatellites(satellites); } void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) @@ -136,15 +138,14 @@ void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector size_t counter_added = 0; for (size_t i = 0; i < B.size(); i++) { size_t counter = 0; - if (B[i]->empty()) { + if (B[i].empty()) { continue; } - for (size_t j = 0; j < B[i].size(); j++) { - if ((B[i][j].isDegenerate() && counter_added < satellite_gap) { + for (size_t j = 0; j < B[i].size_closed(); j++) { + if (B[i][j].isDegenerate() && counter_added < satellite_gap) { counter_added++; _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); } - ++curve_it1; counter++; } } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 4c2ec79570..fa03a5db79 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -28,16 +28,16 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve */ -typedef Geom::Piecewise > PwD2SBasisasis; -typedef std::vector< Satelites > Satelites; +typedef Geom::Piecewise > PwD2SBasis; +typedef std::vector > Satellites; class Pointwise { public: PwD2SBasis getPwd2() const; - Geom::Pathvector getPV() const; + Geom::PathVector getPV() const; void setPwd2(PwD2SBasis const &pwd2_in); - Satelites getSatellites(); + Satellites getSatellites(); size_t getTotalSatellites(); - void setSatellites(Satelites const &sats); + void setSatellites(Satellites const &satellites); void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); //Fired when a path is modified. void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); @@ -48,7 +48,7 @@ public: private: PwD2SBasis _pwd2; Geom::PathVector _pathvector; - Satelites _satellites; + Satellites _satellites; }; #endif //SEEN_POINTWISE_H diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 027497d78d..2672a571ba 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -136,22 +136,22 @@ double Satellite::lenToRad( Geom::Point end_arc_point = curve_out.pointAt(time_out); Geom::Curve *knot_curve1 = curve_in.portion(0, time_in); Geom::Curve *knot_curve2 = curve_out.portion(time_out, 1); - Geom::cubic_bezier const *cubic1 = dynamic_cast(&*knot_curve1); - Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knot_curve1); + Geom::Ray ray1(start_arc_point, curve_in.pointAt(1)); if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); + ray1.setPoints((*cubic1)[2], start_arc_point); } - Geom::cubic_bezier const *cubic2 = dynamic_cast(&*knot_curve2); - Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knot_curve2); + Geom::Ray ray2(curve_out.pointAt(0), end_arc_point); if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); + ray2.setPoints(end_arc_point, (*cubic2)[1]); } - bool ccw_toggle = cross(curve_in.pointAt(1) - startArcPoint, - end_arc_point - startArcPoint) < 0; + bool ccw_toggle = cross(curve_in.pointAt(1) - start_arc_point, + end_arc_point - start_arc_point) < 0; double distance_arc = - Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); - double angle_between = angle_between(ray1, ray2, ccw_toggle); - double divisor = std::sin(angle_between / 2.0); + Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)); + double angle = angle_between(ray1, ray2, ccw_toggle); + double divisor = std::sin(angle / 2.0); if (divisor > 0) { return distance_arc / divisor; } diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index a1aa811a98..64364c88c6 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 bcab1c055a..ab1cf41e39 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 0bbe39293b..c9e2d65639 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 7076a465fc..64d01650c7 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 9274a4aff9..9f14a1d5bf 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 db3776ba38..9a9ec4a88b 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, diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index f982db2861..105cafe681 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.h @@ -10,7 +10,7 @@ #include <2geom/point.h> #include -#include "live_effects/parameter/satellitearray.h" +#include "live_effects/parameter/satellitesarray.h" class SPDesktop; -- GitLab From b03cc6d03c9cfa57ebee8c70412e96c5d92f4f83 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 May 2016 22:27:45 +0200 Subject: [PATCH 083/121] pre-remove of subpath update satellites (bzr r13645.1.132) --- src/helper/geom-pointwise.cpp | 147 +++++++++--------- src/live_effects/lpe-fillet-chamfer.cpp | 28 ++-- .../parameter/satellitesarray.cpp | 1 + 3 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a7082ec241..1fbed612cc 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -54,11 +54,13 @@ void Pointwise::setSatellites(Satellites const &satellites) void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { - if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { - recalculatePwD2(A, S); - } else { - insertDegenerateSatellites(A, B, S); - } +//Remove subpath update for this version of fillet chamfer +// if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { +// recalculatePwD2(A, S); +// } else { +// //insertDegenerateSatellites(A, B, S); +// } + recalculatePwD2(A, S); } void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) @@ -69,7 +71,7 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) _pathvector.clear(); size_t new_size = new_pathv.size(); size_t old_size = old_pathv.size(); - size_t old_increments = old_size; +// size_t old_increments = old_size; for (size_t i = 0; i < new_pathv.size(); i++) { bool match = false; for (size_t j = 0; j < old_pathv.size(); j++) { @@ -81,76 +83,79 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) break; } } - if (!match && new_size > old_increments){ - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); - } - satellites.push_back(subpath_satellites); - old_increments ++; - } - } - if (new_size == old_size) { - //we asume not change the order of subpaths when remove or add nodes to existing subpaths - for (size_t l = 0; l < old_pathv.size(); l++) { - //we assume we only can delete or add nodes not a mix of both - std::vector subpath_satellites; - if (old_pathv[l].size() > new_pathv[l].size()){ - //erase nodes - for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { - subpath_satellites.push_back(_satellites[l][m]); - } - } - if (!old_pathv[l].closed() && - are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) - { - subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); - } - } else if (old_pathv[l].size() < new_pathv[l].size()) { - //add nodes - for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { - _satellites[l].insert(_satellites[l].begin() + m, S); - } - } - if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { - _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); - } - } else { - //never happends - } - satellites.push_back(subpath_satellites); + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); } + satellites.push_back(subpath_satellites); } - setPwd2(A); - setSatellites(satellites); -} -void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -{ - size_t size_A = A.size(); - size_t size_B = B.curveCount(); - size_t satellite_gap = size_B - size_A; - if (satellite_gap == 0) { - return; - } - size_t counter_added = 0; - for (size_t i = 0; i < B.size(); i++) { - size_t counter = 0; - if (B[i].empty()) { - continue; - } - for (size_t j = 0; j < B[i].size_closed(); j++) { - if (B[i][j].isDegenerate() && counter_added < satellite_gap) { - counter_added++; - _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); - } - counter++; - } - } +// if (new_size == old_size) { +// //TODO: ensure select remaining old_path subpath with the updated subpath remaining in new_path +// //This cam make bug with reversed paths or reorderer ones. +// for (size_t l = 0; l < old_pathv.size(); l++) { +// //we assume we only can delete or add nodes not a mix of both +// std::vector subpath_satellites; +// if (old_pathv[l].size() > new_pathv[l].size()){ +// //erase nodes +// size_t erased = 0; +// for (size_t m = 0; m < old_pathv[l].size(); m++) { +// if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m - erased].initialPoint())) { +// subpath_satellites.push_back(_satellites[l][m]); +// } else { +// erased++; +// } +// } +// if (!old_pathv[l].closed() && +// are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) +// { +// subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); +// } +// } else if (old_pathv[l].size() < new_pathv[l].size()) { +// //add nodes +// for (size_t m = 0; m < old_pathv[l].size(); m++) { +// if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { +// _satellites[l].insert(_satellites[l].begin() + m, S); +// } +// } +// if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { +// _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); +// } +// } else { +// //never happends +// } +// satellites.push_back(subpath_satellites); +// } +// } setPwd2(A); + setSatellites(satellites); } +//Remove subpath update for this version of fillet chamfer +//void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) +//{ +// size_t size_A = A.size(); +// size_t size_B = B.curveCount(); +// size_t satellite_gap = size_B - size_A; +// if (satellite_gap == 0) { +// return; +// } +// size_t counter_added = 0; +// for (size_t i = 0; i < B.size(); i++) { +// size_t counter = 0; +// if (B[i].empty()) { +// continue; +// } +// for (size_t j = 0; j < B[i].size_closed(); j++) { +// if (B[i][j].isDegenerate() && counter_added < satellite_gap) { +// counter_added++; +// _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); +// } +// counter++; +// } +// } +// setPwd2(A); +//} /* Local Variables: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ab1cf41e39..7379efcf6b 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 9f14a1d5bf..8e6ba0b416 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()); -- GitLab From c103f187da67d1e2a9d31f45248a415945b1e5c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 May 2016 22:09:34 +0200 Subject: [PATCH 084/121] Fiximg pointwise (bzr r13645.1.133) --- src/helper/geom-pointwise.cpp | 32 ++++++++++++++++++------- src/live_effects/lpe-fillet-chamfer.cpp | 14 +++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 1fbed612cc..a4e5530a41 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -77,18 +77,32 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) for (size_t j = 0; j < old_pathv.size(); j++) { if ( new_pathv[i] == old_pathv[j]){ satellites.push_back(_satellites[j]); - old_pathv.erase(old_pathv.begin() + j); - new_pathv.erase(new_pathv.begin() + i); +// old_pathv.erase(old_pathv.begin() + j); +// new_pathv.erase(new_pathv.begin() + i); + + std::cout << "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmatch\n"; + _pathvector.push_back(new_pathv[i]); match = true; break; } } - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); + if (!match && new_size > old_size) { + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); + } + _pathvector.push_back(new_pathv[i]); + satellites.push_back(subpath_satellites); + } else if(!match) { + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); + } + _pathvector.push_back(new_pathv[i]); + satellites.push_back(subpath_satellites); } - satellites.push_back(subpath_satellites); } // if (new_size == old_size) { @@ -128,8 +142,10 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) // satellites.push_back(subpath_satellites); // } // } - setPwd2(A); + Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(_pathvector), 0.01);; + setPwd2(pwd2); setSatellites(satellites); + std::cout << _satellites.size() << "ssssssssssssssssssssss\n"; } //Remove subpath update for this version of fillet chamfer //void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7379efcf6b..6ecffb388f 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++; -- GitLab From 4c145e43f8ab8d8040fb2fa42309f7bd400f6349 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 May 2016 23:52:45 +0200 Subject: [PATCH 085/121] Fixing pointwise (bzr r13645.1.135) --- src/helper/geom-pointwise.cpp | 143 ++--------- src/helper/geom-pointwise.h | 24 +- 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 +- .../parameter/satellitesarray.cpp | 231 ++++++++---------- src/live_effects/parameter/satellitesarray.h | 8 +- 8 files changed, 191 insertions(+), 382 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a4e5530a41..6ed6e8f839 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -15,20 +15,14 @@ */ #include -PwD2SBasis Pointwise::getPwd2() const -{ - return _pwd2; -} - -Geom::PathVector Pointwise::getPV() const +Geom::PathVector Pointwise::getPathVector() const { return _pathvector; } -void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) +void Pointwise::setPathVector(Geom::PathVector pathv) { - _pwd2 = pwd2_in; - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + _pathvector = pathv; } Satellites Pointwise::getSatellites() @@ -36,6 +30,11 @@ Satellites Pointwise::getSatellites() return _satellites; } +void Pointwise::setSatellites(Satellites satellites) +{ + _satellites = satellites; +} + size_t Pointwise::getTotalSatellites() { size_t counter = 0; @@ -47,131 +46,19 @@ size_t Pointwise::getTotalSatellites() return counter; } -void Pointwise::setSatellites(Satellites const &satellites) -{ - _satellites = satellites; -} - -void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -{ -//Remove subpath update for this version of fillet chamfer -// if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { -// recalculatePwD2(A, S); -// } else { -// //insertDegenerateSatellites(A, B, S); -// } - recalculatePwD2(A, S); -} - -void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) +void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S) { Satellites satellites; - Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - Geom::PathVector old_pathv = _pathvector; - _pathvector.clear(); - size_t new_size = new_pathv.size(); - size_t old_size = old_pathv.size(); -// size_t old_increments = old_size; - for (size_t i = 0; i < new_pathv.size(); i++) { - bool match = false; - for (size_t j = 0; j < old_pathv.size(); j++) { - if ( new_pathv[i] == old_pathv[j]){ - satellites.push_back(_satellites[j]); -// old_pathv.erase(old_pathv.begin() + j); -// new_pathv.erase(new_pathv.begin() + i); - - std::cout << "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmatch\n"; - _pathvector.push_back(new_pathv[i]); - match = true; - break; - } - } - if (!match && new_size > old_size) { - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); - } - _pathvector.push_back(new_pathv[i]); - satellites.push_back(subpath_satellites); - } else if(!match) { - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); - } - _pathvector.push_back(new_pathv[i]); - satellites.push_back(subpath_satellites); + for (size_t i = 0; i < pathv.size(); i++) { + std::vector subpath_satellites; + for (size_t k = 0; k < pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); } + satellites.push_back(subpath_satellites); } - -// if (new_size == old_size) { -// //TODO: ensure select remaining old_path subpath with the updated subpath remaining in new_path -// //This cam make bug with reversed paths or reorderer ones. -// for (size_t l = 0; l < old_pathv.size(); l++) { -// //we assume we only can delete or add nodes not a mix of both -// std::vector subpath_satellites; -// if (old_pathv[l].size() > new_pathv[l].size()){ -// //erase nodes -// size_t erased = 0; -// for (size_t m = 0; m < old_pathv[l].size(); m++) { -// if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m - erased].initialPoint())) { -// subpath_satellites.push_back(_satellites[l][m]); -// } else { -// erased++; -// } -// } -// if (!old_pathv[l].closed() && -// are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) -// { -// subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); -// } -// } else if (old_pathv[l].size() < new_pathv[l].size()) { -// //add nodes -// for (size_t m = 0; m < old_pathv[l].size(); m++) { -// if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { -// _satellites[l].insert(_satellites[l].begin() + m, S); -// } -// } -// if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { -// _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); -// } -// } else { -// //never happends -// } -// satellites.push_back(subpath_satellites); -// } -// } - Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(_pathvector), 0.01);; - setPwd2(pwd2); + setPathVector(pathv); setSatellites(satellites); - std::cout << _satellites.size() << "ssssssssssssssssssssss\n"; } -//Remove subpath update for this version of fillet chamfer -//void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -//{ -// size_t size_A = A.size(); -// size_t size_B = B.curveCount(); -// size_t satellite_gap = size_B - size_A; -// if (satellite_gap == 0) { -// return; -// } -// size_t counter_added = 0; -// for (size_t i = 0; i < B.size(); i++) { -// size_t counter = 0; -// if (B[i].empty()) { -// continue; -// } -// for (size_t j = 0; j < B[i].size_closed(); j++) { -// if (B[i][j].isDegenerate() && counter_added < satellite_gap) { -// counter_added++; -// _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); -// } -// counter++; -// } -// } -// setPwd2(A); -//} /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index fa03a5db79..047de8dd35 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -18,35 +18,23 @@ #define SEEN_POINTWISE_H #include -#include <2geom/sbasis.h> -#include <2geom/sbasis-2d.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> +#include <2geom/pathvector.h> #include /** - * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * @brief Pointwise a class to manage a vector of satellites per curve */ -typedef Geom::Piecewise > PwD2SBasis; typedef std::vector > Satellites; class Pointwise { public: - PwD2SBasis getPwd2() const; - Geom::PathVector getPV() const; - void setPwd2(PwD2SBasis const &pwd2_in); + Geom::PathVector getPathVector() const; + void setPathVector(Geom::PathVector pathv); Satellites getSatellites(); size_t getTotalSatellites(); - void setSatellites(Satellites const &satellites); - void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); - //Fired when a path is modified. - void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); - //Recalculate satellites - void insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); - //Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - + void setSatellites(Satellites satellites); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S); private: - PwD2SBasis _pwd2; Geom::PathVector _pathvector; Satellites _satellites; }; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ecffb388f..f8f17fccfd 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 a209971dde..7603c7de44 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 c9e2d65639..3d2e7773d5 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 64d01650c7..8a9d72fe30 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 8e6ba0b416..be4eb67327 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 9a9ec4a88b..dcd82ada59 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; }; -- GitLab From 159439c26042b7c69aa9c33ce9484e4dfd00372a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 May 2016 11:48:51 +0200 Subject: [PATCH 086/121] Fixing pointwise (bzr r13645.1.137) --- src/live_effects/lpe-fillet-chamfer.cpp | 6 +++- src/live_effects/parameter/array.h | 32 +++++++++---------- .../parameter/satellitesarray.cpp | 10 ++++++ src/live_effects/parameter/satellitesarray.h | 5 +-- src/ui/tool/multi-path-manipulator.cpp | 10 +++--- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f8f17fccfd..9c633ea576 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 8a9d72fe30..9802abc2e8 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 be4eb67327..14660acc44 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 dcd82ada59..0cebb9cb43 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; diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 857f954ce2..9ec6f733f9 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -330,13 +330,13 @@ void MultiPathManipulator::insertNodes() { if (_selection.empty()) return; invokeForAll(&PathManipulator::insertNodes); - _done(_("Add nodes"), true); + _done(_("Add nodes")); } void MultiPathManipulator::insertNodesAtExtrema(ExtremumType extremum) { if (_selection.empty()) return; invokeForAll(&PathManipulator::insertNodeAtExtremum, extremum); - _done(_("Add extremum nodes"), true); + _done(_("Add extremum nodes")); } void MultiPathManipulator::insertNode(Geom::Point pt) @@ -351,7 +351,7 @@ void MultiPathManipulator::duplicateNodes() { if (_selection.empty()) return; invokeForAll(&PathManipulator::duplicateNodes); - _done(_("Duplicate nodes"), true); + _done(_("Duplicate nodes")); } void MultiPathManipulator::joinNodes() @@ -491,10 +491,10 @@ void MultiPathManipulator::reverseSubpaths() { if (_selection.empty()) { invokeForAll(&PathManipulator::reverseSubpaths, false); - _done("Reverse subpaths", true); + _done("Reverse subpaths"); } else { invokeForAll(&PathManipulator::reverseSubpaths, true); - _done("Reverse selected subpaths", true); + _done("Reverse selected subpaths"); } } -- GitLab From c511141b70995ca7295df4ae244d7cc626f6ab73 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 May 2016 23:06:15 +0200 Subject: [PATCH 087/121] Update to refresh knots (bzr r13645.1.139) --- src/helper/geom-pointwise.cpp | 2 +- src/helper/geom-pointwise.h | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 12 +++++++----- src/live_effects/parameter/array.cpp | 18 +++++++++--------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6ed6e8f839..5531bb8496 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -46,7 +46,7 @@ size_t Pointwise::getTotalSatellites() return counter; } -void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S) +void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; for (size_t i = 0; i < pathv.size(); i++) { diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 047de8dd35..5992344731 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,7 +33,7 @@ public: Satellites getSatellites(); size_t getTotalSatellites(); void setSatellites(Satellites satellites); - void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: Geom::PathVector _pathvector; Satellites _satellites; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 9c633ea576..fc31aa4473 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 3d2e7773d5..4e30379047 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++; -- GitLab From ff9ec25d3afc0453ead52d3da10b754637c8207f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 May 2016 20:25:20 +0200 Subject: [PATCH 088/121] Fixing pointwise (bzr r13645.1.141) --- src/live_effects/lpe-fillet-chamfer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index fc31aa4473..a291776b7a 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)."); } -- GitLab From 8d35486a82d04a28dc9f297147ad4666b34cde4a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 19:37:15 +0200 Subject: [PATCH 089/121] Fixing pointwise (bzr r13645.1.143) --- src/live_effects/lpe-fillet-chamfer.cpp | 39 ++++++------- .../parameter/satellitesarray.cpp | 56 ++++++++++--------- src/live_effects/parameter/satellitesarray.h | 4 +- src/ui/tool/path-manipulator.cpp | 1 - 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a291776b7a..6ec711de71 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 14660acc44..78f1a945f6 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 0cebb9cb43..c6893f595e 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; diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 9d479432b6..0d603ad1f7 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -12,7 +12,6 @@ #include "live_effects/lpe-powerstroke.h" #include "live_effects/lpe-bspline.h" -#include "live_effects/lpe-fillet-chamfer.h" #include #include #include -- GitLab From 634be67d2fa8aa07d25d96e10a3ad24fdfdcc80e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 20:44:19 +0200 Subject: [PATCH 090/121] Rename branch (bzr r13645.1.145) --- src/helper/CMakeLists.txt | 4 +- src/helper/Makefile_insert | 4 +- ...wise.cpp => geom-pathvectorsatellites.cpp} | 16 +++---- ...ointwise.h => geom-pathvectorsatellites.h} | 15 +++--- src/live_effects/lpe-fillet-chamfer.cpp | 48 +++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 4 +- .../parameter/satellitesarray.cpp | 28 +++++------ src/live_effects/parameter/satellitesarray.h | 8 ++-- 8 files changed, 63 insertions(+), 64 deletions(-) rename src/helper/{geom-pointwise.cpp => geom-pathvectorsatellites.cpp} (69%) rename src/helper/{geom-pointwise.h => geom-pathvectorsatellites.h} (76%) diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index aa99934b63..92709e4e94 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -14,7 +14,7 @@ set(helper_SRC geom.cpp geom-nodetype.cpp geom-pathstroke.cpp - geom-pointwise.cpp + geom-pathvectorsatellites.cpp geom-satellite.cpp gnome-utils.cpp pixbuf-ops.cpp @@ -34,7 +34,7 @@ set(helper_SRC geom-curves.h geom-nodetype.h geom-pathstroke.h - geom-pointwise.h + geom-pathvectorsatellites.h geom-satellite.h geom.h gnome-utils.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 54588d0ce6..6ba0efbfa3 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -14,8 +14,8 @@ ink_common_sources += \ helper/geom-nodetype.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ - helper/geom-pointwise.cpp \ - helper/geom-pointwise.h \ + helper/geom-pathvectorsatellites.cpp \ + helper/geom-pathvectorsatellites.h \ helper/geom-satellite.cpp \ helper/geom-satellite.h \ helper/gnome-utils.cpp \ diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pathvectorsatellites.cpp similarity index 69% rename from src/helper/geom-pointwise.cpp rename to src/helper/geom-pathvectorsatellites.cpp index 5531bb8496..a5207ab007 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof @@ -14,28 +14,28 @@ * This code is in public domain */ -#include -Geom::PathVector Pointwise::getPathVector() const +#include +Geom::PathVector PathVectorSatellites::getPathVector() const { return _pathvector; } -void Pointwise::setPathVector(Geom::PathVector pathv) +void PathVectorSatellites::setPathVector(Geom::PathVector pathv) { _pathvector = pathv; } -Satellites Pointwise::getSatellites() +Satellites PathVectorSatellites::getSatellites() { return _satellites; } -void Pointwise::setSatellites(Satellites satellites) +void PathVectorSatellites::setSatellites(Satellites satellites) { _satellites = satellites; } -size_t Pointwise::getTotalSatellites() +size_t PathVectorSatellites::getTotalSatellites() { size_t counter = 0; for (size_t i = 0; i < _satellites.size(); ++i) { @@ -46,7 +46,7 @@ size_t Pointwise::getTotalSatellites() return counter; } -void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) +void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; for (size_t i = 0; i < pathv.size(); i++) { diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pathvectorsatellites.h similarity index 76% rename from src/helper/geom-pointwise.h rename to src/helper/geom-pathvectorsatellites.h index 5992344731..72ecef38fd 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof @@ -14,32 +14,31 @@ * This code is in public domain */ -#ifndef SEEN_POINTWISE_H -#define SEEN_POINTWISE_H +#ifndef SEEN_PATHVECTORSATELLITES_H +#define SEEN_PATHVECTORSATELLITES_H #include #include <2geom/path.h> #include <2geom/pathvector.h> -#include /** - * @brief Pointwise a class to manage a vector of satellites per curve + * @brief PathVectorSatellites a class to manage a vector of satellites per curve */ typedef std::vector > Satellites; -class Pointwise { +class PathVectorSatellites { public: Geom::PathVector getPathVector() const; void setPathVector(Geom::PathVector pathv); Satellites getSatellites(); - size_t getTotalSatellites(); void setSatellites(Satellites satellites); + size_t getTotalSatellites(); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: Geom::PathVector _pathvector; Satellites _satellites; }; -#endif //SEEN_POINTWISE_H +#endif //SEEN_PATHVECTORSATELLITES_H /* Local Variables: mode:c++ diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ec711de71..56f7557bae 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 7603c7de44..62b8946608 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 78f1a945f6..45a6282e0b 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 c6893f595e..27e9dea6f8 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; }; -- GitLab From 5ad260d5810f6f8bb2cdea7186d0766091ad9b54 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 11 Jun 2016 17:32:56 +0200 Subject: [PATCH 091/121] Fixing satellites bug on erase (bzr r13645.1.146) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +-- .../parameter/satellitesarray.cpp | 19 +++++++++++++++++-- src/live_effects/parameter/satellitesarray.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 56f7557bae..b4eca69095 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 45a6282e0b..cb7d0df8f1 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 27e9dea6f8..c52d285412 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); -- GitLab From d84bbca17771ed1a2f680328adf14b30a4c66b77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 01:05:25 +0200 Subject: [PATCH 092/121] Fix the bug deleting satellites (bzr r13645.1.148) --- src/helper/geom-pathvectorsatellites.cpp | 13 + src/helper/geom-pathvectorsatellites.h | 1 + src/knotholder.h | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 82 +++--- src/live_effects/lpe-fillet-chamfer.h | 2 +- .../parameter/satellitesarray.cpp | 248 +++++++++--------- src/live_effects/parameter/satellitesarray.h | 13 +- 7 files changed, 192 insertions(+), 172 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index a5207ab007..c423c9b1bc 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -46,6 +46,19 @@ size_t PathVectorSatellites::getTotalSatellites() return counter; } +std::pair PathVectorSatellites::getIndexData(size_t index) +{ + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if (index == counter) { + return std::make_pair(i,j); + } + counter++; + } + } + return std::make_pair(0,0); +} void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 72ecef38fd..483611db56 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -32,6 +32,7 @@ public: Satellites getSatellites(); void setSatellites(Satellites satellites); size_t getTotalSatellites(); + std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: Geom::PathVector _pathvector; diff --git a/src/knotholder.h b/src/knotholder.h index f1bacebe5c..c8136da3f6 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -30,7 +30,8 @@ class Node; } namespace LivePathEffect { class PowerStrokePointArrayParamKnotHolderEntity; -class FilletPointArrayParamKnotHolderEntity; +class SatellitesArrayParam; +class FilletChamferKnotHolderEntity; } } @@ -63,7 +64,7 @@ public: friend class Inkscape::UI::ShapeEditor; // FIXME why? friend class Inkscape::LivePathEffect::PowerStrokePointArrayParamKnotHolderEntity; // why? - friend class Inkscape::LivePathEffect::FilletPointArrayParamKnotHolderEntity; // why? + friend class Inkscape::LivePathEffect::FilletChamferKnotHolderEntity; // why? protected: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b4eca69095..1d5c036baa 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 62b8946608..363a35d43b 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 cb7d0df8f1..e61aaf38df 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 c52d285412..a52bcef536 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 -- GitLab From 1b8a4e46125f60f7bbe497bde69a11b7b3153b00 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 12:09:57 +0200 Subject: [PATCH 093/121] Handle path add and remove nodes (bzr r13645.1.150) --- src/helper/geom-pathvectorsatellites.cpp | 40 +++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c423c9b1bc..625506b2fa 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -59,15 +59,47 @@ std::pair PathVectorSatellites::getIndexData(size_t index) } return std::make_pair(0,0); } + void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; + bool found = false; + //TODO evaluate fix on nodes at same position + size_t number_nodes = pathv.nodes().size(); + size_t previous_number_nodes = _pathvector.nodes().size(); for (size_t i = 0; i < pathv.size(); i++) { - std::vector subpath_satellites; - for (size_t k = 0; k < pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); + satellites.reserve(pathv.size()); + std::vector pathsatellites; + for (size_t j = 0; j < pathv[i].size_closed(); j++) { + satellites[i].reserve(pathv[i].size_closed()); + found = false; + for (size_t k = 0; k < _pathvector.size(); k++) { + for (size_t l = 0; l < _pathvector[k].size_closed(); l++) { + if ((l == _pathvector[k].size_closed() -1 && + j == pathv[i].size_closed() -1 && + Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j-1].finalPoint())) || + (l == _pathvector[k].size_closed() -1 && + Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j].finalPoint())) || + (j == pathv[i].size_closed() -1 && + Geom::are_near(_pathvector[k][l].finalPoint(), pathv[i][j-1].finalPoint())) || + (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) + { + pathsatellites.push_back(_satellites[k][l]); + std::cout << "dgsgdsgsdgsdgsdgsdgsdgsdgsdgsdgsd\n"; + found = true; + break; + } + } + if (found) { + break; + } + } + + if (found == false && previous_number_nodes < number_nodes) { + pathsatellites.push_back(S); + } } - satellites.push_back(subpath_satellites); + satellites.push_back(pathsatellites); } setPathVector(pathv); setSatellites(satellites); -- GitLab From 7e1183de6ed51ff730915fe936e2bb607dd72f33 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 16:33:27 +0200 Subject: [PATCH 094/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1d5c036baa..48e68d3669 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 363a35d43b..420403b70b 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 e61aaf38df..db7cf80c00 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 a52bcef536..30b1db6c1c 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; -- GitLab From e40990e3b9c391cdded31f28bb8f8d448fd1d361 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 17:27:07 +0200 Subject: [PATCH 095/121] Handle both directions on knot reposition (bzr r13645.1.154) --- .../parameter/satellitesarray.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index db7cf80c00..18e1bd4de4 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); -- GitLab From 73f078b27b669c941651ecf14a3119ae491ccabf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:58:55 +0200 Subject: [PATCH 096/121] Fix 90% of tweenk review (bzr r13645.1.155) --- src/helper/geom-pathvectorsatellites.cpp | 111 +++++- src/helper/geom-pathvectorsatellites.h | 11 +- src/helper/geom-satellite.cpp | 58 +-- src/helper/geom-satellite.h | 13 +- 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 + .../parameter/satellitesarray.cpp | 51 ++- src/live_effects/parameter/satellitesarray.h | 5 +- src/ui/tools/node-tool.cpp | 10 +- 14 files changed, 362 insertions(+), 341 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 625506b2fa..c56887f53d 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage satellites -per node extra data- in a pathvector */ /* * Authors: * Jabiertxof @@ -60,6 +60,115 @@ std::pair PathVectorSatellites::getIndexData(size_t index) return std::make_pair(0,0); } +void PathVectorSatellites::setSelected(std::vector selected) +{ + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if(find (selected.begin(), selected.end(), counter) != selected.end()){ + _satellites[i][j].setSelected(true); + } else { + _satellites[i][j].setSelected(false); + } + counter++; + } + } +} + +void PathVectorSatellites::updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected) +{ + 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) { + if (_satellites[i][j].selected) { + _satellites[i][j].steps = steps; + } + } else { + _satellites[i][j].steps = steps; + } + } + } +} + +void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, + bool use_knot_distance, bool flexible) +{ + double power = 0; + if (!flexible) { + power = radius; + } else { + power = radius / 100; + } + 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 && _pathvector[i].closed()){ + previous_index = _pathvector[i].size() - 1; + } else if(!_pathvector[i].closed() || j != 0) { + previous_index = j - 1; + } + if (!_pathvector[i].closed() && j == 0) { + _satellites[i][j].amount = 0; + continue; + } + if (_pathvector[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 = _pathvector[i].pointAt(j); + if (_satellites[i][j].selected || !only_selected) { + if (!use_knot_distance && !flexible) { + if(previous_index) { + _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); + } else { + _satellites[i][j].amount = 0.0; + } + } else { + _satellites[i][j].amount = power; + } + } + } + } +} + +void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, + bool only_selected) +{ + 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 (_pathvector[i].size() == j) { + if (!only_selected) { + _satellites[i][j].satellite_type = satellitetype; + } + continue; + } + if (only_selected) { + Geom::Point satellite_point = _pathvector[i].pointAt(j); + if (_satellites[i][j].selected) { + _satellites[i][j].satellite_type = satellitetype; + } + } else { + _satellites[i][j].satellite_type = satellitetype; + } + } + } +} + void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 483611db56..4a020f5536 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -1,6 +1,6 @@ /** * \file - * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage satellites -per node extra data- in a pathvector */ /* * Authors: * Jabiertxof @@ -21,10 +21,8 @@ #include <2geom/path.h> #include <2geom/pathvector.h> -/** - * @brief PathVectorSatellites a class to manage a vector of satellites per curve - */ typedef std::vector > Satellites; +///@brief PathVectorSatellites a class to manage satellites in a pathvector class PathVectorSatellites { public: Geom::PathVector getPathVector() const; @@ -32,6 +30,11 @@ public: Satellites getSatellites(); void setSatellites(Satellites satellites); size_t getTotalSatellites(); + void setSelected(std::vector selected); + void updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected); + void updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, + bool use_knot_distance, bool flexible); + void updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected); std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 2672a571ba..1242c9aafd 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Satellite a per ?node/curve holder of data. + * \brief Satellite a per node holder of data. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -23,15 +23,14 @@ #include #endif -/** - * @brief Satellite a per ?node/curve holder of data. - */ +///@brief Satellite a per node holder of data. Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), is_time(false), + selected(false), has_mirror(false), hidden(true), amount(0.0), @@ -41,12 +40,8 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} -/** - * Calculate the time in curve_in with a size of A - * TODO: find a better place to it - */ - - +///Calculate the time in curve_in with a size of A +//TODO: find a better place to it double timeAtArcLength(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { @@ -69,10 +64,8 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) return t; } -/** - * Calculate the size in curve_in with a point at A - * TODO: find a better place to it - */ +///Calculate the size in curve_in with a point at A +//TODO: find a better place to it double arcLengthAt(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { @@ -91,9 +84,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) return s; } -/** - * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve - */ +///Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve double Satellite::radToLen( double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out) const @@ -122,9 +113,7 @@ double Satellite::radToLen( return len; } -/** -* Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer -*/ +///Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer double Satellite::lenToRad( double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out, @@ -158,9 +147,7 @@ double Satellite::lenToRad( return 0; } -/** - * Get the time position of the satellite in curve_in - */ +///Get the time position of the satellite in curve_in double Satellite::time(Geom::Curve const &curve_in, bool inverse) const { double t = amount; @@ -175,9 +162,7 @@ double Satellite::time(Geom::Curve const &curve_in, bool inverse) const return t; } -/**. - * Get the time from a length A in other curve, a bolean inverse gived to reverse time - */ +///Get the time from a length A in other curve, a bolean inverse gived to reverse time double Satellite::time(double A, bool inverse, Geom::Curve const &curve_in) const { @@ -195,9 +180,7 @@ double Satellite::time(double A, bool inverse, return timeAtArcLength(A, curve_in); } -/** - * Get the length of the satellite in curve_in - */ +///Get the length of the satellite in curve_in double Satellite::arcDistance(Geom::Curve const &curve_in) const { double s = amount; @@ -207,18 +190,14 @@ double Satellite::arcDistance(Geom::Curve const &curve_in) const return s; } -/** - * Get the point position of the satellite - */ +///Get the point position of the satellite Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool inverse) const { double t = time(curve_in, inverse); return curve_in.pointAt(t); } -/** - * Set the position of the satellite from a gived point P - */ +///Set the position of the satellite from a gived point P void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse) { Geom::Curve * curve = const_cast(&curve_in); @@ -232,9 +211,8 @@ void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bo amount = A; } -/** - * Map a satellite type with gchar - */ + +///Map a satellite type with gchar void Satellite::setSatelliteType(gchar const *A) { std::map gchar_map_to_satellite_type = @@ -245,9 +223,7 @@ void Satellite::setSatelliteType(gchar const *A) } } -/** - * Map a gchar with satelliteType - */ +///Map a gchar with satelliteType gchar const *Satellite::getSatelliteTypeGchar() const { std::map satellite_type_to_gchar_map = diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 6cf891ec5b..a4d63d66e6 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,6 +1,6 @@ /** * \file - * \brief Satellite a per ?node/curve holder of data. + * \brief Satellite a per node holder of data. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -25,7 +25,7 @@ enum SatelliteType { INVALID_SATELLITE // Invalid Satellite }; /** - * @brief Satellite a per ?node/curve holder of data. + * @brief Satellite a per node holder of data. */ class Satellite { @@ -39,6 +39,10 @@ public: { is_time = set_is_time; } + void setSelected(bool set_selected) + { + selected = set_selected; + } void setHasMirror(bool set_has_mirror) { has_mirror = set_has_mirror; @@ -75,9 +79,10 @@ public: void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; SatelliteType satellite_type; - //The value stored could be a time value of the satellite in the curve ot a distance on the curve + //The value stored could be a time value of the satellite in the curve or a lenght of distance to the node from the satellite //"is_time" tell is if is a time or lenght value bool is_time; + bool selected; bool has_mirror; bool hidden; //in "amount" we store the time or distance used in the satellite @@ -85,7 +90,7 @@ public: double angle; size_t steps; }; -//cache_limit never called as 1 + double timeAtArcLength(double const A, Geom::Curve const &curve_in); double arcLengthAt(double const A, Geom::Curve const &curve_in); diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 0a78b199ec..f60d628f61 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 898e089b72..1f08a2bae5 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 48e68d3669..83baab1d13 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 420403b70b..bd0b74b51d 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 1cd59b7fa6..3c4ce07086 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 4e30379047..28867def2a 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 9802abc2e8..9204ede1f6 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 18e1bd4de4..2f5cea7b5c 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 30b1db6c1c..64bc934c8d 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, diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 23aaf6bb11..60d4c807f9 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -292,15 +292,15 @@ void NodeTool::update_helperpath () { if (SP_IS_LPE_ITEM(selection->singleItem())) { Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { - Inkscape::UI::ControlPointSelection::Set &selectionNodes = _selected_nodes->allPoints(); - std::vector selectedNodesPositions; - for (Inkscape::UI::ControlPointSelection::Set::iterator i = selectionNodes.begin(); i != selectionNodes.end(); ++i) { + Inkscape::UI::ControlPointSelection::Set &selection_nodes = _selected_nodes->allPoints(); + std::vector selected_nodes_positions; + for (Inkscape::UI::ControlPointSelection::Set::iterator i = selection_nodes.begin(); i != selection_nodes.end(); ++i) { if ((*i)->selected()) { Inkscape::UI::Node *n = dynamic_cast(*i); - selectedNodesPositions.push_back(n->position()); + selected_nodes_positions.push_back(n->position()); } } - lpe->setSelectedNodePoints(selectedNodesPositions); + lpe->setSelectedNodePoints(selected_nodes_positions); lpe->setCurrentZoom(this->desktop->current_zoom()); SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); -- GitLab From 2c544b51a588c8874b5b5f9a5e1e33d591972b15 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 14 Jun 2016 23:44:32 +0200 Subject: [PATCH 097/121] 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 ++-- .../parameter/satellitesarray.cpp | 20 +++++++++---------- src/live_effects/parameter/satellitesarray.h | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 83baab1d13..ef5f8f0a5e 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 bd0b74b51d..8a3701f7db 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 2f5cea7b5c..c0141ddfad 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 64bc934c8d..5b2d8a7998 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; -- GitLab From c631289820725ebd027571ec34ae2a1540cc3713 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 10:33:51 +0200 Subject: [PATCH 098/121] 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(-) diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ef5f8f0a5e..f2ed8d4d8e 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 8a3701f7db..35e9028f3c 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(); -- GitLab From c5f642fbd66ccb150d361d2861d0b1baa744dcba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 15:07:51 +0200 Subject: [PATCH 099/121] Pre fixing selected points (bzr r13645.1.161) --- src/helper/geom-pathvectorsatellites.cpp | 7 ++- 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 +- .../parameter/satellitesarray.cpp | 45 +++++++++------- .../dialog/lpe-fillet-chamfer-properties.cpp | 7 +-- src/ui/tools/node-tool.cpp | 6 +-- 8 files changed, 80 insertions(+), 58 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c56887f53d..e80d812d7c 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -63,11 +63,16 @@ std::pair PathVectorSatellites::getIndexData(size_t index) void PathVectorSatellites::setSelected(std::vector selected) { size_t counter = 0; + for (size_t h = 0; h < selected.size(); ++h) { + std::cout << selected[h] << "vec\n"; + } for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { if(find (selected.begin(), selected.end(), counter) != selected.end()){ + std::cout << counter << "true\n"; _satellites[i][j].setSelected(true); } else { + std::cout << "false\n"; _satellites[i][j].setSelected(false); } counter++; @@ -171,6 +176,7 @@ void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { + return; Satellites satellites; bool found = false; //TODO evaluate fix on nodes at same position @@ -194,7 +200,6 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) { pathsatellites.push_back(_satellites[k][l]); - std::cout << "dgsgdsgsdgsdgsdgsdgsdgsdgsdgsdgsd\n"; found = true; break; } diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index f60d628f61..515aa26fc8 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 1f08a2bae5..3b02b14d44 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 f2ed8d4d8e..7a663614b0 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 35e9028f3c..134886950b 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 c0141ddfad..71c69c6c52 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; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index c86fc4a209..098a84edfc 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -117,7 +117,8 @@ FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() } void FilletChamferPropertiesDialog::showDialog( - SPDesktop *desktop, double _amount, + SPDesktop *desktop, + double _amount, const Inkscape::LivePathEffect:: FilletChamferKnotHolderEntity *pt, bool _use_distance, @@ -243,9 +244,9 @@ void FilletChamferPropertiesDialog::_setPt( } -void FilletChamferPropertiesDialog::_setAmount(double amm) +void FilletChamferPropertiesDialog::_setAmount(double amount) { - _amount = amm; + _amount = amount; } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 60d4c807f9..d02b8e6d33 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -293,14 +293,14 @@ void NodeTool::update_helperpath () { Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { Inkscape::UI::ControlPointSelection::Set &selection_nodes = _selected_nodes->allPoints(); - std::vector selected_nodes_positions; + std::vector selected_nodes_pos; for (Inkscape::UI::ControlPointSelection::Set::iterator i = selection_nodes.begin(); i != selection_nodes.end(); ++i) { if ((*i)->selected()) { Inkscape::UI::Node *n = dynamic_cast(*i); - selected_nodes_positions.push_back(n->position()); + selected_nodes_pos.push_back(n->position()); } } - lpe->setSelectedNodePoints(selected_nodes_positions); + lpe->setSelectedNodePoints(selected_nodes_pos); lpe->setCurrentZoom(this->desktop->current_zoom()); SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); -- GitLab From 38a1a4d45114a681408e763c3afec79f0bc21940 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 18:53:51 +0200 Subject: [PATCH 100/121] fixing bug moving nodes (bzr r13645.1.162) --- src/helper/geom-pathvectorsatellites.cpp | 1 - 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 +++++----- .../parameter/satellitesarray.cpp | 7 ++--- src/ui/tools/node-tool.cpp | 2 +- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index e80d812d7c..1f71a2e91b 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -176,7 +176,6 @@ void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { - return; Satellites satellites; bool found = false; //TODO evaluate fix on nodes at same position diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 515aa26fc8..7b36e30f92 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 3b02b14d44..ac83d9b756 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 1423e670a2..3fed11d5a1 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 7a663614b0..c9d3d4afdc 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 71c69c6c52..8c86f64ca6 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; } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index d02b8e6d33..6a1feb760e 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -300,7 +300,7 @@ void NodeTool::update_helperpath () { selected_nodes_pos.push_back(n->position()); } } - lpe->setSelectedNodePoints(selected_nodes_pos); + lpe->setSelectedNodes(selected_nodes_pos); lpe->setCurrentZoom(this->desktop->current_zoom()); SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); -- GitLab From 6820ee49d69cd419c5e8d3c9de74b0552758c842 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 00:58:42 +0200 Subject: [PATCH 101/121] Fixes when moves a path (bzr r13645.1.163) --- src/helper/geom-pathvectorsatellites.cpp | 26 +++++-------------- src/live_effects/effect.cpp | 13 +++++----- src/live_effects/lpe-fillet-chamfer.cpp | 24 ++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 1 + .../parameter/satellitesarray.cpp | 1 - src/ui/tools/node-tool.cpp | 9 ++++--- 6 files changed, 29 insertions(+), 45 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 1f71a2e91b..f72841b304 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -63,16 +63,11 @@ std::pair PathVectorSatellites::getIndexData(size_t index) void PathVectorSatellites::setSelected(std::vector selected) { size_t counter = 0; - for (size_t h = 0; h < selected.size(); ++h) { - std::cout << selected[h] << "vec\n"; - } for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { if(find (selected.begin(), selected.end(), counter) != selected.end()){ - std::cout << counter << "true\n"; _satellites[i][j].setSelected(true); } else { - std::cout << "false\n"; _satellites[i][j].setSelected(false); } counter++; @@ -182,23 +177,14 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector.nodes().size(); for (size_t i = 0; i < pathv.size(); i++) { - satellites.reserve(pathv.size()); - std::vector pathsatellites; + std::vector path_satellites; for (size_t j = 0; j < pathv[i].size_closed(); j++) { - satellites[i].reserve(pathv[i].size_closed()); found = false; for (size_t k = 0; k < _pathvector.size(); k++) { for (size_t l = 0; l < _pathvector[k].size_closed(); l++) { - if ((l == _pathvector[k].size_closed() -1 && - j == pathv[i].size_closed() -1 && - Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j-1].finalPoint())) || - (l == _pathvector[k].size_closed() -1 && - Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j].finalPoint())) || - (j == pathv[i].size_closed() -1 && - Geom::are_near(_pathvector[k][l].finalPoint(), pathv[i][j-1].finalPoint())) || - (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) + if (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint())) { - pathsatellites.push_back(_satellites[k][l]); + path_satellites.push_back(_satellites[k][l]); found = true; break; } @@ -208,11 +194,11 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa } } - if (found == false && previous_number_nodes < number_nodes) { - pathsatellites.push_back(S); + if (!found && previous_number_nodes < number_nodes) { + path_satellites.push_back(S); } } - satellites.push_back(pathsatellites); + satellites.push_back(path_satellites); } setPathVector(pathv); setSatellites(satellites); diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 7b36e30f92..5ac5e24072 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 c9d3d4afdc..47b91bf03a 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 134886950b..d3f437afdc 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 8c86f64ca6..d4182d4599 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; } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 6a1feb760e..9bdc578c17 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -292,15 +292,16 @@ void NodeTool::update_helperpath () { if (SP_IS_LPE_ITEM(selection->singleItem())) { Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE(); if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) { - Inkscape::UI::ControlPointSelection::Set &selection_nodes = _selected_nodes->allPoints(); - std::vector selected_nodes_pos; + Inkscape::UI::ControlPointSelection::Set &selection_nodes = this->_selected_nodes->allPoints(); + std::vector positions; + Geom::Affine affine = SP_ITEM(selection->singleItem())->i2dt_affine(); for (Inkscape::UI::ControlPointSelection::Set::iterator i = selection_nodes.begin(); i != selection_nodes.end(); ++i) { if ((*i)->selected()) { Inkscape::UI::Node *n = dynamic_cast(*i); - selected_nodes_pos.push_back(n->position()); + positions.push_back(n->position() * affine); } } - lpe->setSelectedNodes(selected_nodes_pos); + lpe->setSelectedNodes(positions); lpe->setCurrentZoom(this->desktop->current_zoom()); SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); -- GitLab From 417ba16c9f42a5476045ca4f1825fff2fed518ba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 03:30:10 +0200 Subject: [PATCH 102/121] Organize doeffect function (bzr r13645.1.164) --- src/helper/geom-pathvectorsatellites.cpp | 8 +- src/helper/geom-satellite.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 87 +++++++++---------- src/live_effects/parameter/array.cpp | 2 +- .../parameter/satellitesarray.cpp | 26 +++--- .../dialog/lpe-fillet-chamfer-properties.cpp | 6 +- 6 files changed, 61 insertions(+), 70 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index f72841b304..eca8669787 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -65,7 +65,7 @@ void PathVectorSatellites::setSelected(std::vector selected) size_t counter = 0; for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { - if(find (selected.begin(), selected.end(), counter) != selected.end()){ + if (find (selected.begin(), selected.end(), counter) != selected.end()) { _satellites[i][j].setSelected(true); } else { _satellites[i][j].setSelected(false); @@ -107,9 +107,9 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo 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 && _pathvector[i].closed()){ + if (j == 0 && _pathvector[i].closed()) { previous_index = _pathvector[i].size() - 1; - } else if(!_pathvector[i].closed() || j != 0) { + } else if (!_pathvector[i].closed() || j != 0) { previous_index = j - 1; } if (!_pathvector[i].closed() && j == 0) { @@ -128,7 +128,7 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo Geom::Point satellite_point = _pathvector[i].pointAt(j); if (_satellites[i][j].selected || !only_selected) { if (!use_knot_distance && !flexible) { - if(previous_index) { + if (previous_index) { _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); } else { _satellites[i][j].amount = 0.0; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 1242c9aafd..8a92273d0d 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -218,7 +218,7 @@ void Satellite::setSatelliteType(gchar const *A) 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(A)); - if(it != gchar_map_to_satellite_type.end()) { + if (it != gchar_map_to_satellite_type.end()) { satellite_type = it->second; } } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 47b91bf03a..268e089219 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 28867def2a..7470f54cd4 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 d4182d4599..4705fd821c 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]); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 098a84edfc..98b6546402 100644 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp @@ -167,7 +167,7 @@ void FilletChamferPropertiesDialog::_apply() } _satellite.amount = d_pos; size_t steps = (size_t)_fillet_chamfer_chamfer_subdivisions.get_value(); - if(steps < 1) { + if (steps < 1) { steps = 1; } _satellite.steps = steps; @@ -204,10 +204,10 @@ void FilletChamferPropertiesDialog::_setSatellite(Satellite satellite) { double position; std::string distance_or_radius = std::string(_("Radius")); - if(_aprox) { + if (_aprox) { distance_or_radius = std::string(_("Radius approximated")); } - if(_use_distance) { + if (_use_distance) { distance_or_radius = std::string(_("Knot distance")); } if (satellite.is_time) { -- GitLab From d431044fc72f9b668dcfa5771f361f4d6088bdd7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 22 Jan 2017 18:53:31 +0100 Subject: [PATCH 103/121] Update to new code in trunk (bzr r13645.1.166) --- share/keys/default.xml | 2 - share/keys/inkscape.xml | 1 - src/helper/geom-pathvectorsatellites.cpp | 23 +++ src/helper/geom-pathvectorsatellites.h | 1 + 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 +-- .../parameter/satellitesarray.cpp | 8 +- src/live_effects/parameter/satellitesarray.h | 9 +- src/ui/tools/node-tool.cpp | 4 +- 11 files changed, 214 insertions(+), 160 deletions(-) diff --git a/share/keys/default.xml b/share/keys/default.xml index 1342517528..581716d129 100644 --- a/share/keys/default.xml +++ b/share/keys/default.xml @@ -383,8 +383,6 @@ override) the bindings in the main default.xml. - - diff --git a/share/keys/inkscape.xml b/share/keys/inkscape.xml index 4461dee696..581716d129 100644 --- a/share/keys/inkscape.xml +++ b/share/keys/inkscape.xml @@ -382,7 +382,6 @@ override) the bindings in the main default.xml. - diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index eca8669787..79055af8da 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -15,6 +15,8 @@ */ #include +#include "util/units.h" + Geom::PathVector PathVectorSatellites::getPathVector() const { return _pathvector; @@ -141,6 +143,27 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo } } +void PathVectorSatellites::convertUnit(Glib::ustring in, Glib::ustring to, bool apply_no_radius, bool apply_with_radius) +{ + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if (!_pathvector[i].closed() && j == 0) { + _satellites[i][j].amount = 0; + continue; + } + if (_pathvector[i].size() == j) { + continue; + } + if ((!apply_no_radius && _satellites[i][j].amount == 0) || + (!apply_with_radius && _satellites[i][j].amount != 0)) + { + continue; + } + _satellites[i][j].amount = Inkscape::Util::Quantity::convert(_satellites[i][j].amount, in.c_str(), to.c_str()); + } + } +} + void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected) { diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 4a020f5536..d86e6cb25b 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -34,6 +34,7 @@ public: void updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected); void updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, bool use_knot_distance, bool flexible); + void convertUnit(Glib::ustring in, Glib::ustring to, bool apply_no_radius, bool apply_with_radius); void updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected); std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 6899a3161f..19e80c611d 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 61de60db82..0190325c00 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 2bbd3dbab9..410d6f0fc9 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 d3f437afdc..2cee04a1ea 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 4705fd821c..7efe5dd984 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 5b2d8a7998..edaf2f08d4 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 diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 94e684bc42..8561e234f0 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -297,9 +297,9 @@ void sp_update_helperpath() { Inkscape::UI::Node *n = dynamic_cast(*i); selectedNodesPositions.push_back(n->position()); } - lpe->setSelectedNodePoints(selectedNodesPositions); + lpe->setSelectedNodePos(selectedNodesPositions); lpe->setCurrentZoom(desktop->current_zoom()); - + SPCurve *c = new SPCurve(); SPCurve *cc = new SPCurve(); std::vector cs = lpe->getCanvasIndicators(SP_LPE_ITEM(selection->singleItem())); -- GitLab From 98c50c48230463cb059434ad781ccef2ce998cb7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 20:58:19 +0100 Subject: [PATCH 104/121] Remove some warnings (bzr r13645.1.171) --- src/live_effects/parameter/satellitesarray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 7efe5dd984..8cf517852a 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; -- GitLab From 5997087db8a3bc2ec3b3bb0623f3f66cb81a4521 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 21:03:59 +0100 Subject: [PATCH 105/121] Remove some warnings (bzr r13645.1.172) --- src/live_effects/parameter/satellitesarray.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8cf517852a..c7bc7f0261 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; -- GitLab From 3103b99b4cf6c1048c89f75e280761d8cd0ca1c2 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 15 Apr 2017 00:20:13 +0200 Subject: [PATCH 106/121] Allow set and reset default values of LPE parameters (bzr r15620.1.1) --- src/live_effects/effect.cpp | 175 ++++++---- src/live_effects/effect.h | 7 +- src/live_effects/lpe-bendpath.cpp | 8 +- src/live_effects/lpe-bounding-box.cpp | 4 +- src/live_effects/lpe-bspline.cpp | 16 + src/live_effects/lpe-clone-original.cpp | 15 + src/live_effects/lpe-constructgrid.cpp | 4 +- src/live_effects/lpe-copy_rotate.cpp | 15 + 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-fillet-chamfer.cpp | 16 +- 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-lattice2.cpp | 17 +- src/live_effects/lpe-line_segment.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 167 ++++------ src/live_effects/lpe-measure-line.h | 1 - src/live_effects/lpe-mirror_symmetry.cpp | 15 + 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-envelope.cpp | 15 + 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-roughen.cpp | 15 + src/live_effects/lpe-ruler.cpp | 18 +- src/live_effects/lpe-simplify.cpp | 15 + 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-transform_2pts.cpp | 15 + src/live_effects/lpe-vonkoch.cpp | 18 +- src/live_effects/parameter/array.h | 2 +- src/live_effects/parameter/bool.cpp | 8 +- src/live_effects/parameter/bool.h | 4 +- src/live_effects/parameter/enum.h | 10 +- .../parameter/filletchamferpointarray.h | 1 + src/live_effects/parameter/fontbutton.cpp | 11 +- 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/originalitem.h | 1 - .../parameter/originalpatharray.h | 3 +- src/live_effects/parameter/parameter.cpp | 10 + src/live_effects/parameter/parameter.h | 4 +- src/live_effects/parameter/path.cpp | 4 + src/live_effects/parameter/path.h | 1 + src/live_effects/parameter/point.cpp | 15 +- src/live_effects/parameter/point.h | 4 +- .../parameter/powerstrokepointarray.h | 2 +- src/live_effects/parameter/random.cpp | 14 + src/live_effects/parameter/random.h | 4 +- src/live_effects/parameter/text.cpp | 6 +- src/live_effects/parameter/text.h | 6 +- src/live_effects/parameter/togglebutton.cpp | 12 + src/live_effects/parameter/togglebutton.h | 2 + .../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 +- src/preferences-skeleton.h | 310 ++++++++++++++++++ 74 files changed, 980 insertions(+), 365 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 017947cda0..23af55cb36 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)); @@ -350,6 +351,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) : apply_to_clippath_and_mask(false), _provides_knotholder_entities(false), oncanvasedit_it(0), + show_default_widgets(true), 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), @@ -644,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(); @@ -654,10 +657,18 @@ 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 prefs_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(prefs_path).isValid(); + //add to preferences-skeleton the parameters you want reseteable + if(valid && prefs->getString(prefs_path) != DEFAULT_PREF_VALUE){ + param->param_update_default(prefs->getString(prefs_path).c_str()); + } else { + param->param_set_default(); + } } - ++it; } } @@ -667,6 +678,7 @@ void Effect::setParameter(const gchar * key, const gchar * new_value) { Parameter * param = getParameter(key); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (param) { if (new_value) { bool accepted = param->param_readSVGValue(new_value); @@ -674,7 +686,6 @@ Effect::setParameter(const gchar * key, const gchar * new_value) g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key); } } else { - // set default value param->param_set_default(); } } @@ -773,6 +784,21 @@ Effect::newWidget() ++it; } upd_params = false; + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &Effect::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &Effect::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } @@ -866,6 +892,45 @@ Effect::resetDefaults(SPItem const* /*item*/) } } +void +Effect::setDefaultParams() +{ + 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(); + Glib::ustring prefs_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(prefs_path).isValid(); + if (valid){ + prefs->setString(prefs_path, (Glib::ustring)param->param_getSVGValue()); + } + ++it; + } +} + +void +Effect::resetDefaultParams(){ + 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(); + Glib::ustring prefs_path = (Glib::ustring)"/live_effects/" + + (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(prefs_path).isValid(); + if (valid){ + prefs->setString(prefs_path, DEFAULT_PREF_VALUE); + } + ++it; + } +} + void Effect::transform_multiply(Geom::Affine const& postmul, bool set) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index f5e41d50ef..c509db3872 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -136,6 +136,7 @@ public: bool upd_params; BoolParam is_visible; SPCurve * sp_curve; + Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); @@ -156,12 +157,14 @@ protected: virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); - std::vector param_vector; + void setDefaultParams(); + void resetDefaultParams(); + bool _provides_knotholder_entities; int oncanvasedit_it; - + bool show_default_widgets; 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-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index b1e1332922..363356cac9 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 11fb34e045..c83d7e3bc0 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-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 1423e670a2..fb803b7704 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -139,6 +139,22 @@ Gtk::Widget *LPEBSpline::newWidget() ++it; } + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEBSpline::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEBSpline::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index c41b1ef95a..74f93eddc8 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -323,6 +323,21 @@ 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); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECloneOriginal::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECloneOriginal::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } this->upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 8d24f9f473..db620fa956 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-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index bf82b5debb..a462c76a64 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -332,6 +332,21 @@ Gtk::Widget * LPECopyRotate::newWidget() ++it; } + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECopyRotate::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECopyRotate::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index f2fc00aeb5..f8d2e56ca0 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 50bbe6451a..33e754a8ab 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 61a696435f..8528ab14d8 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 daa30d45a0..4a3ad7508a 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 2e1fe0dc13..40fa91c687 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 43fef42889..f8d86ae99e 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-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1e2df7dc8b..f21b53f900 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -176,7 +176,21 @@ Gtk::Widget *LPEFilletChamfer::newWidget() vbox->pack_start(*filletContainer, true, true, 2); vbox->pack_start(*chamferContainer, true, true, 2); - + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return vbox; } diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index e95dc5f382..db3faa307c 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 2defecb779..261612fdb3 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 acffed0003..124a7a9c6a 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-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index e827491c04..fe01ef9ee4 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -256,12 +256,27 @@ LPELattice2::newWidget() ++it; } - + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPELattice2::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPELattice2::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show Points")))); expander->add(*vbox_expander); expander->set_expanded(expanded); vbox->pack_start(*expander, true, true, 2); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPELattice2::onExpanderChanged) ); + return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index cc024fb927..fd23da8049 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-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 86d72615c7..1095cfc0d6 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,56 @@ 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); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } @@ -766,31 +762,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 724c0d9248..b42f7cfd52 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/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 97015c34d5..a00aac3be3 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -336,6 +336,21 @@ LPEMirrorSymmetry::newWidget() ++it; } this->upd_params = false; + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameterss")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMirrorSymmetry::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMirrorSymmetry::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index 057f404e0f..c853e4afa8 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 276749c431..271442c7d4 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 a06dbde98c..61818a73bd 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 966e9020ed..b026bbc22e 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 bce22250ab..dab169cfe8 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-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 365ff53896..e967a01aa2 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -414,6 +414,21 @@ LPEPerspectiveEnvelope::newWidget() reset_button->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); hbox->pack_start(*reset_button, false, false,2); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEPerspectiveEnvelope::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEPerspectiveEnvelope::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index b83fb67d7b..435c91c2d7 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 e9f3975c7d..d87f92fccf 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 aa0db920b7..47613f58ed 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 3cc8658eac..d832b36150 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-roughen.cpp b/src/live_effects/lpe-roughen.cpp index e847494a2f..8b2a07d59e 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -163,6 +163,21 @@ Gtk::Widget *LPERoughen::newWidget() } ++it; } + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPERoughen::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPERoughen::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 60c2a3e1cb..852592219a 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-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 5de9816bb9..5b5bbea6c5 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -115,6 +115,21 @@ LPESimplify::newWidget() ++it; } vbox->pack_start(*buttons,true, true, 2); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPESimplify::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPESimplify::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 4fc18cee26..d3c94269a2 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 e01516f2e5..e3376b7e56 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 5f63e1ee96..69a4dfad9c 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 3248937063..c484c88a20 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 709d05e180..0c1db2f04e 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-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index ef29007750..e5bc8657d8 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -350,6 +350,21 @@ Gtk::Widget *LPETransform2Pts::newWidget() vbox->pack_start(*button2, true, true, 2); vbox->pack_start(*button3, true, true, 2); vbox->pack_start(*button4, true, true, 2); + if (show_default_widgets) { + Gtk::Label *default_label = Gtk::manage(new Gtk::Label( + Glib::ustring(_("Defaults set defaultable parameters")), + Gtk::ALIGN_START)); + default_label->set_use_markup(true); + vbox->pack_start(*default_label, true, true, 2); + Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); + Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); + set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::setDefaultParams)); + Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); + reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::resetDefaultParams)); + defaultBox->pack_start(*set_default, true, true, 2); + defaultBox->pack_start(*reset_default, true, true, 2); + vbox->pack_start(*defaultBox, true, true, 2); + } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 47e2a1cec1..b9fd8908a6 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()); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a600f02573..fa08e1f910 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 813c06b4e2..cdc988ab25 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -37,11 +37,17 @@ BoolParam::param_set_default() } void -BoolParam::param_update_default(bool const default_value) +BoolParam::param_update_default(bool 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 7ad8a9368a..a96966c46f 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -36,9 +36,9 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); - void param_update_default(bool const default_value); + void param_update_default(bool 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 dbfc686237..0bb2d89b22 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 b81339a69c..4e42687034 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 64c203093a..53b8c06124 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 @@ -63,7 +65,7 @@ FontButtonParam::param_newWidget() *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - Glib::ustring fontspec = param_getSVGValue(); + Glib::ustring fontspec = (Glib::ustring)param_getSVGValue(); fontbuttonwdg->setValue( fontspec); fontbuttonwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font button parameter")); param_effect->upd_params = false; @@ -71,11 +73,12 @@ FontButtonParam::param_newWidget() } void -FontButtonParam::param_setValue(const Glib::ustring newvalue) +FontButtonParam::param_setValue(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 df47251a2a..60e1aa46e9 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 93cf2b15f0..7b40f4540f 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 6c719d4510..89c32f9bd4 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/originalitem.h b/src/live_effects/parameter/originalitem.h index 58d04e05a1..de1a6ac25d 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -26,7 +26,6 @@ public: void setInverse(bool inversed) { inverse = inversed; } bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } - virtual Gtk::Widget * param_newWidget(); protected: diff --git a/src/live_effects/parameter/originalpatharray.h b/src/live_effects/parameter/originalpatharray.h index 296c0f7f77..fe93716448 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 befac4df1b..15c81d5431 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 6cf10710c5..e94737a6f9 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; @@ -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 dafc6d406e..aa87508ab9 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 d2dddbe97c..5381a6b361 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 c87b1e2990..683cadc1f3 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -59,11 +59,24 @@ 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; } +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 e8cb66225e..a3797aea5e 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -43,14 +43,14 @@ 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_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); virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); - friend class PointParamKnotHolderEntity; private: PointParam(const PointParam&); diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 56a609fa87..a34163ca1d 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 075e85ee1d..90e53ca0e9 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 ca4440336e..5fb6027acd 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 5c4cdf4c6d..8d526e4ccb 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 @@ -130,7 +130,7 @@ TextParam::param_newWidget() } void -TextParam::param_setValue(const Glib::ustring newvalue) +TextParam::param_setValue(Glib::ustring newvalue) { param_effect->upd_params = true; value = newvalue; diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 553c84c0ab..137f3ee028 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 b3f6442bb8..4eaa1aeb2b 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() { diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 8390fec866..d6ca15e75b 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 0d03432c35..22d5ba3a43 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 c96bedb539..269cc508ef 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 b6ea99bfe0..b78b75dbf1 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 ae58cf9569..c662b6edc3 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 55b4d4b328..470fa9c2d8 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 edee4ff4d4..d270e9f43d 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); diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index ed00092b2c..44775988c5 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -72,6 +72,316 @@ static char const preferences_skeleton[] = " inkscape:window-width=\"640\"\n" " inkscape:window-height=\"480\" />\n" " \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" "\n" " \n" -- GitLab From abda18047008ae28d9711729521fef7bbff8a241 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Apr 2017 21:00:04 +0200 Subject: [PATCH 107/121] Start adding GUI to prefs (bzr r15620.1.3) --- src/live_effects/effect.h | 3 +- src/ui/dialog/inkscape-preferences.cpp | 40 ++++++++++++++++++++++++-- src/ui/dialog/inkscape-preferences.h | 2 ++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index c509db3872..d7f9ab2e77 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -136,7 +136,8 @@ public: bool upd_params; BoolParam is_visible; SPCurve * sp_curve; - + std::vector getParamVector() { return param_vector; } + Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 6464396134..2f962a7ac8 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -27,7 +27,10 @@ #include "preferences.h" #include "verbs.h" #include "selcue.h" - +#include "live_effects/effect-enum.h" +#include "live_effects/effect.h" +#include "live_effects/lpeobject.h" +#include "sp-defs.h" #include "extension/internal/gdkpixbuf-input.h" #include "message-stack.h" #include "style.h" @@ -820,6 +823,39 @@ void InkscapePreferences::initPageUI() this->AddPage(_page_grids, _("Grids"), iter_ui, PREFS_PAGE_UI_GRIDS); initKeyboardShortcuts(iter_ui); + + _page_le.add_group_header( _("Live Effects")); + SPDocument * doc = SP_ACTIVE_DOCUMENT; + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); + lpe_repr->setAttribute("id", "deleteme"); + SPObject *lpeo = SP_OBJECT(doc->getDefs()->appendChildRepr(lpe_repr)); + Inkscape::GC::release(lpe_repr); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + for ( int le = Inkscape::LivePathEffect::EffectType::BEND_PATH; le != Inkscape::LivePathEffect::EffectType::INVALID_LPE; le++ ){ + Inkscape::LivePathEffect::EffectType lpenr = static_cast(le); + Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(lpenr); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(lpenr); + bool is_text_label_lpe = effectkey == (Glib::ustring)"text_label"; + if (!effectname.empty() && !is_text_label_lpe){ + lpeo->setAttribute("effect", effectkey.c_str()); + LivePathEffectObject * lpeobj = dynamic_cast(lpeo); + Glib::ustring liveeffect = effectname +(Glib::ustring)_(":"); + _page_le.add_group_header(liveeffect.c_str()); + Inkscape::LivePathEffect::Effect* effect = Inkscape::LivePathEffect::Effect::New(lpenr, lpeobj); + std::vector param_vector = effect->getParamVector(); + std::vector::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + Inkscape::LivePathEffect::Parameter * param = *it; + const gchar * key = param->param_key.c_str(); + const gchar * value = param->param_label.c_str(); + _page_le.add_group_header(value); + ++it; + } + } + } + lpeo->deleteObject(); + this->AddPage(_page_le, _("Live Effects"), iter_ui, PREFS_PAGE_UI_LE); } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -2042,7 +2078,7 @@ bool InkscapePreferences::PresentPage(const Gtk::TreeModel::iterator& iter) _page_list.expand_row(_path_tools, false); if (desired_page >= PREFS_PAGE_TOOLS_SHAPES && desired_page <= PREFS_PAGE_TOOLS_SHAPES_SPIRAL) _page_list.expand_row(_path_shapes, false); - if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_KEYBOARD_SHORTCUTS) + if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_LE) _page_list.expand_row(_path_ui, false); if (desired_page >= PREFS_PAGE_BEHAVIOR && desired_page <= PREFS_PAGE_BEHAVIOR_MASKS) _page_list.expand_row(_path_behavior, false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index e6ba4e4b21..2e42252d9f 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -73,6 +73,7 @@ enum { PREFS_PAGE_UI_WINDOWS, PREFS_PAGE_UI_GRIDS, PREFS_PAGE_UI_KEYBOARD_SHORTCUTS, + PREFS_PAGE_UI_LE, PREFS_PAGE_BEHAVIOR, PREFS_PAGE_BEHAVIOR_SELECTING, PREFS_PAGE_BEHAVIOR_TRANSFORMS, @@ -187,6 +188,7 @@ protected: UI::Widget::DialogPage _page_spellcheck; UI::Widget::DialogPage _page_keyshortcuts; + UI::Widget::DialogPage _page_le; UI::Widget::PrefSpinButton _mouse_sens; UI::Widget::PrefSpinButton _mouse_thres; -- GitLab From af42d5456d7f523d6cb259d0e2921234aa887146 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 27 Apr 2017 01:06:31 +0200 Subject: [PATCH 108/121] Add LPE prefs dialog (bzr r15620.1.4) --- src/live_effects/effect.cpp | 8 ++-- src/live_effects/parameter/bool.cpp | 12 ++++- src/live_effects/parameter/fontbutton.cpp | 12 ++++- src/live_effects/parameter/parameter.h | 2 +- src/ui/dialog/inkscape-preferences.cpp | 54 ++++++++++++++++++++--- src/ui/dialog/inkscape-preferences.h | 8 ++-- 6 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 23af55cb36..5246dbf89e 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -657,14 +657,14 @@ Effect::readallParameters(Inkscape::XML::Node const* repr) g_warning("Effect::readallParameters - '%s' not accepted for %s", value, key); } } else { - Glib::ustring prefs_path = (Glib::ustring)"/live_effects/" + + 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(prefs_path).isValid(); + bool valid = prefs->getEntry(pref_path).isValid(); //add to preferences-skeleton the parameters you want reseteable - if(valid && prefs->getString(prefs_path) != DEFAULT_PREF_VALUE){ - param->param_update_default(prefs->getString(prefs_path).c_str()); + if(valid && prefs->getString(pref_path) != DEFAULT_PREF_VALUE){ + param->param_update_default(prefs->getString(pref_path).c_str()); } else { param->param_set_default(); } diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index cdc988ab25..a031b5ceda 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -66,8 +66,18 @@ Gtk::Widget * BoolParam::param_newWidget() { if(!hide_widget){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredCheckButton( param_label, + new Inkscape::UI::Widget::RegisteredCheckButton( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index 53b8c06124..ee76c4ab94 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -58,8 +58,18 @@ FontButtonParam::param_getSVGValue() const Gtk::Widget * FontButtonParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredFontButton * fontbuttonwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredFontButton( param_label, + new Inkscape::UI::Widget::RegisteredFontButton( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index e94737a6f9..ee1d2d547c 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -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; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 2f962a7ac8..93cf5eb428 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -824,14 +824,16 @@ void InkscapePreferences::initPageUI() initKeyboardShortcuts(iter_ui); - _page_le.add_group_header( _("Live Effects")); + _page_lpe.add_group_header( _("Allow set default to this parameters:")); SPDocument * doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); lpe_repr->setAttribute("id", "deleteme"); SPObject *lpeo = SP_OBJECT(doc->getDefs()->appendChildRepr(lpe_repr)); Inkscape::GC::release(lpe_repr); + Inkscape::UI::Widget::Registry * wr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + for ( int le = Inkscape::LivePathEffect::EffectType::BEND_PATH; le != Inkscape::LivePathEffect::EffectType::INVALID_LPE; le++ ){ Inkscape::LivePathEffect::EffectType lpenr = static_cast(le); Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(lpenr); @@ -841,21 +843,63 @@ void InkscapePreferences::initPageUI() lpeo->setAttribute("effect", effectkey.c_str()); LivePathEffectObject * lpeobj = dynamic_cast(lpeo); Glib::ustring liveeffect = effectname +(Glib::ustring)_(":"); - _page_le.add_group_header(liveeffect.c_str()); Inkscape::LivePathEffect::Effect* effect = Inkscape::LivePathEffect::Effect::New(lpenr, lpeobj); std::vector param_vector = effect->getParamVector(); std::vector::iterator it = param_vector.begin(); + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); + vbox_expander->set_border_width(10); + vbox_expander->set_spacing(2); while (it != param_vector.end()) { Inkscape::LivePathEffect::Parameter * param = *it; const gchar * key = param->param_key.c_str(); const gchar * value = param->param_label.c_str(); - _page_le.add_group_header(value); + const gchar * tooltip = (param->param_tooltip + (Glib::ustring)_(". Toogling this widget in preferences reset custom values for this parameter")).c_str(); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)key; + bool valid = prefs->getEntry(pref_path).isValid(); + bool set = false; + if(valid){ + set = true; + } + Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredCheckButton( param->param_label, + param->param_tooltip, + param->param_key, + *wr, + false, + NULL, + NULL) ); + checkwdg->setActive(set); + checkwdg->setProgrammatically = false; + checkwdg->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &InkscapePreferences::defaultLpeUpdater), pref_path, checkwdg)); + vbox_expander->pack_start(*dynamic_cast (checkwdg), true, true, 2); ++it; } + + Gtk::Expander * expander = Gtk::manage(new Gtk::Expander(liveeffect)); + expander->add(*vbox_expander); + expander->set_expanded(false); + Glib::ustring tip = (Glib::ustring)_("Set defaultables parameters for ") + liveeffect; + _page_lpe.add_line( true, "", *dynamic_cast(expander), "", tip.c_str() ); } } lpeo->deleteObject(); - this->AddPage(_page_le, _("Live Effects"), iter_ui, PREFS_PAGE_UI_LE); + this->AddPage(_page_lpe, _("Live Effects"), iter_ui, PREFS_PAGE_UI_LPE); +} + +void +InkscapePreferences::defaultLpeUpdater(Glib::ustring pref_path, Inkscape::UI::Widget::RegisteredCheckButton * checkwdg) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (checkwdg->get_active()) + { + prefs->setString(pref_path, "--default"); + + } else { + prefs->remove(pref_path); + } } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -2078,7 +2122,7 @@ bool InkscapePreferences::PresentPage(const Gtk::TreeModel::iterator& iter) _page_list.expand_row(_path_tools, false); if (desired_page >= PREFS_PAGE_TOOLS_SHAPES && desired_page <= PREFS_PAGE_TOOLS_SHAPES_SPIRAL) _page_list.expand_row(_path_shapes, false); - if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_LE) + if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_LPE) _page_list.expand_row(_path_ui, false); if (desired_page >= PREFS_PAGE_BEHAVIOR && desired_page <= PREFS_PAGE_BEHAVIOR_MASKS) _page_list.expand_row(_path_behavior, false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 2e42252d9f..6320ff49c6 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -22,6 +22,7 @@ #include #include #include "ui/widget/preferences-widget.h" +#include "ui/widget/registered-widget.h" #include "ui/widget/button.h" #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +75,7 @@ enum { PREFS_PAGE_UI_WINDOWS, PREFS_PAGE_UI_GRIDS, PREFS_PAGE_UI_KEYBOARD_SHORTCUTS, - PREFS_PAGE_UI_LE, + PREFS_PAGE_UI_LPE, PREFS_PAGE_BEHAVIOR, PREFS_PAGE_BEHAVIOR_SELECTING, PREFS_PAGE_BEHAVIOR_TRANSFORMS, @@ -188,7 +190,7 @@ protected: UI::Widget::DialogPage _page_spellcheck; UI::Widget::DialogPage _page_keyshortcuts; - UI::Widget::DialogPage _page_le; + UI::Widget::DialogPage _page_lpe; UI::Widget::PrefSpinButton _mouse_sens; UI::Widget::PrefSpinButton _mouse_thres; @@ -492,7 +494,7 @@ protected: Gtk::TreeModel::iterator AddPage(UI::Widget::DialogPage& p, Glib::ustring title, Gtk::TreeModel::iterator parent, int id); bool SetMaxDialogSize(const Gtk::TreeModel::iterator& iter); bool PresentPage(const Gtk::TreeModel::iterator& iter); - + void defaultLpeUpdater(Glib::ustring pref_path, Inkscape::UI::Widget::RegisteredCheckButton * checkwdg); static void AddSelcueCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); static void AddGradientCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); static void AddConvertGuidesCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); -- GitLab From 18e032118bbb1718778c6f2e5e55cdb1723dc1ce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 27 Apr 2017 12:05:03 +0200 Subject: [PATCH 109/121] Add end of preferences GUI (bzr r15620.1.6) --- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-bspline.cpp | 2 +- src/live_effects/lpe-clone-original.cpp | 2 +- src/live_effects/lpe-copy_rotate.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- src/live_effects/lpe-lattice2.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 2 +- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- src/live_effects/lpe-perspective-envelope.cpp | 2 +- src/live_effects/lpe-simplify.cpp | 2 +- src/live_effects/lpe-transform_2pts.cpp | 2 +- src/live_effects/parameter/item.cpp | 12 +++++++++++- src/live_effects/parameter/originalitem.cpp | 12 +++++++++++- src/live_effects/parameter/originalpath.cpp | 12 +++++++++++- src/live_effects/parameter/parameter.cpp | 12 +++++++++++- src/live_effects/parameter/path.cpp | 12 +++++++++++- src/live_effects/parameter/point.cpp | 12 +++++++++++- src/live_effects/parameter/random.cpp | 12 +++++++++++- src/live_effects/parameter/text.cpp | 12 +++++++++++- src/live_effects/parameter/togglebutton.cpp | 12 +++++++++++- src/live_effects/parameter/transformedpoint.cpp | 12 +++++++++++- src/live_effects/parameter/unit.cpp | 12 +++++++++++- src/live_effects/parameter/vector.cpp | 12 +++++++++++- src/ui/dialog/inkscape-preferences.cpp | 14 +++++++++++--- 24 files changed, 154 insertions(+), 26 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 5246dbf89e..a7315b37f9 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -786,7 +786,7 @@ Effect::newWidget() upd_params = false; if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index fb803b7704..eb6fb5d0a8 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -142,7 +142,7 @@ Gtk::Widget *LPEBSpline::newWidget() Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index ae20b582ad..93ea4aa9d9 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -320,7 +320,7 @@ LPECloneOriginal::newWidget() vbox->pack_start(*expander, true, true, 2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 1fd0e466fc..3a1925366c 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -330,7 +330,7 @@ Gtk::Widget * LPECopyRotate::newWidget() if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f21b53f900..585972fee4 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -178,7 +178,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() vbox->pack_start(*chamferContainer, true, true, 2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index fe01ef9ee4..88cb815f9b 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -258,7 +258,7 @@ LPELattice2::newWidget() } if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 1095cfc0d6..64b970e7bb 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -729,7 +729,7 @@ Gtk::Widget *LPEMeasureLine::newWidget() vbox->pack_start(*expander, true, true, 2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index a00aac3be3..87107f914c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -338,7 +338,7 @@ LPEMirrorSymmetry::newWidget() this->upd_params = false; if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameterss")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index e967a01aa2..88998aa49b 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -416,7 +416,7 @@ LPEPerspectiveEnvelope::newWidget() hbox->pack_start(*reset_button, false, false,2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 5b5bbea6c5..49d869cffc 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -117,7 +117,7 @@ LPESimplify::newWidget() vbox->pack_start(*buttons,true, true, 2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index e5bc8657d8..6927ee13d7 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -352,7 +352,7 @@ Gtk::Widget *LPETransform2Pts::newWidget() vbox->pack_start(*button4, true, true, 2); if (show_default_widgets) { Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), + Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), Gtk::ALIGN_START)); default_label->set_use_markup(true); vbox->pack_start(*default_label, true, true, 2); diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 7b40f4540f..aba61b96a2 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -108,10 +108,20 @@ ItemParam::param_getSVGValue() const Gtk::Widget * ItemParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } 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)); + Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(label)); static_cast(_widget)->pack_start(*pLabel, true, true); pLabel->set_tooltip_text(param_tooltip); pButton->set_relief(Gtk::RELIEF_NONE); diff --git a/src/live_effects/parameter/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index 053062128e..8db8851bfb 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -46,10 +46,20 @@ OriginalItemParam::~OriginalItemParam() Gtk::Widget * OriginalItemParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); { // Label - Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(param_label)); + Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(label)); static_cast(_widget)->pack_start(*pLabel, true, true); pLabel->set_tooltip_text(param_tooltip); } diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 1e78f7fe1c..388a3b5e66 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -47,10 +47,20 @@ OriginalPathParam::~OriginalPathParam() Gtk::Widget * OriginalPathParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); { // Label - Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(param_label)); + Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(label)); static_cast(_widget)->pack_start(*pLabel, true, true); pLabel->set_tooltip_text(param_tooltip); } diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 15c81d5431..359a519137 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -172,8 +172,18 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } 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() ) ); + label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); rsu->setValue(value); rsu->setDigits(digits); diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index aa87508ab9..9bdebaf478 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -170,9 +170,19 @@ PathParam::param_getSVGValue() const Gtk::Widget * PathParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox()); - Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); + Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(label)); static_cast(_widget)->pack_start(*pLabel, true, true); pLabel->set_tooltip_text(param_tooltip); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 561f1b34c1..2fbe4b3b4a 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -126,8 +126,18 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, + new Inkscape::UI::Widget::RegisteredTransformedPoint( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 90e53ca0e9..bcba053992 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -129,8 +129,18 @@ RandomParam::resetRandomizer() Gtk::Widget * RandomParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredRandom* regrandom = Gtk::manage( - new Inkscape::UI::Widget::RegisteredRandom( param_label, + new Inkscape::UI::Widget::RegisteredRandom( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 8d526e4ccb..5c56e84470 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -119,8 +119,18 @@ TextParam::param_getSVGValue() const Gtk::Widget * TextParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } 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())); + label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); rsu->setText(value); rsu->setProgrammatically = false; diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 4eaa1aeb2b..1d1bc82a69 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -75,12 +75,22 @@ ToggleButtonParam::param_update_default(const gchar * default_value) Gtk::Widget * ToggleButtonParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } if (_toggled_connection.connected()) { _toggled_connection.disconnect(); } checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredToggleButton( param_label, + new Inkscape::UI::Widget::RegisteredToggleButton( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/transformedpoint.cpp b/src/live_effects/parameter/transformedpoint.cpp index 22d5ba3a43..2081a8c0c4 100644 --- a/src/live_effects/parameter/transformedpoint.cpp +++ b/src/live_effects/parameter/transformedpoint.cpp @@ -104,8 +104,18 @@ TransformedPointParam::param_update_default(const gchar * default_point) Gtk::Widget * TransformedPointParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredVector * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredVector( param_label, + new Inkscape::UI::Widget::RegisteredVector( label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index b78b75dbf1..684f295556 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -75,8 +75,18 @@ UnitParam::get_abbreviation() const Gtk::Widget * UnitParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredUnitMenu* unit_menu = Gtk::manage( - new Inkscape::UI::Widget::RegisteredUnitMenu(param_label, + new Inkscape::UI::Widget::RegisteredUnitMenu(label, param_key, *param_wr, param_effect->getRepr(), diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 470fa9c2d8..d6593871da 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -104,8 +104,18 @@ VectorParam::param_getSVGValue() const Gtk::Widget * VectorParam::param_newWidget() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); + Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + + effectkey + + (Glib::ustring)"/" + + (Glib::ustring)param_key; + Glib::ustring label = param_label; + if(prefs->getEntry(pref_path).isValid()){ + label = (Glib::ustring)"* " + param_label; + } Inkscape::UI::Widget::RegisteredVector * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredVector( param_label, + new Inkscape::UI::Widget::RegisteredVector( label, param_tooltip, param_key, *param_wr, diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 93cf5eb428..2f83a08e93 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -834,7 +834,7 @@ void InkscapePreferences::initPageUI() Inkscape::UI::Widget::Registry * wr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - for ( int le = Inkscape::LivePathEffect::EffectType::BEND_PATH; le != Inkscape::LivePathEffect::EffectType::INVALID_LPE; le++ ){ + for ( int le = Inkscape::LivePathEffect::EffectType::BEND_PATH; le != Inkscape::LivePathEffect::EffectType::INVALID_LPE; ++le){ Inkscape::LivePathEffect::EffectType lpenr = static_cast(le); Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(lpenr); Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(lpenr); @@ -845,6 +845,9 @@ void InkscapePreferences::initPageUI() Glib::ustring liveeffect = effectname +(Glib::ustring)_(":"); Inkscape::LivePathEffect::Effect* effect = Inkscape::LivePathEffect::Effect::New(lpenr, lpeobj); std::vector param_vector = effect->getParamVector(); + if (param_vector.size() == 1) { + continue; + } std::vector::iterator it = param_vector.begin(); Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); vbox_expander->set_border_width(10); @@ -852,8 +855,13 @@ void InkscapePreferences::initPageUI() while (it != param_vector.end()) { Inkscape::LivePathEffect::Parameter * param = *it; const gchar * key = param->param_key.c_str(); + if (strcmp(key,"is_visible") == 0 ){ + ++it; + continue; + } const gchar * value = param->param_label.c_str(); - const gchar * tooltip = (param->param_tooltip + (Glib::ustring)_(". Toogling this widget in preferences reset custom values for this parameter")).c_str(); + const gchar * tooltip_extra = _(". Toogling this check in preferences reset to default 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)"/" + @@ -865,7 +873,7 @@ void InkscapePreferences::initPageUI() } Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredCheckButton( param->param_label, - param->param_tooltip, + tooltip, param->param_key, *wr, false, -- GitLab From 7139c8a3275224df37c3e59628355f6b3e3398b4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 27 Apr 2017 15:49:12 +0200 Subject: [PATCH 110/121] Fixing remove prefs (bzr r15620.1.7) --- src/preferences-skeleton.h | 310 ------------------------- src/preferences.cpp | 29 +++ src/ui/dialog/inkscape-preferences.cpp | 2 + 3 files changed, 31 insertions(+), 310 deletions(-) diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 44775988c5..ed00092b2c 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -72,316 +72,6 @@ static char const preferences_skeleton[] = " inkscape:window-width=\"640\"\n" " inkscape:window-height=\"480\" />\n" " \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" "\n" " \n" diff --git a/src/preferences.cpp b/src/preferences.cpp index 4d522a1d88..2849fe068a 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -512,6 +512,35 @@ void Preferences::remove(Glib::ustring const &pref_path) Inkscape::XML::Node *node = _getNode(pref_path, false); if (node && node->parent()) { node->parent()->removeChild(node); + } else { //Handle to remove also attributes in path not only the container node + // verify path + g_assert( pref_path.at(0) == '/' ); + if (_prefs_doc == NULL){ + return; + } + node = _prefs_doc->root(); + Inkscape::XML::Node *child = NULL; + gchar **splits = g_strsplit(pref_path.c_str(), "/", 0); + if ( splits ) { + for (int part_i = 0; splits[part_i]; ++part_i) { + // skip empty path segments + if (!splits[part_i][0]) { + continue; + } + if (!node->firstChild()) { + node->setAttribute(splits[part_i], NULL); + g_strfreev(splits); + return; + } + for (child = node->firstChild(); child; child = child->next()) { + if (!strcmp(splits[part_i], child->attribute("id"))) { + break; + } + } + node = child; + } + } + g_strfreev(splits); } } diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 2f83a08e93..6e12104f0c 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -907,6 +907,8 @@ InkscapePreferences::defaultLpeUpdater(Glib::ustring pref_path, Inkscape::UI::Wi } else { prefs->remove(pref_path); + prefs->remove((Glib::ustring)"/live_effects/gdsgddssdggdsgdsgdsgs"); + prefs->remove((Glib::ustring)"/ddsdsdsgdsg"); } } -- GitLab From 52054e24f8b98c07753588c726a1e777bad7245b Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 28 Apr 2017 21:42:36 +0200 Subject: [PATCH 111/121] Reset (bzr r15620.1.9) --- src/live_effects/effect.cpp | 175 ++++++------------ src/live_effects/effect.h | 8 +- src/live_effects/lpe-bendpath.cpp | 8 +- src/live_effects/lpe-bounding-box.cpp | 4 +- src/live_effects/lpe-bspline.cpp | 16 -- src/live_effects/lpe-clone-original.cpp | 15 -- src/live_effects/lpe-constructgrid.cpp | 4 +- src/live_effects/lpe-copy_rotate.cpp | 17 -- 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-fillet-chamfer.cpp | 16 +- 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-lattice2.cpp | 17 +- src/live_effects/lpe-line_segment.cpp | 2 +- src/live_effects/lpe-measure-line.cpp | 167 ++++++++++------- src/live_effects/lpe-measure-line.h | 1 + src/live_effects/lpe-mirror_symmetry.cpp | 15 -- 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-envelope.cpp | 15 -- 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-roughen.cpp | 15 -- src/live_effects/lpe-ruler.cpp | 18 +- src/live_effects/lpe-simplify.cpp | 15 -- 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-transform_2pts.cpp | 15 -- src/live_effects/lpe-vonkoch.cpp | 18 +- src/live_effects/parameter/array.h | 2 +- src/live_effects/parameter/bool.cpp | 20 +- src/live_effects/parameter/bool.h | 4 +- src/live_effects/parameter/enum.h | 10 +- .../parameter/filletchamferpointarray.h | 1 - src/live_effects/parameter/fontbutton.cpp | 23 +-- src/live_effects/parameter/fontbutton.h | 6 +- src/live_effects/parameter/item.cpp | 16 +- src/live_effects/parameter/item.h | 1 - src/live_effects/parameter/originalitem.cpp | 12 +- src/live_effects/parameter/originalitem.h | 1 + src/live_effects/parameter/originalpath.cpp | 12 +- .../parameter/originalpatharray.h | 3 +- src/live_effects/parameter/parameter.cpp | 22 +-- src/live_effects/parameter/parameter.h | 6 +- src/live_effects/parameter/path.cpp | 16 +- src/live_effects/parameter/path.h | 1 - src/live_effects/parameter/point.cpp | 25 +-- src/live_effects/parameter/point.h | 2 - .../parameter/powerstrokepointarray.h | 2 +- src/live_effects/parameter/random.cpp | 26 +-- src/live_effects/parameter/random.h | 4 +- src/live_effects/parameter/text.cpp | 18 +- src/live_effects/parameter/text.h | 6 +- src/live_effects/parameter/togglebutton.cpp | 24 +-- src/live_effects/parameter/togglebutton.h | 2 - .../parameter/transformedpoint.cpp | 31 +--- src/live_effects/parameter/transformedpoint.h | 4 +- src/live_effects/parameter/unit.cpp | 16 +- src/live_effects/parameter/unit.h | 5 +- src/live_effects/parameter/vector.cpp | 31 +--- src/live_effects/parameter/vector.h | 3 +- src/preferences.cpp | 29 --- src/ui/dialog/inkscape-preferences.cpp | 94 +--------- src/ui/dialog/inkscape-preferences.h | 6 +- 78 files changed, 380 insertions(+), 953 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a7315b37f9..017947cda0 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -74,73 +74,72 @@ #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"}, //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"}, + {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"}, /* 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)); @@ -351,7 +350,6 @@ Effect::Effect(LivePathEffectObject *lpeobject) : apply_to_clippath_and_mask(false), _provides_knotholder_entities(false), oncanvasedit_it(0), - show_default_widgets(true), 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), @@ -646,7 +644,6 @@ 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(); @@ -657,18 +654,10 @@ Effect::readallParameters(Inkscape::XML::Node const* repr) g_warning("Effect::readallParameters - '%s' not accepted for %s", value, key); } } else { - 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(); - //add to preferences-skeleton the parameters you want reseteable - if(valid && prefs->getString(pref_path) != DEFAULT_PREF_VALUE){ - param->param_update_default(prefs->getString(pref_path).c_str()); - } else { - param->param_set_default(); - } + // set default value + param->param_set_default(); } + ++it; } } @@ -678,7 +667,6 @@ void Effect::setParameter(const gchar * key, const gchar * new_value) { Parameter * param = getParameter(key); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (param) { if (new_value) { bool accepted = param->param_readSVGValue(new_value); @@ -686,6 +674,7 @@ Effect::setParameter(const gchar * key, const gchar * new_value) g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key); } } else { + // set default value param->param_set_default(); } } @@ -784,21 +773,6 @@ Effect::newWidget() ++it; } upd_params = false; - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &Effect::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &Effect::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } @@ -892,45 +866,6 @@ Effect::resetDefaults(SPItem const* /*item*/) } } -void -Effect::setDefaultParams() -{ - 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(); - Glib::ustring prefs_path = (Glib::ustring)"/live_effects/" + - (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + - (Glib::ustring)"/" + - (Glib::ustring)key; - bool valid = prefs->getEntry(prefs_path).isValid(); - if (valid){ - prefs->setString(prefs_path, (Glib::ustring)param->param_getSVGValue()); - } - ++it; - } -} - -void -Effect::resetDefaultParams(){ - 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(); - Glib::ustring prefs_path = (Glib::ustring)"/live_effects/" + - (Glib::ustring)LPETypeConverter.get_key(effectType()).c_str() + - (Glib::ustring)"/" + - (Glib::ustring)key; - bool valid = prefs->getEntry(prefs_path).isValid(); - if (valid){ - prefs->setString(prefs_path, DEFAULT_PREF_VALUE); - } - ++it; - } -} - void Effect::transform_multiply(Geom::Affine const& postmul, bool set) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index d7f9ab2e77..f5e41d50ef 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -136,8 +136,6 @@ public: bool upd_params; BoolParam is_visible; SPCurve * sp_curve; - std::vector getParamVector() { return param_vector; } - Geom::PathVector pathvector_before_effect; protected: Effect(LivePathEffectObject *lpeobject); @@ -158,14 +156,12 @@ protected: virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); - std::vector param_vector; - void setDefaultParams(); - void resetDefaultParams(); + std::vector param_vector; bool _provides_knotholder_entities; int oncanvasedit_it; - bool show_default_widgets; + 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-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 363356cac9..b1e1332922 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( &bend_path ); - registerParameter( &prop_scale); - registerParameter( &scale_y_rel); - registerParameter( &vertical_pattern); + registerParameter( dynamic_cast(&bend_path) ); + registerParameter( dynamic_cast(&prop_scale) ); + registerParameter( dynamic_cast(&scale_y_rel) ); + registerParameter( dynamic_cast(&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 c83d7e3bc0..11fb34e045 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(&linked_path); - registerParameter(&visual_bounds); + registerParameter( dynamic_cast(&linked_path) ); + registerParameter( dynamic_cast(&visual_bounds) ); //perceived_path = true; } diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index eb6fb5d0a8..1423e670a2 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -139,22 +139,6 @@ Gtk::Widget *LPEBSpline::newWidget() ++it; } - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEBSpline::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEBSpline::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 93ea4aa9d9..47fb6a04e2 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -318,21 +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); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECloneOriginal::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECloneOriginal::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } this->upd_params = false; return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index db620fa956..8d24f9f473 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(&nr_x); - registerParameter(&nr_y); + registerParameter( dynamic_cast(&nr_x) ); + registerParameter( dynamic_cast(&nr_y) ); nr_x.param_make_integer(); nr_y.param_make_integer(); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3a1925366c..4869e8279a 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -327,23 +327,6 @@ Gtk::Widget * LPECopyRotate::newWidget() reset_button->set_size_request(110,20); vbox->pack_start(*hbox, true,true,2); hbox->pack_start(*reset_button, false, false,2); - - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECopyRotate::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPECopyRotate::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } - return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index f8d2e56ca0..f2fc00aeb5 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(&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); + 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) ); 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 33e754a8ab..50bbe6451a 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(&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); + 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) ); 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 8528ab14d8..61a696435f 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(&yy); - registerParameter(&xx); - registerParameter(&bend_path1); - registerParameter(&bend_path2); - registerParameter(&bend_path3); - registerParameter(&bend_path4); + 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) ); 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 4a3ad7508a..daa30d45a0 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(&extrude_vector); + registerParameter( dynamic_cast(&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 40fa91c687..2e1fe0dc13 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(&linked_paths); - registerParameter(&fuse); - registerParameter(&allow_transforms); - registerParameter(&join); - registerParameter(&close); + registerParameter( dynamic_cast(&linked_paths) ); + registerParameter( dynamic_cast(&fuse) ); + registerParameter( dynamic_cast(&allow_transforms) ); + registerParameter( dynamic_cast(&join) ); + registerParameter( dynamic_cast(&close) ); transformmultiply = false; } diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index f8d86ae99e..43fef42889 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(&linked_path); - registerParameter(&second_path); - registerParameter(&reverse_second); - registerParameter(&fuse); - registerParameter(&allow_transforms); - registerParameter(&join); - registerParameter(&close); + 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) ); transformmultiply = false; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 585972fee4..1e2df7dc8b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -176,21 +176,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() vbox->pack_start(*filletContainer, true, true, 2); vbox->pack_start(*chamferContainer, true, true, 2); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } + return vbox; } diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index db3faa307c..e95dc5f382 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(&trajectory_path); - registerParameter(&equidistant_spacing); - registerParameter(&number_of_steps); + registerParameter( dynamic_cast(&trajectory_path) ); + registerParameter( dynamic_cast(&equidistant_spacing) ); + registerParameter( dynamic_cast(&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 261612fdb3..2defecb779 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(&interruption_width); - registerParameter(&prop_to_stroke_width); - registerParameter(&add_stroke_width); - registerParameter(&add_other_stroke_width); - registerParameter(&switcher_size); - registerParameter(&crossing_points_vector); + 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) ); _provides_knotholder_entities = true; } diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 124a7a9c6a..acffed0003 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(&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); + 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) ); apply_to_clippath_and_mask = true; } diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index 88cb815f9b..e827491c04 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -256,27 +256,12 @@ LPELattice2::newWidget() ++it; } - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPELattice2::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPELattice2::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Show Points")))); expander->add(*vbox_expander); expander->set_expanded(expanded); vbox->pack_start(*expander, true, true, 2); expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &LPELattice2::onExpanderChanged) ); - return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index fd23da8049..cc024fb927 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(&end_type); + registerParameter( dynamic_cast(&end_type) ); } LPELineSegment::~LPELineSegment() diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 64b970e7bb..86d72615c7 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -49,33 +49,32 @@ 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); @@ -100,16 +99,39 @@ 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.c_str()); - + 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_hide_canvas_text(); dimline_format.param_hide_canvas_text(); helperlines_format.param_hide_canvas_text(); @@ -353,7 +375,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.15; + anotation_width = bounds->width() * 1.4; } } @@ -383,14 +405,8 @@ 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){ - if ((elemref = document->getObjectById(id))) { - if (remove) { - elemref->deleteObject(); - } - return; - } + return; } - //k = std::max(k , arrow_gap -1); Geom::Ray ray(end, start); Geom::Coord angle = ray.angle(); line_path.start(start); @@ -606,9 +622,6 @@ 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); @@ -632,6 +645,9 @@ 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()); @@ -692,56 +708,44 @@ 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; - 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); } } } ++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); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMeasureLine::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } + vbox->pack_start(*button1, true, true, 2); return dynamic_cast(vbox); } @@ -762,6 +766,31 @@ 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 b42f7cfd52..724c0d9248 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -49,6 +49,7 @@ 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/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 87107f914c..97015c34d5 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -336,21 +336,6 @@ LPEMirrorSymmetry::newWidget() ++it; } this->upd_params = false; - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMirrorSymmetry::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEMirrorSymmetry::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index c853e4afa8..057f404e0f 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(&offset_pt); + registerParameter(dynamic_cast(&offset_pt)); } LPEOffset::~LPEOffset() diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 271442c7d4..276749c431 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(&offset_pt); - registerParameter(&length_left); - registerParameter(&length_right); + registerParameter(dynamic_cast(&offset_pt)); + registerParameter( dynamic_cast(&length_left) ); + registerParameter( dynamic_cast(&length_right) ); } LPEParallel::~LPEParallel() diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 61818a73bd..a06dbde98c 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(&scale); - registerParameter(&info_text); - registerParameter(&unit); - registerParameter(&display_unit); + registerParameter(dynamic_cast(&scale)); + registerParameter(dynamic_cast(&info_text)); + registerParameter(dynamic_cast(&unit)); + registerParameter(dynamic_cast(&display_unit)); } LPEPathLength::~LPEPathLength() diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index b026bbc22e..966e9020ed 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(&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); + 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) ); 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 dab169cfe8..bce22250ab 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(&length_left); - registerParameter(&length_right); + registerParameter( dynamic_cast(&length_left) ); + registerParameter( dynamic_cast(&length_right) ); } LPEPerpBisector::~LPEPerpBisector() diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 88998aa49b..365ff53896 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -414,21 +414,6 @@ LPEPerspectiveEnvelope::newWidget() reset_button->set_size_request(140,30); vbox->pack_start(*hbox, true,true,2); hbox->pack_start(*reset_button, false, false,2); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEPerspectiveEnvelope::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPEPerspectiveEnvelope::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 435c91c2d7..b83fb67d7b 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( &scalex); - registerParameter( &scaley); - registerParameter( &offsetx); - registerParameter( &offsety); - registerParameter( &uses_plane_xy); + registerParameter( dynamic_cast(&scalex) ); + registerParameter( dynamic_cast(&scaley) ); + registerParameter( dynamic_cast(&offsetx) ); + registerParameter( dynamic_cast(&offsety) ); + registerParameter( dynamic_cast(&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 d87f92fccf..e9f3975c7d 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(&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); + 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) ); } LPEPowerStroke::~LPEPowerStroke() diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index 47613f58ed..aa0db920b7 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(&iterations); + registerParameter( dynamic_cast(&iterations) ); } diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index d832b36150..3cc8658eac 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(&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); + 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) ); //hatch_dist.param_set_range(0.1, Geom::infinity()); growth.param_set_range(0, Geom::infinity()); diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 8b2a07d59e..e847494a2f 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -163,21 +163,6 @@ Gtk::Widget *LPERoughen::newWidget() } ++it; } - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable parameters")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPERoughen::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPERoughen::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 852592219a..60c2a3e1cb 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(&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); + 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)); major_mark_steps.param_make_integer(); major_mark_steps.param_set_range(1, 1000); diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 49d869cffc..5de9816bb9 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -115,21 +115,6 @@ LPESimplify::newWidget() ++it; } vbox->pack_start(*buttons,true, true, 2); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPESimplify::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPESimplify::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index d3c94269a2..4fc18cee26 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(&number); + registerParameter( dynamic_cast(&number) ); } LPESkeleton::~LPESkeleton() diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index e3376b7e56..e01516f2e5 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(&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); + //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) ); #ifdef LPE_SKETCH_USE_CONSTRUCTION_LINES - registerParameter(&nbtangents); - registerParameter(&tgt_places_rdmness); - registerParameter(&tgtscale); - registerParameter(&tgtlength); - registerParameter(&tgtlength_rdm); + registerParameter( dynamic_cast(&nbtangents) ); + registerParameter( dynamic_cast(&tgt_places_rdmness) ); + registerParameter( dynamic_cast(&tgtscale) ); + registerParameter( dynamic_cast(&tgtlength) ); + registerParameter( dynamic_cast(&tgtlength_rdm) ); #ifdef LPE_SKETCH_USE_CURVATURE - registerParameter(&min_curvature); - registerParameter(&max_curvature); + registerParameter( dynamic_cast(&min_curvature) ); + registerParameter( dynamic_cast(&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 69a4dfad9c..5f63e1ee96 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(&angle); - registerParameter(&t_attach); - registerParameter(&length_left); - registerParameter(&length_right); + registerParameter( dynamic_cast(&angle) ); + registerParameter( dynamic_cast(&t_attach) ); + registerParameter( dynamic_cast(&length_left) ); + registerParameter( dynamic_cast(&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 c484c88a20..3248937063 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(&step); - registerParameter(&point); - registerParameter(&path); + registerParameter( dynamic_cast(&step) ); + registerParameter( dynamic_cast(&point) ); + registerParameter( dynamic_cast(&path) ); point.set_oncanvas_looks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); - point.param_setValue(point); + point.param_setValue(point,true); } LPEdoEffectStackTest::~LPEdoEffectStackTest() diff --git a/src/live_effects/lpe-text_label.cpp b/src/live_effects/lpe-text_label.cpp index 0c1db2f04e..709d05e180 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(&label); + registerParameter( dynamic_cast(&label) ); } LPETextLabel::~LPETextLabel() diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 6927ee13d7..ef29007750 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -350,21 +350,6 @@ Gtk::Widget *LPETransform2Pts::newWidget() vbox->pack_start(*button2, true, true, 2); vbox->pack_start(*button3, true, true, 2); vbox->pack_start(*button4, true, true, 2); - if (show_default_widgets) { - Gtk::Label *default_label = Gtk::manage(new Gtk::Label( - Glib::ustring(_("Defaults set defaultable -prefs- parameters (*)")), - Gtk::ALIGN_START)); - default_label->set_use_markup(true); - vbox->pack_start(*default_label, true, true, 2); - Gtk::HBox * defaultBox = Gtk::manage(new Gtk::HBox(true,0)); - Gtk::Button *set_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Set")))); - set_default->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::setDefaultParams)); - Gtk::Button *reset_default = Gtk::manage(new Gtk::Button(Glib::ustring(_("Reset")))); - reset_default->signal_clicked().connect(sigc::mem_fun(*this, &LPETransform2Pts::resetDefaultParams)); - defaultBox->pack_start(*set_default, true, true, 2); - defaultBox->pack_start(*reset_default, true, true, 2); - vbox->pack_start(*defaultBox, true, true, 2); - } return dynamic_cast(vbox); } diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index b9fd8908a6..47e2a1cec1 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(&ref_path); - //registerParameter(&refA) ); - //registerParameter(&refB) ); - registerParameter(&generator); - registerParameter(&similar_only); - registerParameter(&nbgenerations); - registerParameter(&drawall); - registerParameter(&maxComplexity); - //registerParameter(&draw_boxes) ); + 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) ); apply_to_clippath_and_mask = true; nbgenerations.param_make_integer(); nbgenerations.param_set_range(0, Geom::infinity()); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index fa08e1f910..a600f02573 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 a031b5ceda..813c06b4e2 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -37,17 +37,11 @@ BoolParam::param_set_default() } void -BoolParam::param_update_default(bool default_value) +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) { @@ -66,18 +60,8 @@ Gtk::Widget * BoolParam::param_newWidget() { if(!hide_widget){ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredCheckButton( label, + new Inkscape::UI::Widget::RegisteredCheckButton( param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index a96966c46f..7ad8a9368a 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -36,9 +36,9 @@ public: void param_setValue(bool newvalue); virtual void param_set_default(); - void param_update_default(bool default_value); - virtual void param_update_default(const gchar * default_value); + void param_update_default(bool const 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 0bb2d89b22..dbfc686237 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -76,15 +76,7 @@ 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 4e42687034..b81339a69c 100644 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ b/src/live_effects/parameter/filletchamferpointarray.h @@ -55,7 +55,6 @@ 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 ee76c4ab94..64c203093a 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -33,11 +33,9 @@ FontButtonParam::param_set_default() { param_setValue(defvalue); } - void -FontButtonParam::param_update_default(const gchar * default_value) -{ - defvalue = (Glib::ustring)strdup(default_value); +FontButtonParam::param_update_default(const Glib::ustring default_value){ + defvalue = default_value; } bool @@ -58,24 +56,14 @@ FontButtonParam::param_getSVGValue() const Gtk::Widget * FontButtonParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredFontButton * fontbuttonwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredFontButton( label, + new Inkscape::UI::Widget::RegisteredFontButton( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - Glib::ustring fontspec = (Glib::ustring)param_getSVGValue(); + 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; @@ -83,12 +71,11 @@ FontButtonParam::param_newWidget() } void -FontButtonParam::param_setValue(Glib::ustring newvalue) +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 60e1aa46e9..df47251a2a 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 = "Sans 10"); + const Glib::ustring default_value = ""); virtual ~FontButtonParam() {} virtual Gtk::Widget * param_newWidget(); virtual bool param_readSVGValue(const gchar * strvalue); - void param_update_default(const gchar * default_value); + void param_update_default(const Glib::ustring defvalue); virtual gchar * param_getSVGValue() const; - void param_setValue(Glib::ustring newvalue); + void param_setValue(const 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 aba61b96a2..93cf2b15f0 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -60,10 +60,6 @@ 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() @@ -108,20 +104,10 @@ ItemParam::param_getSVGValue() const Gtk::Widget * ItemParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } 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(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); pButton->set_relief(Gtk::RELIEF_NONE); diff --git a/src/live_effects/parameter/item.h b/src/live_effects/parameter/item.h index 89c32f9bd4..6c719d4510 100644 --- a/src/live_effects/parameter/item.h +++ b/src/live_effects/parameter/item.h @@ -36,7 +36,6 @@ 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/originalitem.cpp b/src/live_effects/parameter/originalitem.cpp index 8db8851bfb..053062128e 100644 --- a/src/live_effects/parameter/originalitem.cpp +++ b/src/live_effects/parameter/originalitem.cpp @@ -46,20 +46,10 @@ OriginalItemParam::~OriginalItemParam() Gtk::Widget * OriginalItemParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); { // Label - Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(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); } diff --git a/src/live_effects/parameter/originalitem.h b/src/live_effects/parameter/originalitem.h index de1a6ac25d..58d04e05a1 100644 --- a/src/live_effects/parameter/originalitem.h +++ b/src/live_effects/parameter/originalitem.h @@ -26,6 +26,7 @@ public: void setInverse(bool inversed) { inverse = inversed; } bool linksToItem() const { return (href != NULL); } SPItem * getObject() const { return ref.getObject(); } + virtual Gtk::Widget * param_newWidget(); protected: diff --git a/src/live_effects/parameter/originalpath.cpp b/src/live_effects/parameter/originalpath.cpp index 388a3b5e66..1e78f7fe1c 100644 --- a/src/live_effects/parameter/originalpath.cpp +++ b/src/live_effects/parameter/originalpath.cpp @@ -47,20 +47,10 @@ OriginalPathParam::~OriginalPathParam() Gtk::Widget * OriginalPathParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Gtk::HBox *_widget = Gtk::manage(new Gtk::HBox()); { // Label - Gtk::Label *pLabel = Gtk::manage(new Gtk::Label(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); } diff --git a/src/live_effects/parameter/originalpatharray.h b/src/live_effects/parameter/originalpatharray.h index fe93716448..296c0f7f77 100644 --- a/src/live_effects/parameter/originalpatharray.h +++ b/src/live_effects/parameter/originalpatharray.h @@ -65,11 +65,12 @@ 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 359a519137..befac4df1b 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -107,16 +107,6 @@ 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) { @@ -172,18 +162,8 @@ Gtk::Widget * ScalarParam::param_newWidget() { if(!hide_widget){ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( - label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); rsu->setValue(value); rsu->setDigits(digits); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index ee1d2d547c..6cf10710c5 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,7 +77,6 @@ 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; @@ -85,6 +84,7 @@ public: bool widget_is_visible; protected: + Glib::ustring param_tooltip; Effect* param_effect; @@ -112,7 +112,6 @@ 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); @@ -121,6 +120,7 @@ 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 9bdebaf478..dafc6d406e 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -170,19 +170,9 @@ PathParam::param_getSVGValue() const Gtk::Widget * PathParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox()); - Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(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); @@ -449,10 +439,6 @@ 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 5381a6b361..d2dddbe97c 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -40,7 +40,6 @@ 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 2fbe4b3b4a..db768090ad 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -63,19 +63,6 @@ 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) { @@ -126,18 +113,8 @@ PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) Gtk::Widget * PointParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredTransformedPoint( label, + new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index a5153ad806..5d145a81aa 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -44,8 +44,6 @@ 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 a34163ca1d..56a609fa87 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 bcba053992..075e85ee1d 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -77,20 +77,6 @@ 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) { @@ -129,18 +115,8 @@ RandomParam::resetRandomizer() Gtk::Widget * RandomParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredRandom* regrandom = Gtk::manage( - new Inkscape::UI::Widget::RegisteredRandom( label, + new Inkscape::UI::Widget::RegisteredRandom( param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index 5fb6027acd..ca4440336e 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 5c56e84470..5c4cdf4c6d 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(const gchar * default_value) +TextParam::param_update_default(Glib::ustring default_value) { - defvalue = (Glib::ustring)default_value; + defvalue = default_value; } void @@ -119,18 +119,8 @@ TextParam::param_getSVGValue() const Gtk::Widget * TextParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( - label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); rsu->setText(value); rsu->setProgrammatically = false; @@ -140,7 +130,7 @@ TextParam::param_newWidget() } void -TextParam::param_setValue(Glib::ustring newvalue) +TextParam::param_setValue(const Glib::ustring newvalue) { param_effect->upd_params = true; value = newvalue; diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 137f3ee028..553c84c0ab 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(Glib::ustring newvalue); + void param_setValue(const Glib::ustring newvalue); void param_hide_canvas_text(); virtual void param_set_default(); - virtual void param_update_default(const gchar * default_value); + 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); void setAnchor(double x_value, double y_value); - const Glib::ustring get_value() const { return value; }; + const Glib::ustring get_value() const { return defvalue; }; private: TextParam(const TextParam&); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 1d1bc82a69..b3f6442bb8 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -60,37 +60,15 @@ 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() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } if (_toggled_connection.connected()) { _toggled_connection.disconnect(); } checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredToggleButton( 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 d6ca15e75b..8390fec866 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -51,8 +51,6 @@ 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 2081a8c0c4..0d03432c35 100644 --- a/src/live_effects/parameter/transformedpoint.cpp +++ b/src/live_effects/parameter/transformedpoint.cpp @@ -82,40 +82,11 @@ 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() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredVector * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredVector( label, + new Inkscape::UI::Widget::RegisteredVector( param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/transformedpoint.h b/src/live_effects/parameter/transformedpoint.h index 269cc508ef..c96bedb539 100644 --- a/src/live_effects/parameter/transformedpoint.h +++ b/src/live_effects/parameter/transformedpoint.h @@ -51,9 +51,7 @@ 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 684f295556..b6ea99bfe0 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 gchar * default_unit) +UnitParam::param_update_default(const Glib::ustring default_unit) { - defunit = unit_table.getUnit((Glib::ustring)default_unit); + defunit = unit_table.getUnit(default_unit); } void @@ -75,18 +75,8 @@ UnitParam::get_abbreviation() const Gtk::Widget * UnitParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredUnitMenu* unit_menu = Gtk::manage( - new Inkscape::UI::Widget::RegisteredUnitMenu(label, + new Inkscape::UI::Widget::RegisteredUnitMenu(param_label, param_key, *param_wr, param_effect->getRepr(), diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index c662b6edc3..ae58cf9569 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -33,10 +33,11 @@ public: virtual gchar * param_getSVGValue() const; virtual void param_set_default(); void param_set_value(Inkscape::Util::Unit const &val); - virtual void param_update_default(const gchar * default_unit); + void param_update_default(const Glib::ustring 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 d6593871da..55b4d4b328 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -48,25 +48,6 @@ 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) { @@ -104,18 +85,8 @@ VectorParam::param_getSVGValue() const Gtk::Widget * VectorParam::param_newWidget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(param_effect->effectType()); - Glib::ustring pref_path = (Glib::ustring)"/live_effects/" + - effectkey + - (Glib::ustring)"/" + - (Glib::ustring)param_key; - Glib::ustring label = param_label; - if(prefs->getEntry(pref_path).isValid()){ - label = (Glib::ustring)"* " + param_label; - } Inkscape::UI::Widget::RegisteredVector * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredVector( label, + new Inkscape::UI::Widget::RegisteredVector( param_label, param_tooltip, param_key, *param_wr, diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index d270e9f43d..edee4ff4d4 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -51,8 +51,7 @@ 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); diff --git a/src/preferences.cpp b/src/preferences.cpp index 2849fe068a..4d522a1d88 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -512,35 +512,6 @@ void Preferences::remove(Glib::ustring const &pref_path) Inkscape::XML::Node *node = _getNode(pref_path, false); if (node && node->parent()) { node->parent()->removeChild(node); - } else { //Handle to remove also attributes in path not only the container node - // verify path - g_assert( pref_path.at(0) == '/' ); - if (_prefs_doc == NULL){ - return; - } - node = _prefs_doc->root(); - Inkscape::XML::Node *child = NULL; - gchar **splits = g_strsplit(pref_path.c_str(), "/", 0); - if ( splits ) { - for (int part_i = 0; splits[part_i]; ++part_i) { - // skip empty path segments - if (!splits[part_i][0]) { - continue; - } - if (!node->firstChild()) { - node->setAttribute(splits[part_i], NULL); - g_strfreev(splits); - return; - } - for (child = node->firstChild(); child; child = child->next()) { - if (!strcmp(splits[part_i], child->attribute("id"))) { - break; - } - } - node = child; - } - } - g_strfreev(splits); } } diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 6e12104f0c..6464396134 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -27,10 +27,7 @@ #include "preferences.h" #include "verbs.h" #include "selcue.h" -#include "live_effects/effect-enum.h" -#include "live_effects/effect.h" -#include "live_effects/lpeobject.h" -#include "sp-defs.h" + #include "extension/internal/gdkpixbuf-input.h" #include "message-stack.h" #include "style.h" @@ -823,93 +820,6 @@ void InkscapePreferences::initPageUI() this->AddPage(_page_grids, _("Grids"), iter_ui, PREFS_PAGE_UI_GRIDS); initKeyboardShortcuts(iter_ui); - - _page_lpe.add_group_header( _("Allow set default to this parameters:")); - SPDocument * doc = SP_ACTIVE_DOCUMENT; - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); - lpe_repr->setAttribute("id", "deleteme"); - SPObject *lpeo = SP_OBJECT(doc->getDefs()->appendChildRepr(lpe_repr)); - Inkscape::GC::release(lpe_repr); - Inkscape::UI::Widget::Registry * wr; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - for ( int le = Inkscape::LivePathEffect::EffectType::BEND_PATH; le != Inkscape::LivePathEffect::EffectType::INVALID_LPE; ++le){ - Inkscape::LivePathEffect::EffectType lpenr = static_cast(le); - Glib::ustring effectname = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_label(lpenr); - Glib::ustring effectkey = (Glib::ustring)Inkscape::LivePathEffect::LPETypeConverter.get_key(lpenr); - bool is_text_label_lpe = effectkey == (Glib::ustring)"text_label"; - if (!effectname.empty() && !is_text_label_lpe){ - lpeo->setAttribute("effect", effectkey.c_str()); - LivePathEffectObject * lpeobj = dynamic_cast(lpeo); - Glib::ustring liveeffect = effectname +(Glib::ustring)_(":"); - Inkscape::LivePathEffect::Effect* effect = Inkscape::LivePathEffect::Effect::New(lpenr, lpeobj); - std::vector param_vector = effect->getParamVector(); - if (param_vector.size() == 1) { - continue; - } - std::vector::iterator it = param_vector.begin(); - Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); - vbox_expander->set_border_width(10); - vbox_expander->set_spacing(2); - while (it != param_vector.end()) { - Inkscape::LivePathEffect::Parameter * param = *it; - const gchar * key = param->param_key.c_str(); - if (strcmp(key,"is_visible") == 0 ){ - ++it; - continue; - } - const gchar * value = param->param_label.c_str(); - const gchar * tooltip_extra = _(". Toogling this check in preferences reset to default 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(); - bool set = false; - if(valid){ - set = true; - } - Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredCheckButton( param->param_label, - tooltip, - param->param_key, - *wr, - false, - NULL, - NULL) ); - checkwdg->setActive(set); - checkwdg->setProgrammatically = false; - checkwdg->signal_toggled().connect(sigc::bind(sigc::mem_fun(*this, &InkscapePreferences::defaultLpeUpdater), pref_path, checkwdg)); - vbox_expander->pack_start(*dynamic_cast (checkwdg), true, true, 2); - ++it; - } - - Gtk::Expander * expander = Gtk::manage(new Gtk::Expander(liveeffect)); - expander->add(*vbox_expander); - expander->set_expanded(false); - Glib::ustring tip = (Glib::ustring)_("Set defaultables parameters for ") + liveeffect; - _page_lpe.add_line( true, "", *dynamic_cast(expander), "", tip.c_str() ); - } - } - lpeo->deleteObject(); - this->AddPage(_page_lpe, _("Live Effects"), iter_ui, PREFS_PAGE_UI_LPE); -} - -void -InkscapePreferences::defaultLpeUpdater(Glib::ustring pref_path, Inkscape::UI::Widget::RegisteredCheckButton * checkwdg) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (checkwdg->get_active()) - { - prefs->setString(pref_path, "--default"); - - } else { - prefs->remove(pref_path); - prefs->remove((Glib::ustring)"/live_effects/gdsgddssdggdsgdsgdsgs"); - prefs->remove((Glib::ustring)"/ddsdsdsgdsg"); - } } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -2132,7 +2042,7 @@ bool InkscapePreferences::PresentPage(const Gtk::TreeModel::iterator& iter) _page_list.expand_row(_path_tools, false); if (desired_page >= PREFS_PAGE_TOOLS_SHAPES && desired_page <= PREFS_PAGE_TOOLS_SHAPES_SPIRAL) _page_list.expand_row(_path_shapes, false); - if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_LPE) + if (desired_page >= PREFS_PAGE_UI && desired_page <= PREFS_PAGE_UI_KEYBOARD_SHORTCUTS) _page_list.expand_row(_path_ui, false); if (desired_page >= PREFS_PAGE_BEHAVIOR && desired_page <= PREFS_PAGE_BEHAVIOR_MASKS) _page_list.expand_row(_path_behavior, false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 6320ff49c6..e6ba4e4b21 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -22,7 +22,6 @@ #include #include #include "ui/widget/preferences-widget.h" -#include "ui/widget/registered-widget.h" #include "ui/widget/button.h" #include #include @@ -31,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -75,7 +73,6 @@ enum { PREFS_PAGE_UI_WINDOWS, PREFS_PAGE_UI_GRIDS, PREFS_PAGE_UI_KEYBOARD_SHORTCUTS, - PREFS_PAGE_UI_LPE, PREFS_PAGE_BEHAVIOR, PREFS_PAGE_BEHAVIOR_SELECTING, PREFS_PAGE_BEHAVIOR_TRANSFORMS, @@ -190,7 +187,6 @@ protected: UI::Widget::DialogPage _page_spellcheck; UI::Widget::DialogPage _page_keyshortcuts; - UI::Widget::DialogPage _page_lpe; UI::Widget::PrefSpinButton _mouse_sens; UI::Widget::PrefSpinButton _mouse_thres; @@ -494,7 +490,7 @@ protected: Gtk::TreeModel::iterator AddPage(UI::Widget::DialogPage& p, Glib::ustring title, Gtk::TreeModel::iterator parent, int id); bool SetMaxDialogSize(const Gtk::TreeModel::iterator& iter); bool PresentPage(const Gtk::TreeModel::iterator& iter); - void defaultLpeUpdater(Glib::ustring pref_path, Inkscape::UI::Widget::RegisteredCheckButton * checkwdg); + static void AddSelcueCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); static void AddGradientCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); static void AddConvertGuidesCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); -- GitLab From e5601e5e84df30c40d93271fd69cecd31391e309 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 29 Apr 2017 02:01:22 +0200 Subject: [PATCH 112/121] 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 + .../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 + .../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 + .../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 +- src/preferences.cpp | 29 ++++ src/ui/dialog/livepatheffect-editor.cpp | 19 ++- 35 files changed, 351 insertions(+), 136 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index bfcca422ef..37694f32f0 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 f5e41d50ef..c34c391c0c 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 86d72615c7..52aa56fa0d 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 724c0d9248..b42f7cfd52 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 a600f02573..fa08e1f910 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 813c06b4e2..fafa713687 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 7ad8a9368a..39f328eaa7 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 dbfc686237..0bb2d89b22 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 b81339a69c..4e42687034 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 64c203093a..5ec98df8cf 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 df47251a2a..60e1aa46e9 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 93cf2b15f0..7b40f4540f 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 6c719d4510..89c32f9bd4 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 296c0f7f77..fe93716448 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 befac4df1b..15c81d5431 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 6cf10710c5..ee1d2d547c 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 dafc6d406e..aa87508ab9 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 d2dddbe97c..5381a6b361 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 db768090ad..561f1b34c1 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 5d145a81aa..a5153ad806 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 56a609fa87..a34163ca1d 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 075e85ee1d..90e53ca0e9 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 ca4440336e..5fb6027acd 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 5c4cdf4c6d..84603149e2 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 553c84c0ab..137f3ee028 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 b3f6442bb8..b8058e9c82 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 8390fec866..d6ca15e75b 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 0d03432c35..22d5ba3a43 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 c96bedb539..269cc508ef 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 b6ea99bfe0..b78b75dbf1 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 ae58cf9569..c662b6edc3 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 55b4d4b328..470fa9c2d8 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 edee4ff4d4..d270e9f43d 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); diff --git a/src/preferences.cpp b/src/preferences.cpp index 4d522a1d88..2849fe068a 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -512,6 +512,35 @@ void Preferences::remove(Glib::ustring const &pref_path) Inkscape::XML::Node *node = _getNode(pref_path, false); if (node && node->parent()) { node->parent()->removeChild(node); + } else { //Handle to remove also attributes in path not only the container node + // verify path + g_assert( pref_path.at(0) == '/' ); + if (_prefs_doc == NULL){ + return; + } + node = _prefs_doc->root(); + Inkscape::XML::Node *child = NULL; + gchar **splits = g_strsplit(pref_path.c_str(), "/", 0); + if ( splits ) { + for (int part_i = 0; splits[part_i]; ++part_i) { + // skip empty path segments + if (!splits[part_i][0]) { + continue; + } + if (!node->firstChild()) { + node->setAttribute(splits[part_i], NULL); + g_strfreev(splits); + return; + } + for (child = node->firstChild(); child; child = child->next()) { + if (!strcmp(splits[part_i], child->attribute("id"))) { + break; + } + } + node = child; + } + } + g_strfreev(splits); } } diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index e5becdb5cd..455c12bc30 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -19,7 +19,7 @@ #include "livepatheffect-editor.h" #include "desktop.h" - +#include #include "document.h" #include "document-undo.h" #include "helper/action.h" @@ -193,8 +193,14 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) if ( ! effect.upd_params ) { return; } - + bool expanderopen = false; if (effectwidget) { + Gtk::Expander * expander = NULL; + std::vector childs = dynamic_cast (effectwidget)->get_children(); + std::vector childs_default = dynamic_cast (childs[childs.size()-1])->get_children(); + if ((expander = dynamic_cast(childs_default[childs_default.size()-1]))){ + expanderopen = expander->get_expanded(); + } effectcontrol_vbox.remove(*effectwidget); delete effectwidget; effectwidget = NULL; @@ -204,6 +210,15 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) effectwidget = effect.newWidget(); if (effectwidget) { + Gtk::Widget * defaultswidget = effect.defaultParamSet(); + if (defaultswidget) { + Gtk::Expander * expander = NULL; + std::vector childs_default = dynamic_cast (defaultswidget)->get_children(); + if ((expander = dynamic_cast(childs_default[childs_default.size()-1]))){ + expander->set_expanded(expanderopen); + } + dynamic_cast (effectwidget)->pack_start(*defaultswidget, true, true); + } effectcontrol_vbox.pack_start(*effectwidget, true, true); } button_remove.show(); -- GitLab From a54924aece45764357c36d22d0475ef640b75ba1 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 29 Apr 2017 16:40:51 +0200 Subject: [PATCH 113/121] 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 + src/ui/dialog/livepatheffect-editor.cpp | 15 +++++++++------ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 37694f32f0..22cc5567b1 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 1423e670a2..5c227e68a3 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 15c81d5431..e35c89c094 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; } diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 455c12bc30..f0ccce6d44 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -194,12 +194,15 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) return; } bool expanderopen = false; + Gtk::Widget * defaultswidget = effect.defaultParamSet(); if (effectwidget) { - Gtk::Expander * expander = NULL; - std::vector childs = dynamic_cast (effectwidget)->get_children(); - std::vector childs_default = dynamic_cast (childs[childs.size()-1])->get_children(); - if ((expander = dynamic_cast(childs_default[childs_default.size()-1]))){ - expanderopen = expander->get_expanded(); + if (defaultswidget) { + Gtk::Expander * expander = NULL; + std::vector childs = dynamic_cast (effectwidget)->get_children(); + std::vector childs_default = dynamic_cast (childs[childs.size()-1])->get_children(); + if ((expander = dynamic_cast(childs_default[childs_default.size()-1]))){ + expanderopen = expander->get_expanded(); + } } effectcontrol_vbox.remove(*effectwidget); delete effectwidget; @@ -210,7 +213,7 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) effectwidget = effect.newWidget(); if (effectwidget) { - Gtk::Widget * defaultswidget = effect.defaultParamSet(); + if (defaultswidget) { Gtk::Expander * expander = NULL; std::vector childs_default = dynamic_cast (defaultswidget)->get_children(); -- GitLab From 36dbe5ea8d5bcaba57339df7b0344ca91dce3dd9 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Mon, 1 May 2017 04:04:06 +0200 Subject: [PATCH 114/121] Remove couts (bzr r15620.1.16) --- src/live_effects/parameter/parameter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 5697367355..ccf8f37e77 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; } -- GitLab From e96605dc4a7ca1e990a52380744e5649da2d54f2 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Thu, 4 May 2017 23:41:22 +0200 Subject: [PATCH 115/121] cmake/MSYS2: adjust fonts.conf to store fontconfig cache in AppData MSYS2 uses '/var/cache/fontconfig' by default which is not available outside of the MSYS environment and therefore get's created in the root folder of the Inkscape installation. On most systems this will be in read-only 'Program Files' (which might still work thanks to virtual store, but better be safe then sorry). This also makes sure we do not re-introduce bug #1196373 (bzr r15660.1.1) --- CMakeScripts/InstallMSYS2.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeScripts/InstallMSYS2.cmake b/CMakeScripts/InstallMSYS2.cmake index aac4fd6482..c8c580fe4e 100644 --- a/CMakeScripts/InstallMSYS2.cmake +++ b/CMakeScripts/InstallMSYS2.cmake @@ -166,7 +166,20 @@ if(WIN32) install(DIRECTORY ${MINGW_PATH}/share/glib-2.0/schemas DESTINATION ${CMAKE_INSTALL_PREFIX}/share/glib-2.0) + # fontconfig install(DIRECTORY ${MINGW_PATH}/etc/fonts + DESTINATION ${CMAKE_INSTALL_PREFIX}/etc + FILES_MATCHING PATTERN "fonts.conf" EXCLUDE) + # adjust fonts.conf to store font cache in AppData + set(cachedir_default "\\t^/var/cache/fontconfig^") # the '^' are needed to escape angle brackets on Windows command shell + set(cachedir_appdata "\\t^LOCAL_APPDATA_FONTCONFIG_CACHE^") + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/etc/fonts/fonts.conf + COMMAND sed 's!${cachedir_default}!${cachedir_appdata}\\n${cachedir_default}!' ${MINGW_PATH}/etc/fonts/fonts.conf > ${CMAKE_BINARY_DIR}/etc/fonts/fonts.conf + MAIN_DEPENDENCY ${MINGW_PATH}/etc/fonts/fonts.conf + ) + add_custom_target(fonts_conf ALL DEPENDS ${CMAKE_BINARY_DIR}/etc/fonts/fonts.conf) + install(DIRECTORY ${CMAKE_BINARY_DIR}/etc/fonts DESTINATION ${CMAKE_INSTALL_PREFIX}/etc) # GTK 3.0 -- GitLab From 9c86d51cffce9087d40d07963636f385ec1e5759 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 5 May 2017 03:18:37 +0200 Subject: [PATCH 116/121] parameter refactor (bzr r15661) --- src/live_effects/CMakeLists.txt | 6 +- src/live_effects/effect.cpp | 16 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-angle_bisector.cpp | 4 +- src/live_effects/lpe-attach-path.cpp | 12 +- src/live_effects/lpe-bendpath.cpp | 8 +- src/live_effects/lpe-bspline.cpp | 22 +- src/live_effects/lpe-clone-original.cpp | 6 +- src/live_effects/lpe-constructgrid.cpp | 8 +- src/live_effects/lpe-copy_rotate.cpp | 28 +- src/live_effects/lpe-curvestitch.cpp | 16 +- src/live_effects/lpe-dynastroke.cpp | 10 +- src/live_effects/lpe-fillet-chamfer.cpp | 668 -------------- src/live_effects/lpe-fillet-chamfer.h | 93 -- src/live_effects/lpe-gears.cpp | 6 +- src/live_effects/lpe-interpolate.cpp | 6 +- src/live_effects/lpe-jointype.cpp | 16 +- src/live_effects/lpe-knot.cpp | 6 +- src/live_effects/lpe-knot.h | 2 +- src/live_effects/lpe-lattice.cpp | 30 +- src/live_effects/lpe-lattice2.cpp | 154 +-- src/live_effects/lpe-measure-line.cpp | 92 +- src/live_effects/lpe-mirror_symmetry.cpp | 16 +- src/live_effects/lpe-offset.cpp | 2 +- src/live_effects/lpe-parallel.cpp | 6 +- src/live_effects/lpe-patternalongpath.cpp | 20 +- src/live_effects/lpe-perp_bisector.cpp | 4 +- src/live_effects/lpe-perspective-envelope.cpp | 16 +- src/live_effects/lpe-perspective_path.cpp | 4 +- src/live_effects/lpe-powerstroke.cpp | 4 +- src/live_effects/lpe-recursiveskeleton.cpp | 4 +- src/live_effects/lpe-rough-hatches.cpp | 24 +- src/live_effects/lpe-roughen.cpp | 20 +- src/live_effects/lpe-ruler.cpp | 12 +- src/live_effects/lpe-show_handles.cpp | 6 +- src/live_effects/lpe-simplify.cpp | 24 +- src/live_effects/lpe-sketch.cpp | 40 +- src/live_effects/lpe-tangent_to_curve.cpp | 8 +- src/live_effects/lpe-taperstroke.cpp | 26 +- src/live_effects/lpe-test-doEffect-stack.cpp | 2 +- src/live_effects/lpe-transform_2pts.cpp | 84 +- src/live_effects/lpe-vonkoch.cpp | 16 +- src/live_effects/lpe-vonkoch.h | 8 +- src/live_effects/parameter/array.cpp | 6 +- src/live_effects/parameter/array.h | 16 +- src/live_effects/parameter/bool.cpp | 62 +- src/live_effects/parameter/bool.h | 20 +- src/live_effects/parameter/enum.h | 41 +- .../parameter/filletchamferpointarray.cpp | 873 ------------------ .../parameter/filletchamferpointarray.h | 122 --- src/live_effects/parameter/fontbutton.cpp | 50 +- src/live_effects/parameter/fontbutton.h | 19 +- src/live_effects/parameter/item.cpp | 15 +- src/live_effects/parameter/item.h | 12 +- src/live_effects/parameter/originalpath.h | 2 +- .../parameter/originalpatharray.cpp | 14 +- .../parameter/originalpatharray.h | 10 +- src/live_effects/parameter/parameter.cpp | 152 +-- src/live_effects/parameter/parameter.h | 88 +- src/live_effects/parameter/path.cpp | 32 +- src/live_effects/parameter/path.h | 12 +- src/live_effects/parameter/point.cpp | 26 +- src/live_effects/parameter/point.h | 14 +- .../parameter/powerstrokepointarray.cpp | 12 +- .../parameter/powerstrokepointarray.h | 4 +- src/live_effects/parameter/random.cpp | 18 +- src/live_effects/parameter/random.h | 10 +- src/live_effects/parameter/text.cpp | 14 +- src/live_effects/parameter/text.h | 6 +- src/live_effects/parameter/togglebutton.cpp | 6 +- src/live_effects/parameter/togglebutton.h | 4 +- .../parameter/transformedpoint.cpp | 6 +- src/live_effects/parameter/transformedpoint.h | 4 +- src/live_effects/parameter/unit.cpp | 10 +- src/live_effects/parameter/unit.h | 6 +- src/live_effects/parameter/vector.cpp | 6 +- src/live_effects/parameter/vector.h | 4 +- src/ui/CMakeLists.txt | 2 - src/ui/dialog/livepatheffect-editor.cpp | 5 + .../dialog/lpe-fillet-chamfer-properties.cpp | 266 ------ src/ui/dialog/lpe-fillet-chamfer-properties.h | 109 --- 81 files changed, 651 insertions(+), 2983 deletions(-) delete mode 100644 src/live_effects/lpe-fillet-chamfer.cpp delete mode 100644 src/live_effects/lpe-fillet-chamfer.h delete mode 100644 src/live_effects/parameter/filletchamferpointarray.cpp delete mode 100644 src/live_effects/parameter/filletchamferpointarray.h delete mode 100644 src/ui/dialog/lpe-fillet-chamfer-properties.cpp delete mode 100644 src/ui/dialog/lpe-fillet-chamfer-properties.h diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 5ffccc7c0f..e310e1ff64 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -18,7 +18,6 @@ set(live_effects_SRC lpe-extrude.cpp lpe-fill-between-many.cpp lpe-fill-between-strokes.cpp - lpe-fillet-chamfer.cpp lpe-gears.cpp lpe-interpolate.cpp lpe-interpolate_points.cpp @@ -59,7 +58,6 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp - parameter/filletchamferpointarray.cpp parameter/item-reference.cpp parameter/item.cpp parameter/originalitem.cpp @@ -71,6 +69,7 @@ set(live_effects_SRC parameter/point.cpp parameter/powerstrokepointarray.cpp parameter/random.cpp + parameter/scalar.cpp parameter/text.cpp parameter/fontbutton.cpp parameter/togglebutton.cpp @@ -101,7 +100,6 @@ set(live_effects_SRC lpe-extrude.h lpe-fill-between-many.h lpe-fill-between-strokes.h - lpe-fillet-chamfer.h lpe-gears.h lpe-interpolate.h lpe-interpolate_points.h @@ -144,7 +142,6 @@ set(live_effects_SRC parameter/array.h parameter/bool.h parameter/enum.h - parameter/filletchamferpointarray.h parameter/item.h parameter/item-reference.h parameter/originalitem.h @@ -156,6 +153,7 @@ set(live_effects_SRC parameter/point.h parameter/powerstrokepointarray.h parameter/random.h + parameter/scalar.h parameter/text.h parameter/fontbutton.h parameter/togglebutton.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 326225e0c6..a58c401d8f 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 @@ -575,9 +576,10 @@ Effect::doAcceptPathPreparations(SPLPEItem *lpeitem) void Effect::writeParamsToSVG() { + upd_params = true; std::vector::iterator p; for (p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->write_to_SVG(); + (*p)->writeToSVG(); } } @@ -655,7 +657,7 @@ Effect::readallParameters(Inkscape::XML::Node const* repr) } } else { // set default value - param->param_set_default(); + param->param_valueFromDefault(); } ++it; @@ -675,7 +677,7 @@ Effect::setParameter(const gchar * key, const gchar * new_value) } } else { // set default value - param->param_set_default(); + param->param_valueFromDefault(); } } } @@ -842,7 +844,7 @@ Effect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop) Parameter * param = getNextOncanvasEditableParam(); if (param) { - param->param_editOncanvas(item, desktop); + param->param_editOnCanvas(item, desktop); gchar *message = g_strdup_printf(_("Editing parameter %s."), param->param_label.c_str()); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, message); g_free(message); @@ -860,8 +862,8 @@ Effect::resetDefaults(SPItem const* /*item*/) { std::vector::iterator p; for (p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->param_set_default(); - (*p)->write_to_SVG(); + (*p)->param_valueFromDefault(); + (*p)->writeToSVG(); } } @@ -871,7 +873,7 @@ Effect::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); + param->param_transformMultiply(postmul, set); } } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 973516133d..f5e41d50ef 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-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index 56d33eb4b3..9cd270a729 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -101,7 +101,7 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori Geom::Point const s = snap_knot_position(p, state); double lambda = Geom::nearest_time(s, lpe->ptA, lpe->dir); - lpe->length_left.param_set_value(-lambda); + lpe->length_left.param_setValue(-lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -114,7 +114,7 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or Geom::Point const s = snap_knot_position(p, state); double lambda = Geom::nearest_time(s, lpe->ptA, lpe->dir); - lpe->length_right.param_set_value(lambda); + lpe->length_right.param_setValue(lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp index 3021657191..8759e6e2c1 100644 --- a/src/live_effects/lpe-attach-path.cpp +++ b/src/live_effects/lpe-attach-path.cpp @@ -79,13 +79,13 @@ void LPEAttachPath::doEffect (SPCurve * curve) Geom::Coord length = derivs[deriv_n].length(); if ( ! Geom::are_near(length, 0) ) { if (set_start_end) { - start_path_position.param_set_value(transformedpath.nearestTime(start_path_curve_end.getOrigin()).asFlatTime()); + start_path_position.param_setValue(transformedpath.nearestTime(start_path_curve_end.getOrigin()).asFlatTime()); } if (start_path_position > transformedpath.size()) { - start_path_position.param_set_value(transformedpath.size()); + start_path_position.param_setValue(transformedpath.size()); } else if (start_path_position < 0) { - start_path_position.param_set_value(0); + start_path_position.param_setValue(0); } Geom::Curve const *c = start_path_position >= transformedpath.size() ? &transformedpath.back() : &transformedpath.at((int)start_path_position); @@ -134,13 +134,13 @@ void LPEAttachPath::doEffect (SPCurve * curve) Geom::Coord length = derivs[deriv_n].length(); if ( ! Geom::are_near(length, 0) ) { if (set_end_end) { - end_path_position.param_set_value(transformedpath.nearestTime(end_path_curve_end.getOrigin()).asFlatTime()); + end_path_position.param_setValue(transformedpath.nearestTime(end_path_curve_end.getOrigin()).asFlatTime()); } if (end_path_position > transformedpath.size()) { - end_path_position.param_set_value(transformedpath.size()); + end_path_position.param_setValue(transformedpath.size()); } else if (end_path_position < 0) { - end_path_position.param_set_value(0); + end_path_position.param_setValue(0); } const Geom::Curve *c = end_path_position >= transformedpath.size() ? &transformedpath.back() : &transformedpath.at((int)end_path_position); diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 363356cac9..f076a56482 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -62,8 +62,8 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : registerParameter( &scale_y_rel); registerParameter( &vertical_pattern); - prop_scale.param_set_digits(3); - prop_scale.param_set_increments(0.01, 0.10); + prop_scale.param_setDigits(3); + prop_scale.param_setIncrements(0.01, 0.10); _provides_knotholder_entities = true; apply_to_clippath_and_mask = true; @@ -185,9 +185,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.param_setValue(-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.param_setValue(Geom::distance(s , ptA)/(lpe->original_height/2.0)); } sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 1423e670a2..ddb541a593 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -41,19 +41,19 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) registerParameter(&apply_with_weight); registerParameter(&only_selected); - 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_setRange(NO_POWER, 100.0); + weight.param_setIncrements(0.1, 0.1); + weight.param_setDigits(4); + weight.param_overwriteWidget(true); - steps.param_set_range(1, 10); - steps.param_set_increments(1, 1); - steps.param_set_digits(0); - steps.param_overwrite_widget(true); + steps.param_setRange(1, 10); + steps.param_setIncrements(1, 1); + steps.param_setDigits(0); + steps.param_overwriteWidget(true); - helper_size.param_set_range(0.0, 999.0); - helper_size.param_set_increments(1, 1); - helper_size.param_set_digits(2); + helper_size.param_setRange(0.0, 999.0); + helper_size.param_setIncrements(1, 1); + helper_size.param_setDigits(2); } LPEBSpline::~LPEBSpline() {} diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index d97a990afd..1453b5d1ae 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -57,9 +57,9 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : registerParameter(&paintorder); registerParameter(&opacity); registerParameter(&filter); - scale.param_set_range(0.01, 999999.0); - scale.param_set_increments(1, 1); - scale.param_set_digits(2); + scale.param_setRange(0.01, 999999.0); + scale.param_setIncrements(1, 1); + scale.param_setDigits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); preserve_position_changed = preserve_position; diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index db620fa956..ec85d27b23 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -27,10 +27,10 @@ LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) : registerParameter(&nr_x); registerParameter(&nr_y); - nr_x.param_make_integer(); - nr_y.param_make_integer(); - nr_x.param_set_range(1, 1e10); - nr_y.param_set_range(1, 1e10); + nr_x.param_makeInteger(); + nr_y.param_makeInteger(); + nr_x.param_setRange(1, 1e10); + nr_y.param_setRange(1, 1e10); } LPEConstructGrid::~LPEConstructGrid() diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 900fc8b679..b3a25375ad 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -87,11 +87,11 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&mirror_copies); registerParameter(&split_items); - 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); - num_copies.param_make_integer(true); + gap.param_setRange(-99999.0, 99999.0); + gap.param_setIncrements(0.1, 0.1); + gap.param_setDigits(5); + num_copies.param_setRange(1, 999999); + num_copies.param_makeInteger(true); apply_to_clippath_and_mask = true; previous_num_copies = num_copies; reset = false; @@ -340,7 +340,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_update_default(A); + origin.param_updateDefault(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); } @@ -351,7 +351,7 @@ 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); + param->param_transformMultiply(postmul, set); } sp_lpe_item_update_patheffect(sp_lpe_item, false, false); } @@ -362,20 +362,20 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; original_bbox(lpeitem); if (copies_to_360 && num_copies > 2) { - rotation_angle.param_set_value(360.0/(double)num_copies); + rotation_angle.param_setValue(360.0/(double)num_copies); } if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && rotation_angle * num_copies > 360.1 && rotation_angle > 0) { - num_copies.param_set_value(floor(360/rotation_angle)); + num_copies.param_setValue(floor(360/rotation_angle)); } if ((method == RM_KALEIDOSCOPE || method == RM_FUSE) && mirror_copies && copies_to_360) { - num_copies.param_set_increments(2.0,10.0); + num_copies.param_setIncrements(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); + num_copies.param_setValue(num_copies+1); + rotation_angle.param_setValue(360.0/(double)num_copies); } } else { - num_copies.param_set_increments(1.0, 10.0); + num_copies.param_setIncrements(1.0, 10.0); } A = Point(boundingbox_X.min(), boundingbox_Y.middle()); @@ -388,7 +388,7 @@ 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) { - starting_angle.param_set_value(deg_from_rad(-angle_between(dir, starting_point - origin))); + starting_angle.param_setValue(deg_from_rad(-angle_between(dir, starting_point - origin))); if (GDK_SHIFT_MASK) { dist_angle_handle = L2(B - A); } else { diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index f8d2e56ca0..965bf48325 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -49,11 +49,11 @@ LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) : registerParameter(&prop_scale); registerParameter(&scale_y_rel); - nrofpaths.param_make_integer(); - nrofpaths.param_set_range(2, Geom::infinity()); + nrofpaths.param_makeInteger(); + nrofpaths.param_setRange(2, Geom::infinity()); - prop_scale.param_set_digits(3); - prop_scale.param_set_increments(0.01, 0.10); + prop_scale.param_setDigits(3); + prop_scale.param_setIncrements(0.01, 0.10); transformed = false; } @@ -174,11 +174,11 @@ LPECurveStitch::resetDefaults(SPItem const* item) strokepath.set_new_value( path.toPwSb(), true ); } else { // bounding box is too small to make decent path. set to default default. :-) - strokepath.param_set_and_write_default(); + strokepath.param_valueFromDefault( true ); } } else { // bounding box is non-existent. set to default default. :-) - strokepath.param_set_and_write_default(); + strokepath.param_valueFromDefault( true ); } } @@ -193,10 +193,10 @@ LPECurveStitch::transform_multiply(Geom::Affine const& postmul, bool set) { // only take translations into account if (postmul.isTranslation()) { - strokepath.param_transform_multiply(postmul, set); + strokepath.param_transformMultiply(postmul, set); } else if (!scale_y_rel.get_value()) { transformed = true; - strokepath.param_transform_multiply(postmul, set); + strokepath.param_transformMultiply(postmul, set); } } diff --git a/src/live_effects/lpe-dynastroke.cpp b/src/live_effects/lpe-dynastroke.cpp index 33e754a8ab..e94c5153b6 100644 --- a/src/live_effects/lpe-dynastroke.cpp +++ b/src/live_effects/lpe-dynastroke.cpp @@ -67,11 +67,11 @@ LPEDynastroke::LPEDynastroke(LivePathEffectObject *lpeobject) : registerParameter(&round_ends); registerParameter(&capping); - width.param_set_range(0, Geom::infinity()); - roundness.param_set_range(0.01, 1); - angle.param_set_range(-360, 360); - growfor.param_set_range(0, Geom::infinity()); - fadefor.param_set_range(0, Geom::infinity()); + width.param_setRange(0, Geom::infinity()); + roundness.param_setRange(0.01, 1); + angle.param_setRange(-360, 360); + growfor.param_setRange(0, Geom::infinity()); + fadefor.param_setRange(0, Geom::infinity()); show_orig_path = true; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp deleted file mode 100644 index 1e2df7dc8b..0000000000 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ /dev/null @@ -1,668 +0,0 @@ -/* - * Author(s): - * Jabiertxo Arraiza Cenoz - * - * 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 - */ -#include "live_effects/lpe-fillet-chamfer.h" - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/elliptical-arc.h> - -#include "display/curve.h" -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" -#include "helper/geom.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 { -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), - 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) -{ - registerParameter(&fillet_chamfer_values); - 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); - 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, infinity()); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); - helper_size.param_overwrite_widget(true); - fillet_chamfer_values.set_chamfer_steps(3); -} - -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); - 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) { - 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 = radius * -1; - } else { - power = radius; - } - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doUpdateFillet(path_from_piecewise(pwd2, tolerance), power); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); -} - -void LPEFilletChamfer::fillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 1); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Convert to fillet")); -} - -void LPEFilletChamfer::inverseFillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 2); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Convert to inverse fillet")); -} - -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); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); -} - -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); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Convert to chamfer")); -} - -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); - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Convert to inverse fillet")); -} - -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); - } - DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Knots and helper paths refreshed")); -} - -void LPEFilletChamfer::doUpdateFillet(Geom::PathVector const &original_pathv, double power) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - Geom::PathVector 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(Geom::PathVector const &original_pathv, int type) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - Geom::PathVector 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); - 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_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(); - } - } - int counter = 0; - while (curve_it1 != curve_endit) { - std::pair positions = fillet_chamfer_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; - } - } 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)); - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - } - } - fillet_chamfer_values.param_set_and_write_new_value(point); - } else { - g_warning("LPE Fillet 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_use_distance(use_knot_distance); - 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 (Geom::PathVector::const_iterator path_it = pv.begin(); - path_it != pv.end(); ++path_it) { - if (!(*path_it).closed()) { - nKnots--; - } - } - return nKnots; -} - -void -LPEFilletChamfer::adjustForNewPath(Geom::PathVector 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()); - } -} - -Geom::PathVector -LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) -{ - Geom::PathVector 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); - Geom::PathVector 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 */ - -/* - 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-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h deleted file mode 100644 index 290a37f928..0000000000 --- a/src/live_effects/lpe-fillet-chamfer.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef INKSCAPE_LPE_FILLET_CHAMFER_H -#define INKSCAPE_LPE_FILLET_CHAMFER_H - -/* - * Author(s): - * Jabiertxo Arraiza Cenoz - * - * 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 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/enum.h" -#include "live_effects/parameter/bool.h" -#include "live_effects/parameter/unit.h" - -#include "live_effects/parameter/filletchamferpointarray.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 Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - - virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(Geom::PathVector 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(Geom::PathVector const& original_pathv, double power); - void doChangeType(Geom::PathVector const& original_pathv, int type); - void refreshKnots(); - - FilletChamferPointArrayParam fillet_chamfer_values; - -private: - - BoolParam hide_knots; - BoolParam ignore_radius_0; - BoolParam only_selected; - BoolParam flexible; - BoolParam use_knot_distance; - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - ScalarParam helper_size; - - LPEFilletChamfer(const LPEFilletChamfer &); - LPEFilletChamfer &operator=(const LPEFilletChamfer &); - -}; - -} //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/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index dad520041d..2646472229 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -216,9 +216,9 @@ LPEGears::LPEGears(LivePathEffectObject *lpeobject) : * allows the teeth to have higher capacity and also allows fewer teeth without undercutting. */ - teeth.param_make_integer(); - teeth.param_set_range(3, 1e10); - min_radius.param_set_range(0.01, 9999.0); + teeth.param_makeInteger(); + teeth.param_setRange(3, 1e10); + min_radius.param_setRange(0.01, 9999.0); registerParameter(&teeth); registerParameter(&phi); registerParameter(&min_radius); diff --git a/src/live_effects/lpe-interpolate.cpp b/src/live_effects/lpe-interpolate.cpp index db3faa307c..cf7d539c71 100644 --- a/src/live_effects/lpe-interpolate.cpp +++ b/src/live_effects/lpe-interpolate.cpp @@ -34,8 +34,8 @@ LPEInterpolate::LPEInterpolate(LivePathEffectObject *lpeobject) : registerParameter(&equidistant_spacing); registerParameter(&number_of_steps); - number_of_steps.param_make_integer(); - number_of_steps.param_set_range(2, Geom::infinity()); + number_of_steps.param_makeInteger(); + number_of_steps.param_setRange(2, Geom::infinity()); } LPEInterpolate::~LPEInterpolate() @@ -117,7 +117,7 @@ LPEInterpolate::resetDefaults(SPItem const* item) traj_pathv[0].appendNew( bounds_B->midpoint() ); trajectory_path.set_new_value( traj_pathv, true ); } else { - trajectory_path.param_set_and_write_default(); + trajectory_path.param_valueFromDefault( true ); } } diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index dacb87dd96..6d2d6d1097 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -65,12 +65,12 @@ LPEJoinType::LPEJoinType(LivePathEffectObject *lpeobject) : //registerParameter(&end_lean); registerParameter(&miter_limit); registerParameter(&attempt_force_join); - //start_lean.param_set_range(-1,1); - //start_lean.param_set_increments(0.1, 0.1); - //start_lean.param_set_digits(4); - //end_lean.param_set_range(-1,1); - //end_lean.param_set_increments(0.1, 0.1); - //end_lean.param_set_digits(4); + //start_lean.param_setRange(-1,1); + //start_lean.param_setIncrements(0.1, 0.1); + //start_lean.param_setDigits(4); + //end_lean.param_setRange(-1,1); + //end_lean.param_setIncrements(0.1, 0.1); + //end_lean.param_setDigits(4); } LPEJoinType::~LPEJoinType() @@ -110,8 +110,8 @@ 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); - line_width.write_to_SVG(); + line_width.param_setValue(width); + line_width.writeToSVG(); } } diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 261612fdb3..1cc7d97881 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -300,7 +300,7 @@ idx_of_nearest(CrossingPoints const &cpts, Geom::Point const &p) //TODO: Find a way to warn the user when the topology changes. //TODO: be smarter at guessing the signs when the topology changed? void -CrossingPoints::inherit_signs(CrossingPoints const &other, int default_value) +CrossingPoints::inherit_signs(CrossingPoints const &other, int defaultvalue) { bool topo_changed = false; for (unsigned n=0; n < size(); n++){ @@ -325,7 +325,7 @@ CrossingPoints::inherit_signs(CrossingPoints const &other, int default_value) if (idx < other.size()) { (*this)[n].sign = other[idx].sign; } else { - (*this)[n].sign = default_value; + (*this)[n].sign = defaultvalue; } } } @@ -655,7 +655,7 @@ KnotHolderEntityCrossingSwitcher::knot_click(guint state) lpe->crossing_points[s].sign = ((sign+2)%3)-1; //std::cout<<"crossing set to"<crossing_points[s].sign<<".\n"; } - lpe->crossing_points_vector.param_set_and_write_new_value(lpe->crossing_points.to_vector()); + lpe->crossing_points_vector.param_setAndWriteNewValue(lpe->crossing_points.to_vector()); DocumentUndo::done(lpe->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, /// @todo Is this the right verb? _("Change knot crossing")); diff --git a/src/live_effects/lpe-knot.h b/src/live_effects/lpe-knot.h index ac518b97c6..54ecfceea3 100644 --- a/src/live_effects/lpe-knot.h +++ b/src/live_effects/lpe-knot.h @@ -47,7 +47,7 @@ public: CrossingPoints(std::vector const &input); std::vector to_vector(); CrossingPoint get(unsigned const i, unsigned const ni); - void inherit_signs(CrossingPoints const &from_other, int default_value = 1); + void inherit_signs(CrossingPoints const &from_other, int defaultvalue = 1); }; } diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 124a7a9c6a..aad63dc8a1 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -222,21 +222,21 @@ LPELattice::resetDefaults(SPItem const* item) grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); - grid_point1.param_update_default(grid_point1); - grid_point2.param_update_default(grid_point2); - grid_point3.param_update_default(grid_point3); - grid_point4.param_update_default(grid_point4); - grid_point5.param_update_default(grid_point5); - grid_point6.param_update_default(grid_point6); - grid_point7.param_update_default(grid_point7); - grid_point8.param_update_default(grid_point8); - grid_point9.param_update_default(grid_point9); - grid_point10.param_update_default(grid_point10); - grid_point11.param_update_default(grid_point11); - grid_point12.param_update_default(grid_point12); - grid_point13.param_update_default(grid_point13); - grid_point14.param_update_default(grid_point14); - grid_point15.param_update_default(grid_point15); + grid_point1.param_updateDefault(grid_point1); + grid_point2.param_updateDefault(grid_point2); + grid_point3.param_updateDefault(grid_point3); + grid_point4.param_updateDefault(grid_point4); + grid_point5.param_updateDefault(grid_point5); + grid_point6.param_updateDefault(grid_point6); + grid_point7.param_updateDefault(grid_point7); + grid_point8.param_updateDefault(grid_point8); + grid_point9.param_updateDefault(grid_point9); + grid_point10.param_updateDefault(grid_point10); + grid_point11.param_updateDefault(grid_point11); + grid_point12.param_updateDefault(grid_point12); + grid_point13.param_updateDefault(grid_point13); + grid_point14.param_updateDefault(grid_point14); + grid_point15.param_updateDefault(grid_point15); } /** diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index e827491c04..6c5ce3014d 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -322,8 +322,8 @@ LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); setDefaults(); - Geom::Line vert(grid_point_8x9.param_get_default(),grid_point_10x11.param_get_default()); - Geom::Line horiz(grid_point_24x26.param_get_default(),grid_point_25x27.param_get_default()); + Geom::Line vert(grid_point_8x9.param_getDefault(),grid_point_10x11.param_getDefault()); + Geom::Line horiz(grid_point_24x26.param_getDefault(),grid_point_25x27.param_getDefault()); if(vertical_mirror) { vertical(grid_point_0, grid_point_1,vert); vertical(grid_point_2, grid_point_3,vert); @@ -428,86 +428,86 @@ LPELattice2::setDefaults() Geom::Point gp32x33x34x35((boundingbox_X.max()-boundingbox_X.min())/4*2+boundingbox_X.min(), (boundingbox_Y.max()-boundingbox_Y.min())/4*2+boundingbox_Y.min()); - grid_point_0.param_update_default(gp0); - grid_point_1.param_update_default(gp1); - grid_point_2.param_update_default(gp2); - grid_point_3.param_update_default(gp3); - grid_point_4.param_update_default(gp4); - grid_point_5.param_update_default(gp5); - grid_point_6.param_update_default(gp6); - grid_point_7.param_update_default(gp7); - grid_point_8x9.param_update_default(gp8x9); - grid_point_10x11.param_update_default(gp10x11); - grid_point_12.param_update_default(gp12); - grid_point_13.param_update_default(gp13); - grid_point_14.param_update_default(gp14); - grid_point_15.param_update_default(gp15); - grid_point_16.param_update_default(gp16); - grid_point_17.param_update_default(gp17); - grid_point_18.param_update_default(gp18); - grid_point_19.param_update_default(gp19); - grid_point_20x21.param_update_default(gp20x21); - grid_point_22x23.param_update_default(gp22x23); - grid_point_24x26.param_update_default(gp24x26); - grid_point_25x27.param_update_default(gp25x27); - grid_point_28x30.param_update_default(gp28x30); - grid_point_29x31.param_update_default(gp29x31); - grid_point_32x33x34x35.param_update_default(gp32x33x34x35); - grid_point_0.param_set_liveupdate(live_update); - grid_point_1.param_set_liveupdate(live_update); - grid_point_2.param_set_liveupdate(live_update); - grid_point_3.param_set_liveupdate(live_update); - grid_point_4.param_set_liveupdate(live_update); - grid_point_5.param_set_liveupdate(live_update); - grid_point_6.param_set_liveupdate(live_update); - grid_point_7.param_set_liveupdate(live_update); - grid_point_8x9.param_set_liveupdate(live_update); - grid_point_10x11.param_set_liveupdate(live_update); - grid_point_12.param_set_liveupdate(live_update); - grid_point_13.param_set_liveupdate(live_update); - grid_point_14.param_set_liveupdate(live_update); - grid_point_15.param_set_liveupdate(live_update); - grid_point_16.param_set_liveupdate(live_update); - grid_point_17.param_set_liveupdate(live_update); - grid_point_18.param_set_liveupdate(live_update); - grid_point_19.param_set_liveupdate(live_update); - grid_point_20x21.param_set_liveupdate(live_update); - grid_point_22x23.param_set_liveupdate(live_update); - grid_point_24x26.param_set_liveupdate(live_update); - grid_point_25x27.param_set_liveupdate(live_update); - grid_point_28x30.param_set_liveupdate(live_update); - grid_point_29x31.param_set_liveupdate(live_update); - grid_point_32x33x34x35.param_set_liveupdate(live_update); + grid_point_0.param_updateDefault(gp0); + grid_point_1.param_updateDefault(gp1); + grid_point_2.param_updateDefault(gp2); + grid_point_3.param_updateDefault(gp3); + grid_point_4.param_updateDefault(gp4); + grid_point_5.param_updateDefault(gp5); + grid_point_6.param_updateDefault(gp6); + grid_point_7.param_updateDefault(gp7); + grid_point_8x9.param_updateDefault(gp8x9); + grid_point_10x11.param_updateDefault(gp10x11); + grid_point_12.param_updateDefault(gp12); + grid_point_13.param_updateDefault(gp13); + grid_point_14.param_updateDefault(gp14); + grid_point_15.param_updateDefault(gp15); + grid_point_16.param_updateDefault(gp16); + grid_point_17.param_updateDefault(gp17); + grid_point_18.param_updateDefault(gp18); + grid_point_19.param_updateDefault(gp19); + grid_point_20x21.param_updateDefault(gp20x21); + grid_point_22x23.param_updateDefault(gp22x23); + grid_point_24x26.param_updateDefault(gp24x26); + grid_point_25x27.param_updateDefault(gp25x27); + grid_point_28x30.param_updateDefault(gp28x30); + grid_point_29x31.param_updateDefault(gp29x31); + grid_point_32x33x34x35.param_updateDefault(gp32x33x34x35); + grid_point_0.param_setLiveupdate(live_update); + grid_point_1.param_setLiveupdate(live_update); + grid_point_2.param_setLiveupdate(live_update); + grid_point_3.param_setLiveupdate(live_update); + grid_point_4.param_setLiveupdate(live_update); + grid_point_5.param_setLiveupdate(live_update); + grid_point_6.param_setLiveupdate(live_update); + grid_point_7.param_setLiveupdate(live_update); + grid_point_8x9.param_setLiveupdate(live_update); + grid_point_10x11.param_setLiveupdate(live_update); + grid_point_12.param_setLiveupdate(live_update); + grid_point_13.param_setLiveupdate(live_update); + grid_point_14.param_setLiveupdate(live_update); + grid_point_15.param_setLiveupdate(live_update); + grid_point_16.param_setLiveupdate(live_update); + grid_point_17.param_setLiveupdate(live_update); + grid_point_18.param_setLiveupdate(live_update); + grid_point_19.param_setLiveupdate(live_update); + grid_point_20x21.param_setLiveupdate(live_update); + grid_point_22x23.param_setLiveupdate(live_update); + grid_point_24x26.param_setLiveupdate(live_update); + grid_point_25x27.param_setLiveupdate(live_update); + grid_point_28x30.param_setLiveupdate(live_update); + grid_point_29x31.param_setLiveupdate(live_update); + grid_point_32x33x34x35.param_setLiveupdate(live_update); } void LPELattice2::resetGrid() { - grid_point_0.param_set_default(); - grid_point_1.param_set_default(); - grid_point_2.param_set_default(); - grid_point_3.param_set_default(); - grid_point_4.param_set_default(); - grid_point_5.param_set_default(); - grid_point_6.param_set_default(); - grid_point_7.param_set_default(); - grid_point_8x9.param_set_default(); - grid_point_10x11.param_set_default(); - grid_point_12.param_set_default(); - grid_point_13.param_set_default(); - grid_point_14.param_set_default(); - grid_point_15.param_set_default(); - grid_point_16.param_set_default(); - grid_point_17.param_set_default(); - grid_point_18.param_set_default(); - grid_point_19.param_set_default(); - grid_point_20x21.param_set_default(); - grid_point_22x23.param_set_default(); - grid_point_24x26.param_set_default(); - grid_point_25x27.param_set_default(); - grid_point_28x30.param_set_default(); - grid_point_29x31.param_set_default(); - grid_point_32x33x34x35.param_set_default(); + grid_point_0.param_valueFromDefault(); + grid_point_1.param_valueFromDefault(); + grid_point_2.param_valueFromDefault(); + grid_point_3.param_valueFromDefault(); + grid_point_4.param_valueFromDefault(); + grid_point_5.param_valueFromDefault(); + grid_point_6.param_valueFromDefault(); + grid_point_7.param_valueFromDefault(); + grid_point_8x9.param_valueFromDefault(); + grid_point_10x11.param_valueFromDefault(); + grid_point_12.param_valueFromDefault(); + grid_point_13.param_valueFromDefault(); + grid_point_14.param_valueFromDefault(); + grid_point_15.param_valueFromDefault(); + grid_point_16.param_valueFromDefault(); + grid_point_17.param_valueFromDefault(); + grid_point_18.param_valueFromDefault(); + grid_point_19.param_valueFromDefault(); + grid_point_20x21.param_valueFromDefault(); + grid_point_22x23.param_valueFromDefault(); + grid_point_24x26.param_valueFromDefault(); + grid_point_25x27.param_valueFromDefault(); + grid_point_28x30.param_valueFromDefault(); + grid_point_29x31.param_valueFromDefault(); + grid_point_32x33x34x35.param_valueFromDefault(); } void diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index 63d60da3f3..9af1c0a8e8 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -105,62 +105,62 @@ LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : 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)); + fontbutton.param_updateDefault(fontbutton_value); + scale.param_updateDefault(prefs->getDouble("/live_effects/measure-line/scale", 1.0)); + precision.param_updateDefault(prefs->getInt("/live_effects/measure-line/precision", 2)); + position.param_updateDefault(prefs->getDouble("/live_effects/measure-line/position", 10.0)); + text_top_bottom.param_updateDefault(prefs->getDouble("/live_effects/measure-line/text_top_bottom", 5.0)); + helpline_distance.param_updateDefault(prefs->getDouble("/live_effects/measure-line/helpline_distance", 0.0)); + helpline_overlap.param_updateDefault(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); + unit.param_updateDefault(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_updateDefault(format_value); + dimline_format.param_updateDefault(prefs->getString("/live_effects/measure-line/dimline_format")); + helperlines_format.param_updateDefault(prefs->getString("/live_effects/measure-line/helperlines_format")); + anotation_format.param_updateDefault(prefs->getString("/live_effects/measure-line/anotation_format")); + arrows_format.param_updateDefault(prefs->getString("/live_effects/measure-line/arrows_format")); + flip_side.param_updateDefault(prefs->getBool("/live_effects/measure-line/flip_side")); + scale_sensitive.param_updateDefault(prefs->getBool("/live_effects/measure-line/scale_sensitive")); + local_locale.param_updateDefault(prefs->getBool("/live_effects/measure-line/local_locale")); + line_group_05.param_updateDefault(prefs->getBool("/live_effects/measure-line/line_group_05")); + rotate_anotation.param_updateDefault(prefs->getBool("/live_effects/measure-line/rotate_anotation")); + hide_back.param_updateDefault(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(); 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); - precision.param_make_integer(true); - 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); - precision.param_make_integer(true); - position.param_set_range(-999999.0, 999999.0); - position.param_set_increments(1, 1); - position.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); - helpline_overlap.param_set_range(-999999.0, 999999.0); - helpline_overlap.param_set_increments(1, 1); - helpline_overlap.param_set_digits(2); + precision.param_setRange(0, 100); + precision.param_setIncrements(1, 1); + precision.param_setDigits(0); + precision.param_makeInteger(true); + curve_linked.param_setRange(0, 999); + curve_linked.param_setIncrements(1, 1); + curve_linked.param_setDigits(0); + curve_linked.param_makeInteger(true); + precision.param_makeInteger(true); + position.param_setRange(-999999.0, 999999.0); + position.param_setIncrements(1, 1); + position.param_setDigits(2); + text_top_bottom.param_setRange(-999999.0, 999999.0); + text_top_bottom.param_setIncrements(1, 1); + text_top_bottom.param_setDigits(2); + text_right_left.param_setRange(-999999.0, 999999.0); + text_right_left.param_setIncrements(1, 1); + text_right_left.param_setDigits(2); + helpline_distance.param_setRange(-999999.0, 999999.0); + helpline_distance.param_setIncrements(1, 1); + helpline_distance.param_setDigits(2); + helpline_overlap.param_setRange(-999999.0, 999999.0); + helpline_overlap.param_setIncrements(1, 1); + helpline_overlap.param_setDigits(2); start_stored = Geom::Point(0,0); end_stored = Geom::Point(0,0); } @@ -501,7 +501,7 @@ LPEMeasureLine::doOnApply(SPLPEItem const* lpeitem) item->removeCurrentPathEffect(false); } id_origin.param_setValue(Glib::ustring(lpeitem->getId())); - id_origin.write_to_SVG(); + id_origin.writeToSVG(); } void @@ -529,8 +529,8 @@ LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) format.param_setValue(Glib::ustring("{measure}{unit}")); } size_t ncurves = pathvector.curveCount(); - if (ncurves != (size_t)curve_linked.param_get_max()) { - curve_linked.param_set_range(0, ncurves); + if (ncurves != (size_t)curve_linked.param_getMax()) { + curve_linked.param_setRange(0, ncurves); } Geom::Point start = pathvector.initialPoint(); Geom::Point end = pathvector.finalPoint(); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index b411bd699d..0bc1fa8f02 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -73,9 +73,9 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : 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); + split_gap.param_setRange(-999999.0, 999999.0); + split_gap.param_setIncrements(0.1, 0.1); + split_gap.param_setDigits(5); apply_to_clippath_and_mask = true; previous_center = Geom::Point(0,0); } @@ -114,7 +114,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; original_bbox(lpeitem); - //center_point->param_set_liveupdate(false); + //center_point->param_setLiveupdate(false); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); if (mode == MT_Y) { @@ -362,7 +362,7 @@ 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); + param->param_transformMultiply(postmul, set); } previous_center = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); } @@ -378,15 +378,15 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) 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_update_default(point_a); + start_point.param_updateDefault(point_a); end_point.param_setValue(point_b); - end_point.param_update_default(point_b); + end_point.param_updateDefault(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(); + id_origin.writeToSVG(); } } diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index c853e4afa8..31db8ca075 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -38,7 +38,7 @@ void LPEOffset::doOnApply(SPLPEItem const* lpeitem) { Geom::Point offset = *(SP_SHAPE(lpeitem)->_curve->first_point()); - offset_pt.param_update_default(offset); + offset_pt.param_updateDefault(offset); offset_pt.param_setValue(offset,true); } diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp index 271442c7d4..41f64e58e5 100644 --- a/src/live_effects/lpe-parallel.cpp +++ b/src/live_effects/lpe-parallel.cpp @@ -70,7 +70,7 @@ LPEParallel::doOnApply (SPLPEItem const* lpeitem) B = *(curve->last_point()); dir = unit_vector(B - A); Geom::Point offset = (A + B)/2 + dir.ccw() * 100; - offset_pt.param_update_default(offset); + offset_pt.param_updateDefault(offset); offset_pt.param_setValue(offset, true); } @@ -120,7 +120,7 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori Geom::Point const s = snap_knot_position(p, state); double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir)); - lpe->length_left.param_set_value(-lambda); + lpe->length_left.param_setValue(-lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -135,7 +135,7 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or Geom::Point const s = snap_knot_position(p, state); double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir)); - lpe->length_right.param_set_value(lambda); + lpe->length_right.param_setValue(lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index b026bbc22e..62f71df5d6 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -95,8 +95,8 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) : registerParameter(&prop_units); registerParameter(&vertical_pattern); registerParameter(&fuse_tolerance); - prop_scale.param_set_digits(3); - prop_scale.param_set_increments(0.01, 0.10); + prop_scale.param_setDigits(3); + prop_scale.param_setIncrements(0.01, 0.10); _provides_knotholder_entities = true; @@ -157,9 +157,9 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise > con } //TODO: dynamical update of parameter ranges? //if (prop_units.get_value()){ - // spacing.param_set_range(-.9, Geom::infinity()); + // spacing.param_setRange(-.9, Geom::infinity()); // }else{ - // spacing.param_set_range(-pattBndsX.extent()*.9, Geom::infinity()); + // spacing.param_setRange(-pattBndsX.extent()*.9, Geom::infinity()); // } y0 += noffset; @@ -260,12 +260,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 * ((postmul.expansionX() + postmul.expansionY()) / 2)); - prop_scale.write_to_SVG(); + prop_scale.param_setValue(prop_scale * ((postmul.expansionX() + postmul.expansionY()) / 2)); + prop_scale.writeToSVG(); } if (postmul.isTranslation()) { - pattern.param_transform_multiply(postmul, set); - pattern.write_to_SVG(); + pattern.param_transformMultiply(postmul, set); + pattern.writeToSVG(); } } @@ -307,9 +307,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.param_setValue(-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.param_setValue(Geom::distance(s , ptA)/(lpe->original_height/2.0)); } } diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index dab169cfe8..5f666d5383 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -67,10 +67,10 @@ KnotHolderEntityEnd::bisector_end_set(Geom::Point const &p, guint state, bool le double lambda = Geom::nearest_time(s, lpe->M, lpe->perp_dir); if (left) { lpe->C = lpe->M + lpe->perp_dir * lambda; - lpe->length_left.param_set_value(lambda); + lpe->length_left.param_setValue(lambda); } else { lpe->D = lpe->M + lpe->perp_dir * lambda; - lpe->length_right.param_set_value(-lambda); + lpe->length_right.param_setValue(-lambda); } // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 365ff53896..e9b06b27ee 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -484,19 +484,19 @@ LPEPerspectiveEnvelope::setDefaults() Geom::Point down_left(boundingbox_X.min(), boundingbox_Y.max()); Geom::Point down_right(boundingbox_X.max(), boundingbox_Y.max()); - up_left_point.param_update_default(up_left); - up_right_point.param_update_default(up_right); - down_right_point.param_update_default(down_right); - down_left_point.param_update_default(down_left); + up_left_point.param_updateDefault(up_left); + up_right_point.param_updateDefault(up_right); + down_right_point.param_updateDefault(down_right); + down_left_point.param_updateDefault(down_left); } void LPEPerspectiveEnvelope::resetGrid() { - up_left_point.param_set_default(); - up_right_point.param_set_default(); - down_right_point.param_set_default(); - down_left_point.param_set_default(); + up_left_point.param_valueFromDefault(); + up_right_point.param_valueFromDefault(); + down_right_point.param_valueFromDefault(); + down_left_point.param_valueFromDefault(); } void diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 435c91c2d7..460d96156e 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -273,8 +273,8 @@ KnotHolderEntityOffset::knot_set(Geom::Point const &p, Geom::Point const &origin Geom::Point const s = snap_knot_position(p, state); - lpe->offsetx.param_set_value((s - origin)[Geom::X]); - lpe->offsety.param_set_value(-(s - origin)[Geom::Y]); // additional minus sign is due to coordinate system flipping + lpe->offsetx.param_setValue((s - origin)[Geom::X]); + lpe->offsety.param_setValue(-(s - origin)[Geom::Y]); // additional minus sign is due to coordinate system flipping // 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); diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index d87f92fccf..2c1edbaaa7 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -177,7 +177,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) : /// @todo offset_points are initialized with empty path, is that bug-save? interpolator_beta.addSlider(true); - interpolator_beta.param_set_range(0.,1.); + interpolator_beta.param_setRange(0.,1.); registerParameter(&offset_points); registerParameter(&sort_points); @@ -247,7 +247,7 @@ LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem) points.push_back( Geom::Point(size - 0.2,width) ); } } - offset_points.param_set_and_write_new_value(points); + offset_points.param_setAndWriteNewValue(points); } else { g_warning("LPE Powerstroke can only be applied to shapes (not groups)."); } diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index 47613f58ed..62d4539de0 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -26,8 +26,8 @@ LPERecursiveSkeleton::LPERecursiveSkeleton(LivePathEffectObject *lpeobject) : { show_orig_path = true; concatenate_before_pwd2 = true; - iterations.param_make_integer(true); - iterations.param_set_range(1, 15); + iterations.param_makeInteger(true); + iterations.param_setRange(1, 15); registerParameter(&iterations); } diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index d832b36150..0504ffbf2d 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -262,13 +262,13 @@ LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) : registerParameter(&front_thickness); registerParameter(&back_thickness); - //hatch_dist.param_set_range(0.1, Geom::infinity()); - growth.param_set_range(0, Geom::infinity()); - dist_rdm.param_set_range(0, 99.); - stroke_width_top.param_set_range(0, Geom::infinity()); - stroke_width_bot.param_set_range(0, Geom::infinity()); - front_thickness.param_set_range(0, Geom::infinity()); - back_thickness.param_set_range(0, Geom::infinity()); + //hatch_dist.param_setRange(0.1, Geom::infinity()); + growth.param_setRange(0, Geom::infinity()); + dist_rdm.param_setRange(0, 99.); + stroke_width_top.param_setRange(0, Geom::infinity()); + stroke_width_bot.param_setRange(0, Geom::infinity()); + front_thickness.param_setRange(0, Geom::infinity()); + back_thickness.param_setRange(0, Geom::infinity()); // hide the widgets for direction and bender vectorparams direction.widget_is_visible = false; @@ -558,13 +558,13 @@ LPERoughHatches::resetDefaults(SPItem const* item) if (bbox) { origin = bbox->midpoint(); vector = Geom::Point((*bbox)[X].extent()/4, 0.); - top_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 ); - bot_edge_variation.param_set_value( (*bbox)[Y].extent()/10, 0 ); - top_edge_variation.write_to_SVG(); - bot_edge_variation.write_to_SVG(); + top_edge_variation.param_setValue( (*bbox)[Y].extent()/10, 0 ); + bot_edge_variation.param_setValue( (*bbox)[Y].extent()/10, 0 ); + top_edge_variation.writeToSVG(); + bot_edge_variation.writeToSVG(); } //direction.set_and_write_new_values(origin, vector); - //bender.param_set_and_write_new_value( origin + Geom::Point(5,0) ); + //bender.param_setAndWriteNewValue( origin + Geom::Point(5,0) ); direction.set_and_write_new_values(origin + Geom::Point(0,-5), vector); bender.set_and_write_new_values( origin, Geom::Point(5,0) ); hatch_dist = Geom::L2(vector)/2; diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index e847494a2f..9987da0464 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -75,15 +75,15 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) registerParameter(&shift_nodes); registerParameter(&fixed_displacement); registerParameter(&spray_tool_friendly); - displace_x.param_set_range(0., Geom::infinity()); - displace_y.param_set_range(0., Geom::infinity()); - global_randomize.param_set_range(0., Geom::infinity()); - max_segment_size.param_set_range(0., Geom::infinity()); - max_segment_size.param_set_increments(1, 1); - max_segment_size.param_set_digits(1); - segments.param_set_range(1, Geom::infinity()); - segments.param_set_increments(1, 1); - segments.param_set_digits(0); + displace_x.param_setRange(0., Geom::infinity()); + displace_y.param_setRange(0., Geom::infinity()); + global_randomize.param_setRange(0., Geom::infinity()); + max_segment_size.param_setRange(0., Geom::infinity()); + max_segment_size.param_setIncrements(1, 1); + max_segment_size.param_setDigits(1); + segments.param_setRange(1, Geom::infinity()); + segments.param_setIncrements(1, 1); + segments.param_setDigits(0); seed = 0; apply_to_clippath_and_mask = true; } @@ -95,7 +95,7 @@ void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) if(spray_tool_friendly && seed == 0 && SP_OBJECT(lpeitem)->getId()){ std::string id_item(SP_OBJECT(lpeitem)->getId()); long seed = static_cast(boost::hash_value(id_item)); - global_randomize.param_set_value(global_randomize.get_value(), seed); + global_randomize.param_setValue(global_randomize.get_value(), seed); } displace_x.resetRandomizer(); displace_y.resetRandomizer(); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 852592219a..453142571f 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -55,13 +55,13 @@ LPERuler::LPERuler(LivePathEffectObject *lpeobject) : registerParameter(&mark_dir); registerParameter(&border_marks); - major_mark_steps.param_make_integer(); - major_mark_steps.param_set_range(1, 1000); - shift.param_make_integer(); + major_mark_steps.param_makeInteger(); + major_mark_steps.param_setRange(1, 1000); + shift.param_makeInteger(); - mark_length.param_set_increments(1.0, 10.0); - minor_mark_length.param_set_increments(1.0, 10.0); - offset.param_set_increments(1.0, 10.0); + mark_length.param_setIncrements(1.0, 10.0); + minor_mark_length.param_setIncrements(1.0, 10.0); + offset.param_setIncrements(1.0, 10.0); } LPERuler::~LPERuler() diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index 7c298d0e7f..f7f9b2b181 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -34,9 +34,9 @@ LPEShowHandles::LPEShowHandles(LivePathEffectObject *lpeobject) registerParameter(&original_path); registerParameter(&show_center_node); registerParameter(&scale_nodes_and_handles); - 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); + scale_nodes_and_handles.param_setRange(0, 500.); + scale_nodes_and_handles.param_setIncrements(1, 1); + scale_nodes_and_handles.param_setDigits(2); stroke_width = 1.0; } diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 5de9816bb9..8bc61969bb 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -35,21 +35,21 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) registerParameter(&simplify_individual_paths); registerParameter(&simplify_just_coalesce); - threshold.param_set_range(0.0001, Geom::infinity()); - threshold.param_set_increments(0.0001, 0.0001); - threshold.param_set_digits(6); + threshold.param_setRange(0.0001, Geom::infinity()); + threshold.param_setIncrements(0.0001, 0.0001); + threshold.param_setDigits(6); - steps.param_set_range(0, 100); - steps.param_set_increments(1, 1); - steps.param_set_digits(0); + steps.param_setRange(0, 100); + steps.param_setIncrements(1, 1); + steps.param_setDigits(0); - smooth_angles.param_set_range(0.0, 360.0); - smooth_angles.param_set_increments(10, 10); - smooth_angles.param_set_digits(2); + smooth_angles.param_setRange(0.0, 360.0); + smooth_angles.param_setIncrements(10, 10); + smooth_angles.param_setDigits(2); - helper_size.param_set_range(0.0, 999.0); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(2); + helper_size.param_setRange(0.0, 999.0); + helper_size.param_setIncrements(5, 5); + helper_size.param_setDigits(2); radius_helper_nodes = 6.0; apply_to_clippath_and_mask = true; diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index e3376b7e56..7b34c3747a 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -84,28 +84,28 @@ LPESketch::LPESketch(LivePathEffectObject *lpeobject) : #endif #endif - nbiter_approxstrokes.param_make_integer(); - nbiter_approxstrokes.param_set_range(0, Geom::infinity()); - strokelength.param_set_range(1, Geom::infinity()); - strokelength.param_set_increments(1., 5.); - strokelength_rdm.param_set_range(0, 1.); - strokeoverlap.param_set_range(0, 1.); - strokeoverlap.param_set_increments(0.1, 0.30); - ends_tolerance.param_set_range(0., 1.); - parallel_offset.param_set_range(0, Geom::infinity()); - tremble_frequency.param_set_range(0.01, 100.); - tremble_frequency.param_set_increments(.5, 1.5); - strokeoverlap_rdm.param_set_range(0, 1.); + nbiter_approxstrokes.param_makeInteger(); + nbiter_approxstrokes.param_setRange(0, Geom::infinity()); + strokelength.param_setRange(1, Geom::infinity()); + strokelength.param_setIncrements(1., 5.); + strokelength_rdm.param_setRange(0, 1.); + strokeoverlap.param_setRange(0, 1.); + strokeoverlap.param_setIncrements(0.1, 0.30); + ends_tolerance.param_setRange(0., 1.); + parallel_offset.param_setRange(0, Geom::infinity()); + tremble_frequency.param_setRange(0.01, 100.); + tremble_frequency.param_setIncrements(.5, 1.5); + strokeoverlap_rdm.param_setRange(0, 1.); #ifdef LPE_SKETCH_USE_CONSTRUCTION_LINES - nbtangents.param_make_integer(); - nbtangents.param_set_range(0, Geom::infinity()); - tgtscale.param_set_range(0, Geom::infinity()); - tgtscale.param_set_increments(.1, .5); - tgtlength.param_set_range(0, Geom::infinity()); - tgtlength.param_set_increments(1., 5.); - tgtlength_rdm.param_set_range(0, 1.); - tgt_places_rdmness.param_set_range(0, 1.); + nbtangents.param_makeInteger(); + nbtangents.param_setRange(0, Geom::infinity()); + tgtscale.param_setRange(0, Geom::infinity()); + tgtscale.param_setIncrements(.1, .5); + tgtlength.param_setRange(0, Geom::infinity()); + tgtlength.param_setIncrements(1., 5.); + tgtlength_rdm.param_setRange(0, 1.); + tgt_places_rdmness.param_setRange(0, 1.); //this is not very smart, but required to avoid having lot of tangents stacked on short components. //Nota: we could specify a density instead of an absolute number, but this would be scale dependant. concatenate_before_pwd2 = true; diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index 69a4dfad9c..e21e416e6b 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -125,14 +125,14 @@ KnotHolderEntityAttachPt::knot_set(Geom::Point const &p, Geom::Point const &/*or Geom::Point const s = snap_knot_position(p, state); if ( !SP_IS_SHAPE(lpe->sp_lpe_item) ) { - //lpe->t_attach.param_set_value(0); + //lpe->t_attach.param_setValue(0); g_warning("LPEItem is not a path! %s:%d\n", __FILE__, __LINE__); return; } Piecewise > pwd2 = paths_to_pw( lpe->pathvector_before_effect ); double t0 = nearest_time(s, pwd2); - lpe->t_attach.param_set_value(t0); + lpe->t_attach.param_setValue(t0); // 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); @@ -146,7 +146,7 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori Geom::Point const s = snap_knot_position(p, state); double lambda = Geom::nearest_time(s, lpe->ptA, lpe->derivA); - lpe->length_left.param_set_value(-lambda); + lpe->length_left.param_setValue(-lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } @@ -159,7 +159,7 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or Geom::Point const s = snap_knot_position(p, state); double lambda = Geom::nearest_time(s, lpe->ptA, lpe->derivA); - lpe->length_right.param_set_value(lambda); + lpe->length_right.param_setValue(lambda); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index f4a81aa900..a743cd09bc 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -74,8 +74,8 @@ LPETaperStroke::LPETaperStroke(LivePathEffectObject *lpeobject) : show_orig_path = true; _provides_knotholder_entities = true; - attach_start.param_set_digits(3); - attach_end.param_set_digits(3); + attach_start.param_setDigits(3); + attach_end.param_setDigits(3); registerParameter(&line_width); registerParameter(&attach_start); @@ -118,8 +118,8 @@ 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); - line_width.write_to_SVG(); + line_width.param_setValue(width); + line_width.writeToSVG(); } else { printf("WARNING: It only makes sense to apply Taper stroke to paths (not groups).\n"); } @@ -201,7 +201,7 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) // check to see if the knots were dragged over each other // if so, reset the end offset, but still allow the start offset. if ( attach_start >= (size - attach_end) ) { - attach_end.param_set_value( size - attach_start ); + attach_end.param_setValue( size - attach_start ); metInMiddle = true; } } @@ -216,10 +216,10 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) // don't let it be integer (TODO this is stupid!) { if (double(unsigned(attach_start)) == attach_start) { - attach_start.param_set_value(attach_start - 0.00001); + attach_start.param_setValue(attach_start - 0.00001); } if (double(unsigned(attach_end)) == attach_end) { - attach_end.param_set_value(attach_end - 0.00001); + attach_end.param_setValue(attach_end - 0.00001); } } @@ -229,20 +229,20 @@ Geom::PathVector LPETaperStroke::doEffect_path(Geom::PathVector const& path_in) // don't let the knots be farther than they are allowed to be { if ((unsigned)attach_start >= allowed_start) { - attach_start.param_set_value((double)allowed_start - 0.00001); + attach_start.param_setValue((double)allowed_start - 0.00001); } if ((unsigned)attach_end >= allowed_end) { - attach_end.param_set_value((double)allowed_end - 0.00001); + attach_end.param_setValue((double)allowed_end - 0.00001); } } // don't let it be zero (this is stupid too!) if (attach_start < 0.0000001 || withinRange(double(attach_start), 0.00000001, 0.000001)) { - attach_start.param_set_value( 0.0000001 ); + attach_start.param_setValue( 0.0000001 ); zeroStart = true; } if (attach_end < 0.0000001 || withinRange(double(attach_end), 0.00000001, 0.000001)) { - attach_end.param_set_value( 0.0000001 ); + attach_end.param_setValue( 0.0000001 ); zeroEnd = true; } @@ -476,7 +476,7 @@ void KnotHolderEntityAttachBegin::knot_set(Geom::Point const &p, Geom::Point con pwd2.concat(p_in.toPwSb()); double t0 = nearest_time(s, pwd2); - lpe->attach_start.param_set_value(t0); + lpe->attach_start.param_setValue(t0); // 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); @@ -504,7 +504,7 @@ void KnotHolderEntityAttachEnd::knot_set(Geom::Point const &p, Geom::Point const Piecewise > pwd2 = p_in.toPwSb(); double t0 = nearest_time(s, pwd2); - lpe->attach_end.param_set_value(t0); + lpe->attach_end.param_setValue(t0); sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index c484c88a20..275a2e9969 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -25,7 +25,7 @@ LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : registerParameter(&point); registerParameter(&path); - point.set_oncanvas_looks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); + point.set_onCanvasLooks(SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, 0x00ff0000); point.param_setValue(point); } diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index ef29007750..45917d3fab 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -63,19 +63,19 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : registerParameter(&lock_lenght); registerParameter(&lock_angle); - first_knot.param_make_integer(true); - first_knot.param_overwrite_widget(true); - last_knot.param_make_integer(true); - last_knot.param_overwrite_widget(true); - helper_size.param_set_range(0, 999); - helper_size.param_set_increments(1, 1); - helper_size.param_set_digits(0); - offset.param_set_range(-999999.0, 999999.0); - offset.param_set_increments(1, 1); - offset.param_set_digits(2); - stretch.param_set_range(0, 999.0); - stretch.param_set_increments(0.01, 0.01); - stretch.param_set_digits(4); + first_knot.param_makeInteger(true); + first_knot.param_overwriteWidget(true); + last_knot.param_makeInteger(true); + last_knot.param_overwriteWidget(true); + helper_size.param_setRange(0, 999); + helper_size.param_setIncrements(1, 1); + helper_size.param_setDigits(0); + offset.param_setRange(-999999.0, 999999.0); + offset.param_setIncrements(1, 1); + offset.param_setDigits(2); + stretch.param_setRange(0, 999.0); + stretch.param_setIncrements(0.01, 0.01); + stretch.param_setDigits(4); apply_to_clippath_and_mask = true; } @@ -102,16 +102,16 @@ LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem) point_b = pathvector.back().finalCurve().initialPoint(); } size_t nnodes = nodeCount(pathvector); - last_knot.param_set_value(nnodes); + last_knot.param_setValue(nnodes); } previous_lenght = Geom::distance(point_a,point_b); Geom::Ray transformed(point_a,point_b); previous_angle = transformed.angle(); - start.param_update_default(point_a); - start.param_set_default(); - end.param_update_default(point_b); - end.param_set_default(); + start.param_updateDefault(point_a); + start.param_valueFromDefault(); + end.param_updateDefault(point_b); + end.param_valueFromDefault(); } void @@ -136,14 +136,14 @@ LPETransform2Pts::doBeforeEffect (SPLPEItem const* lpeitem) point_a = pointAtNodeIndex(pathvector,(size_t)first_knot-1); point_b = pointAtNodeIndex(pathvector,(size_t)last_knot-1); size_t nnodes = nodeCount(pathvector); - first_knot.param_set_range(1, last_knot-1); - last_knot.param_set_range(first_knot+1, nnodes); + first_knot.param_setRange(1, last_knot-1); + last_knot.param_setRange(first_knot+1, nnodes); from_original_width.param_setValue(false); } else { - first_knot.param_set_value(1); - last_knot.param_set_value(2); - first_knot.param_set_range(1,1); - last_knot.param_set_range(2,2); + first_knot.param_setValue(1); + last_knot.param_setValue(2); + first_knot.param_setRange(1,1); + last_knot.param_setRange(2,2); from_original_width.param_setValue(true); append_path = false; } @@ -181,14 +181,14 @@ LPETransform2Pts::updateIndex() if(!from_original_width) { point_a = pointAtNodeIndex(pathvector,(size_t)first_knot-1); point_b = pointAtNodeIndex(pathvector,(size_t)last_knot-1); - start.param_update_default(point_a); - start.param_set_default(); - end.param_update_default(point_b); - end.param_set_default(); - start.param_update_default(point_a); - end.param_update_default(point_b); - start.param_set_default(); - end.param_set_default(); + start.param_updateDefault(point_a); + start.param_valueFromDefault(); + end.param_updateDefault(point_b); + end.param_valueFromDefault(); + start.param_updateDefault(point_a); + end.param_updateDefault(point_b); + start.param_valueFromDefault(); + end.param_valueFromDefault(); } DocumentUndo::done(getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change index of knot")); } @@ -241,23 +241,23 @@ LPETransform2Pts::reset() point_b = Geom::Point(boundingbox_X.max(), boundingbox_Y.middle()); if(!pathvector.empty() && !from_original_width) { size_t nnodes = nodeCount(pathvector); - first_knot.param_set_range(1, last_knot-1); - last_knot.param_set_range(first_knot+1, nnodes); - first_knot.param_set_value(1); - last_knot.param_set_value(nnodes); + first_knot.param_setRange(1, last_knot-1); + last_knot.param_setRange(first_knot+1, nnodes); + first_knot.param_setValue(1); + last_knot.param_setValue(nnodes); point_a = pathvector.initialPoint(); point_b = pathvector.finalPoint(); } else { - first_knot.param_set_value(1); - last_knot.param_set_value(2); + first_knot.param_setValue(1); + last_knot.param_setValue(2); } Geom::Ray transformed(point_a, point_b); previous_angle = transformed.angle(); previous_lenght = Geom::distance(point_a, point_b); - start.param_update_default(point_a); - end.param_update_default(point_b); - start.param_set_default(); - end.param_set_default(); + start.param_updateDefault(point_a); + end.param_updateDefault(point_b); + start.param_valueFromDefault(); + end.param_valueFromDefault(); } Gtk::Widget *LPETransform2Pts::newWidget() diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index b9fd8908a6..e5ec33601c 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -13,17 +13,17 @@ namespace Inkscape { namespace LivePathEffect { void -VonKochPathParam::param_setup_nodepath(Inkscape::NodePath::Path *np) +VonKochPathParam::param_setupNodepath(Inkscape::NodePath::Path *np) { - PathParam::param_setup_nodepath(np); + PathParam::param_setupNodepath(np); //sp_nodepath_make_straight_path(np); } //FIXME: a path is used here instead of 2 points to work around path/point param incompatibility bug. void -VonKochRefPathParam::param_setup_nodepath(Inkscape::NodePath::Path *np) +VonKochRefPathParam::param_setupNodepath(Inkscape::NodePath::Path *np) { - PathParam::param_setup_nodepath(np); + PathParam::param_setupNodepath(np); //sp_nodepath_make_straight_path(np); } bool @@ -63,10 +63,10 @@ LPEVonKoch::LPEVonKoch(LivePathEffectObject *lpeobject) : registerParameter(&maxComplexity); //registerParameter(&draw_boxes) ); apply_to_clippath_and_mask = true; - nbgenerations.param_make_integer(); - nbgenerations.param_set_range(0, Geom::infinity()); - maxComplexity.param_make_integer(); - maxComplexity.param_set_range(0, Geom::infinity()); + nbgenerations.param_makeInteger(); + nbgenerations.param_setRange(0, Geom::infinity()); + maxComplexity.param_makeInteger(); + maxComplexity.param_setRange(0, Geom::infinity()); } LPEVonKoch::~LPEVonKoch() diff --git a/src/live_effects/lpe-vonkoch.h b/src/live_effects/lpe-vonkoch.h index bffbebd544..bda4b6c1f7 100644 --- a/src/live_effects/lpe-vonkoch.h +++ b/src/live_effects/lpe-vonkoch.h @@ -25,9 +25,9 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const gchar * default_value = "M0,0 L1,1"):PathParam(label,tip,key,wr,effect,default_value){} + const gchar * defaultvalue = "M0,0 L1,1"):PathParam(label,tip,key,wr,effect,defaultvalue){} virtual ~VonKochPathParam(){} - virtual void param_setup_nodepath(Inkscape::NodePath::Path *np); + virtual void param_setupNodepath(Inkscape::NodePath::Path *np); }; //FIXME: a path is used here instead of 2 points to work around path/point param incompatibility bug. @@ -38,9 +38,9 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const gchar * default_value = "M0,0 L1,1"):PathParam(label,tip,key,wr,effect,default_value){} + const gchar * defaultvalue = "M0,0 L1,1"):PathParam(label,tip,key,wr,effect,defaultvalue){} virtual ~VonKochRefPathParam(){} - virtual void param_setup_nodepath(Inkscape::NodePath::Path *np); + virtual void param_setupNodepath(Inkscape::NodePath::Path *np); virtual bool param_readSVGValue(const gchar * strvalue); }; diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 1b8f742da0..5b0639abd9 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -18,7 +18,7 @@ namespace LivePathEffect { template <> double -ArrayParam::readsvg(const gchar * str) +ArrayParam::readSVG(const gchar * str) { double newx = Geom::infinity(); sp_svg_number_read_d(str, &newx); @@ -27,7 +27,7 @@ ArrayParam::readsvg(const gchar * str) template <> float -ArrayParam::readsvg(const gchar * str) +ArrayParam::readSVG(const gchar * str) { float newx = Geom::infinity(); sp_svg_number_read_f(str, &newx); @@ -36,7 +36,7 @@ ArrayParam::readsvg(const gchar * str) template <> Geom::Point -ArrayParam::readsvg(const gchar * str) +ArrayParam::readSVG(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); double newx, newy; diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a600f02573..5a8a171c61 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -53,7 +53,7 @@ public: gchar ** strarray = g_strsplit(strvalue, "|", 0); gchar ** iter = strarray; while (*iter != NULL) { - _vector.push_back( readsvg(*iter) ); + _vector.push_back( readSVG(*iter) ); iter++; } g_strfreev (strarray); @@ -62,7 +62,7 @@ public: virtual gchar * param_getSVGValue() const { Inkscape::SVGOStringStream os; - writesvg(os, _vector); + writeSVG(os, _vector); gchar * str = g_strdup(os.str().c_str()); return str; } @@ -71,15 +71,15 @@ public: _vector = new_vector; } - void param_set_default() { + void param_valueFromDefault() { param_setValue( std::vector(_default_size) ); } - void param_set_and_write_new_value(std::vector const &new_vector) { + void param_setAndWriteNewValue(std::vector const &new_vector) { Inkscape::SVGOStringStream os; - writesvg(os, new_vector); + writeSVG(os, new_vector); gchar * str = g_strdup(os.str().c_str()); - param_write_to_repr(str); + param_writeToRepr(str); g_free(str); } @@ -87,7 +87,7 @@ protected: std::vector _vector; size_t _default_size; - void writesvg(SVGOStringStream &str, std::vector const &vector) const { + void writeSVG(SVGOStringStream &str, std::vector const &vector) const { for (unsigned int i = 0; i < vector.size(); ++i) { if (i != 0) { // separate items with pipe symbol @@ -97,7 +97,7 @@ protected: } } - StorageType readsvg(const gchar * str); + StorageType readSVG(const gchar * str); private: ArrayParam(const ArrayParam&); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 1bd5f96ad8..c142a07d06 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -21,25 +21,27 @@ 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 defaultvalue) + : Parameter(label, tip, key, wr, effect), value(defaultvalue), defvalue(defaultvalue) { } -BoolParam::~BoolParam() +Gtk::Widget * +BoolParam::param_newWidget() { -} + Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredCheckButton( param_label, + param_tooltip, + param_key, + *param_wr, + false, + param_effect->getRepr(), + param_effect->getSPDoc()) ); -void -BoolParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -BoolParam::param_update_default(bool const default_value) -{ - defvalue = default_value; + checkwdg->setActive(value); + checkwdg->setProgrammatically = false; + checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); + return dynamic_cast (checkwdg); } bool @@ -56,26 +58,22 @@ BoolParam::param_getSVGValue() const return str; } -Gtk::Widget * -BoolParam::param_newWidget() +void +BoolParam::param_valueFromDefault() +{ + param_setValue(defvalue); +} + +void +BoolParam::param_updateDefault(bool const defaultvalue) { - if(!hide_widget){ - Inkscape::UI::Widget::RegisteredCheckButton * checkwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredCheckButton( param_label, - param_tooltip, - param_key, - *param_wr, - false, - param_effect->getRepr(), - param_effect->getSPDoc()) ); + defvalue = defaultvalue; +} - checkwdg->setActive(value); - checkwdg->setProgrammatically = false; - checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - return dynamic_cast (checkwdg); - } else { - return NULL; - } +void +BoolParam::param_update_default(const gchar * default_value) +{ + param_update_default(helperfns_read_bool(default_value, defvalue)); } void diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 7ad8a9368a..3908c17f33 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -25,21 +25,18 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - bool default_value = false, + bool defaultvalue = false, bool no_widget = false); virtual ~BoolParam(); - virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - - void param_setValue(bool newvalue); - virtual void param_set_default(); - void param_update_default(bool const default_value); - bool get_value() const { return value; }; - - inline operator bool() const { return value; }; + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + virtual void param_valueFromDefault(); + virtual void param_updateDefault(bool const defaultvalue); + virtual void param_updateDefault(const gchar * default_value); + void param_setValue(bool newvalue); + bool param_getValue() const { return value; }; private: BoolParam(const BoolParam&); @@ -47,7 +44,6 @@ private: bool value; bool defvalue; - bool hide_widget; }; diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index dbfc686237..8905d3c9be 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -27,12 +27,12 @@ public: const Util::EnumDataConverter& c, Inkscape::UI::Widget::Registry* wr, Effect* effect, - E default_value, + E defaultvalue, bool sort = true) : Parameter(label, tip, key, wr, effect) { enumdataconv = &c; - defvalue = default_value; + defvalue = defaultvalue; value = defvalue; sorted = sort; }; @@ -41,8 +41,14 @@ 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(), sorted ) ); + new Inkscape::UI::Widget::RegisteredEnum(param_label, + param_tooltip, + param_key, + *enumdataconv, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc(), + sorted) ); regenum->set_active_by_id(value); regenum->combobox()->setProgrammatically = false; @@ -52,33 +58,36 @@ public: bool param_readSVGValue(const gchar * strvalue) { if (!strvalue) { - param_set_default(); + param_valueFromDefault(); return true; } - - param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) ); - + param_setValue( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) ); return true; }; + gchar * param_getSVGValue() const { gchar * str = g_strdup( enumdataconv->get_key(value).c_str() ); return str; }; - E get_value() const { + E param_getValue() const { return value; } - inline operator E() const { - return value; - }; + void param_setValue(E val) { + value = val; + } - void param_set_default() { - param_set_value(defvalue); + void param_valueFromDefault(bool /*write*/) { + param_setValue(defvalue); } - void param_set_value(E val) { - value = val; + virtual void param_updateDefault(E defaultvalue) { + defvalue = defaultvalue; + } + + virtual void param_update_default(const gchar * defaultvalue) { + param_update_default(enumdataconv->get_id_from_key(Glib::ustring(defaultvalue))); } private: diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp deleted file mode 100644 index 7696288b0d..0000000000 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ /dev/null @@ -1,873 +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/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 "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 next_is_line = is_straight_curve(*curve_it1); - bool 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].reversed(); - } - } 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_time(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_time(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; - if(_vector.size() == 0){ - return; - } - 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 next_is_line = is_straight_curve(*curve_it1); - bool 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_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::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() - rad_from_deg(270)); - aff *= Geom::Translate(last_pwd2[i].valueAt(Xvalue)); - pathv *= aff; - 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; - Geom::PathVector 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_time(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]); - Geom::PathVector 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, Geom::PathVector 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; - if (static_cast(_vector.size()) <= index){ - std::vector out; - out.push_back(0); - out.push_back(1); - out.push_back(0); - return out; - } - time_it1 = modf(to_time(index, _vector[index][X]), &intpart); - if (_vector[index][Y] == 0) { - time_it1 = 0; - } - double resultLenght = 0; - 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, Geom::PathVector 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, Geom::PathVector 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_time(p, pwd2[_index]); - Geom::Point const s = snap_knot_position(pwd2[_index].valueAt(t), state); - t = nearest_time(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()); - } - Geom::PathVector 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->use_distance, aprox); - } - -} - -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, 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(NULL, 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 b81339a69c..0000000000 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ /dev/null @@ -1,122 +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, Geom::PathVector subpaths); - virtual int last_index(int index, Geom::PathVector subpaths); - std::vector get_times(int index, Geom::PathVector 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 addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { - return true; - } - virtual void updateCanvasIndicators(); - 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; - } - 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; - 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 diff --git a/src/live_effects/parameter/fontbutton.cpp b/src/live_effects/parameter/fontbutton.cpp index baf24d77c4..c25cb30dd1 100644 --- a/src/live_effects/parameter/fontbutton.cpp +++ b/src/live_effects/parameter/fontbutton.cpp @@ -21,21 +21,27 @@ 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 ) + Effect* effect, const Glib::ustring defaultvalue ) : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) + value(defaultvalue), + defvalue(defaultvalue) { } -void -FontButtonParam::param_set_default() +Gtk::Widget * +FontButtonParam::param_newWidget() { - param_setValue(defvalue); -} -void -FontButtonParam::param_update_default(const Glib::ustring default_value){ - defvalue = default_value; + 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")); + return dynamic_cast (fontbuttonwdg); } bool @@ -53,20 +59,18 @@ FontButtonParam::param_getSVGValue() const return g_strdup(value.c_str()); } -Gtk::Widget * -FontButtonParam::param_newWidget() +void +FontButtonParam::param_valueFromDefault( bool write ) { - 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")); - return dynamic_cast (fontbuttonwdg); + param_setValue(defvalue); + if (write) { + param_writeToRepr(defvalue); + } +} + +void +FontButtonParam::param_updateDefault(const Glib::ustring defaultvalue){ + defvalue = defaultvalue; } void diff --git a/src/live_effects/parameter/fontbutton.h b/src/live_effects/parameter/fontbutton.h index df47251a2a..2093f38b75 100644 --- a/src/live_effects/parameter/fontbutton.h +++ b/src/live_effects/parameter/fontbutton.h @@ -21,19 +21,16 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const Glib::ustring default_value = ""); + const Glib::ustring defaultvalue = "Sans 10"); 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; }; + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + virtual void param_valueFromDefault(); + virtual void param_updateDefault(const gchar * default_value); + void param_setValue(Glib::ustring newvalue); + const Glib::ustring param_getValue() const { return value; }; private: FontButtonParam(const FontButtonParam&); diff --git a/src/live_effects/parameter/item.cpp b/src/live_effects/parameter/item.cpp index 93cf2b15f0..5f496e518e 100644 --- a/src/live_effects/parameter/item.cpp +++ b/src/live_effects/parameter/item.cpp @@ -38,13 +38,13 @@ 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) + Effect* effect, const gchar * defaultvalue) : Parameter(label, tip, key, wr, effect), changed(true), href(NULL), ref( (SPObject*)effect->getLPEObj() ) { - defvalue = g_strdup(default_value); + defvalue = g_strdup(defaultvalue); ref_changed_connection = ref.changedSignal().connect(sigc::mem_fun(*this, &ItemParam::ref_changed)); } @@ -55,16 +55,19 @@ ItemParam::~ItemParam() } void -ItemParam::param_set_default() +ItemParam::param_valueFromDefault() { param_readSVGValue(defvalue); } void -ItemParam::param_set_and_write_default() +ItemParam::param_valueFromDefault(bool write) { - param_write_to_repr(defvalue); + param_setValue(defvalue); + if (write) { + param_writeToRepr(defvalue); + } } bool @@ -227,7 +230,7 @@ ItemParam::on_link_button_click() // 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()); + param_writeToRepr(itemid.c_str()); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Link item parameter to path")); } diff --git a/src/live_effects/parameter/item.h b/src/live_effects/parameter/item.h index 6c719d4510..5baa2387e3 100644 --- a/src/live_effects/parameter/item.h +++ b/src/live_effects/parameter/item.h @@ -28,15 +28,13 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const gchar * default_value = ""); + const gchar * defaultvalue = ""); 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 bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + virtual void param_valueFromDefault( bool write ); + virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); sigc::signal signal_item_pasted; diff --git a/src/live_effects/parameter/originalpath.h b/src/live_effects/parameter/originalpath.h index b3feec41f4..5a62a3f561 100644 --- a/src/live_effects/parameter/originalpath.h +++ b/src/live_effects/parameter/originalpath.h @@ -29,7 +29,7 @@ public: virtual Gtk::Widget * param_newWidget(); /** Disable the canvas indicators of parent class by overriding this method */ - virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; + 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*/) {}; diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 693821ed25..3072d075f9 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -124,13 +124,13 @@ void OriginalPathArrayParam::on_reverse_toggled(const Glib::ustring& path) w->reversed = row[_model->_colReverse]; gchar * full = param_getSVGValue(); - param_write_to_repr(full); + param_writeToRepr(full); g_free(full); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Link path parameter to path")); } -void OriginalPathArrayParam::param_set_default() +void OriginalPathArrayParam::param_valueFromDefault(bool /*write*/) { } @@ -224,7 +224,7 @@ void OriginalPathArrayParam::on_up_button_click() } gchar * full = param_getSVGValue(); - param_write_to_repr(full); + param_writeToRepr(full); g_free(full); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, @@ -254,7 +254,7 @@ void OriginalPathArrayParam::on_down_button_click() } gchar * full = param_getSVGValue(); - param_write_to_repr(full); + param_writeToRepr(full); g_free(full); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, @@ -272,7 +272,7 @@ void OriginalPathArrayParam::on_remove_button_click() remove_link(row[_model->_colObject]); gchar * full = param_getSVGValue(); - param_write_to_repr(full); + param_writeToRepr(full); g_free(full); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, @@ -310,7 +310,7 @@ OriginalPathArrayParam::on_link_button_click() os << pathid.c_str() << ",0"; - param_write_to_repr(os.str().c_str()); + param_writeToRepr(os.str().c_str()); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Link path parameter to path")); } @@ -345,7 +345,7 @@ void OriginalPathArrayParam::linked_delete(SPObject */*deleted*/, PathAndDirecti //remove_link(to); gchar * full = param_getSVGValue(); - param_write_to_repr(full); + param_writeToRepr(full); g_free(full); } diff --git a/src/live_effects/parameter/originalpatharray.h b/src/live_effects/parameter/originalpatharray.h index 296c0f7f77..c9cba2f058 100644 --- a/src/live_effects/parameter/originalpatharray.h +++ b/src/live_effects/parameter/originalpatharray.h @@ -61,13 +61,13 @@ public: virtual ~OriginalPathArrayParam(); - virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_getSVGValue() const; - virtual void param_set_default(); + virtual Gtk::Widget * param_newWidget(); + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + virtual void param_valueFromDefault(bool write); /** Disable the canvas indicators of parent class by overriding this method */ - virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; + 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*/) {}; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 26a563909b..5270d246c4 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -37,164 +37,18 @@ Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, } void -Parameter::param_write_to_repr(const char * svgd) +Parameter::param_writeToRepr(const char * svgd) { param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); } -void Parameter::write_to_SVG(void) +void Parameter::writeToSVG(void) { gchar * str = param_getSVGValue(); - param_write_to_repr(str); + param_writeToRepr(str); g_free(str); } -/*########################################### - * REAL PARAM - */ -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) - : Parameter(label, tip, key, wr, effect), - value(default_value), - min(-SCALARPARAM_G_MAXDOUBLE), - max(SCALARPARAM_G_MAXDOUBLE), - integer(false), - defvalue(default_value), - digits(2), - inc_step(0.1), - inc_page(1), - add_slider(false), - overwrite_widget(false), - hide_widget(no_widget) -{ -} - -ScalarParam::~ScalarParam() -{ -} - -bool -ScalarParam::param_readSVGValue(const gchar * strvalue) -{ - double newval; - unsigned int success = sp_svg_number_read_d(strvalue, &newval); - if (success == 1) { - param_set_value(newval); - return true; - } - return false; -} - -gchar * -ScalarParam::param_getSVGValue() const -{ - Inkscape::SVGOStringStream os; - os << value; - gchar * str = g_strdup(os.str().c_str()); - return str; -} - -void -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) -{ - value = val; - if (integer) - value = round(value); - if (value > max) - value = max; - if (value < min) - value = min; -} - -void -ScalarParam::param_set_range(gdouble min, gdouble max) -{ - // if you look at client code, you'll see that many effects - // has a tendency to set an upper range of Geom::infinity(). - // 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. - if (min >= -SCALARPARAM_G_MAXDOUBLE) { - this->min = min; - } else { - this->min = -SCALARPARAM_G_MAXDOUBLE; - } - if (max <= SCALARPARAM_G_MAXDOUBLE) { - this->max = max; - } else { - this->max = SCALARPARAM_G_MAXDOUBLE; - } - param_set_value(value); // reset value to see whether it is in ranges -} - -void -ScalarParam::param_make_integer(bool yes) -{ - integer = yes; - digits = 0; - inc_step = 1; - inc_page = 10; -} - -void -ScalarParam::param_overwrite_widget(bool overwrite_widget) -{ - this->overwrite_widget = overwrite_widget; -} - -Gtk::Widget * -ScalarParam::param_newWidget() -{ - if(!hide_widget){ - 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; - if (add_slider) { - rsu->addSlider(); - } - if(!overwrite_widget){ - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); - } - return dynamic_cast (rsu); - } else { - return NULL; - } -} - -void -ScalarParam::param_set_digits(unsigned digits) -{ - this->digits = digits; -} - -void -ScalarParam::param_set_increments(double step, double page) -{ - inc_step = step; - inc_page = page; -} - - - - } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 6cf10710c5..914a2c9067 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -14,13 +14,6 @@ #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 -// in gtk3, it is an issue: it allocates widget size for the maxmium -// value you pass to it, leading to some insane lengths. -// If you need this to be more, please be conservative about it. -const double SCALARPARAM_G_MAXDOUBLE = 10000000000.0; // TODO fixme: using an arbitrary large number as a magic value seems fragile. - class KnotHolder; class SPLPEItem; class SPDesktop; @@ -55,95 +48,42 @@ public: Effect* effect); virtual ~Parameter() {}; - virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. - virtual gchar * param_getSVGValue() const = 0; - void write_to_SVG(); - - virtual void param_set_default() = 0; + void writeToSVG(); + virtual Gtk::Widget * param_newWidget() = 0; + // Returns true if new value is valid / accepted. + virtual bool param_readSVGValue(const gchar * strvalue) = 0; + virtual gchar * param_getSVGValue() const = 0; + virtual void param_valueFromDefault(bool write = false) = 0; + virtual void param_updateDefault(bool const defaultvalue) = 0; + virtual void param_updateDefault(const gchar * default_value) = 0; // This creates a new widget (newed with Gtk::manage(new ...);) - virtual Gtk::Widget * param_newWidget() = 0; - - virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + virtual void param_transformMultiply(Geom::Affine const& /*postmul*/, bool /*set*/) {}; - // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths + // 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*/, SPItem */*item*/) {}; virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector &/*hp_vec*/) {}; - - virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; - virtual void param_setup_nodepath(Inkscape::NodePath::Path */*np*/) {}; - - virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) {}; + virtual void param_editOnCanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; + virtual void param_setupNodepath(Inkscape::NodePath::Path */*np*/) {}; Glib::ustring param_key; Inkscape::UI::Widget::Registry * param_wr; Glib::ustring param_label; - bool oncanvas_editable; bool widget_is_visible; protected: Glib::ustring param_tooltip; - Effect* param_effect; - - void param_write_to_repr(const char * svgd); + void param_writeToRepr(const char * svgd); private: Parameter(const Parameter&); Parameter& operator=(const Parameter&); }; - -class ScalarParam : public Parameter { -public: - ScalarParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - gdouble default_value = 1.0, - bool no_widget = false); - virtual ~ScalarParam(); - - virtual bool param_readSVGValue(const gchar * strvalue); - 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); - 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(); - - inline operator gdouble() const { return value; }; - -protected: - gdouble value; - gdouble min; - gdouble max; - bool integer; - gdouble defvalue; - unsigned digits; - double inc_step; - double inc_page; - bool add_slider; - bool overwrite_widget; - bool hide_widget; - -private: - ScalarParam(const ScalarParam&); - ScalarParam& operator=(const ScalarParam&); -}; - } //namespace LivePathEffect } //namespace Inkscape diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index dafc6d406e..331b90f6af 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -57,7 +57,7 @@ namespace LivePathEffect { PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const gchar * default_value) + Effect* effect, const gchar * defaultvalue) : Parameter(label, tip, key, wr, effect), changed(true), _pathvector(), @@ -66,7 +66,7 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, href(NULL), ref( (SPObject*)effect->getLPEObj() ) { - defvalue = g_strdup(default_value); + defvalue = g_strdup(defaultvalue); param_readSVGValue(defvalue); oncanvas_editable = true; @@ -108,15 +108,15 @@ PathParam::get_pwd2() } void -PathParam::param_set_default() +PathParam::param_valueFromDefault() { param_readSVGValue(defvalue); } void -PathParam::param_set_and_write_default() +PathParam::param_valueFromDefault( true ) { - param_write_to_repr(defvalue); + param_writeToRepr(defvalue); } bool @@ -222,7 +222,7 @@ PathParam::param_newWidget() } void -PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) +PathParam::param_editOnCanvas(SPItem *item, SPDesktop * dt) { SPDocument *document = dt->getDocument(); bool saved = DocumentUndo::getUndoSensitive(document); @@ -244,9 +244,9 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) r.item = reinterpret_cast(param_effect->getLPEObj()); r.lpe_key = param_key; Geom::PathVector stored_pv = _pathvector; - param_write_to_repr("M0,0 L1,0"); + param_writeToRepr("M0,0 L1,0"); const char *svgd = sp_svg_write_path(stored_pv); - param_write_to_repr(svgd); + param_writeToRepr(svgd); } else { r.item = ref.getObject(); } @@ -256,7 +256,7 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) } void -PathParam::param_setup_nodepath(Inkscape::NodePath::Path *) +PathParam::param_setupNodepath(Inkscape::NodePath::Path *) { // TODO this method should not exist at all! } @@ -271,7 +271,7 @@ PathParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector > const & newpa if (write_to_svg) { gchar * svgd = sp_svg_write_path( _pathvector ); - param_write_to_repr(svgd); + param_writeToRepr(svgd); g_free(svgd); // After the whole "writing to svg avalanche of function calling": force value upon pwd2 and don't recalculate. @@ -320,7 +320,7 @@ PathParam::set_new_value (Geom::PathVector const &newpath, bool write_to_svg) { remove_link(); if (newpath.empty()) { - param_set_and_write_default(); + param_valueFromDefault( true ); return; } else { _pathvector = newpath; @@ -329,7 +329,7 @@ PathParam::set_new_value (Geom::PathVector const &newpath, bool write_to_svg) if (write_to_svg) { gchar * svgd = sp_svg_write_path( _pathvector ); - param_write_to_repr(svgd); + param_writeToRepr(svgd); g_free(svgd); } else { emit_changed(); @@ -446,7 +446,7 @@ PathParam::on_edit_button_click() { SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); if (item != NULL) { - param_editOncanvas(item, SP_ACTIVE_DESKTOP); + param_editOnCanvas(item, SP_ACTIVE_DESKTOP); } } @@ -464,7 +464,7 @@ PathParam::paste_param_path(const char *svgd) svgd = sp_svg_write_path( path_clipboard ); } - param_write_to_repr(svgd); + param_writeToRepr(svgd); signal_path_pasted.emit(); } } @@ -506,7 +506,7 @@ PathParam::on_link_button_click() // 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(pathid.c_str()); + param_writeToRepr(pathid.c_str()); DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Link path parameter to path")); } diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index d2dddbe97c..d9f248de27 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -28,7 +28,7 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const gchar * default_value = "M0,0 L1,1"); + const gchar * defaultvalue = "M0,0 L1,1"); virtual ~PathParam(); Geom::PathVector const & get_pathvector() const; @@ -39,16 +39,16 @@ public: 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 param_valueFromDefault(); + void param_valueFromDefault( true ); void set_new_value (Geom::PathVector const &newpath, bool write_to_svg); void set_new_value (Geom::Piecewise > const &newpath, bool write_to_svg); - virtual void param_editOncanvas(SPItem * item, SPDesktop * dt); - virtual void param_setup_nodepath(Inkscape::NodePath::Path *np); + virtual void param_editOnCanvas(SPItem * item, SPDesktop * dt); + virtual void param_setupNodepath(Inkscape::NodePath::Path *np); virtual void addCanvasIndicators(SPLPEItem const* lpeitem, std::vector &hp_vec); - virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); + virtual void param_transformMultiply(Geom::Affine const& /*postmul*/, bool /*set*/); sigc::signal signal_path_pasted; sigc::signal signal_path_changed; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 55dc79fe8e..1bb9acedcb 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -21,10 +21,10 @@ namespace LivePathEffect { PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const gchar *htip, Geom::Point default_value, + Effect* effect, const gchar *htip, Geom::Point defaultvalue, bool live_update ) : Parameter(label, tip, key, wr, effect), - defvalue(default_value), + defvalue(defaultvalue), liveupdate(live_update), knoth(NULL) { @@ -41,24 +41,24 @@ PointParam::~PointParam() } void -PointParam::param_set_default() +PointParam::param_valueFromDefault() { param_setValue(defvalue,true); } void -PointParam::param_set_liveupdate( bool live_update) +PointParam::param_setLiveupdate( bool live_update) { liveupdate = live_update; } Geom::Point -PointParam::param_get_default() const{ +PointParam::param_getDefault() const{ return defvalue; } void -PointParam::param_update_default(Geom::Point default_point) +PointParam::param_updateDefault(Geom::Point default_point) { defvalue = default_point; } @@ -71,7 +71,7 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) Inkscape::SVGOStringStream os; os << newpoint; gchar * str = g_strdup(os.str().c_str()); - param_write_to_repr(str); + param_writeToRepr(str); g_free(str); } if(knoth && liveupdate){ @@ -104,7 +104,7 @@ PointParam::param_getSVGValue() const } void -PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +PointParam::param_transformMultiply(Geom::Affine const& postmul, bool /*set*/) { param_setValue( (*this) * postmul, true); } @@ -112,7 +112,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, @@ -133,7 +133,7 @@ PointParam::param_newWidget() } void -PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) +PointParam::set_onCanvasLooks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { knot_shape = shape; knot_mode = mode; @@ -169,10 +169,6 @@ PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &or } } pparam->param_setValue(s, this->pparam->liveupdate); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem && this->pparam->liveupdate){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } } Geom::Point @@ -186,7 +182,7 @@ PointParamKnotHolderEntity::knot_click(guint state) { if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - this->pparam->param_set_default(); + this->pparam->param_valueFromDefault(); 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 5d145a81aa..712442b17b 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -30,7 +30,7 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect, const gchar *handle_tip = NULL,// tip for automatically associated on-canvas handle - Geom::Point default_value = Geom::Point(0,0), + Geom::Point defaultvalue = Geom::Point(0,0), bool live_update = true ); virtual ~PointParam(); @@ -40,13 +40,13 @@ public: gchar * param_getSVGValue() const; inline const gchar *handleTip() const { return handle_tip ? handle_tip : param_tooltip.c_str(); } void param_setValue(Geom::Point newpoint, bool write = false); - void param_set_default(); - Geom::Point param_get_default() const; - void param_set_liveupdate(bool live_update); - void param_update_default(Geom::Point default_point); - virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/); + void param_valueFromDefault(); + Geom::Point param_getDefault() const; + void param_setLiveupdate(bool live_update); + void param_updateDefault(Geom::Point default_point); + virtual void param_transformMultiply(Geom::Affine const& /*postmul*/, bool /*set*/); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + void set_onCanvasLooks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); virtual bool providesKnotHolderEntities() const { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index 7753d819d4..e14cdc774b 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -42,7 +42,7 @@ PowerStrokePointArrayParam::param_newWidget() return NULL; } -void PowerStrokePointArrayParam::param_transform_multiply(Geom::Affine const &postmul, bool /*set*/) +void PowerStrokePointArrayParam::param_transformMultiply(Geom::Affine const &postmul, bool /*set*/) { // Check if proportional stroke-width scaling is on Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -57,7 +57,7 @@ void PowerStrokePointArrayParam::param_transform_multiply(Geom::Affine const &po Geom::Coord const A = (*point_it)[Geom::Y] * ((postmul.expansionX() + postmul.expansionY()) / 2); result.push_back(Geom::Point((*point_it)[Geom::X], A)); } - param_set_and_write_new_value(result); + param_setAndWriteNewValue(result); } } @@ -85,7 +85,7 @@ PowerStrokePointArrayParam::recalculate_controlpoints_for_new_pwd2(Geom::Piecewi } } - write_to_SVG(); + writeToSVG(); } } @@ -115,7 +115,7 @@ PowerStrokePointArrayParam::set_pwd2(Geom::Piecewise > co void -PowerStrokePointArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) +PowerStrokePointArrayParam::set_onCanvasLooks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { knot_shape = shape; knot_mode = mode; @@ -202,7 +202,7 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) // delete the clicked knot std::vector & vec = _pparam->_vector; vec.erase(vec.begin() + _index); - _pparam->param_set_and_write_new_value(vec); + _pparam->param_setAndWriteNewValue(vec); // remove knot from knotholder parent_holder->entity.remove(this); @@ -222,7 +222,7 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) // add a knot to XML std::vector & vec = _pparam->_vector; vec.insert(vec.begin() + _index, 1, vec.at(_index)); // this clicked knot is duplicated - _pparam->param_set_and_write_new_value(vec); + _pparam->param_setAndWriteNewValue(vec); // shift knots up one index for(std::list::iterator ent = parent_holder->entity.begin(); ent != parent_holder->entity.end(); ++ent) { diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h index 56a609fa87..4709e8aac9 100644 --- a/src/live_effects/parameter/powerstrokepointarray.h +++ b/src/live_effects/parameter/powerstrokepointarray.h @@ -31,9 +31,9 @@ public: virtual Gtk::Widget * param_newWidget(); - virtual void param_transform_multiply(Geom::Affine const& postmul, bool /*set*/); + virtual void param_transformMultiply(Geom::Affine const& postmul, bool /*set*/); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + void set_onCanvasLooks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); float median_width(); diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 075e85ee1d..0ba615b61d 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -24,10 +24,10 @@ namespace LivePathEffect { RandomParam::RandomParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, gdouble default_value, long default_seed) + Effect* effect, gdouble defaultvalue, long default_seed) : Parameter(label, tip, key, wr, effect) { - defvalue = default_value; + defvalue = defaultvalue; value = defvalue; min = -Geom::infinity(); max = Geom::infinity(); @@ -51,9 +51,9 @@ RandomParam::param_readSVGValue(const gchar * strvalue) if (success == 1) { success += sp_svg_number_read_d(stringarray[1], &newstartseed); if (success == 2) { - param_set_value(newval, static_cast(newstartseed)); + param_setValue(newval, static_cast(newstartseed)); } else { - param_set_value(newval, defseed); + param_setValue(newval, defseed); } g_strfreev(stringarray); return true; @@ -72,13 +72,13 @@ RandomParam::param_getSVGValue() const } void -RandomParam::param_set_default() +RandomParam::param_valueFromDefault() { - param_set_value(defvalue, defseed); + param_setValue(defvalue, defseed); } void -RandomParam::param_set_value(gdouble val, long newseed) +RandomParam::param_setValue(gdouble val, long newseed) { value = val; if (integer) @@ -93,14 +93,14 @@ RandomParam::param_set_value(gdouble val, long newseed) } void -RandomParam::param_set_range(gdouble min, gdouble max) +RandomParam::param_setRange(gdouble min, gdouble max) { this->min = min; this->max = max; } void -RandomParam::param_make_integer(bool yes) +RandomParam::param_makeInteger(bool yes) { integer = yes; } diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index ca4440336e..df85e471c4 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -25,19 +25,19 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - gdouble default_value = 1.0, + gdouble defaultvalue = 1.0, long default_seed = 0); virtual ~RandomParam(); virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; - virtual void param_set_default(); + virtual void param_valueFromDefault(); virtual Gtk::Widget * param_newWidget(); - 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_setValue(gdouble val, long newseed); + void param_makeInteger(bool yes = true); + void param_setRange(gdouble min, gdouble max); void resetRandomizer(); diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index 47fbd39af9..5829f0a124 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -28,15 +28,15 @@ namespace LivePathEffect { TextParam::TextParam( 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 defaultvalue ) : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value), + value(defaultvalue), + defvalue(defaultvalue), _hide_canvas_text(false) { 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_text (canvas_text, defaultvalue.c_str()); sp_canvastext_set_coords (canvas_text, 0, 0); } else { _hide_canvas_text = true; @@ -44,15 +44,15 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, } void -TextParam::param_set_default() +TextParam::param_valueFromDefault() { param_setValue(defvalue); } void -TextParam::param_update_default(Glib::ustring default_value) +TextParam::param_updateDefault(Glib::ustring defaultvalue) { - defvalue = default_value; + defvalue = defaultvalue; } void diff --git a/src/live_effects/parameter/text.h b/src/live_effects/parameter/text.h index 553c84c0ab..fe2c05ef09 100644 --- a/src/live_effects/parameter/text.h +++ b/src/live_effects/parameter/text.h @@ -31,7 +31,7 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - const Glib::ustring default_value = ""); + const Glib::ustring defaultvalue = ""); virtual ~TextParam() {} virtual Gtk::Widget * param_newWidget(); @@ -41,8 +41,8 @@ public: 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); + virtual void param_valueFromDefault(); + void param_updateDefault(Glib::ustring defaultvalue); void setPos(Geom::Point pos); void setPosAndAnchor(const Geom::Piecewise > &pwd2, const double t, const double length, bool use_curvature = false); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index f7042b6d1a..e6a88c3c35 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, + Effect* effect, bool defaultvalue, const Glib::ustring& inactive_label, char const * _icon_active, char const * _icon_inactive, Inkscape::IconSize _icon_size) - : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), + : Parameter(label, tip, key, wr, effect), value(defaultvalue), defvalue(defaultvalue), inactive_label(inactive_label), _icon_active(_icon_active), _icon_inactive(_icon_inactive), _icon_size(_icon_size) { checkwdg = NULL; @@ -41,7 +41,7 @@ ToggleButtonParam::~ToggleButtonParam() } void -ToggleButtonParam::param_set_default() +ToggleButtonParam::param_valueFromDefault() { param_setValue(defvalue); } diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 8390fec866..ffebaf2a80 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -30,7 +30,7 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - bool default_value = false, + bool defaultvalue = false, const Glib::ustring& inactive_label = "", char const * icon_active = NULL, char const * icon_inactive = NULL, @@ -43,7 +43,7 @@ public: virtual gchar * param_getSVGValue() const; void param_setValue(bool newvalue); - virtual void param_set_default(); + virtual void param_valueFromDefault(); bool get_value() const { return value; }; diff --git a/src/live_effects/parameter/transformedpoint.cpp b/src/live_effects/parameter/transformedpoint.cpp index 0d03432c35..8514d5b1ac 100644 --- a/src/live_effects/parameter/transformedpoint.cpp +++ b/src/live_effects/parameter/transformedpoint.cpp @@ -42,7 +42,7 @@ TransformedPointParam::~TransformedPointParam() } void -TransformedPointParam::param_set_default() +TransformedPointParam::param_valueFromDefault() { setOrigin(Geom::Point(0.,0.)); setVector(defvalue); @@ -109,12 +109,12 @@ TransformedPointParam::set_and_write_new_values(Geom::Point const &new_origin, G { setValues(new_origin, new_vector); gchar * str = param_getSVGValue(); - param_write_to_repr(str); + param_writeToRepr(str); g_free(str); } void -TransformedPointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +TransformedPointParam::param_transformMultiply(Geom::Affine const& postmul, bool /*set*/) { if (!noTransform) { set_and_write_new_values( origin * postmul, vector * postmul.withoutTranslation() ); diff --git a/src/live_effects/parameter/transformedpoint.h b/src/live_effects/parameter/transformedpoint.h index c96bedb539..ae2264f949 100644 --- a/src/live_effects/parameter/transformedpoint.h +++ b/src/live_effects/parameter/transformedpoint.h @@ -43,11 +43,11 @@ public: void setValues(Geom::Point const &new_origin, Geom::Point const &new_vector) { setVector(new_vector); setOrigin(new_origin); }; void setVector(Geom::Point const &new_vector) { vector = new_vector; }; void setOrigin(Geom::Point const &new_origin) { origin = new_origin; }; - virtual void param_set_default(); + virtual void param_valueFromDefault(); void set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector); - virtual void param_transform_multiply(Geom::Affine const &postmul, bool set); + virtual void param_transformMultiply(Geom::Affine const &postmul, bool set); void set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); void set_oncanvas_color(guint32 color); diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index b6ea99bfe0..21483451df 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -36,7 +36,7 @@ bool UnitParam::param_readSVGValue(const gchar * strvalue) { if (strvalue) { - param_set_value(*unit_table.getUnit(strvalue)); + param_setValue(*unit_table.getUnit(strvalue)); return true; } return false; @@ -49,19 +49,19 @@ UnitParam::param_getSVGValue() const } void -UnitParam::param_set_default() +UnitParam::param_valueFromDefault() { - param_set_value(*defunit); + param_setValue(*defunit); } void -UnitParam::param_update_default(const Glib::ustring default_unit) +UnitParam::param_updateDefault(const Glib::ustring default_unit) { defunit = unit_table.getUnit(default_unit); } void -UnitParam::param_set_value(Inkscape::Util::Unit const &val) +UnitParam::param_setValue(Inkscape::Util::Unit const &val) { unit = new Inkscape::Util::Unit(val); } diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index ae58cf9569..3695e789b7 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -31,9 +31,9 @@ public: virtual bool param_readSVGValue(const gchar * strvalue); 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_valueFromDefault(); + void param_setValue(Inkscape::Util::Unit const &val); + void param_updateDefault(const Glib::ustring default_unit); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 55b4d4b328..e8056cff3f 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -42,7 +42,7 @@ VectorParam::~VectorParam() } void -VectorParam::param_set_default() +VectorParam::param_valueFromDefault() { setOrigin(Geom::Point(0.,0.)); setVector(defvalue); @@ -109,12 +109,12 @@ VectorParam::set_and_write_new_values(Geom::Point const &new_origin, Geom::Point { setValues(new_origin, new_vector); gchar * str = param_getSVGValue(); - param_write_to_repr(str); + param_writeToRepr(str); g_free(str); } void -VectorParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +VectorParam::param_transformMultiply(Geom::Affine const& postmul, bool /*set*/) { set_and_write_new_values( origin * postmul, vector * postmul.withoutTranslation() ); } diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index edee4ff4d4..f333eef988 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -42,11 +42,11 @@ public: void setValues(Geom::Point const &new_origin, Geom::Point const &new_vector) { setVector(new_vector); setOrigin(new_origin); }; void setVector(Geom::Point const &new_vector) { vector = new_vector; }; void setOrigin(Geom::Point const &new_origin) { origin = new_origin; }; - virtual void param_set_default(); + virtual void param_valueFromDefault(); void set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector); - virtual void param_transform_multiply(Geom::Affine const &postmul, bool set); + virtual void param_transformMultiply(Geom::Affine const &postmul, bool set); void set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); void set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 389e8902a6..e98b146997 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -86,7 +86,6 @@ set(ui_SRC dialog/layers.cpp dialog/livepatheffect-add.cpp dialog/livepatheffect-editor.cpp - dialog/lpe-fillet-chamfer-properties.cpp dialog/lpe-powerstroke-properties.cpp dialog/memory.cpp dialog/messages.cpp @@ -229,7 +228,6 @@ set(ui_SRC dialog/layers.h dialog/livepatheffect-add.h dialog/livepatheffect-editor.h - dialog/lpe-fillet-chamfer-properties.h dialog/lpe-powerstroke-properties.h dialog/memory.h dialog/messages.h diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 45fde90963..5ee836b809 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -191,6 +191,10 @@ LivePathEffectEditor::~LivePathEffectEditor() void LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) { + if ( ! effect.upd_params ) { + return; + } + std::cout << "sdgsdgdsgsdgsdgsdgdgdggsdgsd\n"; if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); delete effectwidget; @@ -208,6 +212,7 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) status_label.hide(); effectcontrol_frame.show(); effectcontrol_vbox.show_all_children(); + effect.upd_params = false; // fixme: add resizing of dialog } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp deleted file mode 100644 index 0baf15e6b6..0000000000 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/** - * From the code of Liam P.White from his Power Stroke Knot dialog - * - * Released under GNU GPL. Read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "lpe-fillet-chamfer-properties.h" -#include -#include -#include "inkscape.h" -#include "desktop.h" -#include "document-undo.h" -#include "layer-manager.h" -#include "message-stack.h" - -#include "selection-chemistry.h" - -//#include "event-context.h" - -namespace Inkscape { -namespace UI { -namespace Dialogs { - -FilletChamferPropertiesDialog::FilletChamferPropertiesDialog() - : _desktop(NULL), - _knotpoint(NULL), - _position_visible(false), - _close_button(_("_Cancel"), true) -{ - Gtk::Box *mainVBox = get_vbox(); - mainVBox->set_homogeneous(false); - _layout_table.set_row_spacing(4); - _layout_table.set_column_spacing(4); - - // Layer name widgets - _fillet_chamfer_position_numeric.set_digits(4); - _fillet_chamfer_position_numeric.set_increments(1,1); - //todo: get tha max aloable infinity freeze the widget - _fillet_chamfer_position_numeric.set_range(0., SCALARPARAM_G_MAXDOUBLE); - _fillet_chamfer_position_numeric.set_hexpand(); - - _fillet_chamfer_position_label.set_label(_("Radius (pixels):")); - _fillet_chamfer_position_label.set_alignment(1.0, 0.5); - - _layout_table.attach(_fillet_chamfer_position_label, 0, 0, 1, 1); - _layout_table.attach(_fillet_chamfer_position_numeric, 1, 0, 1, 1); - _fillet_chamfer_chamfer_subdivisions.set_digits(0); - _fillet_chamfer_chamfer_subdivisions.set_increments(1,1); - //todo: get tha max aloable infinity freeze the widget - _fillet_chamfer_chamfer_subdivisions.set_range(0, SCALARPARAM_G_MAXDOUBLE); - _fillet_chamfer_chamfer_subdivisions.set_hexpand(); - - _fillet_chamfer_chamfer_subdivisions_label.set_label(_("Chamfer subdivisions:")); - _fillet_chamfer_chamfer_subdivisions_label.set_alignment(1.0, 0.5); - - _layout_table.attach(_fillet_chamfer_chamfer_subdivisions_label, 0, 1, 1, 1); - _layout_table.attach(_fillet_chamfer_chamfer_subdivisions, 1, 1, 1, 1); - _fillet_chamfer_type_fillet.set_label(_("Fillet")); - _fillet_chamfer_type_fillet.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_inverse_fillet.set_label(_("Inverse fillet")); - _fillet_chamfer_type_inverse_fillet.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_chamfer.set_label(_("Chamfer")); - _fillet_chamfer_type_chamfer.set_group(_fillet_chamfer_type_group); - _fillet_chamfer_type_inverse_chamfer.set_label(_("Inverse chamfer")); - _fillet_chamfer_type_inverse_chamfer.set_group(_fillet_chamfer_type_group); - - - mainVBox->pack_start(_layout_table, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_fillet, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_inverse_fillet, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_chamfer, true, true, 4); - mainVBox->pack_start(_fillet_chamfer_type_inverse_chamfer, true, true, 4); - - // Buttons - _close_button.set_can_default(); - - _apply_button.set_use_underline(true); - _apply_button.set_can_default(); - - _close_button.signal_clicked() - .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)); - _apply_button.signal_clicked() - .connect(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_apply)); - - signal_delete_event().connect(sigc::bind_return( - sigc::hide(sigc::mem_fun(*this, &FilletChamferPropertiesDialog::_close)), - true)); - - add_action_widget(_close_button, Gtk::RESPONSE_CLOSE); - add_action_widget(_apply_button, Gtk::RESPONSE_APPLY); - - _apply_button.grab_default(); - - show_all_children(); - - set_focus(_fillet_chamfer_position_numeric); -} - -FilletChamferPropertiesDialog::~FilletChamferPropertiesDialog() -{ - - _set_desktop(NULL); -} - -void FilletChamferPropertiesDialog::showDialog( - SPDesktop *desktop, Geom::Point knotpoint, - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt, - bool use_distance, - bool aprox_radius) -{ - FilletChamferPropertiesDialog *dialog = new FilletChamferPropertiesDialog(); - - dialog->_set_desktop(desktop); - dialog->_set_use_distance(use_distance); - dialog->_set_aprox(aprox_radius); - dialog->_set_knot_point(knotpoint); - dialog->_set_pt(pt); - - dialog->set_title(_("Modify Fillet-Chamfer")); - dialog->_apply_button.set_label(_("_Modify")); - - dialog->set_modal(true); - desktop->setWindowTransient(dialog->gobj()); - dialog->property_destroy_with_parent() = true; - - dialog->show(); - dialog->present(); -} - -void FilletChamferPropertiesDialog::_apply() -{ - double d_width; - double d_pos = _fillet_chamfer_position_numeric.get_value(); - if (d_pos) { - if (_fillet_chamfer_type_fillet.get_active() == true) { - d_width = 1; - } else if (_fillet_chamfer_type_inverse_fillet.get_active() == true) { - d_width = 2; - } else if (_fillet_chamfer_type_inverse_chamfer.get_active() == true) { - d_width = _fillet_chamfer_chamfer_subdivisions.get_value() + 4000; - } else { - d_width = _fillet_chamfer_chamfer_subdivisions.get_value() + 3000; - } - if (_flexible) { - if (d_pos > 99.99999 || d_pos < 0) { - d_pos = 0; - } - d_pos = _index + (d_pos / 100); - } else { - d_pos = d_pos * -1; - } - _knotpoint->knot_set_offset(Geom::Point(d_pos, d_width)); - } - _close(); -} - -void FilletChamferPropertiesDialog::_close() -{ - _set_desktop(NULL); - destroy_(); - Glib::signal_idle().connect( - sigc::bind_return( - sigc::bind(sigc::ptr_fun(&::operator delete), this), - false - ) - ); -} - -bool FilletChamferPropertiesDialog::_handleKeyEvent(GdkEventKey * /*event*/) -{ - return false; -} - -void FilletChamferPropertiesDialog::_handleButtonEvent(GdkEventButton *event) -{ - if ((event->type == GDK_2BUTTON_PRESS) && (event->button == 1)) { - _apply(); - } -} - -void FilletChamferPropertiesDialog::_set_knot_point(Geom::Point knotpoint) -{ - double position; - std::string distance_or_radius = std::string(_("Radius")); - if(aprox){ - distance_or_radius = std::string(_("Radius approximated")); - } - if(use_distance){ - distance_or_radius = std::string(_("Knot distance")); - } - if (knotpoint.x() > 0) { - double intpart; - position = modf(knotpoint[Geom::X], &intpart) * 100; - _flexible = true; - _index = intpart; - _fillet_chamfer_position_label.set_label(_("Position (%):")); - } else { - _flexible = false; - std::string posConcat = Glib::ustring::compose (_("%1:"), distance_or_radius); - _fillet_chamfer_position_label.set_label(_(posConcat.c_str())); - position = knotpoint[Geom::X] * -1; - } - _fillet_chamfer_position_numeric.set_value(position); - if (knotpoint.y() == 1) { - _fillet_chamfer_type_fillet.set_active(true); - } else if (knotpoint.y() == 2) { - _fillet_chamfer_type_inverse_fillet.set_active(true); - } else if (knotpoint.y() >= 3000 && knotpoint.y() < 4000) { - _fillet_chamfer_chamfer_subdivisions.set_value(knotpoint.y() - 3000); - _fillet_chamfer_type_chamfer.set_active(true); - } else if (knotpoint.y() >= 4000 && knotpoint.y() < 5000) { - _fillet_chamfer_chamfer_subdivisions.set_value(knotpoint.y() - 4000); - _fillet_chamfer_type_inverse_chamfer.set_active(true); - } -} - -void FilletChamferPropertiesDialog::_set_pt( - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt) -{ - _knotpoint = const_cast< - Inkscape::LivePathEffect::FilletChamferPointArrayParamKnotHolderEntity *>( - pt); -} - -void FilletChamferPropertiesDialog::_set_use_distance(bool use_knot_distance) -{ - use_distance = use_knot_distance; -} - -void FilletChamferPropertiesDialog::_set_aprox(bool aprox_radius) -{ - aprox = aprox_radius; -} - -void FilletChamferPropertiesDialog::_set_desktop(SPDesktop *desktop) -{ - if (desktop) { - Inkscape::GC::anchor(desktop); - } - if (_desktop) { - Inkscape::GC::release(_desktop); - } - _desktop = desktop; -} - -} // namespace -} // namespace -} // namespace - -/* - 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:fileencoding=utf-8:textwidth=99 diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h deleted file mode 100644 index c74e3f0116..0000000000 --- a/src/ui/dialog/lpe-fillet-chamfer-properties.h +++ /dev/null @@ -1,109 +0,0 @@ -/** - * - * From the code of Liam P.White from his Power Stroke Knot dialog - * - * Released under GNU GPL. Read the file 'COPYING' for more information - */ - -#ifndef INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H -#define INKSCAPE_DIALOG_FILLET_CHAMFER_PROPERTIES_H - -#include <2geom/point.h> -#include -#include "live_effects/parameter/filletchamferpointarray.h" - -class SPDesktop; - -namespace Inkscape { -namespace UI { -namespace Dialogs { - -class FilletChamferPropertiesDialog : public Gtk::Dialog { -public: - FilletChamferPropertiesDialog(); - virtual ~FilletChamferPropertiesDialog(); - - Glib::ustring getName() const { - return "LayerPropertiesDialog"; - } - - static void showDialog(SPDesktop *desktop, Geom::Point knotpoint, - const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt, - bool use_distance, - bool aprox_radius); - -protected: - - SPDesktop *_desktop; - Inkscape::LivePathEffect::FilletChamferPointArrayParamKnotHolderEntity * - _knotpoint; - - Gtk::Label _fillet_chamfer_position_label; - Gtk::SpinButton _fillet_chamfer_position_numeric; - Gtk::RadioButton::Group _fillet_chamfer_type_group; - Gtk::RadioButton _fillet_chamfer_type_fillet; - Gtk::RadioButton _fillet_chamfer_type_inverse_fillet; - Gtk::RadioButton _fillet_chamfer_type_chamfer; - Gtk::RadioButton _fillet_chamfer_type_inverse_chamfer; - Gtk::Label _fillet_chamfer_chamfer_subdivisions_label; - Gtk::SpinButton _fillet_chamfer_chamfer_subdivisions; - - Gtk::Grid _layout_table; - bool _position_visible; - double _index; - - Gtk::Button _close_button; - Gtk::Button _apply_button; - - sigc::connection _destroy_connection; - - static FilletChamferPropertiesDialog &_instance() { - static FilletChamferPropertiesDialog instance; - return instance; - } - - void _set_desktop(SPDesktop *desktop); - void _set_pt(const Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity *pt); - void _set_use_distance(bool use_knot_distance); - void _set_aprox(bool aprox_radius); - void _apply(); - void _close(); - bool _flexible; - bool use_distance; - bool aprox; - void _set_knot_point(Geom::Point knotpoint); - void _prepareLabelRenderer(Gtk::TreeModel::const_iterator const &row); - - bool _handleKeyEvent(GdkEventKey *event); - void _handleButtonEvent(GdkEventButton *event); - - friend class Inkscape::LivePathEffect:: - FilletChamferPointArrayParamKnotHolderEntity; - -private: - FilletChamferPropertiesDialog( - FilletChamferPropertiesDialog const &); // no copy - FilletChamferPropertiesDialog &operator=( - FilletChamferPropertiesDialog const &); // no assign -}; - -} // namespace -} // namespace -} // namespace - -#endif //INKSCAPE_DIALOG_LAYER_PROPERTIES_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:fileencoding=utf-8:textwidth=99 -// : -- GitLab From 14fc8c02eab10f3c43e25c0e9f99720e54ce69a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 5 May 2017 16:41:34 +0200 Subject: [PATCH 117/121] Improve responsive from LPE Fixed bugs: - https://launchpad.net/bugs/1688168 (bzr r15660.1.2) --- 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 + src/ui/dialog/livepatheffect-editor.cpp | 15 +++++++- src/ui/dialog/livepatheffect-editor.h | 2 +- 16 files changed, 77 insertions(+), 45 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 326225e0c6..8df1aa9270 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 973516133d..f5e41d50ef 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 900fc8b679..ffd2ef4cfe 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 b411bd699d..4e93a25724 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 c853e4afa8..a5d1d23c8e 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 365ff53896..3cff83fedc 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 ef29007750..f4d233d566 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 1bd5f96ad8..0a1647623e 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 dbfc686237..05ac393c1f 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 baf24d77c4..31534fba09 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 26a563909b..256ebf322a 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 55dc79fe8e..e5216bf2d2 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 f7042b6d1a..dd9ea6fb2d 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 b6ea99bfe0..df0307f970 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); } diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 45fde90963..82c5a075fd 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -53,12 +53,16 @@ void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data { LivePathEffectEditor *lpeeditor = static_cast(data); lpeeditor->lpe_list_locked = false; + lpeeditor->lpe_changed = true; lpeeditor->onSelectionChanged(selection); } void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flags*/, gpointer data) { - lpeeditor_selection_changed (selection, data); + + LivePathEffectEditor *lpeeditor = static_cast(data); + lpeeditor->lpe_list_locked = false; + lpeeditor->onSelectionChanged(selection); } static void lpe_style_button(Gtk::Button& btn, char const* iconName) @@ -81,6 +85,7 @@ LivePathEffectEditor::LivePathEffectEditor() : UI::Widget::Panel("", "/dialogs/livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT), deskTrack(), lpe_list_locked(false), + lpe_changed(true), effectwidget(NULL), status_label("", Gtk::ALIGN_CENTER), effectcontrol_frame(""), @@ -191,6 +196,11 @@ LivePathEffectEditor::~LivePathEffectEditor() void LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) { + if (!effect.upd_params && !lpe_changed) { + lpe_changed = false; + return; + } + std::cout << "trialara\n"; if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); delete effectwidget; @@ -209,6 +219,8 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) effectcontrol_frame.show(); effectcontrol_vbox.show_all_children(); // fixme: add resizing of dialog + effect.upd_params = false; + lpe_changed = false; } void @@ -540,6 +552,7 @@ void LivePathEffectEditor::on_effect_selection_changed() current_lperef = lperef; LivePathEffect::Effect * effect = lperef->lpeobject->get_lpe(); if (effect) { + lpe_changed = true; showParams(*effect); } } diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index b18d434c5f..7f6f56fd2b 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -96,7 +96,7 @@ private: }; bool lpe_list_locked; - + bool lpe_changed; //Inkscape::UI::Widget::ComboBoxEnum combo_effecttype; Gtk::Widget * effectwidget; -- GitLab From 9fdad1dee71336c5d9b78567cbcb0be3d9cb0eb1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 5 May 2017 16:46:43 +0200 Subject: [PATCH 118/121] Remove unwanted cout (bzr r15660.1.3) --- src/ui/dialog/livepatheffect-editor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 82c5a075fd..e60ca77e64 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -200,7 +200,6 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) lpe_changed = false; return; } - std::cout << "trialara\n"; if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); delete effectwidget; -- GitLab From d4c5fb591bf045ed4f4577d5d8d54894c9dbd278 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 01:11:06 +0200 Subject: [PATCH 119/121] LPE widget refactor. Improvement to not update on same value (bzr r15660.1.5) --- 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(-) diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 9cb91bdd6e..3184bfa80f 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 6cadd6953e..78fa87a4f3 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 5add69c1d2..ca8908f0e8 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 1c10639606..45f46a0a73 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 90e53ca0e9..b1375adda1 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 4062a4dc78..d633666aa7 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 9eb89fea53..eb40a7e41f 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(); } -- GitLab From 5c14e84bb4e43c65e23ab5209c86a2425ce0e12c Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 02:27:58 +0200 Subject: [PATCH 120/121] Updating code to trunk (bzr r13645.1.176) --- share/keys/default.xml | 2 + share/keys/inkscape.xml | 1 + src/helper/Makefile_insert.THIS | 49 ------------------------- src/live_effects/lpe-fillet-chamfer.cpp | 1 - 4 files changed, 3 insertions(+), 50 deletions(-) delete mode 100644 src/helper/Makefile_insert.THIS diff --git a/share/keys/default.xml b/share/keys/default.xml index 581716d129..1342517528 100644 --- a/share/keys/default.xml +++ b/share/keys/default.xml @@ -383,6 +383,8 @@ override) the bindings in the main default.xml. + + diff --git a/share/keys/inkscape.xml b/share/keys/inkscape.xml index 581716d129..4461dee696 100644 --- a/share/keys/inkscape.xml +++ b/share/keys/inkscape.xml @@ -382,6 +382,7 @@ override) the bindings in the main default.xml. + diff --git a/src/helper/Makefile_insert.THIS b/src/helper/Makefile_insert.THIS deleted file mode 100644 index 6ba0efbfa3..0000000000 --- a/src/helper/Makefile_insert.THIS +++ /dev/null @@ -1,49 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -helper/unit-menu.$(OBJEXT): helper/sp-marshal.h - -ink_common_sources += \ - helper/action.cpp \ - helper/action.h \ - helper/action-context.cpp \ - helper/action-context.h \ - helper/geom.cpp \ - helper/geom.h \ - helper/geom-curves.h \ - helper/geom-nodetype.cpp \ - helper/geom-nodetype.h \ - helper/geom-pathstroke.cpp \ - helper/geom-pathstroke.h \ - helper/geom-pathvectorsatellites.cpp \ - helper/geom-pathvectorsatellites.h \ - helper/geom-satellite.cpp \ - helper/geom-satellite.h \ - helper/gnome-utils.cpp \ - helper/gnome-utils.h \ - helper/mathfns.h \ - helper/png-write.cpp \ - helper/png-write.h \ - helper/sp-marshal.cpp \ - helper/sp-marshal.h \ - helper/window.cpp \ - helper/window.h \ - helper/stock-items.cpp \ - helper/stock-items.h - -# cmp exits with status 0 when there are no differences. "if" executes the commands -# after "then" when the exit status of the if command is 0 (this is crazy). -helper/sp-marshal.h: helper/sp-marshal.list - glib-genmarshal --prefix=sp_marshal --header $(srcdir)/helper/sp-marshal.list > helper/tmp.sp-marshal.h - if cmp -s helper/sp-marshal.h helper/tmp.sp-marshal.h; \ - then rm helper/tmp.sp-marshal.h; \ - else mv helper/tmp.sp-marshal.h helper/sp-marshal.h; fi - -helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h - ( echo '#include "helper/sp-marshal.h"' && \ - glib-genmarshal --prefix=sp_marshal --body $(srcdir)/helper/sp-marshal.list ) \ - > helper/tmp.sp-marshal.cpp; \ - if cmp -s helper/sp-marshal.cpp helper/tmp.sp-marshal.cpp; \ - then rm helper/tmp.sp-marshal.cpp; \ - else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi - -helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b9e96cb72a..abb6fa9d27 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) { -- GitLab From 7eafd46a267d60265c0f9045b0d1591d2a92d12f Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 19:45:16 +0200 Subject: [PATCH 121/121] Pre merge fixing (bzr r13645.1.177) --- src/helper/geom-pathvectorsatellites.cpp | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 56 ++++++++++++------- src/live_effects/lpe-fillet-chamfer.h | 3 +- .../parameter/satellitesarray.cpp | 15 +++-- src/live_effects/parameter/satellitesarray.h | 2 +- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index dd231d78fa..e995c0a9b4 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -67,9 +67,7 @@ void PathVectorSatellites::setSelected(std::vector selected) size_t counter = 0; for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { - std::cout << j; if (find (selected.begin(), selected.end(), counter) != selected.end()) { - _satellites[i][j].setSelected(true); } else { _satellites[i][j].setSelected(false); @@ -134,6 +132,9 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo if (!use_knot_distance && !flexible) { if (previous_index) { _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); + if (power && !_satellites[i][j].amount) { + g_warning("Seems a too high radius value"); + } } else { _satellites[i][j].amount = 0.0; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index abb6fa9d27..e968a78228 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 2cee04a1ea..7f5dd7d4c3 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 c7bc7f0261..7626317a17 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 edaf2f08d4..5ae372ac2b 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; -- GitLab